@engenty/wizards-runtime 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/apps/runtime/dist/agents/architect.js +8 -7
  2. package/apps/runtime/dist/agents/goose-connections.js +82 -0
  3. package/apps/runtime/dist/agents/space-agent.js +9 -2
  4. package/apps/runtime/dist/agents/studio-assistant.js +101 -67
  5. package/apps/runtime/dist/agents/website.js +1 -1
  6. package/apps/runtime/dist/app.js +17 -1
  7. package/apps/runtime/dist/assistant/knows.js +6 -5
  8. package/apps/runtime/dist/authoring/guide.js +25 -5
  9. package/apps/runtime/dist/broker/account.js +166 -0
  10. package/apps/runtime/dist/broker/call.js +417 -0
  11. package/apps/runtime/dist/broker/caller.js +10 -0
  12. package/apps/runtime/dist/broker/grant.js +152 -0
  13. package/apps/runtime/dist/broker/host.js +51 -0
  14. package/apps/runtime/dist/broker/index.js +8 -0
  15. package/apps/runtime/dist/broker/kept.js +31 -0
  16. package/apps/runtime/dist/broker/log.js +240 -0
  17. package/apps/runtime/dist/broker/registry.js +9 -0
  18. package/apps/runtime/dist/broker/rwx.js +367 -0
  19. package/apps/runtime/dist/broker/send.js +189 -0
  20. package/apps/runtime/dist/connectors/builtin.js +1 -1
  21. package/apps/runtime/dist/connectors/external.js +38 -37
  22. package/apps/runtime/dist/connectors/index.js +30 -91
  23. package/apps/runtime/dist/connectors/mail.js +0 -8
  24. package/apps/runtime/dist/connectors/person-sign-ins.js +73 -0
  25. package/apps/runtime/dist/connectors/plugin-connections.js +65 -92
  26. package/apps/runtime/dist/connectors/smtp.js +1 -1
  27. package/apps/runtime/dist/connectors/space-connections.js +436 -0
  28. package/apps/runtime/dist/db/adopt.js +3 -3
  29. package/apps/runtime/dist/db/client.js +9 -0
  30. package/apps/runtime/dist/db/live-triggers.js +65 -23
  31. package/apps/runtime/dist/db/migrations/tenant/0027_work_chats.sql +52 -0
  32. package/apps/runtime/dist/db/migrations/tenant/0028_chat_approvals.sql +17 -0
  33. package/apps/runtime/dist/db/migrations/tenant/0029_work_chats_live.sql +49 -0
  34. package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
  35. package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
  36. package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
  37. package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
  38. package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
  39. package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
  40. package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
  41. package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
  42. package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
  43. package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
  44. package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
  45. package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
  46. package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
  47. package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
  48. package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
  49. package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
  50. package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
  51. package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
  52. package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
  53. package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
  54. package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
  55. package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
  56. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
  57. package/apps/runtime/dist/db/schema.js +295 -72
  58. package/apps/runtime/dist/docs/dev/architecture.md +215 -0
  59. package/apps/runtime/dist/docs/dev/broker.md +298 -0
  60. package/apps/runtime/dist/docs/dev/index.md +5 -1
  61. package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
  62. package/apps/runtime/dist/docs/dev/meta.json +3 -0
  63. package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
  64. package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
  65. package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
  66. package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
  67. package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
  68. package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
  69. package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
  70. package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
  71. package/apps/runtime/dist/docs/dev/skills.md +16 -9
  72. package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +40 -5
  73. package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
  74. package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
  75. package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
  76. package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
  77. package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
  78. package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
  79. package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
  80. package/apps/runtime/dist/docs/user-guide/index.md +10 -1
  81. package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
  82. package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
  83. package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
  84. package/apps/runtime/dist/docs/user-guide/space.md +5 -4
  85. package/apps/runtime/dist/docs/user-guide/together.md +16 -2
  86. package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
  87. package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
  88. package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
  89. package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
  90. package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
  91. package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
  92. package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
  93. package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
  94. package/apps/runtime/dist/engine/resources.js +43 -12
  95. package/apps/runtime/dist/engine/runner.js +75 -23
  96. package/apps/runtime/dist/engine/steps.js +30 -12
  97. package/apps/runtime/dist/engine/template.js +18 -1
  98. package/apps/runtime/dist/env.js +9 -4
  99. package/apps/runtime/dist/index.js +18 -2
  100. package/apps/runtime/dist/live/feed.js +2 -2
  101. package/apps/runtime/dist/live/origin.js +2 -2
  102. package/apps/runtime/dist/live/views.js +51 -26
  103. package/apps/runtime/dist/manage.js +7 -0
  104. package/apps/runtime/dist/mcp/flow-app.js +1 -1
  105. package/apps/runtime/dist/mcp/tools.js +75 -34
  106. package/apps/runtime/dist/models.js +1 -1
  107. package/apps/runtime/dist/motion-graphics/project.js +8 -8
  108. package/apps/runtime/dist/motion-graphics/tools.js +1 -1
  109. package/apps/runtime/dist/plugins/events.js +2 -2
  110. package/apps/runtime/dist/plugins/jobs.js +4 -1
  111. package/apps/runtime/dist/plugins/loader.js +2 -2
  112. package/apps/runtime/dist/prompts/architect.md +3 -3
  113. package/apps/runtime/dist/prompts/authoring.md +46 -12
  114. package/apps/runtime/dist/prompts/goose.md +7 -7
  115. package/apps/runtime/dist/prompts/mcp.md +6 -6
  116. package/apps/runtime/dist/prompts/services.md +4 -4
  117. package/apps/runtime/dist/prompts/step.md +2 -2
  118. package/apps/runtime/dist/prompts/tools.md +39 -10
  119. package/apps/runtime/dist/routes/api.js +31 -20
  120. package/apps/runtime/dist/routes/broker.js +316 -0
  121. package/apps/runtime/dist/routes/connections.js +71 -0
  122. package/apps/runtime/dist/routes/delivery.js +25 -0
  123. package/apps/runtime/dist/routes/discover.js +17 -0
  124. package/apps/runtime/dist/routes/live.js +11 -1
  125. package/apps/runtime/dist/routes/person.js +4 -1
  126. package/apps/runtime/dist/routes/plugins.js +3 -1
  127. package/apps/runtime/dist/routes/rules.js +26 -0
  128. package/apps/runtime/dist/routes/runs.js +54 -33
  129. package/apps/runtime/dist/routes/skills.js +6 -6
  130. package/apps/runtime/dist/routes/studio.js +153 -144
  131. package/apps/runtime/dist/routes/work.js +199 -0
  132. package/apps/runtime/dist/sandbox/index.js +27 -0
  133. package/apps/runtime/dist/services/access.js +38 -17
  134. package/apps/runtime/dist/services/api.js +38 -13
  135. package/apps/runtime/dist/services/architect.js +3 -3
  136. package/apps/runtime/dist/services/assistant-chats.js +9 -1
  137. package/apps/runtime/dist/services/brand.js +12 -12
  138. package/apps/runtime/dist/services/broker-bell.js +69 -0
  139. package/apps/runtime/dist/services/broker-notify.js +127 -0
  140. package/apps/runtime/dist/services/client-steps.js +79 -0
  141. package/apps/runtime/dist/services/cloud.js +42 -42
  142. package/apps/runtime/dist/services/command-risk.js +51 -0
  143. package/apps/runtime/dist/services/discover.js +85 -0
  144. package/apps/runtime/dist/services/knowledge-model.js +13 -13
  145. package/apps/runtime/dist/services/knowledge.js +117 -80
  146. package/apps/runtime/dist/services/manage-reports.js +74 -7
  147. package/apps/runtime/dist/services/members-studio.js +165 -0
  148. package/apps/runtime/dist/services/onboarding.js +22 -22
  149. package/apps/runtime/dist/services/package-file.js +1 -1
  150. package/apps/runtime/dist/services/package.js +22 -22
  151. package/apps/runtime/dist/services/pages.js +7 -7
  152. package/apps/runtime/dist/services/runs.js +4 -3
  153. package/apps/runtime/dist/services/seen.js +55 -0
  154. package/apps/runtime/dist/services/shares.js +23 -13
  155. package/apps/runtime/dist/services/site.js +23 -23
  156. package/apps/runtime/dist/services/skills-registry.js +15 -15
  157. package/apps/runtime/dist/services/skills.js +44 -44
  158. package/apps/runtime/dist/services/space-categories.js +35 -35
  159. package/apps/runtime/dist/services/space-data.js +130 -111
  160. package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
  161. package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
  162. package/apps/runtime/dist/services/space-origin.js +19 -11
  163. package/apps/runtime/dist/services/spaces.js +478 -612
  164. package/apps/runtime/dist/services/synced-spaces.js +668 -0
  165. package/apps/runtime/dist/services/themes.js +15 -15
  166. package/apps/runtime/dist/services/widgets.js +6 -6
  167. package/apps/runtime/dist/services/wizards.js +112 -38
  168. package/apps/runtime/dist/services/work-ai.js +257 -0
  169. package/apps/runtime/dist/services/work-approvals.js +104 -0
  170. package/apps/runtime/dist/services/work-chats.js +908 -0
  171. package/apps/runtime/dist/services/work-connections.js +90 -0
  172. package/apps/runtime/dist/services/work-files.js +85 -0
  173. package/apps/runtime/dist/services/work-mastra.js +73 -0
  174. package/apps/runtime/dist/services/work-sandbox.js +42 -0
  175. package/apps/runtime/dist/sharing/files.js +14 -4
  176. package/apps/runtime/dist/sharing/index.js +40 -39
  177. package/apps/runtime/dist/sharing/jobs.js +67 -17
  178. package/apps/runtime/dist/sharing/targets/connector.js +10 -6
  179. package/apps/runtime/dist/sharing/targets/email.js +10 -8
  180. package/apps/runtime/dist/sharing/targets/slack.js +10 -8
  181. package/apps/runtime/dist/sharing/targets/storage.js +6 -4
  182. package/apps/runtime/dist/store/index.js +14 -3
  183. package/apps/runtime/dist/store/shared-lists.js +4 -2
  184. package/apps/runtime/dist/sync/apply.js +2 -2
  185. package/apps/runtime/dist/sync/client.js +113 -113
  186. package/apps/runtime/dist/sync/hub.js +41 -41
  187. package/apps/runtime/dist/sync/log.js +12 -12
  188. package/apps/runtime/dist/sync/records.js +118 -120
  189. package/apps/runtime/dist/texts.js +38 -2
  190. package/apps/runtime/dist/tools/connections.js +112 -0
  191. package/apps/runtime/dist/tools/connector.js +157 -67
  192. package/apps/runtime/dist/tools/index.js +28 -13
  193. package/apps/runtime/dist/tools/mail.js +40 -11
  194. package/apps/runtime/dist/tools/pages.js +11 -5
  195. package/apps/runtime/dist/tools/plugin.js +43 -7
  196. package/apps/runtime/dist/tools/skills.js +1 -1
  197. package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
  198. package/apps/runtime/dist/tools/store.js +3 -2
  199. package/apps/runtime/dist/widgets/step.js +10 -10
  200. package/apps/web/dist/assets/AboutDialog-DgfeipUc.js +1 -0
  201. package/apps/web/dist/assets/CapabilitiesPage-BoYJvgIu.js +2 -0
  202. package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-Duab4zTO.js} +1 -1
  203. package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
  204. package/apps/web/dist/assets/EditorPage-ZrgGpYMC.js +3 -0
  205. package/apps/web/dist/assets/{FlowPreview-DtSpjVTl.js → FlowPreview-aMfwcPul.js} +1 -1
  206. package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
  207. package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
  208. package/apps/web/dist/assets/NewWizardChannels-IB18afWN.js +1 -0
  209. package/apps/web/dist/assets/NewWizardPage-rYbcmPGG.js +7 -0
  210. package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
  211. package/apps/web/dist/assets/PreviewPane-DviWTLfi.js +9 -0
  212. package/apps/web/dist/assets/PublicRunner-C2geZhhM.js +1 -0
  213. package/apps/web/dist/assets/ReadOnly-kSb_Kbdm.js +1 -0
  214. package/apps/web/dist/assets/SettingsPage-DM2h8N0J.js +2 -0
  215. package/apps/web/dist/assets/SetupPage-Wfyz6xH4.js +1 -0
  216. package/apps/web/dist/assets/SharePage-CyWQorWB.js +1 -0
  217. package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
  218. package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
  219. package/apps/web/dist/assets/SpacePage-q4Bk3N7k.js +2 -0
  220. package/apps/web/dist/assets/UpdateCheck-C2CE6CC3.js +2 -0
  221. package/apps/web/dist/assets/changelog-B6hN1Cp7.js +1 -0
  222. package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
  223. package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
  224. package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
  225. package/apps/web/dist/assets/{code-xml-TwKzzMtA.js → code-xml-B4kLFZSj.js} +1 -1
  226. package/apps/web/dist/assets/connection-sign-in-CIiv0t2p.js +1 -0
  227. package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
  228. package/apps/web/dist/assets/{eye-Brd-xPUJ.js → eye-BpoKpIdt.js} +1 -1
  229. package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
  230. package/apps/web/dist/assets/host-DJ7-p0Sc.js +118 -0
  231. package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
  232. package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
  233. package/apps/web/dist/assets/index-D2akynS-.js +10 -0
  234. package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
  235. package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
  236. package/apps/web/dist/assets/{phone-DhkHteoJ.js → phone-Ctvf-Am-.js} +1 -1
  237. package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
  238. package/apps/web/dist/assets/{runners-G-XYaDgR.js → runners-CyIvJIHr.js} +1 -1
  239. package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
  240. package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
  241. package/apps/web/dist/assets/theme-CbTcTFWy.js +11 -0
  242. package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
  243. package/apps/web/dist/assets/{upload-BYZTwJTD.js → upload-BchUnQGV.js} +1 -1
  244. package/apps/web/dist/assets/{useMutation-D0QP_k2-.js → useMutation-DEkZhp5c.js} +1 -1
  245. package/apps/web/dist/assets/{volume-2-CVHoxdGM.js → volume-2-CU_oy81Z.js} +1 -1
  246. package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
  247. package/apps/web/dist/index.html +17 -10
  248. package/apps/web/dist/mcp/flow.html +119 -64
  249. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
  250. package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -1
  251. package/node_modules/@engenty/wizards-shared/dist/assistant.js +6 -1
  252. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
  253. package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
  254. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +150 -8
  255. package/node_modules/@engenty/wizards-shared/dist/definition.js +46 -11
  256. package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
  257. package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
  258. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +26 -2
  259. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +26 -2
  260. package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
  261. package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
  262. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
  263. package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
  264. package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
  265. package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
  266. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -6
  267. package/node_modules/@engenty/wizards-shared/dist/run.js +85 -0
  268. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
  269. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
  270. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
  271. package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
  272. package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
  273. package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
  274. package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
  275. package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
  276. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
  277. package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
  278. package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
  279. package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
  280. package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
  281. package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
  282. package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
  283. package/package.json +4 -1
  284. package/plugin/.claude-plugin/plugin.json +1 -1
  285. package/plugin/plugin.json +1 -1
  286. package/plugin/skills/build-wizard/SKILL.md +1 -1
  287. package/apps/runtime/dist/services/projects.js +0 -473
  288. package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +0 -1
  289. package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +0 -3
  290. package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +0 -2
  291. package/apps/web/dist/assets/NewWizardChannels-Tgoexgj4.js +0 -1
  292. package/apps/web/dist/assets/NewWizardPage-B24AF482.js +0 -7
  293. package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +0 -1
  294. package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +0 -10
  295. package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +0 -10
  296. package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +0 -1
  297. package/apps/web/dist/assets/ReadOnly-BXjv-MSv.js +0 -1
  298. package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +0 -2
  299. package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +0 -1
  300. package/apps/web/dist/assets/SharePage-DXGzJSnR.js +0 -1
  301. package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +0 -1
  302. package/apps/web/dist/assets/changelog-BLdS-0Bj.js +0 -1
  303. package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
  304. package/apps/web/dist/assets/i18n-8-Sw11tB.js +0 -55
  305. package/apps/web/dist/assets/index-OsdQFHmh.js +0 -49
  306. package/apps/web/dist/assets/index-QPipX5Fi.css +0 -1
  307. package/apps/web/dist/assets/lock-C0uxcOlq.js +0 -1
  308. package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
  309. package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
  310. package/apps/web/dist/assets/session-BWI-KENJ.js +0 -2
  311. package/apps/web/dist/assets/theme-D7krsx0_.js +0 -11
  312. package/apps/web/dist/assets/ui-DSXG3f49.js +0 -83
  313. /package/apps/runtime/dist/db/migrations/tenant/{0027_space_skill.sql → 0030_space_skill.sql} +0 -0
