@agent-native/core 0.112.0 → 0.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1902) hide show
  1. package/agent-native.eject.json +164 -0
  2. package/corpus/README.md +4 -2
  3. package/corpus/core/CHANGELOG.md +33 -0
  4. package/corpus/core/README.md +61 -174
  5. package/corpus/core/agent-native.eject.json +164 -0
  6. package/corpus/core/docs/AGENTS.md +7 -0
  7. package/corpus/core/docs/content/agent-native-toolkit.mdx +38 -0
  8. package/corpus/core/docs/content/integrations.mdx +63 -2
  9. package/corpus/core/docs/content/package-lifecycle.mdx +54 -4
  10. package/corpus/core/docs/design/provider-integration-authority.md +117 -0
  11. package/corpus/core/package.json +20 -2
  12. package/corpus/core/scripts/materialize-source-corpus.mjs +9 -2
  13. package/corpus/core/src/cli/atomic-json-file.ts +324 -0
  14. package/corpus/core/src/cli/claude-code-participant.ts +515 -0
  15. package/corpus/core/src/cli/code-agent-executor.ts +18 -10
  16. package/corpus/core/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
  17. package/corpus/core/src/cli/code-agent-runs.ts +55 -62
  18. package/corpus/core/src/cli/codex-cli-participant.ts +496 -0
  19. package/corpus/core/src/cli/eject.ts +1594 -0
  20. package/corpus/core/src/cli/index.ts +16 -0
  21. package/corpus/core/src/cli/multi-frontier-runs.ts +1246 -135
  22. package/corpus/core/src/client/chat/ChatHistoryList.tsx +7 -404
  23. package/corpus/core/src/client/index.ts +4 -0
  24. package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +8 -2
  25. package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +7 -2
  26. package/corpus/core/src/client/resources/ResourcesPanel.tsx +17 -3
  27. package/corpus/core/src/client/resources/index.ts +19 -0
  28. package/corpus/core/src/client/resources/mcp-integration-catalog.ts +9 -1
  29. package/corpus/core/src/client/resources/runtime.ts +1 -0
  30. package/corpus/core/src/client/setup-connections/catalog.ts +6 -0
  31. package/corpus/core/src/client/setup-connections/index.ts +1 -0
  32. package/corpus/core/src/client/setup-connections/runtime.ts +1 -0
  33. package/corpus/core/src/connections/catalog.ts +41 -24
  34. package/corpus/core/src/connections/index.ts +1 -0
  35. package/corpus/core/src/connections/runtime.ts +1 -0
  36. package/corpus/core/src/eject/provider-api-definitions.ts +193 -0
  37. package/corpus/core/src/eject/remote-mcp-presets.ts +137 -0
  38. package/corpus/core/src/eject/setup-readiness-ui.tsx +29 -0
  39. package/corpus/core/src/eject/workspace-connections.ts +92 -0
  40. package/corpus/core/src/index.ts +1 -0
  41. package/corpus/core/src/integrations/adapter-overrides.ts +12 -0
  42. package/corpus/core/src/integrations/eject/messaging-adapters.ts +85 -0
  43. package/corpus/core/src/integrations/index.ts +15 -1
  44. package/corpus/core/src/integrations/plugin.ts +34 -12
  45. package/corpus/core/src/integrations/runtime.ts +1 -0
  46. package/corpus/core/src/integrations/slack-oauth.ts +1 -0
  47. package/corpus/core/src/integrations/types.ts +3 -1
  48. package/corpus/core/src/integrations/webhook-delivery.ts +55 -0
  49. package/corpus/core/src/notifications/channels.ts +4 -10
  50. package/corpus/core/src/package-lifecycle/eject-manifest.ts +345 -0
  51. package/corpus/core/src/package-lifecycle/index.ts +1 -0
  52. package/corpus/core/src/provider-api/actions/custom-provider-registration.ts +197 -0
  53. package/corpus/core/src/provider-api/actions/delete-staged-dataset.ts +3 -42
  54. package/corpus/core/src/provider-api/actions/list-staged-datasets.ts +3 -45
  55. package/corpus/core/src/provider-api/actions/provider-api-audit.ts +88 -0
  56. package/corpus/core/src/provider-api/actions/provider-api.ts +460 -0
  57. package/corpus/core/src/provider-api/actions/query-staged-dataset.ts +3 -140
  58. package/corpus/core/src/provider-api/actions/staged-datasets.ts +359 -0
  59. package/corpus/core/src/provider-api/gong.ts +108 -0
  60. package/corpus/core/src/provider-api/index.ts +46 -12
  61. package/corpus/core/src/provider-api/runtime.ts +1 -0
  62. package/corpus/core/src/scripts/docs/source-search.ts +2 -1
  63. package/corpus/core/src/server/google-oauth-credentials.ts +80 -3
  64. package/corpus/core/src/server/index.ts +6 -0
  65. package/corpus/core/src/setup-connections/index.ts +1 -0
  66. package/corpus/core/src/shared/merge-by-id.ts +14 -0
  67. package/corpus/core/src/styles/chat-history-list.css +1 -313
  68. package/corpus/core/src/templates/default/.agents/skills/actions/SKILL.md +32 -12
  69. package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +21 -9
  70. package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  71. package/corpus/core/src/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  72. package/corpus/core/src/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  73. package/corpus/core/src/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  74. package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +14 -2
  75. package/corpus/core/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  76. package/corpus/core/src/templates/default/AGENTS.md +26 -18
  77. package/corpus/core/src/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  78. package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +21 -9
  79. package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  80. package/corpus/core/src/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  81. package/corpus/core/src/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  82. package/corpus/core/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  83. package/corpus/core/src/templates/headless/AGENTS.md +8 -0
  84. package/corpus/core/src/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  85. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +21 -9
  86. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +7 -0
  87. package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  88. package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +14 -2
  89. package/corpus/core/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  90. package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -0
  91. package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -0
  92. package/corpus/core/src/vite/client.ts +25 -2
  93. package/corpus/templates/analytics/.agents/skills/actions/SKILL.md +32 -12
  94. package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  95. package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +14 -2
  96. package/corpus/templates/analytics/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  97. package/corpus/templates/analytics/actions/delete-staged-dataset.ts +3 -23
  98. package/corpus/templates/analytics/actions/list-staged-datasets.ts +3 -27
  99. package/corpus/templates/analytics/actions/provider-api-catalog.ts +16 -19
  100. package/corpus/templates/analytics/actions/provider-api-docs.ts +3 -5
  101. package/corpus/templates/analytics/actions/provider-api-request.ts +162 -185
  102. package/corpus/templates/analytics/actions/query-staged-dataset.ts +3 -47
  103. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +52 -161
  104. package/corpus/templates/assets/.agents/skills/actions/SKILL.md +32 -12
  105. package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  106. package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +14 -2
  107. package/corpus/templates/assets/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  108. package/corpus/templates/assets/app/components/layout/Sidebar.tsx +63 -160
  109. package/corpus/templates/brain/.agents/skills/actions/SKILL.md +32 -12
  110. package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  111. package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +14 -2
  112. package/corpus/templates/brain/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  113. package/corpus/templates/brain/actions/_schemas.ts +13 -7
  114. package/corpus/templates/brain/actions/delete-staged-dataset.ts +3 -24
  115. package/corpus/templates/brain/actions/list-staged-datasets.ts +3 -28
  116. package/corpus/templates/brain/actions/provider-api-catalog.ts +5 -11
  117. package/corpus/templates/brain/actions/provider-api-docs.ts +3 -5
  118. package/corpus/templates/brain/actions/provider-api-request.ts +3 -37
  119. package/corpus/templates/brain/actions/query-staged-dataset.ts +3 -48
  120. package/corpus/templates/brain/actions/remediate-legacy-capture-audiences.ts +167 -0
  121. package/corpus/templates/brain/actions/update-source.ts +5 -1
  122. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +48 -154
  123. package/corpus/templates/brain/app/lib/brain-chat-readiness.ts +6 -0
  124. package/corpus/templates/brain/app/lib/brain.ts +55 -0
  125. package/corpus/templates/brain/app/lib/ingest-handoff.ts +35 -0
  126. package/corpus/templates/brain/app/routes/_index.tsx +8 -0
  127. package/corpus/templates/brain/app/routes.ts +1 -0
  128. package/corpus/templates/brain/changelog/2026-07-19-ask-starts-immediately-when-builder-s-managed-ai-connection-.md +6 -0
  129. package/corpus/templates/brain/changelog/2026-07-19-slack-and-granola-backfills-now-process-captures-concurrentl.md +6 -0
  130. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-can-now-join-configured-public-channels-befo.md +6 -0
  131. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-now-continue-across-the-configured-number-of.md +6 -0
  132. package/corpus/templates/brain/changelog/2026-07-19-slack-backfills-now-start-with-a-safe-four-week-window-and-r.md +6 -0
  133. package/corpus/templates/brain/changelog/2026-07-19-source-review-settings-now-control-knowledge-approval.md +6 -0
  134. package/corpus/templates/brain/changelog/2026-07-19-the-manage-agent-page-now-opens-correctly-from-brain-navigat.md +6 -0
  135. package/corpus/templates/brain/server/db/schema.ts +3 -0
  136. package/corpus/templates/brain/server/lib/brain.ts +41 -2
  137. package/corpus/templates/brain/server/lib/connectors.ts +432 -115
  138. package/corpus/templates/brain/server/lib/meeting-audience.ts +38 -0
  139. package/corpus/templates/brain/server/lib/slack-channel-membership.ts +44 -0
  140. package/corpus/templates/brain/server/plugins/db.ts +10 -0
  141. package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +6 -4
  142. package/corpus/templates/brain/shared/slack-source-config.ts +60 -0
  143. package/corpus/templates/calendar/.agents/skills/actions/SKILL.md +32 -12
  144. package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  145. package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +14 -2
  146. package/corpus/templates/calendar/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  147. package/corpus/templates/calendar/actions/delete-staged-dataset.ts +3 -24
  148. package/corpus/templates/calendar/actions/list-staged-datasets.ts +3 -28
  149. package/corpus/templates/calendar/actions/provider-api-catalog.ts +5 -11
  150. package/corpus/templates/calendar/actions/provider-api-docs.ts +3 -5
  151. package/corpus/templates/calendar/actions/provider-api-request.ts +3 -37
  152. package/corpus/templates/calendar/actions/query-staged-dataset.ts +3 -48
  153. package/corpus/templates/calendar/server/handlers/gong.ts +6 -61
  154. package/corpus/templates/calendar/server/handlers/google-auth.ts +10 -8
  155. package/corpus/templates/calendar/server/lib/google-calendar.ts +7 -45
  156. package/corpus/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  157. package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +21 -9
  158. package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  159. package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +14 -2
  160. package/corpus/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  161. package/corpus/templates/chat/AGENTS.md +6 -2
  162. package/corpus/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  163. package/corpus/templates/clips/.agents/skills/actions/SKILL.md +32 -12
  164. package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  165. package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +14 -2
  166. package/corpus/templates/clips/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  167. package/corpus/templates/clips/AGENTS.md +11 -0
  168. package/corpus/templates/clips/actions/export-to-brain.ts +505 -171
  169. package/corpus/templates/clips/changelog/2026-07-19-ready-clips-transcripts-can-be-backfilled-to-brain-for-a-bou.md +6 -0
  170. package/corpus/templates/clips/server/lib/calendar-event-meetings.ts +1 -1
  171. package/corpus/templates/clips/server/lib/google-calendar-client.ts +12 -22
  172. package/corpus/templates/clips/server/lib/google-calendar-oauth.ts +9 -6
  173. package/corpus/templates/clips/server/lib/slack-oauth.ts +12 -47
  174. package/corpus/templates/clips/server/routes/_agent-native/google/auth-url.get.ts +2 -6
  175. package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +4 -4
  176. package/corpus/templates/content/.agents/skills/actions/SKILL.md +32 -12
  177. package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  178. package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +14 -2
  179. package/corpus/templates/content/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  180. package/corpus/templates/content/actions/delete-staged-dataset.ts +3 -24
  181. package/corpus/templates/content/actions/list-staged-datasets.ts +3 -28
  182. package/corpus/templates/content/actions/provider-api-catalog.ts +5 -11
  183. package/corpus/templates/content/actions/provider-api-docs.ts +3 -5
  184. package/corpus/templates/content/actions/provider-api-request.ts +3 -37
  185. package/corpus/templates/content/actions/query-staged-dataset.ts +3 -48
  186. package/corpus/templates/design/.agents/skills/actions/SKILL.md +32 -12
  187. package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  188. package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +14 -2
  189. package/corpus/templates/design/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  190. package/corpus/templates/design/actions/delete-staged-dataset.ts +4 -23
  191. package/corpus/templates/design/actions/list-staged-datasets.ts +4 -27
  192. package/corpus/templates/design/actions/provider-api-catalog.ts +15 -18
  193. package/corpus/templates/design/actions/provider-api-docs.ts +57 -48
  194. package/corpus/templates/design/actions/provider-api-request.ts +140 -164
  195. package/corpus/templates/design/actions/query-staged-dataset.ts +4 -47
  196. package/corpus/templates/dispatch/.agents/skills/actions/SKILL.md +32 -12
  197. package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  198. package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +14 -2
  199. package/corpus/templates/dispatch/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  200. package/corpus/templates/dispatch/actions/delete-staged-dataset.ts +4 -23
  201. package/corpus/templates/dispatch/actions/list-staged-datasets.ts +4 -30
  202. package/corpus/templates/dispatch/actions/provider-api-catalog.ts +15 -18
  203. package/corpus/templates/dispatch/actions/provider-api-docs.ts +57 -48
  204. package/corpus/templates/dispatch/actions/provider-api-request.ts +138 -163
  205. package/corpus/templates/dispatch/actions/query-staged-dataset.ts +4 -47
  206. package/corpus/templates/forms/.agents/skills/actions/SKILL.md +32 -12
  207. package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  208. package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +14 -2
  209. package/corpus/templates/forms/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  210. package/corpus/templates/forms/server/lib/integrations.ts +23 -22
  211. package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  212. package/corpus/templates/macros/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  213. package/corpus/templates/mail/.agents/skills/actions/SKILL.md +32 -12
  214. package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  215. package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +14 -2
  216. package/corpus/templates/mail/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  217. package/corpus/templates/mail/actions/delete-staged-dataset.ts +4 -23
  218. package/corpus/templates/mail/actions/list-staged-datasets.ts +4 -27
  219. package/corpus/templates/mail/actions/provider-api-catalog.ts +15 -18
  220. package/corpus/templates/mail/actions/provider-api-docs.ts +57 -48
  221. package/corpus/templates/mail/actions/provider-api-request.ts +146 -173
  222. package/corpus/templates/mail/actions/query-staged-dataset.ts +4 -47
  223. package/corpus/templates/mail/server/handlers/gong.ts +6 -61
  224. package/corpus/templates/mail/server/lib/google-auth.ts +10 -13
  225. package/corpus/templates/plan/.agents/skills/actions/SKILL.md +32 -12
  226. package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  227. package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +14 -2
  228. package/corpus/templates/plan/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  229. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +47 -156
  230. package/corpus/templates/slides/.agents/skills/actions/SKILL.md +32 -12
  231. package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  232. package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +14 -2
  233. package/corpus/templates/slides/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  234. package/corpus/templates/slides/actions/delete-staged-dataset.ts +4 -23
  235. package/corpus/templates/slides/actions/list-staged-datasets.ts +4 -27
  236. package/corpus/templates/slides/actions/provider-api-catalog.ts +15 -18
  237. package/corpus/templates/slides/actions/provider-api-docs.ts +57 -48
  238. package/corpus/templates/slides/actions/provider-api-request.ts +145 -172
  239. package/corpus/templates/slides/actions/query-staged-dataset.ts +4 -47
  240. package/corpus/templates/slides/server/lib/google-docs-oauth.ts +11 -36
  241. package/corpus/templates/tasks/.agents/skills/actions/SKILL.md +32 -12
  242. package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +21 -9
  243. package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  244. package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +14 -2
  245. package/corpus/templates/tasks/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  246. package/corpus/toolkit/CHANGELOG.md +131 -0
  247. package/corpus/toolkit/README.md +60 -0
  248. package/corpus/toolkit/agent-native.eject.json +411 -0
  249. package/corpus/toolkit/export-snapshot.json +35 -0
  250. package/corpus/toolkit/migration-manifest.json +4 -0
  251. package/corpus/toolkit/package.json +284 -0
  252. package/corpus/toolkit/scripts/finalize-build.mjs +55 -0
  253. package/corpus/toolkit/src/app-shell/header-actions.tsx +84 -0
  254. package/corpus/toolkit/src/app-shell/index.ts +1 -0
  255. package/corpus/toolkit/src/chat-history/ChatHistoryList.tsx +469 -0
  256. package/corpus/toolkit/src/chat-history/index.ts +7 -0
  257. package/corpus/toolkit/src/chat-history.css +314 -0
  258. package/corpus/toolkit/src/collab-ui/AgentPresenceChip.tsx +69 -0
  259. package/corpus/toolkit/src/collab-ui/LiveCursorOverlay.tsx +241 -0
  260. package/corpus/toolkit/src/collab-ui/PresenceBar.tsx +346 -0
  261. package/corpus/toolkit/src/collab-ui/RecentEditHighlights.tsx +225 -0
  262. package/corpus/toolkit/src/collab-ui/RemoteSelectionRings.tsx +227 -0
  263. package/corpus/toolkit/src/collab-ui/agent-identity.ts +16 -0
  264. package/corpus/toolkit/src/collab-ui/index.ts +39 -0
  265. package/corpus/toolkit/src/collab-ui/lead-client.ts +32 -0
  266. package/corpus/toolkit/src/collab-ui/types.ts +96 -0
  267. package/corpus/toolkit/src/composer/AgentComposerFrame.tsx +59 -0
  268. package/corpus/toolkit/src/composer/ComposerPlusMenu.tsx +983 -0
  269. package/corpus/toolkit/src/composer/MentionPopover.tsx +412 -0
  270. package/corpus/toolkit/src/composer/PastedTextChip.tsx +150 -0
  271. package/corpus/toolkit/src/composer/PromptComposer.tsx +718 -0
  272. package/corpus/toolkit/src/composer/RealtimeVoiceMode.tsx +856 -0
  273. package/corpus/toolkit/src/composer/TiptapComposer.tsx +2936 -0
  274. package/corpus/toolkit/src/composer/VoiceButton.tsx +255 -0
  275. package/corpus/toolkit/src/composer/asset-picker-url.ts +80 -0
  276. package/corpus/toolkit/src/composer/attachment-accept.ts +71 -0
  277. package/corpus/toolkit/src/composer/draft-key.ts +7 -0
  278. package/corpus/toolkit/src/composer/extensions/FileReference.tsx +55 -0
  279. package/corpus/toolkit/src/composer/extensions/MentionReference.tsx +93 -0
  280. package/corpus/toolkit/src/composer/extensions/SkillReference.tsx +56 -0
  281. package/corpus/toolkit/src/composer/index.ts +79 -0
  282. package/corpus/toolkit/src/composer/pasted-text.ts +160 -0
  283. package/corpus/toolkit/src/composer/prompt-attachments.ts +93 -0
  284. package/corpus/toolkit/src/composer/realtime-voice-audio-level.ts +64 -0
  285. package/corpus/toolkit/src/composer/realtime-voice-transcript.ts +134 -0
  286. package/corpus/toolkit/src/composer/runtime-adapters.tsx +343 -0
  287. package/corpus/toolkit/src/composer/types.ts +66 -0
  288. package/corpus/toolkit/src/composer/use-file-search.ts +64 -0
  289. package/corpus/toolkit/src/composer/use-mention-search.ts +90 -0
  290. package/corpus/toolkit/src/composer/use-skills.ts +45 -0
  291. package/corpus/toolkit/src/composer/useRealtimeVoiceMode.tsx +2117 -0
  292. package/corpus/toolkit/src/composer/useVoiceDictation.ts +1191 -0
  293. package/corpus/toolkit/src/context-ui/ContextMeter.tsx +101 -0
  294. package/corpus/toolkit/src/context-ui/ContextSegmentRow.tsx +184 -0
  295. package/corpus/toolkit/src/context-ui/ContextTreemap.tsx +125 -0
  296. package/corpus/toolkit/src/context-ui/ContextXRayPanel.tsx +377 -0
  297. package/corpus/toolkit/src/context-ui/format.ts +42 -0
  298. package/corpus/toolkit/src/context-ui/index.ts +15 -0
  299. package/corpus/toolkit/src/context-ui/types.ts +43 -0
  300. package/corpus/toolkit/src/design-tweaks/index.ts +1 -0
  301. package/corpus/toolkit/src/design-tweaks/visual-style-controls.tsx +1084 -0
  302. package/corpus/toolkit/src/editor/BubbleToolbar.tsx +253 -0
  303. package/corpus/toolkit/src/editor/CodeBlockNode.tsx +254 -0
  304. package/corpus/toolkit/src/editor/DragHandle.ts +1437 -0
  305. package/corpus/toolkit/src/editor/ImageExtension.ts +306 -0
  306. package/corpus/toolkit/src/editor/RegistryBlockContext.tsx +107 -0
  307. package/corpus/toolkit/src/editor/RegistryBlockNode.tsx +652 -0
  308. package/corpus/toolkit/src/editor/RichMarkdownEditor.tsx +81 -0
  309. package/corpus/toolkit/src/editor/RunId.ts +61 -0
  310. package/corpus/toolkit/src/editor/SharedRichEditor.tsx +321 -0
  311. package/corpus/toolkit/src/editor/SlashCommandMenu.tsx +310 -0
  312. package/corpus/toolkit/src/editor/extensions.ts +402 -0
  313. package/corpus/toolkit/src/editor/gfmDoc.ts +92 -0
  314. package/corpus/toolkit/src/editor/index.ts +93 -0
  315. package/corpus/toolkit/src/editor/registrySlashCommands.ts +131 -0
  316. package/corpus/toolkit/src/editor/surgical-apply.ts +192 -0
  317. package/corpus/toolkit/src/editor/useCollabReconcile.ts +589 -0
  318. package/corpus/toolkit/src/editor.css +510 -0
  319. package/corpus/toolkit/src/hooks/index.ts +2 -0
  320. package/corpus/toolkit/src/hooks/use-mobile.tsx +21 -0
  321. package/corpus/toolkit/src/hooks/use-toast.ts +188 -0
  322. package/corpus/toolkit/src/index.ts +8 -0
  323. package/corpus/toolkit/src/onboarding/index.ts +1 -0
  324. package/corpus/toolkit/src/provider.tsx +47 -0
  325. package/corpus/toolkit/src/sharing/VisibilityBadge.tsx +37 -0
  326. package/corpus/toolkit/src/sharing/index.ts +4 -0
  327. package/corpus/toolkit/src/styles.css +21 -0
  328. package/corpus/toolkit/src/ui/accordion.tsx +56 -0
  329. package/corpus/toolkit/src/ui/alert-dialog.tsx +141 -0
  330. package/corpus/toolkit/src/ui/alert.tsx +59 -0
  331. package/corpus/toolkit/src/ui/aspect-ratio.tsx +5 -0
  332. package/corpus/toolkit/src/ui/avatar.tsx +48 -0
  333. package/corpus/toolkit/src/ui/badge.tsx +37 -0
  334. package/corpus/toolkit/src/ui/breadcrumb.tsx +115 -0
  335. package/corpus/toolkit/src/ui/button.tsx +78 -0
  336. package/corpus/toolkit/src/ui/calendar.tsx +214 -0
  337. package/corpus/toolkit/src/ui/card.tsx +86 -0
  338. package/corpus/toolkit/src/ui/carousel.tsx +260 -0
  339. package/corpus/toolkit/src/ui/chart.tsx +375 -0
  340. package/corpus/toolkit/src/ui/checkbox.tsx +28 -0
  341. package/corpus/toolkit/src/ui/collapsible.tsx +9 -0
  342. package/corpus/toolkit/src/ui/command.tsx +174 -0
  343. package/corpus/toolkit/src/ui/context-menu.tsx +202 -0
  344. package/corpus/toolkit/src/ui/date-picker.tsx +64 -0
  345. package/corpus/toolkit/src/ui/dialog.tsx +146 -0
  346. package/corpus/toolkit/src/ui/drawer.tsx +126 -0
  347. package/corpus/toolkit/src/ui/dropdown-menu.tsx +218 -0
  348. package/corpus/toolkit/src/ui/form.tsx +177 -0
  349. package/corpus/toolkit/src/ui/hover-card.tsx +27 -0
  350. package/corpus/toolkit/src/ui/index.ts +52 -0
  351. package/corpus/toolkit/src/ui/input-otp.tsx +69 -0
  352. package/corpus/toolkit/src/ui/input.tsx +22 -0
  353. package/corpus/toolkit/src/ui/label.tsx +24 -0
  354. package/corpus/toolkit/src/ui/logo.tsx +36 -0
  355. package/corpus/toolkit/src/ui/menubar.tsx +235 -0
  356. package/corpus/toolkit/src/ui/navigation-menu.tsx +128 -0
  357. package/corpus/toolkit/src/ui/pagination.tsx +121 -0
  358. package/corpus/toolkit/src/ui/popover.tsx +44 -0
  359. package/corpus/toolkit/src/ui/progress.tsx +26 -0
  360. package/corpus/toolkit/src/ui/radio-group.tsx +42 -0
  361. package/corpus/toolkit/src/ui/resizable.tsx +43 -0
  362. package/corpus/toolkit/src/ui/scroll-area.tsx +46 -0
  363. package/corpus/toolkit/src/ui/select.tsx +158 -0
  364. package/corpus/toolkit/src/ui/separator.tsx +29 -0
  365. package/corpus/toolkit/src/ui/sheet.tsx +160 -0
  366. package/corpus/toolkit/src/ui/sidebar.tsx +777 -0
  367. package/corpus/toolkit/src/ui/skeleton.tsx +18 -0
  368. package/corpus/toolkit/src/ui/slider.tsx +26 -0
  369. package/corpus/toolkit/src/ui/sonner.tsx +58 -0
  370. package/corpus/toolkit/src/ui/spinner.tsx +17 -0
  371. package/corpus/toolkit/src/ui/switch.tsx +27 -0
  372. package/corpus/toolkit/src/ui/table.tsx +117 -0
  373. package/corpus/toolkit/src/ui/tabs.tsx +53 -0
  374. package/corpus/toolkit/src/ui/textarea.tsx +23 -0
  375. package/corpus/toolkit/src/ui/toast.tsx +127 -0
  376. package/corpus/toolkit/src/ui/toaster.tsx +33 -0
  377. package/corpus/toolkit/src/ui/toggle-group.tsx +59 -0
  378. package/corpus/toolkit/src/ui/toggle.tsx +43 -0
  379. package/corpus/toolkit/src/ui/tooltip.tsx +53 -0
  380. package/corpus/toolkit/src/ui/use-toast.ts +3 -0
  381. package/corpus/toolkit/src/utils.ts +8 -0
  382. package/corpus/toolkit/tsconfig.json +23 -0
  383. package/dist/cli/atomic-json-file.d.ts +30 -0
  384. package/dist/cli/atomic-json-file.d.ts.map +1 -0
  385. package/dist/cli/atomic-json-file.js +240 -0
  386. package/dist/cli/atomic-json-file.js.map +1 -0
  387. package/dist/cli/claude-code-participant.d.ts +77 -0
  388. package/dist/cli/claude-code-participant.d.ts.map +1 -0
  389. package/dist/cli/claude-code-participant.js +355 -0
  390. package/dist/cli/claude-code-participant.js.map +1 -0
  391. package/dist/cli/code-agent-executor.d.ts.map +1 -1
  392. package/dist/cli/code-agent-executor.js +18 -10
  393. package/dist/cli/code-agent-executor.js.map +1 -1
  394. package/dist/cli/code-agent-runs.concurrent-worker.d.ts +2 -0
  395. package/dist/cli/code-agent-runs.concurrent-worker.d.ts.map +1 -0
  396. package/dist/cli/code-agent-runs.concurrent-worker.js +32 -0
  397. package/dist/cli/code-agent-runs.concurrent-worker.js.map +1 -0
  398. package/dist/cli/code-agent-runs.d.ts.map +1 -1
  399. package/dist/cli/code-agent-runs.js +43 -56
  400. package/dist/cli/code-agent-runs.js.map +1 -1
  401. package/dist/cli/codex-cli-participant.d.ts +77 -0
  402. package/dist/cli/codex-cli-participant.d.ts.map +1 -0
  403. package/dist/cli/codex-cli-participant.js +354 -0
  404. package/dist/cli/codex-cli-participant.js.map +1 -0
  405. package/dist/cli/eject.d.ts +21 -0
  406. package/dist/cli/eject.d.ts.map +1 -0
  407. package/dist/cli/eject.js +1145 -0
  408. package/dist/cli/eject.js.map +1 -0
  409. package/dist/cli/index.js +15 -0
  410. package/dist/cli/index.js.map +1 -1
  411. package/dist/cli/multi-frontier-runs.d.ts +115 -0
  412. package/dist/cli/multi-frontier-runs.d.ts.map +1 -1
  413. package/dist/cli/multi-frontier-runs.js +831 -113
  414. package/dist/cli/multi-frontier-runs.js.map +1 -1
  415. package/dist/client/chat/ChatHistoryList.d.ts +1 -87
  416. package/dist/client/chat/ChatHistoryList.d.ts.map +1 -1
  417. package/dist/client/chat/ChatHistoryList.js +1 -82
  418. package/dist/client/chat/ChatHistoryList.js.map +1 -1
  419. package/dist/client/index.d.ts +1 -1
  420. package/dist/client/index.d.ts.map +1 -1
  421. package/dist/client/index.js +1 -1
  422. package/dist/client/index.js.map +1 -1
  423. package/dist/client/resources/McpConnectionSuggestion.d.ts +4 -3
  424. package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
  425. package/dist/client/resources/McpConnectionSuggestion.js +3 -3
  426. package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
  427. package/dist/client/resources/McpIntegrationDialog.d.ts +4 -3
  428. package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
  429. package/dist/client/resources/McpIntegrationDialog.js +2 -2
  430. package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
  431. package/dist/client/resources/ResourcesPanel.d.ts +4 -1
  432. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  433. package/dist/client/resources/ResourcesPanel.js +9 -7
  434. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  435. package/dist/client/resources/index.d.ts +3 -0
  436. package/dist/client/resources/index.d.ts.map +1 -1
  437. package/dist/client/resources/index.js +3 -0
  438. package/dist/client/resources/index.js.map +1 -1
  439. package/dist/client/resources/mcp-integration-catalog.d.ts +2 -1
  440. package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
  441. package/dist/client/resources/mcp-integration-catalog.js +6 -2
  442. package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
  443. package/dist/client/resources/runtime.d.ts +2 -0
  444. package/dist/client/resources/runtime.d.ts.map +1 -0
  445. package/dist/client/resources/runtime.js +2 -0
  446. package/dist/client/resources/runtime.js.map +1 -0
  447. package/dist/client/setup-connections/catalog.d.ts +2 -0
  448. package/dist/client/setup-connections/catalog.d.ts.map +1 -0
  449. package/dist/client/setup-connections/catalog.js +7 -0
  450. package/dist/client/setup-connections/catalog.js.map +1 -0
  451. package/dist/client/setup-connections/index.d.ts +1 -0
  452. package/dist/client/setup-connections/index.d.ts.map +1 -1
  453. package/dist/client/setup-connections/index.js +1 -0
  454. package/dist/client/setup-connections/index.js.map +1 -1
  455. package/dist/client/setup-connections/runtime.d.ts +2 -0
  456. package/dist/client/setup-connections/runtime.d.ts.map +1 -0
  457. package/dist/client/setup-connections/runtime.js +2 -0
  458. package/dist/client/setup-connections/runtime.js.map +1 -0
  459. package/dist/collab/awareness.d.ts +2 -2
  460. package/dist/collab/awareness.d.ts.map +1 -1
  461. package/dist/collab/routes.d.ts +1 -1
  462. package/dist/connections/catalog.d.ts +5 -3
  463. package/dist/connections/catalog.d.ts.map +1 -1
  464. package/dist/connections/catalog.js +16 -8
  465. package/dist/connections/catalog.js.map +1 -1
  466. package/dist/connections/index.d.ts +1 -1
  467. package/dist/connections/index.d.ts.map +1 -1
  468. package/dist/connections/index.js +1 -1
  469. package/dist/connections/index.js.map +1 -1
  470. package/dist/connections/runtime.d.ts +2 -0
  471. package/dist/connections/runtime.d.ts.map +1 -0
  472. package/dist/connections/runtime.js +2 -0
  473. package/dist/connections/runtime.js.map +1 -0
  474. package/dist/eject/provider-api-definitions.d.ts +34 -0
  475. package/dist/eject/provider-api-definitions.d.ts.map +1 -0
  476. package/dist/eject/provider-api-definitions.js +88 -0
  477. package/dist/eject/provider-api-definitions.js.map +1 -0
  478. package/dist/eject/remote-mcp-presets.d.ts +17 -0
  479. package/dist/eject/remote-mcp-presets.d.ts.map +1 -0
  480. package/dist/eject/remote-mcp-presets.js +81 -0
  481. package/dist/eject/remote-mcp-presets.js.map +1 -0
  482. package/dist/eject/setup-readiness-ui.d.ts +7 -0
  483. package/dist/eject/setup-readiness-ui.d.ts.map +1 -0
  484. package/dist/eject/setup-readiness-ui.js +13 -0
  485. package/dist/eject/setup-readiness-ui.js.map +1 -0
  486. package/dist/eject/workspace-connections.d.ts +11 -0
  487. package/dist/eject/workspace-connections.d.ts.map +1 -0
  488. package/dist/eject/workspace-connections.js +47 -0
  489. package/dist/eject/workspace-connections.js.map +1 -0
  490. package/dist/index.d.ts +1 -1
  491. package/dist/index.d.ts.map +1 -1
  492. package/dist/index.js +1 -1
  493. package/dist/index.js.map +1 -1
  494. package/dist/integrations/adapter-overrides.d.ts +3 -0
  495. package/dist/integrations/adapter-overrides.d.ts.map +1 -0
  496. package/dist/integrations/adapter-overrides.js +7 -0
  497. package/dist/integrations/adapter-overrides.js.map +1 -0
  498. package/dist/integrations/eject/messaging-adapters.d.ts +12 -0
  499. package/dist/integrations/eject/messaging-adapters.d.ts.map +1 -0
  500. package/dist/integrations/eject/messaging-adapters.js +49 -0
  501. package/dist/integrations/eject/messaging-adapters.js.map +1 -0
  502. package/dist/integrations/index.d.ts +5 -3
  503. package/dist/integrations/index.d.ts.map +1 -1
  504. package/dist/integrations/index.js +4 -2
  505. package/dist/integrations/index.js.map +1 -1
  506. package/dist/integrations/plugin.d.ts +32 -1
  507. package/dist/integrations/plugin.d.ts.map +1 -1
  508. package/dist/integrations/plugin.js +19 -12
  509. package/dist/integrations/plugin.js.map +1 -1
  510. package/dist/integrations/runtime.d.ts +2 -0
  511. package/dist/integrations/runtime.d.ts.map +1 -0
  512. package/dist/integrations/runtime.js +2 -0
  513. package/dist/integrations/runtime.js.map +1 -0
  514. package/dist/integrations/slack-manifest.d.ts +1 -1
  515. package/dist/integrations/slack-oauth.d.ts +1 -1
  516. package/dist/integrations/slack-oauth.d.ts.map +1 -1
  517. package/dist/integrations/slack-oauth.js +1 -0
  518. package/dist/integrations/slack-oauth.js.map +1 -1
  519. package/dist/integrations/types.d.ts +3 -1
  520. package/dist/integrations/types.d.ts.map +1 -1
  521. package/dist/integrations/types.js.map +1 -1
  522. package/dist/integrations/webhook-delivery.d.ts +23 -0
  523. package/dist/integrations/webhook-delivery.d.ts.map +1 -0
  524. package/dist/integrations/webhook-delivery.js +32 -0
  525. package/dist/integrations/webhook-delivery.js.map +1 -0
  526. package/dist/notifications/channels.d.ts.map +1 -1
  527. package/dist/notifications/channels.js +4 -9
  528. package/dist/notifications/channels.js.map +1 -1
  529. package/dist/notifications/routes.d.ts +3 -3
  530. package/dist/package-lifecycle/eject-manifest.d.ts +43 -0
  531. package/dist/package-lifecycle/eject-manifest.d.ts.map +1 -0
  532. package/dist/package-lifecycle/eject-manifest.js +219 -0
  533. package/dist/package-lifecycle/eject-manifest.js.map +1 -0
  534. package/dist/package-lifecycle/index.d.ts +1 -0
  535. package/dist/package-lifecycle/index.d.ts.map +1 -1
  536. package/dist/package-lifecycle/index.js +1 -0
  537. package/dist/package-lifecycle/index.js.map +1 -1
  538. package/dist/progress/routes.d.ts +1 -1
  539. package/dist/provider-api/actions/custom-provider-registration.d.ts +136 -0
  540. package/dist/provider-api/actions/custom-provider-registration.d.ts.map +1 -0
  541. package/dist/provider-api/actions/custom-provider-registration.js +154 -0
  542. package/dist/provider-api/actions/custom-provider-registration.js.map +1 -0
  543. package/dist/provider-api/actions/delete-staged-dataset.d.ts +1 -1
  544. package/dist/provider-api/actions/delete-staged-dataset.d.ts.map +1 -1
  545. package/dist/provider-api/actions/delete-staged-dataset.js +3 -34
  546. package/dist/provider-api/actions/delete-staged-dataset.js.map +1 -1
  547. package/dist/provider-api/actions/list-staged-datasets.d.ts +2 -3
  548. package/dist/provider-api/actions/list-staged-datasets.d.ts.map +1 -1
  549. package/dist/provider-api/actions/list-staged-datasets.js +3 -40
  550. package/dist/provider-api/actions/list-staged-datasets.js.map +1 -1
  551. package/dist/provider-api/actions/provider-api-audit.d.ts +7 -0
  552. package/dist/provider-api/actions/provider-api-audit.d.ts.map +1 -0
  553. package/dist/provider-api/actions/provider-api-audit.js +74 -0
  554. package/dist/provider-api/actions/provider-api-audit.js.map +1 -0
  555. package/dist/provider-api/actions/provider-api.d.ts +370 -0
  556. package/dist/provider-api/actions/provider-api.d.ts.map +1 -0
  557. package/dist/provider-api/actions/provider-api.js +280 -0
  558. package/dist/provider-api/actions/provider-api.js.map +1 -0
  559. package/dist/provider-api/actions/query-staged-dataset.d.ts +1 -1
  560. package/dist/provider-api/actions/query-staged-dataset.d.ts.map +1 -1
  561. package/dist/provider-api/actions/query-staged-dataset.js +3 -116
  562. package/dist/provider-api/actions/query-staged-dataset.js.map +1 -1
  563. package/dist/provider-api/actions/staged-datasets.d.ts +190 -0
  564. package/dist/provider-api/actions/staged-datasets.d.ts.map +1 -0
  565. package/dist/provider-api/actions/staged-datasets.js +210 -0
  566. package/dist/provider-api/actions/staged-datasets.js.map +1 -0
  567. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  568. package/dist/provider-api/gong.d.ts +44 -0
  569. package/dist/provider-api/gong.d.ts.map +1 -0
  570. package/dist/provider-api/gong.js +56 -0
  571. package/dist/provider-api/gong.js.map +1 -0
  572. package/dist/provider-api/index.d.ts +6 -2
  573. package/dist/provider-api/index.d.ts.map +1 -1
  574. package/dist/provider-api/index.js +25 -12
  575. package/dist/provider-api/index.js.map +1 -1
  576. package/dist/provider-api/runtime.d.ts +2 -0
  577. package/dist/provider-api/runtime.d.ts.map +1 -0
  578. package/dist/provider-api/runtime.js +2 -0
  579. package/dist/provider-api/runtime.js.map +1 -0
  580. package/dist/scripts/docs/source-search.d.ts +2 -1
  581. package/dist/scripts/docs/source-search.d.ts.map +1 -1
  582. package/dist/scripts/docs/source-search.js +2 -1
  583. package/dist/scripts/docs/source-search.js.map +1 -1
  584. package/dist/secrets/routes.d.ts +9 -9
  585. package/dist/server/google-oauth-credentials.d.ts +35 -0
  586. package/dist/server/google-oauth-credentials.d.ts.map +1 -1
  587. package/dist/server/google-oauth-credentials.js +48 -2
  588. package/dist/server/google-oauth-credentials.js.map +1 -1
  589. package/dist/server/index.d.ts +1 -1
  590. package/dist/server/index.d.ts.map +1 -1
  591. package/dist/server/index.js +1 -1
  592. package/dist/server/index.js.map +1 -1
  593. package/dist/server/transcribe-voice.d.ts +1 -1
  594. package/dist/setup-connections/index.d.ts +1 -1
  595. package/dist/setup-connections/index.d.ts.map +1 -1
  596. package/dist/setup-connections/index.js +1 -1
  597. package/dist/setup-connections/index.js.map +1 -1
  598. package/dist/shared/merge-by-id.d.ts +5 -0
  599. package/dist/shared/merge-by-id.d.ts.map +1 -0
  600. package/dist/shared/merge-by-id.js +7 -0
  601. package/dist/shared/merge-by-id.js.map +1 -0
  602. package/dist/styles/chat-history-list.css +1 -313
  603. package/dist/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  604. package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +21 -9
  605. package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  606. package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +14 -2
  607. package/dist/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  608. package/dist/templates/chat/AGENTS.md +6 -2
  609. package/dist/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  610. package/dist/templates/default/.agents/skills/actions/SKILL.md +32 -12
  611. package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +21 -9
  612. package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  613. package/dist/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  614. package/dist/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  615. package/dist/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  616. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +14 -2
  617. package/dist/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  618. package/dist/templates/default/AGENTS.md +26 -18
  619. package/dist/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  620. package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +21 -9
  621. package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  622. package/dist/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  623. package/dist/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  624. package/dist/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  625. package/dist/templates/headless/AGENTS.md +8 -0
  626. package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  627. package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +21 -9
  628. package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +7 -0
  629. package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  630. package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +14 -2
  631. package/dist/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  632. package/dist/templates/workspace-core/AGENTS.md +4 -0
  633. package/dist/templates/workspace-root/AGENTS.md +4 -0
  634. package/dist/vite/client.d.ts.map +1 -1
  635. package/dist/vite/client.js +22 -2
  636. package/dist/vite/client.js.map +1 -1
  637. package/docs/AGENTS.md +7 -0
  638. package/docs/content/agent-native-toolkit.mdx +38 -0
  639. package/docs/content/integrations.mdx +63 -2
  640. package/docs/content/package-lifecycle.mdx +54 -4
  641. package/docs/design/provider-integration-authority.md +117 -0
  642. package/package.json +20 -2
  643. package/src/a2a/agent-card.ts +83 -0
  644. package/src/a2a/artifact-response.ts +1648 -0
  645. package/src/a2a/auth-policy.ts +66 -0
  646. package/src/a2a/caller-auth.ts +102 -0
  647. package/src/a2a/client.ts +876 -0
  648. package/src/a2a/correlation.ts +50 -0
  649. package/src/a2a/handlers.ts +1285 -0
  650. package/src/a2a/index.ts +50 -0
  651. package/src/a2a/invoke.ts +348 -0
  652. package/src/a2a/response-text.ts +53 -0
  653. package/src/a2a/server.ts +586 -0
  654. package/src/a2a/task-store.ts +917 -0
  655. package/src/a2a/types.ts +221 -0
  656. package/src/a2a-claims.ts +52 -0
  657. package/src/action-change-marker.ts +74 -0
  658. package/src/action-ui.ts +38 -0
  659. package/src/action.ts +1406 -0
  660. package/src/adapters/cli/index.ts +6 -0
  661. package/src/adapters/cli/registry.ts +73 -0
  662. package/src/adapters/cli/shell-adapter.ts +92 -0
  663. package/src/adapters/cli/types.ts +27 -0
  664. package/src/agent/action-continuation-guidance.ts +38 -0
  665. package/src/agent/app-model-defaults.ts +201 -0
  666. package/src/agent/context-xray/actions/context-evict.ts +56 -0
  667. package/src/agent/context-xray/actions/context-manifest-get.ts +75 -0
  668. package/src/agent/context-xray/actions/context-pin.ts +56 -0
  669. package/src/agent/context-xray/actions/context-preview-get.ts +134 -0
  670. package/src/agent/context-xray/actions/context-report.ts +75 -0
  671. package/src/agent/context-xray/actions/context-restore.ts +51 -0
  672. package/src/agent/context-xray/actions/errors.ts +40 -0
  673. package/src/agent/context-xray/apply-directives.ts +137 -0
  674. package/src/agent/context-xray/directives-store.ts +178 -0
  675. package/src/agent/context-xray/identity.ts +37 -0
  676. package/src/agent/context-xray/manifest.ts +284 -0
  677. package/src/agent/context-xray/migrations.ts +32 -0
  678. package/src/agent/context-xray/plugin.ts +23 -0
  679. package/src/agent/context-xray/schema.ts +17 -0
  680. package/src/agent/context-xray/segments.ts +194 -0
  681. package/src/agent/context-xray/tokenize.ts +93 -0
  682. package/src/agent/default-model.ts +5 -0
  683. package/src/agent/durable-background.ts +547 -0
  684. package/src/agent/engine/ai-sdk-engine.ts +565 -0
  685. package/src/agent/engine/anthropic-engine.ts +320 -0
  686. package/src/agent/engine/builder-engine.ts +1110 -0
  687. package/src/agent/engine/builder-gateway-headers.ts +44 -0
  688. package/src/agent/engine/builtin.ts +122 -0
  689. package/src/agent/engine/context-directives-transform.ts +73 -0
  690. package/src/agent/engine/continuation-dispatch-retry.ts +168 -0
  691. package/src/agent/engine/credential-errors.ts +69 -0
  692. package/src/agent/engine/index.ts +54 -0
  693. package/src/agent/engine/openai-compatible-endpoint.ts +25 -0
  694. package/src/agent/engine/output-tokens.ts +181 -0
  695. package/src/agent/engine/provider-env-vars.ts +69 -0
  696. package/src/agent/engine/registry.ts +853 -0
  697. package/src/agent/engine/tool-call-journal-seed.ts +85 -0
  698. package/src/agent/engine/translate-ai-sdk.ts +407 -0
  699. package/src/agent/engine/translate-anthropic.ts +611 -0
  700. package/src/agent/engine/types.ts +310 -0
  701. package/src/agent/harness/acp-adapter.ts +893 -0
  702. package/src/agent/harness/acp-builtin.ts +70 -0
  703. package/src/agent/harness/ai-sdk-adapter.ts +509 -0
  704. package/src/agent/harness/background.ts +365 -0
  705. package/src/agent/harness/builtin.ts +50 -0
  706. package/src/agent/harness/index.ts +86 -0
  707. package/src/agent/harness/lifecycle.ts +498 -0
  708. package/src/agent/harness/registry.ts +97 -0
  709. package/src/agent/harness/runner.ts +182 -0
  710. package/src/agent/harness/store.ts +466 -0
  711. package/src/agent/harness/translate.ts +130 -0
  712. package/src/agent/harness/types.ts +129 -0
  713. package/src/agent/index.ts +32 -0
  714. package/src/agent/loop-settings.ts +186 -0
  715. package/src/agent/model-config.ts +363 -0
  716. package/src/agent/observational-memory/compactor.ts +78 -0
  717. package/src/agent/observational-memory/config.ts +78 -0
  718. package/src/agent/observational-memory/index.ts +79 -0
  719. package/src/agent/observational-memory/internal-run.ts +89 -0
  720. package/src/agent/observational-memory/message-text.ts +49 -0
  721. package/src/agent/observational-memory/migrations.ts +44 -0
  722. package/src/agent/observational-memory/observer.ts +128 -0
  723. package/src/agent/observational-memory/plugin.ts +35 -0
  724. package/src/agent/observational-memory/prompts.ts +53 -0
  725. package/src/agent/observational-memory/read.ts +131 -0
  726. package/src/agent/observational-memory/reflector.ts +119 -0
  727. package/src/agent/observational-memory/schema.ts +48 -0
  728. package/src/agent/observational-memory/store.ts +275 -0
  729. package/src/agent/observational-memory/types.ts +65 -0
  730. package/src/agent/processors.ts +209 -0
  731. package/src/agent/production-agent.ts +8254 -0
  732. package/src/agent/run-loop-with-resume.ts +394 -0
  733. package/src/agent/run-manager.ts +1825 -0
  734. package/src/agent/run-ownership.ts +75 -0
  735. package/src/agent/run-store.ts +2601 -0
  736. package/src/agent/runtime-context.ts +169 -0
  737. package/src/agent/thread-data-builder.ts +1584 -0
  738. package/src/agent/tool-call-journal.ts +368 -0
  739. package/src/agent/tool-error-redaction.ts +52 -0
  740. package/src/agent/tool-result-images.ts +178 -0
  741. package/src/agent/tool-search.ts +376 -0
  742. package/src/agent/types.ts +372 -0
  743. package/src/agent-native/index.ts +198 -0
  744. package/src/agent-web/config.ts +253 -0
  745. package/src/agent-web/generator.ts +382 -0
  746. package/src/agent-web/index.ts +36 -0
  747. package/src/appearance/actions/change-appearance.ts +35 -0
  748. package/src/application-state/emitter.ts +81 -0
  749. package/src/application-state/handlers.ts +121 -0
  750. package/src/application-state/index.ts +44 -0
  751. package/src/application-state/script-helpers.ts +155 -0
  752. package/src/application-state/store.ts +274 -0
  753. package/src/assets/branding/agent-native.icon/Assets/background.svg +3 -0
  754. package/src/assets/branding/agent-native.icon/Assets/foreground.svg +12 -0
  755. package/src/assets/branding/agent-native.icon/icon.json +49 -0
  756. package/src/assets/branding/favicon.png +0 -0
  757. package/src/assets/branding/favicon.svg +1 -0
  758. package/src/assets/branding/icon-on-dark.svg +10 -0
  759. package/src/assets/branding/icon-on-light.svg +10 -0
  760. package/src/assets/branding/mac-app-icon.svg +1 -0
  761. package/src/assets/branding/slack-bot/agent-native-1024.png +0 -0
  762. package/src/assets/branding/slack-bot/agent-native-512.png +0 -0
  763. package/src/assets/branding/tray-icon.svg +6 -0
  764. package/src/assets/branding/wordmark-on-dark.svg +21 -0
  765. package/src/assets/branding/wordmark-on-light.svg +21 -0
  766. package/src/assets/fonts/LICENSE_LIBERATION +96 -0
  767. package/src/assets/fonts/LICENSE_NOTO_NASKH_ARABIC +93 -0
  768. package/src/assets/fonts/LiberationSans-Bold.ttf +0 -0
  769. package/src/assets/fonts/LiberationSans-Regular.ttf +0 -0
  770. package/src/assets/fonts/NotoNaskhArabic-Variable.ttf +0 -0
  771. package/src/audit/actions/export-audit-events.ts +162 -0
  772. package/src/audit/actions/get-audit-event.ts +24 -0
  773. package/src/audit/actions/list-audit-events.ts +66 -0
  774. package/src/audit/cleanup-job.ts +100 -0
  775. package/src/audit/config.ts +90 -0
  776. package/src/audit/index.ts +43 -0
  777. package/src/audit/record.ts +180 -0
  778. package/src/audit/redact.ts +109 -0
  779. package/src/audit/store.ts +346 -0
  780. package/src/audit/types.ts +141 -0
  781. package/src/automation/index.ts +802 -0
  782. package/src/brand-kit/brand-signals.ts +124 -0
  783. package/src/brand-kit/fig/index.ts +64 -0
  784. package/src/brand-kit/index.ts +72 -0
  785. package/src/brand-kit/types.ts +113 -0
  786. package/src/browser-sessions/actions.ts +302 -0
  787. package/src/browser-sessions/routes.ts +234 -0
  788. package/src/browser-sessions/store.ts +679 -0
  789. package/src/browser-sessions/types.ts +84 -0
  790. package/src/changelog/parse.ts +328 -0
  791. package/src/chat-threads/emitter.ts +22 -0
  792. package/src/chat-threads/schema.ts +43 -0
  793. package/src/chat-threads/store.ts +1311 -0
  794. package/src/checkpoints/index.ts +15 -0
  795. package/src/checkpoints/service.ts +142 -0
  796. package/src/checkpoints/store.ts +153 -0
  797. package/src/cli/add.ts +425 -0
  798. package/src/cli/agent.ts +424 -0
  799. package/src/cli/agents.ts +122 -0
  800. package/src/cli/app-skill.ts +1455 -0
  801. package/src/cli/atomic-json-file.ts +324 -0
  802. package/src/cli/audit-agent-web.ts +324 -0
  803. package/src/cli/changelog.ts +199 -0
  804. package/src/cli/claude-code-participant.ts +515 -0
  805. package/src/cli/code-agent-commands.ts +270 -0
  806. package/src/cli/code-agent-connector.ts +1109 -0
  807. package/src/cli/code-agent-executor.ts +1970 -0
  808. package/src/cli/code-agent-output-smoother.ts +140 -0
  809. package/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
  810. package/src/cli/code-agent-runs.ts +548 -0
  811. package/src/cli/code.ts +1805 -0
  812. package/src/cli/codex-cli-participant.ts +496 -0
  813. package/src/cli/connect.ts +2714 -0
  814. package/src/cli/content-local.ts +442 -0
  815. package/src/cli/context-xray-local.ts +2193 -0
  816. package/src/cli/create-workspace.ts +30 -0
  817. package/src/cli/create.ts +2247 -0
  818. package/src/cli/deploy-build.ts +50 -0
  819. package/src/cli/design-connect.ts +3187 -0
  820. package/src/cli/doctor.ts +472 -0
  821. package/src/cli/eject.ts +1594 -0
  822. package/src/cli/eval.ts +134 -0
  823. package/src/cli/gateway-helpers.ts +70 -0
  824. package/src/cli/index.ts +1217 -0
  825. package/src/cli/info.ts +105 -0
  826. package/src/cli/invoke.ts +288 -0
  827. package/src/cli/mcp-config-writers.ts +857 -0
  828. package/src/cli/mcp.ts +594 -0
  829. package/src/cli/migrate.ts +1813 -0
  830. package/src/cli/migration-codemod.ts +646 -0
  831. package/src/cli/multi-frontier-runs.ts +1952 -0
  832. package/src/cli/package-lifecycle.ts +823 -0
  833. package/src/cli/plan-blocks.ts +143 -0
  834. package/src/cli/plan-local.ts +3189 -0
  835. package/src/cli/plan-publish-store.ts +138 -0
  836. package/src/cli/pr-visual-recap-workflow.ts +2 -0
  837. package/src/cli/recap.ts +5 -0
  838. package/src/cli/setup-agents.ts +120 -0
  839. package/src/cli/skills-content/assets-skill.ts +83 -0
  840. package/src/cli/skills-content/canvas.ts +153 -0
  841. package/src/cli/skills-content/connection.ts +52 -0
  842. package/src/cli/skills-content/content-skill.ts +120 -0
  843. package/src/cli/skills-content/design-exploration-skill.ts +118 -0
  844. package/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
  845. package/src/cli/skills-content/document-quality.ts +196 -0
  846. package/src/cli/skills-content/exemplar.ts +69 -0
  847. package/src/cli/skills-content/help.ts +77 -0
  848. package/src/cli/skills-content/index.ts +22 -0
  849. package/src/cli/skills-content/local-files.ts +100 -0
  850. package/src/cli/skills-content/plan-setup-auth.ts +80 -0
  851. package/src/cli/skills-content/visual-plan-skill.ts +493 -0
  852. package/src/cli/skills-content/visual-recap-skill.ts +553 -0
  853. package/src/cli/skills-content/visualize-repo-skill.ts +93 -0
  854. package/src/cli/skills-content/wireframe.ts +349 -0
  855. package/src/cli/skills.ts +4340 -0
  856. package/src/cli/sync-builder-starter-manifest.ts +631 -0
  857. package/src/cli/telemetry.ts +136 -0
  858. package/src/cli/templates-meta.ts +269 -0
  859. package/src/cli/upgrade.ts +956 -0
  860. package/src/cli/visualize-repo.ts +715 -0
  861. package/src/cli/workspace-dev.ts +1486 -0
  862. package/src/cli/workspacify.ts +258 -0
  863. package/src/client/AgentAskPopover.tsx +89 -0
  864. package/src/client/AgentChatHome.tsx +66 -0
  865. package/src/client/AgentNative.tsx +161 -0
  866. package/src/client/AgentNativeEmbedded.tsx +288 -0
  867. package/src/client/AgentNativeFrame.tsx +151 -0
  868. package/src/client/AgentPanel.tsx +3437 -0
  869. package/src/client/AgentTaskCard.tsx +273 -0
  870. package/src/client/AppearancePicker.tsx +79 -0
  871. package/src/client/AssistantChat.tsx +5793 -0
  872. package/src/client/ClientOnly.tsx +22 -0
  873. package/src/client/CommandMenu.tsx +726 -0
  874. package/src/client/ConnectBuilderCard.tsx +390 -0
  875. package/src/client/DefaultSpinner.tsx +47 -0
  876. package/src/client/ErrorBoundary.tsx +359 -0
  877. package/src/client/ErrorReportActions.tsx +69 -0
  878. package/src/client/FeedbackButton.tsx +553 -0
  879. package/src/client/HighlightedCodeBlock.tsx +173 -0
  880. package/src/client/IframeEmbed.tsx +151 -0
  881. package/src/client/KeepTabOpenNotice.tsx +181 -0
  882. package/src/client/MultiTabAssistantChat.tsx +2576 -0
  883. package/src/client/NewWorkspaceAppFlow.tsx +525 -0
  884. package/src/client/PoweredByBadge.tsx +284 -0
  885. package/src/client/RunStuckBanner.tsx +431 -0
  886. package/src/client/StarfieldBackground.tsx +466 -0
  887. package/src/client/Turnstile.tsx +125 -0
  888. package/src/client/active-run-state.ts +139 -0
  889. package/src/client/agent-chat/index.ts +279 -0
  890. package/src/client/agent-chat-adapter.ts +3692 -0
  891. package/src/client/agent-chat.ts +1233 -0
  892. package/src/client/agent-engine-key.ts +122 -0
  893. package/src/client/agent-page/AgentContextTab.tsx +487 -0
  894. package/src/client/agent-page/AgentEmptyState.tsx +44 -0
  895. package/src/client/agent-page/AgentJobsTab.tsx +441 -0
  896. package/src/client/agent-page/AgentTabFrame.tsx +39 -0
  897. package/src/client/agent-page/AgentTabsPage.tsx +1096 -0
  898. package/src/client/agent-page/types.ts +18 -0
  899. package/src/client/agent-page/use-jobs.ts +150 -0
  900. package/src/client/agent-sidebar-state.ts +166 -0
  901. package/src/client/analytics/index.ts +40 -0
  902. package/src/client/analytics-session.ts +70 -0
  903. package/src/client/analytics.ts +1757 -0
  904. package/src/client/api-path.ts +124 -0
  905. package/src/client/app-providers.tsx +230 -0
  906. package/src/client/appearance.ts +130 -0
  907. package/src/client/application-state.ts +154 -0
  908. package/src/client/assistant-ui-recovery.tsx +205 -0
  909. package/src/client/automation/index.ts +4 -0
  910. package/src/client/automation.ts +22 -0
  911. package/src/client/blocks/AiEditableField.tsx +30 -0
  912. package/src/client/blocks/BlockView.tsx +145 -0
  913. package/src/client/blocks/RegistryBlockDataProvider.tsx +121 -0
  914. package/src/client/blocks/SchemaBlockEditor.tsx +457 -0
  915. package/src/client/blocks/agent.ts +95 -0
  916. package/src/client/blocks/code-block-direction.ts +21 -0
  917. package/src/client/blocks/index.ts +308 -0
  918. package/src/client/blocks/library/AnnotatedCodeBlock.tsx +710 -0
  919. package/src/client/blocks/library/ApiEndpointBlock.tsx +1120 -0
  920. package/src/client/blocks/library/DataModelBlock.tsx +775 -0
  921. package/src/client/blocks/library/DiffBlock.tsx +1854 -0
  922. package/src/client/blocks/library/FileTreeBlock.tsx +868 -0
  923. package/src/client/blocks/library/HighlightedCode.tsx +260 -0
  924. package/src/client/blocks/library/JsonExplorerBlock.tsx +608 -0
  925. package/src/client/blocks/library/MermaidBlock.tsx +362 -0
  926. package/src/client/blocks/library/OpenApiSpecBlock.tsx +998 -0
  927. package/src/client/blocks/library/annotated-code.config.ts +101 -0
  928. package/src/client/blocks/library/annotation-rail.tsx +1020 -0
  929. package/src/client/blocks/library/api-endpoint.config.ts +207 -0
  930. package/src/client/blocks/library/block-copy.ts +399 -0
  931. package/src/client/blocks/library/callout.config.ts +57 -0
  932. package/src/client/blocks/library/callout.tsx +149 -0
  933. package/src/client/blocks/library/checklist.config.ts +56 -0
  934. package/src/client/blocks/library/checklist.tsx +208 -0
  935. package/src/client/blocks/library/code-filename-label.tsx +59 -0
  936. package/src/client/blocks/library/code-highlight.tsx +178 -0
  937. package/src/client/blocks/library/code-tabs.config.ts +70 -0
  938. package/src/client/blocks/library/code-tabs.tsx +606 -0
  939. package/src/client/blocks/library/code.config.ts +69 -0
  940. package/src/client/blocks/library/code.tsx +440 -0
  941. package/src/client/blocks/library/columns.config.ts +85 -0
  942. package/src/client/blocks/library/columns.tsx +334 -0
  943. package/src/client/blocks/library/data-model.config.ts +152 -0
  944. package/src/client/blocks/library/dev-doc-ui.tsx +191 -0
  945. package/src/client/blocks/library/diagram.config.ts +222 -0
  946. package/src/client/blocks/library/diagram.tsx +958 -0
  947. package/src/client/blocks/library/diff.config.ts +115 -0
  948. package/src/client/blocks/library/file-tree.config.ts +92 -0
  949. package/src/client/blocks/library/html.config.ts +79 -0
  950. package/src/client/blocks/library/html.tsx +258 -0
  951. package/src/client/blocks/library/json-explorer.config.ts +74 -0
  952. package/src/client/blocks/library/mermaid.config.ts +49 -0
  953. package/src/client/blocks/library/narrow-container.tsx +37 -0
  954. package/src/client/blocks/library/openapi-spec.config.ts +66 -0
  955. package/src/client/blocks/library/question-form.config.ts +127 -0
  956. package/src/client/blocks/library/question-form.tsx +944 -0
  957. package/src/client/blocks/library/sanitize-html.ts +343 -0
  958. package/src/client/blocks/library/server-specs.ts +338 -0
  959. package/src/client/blocks/library/specs.tsx +308 -0
  960. package/src/client/blocks/library/table.config.ts +61 -0
  961. package/src/client/blocks/library/table.tsx +449 -0
  962. package/src/client/blocks/library/tabs.config.ts +96 -0
  963. package/src/client/blocks/library/tabs.tsx +665 -0
  964. package/src/client/blocks/library/wireframe-icons.ts +210 -0
  965. package/src/client/blocks/library/wireframe-kit.tsx +1850 -0
  966. package/src/client/blocks/library/wireframe.config.ts +539 -0
  967. package/src/client/blocks/library/wireframe.tsx +535 -0
  968. package/src/client/blocks/mdx.ts +364 -0
  969. package/src/client/blocks/provider.tsx +51 -0
  970. package/src/client/blocks/registry.ts +83 -0
  971. package/src/client/blocks/schema-form/introspect.ts +201 -0
  972. package/src/client/blocks/server.ts +170 -0
  973. package/src/client/blocks/types.ts +415 -0
  974. package/src/client/browser-session-bridge.ts +548 -0
  975. package/src/client/browser-tab-id.ts +36 -0
  976. package/src/client/builder-frame.ts +194 -0
  977. package/src/client/builder-mark.tsx +21 -0
  978. package/src/client/changelog/Changelog.tsx +333 -0
  979. package/src/client/changelog/index.ts +1 -0
  980. package/src/client/chat/ChatHistoryList.tsx +7 -0
  981. package/src/client/chat/attachment-adapters.ts +426 -0
  982. package/src/client/chat/connectors.ts +1579 -0
  983. package/src/client/chat/index.ts +160 -0
  984. package/src/client/chat/markdown-renderer.tsx +693 -0
  985. package/src/client/chat/message-components.tsx +1326 -0
  986. package/src/client/chat/repo-helpers.ts +281 -0
  987. package/src/client/chat/run-recovery.tsx +994 -0
  988. package/src/client/chat/runtime.ts +1810 -0
  989. package/src/client/chat/tool-call-display.tsx +1270 -0
  990. package/src/client/chat/tool-render-registry.tsx +144 -0
  991. package/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
  992. package/src/client/chat/use-reconnect-reader-owner.ts +28 -0
  993. package/src/client/chat/widgets/DataChartRenderer.tsx +242 -0
  994. package/src/client/chat/widgets/DataChartWidget.tsx +51 -0
  995. package/src/client/chat/widgets/DataInsightsWidget.tsx +59 -0
  996. package/src/client/chat/widgets/DataTableWidget.tsx +240 -0
  997. package/src/client/chat/widgets/InlineExtensionWidget.tsx +60 -0
  998. package/src/client/chat/widgets/builtin-tool-renderers.tsx +213 -0
  999. package/src/client/chat/widgets/data-widget-types.ts +1 -0
  1000. package/src/client/chat/widgets/inline-extension-result.ts +86 -0
  1001. package/src/client/chat-model-groups.ts +171 -0
  1002. package/src/client/chat-thread-url.ts +11 -0
  1003. package/src/client/chat-view-transition.ts +213 -0
  1004. package/src/client/client-action.ts +21 -0
  1005. package/src/client/client-bootstrap.ts +7 -0
  1006. package/src/client/client-surface.ts +41 -0
  1007. package/src/client/clipboard.ts +89 -0
  1008. package/src/client/code-agent-chat-adapter.ts +537 -0
  1009. package/src/client/collab/index.ts +60 -0
  1010. package/src/client/command-navigation/index.ts +15 -0
  1011. package/src/client/comments-review/index.ts +1 -0
  1012. package/src/client/components/AgentPresenceChip.tsx +4 -0
  1013. package/src/client/components/ApiKeySettings.tsx +309 -0
  1014. package/src/client/components/CodeAgentIndicator.tsx +59 -0
  1015. package/src/client/components/CodeRequiredDialog.tsx +470 -0
  1016. package/src/client/components/LiveCursorOverlay.tsx +5 -0
  1017. package/src/client/components/MissingKeyCard.tsx +61 -0
  1018. package/src/client/components/PresenceBar.tsx +4 -0
  1019. package/src/client/components/RecentEditHighlights.tsx +4 -0
  1020. package/src/client/components/RemoteSelectionRings.tsx +5 -0
  1021. package/src/client/components/icons/AgentNativeIcon.tsx +46 -0
  1022. package/src/client/components/ui/dialog.tsx +1 -0
  1023. package/src/client/components/ui/dropdown-menu.tsx +1 -0
  1024. package/src/client/components/ui/hover-card.tsx +1 -0
  1025. package/src/client/components/ui/message-scroller.tsx +131 -0
  1026. package/src/client/components/ui/popover.tsx +1 -0
  1027. package/src/client/components/ui/sheet.tsx +1 -0
  1028. package/src/client/components/ui/tooltip.tsx +1 -0
  1029. package/src/client/composer/index.ts +11 -0
  1030. package/src/client/composer/runtime-adapters.tsx +123 -0
  1031. package/src/client/composer/use-mention-search.ts +7 -0
  1032. package/src/client/composer/wired-components.tsx +53 -0
  1033. package/src/client/context-xray/ContextMeter.tsx +124 -0
  1034. package/src/client/context-xray/ContextSegmentRow.tsx +27 -0
  1035. package/src/client/context-xray/ContextTreemap.tsx +24 -0
  1036. package/src/client/context-xray/ContextXRayPanel.tsx +59 -0
  1037. package/src/client/context-xray/SegmentProvenancePopover.tsx +18 -0
  1038. package/src/client/context-xray/format.ts +27 -0
  1039. package/src/client/conversation/AgentConversation.tsx +555 -0
  1040. package/src/client/conversation/code-agent-transcript.ts +283 -0
  1041. package/src/client/conversation/index.ts +22 -0
  1042. package/src/client/conversation/types.ts +85 -0
  1043. package/src/client/conversation/use-near-bottom-autoscroll.ts +278 -0
  1044. package/src/client/create-query-client.ts +86 -0
  1045. package/src/client/db-admin/DataGrid.tsx +551 -0
  1046. package/src/client/db-admin/DbAdminPage.tsx +218 -0
  1047. package/src/client/db-admin/DevDatabaseLink.tsx +16 -0
  1048. package/src/client/db-admin/EditableCell.tsx +451 -0
  1049. package/src/client/db-admin/FilterBar.tsx +203 -0
  1050. package/src/client/db-admin/ResultsGrid.tsx +114 -0
  1051. package/src/client/db-admin/RowSidePanel.tsx +337 -0
  1052. package/src/client/db-admin/SqlEditor.tsx +840 -0
  1053. package/src/client/db-admin/TableBrowser.tsx +212 -0
  1054. package/src/client/db-admin/TableEditor.tsx +760 -0
  1055. package/src/client/db-admin/cell-format.ts +246 -0
  1056. package/src/client/db-admin/changeset.ts +296 -0
  1057. package/src/client/db-admin/export-utils.ts +78 -0
  1058. package/src/client/db-admin/index.ts +33 -0
  1059. package/src/client/db-admin/sql-storage.ts +134 -0
  1060. package/src/client/db-admin/storage.ts +68 -0
  1061. package/src/client/db-admin/useAgentSync.ts +226 -0
  1062. package/src/client/db-admin/useDbAdmin.ts +294 -0
  1063. package/src/client/dev-overlay/DevOverlay.tsx +576 -0
  1064. package/src/client/dev-overlay/builtins.ts +40 -0
  1065. package/src/client/dev-overlay/index.ts +23 -0
  1066. package/src/client/dev-overlay/registry.ts +67 -0
  1067. package/src/client/dev-overlay/types.ts +64 -0
  1068. package/src/client/dev-overlay/use-dev-option.ts +78 -0
  1069. package/src/client/dev-overlay/use-dev-overlay-shortcut.ts +31 -0
  1070. package/src/client/dynamic-suggestions.ts +455 -0
  1071. package/src/client/embed-auth.ts +544 -0
  1072. package/src/client/embed.ts +54 -0
  1073. package/src/client/error-capture.ts +690 -0
  1074. package/src/client/error-format.ts +211 -0
  1075. package/src/client/error-reporting.ts +100 -0
  1076. package/src/client/extensions/AgentNativeExtensionFrame.e2e-host.tsx +136 -0
  1077. package/src/client/extensions/AgentNativeExtensionFrame.tsx +708 -0
  1078. package/src/client/extensions/EmbeddedExtension.tsx +604 -0
  1079. package/src/client/extensions/ExtensionEditor.tsx +450 -0
  1080. package/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
  1081. package/src/client/extensions/ExtensionSlot.tsx +345 -0
  1082. package/src/client/extensions/ExtensionViewer.tsx +1502 -0
  1083. package/src/client/extensions/ExtensionViewerPage.tsx +32 -0
  1084. package/src/client/extensions/ExtensionsListPage.tsx +432 -0
  1085. package/src/client/extensions/ExtensionsSidebarSection.tsx +1259 -0
  1086. package/src/client/extensions/InlineExtensionFrame.tsx +660 -0
  1087. package/src/client/extensions/agent-native-extension-runtime.ts +495 -0
  1088. package/src/client/extensions/delete-extension.ts +76 -0
  1089. package/src/client/extensions/extension-load-error.ts +26 -0
  1090. package/src/client/extensions/extension-order.ts +49 -0
  1091. package/src/client/extensions/extension-popularity.ts +61 -0
  1092. package/src/client/extensions/iframe-bridge.ts +377 -0
  1093. package/src/client/extensions/index.ts +84 -0
  1094. package/src/client/extensions/portable-extension.ts +712 -0
  1095. package/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
  1096. package/src/client/feature-flags/helpers.ts +77 -0
  1097. package/src/client/feature-flags/index.ts +13 -0
  1098. package/src/client/feature-flags/types.ts +29 -0
  1099. package/src/client/feature-flags/use-feature-flag.ts +26 -0
  1100. package/src/client/feedback-context.ts +90 -0
  1101. package/src/client/frame-protocol.ts +168 -0
  1102. package/src/client/frame.ts +329 -0
  1103. package/src/client/guided-questions.tsx +1152 -0
  1104. package/src/client/history/VersionHistoryPanel.tsx +175 -0
  1105. package/src/client/history/index.ts +21 -0
  1106. package/src/client/history/use-history.ts +114 -0
  1107. package/src/client/hooks/index.ts +46 -0
  1108. package/src/client/host/index.ts +170 -0
  1109. package/src/client/host-bridge.ts +1272 -0
  1110. package/src/client/host-tools.ts +190 -0
  1111. package/src/client/i18n.tsx +798 -0
  1112. package/src/client/index.ts +370 -0
  1113. package/src/client/integrations/IntegrationCard.tsx +186 -0
  1114. package/src/client/integrations/IntegrationsPanel.tsx +633 -0
  1115. package/src/client/integrations/api.ts +295 -0
  1116. package/src/client/integrations/index.ts +29 -0
  1117. package/src/client/integrations/useIntegrationStatus.ts +52 -0
  1118. package/src/client/mcp-app-host.ts +720 -0
  1119. package/src/client/mcp-apps/McpAppRenderer.tsx +760 -0
  1120. package/src/client/navigation/index.ts +54 -0
  1121. package/src/client/notifications/NotificationsBell.tsx +383 -0
  1122. package/src/client/notifications/index.ts +1 -0
  1123. package/src/client/observability/ObservabilityDashboard.tsx +890 -0
  1124. package/src/client/observability/ThumbsFeedback.tsx +160 -0
  1125. package/src/client/observability/index.ts +20 -0
  1126. package/src/client/observability/useObservability.ts +266 -0
  1127. package/src/client/onboarding/OnboardingBanner.tsx +73 -0
  1128. package/src/client/onboarding/OnboardingPanel.tsx +1036 -0
  1129. package/src/client/onboarding/SetupButton.tsx +64 -0
  1130. package/src/client/onboarding/index.ts +25 -0
  1131. package/src/client/onboarding/use-onboarding.ts +164 -0
  1132. package/src/client/onboarding/use-preview-mode.ts +40 -0
  1133. package/src/client/org/InvitationBanner.tsx +148 -0
  1134. package/src/client/org/OrgSwitcher.tsx +754 -0
  1135. package/src/client/org/RequireActiveOrg.tsx +337 -0
  1136. package/src/client/org/TeamPage.tsx +1432 -0
  1137. package/src/client/org/hooks.ts +359 -0
  1138. package/src/client/org/index.ts +70 -0
  1139. package/src/client/org/workspace-app-links.ts +367 -0
  1140. package/src/client/org-team/index.ts +1 -0
  1141. package/src/client/progress/RunsTray.tsx +680 -0
  1142. package/src/client/progress/index.ts +1 -0
  1143. package/src/client/require-session.tsx +142 -0
  1144. package/src/client/resources/BuiltinCapabilityDetail.tsx +258 -0
  1145. package/src/client/resources/McpConnectionSuggestion.tsx +276 -0
  1146. package/src/client/resources/McpIntegrationDialog.tsx +808 -0
  1147. package/src/client/resources/McpServerDetail.tsx +230 -0
  1148. package/src/client/resources/ResourceEditor.tsx +872 -0
  1149. package/src/client/resources/ResourceTree.tsx +860 -0
  1150. package/src/client/resources/ResourcesPanel.tsx +1960 -0
  1151. package/src/client/resources/index.ts +25 -0
  1152. package/src/client/resources/mcp-integration-catalog.ts +771 -0
  1153. package/src/client/resources/mcp-integration-logos.ts +108 -0
  1154. package/src/client/resources/runtime.ts +1 -0
  1155. package/src/client/resources/use-builtin-capabilities.ts +113 -0
  1156. package/src/client/resources/use-mcp-servers.ts +217 -0
  1157. package/src/client/resources/use-resources.ts +402 -0
  1158. package/src/client/review/ReviewCommentComposer.tsx +123 -0
  1159. package/src/client/review/ReviewStatusBadge.tsx +39 -0
  1160. package/src/client/review/ReviewThreadPanel.tsx +625 -0
  1161. package/src/client/review/index.ts +38 -0
  1162. package/src/client/review/use-review.ts +186 -0
  1163. package/src/client/route-chunk-recovery/index.ts +1 -0
  1164. package/src/client/route-chunk-recovery.ts +331 -0
  1165. package/src/client/route-state.ts +455 -0
  1166. package/src/client/route-warmup.tsx +543 -0
  1167. package/src/client/session-replay-iframe.e2e-host.tsx +100 -0
  1168. package/src/client/session-replay.ts +3417 -0
  1169. package/src/client/settings/AgentsSection.tsx +441 -0
  1170. package/src/client/settings/AutomationsSection.tsx +516 -0
  1171. package/src/client/settings/BackgroundAgentSection.tsx +189 -0
  1172. package/src/client/settings/BrowserSection.tsx +110 -0
  1173. package/src/client/settings/DemoModeSection.tsx +48 -0
  1174. package/src/client/settings/SecretsSection.tsx +875 -0
  1175. package/src/client/settings/SettingsPanel.tsx +3162 -0
  1176. package/src/client/settings/SettingsSection.tsx +283 -0
  1177. package/src/client/settings/SettingsTabsPage.tsx +592 -0
  1178. package/src/client/settings/UsageSection.tsx +401 -0
  1179. package/src/client/settings/VoiceTranscriptionSection.tsx +960 -0
  1180. package/src/client/settings/agent-settings-search.ts +220 -0
  1181. package/src/client/settings/index.ts +27 -0
  1182. package/src/client/settings/useBuilderStatus.ts +1055 -0
  1183. package/src/client/setup-connections/BuilderConnectCard.tsx +89 -0
  1184. package/src/client/setup-connections/ProviderReadinessBadge.tsx +73 -0
  1185. package/src/client/setup-connections/SetupConnectionsPage.tsx +94 -0
  1186. package/src/client/setup-connections/catalog.ts +6 -0
  1187. package/src/client/setup-connections/index.ts +47 -0
  1188. package/src/client/setup-connections/runtime.ts +1 -0
  1189. package/src/client/sharing/ShareButton.tsx +1748 -0
  1190. package/src/client/sharing/ShareDialog.tsx +846 -0
  1191. package/src/client/sharing/VisibilityBadge.tsx +4 -0
  1192. package/src/client/sharing/index.ts +2 -0
  1193. package/src/client/sse-event-processor.ts +2002 -0
  1194. package/src/client/terminal/AgentTerminal.tsx +488 -0
  1195. package/src/client/terminal/index.ts +7 -0
  1196. package/src/client/theme.ts +27 -0
  1197. package/src/client/tombstone/agent-presence-chip.ts +17 -0
  1198. package/src/client/tombstone/editor.ts +265 -0
  1199. package/src/client/tombstone/live-cursor-overlay.ts +21 -0
  1200. package/src/client/tombstone/presence-bar.ts +17 -0
  1201. package/src/client/tombstone/recent-edit-highlights.ts +17 -0
  1202. package/src/client/tombstone/remote-selection-rings.ts +21 -0
  1203. package/src/client/tombstone/rich-markdown-editor.ts +265 -0
  1204. package/src/client/tombstone/ui-dialog.ts +49 -0
  1205. package/src/client/tombstone/ui-dropdown-menu.ts +69 -0
  1206. package/src/client/tombstone/ui-hover-card.ts +21 -0
  1207. package/src/client/tombstone/ui-popover.ts +25 -0
  1208. package/src/client/tombstone/ui-sheet.ts +49 -0
  1209. package/src/client/tombstone/ui-tooltip.ts +29 -0
  1210. package/src/client/tombstone/visual-style-controls.ts +61 -0
  1211. package/src/client/tool-cells/BashCell.tsx +164 -0
  1212. package/src/client/tool-cells/EditCell.tsx +303 -0
  1213. package/src/client/tool-cells/FilesChangedSummary.tsx +208 -0
  1214. package/src/client/tool-cells/WriteCell.tsx +145 -0
  1215. package/src/client/tool-cells/index.ts +7 -0
  1216. package/src/client/tool-display.ts +41 -0
  1217. package/src/client/track.ts +57 -0
  1218. package/src/client/transcription/BuilderTranscriptionCta.tsx +120 -0
  1219. package/src/client/transcription/use-live-transcription.ts +292 -0
  1220. package/src/client/ui/index.ts +55 -0
  1221. package/src/client/uploads/index.ts +6 -0
  1222. package/src/client/uploads/upload-editor-image.ts +79 -0
  1223. package/src/client/uploads/use-upload-resource.ts +24 -0
  1224. package/src/client/url-scrub.ts +51 -0
  1225. package/src/client/use-action.ts +766 -0
  1226. package/src/client/use-agent-chat-context.ts +63 -0
  1227. package/src/client/use-agent-chat-home-handoff.ts +207 -0
  1228. package/src/client/use-agent-chat.ts +53 -0
  1229. package/src/client/use-agent-engine-configured.ts +211 -0
  1230. package/src/client/use-avatar.ts +127 -0
  1231. package/src/client/use-change-version.ts +150 -0
  1232. package/src/client/use-chat-models.ts +252 -0
  1233. package/src/client/use-chat-threads.ts +1262 -0
  1234. package/src/client/use-db-sync.ts +1112 -0
  1235. package/src/client/use-demo-mode-status.ts +30 -0
  1236. package/src/client/use-dev-mode.ts +177 -0
  1237. package/src/client/use-external-value.ts +40 -0
  1238. package/src/client/use-pausing-interval.ts +65 -0
  1239. package/src/client/use-pinch-zoom.ts +202 -0
  1240. package/src/client/use-run-stuck-detection.ts +427 -0
  1241. package/src/client/use-send-to-agent-chat.ts +85 -0
  1242. package/src/client/use-session.ts +114 -0
  1243. package/src/client/utils.ts +7 -0
  1244. package/src/client/visual-style-controls.tsx +1 -0
  1245. package/src/client/vite-dev-recovery-script.ts +226 -0
  1246. package/src/client/voice-provider-status.ts +44 -0
  1247. package/src/client/widgets/index.ts +41 -0
  1248. package/src/code-agents/background-controller.ts +398 -0
  1249. package/src/code-agents/background-run.ts +156 -0
  1250. package/src/code-agents/index.ts +95 -0
  1251. package/src/code-agents/prompt-attachments.ts +39 -0
  1252. package/src/code-agents/transcript-normalizer.ts +750 -0
  1253. package/src/code-agents/transcript-order.ts +73 -0
  1254. package/src/coding-tools/index.ts +742 -0
  1255. package/src/coding-tools/run-code.ts +1662 -0
  1256. package/src/coding-tools/sandbox/adapter.ts +82 -0
  1257. package/src/coding-tools/sandbox/background.ts +406 -0
  1258. package/src/coding-tools/sandbox/executions-store.ts +517 -0
  1259. package/src/coding-tools/sandbox/index.ts +132 -0
  1260. package/src/coding-tools/sandbox/local-child-process-adapter.ts +217 -0
  1261. package/src/collab/agent-identity.ts +5 -0
  1262. package/src/collab/agent-presence.ts +341 -0
  1263. package/src/collab/awareness-store.ts +196 -0
  1264. package/src/collab/awareness.ts +317 -0
  1265. package/src/collab/client-struct.ts +366 -0
  1266. package/src/collab/client.ts +1205 -0
  1267. package/src/collab/emitter.ts +31 -0
  1268. package/src/collab/follow-mode.ts +107 -0
  1269. package/src/collab/index.ts +151 -0
  1270. package/src/collab/json-to-yjs.ts +504 -0
  1271. package/src/collab/presence.ts +207 -0
  1272. package/src/collab/recent-edits.ts +215 -0
  1273. package/src/collab/routes.ts +191 -0
  1274. package/src/collab/storage.ts +228 -0
  1275. package/src/collab/struct-routes.ts +133 -0
  1276. package/src/collab/text-to-yjs.ts +79 -0
  1277. package/src/collab/undo.ts +432 -0
  1278. package/src/collab/xml-ops.ts +68 -0
  1279. package/src/collab/ydoc-manager.ts +544 -0
  1280. package/src/command-navigation/actions.ts +100 -0
  1281. package/src/command-navigation/index.ts +12 -0
  1282. package/src/comments-review/index.ts +1 -0
  1283. package/src/connections/catalog.ts +451 -0
  1284. package/src/connections/index.ts +48 -0
  1285. package/src/connections/reader.ts +911 -0
  1286. package/src/connections/runtime.ts +1 -0
  1287. package/src/credentials/index.ts +187 -0
  1288. package/src/data-programs/actions.ts +335 -0
  1289. package/src/data-programs/contract.ts +284 -0
  1290. package/src/data-programs/execute.ts +693 -0
  1291. package/src/data-programs/index.ts +72 -0
  1292. package/src/data-programs/schema.ts +148 -0
  1293. package/src/data-programs/store.ts +755 -0
  1294. package/src/data-widgets/index.ts +376 -0
  1295. package/src/db/client.ts +1627 -0
  1296. package/src/db/create-get-db.ts +579 -0
  1297. package/src/db/ddl-guard.ts +302 -0
  1298. package/src/db/drizzle-config.ts +190 -0
  1299. package/src/db/ensure-additive-columns.ts +430 -0
  1300. package/src/db/index.ts +57 -0
  1301. package/src/db/migrations.ts +691 -0
  1302. package/src/db/request-telemetry.ts +154 -0
  1303. package/src/db/runtime-diagnostics.ts +331 -0
  1304. package/src/db/schema.ts +121 -0
  1305. package/src/db/widen-columns.ts +75 -0
  1306. package/src/db-admin/agent-tools.ts +202 -0
  1307. package/src/db-admin/index.ts +26 -0
  1308. package/src/db-admin/operations.ts +803 -0
  1309. package/src/db-admin/routes.ts +174 -0
  1310. package/src/db-admin/types.ts +110 -0
  1311. package/src/demo/browser-state.ts +47 -0
  1312. package/src/demo/fetch-interceptor.ts +175 -0
  1313. package/src/demo/redact.ts +575 -0
  1314. package/src/deploy/build.ts +3935 -0
  1315. package/src/deploy/immutable-assets.ts +65 -0
  1316. package/src/deploy/route-discovery.ts +458 -0
  1317. package/src/deploy/workspace-core.ts +282 -0
  1318. package/src/deploy/workspace-deploy.ts +1488 -0
  1319. package/src/eject/provider-api-definitions.ts +193 -0
  1320. package/src/eject/remote-mcp-presets.ts +137 -0
  1321. package/src/eject/setup-readiness-ui.tsx +29 -0
  1322. package/src/eject/workspace-connections.ts +92 -0
  1323. package/src/embedding/agent.ts +159 -0
  1324. package/src/embedding/bridge.ts +297 -0
  1325. package/src/embedding/index.ts +43 -0
  1326. package/src/embedding/protocol.ts +185 -0
  1327. package/src/embedding/react.tsx +319 -0
  1328. package/src/embeddings/index.ts +233 -0
  1329. package/src/eval/agent-runner.ts +210 -0
  1330. package/src/eval/define-eval.ts +55 -0
  1331. package/src/eval/index.ts +49 -0
  1332. package/src/eval/report.ts +75 -0
  1333. package/src/eval/runner.ts +369 -0
  1334. package/src/eval/scorer.ts +244 -0
  1335. package/src/eval/types.ts +188 -0
  1336. package/src/event-bus/bus.ts +140 -0
  1337. package/src/event-bus/index.ts +3 -0
  1338. package/src/event-bus/registry.ts +79 -0
  1339. package/src/event-bus/types.ts +29 -0
  1340. package/src/extensions/actions.ts +1636 -0
  1341. package/src/extensions/change-marker.ts +54 -0
  1342. package/src/extensions/content-patch.ts +468 -0
  1343. package/src/extensions/fetch-tool.ts +461 -0
  1344. package/src/extensions/html-shell.ts +803 -0
  1345. package/src/extensions/local.ts +462 -0
  1346. package/src/extensions/path.ts +40 -0
  1347. package/src/extensions/proxy-security.ts +171 -0
  1348. package/src/extensions/routes.ts +1080 -0
  1349. package/src/extensions/schema.ts +269 -0
  1350. package/src/extensions/session-replay-iframe.ts +131 -0
  1351. package/src/extensions/slots/routes.ts +126 -0
  1352. package/src/extensions/slots/schema.ts +87 -0
  1353. package/src/extensions/slots/store.ts +450 -0
  1354. package/src/extensions/store.ts +1347 -0
  1355. package/src/extensions/theme.ts +114 -0
  1356. package/src/extensions/url-safety.ts +316 -0
  1357. package/src/extensions/web-content.ts +663 -0
  1358. package/src/extensions/web-search-tool.ts +437 -0
  1359. package/src/feature-flags/a2a-action-route.ts +56 -0
  1360. package/src/feature-flags/actions/get-feature-flags.ts +24 -0
  1361. package/src/feature-flags/actions/list-feature-flags.ts +69 -0
  1362. package/src/feature-flags/actions/set-feature-flag.ts +89 -0
  1363. package/src/feature-flags/index.ts +21 -0
  1364. package/src/feature-flags/permissions.ts +53 -0
  1365. package/src/feature-flags/plugin.ts +44 -0
  1366. package/src/feature-flags/registry.ts +96 -0
  1367. package/src/feature-flags/store.ts +176 -0
  1368. package/src/file-upload/actions/upload-image.ts +213 -0
  1369. package/src/file-upload/builder.ts +431 -0
  1370. package/src/file-upload/index.ts +24 -0
  1371. package/src/file-upload/pre-upload-attachments.ts +305 -0
  1372. package/src/file-upload/registry.ts +125 -0
  1373. package/src/file-upload/types.ts +89 -0
  1374. package/src/guards/db-tool-scoping.ts +129 -0
  1375. package/src/guards/index.ts +23 -0
  1376. package/src/guards/no-drizzle-push.ts +116 -0
  1377. package/src/guards/no-env-credentials.ts +229 -0
  1378. package/src/guards/no-env-mutation.ts +114 -0
  1379. package/src/guards/no-localhost-fallback.ts +124 -0
  1380. package/src/guards/no-unscoped-credentials.ts +227 -0
  1381. package/src/guards/no-unscoped-queries.ts +834 -0
  1382. package/src/guards/scan-utils.ts +105 -0
  1383. package/src/guards/types.ts +30 -0
  1384. package/src/history/actions/create-resource-version.ts +92 -0
  1385. package/src/history/actions/get-resource-version.ts +60 -0
  1386. package/src/history/actions/list-resource-history.ts +53 -0
  1387. package/src/history/actions/list-resource-versions.ts +43 -0
  1388. package/src/history/actions/restore-resource-version.ts +96 -0
  1389. package/src/history/index.ts +26 -0
  1390. package/src/history/registry.ts +111 -0
  1391. package/src/history/store.ts +379 -0
  1392. package/src/history/types.ts +69 -0
  1393. package/src/index.browser.ts +155 -0
  1394. package/src/index.ts +408 -0
  1395. package/src/ingestion/docx.ts +158 -0
  1396. package/src/ingestion/figma-node-to-html.ts +1860 -0
  1397. package/src/ingestion/figma.ts +548 -0
  1398. package/src/ingestion/index.ts +107 -0
  1399. package/src/ingestion/media.ts +264 -0
  1400. package/src/ingestion/notion.ts +121 -0
  1401. package/src/ingestion/office.ts +213 -0
  1402. package/src/ingestion/orchestration.ts +160 -0
  1403. package/src/ingestion/pptx.ts +331 -0
  1404. package/src/ingestion/selection.ts +81 -0
  1405. package/src/ingestion/website.ts +151 -0
  1406. package/src/integrations/a2a-continuation-marker.ts +2 -0
  1407. package/src/integrations/a2a-continuation-processor.ts +888 -0
  1408. package/src/integrations/a2a-continuations-store.ts +643 -0
  1409. package/src/integrations/adapter-overrides.ts +12 -0
  1410. package/src/integrations/adapters/discord.ts +364 -0
  1411. package/src/integrations/adapters/email.ts +1164 -0
  1412. package/src/integrations/adapters/google-docs.ts +371 -0
  1413. package/src/integrations/adapters/index.ts +29 -0
  1414. package/src/integrations/adapters/microsoft-teams.ts +413 -0
  1415. package/src/integrations/adapters/slack.ts +1914 -0
  1416. package/src/integrations/adapters/telegram.ts +386 -0
  1417. package/src/integrations/adapters/whatsapp.ts +358 -0
  1418. package/src/integrations/awaiting-input-store.ts +130 -0
  1419. package/src/integrations/catalog.ts +571 -0
  1420. package/src/integrations/computer-supervision-store.ts +423 -0
  1421. package/src/integrations/computer-supervision.ts +213 -0
  1422. package/src/integrations/config-store.ts +131 -0
  1423. package/src/integrations/controls-store.ts +187 -0
  1424. package/src/integrations/eject/messaging-adapters.ts +85 -0
  1425. package/src/integrations/google-docs-poller.ts +671 -0
  1426. package/src/integrations/identity-links-store.ts +210 -0
  1427. package/src/integrations/identity.ts +196 -0
  1428. package/src/integrations/index.ts +220 -0
  1429. package/src/integrations/installations-store.ts +677 -0
  1430. package/src/integrations/integration-memory.ts +187 -0
  1431. package/src/integrations/internal-token.ts +106 -0
  1432. package/src/integrations/pending-tasks-retry-job.ts +286 -0
  1433. package/src/integrations/pending-tasks-store.ts +468 -0
  1434. package/src/integrations/plugin.ts +3048 -0
  1435. package/src/integrations/remote-commands-store.ts +690 -0
  1436. package/src/integrations/remote-devices-store.ts +492 -0
  1437. package/src/integrations/remote-json-safety.ts +127 -0
  1438. package/src/integrations/remote-push-delivery-job.ts +48 -0
  1439. package/src/integrations/remote-push-delivery.ts +370 -0
  1440. package/src/integrations/remote-push-store.ts +664 -0
  1441. package/src/integrations/remote-retry-job.ts +55 -0
  1442. package/src/integrations/remote-run-events-store.ts +222 -0
  1443. package/src/integrations/remote-types.ts +186 -0
  1444. package/src/integrations/runtime.ts +1 -0
  1445. package/src/integrations/scope-store.ts +498 -0
  1446. package/src/integrations/slack-manifest.ts +78 -0
  1447. package/src/integrations/slack-oauth.ts +344 -0
  1448. package/src/integrations/task-queue-stats.ts +144 -0
  1449. package/src/integrations/thread-mapping-store.ts +134 -0
  1450. package/src/integrations/types.ts +485 -0
  1451. package/src/integrations/usage-budget-store.ts +906 -0
  1452. package/src/integrations/webhook-delivery.ts +55 -0
  1453. package/src/integrations/webhook-handler.ts +1939 -0
  1454. package/src/jobs/actions/list-recurring-jobs.ts +105 -0
  1455. package/src/jobs/actions/manage-recurring-job.ts +85 -0
  1456. package/src/jobs/cron.ts +126 -0
  1457. package/src/jobs/index.ts +9 -0
  1458. package/src/jobs/scheduler.ts +703 -0
  1459. package/src/jobs/tools.ts +367 -0
  1460. package/src/local-artifacts/index.ts +1372 -0
  1461. package/src/localization/actions/get-localization-preference.ts +24 -0
  1462. package/src/localization/actions/set-localization-preference.ts +32 -0
  1463. package/src/localization/default-messages.ts +1009 -0
  1464. package/src/localization/index.ts +2 -0
  1465. package/src/localization/server.ts +131 -0
  1466. package/src/localization/shared.ts +208 -0
  1467. package/src/mcp/actions/call-mcp-tool.ts +19 -0
  1468. package/src/mcp/actions/create-org-service-token.ts +87 -0
  1469. package/src/mcp/actions/list-mcp-tools.ts +18 -0
  1470. package/src/mcp/actions/list-org-service-tokens.ts +44 -0
  1471. package/src/mcp/actions/revoke-org-service-token.ts +30 -0
  1472. package/src/mcp/actions/service-token-access.ts +121 -0
  1473. package/src/mcp/ask-app-inline-tasks.ts +125 -0
  1474. package/src/mcp/build-server.ts +2356 -0
  1475. package/src/mcp/builtin-tools.ts +1506 -0
  1476. package/src/mcp/connect-route.ts +1460 -0
  1477. package/src/mcp/connect-store.ts +680 -0
  1478. package/src/mcp/embed-app.ts +2051 -0
  1479. package/src/mcp/embed-route.ts +84 -0
  1480. package/src/mcp/external-agent-policy.ts +18 -0
  1481. package/src/mcp/index.ts +47 -0
  1482. package/src/mcp/oauth-route.ts +1016 -0
  1483. package/src/mcp/oauth-store.ts +581 -0
  1484. package/src/mcp/oauth-token.ts +227 -0
  1485. package/src/mcp/org-directory.ts +343 -0
  1486. package/src/mcp/route-paths.ts +34 -0
  1487. package/src/mcp/screen-memory-stdio.ts +290 -0
  1488. package/src/mcp/server.ts +507 -0
  1489. package/src/mcp/stdio.ts +328 -0
  1490. package/src/mcp/workspace-resolve.ts +261 -0
  1491. package/src/mcp-client/app-api.ts +136 -0
  1492. package/src/mcp-client/app-result.ts +64 -0
  1493. package/src/mcp-client/builtin-capabilities.ts +146 -0
  1494. package/src/mcp-client/builtin-store.ts +93 -0
  1495. package/src/mcp-client/config.ts +281 -0
  1496. package/src/mcp-client/errors.ts +54 -0
  1497. package/src/mcp-client/hub-client.ts +172 -0
  1498. package/src/mcp-client/hub-routes.ts +198 -0
  1499. package/src/mcp-client/index.ts +504 -0
  1500. package/src/mcp-client/manager.ts +968 -0
  1501. package/src/mcp-client/oauth-client.ts +462 -0
  1502. package/src/mcp-client/oauth-routes.ts +307 -0
  1503. package/src/mcp-client/remote-store.ts +674 -0
  1504. package/src/mcp-client/remote-url.ts +97 -0
  1505. package/src/mcp-client/routes.ts +1093 -0
  1506. package/src/mcp-client/screen-memory-local.ts +461 -0
  1507. package/src/mcp-client/tool-policy.ts +182 -0
  1508. package/src/mcp-client/visibility.ts +56 -0
  1509. package/src/mcp-client/workspace-servers.ts +379 -0
  1510. package/src/navigation/index.ts +170 -0
  1511. package/src/notifications/actions.ts +151 -0
  1512. package/src/notifications/channels.ts +410 -0
  1513. package/src/notifications/index.ts +22 -0
  1514. package/src/notifications/registry.ts +216 -0
  1515. package/src/notifications/routes.ts +106 -0
  1516. package/src/notifications/store.ts +236 -0
  1517. package/src/notifications/types.ts +52 -0
  1518. package/src/oauth-tokens/google-refresh.ts +175 -0
  1519. package/src/oauth-tokens/index.ts +15 -0
  1520. package/src/oauth-tokens/store.ts +384 -0
  1521. package/src/observability/cleanup-job.ts +124 -0
  1522. package/src/observability/evals.ts +507 -0
  1523. package/src/observability/experiments.ts +359 -0
  1524. package/src/observability/feedback.ts +332 -0
  1525. package/src/observability/hosted-model-experiment.ts +118 -0
  1526. package/src/observability/index.ts +62 -0
  1527. package/src/observability/plugin.ts +31 -0
  1528. package/src/observability/routes.ts +431 -0
  1529. package/src/observability/sentiment.ts +261 -0
  1530. package/src/observability/store.ts +1347 -0
  1531. package/src/observability/traces.ts +789 -0
  1532. package/src/observability/tracing.ts +157 -0
  1533. package/src/observability/tracking-identity.ts +55 -0
  1534. package/src/observability/types.ts +211 -0
  1535. package/src/onboarding/default-steps.ts +428 -0
  1536. package/src/onboarding/index.ts +22 -0
  1537. package/src/onboarding/plugin.ts +262 -0
  1538. package/src/onboarding/registry.ts +47 -0
  1539. package/src/onboarding/types.ts +96 -0
  1540. package/src/org/accept-pending.ts +98 -0
  1541. package/src/org/auto-join-domain.ts +113 -0
  1542. package/src/org/context.ts +614 -0
  1543. package/src/org/free-email-providers.ts +124 -0
  1544. package/src/org/handlers.ts +1153 -0
  1545. package/src/org/index.ts +63 -0
  1546. package/src/org/migrations.ts +105 -0
  1547. package/src/org/permissions.ts +30 -0
  1548. package/src/org/plugin.ts +255 -0
  1549. package/src/org/schema.ts +28 -0
  1550. package/src/org/types.ts +57 -0
  1551. package/src/org-team/index.ts +1 -0
  1552. package/src/package-lifecycle/deprecated-imports.ts +179 -0
  1553. package/src/package-lifecycle/eject-manifest.ts +345 -0
  1554. package/src/package-lifecycle/index.ts +7 -0
  1555. package/src/package-lifecycle/manifest.ts +120 -0
  1556. package/src/package-lifecycle/migration-manifest.ts +159 -0
  1557. package/src/package-lifecycle/migration-message.ts +6 -0
  1558. package/src/package-lifecycle/tombstone.ts +58 -0
  1559. package/src/package-lifecycle/upgrade-error.ts +37 -0
  1560. package/src/private-blob/index.ts +18 -0
  1561. package/src/private-blob/registry.ts +242 -0
  1562. package/src/private-blob/types.ts +55 -0
  1563. package/src/progress/actions.ts +179 -0
  1564. package/src/progress/index.ts +16 -0
  1565. package/src/progress/registry.ts +127 -0
  1566. package/src/progress/routes.ts +89 -0
  1567. package/src/progress/store.ts +353 -0
  1568. package/src/progress/types.ts +59 -0
  1569. package/src/provider-api/actions/custom-provider-registration.ts +197 -0
  1570. package/src/provider-api/actions/delete-staged-dataset.ts +5 -0
  1571. package/src/provider-api/actions/github-repo-files.ts +266 -0
  1572. package/src/provider-api/actions/list-staged-datasets.ts +5 -0
  1573. package/src/provider-api/actions/provider-api-audit.ts +88 -0
  1574. package/src/provider-api/actions/provider-api.ts +460 -0
  1575. package/src/provider-api/actions/query-staged-dataset.ts +5 -0
  1576. package/src/provider-api/actions/staged-datasets.ts +359 -0
  1577. package/src/provider-api/corpus-jobs-store.ts +522 -0
  1578. package/src/provider-api/corpus-jobs.ts +1817 -0
  1579. package/src/provider-api/custom-registry.ts +456 -0
  1580. package/src/provider-api/github-repo.ts +675 -0
  1581. package/src/provider-api/gong.ts +108 -0
  1582. package/src/provider-api/index.ts +5444 -0
  1583. package/src/provider-api/quota-governor.ts +562 -0
  1584. package/src/provider-api/runtime.ts +1 -0
  1585. package/src/provider-api/staged-datasets-aggregate.ts +304 -0
  1586. package/src/provider-api/staged-datasets-store.ts +441 -0
  1587. package/src/provider-api/staging.ts +483 -0
  1588. package/src/resources/agents.ts +65 -0
  1589. package/src/resources/emitter.ts +54 -0
  1590. package/src/resources/handlers.ts +728 -0
  1591. package/src/resources/index.ts +4 -0
  1592. package/src/resources/metadata.ts +252 -0
  1593. package/src/resources/script-helpers.ts +160 -0
  1594. package/src/resources/store.ts +1618 -0
  1595. package/src/review/actions/consume-review-feedback.ts +48 -0
  1596. package/src/review/actions/create-review-comment.ts +108 -0
  1597. package/src/review/actions/delete-review-comment.ts +67 -0
  1598. package/src/review/actions/get-review-feedback.ts +49 -0
  1599. package/src/review/actions/list-review-comments.ts +87 -0
  1600. package/src/review/actions/reply-review-comment.ts +118 -0
  1601. package/src/review/actions/resolve-review-thread.ts +94 -0
  1602. package/src/review/actions/send-review-thread-to-agent.ts +62 -0
  1603. package/src/review/actions/set-review-status.ts +58 -0
  1604. package/src/review/identity.ts +101 -0
  1605. package/src/review/index.ts +45 -0
  1606. package/src/review/mentions.ts +44 -0
  1607. package/src/review/registry.ts +111 -0
  1608. package/src/review/store.ts +997 -0
  1609. package/src/review/types.ts +101 -0
  1610. package/src/router/index.ts +24 -0
  1611. package/src/scripts/agent-engines/list-agent-engines.ts +130 -0
  1612. package/src/scripts/agent-engines/manage-agent-engine.ts +197 -0
  1613. package/src/scripts/agent-engines/set-agent-engine.ts +84 -0
  1614. package/src/scripts/agent-engines/test-agent-engine.ts +174 -0
  1615. package/src/scripts/call-agent.ts +792 -0
  1616. package/src/scripts/chat/index.ts +8 -0
  1617. package/src/scripts/chat/open-chat.ts +56 -0
  1618. package/src/scripts/chat/search-chats.ts +121 -0
  1619. package/src/scripts/core-scripts.ts +22 -0
  1620. package/src/scripts/db/check-scoping.ts +212 -0
  1621. package/src/scripts/db/exec.ts +791 -0
  1622. package/src/scripts/db/index.ts +19 -0
  1623. package/src/scripts/db/migrate-encrypt-credentials.ts +223 -0
  1624. package/src/scripts/db/migrate-encrypt-oauth-tokens.ts +213 -0
  1625. package/src/scripts/db/migrate-user-api-keys.ts +257 -0
  1626. package/src/scripts/db/patch.ts +820 -0
  1627. package/src/scripts/db/query.ts +299 -0
  1628. package/src/scripts/db/reset-dev-owner.ts +285 -0
  1629. package/src/scripts/db/safety.ts +286 -0
  1630. package/src/scripts/db/schema.ts +364 -0
  1631. package/src/scripts/db/scoping.ts +341 -0
  1632. package/src/scripts/db/sqlite-client.ts +78 -0
  1633. package/src/scripts/db/tool-mode.ts +23 -0
  1634. package/src/scripts/db/tool-schemas.ts +31 -0
  1635. package/src/scripts/db/wipe-leaked-builder-keys.ts +201 -0
  1636. package/src/scripts/dev/index.ts +296 -0
  1637. package/src/scripts/dev/list-files.ts +119 -0
  1638. package/src/scripts/dev/read-file.ts +77 -0
  1639. package/src/scripts/dev/search-files.ts +151 -0
  1640. package/src/scripts/dev/shell.ts +111 -0
  1641. package/src/scripts/dev/write-file.ts +56 -0
  1642. package/src/scripts/dev-session.ts +96 -0
  1643. package/src/scripts/docs/index.ts +8 -0
  1644. package/src/scripts/docs/search.ts +274 -0
  1645. package/src/scripts/docs/source-search.ts +363 -0
  1646. package/src/scripts/index.ts +15 -0
  1647. package/src/scripts/manage-agent-loop-settings.ts +84 -0
  1648. package/src/scripts/parse-args.ts +46 -0
  1649. package/src/scripts/resources/delete-memory.ts +67 -0
  1650. package/src/scripts/resources/delete.ts +69 -0
  1651. package/src/scripts/resources/effective.ts +71 -0
  1652. package/src/scripts/resources/index.ts +18 -0
  1653. package/src/scripts/resources/list.ts +103 -0
  1654. package/src/scripts/resources/migrate-learnings.ts +40 -0
  1655. package/src/scripts/resources/read.ts +107 -0
  1656. package/src/scripts/resources/save-memory.ts +99 -0
  1657. package/src/scripts/resources/write.ts +158 -0
  1658. package/src/scripts/runner.ts +339 -0
  1659. package/src/scripts/utils.ts +130 -0
  1660. package/src/search/index.ts +413 -0
  1661. package/src/search-utils/index.ts +112 -0
  1662. package/src/secrets/crypto.ts +228 -0
  1663. package/src/secrets/index.ts +65 -0
  1664. package/src/secrets/onboarding.ts +101 -0
  1665. package/src/secrets/register-framework-secrets.ts +228 -0
  1666. package/src/secrets/register.ts +129 -0
  1667. package/src/secrets/routes.ts +697 -0
  1668. package/src/secrets/schema.ts +52 -0
  1669. package/src/secrets/storage.ts +561 -0
  1670. package/src/secrets/substitution.ts +305 -0
  1671. package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +150 -0
  1672. package/src/server/action-change.ts +66 -0
  1673. package/src/server/action-discovery.ts +774 -0
  1674. package/src/server/action-routes.ts +608 -0
  1675. package/src/server/agent-access.ts +72 -0
  1676. package/src/server/agent-chat/action-filters-a2a.ts +339 -0
  1677. package/src/server/agent-chat/browser-team-tools.ts +510 -0
  1678. package/src/server/agent-chat/context-tools.ts +599 -0
  1679. package/src/server/agent-chat/framework-prompts.ts +467 -0
  1680. package/src/server/agent-chat/lazy-fs.ts +11 -0
  1681. package/src/server/agent-chat/mcp-glue.ts +91 -0
  1682. package/src/server/agent-chat/plugin-options.ts +379 -0
  1683. package/src/server/agent-chat/process-run-failure.ts +62 -0
  1684. package/src/server/agent-chat/prompt-resources.ts +1004 -0
  1685. package/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
  1686. package/src/server/agent-chat/request-surface.ts +71 -0
  1687. package/src/server/agent-chat/run-code-tools.ts +67 -0
  1688. package/src/server/agent-chat/script-entries.ts +796 -0
  1689. package/src/server/agent-chat/shared-thread.ts +301 -0
  1690. package/src/server/agent-chat/skill-frontmatter.ts +41 -0
  1691. package/src/server/agent-chat-plugin.ts +5930 -0
  1692. package/src/server/agent-discovery.ts +706 -0
  1693. package/src/server/agent-engine-api-key-route.ts +236 -0
  1694. package/src/server/agent-run-context.ts +204 -0
  1695. package/src/server/agent-teams-run-queue.ts +344 -0
  1696. package/src/server/agent-teams.ts +2257 -0
  1697. package/src/server/agents-bundle.ts +464 -0
  1698. package/src/server/analytics.ts +105 -0
  1699. package/src/server/app-base-path.ts +79 -0
  1700. package/src/server/app-name.ts +53 -0
  1701. package/src/server/app-url.ts +184 -0
  1702. package/src/server/attachment-actions.ts +276 -0
  1703. package/src/server/attribution.ts +214 -0
  1704. package/src/server/auth-marketing.ts +260 -0
  1705. package/src/server/auth-plugin.ts +27 -0
  1706. package/src/server/auth.ts +3803 -0
  1707. package/src/server/better-auth-instance.ts +1197 -0
  1708. package/src/server/builder-browser.ts +1701 -0
  1709. package/src/server/builder-design-systems.ts +668 -0
  1710. package/src/server/builder-space.ts +176 -0
  1711. package/src/server/captcha.ts +63 -0
  1712. package/src/server/capture-error.ts +64 -0
  1713. package/src/server/cli-capture.ts +141 -0
  1714. package/src/server/collab-plugin.ts +391 -0
  1715. package/src/server/complete-text.ts +231 -0
  1716. package/src/server/cookie-namespace.ts +159 -0
  1717. package/src/server/core-routes-plugin.ts +4122 -0
  1718. package/src/server/cors-origins.ts +60 -0
  1719. package/src/server/create-server.ts +268 -0
  1720. package/src/server/credential-provider.ts +1202 -0
  1721. package/src/server/csrf.ts +229 -0
  1722. package/src/server/date-utils.ts +42 -0
  1723. package/src/server/deep-link.ts +119 -0
  1724. package/src/server/derived-secret.ts +32 -0
  1725. package/src/server/design-token-utils.ts +1032 -0
  1726. package/src/server/desktop-sso.ts +83 -0
  1727. package/src/server/edge.ts +69 -0
  1728. package/src/server/email-actions.ts +218 -0
  1729. package/src/server/email-template.ts +192 -0
  1730. package/src/server/email-templates.ts +148 -0
  1731. package/src/server/email.ts +219 -0
  1732. package/src/server/embed-route.ts +283 -0
  1733. package/src/server/embed-session.ts +805 -0
  1734. package/src/server/embedded.ts +252 -0
  1735. package/src/server/entry-server.tsx +154 -0
  1736. package/src/server/framework-request-handler.ts +848 -0
  1737. package/src/server/fusion-app.ts +447 -0
  1738. package/src/server/google-auth-mode.ts +34 -0
  1739. package/src/server/google-auth-plugin.ts +496 -0
  1740. package/src/server/google-oauth-credentials.ts +128 -0
  1741. package/src/server/google-oauth.ts +972 -0
  1742. package/src/server/google-realtime-session.ts +182 -0
  1743. package/src/server/h3-helpers.ts +174 -0
  1744. package/src/server/http-response-telemetry.ts +396 -0
  1745. package/src/server/identity-sso-store.ts +304 -0
  1746. package/src/server/identity-sso.ts +514 -0
  1747. package/src/server/index.ts +593 -0
  1748. package/src/server/missing-key.ts +36 -0
  1749. package/src/server/oauth-helpers.ts +44 -0
  1750. package/src/server/oauth-public-origin.ts +44 -0
  1751. package/src/server/oauth-return-url.ts +120 -0
  1752. package/src/server/og-fonts-data.ts +15 -0
  1753. package/src/server/og-fonts.ts +75 -0
  1754. package/src/server/onboarding-html.ts +4040 -0
  1755. package/src/server/open-route.ts +311 -0
  1756. package/src/server/org-admin.ts +28 -0
  1757. package/src/server/poll-events.ts +88 -0
  1758. package/src/server/poll.ts +1224 -0
  1759. package/src/server/prompts/framework-core-compact.ts +107 -0
  1760. package/src/server/prompts/framework-core.ts +143 -0
  1761. package/src/server/prompts/index.ts +16 -0
  1762. package/src/server/prompts/model-overlays.ts +54 -0
  1763. package/src/server/prompts/shared-rules.ts +104 -0
  1764. package/src/server/realtime-voice.ts +967 -0
  1765. package/src/server/recap-image-route.ts +242 -0
  1766. package/src/server/recap-image-store.ts +185 -0
  1767. package/src/server/request-context.ts +416 -0
  1768. package/src/server/request-origin.ts +67 -0
  1769. package/src/server/resources-plugin.ts +119 -0
  1770. package/src/server/schema-prompt.ts +429 -0
  1771. package/src/server/scoped-key-storage.ts +223 -0
  1772. package/src/server/security-headers.ts +170 -0
  1773. package/src/server/self-dispatch.ts +224 -0
  1774. package/src/server/sentry-config.ts +73 -0
  1775. package/src/server/sentry-plugin.ts +138 -0
  1776. package/src/server/sentry.ts +444 -0
  1777. package/src/server/short-lived-token.ts +170 -0
  1778. package/src/server/social-og-image.ts +454 -0
  1779. package/src/server/sse.ts +102 -0
  1780. package/src/server/ssr-handler.ts +466 -0
  1781. package/src/server/transcribe-voice.ts +1076 -0
  1782. package/src/server/voice-providers-status.ts +118 -0
  1783. package/src/server/workspace-oauth.ts +31 -0
  1784. package/src/server/workspace-provider-oauth.ts +970 -0
  1785. package/src/session-replay-iframe-protocol.ts +58 -0
  1786. package/src/settings/handlers.ts +44 -0
  1787. package/src/settings/index.ts +34 -0
  1788. package/src/settings/org-settings.ts +83 -0
  1789. package/src/settings/script-helpers.ts +24 -0
  1790. package/src/settings/store.ts +247 -0
  1791. package/src/settings/user-settings.ts +47 -0
  1792. package/src/setup-connections/index.ts +90 -0
  1793. package/src/setup-connections/onboarding.ts +47 -0
  1794. package/src/shared/agent-access.ts +112 -0
  1795. package/src/shared/agent-chat.ts +124 -0
  1796. package/src/shared/agent-env.ts +46 -0
  1797. package/src/shared/agent-readable-resource.ts +111 -0
  1798. package/src/shared/agent-sidebar-url.ts +39 -0
  1799. package/src/shared/cache-control.ts +25 -0
  1800. package/src/shared/cloudflare-globals.d.ts +34 -0
  1801. package/src/shared/context-xray.ts +172 -0
  1802. package/src/shared/embed-auth.ts +6 -0
  1803. package/src/shared/index.ts +83 -0
  1804. package/src/shared/llm-connection.ts +42 -0
  1805. package/src/shared/markdown-block-split.ts +129 -0
  1806. package/src/shared/mcp-connect-content.ts +130 -0
  1807. package/src/shared/mcp-embed-headers.ts +175 -0
  1808. package/src/shared/mcp-integration-config.ts +101 -0
  1809. package/src/shared/merge-by-id.ts +14 -0
  1810. package/src/shared/oauth-state.ts +39 -0
  1811. package/src/shared/reasoning-effort.ts +228 -0
  1812. package/src/shared/route-warmup-config.ts +128 -0
  1813. package/src/shared/runtime.ts +31 -0
  1814. package/src/shared/social-meta.ts +82 -0
  1815. package/src/shared/streaming-text-smoothing.ts +184 -0
  1816. package/src/shared/truncate.ts +13 -0
  1817. package/src/shared/workspace-app-audience.ts +177 -0
  1818. package/src/shared/workspace-app-id.ts +54 -0
  1819. package/src/sharing/access.ts +585 -0
  1820. package/src/sharing/actions/create-agent-resource-link.ts +91 -0
  1821. package/src/sharing/actions/extension-change.ts +22 -0
  1822. package/src/sharing/actions/list-resource-shares.ts +93 -0
  1823. package/src/sharing/actions/set-resource-visibility.ts +91 -0
  1824. package/src/sharing/actions/share-resource.ts +322 -0
  1825. package/src/sharing/actions/unshare-resource.ts +72 -0
  1826. package/src/sharing/index.ts +35 -0
  1827. package/src/sharing/registry.ts +201 -0
  1828. package/src/sharing/schema.ts +99 -0
  1829. package/src/styles/agent-conversation.css +766 -0
  1830. package/src/styles/agent-native.css +938 -0
  1831. package/src/styles/blocks.css +1717 -0
  1832. package/src/styles/chat-history-list.css +1 -0
  1833. package/src/styles/rich-markdown-editor.css +1 -0
  1834. package/src/tailwind.preset.ts +140 -0
  1835. package/src/templates/chat/.agents/skills/actions/SKILL.md +32 -12
  1836. package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +21 -9
  1837. package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  1838. package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +14 -2
  1839. package/src/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  1840. package/src/templates/chat/AGENTS.md +6 -2
  1841. package/src/templates/chat/app/components/layout/Sidebar.tsx +51 -157
  1842. package/src/templates/default/.agents/skills/actions/SKILL.md +32 -12
  1843. package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +21 -9
  1844. package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  1845. package/src/templates/default/.agents/skills/integration-webhooks/SKILL.md +323 -0
  1846. package/src/templates/default/.agents/skills/onboarding/SKILL.md +56 -0
  1847. package/src/templates/default/.agents/skills/secrets/SKILL.md +273 -0
  1848. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +14 -2
  1849. package/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  1850. package/src/templates/default/AGENTS.md +26 -18
  1851. package/src/templates/headless/.agents/skills/actions/SKILL.md +512 -0
  1852. package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +21 -9
  1853. package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  1854. package/src/templates/headless/.agents/skills/integration-webhooks/SKILL.md +323 -0
  1855. package/src/templates/headless/.agents/skills/secrets/SKILL.md +273 -0
  1856. package/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  1857. package/src/templates/headless/AGENTS.md +8 -0
  1858. package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +32 -12
  1859. package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +21 -9
  1860. package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +7 -0
  1861. package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +145 -0
  1862. package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +14 -2
  1863. package/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +6 -0
  1864. package/src/templates/workspace-core/AGENTS.md +4 -0
  1865. package/src/templates/workspace-root/AGENTS.md +4 -0
  1866. package/src/terminal/cli-registry.ts +57 -0
  1867. package/src/terminal/index.ts +22 -0
  1868. package/src/terminal/pty-server.ts +389 -0
  1869. package/src/terminal/terminal-plugin.ts +265 -0
  1870. package/src/testing.ts +23 -0
  1871. package/src/tracking/index.ts +10 -0
  1872. package/src/tracking/providers.ts +422 -0
  1873. package/src/tracking/registry.ts +102 -0
  1874. package/src/tracking/route.ts +108 -0
  1875. package/src/tracking/types.ts +16 -0
  1876. package/src/transcription/builder-transcription.ts +118 -0
  1877. package/src/triggers/actions/list-automations.ts +99 -0
  1878. package/src/triggers/actions/manage-automation.ts +78 -0
  1879. package/src/triggers/actions.ts +333 -0
  1880. package/src/triggers/condition-evaluator.ts +163 -0
  1881. package/src/triggers/dispatcher.ts +536 -0
  1882. package/src/triggers/index.ts +13 -0
  1883. package/src/triggers/routes.ts +322 -0
  1884. package/src/triggers/types.ts +42 -0
  1885. package/src/types/pglite.d.ts +26 -0
  1886. package/src/usage/store.ts +698 -0
  1887. package/src/vite/action-types-plugin.ts +481 -0
  1888. package/src/vite/agent-web-plugin.ts +78 -0
  1889. package/src/vite/agents-bundle-plugin.ts +185 -0
  1890. package/src/vite/client.ts +3039 -0
  1891. package/src/vite/index.ts +21 -0
  1892. package/src/voice/index.ts +18 -0
  1893. package/src/voice/voice-cleanup-prompt.ts +38 -0
  1894. package/src/voice/voice-context.ts +217 -0
  1895. package/src/voice/voice-replacements.ts +75 -0
  1896. package/src/workspace-connections/credentials.ts +603 -0
  1897. package/src/workspace-connections/index.ts +72 -0
  1898. package/src/workspace-connections/lifecycle.ts +43 -0
  1899. package/src/workspace-connections/store.ts +1943 -0
  1900. package/src/workspace-files/index.ts +18 -0
  1901. package/src/workspace-files/store.ts +339 -0
  1902. package/src/workspace-files/tool.ts +266 -0
