Skip to content

Commit 1ae38c9

Browse files
committed
feat(api): get session and session children routes
1 parent 9609c18 commit 1ae38c9

8 files changed

Lines changed: 134 additions & 4 deletions

File tree

packages/opencode/src/server/server.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,34 @@ export namespace Server {
248248
return c.json(session)
249249
},
250250
)
251+
.get(
252+
"/session/:id/children",
253+
describeRoute({
254+
description: "Get a session's children",
255+
operationId: "session.children",
256+
responses: {
257+
200: {
258+
description: "List of children",
259+
content: {
260+
"application/json": {
261+
schema: resolver(Session.Info.array()),
262+
},
263+
},
264+
},
265+
},
266+
}),
267+
zValidator(
268+
"param",
269+
z.object({
270+
id: z.string(),
271+
}),
272+
),
273+
async (c) => {
274+
const sessionID = c.req.valid("param").id
275+
const session = await Session.children(sessionID)
276+
return c.json(session)
277+
},
278+
)
251279
.post(
252280
"/session",
253281
describeRoute({

packages/sdk/go/.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 37
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-e438f89b86b573c957866c9b057efacc912e3946be03390e4027e8dfab5b83ba.yml
3-
openapi_spec_hash: 4e9d257b86172e266dc9d72fb04548bc
4-
config_hash: a78225c7474eb9ab8745e72a0cfe6f96
1+
configured_endpoints: 39
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-b751e5c3cd3ab7fc61b18fbbfd6092b7264ea2ee305858aa538b884e7c492090.yml
3+
openapi_spec_hash: a61f8b1d9b834cf321f0cb7805cc8522
4+
config_hash: eab3723c4c2232a6ba1821151259d6da

packages/sdk/go/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Methods:
116116
- <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>
117117
- <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>
118118
- <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="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>
120+
- <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>
119121
- <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>
120122
- <code title="get /session/{id}/message/{messageID}">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Message">Message</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>, messageID <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#SessionMessageResponse">SessionMessageResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
121123
- <code title="get /session/{id}/message">client.Session.<a href="https://pkg.go.dev/github.com/sst/opencode-sdk-go#SessionService.Messages">Messages</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#SessionMessagesResponse">SessionMessagesResponse</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>

packages/sdk/go/session.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@ func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatPa
102102
return
103103
}
104104

105+
// Get a session's children
106+
func (r *SessionService) Children(ctx context.Context, id string, opts ...option.RequestOption) (res *[]Session, err error) {
107+
opts = append(r.Options[:], opts...)
108+
if id == "" {
109+
err = errors.New("missing required id parameter")
110+
return
111+
}
112+
path := fmt.Sprintf("session/%s/children", id)
113+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
114+
return
115+
}
116+
117+
// Get session
118+
func (r *SessionService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error) {
119+
opts = append(r.Options[:], opts...)
120+
if id == "" {
121+
err = errors.New("missing required id parameter")
122+
return
123+
}
124+
path := fmt.Sprintf("session/%s", id)
125+
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
126+
return
127+
}
128+
105129
// Analyze the app and create an AGENTS.md file
106130
func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error) {
107131
opts = append(r.Options[:], opts...)

packages/sdk/go/session_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,50 @@ func TestSessionChatWithOptionalParams(t *testing.T) {
174174
}
175175
}
176176

177+
func TestSessionChildren(t *testing.T) {
178+
t.Skip("skipped: tests are disabled for the time being")
179+
baseURL := "http://localhost:4010"
180+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
181+
baseURL = envURL
182+
}
183+
if !testutil.CheckTestServer(t, baseURL) {
184+
return
185+
}
186+
client := opencode.NewClient(
187+
option.WithBaseURL(baseURL),
188+
)
189+
_, err := client.Session.Children(context.TODO(), "id")
190+
if err != nil {
191+
var apierr *opencode.Error
192+
if errors.As(err, &apierr) {
193+
t.Log(string(apierr.DumpRequest(true)))
194+
}
195+
t.Fatalf("err should be nil: %s", err.Error())
196+
}
197+
}
198+
199+
func TestSessionGet(t *testing.T) {
200+
t.Skip("skipped: tests are disabled for the time being")
201+
baseURL := "http://localhost:4010"
202+
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
203+
baseURL = envURL
204+
}
205+
if !testutil.CheckTestServer(t, baseURL) {
206+
return
207+
}
208+
client := opencode.NewClient(
209+
option.WithBaseURL(baseURL),
210+
)
211+
_, err := client.Session.Get(context.TODO(), "id")
212+
if err != nil {
213+
var apierr *opencode.Error
214+
if errors.As(err, &apierr) {
215+
t.Log(string(apierr.DumpRequest(true)))
216+
}
217+
t.Fatalf("err should be nil: %s", err.Error())
218+
}
219+
}
220+
177221
func TestSessionInit(t *testing.T) {
178222
t.Skip("skipped: tests are disabled for the time being")
179223
baseURL := "http://localhost:4010"

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import type {
2121
SessionGetResponses,
2222
SessionUpdateData,
2323
SessionUpdateResponses,
24+
SessionChildrenData,
25+
SessionChildrenResponses,
2426
SessionInitData,
2527
SessionInitResponses,
2628
SessionAbortData,
@@ -247,6 +249,16 @@ class Session extends _HeyApiClient {
247249
})
248250
}
249251

252+
/**
253+
* Get a session's children
254+
*/
255+
public children<ThrowOnError extends boolean = false>(options: Options<SessionChildrenData, ThrowOnError>) {
256+
return (options.client ?? this._client).get<SessionChildrenResponses, unknown, ThrowOnError>({
257+
url: "/session/{id}/children",
258+
...options,
259+
})
260+
}
261+
250262
/**
251263
* Analyze the app and create an AGENTS.md file
252264
*/

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,24 @@ export type SessionUpdateResponses = {
13191319

13201320
export type SessionUpdateResponse = SessionUpdateResponses[keyof SessionUpdateResponses]
13211321

1322+
export type SessionChildrenData = {
1323+
body?: never
1324+
path: {
1325+
id: string
1326+
}
1327+
query?: never
1328+
url: "/session/{id}/children"
1329+
}
1330+
1331+
export type SessionChildrenResponses = {
1332+
/**
1333+
* List of children
1334+
*/
1335+
200: Array<Session>
1336+
}
1337+
1338+
export type SessionChildrenResponse = SessionChildrenResponses[keyof SessionChildrenResponses]
1339+
13221340
export type SessionInitData = {
13231341
body?: {
13241342
messageID: string

packages/sdk/stainless/stainless.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ resources:
113113
toolStateError: ToolStateError
114114

115115
methods:
116+
get: get /session/{id}
116117
list: get /session
118+
children: get /session/{id}/children
117119
create: post /session
118120
delete: delete /session/{id}
119121
init: post /session/{id}/init

0 commit comments

Comments
 (0)