Documentation
¶
Index ¶
- func IsAuthError(err error) bool
- func NormalizeBaseURL(raw string) (string, error)
- type APIError
- type Client
- func (c *Client) AbortSession(ctx context.Context, sessionID string) error
- func (c *Client) CreateSession(ctx context.Context, title, directory string) (*Session, error)
- func (c *Client) DeleteSession(ctx context.Context, sessionID string) error
- func (c *Client) GetMessage(ctx context.Context, sessionID, messageID string) (*MessageWithParts, error)
- func (c *Client) ListMessages(ctx context.Context, sessionID string, limit int) ([]MessageWithParts, error)
- func (c *Client) ListSessions(ctx context.Context) ([]Session, error)
- func (c *Client) RejectQuestion(ctx context.Context, requestID string) error
- func (c *Client) ReplyQuestion(ctx context.Context, requestID string, answers [][]string) error
- func (c *Client) RespondPermission(ctx context.Context, sessionID, permissionID, response string) error
- func (c *Client) SendMessageAsync(ctx context.Context, sessionID, messageID string, parts []PartInput) error
- func (c *Client) StreamEvents(ctx context.Context) (<-chan Event, <-chan error)
- func (c *Client) UpdateSessionTitle(ctx context.Context, sessionID, title string) (*Session, error)
- type Event
- type Message
- type MessageTime
- type MessageWithParts
- type ModelRef
- type Part
- type PartInput
- type PartTime
- type PermissionRequest
- type QuestionInfo
- type QuestionOption
- type QuestionRequest
- type RequestToolRef
- type Session
- type SessionTime
- type Timestamp
- type TokenCache
- type TokenUsage
- type ToolState
- type ToolStateTime
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAuthError ¶
IsAuthError returns true if the error is an auth error.
func NormalizeBaseURL ¶
NormalizeBaseURL ensures a base URL is valid and has no trailing slash.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles HTTP interactions with an OpenCode server.
func (*Client) AbortSession ¶
AbortSession aborts a running session.
func (*Client) CreateSession ¶
CreateSession creates a new session with an optional title and directory.
func (*Client) DeleteSession ¶
DeleteSession deletes an OpenCode session.
func (*Client) GetMessage ¶
func (c *Client) GetMessage(ctx context.Context, sessionID, messageID string) (*MessageWithParts, error)
GetMessage fetches a single message and its parts.
func (*Client) ListMessages ¶
func (c *Client) ListMessages(ctx context.Context, sessionID string, limit int) ([]MessageWithParts, error)
ListMessages lists recent messages in a session.
func (*Client) ListSessions ¶
ListSessions returns all sessions from the server.
func (*Client) RejectQuestion ¶
func (*Client) ReplyQuestion ¶
func (*Client) RespondPermission ¶
func (*Client) SendMessageAsync ¶
func (c *Client) SendMessageAsync(ctx context.Context, sessionID, messageID string, parts []PartInput) error
SendMessageAsync sends a message to a session asynchronously. The server returns 204 immediately; the assistant response is delivered via SSE.
func (*Client) StreamEvents ¶
StreamEvents connects to the OpenCode /event SSE endpoint. It returns a channel of events and a channel for errors.
type Event ¶
type Event struct {
Type string `json:"type"`
Properties json.RawMessage `json:"properties"`
}
Event represents a server-sent event from the OpenCode event stream.
func (Event) DecodeInfo ¶
DecodeInfo decodes the info payload inside an event into the provided target.
type Message ¶
type Message struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Role string `json:"role"`
ParentID string `json:"parentID,omitempty"`
Agent string `json:"agent,omitempty"`
ModelID string `json:"modelID,omitempty"`
ProviderID string `json:"providerID,omitempty"`
Mode string `json:"mode,omitempty"`
Finish string `json:"finish,omitempty"`
Cost float64 `json:"cost,omitempty"`
Tokens *TokenUsage `json:"tokens,omitempty"`
Time MessageTime `json:"time"`
}
Message represents the info block for a session message.
type MessageTime ¶
type MessageTime struct {
Created Timestamp `json:"created"`
Completed Timestamp `json:"completed,omitempty"`
}
MessageTime holds timing info for a message.
type MessageWithParts ¶
MessageWithParts bundles a message info block with its parts.
type ModelRef ¶
type ModelRef struct {
ProviderID string `json:"providerID,omitempty"`
ModelID string `json:"modelID,omitempty"`
}
ModelRef identifies a provider/model pair.
type Part ¶
type Part struct {
ID string `json:"id"`
SessionID string `json:"sessionID,omitempty"`
MessageID string `json:"messageID,omitempty"`
Type string `json:"type"`
Text string `json:"text,omitempty"`
Filename string `json:"filename,omitempty"`
URL string `json:"url,omitempty"`
Mime string `json:"mime,omitempty"`
Name string `json:"name,omitempty"`
Prompt string `json:"prompt,omitempty"`
Description string `json:"description,omitempty"`
Agent string `json:"agent,omitempty"`
Model *ModelRef `json:"model,omitempty"`
Command string `json:"command,omitempty"`
CallID string `json:"callID,omitempty"`
Tool string `json:"tool,omitempty"`
State *ToolState `json:"state,omitempty"`
Snapshot string `json:"snapshot,omitempty"`
Hash string `json:"hash,omitempty"`
Files []string `json:"files,omitempty"`
Reason string `json:"reason,omitempty"`
Cost float64 `json:"cost,omitempty"`
Tokens *TokenUsage `json:"tokens,omitempty"`
Attempt int `json:"attempt,omitempty"`
Auto bool `json:"auto,omitempty"`
Time *PartTime `json:"time,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Error json.RawMessage `json:"error,omitempty"`
Source json.RawMessage `json:"source,omitempty"`
Extra map[string]any `json:"extra,omitempty"`
}
Part represents a message part. Only a subset of fields is used by the bridge.
type PartInput ¶
type PartInput struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
Text string `json:"text,omitempty"`
Mime string `json:"mime,omitempty"`
Filename string `json:"filename,omitempty"`
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
Prompt string `json:"prompt,omitempty"`
Description string `json:"description,omitempty"`
Agent string `json:"agent,omitempty"`
Model *ModelRef `json:"model,omitempty"`
Command string `json:"command,omitempty"`
}
PartInput is used to send parts to OpenCode.
type PermissionRequest ¶
type QuestionInfo ¶
type QuestionInfo struct {
Question string `json:"question"`
Header string `json:"header"`
Options []QuestionOption `json:"options"`
Multiple bool `json:"multiple,omitempty"`
Custom bool `json:"custom,omitempty"`
}
type QuestionOption ¶
type QuestionRequest ¶
type QuestionRequest struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Questions []QuestionInfo `json:"questions"`
Tool *RequestToolRef `json:"tool,omitempty"`
}
type RequestToolRef ¶
type Session ¶
type Session struct {
ID string `json:"id"`
Slug string `json:"slug"`
ProjectID string `json:"projectID"`
Directory string `json:"directory"`
ParentID string `json:"parentID,omitempty"`
Title string `json:"title"`
Version string `json:"version"`
Time SessionTime `json:"time"`
}
Session represents an OpenCode session summary.
type SessionTime ¶
SessionTime holds session timing metadata.
type Timestamp ¶
type Timestamp int64
Timestamp represents millisecond timestamps returned by the OpenCode API.
func (*Timestamp) UnmarshalJSON ¶
UnmarshalJSON accepts either integer or floating-point JSON numbers.
type TokenCache ¶
type TokenCache struct {
Read float64 `json:"read,omitempty"`
Write float64 `json:"write,omitempty"`
}
TokenCache represents cached token usage.
type TokenUsage ¶
type TokenUsage struct {
Input float64 `json:"input,omitempty"`
Output float64 `json:"output,omitempty"`
Reasoning float64 `json:"reasoning,omitempty"`
Cache *TokenCache `json:"cache,omitempty"`
}
TokenUsage represents token usage.
type ToolState ¶
type ToolState struct {
Status string `json:"status"`
Input map[string]any `json:"input,omitempty"`
Raw string `json:"raw,omitempty"`
Title string `json:"title,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Output string `json:"output,omitempty"`
Error string `json:"error,omitempty"`
Time *ToolStateTime `json:"time,omitempty"`
Attachments []Part `json:"attachments,omitempty"`
}
ToolState captures tool execution state.
type ToolStateTime ¶
type ToolStateTime struct {
Start Timestamp `json:"start,omitempty"`
End Timestamp `json:"end,omitempty"`
Compacted Timestamp `json:"compacted,omitempty"`
}
ToolStateTime captures tool state timing.