@agent-native/core 0.117.2 → 0.118.0

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 (524) hide show
  1. package/corpus/README.md +3 -3
  2. package/corpus/core/CHANGELOG.md +30 -0
  3. package/corpus/core/docs/content/custom-design-system.mdx +445 -0
  4. package/corpus/core/docs/content/toolkit-ui.mdx +16 -0
  5. package/corpus/core/package.json +1 -1
  6. package/corpus/core/src/a2a/types.ts +1 -0
  7. package/corpus/core/src/agent/types.ts +1 -1
  8. package/corpus/core/src/client/AgentPanel.tsx +90 -107
  9. package/corpus/core/src/client/AssistantChat.tsx +30 -13
  10. package/corpus/core/src/client/CommandMenu.tsx +68 -178
  11. package/corpus/core/src/client/agent-chat-adapter.ts +3 -1
  12. package/corpus/core/src/client/app-providers.tsx +1 -1
  13. package/corpus/core/src/client/chat/message-components.tsx +116 -10
  14. package/corpus/core/src/client/chat/tool-call-display.tsx +26 -5
  15. package/corpus/core/src/client/chat/widgets/InlineExtensionWidget.tsx +14 -40
  16. package/corpus/core/src/client/components/ui/message-scroller.tsx +15 -1
  17. package/corpus/core/src/client/i18n.tsx +22 -0
  18. package/corpus/core/src/client/index.ts +17 -0
  19. package/corpus/core/src/client/org/TeamPage.tsx +257 -153
  20. package/corpus/core/src/client/progress/RunsTray.tsx +89 -88
  21. package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +5 -2
  22. package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +34 -13
  23. package/corpus/core/src/client/resources/mcp-integration-catalog.ts +13 -0
  24. package/corpus/core/src/client/settings/DemoModeSection.tsx +6 -18
  25. package/corpus/core/src/client/settings/SecretsSection.tsx +97 -52
  26. package/corpus/core/src/client/settings/SettingsPanel.tsx +202 -246
  27. package/corpus/core/src/client/settings/SettingsTabsPage.tsx +23 -2
  28. package/corpus/core/src/client/settings/VoiceTranscriptionSection.tsx +7 -18
  29. package/corpus/core/src/client/settings/index.ts +7 -0
  30. package/corpus/core/src/client/settings/useSettingsPanelController.ts +155 -0
  31. package/corpus/core/src/client/setup-connections/BuilderConnectCard.tsx +116 -51
  32. package/corpus/core/src/client/setup-connections/index.ts +10 -0
  33. package/corpus/core/src/client/setup-connections/useBuilderConnectCardController.ts +82 -0
  34. package/corpus/core/src/client/sharing/ShareButton.tsx +64 -586
  35. package/corpus/core/src/client/sharing/ShareDialog.tsx +299 -633
  36. package/corpus/core/src/client/sharing/index.ts +42 -0
  37. package/corpus/core/src/client/sharing/share-controller-helpers.ts +318 -0
  38. package/corpus/core/src/client/sharing/useShareButtonController.ts +600 -0
  39. package/corpus/core/src/client/sharing/useShareDialogController.ts +559 -0
  40. package/corpus/core/src/client/sse-event-processor.ts +23 -0
  41. package/corpus/core/src/client/tool-display.ts +71 -0
  42. package/corpus/core/src/client/use-agent-engine-configured.ts +12 -19
  43. package/corpus/core/src/client/use-chat-threads.ts +33 -12
  44. package/corpus/core/src/localization/default-messages.ts +5 -0
  45. package/corpus/core/src/mcp-client/oauth-routes.ts +16 -2
  46. package/corpus/core/src/scripts/call-agent.ts +5 -1
  47. package/corpus/core/src/server/realtime-voice.ts +1 -1
  48. package/corpus/core/src/styles/agent-native.css +0 -24
  49. package/corpus/core/src/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  50. package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  51. package/corpus/core/src/templates/default/.agents/skills/frontend-design/SKILL.md +22 -2
  52. package/corpus/core/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +28 -4
  53. package/corpus/core/src/templates/default/app/components/ui/toolkit-provider.tsx +10 -0
  54. package/corpus/core/src/templates/default/app/design-system.ts +3 -0
  55. package/corpus/core/src/templates/default/app/root.tsx +5 -2
  56. package/corpus/core/src/templates/default/package.json +1 -0
  57. package/corpus/core/src/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  58. package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  59. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  60. package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  61. package/corpus/core/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +22 -2
  62. package/corpus/core/src/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +28 -4
  63. package/corpus/core/src/vite/client.ts +39 -0
  64. package/corpus/templates/analytics/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  65. package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  66. package/corpus/templates/analytics/.agents/skills/frontend-design/SKILL.md +22 -2
  67. package/corpus/templates/analytics/.agents/skills/shadcn-ui/SKILL.md +28 -4
  68. package/corpus/templates/analytics/app/components/ui/toolkit-provider.tsx +6 -1
  69. package/corpus/templates/analytics/app/design-system.ts +3 -0
  70. package/corpus/templates/assets/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  71. package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  72. package/corpus/templates/assets/.agents/skills/frontend-design/SKILL.md +22 -2
  73. package/corpus/templates/assets/.agents/skills/shadcn-ui/SKILL.md +28 -4
  74. package/corpus/templates/assets/app/components/ui/alert.tsx +1 -0
  75. package/corpus/templates/assets/app/components/ui/toolkit-provider.tsx +6 -1
  76. package/corpus/templates/assets/app/design-system.ts +3 -0
  77. package/corpus/templates/assets/app/routes/brand-kits.$id_.presets.$presetId.tsx +26 -30
  78. package/corpus/templates/brain/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  79. package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  80. package/corpus/templates/brain/.agents/skills/frontend-design/SKILL.md +22 -2
  81. package/corpus/templates/brain/.agents/skills/shadcn-ui/SKILL.md +28 -4
  82. package/corpus/templates/brain/app/components/ui/dialog.tsx +1 -0
  83. package/corpus/templates/brain/app/components/ui/toolkit-provider.tsx +6 -1
  84. package/corpus/templates/brain/app/design-system.ts +3 -0
  85. package/corpus/templates/brain/app/routes/sources.tsx +8 -8
  86. package/corpus/templates/calendar/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  87. package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  88. package/corpus/templates/calendar/.agents/skills/frontend-design/SKILL.md +22 -2
  89. package/corpus/templates/calendar/.agents/skills/shadcn-ui/SKILL.md +28 -4
  90. package/corpus/templates/calendar/app/components/ui/toolkit-provider.tsx +6 -1
  91. package/corpus/templates/calendar/app/design-system.ts +3 -0
  92. package/corpus/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  93. package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  94. package/corpus/templates/chat/.agents/skills/frontend-design/SKILL.md +22 -2
  95. package/corpus/templates/chat/.agents/skills/shadcn-ui/SKILL.md +28 -4
  96. package/corpus/templates/chat/app/components/ui/toolkit-provider.tsx +6 -1
  97. package/corpus/templates/chat/app/design-system.ts +3 -0
  98. package/corpus/templates/clips/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  99. package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  100. package/corpus/templates/clips/.agents/skills/frontend-design/SKILL.md +22 -2
  101. package/corpus/templates/clips/.agents/skills/shadcn-ui/SKILL.md +28 -4
  102. package/corpus/templates/clips/app/components/ui/toolkit-provider.tsx +6 -1
  103. package/corpus/templates/clips/app/design-system.ts +3 -0
  104. package/corpus/templates/clips/app/routes/_app.library._index.tsx +1 -1
  105. package/corpus/templates/clips/changelog/2026-07-22-fixed-windows-recordings-aborting-during-the-countdown.md +6 -0
  106. package/corpus/templates/clips/changelog/2026-07-22-permissions-and-rewind-controls-are-now-grouped-with-clearer.md +6 -0
  107. package/corpus/templates/clips/changelog/2026-07-22-the-desktop-popover-opens-centered-under-the-menu-bar-icon-o.md +6 -0
  108. package/corpus/templates/clips/desktop/src/app.tsx +86 -82
  109. package/corpus/templates/clips/desktop/src/styles.css +13 -0
  110. package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +10 -1
  111. package/corpus/templates/clips/desktop/src-tauri/src/shortcuts.rs +37 -2
  112. package/corpus/templates/clips/desktop/src-tauri/src/tray.rs +18 -0
  113. package/corpus/templates/content/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  114. package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  115. package/corpus/templates/content/.agents/skills/frontend-design/SKILL.md +22 -2
  116. package/corpus/templates/content/.agents/skills/shadcn-ui/SKILL.md +28 -4
  117. package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +41 -59
  118. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +41 -41
  119. package/corpus/templates/content/app/components/editor/database/GalleryView.tsx +2 -1
  120. package/corpus/templates/content/app/components/editor/database/ListView.tsx +2 -1
  121. package/corpus/templates/content/app/components/editor/database/TimelineView.tsx +9 -9
  122. package/corpus/templates/content/app/components/editor/database/sidebar.tsx +7 -7
  123. package/corpus/templates/content/app/components/editor/database-sources/BuilderSourceReviewDialog.tsx +11 -11
  124. package/corpus/templates/content/app/components/ui/checkbox.tsx +1 -0
  125. package/corpus/templates/content/app/components/ui/collapsible.tsx +1 -0
  126. package/corpus/templates/content/app/components/ui/toolkit-provider.tsx +6 -1
  127. package/corpus/templates/content/app/design-system.ts +3 -0
  128. package/corpus/templates/content/app/global.css +29 -3
  129. package/corpus/templates/content/changelog/2026-07-22-page-actions-are-grouped-into-the-three-dots-menu-for-a-clea.md +6 -0
  130. package/corpus/templates/crm/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  131. package/corpus/templates/crm/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  132. package/corpus/templates/crm/app/components/crm/CreateCrmRecordDialog.tsx +10 -10
  133. package/corpus/templates/crm/app/components/crm/CrmDashboardPanel.tsx +1 -6
  134. package/corpus/templates/crm/app/components/crm/CrmSignalsPanel.tsx +3 -2
  135. package/corpus/templates/crm/app/components/crm/IntelligenceSettings.tsx +13 -12
  136. package/corpus/templates/crm/app/components/crm/RecordActions.tsx +17 -17
  137. package/corpus/templates/crm/app/components/crm/RecordGrid.tsx +8 -8
  138. package/corpus/templates/crm/app/components/crm/RecordWorkspace.tsx +3 -8
  139. package/corpus/templates/crm/app/components/crm/SavedViewDataProgram.tsx +2 -1
  140. package/corpus/templates/crm/app/components/crm/Surface.tsx +3 -2
  141. package/corpus/templates/crm/app/components/crm/WorkOverview.tsx +2 -2
  142. package/corpus/templates/crm/app/components/layout/CrmLayout.tsx +7 -7
  143. package/corpus/templates/crm/app/components/layout/CrmSidebar.tsx +1 -1
  144. package/corpus/templates/crm/app/components/ui/alert-dialog.tsx +1 -0
  145. package/corpus/templates/crm/app/components/ui/badge.tsx +1 -0
  146. package/corpus/templates/crm/app/components/ui/button.tsx +1 -0
  147. package/corpus/templates/crm/app/components/ui/card.tsx +1 -0
  148. package/corpus/templates/crm/app/components/ui/dialog.tsx +1 -0
  149. package/corpus/templates/crm/app/components/ui/input.tsx +1 -0
  150. package/corpus/templates/crm/app/components/ui/label.tsx +1 -0
  151. package/corpus/templates/crm/app/components/ui/select.tsx +1 -0
  152. package/corpus/templates/crm/app/components/ui/sheet.tsx +1 -0
  153. package/corpus/templates/crm/app/components/ui/skeleton.tsx +1 -0
  154. package/corpus/templates/crm/app/components/ui/switch.tsx +1 -0
  155. package/corpus/templates/crm/app/components/ui/table.tsx +1 -0
  156. package/corpus/templates/crm/app/components/ui/tabs.tsx +1 -0
  157. package/corpus/templates/crm/app/components/ui/textarea.tsx +1 -0
  158. package/corpus/templates/crm/app/components/ui/toolkit-provider.tsx +17 -0
  159. package/corpus/templates/crm/app/design-system.ts +3 -0
  160. package/corpus/templates/crm/app/root.tsx +9 -6
  161. package/corpus/templates/crm/app/routes/dashboard.tsx +1 -1
  162. package/corpus/templates/crm/app/routes/proposals.tsx +13 -13
  163. package/corpus/templates/crm/app/routes/setup.tsx +9 -9
  164. package/corpus/templates/crm/app/routes/tasks.tsx +14 -14
  165. package/corpus/templates/crm/app/routes/views.tsx +16 -16
  166. package/corpus/templates/design/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  167. package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  168. package/corpus/templates/design/.agents/skills/frontend-design/SKILL.md +22 -2
  169. package/corpus/templates/design/.agents/skills/shadcn-ui/SKILL.md +28 -4
  170. package/corpus/templates/design/app/components/editor/PromptDialog.tsx +8 -8
  171. package/corpus/templates/design/app/components/ui/command.tsx +1 -0
  172. package/corpus/templates/design/app/components/ui/toolkit-provider.tsx +6 -1
  173. package/corpus/templates/design/app/design-system.ts +3 -0
  174. package/corpus/templates/dispatch/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  175. package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  176. package/corpus/templates/dispatch/.agents/skills/frontend-design/SKILL.md +22 -2
  177. package/corpus/templates/dispatch/.agents/skills/shadcn-ui/SKILL.md +28 -4
  178. package/corpus/templates/dispatch/app/components/ui/button.tsx +1 -0
  179. package/corpus/templates/dispatch/app/components/ui/toolkit-provider.tsx +17 -0
  180. package/corpus/templates/dispatch/app/design-system.ts +3 -0
  181. package/corpus/templates/dispatch/app/root.tsx +10 -7
  182. package/corpus/templates/dispatch/package.json +1 -0
  183. package/corpus/templates/forms/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  184. package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  185. package/corpus/templates/forms/.agents/skills/frontend-design/SKILL.md +22 -2
  186. package/corpus/templates/forms/.agents/skills/shadcn-ui/SKILL.md +28 -4
  187. package/corpus/templates/forms/app/components/ui/toolkit-provider.tsx +6 -1
  188. package/corpus/templates/forms/app/design-system.ts +3 -0
  189. package/corpus/templates/macros/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  190. package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  191. package/corpus/templates/macros/.agents/skills/frontend-design/SKILL.md +22 -2
  192. package/corpus/templates/macros/.agents/skills/shadcn-ui/SKILL.md +28 -4
  193. package/corpus/templates/macros/app/components/ui/toolkit-provider.tsx +6 -1
  194. package/corpus/templates/macros/app/design-system.ts +3 -0
  195. package/corpus/templates/mail/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  196. package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  197. package/corpus/templates/mail/.agents/skills/frontend-design/SKILL.md +22 -2
  198. package/corpus/templates/mail/.agents/skills/shadcn-ui/SKILL.md +28 -4
  199. package/corpus/templates/mail/app/components/email/EmailThread.tsx +134 -93
  200. package/corpus/templates/mail/app/components/email/email-iframe-document.ts +8 -2
  201. package/corpus/templates/mail/app/components/ui/textarea.tsx +1 -21
  202. package/corpus/templates/mail/app/components/ui/toolkit-provider.tsx +6 -1
  203. package/corpus/templates/mail/app/design-system.ts +3 -0
  204. package/corpus/templates/mail/changelog/2026-07-22-email-messages-no-longer-flash-with-an-unstyled-page-while-l.md +6 -0
  205. package/corpus/templates/plan/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  206. package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  207. package/corpus/templates/plan/.agents/skills/frontend-design/SKILL.md +22 -2
  208. package/corpus/templates/plan/.agents/skills/shadcn-ui/SKILL.md +28 -4
  209. package/corpus/templates/plan/app/components/plan/PlanContentRenderer.tsx +1 -1
  210. package/corpus/templates/plan/app/components/ui/toolkit-provider.tsx +6 -1
  211. package/corpus/templates/plan/app/design-system.ts +3 -0
  212. package/corpus/templates/slides/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  213. package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  214. package/corpus/templates/slides/.agents/skills/frontend-design/SKILL.md +22 -2
  215. package/corpus/templates/slides/.agents/skills/shadcn-ui/SKILL.md +28 -4
  216. package/corpus/templates/slides/app/components/ui/toolkit-provider.tsx +6 -1
  217. package/corpus/templates/slides/app/design-system.ts +3 -0
  218. package/corpus/templates/tasks/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  219. package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  220. package/corpus/templates/tasks/.agents/skills/frontend-design/SKILL.md +22 -2
  221. package/corpus/templates/tasks/.agents/skills/shadcn-ui/SKILL.md +28 -4
  222. package/corpus/templates/tasks/app/components/ui/toolkit-provider.tsx +17 -0
  223. package/corpus/templates/tasks/app/design-system.ts +3 -0
  224. package/corpus/templates/tasks/app/root.tsx +5 -2
  225. package/corpus/toolkit/CHANGELOG.md +14 -0
  226. package/corpus/toolkit/agent-native.eject.json +71 -0
  227. package/corpus/toolkit/package.json +31 -1
  228. package/corpus/toolkit/src/chat-history/ChatHistoryRail.tsx +100 -39
  229. package/corpus/toolkit/src/chat-history/index.ts +9 -0
  230. package/corpus/toolkit/src/chat-history/useChatHistoryRailController.ts +76 -0
  231. package/corpus/toolkit/src/chat-history.css +2 -0
  232. package/corpus/toolkit/src/composer/ComposerPlusMenu.tsx +11 -8
  233. package/corpus/toolkit/src/composer/PromptComposer.tsx +27 -6
  234. package/corpus/toolkit/src/composer/useRealtimeVoiceMode.tsx +107 -22
  235. package/corpus/toolkit/src/conformance/__fixtures__/css-in-js-adapter.tsx +401 -0
  236. package/corpus/toolkit/src/conformance/index.ts +3 -0
  237. package/corpus/toolkit/src/conformance/runner.tsx +710 -0
  238. package/corpus/toolkit/src/conformance/types.ts +45 -0
  239. package/corpus/toolkit/src/conformance/version.ts +22 -0
  240. package/corpus/toolkit/src/design-system/components.tsx +146 -0
  241. package/corpus/toolkit/src/design-system/context.tsx +31 -0
  242. package/corpus/toolkit/src/design-system/default-adapter.tsx +915 -0
  243. package/corpus/toolkit/src/design-system/definition.ts +14 -0
  244. package/corpus/toolkit/src/design-system/error-boundary.tsx +37 -0
  245. package/corpus/toolkit/src/design-system/index.ts +7 -0
  246. package/corpus/toolkit/src/design-system/theme.ts +145 -0
  247. package/corpus/toolkit/src/design-system/types.ts +363 -0
  248. package/corpus/toolkit/src/provider.tsx +98 -5
  249. package/corpus/toolkit/src/ui/button.tsx +95 -6
  250. package/corpus/toolkit/src/ui/dialog.tsx +48 -23
  251. package/corpus/toolkit/src/ui/popover.tsx +16 -2
  252. package/corpus/toolkit/src/ui/select.tsx +7 -3
  253. package/corpus/toolkit/src/ui/sidebar.tsx +47 -48
  254. package/corpus/toolkit/src/ui/tooltip.tsx +7 -3
  255. package/dist/a2a/types.d.ts +1 -1
  256. package/dist/a2a/types.d.ts.map +1 -1
  257. package/dist/a2a/types.js.map +1 -1
  258. package/dist/agent/types.d.ts +1 -1
  259. package/dist/agent/types.d.ts.map +1 -1
  260. package/dist/agent/types.js.map +1 -1
  261. package/dist/client/AgentPanel.d.ts.map +1 -1
  262. package/dist/client/AgentPanel.js +14 -14
  263. package/dist/client/AgentPanel.js.map +1 -1
  264. package/dist/client/AssistantChat.d.ts.map +1 -1
  265. package/dist/client/AssistantChat.js +26 -15
  266. package/dist/client/AssistantChat.js.map +1 -1
  267. package/dist/client/CommandMenu.d.ts.map +1 -1
  268. package/dist/client/CommandMenu.js +18 -106
  269. package/dist/client/CommandMenu.js.map +1 -1
  270. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  271. package/dist/client/agent-chat-adapter.js +2 -1
  272. package/dist/client/agent-chat-adapter.js.map +1 -1
  273. package/dist/client/app-providers.d.ts.map +1 -1
  274. package/dist/client/app-providers.js +1 -1
  275. package/dist/client/app-providers.js.map +1 -1
  276. package/dist/client/chat/message-components.d.ts +9 -1
  277. package/dist/client/chat/message-components.d.ts.map +1 -1
  278. package/dist/client/chat/message-components.js +62 -7
  279. package/dist/client/chat/message-components.js.map +1 -1
  280. package/dist/client/chat/tool-call-display.d.ts.map +1 -1
  281. package/dist/client/chat/tool-call-display.js +20 -5
  282. package/dist/client/chat/tool-call-display.js.map +1 -1
  283. package/dist/client/chat/widgets/InlineExtensionWidget.d.ts.map +1 -1
  284. package/dist/client/chat/widgets/InlineExtensionWidget.js +9 -12
  285. package/dist/client/chat/widgets/InlineExtensionWidget.js.map +1 -1
  286. package/dist/client/components/ui/message-scroller.d.ts +1 -1
  287. package/dist/client/components/ui/message-scroller.d.ts.map +1 -1
  288. package/dist/client/components/ui/message-scroller.js +4 -3
  289. package/dist/client/components/ui/message-scroller.js.map +1 -1
  290. package/dist/client/i18n.d.ts.map +1 -1
  291. package/dist/client/i18n.js +9 -0
  292. package/dist/client/i18n.js.map +1 -1
  293. package/dist/client/index.d.ts +2 -2
  294. package/dist/client/index.d.ts.map +1 -1
  295. package/dist/client/index.js +2 -2
  296. package/dist/client/index.js.map +1 -1
  297. package/dist/client/org/TeamPage.d.ts.map +1 -1
  298. package/dist/client/org/TeamPage.js +41 -33
  299. package/dist/client/org/TeamPage.js.map +1 -1
  300. package/dist/client/progress/RunsTray.d.ts.map +1 -1
  301. package/dist/client/progress/RunsTray.js +9 -10
  302. package/dist/client/progress/RunsTray.js.map +1 -1
  303. package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
  304. package/dist/client/resources/McpConnectionSuggestion.js +5 -4
  305. package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
  306. package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
  307. package/dist/client/resources/McpIntegrationDialog.js +10 -8
  308. package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
  309. package/dist/client/resources/mcp-integration-catalog.d.ts +1 -0
  310. package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
  311. package/dist/client/resources/mcp-integration-catalog.js +13 -0
  312. package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
  313. package/dist/client/settings/DemoModeSection.d.ts.map +1 -1
  314. package/dist/client/settings/DemoModeSection.js +2 -5
  315. package/dist/client/settings/DemoModeSection.js.map +1 -1
  316. package/dist/client/settings/SecretsSection.d.ts.map +1 -1
  317. package/dist/client/settings/SecretsSection.js +18 -6
  318. package/dist/client/settings/SecretsSection.js.map +1 -1
  319. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  320. package/dist/client/settings/SettingsPanel.js +52 -117
  321. package/dist/client/settings/SettingsPanel.js.map +1 -1
  322. package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
  323. package/dist/client/settings/SettingsTabsPage.js +16 -1
  324. package/dist/client/settings/SettingsTabsPage.js.map +1 -1
  325. package/dist/client/settings/VoiceTranscriptionSection.d.ts.map +1 -1
  326. package/dist/client/settings/VoiceTranscriptionSection.js +2 -5
  327. package/dist/client/settings/VoiceTranscriptionSection.js.map +1 -1
  328. package/dist/client/settings/index.d.ts +1 -0
  329. package/dist/client/settings/index.d.ts.map +1 -1
  330. package/dist/client/settings/index.js +1 -0
  331. package/dist/client/settings/index.js.map +1 -1
  332. package/dist/client/settings/useSettingsPanelController.d.ts +22 -0
  333. package/dist/client/settings/useSettingsPanelController.d.ts.map +1 -0
  334. package/dist/client/settings/useSettingsPanelController.js +103 -0
  335. package/dist/client/settings/useSettingsPanelController.js.map +1 -0
  336. package/dist/client/setup-connections/BuilderConnectCard.d.ts +14 -6
  337. package/dist/client/setup-connections/BuilderConnectCard.d.ts.map +1 -1
  338. package/dist/client/setup-connections/BuilderConnectCard.js +24 -16
  339. package/dist/client/setup-connections/BuilderConnectCard.js.map +1 -1
  340. package/dist/client/setup-connections/index.d.ts +2 -1
  341. package/dist/client/setup-connections/index.d.ts.map +1 -1
  342. package/dist/client/setup-connections/index.js +2 -1
  343. package/dist/client/setup-connections/index.js.map +1 -1
  344. package/dist/client/setup-connections/useBuilderConnectCardController.d.ts +34 -0
  345. package/dist/client/setup-connections/useBuilderConnectCardController.d.ts.map +1 -0
  346. package/dist/client/setup-connections/useBuilderConnectCardController.js +39 -0
  347. package/dist/client/setup-connections/useBuilderConnectCardController.js.map +1 -0
  348. package/dist/client/sharing/ShareButton.d.ts +2 -1
  349. package/dist/client/sharing/ShareButton.d.ts.map +1 -1
  350. package/dist/client/sharing/ShareButton.js +17 -463
  351. package/dist/client/sharing/ShareButton.js.map +1 -1
  352. package/dist/client/sharing/ShareDialog.d.ts +6 -6
  353. package/dist/client/sharing/ShareDialog.d.ts.map +1 -1
  354. package/dist/client/sharing/ShareDialog.js +69 -283
  355. package/dist/client/sharing/ShareDialog.js.map +1 -1
  356. package/dist/client/sharing/index.d.ts +3 -0
  357. package/dist/client/sharing/index.d.ts.map +1 -1
  358. package/dist/client/sharing/index.js +3 -0
  359. package/dist/client/sharing/index.js.map +1 -1
  360. package/dist/client/sharing/share-controller-helpers.d.ts +70 -0
  361. package/dist/client/sharing/share-controller-helpers.d.ts.map +1 -0
  362. package/dist/client/sharing/share-controller-helpers.js +224 -0
  363. package/dist/client/sharing/share-controller-helpers.js.map +1 -0
  364. package/dist/client/sharing/useShareButtonController.d.ts +91 -0
  365. package/dist/client/sharing/useShareButtonController.d.ts.map +1 -0
  366. package/dist/client/sharing/useShareButtonController.js +397 -0
  367. package/dist/client/sharing/useShareButtonController.js.map +1 -0
  368. package/dist/client/sharing/useShareDialogController.d.ts +109 -0
  369. package/dist/client/sharing/useShareDialogController.d.ts.map +1 -0
  370. package/dist/client/sharing/useShareDialogController.js +348 -0
  371. package/dist/client/sharing/useShareDialogController.js.map +1 -0
  372. package/dist/client/sse-event-processor.d.ts.map +1 -1
  373. package/dist/client/sse-event-processor.js +21 -0
  374. package/dist/client/sse-event-processor.js.map +1 -1
  375. package/dist/client/tool-display.d.ts +16 -0
  376. package/dist/client/tool-display.d.ts.map +1 -1
  377. package/dist/client/tool-display.js +52 -0
  378. package/dist/client/tool-display.js.map +1 -1
  379. package/dist/client/use-agent-engine-configured.d.ts +3 -2
  380. package/dist/client/use-agent-engine-configured.d.ts.map +1 -1
  381. package/dist/client/use-agent-engine-configured.js +7 -19
  382. package/dist/client/use-agent-engine-configured.js.map +1 -1
  383. package/dist/client/use-chat-threads.d.ts.map +1 -1
  384. package/dist/client/use-chat-threads.js +21 -8
  385. package/dist/client/use-chat-threads.js.map +1 -1
  386. package/dist/localization/default-messages.d.ts +4 -0
  387. package/dist/localization/default-messages.d.ts.map +1 -1
  388. package/dist/localization/default-messages.js +4 -0
  389. package/dist/localization/default-messages.js.map +1 -1
  390. package/dist/mcp-client/oauth-routes.d.ts +2 -0
  391. package/dist/mcp-client/oauth-routes.d.ts.map +1 -1
  392. package/dist/mcp-client/oauth-routes.js +12 -2
  393. package/dist/mcp-client/oauth-routes.js.map +1 -1
  394. package/dist/observability/routes.d.ts +3 -3
  395. package/dist/provider-api/actions/custom-provider-registration.d.ts +4 -4
  396. package/dist/scripts/call-agent.d.ts.map +1 -1
  397. package/dist/scripts/call-agent.js +5 -1
  398. package/dist/scripts/call-agent.js.map +1 -1
  399. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  400. package/dist/server/realtime-voice.js +1 -1
  401. package/dist/server/realtime-voice.js.map +1 -1
  402. package/dist/server/transcribe-voice.d.ts +1 -1
  403. package/dist/styles/agent-native.css +0 -24
  404. package/dist/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  405. package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  406. package/dist/templates/chat/.agents/skills/frontend-design/SKILL.md +22 -2
  407. package/dist/templates/chat/.agents/skills/shadcn-ui/SKILL.md +28 -4
  408. package/dist/templates/chat/app/components/ui/toolkit-provider.tsx +6 -1
  409. package/dist/templates/chat/app/design-system.ts +3 -0
  410. package/dist/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  411. package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  412. package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +22 -2
  413. package/dist/templates/default/.agents/skills/shadcn-ui/SKILL.md +28 -4
  414. package/dist/templates/default/app/components/ui/toolkit-provider.tsx +10 -0
  415. package/dist/templates/default/app/design-system.ts +3 -0
  416. package/dist/templates/default/app/root.tsx +5 -2
  417. package/dist/templates/default/package.json +1 -0
  418. package/dist/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  419. package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  420. package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  421. package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  422. package/dist/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +22 -2
  423. package/dist/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +28 -4
  424. package/dist/vite/client.d.ts +3 -0
  425. package/dist/vite/client.d.ts.map +1 -1
  426. package/dist/vite/client.js +31 -0
  427. package/dist/vite/client.js.map +1 -1
  428. package/docs/content/custom-design-system.mdx +445 -0
  429. package/docs/content/toolkit-ui.mdx +16 -0
  430. package/package.json +2 -2
  431. package/src/a2a/types.ts +1 -0
  432. package/src/agent/types.ts +1 -1
  433. package/src/client/AgentPanel.tsx +90 -107
  434. package/src/client/AssistantChat.tsx +30 -13
  435. package/src/client/CommandMenu.tsx +68 -178
  436. package/src/client/agent-chat-adapter.ts +3 -1
  437. package/src/client/app-providers.tsx +1 -1
  438. package/src/client/chat/message-components.tsx +116 -10
  439. package/src/client/chat/tool-call-display.tsx +26 -5
  440. package/src/client/chat/widgets/InlineExtensionWidget.tsx +14 -40
  441. package/src/client/components/ui/message-scroller.tsx +15 -1
  442. package/src/client/i18n.tsx +22 -0
  443. package/src/client/index.ts +17 -0
  444. package/src/client/org/TeamPage.tsx +257 -153
  445. package/src/client/progress/RunsTray.tsx +89 -88
  446. package/src/client/resources/McpConnectionSuggestion.tsx +5 -2
  447. package/src/client/resources/McpIntegrationDialog.tsx +34 -13
  448. package/src/client/resources/mcp-integration-catalog.ts +13 -0
  449. package/src/client/settings/DemoModeSection.tsx +6 -18
  450. package/src/client/settings/SecretsSection.tsx +97 -52
  451. package/src/client/settings/SettingsPanel.tsx +202 -246
  452. package/src/client/settings/SettingsTabsPage.tsx +23 -2
  453. package/src/client/settings/VoiceTranscriptionSection.tsx +7 -18
  454. package/src/client/settings/index.ts +7 -0
  455. package/src/client/settings/useSettingsPanelController.ts +155 -0
  456. package/src/client/setup-connections/BuilderConnectCard.tsx +116 -51
  457. package/src/client/setup-connections/index.ts +10 -0
  458. package/src/client/setup-connections/useBuilderConnectCardController.ts +82 -0
  459. package/src/client/sharing/ShareButton.tsx +64 -586
  460. package/src/client/sharing/ShareDialog.tsx +299 -633
  461. package/src/client/sharing/index.ts +42 -0
  462. package/src/client/sharing/share-controller-helpers.ts +318 -0
  463. package/src/client/sharing/useShareButtonController.ts +600 -0
  464. package/src/client/sharing/useShareDialogController.ts +559 -0
  465. package/src/client/sse-event-processor.ts +23 -0
  466. package/src/client/tool-display.ts +71 -0
  467. package/src/client/use-agent-engine-configured.ts +12 -19
  468. package/src/client/use-chat-threads.ts +33 -12
  469. package/src/localization/default-messages.ts +5 -0
  470. package/src/mcp-client/oauth-routes.ts +16 -2
  471. package/src/scripts/call-agent.ts +5 -1
  472. package/src/server/realtime-voice.ts +1 -1
  473. package/src/styles/agent-native.css +0 -24
  474. package/src/templates/chat/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  475. package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  476. package/src/templates/chat/.agents/skills/frontend-design/SKILL.md +22 -2
  477. package/src/templates/chat/.agents/skills/shadcn-ui/SKILL.md +28 -4
  478. package/src/templates/chat/app/components/ui/toolkit-provider.tsx +6 -1
  479. package/src/templates/chat/app/design-system.ts +3 -0
  480. package/src/templates/default/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  481. package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  482. package/src/templates/default/.agents/skills/frontend-design/SKILL.md +22 -2
  483. package/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +28 -4
  484. package/src/templates/default/app/components/ui/toolkit-provider.tsx +10 -0
  485. package/src/templates/default/app/design-system.ts +3 -0
  486. package/src/templates/default/app/root.tsx +5 -2
  487. package/src/templates/default/package.json +1 -0
  488. package/src/templates/headless/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  489. package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  490. package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +37 -2
  491. package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +86 -11
  492. package/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +22 -2
  493. package/src/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +28 -4
  494. package/src/vite/client.ts +39 -0
  495. package/corpus/templates/analytics/app/components/ui/calendar.tsx +0 -70
  496. package/corpus/templates/analytics/app/components/ui/chart.tsx +0 -386
  497. package/corpus/templates/calendar/app/components/ui/sonner.tsx +0 -58
  498. package/corpus/templates/forms/app/components/ui/calendar.tsx +0 -214
  499. package/corpus/templates/forms/app/components/ui/chart.tsx +0 -379
  500. package/corpus/templates/forms/app/components/ui/command.tsx +0 -153
  501. package/corpus/templates/forms/app/components/ui/context-menu.tsx +0 -198
  502. package/corpus/templates/forms/app/components/ui/menubar.tsx +0 -254
  503. package/corpus/templates/macros/app/components/ui/menubar.tsx +0 -238
  504. package/corpus/templates/macros/app/components/ui/progress.tsx +0 -26
  505. package/corpus/templates/mail/app/components/ui/calendar.tsx +0 -211
  506. package/corpus/templates/mail/app/components/ui/chart.tsx +0 -379
  507. package/corpus/templates/mail/app/components/ui/command.tsx +0 -153
  508. package/corpus/templates/mail/app/components/ui/context-menu.tsx +0 -198
  509. package/corpus/templates/mail/app/components/ui/menubar.tsx +0 -254
  510. package/corpus/templates/tasks/app/components/ui/accordion.tsx +0 -56
  511. package/corpus/templates/tasks/app/components/ui/aspect-ratio.tsx +0 -5
  512. package/corpus/templates/tasks/app/components/ui/breadcrumb.tsx +0 -115
  513. package/corpus/templates/tasks/app/components/ui/calendar.tsx +0 -70
  514. package/corpus/templates/tasks/app/components/ui/carousel.tsx +0 -260
  515. package/corpus/templates/tasks/app/components/ui/chart.tsx +0 -379
  516. package/corpus/templates/tasks/app/components/ui/form.tsx +0 -177
  517. package/corpus/templates/tasks/app/components/ui/hover-card.tsx +0 -27
  518. package/corpus/templates/tasks/app/components/ui/input-otp.tsx +0 -69
  519. package/corpus/templates/tasks/app/components/ui/menubar.tsx +0 -254
  520. package/corpus/templates/tasks/app/components/ui/navigation-menu.tsx +0 -128
  521. package/corpus/templates/tasks/app/components/ui/pagination.tsx +0 -121
  522. package/corpus/templates/tasks/app/components/ui/resizable.tsx +0 -43
  523. package/corpus/templates/tasks/app/components/ui/sidebar.tsx +0 -782
  524. package/corpus/templates/tasks/app/components/ui/toggle.tsx +0 -43
