@elizaos/app-core 2.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (399) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +90 -0
  3. package/src/App.tsx +472 -0
  4. package/src/actions/character.test.ts +139 -0
  5. package/src/actions/character.ts +152 -0
  6. package/src/actions/chat-helpers.ts +100 -0
  7. package/src/actions/cloud.ts +59 -0
  8. package/src/actions/index.ts +12 -0
  9. package/src/actions/lifecycle.ts +175 -0
  10. package/src/actions/onboarding.ts +46 -0
  11. package/src/actions/triggers.ts +190 -0
  12. package/src/ambient.d.ts +16 -0
  13. package/src/api/client.ts +5516 -0
  14. package/src/api/index.ts +1 -0
  15. package/src/autonomy/index.ts +477 -0
  16. package/src/bridge/capacitor-bridge.ts +295 -0
  17. package/src/bridge/electrobun-rpc.ts +58 -0
  18. package/src/bridge/electrobun-runtime.ts +28 -0
  19. package/src/bridge/index.ts +5 -0
  20. package/src/bridge/native-plugins.ts +134 -0
  21. package/src/bridge/plugin-bridge.ts +352 -0
  22. package/src/bridge/storage-bridge.ts +162 -0
  23. package/src/chat/index.ts +250 -0
  24. package/src/coding/index.ts +43 -0
  25. package/src/components/AdvancedPageView.tsx +362 -0
  26. package/src/components/AgentActivityBox.tsx +49 -0
  27. package/src/components/ApiKeyConfig.tsx +224 -0
  28. package/src/components/AppsPageView.tsx +52 -0
  29. package/src/components/AppsView.tsx +293 -0
  30. package/src/components/AvatarLoader.tsx +86 -0
  31. package/src/components/AvatarSelector.tsx +223 -0
  32. package/src/components/BscTradePanel.tsx +549 -0
  33. package/src/components/BugReportModal.tsx +499 -0
  34. package/src/components/CharacterView.tsx +1645 -0
  35. package/src/components/ChatAvatar.test.ts +96 -0
  36. package/src/components/ChatAvatar.tsx +147 -0
  37. package/src/components/ChatComposer.tsx +330 -0
  38. package/src/components/ChatMessage.tsx +448 -0
  39. package/src/components/ChatModalView.test.tsx +118 -0
  40. package/src/components/ChatModalView.tsx +125 -0
  41. package/src/components/ChatView.tsx +992 -0
  42. package/src/components/CloudSourceControls.tsx +80 -0
  43. package/src/components/CodingAgentSettingsSection.tsx +536 -0
  44. package/src/components/CommandPalette.tsx +284 -0
  45. package/src/components/CompanionSceneHost.tsx +497 -0
  46. package/src/components/CompanionShell.tsx +31 -0
  47. package/src/components/CompanionView.tsx +109 -0
  48. package/src/components/ConfigPageView.tsx +758 -0
  49. package/src/components/ConfigSaveFooter.tsx +41 -0
  50. package/src/components/ConfirmModal.tsx +379 -0
  51. package/src/components/ConnectionFailedBanner.tsx +91 -0
  52. package/src/components/ConnectorsPageView.tsx +13 -0
  53. package/src/components/ConversationsSidebar.tsx +279 -0
  54. package/src/components/CustomActionEditor.tsx +1125 -0
  55. package/src/components/CustomActionsPanel.tsx +288 -0
  56. package/src/components/CustomActionsView.tsx +322 -0
  57. package/src/components/DatabasePageView.tsx +55 -0
  58. package/src/components/DatabaseView.tsx +814 -0
  59. package/src/components/ElizaCloudDashboard.tsx +1696 -0
  60. package/src/components/EmotePicker.tsx +529 -0
  61. package/src/components/ErrorBoundary.tsx +76 -0
  62. package/src/components/FineTuningView.tsx +1077 -0
  63. package/src/components/GameView.tsx +552 -0
  64. package/src/components/GameViewOverlay.tsx +133 -0
  65. package/src/components/GlobalEmoteOverlay.tsx +155 -0
  66. package/src/components/Header.test.tsx +413 -0
  67. package/src/components/Header.tsx +403 -0
  68. package/src/components/HeartbeatsView.tsx +1003 -0
  69. package/src/components/InventoryView.tsx +385 -0
  70. package/src/components/KnowledgeView.tsx +1128 -0
  71. package/src/components/LanguageDropdown.tsx +188 -0
  72. package/src/components/LifoMonitorPanel.tsx +196 -0
  73. package/src/components/LifoSandboxView.tsx +499 -0
  74. package/src/components/LoadingScreen.tsx +77 -0
  75. package/src/components/LogsPageView.tsx +17 -0
  76. package/src/components/LogsView.tsx +239 -0
  77. package/src/components/MediaGalleryView.tsx +433 -0
  78. package/src/components/MediaSettingsSection.tsx +893 -0
  79. package/src/components/MessageContent.tsx +815 -0
  80. package/src/components/OnboardingWizard.test.tsx +107 -0
  81. package/src/components/OnboardingWizard.tsx +189 -0
  82. package/src/components/PairingView.tsx +110 -0
  83. package/src/components/PermissionsSection.tsx +1186 -0
  84. package/src/components/PluginsPageView.tsx +9 -0
  85. package/src/components/PluginsView.tsx +3157 -0
  86. package/src/components/ProviderSwitcher.tsx +908 -0
  87. package/src/components/RestartBanner.tsx +76 -0
  88. package/src/components/RuntimeView.tsx +460 -0
  89. package/src/components/SaveCommandModal.tsx +211 -0
  90. package/src/components/SecretsView.tsx +569 -0
  91. package/src/components/SettingsView.tsx +825 -0
  92. package/src/components/ShellOverlays.tsx +41 -0
  93. package/src/components/ShortcutsOverlay.tsx +155 -0
  94. package/src/components/SkillsView.tsx +1435 -0
  95. package/src/components/StartupFailureView.tsx +63 -0
  96. package/src/components/StreamView.tsx +483 -0
  97. package/src/components/StripeEmbeddedCheckout.tsx +155 -0
  98. package/src/components/SubscriptionStatus.tsx +640 -0
  99. package/src/components/SystemWarningBanner.tsx +71 -0
  100. package/src/components/ThemeToggle.tsx +100 -0
  101. package/src/components/TrajectoriesView.tsx +526 -0
  102. package/src/components/TrajectoryDetailView.tsx +426 -0
  103. package/src/components/TriggersView.tsx +1 -0
  104. package/src/components/VectorBrowserView.tsx +1633 -0
  105. package/src/components/VoiceConfigView.tsx +675 -0
  106. package/src/components/VrmStage.test.ts +219 -0
  107. package/src/components/VrmStage.tsx +432 -0
  108. package/src/components/WhatsAppQrOverlay.tsx +230 -0
  109. package/src/components/__tests__/chainConfig.test.ts +220 -0
  110. package/src/components/apps/AppDetailPane.tsx +242 -0
  111. package/src/components/apps/AppsCatalogGrid.tsx +137 -0
  112. package/src/components/apps/extensions/HyperscapeAppDetailPanel.tsx +577 -0
  113. package/src/components/apps/extensions/registry.ts +16 -0
  114. package/src/components/apps/extensions/types.ts +9 -0
  115. package/src/components/apps/helpers.ts +44 -0
  116. package/src/components/avatar/VrmAnimationLoader.test.ts +164 -0
  117. package/src/components/avatar/VrmAnimationLoader.ts +151 -0
  118. package/src/components/avatar/VrmBlinkController.ts +118 -0
  119. package/src/components/avatar/VrmCameraManager.ts +407 -0
  120. package/src/components/avatar/VrmEngine.ts +2678 -0
  121. package/src/components/avatar/VrmFootShadow.ts +96 -0
  122. package/src/components/avatar/VrmViewer.tsx +421 -0
  123. package/src/components/avatar/__tests__/VrmCameraManager.test.ts +168 -0
  124. package/src/components/avatar/__tests__/VrmEngine.test.ts +1574 -0
  125. package/src/components/avatar/mixamoVRMRigMap.ts +62 -0
  126. package/src/components/avatar/retargetMixamoFbxToVrm.ts +144 -0
  127. package/src/components/avatar/retargetMixamoGltfToVrm.ts +119 -0
  128. package/src/components/chainConfig.ts +380 -0
  129. package/src/components/companion/CompanionHeader.tsx +47 -0
  130. package/src/components/companion/CompanionSceneHost.tsx +1 -0
  131. package/src/components/companion/VrmStage.tsx +2 -0
  132. package/src/components/companion/__tests__/walletUtils.test.ts +742 -0
  133. package/src/components/companion/walletUtils.ts +290 -0
  134. package/src/components/companion-shell-styles.test.ts +142 -0
  135. package/src/components/companion-shell-styles.ts +270 -0
  136. package/src/components/confirm-delete-control.tsx +69 -0
  137. package/src/components/conversations/ConversationListItem.tsx +185 -0
  138. package/src/components/conversations/conversation-utils.ts +151 -0
  139. package/src/components/format.ts +131 -0
  140. package/src/components/index.ts +94 -0
  141. package/src/components/inventory/CopyableAddress.tsx +41 -0
  142. package/src/components/inventory/InventoryToolbar.tsx +142 -0
  143. package/src/components/inventory/NftGrid.tsx +99 -0
  144. package/src/components/inventory/TokenLogo.tsx +71 -0
  145. package/src/components/inventory/TokensTable.tsx +216 -0
  146. package/src/components/inventory/constants.ts +170 -0
  147. package/src/components/inventory/index.ts +29 -0
  148. package/src/components/inventory/media-url.test.ts +38 -0
  149. package/src/components/inventory/media-url.ts +36 -0
  150. package/src/components/inventory/useInventoryData.ts +460 -0
  151. package/src/components/knowledge-upload-image.ts +215 -0
  152. package/src/components/labels.ts +46 -0
  153. package/src/components/onboarding/ActivateStep.tsx +30 -0
  154. package/src/components/onboarding/ConnectionStep.tsx +1530 -0
  155. package/src/components/onboarding/IdentityStep.tsx +147 -0
  156. package/src/components/onboarding/OnboardingPanel.tsx +39 -0
  157. package/src/components/onboarding/OnboardingStepNav.tsx +31 -0
  158. package/src/components/onboarding/PermissionsStep.tsx +20 -0
  159. package/src/components/onboarding/RpcStep.tsx +402 -0
  160. package/src/components/onboarding/WakeUpStep.tsx +184 -0
  161. package/src/components/permissions/PermissionIcon.tsx +25 -0
  162. package/src/components/permissions/StreamingPermissions.tsx +413 -0
  163. package/src/components/plugins/showcase-data.ts +481 -0
  164. package/src/components/shared/ShellHeaderControls.tsx +193 -0
  165. package/src/components/shared-companion-scene-context.ts +15 -0
  166. package/src/components/skeletons.tsx +88 -0
  167. package/src/components/stream/ActivityFeed.tsx +113 -0
  168. package/src/components/stream/AvatarPip.tsx +10 -0
  169. package/src/components/stream/ChatContent.tsx +126 -0
  170. package/src/components/stream/ChatTicker.tsx +55 -0
  171. package/src/components/stream/IdleContent.tsx +73 -0
  172. package/src/components/stream/StatusBar.tsx +469 -0
  173. package/src/components/stream/StreamSettings.tsx +506 -0
  174. package/src/components/stream/StreamTerminal.tsx +94 -0
  175. package/src/components/stream/StreamVoiceConfig.tsx +160 -0
  176. package/src/components/stream/helpers.ts +134 -0
  177. package/src/components/stream/overlays/OverlayLayer.tsx +75 -0
  178. package/src/components/stream/overlays/built-in/ActionTickerWidget.tsx +64 -0
  179. package/src/components/stream/overlays/built-in/AlertPopupWidget.tsx +87 -0
  180. package/src/components/stream/overlays/built-in/BrandingWidget.tsx +51 -0
  181. package/src/components/stream/overlays/built-in/CustomHtmlWidget.tsx +105 -0
  182. package/src/components/stream/overlays/built-in/PeonGlassWidget.tsx +265 -0
  183. package/src/components/stream/overlays/built-in/PeonHudWidget.tsx +247 -0
  184. package/src/components/stream/overlays/built-in/PeonSakuraWidget.tsx +278 -0
  185. package/src/components/stream/overlays/built-in/ThoughtBubbleWidget.tsx +77 -0
  186. package/src/components/stream/overlays/built-in/ViewerCountWidget.tsx +46 -0
  187. package/src/components/stream/overlays/built-in/index.ts +13 -0
  188. package/src/components/stream/overlays/registry.ts +22 -0
  189. package/src/components/stream/overlays/types.ts +90 -0
  190. package/src/components/stream/overlays/useOverlayLayout.ts +218 -0
  191. package/src/components/trajectory-format.ts +50 -0
  192. package/src/components/ui-badges.tsx +109 -0
  193. package/src/components/ui-switch.tsx +57 -0
  194. package/src/components/vector-browser-three.ts +27 -0
  195. package/src/config/config-catalog.ts +1092 -0
  196. package/src/config/config-field.tsx +1901 -0
  197. package/src/config/config-renderer.tsx +730 -0
  198. package/src/config/index.ts +11 -0
  199. package/src/config/ui-renderer.tsx +1751 -0
  200. package/src/config/ui-spec.ts +256 -0
  201. package/src/events/index.ts +89 -0
  202. package/src/hooks/index.ts +13 -0
  203. package/src/hooks/useBugReport.tsx +43 -0
  204. package/src/hooks/useCanvasWindow.ts +372 -0
  205. package/src/hooks/useChatAvatarVoice.ts +111 -0
  206. package/src/hooks/useContextMenu.ts +127 -0
  207. package/src/hooks/useKeyboardShortcuts.ts +86 -0
  208. package/src/hooks/useLifoSync.ts +143 -0
  209. package/src/hooks/useMemoryMonitor.ts +334 -0
  210. package/src/hooks/useRenderGuard.ts +43 -0
  211. package/src/hooks/useRetakeCapture.ts +67 -0
  212. package/src/hooks/useStreamPopoutNavigation.ts +27 -0
  213. package/src/hooks/useTimeout.ts +37 -0
  214. package/src/hooks/useVoiceChat.ts +1441 -0
  215. package/src/hooks/useWhatsAppPairing.ts +123 -0
  216. package/src/i18n/index.ts +76 -0
  217. package/src/i18n/locales/en.json +1194 -0
  218. package/src/i18n/locales/es.json +1194 -0
  219. package/src/i18n/locales/ko.json +1194 -0
  220. package/src/i18n/locales/pt.json +1194 -0
  221. package/src/i18n/locales/zh-CN.json +1194 -0
  222. package/src/i18n/messages.ts +21 -0
  223. package/src/index.ts +6 -0
  224. package/src/navigation/index.ts +282 -0
  225. package/src/navigation.test.ts +189 -0
  226. package/src/onboarding-config.test.ts +104 -0
  227. package/src/onboarding-config.ts +114 -0
  228. package/src/platform/browser-launch.test.ts +94 -0
  229. package/src/platform/browser-launch.ts +149 -0
  230. package/src/platform/index.ts +58 -0
  231. package/src/platform/init.ts +236 -0
  232. package/src/platform/lifo.ts +215 -0
  233. package/src/providers/index.ts +99 -0
  234. package/src/state/AppContext.tsx +5846 -0
  235. package/src/state/index.ts +6 -0
  236. package/src/state/internal.ts +86 -0
  237. package/src/state/onboarding-resume.test.ts +135 -0
  238. package/src/state/onboarding-resume.ts +263 -0
  239. package/src/state/parsers.test.ts +124 -0
  240. package/src/state/parsers.ts +308 -0
  241. package/src/state/persistence.ts +321 -0
  242. package/src/state/shell-routing.ts +32 -0
  243. package/src/state/types.ts +701 -0
  244. package/src/state/ui-preferences.ts +3 -0
  245. package/src/state/useApp.ts +23 -0
  246. package/src/state/vrm.ts +76 -0
  247. package/src/stories/AppMockProvider.tsx +32 -0
  248. package/src/stories/ChatEmptyState.stories.tsx +27 -0
  249. package/src/stories/ChatMessage.stories.tsx +115 -0
  250. package/src/stories/CompanionHeader.stories.tsx +74 -0
  251. package/src/stories/CompanionView.stories.tsx +33 -0
  252. package/src/stories/ConversationListItem.stories.tsx +102 -0
  253. package/src/stories/TypingIndicator.stories.tsx +28 -0
  254. package/src/styles/anime.css +6324 -0
  255. package/src/styles/base.css +196 -0
  256. package/src/styles/onboarding-game.css +738 -0
  257. package/src/styles/styles.css +2087 -0
  258. package/src/styles/xterm.css +241 -0
  259. package/src/types/index.ts +715 -0
  260. package/src/types/react-test-renderer.d.ts +45 -0
  261. package/src/utils/asset-url.ts +110 -0
  262. package/src/utils/assistant-text.ts +172 -0
  263. package/src/utils/clipboard.ts +41 -0
  264. package/src/utils/desktop-dialogs.ts +80 -0
  265. package/src/utils/index.ts +6 -0
  266. package/src/utils/number-parsing.ts +125 -0
  267. package/src/utils/openExternalUrl.ts +20 -0
  268. package/src/utils/spoken-text.ts +65 -0
  269. package/src/utils/streaming-text.ts +120 -0
  270. package/src/voice/index.ts +1 -0
  271. package/src/voice/types.ts +197 -0
  272. package/src/wallet-rpc.ts +176 -0
  273. package/test/app/AppContext.pty-sessions.test.tsx +143 -0
  274. package/test/app/MessageContent.test.tsx +326 -0
  275. package/test/app/PermissionsOnboarding.test.tsx +356 -0
  276. package/test/app/PermissionsSection.test.tsx +573 -0
  277. package/test/app/advanced-trajectory-fine-tuning.e2e.test.ts +393 -0
  278. package/test/app/agent-activity-box.test.tsx +132 -0
  279. package/test/app/agent-transfer-lock.test.ts +274 -0
  280. package/test/app/api-client-electron-fallback.test.ts +139 -0
  281. package/test/app/api-client-timeout.test.ts +75 -0
  282. package/test/app/api-client-ws.test.ts +98 -0
  283. package/test/app/api-client.ws-max-reconnect.test.ts +139 -0
  284. package/test/app/api-client.ws-reconnect.test.ts +157 -0
  285. package/test/app/app-context-autonomy-events.test.ts +478 -0
  286. package/test/app/apps-page-view.test.ts +114 -0
  287. package/test/app/apps-view.test.ts +769 -0
  288. package/test/app/autonomous-workflows.e2e.test.ts +765 -0
  289. package/test/app/autonomy-events.test.ts +150 -0
  290. package/test/app/avatar-selector.test.tsx +52 -0
  291. package/test/app/bsc-trade-panel.test.tsx +134 -0
  292. package/test/app/bug-report-modal.test.tsx +353 -0
  293. package/test/app/character-customization.e2e.test.ts +1199 -0
  294. package/test/app/chat-advanced-features.e2e.test.ts +706 -0
  295. package/test/app/chat-composer.test.tsx +181 -0
  296. package/test/app/chat-language-header.test.ts +64 -0
  297. package/test/app/chat-message.test.tsx +222 -0
  298. package/test/app/chat-modal-view.test.tsx +191 -0
  299. package/test/app/chat-routine-filter.test.ts +96 -0
  300. package/test/app/chat-send-lock.test.ts +1465 -0
  301. package/test/app/chat-stream-api-client.test.tsx +390 -0
  302. package/test/app/chat-view-game-modal.test.tsx +661 -0
  303. package/test/app/chat-view.test.tsx +877 -0
  304. package/test/app/cloud-api.e2e.test.ts +258 -0
  305. package/test/app/cloud-login-flow.e2e.test.ts +494 -0
  306. package/test/app/cloud-login-lock.test.ts +411 -0
  307. package/test/app/command-palette.test.tsx +184 -0
  308. package/test/app/command-registry.test.ts +75 -0
  309. package/test/app/companion-greeting-wave.test.tsx +425 -0
  310. package/test/app/companion-stale-conversation.test.tsx +447 -0
  311. package/test/app/companion-view.test.tsx +686 -0
  312. package/test/app/confirm-delete-control.test.ts +79 -0
  313. package/test/app/confirm-modal.test.tsx +219 -0
  314. package/test/app/connectors-ui.e2e.test.ts +508 -0
  315. package/test/app/conversations-sidebar-game-modal.test.tsx +260 -0
  316. package/test/app/conversations-sidebar.test.tsx +160 -0
  317. package/test/app/custom-actions-smoke.test.ts +387 -0
  318. package/test/app/custom-avatar-api-client.test.ts +207 -0
  319. package/test/app/desktop-utils.test.ts +145 -0
  320. package/test/app/electrobun-rpc-bridge.test.ts +83 -0
  321. package/test/app/events.test.ts +88 -0
  322. package/test/app/export-import-flows.e2e.test.ts +700 -0
  323. package/test/app/fine-tuning-view.test.ts +471 -0
  324. package/test/app/game-view-auth-session.test.tsx +186 -0
  325. package/test/app/game-view.test.ts +444 -0
  326. package/test/app/global-emote-overlay.test.tsx +106 -0
  327. package/test/app/header-status.test.tsx +149 -0
  328. package/test/app/i18n.test.ts +152 -0
  329. package/test/app/inventory-bsc-view.test.ts +940 -0
  330. package/test/app/knowledge-ui.e2e.test.ts +762 -0
  331. package/test/app/knowledge-upload-helpers.test.ts +124 -0
  332. package/test/app/lifecycle-lock.test.ts +267 -0
  333. package/test/app/lifo-popout-utils.test.ts +208 -0
  334. package/test/app/lifo-safe-endpoint.test.ts +34 -0
  335. package/test/app/loading-screen.test.tsx +45 -0
  336. package/test/app/memory-monitor.test.ts +332 -0
  337. package/test/app/navigation.test.tsx +22 -0
  338. package/test/app/onboarding-finish-lock.test.ts +663 -0
  339. package/test/app/onboarding-language.test.tsx +160 -0
  340. package/test/app/onboarding-steps.test.tsx +375 -0
  341. package/test/app/open-external-url.test.ts +65 -0
  342. package/test/app/pages-navigation-smoke.e2e.test.ts +633 -0
  343. package/test/app/pairing-lock.test.ts +260 -0
  344. package/test/app/pairing-view.test.tsx +74 -0
  345. package/test/app/permissions-section.test.ts +432 -0
  346. package/test/app/plugin-bridge.test.ts +109 -0
  347. package/test/app/plugins-ui.e2e.test.ts +605 -0
  348. package/test/app/plugins-view-game-modal.test.tsx +650 -0
  349. package/test/app/plugins-view-toggle-restart.test.ts +129 -0
  350. package/test/app/provider-dropdown-default.test.tsx +302 -0
  351. package/test/app/restart-banner.test.tsx +197 -0
  352. package/test/app/retake-capture.test.ts +84 -0
  353. package/test/app/sandbox-api-client.test.ts +108 -0
  354. package/test/app/save-command-modal.test.tsx +109 -0
  355. package/test/app/secrets-view.test.tsx +92 -0
  356. package/test/app/settings-control-styles.test.tsx +142 -0
  357. package/test/app/settings-reset.e2e.test.ts +726 -0
  358. package/test/app/settings-sections.e2e.test.ts +614 -0
  359. package/test/app/shared-format.test.ts +44 -0
  360. package/test/app/shared-switch.test.ts +69 -0
  361. package/test/app/shell-mode-switching.e2e.test.ts +829 -0
  362. package/test/app/shell-mode-tab-memory.test.tsx +58 -0
  363. package/test/app/shell-overlays.test.tsx +50 -0
  364. package/test/app/shortcuts-overlay.test.tsx +111 -0
  365. package/test/app/sse-interruption.test.ts +122 -0
  366. package/test/app/startup-asset-missing.e2e.test.ts +126 -0
  367. package/test/app/startup-backend-missing.e2e.test.ts +118 -0
  368. package/test/app/startup-chat.e2e.test.ts +305 -0
  369. package/test/app/startup-conversation-restore.test.tsx +344 -0
  370. package/test/app/startup-failure-view.test.tsx +103 -0
  371. package/test/app/startup-onboarding.e2e.test.ts +618 -0
  372. package/test/app/startup-timeout.test.tsx +80 -0
  373. package/test/app/startup-token-401.e2e.test.ts +103 -0
  374. package/test/app/stream-helpers.test.ts +46 -0
  375. package/test/app/stream-popout-navigation.test.tsx +41 -0
  376. package/test/app/stream-status-bar.test.tsx +89 -0
  377. package/test/app/theme-toggle.test.tsx +33 -0
  378. package/test/app/training-api-client.test.ts +128 -0
  379. package/test/app/trajectories-view.test.tsx +220 -0
  380. package/test/app/triggers-api-client.test.ts +77 -0
  381. package/test/app/triggers-navigation.test.ts +113 -0
  382. package/test/app/triggers-view.e2e.test.ts +674 -0
  383. package/test/app/update-channel-lock.test.ts +259 -0
  384. package/test/app/vector-browser.async-cleanup.test.tsx +367 -0
  385. package/test/app/vector-browser.e2e.test.ts +653 -0
  386. package/test/app/vrm-stage.test.tsx +351 -0
  387. package/test/app/vrm-viewer.test.tsx +298 -0
  388. package/test/app/wallet-api-save-lock.test.ts +298 -0
  389. package/test/app/wallet-hooks.test.ts +405 -0
  390. package/test/app/wallet-ui-flows.e2e.test.ts +556 -0
  391. package/test/avatar/asset-url.test.ts +90 -0
  392. package/test/avatar/avatar-selector.test.ts +173 -0
  393. package/test/avatar/mixamo-vrm-rig-map.test.ts +111 -0
  394. package/test/avatar/voice-chat-streaming-text.test.ts +96 -0
  395. package/test/avatar/voice-chat.test.ts +391 -0
  396. package/test/ui/command-palette-commands.test.ts +57 -0
  397. package/test/ui/ui-renderer.test.ts +39 -0
  398. package/tsconfig.build.json +19 -0
  399. package/tsconfig.json +20 -0
