chatapp

package
v0.1.0-alpha.54 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: GPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package chatapp coordinates conversation use cases above chat persistence. It owns session admission and turn lifetimes, never HTTP or device dispatch.

Index

Constants

This section is empty.

Variables

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

func (w *Workspace) Activate(id string, discard bool) ([]chat.Session, error)

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

func (w *Workspace) BeginPersonaChange() (func(), error)

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

func (w *Workspace) Create(discard bool) ([]chat.Session, error)

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

func (w *Workspace) Delete(id string) ([]chat.Session, error)

Delete removes an inactive session; persistence enforces active-row protection.

func (*Workspace) Observe

func (w *Workspace) Observe(ctx context.Context, trackMood bool) (Observation, error)

Observe reads status without letting a session switch split the observation.

func (*Workspace) ReconcileShutdown

func (w *Workspace) ReconcileShutdown(keepUnsaved bool) error

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

func (w *Workspace) ResolveActive(ctx context.Context, requested string) (string, error)

ResolveActive checks an optional requested ID against the canonical session.

func (*Workspace) Save

func (w *Workspace) Save(id string) ([]chat.Session, error)

Save retains a session without interrupting an active reply.

func (*Workspace) Sessions

func (w *Workspace) Sessions(ctx context.Context) ([]chat.Session, error)

Sessions returns a stable list with one canonical active session.

func (*Workspace) TurnActive

func (w *Workspace) TurnActive() bool

TurnActive reports admission state without waiting for storage.

Jump to

Keyboard shortcuts

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