Documentation
¶
Index ¶
- Constants
- func AdvancePluginGeneration(root string) error
- func CheckPlugin(root, directory string) error
- func ConfigDir(lookup func(string) (string, bool)) string
- func DataDir(lookup func(string) (string, bool)) string
- func DecodeHistory(reader io.Reader) ([][]byte, int64, error)
- func HomeEnvironment(home string) map[string]string
- func IsMissing(err error) bool
- func ModelSelectionShapeError(value string) error
- func NewID(prefix string) string
- func NewMessageID() string
- func ReadHistory(ctx context.Context, executable, scratchDir string, environment []string, ...) (rows [][]byte, more bool, err error)
- func SessionPath(id string) string
- func WritePlugin(root, config string, ownsHome bool) (string, error)
- type Catalog
- type Client
- func (c *Client) Args() []string
- func (c *Client) Do(ctx context.Context, directory, method, path string, body, out any) error
- func (c *Client) Interrupt(ctx context.Context, dir, id string) error
- func (c *Client) ReadAddress(stdout io.Reader) error
- func (c *Client) Replay(ctx context.Context, dir string, events []SyncEvent) error
- func (c *Client) Session(ctx context.Context, dir, id string) (NativeSession, error)
- func (c *Client) Subscribe(ctx context.Context) (*Stream, error)
- func (c *Client) TurnMessages(ctx context.Context, dir, id, messageID string) ([]NativeMessage, error)
- func (c *Client) UsageAccess(ctx context.Context, directory, providerID, modelID string) (usage.Access, error)
- func (c *Client) UsageGateways(ctx context.Context, directory string, lookup func(string) (string, bool)) ([]gateway.Route, error)
- type CommandRequest
- type Event
- type HTTPError
- type MessageRequest
- type ModelSelector
- type NativeAgent
- type NativeAttachment
- type NativeCommand
- type NativeError
- type NativeMessage
- type NativeMessageInfo
- type NativePart
- type NativeSession
- type NativeSessionStatus
- type NativeTodo
- type NativeTokens
- type OutputFormat
- type PermissionRequest
- type PermissionTool
- type ProviderInfo
- type ProviderModel
- type ProviderModelCapabilities
- type ProviderModelInputCapabilities
- type QuestionInfo
- type QuestionOption
- type QuestionRequest
- type QuestionTool
- type Stream
- type SyncEvent
Constants ¶
const CarrierKey = "acp-go-opencode"
const EventCapacity = 256
const HistoryPageBytes = 8 << 20
HistoryPageBytes bounds the event data one history read selects, so a long conversation reads as several bounded pages.
const InternalEnvPrefix = "ACP_GO_OPENCODE_INTERNAL_"
const MaxBodyBytes = 64 << 20
const OutputFormatJSONSchema = "json_schema"
const ServerUsername = "opencode"
ServerUsername is the basic-auth user the adapter configures the native server with and sends on every request.
Variables ¶
This section is empty.
Functions ¶
func AdvancePluginGeneration ¶ added in v0.2.0
AdvancePluginGeneration makes the environment plugin forget the session carriers it read, so the next shell in each session reads its carrier again.
func CheckPlugin ¶ added in v0.2.0
func DecodeHistory ¶ added in v0.2.0
DecodeHistory decodes the native database command's JSON rows into mirror rows one row at a time and returns the bytes of event data they held. The database keeps each event's data as JSON text.
func HomeEnvironment ¶ added in v0.2.0
func ModelSelectionShapeError ¶ added in v0.2.0
func NewMessageID ¶ added in v0.2.0
func NewMessageID() string
NewMessageID uses the native timestamp layout so later CLI messages sort after it.
func ReadHistory ¶ added in v0.2.0
func ReadHistory(ctx context.Context, executable, scratchDir string, environment []string, id string, cursors map[string]int64, pageBytes int64) (rows [][]byte, more bool, err error)
ReadHistory reads one page of the sync events of a conversation graph through the native database command: the session id and every descendant, each from after its cursor, or from its start when the cursor map has no entry for it. Events are ordered by sequence and id, so each conversation's events in a page continue its cursor without a gap. A page holds events until their data reaches pageBytes, and always at least one; more reports that the page reached the bound, so later events may remain. It returns each event as its encoded mirror row. The HTTP history route exports every session in the account in one response.
func SessionPath ¶ added in v0.2.0
Types ¶
type Catalog ¶ added in v0.2.0
type Catalog struct {
Providers []ProviderInfo `json:"providers"`
Default map[string]string `json:"default"`
}
type Client ¶
Client is an authenticated native HTTP endpoint shared by every session.
func (*Client) ReadAddress ¶ added in v0.2.0
ReadAddress reads the owned server's bound loopback address before any HTTP request.
func (*Client) TurnMessages ¶ added in v0.2.0
func (c *Client) TurnMessages(ctx context.Context, dir, id, messageID string) ([]NativeMessage, error)
TurnMessages reads the session's messages from the user message messageID onward, in native order. It pages back from the newest message until a page holds messageID, so the read costs the turn rather than the whole conversation; when the session has no such message it reads every message.
func (*Client) UsageAccess ¶ added in v0.2.0
func (c *Client) UsageAccess(ctx context.Context, directory, providerID, modelID string) (usage.Access, error)
UsageAccess resolves the addressed directory's effective credentials and model route.
func (*Client) UsageGateways ¶ added in v0.2.0
func (c *Client) UsageGateways(ctx context.Context, directory string, lookup func(string) (string, bool)) ([]gateway.Route, error)
UsageGateways lists the catalog providers configured with their own base URL: the routes opencode sends requests through, each with the key the catalog holds for it, an {env:NAME} key resolved through lookup.
type CommandRequest ¶
type CommandRequest struct {
MessageID string `json:"messageID,omitempty"`
Agent string `json:"agent,omitempty"`
Model string `json:"model,omitempty"`
Variant string `json:"variant,omitempty"`
Command string `json:"command"`
Arguments string `json:"arguments"`
Parts []map[string]any `json:"parts,omitempty"`
}
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Properties json.RawMessage `json:"properties"`
// SessionID is the native session the event addresses, or empty.
SessionID string `json:"-"`
}
Event is one native bus event from the global stream.
type HTTPError ¶
type HTTPError struct {
Status int
Native NativeError
}
type MessageRequest ¶
type MessageRequest struct {
MessageID string `json:"messageID,omitempty"`
Model *ModelSelector `json:"model,omitempty"`
Agent string `json:"agent,omitempty"`
Variant string `json:"variant,omitempty"`
Parts []map[string]any `json:"parts"`
Format *OutputFormat `json:"format,omitempty"`
}
type ModelSelector ¶
type NativeAgent ¶
type NativeAttachment ¶
type NativeAttachment struct {
ID string `json:"id"`
Type string `json:"type"`
Mime string `json:"mime"`
Filename string `json:"filename"`
URL string `json:"url"`
}
NativeAttachment is a native file part carried inside a completed tool state's attachments array. The URL is a data URL, a file URL/path, or a remote location.
type NativeCommand ¶
type NativeError ¶
type NativeMessage ¶
type NativeMessage struct {
Info NativeMessageInfo `json:"info"`
Parts []NativePart `json:"parts"`
}
type NativeMessageInfo ¶
type NativeMessageInfo struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Role string `json:"role"`
ParentID string `json:"parentID"`
ModelID string `json:"modelID"`
ProviderID string `json:"providerID"`
Finish string `json:"finish"`
Summary json.RawMessage `json:"summary,omitempty"`
Structured json.RawMessage `json:"structured,omitempty"`
Error *NativeError `json:"error,omitempty"`
Time struct {
Created int64 `json:"created"`
Completed int64 `json:"completed"`
} `json:"time"`
}
func (NativeMessageInfo) CompactionSummary ¶ added in v0.2.0
func (i NativeMessageInfo) CompactionSummary() bool
CompactionSummary reports whether an assistant message is a compaction summary. The member is true there; on a user message it holds the message's change summary instead.
type NativePart ¶
type NativePart struct {
Auto *bool `json:"auto,omitempty"`
ID string `json:"id"`
SessionID string `json:"sessionID"`
MessageID string `json:"messageID"`
Type string `json:"type"`
Text string `json:"text"`
CallID string `json:"callID"`
Tool string `json:"tool"`
State json.RawMessage `json:"state"`
Mime string `json:"mime"`
Filename string `json:"filename"`
URL string `json:"url"`
Tokens NativeTokens `json:"tokens"`
}
type NativeSession ¶
type NativeSession struct {
ParentID string `json:"parentID"`
ID string `json:"id"`
Title string `json:"title"`
Directory string `json:"directory"`
Agent string `json:"agent"`
Metadata map[string]any `json:"metadata"`
Model struct {
ID string `json:"id"`
ProviderID string `json:"providerID"`
} `json:"model"`
Time struct {
Created int64 `json:"created"`
Updated int64 `json:"updated"`
} `json:"time"`
}
type NativeSessionStatus ¶
type NativeSessionStatus struct {
Type string `json:"type"`
}
type NativeTodo ¶
type NativeTokens ¶
type NativeTokens struct {
Input float64 `json:"input"`
Output float64 `json:"output"`
Reasoning float64 `json:"reasoning"`
Cache struct {
Read float64 `json:"read"`
Write float64 `json:"write"`
} `json:"cache"`
}
NativeTokens is one model call's usage. Input excludes the tokens read from and written to the prompt cache, which Cache counts, and Output excludes Reasoning.
type OutputFormat ¶
type PermissionRequest ¶
type PermissionRequest struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Permission string `json:"permission"`
Patterns []string `json:"patterns"`
Tool PermissionTool `json:"tool"`
}
type PermissionTool ¶
type ProviderInfo ¶
type ProviderInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Models map[string]ProviderModel `json:"models"`
}
type ProviderModel ¶
type ProviderModel struct {
ID string `json:"id"`
Name string `json:"name"`
Limit map[string]any `json:"limit"`
Capabilities *ProviderModelCapabilities `json:"capabilities"`
// Variants are the model's named request presets, keyed by the name a
// prompt selects one with. On a reasoning model the catalog names them by
// effort level, so the keys are the effort levels the model supports.
Variants map[string]map[string]any `json:"variants"`
}
type ProviderModelCapabilities ¶
type ProviderModelCapabilities struct {
Input ProviderModelInputCapabilities `json:"input"`
}
ProviderModelCapabilities is the authenticated provider catalog's exhaustive per-model capability record.
type ProviderModelInputCapabilities ¶
type ProviderModelInputCapabilities struct {
Image *bool `json:"image"`
}
ProviderModelInputCapabilities reports which input kinds the model accepts. A nil field means the catalog did not state the fact either way.
type QuestionInfo ¶
type QuestionInfo struct {
Question string `json:"question"`
Options []QuestionOption `json:"options"`
Multiple bool `json:"multiple"`
Custom *bool `json:"custom,omitempty"`
}
func (QuestionInfo) AllowsCustom ¶ added in v0.2.0
func (q QuestionInfo) AllowsCustom() bool
AllowsCustom applies the native question default.
type QuestionOption ¶
type QuestionOption struct {
Label string `json:"label"`
}
type QuestionRequest ¶
type QuestionRequest struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Questions []QuestionInfo `json:"questions"`
Tool QuestionTool `json:"tool"`
}
type QuestionTool ¶
type Stream ¶ added in v0.2.0
type Stream struct {
Events chan Event
// contains filtered or unexported fields
}
Stream owns one ordered global SSE connection. Closing it joins its reader.
type SyncEvent ¶
type SyncEvent struct {
AggregateID string `json:"aggregate_id"`
Data json.RawMessage `json:"data"`
ID string `json:"id"`
Sequence int64 `json:"seq"`
Type string `json:"type"`
}
SyncEvent is one native sync event as the mirror stores it: Data is the event's JSON object. Its encoding is the mirror row: members in name order, data compact.