opencode

package module
v0.1.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 16 Imported by: 5

README

Opencode Go API Library

Go Reference

The Opencode Go library provides convenient access to the Opencode REST API from applications written in Go.

It is generated with Stainless.

Installation

import (
	"github.com/sst/opencode-sdk-go" // imported as opencode
)

Or to pin the version:

go get -u 'github.com/sst/opencode-sdk-go@v0.1.0-alpha.2'

Requirements

This library requires Go 1.18+.

Usage

The full API of this library can be found in api.md.

package main

import (
	"context"
	"fmt"

	"github.com/sst/opencode-sdk-go"
)

func main() {
	client := opencode.NewClient()
	events, err := client.Event.List(context.TODO())
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", events)
}

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:

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:

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.

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:

client := opencode.NewClient(
	// Adds a header to every request made by the client
	option.WithHeader("X-Some-Header", "custom_header_info"),
)

client.Event.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.:

Errors

When the API returns a non-success status code, we return an error with type *opencode.Error. This contains the StatusCode, *http.Request, and *http.Response values of the request, as well as the JSON of the error body (much like other response objects in the SDK).

To handle errors, we recommend that you use the errors.As pattern:

_, err := client.Event.List(context.TODO())
if err != nil {
	var apierr *opencode.Error
	if errors.As(err, &apierr) {
		println(string(apierr.DumpRequest(true)))  // Prints the serialized HTTP request
		println(string(apierr.DumpResponse(true))) // Prints the serialized HTTP response
	}
	panic(err.Error()) // GET "/event": 400 Bad Request { ... }
}

When other errors occur, they are returned unwrapped; for example, if HTTP transport fails, you might receive *url.Error wrapping *net.OpError.

Timeouts

Requests do not time out by default; use context to configure a timeout for a request lifecycle.

Note that if a request is retried, the context timeout does not start over. To set a per-retry timeout, use option.WithRequestTimeout().

// This sets the timeout for the request, including all the retries.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
client.Event.List(
	ctx,
	// This sets the per-retry timeout
	option.WithRequestTimeout(20*time.Second),
)
File uploads

Request parameters that correspond to file uploads in multipart requests are typed as param.Field[io.Reader]. The contents of the io.Reader will by default be sent as a multipart form part with the file name of "anonymous_file" and content-type of "application/octet-stream".

The file name and content-type can be customized by implementing Name() string or ContentType() string on the run-time type of io.Reader. Note that os.File implements Name() string, so a file returned by os.Open will be sent with the file name on disk.

We also provide a helper opencode.FileParam(reader io.Reader, filename string, contentType string) which can be used to wrap any io.Reader with the appropriate file name and content type.

Retries

Certain errors will be automatically retried 2 times by default, with a short exponential backoff. We retry by default all connection errors, 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors.

You can use the WithMaxRetries option to configure or disable this:

// Configure the default for all requests:
client := opencode.NewClient(
	option.WithMaxRetries(0), // default is 2
)

// Override per-request:
client.Event.List(context.TODO(), option.WithMaxRetries(5))
Accessing raw response data (e.g. response headers)

You can access the raw HTTP response data by using the option.WithResponseInto() request option. This is useful when you need to examine response headers, status codes, or other details.

// Create a variable to store the HTTP response
var response *http.Response
events, err := client.Event.List(context.TODO(), option.WithResponseInto(&response))
if err != nil {
	// handle error
}
fmt.Printf("%+v\n", events)

fmt.Printf("Status Code: %d\n", response.StatusCode)
fmt.Printf("Headers: %+#v\n", response.Header)
Making custom/undocumented requests

This library is typed for convenient access to the documented API. If you need to access undocumented endpoints, params, or response properties, the library can still be used.

Undocumented endpoints

To make requests to undocumented endpoints, you can use client.Get, client.Post, and other HTTP verbs. RequestOptions on the client, such as retries, will be respected when making these requests.

var (
    // params can be an io.Reader, a []byte, an encoding/json serializable object,
    // or a "…Params" struct defined in this library.
    params map[string]interface{}

    // result can be an []byte, *http.Response, a encoding/json deserializable object,
    // or a model defined in this library.
    result *http.Response
)
err := client.Post(context.Background(), "/unspecified", params, &result)
if err != nil {
    …
}
Undocumented request params

To make requests using undocumented parameters, you may use either the option.WithQuerySet() or the option.WithJSONSet() methods.

params := FooNewParams{
    ID:   opencode.F("id_xxxx"),
    Data: opencode.F(FooNewParamsData{
        FirstName: opencode.F("John"),
    }),
}
client.Foo.New(context.Background(), params, option.WithJSONSet("data.last_name", "Doe"))
Undocumented response properties

To access undocumented response properties, you may either access the raw JSON of the response as a string with result.JSON.RawJSON(), or get the raw JSON of a particular field on the result with result.JSON.Foo.Raw().

Any fields that are not present on the response struct will be saved and can be accessed by result.JSON.ExtraFields() which returns the extra fields as a map[string]Field.

Middleware

We provide option.WithMiddleware which applies the given middleware to requests.

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),
)

When multiple middlewares are provided as variadic arguments, the middlewares are applied left to right. If option.WithMiddleware is given multiple times, for example first in the client then the method, the middleware in the client will run first and the middleware given in the method will run next.

You may also replace the default http.Client with option.WithHTTPClient(client). Only one http client is accepted (this overwrites any previous client) and receives requests after any middleware has been applied.

Semantic versioning

This package generally follows SemVer conventions, though certain backwards-incompatible changes may be released as minor versions:

  1. Changes to library internals which are technically public but not intended or documented for external use. (Please open a GitHub issue to let us know if you are relying on such internals.)
  2. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an issue with questions, bugs, or suggestions.

Contributing

See the contributing documentation.

Documentation

Index

Constants

View Source
const ProviderAuthErrorNameProviderAuthError = shared.ProviderAuthErrorNameProviderAuthError

This is an alias to an internal value.

View Source
const UnknownErrorNameUnknownError = shared.UnknownErrorNameUnknownError

This is an alias to an internal value.

Variables

This section is empty.

Functions

func Bool

func Bool(value bool) param.Field[bool]

Bool is a param field helper which helps specify bools.

func DefaultClientOptions

func DefaultClientOptions() []option.RequestOption

DefaultClientOptions read from the environment (OPENCODE_BASE_URL). This should be used to initialize new clients.

func F

func F[T any](value T) param.Field[T]

F is a param field helper used to initialize a param.Field generic struct. This helps specify null, zero values, and overrides, as well as normal values. You can read more about this in our README.

func FileParam

func FileParam(reader io.Reader, filename string, contentType string) param.Field[io.Reader]

FileParam is a param field helper which helps files with a mime content-type.

func Float

func Float(value float64) param.Field[float64]

Float is a param field helper which helps specify floats.

func Int

func Int(value int64) param.Field[int64]

Int is a param field helper which helps specify integers. This is particularly helpful when specifying integer constants for fields.

func Null

func Null[T any]() param.Field[T]

Null is a param field helper which explicitly sends null to the API.

func Raw

func Raw[T any](value any) param.Field[T]

Raw is a param field helper for specifying values for fields when the type you are looking to send is different from the type that is specified in the SDK. For example, if the type of the field is an integer, but you want to send a float, you could do that by setting the corresponding field with Raw[int](0.5).

func String

func String(value string) param.Field[string]

String is a param field helper which helps specify strings.

Types

type App

type App struct {
	Git      bool    `json:"git,required"`
	Hostname string  `json:"hostname,required"`
	Path     AppPath `json:"path,required"`
	Project  string  `json:"project,required"`
	Time     AppTime `json:"time,required"`
	User     string  `json:"user,required"`
	JSON     appJSON `json:"-"`
}

func (*App) UnmarshalJSON

func (r *App) UnmarshalJSON(data []byte) (err error)

type AppPath

type AppPath struct {
	Config string      `json:"config,required"`
	Cwd    string      `json:"cwd,required"`
	Data   string      `json:"data,required"`
	Root   string      `json:"root,required"`
	State  string      `json:"state,required"`
	JSON   appPathJSON `json:"-"`
}

