Documentation
¶
Index ¶
- Variables
- func BearerTokenMiddleware(expectedToken string) echo.MiddlewareFunc
- func Listen(ctx context.Context, addr string) (net.Listener, error)
- func NewSourceLoader(ctx context.Context, inner config.Source, refreshInterval time.Duration) *sourceLoader
- type EventSource
- type Server
- type SessionManager
- func (sm *SessionManager) AddMessage(ctx context.Context, sessionID string, msg *session.Message) error
- func (sm *SessionManager) AddSummary(ctx context.Context, sessionID, summary string, tokens int) error
- func (sm *SessionManager) AttachRuntime(sessionID string, rt runtime.Runtime, sess *session.Session)
- func (sm *SessionManager) AvailableSessionModels(ctx context.Context, sessionID string) (string, string, []runtime.ModelChoice, error)
- func (sm *SessionManager) BatchDeleteSessions(ctx context.Context, sessionIDs []string) (int, []string)
- func (sm *SessionManager) BatchExportSessions(ctx context.Context, sessionIDs []string) (map[string]any, error)
- func (sm *SessionManager) CreateSession(ctx context.Context, sessionTemplate *session.Session) (*session.Session, error)
- func (sm *SessionManager) DeleteSession(ctx context.Context, sessionID string) error
- func (sm *SessionManager) ExportSessionForRecovery(ctx context.Context, sessionID string) (map[string]any, error)
- func (sm *SessionManager) FollowUpSession(_ context.Context, sessionID string, messages []api.Message) (streaming bool, err error)
- func (sm *SessionManager) GetAgentToolCount(ctx context.Context, agentFilename, agentName string) (int, error)
- func (sm *SessionManager) GetEventSource(sessionID string) (EventSource, bool)
- func (sm *SessionManager) GetSession(ctx context.Context, id string) (*session.Session, error)
- func (sm *SessionManager) GetSessionStatus(_ context.Context, id string) (*api.SessionStatusResponse, error)
- func (sm *SessionManager) GetSessions(ctx context.Context) ([]*session.Session, error)
- func (sm *SessionManager) RegisterEventSource(sessionID string, src EventSource)
- func (sm *SessionManager) ResumeElicitation(ctx context.Context, sessionID, action string, content map[string]any) error
- func (sm *SessionManager) ResumeSession(ctx context.Context, sessionID, confirmation, reason, toolName string) error
- func (sm *SessionManager) RunSession(ctx context.Context, sessionID, agentFilename, currentAgent string, ...) (<-chan runtime.Event, error)
- func (sm *SessionManager) SetSessionAgentModel(ctx context.Context, sessionID, modelRef string) (string, string, error)
- func (sm *SessionManager) SetSessionStarred(ctx context.Context, sessionID string, starred bool) error
- func (sm *SessionManager) SteerSession(_ context.Context, sessionID string, messages []api.Message) error
- func (sm *SessionManager) StreamEvents(ctx context.Context, sessionID string, send func(any)) bool
- func (sm *SessionManager) ToggleToolApproval(ctx context.Context, sessionID string) error
- func (sm *SessionManager) UpdateMessage(ctx context.Context, sessionID, msgID string, msg *session.Message) error
- func (sm *SessionManager) UpdateSessionPermissions(ctx context.Context, sessionID string, perms *session.PermissionsConfig) error
- func (sm *SessionManager) UpdateSessionTitle(ctx context.Context, sessionID, title string) error
- func (sm *SessionManager) UpdateSessionTokens(ctx context.Context, sessionID string, inputTokens, outputTokens int64, ...) error
- func (sm *SessionManager) WaitReady(ctx context.Context) error
- func (sm *SessionManager) WaitStopped(ctx context.Context, sessionID string, timeout time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ErrModelSwitchingNotSupported = errors.New("model switching not supported by this runtime")
ErrModelSwitchingNotSupported is returned when the runtime backing a session does not support runtime model switching (e.g. when the agent was created without a ModelSwitcherConfig).
var ErrSessionBusy = errors.New("session is already processing a request")
ErrSessionBusy is returned when a session is already processing a request.
var ErrSessionNotRunning = errors.New("session not found or not running")
ErrSessionNotRunning is returned by methods that require an active runtime for the session (i.e. RunSession must have been called or AttachRuntime invoked) when none is found. HTTP handlers map this to 404 to distinguish from other runtime errors.
Functions ¶
func BearerTokenMiddleware ¶ added in v1.59.0
func BearerTokenMiddleware(expectedToken string) echo.MiddlewareFunc
BearerTokenMiddleware validates bearer token authentication
Types ¶
type EventSource ¶ added in v1.58.0
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 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.
type SessionManager ¶
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) AvailableSessionModels ¶ added in v1.60.0
func (sm *SessionManager) AvailableSessionModels(ctx context.Context, sessionID string) (string, string, []runtime.ModelChoice, error)
AvailableSessionModels returns the list of models available for the session's current agent. The agent's name and the active model override (if any) are returned alongside the choices so callers don't have to peek into the runtime registry. A session-scoped runtime is required, so the session must have been started at least once (RunSession called) or be attached out-of-band via AttachRuntime.
Each returned ModelChoice has IsCurrent set so the picker can highlight the active selection without a second round-trip. When no override is active, the agent's configured default carries IsCurrent=true; if the override points at an inline provider/model not present in the agent config, a synthetic choice is appended (mirrors App.AvailableModels via the shared runtime.DecorateModelChoices helper).
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 ¶
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 ¶
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) SetSessionAgentModel ¶ added in v1.60.0
func (sm *SessionManager) SetSessionAgentModel(ctx context.Context, sessionID, modelRef string) (string, string, error)
SetSessionAgentModel applies modelRef as the model override for the current agent of the session, persists it to the session store, and tracks custom models for later re-selection. Pass an empty modelRef to clear the override and revert to the agent's default model.
On store-write failure the in-memory session state and the runtime override are rolled back so the next call observes a consistent state.
Concurrent SetSessionAgentModel calls on the same session are serialised via the session-scoped modelSwitch lock so the runtime, session and store never observe interleaved updates. The manager-wide sm.mux is only held briefly while reading or mutating session fields, never while calling into the runtime or the store.
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
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.