@@ -1,4 +1,20 @@
1
1
  export declare function humanizeToolName(toolName: string | undefined): string;
2
2
  export declare function runningToolLabel(toolName: string | undefined): string;
3
3
  export declare function humanizeToolLabelText(label: string, toolName: string | undefined): string;
4
+ type ToolDisplayPart = {
5
+ type?: string;
6
+ toolCallId?: string;
7
+ toolName?: string;
8
+ argsText?: string;
9
+ args?: Record<string, unknown>;
10
+ };
11
+ /**
12
+ * `call-agent` emits both its ordinary tool row and a richer `agent:<name>`
13
+ * progress row. Keep the ordinary part in message state for tool completion
14
+ * and history, but let presentation code suppress it once the richer row is
15
+ * available.
16
+ */
17
+ export declare function isCallAgentToolCallShadowed(parts: readonly ToolDisplayPart[], index: number): boolean;
18
+ export declare function shadowedCallAgentToolCallIds(parts: readonly ToolDisplayPart[]): Set<string>;
19
+ export {};
4
20
  //# sourceMappingURL=tool-display.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-display.d.ts","sourceRoot":"","sources":["../../src/client/tool-display.ts"],"names":[],"mappings":"AAMA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAoBrE;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAErE;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,MAAM,CAKR"}
