server

package
v1.59.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionBusy = errors.New("session is already processing a request")

ErrSessionBusy is returned when a session is already processing a request.

Functions

func BearerTokenMiddleware added in v1.59.0

func BearerTokenMiddleware(expectedToken string) echo.MiddlewareFunc

BearerTokenMiddleware validates bearer token authentication

func Listen

func Listen(ctx context.Context, addr string) (net.Listener, error)

func NewSourceLoader

func NewSourceLoader(ctx context.Context, inner config.Source, refreshInterval time.Duration) *sourceLoader

NewSourceLoader creates a new source loader that caches and periodically refreshes a config source.

Types

type EventSource added in v1.58.0

type EventSource func(ctx context.Context, send func(any))

EventSource pushes session events to send for the lifetime of ctx. The callback is invoked from request goroutines (e.g. an SSE handler), so it must be safe to call concurrently across requests.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, sessionStore session.Store, runConfig *config.RuntimeConfig, refreshInterval time.Duration, agentSources config.Sources, authToken string) (*Server, error)

func NewWithManager added in v1.58.0

func NewWithManager(sm *SessionManager, authToken string) *Server

NewWithManager builds a Server around an already-constructed SessionManager. Useful when the runtime is owned by another component (e.g. the TUI) and only needs to be exposed over HTTP.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

type SessionManager

type SessionManager struct {
	Sources config.Sources
	// contains filtered or unexported fields
}

SessionManager manages sessions for HTTP and Connect-RPC servers.

func NewSessionManager

func NewSessionManager(ctx context.Context, sources config.Sources, sessionStore session.Store, refreshInterval time.Duration, runConfig *config.RuntimeConfig) *SessionManager

NewSessionManager creates a new session manager.

func (*SessionManager) AddMessage added in v1.59.0

func (sm *SessionManager) AddMessage(ctx context.Context, sessionID string, msg *session.Message) error

AddMessage adds a message to a session.

func (*SessionManager) AddSummary added in v1.59.0

func (sm *SessionManager) AddSummary(ctx context.Context, sessionID, summary string, tokens int) error

AddSummary adds a summary to a session.

func (*SessionManager) AttachRuntime added in v1.58.0

func (sm *SessionManager) AttachRuntime(sessionID string, rt runtime.Runtime, sess *session.Session)

AttachRuntime registers a pre-built runtime + session under sessionID so that subsequent calls (RunSession, Steer, Resume...) reuse it instead of building one from agentFilename. This is what lets a single in-process runtime be shared between the TUI and an HTTP control plane.

The internal cancellation signal is fired by SessionManager.DeleteSession; SSE streams and other lifetime-bound consumers use it (via SessionManager.StreamEvents) to terminate when the session is detached.

func (*SessionManager) BatchDeleteSessions added in v1.59.0

func (sm *SessionManager) BatchDeleteSessions(ctx context.Context, sessionIDs []string) (int, []string)

BatchDeleteSessions deletes multiple sessions in a single operation.

func (*SessionManager) BatchExportSessions added in v1.59.0

func (sm *SessionManager) BatchExportSessions(ctx context.Context, sessionIDs []string) (map[string]any, error)

BatchExportSessions exports multiple sessions as JSON

func (*SessionManager) CreateSession

func (sm *SessionManager) CreateSession(ctx context.Context, sessionTemplate *session.Session) (*session.Session, error)

CreateSession creates a new session from a template.

func (*SessionManager) DeleteSession

func (sm *SessionManager) DeleteSession(ctx context.Context, sessionID string) error

DeleteSession deletes a session by ID. It cancels the runtime context and removes the session from all registries. Callers that need to wait for the stream to fully stop should call WaitStopped afterwards.

func (*SessionManager) ExportSessionForRecovery added in v1.59.0

func (sm *SessionManager) ExportSessionForRecovery(ctx context.Context, sessionID string) (map[string]any, error)

ExportSessionForRecovery exports a single session as JSON for recovery

func (*SessionManager) FollowUpSession added in v1.44.0

func (sm *SessionManager) FollowUpSession(_ context.Context, sessionID string, messages []api.Message) (streaming bool, err error)

FollowUpSession enqueues user messages for end-of-turn processing in a running session. Each message is popped one at a time after the current turn finishes, giving each follow-up a full undivided agent turn.

If no stream is currently running (agent is idle), the messages are still enqueued but will not be consumed until the next RunSession starts a new stream. The returned boolean indicates whether a stream is active.

func (*SessionManager) GetAgentToolCount

func (sm *SessionManager) GetAgentToolCount(ctx context.Context, agentFilename, agentName string) (int, error)

GetAgentToolCount loads the agent's team and returns the number of tools available to the given agent. When agentName is empty, it resolves to the team's default agent.

