opencode

package
v0.0.0-...-849c623 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const CarrierKey = "acp-go-opencodev2"
View Source
const EventCapacity = 256
View Source
const InternalEnvPrefix = "ACP_GO_OPENCODEV2_INTERNAL_"
View Source
const MaxBodyBytes = 64 << 20
View Source
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 CheckPlugin

func CheckPlugin(root, directory string) error

func ConfigDir

func ConfigDir(lookup func(string) (string, bool)) string

func DataDir

func DataDir(lookup func(string) (string, bool)) string

func HomeEnvironment

func HomeEnvironment(home string) map[string]string

func IsMissing

func IsMissing(err error) bool

func ModelSelectionShapeError

func ModelSelectionShapeError(value string) error

func NewID

func NewID(prefix string) string

func NewMessageID

func NewMessageID() string

NewMessageID uses the native timestamp layout so later CLI messages sort after it.

func SessionPath

func SessionPath(id string) string

func WritePlugin

func WritePlugin(root, config string, ownsHome bool) (string, error)

WritePlugin registers the environment hook alongside the caller's native config.

Types

type Client

type Client struct {
	URL      string
	Password string
	// contains filtered or unexported fields
}

Client is an authenticated native HTTP endpoint shared by every session.

func NewClient

func NewClient() *Client

func (*Client) Args

func (c *Client) Args() []string

func (*Client) CancelInput

func (c *Client) CancelInput(ctx context.Context, sessionID, inputID string) error

func (*Client) Do

func (c *Client) Do(ctx context.Context, directory, method, path string, body, out any) error

func (*Client) Enqueue

func (c *Client) Enqueue(ctx context.Context, input InboxInput) error

func (*Client) Export

func (c *Client) Export(ctx context.Context, id string) (Export, error)

func (*Client) Import

func (c *Client) Import(ctx context.Context, snapshot Export, location Location) error

func (*Client) Inbox

func (c *Client) Inbox(ctx context.Context, sessionID string) ([]InboxInput, error)

func (*Client) Interrupt

func (c *Client) Interrupt(ctx context.Context, id string) error

func (*Client) Move

func (c *Client) Move(ctx context.Context, id, directory string) error

func (*Client) ReadAddress

func (c *Client) ReadAddress(stdout io.Reader) error

ReadAddress reads the owned server's bound loopback address before any HTTP request.

func (*Client) Session

func (c *Client) Session(ctx context.Context, id string) (NativeSession, error)

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context) (*Stream, error)

func (*Client) UsageAccess

func (c *Client) UsageAccess(ctx context.Context, directory, providerID string, selected ModelRef, lookup func(string) (string, bool)) (usage.Access, error)

UsageAccess verifies the effective model route and the native active credential.

func (*Client) UsageGateways

func (c *Client) UsageGateways(ctx context.Context, directory string, selected ModelRef, lookup func(string) (string, bool)) ([]gateway.Route, error)

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, id string) error

func (*Client) WaitForPlugins

func (c *Client) WaitForPlugins(ctx context.Context, directory string) error

WaitForPlugins uses the integration endpoint's activation barrier before reading catalogs whose endpoints return the current, possibly partial snapshot.

type Content

type Content struct {
	Type  string          `json:"type"`
	ID    string          `json:"id,omitempty"`
	Name  string          `json:"name,omitempty"`
	Text  string          `json:"text,omitempty"`
	State json.RawMessage `json:"state,omitempty"`
	URI   string          `json:"uri,omitempty"`
	MIME  string          `json:"mime,omitempty"`
}

Content is one native assistant or tool content block.

type Event

type Event struct {
	ID      string          `json:"id"`
	Type    string          `json:"type"`
	Created int64           `json:"created"`
	Data    json.RawMessage `json:"data"`
	Durable *struct {
		AggregateID string `json:"aggregateID"`
		Seq         int64  `json:"seq"`
		Version     int    `json:"version"`
	} `json:"durable,omitempty"`
	Raw json.RawMessage `json:"-"`
}

func (Event) SessionID

func (e Event) SessionID() string

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(data []byte) error

type Export

type Export struct {
	Info     NativeSession   `json:"info"`
	Messages []NativeMessage `json:"messages"`
	Raw      json.RawMessage `json:"-"`
}

Export is the native, lossless session transfer format.

func (Export) CompletedPrefix

func (e Export) CompletedPrefix() (Export, error)

CompletedPrefix retains only executions ending in a durable idle marker.

func (Export) ContainsHistory

func (e Export) ContainsHistory(saved Export) bool

ContainsHistory verifies saved identities, order, and content. Export omits in-flight assistant, shell, and compaction records; they can appear later at their original positions when they finish.

func (Export) ExecutionPrefix

func (e Export) ExecutionPrefix(event Event) (Export, error)

ExecutionPrefix cuts the export at the terminal event's durable idle marker.

func (Export) SameConfiguration

func (e Export) SameConfiguration(later Export) bool

SameConfiguration excludes native accounting that advances during execution.

func (*Export) UnmarshalJSON

func (e *Export) UnmarshalJSON(data []byte) error

type Form

type Form struct {
	ID        string         `json:"id"`
	SessionID string         `json:"sessionID"`
	Title     string         `json:"title"`
	Fields    []FormField    `json:"fields"`
	Metadata  map[string]any `json:"metadata"`
}

