()
| 27 | } |
| 28 | |
| 29 | func newChatCmd() *cobra.Command { |
| 30 | var flags chatFlags |
| 31 | |
| 32 | cmd := &cobra.Command{ |
| 33 | Use: "chat <agent-file>|<registry-ref>", |
| 34 | Short: "Start an agent as an OpenAI-compatible chat completions server", |
| 35 | Long: `Start an HTTP server that exposes the agent through an OpenAI-compatible |
| 36 | API at /v1/chat/completions and /v1/models. This lets tools that already |
| 37 | speak OpenAI's chat protocol (such as Open WebUI) drive a docker-agent |
| 38 | agent without any custom integration.`, |
| 39 | Example: ` docker-agent serve chat ./agent.yaml |
| 40 | docker-agent serve chat ./team.yaml --agent reviewer |
| 41 | docker-agent serve chat agentcatalog/pirate --listen 127.0.0.1:9090`, |
| 42 | Args: cobra.ExactArgs(1), |
| 43 | RunE: flags.runChatCommand, |
| 44 | } |
| 45 | |
| 46 | cmd.Flags().StringVarP(&flags.agentName, "agent", "a", "", "Name of the agent to expose (all agents if not specified)") |
| 47 | cmd.Flags().StringVarP(&flags.listenAddr, "listen", "l", "127.0.0.1:8083", "Address to listen on") |
| 48 | cmd.Flags().StringVar(&flags.corsOrigin, "cors-origin", "", "Allowed CORS origin (e.g. https://example.com); empty disables CORS entirely") |
| 49 | cmd.Flags().StringVar(&flags.apiKey, "api-key", "", "Required Bearer token clients must present (Authorization: Bearer <token>); empty disables auth") |
| 50 | cmd.Flags().StringVar(&flags.apiKeyEnv, "api-key-env", "", "Read the API key from this environment variable instead of the command line") |
| 51 | cmd.Flags().Int64Var(&flags.maxRequestSize, "max-request-size", 1<<20, "Maximum request body size in bytes (default 1 MiB)") |
| 52 | cmd.Flags().DurationVar(&flags.requestTimeout, "request-timeout", 5*time.Minute, "Per-request timeout (covers model + tool calls + streaming)") |
| 53 | cmd.Flags().IntVar(&flags.conversationsMaxItems, "conversations-max", 0, "Cache up to N conversations server-side, keyed by X-Conversation-Id (0 disables; clients must resend full history)") |
| 54 | cmd.Flags().DurationVar(&flags.conversationTTL, "conversation-ttl", 30*time.Minute, "Idle TTL after which a cached conversation is evicted") |
| 55 | cmd.Flags().IntVar(&flags.maxIdleRuntimes, "max-idle-runtimes", 4, "Maximum number of idle runtimes pooled per agent (0 disables pooling)") |
| 56 | addRuntimeConfigFlags(cmd, &flags.runConfig) |
| 57 | |
| 58 | return cmd |
| 59 | } |
| 60 | |
| 61 | func (f *chatFlags) runChatCommand(cmd *cobra.Command, args []string) (commandErr error) { |
| 62 | ctx := cmd.Context() |
no test coverage detected