Refactor to support multiple instances inside single opencode process (#2360)
This release has a bunch of minor breaking changes if you are using opencode plugins or sdk 1. storage events have been removed (we might bring this back but had some issues) 2. concept of `app` is gone - there is a new concept called `project` and endpoints to list projects and get the current project 3. plugin receives `directory` which is cwd and `worktree` which is where the root of the project is if it's a git repo 4. the session.chat function has been renamed to session.prompt in sdk. it no longer requires model to be passed in (model is now an object) 5. every endpoint takes an optional `directory` parameter to operate as though opencode is running in that directory
This commit is contained in:
@@ -24,7 +24,7 @@ Or to pin the version:
|
||||
<!-- x-release-please-start-version -->
|
||||
|
||||
```sh
|
||||
go get -u 'github.com/sst/opencode-sdk-go@v0.1.0-alpha.8'
|
||||
go get -u 'github.com/sst/opencode-sdk-go@v0.8.0'
|
||||
```
|
||||
|
||||
<!-- x-release-please-end -->
|
||||
@@ -49,7 +49,7 @@ import (
|
||||
|
||||
func main() {
|
||||
client := opencode.NewClient()
|
||||
sessions, err := client.Session.List(context.TODO())
|
||||
sessions, err := client.Session.List(context.TODO(), opencode.SessionListParams{})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
@@ -171,7 +171,7 @@ When the API returns a non-success status code, we return an error with type
|
||||
To handle errors, we recommend that you use the `errors.As` pattern:
|
||||
|
||||
```go
|
||||
_, err := client.Session.List(context.TODO())
|
||||
_, err := client.Session.List(context.TODO(), opencode.SessionListParams{})
|
||||
if err != nil {
|
||||
var apierr *opencode.Error
|
||||
if errors.As(err, &apierr) {
|
||||
@@ -198,6 +198,7 @@ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
defer cancel()
|
||||
client.Session.List(
|
||||
ctx,
|
||||
opencode.SessionListParams{},
|
||||
// This sets the per-retry timeout
|
||||
option.WithRequestTimeout(20*time.Second),
|
||||
)
|
||||
@@ -231,7 +232,11 @@ client := opencode.NewClient(
|
||||
)
|
||||
|
||||
// Override per-request:
|
||||
client.Session.List(context.TODO(), option.WithMaxRetries(5))
|
||||
client.Session.List(
|
||||
context.TODO(),
|
||||
opencode.SessionListParams{},
|
||||
option.WithMaxRetries(5),
|
||||
)
|
||||
```
|
||||
|
||||
### Accessing raw response data (e.g. response headers)
|
||||
@@ -242,7 +247,11 @@ you need to examine response headers, status codes, or other details.
|
||||
```go
|
||||
// Create a variable to store the HTTP response
|
||||
var response *http.Response
|
||||
sessions, err := client.Session.List(context.TODO(), option.WithResponseInto(&response))
|
||||
sessions, err := client.Session.List(
|
||||
context.TODO(),
|
||||
opencode.SessionListParams{},
|
||||
option.WithResponseInto(&response),
|
||||
)
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user