type FormField

type FormField struct {
	Key         string `json:"key"`
	Type        string `json:"type"`
	Label       string `json:"label"`
	Description string `json:"description"`
	Required    bool   `json:"required"`
	Options     []struct {
		Value string `json:"value"`
		Label string `json:"label"`
	} `json:"options"`
	Raw json.RawMessage `json:"-"`
}

func (*FormField) UnmarshalJSON

func (f *FormField) UnmarshalJSON(data []byte) error

type HTTPError

type HTTPError struct {
	Status int
	Native NativeError
}

func (*HTTPError) Error

func (e *HTTPError) Error() string

type InboxInput

type InboxInput struct {
	ID        string          `json:"id"`
	SessionID string          `json:"sessionID"`
	Type      string          `json:"type"`
	Payload   json.RawMessage `json:"payload"`
	Delivery  string          `json:"delivery"`
	Time      struct {
		Created int64 `json:"created"`
	} `json:"time"`
}

InboxInput is native input waiting for the next execution.

func (InboxInput) Validate

func (input InboxInput) Validate(sessionID string) error

type Location

type Location struct {
	Directory string `json:"directory"`
}

type Model

type Model struct {
	Package      string `json:"package"`
	ID           string `json:"id"`
	ProviderID   string `json:"providerID"`
	Name         string `json:"name"`
	Enabled      bool   `json:"enabled"`
	Capabilities struct {
		Input []string `json:"input"`
	} `json:"capabilities"`
	Variants []struct {
		ID string `json:"id"`
	} `json:"variants"`
	Limit map[string]float64 `json:"limit"`
}

type ModelRef

type ModelRef struct {
	ID         string `json:"id"`
	ProviderID string `json:"providerID"`
	Variant    string `json:"variant,omitempty"`
}

type NativeAgent

type NativeAgent struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Mode   string `json:"mode"`
	Hidden bool   `json:"hidden"`
}

type NativeAttachment

type NativeAttachment struct {
	Data     string `json:"data,omitempty"`
	ID       string `json:"id,omitempty"`
	Type     string `json:"type,omitempty"`
	MIME     string `json:"mime,omitempty"`
	Filename string `json:"name,omitempty"`
	URL      string `json:"uri"`
}

type NativeCommand

type NativeCommand struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

type NativeError

type NativeError struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Status  int    `json:"status,omitempty"`
}

type NativeMessage

type NativeMessage struct {
	ID      string             `json:"id"`
	Type    string             `json:"type"`
	Text    string             `json:"text,omitempty"`
	Model   ModelRef           `json:"model"`
	Agent   string             `json:"agent,omitempty"`
	Content []Content          `json:"content,omitempty"`
	Files   []NativeAttachment `json:"files,omitempty"`
	Finish  string             `json:"finish,omitempty"`
	Outcome string             `json:"outcome,omitempty"`
	Error   *NativeError       `json:"error,omitempty"`
	Tokens  NativeTokens       `json:"tokens"`
	Cost    float64            `json:"cost"`
	Time    struct {
		Created   int64 `json:"created"`
		Completed int64 `json:"completed"`
	} `json:"time"`
	Raw json.RawMessage `json:"-"`
}

NativeMessage is a projected message returned by the native transcript API. Raw retains fields needed by import even when ACP does not display them.

func (*NativeMessage) UnmarshalJSON

func (m *NativeMessage) UnmarshalJSON(data []byte) error

type NativeSession

type NativeSession struct {
	ID       string         `json:"id"`
	ParentID string         `json:"parentID,omitempty"`
	Title    string         `json:"title,omitempty"`
	Agent    string         `json:"agent,omitempty"`
	Model    ModelRef       `json:"model"`
	Location Location       `json:"location"`
	Metadata map[string]any `json:"metadata,omitempty"`
	Cost     float64        `json:"cost"`
	Outcome  string         `json:"outcome,omitempty"`
	Time     struct {
		Created int64 `json:"created"`
		Updated int64 `json:"updated"`
		Idle    int64 `json:"idle"`
	} `json:"time"`
}

type NativeSessionStatus

type NativeSessionStatus struct {
	Type string `json:"type"`
}

type NativeTodo

type NativeTodo struct {
	Content  string `json:"content"`
	Status   string `json:"status"`
	Priority string `json:"priority"`
}

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

type PermissionRequest

type PermissionRequest struct {
	ID        string   `json:"id"`
	SessionID string   `json:"sessionID"`
	Action    string   `json:"action"`
	Resources []string `json:"resources"`
	Source    struct {
		Type      string `json:"type"`
		MessageID string `json:"messageID"`
		ID        string `json:"id"`
	} `json:"source"`
}

type ProtocolError

type ProtocolError struct{ Message string }

ProtocolError reports a response that cannot belong to the native JSON API.

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

type Stream

type Stream struct {
	Events chan Event
	// contains filtered or unexported fields
}

Stream owns one ordered global SSE connection. Closing it joins its reader.

func (*Stream) Close

func (s *Stream) Close()

func (*Stream) Err

func (s *Stream) Err() error

type ToolState

type ToolState struct {
	Status   string         `json:"status"`
	Input    any            `json:"input"`
	Content  []Content      `json:"content,omitempty"`
	Error    *NativeError   `json:"error,omitempty"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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