Skip to content

Commit 1549a98

Browse files
committed
feat: update LoadSession method to return LoadSessionResponse
Change-Id: I8b0d3562a5abd7f61416eb4efd8f6b52c0c3f3c8 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 422dc56 commit 1549a98

6 files changed

Lines changed: 61 additions & 32 deletions

File tree

go/acp_test.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (c clientFuncs) SessionUpdate(ctx context.Context, n SessionNotification) e
4949
type agentFuncs struct {
5050
InitializeFunc func(context.Context, InitializeRequest) (InitializeResponse, error)
5151
NewSessionFunc func(context.Context, NewSessionRequest) (NewSessionResponse, error)
52-
LoadSessionFunc func(context.Context, LoadSessionRequest) error
52+
LoadSessionFunc func(context.Context, LoadSessionRequest) (LoadSessionResponse, error)
5353
AuthenticateFunc func(context.Context, AuthenticateRequest) error
5454
PromptFunc func(context.Context, PromptRequest) (PromptResponse, error)
5555
CancelFunc func(context.Context, CancelNotification) error
@@ -74,11 +74,11 @@ func (a agentFuncs) NewSession(ctx context.Context, p NewSessionRequest) (NewSes
7474
return NewSessionResponse{}, nil
7575
}
7676

77-
func (a agentFuncs) LoadSession(ctx context.Context, p LoadSessionRequest) error {
77+
func (a agentFuncs) LoadSession(ctx context.Context, p LoadSessionRequest) (LoadSessionResponse, error) {
7878
if a.LoadSessionFunc != nil {
7979
return a.LoadSessionFunc(ctx, p)
8080
}
81-
return nil
81+
return LoadSessionResponse{}, nil
8282
}
8383

8484
func (a agentFuncs) Authenticate(ctx context.Context, p AuthenticateRequest) error {
@@ -127,8 +127,8 @@ func TestConnectionHandlesErrorsBidirectional(t *testing.T) {
127127
NewSessionFunc: func(context.Context, NewSessionRequest) (NewSessionResponse, error) {
128128
return NewSessionResponse{}, &RequestError{Code: -32603, Message: "Failed to create session"}
129129
},
130-
LoadSessionFunc: func(context.Context, LoadSessionRequest) error {
131-
return &RequestError{Code: -32603, Message: "Failed to load session"}
130+
LoadSessionFunc: func(context.Context, LoadSessionRequest) (LoadSessionResponse, error) {
131+
return LoadSessionResponse{}, &RequestError{Code: -32603, Message: "Failed to load session"}
132132
},
133133
AuthenticateFunc: func(context.Context, AuthenticateRequest) error {
134134
return &RequestError{Code: -32603, Message: "Authentication failed"}
@@ -181,7 +181,9 @@ func TestConnectionHandlesConcurrentRequests(t *testing.T) {
181181
NewSessionFunc: func(context.Context, NewSessionRequest) (NewSessionResponse, error) {
182182
return NewSessionResponse{SessionId: "test-session"}, nil
183183
},
184-
LoadSessionFunc: func(context.Context, LoadSessionRequest) error { return nil },
184+
LoadSessionFunc: func(context.Context, LoadSessionRequest) (LoadSessionResponse, error) {
185+
return LoadSessionResponse{}, nil
186+
},
185187
AuthenticateFunc: func(context.Context, AuthenticateRequest) error { return nil },
186188
PromptFunc: func(context.Context, PromptRequest) (PromptResponse, error) {
187189
return PromptResponse{StopReason: "end_turn"}, nil
@@ -254,9 +256,9 @@ func TestConnectionHandlesMessageOrdering(t *testing.T) {
254256
push("newSession called: " + p.Cwd)
255257
return NewSessionResponse{SessionId: "test-session"}, nil
256258
},
257-
LoadSessionFunc: func(_ context.Context, p LoadSessionRequest) error {
259+
LoadSessionFunc: func(_ context.Context, p LoadSessionRequest) (LoadSessionResponse, error) {
258260
push("loadSession called: " + string(p.SessionId))
259-
return nil
261+
return LoadSessionResponse{}, nil
260262
},
261263
AuthenticateFunc: func(_ context.Context, p AuthenticateRequest) error {
262264
push("authenticate called: " + string(p.MethodId))
@@ -354,7 +356,9 @@ func TestConnectionHandlesNotifications(t *testing.T) {
354356
NewSessionFunc: func(context.Context, NewSessionRequest) (NewSessionResponse, error) {
355357
return NewSessionResponse{SessionId: "test-session"}, nil
356358
},
357-
LoadSessionFunc: func(context.Context, LoadSessionRequest) error { return nil },
359+
LoadSessionFunc: func(context.Context, LoadSessionRequest) (LoadSessionResponse, error) {
360+
return LoadSessionResponse{}, nil
361+
},
358362
AuthenticateFunc: func(context.Context, AuthenticateRequest) error { return nil },
359363
PromptFunc: func(context.Context, PromptRequest) (PromptResponse, error) {
360364
return PromptResponse{StopReason: "end_turn"}, nil
@@ -425,7 +429,9 @@ func TestConnectionHandlesInitialize(t *testing.T) {
425429
NewSessionFunc: func(context.Context, NewSessionRequest) (NewSessionResponse, error) {
426430
return NewSessionResponse{SessionId: "test-session"}, nil
427431
},
428-
LoadSessionFunc: func(context.Context, LoadSessionRequest) error { return nil },
432+
LoadSessionFunc: func(context.Context, LoadSessionRequest) (LoadSessionResponse, error) {
433+
return LoadSessionResponse{}, nil
434+
},
429435
AuthenticateFunc: func(context.Context, AuthenticateRequest) error { return nil },
430436
PromptFunc: func(context.Context, PromptRequest) (PromptResponse, error) {
431437
return PromptResponse{StopReason: "end_turn"}, nil
@@ -472,7 +478,9 @@ func TestPromptCancellationSendsCancelAndAllowsNewSession(t *testing.T) {
472478
NewSessionFunc: func(context.Context, NewSessionRequest) (NewSessionResponse, error) {
473479
return NewSessionResponse{SessionId: "s-1"}, nil
474480
},
475-
LoadSessionFunc: func(context.Context, LoadSessionRequest) error { return nil },
481+
LoadSessionFunc: func(context.Context, LoadSessionRequest) (LoadSessionResponse, error) {
482+
return LoadSessionResponse{}, nil
483+
},
476484
AuthenticateFunc: func(context.Context, AuthenticateRequest) error { return nil },
477485
PromptFunc: func(ctx context.Context, p PromptRequest) (PromptResponse, error) {
478486
<-ctx.Done()

go/cmd/generate/internal/emit/types.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ func WriteTypesJen(outDir string, schema *load.Schema, meta *load.Meta) error {
127127
defaults = append(defaults, *dp)
128128
}
129129
if _, ok := req[pk]; !ok {
130-
// Default: omit if empty for optional fields, unless schema specifies
131-
// a default array/object (always present on wire).
132-
if dp == nil || (dp.kind != KindArray && dp.kind != KindObject) {
130+
// Default: omit if empty for optional fields.
131+
// Keep always-present behavior only for defaults where the zero value is nil (slice/map).
132+
// For typed object defaults (non-nilable), still allow omission on the wire.
133+
if dp == nil || (dp.kind != KindArray && dp.kind != KindObject) || (dp != nil && !dp.nilable) {
133134
tag = pk + ",omitempty"
134135
}
135136
}
@@ -198,6 +199,11 @@ func WriteTypesJen(outDir string, schema *load.Schema, meta *load.Meta) error {
198199
case ir.PrimaryType(def) == "string" || ir.PrimaryType(def) == "integer" || ir.PrimaryType(def) == "number" || ir.PrimaryType(def) == "boolean":
199200
f.Type().Id(name).Add(primitiveJenType(ir.PrimaryType(def)))
200201
f.Line()
202+
case ir.PrimaryType(def) == "object" && len(def.Properties) == 0:
203+
// Empty object shape: emit a concrete empty struct so methods can be defined
204+
// and the wire encoding is consistently {} rather than null.
205+
f.Type().Id(name).Struct()
206+
f.Line()
201207
default:
202208
f.Comment(fmt.Sprintf("%s is a union or complex schema; represented generically.", name))
203209
f.Type().Id(name).Any()
@@ -569,7 +575,9 @@ func emitUnion(f *File, name string, defs []*load.Definition, exactlyOne bool) {
569575
}
570576
}
571577
}
572-
fieldName := tname
578+
// Ensure Title-derived names are exported (e.g., "stdio" -> "Stdio").
579+
tname = util.ToExportedField(tname)
580+
fieldName := util.ToExportedField(tname)
573581
dv := ""
574582
if discKey != "" {
575583
if pd := v.Properties[discKey]; pd != nil && pd.Const != nil {

go/example/agent/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ func (a *exampleAgent) NewSession(ctx context.Context, params acp.NewSessionRequ
5656

5757
func (a *exampleAgent) Authenticate(ctx context.Context, _ acp.AuthenticateRequest) error { return nil }
5858

59-
func (a *exampleAgent) LoadSession(ctx context.Context, _ acp.LoadSessionRequest) error { return nil }
59+
func (a *exampleAgent) LoadSession(ctx context.Context, _ acp.LoadSessionRequest) (acp.LoadSessionResponse, error) {
60+
return acp.LoadSessionResponse{}, nil
61+
}
6062

6163
func (a *exampleAgent) Cancel(ctx context.Context, params acp.CancelNotification) error {
6264
a.mu.Lock()

go/json_parity_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,18 @@ func TestJSONGolden_MethodPayloads(t *testing.T) {
235235
return InitializeResponse{ProtocolVersion: 1, AgentCapabilities: AgentCapabilities{LoadSession: true, PromptCapabilities: PromptCapabilities{Image: true, Audio: true, EmbeddedContext: true}}}
236236
}))
237237
t.Run("new_session_request", runGolden(func() NewSessionRequest {
238-
return NewSessionRequest{Cwd: "/home/user/project", McpServers: []McpServer{{Name: "filesystem", Command: "/path/to/mcp-server", Args: []string{"--stdio"}, Env: []EnvVariable{}}}}
238+
return NewSessionRequest{
239+
Cwd: "/home/user/project", McpServers: []McpServer{
240+
{
241+
Stdio: &Stdio{
242+
Name: "filesystem",
243+
Command: "/path/to/mcp-server",
244+
Args: []string{"--stdio"},
245+
Env: []EnvVariable{},
246+
},
247+
},
248+
},
249+
}
239250
}))
240251
t.Run("new_session_response", runGolden(func() NewSessionResponse { return NewSessionResponse{SessionId: "sess_abc123def456"} }))
241252
t.Run("prompt_request", runGolden(func() PromptRequest {

go/testdata/json_golden/initialize_response.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"protocolVersion": 1,
33
"agentCapabilities": {
44
"loadSession": true,
5+
"mcpCapabilities": {},
56
"promptCapabilities": {
67
"image": true,
78
"audio": true,

go/types_gen.go

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)