| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701 |
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
- package opencode
- import (
- "context"
- "net/http"
- "reflect"
- "github.com/sst/opencode-sdk-go/internal/apijson"
- "github.com/sst/opencode-sdk-go/internal/requestconfig"
- "github.com/sst/opencode-sdk-go/option"
- "github.com/tidwall/gjson"
- )
- // ConfigService contains methods and other services that help with interacting
- // with the opencode API.
- //
- // Note, unlike clients, this service does not read variables from the environment
- // automatically. You should not instantiate this service directly, and instead use
- // the [NewConfigService] method instead.
- type ConfigService struct {
- Options []option.RequestOption
- }
- // NewConfigService generates a new service that applies the given options to each
- // request. These options are applied after the parent client's options (if there
- // is one), and before any request-specific options.
- func NewConfigService(opts ...option.RequestOption) (r *ConfigService) {
- r = &ConfigService{}
- r.Options = opts
- return
- }
- // Get config info
- func (r *ConfigService) Get(ctx context.Context, opts ...option.RequestOption) (res *Config, err error) {
- opts = append(r.Options[:], opts...)
- path := "config"
- err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
- return
- }
- type Config struct {
- // JSON schema reference for configuration validation
- Schema string `json:"$schema"`
- // @deprecated Use 'share' field instead. Share newly created sessions
- // automatically
- Autoshare bool `json:"autoshare"`
- // Automatically update to the latest version
- Autoupdate bool `json:"autoupdate"`
- // Disable providers that are loaded automatically
- DisabledProviders []string `json:"disabled_providers"`
- Experimental ConfigExperimental `json:"experimental"`
- // Additional instruction files or patterns to include
- Instructions []string `json:"instructions"`
- // Custom keybind configurations
- Keybinds KeybindsConfig `json:"keybinds"`
- // Layout to use for the TUI
- Layout LayoutConfig `json:"layout"`
- // Minimum log level to write to log files
- LogLevel LogLevel `json:"log_level"`
- // MCP (Model Context Protocol) server configurations
- Mcp map[string]ConfigMcp `json:"mcp"`
- // Modes configuration, see https://opencode.ai/docs/modes
- Mode ConfigMode `json:"mode"`
- // Model to use in the format of provider/model, eg anthropic/claude-2
- Model string `json:"model"`
- // Custom provider configurations and model overrides
- Provider map[string]ConfigProvider `json:"provider"`
- // Control sharing behavior: 'auto' enables automatic sharing, 'disabled' disables
- // all sharing
- Share ConfigShare `json:"share"`
- // Theme name to use for the interface
- Theme string `json:"theme"`
- // Custom username to display in conversations instead of system username
- Username string `json:"username"`
- JSON configJSON `json:"-"`
- }
- // configJSON contains the JSON metadata for the struct [Config]
- type configJSON struct {
- Schema apijson.Field
- Autoshare apijson.Field
- Autoupdate apijson.Field
- DisabledProviders apijson.Field
- Experimental apijson.Field
- Instructions apijson.Field
- Keybinds apijson.Field
- Layout apijson.Field
- LogLevel apijson.Field
- Mcp apijson.Field
- Mode apijson.Field
- Model apijson.Field
- Provider apijson.Field
- Share apijson.Field
- Theme apijson.Field
- Username apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *Config) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configJSON) RawJSON() string {
- return r.raw
- }
- type ConfigExperimental struct {
- Hook ConfigExperimentalHook `json:"hook"`
- JSON configExperimentalJSON `json:"-"`
- }
- // configExperimentalJSON contains the JSON metadata for the struct
- // [ConfigExperimental]
- type configExperimentalJSON struct {
- Hook apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigExperimental) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configExperimentalJSON) RawJSON() string {
- return r.raw
- }
- type ConfigExperimentalHook struct {
- FileEdited map[string][]ConfigExperimentalHookFileEdited `json:"file_edited"`
- SessionCompleted []ConfigExperimentalHookSessionCompleted `json:"session_completed"`
- JSON configExperimentalHookJSON `json:"-"`
- }
- // configExperimentalHookJSON contains the JSON metadata for the struct
- // [ConfigExperimentalHook]
- type configExperimentalHookJSON struct {
- FileEdited apijson.Field
- SessionCompleted apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigExperimentalHook) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configExperimentalHookJSON) RawJSON() string {
- return r.raw
- }
- type ConfigExperimentalHookFileEdited struct {
- Command []string `json:"command,required"`
- Environment map[string]string `json:"environment"`
- JSON configExperimentalHookFileEditedJSON `json:"-"`
- }
- // configExperimentalHookFileEditedJSON contains the JSON metadata for the struct
- // [ConfigExperimentalHookFileEdited]
- type configExperimentalHookFileEditedJSON struct {
- Command apijson.Field
- Environment apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigExperimentalHookFileEdited) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configExperimentalHookFileEditedJSON) RawJSON() string {
- return r.raw
- }
- type ConfigExperimentalHookSessionCompleted struct {
- Command []string `json:"command,required"`
- Environment map[string]string `json:"environment"`
- JSON configExperimentalHookSessionCompletedJSON `json:"-"`
- }
- // configExperimentalHookSessionCompletedJSON contains the JSON metadata for the
- // struct [ConfigExperimentalHookSessionCompleted]
- type configExperimentalHookSessionCompletedJSON struct {
- Command apijson.Field
- Environment apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigExperimentalHookSessionCompleted) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configExperimentalHookSessionCompletedJSON) RawJSON() string {
- return r.raw
- }
- type ConfigMcp struct {
- // Type of MCP server connection
- Type ConfigMcpType `json:"type,required"`
- // This field can have the runtime type of [[]string].
- Command interface{} `json:"command"`
- // Enable or disable the MCP server on startup
- Enabled bool `json:"enabled"`
- // This field can have the runtime type of [map[string]string].
- Environment interface{} `json:"environment"`
- // URL of the remote MCP server
- URL string `json:"url"`
- JSON configMcpJSON `json:"-"`
- union ConfigMcpUnion
- }
- // configMcpJSON contains the JSON metadata for the struct [ConfigMcp]
- type configMcpJSON struct {
- Type apijson.Field
- Command apijson.Field
- Enabled apijson.Field
- Environment apijson.Field
- URL apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r configMcpJSON) RawJSON() string {
- return r.raw
- }
- func (r *ConfigMcp) UnmarshalJSON(data []byte) (err error) {
- *r = ConfigMcp{}
- err = apijson.UnmarshalRoot(data, &r.union)
- if err != nil {
- return err
- }
- return apijson.Port(r.union, &r)
- }
- // AsUnion returns a [ConfigMcpUnion] interface which you can cast to the specific
- // types for more type safety.
- //
- // Possible runtime types of the union are [McpLocalConfig], [McpRemoteConfig].
- func (r ConfigMcp) AsUnion() ConfigMcpUnion {
- return r.union
- }
- // Union satisfied by [McpLocalConfig] or [McpRemoteConfig].
- type ConfigMcpUnion interface {
- implementsConfigMcp()
- }
- func init() {
- apijson.RegisterUnion(
- reflect.TypeOf((*ConfigMcpUnion)(nil)).Elem(),
- "type",
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(McpLocalConfig{}),
- DiscriminatorValue: "local",
- },
- apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(McpRemoteConfig{}),
- DiscriminatorValue: "remote",
- },
- )
- }
- // Type of MCP server connection
- type ConfigMcpType string
- const (
- ConfigMcpTypeLocal ConfigMcpType = "local"
- ConfigMcpTypeRemote ConfigMcpType = "remote"
- )
- func (r ConfigMcpType) IsKnown() bool {
- switch r {
- case ConfigMcpTypeLocal, ConfigMcpTypeRemote:
- return true
- }
- return false
- }
- // Modes configuration, see https://opencode.ai/docs/modes
- type ConfigMode struct {
- Build ModeConfig `json:"build"`
- Plan ModeConfig `json:"plan"`
- ExtraFields map[string]ModeConfig `json:"-,extras"`
- JSON configModeJSON `json:"-"`
- }
- // configModeJSON contains the JSON metadata for the struct [ConfigMode]
- type configModeJSON struct {
- Build apijson.Field
- Plan apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigMode) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configModeJSON) RawJSON() string {
- return r.raw
- }
- type ConfigProvider struct {
- Models map[string]ConfigProviderModel `json:"models,required"`
- ID string `json:"id"`
- API string `json:"api"`
- Env []string `json:"env"`
- Name string `json:"name"`
- Npm string `json:"npm"`
- Options map[string]interface{} `json:"options"`
- JSON configProviderJSON `json:"-"`
- }
- // configProviderJSON contains the JSON metadata for the struct [ConfigProvider]
- type configProviderJSON struct {
- Models apijson.Field
- ID apijson.Field
- API apijson.Field
- Env apijson.Field
- Name apijson.Field
- Npm apijson.Field
- Options apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigProvider) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configProviderJSON) RawJSON() string {
- return r.raw
- }
- type ConfigProviderModel struct {
- ID string `json:"id"`
- Attachment bool `json:"attachment"`
- Cost ConfigProviderModelsCost `json:"cost"`
- Limit ConfigProviderModelsLimit `json:"limit"`
- Name string `json:"name"`
- Options map[string]interface{} `json:"options"`
- Reasoning bool `json:"reasoning"`
- ReleaseDate string `json:"release_date"`
- Temperature bool `json:"temperature"`
- ToolCall bool `json:"tool_call"`
- JSON configProviderModelJSON `json:"-"`
- }
- // configProviderModelJSON contains the JSON metadata for the struct
- // [ConfigProviderModel]
- type configProviderModelJSON struct {
- ID apijson.Field
- Attachment apijson.Field
- Cost apijson.Field
- Limit apijson.Field
- Name apijson.Field
- Options apijson.Field
- Reasoning apijson.Field
- ReleaseDate apijson.Field
- Temperature apijson.Field
- ToolCall apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigProviderModel) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configProviderModelJSON) RawJSON() string {
- return r.raw
- }
- type ConfigProviderModelsCost struct {
- Input float64 `json:"input,required"`
- Output float64 `json:"output,required"`
- CacheRead float64 `json:"cache_read"`
- CacheWrite float64 `json:"cache_write"`
- JSON configProviderModelsCostJSON `json:"-"`
- }
- // configProviderModelsCostJSON contains the JSON metadata for the struct
- // [ConfigProviderModelsCost]
- type configProviderModelsCostJSON struct {
- Input apijson.Field
- Output apijson.Field
- CacheRead apijson.Field
- CacheWrite apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigProviderModelsCost) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configProviderModelsCostJSON) RawJSON() string {
- return r.raw
- }
- type ConfigProviderModelsLimit struct {
- Context float64 `json:"context,required"`
- Output float64 `json:"output,required"`
- JSON configProviderModelsLimitJSON `json:"-"`
- }
- // configProviderModelsLimitJSON contains the JSON metadata for the struct
- // [ConfigProviderModelsLimit]
- type configProviderModelsLimitJSON struct {
- Context apijson.Field
- Output apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ConfigProviderModelsLimit) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r configProviderModelsLimitJSON) RawJSON() string {
- return r.raw
- }
- // Control sharing behavior: 'auto' enables automatic sharing, 'disabled' disables
- // all sharing
- type ConfigShare string
- const (
- ConfigShareAuto ConfigShare = "auto"
- ConfigShareDisabled ConfigShare = "disabled"
- )
- func (r ConfigShare) IsKnown() bool {
- switch r {
- case ConfigShareAuto, ConfigShareDisabled:
- return true
- }
- return false
- }
- type KeybindsConfig struct {
- // Exit the application
- AppExit string `json:"app_exit,required"`
- // Show help dialog
- AppHelp string `json:"app_help,required"`
- // Open external editor
- EditorOpen string `json:"editor_open,required"`
- // Close file
- FileClose string `json:"file_close,required"`
- // Split/unified diff
- FileDiffToggle string `json:"file_diff_toggle,required"`
- // List files
- FileList string `json:"file_list,required"`
- // Search file
- FileSearch string `json:"file_search,required"`
- // Clear input field
- InputClear string `json:"input_clear,required"`
- // Insert newline in input
- InputNewline string `json:"input_newline,required"`
- // Paste from clipboard
- InputPaste string `json:"input_paste,required"`
- // Submit input
- InputSubmit string `json:"input_submit,required"`
- // Leader key for keybind combinations
- Leader string `json:"leader,required"`
- // Copy message
- MessagesCopy string `json:"messages_copy,required"`
- // Navigate to first message
- MessagesFirst string `json:"messages_first,required"`
- // Scroll messages down by half page
- MessagesHalfPageDown string `json:"messages_half_page_down,required"`
- // Scroll messages up by half page
- MessagesHalfPageUp string `json:"messages_half_page_up,required"`
- // Navigate to last message
- MessagesLast string `json:"messages_last,required"`
- // Toggle layout
- MessagesLayoutToggle string `json:"messages_layout_toggle,required"`
- // Navigate to next message
- MessagesNext string `json:"messages_next,required"`
- // Scroll messages down by one page
- MessagesPageDown string `json:"messages_page_down,required"`
- // Scroll messages up by one page
- MessagesPageUp string `json:"messages_page_up,required"`
- // Navigate to previous message
- MessagesPrevious string `json:"messages_previous,required"`
- // Revert message
- MessagesRevert string `json:"messages_revert,required"`
- // List available models
- ModelList string `json:"model_list,required"`
- // Create/update AGENTS.md
- ProjectInit string `json:"project_init,required"`
- // Compact the session
- SessionCompact string `json:"session_compact,required"`
- // Export session to editor
- SessionExport string `json:"session_export,required"`
- // Interrupt current session
- SessionInterrupt string `json:"session_interrupt,required"`
- // List all sessions
- SessionList string `json:"session_list,required"`
- // Create a new session
- SessionNew string `json:"session_new,required"`
- // Share current session
- SessionShare string `json:"session_share,required"`
- // Unshare current session
- SessionUnshare string `json:"session_unshare,required"`
- // Switch mode
- SwitchMode string `json:"switch_mode,required"`
- // Switch mode reverse
- SwitchModeReverse string `json:"switch_mode_reverse,required"`
- // List available themes
- ThemeList string `json:"theme_list,required"`
- // Toggle tool details
- ToolDetails string `json:"tool_details,required"`
- JSON keybindsConfigJSON `json:"-"`
- }
- // keybindsConfigJSON contains the JSON metadata for the struct [KeybindsConfig]
- type keybindsConfigJSON struct {
- AppExit apijson.Field
- AppHelp apijson.Field
- EditorOpen apijson.Field
- FileClose apijson.Field
- FileDiffToggle apijson.Field
- FileList apijson.Field
- FileSearch apijson.Field
- InputClear apijson.Field
- InputNewline apijson.Field
- InputPaste apijson.Field
- InputSubmit apijson.Field
- Leader apijson.Field
- MessagesCopy apijson.Field
- MessagesFirst apijson.Field
- MessagesHalfPageDown apijson.Field
- MessagesHalfPageUp apijson.Field
- MessagesLast apijson.Field
- MessagesLayoutToggle apijson.Field
- MessagesNext apijson.Field
- MessagesPageDown apijson.Field
- MessagesPageUp apijson.Field
- MessagesPrevious apijson.Field
- MessagesRevert apijson.Field
- ModelList apijson.Field
- ProjectInit apijson.Field
- SessionCompact apijson.Field
- SessionExport apijson.Field
- SessionInterrupt apijson.Field
- SessionList apijson.Field
- SessionNew apijson.Field
- SessionShare apijson.Field
- SessionUnshare apijson.Field
- SwitchMode apijson.Field
- SwitchModeReverse apijson.Field
- ThemeList apijson.Field
- ToolDetails apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *KeybindsConfig) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r keybindsConfigJSON) RawJSON() string {
- return r.raw
- }
- type LayoutConfig string
- const (
- LayoutConfigAuto LayoutConfig = "auto"
- LayoutConfigStretch LayoutConfig = "stretch"
- )
- func (r LayoutConfig) IsKnown() bool {
- switch r {
- case LayoutConfigAuto, LayoutConfigStretch:
- return true
- }
- return false
- }
- type McpLocalConfig struct {
- // Command and arguments to run the MCP server
- Command []string `json:"command,required"`
- // Type of MCP server connection
- Type McpLocalConfigType `json:"type,required"`
- // Enable or disable the MCP server on startup
- Enabled bool `json:"enabled"`
- // Environment variables to set when running the MCP server
- Environment map[string]string `json:"environment"`
- JSON mcpLocalConfigJSON `json:"-"`
- }
- // mcpLocalConfigJSON contains the JSON metadata for the struct [McpLocalConfig]
- type mcpLocalConfigJSON struct {
- Command apijson.Field
- Type apijson.Field
- Enabled apijson.Field
- Environment apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *McpLocalConfig) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r mcpLocalConfigJSON) RawJSON() string {
- return r.raw
- }
- func (r McpLocalConfig) implementsConfigMcp() {}
- // Type of MCP server connection
- type McpLocalConfigType string
- const (
- McpLocalConfigTypeLocal McpLocalConfigType = "local"
- )
- func (r McpLocalConfigType) IsKnown() bool {
- switch r {
- case McpLocalConfigTypeLocal:
- return true
- }
- return false
- }
- type McpRemoteConfig struct {
- // Type of MCP server connection
- Type McpRemoteConfigType `json:"type,required"`
- // URL of the remote MCP server
- URL string `json:"url,required"`
- // Enable or disable the MCP server on startup
- Enabled bool `json:"enabled"`
- JSON mcpRemoteConfigJSON `json:"-"`
- }
- // mcpRemoteConfigJSON contains the JSON metadata for the struct [McpRemoteConfig]
- type mcpRemoteConfigJSON struct {
- Type apijson.Field
- URL apijson.Field
- Enabled apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *McpRemoteConfig) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r mcpRemoteConfigJSON) RawJSON() string {
- return r.raw
- }
- func (r McpRemoteConfig) implementsConfigMcp() {}
- // Type of MCP server connection
- type McpRemoteConfigType string
- const (
- McpRemoteConfigTypeRemote McpRemoteConfigType = "remote"
- )
- func (r McpRemoteConfigType) IsKnown() bool {
- switch r {
- case McpRemoteConfigTypeRemote:
- return true
- }
- return false
- }
- type ModeConfig struct {
- Model string `json:"model"`
- Prompt string `json:"prompt"`
- Tools map[string]bool `json:"tools"`
- JSON modeConfigJSON `json:"-"`
- }
- // modeConfigJSON contains the JSON metadata for the struct [ModeConfig]
- type modeConfigJSON struct {
- Model apijson.Field
- Prompt apijson.Field
- Tools apijson.Field
- raw string
- ExtraFields map[string]apijson.Field
- }
- func (r *ModeConfig) UnmarshalJSON(data []byte) (err error) {
- return apijson.UnmarshalRoot(data, r)
- }
- func (r modeConfigJSON) RawJSON() string {
- return r.raw
- }
|