### Get Request with Client Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Makes a GET request using the client. It accepts context, path, parameters, a response interface, and optional request options. Refer to the Execute documentation for details on params and response handling. ```go func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error ``` -------------------------------- ### StepStartPart Structure Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Represents the start of a step. ```go type StepStartPart struct { ID string `json:"id,required"` MessageID string `json:"messageID,required"` SessionID string `json:"sessionID,required"` Type StepStartPartType `json:"type,required"` Snapshot string `json:"snapshot"` JSON stepStartPartJSON `json:"-"` } ``` -------------------------------- ### EventListResponseEventInstallationUpdatedType Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the type for the installation updated event. ```APIDOC ## EventListResponseEventInstallationUpdatedType ### Description Defines the type for the installation updated event. ### Constants - **InstallationUpdated**: `"installation.updated"` ### Methods #### IsKnown ```go func (r EventListResponseEventInstallationUpdatedType) IsKnown() bool ``` ``` -------------------------------- ### Define EventListResponseEventIdeInstalledType Constant Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the constant for the 'ide.installed' event type. Use this type to identify specific installation events. ```go const ( EventListResponseEventIdeInstalledTypeIdeInstalled EventListResponseEventIdeInstalledType = "ide.installed" ) ``` -------------------------------- ### ConfigService Get Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves configuration information using the ConfigService. Requires a context, query parameters, and optional request options. ```go func (r *ConfigService) Get(ctx context.Context, query ConfigGetParams, opts ...option.RequestOption) (res *Config, err error) ``` -------------------------------- ### ProjectService.Current Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Get the current project. ```APIDOC ## ProjectService.Current ### Description Get the current project. ### Signature ```go func (r *ProjectService) Current(ctx context.Context, query ProjectCurrentParams, opts ...option.RequestOption) (res *Project, err error) ``` ``` -------------------------------- ### Get Current Project Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves the current project details. Requires context, project parameters, and optional request options. ```go func (r *ProjectService) Current(ctx context.Context, query ProjectCurrentParams, opts ...option.RequestOption) (res *Project, err error) ``` -------------------------------- ### Define EventListResponseEventInstallationUpdatedType Constant Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the constant for the 'installation.updated' event type. Use this to identify updates to installations. ```go const ( EventListResponseEventInstallationUpdatedTypeInstallationUpdated EventListResponseEventInstallationUpdatedType = "installation.updated" ) ``` -------------------------------- ### EventListResponseEventIdeInstalled Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Represents an event triggered when an IDE is installed. This event type is available starting from v0.16.0. ```APIDOC ## EventListResponseEventIdeInstalled ### Description Represents an event triggered when an IDE is installed. This event is available in v0.16.0 and later. ### Method N/A (Type definition only) ### Endpoint N/A ### Parameters None ### Request Example None ### Response #### Success Response (N/A) Represents the structure of an IDE installed event. #### Response Example None ``` -------------------------------- ### StepStartPart Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Represents the start of a step, including ID, message ID, session ID, and type. ```APIDOC ## StepStartPart ### Description Represents the start of a step. ### Type Definition ```go type StepStartPart struct { ID string `json:"id,required"` MessageID string `json:"messageID,required"` SessionID string `json:"sessionID,required"` Type StepStartPartType `json:"type,required"` Snapshot string `json:"snapshot"` JSON stepStartPartJSON `json:"-"` } ``` ### Methods #### UnmarshalJSON ```go func (r *StepStartPart) UnmarshalJSON(data []byte) (err error) ``` ``` -------------------------------- ### Client.Get Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Makes a GET request with the given URL, parameters, and optionally deserializes the response. ```APIDOC ## GET ### Description Makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response. ### Method GET ### Endpoint [path] ### Parameters #### Path Parameters - **path** (string) - Required - The URL path for the GET request. #### Query Parameters - **params** (interface{}) - Optional - Parameters for the request, which can be serialized to query strings if `URLQuery` method is implemented. #### Request Body None ### Response - **res** (interface{}) - The response object, deserialized based on its type. ### Options - **opts** (...option.RequestOption) - Optional request configurations. ``` -------------------------------- ### StepStartPartType Structure Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines a type for step start parts. ```go type StepStartPartType string ``` -------------------------------- ### ConfigGetParams Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines parameters for getting configuration, including a directory field. ```go type ConfigGetParams struct { Directory param.Field[string] } ``` -------------------------------- ### PathService Get Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves the current path information using provided context and parameters. Added in v0.4.0. ```go func (r *PathService) Get(ctx context.Context, query PathGetParams, opts ...option.RequestOption) (res *Path, err error) ``` -------------------------------- ### ReasoningPartTime Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the ReasoningPartTime structure, including start and end times. ```go type ReasoningPartTime struct { Start float64 `json:"start,required"` End float64 `json:"end"` JSON reasoningPartTimeJSON `json:"-"` } ``` -------------------------------- ### EventListResponseEventInstallationUpdated Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Represents an event triggered when an installation is updated. It includes properties like the version and the event type. ```APIDOC ## EventListResponseEventInstallationUpdated ### Description Represents an event triggered when an installation is updated. It includes properties like the version and the event type. ### Properties EventListResponseEventInstallationUpdatedProperties ### Type EventListResponseEventInstallationUpdatedType ### JSON eventListResponseEventInstallationUpdatedJSON ### Methods #### UnmarshalJSON ```go func (r *EventListResponseEventInstallationUpdated) UnmarshalJSON(data []byte) (err error) ``` ``` -------------------------------- ### EventListResponseEventIdeInstalled Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Represents an event triggered when an IDE is installed. It includes the type of event and associated JSON data. ```APIDOC ## EventListResponseEventIdeInstalled ### Description Represents an event triggered when an IDE is installed. It includes the type of event and associated JSON data. ### Type EventListResponseEventIdeInstalledType ### JSON eventListResponseEventIdeInstalledJSON ### Methods #### UnmarshalJSON ```go func (r *EventListResponseEventIdeInstalled) UnmarshalJSON(data []byte) (err error) ``` ``` -------------------------------- ### Create New Client with Default Options Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new client instance, applying default options from the environment and any provided options. ```go func NewClient(opts ...option.RequestOption) (r *Client) NewClient generates a new client with the default option read from the environment (OPENCODE_BASE_URL). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes. ``` -------------------------------- ### Opencode Client Initialization and Session List Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Demonstrates how to initialize the Opencode client and list sessions using the SDK. ```APIDOC ## Opencode Go API Library The Opencode Go library provides convenient access to the Opencode REST API from applications written in Go. #### Installation ```go import ( "github.com/sst/opencode-sdk-go" // imported as opencode ) ``` Or to pin the version: ```go go get -u 'github.com/sst/opencode-sdk-go@v0.19.2' ``` #### Requirements This library requires Go 1.22+. #### Usage ```go package main import ( "context" "fmt" "github.com/sst/opencode-sdk-go" ) func main() { client := opencode.NewClient() sessions, err := client.Session.List(context.TODO(), opencode.SessionListParams{}) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", sessions) } ``` ##### Request fields All request parameters are wrapped in a generic `Field` type, which we use to distinguish zero values from null or omitted fields. This prevents accidentally sending a zero value if you forget a required parameter, and enables explicitly sending `null`, `false`, `''`, or `0` on optional parameters. Any field not specified is not sent. To construct fields with values, use the helpers `String()`, `Int()`, `Float()`, or most commonly, the generic `F[T]()`. To send a null, use `Null[T]()`, and to send a nonconforming value, use `Raw[T](any)`. For example: ```go params := FooParams{ Name: opencode.F("hello"), // Explicitly send `"description": null` Description: opencode.Null[string]() Point: opencode.F(opencode.Point{ X: opencode.Int(0), Y: opencode.Int(1), // In cases where the API specifies a given type, // but you want to send something else, use `Raw`: Z: opencode.Raw[int64](0.01), // sends a float }), } ``` ##### Response objects All fields in response structs are value types (not pointers or wrappers). If a given field is `null`, not present, or invalid, the corresponding field will simply be its zero value. All response structs also include a special `JSON` field, containing more detailed information about each property, which you can use like so: ```go if res.Name == "" { // true if `"name"` is either not present or explicitly null res.JSON.Name.IsNull() // true if the `"name"` key was not present in the response JSON at all res.JSON.Name.IsMissing() // When the API returns data that cannot be coerced to the expected type: if res.JSON.Name.IsInvalid() { raw := res.JSON.Name.Raw() legacyName := struct{ First string `json:"first"` Last string `json:"last"` }{} json.Unmarshal([]byte(raw), &legacyName) name = legacyName.First + " " + legacyName.Last } } ``` These `.JSON` structs also include an `Extras` map containing any properties in the json response that were not specified in the struct. This can be useful for API features not yet present in the SDK. ```go body := res.JSON.ExtraFields["my_unexpected_field"].Raw() ``` ##### RequestOptions This library uses the functional options pattern. Functions defined in the `option` package return a `RequestOption`, which is a closure that mutates a `RequestConfig`. These options can be supplied to the client or at individual requests. For example: ```go client := opencode.NewClient( // Adds a header to every request made by the client option.WithHeader("X-Some-Header", "custom_header_info"), ) client.Session.List(context.TODO(), ..., // Override the header option.WithHeader("X-Some-Header", "some_other_custom_header_info"), // Add an undocumented field to the request body, using sjson syntax option.WithJSONSet("some.json.path", map[string]string{"my": "object"}), ) ``` See the full list of request options. ##### Pagination This library provides some conveniences for working with paginated list endpoints. You can use `.ListAutoPaging()` methods to iterate through items across all pages: Or you can use simple `.List()` methods to fetch a single page and receive a standard response object with additional helper methods like `.GetNextPage()`, e.g.: ``` -------------------------------- ### Init Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Analyzes the app and creates an AGENTS.md file for a session. ```APIDOC ## Init ### Description Analyze the app and create an AGENTS.md file ### Signature ```go func (r *SessionService) Init(ctx context.Context, id string, params SessionInitParams, opts ...option.RequestOption) (res *bool, err error) ``` ``` -------------------------------- ### Get Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves a specific session by its ID. ```APIDOC ## Get ### Description Get session ### Signature ```go func (r *SessionService) Get(ctx context.Context, id string, query SessionGetParams, opts ...option.RequestOption) (res *Session, err error) ``` ``` -------------------------------- ### Default Client Options Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Reads client options from the environment (OPENCODE_BASE_URL). Use this to initialize new clients. ```go func DefaultClientOptions() []option.RequestOption ``` -------------------------------- ### Session Service Init Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Initializes a session by analyzing the app and creating an AGENTS.md file. This is used to set up a session for agent interaction. ```go func (r *SessionService) Init(ctx context.Context, id string, params SessionInitParams, opts ...option.RequestOption) (res *bool, err error) ``` -------------------------------- ### EventListResponseEventIdeInstalledType Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the type for the IDE installed event. ```APIDOC ## EventListResponseEventIdeInstalledType ### Description Defines the type for the IDE installed event. ### Constants - **IdeInstalled**: `"ide.installed"` ### Methods #### IsKnown ```go func (r EventListResponseEventIdeInstalledType) IsKnown() bool ``` ``` -------------------------------- ### Configuring Opencode Client with Request Options Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Illustrates how to configure the Opencode client and individual requests using the functional options pattern, such as adding headers or setting JSON fields. ```go client := opencode.NewClient( // Adds a header to every request made by the client option.WithHeader("X-Some-Header", "custom_header_info"), ) client.Session.List(context.TODO(), ..., // Override the header option.WithHeader("X-Some-Header", "some_other_custom_header_info"), // Add an undocumented field to the request body, using sjson syntax option.WithJSONSet("some.json.path", map[string]string{"my": "object"}), ) ``` -------------------------------- ### SymbolSourceRangeStart Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the SymbolSourceRangeStart structure, representing the start of a symbol source range with character and line details. It includes an ignored JSON field. ```go type SymbolSourceRangeStart struct { Character float64 `json:"character,required" Line float64 `json:"line,required" JSON symbolSourceRangeStartJSON `json:"-" } ``` -------------------------------- ### SessionGetParams Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Parameters for getting a session. Supports an optional Directory. ```APIDOC ## SessionGetParams ### Description Parameters for getting a session. Supports an optional Directory. ### Fields - **Directory** (string) - Optional - The directory of the session to retrieve. ``` -------------------------------- ### TuiService OpenHelp Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Opens the help dialog in the TUI. Requires a context, TuiOpenHelpParams, and optional request options. ```go func (r *TuiService) OpenHelp(ctx context.Context, body TuiOpenHelpParams, opts ...option.RequestOption) (res *bool, err error) ``` -------------------------------- ### Define EventListResponseEventInstallationUpdatedProperties Struct Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the properties for the EventListResponseEventInstallationUpdated struct, including the updated version. This struct holds specific details about installation updates. ```go type EventListResponseEventInstallationUpdatedProperties struct { Version string `json:"version,required"` JSON eventListResponseEventInstallationUpdatedPropertiesJSON `json:"-"` } ``` -------------------------------- ### Basic Opencode API Client Usage Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Initialize the Opencode client and make a basic API call to list sessions. Handles potential errors and prints the session data. ```go package main import ( "context" "fmt" "github.com/sst/opencode-sdk-go" ) func main() { client := opencode.NewClient() sessions, err := client.Session.List(context.TODO(), opencode.SessionListParams{}) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", sessions) } ``` -------------------------------- ### Post Request with Client Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Makes a POST request using the client. It accepts context, path, parameters, a response interface, and optional request options. Refer to the Execute documentation for details on params and response handling. ```go func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error ``` -------------------------------- ### Define SessionGetParams Type Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines parameters for getting a session, including the directory. ```go type SessionGetParams struct { Directory param.Field[string] `query:"directory"` } ``` -------------------------------- ### List All Projects Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves a list of all projects. Requires context, project list parameters, and optional request options. ```go func (r *ProjectService) List(ctx context.Context, query ProjectListParams, opts ...option.RequestOption) (res *[]Project, err error) ``` -------------------------------- ### StepStartPartType Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the type of a step start part, with a known constant for 'step-start'. ```APIDOC ## StepStartPartType ### Description Defines the type of a step start part. ### Type Definition ```go type StepStartPartType string ``` ### Constants ```go const ( StepStartPartTypeStepStart StepStartPartType = "step-start" ) ``` ### Methods #### IsKnown ```go func (r StepStartPartType) IsKnown() bool ``` ``` -------------------------------- ### Pin Opencode Go SDK Version Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Pin the specific version of the Opencode Go SDK using go get. This ensures reproducible builds by locking to a particular version. ```go go get -u 'github.com/sst/opencode-sdk-go@v0.19.2' ``` -------------------------------- ### StepStartPartType Constant Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the constant value for a step start part type. ```go const ( StepStartPartTypeStepStart StepStartPartType = "step-start" ) ``` -------------------------------- ### Initialize New Project Service Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new service for interacting with the Opencode API. Options are applied after client options and before request-specific options. ```go func NewProjectService(opts ...option.RequestOption) (r *ProjectService) ``` -------------------------------- ### Constructing Request Fields with Field Wrappers Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Demonstrates how to use Field wrappers (F, Null, Raw) to construct request parameters, distinguishing zero values from null/omitted fields and handling type coercion. ```go params := FooParams{ Name: opencode.F("hello"), // Explicitly send "description": null Description: opencode.Null[string]() , Point: opencode.F(opencode.Point{ X: opencode.Int(0), Y: opencode.Int(1), // In cases where the API specifies a given type, // but you want to send something else, use `Raw`: Z: opencode.Raw[int64](0.01), // sends a float }), } ``` -------------------------------- ### FileService.List - List Files and Directories Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Lists files and directories within the opencode API. Requires a context, FileListParams for query, and optional request options. ```go func (r *FileService) List(ctx context.Context, query FileListParams, opts ...option.RequestOption) (res *[]FileNode, err error) ``` -------------------------------- ### Get Raw JSON Field Value Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/internal/apijson Returns the raw string value of the JSON field. ```go func (j Field) Raw() string ``` -------------------------------- ### ProjectService.List Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go List all projects. ```APIDOC ## ProjectService.List ### Description List all projects. ### Signature ```go func (r *ProjectService) List(ctx context.Context, query ProjectListParams, opts ...option.RequestOption) (res *[]Project, err error) ``` ``` -------------------------------- ### ListStreaming Events Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves events via a streaming interface. Use this method to get a stream of events. ```go func (r *EventService) ListStreaming(ctx context.Context, query EventListParams, opts ...option.RequestOption) (stream *ssestream.Stream[EventListResponse]) ``` -------------------------------- ### Get Stream Error Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/packages/ssestream Returns any error that occurred during stream processing. Check this after Next() returns false. ```go func (s *Stream[T]) Err() error ``` -------------------------------- ### ConfigAgentPlanPermissionWebfetch Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the possible permission levels for webfetch: ask, allow, and deny. ```go const ( ConfigAgentPlanPermissionWebfetchAsk ConfigAgentPlanPermissionWebfetch = "ask" ConfigAgentPlanPermissionWebfetchAllow ConfigAgentPlanPermissionWebfetch = "allow" ConfigAgentPlanPermissionWebfetchDeny ConfigAgentPlanPermissionWebfetch = "deny" ) ``` -------------------------------- ### NewFileService - Initialize File Service Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new FileService instance. Options are applied after client options and before request-specific options. Do not instantiate directly; use this method instead. ```go func NewFileService(opts ...option.RequestOption) (r *FileService) ``` -------------------------------- ### FilePartSourceText Struct Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Represents text content within a file part, including start and end positions. ```go type FilePartSourceText struct { End int64 `json:"end,required"` Start int64 `json:"start,required"` Value string `json:"value,required"` JSON filePartSourceTextJSON `json:"-"` } ``` -------------------------------- ### NewAppService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Initializes a new AppService with optional request options. ```APIDOC ## NewAppService ### Description Initializes a new AppService with optional request options. ### Signature func NewAppService(opts ...option.RequestOption) (r *AppService) ``` -------------------------------- ### NewFindService - Initialize Find Service Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new FindService instance. Options are applied after client options and before request-specific options. Use this method instead of direct instantiation. ```go func NewFindService(opts ...option.RequestOption) (r *FindService) ``` -------------------------------- ### New Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Creates a new session. ```APIDOC ## New ### Description Create a new session ### Signature ```go func (r *SessionService) New(ctx context.Context, params SessionNewParams, opts ...option.RequestOption) (res *Session, err error) ``` ``` -------------------------------- ### NewConfigService Initialization Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new ConfigService with specified options. These options are applied after client options and before request-specific options. ```go func NewConfigService(opts ...option.RequestOption) (r *ConfigService) ``` -------------------------------- ### EventListResponseEventIdeInstalled Type Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the structure for an IDE installed event, including its properties. Added in v0.16.0. ```go type EventListResponseEventIdeInstalled struct { Properties EventListResponseEventIdeInstalledProperties `json:"properties,required"` } ``` -------------------------------- ### NewClient Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Creates a new client instance with optional request options. ```APIDOC ## NewClient ### Description Creates a new client instance with optional request options. ### Signature func NewClient(opts ...option.RequestOption) (r *Client) ``` -------------------------------- ### TuiService.OpenHelp Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Opens the help dialog in the TUI. This method takes a context, TuiOpenHelpParams, and optional request options, returning a boolean and an error. ```APIDOC ## OpenHelp ### Description Open the help dialog ### Method func (*TuiService) OpenHelp(ctx context.Context, body TuiOpenHelpParams, opts ...option.RequestOption) (res *bool, err error) ### Parameters #### Request Body - **directory** (string) - Optional - The directory to open help for. ``` -------------------------------- ### Get Current Stream Event Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/packages/ssestream Retrieves the current event data from the stream. This should be called after a successful call to Next(). ```go func (s *Stream[T]) Current() T ``` -------------------------------- ### Session Service Get Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves a specific session by its ID. This method is used to fetch details of a particular session. ```go func (r *SessionService) Get(ctx context.Context, id string, query SessionGetParams, opts ...option.RequestOption) (res *Session, err error) ``` -------------------------------- ### Put Request with Client Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Makes a PUT request using the client. It accepts context, path, parameters, a response interface, and optional request options. Refer to the Execute documentation for details on params and response handling. ```go func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error ``` -------------------------------- ### ConfigService.Get Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves the current configuration. It accepts context, query parameters, and optional request options. ```APIDOC ## ConfigService.Get ### Description Retrieves the current configuration settings. ### Method `Get` ### Parameters #### Path Parameters None #### Query Parameters - **query** (ConfigGetParams) - Required - Parameters for fetching the configuration. #### Request Body None ### Request Example ```go // Example usage (assuming ctx, query, and opts are defined) res, err := configService.Get(ctx, query, opts...) ``` ### Response #### Success Response (200) - **res** (*Config) - The configuration object. - **err** (error) - An error if the retrieval fails. #### Response Example ```json { "example": "Config object structure" } ``` ``` -------------------------------- ### FileService.Status - Get File Status Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves the status of files. Requires a context, FileStatusParams for query, and optional request options. ```go func (r *FileService) Status(ctx context.Context, query FileStatusParams, opts ...option.RequestOption) (res *[]File, err error) ``` -------------------------------- ### Implement UnmarshalJSON for EventListResponseEventInstallationUpdatedProperties Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Custom JSON unmarshalling for the EventListResponseEventInstallationUpdatedProperties struct. This method parses the version information for installation updates. ```go func (r *EventListResponseEventInstallationUpdatedProperties) UnmarshalJSON(data []byte) (err error) ``` -------------------------------- ### Write Log Entry to Server Logs Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Use this method to write a log entry to the server logs. It requires a context and parameters for the log entry. ```go func (r *AppService) Log(ctx context.Context, params AppLogParams, opts ...option.RequestOption) (res *bool, err error) ``` -------------------------------- ### ConfigAgentBuildPermissionWebfetch Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines string constants for webfetch permissions: ask, allow, and deny. Use these to set webfetch permissions. ```go const ( ConfigAgentBuildPermissionWebfetchAsk ConfigAgentBuildPermissionWebfetch = "ask" ConfigAgentBuildPermissionWebfetchAllow ConfigAgentBuildPermissionWebfetch = "allow" ConfigAgentBuildPermissionWebfetchDeny ConfigAgentBuildPermissionWebfetch = "deny" ) ``` -------------------------------- ### ConfigAgentBuildPermissionBashString Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines string constants for bash build permissions: ask, allow, and deny. Use these to set bash permissions. ```go const ( ConfigAgentBuildPermissionBashStringAsk ConfigAgentBuildPermissionBashString = "ask" ConfigAgentBuildPermissionBashStringAllow ConfigAgentBuildPermissionBashString = "allow" ConfigAgentBuildPermissionBashStringDeny ConfigAgentBuildPermissionBashString = "deny" ) ``` -------------------------------- ### FindTextResponseSubmatch Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the structure for a FindTextResponseSubmatch, including start and end positions, the matched text, and an internal JSON field. ```go type FindTextResponseSubmatch struct { End float64 `json:"end,required"` Match FindTextResponseSubmatchesMatch `json:"match,required"` Start float64 `json:"start,required"` JSON findTextResponseSubmatchJSON `json:"-"` } ``` -------------------------------- ### ConfigExperimental Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines experimental configuration settings, including paste summary disabling and hook configurations. ```go type ConfigExperimental struct { DisablePasteSummary bool Hook ConfigExperimentalHook JSON configExperimentalJSON } ``` -------------------------------- ### Create Decoder from HTTP Response Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/packages/ssestream Creates a new Decoder instance from an http.Response. This is a common way to start processing an SSE stream. ```go func NewDecoder(res *http.Response) Decoder ``` -------------------------------- ### Create New AgentService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new AgentService with specified request options. Options are applied after client options and before request-specific options. ```go func NewAgentService(opts ...option.RequestOption) (r *AgentService) ``` -------------------------------- ### Implement UnmarshalJSON for EventListResponseEventInstallationUpdated Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Custom JSON unmarshalling for the EventListResponseEventInstallationUpdated struct. This method handles deserializing installation update event data. ```go func (r *EventListResponseEventInstallationUpdated) UnmarshalJSON(data []byte) (err error) ``` -------------------------------- ### Implement UnmarshalJSON for EventListResponseEventIdeInstalledProperties Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Custom JSON unmarshalling for the EventListResponseEventIdeInstalledProperties struct. This method is responsible for parsing the properties of an installed IDE event. ```go func (r *EventListResponseEventIdeInstalledProperties) UnmarshalJSON(data []byte) (err error) ``` -------------------------------- ### Import Opencode Go SDK Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Import the Opencode Go SDK package. This is the primary import statement for using the library. ```go import ( "github.com/sst/opencode-sdk-go" // imported as opencode ) ``` -------------------------------- ### NewConfigService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Initializes a new ConfigService with optional request options. ```APIDOC ## NewConfigService ### Description Creates and returns a new instance of the ConfigService. ### Method `NewConfigService` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **opts** (...option.RequestOption) - Optional - Request options to configure the service client. ### Request Example ```go // Example usage (assuming opts are defined) configService := NewConfigService(opts...) ``` ### Response - **r** (*ConfigService) - A pointer to the initialized ConfigService. - **err** (error) - An error if initialization fails (though not explicitly shown in signature, common for constructors). ``` -------------------------------- ### Session Service Children Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves the children of a given session ID. This method is used to get a list of sub-sessions or related sessions. ```go func (r *SessionService) Children(ctx context.Context, id string, query SessionChildrenParams, opts ...option.RequestOption) (res *[]Session, err error) ``` -------------------------------- ### SymbolSourceRangeParam Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the SymbolSourceRangeParam structure, which uses `param.Field` for nested start and end range parameters, intended for API usage. ```go type SymbolSourceRangeParam struct { End param.Field[SymbolSourceRangeEndParam] `json:"end,required" Start param.Field[SymbolSourceRangeStartParam] `json:"start,required" } ``` -------------------------------- ### ProjectService.List Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Lists all projects. Supports custom request options and query parameters for filtering and pagination. ```APIDOC ## ProjectService.List ### Description Lists all projects. Supports custom request options and query parameters for filtering and pagination. ### Method GET ### Endpoint /project/list ### Parameters #### Query Parameters - **query** (ProjectListParams) - Required - Parameters for listing projects. #### Request Example ```json { "example": "ProjectListParams object" } ``` ### Response #### Success Response (200) - **res** (*[]Project) - A list of projects. #### Response Example ```json { "example": "[]Project object" } ``` ``` -------------------------------- ### StepFinishPartTokens Structure Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Contains token usage details for a step finish. ```go type StepFinishPartTokens struct { Cache StepFinishPartTokensCache `json:"cache,required"` Input float64 `json:"input,required"` Output float64 `json:"output,required"` Reasoning float64 `json:"reasoning,required"` JSON stepFinishPartTokensJSON `json:"-"` } ``` -------------------------------- ### SymbolLocationRange Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the SymbolLocationRange structure, which represents a range with start and end points. It includes a JSON field that is ignored during marshaling/unmarshaling. ```go type SymbolLocationRange struct { End SymbolLocationRangeEnd `json:"end,required" Start SymbolLocationRangeStart `json:"start,required" JSON symbolLocationRangeJSON `json:"-" } ``` -------------------------------- ### Patch Request with Client Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Makes a PATCH request using the client. It accepts context, path, parameters, a response interface, and optional request options. Refer to the Execute documentation for details on params and response handling. ```go func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error ``` -------------------------------- ### Configuring Request Timeouts with Context Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Explains how to set request timeouts using `context` and per-retry timeouts using `option.WithRequestTimeout()`. ```APIDOC ## Timeouts Requests do not time out by default. Use `context` to configure a timeout for the entire request lifecycle. If a request is retried, the context timeout does not reset. For per-retry timeouts, use `option.WithRequestTimeout()`. ```go import ( "context" "time" "github.com/sst/opencode-sdk-go/option" ) // Assuming 'client' is an initialized opencode.Client // This sets the timeout for the request, including all retries. 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), ) ``` ``` -------------------------------- ### SymbolLocationRangeStart Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the SymbolLocationRangeStart structure, specifying the start of a range with character and line details. It includes a JSON field for internal processing. ```go type SymbolLocationRangeStart struct { Character float64 `json:"character,required" Line float64 `json:"line,required" JSON symbolLocationRangeStartJSON `json:"-" } ``` -------------------------------- ### Apply Request Options to Config Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/internal/requestconfig Applies a list of RequestOptions to an existing RequestConfig. ```go func (cfg *RequestConfig) Apply(opts ...RequestOption) error ``` -------------------------------- ### List Commands with CommandService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Lists all available commands using the CommandService. It takes context, CommandListParams for filtering, and optional request options. ```go func (r *CommandService) List(ctx context.Context, query CommandListParams, opts ...option.RequestOption) (res *[]Command, err error) ``` -------------------------------- ### SymbolSourceRange Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the SymbolSourceRange structure, representing a range with start and end points for symbol source information. It includes an ignored JSON field. ```go type SymbolSourceRange struct { End SymbolSourceRangeEnd `json:"end,required" Start SymbolSourceRangeStart `json:"start,required" JSON symbolSourceRangeJSON `json:"-" } ``` -------------------------------- ### Define TuiOpenHelpParams Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the parameters for opening the help dialog in the TUI. It accepts an optional directory. ```go type TuiOpenHelpParams struct { Directory param.Field[string] `query:"directory"` } ``` -------------------------------- ### Define EventListResponseEventIdeInstalledProperties Struct Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the properties for the EventListResponseEventIdeInstalled struct, including the IDE identifier. This struct is used to hold specific details about an installed IDE event. ```go type EventListResponseEventIdeInstalledProperties struct { Ide string `json:"ide,required"` JSON eventListResponseEventIdeInstalledPropertiesJSON `json:"-"` } ``` -------------------------------- ### Session Service Initialization Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Creates a new SessionService with optional request options. This service is used to interact with the opencode API for session management. Do not instantiate directly; use NewSessionService. ```go func NewSessionService(opts ...option.RequestOption) (r *SessionService) ``` -------------------------------- ### Agent Part Input Source Parameter Struct Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the `AgentPartInputSourceParam` struct, representing the source of an agent part input. It includes `Start`, `End`, and `Value` fields. ```go type AgentPartInputSourceParam struct { End param.Field[int64] `json:"end,required"` Start param.Field[int64] `json:"start,required"` Value param.Field[string] `json:"value,required"` } ``` -------------------------------- ### ConfigService.Get Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves configuration information. ```APIDOC ## func (*ConfigService) Get ### Description Get config info ### Signature ```go func (r *ConfigService) Get(ctx context.Context, query ConfigGetParams, opts ...option.RequestOption) (res *Config, err error) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **res** (*Config) - The configuration object. #### Response Example None ``` -------------------------------- ### Iterate Through SSE Stream Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/packages/ssestream Advances the stream to the next event. Returns false if the stream has ended or an error occurred. Use Current() to get the data and Err() to check for errors. ```go func (s *Stream[T]) Next() bool ``` ```go for stream.Next() { data := stream.Current() } if stream.Err() != nil { ... } ``` -------------------------------- ### ConfigModeBuildPermissionWebfetch Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go An enumerated string type for webfetch permissions, with constants for ask, allow, and deny. ```APIDOC ## Type: ConfigModeBuildPermissionWebfetch ### Description An enumerated string type for webfetch permissions, with constants for ask, allow, and deny. ### Constants - **Ask**: ConfigModeBuildPermissionWebfetch = "ask" - **Allow**: ConfigModeBuildPermissionWebfetch = "allow" - **Deny**: ConfigModeBuildPermissionWebfetch = "deny" ### Methods #### IsKnown ```go func (r ConfigModeBuildPermissionWebfetch) IsKnown() bool ``` Description: Checks if the webfetch permission is a known value. ``` -------------------------------- ### Stream.Next Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/packages/ssestream Advances the stream to the next event. Returns false if the stream has ended or an error occurred. After calling Next(), use Current() to get the event data or Err() to check for errors. ```APIDOC ## func (*Stream[T]) Next ### Description Advances to the next event in the stream. Returns false if the stream has ended or an error occurred. ### Signature ```go func (s *Stream[T]) Next() bool ``` ### Returns * bool - True if there is a next event, false otherwise. ### Example ```go for stream.Next() { data := stream.Current() // Process data } if stream.Err() != nil { // Handle error } ``` ``` -------------------------------- ### NewAgentService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Initializes a new AgentService with optional request options. ```APIDOC ## NewAgentService ### Description Initializes a new AgentService with optional request options. ### Signature func NewAgentService(opts ...option.RequestOption) (r *AgentService) ``` -------------------------------- ### Agent Part Source Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the `AgentPartSource` struct, representing the source of an agent part. It includes `Start`, `End`, and `Value` fields, along with a JSON unmarshalling helper. ```go type AgentPartSource struct { End int64 `json:"end,required"` Start int64 `json:"start,required"` Value string `json:"value,required"` JSON agentPartSourceJSON `json:"-"` } ``` -------------------------------- ### DefaultClientOptions Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Retrieves default client options, reading from the OPENCODE_BASE_URL environment variable. Used for initializing new clients. ```APIDOC ## DefaultClientOptions ### Description Retrieves default client options, reading from the OPENCODE_BASE_URL environment variable. Used for initializing new clients. ### Function Signature ```go func DefaultClientOptions() []option.RequestOption ``` ### Returns - `[]option.RequestOption` - A slice of default request options. ``` -------------------------------- ### ConfigCommand Struct Definition Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines a command configuration, including template, agent, description, model, and subtask options. ```go type ConfigCommand struct { Template string Agent string Description string Model string Subtask bool JSON configCommandJSON } ``` -------------------------------- ### NewClient Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new client with default options read from the environment (OPENCODE_BASE_URL). Options passed as arguments are applied after default arguments and are passed down to services and requests. ```APIDOC ## NewClient ### Description Generates a new client with the default option read from the environment (OPENCODE_BASE_URL). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes. ### Signature ```go func NewClient(opts ...option.RequestOption) (r *Client) ``` ``` -------------------------------- ### NewProjectService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go 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. ```APIDOC ## NewProjectService ### Description 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. ### Signature ```go func NewProjectService(opts ...option.RequestOption) (r *ProjectService) ``` ``` -------------------------------- ### Session Service List Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Lists all available sessions. This method is useful for retrieving an overview of all active or past sessions. ```go func (r *SessionService) List(ctx context.Context, query SessionListParams, opts ...option.RequestOption) (res *[]Session, err error) ``` -------------------------------- ### ConfigModePlanPermissionBashMapItem Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Constants for ConfigModePlanPermissionBashMapItem, specifying 'ask'. Added in v0.2.0. ```go const ( ConfigModePlanPermissionBashMapAsk ConfigModePlanPermissionBashMapItem = "ask" ) ``` -------------------------------- ### ConfigAgentPlanPermissionEdit Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the possible permission levels for agent plan editing: ask, allow, and deny. ```go const ( ConfigAgentPlanPermissionEditAsk ConfigAgentPlanPermissionEdit = "ask" ConfigAgentPlanPermissionEditAllow ConfigAgentPlanPermissionEdit = "allow" ConfigAgentPlanPermissionEditDeny ConfigAgentPlanPermissionEdit = "deny" ) ``` -------------------------------- ### SessionService.New Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Creates a new session. Accepts optional request options. ```APIDOC ## SessionService.New ### Description Creates a new session. ### Method func (r *SessionService) New(ctx context.Context, params SessionNewParams, opts ...option.RequestOption) (res *Session, err error) ### Parameters - **ctx** (context.Context) - The context for the request. - **params** (SessionNewParams) - Parameters for creating the new session. - **opts** (...option.RequestOption) - Optional request options. ### Returns - **(*Session)**: The newly created Session object. - **(error)**: An error if the operation fails. ``` -------------------------------- ### ConfigAgentPlanPermissionBashString Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the possible values for bash string permissions: ask, allow, or deny. Use these constants for direct string-based bash permission configuration. ```go const ( ConfigAgentPlanPermissionBashStringAsk ConfigAgentPlanPermissionBashString = "ask" ConfigAgentPlanPermissionBashStringAllow ConfigAgentPlanPermissionBashString = "allow" ConfigAgentPlanPermissionBashStringDeny ConfigAgentPlanPermissionBashString = "deny" ) ``` -------------------------------- ### Session Service New Method Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Creates a new session with the specified parameters. This method is used to initiate a new session for interaction. ```go func (r *SessionService) New(ctx context.Context, params SessionNewParams, opts ...option.RequestOption) (res *Session, err error) ``` -------------------------------- ### Create New AppService Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Generates a new AppService with specified request options. Options are applied after client options and before request-specific options. ```go func NewAppService(opts ...option.RequestOption) (r *AppService) ``` -------------------------------- ### ConfigAgentBuildPermissionEdit Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines string constants for edit permissions: ask, allow, and deny. Use these to set edit permissions. ```go const ( ConfigAgentBuildPermissionEditAsk ConfigAgentBuildPermissionEdit = "ask" ConfigAgentBuildPermissionEditAllow ConfigAgentBuildPermissionEdit = "allow" ConfigAgentBuildPermissionEditDeny ConfigAgentBuildPermissionEdit = "deny" ) ``` -------------------------------- ### Set Environment to Production Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go/option Returns a RequestOption that sets the current environment to be the "production" environment. An environment specifies which base URL to use by default. ```go func WithEnvironmentProduction() RequestOption ``` -------------------------------- ### ConfigModeBuildPermission Constants Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Defines the possible values for build permissions: Edit, Webfetch, and JSON. ```go const ( ConfigModeBuildPermissionEdit ConfigModeBuildPermission = "edit" ConfigModeBuildPermissionWebfetch ConfigModeBuildPermission = "webfetch" JSON ConfigModeBuildPermission = "json" ) ``` -------------------------------- ### Prompt Session Go SDK Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Use this function to create and send a new message to an existing session. It requires a context, session ID, parameters, and optional request options. ```go func (r *SessionService) Prompt(ctx context.Context, id string, params SessionPromptParams, opts ...option.RequestOption) (res *SessionPromptResponse, err error) ``` -------------------------------- ### StepFinishPartTokensCache Structure Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Details cache token usage for a step finish. ```go type StepFinishPartTokensCache struct { Read float64 `json:"read,required"` Write float64 `json:"write,required"` JSON stepFinishPartTokensCacheJSON `json:"-"` } ``` -------------------------------- ### Apply Custom Middleware to Requests Source: https://pkg.go.dev/github.com/sst/opencode-sdk-go Implement custom middleware by creating a function that accepts `*http.Request` and `option.MiddlewareNext`. The middleware can process requests before they are sent and responses after they are received. Apply it using `option.WithMiddleware` when creating the client. ```go func Logger(req *http.Request, next option.MiddlewareNext) (res *http.Response, err error) { // Before the request start := time.Now() LogReq(req) // Forward the request to the next handler res, err = next(req) // Handle stuff after the request end := time.Now() LogRes(res, err, start - end) return res, err } client := opencode.NewClient( option.WithMiddleware(Logger), ) ```