@agent-native/core 0.97.0 → 0.98.1

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 (1019) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +56 -0
  3. package/corpus/core/docs/content/authentication.mdx +3 -3
  4. package/corpus/core/docs/content/doctor.mdx +170 -0
  5. package/corpus/core/docs/content/external-agents.mdx +8 -7
  6. package/corpus/core/docs/content/locales/ar-SA/authentication.mdx +2 -2
  7. package/corpus/core/docs/content/locales/ar-SA/external-agents.mdx +8 -7
  8. package/corpus/core/docs/content/locales/ar-SA/mcp-protocol.mdx +1 -1
  9. package/corpus/core/docs/content/locales/ar-SA/security.mdx +2 -0
  10. package/corpus/core/docs/content/locales/de-DE/authentication.mdx +1 -1
  11. package/corpus/core/docs/content/locales/de-DE/external-agents.mdx +8 -7
  12. package/corpus/core/docs/content/locales/de-DE/mcp-protocol.mdx +1 -1
  13. package/corpus/core/docs/content/locales/de-DE/security.mdx +2 -0
  14. package/corpus/core/docs/content/locales/es-ES/authentication.mdx +2 -2
  15. package/corpus/core/docs/content/locales/es-ES/external-agents.mdx +8 -7
  16. package/corpus/core/docs/content/locales/es-ES/mcp-protocol.mdx +1 -1
  17. package/corpus/core/docs/content/locales/es-ES/security.mdx +2 -0
  18. package/corpus/core/docs/content/locales/fr-FR/authentication.mdx +1 -1
  19. package/corpus/core/docs/content/locales/fr-FR/external-agents.mdx +8 -7
  20. package/corpus/core/docs/content/locales/fr-FR/mcp-protocol.mdx +1 -1
  21. package/corpus/core/docs/content/locales/fr-FR/security.mdx +2 -0
  22. package/corpus/core/docs/content/locales/hi-IN/authentication.mdx +2 -2
  23. package/corpus/core/docs/content/locales/hi-IN/external-agents.mdx +8 -7
  24. package/corpus/core/docs/content/locales/hi-IN/mcp-protocol.mdx +1 -1
  25. package/corpus/core/docs/content/locales/hi-IN/security.mdx +2 -0
  26. package/corpus/core/docs/content/locales/ja-JP/authentication.mdx +2 -2
  27. package/corpus/core/docs/content/locales/ja-JP/external-agents.mdx +8 -7
  28. package/corpus/core/docs/content/locales/ja-JP/mcp-protocol.mdx +1 -1
  29. package/corpus/core/docs/content/locales/ja-JP/security.mdx +2 -0
  30. package/corpus/core/docs/content/locales/ko-KR/authentication.mdx +2 -2
  31. package/corpus/core/docs/content/locales/ko-KR/external-agents.mdx +8 -7
  32. package/corpus/core/docs/content/locales/ko-KR/mcp-protocol.mdx +1 -1
  33. package/corpus/core/docs/content/locales/ko-KR/security.mdx +2 -0
  34. package/corpus/core/docs/content/locales/pt-BR/authentication.mdx +2 -2
  35. package/corpus/core/docs/content/locales/pt-BR/external-agents.mdx +8 -7
  36. package/corpus/core/docs/content/locales/pt-BR/mcp-protocol.mdx +1 -1
  37. package/corpus/core/docs/content/locales/pt-BR/security.mdx +2 -0
  38. package/corpus/core/docs/content/locales/zh-CN/authentication.mdx +2 -2
  39. package/corpus/core/docs/content/locales/zh-CN/external-agents.mdx +8 -7
  40. package/corpus/core/docs/content/locales/zh-CN/mcp-protocol.mdx +1 -1
  41. package/corpus/core/docs/content/locales/zh-CN/security.mdx +2 -0
  42. package/corpus/core/docs/content/locales/zh-TW/authentication.mdx +2 -2
  43. package/corpus/core/docs/content/locales/zh-TW/external-agents.mdx +8 -7
  44. package/corpus/core/docs/content/locales/zh-TW/mcp-protocol.mdx +1 -1
  45. package/corpus/core/docs/content/locales/zh-TW/security.mdx +2 -0
  46. package/corpus/core/docs/content/mcp-protocol.mdx +1 -1
  47. package/corpus/core/docs/content/security.mdx +2 -0
  48. package/corpus/core/package.json +6 -2
  49. package/corpus/core/scripts/finalize-build.mjs +63 -3
  50. package/corpus/core/scripts/materialize-source-corpus.mjs +101 -15
  51. package/corpus/core/src/action-change-marker.ts +8 -1
  52. package/corpus/core/src/action.ts +42 -0
  53. package/corpus/core/src/agent/engine/builder-engine.ts +3 -0
  54. package/corpus/core/src/agent/engine/context-directives-transform.ts +69 -0
  55. package/corpus/core/src/agent/engine/continuation-dispatch-retry.ts +168 -0
  56. package/corpus/core/src/agent/engine/tool-call-journal-seed.ts +85 -0
  57. package/corpus/core/src/agent/production-agent.ts +129 -244
  58. package/corpus/core/src/changelog/parse.ts +8 -3
  59. package/corpus/core/src/cli/doctor.ts +9 -3
  60. package/corpus/core/src/cli/plan-local.ts +10 -2
  61. package/corpus/core/src/cli/skills-content/assets-skill.ts +83 -0
  62. package/corpus/core/src/cli/skills-content/canvas.ts +153 -0
  63. package/corpus/core/src/cli/skills-content/connection.ts +52 -0
  64. package/corpus/core/src/cli/skills-content/content-skill.ts +109 -0
  65. package/corpus/core/src/cli/skills-content/design-exploration-skill.ts +118 -0
  66. package/corpus/core/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
  67. package/corpus/core/src/cli/skills-content/document-quality.ts +196 -0
  68. package/corpus/core/src/cli/skills-content/exemplar.ts +69 -0
  69. package/corpus/core/src/cli/skills-content/help.ts +77 -0
  70. package/corpus/core/src/cli/skills-content/index.ts +22 -0
  71. package/corpus/core/src/cli/skills-content/local-files.ts +95 -0
  72. package/corpus/core/src/cli/skills-content/plan-setup-auth.ts +80 -0
  73. package/corpus/core/src/cli/skills-content/visual-plan-skill.ts +470 -0
  74. package/corpus/core/src/cli/skills-content/visual-recap-skill.ts +547 -0
  75. package/corpus/core/src/cli/skills-content/visualize-repo-skill.ts +93 -0
  76. package/corpus/core/src/cli/skills-content/wireframe.ts +349 -0
  77. package/corpus/core/src/cli/skills.ts +27 -2733
  78. package/corpus/core/src/client/AgentPanel.tsx +8 -8
  79. package/corpus/core/src/client/AssistantChat.tsx +83 -39
  80. package/corpus/core/src/client/CommandMenu.tsx +16 -5
  81. package/corpus/core/src/client/FeedbackButton.tsx +2 -2
  82. package/corpus/core/src/client/analytics.ts +29 -0
  83. package/corpus/core/src/client/app-providers.tsx +18 -5
  84. package/corpus/core/src/client/blocks/library/wireframe-kit.tsx +16 -2
  85. package/corpus/core/src/client/chat/tool-call-display.tsx +3 -3
  86. package/corpus/core/src/client/chat-model-groups.ts +28 -0
  87. package/corpus/core/src/client/composer/PastedTextChip.tsx +1 -1
  88. package/corpus/core/src/client/composer/RealtimeVoiceMode.tsx +523 -68
  89. package/corpus/core/src/client/composer/TiptapComposer.tsx +47 -30
  90. package/corpus/core/src/client/composer/VoiceButton.tsx +22 -5
  91. package/corpus/core/src/client/composer/index.ts +5 -0
  92. package/corpus/core/src/client/composer/useRealtimeVoiceMode.tsx +1271 -35
  93. package/corpus/core/src/client/context-xray/ContextXRayPanel.tsx +5 -2
  94. package/corpus/core/src/client/extensions/ExtensionEditor.tsx +37 -4
  95. package/corpus/core/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
  96. package/corpus/core/src/client/extensions/ExtensionSlot.tsx +39 -10
  97. package/corpus/core/src/client/extensions/ExtensionViewer.tsx +44 -6
  98. package/corpus/core/src/client/extensions/ExtensionsListPage.tsx +12 -3
  99. package/corpus/core/src/client/extensions/ExtensionsSidebarSection.tsx +49 -11
  100. package/corpus/core/src/client/index.ts +5 -13
  101. package/corpus/core/src/client/progress/RunsTray.tsx +23 -4
  102. package/corpus/core/src/client/settings/SecretsSection.tsx +387 -266
  103. package/corpus/core/src/client/settings/SettingsPanel.tsx +117 -38
  104. package/corpus/core/src/client/settings/SettingsTabsPage.tsx +7 -0
  105. package/corpus/core/src/client/settings/useBuilderStatus.ts +6 -0
  106. package/corpus/core/src/client/tool-cells/EditCell.tsx +19 -16
  107. package/corpus/core/src/client/tool-cells/FilesChangedSummary.tsx +26 -23
  108. package/corpus/core/src/client/tool-cells/WriteCell.tsx +19 -16
  109. package/corpus/core/src/client/use-action.ts +12 -0
  110. package/corpus/core/src/client/use-agent-chat-home-handoff.ts +8 -1
  111. package/corpus/core/src/client/use-agent-engine-configured.ts +17 -3
  112. package/corpus/core/src/client/use-db-sync.ts +84 -34
  113. package/corpus/core/src/client/use-pausing-interval.ts +14 -4
  114. package/corpus/core/src/client/visual-style-controls.tsx +1 -1
  115. package/corpus/core/src/deploy/build.ts +36 -14
  116. package/corpus/core/src/integrations/google-docs-poller.ts +23 -2
  117. package/corpus/core/src/integrations/plugin.ts +10 -0
  118. package/corpus/core/src/integrations/scope-store.ts +1 -1
  119. package/corpus/core/src/integrations/usage-budget-store.ts +1 -1
  120. package/corpus/core/src/integrations/webhook-handler.ts +27 -2
  121. package/corpus/core/src/jobs/scheduler.ts +28 -2
  122. package/corpus/core/src/localization/default-messages.ts +51 -1
  123. package/corpus/core/src/mcp/oauth-token.ts +6 -1
  124. package/corpus/core/src/mcp-client/workspace-servers.ts +4 -4
  125. package/corpus/core/src/observability/routes.ts +36 -0
  126. package/corpus/core/src/observability/sentiment.ts +261 -0
  127. package/corpus/core/src/observability/store.ts +23 -0
  128. package/corpus/core/src/observability/traces.ts +49 -63
  129. package/corpus/core/src/observability/tracking-identity.ts +55 -0
  130. package/corpus/core/src/observability/types.ts +13 -0
  131. package/corpus/core/src/secrets/crypto.ts +28 -8
  132. package/corpus/core/src/secrets/storage.ts +67 -3
  133. package/corpus/core/src/server/action-change.ts +5 -1
  134. package/corpus/core/src/server/action-routes.ts +8 -0
  135. package/corpus/core/src/server/agent-chat/action-filters-a2a.ts +199 -0
  136. package/corpus/core/src/server/agent-chat/browser-team-tools.ts +510 -0
  137. package/corpus/core/src/server/agent-chat/context-tools.ts +595 -0
  138. package/corpus/core/src/server/agent-chat/framework-prompts.ts +470 -0
  139. package/corpus/core/src/server/agent-chat/lazy-fs.ts +11 -0
  140. package/corpus/core/src/server/agent-chat/mcp-glue.ts +91 -0
  141. package/corpus/core/src/server/agent-chat/plugin-options.ts +350 -0
  142. package/corpus/core/src/server/agent-chat/process-run-failure.ts +62 -0
  143. package/corpus/core/src/server/agent-chat/prompt-resources.ts +688 -0
  144. package/corpus/core/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
  145. package/corpus/core/src/server/agent-chat/request-surface.ts +71 -0
  146. package/corpus/core/src/server/agent-chat/run-code-tools.ts +67 -0
  147. package/corpus/core/src/server/agent-chat/script-entries.ts +779 -0
  148. package/corpus/core/src/server/agent-chat/shared-thread.ts +301 -0
  149. package/corpus/core/src/server/agent-chat/skill-frontmatter.ts +41 -0
  150. package/corpus/core/src/server/agent-chat-plugin.ts +364 -4182
  151. package/corpus/core/src/server/agent-teams.ts +26 -3
  152. package/corpus/core/src/server/auth.ts +55 -57
  153. package/corpus/core/src/server/credential-provider.ts +22 -25
  154. package/corpus/core/src/server/edge.ts +1 -0
  155. package/corpus/core/src/server/onboarding-html.ts +1 -16
  156. package/corpus/core/src/server/poll.ts +1 -0
  157. package/corpus/core/src/server/realtime-voice.ts +335 -14
  158. package/corpus/core/src/server/request-origin.ts +6 -2
  159. package/corpus/core/src/server/ssr-handler.ts +55 -2
  160. package/corpus/core/src/sharing/access.ts +155 -11
  161. package/corpus/core/src/sharing/registry.ts +7 -0
  162. package/corpus/core/src/styles/agent-native.css +17 -16
  163. package/corpus/core/src/templates/default/.agents/skills/frontend-design/SKILL.md +1 -1
  164. package/corpus/core/src/templates/default/.agents/skills/real-time-sync/SKILL.md +2 -2
  165. package/corpus/core/src/templates/default/app/i18n/ar-SA.ts +6 -0
  166. package/corpus/core/src/templates/default/app/i18n/de-DE.ts +6 -0
  167. package/corpus/core/src/templates/default/app/i18n/en-US.ts +6 -0
  168. package/corpus/core/src/templates/default/app/i18n/es-ES.ts +6 -0
  169. package/corpus/core/src/templates/default/app/i18n/fr-FR.ts +6 -0
  170. package/corpus/core/src/templates/default/app/i18n/hi-IN.ts +6 -0
  171. package/corpus/core/src/templates/default/app/i18n/ja-JP.ts +6 -0
  172. package/corpus/core/src/templates/default/app/i18n/ko-KR.ts +6 -0
  173. package/corpus/core/src/templates/default/app/i18n/pt-BR.ts +6 -0
  174. package/corpus/core/src/templates/default/app/i18n/zh-CN.ts +6 -0
  175. package/corpus/core/src/templates/default/app/i18n/zh-TW.ts +6 -0
  176. package/corpus/core/src/templates/workspace-core/.agents/skills/authentication/SKILL.md +27 -29
  177. package/corpus/core/src/templates/workspace-core/.agents/skills/external-agents/SKILL.md +2 -1
  178. package/corpus/core/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +1 -1
  179. package/corpus/core/src/templates/workspace-core/.agents/skills/observability/SKILL.md +32 -0
  180. package/corpus/core/src/templates/workspace-core/.agents/skills/real-time-sync/SKILL.md +2 -2
  181. package/corpus/core/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +7 -3
  182. package/corpus/core/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -9
  183. package/corpus/core/src/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +25 -0
  184. package/corpus/core/src/templates/workspace-core/src/server/index.ts +4 -2
  185. package/corpus/core/src/testing.ts +26 -0
  186. package/corpus/core/src/triggers/dispatcher.ts +23 -2
  187. package/corpus/core/src/vite/client.ts +135 -3
  188. package/corpus/core/tsconfig.cli.json +1 -1
  189. package/corpus/core/tsconfig.json +5 -1
  190. package/corpus/templates/analytics/.agents/skills/bigquery/SKILL.md +2 -2
  191. package/corpus/templates/analytics/.agents/skills/frontend-design/SKILL.md +1 -1
  192. package/corpus/templates/analytics/.agents/skills/real-time-sync/SKILL.md +2 -2
  193. package/corpus/templates/analytics/.agents/skills/session-replay/SKILL.md +10 -5
  194. package/corpus/templates/analytics/AGENTS.md +15 -6
  195. package/corpus/templates/analytics/actions/install-dashboard-template.ts +79 -43
  196. package/corpus/templates/analytics/actions/list-explorer-dashboards.ts +3 -3
  197. package/corpus/templates/analytics/actions/list-sql-dashboards.ts +8 -3
  198. package/corpus/templates/analytics/actions/navigate.ts +59 -5
  199. package/corpus/templates/analytics/actions/rename-analysis.ts +8 -2
  200. package/corpus/templates/analytics/actions/rename-dashboard.ts +8 -7
  201. package/corpus/templates/analytics/actions/view-screen.ts +7 -29
  202. package/corpus/templates/analytics/app/components/ProviderCorpusJobNotifier.tsx +20 -3
  203. package/corpus/templates/analytics/app/components/ResourceLoadError.tsx +42 -0
  204. package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +2 -1
  205. package/corpus/templates/analytics/app/components/layout/CommandPalette.tsx +85 -70
  206. package/corpus/templates/analytics/app/components/layout/Header.tsx +1 -1
  207. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +128 -95
  208. package/corpus/templates/analytics/app/components/layout/SidebarLoadError.tsx +24 -0
  209. package/corpus/templates/analytics/app/global.css +19 -20
  210. package/corpus/templates/analytics/app/hooks/use-dashboard-views.ts +15 -5
  211. package/corpus/templates/analytics/app/i18n/zh-TW.ts +4 -0
  212. package/corpus/templates/analytics/app/i18n-data.ts +40 -0
  213. package/corpus/templates/analytics/app/lib/provider-corpus-job-sync.ts +26 -0
  214. package/corpus/templates/analytics/app/pages/Settings.tsx +41 -343
  215. package/corpus/templates/analytics/app/pages/adhoc/explorer/components/SqlPreview.tsx +36 -20
  216. package/corpus/templates/analytics/app/pages/adhoc/explorer/index.tsx +34 -20
  217. package/corpus/templates/analytics/app/pages/adhoc/explorer/use-explorer-config.ts +42 -41
  218. package/corpus/templates/analytics/app/pages/adhoc/explorer-dashboard/index.tsx +43 -36
  219. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/ViewsMenu.tsx +11 -2
  220. package/corpus/templates/analytics/app/pages/monitoring/ErrorsPanel.tsx +38 -7
  221. package/corpus/templates/analytics/app/pages/monitoring/MonitoringPage.tsx +1 -1
  222. package/corpus/templates/analytics/app/pages/monitoring/errors/i18n.ts +3 -0
  223. package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +333 -272
  224. package/corpus/templates/analytics/app/pages/sessions/SessionDevToolsPanel.tsx +72 -17
  225. package/corpus/templates/analytics/app/pages/sessions/SessionsPage.tsx +297 -108
  226. package/corpus/templates/analytics/app/root.tsx +40 -8
  227. package/corpus/templates/analytics/app/routes/_index.tsx +14 -2
  228. package/corpus/templates/analytics/changelog/2026-06-24-first-party-signup-and-pageview-panels-now-honor-dashboard-filters.md +2 -1
  229. package/corpus/templates/analytics/changelog/2026-06-25-referrer-dashboard-panels-show-external-domains.md +2 -1
  230. package/corpus/templates/analytics/changelog/2026-07-03-agent-llm-observability-dashboard.md +1 -1
  231. package/corpus/templates/analytics/changelog/2026-07-06-mobile-chat-header-is-more-compact-and-the-menu-button-opens-navigation.md +1 -0
  232. package/corpus/templates/analytics/changelog/2026-07-08-dashboard-history-and-chat-context.md +1 -0
  233. package/corpus/templates/analytics/changelog/2026-07-08-settings-are-cleaner-searchable-and-alerts-have-their-own-tab.md +1 -0
  234. package/corpus/templates/analytics/changelog/2026-07-08-sidebar-sections-stay-collapsed-until-opened.md +1 -0
  235. package/corpus/templates/analytics/changelog/2026-07-11-agent-feedback-sentiment-dashboard.md +6 -0
  236. package/corpus/templates/analytics/changelog/2026-07-11-analytics-chats-now-start-faster-by-loading-metric-definitio.md +6 -0
  237. package/corpus/templates/analytics/changelog/2026-07-11-analytics-no-longer-repeatedly-restarts-background-requests-.md +6 -0
  238. package/corpus/templates/analytics/changelog/2026-07-11-analytics-only-asks-for-replay-storage-when-you-enable-sessi.md +6 -0
  239. package/corpus/templates/analytics/changelog/2026-07-11-charts-now-show-their-loading-skeleton-while-refreshing.md +6 -0
  240. package/corpus/templates/analytics/changelog/2026-07-11-command-and-sql-previews-now-respond-without-lag.md +6 -0
  241. package/corpus/templates/analytics/changelog/2026-07-11-command-search-now-reports-loading-failures-and-lets-you-ret.md +6 -0
  242. package/corpus/templates/analytics/changelog/2026-07-11-dashboard-navigation-now-loads-faster-and-reports-request-fa.md +6 -0
  243. package/corpus/templates/analytics/changelog/2026-07-11-inferred-message-sentiment-dashboard.md +6 -0
  244. package/corpus/templates/analytics/changelog/2026-07-11-microphone-settings-from-realtime-voice-mode-now-open-the-vo.md +6 -0
  245. package/corpus/templates/analytics/changelog/2026-07-11-more-dashboard-edit-paths-are-now-safe-against-simultaneous-.md +6 -0
  246. package/corpus/templates/analytics/changelog/2026-07-11-realtime-voice-now-shows-a-clear-connection-indicator-comple.md +6 -0
  247. package/corpus/templates/analytics/changelog/2026-07-11-renaming-a-dashboard-is-now-safe-against-simultaneous-agent-.md +6 -0
  248. package/corpus/templates/analytics/changelog/2026-07-11-renaming-an-analysis-is-now-safe-against-simultaneous-edits.md +6 -0
  249. package/corpus/templates/analytics/changelog/2026-07-11-replay-event-counts-stay-hidden-until-recordings-finish-load.md +6 -0
  250. package/corpus/templates/analytics/changelog/2026-07-11-replay-storage-key-mismatches-show-actionable-setup-guidance.md +6 -0
  251. package/corpus/templates/analytics/changelog/2026-07-11-replay-timelines-group-continuous-scrolling-and-dev-tools-co.md +6 -0
  252. package/corpus/templates/analytics/changelog/2026-07-11-session-filters-now-stay-compact-in-a-settings-menu-at-mediu.md +6 -0
  253. package/corpus/templates/analytics/changelog/2026-07-11-session-replay-console-errors-now-link-to-matching-issues-or.md +6 -0
  254. package/corpus/templates/analytics/changelog/2026-07-11-session-replays-load-large-recordings-faster-and-surface-fai.md +6 -0
  255. package/corpus/templates/analytics/changelog/2026-07-11-session-replays-preserve-recorded-styles-and-viewport-layout.md +6 -0
  256. package/corpus/templates/analytics/changelog/2026-07-11-session-replays-stay-centered-instead-of-clipping-wide-recor.md +6 -0
  257. package/corpus/templates/analytics/changelog/2026-07-11-workspace-mounted-analytics-now-opens-ask-reliably-and-route.md +6 -0
  258. package/corpus/templates/analytics/docs/schemas/first-party-analytics.md +37 -3
  259. package/corpus/templates/analytics/package.json +1 -1
  260. package/corpus/templates/analytics/seeds/dashboards/agent-native-templates-first-party.json +37 -1
  261. package/corpus/templates/analytics/server/handlers/session-replay.ts +57 -0
  262. package/corpus/templates/analytics/server/lib/dashboard-catalog.ts +1 -24
  263. package/corpus/templates/analytics/server/lib/dashboard-seeds.ts +0 -5
  264. package/corpus/templates/analytics/server/lib/dashboards-store.ts +289 -20
  265. package/corpus/templates/analytics/server/lib/data-dictionary-context.ts +106 -34
  266. package/corpus/templates/analytics/server/lib/demo-dashboards.ts +20 -4
  267. package/corpus/templates/analytics/server/lib/session-replay-agent-context.ts +12 -0
  268. package/corpus/templates/analytics/server/lib/session-replay.ts +208 -2
  269. package/corpus/templates/analytics/server/plugins/agent-chat.ts +11 -39
  270. package/corpus/templates/analytics/server/plugins/onboarding.ts +7 -79
  271. package/corpus/templates/analytics/server/routes/api/session-replay/recordings/[recordingId]/chunks.get.ts +1 -0
  272. package/corpus/templates/assets/.agents/skills/frontend-design/SKILL.md +1 -1
  273. package/corpus/templates/assets/.agents/skills/real-time-sync/SKILL.md +2 -2
  274. package/corpus/templates/assets/app/components/create/RecentDraftsSection.tsx +30 -4
  275. package/corpus/templates/assets/app/global.css +4 -4
  276. package/corpus/templates/assets/app/routes/brand-kits.$id.tsx +0 -1
  277. package/corpus/templates/assets/app/routes/library.tsx +49 -6
  278. package/corpus/templates/assets/changelog/2026-07-11-library-load-failures-now-show-a-retry-action.md +6 -0
  279. package/corpus/templates/brain/.agents/skills/frontend-design/SKILL.md +1 -1
  280. package/corpus/templates/brain/.agents/skills/real-time-sync/SKILL.md +2 -2
  281. package/corpus/templates/brain/app/global.css +5 -5
  282. package/corpus/templates/brain/app/root.tsx +0 -3
  283. package/corpus/templates/calendar/.agents/skills/frontend-design/SKILL.md +1 -1
  284. package/corpus/templates/calendar/.agents/skills/real-time-sync/SKILL.md +2 -2
  285. package/corpus/templates/calendar/.env.example +5 -0
  286. package/corpus/templates/calendar/app/components/calendar/EventCard.tsx +2 -2
  287. package/corpus/templates/calendar/app/i18n/zh-TW.ts +2 -0
  288. package/corpus/templates/calendar/app/i18n-data.ts +20 -0
  289. package/corpus/templates/calendar/app/pages/BookingLinksPage.tsx +37 -1
  290. package/corpus/templates/calendar/app/pages/BookingsList.tsx +20 -3
  291. package/corpus/templates/calendar/app/root.tsx +1 -0
  292. package/corpus/templates/calendar/changelog/2026-07-11-booking-load-failures-now-show-a-retry-action.md +6 -0
  293. package/corpus/templates/calendar/changelog/2026-07-11-event-cards-give-subtle-press-feedback-and-smoother-hover.md +6 -0
  294. package/corpus/templates/chat/.agents/skills/frontend-design/SKILL.md +1 -1
  295. package/corpus/templates/chat/.agents/skills/real-time-sync/SKILL.md +2 -2
  296. package/corpus/templates/clips/.agents/skills/frontend-design/SKILL.md +1 -1
  297. package/corpus/templates/clips/actions/decline-invite.ts +8 -0
  298. package/corpus/templates/clips/app/components/library/folder-tree.tsx +209 -187
  299. package/corpus/templates/clips/app/components/meetings/meeting-card.tsx +2 -2
  300. package/corpus/templates/clips/app/components/player/reactions-tray.tsx +17 -5
  301. package/corpus/templates/clips/app/components/player/scrubber.tsx +5 -3
  302. package/corpus/templates/clips/app/components/recorder/pre-record-panel.tsx +2 -2
  303. package/corpus/templates/clips/app/components/workspace/insights-hub.tsx +119 -95
  304. package/corpus/templates/clips/app/global.css +45 -0
  305. package/corpus/templates/clips/app/hooks/use-auto-title.ts +74 -8
  306. package/corpus/templates/clips/app/hooks/use-library.ts +12 -25
  307. package/corpus/templates/clips/app/root.tsx +4 -0
  308. package/corpus/templates/clips/app/routes/_app.notifications.tsx +23 -2
  309. package/corpus/templates/clips/app/routes/_app.settings._index.tsx +20 -22
  310. package/corpus/templates/clips/app/routes/_app.trash.tsx +24 -2
  311. package/corpus/templates/clips/changelog/2026-07-11-controls-and-folders-now-move-more-smoothly.md +6 -0
  312. package/corpus/templates/clips/changelog/2026-07-11-declining-an-invitation-now-requires-being-its-recipient.md +6 -0
  313. package/corpus/templates/clips/changelog/2026-07-11-generated-titles-no-longer-cause-continuous-background-refreshes.md +6 -0
  314. package/corpus/templates/clips/changelog/2026-07-11-recording-overlays-are-lighter-weight-and-no-longer-cause-pa.md +6 -0
  315. package/corpus/templates/clips/changelog/2026-07-11-s3-storage-setup-stays-collapsed-until-you-choose-it-as-the-.md +6 -0
  316. package/corpus/templates/clips/changelog/2026-07-11-workspace-load-failures-now-show-a-retry-action.md +6 -0
  317. package/corpus/templates/clips/chrome-extension/src/overlay.css +34 -5
  318. package/corpus/templates/clips/chrome-extension/src/styles.css +2 -2
  319. package/corpus/templates/clips/desktop/src/styles.css +71 -26
  320. package/corpus/templates/content/.agents/skills/frontend-design/SKILL.md +1 -1
  321. package/corpus/templates/content/.agents/skills/real-time-sync/SKILL.md +2 -2
  322. package/corpus/templates/content/actions/move-document.ts +34 -18
  323. package/corpus/templates/content/app/components/QueryErrorState.tsx +39 -0
  324. package/corpus/templates/content/app/components/editor/LinkHoverPreview.tsx +1 -1
  325. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +225 -1435
  326. package/corpus/templates/content/app/components/editor/database/GalleryView.tsx +368 -0
  327. package/corpus/templates/content/app/components/editor/database/ListView.tsx +353 -0
  328. package/corpus/templates/content/app/components/editor/database/TimelineView.tsx +580 -0
  329. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +11 -2
  330. package/corpus/templates/content/app/global.css +19 -19
  331. package/corpus/templates/content/app/hooks/use-comments.ts +0 -1
  332. package/corpus/templates/content/app/root.tsx +2 -2
  333. package/corpus/templates/content/app/routes/_app._index.tsx +11 -1
  334. package/corpus/templates/content/changelog/2026-07-11-comments-now-update-from-live-collaboration-events-without-c.md +6 -0
  335. package/corpus/templates/content/changelog/2026-07-11-document-load-failures-now-show-a-retry-action.md +6 -0
  336. package/corpus/templates/content/changelog/2026-07-11-editor-toggle-feedback-now-feels-more-responsive.md +6 -0
  337. package/corpus/templates/content/changelog/2026-07-11-moving-documents-at-the-same-time-no-longer-scrambles-their-.md +6 -0
  338. package/corpus/templates/content/changelog/2026-07-11-public-document-chats-now-start-faster-while-keeping-full-do.md +6 -0
  339. package/corpus/templates/content/changelog/2026-07-11-reopening-a-comment-now-uses-consistent-permissions-everywhe.md +6 -0
  340. package/corpus/templates/content/changelog/2026-07-11-sidebar-resizing-now-tracks-your-cursor-instantly-instead-of.md +6 -0
  341. package/corpus/templates/content/server/lib/public-documents.ts +47 -10
  342. package/corpus/templates/content/server/routes/api/comments/[id].patch.ts +24 -24
  343. package/corpus/templates/design/.agents/skills/frontend-design/SKILL.md +1 -1
  344. package/corpus/templates/design/app/components/QueryErrorState.tsx +24 -0
  345. package/corpus/templates/design/app/components/design/CanvasContextMenu.tsx +1 -1
  346. package/corpus/templates/design/app/components/design/DesignImportPanel.tsx +5 -2
  347. package/corpus/templates/design/app/components/design/EditPanel.tsx +326 -319
  348. package/corpus/templates/design/app/components/design/LayersPanel.tsx +198 -193
  349. package/corpus/templates/design/app/components/design/edit-panel/panel-primitives.tsx +11 -4
  350. package/corpus/templates/design/app/components/design/inspector/DesignColorPicker.tsx +1 -1
  351. package/corpus/templates/design/app/components/layout/Header.tsx +1 -1
  352. package/corpus/templates/design/app/components/layout/Layout.tsx +1 -1
  353. package/corpus/templates/design/app/pages/DesignSystems.tsx +7 -1
  354. package/corpus/templates/design/app/pages/Index.tsx +14 -2
  355. package/corpus/templates/design/app/pages/Present.tsx +16 -3
  356. package/corpus/templates/design/app/pages/Templates.tsx +10 -4
  357. package/corpus/templates/design/app/pages/design-editor/canvas-primitive-insert.ts +484 -0
  358. package/corpus/templates/design/app/pages/design-editor/clone-and-pen-edit.ts +378 -0
  359. package/corpus/templates/design/app/pages/design-editor/design-data-geometry-utils.ts +138 -0
  360. package/corpus/templates/design/app/pages/design-editor/dom-utils.ts +15 -0
  361. package/corpus/templates/design/app/pages/design-editor/generation-prompt-directives.ts +180 -0
  362. package/corpus/templates/design/app/pages/design-editor/html-layer-positioning.ts +226 -0
  363. package/corpus/templates/design/app/pages/design-editor/png-export-render.ts +348 -0
  364. package/corpus/templates/design/app/pages/design-editor/screen-command-utils.ts +160 -0
  365. package/corpus/templates/design/app/pages/design-editor/text-edit-utils.ts +238 -0
  366. package/corpus/templates/design/app/pages/design-editor/tool-state.ts +23 -1
  367. package/corpus/templates/design/app/pages/design-editor/types.ts +25 -0
  368. package/corpus/templates/design/app/root.tsx +10 -1
  369. package/corpus/templates/design/changelog/2026-07-11-canvas-context-menus-now-open-without-motion-jitter.md +6 -0
  370. package/corpus/templates/design/changelog/2026-07-11-design-load-failures-now-show-a-retry-action.md +6 -0
  371. package/corpus/templates/design/changelog/2026-07-11-inspector-tooltips-appear-instantly-as-you-sweep-across-icon.md +6 -0
  372. package/corpus/templates/dispatch/.agents/skills/frontend-design/SKILL.md +1 -1
  373. package/corpus/templates/dispatch/app/i18n/zh-TW.ts +10 -0
  374. package/corpus/templates/dispatch/app/i18n-data.ts +123 -0
  375. package/corpus/templates/dispatch/app/routes/integrations.tsx +163 -144
  376. package/corpus/templates/dispatch/changelog/2026-07-11-dispatch-mcp-connections-now-start-with-safer-app-access-and.md +6 -0
  377. package/corpus/templates/dispatch/changelog/2026-07-11-overview-and-chat-now-share-a-cleaner-more-stable-flow.md +6 -0
  378. package/corpus/templates/dispatch/changelog/2026-07-11-query-errors-now-show-a-retry-option.md +6 -0
  379. package/corpus/templates/forms/.agents/skills/frontend-design/SKILL.md +1 -1
  380. package/corpus/templates/forms/.agents/skills/real-time-sync/SKILL.md +2 -2
  381. package/corpus/templates/forms/app/components/layout/Sidebar.tsx +3 -3
  382. package/corpus/templates/forms/app/root.tsx +34 -8
  383. package/corpus/templates/macros/.agents/skills/frontend-design/SKILL.md +1 -1
  384. package/corpus/templates/macros/app/components/DailyProgress.tsx +25 -5
  385. package/corpus/templates/macros/app/components/QueryErrorState.tsx +31 -0
  386. package/corpus/templates/macros/app/components/WeightTracker.tsx +5 -1
  387. package/corpus/templates/macros/app/components/layout/AppLayout.tsx +1 -2
  388. package/corpus/templates/macros/app/components/ui/button.tsx +1 -1
  389. package/corpus/templates/macros/app/components/ui/progress.tsx +1 -1
  390. package/corpus/templates/macros/app/components/ui/tabs.tsx +1 -1
  391. package/corpus/templates/macros/app/i18n/ar-SA.ts +2 -0
  392. package/corpus/templates/macros/app/i18n/de-DE.ts +2 -0
  393. package/corpus/templates/macros/app/i18n/en-US.ts +2 -0
  394. package/corpus/templates/macros/app/i18n/es-ES.ts +2 -0
  395. package/corpus/templates/macros/app/i18n/fr-FR.ts +2 -0
  396. package/corpus/templates/macros/app/i18n/hi-IN.ts +2 -0
  397. package/corpus/templates/macros/app/i18n/ja-JP.ts +2 -0
  398. package/corpus/templates/macros/app/i18n/ko-KR.ts +2 -0
  399. package/corpus/templates/macros/app/i18n/pt-BR.ts +2 -0
  400. package/corpus/templates/macros/app/i18n/zh-CN.ts +2 -0
  401. package/corpus/templates/macros/app/i18n/zh-TW.ts +2 -0
  402. package/corpus/templates/macros/app/root.tsx +0 -3
  403. package/corpus/templates/macros/app/routes/_index.tsx +22 -12
  404. package/corpus/templates/macros/app/routes/analytics.tsx +31 -10
  405. package/corpus/templates/macros/changelog/2026-07-11-daily-tracking-now-loads-and-updates-more-quickly.md +6 -0
  406. package/corpus/templates/macros/changelog/2026-07-11-data-load-failures-now-show-a-clear-error-with-a-retry-actio.md +6 -0
  407. package/corpus/templates/mail/.agents/skills/frontend-design/SKILL.md +1 -1
  408. package/corpus/templates/mail/.agents/skills/real-time-sync/SKILL.md +2 -2
  409. package/corpus/templates/mail/.env.example +16 -11
  410. package/corpus/templates/mail/actions/list-emails.ts +39 -35
  411. package/corpus/templates/mail/app/components/email/ComposeModal.tsx +58 -6
  412. package/corpus/templates/mail/app/components/email/EmailListItem.tsx +35 -2
  413. package/corpus/templates/mail/app/components/layout/AppLayout.tsx +113 -104
  414. package/corpus/templates/mail/app/hooks/use-compose-state.ts +1 -0
  415. package/corpus/templates/mail/app/root.tsx +9 -22
  416. package/corpus/templates/mail/changelog/2026-07-11-compose-and-navigation-motion-now-feel-faster-and-smoother.md +6 -0
  417. package/corpus/templates/mail/changelog/2026-07-11-swipe-to-archive-or-snooze-now-responds-to-quick-flicks-not-.md +6 -0
  418. package/corpus/templates/mail/changelog/2026-07-11-the-assistant-now-sees-the-same-inbox-you-do-snoozed-mail-st.md +6 -0
  419. package/corpus/templates/mail/server/handlers/emails.ts +25 -69
  420. package/corpus/templates/mail/server/lib/list-inbox-emails.ts +169 -0
  421. package/corpus/templates/plan/.agents/skills/frontend-design/SKILL.md +1 -1
  422. package/corpus/templates/plan/.agents/skills/real-time-sync/SKILL.md +2 -2
  423. package/corpus/templates/plan/.env.example +4 -0
  424. package/corpus/templates/plan/actions/create-plan-design.ts +89 -81
  425. package/corpus/templates/plan/actions/create-prototype-plan.ts +72 -59
  426. package/corpus/templates/plan/actions/create-ui-plan.ts +70 -55
  427. package/corpus/templates/plan/actions/create-visual-plan.ts +65 -51
  428. package/corpus/templates/plan/actions/update-local-plan-folder.ts +43 -30
  429. package/corpus/templates/plan/actions/update-visual-plan.ts +81 -64
  430. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +17 -0
  431. package/corpus/templates/plan/app/components/ui/tabs.tsx +1 -1
  432. package/corpus/templates/plan/app/hooks/use-navigation-state.ts +5 -2
  433. package/corpus/templates/plan/app/hooks/use-plans.ts +6 -13
  434. package/corpus/templates/plan/app/i18n/ar-SA.ts +10 -0
  435. package/corpus/templates/plan/app/i18n/de-DE.ts +10 -0
  436. package/corpus/templates/plan/app/i18n/en-US.ts +10 -0
  437. package/corpus/templates/plan/app/i18n/es-ES.ts +10 -0
  438. package/corpus/templates/plan/app/i18n/fr-FR.ts +10 -0
  439. package/corpus/templates/plan/app/i18n/hi-IN.ts +10 -0
  440. package/corpus/templates/plan/app/i18n/ja-JP.ts +10 -0
  441. package/corpus/templates/plan/app/i18n/ko-KR.ts +10 -0
  442. package/corpus/templates/plan/app/i18n/pt-BR.ts +10 -0
  443. package/corpus/templates/plan/app/i18n/zh-CN.ts +10 -0
  444. package/corpus/templates/plan/app/i18n/zh-TW.ts +10 -0
  445. package/corpus/templates/plan/app/lib/plan-local-bridge.ts +80 -1
  446. package/corpus/templates/plan/app/pages/PlansPage.tsx +157 -31
  447. package/corpus/templates/plan/app/root.tsx +11 -0
  448. package/corpus/templates/plan/changelog/2026-07-11-local-plans-now-explain-and-recover-from-browser-permission-.md +6 -0
  449. package/corpus/templates/plan/changelog/2026-07-11-plan-edits-now-save-atomically-and-can-no-longer-partially-a.md +6 -0
  450. package/corpus/templates/plan/changelog/2026-07-11-plan-lists-now-show-a-clear-error-with-a-retry-action-when-t.md +6 -0
  451. package/corpus/templates/plan/changelog/2026-07-11-plan-refreshes-only-when-content-changes.md +6 -0
  452. package/corpus/templates/plan/shared/plan-content.ts +546 -260
  453. package/corpus/templates/slides/.agents/skills/frontend-design/SKILL.md +1 -1
  454. package/corpus/templates/slides/actions/delete-slide-comment.ts +49 -0
  455. package/corpus/templates/slides/actions/update-slide-comment.ts +93 -0
  456. package/corpus/templates/slides/actions/view-screen.ts +14 -6
  457. package/corpus/templates/slides/app/components/comments/SlideCommentsPanel.tsx +37 -11
  458. package/corpus/templates/slides/app/components/editor/EditorSidebar.tsx +1 -1
  459. package/corpus/templates/slides/app/components/editor/EditorToolbar.tsx +2 -2
  460. package/corpus/templates/slides/app/components/editor/GenerateSlidesDialog.tsx +2 -2
  461. package/corpus/templates/slides/app/components/layout/Header.tsx +1 -1
  462. package/corpus/templates/slides/app/components/presentation/PresentationView.tsx +4 -2
  463. package/corpus/templates/slides/app/components/visual-editor/CanvasCommentPins.tsx +4 -3
  464. package/corpus/templates/slides/app/context/DeckContext.tsx +10 -0
  465. package/corpus/templates/slides/app/hooks/use-slide-comments.ts +7 -31
  466. package/corpus/templates/slides/app/i18n/ar-SA.ts +6 -0
  467. package/corpus/templates/slides/app/i18n/de-DE.ts +6 -0
  468. package/corpus/templates/slides/app/i18n/en-US.ts +6 -0
  469. package/corpus/templates/slides/app/i18n/es-ES.ts +6 -0
  470. package/corpus/templates/slides/app/i18n/fr-FR.ts +6 -0
  471. package/corpus/templates/slides/app/i18n/hi-IN.ts +6 -0
  472. package/corpus/templates/slides/app/i18n/ja-JP.ts +6 -0
  473. package/corpus/templates/slides/app/i18n/ko-KR.ts +6 -0
  474. package/corpus/templates/slides/app/i18n/pt-BR.ts +6 -0
  475. package/corpus/templates/slides/app/i18n/zh-CN.ts +5 -0
  476. package/corpus/templates/slides/app/i18n/zh-TW.ts +5 -0
  477. package/corpus/templates/slides/app/pages/DesignSystems.tsx +23 -2
  478. package/corpus/templates/slides/app/pages/Index.tsx +29 -1
  479. package/corpus/templates/slides/changelog/2026-07-11-comment-load-failures-now-show-a-retry-action-instead-of-say.md +6 -0
  480. package/corpus/templates/slides/changelog/2026-07-11-comment-pins-now-clear-with-a-faster-smoother-confirmation.md +6 -0
  481. package/corpus/templates/slides/changelog/2026-07-11-comments-now-update-from-live-collaboration-events-without-c.md +6 -0
  482. package/corpus/templates/slides/changelog/2026-07-11-deck-and-design-system-load-failures-now-show-a-retry-action.md +6 -0
  483. package/corpus/templates/slides/changelog/2026-07-11-editor-toggles-and-toolbar-menus-now-animate-smoothly.md +6 -0
  484. package/corpus/templates/slides/changelog/2026-07-11-the-assistant-can-now-resolve-reopen-and-delete-slide-commen.md +6 -0
  485. package/corpus/templates/slides/changelog/2026-07-11-viewing-slides-no-longer-loads-every-deck-s-full-contents-in.md +6 -0
  486. package/corpus/templates/slides/server/routes/api/comments/[id].delete.ts +29 -48
  487. package/corpus/templates/slides/server/routes/api/comments/[id].patch.ts +29 -65
  488. package/dist/action-change-marker.d.ts +1 -0
  489. package/dist/action-change-marker.d.ts.map +1 -1
  490. package/dist/action-change-marker.js +7 -1
  491. package/dist/action-change-marker.js.map +1 -1
  492. package/dist/action.d.ts +23 -0
  493. package/dist/action.d.ts.map +1 -1
  494. package/dist/action.js +13 -0
  495. package/dist/action.js.map +1 -1
  496. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  497. package/dist/agent/engine/builder-engine.js +3 -0
  498. package/dist/agent/engine/builder-engine.js.map +1 -1
  499. package/dist/agent/engine/context-directives-transform.d.ts +25 -0
  500. package/dist/agent/engine/context-directives-transform.d.ts.map +1 -0
  501. package/dist/agent/engine/context-directives-transform.js +53 -0
  502. package/dist/agent/engine/context-directives-transform.js.map +1 -0
  503. package/dist/agent/engine/continuation-dispatch-retry.d.ts +40 -0
  504. package/dist/agent/engine/continuation-dispatch-retry.d.ts.map +1 -0
  505. package/dist/agent/engine/continuation-dispatch-retry.js +109 -0
  506. package/dist/agent/engine/continuation-dispatch-retry.js.map +1 -0
  507. package/dist/agent/engine/tool-call-journal-seed.d.ts +46 -0
  508. package/dist/agent/engine/tool-call-journal-seed.d.ts.map +1 -0
  509. package/dist/agent/engine/tool-call-journal-seed.js +60 -0
  510. package/dist/agent/engine/tool-call-journal-seed.js.map +1 -0
  511. package/dist/agent/production-agent.d.ts +7 -0
  512. package/dist/agent/production-agent.d.ts.map +1 -1
  513. package/dist/agent/production-agent.js +102 -222
  514. package/dist/agent/production-agent.js.map +1 -1
  515. package/dist/changelog/parse.d.ts +4 -2
  516. package/dist/changelog/parse.d.ts.map +1 -1
  517. package/dist/changelog/parse.js +5 -3
  518. package/dist/changelog/parse.js.map +1 -1
  519. package/dist/cli/doctor.d.ts.map +1 -1
  520. package/dist/cli/doctor.js +7 -3
  521. package/dist/cli/doctor.js.map +1 -1
  522. package/dist/cli/plan-local.d.ts.map +1 -1
  523. package/dist/cli/plan-local.js +8 -2
  524. package/dist/cli/plan-local.js.map +1 -1
  525. package/dist/cli/skills-content/assets-skill.d.ts +2 -0
  526. package/dist/cli/skills-content/assets-skill.d.ts.map +1 -0
  527. package/dist/cli/skills-content/assets-skill.js +84 -0
  528. package/dist/cli/skills-content/assets-skill.js.map +1 -0
  529. package/dist/cli/skills-content/canvas.d.ts +4 -0
  530. package/dist/cli/skills-content/canvas.d.ts.map +1 -0
  531. package/dist/cli/skills-content/canvas.js +152 -0
  532. package/dist/cli/skills-content/canvas.js.map +1 -0
  533. package/dist/cli/skills-content/connection.d.ts +2 -0
  534. package/dist/cli/skills-content/connection.d.ts.map +1 -0
  535. package/dist/cli/skills-content/connection.js +53 -0
  536. package/dist/cli/skills-content/connection.js.map +1 -0
  537. package/dist/cli/skills-content/content-skill.d.ts +2 -0
  538. package/dist/cli/skills-content/content-skill.d.ts.map +1 -0
  539. package/dist/cli/skills-content/content-skill.js +110 -0
  540. package/dist/cli/skills-content/content-skill.js.map +1 -0
  541. package/dist/cli/skills-content/design-exploration-skill.d.ts +2 -0
  542. package/dist/cli/skills-content/design-exploration-skill.d.ts.map +1 -0
  543. package/dist/cli/skills-content/design-exploration-skill.js +119 -0
  544. package/dist/cli/skills-content/design-exploration-skill.js.map +1 -0
  545. package/dist/cli/skills-content/design-visual-edit-skill.d.ts +2 -0
  546. package/dist/cli/skills-content/design-visual-edit-skill.d.ts.map +1 -0
  547. package/dist/cli/skills-content/design-visual-edit-skill.js +229 -0
  548. package/dist/cli/skills-content/design-visual-edit-skill.js.map +1 -0
  549. package/dist/cli/skills-content/document-quality.d.ts +4 -0
  550. package/dist/cli/skills-content/document-quality.d.ts.map +1 -0
  551. package/dist/cli/skills-content/document-quality.js +195 -0
  552. package/dist/cli/skills-content/document-quality.js.map +1 -0
  553. package/dist/cli/skills-content/exemplar.d.ts +4 -0
  554. package/dist/cli/skills-content/exemplar.d.ts.map +1 -0
  555. package/dist/cli/skills-content/exemplar.js +68 -0
  556. package/dist/cli/skills-content/exemplar.js.map +1 -0
  557. package/dist/cli/skills-content/help.d.ts +2 -0
  558. package/dist/cli/skills-content/help.d.ts.map +1 -0
  559. package/dist/cli/skills-content/help.js +78 -0
  560. package/dist/cli/skills-content/help.js.map +1 -0
  561. package/dist/cli/skills-content/index.d.ts +23 -0
  562. package/dist/cli/skills-content/index.d.ts.map +1 -0
  563. package/dist/cli/skills-content/index.js +23 -0
  564. package/dist/cli/skills-content/index.js.map +1 -0
  565. package/dist/cli/skills-content/local-files.d.ts +2 -0
  566. package/dist/cli/skills-content/local-files.d.ts.map +1 -0
  567. package/dist/cli/skills-content/local-files.js +96 -0
  568. package/dist/cli/skills-content/local-files.js.map +1 -0
  569. package/dist/cli/skills-content/plan-setup-auth.d.ts +9 -0
  570. package/dist/cli/skills-content/plan-setup-auth.d.ts.map +1 -0
  571. package/dist/cli/skills-content/plan-setup-auth.js +81 -0
  572. package/dist/cli/skills-content/plan-setup-auth.js.map +1 -0
  573. package/dist/cli/skills-content/visual-plan-skill.d.ts +2 -0
  574. package/dist/cli/skills-content/visual-plan-skill.d.ts.map +1 -0
  575. package/dist/cli/skills-content/visual-plan-skill.js +471 -0
  576. package/dist/cli/skills-content/visual-plan-skill.js.map +1 -0
  577. package/dist/cli/skills-content/visual-recap-skill.d.ts +2 -0
  578. package/dist/cli/skills-content/visual-recap-skill.d.ts.map +1 -0
  579. package/dist/cli/skills-content/visual-recap-skill.js +548 -0
  580. package/dist/cli/skills-content/visual-recap-skill.js.map +1 -0
  581. package/dist/cli/skills-content/visualize-repo-skill.d.ts +2 -0
  582. package/dist/cli/skills-content/visualize-repo-skill.d.ts.map +1 -0
  583. package/dist/cli/skills-content/visualize-repo-skill.js +94 -0
  584. package/dist/cli/skills-content/visualize-repo-skill.js.map +1 -0
  585. package/dist/cli/skills-content/wireframe.d.ts +4 -0
  586. package/dist/cli/skills-content/wireframe.d.ts.map +1 -0
  587. package/dist/cli/skills-content/wireframe.js +347 -0
  588. package/dist/cli/skills-content/wireframe.js.map +1 -0
  589. package/dist/cli/skills.d.ts +2 -10
  590. package/dist/cli/skills.d.ts.map +1 -1
  591. package/dist/cli/skills.js +2 -2710
  592. package/dist/cli/skills.js.map +1 -1
  593. package/dist/client/AgentPanel.d.ts.map +1 -1
  594. package/dist/client/AgentPanel.js +6 -5
  595. package/dist/client/AgentPanel.js.map +1 -1
  596. package/dist/client/AssistantChat.d.ts +7 -0
  597. package/dist/client/AssistantChat.d.ts.map +1 -1
  598. package/dist/client/AssistantChat.js +62 -40
  599. package/dist/client/AssistantChat.js.map +1 -1
  600. package/dist/client/CommandMenu.d.ts.map +1 -1
  601. package/dist/client/CommandMenu.js +15 -3
  602. package/dist/client/CommandMenu.js.map +1 -1
  603. package/dist/client/FeedbackButton.js +2 -2
  604. package/dist/client/FeedbackButton.js.map +1 -1
  605. package/dist/client/analytics.d.ts.map +1 -1
  606. package/dist/client/analytics.js +26 -0
  607. package/dist/client/analytics.js.map +1 -1
  608. package/dist/client/app-providers.d.ts +13 -5
  609. package/dist/client/app-providers.d.ts.map +1 -1
  610. package/dist/client/app-providers.js +9 -6
  611. package/dist/client/app-providers.js.map +1 -1
  612. package/dist/client/blocks/library/wireframe-kit.d.ts +2 -0
  613. package/dist/client/blocks/library/wireframe-kit.d.ts.map +1 -1
  614. package/dist/client/blocks/library/wireframe-kit.js +9 -2
  615. package/dist/client/blocks/library/wireframe-kit.js.map +1 -1
  616. package/dist/client/chat/tool-call-display.d.ts +4 -0
  617. package/dist/client/chat/tool-call-display.d.ts.map +1 -1
  618. package/dist/client/chat/tool-call-display.js +3 -3
  619. package/dist/client/chat/tool-call-display.js.map +1 -1
  620. package/dist/client/chat-model-groups.d.ts.map +1 -1
  621. package/dist/client/chat-model-groups.js +24 -0
  622. package/dist/client/chat-model-groups.js.map +1 -1
  623. package/dist/client/composer/PastedTextChip.js +1 -1
  624. package/dist/client/composer/PastedTextChip.js.map +1 -1
  625. package/dist/client/composer/RealtimeVoiceMode.d.ts +40 -2
  626. package/dist/client/composer/RealtimeVoiceMode.d.ts.map +1 -1
  627. package/dist/client/composer/RealtimeVoiceMode.js +186 -35
  628. package/dist/client/composer/RealtimeVoiceMode.js.map +1 -1
  629. package/dist/client/composer/TiptapComposer.d.ts +4 -0
  630. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  631. package/dist/client/composer/TiptapComposer.js +48 -30
  632. package/dist/client/composer/TiptapComposer.js.map +1 -1
  633. package/dist/client/composer/VoiceButton.d.ts +2 -0
  634. package/dist/client/composer/VoiceButton.d.ts.map +1 -1
  635. package/dist/client/composer/VoiceButton.js +9 -3
  636. package/dist/client/composer/VoiceButton.js.map +1 -1
  637. package/dist/client/composer/index.d.ts +2 -2
  638. package/dist/client/composer/index.d.ts.map +1 -1
  639. package/dist/client/composer/index.js +1 -1
  640. package/dist/client/composer/index.js.map +1 -1
  641. package/dist/client/composer/useRealtimeVoiceMode.d.ts +104 -2
  642. package/dist/client/composer/useRealtimeVoiceMode.d.ts.map +1 -1
  643. package/dist/client/composer/useRealtimeVoiceMode.js +1015 -35
  644. package/dist/client/composer/useRealtimeVoiceMode.js.map +1 -1
  645. package/dist/client/context-xray/ContextXRayPanel.d.ts.map +1 -1
  646. package/dist/client/context-xray/ContextXRayPanel.js +4 -1
  647. package/dist/client/context-xray/ContextXRayPanel.js.map +1 -1
  648. package/dist/client/extensions/ExtensionEditor.d.ts.map +1 -1
  649. package/dist/client/extensions/ExtensionEditor.js +15 -5
  650. package/dist/client/extensions/ExtensionEditor.js.map +1 -1
  651. package/dist/client/extensions/ExtensionQueryErrorState.d.ts +8 -0
  652. package/dist/client/extensions/ExtensionQueryErrorState.d.ts.map +1 -0
  653. package/dist/client/extensions/ExtensionQueryErrorState.js +11 -0
  654. package/dist/client/extensions/ExtensionQueryErrorState.js.map +1 -0
  655. package/dist/client/extensions/ExtensionSlot.d.ts.map +1 -1
  656. package/dist/client/extensions/ExtensionSlot.js +17 -7
  657. package/dist/client/extensions/ExtensionSlot.js.map +1 -1
  658. package/dist/client/extensions/ExtensionViewer.d.ts.map +1 -1
  659. package/dist/client/extensions/ExtensionViewer.js +17 -7
  660. package/dist/client/extensions/ExtensionViewer.js.map +1 -1
  661. package/dist/client/extensions/ExtensionsListPage.d.ts.map +1 -1
  662. package/dist/client/extensions/ExtensionsListPage.js +5 -3
  663. package/dist/client/extensions/ExtensionsListPage.js.map +1 -1
  664. package/dist/client/extensions/ExtensionsSidebarSection.d.ts.map +1 -1
  665. package/dist/client/extensions/ExtensionsSidebarSection.js +21 -8
  666. package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -1
  667. package/dist/client/index.d.ts +1 -3
  668. package/dist/client/index.d.ts.map +1 -1
  669. package/dist/client/index.js +1 -6
  670. package/dist/client/index.js.map +1 -1
  671. package/dist/client/progress/RunsTray.d.ts.map +1 -1
  672. package/dist/client/progress/RunsTray.js +17 -4
  673. package/dist/client/progress/RunsTray.js.map +1 -1
  674. package/dist/client/settings/SecretsSection.d.ts +2 -3
  675. package/dist/client/settings/SecretsSection.d.ts.map +1 -1
  676. package/dist/client/settings/SecretsSection.js +46 -22
  677. package/dist/client/settings/SecretsSection.js.map +1 -1
  678. package/dist/client/settings/SettingsPanel.d.ts +9 -0
  679. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  680. package/dist/client/settings/SettingsPanel.js +46 -12
  681. package/dist/client/settings/SettingsPanel.js.map +1 -1
  682. package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
  683. package/dist/client/settings/SettingsTabsPage.js +4 -0
  684. package/dist/client/settings/SettingsTabsPage.js.map +1 -1
  685. package/dist/client/settings/useBuilderStatus.d.ts +2 -0
  686. package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
  687. package/dist/client/settings/useBuilderStatus.js +4 -0
  688. package/dist/client/settings/useBuilderStatus.js.map +1 -1
  689. package/dist/client/tool-cells/EditCell.d.ts.map +1 -1
  690. package/dist/client/tool-cells/EditCell.js +2 -1
  691. package/dist/client/tool-cells/EditCell.js.map +1 -1
  692. package/dist/client/tool-cells/FilesChangedSummary.d.ts.map +1 -1
  693. package/dist/client/tool-cells/FilesChangedSummary.js +2 -1
  694. package/dist/client/tool-cells/FilesChangedSummary.js.map +1 -1
  695. package/dist/client/tool-cells/WriteCell.d.ts.map +1 -1
  696. package/dist/client/tool-cells/WriteCell.js +2 -1
  697. package/dist/client/tool-cells/WriteCell.js.map +1 -1
  698. package/dist/client/use-action.d.ts +2 -0
  699. package/dist/client/use-action.d.ts.map +1 -1
  700. package/dist/client/use-action.js +10 -0
  701. package/dist/client/use-action.js.map +1 -1
  702. package/dist/client/use-agent-chat-home-handoff.d.ts +2 -0
  703. package/dist/client/use-agent-chat-home-handoff.d.ts.map +1 -1
  704. package/dist/client/use-agent-chat-home-handoff.js +7 -1
  705. package/dist/client/use-agent-chat-home-handoff.js.map +1 -1
  706. package/dist/client/use-agent-engine-configured.d.ts.map +1 -1
  707. package/dist/client/use-agent-engine-configured.js +17 -3
  708. package/dist/client/use-agent-engine-configured.js.map +1 -1
  709. package/dist/client/use-db-sync.d.ts +8 -2
  710. package/dist/client/use-db-sync.d.ts.map +1 -1
  711. package/dist/client/use-db-sync.js +57 -32
  712. package/dist/client/use-db-sync.js.map +1 -1
  713. package/dist/client/use-pausing-interval.d.ts.map +1 -1
  714. package/dist/client/use-pausing-interval.js +16 -4
  715. package/dist/client/use-pausing-interval.js.map +1 -1
  716. package/dist/client/visual-style-controls.js +1 -1
  717. package/dist/client/visual-style-controls.js.map +1 -1
  718. package/dist/collab/routes.d.ts +1 -1
  719. package/dist/deploy/build.d.ts.map +1 -1
  720. package/dist/deploy/build.js +36 -14
  721. package/dist/deploy/build.js.map +1 -1
  722. package/dist/integrations/google-docs-poller.d.ts +7 -0
  723. package/dist/integrations/google-docs-poller.d.ts.map +1 -1
  724. package/dist/integrations/google-docs-poller.js +13 -3
  725. package/dist/integrations/google-docs-poller.js.map +1 -1
  726. package/dist/integrations/plugin.d.ts.map +1 -1
  727. package/dist/integrations/plugin.js +10 -0
  728. package/dist/integrations/plugin.js.map +1 -1
  729. package/dist/integrations/scope-store.js +1 -1
  730. package/dist/integrations/scope-store.js.map +1 -1
  731. package/dist/integrations/usage-budget-store.js +1 -1
  732. package/dist/integrations/usage-budget-store.js.map +1 -1
  733. package/dist/integrations/webhook-handler.d.ts +11 -0
  734. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  735. package/dist/integrations/webhook-handler.js +16 -4
  736. package/dist/integrations/webhook-handler.js.map +1 -1
  737. package/dist/jobs/scheduler.d.ts +12 -0
  738. package/dist/jobs/scheduler.d.ts.map +1 -1
  739. package/dist/jobs/scheduler.js +13 -3
  740. package/dist/jobs/scheduler.js.map +1 -1
  741. package/dist/localization/default-messages.d.ts +47 -0
  742. package/dist/localization/default-messages.d.ts.map +1 -1
  743. package/dist/localization/default-messages.js +48 -1
  744. package/dist/localization/default-messages.js.map +1 -1
  745. package/dist/mcp/oauth-token.d.ts +1 -1
  746. package/dist/mcp/oauth-token.d.ts.map +1 -1
  747. package/dist/mcp/oauth-token.js +6 -1
  748. package/dist/mcp/oauth-token.js.map +1 -1
  749. package/dist/mcp-client/workspace-servers.js +4 -4
  750. package/dist/mcp-client/workspace-servers.js.map +1 -1
  751. package/dist/notifications/routes.d.ts +2 -2
  752. package/dist/observability/routes.d.ts +5 -5
  753. package/dist/observability/routes.d.ts.map +1 -1
  754. package/dist/observability/routes.js +32 -0
  755. package/dist/observability/routes.js.map +1 -1
  756. package/dist/observability/sentiment.d.ts +42 -0
  757. package/dist/observability/sentiment.d.ts.map +1 -0
  758. package/dist/observability/sentiment.js +196 -0
  759. package/dist/observability/sentiment.js.map +1 -0
  760. package/dist/observability/store.d.ts +5 -0
  761. package/dist/observability/store.d.ts.map +1 -1
  762. package/dist/observability/store.js +17 -0
  763. package/dist/observability/store.js.map +1 -1
  764. package/dist/observability/traces.d.ts +2 -0
  765. package/dist/observability/traces.d.ts.map +1 -1
  766. package/dist/observability/traces.js +42 -57
  767. package/dist/observability/traces.js.map +1 -1
  768. package/dist/observability/tracking-identity.d.ts +3 -0
  769. package/dist/observability/tracking-identity.d.ts.map +1 -0
  770. package/dist/observability/tracking-identity.js +51 -0
  771. package/dist/observability/tracking-identity.js.map +1 -0
  772. package/dist/observability/types.d.ts +10 -0
  773. package/dist/observability/types.d.ts.map +1 -1
  774. package/dist/observability/types.js +3 -0
  775. package/dist/observability/types.js.map +1 -1
  776. package/dist/progress/routes.d.ts +1 -1
  777. package/dist/resources/handlers.d.ts +1 -1
  778. package/dist/secrets/crypto.d.ts +7 -6
  779. package/dist/secrets/crypto.d.ts.map +1 -1
  780. package/dist/secrets/crypto.js +30 -11
  781. package/dist/secrets/crypto.js.map +1 -1
  782. package/dist/secrets/routes.d.ts +9 -9
  783. package/dist/secrets/storage.d.ts +6 -0
  784. package/dist/secrets/storage.d.ts.map +1 -1
  785. package/dist/secrets/storage.js +61 -3
  786. package/dist/secrets/storage.js.map +1 -1
  787. package/dist/server/action-change.d.ts +1 -0
  788. package/dist/server/action-change.d.ts.map +1 -1
  789. package/dist/server/action-change.js +4 -1
  790. package/dist/server/action-change.js.map +1 -1
  791. package/dist/server/action-routes.d.ts.map +1 -1
  792. package/dist/server/action-routes.js +5 -0
  793. package/dist/server/action-routes.js.map +1 -1
  794. package/dist/server/agent-chat/action-filters-a2a.d.ts +50 -0
  795. package/dist/server/agent-chat/action-filters-a2a.d.ts.map +1 -0
  796. package/dist/server/agent-chat/action-filters-a2a.js +127 -0
  797. package/dist/server/agent-chat/action-filters-a2a.js.map +1 -0
  798. package/dist/server/agent-chat/browser-team-tools.d.ts +21 -0
  799. package/dist/server/agent-chat/browser-team-tools.d.ts.map +1 -0
  800. package/dist/server/agent-chat/browser-team-tools.js +417 -0
  801. package/dist/server/agent-chat/browser-team-tools.js.map +1 -0
  802. package/dist/server/agent-chat/context-tools.d.ts +33 -0
  803. package/dist/server/agent-chat/context-tools.d.ts.map +1 -0
  804. package/dist/server/agent-chat/context-tools.js +520 -0
  805. package/dist/server/agent-chat/context-tools.js.map +1 -0
  806. package/dist/server/agent-chat/framework-prompts.d.ts +65 -0
  807. package/dist/server/agent-chat/framework-prompts.d.ts.map +1 -0
  808. package/dist/server/agent-chat/framework-prompts.js +403 -0
  809. package/dist/server/agent-chat/framework-prompts.js.map +1 -0
  810. package/dist/server/agent-chat/lazy-fs.d.ts +2 -0
  811. package/dist/server/agent-chat/lazy-fs.d.ts.map +1 -0
  812. package/dist/server/agent-chat/lazy-fs.js +11 -0
  813. package/dist/server/agent-chat/lazy-fs.js.map +1 -0
  814. package/dist/server/agent-chat/mcp-glue.d.ts +9 -0
  815. package/dist/server/agent-chat/mcp-glue.d.ts.map +1 -0
  816. package/dist/server/agent-chat/mcp-glue.js +63 -0
  817. package/dist/server/agent-chat/mcp-glue.js.map +1 -0
  818. package/dist/server/agent-chat/plugin-options.d.ts +322 -0
  819. package/dist/server/agent-chat/plugin-options.d.ts.map +1 -0
  820. package/dist/server/agent-chat/plugin-options.js +2 -0
  821. package/dist/server/agent-chat/plugin-options.js.map +1 -0
  822. package/dist/server/agent-chat/process-run-failure.d.ts +12 -0
  823. package/dist/server/agent-chat/process-run-failure.d.ts.map +1 -0
  824. package/dist/server/agent-chat/process-run-failure.js +24 -0
  825. package/dist/server/agent-chat/process-run-failure.js.map +1 -0
  826. package/dist/server/agent-chat/prompt-resources.d.ts +28 -0
  827. package/dist/server/agent-chat/prompt-resources.d.ts.map +1 -0
  828. package/dist/server/agent-chat/prompt-resources.js +514 -0
  829. package/dist/server/agent-chat/prompt-resources.js.map +1 -0
  830. package/dist/server/agent-chat/recurring-jobs-runtime.d.ts +5 -0
  831. package/dist/server/agent-chat/recurring-jobs-runtime.d.ts.map +1 -0
  832. package/dist/server/agent-chat/recurring-jobs-runtime.js +53 -0
  833. package/dist/server/agent-chat/recurring-jobs-runtime.js.map +1 -0
  834. package/dist/server/agent-chat/request-surface.d.ts +8 -0
  835. package/dist/server/agent-chat/request-surface.d.ts.map +1 -0
  836. package/dist/server/agent-chat/request-surface.js +56 -0
  837. package/dist/server/agent-chat/request-surface.js.map +1 -0
  838. package/dist/server/agent-chat/run-code-tools.d.ts +17 -0
  839. package/dist/server/agent-chat/run-code-tools.d.ts.map +1 -0
  840. package/dist/server/agent-chat/run-code-tools.js +55 -0
  841. package/dist/server/agent-chat/run-code-tools.js.map +1 -0
  842. package/dist/server/agent-chat/script-entries.d.ts +47 -0
  843. package/dist/server/agent-chat/script-entries.d.ts.map +1 -0
  844. package/dist/server/agent-chat/script-entries.js +633 -0
  845. package/dist/server/agent-chat/script-entries.js.map +1 -0
  846. package/dist/server/agent-chat/shared-thread.d.ts +33 -0
  847. package/dist/server/agent-chat/shared-thread.d.ts.map +1 -0
  848. package/dist/server/agent-chat/shared-thread.js +242 -0
  849. package/dist/server/agent-chat/shared-thread.js.map +1 -0
  850. package/dist/server/agent-chat/skill-frontmatter.d.ts +7 -0
  851. package/dist/server/agent-chat/skill-frontmatter.d.ts.map +1 -0
  852. package/dist/server/agent-chat/skill-frontmatter.js +26 -0
  853. package/dist/server/agent-chat/skill-frontmatter.js.map +1 -0
  854. package/dist/server/agent-chat-plugin.d.ts +45 -486
  855. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  856. package/dist/server/agent-chat-plugin.js +173 -3005
  857. package/dist/server/agent-chat-plugin.js.map +1 -1
  858. package/dist/server/agent-teams.d.ts +10 -0
  859. package/dist/server/agent-teams.d.ts.map +1 -1
  860. package/dist/server/agent-teams.js +13 -3
  861. package/dist/server/agent-teams.js.map +1 -1
  862. package/dist/server/auth.d.ts.map +1 -1
  863. package/dist/server/auth.js +50 -52
  864. package/dist/server/auth.js.map +1 -1
  865. package/dist/server/credential-provider.d.ts.map +1 -1
  866. package/dist/server/credential-provider.js +22 -21
  867. package/dist/server/credential-provider.js.map +1 -1
  868. package/dist/server/edge.d.ts +1 -0
  869. package/dist/server/edge.d.ts.map +1 -1
  870. package/dist/server/edge.js +1 -0
  871. package/dist/server/edge.js.map +1 -1
  872. package/dist/server/onboarding-html.d.ts.map +1 -1
  873. package/dist/server/onboarding-html.js +1 -16
  874. package/dist/server/onboarding-html.js.map +1 -1
  875. package/dist/server/poll.d.ts.map +1 -1
  876. package/dist/server/poll.js +1 -0
  877. package/dist/server/poll.js.map +1 -1
  878. package/dist/server/realtime-voice.d.ts +10 -0
  879. package/dist/server/realtime-voice.d.ts.map +1 -1
  880. package/dist/server/realtime-voice.js +249 -15
  881. package/dist/server/realtime-voice.js.map +1 -1
  882. package/dist/server/request-origin.d.ts.map +1 -1
  883. package/dist/server/request-origin.js +6 -3
  884. package/dist/server/request-origin.js.map +1 -1
  885. package/dist/server/ssr-handler.d.ts.map +1 -1
  886. package/dist/server/ssr-handler.js +47 -2
  887. package/dist/server/ssr-handler.js.map +1 -1
  888. package/dist/sharing/access.d.ts +63 -3
  889. package/dist/sharing/access.d.ts.map +1 -1
  890. package/dist/sharing/access.js +53 -15
  891. package/dist/sharing/access.js.map +1 -1
  892. package/dist/sharing/registry.d.ts +7 -0
  893. package/dist/sharing/registry.d.ts.map +1 -1
  894. package/dist/sharing/registry.js.map +1 -1
  895. package/dist/styles/agent-native.css +17 -16
  896. package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +1 -1
  897. package/dist/templates/default/.agents/skills/real-time-sync/SKILL.md +2 -2
  898. package/dist/templates/default/app/i18n/ar-SA.ts +6 -0
  899. package/dist/templates/default/app/i18n/de-DE.ts +6 -0
  900. package/dist/templates/default/app/i18n/en-US.ts +6 -0
  901. package/dist/templates/default/app/i18n/es-ES.ts +6 -0
  902. package/dist/templates/default/app/i18n/fr-FR.ts +6 -0
  903. package/dist/templates/default/app/i18n/hi-IN.ts +6 -0
  904. package/dist/templates/default/app/i18n/ja-JP.ts +6 -0
  905. package/dist/templates/default/app/i18n/ko-KR.ts +6 -0
  906. package/dist/templates/default/app/i18n/pt-BR.ts +6 -0
  907. package/dist/templates/default/app/i18n/zh-CN.ts +6 -0
  908. package/dist/templates/default/app/i18n/zh-TW.ts +6 -0
  909. package/dist/templates/workspace-core/.agents/skills/authentication/SKILL.md +27 -29
  910. package/dist/templates/workspace-core/.agents/skills/external-agents/SKILL.md +2 -1
  911. package/dist/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +1 -1
  912. package/dist/templates/workspace-core/.agents/skills/observability/SKILL.md +32 -0
  913. package/dist/templates/workspace-core/.agents/skills/real-time-sync/SKILL.md +2 -2
  914. package/dist/templates/workspace-core/.agents/skills/secrets/SKILL.md +7 -3
  915. package/dist/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -9
  916. package/dist/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +25 -0
  917. package/dist/templates/workspace-core/src/server/index.ts +4 -2
  918. package/dist/testing.d.ts +16 -0
  919. package/dist/testing.d.ts.map +1 -0
  920. package/dist/testing.js +16 -0
  921. package/dist/testing.js.map +1 -0
  922. package/dist/triggers/dispatcher.d.ts +7 -0
  923. package/dist/triggers/dispatcher.d.ts.map +1 -1
  924. package/dist/triggers/dispatcher.js +13 -3
  925. package/dist/triggers/dispatcher.js.map +1 -1
  926. package/dist/vite/client.d.ts +16 -1
  927. package/dist/vite/client.d.ts.map +1 -1
  928. package/dist/vite/client.js +111 -3
  929. package/dist/vite/client.js.map +1 -1
  930. package/docs/content/authentication.mdx +3 -3
  931. package/docs/content/doctor.mdx +170 -0
  932. package/docs/content/external-agents.mdx +8 -7
  933. package/docs/content/locales/ar-SA/authentication.mdx +2 -2
  934. package/docs/content/locales/ar-SA/external-agents.mdx +8 -7
  935. package/docs/content/locales/ar-SA/mcp-protocol.mdx +1 -1
  936. package/docs/content/locales/ar-SA/security.mdx +2 -0
  937. package/docs/content/locales/de-DE/authentication.mdx +1 -1
  938. package/docs/content/locales/de-DE/external-agents.mdx +8 -7
  939. package/docs/content/locales/de-DE/mcp-protocol.mdx +1 -1
  940. package/docs/content/locales/de-DE/security.mdx +2 -0
  941. package/docs/content/locales/es-ES/authentication.mdx +2 -2
  942. package/docs/content/locales/es-ES/external-agents.mdx +8 -7
  943. package/docs/content/locales/es-ES/mcp-protocol.mdx +1 -1
  944. package/docs/content/locales/es-ES/security.mdx +2 -0
  945. package/docs/content/locales/fr-FR/authentication.mdx +1 -1
  946. package/docs/content/locales/fr-FR/external-agents.mdx +8 -7
  947. package/docs/content/locales/fr-FR/mcp-protocol.mdx +1 -1
  948. package/docs/content/locales/fr-FR/security.mdx +2 -0
  949. package/docs/content/locales/hi-IN/authentication.mdx +2 -2
  950. package/docs/content/locales/hi-IN/external-agents.mdx +8 -7
  951. package/docs/content/locales/hi-IN/mcp-protocol.mdx +1 -1
  952. package/docs/content/locales/hi-IN/security.mdx +2 -0
  953. package/docs/content/locales/ja-JP/authentication.mdx +2 -2
  954. package/docs/content/locales/ja-JP/external-agents.mdx +8 -7
  955. package/docs/content/locales/ja-JP/mcp-protocol.mdx +1 -1
  956. package/docs/content/locales/ja-JP/security.mdx +2 -0
  957. package/docs/content/locales/ko-KR/authentication.mdx +2 -2
  958. package/docs/content/locales/ko-KR/external-agents.mdx +8 -7
  959. package/docs/content/locales/ko-KR/mcp-protocol.mdx +1 -1
  960. package/docs/content/locales/ko-KR/security.mdx +2 -0
  961. package/docs/content/locales/pt-BR/authentication.mdx +2 -2
  962. package/docs/content/locales/pt-BR/external-agents.mdx +8 -7
  963. package/docs/content/locales/pt-BR/mcp-protocol.mdx +1 -1
  964. package/docs/content/locales/pt-BR/security.mdx +2 -0
  965. package/docs/content/locales/zh-CN/authentication.mdx +2 -2
  966. package/docs/content/locales/zh-CN/external-agents.mdx +8 -7
  967. package/docs/content/locales/zh-CN/mcp-protocol.mdx +1 -1
  968. package/docs/content/locales/zh-CN/security.mdx +2 -0
  969. package/docs/content/locales/zh-TW/authentication.mdx +2 -2
  970. package/docs/content/locales/zh-TW/external-agents.mdx +8 -7
  971. package/docs/content/locales/zh-TW/mcp-protocol.mdx +1 -1
  972. package/docs/content/locales/zh-TW/security.mdx +2 -0
  973. package/docs/content/mcp-protocol.mdx +1 -1
  974. package/docs/content/security.mdx +2 -0
  975. package/package.json +7 -3
  976. package/src/templates/default/.agents/skills/frontend-design/SKILL.md +1 -1
  977. package/src/templates/default/.agents/skills/real-time-sync/SKILL.md +2 -2
  978. package/src/templates/default/app/i18n/ar-SA.ts +6 -0
  979. package/src/templates/default/app/i18n/de-DE.ts +6 -0
  980. package/src/templates/default/app/i18n/en-US.ts +6 -0
  981. package/src/templates/default/app/i18n/es-ES.ts +6 -0
  982. package/src/templates/default/app/i18n/fr-FR.ts +6 -0
  983. package/src/templates/default/app/i18n/hi-IN.ts +6 -0
  984. package/src/templates/default/app/i18n/ja-JP.ts +6 -0
  985. package/src/templates/default/app/i18n/ko-KR.ts +6 -0
  986. package/src/templates/default/app/i18n/pt-BR.ts +6 -0
  987. package/src/templates/default/app/i18n/zh-CN.ts +6 -0
  988. package/src/templates/default/app/i18n/zh-TW.ts +6 -0
  989. package/src/templates/workspace-core/.agents/skills/authentication/SKILL.md +27 -29
  990. package/src/templates/workspace-core/.agents/skills/external-agents/SKILL.md +2 -1
  991. package/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +1 -1
  992. package/src/templates/workspace-core/.agents/skills/observability/SKILL.md +32 -0
  993. package/src/templates/workspace-core/.agents/skills/real-time-sync/SKILL.md +2 -2
  994. package/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +7 -3
  995. package/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -9
  996. package/src/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +25 -0
  997. package/src/templates/workspace-core/src/server/index.ts +4 -2
  998. package/corpus/core/src/client/ProductionAgentPanel.tsx +0 -9
  999. package/corpus/core/src/client/auth-redirect-url.ts +0 -23
  1000. package/corpus/core/src/client/useProductionAgent.ts +0 -253
  1001. package/corpus/core/src/shared/auth-redirect-url.ts +0 -1
  1002. package/corpus/templates/analytics/app/pages/Index.tsx +0 -16
  1003. package/corpus/templates/analytics/seeds/dashboards/agent-observability-llm.json +0 -173
  1004. package/dist/client/ProductionAgentPanel.d.ts +0 -6
  1005. package/dist/client/ProductionAgentPanel.d.ts.map +0 -1
  1006. package/dist/client/ProductionAgentPanel.js +0 -6
  1007. package/dist/client/ProductionAgentPanel.js.map +0 -1
  1008. package/dist/client/auth-redirect-url.d.ts +0 -2
  1009. package/dist/client/auth-redirect-url.d.ts.map +0 -1
  1010. package/dist/client/auth-redirect-url.js +0 -19
  1011. package/dist/client/auth-redirect-url.js.map +0 -1
  1012. package/dist/client/useProductionAgent.d.ts +0 -24
  1013. package/dist/client/useProductionAgent.d.ts.map +0 -1
  1014. package/dist/client/useProductionAgent.js +0 -179
  1015. package/dist/client/useProductionAgent.js.map +0 -1
  1016. package/dist/shared/auth-redirect-url.d.ts +0 -2
  1017. package/dist/shared/auth-redirect-url.d.ts.map +0 -1
  1018. package/dist/shared/auth-redirect-url.js +0 -2
  1019. package/dist/shared/auth-redirect-url.js.map +0 -1
