Documentation
¶
Overview ¶
Package opencodeacp exposes OpenCode as an Agent Client Protocol agent.
The package runs one authenticated loopback `opencode serve` process per ACP session and maps native REST/SSE state to ACP methods and notifications.
Index ¶
- Constants
- func CallForkSession(ctx context.Context, conn *acp.ClientSideConnection, ...) (acp.UnstableForkSessionResponse, error)
- func DeleteSessionRequest(sessionID acp.SessionId) acp.UnstableDeleteSessionRequest
- func ForkSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.UnstableForkSessionRequest
- func HTTPMCPServer(name string, url string, headers map[string]string) acp.McpServer
- func ListSessionsRequest(opts ...ListSessionsRequestOption) acp.ListSessionsRequest
- func LoadSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.LoadSessionRequest
- func NewSessionRequest(cwd string, opts ...SessionRequestOption) acp.NewSessionRequest
- func PromptRequest(sessionID acp.SessionId, blocks ...acp.ContentBlock) acp.PromptRequest
- func ResumeSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.ResumeSessionRequest
- func Serve(ctx context.Context, input io.Reader, output io.Writer, opts ...Option) error
- func SetConfigOptionRequest(sessionID acp.SessionId, configID acp.SessionConfigId, ...) acp.SetSessionConfigOptionRequest
- func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest
- func StdioMCPServer(name string, command string, args []string, env map[string]string) acp.McpServer
- func TextPromptRequest(sessionID acp.SessionId, text string) acp.PromptRequest
- type Agent
- func (a *Agent) Authenticate(_ context.Context, params acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
- func (a *Agent) Cancel(ctx context.Context, params acp.CancelNotification) error
- func (a *Agent) Close() error
- func (a *Agent) CloseSession(ctx context.Context, params acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
- func (a *Agent) HandleExtensionMethod(ctx context.Context, method string, params json.RawMessage) (any, error)
- func (a *Agent) Initialize(_ context.Context, params acp.InitializeRequest) (acp.InitializeResponse, error)
- func (a *Agent) ListSessions(ctx context.Context, params acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
- func (a *Agent) LoadSession(ctx context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
- func (a *Agent) Logout(context.Context, acp.LogoutRequest) (acp.LogoutResponse, error)
- func (a *Agent) NewSession(ctx context.Context, params acp.NewSessionRequest) (acp.NewSessionResponse, error)
- func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)
- func (a *Agent) ResumeSession(ctx context.Context, params acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
- func (a *Agent) SetSessionConfigOption(ctx context.Context, params acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
- func (a *Agent) SetSessionMode(context.Context, acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
- func (a *Agent) UnstableDeleteSession(ctx context.Context, params acp.UnstableDeleteSessionRequest) (acp.UnstableDeleteSessionResponse, error)
- type ConcurrencyLimits
- type InMemorySessionStore
- func (s *InMemorySessionStore) Append(ctx context.Context, key SessionKey, entries []SessionStoreEntry) error
- func (s *InMemorySessionStore) Delete(ctx context.Context, key SessionKey) error
- func (s *InMemorySessionStore) ListSessions(ctx context.Context) ([]SessionSummary, error)
- func (s *InMemorySessionStore) ListSubkeys(ctx context.Context, key SessionKey) ([]string, error)
- func (s *InMemorySessionStore) Load(ctx context.Context, key SessionKey) ([]SessionStoreEntry, error)
- func (s *InMemorySessionStore) Replace(ctx context.Context, main SessionKey, replacements []SessionStoreReplacement) error
- type ListSessionsRequestOption
- type OpenCodeOption
- type OpenCodeOptions
- type Option
- func WithAgentName(name string) Option
- func WithAgentTitle(title string) Option
- func WithAgentVersion(version string) Option
- func WithConcurrencyLimits(limits ConcurrencyLimits) Option
- func WithDefaultModel(model string) Option
- func WithEnv(env map[string]string) Option
- func WithExecutablePath(path string) Option
- func WithHome(path string) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMeterProvider(provider metric.MeterProvider) Option
- func WithOpenCodeHealthCheckTimeout(timeout time.Duration) Option
- func WithOpenCodeLogLevel(level string) Option
- func WithOpenCodeMinimumVersion(version string) Option
- func WithOpenCodePure(enabled bool) Option
- func WithOpenCodeQuestionTool(enabled bool) Option
- func WithSessionStore(store SessionStore) Option
- func WithSessionStoreLoadTimeout(timeout time.Duration) Option
- func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
- func WithTracerProvider(provider trace.TracerProvider) Option
- type Options
- type SessionKey
- type SessionRequestOption
- func WithSessionAdditionalDirectories(paths ...string) SessionRequestOption
- func WithSessionMCPServers(servers ...acp.McpServer) SessionRequestOption
- func WithSessionMeta(meta map[string]any) SessionRequestOption
- func WithSessionOpenCodeOptions(options OpenCodeOptions) SessionRequestOption
- func WithSessionOutputSchema(schema map[string]any) SessionRequestOption
- func WithSessionRawEvents(enabled bool) SessionRequestOption
- type SessionStore
- type SessionStoreEntry
- type SessionStoreReplacement
- type SessionSummary
Constants ¶
const ( ForkSessionMethod = "_opencode/session/fork" RawEventMethod = "_opencode/rawEvent" )
const ( SessionStoreMainSubpath = "" SessionStoreFormat = "opencode-state-v1" )
Variables ¶
This section is empty.
Functions ¶
func CallForkSession ¶
func CallForkSession(ctx context.Context, conn *acp.ClientSideConnection, params acp.UnstableForkSessionRequest) (acp.UnstableForkSessionResponse, error)
func DeleteSessionRequest ¶
func DeleteSessionRequest(sessionID acp.SessionId) acp.UnstableDeleteSessionRequest
func ForkSessionRequest ¶
func ForkSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.UnstableForkSessionRequest
func HTTPMCPServer ¶
func ListSessionsRequest ¶
func ListSessionsRequest(opts ...ListSessionsRequestOption) acp.ListSessionsRequest
func LoadSessionRequest ¶
func LoadSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.LoadSessionRequest
func NewSessionRequest ¶
func NewSessionRequest(cwd string, opts ...SessionRequestOption) acp.NewSessionRequest
func PromptRequest ¶
func PromptRequest(sessionID acp.SessionId, blocks ...acp.ContentBlock) acp.PromptRequest
func ResumeSessionRequest ¶
func ResumeSessionRequest(sessionID acp.SessionId, cwd string, opts ...SessionRequestOption) acp.ResumeSessionRequest
func SetConfigOptionRequest ¶
func SetConfigOptionRequest(sessionID acp.SessionId, configID acp.SessionConfigId, value acp.SessionConfigValueId) acp.SetSessionConfigOptionRequest
func SetModelRequest ¶
func SetModelRequest(sessionID acp.SessionId, model string) acp.SetSessionConfigOptionRequest
func StdioMCPServer ¶
func TextPromptRequest ¶
func TextPromptRequest(sessionID acp.SessionId, text string) acp.PromptRequest
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent exposes OpenCode through ACP.
func (*Agent) Authenticate ¶
func (a *Agent) Authenticate(_ context.Context, params acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
func (*Agent) CloseSession ¶
func (a *Agent) CloseSession(ctx context.Context, params acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
func (*Agent) HandleExtensionMethod ¶
func (*Agent) Initialize ¶
func (a *Agent) Initialize(_ context.Context, params acp.InitializeRequest) (acp.InitializeResponse, error)
func (*Agent) ListSessions ¶
func (a *Agent) ListSessions(ctx context.Context, params acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
func (*Agent) LoadSession ¶
func (a *Agent) LoadSession(ctx context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
func (*Agent) Logout ¶
func (a *Agent) Logout(context.Context, acp.LogoutRequest) (acp.LogoutResponse, error)
func (*Agent) NewSession ¶
func (a *Agent) NewSession(ctx context.Context, params acp.NewSessionRequest) (acp.NewSessionResponse, error)
func (*Agent) Prompt ¶
func (a *Agent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)
func (*Agent) ResumeSession ¶
func (a *Agent) ResumeSession(ctx context.Context, params acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
func (*Agent) SetSessionConfigOption ¶
func (a *Agent) SetSessionConfigOption(ctx context.Context, params acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
func (*Agent) SetSessionMode ¶
func (a *Agent) SetSessionMode(context.Context, acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
func (*Agent) UnstableDeleteSession ¶
func (a *Agent) UnstableDeleteSession(ctx context.Context, params acp.UnstableDeleteSessionRequest) (acp.UnstableDeleteSessionResponse, error)
type ConcurrencyLimits ¶
type ConcurrencyLimits struct {
MaxActiveSessions int
MaxConcurrentPrompts int
MaxConcurrentClientCalls int
}
ConcurrencyLimits bounds work accepted by one Agent.
type InMemorySessionStore ¶
type InMemorySessionStore struct {
// contains filtered or unexported fields
}
func NewInMemorySessionStore ¶
func NewInMemorySessionStore() *InMemorySessionStore
func (*InMemorySessionStore) Append ¶
func (s *InMemorySessionStore) Append(ctx context.Context, key SessionKey, entries []SessionStoreEntry) error
func (*InMemorySessionStore) Delete ¶
func (s *InMemorySessionStore) Delete(ctx context.Context, key SessionKey) error
func (*InMemorySessionStore) ListSessions ¶
func (s *InMemorySessionStore) ListSessions(ctx context.Context) ([]SessionSummary, error)
func (*InMemorySessionStore) ListSubkeys ¶
func (s *InMemorySessionStore) ListSubkeys(ctx context.Context, key SessionKey) ([]string, error)
func (*InMemorySessionStore) Load ¶
func (s *InMemorySessionStore) Load(ctx context.Context, key SessionKey) ([]SessionStoreEntry, error)
func (*InMemorySessionStore) Replace ¶
func (s *InMemorySessionStore) Replace(ctx context.Context, main SessionKey, replacements []SessionStoreReplacement) error
type ListSessionsRequestOption ¶
type ListSessionsRequestOption func(*acp.ListSessionsRequest)
func WithListSessionsCursor ¶
func WithListSessionsCursor(cursor string) ListSessionsRequestOption
func WithListSessionsCwd ¶
func WithListSessionsCwd(cwd string) ListSessionsRequestOption
func WithListSessionsMeta ¶
func WithListSessionsMeta(meta map[string]any) ListSessionsRequestOption
type OpenCodeOption ¶
type OpenCodeOption func(*OpenCodeOptions)
func WithOpenCodeEnv ¶
func WithOpenCodeEnv(env map[string]string) OpenCodeOption
func WithOpenCodeMode ¶
func WithOpenCodeMode(mode string) OpenCodeOption
func WithOpenCodeModel ¶
func WithOpenCodeModel(model string) OpenCodeOption
func WithOpenCodeOutputSchema ¶
func WithOpenCodeOutputSchema(schema map[string]any) OpenCodeOption
func WithOpenCodePermission ¶
func WithOpenCodePermission(permission string) OpenCodeOption
type OpenCodeOptions ¶
type OpenCodeOptions struct {
Model string `json:"model,omitempty"`
Env map[string]string `json:"env,omitempty"`
OutputSchema map[string]any `json:"outputSchema,omitempty"`
Mode string `json:"mode,omitempty"`
Permission string `json:"permission,omitempty"`
}
OpenCodeOptions is the stable OpenCode-specific subset accepted at _meta.opencode.options.
func NewOpenCodeOptions ¶
func NewOpenCodeOptions(opts ...OpenCodeOption) OpenCodeOptions
func (OpenCodeOptions) Meta ¶
func (options OpenCodeOptions) Meta() map[string]any
Meta returns an ACP _meta object for the supported OpenCode-specific options.
type Option ¶
type Option func(*Options)
Option configures the OpenCode ACP agent.
func WithAgentName ¶
func WithAgentTitle ¶
func WithAgentVersion ¶
func WithConcurrencyLimits ¶
func WithConcurrencyLimits(limits ConcurrencyLimits) Option
func WithDefaultModel ¶
func WithExecutablePath ¶
func WithHome ¶
WithHome sets the parent root under which isolated per-session OpenCode XDG data, config, cache, and state directories are created.
func WithLogger ¶
func WithMeterProvider ¶
func WithMeterProvider(provider metric.MeterProvider) Option
func WithOpenCodeLogLevel ¶
func WithOpenCodePure ¶
func WithSessionStore ¶
func WithSessionStore(store SessionStore) Option
func WithTextMapPropagator ¶
func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
type Options ¶
type Options struct {
AgentName string
AgentTitle string
AgentVersion string
ExecutablePath string
Home string
DefaultModel string
Env map[string]string
Logger *slog.Logger
TracerProvider trace.TracerProvider
MeterProvider metric.MeterProvider
TextMapPropagator propagation.TextMapPropagator
SessionStore SessionStore
SessionStoreLoadTimeout time.Duration
ConcurrencyLimits ConcurrencyLimits
Pure bool
QuestionTool bool
LogLevel string
MinimumVersion string
HealthCheckTimeout time.Duration
// contains filtered or unexported fields
}
Options configures the ACP agent process and OpenCode sessions it starts.
type SessionKey ¶
type SessionRequestOption ¶
type SessionRequestOption func(*sessionRequestConfig)
func WithSessionAdditionalDirectories ¶
func WithSessionAdditionalDirectories(paths ...string) SessionRequestOption
func WithSessionMCPServers ¶
func WithSessionMCPServers(servers ...acp.McpServer) SessionRequestOption
func WithSessionMeta ¶
func WithSessionMeta(meta map[string]any) SessionRequestOption
func WithSessionOpenCodeOptions ¶
func WithSessionOpenCodeOptions(options OpenCodeOptions) SessionRequestOption
func WithSessionOutputSchema ¶
func WithSessionOutputSchema(schema map[string]any) SessionRequestOption
func WithSessionRawEvents ¶
func WithSessionRawEvents(enabled bool) SessionRequestOption
type SessionStore ¶
type SessionStore interface {
Append(ctx context.Context, key SessionKey, entries []SessionStoreEntry) error
Load(ctx context.Context, key SessionKey) ([]SessionStoreEntry, error)
Replace(ctx context.Context, main SessionKey, replacements []SessionStoreReplacement) error
Delete(ctx context.Context, key SessionKey) error
ListSessions(ctx context.Context) ([]SessionSummary, error)
ListSubkeys(ctx context.Context, key SessionKey) ([]string, error)
}
type SessionStoreEntry ¶
type SessionStoreEntry = json.RawMessage
type SessionStoreReplacement ¶
type SessionStoreReplacement struct {
Key SessionKey
Entries []SessionStoreEntry
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
acp-go-opencode
command
|
|
|
examples
|
|
|
interactive-chat
command
|
|
|
minimal-client
command
|
|
|
resume-from-file
command
|
|
|
internal
|
|