func (*SessionManager) GetEventSource added in v1.58.0

func (sm *SessionManager) GetEventSource(sessionID string) (EventSource, bool)

GetEventSource returns the registered event source for sessionID.

func (*SessionManager) GetSession

func (sm *SessionManager) GetSession(ctx context.Context, id string) (*session.Session, error)

GetSession retrieves a session by ID.

func (*SessionManager) GetSessionStatus added in v1.59.0

func (sm *SessionManager) GetSessionStatus(_ context.Context, id string) (*api.SessionStatusResponse, error)

GetSessionStatus returns a lightweight snapshot of the session's current runtime state. Designed for late-joining SSE consumers that need to know the session's state without waiting for the next event transition.

func (*SessionManager) GetSessions

func (sm *SessionManager) GetSessions(ctx context.Context) ([]*session.Session, error)

GetSessions retrieves all sessions.

func (*SessionManager) RegisterEventSource added in v1.58.0

func (sm *SessionManager) RegisterEventSource(sessionID string, src EventSource)

RegisterEventSource attaches an event source for sessionID. It is used by callers that own a runtime out-of-band (e.g. the TUI) so that HTTP clients can subscribe to events via GET /api/sessions/:id/events.

func (*SessionManager) ResumeElicitation

func (sm *SessionManager) ResumeElicitation(ctx context.Context, sessionID, action string, content map[string]any) error

ResumeElicitation resumes an elicitation request.

func (*SessionManager) ResumeSession

func (sm *SessionManager) ResumeSession(ctx context.Context, sessionID, confirmation, reason, toolName string) error

ResumeSession resumes a paused session with an optional rejection reason or tool name.

func (*SessionManager) RunSession

func (sm *SessionManager) RunSession(ctx context.Context, sessionID, agentFilename, currentAgent string, messages []api.Message) (<-chan runtime.Event, error)

RunSession runs a session with the given messages.

func (*SessionManager) SetSessionStarred added in v1.59.0

func (sm *SessionManager) SetSessionStarred(ctx context.Context, sessionID string, starred bool) error

SetSessionStarred sets the starred status for a session.

func (*SessionManager) SteerSession added in v1.44.0

func (sm *SessionManager) SteerSession(_ context.Context, sessionID string, messages []api.Message) error

SteerSession enqueues user messages for mid-turn injection into a running session. The messages are picked up by the agent loop after the current tool calls finish but before the next LLM call. Returns an error if the session is not actively running or if the steer buffer is full.

func (*SessionManager) StreamEvents added in v1.58.0

func (sm *SessionManager) StreamEvents(ctx context.Context, sessionID string, send func(any)) bool

StreamEvents drives the EventSource registered for sessionID, sending each event through send. It blocks until the source returns, the caller's ctx is cancelled, or the session is detached via SessionManager.DeleteSession. Returns false when no source is registered.

func (*SessionManager) ToggleToolApproval

func (sm *SessionManager) ToggleToolApproval(ctx context.Context, sessionID string) error

ToggleToolApproval toggles the tool approval mode for a session.

func (*SessionManager) UpdateMessage added in v1.59.0

func (sm *SessionManager) UpdateMessage(ctx context.Context, sessionID, msgID string, msg *session.Message) error

UpdateMessage updates a message in a session.

func (*SessionManager) UpdateSessionPermissions

func (sm *SessionManager) UpdateSessionPermissions(ctx context.Context, sessionID string, perms *session.PermissionsConfig) error

UpdateSessionPermissions updates the permissions for a session.

func (*SessionManager) UpdateSessionTitle

func (sm *SessionManager) UpdateSessionTitle(ctx context.Context, sessionID, title string) error

UpdateSessionTitle updates the title for a session. If the session is actively running, it also updates the in-memory session object to prevent subsequent runtime saves from overwriting the title.

func (*SessionManager) UpdateSessionTokens added in v1.59.0

func (sm *SessionManager) UpdateSessionTokens(ctx context.Context, sessionID string, inputTokens, outputTokens int64, cost float64) error

UpdateSessionTokens updates the token counts for a session.

func (*SessionManager) WaitReady added in v1.59.0

func (sm *SessionManager) WaitReady(ctx context.Context) error

WaitReady blocks until at least one session has been attached or created, or ctx is cancelled. Returns nil when ready, ctx.Err() on timeout.

func (*SessionManager) WaitStopped added in v1.59.0

func (sm *SessionManager) WaitStopped(ctx context.Context, sessionID string, timeout time.Duration) error

WaitStopped blocks until the session's runtime stream goroutine has fully exited (streaming mutex released), the timeout fires, or ctx is cancelled (e.g. client disconnect). It should be called after DeleteSession. Returns nil when the stream has stopped.

Jump to

Keyboard shortcuts

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