runtime

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrCodeBackendMissing indicates no ACP runtime backend is configured.
	ErrCodeBackendMissing = "ACP_BACKEND_MISSING"

	// ErrCodeBackendUnavailable indicates the ACP runtime backend is unhealthy.
	ErrCodeBackendUnavailable = "ACP_BACKEND_UNAVAILABLE"

	// ErrCodeSessionInitFailed indicates ACP session initialization failed.
	ErrCodeSessionInitFailed = "ACP_SESSION_INIT_FAILED"

	// ErrCodeTurnFailed indicates an ACP turn execution failed.
	ErrCodeTurnFailed = "ACP_TURN_FAILED"

	// ErrCodeTurnCanceled indicates an ACP turn was canceled.
	ErrCodeTurnCanceled = "ACP_TURN_CANCELED"

	// ErrCodeBackendUnsupportedControl indicates the backend doesn't support a control operation.
	ErrCodeBackendUnsupportedControl = "ACP_BACKEND_UNSUPPORTED_CONTROL"

	// ErrCodeSessionLimitReached indicates the maximum concurrent sessions limit was reached.
	ErrCodeSessionLimitReached = "ACP_SESSION_LIMIT_REACHED"

	// ErrCodeSessionNotFound indicates the ACP session doesn't exist.
	ErrCodeSessionNotFound = "ACP_SESSION_NOT_FOUND"

	// ErrCodeInvalidSessionKey indicates the session key is invalid.
	ErrCodeInvalidSessionKey = "ACP_INVALID_SESSION_KEY"

	// ErrCodeAgentUnauthorized indicates the agent is not authorized to use ACP.
	ErrCodeAgentUnauthorized = "ACP_AGENT_UNAUTHORIZED"

	// ErrCodePolicyDisabled indicates ACP is disabled by policy.
	ErrCodePolicyDisabled = "ACP_POLICY_DISABLED"

	// ErrCodeThreadBindingDisabled indicates thread bindings are disabled.
	ErrCodeThreadBindingDisabled = "ACP_THREAD_BINDING_DISABLED"

	// ErrCodeThreadBindingSpawnDisabled indicates thread-bound spawning is disabled.
	ErrCodeThreadBindingSpawnDisabled = "ACP_THREAD_BINDING_SPAWN_DISABLED"

	// ErrCodeThreadBindingFailed indicates thread binding creation failed.
	ErrCodeThreadBindingFailed = "ACP_THREAD_BINDING_FAILED"
)

ACP runtime error codes.

Variables

This section is empty.

Functions

func GetAcpErrorCode

func GetAcpErrorCode(err error) string

GetAcpErrorCode extracts the error code from an error. Returns empty string if not an AcpRuntimeError.

func GetAcpRuntimeBackendCount

func GetAcpRuntimeBackendCount() int

GetAcpRuntimeBackendCount returns the number of registered backends.

func IsAcpRuntimeError

func IsAcpRuntimeError(err error) bool

IsAcpRuntimeError checks if an error is an AcpRuntimeError.

func ListAcpRuntimeBackends

func ListAcpRuntimeBackends() []string

ListAcpRuntimeBackends returns all registered backend IDs.

func RegisterAcpRuntimeBackend

func RegisterAcpRuntimeBackend(backend AcpRuntimeBackend) error

RegisterAcpRuntimeBackend registers an ACP runtime backend. If a backend with the same ID already exists, it will be replaced.

func ResetAcpRuntimeRegistry

func ResetAcpRuntimeRegistry()

ResetAcpRuntimeRegistry clears all registered backends. This is primarily intended for testing purposes.

func UnregisterAcpRuntimeBackend

func UnregisterAcpRuntimeBackend(id string)

UnregisterAcpRuntimeBackend removes an ACP runtime backend from the registry.

Types

type AcpEventDone

type AcpEventDone struct {
	StopReason string // Reason for completion
}

AcpEventDone is emitted when turn execution completes.

type AcpEventError

type AcpEventError struct {
	Message   string // Error message
	Code      string // Error code
	Retryable bool   // Whether the error is retryable
}

AcpEventError is emitted when an error occurs.

type AcpEventStatus

type AcpEventStatus struct {
	Text string // Status message
}

AcpEventStatus is emitted for status updates.

type AcpEventTextDelta

type AcpEventTextDelta struct {
	Text   string // Generated text content
	Stream string // "output" or "thought"
}

AcpEventTextDelta is emitted when text content is generated.

type AcpEventToolCall

type AcpEventToolCall struct {
	ID        string                 // Tool call ID
	Name      string                 // Tool name/function name
	Arguments map[string]interface{} // Tool arguments
	Text      string                 // Tool call description (legacy)
	Status    string                 // Tool status: "pending", "in_progress", "completed", "failed"
}

AcpEventToolCall is emitted when a tool is called.

type AcpRuntime

