@agent-native/core 0.113.0 → 0.114.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1638) hide show
  1. package/agent-native.eject.json +164 -0
  2. package/corpus/README.md +3 -3
  3. package/corpus/core/CHANGELOG.md +20 -0
  4. package/corpus/core/README.md +61 -174
  5. package/corpus/core/agent-native.eject.json +164 -0
  6. package/corpus/core/docs/content/agent-native-toolkit.mdx +38 -0
  7. package/corpus/core/docs/content/package-lifecycle.mdx +54 -4
  8. package/corpus/core/package.json +15 -2
  9. package/corpus/core/src/cli/eject.ts +1594 -0
  10. package/corpus/core/src/cli/index.ts +16 -0
  11. package/corpus/core/src/client/build-compatibility.ts +77 -0
  12. package/corpus/core/src/client/index.ts +4 -0
  13. package/corpus/core/src/client/resources/McpConnectionSuggestion.tsx +8 -2
  14. package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +7 -2
  15. package/corpus/core/src/client/resources/ResourcesPanel.tsx +17 -3
  16. package/corpus/core/src/client/resources/index.ts +19 -0
  17. package/corpus/core/src/client/resources/mcp-integration-catalog.ts +9 -1
  18. package/corpus/core/src/client/resources/runtime.ts +1 -0
  19. package/corpus/core/src/client/route-chunk-recovery/index.ts +1 -0
  20. package/corpus/core/src/client/setup-connections/catalog.ts +6 -0
  21. package/corpus/core/src/client/setup-connections/index.ts +1 -0
  22. package/corpus/core/src/client/setup-connections/runtime.ts +1 -0
  23. package/corpus/core/src/client/use-action.ts +32 -1
  24. package/corpus/core/src/connections/catalog.ts +41 -24
  25. package/corpus/core/src/connections/index.ts +1 -0
  26. package/corpus/core/src/connections/runtime.ts +1 -0
  27. package/corpus/core/src/deploy/build.ts +4 -1
  28. package/corpus/core/src/eject/provider-api-definitions.ts +193 -0
  29. package/corpus/core/src/eject/remote-mcp-presets.ts +137 -0
  30. package/corpus/core/src/eject/setup-readiness-ui.tsx +29 -0
  31. package/corpus/core/src/eject/workspace-connections.ts +92 -0
  32. package/corpus/core/src/index.ts +1 -0
  33. package/corpus/core/src/integrations/adapter-overrides.ts +12 -0
  34. package/corpus/core/src/integrations/eject/messaging-adapters.ts +85 -0
  35. package/corpus/core/src/integrations/index.ts +5 -1
  36. package/corpus/core/src/integrations/plugin.ts +34 -12
  37. package/corpus/core/src/integrations/runtime.ts +1 -0
  38. package/corpus/core/src/integrations/types.ts +3 -1
  39. package/corpus/core/src/org/context.ts +56 -30
  40. package/corpus/core/src/package-lifecycle/eject-manifest.ts +345 -0
  41. package/corpus/core/src/package-lifecycle/index.ts +1 -0
  42. package/corpus/core/src/provider-api/index.ts +46 -12
  43. package/corpus/core/src/provider-api/runtime.ts +1 -0
  44. package/corpus/core/src/server/action-routes.ts +52 -2
  45. package/corpus/core/src/server/auth-plugin.ts +9 -4
  46. package/corpus/core/src/server/better-auth-instance.ts +5 -1
  47. package/corpus/core/src/setup-connections/index.ts +1 -0
  48. package/corpus/core/src/shared/mcp-embed-headers.ts +1 -1
  49. package/corpus/core/src/shared/merge-by-id.ts +14 -0
  50. package/corpus/core/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
  51. package/corpus/core/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  52. package/corpus/core/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
  53. package/corpus/core/src/templates/default/AGENTS.md +6 -5
  54. package/corpus/core/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
  55. package/corpus/core/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  56. package/corpus/core/src/templates/headless/AGENTS.md +5 -4
  57. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
  58. package/corpus/core/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
  59. package/corpus/core/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  60. package/corpus/core/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
  61. package/corpus/core/src/templates/workspace-core/AGENTS.md +4 -4
  62. package/corpus/core/src/templates/workspace-root/AGENTS.md +4 -4
  63. package/corpus/core/src/vite/client.ts +42 -2
  64. package/corpus/templates/analytics/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  65. package/corpus/templates/analytics/.agents/skills/self-modifying-code/SKILL.md +9 -6
  66. package/corpus/templates/assets/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  67. package/corpus/templates/assets/.agents/skills/self-modifying-code/SKILL.md +9 -6
  68. package/corpus/templates/brain/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  69. package/corpus/templates/brain/.agents/skills/self-modifying-code/SKILL.md +9 -6
  70. package/corpus/templates/brain/actions/remediate-legacy-capture-audiences.ts +167 -0
  71. package/corpus/templates/brain/app/lib/brain-chat-readiness.ts +6 -0
  72. package/corpus/templates/brain/app/routes/_index.tsx +8 -0
  73. package/corpus/templates/brain/app/routes.ts +1 -0
  74. package/corpus/templates/brain/changelog/2026-07-19-ask-starts-immediately-when-builder-s-managed-ai-connection-.md +6 -0
  75. package/corpus/templates/brain/changelog/2026-07-19-slack-and-granola-backfills-now-process-captures-concurrentl.md +6 -0
  76. package/corpus/templates/brain/changelog/2026-07-19-source-review-settings-now-control-knowledge-approval.md +6 -0
  77. package/corpus/templates/brain/changelog/2026-07-19-the-manage-agent-page-now-opens-correctly-from-brain-navigat.md +6 -0
  78. package/corpus/templates/brain/server/db/schema.ts +3 -0
  79. package/corpus/templates/brain/server/lib/brain.ts +41 -2
  80. package/corpus/templates/brain/server/lib/connectors.ts +379 -113
  81. package/corpus/templates/brain/server/lib/meeting-audience.ts +38 -0
  82. package/corpus/templates/brain/server/plugins/db.ts +10 -0
  83. package/corpus/templates/brain/server/routes/api/_agent-native/brain/ingest.post.ts +6 -4
  84. package/corpus/templates/calendar/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  85. package/corpus/templates/calendar/.agents/skills/self-modifying-code/SKILL.md +9 -6
  86. package/corpus/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
  87. package/corpus/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  88. package/corpus/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
  89. package/corpus/templates/chat/AGENTS.md +3 -2
  90. package/corpus/templates/clips/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  91. package/corpus/templates/clips/.agents/skills/self-modifying-code/SKILL.md +9 -6
  92. package/corpus/templates/content/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  93. package/corpus/templates/content/.agents/skills/self-modifying-code/SKILL.md +9 -6
  94. package/corpus/templates/content/AGENTS.md +2 -0
  95. package/corpus/templates/content/actions/_content-database-personal-view.ts +49 -5
  96. package/corpus/templates/content/actions/_content-document-access.ts +21 -0
  97. package/corpus/templates/content/actions/_content-favorites.ts +91 -0
  98. package/corpus/templates/content/actions/_content-files.ts +79 -23
  99. package/corpus/templates/content/actions/_content-sidebar-state.ts +24 -0
  100. package/corpus/templates/content/actions/_content-space-access.ts +15 -17
  101. package/corpus/templates/content/actions/_content-space-catalog-guards.ts +20 -0
  102. package/corpus/templates/content/actions/_content-spaces.ts +364 -167
  103. package/corpus/templates/content/actions/_database-source-utils.ts +8 -0
  104. package/corpus/templates/content/actions/_database-utils.ts +249 -15
  105. package/corpus/templates/content/actions/_delete-content-space.ts +84 -0
  106. package/corpus/templates/content/actions/_files-system-properties.ts +499 -0
  107. package/corpus/templates/content/actions/_local-file-documents.ts +0 -1
  108. package/corpus/templates/content/actions/_property-utils.ts +18 -9
  109. package/corpus/templates/content/actions/bind-content-database-source-field.ts +3 -0
  110. package/corpus/templates/content/actions/configure-document-property.ts +3 -0
  111. package/corpus/templates/content/actions/create-content-database.ts +2 -2
  112. package/corpus/templates/content/actions/create-content-space.ts +34 -0
  113. package/corpus/templates/content/actions/create-document.ts +4 -1
  114. package/corpus/templates/content/actions/delete-content-space.ts +19 -0
  115. package/corpus/templates/content/actions/delete-database-items.ts +28 -1
  116. package/corpus/templates/content/actions/delete-document-property.ts +3 -0
  117. package/corpus/templates/content/actions/delete-document.ts +39 -2
  118. package/corpus/templates/content/actions/duplicate-database-item.ts +6 -0
  119. package/corpus/templates/content/actions/duplicate-database-items.ts +6 -0
  120. package/corpus/templates/content/actions/duplicate-document-property.ts +3 -0
  121. package/corpus/templates/content/actions/get-content-database.ts +11 -2
  122. package/corpus/templates/content/actions/get-content-sidebar-state.ts +23 -0
  123. package/corpus/templates/content/actions/get-document.ts +32 -7
  124. package/corpus/templates/content/actions/import-content-source.ts +33 -1
  125. package/corpus/templates/content/actions/list-content-spaces.ts +34 -2
  126. package/corpus/templates/content/actions/list-documents.ts +39 -7
  127. package/corpus/templates/content/actions/reorder-document-property.ts +9 -0
  128. package/corpus/templates/content/actions/set-document-property.ts +41 -23
  129. package/corpus/templates/content/actions/share-local-file-document.ts +15 -0
  130. package/corpus/templates/content/actions/submit-content-database-form.ts +7 -0
  131. package/corpus/templates/content/actions/sync-local-folder-source.ts +14 -0
  132. package/corpus/templates/content/actions/update-content-database-view.ts +1 -0
  133. package/corpus/templates/content/actions/update-content-sidebar-state.ts +27 -0
  134. package/corpus/templates/content/actions/update-document.ts +158 -66
  135. package/corpus/templates/content/app/components/EmptyState.tsx +4 -57
  136. package/corpus/templates/content/app/components/editor/CommentsSidebar.tsx +8 -1
  137. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +519 -178
  138. package/corpus/templates/content/app/components/editor/DocumentInfoPanel.tsx +39 -0
  139. package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +1 -1
  140. package/corpus/templates/content/app/components/editor/DocumentToolbar.tsx +266 -7
  141. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +430 -152
  142. package/corpus/templates/content/app/components/editor/database/sidebar.tsx +467 -66
  143. package/corpus/templates/content/app/components/editor/database/view-config.ts +9 -3
  144. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +720 -196
  145. package/corpus/templates/content/app/components/sidebar/DocumentTreeItem.tsx +173 -1
  146. package/corpus/templates/content/app/components/sidebar/document-sidebar-sections.ts +1 -1
  147. package/corpus/templates/content/app/components/sidebar/select-content-space.ts +91 -16
  148. package/corpus/templates/content/app/entry.client.tsx +5 -1
  149. package/corpus/templates/content/app/hooks/use-content-database.ts +84 -3
  150. package/corpus/templates/content/app/hooks/use-content-spaces.ts +60 -2
  151. package/corpus/templates/content/app/hooks/use-create-page.ts +30 -0
  152. package/corpus/templates/content/app/hooks/use-documents.ts +270 -19
  153. package/corpus/templates/content/app/i18n-data.ts +243 -20
  154. package/corpus/templates/content/app/lib/local-folder-picker-safety.ts +54 -0
  155. package/corpus/templates/content/app/lib/local-folder-picker-support.ts +18 -0
  156. package/corpus/templates/content/app/routes/_app.favorites.tsx +30 -0
  157. package/corpus/templates/content/app/routes/_app.local-files.tsx +18 -6
  158. package/corpus/templates/content/changelog/2026-07-17-workspace-files-now-stay-in-a-loading-state-until-automatic-.md +6 -0
  159. package/corpus/templates/content/changelog/2026-07-17-workspace-switching-now-opens-the-selected-files-database-pr.md +6 -0
  160. package/corpus/templates/content/changelog/2026-07-17-workspaces-now-expand-above-their-own-files-list-without-dup.md +6 -0
  161. package/corpus/templates/content/changelog/2026-07-18-create-named-workspaces-each-with-its-own-private-files-data.md +6 -0
  162. package/corpus/templates/content/changelog/2026-07-18-favorites-align-with-workspace-and-file-rows-in-the-sidebar.md +6 -0
  163. package/corpus/templates/content/changelog/2026-07-18-local-folder-selection-no-longer-invokes-the-unsafe-native-p.md +6 -0
  164. package/corpus/templates/content/changelog/2026-07-18-made-content-workspaces-independently-expandable-restored-or.md +6 -0
  165. package/corpus/templates/content/changelog/2026-07-18-page-details-now-live-in-a-shared-info-and-comments-rail-dat.md +6 -0
  166. package/corpus/templates/content/changelog/2026-07-18-workspace-database-views-now-control-sidebar-workspace-navig.md +6 -0
  167. package/corpus/templates/content/changelog/2026-07-18-workspace-navigation-now-aligns-favorites-with-workspace-pag.md +6 -0
  168. package/corpus/templates/content/changelog/2026-07-19-favorites-now-open-as-a-table-and-compact-breadcrumbs-make-w.md +6 -0
  169. package/corpus/templates/content/changelog/2026-07-19-files-databases-now-start-unfiltered-sidebar-rows-exactly-fo.md +6 -0
  170. package/corpus/templates/content/changelog/2026-07-19-sidebar-page-trees-now-open-only-when-expanded-remember-thei.md +6 -0
  171. package/corpus/templates/content/changelog/2026-07-19-workspace-file-databases-now-use-the-workspace-name-open-as-.md +6 -0
  172. package/corpus/templates/content/changelog/2026-07-19-workspace-navigation-now-stays-stable-on-hover-uses-folder-i.md +6 -0
  173. package/corpus/templates/content/changelog/2026-07-19-workspace-rows-now-use-folder-icons-and-deleting-a-user-crea.md +6 -0
  174. package/corpus/templates/content/changelog/2026-07-19-workspaces-can-be-created-without-leaving-the-workspaces-dat.md +6 -0
  175. package/corpus/templates/content/e2e/global-setup.ts +3 -2
  176. package/corpus/templates/content/parity/matrix.md +28 -28
  177. package/corpus/templates/content/parity/matrix.ts +8 -2
  178. package/corpus/templates/content/server/db/index.ts +1 -0
  179. package/corpus/templates/content/server/db/schema.ts +10 -0
  180. package/corpus/templates/content/server/lib/documents.ts +12 -7
  181. package/corpus/templates/content/server/plugins/db.ts +17 -0
  182. package/corpus/templates/content/shared/api.ts +9 -0
  183. package/corpus/templates/content/shared/database-form.ts +11 -2
  184. package/corpus/templates/content/vite.config.ts +1 -0
  185. package/corpus/templates/design/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  186. package/corpus/templates/design/.agents/skills/self-modifying-code/SKILL.md +9 -6
  187. package/corpus/templates/dispatch/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  188. package/corpus/templates/dispatch/.agents/skills/self-modifying-code/SKILL.md +9 -6
  189. package/corpus/templates/forms/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  190. package/corpus/templates/forms/.agents/skills/self-modifying-code/SKILL.md +9 -6
  191. package/corpus/templates/macros/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  192. package/corpus/templates/mail/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  193. package/corpus/templates/mail/.agents/skills/self-modifying-code/SKILL.md +9 -6
  194. package/corpus/templates/plan/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  195. package/corpus/templates/plan/.agents/skills/self-modifying-code/SKILL.md +9 -6
  196. package/corpus/templates/slides/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  197. package/corpus/templates/slides/.agents/skills/self-modifying-code/SKILL.md +9 -6
  198. package/corpus/templates/tasks/.agents/skills/agent-native-docs/SKILL.md +15 -13
  199. package/corpus/templates/tasks/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  200. package/corpus/templates/tasks/.agents/skills/self-modifying-code/SKILL.md +9 -6
  201. package/corpus/toolkit/CHANGELOG.md +6 -0
  202. package/corpus/toolkit/agent-native.eject.json +411 -0
  203. package/corpus/toolkit/package.json +5 -2
  204. package/dist/cli/eject.d.ts +21 -0
  205. package/dist/cli/eject.d.ts.map +1 -0
  206. package/dist/cli/eject.js +1145 -0
  207. package/dist/cli/eject.js.map +1 -0
  208. package/dist/cli/index.js +15 -0
  209. package/dist/cli/index.js.map +1 -1
  210. package/dist/client/build-compatibility.d.ts +11 -0
  211. package/dist/client/build-compatibility.d.ts.map +1 -0
  212. package/dist/client/build-compatibility.js +56 -0
  213. package/dist/client/build-compatibility.js.map +1 -0
  214. package/dist/client/index.d.ts +1 -1
  215. package/dist/client/index.d.ts.map +1 -1
  216. package/dist/client/index.js +1 -1
  217. package/dist/client/index.js.map +1 -1
  218. package/dist/client/resources/McpConnectionSuggestion.d.ts +4 -3
  219. package/dist/client/resources/McpConnectionSuggestion.d.ts.map +1 -1
  220. package/dist/client/resources/McpConnectionSuggestion.js +3 -3
  221. package/dist/client/resources/McpConnectionSuggestion.js.map +1 -1
  222. package/dist/client/resources/McpIntegrationDialog.d.ts +4 -3
  223. package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
  224. package/dist/client/resources/McpIntegrationDialog.js +2 -2
  225. package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
  226. package/dist/client/resources/ResourcesPanel.d.ts +4 -1
  227. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  228. package/dist/client/resources/ResourcesPanel.js +9 -7
  229. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  230. package/dist/client/resources/index.d.ts +3 -0
  231. package/dist/client/resources/index.d.ts.map +1 -1
  232. package/dist/client/resources/index.js +3 -0
  233. package/dist/client/resources/index.js.map +1 -1
  234. package/dist/client/resources/mcp-integration-catalog.d.ts +2 -1
  235. package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
  236. package/dist/client/resources/mcp-integration-catalog.js +6 -2
  237. package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
  238. package/dist/client/resources/runtime.d.ts +2 -0
  239. package/dist/client/resources/runtime.d.ts.map +1 -0
  240. package/dist/client/resources/runtime.js +2 -0
  241. package/dist/client/resources/runtime.js.map +1 -0
  242. package/dist/client/route-chunk-recovery/index.d.ts +1 -0
  243. package/dist/client/route-chunk-recovery/index.d.ts.map +1 -1
  244. package/dist/client/route-chunk-recovery/index.js +1 -0
  245. package/dist/client/route-chunk-recovery/index.js.map +1 -1
  246. package/dist/client/setup-connections/catalog.d.ts +2 -0
  247. package/dist/client/setup-connections/catalog.d.ts.map +1 -0
  248. package/dist/client/setup-connections/catalog.js +7 -0
  249. package/dist/client/setup-connections/catalog.js.map +1 -0
  250. package/dist/client/setup-connections/index.d.ts +1 -0
  251. package/dist/client/setup-connections/index.d.ts.map +1 -1
  252. package/dist/client/setup-connections/index.js +1 -0
  253. package/dist/client/setup-connections/index.js.map +1 -1
  254. package/dist/client/setup-connections/runtime.d.ts +2 -0
  255. package/dist/client/setup-connections/runtime.d.ts.map +1 -0
  256. package/dist/client/setup-connections/runtime.js +2 -0
  257. package/dist/client/setup-connections/runtime.js.map +1 -0
  258. package/dist/client/use-action.d.ts.map +1 -1
  259. package/dist/client/use-action.js +19 -1
  260. package/dist/client/use-action.js.map +1 -1
  261. package/dist/collab/awareness.d.ts +2 -2
  262. package/dist/collab/awareness.d.ts.map +1 -1
  263. package/dist/collab/struct-routes.d.ts +1 -1
  264. package/dist/connections/catalog.d.ts +5 -3
  265. package/dist/connections/catalog.d.ts.map +1 -1
  266. package/dist/connections/catalog.js +16 -8
  267. package/dist/connections/catalog.js.map +1 -1
  268. package/dist/connections/index.d.ts +1 -1
  269. package/dist/connections/index.d.ts.map +1 -1
  270. package/dist/connections/index.js +1 -1
  271. package/dist/connections/index.js.map +1 -1
  272. package/dist/connections/runtime.d.ts +2 -0
  273. package/dist/connections/runtime.d.ts.map +1 -0
  274. package/dist/connections/runtime.js +2 -0
  275. package/dist/connections/runtime.js.map +1 -0
  276. package/dist/deploy/build.js +2 -1
  277. package/dist/deploy/build.js.map +1 -1
  278. package/dist/eject/provider-api-definitions.d.ts +34 -0
  279. package/dist/eject/provider-api-definitions.d.ts.map +1 -0
  280. package/dist/eject/provider-api-definitions.js +88 -0
  281. package/dist/eject/provider-api-definitions.js.map +1 -0
  282. package/dist/eject/remote-mcp-presets.d.ts +17 -0
  283. package/dist/eject/remote-mcp-presets.d.ts.map +1 -0
  284. package/dist/eject/remote-mcp-presets.js +81 -0
  285. package/dist/eject/remote-mcp-presets.js.map +1 -0
  286. package/dist/eject/setup-readiness-ui.d.ts +7 -0
  287. package/dist/eject/setup-readiness-ui.d.ts.map +1 -0
  288. package/dist/eject/setup-readiness-ui.js +13 -0
  289. package/dist/eject/setup-readiness-ui.js.map +1 -0
  290. package/dist/eject/workspace-connections.d.ts +11 -0
  291. package/dist/eject/workspace-connections.d.ts.map +1 -0
  292. package/dist/eject/workspace-connections.js +47 -0
  293. package/dist/eject/workspace-connections.js.map +1 -0
  294. package/dist/file-upload/actions/upload-image.d.ts +1 -1
  295. package/dist/index.d.ts +1 -1
  296. package/dist/index.d.ts.map +1 -1
  297. package/dist/index.js +1 -1
  298. package/dist/index.js.map +1 -1
  299. package/dist/integrations/adapter-overrides.d.ts +3 -0
  300. package/dist/integrations/adapter-overrides.d.ts.map +1 -0
  301. package/dist/integrations/adapter-overrides.js +7 -0
  302. package/dist/integrations/adapter-overrides.js.map +1 -0
  303. package/dist/integrations/eject/messaging-adapters.d.ts +12 -0
  304. package/dist/integrations/eject/messaging-adapters.d.ts.map +1 -0
  305. package/dist/integrations/eject/messaging-adapters.js +49 -0
  306. package/dist/integrations/eject/messaging-adapters.js.map +1 -0
  307. package/dist/integrations/index.d.ts +3 -2
  308. package/dist/integrations/index.d.ts.map +1 -1
  309. package/dist/integrations/index.js +2 -1
  310. package/dist/integrations/index.js.map +1 -1
  311. package/dist/integrations/plugin.d.ts +32 -1
  312. package/dist/integrations/plugin.d.ts.map +1 -1
  313. package/dist/integrations/plugin.js +19 -12
  314. package/dist/integrations/plugin.js.map +1 -1
  315. package/dist/integrations/runtime.d.ts +2 -0
  316. package/dist/integrations/runtime.d.ts.map +1 -0
  317. package/dist/integrations/runtime.js +2 -0
  318. package/dist/integrations/runtime.js.map +1 -0
  319. package/dist/integrations/types.d.ts +3 -1
  320. package/dist/integrations/types.d.ts.map +1 -1
  321. package/dist/integrations/types.js.map +1 -1
  322. package/dist/notifications/routes.d.ts +2 -2
  323. package/dist/observability/routes.d.ts +5 -5
  324. package/dist/org/context.d.ts +4 -2
  325. package/dist/org/context.d.ts.map +1 -1
  326. package/dist/org/context.js +44 -22
  327. package/dist/org/context.js.map +1 -1
  328. package/dist/package-lifecycle/eject-manifest.d.ts +43 -0
  329. package/dist/package-lifecycle/eject-manifest.d.ts.map +1 -0
  330. package/dist/package-lifecycle/eject-manifest.js +219 -0
  331. package/dist/package-lifecycle/eject-manifest.js.map +1 -0
  332. package/dist/package-lifecycle/index.d.ts +1 -0
  333. package/dist/package-lifecycle/index.d.ts.map +1 -1
  334. package/dist/package-lifecycle/index.js +1 -0
  335. package/dist/package-lifecycle/index.js.map +1 -1
  336. package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
  337. package/dist/provider-api/actions/provider-api.d.ts +11 -11
  338. package/dist/provider-api/index.d.ts +6 -2
  339. package/dist/provider-api/index.d.ts.map +1 -1
  340. package/dist/provider-api/index.js +25 -12
  341. package/dist/provider-api/index.js.map +1 -1
  342. package/dist/provider-api/runtime.d.ts +2 -0
  343. package/dist/provider-api/runtime.d.ts.map +1 -0
  344. package/dist/provider-api/runtime.js +2 -0
  345. package/dist/provider-api/runtime.js.map +1 -0
  346. package/dist/resources/handlers.d.ts +1 -1
  347. package/dist/server/action-routes.d.ts.map +1 -1
  348. package/dist/server/action-routes.js +32 -2
  349. package/dist/server/action-routes.js.map +1 -1
  350. package/dist/server/auth-plugin.d.ts.map +1 -1
  351. package/dist/server/auth-plugin.js +9 -5
  352. package/dist/server/auth-plugin.js.map +1 -1
  353. package/dist/server/better-auth-instance.d.ts.map +1 -1
  354. package/dist/server/better-auth-instance.js +4 -1
  355. package/dist/server/better-auth-instance.js.map +1 -1
  356. package/dist/setup-connections/index.d.ts +1 -1
  357. package/dist/setup-connections/index.d.ts.map +1 -1
  358. package/dist/setup-connections/index.js +1 -1
  359. package/dist/setup-connections/index.js.map +1 -1
  360. package/dist/shared/mcp-embed-headers.d.ts +1 -1
  361. package/dist/shared/mcp-embed-headers.d.ts.map +1 -1
  362. package/dist/shared/mcp-embed-headers.js +1 -1
  363. package/dist/shared/mcp-embed-headers.js.map +1 -1
  364. package/dist/shared/merge-by-id.d.ts +5 -0
  365. package/dist/shared/merge-by-id.d.ts.map +1 -0
  366. package/dist/shared/merge-by-id.js +7 -0
  367. package/dist/shared/merge-by-id.js.map +1 -0
  368. package/dist/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
  369. package/dist/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  370. package/dist/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
  371. package/dist/templates/chat/AGENTS.md +3 -2
  372. package/dist/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
  373. package/dist/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  374. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
  375. package/dist/templates/default/AGENTS.md +6 -5
  376. package/dist/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
  377. package/dist/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  378. package/dist/templates/headless/AGENTS.md +5 -4
  379. package/dist/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
  380. package/dist/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
  381. package/dist/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  382. package/dist/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
  383. package/dist/templates/workspace-core/AGENTS.md +4 -4
  384. package/dist/templates/workspace-root/AGENTS.md +4 -4
  385. package/dist/vite/client.d.ts +6 -0
  386. package/dist/vite/client.d.ts.map +1 -1
  387. package/dist/vite/client.js +30 -2
  388. package/dist/vite/client.js.map +1 -1
  389. package/docs/content/agent-native-toolkit.mdx +38 -0
  390. package/docs/content/package-lifecycle.mdx +54 -4
  391. package/package.json +15 -2
  392. package/src/a2a/agent-card.ts +83 -0
  393. package/src/a2a/artifact-response.ts +1648 -0
  394. package/src/a2a/auth-policy.ts +66 -0
  395. package/src/a2a/caller-auth.ts +102 -0
  396. package/src/a2a/client.ts +876 -0
  397. package/src/a2a/correlation.ts +50 -0
  398. package/src/a2a/handlers.ts +1285 -0
  399. package/src/a2a/index.ts +50 -0
  400. package/src/a2a/invoke.ts +348 -0
  401. package/src/a2a/response-text.ts +53 -0
  402. package/src/a2a/server.ts +586 -0
  403. package/src/a2a/task-store.ts +917 -0
  404. package/src/a2a/types.ts +221 -0
  405. package/src/a2a-claims.ts +52 -0
  406. package/src/action-change-marker.ts +74 -0
  407. package/src/action-ui.ts +38 -0
  408. package/src/action.ts +1406 -0
  409. package/src/adapters/cli/index.ts +6 -0
  410. package/src/adapters/cli/registry.ts +73 -0
  411. package/src/adapters/cli/shell-adapter.ts +92 -0
  412. package/src/adapters/cli/types.ts +27 -0
  413. package/src/agent/action-continuation-guidance.ts +38 -0
  414. package/src/agent/app-model-defaults.ts +201 -0
  415. package/src/agent/context-xray/actions/context-evict.ts +56 -0
  416. package/src/agent/context-xray/actions/context-manifest-get.ts +75 -0
  417. package/src/agent/context-xray/actions/context-pin.ts +56 -0
  418. package/src/agent/context-xray/actions/context-preview-get.ts +134 -0
  419. package/src/agent/context-xray/actions/context-report.ts +75 -0
  420. package/src/agent/context-xray/actions/context-restore.ts +51 -0
  421. package/src/agent/context-xray/actions/errors.ts +40 -0
  422. package/src/agent/context-xray/apply-directives.ts +137 -0
  423. package/src/agent/context-xray/directives-store.ts +178 -0
  424. package/src/agent/context-xray/identity.ts +37 -0
  425. package/src/agent/context-xray/manifest.ts +284 -0
  426. package/src/agent/context-xray/migrations.ts +32 -0
  427. package/src/agent/context-xray/plugin.ts +23 -0
  428. package/src/agent/context-xray/schema.ts +17 -0
  429. package/src/agent/context-xray/segments.ts +194 -0
  430. package/src/agent/context-xray/tokenize.ts +93 -0
  431. package/src/agent/default-model.ts +5 -0
  432. package/src/agent/durable-background.ts +547 -0
  433. package/src/agent/engine/ai-sdk-engine.ts +565 -0
  434. package/src/agent/engine/anthropic-engine.ts +320 -0
  435. package/src/agent/engine/builder-engine.ts +1110 -0
  436. package/src/agent/engine/builder-gateway-headers.ts +44 -0
  437. package/src/agent/engine/builtin.ts +122 -0
  438. package/src/agent/engine/context-directives-transform.ts +73 -0
  439. package/src/agent/engine/continuation-dispatch-retry.ts +168 -0
  440. package/src/agent/engine/credential-errors.ts +69 -0
  441. package/src/agent/engine/index.ts +54 -0
  442. package/src/agent/engine/openai-compatible-endpoint.ts +25 -0
  443. package/src/agent/engine/output-tokens.ts +181 -0
  444. package/src/agent/engine/provider-env-vars.ts +69 -0
  445. package/src/agent/engine/registry.ts +853 -0
  446. package/src/agent/engine/tool-call-journal-seed.ts +85 -0
  447. package/src/agent/engine/translate-ai-sdk.ts +407 -0
  448. package/src/agent/engine/translate-anthropic.ts +611 -0
  449. package/src/agent/engine/types.ts +310 -0
  450. package/src/agent/harness/acp-adapter.ts +893 -0
  451. package/src/agent/harness/acp-builtin.ts +70 -0
  452. package/src/agent/harness/ai-sdk-adapter.ts +509 -0
  453. package/src/agent/harness/background.ts +365 -0
  454. package/src/agent/harness/builtin.ts +50 -0
  455. package/src/agent/harness/index.ts +86 -0
  456. package/src/agent/harness/lifecycle.ts +498 -0
  457. package/src/agent/harness/registry.ts +97 -0
  458. package/src/agent/harness/runner.ts +182 -0
  459. package/src/agent/harness/store.ts +466 -0
  460. package/src/agent/harness/translate.ts +130 -0
  461. package/src/agent/harness/types.ts +129 -0
  462. package/src/agent/index.ts +32 -0
  463. package/src/agent/loop-settings.ts +186 -0
  464. package/src/agent/model-config.ts +363 -0
  465. package/src/agent/observational-memory/compactor.ts +78 -0
  466. package/src/agent/observational-memory/config.ts +78 -0
  467. package/src/agent/observational-memory/index.ts +79 -0
  468. package/src/agent/observational-memory/internal-run.ts +89 -0
  469. package/src/agent/observational-memory/message-text.ts +49 -0
  470. package/src/agent/observational-memory/migrations.ts +44 -0
  471. package/src/agent/observational-memory/observer.ts +128 -0
  472. package/src/agent/observational-memory/plugin.ts +35 -0
  473. package/src/agent/observational-memory/prompts.ts +53 -0
  474. package/src/agent/observational-memory/read.ts +131 -0
  475. package/src/agent/observational-memory/reflector.ts +119 -0
  476. package/src/agent/observational-memory/schema.ts +48 -0
  477. package/src/agent/observational-memory/store.ts +275 -0
  478. package/src/agent/observational-memory/types.ts +65 -0
  479. package/src/agent/processors.ts +209 -0
  480. package/src/agent/production-agent.ts +8254 -0
  481. package/src/agent/run-loop-with-resume.ts +394 -0
  482. package/src/agent/run-manager.ts +1825 -0
  483. package/src/agent/run-ownership.ts +75 -0
  484. package/src/agent/run-store.ts +2601 -0
  485. package/src/agent/runtime-context.ts +169 -0
  486. package/src/agent/thread-data-builder.ts +1584 -0
  487. package/src/agent/tool-call-journal.ts +368 -0
  488. package/src/agent/tool-error-redaction.ts +52 -0
  489. package/src/agent/tool-result-images.ts +178 -0
  490. package/src/agent/tool-search.ts +376 -0
  491. package/src/agent/types.ts +372 -0
  492. package/src/agent-native/index.ts +198 -0
  493. package/src/agent-web/config.ts +253 -0
  494. package/src/agent-web/generator.ts +382 -0
  495. package/src/agent-web/index.ts +36 -0
  496. package/src/appearance/actions/change-appearance.ts +35 -0
  497. package/src/application-state/emitter.ts +81 -0
  498. package/src/application-state/handlers.ts +121 -0
  499. package/src/application-state/index.ts +44 -0
  500. package/src/application-state/script-helpers.ts +155 -0
  501. package/src/application-state/store.ts +274 -0
  502. package/src/assets/branding/agent-native.icon/Assets/background.svg +3 -0
  503. package/src/assets/branding/agent-native.icon/Assets/foreground.svg +12 -0
  504. package/src/assets/branding/agent-native.icon/icon.json +49 -0
  505. package/src/assets/branding/favicon.png +0 -0
  506. package/src/assets/branding/favicon.svg +1 -0
  507. package/src/assets/branding/icon-on-dark.svg +10 -0
  508. package/src/assets/branding/icon-on-light.svg +10 -0
  509. package/src/assets/branding/mac-app-icon.svg +1 -0
  510. package/src/assets/branding/slack-bot/agent-native-1024.png +0 -0
  511. package/src/assets/branding/slack-bot/agent-native-512.png +0 -0
  512. package/src/assets/branding/tray-icon.svg +6 -0
  513. package/src/assets/branding/wordmark-on-dark.svg +21 -0
  514. package/src/assets/branding/wordmark-on-light.svg +21 -0
  515. package/src/assets/fonts/LICENSE_LIBERATION +96 -0
  516. package/src/assets/fonts/LICENSE_NOTO_NASKH_ARABIC +93 -0
  517. package/src/assets/fonts/LiberationSans-Bold.ttf +0 -0
  518. package/src/assets/fonts/LiberationSans-Regular.ttf +0 -0
  519. package/src/assets/fonts/NotoNaskhArabic-Variable.ttf +0 -0
  520. package/src/audit/actions/export-audit-events.ts +162 -0
  521. package/src/audit/actions/get-audit-event.ts +24 -0
  522. package/src/audit/actions/list-audit-events.ts +66 -0
  523. package/src/audit/cleanup-job.ts +100 -0
  524. package/src/audit/config.ts +90 -0
  525. package/src/audit/index.ts +43 -0
  526. package/src/audit/record.ts +180 -0
  527. package/src/audit/redact.ts +109 -0
  528. package/src/audit/store.ts +346 -0
  529. package/src/audit/types.ts +141 -0
  530. package/src/automation/index.ts +802 -0
  531. package/src/brand-kit/brand-signals.ts +124 -0
  532. package/src/brand-kit/fig/index.ts +64 -0
  533. package/src/brand-kit/index.ts +72 -0
  534. package/src/brand-kit/types.ts +113 -0
  535. package/src/browser-sessions/actions.ts +302 -0
  536. package/src/browser-sessions/routes.ts +234 -0
  537. package/src/browser-sessions/store.ts +679 -0
  538. package/src/browser-sessions/types.ts +84 -0
  539. package/src/changelog/parse.ts +328 -0
  540. package/src/chat-threads/emitter.ts +22 -0
  541. package/src/chat-threads/schema.ts +43 -0
  542. package/src/chat-threads/store.ts +1311 -0
  543. package/src/checkpoints/index.ts +15 -0
  544. package/src/checkpoints/service.ts +142 -0
  545. package/src/checkpoints/store.ts +153 -0
  546. package/src/cli/add.ts +425 -0
  547. package/src/cli/agent.ts +424 -0
  548. package/src/cli/agents.ts +122 -0
  549. package/src/cli/app-skill.ts +1455 -0
  550. package/src/cli/atomic-json-file.ts +324 -0
  551. package/src/cli/audit-agent-web.ts +324 -0
  552. package/src/cli/changelog.ts +199 -0
  553. package/src/cli/claude-code-participant.ts +515 -0
  554. package/src/cli/code-agent-commands.ts +270 -0
  555. package/src/cli/code-agent-connector.ts +1109 -0
  556. package/src/cli/code-agent-executor.ts +1970 -0
  557. package/src/cli/code-agent-output-smoother.ts +140 -0
  558. package/src/cli/code-agent-runs.concurrent-worker.ts +33 -0
  559. package/src/cli/code-agent-runs.ts +548 -0
  560. package/src/cli/code.ts +1805 -0
  561. package/src/cli/codex-cli-participant.ts +496 -0
  562. package/src/cli/connect.ts +2714 -0
  563. package/src/cli/content-local.ts +442 -0
  564. package/src/cli/context-xray-local.ts +2193 -0
  565. package/src/cli/create-workspace.ts +30 -0
  566. package/src/cli/create.ts +2247 -0
  567. package/src/cli/deploy-build.ts +50 -0
  568. package/src/cli/design-connect.ts +3187 -0
  569. package/src/cli/doctor.ts +472 -0
  570. package/src/cli/eject.ts +1594 -0
  571. package/src/cli/eval.ts +134 -0
  572. package/src/cli/gateway-helpers.ts +70 -0
  573. package/src/cli/index.ts +1217 -0
  574. package/src/cli/info.ts +105 -0
  575. package/src/cli/invoke.ts +288 -0
  576. package/src/cli/mcp-config-writers.ts +857 -0
  577. package/src/cli/mcp.ts +594 -0
  578. package/src/cli/migrate.ts +1813 -0
  579. package/src/cli/migration-codemod.ts +646 -0
  580. package/src/cli/multi-frontier-runs.ts +1952 -0
  581. package/src/cli/package-lifecycle.ts +823 -0
  582. package/src/cli/plan-blocks.ts +143 -0
  583. package/src/cli/plan-local.ts +3189 -0
  584. package/src/cli/plan-publish-store.ts +138 -0
  585. package/src/cli/pr-visual-recap-workflow.ts +2 -0
  586. package/src/cli/recap.ts +5 -0
  587. package/src/cli/setup-agents.ts +120 -0
  588. package/src/cli/skills-content/assets-skill.ts +83 -0
  589. package/src/cli/skills-content/canvas.ts +153 -0
  590. package/src/cli/skills-content/connection.ts +52 -0
  591. package/src/cli/skills-content/content-skill.ts +120 -0
  592. package/src/cli/skills-content/design-exploration-skill.ts +118 -0
  593. package/src/cli/skills-content/design-visual-edit-skill.ts +228 -0
  594. package/src/cli/skills-content/document-quality.ts +196 -0
  595. package/src/cli/skills-content/exemplar.ts +69 -0
  596. package/src/cli/skills-content/help.ts +77 -0
  597. package/src/cli/skills-content/index.ts +22 -0
  598. package/src/cli/skills-content/local-files.ts +100 -0
  599. package/src/cli/skills-content/plan-setup-auth.ts +80 -0
  600. package/src/cli/skills-content/visual-plan-skill.ts +493 -0
  601. package/src/cli/skills-content/visual-recap-skill.ts +553 -0
  602. package/src/cli/skills-content/visualize-repo-skill.ts +93 -0
  603. package/src/cli/skills-content/wireframe.ts +349 -0
  604. package/src/cli/skills.ts +4340 -0
  605. package/src/cli/sync-builder-starter-manifest.ts +631 -0
  606. package/src/cli/telemetry.ts +136 -0
  607. package/src/cli/templates-meta.ts +269 -0
  608. package/src/cli/upgrade.ts +956 -0
  609. package/src/cli/visualize-repo.ts +715 -0
  610. package/src/cli/workspace-dev.ts +1486 -0
  611. package/src/cli/workspacify.ts +258 -0
  612. package/src/client/AgentAskPopover.tsx +89 -0
  613. package/src/client/AgentChatHome.tsx +66 -0
  614. package/src/client/AgentNative.tsx +161 -0
  615. package/src/client/AgentNativeEmbedded.tsx +288 -0
  616. package/src/client/AgentNativeFrame.tsx +151 -0
  617. package/src/client/AgentPanel.tsx +3437 -0
  618. package/src/client/AgentTaskCard.tsx +273 -0
  619. package/src/client/AppearancePicker.tsx +79 -0
  620. package/src/client/AssistantChat.tsx +5793 -0
  621. package/src/client/ClientOnly.tsx +22 -0
  622. package/src/client/CommandMenu.tsx +726 -0
  623. package/src/client/ConnectBuilderCard.tsx +390 -0
  624. package/src/client/DefaultSpinner.tsx +47 -0
  625. package/src/client/ErrorBoundary.tsx +359 -0
  626. package/src/client/ErrorReportActions.tsx +69 -0
  627. package/src/client/FeedbackButton.tsx +553 -0
  628. package/src/client/HighlightedCodeBlock.tsx +173 -0
  629. package/src/client/IframeEmbed.tsx +151 -0
  630. package/src/client/KeepTabOpenNotice.tsx +181 -0
  631. package/src/client/MultiTabAssistantChat.tsx +2576 -0
  632. package/src/client/NewWorkspaceAppFlow.tsx +525 -0
  633. package/src/client/PoweredByBadge.tsx +284 -0
  634. package/src/client/RunStuckBanner.tsx +431 -0
  635. package/src/client/StarfieldBackground.tsx +466 -0
  636. package/src/client/Turnstile.tsx +125 -0
  637. package/src/client/active-run-state.ts +139 -0
  638. package/src/client/agent-chat/index.ts +279 -0
  639. package/src/client/agent-chat-adapter.ts +3692 -0
  640. package/src/client/agent-chat.ts +1233 -0
  641. package/src/client/agent-engine-key.ts +122 -0
  642. package/src/client/agent-page/AgentContextTab.tsx +487 -0
  643. package/src/client/agent-page/AgentEmptyState.tsx +44 -0
  644. package/src/client/agent-page/AgentJobsTab.tsx +441 -0
  645. package/src/client/agent-page/AgentTabFrame.tsx +39 -0
  646. package/src/client/agent-page/AgentTabsPage.tsx +1096 -0
  647. package/src/client/agent-page/types.ts +18 -0
  648. package/src/client/agent-page/use-jobs.ts +150 -0
  649. package/src/client/agent-sidebar-state.ts +166 -0
  650. package/src/client/analytics/index.ts +40 -0
  651. package/src/client/analytics-session.ts +70 -0
  652. package/src/client/analytics.ts +1757 -0
  653. package/src/client/api-path.ts +124 -0
  654. package/src/client/app-providers.tsx +230 -0
  655. package/src/client/appearance.ts +130 -0
  656. package/src/client/application-state.ts +154 -0
  657. package/src/client/assistant-ui-recovery.tsx +205 -0
  658. package/src/client/automation/index.ts +4 -0
  659. package/src/client/automation.ts +22 -0
  660. package/src/client/blocks/AiEditableField.tsx +30 -0
  661. package/src/client/blocks/BlockView.tsx +145 -0
  662. package/src/client/blocks/RegistryBlockDataProvider.tsx +121 -0
  663. package/src/client/blocks/SchemaBlockEditor.tsx +457 -0
  664. package/src/client/blocks/agent.ts +95 -0
  665. package/src/client/blocks/code-block-direction.ts +21 -0
  666. package/src/client/blocks/index.ts +308 -0
  667. package/src/client/blocks/library/AnnotatedCodeBlock.tsx +710 -0
  668. package/src/client/blocks/library/ApiEndpointBlock.tsx +1120 -0
  669. package/src/client/blocks/library/DataModelBlock.tsx +775 -0
  670. package/src/client/blocks/library/DiffBlock.tsx +1854 -0
  671. package/src/client/blocks/library/FileTreeBlock.tsx +868 -0
  672. package/src/client/blocks/library/HighlightedCode.tsx +260 -0
  673. package/src/client/blocks/library/JsonExplorerBlock.tsx +608 -0
  674. package/src/client/blocks/library/MermaidBlock.tsx +362 -0
  675. package/src/client/blocks/library/OpenApiSpecBlock.tsx +998 -0
  676. package/src/client/blocks/library/annotated-code.config.ts +101 -0
  677. package/src/client/blocks/library/annotation-rail.tsx +1020 -0
  678. package/src/client/blocks/library/api-endpoint.config.ts +207 -0
  679. package/src/client/blocks/library/block-copy.ts +399 -0
  680. package/src/client/blocks/library/callout.config.ts +57 -0
  681. package/src/client/blocks/library/callout.tsx +149 -0
  682. package/src/client/blocks/library/checklist.config.ts +56 -0
  683. package/src/client/blocks/library/checklist.tsx +208 -0
  684. package/src/client/blocks/library/code-filename-label.tsx +59 -0
  685. package/src/client/blocks/library/code-highlight.tsx +178 -0
  686. package/src/client/blocks/library/code-tabs.config.ts +70 -0
  687. package/src/client/blocks/library/code-tabs.tsx +606 -0
  688. package/src/client/blocks/library/code.config.ts +69 -0
  689. package/src/client/blocks/library/code.tsx +440 -0
  690. package/src/client/blocks/library/columns.config.ts +85 -0
  691. package/src/client/blocks/library/columns.tsx +334 -0
  692. package/src/client/blocks/library/data-model.config.ts +152 -0
  693. package/src/client/blocks/library/dev-doc-ui.tsx +191 -0
  694. package/src/client/blocks/library/diagram.config.ts +222 -0
  695. package/src/client/blocks/library/diagram.tsx +958 -0
  696. package/src/client/blocks/library/diff.config.ts +115 -0
  697. package/src/client/blocks/library/file-tree.config.ts +92 -0
  698. package/src/client/blocks/library/html.config.ts +79 -0
  699. package/src/client/blocks/library/html.tsx +258 -0
  700. package/src/client/blocks/library/json-explorer.config.ts +74 -0
  701. package/src/client/blocks/library/mermaid.config.ts +49 -0
  702. package/src/client/blocks/library/narrow-container.tsx +37 -0
  703. package/src/client/blocks/library/openapi-spec.config.ts +66 -0
  704. package/src/client/blocks/library/question-form.config.ts +127 -0
  705. package/src/client/blocks/library/question-form.tsx +944 -0
  706. package/src/client/blocks/library/sanitize-html.ts +343 -0
  707. package/src/client/blocks/library/server-specs.ts +338 -0
  708. package/src/client/blocks/library/specs.tsx +308 -0
  709. package/src/client/blocks/library/table.config.ts +61 -0
  710. package/src/client/blocks/library/table.tsx +449 -0
  711. package/src/client/blocks/library/tabs.config.ts +96 -0
  712. package/src/client/blocks/library/tabs.tsx +665 -0
  713. package/src/client/blocks/library/wireframe-icons.ts +210 -0
  714. package/src/client/blocks/library/wireframe-kit.tsx +1850 -0
  715. package/src/client/blocks/library/wireframe.config.ts +539 -0
  716. package/src/client/blocks/library/wireframe.tsx +535 -0
  717. package/src/client/blocks/mdx.ts +364 -0
  718. package/src/client/blocks/provider.tsx +51 -0
  719. package/src/client/blocks/registry.ts +83 -0
  720. package/src/client/blocks/schema-form/introspect.ts +201 -0
  721. package/src/client/blocks/server.ts +170 -0
  722. package/src/client/blocks/types.ts +415 -0
  723. package/src/client/browser-session-bridge.ts +548 -0
  724. package/src/client/browser-tab-id.ts +36 -0
  725. package/src/client/build-compatibility.ts +77 -0
  726. package/src/client/builder-frame.ts +194 -0
  727. package/src/client/builder-mark.tsx +21 -0
  728. package/src/client/changelog/Changelog.tsx +333 -0
  729. package/src/client/changelog/index.ts +1 -0
  730. package/src/client/chat/ChatHistoryList.tsx +7 -0
  731. package/src/client/chat/attachment-adapters.ts +426 -0
  732. package/src/client/chat/connectors.ts +1579 -0
  733. package/src/client/chat/index.ts +160 -0
  734. package/src/client/chat/markdown-renderer.tsx +693 -0
  735. package/src/client/chat/message-components.tsx +1326 -0
  736. package/src/client/chat/repo-helpers.ts +281 -0
  737. package/src/client/chat/run-recovery.tsx +994 -0
  738. package/src/client/chat/runtime.ts +1810 -0
  739. package/src/client/chat/tool-call-display.tsx +1270 -0
  740. package/src/client/chat/tool-render-registry.tsx +144 -0
  741. package/src/client/chat/use-agent-chat-lifecycle-tracking.ts +74 -0
  742. package/src/client/chat/use-reconnect-reader-owner.ts +28 -0
  743. package/src/client/chat/widgets/DataChartRenderer.tsx +242 -0
  744. package/src/client/chat/widgets/DataChartWidget.tsx +51 -0
  745. package/src/client/chat/widgets/DataInsightsWidget.tsx +59 -0
  746. package/src/client/chat/widgets/DataTableWidget.tsx +240 -0
  747. package/src/client/chat/widgets/InlineExtensionWidget.tsx +60 -0
  748. package/src/client/chat/widgets/builtin-tool-renderers.tsx +213 -0
  749. package/src/client/chat/widgets/data-widget-types.ts +1 -0
  750. package/src/client/chat/widgets/inline-extension-result.ts +86 -0
  751. package/src/client/chat-model-groups.ts +171 -0
  752. package/src/client/chat-thread-url.ts +11 -0
  753. package/src/client/chat-view-transition.ts +213 -0
  754. package/src/client/client-action.ts +21 -0
  755. package/src/client/client-bootstrap.ts +7 -0
  756. package/src/client/client-surface.ts +41 -0
  757. package/src/client/clipboard.ts +89 -0
  758. package/src/client/code-agent-chat-adapter.ts +537 -0
  759. package/src/client/collab/index.ts +60 -0
  760. package/src/client/command-navigation/index.ts +15 -0
  761. package/src/client/comments-review/index.ts +1 -0
  762. package/src/client/components/AgentPresenceChip.tsx +4 -0
  763. package/src/client/components/ApiKeySettings.tsx +309 -0
  764. package/src/client/components/CodeAgentIndicator.tsx +59 -0
  765. package/src/client/components/CodeRequiredDialog.tsx +470 -0
  766. package/src/client/components/LiveCursorOverlay.tsx +5 -0
  767. package/src/client/components/MissingKeyCard.tsx +61 -0
  768. package/src/client/components/PresenceBar.tsx +4 -0
  769. package/src/client/components/RecentEditHighlights.tsx +4 -0
  770. package/src/client/components/RemoteSelectionRings.tsx +5 -0
  771. package/src/client/components/icons/AgentNativeIcon.tsx +46 -0
  772. package/src/client/components/ui/dialog.tsx +1 -0
  773. package/src/client/components/ui/dropdown-menu.tsx +1 -0
  774. package/src/client/components/ui/hover-card.tsx +1 -0
  775. package/src/client/components/ui/message-scroller.tsx +131 -0
  776. package/src/client/components/ui/popover.tsx +1 -0
  777. package/src/client/components/ui/sheet.tsx +1 -0
  778. package/src/client/components/ui/tooltip.tsx +1 -0
  779. package/src/client/composer/index.ts +11 -0
  780. package/src/client/composer/runtime-adapters.tsx +123 -0
  781. package/src/client/composer/use-mention-search.ts +7 -0
  782. package/src/client/composer/wired-components.tsx +53 -0
  783. package/src/client/context-xray/ContextMeter.tsx +124 -0
  784. package/src/client/context-xray/ContextSegmentRow.tsx +27 -0
  785. package/src/client/context-xray/ContextTreemap.tsx +24 -0
  786. package/src/client/context-xray/ContextXRayPanel.tsx +59 -0
  787. package/src/client/context-xray/SegmentProvenancePopover.tsx +18 -0
  788. package/src/client/context-xray/format.ts +27 -0
  789. package/src/client/conversation/AgentConversation.tsx +555 -0
  790. package/src/client/conversation/code-agent-transcript.ts +283 -0
  791. package/src/client/conversation/index.ts +22 -0
  792. package/src/client/conversation/types.ts +85 -0
  793. package/src/client/conversation/use-near-bottom-autoscroll.ts +278 -0
  794. package/src/client/create-query-client.ts +86 -0
  795. package/src/client/db-admin/DataGrid.tsx +551 -0
  796. package/src/client/db-admin/DbAdminPage.tsx +218 -0
  797. package/src/client/db-admin/DevDatabaseLink.tsx +16 -0
  798. package/src/client/db-admin/EditableCell.tsx +451 -0
  799. package/src/client/db-admin/FilterBar.tsx +203 -0
  800. package/src/client/db-admin/ResultsGrid.tsx +114 -0
  801. package/src/client/db-admin/RowSidePanel.tsx +337 -0
  802. package/src/client/db-admin/SqlEditor.tsx +840 -0
  803. package/src/client/db-admin/TableBrowser.tsx +212 -0
  804. package/src/client/db-admin/TableEditor.tsx +760 -0
  805. package/src/client/db-admin/cell-format.ts +246 -0
  806. package/src/client/db-admin/changeset.ts +296 -0
  807. package/src/client/db-admin/export-utils.ts +78 -0
  808. package/src/client/db-admin/index.ts +33 -0
  809. package/src/client/db-admin/sql-storage.ts +134 -0
  810. package/src/client/db-admin/storage.ts +68 -0
  811. package/src/client/db-admin/useAgentSync.ts +226 -0
  812. package/src/client/db-admin/useDbAdmin.ts +294 -0
  813. package/src/client/dev-overlay/DevOverlay.tsx +576 -0
  814. package/src/client/dev-overlay/builtins.ts +40 -0
  815. package/src/client/dev-overlay/index.ts +23 -0
  816. package/src/client/dev-overlay/registry.ts +67 -0
  817. package/src/client/dev-overlay/types.ts +64 -0
  818. package/src/client/dev-overlay/use-dev-option.ts +78 -0
  819. package/src/client/dev-overlay/use-dev-overlay-shortcut.ts +31 -0
  820. package/src/client/dynamic-suggestions.ts +455 -0
  821. package/src/client/embed-auth.ts +544 -0
  822. package/src/client/embed.ts +54 -0
  823. package/src/client/error-capture.ts +690 -0
  824. package/src/client/error-format.ts +211 -0
  825. package/src/client/error-reporting.ts +100 -0
  826. package/src/client/extensions/AgentNativeExtensionFrame.e2e-host.tsx +136 -0
  827. package/src/client/extensions/AgentNativeExtensionFrame.tsx +708 -0
  828. package/src/client/extensions/EmbeddedExtension.tsx +604 -0
  829. package/src/client/extensions/ExtensionEditor.tsx +450 -0
  830. package/src/client/extensions/ExtensionQueryErrorState.tsx +47 -0
  831. package/src/client/extensions/ExtensionSlot.tsx +345 -0
  832. package/src/client/extensions/ExtensionViewer.tsx +1502 -0
  833. package/src/client/extensions/ExtensionViewerPage.tsx +32 -0
  834. package/src/client/extensions/ExtensionsListPage.tsx +432 -0
  835. package/src/client/extensions/ExtensionsSidebarSection.tsx +1259 -0
  836. package/src/client/extensions/InlineExtensionFrame.tsx +660 -0
  837. package/src/client/extensions/agent-native-extension-runtime.ts +495 -0
  838. package/src/client/extensions/delete-extension.ts +76 -0
  839. package/src/client/extensions/extension-load-error.ts +26 -0
  840. package/src/client/extensions/extension-order.ts +49 -0
  841. package/src/client/extensions/extension-popularity.ts +61 -0
  842. package/src/client/extensions/iframe-bridge.ts +377 -0
  843. package/src/client/extensions/index.ts +84 -0
  844. package/src/client/extensions/portable-extension.ts +712 -0
  845. package/src/client/feature-flags/FeatureFlagsPanel.tsx +519 -0
  846. package/src/client/feature-flags/helpers.ts +77 -0
  847. package/src/client/feature-flags/index.ts +13 -0
  848. package/src/client/feature-flags/types.ts +29 -0
  849. package/src/client/feature-flags/use-feature-flag.ts +26 -0
  850. package/src/client/feedback-context.ts +90 -0
  851. package/src/client/frame-protocol.ts +168 -0
  852. package/src/client/frame.ts +329 -0
  853. package/src/client/guided-questions.tsx +1152 -0
  854. package/src/client/history/VersionHistoryPanel.tsx +175 -0
  855. package/src/client/history/index.ts +21 -0
  856. package/src/client/history/use-history.ts +114 -0
  857. package/src/client/hooks/index.ts +46 -0
  858. package/src/client/host/index.ts +170 -0
  859. package/src/client/host-bridge.ts +1272 -0
  860. package/src/client/host-tools.ts +190 -0
  861. package/src/client/i18n.tsx +798 -0
  862. package/src/client/index.ts +370 -0
  863. package/src/client/integrations/IntegrationCard.tsx +186 -0
  864. package/src/client/integrations/IntegrationsPanel.tsx +633 -0
  865. package/src/client/integrations/api.ts +295 -0
  866. package/src/client/integrations/index.ts +29 -0
  867. package/src/client/integrations/useIntegrationStatus.ts +52 -0
  868. package/src/client/mcp-app-host.ts +720 -0
  869. package/src/client/mcp-apps/McpAppRenderer.tsx +760 -0
  870. package/src/client/navigation/index.ts +54 -0
  871. package/src/client/notifications/NotificationsBell.tsx +383 -0
  872. package/src/client/notifications/index.ts +1 -0
  873. package/src/client/observability/ObservabilityDashboard.tsx +890 -0
  874. package/src/client/observability/ThumbsFeedback.tsx +160 -0
  875. package/src/client/observability/index.ts +20 -0
  876. package/src/client/observability/useObservability.ts +266 -0
  877. package/src/client/onboarding/OnboardingBanner.tsx +73 -0
  878. package/src/client/onboarding/OnboardingPanel.tsx +1036 -0
  879. package/src/client/onboarding/SetupButton.tsx +64 -0
  880. package/src/client/onboarding/index.ts +25 -0
  881. package/src/client/onboarding/use-onboarding.ts +164 -0
  882. package/src/client/onboarding/use-preview-mode.ts +40 -0
  883. package/src/client/org/InvitationBanner.tsx +148 -0
  884. package/src/client/org/OrgSwitcher.tsx +754 -0
  885. package/src/client/org/RequireActiveOrg.tsx +337 -0
  886. package/src/client/org/TeamPage.tsx +1432 -0
  887. package/src/client/org/hooks.ts +359 -0
  888. package/src/client/org/index.ts +70 -0
  889. package/src/client/org/workspace-app-links.ts +367 -0
  890. package/src/client/org-team/index.ts +1 -0
  891. package/src/client/progress/RunsTray.tsx +680 -0
  892. package/src/client/progress/index.ts +1 -0
  893. package/src/client/require-session.tsx +142 -0
  894. package/src/client/resources/BuiltinCapabilityDetail.tsx +258 -0
  895. package/src/client/resources/McpConnectionSuggestion.tsx +276 -0
  896. package/src/client/resources/McpIntegrationDialog.tsx +808 -0
  897. package/src/client/resources/McpServerDetail.tsx +230 -0
  898. package/src/client/resources/ResourceEditor.tsx +872 -0
  899. package/src/client/resources/ResourceTree.tsx +860 -0
  900. package/src/client/resources/ResourcesPanel.tsx +1960 -0
  901. package/src/client/resources/index.ts +25 -0
  902. package/src/client/resources/mcp-integration-catalog.ts +771 -0
  903. package/src/client/resources/mcp-integration-logos.ts +108 -0
  904. package/src/client/resources/runtime.ts +1 -0
  905. package/src/client/resources/use-builtin-capabilities.ts +113 -0
  906. package/src/client/resources/use-mcp-servers.ts +217 -0
  907. package/src/client/resources/use-resources.ts +402 -0
  908. package/src/client/review/ReviewCommentComposer.tsx +123 -0
  909. package/src/client/review/ReviewStatusBadge.tsx +39 -0
  910. package/src/client/review/ReviewThreadPanel.tsx +625 -0
  911. package/src/client/review/index.ts +38 -0
  912. package/src/client/review/use-review.ts +186 -0
  913. package/src/client/route-chunk-recovery/index.ts +2 -0
  914. package/src/client/route-chunk-recovery.ts +331 -0
  915. package/src/client/route-state.ts +455 -0
  916. package/src/client/route-warmup.tsx +543 -0
  917. package/src/client/session-replay-iframe.e2e-host.tsx +100 -0
  918. package/src/client/session-replay.ts +3417 -0
  919. package/src/client/settings/AgentsSection.tsx +441 -0
  920. package/src/client/settings/AutomationsSection.tsx +516 -0
  921. package/src/client/settings/BackgroundAgentSection.tsx +189 -0
  922. package/src/client/settings/BrowserSection.tsx +110 -0
  923. package/src/client/settings/DemoModeSection.tsx +48 -0
  924. package/src/client/settings/SecretsSection.tsx +875 -0
  925. package/src/client/settings/SettingsPanel.tsx +3162 -0
  926. package/src/client/settings/SettingsSection.tsx +283 -0
  927. package/src/client/settings/SettingsTabsPage.tsx +592 -0
  928. package/src/client/settings/UsageSection.tsx +401 -0
  929. package/src/client/settings/VoiceTranscriptionSection.tsx +960 -0
  930. package/src/client/settings/agent-settings-search.ts +220 -0
  931. package/src/client/settings/index.ts +27 -0
  932. package/src/client/settings/useBuilderStatus.ts +1055 -0
  933. package/src/client/setup-connections/BuilderConnectCard.tsx +89 -0
  934. package/src/client/setup-connections/ProviderReadinessBadge.tsx +73 -0
  935. package/src/client/setup-connections/SetupConnectionsPage.tsx +94 -0
  936. package/src/client/setup-connections/catalog.ts +6 -0
  937. package/src/client/setup-connections/index.ts +47 -0
  938. package/src/client/setup-connections/runtime.ts +1 -0
  939. package/src/client/sharing/ShareButton.tsx +1748 -0
  940. package/src/client/sharing/ShareDialog.tsx +846 -0
  941. package/src/client/sharing/VisibilityBadge.tsx +4 -0
  942. package/src/client/sharing/index.ts +2 -0
  943. package/src/client/sse-event-processor.ts +2002 -0
  944. package/src/client/terminal/AgentTerminal.tsx +488 -0
  945. package/src/client/terminal/index.ts +7 -0
  946. package/src/client/theme.ts +27 -0
  947. package/src/client/tombstone/agent-presence-chip.ts +17 -0
  948. package/src/client/tombstone/editor.ts +265 -0
  949. package/src/client/tombstone/live-cursor-overlay.ts +21 -0
  950. package/src/client/tombstone/presence-bar.ts +17 -0
  951. package/src/client/tombstone/recent-edit-highlights.ts +17 -0
  952. package/src/client/tombstone/remote-selection-rings.ts +21 -0
  953. package/src/client/tombstone/rich-markdown-editor.ts +265 -0
  954. package/src/client/tombstone/ui-dialog.ts +49 -0
  955. package/src/client/tombstone/ui-dropdown-menu.ts +69 -0
  956. package/src/client/tombstone/ui-hover-card.ts +21 -0
  957. package/src/client/tombstone/ui-popover.ts +25 -0
  958. package/src/client/tombstone/ui-sheet.ts +49 -0
  959. package/src/client/tombstone/ui-tooltip.ts +29 -0
  960. package/src/client/tombstone/visual-style-controls.ts +61 -0
  961. package/src/client/tool-cells/BashCell.tsx +164 -0
  962. package/src/client/tool-cells/EditCell.tsx +303 -0
  963. package/src/client/tool-cells/FilesChangedSummary.tsx +208 -0
  964. package/src/client/tool-cells/WriteCell.tsx +145 -0
  965. package/src/client/tool-cells/index.ts +7 -0
  966. package/src/client/tool-display.ts +41 -0
  967. package/src/client/track.ts +57 -0
  968. package/src/client/transcription/BuilderTranscriptionCta.tsx +120 -0
  969. package/src/client/transcription/use-live-transcription.ts +292 -0
  970. package/src/client/ui/index.ts +55 -0
  971. package/src/client/uploads/index.ts +6 -0
  972. package/src/client/uploads/upload-editor-image.ts +79 -0
  973. package/src/client/uploads/use-upload-resource.ts +24 -0
  974. package/src/client/url-scrub.ts +51 -0
  975. package/src/client/use-action.ts +797 -0
  976. package/src/client/use-agent-chat-context.ts +63 -0
  977. package/src/client/use-agent-chat-home-handoff.ts +207 -0
  978. package/src/client/use-agent-chat.ts +53 -0
  979. package/src/client/use-agent-engine-configured.ts +211 -0
  980. package/src/client/use-avatar.ts +127 -0
  981. package/src/client/use-change-version.ts +150 -0
  982. package/src/client/use-chat-models.ts +252 -0
  983. package/src/client/use-chat-threads.ts +1262 -0
  984. package/src/client/use-db-sync.ts +1112 -0
  985. package/src/client/use-demo-mode-status.ts +30 -0
  986. package/src/client/use-dev-mode.ts +177 -0
  987. package/src/client/use-external-value.ts +40 -0
  988. package/src/client/use-pausing-interval.ts +65 -0
  989. package/src/client/use-pinch-zoom.ts +202 -0
  990. package/src/client/use-run-stuck-detection.ts +427 -0
  991. package/src/client/use-send-to-agent-chat.ts +85 -0
  992. package/src/client/use-session.ts +114 -0
  993. package/src/client/utils.ts +7 -0
  994. package/src/client/visual-style-controls.tsx +1 -0
  995. package/src/client/vite-dev-recovery-script.ts +226 -0
  996. package/src/client/voice-provider-status.ts +44 -0
  997. package/src/client/widgets/index.ts +41 -0
  998. package/src/code-agents/background-controller.ts +398 -0
  999. package/src/code-agents/background-run.ts +156 -0
  1000. package/src/code-agents/index.ts +95 -0
  1001. package/src/code-agents/prompt-attachments.ts +39 -0
  1002. package/src/code-agents/transcript-normalizer.ts +750 -0
  1003. package/src/code-agents/transcript-order.ts +73 -0
  1004. package/src/coding-tools/index.ts +742 -0
  1005. package/src/coding-tools/run-code.ts +1662 -0
  1006. package/src/coding-tools/sandbox/adapter.ts +82 -0
  1007. package/src/coding-tools/sandbox/background.ts +406 -0
  1008. package/src/coding-tools/sandbox/executions-store.ts +517 -0
  1009. package/src/coding-tools/sandbox/index.ts +132 -0
  1010. package/src/coding-tools/sandbox/local-child-process-adapter.ts +217 -0
  1011. package/src/collab/agent-identity.ts +5 -0
  1012. package/src/collab/agent-presence.ts +341 -0
  1013. package/src/collab/awareness-store.ts +196 -0
  1014. package/src/collab/awareness.ts +317 -0
  1015. package/src/collab/client-struct.ts +366 -0
  1016. package/src/collab/client.ts +1205 -0
  1017. package/src/collab/emitter.ts +31 -0
  1018. package/src/collab/follow-mode.ts +107 -0
  1019. package/src/collab/index.ts +151 -0
  1020. package/src/collab/json-to-yjs.ts +504 -0
  1021. package/src/collab/presence.ts +207 -0
  1022. package/src/collab/recent-edits.ts +215 -0
  1023. package/src/collab/routes.ts +191 -0
  1024. package/src/collab/storage.ts +228 -0
  1025. package/src/collab/struct-routes.ts +133 -0
  1026. package/src/collab/text-to-yjs.ts +79 -0
  1027. package/src/collab/undo.ts +432 -0
  1028. package/src/collab/xml-ops.ts +68 -0
  1029. package/src/collab/ydoc-manager.ts +544 -0
  1030. package/src/command-navigation/actions.ts +100 -0
  1031. package/src/command-navigation/index.ts +12 -0
  1032. package/src/comments-review/index.ts +1 -0
  1033. package/src/connections/catalog.ts +451 -0
  1034. package/src/connections/index.ts +48 -0
  1035. package/src/connections/reader.ts +911 -0
  1036. package/src/connections/runtime.ts +1 -0
  1037. package/src/credentials/index.ts +187 -0
  1038. package/src/data-programs/actions.ts +335 -0
  1039. package/src/data-programs/contract.ts +284 -0
  1040. package/src/data-programs/execute.ts +693 -0
  1041. package/src/data-programs/index.ts +72 -0
  1042. package/src/data-programs/schema.ts +148 -0
  1043. package/src/data-programs/store.ts +755 -0
  1044. package/src/data-widgets/index.ts +376 -0
  1045. package/src/db/client.ts +1627 -0
  1046. package/src/db/create-get-db.ts +579 -0
  1047. package/src/db/ddl-guard.ts +302 -0
  1048. package/src/db/drizzle-config.ts +190 -0
  1049. package/src/db/ensure-additive-columns.ts +430 -0
  1050. package/src/db/index.ts +57 -0
  1051. package/src/db/migrations.ts +691 -0
  1052. package/src/db/request-telemetry.ts +154 -0
  1053. package/src/db/runtime-diagnostics.ts +331 -0
  1054. package/src/db/schema.ts +121 -0
  1055. package/src/db/widen-columns.ts +75 -0
  1056. package/src/db-admin/agent-tools.ts +202 -0
  1057. package/src/db-admin/index.ts +26 -0
  1058. package/src/db-admin/operations.ts +803 -0
  1059. package/src/db-admin/routes.ts +174 -0
  1060. package/src/db-admin/types.ts +110 -0
  1061. package/src/demo/browser-state.ts +47 -0
  1062. package/src/demo/fetch-interceptor.ts +175 -0
  1063. package/src/demo/redact.ts +575 -0
  1064. package/src/deploy/build.ts +3938 -0
  1065. package/src/deploy/immutable-assets.ts +65 -0
  1066. package/src/deploy/route-discovery.ts +458 -0
  1067. package/src/deploy/workspace-core.ts +282 -0
  1068. package/src/deploy/workspace-deploy.ts +1488 -0
  1069. package/src/eject/provider-api-definitions.ts +193 -0
  1070. package/src/eject/remote-mcp-presets.ts +137 -0
  1071. package/src/eject/setup-readiness-ui.tsx +29 -0
  1072. package/src/eject/workspace-connections.ts +92 -0
  1073. package/src/embedding/agent.ts +159 -0
  1074. package/src/embedding/bridge.ts +297 -0
  1075. package/src/embedding/index.ts +43 -0
  1076. package/src/embedding/protocol.ts +185 -0
  1077. package/src/embedding/react.tsx +319 -0
  1078. package/src/embeddings/index.ts +233 -0
  1079. package/src/eval/agent-runner.ts +210 -0
  1080. package/src/eval/define-eval.ts +55 -0
  1081. package/src/eval/index.ts +49 -0
  1082. package/src/eval/report.ts +75 -0
  1083. package/src/eval/runner.ts +369 -0
  1084. package/src/eval/scorer.ts +244 -0
  1085. package/src/eval/types.ts +188 -0
  1086. package/src/event-bus/bus.ts +140 -0
  1087. package/src/event-bus/index.ts +3 -0
  1088. package/src/event-bus/registry.ts +79 -0
  1089. package/src/event-bus/types.ts +29 -0
  1090. package/src/extensions/actions.ts +1636 -0
  1091. package/src/extensions/change-marker.ts +54 -0
  1092. package/src/extensions/content-patch.ts +468 -0
  1093. package/src/extensions/fetch-tool.ts +461 -0
  1094. package/src/extensions/html-shell.ts +803 -0
  1095. package/src/extensions/local.ts +462 -0
  1096. package/src/extensions/path.ts +40 -0
  1097. package/src/extensions/proxy-security.ts +171 -0
  1098. package/src/extensions/routes.ts +1080 -0
  1099. package/src/extensions/schema.ts +269 -0
  1100. package/src/extensions/session-replay-iframe.ts +131 -0
  1101. package/src/extensions/slots/routes.ts +126 -0
  1102. package/src/extensions/slots/schema.ts +87 -0
  1103. package/src/extensions/slots/store.ts +450 -0
  1104. package/src/extensions/store.ts +1347 -0
  1105. package/src/extensions/theme.ts +114 -0
  1106. package/src/extensions/url-safety.ts +316 -0
  1107. package/src/extensions/web-content.ts +663 -0
  1108. package/src/extensions/web-search-tool.ts +437 -0
  1109. package/src/feature-flags/a2a-action-route.ts +56 -0
  1110. package/src/feature-flags/actions/get-feature-flags.ts +24 -0
  1111. package/src/feature-flags/actions/list-feature-flags.ts +69 -0
  1112. package/src/feature-flags/actions/set-feature-flag.ts +89 -0
  1113. package/src/feature-flags/index.ts +21 -0
  1114. package/src/feature-flags/permissions.ts +53 -0
  1115. package/src/feature-flags/plugin.ts +44 -0
  1116. package/src/feature-flags/registry.ts +96 -0
  1117. package/src/feature-flags/store.ts +176 -0
  1118. package/src/file-upload/actions/upload-image.ts +213 -0
  1119. package/src/file-upload/builder.ts +431 -0
  1120. package/src/file-upload/index.ts +24 -0
  1121. package/src/file-upload/pre-upload-attachments.ts +305 -0
  1122. package/src/file-upload/registry.ts +125 -0
  1123. package/src/file-upload/types.ts +89 -0
  1124. package/src/guards/db-tool-scoping.ts +129 -0
  1125. package/src/guards/index.ts +23 -0
  1126. package/src/guards/no-drizzle-push.ts +116 -0
  1127. package/src/guards/no-env-credentials.ts +229 -0
  1128. package/src/guards/no-env-mutation.ts +114 -0
  1129. package/src/guards/no-localhost-fallback.ts +124 -0
  1130. package/src/guards/no-unscoped-credentials.ts +227 -0
  1131. package/src/guards/no-unscoped-queries.ts +834 -0
  1132. package/src/guards/scan-utils.ts +105 -0
  1133. package/src/guards/types.ts +30 -0
  1134. package/src/history/actions/create-resource-version.ts +92 -0
  1135. package/src/history/actions/get-resource-version.ts +60 -0
  1136. package/src/history/actions/list-resource-history.ts +53 -0
  1137. package/src/history/actions/list-resource-versions.ts +43 -0
  1138. package/src/history/actions/restore-resource-version.ts +96 -0
  1139. package/src/history/index.ts +26 -0
  1140. package/src/history/registry.ts +111 -0
  1141. package/src/history/store.ts +379 -0
  1142. package/src/history/types.ts +69 -0
  1143. package/src/index.browser.ts +155 -0
  1144. package/src/index.ts +408 -0
  1145. package/src/ingestion/docx.ts +158 -0
  1146. package/src/ingestion/figma-node-to-html.ts +1860 -0
  1147. package/src/ingestion/figma.ts +548 -0
  1148. package/src/ingestion/index.ts +107 -0
  1149. package/src/ingestion/media.ts +264 -0
  1150. package/src/ingestion/notion.ts +121 -0
  1151. package/src/ingestion/office.ts +213 -0
  1152. package/src/ingestion/orchestration.ts +160 -0
  1153. package/src/ingestion/pptx.ts +331 -0
  1154. package/src/ingestion/selection.ts +81 -0
  1155. package/src/ingestion/website.ts +151 -0
  1156. package/src/integrations/a2a-continuation-marker.ts +2 -0
  1157. package/src/integrations/a2a-continuation-processor.ts +888 -0
  1158. package/src/integrations/a2a-continuations-store.ts +643 -0
  1159. package/src/integrations/adapter-overrides.ts +12 -0
  1160. package/src/integrations/adapters/discord.ts +364 -0
  1161. package/src/integrations/adapters/email.ts +1164 -0
  1162. package/src/integrations/adapters/google-docs.ts +371 -0
  1163. package/src/integrations/adapters/index.ts +29 -0
  1164. package/src/integrations/adapters/microsoft-teams.ts +413 -0
  1165. package/src/integrations/adapters/slack.ts +1914 -0
  1166. package/src/integrations/adapters/telegram.ts +386 -0
  1167. package/src/integrations/adapters/whatsapp.ts +358 -0
  1168. package/src/integrations/awaiting-input-store.ts +130 -0
  1169. package/src/integrations/catalog.ts +571 -0
  1170. package/src/integrations/computer-supervision-store.ts +423 -0
  1171. package/src/integrations/computer-supervision.ts +213 -0
  1172. package/src/integrations/config-store.ts +131 -0
  1173. package/src/integrations/controls-store.ts +187 -0
  1174. package/src/integrations/eject/messaging-adapters.ts +85 -0
  1175. package/src/integrations/google-docs-poller.ts +671 -0
  1176. package/src/integrations/identity-links-store.ts +210 -0
  1177. package/src/integrations/identity.ts +196 -0
  1178. package/src/integrations/index.ts +220 -0
  1179. package/src/integrations/installations-store.ts +677 -0
  1180. package/src/integrations/integration-memory.ts +187 -0
  1181. package/src/integrations/internal-token.ts +106 -0
  1182. package/src/integrations/pending-tasks-retry-job.ts +286 -0
  1183. package/src/integrations/pending-tasks-store.ts +468 -0
  1184. package/src/integrations/plugin.ts +3048 -0
  1185. package/src/integrations/remote-commands-store.ts +690 -0
  1186. package/src/integrations/remote-devices-store.ts +492 -0
  1187. package/src/integrations/remote-json-safety.ts +127 -0
  1188. package/src/integrations/remote-push-delivery-job.ts +48 -0
  1189. package/src/integrations/remote-push-delivery.ts +370 -0
  1190. package/src/integrations/remote-push-store.ts +664 -0
  1191. package/src/integrations/remote-retry-job.ts +55 -0
  1192. package/src/integrations/remote-run-events-store.ts +222 -0
  1193. package/src/integrations/remote-types.ts +186 -0
  1194. package/src/integrations/runtime.ts +1 -0
  1195. package/src/integrations/scope-store.ts +498 -0
  1196. package/src/integrations/slack-manifest.ts +78 -0
  1197. package/src/integrations/slack-oauth.ts +344 -0
  1198. package/src/integrations/task-queue-stats.ts +144 -0
  1199. package/src/integrations/thread-mapping-store.ts +134 -0
  1200. package/src/integrations/types.ts +485 -0
  1201. package/src/integrations/usage-budget-store.ts +906 -0
  1202. package/src/integrations/webhook-delivery.ts +55 -0
  1203. package/src/integrations/webhook-handler.ts +1939 -0
  1204. package/src/jobs/actions/list-recurring-jobs.ts +105 -0
  1205. package/src/jobs/actions/manage-recurring-job.ts +85 -0
  1206. package/src/jobs/cron.ts +126 -0
  1207. package/src/jobs/index.ts +9 -0
  1208. package/src/jobs/scheduler.ts +703 -0
  1209. package/src/jobs/tools.ts +367 -0
  1210. package/src/local-artifacts/index.ts +1372 -0
  1211. package/src/localization/actions/get-localization-preference.ts +24 -0
  1212. package/src/localization/actions/set-localization-preference.ts +32 -0
  1213. package/src/localization/default-messages.ts +1009 -0
  1214. package/src/localization/index.ts +2 -0
  1215. package/src/localization/server.ts +131 -0
  1216. package/src/localization/shared.ts +208 -0
  1217. package/src/mcp/actions/call-mcp-tool.ts +19 -0
  1218. package/src/mcp/actions/create-org-service-token.ts +87 -0
  1219. package/src/mcp/actions/list-mcp-tools.ts +18 -0
  1220. package/src/mcp/actions/list-org-service-tokens.ts +44 -0
  1221. package/src/mcp/actions/revoke-org-service-token.ts +30 -0
  1222. package/src/mcp/actions/service-token-access.ts +121 -0
  1223. package/src/mcp/ask-app-inline-tasks.ts +125 -0
  1224. package/src/mcp/build-server.ts +2356 -0
  1225. package/src/mcp/builtin-tools.ts +1506 -0
  1226. package/src/mcp/connect-route.ts +1460 -0
  1227. package/src/mcp/connect-store.ts +680 -0
  1228. package/src/mcp/embed-app.ts +2051 -0
  1229. package/src/mcp/embed-route.ts +84 -0
  1230. package/src/mcp/external-agent-policy.ts +18 -0
  1231. package/src/mcp/index.ts +47 -0
  1232. package/src/mcp/oauth-route.ts +1016 -0
  1233. package/src/mcp/oauth-store.ts +581 -0
  1234. package/src/mcp/oauth-token.ts +227 -0
  1235. package/src/mcp/org-directory.ts +343 -0
  1236. package/src/mcp/route-paths.ts +34 -0
  1237. package/src/mcp/screen-memory-stdio.ts +290 -0
  1238. package/src/mcp/server.ts +507 -0
  1239. package/src/mcp/stdio.ts +328 -0
  1240. package/src/mcp/workspace-resolve.ts +261 -0
  1241. package/src/mcp-client/app-api.ts +136 -0
  1242. package/src/mcp-client/app-result.ts +64 -0
  1243. package/src/mcp-client/builtin-capabilities.ts +146 -0
  1244. package/src/mcp-client/builtin-store.ts +93 -0
  1245. package/src/mcp-client/config.ts +281 -0
  1246. package/src/mcp-client/errors.ts +54 -0
  1247. package/src/mcp-client/hub-client.ts +172 -0
  1248. package/src/mcp-client/hub-routes.ts +198 -0
  1249. package/src/mcp-client/index.ts +504 -0
  1250. package/src/mcp-client/manager.ts +968 -0
  1251. package/src/mcp-client/oauth-client.ts +462 -0
  1252. package/src/mcp-client/oauth-routes.ts +307 -0
  1253. package/src/mcp-client/remote-store.ts +674 -0
  1254. package/src/mcp-client/remote-url.ts +97 -0
  1255. package/src/mcp-client/routes.ts +1093 -0
  1256. package/src/mcp-client/screen-memory-local.ts +461 -0
  1257. package/src/mcp-client/tool-policy.ts +182 -0
  1258. package/src/mcp-client/visibility.ts +56 -0
  1259. package/src/mcp-client/workspace-servers.ts +379 -0
  1260. package/src/navigation/index.ts +170 -0
  1261. package/src/notifications/actions.ts +151 -0
  1262. package/src/notifications/channels.ts +410 -0
  1263. package/src/notifications/index.ts +22 -0
  1264. package/src/notifications/registry.ts +216 -0
  1265. package/src/notifications/routes.ts +106 -0
  1266. package/src/notifications/store.ts +236 -0
  1267. package/src/notifications/types.ts +52 -0
  1268. package/src/oauth-tokens/google-refresh.ts +175 -0
  1269. package/src/oauth-tokens/index.ts +15 -0
  1270. package/src/oauth-tokens/store.ts +384 -0
  1271. package/src/observability/cleanup-job.ts +124 -0
  1272. package/src/observability/evals.ts +507 -0
  1273. package/src/observability/experiments.ts +359 -0
  1274. package/src/observability/feedback.ts +332 -0
  1275. package/src/observability/hosted-model-experiment.ts +118 -0
  1276. package/src/observability/index.ts +62 -0
  1277. package/src/observability/plugin.ts +31 -0
  1278. package/src/observability/routes.ts +431 -0
  1279. package/src/observability/sentiment.ts +261 -0
  1280. package/src/observability/store.ts +1347 -0
  1281. package/src/observability/traces.ts +789 -0
  1282. package/src/observability/tracing.ts +157 -0
  1283. package/src/observability/tracking-identity.ts +55 -0
  1284. package/src/observability/types.ts +211 -0
  1285. package/src/onboarding/default-steps.ts +428 -0
  1286. package/src/onboarding/index.ts +22 -0
  1287. package/src/onboarding/plugin.ts +262 -0
  1288. package/src/onboarding/registry.ts +47 -0
  1289. package/src/onboarding/types.ts +96 -0
  1290. package/src/org/accept-pending.ts +98 -0
  1291. package/src/org/auto-join-domain.ts +113 -0
  1292. package/src/org/context.ts +640 -0
  1293. package/src/org/free-email-providers.ts +124 -0
  1294. package/src/org/handlers.ts +1153 -0
  1295. package/src/org/index.ts +63 -0
  1296. package/src/org/migrations.ts +105 -0
  1297. package/src/org/permissions.ts +30 -0
  1298. package/src/org/plugin.ts +255 -0
  1299. package/src/org/schema.ts +28 -0
  1300. package/src/org/types.ts +57 -0
  1301. package/src/org-team/index.ts +1 -0
  1302. package/src/package-lifecycle/deprecated-imports.ts +179 -0
  1303. package/src/package-lifecycle/eject-manifest.ts +345 -0
  1304. package/src/package-lifecycle/index.ts +7 -0
  1305. package/src/package-lifecycle/manifest.ts +120 -0
  1306. package/src/package-lifecycle/migration-manifest.ts +159 -0
  1307. package/src/package-lifecycle/migration-message.ts +6 -0
  1308. package/src/package-lifecycle/tombstone.ts +58 -0
  1309. package/src/package-lifecycle/upgrade-error.ts +37 -0
  1310. package/src/private-blob/index.ts +18 -0
  1311. package/src/private-blob/registry.ts +242 -0
  1312. package/src/private-blob/types.ts +55 -0
  1313. package/src/progress/actions.ts +179 -0
  1314. package/src/progress/index.ts +16 -0
  1315. package/src/progress/registry.ts +127 -0
  1316. package/src/progress/routes.ts +89 -0
  1317. package/src/progress/store.ts +353 -0
  1318. package/src/progress/types.ts +59 -0
  1319. package/src/provider-api/actions/custom-provider-registration.ts +197 -0
  1320. package/src/provider-api/actions/delete-staged-dataset.ts +5 -0
  1321. package/src/provider-api/actions/github-repo-files.ts +266 -0
  1322. package/src/provider-api/actions/list-staged-datasets.ts +5 -0
  1323. package/src/provider-api/actions/provider-api-audit.ts +88 -0
  1324. package/src/provider-api/actions/provider-api.ts +460 -0
  1325. package/src/provider-api/actions/query-staged-dataset.ts +5 -0
  1326. package/src/provider-api/actions/staged-datasets.ts +359 -0
  1327. package/src/provider-api/corpus-jobs-store.ts +522 -0
  1328. package/src/provider-api/corpus-jobs.ts +1817 -0
  1329. package/src/provider-api/custom-registry.ts +456 -0
  1330. package/src/provider-api/github-repo.ts +675 -0
  1331. package/src/provider-api/gong.ts +108 -0
  1332. package/src/provider-api/index.ts +5444 -0
  1333. package/src/provider-api/quota-governor.ts +562 -0
  1334. package/src/provider-api/runtime.ts +1 -0
  1335. package/src/provider-api/staged-datasets-aggregate.ts +304 -0
  1336. package/src/provider-api/staged-datasets-store.ts +441 -0
  1337. package/src/provider-api/staging.ts +483 -0
  1338. package/src/resources/agents.ts +65 -0
  1339. package/src/resources/emitter.ts +54 -0
  1340. package/src/resources/handlers.ts +728 -0
  1341. package/src/resources/index.ts +4 -0
  1342. package/src/resources/metadata.ts +252 -0
  1343. package/src/resources/script-helpers.ts +160 -0
  1344. package/src/resources/store.ts +1618 -0
  1345. package/src/review/actions/consume-review-feedback.ts +48 -0
  1346. package/src/review/actions/create-review-comment.ts +108 -0
  1347. package/src/review/actions/delete-review-comment.ts +67 -0
  1348. package/src/review/actions/get-review-feedback.ts +49 -0
  1349. package/src/review/actions/list-review-comments.ts +87 -0
  1350. package/src/review/actions/reply-review-comment.ts +118 -0
  1351. package/src/review/actions/resolve-review-thread.ts +94 -0
  1352. package/src/review/actions/send-review-thread-to-agent.ts +62 -0
  1353. package/src/review/actions/set-review-status.ts +58 -0
  1354. package/src/review/identity.ts +101 -0
  1355. package/src/review/index.ts +45 -0
  1356. package/src/review/mentions.ts +44 -0
  1357. package/src/review/registry.ts +111 -0
  1358. package/src/review/store.ts +997 -0
  1359. package/src/review/types.ts +101 -0
  1360. package/src/router/index.ts +24 -0
  1361. package/src/scripts/agent-engines/list-agent-engines.ts +130 -0
  1362. package/src/scripts/agent-engines/manage-agent-engine.ts +197 -0
  1363. package/src/scripts/agent-engines/set-agent-engine.ts +84 -0
  1364. package/src/scripts/agent-engines/test-agent-engine.ts +174 -0
  1365. package/src/scripts/call-agent.ts +792 -0
  1366. package/src/scripts/chat/index.ts +8 -0
  1367. package/src/scripts/chat/open-chat.ts +56 -0
  1368. package/src/scripts/chat/search-chats.ts +121 -0
  1369. package/src/scripts/core-scripts.ts +22 -0
  1370. package/src/scripts/db/check-scoping.ts +212 -0
  1371. package/src/scripts/db/exec.ts +791 -0
  1372. package/src/scripts/db/index.ts +19 -0
  1373. package/src/scripts/db/migrate-encrypt-credentials.ts +223 -0
  1374. package/src/scripts/db/migrate-encrypt-oauth-tokens.ts +213 -0
  1375. package/src/scripts/db/migrate-user-api-keys.ts +257 -0
  1376. package/src/scripts/db/patch.ts +820 -0
  1377. package/src/scripts/db/query.ts +299 -0
  1378. package/src/scripts/db/reset-dev-owner.ts +285 -0
  1379. package/src/scripts/db/safety.ts +286 -0
  1380. package/src/scripts/db/schema.ts +364 -0
  1381. package/src/scripts/db/scoping.ts +341 -0
  1382. package/src/scripts/db/sqlite-client.ts +78 -0
  1383. package/src/scripts/db/tool-mode.ts +23 -0
  1384. package/src/scripts/db/tool-schemas.ts +31 -0
  1385. package/src/scripts/db/wipe-leaked-builder-keys.ts +201 -0
  1386. package/src/scripts/dev/index.ts +296 -0
  1387. package/src/scripts/dev/list-files.ts +119 -0
  1388. package/src/scripts/dev/read-file.ts +77 -0
  1389. package/src/scripts/dev/search-files.ts +151 -0
  1390. package/src/scripts/dev/shell.ts +111 -0
  1391. package/src/scripts/dev/write-file.ts +56 -0
  1392. package/src/scripts/dev-session.ts +96 -0
  1393. package/src/scripts/docs/index.ts +8 -0
  1394. package/src/scripts/docs/search.ts +274 -0
  1395. package/src/scripts/docs/source-search.ts +363 -0
  1396. package/src/scripts/index.ts +15 -0
  1397. package/src/scripts/manage-agent-loop-settings.ts +84 -0
  1398. package/src/scripts/parse-args.ts +46 -0
  1399. package/src/scripts/resources/delete-memory.ts +67 -0
  1400. package/src/scripts/resources/delete.ts +69 -0
  1401. package/src/scripts/resources/effective.ts +71 -0
  1402. package/src/scripts/resources/index.ts +18 -0
  1403. package/src/scripts/resources/list.ts +103 -0
  1404. package/src/scripts/resources/migrate-learnings.ts +40 -0
  1405. package/src/scripts/resources/read.ts +107 -0
  1406. package/src/scripts/resources/save-memory.ts +99 -0
  1407. package/src/scripts/resources/write.ts +158 -0
  1408. package/src/scripts/runner.ts +339 -0
  1409. package/src/scripts/utils.ts +130 -0
  1410. package/src/search/index.ts +413 -0
  1411. package/src/search-utils/index.ts +112 -0
  1412. package/src/secrets/crypto.ts +228 -0
  1413. package/src/secrets/index.ts +65 -0
  1414. package/src/secrets/onboarding.ts +101 -0
  1415. package/src/secrets/register-framework-secrets.ts +228 -0
  1416. package/src/secrets/register.ts +129 -0
  1417. package/src/secrets/routes.ts +697 -0
  1418. package/src/secrets/schema.ts +52 -0
  1419. package/src/secrets/storage.ts +561 -0
  1420. package/src/secrets/substitution.ts +305 -0
  1421. package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +150 -0
  1422. package/src/server/action-change.ts +66 -0
  1423. package/src/server/action-discovery.ts +774 -0
  1424. package/src/server/action-routes.ts +658 -0
  1425. package/src/server/agent-access.ts +72 -0
  1426. package/src/server/agent-chat/action-filters-a2a.ts +339 -0
  1427. package/src/server/agent-chat/browser-team-tools.ts +510 -0
  1428. package/src/server/agent-chat/context-tools.ts +599 -0
  1429. package/src/server/agent-chat/framework-prompts.ts +467 -0
  1430. package/src/server/agent-chat/lazy-fs.ts +11 -0
  1431. package/src/server/agent-chat/mcp-glue.ts +91 -0
  1432. package/src/server/agent-chat/plugin-options.ts +379 -0
  1433. package/src/server/agent-chat/process-run-failure.ts +62 -0
  1434. package/src/server/agent-chat/prompt-resources.ts +1004 -0
  1435. package/src/server/agent-chat/recurring-jobs-runtime.ts +80 -0
  1436. package/src/server/agent-chat/request-surface.ts +71 -0
  1437. package/src/server/agent-chat/run-code-tools.ts +67 -0
  1438. package/src/server/agent-chat/script-entries.ts +796 -0
  1439. package/src/server/agent-chat/shared-thread.ts +301 -0
  1440. package/src/server/agent-chat/skill-frontmatter.ts +41 -0
  1441. package/src/server/agent-chat-plugin.ts +5930 -0
  1442. package/src/server/agent-discovery.ts +706 -0
  1443. package/src/server/agent-engine-api-key-route.ts +236 -0
  1444. package/src/server/agent-run-context.ts +204 -0
  1445. package/src/server/agent-teams-run-queue.ts +344 -0
  1446. package/src/server/agent-teams.ts +2257 -0
  1447. package/src/server/agents-bundle.ts +464 -0
  1448. package/src/server/analytics.ts +105 -0
  1449. package/src/server/app-base-path.ts +79 -0
  1450. package/src/server/app-name.ts +53 -0
  1451. package/src/server/app-url.ts +184 -0
  1452. package/src/server/attachment-actions.ts +276 -0
  1453. package/src/server/attribution.ts +214 -0
  1454. package/src/server/auth-marketing.ts +260 -0
  1455. package/src/server/auth-plugin.ts +32 -0
  1456. package/src/server/auth.ts +3803 -0
  1457. package/src/server/better-auth-instance.ts +1201 -0
  1458. package/src/server/builder-browser.ts +1701 -0
  1459. package/src/server/builder-design-systems.ts +668 -0
  1460. package/src/server/builder-space.ts +176 -0
  1461. package/src/server/captcha.ts +63 -0
  1462. package/src/server/capture-error.ts +64 -0
  1463. package/src/server/cli-capture.ts +141 -0
  1464. package/src/server/collab-plugin.ts +391 -0
  1465. package/src/server/complete-text.ts +231 -0
  1466. package/src/server/cookie-namespace.ts +159 -0
  1467. package/src/server/core-routes-plugin.ts +4122 -0
  1468. package/src/server/cors-origins.ts +60 -0
  1469. package/src/server/create-server.ts +268 -0
  1470. package/src/server/credential-provider.ts +1202 -0
  1471. package/src/server/csrf.ts +229 -0
  1472. package/src/server/date-utils.ts +42 -0
  1473. package/src/server/deep-link.ts +119 -0
  1474. package/src/server/derived-secret.ts +32 -0
  1475. package/src/server/design-token-utils.ts +1032 -0
  1476. package/src/server/desktop-sso.ts +83 -0
  1477. package/src/server/edge.ts +69 -0
  1478. package/src/server/email-actions.ts +218 -0
  1479. package/src/server/email-template.ts +192 -0
  1480. package/src/server/email-templates.ts +148 -0
  1481. package/src/server/email.ts +219 -0
  1482. package/src/server/embed-route.ts +283 -0
  1483. package/src/server/embed-session.ts +805 -0
  1484. package/src/server/embedded.ts +252 -0
  1485. package/src/server/entry-server.tsx +154 -0
  1486. package/src/server/framework-request-handler.ts +848 -0
  1487. package/src/server/fusion-app.ts +447 -0
  1488. package/src/server/google-auth-mode.ts +34 -0
  1489. package/src/server/google-auth-plugin.ts +496 -0
  1490. package/src/server/google-oauth-credentials.ts +128 -0
  1491. package/src/server/google-oauth.ts +972 -0
  1492. package/src/server/google-realtime-session.ts +182 -0
  1493. package/src/server/h3-helpers.ts +174 -0
  1494. package/src/server/http-response-telemetry.ts +396 -0
  1495. package/src/server/identity-sso-store.ts +304 -0
  1496. package/src/server/identity-sso.ts +514 -0
  1497. package/src/server/index.ts +593 -0
  1498. package/src/server/missing-key.ts +36 -0
  1499. package/src/server/oauth-helpers.ts +44 -0
  1500. package/src/server/oauth-public-origin.ts +44 -0
  1501. package/src/server/oauth-return-url.ts +120 -0
  1502. package/src/server/og-fonts-data.ts +15 -0
  1503. package/src/server/og-fonts.ts +75 -0
  1504. package/src/server/onboarding-html.ts +4040 -0
  1505. package/src/server/open-route.ts +311 -0
  1506. package/src/server/org-admin.ts +28 -0
  1507. package/src/server/poll-events.ts +88 -0
  1508. package/src/server/poll.ts +1224 -0
  1509. package/src/server/prompts/framework-core-compact.ts +107 -0
  1510. package/src/server/prompts/framework-core.ts +143 -0
  1511. package/src/server/prompts/index.ts +16 -0
  1512. package/src/server/prompts/model-overlays.ts +54 -0
  1513. package/src/server/prompts/shared-rules.ts +104 -0
  1514. package/src/server/realtime-voice.ts +967 -0
  1515. package/src/server/recap-image-route.ts +242 -0
  1516. package/src/server/recap-image-store.ts +185 -0
  1517. package/src/server/request-context.ts +416 -0
  1518. package/src/server/request-origin.ts +67 -0
  1519. package/src/server/resources-plugin.ts +119 -0
  1520. package/src/server/schema-prompt.ts +429 -0
  1521. package/src/server/scoped-key-storage.ts +223 -0
  1522. package/src/server/security-headers.ts +170 -0
  1523. package/src/server/self-dispatch.ts +224 -0
  1524. package/src/server/sentry-config.ts +73 -0
  1525. package/src/server/sentry-plugin.ts +138 -0
  1526. package/src/server/sentry.ts +444 -0
  1527. package/src/server/short-lived-token.ts +170 -0
  1528. package/src/server/social-og-image.ts +454 -0
  1529. package/src/server/sse.ts +102 -0
  1530. package/src/server/ssr-handler.ts +466 -0
  1531. package/src/server/transcribe-voice.ts +1076 -0
  1532. package/src/server/voice-providers-status.ts +118 -0
  1533. package/src/server/workspace-oauth.ts +31 -0
  1534. package/src/server/workspace-provider-oauth.ts +970 -0
  1535. package/src/session-replay-iframe-protocol.ts +58 -0
  1536. package/src/settings/handlers.ts +44 -0
  1537. package/src/settings/index.ts +34 -0
  1538. package/src/settings/org-settings.ts +83 -0
  1539. package/src/settings/script-helpers.ts +24 -0
  1540. package/src/settings/store.ts +247 -0
  1541. package/src/settings/user-settings.ts +47 -0
  1542. package/src/setup-connections/index.ts +90 -0
  1543. package/src/setup-connections/onboarding.ts +47 -0
  1544. package/src/shared/agent-access.ts +112 -0
  1545. package/src/shared/agent-chat.ts +124 -0
  1546. package/src/shared/agent-env.ts +46 -0
  1547. package/src/shared/agent-readable-resource.ts +111 -0
  1548. package/src/shared/agent-sidebar-url.ts +39 -0
  1549. package/src/shared/cache-control.ts +25 -0
  1550. package/src/shared/cloudflare-globals.d.ts +34 -0
  1551. package/src/shared/context-xray.ts +172 -0
  1552. package/src/shared/embed-auth.ts +6 -0
  1553. package/src/shared/index.ts +83 -0
  1554. package/src/shared/llm-connection.ts +42 -0
  1555. package/src/shared/markdown-block-split.ts +129 -0
  1556. package/src/shared/mcp-connect-content.ts +130 -0
  1557. package/src/shared/mcp-embed-headers.ts +175 -0
  1558. package/src/shared/mcp-integration-config.ts +101 -0
  1559. package/src/shared/merge-by-id.ts +14 -0
  1560. package/src/shared/oauth-state.ts +39 -0
  1561. package/src/shared/reasoning-effort.ts +228 -0
  1562. package/src/shared/route-warmup-config.ts +128 -0
  1563. package/src/shared/runtime.ts +31 -0
  1564. package/src/shared/social-meta.ts +82 -0
  1565. package/src/shared/streaming-text-smoothing.ts +184 -0
  1566. package/src/shared/truncate.ts +13 -0
  1567. package/src/shared/workspace-app-audience.ts +177 -0
  1568. package/src/shared/workspace-app-id.ts +54 -0
  1569. package/src/sharing/access.ts +585 -0
  1570. package/src/sharing/actions/create-agent-resource-link.ts +91 -0
  1571. package/src/sharing/actions/extension-change.ts +22 -0
  1572. package/src/sharing/actions/list-resource-shares.ts +93 -0
  1573. package/src/sharing/actions/set-resource-visibility.ts +91 -0
  1574. package/src/sharing/actions/share-resource.ts +322 -0
  1575. package/src/sharing/actions/unshare-resource.ts +72 -0
  1576. package/src/sharing/index.ts +35 -0
  1577. package/src/sharing/registry.ts +201 -0
  1578. package/src/sharing/schema.ts +99 -0
  1579. package/src/styles/agent-conversation.css +766 -0
  1580. package/src/styles/agent-native.css +938 -0
  1581. package/src/styles/blocks.css +1717 -0
  1582. package/src/styles/chat-history-list.css +1 -0
  1583. package/src/styles/rich-markdown-editor.css +1 -0
  1584. package/src/tailwind.preset.ts +140 -0
  1585. package/src/templates/chat/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1586. package/src/templates/chat/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1587. package/src/templates/chat/.agents/skills/self-modifying-code/SKILL.md +9 -6
  1588. package/src/templates/chat/AGENTS.md +3 -2
  1589. package/src/templates/default/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1590. package/src/templates/default/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1591. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +9 -6
  1592. package/src/templates/default/AGENTS.md +6 -5
  1593. package/src/templates/headless/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1594. package/src/templates/headless/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1595. package/src/templates/headless/AGENTS.md +5 -4
  1596. package/src/templates/workspace-core/.agents/skills/agent-native-docs/SKILL.md +15 -13
  1597. package/src/templates/workspace-core/.agents/skills/agent-native-toolkit/SKILL.md +3 -2
  1598. package/src/templates/workspace-core/.agents/skills/customizing-agent-native/SKILL.md +63 -20
  1599. package/src/templates/workspace-core/.agents/skills/self-modifying-code/SKILL.md +9 -6
  1600. package/src/templates/workspace-core/AGENTS.md +4 -4
  1601. package/src/templates/workspace-root/AGENTS.md +4 -4
  1602. package/src/terminal/cli-registry.ts +57 -0
  1603. package/src/terminal/index.ts +22 -0
  1604. package/src/terminal/pty-server.ts +389 -0
  1605. package/src/terminal/terminal-plugin.ts +265 -0
  1606. package/src/testing.ts +23 -0
  1607. package/src/tracking/index.ts +10 -0
  1608. package/src/tracking/providers.ts +422 -0
  1609. package/src/tracking/registry.ts +102 -0
  1610. package/src/tracking/route.ts +108 -0
  1611. package/src/tracking/types.ts +16 -0
  1612. package/src/transcription/builder-transcription.ts +118 -0
  1613. package/src/triggers/actions/list-automations.ts +99 -0
  1614. package/src/triggers/actions/manage-automation.ts +78 -0
  1615. package/src/triggers/actions.ts +333 -0
  1616. package/src/triggers/condition-evaluator.ts +163 -0
  1617. package/src/triggers/dispatcher.ts +536 -0
  1618. package/src/triggers/index.ts +13 -0
  1619. package/src/triggers/routes.ts +322 -0
  1620. package/src/triggers/types.ts +42 -0
  1621. package/src/types/pglite.d.ts +26 -0
  1622. package/src/usage/store.ts +698 -0
  1623. package/src/vite/action-types-plugin.ts +481 -0
  1624. package/src/vite/agent-web-plugin.ts +78 -0
  1625. package/src/vite/agents-bundle-plugin.ts +185 -0
  1626. package/src/vite/client.ts +3056 -0
  1627. package/src/vite/index.ts +21 -0
  1628. package/src/voice/index.ts +18 -0
  1629. package/src/voice/voice-cleanup-prompt.ts +38 -0
  1630. package/src/voice/voice-context.ts +217 -0
  1631. package/src/voice/voice-replacements.ts +75 -0
  1632. package/src/workspace-connections/credentials.ts +603 -0
  1633. package/src/workspace-connections/index.ts +72 -0
  1634. package/src/workspace-connections/lifecycle.ts +43 -0
  1635. package/src/workspace-connections/store.ts +1943 -0
  1636. package/src/workspace-files/index.ts +18 -0
  1637. package/src/workspace-files/store.ts +339 -0
  1638. package/src/workspace-files/tool.ts +266 -0
