Skip to content

Commit bf95d2d

Browse files
authored
rewrite interface{} to any (#298)
1 parent a552ae4 commit bf95d2d

File tree

10 files changed

+157
-157
lines changed

10 files changed

+157
-157
lines changed

go/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,18 @@ For more control over the JSON schema, use the `Tool` struct directly:
192192
lookupIssue := copilot.Tool{
193193
Name: "lookup_issue",
194194
Description: "Fetch issue details from our tracker",
195-
Parameters: map[string]interface{}{
195+
Parameters: map[string]any{
196196
"type": "object",
197-
"properties": map[string]interface{}{
198-
"id": map[string]interface{}{
197+
"properties": map[string]any{
198+
"id": map[string]any{
199199
"type": "string",
200200
"description": "Issue identifier",
201201
},
202202
},
203203
"required": []string{"id"},
204204
},
205205
Handler: func(invocation copilot.ToolInvocation) (copilot.ToolResult, error) {
206-
args := invocation.Arguments.(map[string]interface{})
206+
args := invocation.Arguments.(map[string]any)
207207
issue, err := fetchIssue(args["id"].(string))
208208
if err != nil {
209209
return copilot.ToolResult{}, err
@@ -414,12 +414,12 @@ session, err := client.CreateSession(&copilot.SessionConfig{
414414
// request.Question - The question to ask
415415
// request.Choices - Optional slice of choices for multiple choice
416416
// request.AllowFreeform - Whether freeform input is allowed (default: true)
417-
417+
418418
fmt.Printf("Agent asks: %s\n", request.Question)
419419
if len(request.Choices) > 0 {
420420
fmt.Printf("Choices: %v\n", request.Choices)
421421
}
422-
422+
423423
// Return the user's response
424424
return copilot.UserInputResponse{
425425
Answer: "User's answer here",
@@ -447,37 +447,37 @@ session, err := client.CreateSession(&copilot.SessionConfig{
447447
AdditionalContext: "Extra context for the model",
448448
}, nil
449449
},
450-
450+
451451
// Called after each tool execution
452452
OnPostToolUse: func(input copilot.PostToolUseHookInput, invocation copilot.HookInvocation) (*copilot.PostToolUseHookOutput, error) {
453453
fmt.Printf("Tool %s completed\n", input.ToolName)
454454
return &copilot.PostToolUseHookOutput{
455455
AdditionalContext: "Post-execution notes",
456456
}, nil
457457
},
458-
458+
459459
// Called when user submits a prompt
460460
OnUserPromptSubmitted: func(input copilot.UserPromptSubmittedHookInput, invocation copilot.HookInvocation) (*copilot.UserPromptSubmittedHookOutput, error) {
461461
fmt.Printf("User prompt: %s\n", input.Prompt)
462462
return &copilot.UserPromptSubmittedHookOutput{
463463
ModifiedPrompt: input.Prompt, // Optionally modify the prompt
464464
}, nil
465465
},
466-
466+
467467
// Called when session starts
468468
OnSessionStart: func(input copilot.SessionStartHookInput, invocation copilot.HookInvocation) (*copilot.SessionStartHookOutput, error) {
469469
fmt.Printf("Session started from: %s\n", input.Source) // "startup", "resume", "new"
470470
return &copilot.SessionStartHookOutput{
471471
AdditionalContext: "Session initialization context",
472472
}, nil
473473
},
474-
474+
475475
// Called when session ends
476476
OnSessionEnd: func(input copilot.SessionEndHookInput, invocation copilot.HookInvocation) (*copilot.SessionEndHookOutput, error) {
477477
fmt.Printf("Session ended: %s\n", input.Reason)
478478
return nil, nil
479479
},
480-
480+
481481
// Called when an error occurs
482482
OnErrorOccurred: func(input copilot.ErrorOccurredHookInput, invocation copilot.HookInvocation) (*copilot.ErrorOccurredHookOutput, error) {
483483
fmt.Printf("Error in %s: %s\n", input.ErrorContext, input.Error)

go/client.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ type Client struct {
7070
sessions map[string]*Session
7171
sessionsMux sync.Mutex
7272
isExternalServer bool
73-
conn interface{} // stores net.Conn for external TCP connections
74-
useStdio bool // resolved value from options
75-
autoStart bool // resolved value from options
76-
autoRestart bool // resolved value from options
73+
conn any // stores net.Conn for external TCP connections
74+
useStdio bool // resolved value from options
75+
autoStart bool // resolved value from options
76+
autoRestart bool // resolved value from options
7777
modelsCache []ModelInfo
7878
modelsCacheMux sync.Mutex
7979
}
@@ -399,8 +399,8 @@ func (c *Client) ForceStop() {
399399
}
400400

401401
// buildProviderParams converts a ProviderConfig to a map for JSON-RPC params.
402-
func buildProviderParams(p *ProviderConfig) map[string]interface{} {
403-
params := make(map[string]interface{})
402+
func buildProviderParams(p *ProviderConfig) map[string]any {
403+
params := make(map[string]any)
404404
if p.Type != "" {
405405
params["type"] = p.Type
406406
}
@@ -417,7 +417,7 @@ func buildProviderParams(p *ProviderConfig) map[string]interface{} {
417417
params["bearerToken"] = p.BearerToken
418418
}
419419
if p.Azure != nil {
420-
azure := make(map[string]interface{})
420+
azure := make(map[string]any)
421421
if p.Azure.APIVersion != "" {
422422
azure["apiVersion"] = p.Azure.APIVersion
423423
}
@@ -465,7 +465,7 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) {
465465
}
466466
}
467467

468-
params := make(map[string]interface{})
468+
params := make(map[string]any)
469469
if config != nil {
470470
if config.Model != "" {
471471
params["model"] = config.Model
@@ -477,12 +477,12 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) {
477477
params["reasoningEffort"] = config.ReasoningEffort
478478
}
479479
if len(config.Tools) > 0 {
480-
toolDefs := make([]map[string]interface{}, 0, len(config.Tools))
480+
toolDefs := make([]map[string]any, 0, len(config.Tools))
481481
for _, tool := range config.Tools {
482482
if tool.Name == "" {
483483
continue
484484
}
485-
definition := map[string]interface{}{
485+
definition := map[string]any{
486486
"name": tool.Name,
487487
"description": tool.Description,
488488
}
@@ -497,7 +497,7 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) {
497497
}
498498
// Add system message configuration if provided
499499
if config.SystemMessage != nil {
500-
systemMessage := make(map[string]interface{})
500+
systemMessage := make(map[string]any)
501501

502502
if config.SystemMessage.Mode != "" {
503503
systemMessage["mode"] = config.SystemMessage.Mode
@@ -559,9 +559,9 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) {
559559
}
560560
// Add custom agents configuration
561561
if len(config.CustomAgents) > 0 {
562-
customAgents := make([]map[string]interface{}, 0, len(config.CustomAgents))
562+
customAgents := make([]map[string]any, 0, len(config.CustomAgents))
563563
for _, agent := range config.CustomAgents {
564-
agentMap := map[string]interface{}{
564+
agentMap := map[string]any{
565565
"name": agent.Name,
566566
"prompt": agent.Prompt,
567567
}
@@ -598,7 +598,7 @@ func (c *Client) CreateSession(config *SessionConfig) (*Session, error) {
598598
}
599599
// Add infinite sessions configuration
600600
if config.InfiniteSessions != nil {
601-
infiniteSessions := make(map[string]interface{})
601+
infiniteSessions := make(map[string]any)
602602
if config.InfiniteSessions.Enabled != nil {
603603
infiniteSessions["enabled"] = *config.InfiniteSessions.Enabled
604604
}
@@ -680,7 +680,7 @@ func (c *Client) ResumeSessionWithOptions(sessionID string, config *ResumeSessio
680680
}
681681
}
682682

683-
params := map[string]interface{}{
683+
params := map[string]any{
684684
"sessionId": sessionID,
685685
}
686686

@@ -689,12 +689,12 @@ func (c *Client) ResumeSessionWithOptions(sessionID string, config *ResumeSessio
689689
params["reasoningEffort"] = config.ReasoningEffort
690690
}
691691
if len(config.Tools) > 0 {
692-
toolDefs := make([]map[string]interface{}, 0, len(config.Tools))
692+
toolDefs := make([]map[string]any, 0, len(config.Tools))
693693
for _, tool := range config.Tools {
694694
if tool.Name == "" {
695695
continue
696696
}
697-
definition := map[string]interface{}{
697+
definition := map[string]any{
698698
"name": tool.Name,
699699
"description": tool.Description,
700700
}
@@ -745,9 +745,9 @@ func (c *Client) ResumeSessionWithOptions(sessionID string, config *ResumeSessio
745745
}
746746
// Add custom agents configuration
747747
if len(config.CustomAgents) > 0 {
748-
customAgents := make([]map[string]interface{}, 0, len(config.CustomAgents))
748+
customAgents := make([]map[string]any, 0, len(config.CustomAgents))
749749
for _, agent := range config.CustomAgents {
750-
agentMap := map[string]interface{}{
750+
agentMap := map[string]any{
751751
"name": agent.Name,
752752
"prompt": agent.Prompt,
753753
}
@@ -840,7 +840,7 @@ func (c *Client) ListSessions() ([]SessionMetadata, error) {
840840
}
841841
}
842842

843-
result, err := c.client.Request("session.list", map[string]interface{}{})
843+
result, err := c.client.Request("session.list", map[string]any{})
844844
if err != nil {
845845
return nil, err
846846
}
@@ -880,7 +880,7 @@ func (c *Client) DeleteSession(sessionID string) error {
880880
}
881881
}
882882

883-
params := map[string]interface{}{
883+
params := map[string]any{
884884
"sessionId": sessionID,
885885
}
886886

@@ -947,7 +947,7 @@ func (c *Client) Ping(message string) (*PingResponse, error) {
947947
return nil, fmt.Errorf("client not connected")
948948
}
949949

950-
params := map[string]interface{}{}
950+
params := map[string]any{}
951951
if message != "" {
952952
params["message"] = message
953953
}
@@ -978,7 +978,7 @@ func (c *Client) GetStatus() (*GetStatusResponse, error) {
978978
return nil, fmt.Errorf("client not connected")
979979
}
980980

981-
result, err := c.client.Request("status.get", map[string]interface{}{})
981+
result, err := c.client.Request("status.get", map[string]any{})
982982
if err != nil {
983983
return nil, err
984984
}
@@ -1000,7 +1000,7 @@ func (c *Client) GetAuthStatus() (*GetAuthStatusResponse, error) {
10001000
return nil, fmt.Errorf("client not connected")
10011001
}
10021002

1003-
result, err := c.client.Request("auth.getStatus", map[string]interface{}{})
1003+
result, err := c.client.Request("auth.getStatus", map[string]any{})
10041004
if err != nil {
10051005
return nil, err
10061006
}
@@ -1047,7 +1047,7 @@ func (c *Client) ListModels() ([]ModelInfo, error) {
10471047
}
10481048

10491049
// Cache miss - fetch from backend while holding lock
1050-
result, err := c.client.Request("models.list", map[string]interface{}{})
1050+
result, err := c.client.Request("models.list", map[string]any{})
10511051
if err != nil {
10521052
return nil, err
10531053
}
@@ -1250,7 +1250,7 @@ func (c *Client) connectViaTcp() error {
12501250

12511251
// setupNotificationHandler configures handlers for session events, tool calls, and permission requests.
12521252
func (c *Client) setupNotificationHandler() {
1253-
c.client.SetNotificationHandler(func(method string, params map[string]interface{}) {
1253+
c.client.SetNotificationHandler(func(method string, params map[string]any) {
12541254
if method == "session.event" {
12551255
// Extract sessionId and event
12561256
sessionID, ok := params["sessionId"].(string)
@@ -1287,7 +1287,7 @@ func (c *Client) setupNotificationHandler() {
12871287
}
12881288

12891289
// handleToolCallRequest handles a tool call request from the CLI server.
1290-
func (c *Client) handleToolCallRequest(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) {
1290+
func (c *Client) handleToolCallRequest(params map[string]any) (map[string]any, *JSONRPCError) {
12911291
sessionID, _ := params["sessionId"].(string)
12921292
toolCallID, _ := params["toolCallId"].(string)
12931293
toolName, _ := params["toolName"].(string)
@@ -1305,19 +1305,19 @@ func (c *Client) handleToolCallRequest(params map[string]interface{}) (map[strin
13051305

13061306
handler, ok := session.getToolHandler(toolName)
13071307
if !ok {
1308-
return map[string]interface{}{"result": buildUnsupportedToolResult(toolName)}, nil
1308+
return map[string]any{"result": buildUnsupportedToolResult(toolName)}, nil
13091309
}
13101310

13111311
arguments := params["arguments"]
13121312
result := c.executeToolCall(sessionID, toolCallID, toolName, arguments, handler)
13131313

1314-
return map[string]interface{}{"result": result}, nil
1314+
return map[string]any{"result": result}, nil
13151315
}
13161316

13171317
// executeToolCall executes a tool handler and returns the result.
13181318
func (c *Client) executeToolCall(
13191319
sessionID, toolCallID, toolName string,
1320-
arguments interface{},
1320+
arguments any,
13211321
handler ToolHandler,
13221322
) (result ToolResult) {
13231323
invocation := ToolInvocation{
@@ -1347,9 +1347,9 @@ func (c *Client) executeToolCall(
13471347
}
13481348

13491349
// handlePermissionRequest handles a permission request from the CLI server.
1350-
func (c *Client) handlePermissionRequest(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) {
1350+
func (c *Client) handlePermissionRequest(params map[string]any) (map[string]any, *JSONRPCError) {
13511351
sessionID, _ := params["sessionId"].(string)
1352-
permissionRequest, _ := params["permissionRequest"].(map[string]interface{})
1352+
permissionRequest, _ := params["permissionRequest"].(map[string]any)
13531353

13541354
if sessionID == "" {
13551355
return nil, &JSONRPCError{Code: -32602, Message: "invalid permission request payload"}
@@ -1365,18 +1365,18 @@ func (c *Client) handlePermissionRequest(params map[string]interface{}) (map[str
13651365
result, err := session.handlePermissionRequest(permissionRequest)
13661366
if err != nil {
13671367
// Return denial on error
1368-
return map[string]interface{}{
1369-
"result": map[string]interface{}{
1368+
return map[string]any{
1369+
"result": map[string]any{
13701370
"kind": "denied-no-approval-rule-and-could-not-request-from-user",
13711371
},
13721372
}, nil
13731373
}
13741374

1375-
return map[string]interface{}{"result": result}, nil
1375+
return map[string]any{"result": result}, nil
13761376
}
13771377

13781378
// handleUserInputRequest handles a user input request from the CLI server.
1379-
func (c *Client) handleUserInputRequest(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) {
1379+
func (c *Client) handleUserInputRequest(params map[string]any) (map[string]any, *JSONRPCError) {
13801380
sessionID, _ := params["sessionId"].(string)
13811381
question, _ := params["question"].(string)
13821382

@@ -1393,7 +1393,7 @@ func (c *Client) handleUserInputRequest(params map[string]interface{}) (map[stri
13931393

13941394
// Parse choices
13951395
var choices []string
1396-
if choicesRaw, ok := params["choices"].([]interface{}); ok {
1396+
if choicesRaw, ok := params["choices"].([]any); ok {
13971397
for _, choice := range choicesRaw {
13981398
if s, ok := choice.(string); ok {
13991399
choices = append(choices, s)
@@ -1417,17 +1417,17 @@ func (c *Client) handleUserInputRequest(params map[string]interface{}) (map[stri
14171417
return nil, &JSONRPCError{Code: -32603, Message: err.Error()}
14181418
}
14191419

1420-
return map[string]interface{}{
1420+
return map[string]any{
14211421
"answer": response.Answer,
14221422
"wasFreeform": response.WasFreeform,
14231423
}, nil
14241424
}
14251425

14261426
// handleHooksInvoke handles a hooks invocation from the CLI server.
1427-
func (c *Client) handleHooksInvoke(params map[string]interface{}) (map[string]interface{}, *JSONRPCError) {
1427+
func (c *Client) handleHooksInvoke(params map[string]any) (map[string]any, *JSONRPCError) {
14281428
sessionID, _ := params["sessionId"].(string)
14291429
hookType, _ := params["hookType"].(string)
1430-
input, _ := params["input"].(map[string]interface{})
1430+
input, _ := params["input"].(map[string]any)
14311431

14321432
if sessionID == "" || hookType == "" {
14331433
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
14451445
return nil, &JSONRPCError{Code: -32603, Message: err.Error()}
14461446
}
14471447

1448-
result := make(map[string]interface{})
1448+
result := make(map[string]any)
14491449
if output != nil {
14501450
result["output"] = output
14511451
}
@@ -1458,7 +1458,7 @@ func buildFailedToolResult(internalError string) ToolResult {
14581458
TextResultForLLM: "Invoking this tool produced an error. Detailed information is not available.",
14591459
ResultType: "failure",
14601460
Error: internalError,
1461-
ToolTelemetry: map[string]interface{}{},
1461+
ToolTelemetry: map[string]any{},
14621462
}
14631463
}
14641464

@@ -1468,6 +1468,6 @@ func buildUnsupportedToolResult(toolName string) ToolResult {
14681468
TextResultForLLM: fmt.Sprintf("Tool '%s' is not supported by this client instance.", toolName),
14691469
ResultType: "failure",
14701470
Error: fmt.Sprintf("tool '%s' not supported", toolName),
1471-
ToolTelemetry: map[string]interface{}{},
1471+
ToolTelemetry: map[string]any{},
14721472
}
14731473
}

0 commit comments

Comments
 (0)