mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-19 00:34:23 +01:00
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:
@@ -5,11 +5,15 @@ package opencode
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
||||
"github.com/sst/opencode-sdk-go/internal/apijson"
|
||||
"github.com/sst/opencode-sdk-go/internal/apiquery"
|
||||
"github.com/sst/opencode-sdk-go/internal/param"
|
||||
"github.com/sst/opencode-sdk-go/internal/requestconfig"
|
||||
"github.com/sst/opencode-sdk-go/option"
|
||||
"github.com/sst/opencode-sdk-go/shared"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
@@ -33,10 +37,10 @@ func NewConfigService(opts ...option.RequestOption) (r *ConfigService) {
|
||||
}
|
||||
|
||||
// Get config info
|
||||
func (r *ConfigService) Get(ctx context.Context, opts ...option.RequestOption) (res *Config, err error) {
|
||||
func (r *ConfigService) Get(ctx context.Context, query ConfigGetParams, opts ...option.RequestOption) (res *Config, err error) {
|
||||
opts = append(r.Options[:], opts...)
|
||||
path := "config"
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
|
||||
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,8 +53,9 @@ type Config struct {
|
||||
// automatically
|
||||
Autoshare bool `json:"autoshare"`
|
||||
// Automatically update to the latest version
|
||||
Autoupdate bool `json:"autoupdate"`
|
||||
Command map[string]ConfigCommand `json:"command"`
|
||||
Autoupdate bool `json:"autoupdate"`
|
||||
// Command configuration, see https://opencode.ai/docs/commands
|
||||
Command map[string]ConfigCommand `json:"command"`
|
||||
// Disable providers that are loaded automatically
|
||||
DisabledProviders []string `json:"disabled_providers"`
|
||||
Experimental ConfigExperimental `json:"experimental"`
|
||||
@@ -1646,10 +1651,13 @@ func (r configProviderModelsLimitJSON) RawJSON() string {
|
||||
}
|
||||
|
||||
type ConfigProviderOptions struct {
|
||||
APIKey string `json:"apiKey"`
|
||||
BaseURL string `json:"baseURL"`
|
||||
ExtraFields map[string]interface{} `json:"-,extras"`
|
||||
JSON configProviderOptionsJSON `json:"-"`
|
||||
APIKey string `json:"apiKey"`
|
||||
BaseURL string `json:"baseURL"`
|
||||
// Timeout in milliseconds for requests to this provider. Default is 300000 (5
|
||||
// minutes). Set to false to disable timeout.
|
||||
Timeout ConfigProviderOptionsTimeoutUnion `json:"timeout"`
|
||||
ExtraFields map[string]interface{} `json:"-,extras"`
|
||||
JSON configProviderOptionsJSON `json:"-"`
|
||||
}
|
||||
|
||||
// configProviderOptionsJSON contains the JSON metadata for the struct
|
||||
@@ -1657,6 +1665,7 @@ type ConfigProviderOptions struct {
|
||||
type configProviderOptionsJSON struct {
|
||||
APIKey apijson.Field
|
||||
BaseURL apijson.Field
|
||||
Timeout apijson.Field
|
||||
raw string
|
||||
ExtraFields map[string]apijson.Field
|
||||
}
|
||||
@@ -1669,6 +1678,33 @@ func (r configProviderOptionsJSON) RawJSON() string {
|
||||
return r.raw
|
||||
}
|
||||
|
||||
// Timeout in milliseconds for requests to this provider. Default is 300000 (5
|
||||
// minutes). Set to false to disable timeout.
|
||||
//
|
||||
// Union satisfied by [shared.UnionInt] or [shared.UnionBool].
|
||||
type ConfigProviderOptionsTimeoutUnion interface {
|
||||
ImplementsConfigProviderOptionsTimeoutUnion()
|
||||
}
|
||||
|
||||
func init() {
|
||||
apijson.RegisterUnion(
|
||||
reflect.TypeOf((*ConfigProviderOptionsTimeoutUnion)(nil)).Elem(),
|
||||
"",
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.Number,
|
||||
Type: reflect.TypeOf(shared.UnionInt(0)),
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.True,
|
||||
Type: reflect.TypeOf(shared.UnionBool(false)),
|
||||
},
|
||||
apijson.UnionVariant{
|
||||
TypeFilter: gjson.False,
|
||||
Type: reflect.TypeOf(shared.UnionBool(false)),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Control sharing behavior:'manual' allows manual sharing via commands, 'auto'
|
||||
// enables automatic sharing, 'disabled' disables all sharing
|
||||
type ConfigShare string
|
||||
@@ -1967,3 +2003,15 @@ func (r McpRemoteConfigType) IsKnown() bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type ConfigGetParams struct {
|
||||
Directory param.Field[string] `query:"directory"`
|
||||
}
|
||||
|
||||
// URLQuery serializes [ConfigGetParams]'s query parameters as `url.Values`.
|
||||
func (r ConfigGetParams) URLQuery() (v url.Values) {
|
||||
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
|
||||
ArrayFormat: apiquery.ArrayQueryFormatComma,
|
||||
NestedFormat: apiquery.NestedQueryFormatBrackets,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user