NewClient creates a new HTTP client for the docker agent server
(baseURL string, opts ...ClientOption)
| 66 | |
| 67 | // NewClient creates a new HTTP client for the docker agent server |
| 68 | func NewClient(baseURL string, opts ...ClientOption) (*Client, error) { |
| 69 | parsedURL, err := url.Parse(baseURL) |
| 70 | if err != nil { |
| 71 | return nil, fmt.Errorf("invalid base URL: %w", err) |
| 72 | } |
| 73 | |
| 74 | client := &Client{ |
| 75 | baseURL: parsedURL, |
| 76 | httpClient: &http.Client{ |
| 77 | Timeout: 30 * time.Second, |
| 78 | }, |
| 79 | registry: map[string]func() Event{ |
| 80 | "user_message": func() Event { return &UserMessageEvent{} }, |
| 81 | "tool_call": func() Event { return &ToolCallEvent{} }, |
| 82 | "tool_call_output": func() Event { return &ToolCallOutputEvent{} }, |
| 83 | "tool_call_response": func() Event { return &ToolCallResponseEvent{} }, |
| 84 | "tool_call_confirmation": func() Event { return &ToolCallConfirmationEvent{} }, |
| 85 | "token_usage": func() Event { return &TokenUsageEvent{} }, |
| 86 | "stream_stopped": func() Event { return &StreamStoppedEvent{} }, |
| 87 | "runtime_paused": func() Event { return &PausedEvent{} }, |
| 88 | "stream_started": func() Event { return &StreamStartedEvent{} }, |
| 89 | "shell": func() Event { return &ShellOutputEvent{} }, |
| 90 | "session_title": func() Event { return &SessionTitleEvent{} }, |
| 91 | "session_plan_updated": func() Event { return &SessionPlanUpdatedEvent{} }, |
| 92 | "session_summary": func() Event { return &SessionSummaryEvent{} }, |
| 93 | "session_compaction": func() Event { return &SessionCompactionEvent{} }, |
| 94 | "partial_tool_call": func() Event { return &PartialToolCallEvent{} }, |
| 95 | "max_iterations_reached": func() Event { return &MaxIterationsReachedEvent{} }, |
| 96 | "error": func() Event { return &ErrorEvent{} }, |
| 97 | "elicitation_request": func() Event { return &ElicitationRequestEvent{} }, |
| 98 | "authorization_event": func() Event { return &AuthorizationEvent{} }, |
| 99 | "agent_choice": func() Event { return &AgentChoiceEvent{} }, |
| 100 | "agent_choice_reasoning": func() Event { return &AgentChoiceReasoningEvent{} }, |
| 101 | "mcp_init_started": func() Event { return &MCPInitStartedEvent{} }, |
| 102 | "mcp_init_finished": func() Event { return &MCPInitFinishedEvent{} }, |
| 103 | "agent_info": func() Event { return &AgentInfoEvent{} }, |
| 104 | "team_info": func() Event { return &TeamInfoEvent{} }, |
| 105 | "toolset_info": func() Event { return &ToolsetInfoEvent{} }, |
| 106 | "agent_switching": func() Event { return &AgentSwitchingEvent{} }, |
| 107 | "warning": func() Event { return &WarningEvent{} }, |
| 108 | "hook_blocked": func() Event { return &HookBlockedEvent{} }, |
| 109 | "hook_started": func() Event { return &HookStartedEvent{} }, |
| 110 | "hook_finished": func() Event { return &HookFinishedEvent{} }, |
| 111 | "rag_indexing_started": func() Event { return &RAGIndexingStartedEvent{} }, |
| 112 | "rag_indexing_progress": func() Event { return &RAGIndexingProgressEvent{} }, |
| 113 | "rag_indexing_completed": func() Event { return &RAGIndexingCompletedEvent{} }, |
| 114 | "message_added": func() Event { return &MessageAddedEvent{} }, |
| 115 | "model_fallback": func() Event { return &ModelFallbackEvent{} }, |
| 116 | "sub_session_completed": func() Event { return &SubSessionCompletedEvent{} }, |
| 117 | "connection_lost": func() Event { return &ConnectionLostEvent{} }, |
| 118 | "connection_restored": func() Event { return &ConnectionRestoredEvent{} }, |
| 119 | }, |
| 120 | } |
| 121 | |
| 122 | for _, opt := range opts { |
| 123 | opt(client) |
| 124 | } |
| 125 |