@@ -93,6 +93,7 @@ func init() {
9393 tasksCmd .AddCommand (listTasksCmd )
9494 tasksCmd .AddCommand (getTaskCmd )
9595 tasksCmd .AddCommand (historyCmd )
96+ tasksCmd .AddCommand (submitTaskCmd )
9697
9798 rootCmd .AddCommand (configCmd )
9899 rootCmd .AddCommand (tasksCmd )
@@ -105,6 +106,7 @@ func init() {
105106 listTasksCmd .Flags ().Int ("limit" , 50 , "Maximum number of tasks to return" )
106107 listTasksCmd .Flags ().Int ("offset" , 0 , "Number of tasks to skip" )
107108 getTaskCmd .Flags ().Int ("history-length" , 0 , "Number of history messages to include" )
109+ submitTaskCmd .Flags ().String ("context-id" , "" , "Context ID for the task (optional, will generate new context if not provided)" )
108110}
109111
110112func initConfig () {
@@ -562,3 +564,63 @@ var versionCmd = &cobra.Command{
562564 fmt .Printf ("Built: %s\n " , buildDate )
563565 },
564566}
567+
568+ var submitTaskCmd = & cobra.Command {
569+ Use : "submit [message]" ,
570+ Short : "Submit a new task to the A2A server" ,
571+ Long : "Submits a new task to the A2A server with the specified message." ,
572+ Args : cobra .ExactArgs (1 ),
573+ RunE : func (cmd * cobra.Command , args []string ) error {
574+ ctx := context .Background ()
575+ ensureA2AClient ()
576+
577+ message := args [0 ]
578+ contextID , _ := cmd .Flags ().GetString ("context-id" )
579+
580+ messageID := fmt .Sprintf ("msg-%d" , time .Now ().Unix ())
581+
582+ params := adk.MessageSendParams {
583+ Message : adk.Message {
584+ Kind : "message" ,
585+ MessageID : messageID ,
586+ Role : "user" ,
587+ Parts : []adk.Part {
588+ map [string ]interface {}{
589+ "kind" : "text" ,
590+ "text" : message ,
591+ },
592+ },
593+ },
594+ }
595+
596+ if contextID != "" {
597+ params .Message .ContextID = & contextID
598+ }
599+
600+ logger .Debug ("Submitting new task" , zap .String ("message" , message ), zap .String ("context_id" , contextID ))
601+
602+ resp , err := a2aClient .SendTask (ctx , params )
603+ if err != nil {
604+ return handleA2AError (err , "message/send" )
605+ }
606+
607+ resultBytes , err := json .Marshal (resp .Result )
608+ if err != nil {
609+ return fmt .Errorf ("failed to marshal response: %w" , err )
610+ }
611+
612+ var task adk.Task
613+ if err := json .Unmarshal (resultBytes , & task ); err != nil {
614+ return fmt .Errorf ("failed to unmarshal task: %w" , err )
615+ }
616+
617+ fmt .Printf ("✅ Task submitted successfully!\n \n " )
618+ fmt .Printf ("Task Details:\n " )
619+ fmt .Printf (" Task ID: %s\n " , task .ID )
620+ fmt .Printf (" Context ID: %s\n " , task .ContextID )
621+ fmt .Printf (" Status: %s\n " , task .Status .State )
622+ fmt .Printf (" Message ID: %s\n " , messageID )
623+
624+ return nil
625+ },
626+ }
0 commit comments