1
+ {"version":3,"file":"tool-display.d.ts","sourceRoot":"","sources":["../../src/client/tool-display.ts"],"names":[],"mappings":"AAMA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAoBrE;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAErE;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,MAAM,CAKR;AAED,KAAK,eAAe,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CAAC;AAqBF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,KAAK,EAAE,MAAM,GACZ,OAAO,CAqBT;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,SAAS,eAAe,EAAE,GAChC,GAAG,CAAC,MAAM,CAAC,CAQb"}
@@ -33,4 +33,56 @@ export function humanizeToolLabelText(label, toolName) {
33
33
  return text;
34
34
  return text.split(tool).join(humanizeToolName(tool));
35
35
  }
36
+ function normalizedAgentName(value) {
37
+ if (typeof value !== "string")
38
+ return null;
39
+ const name = value.trim().toLowerCase();
40
+ return name || null;
41
+ }
42
+ function callAgentTarget(part) {
43
+ const parsedTarget = normalizedAgentName(part.args?.agent);
44
+ if (parsedTarget)
45
+ return parsedTarget;
46
+ if (!part.argsText)
47
+ return null;
48
+ try {
49
+ const args = JSON.parse(part.argsText);
50
+ return normalizedAgentName(args.agent);
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
56
+ /**
57
+ * `call-agent` emits both its ordinary tool row and a richer `agent:<name>`
58
+ * progress row. Keep the ordinary part in message state for tool completion
59
+ * and history, but let presentation code suppress it once the richer row is
60
+ * available.
61
+ */
62
+ export function isCallAgentToolCallShadowed(parts, index) {
63
+ const part = parts[index];
64
+ if (part?.type !== "tool-call" || part.toolName !== "call-agent") {
65
+ return false;
66
+ }
67
+ const agentRows = parts.filter((candidate) => {
68
+ if (candidate.type !== "tool-call" ||
69
+ !candidate.toolName?.startsWith("agent:")) {
70
+ return false;
71
+ }
72
+ return true;
73
+ });
74
+ const target = callAgentTarget(part);
75
+ if (!target)
76
+ return agentRows.length > 0;
77
+ return agentRows.some((candidate) => normalizedAgentName(candidate.toolName?.slice(6)) === target);
78
+ }
79
+ export function shadowedCallAgentToolCallIds(parts) {
80
+ const ids = new Set();
81
+ parts.forEach((part, index) => {
82
+ if (part.toolCallId && isCallAgentToolCallShadowed(parts, index)) {
83
+ ids.add(part.toolCallId);
84
+ }
85
+ });
86
+ return ids;
87
+ }
36
88
  //# sourceMappingURL=tool-display.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-display.js","sourceRoot":"","sources":["../../src/client/tool-display.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAA2B;IACjD,aAAa,EAAE,eAAe;IAC9B,qBAAqB,EAAE,qBAAqB;IAC5C,aAAa,EAAE,aAAa;CAC7B,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,MAAM,GAAG,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IACxB,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IAEpC,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,IAAI,GAAG,IAAI;SACR,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;SAClB,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;SACtC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;IAEV,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,OAAO,WAAW,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAa,EACb,QAA4B;IAE5B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1B,MAAM,IAAI,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["const TOOL_DISPLAY_NAMES: Record<string, string> = {\n \"delete-file\": \"remove screen\",\n \"get-design-snapshot\": \"get screen snapshot\",\n \"edit-design\": \"edit screen\",\n};\n\nexport function humanizeToolName(toolName: string | undefined): string {\n const raw = (toolName ?? \"\").trim();\n if (!raw) return \"tool\";\n const displayName = TOOL_DISPLAY_NAMES[raw];\n if (displayName) return displayName;\n\n let name = raw;\n if (name.startsWith(\"mcp__\")) {\n const parts = name.split(\"__\").filter(Boolean);\n name = parts[parts.length - 1] ?? name;\n }\n\n name = name\n .replace(/^_+/, \"\")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/[-_]+/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n\n return (name || \"tool\").toLowerCase();\n}\n\nexport function runningToolLabel(toolName: string | undefined): string {\n return `Running ${humanizeToolName(toolName)}`;\n}\n\nexport function humanizeToolLabelText(\n label: string,\n toolName: string | undefined,\n): string {\n const text = label.trim();\n const tool = (toolName ?? \"\").trim();\n if (!tool) return text;\n return text.split(tool).join(humanizeToolName(tool));\n}\n"]}
1
+ {"version":3,"file":"tool-display.js","sourceRoot":"","sources":["../../src/client/tool-display.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAA2B;IACjD,aAAa,EAAE,eAAe;IAC9B,qBAAqB,EAAE,qBAAqB;IAC5C,aAAa,EAAE,aAAa;CAC7B,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,MAAM,GAAG,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC;IACxB,MAAM,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,WAAW;QAAE,OAAO,WAAW,CAAC;IAEpC,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC/C,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,IAAI,GAAG,IAAI;SAC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CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["const TOOL_DISPLAY_NAMES: Record<string, string> = {\n \"delete-file\": \"remove screen\",\n \"get-design-snapshot\": \"get screen snapshot\",\n \"edit-design\": \"edit screen\",\n};\n\nexport function humanizeToolName(toolName: string | undefined): string {\n const raw = (toolName ?? \"\").trim();\n if (!raw) return \"tool\";\n const displayName = TOOL_DISPLAY_NAMES[raw];\n if (displayName) return displayName;\n\n let name = raw;\n if (name.startsWith(\"mcp__\")) {\n const parts = name.split(\"__\").filter(Boolean);\n name = parts[parts.length - 1] ?? name;\n }\n\n name = name\n .replace(/^_+/, \"\")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/[-_]+/g, \" \")\n .replace(/\\s+/g, \" \")\n .trim();\n\n return (name || \"tool\").toLowerCase();\n}\n\nexport function runningToolLabel(toolName: string | undefined): string {\n return `Running ${humanizeToolName(toolName)}`;\n}\n\nexport function humanizeToolLabelText(\n label: string,\n toolName: string | undefined,\n): string {\n const text = label.trim();\n const tool = (toolName ?? \"\").trim();\n if (!tool) return text;\n return text.split(tool).join(humanizeToolName(tool));\n}\n\ntype ToolDisplayPart = {\n type?: string;\n toolCallId?: string;\n toolName?: string;\n argsText?: string;\n args?: Record<string, unknown>;\n};\n\nfunction normalizedAgentName(value: unknown): string | null {\n if (typeof value !== \"string\") return null;\n const name = value.trim().toLowerCase();\n return name || null;\n}\n\nfunction callAgentTarget(part: ToolDisplayPart): string | null {\n const parsedTarget = normalizedAgentName(part.args?.agent);\n if (parsedTarget) return parsedTarget;\n if (!part.argsText) return null;\n\n try {\n const args = JSON.parse(part.argsText) as Record<string, unknown>;\n return normalizedAgentName(args.agent);\n } catch {\n return null;\n }\n}\n\n/**\n * `call-agent` emits both its ordinary tool row and a richer `agent:<name>`\n * progress row. Keep the ordinary part in message state for tool completion\n * and history, but let presentation code suppress it once the richer row is\n * available.\n */\nexport function isCallAgentToolCallShadowed(\n parts: readonly ToolDisplayPart[],\n index: number,\n): boolean {\n const part = parts[index];\n if (part?.type !== \"tool-call\" || part.toolName !== \"call-agent\") {\n return false;\n }\n\n const agentRows = parts.filter((candidate) => {\n if (\n candidate.type !== \"tool-call\" ||\n !candidate.toolName?.startsWith(\"agent:\")\n ) {\n return false;\n }\n return true;\n });\n const target = callAgentTarget(part);\n if (!target) return agentRows.length > 0;\n\n return agentRows.some(\n (candidate) => normalizedAgentName(candidate.toolName?.slice(6)) === target,\n );\n}\n\nexport function shadowedCallAgentToolCallIds(\n parts: readonly ToolDisplayPart[],\n): Set<string> {\n const ids = new Set<string>();\n parts.forEach((part, index) => {\n if (part.toolCallId && isCallAgentToolCallShadowed(parts, index)) {\n ids.add(part.toolCallId);\n }\n });\n return ids;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  /** `unknown` until the first check resolves, so callers don't flash the gate. */
2
- export type AgentEngineConfiguredState = "unknown" | "configured" | "missing";
2
+ export type AgentEngineConfiguredState = "unknown" | "configured" | "missing" | "unavailable";
3
3
  export interface UseAgentEngineConfiguredResult {
4
4
  /** True once we know nothing can run the agent (no key / Builder / BYOK). */
5
5
  missing: boolean;
@@ -24,7 +24,8 @@ export declare function fetchAgentEngineConfiguredState(enabled?: boolean, optio
24
24
  * composer and app prompt boxes. Checks the env-key / Builder / BYOK status
25
25
  * endpoints on mount, re-checks on `agent-engine:configured-changed`, and folds
26
26
  * in the adapter's `agent-chat:missing-api-key` signal. Pass `enabled = false`
27
- * to short-circuit to configured; flaky requests stay `unknown`.
27
+ * to short-circuit to configured; unavailable checks can be retried by firing
28
+ * `agent-engine:configured-changed`.
28
29
  */
29
30
  export declare function useAgentEngineConfigured(enabled?: boolean, options?: UseAgentEngineConfiguredOptions): UseAgentEngineConfiguredResult;
30
31
  //# sourceMappingURL=use-agent-engine-configured.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-agent-engine-configured.d.ts","sourceRoot":"","sources":["../../src/client/use-agent-engine-configured.ts"],"names":[],"mappings":"AAOA,iFAAiF;AACjF,MAAM,MAAM,0BAA0B,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;AAE9E,MAAM,WAAW,8BAA8B;IAC7C,6EAA6E;IAC7E,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,0BAA0B,CAAC;CACnC;AAED,MAAM,WAAW,sCAAsC;IACrD;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,+BAA+B;IAC9C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAiED,wBAAsB,+BAA+B,CACnD,OAAO,UAAO,EACd,OAAO,CAAC,EAAE,sCAAsC,GAC/C,OAAO,CAAC,0BAA0B,CAAC,CA4CrC;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,UAAO,EACd,OAAO,CAAC,EAAE,+BAA+B,GACxC,8BAA8B,CAyDhC"}
1
+ {"version":3,"file":"use-agent-engine-configured.d.ts","sourceRoot":"","sources":["../../src/client/use-agent-engine-configured.ts"],"names":[],"mappings":"AAOA,iFAAiF;AACjF,MAAM,MAAM,0BAA0B,GAClC,SAAS,GACT,YAAY,GACZ,SAAS,GACT,aAAa,CAAC;AAElB,MAAM,WAAW,8BAA8B;IAC7C,6EAA6E;IAC7E,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,0BAA0B,CAAC;CACnC;AAED,MAAM,WAAW,sCAAsC;IACrD;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,+BAA+B;IAC9C,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAgED,wBAAsB,+BAA+B,CACnD,OAAO,UAAO,EACd,OAAO,CAAC,EAAE,sCAAsC,GAC/C,OAAO,CAAC,0BAA0B,CAAC,CA2CrC;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,UAAO,EACd,OAAO,CAAC,EAAE,+BAA+B,GACxC,8BAA8B,CA+ChC"}
@@ -3,7 +3,6 @@ import { PROVIDER_ENV_VARS } from "../agent/engine/provider-env-vars.js";
3
3
  import { agentNativePath } from "./api-path.js";
4
4
  const PROVIDER_ENV_VAR_SET = new Set(PROVIDER_ENV_VARS);
5
5
  const DEFAULT_STATUS_CHECK_TIMEOUT_MS = 2500;
6
- const UNKNOWN_STATUS_RETRY_MS = 2000;
7
6
  async function fetchStatusJson(path, timeoutMs) {
8
7
  const controller = typeof AbortController !== "undefined" ? new AbortController() : null;
9
8
  let timeoutId;
@@ -58,11 +57,10 @@ export async function fetchAgentEngineConfiguredState(enabled = true, options) {
58
57
  fetchStatusJson("/_agent-native/builder/status", timeoutMs),
59
58
  fetchStatusJson("/_agent-native/agent-engine/status", timeoutMs),
60
59
  ]);
61
- // All three failed — likely a flaky network; keep the caller in unknown.
62
- // Even an explicit missing-key stream event should not pin the composer into
63
- // setup without a fresh authoritative status response.
60
+ // All three failed — surface a retryable unavailable state instead of
61
+ // leaving the composer in an infinite checking loop.
64
62
  if (envKeys == null && builderStatus == null && engineStatus == null) {
65
- return "unknown";
63
+ return "unavailable";
66
64
  }
67
65
  const envKeysKnown = Array.isArray(envKeys);
68
66
  const builderStatusKnown = hasConfiguredFlag(builderStatus);
@@ -83,39 +81,31 @@ export async function fetchAgentEngineConfiguredState(enabled = true, options) {
83
81
  if (engineStatusKnown)
84
82
  return "missing";
85
83
  // Compatibility fallback for older hosts without the canonical route.
86
- return envKeysKnown && builderStatusKnown ? "missing" : "unknown";
84
+ return envKeysKnown && builderStatusKnown ? "missing" : "unavailable";
87
85
  }
88
86
  /**
89
87
  * Shared "can the agent run?" gate — the single source of truth for the sidebar
90
88
  * composer and app prompt boxes. Checks the env-key / Builder / BYOK status
91
89
  * endpoints on mount, re-checks on `agent-engine:configured-changed`, and folds
92
90
  * in the adapter's `agent-chat:missing-api-key` signal. Pass `enabled = false`
93
- * to short-circuit to configured; flaky requests stay `unknown`.
91
+ * to short-circuit to configured; unavailable checks can be retried by firing
92
+ * `agent-engine:configured-changed`.
94
93
  */
95
94
  export function useAgentEngineConfigured(enabled = true, options) {
96
95
  const [state, setState] = useState("unknown");
97
96
  useEffect(() => {
98
97
  let cancelled = false;
99
- let retryId;
100
98
  // Monotonic call counter: overlapping checks (mount + a
101
99
  // `agent-engine:configured-changed` fired right after a key is saved) can
102
100
  // resolve out of order; only the latest call may write state, or a slow
103
101
  // stale "missing" response would overwrite the fresh "configured" one.
104
102
  let requestSeq = 0;
105
103
  const check = async (options) => {
106
- if (retryId !== undefined) {
107
- clearTimeout(retryId);
108
- retryId = undefined;
109
- }
110
104
  const seq = ++requestSeq;
111
105
  const nextState = await fetchAgentEngineConfiguredState(enabled, options);
112
106
  if (cancelled || seq !== requestSeq)
113
107
  return;
114
- if (nextState === "unknown") {
115
- retryId = setTimeout(() => void check(), UNKNOWN_STATUS_RETRY_MS);
116
- return;
117
- }
118
- setState(nextState);
108
+ setState(nextState === "unknown" ? "unavailable" : nextState);
119
109
  };
120
110
  const onConfiguredChanged = () => {
121
111
  void check();
@@ -136,8 +126,6 @@ export function useAgentEngineConfigured(enabled = true, options) {
136
126
  window.addEventListener("agent-chat:missing-api-key", onMissing);
137
127
  return () => {
138
128
  cancelled = true;
139
- if (retryId !== undefined)
140
- clearTimeout(retryId);
141
129
  window.removeEventListener("agent-engine:configured-changed", onConfiguredChanged);
142
130
  window.removeEventListener("agent-chat:missing-api-key", onMissing);
143
131
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-agent-engine-configured.js","sourceRoot":"","sources":["../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mB,GAAG,GAAG,EAAE;YAC/B,KAAK,KAAK,EAAE,CAAC;QACf,CAAC,CAAC;QACF,MAAM,SAAS,GAAG,CAAC,KAAY,EAAE,EAAE;YACjC,IAAI,CAAC,2BAA2B,CAAC,KAAK,EAAE,OAAO,CAAC;gBAAE,OAAO;YACzD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,QAAQ,CAAC,YAAY,CAAC,CAAC;gBACvB,OAAO;YACT,CAAC;YACD,KAAK,KAAK,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC;QAEF,KAAK,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,gBAAgB,CACrB,iCAAiC,EACjC,mBAAmB,CACpB,CAAC;QACF,4EAA4E;QAC5E,uDAAuD;QACvD,MAAM,CAAC,gBAAgB,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;QACjE,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,IAAI,OAAO,KAAK,SAAS;gBAAE,YAAY,CAAC,OAAO,CAAC,CAAC;YACjD,MAAM,CAAC,mBAAmB,CACxB,iCAAiC,EACjC,mBAAmB,CACpB,CAAC;YACF,MAAM,CAAC,mBAAmB,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;QACtE,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEjD,OAAO,EAAE,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC","sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport { PROVIDER_ENV_VARS } from \"../agent/engine/provider-env-vars.js\";\nimport { agentNativePath } from \"./api-path.js\";\n\nconst PROVIDER_ENV_VAR_SET = new Set(PROVIDER_ENV_VARS);\n\n/** `unknown` until the first check resolves, so callers don't flash the gate. */\nexport type AgentEngineConfiguredState = \"unknown\" | \"configured\" | \"missing\";\n\nexport interface UseAgentEngineConfiguredResult {\n /** True once we know nothing can run the agent (no key / Builder / BYOK). */\n missing: boolean;\n state: AgentEngineConfiguredState;\n}\n\nexport interface FetchAgentEngineConfiguredStateOptions {\n /**\n * Legacy hint from explicit missing-key stream events. Kept for API\n * compatibility, but missing state still requires authoritative status\n * responses so transient endpoint failures do not clobber connected state.\n */\n missingFallback?: boolean;\n timeoutMs?: number;\n}\n\nexport interface UseAgentEngineConfiguredOptions {\n tabId?: string | null;\n threadId?: string | null;\n}\n\nconst DEFAULT_STATUS_CHECK_TIMEOUT_MS = 2500;\nconst UNKNOWN_STATUS_RETRY_MS = 2000;\n\nasync function fetchStatusJson(\n path: string,\n timeoutMs: number,\n): Promise<unknown | null> {\n const controller =\n typeof AbortController !== \"undefined\" ? new AbortController() : null;\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<null>((resolve) => {\n timeoutId = setTimeout(() => {\n controller?.abort();\n resolve(null);\n }, timeoutMs);\n });\n\n // Never serve a stale status from the HTTP cache: this is re-fetched right\n // after a provider connects, and a cached \"missing\" would keep the composer\n // gate and error banner pinned even though a provider is now configured.\n const request = fetch(agentNativePath(path), {\n cache: \"no-store\",\n ...(controller ? { signal: controller.signal } : {}),\n })\n .then((r) => (r.ok ? r.json() : null))\n .catch(() => null)\n .finally(() => {\n if (timeoutId !== undefined) clearTimeout(timeoutId);\n });\n\n return Promise.race([request, timeout]);\n}\n\nfunction hasConfiguredFlag(value: unknown): value is { configured: boolean } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"configured\" in value &&\n typeof (value as { configured?: unknown }).configured === \"boolean\"\n );\n}\n\nfunction missingKeyEventMatchesScope(\n event: Event,\n options: UseAgentEngineConfiguredOptions | undefined,\n): boolean {\n const detail = (event as CustomEvent).detail as\n | { tabId?: unknown; threadId?: unknown }\n | undefined;\n const eventTabId = typeof detail?.tabId === \"string\" ? detail.tabId : null;\n const eventThreadId =\n typeof detail?.threadId === \"string\" ? detail.threadId : null;\n if (!eventTabId && !eventThreadId) return true;\n\n const tabId = options?.tabId ?? null;\n const threadId = options?.threadId ?? null;\n if (!tabId && !threadId) return true;\n return (\n (eventTabId != null && eventTabId === tabId) ||\n (eventThreadId != null && eventThreadId === threadId)\n );\n}\n\nexport async function fetchAgentEngineConfiguredState(\n enabled = true,\n options?: FetchAgentEngineConfiguredStateOptions,\n): Promise<AgentEngineConfiguredState> {\n if (!enabled) return \"configured\";\n\n const timeoutMs =\n typeof options?.timeoutMs === \"number\" && options.timeoutMs > 0\n ? options.timeoutMs\n : DEFAULT_STATUS_CHECK_TIMEOUT_MS;\n const [envKeys, builderStatus, engineStatus] = await Promise.all([\n fetchStatusJson(\"/_agent-native/env-status\", timeoutMs),\n fetchStatusJson(\"/_agent-native/builder/status\", timeoutMs),\n fetchStatusJson(\"/_agent-native/agent-engine/status\", timeoutMs),\n ]);\n\n // All three failed — likely a flaky network; keep the caller in unknown.\n // Even an explicit missing-key stream event should not pin the composer into\n // setup without a fresh authoritative status response.\n if (envKeys == null && builderStatus == null && engineStatus == null) {\n return \"unknown\";\n }\n\n const envKeysKnown = Array.isArray(envKeys);\n const builderStatusKnown = hasConfiguredFlag(builderStatus);\n const engineStatusKnown = hasConfiguredFlag(engineStatus);\n const keys = envKeysKnown\n ? (envKeys as Array<{\n key: string;\n configured: boolean;\n }>)\n : [];\n const llmKeys = keys.filter((k) => PROVIDER_ENV_VAR_SET.has(k.key));\n const anyConfigured =\n llmKeys.some((k) => k.configured) ||\n (builderStatusKnown && builderStatus.configured) ||\n (engineStatusKnown && engineStatus.configured);\n if (anyConfigured) return \"configured\";\n\n // The engine status route is the canonical readiness check: it resolves\n // Builder, scoped BYOK secrets, deployment credentials, and custom engines.\n // Once it has answered `configured: false`, a slow legacy env/Builder status\n // request must not leave the composer permissively stuck in `unknown`.\n if (engineStatusKnown) return \"missing\";\n\n // Compatibility fallback for older hosts without the canonical route.\n return envKeysKnown && builderStatusKnown ? \"missing\" : \"unknown\";\n}\n\n/**\n * Shared \"can the agent run?\" gate — the single source of truth for the sidebar\n * composer and app prompt boxes. Checks the env-key / Builder / BYOK status\n * endpoints on mount, re-checks on `agent-engine:configured-changed`, and folds\n * in the adapter's `agent-chat:missing-api-key` signal. Pass `enabled = false`\n * to short-circuit to configured; flaky requests stay `unknown`.\n */\nexport function useAgentEngineConfigured(\n enabled = true,\n options?: UseAgentEngineConfiguredOptions,\n): UseAgentEngineConfiguredResult {\n const [state, setState] = useState<AgentEngineConfiguredState>(\"unknown\");\n\n useEffect(() => {\n let cancelled = false;\n let retryId: ReturnType<typeof setTimeout> | undefined;\n // Monotonic call counter: overlapping checks (mount + a\n // `agent-engine:configured-changed` fired right after a key is saved) can\n // resolve out of order; only the latest call may write state, or a slow\n // stale \"missing\" response would overwrite the fresh \"configured\" one.\n let requestSeq = 0;\n const check = async (options?: { missingFallback?: boolean }) => {\n if (retryId !== undefined) {\n clearTimeout(retryId);\n retryId = undefined;\n }\n const seq = ++requestSeq;\n const nextState = await fetchAgentEngineConfiguredState(enabled, options);\n if (cancelled || seq !== requestSeq) return;\n if (nextState === \"unknown\") {\n retryId = setTimeout(() => void check(), UNKNOWN_STATUS_RETRY_MS);\n return;\n }\n setState(nextState);\n };\n const onConfiguredChanged = () => {\n void check();\n };\n const onMissing = (event: Event) => {\n if (!missingKeyEventMatchesScope(event, options)) return;\n if (!enabled) {\n setState(\"configured\");\n return;\n }\n void check({ missingFallback: true });\n };\n\n void check();\n window.addEventListener(\n \"agent-engine:configured-changed\",\n onConfiguredChanged,\n );\n // A stale failed stream can arrive after a reconnect succeeds. Re-check the\n // current status before pinning the composer in setup.\n window.addEventListener(\"agent-chat:missing-api-key\", onMissing);\n return () => {\n cancelled = true;\n if (retryId !== undefined) clearTimeout(retryId);\n window.removeEventListener(\n \"agent-engine:configured-changed\",\n onConfiguredChanged,\n );\n window.removeEventListener(\"agent-chat:missing-api-key\", onMissing);\n };\n }, [enabled, options?.tabId, options?.threadId]);\n\n return { missing: state === \"missing\", state };\n}\n"]}
1
+ {"version":3,"file":"use-agent-engine-configured.js","sourceRoot":"","sources":["../../src/client/use-agent-engine-configured.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;AA8BxD,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAE7C,KAAK,UAAU,eAAe,CAC5B,IAAY,EACZ,SAAiB;IAEjB,MAAM,UAAU,GACd,OAAO,eAAe,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACxE,IAAI,SAAoD,CAAC;IACzD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC5C,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC1B,UAAU,EAAE,KAAK,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,MAAM,OAAO,GAAG,KAAK,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QAC3C,KAAK,EAAE,UAAU;QACjB,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC;SACC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,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AAE,CAAC;gBACb,QAAQ,CAAC,YAAY,CAAC,CAAC;gBACvB,OAAO;YACT,CAAC;YACD,KAAK,KAAK,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC;QAEF,KAAK,KAAK,EAAE,CAAC;QACb,MAAM,CAAC,gBAAgB,CACrB,iCAAiC,EACjC,mBAAmB,CACpB,CAAC;QACF,4EAA4E;QAC5E,uDAAuD;QACvD,MAAM,CAAC,gBAAgB,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;QACjE,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAC;YACjB,MAAM,CAAC,mBAAmB,CACxB,iCAAiC,EACjC,mBAAmB,CACpB,CAAC;YACF,MAAM,CAAC,mBAAmB,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;QACtE,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEjD,OAAO,EAAE,OAAO,EAAE,KAAK,KAAK,SAAS,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC","sourcesContent":["import { useEffect, useState } from \"react\";\n\nimport { PROVIDER_ENV_VARS } from \"../agent/engine/provider-env-vars.js\";\nimport { agentNativePath } from \"./api-path.js\";\n\nconst PROVIDER_ENV_VAR_SET = new Set(PROVIDER_ENV_VARS);\n\n/** `unknown` until the first check resolves, so callers don't flash the gate. */\nexport type AgentEngineConfiguredState =\n | \"unknown\"\n | \"configured\"\n | \"missing\"\n | \"unavailable\";\n\nexport interface UseAgentEngineConfiguredResult {\n /** True once we know nothing can run the agent (no key / Builder / BYOK). */\n missing: boolean;\n state: AgentEngineConfiguredState;\n}\n\nexport interface FetchAgentEngineConfiguredStateOptions {\n /**\n * Legacy hint from explicit missing-key stream events. Kept for API\n * compatibility, but missing state still requires authoritative status\n * responses so transient endpoint failures do not clobber connected state.\n */\n missingFallback?: boolean;\n timeoutMs?: number;\n}\n\nexport interface UseAgentEngineConfiguredOptions {\n tabId?: string | null;\n threadId?: string | null;\n}\n\nconst DEFAULT_STATUS_CHECK_TIMEOUT_MS = 2500;\n\nasync function fetchStatusJson(\n path: string,\n timeoutMs: number,\n): Promise<unknown | null> {\n const controller =\n typeof AbortController !== \"undefined\" ? new AbortController() : null;\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<null>((resolve) => {\n timeoutId = setTimeout(() => {\n controller?.abort();\n resolve(null);\n }, timeoutMs);\n });\n\n // Never serve a stale status from the HTTP cache: this is re-fetched right\n // after a provider connects, and a cached \"missing\" would keep the composer\n // gate and error banner pinned even though a provider is now configured.\n const request = fetch(agentNativePath(path), {\n cache: \"no-store\",\n ...(controller ? { signal: controller.signal } : {}),\n })\n .then((r) => (r.ok ? r.json() : null))\n .catch(() => null)\n .finally(() => {\n if (timeoutId !== undefined) clearTimeout(timeoutId);\n });\n\n return Promise.race([request, timeout]);\n}\n\nfunction hasConfiguredFlag(value: unknown): value is { configured: boolean } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"configured\" in value &&\n typeof (value as { configured?: unknown }).configured === \"boolean\"\n );\n}\n\nfunction missingKeyEventMatchesScope(\n event: Event,\n options: UseAgentEngineConfiguredOptions | undefined,\n): boolean {\n const detail = (event as CustomEvent).detail as\n | { tabId?: unknown; threadId?: unknown }\n | undefined;\n const eventTabId = typeof detail?.tabId === \"string\" ? detail.tabId : null;\n const eventThreadId =\n typeof detail?.threadId === \"string\" ? detail.threadId : null;\n if (!eventTabId && !eventThreadId) return true;\n\n const tabId = options?.tabId ?? null;\n const threadId = options?.threadId ?? null;\n if (!tabId && !threadId) return true;\n return (\n (eventTabId != null && eventTabId === tabId) ||\n (eventThreadId != null && eventThreadId === threadId)\n );\n}\n\nexport async function fetchAgentEngineConfiguredState(\n enabled = true,\n options?: FetchAgentEngineConfiguredStateOptions,\n): Promise<AgentEngineConfiguredState> {\n if (!enabled) return \"configured\";\n\n const timeoutMs =\n typeof options?.timeoutMs === \"number\" && options.timeoutMs > 0\n ? options.timeoutMs\n : DEFAULT_STATUS_CHECK_TIMEOUT_MS;\n const [envKeys, builderStatus, engineStatus] = await Promise.all([\n fetchStatusJson(\"/_agent-native/env-status\", timeoutMs),\n fetchStatusJson(\"/_agent-native/builder/status\", timeoutMs),\n fetchStatusJson(\"/_agent-native/agent-engine/status\", timeoutMs),\n ]);\n\n // All three failed — surface a retryable unavailable state instead of\n // leaving the composer in an infinite checking loop.\n if (envKeys == null && builderStatus == null && engineStatus == null) {\n return \"unavailable\";\n }\n\n const envKeysKnown = Array.isArray(envKeys);\n const builderStatusKnown = hasConfiguredFlag(builderStatus);\n const engineStatusKnown = hasConfiguredFlag(engineStatus);\n const keys = envKeysKnown\n ? (envKeys as Array<{\n key: string;\n configured: boolean;\n }>)\n : [];\n const llmKeys = keys.filter((k) => PROVIDER_ENV_VAR_SET.has(k.key));\n const anyConfigured =\n llmKeys.some((k) => k.configured) ||\n (builderStatusKnown && builderStatus.configured) ||\n (engineStatusKnown && engineStatus.configured);\n if (anyConfigured) return \"configured\";\n\n // The engine status route is the canonical readiness check: it resolves\n // Builder, scoped BYOK secrets, deployment credentials, and custom engines.\n // Once it has answered `configured: false`, a slow legacy env/Builder status\n // request must not leave the composer permissively stuck in `unknown`.\n if (engineStatusKnown) return \"missing\";\n\n // Compatibility fallback for older hosts without the canonical route.\n return envKeysKnown && builderStatusKnown ? \"missing\" : \"unavailable\";\n}\n\n/**\n * Shared \"can the agent run?\" gate — the single source of truth for the sidebar\n * composer and app prompt boxes. Checks the env-key / Builder / BYOK status\n * endpoints on mount, re-checks on `agent-engine:configured-changed`, and folds\n * in the adapter's `agent-chat:missing-api-key` signal. Pass `enabled = false`\n * to short-circuit to configured; unavailable checks can be retried by firing\n * `agent-engine:configured-changed`.\n */\nexport function useAgentEngineConfigured(\n enabled = true,\n options?: UseAgentEngineConfiguredOptions,\n): UseAgentEngineConfiguredResult {\n const [state, setState] = useState<AgentEngineConfiguredState>(\"unknown\");\n\n useEffect(() => {\n let cancelled = false;\n // Monotonic call counter: overlapping checks (mount + a\n // `agent-engine:configured-changed` fired right after a key is saved) can\n // resolve out of order; only the latest call may write state, or a slow\n // stale \"missing\" response would overwrite the fresh \"configured\" one.\n let requestSeq = 0;\n const check = async (options?: { missingFallback?: boolean }) => {\n const seq = ++requestSeq;\n const nextState = await fetchAgentEngineConfiguredState(enabled, options);\n if (cancelled || seq !== requestSeq) return;\n setState(nextState === \"unknown\" ? \"unavailable\" : nextState);\n };\n const onConfiguredChanged = () => {\n void check();\n };\n const onMissing = (event: Event) => {\n if (!missingKeyEventMatchesScope(event, options)) return;\n if (!enabled) {\n setState(\"configured\");\n return;\n }\n void check({ missingFallback: true });\n };\n\n void check();\n window.addEventListener(\n \"agent-engine:configured-changed\",\n onConfiguredChanged,\n );\n // A stale failed stream can arrive after a reconnect succeeds. Re-check the\n // current status before pinning the composer in setup.\n window.addEventListener(\"agent-chat:missing-api-key\", onMissing);\n return () => {\n cancelled = true;\n window.removeEventListener(\n \"agent-engine:configured-changed\",\n onConfiguredChanged,\n );\n window.removeEventListener(\"agent-chat:missing-api-key\", onMissing);\n };\n }, [enabled, options?.tabId, options?.threadId]);\n\n return { missing: state === \"missing\", state };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-chat-threads.d.ts","sourceRoot":"","sources":["../../src/client/use-chat-threads.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB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AO,CAAC,iBAAiB,EAAE,CAAC;2BAxoBP,OAAO,CAAC,IAAI,CAAC;oCAwpBxC,MAAM,KAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;sCAgB7C,MAAM,KAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;sCAkB5C,MAAM,KAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;;;;;sBA5UzD,MAAM;EAyXd"}
@@ -217,6 +217,17 @@ export function useChatThreads(apiUrl = agentNativePath("/_agent-native/agent-ch
217
217
  const fetchedRef = useRef(false);
218
218
  const activeThreadIdRef = useRef(activeThreadId);
219
219
  activeThreadIdRef.current = activeThreadId;
220
+ const persistActiveThreadId = useCallback((id) => {
221
+ try {
222
+ const threadScope = readKnownThreadScope(id);
223
+ const targetKey = threadScope === undefined
224
+ ? activeThreadKey
225
+ : activeThreadStorageKey(storageKey, threadScope);
226
+ localStorage.setItem(targetKey, id);
227
+ localStorage.setItem(activeThreadSeenStorageKey(targetKey), String(Date.now()));
228
+ }
229
+ catch { }
230
+ }, [activeThreadKey, readKnownThreadScope, storageKey]);
220
231
  // Persist active thread ID — and rehydrate on scope flips. When the user
221
232
  // navigates from deck A to deck B, `activeThreadKey` changes; we re-read B's
222
233
  // scoped thread only if the currently visible chat is itself scoped to a
@@ -262,6 +273,9 @@ export function useChatThreads(apiUrl = agentNativePath("/_agent-native/agent-ch
262
273
  setActiveThreadId(nextActiveThreadId);
263
274
  return;
264
275
  }
276
+ if (!activeThreadId && !restoreActiveThread && !routeControlsActiveThread) {
277
+ return;
278
+ }
265
279
  try {
266
280
  if (routeControlsActiveThread && !routeThreadId) {
267
281
  localStorage.removeItem(activeThreadKey);
@@ -269,12 +283,7 @@ export function useChatThreads(apiUrl = agentNativePath("/_agent-native/agent-ch
269
283
  return;
270
284
  }
271
285
  if (activeThreadId) {
272
- const threadScope = readKnownThreadScope(activeThreadId);
273
- if (threadScope === undefined)
274
- return;
275
- const targetKey = activeThreadStorageKey(storageKey, threadScope);
276
- localStorage.setItem(targetKey, activeThreadId);
277
- localStorage.setItem(activeThreadSeenStorageKey(targetKey), String(Date.now()));
286
+ persistActiveThreadId(activeThreadId);
278
287
  }
279
288
  else {
280
289
  localStorage.removeItem(activeThreadKey);
@@ -288,7 +297,9 @@ export function useChatThreads(apiUrl = agentNativePath("/_agent-native/agent-ch
288
297
  activeThreadSeenKey,
289
298
  addOptimisticThread,
290
299
  autoCreate,
300
+ persistActiveThreadId,
291
301
  readKnownThreadScope,
302
+ restoreActiveThread,
292
303
  routeControlsActiveThread,
293
304
  routeThreadId,
294
305
  storageKey,
@@ -505,9 +516,10 @@ export function useChatThreads(apiUrl = agentNativePath("/_agent-native/agent-ch
505
516
  const id = preferredId || createLocalThreadId();
506
517
  newlyCreatedRef.current.add(id);
507
518
  addOptimisticThread(id, scopeRef.current ?? null);
519
+ persistActiveThreadId(id);
508
520
  setActiveThreadId(id);
509
521
  return Promise.resolve(id);
510
- }, [addOptimisticThread]);
522
+ }, [addOptimisticThread, persistActiveThreadId]);
511
523
  useEffect(() => {
512
524
  if (!routeControlsActiveThread)
513
525
  return;
@@ -695,8 +707,9 @@ export function useChatThreads(apiUrl = agentNativePath("/_agent-native/agent-ch
695
707
  }, [apiUrl, clearUserRenamedThread, fetchThreads, markUserRenamedThread]);
696
708
  const isNewThread = useCallback((id) => newlyCreatedRef.current.has(id), []);
697
709
  const switchThread = useCallback((id) => {
710
+ persistActiveThreadId(id);
698
711
  setActiveThreadId(id);
699
- }, []);
712
+ }, [persistActiveThreadId]);
700
713
  const removeThread = useCallback(async (id) => {
701
714
  try {
702
715
  await fetch(`${apiUrl}/threads/${encodeURIComponent(id)}`, {