(deps commandDeps)
| 250 | } |
| 251 | |
| 252 | func newChannelReplyCommand(deps commandDeps) *cobra.Command { |
| 253 | var bodyRaw string |
| 254 | var toMessage string |
| 255 | var idempotencyKey string |
| 256 | flags := coordinationMetadataFlags{kind: string(contract.CoordinationMessageReply)} |
| 257 | |
| 258 | cmd := &cobra.Command{ |
| 259 | Use: agentKernelReplyKey, |
| 260 | Short: "Reply to a received coordination message", |
| 261 | Example: ` # Reply to one received coordination message |
| 262 | agh ch reply --to-message msg-123 --body '{"answer":"ready for review"}' |
| 263 | |
| 264 | # Add explicit correlation metadata when replying from outside an inherited delivery |
| 265 | agh ch reply \ |
| 266 | --to-message msg-123 \ |
| 267 | --task-id task-123 \ |
| 268 | --run-id run-123 \ |
| 269 | --coordination-channel-id coord-run-123 \ |
| 270 | --correlation-id run-123 \ |
| 271 | --body '{"answer":"ready for review"}'`, |
| 272 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 273 | flags.kindExplicit = cmd.Flags().Changed(agentKernelKindKey) |
| 274 | if flags.kindExplicit && |
| 275 | contract.CoordinationMessageKind(strings.TrimSpace(flags.kind)) != contract.CoordinationMessageReply { |
| 276 | return errors.New("cli: --kind must be reply for `agh ch reply`") |
| 277 | } |
| 278 | body, err := parseNetworkJSONValue("--body", bodyRaw) |
| 279 | if err != nil { |
| 280 | return err |
| 281 | } |
| 282 | metadata, err := flags.metadata("", contract.CoordinationMessageReply, false) |
| 283 | if err != nil { |
| 284 | return err |
| 285 | } |
| 286 | if !zeroCLIAgentCoordinationMetadata(metadata) && |
| 287 | metadata.MessageKind != contract.CoordinationMessageReply { |
| 288 | return errors.New("cli: --kind must be reply for `agh ch reply`") |
| 289 | } |
| 290 | request := AgentChannelReplyRequest{ |
| 291 | ReplyToMessageID: strings.TrimSpace(toMessage), |
| 292 | Body: body, |
| 293 | Metadata: metadata, |
| 294 | IdempotencyKey: strings.TrimSpace(idempotencyKey), |
| 295 | } |
| 296 | if err := contract.ValidateNoRawClaimTokenField(request); err != nil { |
| 297 | return err |
| 298 | } |
| 299 | |
| 300 | client, err := clientFromDeps(deps) |
| 301 | if err != nil { |
| 302 | return err |
| 303 | } |
| 304 | credentials, err := requireAgentCommandIdentity(cmd.Context(), deps, client, agentActionCLI("ch.reply")) |
| 305 | if err != nil { |
| 306 | return err |
| 307 | } |
| 308 | message, err := client.AgentChannelReply(cmd.Context(), request, credentials) |
| 309 | if err != nil { |
no test coverage detected