@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
@@ -4,23 +4,24 @@ import { editCells, SPACE_DATA_LIMITS, } from "@engenty/wizards-shared/space-dat
4
4
  import { rowKey } from "@engenty/wizards-shared/store";
5
5
  import { and, asc, count, desc, eq, inArray, isNotNull, isNull, max } from "drizzle-orm";
6
6
  import { nanoid } from "nanoid";
7
+ import { assertRwx, pageResources, readable, tableResources } from "../broker/rwx.js";
7
8
  import { db, schema } from "../db/client.js";
8
9
  import { saidOf } from "../model-errors.js";
9
10
  import { currentTenant } from "../tenants/tenant.js";
10
11
  import { serverText } from "../texts.js";
11
- import { projectWritable, requireWritableProject } from "./access.js";
12
+ import { requireWritableSpace, spaceWritable } from "./access.js";
12
13
  import { notFound, ServiceError } from "./errors.js";
13
14
  import { filePaths, freeSlug, knowledgePage, pageTree, tablePaths } from "./knowledge.js";
14
- import { queueIndex } from "./project-index.js";
15
- import { ownedProject } from "./projects.js";
16
15
  import { itemCategoriesOf, setItemCategories, syncTableRowCategories } from "./space-categories.js";
16
+ import { queueIndex } from "./space-index.js";
17
+ import { ownedSpace } from "./spaces.js";
17
18
  /** A wizard of the space, or null for the space's own. */
