@elizaos/app-core 2.0.0-alpha.73 → 2.0.0-alpha.75

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 (1143) hide show
  1. package/App.d.ts +5 -0
  2. package/App.d.ts.map +1 -0
  3. package/App.js +220 -0
  4. package/actions/character.d.ts +39 -0
  5. package/actions/character.d.ts.map +1 -0
  6. package/actions/character.js +247 -0
  7. package/actions/chat-helpers.d.ts +47 -0
  8. package/actions/chat-helpers.d.ts.map +1 -0
  9. package/actions/chat-helpers.js +79 -0
  10. package/actions/cloud.d.ts +17 -0
  11. package/actions/cloud.d.ts.map +1 -0
  12. package/actions/cloud.js +43 -0
  13. package/actions/index.d.ts +12 -0
  14. package/actions/index.d.ts.map +1 -0
  15. package/actions/index.js +11 -0
  16. package/actions/lifecycle.d.ts +43 -0
  17. package/actions/lifecycle.d.ts.map +1 -0
  18. package/actions/lifecycle.js +118 -0
  19. package/actions/onboarding.d.ts +12 -0
  20. package/actions/onboarding.d.ts.map +1 -0
  21. package/actions/onboarding.js +26 -0
  22. package/actions/triggers.d.ts +23 -0
  23. package/actions/triggers.d.ts.map +1 -0
  24. package/actions/triggers.js +148 -0
  25. package/api/client.d.ts +2736 -0
  26. package/api/client.d.ts.map +1 -0
  27. package/api/client.js +2492 -0
  28. package/api/index.d.ts +2 -0
  29. package/api/index.d.ts.map +1 -0
  30. package/autonomy/index.d.ts +48 -0
  31. package/autonomy/index.d.ts.map +1 -0
  32. package/autonomy/index.js +330 -0
  33. package/bridge/capacitor-bridge.d.ts +153 -0
  34. package/bridge/capacitor-bridge.d.ts.map +1 -0
  35. package/bridge/capacitor-bridge.js +193 -0
  36. package/bridge/electrobun-rpc.d.ts +28 -0
  37. package/bridge/electrobun-rpc.d.ts.map +1 -0
  38. package/bridge/electrobun-rpc.js +35 -0
  39. package/bridge/electrobun-runtime.d.ts +3 -0
  40. package/bridge/electrobun-runtime.d.ts.map +1 -0
  41. package/bridge/electrobun-runtime.js +17 -0
  42. package/bridge/index.d.ts +6 -0
  43. package/bridge/index.d.ts.map +1 -0
  44. package/bridge/native-plugins.d.ts +82 -0
  45. package/bridge/native-plugins.d.ts.map +1 -0
  46. package/bridge/native-plugins.js +39 -0
  47. package/bridge/plugin-bridge.d.ts +116 -0
  48. package/bridge/plugin-bridge.d.ts.map +1 -0
  49. package/bridge/plugin-bridge.js +203 -0
  50. package/bridge/storage-bridge.d.ts +39 -0
  51. package/bridge/storage-bridge.d.ts.map +1 -0
  52. package/bridge/storage-bridge.js +135 -0
  53. package/chat/index.d.ts +57 -0
  54. package/chat/index.d.ts.map +1 -0
  55. package/chat/index.js +160 -0
  56. package/coding/index.d.ts +25 -0
  57. package/coding/index.d.ts.map +1 -0
  58. package/coding/index.js +25 -0
  59. package/components/AdvancedPageView.d.ts +17 -0
  60. package/components/AdvancedPageView.d.ts.map +1 -0
  61. package/components/AdvancedPageView.js +146 -0
  62. package/components/AgentActivityBox.d.ts +7 -0
  63. package/components/AgentActivityBox.d.ts.map +1 -0
  64. package/components/AgentActivityBox.js +25 -0
  65. package/components/ApiKeyConfig.d.ts +26 -0
  66. package/components/ApiKeyConfig.d.ts.map +1 -0
  67. package/components/ApiKeyConfig.js +119 -0
  68. package/components/AppsPageView.d.ts +7 -0
  69. package/components/AppsPageView.d.ts.map +1 -0
  70. package/components/AppsPageView.js +31 -0
  71. package/components/AppsView.d.ts +8 -0
  72. package/components/AppsView.d.ts.map +1 -0
  73. package/components/AppsView.js +149 -0
  74. package/components/AvatarLoader.d.ts +13 -0
  75. package/components/AvatarLoader.d.ts.map +1 -0
  76. package/components/AvatarLoader.js +53 -0
  77. package/components/AvatarSelector.d.ts +23 -0
  78. package/components/AvatarSelector.d.ts.map +1 -0
  79. package/components/AvatarSelector.js +105 -0
  80. package/components/BscTradePanel.d.ts +22 -0
  81. package/components/BscTradePanel.d.ts.map +1 -0
  82. package/components/BscTradePanel.js +221 -0
  83. package/components/BugReportModal.d.ts +2 -0
  84. package/components/BugReportModal.d.ts.map +1 -0
  85. package/components/BugReportModal.js +219 -0
  86. package/components/CharacterRoster.d.ts +31 -0
  87. package/components/CharacterRoster.d.ts.map +1 -0
  88. package/components/CharacterRoster.js +41 -0
  89. package/components/CharacterView.d.ts +8 -0
  90. package/components/CharacterView.d.ts.map +1 -0
  91. package/components/CharacterView.js +685 -0
  92. package/components/ChatAvatar.d.ts +8 -0
  93. package/components/ChatAvatar.d.ts.map +1 -0
  94. package/components/ChatAvatar.js +89 -0
  95. package/components/ChatComposer.d.ts +37 -0
  96. package/components/ChatComposer.d.ts.map +1 -0
  97. package/components/ChatComposer.js +136 -0
  98. package/components/ChatMessage.d.ts +24 -0
  99. package/components/ChatMessage.d.ts.map +1 -0
  100. package/components/ChatMessage.js +167 -0
  101. package/components/ChatModalView.d.ts +10 -0
  102. package/components/ChatModalView.d.ts.map +1 -0
  103. package/components/ChatModalView.js +57 -0
  104. package/components/ChatView.d.ts +14 -0
  105. package/components/ChatView.d.ts.map +1 -0
  106. package/components/ChatView.js +526 -0
  107. package/components/CloudOnboarding.d.ts +7 -0
  108. package/components/CloudOnboarding.d.ts.map +1 -0
  109. package/components/CloudOnboarding.js +22 -0
  110. package/components/CloudSourceControls.d.ts +13 -0
  111. package/components/CloudSourceControls.d.ts.map +1 -0
  112. package/components/CloudSourceControls.js +16 -0
  113. package/components/CodingAgentSettingsSection.d.ts +2 -0
  114. package/components/CodingAgentSettingsSection.d.ts.map +1 -0
  115. package/components/CodingAgentSettingsSection.js +270 -0
  116. package/components/CommandPalette.d.ts +2 -0
  117. package/components/CommandPalette.d.ts.map +1 -0
  118. package/components/CommandPalette.js +181 -0
  119. package/components/CompanionSceneHost.d.ts +14 -0
  120. package/components/CompanionSceneHost.d.ts.map +1 -0
  121. package/components/CompanionSceneHost.js +360 -0
  122. package/components/CompanionShell.d.ts +17 -0
  123. package/components/CompanionShell.d.ts.map +1 -0
  124. package/components/CompanionShell.js +15 -0
  125. package/components/CompanionView.d.ts +2 -0
  126. package/components/CompanionView.d.ts.map +1 -0
  127. package/components/CompanionView.js +22 -0
  128. package/components/ConfigPageView.d.ts +11 -0
  129. package/components/ConfigPageView.d.ts.map +1 -0
  130. package/components/ConfigPageView.js +303 -0
  131. package/components/ConfigSaveFooter.d.ts +8 -0
  132. package/components/ConfigSaveFooter.d.ts.map +1 -0
  133. package/components/ConfigSaveFooter.js +10 -0
  134. package/components/ConfirmModal.d.ts +61 -0
  135. package/components/ConfirmModal.d.ts.map +1 -0
  136. package/components/ConfirmModal.js +164 -0
  137. package/components/ConnectionFailedBanner.d.ts +6 -0
  138. package/components/ConnectionFailedBanner.d.ts.map +1 -0
  139. package/components/ConnectionFailedBanner.js +22 -0
  140. package/components/ConnectorsPageView.d.ts +7 -0
  141. package/components/ConnectorsPageView.d.ts.map +1 -0
  142. package/components/ConnectorsPageView.js +8 -0
  143. package/components/ConversationsSidebar.d.ts +9 -0
  144. package/components/ConversationsSidebar.d.ts.map +1 -0
  145. package/components/ConversationsSidebar.js +116 -0
  146. package/components/CustomActionEditor.d.ts +10 -0
  147. package/components/CustomActionEditor.d.ts.map +1 -0
  148. package/components/CustomActionEditor.js +578 -0
  149. package/components/CustomActionsPanel.d.ts +9 -0
  150. package/components/CustomActionsPanel.d.ts.map +1 -0
  151. package/components/CustomActionsPanel.js +107 -0
  152. package/components/CustomActionsView.d.ts +2 -0
  153. package/components/CustomActionsView.d.ts.map +1 -0
  154. package/components/CustomActionsView.js +134 -0
  155. package/components/DatabasePageView.d.ts +5 -0
  156. package/components/DatabasePageView.d.ts.map +1 -0
  157. package/components/DatabasePageView.js +28 -0
  158. package/components/DatabaseView.d.ts +9 -0
  159. package/components/DatabaseView.d.ts.map +1 -0
  160. package/components/DatabaseView.js +311 -0
  161. package/components/ElizaCloudDashboard.d.ts +2 -0
  162. package/components/ElizaCloudDashboard.d.ts.map +1 -0
  163. package/components/ElizaCloudDashboard.js +657 -0
  164. package/components/EmotePicker.d.ts +2 -0
  165. package/components/EmotePicker.d.ts.map +1 -0
  166. package/components/EmotePicker.js +343 -0
  167. package/components/ErrorBoundary.d.ts +22 -0
  168. package/components/ErrorBoundary.d.ts.map +1 -0
  169. package/components/ErrorBoundary.js +31 -0
  170. package/components/FineTuningView.d.ts +2 -0
  171. package/components/FineTuningView.d.ts.map +1 -0
  172. package/components/FineTuningView.js +433 -0
  173. package/components/FlaminaGuide.d.ts +10 -0
  174. package/components/FlaminaGuide.d.ts.map +1 -0
  175. package/components/FlaminaGuide.js +64 -0
  176. package/components/GameView.d.ts +11 -0
  177. package/components/GameView.d.ts.map +1 -0
  178. package/components/GameView.js +294 -0
  179. package/components/GameViewOverlay.d.ts +8 -0
  180. package/components/GameViewOverlay.d.ts.map +1 -0
  181. package/components/GameViewOverlay.js +70 -0
  182. package/components/GlobalEmoteOverlay.d.ts +2 -0
  183. package/components/GlobalEmoteOverlay.d.ts.map +1 -0
  184. package/components/GlobalEmoteOverlay.js +112 -0
  185. package/components/Header.d.ts +9 -0
  186. package/components/Header.d.ts.map +1 -0
  187. package/components/Header.js +123 -0
  188. package/components/HeartbeatsView.d.ts +2 -0
  189. package/components/HeartbeatsView.d.ts.map +1 -0
  190. package/components/HeartbeatsView.js +378 -0
  191. package/components/InventoryView.d.ts +10 -0
  192. package/components/InventoryView.d.ts.map +1 -0
  193. package/components/InventoryView.js +176 -0
  194. package/components/KnowledgeView.d.ts +20 -0
  195. package/components/KnowledgeView.d.ts.map +1 -0
  196. package/components/KnowledgeView.js +480 -0
  197. package/components/LanguageDropdown.d.ts +30 -0
  198. package/components/LanguageDropdown.d.ts.map +1 -0
  199. package/components/LanguageDropdown.js +99 -0
  200. package/components/LifoMonitorPanel.d.ts +21 -0
  201. package/components/LifoMonitorPanel.d.ts.map +1 -0
  202. package/components/LifoMonitorPanel.js +24 -0
  203. package/components/LifoSandboxView.d.ts +5 -0
  204. package/components/LifoSandboxView.d.ts.map +1 -0
  205. package/components/LifoSandboxView.js +333 -0
  206. package/components/LoadingScreen.d.ts +13 -0
  207. package/components/LoadingScreen.d.ts.map +1 -0
  208. package/components/LoadingScreen.js +70 -0
  209. package/components/LogsPageView.d.ts +2 -0
  210. package/components/LogsPageView.d.ts.map +1 -0
  211. package/components/LogsPageView.js +7 -0
  212. package/components/LogsView.d.ts +5 -0
  213. package/components/LogsView.d.ts.map +1 -0
  214. package/components/LogsView.js +71 -0
  215. package/components/MediaGalleryView.d.ts +9 -0
  216. package/components/MediaGalleryView.d.ts.map +1 -0
  217. package/components/MediaGalleryView.js +236 -0
  218. package/components/MediaSettingsSection.d.ts +11 -0
  219. package/components/MediaSettingsSection.d.ts.map +1 -0
  220. package/components/MediaSettingsSection.js +329 -0
  221. package/components/MessageContent.d.ts +51 -0
  222. package/components/MessageContent.d.ts.map +1 -0
  223. package/components/MessageContent.js +553 -0
  224. package/components/OnboardingWizard.d.ts +2 -0
  225. package/components/OnboardingWizard.d.ts.map +1 -0
  226. package/components/OnboardingWizard.js +96 -0
  227. package/components/PairingView.d.ts +5 -0
  228. package/components/PairingView.d.ts.map +1 -0
  229. package/components/PairingView.js +29 -0
  230. package/components/PermissionsSection.d.ts +20 -0
  231. package/components/PermissionsSection.d.ts.map +1 -0
  232. package/components/PermissionsSection.js +573 -0
  233. package/components/PluginsPageView.d.ts +5 -0
  234. package/components/PluginsPageView.d.ts.map +1 -0
  235. package/components/PluginsPageView.js +8 -0
  236. package/components/PluginsView.d.ts +21 -0
  237. package/components/PluginsView.d.ts.map +1 -0
  238. package/components/PluginsView.js +1534 -0
  239. package/components/ProviderSwitcher.d.ts +42 -0
  240. package/components/ProviderSwitcher.d.ts.map +1 -0
  241. package/components/ProviderSwitcher.js +493 -0
  242. package/components/RestartBanner.d.ts +2 -0
  243. package/components/RestartBanner.d.ts.map +1 -0
  244. package/components/RestartBanner.js +36 -0
  245. package/components/RuntimeView.d.ts +10 -0
  246. package/components/RuntimeView.d.ts.map +1 -0
  247. package/components/RuntimeView.js +165 -0
  248. package/components/SaveCommandModal.d.ts +12 -0
  249. package/components/SaveCommandModal.d.ts.map +1 -0
  250. package/components/SaveCommandModal.js +84 -0
  251. package/components/SecretsView.d.ts +9 -0
  252. package/components/SecretsView.d.ts.map +1 -0
  253. package/components/SecretsView.js +249 -0
  254. package/components/SettingsView.d.ts +9 -0
  255. package/components/SettingsView.d.ts.map +1 -0
  256. package/components/SettingsView.js +230 -0
  257. package/components/ShellOverlays.d.ts +8 -0
  258. package/components/ShellOverlays.d.ts.map +1 -0
  259. package/components/ShellOverlays.js +10 -0
  260. package/components/ShortcutsOverlay.d.ts +2 -0
  261. package/components/ShortcutsOverlay.d.ts.map +1 -0
  262. package/components/ShortcutsOverlay.js +79 -0
  263. package/components/SkillsView.d.ts +11 -0
  264. package/components/SkillsView.d.ts.map +1 -0
  265. package/components/SkillsView.js +358 -0
  266. package/components/StartupFailureView.d.ts +8 -0
  267. package/components/StartupFailureView.d.ts.map +1 -0
  268. package/components/StartupFailureView.js +16 -0
  269. package/components/StreamView.d.ts +16 -0
  270. package/components/StreamView.d.ts.map +1 -0
  271. package/components/StreamView.js +300 -0
  272. package/components/StripeEmbeddedCheckout.d.ts +24 -0
  273. package/components/StripeEmbeddedCheckout.d.ts.map +1 -0
  274. package/components/StripeEmbeddedCheckout.js +101 -0
  275. package/components/SubscriptionStatus.d.ts +23 -0
  276. package/components/SubscriptionStatus.d.ts.map +1 -0
  277. package/components/SubscriptionStatus.js +301 -0
  278. package/components/SystemWarningBanner.d.ts +6 -0
  279. package/components/SystemWarningBanner.d.ts.map +1 -0
  280. package/components/SystemWarningBanner.js +46 -0
  281. package/components/ThemeToggle.d.ts +21 -0
  282. package/components/ThemeToggle.d.ts.map +1 -0
  283. package/components/ThemeToggle.js +24 -0
  284. package/components/TrajectoriesView.d.ts +12 -0
  285. package/components/TrajectoriesView.d.ts.map +1 -0
  286. package/components/TrajectoriesView.js +183 -0
  287. package/components/TrajectoryDetailView.d.ts +13 -0
  288. package/components/TrajectoryDetailView.d.ts.map +1 -0
  289. package/components/TrajectoryDetailView.js +112 -0
  290. package/components/TriggersView.d.ts +2 -0
  291. package/components/TriggersView.d.ts.map +1 -0
  292. package/components/VectorBrowserView.d.ts +10 -0
  293. package/components/VectorBrowserView.d.ts.map +1 -0
  294. package/components/VectorBrowserView.js +997 -0
  295. package/components/VoiceConfigView.d.ts +11 -0
  296. package/components/VoiceConfigView.d.ts.map +1 -0
  297. package/components/VoiceConfigView.js +329 -0
  298. package/components/VrmStage.d.ts +28 -0
  299. package/components/VrmStage.d.ts.map +1 -0
  300. package/components/VrmStage.js +178 -0
  301. package/components/WhatsAppQrOverlay.d.ts +8 -0
  302. package/components/WhatsAppQrOverlay.d.ts.map +1 -0
  303. package/components/WhatsAppQrOverlay.js +63 -0
  304. package/components/apps/AppDetailPane.d.ts +15 -0
  305. package/components/apps/AppDetailPane.d.ts.map +1 -0
  306. package/components/apps/AppDetailPane.js +13 -0
  307. package/components/apps/AppsCatalogGrid.d.ts +20 -0
  308. package/components/apps/AppsCatalogGrid.d.ts.map +1 -0
  309. package/components/apps/AppsCatalogGrid.js +18 -0
  310. package/components/apps/extensions/registry.d.ts +4 -0
  311. package/components/apps/extensions/registry.d.ts.map +1 -0
  312. package/components/apps/extensions/registry.js +7 -0
  313. package/components/apps/extensions/types.d.ts +7 -0
  314. package/components/apps/extensions/types.d.ts.map +1 -0
  315. package/components/apps/extensions/types.js +1 -0
  316. package/components/apps/helpers.d.ts +7 -0
  317. package/components/apps/helpers.d.ts.map +1 -0
  318. package/components/apps/helpers.js +44 -0
  319. package/components/avatar/VrmAnimationLoader.d.ts +30 -0
  320. package/components/avatar/VrmAnimationLoader.d.ts.map +1 -0
  321. package/components/avatar/VrmAnimationLoader.js +99 -0
  322. package/components/avatar/VrmBlinkController.d.ts +37 -0
  323. package/components/avatar/VrmBlinkController.d.ts.map +1 -0
  324. package/components/avatar/VrmBlinkController.js +98 -0
  325. package/components/avatar/VrmCameraManager.d.ts +57 -0
  326. package/components/avatar/VrmCameraManager.d.ts.map +1 -0
  327. package/components/avatar/VrmCameraManager.js +277 -0
  328. package/components/avatar/VrmEngine.d.ts +246 -0
  329. package/components/avatar/VrmEngine.d.ts.map +1 -0
  330. package/components/avatar/VrmEngine.js +2076 -0
  331. package/components/avatar/VrmFootShadow.d.ts +18 -0
  332. package/components/avatar/VrmFootShadow.d.ts.map +1 -0
  333. package/components/avatar/VrmFootShadow.js +83 -0
  334. package/components/avatar/VrmViewer.d.ts +60 -0
  335. package/components/avatar/VrmViewer.d.ts.map +1 -0
  336. package/components/avatar/VrmViewer.js +396 -0
  337. package/components/avatar/mixamoVRMRigMap.d.ts +3 -0
  338. package/components/avatar/mixamoVRMRigMap.d.ts.map +1 -0
  339. package/components/avatar/mixamoVRMRigMap.js +56 -0
  340. package/components/avatar/retargetMixamoFbxToVrm.d.ts +9 -0
  341. package/components/avatar/retargetMixamoFbxToVrm.d.ts.map +1 -0
  342. package/components/avatar/retargetMixamoFbxToVrm.js +88 -0
  343. package/components/avatar/retargetMixamoGltfToVrm.d.ts +11 -0
  344. package/components/avatar/retargetMixamoGltfToVrm.d.ts.map +1 -0
  345. package/components/avatar/retargetMixamoGltfToVrm.js +80 -0
  346. package/components/chainConfig.d.ts +89 -0
  347. package/components/chainConfig.d.ts.map +1 -0
  348. package/components/chainConfig.js +287 -0
  349. package/components/companion/CompanionHeader.d.ts +15 -0
  350. package/components/companion/CompanionHeader.d.ts.map +1 -0
  351. package/components/companion/CompanionHeader.js +7 -0
  352. package/components/companion/CompanionSceneHost.d.ts +2 -0
  353. package/components/companion/CompanionSceneHost.d.ts.map +1 -0
  354. package/components/companion/CompanionSceneHost.js +1 -0
  355. package/components/companion/VrmStage.d.ts +3 -0
  356. package/components/companion/VrmStage.d.ts.map +1 -0
  357. package/components/companion/VrmStage.js +1 -0
  358. package/components/companion/index.d.ts +18 -0
  359. package/components/companion/index.d.ts.map +1 -0
  360. package/components/companion/index.js +17 -0
  361. package/components/companion/walletUtils.d.ts +95 -0
  362. package/components/companion/walletUtils.d.ts.map +1 -0
  363. package/components/companion/walletUtils.js +167 -0
  364. package/components/companion-shell-styles.d.ts +38 -0
  365. package/components/companion-shell-styles.d.ts.map +1 -0
  366. package/components/companion-shell-styles.js +248 -0
  367. package/components/confirm-delete-control.d.ts +16 -0
  368. package/components/confirm-delete-control.d.ts.map +1 -0
  369. package/components/confirm-delete-control.js +12 -0
  370. package/components/conversations/ConversationListItem.d.ts +31 -0
  371. package/components/conversations/ConversationListItem.d.ts.map +1 -0
  372. package/components/conversations/ConversationListItem.js +52 -0
  373. package/components/conversations/conversation-utils.d.ts +9 -0
  374. package/components/conversations/conversation-utils.d.ts.map +1 -0
  375. package/components/conversations/conversation-utils.js +138 -0
  376. package/components/format.d.ts +54 -0
  377. package/components/format.d.ts.map +1 -0
  378. package/components/format.js +82 -0
  379. package/components/index.d.ts +96 -0
  380. package/components/index.d.ts.map +1 -0
  381. package/components/index.js +95 -0
  382. package/components/inventory/CopyableAddress.d.ts +8 -0
  383. package/components/inventory/CopyableAddress.d.ts.map +1 -0
  384. package/components/inventory/CopyableAddress.js +18 -0
  385. package/components/inventory/InventoryToolbar.d.ts +25 -0
  386. package/components/inventory/InventoryToolbar.d.ts.map +1 -0
  387. package/components/inventory/InventoryToolbar.js +28 -0
  388. package/components/inventory/NftGrid.d.ts +13 -0
  389. package/components/inventory/NftGrid.d.ts.map +1 -0
  390. package/components/inventory/NftGrid.js +29 -0
  391. package/components/inventory/TokenLogo.d.ts +12 -0
  392. package/components/inventory/TokenLogo.d.ts.map +1 -0
  393. package/components/inventory/TokenLogo.js +33 -0
  394. package/components/inventory/TokensTable.d.ts +24 -0
  395. package/components/inventory/TokensTable.d.ts.map +1 -0
  396. package/components/inventory/TokensTable.js +26 -0
  397. package/components/inventory/constants.d.ts +52 -0
  398. package/components/inventory/constants.d.ts.map +1 -0
  399. package/components/inventory/constants.js +121 -0
  400. package/components/inventory/index.d.ts +9 -0
  401. package/components/inventory/index.d.ts.map +1 -0
  402. package/components/inventory/index.js +8 -0
  403. package/components/inventory/media-url.d.ts +6 -0
  404. package/components/inventory/media-url.d.ts.map +1 -0
  405. package/components/inventory/media-url.js +28 -0
  406. package/components/inventory/useInventoryData.d.ts +53 -0
  407. package/components/inventory/useInventoryData.d.ts.map +1 -0
  408. package/components/inventory/useInventoryData.js +332 -0
  409. package/components/knowledge-upload-image.d.ts +27 -0
  410. package/components/knowledge-upload-image.d.ts.map +1 -0
  411. package/components/knowledge-upload-image.js +146 -0
  412. package/components/labels.d.ts +6 -0
  413. package/components/labels.d.ts.map +1 -0
  414. package/components/labels.js +40 -0
  415. package/components/onboarding/ActivateStep.d.ts +2 -0
  416. package/components/onboarding/ActivateStep.d.ts.map +1 -0
  417. package/components/onboarding/ActivateStep.js +10 -0
  418. package/components/onboarding/ConnectionStep.d.ts +2 -0
  419. package/components/onboarding/ConnectionStep.d.ts.map +1 -0
  420. package/components/onboarding/ConnectionStep.js +609 -0
  421. package/components/onboarding/IdentityStep.d.ts +2 -0
  422. package/components/onboarding/IdentityStep.d.ts.map +1 -0
  423. package/components/onboarding/IdentityStep.js +102 -0
  424. package/components/onboarding/OnboardingPanel.d.ts +9 -0
  425. package/components/onboarding/OnboardingPanel.d.ts.map +1 -0
  426. package/components/onboarding/OnboardingPanel.js +24 -0
  427. package/components/onboarding/OnboardingStepNav.d.ts +2 -0
  428. package/components/onboarding/OnboardingStepNav.d.ts.map +1 -0
  429. package/components/onboarding/OnboardingStepNav.js +23 -0
  430. package/components/onboarding/PermissionsStep.d.ts +2 -0
  431. package/components/onboarding/PermissionsStep.d.ts.map +1 -0
  432. package/components/onboarding/PermissionsStep.js +7 -0
  433. package/components/onboarding/RpcStep.d.ts +2 -0
  434. package/components/onboarding/RpcStep.d.ts.map +1 -0
  435. package/components/onboarding/RpcStep.js +125 -0
  436. package/components/permissions/PermissionIcon.d.ts +4 -0
  437. package/components/permissions/PermissionIcon.d.ts.map +1 -0
  438. package/components/permissions/PermissionIcon.js +12 -0
  439. package/components/permissions/StreamingPermissions.d.ts +20 -0
  440. package/components/permissions/StreamingPermissions.d.ts.map +1 -0
  441. package/components/permissions/StreamingPermissions.js +177 -0
  442. package/components/plugins/showcase-data.d.ts +7 -0
  443. package/components/plugins/showcase-data.d.ts.map +1 -0
  444. package/components/plugins/showcase-data.js +464 -0
  445. package/components/shared/ShellHeaderControls.d.ts +27 -0
  446. package/components/shared/ShellHeaderControls.d.ts.map +1 -0
  447. package/components/shared/ShellHeaderControls.js +60 -0
  448. package/components/shared-companion-scene-context.d.ts +3 -0
  449. package/components/shared-companion-scene-context.d.ts.map +1 -0
  450. package/components/shared-companion-scene-context.js +13 -0
  451. package/components/skeletons.d.ts +17 -0
  452. package/components/skeletons.d.ts.map +1 -0
  453. package/components/skeletons.js +22 -0
  454. package/components/stream/ActivityFeed.d.ts +5 -0
  455. package/components/stream/ActivityFeed.d.ts.map +1 -0
  456. package/components/stream/ActivityFeed.js +57 -0
  457. package/components/stream/AvatarPip.d.ts +5 -0
  458. package/components/stream/AvatarPip.d.ts.map +1 -0
  459. package/components/stream/AvatarPip.js +6 -0
  460. package/components/stream/ChatContent.d.ts +6 -0
  461. package/components/stream/ChatContent.d.ts.map +1 -0
  462. package/components/stream/ChatContent.js +69 -0
  463. package/components/stream/ChatTicker.d.ts +5 -0
  464. package/components/stream/ChatTicker.d.ts.map +1 -0
  465. package/components/stream/ChatTicker.js +34 -0
  466. package/components/stream/IdleContent.d.ts +5 -0
  467. package/components/stream/IdleContent.d.ts.map +1 -0
  468. package/components/stream/IdleContent.js +17 -0
  469. package/components/stream/StatusBar.d.ts +36 -0
  470. package/components/stream/StatusBar.d.ts.map +1 -0
  471. package/components/stream/StatusBar.js +140 -0
  472. package/components/stream/StreamSettings.d.ts +33 -0
  473. package/components/stream/StreamSettings.d.ts.map +1 -0
  474. package/components/stream/StreamSettings.js +99 -0
  475. package/components/stream/StreamTerminal.d.ts +2 -0
  476. package/components/stream/StreamTerminal.d.ts.map +1 -0
  477. package/components/stream/StreamTerminal.js +52 -0
  478. package/components/stream/StreamVoiceConfig.d.ts +10 -0
  479. package/components/stream/StreamVoiceConfig.d.ts.map +1 -0
  480. package/components/stream/StreamVoiceConfig.js +88 -0
  481. package/components/stream/helpers.d.ts +32 -0
  482. package/components/stream/helpers.d.ts.map +1 -0
  483. package/components/stream/helpers.js +110 -0
  484. package/components/stream/overlays/OverlayLayer.d.ts +20 -0
  485. package/components/stream/overlays/OverlayLayer.d.ts.map +1 -0
  486. package/components/stream/overlays/OverlayLayer.js +24 -0
  487. package/components/stream/overlays/built-in/ActionTickerWidget.d.ts +8 -0
  488. package/components/stream/overlays/built-in/ActionTickerWidget.d.ts.map +1 -0
  489. package/components/stream/overlays/built-in/ActionTickerWidget.js +44 -0
  490. package/components/stream/overlays/built-in/AlertPopupWidget.d.ts +7 -0
  491. package/components/stream/overlays/built-in/AlertPopupWidget.d.ts.map +1 -0
  492. package/components/stream/overlays/built-in/AlertPopupWidget.js +62 -0
  493. package/components/stream/overlays/built-in/BrandingWidget.d.ts +7 -0
  494. package/components/stream/overlays/built-in/BrandingWidget.d.ts.map +1 -0
  495. package/components/stream/overlays/built-in/BrandingWidget.js +36 -0
  496. package/components/stream/overlays/built-in/CustomHtmlWidget.d.ts +26 -0
  497. package/components/stream/overlays/built-in/CustomHtmlWidget.d.ts.map +1 -0
  498. package/components/stream/overlays/built-in/CustomHtmlWidget.js +78 -0
  499. package/components/stream/overlays/built-in/PeonGlassWidget.d.ts +11 -0
  500. package/components/stream/overlays/built-in/PeonGlassWidget.d.ts.map +1 -0
  501. package/components/stream/overlays/built-in/PeonGlassWidget.js +188 -0
  502. package/components/stream/overlays/built-in/PeonHudWidget.d.ts +10 -0
  503. package/components/stream/overlays/built-in/PeonHudWidget.d.ts.map +1 -0
  504. package/components/stream/overlays/built-in/PeonHudWidget.js +168 -0
  505. package/components/stream/overlays/built-in/PeonSakuraWidget.d.ts +11 -0
  506. package/components/stream/overlays/built-in/PeonSakuraWidget.d.ts.map +1 -0
  507. package/components/stream/overlays/built-in/PeonSakuraWidget.js +213 -0
  508. package/components/stream/overlays/built-in/ThoughtBubbleWidget.d.ts +8 -0
  509. package/components/stream/overlays/built-in/ThoughtBubbleWidget.d.ts.map +1 -0
  510. package/components/stream/overlays/built-in/ThoughtBubbleWidget.js +59 -0
  511. package/components/stream/overlays/built-in/ViewerCountWidget.d.ts +7 -0
  512. package/components/stream/overlays/built-in/ViewerCountWidget.d.ts.map +1 -0
  513. package/components/stream/overlays/built-in/ViewerCountWidget.js +34 -0
  514. package/components/stream/overlays/built-in/index.d.ts +13 -0
  515. package/components/stream/overlays/built-in/index.d.ts.map +1 -0
  516. package/components/stream/overlays/built-in/index.js +12 -0
  517. package/components/stream/overlays/registry.d.ts +11 -0
  518. package/components/stream/overlays/registry.d.ts.map +1 -0
  519. package/components/stream/overlays/registry.js +16 -0
  520. package/components/stream/overlays/types.d.ts +67 -0
  521. package/components/stream/overlays/types.d.ts.map +1 -0
  522. package/components/stream/overlays/types.js +7 -0
  523. package/components/stream/overlays/useOverlayLayout.d.ts +27 -0
  524. package/components/stream/overlays/useOverlayLayout.d.ts.map +1 -0
  525. package/components/stream/overlays/useOverlayLayout.js +162 -0
  526. package/components/trajectory-format.d.ts +6 -0
  527. package/components/trajectory-format.d.ts.map +1 -0
  528. package/components/trajectory-format.js +43 -0
  529. package/components/ui-badges.d.ts +23 -0
  530. package/components/ui-badges.d.ts.map +1 -0
  531. package/components/ui-badges.js +38 -0
  532. package/components/ui-switch.d.ts +14 -0
  533. package/components/ui-switch.d.ts.map +1 -0
  534. package/components/ui-switch.js +15 -0
  535. package/components/vector-browser-three.d.ts +4 -0
  536. package/components/vector-browser-three.d.ts.map +1 -0
  537. package/components/vector-browser-three.js +21 -0
  538. package/config/branding.d.ts +49 -0
  539. package/config/branding.d.ts.map +1 -0
  540. package/config/branding.js +16 -0
  541. package/config/config-catalog.d.ts +376 -0
  542. package/config/config-catalog.d.ts.map +1 -0
  543. package/config/config-catalog.js +724 -0
  544. package/config/config-field.d.ts +68 -0
  545. package/config/config-field.d.ts.map +1 -0
  546. package/config/config-field.js +840 -0
  547. package/config/config-renderer.d.ts +176 -0
  548. package/config/config-renderer.d.ts.map +1 -0
  549. package/config/config-renderer.js +405 -0
  550. package/config/index.d.ts +6 -0
  551. package/config/index.d.ts.map +1 -0
  552. package/config/index.js +5 -0
  553. package/config/ui-renderer.d.ts +26 -0
  554. package/config/ui-renderer.d.ts.map +1 -0
  555. package/config/ui-renderer.js +815 -0
  556. package/config/ui-spec.d.ts +164 -0
  557. package/config/ui-spec.d.ts.map +1 -0
  558. package/config/ui-spec.js +13 -0
  559. package/events/index.d.ts +47 -0
  560. package/events/index.d.ts.map +1 -0
  561. package/events/index.js +43 -0
  562. package/hooks/index.d.ts +15 -0
  563. package/hooks/index.d.ts.map +1 -0
  564. package/hooks/useBugReport.d.ts +14 -0
  565. package/hooks/useBugReport.d.ts.map +1 -0
  566. package/hooks/useBugReport.js +18 -0
  567. package/hooks/useCanvasWindow.d.ts +38 -0
  568. package/hooks/useCanvasWindow.d.ts.map +1 -0
  569. package/hooks/useCanvasWindow.js +273 -0
  570. package/hooks/useChatAvatarVoice.d.ts +10 -0
  571. package/hooks/useChatAvatarVoice.d.ts.map +1 -0
  572. package/hooks/useChatAvatarVoice.js +71 -0
  573. package/hooks/useClickOutside.d.ts +6 -0
  574. package/hooks/useClickOutside.d.ts.map +1 -0
  575. package/hooks/useClickOutside.js +25 -0
  576. package/hooks/useContextMenu.d.ts +17 -0
  577. package/hooks/useContextMenu.d.ts.map +1 -0
  578. package/hooks/useContextMenu.js +100 -0
  579. package/hooks/useKeyboardShortcuts.d.ts +17 -0
  580. package/hooks/useKeyboardShortcuts.d.ts.map +1 -0
  581. package/hooks/useKeyboardShortcuts.js +67 -0
  582. package/hooks/useLifoSync.d.ts +18 -0
  583. package/hooks/useLifoSync.d.ts.map +1 -0
  584. package/hooks/useLifoSync.js +113 -0
  585. package/hooks/useMemoryMonitor.d.ts +87 -0
  586. package/hooks/useMemoryMonitor.d.ts.map +1 -0
  587. package/hooks/useMemoryMonitor.js +209 -0
  588. package/hooks/useRenderGuard.d.ts +17 -0
  589. package/hooks/useRenderGuard.d.ts.map +1 -0
  590. package/hooks/useRenderGuard.js +36 -0
  591. package/hooks/useRetakeCapture.d.ts +12 -0
  592. package/hooks/useRetakeCapture.d.ts.map +1 -0
  593. package/hooks/useRetakeCapture.js +60 -0
  594. package/hooks/useStreamPopoutNavigation.d.ts +3 -0
  595. package/hooks/useStreamPopoutNavigation.d.ts.map +1 -0
  596. package/hooks/useStreamPopoutNavigation.js +17 -0
  597. package/hooks/useTimeout.d.ts +11 -0
  598. package/hooks/useTimeout.d.ts.map +1 -0
  599. package/hooks/useTimeout.js +32 -0
  600. package/hooks/useVoiceChat.d.ts +94 -0
  601. package/hooks/useVoiceChat.d.ts.map +1 -0
  602. package/hooks/useVoiceChat.js +1074 -0
  603. package/hooks/useWhatsAppPairing.d.ts +11 -0
  604. package/hooks/useWhatsAppPairing.d.ts.map +1 -0
  605. package/hooks/useWhatsAppPairing.js +95 -0
  606. package/i18n/index.d.ts +7 -0
  607. package/i18n/index.d.ts.map +1 -0
  608. package/i18n/index.js +53 -0
  609. package/i18n/locales/en.json +1239 -0
  610. package/i18n/locales/es.json +1236 -0
  611. package/i18n/locales/ko.json +1236 -0
  612. package/i18n/locales/pt.json +1236 -0
  613. package/i18n/locales/zh-CN.json +1236 -0
  614. package/i18n/messages.d.ts +6 -0
  615. package/i18n/messages.d.ts.map +1 -0
  616. package/i18n/messages.js +14 -0
  617. package/index.d.ts +5 -0
  618. package/index.d.ts.map +1 -0
  619. package/navigation/index.d.ts +27 -0
  620. package/navigation/index.d.ts.map +1 -0
  621. package/navigation/index.js +232 -0
  622. package/onboarding-config.d.ts +25 -0
  623. package/onboarding-config.d.ts.map +1 -0
  624. package/onboarding-config.js +76 -0
  625. package/package.json +143 -53
  626. package/platform/browser-launch.d.ts +2 -0
  627. package/platform/browser-launch.d.ts.map +1 -0
  628. package/platform/browser-launch.js +109 -0
  629. package/platform/index.d.ts +14 -0
  630. package/platform/index.d.ts.map +1 -0
  631. package/platform/index.js +24 -0
  632. package/platform/init.d.ts +40 -0
  633. package/platform/init.d.ts.map +1 -0
  634. package/platform/init.js +160 -0
  635. package/platform/lifo.d.ts +51 -0
  636. package/platform/lifo.d.ts.map +1 -0
  637. package/platform/lifo.js +138 -0
  638. package/providers/index.d.ts +19 -0
  639. package/providers/index.d.ts.map +1 -0
  640. package/providers/index.js +80 -0
  641. package/shell-params.d.ts +12 -0
  642. package/shell-params.d.ts.map +1 -0
  643. package/shell-params.js +19 -0
  644. package/state/AppContext.d.ts +12 -0
  645. package/state/AppContext.d.ts.map +1 -0
  646. package/state/AppContext.js +5060 -0
  647. package/state/index.d.ts +7 -0
  648. package/state/index.d.ts.map +1 -0
  649. package/state/internal.d.ts +7 -0
  650. package/state/internal.d.ts.map +1 -0
  651. package/state/internal.js +6 -0
  652. package/state/onboarding-resume.d.ts +11 -0
  653. package/state/onboarding-resume.d.ts.map +1 -0
  654. package/state/onboarding-resume.js +189 -0
  655. package/state/parsers.d.ts +26 -0
  656. package/state/parsers.d.ts.map +1 -0
  657. package/state/parsers.js +255 -0
  658. package/state/persistence.d.ts +59 -0
  659. package/state/persistence.d.ts.map +1 -0
  660. package/state/persistence.js +326 -0
  661. package/state/shell-routing.d.ts +12 -0
  662. package/state/shell-routing.d.ts.map +1 -0
  663. package/state/shell-routing.js +25 -0
  664. package/state/types.d.ts +421 -0
  665. package/state/types.d.ts.map +1 -0
  666. package/state/types.js +75 -0
  667. package/state/ui-preferences.d.ts +3 -0
  668. package/state/ui-preferences.d.ts.map +1 -0
  669. package/state/ui-preferences.js +1 -0
  670. package/state/useApp.d.ts +4 -0
  671. package/state/useApp.d.ts.map +1 -0
  672. package/state/useApp.js +22 -0
  673. package/state/vrm.d.ts +30 -0
  674. package/state/vrm.d.ts.map +1 -0
  675. package/state/vrm.js +82 -0
  676. package/styles/anime.css +6321 -0
  677. package/styles/onboarding-game.css +1092 -0
  678. package/types/index.d.ts +657 -0
  679. package/types/index.d.ts.map +1 -0
  680. package/types/index.js +1 -0
  681. package/utils/asset-url.d.ts +26 -0
  682. package/utils/asset-url.d.ts.map +1 -0
  683. package/utils/asset-url.js +99 -0
  684. package/utils/assistant-text.d.ts +2 -0
  685. package/utils/assistant-text.d.ts.map +1 -0
  686. package/utils/assistant-text.js +161 -0
  687. package/utils/clipboard.d.ts +2 -0
  688. package/utils/clipboard.d.ts.map +1 -0
  689. package/utils/clipboard.js +38 -0
  690. package/utils/desktop-dialogs.d.ts +19 -0
  691. package/utils/desktop-dialogs.d.ts.map +1 -0
  692. package/utils/desktop-dialogs.js +50 -0
  693. package/utils/eliza-globals.d.ts +11 -0
  694. package/utils/eliza-globals.d.ts.map +1 -0
  695. package/utils/eliza-globals.js +33 -0
  696. package/utils/index.d.ts +8 -0
  697. package/utils/index.d.ts.map +1 -0
  698. package/utils/number-parsing.d.ts +44 -0
  699. package/utils/number-parsing.d.ts.map +1 -0
  700. package/utils/number-parsing.js +56 -0
  701. package/utils/openExternalUrl.d.ts +2 -0
  702. package/utils/openExternalUrl.d.ts.map +1 -0
  703. package/utils/openExternalUrl.js +17 -0
  704. package/utils/spoken-text.d.ts +2 -0
  705. package/utils/spoken-text.d.ts.map +1 -0
  706. package/utils/spoken-text.js +56 -0
  707. package/utils/streaming-text.d.ts +3 -0
  708. package/utils/streaming-text.d.ts.map +1 -0
  709. package/utils/streaming-text.js +87 -0
  710. package/voice/index.d.ts +2 -0
  711. package/voice/index.d.ts.map +1 -0
  712. package/voice/types.d.ts +25 -0
  713. package/voice/types.d.ts.map +1 -0
  714. package/voice/types.js +166 -0
  715. package/wallet-rpc.d.ts +8 -0
  716. package/wallet-rpc.d.ts.map +1 -0
  717. package/wallet-rpc.js +131 -0
  718. package/.turbo/turbo-build.log +0 -5
  719. package/src/App.tsx +0 -504
  720. package/src/actions/character.test.ts +0 -139
  721. package/src/actions/character.ts +0 -334
  722. package/src/actions/chat-helpers.ts +0 -100
  723. package/src/actions/cloud.ts +0 -59
  724. package/src/actions/index.ts +0 -12
  725. package/src/actions/lifecycle.ts +0 -175
  726. package/src/actions/onboarding.ts +0 -38
  727. package/src/actions/triggers.ts +0 -190
  728. package/src/ambient.d.ts +0 -33
  729. package/src/api/client.ts +0 -5659
  730. package/src/autonomy/index.ts +0 -477
  731. package/src/bridge/capacitor-bridge.ts +0 -295
  732. package/src/bridge/electrobun-rpc.ts +0 -78
  733. package/src/bridge/electrobun-runtime.ts +0 -28
  734. package/src/bridge/native-plugins.ts +0 -138
  735. package/src/bridge/plugin-bridge.ts +0 -352
  736. package/src/bridge/storage-bridge.ts +0 -162
  737. package/src/chat/index.ts +0 -250
  738. package/src/coding/index.ts +0 -43
  739. package/src/components/AdvancedPageView.tsx +0 -382
  740. package/src/components/AgentActivityBox.tsx +0 -49
  741. package/src/components/ApiKeyConfig.tsx +0 -222
  742. package/src/components/AppsPageView.tsx +0 -52
  743. package/src/components/AppsView.tsx +0 -293
  744. package/src/components/AvatarLoader.tsx +0 -104
  745. package/src/components/AvatarSelector.tsx +0 -223
  746. package/src/components/BscTradePanel.tsx +0 -549
  747. package/src/components/BugReportModal.tsx +0 -499
  748. package/src/components/CharacterRoster.tsx +0 -143
  749. package/src/components/CharacterView.tsx +0 -1575
  750. package/src/components/ChatAvatar.test.ts +0 -97
  751. package/src/components/ChatAvatar.tsx +0 -147
  752. package/src/components/ChatComposer.tsx +0 -330
  753. package/src/components/ChatMessage.tsx +0 -448
  754. package/src/components/ChatModalView.test.tsx +0 -118
  755. package/src/components/ChatModalView.tsx +0 -125
  756. package/src/components/ChatView.tsx +0 -992
  757. package/src/components/CloudOnboarding.tsx +0 -81
  758. package/src/components/CloudSourceControls.tsx +0 -85
  759. package/src/components/CodingAgentSettingsSection.tsx +0 -537
  760. package/src/components/CommandPalette.tsx +0 -284
  761. package/src/components/CompanionSceneHost.tsx +0 -517
  762. package/src/components/CompanionShell.tsx +0 -31
  763. package/src/components/CompanionView.tsx +0 -110
  764. package/src/components/ConfigPageView.tsx +0 -763
  765. package/src/components/ConfigSaveFooter.tsx +0 -41
  766. package/src/components/ConfirmModal.tsx +0 -379
  767. package/src/components/ConnectionFailedBanner.tsx +0 -91
  768. package/src/components/ConnectorsPageView.tsx +0 -13
  769. package/src/components/ConversationsSidebar.tsx +0 -279
  770. package/src/components/CustomActionEditor.tsx +0 -1127
  771. package/src/components/CustomActionsPanel.tsx +0 -288
  772. package/src/components/CustomActionsView.tsx +0 -325
  773. package/src/components/DatabasePageView.tsx +0 -55
  774. package/src/components/DatabaseView.tsx +0 -814
  775. package/src/components/ElizaCloudDashboard.tsx +0 -1696
  776. package/src/components/EmotePicker.tsx +0 -529
  777. package/src/components/ErrorBoundary.tsx +0 -76
  778. package/src/components/FineTuningView.tsx +0 -1080
  779. package/src/components/FlaminaGuide.test.tsx +0 -61
  780. package/src/components/FlaminaGuide.tsx +0 -212
  781. package/src/components/GameView.tsx +0 -551
  782. package/src/components/GameViewOverlay.tsx +0 -133
  783. package/src/components/GlobalEmoteOverlay.tsx +0 -152
  784. package/src/components/Header.test.tsx +0 -413
  785. package/src/components/Header.tsx +0 -400
  786. package/src/components/HeartbeatsView.tsx +0 -1003
  787. package/src/components/InventoryView.tsx +0 -393
  788. package/src/components/KnowledgeView.tsx +0 -1128
  789. package/src/components/LanguageDropdown.tsx +0 -192
  790. package/src/components/LifoMonitorPanel.tsx +0 -196
  791. package/src/components/LifoSandboxView.tsx +0 -499
  792. package/src/components/LoadingScreen.tsx +0 -112
  793. package/src/components/LogsPageView.tsx +0 -17
  794. package/src/components/LogsView.tsx +0 -239
  795. package/src/components/MediaGalleryView.tsx +0 -431
  796. package/src/components/MediaSettingsSection.tsx +0 -893
  797. package/src/components/MessageContent.tsx +0 -815
  798. package/src/components/MiladyBar.tsx +0 -103
  799. package/src/components/MiladyBarSettings.tsx +0 -872
  800. package/src/components/OnboardingWizard.test.tsx +0 -104
  801. package/src/components/OnboardingWizard.tsx +0 -249
  802. package/src/components/PairingView.tsx +0 -109
  803. package/src/components/PermissionsSection.tsx +0 -1184
  804. package/src/components/PluginsPageView.tsx +0 -9
  805. package/src/components/PluginsView.tsx +0 -3129
  806. package/src/components/ProviderSwitcher.tsx +0 -903
  807. package/src/components/RestartBanner.tsx +0 -76
  808. package/src/components/RuntimeView.tsx +0 -460
  809. package/src/components/SaveCommandModal.tsx +0 -211
  810. package/src/components/SecretsView.tsx +0 -569
  811. package/src/components/SecurityPageView.tsx +0 -242
  812. package/src/components/SettingsView.tsx +0 -825
  813. package/src/components/ShellOverlays.tsx +0 -41
  814. package/src/components/ShortcutsOverlay.tsx +0 -155
  815. package/src/components/SkillsView.tsx +0 -1435
  816. package/src/components/StartupFailureView.tsx +0 -63
  817. package/src/components/StreamView.tsx +0 -481
  818. package/src/components/StripeEmbeddedCheckout.tsx +0 -155
  819. package/src/components/SubscriptionStatus.tsx +0 -640
  820. package/src/components/SystemWarningBanner.tsx +0 -71
  821. package/src/components/ThemeToggle.tsx +0 -103
  822. package/src/components/TrajectoriesView.tsx +0 -526
  823. package/src/components/TrajectoryDetailView.tsx +0 -426
  824. package/src/components/VectorBrowserView.tsx +0 -1633
  825. package/src/components/VoiceConfigView.tsx +0 -674
  826. package/src/components/VrmStage.test.ts +0 -176
  827. package/src/components/VrmStage.tsx +0 -309
  828. package/src/components/WhatsAppQrOverlay.tsx +0 -230
  829. package/src/components/__tests__/chainConfig.test.ts +0 -220
  830. package/src/components/apps/AppDetailPane.tsx +0 -242
  831. package/src/components/apps/AppsCatalogGrid.tsx +0 -137
  832. package/src/components/apps/extensions/registry.ts +0 -13
  833. package/src/components/apps/extensions/types.ts +0 -9
  834. package/src/components/apps/helpers.ts +0 -43
  835. package/src/components/avatar/VrmAnimationLoader.test.ts +0 -164
  836. package/src/components/avatar/VrmAnimationLoader.ts +0 -151
  837. package/src/components/avatar/VrmBlinkController.ts +0 -118
  838. package/src/components/avatar/VrmCameraManager.ts +0 -407
  839. package/src/components/avatar/VrmEngine.ts +0 -2767
  840. package/src/components/avatar/VrmFootShadow.ts +0 -96
  841. package/src/components/avatar/VrmViewer.tsx +0 -421
  842. package/src/components/avatar/__tests__/VrmCameraManager.test.ts +0 -168
  843. package/src/components/avatar/__tests__/VrmEngine.test.ts +0 -1574
  844. package/src/components/avatar/mixamoVRMRigMap.ts +0 -62
  845. package/src/components/avatar/retargetMixamoFbxToVrm.ts +0 -144
  846. package/src/components/avatar/retargetMixamoGltfToVrm.ts +0 -119
  847. package/src/components/chainConfig.ts +0 -400
  848. package/src/components/companion/CompanionHeader.tsx +0 -50
  849. package/src/components/companion/CompanionSceneHost.tsx +0 -5
  850. package/src/components/companion/VrmStage.tsx +0 -2
  851. package/src/components/companion/__tests__/walletUtils.test.ts +0 -742
  852. package/src/components/companion/index.ts +0 -18
  853. package/src/components/companion/walletUtils.ts +0 -290
  854. package/src/components/companion-shell-styles.test.ts +0 -142
  855. package/src/components/companion-shell-styles.ts +0 -270
  856. package/src/components/confirm-delete-control.tsx +0 -69
  857. package/src/components/conversations/ConversationListItem.tsx +0 -185
  858. package/src/components/conversations/conversation-utils.ts +0 -151
  859. package/src/components/format.ts +0 -131
  860. package/src/components/index.ts +0 -96
  861. package/src/components/inventory/CopyableAddress.tsx +0 -41
  862. package/src/components/inventory/InventoryToolbar.tsx +0 -142
  863. package/src/components/inventory/NftGrid.tsx +0 -99
  864. package/src/components/inventory/TokenLogo.tsx +0 -71
  865. package/src/components/inventory/TokensTable.tsx +0 -216
  866. package/src/components/inventory/constants.ts +0 -170
  867. package/src/components/inventory/index.ts +0 -29
  868. package/src/components/inventory/media-url.test.ts +0 -38
  869. package/src/components/inventory/media-url.ts +0 -36
  870. package/src/components/inventory/useInventoryData.ts +0 -460
  871. package/src/components/knowledge-upload-image.ts +0 -215
  872. package/src/components/labels.ts +0 -46
  873. package/src/components/milady-bar/CloudCreditsChip.tsx +0 -61
  874. package/src/components/milady-bar/ProviderDropdown.tsx +0 -166
  875. package/src/components/milady-bar/WalletSummary.tsx +0 -61
  876. package/src/components/milady-bar/index.ts +0 -3
  877. package/src/components/onboarding/ActivateStep.tsx +0 -34
  878. package/src/components/onboarding/ConnectionStep.tsx +0 -1591
  879. package/src/components/onboarding/IdentityStep.tsx +0 -251
  880. package/src/components/onboarding/OnboardingPanel.tsx +0 -39
  881. package/src/components/onboarding/OnboardingStepNav.tsx +0 -41
  882. package/src/components/onboarding/PermissionsStep.tsx +0 -20
  883. package/src/components/onboarding/RpcStep.tsx +0 -402
  884. package/src/components/permissions/PermissionIcon.tsx +0 -25
  885. package/src/components/permissions/StreamingPermissions.tsx +0 -413
  886. package/src/components/plugins/showcase-data.ts +0 -481
  887. package/src/components/shared/ShellHeaderControls.tsx +0 -198
  888. package/src/components/shared-companion-scene-context.ts +0 -15
  889. package/src/components/skeletons.tsx +0 -88
  890. package/src/components/stream/ActivityFeed.tsx +0 -113
  891. package/src/components/stream/AvatarPip.tsx +0 -10
  892. package/src/components/stream/ChatContent.tsx +0 -126
  893. package/src/components/stream/ChatTicker.tsx +0 -55
  894. package/src/components/stream/IdleContent.tsx +0 -73
  895. package/src/components/stream/StatusBar.tsx +0 -463
  896. package/src/components/stream/StreamSettings.tsx +0 -506
  897. package/src/components/stream/StreamTerminal.tsx +0 -94
  898. package/src/components/stream/StreamVoiceConfig.tsx +0 -160
  899. package/src/components/stream/helpers.ts +0 -134
  900. package/src/components/stream/overlays/OverlayLayer.tsx +0 -75
  901. package/src/components/stream/overlays/built-in/ActionTickerWidget.tsx +0 -64
  902. package/src/components/stream/overlays/built-in/AlertPopupWidget.tsx +0 -87
  903. package/src/components/stream/overlays/built-in/BrandingWidget.tsx +0 -51
  904. package/src/components/stream/overlays/built-in/CustomHtmlWidget.tsx +0 -105
  905. package/src/components/stream/overlays/built-in/PeonGlassWidget.tsx +0 -265
  906. package/src/components/stream/overlays/built-in/PeonHudWidget.tsx +0 -247
  907. package/src/components/stream/overlays/built-in/PeonSakuraWidget.tsx +0 -278
  908. package/src/components/stream/overlays/built-in/ThoughtBubbleWidget.tsx +0 -77
  909. package/src/components/stream/overlays/built-in/ViewerCountWidget.tsx +0 -46
  910. package/src/components/stream/overlays/built-in/index.ts +0 -13
  911. package/src/components/stream/overlays/registry.ts +0 -22
  912. package/src/components/stream/overlays/types.ts +0 -90
  913. package/src/components/stream/overlays/useOverlayLayout.ts +0 -218
  914. package/src/components/trajectory-format.ts +0 -50
  915. package/src/components/ui-badges.tsx +0 -109
  916. package/src/components/ui-switch.tsx +0 -57
  917. package/src/components/vector-browser-three.ts +0 -29
  918. package/src/config/branding.ts +0 -67
  919. package/src/config/config-catalog.ts +0 -1092
  920. package/src/config/config-field.tsx +0 -1924
  921. package/src/config/config-renderer.tsx +0 -734
  922. package/src/config/index.ts +0 -12
  923. package/src/config/ui-renderer.tsx +0 -1751
  924. package/src/config/ui-spec.ts +0 -256
  925. package/src/events/index.ts +0 -96
  926. package/src/hooks/useBugReport.tsx +0 -43
  927. package/src/hooks/useCanvasWindow.ts +0 -372
  928. package/src/hooks/useChatAvatarVoice.ts +0 -111
  929. package/src/hooks/useClickOutside.ts +0 -31
  930. package/src/hooks/useContextMenu.ts +0 -127
  931. package/src/hooks/useKeyboardShortcuts.ts +0 -86
  932. package/src/hooks/useLifoSync.ts +0 -143
  933. package/src/hooks/useMemoryMonitor.ts +0 -334
  934. package/src/hooks/useMiladyBar.ts +0 -594
  935. package/src/hooks/useRenderGuard.ts +0 -43
  936. package/src/hooks/useRetakeCapture.ts +0 -68
  937. package/src/hooks/useStreamPopoutNavigation.ts +0 -27
  938. package/src/hooks/useTimeout.ts +0 -37
  939. package/src/hooks/useVoiceChat.ts +0 -1442
  940. package/src/hooks/useWhatsAppPairing.ts +0 -123
  941. package/src/i18n/index.ts +0 -76
  942. package/src/i18n/locales/en.json +0 -1195
  943. package/src/i18n/locales/es.json +0 -1195
  944. package/src/i18n/locales/ko.json +0 -1195
  945. package/src/i18n/locales/pt.json +0 -1195
  946. package/src/i18n/locales/zh-CN.json +0 -1195
  947. package/src/i18n/messages.ts +0 -21
  948. package/src/navigation/index.ts +0 -286
  949. package/src/navigation.test.ts +0 -189
  950. package/src/onboarding-config.test.ts +0 -104
  951. package/src/onboarding-config.ts +0 -122
  952. package/src/platform/browser-launch.test.ts +0 -94
  953. package/src/platform/browser-launch.ts +0 -149
  954. package/src/platform/index.ts +0 -58
  955. package/src/platform/init.ts +0 -238
  956. package/src/platform/lifo.ts +0 -225
  957. package/src/providers/index.ts +0 -108
  958. package/src/shell-params.test.ts +0 -48
  959. package/src/shell-params.ts +0 -36
  960. package/src/state/AppContext.tsx +0 -6415
  961. package/src/state/internal.ts +0 -91
  962. package/src/state/onboarding-resume.test.ts +0 -135
  963. package/src/state/onboarding-resume.ts +0 -263
  964. package/src/state/parsers.test.ts +0 -124
  965. package/src/state/parsers.ts +0 -309
  966. package/src/state/persistence.ts +0 -379
  967. package/src/state/shell-routing.ts +0 -39
  968. package/src/state/types.ts +0 -724
  969. package/src/state/ui-preferences.ts +0 -3
  970. package/src/state/useApp.ts +0 -23
  971. package/src/state/vrm.ts +0 -108
  972. package/src/styles/anime.css +0 -6324
  973. package/src/styles/onboarding-game.css +0 -976
  974. package/src/types/index.ts +0 -715
  975. package/src/types/react-test-renderer.d.ts +0 -45
  976. package/src/utils/asset-url.ts +0 -110
  977. package/src/utils/assistant-text.ts +0 -172
  978. package/src/utils/clipboard.ts +0 -41
  979. package/src/utils/desktop-dialogs.ts +0 -80
  980. package/src/utils/eliza-globals.ts +0 -44
  981. package/src/utils/number-parsing.ts +0 -125
  982. package/src/utils/openExternalUrl.ts +0 -20
  983. package/src/utils/spoken-text.ts +0 -65
  984. package/src/utils/streaming-text.ts +0 -120
  985. package/src/voice/types.ts +0 -197
  986. package/src/wallet-rpc.ts +0 -176
  987. package/test/app/AppContext.pty-sessions.test.tsx +0 -143
  988. package/test/app/MessageContent.test.tsx +0 -366
  989. package/test/app/PermissionsOnboarding.test.tsx +0 -358
  990. package/test/app/PermissionsSection.test.tsx +0 -575
  991. package/test/app/advanced-trajectory-fine-tuning.e2e.test.ts +0 -396
  992. package/test/app/agent-activity-box.test.tsx +0 -132
  993. package/test/app/agent-transfer-lock.test.ts +0 -279
  994. package/test/app/api-client-electrobun-fallback.test.ts +0 -139
  995. package/test/app/api-client-electron-fallback.test.ts +0 -139
  996. package/test/app/api-client-timeout.test.ts +0 -75
  997. package/test/app/api-client-ws.test.ts +0 -98
  998. package/test/app/api-client.ws-max-reconnect.test.ts +0 -139
  999. package/test/app/api-client.ws-reconnect.test.ts +0 -157
  1000. package/test/app/app-context-autonomy-events.test.ts +0 -559
  1001. package/test/app/apps-page-view.test.ts +0 -114
  1002. package/test/app/apps-view.test.ts +0 -768
  1003. package/test/app/autonomous-workflows.e2e.test.ts +0 -765
  1004. package/test/app/autonomy-events.test.ts +0 -150
  1005. package/test/app/avatar-selector.test.tsx +0 -52
  1006. package/test/app/bsc-trade-panel.test.tsx +0 -134
  1007. package/test/app/bug-report-modal.test.tsx +0 -353
  1008. package/test/app/character-action-bar-visibility.test.ts +0 -70
  1009. package/test/app/character-customization.e2e.test.ts +0 -1384
  1010. package/test/app/character-save-journey.test.ts +0 -1245
  1011. package/test/app/chat-advanced-features.e2e.test.ts +0 -706
  1012. package/test/app/chat-composer.test.tsx +0 -181
  1013. package/test/app/chat-journey.test.ts +0 -1075
  1014. package/test/app/chat-language-header.test.ts +0 -64
  1015. package/test/app/chat-message.test.tsx +0 -222
  1016. package/test/app/chat-modal-view.test.tsx +0 -191
  1017. package/test/app/chat-routine-filter.test.ts +0 -96
  1018. package/test/app/chat-send-lock.test.ts +0 -1465
  1019. package/test/app/chat-stream-api-client.test.tsx +0 -390
  1020. package/test/app/chat-view-game-modal.test.tsx +0 -661
  1021. package/test/app/chat-view.test.tsx +0 -877
  1022. package/test/app/cloud-api.e2e.test.ts +0 -258
  1023. package/test/app/cloud-login-flow.e2e.test.ts +0 -494
  1024. package/test/app/cloud-login-lock.test.ts +0 -416
  1025. package/test/app/command-palette.test.tsx +0 -184
  1026. package/test/app/command-registry.test.ts +0 -75
  1027. package/test/app/companion-greeting-wave.test.tsx +0 -431
  1028. package/test/app/companion-scene-host.test.tsx +0 -85
  1029. package/test/app/companion-stale-conversation.test.tsx +0 -447
  1030. package/test/app/companion-view.test.tsx +0 -690
  1031. package/test/app/confirm-delete-control.test.ts +0 -79
  1032. package/test/app/confirm-modal.test.tsx +0 -219
  1033. package/test/app/connection-mode-persistence.test.ts +0 -411
  1034. package/test/app/connectors-ui.e2e.test.ts +0 -508
  1035. package/test/app/conversations-sidebar-game-modal.test.tsx +0 -265
  1036. package/test/app/conversations-sidebar.test.tsx +0 -185
  1037. package/test/app/custom-actions-smoke.test.ts +0 -387
  1038. package/test/app/custom-avatar-api-client.test.ts +0 -207
  1039. package/test/app/desktop-utils.test.ts +0 -145
  1040. package/test/app/electrobun-rpc-bridge.test.ts +0 -83
  1041. package/test/app/events.test.ts +0 -88
  1042. package/test/app/export-import-flows.e2e.test.ts +0 -700
  1043. package/test/app/fine-tuning-view.test.ts +0 -471
  1044. package/test/app/game-view-auth-session.test.tsx +0 -187
  1045. package/test/app/game-view.test.ts +0 -444
  1046. package/test/app/global-emote-overlay.test.tsx +0 -106
  1047. package/test/app/header-status.test.tsx +0 -149
  1048. package/test/app/i18n.test.ts +0 -152
  1049. package/test/app/inventory-bsc-view.test.ts +0 -940
  1050. package/test/app/knowledge-ui.e2e.test.ts +0 -762
  1051. package/test/app/knowledge-upload-helpers.test.ts +0 -124
  1052. package/test/app/lifecycle-lock.test.ts +0 -267
  1053. package/test/app/lifo-popout-utils.test.ts +0 -208
  1054. package/test/app/lifo-safe-endpoint.test.ts +0 -34
  1055. package/test/app/loading-screen.test.tsx +0 -45
  1056. package/test/app/memory-monitor.test.ts +0 -331
  1057. package/test/app/milady-bar-regression.test.tsx +0 -519
  1058. package/test/app/milady-bar-settings.test.tsx +0 -1056
  1059. package/test/app/milady-bar.test.tsx +0 -583
  1060. package/test/app/navigation.test.tsx +0 -22
  1061. package/test/app/onboarding-e2e-journey.test.ts +0 -1409
  1062. package/test/app/onboarding-finish-lock.test.ts +0 -676
  1063. package/test/app/onboarding-language.test.tsx +0 -160
  1064. package/test/app/onboarding-steps.test.tsx +0 -375
  1065. package/test/app/open-external-url.test.ts +0 -65
  1066. package/test/app/pages-navigation-smoke.e2e.test.ts +0 -646
  1067. package/test/app/pairing-lock.test.ts +0 -260
  1068. package/test/app/pairing-view.test.tsx +0 -74
  1069. package/test/app/permissions-section.test.ts +0 -432
  1070. package/test/app/plugin-bridge.test.ts +0 -109
  1071. package/test/app/plugins-ui.e2e.test.ts +0 -605
  1072. package/test/app/plugins-view-game-modal.test.tsx +0 -686
  1073. package/test/app/plugins-view-toggle-restart.test.ts +0 -129
  1074. package/test/app/provider-dropdown-default.test.tsx +0 -300
  1075. package/test/app/restart-banner.test.tsx +0 -205
  1076. package/test/app/retake-capture.test.ts +0 -84
  1077. package/test/app/sandbox-api-client.test.ts +0 -108
  1078. package/test/app/save-command-modal.test.tsx +0 -109
  1079. package/test/app/secrets-view.test.tsx +0 -92
  1080. package/test/app/settings-control-styles.test.tsx +0 -142
  1081. package/test/app/settings-reset.e2e.test.ts +0 -726
  1082. package/test/app/settings-sections.e2e.test.ts +0 -614
  1083. package/test/app/shared-format.test.ts +0 -44
  1084. package/test/app/shared-switch.test.ts +0 -69
  1085. package/test/app/shell-mode-switching.e2e.test.ts +0 -841
  1086. package/test/app/shell-mode-tab-memory.test.tsx +0 -58
  1087. package/test/app/shell-overlays.test.tsx +0 -50
  1088. package/test/app/shortcuts-overlay.test.tsx +0 -111
  1089. package/test/app/sse-interruption.test.ts +0 -122
  1090. package/test/app/startup-asset-missing.e2e.test.ts +0 -126
  1091. package/test/app/startup-backend-missing.e2e.test.ts +0 -126
  1092. package/test/app/startup-chat.e2e.test.ts +0 -323
  1093. package/test/app/startup-conversation-restore.test.tsx +0 -381
  1094. package/test/app/startup-failure-view.test.tsx +0 -103
  1095. package/test/app/startup-onboarding.e2e.test.ts +0 -712
  1096. package/test/app/startup-timeout.test.tsx +0 -80
  1097. package/test/app/startup-token-401.e2e.test.ts +0 -103
  1098. package/test/app/stream-helpers.test.ts +0 -46
  1099. package/test/app/stream-popout-navigation.test.tsx +0 -41
  1100. package/test/app/stream-status-bar.test.tsx +0 -89
  1101. package/test/app/theme-toggle.test.tsx +0 -40
  1102. package/test/app/training-api-client.test.ts +0 -128
  1103. package/test/app/trajectories-view.test.tsx +0 -220
  1104. package/test/app/triggers-api-client.test.ts +0 -77
  1105. package/test/app/triggers-navigation.test.ts +0 -113
  1106. package/test/app/triggers-view.e2e.test.ts +0 -675
  1107. package/test/app/update-channel-lock.test.ts +0 -259
  1108. package/test/app/vector-browser.async-cleanup.test.tsx +0 -367
  1109. package/test/app/vector-browser.e2e.test.ts +0 -653
  1110. package/test/app/vrm-stage.test.tsx +0 -351
  1111. package/test/app/vrm-viewer.test.tsx +0 -298
  1112. package/test/app/wallet-api-save-lock.test.ts +0 -299
  1113. package/test/app/wallet-hooks.test.ts +0 -405
  1114. package/test/app/wallet-ui-flows.e2e.test.ts +0 -556
  1115. package/test/avatar/asset-url.test.ts +0 -90
  1116. package/test/avatar/avatar-selector.test.ts +0 -173
  1117. package/test/avatar/mixamo-vrm-rig-map.test.ts +0 -111
  1118. package/test/avatar/voice-chat-streaming-text.test.ts +0 -96
  1119. package/test/avatar/voice-chat.test.ts +0 -391
  1120. package/test/browser-extension/README.md +0 -138
  1121. package/test/browser-extension/test-harness.ts +0 -499
  1122. package/test/capacitor-plugins.e2e.test.ts +0 -168
  1123. package/test/test-types.ts +0 -5
  1124. package/test/ui/command-palette-commands.test.ts +0 -57
  1125. package/test/ui/ui-renderer.test.ts +0 -39
  1126. package/test/utils/assistant-text.test.ts +0 -68
  1127. package/test/utils/eliza-globals.test.ts +0 -59
  1128. package/test/utils/package-exports.test.ts +0 -70
  1129. package/test/utils/streaming-text.test.ts +0 -89
  1130. package/tsconfig.build.json +0 -19
  1131. package/tsconfig.json +0 -20
  1132. package/tsconfig.typecheck.json +0 -12
  1133. /package/{src/api/index.ts → api/index.js} +0 -0
  1134. /package/{src/bridge/index.ts → bridge/index.js} +0 -0
  1135. /package/{src/components/TriggersView.tsx → components/TriggersView.js} +0 -0
  1136. /package/{src/hooks/index.ts → hooks/index.js} +0 -0
  1137. /package/{src/index.ts → index.js} +0 -0
  1138. /package/{src/state/index.ts → state/index.js} +0 -0
  1139. /package/{src/styles → styles}/base.css +0 -0
  1140. /package/{src/styles → styles}/styles.css +0 -0
  1141. /package/{src/styles → styles}/xterm.css +0 -0
  1142. /package/{src/utils/index.ts → utils/index.js} +0 -0
  1143. /package/{src/voice/index.ts → voice/index.js} +0 -0
