@allbluecn/web-app 0.12.0 → 0.12.2

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 (1103) hide show
  1. package/package.json +85 -45
  2. package/public/devframe-docks/ai-chat-iframe.html +17 -0
  3. package/public/devframe-docks/session-iframe.html +17 -0
  4. package/public/fonts/Trap-font/Trap-Black.otf +0 -0
  5. package/public/fonts/Trap-font/Trap-Bold.otf +0 -0
  6. package/public/fonts/Trap-font/Trap-ExtraBold.otf +0 -0
  7. package/public/fonts/Trap-font/Trap-Light.otf +0 -0
  8. package/public/fonts/Trap-font/Trap-Medium.otf +0 -0
  9. package/public/fonts/Trap-font/Trap-Regular.otf +0 -0
  10. package/public/fonts/Trap-font/Trap-SemiBold.otf +0 -0
  11. package/public/fonts/buttersans-Rounded.otf +0 -0
  12. package/public/fonts/fonts.css +67 -0
  13. package/public/logo/allblue-logo-bold-dark.svg +11 -0
  14. package/public/logo/allblue-logo-bold-light.svg +11 -0
  15. package/public/logo/allblue-logo-dark.svg +13 -4
  16. package/public/logo/allblue-logo-light.svg +13 -4
  17. package/public/logo/allblue-logo-text-dark.svg +22 -0
  18. package/public/logo/allblue-logo-text-light.svg +22 -0
  19. package/public/logo/allblue-text-dark.svg +17 -0
  20. package/public/logo/allblue-text-light.svg +17 -0
  21. package/src/__tests__/security/ai/agui-body-validation.test.ts +96 -0
  22. package/src/__tests__/security/ai/destructive-tool-approval.test.ts +107 -0
  23. package/src/__tests__/security/ai/prompt-injection.test.ts +30 -17
  24. package/src/__tests__/security/ai/sandbox-network.test.ts +83 -0
  25. package/src/__tests__/security/ai/sandbox-snapshots.test.ts +92 -0
  26. package/src/__tests__/security/ai/sandbox-tool-bridge.test.ts +108 -0
  27. package/src/__tests__/security/ai/search-injection.test.ts +76 -0
  28. package/src/__tests__/security/ai/session-id-idor.test.ts +85 -0
  29. package/src/__tests__/setup.ts +16 -0
  30. package/src/components/agents/agent-bindings-tab.tsx +174 -0
  31. package/src/components/agents/agent-card.tsx +3 -7
  32. package/src/components/agents/agent-form-dialog.tsx +35 -13
  33. package/src/components/agents/agent-selector.tsx +1 -1
  34. package/src/components/agents/agents-page.tsx +33 -4
  35. package/src/components/agents/schemas/agent-form.ts +1 -1
  36. package/src/components/agents/skill-form-dialog.tsx +1 -1
  37. package/src/components/agents/slash-skill-menu.tsx +23 -16
  38. package/src/components/agents/use-agent-handlers.ts +1 -1
  39. package/src/components/ai/__tests__/ai-prompt-input-attach.test.tsx +115 -0
  40. package/src/components/ai/__tests__/global-sidebar.test.tsx +115 -0
  41. package/src/components/ai/__tests__/prompt-input-actions.test.tsx +72 -0
  42. package/src/components/ai/ai-chat-prompt.tsx +53 -21
  43. package/src/components/{chat → ai}/ai-prompt-input/components/action-buttons.tsx +80 -42
  44. package/src/components/{chat → ai}/ai-prompt-input/components/agent-mode-select.tsx +1 -1
  45. package/src/components/{chat → ai}/ai-prompt-input/components/kb-context-selector.tsx +3 -7
  46. package/src/components/{chat → ai}/ai-prompt-input/components/model-select.tsx +1 -1
  47. package/src/components/{chat → ai}/ai-prompt-input/components/page-user-context-selector.tsx +3 -7
  48. package/src/components/ai/ai-prompt-input/image-filter.ts +22 -0
  49. package/src/components/{chat → ai}/ai-prompt-input/index.tsx +203 -26
  50. package/src/components/ai/global-harness-sidebar.tsx +385 -0
  51. package/src/components/ai/tool-cards/-shared.tsx +150 -0
  52. package/src/components/ai/tool-cards/fallback-tool-card.tsx +144 -0
  53. package/src/components/{chat/ai-message/types.ts → ai/tool-cards/index.ts} +3 -8
  54. package/src/components/ai/tool-cards/knowledge-search-card.tsx +184 -0
  55. package/src/components/ai/tool-cards/web-search-card.tsx +177 -0
  56. package/src/components/ai/tool-parts/tool-call-part.tsx +95 -0
  57. package/src/components/ai/tool-parts/tool-result-part.tsx +95 -0
  58. package/src/components/ai/turn-folded-bar.tsx +75 -0
  59. package/src/components/anyhub/anyhub-app-card.tsx +3 -5
  60. package/src/components/anyhub/anyhub-install-dialog.tsx +1 -1
  61. package/src/components/anyhub/anyhub-marketplace-view.tsx +1 -1
  62. package/src/components/anyhub/anyhub-permission-panel.tsx +1 -1
  63. package/src/components/anyhub/anyhub-top-nav.tsx +9 -21
  64. package/src/components/billing/__tests__/seats-manager.test.tsx +1 -1
  65. package/src/components/billing/__tests__/use-resource.test.tsx +3 -0
  66. package/src/components/billing/checkout-redirect.ts +1 -1
  67. package/src/components/billing/login-prompt-dialog.tsx +1 -1
  68. package/src/components/billing/seats-manager.tsx +2 -4
  69. package/src/components/billing/subscription-provider.tsx +3 -0
  70. package/src/components/changelog/changelog-page.tsx +21 -8
  71. package/src/components/error/global-error-boundary.tsx +2 -4
  72. package/src/components/forms/app-combobox.tsx +2 -6
  73. package/src/components/forms/app-date-picker.tsx +2 -6
  74. package/src/components/forms/hooks/use-form-submit.ts +1 -1
  75. package/src/components/harness/__tests__/attachment-policy.test.ts +34 -0
  76. package/src/components/harness/__tests__/composer-prefill.test.ts +114 -0
  77. package/src/components/harness/__tests__/composer-send.test.tsx +53 -0
  78. package/src/components/harness/__tests__/dock-registry.test.ts +21 -0
  79. package/src/components/harness/__tests__/fuzzy.test.ts +17 -0
  80. package/src/components/harness/__tests__/gallery-behavior.test.tsx +171 -0
  81. package/src/components/harness/__tests__/harness-workbench-mount.test.ts +47 -0
  82. package/src/components/harness/__tests__/media-route.test.tsx +52 -0
  83. package/src/components/harness/__tests__/mention-resolvers.test.ts +41 -0
  84. package/src/components/harness/__tests__/message-actions.test.tsx +199 -0
  85. package/src/components/harness/__tests__/resource-uri.test.ts +53 -0
  86. package/src/components/harness/__tests__/submit-machine.test.ts +61 -0
  87. package/src/components/harness/__tests__/turn-group.test.ts +124 -0
  88. package/src/components/harness/__tests__/use-track-columns.test.ts +27 -0
  89. package/src/components/harness/agent-preset-picker.tsx +104 -0
  90. package/src/components/{chat → harness}/ai-chat-history/components/conversation-group.tsx +3 -0
  91. package/src/components/{chat → harness}/ai-chat-history/components/conversation-item.tsx +21 -7
  92. package/src/components/{chat → harness}/ai-chat-history/index.tsx +2 -0
  93. package/src/components/{chat → harness}/ai-chat-history/types.ts +2 -0
  94. package/src/components/harness/chat-ui.tsx +192 -0
  95. package/src/components/harness/code/changeset-panel.tsx +112 -0
  96. package/src/components/harness/code/code-workspace-sidebar.tsx +138 -0
  97. package/src/components/harness/code/file-tree.tsx +241 -0
  98. package/src/components/harness/code/preview-panel.tsx +169 -0
  99. package/src/components/harness/code/terminal-panel.tsx +90 -0
  100. package/src/components/harness/code/workspace-context.tsx +50 -0
  101. package/src/components/harness/code/workspace-picker.tsx +229 -0
  102. package/src/components/harness/composer/attachments/attachment-policy.ts +17 -0
  103. package/src/components/harness/composer/attachments/attachment-tray.tsx +72 -0
  104. package/src/components/harness/composer/attachments/use-attachments.ts +108 -0
  105. package/src/components/harness/composer/composer-editor.tsx +136 -0
  106. package/src/components/harness/composer/context-meter.tsx +106 -0
  107. package/src/components/harness/composer/fuzzy.ts +21 -0
  108. package/src/components/harness/composer/harness-composer.tsx +385 -0
  109. package/src/components/harness/composer/mention/mention-resolvers.ts +35 -0
  110. package/src/components/harness/composer/mention/mention-suggestion-menu.tsx +202 -0
  111. package/src/components/harness/composer/mention/use-mention-sources.ts +43 -0
  112. package/src/components/harness/composer/model-select.tsx +76 -0
  113. package/src/components/harness/composer/submit-machine.ts +38 -0
  114. package/src/components/harness/composer/use-composer-submit.ts +81 -0
  115. package/src/components/harness/composer/use-drafts.ts +25 -0
  116. package/src/components/harness/dock/dock-panel-container.tsx +110 -0
  117. package/src/components/harness/dock/dock-registry.ts +58 -0
  118. package/src/components/harness/dock/resource-preview.tsx +274 -0
  119. package/src/components/harness/dock/resource-uri.ts +44 -0
  120. package/src/components/harness/gallery/gallery-card.tsx +63 -0
  121. package/src/components/harness/gallery/gallery-grid.tsx +169 -0
  122. package/src/components/harness/gallery/gallery-types.ts +40 -0
  123. package/src/components/harness/gallery/lightbox-viewer.tsx +73 -0
  124. package/src/components/harness/gallery/types.ts +51 -0
  125. package/src/components/{devtools/index.ts → harness/harness-chat-contexts.ts} +5 -3
  126. package/src/components/harness/harness-chat-slots.ts +256 -0
  127. package/src/components/harness/harness-layout.tsx +258 -0
  128. package/src/components/harness/harness-message.tsx +207 -0
  129. package/src/components/harness/harness-workbench-mount.ts +30 -0
  130. package/src/components/harness/harness-workbench-page.tsx +467 -0
  131. package/src/components/harness/image-lightbox.tsx +51 -0
  132. package/src/components/harness/interrupt-approval.tsx +179 -0
  133. package/src/components/{chat/ai-message/components → harness}/message-actions.tsx +4 -8
  134. package/src/components/harness/plan-approval-card.tsx +101 -0
  135. package/src/components/harness/plugin-define-approval.tsx +125 -0
  136. package/src/components/harness/plugin-mention-menu.tsx +126 -0
  137. package/src/components/harness/plugin-panel.tsx +205 -0
  138. package/src/components/harness/queue-bar.tsx +78 -0
  139. package/src/components/harness/queue-item.tsx +69 -0
  140. package/src/components/harness/sandbox-file-change-card.tsx +135 -0
  141. package/src/components/harness/todo-panel.tsx +90 -0
  142. package/src/components/harness/transcript-width-handle.tsx +73 -0
  143. package/src/components/harness/turn-group.tsx +103 -0
  144. package/src/components/harness/turn-navigator.tsx +70 -0
  145. package/src/components/harness/turn-usage-pill.tsx +61 -0
  146. package/src/components/harness/use-todo-projection.ts +57 -0
  147. package/src/components/harness/workbench/use-track-columns.ts +69 -0
  148. package/src/components/harness/workbench/workbench-shell.tsx +102 -0
  149. package/src/components/hextaui/ai-chat-history.tsx +752 -0
  150. package/src/components/hextaui/ai-citations.tsx +579 -0
  151. package/src/components/hextaui/ai-error-handler.tsx +108 -0
  152. package/src/components/hextaui/ai-file-upload.tsx +575 -0
  153. package/src/components/hextaui/ai-message.tsx +639 -0
  154. package/src/components/hextaui/ai-prompt-input.tsx +782 -0
  155. package/src/components/hextaui/ai-suggested-prompts.tsx +586 -0
  156. package/src/components/hextaui/ai-thinking.tsx +291 -0
  157. package/src/components/hextaui/ai-usage-quota.tsx +501 -0
  158. package/src/components/hextaui/command-menu.tsx +0 -2
  159. package/src/components/iteration/auto-schedule-dialog.tsx +1 -1
  160. package/src/components/iteration/create-iteration-dialog.tsx +1 -1
  161. package/src/components/iteration/iteration-editor.tsx +3 -5
  162. package/src/components/knowledge/editor/doc-header.tsx +2 -4
  163. package/src/components/knowledge/editor/knowledge-doc-editor.tsx +32 -2
  164. package/src/components/knowledge/kb-filter-popover.tsx +2 -4
  165. package/src/components/knowledge/knowledge-toolbar.tsx +44 -27
  166. package/src/components/knowledge/knowledge-tree-item.tsx +12 -18
  167. package/src/components/knowledge/knowledge-tree.tsx +7 -7
  168. package/src/components/knowledge-public/bookmark-card.tsx +5 -11
  169. package/src/components/knowledge-public/bookmark-form-dialog.tsx +2 -2
  170. package/src/components/knowledge-public/knowledge-form-dialog.tsx +3 -3
  171. package/src/components/knowledge-public/legal-compliance-editor.tsx +3 -5
  172. package/src/components/knowledge-public/sharers-avatar-group.tsx +3 -7
  173. package/src/components/layout/sidebar-03/__tests__/user-menu-anonymous.test.tsx +1 -1
  174. package/src/components/layout/sidebar-03/app-sidebar.tsx +22 -10
  175. package/src/components/layout/sidebar-03/nav-anyhub.tsx +7 -21
  176. package/src/components/layout/sidebar-03/nav-knowledge.tsx +14 -40
  177. package/src/components/layout/sidebar-03/nav-main.tsx +11 -26
  178. package/src/components/layout/sidebar-03/nav-notifications.tsx +3 -7
  179. package/src/components/layout/sidebar-03/nav-secondary.tsx +11 -27
  180. package/src/components/layout/sidebar-03/nav-workspace.tsx +8 -32
  181. package/src/components/layout/sidebar-03/team-switcher.tsx +3 -7
  182. package/src/components/layout/sidebar-03/user-menu.tsx +3 -5
  183. package/src/components/notifications/settings-notifications.tsx +1 -1
  184. package/src/components/notifications/team-notifications.tsx +3 -7
  185. package/src/components/project/create-project-dialog.tsx +1 -1
  186. package/src/components/project/invite-member-dialog.tsx +1 -1
  187. package/src/components/project/project-member-manager.tsx +3 -5
  188. package/src/components/settings/ai/byok-section.tsx +162 -0
  189. package/src/components/settings/ai/create-custom-model-dialog.tsx +1 -1
  190. package/src/components/settings/ai/create-custom-provider-dialog.tsx +1 -1
  191. package/src/components/settings/ai/model-manager.tsx +1 -1
  192. package/src/components/settings/ai/provider-card.tsx +2 -2
  193. package/src/components/settings/ai/provider-detail-form.tsx +4 -6
  194. package/src/components/settings/ai/source/model-source-picker.tsx +99 -0
  195. package/src/components/settings/language-selector.tsx +2 -2
  196. package/src/components/settings/personal-team/account/account-client.tsx +1 -1
  197. package/src/components/settings/personal-team/account/avatar/notion-avatar-editor.tsx +12 -26
  198. package/src/components/settings/personal-team/account/settings-profile.tsx +1 -1
  199. package/src/components/settings/personal-team/team/team-client.tsx +1 -1
  200. package/src/components/settings/personal-team/team/team-invitations.tsx +19 -34
  201. package/src/components/settings/personal-team/team/team-member-list.tsx +5 -10
  202. package/src/components/shadcn-space/blocks/faq-01/faq.tsx +1 -1
  203. package/src/components/shadcn-space/blocks/hero-01/header.tsx +20 -3
  204. package/src/components/shared-kit/__tests__/ask-ai-entry-button.test.tsx +103 -0
  205. package/src/components/shared-kit/ask-ai-entry-button.tsx +80 -0
  206. package/src/components/shared-kit/data-viz/contribution-graph-tooltip.tsx +1 -1
  207. package/src/components/shared-kit/dialogs/name-confirm-dialog.tsx +4 -8
  208. package/src/components/shared-kit/i18n/language-switcher.tsx +2 -4
  209. package/src/components/shared-kit/icons/lucide-icon-picker/index.tsx +15 -13
  210. package/src/components/shared-kit/index.ts +1 -0
  211. package/src/components/shared-kit/navigation/nav-float-button.tsx +8 -16
  212. package/src/components/shared-kit/theme/theme-surface.tsx +1 -3
  213. package/src/components/shared-kit/timezone/timezone-select.tsx +3 -7
  214. package/src/components/story/ai/handlers/more-popover.tsx +3 -7
  215. package/src/components/story/ai/handlers/stream-text.ts +1 -1
  216. package/src/components/story/ai/prototype-dialog.tsx +1 -1
  217. package/src/components/story/ai/split-dialog.tsx +1 -1
  218. package/src/components/story/ai/story-ai-panel.tsx +5 -7
  219. package/src/components/story/ai/story-ai-preview-list.tsx +2 -2
  220. package/src/components/story/ai/story-ai-toolbar.tsx +6 -12
  221. package/src/components/story/create-story-dialog.tsx +3 -7
  222. package/src/components/story/detail/__tests__/associated-attachments-panel.test.tsx +1 -1
  223. package/src/components/story/detail/comment-input.tsx +1 -1
  224. package/src/components/story/detail/comment-item.tsx +3 -5
  225. package/src/components/story/detail/emoji-picker.tsx +1 -1
  226. package/src/components/story/detail/story-detail-body.tsx +9 -19
  227. package/src/components/story/detail/story-detail-toolbar/associated-attachments-panel.tsx +42 -63
  228. package/src/components/story/detail/story-detail-toolbar/categories.tsx +3 -7
  229. package/src/components/story/detail/story-detail-toolbar/children.tsx +13 -30
  230. package/src/components/story/detail/story-detail-toolbar/dependency-panel.tsx +8 -19
  231. package/src/components/story/detail/story-detail-toolbar.tsx +1 -1
  232. package/src/components/story/display/__tests__/display-dropdown.test.tsx +1 -1
  233. package/src/components/story/display/display-dropdown.tsx +3 -9
  234. package/src/components/story/filters/add-filter-dropdown.tsx +3 -3
  235. package/src/components/story/filters/filter-condition.tsx +3 -7
  236. package/src/components/story/filters/filter-toggle.tsx +3 -3
  237. package/src/components/story/filters/filter-value-input.tsx +4 -8
  238. package/src/components/story/inline-editors/__tests__/labels-editor.test.tsx +1 -1
  239. package/src/components/story/inline-editors/assignee-editor.tsx +4 -8
  240. package/src/components/story/inline-editors/dependency-type-select.tsx +26 -26
  241. package/src/components/story/inline-editors/inline-trigger.tsx +3 -9
  242. package/src/components/story/inline-editors/labels-editor.tsx +4 -6
  243. package/src/components/story/inline-editors/priority-editor.tsx +4 -8
  244. package/src/components/story/inline-editors/state-editor.tsx +4 -8
  245. package/src/components/story/inline-editors/story-select-dialog.tsx +12 -23
  246. package/src/components/story/peek-panel.tsx +1 -1
  247. package/src/components/story/relations/__tests__/attachment-manage-dialog.test.tsx +3 -3
  248. package/src/components/story/relations/__tests__/knowledge-select-dialog.test.tsx +5 -8
  249. package/src/components/story/relations/__tests__/link-manage-dialog.test.tsx +1 -1
  250. package/src/components/story/relations/attachment-manage-dialog.tsx +1 -1
  251. package/src/components/story/relations/knowledge-select-dialog.tsx +3 -2
  252. package/src/components/story/relations/link-manage-dialog.tsx +1 -1
  253. package/src/components/story/relations/story-ref-row.tsx +9 -19
  254. package/src/components/story/search-popover.tsx +15 -13
  255. package/src/components/story/story-list-view.tsx +1 -1
  256. package/src/components/story/story-panel-header.tsx +65 -35
  257. package/src/components/story/story-toolbar.tsx +4 -8
  258. package/src/components/story/transfer-story-popover.tsx +18 -14
  259. package/src/components/story/views/calendar-view.tsx +4 -8
  260. package/src/components/story/views/create-view-dialog.tsx +3 -7
  261. package/src/components/story/views/kanban-board.tsx +1 -1
  262. package/src/components/story/views/story-list/__tests__/batch-toolbar.test.tsx +3 -3
  263. package/src/components/story/views/story-list/batch-preview-dialog.tsx +12 -23
  264. package/src/components/story/views/story-list/batch-toolbar.tsx +7 -10
  265. package/src/components/story/views/story-list/group.tsx +2 -1
  266. package/src/components/story/views/story-list/index.tsx +1 -1
  267. package/src/components/story/views/story-list/row.tsx +1 -1
  268. package/src/components/story/views/timeline-view.tsx +1 -1
  269. package/src/components/story/views/view-list-section.tsx +3 -7
  270. package/src/components/story/views/view-selector-button.tsx +2 -4
  271. package/src/components/story/views/view-switcher.tsx +3 -7
  272. package/src/components/tiptap/extension/ai-extension.ts +21 -25
  273. package/src/components/tiptap/extension/ai-suggestion-mark.ts +45 -0
  274. package/src/components/tiptap/lib/advanced-utils.ts +0 -2
  275. package/src/components/tiptap/lib/utils/selection.ts +17 -0
  276. package/src/components/tiptap/mindmap/mind-map.tsx +26 -50
  277. package/src/components/tiptap/node/annotation-node/annotation-node-view.tsx +1 -1
  278. package/src/components/tiptap/notion-like/notion-like-editor-header.tsx +3 -7
  279. package/src/components/tiptap/notion-like/notion-like-editor.tsx +2 -0
  280. package/src/components/tiptap/ui/ai-ask-button/use-ai-ask.ts +5 -0
  281. package/src/components/tiptap/ui/ai-menu/ai-menu-actions/ai-menu-actions.tsx +1 -2
  282. package/src/components/tiptap/ui/ai-menu/ai-menu.tsx +94 -57
  283. package/src/components/tiptap/ui/drag-context-menu/drag-context-menu.tsx +2 -2
  284. package/src/components/ui/accordion.tsx +10 -37
  285. package/src/components/ui/alert-dialog.tsx +29 -60
  286. package/src/components/ui/alert.tsx +3 -21
  287. package/src/components/ui/avatar.tsx +5 -28
  288. package/src/components/ui/badge.tsx +19 -34
  289. package/src/components/ui/breadcrumb.tsx +20 -35
  290. package/src/components/ui/button-group.tsx +24 -37
  291. package/src/components/ui/button.tsx +14 -41
  292. package/src/components/ui/calendar.tsx +3 -19
  293. package/src/components/ui/card.tsx +5 -23
  294. package/src/components/ui/checkbox.tsx +8 -30
  295. package/src/components/ui/collapsible.tsx +6 -37
  296. package/src/components/ui/command.tsx +6 -20
  297. package/src/components/ui/context-menu.tsx +87 -97
  298. package/src/components/ui/dialog.tsx +31 -59
  299. package/src/components/ui/dropdown-menu.tsx +118 -139
  300. package/src/components/ui/empty.tsx +5 -23
  301. package/src/components/ui/field.tsx +8 -27
  302. package/src/components/ui/hover-card.tsx +30 -41
  303. package/src/components/ui/input-group.tsx +13 -26
  304. package/src/components/ui/input.tsx +4 -21
  305. package/src/components/ui/item.tsx +22 -34
  306. package/src/components/ui/kbd.tsx +13 -20
  307. package/src/components/ui/label.tsx +3 -25
  308. package/src/components/ui/marker.tsx +70 -0
  309. package/src/components/ui/message-scroller.tsx +131 -0
  310. package/src/components/ui/message.tsx +91 -0
  311. package/src/components/ui/navigation-menu.tsx +42 -56
  312. package/src/components/ui/popover.tsx +30 -47
  313. package/src/components/ui/progress.tsx +65 -33
  314. package/src/components/ui/questionnaire.tsx +322 -0
  315. package/src/components/ui/radio-group.tsx +12 -33
  316. package/src/components/ui/resizable.tsx +2 -22
  317. package/src/components/ui/scroll-area.tsx +8 -24
  318. package/src/components/ui/select.tsx +68 -77
  319. package/src/components/ui/separator.tsx +5 -26
  320. package/src/components/ui/sheet.tsx +29 -58
  321. package/src/components/ui/sidebar.tsx +143 -130
  322. package/src/components/ui/skeleton.tsx +1 -18
  323. package/src/components/ui/spinner.tsx +2 -20
  324. package/src/components/ui/switch.tsx +6 -23
  325. package/src/components/ui/table.tsx +1 -21
  326. package/src/components/ui/tabs.tsx +15 -42
  327. package/src/components/ui/textarea.tsx +2 -20
  328. package/src/components/ui/toast.tsx +282 -0
  329. package/src/components/ui/toggle.tsx +9 -31
  330. package/src/components/ui/tooltip.tsx +35 -42
  331. package/src/components/workspace/__tests__/kb/workspace-kb-card.test.tsx +4 -2
  332. package/src/components/workspace/__tests__/members/workspace-members-manager.test.tsx +1 -1
  333. package/src/components/workspace/dialogs/create-workspace-dialog.tsx +2 -4
  334. package/src/components/workspace/dialogs/delete-workspace-options.tsx +1 -1
  335. package/src/components/workspace/header/workspace-header.tsx +6 -12
  336. package/src/components/workspace/kb/workspace-kb-card.tsx +16 -38
  337. package/src/components/workspace/kb/workspace-kb-manage-dialog.tsx +1 -1
  338. package/src/components/workspace/kb/workspace-quick-doc-dialog.tsx +5 -7
  339. package/src/components/workspace/members/workspace-members-manager.tsx +4 -6
  340. package/src/config/sidebar-routes.tsx +5 -5
  341. package/src/devframe-docks/ai-chat-iframe.tsx +29 -0
  342. package/src/devframe-docks/session-iframe.tsx +86 -0
  343. package/src/hooks/use-commands.ts +1 -1
  344. package/src/hooks/use-mobile.ts +0 -17
  345. package/src/hooks/use-notifications.ts +1 -1
  346. package/src/lib/__tests__/annotation-prompt.test.ts +74 -0
  347. package/src/lib/__tests__/provider-router.test.ts +1 -1
  348. package/src/lib/__tests__/rag.test.ts +7 -3
  349. package/src/lib/ai/__tests__/chat-handoff.test.ts +19 -0
  350. package/src/lib/ai/__tests__/story-prompt.test.ts +42 -15
  351. package/src/lib/ai/byok.ts +32 -0
  352. package/src/lib/{chat-handoff.ts → ai/chat-handoff.ts} +48 -24
  353. package/src/lib/ai/story-ai-stream.ts +0 -1
  354. package/src/lib/ai/use-code-mode-readiness.ts +32 -0
  355. package/src/{components → lib}/ai/use-knowledge-bases.ts +2 -2
  356. package/src/lib/ai/use-search-capability.ts +78 -0
  357. package/src/{components → lib}/ai/use-selected-model.ts +1 -1
  358. package/src/lib/auth/auth.config.ts +44 -6
  359. package/src/lib/changelog/sdk-versions.ts +6 -6
  360. package/src/lib/commands/__tests__/registry.test.ts +1 -1
  361. package/src/lib/commands/registry.ts +2 -1
  362. package/src/lib/crypto/__tests__/base64.test.ts +78 -0
  363. package/src/lib/crypto/base64.ts +63 -0
  364. package/src/lib/fsap.ts +61 -0
  365. package/src/lib/optimistic/use-optimistic-mutation.ts +1 -1
  366. package/src/lib/plugin-runtime/bridge.ts +51 -0
  367. package/src/lib/plugin-runtime/plugin-client-tools.ts +115 -0
  368. package/src/lib/plugin-runtime/plugin-client.ts +161 -0
  369. package/src/lib/plugin-runtime/worker-realm-source.ts +172 -0
  370. package/src/lib/plugin-runtime/worker-realm.ts +225 -0
  371. package/src/lib/rag.ts +6 -4
  372. package/src/lib/router-context.ts +1 -0
  373. package/src/lib/session.ts +1 -0
  374. package/src/lib/utils.ts +1 -23
  375. package/src/lib/vector-store/__tests__/vector-store.test.ts +51 -2
  376. package/src/lib/vector-store/pg-vector-store.ts +6 -0
  377. package/src/lib/vector-store/sqlite-vec-store.ts +29 -12
  378. package/src/lib/vector-store/types.ts +1 -1
  379. package/src/paraglide/messages/_index.js +3728 -54071
  380. package/src/paraglide/messages/agents_agentform_setdefault2.js +30 -0
  381. package/src/paraglide/messages/agents_agentform_setdefaulthint3.js +30 -0
  382. package/src/paraglide/messages/agents_askai_advice1.js +30 -0
  383. package/src/paraglide/messages/agents_askai_advice_prompt1.js +30 -0
  384. package/src/paraglide/messages/agents_askai_skills1.js +30 -0
  385. package/src/paraglide/messages/agents_askai_skills_prompt1.js +30 -0
  386. package/src/paraglide/messages/agents_bindings_defaulttag1.js +30 -0
  387. package/src/paraglide/messages/agents_bindings_desc.js +29 -0
  388. package/src/paraglide/messages/agents_bindings_failed.js +29 -0
  389. package/src/paraglide/messages/agents_bindings_followdefault1.js +30 -0
  390. package/src/paraglide/messages/agents_bindings_loading.js +29 -0
  391. package/src/paraglide/messages/agents_bindings_noagents1.js +30 -0
  392. package/src/paraglide/messages/agents_bindings_saved.js +29 -0
  393. package/src/paraglide/messages/agents_bindings_title.js +29 -0
  394. package/src/paraglide/messages/agents_bindings_unbound.js +29 -0
  395. package/src/paraglide/messages/agents_page_tabs_bindings.js +29 -0
  396. package/src/paraglide/messages/agents_skills_menuhint1.js +30 -0
  397. package/src/paraglide/messages/apps_askai_checkup1.js +30 -0
  398. package/src/paraglide/messages/apps_askai_checkup_prompt1.js +30 -0
  399. package/src/paraglide/messages/apps_askai_integration1.js +30 -0
  400. package/src/paraglide/messages/apps_askai_integration_prompt1.js +30 -0
  401. package/src/paraglide/messages/chat_actions_codemode1.js +30 -0
  402. package/src/paraglide/messages/chat_actions_codemodeunavailable2.js +30 -0
  403. package/src/paraglide/messages/chat_actions_disablecodemode2.js +30 -0
  404. package/src/paraglide/messages/chat_actions_enablecodemode2.js +30 -0
  405. package/src/paraglide/messages/chat_actions_fork.js +29 -0
  406. package/src/paraglide/messages/chat_actions_moreactions1.js +30 -0
  407. package/src/paraglide/messages/chat_actions_stop.js +29 -0
  408. package/src/paraglide/messages/chat_actions_stopmessage1.js +30 -0
  409. package/src/paraglide/messages/chat_code_changeset.js +29 -0
  410. package/src/paraglide/messages/chat_code_clearterminal1.js +30 -0
  411. package/src/paraglide/messages/chat_code_filedetail1.js +30 -0
  412. package/src/paraglide/messages/chat_code_files.js +29 -0
  413. package/src/paraglide/messages/chat_code_loadingfiles1.js +30 -0
  414. package/src/paraglide/messages/chat_code_nochanges1.js +30 -0
  415. package/src/paraglide/messages/chat_code_nofiles1.js +30 -0
  416. package/src/paraglide/messages/chat_code_noterminal1.js +30 -0
  417. package/src/paraglide/messages/chat_code_preview.js +29 -0
  418. package/src/paraglide/messages/chat_code_previewempty1.js +30 -0
  419. package/src/paraglide/messages/chat_code_terminal.js +29 -0
  420. package/src/paraglide/messages/chat_code_terminalhelp1.js +30 -0
  421. package/src/paraglide/messages/chat_code_uploaderror1.js +30 -0
  422. package/src/paraglide/messages/chat_code_uploadsuccess1.js +30 -0
  423. package/src/paraglide/messages/chat_fork_at_message.js +29 -0
  424. package/src/paraglide/messages/chat_globalchat_draftrestored2.js +30 -0
  425. package/src/paraglide/messages/chat_globalchat_openinharness3.js +30 -0
  426. package/src/paraglide/messages/chat_prompt_input.js +29 -0
  427. package/src/paraglide/messages/chat_sandbox_created.js +29 -0
  428. package/src/paraglide/messages/chat_sandbox_filechanged1.js +30 -0
  429. package/src/paraglide/messages/chat_sandbox_filecreated1.js +30 -0
  430. package/src/paraglide/messages/chat_sandbox_filedeleted1.js +30 -0
  431. package/src/paraglide/messages/chat_sandbox_morechanges1.js +30 -0
  432. package/src/paraglide/messages/chat_sandbox_nodiff1.js +30 -0
  433. package/src/paraglide/messages/chat_sandbox_resumed.js +29 -0
  434. package/src/paraglide/messages/chat_searchunavailable1.js +30 -0
  435. package/src/paraglide/messages/chat_toolcall_error1.js +30 -0
  436. package/src/paraglide/messages/chat_toolcall_pending1.js +30 -0
  437. package/src/paraglide/messages/chat_toolcall_ready1.js +30 -0
  438. package/src/paraglide/messages/chat_toolresult_error1.js +30 -0
  439. package/src/paraglide/messages/chat_toolresult_running1.js +30 -0
  440. package/src/paraglide/messages/chat_toolresult_success1.js +30 -0
  441. package/src/paraglide/messages/chat_workspace_branch.js +29 -0
  442. package/src/paraglide/messages/chat_workspace_connectgithub1.js +30 -0
  443. package/src/paraglide/messages/chat_workspace_fsapunavailable1.js +30 -0
  444. package/src/paraglide/messages/chat_workspace_github.js +29 -0
  445. package/src/paraglide/messages/chat_workspace_githubconnect1.js +30 -0
  446. package/src/paraglide/messages/chat_workspace_local.js +29 -0
  447. package/src/paraglide/messages/chat_workspace_localhint1.js +30 -0
  448. package/src/paraglide/messages/chat_workspace_private.js +29 -0
  449. package/src/paraglide/messages/chat_workspace_selectbranch1.js +30 -0
  450. package/src/paraglide/messages/chat_workspace_selectfolder1.js +30 -0
  451. package/src/paraglide/messages/chat_workspace_selectfoldererror2.js +30 -0
  452. package/src/paraglide/messages/chat_workspace_selectrepo1.js +30 -0
  453. package/src/paraglide/messages/common_button_remove.js +29 -0
  454. package/src/paraglide/messages/common_changelog_sdkgroups_allblue_sdk1.js +3 -3
  455. package/src/paraglide/messages/common_changelog_sdkgroups_core_sdk1.js +2 -2
  456. package/src/paraglide/messages/common_changelog_sdkgroups_tanstack_sdk1.js +2 -2
  457. package/src/paraglide/messages/common_changelog_title.js +2 -2
  458. package/src/paraglide/messages/common_command_searchplaceholder1.js +2 -2
  459. package/src/paraglide/messages/common_nav_harness.js +29 -0
  460. package/src/paraglide/messages/composer_attach_button.js +29 -0
  461. package/src/paraglide/messages/composer_attach_imagesonly1.js +30 -0
  462. package/src/paraglide/messages/composer_attach_remove.js +29 -0
  463. package/src/paraglide/messages/dashboard_askai_overview1.js +30 -0
  464. package/src/paraglide/messages/dashboard_askai_overview_prompt1.js +30 -0
  465. package/src/paraglide/messages/dashboard_askai_todo1.js +30 -0
  466. package/src/paraglide/messages/dashboard_askai_todo_prompt1.js +30 -0
  467. package/src/paraglide/messages/editor_ai_image_not_supported.js +30 -0
  468. package/src/paraglide/messages/editor_ai_request_failed.js +30 -0
  469. package/src/paraglide/messages/gallery_attachfailed1.js +30 -0
  470. package/src/paraglide/messages/gallery_attachsuccess1.js +30 -0
  471. package/src/paraglide/messages/gallery_attachto1.js +30 -0
  472. package/src/paraglide/messages/gallery_attachtokb2.js +30 -0
  473. package/src/paraglide/messages/gallery_attachtoprd2.js +30 -0
  474. package/src/paraglide/messages/gallery_attachtostory2.js +30 -0
  475. package/src/paraglide/messages/gallery_bytes.js +29 -0
  476. package/src/paraglide/messages/gallery_close.js +29 -0
  477. package/src/paraglide/messages/gallery_copyerror1.js +30 -0
  478. package/src/paraglide/messages/gallery_copyprompt1.js +30 -0
  479. package/src/paraglide/messages/gallery_created.js +29 -0
  480. package/src/paraglide/messages/gallery_createvariant1.js +30 -0
  481. package/src/paraglide/messages/gallery_failed.js +29 -0
  482. package/src/paraglide/messages/gallery_image.js +29 -0
  483. package/src/paraglide/messages/gallery_linked.js +29 -0
  484. package/src/paraglide/messages/gallery_loaderror1.js +30 -0
  485. package/src/paraglide/messages/gallery_loading.js +29 -0
  486. package/src/paraglide/messages/gallery_loadmore1.js +30 -0
  487. package/src/paraglide/messages/gallery_model.js +29 -0
  488. package/src/paraglide/messages/gallery_next.js +29 -0
  489. package/src/paraglide/messages/gallery_noitems1.js +30 -0
  490. package/src/paraglide/messages/gallery_pickconfirm1.js +30 -0
  491. package/src/paraglide/messages/gallery_pickempty1.js +30 -0
  492. package/src/paraglide/messages/gallery_pickkb1.js +30 -0
  493. package/src/paraglide/messages/gallery_pickoptionsfailed2.js +30 -0
  494. package/src/paraglide/messages/gallery_pickprd1.js +30 -0
  495. package/src/paraglide/messages/gallery_pickstory1.js +30 -0
  496. package/src/paraglide/messages/gallery_preview.js +29 -0
  497. package/src/paraglide/messages/gallery_previewitem1.js +30 -0
  498. package/src/paraglide/messages/gallery_previous.js +29 -0
  499. package/src/paraglide/messages/gallery_prompt.js +29 -0
  500. package/src/paraglide/messages/gallery_prototype.js +29 -0
  501. package/src/paraglide/messages/gallery_provider.js +29 -0
  502. package/src/paraglide/messages/gallery_retry.js +29 -0
  503. package/src/paraglide/messages/gallery_size.js +29 -0
  504. package/src/paraglide/messages/gallery_speech.js +29 -0
  505. package/src/paraglide/messages/gallery_title.js +29 -0
  506. package/src/paraglide/messages/gallery_transcription.js +29 -0
  507. package/src/paraglide/messages/gallery_unsupported.js +29 -0
  508. package/src/paraglide/messages/gallery_varianterror1.js +30 -0
  509. package/src/paraglide/messages/gallery_video.js +29 -0
  510. package/src/paraglide/messages/harness_agent_default.js +29 -0
  511. package/src/paraglide/messages/harness_agent_mode.js +29 -0
  512. package/src/paraglide/messages/harness_approval_approveall1.js +30 -0
  513. package/src/paraglide/messages/harness_approval_cancelreject1.js +30 -0
  514. package/src/paraglide/messages/harness_approval_confirmreject1.js +30 -0
  515. package/src/paraglide/messages/harness_approval_rejectall1.js +30 -0
  516. package/src/paraglide/messages/harness_approval_rejectreason1.js +30 -0
  517. package/src/paraglide/messages/harness_approval_rejectreasonplaceholder2.js +30 -0
  518. package/src/paraglide/messages/harness_askai_cat_advice1.js +30 -0
  519. package/src/paraglide/messages/harness_askai_cat_analysis1.js +30 -0
  520. package/src/paraglide/messages/harness_askai_cat_general1.js +30 -0
  521. package/src/paraglide/messages/harness_askai_cat_skills1.js +30 -0
  522. package/src/paraglide/messages/harness_attach_file.js +29 -0
  523. package/src/paraglide/messages/harness_composer_arialabel1.js +30 -0
  524. package/src/paraglide/messages/harness_composer_pendingapproval1.js +30 -0
  525. package/src/paraglide/messages/harness_composer_placeholder.js +29 -0
  526. package/src/paraglide/messages/harness_composer_placeholderdefault1.js +30 -0
  527. package/src/paraglide/messages/harness_composer_placeholdernokey2.js +30 -0
  528. package/src/paraglide/messages/harness_composer_placeholderplan1.js +30 -0
  529. package/src/paraglide/messages/harness_composer_placeholderqueue1.js +30 -0
  530. package/src/paraglide/messages/harness_composer_placeholdersandboxreadonly2.js +30 -0
  531. package/src/paraglide/messages/harness_composer_queuelabel1.js +30 -0
  532. package/src/paraglide/messages/harness_composer_send.js +29 -0
  533. package/src/paraglide/messages/harness_composer_steerlabel1.js +30 -0
  534. package/src/paraglide/messages/harness_context_add.js +29 -0
  535. package/src/paraglide/messages/harness_context_meter_hint.js +29 -0
  536. package/src/paraglide/messages/harness_context_meter_label.js +29 -0
  537. package/src/paraglide/messages/harness_context_pages.js +29 -0
  538. package/src/paraglide/messages/harness_context_selected.js +29 -0
  539. package/src/paraglide/messages/harness_context_users.js +29 -0
  540. package/src/paraglide/messages/harness_conversation_fork.js +29 -0
  541. package/src/paraglide/messages/harness_conversation_pending.js +29 -0
  542. package/src/paraglide/messages/harness_dock_codeworkspace1.js +30 -0
  543. package/src/paraglide/messages/harness_dock_docnotfound2.js +30 -0
  544. package/src/paraglide/messages/harness_dock_fileempty1.js +30 -0
  545. package/src/paraglide/messages/harness_dock_loadingdoc1.js +30 -0
  546. package/src/paraglide/messages/harness_dock_loadingfile1.js +30 -0
  547. package/src/paraglide/messages/harness_dock_placeholder.js +29 -0
  548. package/src/paraglide/messages/harness_dock_plugin.js +29 -0
  549. package/src/paraglide/messages/harness_dock_prdnotfound2.js +30 -0
  550. package/src/paraglide/messages/harness_dock_storyempty1.js +30 -0
  551. package/src/paraglide/messages/harness_dock_storynotfound2.js +30 -0
  552. package/src/paraglide/messages/harness_dock_todo.js +29 -0
  553. package/src/paraglide/messages/harness_dock_unknownresource1.js +30 -0
  554. package/src/paraglide/messages/harness_media_code.js +29 -0
  555. package/src/paraglide/messages/harness_media_nocode1.js +30 -0
  556. package/src/paraglide/messages/harness_media_nospec1.js +30 -0
  557. package/src/paraglide/messages/harness_media_pro.js +29 -0
  558. package/src/paraglide/messages/harness_media_spec.js +29 -0
  559. package/src/paraglide/messages/harness_mention_kb_doc.js +29 -0
  560. package/src/paraglide/messages/harness_mention_prd.js +29 -0
  561. package/src/paraglide/messages/harness_model_select_default.js +29 -0
  562. package/src/paraglide/messages/harness_model_select_nomodels1.js +30 -0
  563. package/src/paraglide/messages/harness_plan_approve.js +29 -0
  564. package/src/paraglide/messages/harness_plan_feedbackplaceholder1.js +30 -0
  565. package/src/paraglide/messages/harness_plan_reject.js +29 -0
  566. package/src/paraglide/messages/harness_plan_title.js +29 -0
  567. package/src/paraglide/messages/harness_plugin_defineapprovaltitle2.js +30 -0
  568. package/src/paraglide/messages/harness_plugin_empty.js +29 -0
  569. package/src/paraglide/messages/harness_plugin_mentionempty1.js +30 -0
  570. package/src/paraglide/messages/harness_plugin_mentionnomatch2.js +30 -0
  571. package/src/paraglide/messages/harness_plugin_mentiontitle1.js +30 -0
  572. package/src/paraglide/messages/harness_plugin_paneltitle1.js +30 -0
  573. package/src/paraglide/messages/harness_plugin_status_defined.js +29 -0
  574. package/src/paraglide/messages/harness_plugin_status_error.js +29 -0
  575. package/src/paraglide/messages/harness_plugin_status_running.js +29 -0
  576. package/src/paraglide/messages/harness_plugin_status_stopped.js +29 -0
  577. package/src/paraglide/messages/harness_plugin_version.js +29 -0
  578. package/src/paraglide/messages/harness_queue_cancel.js +29 -0
  579. package/src/paraglide/messages/harness_queue_title.js +29 -0
  580. package/src/paraglide/messages/harness_queuedmultimedia1.js +30 -0
  581. package/src/paraglide/messages/harness_sandbox_full.js +29 -0
  582. package/src/paraglide/messages/harness_sandbox_pro.js +29 -0
  583. package/src/paraglide/messages/harness_sandbox_readonly.js +29 -0
  584. package/src/paraglide/messages/harness_sandbox_workspacewrite1.js +30 -0
  585. package/src/paraglide/messages/harness_spec_generatefailed1.js +30 -0
  586. package/src/paraglide/messages/harness_spec_needthread1.js +30 -0
  587. package/src/paraglide/messages/harness_steerhint1.js +30 -0
  588. package/src/paraglide/messages/harness_thinking_disable.js +29 -0
  589. package/src/paraglide/messages/harness_thinking_enable.js +29 -0
  590. package/src/paraglide/messages/harness_thinking_toggle.js +29 -0
  591. package/src/paraglide/messages/harness_todo_empty.js +29 -0
  592. package/src/paraglide/messages/harness_todo_paneltitle1.js +30 -0
  593. package/src/paraglide/messages/harness_tool_input.js +29 -0
  594. package/src/paraglide/messages/harness_tool_knowledgesearch1.js +30 -0
  595. package/src/paraglide/messages/harness_tool_output.js +29 -0
  596. package/src/paraglide/messages/harness_tool_resultcount1.js +30 -0
  597. package/src/paraglide/messages/harness_tool_websearch1.js +30 -0
  598. package/src/paraglide/messages/harness_turn_collapse.js +29 -0
  599. package/src/paraglide/messages/harness_turn_collapsearia1.js +30 -0
  600. package/src/paraglide/messages/harness_turn_expandaria1.js +30 -0
  601. package/src/paraglide/messages/harness_turn_navigator_label.js +29 -0
  602. package/src/paraglide/messages/harness_turn_replies.js +29 -0
  603. package/src/paraglide/messages/harness_turn_streaming.js +29 -0
  604. package/src/paraglide/messages/harness_turn_thoughtmoment1.js +30 -0
  605. package/src/paraglide/messages/harness_turn_thoughtmoment_aria1.js +30 -0
  606. package/src/paraglide/messages/harness_turn_tools.js +29 -0
  607. package/src/paraglide/messages/harness_turn_usage_label.js +29 -0
  608. package/src/paraglide/messages/harness_web_search_disable.js +29 -0
  609. package/src/paraglide/messages/harness_web_search_enable.js +29 -0
  610. package/src/paraglide/messages/harness_web_search_label.js +29 -0
  611. package/src/paraglide/messages/harness_web_search_toggle.js +29 -0
  612. package/src/paraglide/messages/knowledge_askai_button1.js +30 -0
  613. package/src/paraglide/messages/knowledge_askai_cat_all1.js +30 -0
  614. package/src/paraglide/messages/knowledge_askai_cat_graph1.js +30 -0
  615. package/src/paraglide/messages/knowledge_askai_cat_search1.js +30 -0
  616. package/src/paraglide/messages/knowledge_askai_cat_summary1.js +30 -0
  617. package/src/paraglide/messages/knowledge_askai_graph1.js +30 -0
  618. package/src/paraglide/messages/knowledge_askai_search1.js +30 -0
  619. package/src/paraglide/messages/knowledge_askai_summarize1.js +30 -0
  620. package/src/paraglide/messages/prd_askai_analyze1.js +30 -0
  621. package/src/paraglide/messages/prd_askai_button1.js +30 -0
  622. package/src/paraglide/messages/prd_askai_cat_all1.js +30 -0
  623. package/src/paraglide/messages/prd_askai_cat_analysis1.js +30 -0
  624. package/src/paraglide/messages/prd_askai_cat_design1.js +30 -0
  625. package/src/paraglide/messages/prd_askai_cat_extraction1.js +30 -0
  626. package/src/paraglide/messages/prd_askai_extract1.js +30 -0
  627. package/src/paraglide/messages/prd_askai_prototype1.js +30 -0
  628. package/src/paraglide/messages/settings_ai_byokdelete1.js +30 -0
  629. package/src/paraglide/messages/settings_ai_byokdescription1.js +30 -0
  630. package/src/paraglide/messages/settings_ai_byokhidekey2.js +30 -0
  631. package/src/paraglide/messages/settings_ai_byokhint1.js +30 -0
  632. package/src/paraglide/messages/settings_ai_byokplaceholder1.js +30 -0
  633. package/src/paraglide/messages/settings_ai_byoksave1.js +30 -0
  634. package/src/paraglide/messages/settings_ai_byokshowkey2.js +30 -0
  635. package/src/paraglide/messages/settings_ai_byokstateempty2.js +30 -0
  636. package/src/paraglide/messages/settings_ai_byokstatelocked2.js +30 -0
  637. package/src/paraglide/messages/settings_ai_byokstateset2.js +30 -0
  638. package/src/paraglide/messages/settings_ai_byoktitle1.js +30 -0
  639. package/src/paraglide/messages/settings_ai_hosted_desc.js +29 -0
  640. package/src/paraglide/messages/settings_ai_hosted_empty.js +29 -0
  641. package/src/paraglide/messages/settings_ai_hosted_quota.js +29 -0
  642. package/src/paraglide/messages/settings_ai_hosted_title.js +29 -0
  643. package/src/paraglide/messages/settings_ai_source_byok_desc.js +29 -0
  644. package/src/paraglide/messages/settings_ai_source_byok_tagmulti1.js +30 -0
  645. package/src/paraglide/messages/settings_ai_source_byok_tagurl1.js +30 -0
  646. package/src/paraglide/messages/settings_ai_source_byok_title.js +29 -0
  647. package/src/paraglide/messages/settings_ai_source_continue.js +29 -0
  648. package/src/paraglide/messages/settings_ai_source_current.js +29 -0
  649. package/src/paraglide/messages/settings_ai_source_hosted_desc.js +29 -0
  650. package/src/paraglide/messages/settings_ai_source_hosted_tagbilling1.js +30 -0
  651. package/src/paraglide/messages/settings_ai_source_hosted_tagnokey2.js +30 -0
  652. package/src/paraglide/messages/settings_ai_source_hosted_title.js +29 -0
  653. package/src/paraglide/messages/settings_ai_source_local_desc.js +29 -0
  654. package/src/paraglide/messages/settings_ai_source_local_needdesktop1.js +30 -0
  655. package/src/paraglide/messages/settings_ai_source_local_tagbyok1.js +30 -0
  656. package/src/paraglide/messages/settings_ai_source_local_taglocal1.js +30 -0
  657. package/src/paraglide/messages/settings_ai_source_local_title.js +29 -0
  658. package/src/paraglide/messages/settings_ai_source_title.js +29 -0
  659. package/src/paraglide/messages/story_askai_analyze1.js +30 -0
  660. package/src/paraglide/messages/story_askai_cat_all1.js +30 -0
  661. package/src/paraglide/messages/story_askai_cat_analysis1.js +30 -0
  662. package/src/paraglide/messages/story_askai_cat_refine1.js +30 -0
  663. package/src/paraglide/messages/story_askai_cat_test1.js +30 -0
  664. package/src/paraglide/messages/story_askai_refine1.js +30 -0
  665. package/src/paraglide/messages/story_askai_test1.js +30 -0
  666. package/src/paraglide/messages/story_panel_askai1.js +30 -0
  667. package/src/paraglide/messages/workspaces_askai_overview1.js +30 -0
  668. package/src/paraglide/messages/workspaces_askai_overview_prompt1.js +30 -0
  669. package/src/paraglide/messages/workspaces_askai_seats1.js +30 -0
  670. package/src/paraglide/messages/workspaces_askai_seats_prompt1.js +30 -0
  671. package/src/plugins/core/inspiration/ui.tsx +2 -4
  672. package/src/plugins/core/prd/components/agent-input.tsx +5 -11
  673. package/src/plugins/core/prd/components/component-editor/content-section.tsx +1 -1
  674. package/src/plugins/core/prd/components/component-editor/style-fields.tsx +1 -1
  675. package/src/plugins/core/prd/components/dialog/prd-detail-client.tsx +3 -7
  676. package/src/plugins/core/prd/components/page-version-panel.tsx +23 -43
  677. package/src/plugins/core/prd/components/page-version-tree.tsx +6 -14
  678. package/src/plugins/core/prd/components/prd-agent-panel.tsx +3 -5
  679. package/src/plugins/core/prd/components/prd-comment-review-panel.tsx +2 -4
  680. package/src/plugins/core/prd/components/prd-doc-panel.tsx +6 -14
  681. package/src/plugins/core/prd/components/prd-editor-layout.tsx +1 -1
  682. package/src/plugins/core/prd/components/prd-left-sidebar.tsx +5 -11
  683. package/src/plugins/core/prd/components/prd-navigation.tsx +41 -11
  684. package/src/plugins/core/prd/components/prd-prototype-panel.tsx +9 -21
  685. package/src/plugins/core/prd/components/prd-right-sidebar.tsx +7 -15
  686. package/src/plugins/core/prd/components/prd-share-panel/components/single-version-share-card.tsx +13 -27
  687. package/src/plugins/core/prd/components/prd-share-panel.tsx +8 -14
  688. package/src/plugins/core/prd/components/prd-tree-page-tab.tsx +9 -21
  689. package/src/plugins/core/prd/components/share/share-comment-panel.tsx +1 -1
  690. package/src/plugins/core/prd/components/share/share-nav-bar.tsx +3 -7
  691. package/src/plugins/core/prd/components/share/share-password-gate.tsx +1 -1
  692. package/src/plugins/core/prd/components/share/share-review-panel.tsx +1 -1
  693. package/src/plugins/core/prd/lib/ai/annotation-prompt.ts +9 -14
  694. package/src/plugins/core/prd/pages/prd-detail-page.tsx +2 -6
  695. package/src/plugins/core/prd/prd-nav.tsx +4 -8
  696. package/src/plugins/core/prd/serverFns/ai/fill-annotation.ts +2 -2
  697. package/src/plugins/core/prd/serverFns/ai/generate-prototype.ts +12 -64
  698. package/src/{server/serverFns/ai/detect.ts → plugins/core/prd/serverFns/ai/hosted-models.ts} +10 -13
  699. package/src/plugins/core/prd/serverFns/ai/source-mode.ts +51 -0
  700. package/src/plugins/core/server/api-key-cipher.ts +6 -4
  701. package/src/plugins/core/tags/nav-tag.tsx +9 -24
  702. package/src/plugins/core/tags/tag-manager.tsx +1 -1
  703. package/src/plugins/core/tags/tag-selector.tsx +3 -7
  704. package/src/providers/index.tsx +1 -1
  705. package/src/routeTree.gen.ts +293 -54
  706. package/src/routes/__desktop/onboarding/route.lazy.tsx +1 -1
  707. package/src/routes/__root.tsx +4 -8
  708. package/src/routes/__tests__/-edition-routing.test.tsx +6 -4
  709. package/src/routes/__tests__/route-tree-structure.test.ts +10 -1
  710. package/src/routes/_login/changelog/confirm/route.lazy.tsx +10 -10
  711. package/src/routes/_login/email-unsubscribe/route.lazy.tsx +11 -11
  712. package/src/routes/_login/forgot-password/route.lazy.tsx +1 -1
  713. package/src/routes/_login/login/route.lazy.tsx +1 -1
  714. package/src/routes/_login/register/route.lazy.tsx +1 -1
  715. package/src/routes/_login/reset-password/route.lazy.tsx +1 -1
  716. package/src/routes/_login/verify-email/route.lazy.tsx +6 -6
  717. package/src/routes/_nav/apps/anyhub/$id/route.lazy.tsx +54 -0
  718. package/src/routes/_nav/apps/anyhub/$id/route.tsx +1 -8
  719. package/src/routes/_nav/apps/anyhub/route.tsx +29 -3
  720. package/src/routes/_nav/chat.$threadId.tsx +24 -0
  721. package/src/routes/_nav/chat.tsx +31 -0
  722. package/src/routes/_nav/dashboard/route.lazy.tsx +18 -1
  723. package/src/routes/_nav/harness/$threadId.lazy.tsx +28 -0
  724. package/src/routes/_nav/{chat → harness}/$threadId.tsx +2 -7
  725. package/src/routes/_nav/harness/gallery/route.lazy.tsx +33 -0
  726. package/src/{components/chat/ai-message.tsx → routes/_nav/harness/gallery/route.tsx} +3 -2
  727. package/src/routes/_nav/harness/route.lazy.tsx +28 -0
  728. package/src/routes/_nav/{chat → harness}/route.tsx +1 -1
  729. package/src/routes/_nav/knowledge/bookmarks/$id.lazy.tsx +2 -2
  730. package/src/routes/_nav/knowledge/bookmarks/index.lazy.tsx +1 -1
  731. package/src/routes/_nav/knowledge/compliance/$id.lazy.tsx +14 -30
  732. package/src/routes/_nav/knowledge/dictionaries/$id.lazy.tsx +1 -1
  733. package/src/routes/_nav/knowledge/index.lazy.tsx +2 -8
  734. package/src/routes/_nav/knowledge/laws/$id.lazy.tsx +14 -30
  735. package/src/routes/_nav/projects/$projectId/$storyId/route.lazy.tsx +3 -5
  736. package/src/routes/_nav/projects/$projectId/index.lazy.tsx +8 -18
  737. package/src/routes/_nav/projects/$projectId/iterations/$iterationId/route.lazy.tsx +4 -8
  738. package/src/routes/_nav/projects/$projectId/settings/route.lazy.tsx +4 -6
  739. package/src/routes/_nav/route.lazy.tsx +10 -2
  740. package/src/routes/_nav/route.tsx +3 -8
  741. package/src/routes/_nav/settings/ai/$providerId/route.tsx +3 -16
  742. package/src/routes/_nav/settings/ai/hosted/route.lazy.tsx +55 -0
  743. package/src/routes/_nav/settings/ai/hosted/route.tsx +26 -0
  744. package/src/routes/_nav/settings/ai/index/route.lazy.tsx +59 -25
  745. package/src/routes/_nav/settings/ai/{$providerId → providers/$providerId}/route.lazy.tsx +1 -1
  746. package/src/routes/_nav/settings/ai/providers/$providerId/route.tsx +37 -0
  747. package/src/routes/_nav/settings/ai/providers/index/route.lazy.tsx +43 -0
  748. package/src/routes/_nav/settings/ai/route.tsx +6 -3
  749. package/src/routes/_nav/settings/billing/route.lazy.tsx +1 -1
  750. package/src/routes/_nav/settings/design/route.lazy.tsx +3 -5
  751. package/src/routes/_nav/settings/general/route.lazy.tsx +1 -1
  752. package/src/routes/_nav/settings/privacy/route.lazy.tsx +3 -5
  753. package/src/routes/_nav/settings/route.tsx +2 -6
  754. package/src/routes/_nav/workspaces/$workspaceId/activities/route.lazy.tsx +3 -5
  755. package/src/routes/_nav/workspaces/$workspaceId/settings/route.lazy.tsx +4 -6
  756. package/src/routes/_nav/workspaces/index.lazy.tsx +34 -17
  757. package/src/routes/api/chat.ts +42 -22
  758. package/src/routes/api/cron/ai-run-reaper.ts +80 -0
  759. package/src/routes/api/devframe/__tests__/auth-trace.test.ts +18 -0
  760. package/src/routes/api/devframe/__tests__/bundle-stats.test.ts +18 -0
  761. package/src/routes/api/devframe/__tests__/entitlements.test.ts +20 -0
  762. package/src/routes/api/devframe/__tests__/hydration-probe.test.ts +16 -0
  763. package/src/routes/api/devframe/auth-trace.ts +39 -0
  764. package/src/routes/api/devframe/bundle-stats.ts +73 -0
  765. package/src/routes/api/devframe/entitlements.ts +19 -0
  766. package/src/routes/api/devframe/hydration-probe.ts +30 -0
  767. package/src/routes/invite/$token/route.lazy.tsx +1 -1
  768. package/src/routes/server.ai-stream.ts +34 -19
  769. package/src/routes/share/compliance/$id/route.lazy.tsx +4 -6
  770. package/src/routes/share/law/$id/route.lazy.tsx +4 -6
  771. package/src/server/__tests__/agent-client-graph.test.ts +2 -2
  772. package/src/server/__tests__/chat-agent-resolve.test.ts +1 -1
  773. package/src/server/__tests__/chat-conversations.test.ts +5 -0
  774. package/src/server/__tests__/entitlements.test.ts +99 -1
  775. package/src/server/__tests__/resource-registry.test.ts +12 -2
  776. package/src/server/__tests__/resources.agents.test.ts +2 -1
  777. package/src/server/__tests__/resources.license.test.ts +2 -1
  778. package/src/server/__tests__/resources.test.ts +2 -1
  779. package/src/server/__tests__/sandbox-entitlement.test.ts +169 -0
  780. package/src/server/ai-gateway/__tests__/adapter-temperature.test.ts +104 -0
  781. package/src/server/ai-gateway/__tests__/agent-runtime.test.ts +334 -0
  782. package/src/server/ai-gateway/__tests__/chat-handler-prompt-key.test.ts +244 -0
  783. package/src/server/ai-gateway/__tests__/chat-prompt-key-drift.test.ts +96 -0
  784. package/src/server/ai-gateway/__tests__/chat-stream-builder-code-mode.test.ts +215 -0
  785. package/src/server/ai-gateway/__tests__/chat-stream-builder-memory.test.ts +179 -0
  786. package/src/server/ai-gateway/__tests__/chat-stream-builder-sandbox.test.ts +211 -0
  787. package/src/server/ai-gateway/__tests__/chat-stream-builder-skills.test.ts +126 -0
  788. package/src/server/ai-gateway/__tests__/code-mode-integration-smoke.test.ts +178 -0
  789. package/src/server/ai-gateway/__tests__/code-mode-stack.test.ts +390 -0
  790. package/src/server/ai-gateway/__tests__/compaction.test.ts +509 -0
  791. package/src/server/ai-gateway/__tests__/conformance.test.ts +45 -13
  792. package/src/server/ai-gateway/__tests__/env-key.test.ts +175 -0
  793. package/src/server/ai-gateway/__tests__/interrupt-store.test.ts +19 -4
  794. package/src/server/ai-gateway/__tests__/kb-context-guard.test.ts +24 -16
  795. package/src/server/ai-gateway/__tests__/knowledge-search-fence.test.ts +7 -0
  796. package/src/server/ai-gateway/__tests__/label-suggest.test.ts +22 -5
  797. package/src/server/ai-gateway/__tests__/message-store.test.ts +14 -9
  798. package/src/server/ai-gateway/__tests__/pgvector-memory-adapter.test.ts +422 -0
  799. package/src/server/ai-gateway/__tests__/plugin-lifecycle.test.ts +57 -0
  800. package/src/server/ai-gateway/__tests__/prompt-builtin.test.ts +273 -0
  801. package/src/server/ai-gateway/__tests__/prompt-registry.test.ts +549 -0
  802. package/src/server/ai-gateway/__tests__/prompt-vars-contract.test.ts +146 -0
  803. package/src/server/ai-gateway/__tests__/provider-adapter.test.ts +164 -0
  804. package/src/server/ai-gateway/__tests__/run-store-durable.test.ts +151 -0
  805. package/src/server/ai-gateway/__tests__/run-store.test.ts +90 -0
  806. package/src/server/ai-gateway/__tests__/runtime.test.ts +1 -1
  807. package/src/server/ai-gateway/__tests__/skills-source.test.ts +306 -0
  808. package/src/server/ai-gateway/__tests__/snippets.test.ts +328 -0
  809. package/src/server/ai-gateway/__tests__/source-mode.test.ts +77 -0
  810. package/src/server/ai-gateway/__tests__/story-prompt.test.ts +75 -11
  811. package/src/server/ai-gateway/__tests__/todo-plan-tools.test.ts +435 -0
  812. package/src/server/ai-gateway/__tests__/tool-registry.test.ts +182 -0
  813. package/src/server/ai-gateway/__tests__/tools-select.test.ts +32 -6
  814. package/src/server/ai-gateway/__tests__/unified-router.test.ts +107 -1
  815. package/src/server/ai-gateway/__tests__/usage-log.test.ts +192 -0
  816. package/src/server/ai-gateway/__tests__/vm-driver.test.ts +193 -0
  817. package/src/server/ai-gateway/adapter.ts +60 -3
  818. package/src/server/ai-gateway/byok.ts +144 -0
  819. package/src/server/ai-gateway/chat-handler.ts +275 -45
  820. package/src/server/ai-gateway/chat-stream-builder.ts +177 -14
  821. package/src/server/ai-gateway/code-mode/index.ts +236 -0
  822. package/src/server/ai-gateway/code-mode/sandbox.ts +213 -0
  823. package/src/server/ai-gateway/code-mode/snippets.ts +235 -0
  824. package/src/server/ai-gateway/code-mode/vm-driver.ts +197 -0
  825. package/src/server/ai-gateway/connectivity-check.ts +3 -1
  826. package/src/server/ai-gateway/durability/__tests__/pg-stream.test.ts +343 -0
  827. package/src/server/ai-gateway/durability/__tests__/reaper-drive.test.ts +154 -0
  828. package/src/server/ai-gateway/durability/__tests__/reaper-lazy.test.ts +145 -0
  829. package/src/server/ai-gateway/durability/__tests__/reaper-real-db.test.ts +315 -0
  830. package/src/server/ai-gateway/durability/__tests__/reaper.test.ts +227 -0
  831. package/src/server/ai-gateway/durability/pg-stream.ts +355 -0
  832. package/src/server/ai-gateway/durability/reaper-driver.ts +80 -0
  833. package/src/server/ai-gateway/durability/reaper-lazy.ts +97 -0
  834. package/src/server/ai-gateway/durability/reaper.ts +130 -0
  835. package/src/server/ai-gateway/embedding.ts +8 -4
  836. package/src/server/ai-gateway/env-key.ts +33 -0
  837. package/src/server/ai-gateway/index.ts +52 -2
  838. package/src/server/ai-gateway/kb-context-guard.ts +7 -7
  839. package/src/server/ai-gateway/knowledge-index-core.ts +14 -0
  840. package/src/server/ai-gateway/label-suggest.ts +23 -18
  841. package/src/server/ai-gateway/locks/__tests__/pg-lock.test.ts +133 -0
  842. package/src/server/ai-gateway/locks/pg-lock.ts +111 -0
  843. package/src/server/ai-gateway/media/__tests__/generation.spec.ts +52 -0
  844. package/src/server/ai-gateway/media/__tests__/index.test.ts +116 -0
  845. package/src/server/ai-gateway/media/__tests__/prototype-schema.spec.ts +36 -0
  846. package/src/server/ai-gateway/media/adapters.ts +128 -0
  847. package/src/server/ai-gateway/media/index.ts +231 -0
  848. package/src/server/ai-gateway/media/prototype-schema.ts +75 -0
  849. package/src/server/ai-gateway/media/recorder.ts +73 -0
  850. package/src/server/ai-gateway/memory/index.ts +76 -0
  851. package/src/server/ai-gateway/memory/pgvector-adapter.ts +243 -0
  852. package/src/server/ai-gateway/memory/scope.ts +54 -0
  853. package/src/server/ai-gateway/middlewares/compaction.ts +232 -0
  854. package/src/server/ai-gateway/middlewares/index.ts +11 -1
  855. package/src/server/ai-gateway/middlewares/logger.ts +4 -4
  856. package/src/server/ai-gateway/middlewares/plan-approval.ts +125 -0
  857. package/src/server/ai-gateway/middlewares/rate-limit.ts +4 -4
  858. package/src/server/ai-gateway/middlewares/tool-budget.ts +50 -0
  859. package/src/server/ai-gateway/middlewares/usage-log.ts +158 -0
  860. package/src/server/ai-gateway/model-fetch.ts +4 -2
  861. package/src/server/ai-gateway/persistence/index.ts +4 -2
  862. package/src/server/ai-gateway/persistence/interrupt-store.ts +78 -16
  863. package/src/server/ai-gateway/persistence/message-store.ts +35 -36
  864. package/src/server/ai-gateway/persistence/metadata-store.ts +62 -0
  865. package/src/server/ai-gateway/persistence/run-store.ts +67 -21
  866. package/src/server/ai-gateway/ports.ts +3 -1
  867. package/src/server/ai-gateway/prompts/builtin.ts +327 -0
  868. package/src/server/ai-gateway/prompts/definitions.ts +36 -0
  869. package/src/server/ai-gateway/prompts/index.ts +41 -0
  870. package/src/server/ai-gateway/prompts/registry.ts +248 -0
  871. package/src/server/ai-gateway/prompts/seed.ts +54 -0
  872. package/src/server/ai-gateway/prompts/types.ts +40 -0
  873. package/src/server/ai-gateway/rerank.ts +2 -1
  874. package/src/server/ai-gateway/runs/agent-runtime.ts +176 -0
  875. package/src/server/ai-gateway/runs/biz-keys.ts +54 -0
  876. package/src/server/{serverFns/agents → ai-gateway/runs}/resolve-overrides.ts +2 -8
  877. package/src/server/ai-gateway/sandbox/__tests__/harness-sandbox.test.ts +170 -0
  878. package/src/server/ai-gateway/sandbox/__tests__/instance-store.test.ts +130 -0
  879. package/src/server/ai-gateway/sandbox/__tests__/local-process.test.ts +316 -0
  880. package/src/server/ai-gateway/sandbox/__tests__/policy.test.ts +157 -0
  881. package/src/server/ai-gateway/sandbox/__tests__/provider.test.ts +102 -0
  882. package/src/server/ai-gateway/sandbox/__tests__/tool-bridge.test.ts +112 -0
  883. package/src/server/ai-gateway/sandbox/entitlement.ts +51 -0
  884. package/src/server/ai-gateway/sandbox/harness-sandbox.ts +345 -0
  885. package/src/server/ai-gateway/sandbox/instance-store.ts +91 -0
  886. package/src/server/ai-gateway/sandbox/local-process.ts +329 -0
  887. package/src/server/ai-gateway/sandbox/policy-levels.ts +3 -0
  888. package/src/server/ai-gateway/sandbox/policy.ts +267 -0
  889. package/src/server/ai-gateway/sandbox/provider.ts +128 -0
  890. package/src/server/ai-gateway/sandbox/tool-bridge.ts +78 -0
  891. package/src/server/ai-gateway/skills/builtin/competitive-analysis/SKILL.md +40 -0
  892. package/src/server/ai-gateway/skills/builtin/competitive-analysis/references/matrix-template.md +37 -0
  893. package/src/server/ai-gateway/skills/builtin/naming-advisor/SKILL.md +43 -0
  894. package/src/server/ai-gateway/skills/builtin/prd-review/SKILL.md +29 -0
  895. package/src/server/ai-gateway/skills/builtin/prd-review/references/review-checklist.md +46 -0
  896. package/src/server/ai-gateway/skills/builtin-source.ts +115 -0
  897. package/src/server/ai-gateway/skills/governance.ts +87 -0
  898. package/src/server/ai-gateway/skills/index.ts +137 -0
  899. package/src/server/ai-gateway/skills/user-source.ts +109 -0
  900. package/src/server/ai-gateway/source-mode.ts +62 -0
  901. package/src/server/ai-gateway/story-handler.ts +27 -21
  902. package/src/server/ai-gateway/story-prompt.ts +16 -25
  903. package/src/server/ai-gateway/tools/create-pr.ts +296 -0
  904. package/src/server/ai-gateway/tools/delegate-task.ts +91 -0
  905. package/src/server/ai-gateway/tools/delete-project.ts +3 -0
  906. package/src/server/ai-gateway/tools/index.ts +15 -0
  907. package/src/server/ai-gateway/tools/keys.ts +42 -0
  908. package/src/server/ai-gateway/tools/plan-submit.ts +113 -0
  909. package/src/server/ai-gateway/tools/plugin-lifecycle-defs.ts +122 -0
  910. package/src/server/ai-gateway/tools/plugin-lifecycle-server.ts +160 -0
  911. package/src/server/ai-gateway/tools/plugin-tools.ts +57 -0
  912. package/src/server/ai-gateway/tools/projection-namespace.ts +28 -0
  913. package/src/server/ai-gateway/tools/registry.ts +101 -0
  914. package/src/server/ai-gateway/tools/select.ts +70 -11
  915. package/src/server/ai-gateway/tools/server.ts +4 -2
  916. package/src/server/ai-gateway/tools/todo-write.ts +78 -0
  917. package/src/server/ai-gateway/types.ts +16 -0
  918. package/src/server/ai-gateway/unified-router.ts +99 -9
  919. package/src/server/ai-ports.ts +7 -3
  920. package/src/server/entitlements-token.ts +3 -15
  921. package/src/server/entitlements.ts +9 -0
  922. package/src/server/middlewares/security-headers.ts +60 -40
  923. package/src/server/resources.ts +54 -0
  924. package/src/server/serverFns/__tests__/ai-hosted-models.test.ts +68 -0
  925. package/src/server/serverFns/__tests__/ai-source-mode.test.ts +119 -0
  926. package/src/server/serverFns/__tests__/harness-plugins.test.ts +140 -0
  927. package/src/server/serverFns/__tests__/knowledge-index.test.ts +42 -4
  928. package/src/server/serverFns/__tests__/knowledge-search.test.ts +262 -0
  929. package/src/server/serverFns/activity.ts +1 -1
  930. package/src/server/serverFns/agents/agent-crud.ts +8 -1
  931. package/src/server/serverFns/agents/bindings.ts +113 -0
  932. package/src/server/serverFns/agents/skill-crud.ts +5 -1
  933. package/src/server/serverFns/ai/code-mode-readiness.ts +23 -0
  934. package/src/server/serverFns/ai/hosted-models.ts +1 -0
  935. package/src/server/serverFns/ai/search-capability.ts +23 -0
  936. package/src/server/serverFns/ai/source-mode.ts +1 -0
  937. package/src/server/serverFns/anyhub/app.ts +3 -1
  938. package/src/server/serverFns/anyhub/index.ts +3 -1
  939. package/src/server/serverFns/anyhub/install.ts +1 -1
  940. package/src/server/serverFns/anyhub/proxy.ts +1 -1
  941. package/src/server/serverFns/auth/email-verification.ts +3 -1
  942. package/src/server/serverFns/auth/forgot-password.ts +1 -1
  943. package/src/server/serverFns/auth/register.ts +2 -1
  944. package/src/server/serverFns/auth/reset-password.ts +2 -1
  945. package/src/server/serverFns/auth/setup.ts +1 -1
  946. package/src/server/serverFns/billing.ts +8 -1
  947. package/src/server/serverFns/changelog/fetch.ts +1 -1
  948. package/src/server/serverFns/changelog/subscribe.ts +2 -1
  949. package/src/server/serverFns/chat/conversations.ts +78 -1
  950. package/src/server/serverFns/chat/list-messages.ts +1 -1
  951. package/src/server/serverFns/design/settings.ts +3 -1
  952. package/src/server/serverFns/design.ts +4 -1
  953. package/src/server/serverFns/email-unsubscribe.ts +1 -1
  954. package/src/server/serverFns/harness/__tests__/attach-guards.spec.ts +45 -0
  955. package/src/server/serverFns/harness/__tests__/attach-prototype.spec.ts +69 -0
  956. package/src/server/serverFns/harness/__tests__/attach-to-kb.spec.ts +86 -0
  957. package/src/server/serverFns/harness/__tests__/attach-to-story.spec.ts +90 -0
  958. package/src/server/serverFns/harness/__tests__/cancel-run.test.ts +146 -0
  959. package/src/server/serverFns/harness/__tests__/gallery.spec.ts +126 -0
  960. package/src/server/serverFns/harness/__tests__/media-prototype.spec.ts +67 -0
  961. package/src/server/serverFns/harness/__tests__/media.spec.ts +43 -0
  962. package/src/server/serverFns/harness/__tests__/sandbox-policy.test.ts +199 -0
  963. package/src/server/serverFns/harness/__tests__/workspace-files.test.ts +224 -0
  964. package/src/server/serverFns/harness/attach-guards.ts +31 -0
  965. package/src/server/serverFns/harness/attach-prototype.ts +63 -0
  966. package/src/server/serverFns/harness/attach-to-kb.ts +80 -0
  967. package/src/server/serverFns/harness/attach-to-story.ts +74 -0
  968. package/src/server/serverFns/harness/cancel-run.ts +89 -0
  969. package/src/server/serverFns/{ai/execute.ts → harness/extract-attachment.ts} +19 -15
  970. package/src/server/serverFns/harness/gallery.ts +213 -0
  971. package/src/server/serverFns/harness/github-workspace.ts +202 -0
  972. package/src/server/serverFns/harness/media.ts +300 -0
  973. package/src/server/serverFns/harness/sandbox-policy.ts +88 -0
  974. package/src/server/serverFns/harness/search-mention-candidates.ts +53 -0
  975. package/src/server/serverFns/harness/workspace-files.ts +136 -0
  976. package/src/server/serverFns/iteration/__tests__/iteration-stories.test.ts +11 -1
  977. package/src/server/serverFns/iteration/__tests__/iteration-transfer.test.ts +11 -1
  978. package/src/server/serverFns/iteration/auto-schedule-internal.ts +3 -1
  979. package/src/server/serverFns/iteration/iteration-auto-schedule.ts +2 -1
  980. package/src/server/serverFns/iteration/iteration-burndown.ts +1 -1
  981. package/src/server/serverFns/iteration/iteration-crud.ts +8 -1
  982. package/src/server/serverFns/iteration/iteration-stories.ts +4 -1
  983. package/src/server/serverFns/iteration/transfer-internal.ts +1 -1
  984. package/src/server/serverFns/kb-doc-search.ts +2 -1
  985. package/src/server/serverFns/knowledge-index-utils.ts +26 -5
  986. package/src/server/serverFns/knowledge-index.ts +8 -4
  987. package/src/server/serverFns/knowledge-public/bookmarks/categories.ts +3 -1
  988. package/src/server/serverFns/knowledge-public/bookmarks/create.ts +1 -1
  989. package/src/server/serverFns/knowledge-public/bookmarks/delete.ts +1 -1
  990. package/src/server/serverFns/knowledge-public/bookmarks/detail.ts +1 -1
  991. package/src/server/serverFns/knowledge-public/bookmarks/favorite.ts +1 -1
  992. package/src/server/serverFns/knowledge-public/bookmarks/list.ts +1 -1
  993. package/src/server/serverFns/knowledge-public/bookmarks/share.ts +1 -1
  994. package/src/server/serverFns/knowledge-public/bookmarks/unshare.ts +1 -1
  995. package/src/server/serverFns/knowledge-public/bookmarks/update.ts +1 -1
  996. package/src/server/serverFns/knowledge-public/compliance/create.ts +1 -1
  997. package/src/server/serverFns/knowledge-public/compliance/delete.ts +1 -1
  998. package/src/server/serverFns/knowledge-public/compliance/detail.ts +1 -1
  999. package/src/server/serverFns/knowledge-public/compliance/list.ts +1 -1
  1000. package/src/server/serverFns/knowledge-public/compliance/public.ts +1 -1
  1001. package/src/server/serverFns/knowledge-public/compliance/share.ts +1 -1
  1002. package/src/server/serverFns/knowledge-public/compliance/unshare.ts +1 -1
  1003. package/src/server/serverFns/knowledge-public/compliance/update.ts +1 -1
  1004. package/src/server/serverFns/knowledge-public/dictionary/create.ts +1 -1
  1005. package/src/server/serverFns/knowledge-public/dictionary/delete.ts +1 -1
  1006. package/src/server/serverFns/knowledge-public/dictionary/detail.ts +1 -1
  1007. package/src/server/serverFns/knowledge-public/dictionary/list.ts +1 -1
  1008. package/src/server/serverFns/knowledge-public/dictionary/share.ts +1 -1
  1009. package/src/server/serverFns/knowledge-public/dictionary/unshare.ts +1 -1
  1010. package/src/server/serverFns/knowledge-public/dictionary/update.ts +1 -1
  1011. package/src/server/serverFns/knowledge-public/entity-tags.ts +1 -1
  1012. package/src/server/serverFns/knowledge-public/favorite.ts +2 -1
  1013. package/src/server/serverFns/knowledge-public/legal/create.ts +1 -1
  1014. package/src/server/serverFns/knowledge-public/legal/delete.ts +1 -1
  1015. package/src/server/serverFns/knowledge-public/legal/detail.ts +1 -1
  1016. package/src/server/serverFns/knowledge-public/legal/list.ts +1 -1
  1017. package/src/server/serverFns/knowledge-public/legal/public.ts +1 -1
  1018. package/src/server/serverFns/knowledge-public/legal/share.ts +1 -1
  1019. package/src/server/serverFns/knowledge-public/legal/unshare.ts +1 -1
  1020. package/src/server/serverFns/knowledge-public/legal/update.ts +1 -1
  1021. package/src/server/serverFns/knowledge.ts +56 -9
  1022. package/src/server/serverFns/notifications.ts +8 -1
  1023. package/src/server/serverFns/plugins/harness-plugins.ts +233 -0
  1024. package/src/server/serverFns/plugins/plugin-precheck.ts +82 -0
  1025. package/src/server/serverFns/project/module-overview.ts +2 -1
  1026. package/src/server/serverFns/project.ts +19 -1
  1027. package/src/server/serverFns/settings/account-team.ts +1 -1
  1028. package/src/server/serverFns/share/version.ts +1 -1
  1029. package/src/server/serverFns/sso.ts +1 -1
  1030. package/src/server/serverFns/story/__tests__/label-suggest-fn.test.ts +43 -21
  1031. package/src/server/serverFns/story/kb-general.ts +2 -2
  1032. package/src/server/serverFns/story/story-assoc.ts +14 -3
  1033. package/src/server/serverFns/story/story-attachments.ts +2 -1
  1034. package/src/server/serverFns/story/story-children.ts +1 -1
  1035. package/src/server/serverFns/story/story-comments.ts +4 -1
  1036. package/src/server/serverFns/story/story-crud/activities.ts +1 -1
  1037. package/src/server/serverFns/story/story-crud/archive.ts +2 -1
  1038. package/src/server/serverFns/story/story-crud/bulk.ts +4 -1
  1039. package/src/server/serverFns/story/story-crud/detail.ts +2 -1
  1040. package/src/server/serverFns/story/story-crud/label-suggest-core.ts +15 -6
  1041. package/src/server/serverFns/story/story-crud/label-upsert.ts +1 -1
  1042. package/src/server/serverFns/story/story-crud/labels.ts +3 -1
  1043. package/src/server/serverFns/story/story-crud.ts +6 -1
  1044. package/src/server/serverFns/story/story-dependencies.ts +4 -1
  1045. package/src/server/serverFns/story/story-groups.ts +4 -1
  1046. package/src/server/serverFns/story/story-links.ts +4 -1
  1047. package/src/server/serverFns/story/story-reactions.ts +4 -1
  1048. package/src/server/serverFns/story/story-search.ts +2 -1
  1049. package/src/server/serverFns/story/story-transfer.ts +7 -2
  1050. package/src/server/serverFns/story/story-tree.ts +5 -1
  1051. package/src/server/serverFns/story/types.ts +2 -1
  1052. package/src/server/serverFns/story-display-options.ts +3 -1
  1053. package/src/server/serverFns/story-view.ts +5 -1
  1054. package/src/server/serverFns/team.ts +19 -1
  1055. package/src/server/serverFns/translation.ts +7 -7
  1056. package/src/server/serverFns/user/avatar.ts +1 -1
  1057. package/src/server/serverFns/user/settings.ts +1 -1
  1058. package/src/server/serverFns/user/update-locale.ts +1 -1
  1059. package/src/server/serverFns/web-search.ts +20 -4
  1060. package/src/server/serverFns/workspace-kb.ts +9 -1
  1061. package/src/server/serverFns/workspace.ts +16 -1
  1062. package/src/start.ts +4 -0
  1063. package/src/styles/globals.css +124 -84
  1064. package/vite.shared.ts +23 -1
  1065. package/src/components/ai/global-chat-panel.tsx +0 -137
  1066. package/src/components/chat/__tests__/ai-conversation.test.tsx +0 -79
  1067. package/src/components/chat/ai-conversation.tsx +0 -332
  1068. package/src/components/chat/ai-message/hooks/use-streaming-text.ts +0 -73
  1069. package/src/components/chat/ai-message/index.tsx +0 -128
  1070. package/src/components/chat/chat-thread-page.tsx +0 -164
  1071. package/src/components/chat/interrupt-approval.tsx +0 -120
  1072. package/src/components/devtools/ai-chat-panel.tsx +0 -54
  1073. package/src/components/devtools/devtools-panel.tsx +0 -100
  1074. package/src/components/devtools/session-panel.tsx +0 -102
  1075. package/src/components/ui/sonner.tsx +0 -37
  1076. package/src/paraglide/messages/chat_systemprompt1.js +0 -30
  1077. package/src/paraglide/messages/common_nav_chat.js +0 -29
  1078. package/src/paraglide/messages/en.js +0 -17242
  1079. package/src/paraglide/messages/zh.js +0 -17240
  1080. package/src/routes/_nav/agents/route.tsx +0 -12
  1081. package/src/routes/_nav/chat/route.lazy.tsx +0 -427
  1082. /package/src/components/{chat → ai}/ai-prompt-input/components/context-badge.tsx +0 -0
  1083. /package/src/components/{chat → ai}/ai-prompt-input/constants.tsx +0 -0
  1084. /package/src/components/{chat → ai}/ai-prompt-input/types.ts +0 -0
  1085. /package/src/components/{chat → ai}/ai-prompt-input.tsx +0 -0
  1086. /package/src/components/{chat → harness}/ai-chat-history/components/conversation-header.tsx +0 -0
  1087. /package/src/components/{chat → harness}/ai-chat-history/components/conversation-search.tsx +0 -0
  1088. /package/src/components/{chat → harness}/ai-chat-history/components/empty-state.tsx +0 -0
  1089. /package/src/components/{chat → harness}/ai-chat-history/utils/group-conversations.ts +0 -0
  1090. /package/src/components/{chat → harness}/ai-chat-history.tsx +0 -0
  1091. /package/src/components/{chat → harness}/ai-citations/components/citation-item.tsx +0 -0
  1092. /package/src/components/{chat → harness}/ai-citations/components/citations-list.tsx +0 -0
  1093. /package/src/components/{chat → harness}/ai-citations/components/inline-citation.tsx +0 -0
  1094. /package/src/components/{chat → harness}/ai-citations/components/source-components.tsx +0 -0
  1095. /package/src/components/{chat → harness}/ai-citations/index.tsx +0 -0
  1096. /package/src/components/{chat → harness}/ai-citations/types.ts +0 -0
  1097. /package/src/components/{chat → harness}/ai-citations/utils.ts +0 -0
  1098. /package/src/components/{chat → harness}/ai-citations.tsx +0 -0
  1099. /package/src/components/{chat → harness}/ai-message/components/code-block.tsx +0 -0
  1100. /package/src/components/{chat → harness}/ai-message/components/markdown-content.tsx +0 -0
  1101. /package/src/components/{chat → harness}/ai-message/components/streaming-indicator.tsx +0 -0
  1102. /package/src/components/{chat → harness}/ai-message/utils/dom-utils.ts +0 -0
  1103. /package/src/components/{chat → harness}/ai-thinking.tsx +0 -0