@@ -2,6 +2,8 @@ import { defineEventHandler, getHeader, getMethod, readRawBody, setResponseHeade
2
2
  import { getBuilderGatewayRequestHeaders } from "../agent/engine/builder-gateway-headers.js";
3
3
  import { actionsToEngineTools, } from "../agent/production-agent.js";
4
4
  import { redactSensitiveFields, sanitizeToolErrorText, sanitizeToolErrorValue, } from "../agent/tool-error-redaction.js";
5
+ import { TOOL_SEARCH_ACTION_NAME } from "../agent/tool-search.js";
6
+ import { parseAcceptLanguage } from "../localization/server.js";
5
7
  import { getSession } from "./auth.js";
6
8
  import { getBuilderGatewayBaseUrl, resolveBuilderCredentials, resolveSecret, } from "./credential-provider.js";
7
9
  import { getH3App } from "./framework-request-handler.js";
@@ -12,18 +14,53 @@ export const REALTIME_VOICE_TOOL_PATH = "/_agent-native/realtime-voice/tool";
12
14
  export const REALTIME_VOICE_MAX_SDP_BYTES = 64 * 1024;
13
15
  export const REALTIME_VOICE_MAX_TOOL_BODY_BYTES = 64 * 1024;
14
16
  export const REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS = 16_000;
17
+ export const REALTIME_VOICE_MAX_TOOLS = 32;
18
+ export const REALTIME_VOICE_MAX_TOOL_SCHEMA_BYTES = 32_000;
19
+ export const REALTIME_VOICE_MAX_SESSION_BYTES = 64_000;
20
+ export const REALTIME_VOICE_TOOL_GRANT_TTL_MS = 10 * 60 * 1_000;
21
+ export const REALTIME_VOICE_MAX_TOOL_GRANT_SESSIONS = 256;
22
+ export const REALTIME_VOICE_CAPABILITY_HEADER = "X-Agent-Native-Realtime-Capability";
15
23
  const OPENAI_REALTIME_CALLS_URL = "https://api.openai.com/v1/realtime/calls";
16
24
  const DEFAULT_MODEL = "gpt-realtime-2.1";
17
25
  const DEFAULT_VOICE = "marin";
18
26
  const DEFAULT_INSTRUCTIONS = "You are the live voice interface for this Agent Native app. Speak naturally, briefly, and conversationally. Use the available function tools when the user asks you to navigate or take an action. Never claim an action succeeded until its tool result confirms success. If a tool requires approval, explain that the user must approve it in chat.";
19
27
  const MAX_INSTRUCTIONS_CHARS = 16_000;
20
28
  const MAX_TOOL_DESCRIPTION_CHARS = 2_000;
21
- const MAX_TOOL_SCHEMA_CHARS = 64 * 1024;
22
29
  const MAX_APPROVAL_KEY_CHARS = 1_024;
23
30
  const REALTIME_TOOL_NAME = /^[A-Za-z0-9_-]{1,64}$/;
24
31
  const CALL_ID = /^[A-Za-z0-9_-]{1,256}$/;
25
32
  const SESSION_ID = /^[A-Za-z0-9_.:-]{1,256}$/;
26
33
  const BROWSER_TAB_ID = /^[A-Za-z0-9_-]{1,96}$/;
34
+ const ISO_639_1_LANGUAGE = /^[A-Za-z]{2}$/;
35
+ const REALTIME_VOICE_BUILT_INS = new Set([
36
+ "alloy",
37
+ "ash",
38
+ "ballad",
39
+ "coral",
40
+ "echo",
41
+ "sage",
42
+ "shimmer",
43
+ "verse",
44
+ "marin",
45
+ "cedar",
46
+ ]);
47
+ const REALTIME_VOICE_REASONING_EFFORT = {
48
+ instant: "minimal",
49
+ balanced: "low",
50
+ deep: "medium",
51
+ };
52
+ /**
53
+ * Realtime sessions have a deliberately bounded tool manifest. Keep the
54
+ * context/navigation tools ahead of large template registries so voice can
55
+ * always see and operate the same UI navigation surface as text chat.
56
+ */
57
+ const REALTIME_VOICE_PRIORITY_TOOLS = [
58
+ "navigate",
59
+ "set-url-path",
60
+ "set-search-params",
61
+ "view-screen",
62
+ TOOL_SEARCH_ACTION_NAME,
63
+ ];
27
64
  function readSafeHeader(event, name) {
28
65
  const value = getHeader(event, name);
29
66
  if (typeof value !== "string")
@@ -37,6 +74,34 @@ function configuredIdentifier(value, fallback) {
37
74
  ? trimmed
38
75
  : fallback;
39
76
  }
77
+ export function resolveRealtimeVoiceTranscriptionLanguage(acceptLanguage) {
78
+ for (const locale of parseAcceptLanguage(acceptLanguage)) {
79
+ const primaryLanguage = locale.split("-")[0];
80
+ if (ISO_639_1_LANGUAGE.test(primaryLanguage)) {
81
+ return primaryLanguage.toLowerCase();
82
+ }
83
+ }
84
+ return "en";
85
+ }
86
+ export function resolveRealtimeVoiceLanguagePreference(value, acceptLanguage) {
87
+ const normalized = value?.trim().toLowerCase();
88
+ return normalized && ISO_639_1_LANGUAGE.test(normalized)
89
+ ? normalized
90
+ : resolveRealtimeVoiceTranscriptionLanguage(acceptLanguage);
91
+ }
92
+ export function resolveRealtimeVoiceReasoningEffort(value) {
93
+ const normalized = value?.trim().toLowerCase();
94
+ return normalized &&
95
+ Object.hasOwn(REALTIME_VOICE_REASONING_EFFORT, normalized)
96
+ ? REALTIME_VOICE_REASONING_EFFORT[normalized]
97
+ : "low";
98
+ }
99
+ export function resolveRealtimeVoicePreference(value, fallback) {
100
+ const normalized = value?.trim().toLowerCase();
101
+ return normalized && REALTIME_VOICE_BUILT_INS.has(normalized)
102
+ ? normalized
103
+ : fallback;
104
+ }
40
105
  function truncate(value, maxChars) {
41
106
  if (value.length <= maxChars)
42
107
  return value;
@@ -79,8 +144,11 @@ async function safeOpenAiErrorDetail(response, apiKey) {
79
144
  function normalizeToolSchema(inputSchema) {
80
145
  try {
81
146
  const serialized = JSON.stringify(inputSchema);
82
- if (!serialized || serialized.length > MAX_TOOL_SCHEMA_CHARS)
147
+ if (!serialized ||
148
+ Buffer.byteLength(serialized, "utf8") >
149
+ REALTIME_VOICE_MAX_TOOL_SCHEMA_BYTES) {
83
150
  return null;
151
+ }
84
152
  const parsed = JSON.parse(serialized);
85
153
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
86
154
  return null;
@@ -106,7 +174,136 @@ function buildRealtimeTools(actions) {
106
174
  parameters,
107
175
  });
108
176
  }
109
- return tools;
177
+ const priority = new Map(REALTIME_VOICE_PRIORITY_TOOLS.map((name, index) => [name, index]));
178
+ return tools
179
+ .map((tool, index) => ({ tool, index }))
180
+ .sort((left, right) => {
181
+ const leftPriority = priority.get(left.tool.name);
182
+ const rightPriority = priority.get(right.tool.name);
183
+ if (leftPriority !== undefined || rightPriority !== undefined) {
184
+ if (leftPriority === undefined)
185
+ return 1;
186
+ if (rightPriority === undefined)
187
+ return -1;
188
+ return leftPriority - rightPriority;
189
+ }
190
+ return left.index - right.index;
191
+ })
192
+ .map(({ tool }) => tool);
193
+ }
194
+ function packRealtimeTools(session, eligibleTools) {
195
+ const packed = [];
196
+ for (const tool of eligibleTools.slice(0, REALTIME_VOICE_MAX_TOOLS)) {
197
+ const candidate = [...packed, tool];
198
+ const candidateSession = {
199
+ ...session,
200
+ tools: candidate,
201
+ tool_choice: "auto",
202
+ };
203
+ if (Buffer.byteLength(JSON.stringify(candidateSession), "utf8") <=
204
+ REALTIME_VOICE_MAX_SESSION_BYTES) {
205
+ packed.push(tool);
206
+ }
207
+ }
208
+ return packed;
209
+ }
210
+ function mintRealtimeToolCapability() {
211
+ return globalThis.crypto.randomUUID().replaceAll("-", "");
212
+ }
213
+ function cleanRealtimeToolCapabilities(capabilities, now = Date.now()) {
214
+ for (const [key, capability] of capabilities) {
215
+ if (capability.expiresAt <= now)
216
+ capabilities.delete(key);
217
+ }
218
+ while (capabilities.size > REALTIME_VOICE_MAX_TOOL_GRANT_SESSIONS) {
219
+ let oldestKey;
220
+ let oldestExpiry = Number.POSITIVE_INFINITY;
221
+ for (const [key, capability] of capabilities) {
222
+ if (capability.expiresAt < oldestExpiry) {
223
+ oldestKey = key;
224
+ oldestExpiry = capability.expiresAt;
225
+ }
226
+ }
227
+ if (!oldestKey)
228
+ break;
229
+ capabilities.delete(oldestKey);
230
+ }
231
+ }
232
+ function registerRealtimeToolCapability(capabilities, auth, initialNames) {
233
+ cleanRealtimeToolCapabilities(capabilities);
234
+ const token = mintRealtimeToolCapability();
235
+ capabilities.set(token, {
236
+ userEmail: auth.userEmail.trim().toLowerCase(),
237
+ ...(auth.orgId ? { orgId: auth.orgId } : {}),
238
+ ...(auth.browserTabId ? { browserTabId: auth.browserTabId } : {}),
239
+ expiresAt: Date.now() + REALTIME_VOICE_TOOL_GRANT_TTL_MS,
240
+ initialNames: new Set(initialNames),
241
+ names: new Set(),
242
+ });
243
+ cleanRealtimeToolCapabilities(capabilities);
244
+ return token;
245
+ }
246
+ function resolveRealtimeToolCapability(capabilities, token, auth) {
247
+ cleanRealtimeToolCapabilities(capabilities);
248
+ if (!token)
249
+ return null;
250
+ const capability = capabilities.get(token);
251
+ if (!capability)
252
+ return null;
253
+ if (capability.userEmail !== auth.userEmail.trim().toLowerCase() ||
254
+ capability.orgId !== auth.orgId ||
255
+ capability.browserTabId !== auth.browserTabId) {
256
+ return null;
257
+ }
258
+ capability.expiresAt = Date.now() + REALTIME_VOICE_TOOL_GRANT_TTL_MS;
259
+ return capability;
260
+ }
261
+ function parseSuccessfulToolSearchNames(output) {
262
+ try {
263
+ const parsed = JSON.parse(output);
264
+ if (!Array.isArray(parsed.results))
265
+ return [];
266
+ const names = [];
267
+ for (const result of parsed.results) {
268
+ if (!isRecord(result) || typeof result.name !== "string")
269
+ continue;
270
+ if (!REALTIME_TOOL_NAME.test(result.name))
271
+ continue;
272
+ if (!names.includes(result.name))
273
+ names.push(result.name);
274
+ if (names.length >= REALTIME_VOICE_MAX_TOOLS)
275
+ break;
276
+ }
277
+ return names;
278
+ }
279
+ catch {
280
+ return [];
281
+ }
282
+ }
283
+ function grantDiscoveredRealtimeTools(input) {
284
+ const query = input.request.args.query;
285
+ if (input.request.name !== TOOL_SEARCH_ACTION_NAME ||
286
+ input.result.status !== "completed" ||
287
+ typeof query !== "string" ||
288
+ !query.trim()) {
289
+ return [];
290
+ }
291
+ const candidates = parseSuccessfulToolSearchNames(input.result.output)
292
+ .filter((name) => !input.initialAllowedNames.has(name))
293
+ .map((name) => input.toolsByName.get(name))
294
+ .filter((tool) => Boolean(tool));
295
+ const boundedTools = packRealtimeTools({}, candidates);
296
+ const expandedTools = [];
297
+ for (const tool of boundedTools) {
298
+ if (!input.capability.names.has(tool.name) &&
299
+ input.capability.names.size >= REALTIME_VOICE_MAX_TOOLS) {
300
+ continue;
301
+ }
302
+ input.capability.names.add(tool.name);
303
+ expandedTools.push(tool);
304
+ }
305
+ input.capability.expiresAt = Date.now() + REALTIME_VOICE_TOOL_GRANT_TTL_MS;
306
+ return expandedTools;
110
307
  }
111
308
  function declaredBodyBytes(event) {
112
309
  const raw = readSafeHeader(event, "content-length");
@@ -167,7 +364,7 @@ function invalidMethod(event) {
167
364
  setResponseStatus(event, 405);
168
365
  return { error: "Method not allowed" };
169
366
  }
170
- function createSessionHandler(tools, options) {
367
+ function createSessionHandler(tools, capabilities, options) {
171
368
  return defineEventHandler(async (event) => {
172
369
  if (getMethod(event) !== "POST")
173
370
  return invalidMethod(event);
@@ -220,14 +417,22 @@ function createSessionHandler(tools, options) {
220
417
  };
221
418
  }
222
419
  const instructions = await buildInstructions(auth, options);
223
- const session = {
420
+ const transcriptionLanguage = resolveRealtimeVoiceLanguagePreference(readSafeHeader(event, "x-agent-native-realtime-language"), readSafeHeader(event, "accept-language"));
421
+ const reasoningEffort = resolveRealtimeVoiceReasoningEffort(readSafeHeader(event, "x-agent-native-realtime-intelligence"));
422
+ const voice = resolveRealtimeVoicePreference(readSafeHeader(event, "x-agent-native-realtime-voice"), configuredIdentifier(options.voice, DEFAULT_VOICE));
423
+ const sessionBase = {
224
424
  type: "realtime",
225
425
  model: configuredIdentifier(options.model, DEFAULT_MODEL),
226
426
  instructions,
427
+ parallel_tool_calls: false,
428
+ reasoning: { effort: reasoningEffort },
227
429
  output_modalities: ["audio"],
228
430
  audio: {
229
431
  input: {
230
- transcription: { model: "gpt-4o-mini-transcribe" },
432
+ transcription: {
433
+ model: "gpt-4o-mini-transcribe",
434
+ language: transcriptionLanguage,
435
+ },
231
436
  turn_detection: {
232
437
  type: "semantic_vad",
233
438
  create_response: true,
@@ -236,10 +441,14 @@ function createSessionHandler(tools, options) {
236
441
  },
237
442
  },
238
443
  output: {
239
- voice: configuredIdentifier(options.voice, DEFAULT_VOICE),
444
+ voice,
240
445
  },
241
446
  },
242
- tools,
447
+ };
448
+ const packedTools = packRealtimeTools(sessionBase, tools);
449
+ const session = {
450
+ ...sessionBase,
451
+ tools: packedTools,
243
452
  tool_choice: "auto",
244
453
  };
245
454
  let upstream;
@@ -301,6 +510,7 @@ function createSessionHandler(tools, options) {
301
510
  }
302
511
  setResponseStatus(event, upstream.status);
303
512
  setResponseHeader(event, "Content-Type", "application/sdp");
513
+ setResponseHeader(event, REALTIME_VOICE_CAPABILITY_HEADER, registerRealtimeToolCapability(capabilities, auth, packedTools.map((tool) => tool.name)));
304
514
  return answerSdp;
305
515
  });
306
516
  });
@@ -353,7 +563,7 @@ function normalizeExecutionResult(result) {
353
563
  : {}),
354
564
  };
355
565
  }
356
- function createToolHandler(allowedToolNames, options) {
566
+ function createToolHandler(toolsByName, capabilities, options) {
357
567
  return defineEventHandler(async (event) => {
358
568
  if (getMethod(event) !== "POST")
359
569
  return invalidMethod(event);
@@ -367,6 +577,11 @@ function createToolHandler(allowedToolNames, options) {
367
577
  setResponseStatus(event, 401);
368
578
  return { error: "Authentication required" };
369
579
  }
580
+ const capability = resolveRealtimeToolCapability(capabilities, readSafeHeader(event, REALTIME_VOICE_CAPABILITY_HEADER), auth);
581
+ if (!capability) {
582
+ setResponseStatus(event, 403);
583
+ return { error: "Invalid or expired realtime voice capability" };
584
+ }
370
585
  const contentType = readSafeHeader(event, "content-type")?.toLowerCase();
371
586
  if (!contentType?.includes("application/json")) {
372
587
  setResponseStatus(event, 415);
@@ -392,11 +607,17 @@ function createToolHandler(allowedToolNames, options) {
392
607
  setResponseStatus(event, 400);
393
608
  return { error: "Invalid realtime tool request" };
394
609
  }
395
- if (!allowedToolNames.has(request.name)) {
610
+ if (request.browserTabId !== undefined &&
611
+ request.browserTabId !== capability.browserTabId) {
612
+ setResponseStatus(event, 403);
613
+ return { error: "Realtime voice browser tab mismatch" };
614
+ }
615
+ if (!capability.initialNames.has(request.name) &&
616
+ !capability.names.has(request.name)) {
396
617
  setResponseStatus(event, 404);
397
618
  return { error: "Unknown realtime voice tool" };
398
619
  }
399
- const browserTabId = request.browserTabId ?? auth.browserTabId;
620
+ const browserTabId = capability.browserTabId;
400
621
  const threadId = request.sessionId
401
622
  ? `realtime:${request.sessionId}`
402
623
  : `realtime:${request.callId}`;
@@ -415,8 +636,20 @@ function createToolHandler(allowedToolNames, options) {
415
636
  userEmail: auth.userEmail,
416
637
  orgId: auth.orgId,
417
638
  ...request,
639
+ ...(browserTabId ? { browserTabId } : {}),
418
640
  }));
419
- return { callId: request.callId, ...result };
641
+ const expandedTools = grantDiscoveredRealtimeTools({
642
+ request,
643
+ result,
644
+ toolsByName,
645
+ initialAllowedNames: capability.initialNames,
646
+ capability,
647
+ });
648
+ return {
649
+ callId: request.callId,
650
+ ...result,
651
+ ...(expandedTools.length > 0 ? { expandedTools } : {}),
652
+ };
420
653
  }
421
654
  catch (error) {
422
655
  setResponseStatus(event, 500);
@@ -435,10 +668,11 @@ export function mountRealtimeVoiceRoutes(nitroApp, actions, options) {
435
668
  throw new Error("mountRealtimeVoiceRoutes requires executeTool");
436
669
  }
437
670
  const tools = buildRealtimeTools(actions);
438
- const allowedToolNames = new Set(tools.map((tool) => tool.name));
671
+ const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
672
+ const capabilities = new Map();
439
673
  const app = getH3App(nitroApp);
440
- app.use(REALTIME_VOICE_SESSION_PATH, createSessionHandler(tools, options));
441
- app.use(REALTIME_VOICE_TOOL_PATH, createToolHandler(allowedToolNames, options));
674
+ app.use(REALTIME_VOICE_SESSION_PATH, createSessionHandler(tools, capabilities, options));
675
+ app.use(REALTIME_VOICE_TOOL_PATH, createToolHandler(toolsByName, capabilities, options));
442
676
  return {
443
677
  sessionPath: REALTIME_VOICE_SESSION_PATH,
444
678
  toolPath: REALTIME_VOICE_TOOL_PATH,
@@ -1 +1 @@
1
- {"version":3,"file":"realtime-voice.js","sourceRoot":"","sources":["../../src/server/realtime-voice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,EACL,oBAAoB,GAErB,MAAM,8BAA8B,CAAC;A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;IAC/B,GAAG,CAAC,GAAG,CAAC,2BAA2B,EAAE,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,GAAG,CAAC,GAAG,CACL,wBAAwB,EACxB,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAC7C,CAAC;IACF,OAAO;QACL,WAAW,EAAE,2BAA2B;QACxC,QAAQ,EAAE,wBAAwB;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import {\n defineEventHandler,\n getHeader,\n getMethod,\n readRawBody,\n setResponseHeader,\n setResponseStatus,\n type H3Event,\n} from \"h3\";\n\nimport { getBuilderGatewayRequestHeaders } from \"../agent/engine/builder-gateway-headers.js\";\nimport {\n actionsToEngineTools,\n type ActionEntry,\n} from \"../agent/production-agent.js\";\nimport {\n redactSensitiveFields,\n sanitizeToolErrorText,\n sanitizeToolErrorValue,\n} from \"../agent/tool-error-redaction.js\";\nimport { getSession } from \"./auth.js\";\nimport {\n getBuilderGatewayBaseUrl,\n resolveBuilderCredentials,\n resolveSecret,\n} from \"./credential-provider.js\";\nimport { getH3App } from \"./framework-request-handler.js\";\nimport { runWithRequestContext } from \"./request-context.js\";\nimport { isSameOriginRequest } from \"./request-origin.js\";\n\nexport const REALTIME_VOICE_SESSION_PATH =\n \"/_agent-native/realtime-voice/session\";\nexport const REALTIME_VOICE_TOOL_PATH = \"/_agent-native/realtime-voice/tool\";\nexport const REALTIME_VOICE_MAX_SDP_BYTES = 64 * 1024;\nexport const REALTIME_VOICE_MAX_TOOL_BODY_BYTES = 64 * 1024;\nexport const REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS = 16_000;\n\nconst OPENAI_REALTIME_CALLS_URL = \"https://api.openai.com/v1/realtime/calls\";\nconst DEFAULT_MODEL = \"gpt-realtime-2.1\";\nconst DEFAULT_VOICE = \"marin\";\nconst DEFAULT_INSTRUCTIONS =\n \"You are the live voice interface for this Agent Native app. Speak naturally, briefly, and conversationally. Use the available function tools when the user asks you to navigate or take an action. Never claim an action succeeded until its tool result confirms success. If a tool requires approval, explain that the user must approve it in chat.\";\nconst MAX_INSTRUCTIONS_CHARS = 16_000;\nconst MAX_TOOL_DESCRIPTION_CHARS = 2_000;\nconst MAX_TOOL_SCHEMA_CHARS = 64 * 1024;\nconst MAX_APPROVAL_KEY_CHARS = 1_024;\nconst REALTIME_TOOL_NAME = /^[A-Za-z0-9_-]{1,64}$/;\nconst CALL_ID = /^[A-Za-z0-9_-]{1,256}$/;\nconst SESSION_ID = /^[A-Za-z0-9_.:-]{1,256}$/;\nconst BROWSER_TAB_ID = /^[A-Za-z0-9_-]{1,96}$/;\n\nexport interface RealtimeVoiceRequestContext {\n event: H3Event;\n userEmail: string;\n orgId?: string;\n browserTabId?: string;\n}\n\nexport interface RealtimeVoiceToolExecutionRequest extends RealtimeVoiceRequestContext {\n name: string;\n args: Record<string, unknown>;\n callId: string;\n sessionId?: string;\n}\n\nexport interface RealtimeVoiceToolExecutionResult {\n status: \"completed\" | \"failed\" | \"approval_required\";\n output: string;\n approvalKey?: string;\n}\n\nexport interface MountRealtimeVoiceRoutesOptions {\n /** Server-controlled model. Defaults to gpt-realtime-2.1. */\n model?: string;\n /** Server-controlled output voice. Defaults to marin. */\n voice?: string;\n /** Static app guidance appended to the safe default voice instructions. */\n instructions?: string;\n /** Per-request app/navigation guidance. It is sent only to OpenAI. */\n getInstructions?: (\n context: RealtimeVoiceRequestContext,\n ) => string | null | undefined | Promise<string | null | undefined>;\n /** Optional app-specific active-organization resolver. */\n resolveOrgId?: (\n event: H3Event,\n ) => string | null | undefined | Promise<string | null | undefined>;\n /**\n * Central agent tool executor supplied by the agent-chat plugin. The executor\n * owns validation, approval, journaling, timeout, mutation notification, and\n * action-result normalization; this transport must not call ActionEntry.run.\n */\n executeTool: (\n request: RealtimeVoiceToolExecutionRequest,\n ) =>\n | RealtimeVoiceToolExecutionResult\n | Promise<RealtimeVoiceToolExecutionResult>;\n}\n\ninterface RealtimeFunctionTool {\n type: \"function\";\n name: string;\n description: string;\n parameters: Record<string, unknown>;\n}\n\ninterface AuthenticatedVoiceContext extends RealtimeVoiceRequestContext {\n timezone?: string;\n}\n\nfunction readSafeHeader(event: H3Event, name: string): string | undefined {\n const value = getHeader(event, name);\n if (typeof value !== \"string\") return undefined;\n const trimmed = value.trim();\n return trimmed || undefined;\n}\n\nfunction configuredIdentifier(\n value: string | undefined,\n fallback: string,\n): string {\n const trimmed = value?.trim();\n return trimmed && /^[A-Za-z0-9_.:-]{1,128}$/.test(trimmed)\n ? trimmed\n : fallback;\n}\n\nfunction truncate(value: string, maxChars: number): string {\n if (value.length <= maxChars) return value;\n return `${value.slice(0, maxChars)}\\n\\n...[truncated]`;\n}\n\nfunction sanitizeOutput(value: unknown, maxChars: number): string {\n let serialized: string;\n try {\n const redacted = redactSensitiveFields(value);\n serialized =\n typeof redacted === \"string\"\n ? redacted\n : (JSON.stringify(redacted, (_key, entry) =>\n typeof entry === \"bigint\" ? entry.toString() : entry,\n ) ?? \"null\");\n } catch {\n serialized = \"[Unserializable tool result]\";\n }\n return truncate(sanitizeToolErrorText(serialized), maxChars);\n}\n\nasync function safeOpenAiErrorDetail(\n response: Response,\n apiKey: string,\n): Promise<string | null> {\n const raw = await response.text().catch(() => \"\");\n if (!raw) return null;\n let detail = raw;\n try {\n const parsed = JSON.parse(raw) as {\n error?: { message?: unknown; code?: unknown; type?: unknown } | unknown;\n };\n if (parsed.error && typeof parsed.error === \"object\") {\n const error = parsed.error as {\n message?: unknown;\n code?: unknown;\n type?: unknown;\n };\n detail = [error.message, error.code, error.type]\n .filter((value) => typeof value === \"string\" && value.trim())\n .join(\" · \");\n }\n } catch {\n // Plain-text upstream errors are sanitized below.\n }\n const redacted = sanitizeToolErrorText(detail).replaceAll(\n apiKey,\n \"[REDACTED]\",\n );\n return truncate(redacted, 500) || null;\n}\n\nfunction normalizeToolSchema(\n inputSchema: unknown,\n): Record<string, unknown> | null {\n try {\n const serialized = JSON.stringify(inputSchema);\n if (!serialized || serialized.length > MAX_TOOL_SCHEMA_CHARS) return null;\n const parsed = JSON.parse(serialized) as unknown;\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n return null;\n }\n return parsed as Record<string, unknown>;\n } catch {\n return null;\n }\n}\n\nfunction buildRealtimeTools(\n actions: Record<string, ActionEntry>,\n): RealtimeFunctionTool[] {\n const tools: RealtimeFunctionTool[] = [];\n for (const tool of actionsToEngineTools(actions)) {\n if (!REALTIME_TOOL_NAME.test(tool.name)) continue;\n const parameters = normalizeToolSchema(tool.inputSchema);\n if (!parameters) continue;\n tools.push({\n type: \"function\",\n name: tool.name,\n description: truncate(\n sanitizeToolErrorText(tool.description || \"\"),\n MAX_TOOL_DESCRIPTION_CHARS,\n ),\n parameters,\n });\n }\n return tools;\n}\n\nfunction declaredBodyBytes(event: H3Event): number | undefined {\n const raw = readSafeHeader(event, \"content-length\");\n if (!raw) return undefined;\n const parsed = Number.parseInt(raw, 10);\n return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;\n}\n\nasync function readLimitedRawBody(\n event: H3Event,\n maxBytes: number,\n): Promise<string | null | \"oversize\"> {\n const declared = declaredBodyBytes(event);\n if (declared !== undefined && declared > maxBytes) return \"oversize\";\n\n const raw = await readRawBody(event, \"utf8\").catch(() => undefined);\n if (raw == null) return null;\n const text =\n typeof raw === \"string\" ? raw : new TextDecoder().decode(raw as Uint8Array);\n return new TextEncoder().encode(text).byteLength > maxBytes\n ? \"oversize\"\n : text;\n}\n\nasync function authenticateVoiceRequest(\n event: H3Event,\n options: MountRealtimeVoiceRoutesOptions,\n): Promise<AuthenticatedVoiceContext | null> {\n const session = await getSession(event).catch(() => null);\n if (!session?.email) return null;\n const resolvedOrgId = options.resolveOrgId\n ? await options.resolveOrgId(event)\n : session.orgId;\n const timezone = readSafeHeader(event, \"x-user-timezone\");\n const rawBrowserTabId = readSafeHeader(event, \"x-agent-native-browser-tab\");\n const browserTabId =\n rawBrowserTabId && BROWSER_TAB_ID.test(rawBrowserTabId)\n ? rawBrowserTabId\n : undefined;\n return {\n event,\n userEmail: session.email,\n ...(resolvedOrgId ? { orgId: resolvedOrgId } : {}),\n ...(timezone && timezone.length < 64 ? { timezone } : {}),\n ...(browserTabId ? { browserTabId } : {}),\n };\n}\n\nasync function buildInstructions(\n context: RealtimeVoiceRequestContext,\n options: MountRealtimeVoiceRoutesOptions,\n): Promise<string> {\n const dynamic = await options.getInstructions?.(context);\n const appInstructions = dynamic ?? options.instructions;\n if (!appInstructions?.trim()) return DEFAULT_INSTRUCTIONS;\n return truncate(\n sanitizeToolErrorText(\n `${DEFAULT_INSTRUCTIONS}\\n\\n${appInstructions.trim()}`,\n ),\n MAX_INSTRUCTIONS_CHARS,\n );\n}\n\n/**\n * Hash the authenticated identity before sending it to OpenAI. The stable\n * digest is useful for abuse detection without disclosing the user's email.\n */\nexport async function realtimeVoiceSafetyIdentifier(\n userEmail: string,\n): Promise<string> {\n const input = new TextEncoder().encode(\n `agent-native:${userEmail.trim().toLowerCase()}`,\n );\n const digest = await globalThis.crypto.subtle.digest(\"SHA-256\", input);\n return Array.from(new Uint8Array(digest), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n}\n\nfunction invalidMethod(event: H3Event): { error: string } {\n setResponseStatus(event, 405);\n return { error: \"Method not allowed\" };\n}\n\nfunction createSessionHandler(\n tools: RealtimeFunctionTool[],\n options: MountRealtimeVoiceRoutesOptions,\n) {\n return defineEventHandler(async (event: H3Event) => {\n if (getMethod(event) !== \"POST\") return invalidMethod(event);\n if (!isSameOriginRequest(event)) {\n setResponseStatus(event, 403);\n return { error: \"Cross-origin request rejected\" };\n }\n setResponseHeader(event, \"Cache-Control\", \"no-store\");\n\n const auth = await authenticateVoiceRequest(event, options);\n if (!auth) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n\n const contentType = readSafeHeader(event, \"content-type\")?.toLowerCase();\n if (!contentType?.includes(\"application/sdp\")) {\n setResponseStatus(event, 415);\n return { error: \"Expected Content-Type: application/sdp\" };\n }\n\n const rawSdp = await readLimitedRawBody(\n event,\n REALTIME_VOICE_MAX_SDP_BYTES,\n );\n if (rawSdp === \"oversize\") {\n setResponseStatus(event, 413);\n return {\n error: `SDP offer is too large (max ${REALTIME_VOICE_MAX_SDP_BYTES} bytes)`,\n };\n }\n const sdp = rawSdp ?? \"\";\n if (!sdp.trim()) {\n setResponseStatus(event, 400);\n return { error: \"SDP offer is required\" };\n }\n\n return runWithRequestContext(\n {\n userEmail: auth.userEmail,\n orgId: auth.orgId,\n timezone: auth.timezone,\n run: auth.browserTabId\n ? { browserTabId: auth.browserTabId }\n : undefined,\n },\n async () => {\n const builderCredentials = await resolveBuilderCredentials();\n const builderConfigured = Boolean(\n builderCredentials.privateKey?.trim() &&\n builderCredentials.publicKey?.trim(),\n );\n const apiKey = builderConfigured\n ? null\n : (await resolveSecret(\"OPENAI_API_KEY\"))?.trim();\n if (!builderConfigured && !apiKey) {\n setResponseStatus(event, 409);\n return {\n error:\n \"Connect Builder or configure an OpenAI API key to use realtime voice.\",\n code: \"realtime_voice_setup_required\",\n };\n }\n\n const instructions = await buildInstructions(auth, options);\n const session = {\n type: \"realtime\",\n model: configuredIdentifier(options.model, DEFAULT_MODEL),\n instructions,\n output_modalities: [\"audio\"],\n audio: {\n input: {\n transcription: { model: \"gpt-4o-mini-transcribe\" },\n turn_detection: {\n type: \"semantic_vad\",\n create_response: true,\n interrupt_response: true,\n eagerness: \"auto\",\n },\n },\n output: {\n voice: configuredIdentifier(options.voice, DEFAULT_VOICE),\n },\n },\n tools,\n tool_choice: \"auto\",\n };\n\n let upstream: Response;\n try {\n if (builderConfigured) {\n const gatewayUrl = new URL(\n \"realtime/calls\",\n getBuilderGatewayBaseUrl().endsWith(\"/\")\n ? getBuilderGatewayBaseUrl()\n : `${getBuilderGatewayBaseUrl()}/`,\n );\n gatewayUrl.searchParams.set(\n \"apiKey\",\n builderCredentials.publicKey!.trim(),\n );\n upstream = await fetch(gatewayUrl.toString(), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${builderCredentials.privateKey!.trim()}`,\n \"x-builder-api-key\": builderCredentials.publicKey!.trim(),\n ...getBuilderGatewayRequestHeaders(),\n ...(builderCredentials.userId\n ? { \"x-builder-user-id\": builderCredentials.userId }\n : {}),\n },\n body: JSON.stringify({ sdp, session }),\n });\n } else {\n const form = new FormData();\n form.set(\"sdp\", sdp);\n form.set(\"session\", JSON.stringify(session));\n upstream = await fetch(OPENAI_REALTIME_CALLS_URL, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"OpenAI-Safety-Identifier\": await realtimeVoiceSafetyIdentifier(\n auth.userEmail,\n ),\n },\n body: form,\n });\n }\n } catch {\n setResponseStatus(event, 502);\n return {\n error: builderConfigured\n ? \"Could not reach the Builder realtime voice gateway\"\n : \"Could not reach the OpenAI Realtime API\",\n };\n }\n\n if (!upstream.ok) {\n const detail = await safeOpenAiErrorDetail(\n upstream,\n builderConfigured ? builderCredentials.privateKey! : apiKey!,\n );\n setResponseStatus(event, builderConfigured ? upstream.status : 502);\n return {\n error: `${builderConfigured ? \"Builder\" : \"OpenAI\"} rejected the realtime session (${upstream.status})${detail ? `: ${detail}` : \"\"}`,\n };\n }\n\n const answerSdp = await upstream.text().catch(() => \"\");\n if (!answerSdp.trim()) {\n setResponseStatus(event, 502);\n return {\n error: `${builderConfigured ? \"Builder\" : \"OpenAI\"} returned an empty realtime session answer`,\n };\n }\n\n setResponseStatus(event, upstream.status);\n setResponseHeader(event, \"Content-Type\", \"application/sdp\");\n return answerSdp;\n },\n );\n });\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction parseToolRequest(value: unknown): {\n name: string;\n args: Record<string, unknown>;\n callId: string;\n sessionId?: string;\n browserTabId?: string;\n} | null {\n if (!isRecord(value)) return null;\n const { name, args, callId, sessionId, browserTabId } = value;\n if (typeof name !== \"string\" || !REALTIME_TOOL_NAME.test(name)) return null;\n if (typeof callId !== \"string\" || !CALL_ID.test(callId)) return null;\n if (!isRecord(args)) return null;\n if (\n sessionId !== undefined &&\n (typeof sessionId !== \"string\" || !SESSION_ID.test(sessionId))\n ) {\n return null;\n }\n if (\n browserTabId !== undefined &&\n (typeof browserTabId !== \"string\" || !BROWSER_TAB_ID.test(browserTabId))\n ) {\n return null;\n }\n return {\n name,\n args,\n callId,\n ...(sessionId ? { sessionId } : {}),\n ...(browserTabId ? { browserTabId } : {}),\n };\n}\n\nfunction normalizeExecutionResult(\n result: RealtimeVoiceToolExecutionResult,\n): RealtimeVoiceToolExecutionResult {\n const status = result?.status;\n if (\n status !== \"completed\" &&\n status !== \"failed\" &&\n status !== \"approval_required\"\n ) {\n throw new Error(\"Invalid realtime tool execution status\");\n }\n const output = sanitizeOutput(\n result.output,\n REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS,\n );\n return {\n status,\n output,\n ...(status === \"approval_required\" &&\n typeof result.approvalKey === \"string\" &&\n result.approvalKey.length > 0 &&\n result.approvalKey.length <= MAX_APPROVAL_KEY_CHARS\n ? { approvalKey: result.approvalKey }\n : {}),\n };\n}\n\nfunction createToolHandler(\n allowedToolNames: ReadonlySet<string>,\n options: MountRealtimeVoiceRoutesOptions,\n) {\n return defineEventHandler(async (event: H3Event) => {\n if (getMethod(event) !== \"POST\") return invalidMethod(event);\n if (!isSameOriginRequest(event)) {\n setResponseStatus(event, 403);\n return { error: \"Cross-origin request rejected\" };\n }\n setResponseHeader(event, \"Cache-Control\", \"no-store\");\n\n const auth = await authenticateVoiceRequest(event, options);\n if (!auth) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n\n const contentType = readSafeHeader(event, \"content-type\")?.toLowerCase();\n if (!contentType?.includes(\"application/json\")) {\n setResponseStatus(event, 415);\n return { error: \"Expected Content-Type: application/json\" };\n }\n\n const raw = await readLimitedRawBody(\n event,\n REALTIME_VOICE_MAX_TOOL_BODY_BYTES,\n );\n if (raw === \"oversize\") {\n setResponseStatus(event, 413);\n return {\n error: `Tool request is too large (max ${REALTIME_VOICE_MAX_TOOL_BODY_BYTES} bytes)`,\n };\n }\n\n let parsedBody: unknown;\n try {\n parsedBody = JSON.parse(raw ?? \"\");\n } catch {\n setResponseStatus(event, 400);\n return { error: \"Invalid realtime tool request\" };\n }\n const request = parseToolRequest(parsedBody);\n if (!request) {\n setResponseStatus(event, 400);\n return { error: \"Invalid realtime tool request\" };\n }\n if (!allowedToolNames.has(request.name)) {\n setResponseStatus(event, 404);\n return { error: \"Unknown realtime voice tool\" };\n }\n\n const browserTabId = request.browserTabId ?? auth.browserTabId;\n const threadId = request.sessionId\n ? `realtime:${request.sessionId}`\n : `realtime:${request.callId}`;\n return runWithRequestContext(\n {\n userEmail: auth.userEmail,\n orgId: auth.orgId,\n timezone: auth.timezone,\n run: {\n threadId,\n ...(browserTabId ? { browserTabId } : {}),\n },\n },\n async () => {\n try {\n const result = normalizeExecutionResult(\n await options.executeTool({\n event,\n userEmail: auth.userEmail,\n orgId: auth.orgId,\n ...request,\n }),\n );\n return { callId: request.callId, ...result };\n } catch (error) {\n setResponseStatus(event, 500);\n return {\n callId: request.callId,\n status: \"failed\" as const,\n output: truncate(\n sanitizeToolErrorValue(error) || \"Tool execution failed\",\n REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS,\n ),\n };\n }\n },\n );\n });\n}\n\n/** Mount the authenticated OpenAI Realtime WebRTC and tool bridge routes. */\nexport function mountRealtimeVoiceRoutes(\n nitroApp: any,\n actions: Record<string, ActionEntry>,\n options: MountRealtimeVoiceRoutesOptions,\n): { sessionPath: string; toolPath: string } {\n if (typeof options?.executeTool !== \"function\") {\n throw new Error(\"mountRealtimeVoiceRoutes requires executeTool\");\n }\n\n const tools = buildRealtimeTools(actions);\n const allowedToolNames = new Set(tools.map((tool) => tool.name));\n const app = getH3App(nitroApp);\n app.use(REALTIME_VOICE_SESSION_PATH, createSessionHandler(tools, options));\n app.use(\n REALTIME_VOICE_TOOL_PATH,\n createToolHandler(allowedToolNames, options),\n );\n return {\n sessionPath: REALTIME_VOICE_SESSION_PATH,\n toolPath: REALTIME_VOICE_TOOL_PATH,\n };\n}\n"]}
1
+ {"version":3,"file":"realtime-voice.js","sourceRoot":"","sources":["../../src/server/realtime-voice.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,iBAAiB,GAElB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,EACL,oBAAoB,GAErB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,GACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,CAAC,MAAM,2BAA2B,GACtC,uCAAuC,CAAC;AAC1C,MAAM,CAAC,MAAM,wBAAwB,GAAG,oCAAoC,CAAC;AAC7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,GAAG,IAAI,CAAC;AACtD,MAAM,CAAC,MAAM,kCAAkC,GAAG,EAAE,GAAG,IAAI,CAAC;AAC5D,MAAM,CAAC,MAAM,oCAAoC,GAAG,MAAM,CAAC;AAC3D,MA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;IACpE,MAAM,YAAY,GAAgC,IAAI,GAAG,EAAE,CAAC;IAC5D,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/B,GAAG,CAAC,GAAG,CACL,2BAA2B,EAC3B,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,CACnD,CAAC;IACF,GAAG,CAAC,GAAG,CACL,wBAAwB,EACxB,iBAAiB,CAAC,WAAW,EAAE,YAAY,EAAE,OAAO,CAAC,CACtD,CAAC;IACF,OAAO;QACL,WAAW,EAAE,2BAA2B;QACxC,QAAQ,EAAE,wBAAwB;KACnC,CAAC;AACJ,CAAC","sourcesContent":["import {\n defineEventHandler,\n getHeader,\n getMethod,\n readRawBody,\n setResponseHeader,\n setResponseStatus,\n type H3Event,\n} from \"h3\";\n\nimport { getBuilderGatewayRequestHeaders } from \"../agent/engine/builder-gateway-headers.js\";\nimport {\n actionsToEngineTools,\n type ActionEntry,\n} from \"../agent/production-agent.js\";\nimport {\n redactSensitiveFields,\n sanitizeToolErrorText,\n sanitizeToolErrorValue,\n} from \"../agent/tool-error-redaction.js\";\nimport { TOOL_SEARCH_ACTION_NAME } from \"../agent/tool-search.js\";\nimport { parseAcceptLanguage } from \"../localization/server.js\";\nimport { getSession } from \"./auth.js\";\nimport {\n getBuilderGatewayBaseUrl,\n resolveBuilderCredentials,\n resolveSecret,\n} from \"./credential-provider.js\";\nimport { getH3App } from \"./framework-request-handler.js\";\nimport { runWithRequestContext } from \"./request-context.js\";\nimport { isSameOriginRequest } from \"./request-origin.js\";\n\nexport const REALTIME_VOICE_SESSION_PATH =\n \"/_agent-native/realtime-voice/session\";\nexport const REALTIME_VOICE_TOOL_PATH = \"/_agent-native/realtime-voice/tool\";\nexport const REALTIME_VOICE_MAX_SDP_BYTES = 64 * 1024;\nexport const REALTIME_VOICE_MAX_TOOL_BODY_BYTES = 64 * 1024;\nexport const REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS = 16_000;\nexport const REALTIME_VOICE_MAX_TOOLS = 32;\nexport const REALTIME_VOICE_MAX_TOOL_SCHEMA_BYTES = 32_000;\nexport const REALTIME_VOICE_MAX_SESSION_BYTES = 64_000;\nexport const REALTIME_VOICE_TOOL_GRANT_TTL_MS = 10 * 60 * 1_000;\nexport const REALTIME_VOICE_MAX_TOOL_GRANT_SESSIONS = 256;\nexport const REALTIME_VOICE_CAPABILITY_HEADER =\n \"X-Agent-Native-Realtime-Capability\";\n\nconst OPENAI_REALTIME_CALLS_URL = \"https://api.openai.com/v1/realtime/calls\";\nconst DEFAULT_MODEL = \"gpt-realtime-2.1\";\nconst DEFAULT_VOICE = \"marin\";\nconst DEFAULT_INSTRUCTIONS =\n \"You are the live voice interface for this Agent Native app. Speak naturally, briefly, and conversationally. Use the available function tools when the user asks you to navigate or take an action. Never claim an action succeeded until its tool result confirms success. If a tool requires approval, explain that the user must approve it in chat.\";\nconst MAX_INSTRUCTIONS_CHARS = 16_000;\nconst MAX_TOOL_DESCRIPTION_CHARS = 2_000;\nconst MAX_APPROVAL_KEY_CHARS = 1_024;\nconst REALTIME_TOOL_NAME = /^[A-Za-z0-9_-]{1,64}$/;\nconst CALL_ID = /^[A-Za-z0-9_-]{1,256}$/;\nconst SESSION_ID = /^[A-Za-z0-9_.:-]{1,256}$/;\nconst BROWSER_TAB_ID = /^[A-Za-z0-9_-]{1,96}$/;\nconst ISO_639_1_LANGUAGE = /^[A-Za-z]{2}$/;\nconst REALTIME_VOICE_BUILT_INS = new Set([\n \"alloy\",\n \"ash\",\n \"ballad\",\n \"coral\",\n \"echo\",\n \"sage\",\n \"shimmer\",\n \"verse\",\n \"marin\",\n \"cedar\",\n]);\nconst REALTIME_VOICE_REASONING_EFFORT = {\n instant: \"minimal\",\n balanced: \"low\",\n deep: \"medium\",\n} as const;\n\n/**\n * Realtime sessions have a deliberately bounded tool manifest. Keep the\n * context/navigation tools ahead of large template registries so voice can\n * always see and operate the same UI navigation surface as text chat.\n */\nconst REALTIME_VOICE_PRIORITY_TOOLS = [\n \"navigate\",\n \"set-url-path\",\n \"set-search-params\",\n \"view-screen\",\n TOOL_SEARCH_ACTION_NAME,\n] as const;\n\nexport interface RealtimeVoiceRequestContext {\n event: H3Event;\n userEmail: string;\n orgId?: string;\n browserTabId?: string;\n}\n\nexport interface RealtimeVoiceToolExecutionRequest extends RealtimeVoiceRequestContext {\n name: string;\n args: Record<string, unknown>;\n callId: string;\n sessionId?: string;\n}\n\nexport interface RealtimeVoiceToolExecutionResult {\n status: \"completed\" | \"failed\" | \"approval_required\";\n output: string;\n approvalKey?: string;\n}\n\nexport interface MountRealtimeVoiceRoutesOptions {\n /** Server-controlled model. Defaults to gpt-realtime-2.1. */\n model?: string;\n /** Server-controlled output voice. Defaults to marin. */\n voice?: string;\n /** Static app guidance appended to the safe default voice instructions. */\n instructions?: string;\n /** Per-request app/navigation guidance. It is sent only to OpenAI. */\n getInstructions?: (\n context: RealtimeVoiceRequestContext,\n ) => string | null | undefined | Promise<string | null | undefined>;\n /** Optional app-specific active-organization resolver. */\n resolveOrgId?: (\n event: H3Event,\n ) => string | null | undefined | Promise<string | null | undefined>;\n /**\n * Central agent tool executor supplied by the agent-chat plugin. The executor\n * owns validation, approval, journaling, timeout, mutation notification, and\n * action-result normalization; this transport must not call ActionEntry.run.\n */\n executeTool: (\n request: RealtimeVoiceToolExecutionRequest,\n ) =>\n | RealtimeVoiceToolExecutionResult\n | Promise<RealtimeVoiceToolExecutionResult>;\n}\n\ninterface RealtimeFunctionTool {\n type: \"function\";\n name: string;\n description: string;\n parameters: Record<string, unknown>;\n}\n\ninterface RealtimeToolCapability {\n userEmail: string;\n orgId?: string;\n browserTabId?: string;\n expiresAt: number;\n initialNames: Set<string>;\n names: Set<string>;\n}\n\ntype RealtimeToolCapabilityStore = Map<string, RealtimeToolCapability>;\n\ninterface AuthenticatedVoiceContext extends RealtimeVoiceRequestContext {\n timezone?: string;\n}\n\nfunction readSafeHeader(event: H3Event, name: string): string | undefined {\n const value = getHeader(event, name);\n if (typeof value !== \"string\") return undefined;\n const trimmed = value.trim();\n return trimmed || undefined;\n}\n\nfunction configuredIdentifier(\n value: string | undefined,\n fallback: string,\n): string {\n const trimmed = value?.trim();\n return trimmed && /^[A-Za-z0-9_.:-]{1,128}$/.test(trimmed)\n ? trimmed\n : fallback;\n}\n\nexport function resolveRealtimeVoiceTranscriptionLanguage(\n acceptLanguage: string | null | undefined,\n): string {\n for (const locale of parseAcceptLanguage(acceptLanguage)) {\n const primaryLanguage = locale.split(\"-\")[0];\n if (ISO_639_1_LANGUAGE.test(primaryLanguage)) {\n return primaryLanguage.toLowerCase();\n }\n }\n return \"en\";\n}\n\nexport function resolveRealtimeVoiceLanguagePreference(\n value: string | null | undefined,\n acceptLanguage: string | null | undefined,\n): string {\n const normalized = value?.trim().toLowerCase();\n return normalized && ISO_639_1_LANGUAGE.test(normalized)\n ? normalized\n : resolveRealtimeVoiceTranscriptionLanguage(acceptLanguage);\n}\n\nexport function resolveRealtimeVoiceReasoningEffort(\n value: string | null | undefined,\n): \"minimal\" | \"low\" | \"medium\" {\n const normalized = value?.trim().toLowerCase();\n return normalized &&\n Object.hasOwn(REALTIME_VOICE_REASONING_EFFORT, normalized)\n ? REALTIME_VOICE_REASONING_EFFORT[\n normalized as keyof typeof REALTIME_VOICE_REASONING_EFFORT\n ]\n : \"low\";\n}\n\nexport function resolveRealtimeVoicePreference(\n value: string | null | undefined,\n fallback: string,\n): string {\n const normalized = value?.trim().toLowerCase();\n return normalized && REALTIME_VOICE_BUILT_INS.has(normalized)\n ? normalized\n : fallback;\n}\n\nfunction truncate(value: string, maxChars: number): string {\n if (value.length <= maxChars) return value;\n return `${value.slice(0, maxChars)}\\n\\n...[truncated]`;\n}\n\nfunction sanitizeOutput(value: unknown, maxChars: number): string {\n let serialized: string;\n try {\n const redacted = redactSensitiveFields(value);\n serialized =\n typeof redacted === \"string\"\n ? redacted\n : (JSON.stringify(redacted, (_key, entry) =>\n typeof entry === \"bigint\" ? entry.toString() : entry,\n ) ?? \"null\");\n } catch {\n serialized = \"[Unserializable tool result]\";\n }\n return truncate(sanitizeToolErrorText(serialized), maxChars);\n}\n\nasync function safeOpenAiErrorDetail(\n response: Response,\n apiKey: string,\n): Promise<string | null> {\n const raw = await response.text().catch(() => \"\");\n if (!raw) return null;\n let detail = raw;\n try {\n const parsed = JSON.parse(raw) as {\n error?: { message?: unknown; code?: unknown; type?: unknown } | unknown;\n };\n if (parsed.error && typeof parsed.error === \"object\") {\n const error = parsed.error as {\n message?: unknown;\n code?: unknown;\n type?: unknown;\n };\n detail = [error.message, error.code, error.type]\n .filter((value) => typeof value === \"string\" && value.trim())\n .join(\" · \");\n }\n } catch {\n // Plain-text upstream errors are sanitized below.\n }\n const redacted = sanitizeToolErrorText(detail).replaceAll(\n apiKey,\n \"[REDACTED]\",\n );\n return truncate(redacted, 500) || null;\n}\n\nfunction normalizeToolSchema(\n inputSchema: unknown,\n): Record<string, unknown> | null {\n try {\n const serialized = JSON.stringify(inputSchema);\n if (\n !serialized ||\n Buffer.byteLength(serialized, \"utf8\") >\n REALTIME_VOICE_MAX_TOOL_SCHEMA_BYTES\n ) {\n return null;\n }\n const parsed = JSON.parse(serialized) as unknown;\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n return null;\n }\n return parsed as Record<string, unknown>;\n } catch {\n return null;\n }\n}\n\nfunction buildRealtimeTools(\n actions: Record<string, ActionEntry>,\n): RealtimeFunctionTool[] {\n const tools: RealtimeFunctionTool[] = [];\n for (const tool of actionsToEngineTools(actions)) {\n if (!REALTIME_TOOL_NAME.test(tool.name)) continue;\n const parameters = normalizeToolSchema(tool.inputSchema);\n if (!parameters) continue;\n tools.push({\n type: \"function\",\n name: tool.name,\n description: truncate(\n sanitizeToolErrorText(tool.description || \"\"),\n MAX_TOOL_DESCRIPTION_CHARS,\n ),\n parameters,\n });\n }\n const priority = new Map<string, number>(\n REALTIME_VOICE_PRIORITY_TOOLS.map((name, index) => [name, index]),\n );\n return tools\n .map((tool, index) => ({ tool, index }))\n .sort((left, right) => {\n const leftPriority = priority.get(left.tool.name);\n const rightPriority = priority.get(right.tool.name);\n if (leftPriority !== undefined || rightPriority !== undefined) {\n if (leftPriority === undefined) return 1;\n if (rightPriority === undefined) return -1;\n return leftPriority - rightPriority;\n }\n return left.index - right.index;\n })\n .map(({ tool }) => tool);\n}\n\nfunction packRealtimeTools(\n session: Record<string, unknown>,\n eligibleTools: RealtimeFunctionTool[],\n): RealtimeFunctionTool[] {\n const packed: RealtimeFunctionTool[] = [];\n for (const tool of eligibleTools.slice(0, REALTIME_VOICE_MAX_TOOLS)) {\n const candidate = [...packed, tool];\n const candidateSession = {\n ...session,\n tools: candidate,\n tool_choice: \"auto\",\n };\n if (\n Buffer.byteLength(JSON.stringify(candidateSession), \"utf8\") <=\n REALTIME_VOICE_MAX_SESSION_BYTES\n ) {\n packed.push(tool);\n }\n }\n return packed;\n}\n\nfunction mintRealtimeToolCapability(): string {\n return globalThis.crypto.randomUUID().replaceAll(\"-\", \"\");\n}\n\nfunction cleanRealtimeToolCapabilities(\n capabilities: RealtimeToolCapabilityStore,\n now = Date.now(),\n): void {\n for (const [key, capability] of capabilities) {\n if (capability.expiresAt <= now) capabilities.delete(key);\n }\n while (capabilities.size > REALTIME_VOICE_MAX_TOOL_GRANT_SESSIONS) {\n let oldestKey: string | undefined;\n let oldestExpiry = Number.POSITIVE_INFINITY;\n for (const [key, capability] of capabilities) {\n if (capability.expiresAt < oldestExpiry) {\n oldestKey = key;\n oldestExpiry = capability.expiresAt;\n }\n }\n if (!oldestKey) break;\n capabilities.delete(oldestKey);\n }\n}\n\nfunction registerRealtimeToolCapability(\n capabilities: RealtimeToolCapabilityStore,\n auth: AuthenticatedVoiceContext,\n initialNames: Iterable<string>,\n): string {\n cleanRealtimeToolCapabilities(capabilities);\n const token = mintRealtimeToolCapability();\n capabilities.set(token, {\n userEmail: auth.userEmail.trim().toLowerCase(),\n ...(auth.orgId ? { orgId: auth.orgId } : {}),\n ...(auth.browserTabId ? { browserTabId: auth.browserTabId } : {}),\n expiresAt: Date.now() + REALTIME_VOICE_TOOL_GRANT_TTL_MS,\n initialNames: new Set(initialNames),\n names: new Set(),\n });\n cleanRealtimeToolCapabilities(capabilities);\n return token;\n}\n\nfunction resolveRealtimeToolCapability(\n capabilities: RealtimeToolCapabilityStore,\n token: string | undefined,\n auth: AuthenticatedVoiceContext,\n): RealtimeToolCapability | null {\n cleanRealtimeToolCapabilities(capabilities);\n if (!token) return null;\n const capability = capabilities.get(token);\n if (!capability) return null;\n if (\n capability.userEmail !== auth.userEmail.trim().toLowerCase() ||\n capability.orgId !== auth.orgId ||\n capability.browserTabId !== auth.browserTabId\n ) {\n return null;\n }\n capability.expiresAt = Date.now() + REALTIME_VOICE_TOOL_GRANT_TTL_MS;\n return capability;\n}\n\nfunction parseSuccessfulToolSearchNames(output: string): string[] {\n try {\n const parsed = JSON.parse(output) as { results?: unknown };\n if (!Array.isArray(parsed.results)) return [];\n const names: string[] = [];\n for (const result of parsed.results) {\n if (!isRecord(result) || typeof result.name !== \"string\") continue;\n if (!REALTIME_TOOL_NAME.test(result.name)) continue;\n if (!names.includes(result.name)) names.push(result.name);\n if (names.length >= REALTIME_VOICE_MAX_TOOLS) break;\n }\n return names;\n } catch {\n return [];\n }\n}\n\nfunction grantDiscoveredRealtimeTools(input: {\n request: NonNullable<ReturnType<typeof parseToolRequest>>;\n result: RealtimeVoiceToolExecutionResult;\n toolsByName: ReadonlyMap<string, RealtimeFunctionTool>;\n initialAllowedNames: ReadonlySet<string>;\n capability: RealtimeToolCapability;\n}): RealtimeFunctionTool[] {\n const query = input.request.args.query;\n if (\n input.request.name !== TOOL_SEARCH_ACTION_NAME ||\n input.result.status !== \"completed\" ||\n typeof query !== \"string\" ||\n !query.trim()\n ) {\n return [];\n }\n\n const candidates = parseSuccessfulToolSearchNames(input.result.output)\n .filter((name) => !input.initialAllowedNames.has(name))\n .map((name) => input.toolsByName.get(name))\n .filter((tool): tool is RealtimeFunctionTool => Boolean(tool));\n const boundedTools = packRealtimeTools({}, candidates);\n const expandedTools: RealtimeFunctionTool[] = [];\n for (const tool of boundedTools) {\n if (\n !input.capability.names.has(tool.name) &&\n input.capability.names.size >= REALTIME_VOICE_MAX_TOOLS\n ) {\n continue;\n }\n input.capability.names.add(tool.name);\n expandedTools.push(tool);\n }\n input.capability.expiresAt = Date.now() + REALTIME_VOICE_TOOL_GRANT_TTL_MS;\n return expandedTools;\n}\n\nfunction declaredBodyBytes(event: H3Event): number | undefined {\n const raw = readSafeHeader(event, \"content-length\");\n if (!raw) return undefined;\n const parsed = Number.parseInt(raw, 10);\n return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;\n}\n\nasync function readLimitedRawBody(\n event: H3Event,\n maxBytes: number,\n): Promise<string | null | \"oversize\"> {\n const declared = declaredBodyBytes(event);\n if (declared !== undefined && declared > maxBytes) return \"oversize\";\n\n const raw = await readRawBody(event, \"utf8\").catch(() => undefined);\n if (raw == null) return null;\n const text =\n typeof raw === \"string\" ? raw : new TextDecoder().decode(raw as Uint8Array);\n return new TextEncoder().encode(text).byteLength > maxBytes\n ? \"oversize\"\n : text;\n}\n\nasync function authenticateVoiceRequest(\n event: H3Event,\n options: MountRealtimeVoiceRoutesOptions,\n): Promise<AuthenticatedVoiceContext | null> {\n const session = await getSession(event).catch(() => null);\n if (!session?.email) return null;\n const resolvedOrgId = options.resolveOrgId\n ? await options.resolveOrgId(event)\n : session.orgId;\n const timezone = readSafeHeader(event, \"x-user-timezone\");\n const rawBrowserTabId = readSafeHeader(event, \"x-agent-native-browser-tab\");\n const browserTabId =\n rawBrowserTabId && BROWSER_TAB_ID.test(rawBrowserTabId)\n ? rawBrowserTabId\n : undefined;\n return {\n event,\n userEmail: session.email,\n ...(resolvedOrgId ? { orgId: resolvedOrgId } : {}),\n ...(timezone && timezone.length < 64 ? { timezone } : {}),\n ...(browserTabId ? { browserTabId } : {}),\n };\n}\n\nasync function buildInstructions(\n context: RealtimeVoiceRequestContext,\n options: MountRealtimeVoiceRoutesOptions,\n): Promise<string> {\n const dynamic = await options.getInstructions?.(context);\n const appInstructions = dynamic ?? options.instructions;\n if (!appInstructions?.trim()) return DEFAULT_INSTRUCTIONS;\n return truncate(\n sanitizeToolErrorText(\n `${DEFAULT_INSTRUCTIONS}\\n\\n${appInstructions.trim()}`,\n ),\n MAX_INSTRUCTIONS_CHARS,\n );\n}\n\n/**\n * Hash the authenticated identity before sending it to OpenAI. The stable\n * digest is useful for abuse detection without disclosing the user's email.\n */\nexport async function realtimeVoiceSafetyIdentifier(\n userEmail: string,\n): Promise<string> {\n const input = new TextEncoder().encode(\n `agent-native:${userEmail.trim().toLowerCase()}`,\n );\n const digest = await globalThis.crypto.subtle.digest(\"SHA-256\", input);\n return Array.from(new Uint8Array(digest), (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\");\n}\n\nfunction invalidMethod(event: H3Event): { error: string } {\n setResponseStatus(event, 405);\n return { error: \"Method not allowed\" };\n}\n\nfunction createSessionHandler(\n tools: RealtimeFunctionTool[],\n capabilities: RealtimeToolCapabilityStore,\n options: MountRealtimeVoiceRoutesOptions,\n) {\n return defineEventHandler(async (event: H3Event) => {\n if (getMethod(event) !== \"POST\") return invalidMethod(event);\n if (!isSameOriginRequest(event)) {\n setResponseStatus(event, 403);\n return { error: \"Cross-origin request rejected\" };\n }\n setResponseHeader(event, \"Cache-Control\", \"no-store\");\n\n const auth = await authenticateVoiceRequest(event, options);\n if (!auth) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n\n const contentType = readSafeHeader(event, \"content-type\")?.toLowerCase();\n if (!contentType?.includes(\"application/sdp\")) {\n setResponseStatus(event, 415);\n return { error: \"Expected Content-Type: application/sdp\" };\n }\n\n const rawSdp = await readLimitedRawBody(\n event,\n REALTIME_VOICE_MAX_SDP_BYTES,\n );\n if (rawSdp === \"oversize\") {\n setResponseStatus(event, 413);\n return {\n error: `SDP offer is too large (max ${REALTIME_VOICE_MAX_SDP_BYTES} bytes)`,\n };\n }\n const sdp = rawSdp ?? \"\";\n if (!sdp.trim()) {\n setResponseStatus(event, 400);\n return { error: \"SDP offer is required\" };\n }\n\n return runWithRequestContext(\n {\n userEmail: auth.userEmail,\n orgId: auth.orgId,\n timezone: auth.timezone,\n run: auth.browserTabId\n ? { browserTabId: auth.browserTabId }\n : undefined,\n },\n async () => {\n const builderCredentials = await resolveBuilderCredentials();\n const builderConfigured = Boolean(\n builderCredentials.privateKey?.trim() &&\n builderCredentials.publicKey?.trim(),\n );\n const apiKey = builderConfigured\n ? null\n : (await resolveSecret(\"OPENAI_API_KEY\"))?.trim();\n if (!builderConfigured && !apiKey) {\n setResponseStatus(event, 409);\n return {\n error:\n \"Connect Builder or configure an OpenAI API key to use realtime voice.\",\n code: \"realtime_voice_setup_required\",\n };\n }\n\n const instructions = await buildInstructions(auth, options);\n const transcriptionLanguage = resolveRealtimeVoiceLanguagePreference(\n readSafeHeader(event, \"x-agent-native-realtime-language\"),\n readSafeHeader(event, \"accept-language\"),\n );\n const reasoningEffort = resolveRealtimeVoiceReasoningEffort(\n readSafeHeader(event, \"x-agent-native-realtime-intelligence\"),\n );\n const voice = resolveRealtimeVoicePreference(\n readSafeHeader(event, \"x-agent-native-realtime-voice\"),\n configuredIdentifier(options.voice, DEFAULT_VOICE),\n );\n const sessionBase = {\n type: \"realtime\",\n model: configuredIdentifier(options.model, DEFAULT_MODEL),\n instructions,\n parallel_tool_calls: false,\n reasoning: { effort: reasoningEffort },\n output_modalities: [\"audio\"],\n audio: {\n input: {\n transcription: {\n model: \"gpt-4o-mini-transcribe\",\n language: transcriptionLanguage,\n },\n turn_detection: {\n type: \"semantic_vad\",\n create_response: true,\n interrupt_response: true,\n eagerness: \"auto\",\n },\n },\n output: {\n voice,\n },\n },\n };\n const packedTools = packRealtimeTools(sessionBase, tools);\n const session = {\n ...sessionBase,\n tools: packedTools,\n tool_choice: \"auto\",\n };\n\n let upstream: Response;\n try {\n if (builderConfigured) {\n const gatewayUrl = new URL(\n \"realtime/calls\",\n getBuilderGatewayBaseUrl().endsWith(\"/\")\n ? getBuilderGatewayBaseUrl()\n : `${getBuilderGatewayBaseUrl()}/`,\n );\n gatewayUrl.searchParams.set(\n \"apiKey\",\n builderCredentials.publicKey!.trim(),\n );\n upstream = await fetch(gatewayUrl.toString(), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${builderCredentials.privateKey!.trim()}`,\n \"x-builder-api-key\": builderCredentials.publicKey!.trim(),\n ...getBuilderGatewayRequestHeaders(),\n ...(builderCredentials.userId\n ? { \"x-builder-user-id\": builderCredentials.userId }\n : {}),\n },\n body: JSON.stringify({ sdp, session }),\n });\n } else {\n const form = new FormData();\n form.set(\"sdp\", sdp);\n form.set(\"session\", JSON.stringify(session));\n upstream = await fetch(OPENAI_REALTIME_CALLS_URL, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${apiKey}`,\n \"OpenAI-Safety-Identifier\": await realtimeVoiceSafetyIdentifier(\n auth.userEmail,\n ),\n },\n body: form,\n });\n }\n } catch {\n setResponseStatus(event, 502);\n return {\n error: builderConfigured\n ? \"Could not reach the Builder realtime voice gateway\"\n : \"Could not reach the OpenAI Realtime API\",\n };\n }\n\n if (!upstream.ok) {\n const detail = await safeOpenAiErrorDetail(\n upstream,\n builderConfigured ? builderCredentials.privateKey! : apiKey!,\n );\n setResponseStatus(event, builderConfigured ? upstream.status : 502);\n return {\n error: `${builderConfigured ? \"Builder\" : \"OpenAI\"} rejected the realtime session (${upstream.status})${detail ? `: ${detail}` : \"\"}`,\n };\n }\n\n const answerSdp = await upstream.text().catch(() => \"\");\n if (!answerSdp.trim()) {\n setResponseStatus(event, 502);\n return {\n error: `${builderConfigured ? \"Builder\" : \"OpenAI\"} returned an empty realtime session answer`,\n };\n }\n\n setResponseStatus(event, upstream.status);\n setResponseHeader(event, \"Content-Type\", \"application/sdp\");\n setResponseHeader(\n event,\n REALTIME_VOICE_CAPABILITY_HEADER,\n registerRealtimeToolCapability(\n capabilities,\n auth,\n packedTools.map((tool) => tool.name),\n ),\n );\n return answerSdp;\n },\n );\n });\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction parseToolRequest(value: unknown): {\n name: string;\n args: Record<string, unknown>;\n callId: string;\n sessionId?: string;\n browserTabId?: string;\n} | null {\n if (!isRecord(value)) return null;\n const { name, args, callId, sessionId, browserTabId } = value;\n if (typeof name !== \"string\" || !REALTIME_TOOL_NAME.test(name)) return null;\n if (typeof callId !== \"string\" || !CALL_ID.test(callId)) return null;\n if (!isRecord(args)) return null;\n if (\n sessionId !== undefined &&\n (typeof sessionId !== \"string\" || !SESSION_ID.test(sessionId))\n ) {\n return null;\n }\n if (\n browserTabId !== undefined &&\n (typeof browserTabId !== \"string\" || !BROWSER_TAB_ID.test(browserTabId))\n ) {\n return null;\n }\n return {\n name,\n args,\n callId,\n ...(sessionId ? { sessionId } : {}),\n ...(browserTabId ? { browserTabId } : {}),\n };\n}\n\nfunction normalizeExecutionResult(\n result: RealtimeVoiceToolExecutionResult,\n): RealtimeVoiceToolExecutionResult {\n const status = result?.status;\n if (\n status !== \"completed\" &&\n status !== \"failed\" &&\n status !== \"approval_required\"\n ) {\n throw new Error(\"Invalid realtime tool execution status\");\n }\n const output = sanitizeOutput(\n result.output,\n REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS,\n );\n return {\n status,\n output,\n ...(status === \"approval_required\" &&\n typeof result.approvalKey === \"string\" &&\n result.approvalKey.length > 0 &&\n result.approvalKey.length <= MAX_APPROVAL_KEY_CHARS\n ? { approvalKey: result.approvalKey }\n : {}),\n };\n}\n\nfunction createToolHandler(\n toolsByName: ReadonlyMap<string, RealtimeFunctionTool>,\n capabilities: RealtimeToolCapabilityStore,\n options: MountRealtimeVoiceRoutesOptions,\n) {\n return defineEventHandler(async (event: H3Event) => {\n if (getMethod(event) !== \"POST\") return invalidMethod(event);\n if (!isSameOriginRequest(event)) {\n setResponseStatus(event, 403);\n return { error: \"Cross-origin request rejected\" };\n }\n setResponseHeader(event, \"Cache-Control\", \"no-store\");\n\n const auth = await authenticateVoiceRequest(event, options);\n if (!auth) {\n setResponseStatus(event, 401);\n return { error: \"Authentication required\" };\n }\n const capability = resolveRealtimeToolCapability(\n capabilities,\n readSafeHeader(event, REALTIME_VOICE_CAPABILITY_HEADER),\n auth,\n );\n if (!capability) {\n setResponseStatus(event, 403);\n return { error: \"Invalid or expired realtime voice capability\" };\n }\n\n const contentType = readSafeHeader(event, \"content-type\")?.toLowerCase();\n if (!contentType?.includes(\"application/json\")) {\n setResponseStatus(event, 415);\n return { error: \"Expected Content-Type: application/json\" };\n }\n\n const raw = await readLimitedRawBody(\n event,\n REALTIME_VOICE_MAX_TOOL_BODY_BYTES,\n );\n if (raw === \"oversize\") {\n setResponseStatus(event, 413);\n return {\n error: `Tool request is too large (max ${REALTIME_VOICE_MAX_TOOL_BODY_BYTES} bytes)`,\n };\n }\n\n let parsedBody: unknown;\n try {\n parsedBody = JSON.parse(raw ?? \"\");\n } catch {\n setResponseStatus(event, 400);\n return { error: \"Invalid realtime tool request\" };\n }\n const request = parseToolRequest(parsedBody);\n if (!request) {\n setResponseStatus(event, 400);\n return { error: \"Invalid realtime tool request\" };\n }\n if (\n request.browserTabId !== undefined &&\n request.browserTabId !== capability.browserTabId\n ) {\n setResponseStatus(event, 403);\n return { error: \"Realtime voice browser tab mismatch\" };\n }\n if (\n !capability.initialNames.has(request.name) &&\n !capability.names.has(request.name)\n ) {\n setResponseStatus(event, 404);\n return { error: \"Unknown realtime voice tool\" };\n }\n\n const browserTabId = capability.browserTabId;\n const threadId = request.sessionId\n ? `realtime:${request.sessionId}`\n : `realtime:${request.callId}`;\n return runWithRequestContext(\n {\n userEmail: auth.userEmail,\n orgId: auth.orgId,\n timezone: auth.timezone,\n run: {\n threadId,\n ...(browserTabId ? { browserTabId } : {}),\n },\n },\n async () => {\n try {\n const result = normalizeExecutionResult(\n await options.executeTool({\n event,\n userEmail: auth.userEmail,\n orgId: auth.orgId,\n ...request,\n ...(browserTabId ? { browserTabId } : {}),\n }),\n );\n const expandedTools = grantDiscoveredRealtimeTools({\n request,\n result,\n toolsByName,\n initialAllowedNames: capability.initialNames,\n capability,\n });\n return {\n callId: request.callId,\n ...result,\n ...(expandedTools.length > 0 ? { expandedTools } : {}),\n };\n } catch (error) {\n setResponseStatus(event, 500);\n return {\n callId: request.callId,\n status: \"failed\" as const,\n output: truncate(\n sanitizeToolErrorValue(error) || \"Tool execution failed\",\n REALTIME_VOICE_MAX_TOOL_OUTPUT_CHARS,\n ),\n };\n }\n },\n );\n });\n}\n\n/** Mount the authenticated OpenAI Realtime WebRTC and tool bridge routes. */\nexport function mountRealtimeVoiceRoutes(\n nitroApp: any,\n actions: Record<string, ActionEntry>,\n options: MountRealtimeVoiceRoutesOptions,\n): { sessionPath: string; toolPath: string } {\n if (typeof options?.executeTool !== \"function\") {\n throw new Error(\"mountRealtimeVoiceRoutes requires executeTool\");\n }\n\n const tools = buildRealtimeTools(actions);\n const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));\n const capabilities: RealtimeToolCapabilityStore = new Map();\n const app = getH3App(nitroApp);\n app.use(\n REALTIME_VOICE_SESSION_PATH,\n createSessionHandler(tools, capabilities, options),\n );\n app.use(\n REALTIME_VOICE_TOOL_PATH,\n createToolHandler(toolsByName, capabilities, options),\n );\n return {\n sessionPath: REALTIME_VOICE_SESSION_PATH,\n toolPath: REALTIME_VOICE_TOOL_PATH,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"request-origin.d.ts","sourceRoot":"","sources":["../../src/server/request-origin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,IAAI,CAAC;AAMpD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAiD3D"}
1
+ {"version":3,"file":"request-origin.d.ts","sourceRoot":"","sources":["../../src/server/request-origin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,MAAM,IAAI,CAAC;AAMpD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAqD3D"}
@@ -10,6 +10,12 @@ function isLoopbackHost(host) {
10
10
  * back to `Sec-Fetch-Site` so Safari's fetch-spec behavior still works.
11
11
  */
12
12
  export function isSameOriginRequest(event) {
13
+ // Fetch metadata is browser-controlled and describes the relationship
14
+ // before a reverse proxy rewrites Host (dev-lazy maps :8080 to :8088).
15
+ // Reject an explicit cross-site signal before consulting forgeable headers.
16
+ const fetchSite = getRequestHeader(event, "sec-fetch-site");
17
+ if (fetchSite)
18
+ return fetchSite === "same-origin" || fetchSite === "none";
13
19
  const host = getRequestHeader(event, "host");
14
20
  const origin = getRequestHeader(event, "origin");
15
21
  if (origin && host) {
@@ -50,9 +56,6 @@ export function isSameOriginRequest(event) {
50
56
  return false;
51
57
  }
52
58
  }
53
- const fetchSite = getRequestHeader(event, "sec-fetch-site");
54
- if (fetchSite)
55
- return fetchSite === "same-origin" || fetchSite === "none";
56
59
  // No Origin and no Sec-Fetch-Site: likely a non-browser client (curl,
57
60
  // server-side) — safe to allow, CSRF requires a browser with ambient cookies.
58
61
  return true;