type AcpRuntime interface {
	// EnsureSession creates or retrieves an ACP session.
	// Returns a handle that identifies the session for subsequent operations.
	EnsureSession(ctx context.Context, input AcpRuntimeEnsureInput) (AcpRuntimeHandle, error)

	// RunTurn executes a single turn in an ACP session.
	// Returns a channel of events that will be closed when the turn completes.
	RunTurn(ctx context.Context, input AcpRuntimeTurnInput) (<-chan AcpRuntimeEvent, error)

	// GetCapabilities returns the capabilities of the runtime.
	// If the runtime doesn't support capability queries, it may return static capabilities.
	GetCapabilities(ctx context.Context, handle *AcpRuntimeHandle) (AcpRuntimeCapabilities, error)

	// GetStatus returns the current status of an ACP session.
	// Optional - runtimes that don't support status queries may return nil.
	GetStatus(ctx context.Context, handle AcpRuntimeHandle) (*AcpRuntimeStatus, error)

	// SetMode changes the runtime mode for an ACP session.
	// Optional - runtimes that don't support mode changes may return an error.
	SetMode(ctx context.Context, handle AcpRuntimeHandle, mode string) error

	// SetConfigOption sets a configuration option on an ACP session.
	// Optional - runtimes that don't support config options may return an error.
	SetConfigOption(ctx context.Context, handle AcpRuntimeHandle, key, value string) error

	// Doctor performs a health check on the runtime backend.
	// Optional - runtimes without health checks may return a static report.
	Doctor(ctx context.Context) (AcpRuntimeDoctorReport, error)

	// Cancel cancels an active turn in an ACP session.
	Cancel(ctx context.Context, handle AcpRuntimeHandle, reason string) error

	// Close closes an ACP session and releases resources.
	Close(ctx context.Context, handle AcpRuntimeHandle, reason string) error
}

AcpRuntime is the interface that all ACP runtime backends must implement. It provides methods for session lifecycle, turn execution, and control operations.

type AcpRuntimeBackend

type AcpRuntimeBackend struct {
	// ID is the unique identifier for this backend
	ID string

	// Runtime is the ACP runtime implementation
	Runtime AcpRuntime

	// Healthy is an optional function to check if the backend is healthy.
	// If nil, the backend is always considered healthy.
	Healthy func() bool
}

AcpRuntimeBackend represents a registered ACP runtime backend.

func GetAcpRuntimeBackend

func GetAcpRuntimeBackend(id string) *AcpRuntimeBackend

GetAcpRuntimeBackend retrieves an ACP runtime backend by ID. If ID is empty, returns the first healthy backend. Returns nil if no matching backend is found.

func RequireAcpRuntimeBackend

func RequireAcpRuntimeBackend(id string) (*AcpRuntimeBackend, error)

RequireAcpRuntimeBackend retrieves an ACP runtime backend or returns an error. If ID is empty, returns the first healthy backend. Returns an error if no matching backend is found or if the backend is unhealthy.

type AcpRuntimeBackendStats

type AcpRuntimeBackendStats struct {
	Total      int // Total number of registered backends
	Healthy    int // Number of healthy backends
	Unhealthy  int // Number of unhealthy backends
	BackendIDs []string
}

GetAcpRuntimeBackendStats returns statistics about registered backends.

func GetAcpRuntimeBackendStats

func GetAcpRuntimeBackendStats() AcpRuntimeBackendStats

GetAcpRuntimeBackendStats returns statistics about all registered backends.

type AcpRuntimeCapabilities

type AcpRuntimeCapabilities struct {
	// Controls lists the control operations supported by this runtime
	Controls []AcpRuntimeControl

	// ConfigOptionKeys are optional backend-advertised config keys for session/set_config_option.
	// Empty/nil means backend accepts keys but did not advertise a strict list.
	ConfigOptionKeys []string
}

AcpRuntimeCapabilities describes the capabilities of an ACP runtime.

type AcpRuntimeControl

type AcpRuntimeControl string

AcpRuntimeControl represents control operations supported by ACP runtimes.

const (
	AcpControlSessionSetMode         AcpRuntimeControl = "session/set_mode"
	AcpControlSessionSetConfigOption AcpRuntimeControl = "session/set_config_option"
	AcpControlSessionStatus          AcpRuntimeControl = "session/status"
)

type AcpRuntimeDoctorReport

type AcpRuntimeDoctorReport struct {
	// Ok indicates if the runtime is healthy
	Ok bool

	// Code is an error code if Ok is false
	Code string

	// Message describes the health status
	Message string

	// InstallCommand is a suggested installation command if the runtime is missing
	InstallCommand string

	// Details contains additional diagnostic information
	Details []string
}

AcpRuntimeDoctorReport is the result of a health check on an ACP runtime.

type AcpRuntimeEnsureInput

