Documentation
¶
Overview ¶
Package handlers provides a Dispatcher that implements acp.Client so the coder/acp-go-sdk ClientSideConnection can dispatch agent→client RPCs and notifications into opencodesdk. Each method routes to a user-supplied callback when present, and falls back to a sensible default otherwise (pass-through for fs/write, reject for permission, no-op for session/update, unsupported for terminal).
Index ¶
- type Callbacks
- type Dispatcher
- func (d *Dispatcher) CreateTerminal(context.Context, acp.CreateTerminalRequest) (acp.CreateTerminalResponse, error)
- func (d *Dispatcher) KillTerminal(context.Context, acp.KillTerminalRequest) (acp.KillTerminalResponse, error)
- func (d *Dispatcher) ReadTextFile(_ context.Context, params acp.ReadTextFileRequest) (acp.ReadTextFileResponse, error)
- func (d *Dispatcher) ReleaseTerminal(context.Context, acp.ReleaseTerminalRequest) (acp.ReleaseTerminalResponse, error)
- func (d *Dispatcher) RequestPermission(ctx context.Context, params acp.RequestPermissionRequest) (acp.RequestPermissionResponse, error)
- func (d *Dispatcher) SessionUpdate(ctx context.Context, params acp.SessionNotification) error
- func (d *Dispatcher) TerminalOutput(context.Context, acp.TerminalOutputRequest) (acp.TerminalOutputResponse, error)
- func (d *Dispatcher) UnstableCompleteElicitation(ctx context.Context, params acp.UnstableCompleteElicitationNotification) error
- func (d *Dispatcher) UnstableCreateElicitation(ctx context.Context, params acp.UnstableCreateElicitationRequest) (acp.UnstableCreateElicitationResponse, error)
- func (d *Dispatcher) WaitForTerminalExit(context.Context, acp.WaitForTerminalExitRequest) (acp.WaitForTerminalExitResponse, error)
- func (d *Dispatcher) WriteTextFile(ctx context.Context, params acp.WriteTextFileRequest) (acp.WriteTextFileResponse, error)
- type ElicitationCallback
- type ElicitationCompleteCallback
- type FsWriteCallback
- type PermissionCallback
- type SessionUpdateCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Callbacks ¶
type Callbacks struct {
Permission PermissionCallback
FsWrite FsWriteCallback
SessionUpdate SessionUpdateCallback
Elicitation ElicitationCallback
ElicitationComplete ElicitationCompleteCallback
}
Callbacks bundles all user-supplied handler hooks.
type Dispatcher ¶
type Dispatcher struct {
Callbacks Callbacks
Logger *slog.Logger
// StrictCwdBoundary rejects fs/write_text_file delegations for any
// path outside Cwd. If StrictCwdBoundary is true but Cwd is empty,
// every write is rejected.
StrictCwdBoundary bool
Cwd string
}
Dispatcher implements acp.Client by routing incoming RPCs into the supplied Callbacks.
func (*Dispatcher) CreateTerminal ¶
func (d *Dispatcher) CreateTerminal(context.Context, acp.CreateTerminalRequest) (acp.CreateTerminalResponse, error)
func (*Dispatcher) KillTerminal ¶
func (d *Dispatcher) KillTerminal(context.Context, acp.KillTerminalRequest) (acp.KillTerminalResponse, error)
func (*Dispatcher) ReadTextFile ¶
func (d *Dispatcher) ReadTextFile(_ context.Context, params acp.ReadTextFileRequest) (acp.ReadTextFileResponse, error)
ReadTextFile handles fs/read_text_file delegations. opencode never emits these at present, but we implement the method anyway because we advertise fs.readTextFile capability and coder SDK requires the full interface.
func (*Dispatcher) ReleaseTerminal ¶
func (d *Dispatcher) ReleaseTerminal(context.Context, acp.ReleaseTerminalRequest) (acp.ReleaseTerminalResponse, error)
func (*Dispatcher) RequestPermission ¶
func (d *Dispatcher) RequestPermission(ctx context.Context, params acp.RequestPermissionRequest) (acp.RequestPermissionResponse, error)
RequestPermission handles agent-initiated permission requests. If no callback is set, the request is rejected with the "reject" option (if offered) and an error is logged so developers notice the missing handler.
func (*Dispatcher) SessionUpdate ¶
func (d *Dispatcher) SessionUpdate(ctx context.Context, params acp.SessionNotification) error
SessionUpdate handles inbound session/update notifications. The callback is invoked synchronously; a non-nil error is returned to the coder SDK which surfaces it as a notification-handling failure.
func (*Dispatcher) TerminalOutput ¶
func (d *Dispatcher) TerminalOutput(context.Context, acp.TerminalOutputRequest) (acp.TerminalOutputResponse, error)
func (*Dispatcher) UnstableCompleteElicitation ¶
func (d *Dispatcher) UnstableCompleteElicitation(ctx context.Context, params acp.UnstableCompleteElicitationNotification) error
UnstableCompleteElicitation routes elicitation/complete notifications to the configured callback. Notification-only: the callback's return path does not surface back to the agent.
func (*Dispatcher) UnstableCreateElicitation ¶
func (d *Dispatcher) UnstableCreateElicitation(ctx context.Context, params acp.UnstableCreateElicitationRequest) (acp.UnstableCreateElicitationResponse, error)
UnstableCreateElicitation routes an agent-initiated elicitation/create request to the configured callback. When no callback is set, we return a Decline response so the agent gracefully recovers without the SDK having to synthesise a JSON-RPC error from inside the handler.
opencode 1.14.20 does not currently emit elicitation/create; this handler is wired in anticipation of future ACP agents that do.
func (*Dispatcher) WaitForTerminalExit ¶
func (d *Dispatcher) WaitForTerminalExit(context.Context, acp.WaitForTerminalExitRequest) (acp.WaitForTerminalExitResponse, error)
func (*Dispatcher) WriteTextFile ¶
func (d *Dispatcher) WriteTextFile(ctx context.Context, params acp.WriteTextFileRequest) (acp.WriteTextFileResponse, error)
WriteTextFile handles fs/write_text_file delegations. opencode emits this after an approved edit to sync the client's in-memory buffer with on-disk state. Default behavior is to write through; callers can override via FsWriteCallback.
type ElicitationCallback ¶
type ElicitationCallback func(ctx context.Context, req acp.UnstableCreateElicitationRequest) (acp.UnstableCreateElicitationResponse, error)
ElicitationCallback is invoked when the agent issues an elicitation/create request (agent → client). Returning a non-nil error surfaces as a JSON-RPC error to the agent.
type ElicitationCompleteCallback ¶
type ElicitationCompleteCallback func(ctx context.Context, params acp.UnstableCompleteElicitationNotification)
ElicitationCompleteCallback is invoked for elicitation/complete notifications. Notification-only: errors are not propagated.
type FsWriteCallback ¶
type FsWriteCallback func(ctx context.Context, req acp.WriteTextFileRequest) error
FsWriteCallback is invoked when the agent delegates a file write. Return a non-nil error to refuse the write (opencode will surface this as a tool failure).
type PermissionCallback ¶
type PermissionCallback func(ctx context.Context, req acp.RequestPermissionRequest) (acp.RequestPermissionResponse, error)
PermissionCallback is invoked when the agent requests permission for a tool call. Return the option the user selected, or return with ctx.Err != nil to signal cancellation.
type SessionUpdateCallback ¶
type SessionUpdateCallback func(ctx context.Context, params acp.SessionNotification) error
SessionUpdateCallback is invoked for every session/update notification streamed by the agent.