@@ -0,0 +1,1860 @@
1
+ /**
2
+ * Figma node JSON -> HTML mapper.
3
+ *
4
+ * Input is the `document` subtree returned by
5
+ * `GET /v1/files/:fileKey/nodes?ids=...&geometry=paths` (or the file's root
6
+ * `document` node). Output is a self-contained HTML fragment using absolute
7
+ * positioning + inline styles, matching Figma's own canvas model 1:1 rather
8
+ * than reconstructing a semantic/Tailwind layout — the goal is pixel fidelity
9
+ * for an imported snapshot, not idiomatic hand-authored markup.
10
+ *
11
+ * This module is pure and synchronous: it never calls the network. The
12
+ * caller (an action) is responsible for:
13
+ * 1. Fetching the node JSON from the Figma REST API.
14
+ * 2. Calling `collectFallbackNodeIds` / `collectImageFillRefs` to find out
15
+ * which nodes need a rendered PNG fallback and which image fills need
16
+ * resolved URLs.
17
+ * 3. Fetching those via `/v1/images/:fileKey` (fallback renders) and
18
+ * `/v1/files/:fileKey/images` (fill ref -> URL map).
19
+ * 4. Calling `mapFigmaNodeToHtml` with the resulting maps.
20
+ *
21
+ * ## Pixel-perfect property coverage
22
+ *
23
+ * | Property | Fidelity | Notes |
24
+ * | ------------------------------------------- | ------------- | ----- |
25
+ * | Position/size (absoluteBoundingBox) | exact | frame-relative |
26
+ * | Auto-layout (flex*) | exact | Figma auto-layout IS flexbox |
27
+ * | Text font/size/weight/case/decoration/align | exact | |
28
+ * | Line-height (px vs percent-of-font-size) | exact | resolved to px |
29
+ * | Letter-spacing | exact | already px in REST API |
30
+ * | Solid fills | exact | |
31
+ * | Gradient fills (angle/position) | exact (linear)/approximated (radial/angular/diamond) | derived from gradientHandlePositions, not a default angle |
32
+ * | Multiple fills (layering) | exact | reversed to match CSS background-image stacking |
33
+ * | Image fills (scale modes) | exact (FILL/FIT/TILE/STRETCH-axis-aligned) / approximated (skewed imageTransform) | |
34
+ * | Strokes (uniform, align) | exact | CENTER via outline+negative offset, INSIDE via inset box-shadow, OUTSIDE via outline |
35
+ * | Strokes (per-side weights) | approximated | CSS has no per-side outline; falls back to per-side `border` (inside-only) |
36
+ * | Corner radii (uniform + per-corner) | exact | |
37
+ * | Effects: drop/inner shadow | exact | |
38
+ * | Effects: layer/background blur | approximated | Figma <-> CSS blur radius scale is not publicly specified as 1:1 |
39
+ * | Opacity | exact | |
40
+ * | Blend modes (CSS-supported) | exact | |
41
+ * | Blend modes (Figma-only: LINEAR_BURN/DODGE/LIGHTER/DARKER) | approximated | mapped to closest CSS equivalent |
42
+ * | clipsContent | exact | overflow: hidden |
43
+ * | Rotation | approximated | pivots about the bounding-box center (see below) |
44
+ * | Vector networks / boolean ops / unsupported types | image fallback | never approximated structurally |
45
+ *
46
+ * ### Rotation caveat
47
+ * The REST API docs describe `rotation` as being in degrees, but the field
48
+ * is empirically returned in RADIANS (verified against known authored
49
+ * rotations via the Plugin API); this mapper converts it to degrees before
50
+ * use. `absoluteBoundingBox` is the *already-rotated* axis-aligned bounding
51
+ * box —
52
+ * Figma does not expose the pre-rotation box directly. We reconstruct the
53
+ * unrotated box by treating the AABB's center as invariant under rotation
54
+ * (true for a shape rotated about its own center) and rotate the CSS element
55
+ * about `transform-origin: center` by `-rotation` degrees (Figma's rotation
56
+ * is clockwise-negative relative to CSS's clockwise-positive convention).
57
+ * This is exact when Figma pivots rotation about the shape's center and only
58
+ * approximated if Figma's internal pivot differs (rare in practice; visually
59
+ * indistinguishable in the overwhelming majority of designs). A fully exact
60
+ * alternative would consume `relativeTransform` as a CSS `matrix()` directly,
61
+ * which is a documented follow-up if a specific design surfaces a visible
62
+ * mismatch.
63
+ */
64
+
65
+ export interface FigmaColor {
66
+ r: number;
67
+ g: number;
68
+ b: number;
69
+ a?: number;
70
+ }
71
+
72
+ export interface FigmaColorStop {
73
+ position: number;
74
+ color: FigmaColor;
75
+ }
76
+
77
+ export interface FigmaImageFilter {
78
+ exposure?: number;
79
+ contrast?: number;
80
+ saturation?: number;
81
+ temperature?: number;
82
+ tint?: number;
83
+ highlights?: number;
84
+ shadows?: number;
85
+ }
86
+
87
+ export interface FigmaPaint {
88
+ type:
89
+ | "SOLID"
90
+ | "GRADIENT_LINEAR"
91
+ | "GRADIENT_RADIAL"
92
+ | "GRADIENT_ANGULAR"
93
+ | "GRADIENT_DIAMOND"
94
+ | "IMAGE"
95
+ | "EMOJI"
96
+ | "VIDEO";
97
+ visible?: boolean;
98
+ opacity?: number;
99
+ color?: FigmaColor;
100
+ gradientHandlePositions?: Array<{ x: number; y: number }>;
101
+ gradientStops?: FigmaColorStop[];
102
+ imageRef?: string;
103
+ scaleMode?: "FILL" | "FIT" | "TILE" | "STRETCH";
104
+ imageTransform?: [[number, number, number], [number, number, number]];
105
+ filters?: FigmaImageFilter;
106
+ blendMode?: string;
107
+ }
108
+
109
+ export interface FigmaEffect {
110
+ type: "DROP_SHADOW" | "INNER_SHADOW" | "LAYER_BLUR" | "BACKGROUND_BLUR";
111
+ visible?: boolean;
112
+ radius?: number;
113
+ spread?: number;
114
+ color?: FigmaColor;
115
+ offset?: { x: number; y: number };
116
+ blendMode?: string;
117
+ }
118
+
119
+ export interface FigmaTypeStyle {
120
+ fontFamily?: string;
121
+ fontPostScriptName?: string;
122
+ fontWeight?: number;
123
+ fontSize?: number;
124
+ italic?: boolean;
125
+ letterSpacing?: number;
126
+ lineHeightPx?: number;
127
+ lineHeightPercent?: number;
128
+ lineHeightPercentFontSize?: number;
129
+ lineHeightUnit?: "PIXELS" | "FONT_SIZE_%" | "INTRINSIC_%";
130
+ textCase?: "ORIGINAL" | "UPPER" | "LOWER" | "TITLE";
131
+ textDecoration?: "NONE" | "UNDERLINE" | "STRIKETHROUGH";
132
+ textAlignHorizontal?: "LEFT" | "RIGHT" | "CENTER" | "JUSTIFIED";
133
+ textAlignVertical?: "TOP" | "CENTER" | "BOTTOM";
134
+ textAutoResize?: "NONE" | "WIDTH_AND_HEIGHT" | "HEIGHT" | "TRUNCATE";
135
+ paragraphSpacing?: number;
136
+ paragraphIndent?: number;
137
+ listSpacing?: number;
138
+ hangingPunctuation?: boolean;
139
+ hangingList?: boolean;
140
+ opentypeFlags?: Record<string, number>;
141
+ hyperlink?: unknown;
142
+ fills?: FigmaPaint[];
143
+ }
144
+
145
+ export interface FigmaIndividualStrokeWeights {
146
+ top?: number;
147
+ right?: number;
148
+ bottom?: number;
149
+ left?: number;
150
+ }
151
+
152
+ export interface FigmaBoundingBox {
153
+ x: number;
154
+ y: number;
155
+ width: number;
156
+ height: number;
157
+ }
158
+
159
+ export interface FigmaNode {
160
+ id: string;
161
+ name?: string;
162
+ type: string;
163
+ visible?: boolean;
164
+ opacity?: number;
165
+ blendMode?: string;
166
+ rotation?: number;
167
+ absoluteBoundingBox?: FigmaBoundingBox;
168
+ relativeTransform?: [[number, number, number], [number, number, number]];
169
+ /**
170
+ * The node's actual visual extent, INCLUDING stroke/effect overflow --
171
+ * e.g. an OUTSIDE-aligned stroke or a drop shadow makes this larger than
172
+ * `absoluteBoundingBox` (the purely geometric fill bounds). Figma's own
173
+ * `/v1/images` renders for a node are cropped to this box, not to
174
+ * `absoluteBoundingBox` -- sizing an image-fallback `<img>` using the
175
+ * geometric box instead squishes/crops the rendered PNG to the wrong
176
+ * aspect ratio whenever a fallback node has stroke/effect overflow.
177
+ */
178
+ absoluteRenderBounds?: FigmaBoundingBox;
179
+ size?: { x: number; y: number };
180
+ clipsContent?: boolean;
181
+ isMask?: boolean;
182
+ maskType?: "ALPHA" | "VECTOR" | "LUMINANCE";
183
+ arcData?: {
184
+ startingAngle?: number;
185
+ endingAngle?: number;
186
+ innerRadius?: number;
187
+ };
188
+ characters?: string;
189
+ style?: FigmaTypeStyle;
190
+ characterStyleOverrides?: number[];
191
+ styleOverrideTable?: Record<string, FigmaTypeStyle>;
192
+ lineTypes?: string[];
193
+ lineIndentations?: number[];
194
+ fills?: FigmaPaint[];
195
+ strokes?: FigmaPaint[];
196
+ strokeWeight?: number;
197
+ strokeAlign?: "INSIDE" | "OUTSIDE" | "CENTER";
198
+ individualStrokeWeights?: FigmaIndividualStrokeWeights;
199
+ strokeDashes?: number[];
200
+ cornerRadius?: number;
201
+ rectangleCornerRadii?: [number, number, number, number];
202
+ effects?: FigmaEffect[];
203
+ layoutMode?: "NONE" | "HORIZONTAL" | "VERTICAL" | "GRID";
204
+ layoutPositioning?: "AUTO" | "ABSOLUTE";
205
+ primaryAxisAlignItems?: "MIN" | "CENTER" | "MAX" | "SPACE_BETWEEN";
206
+ counterAxisAlignItems?: "MIN" | "CENTER" | "MAX" | "BASELINE";
207
+ layoutSizingHorizontal?: "FIXED" | "HUG" | "FILL";
208
+ layoutSizingVertical?: "FIXED" | "HUG" | "FILL";
209
+ layoutWrap?: "NO_WRAP" | "WRAP";
210
+ itemSpacing?: number;
211
+ counterAxisSpacing?: number;
212
+ paddingLeft?: number;
213
+ paddingRight?: number;
214
+ paddingTop?: number;
215
+ paddingBottom?: number;
216
+ minWidth?: number | null;
217
+ maxWidth?: number | null;
218
+ minHeight?: number | null;
219
+ maxHeight?: number | null;
220
+ componentId?: string;
221
+ componentProperties?: Record<string, unknown>;
222
+ boundVariables?: Record<string, unknown>;
223
+ interactions?: unknown[];
224
+ children?: FigmaNode[];
225
+ }
226
+
227
+ export type FidelityLevel = "exact" | "approximated" | "image-fallback";
228
+
229
+ export interface FidelityEntry {
230
+ nodeId: string;
231
+ nodeName: string;
232
+ nodeType: string;
233
+ level: FidelityLevel;
234
+ notes: string[];
235
+ }
236
+
237
+ export interface FidelityReport {
238
+ entries: FidelityEntry[];
239
+ summary: {
240
+ exact: number;
241
+ approximated: number;
242
+ imageFallback: number;
243
+ };
244
+ }
245
+
246
+ export interface MapFigmaNodeOptions {
247
+ /** imageRef hash -> resolved public URL, from `/v1/files/:key/images`. */
248
+ imageFillUrls?: Record<string, string>;
249
+ /** nodeId -> rendered PNG URL, from `/v1/images/:key` for fallback subtrees. */
250
+ fallbackImageUrls?: Record<string, string>;
251
+ /** Node ids that should be rendered as an image regardless of type. */
252
+ forceImageFallbackNodeIds?: Set<string>;
253
+ }
254
+
255
+ export interface MapFigmaNodeResult {
256
+ html: string;
257
+ fidelity: FidelityReport;
258
+ }
259
+
260
+ const UNSUPPORTED_STRUCTURAL_TYPES = new Set([
261
+ "BOOLEAN_OPERATION",
262
+ "VECTOR",
263
+ "STAR",
264
+ "REGULAR_POLYGON",
265
+ "SLICE",
266
+ "STICKY",
267
+ "SHAPE_WITH_TEXT",
268
+ "CONNECTOR",
269
+ "WASHI_TAPE",
270
+ "TABLE",
271
+ ]);
272
+
273
+ const SUPPORTED_CONTAINER_TYPES = new Set([
274
+ "FRAME",
275
+ "GROUP",
276
+ "COMPONENT",
277
+ "COMPONENT_SET",
278
+ "INSTANCE",
279
+ "SECTION",
280
+ ]);
281
+
282
+ const MAX_FIGMA_NODE_COUNT = 75_000;
283
+ const MAX_FIGMA_NODE_DEPTH = 256;
284
+ const MAX_METADATA_ATTRIBUTE_CHARS = 16_384;
285
+
286
+ // ---------------------------------------------------------------------------
287
+ // Formatting helpers
288
+ // ---------------------------------------------------------------------------
289
+
290
+ function round(value: number, precision = 2): number {
291
+ const factor = 10 ** precision;
292
+ return Math.round(value * factor) / factor;
293
+ }
294
+
295
+ function px(value: number | undefined, precision = 2): string | undefined {
296
+ if (typeof value !== "number" || !Number.isFinite(value)) return undefined;
297
+ return `${round(value, precision)}px`;
298
+ }
299
+
300
+ function colorToCss(
301
+ color: FigmaColor | undefined,
302
+ opacityMul = 1,
303
+ ): string | null {
304
+ if (!color) return null;
305
+ const r = Math.round((color.r ?? 0) * 255);
306
+ const g = Math.round((color.g ?? 0) * 255);
307
+ const b = Math.round((color.b ?? 0) * 255);
308
+ const a = round((color.a ?? 1) * opacityMul, 4);
309
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
310
+ }
311
+
312
+ function escapeHtml(value: string): string {
313
+ return value
314
+ .replace(/&/g, "&amp;")
315
+ .replace(/</g, "&lt;")
316
+ .replace(/>/g, "&gt;")
317
+ .replace(/"/g, "&quot;");
318
+ }
319
+
320
+ function escapeAttr(value: string): string {
321
+ return escapeHtml(value);
322
+ }
323
+
324
+ function metadataAttr(
325
+ name: string,
326
+ value: unknown,
327
+ node: FigmaNode,
328
+ tracker: FidelityTracker,
329
+ ): string {
330
+ if (value === undefined || value === null) return "";
331
+ let serialized: string;
332
+ try {
333
+ serialized = typeof value === "string" ? value : JSON.stringify(value);
334
+ } catch {
335
+ tracker.record(
336
+ node,
337
+ "approximated",
338
+ `${name} metadata could not be serialized and was omitted.`,
339
+ );
340
+ return "";
341
+ }
342
+ if (serialized.length > MAX_METADATA_ATTRIBUTE_CHARS) {
343
+ tracker.record(
344
+ node,
345
+ "approximated",
346
+ `${name} metadata exceeded ${MAX_METADATA_ATTRIBUTE_CHARS} characters and was omitted.`,
347
+ );
348
+ return "";
349
+ }
350
+ return ` ${name}="${escapeAttr(serialized)}"`;
351
+ }
352
+
353
+ /**
354
+ * Builds the CSS text for a `style="..."` attribute AND escapes it for HTML
355
+ * attribute context. This matters because at least one style value we emit
356
+ * legitimately contains a literal double-quote character: font-family values
357
+ * are built as `"Inter", sans-serif` (CSS requires quoting family names with
358
+ * spaces). Without escaping here, that embedded `"` prematurely terminates
359
+ * the enclosing `style="..."` attribute the moment a browser (or any other
360
+ * HTML parser) reads it -- silently dropping every style declared after
361
+ * font-family in object-key order (font-size, font-weight, line-height,
362
+ * text-align, and the text node's own `display: flex` used to emulate
363
+ * vertical alignment). The visible symptom is text rendering at the
364
+ * browser's default font/size instead of the mapped Figma typography, with
365
+ * no error anywhere -- caught here via a real headless-browser render that
366
+ * showed a Figma TEXT node's own style attribute silently truncated at
367
+ * `font-family: "`.
368
+ */
369
+ function styleAttr(styles: Record<string, string | undefined>): string {
370
+ const parts = Object.entries(styles)
371
+ .filter((entry): entry is [string, string] => typeof entry[1] === "string")
372
+ .map(([key, value]) => `${key}: ${value}`);
373
+ return escapeAttr(parts.join("; "));
374
+ }
375
+
376
+ // ---------------------------------------------------------------------------
377
+ // Fidelity report builder
378
+ // ---------------------------------------------------------------------------
379
+
380
+ class FidelityTracker {
381
+ private entries = new Map<string, FidelityEntry>();
382
+
383
+ record(node: FigmaNode, level: FidelityLevel, note: string) {
384
+ const existing = this.entries.get(node.id);
385
+ if (existing) {
386
+ // Never downgrade an image-fallback entry, and never upgrade below the
387
+ // worst level recorded for this node.
388
+ const rank: Record<FidelityLevel, number> = {
389
+ exact: 0,
390
+ approximated: 1,
391
+ "image-fallback": 2,
392
+ };
393
+ if (rank[level] > rank[existing.level]) existing.level = level;
394
+ existing.notes.push(note);
395
+ return;
396
+ }
397
+ this.entries.set(node.id, {
398
+ nodeId: node.id,
399
+ nodeName: node.name ?? node.id,
400
+ nodeType: node.type,
401
+ level,
402
+ notes: [note],
403
+ });
404
+ }
405
+
406
+ build(): FidelityReport {
407
+ const entries = [...this.entries.values()];
408
+ const summary = entries.reduce(
409
+ (acc, entry) => {
410
+ if (entry.level === "exact") acc.exact += 1;
411
+ else if (entry.level === "approximated") acc.approximated += 1;
412
+ else acc.imageFallback += 1;
413
+ return acc;
414
+ },
415
+ { exact: 0, approximated: 0, imageFallback: 0 },
416
+ );
417
+ return { entries, summary };
418
+ }
419
+ }
420
+
421
+ // ---------------------------------------------------------------------------
422
+ // Gradient angle / position derivation
423
+ // ---------------------------------------------------------------------------
424
+
425
+ interface GradientGeometry {
426
+ start: { x: number; y: number };
427
+ end: { x: number; y: number };
428
+ width: { x: number; y: number };
429
+ }
430
+
431
+ function resolveGradientGeometry(paint: FigmaPaint): GradientGeometry | null {
432
+ const handles = paint.gradientHandlePositions;
433
+ if (!handles || handles.length < 3) return null;
434
+ return { start: handles[0]!, end: handles[1]!, width: handles[2]! };
435
+ }
436
+
437
+ /**
438
+ * Derive a CSS `linear-gradient()` angle (degrees) from Figma's normalized
439
+ * `gradientHandlePositions`. Handle positions are normalized independently in
440
+ * x and y (0..1 relative to the node's bounding box), so the angle must be
441
+ * computed in actual pixel space using the node's real width/height —
442
+ * otherwise a non-square box silently distorts the angle.
443
+ *
444
+ * Verified against Figma's documented identity handles
445
+ * (start=(0,0.5), end=(1,0.5), width=(1,0), i.e. a plain left-to-right
446
+ * gradient) which must resolve to CSS `90deg` ("to right"):
447
+ * dx = 1*w, dy = 0 -> atan2(0, dx) = 0deg -> +90 = 90deg. Matches.
448
+ * And a top-to-bottom gradient (start=(0.5,0), end=(0.5,1)) must resolve to
449
+ * CSS `180deg` ("to bottom"):
450
+ * dx = 0, dy = 1*h -> atan2(dy, 0) = 90deg -> +90 = 180deg. Matches.
451
+ */
452
+ export function gradientAngleDegrees(
453
+ paint: FigmaPaint,
454
+ box: { width: number; height: number },
455
+ ): number | null {
456
+ const geometry = resolveGradientGeometry(paint);
457
+ if (!geometry) return null;
458
+ const dx = (geometry.end.x - geometry.start.x) * box.width;
459
+ const dy = (geometry.end.y - geometry.start.y) * box.height;
460
+ const angleRad = Math.atan2(dy, dx);
461
+ const angleDeg = (angleRad * 180) / Math.PI + 90;
462
+ return ((angleDeg % 360) + 360) % 360;
463
+ }
464
+
465
+ function gradientStopsCss(
466
+ paint: FigmaPaint,
467
+ remapPosition?: (position: number) => number,
468
+ ): string {
469
+ const stops = paint.gradientStops ?? [];
470
+ return stops
471
+ .map((stop) => {
472
+ const color = colorToCss(stop.color, paint.opacity ?? 1) ?? "transparent";
473
+ const position = remapPosition
474
+ ? remapPosition(stop.position)
475
+ : stop.position;
476
+ return `${color} ${round(position * 100, 2)}%`;
477
+ })
478
+ .join(", ");
479
+ }
480
+
481
+ /**
482
+ * CSS `linear-gradient(angle, ...)` always stretches its 0%/100% stops
483
+ * across the box's FULL diagonal extent at that angle (the CSS spec's
484
+ * "gradient line" always spans corner-to-corner) -- it has no way to say
485
+ * "start partway in, end partway in" the way Figma's actual gradient handles
486
+ * can (a designer can drag the start/end handles anywhere, including short
487
+ * of the shape's edges, or past them). Figma's own stop positions are
488
+ * fractions of the literal start-handle-to-end-handle distance, which only
489
+ * happens to coincide with the CSS full-box span when the handles are
490
+ * dragged exactly corner-to-corner -- a common case, but far from the only
491
+ * one, and the divergence gets worse the more the box's aspect ratio departs
492
+ * from square (rotated/skewed handles included, e.g. gradientTransform-authored
493
+ * paints). This projects each Figma stop's real pixel position onto the same
494
+ * angle CSS will use and re-expresses it as a percentage of the CSS line's
495
+ * length, so a partial/offset gradient renders at the same actual pixel
496
+ * positions Figma draws it at instead of silently stretching to fill the box.
497
+ */
498
+ function remapLinearStopPosition(
499
+ geometry: GradientGeometry,
500
+ box: { width: number; height: number },
501
+ angleDeg: number,
502
+ ): (position: number) => number {
503
+ const angleRad = (angleDeg * Math.PI) / 180;
504
+ const ux = Math.sin(angleRad);
505
+ const uy = -Math.cos(angleRad);
506
+ const lineLength = box.width * Math.abs(ux) + box.height * Math.abs(uy);
507
+ if (lineLength < 1e-6) return (position) => position;
508
+ const startPx = {
509
+ x: geometry.start.x * box.width,
510
+ y: geometry.start.y * box.height,
511
+ };
512
+ const endPx = {
513
+ x: geometry.end.x * box.width,
514
+ y: geometry.end.y * box.height,
515
+ };
516
+ const centerX = box.width / 2;
517
+ const centerY = box.height / 2;
518
+ return (position: number) => {
519
+ const pointX = startPx.x + position * (endPx.x - startPx.x);
520
+ const pointY = startPx.y + position * (endPx.y - startPx.y);
521
+ const projected = (pointX - centerX) * ux + (pointY - centerY) * uy;
522
+ return (projected + lineLength / 2) / lineLength;
523
+ };
524
+ }
525
+
526
+ function vectorLength(
527
+ from: { x: number; y: number },
528
+ to: { x: number; y: number },
529
+ box: { width: number; height: number },
530
+ ): number {
531
+ const dx = (to.x - from.x) * box.width;
532
+ const dy = (to.y - from.y) * box.height;
533
+ return Math.sqrt(dx * dx + dy * dy);
534
+ }
535
+
536
+ /**
537
+ * Convert one Figma paint layer to a CSS `background-image` value (or plain
538
+ * color for a SOLID paint used standalone). Returns null for paints that
539
+ * cannot be expressed as a background-image (handled elsewhere).
540
+ */
541
+ function paintToCssImage(
542
+ paint: FigmaPaint,
543
+ box: { width: number; height: number },
544
+ tracker: FidelityTracker,
545
+ node: FigmaNode,
546
+ ): string | null {
547
+ if (paint.visible === false) return null;
548
+ const stops = gradientStopsCss(paint);
549
+ if (!stops) return null;
550
+
551
+ switch (paint.type) {
552
+ case "GRADIENT_LINEAR": {
553
+ const angle = gradientAngleDegrees(paint, box);
554
+ const geometry = resolveGradientGeometry(paint);
555
+ // Re-express Figma's handle-relative stop positions as percentages of
556
+ // CSS's own full-box gradient line (see remapLinearStopPosition) so a
557
+ // gradient whose handles don't span exactly corner-to-corner still
558
+ // lands its color transitions at the same real pixel positions Figma
559
+ // draws them at, instead of being stretched to fill the whole box.
560
+ const linearStops =
561
+ angle !== null && geometry
562
+ ? gradientStopsCss(
563
+ paint,
564
+ remapLinearStopPosition(geometry, box, angle),
565
+ )
566
+ : stops;
567
+ tracker.record(
568
+ node,
569
+ "exact",
570
+ "Linear gradient angle and stop offsets derived from gradientHandlePositions.",
571
+ );
572
+ return `linear-gradient(${round(angle ?? 90, 2)}deg, ${linearStops})`;
573
+ }
574
+ case "GRADIENT_RADIAL": {
575
+ const geometry = resolveGradientGeometry(paint);
576
+ if (!geometry) return `radial-gradient(${stops})`;
577
+ const cx = round(geometry.start.x * 100, 2);
578
+ const cy = round(geometry.start.y * 100, 2);
579
+ // Figma's handle[1] ("end") is the radius vector along the gradient's
580
+ // own primary axis; handle[2] ("width") is the perpendicular radius.
581
+ // For an axis-aligned box those map directly to the ellipse's
582
+ // horizontal/vertical radii -- swapping them (as a prior version of
583
+ // this code did) silently rotates the ellipse 90 degrees, which is
584
+ // invisible for a square box but produces a badly wrong bowtie-shaped
585
+ // gradient for any non-square rectangle (the common case).
586
+ const radiusX = vectorLength(geometry.start, geometry.end, box);
587
+ const radiusY = vectorLength(geometry.start, geometry.width, box);
588
+ tracker.record(
589
+ node,
590
+ "approximated",
591
+ "Radial gradient rendered as an axis-aligned ellipse sized from gradientHandlePositions; rotated/skewed radial gradients are not expressible in CSS radial-gradient().",
592
+ );
593
+ return `radial-gradient(ellipse ${round(radiusX, 2)}px ${round(radiusY, 2)}px at ${cx}% ${cy}%, ${stops})`;
594
+ }
595
+ case "GRADIENT_ANGULAR": {
596
+ const geometry = resolveGradientGeometry(paint);
597
+ const cx = geometry ? round(geometry.start.x * 100, 2) : 50;
598
+ const cy = geometry ? round(geometry.start.y * 100, 2) : 50;
599
+ const fromAngle = geometry ? gradientAngleDegrees(paint, box) : 0;
600
+ tracker.record(
601
+ node,
602
+ "approximated",
603
+ "Conic (angular) gradient start angle derived from gradientHandlePositions using the same angle formula as linear gradients; CSS conic-gradient() has no elliptical distortion so non-uniform boxes may render slightly differently than Figma.",
604
+ );
605
+ return `conic-gradient(from ${round(fromAngle ?? 0, 2)}deg at ${cx}% ${cy}%, ${stops})`;
606
+ }
607
+ case "GRADIENT_DIAMOND": {
608
+ const geometry = resolveGradientGeometry(paint);
609
+ const cx = geometry ? round(geometry.start.x * 100, 2) : 50;
610
+ const cy = geometry ? round(geometry.start.y * 100, 2) : 50;
611
+ // Same handle-to-axis mapping fix as GRADIENT_RADIAL above: handle[1]
612
+ // ("end") is the primary-axis radius, handle[2] ("width") the
613
+ // perpendicular one.
614
+ const radiusX = geometry
615
+ ? vectorLength(geometry.start, geometry.end, box)
616
+ : box.width / 2;
617
+ const radiusY = geometry
618
+ ? vectorLength(geometry.start, geometry.width, box)
619
+ : box.height / 2;
620
+ tracker.record(
621
+ node,
622
+ "approximated",
623
+ "Diamond gradient has no CSS equivalent; approximated as an axis-aligned elliptical radial-gradient sized from gradientHandlePositions. True diamond (rotated-square) falloff is not reproduced.",
624
+ );
625
+ return `radial-gradient(ellipse ${round(radiusX, 2)}px ${round(radiusY, 2)}px at ${cx}% ${cy}%, ${stops})`;
626
+ }
627
+ default:
628
+ return null;
629
+ }
630
+ }
631
+
632
+ // ---------------------------------------------------------------------------
633
+ // Fills -> background
634
+ // ---------------------------------------------------------------------------
635
+
636
+ interface BackgroundResult {
637
+ backgroundColor?: string;
638
+ backgroundImage?: string;
639
+ backgroundSize?: string;
640
+ backgroundPosition?: string;
641
+ backgroundRepeat?: string;
642
+ color?: string; // for TEXT nodes, fill paints color the glyphs, not a background
643
+ }
644
+
645
+ function imageScaleModeCss(
646
+ paint: FigmaPaint,
647
+ node: FigmaNode,
648
+ tracker: FidelityTracker,
649
+ ): { size: string; position: string; repeat: string } {
650
+ const transform = paint.imageTransform;
651
+ const isAxisAligned =
652
+ !transform ||
653
+ (Math.abs(transform[0][1]) < 1e-6 && Math.abs(transform[1][0]) < 1e-6);
654
+ if (!isAxisAligned) {
655
+ tracker.record(
656
+ node,
657
+ "approximated",
658
+ "Image fill has a non-axis-aligned imageTransform (rotated/skewed crop); approximated using the scale-mode-only CSS mapping without the transform matrix.",
659
+ );
660
+ }
661
+ switch (paint.scaleMode) {
662
+ case "FILL":
663
+ return { size: "cover", position: "center", repeat: "no-repeat" };
664
+ case "FIT":
665
+ return { size: "contain", position: "center", repeat: "no-repeat" };
666
+ case "TILE":
667
+ return { size: "auto", position: "top left", repeat: "repeat" };
668
+ case "STRETCH":
669
+ return { size: "100% 100%", position: "center", repeat: "no-repeat" };
670
+ default:
671
+ return { size: "cover", position: "center", repeat: "no-repeat" };
672
+ }
673
+ }
674
+
675
+ /**
676
+ * Build the background-* properties for a node's fill stack. Figma paints
677
+ * fills bottom-to-top (index 0 is the bottommost layer); CSS
678
+ * `background-image` layers top-to-bottom (first value on top), so the
679
+ * stack is reversed here to preserve visual order. A solid fill above other
680
+ * layers is expressed as a flat `linear-gradient(color, color)` since CSS
681
+ * `background-color` always paints *beneath every* background-image and
682
+ * cannot be interleaved mid-stack.
683
+ */
684
+ function buildFills(
685
+ node: FigmaNode,
686
+ fills: FigmaPaint[] | undefined,
687
+ box: { width: number; height: number },
688
+ options: MapFigmaNodeOptions,
689
+ tracker: FidelityTracker,
690
+ isTextNode: boolean,
691
+ ): BackgroundResult {
692
+ const visible = (fills ?? []).filter((fill) => fill.visible !== false);
693
+ if (visible.length === 0) return {};
694
+
695
+ if (isTextNode) {
696
+ // Text color comes from the topmost visible SOLID fill; gradient/image
697
+ // text fills are a CSS `background-clip: text` trick we intentionally
698
+ // skip for now (rare in practice) and record as approximated.
699
+ const solid = [...visible].reverse().find((fill) => fill.type === "SOLID");
700
+ if (solid) {
701
+ return {
702
+ color: colorToCss(solid.color, solid.opacity ?? 1) ?? undefined,
703
+ };
704
+ }
705
+ tracker.record(
706
+ node,
707
+ "approximated",
708
+ "Text fill is a gradient/image, not a solid color; rendered with the default text color instead of a background-clip: text gradient.",
709
+ );
710
+ return {};
711
+ }
712
+
713
+ const images: string[] = [];
714
+ const sizes: string[] = [];
715
+ const positions: string[] = [];
716
+ const repeats: string[] = [];
717
+ let backgroundColor: string | undefined;
718
+
719
+ // Reverse so the topmost Figma fill becomes the first (topmost) CSS layer.
720
+ const ordered = [...visible].reverse();
721
+ for (let index = 0; index < ordered.length; index += 1) {
722
+ const fill = ordered[index]!;
723
+ const isBottommost = index === ordered.length - 1;
724
+
725
+ if (fill.type === "SOLID") {
726
+ const color = colorToCss(fill.color, fill.opacity ?? 1);
727
+ if (!color) continue;
728
+ if (isBottommost) {
729
+ // A bottom-most solid always paints beneath every background-image
730
+ // layer, so it can always become plain backgroundColor regardless of
731
+ // how many gradient/image layers are stacked above it.
732
+ backgroundColor = color;
733
+ } else {
734
+ // Solid above other layers: express as a flat gradient so it stacks
735
+ // in the correct z-order alongside gradient/image layers.
736
+ images.push(`linear-gradient(${color}, ${color})`);
737
+ sizes.push("100% 100%");
738
+ positions.push("center");
739
+ repeats.push("no-repeat");
740
+ }
741
+ continue;
742
+ }
743
+
744
+ if (fill.type === "IMAGE") {
745
+ const url = fill.imageRef
746
+ ? options.imageFillUrls?.[fill.imageRef]
747
+ : undefined;
748
+ if (!url) {
749
+ tracker.record(
750
+ node,
751
+ "approximated",
752
+ `Image fill imageRef "${fill.imageRef ?? "unknown"}" had no resolved URL; layer omitted.`,
753
+ );
754
+ continue;
755
+ }
756
+ const mode = imageScaleModeCss(fill, node, tracker);
757
+ images.push(`url("${url}")`);
758
+ sizes.push(mode.size);
759
+ positions.push(mode.position);
760
+ repeats.push(mode.repeat);
761
+ continue;
762
+ }
763
+
764
+ const cssImage = paintToCssImage(fill, box, tracker, node);
765
+ if (cssImage) {
766
+ images.push(cssImage);
767
+ sizes.push("100% 100%");
768
+ positions.push("center");
769
+ repeats.push("no-repeat");
770
+ }
771
+ }
772
+
773
+ const result: BackgroundResult = {};
774
+ if (backgroundColor) result.backgroundColor = backgroundColor;
775
+ if (images.length > 0) {
776
+ result.backgroundImage = images.join(", ");
777
+ result.backgroundSize = sizes.join(", ");
778
+ result.backgroundPosition = positions.join(", ");
779
+ result.backgroundRepeat = repeats.join(", ");
780
+ }
781
+ return result;
782
+ }
783
+
784
+ // ---------------------------------------------------------------------------
785
+ // Strokes -> border / outline / box-shadow
786
+ // ---------------------------------------------------------------------------
787
+
788
+ interface StrokeResult {
789
+ styles: Record<string, string | undefined>;
790
+ insetShadow?: string;
791
+ }
792
+
793
+ function buildStrokes(node: FigmaNode, tracker: FidelityTracker): StrokeResult {
794
+ const strokes = (node.strokes ?? []).filter(
795
+ (stroke) => stroke.visible !== false,
796
+ );
797
+ if (strokes.length === 0) return { styles: {} };
798
+
799
+ const first = strokes[0]!;
800
+ const color =
801
+ colorToCss(first.color, first.opacity ?? 1) ?? "rgba(0, 0, 0, 1)";
802
+ const iw = node.individualStrokeWeights;
803
+ const hasPerSide =
804
+ iw &&
805
+ (iw.top !== undefined ||
806
+ iw.right !== undefined ||
807
+ iw.bottom !== undefined ||
808
+ iw.left !== undefined);
809
+ const uniformWeight = node.strokeWeight ?? 0;
810
+
811
+ if (hasPerSide) {
812
+ // CSS `outline`/inset-`box-shadow` tricks are single-weight only; per-side
813
+ // stroke weights can only be expressed as a real per-side `border`, which
814
+ // always renders fully inside the border-box regardless of strokeAlign.
815
+ // This is exact for INSIDE and an approximation for CENTER/OUTSIDE.
816
+ const top = iw?.top ?? uniformWeight;
817
+ const right = iw?.right ?? uniformWeight;
818
+ const bottom = iw?.bottom ?? uniformWeight;
819
+ const left = iw?.left ?? uniformWeight;
820
+ tracker.record(
821
+ node,
822
+ node.strokeAlign === "INSIDE" || !node.strokeAlign
823
+ ? "exact"
824
+ : "approximated",
825
+ `Per-side stroke weights rendered as CSS border (inside-aligned); strokeAlign="${node.strokeAlign ?? "INSIDE"}" cannot vary per-side with outline tricks.`,
826
+ );
827
+ return {
828
+ styles: {
829
+ "border-top": top ? `${px(top)} solid ${color}` : undefined,
830
+ "border-right": right ? `${px(right)} solid ${color}` : undefined,
831
+ "border-bottom": bottom ? `${px(bottom)} solid ${color}` : undefined,
832
+ "border-left": left ? `${px(left)} solid ${color}` : undefined,
833
+ },
834
+ };
835
+ }
836
+
837
+ if (!uniformWeight) return { styles: {} };
838
+
839
+ switch (node.strokeAlign) {
840
+ case "OUTSIDE":
841
+ tracker.record(
842
+ node,
843
+ "exact",
844
+ "OUTSIDE stroke rendered via outline (offset 0).",
845
+ );
846
+ return {
847
+ styles: {
848
+ outline: `${px(uniformWeight)} solid ${color}`,
849
+ "outline-offset": "0px",
850
+ },
851
+ };
852
+ case "INSIDE":
853
+ tracker.record(
854
+ node,
855
+ "exact",
856
+ "INSIDE stroke rendered via inset box-shadow.",
857
+ );
858
+ return {
859
+ styles: {},
860
+ insetShadow: `inset 0 0 0 ${px(uniformWeight)} ${color}`,
861
+ };
862
+ case "CENTER":
863
+ default:
864
+ // outline-offset of -half the weight pulls the outline half inside,
865
+ // half outside the border-box edge -- reproducing Figma's CENTER
866
+ // straddle exactly (plain CSS `border` cannot straddle the edge).
867
+ tracker.record(
868
+ node,
869
+ "exact",
870
+ "CENTER stroke rendered via outline with outline-offset = -weight/2 (straddles the edge like Figma).",
871
+ );
872
+ return {
873
+ styles: {
874
+ outline: `${px(uniformWeight)} solid ${color}`,
875
+ "outline-offset": px(-uniformWeight / 2),
876
+ },
877
+ };
878
+ }
879
+ }
880
+
881
+ // ---------------------------------------------------------------------------
882
+ // Corner radii
883
+ // ---------------------------------------------------------------------------
884
+
885
+ function buildCornerRadius(node: FigmaNode): string | undefined {
886
+ if (node.rectangleCornerRadii) {
887
+ const [tl, tr, br, bl] = node.rectangleCornerRadii;
888
+ return `${px(tl) ?? "0px"} ${px(tr) ?? "0px"} ${px(br) ?? "0px"} ${px(bl) ?? "0px"}`;
889
+ }
890
+ if (typeof node.cornerRadius === "number" && node.cornerRadius > 0) {
891
+ return px(node.cornerRadius);
892
+ }
893
+ return undefined;
894
+ }
895
+
896
+ // ---------------------------------------------------------------------------
897
+ // Effects -> box-shadow / filter / backdrop-filter
898
+ // ---------------------------------------------------------------------------
899
+
900
+ interface EffectResult {
901
+ boxShadowLayers: string[];
902
+ filter?: string;
903
+ backdropFilter?: string;
904
+ }
905
+
906
+ function buildEffects(
907
+ node: FigmaNode,
908
+ isTextNode: boolean,
909
+ tracker: FidelityTracker,
910
+ ): EffectResult {
911
+ const effects = (node.effects ?? []).filter(
912
+ (effect) => effect.visible !== false,
913
+ );
914
+ const boxShadowLayers: string[] = [];
915
+ let filter: string | undefined;
916
+ let backdropFilter: string | undefined;
917
+
918
+ for (const effect of effects) {
919
+ if (effect.type === "DROP_SHADOW" || effect.type === "INNER_SHADOW") {
920
+ const color = colorToCss(effect.color, 1) ?? "rgba(0, 0, 0, 1)";
921
+ const x = px(effect.offset?.x ?? 0) ?? "0px";
922
+ const y = px(effect.offset?.y ?? 0) ?? "0px";
923
+ const blur = px(effect.radius ?? 0) ?? "0px";
924
+ const spread =
925
+ !isTextNode && typeof effect.spread === "number"
926
+ ? ` ${px(effect.spread)}`
927
+ : "";
928
+ const inset = effect.type === "INNER_SHADOW" ? "inset " : "";
929
+ boxShadowLayers.push(`${inset}${x} ${y} ${blur}${spread} ${color}`);
930
+ tracker.record(
931
+ node,
932
+ "exact",
933
+ `${effect.type} rendered as ${isTextNode ? "text-shadow" : "box-shadow"}.`,
934
+ );
935
+ } else if (effect.type === "LAYER_BLUR") {
936
+ const radius = px(effect.radius ?? 0) ?? "0px";
937
+ filter = filter ? `${filter} blur(${radius})` : `blur(${radius})`;
938
+ tracker.record(
939
+ node,
940
+ "approximated",
941
+ "LAYER_BLUR mapped 1:1 to CSS filter: blur(); Figma's blur radius-to-CSS-stdDeviation scale is not publicly documented, so the rendered softness may differ slightly.",
942
+ );
943
+ } else if (effect.type === "BACKGROUND_BLUR") {
944
+ const radius = px(effect.radius ?? 0) ?? "0px";
945
+ backdropFilter = backdropFilter
946
+ ? `${backdropFilter} blur(${radius})`
947
+ : `blur(${radius})`;
948
+ tracker.record(
949
+ node,
950
+ "approximated",
951
+ "BACKGROUND_BLUR mapped 1:1 to CSS backdrop-filter: blur(); same radius-scale caveat as LAYER_BLUR.",
952
+ );
953
+ }
954
+ }
955
+
956
+ return { boxShadowLayers, filter, backdropFilter };
957
+ }
958
+
959
+ // ---------------------------------------------------------------------------
960
+ // Blend modes
961
+ // ---------------------------------------------------------------------------
962
+
963
+ const CSS_BLEND_MODES = new Set([
964
+ "multiply",
965
+ "screen",
966
+ "overlay",
967
+ "darken",
968
+ "lighten",
969
+ "color-dodge",
970
+ "color-burn",
971
+ "hard-light",
972
+ "soft-light",
973
+ "difference",
974
+ "exclusion",
975
+ "hue",
976
+ "saturation",
977
+ "color",
978
+ "luminosity",
979
+ ]);
980
+
981
+ const FIGMA_ONLY_BLEND_MODE_FALLBACK: Record<string, string> = {
982
+ LINEAR_BURN: "multiply",
983
+ LINEAR_DODGE: "plus-lighter",
984
+ LIGHTER: "plus-lighter",
985
+ DARKER: "darken",
986
+ };
987
+
988
+ function buildBlendMode(
989
+ node: FigmaNode,
990
+ tracker: FidelityTracker,
991
+ ): string | undefined {
992
+ const mode = node.blendMode;
993
+ if (!mode || mode === "PASS_THROUGH" || mode === "NORMAL") return undefined;
994
+ const cssMode = mode.toLowerCase().replace(/_/g, "-");
995
+ if (CSS_BLEND_MODES.has(cssMode)) return cssMode;
996
+ const fallback = FIGMA_ONLY_BLEND_MODE_FALLBACK[mode];
997
+ if (fallback) {
998
+ tracker.record(
999
+ node,
1000
+ "approximated",
1001
+ `Figma blend mode "${mode}" has no CSS equivalent; approximated as mix-blend-mode: ${fallback}.`,
1002
+ );
1003
+ return fallback;
1004
+ }
1005
+ return undefined;
1006
+ }
1007
+
1008
+ // ---------------------------------------------------------------------------
1009
+ // Text styling
1010
+ // ---------------------------------------------------------------------------
1011
+
1012
+ function resolveLineHeight(style: FigmaTypeStyle): string | undefined {
1013
+ if (
1014
+ typeof style.lineHeightPx === "number" &&
1015
+ style.lineHeightUnit !== "FONT_SIZE_%"
1016
+ ) {
1017
+ return px(style.lineHeightPx);
1018
+ }
1019
+ if (
1020
+ typeof style.lineHeightPercentFontSize === "number" &&
1021
+ typeof style.fontSize === "number"
1022
+ ) {
1023
+ // lineHeightPercentFontSize is literally "percent of the font's nominal
1024
+ // size" -- resolve to an exact px value rather than a unitless ratio so
1025
+ // the rendered line box matches Figma regardless of font metrics.
1026
+ return px(style.fontSize * (style.lineHeightPercentFontSize / 100));
1027
+ }
1028
+ if (typeof style.lineHeightPx === "number") {
1029
+ return px(style.lineHeightPx);
1030
+ }
1031
+ return undefined;
1032
+ }
1033
+
1034
+ function textTransformCss(
1035
+ textCase: FigmaTypeStyle["textCase"],
1036
+ ): string | undefined {
1037
+ switch (textCase) {
1038
+ case "UPPER":
1039
+ return "uppercase";
1040
+ case "LOWER":
1041
+ return "lowercase";
1042
+ case "TITLE":
1043
+ return "capitalize";
1044
+ default:
1045
+ return undefined;
1046
+ }
1047
+ }
1048
+
1049
+ function textDecorationCss(
1050
+ decoration: FigmaTypeStyle["textDecoration"],
1051
+ ): string | undefined {
1052
+ switch (decoration) {
1053
+ case "UNDERLINE":
1054
+ return "underline";
1055
+ case "STRIKETHROUGH":
1056
+ return "line-through";
1057
+ default:
1058
+ return undefined;
1059
+ }
1060
+ }
1061
+
1062
+ function textAlignCss(
1063
+ align: FigmaTypeStyle["textAlignHorizontal"],
1064
+ ): string | undefined {
1065
+ switch (align) {
1066
+ case "CENTER":
1067
+ return "center";
1068
+ case "RIGHT":
1069
+ return "right";
1070
+ case "JUSTIFIED":
1071
+ return "justify";
1072
+ case "LEFT":
1073
+ return "left";
1074
+ default:
1075
+ return undefined;
1076
+ }
1077
+ }
1078
+
1079
+ function verticalAlignJustifyContent(
1080
+ align: FigmaTypeStyle["textAlignVertical"],
1081
+ ): string {
1082
+ switch (align) {
1083
+ case "CENTER":
1084
+ return "center";
1085
+ case "BOTTOM":
1086
+ return "flex-end";
1087
+ default:
1088
+ return "flex-start";
1089
+ }
1090
+ }
1091
+
1092
+ // ---------------------------------------------------------------------------
1093
+ // Auto-layout
1094
+ // ---------------------------------------------------------------------------
1095
+
1096
+ function primaryAxisJustify(align: FigmaNode["primaryAxisAlignItems"]): string {
1097
+ switch (align) {
1098
+ case "CENTER":
1099
+ return "center";
1100
+ case "MAX":
1101
+ return "flex-end";
1102
+ case "SPACE_BETWEEN":
1103
+ return "space-between";
1104
+ default:
1105
+ return "flex-start";
1106
+ }
1107
+ }
1108
+
1109
+ function counterAxisAlign(align: FigmaNode["counterAxisAlignItems"]): string {
1110
+ switch (align) {
1111
+ case "CENTER":
1112
+ return "center";
1113
+ case "MAX":
1114
+ return "flex-end";
1115
+ case "BASELINE":
1116
+ return "baseline";
1117
+ default:
1118
+ return "flex-start";
1119
+ }
1120
+ }
1121
+
1122
+ function buildAutoLayoutStyles(
1123
+ node: FigmaNode,
1124
+ ): Record<string, string | undefined> {
1125
+ if (
1126
+ !node.layoutMode ||
1127
+ node.layoutMode === "NONE" ||
1128
+ node.layoutMode === "GRID"
1129
+ ) {
1130
+ return {};
1131
+ }
1132
+ const isHorizontal = node.layoutMode === "HORIZONTAL";
1133
+ const styles: Record<string, string | undefined> = {
1134
+ display: "flex",
1135
+ "flex-direction": isHorizontal ? "row" : "column",
1136
+ "justify-content": primaryAxisJustify(node.primaryAxisAlignItems),
1137
+ "align-items": counterAxisAlign(node.counterAxisAlignItems),
1138
+ };
1139
+ if (node.layoutWrap === "WRAP") styles["flex-wrap"] = "wrap";
1140
+ if (typeof node.itemSpacing === "number" && node.itemSpacing !== 0) {
1141
+ styles[isHorizontal ? "column-gap" : "row-gap"] = px(node.itemSpacing);
1142
+ }
1143
+ if (
1144
+ typeof node.counterAxisSpacing === "number" &&
1145
+ node.counterAxisSpacing !== 0
1146
+ ) {
1147
+ styles[isHorizontal ? "row-gap" : "column-gap"] = px(
1148
+ node.counterAxisSpacing,
1149
+ );
1150
+ }
1151
+ const padTop = node.paddingTop ?? 0;
1152
+ const padRight = node.paddingRight ?? 0;
1153
+ const padBottom = node.paddingBottom ?? 0;
1154
+ const padLeft = node.paddingLeft ?? 0;
1155
+ if (padTop || padRight || padBottom || padLeft) {
1156
+ styles.padding = `${px(padTop)} ${px(padRight)} ${px(padBottom)} ${px(padLeft)}`;
1157
+ }
1158
+ return styles;
1159
+ }
1160
+
1161
+ /**
1162
+ * "FILL" sizing must map to different CSS depending on which axis is the
1163
+ * flex *main* axis for this node's parent: main-axis FILL grows via
1164
+ * `flex-grow`/`flex-basis` (row parent -> horizontal FILL, column parent ->
1165
+ * vertical FILL); cross-axis FILL stretches via `align-self: stretch` (row
1166
+ * parent -> vertical FILL, column parent -> horizontal FILL). Passing only a
1167
+ * `parentHasAutoLayout` boolean (as this used to) loses the row/column
1168
+ * direction and always mapped horizontal-FILL to flex-grow — correct for row
1169
+ * parents but wrong for column parents, where a FILL-width text/rect child
1170
+ * got `width: auto` with no stretch and overflowed to its content width.
1171
+ */
1172
+ function buildChildSizingStyles(
1173
+ node: FigmaNode,
1174
+ parentLayoutMode: "NONE" | "HORIZONTAL" | "VERTICAL",
1175
+ ): Record<string, string | undefined> {
1176
+ if (parentLayoutMode === "NONE") return {};
1177
+ const parentIsHorizontal = parentLayoutMode === "HORIZONTAL";
1178
+ const styles: Record<string, string | undefined> = {};
1179
+ if (node.layoutSizingHorizontal === "FILL") {
1180
+ if (parentIsHorizontal) {
1181
+ styles["flex-grow"] = "1";
1182
+ styles["flex-basis"] = "0%";
1183
+ } else {
1184
+ styles["align-self"] = "stretch";
1185
+ }
1186
+ styles.width = "auto";
1187
+ } else if (node.layoutSizingHorizontal === "HUG") {
1188
+ styles.width = "auto";
1189
+ }
1190
+ if (node.layoutSizingVertical === "FILL") {
1191
+ if (parentIsHorizontal) {
1192
+ styles["align-self"] = "stretch";
1193
+ } else {
1194
+ styles["flex-grow"] = "1";
1195
+ styles["flex-basis"] = "0%";
1196
+ }
1197
+ styles.height = "auto";
1198
+ } else if (node.layoutSizingVertical === "HUG") {
1199
+ styles.height = "auto";
1200
+ }
1201
+ return styles;
1202
+ }
1203
+
1204
+ // ---------------------------------------------------------------------------
1205
+ // Node type classification
1206
+ // ---------------------------------------------------------------------------
1207
+
1208
+ function needsImageFallback(
1209
+ node: FigmaNode,
1210
+ options: MapFigmaNodeOptions,
1211
+ ): boolean {
1212
+ if (options.forceImageFallbackNodeIds?.has(node.id)) return true;
1213
+ if (UNSUPPORTED_STRUCTURAL_TYPES.has(node.type)) return true;
1214
+ // A Figma mask affects its following siblings, not just the mask node. CSS
1215
+ // cannot reproduce that sibling-range operation on an arbitrary DOM tree,
1216
+ // so render the smallest containing subtree rather than importing a visibly
1217
+ // wrong unmasked composition. A mask imported as the root is also rendered.
1218
+ if (node.isMask || node.children?.some((child) => child.isMask)) return true;
1219
+ // A CSS div with an outline is not a Figma line. Partial/ring ellipses also
1220
+ // need real path geometry, which this structural mapper intentionally does
1221
+ // not request because geometry=paths makes ordinary REST payloads enormous.
1222
+ if (node.type === "LINE") return true;
1223
+ if (node.type === "ELLIPSE" && node.arcData) {
1224
+ const start = node.arcData.startingAngle ?? 0;
1225
+ const end = node.arcData.endingAngle ?? Math.PI * 2;
1226
+ const span = Math.abs(end - start);
1227
+ const isFullCircle =
1228
+ Math.abs(span - Math.PI * 2) < 1e-4 &&
1229
+ Math.abs(node.arcData.innerRadius ?? 0) < 1e-4;
1230
+ if (!isFullCircle) return true;
1231
+ }
1232
+ const visibleStrokes = (node.strokes ?? []).filter(
1233
+ (stroke) => stroke.visible !== false,
1234
+ );
1235
+ if (
1236
+ visibleStrokes.length > 1 ||
1237
+ visibleStrokes.some((stroke) => stroke.type !== "SOLID") ||
1238
+ (node.strokeDashes?.length ?? 0) > 0
1239
+ ) {
1240
+ return true;
1241
+ }
1242
+ const visibleFills = (node.fills ?? []).filter(
1243
+ (fill) => fill.visible !== false,
1244
+ );
1245
+ if (
1246
+ visibleFills.some(
1247
+ (fill) =>
1248
+ fill.type === "VIDEO" ||
1249
+ fill.type === "EMOJI" ||
1250
+ (fill.blendMode &&
1251
+ fill.blendMode !== "NORMAL" &&
1252
+ fill.blendMode !== "PASS_THROUGH") ||
1253
+ (fill.type === "IMAGE" &&
1254
+ ((fill.imageTransform &&
1255
+ (Math.abs(fill.imageTransform[0][1]) >= 1e-6 ||
1256
+ Math.abs(fill.imageTransform[1][0]) >= 1e-6)) ||
1257
+ Object.values(fill.filters ?? {}).some(
1258
+ (value) => typeof value === "number" && Math.abs(value) > 1e-6,
1259
+ ))),
1260
+ ) ||
1261
+ (node.type === "TEXT" && visibleFills.some((fill) => fill.type !== "SOLID"))
1262
+ ) {
1263
+ return true;
1264
+ }
1265
+ if (node.type === "TEXT") {
1266
+ const styles = [
1267
+ node.style,
1268
+ ...Object.values(node.styleOverrideTable ?? {}),
1269
+ ].filter((style): style is FigmaTypeStyle => Boolean(style));
1270
+ const hasAdvancedTypography = styles.some(
1271
+ (style) =>
1272
+ Math.abs(style.paragraphSpacing ?? 0) > 1e-6 ||
1273
+ Math.abs(style.paragraphIndent ?? 0) > 1e-6 ||
1274
+ Math.abs(style.listSpacing ?? 0) > 1e-6 ||
1275
+ style.hangingPunctuation === true ||
1276
+ style.hangingList === true ||
1277
+ style.hyperlink !== undefined ||
1278
+ Object.values(style.opentypeFlags ?? {}).some((value) => value !== 0),
1279
+ );
1280
+ if (
1281
+ hasAdvancedTypography ||
1282
+ // Figma's REST API always returns one `lineTypes` entry per line —
1283
+ // ordinary non-list text comes back as `["NONE", "NONE", ...]`, not an
1284
+ // empty array. Checking `.length > 0` alone treats every multi-line
1285
+ // text node in existence as an unsupported list and routes it to an
1286
+ // image fallback; only a line whose type is actually "ORDERED" or
1287
+ // "UNORDERED" means the text uses real list formatting.
1288
+ (node.lineTypes?.some((type) => type !== "NONE") ?? false) ||
1289
+ (node.lineIndentations?.some((value) => value !== 0) ?? false)
1290
+ ) {
1291
+ return true;
1292
+ }
1293
+ }
1294
+ if (
1295
+ (node.effects ?? []).some(
1296
+ (effect) =>
1297
+ effect.visible !== false &&
1298
+ effect.blendMode &&
1299
+ effect.blendMode !== "NORMAL" &&
1300
+ effect.blendMode !== "PASS_THROUGH",
1301
+ )
1302
+ ) {
1303
+ return true;
1304
+ }
1305
+ if (
1306
+ !SUPPORTED_CONTAINER_TYPES.has(node.type) &&
1307
+ node.type !== "RECTANGLE" &&
1308
+ node.type !== "ELLIPSE" &&
1309
+ node.type !== "TEXT"
1310
+ ) {
1311
+ return true;
1312
+ }
1313
+ return false;
1314
+ }
1315
+
1316
+ /** Fail clearly before recursive rendering can overflow or lock the worker. */
1317
+ export function assertFigmaNodeTreeComplexity(node: FigmaNode): void {
1318
+ const stack: Array<{ node: FigmaNode; depth: number }> = [{ node, depth: 1 }];
1319
+ const ancestors = new WeakSet<object>();
1320
+ let count = 0;
1321
+ while (stack.length > 0) {
1322
+ const current = stack.pop()!;
1323
+ count += 1;
1324
+ if (count > MAX_FIGMA_NODE_COUNT) {
1325
+ throw new Error(
1326
+ `Figma node tree is too large (max ${MAX_FIGMA_NODE_COUNT.toLocaleString("en-US")} nodes). Import a smaller frame or selection.`,
1327
+ );
1328
+ }
1329
+ if (current.depth > MAX_FIGMA_NODE_DEPTH) {
1330
+ throw new Error(
1331
+ `Figma node tree is nested too deeply (max ${MAX_FIGMA_NODE_DEPTH} levels). Import a smaller frame or selection.`,
1332
+ );
1333
+ }
1334
+ if (ancestors.has(current.node)) {
1335
+ throw new Error("Figma node tree contains a cyclic child reference.");
1336
+ }
1337
+ ancestors.add(current.node);
1338
+ for (const child of current.node.children ?? []) {
1339
+ stack.push({ node: child, depth: current.depth + 1 });
1340
+ }
1341
+ }
1342
+ }
1343
+
1344
+ /**
1345
+ * Walk a node tree and return the ids of every subtree that will render as a
1346
+ * PNG image fallback (vector networks, boolean ops, and any node type this
1347
+ * mapper does not model structurally). Call this before fetching node data
1348
+ * so the caller can request rendered images for exactly these ids via
1349
+ * `GET /v1/images/:fileKey?ids=...&scale=2`.
1350
+ */
1351
+ export function collectFallbackNodeIds(
1352
+ node: FigmaNode,
1353
+ options: MapFigmaNodeOptions = {},
1354
+ ): string[] {
1355
+ assertFigmaNodeTreeComplexity(node);
1356
+ const ids: string[] = [];
1357
+ const visit = (current: FigmaNode) => {
1358
+ if (current.visible === false || current.opacity === 0) return;
1359
+ if (needsImageFallback(current, options)) {
1360
+ ids.push(current.id);
1361
+ return; // Don't recurse into a subtree that's rendered as one image.
1362
+ }
1363
+ for (const child of current.children ?? []) visit(child);
1364
+ };
1365
+ visit(node);
1366
+ return ids;
1367
+ }
1368
+
1369
+ /**
1370
+ * Walk a node tree and return every distinct `imageRef` used by IMAGE fills
1371
+ * (on fills or strokes) so the caller can resolve them to URLs via
1372
+ * `GET /v1/files/:fileKey/images` before mapping.
1373
+ */
1374
+ export function collectImageFillRefs(
1375
+ node: FigmaNode,
1376
+ options: MapFigmaNodeOptions = {},
1377
+ ): string[] {
1378
+ assertFigmaNodeTreeComplexity(node);
1379
+ const refs = new Set<string>();
1380
+ const visitPaints = (paints: FigmaPaint[] | undefined) => {
1381
+ for (const paint of paints ?? []) {
1382
+ if (paint.type === "IMAGE" && paint.imageRef) refs.add(paint.imageRef);
1383
+ }
1384
+ };
1385
+ const visit = (current: FigmaNode) => {
1386
+ if (current.visible === false || current.opacity === 0) return;
1387
+ if (needsImageFallback(current, options)) return;
1388
+ visitPaints(current.fills);
1389
+ visitPaints(current.strokes);
1390
+ for (const child of current.children ?? []) visit(child);
1391
+ };
1392
+ visit(node);
1393
+ return [...refs];
1394
+ }
1395
+
1396
+ export interface FigmaFontUsage {
1397
+ family: string;
1398
+ weight: number;
1399
+ italic: boolean;
1400
+ }
1401
+
1402
+ function recordFontUsage(
1403
+ style: FigmaTypeStyle | undefined,
1404
+ usage: Map<string, FigmaFontUsage>,
1405
+ ): void {
1406
+ if (!style?.fontFamily) return;
1407
+ const weight = typeof style.fontWeight === "number" ? style.fontWeight : 400;
1408
+ const italic = Boolean(style.italic);
1409
+ const key = `${style.fontFamily}|${weight}|${italic ? 1 : 0}`;
1410
+ if (!usage.has(key))
1411
+ usage.set(key, { family: style.fontFamily, weight, italic });
1412
+ }
1413
+
1414
+ /**
1415
+ * Walk a node tree and return every distinct (font family, weight, italic)
1416
+ * combination used by TEXT nodes -- including per-run character style
1417
+ * overrides -- so the caller can request the actual web font (e.g. from
1418
+ * Google Fonts) before the imported HTML is saved. Without this, an imported
1419
+ * screen's CSS correctly names the intended font-family, but the browser has
1420
+ * no way to load it and silently falls back to a generic sans-serif with
1421
+ * different glyph advance widths -- individually invisible per character but
1422
+ * compounding into a growing horizontal drift across any wrapped or
1423
+ * multi-word line, worst on text-dense imports.
1424
+ */
1425
+ export function collectFontUsage(node: FigmaNode): FigmaFontUsage[] {
1426
+ assertFigmaNodeTreeComplexity(node);
1427
+ const usage = new Map<string, FigmaFontUsage>();
1428
+ const visit = (current: FigmaNode) => {
1429
+ if (current.visible === false || current.opacity === 0) return;
1430
+ if (current.type === "TEXT") {
1431
+ recordFontUsage(current.style, usage);
1432
+ for (const style of Object.values(current.styleOverrideTable ?? {})) {
1433
+ recordFontUsage(style, usage);
1434
+ }
1435
+ }
1436
+ for (const child of current.children ?? []) visit(child);
1437
+ };
1438
+ visit(node);
1439
+ return [...usage.values()];
1440
+ }
1441
+
1442
+ function textOverrideCss(
1443
+ style: FigmaTypeStyle | undefined,
1444
+ ): Record<string, string | undefined> {
1445
+ const solidFill = [...(style?.fills ?? [])]
1446
+ .reverse()
1447
+ .find((fill) => fill.visible !== false && fill.type === "SOLID");
1448
+ return {
1449
+ "font-family": style?.fontFamily
1450
+ ? `"${style.fontFamily.replace(/"/g, "")}", sans-serif`
1451
+ : undefined,
1452
+ "font-size": px(style?.fontSize),
1453
+ "font-weight":
1454
+ typeof style?.fontWeight === "number"
1455
+ ? String(style.fontWeight)
1456
+ : undefined,
1457
+ "font-style": style?.italic ? "italic" : undefined,
1458
+ "line-height": style ? resolveLineHeight(style) : undefined,
1459
+ "letter-spacing":
1460
+ typeof style?.letterSpacing === "number"
1461
+ ? px(style.letterSpacing)
1462
+ : undefined,
1463
+ "text-transform": textTransformCss(style?.textCase),
1464
+ "text-decoration": textDecorationCss(style?.textDecoration),
1465
+ color: solidFill
1466
+ ? (colorToCss(solidFill.color, solidFill.opacity ?? 1) ?? undefined)
1467
+ : undefined,
1468
+ };
1469
+ }
1470
+
1471
+ /** Render contiguous Figma character-style override runs as inline spans. */
1472
+ function buildMixedTextHtml(
1473
+ node: FigmaNode,
1474
+ characters: string,
1475
+ tracker: FidelityTracker,
1476
+ ): string {
1477
+ const overrideIds = node.characterStyleOverrides ?? [];
1478
+ const table = node.styleOverrideTable ?? {};
1479
+ if (
1480
+ characters.length === 0 ||
1481
+ !overrideIds.some((id) => id !== 0 && table[String(id)])
1482
+ ) {
1483
+ return escapeHtml(characters);
1484
+ }
1485
+
1486
+ const runs: Array<{ id: number; text: string }> = [];
1487
+ for (let index = 0; index < characters.length; index += 1) {
1488
+ const id = overrideIds[index] ?? 0;
1489
+ const previous = runs[runs.length - 1];
1490
+ if (previous?.id === id) previous.text += characters[index] ?? "";
1491
+ else runs.push({ id, text: characters[index] ?? "" });
1492
+ }
1493
+
1494
+ tracker.record(
1495
+ node,
1496
+ "exact",
1497
+ "Mixed character style overrides were preserved as inline text runs.",
1498
+ );
1499
+ return runs
1500
+ .map((run) => {
1501
+ if (run.id === 0) return escapeHtml(run.text);
1502
+ const style = table[String(run.id)];
1503
+ if (!style) return escapeHtml(run.text);
1504
+ return `<span style="${styleAttr(textOverrideCss(style))}">${escapeHtml(run.text)}</span>`;
1505
+ })
1506
+ .join("");
1507
+ }
1508
+
1509
+ // ---------------------------------------------------------------------------
1510
+ // Main mapper
1511
+ // ---------------------------------------------------------------------------
1512
+
1513
+ function frameRelativeBox(
1514
+ node: FigmaNode,
1515
+ parentBox: FigmaBoundingBox | null,
1516
+ ): { left: number; top: number; width: number; height: number } {
1517
+ const box = node.absoluteBoundingBox;
1518
+ if (!box) return { left: 0, top: 0, width: 0, height: 0 };
1519
+ return {
1520
+ left: box.x - (parentBox?.x ?? box.x),
1521
+ top: box.y - (parentBox?.y ?? box.y),
1522
+ width: box.width,
1523
+ height: box.height,
1524
+ };
1525
+ }
1526
+
1527
+ /**
1528
+ * Figma's `absoluteBoundingBox` for a rotated node is the axis-aligned
1529
+ * bounding box of the ALREADY-ROTATED shape, not the shape's own (pre-
1530
+ * rotation) width/height -- e.g. a 120x80 rectangle rotated 15 degrees comes
1531
+ * back with an ~136.6x108.3 bounding box. Applying a CSS `rotate()` on TOP
1532
+ * of a div already sized to that expanded AABB rotates an oversized box,
1533
+ * producing a visibly wrong (too-large, wrong-aspect-ratio) rotated shape.
1534
+ * This inverts the AABB formula (`W' = W*|cos| + H*|sin|`,
1535
+ * `H' = W*|sin| + H*|cos|`) to recover the true pre-rotation width/height,
1536
+ * then re-centers the (smaller) box at the same center point the AABB had --
1537
+ * matching this module's existing "rotate about the AABB center" pivot
1538
+ * assumption, so the CSS `rotate()` reproduces the original box exactly.
1539
+ */
1540
+ function unrotateBox(
1541
+ box: { left: number; top: number; width: number; height: number },
1542
+ rotationDeg: number,
1543
+ ): { left: number; top: number; width: number; height: number } {
1544
+ const theta = (rotationDeg * Math.PI) / 180;
1545
+ const c = Math.abs(Math.cos(theta));
1546
+ const s = Math.abs(Math.sin(theta));
1547
+ const det = c * c - s * s;
1548
+ // Near +-45/+-135 degrees the AABB<->true-size system is near-singular
1549
+ // (many different true sizes produce almost the same AABB); fall back to
1550
+ // the AABB dimensions rather than dividing by ~zero and producing a huge
1551
+ // or negative "true" size.
1552
+ if (Math.abs(det) < 0.05) return box;
1553
+ const trueWidth = (c * box.width - s * box.height) / det;
1554
+ const trueHeight = (c * box.height - s * box.width) / det;
1555
+ if (
1556
+ !Number.isFinite(trueWidth) ||
1557
+ !Number.isFinite(trueHeight) ||
1558
+ trueWidth <= 0 ||
1559
+ trueHeight <= 0
1560
+ ) {
1561
+ return box;
1562
+ }
1563
+ const centerX = box.left + box.width / 2;
1564
+ const centerY = box.top + box.height / 2;
1565
+ return {
1566
+ left: centerX - trueWidth / 2,
1567
+ top: centerY - trueHeight / 2,
1568
+ width: trueWidth,
1569
+ height: trueHeight,
1570
+ };
1571
+ }
1572
+
1573
+ /**
1574
+ * Same as `frameRelativeBox` but sized/positioned from `absoluteRenderBounds`
1575
+ * (falling back to `absoluteBoundingBox` when Figma didn't return render
1576
+ * bounds). Used only for image-fallback `<img>` geometry -- see the
1577
+ * `absoluteRenderBounds` field doc for why the geometric box is wrong there.
1578
+ */
1579
+ function frameRelativeRenderBox(
1580
+ node: FigmaNode,
1581
+ parentBox: FigmaBoundingBox | null,
1582
+ ): { left: number; top: number; width: number; height: number } {
1583
+ const box = node.absoluteRenderBounds ?? node.absoluteBoundingBox;
1584
+ if (!box) return { left: 0, top: 0, width: 0, height: 0 };
1585
+ return {
1586
+ left: box.x - (parentBox?.x ?? box.x),
1587
+ top: box.y - (parentBox?.y ?? box.y),
1588
+ width: box.width,
1589
+ height: box.height,
1590
+ };
1591
+ }
1592
+
1593
+ function buildNode(
1594
+ node: FigmaNode,
1595
+ parentBox: FigmaBoundingBox | null,
1596
+ parentLayoutMode: "NONE" | "HORIZONTAL" | "VERTICAL",
1597
+ options: MapFigmaNodeOptions,
1598
+ tracker: FidelityTracker,
1599
+ isRoot: boolean,
1600
+ ): string {
1601
+ const parentHasAutoLayout = parentLayoutMode !== "NONE";
1602
+ if (node.visible === false || node.opacity === 0) return "";
1603
+
1604
+ let box = frameRelativeBox(node, parentBox);
1605
+ // The Figma REST API's file-node-types docs describe `rotation` as
1606
+ // "in degrees", but empirically (verified against known authored values
1607
+ // via the Plugin API -- e.g. an authored 15deg/20deg rotation comes back
1608
+ // as 0.2617993.../0.3490658... here) the REST API actually returns
1609
+ // RADIANS. Treating that value as degrees silently shrinks every rotation
1610
+ // by a factor of ~57 (pi/180), rendering rotated content as visually
1611
+ // unrotated. Convert to degrees before using it anywhere below.
1612
+ const rotationDeg =
1613
+ typeof node.rotation === "number"
1614
+ ? (node.rotation * 180) / Math.PI
1615
+ : undefined;
1616
+ const rotation =
1617
+ rotationDeg !== undefined && Math.abs(rotationDeg) > 0.001
1618
+ ? rotationDeg
1619
+ : undefined;
1620
+ if (rotation !== undefined) {
1621
+ // `box` (from absoluteBoundingBox) is the rotated shape's AABB; recover
1622
+ // the true pre-rotation width/height/position so fills/effects/strokes
1623
+ // below -- and the CSS `rotate()` applied later -- operate on the
1624
+ // correct box instead of an oversized one. See `unrotateBox`.
1625
+ box = unrotateBox(box, rotation);
1626
+ }
1627
+ const nameAttr = node.name
1628
+ ? ` data-agent-native-layer-name="${escapeAttr(node.name)}"`
1629
+ : "";
1630
+ const idAttr = ` data-figma-node-id="${escapeAttr(node.id)}"`;
1631
+ const typeAttr = ` data-figma-node-type="${escapeAttr(node.type)}"`;
1632
+ const semanticAttrs =
1633
+ metadataAttr("data-figma-component-id", node.componentId, node, tracker) +
1634
+ metadataAttr(
1635
+ "data-figma-component-properties",
1636
+ node.componentProperties,
1637
+ node,
1638
+ tracker,
1639
+ ) +
1640
+ metadataAttr(
1641
+ "data-figma-bound-variables",
1642
+ node.boundVariables,
1643
+ node,
1644
+ tracker,
1645
+ ) +
1646
+ metadataAttr("data-figma-interactions", node.interactions, node, tracker);
1647
+ if (node.componentId || node.componentProperties) {
1648
+ tracker.record(
1649
+ node,
1650
+ "approximated",
1651
+ "Figma component/instance provenance was preserved as metadata, but the imported HTML is not linked to the original Figma component master.",
1652
+ );
1653
+ }
1654
+ if (node.boundVariables && Object.keys(node.boundVariables).length > 0) {
1655
+ tracker.record(
1656
+ node,
1657
+ "approximated",
1658
+ "Figma variable bindings were preserved as metadata; resolved visual values are imported, but bindings are not live Design tokens.",
1659
+ );
1660
+ }
1661
+ if (node.interactions && node.interactions.length > 0) {
1662
+ tracker.record(
1663
+ node,
1664
+ "approximated",
1665
+ "Prototype interactions were preserved as inert metadata and do not execute or navigate inside the editor preview.",
1666
+ );
1667
+ }
1668
+
1669
+ if (needsImageFallback(node, options)) {
1670
+ const imageUrl = options.fallbackImageUrls?.[node.id];
1671
+ if (!imageUrl) {
1672
+ tracker.record(
1673
+ node,
1674
+ "image-fallback",
1675
+ `Node type "${node.type}" requires an image fallback but no rendered URL was provided; nothing was rendered for this node.`,
1676
+ );
1677
+ return "";
1678
+ }
1679
+ tracker.record(
1680
+ node,
1681
+ "image-fallback",
1682
+ `Node type "${node.type}" cannot be reproduced structurally (vector network / boolean op / unsupported type); rendered as an exact PNG (scale=2) instead of an approximated structural guess.`,
1683
+ );
1684
+ const isFlowChild =
1685
+ !isRoot && parentHasAutoLayout && node.layoutPositioning !== "ABSOLUTE";
1686
+ // Use render bounds (not the geometric box) so a fallback PNG whose
1687
+ // stroke/effects overflow the node's own bounding box (e.g. an
1688
+ // OUTSIDE-aligned stroke) is placed at its natural size instead of being
1689
+ // squished/cropped into the smaller geometric box.
1690
+ const renderBox = frameRelativeRenderBox(node, parentBox);
1691
+ const styles: Record<string, string | undefined> = {
1692
+ position: isRoot || isFlowChild ? "relative" : "absolute",
1693
+ left: isRoot || isFlowChild ? undefined : px(renderBox.left),
1694
+ top: isRoot || isFlowChild ? undefined : px(renderBox.top),
1695
+ width: px(renderBox.width),
1696
+ height: px(renderBox.height),
1697
+ opacity:
1698
+ typeof node.opacity === "number" && node.opacity !== 1
1699
+ ? String(round(node.opacity, 4))
1700
+ : undefined,
1701
+ };
1702
+ return `<img${idAttr}${typeAttr}${nameAttr}${semanticAttrs} src="${escapeAttr(imageUrl)}" alt="${escapeAttr(node.name ?? "")}" style="${styleAttr(styles)}" />`;
1703
+ }
1704
+
1705
+ const isTextNode = node.type === "TEXT";
1706
+ const isEllipse = node.type === "ELLIPSE";
1707
+ const box2 = { width: box.width, height: box.height };
1708
+
1709
+ const fills = buildFills(
1710
+ node,
1711
+ node.fills,
1712
+ box2,
1713
+ options,
1714
+ tracker,
1715
+ isTextNode,
1716
+ );
1717
+ const strokeResult = buildStrokes(node, tracker);
1718
+ const effects = buildEffects(node, isTextNode, tracker);
1719
+ const cornerRadius = isEllipse ? "50%" : buildCornerRadius(node);
1720
+ const blendMode = buildBlendMode(node, tracker);
1721
+
1722
+ const boxShadowParts = [...effects.boxShadowLayers];
1723
+ if (strokeResult.insetShadow) boxShadowParts.push(strokeResult.insetShadow);
1724
+
1725
+ if (rotation !== undefined) {
1726
+ tracker.record(
1727
+ node,
1728
+ "approximated",
1729
+ `Rotation (${round(rotation, 2)}deg) reconstructed by pivoting the unrotated box about the absoluteBoundingBox center; exact only when Figma's internal pivot is also the shape's center.`,
1730
+ );
1731
+ }
1732
+
1733
+ const autoLayoutStyles = buildAutoLayoutStyles(node);
1734
+ const childSizingStyles = buildChildSizingStyles(node, parentLayoutMode);
1735
+ const hasAutoLayout = Boolean(autoLayoutStyles.display);
1736
+ // A node is positioned relative to its parent's free canvas (absolute,
1737
+ // left/top from absoluteBoundingBox) unless its *parent* is an auto-layout
1738
+ // container, in which case it's a normal flex item (relative, no left/top)
1739
+ // -- this mirrors Figma's own rule that auto-layout children give up
1740
+ // manual x/y in favor of flex flow.
1741
+ const isFlexChild =
1742
+ !isRoot && parentHasAutoLayout && node.layoutPositioning !== "ABSOLUTE";
1743
+
1744
+ const baseStyles: Record<string, string | undefined> = {
1745
+ position: isRoot ? "relative" : isFlexChild ? "relative" : "absolute",
1746
+ left: isRoot || isFlexChild ? undefined : px(box.left),
1747
+ top: isRoot || isFlexChild ? undefined : px(box.top),
1748
+ width: childSizingStyles.width ?? px(box.width),
1749
+ height: childSizingStyles.height ?? px(box.height),
1750
+ "background-color": fills.backgroundColor,
1751
+ "background-image": fills.backgroundImage,
1752
+ "background-size": fills.backgroundSize,
1753
+ "background-position": fills.backgroundPosition,
1754
+ "background-repeat": fills.backgroundRepeat,
1755
+ color: fills.color,
1756
+ "border-radius": cornerRadius,
1757
+ "box-shadow":
1758
+ boxShadowParts.length > 0 ? boxShadowParts.join(", ") : undefined,
1759
+ filter: effects.filter,
1760
+ "backdrop-filter": effects.backdropFilter,
1761
+ "-webkit-backdrop-filter": effects.backdropFilter,
1762
+ opacity:
1763
+ typeof node.opacity === "number" && node.opacity !== 1
1764
+ ? String(round(node.opacity, 4))
1765
+ : undefined,
1766
+ "mix-blend-mode": blendMode,
1767
+ overflow: node.clipsContent ? "hidden" : undefined,
1768
+ transform:
1769
+ rotation !== undefined ? `rotate(${round(-rotation, 3)}deg)` : undefined,
1770
+ "transform-origin": rotation !== undefined ? "center" : undefined,
1771
+ "min-width": px(node.minWidth ?? undefined),
1772
+ "max-width": px(node.maxWidth ?? undefined),
1773
+ "min-height": px(node.minHeight ?? undefined),
1774
+ "max-height": px(node.maxHeight ?? undefined),
1775
+ ...autoLayoutStyles,
1776
+ ...strokeResult.styles,
1777
+ ...childSizingStyles,
1778
+ };
1779
+
1780
+ if (isTextNode) {
1781
+ const style = node.style ?? {};
1782
+ baseStyles["font-family"] = style.fontFamily
1783
+ ? `"${style.fontFamily.replace(/"/g, "")}", sans-serif`
1784
+ : undefined;
1785
+ baseStyles["font-size"] = px(style.fontSize);
1786
+ baseStyles["font-weight"] =
1787
+ typeof style.fontWeight === "number"
1788
+ ? String(style.fontWeight)
1789
+ : undefined;
1790
+ baseStyles["font-style"] = style.italic ? "italic" : undefined;
1791
+ baseStyles["line-height"] = resolveLineHeight(style);
1792
+ baseStyles["letter-spacing"] =
1793
+ typeof style.letterSpacing === "number" && style.letterSpacing !== 0
1794
+ ? px(style.letterSpacing)
1795
+ : undefined;
1796
+ baseStyles["text-transform"] = textTransformCss(style.textCase);
1797
+ baseStyles["text-decoration"] = textDecorationCss(style.textDecoration);
1798
+ baseStyles["text-align"] = textAlignCss(style.textAlignHorizontal);
1799
+ if (style.textAutoResize === "TRUNCATE") {
1800
+ baseStyles["white-space"] = "nowrap";
1801
+ baseStyles.overflow = "hidden";
1802
+ baseStyles["text-overflow"] = "ellipsis";
1803
+ } else {
1804
+ // Figma preserves explicit newlines and repeated spaces. Normal HTML
1805
+ // whitespace collapsing changes both wrapping and measured geometry.
1806
+ baseStyles["white-space"] = "pre-wrap";
1807
+ }
1808
+ baseStyles.display = "flex";
1809
+ baseStyles["flex-direction"] = "column";
1810
+ baseStyles["justify-content"] = verticalAlignJustifyContent(
1811
+ style.textAlignVertical,
1812
+ );
1813
+ tracker.record(node, "exact", "Text styling mapped from TypeStyle fields.");
1814
+
1815
+ const characters = node.characters ?? "";
1816
+ const textHtml = buildMixedTextHtml(node, characters, tracker);
1817
+ return `<div${idAttr}${typeAttr}${nameAttr}${semanticAttrs} style="${styleAttr(baseStyles)}"><span>${textHtml}</span></div>`;
1818
+ }
1819
+
1820
+ tracker.record(
1821
+ node,
1822
+ "exact",
1823
+ "Position, size, fills, strokes, and effects mapped 1:1.",
1824
+ );
1825
+
1826
+ // hasAutoLayout guarantees node.layoutMode is "HORIZONTAL" or "VERTICAL"
1827
+ // (buildAutoLayoutStyles returns {} -- no `display` -- for "NONE"/"GRID").
1828
+ const childParentLayoutMode: "NONE" | "HORIZONTAL" | "VERTICAL" =
1829
+ hasAutoLayout ? (node.layoutMode as "HORIZONTAL" | "VERTICAL") : "NONE";
1830
+ const childrenHtml = (node.children ?? [])
1831
+ .map((child) =>
1832
+ buildNode(
1833
+ child,
1834
+ node.absoluteBoundingBox ?? null,
1835
+ childParentLayoutMode,
1836
+ options,
1837
+ tracker,
1838
+ false,
1839
+ ),
1840
+ )
1841
+ .filter(Boolean)
1842
+ .join("\n");
1843
+
1844
+ return `<div${idAttr}${typeAttr}${nameAttr}${semanticAttrs} style="${styleAttr(baseStyles)}">\n${childrenHtml}\n</div>`;
1845
+ }
1846
+
1847
+ /**
1848
+ * Map a Figma node (and its subtree) to an HTML fragment plus a fidelity
1849
+ * report describing which properties were exact, approximated, or rendered
1850
+ * as an image fallback.
1851
+ */
1852
+ export function mapFigmaNodeToHtml(
1853
+ node: FigmaNode,
1854
+ options: MapFigmaNodeOptions = {},
1855
+ ): MapFigmaNodeResult {
1856
+ assertFigmaNodeTreeComplexity(node);
1857
+ const tracker = new FidelityTracker();
1858
+ const html = buildNode(node, null, "NONE", options, tracker, true);
1859
+ return { html, fidelity: tracker.build() };
1860
+ }