@@ -0,0 +1,243 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ import { randomUUID } from "node:crypto"
19
+ import { prisma } from "@allbluecn/database"
20
+ import type {
21
+ MemoryAdapter,
22
+ MemoryFact,
23
+ MemoryScope,
24
+ MemorySnapshot,
25
+ MemoryTurn,
26
+ RecallResult,
27
+ SaveReceipt,
28
+ } from "@tanstack/ai-memory"
29
+ import { generateEmbedding } from "../embedding"
30
+ import { fenceLlmData } from "../llm-fence"
31
+
32
+ // 过短寒暄不入库:省 embedding 调用费 + 避免噪音稀释召回
33
+ export const DEFAULT_MIN_USER_CHARS = 8
34
+ export const DEFAULT_RECALL_CANDIDATE_LIMIT = 50
35
+ export const DEFAULT_RECALL_TOP_K = 5
36
+ // 余弦相似度(1 - 距离)下限:text-embedding-3-small 在无关文本上常落 0.1~0.2
37
+ export const DEFAULT_SIMILARITY_THRESHOLD = 0.25
38
+ export const DEFAULT_LIST_FACTS_LIMIT = 200
39
+
40
+ export interface PgVectorMemoryAdapterOptions {
41
+ minUserChars?: number
42
+ recallCandidateLimit?: number
43
+ recallTopK?: number
44
+ similarityThreshold?: number
45
+ listFactsLimit?: number
46
+ now?: () => string
47
+ }
48
+
49
+ interface StoredFactRow {
50
+ id: string
51
+ content: string
52
+ threadId: string
53
+ createdAt: Date | string
54
+ similarity?: number | string
55
+ }
56
+
57
+ interface MemoryStatsRow {
58
+ c: number | string
59
+ lastWrite: Date | string | null
60
+ }
61
+
62
+ function formatVector(embedding: number[]): string {
63
+ return `[${embedding.join(",")}]`
64
+ }
65
+
66
+ function toMillis(value: Date | number | string | null | undefined): number {
67
+ if (value === null || value === undefined) return 0
68
+ if (value instanceof Date) return value.getTime()
69
+ return new Date(value).getTime()
70
+ }
71
+
72
+ function roundMs(value: number): number {
73
+ return Math.round(value)
74
+ }
75
+
76
+ function errorMessage(error: unknown): string {
77
+ return error instanceof Error ? error.message : String(error)
78
+ }
79
+
80
+ function buildFactContent(turn: MemoryTurn): string {
81
+ return [turn.user.trim(), turn.assistant.trim()].filter(Boolean).join("\n")
82
+ }
83
+
84
+ // pgvector 原生表由 raw SQL 读写(Prisma 无法表达 vector 类型)
85
+ export function createPgVectorMemoryAdapter(
86
+ options: PgVectorMemoryAdapterOptions = {},
87
+ ): MemoryAdapter {
88
+ const minUserChars = options.minUserChars ?? DEFAULT_MIN_USER_CHARS
89
+ const candidateLimit = options.recallCandidateLimit ?? DEFAULT_RECALL_CANDIDATE_LIMIT
90
+ const topK = options.recallTopK ?? DEFAULT_RECALL_TOP_K
91
+ const similarityThreshold =
92
+ options.similarityThreshold ?? DEFAULT_SIMILARITY_THRESHOLD
93
+ const listFactsLimit = options.listFactsLimit ?? DEFAULT_LIST_FACTS_LIMIT
94
+ const takenAt = () => (options.now ?? (() => new Date().toISOString()))()
95
+
96
+ async function listFactsByUser(
97
+ userId: string,
98
+ limit: number,
99
+ ): Promise<Array<StoredFactRow>> {
100
+ return (await prisma.$queryRawUnsafe(
101
+ `SELECT "id", "content", "threadId", "createdAt" FROM "memory_facts" WHERE "userId" = $1 ORDER BY "createdAt" DESC LIMIT $2`,
102
+ userId,
103
+ limit,
104
+ )) as Array<StoredFactRow>
105
+ }
106
+
107
+ async function searchFacts(
108
+ userId: string,
109
+ query: string,
110
+ ): Promise<Array<StoredFactRow>> {
111
+ const embedding = await generateEmbedding(query)
112
+ if (!Array.isArray(embedding) || embedding.length === 0) return []
113
+ const embeddingStr = formatVector(embedding)
114
+ return (await prisma.$queryRawUnsafe(
115
+ `SELECT "id", "content", "threadId", "createdAt", 1 - (embedding <=> $1::vector) AS similarity FROM "memory_facts" WHERE "userId" = $2 ORDER BY embedding <=> $3::vector LIMIT $4`,
116
+ embeddingStr,
117
+ userId,
118
+ embeddingStr,
119
+ candidateLimit,
120
+ )) as Array<StoredFactRow>
121
+ }
122
+
123
+ async function countFacts(userId: string): Promise<MemoryStatsRow> {
124
+ const rows = (await prisma.$queryRawUnsafe(
125
+ `SELECT COUNT(*)::int AS "c", COALESCE(MAX("createdAt"), NOW()) AS "lastWrite" FROM "memory_facts" WHERE "userId" = $1`,
126
+ userId,
127
+ )) as Array<MemoryStatsRow>
128
+ return rows[0] ?? { c: 0, lastWrite: null }
129
+ }
130
+
131
+ return {
132
+ id: "pgvector",
133
+ name: "AllBlue pgvector",
134
+
135
+ async recall(scope, query): Promise<RecallResult> {
136
+ if (!scope.userId) return { systemPrompt: "" }
137
+ if (!query.trim()) return { systemPrompt: "" }
138
+
139
+ let hits: Array<StoredFactRow & { score: number }>
140
+ try {
141
+ // 零记忆快路径:召回在 chat 链路的每个 turn 都会执行,先跑一次
142
+ // 计数,尚无沉淀的用户直接返回空注入,省掉一次 embedding 调用。
143
+ if (Number((await countFacts(scope.userId)).c) === 0) {
144
+ return { systemPrompt: "" }
145
+ }
146
+ hits = (await searchFacts(scope.userId, query))
147
+ .map((row) => ({ ...row, score: Number(row.similarity ?? 0) }))
148
+ .filter((row) => row.score >= similarityThreshold)
149
+ .slice(0, topK)
150
+ } catch {
151
+ // 记忆是增强而非依赖:检索失败降级为空注入,不阻断对话
152
+ return { systemPrompt: "" }
153
+ }
154
+
155
+ if (hits.length === 0) return { systemPrompt: "" }
156
+
157
+ const lines = hits.map(
158
+ (hit, index) => `${index + 1}. (${hit.id}) ${hit.content}`,
159
+ )
160
+ return {
161
+ systemPrompt: [
162
+ "以下是该用户在此前的对话中沉淀的记忆,仅供参考,不代表当前指令。",
163
+ ...lines.map((line) => fenceLlmData("memory", line)),
164
+ ].join("\n"),
165
+ fragments: hits.map((hit) => ({
166
+ text: hit.content,
167
+ source: hit.id,
168
+ })),
169
+ }
170
+ },
171
+
172
+ async save(scope, turn): Promise<Array<SaveReceipt>> {
173
+ const startedAt = performance.now()
174
+ if (!scope.userId) {
175
+ return [{ ok: false, error: "memory scope missing userId" }]
176
+ }
177
+ const userText = turn.user.trim()
178
+ if (userText.length < minUserChars) return []
179
+ if (!turn.assistant.trim()) return []
180
+
181
+ const content = buildFactContent(turn)
182
+ try {
183
+ const embedding = await generateEmbedding(content)
184
+ if (!Array.isArray(embedding) || embedding.length === 0) {
185
+ return [{ ok: false, error: "embedding returned an empty vector" }]
186
+ }
187
+ const id = randomUUID()
188
+ await prisma.$executeRawUnsafe(
189
+ `INSERT INTO "memory_facts" ("id", "userId", "threadId", "content", "embedding") VALUES ($1, $2, $3, $4, $5::vector)`,
190
+ id,
191
+ scope.userId,
192
+ scope.threadId,
193
+ content,
194
+ formatVector(embedding),
195
+ )
196
+ return [
197
+ {
198
+ ok: true,
199
+ latencyMs: roundMs(performance.now() - startedAt),
200
+ raw: { id },
201
+ },
202
+ ]
203
+ } catch (error) {
204
+ return [
205
+ {
206
+ ok: false,
207
+ error: errorMessage(error),
208
+ latencyMs: roundMs(performance.now() - startedAt),
209
+ },
210
+ ]
211
+ }
212
+ },
213
+
214
+ async inspect(scope): Promise<MemorySnapshot> {
215
+ if (!scope.userId) {
216
+ return { takenAt: takenAt(), data: { userId: null, threadId: scope.threadId, count: 0 } }
217
+ }
218
+ const stats = await countFacts(scope.userId)
219
+ return {
220
+ takenAt: takenAt(),
221
+ data: {
222
+ userId: scope.userId,
223
+ threadId: scope.threadId,
224
+ count: Number(stats.c),
225
+ lastWrite: stats.lastWrite ? toMillis(stats.lastWrite) : null,
226
+ },
227
+ }
228
+ },
229
+
230
+ async listFacts(scope): Promise<Array<MemoryFact>> {
231
+ if (!scope.userId) return []
232
+ const rows = await listFactsByUser(scope.userId, listFactsLimit)
233
+ return rows.map((row) => ({
234
+ id: row.id,
235
+ text: row.content,
236
+ source: row.threadId,
237
+ createdAt: toMillis(row.createdAt)
238
+ ? new Date(toMillis(row.createdAt)).toISOString()
239
+ : undefined,
240
+ }))
241
+ },
242
+ }
243
+ }
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ import { prisma } from "@allbluecn/database"
19
+ import type { ChatMiddlewareContext } from "@tanstack/ai"
20
+ import type { MemoryScope } from "@tanstack/ai-memory"
21
+
22
+ // scope 函数抛错即「跳过」语义:memoryMiddleware 在 onConfig(recall)与
23
+ // onFinish defer(save)两处均 try-catch 并仅发 memory:error 事件,对话不受影响。
24
+ // MemoryScope 类型不允许返回 undefined,故抛错是唯一安全的 fail-closed 出口。
25
+ export class MemoryScopeError extends Error {
26
+ constructor(message: string) {
27
+ super(message)
28
+ this.name = "MemoryScopeError"
29
+ }
30
+ }
31
+
32
+ export type MemoryScopeResolver = (
33
+ ctx: ChatMiddlewareContext,
34
+ ) => MemoryScope | Promise<MemoryScope>
35
+
36
+ // userId 由调用方从服务端 session 派生并闭包捕获,禁止从 request body 接收。
37
+ // threadId 来自 ChatMiddlewareContext(客户端可指定),必须校验归属后才可使用。
38
+ export function createMemoryScopeResolver(
39
+ userId: string,
40
+ ): MemoryScopeResolver {
41
+ return async (ctx: ChatMiddlewareContext): Promise<MemoryScope> => {
42
+ const threadId = ctx.threadId
43
+ const thread = await prisma.chatThread.findUnique({
44
+ where: { id: threadId },
45
+ select: { id: true, userId: true },
46
+ })
47
+ if (!thread || thread.userId !== userId) {
48
+ throw new MemoryScopeError(
49
+ `memory scope rejected: thread ${threadId} not owned by ${userId}`,
50
+ )
51
+ }
52
+ return { threadId: thread.id, userId: thread.userId }
53
+ }
54
+ }
@@ -0,0 +1,232 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ import { defineChatMiddleware } from "@tanstack/ai"
19
+ import type { ModelMessage } from "@tanstack/ai"
20
+ import type { AppContext } from "../types"
21
+
22
+ export interface CompactionOptions {
23
+ maxTokens: number
24
+ keepRecentTokens: number
25
+ keepRecentToolResults: number
26
+ }
27
+
28
+ const DEFAULT_MAX_TOKENS = 24000
29
+ const DEFAULT_KEEP_RECENT_TOKENS = 8000
30
+ const DEFAULT_KEEP_RECENT_TOOL_RESULTS = 3
31
+
32
+ /**
33
+ * onConfig 在 init 与每个 agent 迭代开头都会调用,退化路径每轮触发会刷屏。
34
+ * 每个条件在进程生命周期内只 warn 一次,避免日志淹没真实的请求日志。
35
+ */
36
+ const warnedOnce = new Set<string>()
37
+
38
+ function warnOnce(key: string, message: string) {
39
+ if (warnedOnce.has(key)) return
40
+ warnedOnce.add(key)
41
+ console.warn(`[AI] ${message}`)
42
+ }
43
+
44
+ /**
45
+ * 退化原因:超阈值但无法安全压缩(或配置本身退化)。
46
+ * 回调注入而非内置 console.warn —— compactProviderMessages 保持纯函数,
47
+ * 副作用(日志去重)由调用方决定,测试可直接断言 reason 而不受全局状态污染。
48
+ */
49
+ export type CompactionDegradeReason =
50
+ | "protectFrom0"
51
+ | "noUserBoundary"
52
+ | "maxTokensBelowKeepRecent"
53
+
54
+ export function estimateTokens(text: string): number {
55
+ if (!text) return 0
56
+ return Math.ceil(text.length / 4)
57
+ }
58
+
59
+ export function resolveCompactionOptions(
60
+ env: Record<string, string | undefined> = process.env,
61
+ onDegrade?: (reason: CompactionDegradeReason, message: string) => void,
62
+ ): CompactionOptions {
63
+ const base: CompactionOptions = {
64
+ maxTokens: DEFAULT_MAX_TOKENS,
65
+ keepRecentTokens: DEFAULT_KEEP_RECENT_TOKENS,
66
+ keepRecentToolResults: DEFAULT_KEEP_RECENT_TOOL_RESULTS,
67
+ }
68
+ const raw = env.AI_COMPACTION_MAX_TOKENS
69
+ if (raw == null || raw === "") return base
70
+ const parsed = parseInt(raw, 10)
71
+ if (!Number.isFinite(parsed) || parsed <= 0) return base
72
+ // 保护窗口比阈值还大时,evictOldest 的丢弃区间恒为空,压缩永不生效
73
+ if (parsed < DEFAULT_KEEP_RECENT_TOKENS) {
74
+ onDegrade?.(
75
+ "maxTokensBelowKeepRecent",
76
+ `compaction 配置退化:AI_COMPACTION_MAX_TOKENS=${parsed} < keepRecentTokens=${DEFAULT_KEEP_RECENT_TOKENS},evictOldest 永不生效`,
77
+ )
78
+ }
79
+ return { ...base, maxTokens: parsed }
80
+ }
81
+
82
+ function messageTokens(m: ModelMessage): number {
83
+ let text = ""
84
+ if (typeof m.content === "string") {
85
+ text = m.content
86
+ } else if (m.content != null) {
87
+ text = JSON.stringify(m.content)
88
+ }
89
+ if (m.toolCalls && m.toolCalls.length > 0) {
90
+ text += JSON.stringify(m.toolCalls)
91
+ }
92
+ return estimateTokens(text)
93
+ }
94
+
95
+ function totalTokens(messages: readonly ModelMessage[]): number {
96
+ let sum = 0
97
+ for (const m of messages) {
98
+ sum += messageTokens(m)
99
+ }
100
+ return sum
101
+ }
102
+
103
+ function clearToolResults(
104
+ messages: readonly ModelMessage[],
105
+ keepRecent: number,
106
+ ): ModelMessage[] {
107
+ const toolIndices: number[] = []
108
+ for (let i = 0; i < messages.length; i++) {
109
+ if (messages[i].role === "tool") {
110
+ toolIndices.push(i)
111
+ }
112
+ }
113
+ if (toolIndices.length <= keepRecent) {
114
+ return messages as ModelMessage[]
115
+ }
116
+ const evictCount = toolIndices.length - keepRecent
117
+ const evictSet = new Set(toolIndices.slice(0, evictCount))
118
+ return messages.map((m, i) => {
119
+ if (!evictSet.has(i)) return m
120
+ const name = m.name ?? "unknown"
121
+ return { ...m, content: `[tool result evicted: ${name}]` }
122
+ })
123
+ }
124
+
125
+ function evictOldest(
126
+ messages: readonly ModelMessage[],
127
+ opts: CompactionOptions,
128
+ onDegrade?: (reason: CompactionDegradeReason, message: string) => void,
129
+ ): ModelMessage[] {
130
+ const tokens = messages.map(messageTokens)
131
+ const total = tokens.reduce((s, t) => s + t, 0)
132
+ if (total <= opts.maxTokens) {
133
+ return messages as ModelMessage[]
134
+ }
135
+
136
+ let protectFrom = 0
137
+ let acc = 0
138
+ for (let i = messages.length - 1; i >= 0; i--) {
139
+ acc += tokens[i]
140
+ protectFrom = i
141
+ if (acc > opts.keepRecentTokens) {
142
+ protectFrom = i + 1
143
+ break
144
+ }
145
+ }
146
+
147
+ // 保护窗口覆盖全部上下文:丢弃区间为空,压缩无法生效
148
+ if (protectFrom === 0) {
149
+ onDegrade?.(
150
+ "protectFrom0",
151
+ `compaction 无法压缩:最近保护窗口(${opts.keepRecentTokens})已覆盖全部上下文(total=${total}),实际发出超过 maxTokens=${opts.maxTokens}`,
152
+ )
153
+ return messages as ModelMessage[]
154
+ }
155
+
156
+ let dropEnd = -1
157
+ let suffixSum = total - tokens[0]
158
+ for (let i = 1; i < protectFrom; i++) {
159
+ if (suffixSum <= opts.maxTokens && messages[i].role === "user") {
160
+ dropEnd = i
161
+ break
162
+ }
163
+ suffixSum -= tokens[i]
164
+ }
165
+
166
+ // 丢弃区间内没有 user 消息:无法在保持 tool call 配对安全的前提下压缩
167
+ if (dropEnd <= 0) {
168
+ onDegrade?.(
169
+ "noUserBoundary",
170
+ `compaction 找不到 user 消息边界(total=${total}),实际发出超过 maxTokens=${opts.maxTokens}`,
171
+ )
172
+ return messages as ModelMessage[]
173
+ }
174
+
175
+ return messages.slice(dropEnd)
176
+ }
177
+
178
+ export function compactProviderMessages(
179
+ messages: readonly ModelMessage[],
180
+ opts: CompactionOptions,
181
+ onDegrade?: (reason: CompactionDegradeReason, message: string) => void,
182
+ ): ModelMessage[] {
183
+ if (messages.length === 0) {
184
+ return messages as ModelMessage[]
185
+ }
186
+
187
+ const total = totalTokens(messages)
188
+
189
+ const afterClear = clearToolResults(messages, opts.keepRecentToolResults)
190
+
191
+ if (total <= opts.maxTokens && afterClear === messages) {
192
+ return messages as ModelMessage[]
193
+ }
194
+
195
+ const totalAfterClear = totalTokens(afterClear)
196
+ if (totalAfterClear <= opts.maxTokens) {
197
+ return afterClear
198
+ }
199
+
200
+ return evictOldest(afterClear, opts, onDegrade)
201
+ }
202
+
203
+ /**
204
+ * 自研 compaction(ADR 19 顺位:官方 0.54.0 无 withCompaction——文档超前于版本,
205
+ * 全包 grep 零命中)。onConfig 返回 { providerMessages } 只改 provider 上下文;
206
+ * canonical messages 与 persistence transcript 不动(reload 后完整 transcript
207
+ * 可见——P1 验收项)。
208
+ *
209
+ * 输入源取 providerMessages ?? messages:middleware 是 pipe 顺序执行,上游若已
210
+ * 改写过 provider 视图(如 provider-specific reshape),以 canonical 重算会整体
211
+ * 覆盖上游改动。这里以 providerMessages 为源,保证 compaction 只压缩、不重建。
212
+ */
213
+ /** 退化日志去重:onConfig 每 agent 迭代调用,罕见退化也应避免刷屏 */
214
+ const logDegrade = (reason: CompactionDegradeReason, message: string) => {
215
+ warnOnce(reason, message)
216
+ }
217
+
218
+ export function compactionMiddleware(
219
+ opts: CompactionOptions = resolveCompactionOptions(process.env, logDegrade),
220
+ ) {
221
+ return defineChatMiddleware<AppContext>({
222
+ name: "ai-compaction",
223
+ onConfig(_ctx, config) {
224
+ const base = config.providerMessages ?? config.messages
225
+ const compacted = compactProviderMessages(base, opts, logDegrade)
226
+ if (compacted === base) {
227
+ return undefined
228
+ }
229
+ return { providerMessages: compacted }
230
+ },
231
+ })
232
+ }
@@ -16,4 +16,14 @@
16
16
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
 
