serve

package
v0.0.0-...-bea457f Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package serve implements the agentctl HTTP/SSE agent server (v0.8).

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionBusy = errors.New("serve: session busy")

ErrSessionBusy is returned by tryLockSession when another turn is already in-flight for the requested session id.

View Source
var ErrTooManySessions = errors.New("serve: max sessions reached")

ErrTooManySessions is returned by CreateSession when the active session count has reached the configured MaxSessions limit.

View Source
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

func WriteSSE

func WriteSSE(w io.Writer, ev wire.Event) error

WriteSSE writes one Server-Sent-Events frame for a wire event: an `event:` line carrying the wire type (so clients can switch on it) and a `data:` line carrying the full event JSON, terminated by a blank line. The caller is responsible for flushing.

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 NewManager(cfg Config) *Manager

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) Draining

func (m *Manager) Draining() bool

func (*Manager) EndSession

func (m *Manager) EndSession(ctx context.Context, id string) error

EndSession transitions a session to StatusEnded. Returns sessions.ErrNotFound when the session doesn't exist.

func (*Manager) GetSession

func (m *Manager) GetSession(ctx context.Context, id string) (sessions.Session, error)

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

func (m *Manager) RunTurn(ctx context.Context, id, input string, emit func(wire.Event) error) error

RunTurn drives a single adapter turn for the session identified by id. It mirrors the runChatTurn logic in cli/cmd/agentctl/chat.go:

  1. Load the session; return ErrNotFound if missing or in a terminal state.
  2. Build a per-turn spec (Task = input, SessionID = session id).
  3. Resolve → emit warnings via emit.
  4. Submit → drain Events, forwarding each to emit.
  5. Map EventError / session.ended{reason=error|cancelled} to a returned error.
  6. Best-effort: update LastActiveAt in the store before returning.

func (*Manager) Serve

func (m *Manager) Serve(ctx context.Context, addr string) error

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.

func (*Manager) SetDraining

func (m *Manager) SetDraining(v bool)

Jump to

Keyboard shortcuts

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