Repository navigation
Component Frontend App
The frontend app is a React + Vite single-page shell that renders the TV cabinet experience, owns local TV power/theme/volume state, and wires audio, greeting playback, state stores, and SSE runtime send paths together. See also Component-CRT-Presentation, Component-Audio-Chain, Component-WebSocket-Transport, and Component-State-Stores.
-
packages/frontend/src/main.tsxmounts React into#root, wrapsAppinStrictMode, and catches render failures withErrorBoundary. -
packages/frontend/src/App.tsxcomposes the TV scene, power sequence, greeting lifecycle, channel/theme switching, text submission, audio chain, and SSE stream hook. -
packages/frontend/src/config/constants.tsdefines avatar themes, greeting duration, background timing, tuning duration bounds, and tune-in glitch pattern. -
packages/frontend/src/config/buildConfig.tsowns build-time runtime and Cognito configuration. -
packages/frontend/src/services/authService.tsowns the Cognito auth service and runtime ARN. -
packages/frontend/src/hooks/useAgentStream.tsposts chat turns and no-session actions over SSE. -
packages/frontend/src/components/ErrorBoundary.tsxshows an in-character fallback instead of a blank React crash. -
packages/frontend/src/App.csspositions the TV frame, controls, screen, chat bar, overlays, and LED styles.
-
GREETING_DISPLAY_MS,AVATAR_THEMES,DEFAULT_AVATAR_THEME,BACKGROUND_CYCLE_MS,BACKGROUND_FRAME_COUNT,BACKGROUND_ASSET_BASE,TUNING_MIN_MS,TUNING_MAX_MS,SETTLING_DURATION_MS, andTUNE_IN_GLITCH_PATTERNare exported constants. type AvatarTheme = 'retro' | 'pop-art' | 'cartoon'nextTheme(theme: AvatarTheme): AvatarThemegetRandomTalkFrameIntervalMs(): numbergetRandomTalkFrameIndex(): 0 | 1type TvPowerState = 'off' | 'tuning' | 'settling' | 'on'App(): JSX.Elementclass ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState>
main.tsx requires a root element and throws if it is missing. It renders:
<StrictMode>
<ErrorBoundary>
<App />
</ErrorBoundary>
</StrictMode>App creates one AudioChain and one greeting player (createUseGreeting()) through lazy useState initializers, builds the voice player (createUseAudio()) in a mount effect, and disposes the player and the chain on unmount. The visible TV has four power phases:
-
off: screen and chat input disabled. -
tuning:TuningOverlayand looping white noise run while greeting audio preloads. -
settling: avatar/background appear andTUNE_IN_GLITCH_PATTERNcan forceglitch/idleframes. -
on: greeting playback starts, a no-modelruntime.readySSE action starts concurrently, text input can send messages.
Greeting completion is the startup deadline: a successful readiness action leaves the connected idle/listening state; a failure or unresolved probe becomes SIGNAL_LOST after the greeting completes. Power-off aborts the probe, and a late result cannot change state.
The scene inside CrtFrame is ordered as background, avatar, broadcast text, session overlay, settling glitch overlay, and tuning overlay. The right-side panel contains TvKnob, ChannelKnob, and VolumeKnob. The TextInput lives below the TV in .chat-bar, not in the CrtFrame footer.
-
useConnectionStoresuppliessessionIdandsessionState. -
useConversationStoresupplies streamingcurrentResponseText, completedfullText, andcurrentTurnIndex. -
useVoiceStoresuppliesisMouthOpenandisGreetingfor avatar animation. -
useAgentStream({ runtimeArn, getAccessToken, refreshAccessToken })opens an SSE request only whensend()orrunAction()is called. - On
tvPower === 'on',AppcallsrunAction({ action: 'runtime.ready' }, powerOffSignal)once so local greeting audio and runtime bootup overlap. -
handleSend(text)sends{ message, clientTimestamp, voice: 'on' }throughstream.send()only when the trimmed message is non-empty and the session state is not one ofSEND_BLOCKED_STATES(ENDED,BUDGET_CAPPED,RATE_LIMITED,DENIED,ERROR; spec 003 FR-037). See the first Gotcha below for why it is not anACTIVEcheck.
toOverlayState(state, isGreetingDone) hides terminal overlays until greeting finishes, then maps ENDED, BUDGET_CAPPED, RATE_LIMITED, SIGNAL_LOST, and ERROR to SessionStateOverlay.
-
Never gate sending on
ACTIVE. Over SSE a session reachesACTIVEonly when the firstsessionevent arrives, which is a response to a send, so a gate onACTIVEmakes the first message unsendable.App.test.tsxonce hid this by mocking the store asACTIVE; the tests now use the real store fromINITIALIZINGandSIGNAL_LOST. ASIGNAL_LOSTsession can therefore retry by sending (found in the 2026-11-16 branch review). -
Never replace a persistent startup transport with request-only SSE and leave startup readiness implicit. SSE
runAction()exists for memory/actions and chatsend()exists for turns, but neither opens a connection at power-on.Appnow explicitly racesruntime.readyagainst greeting completion and aborts it on power-off; unresolved or failed readiness becomesSIGNAL_LOSTonly after the greeting. -
useRef(createX())re-runscreateX()on every render, because the argument is evaluated each time and only the first result is kept.Apponce did this for the audio chain, voice player and greeting player, orphaning a set of store subscribers per render. Use a lazyuseState(() => createX()). The voice player is built in a mount effect instead, becauseuseAudio().dispose()is permanent (it unsubscribes for good) and<StrictMode>simulates an unmount and remount, which a lazily initialized player would not survive.AudioChain.dispose()is re-initable, so it can live in a state initializer. - The visible volume is local
Appstate (useState(6 / 11)), notvoiceStorestate; TV power cycles preserve the selection. Component-Volume-Knob covers the current implementation. - Channel change stops greeting audio and cycles avatar theme, but it does not reset conversation or connection stores.
- Session terminal states power the TV off for
ENDED,BUDGET_CAPPED,RATE_LIMITED, andERROR, but not forSIGNAL_LOST; the signal-lost overlay is displayed while powered on.
- Concept-Cloud-Only-Inference
- Concept-Budget-Ceiling
- Concept-Personality-Gate
- Concept-IP-And-Legal-Posture
- Concept-Supply-Chain-Discipline
- Concept-Graceful-Degradation
- Concept-Observability
- Concept-Testing-And-TDD
- Concept-Credential-Hygiene
Editing in the browser? Wiki edits are live and bypass wiki:lint. Read
Guide-Wiki-Contributing first.