Documentation
¶
Index ¶
- Variables
- type ArchiveBoundaryNotFoundError
- type CreateSessionRequest
- type ListSessionsRequest
- type RunLockKey
- type RunScopedLocker
- type Session
- type SessionService
- type SessionSortField
- type SortOrder
- type Turn
- type TurnFailure
- type TurnFailureProvider
- type TurnFailureStage
- type TurnNotFoundError
- type TurnOutcome
- type TurnReason
- type TurnStateConflictError
- type TurnStatus
- type TurnStore
Constants ¶
This section is empty.
Variables ¶
var ErrArchiveBoundaryNotFound = errors.New("session: archive boundary not found")
ErrArchiveBoundaryNotFound indicates that an archive boundary is not an active event in the session.
var ErrTurnNotFound = errors.New("session: turn not found")
ErrTurnNotFound identifies a requested Turn that does not exist.
var ErrTurnStateConflict = errors.New("session: turn state conflict")
ErrTurnStateConflict identifies an invalid Turn lifecycle transition.
Functions ¶
This section is empty.
Types ¶
type ArchiveBoundaryNotFoundError ¶ added in v0.0.11
type ArchiveBoundaryNotFoundError struct {
EventID int64
}
ArchiveBoundaryNotFoundError reports the missing archive boundary event.
func (*ArchiveBoundaryNotFoundError) Error ¶ added in v0.0.11
func (e *ArchiveBoundaryNotFoundError) Error() string
Error implements the error interface.
func (*ArchiveBoundaryNotFoundError) Unwrap ¶ added in v0.0.11
func (e *ArchiveBoundaryNotFoundError) Unwrap() error
Unwrap allows callers to match ErrArchiveBoundaryNotFound with errors.Is.
type CreateSessionRequest ¶ added in v0.0.6
type CreateSessionRequest struct {
// SessionID is the application-provided session identifier. It must be unique
// in the session store.
SessionID string
// AppID identifies the application or tenant that owns the session.
AppID string
// UserID identifies the end user that owns the session.
UserID string
}
CreateSessionRequest describes the session identity and ownership metadata recorded when a session is created.
type ListSessionsRequest ¶ added in v0.0.11
type ListSessionsRequest struct {
// AppID restricts results to sessions owned by this application or tenant.
AppID string
// UserID restricts results to sessions owned by this end user.
UserID string
// Limit is the maximum number of sessions to return. Zero uses the default of 50.
Limit int64
// Offset is the number of ordered sessions to skip.
Offset int64
// SortBy is the primary sort field. Empty defaults to SessionSortByCreatedAt.
SortBy SessionSortField
// SortOrder is the sort direction. Empty defaults to SortDescending.
SortOrder SortOrder
}
ListSessionsRequest filters, paginates, and orders sessions.
func (ListSessionsRequest) Normalize ¶ added in v0.0.11
func (r ListSessionsRequest) Normalize() (ListSessionsRequest, error)
Normalize validates the request and fills its documented defaults. Custom SessionService implementations should call Normalize before listing.
type RunLockKey ¶ added in v0.0.6
type RunLockKey struct {
// AppID identifies the application or tenant that owns the session.
AppID string
// UserID identifies the end user that owns the session.
UserID string
// SessionID is the application-provided session identifier.
SessionID string
}
RunLockKey identifies the conversation turn protected by a run lock.
type RunScopedLocker ¶ added in v0.0.6
type RunScopedLocker interface {
LockRun(ctx context.Context, key RunLockKey) (unlock func(), err error)
}
RunScopedLocker is an optional SessionService capability used by Runner to serialize complete turns for the same app/user/session identity. Implementations should allow different identities to proceed concurrently and honor context cancellation while waiting.
type Session ¶
type Session interface {
// GetSessionID returns the application-provided session identifier.
GetSessionID() string
// GetAppID returns the application or tenant that owns the session.
GetAppID() string
// GetUserID returns the end user that owns the session.
GetUserID() string
// GetCreatedAt returns the Unix millisecond timestamp when the session was created.
GetCreatedAt() int64
CreateEvent(ctx context.Context, event *event.Event) error
// GetEvents returns a paginated slice of active (non-archived, non-deleted) events
// sorted by created_at ASC.
GetEvents(ctx context.Context, limit, offset int64) ([]*event.Event, error)
// ListEvents returns all active (non-archived, non-deleted) events sorted by
// created_at ASC. Use this instead of GetEvents when the full history is needed.
ListEvents(ctx context.Context) ([]*event.Event, error)
DeleteEvent(ctx context.Context, eventID int64) error
// ListArchivedEvents returns all archived, non-deleted events sorted by
// created_at ASC with event_id as a stable tiebreaker.
ListArchivedEvents(ctx context.Context) ([]*event.Event, error)
// ArchiveEventsBefore archives all active events that precede eventID in
// conversation order. eventID remains active. Zero archives all active
// events. A non-zero eventID must identify an active event in this session.
// Archiving is idempotent and never creates or deletes events.
ArchiveEventsBefore(ctx context.Context, eventID int64) error
}
Session stores the durable event ledger and ownership metadata for one conversation thread.
type SessionService ¶
type SessionService interface {
CreateSession(ctx context.Context, req CreateSessionRequest) (Session, error)
DeleteSession(ctx context.Context, sessionID string) error
GetSession(ctx context.Context, sessionID string) (Session, error)
ListSessions(ctx context.Context, req ListSessionsRequest) ([]Session, error)
}
SessionService creates, deletes, lists, and retrieves sessions by ID.
type SessionSortField ¶ added in v0.0.11
type SessionSortField string
SessionSortField identifies a supported field for ordering listed sessions.
const ( // SessionSortByCreatedAt orders sessions by creation time. SessionSortByCreatedAt SessionSortField = "created_at" // SessionSortBySessionID orders sessions by their application-provided IDs. SessionSortBySessionID SessionSortField = "session_id" )
type SortOrder ¶ added in v0.0.11
type SortOrder string
SortOrder identifies the direction used to order listed sessions.
type Turn ¶ added in v0.1.0
type Turn struct {
ID string `json:"turn_id" db:"turn_id"`
SessionID string `json:"session_id" db:"session_id"`
Status TurnStatus `json:"status" db:"status"`
Reason TurnReason `json:"reason" db:"reason"`
Failure *TurnFailure `json:"failure,omitempty" db:"-"`
StartedAt int64 `json:"started_at" db:"started_at"`
FinishedAt int64 `json:"finished_at" db:"finished_at"`
}
Turn records the durable lifecycle metadata for one Runner execution. Events remain stored separately and are associated by SessionID and ID.
type TurnFailure ¶ added in v0.1.0
type TurnFailure struct {
Code string `json:"code" db:"failure_code"`
Message string `json:"message" db:"failure_message"`
Stage TurnFailureStage `json:"stage" db:"failure_stage"`
}
TurnFailure contains structured failure information that is safe to persist and display. Message must never be populated from an arbitrary error string.
type TurnFailureProvider ¶ added in v0.1.0
type TurnFailureProvider interface {
TurnFailure() TurnFailure
}
TurnFailureProvider may be implemented by typed errors that can expose structured failure information safe to persist and display.
type TurnFailureStage ¶ added in v0.1.0
type TurnFailureStage string
TurnFailureStage identifies where a safe, structured Turn failure occurred.
const ( // TurnFailureStageAgent identifies agent orchestration failures. TurnFailureStageAgent TurnFailureStage = "agent" // TurnFailureStageProvider identifies model-provider failures. TurnFailureStageProvider TurnFailureStage = "provider" // TurnFailureStageTool identifies tool execution or protocol failures. TurnFailureStageTool TurnFailureStage = "tool" // TurnFailureStagePersistence identifies session persistence failures. TurnFailureStagePersistence TurnFailureStage = "persistence" // TurnFailureStageConsumer identifies output delivery or consumer failures. TurnFailureStageConsumer TurnFailureStage = "consumer" )
type TurnNotFoundError ¶ added in v0.1.0
type TurnNotFoundError struct {
TurnID string
}
TurnNotFoundError reports a missing Turn.
func (*TurnNotFoundError) Error ¶ added in v0.1.0
func (e *TurnNotFoundError) Error() string
func (*TurnNotFoundError) Unwrap ¶ added in v0.1.0
func (e *TurnNotFoundError) Unwrap() error
Unwrap supports errors.Is(err, ErrTurnNotFound).
type TurnOutcome ¶ added in v0.1.0
type TurnOutcome struct {
// Status is the terminal state to record.
Status TurnStatus
// Reason is the stable terminal classification. It is empty for completed Turns.
Reason TurnReason
// Failure contains optional safe display metadata for a non-completed Turn.
Failure *TurnFailure
}
TurnOutcome describes one terminal state transition for a running Turn.
func (TurnOutcome) Validate ¶ added in v0.1.0
func (o TurnOutcome) Validate() error
Validate checks that the outcome represents a valid terminal Turn state.
type TurnReason ¶ added in v0.1.0
type TurnReason string
TurnReason is a stable, non-sensitive explanation for a terminal Turn state.
const ( // TurnReasonCanceled indicates context cancellation. TurnReasonCanceled TurnReason = "canceled" // TurnReasonDeadline indicates that the execution deadline expired. TurnReasonDeadline TurnReason = "deadline_exceeded" // TurnReasonConsumerStopped indicates that the caller stopped consuming events. TurnReasonConsumerStopped TurnReason = "consumer_stopped" // TurnReasonAgentError indicates an agent, tool, provider, or framework failure. TurnReasonAgentError TurnReason = "agent_error" // TurnReasonAbandoned indicates a running Turn left behind by an earlier execution. TurnReasonAbandoned TurnReason = "abandoned" )
type TurnStateConflictError ¶ added in v0.1.0
type TurnStateConflictError struct {
TurnID string
Status TurnStatus
}
TurnStateConflictError reports an attempted transition from a non-running Turn.
func (*TurnStateConflictError) Error ¶ added in v0.1.0
func (e *TurnStateConflictError) Error() string
func (*TurnStateConflictError) Unwrap ¶ added in v0.1.0
func (e *TurnStateConflictError) Unwrap() error
Unwrap supports errors.Is(err, ErrTurnStateConflict).
type TurnStatus ¶ added in v0.1.0
type TurnStatus string
TurnStatus describes the durable lifecycle state of one Runner execution.
const ( // TurnRunning indicates that the execution has started but has not finalized. TurnRunning TurnStatus = "running" // TurnCompleted indicates that the execution finished normally. TurnCompleted TurnStatus = "completed" // TurnInterrupted indicates that execution stopped because it was canceled, // timed out, abandoned, or no longer consumed by the caller. TurnInterrupted TurnStatus = "interrupted" // TurnFailed indicates that execution terminated with an agent or framework error. TurnFailed TurnStatus = "failed" )
type TurnStore ¶ added in v0.1.0
type TurnStore interface {
// BeginTurn durably creates a running Turn.
BeginTurn(ctx context.Context, turn Turn) error
// FinalizeTurn atomically transitions a running Turn to one terminal outcome.
FinalizeTurn(ctx context.Context, turnID string, outcome TurnOutcome) error
// GetTurn returns one Turn, or nil when it does not exist.
GetTurn(ctx context.Context, turnID string) (*Turn, error)
// ListTurns returns all Turns in timeline order.
ListTurns(ctx context.Context) ([]*Turn, error)
// InterruptRunningTurns marks every running Turn as interrupted with reason.
InterruptRunningTurns(ctx context.Context, reason TurnReason) error
}
TurnStore is an optional Session capability for durable Turn lifecycle tracking. Implementations must only allow transitions from TurnRunning to a terminal state and must make repeated finalization attempts fail atomically.