@@ -0,0 +1,3039 @@
1
+ import { EventEmitter } from "events";
2
+ import fs from "fs";
3
+ import type { IncomingMessage, ServerResponse } from "http";
4
+ import { createRequire, syncBuiltinESMExports } from "module";
5
+ import path from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ import type {
9
+ ConfigEnv,
10
+ HotUpdateOptions,
11
+ NormalizedHotChannel,
12
+ Plugin,
13
+ UserConfig,
14
+ } from "vite";
15
+
16
+ import {
17
+ mergePendingChangelog,
18
+ parsePendingEntry,
19
+ } from "../changelog/parse.js";
20
+ import { getViteDevRecoveryScript } from "../client/vite-dev-recovery-script.js";
21
+ import { findWorkspaceRoot } from "../scripts/utils.js";
22
+ import { verifyEmbedSessionToken } from "../server/embed-session.js";
23
+ import {
24
+ EMBED_SESSION_COOKIE,
25
+ EMBED_TOKEN_QUERY_PARAM,
26
+ MCP_APP_CHAT_BRIDGE_QUERY_PARAM,
27
+ } from "../shared/embed-auth.js";
28
+ import {
29
+ isMcpEmbedCorsOrigin,
30
+ MCP_EMBED_CORS_ALLOW_HEADERS,
31
+ MCP_EMBED_STATIC_ASSET_HEADERS,
32
+ mcpEmbedStaticAssetRouteRules,
33
+ shouldAllowMcpEmbedCredentials,
34
+ } from "../shared/mcp-embed-headers.js";
35
+ import {
36
+ normalizeMcpIntegrationsConfig,
37
+ type McpIntegrationsConfigInput,
38
+ } from "../shared/mcp-integration-config.js";
39
+ import {
40
+ normalizeAgentNativeRouteWarmupConfig,
41
+ type AgentNativeRouteWarmupConfigInput,
42
+ } from "../shared/route-warmup-config.js";
43
+ import { actionTypesPlugin } from "./action-types-plugin.js";
44
+ import { agentsBundlePlugin } from "./agents-bundle-plugin.js";
45
+
46
+ const require = createRequire(import.meta.url);
47
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
48
+ let nitroFsWatchGuardInstalled = false;
49
+
50
+ type FsWatchArgs = [fs.PathLike, ...any[]];
51
+
52
+ function isFileWatchLimitError(
53
+ error: NodeJS.ErrnoException | undefined,
54
+ ): boolean {
55
+ return error?.code === "EMFILE" || error?.code === "ENOSPC";
56
+ }
57
+
58
+ function watchPollingIntervalMs(): number {
59
+ const raw = Number(process.env.CHOKIDAR_INTERVAL ?? 1000);
60
+ return Number.isFinite(raw) && raw > 0 ? raw : 1000;
61
+ }
62
+
63
+ function fsWatchListener(args: FsWatchArgs): fs.WatchListener<string> | null {
64
+ const maybeOptionsOrListener = args[1];
65
+ const maybeListener = args[2];
66
+ if (typeof maybeOptionsOrListener === "function")
67
+ return maybeOptionsOrListener as fs.WatchListener<string>;
68
+ if (typeof maybeListener === "function")
69
+ return maybeListener as fs.WatchListener<string>;
70
+ return null;
71
+ }
72
+
73
+ function fsWatchPersistent(args: FsWatchArgs): boolean {
74
+ const options = args[1];
75
+ if (!options || typeof options === "function") return true;
76
+ if (typeof options === "string" || Buffer.isBuffer(options)) return true;
77
+ return options.persistent !== false;
78
+ }
79
+
80
+ function directEntrySnapshot(
81
+ target: string,
82
+ ): Map<string, { mtimeMs: number; size: number; directory: boolean }> {
83
+ const snapshot = new Map<
84
+ string,
85
+ { mtimeMs: number; size: number; directory: boolean }
86
+ >();
87
+ const stat = fs.statSync(target);
88
+ if (!stat.isDirectory()) {
89
+ snapshot.set(path.basename(target), {
90
+ mtimeMs: stat.mtimeMs,
91
+ size: stat.size,
92
+ directory: false,
93
+ });
94
+ return snapshot;
95
+ }
96
+ for (const entry of fs.readdirSync(target, { withFileTypes: true })) {
97
+ const entryPath = path.join(target, entry.name);
98
+ try {
99
+ const entryStat = fs.statSync(entryPath);
100
+ snapshot.set(entry.name, {
101
+ mtimeMs: entryStat.mtimeMs,
102
+ size: entryStat.size,
103
+ directory: entryStat.isDirectory(),
104
+ });
105
+ } catch {
106
+ // The entry may have disappeared between readdir and stat.
107
+ }
108
+ }
109
+ return snapshot;
110
+ }
111
+
112
+ function createPollingFsWatcher(args: FsWatchArgs): fs.FSWatcher {
113
+ const target = String(args[0]);
114
+ const listener = fsWatchListener(args);
115
+ const emitter = new EventEmitter() as fs.FSWatcher;
116
+ let closed = false;
117
+ let previous = directEntrySnapshot(target);
118
+
119
+ if (listener) emitter.on("change", listener);
120
+
121
+ const emitChange = (eventName: "change" | "rename", filename: string) => {
122
+ emitter.emit("change", eventName, filename);
123
+ };
124
+
125
+ const timer = setInterval(() => {
126
+ if (closed) return;
127
+ let next: typeof previous;
128
+ try {
129
+ next = directEntrySnapshot(target);
130
+ } catch (error) {
131
+ emitter.emit("error", error);
132
+ return;
133
+ }
134
+
135
+ for (const [filename, current] of next) {
136
+ const old = previous.get(filename);
137
+ if (!old) {
138
+ emitChange("rename", filename);
139
+ continue;
140
+ }
141
+ if (
142
+ old.mtimeMs !== current.mtimeMs ||
143
+ old.size !== current.size ||
144
+ old.directory !== current.directory
145
+ ) {
146
+ emitChange("change", filename);
147
+ }
148
+ }
149
+ for (const filename of previous.keys()) {
150
+ if (!next.has(filename)) emitChange("rename", filename);
151
+ }
152
+ previous = next;
153
+ }, watchPollingIntervalMs());
154
+
155
+ if (!fsWatchPersistent(args)) timer.unref();
156
+
157
+ emitter.close = () => {
158
+ if (closed) return;
159
+ closed = true;
160
+ clearInterval(timer);
161
+ emitter.removeAllListeners();
162
+ };
163
+ emitter.ref = () => {
164
+ timer.ref();
165
+ return emitter;
166
+ };
167
+ emitter.unref = () => {
168
+ timer.unref();
169
+ return emitter;
170
+ };
171
+
172
+ return emitter;
173
+ }
174
+
175
+ function warnNitroFsWatchFallback(target: unknown, err: NodeJS.ErrnoException) {
176
+ console.warn(
177
+ `[agent-native] Falling back to polling Nitro fs.watch for ${String(target)}: ${err.message}`,
178
+ );
179
+ }
180
+
181
+ function installNitroFsWatchGuard(): void {
182
+ if (nitroFsWatchGuardInstalled) return;
183
+ nitroFsWatchGuardInstalled = true;
184
+
185
+ const originalWatch = fs.watch.bind(fs) as (...args: any[]) => fs.FSWatcher;
186
+ (fs as typeof fs & { watch: (...args: any[]) => fs.FSWatcher }).watch = (
187
+ ...args: any[]
188
+ ) => {
189
+ let watcher: fs.FSWatcher;
190
+ try {
191
+ watcher = originalWatch(...args);
192
+ } catch (error) {
193
+ const err = error as NodeJS.ErrnoException;
194
+ if (!isFileWatchLimitError(err)) throw error;
195
+ warnNitroFsWatchFallback(args[0], err);
196
+ return createPollingFsWatcher(args as FsWatchArgs);
197
+ }
198
+
199
+ const originalEmit = watcher.emit.bind(watcher);
200
+ const originalClose = watcher.close.bind(watcher);
201
+ let pollingFallback: fs.FSWatcher | undefined;
202
+
203
+ watcher.close = (() => {
204
+ pollingFallback?.close();
205
+ return originalClose();
206
+ }) as fs.FSWatcher["close"];
207
+
208
+ watcher.emit = ((eventName: string | symbol, ...eventArgs: any[]) => {
209
+ const err = eventArgs[0] as NodeJS.ErrnoException | undefined;
210
+ if (eventName === "error" && isFileWatchLimitError(err) && err) {
211
+ warnNitroFsWatchFallback(args[0], err);
212
+ watcher.close();
213
+ pollingFallback = createPollingFsWatcher(args as FsWatchArgs);
214
+ pollingFallback.on("change", (changeEvent, filename) => {
215
+ originalEmit("change", changeEvent, filename);
216
+ });
217
+ pollingFallback.on("error", (pollingError) => {
218
+ originalEmit("error", pollingError);
219
+ });
220
+ return false;
221
+ }
222
+ return originalEmit(eventName, ...eventArgs);
223
+ }) as fs.FSWatcher["emit"];
224
+ return watcher;
225
+ };
226
+ syncBuiltinESMExports();
227
+ }
228
+
229
+ function nitroVitePlugin(
230
+ ...args: Parameters<typeof import("nitro/vite").nitro>
231
+ ) {
232
+ installNitroFsWatchGuard();
233
+ const plugins = require("nitro/vite").nitro(...args) as Plugin[];
234
+ return plugins.map(debounceNitroFullReloadHotUpdate);
235
+ }
236
+
237
+ /**
238
+ * Debounce window for coalescing Nitro's dev-mode full-reload broadcasts.
239
+ *
240
+ * Nitro's own Vite plugin (the `hotUpdate` hook inside `nitro/vite`)
241
+ * invalidates each changed server module in the module graph synchronously,
242
+ * then sends `{ type: "full-reload" }` over that environment's hot channel —
243
+ * once per file-change event, with no debounce of its own. Every full-reload
244
+ * makes the Nitro dev worker re-import the entire SSR/server entry point,
245
+ * which is expensive. AI coding agents routinely write dozens of files in a
246
+ * single burst, so one edit session can trigger dozens of sequential
247
+ * re-imports back to back and pin a CPU core for minutes. This is a distinct
248
+ * concern from `fullReloadOnOptimizeDep504` elsewhere in this file (which
249
+ * rate-limits an unrelated client-reload nudge); keep the two independent.
250
+ */
251
+ const NITRO_FULL_RELOAD_DEBOUNCE_MS = 300;
252
+
253
+ /**
254
+ * Wraps a single Nitro-provided Vite plugin so that, if it defines a
255
+ * `hotUpdate` hook, any `environment.hot.send({ type: "full-reload" })` call
256
+ * made from inside that hook is coalesced with a trailing debounce (leading
257
+ * edge suppressed) instead of firing immediately for every changed file.
258
+ * Everything else — module-graph invalidation, non-reload hot messages, the
259
+ * hook's return value — passes through unchanged and immediate. A burst of
260
+ * N changes within the debounce window collapses into exactly one
261
+ * full-reload once things go quiet; a single isolated change still reloads,
262
+ * just delayed by up to `NITRO_FULL_RELOAD_DEBOUNCE_MS`.
263
+ *
264
+ * `hotUpdate` only ever runs on Vite's dev server (never during a build), so
265
+ * this has no effect outside `vite dev`.
266
+ */
267
+ function debounceNitroFullReloadHotUpdate(plugin: Plugin): Plugin {
268
+ const originalHook = plugin.hotUpdate;
269
+ if (!originalHook) return plugin;
270
+
271
+ // Vite hook properties are either a plain function or `{ handler, ... }`
272
+ // ("object form", used to attach hook metadata like `order`). Support both.
273
+ const isHandlerForm = typeof originalHook === "object";
274
+ const originalHandler = (
275
+ isHandlerForm
276
+ ? (originalHook as { handler: unknown }).handler
277
+ : originalHook
278
+ ) as (
279
+ this: { environment: { name: string; hot: NormalizedHotChannel } },
280
+ options: HotUpdateOptions,
281
+ ) => unknown;
282
+
283
+ // One pending-reload timer per Vite environment name ("ssr" by default, or
284
+ // a named Nitro service environment), so unrelated environments can never
285
+ // block or coalesce into each other.
286
+ const pendingReloadTimers = new Map<string, ReturnType<typeof setTimeout>>();
287
+
288
+ function wrappedHotUpdate(
289
+ this: { environment: { name: string; hot: NormalizedHotChannel } },
290
+ options: HotUpdateOptions,
291
+ ) {
292
+ const realEnvironment = this.environment;
293
+ // Proxy `this.environment.hot.send` so nitro's hook body (which reads
294
+ // `this.environment` and calls `env.hot.send(...)`) is otherwise
295
+ // untouched — only full-reload payloads get intercepted below.
296
+ const proxiedThis = new Proxy(this, {
297
+ get(target, prop, receiver) {
298
+ if (prop !== "environment") {
299
+ return Reflect.get(target, prop, receiver);
300
+ }
301
+ return new Proxy(realEnvironment, {
302
+ get(envTarget, envProp, envReceiver) {
303
+ if (envProp !== "hot") {
304
+ return Reflect.get(envTarget, envProp, envReceiver);
305
+ }
306
+ const realHot = envTarget.hot;
307
+ return new Proxy(realHot, {
308
+ get(hotTarget, hotProp, hotReceiver) {
309
+ if (hotProp !== "send") {
310
+ return Reflect.get(hotTarget, hotProp, hotReceiver);
311
+ }
312
+ return (payload: unknown) => {
313
+ if (
314
+ !payload ||
315
+ typeof payload !== "object" ||
316
+ (payload as { type?: string }).type !== "full-reload"
317
+ ) {
318
+ // Not a full-reload — pass through immediately.
319
+ return (hotTarget.send as (p: unknown) => void)(payload);
320
+ }
321
+ const key = realEnvironment.name || "default";
322
+ const pending = pendingReloadTimers.get(key);
323
+ if (pending) clearTimeout(pending);
324
+ const timer = setTimeout(() => {
325
+ pendingReloadTimers.delete(key);
326
+ (hotTarget.send as (p: unknown) => void)(payload);
327
+ }, NITRO_FULL_RELOAD_DEBOUNCE_MS);
328
+ // Never hold the process open just for a pending reload.
329
+ timer.unref?.();
330
+ pendingReloadTimers.set(key, timer);
331
+ };
332
+ },
333
+ });
334
+ },
335
+ });
336
+ },
337
+ });
338
+ return originalHandler.call(proxiedThis, options);
339
+ }
340
+
341
+ if (isHandlerForm) {
342
+ return {
343
+ ...plugin,
344
+ hotUpdate: {
345
+ ...(originalHook as object),
346
+ handler: wrappedHotUpdate,
347
+ },
348
+ } as Plugin;
349
+ }
350
+ return { ...plugin, hotUpdate: wrappedHotUpdate } as Plugin;
351
+ }
352
+
353
+ /**
354
+ * Sync discovery for the workspace-core in an enterprise monorepo.
355
+ *
356
+ * Mirrors `getWorkspaceCoreExports` in deploy/workspace-core.ts but stays
357
+ * synchronous so it can run inline in `defineConfig`. Returns the workspace
358
+ * core's package name + absolute directory, or null if no workspace core is
359
+ * declared in the ancestor chain.
360
+ *
361
+ * Walks up from `startDir` looking for a package.json with
362
+ * `agent-native.workspaceCore`. Resolves the declared package name through
363
+ * `<workspaceRoot>/node_modules/<name>` (pnpm symlink, fastest) or by
364
+ * scanning `packages/*` for a matching `name` field (fallback for
365
+ * pre-install scenarios).
366
+ */
367
+ function findWorkspaceCoreSync(
368
+ startDir: string,
369
+ ): { packageName: string; packageDir: string; workspaceRoot: string } | null {
370
+ // 1) Walk up looking for the root package.json that declares workspaceCore.
371
+ let dir = path.resolve(startDir);
372
+ let workspaceRoot: string | null = null;
373
+ let packageName: string | null = null;
374
+ for (let i = 0; i < 20; i++) {
375
+ const pkgPath = path.join(dir, "package.json");
376
+ if (fs.existsSync(pkgPath)) {
377
+ try {
378
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
379
+ const declared = pkg?.["agent-native"]?.workspaceCore;
380
+ if (typeof declared === "string" && declared.length > 0) {
381
+ workspaceRoot = dir;
382
+ packageName = declared;
383
+ break;
384
+ }
385
+ } catch {
386
+ // Malformed package.json — keep walking up.
387
+ }
388
+ }
389
+ const parent = path.dirname(dir);
390
+ if (parent === dir) break;
391
+ dir = parent;
392
+ }
393
+ if (!workspaceRoot || !packageName) return null;
394
+
395
+ // 2a) pnpm/npm symlink under workspaceRoot/node_modules.
396
+ const nm = path.join(workspaceRoot, "node_modules", packageName);
397
+ if (fs.existsSync(path.join(nm, "package.json"))) {
398
+ return { packageName, packageDir: fs.realpathSync(nm), workspaceRoot };
399
+ }
400
+
401
+ // 2b) Scan packages/* and packages/@scope/* for a matching `name`.
402
+ const packagesDir = path.join(workspaceRoot, "packages");
403
+ if (fs.existsSync(packagesDir)) {
404
+ const candidates: string[] = [];
405
+ for (const entry of fs.readdirSync(packagesDir, { withFileTypes: true })) {
406
+ if (!entry.isDirectory()) continue;
407
+ candidates.push(path.join(packagesDir, entry.name));
408
+ if (entry.name.startsWith("@")) {
409
+ const scopeDir = path.join(packagesDir, entry.name);
410
+ for (const sub of fs.readdirSync(scopeDir, { withFileTypes: true })) {
411
+ if (sub.isDirectory()) candidates.push(path.join(scopeDir, sub.name));
412
+ }
413
+ }
414
+ }
415
+ for (const c of candidates) {
416
+ const p = path.join(c, "package.json");
417
+ if (!fs.existsSync(p)) continue;
418
+ try {
419
+ const pkg = JSON.parse(fs.readFileSync(p, "utf-8"));
420
+ if (pkg?.name === packageName)
421
+ return { packageName, packageDir: fs.realpathSync(c), workspaceRoot };
422
+ } catch {
423
+ // ignore malformed package.json
424
+ }
425
+ }
426
+ }
427
+ return null;
428
+ }
429
+
430
+ function findLocalWorkspacePackageDeps(
431
+ startDir: string,
432
+ workspaceRoot: string | null,
433
+ ): Array<{ packageName: string; packageDir: string }> {
434
+ const pkgPath = path.join(startDir, "package.json");
435
+ if (!fs.existsSync(pkgPath)) return [];
436
+
437
+ try {
438
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
439
+ const deps = {
440
+ ...(pkg.dependencies ?? {}),
441
+ ...(pkg.devDependencies ?? {}),
442
+ ...(pkg.peerDependencies ?? {}),
443
+ } as Record<string, string>;
444
+ const seen = new Set<string>();
445
+ const packages: Array<{ packageName: string; packageDir: string }> = [];
446
+
447
+ for (const [packageName, range] of Object.entries(deps)) {
448
+ if (seen.has(packageName)) continue;
449
+ seen.add(packageName);
450
+
451
+ try {
452
+ let packageJsonPath: string | null = null;
453
+ if (range.startsWith("file:")) {
454
+ packageJsonPath = findFilePackageJsonPath(pkgPath, range);
455
+ } else if (range.startsWith("workspace:")) {
456
+ packageJsonPath = findWorkspacePackageJsonPath(
457
+ pkgPath,
458
+ packageName,
459
+ workspaceRoot,
460
+ );
461
+ } else {
462
+ continue;
463
+ }
464
+ if (!packageJsonPath) continue;
465
+ const packageDir = fs.realpathSync(path.dirname(packageJsonPath));
466
+ const packageJson = JSON.parse(
467
+ fs.readFileSync(packageJsonPath, "utf-8"),
468
+ );
469
+ if (packageJson?.name !== packageName) continue;
470
+ packages.push({ packageName, packageDir });
471
+ } catch {
472
+ // Dependency may not have been installed yet; ignore it for dev config.
473
+ }
474
+ }
475
+
476
+ return packages;
477
+ } catch {
478
+ return [];
479
+ }
480
+ }
481
+
482
+ function packagePathSegments(packageName: string): string[] {
483
+ return packageName.split("/");
484
+ }
485
+
486
+ function findWorkspacePackageJsonPath(
487
+ pkgPath: string,
488
+ packageName: string,
489
+ workspaceRoot: string | null,
490
+ ): string | null {
491
+ const packageSegments = packagePathSegments(packageName);
492
+ const candidates = [
493
+ path.join(path.dirname(pkgPath), "node_modules", ...packageSegments),
494
+ ...(workspaceRoot
495
+ ? [path.join(workspaceRoot, "node_modules", ...packageSegments)]
496
+ : []),
497
+ ];
498
+
499
+ for (const candidate of candidates) {
500
+ const packageJsonPath = path.join(candidate, "package.json");
501
+ if (!fs.existsSync(packageJsonPath)) continue;
502
+ const realPath = fs.realpathSync(packageJsonPath);
503
+ if (
504
+ workspaceRoot &&
505
+ !realPath.startsWith(`${fs.realpathSync(workspaceRoot)}${path.sep}`)
506
+ ) {
507
+ continue;
508
+ }
509
+ return realPath;
510
+ }
511
+
512
+ if (workspaceRoot) {
513
+ return findWorkspacePackageJsonByName(workspaceRoot, packageName);
514
+ }
515
+
516
+ return null;
517
+ }
518
+
519
+ function findWorkspacePackageJsonByName(
520
+ workspaceRoot: string,
521
+ packageName: string,
522
+ ): string | null {
523
+ const searchRoots = ["packages", "templates"].map((name) =>
524
+ path.join(workspaceRoot, name),
525
+ );
526
+
527
+ for (const searchRoot of searchRoots) {
528
+ const packageJsonPath = findPackageJsonInTree(searchRoot, packageName, 2);
529
+ if (packageJsonPath) return packageJsonPath;
530
+ }
531
+
532
+ return null;
533
+ }
534
+
535
+ function findPackageJsonInTree(
536
+ root: string,
537
+ packageName: string,
538
+ maxDepth: number,
539
+ ): string | null {
540
+ if (!fs.existsSync(root)) return null;
541
+
542
+ const packageJsonPath = path.join(root, "package.json");
543
+ if (fs.existsSync(packageJsonPath)) {
544
+ try {
545
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
546
+ if (pkg?.name === packageName) return fs.realpathSync(packageJsonPath);
547
+ } catch {
548
+ // Ignore malformed workspace package metadata.
549
+ }
550
+ }
551
+
552
+ if (maxDepth <= 0) return null;
553
+
554
+ for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
555
+ if (!entry.isDirectory()) continue;
556
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
557
+
558
+ const found = findPackageJsonInTree(
559
+ path.join(root, entry.name),
560
+ packageName,
561
+ maxDepth - 1,
562
+ );
563
+ if (found) return found;
564
+ }
565
+
566
+ return null;
567
+ }
568
+
569
+ function findFilePackageJsonPath(
570
+ pkgPath: string,
571
+ range: string,
572
+ ): string | null {
573
+ const spec = range.slice("file:".length);
574
+ const packageDir = spec.startsWith("//")
575
+ ? fileURLToPath(range)
576
+ : path.resolve(path.dirname(pkgPath), spec);
577
+ const packageJsonPath = path.join(packageDir, "package.json");
578
+ return fs.existsSync(packageJsonPath) ? packageJsonPath : null;
579
+ }
580
+
581
+ function findPnpmWorkspaceRoot(startDir: string): string | null {
582
+ let dir = path.resolve(startDir);
583
+ for (let i = 0; i < 20; i++) {
584
+ if (fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) return dir;
585
+ const parent = path.dirname(dir);
586
+ if (parent === dir) break;
587
+ dir = parent;
588
+ }
589
+ return null;
590
+ }
591
+
592
+ /** Escape a string so it can be embedded as a regex literal. */
593
+ function escapeRegex(s: string): string {
594
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
595
+ }
596
+
597
+ /** Check if a package is installed in the project */
598
+ function hasDep(pkg: string, cwd: string): boolean {
599
+ try {
600
+ const pkgJson = JSON.parse(
601
+ fs.readFileSync(path.join(cwd, "package.json"), "utf-8"),
602
+ );
603
+ return !!(
604
+ pkgJson.dependencies?.[pkg] ||
605
+ pkgJson.devDependencies?.[pkg] ||
606
+ pkgJson.peerDependencies?.[pkg]
607
+ );
608
+ } catch {
609
+ return false;
610
+ }
611
+ }
612
+
613
+ function hasCoreDep(pkg: string, cwd: string): boolean {
614
+ const coreRoot = findCorePackageRoot(cwd);
615
+ if (!coreRoot) return false;
616
+ try {
617
+ const pkgJson = JSON.parse(
618
+ fs.readFileSync(path.join(coreRoot, "package.json"), "utf-8"),
619
+ );
620
+ return !!(pkgJson.dependencies?.[pkg] || pkgJson.devDependencies?.[pkg]);
621
+ } catch {
622
+ return false;
623
+ }
624
+ }
625
+
626
+ function hasOptimizeDep(pkg: string, cwd: string): boolean {
627
+ return hasDep(pkg, cwd) || hasCoreDep(pkg, cwd);
628
+ }
629
+
630
+ /**
631
+ * Build the `resolve.dedupe` list dynamically. Reads core's package.json and
632
+ * collects every peerDependency that the consuming app also declares. This
633
+ * ensures Vite resolves them from the app root, not from core's own
634
+ * node_modules — preventing duplicate React context / singleton issues.
635
+ */
636
+ function getClientDedupe(cwd: string): string[] {
637
+ // Always dedupe React internals (sub-path exports aren't in peerDeps)
638
+ const always = new Set([
639
+ "react",
640
+ "react-dom",
641
+ "react-dom/client",
642
+ // Framework routers must share one react-router instance so
643
+ // FrameworkContext (Meta/Links/Scripts) matches ServerRouter/HydratedRouter.
644
+ ...(hasDep("react-router", cwd)
645
+ ? ["react-router", "react-router/dom"]
646
+ : []),
647
+ ]);
648
+
649
+ // Server-only packages that never run in the browser — no point deduping.
650
+ const serverOnly = new Set([
651
+ "drizzle-kit",
652
+ "node-pty",
653
+ "postgres",
654
+ "ws",
655
+ "typescript",
656
+ "vite",
657
+ "@vitejs/plugin-react-swc",
658
+ "tailwindcss",
659
+ "@tailwindcss/vite",
660
+ ]);
661
+
662
+ try {
663
+ const corePkgPath = path.resolve(__dirname, "../../package.json");
664
+ const corePkg = JSON.parse(fs.readFileSync(corePkgPath, "utf-8"));
665
+
666
+ // Scan both peerDependencies and dependencies. Direct deps like
667
+ // @radix-ui/* use React internally — they must resolve against the
668
+ // app's React, not a second copy inside core's node_modules.
669
+ const coreDeps = new Set([
670
+ ...Object.keys(corePkg.peerDependencies ?? {}),
671
+ ...Object.keys(corePkg.dependencies ?? {}),
672
+ ]);
673
+
674
+ // Read the consuming app's dependencies
675
+ const appPkg = JSON.parse(
676
+ fs.readFileSync(path.join(cwd, "package.json"), "utf-8"),
677
+ );
678
+ const appDeps = new Set([
679
+ ...Object.keys(appPkg.dependencies ?? {}),
680
+ ...Object.keys(appPkg.devDependencies ?? {}),
681
+ ]);
682
+
683
+ for (const dep of coreDeps) {
684
+ if (serverOnly.has(dep)) continue;
685
+ // Dedupe if the app also declares it, OR if it's a React-based
686
+ // UI library (Radix, Tanstack) that must share the app's React.
687
+ if (
688
+ appDeps.has(dep) ||
689
+ dep.startsWith("@radix-ui/") ||
690
+ dep.startsWith("@tanstack/")
691
+ ) {
692
+ always.add(dep);
693
+ }
694
+ }
695
+ } catch {
696
+ // Can't read package.json — fall back to known singletons
697
+ }
698
+
699
+ return [...always];
700
+ }
701
+
702
+ /**
703
+ * Locate `packages/core/src` if we're inside the framework monorepo.
704
+ * Shared between `getCoreSourceAliases` (which redirects imports to src/)
705
+ * and `getDefaultOptimizeDeps` (which must NOT prebundle from dist/ when
706
+ * the alias is active — otherwise the prebundle is built from a snapshot
707
+ * of dist/ at startup and never picks up new exports).
708
+ */
709
+ function findCorePackageRoot(cwd: string): string | null {
710
+ try {
711
+ const pkg = JSON.parse(
712
+ fs.readFileSync(path.join(cwd, "package.json"), "utf-8"),
713
+ ) as {
714
+ dependencies?: Record<string, string>;
715
+ devDependencies?: Record<string, string>;
716
+ };
717
+ const spec =
718
+ pkg.dependencies?.["@agent-native/core"] ??
719
+ pkg.devDependencies?.["@agent-native/core"];
720
+ if (typeof spec === "string" && spec.startsWith("file:")) {
721
+ const rooted = fileURLToPath(spec);
722
+ if (fs.existsSync(path.join(rooted, "src/index.ts"))) return rooted;
723
+ }
724
+ } catch {
725
+ // package.json missing or unreadable — fall through to path heuristics.
726
+ }
727
+
728
+ const candidates = [
729
+ path.resolve(cwd, "../../packages/core"), // templates/<name>/
730
+ path.resolve(cwd, "../core"), // packages/<name>/
731
+ path.resolve(cwd, "node_modules/@agent-native/core"),
732
+ ];
733
+ for (const candidate of candidates) {
734
+ try {
735
+ if (!fs.existsSync(candidate)) continue;
736
+ const root = fs.realpathSync(candidate);
737
+ if (fs.existsSync(path.join(root, "src/index.ts"))) return root;
738
+ } catch {
739
+ continue;
740
+ }
741
+ }
742
+ return null;
743
+ }
744
+
745
+ function findCoreSrcDir(cwd: string): string | null {
746
+ const root = findCorePackageRoot(cwd);
747
+ return root ? path.join(root, "src") : null;
748
+ }
749
+
750
+ /**
751
+ * Pin react-router imports to the consuming app's install. pnpm keeps a peer
752
+ * copy under `@agent-native/core/node_modules/react-router`; `resolve.dedupe`
753
+ * alone can still leave SSR `Meta`/`Links` on a different FrameworkContext
754
+ * than React Router's dev server router.
755
+ */
756
+ function getReactRouterAliases(
757
+ cwd: string,
758
+ ): Array<{ find: RegExp; replacement: string }> {
759
+ if (!hasDep("react-router", cwd)) return [];
760
+ try {
761
+ const req = createRequire(path.join(cwd, "package.json"));
762
+ return [
763
+ {
764
+ find: /^react-router\/dom$/,
765
+ replacement: req.resolve("react-router/dom"),
766
+ },
767
+ { find: /^react-router$/, replacement: req.resolve("react-router") },
768
+ ];
769
+ } catch {
770
+ return [];
771
+ }
772
+ }
773
+
774
+ /**
775
+ * Every `@agent-native/core` subpath that gets a source alias. Must stay in
776
+ * sync with `getCoreSourceAliases`. Used by `getDefaultOptimizeDeps` to skip
777
+ * prebundling in monorepo mode, and by the consumer config to add them to
778
+ * `optimizeDeps.exclude` so Vite always resolves them through the source
779
+ * alias on every request — never from a stale dist/ snapshot.
780
+ */
781
+ const CORE_CLIENT_SUBPATHS = [
782
+ "@agent-native/core",
783
+ "@agent-native/core/client",
784
+ "@agent-native/core/client/agent-chat",
785
+ "@agent-native/core/client/analytics",
786
+ "@agent-native/core/client/automation",
787
+ "@agent-native/core/client/chat",
788
+ "@agent-native/core/client/changelog",
789
+ "@agent-native/core/client/collab",
790
+ "@agent-native/core/client/composer",
791
+ "@agent-native/core/client/conversation",
792
+ "@agent-native/core/client/dev-overlay",
793
+ "@agent-native/core/client/editor",
794
+ "@agent-native/core/client/rich-markdown-editor",
795
+ "@agent-native/core/client/components/ui/dialog",
796
+ "@agent-native/core/client/components/ui/dropdown-menu",
797
+ "@agent-native/core/client/components/ui/hover-card",
798
+ "@agent-native/core/client/components/ui/popover",
799
+ "@agent-native/core/client/components/ui/sheet",
800
+ "@agent-native/core/client/components/ui/tooltip",
801
+ "@agent-native/core/client/components/AgentPresenceChip",
802
+ "@agent-native/core/client/components/LiveCursorOverlay",
803
+ "@agent-native/core/client/components/PresenceBar",
804
+ "@agent-native/core/client/components/RecentEditHighlights",
805
+ "@agent-native/core/client/components/RemoteSelectionRings",
806
+ "@agent-native/core/client/visual-style-controls",
807
+ "@agent-native/core/client/feature-flags",
808
+ "@agent-native/core/client/hooks",
809
+ "@agent-native/core/client/host",
810
+ "@agent-native/core/client/i18n",
811
+ "@agent-native/core/client/integrations",
812
+ "@agent-native/core/client/navigation",
813
+ "@agent-native/core/client/resources",
814
+ "@agent-native/core/client/route-chunk-recovery",
815
+ "@agent-native/core/client/settings",
816
+ "@agent-native/core/client/ui",
817
+ "@agent-native/core/client/uploads",
818
+ "@agent-native/core/client/widgets",
819
+ // Dedicated subpath that exports ONLY appBasePath/agentNativePath/appPath.
820
+ // entry.client.tsx imports from here so it never pulls the full client barrel
821
+ // (and its transitive ~650-700 KB gzip chat stack) onto the critical path.
822
+ "@agent-native/core/client/api-path",
823
+ "@agent-native/core/blocks",
824
+ "@agent-native/core/blocks/server",
825
+ "@agent-native/core/client/extensions",
826
+ "@agent-native/core/client/tools", // legacy alias
827
+ "@agent-native/core/client/org",
828
+ "@agent-native/core/client/db-admin",
829
+ "@agent-native/core/client/observability",
830
+ "@agent-native/core/client/onboarding",
831
+ "@agent-native/core/client/sharing",
832
+ "@agent-native/core/client/notifications",
833
+ "@agent-native/core/client/progress",
834
+ "@agent-native/core/client/transcription/use-live-transcription",
835
+ "@agent-native/core/voice",
836
+ ];
837
+
838
+ const NODE_SSR_NATIVE_EXTERNALS = ["better-sqlite3", "bindings"];
839
+
840
+ function getDefaultOptimizeDeps(cwd: string): string[] {
841
+ const inMonorepo = findCoreSrcDir(cwd) !== null;
842
+ const entries: Array<{ specifier: string; packageName?: string }> = [
843
+ // In monorepo mode the source alias resolves these to src/ on every
844
+ // import, so prebundling from dist/ would just create a stale snapshot.
845
+ // Skip them entirely — `optimizeDeps.exclude` below makes that explicit.
846
+ ...(inMonorepo
847
+ ? []
848
+ : ([
849
+ { specifier: "@agent-native/core" },
850
+ // Client and Toolkit subpaths are deliberately discovered from app
851
+ // imports. Eagerly including every leaf would rebuild the old
852
+ // all-app prebundle under a different set of entry names.
853
+ ] as Array<{ specifier: string; packageName?: string }>)),
854
+ { specifier: "@libsql/client" },
855
+ { specifier: "@amplitude/analytics-browser" },
856
+ { specifier: "@assistant-ui/react" },
857
+ { specifier: "@codemirror/lang-sql" },
858
+ { specifier: "@codemirror/theme-one-dark" },
859
+ { specifier: "@excalidraw/excalidraw" },
860
+ { specifier: "@excalidraw/mermaid-to-excalidraw" },
861
+ {
862
+ specifier: "@modelcontextprotocol/ext-apps/app-bridge",
863
+ packageName: "@modelcontextprotocol/ext-apps",
864
+ },
865
+ { specifier: "@paper-design/shaders-react" },
866
+ { specifier: "@radix-ui/react-accordion" },
867
+ { specifier: "@radix-ui/react-alert-dialog" },
868
+ { specifier: "@radix-ui/react-aspect-ratio" },
869
+ { specifier: "@radix-ui/react-avatar" },
870
+ { specifier: "@radix-ui/react-checkbox" },
871
+ { specifier: "@radix-ui/react-collapsible" },
872
+ { specifier: "@radix-ui/react-context-menu" },
873
+ { specifier: "@radix-ui/react-label" },
874
+ { specifier: "@radix-ui/react-menubar" },
875
+ { specifier: "@radix-ui/react-navigation-menu" },
876
+ { specifier: "@radix-ui/react-popover" },
877
+ { specifier: "@radix-ui/react-progress" },
878
+ { specifier: "@radix-ui/react-radio-group" },
879
+ { specifier: "@radix-ui/react-scroll-area" },
880
+ { specifier: "@radix-ui/react-select" },
881
+ { specifier: "@radix-ui/react-separator" },
882
+ { specifier: "@radix-ui/react-slider" },
883
+ { specifier: "@radix-ui/react-slot" },
884
+ { specifier: "@radix-ui/react-switch" },
885
+ { specifier: "@radix-ui/react-tabs" },
886
+ { specifier: "@radix-ui/react-toast" },
887
+ { specifier: "@radix-ui/react-toggle" },
888
+ { specifier: "@radix-ui/react-toggle-group" },
889
+ { specifier: "@radix-ui/react-tooltip" },
890
+ { specifier: "@sentry/browser" },
891
+ {
892
+ specifier: "@shadcn/react/message-scroller",
893
+ packageName: "@shadcn/react",
894
+ },
895
+ { specifier: "@tanstack/react-query" },
896
+ { specifier: "@tabler/icons-react" },
897
+ { specifier: "@uiw/react-codemirror" },
898
+ { specifier: "@xterm/addon-fit" },
899
+ { specifier: "@xterm/addon-web-links" },
900
+ { specifier: "@xterm/xterm" },
901
+ { specifier: "class-variance-authority" },
902
+ { specifier: "clsx" },
903
+ { specifier: "cmdk" },
904
+ { specifier: "date-fns" },
905
+ { specifier: "drizzle-orm" },
906
+ { specifier: "drizzle-orm/pg-core", packageName: "drizzle-orm" },
907
+ { specifier: "drizzle-orm/sqlite-core", packageName: "drizzle-orm" },
908
+ { specifier: "embla-carousel-react" },
909
+ { specifier: "h3" },
910
+ {
911
+ specifier: "highlight.js/lib/languages/bash",
912
+ packageName: "highlight.js",
913
+ },
914
+ {
915
+ specifier: "highlight.js/lib/languages/css",
916
+ packageName: "highlight.js",
917
+ },
918
+ {
919
+ specifier: "highlight.js/lib/languages/javascript",
920
+ packageName: "highlight.js",
921
+ },
922
+ {
923
+ specifier: "highlight.js/lib/languages/json",
924
+ packageName: "highlight.js",
925
+ },
926
+ {
927
+ specifier: "highlight.js/lib/languages/markdown",
928
+ packageName: "highlight.js",
929
+ },
930
+ {
931
+ specifier: "highlight.js/lib/languages/python",
932
+ packageName: "highlight.js",
933
+ },
934
+ {
935
+ specifier: "highlight.js/lib/languages/sql",
936
+ packageName: "highlight.js",
937
+ },
938
+ {
939
+ specifier: "highlight.js/lib/languages/typescript",
940
+ packageName: "highlight.js",
941
+ },
942
+ {
943
+ specifier: "highlight.js/lib/languages/xml",
944
+ packageName: "highlight.js",
945
+ },
946
+ {
947
+ specifier: "highlight.js/lib/languages/yaml",
948
+ packageName: "highlight.js",
949
+ },
950
+ { specifier: "highlight.js/lib/core", packageName: "highlight.js" },
951
+ { specifier: "html2canvas" },
952
+ { specifier: "i18next" },
953
+ { specifier: "input-otp" },
954
+ { specifier: "lowlight" },
955
+ { specifier: "mermaid" },
956
+ { specifier: "nanoid" },
957
+ { specifier: "next-themes" },
958
+ { specifier: "react-hook-form" },
959
+ { specifier: "react-day-picker" },
960
+ { specifier: "react-i18next" },
961
+ { specifier: "react-markdown" },
962
+ { specifier: "react-dom/server", packageName: "react-dom" },
963
+ { specifier: "react-resizable-panels" },
964
+ { specifier: "recharts" },
965
+ ...(hasDep("react-router", cwd)
966
+ ? [
967
+ { specifier: "react-router" },
968
+ { specifier: "react-router/dom", packageName: "react-router" },
969
+ ]
970
+ : []),
971
+ { specifier: "remark-gfm" },
972
+ { specifier: "roughjs" },
973
+ { specifier: "shiki/core", packageName: "shiki" },
974
+ { specifier: "shiki/engine/javascript", packageName: "shiki" },
975
+ { specifier: "shiki/langs/bash.mjs", packageName: "shiki" },
976
+ { specifier: "shiki/langs/css.mjs", packageName: "shiki" },
977
+ { specifier: "shiki/langs/html.mjs", packageName: "shiki" },
978
+ { specifier: "shiki/langs/javascript.mjs", packageName: "shiki" },
979
+ { specifier: "shiki/langs/json.mjs", packageName: "shiki" },
980
+ { specifier: "shiki/langs/jsx.mjs", packageName: "shiki" },
981
+ { specifier: "shiki/langs/markdown.mjs", packageName: "shiki" },
982
+ { specifier: "shiki/langs/python.mjs", packageName: "shiki" },
983
+ { specifier: "shiki/langs/shellscript.mjs", packageName: "shiki" },
984
+ { specifier: "shiki/langs/sql.mjs", packageName: "shiki" },
985
+ { specifier: "shiki/langs/tsx.mjs", packageName: "shiki" },
986
+ { specifier: "shiki/langs/typescript.mjs", packageName: "shiki" },
987
+ { specifier: "shiki/langs/yaml.mjs", packageName: "shiki" },
988
+ { specifier: "shiki/themes/github-dark-default.mjs", packageName: "shiki" },
989
+ {
990
+ specifier: "shiki/themes/github-light-default.mjs",
991
+ packageName: "shiki",
992
+ },
993
+ { specifier: "sonner" },
994
+ { specifier: "tailwind-merge" },
995
+ ...(hasDep("@agent-native/toolkit", cwd)
996
+ ? [
997
+ {
998
+ specifier:
999
+ "@agent-native/toolkit > @tiptap/react > use-sync-external-store/shim/index.js",
1000
+ packageName: "@agent-native/toolkit",
1001
+ },
1002
+ {
1003
+ specifier:
1004
+ "@agent-native/toolkit > @tiptap/react > use-sync-external-store/shim/with-selector.js",
1005
+ packageName: "@agent-native/toolkit",
1006
+ },
1007
+ {
1008
+ specifier:
1009
+ "@agent-native/toolkit > tiptap-markdown > markdown-it-task-lists",
1010
+ packageName: "@agent-native/toolkit",
1011
+ },
1012
+ ]
1013
+ : []),
1014
+ { specifier: "vaul" },
1015
+ { specifier: "y-protocols/awareness", packageName: "y-protocols" },
1016
+ { specifier: "yjs" },
1017
+ { specifier: "zod" },
1018
+ ];
1019
+
1020
+ return entries
1021
+ .filter(({ specifier, packageName }) =>
1022
+ hasOptimizeDep(packageName ?? specifier, cwd),
1023
+ )
1024
+ .map(({ specifier, packageName }) => {
1025
+ const dependencyName = packageName ?? specifier;
1026
+ // In the monorepo, core is source-aliased and its dependencies live
1027
+ // under packages/core/node_modules. A bare optimizeDeps.include entry
1028
+ // is resolved from the template root, so core-only dependencies fail
1029
+ // the initial prebundle and are rediscovered after the page loads. Vite
1030
+ // then rebundles and reloads the editor. Its documented nested-dependency
1031
+ // syntax resolves the right-hand package from core's package directory,
1032
+ // while app-owned dependencies should remain direct entries.
1033
+ if (
1034
+ inMonorepo &&
1035
+ !hasDep(dependencyName, cwd) &&
1036
+ hasCoreDep(dependencyName, cwd)
1037
+ ) {
1038
+ return `@agent-native/core > ${specifier}`;
1039
+ }
1040
+ return specifier;
1041
+ });
1042
+ }
1043
+
1044
+ /**
1045
+ * In monorepo dev mode, resolve @agent-native/core imports to source (src/)
1046
+ * instead of dist/ so that Vite HMR picks up changes without rebuilding.
1047
+ *
1048
+ * Returns Vite array-style aliases with exact matching (regex anchored with $)
1049
+ * to prevent `@agent-native/core` from prefix-matching and swallowing
1050
+ * sub-path imports like `@agent-native/core/client`.
1051
+ */
1052
+ function getCoreSourceAliases(
1053
+ cwd: string,
1054
+ ): Array<{ find: RegExp; replacement: string }> {
1055
+ const coreSrc = findCoreSrcDir(cwd);
1056
+ if (!coreSrc) return []; // Not in monorepo — use dist as normal
1057
+
1058
+ // Map every @agent-native/core/* export to its src/ equivalent.
1059
+ // Each entry uses a regex with $ anchor for exact matching.
1060
+ const entries: Record<string, string> = {
1061
+ "@agent-native/core": path.join(coreSrc, "index.browser.ts"),
1062
+ "@agent-native/core/server": path.join(coreSrc, "server/index.ts"),
1063
+ "@agent-native/core/server/edge": path.join(coreSrc, "server/edge.ts"),
1064
+ "@agent-native/core/client": path.join(coreSrc, "client/index.ts"),
1065
+ "@agent-native/core/client/agent-chat": path.join(
1066
+ coreSrc,
1067
+ "client/agent-chat/index.ts",
1068
+ ),
1069
+ "@agent-native/core/client/analytics": path.join(
1070
+ coreSrc,
1071
+ "client/analytics/index.ts",
1072
+ ),
1073
+ "@agent-native/core/client/automation": path.join(
1074
+ coreSrc,
1075
+ "client/automation/index.ts",
1076
+ ),
1077
+ "@agent-native/core/client/chat": path.join(
1078
+ coreSrc,
1079
+ "client/chat/index.ts",
1080
+ ),
1081
+ "@agent-native/core/client/changelog": path.join(
1082
+ coreSrc,
1083
+ "client/changelog/index.ts",
1084
+ ),
1085
+ "@agent-native/core/client/collab": path.join(
1086
+ coreSrc,
1087
+ "client/collab/index.ts",
1088
+ ),
1089
+ "@agent-native/core/client/composer": path.join(
1090
+ coreSrc,
1091
+ "client/composer/index.ts",
1092
+ ),
1093
+ "@agent-native/core/client/conversation": path.join(
1094
+ coreSrc,
1095
+ "client/conversation/index.ts",
1096
+ ),
1097
+ "@agent-native/core/client/dev-overlay": path.join(
1098
+ coreSrc,
1099
+ "client/dev-overlay/index.ts",
1100
+ ),
1101
+ "@agent-native/core/client/editor": path.join(
1102
+ coreSrc,
1103
+ "client/tombstone/editor.ts",
1104
+ ),
1105
+ "@agent-native/core/client/rich-markdown-editor": path.join(
1106
+ coreSrc,
1107
+ "client/tombstone/rich-markdown-editor.ts",
1108
+ ),
1109
+ "@agent-native/core/client/components/ui/dialog": path.join(
1110
+ coreSrc,
1111
+ "client/tombstone/ui-dialog.ts",
1112
+ ),
1113
+ "@agent-native/core/client/components/ui/dropdown-menu": path.join(
1114
+ coreSrc,
1115
+ "client/tombstone/ui-dropdown-menu.ts",
1116
+ ),
1117
+ "@agent-native/core/client/components/ui/hover-card": path.join(
1118
+ coreSrc,
1119
+ "client/tombstone/ui-hover-card.ts",
1120
+ ),
1121
+ "@agent-native/core/client/components/ui/popover": path.join(
1122
+ coreSrc,
1123
+ "client/tombstone/ui-popover.ts",
1124
+ ),
1125
+ "@agent-native/core/client/components/ui/sheet": path.join(
1126
+ coreSrc,
1127
+ "client/tombstone/ui-sheet.ts",
1128
+ ),
1129
+ "@agent-native/core/client/components/ui/tooltip": path.join(
1130
+ coreSrc,
1131
+ "client/tombstone/ui-tooltip.ts",
1132
+ ),
1133
+ "@agent-native/core/client/components/AgentPresenceChip": path.join(
1134
+ coreSrc,
1135
+ "client/tombstone/agent-presence-chip.ts",
1136
+ ),
1137
+ "@agent-native/core/client/components/LiveCursorOverlay": path.join(
1138
+ coreSrc,
1139
+ "client/tombstone/live-cursor-overlay.ts",
1140
+ ),
1141
+ "@agent-native/core/client/components/PresenceBar": path.join(
1142
+ coreSrc,
1143
+ "client/tombstone/presence-bar.ts",
1144
+ ),
1145
+ "@agent-native/core/client/components/RecentEditHighlights": path.join(
1146
+ coreSrc,
1147
+ "client/tombstone/recent-edit-highlights.ts",
1148
+ ),
1149
+ "@agent-native/core/client/components/RemoteSelectionRings": path.join(
1150
+ coreSrc,
1151
+ "client/tombstone/remote-selection-rings.ts",
1152
+ ),
1153
+ "@agent-native/core/client/visual-style-controls": path.join(
1154
+ coreSrc,
1155
+ "client/tombstone/visual-style-controls.ts",
1156
+ ),
1157
+ "@agent-native/core/client/feature-flags": path.join(
1158
+ coreSrc,
1159
+ "client/feature-flags/index.ts",
1160
+ ),
1161
+ "@agent-native/core/client/hooks": path.join(
1162
+ coreSrc,
1163
+ "client/hooks/index.ts",
1164
+ ),
1165
+ "@agent-native/core/client/host": path.join(
1166
+ coreSrc,
1167
+ "client/host/index.ts",
1168
+ ),
1169
+ "@agent-native/core/client/i18n": path.join(coreSrc, "client/i18n.tsx"),
1170
+ "@agent-native/core/client/integrations": path.join(
1171
+ coreSrc,
1172
+ "client/integrations/index.ts",
1173
+ ),
1174
+ "@agent-native/core/client/navigation": path.join(
1175
+ coreSrc,
1176
+ "client/navigation/index.ts",
1177
+ ),
1178
+ "@agent-native/core/client/resources": path.join(
1179
+ coreSrc,
1180
+ "client/resources/index.ts",
1181
+ ),
1182
+ "@agent-native/core/client/route-chunk-recovery": path.join(
1183
+ coreSrc,
1184
+ "client/route-chunk-recovery/index.ts",
1185
+ ),
1186
+ "@agent-native/core/client/settings": path.join(
1187
+ coreSrc,
1188
+ "client/settings/index.ts",
1189
+ ),
1190
+ "@agent-native/core/client/ui": path.join(coreSrc, "client/ui/index.ts"),
1191
+ "@agent-native/core/client/uploads": path.join(
1192
+ coreSrc,
1193
+ "client/uploads/index.ts",
1194
+ ),
1195
+ "@agent-native/core/client/widgets": path.join(
1196
+ coreSrc,
1197
+ "client/widgets/index.ts",
1198
+ ),
1199
+ // Dedicated thin subpath — only the URL helpers, no chat stack in the closure.
1200
+ "@agent-native/core/client/api-path": path.join(
1201
+ coreSrc,
1202
+ "client/api-path.ts",
1203
+ ),
1204
+ "@agent-native/core/blocks": path.join(coreSrc, "client/blocks/index.ts"),
1205
+ "@agent-native/core/blocks/server": path.join(
1206
+ coreSrc,
1207
+ "client/blocks/server.ts",
1208
+ ),
1209
+ "@agent-native/core/client/extensions": path.join(
1210
+ coreSrc,
1211
+ "client/extensions/index.ts",
1212
+ ),
1213
+ // Legacy alias — see exports map note above.
1214
+ "@agent-native/core/client/tools": path.join(
1215
+ coreSrc,
1216
+ "client/extensions/index.ts",
1217
+ ),
1218
+ "@agent-native/core/client/org": path.join(coreSrc, "client/org/index.ts"),
1219
+ "@agent-native/core/client/db-admin": path.join(
1220
+ coreSrc,
1221
+ "client/db-admin/index.ts",
1222
+ ),
1223
+ "@agent-native/core/client/observability": path.join(
1224
+ coreSrc,
1225
+ "client/observability/index.ts",
1226
+ ),
1227
+ "@agent-native/core/client/onboarding": path.join(
1228
+ coreSrc,
1229
+ "client/onboarding/index.ts",
1230
+ ),
1231
+ "@agent-native/core/client/sharing": path.join(
1232
+ coreSrc,
1233
+ "client/sharing/index.ts",
1234
+ ),
1235
+ "@agent-native/core/client/notifications": path.join(
1236
+ coreSrc,
1237
+ "client/notifications/index.ts",
1238
+ ),
1239
+ "@agent-native/core/client/progress": path.join(
1240
+ coreSrc,
1241
+ "client/progress/index.ts",
1242
+ ),
1243
+ "@agent-native/core/client/transcription/use-live-transcription": path.join(
1244
+ coreSrc,
1245
+ "client/transcription/use-live-transcription.ts",
1246
+ ),
1247
+ "@agent-native/core/voice": path.join(coreSrc, "voice/index.ts"),
1248
+ "@agent-native/core/db": path.join(coreSrc, "db/index.ts"),
1249
+ "@agent-native/core/db/schema": path.join(coreSrc, "db/schema.ts"),
1250
+ "@agent-native/core/shared": path.join(coreSrc, "shared/index.ts"),
1251
+ "@agent-native/core/scripts": path.join(coreSrc, "scripts/index.ts"),
1252
+ "@agent-native/core/application-state": path.join(
1253
+ coreSrc,
1254
+ "application-state/index.ts",
1255
+ ),
1256
+ "@agent-native/core/settings": path.join(coreSrc, "settings/index.ts"),
1257
+ "@agent-native/core/credentials": path.join(
1258
+ coreSrc,
1259
+ "credentials/index.ts",
1260
+ ),
1261
+ "@agent-native/core/resources": path.join(coreSrc, "resources/index.ts"),
1262
+ "@agent-native/core/oauth-tokens": path.join(
1263
+ coreSrc,
1264
+ "oauth-tokens/index.ts",
1265
+ ),
1266
+ "@agent-native/core/workspace-connections": path.join(
1267
+ coreSrc,
1268
+ "workspace-connections/index.ts",
1269
+ ),
1270
+ "@agent-native/core/provider-api": path.join(
1271
+ coreSrc,
1272
+ "provider-api/index.ts",
1273
+ ),
1274
+ "@agent-native/core/a2a": path.join(coreSrc, "a2a/index.ts"),
1275
+ "@agent-native/core/router": path.join(coreSrc, "router/index.ts"),
1276
+ "@agent-native/core/terminal": path.join(
1277
+ coreSrc,
1278
+ "client/terminal/index.ts",
1279
+ ),
1280
+ "@agent-native/core/terminal/server": path.join(
1281
+ coreSrc,
1282
+ "terminal/index.ts",
1283
+ ),
1284
+ "@agent-native/core/adapters/cli": path.join(
1285
+ coreSrc,
1286
+ "adapters/cli/index.ts",
1287
+ ),
1288
+ "@agent-native/core/usage": path.join(coreSrc, "usage/store.ts"),
1289
+ "@agent-native/core/brand-kit": path.join(coreSrc, "brand-kit/index.ts"),
1290
+ "@agent-native/core/data-widgets": path.join(
1291
+ coreSrc,
1292
+ "data-widgets/index.ts",
1293
+ ),
1294
+ "@agent-native/core/server/design-token-utils": path.join(
1295
+ coreSrc,
1296
+ "server/design-token-utils.ts",
1297
+ ),
1298
+ "@agent-native/core/server/entry-server": path.join(
1299
+ coreSrc,
1300
+ "server/entry-server.tsx",
1301
+ ),
1302
+ // Shared stylesheet — alias to src so CSS edits (composer/theme rules)
1303
+ // take effect live in dev instead of silently loading the stale built
1304
+ // copy at dist/styles/. From src/styles/ the `@source "../client/**"`
1305
+ // directive resolves to the real .tsx source, which is what dev should
1306
+ // scan for Tailwind classes anyway.
1307
+ "@agent-native/core/styles/agent-native.css": path.join(
1308
+ coreSrc,
1309
+ "styles/agent-native.css",
1310
+ ),
1311
+ };
1312
+
1313
+ // Escape special regex chars in the key and anchor with $
1314
+ return Object.entries(entries).map(([find, replacement]) => ({
1315
+ find: new RegExp(`^${find.replace(/[/]/g, "\\/")}$`),
1316
+ replacement,
1317
+ }));
1318
+ }
1319
+
1320
+ export interface NitroOptions {
1321
+ /** Nitro deployment preset (e.g. "node", "vercel", "netlify", "cloudflare_pages"). Default: "node" */
1322
+ preset?: string;
1323
+ /** Source directory for server files. Default: "./server" */
1324
+ srcDir?: string;
1325
+ /** Routes directory name (relative to srcDir). Default: "routes" */
1326
+ routesDir?: string;
1327
+ /** Any additional Nitro config overrides */
1328
+ [key: string]: unknown;
1329
+ }
1330
+
1331
+ export interface ClientConfigOptions {
1332
+ /** Port for dev server. Default: 8080 */
1333
+ port?: number;
1334
+ /** Additional hostnames allowed to access the dev server. */
1335
+ allowedHosts?: NonNullable<NonNullable<UserConfig["server"]>["allowedHosts"]>;
1336
+ /** Vite log level. Workspace child apps default to "warn" so only the gateway URL is advertised. */
1337
+ logLevel?: UserConfig["logLevel"];
1338
+ /** Additional Vite plugins */
1339
+ plugins?: any[];
1340
+ /** Nitro plugin options (preset, srcDir, etc) */
1341
+ nitro?: NitroOptions;
1342
+ /** Override resolve aliases */
1343
+ aliases?: Record<string, string>;
1344
+ /** Override build.outDir. Default: "dist/spa" */
1345
+ outDir?: string;
1346
+ /** Additional fs.allow paths */
1347
+ fsAllow?: string[];
1348
+ /** Additional fs.deny patterns */
1349
+ fsDeny?: string[];
1350
+ /** Additional Vite optimizeDeps configuration */
1351
+ optimizeDeps?: NonNullable<UserConfig["optimizeDeps"]>;
1352
+ /** Additional Vite define constants. */
1353
+ define?: UserConfig["define"];
1354
+ /**
1355
+ * Framework route warmup behavior mounted by AgentSidebar.
1356
+ *
1357
+ * React Router's native prefetch warms both `.data` and JS, but its `.data`
1358
+ * request uses browser link prefetch. Chrome sends `Sec-Purpose: prefetch`
1359
+ * on those requests, which some production CDNs reject for dynamic `.data`
1360
+ * URLs before our SWR cache headers can help. Agent-Native therefore uses
1361
+ * ordinary fetches for `.data` and `modulepreload` for route JS by default.
1362
+ */
1363
+ routeWarmup?: AgentNativeRouteWarmupConfigInput;
1364
+ /**
1365
+ * Controls the MCP integrations catalog exposed from the composer + menu.
1366
+ *
1367
+ * - `false` hides the whole MCP integrations entry.
1368
+ * - `{ defaults: false }` hides all bundled provider presets but still
1369
+ * allows custom MCP servers.
1370
+ * - `{ defaults: { include: ["context7"] } }` allows only those preset ids.
1371
+ * - `{ defaults: { exclude: ["stripe"] } }` hides specific preset ids.
1372
+ */
1373
+ mcpIntegrations?: McpIntegrationsConfigInput;
1374
+ /**
1375
+ * Whether to auto-inject the Tailwind v4 Vite plugin (`@tailwindcss/vite`).
1376
+ * Defaults to true — set to `false` if a template wants to manage Tailwind
1377
+ * itself (e.g. the legacy v3 PostCSS pipeline).
1378
+ */
1379
+ tailwind?: boolean;
1380
+ /**
1381
+ * Package names to stub in the SSR bundle with an empty proxy object.
1382
+ *
1383
+ * Use this for dependencies that only run in the browser (canvas / diagram
1384
+ * libraries, editors, WebGL) but would otherwise get pulled into the
1385
+ * server bundle via SSR's noExternal policy — pushing the CF Pages
1386
+ * Functions bundle over the 25 MiB limit.
1387
+ *
1388
+ * Only add packages that are provably never called during SSR. If the
1389
+ * server imports one, it will receive a Proxy that throws on any real
1390
+ * use (which is better than bundling a 10 MiB dep the worker never calls).
1391
+ *
1392
+ * @example
1393
+ * ssrStubs: ["mermaid", "@excalidraw/excalidraw"]
1394
+ */
1395
+ ssrStubs?: string[];
1396
+ /**
1397
+ * @deprecated Pass `reactRouter()` directly in the `plugins` array instead.
1398
+ * Previously used to auto-load the React Router Vite plugin via require(),
1399
+ * but this fails in ESM contexts. Templates should now do:
1400
+ * ```ts
1401
+ * import { reactRouter } from "@react-router/dev/vite";
1402
+ * defineConfig({ plugins: [reactRouter()] })
1403
+ * ```
1404
+ */
1405
+ reactRouter?: boolean | Record<string, unknown>;
1406
+ }
1407
+
1408
+ export interface AgentNativeVitePluginOptions extends Omit<
1409
+ ClientConfigOptions,
1410
+ "plugins" | "reactRouter"
1411
+ > {
1412
+ /**
1413
+ * Include the legacy React SWC transform for non-React Router SPA apps.
1414
+ *
1415
+ * React Router framework-mode apps should pass `reactRouter()` as a normal
1416
+ * Vite plugin and leave this off.
1417
+ */
1418
+ legacySpa?: boolean;
1419
+ }
1420
+
1421
+ /**
1422
+ * Vite plugin that recovers the page when Vite's dependency optimizer
1423
+ * invalidates modules mid-load (the "504 Outdated Optimize Dep" error).
1424
+ *
1425
+ * Without this, the page silently fails: <script type="module"> tags 504,
1426
+ * React never mounts, and the user is stuck on a blank screen until they
1427
+ * manually refresh. We catch the failure modes and auto-reload, with a
1428
+ * visible overlay so the user knows what's happening, and a loop guard
1429
+ * so we never thrash forever.
1430
+ *
1431
+ * CRITICAL: this must be a SYNCHRONOUS (non-module) script injected at
1432
+ * `head-prepend`. Module scripts are deferred — the browser starts fetching
1433
+ * all module scripts in parallel during HTML parsing, so a module listener
1434
+ * registers AFTER sibling modules have already started loading and
1435
+ * possibly errored out. A regular <script> blocks parsing and runs
1436
+ * synchronously, so the listener is registered before ANY module fetch
1437
+ * begins.
1438
+ *
1439
+ * Catches three failure modes (all before React needs to mount):
1440
+ * 1. <script type="module"> / <link> 504 — window "error" event, capture phase
1441
+ * 2. Dynamic import 504 — "unhandledrejection" with "dynamically imported module"
1442
+ * 3. Child module 504 — resource timing when browser exposes the HTTP status
1443
+ */
1444
+ function autoReloadOnOptimizeDep(): Plugin {
1445
+ return {
1446
+ name: "agent-native-auto-reload-optimize-dep",
1447
+ apply: "serve",
1448
+ transformIndexHtml() {
1449
+ return [
1450
+ {
1451
+ tag: "script",
1452
+ // NOTE: no `type: "module"` — this must be a synchronous script.
1453
+ children: getViteDevRecoveryScript(),
1454
+ injectTo: "head-prepend",
1455
+ },
1456
+ ];
1457
+ },
1458
+ };
1459
+ }
1460
+
1461
+ /**
1462
+ * Vite handles outdated optimized-dep requests inside its own transform
1463
+ * middleware and ends the HTTP response with `504 Outdated Optimize Dep`.
1464
+ * Browser module loaders do not consistently surface those child-module
1465
+ * failures to userland JavaScript, so also nudge the Vite HMR client from the
1466
+ * server side. This turns the confusing blank-screen state into the same
1467
+ * full-page reload Vite would have requested once optimization settled.
1468
+ */
1469
+ function fullReloadOnOptimizeDep504(): Plugin {
1470
+ return {
1471
+ name: "agent-native-full-reload-optimize-dep-504",
1472
+ apply: "serve",
1473
+ configureServer(server) {
1474
+ let lastReloadAt = 0;
1475
+ server.middlewares.use((req, res, next) => {
1476
+ const originalEnd = res.end;
1477
+ (res as unknown as { end: (...args: unknown[]) => unknown }).end = (
1478
+ ...endArgs: unknown[]
1479
+ ) => {
1480
+ const statusMessage = String(res.statusMessage || "");
1481
+ if (
1482
+ res.statusCode === 504 &&
1483
+ statusMessage === "Outdated Optimize Dep"
1484
+ ) {
1485
+ const now = Date.now();
1486
+ if (now - lastReloadAt > 500) {
1487
+ lastReloadAt = now;
1488
+ server.ws.send({ type: "full-reload" });
1489
+ server.config.logger.info(
1490
+ `[agent-native] Vite optimized deps changed while loading ${
1491
+ req.url ?? "a module"
1492
+ }; reloading the page.`,
1493
+ { timestamp: true },
1494
+ );
1495
+ }
1496
+ }
1497
+ return (originalEnd as (...args: unknown[]) => unknown).apply(
1498
+ res,
1499
+ endArgs,
1500
+ );
1501
+ };
1502
+ next();
1503
+ });
1504
+ },
1505
+ };
1506
+ }
1507
+
1508
+ /**
1509
+ * Vite plugin that prevents the built-in base middleware from redirecting
1510
+ * "/" → "/app/" (or whatever the base is). When agent-native apps run with
1511
+ * --base /app/ in single-port mode, Vite's baseMiddleware sends a 302 from
1512
+ * "/" to the base path. This breaks Electron webview and iframe embeds
1513
+ * that load the app at the root. Instead, we rewrite "/" to the base path
1514
+ * internally so the app serves without a visible redirect.
1515
+ */
1516
+ function baseRedirectGuard(): Plugin {
1517
+ return {
1518
+ name: "agent-native-base-redirect-guard",
1519
+ apply: "serve",
1520
+ configureServer(server) {
1521
+ // Return a function so the middleware is added AFTER Vite's internal
1522
+ // middleware is built — but we insert BEFORE by using the pre-hook
1523
+ // approach: configureServer hooks that return nothing run before
1524
+ // internal middleware.
1525
+ server.middlewares.use((req, res, next) => {
1526
+ const base = server.config.base;
1527
+ if (base && base !== "/" && req.url?.startsWith(base)) {
1528
+ const relativeUrl = req.url.slice(base.length - 1);
1529
+ try {
1530
+ const url = new URL(relativeUrl, "http://agent-native.local");
1531
+ const publicDir = server.config.publicDir;
1532
+ if (typeof publicDir !== "string") {
1533
+ return next();
1534
+ }
1535
+ const publicPath = path.normalize(
1536
+ path.join(publicDir, decodeURIComponent(url.pathname)),
1537
+ );
1538
+ if (
1539
+ publicPath.startsWith(publicDir + path.sep) &&
1540
+ fs.existsSync(publicPath) &&
1541
+ fs.statSync(publicPath).isFile()
1542
+ ) {
1543
+ const contentType = contentTypeForPublicFile(publicPath);
1544
+ if (contentType) res.setHeader("content-type", contentType);
1545
+ if (req.method === "HEAD") {
1546
+ res.statusCode = 200;
1547
+ res.end();
1548
+ return;
1549
+ }
1550
+ fs.createReadStream(publicPath).pipe(res);
1551
+ return;
1552
+ }
1553
+ } catch {
1554
+ // Fall through to Vite/Nitro. Malformed URLs should keep their
1555
+ // original path so the normal dev-server error handling applies.
1556
+ }
1557
+ }
1558
+ if (serveExternalEmbedBrowserManifest(server, req, res)) {
1559
+ return;
1560
+ }
1561
+ if (serveMountedEmbedRuntimeModule(server, req, res, base)) {
1562
+ return;
1563
+ }
1564
+ // Nitro's pre-middleware only intercepts document/iframe/frame/empty
1565
+ // fetch-dest requests. For video/audio/image etc. it calls next() and
1566
+ // the post-internal Nitro middleware handles them instead. If we strip
1567
+ // the base path here for those requests, Vite's base middleware sees the
1568
+ // stripped path (e.g. /api/video/:id without /clips/) and responds with
1569
+ // a "did you mean /clips/api/video/:id" error before Nitro can handle it.
1570
+ // Only strip when the request type matches Nitro's pre-middleware gate.
1571
+ const secFetchDest = req.headers["sec-fetch-dest"] as
1572
+ | string
1573
+ | undefined;
1574
+ const isNitroPreHandled =
1575
+ !secFetchDest || /^(document|iframe|frame|empty)$/.test(secFetchDest);
1576
+ if (isNitroPreHandled) {
1577
+ req.url = stripMountedDevApiPath(req.url, base);
1578
+ }
1579
+ if (
1580
+ req.method === "HEAD" &&
1581
+ req.url &&
1582
+ !isFrameworkDevPath(req.url, base)
1583
+ ) {
1584
+ req.method = "GET";
1585
+ }
1586
+ if (
1587
+ base &&
1588
+ base !== "/" &&
1589
+ (req.url === "/" || req.url === "/index.html")
1590
+ ) {
1591
+ // Rewrite to the base path so Vite serves the app directly
1592
+ req.url = base;
1593
+ }
1594
+ next();
1595
+ });
1596
+ },
1597
+ };
1598
+ }
1599
+
1600
+ const VITE_RUNTIME_PATH_PREFIXES = [
1601
+ "/@fs/",
1602
+ "/@id/",
1603
+ "/@vite/",
1604
+ "/app/",
1605
+ "/node_modules/",
1606
+ "/packages/",
1607
+ "/src/",
1608
+ ];
1609
+
1610
+ const EMBED_DEV_STATIC_ASSET_PATH_PREFIXES = [
1611
+ ...VITE_RUNTIME_PATH_PREFIXES,
1612
+ "/assets/",
1613
+ "/library-presets/",
1614
+ ];
1615
+
1616
+ const EMBED_DEV_STATIC_ASSET_PATHS = new Set([
1617
+ "/favicon.ico",
1618
+ "/favicon.svg",
1619
+ "/manifest.json",
1620
+ ]);
1621
+
1622
+ function mountedPathCandidates(
1623
+ reqUrl: string | undefined,
1624
+ base: string | undefined,
1625
+ ): string[] {
1626
+ if (!reqUrl) return [];
1627
+ let pathname: string;
1628
+ try {
1629
+ pathname = new URL(reqUrl, "http://agent-native.local").pathname;
1630
+ } catch {
1631
+ return [];
1632
+ }
1633
+ if (base && base !== "/") {
1634
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
1635
+ if (pathname.startsWith(normalizedBase)) {
1636
+ return [pathname.slice(normalizedBase.length - 1) || "/"];
1637
+ }
1638
+ }
1639
+ return [pathname];
1640
+ }
1641
+
1642
+ function isEmbedDevStaticAssetRequest(
1643
+ reqUrl: string | undefined,
1644
+ base: string | undefined,
1645
+ ): boolean {
1646
+ return mountedPathCandidates(reqUrl, base).some((pathname) => {
1647
+ if (EMBED_DEV_STATIC_ASSET_PATHS.has(pathname)) return true;
1648
+ if (/^\/icon-[^/]+\.svg$/i.test(pathname)) return true;
1649
+ if (/^\/agent-native-[^/]+\.svg$/i.test(pathname)) return true;
1650
+ return EMBED_DEV_STATIC_ASSET_PATH_PREFIXES.some((prefix) =>
1651
+ pathname.startsWith(prefix),
1652
+ );
1653
+ });
1654
+ }
1655
+
1656
+ function cookieValue(req: IncomingMessage, name: string): string | undefined {
1657
+ const header = req.headers.cookie;
1658
+ if (typeof header !== "string" || !header) return undefined;
1659
+ for (const part of header.split(";")) {
1660
+ const index = part.indexOf("=");
1661
+ if (index < 0) continue;
1662
+ const key = part.slice(0, index).trim();
1663
+ if (key !== name) continue;
1664
+ try {
1665
+ return decodeURIComponent(part.slice(index + 1).trim());
1666
+ } catch {
1667
+ return part.slice(index + 1).trim();
1668
+ }
1669
+ }
1670
+ return undefined;
1671
+ }
1672
+
1673
+ function hasValidEmbedRuntimeToken(req: IncomingMessage): boolean {
1674
+ try {
1675
+ const url = new URL(req.url ?? "/", "http://agent-native.local");
1676
+ const queryToken = url.searchParams.get(EMBED_TOKEN_QUERY_PARAM);
1677
+ const cookieToken = cookieValue(req, EMBED_SESSION_COOKIE);
1678
+ return [queryToken, cookieToken].some(
1679
+ (token) => verifyEmbedSessionToken(token).ok,
1680
+ );
1681
+ } catch {
1682
+ return false;
1683
+ }
1684
+ }
1685
+
1686
+ function mountedEmbedRuntimeModuleUrl(
1687
+ reqUrl: string | undefined,
1688
+ base: string | undefined,
1689
+ ): string | null {
1690
+ if (!reqUrl || !base || base === "/") return null;
1691
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
1692
+ if (!reqUrl.startsWith(normalizedBase)) return null;
1693
+
1694
+ const runtimeUrl = reqUrl.slice(normalizedBase.length - 1) || "/";
1695
+ let url: URL;
1696
+ try {
1697
+ url = new URL(runtimeUrl, "http://agent-native.local");
1698
+ } catch {
1699
+ return null;
1700
+ }
1701
+ if (
1702
+ !VITE_RUNTIME_PATH_PREFIXES.some((prefix) =>
1703
+ url.pathname.startsWith(prefix),
1704
+ )
1705
+ ) {
1706
+ return null;
1707
+ }
1708
+ url.searchParams.delete(EMBED_TOKEN_QUERY_PARAM);
1709
+ url.searchParams.delete(MCP_APP_CHAT_BRIDGE_QUERY_PARAM);
1710
+ return `${url.pathname}${url.search}${url.hash}`;
1711
+ }
1712
+
1713
+ function virtualModuleIdFromRuntimeUrl(runtimeUrl: string): string | null {
1714
+ try {
1715
+ const pathname = new URL(runtimeUrl, "http://agent-native.local").pathname;
1716
+ const prefix = "/@id/__x00__";
1717
+ if (!pathname.startsWith(prefix)) return null;
1718
+ return `\0${decodeURIComponent(pathname.slice(prefix.length))}`;
1719
+ } catch {
1720
+ return null;
1721
+ }
1722
+ }
1723
+
1724
+ async function loadMountedEmbedRuntimeModule(
1725
+ server: any,
1726
+ runtimeUrl: string,
1727
+ ): Promise<string | null> {
1728
+ const virtualId = virtualModuleIdFromRuntimeUrl(runtimeUrl);
1729
+ if (virtualId) {
1730
+ const loaded = await server.pluginContainer?.load?.(virtualId);
1731
+ if (typeof loaded === "string") return loaded;
1732
+ if (loaded && typeof loaded.code === "string") return loaded.code;
1733
+ }
1734
+ const result = await server.transformRequest(runtimeUrl);
1735
+ return result?.code ?? null;
1736
+ }
1737
+
1738
+ function serveMountedEmbedRuntimeModule(
1739
+ server: any,
1740
+ req: IncomingMessage,
1741
+ res: ServerResponse,
1742
+ base: string | undefined,
1743
+ ): boolean {
1744
+ if (req.method !== "GET" && req.method !== "HEAD") return false;
1745
+ if (!hasValidEmbedRuntimeToken(req)) return false;
1746
+ const runtimeUrl = mountedEmbedRuntimeModuleUrl(req.url, base);
1747
+ if (!runtimeUrl) return false;
1748
+
1749
+ void loadMountedEmbedRuntimeModule(server, runtimeUrl)
1750
+ .then((code: string | null) => {
1751
+ if (!code) {
1752
+ if (!res.headersSent) {
1753
+ res.statusCode = 404;
1754
+ res.end();
1755
+ }
1756
+ return;
1757
+ }
1758
+ res.statusCode = 200;
1759
+ res.setHeader("content-type", "text/javascript");
1760
+ if (req.method === "HEAD") {
1761
+ res.end();
1762
+ return;
1763
+ }
1764
+ res.end(code);
1765
+ })
1766
+ .catch((err: unknown) => {
1767
+ if (res.headersSent) return;
1768
+ res.statusCode = 500;
1769
+ res.setHeader("content-type", "text/plain");
1770
+ res.end(err instanceof Error ? err.message : String(err));
1771
+ });
1772
+ return true;
1773
+ }
1774
+
1775
+ function publicOriginFromDevRequest(req: IncomingMessage): string | null {
1776
+ const forwardedHost = String(req.headers["x-forwarded-host"] ?? "")
1777
+ .split(",")[0]
1778
+ ?.trim();
1779
+ const host =
1780
+ forwardedHost ||
1781
+ String(req.headers.host ?? "")
1782
+ .split(",")[0]
1783
+ ?.trim();
1784
+ if (!host) return null;
1785
+ const forwardedProto = String(req.headers["x-forwarded-proto"] ?? "")
1786
+ .split(",")[0]
1787
+ ?.trim();
1788
+ const proto =
1789
+ forwardedProto ||
1790
+ (/^(localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/i.test(host)
1791
+ ? "http"
1792
+ : "https");
1793
+ return `${proto}://${host}`;
1794
+ }
1795
+
1796
+ function isReactRouterBrowserManifestUrl(reqUrl: string | undefined): boolean {
1797
+ if (!reqUrl) return false;
1798
+ try {
1799
+ const url = new URL(reqUrl, "http://agent-native.local");
1800
+ return (
1801
+ virtualModuleIdFromRuntimeUrl(url.pathname) ===
1802
+ "\0virtual:react-router/browser-manifest"
1803
+ );
1804
+ } catch {
1805
+ return false;
1806
+ }
1807
+ }
1808
+
1809
+ function rewriteRootRelativeManifestUrls(
1810
+ code: string,
1811
+ publicOrigin: string,
1812
+ ): string {
1813
+ return code.replace(/'\/(?!\/)([^']*)'/g, (match, rest: string) => {
1814
+ try {
1815
+ return JSON.stringify(new URL(`/${rest}`, publicOrigin).toString());
1816
+ } catch {
1817
+ return match;
1818
+ }
1819
+ });
1820
+ }
1821
+
1822
+ function serveExternalEmbedBrowserManifest(
1823
+ server: any,
1824
+ req: IncomingMessage,
1825
+ res: ServerResponse,
1826
+ ): boolean {
1827
+ if (req.method !== "GET" && req.method !== "HEAD") return false;
1828
+ if (!isMcpEmbedCorsOrigin(String(req.headers.origin ?? ""))) return false;
1829
+ if (!isReactRouterBrowserManifestUrl(req.url)) return false;
1830
+ const publicOrigin = publicOriginFromDevRequest(req);
1831
+ if (!publicOrigin) return false;
1832
+ const runtimeUrl = mountedEmbedRuntimeModuleUrl(req.url, "/") ?? req.url;
1833
+ if (!runtimeUrl) return false;
1834
+
1835
+ void loadMountedEmbedRuntimeModule(server, runtimeUrl)
1836
+ .then((code: string | null) => {
1837
+ if (!code) {
1838
+ if (!res.headersSent) {
1839
+ res.statusCode = 404;
1840
+ res.end();
1841
+ }
1842
+ return;
1843
+ }
1844
+ res.statusCode = 200;
1845
+ res.setHeader("content-type", "text/javascript");
1846
+ if (req.method === "HEAD") {
1847
+ res.end();
1848
+ return;
1849
+ }
1850
+ res.end(rewriteRootRelativeManifestUrls(code, publicOrigin));
1851
+ })
1852
+ .catch((err: unknown) => {
1853
+ if (res.headersSent) return;
1854
+ res.statusCode = 500;
1855
+ res.setHeader("content-type", "text/plain");
1856
+ res.end(err instanceof Error ? err.message : String(err));
1857
+ });
1858
+ return true;
1859
+ }
1860
+
1861
+ function embedDevFrameHeaders(): Plugin {
1862
+ return {
1863
+ name: "agent-native-embed-dev-frame-headers",
1864
+ apply: "serve",
1865
+ configureServer(server) {
1866
+ server.middlewares.use((req, res, next) => {
1867
+ const origin = String(req.headers.origin ?? "");
1868
+ if (isEmbedDevStaticAssetRequest(req.url, server.config?.base)) {
1869
+ for (const [name, value] of Object.entries(
1870
+ MCP_EMBED_STATIC_ASSET_HEADERS,
1871
+ )) {
1872
+ res.setHeader(name, value);
1873
+ }
1874
+ }
1875
+ if (isMcpEmbedCorsOrigin(origin)) {
1876
+ res.setHeader("Access-Control-Allow-Origin", origin);
1877
+ res.setHeader("Vary", "Origin");
1878
+ // The desktop app's dev origin (http://localhost:1420) also matches
1879
+ // here, and it logs in with `credentials: "include"`. A credentialed
1880
+ // request needs this header or the browser discards the response.
1881
+ // The OPTIONS short-circuit below means we can't rely on the real
1882
+ // auth handler to set it, so set it here too (production already does
1883
+ // the same).
1884
+ if (shouldAllowMcpEmbedCredentials(origin)) {
1885
+ res.setHeader("Access-Control-Allow-Credentials", "true");
1886
+ }
1887
+ res.setHeader(
1888
+ "Access-Control-Allow-Methods",
1889
+ "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS",
1890
+ );
1891
+ res.setHeader(
1892
+ "Access-Control-Allow-Headers",
1893
+ MCP_EMBED_CORS_ALLOW_HEADERS,
1894
+ );
1895
+ for (const [name, value] of Object.entries(
1896
+ MCP_EMBED_STATIC_ASSET_HEADERS,
1897
+ )) {
1898
+ if (name === "Access-Control-Allow-Origin") continue;
1899
+ res.setHeader(name, value);
1900
+ }
1901
+ if (req.method === "OPTIONS") {
1902
+ res.statusCode = 204;
1903
+ res.end();
1904
+ return;
1905
+ }
1906
+ }
1907
+
1908
+ const cookieHeader = String(req.headers.cookie ?? "");
1909
+ let hasEmbedMarker = /\ban_embed_session=/.test(cookieHeader);
1910
+ try {
1911
+ const url = new URL(req.url ?? "/", "http://agent-native.local");
1912
+ hasEmbedMarker =
1913
+ hasEmbedMarker || url.searchParams.has("__an_embed_token");
1914
+ } catch {
1915
+ // Malformed URLs should continue through Vite's normal handling.
1916
+ }
1917
+ if (hasEmbedMarker) {
1918
+ res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
1919
+ res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
1920
+ res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
1921
+ res.setHeader("Referrer-Policy", "no-referrer");
1922
+ }
1923
+ next();
1924
+ });
1925
+ },
1926
+ };
1927
+ }
1928
+
1929
+ function contentTypeForPublicFile(filePath: string): string | null {
1930
+ switch (path.extname(filePath).toLowerCase()) {
1931
+ case ".css":
1932
+ return "text/css";
1933
+ case ".html":
1934
+ return "text/html";
1935
+ case ".ico":
1936
+ return "image/x-icon";
1937
+ case ".json":
1938
+ case ".webmanifest":
1939
+ return "application/json";
1940
+ case ".js":
1941
+ case ".mjs":
1942
+ return "text/javascript";
1943
+ case ".png":
1944
+ return "image/png";
1945
+ case ".svg":
1946
+ return "image/svg+xml";
1947
+ case ".txt":
1948
+ return "text/plain";
1949
+ case ".xml":
1950
+ return "application/xml";
1951
+ default:
1952
+ return null;
1953
+ }
1954
+ }
1955
+
1956
+ function devPathname(reqUrl: string): string {
1957
+ return new URL(reqUrl, "http://agent-native.local").pathname;
1958
+ }
1959
+
1960
+ function isApiDevPath(reqUrl: string): boolean {
1961
+ const pathname = devPathname(reqUrl);
1962
+ return pathname === "/api" || pathname.startsWith("/api/");
1963
+ }
1964
+
1965
+ export function stripMountedDevApiPath(
1966
+ reqUrl: string | undefined,
1967
+ base: string | undefined,
1968
+ ): string | undefined {
1969
+ if (!reqUrl || !base || base === "/") return reqUrl;
1970
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
1971
+ if (!reqUrl.startsWith(normalizedBase)) return reqUrl;
1972
+ const stripped = reqUrl.slice(normalizedBase.length - 1) || "/";
1973
+ return isApiDevPath(stripped) ? stripped : reqUrl;
1974
+ }
1975
+
1976
+ export function isFrameworkDevPath(
1977
+ reqUrl: string,
1978
+ base: string | undefined,
1979
+ ): boolean {
1980
+ const pathname = devPathname(reqUrl);
1981
+ if (pathname === "/_agent-native" || pathname.startsWith("/_agent-native/")) {
1982
+ return true;
1983
+ }
1984
+ if (!base || base === "/") return false;
1985
+ const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base;
1986
+ return (
1987
+ pathname === `${normalizedBase}/_agent-native` ||
1988
+ pathname.startsWith(`${normalizedBase}/_agent-native/`)
1989
+ );
1990
+ }
1991
+
1992
+ /**
1993
+ * Work around a Rolldown bug where Nitro passes service entries as objects
1994
+ * ({index: "path"}) but Rolldown expects strings. This plugin normalizes
1995
+ * rollupOptions.input entries in the SSR environment.
1996
+ */
1997
+ function rolldownInputFix(): Plugin {
1998
+ return {
1999
+ name: "agent-native-rolldown-input-fix",
2000
+ configEnvironment(_name, config) {
2001
+ const input = config.build?.rollupOptions?.input;
2002
+ if (!Array.isArray(input)) return;
2003
+ // Flatten any object entries to just their string values
2004
+ const fixed = input.map((entry: any) => {
2005
+ if (typeof entry === "string") return entry;
2006
+ if (typeof entry === "object" && entry !== null) {
2007
+ const values = Object.values(entry);
2008
+ return values[0] as string;
2009
+ }
2010
+ return entry;
2011
+ });
2012
+ config.build!.rollupOptions!.input = fixed;
2013
+ },
2014
+ };
2015
+ }
2016
+
2017
+ /**
2018
+ * Replace caller-specified packages with an empty proxy stub during SSR
2019
+ * builds. For apps whose heavy browser-only deps would otherwise bloat the
2020
+ * edge worker past CF Pages' 25 MiB Functions limit.
2021
+ *
2022
+ * The template lists the packages in its `defineConfig({ ssrStubs })` call —
2023
+ * the framework never hardcodes package names.
2024
+ */
2025
+ function ssrStubPlugin(packages: string[]): Plugin | null {
2026
+ if (!packages.length) return null;
2027
+ const stubbed = new Set(packages);
2028
+ const STUB_ID = "\0agent-native-ssr-stub";
2029
+ const namedExports = [
2030
+ "ActionBarPrimitive",
2031
+ "AllSelection",
2032
+ "Array",
2033
+ "AssistantRuntimeProvider",
2034
+ "Awareness",
2035
+ "BranchPickerPrimitive",
2036
+ "BubbleMenu",
2037
+ "CodeBlockLowlight",
2038
+ "Collaboration",
2039
+ "CollaborationCaret",
2040
+ "ComposerPrimitive",
2041
+ "CompositeAttachmentAdapter",
2042
+ "DOMParser",
2043
+ "Decoration",
2044
+ "DecorationSet",
2045
+ "Editor",
2046
+ "EditorContent",
2047
+ "Extension",
2048
+ "FitAddon",
2049
+ "Fragment",
2050
+ "Image",
2051
+ "InputRule",
2052
+ "Link",
2053
+ "Map",
2054
+ "Markdown",
2055
+ "Mark",
2056
+ "MessagePrimitive",
2057
+ "Node",
2058
+ "NodeSelection",
2059
+ "NodeViewContent",
2060
+ "NodeViewWrapper",
2061
+ "Placeholder",
2062
+ "Plugin",
2063
+ "PluginKey",
2064
+ "ReactNodeViewRenderer",
2065
+ "Selection",
2066
+ "SimpleImageAttachmentAdapter",
2067
+ "SimpleTextAttachmentAdapter",
2068
+ "StarterKit",
2069
+ "Table",
2070
+ "TableCell",
2071
+ "TableHeader",
2072
+ "TableRow",
2073
+ "TaskItem",
2074
+ "TaskList",
2075
+ "Terminal",
2076
+ "TextSelection",
2077
+ "ThreadPrimitive",
2078
+ "WebLinksAddon",
2079
+ "captureException",
2080
+ "common",
2081
+ "createLowlight",
2082
+ "createNodeFromContent",
2083
+ "defaultUrlTransform",
2084
+ "extensions",
2085
+ "findTable",
2086
+ "format",
2087
+ "Doc",
2088
+ "getHTMLFromFragment",
2089
+ "getIsolationScope",
2090
+ "init",
2091
+ "isChangeOrigin",
2092
+ "mergeAttributes",
2093
+ "renderToString",
2094
+ "applyUpdate",
2095
+ "encodeStateVector",
2096
+ "encodeStateAsUpdate",
2097
+ "mergeUpdates",
2098
+ "useAui",
2099
+ "useComposer",
2100
+ "useComposerRuntime",
2101
+ "useCurrentEditor",
2102
+ "useEditor",
2103
+ "useLocalRuntime",
2104
+ "useMessagePartReasoning",
2105
+ "useMessagePartRuntime",
2106
+ "useMessagePartText",
2107
+ "useMessageRuntime",
2108
+ "useThread",
2109
+ "useThreadRuntime",
2110
+ "withScope",
2111
+ "XmlFragment",
2112
+ "XmlText",
2113
+ ];
2114
+ return {
2115
+ name: "agent-native-ssr-stub-heavy-libs",
2116
+ enforce: "pre",
2117
+ resolveId(id, _importer, opts) {
2118
+ if (!opts?.ssr) return null;
2119
+ // Match the bare package name or any subpath
2120
+ const pkg = id
2121
+ .split("/")
2122
+ .slice(0, id.startsWith("@") ? 2 : 1)
2123
+ .join("/");
2124
+ if (stubbed.has(pkg)) return STUB_ID;
2125
+ return null;
2126
+ },
2127
+ load(id) {
2128
+ if (id !== STUB_ID) return null;
2129
+ // Proxy that answers any property access with itself — lets dead
2130
+ // import/re-export chains parse without blowing up, and still throws
2131
+ // if code actually tries to call any of it on the server.
2132
+ return (
2133
+ "const handler = { get(_, p) { " +
2134
+ "if (p === Symbol.toPrimitive) return () => ''; " +
2135
+ "if (p === 'then') return undefined; " +
2136
+ "return new Proxy(() => {}, handler); " +
2137
+ "} };" +
2138
+ "const stub = new Proxy(() => {}, handler);" +
2139
+ "export default stub;" +
2140
+ namedExports.map((name) => `export const ${name} = stub;`).join("")
2141
+ );
2142
+ },
2143
+ };
2144
+ }
2145
+
2146
+ function splitViteRequest(id: string): { file: string; query: string } | null {
2147
+ const queryIndex = id.indexOf("?");
2148
+ if (queryIndex === -1) return null;
2149
+ return {
2150
+ file: id.slice(0, queryIndex),
2151
+ query: id.slice(queryIndex + 1),
2152
+ };
2153
+ }
2154
+
2155
+ function hasRawQuery(query: string): boolean {
2156
+ return new URLSearchParams(query).has("raw");
2157
+ }
2158
+
2159
+ function normalizeViteFilePath(file: string): string | null {
2160
+ if (!file || file.startsWith("\0")) return null;
2161
+ const fsPath = file.startsWith("/@fs/") ? file.slice("/@fs".length) : file;
2162
+ try {
2163
+ return decodeURI(fsPath);
2164
+ } catch {
2165
+ return fsPath;
2166
+ }
2167
+ }
2168
+
2169
+ function changelogRawPathFromId(id: string): string | null {
2170
+ const request = splitViteRequest(id);
2171
+ if (!request || !hasRawQuery(request.query)) return null;
2172
+ const file = normalizeViteFilePath(request.file);
2173
+ if (!file || path.basename(file) !== "CHANGELOG.md") return null;
2174
+ return path.resolve(file);
2175
+ }
2176
+
2177
+ function resolveChangelogRawImport(
2178
+ source: string,
2179
+ importer: string | undefined,
2180
+ ): string | null {
2181
+ const request = splitViteRequest(source);
2182
+ if (!request || !hasRawQuery(request.query)) return null;
2183
+ const rawFile = normalizeViteFilePath(request.file);
2184
+ if (!rawFile || path.basename(rawFile) !== "CHANGELOG.md") return null;
2185
+
2186
+ const rawImporter = importer?.split("?")[0];
2187
+ const importerFile =
2188
+ (rawImporter && normalizeViteFilePath(rawImporter)) ||
2189
+ rawImporter ||
2190
+ path.join(process.cwd(), "index.ts");
2191
+ const resolved = path.isAbsolute(rawFile)
2192
+ ? rawFile
2193
+ : path.resolve(path.dirname(importerFile), rawFile);
2194
+ return `${resolved}?${request.query}`;
2195
+ }
2196
+
2197
+ function readAppChangelogMarkdown(
2198
+ changelogPath: string,
2199
+ watchFile: (file: string) => void,
2200
+ ): string {
2201
+ // Only ever register real files with Vite's `addWatchFile`. Passing a
2202
+ // directory makes import-analysis try to resolve it as a module and fail
2203
+ // with "Failed to resolve import .../changelog", which breaks hydration for
2204
+ // every template in dev. New/removed pending files are still picked up via
2205
+ // `handleHotUpdate` (Vite watches the project root recursively).
2206
+ watchFile(changelogPath);
2207
+ const existing = fs.existsSync(changelogPath)
2208
+ ? fs.readFileSync(changelogPath, "utf-8")
2209
+ : "";
2210
+ const pendingDir = path.join(path.dirname(changelogPath), "changelog");
2211
+ if (!fs.existsSync(pendingDir)) {
2212
+ return existing;
2213
+ }
2214
+
2215
+ const pending = fs
2216
+ .readdirSync(pendingDir)
2217
+ .filter(
2218
+ (file) => file.endsWith(".md") && file.toLowerCase() !== "readme.md",
2219
+ )
2220
+ .sort()
2221
+ .map((file) => {
2222
+ const filePath = path.join(pendingDir, file);
2223
+ watchFile(filePath);
2224
+ // `agent-native changelog add` prefixes every pending filename with its
2225
+ // date. Preserve that date when a hand-written entry omits `date:` so a
2226
+ // deployed What's new surface never groups an already-merged update
2227
+ // under an inaccurate "Unreleased" heading.
2228
+ const filenameDate = file.match(/^(\d{4}-\d{2}-\d{2})(?:-|\.md$)/)?.[1];
2229
+ return parsePendingEntry(
2230
+ fs.readFileSync(filePath, "utf-8"),
2231
+ filenameDate,
2232
+ );
2233
+ });
2234
+ return mergePendingChangelog(existing, pending);
2235
+ }
2236
+
2237
+ function isChangelogSourceFile(file: string): boolean {
2238
+ if (path.basename(file) === "CHANGELOG.md") return true;
2239
+ return (
2240
+ path.basename(path.dirname(file)) === "changelog" &&
2241
+ file.endsWith(".md") &&
2242
+ path.basename(file).toLowerCase() !== "readme.md"
2243
+ );
2244
+ }
2245
+
2246
+ function invalidateChangelogRawModules(server: {
2247
+ moduleGraph?: { idToModuleMap?: Map<string, any>; invalidateModule?: any };
2248
+ }) {
2249
+ const moduleGraph = server.moduleGraph;
2250
+ if (!moduleGraph?.idToModuleMap || !moduleGraph.invalidateModule) return;
2251
+ for (const mod of moduleGraph.idToModuleMap.values()) {
2252
+ if (!mod?.id || !changelogRawPathFromId(mod.id)) continue;
2253
+ moduleGraph.invalidateModule(mod);
2254
+ }
2255
+ }
2256
+
2257
+ function appChangelogRawPlugin(): Plugin {
2258
+ return {
2259
+ name: "agent-native-app-changelog-raw",
2260
+ enforce: "pre",
2261
+ resolveId(source, importer) {
2262
+ return resolveChangelogRawImport(source, importer);
2263
+ },
2264
+ load(id) {
2265
+ const changelogPath = changelogRawPathFromId(id);
2266
+ if (!changelogPath) return null;
2267
+ const markdown = readAppChangelogMarkdown(changelogPath, (file) =>
2268
+ this.addWatchFile(file),
2269
+ );
2270
+ return `export default ${JSON.stringify(markdown)};`;
2271
+ },
2272
+ handleHotUpdate(ctx) {
2273
+ if (!isChangelogSourceFile(ctx.file)) return;
2274
+ invalidateChangelogRawModules(ctx.server as any);
2275
+ ctx.server.ws.send({ type: "full-reload" });
2276
+ return [];
2277
+ },
2278
+ };
2279
+ }
2280
+
2281
+ /**
2282
+ * Expose the resolved Vite dev server port as process.env.PORT so that
2283
+ * in-process scripts (which use localFetch → http://localhost:${PORT}/api/...)
2284
+ * hit the right address even when Vite auto-increments the port.
2285
+ */
2286
+ function portExposer(): Plugin {
2287
+ return {
2288
+ name: "agent-native-port-exposer",
2289
+ apply: "serve",
2290
+ configureServer(server) {
2291
+ server.httpServer?.once("listening", () => {
2292
+ const addr = server.httpServer?.address();
2293
+ if (addr && typeof addr === "object" && addr.port) {
2294
+ process.env.PORT = String(addr.port); // guard:allow-env-mutation — Vite dev server port published once at boot before any request
2295
+ }
2296
+ });
2297
+ },
2298
+ };
2299
+ }
2300
+
2301
+ /**
2302
+ * Silence benign connection-reset noise from Vite's dev middleware.
2303
+ * Fires when a browser closes/reloads/navigates mid-request — the peer has
2304
+ * already gone away, there's nothing to fix, and Vite's error middleware
2305
+ * spams the terminal and browser HMR overlay with errors like
2306
+ * "read ECONNRESET" and "socket hang up". Our H3 server layer already
2307
+ * swallows these (create-server.ts onError); this plugin does the same for
2308
+ * Vite's own connect pipeline.
2309
+ */
2310
+ function silenceConnectionResets(): Plugin {
2311
+ const isClosedWebStreamController = (err: unknown) => {
2312
+ const e = err as
2313
+ | (NodeJS.ErrnoException & { cause?: NodeJS.ErrnoException })
2314
+ | undefined;
2315
+ const code = e?.code || (e?.cause as NodeJS.ErrnoException)?.code;
2316
+ const message = [
2317
+ String(e?.message ?? ""),
2318
+ String((e?.cause as NodeJS.ErrnoException | undefined)?.message ?? ""),
2319
+ ].join("\n");
2320
+ const stack = [
2321
+ String(e?.stack ?? ""),
2322
+ String((e?.cause as NodeJS.ErrnoException | undefined)?.stack ?? ""),
2323
+ ].join("\n");
2324
+ return (
2325
+ code === "ERR_INVALID_STATE" &&
2326
+ /Controller is already closed/i.test(message) &&
2327
+ (!stack ||
2328
+ /ReadableStreamDefaultController\.close|internal\/webstreams\/adapters|IncomingMessage\.onclose/.test(
2329
+ stack,
2330
+ ))
2331
+ );
2332
+ };
2333
+ const isBenign = (err: unknown) => {
2334
+ const e = err as
2335
+ | (NodeJS.ErrnoException & { cause?: NodeJS.ErrnoException })
2336
+ | undefined;
2337
+ const code = e?.code || (e?.cause as NodeJS.ErrnoException)?.code;
2338
+ const message = String(e?.message ?? "");
2339
+ return (
2340
+ code === "ECONNRESET" ||
2341
+ code === "ECONNABORTED" ||
2342
+ code === "EPIPE" ||
2343
+ isClosedWebStreamController(err) ||
2344
+ /^(read ECONNRESET|write ECONNRESET|socket hang up|aborted|write EPIPE)$/i.test(
2345
+ message,
2346
+ )
2347
+ );
2348
+ };
2349
+ const isBenignErrorPayload = (payload: unknown) => {
2350
+ const p = payload as { type?: string; err?: unknown } | undefined;
2351
+ return p?.type === "error" && isBenign(p.err);
2352
+ };
2353
+ return {
2354
+ name: "agent-native-silence-connection-resets",
2355
+ apply: "serve",
2356
+ configureServer(server) {
2357
+ // Swallow socket-level resets so Node doesn't surface them as uncaught.
2358
+ server.httpServer?.on("connection", (socket) => {
2359
+ socket.on("error", (err: Error) => {
2360
+ if (!isBenign(err)) throw err;
2361
+ });
2362
+ });
2363
+ // Drop Vite's "Internal server error: read ECONNRESET" log lines.
2364
+ const origError = server.config.logger.error.bind(server.config.logger);
2365
+ server.config.logger.error = (msg, opts) => {
2366
+ const text = typeof msg === "string" ? msg : String(msg ?? "");
2367
+ if (
2368
+ (opts?.error && isBenign(opts.error)) ||
2369
+ /Internal server error:\s*(read ECONNRESET|write ECONNRESET|socket hang up|aborted|EPIPE)/i.test(
2370
+ text,
2371
+ )
2372
+ ) {
2373
+ return;
2374
+ }
2375
+ origError(msg, opts);
2376
+ };
2377
+
2378
+ // Vite's error middleware sends these same benign errors to the HMR
2379
+ // client, which turns them into the full-screen browser overlay.
2380
+ // Suppress just those payloads while leaving real transform/runtime
2381
+ // errors untouched.
2382
+ const hot = (
2383
+ server as unknown as {
2384
+ environments?: { client?: { hot?: { send?: Function } } };
2385
+ }
2386
+ ).environments?.client?.hot;
2387
+ if (hot?.send) {
2388
+ const origHotSend = hot.send.bind(hot);
2389
+ hot.send = (payload: unknown, ...args: unknown[]) => {
2390
+ if (isBenignErrorPayload(payload)) return;
2391
+ return origHotSend(payload, ...args);
2392
+ };
2393
+ }
2394
+
2395
+ const ws = (server as unknown as { ws?: { send?: Function } }).ws;
2396
+ if (ws?.send) {
2397
+ const origWsSend = ws.send.bind(ws);
2398
+ ws.send = (payload: unknown, ...args: unknown[]) => {
2399
+ if (isBenignErrorPayload(payload)) return;
2400
+ return origWsSend(payload, ...args);
2401
+ };
2402
+ }
2403
+ },
2404
+ };
2405
+ }
2406
+
2407
+ type AgentNativeViteCommand = ConfigEnv["command"];
2408
+
2409
+ function isBuildCommand(command?: AgentNativeViteCommand): boolean {
2410
+ return command === "build" || (!command && process.argv.includes("build"));
2411
+ }
2412
+
2413
+ function hasReactRouterPlugin(plugins: any[] | undefined): boolean {
2414
+ return Boolean(
2415
+ plugins?.some(
2416
+ (p: any) =>
2417
+ p?.name === "react-router" ||
2418
+ (Array.isArray(p) && p.some((pp: any) => pp?.name === "react-router")),
2419
+ ),
2420
+ );
2421
+ }
2422
+
2423
+ function createReactTransformPlugin(): any {
2424
+ try {
2425
+ let reactTransformPlugin = require("@vitejs/plugin-react-swc");
2426
+ if (reactTransformPlugin.default)
2427
+ reactTransformPlugin = reactTransformPlugin.default;
2428
+ return reactTransformPlugin?.();
2429
+ } catch {
2430
+ // Will be resolved at runtime by Vite
2431
+ return null;
2432
+ }
2433
+ }
2434
+
2435
+ function createTailwindPlugin(options: Pick<ClientConfigOptions, "tailwind">) {
2436
+ if (options.tailwind === false) return null;
2437
+ try {
2438
+ let tailwindPlugin = require("@tailwindcss/vite");
2439
+ if (tailwindPlugin.default) tailwindPlugin = tailwindPlugin.default;
2440
+ // Tailwind's Vite optimizer uses Lightning CSS internally and runs
2441
+ // before Vite's own CSS minifier. Lightning CSS collapses the standard
2442
+ // `backdrop-filter` declaration when a `-webkit-` fallback is present,
2443
+ // so let Vite/esbuild handle the production CSS pass instead.
2444
+ return tailwindPlugin({ optimize: false });
2445
+ } catch {
2446
+ // Plugin not installed — silently skip. Old templates may still be on v3.
2447
+ return null;
2448
+ }
2449
+ }
2450
+
2451
+ function getConfiguredAppBasePath(): { appBasePath: string; base: string } {
2452
+ // APP_BASE_PATH lets this app be mounted under a prefix (e.g. "/mail") as
2453
+ // part of a unified workspace deploy. Defaults to "/" for standalone apps.
2454
+ const appBasePath =
2455
+ process.env.VITE_APP_BASE_PATH || process.env.APP_BASE_PATH || "/";
2456
+ const base = appBasePath.endsWith("/") ? appBasePath : `${appBasePath}/`;
2457
+ return { appBasePath, base };
2458
+ }
2459
+
2460
+ function createNitroDevPlugin(
2461
+ options: Pick<ClientConfigOptions, "nitro">,
2462
+ appBasePath: string,
2463
+ ) {
2464
+ return nitroVitePlugin({
2465
+ serverDir: "./server",
2466
+ ...(options.nitro ?? {}),
2467
+ // Never auto-load test files as server handlers/plugins/middleware.
2468
+ // Nitro scans server/{plugins,middleware,routes,api}/*; a co-located
2469
+ // *.spec.ts would otherwise be loaded at runtime and crash the server
2470
+ // (its top-level vitest calls throw). Keep tests next to their source safely.
2471
+ ignore: [
2472
+ ...((options.nitro as { ignore?: string[] })?.ignore ?? []),
2473
+ "**/*.spec.ts",
2474
+ "**/*.spec.tsx",
2475
+ "**/*.test.ts",
2476
+ "**/*.test.tsx",
2477
+ ],
2478
+ routeRules: {
2479
+ ...mcpEmbedStaticAssetRouteRules(appBasePath),
2480
+ ...((options.nitro as { routeRules?: Record<string, any> })?.routeRules ??
2481
+ {}),
2482
+ },
2483
+ } as any);
2484
+ }
2485
+
2486
+ function arrayFrom<T>(value: T | T[] | undefined): T[] {
2487
+ if (value === undefined) return [];
2488
+ return Array.isArray(value) ? value : [value];
2489
+ }
2490
+
2491
+ function localWorkspacePackageAliases(
2492
+ packages: Array<{ packageName: string; packageDir: string }>,
2493
+ ): any[] {
2494
+ const aliases: any[] = [];
2495
+ const sourceAliasExcludes = new Set(["@agent-native/pinpoint"]);
2496
+
2497
+ for (const { packageName, packageDir } of packages) {
2498
+ if (sourceAliasExcludes.has(packageName)) continue;
2499
+ const pkgPath = path.join(packageDir, "package.json");
2500
+ if (!fs.existsSync(pkgPath)) continue;
2501
+
2502
+ try {
2503
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
2504
+ const exportsMap = pkg.exports as Record<string, unknown> | undefined;
2505
+ if (!exportsMap || typeof exportsMap !== "object") continue;
2506
+
2507
+ for (const [exportPath, target] of Object.entries(exportsMap)) {
2508
+ const exportTarget = localWorkspaceExportTarget(packageDir, target);
2509
+ if (!exportTarget) continue;
2510
+ const importPath =
2511
+ exportPath === "."
2512
+ ? packageName
2513
+ : `${packageName}${exportPath.slice(1)}`;
2514
+ const replacement = path.resolve(packageDir, exportTarget);
2515
+
2516
+ if (importPath.includes("*") || replacement.includes("*")) {
2517
+ aliases.push({
2518
+ find: new RegExp(
2519
+ `^${escapeRegex(importPath).replace("\\*", "(.+)")}$`,
2520
+ ),
2521
+ replacement: replacement.replace("*", "$1"),
2522
+ });
2523
+ continue;
2524
+ }
2525
+
2526
+ aliases.push({
2527
+ find: new RegExp(`^${escapeRegex(importPath)}$`),
2528
+ replacement,
2529
+ });
2530
+ }
2531
+ } catch {
2532
+ // Ignore malformed package metadata; normal package resolution can handle it.
2533
+ }
2534
+ }
2535
+
2536
+ return aliases;
2537
+ }
2538
+
2539
+ function localWorkspaceExportTarget(
2540
+ packageDir: string,
2541
+ target: unknown,
2542
+ ): string | null {
2543
+ const rawTarget = pickLocalWorkspaceExportTarget(target);
2544
+ if (!rawTarget) return null;
2545
+ return distExportToSourceTarget(packageDir, rawTarget);
2546
+ }
2547
+
2548
+ function pickLocalWorkspaceExportTarget(target: unknown): string | null {
2549
+ if (typeof target === "string") return target;
2550
+ if (!target || typeof target !== "object" || Array.isArray(target)) {
2551
+ return null;
2552
+ }
2553
+
2554
+ const record = target as Record<string, unknown>;
2555
+ for (const condition of ["development", "browser", "import", "default"]) {
2556
+ const resolved = pickLocalWorkspaceExportTarget(record[condition]);
2557
+ if (resolved) return resolved;
2558
+ }
2559
+ return null;
2560
+ }
2561
+
2562
+ function distExportToSourceTarget(packageDir: string, target: string): string {
2563
+ if (!target.startsWith("./dist/")) return target;
2564
+
2565
+ if (target.includes("*")) {
2566
+ return target
2567
+ .replace("./dist/", "./src/")
2568
+ .replace(/\.d\.ts$/, "")
2569
+ .replace(/\.js$/, "");
2570
+ }
2571
+
2572
+ const sourceBase = target
2573
+ .replace("./dist/", "./src/")
2574
+ .replace(/\.d\.ts$/, "")
2575
+ .replace(/\.js$/, "");
2576
+ const candidates = target.endsWith(".css")
2577
+ ? [sourceBase]
2578
+ : [`${sourceBase}.tsx`, `${sourceBase}.ts`, sourceBase];
2579
+
2580
+ for (const candidate of candidates) {
2581
+ if (fs.existsSync(path.resolve(packageDir, candidate))) return candidate;
2582
+ }
2583
+ return target;
2584
+ }
2585
+
2586
+ function aliasArrayFrom(alias: unknown): any[] {
2587
+ if (!alias) return [];
2588
+ if (Array.isArray(alias)) return alias;
2589
+ if (typeof alias === "object") {
2590
+ return Object.entries(alias as Record<string, string>).map(
2591
+ ([find, replacement]) => ({ find, replacement }),
2592
+ );
2593
+ }
2594
+ return [];
2595
+ }
2596
+
2597
+ const DEFAULT_VITE_WATCH_IGNORES = [
2598
+ "**/.git/**",
2599
+ "**/node_modules/**",
2600
+ "**/.react-router/**",
2601
+ "**/.generated/**",
2602
+ "**/.agents/**",
2603
+ "**/.claude/**",
2604
+ "**/data/**",
2605
+ "**/dist/**",
2606
+ "**/build/**",
2607
+ ];
2608
+
2609
+ function forceServeOnly(pluginOrPreset: any): any {
2610
+ if (Array.isArray(pluginOrPreset)) return pluginOrPreset.map(forceServeOnly);
2611
+ return { ...pluginOrPreset, apply: "serve" };
2612
+ }
2613
+
2614
+ function createAgentNativePlugins(
2615
+ options: ClientConfigOptions | AgentNativeVitePluginOptions,
2616
+ {
2617
+ command,
2618
+ includeReactTransform,
2619
+ useServeOnlyNitroPlugin = false,
2620
+ userPlugins = [],
2621
+ }: {
2622
+ command?: AgentNativeViteCommand;
2623
+ includeReactTransform: boolean;
2624
+ useServeOnlyNitroPlugin?: boolean;
2625
+ userPlugins?: any[];
2626
+ },
2627
+ ): any[] {
2628
+ const { appBasePath } = getConfiguredAppBasePath();
2629
+ const nitroPlugin = createNitroDevPlugin(options, appBasePath);
2630
+ const includeNitro = !isBuildCommand(command);
2631
+
2632
+ return [
2633
+ // Stub packages from `options.ssrStubs` in the SSR bundle so they
2634
+ // don't bloat the edge worker. Opt-in per template — the framework
2635
+ // hardcodes nothing (e.g. docs sites legitimately import `shiki` on
2636
+ // the server, so we can't blanket-stub it here).
2637
+ ssrStubPlugin(options.ssrStubs ?? []),
2638
+ ...userPlugins,
2639
+ appChangelogRawPlugin(),
2640
+ actionTypesPlugin(),
2641
+ agentsBundlePlugin(),
2642
+ autoReloadOnOptimizeDep(),
2643
+ fullReloadOnOptimizeDep504(),
2644
+ embedDevFrameHeaders(),
2645
+ baseRedirectGuard(),
2646
+ portExposer(),
2647
+ silenceConnectionResets(),
2648
+ rolldownInputFix(),
2649
+ // Nitro Vite plugin for dev-mode API route serving and HMR.
2650
+ // Disabled during build — React Router's build handles production.
2651
+ ...(useServeOnlyNitroPlugin
2652
+ ? [forceServeOnly(nitroPlugin)]
2653
+ : includeNitro
2654
+ ? [nitroPlugin]
2655
+ : []),
2656
+ includeReactTransform ? createReactTransformPlugin() : null,
2657
+ createTailwindPlugin(options),
2658
+ ].filter(Boolean);
2659
+ }
2660
+
2661
+ function resolveAgentNativeTemplate(cwd: string): string {
2662
+ const configured = [
2663
+ process.env.AGENT_NATIVE_TEMPLATE,
2664
+ process.env.VITE_AGENT_NATIVE_TEMPLATE,
2665
+ process.env.VITE_APP_TEMPLATE,
2666
+ ].find((value) => value?.trim());
2667
+ if (configured) return configured.trim().toLowerCase();
2668
+
2669
+ const normalizedCwd = cwd.replaceAll("\\", "/");
2670
+ const marker = "/templates/";
2671
+ const markerIndex = normalizedCwd.lastIndexOf(marker);
2672
+ if (markerIndex === -1) return "";
2673
+ return (
2674
+ normalizedCwd
2675
+ .slice(markerIndex + marker.length)
2676
+ .split("/")[0]
2677
+ ?.trim()
2678
+ .toLowerCase() ?? ""
2679
+ );
2680
+ }
2681
+
2682
+ function createAgentNativeConfig(
2683
+ options: ClientConfigOptions | AgentNativeVitePluginOptions = {},
2684
+ command?: AgentNativeViteCommand,
2685
+ userConfig: UserConfig = {},
2686
+ ): UserConfig {
2687
+ const cwd = process.cwd();
2688
+
2689
+ // Workspace env fallback. If this app is inside a workspace, tell Vite to
2690
+ // also look for .env files at the workspace root. Per-app .env still wins
2691
+ // (Vite's loadEnv merges in precedence order — app dir is loaded after).
2692
+ const workspaceRoot = findWorkspaceRoot(cwd);
2693
+ const envDir = workspaceRoot && workspaceRoot !== cwd ? workspaceRoot : cwd;
2694
+
2695
+ // Preload workspace-root .env into process.env so Nitro server code sees
2696
+ // shared keys during dev (Nitro reads process.env, not vite's envDir).
2697
+ if (workspaceRoot && workspaceRoot !== cwd) {
2698
+ try {
2699
+ const dotenv = require("dotenv");
2700
+ dotenv.config({
2701
+ path: path.join(workspaceRoot, ".env"),
2702
+ override: false,
2703
+ // Suppress the dotenv v17 tip line — this loader fires alongside
2704
+ // utils.ts loadEnv() during dev startup and would otherwise emit a
2705
+ // duplicate "[dotenv] injecting env" message.
2706
+ quiet: true,
2707
+ });
2708
+ } catch {}
2709
+ }
2710
+
2711
+ const { base } = getConfiguredAppBasePath();
2712
+ const isWorkspaceChild = process.env.AGENT_NATIVE_WORKSPACE === "1";
2713
+ const monorepoPackageAllow = [
2714
+ path.resolve(cwd, "../../packages/core"),
2715
+ path.resolve(cwd, "../core"),
2716
+ path.resolve(cwd, "../../packages/toolkit"),
2717
+ path.resolve(cwd, "../toolkit"),
2718
+ ].filter((candidate) => fs.existsSync(path.join(candidate, "package.json")));
2719
+ const monorepoNodeModulesAllow = [
2720
+ path.resolve(cwd, "../../node_modules"),
2721
+ ].filter((candidate) => fs.existsSync(candidate));
2722
+
2723
+ // Workspace-core (enterprise monorepo): pull its directory into Vite's
2724
+ // file watcher + module graph so edits to its TS sources hot-reload the
2725
+ // dev server, and its package name into ssr.noExternal so the dynamic
2726
+ // import in framework-request-handler.ts goes through Vite's transform
2727
+ // pipeline (TypeScript, SSR HMR, the works).
2728
+ const workspaceCore = findWorkspaceCoreSync(cwd);
2729
+ const workspaceCoreFsAllow = workspaceCore
2730
+ ? [
2731
+ workspaceCore.packageDir,
2732
+ // Also allow the workspace root's node_modules so Vite can serve
2733
+ // pnpm-hoisted transitive deps (e.g. recharts, es-toolkit) as native
2734
+ // ESM when they are excluded from the Rolldown optimizer.
2735
+ path.join(workspaceCore.workspaceRoot, "node_modules"),
2736
+ ]
2737
+ : [];
2738
+ const workspaceNodeModulesAllow = isWorkspaceChild
2739
+ ? [path.resolve(cwd, "../../node_modules")]
2740
+ : [];
2741
+ const packageWorkspaceRoot = workspaceRoot ?? findPnpmWorkspaceRoot(cwd);
2742
+ const localWorkspacePackageDeps = findLocalWorkspacePackageDeps(
2743
+ cwd,
2744
+ packageWorkspaceRoot,
2745
+ );
2746
+ const localWorkspacePackageAllow = localWorkspacePackageDeps.map(
2747
+ (pkg) => pkg.packageDir,
2748
+ );
2749
+ const localWorkspacePackageResolveAliases = localWorkspacePackageAliases(
2750
+ localWorkspacePackageDeps,
2751
+ );
2752
+ const workspaceCoreNoExternal = workspaceCore
2753
+ ? [new RegExp(`^${escapeRegex(workspaceCore.packageName)}(/.*)?$`)]
2754
+ : [];
2755
+ const localWorkspacePackageNoExternal = localWorkspacePackageDeps.map(
2756
+ (pkg) => new RegExp(`^${escapeRegex(pkg.packageName)}(/.*)?$`),
2757
+ );
2758
+ const forcePollingWatch = process.env.CHOKIDAR_USEPOLLING === "1";
2759
+ const pollingWatchInterval = Number(process.env.CHOKIDAR_INTERVAL ?? 1000);
2760
+ const userWatch = userConfig.server?.watch ?? {};
2761
+
2762
+ return {
2763
+ logLevel:
2764
+ options.logLevel ??
2765
+ userConfig.logLevel ??
2766
+ (isWorkspaceChild ? "warn" : undefined),
2767
+ envDir,
2768
+ base,
2769
+ define: {
2770
+ ...(userConfig.define ?? {}),
2771
+ ...(options.define ?? {}),
2772
+ __AGENT_NATIVE_BUILD_GA_MEASUREMENT_ID__: JSON.stringify(
2773
+ process.env.GA_MEASUREMENT_ID?.trim() || "",
2774
+ ),
2775
+ "process.env.AGENT_NATIVE_BUILD_GA_MEASUREMENT_ID": JSON.stringify(
2776
+ process.env.GA_MEASUREMENT_ID?.trim() || "",
2777
+ ),
2778
+ // Framework route warmup controls how SSR `.data` routes are fetched:
2779
+ // ordinary fetches keep them CDN-cacheable, while native prefetch headers
2780
+ // can be refused before the CDN/origin sees the request. Keep this value
2781
+ // authoritative even if app config provides its own `define` entries.
2782
+ __AGENT_NATIVE_ROUTE_WARMUP_CONFIG__: JSON.stringify(
2783
+ normalizeAgentNativeRouteWarmupConfig(options.routeWarmup),
2784
+ ),
2785
+ __AGENT_NATIVE_MCP_INTEGRATIONS_CONFIG__: JSON.stringify(
2786
+ normalizeMcpIntegrationsConfig(options.mcpIntegrations),
2787
+ ),
2788
+ __AGENT_NATIVE_TEMPLATE__: JSON.stringify(
2789
+ resolveAgentNativeTemplate(cwd),
2790
+ ),
2791
+ },
2792
+ server: {
2793
+ ...(userConfig.server ?? {}),
2794
+ host: userConfig.server?.host ?? "::",
2795
+ port: options.port ?? userConfig.server?.port ?? 8080,
2796
+ allowedHosts: options.allowedHosts ??
2797
+ userConfig.server?.allowedHosts ?? [
2798
+ ".ngrok-free.dev",
2799
+ ".ngrok-free.app",
2800
+ ".ngrok.io",
2801
+ ".trycloudflare.com",
2802
+ ],
2803
+ watch: {
2804
+ ...userWatch,
2805
+ ignored: [
2806
+ ...DEFAULT_VITE_WATCH_IGNORES,
2807
+ ...arrayFrom((userWatch as { ignored?: any })?.ignored),
2808
+ ],
2809
+ ...(forcePollingWatch
2810
+ ? {
2811
+ usePolling: true,
2812
+ interval: Number.isFinite(pollingWatchInterval)
2813
+ ? pollingWatchInterval
2814
+ : 1000,
2815
+ }
2816
+ : {}),
2817
+ },
2818
+ fs: {
2819
+ ...(userConfig.server?.fs ?? {}),
2820
+ allow: [
2821
+ ".",
2822
+ ...monorepoPackageAllow,
2823
+ ...monorepoNodeModulesAllow,
2824
+ ...workspaceCoreFsAllow,
2825
+ ...localWorkspacePackageAllow,
2826
+ ...workspaceNodeModulesAllow,
2827
+ ...(userConfig.server?.fs?.allow ?? []),
2828
+ ...(options.fsAllow ?? []),
2829
+ ],
2830
+ deny: [
2831
+ ".env",
2832
+ ".env.*",
2833
+ "*.{crt,pem}",
2834
+ "**/.git/**",
2835
+ ...(userConfig.server?.fs?.deny ?? []),
2836
+ ...(options.fsDeny ?? []),
2837
+ ],
2838
+ },
2839
+ },
2840
+ build: {
2841
+ ...(userConfig.build ?? {}),
2842
+ outDir: options.outDir ?? userConfig.build?.outDir ?? "dist/spa",
2843
+ // Vite 8 defaults CSS minification to Lightning CSS, which collapses a
2844
+ // `backdrop-filter` + `-webkit-backdrop-filter` pair down to only the
2845
+ // prefixed form. Chrome ignores that, so glass effects disappear in
2846
+ // production. Keep esbuild as the CSS minifier and target Safari 18+ so
2847
+ // the standard property survives the production pipeline.
2848
+ cssMinify: userConfig.build?.cssMinify ?? "esbuild",
2849
+ cssTarget: userConfig.build?.cssTarget ?? ["es2020", "safari18"],
2850
+ },
2851
+ // Bundle all non-Node.js deps into the production SSR server build.
2852
+ // Edge runtimes (CF Workers, Deno) don't have node_modules at runtime.
2853
+ // In dev, React Router's Vite Environment runner expects CJS packages
2854
+ // like React to stay external; forcing them through the module runner
2855
+ // raises `module is not defined`.
2856
+ ssr: isBuildCommand(command)
2857
+ ? {
2858
+ ...(userConfig.ssr ?? {}),
2859
+ noExternal: /^(?!node:)/,
2860
+ external: [
2861
+ // Yjs is used by both server-side collaboration actions and the
2862
+ // client SSR graph. If Vite inlines it here, Nitro also emits its
2863
+ // own server copy and a single request imports Yjs twice, breaking
2864
+ // Yjs constructor identity. This externalizes only Vite's
2865
+ // intermediate React Router SSR graph; Nitro's final Node/edge
2866
+ // bundle still owns and bundles the dependency, so both paths
2867
+ // share one portable module instance.
2868
+ "yjs",
2869
+ ...NODE_SSR_NATIVE_EXTERNALS,
2870
+ ...arrayFrom((userConfig.ssr as { external?: any })?.external),
2871
+ ],
2872
+ // Pick the workspace-core's compiled `dist/` exports in prod —
2873
+ // Node-style `default` condition matches what edge runtimes (CF
2874
+ // Workers, Deno) can actually load. Without this, Vite's prod
2875
+ // build inherits the dev-condition src/ entry and ships unbuilt
2876
+ // TypeScript into the worker.
2877
+ resolve: {
2878
+ ...((
2879
+ userConfig.ssr as
2880
+ | { resolve?: Record<string, unknown> }
2881
+ | undefined
2882
+ )?.resolve ?? {}),
2883
+ conditions: ["node", "module", "import", "default"],
2884
+ externalConditions: ["node", "module", "import", "default"],
2885
+ },
2886
+ }
2887
+ : {
2888
+ ...(userConfig.ssr ?? {}),
2889
+ // Vite already sets `development` in the dev resolve conditions,
2890
+ // so the workspace-core template's exports.development → src/
2891
+ // entry is picked automatically — Vite handles TS compilation
2892
+ // and triggers a server restart when those files change.
2893
+ noExternal: [
2894
+ /^@agent-native\/core(\/.*)?$/,
2895
+ // Keep React Router in Vite's SSR module graph so resolve.dedupe
2896
+ // can force root.tsx and core's shared entry-server through the
2897
+ // same FrameworkContext instance.
2898
+ ...(hasDep("react-router", cwd) ? [/^react-router(\/.*)?$/] : []),
2899
+ // Radix UI primitives are transitive deps of @agent-native/core
2900
+ // (used by FeedbackButton, AgentSidebar, ShareDialog, etc.). When
2901
+ // a consumer app SSRs a component that imports Radix, Node's
2902
+ // externalized resolver can't find @radix-ui/* from the app cwd
2903
+ // because pnpm doesn't hoist transitive deps. Bundling them
2904
+ // through Vite resolves them via the workspace store.
2905
+ /^@radix-ui\//,
2906
+ // scheduling ships TypeScript-compiled dist files that contain literal
2907
+ // `@/` path-alias imports (e.g. `import { Input } from
2908
+ // "@/components/ui/input"`). In standalone (published) mode Node
2909
+ // treats the package as an external CJS dep and can't resolve
2910
+ // `@/components`. Adding it to noExternal makes Vite process it
2911
+ // through the module pipeline, where the consumer app's `@` →
2912
+ // `./app` alias is already registered.
2913
+ ...(hasDep("@agent-native/scheduling", cwd)
2914
+ ? [/^@agent-native\/scheduling(\/.*)?$/]
2915
+ : []),
2916
+ ...workspaceCoreNoExternal,
2917
+ ...localWorkspacePackageNoExternal,
2918
+ ...arrayFrom((userConfig.ssr as { noExternal?: any })?.noExternal),
2919
+ ],
2920
+ external: [
2921
+ "react",
2922
+ "react-dom",
2923
+ "react-dom/server",
2924
+ ...arrayFrom((userConfig.ssr as { external?: any })?.external),
2925
+ ],
2926
+ },
2927
+ optimizeDeps: {
2928
+ ...(userConfig.optimizeDeps ?? {}),
2929
+ include: [
2930
+ ...getDefaultOptimizeDeps(cwd),
2931
+ ...(hasDep("@agent-native/pinpoint", cwd)
2932
+ ? ["@agent-native/pinpoint/react"]
2933
+ : []),
2934
+ ...(userConfig.optimizeDeps?.include ?? []),
2935
+ ...(options.optimizeDeps?.include ?? []),
2936
+ ],
2937
+ // In monorepo mode: explicitly exclude @agent-native/core subpaths so
2938
+ // Vite never prebundles them from dist/. The source alias above
2939
+ // (`getCoreSourceAliases`) resolves every import to src/ on every
2940
+ // request, so HMR picks up new exports immediately. Without exclude,
2941
+ // the prebundle is built from dist/ once at startup and silently
2942
+ // serves stale code even after the source / dist is updated.
2943
+ exclude: [
2944
+ ...(findCoreSrcDir(cwd) !== null ? CORE_CLIENT_SUBPATHS : []),
2945
+ ...(userConfig.optimizeDeps?.exclude ?? []),
2946
+ ...(options.optimizeDeps?.exclude ?? []),
2947
+ ],
2948
+ },
2949
+ resolve: {
2950
+ ...(userConfig.resolve ?? {}),
2951
+ // Dedupe all client-side packages that core shares with the consuming
2952
+ // app. In pnpm monorepos, core's devDependencies can install separate
2953
+ // copies (linked to different React versions). Without deduping, each
2954
+ // copy creates its own React context — QueryClientProvider, RouterProvider,
2955
+ // Radix, etc. — causing "No provider" crashes at runtime.
2956
+ dedupe: [
2957
+ ...getClientDedupe(cwd),
2958
+ ...arrayFrom((userConfig.resolve as { dedupe?: any })?.dedupe),
2959
+ ],
2960
+ alias: [
2961
+ // Published npm installs: one react-router instance for app + core.
2962
+ ...getReactRouterAliases(cwd),
2963
+ // In monorepo dev: resolve @agent-native/core to source for HMR.
2964
+ // Uses regex with $ anchor for exact matching to prevent
2965
+ // @agent-native/core from prefix-matching @agent-native/core/client.
2966
+ ...getCoreSourceAliases(cwd),
2967
+ ...localWorkspacePackageResolveAliases,
2968
+ // Standard path aliases (prefix matching is fine here)
2969
+ { find: "@", replacement: path.resolve(cwd, "./app") },
2970
+ { find: "@shared", replacement: path.resolve(cwd, "./shared") },
2971
+ ...Object.entries(options.aliases ?? {}).map(([find, replacement]) => ({
2972
+ find,
2973
+ replacement,
2974
+ })),
2975
+ ...aliasArrayFrom((userConfig.resolve as { alias?: unknown })?.alias),
2976
+ ],
2977
+ },
2978
+ };
2979
+ }
2980
+
2981
+ /**
2982
+ * Agent-Native's Vite plugin preset.
2983
+ *
2984
+ * Use this in ordinary Vite configs so `vite.config.ts` keeps Vite's native
2985
+ * `UserConfig` type surface:
2986
+ *
2987
+ * ```ts
2988
+ * import { defineConfig } from "vite";
2989
+ * import { reactRouter } from "@react-router/dev/vite";
2990
+ * import { agentNative } from "@agent-native/core/vite";
2991
+ *
2992
+ * export default defineConfig({
2993
+ * plugins: [reactRouter(), agentNative({ ssrStubs: ["shiki"] })],
2994
+ * });
2995
+ * ```
2996
+ */
2997
+ export function agentNative(
2998
+ options: AgentNativeVitePluginOptions = {},
2999
+ ): Plugin[] {
3000
+ return [
3001
+ {
3002
+ name: "agent-native-config",
3003
+ enforce: "pre",
3004
+ config(config: UserConfig, env: ConfigEnv) {
3005
+ return createAgentNativeConfig(options, env.command, config);
3006
+ },
3007
+ },
3008
+ ...createAgentNativePlugins(options, {
3009
+ includeReactTransform: options.legacySpa === true,
3010
+ useServeOnlyNitroPlugin: true,
3011
+ }),
3012
+ ] as Plugin[];
3013
+ }
3014
+
3015
+ /**
3016
+ * Create the client Vite config with sensible agent-native defaults.
3017
+ *
3018
+ * @deprecated Prefer `defineConfig` from `vite` plus the `agentNative()` plugin
3019
+ * preset. This compatibility wrapper remains for existing templates.
3020
+ */
3021
+ export function defineConfig(options: ClientConfigOptions = {}): UserConfig {
3022
+ const includeReactTransform =
3023
+ !hasReactRouterPlugin(options.plugins) && !options.reactRouter;
3024
+ return {
3025
+ ...createAgentNativeConfig(options),
3026
+ plugins: createAgentNativePlugins(options, {
3027
+ includeReactTransform,
3028
+ userPlugins: options.plugins,
3029
+ }),
3030
+ };
3031
+ }
3032
+
3033
+ export {
3034
+ getClientDedupe as _getClientDedupe,
3035
+ getDefaultOptimizeDeps as _getDefaultOptimizeDeps,
3036
+ findCorePackageRoot as _findCorePackageRoot,
3037
+ getReactRouterAliases as _getReactRouterAliases,
3038
+ debounceNitroFullReloadHotUpdate as _debounceNitroFullReloadHotUpdate,
3039
+ };