func (*AppPath) UnmarshalJSON

func (r *AppPath) UnmarshalJSON(data []byte) (err error)

type AppService added in v0.2.0

type AppService struct {
	Options []option.RequestOption
}

AppService 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 NewAppService method instead.

func NewAppService added in v0.2.0

func NewAppService(opts ...option.RequestOption) (r *AppService)

NewAppService 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 (*AppService) Get

func (r *AppService) Get(ctx context.Context, opts ...option.RequestOption) (res *App, err error)

Get app info

func (*AppService) Init

func (r *AppService) Init(ctx context.Context, opts ...option.RequestOption) (res *bool, err error)

Initialize the app

type AppTime

type AppTime struct {
	Initialized float64     `json:"initialized"`
	JSON        appTimeJSON `json:"-"`
}

func (*AppTime) UnmarshalJSON

func (r *AppTime) UnmarshalJSON(data []byte) (err error)

type Client

type Client struct {
	Options []option.RequestOption
	Event   *EventService
	App     *AppService
	File    *FileService
	Config  *ConfigService
	Session *SessionService
}

Client creates a struct with services and top level methods that help with interacting with the opencode API. You should not instantiate this client directly, and instead use the NewClient method instead.

func NewClient

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.

func (*Client) Delete

func (r *Client) Delete(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Execute

func (r *Client) Execute(ctx context.Context, method string, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.

If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.

The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.

If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.

Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.

The response body will be deserialized into the res variable, depending on its type:

  • A pointer to a *http.Response is populated by the raw response.
  • A pointer to a byte array will be populated with the contents of the request body.
  • A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
  • A nil value will not read the response body.

For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.

func (*Client) Get

func (r *Client) Get(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Patch

func (r *Client) Patch(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Post

func (r *Client) Post(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Post makes a POST request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

func (*Client) Put

func (r *Client) Put(ctx context.Context, path string, params interface{}, res interface{}, opts ...option.RequestOption) error

Put makes a PUT request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.

type Config

type Config struct {
	// JSON schema reference for configuration validation
	Schema string `json:"$schema"`
	// 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"`
	// Custom keybind configurations
	Keybinds Keybinds `json:"keybinds"`
	// MCP (Model Context Protocol) server configurations
	Mcp map[string]ConfigMcp `json:"mcp"`
	// 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"`
	// Theme name to use for the interface
	Theme string     `json:"theme"`
	JSON  configJSON `json:"-"`
}

func (*Config) UnmarshalJSON

func (r *Config) UnmarshalJSON(data []byte) (err error)

type ConfigExperimental

type ConfigExperimental struct {
	Hook ConfigExperimentalHook `json:"hook"`
	JSON configExperimentalJSON `json:"-"`
}

func (*ConfigExperimental) UnmarshalJSON

func (r *ConfigExperimental) UnmarshalJSON(data []byte) (err error)

type ConfigExperimentalHook

type ConfigExperimentalHook struct {
	FileEdited       map[string][]ConfigExperimentalHookFileEdited `json:"file_edited"`
	SessionCompleted []ConfigExperimentalHookSessionCompleted      `json:"session_completed"`
	JSON             configExperimentalHookJSON                    `json:"-"`
}

func (*ConfigExperimentalHook) UnmarshalJSON

func (r *ConfigExperimentalHook) UnmarshalJSON(data []byte) (err error)

type ConfigExperimentalHookFileEdited

type ConfigExperimentalHookFileEdited struct {
	Command     []string                             `json:"command,required"`
	Environment map[string]string                    `json:"environment"`
	JSON        configExperimentalHookFileEditedJSON `json:"-"`
}

func (*ConfigExperimentalHookFileEdited) UnmarshalJSON

func (r *ConfigExperimentalHookFileEdited) UnmarshalJSON(data []byte) (err error)

type ConfigExperimentalHookSessionCompleted

type ConfigExperimentalHookSessionCompleted struct {
	Command     []string                                   `json:"command,required"`
	Environment map[string]string                          `json:"environment"`
	JSON        configExperimentalHookSessionCompletedJSON `json:"-"`
}

func (*ConfigExperimentalHookSessionCompleted) UnmarshalJSON

func (r *ConfigExperimentalHookSessionCompleted) UnmarshalJSON(data []byte) (err error)

type ConfigMcp

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"`
	// 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:"-"`
	// contains filtered or unexported fields
}

func (ConfigMcp) AsUnion

func (r ConfigMcp) AsUnion() ConfigMcpUnion

AsUnion returns a ConfigMcpUnion interface which you can cast to the specific types for more type safety.

Possible runtime types of the union are McpLocal, McpRemote.

func (*ConfigMcp) UnmarshalJSON

func (r *ConfigMcp) UnmarshalJSON(data []byte) (err error)

type ConfigMcpType

type ConfigMcpType string

Type of MCP server connection

const (
	ConfigMcpTypeLocal  ConfigMcpType = "local"
	ConfigMcpTypeRemote ConfigMcpType = "remote"
)

func (ConfigMcpType) IsKnown

func (r ConfigMcpType) IsKnown() bool

type ConfigMcpUnion

type ConfigMcpUnion interface {
	// contains filtered or unexported methods
}

Union satisfied by McpLocal or McpRemote.

type ConfigProvider

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:"-"`
}

func (*ConfigProvider) UnmarshalJSON

func (r *ConfigProvider) UnmarshalJSON(data []byte) (err error)

type ConfigProviderModel

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"`
	Temperature bool                      `json:"temperature"`
	ToolCall    bool                      `json:"tool_call"`
	JSON        configProviderModelJSON   `json:"-"`
}

func (*ConfigProviderModel) UnmarshalJSON

func (r *ConfigProviderModel) UnmarshalJSON(data []byte) (err error)

type ConfigProviderModelsCost

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:"-"`
}

func (*ConfigProviderModelsCost) UnmarshalJSON

func (r *ConfigProviderModelsCost) UnmarshalJSON(data []byte) (err error)

type ConfigProviderModelsLimit

type ConfigProviderModelsLimit struct {
	Context float64                       `json:"context,required"`
	Output  float64                       `json:"output,required"`
	JSON    configProviderModelsLimitJSON `json:"-"`
}

func (*ConfigProviderModelsLimit) UnmarshalJSON

func (r *ConfigProviderModelsLimit) UnmarshalJSON(data []byte) (err error)

type ConfigProvidersResponse

type ConfigProvidersResponse struct {
	Default   map[string]string           `json:"default,required"`
	Providers []Provider                  `json:"providers,required"`
	JSON      configProvidersResponseJSON `json:"-"`
}

func (*ConfigProvidersResponse) UnmarshalJSON

func (r *ConfigProvidersResponse) UnmarshalJSON(data []byte) (err error)

type ConfigService

type ConfigService struct {
	Options []option.RequestOption
}

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.

func NewConfigService

func NewConfigService(opts ...option.RequestOption) (r *ConfigService)

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 (*ConfigService) Get

func (r *ConfigService) Get(ctx context.Context, opts ...option.RequestOption) (res *Config, err error)

Get config info

func (*ConfigService) Providers

func (r *ConfigService) Providers(ctx context.Context, opts ...option.RequestOption) (res *ConfigProvidersResponse, err error)

List all providers

type Error

type Error = apierror.Error

type EventListResponse

type EventListResponse struct {
	// This field can have the runtime type of
	// [EventListResponseEventStorageWriteProperties],
	// [EventListResponseEventInstallationUpdatedProperties],
	// [EventListResponseEventLspClientDiagnosticsProperties],
	// [EventListResponseEventPermissionUpdatedProperties],
	// [EventListResponseEventMessageUpdatedProperties],
	// [EventListResponseEventMessagePartUpdatedProperties],
	// [EventListResponseEventSessionUpdatedProperties],
	// [EventListResponseEventSessionDeletedProperties],
	// [EventListResponseEventSessionErrorProperties].
	Properties interface{}           `json:"properties,required"`
	Type       EventListResponseType `json:"type,required"`
	JSON       eventListResponseJSON `json:"-"`
	// contains filtered or unexported fields
}

func (*EventListResponse) UnmarshalJSON

func (r *EventListResponse) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventInstallationUpdated

type EventListResponseEventInstallationUpdated struct {
	Properties EventListResponseEventInstallationUpdatedProperties `json:"properties,required"`
	Type       EventListResponseEventInstallationUpdatedType       `json:"type,required"`
	JSON       eventListResponseEventInstallationUpdatedJSON       `json:"-"`
}

func (*EventListResponseEventInstallationUpdated) UnmarshalJSON

func (r *EventListResponseEventInstallationUpdated) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventInstallationUpdatedProperties

type EventListResponseEventInstallationUpdatedProperties struct {
	Version string                                                  `json:"version,required"`
	JSON    eventListResponseEventInstallationUpdatedPropertiesJSON `json:"-"`
}

func (*EventListResponseEventInstallationUpdatedProperties) UnmarshalJSON

func (r *EventListResponseEventInstallationUpdatedProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventInstallationUpdatedType

type EventListResponseEventInstallationUpdatedType string
const (
	EventListResponseEventInstallationUpdatedTypeInstallationUpdated EventListResponseEventInstallationUpdatedType = "installation.updated"
)

func (EventListResponseEventInstallationUpdatedType) IsKnown

type EventListResponseEventLspClientDiagnostics

type EventListResponseEventLspClientDiagnostics struct {
	Properties EventListResponseEventLspClientDiagnosticsProperties `json:"properties,required"`
	Type       EventListResponseEventLspClientDiagnosticsType       `json:"type,required"`
	JSON       eventListResponseEventLspClientDiagnosticsJSON       `json:"-"`
}

func (*EventListResponseEventLspClientDiagnostics) UnmarshalJSON

func (r *EventListResponseEventLspClientDiagnostics) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventLspClientDiagnosticsProperties

type EventListResponseEventLspClientDiagnosticsProperties struct {
	Path     string                                                   `json:"path,required"`
	ServerID string                                                   `json:"serverID,required"`
	JSON     eventListResponseEventLspClientDiagnosticsPropertiesJSON `json:"-"`
}

func (*EventListResponseEventLspClientDiagnosticsProperties) UnmarshalJSON

func (r *EventListResponseEventLspClientDiagnosticsProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventLspClientDiagnosticsType

type EventListResponseEventLspClientDiagnosticsType string
const (
	EventListResponseEventLspClientDiagnosticsTypeLspClientDiagnostics EventListResponseEventLspClientDiagnosticsType = "lsp.client.diagnostics"
)

func (EventListResponseEventLspClientDiagnosticsType) IsKnown

type EventListResponseEventMessagePartUpdated

type EventListResponseEventMessagePartUpdated struct {
	Properties EventListResponseEventMessagePartUpdatedProperties `json:"properties,required"`
	Type       EventListResponseEventMessagePartUpdatedType       `json:"type,required"`
	JSON       eventListResponseEventMessagePartUpdatedJSON       `json:"-"`
}

func (*EventListResponseEventMessagePartUpdated) UnmarshalJSON

func (r *EventListResponseEventMessagePartUpdated) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventMessagePartUpdatedProperties

type EventListResponseEventMessagePartUpdatedProperties struct {
	MessageID string                                                 `json:"messageID,required"`
	Part      MessagePart                                            `json:"part,required"`
	SessionID string                                                 `json:"sessionID,required"`
	JSON      eventListResponseEventMessagePartUpdatedPropertiesJSON `json:"-"`
}

func (*EventListResponseEventMessagePartUpdatedProperties) UnmarshalJSON

func (r *EventListResponseEventMessagePartUpdatedProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventMessagePartUpdatedType

type EventListResponseEventMessagePartUpdatedType string
const (
	EventListResponseEventMessagePartUpdatedTypeMessagePartUpdated EventListResponseEventMessagePartUpdatedType = "message.part.updated"
)

func (EventListResponseEventMessagePartUpdatedType) IsKnown

type EventListResponseEventMessageUpdated

type EventListResponseEventMessageUpdated struct {
	Properties EventListResponseEventMessageUpdatedProperties `json:"properties,required"`
	Type       EventListResponseEventMessageUpdatedType       `json:"type,required"`
	JSON       eventListResponseEventMessageUpdatedJSON       `json:"-"`
}

func (*EventListResponseEventMessageUpdated) UnmarshalJSON

func (r *EventListResponseEventMessageUpdated) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventMessageUpdatedProperties

type EventListResponseEventMessageUpdatedProperties struct {
	Info Message                                            `json:"info,required"`
	JSON eventListResponseEventMessageUpdatedPropertiesJSON `json:"-"`
}

func (*EventListResponseEventMessageUpdatedProperties) UnmarshalJSON

func (r *EventListResponseEventMessageUpdatedProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventMessageUpdatedType

type EventListResponseEventMessageUpdatedType string
const (
	EventListResponseEventMessageUpdatedTypeMessageUpdated EventListResponseEventMessageUpdatedType = "message.updated"
)

func (EventListResponseEventMessageUpdatedType) IsKnown

type EventListResponseEventPermissionUpdated

type EventListResponseEventPermissionUpdated struct {
	Properties EventListResponseEventPermissionUpdatedProperties `json:"properties,required"`
	Type       EventListResponseEventPermissionUpdatedType       `json:"type,required"`
	JSON       eventListResponseEventPermissionUpdatedJSON       `json:"-"`
}

func (*EventListResponseEventPermissionUpdated) UnmarshalJSON

func (r *EventListResponseEventPermissionUpdated) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventPermissionUpdatedProperties

type EventListResponseEventPermissionUpdatedProperties struct {
	ID        string                                                `json:"id,required"`
	Metadata  map[string]interface{}                                `json:"metadata,required"`
	SessionID string                                                `json:"sessionID,required"`
	Time      EventListResponseEventPermissionUpdatedPropertiesTime `json:"time,required"`
	Title     string                                                `json:"title,required"`
	JSON      eventListResponseEventPermissionUpdatedPropertiesJSON `json:"-"`
}

func (*EventListResponseEventPermissionUpdatedProperties) UnmarshalJSON

func (r *EventListResponseEventPermissionUpdatedProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventPermissionUpdatedPropertiesTime

type EventListResponseEventPermissionUpdatedPropertiesTime struct {
	Created float64                                                   `json:"created,required"`
	JSON    eventListResponseEventPermissionUpdatedPropertiesTimeJSON `json:"-"`
}

func (*EventListResponseEventPermissionUpdatedPropertiesTime) UnmarshalJSON

func (r *EventListResponseEventPermissionUpdatedPropertiesTime) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventPermissionUpdatedType

type EventListResponseEventPermissionUpdatedType string
const (
	EventListResponseEventPermissionUpdatedTypePermissionUpdated EventListResponseEventPermissionUpdatedType = "permission.updated"
)

func (EventListResponseEventPermissionUpdatedType) IsKnown

type EventListResponseEventSessionDeleted

type EventListResponseEventSessionDeleted struct {
	Properties EventListResponseEventSessionDeletedProperties `json:"properties,required"`
	Type       EventListResponseEventSessionDeletedType       `json:"type,required"`
	JSON       eventListResponseEventSessionDeletedJSON       `json:"-"`
}

func (*EventListResponseEventSessionDeleted) UnmarshalJSON

func (r *EventListResponseEventSessionDeleted) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionDeletedProperties

type EventListResponseEventSessionDeletedProperties struct {
	Info Session                                            `json:"info,required"`
	JSON eventListResponseEventSessionDeletedPropertiesJSON `json:"-"`
}

func (*EventListResponseEventSessionDeletedProperties) UnmarshalJSON

func (r *EventListResponseEventSessionDeletedProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionDeletedType

type EventListResponseEventSessionDeletedType string
const (
	EventListResponseEventSessionDeletedTypeSessionDeleted EventListResponseEventSessionDeletedType = "session.deleted"
)

func (EventListResponseEventSessionDeletedType) IsKnown

type EventListResponseEventSessionError

type EventListResponseEventSessionError struct {
	Properties EventListResponseEventSessionErrorProperties `json:"properties,required"`
	Type       EventListResponseEventSessionErrorType       `json:"type,required"`
	JSON       eventListResponseEventSessionErrorJSON       `json:"-"`
}

func (*EventListResponseEventSessionError) UnmarshalJSON

func (r *EventListResponseEventSessionError) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionErrorProperties

type EventListResponseEventSessionErrorProperties struct {
	Error EventListResponseEventSessionErrorPropertiesError `json:"error"`
	JSON  eventListResponseEventSessionErrorPropertiesJSON  `json:"-"`
}

func (*EventListResponseEventSessionErrorProperties) UnmarshalJSON

func (r *EventListResponseEventSessionErrorProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionErrorPropertiesError

type EventListResponseEventSessionErrorPropertiesError struct {
	// This field can have the runtime type of [shared.ProviderAuthErrorData],
	// [shared.UnknownErrorData], [interface{}].
	Data interface{}                                           `json:"data,required"`
	Name EventListResponseEventSessionErrorPropertiesErrorName `json:"name,required"`
	JSON eventListResponseEventSessionErrorPropertiesErrorJSON `json:"-"`
	// contains filtered or unexported fields
}

func (EventListResponseEventSessionErrorPropertiesError) AsUnion

AsUnion returns a EventListResponseEventSessionErrorPropertiesErrorUnion interface which you can cast to the specific types for more type safety.

Possible runtime types of the union are shared.ProviderAuthError, shared.UnknownError, EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError.

func (*EventListResponseEventSessionErrorPropertiesError) UnmarshalJSON

func (r *EventListResponseEventSessionErrorPropertiesError) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError

type EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError struct {
	Data interface{}                                                                   `json:"data,required"`
	Name EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorName `json:"name,required"`
	JSON eventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorJSON `json:"-"`
}

func (EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError) ImplementsEventListResponseEventSessionErrorPropertiesError

func (r EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError) ImplementsEventListResponseEventSessionErrorPropertiesError()

func (*EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError) UnmarshalJSON

type EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorName

type EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorName string
const (
	EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorNameMessageOutputLengthError EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
)

func (EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthErrorName) IsKnown

type EventListResponseEventSessionErrorPropertiesErrorName

type EventListResponseEventSessionErrorPropertiesErrorName string
const (
	EventListResponseEventSessionErrorPropertiesErrorNameProviderAuthError        EventListResponseEventSessionErrorPropertiesErrorName = "ProviderAuthError"
	EventListResponseEventSessionErrorPropertiesErrorNameUnknownError             EventListResponseEventSessionErrorPropertiesErrorName = "UnknownError"
	EventListResponseEventSessionErrorPropertiesErrorNameMessageOutputLengthError EventListResponseEventSessionErrorPropertiesErrorName = "MessageOutputLengthError"
)

func (EventListResponseEventSessionErrorPropertiesErrorName) IsKnown

type EventListResponseEventSessionErrorPropertiesErrorUnion

type EventListResponseEventSessionErrorPropertiesErrorUnion interface {
	ImplementsEventListResponseEventSessionErrorPropertiesError()
}

Union satisfied by shared.ProviderAuthError, shared.UnknownError or EventListResponseEventSessionErrorPropertiesErrorMessageOutputLengthError.

type EventListResponseEventSessionErrorType

type EventListResponseEventSessionErrorType string
const (
	EventListResponseEventSessionErrorTypeSessionError EventListResponseEventSessionErrorType = "session.error"
)

func (EventListResponseEventSessionErrorType) IsKnown

type EventListResponseEventSessionUpdated

type EventListResponseEventSessionUpdated struct {
	Properties EventListResponseEventSessionUpdatedProperties `json:"properties,required"`
	Type       EventListResponseEventSessionUpdatedType       `json:"type,required"`
	JSON       eventListResponseEventSessionUpdatedJSON       `json:"-"`
}

func (*EventListResponseEventSessionUpdated) UnmarshalJSON

func (r *EventListResponseEventSessionUpdated) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionUpdatedProperties

type EventListResponseEventSessionUpdatedProperties struct {
	Info Session                                            `json:"info,required"`
	JSON eventListResponseEventSessionUpdatedPropertiesJSON `json:"-"`
}

func (*EventListResponseEventSessionUpdatedProperties) UnmarshalJSON

func (r *EventListResponseEventSessionUpdatedProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventSessionUpdatedType

type EventListResponseEventSessionUpdatedType string
const (
	EventListResponseEventSessionUpdatedTypeSessionUpdated EventListResponseEventSessionUpdatedType = "session.updated"
)

func (EventListResponseEventSessionUpdatedType) IsKnown

type EventListResponseEventStorageWrite

type EventListResponseEventStorageWrite struct {
	Properties EventListResponseEventStorageWriteProperties `json:"properties,required"`
	Type       EventListResponseEventStorageWriteType       `json:"type,required"`
	JSON       eventListResponseEventStorageWriteJSON       `json:"-"`
}

func (*EventListResponseEventStorageWrite) UnmarshalJSON

func (r *EventListResponseEventStorageWrite) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventStorageWriteProperties

type EventListResponseEventStorageWriteProperties struct {
	Key     string                                           `json:"key,required"`
	Content interface{}                                      `json:"content"`
	JSON    eventListResponseEventStorageWritePropertiesJSON `json:"-"`
}

func (*EventListResponseEventStorageWriteProperties) UnmarshalJSON

func (r *EventListResponseEventStorageWriteProperties) UnmarshalJSON(data []byte) (err error)

type EventListResponseEventStorageWriteType

type EventListResponseEventStorageWriteType string
const (
	EventListResponseEventStorageWriteTypeStorageWrite EventListResponseEventStorageWriteType = "storage.write"
)

func (EventListResponseEventStorageWriteType) IsKnown

type EventListResponseType

type EventListResponseType string
const (
	EventListResponseTypeStorageWrite         EventListResponseType = "storage.write"
	EventListResponseTypeInstallationUpdated  EventListResponseType = "installation.updated"
	EventListResponseTypeLspClientDiagnostics EventListResponseType = "lsp.client.diagnostics"
	EventListResponseTypePermissionUpdated    EventListResponseType = "permission.updated"
	EventListResponseTypeMessageUpdated       EventListResponseType = "message.updated"
	EventListResponseTypeMessagePartUpdated   EventListResponseType = "message.part.updated"
	EventListResponseTypeSessionUpdated       EventListResponseType = "session.updated"
	EventListResponseTypeSessionDeleted       EventListResponseType = "session.deleted"
	EventListResponseTypeSessionError         EventListResponseType = "session.error"
)

func (EventListResponseType) IsKnown

func (r EventListResponseType) IsKnown() bool

type EventService

type EventService struct {
	Options []option.RequestOption
}

EventService 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 NewEventService method instead.

func NewEventService

func NewEventService(opts ...option.RequestOption) (r *EventService)

NewEventService 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 (*EventService) List

func (r *EventService) List(ctx context.Context, opts ...option.RequestOption) (res *EventListResponse, err error)

Get events

type FilePart

type FilePart struct {
	MediaType string       `json:"mediaType,required"`
	Type      FilePartType `json:"type,required"`
	URL       string       `json:"url,required"`
	Filename  string       `json:"filename"`
	JSON      filePartJSON `json:"-"`
}

func (*FilePart) UnmarshalJSON

func (r *FilePart) UnmarshalJSON(data []byte) (err error)

type FilePartParam

type FilePartParam struct {
	MediaType param.Field[string]       `json:"mediaType,required"`
	Type      param.Field[FilePartType] `json:"type,required"`
	URL       param.Field[string]       `json:"url,required"`
	Filename  param.Field[string]       `json:"filename"`
}

func (FilePartParam) MarshalJSON

func (r FilePartParam) MarshalJSON() (data []byte, err error)

type FilePartType

type FilePartType string
const (
	FilePartTypeFile FilePartType = "file"
)

func (FilePartType) IsKnown

func (r FilePartType) IsKnown() bool

type FileSearchParams

type FileSearchParams struct {
	Query param.Field[string] `query:"query,required"`
}

func (FileSearchParams) URLQuery

func (r FileSearchParams) URLQuery() (v url.Values)

URLQuery serializes FileSearchParams's query parameters as `url.Values`.

type FileService

type FileService struct {
	Options []option.RequestOption
}

FileService 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 NewFileService method instead.

func NewFileService

func NewFileService(opts ...option.RequestOption) (r *FileService)

NewFileService 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 (*FileService) Search

func (r *FileService) Search(ctx context.Context, query FileSearchParams, opts ...option.RequestOption) (res *[]string, err error)

Search for files

type Keybinds

type Keybinds struct {
	// Exit the application
	AppExit string `json:"app_exit"`
	// Open external editor
	EditorOpen string `json:"editor_open"`
	// Show help dialog
	Help string `json:"help"`
	// Navigate to next history item
	HistoryNext string `json:"history_next"`
	// Navigate to previous history item
	HistoryPrevious string `json:"history_previous"`
	// Clear input field
	InputClear string `json:"input_clear"`
	// Insert newline in input
	InputNewline string `json:"input_newline"`
	// Paste from clipboard
	InputPaste string `json:"input_paste"`
	// Submit input
	InputSubmit string `json:"input_submit"`
	// Leader key for keybind combinations
	Leader string `json:"leader"`
	// Navigate to first message
	MessagesFirst string `json:"messages_first"`
	// Scroll messages down by half page
	MessagesHalfPageDown string `json:"messages_half_page_down"`
	// Scroll messages up by half page
	MessagesHalfPageUp string `json:"messages_half_page_up"`
	// Navigate to last message
	MessagesLast string `json:"messages_last"`
	// Navigate to next message
	MessagesNext string `json:"messages_next"`
	// Scroll messages down by one page
	MessagesPageDown string `json:"messages_page_down"`
	// Scroll messages up by one page
	MessagesPageUp string `json:"messages_page_up"`
	// Navigate to previous message
	MessagesPrevious string `json:"messages_previous"`
	// List available models
	ModelList string `json:"model_list"`
	// Initialize project configuration
	ProjectInit string `json:"project_init"`
	// Toggle compact mode for session
	SessionCompact string `json:"session_compact"`
	// Interrupt current session
	SessionInterrupt string `json:"session_interrupt"`
	// List all sessions
	SessionList string `json:"session_list"`
	// Create a new session
	SessionNew string `json:"session_new"`
	// Share current session
	SessionShare string `json:"session_share"`
	// List available themes
	ThemeList string `json:"theme_list"`
	// Show tool details
	ToolDetails string       `json:"tool_details"`
	JSON        keybindsJSON `json:"-"`
}

func (*Keybinds) UnmarshalJSON

func (r *Keybinds) UnmarshalJSON(data []byte) (err error)

type McpLocal

type McpLocal struct {
	// Command and arguments to run the MCP server
	Command []string `json:"command,required"`
	// Type of MCP server connection
	Type McpLocalType `json:"type,required"`
	// Environment variables to set when running the MCP server
	Environment map[string]string `json:"environment"`
	JSON        mcpLocalJSON      `json:"-"`
}

func (*McpLocal) UnmarshalJSON

func (r *McpLocal) UnmarshalJSON(data []byte) (err error)

type McpLocalType

type McpLocalType string

Type of MCP server connection

const (
	McpLocalTypeLocal McpLocalType = "local"
)

func (McpLocalType) IsKnown

func (r McpLocalType) IsKnown() bool

type McpRemote

type McpRemote struct {
	// Type of MCP server connection
	Type McpRemoteType `json:"type,required"`
	// URL of the remote MCP server
	URL  string        `json:"url,required"`
	JSON mcpRemoteJSON `json:"-"`
}

func (*McpRemote) UnmarshalJSON

func (r *McpRemote) UnmarshalJSON(data []byte) (err error)

type McpRemoteType

type McpRemoteType string

Type of MCP server connection

const (
	McpRemoteTypeRemote McpRemoteType = "remote"
)

func (McpRemoteType) IsKnown

func (r McpRemoteType) IsKnown() bool

type Message

type Message struct {
	ID       string          `json:"id,required"`
	Metadata MessageMetadata `json:"metadata,required"`
	Parts    []MessagePart   `json:"parts,required"`
	Role     MessageRole     `json:"role,required"`
	JSON     messageJSON     `json:"-"`
}

func (*Message) UnmarshalJSON

func (r *Message) UnmarshalJSON(data []byte) (err error)

type MessageMetadata

type MessageMetadata struct {
	SessionID string                         `json:"sessionID,required"`
	Time      MessageMetadataTime            `json:"time,required"`
	Tool      map[string]MessageMetadataTool `json:"tool,required"`
	Assistant MessageMetadataAssistant       `json:"assistant"`
	Error     MessageMetadataError           `json:"error"`
	JSON      messageMetadataJSON            `json:"-"`
}

func (*MessageMetadata) UnmarshalJSON

func (r *MessageMetadata) UnmarshalJSON(data []byte) (err error)

type MessageMetadataAssistant

type MessageMetadataAssistant struct {
	Cost       float64                        `json:"cost,required"`
	ModelID    string                         `json:"modelID,required"`
	Path       MessageMetadataAssistantPath   `json:"path,required"`
	ProviderID string                         `json:"providerID,required"`
	System     []string                       `json:"system,required"`
	Tokens     MessageMetadataAssistantTokens `json:"tokens,required"`
	Summary    bool                           `json:"summary"`
	JSON       messageMetadataAssistantJSON   `json:"-"`
}

func (*MessageMetadataAssistant) UnmarshalJSON

func (r *MessageMetadataAssistant) UnmarshalJSON(data []byte) (err error)

type MessageMetadataAssistantPath

type MessageMetadataAssistantPath struct {
	Cwd  string                           `json:"cwd,required"`
	Root string                           `json:"root,required"`
	JSON messageMetadataAssistantPathJSON `json:"-"`
}

func (*MessageMetadataAssistantPath) UnmarshalJSON

func (r *MessageMetadataAssistantPath) UnmarshalJSON(data []byte) (err error)

type MessageMetadataAssistantTokens

type MessageMetadataAssistantTokens struct {
	Cache     MessageMetadataAssistantTokensCache `json:"cache,required"`
	Input     float64                             `json:"input,required"`
	Output    float64                             `json:"output,required"`
	Reasoning float64                             `json:"reasoning,required"`
	JSON      messageMetadataAssistantTokensJSON  `json:"-"`
}

func (*MessageMetadataAssistantTokens) UnmarshalJSON

func (r *MessageMetadataAssistantTokens) UnmarshalJSON(data []byte) (err error)

type MessageMetadataAssistantTokensCache

type MessageMetadataAssistantTokensCache struct {
	Read  float64                                 `json:"read,required"`
	Write float64                                 `json:"write,required"`
	JSON  messageMetadataAssistantTokensCacheJSON `json:"-"`
}

func (*MessageMetadataAssistantTokensCache) UnmarshalJSON

func (r *MessageMetadataAssistantTokensCache) UnmarshalJSON(data []byte) (err error)

type MessageMetadataError

type MessageMetadataError struct {
	// This field can have the runtime type of [shared.ProviderAuthErrorData],
	// [shared.UnknownErrorData], [interface{}].
	Data interface{}              `json:"data,required"`
	Name MessageMetadataErrorName `json:"name,required"`
	JSON messageMetadataErrorJSON `json:"-"`
	// contains filtered or unexported fields
}

func (MessageMetadataError) AsUnion

AsUnion returns a MessageMetadataErrorUnion interface which you can cast to the specific types for more type safety.

Possible runtime types of the union are shared.ProviderAuthError, shared.UnknownError, MessageMetadataErrorMessageOutputLengthError.

func (*MessageMetadataError) UnmarshalJSON

func (r *MessageMetadataError) UnmarshalJSON(data []byte) (err error)

type MessageMetadataErrorMessageOutputLengthError

type MessageMetadataErrorMessageOutputLengthError struct {
	Data interface{}                                      `json:"data,required"`
	Name MessageMetadataErrorMessageOutputLengthErrorName `json:"name,required"`
	JSON messageMetadataErrorMessageOutputLengthErrorJSON `json:"-"`
}

func (MessageMetadataErrorMessageOutputLengthError) ImplementsMessageMetadataError

func (r MessageMetadataErrorMessageOutputLengthError) ImplementsMessageMetadataError()

func (*MessageMetadataErrorMessageOutputLengthError) UnmarshalJSON

func (r *MessageMetadataErrorMessageOutputLengthError) UnmarshalJSON(data []byte) (err error)

type MessageMetadataErrorMessageOutputLengthErrorName

type MessageMetadataErrorMessageOutputLengthErrorName string
const (
	MessageMetadataErrorMessageOutputLengthErrorNameMessageOutputLengthError MessageMetadataErrorMessageOutputLengthErrorName = "MessageOutputLengthError"
)

func (MessageMetadataErrorMessageOutputLengthErrorName) IsKnown

type MessageMetadataErrorName

type MessageMetadataErrorName string
const (
	MessageMetadataErrorNameProviderAuthError        MessageMetadataErrorName = "ProviderAuthError"
	MessageMetadataErrorNameUnknownError             MessageMetadataErrorName = "UnknownError"
	MessageMetadataErrorNameMessageOutputLengthError MessageMetadataErrorName = "MessageOutputLengthError"
)

func (MessageMetadataErrorName) IsKnown

func (r MessageMetadataErrorName) IsKnown() bool

type MessageMetadataErrorUnion

type MessageMetadataErrorUnion interface {
	ImplementsMessageMetadataError()
}

Union satisfied by shared.ProviderAuthError, shared.UnknownError or MessageMetadataErrorMessageOutputLengthError.

type MessageMetadataTime

type MessageMetadataTime struct {
	Created   float64                 `json:"created,required"`
	Completed float64                 `json:"completed"`
	JSON      messageMetadataTimeJSON `json:"-"`
}

func (*MessageMetadataTime) UnmarshalJSON

func (r *MessageMetadataTime) UnmarshalJSON(data []byte) (err error)

type MessageMetadataTool

type MessageMetadataTool struct {
	Time        MessageMetadataToolTime `json:"time,required"`
	Title       string                  `json:"title,required"`
	ExtraFields map[string]interface{}  `json:"-,extras"`
	JSON        messageMetadataToolJSON `json:"-"`
}

func (*MessageMetadataTool) UnmarshalJSON

func (r *MessageMetadataTool) UnmarshalJSON(data []byte) (err error)

type MessageMetadataToolTime

type MessageMetadataToolTime struct {
	End   float64                     `json:"end,required"`
	Start float64                     `json:"start,required"`
	JSON  messageMetadataToolTimeJSON `json:"-"`
}

func (*MessageMetadataToolTime) UnmarshalJSON

func (r *MessageMetadataToolTime) UnmarshalJSON(data []byte) (err error)

type MessagePart

type MessagePart struct {
	Type      MessagePartType `json:"type,required"`
	Filename  string          `json:"filename"`
	MediaType string          `json:"mediaType"`
	// This field can have the runtime type of [map[string]interface{}].
	ProviderMetadata interface{} `json:"providerMetadata"`
	SourceID         string      `json:"sourceId"`
	Text             string      `json:"text"`
	Title            string      `json:"title"`
	// This field can have the runtime type of [ToolInvocationPartToolInvocation].
	ToolInvocation interface{}     `json:"toolInvocation"`
	URL            string          `json:"url"`
	JSON           messagePartJSON `json:"-"`
	// contains filtered or unexported fields
}

func (MessagePart) AsUnion

func (r MessagePart) AsUnion() MessagePartUnion

AsUnion returns a MessagePartUnion interface which you can cast to the specific types for more type safety.

Possible runtime types of the union are TextPart, ReasoningPart, ToolInvocationPart, SourceURLPart, FilePart, StepStartPart.

func (*MessagePart) UnmarshalJSON

func (r *MessagePart) UnmarshalJSON(data []byte) (err error)

type MessagePartParam

type MessagePartParam struct {
	Type             param.Field[MessagePartType] `json:"type,required"`
	Filename         param.Field[string]          `json:"filename"`
	MediaType        param.Field[string]          `json:"mediaType"`
	ProviderMetadata param.Field[interface{}]     `json:"providerMetadata"`
	SourceID         param.Field[string]          `json:"sourceId"`
	Text             param.Field[string]          `json:"text"`
	Title            param.Field[string]          `json:"title"`
	ToolInvocation   param.Field[interface{}]     `json:"toolInvocation"`
	URL              param.Field[string]          `json:"url"`
}

func (MessagePartParam) MarshalJSON

func (r MessagePartParam) MarshalJSON() (data []byte, err error)

type MessagePartType

type MessagePartType string
const (
	MessagePartTypeText           MessagePartType = "text"
	MessagePartTypeReasoning      MessagePartType = "reasoning"
	MessagePartTypeToolInvocation MessagePartType = "tool-invocation"
	MessagePartTypeSourceURL      MessagePartType = "source-url"
	MessagePartTypeFile           MessagePartType = "file"
	MessagePartTypeStepStart      MessagePartType = "step-start"
)

func (MessagePartType) IsKnown

func (r MessagePartType) IsKnown() bool

type MessagePartUnion

type MessagePartUnion interface {
	// contains filtered or unexported methods
}

Union satisfied by TextPart, ReasoningPart, ToolInvocationPart, SourceURLPart, FilePart or StepStartPart.

type MessagePartUnionParam

type MessagePartUnionParam interface {
	// contains filtered or unexported methods
}

Satisfied by TextPartParam, ReasoningPartParam, ToolInvocationPartParam, SourceURLPartParam, FilePartParam, StepStartPartParam, MessagePartParam.

type MessageRole

type MessageRole string
const (
	MessageRoleUser      MessageRole = "user"
	MessageRoleAssistant MessageRole = "assistant"
)

func (MessageRole) IsKnown

func (r MessageRole) IsKnown() bool

type Model added in v0.2.0

type Model struct {
	ID          string                 `json:"id,required"`
	Attachment  bool                   `json:"attachment,required"`
	Cost        ModelCost              `json:"cost,required"`
	Limit       ModelLimit             `json:"limit,required"`
	Name        string                 `json:"name,required"`
	Options     map[string]interface{} `json:"options,required"`
	Reasoning   bool                   `json:"reasoning,required"`
	Temperature bool                   `json:"temperature,required"`
	ToolCall    bool                   `json:"tool_call,required"`
	JSON        modelJSON              `json:"-"`
}

func (*Model) UnmarshalJSON added in v0.2.0

func (r *Model) UnmarshalJSON(data []byte) (err error)

type ModelCost added in v0.2.0

type ModelCost struct {
	Input      float64       `json:"input,required"`
	Output     float64       `json:"output,required"`
	CacheRead  float64       `json:"cache_read"`
	CacheWrite float64       `json:"cache_write"`
	JSON       modelCostJSON `json:"-"`
}

func (*ModelCost) UnmarshalJSON added in v0.2.0

func (r *ModelCost) UnmarshalJSON(data []byte) (err error)

type ModelLimit added in v0.2.0

type ModelLimit struct {
	Context float64        `json:"context,required"`
	Output  float64        `json:"output,required"`
	JSON    modelLimitJSON `json:"-"`
}

func (*ModelLimit) UnmarshalJSON added in v0.2.0

func (r *ModelLimit) UnmarshalJSON(data []byte) (err error)

type Provider added in v0.2.0

type Provider struct {
	ID     string           `json:"id,required"`
	Env    []string         `json:"env,required"`
	Models map[string]Model `json:"models,required"`
	Name   string           `json:"name,required"`
	API    string           `json:"api"`
	Npm    string           `json:"npm"`
	JSON   providerJSON     `json:"-"`
}

func (*Provider) UnmarshalJSON added in v0.2.0

func (r *Provider) UnmarshalJSON(data []byte) (err error)

type ProviderAuthError

type ProviderAuthError = shared.ProviderAuthError

This is an alias to an internal type.

type ProviderAuthErrorData

type ProviderAuthErrorData = shared.ProviderAuthErrorData

This is an alias to an internal type.

type ProviderAuthErrorName

type ProviderAuthErrorName = shared.ProviderAuthErrorName

This is an alias to an internal type.

type ReasoningPart

type ReasoningPart struct {
	Text             string                 `json:"text,required"`
	Type             ReasoningPartType      `json:"type,required"`
	ProviderMetadata map[string]interface{} `json:"providerMetadata"`
	JSON             reasoningPartJSON      `json:"-"`
}

func (*ReasoningPart) UnmarshalJSON

func (r *ReasoningPart) UnmarshalJSON(data []byte) (err error)

type ReasoningPartParam

type ReasoningPartParam struct {
	Text             param.Field[string]                 `json:"text,required"`
	Type             param.Field[ReasoningPartType]      `json:"type,required"`
	ProviderMetadata param.Field[map[string]interface{}] `json:"providerMetadata"`
}

func (ReasoningPartParam) MarshalJSON

func (r ReasoningPartParam) MarshalJSON() (data []byte, err error)

type ReasoningPartType

type ReasoningPartType string
const (
	ReasoningPartTypeReasoning ReasoningPartType = "reasoning"
)

func (ReasoningPartType) IsKnown

func (r ReasoningPartType) IsKnown() bool

type Session

type Session struct {
	ID       string       `json:"id,required"`
	Time     SessionTime  `json:"time,required"`
	Title    string       `json:"title,required"`
	Version  string       `json:"version,required"`
	ParentID string       `json:"parentID"`
	Share    SessionShare `json:"share"`
	JSON     sessionJSON  `json:"-"`
}

func (*Session) UnmarshalJSON

func (r *Session) UnmarshalJSON(data []byte) (err error)

type SessionChatParams

type SessionChatParams struct {
	ModelID    param.Field[string]                  `json:"modelID,required"`
	Parts      param.Field[[]MessagePartUnionParam] `json:"parts,required"`
	ProviderID param.Field[string]                  `json:"providerID,required"`
	SessionID  param.Field[string]                  `json:"sessionID,required"`
}

func (SessionChatParams) MarshalJSON

func (r SessionChatParams) MarshalJSON() (data []byte, err error)

type SessionInitParams

type SessionInitParams struct {
	ModelID    param.Field[string] `json:"modelID,required"`
	ProviderID param.Field[string] `json:"providerID,required"`
}

func (SessionInitParams) MarshalJSON

func (r SessionInitParams) MarshalJSON() (data []byte, err error)

type SessionService

type SessionService struct {
	Options []option.RequestOption
}

SessionService 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 NewSessionService method instead.

func NewSessionService

func NewSessionService(opts ...option.RequestOption) (r *SessionService)

NewSessionService 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 (*SessionService) Abort

func (r *SessionService) Abort(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error)

Abort a session

func (*SessionService) Chat

func (r *SessionService) Chat(ctx context.Context, id string, body SessionChatParams, opts ...option.RequestOption) (res *Message, err error)

Create and send a new message to a session

func (*SessionService) Delete

func (r *SessionService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *bool, err error)

Delete a session and all its data

func (*SessionService) Init

func (r *SessionService) Init(ctx context.Context, id string, body SessionInitParams, opts ...option.RequestOption) (res *bool, err error)

Analyze the app and create an AGENTS.md file

func (*SessionService) List

func (r *SessionService) List(ctx context.Context, opts ...option.RequestOption) (res *[]Session, err error)

List all sessions

func (*SessionService) Messages

func (r *SessionService) Messages(ctx context.Context, id string, opts ...option.RequestOption) (res *[]Message, err error)

List messages for a session

func (*SessionService) New

func (r *SessionService) New(ctx context.Context, opts ...option.RequestOption) (res *Session, err error)

Create a new session

func (*SessionService) Share

func (r *SessionService) Share(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error)

Share a session

func (*SessionService) Summarize

func (r *SessionService) Summarize(ctx context.Context, id string, body SessionSummarizeParams, opts ...option.RequestOption) (res *bool, err error)

Summarize the session

func (*SessionService) Unshare

func (r *SessionService) Unshare(ctx context.Context, id string, opts ...option.RequestOption) (res *Session, err error)

Unshare the session

type SessionShare

type SessionShare struct {
	URL  string           `json:"url,required"`
	JSON sessionShareJSON `json:"-"`
}

func (*SessionShare) UnmarshalJSON

func (r *SessionShare) UnmarshalJSON(data []byte) (err error)

type SessionSummarizeParams

type SessionSummarizeParams struct {
	ModelID    param.Field[string] `json:"modelID,required"`
	ProviderID param.Field[string] `json:"providerID,required"`
}

func (SessionSummarizeParams) MarshalJSON

func (r SessionSummarizeParams) MarshalJSON() (data []byte, err error)

type SessionTime

type SessionTime struct {
	Created float64         `json:"created,required"`
	Updated float64         `json:"updated,required"`
	JSON    sessionTimeJSON `json:"-"`
}

func (*SessionTime) UnmarshalJSON

func (r *SessionTime) UnmarshalJSON(data []byte) (err error)

type SourceURLPart

type SourceURLPart struct {
	SourceID         string                 `json:"sourceId,required"`
	Type             SourceURLPartType      `json:"type,required"`
	URL              string                 `json:"url,required"`
	ProviderMetadata map[string]interface{} `json:"providerMetadata"`
	Title            string                 `json:"title"`
	JSON             sourceURLPartJSON      `json:"-"`
}

func (*SourceURLPart) UnmarshalJSON

func (r *SourceURLPart) UnmarshalJSON(data []byte) (err error)

type SourceURLPartParam

type SourceURLPartParam struct {
	SourceID         param.Field[string]                 `json:"sourceId,required"`
	Type             param.Field[SourceURLPartType]      `json:"type,required"`
	URL              param.Field[string]                 `json:"url,required"`
	ProviderMetadata param.Field[map[string]interface{}] `json:"providerMetadata"`
	Title            param.Field[string]                 `json:"title"`
}

func (SourceURLPartParam) MarshalJSON

func (r SourceURLPartParam) MarshalJSON() (data []byte, err error)

type SourceURLPartType

type SourceURLPartType string
const (
	SourceURLPartTypeSourceURL SourceURLPartType = "source-url"
)

func (SourceURLPartType) IsKnown

func (r SourceURLPartType) IsKnown() bool

type StepStartPart

type StepStartPart struct {
	Type StepStartPartType `json:"type,required"`
	JSON stepStartPartJSON `json:"-"`
}

func (*StepStartPart) UnmarshalJSON

func (r *StepStartPart) UnmarshalJSON(data []byte) (err error)

type StepStartPartParam

type StepStartPartParam struct {
	Type param.Field[StepStartPartType] `json:"type,required"`
}

func (StepStartPartParam) MarshalJSON

func (r StepStartPartParam) MarshalJSON() (data []byte, err error)

type StepStartPartType

type StepStartPartType string
const (
	StepStartPartTypeStepStart StepStartPartType = "step-start"
)

func (StepStartPartType) IsKnown

func (r StepStartPartType) IsKnown() bool

type TextPart

type TextPart struct {
	Text string       `json:"text,required"`
	Type TextPartType `json:"type,required"`
	JSON textPartJSON `json:"-"`
}

func (*TextPart) UnmarshalJSON

func (r *TextPart) UnmarshalJSON(data []byte) (err error)

type TextPartParam

type TextPartParam struct {
	Text param.Field[string]       `json:"text,required"`
	Type param.Field[TextPartType] `json:"type,required"`
}

func (TextPartParam) MarshalJSON

func (r TextPartParam) MarshalJSON() (data []byte, err error)

type TextPartType

type TextPartType string
const (
	TextPartTypeText TextPartType = "text"
)

func (TextPartType) IsKnown

func (r TextPartType) IsKnown() bool

type ToolCall

type ToolCall struct {
	State      ToolCallState `json:"state,required"`
	ToolCallID string        `json:"toolCallId,required"`
	ToolName   string        `json:"toolName,required"`
	Args       interface{}   `json:"args"`
	Step       float64       `json:"step"`
	JSON       toolCallJSON  `json:"-"`
}

func (*ToolCall) UnmarshalJSON

func (r *ToolCall) UnmarshalJSON(data []byte) (err error)

type ToolCallParam

type ToolCallParam struct {
	State      param.Field[ToolCallState] `json:"state,required"`
	ToolCallID param.Field[string]        `json:"toolCallId,required"`
	ToolName   param.Field[string]        `json:"toolName,required"`
	Args       param.Field[interface{}]   `json:"args"`
	Step       param.Field[float64]       `json:"step"`
}

func (ToolCallParam) MarshalJSON

func (r ToolCallParam) MarshalJSON() (data []byte, err error)

type ToolCallState

type ToolCallState string
const (
	ToolCallStateCall ToolCallState = "call"
)

func (ToolCallState) IsKnown

func (r ToolCallState) IsKnown() bool

type ToolInvocationPart

type ToolInvocationPart struct {
	ToolInvocation ToolInvocationPartToolInvocation `json:"toolInvocation,required"`
	Type           ToolInvocationPartType           `json:"type,required"`
	JSON           toolInvocationPartJSON           `json:"-"`
}

func (*ToolInvocationPart) UnmarshalJSON

func (r *ToolInvocationPart) UnmarshalJSON(data []byte) (err error)

type ToolInvocationPartParam

type ToolInvocationPartParam struct {
	ToolInvocation param.Field[ToolInvocationPartToolInvocationUnionParam] `json:"toolInvocation,required"`
	Type           param.Field[ToolInvocationPartType]                     `json:"type,required"`
}

func (ToolInvocationPartParam) MarshalJSON

func (r ToolInvocationPartParam) MarshalJSON() (data []byte, err error)

type ToolInvocationPartToolInvocation

type ToolInvocationPartToolInvocation struct {
	State      ToolInvocationPartToolInvocationState `json:"state,required"`
	ToolCallID string                                `json:"toolCallId,required"`
	ToolName   string                                `json:"toolName,required"`
	// This field can have the runtime type of [interface{}].
	Args   interface{}                          `json:"args"`
	Result string                               `json:"result"`
	Step   float64                              `json:"step"`
	JSON   toolInvocationPartToolInvocationJSON `json:"-"`
	// contains filtered or unexported fields
}

func (ToolInvocationPartToolInvocation) AsUnion

AsUnion returns a ToolInvocationPartToolInvocationUnion interface which you can cast to the specific types for more type safety.

Possible runtime types of the union are ToolCall, ToolPartialCall, ToolResult.

func (*ToolInvocationPartToolInvocation) UnmarshalJSON

func (r *ToolInvocationPartToolInvocation) UnmarshalJSON(data []byte) (err error)

type ToolInvocationPartToolInvocationParam

type ToolInvocationPartToolInvocationParam struct {
	State      param.Field[ToolInvocationPartToolInvocationState] `json:"state,required"`
	ToolCallID param.Field[string]                                `json:"toolCallId,required"`
	ToolName   param.Field[string]                                `json:"toolName,required"`
	Args       param.Field[interface{}]                           `json:"args"`
	Result     param.Field[string]                                `json:"result"`
	Step       param.Field[float64]                               `json:"step"`
}

func (ToolInvocationPartToolInvocationParam) MarshalJSON

func (r ToolInvocationPartToolInvocationParam) MarshalJSON() (data []byte, err error)

type ToolInvocationPartToolInvocationState

type ToolInvocationPartToolInvocationState string
const (
	ToolInvocationPartToolInvocationStateCall        ToolInvocationPartToolInvocationState = "call"
	ToolInvocationPartToolInvocationStatePartialCall ToolInvocationPartToolInvocationState = "partial-call"
	ToolInvocationPartToolInvocationStateResult      ToolInvocationPartToolInvocationState = "result"
)

func (ToolInvocationPartToolInvocationState) IsKnown

type ToolInvocationPartToolInvocationUnion

type ToolInvocationPartToolInvocationUnion interface {
	// contains filtered or unexported methods
}

Union satisfied by ToolCall, ToolPartialCall or ToolResult.

type ToolInvocationPartToolInvocationUnionParam

type ToolInvocationPartToolInvocationUnionParam interface {
	// contains filtered or unexported methods
}

Satisfied by ToolCallParam, ToolPartialCallParam, ToolResultParam, ToolInvocationPartToolInvocationParam.

type ToolInvocationPartType

type ToolInvocationPartType string
const (
	ToolInvocationPartTypeToolInvocation ToolInvocationPartType = "tool-invocation"
)

func (ToolInvocationPartType) IsKnown

func (r ToolInvocationPartType) IsKnown() bool

type ToolPartialCall

type ToolPartialCall struct {
	State      ToolPartialCallState `json:"state,required"`
	ToolCallID string               `json:"toolCallId,required"`
	ToolName   string               `json:"toolName,required"`
	Args       interface{}          `json:"args"`
	Step       float64              `json:"step"`
	JSON       toolPartialCallJSON  `json:"-"`
}

func (*ToolPartialCall) UnmarshalJSON

func (r *ToolPartialCall) UnmarshalJSON(data []byte) (err error)

type ToolPartialCallParam

type ToolPartialCallParam struct {
	State      param.Field[ToolPartialCallState] `json:"state,required"`
	ToolCallID param.Field[string]               `json:"toolCallId,required"`
	ToolName   param.Field[string]               `json:"toolName,required"`
	Args       param.Field[interface{}]          `json:"args"`
	Step       param.Field[float64]              `json:"step"`
}

func (ToolPartialCallParam) MarshalJSON

func (r ToolPartialCallParam) MarshalJSON() (data []byte, err error)

type ToolPartialCallState

type ToolPartialCallState string
const (
	ToolPartialCallStatePartialCall ToolPartialCallState = "partial-call"
)

func (ToolPartialCallState) IsKnown

func (r ToolPartialCallState) IsKnown() bool

type ToolResult

type ToolResult struct {
	Result     string          `json:"result,required"`
	State      ToolResultState `json:"state,required"`
	ToolCallID string          `json:"toolCallId,required"`
	ToolName   string          `json:"toolName,required"`
	Args       interface{}     `json:"args"`
	Step       float64         `json:"step"`
	JSON       toolResultJSON  `json:"-"`
}

func (*ToolResult) UnmarshalJSON

func (r *ToolResult) UnmarshalJSON(data []byte) (err error)

type ToolResultParam

type ToolResultParam struct {
	Result     param.Field[string]          `json:"result,required"`
	State      param.Field[ToolResultState] `json:"state,required"`
	ToolCallID param.Field[string]          `json:"toolCallId,required"`
	ToolName   param.Field[string]          `json:"toolName,required"`
	Args       param.Field[interface{}]     `json:"args"`
	Step       param.Field[float64]         `json:"step"`
}

func (ToolResultParam) MarshalJSON

func (r ToolResultParam) MarshalJSON() (data []byte, err error)

type ToolResultState

type ToolResultState string
const (
	ToolResultStateResult ToolResultState = "result"
)

func (ToolResultState) IsKnown

func (r ToolResultState) IsKnown() bool

type UnknownError

type UnknownError = shared.UnknownError

This is an alias to an internal type.

type UnknownErrorData

type UnknownErrorData = shared.UnknownErrorData

This is an alias to an internal type.

type UnknownErrorName

type UnknownErrorName = shared.UnknownErrorName

This is an alias to an internal type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL