Skip to content

Commit e92c67c

Browse files
feat(api): api update
1 parent 1441d64 commit e92c67c

File tree

4 files changed

+23
-57
lines changed

4 files changed

+23
-57
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 22
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/opencode%2Fopencode-7270b9e4859010d6680bcc92afcd6f7c679d80a2645f65d7097d19ce2e8cdc5a.yml
33
openapi_spec_hash: 5fcbfaedebfea62c17c74437a9728b04
4-
config_hash: 931828b5dd9393834a3c1703e02e02b0
4+
config_hash: 38a50dff50297c2f735b5e1c83fa0188

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@ import (
4949

5050
func main() {
5151
client := opencode.NewClient()
52-
stream := client.Event.ListStreaming(context.TODO())
53-
for stream.Next() {
54-
fmt.Printf("%+v\n", stream.Current())
55-
}
56-
err := stream.Err()
52+
sessions, err := client.Session.List(context.TODO())
5753
if err != nil {
5854
panic(err.Error())
5955
}
56+
fmt.Printf("%+v\n", sessions)
6057
}
6158

6259
```
@@ -145,7 +142,7 @@ client := opencode.NewClient(
145142
option.WithHeader("X-Some-Header", "custom_header_info"),
146143
)
147144

148-
client.Event.List(context.TODO(), ...,
145+
client.Session.List(context.TODO(), ...,
149146
// Override the header
150147
option.WithHeader("X-Some-Header", "some_other_custom_header_info"),
151148
// Add an undocumented field to the request body, using sjson syntax
@@ -174,14 +171,14 @@ When the API returns a non-success status code, we return an error with type
174171
To handle errors, we recommend that you use the `errors.As` pattern:
175172

176173
```go
177-
stream := client.Event.ListStreaming(context.TODO())
178-
if stream.Err() != nil {
174+
_, err := client.Session.List(context.TODO())
175+
if err != nil {
179176
var apierr *opencode.Error
180-
if errors.As(stream.Err(), &apierr) {
177+
if errors.As(err, &apierr) {
181178
println(string(apierr.DumpRequest(true))) // Prints the serialized HTTP request
182179
println(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response
183180
}
184-
panic(stream.Err().Error()) // GET "/event": 400 Bad Request { ... }
181+
panic(err.Error()) // GET "/session": 400 Bad Request { ... }
185182
}
186183
```
187184

@@ -199,7 +196,7 @@ To set a per-retry timeout, use `option.WithRequestTimeout()`.
199196
// This sets the timeout for the request, including all the retries.
200197
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
201198
defer cancel()
202-
client.Event.ListStreaming(
199+
client.Session.List(
203200
ctx,
204201
// This sets the per-retry timeout
205202
option.WithRequestTimeout(20*time.Second),
@@ -234,7 +231,7 @@ client := opencode.NewClient(
234231
)
235232

236233
// Override per-request:
237-
client.Event.ListStreaming(context.TODO(), option.WithMaxRetries(5))
234+
client.Session.List(context.TODO(), option.WithMaxRetries(5))
238235
```
239236

240237
### Accessing raw response data (e.g. response headers)
@@ -245,11 +242,11 @@ you need to examine response headers, status codes, or other details.
245242
```go
246243
// Create a variable to store the HTTP response
247244
var response *http.Response
248-
stream := client.Event.ListStreaming(context.TODO(), option.WithResponseInto(&response))
249-
if stream.Err() != nil {
245+
sessions, err := client.Session.List(context.TODO(), option.WithResponseInto(&response))
246+
if err != nil {
250247
// handle error
251248
}
252-
fmt.Printf("%+v\n", events)
249+
fmt.Printf("%+v\n", sessions)
253250

254251
fmt.Printf("Status Code: %d\n", response.StatusCode)
255252
fmt.Printf("Headers: %+#v\n", response.Header)

client_test.go

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestUserAgentHeader(t *testing.T) {
3838
},
3939
}),
4040
)
41-
client.Event.ListStreaming(context.Background())
41+
client.Session.List(context.Background())
4242
if userAgent != fmt.Sprintf("Opencode/Go %s", internal.PackageVersion) {
4343
t.Errorf("Expected User-Agent to be correct, but got: %#v", userAgent)
4444
}
@@ -61,11 +61,7 @@ func TestRetryAfter(t *testing.T) {
6161
},
6262
}),
6363
)
64-
stream := client.Event.ListStreaming(context.Background())
65-
for stream.Next() {
66-
// ...
67-
}
68-
err := stream.Err()
64+
_, err := client.Session.List(context.Background())
6965
if err == nil {
7066
t.Error("Expected there to be a cancel error")
7167
}
@@ -99,11 +95,7 @@ func TestDeleteRetryCountHeader(t *testing.T) {
9995
}),
10096
option.WithHeaderDel("X-Stainless-Retry-Count"),
10197
)
102-
stream := client.Event.ListStreaming(context.Background())
103-
for stream.Next() {
104-
// ...
105-
}
106-
err := stream.Err()
98+
_, err := client.Session.List(context.Background())
10799
if err == nil {
108100
t.Error("Expected there to be a cancel error")
109101
}
@@ -132,11 +124,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
132124
}),
133125
option.WithHeader("X-Stainless-Retry-Count", "42"),
134126
)
135-
stream := client.Event.ListStreaming(context.Background())
136-
for stream.Next() {
137-
// ...
138-
}
139-
err := stream.Err()
127+
_, err := client.Session.List(context.Background())
140128
if err == nil {
141129
t.Error("Expected there to be a cancel error")
142130
}
@@ -164,11 +152,7 @@ func TestRetryAfterMs(t *testing.T) {
164152
},
165153
}),
166154
)
167-
stream := client.Event.ListStreaming(context.Background())
168-
for stream.Next() {
169-
// ...
170-
}
171-
err := stream.Err()
155+
_, err := client.Session.List(context.Background())
172156
if err == nil {
173157
t.Error("Expected there to be a cancel error")
174158
}
@@ -190,11 +174,7 @@ func TestContextCancel(t *testing.T) {
190174
)
191175
cancelCtx, cancel := context.WithCancel(context.Background())
192176
cancel()
193-
stream := client.Event.ListStreaming(cancelCtx)
194-
for stream.Next() {
195-
// ...
196-
}
197-
err := stream.Err()
177+
_, err := client.Session.List(cancelCtx)
198178
if err == nil {
199179
t.Error("Expected there to be a cancel error")
200180
}
@@ -213,11 +193,7 @@ func TestContextCancelDelay(t *testing.T) {
213193
)
214194
cancelCtx, cancel := context.WithTimeout(context.Background(), 2*time.Millisecond)
215195
defer cancel()
216-
stream := client.Event.ListStreaming(cancelCtx)
217-
for stream.Next() {
218-
// ...
219-
}
220-
err := stream.Err()
196+
_, err := client.Session.List(cancelCtx)
221197
if err == nil {
222198
t.Error("expected there to be a cancel error")
223199
}
@@ -242,11 +218,7 @@ func TestContextDeadline(t *testing.T) {
242218
},
243219
}),
244220
)
245-
stream := client.Event.ListStreaming(deadlineCtx)
246-
for stream.Next() {
247-
// ...
248-
}
249-
err := stream.Err()
221+
_, err := client.Session.List(deadlineCtx)
250222
if err == nil {
251223
t.Error("expected there to be a deadline error")
252224
}

usage_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ func TestUsage(t *testing.T) {
2323
client := opencode.NewClient(
2424
option.WithBaseURL(baseURL),
2525
)
26-
stream := client.Event.ListStreaming(context.TODO())
27-
for stream.Next() {
28-
t.Logf("%+v\n", stream.Current())
29-
}
30-
err := stream.Err()
26+
sessions, err := client.Session.List(context.TODO())
3127
if err != nil {
3228
t.Error(err)
3329
return
3430
}
31+
t.Logf("%+v\n", sessions)
3532
}

0 commit comments

Comments
 (0)