18
18
  export { loggerMiddleware } from "./logger"
19
- export { rateLimitMiddleware } from "./rate-limit"
19
+ export { rateLimitMiddleware } from "./rate-limit"
20
+ export { createToolBudgetMiddleware } from "./tool-budget"
21
+ export { createPlanApprovalMiddleware } from "./plan-approval"
22
+ export { compactionMiddleware, resolveCompactionOptions } from "./compaction"
23
+ export {
24
+ createUsageLogMiddleware,
25
+ resolveUsageWorkspaceId,
26
+ writeAiUsageLog,
27
+ type AiUsageActivity,
28
+ type WriteAiUsageLogInput,
29
+ } from "./usage-log"
@@ -15,11 +15,11 @@
15
15
  // You should have received a copy of the GNU Affero General Public License
16
16
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
17
 
18
- import type { ChatMiddleware } from "@tanstack/ai"
18
+ import { defineChatMiddleware } from "@tanstack/ai"
19
19
  import type { AppContext } from "../types"
20
20
 
21
- export const loggerMiddleware: ChatMiddleware<AppContext> = {
22
- name: "logger",
21
+ export const loggerMiddleware = defineChatMiddleware<AppContext>({
22
+ name: "ai-logger",
23
23
  onStart(ctx) {
24
24
  console.log(`[AI] start requestId=${ctx.requestId} userId=${ctx.context.userId}`)
25
25
  },
@@ -32,4 +32,4 @@ export const loggerMiddleware: ChatMiddleware<AppContext> = {
32
32
  onError(ctx, { error }) {
33
33
  console.error(`[AI] error requestId=${ctx.requestId}:`, error)
34
34
  },
35
- }
35
+ })
@@ -0,0 +1,125 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-or-later
2
+ // AllBlue - 理想之海
3
+ // Copyright (C) 2026 AllBlue Contributors
4
+ //
5
+ // This program is free software: you can redistribute it and/or modify
6
+ // it under the terms of the GNU Affero General Public License as published by
7
+ // the Free Software Foundation, either version 3 of the License, or
8
+ // (at your option) any later version.
9
+ //
10
+ // This program is distributed in the hope that it will be useful,
11
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ // GNU Affero General Public License for more details.
14
+ //
15
+ // You should have received a copy of the GNU Affero General Public License
16
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ import { defineChatMiddleware } from "@tanstack/ai";
19
+ import type { ChatMiddlewareContext } from "@tanstack/ai";
20
+ import type { AppContext } from "../types";
21
+ import {
22
+ planApprovalInterrupt,
23
+ planApprovalPayloadSchema,
24
+ } from "../tools/plan-submit";
25
+
26
+ const PLAN_SUBMIT_TOOL_NAME = "plan_submit";
27
+
28
+ /**
29
+ * 工厂函数:每次 chat() 调用创建独立实例,闭包 Set 记录已 raise 过的 toolCallId,
30
+ * 防止 resume 时同一 tool call 被二次触发 interrupt。tool-budget.ts 也是这个模式。
31
+ *
32
+ * 触发点:onInterruptBoundary('beforeTools')。此相位时引擎已把本轮 assistant
33
+ * tool calls 追加到 ctx.messages(addAssistantToolCallMessage 在 emitBoundaryInterrupts
34
+ * 之前调用,见 index.js:862 → 886),因此从 messages 末条 assistant 消息的
35
+ * toolCalls 字段取 plan_submit 调用即可。
36
+ */
37
+ export function createPlanApprovalMiddleware() {
38
+ const raisedToolCallIds = new Set<string>();
39
+
40
+ const mw = defineChatMiddleware<AppContext, readonly [], readonly [], typeof planApprovalInterrupt>({
41
+ name: "ai-plan-approval",
42
+
43
+ onInterruptBoundary(ctx) {
44
+ if (ctx.phase !== "beforeTools") return undefined;
45
+
46
+ const last = ctx.messages[ctx.messages.length - 1];
47
+ if (!last || last.role !== "assistant") return undefined;
48
+
49
+ const toolCalls = (last as { toolCalls?: Array<{ id: string; function: { name: string; arguments: string } }> }).toolCalls;
50
+ if (!toolCalls || toolCalls.length === 0) return undefined;
51
+
52
+ const planCalls = toolCalls.filter(
53
+ (tc) => tc.function.name === PLAN_SUBMIT_TOOL_NAME && !raisedToolCallIds.has(tc.id),
54
+ );
55
+ if (planCalls.length === 0) return undefined;
56
+
57
+ const interrupts = planCalls.map((tc) => {
58
+ let parsed: unknown;
59
+ try {
60
+ parsed = JSON.parse(tc.function.arguments.trim() || "{}");
61
+ } catch (err) {
62
+ console.warn(
63
+ `[AI] plan_submit arguments 非合法 JSON,跳过审批 (toolCall=${tc.id})`,
64
+ err instanceof Error ? err.message : "unknown",
65
+ );
66
+ return null;
67
+ }
68
+ const check = planApprovalPayloadSchema.safeParse(parsed);
69
+ if (!check.success) {
70
+ console.warn(
71
+ `[AI] plan_submit payload 未通过 schema 校验,跳过审批 (toolCall=${tc.id})`,
72
+ check.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join(", "),
73
+ );
74
+ return null;
75
+ }
76
+ raisedToolCallIds.add(tc.id);
77
+ return planApprovalInterrupt.interrupt({
78
+ key: tc.id,
79
+ reason: "plan_approval",
80
+ message: `需要审批执行计划${check.data.title ? `:${check.data.title}` : ""}`,
81
+ payload: check.data,
82
+ });
83
+ }).filter((r): r is NonNullable<typeof r> => r !== null);
84
+
85
+ if (interrupts.length === 0) return undefined;
86
+ return { interrupts };
87
+ },
88
+
89
+ onInterruptResolution(_ctx, resolutions) {
90
+ const planResolutions = resolutions.for(planApprovalInterrupt);
91
+ if (planResolutions.length === 0) return undefined;
92
+
93
+ const hasCancelled = planResolutions.some((r) => r.status === "cancelled");
94
+ const hasResolved = planResolutions.some((r) => r.status === "resolved");
95
+
96
+ if (hasCancelled && !hasResolved) {
97
+ return { toolResume: "cancel" as const };
98
+ }
99
+
100
+ const rejectedCount = planResolutions.filter(
101
+ (r) => r.status === "resolved" && (r.response as { approved?: boolean })?.approved === false,
102
+ ).length;
103
+ const approvedCount = planResolutions.filter(
104
+ (r) => r.status === "resolved" && (r.response as { approved?: boolean })?.approved === true,
105
+ ).length;
106
+
107
+ // 不变式:任一批次出现 rejected 时整批 cancel。
108
+ // toolResume 是全局单一决策(compose.js:66 priority 最高者胜出),
109
+ // 一旦 continue 全部 pending toolCalls 都被执行——被拒的 plan 也会被
110
+ // 写入权威快照,造成用户已拒绝的计划落库。因此拒绝优先 cancel,
111
+ // 让 LLM 收到取消信号后重新规划。
112
+ if (rejectedCount > 0) {
113
+ return { toolResume: "cancel" as const };
114
+ }
115
+
116
+ if (approvedCount > 0) {
117
+ return { toolResume: "continue" as const };
118
+ }
119
+
120
+ return { toolResume: "cancel" as const };
121
+ },
122
+ });
123
+
124
+ return mw;
125
+ }