@@ -0,0 +1,992 @@
1
+ /**
2
+ * Chat view component.
3
+ *
4
+ * Layout: flex column filling parent. Header row (title + clear + toggles).
5
+ * Scrollable messages area. Share/file notices below messages.
6
+ * Input row at bottom with mic + textarea + send button.
7
+ */
8
+
9
+ import {
10
+ type ConversationChannelType,
11
+ type ConversationMessage,
12
+ client,
13
+ type ImageAttachment,
14
+ type VoiceConfig,
15
+ } from "@elizaos/app-core/api";
16
+ import { isRoutineCodingAgentMessage } from "@elizaos/app-core/chat";
17
+ import { VOICE_CONFIG_UPDATED_EVENT } from "@elizaos/app-core/events";
18
+ import {
19
+ useChatAvatarVoiceBridge,
20
+ useTimeout,
21
+ useVoiceChat,
22
+ type VoiceCaptureMode,
23
+ type VoicePlaybackStartEvent,
24
+ } from "@elizaos/app-core/hooks";
25
+ import { getVrmPreviewUrl, useApp } from "@elizaos/app-core/state";
26
+ import {
27
+ type ChangeEvent,
28
+ type DragEvent,
29
+ type KeyboardEvent,
30
+ useCallback,
31
+ useEffect,
32
+ useMemo,
33
+ useRef,
34
+ useState,
35
+ } from "react";
36
+ import { AgentActivityBox } from "./AgentActivityBox";
37
+ import { ChatComposer } from "./ChatComposer";
38
+ import { ChatEmptyState, ChatMessage, TypingIndicator } from "./ChatMessage";
39
+ import { MessageContent } from "./MessageContent";
40
+
41
+ function nowMs(): number {
42
+ return typeof performance !== "undefined" ? performance.now() : Date.now();
43
+ }
44
+
45
+ const CHAT_INPUT_MIN_HEIGHT_PX = 46;
46
+ const CHAT_INPUT_MAX_HEIGHT_PX = 200;
47
+ const COMPANION_VISIBLE_MESSAGE_LIMIT = 2;
48
+ const COMPANION_HISTORY_HOLD_MS = 30_000;
49
+ const COMPANION_HISTORY_FADE_MS = 5_000;
50
+ const COMPANION_MESSAGE_LAYER_TOP = "calc(-100% + 1.5rem)";
51
+ const COMPANION_MESSAGE_LAYER_BOTTOM = "4rem";
52
+ const COMPANION_MESSAGE_LAYER_MASK =
53
+ "linear-gradient(to bottom, transparent 0%, rgba(0,0,0,0.28) 6%, rgba(0,0,0,0.82) 12%, black 17%, black 100%)";
54
+
55
+ type ChatViewVariant = "default" | "game-modal";
56
+
57
+ interface ChatViewProps {
58
+ variant?: ChatViewVariant;
59
+ }
60
+
61
+ interface CompanionCarryoverState {
62
+ expiresAtMs: number;
63
+ fadeStartsAtMs: number;
64
+ messages: ConversationMessage[];
65
+ }
66
+
67
+ function findLatestAssistantMessage(messages: ConversationMessage[]) {
68
+ return [...messages]
69
+ .reverse()
70
+ .find((message) => message.role === "assistant" && message.text.trim());
71
+ }
72
+
73
+ function useChatVoiceController(options: {
74
+ agentVoiceMuted: boolean;
75
+ chatFirstTokenReceived: boolean;
76
+ chatInput: string;
77
+ chatSending: boolean;
78
+ conversationMessages: ConversationMessage[];
79
+ elizaCloudConnected: boolean;
80
+ handleChatEdit: (messageId: string, text: string) => Promise<boolean>;
81
+ handleChatSend: (channelType?: ConversationChannelType) => Promise<void>;
82
+ isComposerLocked: boolean;
83
+ isGameModal: boolean;
84
+ setState: ReturnType<typeof useApp>["setState"];
85
+ uiLanguage: string;
86
+ }) {
87
+ const { setTimeout } = useTimeout();
88
+ const {
89
+ agentVoiceMuted,
90
+ chatFirstTokenReceived,
91
+ chatInput,
92
+ chatSending,
93
+ conversationMessages,
94
+ elizaCloudConnected,
95
+ handleChatEdit,
96
+ handleChatSend,
97
+ isComposerLocked,
98
+ isGameModal,
99
+ setState,
100
+ uiLanguage,
101
+ } = options;
102
+ const [voiceConfig, setVoiceConfig] = useState<VoiceConfig | null>(null);
103
+ const [voiceLatency, setVoiceLatency] = useState<{
104
+ firstSegmentCached: boolean | null;
105
+ speechEndToFirstTokenMs: number | null;
106
+ speechEndToVoiceStartMs: number | null;
107
+ } | null>(null);
108
+ const pendingVoiceTurnRef = useRef<{
109
+ expiresAtMs: number;
110
+ firstSegmentCached?: boolean;
111
+ firstTokenAtMs?: number;
112
+ speechEndedAtMs: number;
113
+ voiceStartedAtMs?: number;
114
+ } | null>(null);
115
+ const suppressedAssistantSpeechIdRef = useRef<string | null>(null);
116
+ const voiceDraftBaseInputRef = useRef("");
117
+
118
+ const loadVoiceConfig = useCallback(async () => {
119
+ try {
120
+ const cfg = await client.getConfig();
121
+ const messages = cfg.messages as
122
+ | Record<string, Record<string, string>>
123
+ | undefined;
124
+ const tts = messages?.tts as VoiceConfig | undefined;
125
+ setVoiceConfig(tts ?? null);
126
+ } catch {
127
+ /* ignore — will use browser TTS fallback */
128
+ }
129
+ }, []);
130
+
131
+ useEffect(() => {
132
+ void loadVoiceConfig();
133
+ }, [loadVoiceConfig]);
134
+
135
+ useEffect(() => {
136
+ if (typeof window === "undefined") {
137
+ return;
138
+ }
139
+
140
+ const handler = (event: Event) => {
141
+ const detail = (event as CustomEvent<VoiceConfig | undefined>).detail;
142
+ if (detail && typeof detail === "object") {
143
+ setVoiceConfig(detail);
144
+ return;
145
+ }
146
+ void loadVoiceConfig();
147
+ };
148
+
149
+ window.addEventListener(VOICE_CONFIG_UPDATED_EVENT, handler);
150
+ return () =>
151
+ window.removeEventListener(VOICE_CONFIG_UPDATED_EVENT, handler);
152
+ }, [loadVoiceConfig]);
153
+
154
+ const composeVoiceDraft = useCallback((transcript: string) => {
155
+ const base = voiceDraftBaseInputRef.current.trim();
156
+ const spoken = transcript.trim();
157
+ if (base && spoken) {
158
+ return `${base} ${spoken}`;
159
+ }
160
+ return base || spoken;
161
+ }, []);
162
+
163
+ const handleVoiceTranscript = useCallback(
164
+ (text: string) => {
165
+ if (isComposerLocked) return;
166
+ const composedText = composeVoiceDraft(text);
167
+ if (!composedText) return;
168
+ const speechEndedAtMs = nowMs();
169
+ pendingVoiceTurnRef.current = {
170
+ expiresAtMs: speechEndedAtMs + 15000,
171
+ speechEndedAtMs,
172
+ };
173
+ setVoiceLatency(null);
174
+ setState("chatInput", composedText);
175
+ setTimeout(() => void handleChatSend("VOICE_DM"), 50);
176
+ },
177
+ [composeVoiceDraft, handleChatSend, isComposerLocked, setState, setTimeout],
178
+ );
179
+
180
+ const handleVoiceTranscriptPreview = useCallback(
181
+ (text: string) => {
182
+ if (isComposerLocked) return;
183
+ setState("chatInput", composeVoiceDraft(text));
184
+ },
185
+ [composeVoiceDraft, isComposerLocked, setState],
186
+ );
187
+
188
+ const handleVoicePlaybackStart = useCallback(
189
+ (event: VoicePlaybackStartEvent) => {
190
+ const pending = pendingVoiceTurnRef.current;
191
+ if (!pending) return;
192
+ if (event.startedAtMs > pending.expiresAtMs) {
193
+ pendingVoiceTurnRef.current = null;
194
+ return;
195
+ }
196
+ if (pending.voiceStartedAtMs != null) return;
197
+
198
+ pending.voiceStartedAtMs = event.startedAtMs;
199
+ pending.firstSegmentCached = event.cached;
200
+
201
+ setVoiceLatency((prev) => ({
202
+ firstSegmentCached: event.cached,
203
+ speechEndToFirstTokenMs: prev?.speechEndToFirstTokenMs ?? null,
204
+ speechEndToVoiceStartMs: Math.max(
205
+ 0,
206
+ Math.round(event.startedAtMs - pending.speechEndedAtMs),
207
+ ),
208
+ }));
209
+ },
210
+ [],
211
+ );
212
+
213
+ const voice = useVoiceChat({
214
+ cloudConnected: elizaCloudConnected,
215
+ interruptOnSpeech: isGameModal,
216
+ lang: uiLanguage === "zh-CN" ? "zh-CN" : "en-US",
217
+ onPlaybackStart: handleVoicePlaybackStart,
218
+ onTranscript: handleVoiceTranscript,
219
+ onTranscriptPreview: handleVoiceTranscriptPreview,
220
+ voiceConfig,
221
+ });
222
+ const {
223
+ queueAssistantSpeech,
224
+ speak,
225
+ startListening,
226
+ stopListening,
227
+ stopSpeaking,
228
+ } = voice;
229
+
230
+ const beginVoiceCapture = useCallback(
231
+ (mode: Exclude<VoiceCaptureMode, "idle"> = "compose") => {
232
+ if (isComposerLocked || voice.isListening) return;
233
+ const latestAssistant = findLatestAssistantMessage(conversationMessages);
234
+ suppressedAssistantSpeechIdRef.current = latestAssistant?.id ?? null;
235
+ voiceDraftBaseInputRef.current = chatInput;
236
+ stopSpeaking();
237
+ void startListening(mode);
238
+ },
239
+ [
240
+ chatInput,
241
+ conversationMessages,
242
+ isComposerLocked,
243
+ startListening,
244
+ stopSpeaking,
245
+ voice.isListening,
246
+ ],
247
+ );
248
+
249
+ const endVoiceCapture = useCallback(
250
+ (captureOptions?: { submit?: boolean }) => {
251
+ if (!voice.isListening) return;
252
+ void stopListening(captureOptions);
253
+ },
254
+ [stopListening, voice.isListening],
255
+ );
256
+
257
+ const handleSpeakMessage = useCallback(
258
+ (messageId: string, text: string) => {
259
+ if (!text.trim()) return;
260
+ suppressedAssistantSpeechIdRef.current = messageId;
261
+ speak(text);
262
+ },
263
+ [speak],
264
+ );
265
+
266
+ const handleEditMessage = useCallback(
267
+ async (messageId: string, text: string) => {
268
+ stopSpeaking();
269
+ return handleChatEdit(messageId, text);
270
+ },
271
+ [handleChatEdit, stopSpeaking],
272
+ );
273
+
274
+ useEffect(() => {
275
+ if (!isGameModal || agentVoiceMuted || voice.isListening) return;
276
+ const latestAssistant = findLatestAssistantMessage(conversationMessages);
277
+ if (!latestAssistant) return;
278
+ if (suppressedAssistantSpeechIdRef.current === latestAssistant.id) return;
279
+
280
+ queueAssistantSpeech(
281
+ latestAssistant.id,
282
+ latestAssistant.text,
283
+ !chatSending,
284
+ );
285
+ suppressedAssistantSpeechIdRef.current = null;
286
+ }, [
287
+ agentVoiceMuted,
288
+ chatSending,
289
+ conversationMessages,
290
+ isGameModal,
291
+ queueAssistantSpeech,
292
+ voice.isListening,
293
+ ]);
294
+
295
+ useEffect(() => {
296
+ if (!agentVoiceMuted) return;
297
+ stopSpeaking();
298
+ }, [agentVoiceMuted, stopSpeaking]);
299
+
300
+ useEffect(() => {
301
+ const pending = pendingVoiceTurnRef.current;
302
+ if (!pending || !chatFirstTokenReceived) return;
303
+ if (nowMs() > pending.expiresAtMs) {
304
+ pendingVoiceTurnRef.current = null;
305
+ return;
306
+ }
307
+ if (pending.firstTokenAtMs != null) return;
308
+
309
+ const firstTokenAtMs = nowMs();
310
+ pending.firstTokenAtMs = firstTokenAtMs;
311
+ setVoiceLatency((prev) => ({
312
+ firstSegmentCached: prev?.firstSegmentCached ?? null,
313
+ speechEndToFirstTokenMs: Math.max(
314
+ 0,
315
+ Math.round(firstTokenAtMs - pending.speechEndedAtMs),
316
+ ),
317
+ speechEndToVoiceStartMs: prev?.speechEndToVoiceStartMs ?? null,
318
+ }));
319
+ }, [chatFirstTokenReceived]);
320
+
321
+ return {
322
+ beginVoiceCapture,
323
+ endVoiceCapture,
324
+ handleEditMessage,
325
+ handleSpeakMessage,
326
+ stopSpeaking,
327
+ voice,
328
+ voiceLatency,
329
+ };
330
+ }
331
+
332
+ function useGameModalMessages(options: {
333
+ activeConversationId: string | null;
334
+ agentVoiceMuted: boolean;
335
+ companionMessageCutoffTs: number;
336
+ isGameModal: boolean;
337
+ setState: ReturnType<typeof useApp>["setState"];
338
+ stopSpeaking: () => void;
339
+ visibleMsgs: ConversationMessage[];
340
+ }) {
341
+ const {
342
+ activeConversationId,
343
+ agentVoiceMuted,
344
+ companionMessageCutoffTs,
345
+ isGameModal,
346
+ setState,
347
+ stopSpeaking,
348
+ visibleMsgs,
349
+ } = options;
350
+ const previousCompanionCutoffTsRef = useRef(companionMessageCutoffTs);
351
+ const previousGameModalVisibleMsgsRef = useRef<ConversationMessage[]>([]);
352
+ const previousActiveConversationIdRef = useRef(activeConversationId);
353
+ const companionVoiceInitializedRef = useRef(false);
354
+ const [companionNowMs, setCompanionNowMs] = useState(() => Date.now());
355
+ const [companionCarryover, setCompanionCarryover] =
356
+ useState<CompanionCarryoverState | null>(null);
357
+
358
+ const gameModalRecentMsgs = useMemo(
359
+ () =>
360
+ visibleMsgs.filter(
361
+ (message) => message.timestamp >= companionMessageCutoffTs,
362
+ ),
363
+ [companionMessageCutoffTs, visibleMsgs],
364
+ );
365
+ const gameModalContextMsgs = useMemo(() => {
366
+ if (gameModalRecentMsgs.length > 0) {
367
+ return gameModalRecentMsgs;
368
+ }
369
+ return visibleMsgs.slice(-COMPANION_VISIBLE_MESSAGE_LIMIT);
370
+ }, [gameModalRecentMsgs, visibleMsgs]);
371
+ const gameModalVisibleMsgs = useMemo(
372
+ () => gameModalContextMsgs.slice(-COMPANION_VISIBLE_MESSAGE_LIMIT),
373
+ [gameModalContextMsgs],
374
+ );
375
+ const gameModalCarryoverOpacity = useMemo(() => {
376
+ if (!companionCarryover) return 0;
377
+ if (companionNowMs < companionCarryover.fadeStartsAtMs) return 1;
378
+ const remainingMs = companionCarryover.expiresAtMs - companionNowMs;
379
+ if (remainingMs <= 0) return 0;
380
+ return Math.max(0, remainingMs / COMPANION_HISTORY_FADE_MS);
381
+ }, [companionCarryover, companionNowMs]);
382
+
383
+ useEffect(() => {
384
+ if (!isGameModal) {
385
+ previousActiveConversationIdRef.current = activeConversationId;
386
+ companionVoiceInitializedRef.current = false;
387
+ return;
388
+ }
389
+ if (companionVoiceInitializedRef.current) return;
390
+ companionVoiceInitializedRef.current = true;
391
+ if (agentVoiceMuted) {
392
+ setState("chatAgentVoiceMuted", false);
393
+ }
394
+ }, [activeConversationId, agentVoiceMuted, isGameModal, setState]);
395
+
396
+ useEffect(() => {
397
+ if (!isGameModal) {
398
+ previousActiveConversationIdRef.current = activeConversationId;
399
+ return;
400
+ }
401
+
402
+ if (previousActiveConversationIdRef.current === activeConversationId) {
403
+ return;
404
+ }
405
+
406
+ previousActiveConversationIdRef.current = activeConversationId;
407
+ previousGameModalVisibleMsgsRef.current = [];
408
+ previousCompanionCutoffTsRef.current = companionMessageCutoffTs;
409
+ setCompanionCarryover(null);
410
+ stopSpeaking();
411
+ }, [
412
+ activeConversationId,
413
+ companionMessageCutoffTs,
414
+ isGameModal,
415
+ stopSpeaking,
416
+ ]);
417
+
418
+ useEffect(() => {
419
+ if (!isGameModal) {
420
+ previousCompanionCutoffTsRef.current = companionMessageCutoffTs;
421
+ return;
422
+ }
423
+
424
+ const previousCutoffTs = previousCompanionCutoffTsRef.current;
425
+ if (companionMessageCutoffTs > previousCutoffTs) {
426
+ const carryoverMessages = previousGameModalVisibleMsgsRef.current.filter(
427
+ (message) => message.timestamp < companionMessageCutoffTs,
428
+ );
429
+ if (carryoverMessages.length > 0) {
430
+ const startedAtMs = Date.now();
431
+ setCompanionCarryover({
432
+ expiresAtMs:
433
+ startedAtMs + COMPANION_HISTORY_HOLD_MS + COMPANION_HISTORY_FADE_MS,
434
+ fadeStartsAtMs: startedAtMs + COMPANION_HISTORY_HOLD_MS,
435
+ messages: carryoverMessages,
436
+ });
437
+ } else {
438
+ setCompanionCarryover(null);
439
+ }
440
+ }
441
+ previousCompanionCutoffTsRef.current = companionMessageCutoffTs;
442
+ }, [companionMessageCutoffTs, isGameModal]);
443
+
444
+ useEffect(() => {
445
+ previousGameModalVisibleMsgsRef.current = gameModalVisibleMsgs;
446
+ }, [gameModalVisibleMsgs]);
447
+
448
+ useEffect(() => {
449
+ if (!companionCarryover) return;
450
+
451
+ const tick = () => setCompanionNowMs(Date.now());
452
+ tick();
453
+
454
+ const intervalId = window.setInterval(tick, 250);
455
+ return () => window.clearInterval(intervalId);
456
+ }, [companionCarryover]);
457
+
458
+ useEffect(() => {
459
+ if (!companionCarryover) return;
460
+ if (companionNowMs >= companionCarryover.expiresAtMs) {
461
+ setCompanionCarryover(null);
462
+ }
463
+ }, [companionCarryover, companionNowMs]);
464
+
465
+ return {
466
+ companionCarryover,
467
+ gameModalCarryoverOpacity,
468
+ gameModalVisibleMsgs,
469
+ };
470
+ }
471
+
472
+ export function ChatView({ variant = "default" }: ChatViewProps) {
473
+ const isGameModal = variant === "game-modal";
474
+ const showComposerVoiceToggle = false;
475
+ const {
476
+ agentStatus,
477
+ activeConversationId,
478
+ chatInput,
479
+ chatSending,
480
+ chatFirstTokenReceived,
481
+ companionMessageCutoffTs,
482
+ conversationMessages,
483
+ handleChatSend,
484
+ handleChatStop,
485
+ handleChatEdit,
486
+ elizaCloudConnected,
487
+ setState,
488
+ droppedFiles,
489
+ shareIngestNotice,
490
+ chatAgentVoiceMuted: agentVoiceMuted,
491
+ selectedVrmIndex,
492
+ chatPendingImages,
493
+ setChatPendingImages,
494
+ uiLanguage,
495
+ ptySessions,
496
+ t,
497
+ } = useApp();
498
+
499
+ const messagesRef = useRef<HTMLDivElement>(null);
500
+ const textareaRef = useRef<HTMLTextAreaElement>(null);
501
+ const fileInputRef = useRef<HTMLInputElement>(null);
502
+ const [imageDragOver, setImageDragOver] = useState(false);
503
+
504
+ // ── Derived composer state ──────────────────────────────────────
505
+ const isAgentStarting =
506
+ agentStatus?.state === "starting" || agentStatus?.state === "restarting";
507
+ const isComposerLocked = chatSending || isAgentStarting;
508
+ const {
509
+ beginVoiceCapture,
510
+ endVoiceCapture,
511
+ handleEditMessage,
512
+ handleSpeakMessage,
513
+ stopSpeaking,
514
+ voice,
515
+ voiceLatency,
516
+ } = useChatVoiceController({
517
+ agentVoiceMuted,
518
+ chatFirstTokenReceived,
519
+ chatInput,
520
+ chatSending,
521
+ conversationMessages,
522
+ elizaCloudConnected,
523
+ handleChatEdit,
524
+ handleChatSend,
525
+ isComposerLocked,
526
+ isGameModal,
527
+ setState,
528
+ uiLanguage,
529
+ });
530
+ const handleChatAvatarSpeakingChange = useCallback(
531
+ (isSpeaking: boolean) => {
532
+ setState("chatAvatarSpeaking", isSpeaking);
533
+ },
534
+ [setState],
535
+ );
536
+
537
+ const agentName = agentStatus?.agentName ?? "Agent";
538
+ const msgs = conversationMessages;
539
+ const visibleMsgs = useMemo(
540
+ () =>
541
+ msgs.filter(
542
+ (msg) =>
543
+ !(
544
+ chatSending &&
545
+ !chatFirstTokenReceived &&
546
+ msg.role === "assistant" &&
547
+ !msg.text.trim()
548
+ ) && !isRoutineCodingAgentMessage(msg),
549
+ ),
550
+ [chatFirstTokenReceived, chatSending, msgs],
551
+ );
552
+ const {
553
+ companionCarryover,
554
+ gameModalCarryoverOpacity,
555
+ gameModalVisibleMsgs,
556
+ } = useGameModalMessages({
557
+ activeConversationId,
558
+ agentVoiceMuted: agentVoiceMuted,
559
+ companionMessageCutoffTs,
560
+ isGameModal,
561
+ setState,
562
+ stopSpeaking,
563
+ visibleMsgs,
564
+ });
565
+ const agentAvatarSrc =
566
+ selectedVrmIndex > 0 ? getVrmPreviewUrl(selectedVrmIndex) : null;
567
+
568
+ useChatAvatarVoiceBridge({
569
+ mouthOpen: voice.mouthOpen,
570
+ isSpeaking: voice.isSpeaking,
571
+ usingAudioAnalysis: voice.usingAudioAnalysis,
572
+ onSpeakingChange: handleChatAvatarSpeakingChange,
573
+ });
574
+
575
+ // Auto-scroll on new messages. Use instant scroll when already near the
576
+ // bottom (or when the user is actively sending) to prevent the visible
577
+ // "scroll from top" effect that occurs when many background messages
578
+ // (e.g. coding-agent updates) arrive in rapid succession during smooth
579
+ // scrolling. Only smooth-scroll when the user has scrolled up and a new
580
+ // message nudges them back down.
581
+ useEffect(() => {
582
+ if (isGameModal) {
583
+ return;
584
+ }
585
+ if (!chatSending && visibleMsgs.length === 0) {
586
+ return;
587
+ }
588
+ const el = messagesRef.current;
589
+ if (!el) return;
590
+ const distanceFromBottom = el.scrollHeight - el.scrollTop - el.clientHeight;
591
+ const nearBottom = distanceFromBottom < 150;
592
+ el.scrollTo({
593
+ top: el.scrollHeight,
594
+ behavior: nearBottom ? "instant" : "smooth",
595
+ });
596
+ }, [chatSending, isGameModal, visibleMsgs]);
597
+
598
+ // Auto-resize textarea
599
+ useEffect(() => {
600
+ const ta = textareaRef.current;
601
+ if (!ta) return;
602
+
603
+ // Force a compact baseline when empty so the composer never boots oversized.
604
+ if (!chatInput) {
605
+ ta.style.height = `${CHAT_INPUT_MIN_HEIGHT_PX}px`;
606
+ ta.style.overflowY = "hidden";
607
+ return;
608
+ }
609
+
610
+ ta.style.height = "auto";
611
+ ta.style.overflowY = "hidden";
612
+ const h = Math.min(ta.scrollHeight, CHAT_INPUT_MAX_HEIGHT_PX);
613
+ ta.style.height = `${h}px`;
614
+ ta.style.overflowY =
615
+ ta.scrollHeight > CHAT_INPUT_MAX_HEIGHT_PX ? "auto" : "hidden";
616
+ }, [chatInput]);
617
+
618
+ const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
619
+ if (isComposerLocked) return;
620
+ if (e.key === "Enter" && !e.shiftKey) {
621
+ e.preventDefault();
622
+ void handleChatSend();
623
+ }
624
+ };
625
+
626
+ const addImageFiles = useCallback(
627
+ (files: FileList | File[]) => {
628
+ const imageFiles = Array.from(files).filter((f) =>
629
+ f.type.startsWith("image/"),
630
+ );
631
+ if (!imageFiles.length) return;
632
+
633
+ const readers = imageFiles.map(
634
+ (file) =>
635
+ new Promise<ImageAttachment>((resolve) => {
636
+ const reader = new FileReader();
637
+ reader.onload = () => {
638
+ const result = reader.result as string;
639
+ // result is "data:<mime>;base64,<data>" — strip the prefix
640
+ const commaIdx = result.indexOf(",");
641
+ const data = commaIdx >= 0 ? result.slice(commaIdx + 1) : result;
642
+ resolve({ data, mimeType: file.type, name: file.name });
643
+ };
644
+ reader.readAsDataURL(file);
645
+ }),
646
+ );
647
+
648
+ void Promise.all(readers).then((attachments) => {
649
+ setChatPendingImages((prev) => {
650
+ const combined = [...prev, ...attachments];
651
+ // Mirror the server-side MAX_CHAT_IMAGES=4 limit so the user gets
652
+ // immediate feedback rather than a 400 after upload.
653
+ return combined.slice(0, 4);
654
+ });
655
+ });
656
+ },
657
+ [setChatPendingImages],
658
+ );
659
+
660
+ const handleImageDrop = useCallback(
661
+ (e: DragEvent<HTMLDivElement>) => {
662
+ e.preventDefault();
663
+ setImageDragOver(false);
664
+ if (e.dataTransfer.files.length) {
665
+ addImageFiles(e.dataTransfer.files);
666
+ }
667
+ },
668
+ [addImageFiles],
669
+ );
670
+
671
+ const handleFileInputChange = useCallback(
672
+ (e: ChangeEvent<HTMLInputElement>) => {
673
+ if (e.target.files) {
674
+ addImageFiles(e.target.files);
675
+ }
676
+ e.target.value = "";
677
+ },
678
+ [addImageFiles],
679
+ );
680
+
681
+ const removeImage = useCallback(
682
+ (index: number) => {
683
+ setChatPendingImages((prev) => prev.filter((_, i) => i !== index));
684
+ },
685
+ [setChatPendingImages],
686
+ );
687
+
688
+ return (
689
+ <section
690
+ aria-label="Chat workspace"
691
+ className={`flex flex-col flex-1 min-h-0 relative${isGameModal ? " overflow-visible px-2 sm:px-3" : ""}${imageDragOver ? " ring-2 ring-accent ring-inset" : ""}`}
692
+ onDragOver={(e) => {
693
+ e.preventDefault();
694
+ setImageDragOver(true);
695
+ }}
696
+ onDragLeave={() => setImageDragOver(false)}
697
+ onDrop={handleImageDrop}
698
+ >
699
+ {/* ── Messages ───────────────────────────────────────────────── */}
700
+ <div
701
+ ref={messagesRef}
702
+ data-testid="chat-messages-scroll"
703
+ className={
704
+ isGameModal
705
+ ? "absolute inset-x-0 overflow-hidden select-none pointer-events-none"
706
+ : "chat-native-scrollbar relative flex flex-1 flex-col overflow-x-hidden overflow-y-auto py-2"
707
+ }
708
+ style={
709
+ isGameModal
710
+ ? {
711
+ zIndex: 1,
712
+ top: COMPANION_MESSAGE_LAYER_TOP,
713
+ bottom: COMPANION_MESSAGE_LAYER_BOTTOM,
714
+ userSelect: "none",
715
+ WebkitUserSelect: "none",
716
+ maskImage: COMPANION_MESSAGE_LAYER_MASK,
717
+ WebkitMaskImage: COMPANION_MESSAGE_LAYER_MASK,
718
+ }
719
+ : {
720
+ zIndex: 1,
721
+ }
722
+ }
723
+ >
724
+ {visibleMsgs.length === 0 && !chatSending ? (
725
+ isGameModal ? (
726
+ <div className="flex h-full items-end px-1 py-4" />
727
+ ) : (
728
+ <ChatEmptyState agentName={agentName} />
729
+ )
730
+ ) : isGameModal ? (
731
+ <div className="flex h-full w-full flex-col justify-end gap-4 px-1 py-4">
732
+ {companionCarryover?.messages.map((msg) => {
733
+ const isUser = msg.role === "user";
734
+ return (
735
+ <div
736
+ key={`carryover-${msg.id}`}
737
+ data-testid="companion-message-row"
738
+ data-companion-carryover="true"
739
+ className={`flex w-full ${isUser ? "justify-end" : "justify-start"}`}
740
+ style={{ opacity: gameModalCarryoverOpacity }}
741
+ >
742
+ <div
743
+ className={`max-w-[85%] rounded-2xl px-4 py-3 text-[15px] leading-relaxed ${
744
+ isUser
745
+ ? "bg-accent/85 text-white rounded-br-sm"
746
+ : "border border-white/10 bg-black/45 text-white/95 rounded-bl-sm backdrop-blur-md"
747
+ }`}
748
+ >
749
+ <div
750
+ className="break-words"
751
+ style={{ fontFamily: "var(--font-chat)" }}
752
+ >
753
+ <MessageContent message={msg} />
754
+ </div>
755
+ </div>
756
+ </div>
757
+ );
758
+ })}
759
+ {gameModalVisibleMsgs.map((msg) => {
760
+ const isUser = msg.role === "user";
761
+ return (
762
+ <div
763
+ key={msg.id}
764
+ data-testid="companion-message-row"
765
+ className={`flex w-full ${isUser ? "justify-end" : "justify-start"}`}
766
+ >
767
+ <div
768
+ className={`max-w-[85%] rounded-2xl px-4 py-3 text-[15px] leading-relaxed ${
769
+ isUser
770
+ ? "bg-accent/85 text-white rounded-br-sm"
771
+ : "border border-white/10 bg-black/45 text-white/95 rounded-bl-sm backdrop-blur-md"
772
+ }`}
773
+ >
774
+ <div
775
+ className="break-words"
776
+ style={{ fontFamily: "var(--font-chat)" }}
777
+ >
778
+ <MessageContent message={msg} />
779
+ </div>
780
+ </div>
781
+ </div>
782
+ );
783
+ })}
784
+ {chatSending && !chatFirstTokenReceived && (
785
+ <div className="flex w-full justify-start">
786
+ <div className="max-w-[85%] rounded-2xl rounded-bl-sm px-4 py-3 bg-black/30 flex items-center gap-1">
787
+ <span
788
+ className="w-1.5 h-1.5 rounded-full bg-white/50 animate-bounce"
789
+ style={{ animationDelay: "0ms" }}
790
+ />
791
+ <span
792
+ className="w-1.5 h-1.5 rounded-full bg-white/50 animate-bounce"
793
+ style={{ animationDelay: "150ms" }}
794
+ />
795
+ <span
796
+ className="w-1.5 h-1.5 rounded-full bg-white/50 animate-bounce"
797
+ style={{ animationDelay: "300ms" }}
798
+ />
799
+ </div>
800
+ </div>
801
+ )}
802
+ </div>
803
+ ) : (
804
+ <div className="w-full pl-2 sm:pl-3 pr-3 sm:pr-4 space-y-1">
805
+ {visibleMsgs.map((msg, i) => {
806
+ const prev = i > 0 ? visibleMsgs[i - 1] : null;
807
+ const isGrouped = prev?.role === msg.role;
808
+
809
+ return (
810
+ <ChatMessage
811
+ key={msg.id}
812
+ message={msg}
813
+ isGrouped={isGrouped}
814
+ agentName={agentName}
815
+ agentAvatarSrc={agentAvatarSrc}
816
+ onSpeak={handleSpeakMessage}
817
+ onEdit={handleEditMessage}
818
+ />
819
+ );
820
+ })}
821
+
822
+ {chatSending && !chatFirstTokenReceived && (
823
+ <TypingIndicator
824
+ agentName={agentName}
825
+ agentAvatarSrc={agentAvatarSrc}
826
+ />
827
+ )}
828
+ </div>
829
+ )}
830
+ </div>
831
+
832
+ {/* Agent activity box — sticky status per active coding-agent task */}
833
+ <AgentActivityBox sessions={ptySessions} />
834
+
835
+ {/* Share ingest notice */}
836
+ {shareIngestNotice && (
837
+ <div className="text-xs text-ok py-1 relative" style={{ zIndex: 1 }}>
838
+ {shareIngestNotice}
839
+ </div>
840
+ )}
841
+
842
+ {/* Dropped files */}
843
+ {droppedFiles.length > 0 && (
844
+ <div
845
+ className="text-xs text-muted py-0.5 flex gap-2 relative"
846
+ style={{ zIndex: 1 }}
847
+ >
848
+ {droppedFiles.map((f) => (
849
+ <span key={f}>{f}</span>
850
+ ))}
851
+ </div>
852
+ )}
853
+
854
+ {/* Pending image thumbnails */}
855
+ {chatPendingImages.length > 0 && (
856
+ <div
857
+ className="flex gap-2 flex-wrap py-1 relative"
858
+ data-no-camera-drag={isGameModal || undefined}
859
+ style={{ zIndex: 1 }}
860
+ >
861
+ {chatPendingImages.map((img, i) => (
862
+ <div
863
+ key={`${img.name}-${i}`}
864
+ className="relative group w-16 h-16 shrink-0"
865
+ >
866
+ <img
867
+ src={`data:${img.mimeType};base64,${img.data}`}
868
+ alt={img.name}
869
+ className="w-16 h-16 object-cover border border-border rounded"
870
+ />
871
+ <button
872
+ type="button"
873
+ title={t("chatview.RemoveImage")}
874
+ aria-label={`Remove image ${img.name}`}
875
+ onClick={() => removeImage(i)}
876
+ className="absolute -top-1.5 -right-1.5 w-4 h-4 rounded-full bg-danger text-white text-[10px] flex items-center justify-center opacity-100 sm:opacity-0 sm:group-hover:opacity-100 focus-visible:opacity-100 transition-opacity cursor-pointer"
877
+ >
878
+ ×
879
+ </button>
880
+ </div>
881
+ ))}
882
+ </div>
883
+ )}
884
+
885
+ {voiceLatency && (
886
+ <div
887
+ className="pb-1 text-[10px] text-muted relative"
888
+ style={{ zIndex: 1 }}
889
+ >
890
+ {t("chatview.SilenceEndFirstTo")}{" "}
891
+ {voiceLatency.speechEndToFirstTokenMs ?? "—"}
892
+ {t("chatview.msEndVoiceStart")}{" "}
893
+ {voiceLatency.speechEndToVoiceStartMs ?? "—"}
894
+ {t("chatview.msFirst")}{" "}
895
+ {voiceLatency.firstSegmentCached == null
896
+ ? "—"
897
+ : voiceLatency.firstSegmentCached
898
+ ? "cached"
899
+ : "uncached"}
900
+ </div>
901
+ )}
902
+
903
+ {/* ── Input row: mic + paperclip + textarea + send ───────────── */}
904
+ <input
905
+ ref={fileInputRef}
906
+ type="file"
907
+ accept="image/*"
908
+ multiple
909
+ className="hidden"
910
+ onChange={handleFileInputChange}
911
+ />
912
+ {isGameModal ? (
913
+ /* ── Game-modal composer ──────────────────────────────────────── */
914
+ <div
915
+ className="mt-auto pt-2.5 relative"
916
+ data-no-camera-drag="true"
917
+ style={{ zIndex: 1 }}
918
+ >
919
+ <ChatComposer
920
+ variant="game-modal"
921
+ textareaRef={textareaRef}
922
+ chatInput={chatInput}
923
+ chatPendingImagesCount={chatPendingImages.length}
924
+ isComposerLocked={isComposerLocked}
925
+ isAgentStarting={isAgentStarting}
926
+ chatSending={chatSending}
927
+ voice={{
928
+ supported: voice.supported,
929
+ isListening: voice.isListening,
930
+ captureMode: voice.captureMode,
931
+ interimTranscript: voice.interimTranscript,
932
+ isSpeaking: voice.isSpeaking,
933
+ toggleListening: voice.toggleListening,
934
+ startListening: beginVoiceCapture,
935
+ stopListening: endVoiceCapture,
936
+ }}
937
+ agentVoiceEnabled={!agentVoiceMuted}
938
+ showAgentVoiceToggle={showComposerVoiceToggle}
939
+ t={t}
940
+ onAttachImage={() => fileInputRef.current?.click()}
941
+ onChatInputChange={(value) => setState("chatInput", value)}
942
+ onKeyDown={handleKeyDown}
943
+ onSend={() => void handleChatSend()}
944
+ onStop={handleChatStop}
945
+ onStopSpeaking={stopSpeaking}
946
+ onToggleAgentVoice={() =>
947
+ setState("chatAgentVoiceMuted", !agentVoiceMuted)
948
+ }
949
+ />
950
+ </div>
951
+ ) : (
952
+ /* ── Default composer ─────────────────────────────────────────── */
953
+ <div
954
+ className="border-t border-border pt-3 pb-3 sm:pb-4 px-2 sm:px-3 relative"
955
+ style={{ zIndex: 1 }}
956
+ >
957
+ <ChatComposer
958
+ variant="default"
959
+ textareaRef={textareaRef}
960
+ chatInput={chatInput}
961
+ chatPendingImagesCount={chatPendingImages.length}
962
+ isComposerLocked={isComposerLocked}
963
+ isAgentStarting={isAgentStarting}
964
+ chatSending={chatSending}
965
+ voice={{
966
+ supported: voice.supported,
967
+ isListening: voice.isListening,
968
+ captureMode: voice.captureMode,
969
+ interimTranscript: voice.interimTranscript,
970
+ isSpeaking: voice.isSpeaking,
971
+ toggleListening: voice.toggleListening,
972
+ startListening: beginVoiceCapture,
973
+ stopListening: endVoiceCapture,
974
+ }}
975
+ agentVoiceEnabled={!agentVoiceMuted}
976
+ showAgentVoiceToggle={showComposerVoiceToggle}
977
+ t={t}
978
+ onAttachImage={() => fileInputRef.current?.click()}
979
+ onChatInputChange={(value) => setState("chatInput", value)}
980
+ onKeyDown={handleKeyDown}
981
+ onSend={() => void handleChatSend()}
982
+ onStop={handleChatStop}
983
+ onStopSpeaking={stopSpeaking}
984
+ onToggleAgentVoice={() =>
985
+ setState("chatAgentVoiceMuted", !agentVoiceMuted)
986
+ }
987
+ />
988
+ </div>
989
+ )}
990
+ </section>
991
+ );
992
+ }