diff --git a/go/README.md b/go/README.md index a6a7fe4a..2e2dbb78 100644 --- a/go/README.md +++ b/go/README.md @@ -192,10 +192,10 @@ For more control over the JSON schema, use the `Tool` struct directly: lookupIssue := copilot.Tool{ Name: "lookup_issue", Description: "Fetch issue details from our tracker", - Parameters: map[string]interface{}{ + Parameters: map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "id": map[string]interface{}{ + "properties": map[string]any{ + "id": map[string]any{ "type": "string", "description": "Issue identifier", }, @@ -203,7 +203,7 @@ lookupIssue := copilot.Tool{ "required": []string{"id"}, }, Handler: func(invocation copilot.ToolInvocation) (copilot.ToolResult, error) { - args := invocation.Arguments.(map[string]interface{}) + args := invocation.Arguments.(map[string]any) issue, err := fetchIssue(args["id"].(string)) if err != nil { return copilot.ToolResult{}, err @@ -414,12 +414,12 @@ session, err := client.CreateSession(&copilot.SessionConfig{ // request.Question - The question to ask // request.Choices - Optional slice of choices for multiple choice // request.AllowFreeform - Whether freeform input is allowed (default: true) - + fmt.Printf("Agent asks: %s\n", request.Question) if len(request.Choices) > 0 { fmt.Printf("Choices: %v\n", request.Choices) } - + // Return the user's response return copilot.UserInputResponse{ Answer: "User's answer here", @@ -447,7 +447,7 @@ session, err := client.CreateSession(&copilot.SessionConfig{ AdditionalContext: "Extra context for the model", }, nil }, - + // Called after each tool execution OnPostToolUse: func(input copilot.PostToolUseHookInput, invocation copilot.HookInvocation) (*copilot.PostToolUseHookOutput, error) { fmt.Printf("Tool %s completed\n", input.ToolName) @@ -455,7 +455,7 @@ session, err := client.CreateSession(&copilot.SessionConfig{ AdditionalContext: "Post-execution notes", }, nil }, - + // Called when user submits a prompt OnUserPromptSubmitted: func(input copilot.UserPromptSubmittedHookInput, invocation copilot.HookInvocation) (*copilot.UserPromptSubmittedHookOutput, error) { fmt.Printf("User prompt: %s\n", input.Prompt) @@ -463,7 +463,7 @@ session, err := client.CreateSession(&copilot.SessionConfig{ ModifiedPrompt: input.Prompt, // Optionally modify the prompt }, nil }, - + // Called when session starts OnSessionStart: func(input copilot.SessionStartHookInput, invocation copilot.HookInvocation) (*copilot.SessionStartHookOutput, error) { fmt.Printf("Session started from: %s\n", input.Source) // "startup", "resume", "new" @@ -471,13 +471,13 @@ session, err := client.CreateSession(&copilot.SessionConfig{ AdditionalContext: "Session initialization context", }, nil }, - + // Called when session ends OnSessionEnd: func(input copilot.SessionEndHookInput, invocation copilot.HookInvocation) (*copilot.SessionEndHookOutput, error) { fmt.Printf("Session ended: %s\n", input.Reason) return nil, nil }, - + // Called when an error occurs OnErrorOccurred: func(input copilot.ErrorOccurredHookInput, invocation copilot.HookInvocation) (*copilot.ErrorOccurredHookOutput, error) { fmt.Printf("Error in %s: %s\n", input.ErrorContext, input.Error) diff --git a/go/client.go b/go/client.go index 4fd44c3a..1992cecd 100644 --- a/go/client.go +++ b/go/client.go @@ -70,10 +70,10 @@ type Client struct { sessions map[string]*Session sessionsMux sync.Mutex isExternalServer bool - conn interface{} // stores net.Conn for external TCP connections - useStdio bool // resolved value from options - autoStart bool // resolved value from options - autoRestart bool // resolved value from options + conn any // stores net.Conn for external TCP connections + useStdio bool // resolved value from options + autoStart bool // resolved value from options + autoRestart bool // resolved value from options modelsCache []ModelInfo modelsCacheMux sync.Mutex } @@ -399,8 +399,8 @@ func (c *Client) ForceStop() { } // buildProviderParams converts a ProviderConfig to a map for JSON-RPC params. -func buildProviderParams(p *ProviderConfig) map[string]interface{} { - params := make(map[string]interface{}) +func buildProviderParams(p *ProviderConfig) map[string]any { + params := make(map[string]any) if p.Type != "" { params["type"] = p.Type } @@ -417,7 +417,7 @@ func buildProviderParams(p *ProviderConfig) map[string]interface{} { params["bearerToken"] = p.BearerToken } if p.Azure != nil { - azure := make(map[string]interface{}) + azure := make(map[string]any) if p.Azure.APIVersion != "" { azure["apiVersion"] = p.Azure.APIVersion } @@ -465,7 +465,7 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) { } } - params := make(map[string]interface{}) + params := make(map[string]any) if config != nil { if config.Model != "" { params["model"] = config.Model @@ -477,12 +477,12 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) { params["reasoningEffort"] = config.ReasoningEffort } if len(config.Tools) > 0 { - toolDefs := make([]map[string]interface{}, 0, len(config.Tools)) + toolDefs := make([]map[string]any, 0, len(config.Tools)) for _, tool := range config.Tools { if tool.Name == "" { continue } - definition := map[string]interface{}{ + definition := map[string]any{ "name": tool.Name, "description": tool.Description, } @@ -497,7 +497,7 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) { } // Add system message configuration if provided if config.SystemMessage != nil { - systemMessage := make(map[string]interface{}) + systemMessage := make(map[string]any) if config.SystemMessage.Mode != "" { systemMessage["mode"] = config.SystemMessage.Mode @@ -559,9 +559,9 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) { } // Add custom agents configuration if len(config.CustomAgents) > 0 { - customAgents := make([]map[string]interface{}, 0, len(config.CustomAgents)) + customAgents := make([]map[string]any, 0, len(config.CustomAgents)) for _, agent := range config.CustomAgents { - agentMap := map[string]interface{}{ + agentMap := map[string]any{ "name": agent.Name, "prompt": agent.Prompt, } @@ -598,7 +598,7 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) { } // Add infinite sessions configuration if config.InfiniteSessions != nil { - infiniteSessions := make(map[string]interface{}) + infiniteSessions := make(map[string]any) if config.InfiniteSessions.Enabled != nil { infiniteSessions["enabled"] = *config.InfiniteSessions.Enabled } @@ -680,7 +680,7 @@ func (c *Client) ResumeSessionWithOptions(sessionID string, config *ResumeSessio } } - params := map[string]interface{}{ + params := map[string]any{ "sessionId": sessionID, } @@ -689,12 +689,12 @@ func (c *Client) ResumeSessionWithOptions(sessionID string, config *ResumeSessio params["reasoningEffort"] = config.ReasoningEffort } if len(config.Tools) > 0 { - toolDefs := make([]map[string]interface{}, 0, len(config.Tools)) + toolDefs := make([]map[string]any, 0, len(config.Tools)) for _, tool := range config.Tools { if tool.Name == "" { continue } - definition := map[string]interface{}{ + definition := map[string]any{ "name": tool.Name, "description": tool.Description, } @@ -745,9 +745,9 @@ func (c *Client) ResumeSessionWithOptions(sessionID string, config *ResumeSessio } // Add custom agents configuration if len(config.CustomAgents) > 0 { - customAgents := make([]map[string]interface{}, 0, len(config.CustomAgents)) + customAgents := make([]map[string]any, 0, len(config.CustomAgents)) for _, agent := range config.CustomAgents { - agentMap := map[string]interface{}{ + agentMap := map[string]any{ "name": agent.Name, "prompt": agent.Prompt, } @@ -840,7 +840,7 @@ func (c *Client) ListSessions() ([]SessionMetadata, error) { } } - result, err := c.client.Request("session.list", map[string]interface{}{}) + result, err := c.client.Request("session.list", map[string]any{}) if err != nil { return nil, err } @@ -880,7 +880,7 @@ func (c *Client) DeleteSession(sessionID string) error { } } - params := map[string]interface{}{ + params := map[string]any{ "sessionId": sessionID, } @@ -947,7 +947,7 @@ func (c *Client) Ping(message string) (*PingResponse, error) { return nil, fmt.Errorf("client not connected") } - params := map[string]interface{}{} + params := map[string]any{} if message != "" { params["message"] = message } @@ -978,7 +978,7 @@ func (c *Client) GetStatus() (*GetStatusResponse, error) { return nil, fmt.Errorf("client not connected") } - result, err := c.client.Request("status.get", map[string]interface{}{}) + result, err := c.client.Request("status.get", map[string]any{}) if err != nil { return nil, err } @@ -1000,7 +1000,7 @@ func (c *Client) GetAuthStatus() (*GetAuthStatusResponse, error) { return nil, fmt.Errorf("client not connected") } - result, err := c.client.Request("auth.getStatus", map[string]interface{}{}) + result, err := c.client.Request("auth.getStatus", map[string]any{}) if err != nil { return nil, err } @@ -1047,7 +1047,7 @@ func (c *Client) ListModels() ([]ModelInfo, error) { } // Cache miss - fetch from backend while holding lock - result, err := c.client.Request("models.list", map[string]interface{}{}) + result, err := c.client.Request("models.list", map[string]any{}) if err != nil { return nil, err } @@ -1250,7 +1250,7 @@ func (c *Client) connectViaTcp() error { // setupNotificationHandler configures handlers for session events, tool calls, and permission requests. func (c *Client) setupNotificationHandler() { - c.client.SetNotificationHandler(func(method string, params map[string]interface{}) { + c.client.SetNotificationHandler(func(method string, params map[string]any) { if method == "session.event" { // Extract sessionId and event sessionID, ok := params["sessionId"].(string) @@ -1287,7 +1287,7 @@ func (c *Client) setupNotificationHandler() { } // handleToolCallRequest handles a tool call request from the CLI server. -func (c *Client) handleToolCallRequest(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) { +func (c *Client) handleToolCallRequest(params map[string]any) (map[string]any, *JSONRPCError) { sessionID, _ := params["sessionId"].(string) toolCallID, _ := params["toolCallId"].(string) toolName, _ := params["toolName"].(string) @@ -1305,19 +1305,19 @@ func (c *Client) handleToolCallRequest(params map[string]interface{}) (map[strin handler, ok := session.getToolHandler(toolName) if !ok { - return map[string]interface{}{"result": buildUnsupportedToolResult(toolName)}, nil + return map[string]any{"result": buildUnsupportedToolResult(toolName)}, nil } arguments := params["arguments"] result := c.executeToolCall(sessionID, toolCallID, toolName, arguments, handler) - return map[string]interface{}{"result": result}, nil + return map[string]any{"result": result}, nil } // executeToolCall executes a tool handler and returns the result. func (c *Client) executeToolCall( sessionID, toolCallID, toolName string, - arguments interface{}, + arguments any, handler ToolHandler, ) (result ToolResult) { invocation := ToolInvocation{ @@ -1347,9 +1347,9 @@ func (c *Client) executeToolCall( } // handlePermissionRequest handles a permission request from the CLI server. -func (c *Client) handlePermissionRequest(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) { +func (c *Client) handlePermissionRequest(params map[string]any) (map[string]any, *JSONRPCError) { sessionID, _ := params["sessionId"].(string) - permissionRequest, _ := params["permissionRequest"].(map[string]interface{}) + permissionRequest, _ := params["permissionRequest"].(map[string]any) if sessionID == "" { return nil, &JSONRPCError{Code: -32602, Message: "invalid permission request payload"} @@ -1365,18 +1365,18 @@ func (c *Client) handlePermissionRequest(params map[string]interface{}) (map[str result, err := session.handlePermissionRequest(permissionRequest) if err != nil { // Return denial on error - return map[string]interface{}{ - "result": map[string]interface{}{ + return map[string]any{ + "result": map[string]any{ "kind": "denied-no-approval-rule-and-could-not-request-from-user", }, }, nil } - return map[string]interface{}{"result": result}, nil + return map[string]any{"result": result}, nil } // handleUserInputRequest handles a user input request from the CLI server. -func (c *Client) handleUserInputRequest(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) { +func (c *Client) handleUserInputRequest(params map[string]any) (map[string]any, *JSONRPCError) { sessionID, _ := params["sessionId"].(string) question, _ := params["question"].(string) @@ -1393,7 +1393,7 @@ func (c *Client) handleUserInputRequest(params map[string]interface{}) (map[stri // Parse choices var choices []string - if choicesRaw, ok := params["choices"].([]interface{}); ok { + if choicesRaw, ok := params["choices"].([]any); ok { for _, choice := range choicesRaw { if s, ok := choice.(string); ok { choices = append(choices, s) @@ -1417,17 +1417,17 @@ func (c *Client) handleUserInputRequest(params map[string]interface{}) (map[stri return nil, &JSONRPCError{Code: -32603, Message: err.Error()} } - return map[string]interface{}{ + return map[string]any{ "answer": response.Answer, "wasFreeform": response.WasFreeform, }, nil } // handleHooksInvoke handles a hooks invocation from the CLI server. -func (c *Client) handleHooksInvoke(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) { +func (c *Client) handleHooksInvoke(params map[string]any) (map[string]any, *JSONRPCError) { sessionID, _ := params["sessionId"].(string) hookType, _ := params["hookType"].(string) - input, _ := params["input"].(map[string]interface{}) + input, _ := params["input"].(map[string]any) if sessionID == "" || hookType == "" { return nil, &JSONRPCError{Code: -32602, Message: "invalid hooks invoke payload"} @@ -1445,7 +1445,7 @@ func (c *Client) handleHooksInvoke(params map[string]interface{}) (map[string]in return nil, &JSONRPCError{Code: -32603, Message: err.Error()} } - result := make(map[string]interface{}) + result := make(map[string]any) if output != nil { result["output"] = output } @@ -1458,7 +1458,7 @@ func buildFailedToolResult(internalError string) ToolResult { TextResultForLLM: "Invoking this tool produced an error. Detailed information is not available.", ResultType: "failure", Error: internalError, - ToolTelemetry: map[string]interface{}{}, + ToolTelemetry: map[string]any{}, } } @@ -1468,6 +1468,6 @@ func buildUnsupportedToolResult(toolName string) ToolResult { TextResultForLLM: fmt.Sprintf("Tool '%s' is not supported by this client instance.", toolName), ResultType: "failure", Error: fmt.Sprintf("tool '%s' not supported", toolName), - ToolTelemetry: map[string]interface{}{}, + ToolTelemetry: map[string]any{}, } } diff --git a/go/client_test.go b/go/client_test.go index d020e0dc..41e4f27c 100644 --- a/go/client_test.go +++ b/go/client_test.go @@ -25,11 +25,11 @@ func TestClient_HandleToolCallRequest(t *testing.T) { t.Fatalf("Failed to create session: %v", err) } - params := map[string]interface{}{ + params := map[string]any{ "sessionId": session.SessionID, "toolCallId": "123", "toolName": "missing_tool", - "arguments": map[string]interface{}{}, + "arguments": map[string]any{}, } response, _ := client.handleToolCallRequest(params) diff --git a/go/definetool.go b/go/definetool.go index 876f5687..406a8c0b 100644 --- a/go/definetool.go +++ b/go/definetool.go @@ -45,7 +45,7 @@ func createTypedHandler[T any, U any](handler func(T, ToolInvocation) (U, error) var params T // Convert arguments to typed struct via JSON round-trip - // Arguments is already map[string]interface{} from JSON-RPC parsing + // Arguments is already map[string]any from JSON-RPC parsing jsonBytes, err := json.Marshal(inv.Arguments) if err != nil { return ToolResult{}, fmt.Errorf("failed to marshal arguments: %w", err) @@ -101,7 +101,7 @@ func normalizeResult(result any) (ToolResult, error) { // generateSchemaForType generates a JSON schema map from a Go type using reflection. // Panics if schema generation fails, as this indicates a programming error. -func generateSchemaForType(t reflect.Type) map[string]interface{} { +func generateSchemaForType(t reflect.Type) map[string]any { if t == nil { return nil } @@ -117,13 +117,13 @@ func generateSchemaForType(t reflect.Type) map[string]interface{} { panic(fmt.Sprintf("failed to generate schema for type %v: %v", t, err)) } - // Convert schema to map[string]interface{} + // Convert schema to map[string]any schemaBytes, err := json.Marshal(schema) if err != nil { panic(fmt.Sprintf("failed to marshal schema for type %v: %v", t, err)) } - var schemaMap map[string]interface{} + var schemaMap map[string]any if err := json.Unmarshal(schemaBytes, &schemaMap); err != nil { panic(fmt.Sprintf("failed to unmarshal schema for type %v: %v", t, err)) } diff --git a/go/definetool_test.go b/go/definetool_test.go index 5a871b3e..af620b18 100644 --- a/go/definetool_test.go +++ b/go/definetool_test.go @@ -47,7 +47,7 @@ func TestDefineTool(t *testing.T) { t.Errorf("Expected schema type 'object', got %v", schema["type"]) } - props, ok := schema["properties"].(map[string]interface{}) + props, ok := schema["properties"].(map[string]any) if !ok { t.Fatalf("Expected properties to be map, got %T", schema["properties"]) } @@ -77,7 +77,7 @@ func TestDefineTool(t *testing.T) { SessionID: "session-1", ToolCallID: "call-1", ToolName: "test", - Arguments: map[string]interface{}{ + Arguments: map[string]any{ "name": "Alice", "count": float64(42), // JSON numbers are float64 }, @@ -110,7 +110,7 @@ func TestDefineTool(t *testing.T) { SessionID: "session-123", ToolCallID: "call-456", ToolName: "test", - Arguments: map[string]interface{}{}, + Arguments: map[string]any{}, } tool.Handler(inv) @@ -132,7 +132,7 @@ func TestDefineTool(t *testing.T) { }) inv := ToolInvocation{ - Arguments: map[string]interface{}{}, + Arguments: map[string]any{}, } _, err := tool.Handler(inv) @@ -218,7 +218,7 @@ func TestNormalizeResult(t *testing.T) { }) t.Run("map is JSON serialized", func(t *testing.T) { - result, err := normalizeResult(map[string]interface{}{ + result, err := normalizeResult(map[string]any{ "key": "value", }) if err != nil { @@ -266,12 +266,12 @@ func TestGenerateSchemaForType(t *testing.T) { t.Errorf("Expected type 'object', got %v", schema["type"]) } - props, ok := schema["properties"].(map[string]interface{}) + props, ok := schema["properties"].(map[string]any) if !ok { t.Fatalf("Expected properties map, got %T", schema["properties"]) } - nameProp, ok := props["name"].(map[string]interface{}) + nameProp, ok := props["name"].(map[string]any) if !ok { t.Fatal("Expected 'name' property") } @@ -279,7 +279,7 @@ func TestGenerateSchemaForType(t *testing.T) { t.Errorf("Expected name type 'string', got %v", nameProp["type"]) } - ageProp, ok := props["age"].(map[string]interface{}) + ageProp, ok := props["age"].(map[string]any) if !ok { t.Fatal("Expected 'age' property") } @@ -300,14 +300,14 @@ func TestGenerateSchemaForType(t *testing.T) { schema := generateSchemaForType(reflect.TypeOf(Person{})) - props := schema["properties"].(map[string]interface{}) - addrProp, ok := props["address"].(map[string]interface{}) + props := schema["properties"].(map[string]any) + addrProp, ok := props["address"].(map[string]any) if !ok { t.Fatal("Expected 'address' property") } // Nested struct should have properties - addrProps, ok := addrProp["properties"].(map[string]interface{}) + addrProps, ok := addrProp["properties"].(map[string]any) if !ok { t.Fatal("Expected address to have properties") } @@ -327,7 +327,7 @@ func TestGenerateSchemaForType(t *testing.T) { t.Errorf("Expected type 'object', got %v", schema["type"]) } - props := schema["properties"].(map[string]interface{}) + props := schema["properties"].(map[string]any) if _, ok := props["value"]; !ok { t.Error("Expected 'value' property") } @@ -348,8 +348,8 @@ func TestGenerateSchemaForType(t *testing.T) { schema := generateSchemaForType(reflect.TypeOf(Params{})) - props := schema["properties"].(map[string]interface{}) - tagsProp, ok := props["tags"].(map[string]interface{}) + props := schema["properties"].(map[string]any) + tagsProp, ok := props["tags"].(map[string]any) if !ok { t.Fatal("Expected 'tags' property") } @@ -361,7 +361,7 @@ func TestGenerateSchemaForType(t *testing.T) { if v != "array" { t.Errorf("Expected tags type 'array', got %v", v) } - case []interface{}: + case []any: hasArray := false for _, item := range v { if item == "array" { diff --git a/go/e2e/session_test.go b/go/e2e/session_test.go index 6368fa18..35a2d549 100644 --- a/go/e2e/session_test.go +++ b/go/e2e/session_test.go @@ -264,10 +264,10 @@ func TestSession(t *testing.T) { { Name: "get_secret_number", Description: "Gets the secret number", - Parameters: map[string]interface{}{ + Parameters: map[string]any{ "type": "object", - "properties": map[string]interface{}{ - "key": map[string]interface{}{ + "properties": map[string]any{ + "key": map[string]any{ "type": "string", "description": "Key", }, @@ -275,7 +275,7 @@ func TestSession(t *testing.T) { "required": []string{"key"}, }, Handler: func(invocation copilot.ToolInvocation) (copilot.ToolResult, error) { - args, _ := invocation.Arguments.(map[string]interface{}) + args, _ := invocation.Arguments.(map[string]any) key, _ := args["key"].(string) if key == "ALPHA" { return copilot.ToolResult{ diff --git a/go/generated_session_events.go b/go/generated_session_events.go index 98af62b5..ae5e7fe5 100644 --- a/go/generated_session_events.go +++ b/go/generated_session_events.go @@ -107,7 +107,7 @@ type Data struct { ProviderCallID *string `json:"providerCallId,omitempty"` QuotaSnapshots map[string]QuotaSnapshot `json:"quotaSnapshots,omitempty"` Reason *string `json:"reason,omitempty"` - Arguments interface{} `json:"arguments"` + Arguments any `json:"arguments"` ToolCallID *string `json:"toolCallId,omitempty"` ToolName *string `json:"toolName,omitempty"` MCPServerName *string `json:"mcpServerName,omitempty"` @@ -116,15 +116,15 @@ type Data struct { ProgressMessage *string `json:"progressMessage,omitempty"` IsUserRequested *bool `json:"isUserRequested,omitempty"` Result *Result `json:"result,omitempty"` - ToolTelemetry map[string]interface{} `json:"toolTelemetry,omitempty"` + ToolTelemetry map[string]any `json:"toolTelemetry,omitempty"` AgentDescription *string `json:"agentDescription,omitempty"` AgentDisplayName *string `json:"agentDisplayName,omitempty"` AgentName *string `json:"agentName,omitempty"` Tools []string `json:"tools"` HookInvocationID *string `json:"hookInvocationId,omitempty"` HookType *string `json:"hookType,omitempty"` - Input interface{} `json:"input"` - Output interface{} `json:"output"` + Input any `json:"input"` + Output any `json:"output"` Metadata *Metadata `json:"metadata,omitempty"` Name *string `json:"name,omitempty"` Role *Role `json:"role,omitempty"` @@ -174,8 +174,8 @@ type ErrorClass struct { } type Metadata struct { - PromptVersion *string `json:"promptVersion,omitempty"` - Variables map[string]interface{} `json:"variables,omitempty"` + PromptVersion *string `json:"promptVersion,omitempty"` + Variables map[string]any `json:"variables,omitempty"` } type QuotaSnapshot struct { @@ -201,7 +201,7 @@ type Result struct { } type ToolRequest struct { - Arguments interface{} `json:"arguments"` + Arguments any `json:"arguments"` Name string `json:"name"` ToolCallID string `json:"toolCallId"` Type *ToolRequestType `json:"type,omitempty"` @@ -320,7 +320,7 @@ func (x *ErrorUnion) MarshalJSON() ([]byte, error) { return marshalUnion(nil, nil, nil, x.String, false, nil, x.ErrorClass != nil, x.ErrorClass, false, nil, false, nil, false) } -func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) (bool, error) { +func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa any, haveObject bool, pc any, haveMap bool, pm any, haveEnum bool, pe any, nullable bool) (bool, error) { if pi != nil { *pi = nil } @@ -402,7 +402,7 @@ func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **strin return false, errors.New("Cannot unmarshal union") } -func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) ([]byte, error) { +func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa any, haveObject bool, pc any, haveMap bool, pm any, haveEnum bool, pe any, nullable bool) ([]byte, error) { if pi != nil { return json.Marshal(*pi) } diff --git a/go/jsonrpc.go b/go/jsonrpc.go index 678fd1cf..f79db4b9 100644 --- a/go/jsonrpc.go +++ b/go/jsonrpc.go @@ -11,9 +11,9 @@ import ( // JSONRPCError represents a JSON-RPC error response type JSONRPCError struct { - Code int `json:"code"` - Message string `json:"message"` - Data map[string]interface{} `json:"data,omitempty"` + Code int `json:"code"` + Message string `json:"message"` + Data map[string]any `json:"data,omitempty"` } func (e *JSONRPCError) Error() string { @@ -22,32 +22,32 @@ func (e *JSONRPCError) Error() string { // JSONRPCRequest represents a JSON-RPC 2.0 request type JSONRPCRequest struct { - JSONRPC string `json:"jsonrpc"` - ID json.RawMessage `json:"id"` - Method string `json:"method"` - Params map[string]interface{} `json:"params"` + JSONRPC string `json:"jsonrpc"` + ID json.RawMessage `json:"id"` + Method string `json:"method"` + Params map[string]any `json:"params"` } // JSONRPCResponse represents a JSON-RPC 2.0 response type JSONRPCResponse struct { - JSONRPC string `json:"jsonrpc"` - ID json.RawMessage `json:"id,omitempty"` - Result map[string]interface{} `json:"result,omitempty"` - Error *JSONRPCError `json:"error,omitempty"` + JSONRPC string `json:"jsonrpc"` + ID json.RawMessage `json:"id,omitempty"` + Result map[string]any `json:"result,omitempty"` + Error *JSONRPCError `json:"error,omitempty"` } // JSONRPCNotification represents a JSON-RPC 2.0 notification type JSONRPCNotification struct { - JSONRPC string `json:"jsonrpc"` - Method string `json:"method"` - Params map[string]interface{} `json:"params"` + JSONRPC string `json:"jsonrpc"` + Method string `json:"method"` + Params map[string]any `json:"params"` } // NotificationHandler handles incoming notifications -type NotificationHandler func(method string, params map[string]interface{}) +type NotificationHandler func(method string, params map[string]any) // RequestHandler handles incoming server requests and returns a result or error -type RequestHandler func(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) +type RequestHandler func(params map[string]any) (map[string]any, *JSONRPCError) // JSONRPCClient is a minimal JSON-RPC 2.0 client for stdio transport type JSONRPCClient struct { @@ -115,7 +115,7 @@ func (c *JSONRPCClient) SetRequestHandler(method string, handler RequestHandler) } // Request sends a JSON-RPC request and waits for the response -func (c *JSONRPCClient) Request(method string, params map[string]interface{}) (map[string]interface{}, error) { +func (c *JSONRPCClient) Request(method string, params map[string]any) (map[string]any, error) { requestID := generateUUID() // Create response channel @@ -156,7 +156,7 @@ func (c *JSONRPCClient) Request(method string, params map[string]interface{}) (m } // Notify sends a JSON-RPC notification (no response expected) -func (c *JSONRPCClient) Notify(method string, params map[string]interface{}) error { +func (c *JSONRPCClient) Notify(method string, params map[string]any) error { notification := JSONRPCNotification{ JSONRPC: "2.0", Method: method, @@ -166,7 +166,7 @@ func (c *JSONRPCClient) Notify(method string, params map[string]interface{}) err } // sendMessage writes a message to stdin -func (c *JSONRPCClient) sendMessage(message interface{}) error { +func (c *JSONRPCClient) sendMessage(message any) error { data, err := json.Marshal(message) if err != nil { return fmt.Errorf("failed to marshal message: %w", err) @@ -304,13 +304,13 @@ func (c *JSONRPCClient) handleRequest(request *JSONRPCRequest) { return } if result == nil { - result = make(map[string]interface{}) + result = make(map[string]any) } c.sendResponse(request.ID, result) }() } -func (c *JSONRPCClient) sendResponse(id json.RawMessage, result map[string]interface{}) { +func (c *JSONRPCClient) sendResponse(id json.RawMessage, result map[string]any) { response := JSONRPCResponse{ JSONRPC: "2.0", ID: id, @@ -321,7 +321,7 @@ func (c *JSONRPCClient) sendResponse(id json.RawMessage, result map[string]inter } } -func (c *JSONRPCClient) sendErrorResponse(id json.RawMessage, code int, message string, data map[string]interface{}) { +func (c *JSONRPCClient) sendErrorResponse(id json.RawMessage, code int, message string, data map[string]any) { response := JSONRPCResponse{ JSONRPC: "2.0", ID: id, diff --git a/go/session.go b/go/session.go index 63838569..822fa0d6 100644 --- a/go/session.go +++ b/go/session.go @@ -106,7 +106,7 @@ func NewSession(sessionID string, client *JSONRPCClient, workspacePath string) * // log.Printf("Failed to send message: %v", err) // } func (s *Session) Send(options MessageOptions) (string, error) { - params := map[string]interface{}{ + params := map[string]any{ "sessionId": s.SessionID, "prompt": options.Prompt, } @@ -304,7 +304,7 @@ func (s *Session) getPermissionHandler() PermissionHandler { // handlePermissionRequest handles a permission request from the Copilot CLI. // This is an internal method called by the SDK when the CLI requests permission. -func (s *Session) handlePermissionRequest(requestData map[string]interface{}) (PermissionRequestResult, error) { +func (s *Session) handlePermissionRequest(requestData map[string]any) (PermissionRequestResult, error) { handler := s.getPermissionHandler() if handler == nil { @@ -386,7 +386,7 @@ func (s *Session) getHooks() *SessionHooks { // handleHooksInvoke handles a hook invocation from the Copilot CLI. // This is an internal method called by the SDK when the CLI invokes a hook. -func (s *Session) handleHooksInvoke(hookType string, input map[string]interface{}) (interface{}, error) { +func (s *Session) handleHooksInvoke(hookType string, input map[string]any) (any, error) { hooks := s.getHooks() if hooks == nil { @@ -447,7 +447,7 @@ func (s *Session) handleHooksInvoke(hookType string, input map[string]interface{ // Helper functions to parse hook inputs -func parsePreToolUseInput(input map[string]interface{}) PreToolUseHookInput { +func parsePreToolUseInput(input map[string]any) PreToolUseHookInput { result := PreToolUseHookInput{} if ts, ok := input["timestamp"].(float64); ok { result.Timestamp = int64(ts) @@ -462,7 +462,7 @@ func parsePreToolUseInput(input map[string]interface{}) PreToolUseHookInput { return result } -func parsePostToolUseInput(input map[string]interface{}) PostToolUseHookInput { +func parsePostToolUseInput(input map[string]any) PostToolUseHookInput { result := PostToolUseHookInput{} if ts, ok := input["timestamp"].(float64); ok { result.Timestamp = int64(ts) @@ -478,7 +478,7 @@ func parsePostToolUseInput(input map[string]interface{}) PostToolUseHookInput { return result } -func parseUserPromptSubmittedInput(input map[string]interface{}) UserPromptSubmittedHookInput { +func parseUserPromptSubmittedInput(input map[string]any) UserPromptSubmittedHookInput { result := UserPromptSubmittedHookInput{} if ts, ok := input["timestamp"].(float64); ok { result.Timestamp = int64(ts) @@ -492,7 +492,7 @@ func parseUserPromptSubmittedInput(input map[string]interface{}) UserPromptSubmi return result } -func parseSessionStartInput(input map[string]interface{}) SessionStartHookInput { +func parseSessionStartInput(input map[string]any) SessionStartHookInput { result := SessionStartHookInput{} if ts, ok := input["timestamp"].(float64); ok { result.Timestamp = int64(ts) @@ -509,7 +509,7 @@ func parseSessionStartInput(input map[string]interface{}) SessionStartHookInput return result } -func parseSessionEndInput(input map[string]interface{}) SessionEndHookInput { +func parseSessionEndInput(input map[string]any) SessionEndHookInput { result := SessionEndHookInput{} if ts, ok := input["timestamp"].(float64); ok { result.Timestamp = int64(ts) @@ -529,7 +529,7 @@ func parseSessionEndInput(input map[string]interface{}) SessionEndHookInput { return result } -func parseErrorOccurredInput(input map[string]interface{}) ErrorOccurredHookInput { +func parseErrorOccurredInput(input map[string]any) ErrorOccurredHookInput { result := ErrorOccurredHookInput{} if ts, ok := input["timestamp"].(float64); ok { result.Timestamp = int64(ts) @@ -594,7 +594,7 @@ func (s *Session) dispatchEvent(event SessionEvent) { // } // } func (s *Session) GetMessages() ([]SessionEvent, error) { - params := map[string]interface{}{ + params := map[string]any{ "sessionId": s.SessionID, } @@ -603,7 +603,7 @@ func (s *Session) GetMessages() ([]SessionEvent, error) { return nil, fmt.Errorf("failed to get messages: %w", err) } - eventsRaw, ok := result["events"].([]interface{}) + eventsRaw, ok := result["events"].([]any) if !ok { return nil, fmt.Errorf("invalid response: missing events") } @@ -643,7 +643,7 @@ func (s *Session) GetMessages() ([]SessionEvent, error) { // log.Printf("Failed to destroy session: %v", err) // } func (s *Session) Destroy() error { - params := map[string]interface{}{ + params := map[string]any{ "sessionId": s.SessionID, } @@ -690,7 +690,7 @@ func (s *Session) Destroy() error { // log.Printf("Failed to abort: %v", err) // } func (s *Session) Abort() error { - params := map[string]interface{}{ + params := map[string]any{ "sessionId": s.SessionID, } diff --git a/go/types.go b/go/types.go index 6b44aec3..7e51843d 100644 --- a/go/types.go +++ b/go/types.go @@ -91,15 +91,15 @@ type SystemMessageConfig struct { // PermissionRequest represents a permission request from the server type PermissionRequest struct { - Kind string `json:"kind"` - ToolCallID string `json:"toolCallId,omitempty"` - Extra map[string]interface{} `json:"-"` // Additional fields vary by kind + Kind string `json:"kind"` + ToolCallID string `json:"toolCallId,omitempty"` + Extra map[string]any `json:"-"` // Additional fields vary by kind } // PermissionRequestResult represents the result of a permission request type PermissionRequestResult struct { - Kind string `json:"kind"` - Rules []interface{} `json:"rules,omitempty"` + Kind string `json:"kind"` + Rules []any `json:"rules,omitempty"` } // PermissionHandler executes a permission request @@ -135,19 +135,19 @@ type UserInputInvocation struct { // PreToolUseHookInput is the input for a pre-tool-use hook type PreToolUseHookInput struct { - Timestamp int64 `json:"timestamp"` - Cwd string `json:"cwd"` - ToolName string `json:"toolName"` - ToolArgs interface{} `json:"toolArgs"` + Timestamp int64 `json:"timestamp"` + Cwd string `json:"cwd"` + ToolName string `json:"toolName"` + ToolArgs any `json:"toolArgs"` } // PreToolUseHookOutput is the output for a pre-tool-use hook type PreToolUseHookOutput struct { - PermissionDecision string `json:"permissionDecision,omitempty"` // "allow", "deny", "ask" - PermissionDecisionReason string `json:"permissionDecisionReason,omitempty"` - ModifiedArgs interface{} `json:"modifiedArgs,omitempty"` - AdditionalContext string `json:"additionalContext,omitempty"` - SuppressOutput bool `json:"suppressOutput,omitempty"` + PermissionDecision string `json:"permissionDecision,omitempty"` // "allow", "deny", "ask" + PermissionDecisionReason string `json:"permissionDecisionReason,omitempty"` + ModifiedArgs any `json:"modifiedArgs,omitempty"` + AdditionalContext string `json:"additionalContext,omitempty"` + SuppressOutput bool `json:"suppressOutput,omitempty"` } // PreToolUseHandler handles pre-tool-use hook invocations @@ -155,18 +155,18 @@ type PreToolUseHandler func(input PreToolUseHookInput, invocation HookInvocation // PostToolUseHookInput is the input for a post-tool-use hook type PostToolUseHookInput struct { - Timestamp int64 `json:"timestamp"` - Cwd string `json:"cwd"` - ToolName string `json:"toolName"` - ToolArgs interface{} `json:"toolArgs"` - ToolResult interface{} `json:"toolResult"` + Timestamp int64 `json:"timestamp"` + Cwd string `json:"cwd"` + ToolName string `json:"toolName"` + ToolArgs any `json:"toolArgs"` + ToolResult any `json:"toolResult"` } // PostToolUseHookOutput is the output for a post-tool-use hook type PostToolUseHookOutput struct { - ModifiedResult interface{} `json:"modifiedResult,omitempty"` - AdditionalContext string `json:"additionalContext,omitempty"` - SuppressOutput bool `json:"suppressOutput,omitempty"` + ModifiedResult any `json:"modifiedResult,omitempty"` + AdditionalContext string `json:"additionalContext,omitempty"` + SuppressOutput bool `json:"suppressOutput,omitempty"` } // PostToolUseHandler handles post-tool-use hook invocations @@ -199,8 +199,8 @@ type SessionStartHookInput struct { // SessionStartHookOutput is the output for a session-start hook type SessionStartHookOutput struct { - AdditionalContext string `json:"additionalContext,omitempty"` - ModifiedConfig map[string]interface{} `json:"modifiedConfig,omitempty"` + AdditionalContext string `json:"additionalContext,omitempty"` + ModifiedConfig map[string]any `json:"modifiedConfig,omitempty"` } // SessionStartHandler handles session-start hook invocations @@ -281,8 +281,8 @@ type MCPRemoteServerConfig struct { } // MCPServerConfig can be either MCPLocalServerConfig or MCPRemoteServerConfig -// Use a map[string]interface{} for flexibility, or create separate configs -type MCPServerConfig map[string]interface{} +// Use a map[string]any for flexibility, or create separate configs +type MCPServerConfig map[string]any // CustomAgentConfig configures a custom agent type CustomAgentConfig struct { @@ -371,7 +371,7 @@ type SessionConfig struct { type Tool struct { Name string Description string // optional - Parameters map[string]interface{} + Parameters map[string]any Handler ToolHandler } @@ -380,7 +380,7 @@ type ToolInvocation struct { SessionID string ToolCallID string ToolName string - Arguments interface{} + Arguments any } // ToolHandler executes a tool invocation. @@ -389,12 +389,12 @@ type ToolHandler func(invocation ToolInvocation) (ToolResult, error) // ToolResult represents the result of a tool invocation. type ToolResult struct { - TextResultForLLM string `json:"textResultForLlm"` - BinaryResultsForLLM []ToolBinaryResult `json:"binaryResultsForLlm,omitempty"` - ResultType string `json:"resultType"` - Error string `json:"error,omitempty"` - SessionLog string `json:"sessionLog,omitempty"` - ToolTelemetry map[string]interface{} `json:"toolTelemetry,omitempty"` + TextResultForLLM string `json:"textResultForLlm"` + BinaryResultsForLLM []ToolBinaryResult `json:"binaryResultsForLlm,omitempty"` + ResultType string `json:"resultType"` + Error string `json:"error,omitempty"` + SessionLog string `json:"sessionLog,omitempty"` + ToolTelemetry map[string]any `json:"toolTelemetry,omitempty"` } // ResumeSessionConfig configures options when resuming a session