Documentation
¶
Overview ¶
Package serve implements the agentctl HTTP/SSE agent server (v0.8).
Index ¶
- Variables
- func WriteSSE(w io.Writer, ev wire.Event) error
- type Config
- type Manager
- func (m *Manager) CreateSession(ctx context.Context, inputs map[string]string) (sessions.Session, error)
- func (m *Manager) Draining() bool
- func (m *Manager) EndSession(ctx context.Context, id string) error
- func (m *Manager) GetSession(ctx context.Context, id string) (sessions.Session, error)
- func (m *Manager) ListSessions(ctx context.Context, status sessions.SessionStatus) ([]sessions.Session, error)
- func (m *Manager) RunTurn(ctx context.Context, id, input string, emit func(wire.Event) error) error
- func (m *Manager) Serve(ctx context.Context, addr string) error
- func (m *Manager) SetDraining(v bool)
Constants ¶
This section is empty.
Variables ¶
var ErrSessionBusy = errors.New("serve: session busy")
ErrSessionBusy is returned by tryLockSession when another turn is already in-flight for the requested session id.
var ErrTooManySessions = errors.New("serve: max sessions reached")
ErrTooManySessions is returned by CreateSession when the active session count has reached the configured MaxSessions limit.
var ErrTooManyTurns = errors.New("serve: too many concurrent turns")
ErrTooManyTurns is returned by acquireTurnSlot when the global concurrent turn cap (MaxConcurrentTurns) has been reached.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Store sessions.Store
Spec adl.CompiledSpec
RuntimeCommand []string
MaxConcurrentTurns int
MaxSessions int
SessionTTL time.Duration
ShutdownGrace time.Duration
Backend backend.Backend
}
Config holds the knobs newServeCmd wires from flags.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns all server-side session state: the store, adapter dispatch, concurrency controls, and the draining flag. Safe for concurrent use.
func NewManager ¶
func (*Manager) CreateSession ¶
func (m *Manager) CreateSession(ctx context.Context, inputs map[string]string) (sessions.Session, error)
CreateSession creates a new active session. It generates a unique session id, applies ${inputs.*} interpolation to a copy of the spec's task, and persists the session via the store. Returns ErrTooManySessions when the active count is at or above MaxSessions (0 means unlimited).
func (*Manager) EndSession ¶
EndSession transitions a session to StatusEnded. Returns sessions.ErrNotFound when the session doesn't exist.
func (*Manager) GetSession ¶
GetSession retrieves a session by id. Returns sessions.ErrNotFound when the session doesn't exist.
func (*Manager) ListSessions ¶
func (m *Manager) ListSessions(ctx context.Context, status sessions.SessionStatus) ([]sessions.Session, error)
ListSessions returns sessions matching the given status. An empty status returns all sessions.
func (*Manager) RunTurn ¶
RunTurn drives a single adapter turn for the session identified by id. It mirrors the runChatTurn logic in cli/cmd/agentctl/chat.go:
- Load the session; return ErrNotFound if missing or in a terminal state.
- Build a per-turn spec (Task = input, SessionID = session id).
- Resolve → emit warnings via emit.
- Submit → drain Events, forwarding each to emit.
- Map EventError / session.ended{reason=error|cancelled} to a returned error.
- Best-effort: update LastActiveAt in the store before returning.
func (*Manager) Serve ¶
Serve starts the HTTP server on addr and blocks until ctx is cancelled, then drains in-flight requests up to cfg.ShutdownGrace. Returns nil on a clean drain.