Skip to content

Component State Stores

Reese Hodge edited this page Nov 16, 2026 · 2 revisions

Component State Stores

The frontend state stores are four Zustand stores with narrow ownership boundaries: connection/session transport state, conversation stream state, visitor identity/history/rate counters, and voice/UI audio state. They are consumed by Component-Frontend-App, Component-WebSocket-Transport, Component-Audio-Chain, and Component-Speech-Input.

Files

  • packages/frontend/src/stores/connectionStore.ts
  • packages/frontend/src/stores/conversationStore.ts
  • packages/frontend/src/stores/visitorStore.ts
  • packages/frontend/src/stores/voiceStore.ts
  • packages/frontend/src/types/domain.ts

Domain types

domain.ts exports:

  • type SessionState = 'INITIALIZING' | 'GREETING' | 'ACTIVE' | 'ENDED' | 'BUDGET_CAPPED' | 'RATE_LIMITED' | 'SIGNAL_LOST' | 'ERROR'
  • type GreetingArchetype = 'TV_PRESENTER_INTRO' | 'MID_MONOLOGUE' | 'MOCK_ANNOYANCE' | 'SPONSOR_BREAK' | 'TIME_OF_DAY_RIFF' | 'SELF_CONGRATULATION' | 'FAKE_NEWS_FLASH' | 'GLITCH_COLD_OPEN'
  • interface Greeting { id; archetype; text; audioPath; audioDurationMs; videoPath; weight; tags; }
  • interface RateLimitState { hourlyCount; hourlyWindowStart; dailyCount; dailyWindowStart; }
  • interface Visitor { actorId; displayAlias; greetingHistory; rateLimitCounters; }

Store ownership

connectionStore

Owns transport/session status:

  • sessionState: SessionState, initially INITIALIZING
  • sessionId: string | null
  • agentCoreSessionId: string | null
  • isWebSocketReady: boolean

Actions:

  • setSessionState(state: SessionState): void
  • setConnected(sessionId: string, agentCoreSessionId: string): void
  • reset(): void

conversationStore

Owns the current streamed/completed assistant response and session counters:

  • turnCount: number
  • tokenCount: number
  • currentResponseText: string
  • isStreaming: boolean
  • currentTurnIndex: number

Actions:

  • appendToken(token: string): void
  • setFullText(text: string): void
  • advanceTurn(): void
  • updateCounters(counters: { sessionTokenTotal: number; sessionTurnTotal: number }): void
  • reset(): void

visitorStore

Owns local visitor identity and rate-limit history:

  • actorId: string
  • displayAlias: string | null
  • greetingHistory: string[]
  • rateLimitCounters: RateLimitState

Actions:

  • setDisplayAlias(alias: string): void
  • pushGreeting(greetingId: string): void
  • updateRateLimits(limits: RateLimitState): void
  • clearAll(): void
  • reset(): void

actorId is stored in localStorage under a max-height- prefixed key and created with crypto.randomUUID() if absent. pushGreeting() keeps only the latest 20 IDs.

voiceStore

Owns voice/speech animation flags, not volume:

  • isSpeaking: boolean
  • isMouthOpen: boolean
  • isMicActive: boolean
  • isGreeting: boolean

Actions:

  • setSpeaking(value: boolean): void
  • setMouthOpen(value: boolean): void
  • setMicActive(value: boolean): void
  • setGreeting(value: boolean): void
  • reset(): void

Gotchas

  • visitorStore reads localStorage during initial state creation, so it assumes a browser environment.
  • voiceStore does not own volume despite its audio-adjacent name; current volume is local state in App.tsx.
  • connectionStore.sessionState starts at INITIALIZING, and over SSE ACTIVE arrives only with the first session event, after a send. App therefore blocks sending only in terminal and refusal states (SEND_BLOCKED_STATES), not until ACTIVE. This page's earlier claim that App sends only when state is ACTIVE or GREETING described a bug, fixed 2026-11-16; see Component-Frontend-App.
  • Audio clips are numbered per turn: the server restarts each turn's segment seq at 0. voiceStore stamps every queued clip with audioTurn, which beginAudioTurn() advances when useAgentStream starts a non-capture exchange, and useAudio resets its duplicate-drop seq when the turn changes. A player that remembers the highest seq it has ever played drops every later turn's audio, so the voice goes silent after the first reply (fixed 2026-11-16).

Clone this wiki locally