18
- async function ownerOf(projectId, wizardId) {
19
+ async function ownerOf(spaceId, wizardId) {
19
20
  if (!wizardId) {
20
21
  return null;
21
22
  }
22
23
  const w = await db.query.wizard.findFirst({
23
- where: and(eq(schema.wizard.id, wizardId), eq(schema.wizard.projectId, projectId)),
24
+ where: and(eq(schema.wizard.id, wizardId), eq(schema.wizard.spaceId, spaceId)),
24
25
  columns: { id: true },
25
26
  });
26
27
  if (!w) {
@@ -41,12 +42,15 @@ export function checkColumns(columns) {
41
42
  }
42
43
  return parsed.data;
43
44
  }
44
- /** Data: the tables and pages the space's wizards keep, and the wizards to name whose they are. */
45
- export async function listSpaceData(userId, projectId) {
46
- const project = await ownedProject(userId, projectId);
45
+ /**
46
+ * Data: the tables and pages the space's wizards keep that `who` may read, and the wizards to
47
+ * name whose they are.
48
+ */
49
+ export async function listSpaceData(userId, spaceId, who) {
50
+ const space = await ownedSpace(userId, spaceId);
47
51
  const [tables, rows, pages, wizards] = await Promise.all([
48
52
  db.query.spaceTable.findMany({
49
- where: and(eq(schema.spaceTable.projectId, project.id), isNotNull(schema.spaceTable.wizardId)),
53
+ where: and(eq(schema.spaceTable.spaceId, space.id), isNotNull(schema.spaceTable.wizardId)),
50
54
  orderBy: [asc(schema.spaceTable.title)],
51
55
  columns: { id: true, wizardId: true, list: true, title: true, updatedAt: true },
52
56
  }),
@@ -54,26 +58,34 @@ export async function listSpaceData(userId, projectId) {
54
58
  .select({ tableId: schema.spaceTableRow.tableId, n: count() })
55
59
  .from(schema.spaceTableRow)
56
60
  .innerJoin(schema.spaceTable, eq(schema.spaceTable.id, schema.spaceTableRow.tableId))
57
- .where(eq(schema.spaceTable.projectId, project.id))
61
+ .where(eq(schema.spaceTable.spaceId, space.id))
58
62
  .groupBy(schema.spaceTableRow.tableId),
59
63
  db.query.spacePage.findMany({
60
- where: and(eq(schema.spacePage.projectId, project.id), isNotNull(schema.spacePage.wizardId)),
64
+ where: and(eq(schema.spacePage.spaceId, space.id), isNotNull(schema.spacePage.wizardId)),
61
65
  orderBy: [asc(schema.spacePage.title)],
62
66
  columns: { id: true, wizardId: true, title: true, updatedAt: true },
63
67
  }),
64
68
  db.query.wizard.findMany({
65
- where: eq(schema.wizard.projectId, project.id),
69
+ where: eq(schema.wizard.spaceId, space.id),
66
70
  orderBy: [desc(schema.wizard.updatedAt)],
67
71
  columns: { id: true, title: true },
68
72
  }),
69
73
  ]);
74
+ const [okTables, okPages] = await Promise.all([
75
+ readable(space.id, who, await tableResources(tables.map((t) => t.id))),
76
+ readable(space.id, who, await pageResources(pages.map((p) => p.id))),
77
+ ]);
70
78
  return {
71
- tables: tables.map((t) => ({
79
+ tables: tables
80
+ .filter((t) => okTables.has(t.id))
81
+ .map((t) => ({
72
82
  ...t,
73
83
  rows: rows.find((r) => r.tableId === t.id)?.n ?? 0,
74
84
  updatedAt: t.updatedAt.toISOString(),
75
85
  })),
76
- pages: pages.map((p) => ({ ...p, updatedAt: p.updatedAt.toISOString() })),
86
+ pages: pages
87
+ .filter((p) => okPages.has(p.id))
88
+ .map((p) => ({ ...p, updatedAt: p.updatedAt.toISOString() })),
77
89
  wizards,
78
90
  };
79
91
  }
@@ -89,7 +101,7 @@ async function tableRow(tableId) {
89
101
  }
90
102
  async function writableTable(tableId) {
91
103
  const table = await tableRow(tableId);
92
- await requireWritableProject(table.projectId);
104
+ await requireWritableSpace(table.spaceId);
93
105
  return table;
94
106
  }
95
107
  /** A person changed a table: when a plugin wrote it, the plugin no longer does. */
@@ -99,19 +111,19 @@ async function touchTable(table) {
99
111
  .set({ updatedAt: new Date(), ...(table.origin && !table.kept ? { kept: true } : {}) })
100
112
  .where(eq(schema.spaceTable.id, table.id));
101
113
  }
102
- async function tableCount(projectId) {
114
+ async function tableCount(spaceId) {
103
115
  const [{ n }] = await db
104
116
  .select({ n: count() })
105
117
  .from(schema.spaceTable)
106
- .where(eq(schema.spaceTable.projectId, projectId));
118
+ .where(eq(schema.spaceTable.spaceId, spaceId));
107
119
  if (n >= SPACE_DATA_LIMITS.tables) {
108
120
  throw new ServiceError("refused", note("spaceMostTables", { count: SPACE_DATA_LIMITS.tables }));
109
121
  }
110
122
  }
111
- export async function createTable(userId, projectId, input, lang = "en") {
112
- const project = await ownedProject(userId, projectId);
113
- await requireWritableProject(project.id);
114
- await tableCount(project.id);
123
+ export async function createTable(userId, spaceId, input, lang = "en") {
124
+ const space = await ownedSpace(userId, spaceId);
125
+ await requireWritableSpace(space.id);
126
+ await tableCount(space.id);
115
127
  const columns = input.columns
116
128
  ? checkColumns(input.columns)
117
129
  : input.format === "faq"
@@ -126,15 +138,15 @@ export async function createTable(userId, projectId, input, lang = "en") {
126
138
  ]
127
139
  : [{ id: "name", name: "Name", type: "text" }];
128
140
  const id = nanoid(12);
129
- const wizardId = await ownerOf(project.id, input.wizardId);
141
+ const wizardId = await ownerOf(space.id, input.wizardId);
130
142
  const title = input.title.trim() || serverText(lang, "tableTitle");
131
143
  await db.insert(schema.spaceTable).values({
132
144
  id,
133
145
  tenantId: currentTenant(),
134
- projectId: project.id,
146
+ spaceId: space.id,
135
147
  wizardId,
136
148
  title,
137
- slug: wizardId ? null : await freeSlug(project.id, title, "table"),
149
+ slug: wizardId ? null : await freeSlug(space.id, title, "table"),
138
150
  format: input.format ?? null,
139
151
  columns,
140
152
  });
@@ -145,13 +157,13 @@ async function tableKnowledge(table) {
145
157
  return null;
146
158
  }
147
159
  const file = table.fileId
148
- ? await db.query.projectFile.findFirst({
149
- where: eq(schema.projectFile.id, table.fileId),
160
+ ? await db.query.spaceFile.findFirst({
161
+ where: eq(schema.spaceFile.id, table.fileId),
150
162
  columns: { id: true, name: true, mime: true },
151
163
  })
152
164
  : undefined;
153
165
  return {
154
- path: (await tablePaths(table.projectId)).get(table.id) ?? "",
166
+ path: (await tablePaths(table.spaceId)).get(table.id) ?? "",
155
167
  categories: (await itemCategoriesOf([{ tableId: table.id }])).get(`t:${table.id}`) ?? [],
156
168
  origin: table.origin,
157
169
  originLabel: table.originLabel,
@@ -160,8 +172,8 @@ async function tableKnowledge(table) {
160
172
  file: file ?? null,
161
173
  };
162
174
  }
163
- export async function getTable(userId, tableId) {
164
- const header = await getTableHeader(userId, tableId);
175
+ export async function getTable(userId, tableId, who) {
176
+ const header = await getTableHeader(userId, tableId, who);
165
177
  const rows = await db.query.spaceTableRow.findMany({
166
178
  where: eq(schema.spaceTableRow.tableId, header.id),
167
179
  orderBy: [asc(schema.spaceTableRow.createdAt), asc(schema.spaceTableRow.id)],
@@ -169,24 +181,26 @@ export async function getTable(userId, tableId) {
169
181
  return { ...header, rows: rows.map(rowView) };
170
182
  }
171
183
  /** A table without its rows: what a change of its title or columns needs (live/views.ts). */
172
- export async function getTableHeader(userId, tableId) {
184
+ export async function getTableHeader(userId, tableId, who) {
173
185
  const table = await tableRow(tableId);
174
- const project = await ownedProject(userId, table.projectId);
186
+ const space = await ownedSpace(userId, table.spaceId);
187
+ await assertRwx(space.id, who, { kind: "table", id: table.id, fileId: table.fileId }, "r");
175
188
  return {
176
189
  id: table.id,
177
- projectId: table.projectId,
190
+ spaceId: table.spaceId,
178
191
  wizardId: table.wizardId,
179
192
  list: table.list,
180
193
  title: table.title,
181
194
  format: table.format,
182
195
  columns: table.columns,
183
- readOnly: !(await projectWritable(project)),
196
+ readOnly: !(await spaceWritable(space)),
184
197
  knowledge: await tableKnowledge(table),
185
198
  };
186
199
  }
187
200
  /** One row of a table, as the table shows it; null when it is gone. */
188
- export async function getRow(_userId, tableId, rowId) {
189
- await tableRow(tableId);
201
+ export async function getRow(_userId, tableId, rowId, who) {
202
+ const table = await tableRow(tableId);
203
+ await assertRwx(table.spaceId, who, { kind: "table", id: table.id, fileId: table.fileId }, "r");
190
204
  const row = await db.query.spaceTableRow.findFirst({
191
205
  where: and(eq(schema.spaceTableRow.id, rowId), eq(schema.spaceTableRow.tableId, tableId)),
192
206
  });
@@ -207,7 +221,7 @@ export async function updateTable(_userId, tableId, patch) {
207
221
  throw new ServiceError("refused", note("tableBelongsOneWizard"));
208
222
  }
209
223
  const title = patch.title !== undefined ? patch.title.trim() || table.title : table.title;
210
- const wizardId = patch.wizardId !== undefined ? await ownerOf(table.projectId, patch.wizardId) : table.wizardId;
224
+ const wizardId = patch.wizardId !== undefined ? await ownerOf(table.spaceId, patch.wizardId) : table.wizardId;
211
225
  const changed = title !== table.title || patch.columns !== undefined || patch.format !== undefined;
212
226
  await db
213
227
  .update(schema.spaceTable)
@@ -215,7 +229,7 @@ export async function updateTable(_userId, tableId, patch) {
215
229
  title,
216
230
  wizardId,
217
231
  ...(title !== table.title || wizardId !== table.wizardId
218
- ? { slug: wizardId ? null : await freeSlug(table.projectId, title, "table", table.id) }
232
+ ? { slug: wizardId ? null : await freeSlug(table.spaceId, title, "table", table.id) }
219
233
  : {}),
220
234
  ...(patch.columns !== undefined ? { columns: checkColumns(patch.columns) } : {}),
221
235
  ...(patch.format !== undefined ? { format: patch.format } : {}),
@@ -242,8 +256,8 @@ async function dropOriginal(item) {
242
256
  columns: { id: true },
243
257
  }));
244
258
  if (!used) {
245
- const { removeProjectFile } = await import("./project-files.js");
246
- await removeProjectFile(item.projectId, item.fileId).catch(() => undefined);
259
+ const { removeSpaceFile } = await import("./space-files.js");
260
+ await removeSpaceFile(item.spaceId, item.fileId).catch(() => undefined);
247
261
  }
248
262
  }
249
263
  export async function deleteTable(_userId, tableId) {
@@ -358,22 +372,22 @@ function checkMarkdown(markdown) {
358
372
  }
359
373
  return markdown;
360
374
  }
361
- async function pageCount(projectId, more = 1) {
375
+ async function pageCount(spaceId, more = 1) {
362
376
  const [{ n }] = await db
363
377
  .select({ n: count() })
364
378
  .from(schema.spacePage)
365
- .where(eq(schema.spacePage.projectId, projectId));
379
+ .where(eq(schema.spacePage.spaceId, spaceId));
366
380
  if (n + more > SPACE_DATA_LIMITS.pages) {
367
381
  throw new ServiceError("refused", note("spaceMostPages", { count: SPACE_DATA_LIMITS.pages }));
368
382
  }
369
383
  }
370
384
  /** A page of the space's own that a sub-page may stand under: never one of its own sub-pages. */
371
- async function parentOf(projectId, parentId, pageId) {
385
+ async function parentOf(spaceId, parentId, pageId) {
372
386
  if (!parentId) {
373
387
  return null;
374
388
  }
375
389
  const parent = await db.query.spacePage.findFirst({
376
- where: and(eq(schema.spacePage.id, parentId), eq(schema.spacePage.projectId, projectId)),
390
+ where: and(eq(schema.spacePage.id, parentId), eq(schema.spacePage.spaceId, spaceId)),
377
391
  columns: { id: true, wizardId: true, parentId: true },
378
392
  });
379
393
  if (!parent || parent.wizardId) {
@@ -391,30 +405,30 @@ async function parentOf(projectId, parentId, pageId) {
391
405
  }
392
406
  return parent.id;
393
407
  }
394
- async function nextPosition(projectId, parentId) {
408
+ async function nextPosition(spaceId, parentId) {
395
409
  const [{ last }] = await db
396
410
  .select({ last: max(schema.spacePage.position) })
397
411
  .from(schema.spacePage)
398
- .where(and(eq(schema.spacePage.projectId, projectId), isNull(schema.spacePage.wizardId), parentId ? eq(schema.spacePage.parentId, parentId) : isNull(schema.spacePage.parentId)));
412
+ .where(and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId), parentId ? eq(schema.spacePage.parentId, parentId) : isNull(schema.spacePage.parentId)));
399
413
  return (last ?? -1) + 1;
400
414
  }
401
- export async function createPage(userId, projectId, input) {
402
- const project = await ownedProject(userId, projectId);
403
- await requireWritableProject(project.id);
404
- await pageCount(project.id);
415
+ export async function createPage(userId, spaceId, input) {
416
+ const space = await ownedSpace(userId, spaceId);
417
+ await requireWritableSpace(space.id);
418
+ await pageCount(space.id);
405
419
  const id = nanoid(12);
406
- const wizardId = await ownerOf(project.id, input.wizardId);
407
- const parentId = wizardId ? null : await parentOf(project.id, input.parentId);
420
+ const wizardId = await ownerOf(space.id, input.wizardId);
421
+ const parentId = wizardId ? null : await parentOf(space.id, input.parentId);
408
422
  const title = input.title.trim() || "Seite";
409
423
  await db.insert(schema.spacePage).values({
410
424
  id,
411
425
  tenantId: currentTenant(),
412
- projectId: project.id,
426
+ spaceId: space.id,
413
427
  wizardId,
414
428
  parentId,
415
- position: wizardId ? 0 : await nextPosition(project.id, parentId),
429
+ position: wizardId ? 0 : await nextPosition(space.id, parentId),
416
430
  title,
417
- slug: wizardId ? null : await freeSlug(project.id, title, { parentId }),
431
+ slug: wizardId ? null : await freeSlug(space.id, title, { parentId }),
418
432
  markdown: checkMarkdown(input.markdown ?? ""),
419
433
  });
420
434
  if (!wizardId) {
@@ -422,17 +436,22 @@ export async function createPage(userId, projectId, input) {
422
436
  }
423
437
  return { id };
424
438
  }
425
- export async function getPage(userId, pageId) {
439
+ export async function getPage(userId, pageId, who) {
426
440
  const page = await pageRow(pageId);
427
- const project = await ownedProject(userId, page.projectId);
441
+ const space = await ownedSpace(userId, page.spaceId);
442
+ await assertRwx(space.id, who, { kind: "page", id: page.id, fileId: page.fileId }, "r");
443
+ return pageView(page, space);
444
+ }
445
+ /** A page as the studio shows it, for one that was just read or written. */
446
+ async function pageView(page, space) {
428
447
  return {
429
448
  id: page.id,
430
- projectId: page.projectId,
449
+ spaceId: page.spaceId,
431
450
  wizardId: page.wizardId,
432
451
  title: page.title,
433
452
  markdown: page.markdown,
434
453
  updatedAt: page.updatedAt.toISOString(),
435
- readOnly: !(await projectWritable(project)),
454
+ readOnly: !(await spaceWritable(space)),
436
455
  knowledge: page.wizardId ? null : await knowledgePage(page),
437
456
  };
438
457
  }
@@ -442,18 +461,18 @@ export async function getPage(userId, pageId) {
442
461
  */
443
462
  export async function updatePage(_userId, pageId, patch) {
444
463
  const page = await pageRow(pageId);
445
- await requireWritableProject(page.projectId);
464
+ await requireWritableSpace(page.spaceId);
446
465
  if (patch.baseUpdatedAt && page.updatedAt.getTime() > Date.parse(patch.baseUpdatedAt)) {
447
466
  throw new ServiceError("revision_conflict", note("itemChangedMeantime"), {
448
- page: await getPage(_userId, pageId),
467
+ page: await pageView(page, await ownedSpace(_userId, page.spaceId)),
449
468
  });
450
469
  }
451
470
  const title = patch.title !== undefined ? patch.title.trim() || page.title : page.title;
452
- const wizardId = patch.wizardId !== undefined ? await ownerOf(page.projectId, patch.wizardId) : page.wizardId;
471
+ const wizardId = patch.wizardId !== undefined ? await ownerOf(page.spaceId, patch.wizardId) : page.wizardId;
453
472
  const parentId = wizardId !== null
454
473
  ? null
455
474
  : patch.parentId !== undefined
456
- ? await parentOf(page.projectId, patch.parentId, page.id)
475
+ ? await parentOf(page.spaceId, patch.parentId, page.id)
457
476
  : page.parentId;
458
477
  const moved = title !== page.title || wizardId !== page.wizardId || parentId !== page.parentId;
459
478
  const edited = moved || (patch.markdown !== undefined && patch.markdown !== page.markdown);
@@ -466,9 +485,9 @@ export async function updatePage(_userId, pageId, patch) {
466
485
  parentId,
467
486
  ...(moved
468
487
  ? {
469
- slug: wizardId ? null : await freeSlug(page.projectId, title, { parentId }, page.id),
488
+ slug: wizardId ? null : await freeSlug(page.spaceId, title, { parentId }, page.id),
470
489
  ...(parentId !== page.parentId
471
- ? { position: await nextPosition(page.projectId, parentId) }
490
+ ? { position: await nextPosition(page.spaceId, parentId) }
472
491
  : {}),
473
492
  }
474
493
  : {}),
@@ -488,14 +507,14 @@ export async function updatePage(_userId, pageId, patch) {
488
507
  }
489
508
  export async function deletePage(_userId, pageId) {
490
509
  const page = await pageRow(pageId);
491
- await requireWritableProject(page.projectId);
510
+ await requireWritableSpace(page.spaceId);
492
511
  await db.delete(schema.spacePage).where(eq(schema.spacePage.id, page.id));
493
512
  await dropOriginal(page);
494
513
  }
495
514
  /** Puts a page's sub-pages into the order of `ids`. */
496
515
  export async function orderSubPages(_userId, pageId, ids) {
497
516
  const page = await pageRow(pageId);
498
- await requireWritableProject(page.projectId);
517
+ await requireWritableSpace(page.spaceId);
499
518
  for (const [position, id] of ids.entries()) {
500
519
  await db
501
520
  .update(schema.spacePage)
@@ -508,21 +527,21 @@ export async function orderSubPages(_userId, pageId, ids) {
508
527
  // the server's, also in a space a local install synced, which the studio there only shows. It
509
528
  // reads its wizard's pages; the space's own are Knowledge, read by path.
510
529
  /** The pages of a run's wizard. */
511
- export async function runPages(projectId, wizardId) {
530
+ export async function runPages(spaceId, wizardId) {
512
531
  return db.query.spacePage.findMany({
513
- where: and(eq(schema.spacePage.projectId, projectId), eq(schema.spacePage.wizardId, wizardId)),
532
+ where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.wizardId, wizardId)),
514
533
  columns: { id: true, wizardId: true, title: true, markdown: true, updatedAt: true },
515
534
  orderBy: [asc(schema.spacePage.title)],
516
535
  });
517
536
  }
518
537
  /** Writes a page of the run's wizard: a new one, or the one with this title, replaced or added to. */
519
- export async function writeRunPage(projectId, wizardId, input) {
538
+ export async function writeRunPage(spaceId, wizardId, input) {
520
539
  const title = input.title.trim();
521
540
  if (!title) {
522
541
  throw new ServiceError("invalid", note("pageNeedsTitle"));
523
542
  }
524
543
  const existing = (await db.query.spacePage.findMany({
525
- where: and(eq(schema.spacePage.projectId, projectId), eq(schema.spacePage.wizardId, wizardId)),
544
+ where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.wizardId, wizardId)),
526
545
  })).find((p) => p.title.toLowerCase() === title.toLowerCase());
527
546
  const markdown = existing && input.append
528
547
  ? `${existing.markdown.trimEnd()}\n\n${input.markdown.trim()}`
@@ -538,7 +557,7 @@ export async function writeRunPage(projectId, wizardId, input) {
538
557
  const [{ n }] = await db
539
558
  .select({ n: count() })
540
559
  .from(schema.spacePage)
541
- .where(eq(schema.spacePage.projectId, projectId));
560
+ .where(eq(schema.spacePage.spaceId, spaceId));
542
561
  if (n >= SPACE_DATA_LIMITS.pages) {
543
562
  throw new ServiceError("refused", note("spaceMostPages", { count: SPACE_DATA_LIMITS.pages }));
544
563
  }
@@ -546,7 +565,7 @@ export async function writeRunPage(projectId, wizardId, input) {
546
565
  await db.insert(schema.spacePage).values({
547
566
  id,
548
567
  tenantId: currentTenant(),
549
- projectId,
568
+ spaceId,
550
569
  wizardId,
551
570
  title: title.slice(0, 200),
552
571
  markdown,
@@ -554,21 +573,21 @@ export async function writeRunPage(projectId, wizardId, input) {
554
573
  return { id, title, chars: markdown.length, made: true };
555
574
  }
556
575
  async function originSpace(space) {
557
- const project = await db.query.project.findFirst({
558
- where: and(eq(schema.project.id, space), eq(schema.project.tenantId, currentTenant())),
576
+ const row = await db.query.space.findFirst({
577
+ where: and(eq(schema.space.id, space), eq(schema.space.tenantId, currentTenant())),
559
578
  columns: { id: true },
560
579
  });
561
- if (!project) {
580
+ if (!row) {
562
581
  throw new ServiceError("not_found", note("unknownSpace", { space }));
563
582
  }
564
- await requireWritableProject(project.id);
565
- return project.id;
583
+ await requireWritableSpace(row.id);
584
+ return row.id;
566
585
  }
567
586
  /** Keeps the original of what a plugin wrote: a document of the space under the same key. */
568
- async function originalFile(origin, projectId, key, label, original, text) {
569
- const { putOriginFile } = await import("./project-files.js");
587
+ async function originalFile(origin, spaceId, key, label, original, text) {
588
+ const { putOriginFile } = await import("./space-files.js");
570
589
  return putOriginFile(origin, {
571
- space: projectId,
590
+ space: spaceId,
572
591
  key,
573
592
  label,
574
593
  name: original.name,
@@ -578,17 +597,17 @@ async function originalFile(origin, projectId, key, label, original, text) {
578
597
  });
579
598
  }
580
599
  export async function putOriginPage(origin, input) {
581
- const projectId = await originSpace(input.space);
600
+ const spaceId = await originSpace(input.space);
582
601
  const key = input.key.trim().slice(0, 300);
583
602
  const existing = await db.query.spacePage.findFirst({
584
- where: and(eq(schema.spacePage.projectId, projectId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.originKey, key)),
603
+ where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.originKey, key)),
585
604
  });
586
605
  if (existing?.kept) {
587
606
  return { id: existing.id, state: "kept" };
588
607
  }
589
608
  const parent = input.parent
590
609
  ? await db.query.spacePage.findFirst({
591
- where: and(eq(schema.spacePage.projectId, projectId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.originKey, input.parent)),
610
+ where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.originKey, input.parent)),
592
611
  columns: { id: true },
593
612
  })
594
613
  : null;
@@ -600,9 +619,9 @@ export async function putOriginPage(origin, input) {
600
619
  const label = input.label?.trim().slice(0, 120) || null;
601
620
  const parentId = parent?.id ?? null;
602
621
  const fileId = input.original
603
- ? await originalFile(origin, projectId, key, label, input.original, markdown)
622
+ ? await originalFile(origin, spaceId, key, label, input.original, markdown)
604
623
  : (existing?.fileId ?? null);
605
- const position = input.position ?? existing?.position ?? (await nextPosition(projectId, parentId));
624
+ const position = input.position ?? existing?.position ?? (await nextPosition(spaceId, parentId));
606
625
  let id = existing?.id;
607
626
  const moved = !existing || existing.title !== title || existing.parentId !== parentId;
608
627
  if (existing) {
@@ -616,22 +635,22 @@ export async function putOriginPage(origin, input) {
616
635
  originLabel: label,
617
636
  fileId,
618
637
  review: input.review ?? null,
619
- ...(moved ? { slug: await freeSlug(projectId, title, { parentId }, existing.id) } : {}),
638
+ ...(moved ? { slug: await freeSlug(spaceId, title, { parentId }, existing.id) } : {}),
620
639
  updatedAt: new Date(),
621
640
  })
622
641
  .where(eq(schema.spacePage.id, existing.id));
623
642
  }
624
643
  else {
625
- await pageCount(projectId);
644
+ await pageCount(spaceId);
626
645
  id = nanoid(12);
627
646
  await db.insert(schema.spacePage).values({
628
647
  id,
629
648
  tenantId: currentTenant(),
630
- projectId,
649
+ spaceId,
631
650
  parentId,
632
651
  position,
633
652
  title,
634
- slug: await freeSlug(projectId, title, { parentId }),
653
+ slug: await freeSlug(spaceId, title, { parentId }),
635
654
  markdown,
636
655
  origin,
637
656
  originKey: key,
@@ -641,16 +660,16 @@ export async function putOriginPage(origin, input) {
641
660
  });
642
661
  }
643
662
  const set = input.categories
644
- ? await setItemCategories(projectId, { pageId: id }, input.categories, "origin")
663
+ ? await setItemCategories(spaceId, { pageId: id }, input.categories, "origin")
645
664
  : { changed: false };
646
665
  queueIndex(`${moved || set.changed ? "P" : "p"}:${id}`);
647
666
  return { id: id, state: "written" };
648
667
  }
649
668
  export async function putOriginTable(origin, input) {
650
- const projectId = await originSpace(input.space);
669
+ const spaceId = await originSpace(input.space);
651
670
  const key = input.key.trim().slice(0, 300);
652
671
  const existing = await db.query.spaceTable.findFirst({
653
- where: and(eq(schema.spaceTable.projectId, projectId), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.originKey, key)),
672
+ where: and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.originKey, key)),
654
673
  });
655
674
  if (existing?.kept) {
656
675
  return { id: existing.id, state: "kept" };
@@ -673,7 +692,7 @@ export async function putOriginTable(origin, input) {
673
692
  ...cells.map((r) => columns.map((c) => String(r[c.id] ?? "")).join(",")),
674
693
  ].join("\n");
675
694
  const fileId = input.original
676
- ? await originalFile(origin, projectId, key, label, input.original, csv)
695
+ ? await originalFile(origin, spaceId, key, label, input.original, csv)
677
696
  : (existing?.fileId ?? null);
678
697
  let id = existing?.id;
679
698
  if (existing) {
@@ -687,7 +706,7 @@ export async function putOriginTable(origin, input) {
687
706
  fileId,
688
707
  review: input.review ?? null,
689
708
  ...(existing.title !== title
690
- ? { slug: await freeSlug(projectId, title, "table", existing.id) }
709
+ ? { slug: await freeSlug(spaceId, title, "table", existing.id) }
691
710
  : {}),
692
711
  updatedAt: new Date(),
693
712
  })
@@ -695,14 +714,14 @@ export async function putOriginTable(origin, input) {
695
714
  await db.delete(schema.spaceTableRow).where(eq(schema.spaceTableRow.tableId, existing.id));
696
715
  }
697
716
  else {
698
- await tableCount(projectId);
717
+ await tableCount(spaceId);
699
718
  id = nanoid(12);
700
719
  await db.insert(schema.spaceTable).values({
701
720
  id,
702
721
  tenantId: currentTenant(),
703
- projectId,
722
+ spaceId,
704
723
  title,
705
- slug: await freeSlug(projectId, title, "table"),
724
+ slug: await freeSlug(spaceId, title, "table"),
706
725
  format: input.format ?? null,
707
726
  columns,
708
727
  origin,
@@ -723,7 +742,7 @@ export async function putOriginTable(origin, input) {
723
742
  })));
724
743
  }
725
744
  if (input.categories) {
726
- await setItemCategories(projectId, { tableId: id }, input.categories, "origin");
745
+ await setItemCategories(spaceId, { tableId: id }, input.categories, "origin");
727
746
  }
728
747
  await syncTableRowCategories(id);
729
748
  queueIndex(`t:${id}`);
@@ -731,11 +750,11 @@ export async function putOriginTable(origin, input) {
731
750
  }
732
751
  /** What a plugin wrote into a space, by its keys. */
733
752
  export async function listOrigin(origin, space) {
734
- const projectId = await originSpace(space);
753
+ const spaceId = await originSpace(space);
735
754
  const [pages, tables, files] = await Promise.all([
736
755
  // What a document of the plugin was read into stands behind the document, not on its own.
737
756
  db.query.spacePage.findMany({
738
- where: and(eq(schema.spacePage.projectId, projectId), eq(schema.spacePage.origin, origin), isNotNull(schema.spacePage.originKey)),
757
+ where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), isNotNull(schema.spacePage.originKey)),
739
758
  columns: {
740
759
  id: true,
741
760
  originKey: true,
@@ -746,7 +765,7 @@ export async function listOrigin(origin, space) {
746
765
  },
747
766
  }),
748
767
  db.query.spaceTable.findMany({
749
- where: and(eq(schema.spaceTable.projectId, projectId), eq(schema.spaceTable.origin, origin), isNotNull(schema.spaceTable.originKey)),
768
+ where: and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.origin, origin), isNotNull(schema.spaceTable.originKey)),
750
769
  columns: {
751
770
  id: true,
752
771
  originKey: true,
@@ -756,15 +775,15 @@ export async function listOrigin(origin, space) {
756
775
  updatedAt: true,
757
776
  },
758
777
  }),
759
- db.query.projectFile.findMany({
760
- where: and(eq(schema.projectFile.projectId, projectId), eq(schema.projectFile.origin, origin)),
778
+ db.query.spaceFile.findMany({
779
+ where: and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.origin, origin)),
761
780
  columns: { id: true, originKey: true, name: true, updatedAt: true },
762
781
  }),
763
782
  ]);
764
783
  const [tree, tPaths, fPaths] = await Promise.all([
765
- pageTree(projectId),
766
- tablePaths(projectId),
767
- filePaths(projectId),
784
+ pageTree(spaceId),
785
+ tablePaths(spaceId),
786
+ filePaths(spaceId),
768
787
  ]);
769
788
  return [
770
789
  ...pages.map((p) => ({
@@ -804,16 +823,16 @@ export async function listOrigin(origin, space) {
804
823
  * space. What a person changed since stays. Returns how many items went.
805
824
  */
806
825
  export async function removeOrigin(origin, space, key) {
807
- const projectId = await originSpace(space);
826
+ const spaceId = await originSpace(space);
808
827
  const pages = await db
809
828
  .delete(schema.spacePage)
810
- .where(and(eq(schema.spacePage.projectId, projectId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.kept, false), key === undefined ? undefined : eq(schema.spacePage.originKey, key)))
829
+ .where(and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.kept, false), key === undefined ? undefined : eq(schema.spacePage.originKey, key)))
811
830
  .returning({ id: schema.spacePage.id });
812
831
  const tables = await db
813
832
  .delete(schema.spaceTable)
814
- .where(and(eq(schema.spaceTable.projectId, projectId), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.kept, false), key === undefined ? undefined : eq(schema.spaceTable.originKey, key)))
833
+ .where(and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.kept, false), key === undefined ? undefined : eq(schema.spaceTable.originKey, key)))
815
834
  .returning({ id: schema.spaceTable.id });
816
- const { removeOriginFiles } = await import("./project-files.js");
817
- const files = await removeOriginFiles(origin, projectId, key);
835
+ const { removeOriginFiles } = await import("./space-files.js");
836
+ const files = await removeOriginFiles(origin, spaceId, key);
818
837
  return pages.length + tables.length + files;
819
838
  }