opencode

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const CarrierKey = "acp-go-opencodev2"
View Source
const EventCapacity = 256

EventCapacity bounds the decoded frames waiting for the runtime pump.

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

View Source
var ErrMarkerMissing = errors.New("native execution marker missing")

ErrMarkerMissing reports an export that does not yet hold the execution's durable idle marker.

Functions

func AdvancePluginGeneration

func AdvancePluginGeneration(root string) error

AdvancePluginGeneration makes the environment plugin forget the session environments it applied, so the next tool call in each session reads its carrier again.

func CheckPlugin

func CheckPlugin(root, directory string) error

CheckPlugin verifies the environment plugin loaded for directory, which names the native location exactly as the adapter addressed it.

func ConfigDir

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

func DataDir

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

func ExecutionMarker

func ExecutionMarker(event Event) (id, outcome string, err error)

ExecutionMarker names the durable idle marker a terminal execution event leaves in its session's history, and the outcome it records.

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

func (c *Client) StreamExport(ctx context.Context, id string, info func(json.RawMessage) error, message func(raw []byte) error) error

StreamExport reads one session export as it arrives: info receives the session information, then message receives each settled message's raw bytes in native order. A message's bytes are valid only during its call, so the export is never held whole.

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"`
	SessionID string          `json:"-"`
	Raw       json.RawMessage `json:"-"`
}

Event is one native SSE frame. SessionID names the session the event addresses, read from its data once when the frame is decoded.

func DecodeEvent

func DecodeEvent(frame []byte) (Event, error)

DecodeEvent decodes one owned SSE frame, which becomes the event's Raw; Data is the slice of Raw holding the event's data, not a copy.

func (Event) MessageID

func (e Event) MessageID() string

MessageID is the native message identity derived from a durable event.

type Export

type Export struct {
	Info     NativeSession
	InfoRaw  json.RawMessage
	Messages []Message
}

Export is the native, lossless session transfer format: the session's information and its settled messages, each kept as its raw bytes.

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

func (e Export) MarshalJSON() ([]byte, error)

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 Message

type Message struct {
	ID      string
	Type    string
	Outcome string
	Created int64
	Raw     json.RawMessage
}

Message is one exported native message: its raw bytes and the fields a checkpoint orders and cuts by. Decode yields the full projection.

func ParseMessage

func ParseMessage(raw json.RawMessage) (Message, error)

ParseMessage reads a message whose raw bytes the caller hands over.

func (Message) Decode

func (m Message) Decode() (NativeMessage, error)

Decode returns the message's full projection.

func (Message) MarshalJSON

func (m Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

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

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

NativeMessage is a projected message returned by the native transcript API.

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