@@ -1,6 +1,7 @@
1
1
  import { formatTableCell } from "@engenty/wizards-shared/engenty/data-tables";
2
2
  import { embedMany } from "ai";
3
3
  import { and, eq, inArray, isNotNull, isNull, sql } from "drizzle-orm";
4
+ import { brokerOn, forbidden, pageResources, readable, readsEverything, tableResources, } from "../broker/rwx.js";
4
5
  import { db, schema, withTenant } from "../db/client.js";
5
6
  import { createSearchChunks } from "../engenty/search-index/chunks.js";
6
7
  import { getBlob, putBlob } from "../files/blobs.js";
@@ -29,7 +30,7 @@ async function embed(texts) {
29
30
  return { vectors: result.embeddings.map((e) => Array.from(e)), model: resolved.ref };
30
31
  }
31
32
  export async function dropIndex(fileId) {
32
- await db.delete(schema.projectChunk).where(eq(schema.projectChunk.fileId, fileId));
33
+ await db.delete(schema.spaceChunk).where(eq(schema.spaceChunk.fileId, fileId));
33
34
  }
34
35
  export async function documentText(file) {
35
36
  return file.textHash ? (await getBlob(file.textHash)).toString("utf8") : "";
@@ -45,11 +46,11 @@ export async function keepText(text) {
45
46
  async function writeUnits(scope, units) {
46
47
  const before = await db
47
48
  .select({
48
- text: schema.projectChunk.text,
49
- embedding: schema.projectChunk.embedding,
50
- model: schema.projectChunk.model,
49
+ text: schema.spaceChunk.text,
50
+ embedding: schema.spaceChunk.embedding,
51
+ model: schema.spaceChunk.model,
51
52
  })
52
- .from(schema.projectChunk)
53
+ .from(schema.spaceChunk)
53
54
  .where(scope);
54
55
  const resolved = await embeddingModel().catch(() => null);
55
56
  const kept = new Map(before
@@ -58,7 +59,7 @@ async function writeUnits(scope, units) {
58
59
  const missing = [...new Set(units.map((u) => u.text).filter((t) => !kept.has(t)))];
59
60
  // Without an embedding model, or when it fails, the keywords still find the unit.
60
61
  const embedded = await embed(missing).catch((err) => {
61
- console.error("[project-index] embedding failed", err);
62
+ console.error("[space-index] embedding failed", err);
62
63
  return null;
63
64
  });
64
65
  if (embedded) {
@@ -67,9 +68,9 @@ async function writeUnits(scope, units) {
67
68
  }
68
69
  }
69
70
  const model = embedded?.model ?? (kept.size ? (resolved?.ref ?? null) : null);
70
- await db.delete(schema.projectChunk).where(scope);
71
+ await db.delete(schema.spaceChunk).where(scope);
71
72
  for (let i = 0; i < units.length; i += 100) {
72
- await db.insert(schema.projectChunk).values(units.slice(i, i + 100).map((u) => {
73
+ await db.insert(schema.spaceChunk).values(units.slice(i, i + 100).map((u) => {
73
74
  const vector = kept.get(u.text) ?? null;
74
75
  return { ...u, embedding: vector, model: vector ? model : null };
75
76
  }));
@@ -144,15 +145,15 @@ function partsOf(body) {
144
145
  }
145
146
  const head = (titles, lines) => [titles.join(" › "), lines.length ? lines.join(" · ") : ""].filter(Boolean).join("\n");
146
147
  async function indexPage(pageId) {
147
- const scope = eq(schema.projectChunk.pageId, pageId);
148
+ const scope = eq(schema.spaceChunk.pageId, pageId);
148
149
  const page = await db.query.spacePage.findFirst({ where: eq(schema.spacePage.id, pageId) });
149
150
  if (!page || page.wizardId) {
150
- await db.delete(schema.projectChunk).where(scope);
151
+ await db.delete(schema.spaceChunk).where(scope);
151
152
  return;
152
153
  }
153
154
  const [tree, categories] = await Promise.all([
154
- pageTree(page.projectId),
155
- categoryRows(page.projectId),
155
+ pageTree(page.spaceId),
156
+ categoryRows(page.spaceId),
156
157
  ]);
157
158
  const node = tree.get(page.id);
158
159
  const lines = categoryLines(categories, (await itemCategoriesOf([{ pageId: page.id }])).get(`p:${page.id}`));
@@ -168,7 +169,7 @@ async function indexPage(pageId) {
168
169
  const heading = path.join(" › ") || null;
169
170
  for (const part of partsOf(section.body)) {
170
171
  units.push({
171
- projectId: page.projectId,
172
+ spaceId: page.spaceId,
172
173
  pageId: page.id,
173
174
  heading,
174
175
  sheet: section.sheet,
@@ -182,10 +183,10 @@ async function indexPage(pageId) {
182
183
  async function indexRows(tableId, rowIds) {
183
184
  const table = await db.query.spaceTable.findFirst({ where: eq(schema.spaceTable.id, tableId) });
184
185
  const scope = rowIds
185
- ? inArray(schema.projectChunk.rowId, rowIds)
186
- : eq(schema.projectChunk.tableId, tableId);
186
+ ? inArray(schema.spaceChunk.rowId, rowIds)
187
+ : eq(schema.spaceChunk.tableId, tableId);
187
188
  if (!table || table.wizardId) {
188
- await db.delete(schema.projectChunk).where(scope);
189
+ await db.delete(schema.spaceChunk).where(scope);
189
190
  return;
190
191
  }
191
192
  const rows = await db.query.spaceTableRow.findMany({
@@ -193,7 +194,7 @@ async function indexRows(tableId, rowIds) {
193
194
  ? and(eq(schema.spaceTableRow.tableId, table.id), inArray(schema.spaceTableRow.id, rowIds))
194
195
  : eq(schema.spaceTableRow.tableId, table.id),
195
196
  });
196
- const categories = await categoryRows(table.projectId);
197
+ const categories = await categoryRows(table.spaceId);
197
198
  const cats = await itemCategoriesOf([
198
199
  { tableId: table.id },
199
200
  ...rows.map((r) => ({ rowId: r.id })),
@@ -211,7 +212,7 @@ async function indexRows(tableId, rowIds) {
211
212
  .join("\n\n")}`
212
213
  : cells.map(([name, v]) => `${name}: ${v}`).join("\n");
213
214
  return {
214
- projectId: table.projectId,
215
+ spaceId: table.spaceId,
215
216
  tableId: table.id,
216
217
  rowId: row.id,
217
218
  heading: table.format === "faq" ? (cells[0]?.[1] ?? null) : null,
@@ -229,12 +230,12 @@ export function indexedFile(file) {
229
230
  }
230
231
  /** An asset stands in the index as one unit: its name, its kind, its categories, its description. */
231
232
  async function indexAsset(file) {
232
- const categories = await categoryRows(file.projectId);
233
+ const categories = await categoryRows(file.spaceId);
233
234
  const lines = categoryLines(categories, (await itemCategoriesOf([{ fileId: file.id }])).get(`f:${file.id}`));
234
235
  const kind = file.mime.split("/")[0];
235
- await writeUnits(eq(schema.projectChunk.fileId, file.id), [
236
+ await writeUnits(eq(schema.spaceChunk.fileId, file.id), [
236
237
  {
237
- projectId: file.projectId,
238
+ spaceId: file.spaceId,
238
239
  fileId: file.id,
239
240
  heading: file.name,
240
241
  idx: 0,
@@ -245,7 +246,7 @@ async function indexAsset(file) {
245
246
  ]);
246
247
  }
247
248
  async function indexFile(fileId) {
248
- const file = await db.query.projectFile.findFirst({ where: eq(schema.projectFile.id, fileId) });
249
+ const file = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, fileId) });
249
250
  if (!(file && indexedFile(file) && file.status === "ready")) {
250
251
  return;
251
252
  }
@@ -260,25 +261,25 @@ async function indexFile(fileId) {
260
261
  where: eq(schema.spaceTable.fileId, file.id),
261
262
  columns: { id: true },
262
263
  }));
263
- const scope = eq(schema.projectChunk.fileId, file.id);
264
+ const scope = eq(schema.spaceChunk.fileId, file.id);
264
265
  if (converted) {
265
266
  // Its text is the page's now; the file stands behind it as the original.
266
- await db.delete(schema.projectChunk).where(scope);
267
+ await db.delete(schema.spaceChunk).where(scope);
267
268
  return;
268
269
  }
269
270
  const passages = await db
270
- .select({ heading: schema.projectChunk.heading, idx: schema.projectChunk.idx })
271
- .from(schema.projectChunk)
271
+ .select({ heading: schema.spaceChunk.heading, idx: schema.spaceChunk.idx })
272
+ .from(schema.spaceChunk)
272
273
  .where(scope);
273
274
  // Passages of a document read before Knowledge had pages stay until it is read again.
274
275
  if (passages.some((p) => p.heading === null)) {
275
276
  return;
276
277
  }
277
- const categories = await categoryRows(file.projectId);
278
+ const categories = await categoryRows(file.spaceId);
278
279
  const lines = categoryLines(categories, (await itemCategoriesOf([{ fileId: file.id }])).get(`f:${file.id}`));
279
280
  await writeUnits(scope, [
280
281
  {
281
- projectId: file.projectId,
282
+ spaceId: file.spaceId,
282
283
  fileId: file.id,
283
284
  heading: file.name,
284
285
  idx: 0,
@@ -287,7 +288,7 @@ async function indexFile(fileId) {
287
288
  ]);
288
289
  }
289
290
  async function indexValue(valueId) {
290
- const scope = eq(schema.projectChunk.valueId, valueId);
291
+ const scope = eq(schema.spaceChunk.valueId, valueId);
291
292
  const value = await db.query.spaceCategoryValue.findFirst({
292
293
  where: eq(schema.spaceCategoryValue.id, valueId),
293
294
  });
@@ -297,11 +298,11 @@ async function indexValue(valueId) {
297
298
  })
298
299
  : undefined;
299
300
  if (!(value?.summary && category)) {
300
- await db.delete(schema.projectChunk).where(scope);
301
+ await db.delete(schema.spaceChunk).where(scope);
301
302
  return;
302
303
  }
303
304
  const units = partsOf(value.summary).map((part, i) => ({
304
- projectId: category.projectId,
305
+ spaceId: category.spaceId,
305
306
  valueId: value.id,
306
307
  heading: `${category.name}: ${value.value}`,
307
308
  idx: i,
@@ -360,7 +361,7 @@ let working = Promise.resolve();
360
361
  function run(tenant, key) {
361
362
  working = working
362
363
  .then(() => withTenant(tenant, () => indexItem(key)))
363
- .catch((err) => console.error(`[project-index] ${key}`, err));
364
+ .catch((err) => console.error(`[space-index] ${key}`, err));
364
365
  }
365
366
  /** Indexes an item a moment from now; a change before then waits again. */
366
367
  export function queueIndex(key) {
@@ -392,14 +393,14 @@ export async function flushIndex() {
392
393
  // --- plugins' texts ---------------------------------------------------------------------
393
394
  /** Puts a plugin's text into the space's index, in the place of what its key held. */
394
395
  export async function putIndexEntry(plugin, entry) {
395
- const space = await db.query.project.findFirst({ where: eq(schema.project.id, entry.space) });
396
+ const space = await db.query.space.findFirst({ where: eq(schema.space.id, entry.space) });
396
397
  if (!space) {
397
398
  throw new ServiceError("not_found", `There is no space "${entry.space}".`);
398
399
  }
399
400
  const text = `${entry.title.trim()}\n\n${entry.text.trim()}`;
400
401
  const chunks = createSearchChunks({ doc_id: `${plugin}:${entry.key}`, text, ...CHUNK }).slice(0, MAX_UNITS);
401
- await writeUnits(and(eq(schema.projectChunk.projectId, entry.space), eq(schema.projectChunk.plugin, plugin), eq(schema.projectChunk.ref, entry.key)), chunks.map((c) => ({
402
- projectId: entry.space,
402
+ await writeUnits(and(eq(schema.spaceChunk.spaceId, entry.space), eq(schema.spaceChunk.plugin, plugin), eq(schema.spaceChunk.ref, entry.key)), chunks.map((c) => ({
403
+ spaceId: entry.space,
403
404
  plugin,
404
405
  ref: entry.key,
405
406
  title: entry.title.trim().slice(0, 300),
@@ -411,18 +412,18 @@ export async function putIndexEntry(plugin, entry) {
411
412
  /** Takes a plugin's text out of the space's index; without a key, all of the plugin's texts. */
412
413
  export async function removeIndexEntries(plugin, space, key) {
413
414
  await db
414
- .delete(schema.projectChunk)
415
- .where(and(eq(schema.projectChunk.projectId, space), eq(schema.projectChunk.plugin, plugin), key === undefined ? undefined : eq(schema.projectChunk.ref, key)));
415
+ .delete(schema.spaceChunk)
416
+ .where(and(eq(schema.spaceChunk.spaceId, space), eq(schema.spaceChunk.plugin, plugin), key === undefined ? undefined : eq(schema.spaceChunk.ref, key)));
416
417
  }
417
418
  /** Whether a plugin the tenant has put a text into the space's index. */
418
- export async function hasIndexEntries(projectId) {
419
+ export async function hasIndexEntries(spaceId) {
419
420
  const plugins = [...(await pluginIdsOf(currentTenant()))];
420
421
  if (!plugins.length) {
421
422
  return false;
422
423
  }
423
- const found = await db.query.projectChunk.findFirst({
424
+ const found = await db.query.spaceChunk.findFirst({
424
425
  columns: { id: true },
425
- where: and(eq(schema.projectChunk.projectId, projectId), inArray(schema.projectChunk.plugin, plugins)),
426
+ where: and(eq(schema.spaceChunk.spaceId, spaceId), inArray(schema.spaceChunk.plugin, plugins)),
426
427
  });
427
428
  return Boolean(found);
428
429
  }
@@ -491,53 +492,95 @@ function itemOf(u) {
491
492
  return `x:${u.plugin}:${u.ref}`;
492
493
  }
493
494
  /**
494
- * Searches Knowledge: items whose categories pass `where`, then the units the keywords, the
495
- * trigrams and the vectors rank best, merged by rank (RRF), then the classifier's judgement of
496
- * each of the CANDIDATES best. Gives up to `limit` items with their best section. `check: false`
497
- * leaves the classifier out.
495
+ * What `who` may read among the units found: a page or file by its own rule, a row by its
496
+ * table's, a value's summary (made of many items) only where they may read everything; a
497
+ * plugin's text is not the broker's yet. Null while the switch is off: everything.
498
498
  */
499
- export async function searchKnowledge(projectId, query, opts = {}) {
499
+ async function readableUnits(spaceId, who, units) {
500
+ if (!(await brokerOn())) {
501
+ return null;
502
+ }
503
+ const ids = (pick) => [
504
+ ...new Set(units.flatMap((u) => (pick(u) ? [pick(u)] : []))),
505
+ ];
506
+ const [pages, tables, files, all] = await Promise.all([
507
+ pageResources(ids((u) => u.page_id)).then((r) => readable(spaceId, who, r)),
508
+ tableResources(ids((u) => u.table_id)).then((r) => readable(spaceId, who, r)),
509
+ readable(spaceId, who, ids((u) => u.file_id).map((id) => ({ kind: "document", id }))),
510
+ readsEverything(spaceId, who),
511
+ ]);
512
+ return (u) => {
513
+ if (u.page_id) {
514
+ return pages.has(u.page_id);
515
+ }
516
+ if (u.row_id) {
517
+ return u.table_id !== null && tables.has(u.table_id);
518
+ }
519
+ if (u.value_id) {
520
+ return all;
521
+ }
522
+ if (u.file_id) {
523
+ return files.has(u.file_id);
524
+ }
525
+ return Boolean(u.plugin);
526
+ };
527
+ }
528
+ /**
529
+ * Searches Knowledge for `who`: items whose categories pass `where` and that they may read, then
530
+ * the units the keywords, the trigrams and the vectors rank best, merged by rank (RRF), then the
531
+ * classifier's judgement of each of the CANDIDATES best. Gives up to `limit` items with their
532
+ * best section. `check: false` leaves the classifier out. While the `broker` switch is on, a call
533
+ * without `who` is refused, and an item they may not read is in no hit, candidate or count.
534
+ */
535
+ export async function searchKnowledge(spaceId, query, opts = {}) {
500
536
  const limit = Math.min(Math.max(1, opts.limit ?? 6), 12);
501
- const filter = await filterItems(projectId, opts.where);
537
+ const on = await brokerOn();
538
+ if (on && !opts.who?.length) {
539
+ throw forbidden({ kind: "document", id: "*" }, "r");
540
+ }
541
+ const filter = await filterItems(spaceId, opts.where);
502
542
  if (filter && !filter.size) {
503
543
  return { hits: [], candidates: 0, checked: false, filtered: 0 };
504
544
  }
505
545
  const plugins = [...(await pluginIdsOf(currentTenant()))];
506
546
  const inFilter = filter ? filtered(filter) : null;
507
547
  // A filter keeps plugins' texts and summaries out: they have no categories.
508
- const where = and(sql `c.project_id = ${projectId}`, searchable(plugins), filter
548
+ const where = and(sql `c.space_id = ${spaceId}`, searchable(plugins), filter
509
549
  ? (inFilter ?? sql `(c.page_id IS NOT NULL OR c.row_id IS NOT NULL OR c.file_id IS NOT NULL)`)
510
550
  : undefined);
511
- const take = filter && !inFilter ? 300 : CANDIDATES;
551
+ // What the rules or a long filter take out afterwards must not starve the candidates.
552
+ const take = on || (filter && !inFilter) ? 300 : CANDIDATES;
512
553
  const lists = [];
513
554
  const words = keywordQuery(query);
514
555
  if (words) {
515
556
  lists.push(await db.all(sql `
516
- SELECT ${COLUMNS} FROM project_chunk_fts f JOIN project_chunk c ON c.id = f.rowid
517
- WHERE project_chunk_fts MATCH ${words} AND ${where}
518
- ORDER BY bm25(project_chunk_fts) LIMIT ${take}`));
557
+ SELECT ${COLUMNS} FROM space_chunk_fts f JOIN space_chunk c ON c.id = f.rowid
558
+ WHERE space_chunk_fts MATCH ${words} AND ${where}
559
+ ORDER BY bm25(space_chunk_fts) LIMIT ${take}`));
519
560
  }
520
561
  const grams = trigramQuery(query);
521
562
  if (grams) {
522
563
  lists.push(await db
523
564
  .all(sql `
524
- SELECT ${COLUMNS} FROM project_chunk_tri f JOIN project_chunk c ON c.id = f.rowid
525
- WHERE project_chunk_tri MATCH ${grams} AND ${where}
526
- ORDER BY bm25(project_chunk_tri) LIMIT ${take}`)
565
+ SELECT ${COLUMNS} FROM space_chunk_tri f JOIN space_chunk c ON c.id = f.rowid
566
+ WHERE space_chunk_tri MATCH ${grams} AND ${where}
567
+ ORDER BY bm25(space_chunk_tri) LIMIT ${take}`)
527
568
  .catch(() => []));
528
569
  }
529
570
  const embedded = await embed([query]).catch(() => null);
530
571
  if (embedded) {
531
572
  lists.push(await db.all(sql `
532
- SELECT ${COLUMNS} FROM project_chunk c
573
+ SELECT ${COLUMNS} FROM space_chunk c
533
574
  WHERE ${where} AND c.model = ${embedded.model}
534
575
  ORDER BY vector_distance_cos(c.embedding, ${vectorBytes(embedded.vectors[0])}) LIMIT ${take}`));
535
576
  }
577
+ const allowed = await readableUnits(spaceId, opts.who ?? [], lists.flat());
536
578
  // Reciprocal rank fusion: a unit the lists rank high comes first.
537
579
  const scored = new Map();
538
580
  for (const list of lists) {
539
581
  list
540
582
  .filter((u) => !filter || inFilter || leaves(filter, u))
583
+ .filter((u) => !allowed || allowed(u))
541
584
  .slice(0, CANDIDATES)
542
585
  .forEach((unit, rank) => {
543
586
  const entry = scored.get(unit.id) ?? { unit, score: 0 };
@@ -549,7 +592,7 @@ export async function searchKnowledge(projectId, query, opts = {}) {
549
592
  if (!candidates.length) {
550
593
  return { hits: [], candidates: 0, checked: false, filtered: filter?.size ?? null };
551
594
  }
552
- const described = await describe(projectId, candidates.map((c) => c.unit));
595
+ const described = await describe(spaceId, candidates.map((c) => c.unit));
553
596
  const judged = opts.check === false
554
597
  ? null
555
598
  : await judgeRelevance(query, described.map((d) => ({
@@ -586,16 +629,16 @@ export async function searchKnowledge(projectId, query, opts = {}) {
586
629
  };
587
630
  }
588
631
  /** What a step and the studio see of each unit: the item's path, title and categories. */
589
- async function describe(projectId, units) {
632
+ async function describe(spaceId, units) {
590
633
  const pageIds = [...new Set(units.flatMap((u) => (u.page_id ? [u.page_id] : [])))];
591
634
  const rowIds = [...new Set(units.flatMap((u) => (u.row_id ? [u.row_id] : [])))];
592
635
  const fileIds = [...new Set(units.flatMap((u) => (u.file_id ? [u.file_id] : [])))];
593
636
  const valueIds = [...new Set(units.flatMap((u) => (u.value_id ? [u.value_id] : [])))];
594
637
  const [tree, tPaths, fPaths, categories, rows, files, values] = await Promise.all([
595
- pageIds.length ? pageTree(projectId) : new Map(),
596
- rowIds.length ? tablePaths(projectId) : new Map(),
597
- fileIds.length ? filePaths(projectId) : new Map(),
598
- categoryRows(projectId),
638
+ pageIds.length ? pageTree(spaceId) : new Map(),
639
+ rowIds.length ? tablePaths(spaceId) : new Map(),
640
+ fileIds.length ? filePaths(spaceId) : new Map(),
641
+ categoryRows(spaceId),
599
642
  rowIds.length
600
643
  ? db.query.spaceTableRow.findMany({
601
644
  where: inArray(schema.spaceTableRow.id, rowIds),
@@ -603,8 +646,8 @@ async function describe(projectId, units) {
603
646
  })
604
647
  : [],
605
648
  fileIds.length
606
- ? db.query.projectFile.findMany({
607
- where: inArray(schema.projectFile.id, fileIds),
649
+ ? db.query.spaceFile.findMany({
650
+ where: inArray(schema.spaceFile.id, fileIds),
608
651
  columns: { id: true, name: true },
609
652
  })
610
653
  : [],
@@ -698,25 +741,25 @@ async function describe(projectId, units) {
698
741
  });
699
742
  }
700
743
  /** Puts every item of a space into the index again: after a sync, or a change of embedding model. */
701
- export async function reindexSpace(projectId) {
744
+ export async function reindexSpace(spaceId) {
702
745
  const [pages, tables, files, values] = await Promise.all([
703
746
  db.query.spacePage.findMany({
704
- where: and(eq(schema.spacePage.projectId, projectId), isNull(schema.spacePage.wizardId)),
747
+ where: and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId)),
705
748
  columns: { id: true },
706
749
  }),
707
750
  db.query.spaceTable.findMany({
708
- where: and(eq(schema.spaceTable.projectId, projectId), isNull(schema.spaceTable.wizardId)),
751
+ where: and(eq(schema.spaceTable.spaceId, spaceId), isNull(schema.spaceTable.wizardId)),
709
752
  columns: { id: true },
710
753
  }),
711
- db.query.projectFile.findMany({
712
- where: and(eq(schema.projectFile.projectId, projectId), inArray(schema.projectFile.kind, ["document", "asset"])),
754
+ db.query.spaceFile.findMany({
755
+ where: and(eq(schema.spaceFile.spaceId, spaceId), inArray(schema.spaceFile.kind, ["document", "asset"])),
713
756
  columns: { id: true, kind: true, mime: true },
714
757
  }),
715
758
  db
716
759
  .select({ id: schema.spaceCategoryValue.id })
717
760
  .from(schema.spaceCategoryValue)
718
761
  .innerJoin(schema.spaceCategory, eq(schema.spaceCategory.id, schema.spaceCategoryValue.categoryId))
719
- .where(and(eq(schema.spaceCategory.projectId, projectId), isNotNull(schema.spaceCategoryValue.summary))),
762
+ .where(and(eq(schema.spaceCategory.spaceId, spaceId), isNotNull(schema.spaceCategoryValue.summary))),
720
763
  ]);
721
764
  for (const p of pages) {
722
765
  queueIndex(`p:${p.id}`);
@@ -733,17 +776,17 @@ export async function reindexSpace(projectId) {
733
776
  }
734
777
  /** Every space into the index again, with the embedding model that is set up now. */
735
778
  export async function reindexAll() {
736
- const projects = await db.query.project.findMany({ columns: { id: true } });
737
- for (const p of projects) {
779
+ const spaces = await db.query.space.findMany({ columns: { id: true } });
780
+ for (const p of spaces) {
738
781
  await reindexSpace(p.id);
739
782
  }
740
783
  }
741
784
  /** The image, video and sound assets the index does not hold yet: added at start, once each. */
742
785
  export async function indexMissingAssets() {
743
786
  const rows = await db.all(sql `
744
- SELECT f.id, f.kind, f.mime FROM project_file f
787
+ SELECT f.id, f.kind, f.mime FROM space_file f
745
788
  WHERE f.kind = 'asset' AND f.status = 'ready'
746
- AND NOT EXISTS (SELECT 1 FROM project_chunk c WHERE c.file_id = f.id)`);
789
+ AND NOT EXISTS (SELECT 1 FROM space_chunk c WHERE c.file_id = f.id)`);
747
790
  for (const row of rows.filter(indexedFile)) {
748
791
  queueIndex(`f:${row.id}`);
749
792
  }
@@ -1,13 +1,15 @@
1
1
  import { and, desc, eq, isNull } from "drizzle-orm";
2
+ import { currentCaller } from "../broker/caller.js";
3
+ import { currentReader, subjectsOfCaller } from "../broker/rwx.js";
2
4
  import { db, schema } from "../db/client.js";
3
5
  import { UnreadableDocument } from "../documents/parse.js";
4
6
  import { ServiceError } from "./errors.js";
5
7
  import { filePaths, pageTree, tablePaths } from "./knowledge.js";
6
8
  import { convertDocument, fillCategories, summarizeValues } from "./knowledge-model.js";
7
- import { projectFileContent, putOriginFile } from "./project-files.js";
8
- import { queueIndex } from "./project-index.js";
9
9
  import { putCategory, setItemCategories } from "./space-categories.js";
10
10
  import { listOrigin, putOriginPage, putOriginTable, removeOrigin } from "./space-data.js";
11
+ import { putOriginFile, spaceFileContent } from "./space-files.js";
12
+ import { queueIndex } from "./space-index.js";
11
13
  /**
12
14
  * `server.spaceData` of a plugin: Knowledge it writes under keys of its own, with categories. The
13
15
  * plugin's id is the origin of everything it writes; a person who changes an item keeps it.
@@ -19,7 +21,7 @@ export function originData(origin) {
19
21
  let tableId = null;
20
22
  if (c.column) {
21
23
  const table = await db.query.spaceTable.findFirst({
22
- where: and(eq(schema.spaceTable.projectId, space), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.originKey, c.column.table)),
24
+ where: and(eq(schema.spaceTable.spaceId, space), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.originKey, c.column.table)),
23
25
  columns: { id: true },
24
26
  });
25
27
  if (!table) {
@@ -72,7 +74,7 @@ export function originData(origin) {
72
74
  },
73
75
  async putDocument(input) {
74
76
  const id = await putOriginFile(origin, { ...input, categories: undefined });
75
- const file = await db.query.projectFile.findFirst({ where: eq(schema.projectFile.id, id) });
77
+ const file = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, id) });
76
78
  if (!file) {
77
79
  throw new ServiceError("not_found", "The document was removed while it was being read.");
78
80
  }
@@ -100,14 +102,14 @@ export function originData(origin) {
100
102
  throw err;
101
103
  }
102
104
  await db
103
- .update(schema.projectFile)
105
+ .update(schema.spaceFile)
104
106
  .set({
105
107
  textHash: converted.textHash,
106
108
  pages: converted.pages,
107
109
  chars: converted.chars,
108
110
  updatedAt: new Date(),
109
111
  })
110
- .where(eq(schema.projectFile.id, id));
112
+ .where(eq(schema.spaceFile.id, id));
111
113
  const [tree, tables] = await Promise.all([pageTree(input.space), tablePaths(input.space)]);
112
114
  const items = await Promise.all(converted.items.map(async (key) => {
113
115
  const itemId = key.slice(2);
@@ -160,7 +162,7 @@ export function originData(origin) {
160
162
  async readPages(space, opts) {
161
163
  const tree = await pageTree(space);
162
164
  const rows = await db.query.spacePage.findMany({
163
- where: and(eq(schema.spacePage.projectId, space), isNull(schema.spacePage.wizardId), opts?.parent ? eq(schema.spacePage.parentId, opts.parent) : undefined),
165
+ where: and(eq(schema.spacePage.spaceId, space), isNull(schema.spacePage.wizardId), opts?.parent ? eq(schema.spacePage.parentId, opts.parent) : undefined),
164
166
  orderBy: [schema.spacePage.position, schema.spacePage.title],
165
167
  });
166
168
  return rows.map((r) => ({
@@ -175,9 +177,9 @@ export function originData(origin) {
175
177
  }));
176
178
  },
177
179
  async files(space, kind = "document") {
178
- const rows = await db.query.projectFile.findMany({
179
- where: and(eq(schema.projectFile.projectId, space), eq(schema.projectFile.kind, kind), eq(schema.projectFile.status, "ready")),
180
- orderBy: [desc(schema.projectFile.updatedAt)],
180
+ const rows = await db.query.spaceFile.findMany({
181
+ where: and(eq(schema.spaceFile.spaceId, space), eq(schema.spaceFile.kind, kind), eq(schema.spaceFile.status, "ready")),
182
+ orderBy: [desc(schema.spaceFile.updatedAt)],
181
183
  });
182
184
  return rows.map((r) => ({
183
185
  id: r.id,
@@ -189,7 +191,13 @@ export function originData(origin) {
189
191
  }));
190
192
  },
191
193
  async readFile(space, fileId) {
192
- const { row, data } = await projectFileContent(space, fileId);
194
+ // As whom the plugin was called for, and as itself: a tool in a step or a Work chat as its
195
+ // caller, an HTTP route as the person it answers, a job as the runtime itself (readingAs).
196
+ // Anything else reads as the plugin alone, which no seed allows. A deny for it always wins.
197
+ const caller = currentCaller();
198
+ const plugin = { kind: "plugin", id: origin };
199
+ const who = [...(caller ? await subjectsOfCaller(caller) : currentReader()), plugin];
200
+ const { row, data } = await spaceFileContent(space, fileId, who);
193
201
  return {
194
202
  id: row.id,
195
203
  name: row.name,