Documentation
¶
Overview ¶
Package chatapp coordinates conversation use cases above chat persistence. It owns session admission and turn lifetimes, never HTTP or device dispatch.
Index ¶
- Variables
- type Observation
- type Sessions
- type StopRecord
- type Workspace
- func (w *Workspace) Activate(id string, discard bool) ([]chat.Session, error)
- func (w *Workspace) BeginModeChange() func()
- func (w *Workspace) BeginPersonaChange() (func(), error)
- func (w *Workspace) BeginTurn(parent context.Context, sessionID string) (context.Context, context.CancelFunc, error)
- func (w *Workspace) CancelTurns()
- func (w *Workspace) Create(discard bool) ([]chat.Session, error)
- func (w *Workspace) Delete(id string) ([]chat.Session, error)
- func (w *Workspace) Observe(ctx context.Context, trackMood bool) (Observation, error)
- func (w *Workspace) ReconcileShutdown(keepUnsaved bool) error
- func (w *Workspace) RecordStoppedReply(requestedID, message, reply, clientID string, trackMood bool, ...) (StopRecord, error)
- func (w *Workspace) ResolveActive(ctx context.Context, requested string) (string, error)
- func (w *Workspace) Save(id string) ([]chat.Session, error)
- func (w *Workspace) Sessions(ctx context.Context) ([]chat.Session, error)
- func (w *Workspace) TurnActive() bool
Constants ¶
This section is empty.
Variables ¶
var ( // ErrReplyActive rejects conversation changes during an interactive turn. ErrReplyActive = errors.New("wait for the active reply to finish") // ErrAutopilotActive rejects conversation changes during autonomous work. ErrAutopilotActive = errors.New("stop Autopilot") // ErrTurnInvalidated rejects admission overtaken by application Stop. ErrTurnInvalidated = errors.New("chat request was invalidated by Stop") )
Functions ¶
This section is empty.
Types ¶
type Observation ¶
type Observation struct {
ActiveSessionID string
LatestSeq int64
Revision int64
CurrentMood chat.Mood
}
Observation is one coherent read of the active conversation's status.
type Sessions ¶
type Sessions interface {
ActiveSessionIDContext(context.Context) (string, error)
SessionsContext(context.Context) ([]chat.Session, error)
CreateSession(bool) (chat.Session, error)
ActivateSession(string, bool) (chat.Session, error)
SaveSession(string) (chat.Session, error)
DeleteSession(string) error
ConversationHeadContext(context.Context, string) (int64, int64, error)
ReadPromptContext(context.Context, string) (chat.SessionPromptContext, error)
AppendTo(string, string, string, string, *chat.MessageDiagnostics) (int64, error)
ReconcileShutdown(bool) error
}
Sessions is the persistence port used by conversation lifecycle operations. Message generation, transport payloads, and HTTP responses are outside it.
type StopRecord ¶
type StopRecord struct {
SessionID string
UserSeq int64
ReplySeq int64
Diagnostics chat.MessageDiagnostics
}
StopRecord contains the transcript metadata accepted after a completed Stop.
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace serializes session changes against turn admission. turnsMu never spans persistence or mode calls: Stop can cancel a turn while a session operation is blocked on disk. Cancellation epochs reject pending admissions; turn IDs keep late cleanup from releasing a newer request.
func NewWorkspace ¶
func NewWorkspace(lifetime context.Context, sessions Sessions, autopilotActive func() bool) *Workspace
NewWorkspace borrows persistence and the application lifetime. A nil mode accessor means autonomous work is unavailable. Callers supply non-nil context and persistence; the datastore remains owned by the process composition root.
func (*Workspace) Activate ¶
Activate switches the canonical session after checking conversation admission.
func (*Workspace) BeginModeChange ¶
func (w *Workspace) BeginModeChange() func()
BeginModeChange holds the session boundary while the edge performs a mode transition. The edge may take the persona mutation lock after this lease, never in reverse order. Physical Stop never needs this lease.
func (*Workspace) BeginPersonaChange ¶
BeginPersonaChange admits a stable conversation/persona mutation. The caller performs the persona-domain operation and releases the returned lease.
func (*Workspace) BeginTurn ¶
func (w *Workspace) BeginTurn(parent context.Context, sessionID string) (context.Context, context.CancelFunc, error)
BeginTurn admits one interactive request against the canonical active session.
func (*Workspace) CancelTurns ¶
func (w *Workspace) CancelTurns()
CancelTurns never waits on the session gate, persistence, or mode teardown.
func (*Workspace) Create ¶
Create starts a conversation only when neither chat nor Autopilot owns it. The result is the session list observed in the same mutation boundary.
func (*Workspace) Delete ¶
Delete removes an inactive session; persistence enforces active-row protection.
func (*Workspace) Observe ¶
Observe reads status without letting a session switch split the observation.
func (*Workspace) ReconcileShutdown ¶
ReconcileShutdown applies the saved retention policy after work is quiesced.
func (*Workspace) RecordStoppedReply ¶
func (w *Workspace) RecordStoppedReply(requestedID, message, reply, clientID string, trackMood bool, diagnostics chat.MessageDiagnostics) (StopRecord, error)
RecordStoppedReply is best-effort history after physical Stop has completed or timed out. It cannot dispatch motion or speech, and stale session IDs never redirect the transcript into the new active chat.
func (*Workspace) ResolveActive ¶
ResolveActive checks an optional requested ID against the canonical session.
func (*Workspace) TurnActive ¶
TurnActive reports admission state without waiting for storage.