interrupt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionAllowOnce    = "allow_once"
	PermissionAllowAlways  = "allow_always"
	PermissionRejectOnce   = "reject_once"
	PermissionRejectAlways = "reject_always"
)

ACP PermissionOptionKind values.

Variables

View Source
var (
	ErrInterruptNotFound = errors.New("interrupt not found")
	ErrInvalidPayload    = errors.New("invalid payload")
)

Functions

func Register

func Register(factory func() Interrupt)

Register adds a factory for an Interrupt type under its TypeName. Call at init for custom interrupts so checkpoints can rehydrate them.

Types

type Interrupt

type Interrupt interface {
	// TypeName returns a stable, unique name for this interrupt type. It is
	// used as the JSON discriminator when persisting interrupts to session
	// storage and as the lookup key in the interrupt registry.
	TypeName() string
	// Serialize the interrupt to a byte slice for transmission.
	Serialize() ([]byte, error)
	// Return the interrupt to the agent workflow with a serialized
	// payload of the interrupt result.
	Return([]byte) error
	// Error makes Interrupt compatible with the error interface.
	Error() string
}

Interrupt represents a pending interrupt in an agent workflow requesting the user for additional input or approval. Implementations must also satisfy the error interface so they can be returned from tool handlers and detected via errors.As.

func Clone

func Clone(intr Interrupt) Interrupt

Clone returns a deep copy via JSON for checkpoint snapshots. Returns nil if the type is unknown or serialization fails (best-effort).

func New

func New(typeName string) (Interrupt, bool)

New returns a fresh Interrupt for a registered type name.

type PayloadInitializer

type PayloadInitializer interface {
	InitFromPayload([]byte) error
}

PayloadInitializer is an optional capability Interrupt types implement to populate themselves from the raw payload provided to RaiseInterrupt.

type PayloadValidator

type PayloadValidator interface {
	ValidatePayload([]byte) error
}

PayloadValidator is an optional capability for Interrupt types that want to pre-validate the consumer's response payload before it is passed to Return(). Implementations should check field presence, types, and bounds without mutating the Interrupt's internal state (that happens in Return). Detected via type assertion in ReturnInterrupt.

type PermissionOption

type PermissionOption struct {
	OptionID string `json:"optionId"`
	Name     string `json:"name"`
	Kind     string `json:"kind"`
}

PermissionOption is a single choice offered when a tool requires user approval. Field names match ACP session/request_permission options.

func DefaultPermissionOptions

func DefaultPermissionOptions() []PermissionOption

DefaultPermissionOptions are the standard ACP permission choices.

type ToolPermissionInterrupt

type ToolPermissionInterrupt struct {
	ToolName string             `json:"toolName,omitempty"`
	Title    string             `json:"title,omitempty"` // human-readable invocation label
	Options  []PermissionOption `json:"options"`

	// Set by Return after the consumer selects an option.
	SelectedOptionID string `json:"-"`
	SelectedKind     string `json:"-"`
	Allowed          bool   `json:"-"`
}

ToolPermissionInterrupt asks the user to approve or reject a tool call.

func (*ToolPermissionInterrupt) Error

func (p *ToolPermissionInterrupt) Error() string

func (*ToolPermissionInterrupt) InitFromPayload

func (p *ToolPermissionInterrupt) InitFromPayload(payload []byte) error

func (*ToolPermissionInterrupt) Return

func (p *ToolPermissionInterrupt) Return(payload []byte) error

func (*ToolPermissionInterrupt) Serialize

func (p *ToolPermissionInterrupt) Serialize() ([]byte, error)

func (*ToolPermissionInterrupt) TypeName

func (p *ToolPermissionInterrupt) TypeName() string

func (*ToolPermissionInterrupt) ValidatePayload

func (p *ToolPermissionInterrupt) ValidatePayload(payload []byte) error

type ToolPermissionPayload

type ToolPermissionPayload struct {
	InterruptId string `json:"interruptId,omitempty"`
	OptionID    string `json:"optionId"`
}

ToolPermissionPayload is the consumer resolution for a tool permission interrupt.

type UserChoice

type UserChoice struct {
	Title         string `json:"title"`
	Description   string `json:"description"`
	IsRecommended bool   `json:"isRecommended"`
}

type UserSelectionInterrupt

type UserSelectionInterrupt struct {
	Options         []UserChoice `json:"options"`
	ConfirmedChoice *UserChoice
}

func (*UserSelectionInterrupt) Error

func (c *UserSelectionInterrupt) Error() string

func (*UserSelectionInterrupt) InitFromPayload

func (c *UserSelectionInterrupt) InitFromPayload(payload []byte) error

func (*UserSelectionInterrupt) Return

func (c *UserSelectionInterrupt) Return(payload []byte) error

func (*UserSelectionInterrupt) Serialize

func (c *UserSelectionInterrupt) Serialize() ([]byte, error)

func (*UserSelectionInterrupt) TypeName

func (c *UserSelectionInterrupt) TypeName() string

func (*UserSelectionInterrupt) ValidatePayload

func (c *UserSelectionInterrupt) ValidatePayload(payload []byte) error

type UserSelectionPayload

type UserSelectionPayload struct {
	InterruptId  string `json:"interruptId"`
	SelectionIdx int    `json:"selectionIdx"`
}

Jump to

Keyboard shortcuts

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