package/api/client.js ADDED
@@ -0,0 +1,2492 @@
1
+ /**
2
+ * API client for the Milady backend.
3
+ *
4
+ * Thin fetch wrapper + WebSocket for real-time chat/events.
5
+ * Replaces the gateway WebSocket protocol entirely.
6
+ */
7
+ import { DEFAULT_WALLET_RPC_SELECTIONS, normalizeWalletRpcProviderId, normalizeWalletRpcSelections, WALLET_RPC_PROVIDER_OPTIONS, } from "@elizaos/autonomous/contracts/wallet";
8
+ import { stripAssistantStageDirections } from "../utils/assistant-text";
9
+ import { mergeStreamingText } from "../utils/streaming-text";
10
+ export { DEFAULT_WALLET_RPC_SELECTIONS, normalizeWalletRpcProviderId, normalizeWalletRpcSelections, WALLET_RPC_PROVIDER_OPTIONS, };
11
+ export class ApiError extends Error {
12
+ kind;
13
+ status;
14
+ path;
15
+ constructor(options) {
16
+ super(options.message);
17
+ this.name = "ApiError";
18
+ this.kind = options.kind;
19
+ this.path = options.path;
20
+ this.status = options.status;
21
+ if (options.cause !== undefined) {
22
+ this.cause = options.cause;
23
+ }
24
+ }
25
+ }
26
+ export function isApiError(value) {
27
+ return value instanceof ApiError;
28
+ }
29
+ // ---------------------------------------------------------------------------
30
+ // Client
31
+ // ---------------------------------------------------------------------------
32
+ const GENERIC_NO_RESPONSE_TEXT = "Sorry, I couldn't generate a response right now. Please try again.";
33
+ const AGENT_TRANSFER_MIN_PASSWORD_LENGTH = 4;
34
+ const DEFAULT_FETCH_TIMEOUT_MS = 10_000;
35
+ const SESSION_STORAGE_API_BASE_KEY = "milady_api_base";
36
+ const SESSION_STORAGE_API_TOKEN_KEY = "milady_api_token";
37
+ export class MiladyClient {
38
+ _baseUrl;
39
+ _explicitBase;
40
+ _token;
41
+ clientId;
42
+ ws = null;
43
+ wsHandlers = new Map();
44
+ wsSendQueue = [];
45
+ wsSendQueueLimit = 32;
46
+ reconnectTimer = null;
47
+ backoffMs = 500;
48
+ wsHasConnectedOnce = false;
49
+ // Connection state tracking for backend crash handling
50
+ connectionState = "disconnected";
51
+ reconnectAttempt = 0;
52
+ disconnectedAt = null;
53
+ connectionStateListeners = new Set();
54
+ maxReconnectAttempts = 15;
55
+ // UI language propagation — set by AppContext so the backend can
56
+ // localise responses when needed.
57
+ _uiLanguage = null;
58
+ /** Store the current UI language so it can be sent as a header on every request. */
59
+ setUiLanguage(lang) {
60
+ this._uiLanguage = lang || null;
61
+ }
62
+ static resolveDesktopLocalFallbackBase() {
63
+ if (typeof window === "undefined")
64
+ return "";
65
+ const proto = window.location.protocol;
66
+ // In the desktop shell the main process injects the live API base
67
+ // once the embedded agent has bound a port. Avoid eager localhost probes
68
+ // to prevent noisy ERR_CONNECTION_REFUSED logs during startup.
69
+ if (proto === "electrobun:")
70
+ return "";
71
+ if (proto === "file:") {
72
+ return "http://localhost:2138";
73
+ }
74
+ return "";
75
+ }
76
+ static generateClientId() {
77
+ const random = typeof globalThis.crypto?.randomUUID === "function"
78
+ ? globalThis.crypto.randomUUID()
79
+ : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
80
+ return `ui-${random.replace(/[^a-zA-Z0-9._-]/g, "")}`;
81
+ }
82
+ constructor(baseUrl, token) {
83
+ this.clientId = MiladyClient.generateClientId();
84
+ const stored = typeof window !== "undefined"
85
+ ? window.sessionStorage.getItem(SESSION_STORAGE_API_TOKEN_KEY)
86
+ : null;
87
+ const storedBase = typeof window !== "undefined"
88
+ ? window.sessionStorage.getItem(SESSION_STORAGE_API_BASE_KEY)
89
+ : null;
90
+ this._explicitBase = baseUrl != null || Boolean(storedBase?.trim());
91
+ this._token = token?.trim() || stored || null;
92
+ // Priority: explicit arg > desktop-injected global > same origin (Vite proxy)
93
+ const injectedBase = typeof window !== "undefined" ? window.__MILADY_API_BASE__ : undefined;
94
+ this._baseUrl =
95
+ baseUrl ??
96
+ storedBase ??
97
+ injectedBase ??
98
+ MiladyClient.resolveDesktopLocalFallbackBase();
99
+ }
100
+ /**
101
+ * Resolve the API base URL lazily.
102
+ * In the desktop shell the main process injects window.__MILADY_API_BASE__ after the
103
+ * page loads (once the agent runtime starts). Re-checking on every call
104
+ * ensures we pick up the injected value even if it wasn't set at construction.
105
+ */
106
+ get baseUrl() {
107
+ if (!this._explicitBase && typeof window !== "undefined") {
108
+ const injected = window.__MILADY_API_BASE__;
109
+ // In the desktop shell the API base can be injected after initial render. Always
110
+ // prefer the injected value when present so the client can switch away
111
+ // from the localhost fallback once the main process publishes the real
112
+ // endpoint.
113
+ if (injected && injected !== this._baseUrl) {
114
+ this._baseUrl = injected;
115
+ }
116
+ else if (!this._baseUrl) {
117
+ this._baseUrl = MiladyClient.resolveDesktopLocalFallbackBase();
118
+ }
119
+ }
120
+ return this._baseUrl;
121
+ }
122
+ get apiToken() {
123
+ if (this._token)
124
+ return this._token;
125
+ if (typeof window === "undefined")
126
+ return null;
127
+ const injected = window.__MILADY_API_TOKEN__;
128
+ if (typeof injected === "string" && injected.trim())
129
+ return injected.trim();
130
+ return null;
131
+ }
132
+ hasToken() {
133
+ return Boolean(this.apiToken);
134
+ }
135
+ setToken(token) {
136
+ this._token = token?.trim() || null;
137
+ if (typeof window !== "undefined") {
138
+ if (this._token) {
139
+ window.__MILADY_API_TOKEN__ = this._token;
140
+ window.sessionStorage.setItem(SESSION_STORAGE_API_TOKEN_KEY, this._token);
141
+ }
142
+ else {
143
+ delete window.__MILADY_API_TOKEN__;
144
+ window.sessionStorage.removeItem(SESSION_STORAGE_API_TOKEN_KEY);
145
+ }
146
+ }
147
+ }
148
+ getBaseUrl() {
149
+ return this.baseUrl;
150
+ }
151
+ setBaseUrl(baseUrl) {
152
+ const normalized = baseUrl?.trim().replace(/\/+$/, "") || "";
153
+ this._explicitBase = normalized.length > 0;
154
+ this._baseUrl = normalized;
155
+ this.disconnectWs();
156
+ if (typeof window !== "undefined") {
157
+ if (normalized) {
158
+ window.__MILADY_API_BASE__ = normalized;
159
+ window.sessionStorage.setItem(SESSION_STORAGE_API_BASE_KEY, normalized);
160
+ }
161
+ else {
162
+ delete window.__MILADY_API_BASE__;
163
+ window.sessionStorage.removeItem(SESSION_STORAGE_API_BASE_KEY);
164
+ }
165
+ }
166
+ }
167
+ /** True when we have a usable HTTP(S) API endpoint. */
168
+ get apiAvailable() {
169
+ if (this.baseUrl)
170
+ return true;
171
+ if (typeof window !== "undefined") {
172
+ const proto = window.location.protocol;
173
+ return proto === "http:" || proto === "https:";
174
+ }
175
+ return false;
176
+ }
177
+ // --- REST API ---
178
+ async rawRequest(path, init, options) {
179
+ if (!this.apiAvailable) {
180
+ throw new ApiError({
181
+ kind: "network",
182
+ path,
183
+ message: "API not available (no HTTP origin)",
184
+ });
185
+ }
186
+ const makeRequest = async (token) => {
187
+ let timeoutId;
188
+ let abortListener;
189
+ const requestInit = {
190
+ ...init,
191
+ headers: {
192
+ "X-Milady-Client-Id": this.clientId,
193
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
194
+ ...(this._uiLanguage
195
+ ? { "X-Milady-UI-Language": this._uiLanguage }
196
+ : {}),
197
+ ...init?.headers,
198
+ },
199
+ };
200
+ const fetchPromise = fetch(`${this.baseUrl}${path}`, requestInit);
201
+ const pending = [fetchPromise];
202
+ pending.push(new Promise((_, reject) => {
203
+ timeoutId = setTimeout(() => {
204
+ reject(new ApiError({
205
+ kind: "timeout",
206
+ path,
207
+ message: `Request timed out after ${DEFAULT_FETCH_TIMEOUT_MS}ms`,
208
+ }));
209
+ }, DEFAULT_FETCH_TIMEOUT_MS);
210
+ }));
211
+ if (init?.signal) {
212
+ if (init.signal.aborted) {
213
+ throw new ApiError({
214
+ kind: "network",
215
+ path,
216
+ message: "Request aborted",
217
+ });
218
+ }
219
+ pending.push(new Promise((_, reject) => {
220
+ abortListener = () => {
221
+ reject(new ApiError({
222
+ kind: "network",
223
+ path,
224
+ message: "Request aborted",
225
+ }));
226
+ };
227
+ init.signal?.addEventListener("abort", abortListener, {
228
+ once: true,
229
+ });
230
+ }));
231
+ }
232
+ try {
233
+ return await Promise.race(pending);
234
+ }
235
+ catch (err) {
236
+ if (err instanceof ApiError) {
237
+ throw err;
238
+ }
239
+ throw new ApiError({
240
+ kind: "network",
241
+ path,
242
+ message: err instanceof Error && err.message
243
+ ? err.message
244
+ : "Network request failed",
245
+ cause: err,
246
+ });
247
+ }
248
+ finally {
249
+ if (timeoutId !== undefined) {
250
+ clearTimeout(timeoutId);
251
+ }
252
+ if (init?.signal && abortListener) {
253
+ init.signal.removeEventListener("abort", abortListener);
254
+ }
255
+ }
256
+ };
257
+ const token = this.apiToken;
258
+ let res = await makeRequest(token);
259
+ if (res.status === 401 && !token) {
260
+ const retryToken = this.apiToken;
261
+ if (retryToken) {
262
+ res = await makeRequest(retryToken);
263
+ }
264
+ }
265
+ if (!res.ok && !options?.allowNonOk) {
266
+ const body = (await res
267
+ .json()
268
+ .catch(() => ({ error: res.statusText })));
269
+ throw new ApiError({
270
+ kind: "http",
271
+ path,
272
+ status: res.status,
273
+ message: body.error ?? `HTTP ${res.status}`,
274
+ });
275
+ }
276
+ return res;
277
+ }
278
+ async fetch(path, init) {
279
+ const res = await this.rawRequest(path, {
280
+ ...init,
281
+ headers: {
282
+ "Content-Type": "application/json",
283
+ ...init?.headers,
284
+ },
285
+ });
286
+ return res.json();
287
+ }
288
+ async getStatus() {
289
+ return this.fetch("/api/status");
290
+ }
291
+ async getAgentSelfStatus() {
292
+ return this.fetch("/api/agent/self-status");
293
+ }
294
+ async getRuntimeSnapshot(opts) {
295
+ const params = new URLSearchParams();
296
+ if (typeof opts?.depth === "number")
297
+ params.set("depth", String(opts.depth));
298
+ if (typeof opts?.maxArrayLength === "number") {
299
+ params.set("maxArrayLength", String(opts.maxArrayLength));
300
+ }
301
+ if (typeof opts?.maxObjectEntries === "number") {
302
+ params.set("maxObjectEntries", String(opts.maxObjectEntries));
303
+ }
304
+ if (typeof opts?.maxStringLength === "number") {
305
+ params.set("maxStringLength", String(opts.maxStringLength));
306
+ }
307
+ const qs = params.toString();
308
+ return this.fetch(`/api/runtime${qs ? `?${qs}` : ""}`);
309
+ }
310
+ async setAutomationMode(mode) {
311
+ return this.fetch("/api/permissions/automation-mode", {
312
+ method: "PUT",
313
+ body: JSON.stringify({ mode }),
314
+ });
315
+ }
316
+ async setTradeMode(mode) {
317
+ return this.fetch("/api/permissions/trade-mode", {
318
+ method: "PUT",
319
+ body: JSON.stringify({ mode }),
320
+ });
321
+ }
322
+ async playEmote(emoteId) {
323
+ return this.fetch("/api/emote", {
324
+ method: "POST",
325
+ body: JSON.stringify({ emoteId }),
326
+ });
327
+ }
328
+ async runTerminalCommand(command) {
329
+ return this.fetch("/api/terminal/run", {
330
+ method: "POST",
331
+ body: JSON.stringify({ command }),
332
+ });
333
+ }
334
+ async getOnboardingStatus() {
335
+ return this.fetch("/api/onboarding/status");
336
+ }
337
+ async getAuthStatus() {
338
+ // Retry with exponential backoff — the server may not be ready during boot.
339
+ const maxRetries = 3;
340
+ const baseBackoffMs = 1000;
341
+ let lastErr;
342
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
343
+ try {
344
+ return await this.fetch("/api/auth/status");
345
+ }
346
+ catch (err) {
347
+ const status = err?.status;
348
+ if (status === 401) {
349
+ return { required: true, pairingEnabled: false, expiresAt: null };
350
+ }
351
+ if (status === 404) {
352
+ return { required: false, pairingEnabled: false, expiresAt: null };
353
+ }
354
+ lastErr = err;
355
+ const kind = err?.kind;
356
+ if (kind === "timeout" && attempt < maxRetries) {
357
+ await new Promise((r) => setTimeout(r, baseBackoffMs * 2 ** attempt));
358
+ continue;
359
+ }
360
+ if (attempt >= maxRetries)
361
+ break;
362
+ }
363
+ }
364
+ throw lastErr;
365
+ }
366
+ async pair(code) {
367
+ const res = await this.fetch("/api/auth/pair", {
368
+ method: "POST",
369
+ body: JSON.stringify({ code }),
370
+ });
371
+ return res;
372
+ }
373
+ async getOnboardingOptions() {
374
+ return this.fetch("/api/onboarding/options");
375
+ }
376
+ async submitOnboarding(data) {
377
+ await this.fetch("/api/onboarding", {
378
+ method: "POST",
379
+ body: JSON.stringify(data),
380
+ });
381
+ }
382
+ async startAnthropicLogin() {
383
+ return this.fetch("/api/subscription/anthropic/start", { method: "POST" });
384
+ }
385
+ async exchangeAnthropicCode(code) {
386
+ return this.fetch("/api/subscription/anthropic/exchange", {
387
+ method: "POST",
388
+ headers: { "Content-Type": "application/json" },
389
+ body: JSON.stringify({ code }),
390
+ });
391
+ }
392
+ async submitAnthropicSetupToken(token) {
393
+ return this.fetch("/api/subscription/anthropic/setup-token", {
394
+ method: "POST",
395
+ headers: { "Content-Type": "application/json" },
396
+ body: JSON.stringify({ token }),
397
+ });
398
+ }
399
+ async getSubscriptionStatus() {
400
+ return this.fetch("/api/subscription/status");
401
+ }
402
+ async deleteSubscription(provider) {
403
+ return this.fetch(`/api/subscription/${encodeURIComponent(provider)}`, {
404
+ method: "DELETE",
405
+ });
406
+ }
407
+ async switchProvider(provider, apiKey) {
408
+ return this.fetch("/api/provider/switch", {
409
+ method: "POST",
410
+ headers: { "Content-Type": "application/json" },
411
+ body: JSON.stringify({ provider, ...(apiKey ? { apiKey } : {}) }),
412
+ });
413
+ }
414
+ async startOpenAILogin() {
415
+ return this.fetch("/api/subscription/openai/start", { method: "POST" });
416
+ }
417
+ async exchangeOpenAICode(code) {
418
+ return this.fetch("/api/subscription/openai/exchange", {
419
+ method: "POST",
420
+ headers: { "Content-Type": "application/json" },
421
+ body: JSON.stringify({ code }),
422
+ });
423
+ }
424
+ async getSandboxPlatform() {
425
+ return this.fetch("/api/sandbox/platform");
426
+ }
427
+ async getSandboxBrowser() {
428
+ return this.fetch("/api/sandbox/browser");
429
+ }
430
+ async getSandboxScreenshot(region) {
431
+ if (!region) {
432
+ return this.fetch("/api/sandbox/screen/screenshot", {
433
+ method: "POST",
434
+ });
435
+ }
436
+ return this.fetch("/api/sandbox/screen/screenshot", {
437
+ method: "POST",
438
+ headers: { "Content-Type": "application/json" },
439
+ body: JSON.stringify(region),
440
+ });
441
+ }
442
+ async getSandboxWindows() {
443
+ return this.fetch("/api/sandbox/screen/windows");
444
+ }
445
+ async startDocker() {
446
+ return this.fetch("/api/sandbox/docker/start", { method: "POST" });
447
+ }
448
+ async startAgent() {
449
+ const res = await this.fetch("/api/agent/start", {
450
+ method: "POST",
451
+ });
452
+ return res.status;
453
+ }
454
+ async stopAgent() {
455
+ const res = await this.fetch("/api/agent/stop", {
456
+ method: "POST",
457
+ });
458
+ return res.status;
459
+ }
460
+ async pauseAgent() {
461
+ const res = await this.fetch("/api/agent/pause", {
462
+ method: "POST",
463
+ });
464
+ return res.status;
465
+ }
466
+ async resumeAgent() {
467
+ const res = await this.fetch("/api/agent/resume", {
468
+ method: "POST",
469
+ });
470
+ return res.status;
471
+ }
472
+ async restartAgent() {
473
+ const res = await this.fetch("/api/agent/restart", { method: "POST" });
474
+ return res.status;
475
+ }
476
+ /**
477
+ * Restart the agent if possible, or wait for an in-progress restart to finish.
478
+ * Polls status until the agent state is "running".
479
+ */
480
+ async restartAndWait(maxWaitMs = 30000) {
481
+ // Try triggering a restart; 409 means one is already in progress
482
+ try {
483
+ await this.restartAgent();
484
+ }
485
+ catch {
486
+ // Already restarting — that's fine, we'll poll
487
+ }
488
+ // Poll until running
489
+ const start = Date.now();
490
+ const interval = 1000;
491
+ while (Date.now() - start < maxWaitMs) {
492
+ await new Promise((r) => setTimeout(r, interval));
493
+ try {
494
+ const status = await this.getStatus();
495
+ if (status.state === "running")
496
+ return status;
497
+ }
498
+ catch {
499
+ // Server may be briefly unavailable during restart
500
+ }
501
+ }
502
+ // Return whatever we get after timeout
503
+ return this.getStatus();
504
+ }
505
+ async resetAgent() {
506
+ await this.fetch("/api/agent/reset", { method: "POST" });
507
+ }
508
+ async getConfig() {
509
+ return this.fetch("/api/config");
510
+ }
511
+ async getConfigSchema() {
512
+ return this.fetch("/api/config/schema");
513
+ }
514
+ async updateConfig(patch) {
515
+ return this.fetch("/api/config", {
516
+ method: "PUT",
517
+ headers: { "Content-Type": "application/json" },
518
+ body: JSON.stringify(patch),
519
+ });
520
+ }
521
+ // ── Custom VRM avatar ────────────────────────────────────────────────
522
+ async uploadCustomVrm(file) {
523
+ const buf = await file.arrayBuffer();
524
+ await this.fetch("/api/avatar/vrm", {
525
+ method: "POST",
526
+ headers: { "Content-Type": "application/octet-stream" },
527
+ body: buf,
528
+ });
529
+ }
530
+ /** Uses raw fetch instead of this.fetch() because HEAD returns no JSON body. */
531
+ async hasCustomVrm() {
532
+ try {
533
+ const res = await this.rawRequest("/api/avatar/vrm", { method: "HEAD" }, { allowNonOk: true });
534
+ return res.ok;
535
+ }
536
+ catch {
537
+ return false;
538
+ }
539
+ }
540
+ // ── Custom background image ─────────────────────────────────────────
541
+ async uploadCustomBackground(file) {
542
+ const buf = await file.arrayBuffer();
543
+ await this.fetch("/api/avatar/background", {
544
+ method: "POST",
545
+ headers: { "Content-Type": "application/octet-stream" },
546
+ body: buf,
547
+ });
548
+ }
549
+ /** Uses raw fetch instead of this.fetch() because HEAD returns no JSON body. */
550
+ async hasCustomBackground() {
551
+ try {
552
+ const res = await this.rawRequest("/api/avatar/background", { method: "HEAD" }, { allowNonOk: true });
553
+ return res.ok;
554
+ }
555
+ catch {
556
+ return false;
557
+ }
558
+ }
559
+ // ── Connectors ──────────────────────────────────────────────────────
560
+ async getConnectors() {
561
+ return this.fetch("/api/connectors");
562
+ }
563
+ async saveConnector(name, config) {
564
+ return this.fetch("/api/connectors", {
565
+ method: "POST",
566
+ body: JSON.stringify({ name, config }),
567
+ });
568
+ }
569
+ async deleteConnector(name) {
570
+ return this.fetch(`/api/connectors/${encodeURIComponent(name)}`, {
571
+ method: "DELETE",
572
+ });
573
+ }
574
+ async getTriggers() {
575
+ return this.fetch("/api/triggers");
576
+ }
577
+ async getTrigger(id) {
578
+ return this.fetch(`/api/triggers/${encodeURIComponent(id)}`);
579
+ }
580
+ async createTrigger(request) {
581
+ return this.fetch("/api/triggers", {
582
+ method: "POST",
583
+ body: JSON.stringify(request),
584
+ });
585
+ }
586
+ async updateTrigger(id, request) {
587
+ return this.fetch(`/api/triggers/${encodeURIComponent(id)}`, {
588
+ method: "PUT",
589
+ body: JSON.stringify(request),
590
+ });
591
+ }
592
+ async deleteTrigger(id) {
593
+ return this.fetch(`/api/triggers/${encodeURIComponent(id)}`, {
594
+ method: "DELETE",
595
+ });
596
+ }
597
+ async runTriggerNow(id) {
598
+ return this.fetch(`/api/triggers/${encodeURIComponent(id)}/execute`, {
599
+ method: "POST",
600
+ });
601
+ }
602
+ async getTriggerRuns(id) {
603
+ return this.fetch(`/api/triggers/${encodeURIComponent(id)}/runs`);
604
+ }
605
+ async getTriggerHealth() {
606
+ return this.fetch("/api/triggers/health");
607
+ }
608
+ // Fine-tuning / training
609
+ async getTrainingStatus() {
610
+ return this.fetch("/api/training/status");
611
+ }
612
+ async listTrainingTrajectories(opts) {
613
+ const params = new URLSearchParams();
614
+ if (typeof opts?.limit === "number")
615
+ params.set("limit", String(opts.limit));
616
+ if (typeof opts?.offset === "number")
617
+ params.set("offset", String(opts.offset));
618
+ const qs = params.toString();
619
+ return this.fetch(`/api/training/trajectories${qs ? `?${qs}` : ""}`);
620
+ }
621
+ async getTrainingTrajectory(trajectoryId) {
622
+ return this.fetch(`/api/training/trajectories/${encodeURIComponent(trajectoryId)}`);
623
+ }
624
+ async listTrainingDatasets() {
625
+ return this.fetch("/api/training/datasets");
626
+ }
627
+ async buildTrainingDataset(options) {
628
+ return this.fetch("/api/training/datasets/build", {
629
+ method: "POST",
630
+ body: JSON.stringify(options ?? {}),
631
+ });
632
+ }
633
+ async listTrainingJobs() {
634
+ return this.fetch("/api/training/jobs");
635
+ }
636
+ async startTrainingJob(options) {
637
+ return this.fetch("/api/training/jobs", {
638
+ method: "POST",
639
+ body: JSON.stringify(options ?? {}),
640
+ });
641
+ }
642
+ async getTrainingJob(jobId) {
643
+ return this.fetch(`/api/training/jobs/${encodeURIComponent(jobId)}`);
644
+ }
645
+ async cancelTrainingJob(jobId) {
646
+ return this.fetch(`/api/training/jobs/${encodeURIComponent(jobId)}/cancel`, {
647
+ method: "POST",
648
+ });
649
+ }
650
+ async listTrainingModels() {
651
+ return this.fetch("/api/training/models");
652
+ }
653
+ async importTrainingModelToOllama(modelId, options) {
654
+ return this.fetch(`/api/training/models/${encodeURIComponent(modelId)}/import-ollama`, {
655
+ method: "POST",
656
+ body: JSON.stringify(options ?? {}),
657
+ });
658
+ }
659
+ async activateTrainingModel(modelId, providerModel) {
660
+ return this.fetch(`/api/training/models/${encodeURIComponent(modelId)}/activate`, {
661
+ method: "POST",
662
+ body: JSON.stringify({ providerModel }),
663
+ });
664
+ }
665
+ async benchmarkTrainingModel(modelId) {
666
+ return this.fetch(`/api/training/models/${encodeURIComponent(modelId)}/benchmark`, {
667
+ method: "POST",
668
+ });
669
+ }
670
+ async getPlugins() {
671
+ return this.fetch("/api/plugins");
672
+ }
673
+ async fetchModels(provider, refresh = true) {
674
+ const params = new URLSearchParams({ provider });
675
+ if (refresh)
676
+ params.set("refresh", "true");
677
+ return this.fetch(`/api/models?${params.toString()}`);
678
+ }
679
+ async getCorePlugins() {
680
+ return this.fetch("/api/plugins/core");
681
+ }
682
+ async toggleCorePlugin(npmName, enabled) {
683
+ return this.fetch("/api/plugins/core/toggle", {
684
+ method: "POST",
685
+ body: JSON.stringify({ npmName, enabled }),
686
+ });
687
+ }
688
+ async updatePlugin(id, config) {
689
+ return this.fetch(`/api/plugins/${id}`, {
690
+ method: "PUT",
691
+ body: JSON.stringify(config),
692
+ });
693
+ }
694
+ async getSecrets() {
695
+ return this.fetch("/api/secrets");
696
+ }
697
+ async updateSecrets(secrets) {
698
+ return this.fetch("/api/secrets", {
699
+ method: "PUT",
700
+ body: JSON.stringify({ secrets }),
701
+ });
702
+ }
703
+ async testPluginConnection(id) {
704
+ return this.fetch(`/api/plugins/${encodeURIComponent(id)}/test`, {
705
+ method: "POST",
706
+ });
707
+ }
708
+ async restart() {
709
+ return this.fetch("/api/restart", { method: "POST" });
710
+ }
711
+ async getSkills() {
712
+ return this.fetch("/api/skills");
713
+ }
714
+ async refreshSkills() {
715
+ return this.fetch("/api/skills/refresh", { method: "POST" });
716
+ }
717
+ async getLogs(filter) {
718
+ const params = new URLSearchParams();
719
+ if (filter?.source)
720
+ params.set("source", filter.source);
721
+ if (filter?.level)
722
+ params.set("level", filter.level);
723
+ if (filter?.tag)
724
+ params.set("tag", filter.tag);
725
+ if (filter?.since)
726
+ params.set("since", String(filter.since));
727
+ const qs = params.toString();
728
+ return this.fetch(`/api/logs${qs ? `?${qs}` : ""}`);
729
+ }
730
+ buildSecurityAuditParams(filter, includeStream = false) {
731
+ const params = new URLSearchParams();
732
+ if (filter?.type)
733
+ params.set("type", filter.type);
734
+ if (filter?.severity)
735
+ params.set("severity", filter.severity);
736
+ if (filter?.since !== undefined) {
737
+ const sinceValue = filter.since instanceof Date
738
+ ? filter.since.toISOString()
739
+ : String(filter.since);
740
+ params.set("since", sinceValue);
741
+ }
742
+ if (filter?.limit !== undefined)
743
+ params.set("limit", String(filter.limit));
744
+ if (includeStream)
745
+ params.set("stream", "1");
746
+ return params;
747
+ }
748
+ async getSecurityAudit(filter) {
749
+ const qs = this.buildSecurityAuditParams(filter).toString();
750
+ return this.fetch(`/api/security/audit${qs ? `?${qs}` : ""}`);
751
+ }
752
+ async streamSecurityAudit(onEvent, filter, signal) {
753
+ if (!this.apiAvailable) {
754
+ throw new Error("API not available (no HTTP origin)");
755
+ }
756
+ const token = this.apiToken;
757
+ const qs = this.buildSecurityAuditParams(filter, true).toString();
758
+ const res = await fetch(`${this.baseUrl}/api/security/audit${qs ? `?${qs}` : ""}`, {
759
+ method: "GET",
760
+ headers: {
761
+ Accept: "text/event-stream",
762
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
763
+ },
764
+ signal,
765
+ });
766
+ if (!res.ok) {
767
+ const body = (await res
768
+ .json()
769
+ .catch(() => ({ error: res.statusText })));
770
+ const err = new Error(body.error ?? `HTTP ${res.status}`);
771
+ err.status = res.status;
772
+ throw err;
773
+ }
774
+ if (!res.body) {
775
+ throw new Error("Streaming not supported by this browser");
776
+ }
777
+ const parsePayload = (payload) => {
778
+ if (!payload)
779
+ return;
780
+ try {
781
+ const parsed = JSON.parse(payload);
782
+ if (parsed.type === "snapshot" || parsed.type === "entry") {
783
+ onEvent(parsed);
784
+ }
785
+ }
786
+ catch {
787
+ // Ignore malformed payloads to keep stream consumption resilient.
788
+ }
789
+ };
790
+ const decoder = new TextDecoder();
791
+ const reader = res.body.getReader();
792
+ let buffer = "";
793
+ const findSseEventBreak = (chunkBuffer) => {
794
+ const lfBreak = chunkBuffer.indexOf("\n\n");
795
+ const crlfBreak = chunkBuffer.indexOf("\r\n\r\n");
796
+ if (lfBreak === -1 && crlfBreak === -1)
797
+ return null;
798
+ if (lfBreak === -1)
799
+ return { index: crlfBreak, length: 4 };
800
+ if (crlfBreak === -1)
801
+ return { index: lfBreak, length: 2 };
802
+ return lfBreak < crlfBreak
803
+ ? { index: lfBreak, length: 2 }
804
+ : { index: crlfBreak, length: 4 };
805
+ };
806
+ while (true) {
807
+ const { done, value } = await reader.read();
808
+ if (done)
809
+ break;
810
+ buffer += decoder.decode(value, { stream: true });
811
+ let eventBreak = findSseEventBreak(buffer);
812
+ while (eventBreak) {
813
+ const rawEvent = buffer.slice(0, eventBreak.index);
814
+ buffer = buffer.slice(eventBreak.index + eventBreak.length);
815
+ for (const line of rawEvent.split(/\r?\n/)) {
816
+ if (!line.startsWith("data:"))
817
+ continue;
818
+ parsePayload(line.slice(5).trim());
819
+ }
820
+ eventBreak = findSseEventBreak(buffer);
821
+ }
822
+ }
823
+ if (buffer.trim()) {
824
+ for (const line of buffer.split(/\r?\n/)) {
825
+ if (!line.startsWith("data:"))
826
+ continue;
827
+ parsePayload(line.slice(5).trim());
828
+ }
829
+ }
830
+ }
831
+ async getAgentEvents(opts) {
832
+ const params = new URLSearchParams();
833
+ if (opts?.afterEventId)
834
+ params.set("after", opts.afterEventId);
835
+ if (typeof opts?.limit === "number")
836
+ params.set("limit", String(opts.limit));
837
+ if (opts?.runId)
838
+ params.set("runId", opts.runId);
839
+ if (typeof opts?.fromSeq === "number")
840
+ params.set("fromSeq", String(Math.trunc(opts.fromSeq)));
841
+ const qs = params.toString();
842
+ return this.fetch(`/api/agent/events${qs ? `?${qs}` : ""}`);
843
+ }
844
+ async getExtensionStatus() {
845
+ return this.fetch("/api/extension/status");
846
+ }
847
+ // Skill Catalog
848
+ async getSkillCatalog(opts) {
849
+ const params = new URLSearchParams();
850
+ if (opts?.page)
851
+ params.set("page", String(opts.page));
852
+ if (opts?.perPage)
853
+ params.set("perPage", String(opts.perPage));
854
+ if (opts?.sort)
855
+ params.set("sort", opts.sort);
856
+ const qs = params.toString();
857
+ return this.fetch(`/api/skills/catalog${qs ? `?${qs}` : ""}`);
858
+ }
859
+ async searchSkillCatalog(query, limit = 30) {
860
+ return this.fetch(`/api/skills/catalog/search?q=${encodeURIComponent(query)}&limit=${limit}`);
861
+ }
862
+ async getSkillCatalogDetail(slug) {
863
+ return this.fetch(`/api/skills/catalog/${encodeURIComponent(slug)}`);
864
+ }
865
+ async refreshSkillCatalog() {
866
+ return this.fetch("/api/skills/catalog/refresh", { method: "POST" });
867
+ }
868
+ async installCatalogSkill(slug, version) {
869
+ return this.fetch("/api/skills/catalog/install", {
870
+ method: "POST",
871
+ body: JSON.stringify({ slug, version }),
872
+ });
873
+ }
874
+ async uninstallCatalogSkill(slug) {
875
+ return this.fetch("/api/skills/catalog/uninstall", {
876
+ method: "POST",
877
+ body: JSON.stringify({ slug }),
878
+ });
879
+ }
880
+ // Registry / Plugin Store
881
+ async getRegistryPlugins() {
882
+ return this.fetch("/api/registry/plugins");
883
+ }
884
+ async getRegistryPluginInfo(name) {
885
+ return this.fetch(`/api/registry/plugins/${encodeURIComponent(name)}`);
886
+ }
887
+ async getInstalledPlugins() {
888
+ return this.fetch("/api/plugins/installed");
889
+ }
890
+ async installRegistryPlugin(name, autoRestart = true) {
891
+ return this.fetch("/api/plugins/install", {
892
+ method: "POST",
893
+ body: JSON.stringify({ name, autoRestart }),
894
+ });
895
+ }
896
+ async uninstallRegistryPlugin(name, autoRestart = true) {
897
+ return this.fetch("/api/plugins/uninstall", {
898
+ method: "POST",
899
+ body: JSON.stringify({ name, autoRestart }),
900
+ });
901
+ }
902
+ // Agent Export / Import
903
+ /**
904
+ * Export the agent as a password-encrypted .eliza-agent file.
905
+ * Returns the raw Response so the caller can stream the binary body.
906
+ */
907
+ async exportAgent(password, includeLogs = false) {
908
+ if (password.length < AGENT_TRANSFER_MIN_PASSWORD_LENGTH) {
909
+ throw new Error(`Password must be at least ${AGENT_TRANSFER_MIN_PASSWORD_LENGTH} characters.`);
910
+ }
911
+ return this.rawRequest("/api/agent/export", {
912
+ method: "POST",
913
+ headers: {
914
+ "Content-Type": "application/json",
915
+ },
916
+ body: JSON.stringify({ password, includeLogs }),
917
+ });
918
+ }
919
+ /** Get an estimate of the export size. */
920
+ async getExportEstimate() {
921
+ return this.fetch("/api/agent/export/estimate");
922
+ }
923
+ /**
924
+ * Import an agent from a password-encrypted .eliza-agent file.
925
+ * Encodes the password and file into a binary envelope.
926
+ */
927
+ async importAgent(password, fileBuffer) {
928
+ if (password.length < AGENT_TRANSFER_MIN_PASSWORD_LENGTH) {
929
+ throw new Error(`Password must be at least ${AGENT_TRANSFER_MIN_PASSWORD_LENGTH} characters.`);
930
+ }
931
+ const passwordBytes = new TextEncoder().encode(password);
932
+ const envelope = new Uint8Array(4 + passwordBytes.length + fileBuffer.byteLength);
933
+ const view = new DataView(envelope.buffer);
934
+ view.setUint32(0, passwordBytes.length, false);
935
+ envelope.set(passwordBytes, 4);
936
+ envelope.set(new Uint8Array(fileBuffer), 4 + passwordBytes.length);
937
+ const res = await this.rawRequest("/api/agent/import", {
938
+ method: "POST",
939
+ headers: {
940
+ "Content-Type": "application/octet-stream",
941
+ },
942
+ body: envelope,
943
+ });
944
+ const data = (await res.json());
945
+ if (!data.success) {
946
+ throw new Error(data.error ?? `Import failed (${res.status})`);
947
+ }
948
+ return data;
949
+ }
950
+ // Character
951
+ async getCharacter() {
952
+ return this.fetch("/api/character");
953
+ }
954
+ async getRandomName() {
955
+ return this.fetch("/api/character/random-name");
956
+ }
957
+ async generateCharacterField(field, context, mode) {
958
+ return this.fetch("/api/character/generate", {
959
+ method: "POST",
960
+ body: JSON.stringify({ field, context, mode }),
961
+ });
962
+ }
963
+ async updateCharacter(character) {
964
+ return this.fetch("/api/character", {
965
+ method: "PUT",
966
+ body: JSON.stringify(character),
967
+ });
968
+ }
969
+ // Wallet
970
+ async getWalletAddresses() {
971
+ return this.fetch("/api/wallet/addresses");
972
+ }
973
+ async getWalletBalances() {
974
+ return this.fetch("/api/wallet/balances");
975
+ }
976
+ async getWalletNfts() {
977
+ return this.fetch("/api/wallet/nfts");
978
+ }
979
+ async getWalletConfig() {
980
+ return this.fetch("/api/wallet/config");
981
+ }
982
+ async updateWalletConfig(config) {
983
+ return this.fetch("/api/wallet/config", {
984
+ method: "PUT",
985
+ body: JSON.stringify(config),
986
+ });
987
+ }
988
+ async exportWalletKeys(exportToken) {
989
+ return this.fetch("/api/wallet/export", {
990
+ method: "POST",
991
+ body: JSON.stringify({ confirm: true, exportToken }),
992
+ });
993
+ }
994
+ // BSC Trading
995
+ async getBscTradePreflight(tokenAddress) {
996
+ return this.fetch("/api/wallet/trade/preflight", {
997
+ method: "POST",
998
+ body: JSON.stringify(tokenAddress?.trim() ? { tokenAddress: tokenAddress.trim() } : {}),
999
+ });
1000
+ }
1001
+ async getBscTradeQuote(request) {
1002
+ return this.fetch("/api/wallet/trade/quote", {
1003
+ method: "POST",
1004
+ body: JSON.stringify(request),
1005
+ });
1006
+ }
1007
+ async executeBscTrade(request) {
1008
+ return this.fetch("/api/wallet/trade/execute", {
1009
+ method: "POST",
1010
+ body: JSON.stringify(request),
1011
+ });
1012
+ }
1013
+ async executeBscTransfer(request) {
1014
+ return this.fetch("/api/wallet/transfer/execute", {
1015
+ method: "POST",
1016
+ body: JSON.stringify(request),
1017
+ });
1018
+ }
1019
+ async getBscTradeTxStatus(hash) {
1020
+ return this.fetch(`/api/wallet/trade/tx-status?hash=${encodeURIComponent(hash)}`);
1021
+ }
1022
+ async getWalletTradingProfile(window = "30d", source = "all") {
1023
+ const params = new URLSearchParams({
1024
+ window,
1025
+ source,
1026
+ });
1027
+ return this.fetch(`/api/wallet/trading/profile?${params.toString()}`);
1028
+ }
1029
+ async applyProductionWalletDefaults() {
1030
+ return this.fetch("/api/wallet/production-defaults", {
1031
+ method: "POST",
1032
+ body: JSON.stringify({ confirm: true }),
1033
+ });
1034
+ }
1035
+ // Software Updates
1036
+ async getUpdateStatus(force = false) {
1037
+ return this.fetch(`/api/update/status${force ? "?force=true" : ""}`);
1038
+ }
1039
+ async setUpdateChannel(channel) {
1040
+ return this.fetch("/api/update/channel", {
1041
+ method: "PUT",
1042
+ body: JSON.stringify({ channel }),
1043
+ });
1044
+ }
1045
+ // Cloud
1046
+ async getCloudStatus() {
1047
+ return this.fetch("/api/cloud/status");
1048
+ }
1049
+ async getCloudCredits() {
1050
+ return this.fetch("/api/cloud/credits");
1051
+ }
1052
+ async getCloudBillingSummary() {
1053
+ return this.fetch("/api/cloud/billing/summary");
1054
+ }
1055
+ async getCloudBillingSettings() {
1056
+ return this.fetch("/api/cloud/billing/settings");
1057
+ }
1058
+ async updateCloudBillingSettings(request) {
1059
+ return this.fetch("/api/cloud/billing/settings", {
1060
+ method: "PUT",
1061
+ body: JSON.stringify(request),
1062
+ });
1063
+ }
1064
+ async getCloudBillingPaymentMethods() {
1065
+ return this.fetch("/api/cloud/billing/payment-methods");
1066
+ }
1067
+ async getCloudBillingHistory() {
1068
+ return this.fetch("/api/cloud/billing/history");
1069
+ }
1070
+ async createCloudBillingCheckout(request) {
1071
+ return this.fetch("/api/cloud/billing/checkout", {
1072
+ method: "POST",
1073
+ body: JSON.stringify(request),
1074
+ });
1075
+ }
1076
+ async createCloudBillingCryptoQuote(request) {
1077
+ return this.fetch("/api/cloud/billing/crypto/quote", {
1078
+ method: "POST",
1079
+ body: JSON.stringify(request),
1080
+ });
1081
+ }
1082
+ async cloudLogin() {
1083
+ return this.fetch("/api/cloud/login", { method: "POST" });
1084
+ }
1085
+ async cloudLoginPoll(sessionId) {
1086
+ return this.fetch(`/api/cloud/login/status?sessionId=${encodeURIComponent(sessionId)}`);
1087
+ }
1088
+ async cloudDisconnect() {
1089
+ return this.fetch("/api/cloud/disconnect", { method: "POST" });
1090
+ }
1091
+ // Cloud Compat (Eliza Cloud v2 thin-client endpoints)
1092
+ /** List all cloud-hosted agents for the authenticated user. */
1093
+ async getCloudCompatAgents() {
1094
+ return this.fetch("/api/cloud/compat/agents");
1095
+ }
1096
+ /** Create a new cloud-hosted agent. */
1097
+ async createCloudCompatAgent(opts) {
1098
+ return this.fetch("/api/cloud/compat/agents", {
1099
+ method: "POST",
1100
+ body: JSON.stringify(opts),
1101
+ });
1102
+ }
1103
+ /** Get a specific cloud-hosted agent by ID. */
1104
+ async getCloudCompatAgent(agentId) {
1105
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}`);
1106
+ }
1107
+ /** Delete a cloud-hosted agent. */
1108
+ async deleteCloudCompatAgent(agentId) {
1109
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}`, { method: "DELETE" });
1110
+ }
1111
+ /** Get status of a cloud-hosted agent. */
1112
+ async getCloudCompatAgentStatus(agentId) {
1113
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}/status`);
1114
+ }
1115
+ /** Get logs from a cloud-hosted agent. */
1116
+ async getCloudCompatAgentLogs(agentId, tail = 100) {
1117
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}/logs?tail=${tail}`);
1118
+ }
1119
+ /** Restart a cloud-hosted agent. */
1120
+ async restartCloudCompatAgent(agentId) {
1121
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}/restart`, { method: "POST" });
1122
+ }
1123
+ /** Suspend a cloud-hosted agent. */
1124
+ async suspendCloudCompatAgent(agentId) {
1125
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}/suspend`, { method: "POST" });
1126
+ }
1127
+ /** Resume a cloud-hosted agent. */
1128
+ async resumeCloudCompatAgent(agentId) {
1129
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}/resume`, { method: "POST" });
1130
+ }
1131
+ /** Launch a managed cloud agent into the Milady app. */
1132
+ async launchCloudCompatAgent(agentId) {
1133
+ return this.fetch(`/api/cloud/compat/agents/${encodeURIComponent(agentId)}/launch`, { method: "POST" });
1134
+ }
1135
+ /** Get cloud availability (capacity info). */
1136
+ async getCloudCompatAvailability() {
1137
+ return this.fetch("/api/cloud/compat/availability");
1138
+ }
1139
+ /** Poll a cloud job status by job ID. */
1140
+ async getCloudCompatJobStatus(jobId) {
1141
+ return this.fetch(`/api/cloud/compat/jobs/${encodeURIComponent(jobId)}`);
1142
+ }
1143
+ // Apps & Registry
1144
+ async listApps() {
1145
+ return this.fetch("/api/apps");
1146
+ }
1147
+ async searchApps(query) {
1148
+ return this.fetch(`/api/apps/search?q=${encodeURIComponent(query)}`);
1149
+ }
1150
+ async listInstalledApps() {
1151
+ return this.fetch("/api/apps/installed");
1152
+ }
1153
+ async stopApp(name) {
1154
+ return this.fetch("/api/apps/stop", {
1155
+ method: "POST",
1156
+ body: JSON.stringify({ name }),
1157
+ });
1158
+ }
1159
+ async getAppInfo(name) {
1160
+ return this.fetch(`/api/apps/info/${encodeURIComponent(name)}`);
1161
+ }
1162
+ /** Launch an app: installs its plugin (if needed), returns viewer config for iframe. */
1163
+ async launchApp(name) {
1164
+ return this.fetch("/api/apps/launch", {
1165
+ method: "POST",
1166
+ body: JSON.stringify({ name }),
1167
+ });
1168
+ }
1169
+ async listRegistryPlugins() {
1170
+ return this.fetch("/api/apps/plugins");
1171
+ }
1172
+ async searchRegistryPlugins(query) {
1173
+ return this.fetch(`/api/apps/plugins/search?q=${encodeURIComponent(query)}`);
1174
+ }
1175
+ async listHyperscapeEmbeddedAgents() {
1176
+ return this.fetch("/api/apps/hyperscape/embedded-agents");
1177
+ }
1178
+ async createHyperscapeEmbeddedAgent(input) {
1179
+ return this.fetch("/api/apps/hyperscape/embedded-agents", {
1180
+ method: "POST",
1181
+ body: JSON.stringify(input),
1182
+ });
1183
+ }
1184
+ async controlHyperscapeEmbeddedAgent(characterId, action) {
1185
+ return this.fetch(`/api/apps/hyperscape/embedded-agents/${encodeURIComponent(characterId)}/${action}`, { method: "POST" });
1186
+ }
1187
+ async sendHyperscapeEmbeddedAgentCommand(characterId, command, data) {
1188
+ return this.fetch(`/api/apps/hyperscape/embedded-agents/${encodeURIComponent(characterId)}/command`, {
1189
+ method: "POST",
1190
+ body: JSON.stringify({ command, data }),
1191
+ });
1192
+ }
1193
+ async sendHyperscapeAgentMessage(agentId, content) {
1194
+ return this.fetch(`/api/apps/hyperscape/agents/${encodeURIComponent(agentId)}/message`, {
1195
+ method: "POST",
1196
+ body: JSON.stringify({ content }),
1197
+ });
1198
+ }
1199
+ async getHyperscapeAgentGoal(agentId) {
1200
+ return this.fetch(`/api/apps/hyperscape/agents/${encodeURIComponent(agentId)}/goal`);
1201
+ }
1202
+ async getHyperscapeAgentQuickActions(agentId) {
1203
+ return this.fetch(`/api/apps/hyperscape/agents/${encodeURIComponent(agentId)}/quick-actions`);
1204
+ }
1205
+ // Skills Marketplace
1206
+ async searchSkillsMarketplace(query, installed, limit) {
1207
+ const params = new URLSearchParams({
1208
+ q: query,
1209
+ installed: String(installed),
1210
+ limit: String(limit),
1211
+ });
1212
+ return this.fetch(`/api/skills/marketplace/search?${params}`);
1213
+ }
1214
+ async getSkillsMarketplaceConfig() {
1215
+ return this.fetch("/api/skills/marketplace/config");
1216
+ }
1217
+ async updateSkillsMarketplaceConfig(apiKey) {
1218
+ return this.fetch("/api/skills/marketplace/config", {
1219
+ method: "PUT",
1220
+ body: JSON.stringify({ apiKey }),
1221
+ });
1222
+ }
1223
+ async installMarketplaceSkill(data) {
1224
+ await this.fetch("/api/skills/marketplace/install", {
1225
+ method: "POST",
1226
+ body: JSON.stringify(data),
1227
+ });
1228
+ }
1229
+ async uninstallMarketplaceSkill(skillId, autoRefresh) {
1230
+ await this.fetch("/api/skills/marketplace/uninstall", {
1231
+ method: "POST",
1232
+ body: JSON.stringify({ id: skillId, autoRefresh }),
1233
+ });
1234
+ }
1235
+ async updateSkill(skillId, enabled) {
1236
+ return this.fetch(`/api/skills/${encodeURIComponent(skillId)}`, {
1237
+ method: "PUT",
1238
+ body: JSON.stringify({ enabled }),
1239
+ });
1240
+ }
1241
+ // ── Skill CRUD & Security ────────────────────────────────────────────────
1242
+ async createSkill(name, description) {
1243
+ return this.fetch("/api/skills/create", {
1244
+ method: "POST",
1245
+ body: JSON.stringify({ name, description }),
1246
+ });
1247
+ }
1248
+ async openSkill(id) {
1249
+ return this.fetch(`/api/skills/${encodeURIComponent(id)}/open`, {
1250
+ method: "POST",
1251
+ });
1252
+ }
1253
+ async getSkillSource(id) {
1254
+ return this.fetch(`/api/skills/${encodeURIComponent(id)}/source`);
1255
+ }
1256
+ async saveSkillSource(id, content) {
1257
+ return this.fetch(`/api/skills/${encodeURIComponent(id)}/source`, {
1258
+ method: "PUT",
1259
+ body: JSON.stringify({ content }),
1260
+ });
1261
+ }
1262
+ async deleteSkill(id) {
1263
+ return this.fetch(`/api/skills/${encodeURIComponent(id)}`, {
1264
+ method: "DELETE",
1265
+ });
1266
+ }
1267
+ async getSkillScanReport(id) {
1268
+ return this.fetch(`/api/skills/${encodeURIComponent(id)}/scan`);
1269
+ }
1270
+ async acknowledgeSkill(id, enable) {
1271
+ return this.fetch(`/api/skills/${encodeURIComponent(id)}/acknowledge`, {
1272
+ method: "POST",
1273
+ body: JSON.stringify({ enable }),
1274
+ });
1275
+ }
1276
+ // Workbench
1277
+ async getWorkbenchOverview() {
1278
+ return this.fetch("/api/workbench/overview");
1279
+ }
1280
+ async listWorkbenchTasks() {
1281
+ return this.fetch("/api/workbench/tasks");
1282
+ }
1283
+ async getWorkbenchTask(taskId) {
1284
+ return this.fetch(`/api/workbench/tasks/${encodeURIComponent(taskId)}`);
1285
+ }
1286
+ async createWorkbenchTask(data) {
1287
+ return this.fetch("/api/workbench/tasks", {
1288
+ method: "POST",
1289
+ body: JSON.stringify(data),
1290
+ });
1291
+ }
1292
+ async updateWorkbenchTask(taskId, data) {
1293
+ return this.fetch(`/api/workbench/tasks/${encodeURIComponent(taskId)}`, {
1294
+ method: "PUT",
1295
+ body: JSON.stringify(data),
1296
+ });
1297
+ }
1298
+ async deleteWorkbenchTask(taskId) {
1299
+ return this.fetch(`/api/workbench/tasks/${encodeURIComponent(taskId)}`, {
1300
+ method: "DELETE",
1301
+ });
1302
+ }
1303
+ async listWorkbenchTodos() {
1304
+ return this.fetch("/api/workbench/todos");
1305
+ }
1306
+ async getWorkbenchTodo(todoId) {
1307
+ return this.fetch(`/api/workbench/todos/${encodeURIComponent(todoId)}`);
1308
+ }
1309
+ async createWorkbenchTodo(data) {
1310
+ return this.fetch("/api/workbench/todos", {
1311
+ method: "POST",
1312
+ body: JSON.stringify(data),
1313
+ });
1314
+ }
1315
+ async updateWorkbenchTodo(todoId, data) {
1316
+ return this.fetch(`/api/workbench/todos/${encodeURIComponent(todoId)}`, {
1317
+ method: "PUT",
1318
+ body: JSON.stringify(data),
1319
+ });
1320
+ }
1321
+ async setWorkbenchTodoCompleted(todoId, isCompleted) {
1322
+ await this.fetch(`/api/workbench/todos/${encodeURIComponent(todoId)}/complete`, {
1323
+ method: "POST",
1324
+ body: JSON.stringify({ isCompleted }),
1325
+ });
1326
+ }
1327
+ async deleteWorkbenchTodo(todoId) {
1328
+ return this.fetch(`/api/workbench/todos/${encodeURIComponent(todoId)}`, {
1329
+ method: "DELETE",
1330
+ });
1331
+ }
1332
+ // Registry
1333
+ async refreshRegistry() {
1334
+ await this.fetch("/api/apps/refresh", { method: "POST" });
1335
+ }
1336
+ // Knowledge
1337
+ async getKnowledgeStats() {
1338
+ return this.fetch("/api/knowledge/stats");
1339
+ }
1340
+ async listKnowledgeDocuments(options) {
1341
+ const params = new URLSearchParams();
1342
+ if (options?.limit)
1343
+ params.set("limit", String(options.limit));
1344
+ if (options?.offset)
1345
+ params.set("offset", String(options.offset));
1346
+ const query = params.toString();
1347
+ return this.fetch(`/api/knowledge/documents${query ? `?${query}` : ""}`);
1348
+ }
1349
+ async getKnowledgeDocument(documentId) {
1350
+ return this.fetch(`/api/knowledge/documents/${encodeURIComponent(documentId)}`);
1351
+ }
1352
+ async deleteKnowledgeDocument(documentId) {
1353
+ return this.fetch(`/api/knowledge/documents/${encodeURIComponent(documentId)}`, {
1354
+ method: "DELETE",
1355
+ });
1356
+ }
1357
+ async uploadKnowledgeDocument(data) {
1358
+ return this.fetch("/api/knowledge/documents", {
1359
+ method: "POST",
1360
+ body: JSON.stringify(data),
1361
+ });
1362
+ }
1363
+ async uploadKnowledgeDocumentsBulk(data) {
1364
+ return this.fetch("/api/knowledge/documents/bulk", {
1365
+ method: "POST",
1366
+ body: JSON.stringify(data),
1367
+ });
1368
+ }
1369
+ async uploadKnowledgeFromUrl(url, metadata) {
1370
+ return this.fetch("/api/knowledge/documents/url", {
1371
+ method: "POST",
1372
+ body: JSON.stringify({ url, metadata }),
1373
+ });
1374
+ }
1375
+ async searchKnowledge(query, options) {
1376
+ const params = new URLSearchParams({ q: query });
1377
+ if (options?.threshold !== undefined)
1378
+ params.set("threshold", String(options.threshold));
1379
+ if (options?.limit !== undefined)
1380
+ params.set("limit", String(options.limit));
1381
+ return this.fetch(`/api/knowledge/search?${params}`);
1382
+ }
1383
+ async getKnowledgeFragments(documentId) {
1384
+ return this.fetch(`/api/knowledge/fragments/${encodeURIComponent(documentId)}`);
1385
+ }
1386
+ // Memory commands
1387
+ async rememberMemory(text) {
1388
+ return this.fetch("/api/memory/remember", {
1389
+ method: "POST",
1390
+ body: JSON.stringify({ text }),
1391
+ });
1392
+ }
1393
+ async searchMemory(query, options) {
1394
+ const params = new URLSearchParams({ q: query });
1395
+ if (options?.limit !== undefined)
1396
+ params.set("limit", String(options.limit));
1397
+ return this.fetch(`/api/memory/search?${params}`);
1398
+ }
1399
+ async quickContext(query, options) {
1400
+ const params = new URLSearchParams({ q: query });
1401
+ if (options?.limit !== undefined)
1402
+ params.set("limit", String(options.limit));
1403
+ return this.fetch(`/api/context/quick?${params}`);
1404
+ }
1405
+ // MCP
1406
+ async getMcpConfig() {
1407
+ return this.fetch("/api/mcp/config");
1408
+ }
1409
+ async getMcpStatus() {
1410
+ return this.fetch("/api/mcp/status");
1411
+ }
1412
+ async searchMcpMarketplace(query, limit) {
1413
+ const params = new URLSearchParams({ q: query, limit: String(limit) });
1414
+ return this.fetch(`/api/mcp/marketplace/search?${params}`);
1415
+ }
1416
+ async getMcpServerDetails(name) {
1417
+ return this.fetch(`/api/mcp/marketplace/${encodeURIComponent(name)}`);
1418
+ }
1419
+ async addMcpServer(name, config) {
1420
+ await this.fetch("/api/mcp/servers", {
1421
+ method: "POST",
1422
+ body: JSON.stringify({ name, config }),
1423
+ });
1424
+ }
1425
+ async removeMcpServer(name) {
1426
+ await this.fetch(`/api/mcp/servers/${encodeURIComponent(name)}`, {
1427
+ method: "DELETE",
1428
+ });
1429
+ }
1430
+ // Share Ingest
1431
+ async ingestShare(payload) {
1432
+ return this.fetch("/api/ingest/share", {
1433
+ method: "POST",
1434
+ body: JSON.stringify(payload),
1435
+ });
1436
+ }
1437
+ async consumeShareIngest() {
1438
+ return this.fetch("/api/share/consume", { method: "POST" });
1439
+ }
1440
+ // WebSocket
1441
+ connectWs() {
1442
+ if (this.ws?.readyState === WebSocket.OPEN)
1443
+ return;
1444
+ let host;
1445
+ if (this.baseUrl) {
1446
+ host = new URL(this.baseUrl).host;
1447
+ }
1448
+ else {
1449
+ // In non-HTTP environments (electrobun://, file://, etc.)
1450
+ // window.location.host may be empty or a non-routable placeholder like "-".
1451
+ const loc = window.location;
1452
+ if (loc.protocol !== "http:" && loc.protocol !== "https:")
1453
+ return;
1454
+ host = loc.host;
1455
+ }
1456
+ if (!host)
1457
+ return;
1458
+ const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
1459
+ let url = `${protocol}//${host}/ws`;
1460
+ const params = new URLSearchParams({ clientId: this.clientId });
1461
+ const token = this.apiToken;
1462
+ if (token)
1463
+ params.set("token", token);
1464
+ url += `?${params.toString()}`;
1465
+ this.ws = new WebSocket(url);
1466
+ this.ws.onopen = () => {
1467
+ this.backoffMs = 500;
1468
+ // Reset connection state on successful connection
1469
+ this.reconnectAttempt = 0;
1470
+ this.disconnectedAt = null;
1471
+ this.connectionState = "connected";
1472
+ this.emitConnectionStateChange();
1473
+ // Notify listeners when the WS reconnects (not on the first connect)
1474
+ // so they can re-hydrate state that may have been lost during the gap.
1475
+ if (this.wsHasConnectedOnce) {
1476
+ const handlers = this.wsHandlers.get("ws-reconnected");
1477
+ if (handlers) {
1478
+ for (const handler of handlers) {
1479
+ handler({ type: "ws-reconnected" });
1480
+ }
1481
+ }
1482
+ }
1483
+ this.wsHasConnectedOnce = true;
1484
+ if (this.wsSendQueue.length > 0 &&
1485
+ this.ws?.readyState === WebSocket.OPEN) {
1486
+ const pending = this.wsSendQueue;
1487
+ this.wsSendQueue = [];
1488
+ for (let i = 0; i < pending.length; i++) {
1489
+ if (this.ws?.readyState !== WebSocket.OPEN) {
1490
+ this.wsSendQueue = pending.slice(i).concat(this.wsSendQueue);
1491
+ break;
1492
+ }
1493
+ try {
1494
+ this.ws.send(pending[i]);
1495
+ }
1496
+ catch {
1497
+ this.wsSendQueue = pending.slice(i).concat(this.wsSendQueue);
1498
+ break;
1499
+ }
1500
+ }
1501
+ }
1502
+ };
1503
+ this.ws.onmessage = (event) => {
1504
+ try {
1505
+ const data = JSON.parse(event.data);
1506
+ const type = data.type;
1507
+ const handlers = this.wsHandlers.get(type);
1508
+ if (handlers) {
1509
+ for (const handler of handlers) {
1510
+ handler(data);
1511
+ }
1512
+ }
1513
+ // Also fire "all" handlers
1514
+ const allHandlers = this.wsHandlers.get("*");
1515
+ if (allHandlers) {
1516
+ for (const handler of allHandlers) {
1517
+ handler(data);
1518
+ }
1519
+ }
1520
+ }
1521
+ catch {
1522
+ // ignore parse errors
1523
+ }
1524
+ };
1525
+ this.ws.onclose = () => {
1526
+ this.ws = null;
1527
+ // Track disconnection time if not already set
1528
+ if (this.disconnectedAt === null) {
1529
+ this.disconnectedAt = Date.now();
1530
+ }
1531
+ this.reconnectAttempt++;
1532
+ // Update state based on attempt count
1533
+ if (this.reconnectAttempt >= this.maxReconnectAttempts) {
1534
+ this.connectionState = "failed";
1535
+ }
1536
+ else {
1537
+ this.connectionState = "reconnecting";
1538
+ }
1539
+ this.emitConnectionStateChange();
1540
+ this.scheduleReconnect();
1541
+ };
1542
+ this.ws.onerror = () => {
1543
+ // close handler will fire
1544
+ };
1545
+ }
1546
+ scheduleReconnect() {
1547
+ if (this.reconnectTimer)
1548
+ return;
1549
+ // Stop reconnecting if we've hit max attempts
1550
+ if (this.reconnectAttempt >= this.maxReconnectAttempts) {
1551
+ return;
1552
+ }
1553
+ this.reconnectTimer = setTimeout(() => {
1554
+ this.reconnectTimer = null;
1555
+ this.connectWs();
1556
+ }, this.backoffMs);
1557
+ this.backoffMs = Math.min(this.backoffMs * 1.5, 10000);
1558
+ }
1559
+ emitConnectionStateChange() {
1560
+ const state = this.getConnectionState();
1561
+ for (const listener of this.connectionStateListeners) {
1562
+ try {
1563
+ listener(state);
1564
+ }
1565
+ catch {
1566
+ // ignore listener errors
1567
+ }
1568
+ }
1569
+ }
1570
+ /** Get the current WebSocket connection state. */
1571
+ getConnectionState() {
1572
+ return {
1573
+ state: this.connectionState,
1574
+ reconnectAttempt: this.reconnectAttempt,
1575
+ maxReconnectAttempts: this.maxReconnectAttempts,
1576
+ disconnectedAt: this.disconnectedAt,
1577
+ };
1578
+ }
1579
+ /** Subscribe to connection state changes. Returns an unsubscribe function. */
1580
+ onConnectionStateChange(listener) {
1581
+ this.connectionStateListeners.add(listener);
1582
+ return () => {
1583
+ this.connectionStateListeners.delete(listener);
1584
+ };
1585
+ }
1586
+ /** Reset connection state and restart reconnection attempts. */
1587
+ resetConnection() {
1588
+ this.reconnectAttempt = 0;
1589
+ this.disconnectedAt = null;
1590
+ this.connectionState = "disconnected";
1591
+ if (this.reconnectTimer) {
1592
+ clearTimeout(this.reconnectTimer);
1593
+ this.reconnectTimer = null;
1594
+ }
1595
+ this.backoffMs = 500;
1596
+ this.emitConnectionStateChange();
1597
+ this.connectWs();
1598
+ }
1599
+ /** Send an arbitrary JSON message over the WebSocket connection. */
1600
+ sendWsMessage(data) {
1601
+ const payload = JSON.stringify(data);
1602
+ if (this.ws?.readyState === WebSocket.OPEN) {
1603
+ this.ws.send(payload);
1604
+ return;
1605
+ }
1606
+ // Keep only the newest active-conversation update while disconnected.
1607
+ if (data.type === "active-conversation") {
1608
+ this.wsSendQueue = this.wsSendQueue.filter((queued) => {
1609
+ try {
1610
+ const parsed = JSON.parse(queued);
1611
+ return parsed.type !== "active-conversation";
1612
+ }
1613
+ catch {
1614
+ return true;
1615
+ }
1616
+ });
1617
+ }
1618
+ if (this.wsSendQueue.length >= this.wsSendQueueLimit) {
1619
+ this.wsSendQueue.shift();
1620
+ }
1621
+ this.wsSendQueue.push(payload);
1622
+ if (!this.ws || this.ws.readyState === WebSocket.CLOSED) {
1623
+ this.connectWs();
1624
+ }
1625
+ }
1626
+ onWsEvent(type, handler) {
1627
+ if (!this.wsHandlers.has(type)) {
1628
+ this.wsHandlers.set(type, new Set());
1629
+ }
1630
+ this.wsHandlers.get(type)?.add(handler);
1631
+ return () => {
1632
+ this.wsHandlers.get(type)?.delete(handler);
1633
+ };
1634
+ }
1635
+ normalizeAssistantText(text) {
1636
+ const stripped = stripAssistantStageDirections(text);
1637
+ const trimmed = stripped.trim();
1638
+ if (trimmed.length === 0) {
1639
+ if (text.trim().length === 0 ||
1640
+ /^\(?no response\)?$/i.test(text.trim())) {
1641
+ return GENERIC_NO_RESPONSE_TEXT;
1642
+ }
1643
+ return "";
1644
+ }
1645
+ if (/^\(?no response\)?$/i.test(trimmed)) {
1646
+ return GENERIC_NO_RESPONSE_TEXT;
1647
+ }
1648
+ return trimmed;
1649
+ }
1650
+ normalizeGreetingText(text) {
1651
+ const stripped = stripAssistantStageDirections(text);
1652
+ const trimmed = stripped.trim();
1653
+ if (trimmed.length === 0 || /^\(?no response\)?$/i.test(trimmed)) {
1654
+ return "";
1655
+ }
1656
+ return trimmed;
1657
+ }
1658
+ normalizeConversationMessage(message) {
1659
+ if (message.role !== "assistant")
1660
+ return message;
1661
+ const text = this.normalizeAssistantText(message.text);
1662
+ return text === message.text ? message : { ...message, text };
1663
+ }
1664
+ async streamChatEndpoint(path, text, onToken, channelType = "DM", signal, images, conversationMode) {
1665
+ const res = await this.rawRequest(path, {
1666
+ method: "POST",
1667
+ headers: {
1668
+ "Content-Type": "application/json",
1669
+ Accept: "text/event-stream",
1670
+ },
1671
+ body: JSON.stringify({
1672
+ text,
1673
+ channelType,
1674
+ ...(images?.length ? { images } : {}),
1675
+ ...(conversationMode ? { conversationMode } : {}),
1676
+ }),
1677
+ signal,
1678
+ });
1679
+ if (!res.body) {
1680
+ throw new Error("Streaming not supported by this browser");
1681
+ }
1682
+ const decoder = new TextDecoder();
1683
+ const reader = res.body.getReader();
1684
+ let buffer = "";
1685
+ let fullText = "";
1686
+ let doneText = null;
1687
+ let doneAgentName = null;
1688
+ let doneUsage;
1689
+ let receivedDone = false;
1690
+ const findSseEventBreak = (chunkBuffer) => {
1691
+ const lfBreak = chunkBuffer.indexOf("\n\n");
1692
+ const crlfBreak = chunkBuffer.indexOf("\r\n\r\n");
1693
+ if (lfBreak === -1 && crlfBreak === -1)
1694
+ return null;
1695
+ if (lfBreak === -1)
1696
+ return { index: crlfBreak, length: 4 };
1697
+ if (crlfBreak === -1)
1698
+ return { index: lfBreak, length: 2 };
1699
+ return lfBreak < crlfBreak
1700
+ ? { index: lfBreak, length: 2 }
1701
+ : { index: crlfBreak, length: 4 };
1702
+ };
1703
+ const parseDataLine = (line) => {
1704
+ const payload = line.startsWith("data:") ? line.slice(5).trim() : "";
1705
+ if (!payload)
1706
+ return;
1707
+ let parsed;
1708
+ try {
1709
+ parsed = JSON.parse(payload);
1710
+ }
1711
+ catch {
1712
+ return;
1713
+ }
1714
+ if (parsed.type === "token") {
1715
+ const chunk = parsed.text ?? "";
1716
+ const nextFullText = typeof parsed.fullText === "string"
1717
+ ? parsed.fullText
1718
+ : chunk
1719
+ ? mergeStreamingText(fullText, chunk)
1720
+ : fullText;
1721
+ if (nextFullText === fullText)
1722
+ return;
1723
+ fullText = nextFullText;
1724
+ onToken(chunk, fullText);
1725
+ return;
1726
+ }
1727
+ if (parsed.type === "done") {
1728
+ receivedDone = true;
1729
+ if (typeof parsed.fullText === "string")
1730
+ doneText = parsed.fullText;
1731
+ if (typeof parsed.agentName === "string" && parsed.agentName.trim()) {
1732
+ doneAgentName = parsed.agentName;
1733
+ }
1734
+ if (parsed.usage) {
1735
+ doneUsage = {
1736
+ promptTokens: parsed.usage.promptTokens ?? 0,
1737
+ completionTokens: parsed.usage.completionTokens ?? 0,
1738
+ totalTokens: parsed.usage.totalTokens ?? 0,
1739
+ model: parsed.usage.model,
1740
+ };
1741
+ }
1742
+ return;
1743
+ }
1744
+ if (parsed.type === "error") {
1745
+ throw new Error(parsed.message ?? "generation failed");
1746
+ }
1747
+ // Backward compatibility with legacy stream payloads: { text: "..." }
1748
+ if (parsed.text) {
1749
+ fullText = mergeStreamingText(fullText, parsed.text);
1750
+ onToken(parsed.text, fullText);
1751
+ }
1752
+ };
1753
+ while (true) {
1754
+ let done = false;
1755
+ let value;
1756
+ try {
1757
+ ({ done, value } = await reader.read());
1758
+ }
1759
+ catch (streamErr) {
1760
+ console.warn("[api-client] SSE stream interrupted:", streamErr);
1761
+ break;
1762
+ }
1763
+ if (done || !value)
1764
+ break;
1765
+ buffer += decoder.decode(value, { stream: true });
1766
+ let eventBreak = findSseEventBreak(buffer);
1767
+ while (eventBreak) {
1768
+ const rawEvent = buffer.slice(0, eventBreak.index);
1769
+ buffer = buffer.slice(eventBreak.index + eventBreak.length);
1770
+ for (const line of rawEvent.split(/\r?\n/)) {
1771
+ if (!line.startsWith("data:"))
1772
+ continue;
1773
+ parseDataLine(line);
1774
+ }
1775
+ eventBreak = findSseEventBreak(buffer);
1776
+ }
1777
+ }
1778
+ if (buffer.trim()) {
1779
+ for (const line of buffer.split(/\r?\n/)) {
1780
+ if (line.startsWith("data:"))
1781
+ parseDataLine(line);
1782
+ }
1783
+ }
1784
+ const resolvedText = this.normalizeAssistantText(doneText ?? fullText);
1785
+ return {
1786
+ text: resolvedText,
1787
+ agentName: doneAgentName ?? "Milady",
1788
+ completed: receivedDone,
1789
+ ...(doneUsage ? { usage: doneUsage } : {}),
1790
+ };
1791
+ }
1792
+ /**
1793
+ * Send a chat message via the REST endpoint (reliable — does not depend on
1794
+ * a WebSocket connection). Returns the agent's response text.
1795
+ */
1796
+ async sendChatRest(text, channelType = "DM", conversationMode) {
1797
+ const response = await this.fetch("/api/chat", {
1798
+ method: "POST",
1799
+ body: JSON.stringify({
1800
+ text,
1801
+ channelType,
1802
+ ...(conversationMode ? { conversationMode } : {}),
1803
+ }),
1804
+ });
1805
+ return {
1806
+ ...response,
1807
+ text: this.normalizeAssistantText(response.text),
1808
+ };
1809
+ }
1810
+ async sendChatStream(text, onToken, channelType = "DM", signal, conversationMode) {
1811
+ return this.streamChatEndpoint("/api/chat/stream", text, onToken, channelType, signal, undefined, conversationMode);
1812
+ }
1813
+ // Conversations
1814
+ async listConversations() {
1815
+ return this.fetch("/api/conversations");
1816
+ }
1817
+ async createConversation(title, options) {
1818
+ const response = await this.fetch("/api/conversations", {
1819
+ method: "POST",
1820
+ body: JSON.stringify({
1821
+ title,
1822
+ ...(options?.bootstrapGreeting === true
1823
+ ? { bootstrapGreeting: true }
1824
+ : {}),
1825
+ ...(typeof options?.lang === "string" && options.lang.trim()
1826
+ ? { lang: options.lang.trim() }
1827
+ : {}),
1828
+ }),
1829
+ });
1830
+ if (!response.greeting) {
1831
+ return response;
1832
+ }
1833
+ return {
1834
+ ...response,
1835
+ greeting: {
1836
+ ...response.greeting,
1837
+ text: this.normalizeGreetingText(response.greeting.text),
1838
+ },
1839
+ };
1840
+ }
1841
+ async getConversationMessages(id) {
1842
+ const response = await this.fetch(`/api/conversations/${encodeURIComponent(id)}/messages`);
1843
+ return {
1844
+ messages: response.messages.map((message) => this.normalizeConversationMessage(message)),
1845
+ };
1846
+ }
1847
+ async truncateConversationMessages(id, messageId, options) {
1848
+ return this.fetch(`/api/conversations/${encodeURIComponent(id)}/messages/truncate`, {
1849
+ method: "POST",
1850
+ body: JSON.stringify({
1851
+ messageId,
1852
+ inclusive: options?.inclusive === true,
1853
+ }),
1854
+ });
1855
+ }
1856
+ async sendConversationMessage(id, text, channelType = "DM", images, conversationMode) {
1857
+ const response = await this.fetch(`/api/conversations/${encodeURIComponent(id)}/messages`, {
1858
+ method: "POST",
1859
+ body: JSON.stringify({
1860
+ text,
1861
+ channelType,
1862
+ ...(images?.length ? { images } : {}),
1863
+ ...(conversationMode ? { conversationMode } : {}),
1864
+ }),
1865
+ });
1866
+ return {
1867
+ ...response,
1868
+ text: this.normalizeAssistantText(response.text),
1869
+ };
1870
+ }
1871
+ async sendConversationMessageStream(id, text, onToken, channelType = "DM", signal, images, conversationMode) {
1872
+ return this.streamChatEndpoint(`/api/conversations/${encodeURIComponent(id)}/messages/stream`, text, onToken, channelType, signal, images, conversationMode);
1873
+ }
1874
+ async requestGreeting(id, lang) {
1875
+ const qs = lang ? `?lang=${encodeURIComponent(lang)}` : "";
1876
+ const response = await this.fetch(`/api/conversations/${encodeURIComponent(id)}/greeting${qs}`, {
1877
+ method: "POST",
1878
+ });
1879
+ return {
1880
+ ...response,
1881
+ text: this.normalizeGreetingText(response.text),
1882
+ };
1883
+ }
1884
+ async renameConversation(id, title) {
1885
+ return this.fetch(`/api/conversations/${encodeURIComponent(id)}`, {
1886
+ method: "PATCH",
1887
+ body: JSON.stringify({ title }),
1888
+ });
1889
+ }
1890
+ async deleteConversation(id) {
1891
+ return this.fetch(`/api/conversations/${encodeURIComponent(id)}`, {
1892
+ method: "DELETE",
1893
+ });
1894
+ }
1895
+ /** @deprecated Prefer {@link sendChatRest} — WebSocket chat may silently drop messages. */
1896
+ sendChat(text) {
1897
+ if (this.ws?.readyState === WebSocket.OPEN) {
1898
+ this.ws.send(JSON.stringify({ type: "chat", text }));
1899
+ }
1900
+ }
1901
+ // ── Database API ──────────────────────────────────────────────────────
1902
+ async getDatabaseStatus() {
1903
+ return this.fetch("/api/database/status");
1904
+ }
1905
+ async getDatabaseConfig() {
1906
+ return this.fetch("/api/database/config");
1907
+ }
1908
+ async saveDatabaseConfig(config) {
1909
+ return this.fetch("/api/database/config", {
1910
+ method: "PUT",
1911
+ body: JSON.stringify(config),
1912
+ });
1913
+ }
1914
+ async testDatabaseConnection(creds) {
1915
+ return this.fetch("/api/database/test", {
1916
+ method: "POST",
1917
+ body: JSON.stringify(creds),
1918
+ });
1919
+ }
1920
+ async getDatabaseTables() {
1921
+ return this.fetch("/api/database/tables");
1922
+ }
1923
+ async getDatabaseRows(table, opts) {
1924
+ const params = new URLSearchParams();
1925
+ if (opts?.offset != null)
1926
+ params.set("offset", String(opts.offset));
1927
+ if (opts?.limit != null)
1928
+ params.set("limit", String(opts.limit));
1929
+ if (opts?.sort)
1930
+ params.set("sort", opts.sort);
1931
+ if (opts?.order)
1932
+ params.set("order", opts.order);
1933
+ if (opts?.search)
1934
+ params.set("search", opts.search);
1935
+ const qs = params.toString();
1936
+ return this.fetch(`/api/database/tables/${encodeURIComponent(table)}/rows${qs ? `?${qs}` : ""}`);
1937
+ }
1938
+ async insertDatabaseRow(table, data) {
1939
+ return this.fetch(`/api/database/tables/${encodeURIComponent(table)}/rows`, {
1940
+ method: "POST",
1941
+ body: JSON.stringify({ data }),
1942
+ });
1943
+ }
1944
+ async updateDatabaseRow(table, where, data) {
1945
+ return this.fetch(`/api/database/tables/${encodeURIComponent(table)}/rows`, {
1946
+ method: "PUT",
1947
+ body: JSON.stringify({ where, data }),
1948
+ });
1949
+ }
1950
+ async deleteDatabaseRow(table, where) {
1951
+ return this.fetch(`/api/database/tables/${encodeURIComponent(table)}/rows`, {
1952
+ method: "DELETE",
1953
+ body: JSON.stringify({ where }),
1954
+ });
1955
+ }
1956
+ async executeDatabaseQuery(sql, readOnly = true) {
1957
+ return this.fetch("/api/database/query", {
1958
+ method: "POST",
1959
+ body: JSON.stringify({ sql, readOnly }),
1960
+ });
1961
+ }
1962
+ // ── Trajectories ─────────────────────────────────────────────────────
1963
+ async getTrajectories(options) {
1964
+ const params = new URLSearchParams();
1965
+ if (options?.limit)
1966
+ params.set("limit", String(options.limit));
1967
+ if (options?.offset)
1968
+ params.set("offset", String(options.offset));
1969
+ if (options?.source)
1970
+ params.set("source", options.source);
1971
+ if (options?.status)
1972
+ params.set("status", options.status);
1973
+ if (options?.startDate)
1974
+ params.set("startDate", options.startDate);
1975
+ if (options?.endDate)
1976
+ params.set("endDate", options.endDate);
1977
+ if (options?.search)
1978
+ params.set("search", options.search);
1979
+ const query = params.toString();
1980
+ return this.fetch(`/api/trajectories${query ? `?${query}` : ""}`);
1981
+ }
1982
+ async getTrajectoryDetail(trajectoryId) {
1983
+ return this.fetch(`/api/trajectories/${encodeURIComponent(trajectoryId)}`);
1984
+ }
1985
+ async getTrajectoryStats() {
1986
+ return this.fetch("/api/trajectories/stats");
1987
+ }
1988
+ async getTrajectoryConfig() {
1989
+ return this.fetch("/api/trajectories/config");
1990
+ }
1991
+ async updateTrajectoryConfig(config) {
1992
+ return this.fetch("/api/trajectories/config", {
1993
+ method: "PUT",
1994
+ body: JSON.stringify(config),
1995
+ });
1996
+ }
1997
+ async exportTrajectories(options) {
1998
+ const res = await this.rawRequest("/api/trajectories/export", {
1999
+ method: "POST",
2000
+ headers: {
2001
+ "Content-Type": "application/json",
2002
+ },
2003
+ body: JSON.stringify(options),
2004
+ });
2005
+ return res.blob();
2006
+ }
2007
+ async deleteTrajectories(trajectoryIds) {
2008
+ return this.fetch("/api/trajectories", {
2009
+ method: "DELETE",
2010
+ body: JSON.stringify({ trajectoryIds }),
2011
+ });
2012
+ }
2013
+ async clearAllTrajectories() {
2014
+ return this.fetch("/api/trajectories", {
2015
+ method: "DELETE",
2016
+ body: JSON.stringify({ clearAll: true }),
2017
+ });
2018
+ }
2019
+ // ═══════════════════════════════════════════════════════════════════════
2020
+ // System Permissions
2021
+ // ═══════════════════════════════════════════════════════════════════════
2022
+ /**
2023
+ * Get all system permission states.
2024
+ */
2025
+ async getPermissions() {
2026
+ return this.fetch("/api/permissions");
2027
+ }
2028
+ /**
2029
+ * Get a single permission state.
2030
+ */
2031
+ async getPermission(id) {
2032
+ return this.fetch(`/api/permissions/${id}`);
2033
+ }
2034
+ /**
2035
+ * Request a specific permission (triggers OS prompt if applicable).
2036
+ */
2037
+ async requestPermission(id) {
2038
+ return this.fetch(`/api/permissions/${id}/request`, { method: "POST" });
2039
+ }
2040
+ /**
2041
+ * Open system settings for a specific permission.
2042
+ */
2043
+ async openPermissionSettings(id) {
2044
+ await this.fetch(`/api/permissions/${id}/open-settings`, {
2045
+ method: "POST",
2046
+ });
2047
+ }
2048
+ /**
2049
+ * Refresh all permission states from the OS.
2050
+ */
2051
+ async refreshPermissions() {
2052
+ return this.fetch("/api/permissions/refresh", { method: "POST" });
2053
+ }
2054
+ /**
2055
+ * Enable or disable shell access.
2056
+ */
2057
+ async setShellEnabled(enabled) {
2058
+ return this.fetch("/api/permissions/shell", {
2059
+ method: "PUT",
2060
+ body: JSON.stringify({ enabled }),
2061
+ });
2062
+ }
2063
+ /**
2064
+ * Get shell enabled status.
2065
+ */
2066
+ async isShellEnabled() {
2067
+ const result = await this.fetch("/api/permissions/shell");
2068
+ return result.enabled;
2069
+ }
2070
+ /**
2071
+ * Get agent automation permission mode.
2072
+ */
2073
+ async getAgentAutomationMode() {
2074
+ return this.fetch("/api/permissions/automation-mode");
2075
+ }
2076
+ /**
2077
+ * Set agent automation permission mode.
2078
+ */
2079
+ async setAgentAutomationMode(mode) {
2080
+ return this.fetch("/api/permissions/automation-mode", {
2081
+ method: "PUT",
2082
+ body: JSON.stringify({ mode }),
2083
+ });
2084
+ }
2085
+ /**
2086
+ * Get wallet trade execution permission mode.
2087
+ */
2088
+ async getTradePermissionMode() {
2089
+ return this.fetch("/api/permissions/trade-mode");
2090
+ }
2091
+ /**
2092
+ * Set wallet trade execution permission mode.
2093
+ */
2094
+ async setTradePermissionMode(mode) {
2095
+ return this.fetch("/api/permissions/trade-mode", {
2096
+ method: "PUT",
2097
+ body: JSON.stringify({ mode }),
2098
+ });
2099
+ }
2100
+ disconnectWs() {
2101
+ if (this.reconnectTimer) {
2102
+ clearTimeout(this.reconnectTimer);
2103
+ this.reconnectTimer = null;
2104
+ }
2105
+ this.ws?.close();
2106
+ this.ws = null;
2107
+ this.wsSendQueue = [];
2108
+ // Reset connection state on intentional disconnect
2109
+ this.reconnectAttempt = 0;
2110
+ this.disconnectedAt = null;
2111
+ this.connectionState = "disconnected";
2112
+ this.emitConnectionStateChange();
2113
+ }
2114
+ // ═══════════════════════════════════════════════════════════════════════
2115
+ // ERC-8004 Registry
2116
+ // ═══════════════════════════════════════════════════════════════════════
2117
+ async getRegistryStatus() {
2118
+ return this.fetch("/api/registry/status");
2119
+ }
2120
+ async registerAgent(params) {
2121
+ return this.fetch("/api/registry/register", {
2122
+ method: "POST",
2123
+ body: JSON.stringify(params ?? {}),
2124
+ });
2125
+ }
2126
+ async updateRegistryTokenURI(tokenURI) {
2127
+ return this.fetch("/api/registry/update-uri", {
2128
+ method: "POST",
2129
+ body: JSON.stringify({ tokenURI }),
2130
+ });
2131
+ }
2132
+ async syncRegistryProfile(params) {
2133
+ return this.fetch("/api/registry/sync", {
2134
+ method: "POST",
2135
+ body: JSON.stringify(params ?? {}),
2136
+ });
2137
+ }
2138
+ async getRegistryConfig() {
2139
+ return this.fetch("/api/registry/config");
2140
+ }
2141
+ // ═══════════════════════════════════════════════════════════════════════
2142
+ // Drop / Mint
2143
+ // ═══════════════════════════════════════════════════════════════════════
2144
+ async getDropStatus() {
2145
+ return this.fetch("/api/drop/status");
2146
+ }
2147
+ async mintAgent(params) {
2148
+ return this.fetch("/api/drop/mint", {
2149
+ method: "POST",
2150
+ body: JSON.stringify(params ?? {}),
2151
+ });
2152
+ }
2153
+ async mintAgentWhitelist(params) {
2154
+ return this.fetch("/api/drop/mint-whitelist", {
2155
+ method: "POST",
2156
+ body: JSON.stringify(params),
2157
+ });
2158
+ }
2159
+ // ═══════════════════════════════════════════════════════════════════════
2160
+ // Whitelist
2161
+ // ═══════════════════════════════════════════════════════════════════════
2162
+ async getWhitelistStatus() {
2163
+ return this.fetch("/api/whitelist/status");
2164
+ }
2165
+ async generateTwitterVerificationMessage() {
2166
+ return this.fetch("/api/whitelist/twitter/message", { method: "POST" });
2167
+ }
2168
+ async verifyTwitter(tweetUrl) {
2169
+ return this.fetch("/api/whitelist/twitter/verify", {
2170
+ method: "POST",
2171
+ body: JSON.stringify({ tweetUrl }),
2172
+ });
2173
+ }
2174
+ // ── Custom Actions ─────────────────────────────────────────────────────
2175
+ async listCustomActions() {
2176
+ const data = await this.fetch("/api/custom-actions");
2177
+ return data.actions;
2178
+ }
2179
+ async createCustomAction(action) {
2180
+ const data = await this.fetch("/api/custom-actions", { method: "POST", body: JSON.stringify(action) });
2181
+ return data.action;
2182
+ }
2183
+ async updateCustomAction(id, action) {
2184
+ const data = await this.fetch(`/api/custom-actions/${encodeURIComponent(id)}`, { method: "PUT", body: JSON.stringify(action) });
2185
+ return data.action;
2186
+ }
2187
+ async deleteCustomAction(id) {
2188
+ await this.fetch(`/api/custom-actions/${encodeURIComponent(id)}`, {
2189
+ method: "DELETE",
2190
+ });
2191
+ }
2192
+ async testCustomAction(id, params) {
2193
+ return this.fetch(`/api/custom-actions/${encodeURIComponent(id)}/test`, {
2194
+ method: "POST",
2195
+ body: JSON.stringify({ params }),
2196
+ });
2197
+ }
2198
+ async generateCustomAction(prompt) {
2199
+ return this.fetch("/api/custom-actions/generate", {
2200
+ method: "POST",
2201
+ body: JSON.stringify({ prompt }),
2202
+ });
2203
+ }
2204
+ // ═══════════════════════════════════════════════════════════════════════
2205
+ // WhatsApp Pairing
2206
+ // ═══════════════════════════════════════════════════════════════════════
2207
+ async getWhatsAppStatus(accountId = "default") {
2208
+ return this.fetch(`/api/whatsapp/status?accountId=${encodeURIComponent(accountId)}`);
2209
+ }
2210
+ async startWhatsAppPairing(accountId = "default") {
2211
+ return this.fetch("/api/whatsapp/pair", {
2212
+ method: "POST",
2213
+ body: JSON.stringify({ accountId }),
2214
+ });
2215
+ }
2216
+ async stopWhatsAppPairing(accountId = "default") {
2217
+ return this.fetch("/api/whatsapp/pair/stop", {
2218
+ method: "POST",
2219
+ body: JSON.stringify({ accountId }),
2220
+ });
2221
+ }
2222
+ async disconnectWhatsApp(accountId = "default") {
2223
+ return this.fetch("/api/whatsapp/disconnect", {
2224
+ method: "POST",
2225
+ body: JSON.stringify({ accountId }),
2226
+ });
2227
+ }
2228
+ // --- Bug Report ---
2229
+ async checkBugReportInfo() {
2230
+ return this.fetch("/api/bug-report/info");
2231
+ }
2232
+ async submitBugReport(report) {
2233
+ return this.fetch("/api/bug-report", {
2234
+ method: "POST",
2235
+ body: JSON.stringify(report),
2236
+ });
2237
+ }
2238
+ // ── Coding Agents ───────────────────────────────────────────────────
2239
+ async getCodingAgentStatus() {
2240
+ try {
2241
+ return await this.fetch("/api/coding-agents/coordinator/status");
2242
+ }
2243
+ catch {
2244
+ return null;
2245
+ }
2246
+ }
2247
+ async stopCodingAgent(sessionId) {
2248
+ try {
2249
+ await this.fetch(`/api/coding-agents/${encodeURIComponent(sessionId)}/stop`, { method: "POST" });
2250
+ return true;
2251
+ }
2252
+ catch {
2253
+ return false;
2254
+ }
2255
+ }
2256
+ async listCodingAgentScratchWorkspaces() {
2257
+ try {
2258
+ return await this.fetch("/api/coding-agents/scratch");
2259
+ }
2260
+ catch {
2261
+ return [];
2262
+ }
2263
+ }
2264
+ async keepCodingAgentScratchWorkspace(sessionId) {
2265
+ try {
2266
+ await this.fetch(`/api/coding-agents/${encodeURIComponent(sessionId)}/scratch/keep`, { method: "POST" });
2267
+ return true;
2268
+ }
2269
+ catch {
2270
+ return false;
2271
+ }
2272
+ }
2273
+ async deleteCodingAgentScratchWorkspace(sessionId) {
2274
+ try {
2275
+ // Keep POST for compatibility with plugin route handlers.
2276
+ await this.fetch(`/api/coding-agents/${encodeURIComponent(sessionId)}/scratch/delete`, { method: "POST" });
2277
+ return true;
2278
+ }
2279
+ catch {
2280
+ return false;
2281
+ }
2282
+ }
2283
+ async promoteCodingAgentScratchWorkspace(sessionId, name) {
2284
+ try {
2285
+ const response = await this.fetch(`/api/coding-agents/${encodeURIComponent(sessionId)}/scratch/promote`, {
2286
+ method: "POST",
2287
+ body: JSON.stringify(name ? { name } : {}),
2288
+ });
2289
+ return response.scratch ?? null;
2290
+ }
2291
+ catch {
2292
+ return null;
2293
+ }
2294
+ }
2295
+ // ── PTY Terminal (xterm.js bridge) ─────────────────────────────────────
2296
+ /** Subscribe to live PTY output for a session over WebSocket. */
2297
+ subscribePtyOutput(sessionId) {
2298
+ this.sendWsMessage({ type: "pty-subscribe", sessionId });
2299
+ }
2300
+ /** Unsubscribe from live PTY output for a session. */
2301
+ unsubscribePtyOutput(sessionId) {
2302
+ this.sendWsMessage({ type: "pty-unsubscribe", sessionId });
2303
+ }
2304
+ /** Send raw keyboard input to a PTY session. */
2305
+ sendPtyInput(sessionId, data) {
2306
+ this.sendWsMessage({ type: "pty-input", sessionId, data });
2307
+ }
2308
+ /** Resize a PTY session's terminal dimensions. */
2309
+ resizePty(sessionId, cols, rows) {
2310
+ this.sendWsMessage({ type: "pty-resize", sessionId, cols, rows });
2311
+ }
2312
+ /** Fetch buffered terminal output (raw ANSI) for xterm.js hydration. */
2313
+ async getPtyBufferedOutput(sessionId) {
2314
+ try {
2315
+ const res = await this.fetch(`/api/coding-agents/${encodeURIComponent(sessionId)}/buffered-output`);
2316
+ return res.output ?? "";
2317
+ }
2318
+ catch {
2319
+ return "";
2320
+ }
2321
+ }
2322
+ // ── Stream controls ─────────────────────────────────────────────────────
2323
+ async streamGoLive() {
2324
+ return this.fetch("/api/stream/live", { method: "POST" });
2325
+ }
2326
+ async streamGoOffline() {
2327
+ return this.fetch("/api/stream/offline", { method: "POST" });
2328
+ }
2329
+ async streamStatus() {
2330
+ return this.fetch("/api/stream/status");
2331
+ }
2332
+ async getStreamingDestinations() {
2333
+ return this.fetch("/api/streaming/destinations");
2334
+ }
2335
+ async setActiveDestination(destinationId) {
2336
+ return this.fetch("/api/streaming/destination", {
2337
+ method: "POST",
2338
+ body: JSON.stringify({ destinationId }),
2339
+ });
2340
+ }
2341
+ async setStreamVolume(volume) {
2342
+ return this.fetch("/api/stream/volume", {
2343
+ method: "POST",
2344
+ body: JSON.stringify({ volume }),
2345
+ });
2346
+ }
2347
+ async muteStream() {
2348
+ return this.fetch("/api/stream/mute", { method: "POST" });
2349
+ }
2350
+ async unmuteStream() {
2351
+ return this.fetch("/api/stream/unmute", { method: "POST" });
2352
+ }
2353
+ // ── Stream voice (TTS) ───────────────────────────────────────────────
2354
+ async getStreamVoice() {
2355
+ return this.fetch("/api/stream/voice");
2356
+ }
2357
+ async saveStreamVoice(settings) {
2358
+ return this.fetch("/api/stream/voice", {
2359
+ method: "POST",
2360
+ body: JSON.stringify(settings),
2361
+ });
2362
+ }
2363
+ async streamVoiceSpeak(text) {
2364
+ return this.fetch("/api/stream/voice/speak", {
2365
+ method: "POST",
2366
+ body: JSON.stringify({ text }),
2367
+ });
2368
+ }
2369
+ // ── Overlay layout ────────────────────────────────────────────────────
2370
+ async getOverlayLayout(destinationId) {
2371
+ const qs = destinationId
2372
+ ? `?destination=${encodeURIComponent(destinationId)}`
2373
+ : "";
2374
+ return this.fetch(`/api/stream/overlay-layout${qs}`);
2375
+ }
2376
+ async saveOverlayLayout(layout, destinationId) {
2377
+ const qs = destinationId
2378
+ ? `?destination=${encodeURIComponent(destinationId)}`
2379
+ : "";
2380
+ return this.fetch(`/api/stream/overlay-layout${qs}`, {
2381
+ method: "POST",
2382
+ body: JSON.stringify({ layout }),
2383
+ });
2384
+ }
2385
+ // ── Stream source picker ──────────────────────────────────────────────
2386
+ async getStreamSource() {
2387
+ return this.fetch("/api/stream/source");
2388
+ }
2389
+ async setStreamSource(sourceType, customUrl) {
2390
+ return this.fetch("/api/stream/source", {
2391
+ method: "POST",
2392
+ body: JSON.stringify({ sourceType, customUrl }),
2393
+ });
2394
+ }
2395
+ // ── Stream visual settings (theme, avatar for headless parity) ────────
2396
+ async getStreamSettings() {
2397
+ return this.fetch("/api/stream/settings");
2398
+ }
2399
+ async saveStreamSettings(settings) {
2400
+ return this.fetch("/api/stream/settings", {
2401
+ method: "POST",
2402
+ body: JSON.stringify({ settings }),
2403
+ });
2404
+ }
2405
+ // ── Direct Eliza Cloud Auth (no local backend required) ─────────────
2406
+ /**
2407
+ * Initiate a direct login to Eliza Cloud without going through a local agent.
2408
+ * Used in sandbox mode when no local backend exists yet.
2409
+ */
2410
+ async cloudLoginDirect(cloudApiBase) {
2411
+ const res = await fetch(`${cloudApiBase}/api/v1/auth/login`, {
2412
+ method: "POST",
2413
+ headers: { "Content-Type": "application/json" },
2414
+ });
2415
+ if (!res.ok) {
2416
+ return { ok: false, error: `Login failed (${res.status})` };
2417
+ }
2418
+ return res.json();
2419
+ }
2420
+ /**
2421
+ * Poll a direct Eliza Cloud login session for authentication status.
2422
+ */
2423
+ async cloudLoginPollDirect(cloudApiBase, sessionId) {
2424
+ const res = await fetch(`${cloudApiBase}/api/v1/auth/login/status?sessionId=${encodeURIComponent(sessionId)}`);
2425
+ if (!res.ok) {
2426
+ return { status: "error", error: `Poll failed (${res.status})` };
2427
+ }
2428
+ return res.json();
2429
+ }
2430
+ // ── Eliza Cloud Sandbox Provisioning ───────────────────────────────
2431
+ /**
2432
+ * Create a sandbox agent on Eliza Cloud and provision it.
2433
+ * Returns the bridge URL when provisioning completes.
2434
+ *
2435
+ * Flow:
2436
+ * 1. POST /api/v1/milady/agents — create agent record
2437
+ * 2. POST /api/v1/milady/agents/{id}/provision — start async provisioning
2438
+ * 3. Poll GET /api/v1/jobs/{jobId} until completed
2439
+ * 4. Return bridgeUrl from job result
2440
+ */
2441
+ async provisionCloudSandbox(options) {
2442
+ const { cloudApiBase, authToken, name, bio, onProgress } = options;
2443
+ const headers = {
2444
+ "Content-Type": "application/json",
2445
+ Authorization: `Bearer ${authToken}`,
2446
+ };
2447
+ onProgress?.("creating", "Creating agent...");
2448
+ // Step 1: Create agent
2449
+ const createRes = await fetch(`${cloudApiBase}/api/v1/milady/agents`, {
2450
+ method: "POST",
2451
+ headers,
2452
+ body: JSON.stringify({ name, bio }),
2453
+ });
2454
+ if (!createRes.ok) {
2455
+ const err = await createRes.text().catch(() => "Unknown error");
2456
+ throw new Error(`Failed to create cloud agent: ${err}`);
2457
+ }
2458
+ const createData = (await createRes.json());
2459
+ const agentId = createData.id;
2460
+ onProgress?.("provisioning", "Provisioning sandbox environment...");
2461
+ // Step 2: Start provisioning
2462
+ const provisionRes = await fetch(`${cloudApiBase}/api/v1/milady/agents/${agentId}/provision`, { method: "POST", headers });
2463
+ if (!provisionRes.ok) {
2464
+ const err = await provisionRes.text().catch(() => "Unknown error");
2465
+ throw new Error(`Failed to start provisioning: ${err}`);
2466
+ }
2467
+ const provisionData = (await provisionRes.json());
2468
+ const jobId = provisionData.jobId;
2469
+ // Step 3: Poll job status
2470
+ const deadline = Date.now() + 120_000; // 2 minute timeout
2471
+ while (Date.now() < deadline) {
2472
+ await new Promise((r) => setTimeout(r, 2000));
2473
+ const jobRes = await fetch(`${cloudApiBase}/api/v1/jobs/${jobId}`, {
2474
+ headers,
2475
+ });
2476
+ if (!jobRes.ok)
2477
+ continue;
2478
+ const jobData = (await jobRes.json());
2479
+ if (jobData.status === "completed" && jobData.result?.bridgeUrl) {
2480
+ onProgress?.("ready", "Sandbox ready!");
2481
+ return { bridgeUrl: jobData.result.bridgeUrl, agentId };
2482
+ }
2483
+ if (jobData.status === "failed") {
2484
+ throw new Error(`Provisioning failed: ${jobData.error ?? "Unknown error"}`);
2485
+ }
2486
+ onProgress?.("provisioning", `Status: ${jobData.status}...`);
2487
+ }
2488
+ throw new Error("Provisioning timed out after 2 minutes");
2489
+ }
2490
+ }
2491
+ // Singleton
2492
+ export const client = new MiladyClient();