@@ -1031,39 +1031,30 @@ func (s *Server) runAgent(c echo.Context) error {
10311031 slog .Debug ("Runtime created for session" , "session_id" , sess .ID )
10321032 }
10331033
1034- var messages []api.Message
1035- if err := json .NewDecoder (c .Request ().Body ).Decode (& messages ); err != nil {
1036- return jsonErr (c , http .StatusBadRequest , "invalid request body" )
1037- }
1038-
1039- // TODO(dga): for now, we only receive one message and it's always a user message.
1040- for _ , msg := range messages {
1041- sess .AddMessage (session .UserMessage (agentFilename , msg .Content ))
1042- // Optional: run using a named command (?command=name)
1043- if cmd := strings .TrimSpace (c .QueryParam ("command" )); cmd != "" {
1044- cmds := agent .Commands ()
1045- if len (cmds ) == 0 {
1046- return c .JSON (http .StatusBadRequest , map [string ]string {"error" : fmt .Sprintf ("agent '%s' has no commands" , currentAgent )})
1047- }
1048- text , ok := cmds [cmd ]
1049- if ! ok {
1050- var names []string
1051- for k := range cmds {
1052- names = append (names , k )
1053- }
1054- sort .Strings (names )
1055- return c .JSON (http .StatusBadRequest , map [string ]string {"error" : fmt .Sprintf ("unknown command '%s'. Available: %s" , cmd , strings .Join (names , ", " ))})
1056- }
1057- sess .AddMessage (session .UserMessage (agentFilename , text ))
1058- } else {
1059- var messages []api.Message
1060- if err := json .NewDecoder (c .Request ().Body ).Decode (& messages ); err != nil {
1061- return c .JSON (http .StatusBadRequest , map [string ]string {"error" : "invalid request body" })
1062- }
1063- // TODO(dga): for now, we only receive one message and it's always a user message.
1064- for _ , msg := range messages {
1065- sess .AddMessage (session .UserMessage (agentFilename , msg .Content ))
1034+ if cmd := strings .TrimSpace (c .QueryParam ("command" )); cmd != "" {
1035+ cmds := agent .Commands ()
1036+ if len (cmds ) == 0 {
1037+ return c .JSON (http .StatusBadRequest , map [string ]string {"error" : fmt .Sprintf ("agent '%s' has no commands" , currentAgent )})
1038+ }
1039+ text , ok := cmds [cmd ]
1040+ if ! ok {
1041+ var names []string
1042+ for k := range cmds {
1043+ names = append (names , k )
10661044 }
1045+ sort .Strings (names )
1046+ return c .JSON (http .StatusBadRequest , map [string ]string {"error" : fmt .Sprintf ("unknown command '%s'. Available: %s" , cmd , strings .Join (names , ", " ))})
1047+ }
1048+ sess .AddMessage (session .UserMessage (agentFilename , text ))
1049+ } else {
1050+ // TODO(dga): for now, we only receive one message and it's always a user message.
1051+ var messages []api.Message
1052+ if err := json .NewDecoder (c .Request ().Body ).Decode (& messages ); err != nil {
1053+ return jsonErr (c , http .StatusBadRequest , "invalid request body" )
1054+ }
1055+
1056+ for _ , msg := range messages {
1057+ sess .AddMessage (session .UserMessage (agentFilename , msg .Content ))
10671058 }
10681059 }
10691060
0 commit comments