type AcpRuntimeEnsureInput struct {
	// SessionKey is the goclaw session key
	SessionKey string

	// Agent is the agent ID to use for this session
	Agent string

	// Mode is the session lifecycle mode
	Mode AcpRuntimeSessionMode

	// Cwd is the working directory for the session
	Cwd string

	// Env contains environment variables to pass to the runtime
	Env map[string]string
}

AcpRuntimeEnsureInput contains parameters for creating/ensuring an ACP session.

type AcpRuntimeError

type AcpRuntimeError struct {
	Code    string // Machine-readable error code
	Message string // Human-readable error message
	Err     error  // Underlying error, if any
}

AcpRuntimeError represents errors that occur during ACP runtime operations.

func NewAcpRuntimeError

func NewAcpRuntimeError(code, message string, err error) *AcpRuntimeError

NewAcpRuntimeError creates a new AcpRuntimeError.

func NewBackendMissingError

func NewBackendMissingError(backend string) *AcpRuntimeError

NewBackendMissingError creates an error for missing backend.

func NewBackendUnavailableError

func NewBackendUnavailableError(backend string) *AcpRuntimeError

NewBackendUnavailableError creates an error for unavailable backend.

func NewSessionInitError

func NewSessionInitError(message string, err error) *AcpRuntimeError

NewSessionInitError creates an error for session initialization failure.

func NewSessionLimitError

func NewSessionLimitError(current, max int) *AcpRuntimeError

NewSessionLimitError creates an error for session limit reached.

func NewTurnError

func NewTurnError(message string, err error) *AcpRuntimeError

NewTurnError creates an error for turn execution failure.

func NewUnsupportedControlError

func NewUnsupportedControlError(backend string, control AcpRuntimeControl) *AcpRuntimeError

NewUnsupportedControlError creates an error for unsupported control operations.

func (*AcpRuntimeError) Error

func (e *AcpRuntimeError) Error() string

Error implements the error interface.

func (*AcpRuntimeError) Unwrap

func (e *AcpRuntimeError) Unwrap() error

Unwrap returns the underlying error.

type AcpRuntimeEvent

type AcpRuntimeEvent interface {
	// contains filtered or unexported methods
}

AcpRuntimeEvent represents events streamed during ACP turn execution.

type AcpRuntimeHandle

type AcpRuntimeHandle struct {
	// SessionKey is the goclaw session key for this ACP session
	SessionKey string

	// Backend is the identifier of the runtime backend (e.g., "acpx", "acp-go-sdk")
	Backend string

	// RuntimeSessionName is the session name assigned by the runtime
	RuntimeSessionName string

	// Cwd is the effective working directory for this ACP session
	Cwd string

	// AcpxRecordId is the backend-local record identifier (for acpx backend)
	AcpxRecordId string

	// BackendSessionId is the backend-level ACP session identifier
	BackendSessionId string

	// AgentSessionId is the upstream harness/agent session identifier
	AgentSessionId string
}

AcpRuntimeHandle uniquely identifies an active ACP session.

type AcpRuntimePromptMode

type AcpRuntimePromptMode string

AcpRuntimePromptMode defines how a prompt is delivered to the ACP agent. "prompt" - Standard prompt delivery "steer" - Steering/instructional prompt for active turns

const (
	AcpPromptModePrompt AcpRuntimePromptMode = "prompt"
	AcpPromptModeSteer  AcpRuntimePromptMode = "steer"
)

type AcpRuntimeSessionMode

type AcpRuntimeSessionMode string

AcpRuntimeSessionMode defines the lifecycle mode of an ACP session. "persistent" - Session remains active after turn completion "oneshot" - Session closes after single turn completion

const (
	AcpSessionModePersistent AcpRuntimeSessionMode = "persistent"
	AcpSessionModeOneshot    AcpRuntimeSessionMode = "oneshot"
)

type AcpRuntimeStatus

type AcpRuntimeStatus struct {
	// Summary is a human-readable status summary
	Summary string

	// AcpxRecordId is the backend-local record identifier
	AcpxRecordId string

	// BackendSessionId is the backend-level ACP session identifier
	BackendSessionId string

	// AgentSessionId is the upstream harness session identifier
	AgentSessionId string

	// Details contains additional backend-specific status details
	Details map[string]any
}

AcpRuntimeStatus represents the current status of an ACP session.

type AcpRuntimeTurnInput

type AcpRuntimeTurnInput struct {
	// Handle identifies the ACP session
	Handle AcpRuntimeHandle

	// Text is the prompt text to send
	Text string

	// Mode is the prompt delivery mode
	Mode AcpRuntimePromptMode

	// RequestID uniquely identifies this turn request
	RequestID string

	// Signal allows canceling the turn
	Signal context.CancelFunc
}

AcpRuntimeTurnInput contains parameters for executing a turn in an ACP session.

Jump to

Keyboard shortcuts

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