Skip to content

Commit bca523e

Browse files
zWingzzwingzhengrekram1-node
authored
fix(js-sdk): fix types in session.chat (anomalyco#1925)
Co-authored-by: zwingzheng <zwingzheng@tencent.com> Co-authored-by: rekram1-node <aidenpcline@gmail.com>
1 parent 2ff4cd2 commit bca523e

6 files changed

Lines changed: 42 additions & 7 deletions

File tree

packages/opencode/src/server/server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,10 @@ export namespace Server {
611611
description: "Created message",
612612
content: {
613613
"application/json": {
614-
schema: resolver(MessageV2.Assistant),
614+
schema: resolver(z.object({
615+
info: MessageV2.Assistant,
616+
parts: MessageV2.Part.array(),
617+
})),
615618
},
616619
},
617620
},

packages/sdk/go/.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 39
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-e4b6496e5f2c68fa8b3ea1b88e40041eaf5ce2652001344df80bf130675d1766.yml
3-
openapi_spec_hash: df474311dc9e4a89cd483bd8b8d971d8
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-be3e40e0bf7dde2bb15ff82d5d104418fb47fe335808a1aa6468b0be2210a88f.yml
3+
openapi_spec_hash: c1bbb3ebd807656bd9f31a618077e76b
44
config_hash: eab3723c4c2232a6ba1821151259d6da

packages/sdk/go/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Response Types:
105105
- <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#ToolStatePending">ToolStatePending</a>
106106
- <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#ToolStateRunning">ToolStateRunning</a>
107107
- <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#UserMessage">UserMessage</a>
108+
- <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionChatResponse">SessionChatResponse</a>
108109
- <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionMessageResponse">SessionMessageResponse</a>
109110
- <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionMessagesResponse">SessionMessagesResponse</a>
110111

@@ -115,7 +116,7 @@ Methods:
115116
- <code title="get /session">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>) ([]<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
116117
- <code title="delete /session/{id}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Delete">Delete</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
117118
- <code title="post /session/{id}/abort">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Abort">Abort</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
118-
- <code title="post /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Chat">Chat</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionChatParams">SessionChatParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#AssistantMessage">AssistantMessage</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
119+
- <code title="post /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Chat">Chat</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionChatParams">SessionChatParams</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionChatResponse">SessionChatResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
119120
- <code title="get /session/{id}/children">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Children">Children</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) ([]<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
120121
- <code title="get /session/{id}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>) (<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#Session">Session</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
121122
- <code title="post /session/{id}/init">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Init">Init</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, id <a href="https://pkg.go.dev/builtin#string">string</a>, body <a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go">opencode</a>.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionInitParams">SessionInitParams</a>) (<a href="https://pkg.go.dev/builtin#bool">bool</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

packages/sdk/go/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ type Config struct {
7979
SmallModel string `json:"small_model"`
8080
Snapshot bool `json:"snapshot"`
8181
// Theme name to use for the interface
82-
Theme string `json:"theme"`
82+
Theme string `json:"theme"`
83+
Tools map[string]bool `json:"tools"`
8384
// TUI specific settings
8485
Tui ConfigTui `json:"tui"`
8586
// Custom username to display in conversations instead of system username
@@ -110,6 +111,7 @@ type configJSON struct {
110111
SmallModel apijson.Field
111112
Snapshot apijson.Field
112113
Theme apijson.Field
114+
Tools apijson.Field
113115
Tui apijson.Field
114116
Username apijson.Field
115117
raw string
@@ -1760,6 +1762,8 @@ type KeybindsConfig struct {
17601762
SessionNew string `json:"session_new,required"`
17611763
// Share current session
17621764
SessionShare string `json:"session_share,required"`
1765+
// Show session timeline
1766+
SessionTimeline string `json:"session_timeline,required"`
17631767
// Unshare current session
17641768
SessionUnshare string `json:"session_unshare,required"`
17651769
// @deprecated use agent_cycle. Next agent
@@ -1821,6 +1825,7 @@ type keybindsConfigJSON struct {
18211825
SessionList apijson.Field
18221826
SessionNew apijson.Field
18231827
SessionShare apijson.Field
1828+
SessionTimeline apijson.Field
18241829
SessionUnshare apijson.Field
18251830
SwitchAgent apijson.Field
18261831
SwitchAgentReverse apijson.Field

packages/sdk/go/session.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.Re
9191
}
9292

9393
// Create and send a new message to a session
94-
func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *AssistantMessage, err error) {
94+
func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *SessionChatResponse, err error) {
9595
opts = append(r.Options[:], opts...)
9696
if id == "" {
9797
err = errors.New("missing required id parameter")
@@ -2278,6 +2278,29 @@ func (r userMessageTimeJSON) RawJSON() string {
22782278
return r.raw
22792279
}
22802280

2281+
type SessionChatResponse struct {
2282+
Info AssistantMessage `json:"info,required"`
2283+
Parts []Part `json:"parts,required"`
2284+
JSON sessionChatResponseJSON `json:"-"`
2285+
}
2286+
2287+
// sessionChatResponseJSON contains the JSON metadata for the struct
2288+
// [SessionChatResponse]
2289+
type sessionChatResponseJSON struct {
2290+
Info apijson.Field
2291+
Parts apijson.Field
2292+
raw string
2293+
ExtraFields map[string]apijson.Field
2294+
}
2295+
2296+
func (r *SessionChatResponse) UnmarshalJSON(data []byte) (err error) {
2297+
return apijson.UnmarshalRoot(data, r)
2298+
}
2299+
2300+
func (r sessionChatResponseJSON) RawJSON() string {
2301+
return r.raw
2302+
}
2303+
22812304
type SessionMessageResponse struct {
22822305
Info Message `json:"info,required"`
22832306
Parts []Part `json:"parts,required"`

packages/sdk/js/src/gen/types.gen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,10 @@ export type SessionChatResponses = {
15271527
/**
15281528
* Created message
15291529
*/
1530-
200: AssistantMessage
1530+
200: {
1531+
info: AssistantMessage
1532+
parts: Array<Part>
1533+
}
15311534
}
15321535

15331536
export type SessionChatResponse = SessionChatResponses[keyof SessionChatResponses]

0 commit comments

Comments
 (0)