@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
@@ -0,0 +1,436 @@
1
+ import { CONNECTION_ACTION_KINDS, CONNECTION_AUDIENCES, CONNECTION_LIMITS, CONNECTION_OUTCOMES, CONNECTION_SIGN_INS, DEFAULT_CONNECTION_RULES, } from "@engenty/wizards-shared/connectors";
2
+ import { note } from "@engenty/wizards-shared/run";
3
+ import { and, asc, eq, inArray } from "drizzle-orm";
4
+ import { nanoid } from "nanoid";
5
+ import { z } from "zod";
6
+ import { inAudience, logRuleChange } from "../broker/index.js";
7
+ import { db, schema } from "../db/client.js";
8
+ import { buildAuthorizationUrl, createOAuth2Pkce, exchangeAuthorizationCode, } from "../engenty/connections-sdk/oauth2.js";
9
+ import { seal, unseal } from "../secrets/crypto.js";
10
+ import { isAdminRole, requireAdmin, requireWritableSpace } from "../services/access.js";
11
+ import { notFound, ServiceError } from "../services/errors.js";
12
+ import { ownedSpace } from "../services/spaces.js";
13
+ import { currentTenant } from "../tenants/tenant.js";
14
+ import { connectorFetch, resolveEnv, viaAccount } from "./builtin.js";
15
+ import { resolveConnector } from "./external.js";
16
+ import { connectRedirectUri as redirectUri } from "./index.js";
17
+ import { AccountConnectError, redeemTicket, startThroughAccount } from "./via-account.js";
18
+ export const rulesSchema = z.object(Object.fromEntries(CONNECTION_ACTION_KINDS.map((k) => [k, z.enum(CONNECTION_OUTCOMES)])));
19
+ export const newConnectionSchema = z.object({
20
+ connectorId: z.string().min(1).max(200),
21
+ name: z.string().trim().min(1).max(CONNECTION_LIMITS.name),
22
+ signIn: z.enum(CONNECTION_SIGN_INS),
23
+ audience: z.enum(CONNECTION_AUDIENCES).default("members"),
24
+ rules: rulesSchema.default(DEFAULT_CONNECTION_RULES),
25
+ /** The connector's actions it is for; left out: every action. */
26
+ actions: z.array(z.string().max(200)).max(200).default([]),
27
+ });
28
+ export const connectionPatchSchema = z.object({
29
+ name: z.string().trim().min(1).max(CONNECTION_LIMITS.name).optional(),
30
+ audience: z.enum(CONNECTION_AUDIENCES).optional(),
31
+ rules: rulesSchema.optional(),
32
+ actions: z.array(z.string().max(200)).max(200).optional(),
33
+ });
34
+ // --- reading ---------------------------------------------------------------------------------
35
+ /** A connection by id, in this tenant; not found where the id is another tenant's or nobody's. */
36
+ export async function spaceConnectionById(id) {
37
+ const row = await db.query.spaceConnection.findFirst({
38
+ where: eq(schema.spaceConnection.id, id),
39
+ });
40
+ if (!row) {
41
+ throw notFound();
42
+ }
43
+ // The space check says whether the row is this tenant's.
44
+ await ownedSpace("", row.spaceId);
45
+ return row;
46
+ }
47
+ /** A connection of this space by id, or null. */
48
+ export async function spaceConnectionOf(spaceId, id) {
49
+ const row = await db.query.spaceConnection.findFirst({
50
+ where: and(eq(schema.spaceConnection.id, id), eq(schema.spaceConnection.spaceId, spaceId)),
51
+ });
52
+ return row ?? null;
53
+ }
54
+ export async function listSpaceConnections(spaceId) {
55
+ return db.query.spaceConnection.findMany({
56
+ where: eq(schema.spaceConnection.spaceId, spaceId),
57
+ orderBy: [asc(schema.spaceConnection.setUpAt)],
58
+ });
59
+ }
60
+ /** The connector behind a connection: a built-in one, or one the space imported. */
61
+ export async function connectorOfRow(row) {
62
+ const found = await resolveConnector(row.spaceId, row.connectorId);
63
+ if (!found) {
64
+ throw new ServiceError("not_found", note("connectorGone", { id: row.connectorId }));
65
+ }
66
+ return found.connector;
67
+ }
68
+ /** The space's connections as the authoring guide lists them: id, name, connector, sign-in, actions. */
69
+ export async function guideSpaceConnections(spaceId) {
70
+ const rows = await listSpaceConnections(spaceId);
71
+ const listed = [];
72
+ for (const row of rows) {
73
+ const connector = (await resolveConnector(spaceId, row.connectorId))?.connector;
74
+ if (!connector) {
75
+ continue;
76
+ }
77
+ const actions = row.actions.length
78
+ ? connector.actions.filter((a) => row.actions.includes(a.id))
79
+ : connector.actions;
80
+ listed.push({
81
+ id: row.id,
82
+ name: row.name,
83
+ connector: connector.name,
84
+ signIn: row.signIn,
85
+ actions: actions.map((a) => ({ id: a.id, group: a.group })),
86
+ });
87
+ }
88
+ return listed;
89
+ }
90
+ /** What the studio shows: never a secret. `userId` tells whose own sign-in to look up. */
91
+ export async function spaceConnectionViews(spaceId, userId) {
92
+ const rows = await listSpaceConnections(spaceId);
93
+ const people = rows.some((row) => row.signIn === "person");
94
+ const signIns = people
95
+ ? await db
96
+ .select({
97
+ connectionId: schema.spaceConnectionSignIn.connectionId,
98
+ userId: schema.spaceConnectionSignIn.userId,
99
+ label: schema.spaceConnectionSignIn.label,
100
+ signedInAt: schema.spaceConnectionSignIn.signedInAt,
101
+ })
102
+ .from(schema.spaceConnectionSignIn)
103
+ .where(inArray(schema.spaceConnectionSignIn.connectionId, rows.map((row) => row.id)))
104
+ : [];
105
+ return Promise.all(rows.map(async (row) => {
106
+ const connector = (await resolveConnector(spaceId, row.connectorId))?.connector ?? null;
107
+ const theirs = row.signIn === "person" ? signIns.filter((s) => s.connectionId === row.id) : [];
108
+ const mine = theirs.find((s) => s.userId === userId);
109
+ return {
110
+ id: row.id,
111
+ spaceId: row.spaceId,
112
+ connectorId: row.connectorId,
113
+ connector: connector
114
+ ? {
115
+ id: connector.id,
116
+ name: connector.name,
117
+ auth: connector.auth.kind,
118
+ description: connector.description,
119
+ ...(connector.auth.kind === "api_key"
120
+ ? { fields: connector.auth.apiKey.fields }
121
+ : {}),
122
+ }
123
+ : null,
124
+ name: row.name,
125
+ signIn: row.signIn,
126
+ audience: row.audience,
127
+ rules: row.rules,
128
+ actions: row.actions,
129
+ plugin: row.plugin,
130
+ account: row.signIn === "space" && row.secret
131
+ ? {
132
+ label: row.label ?? connector?.name ?? row.name,
133
+ signedInAt: row.setUpAt.toISOString(),
134
+ }
135
+ : null,
136
+ mySignIn: row.signIn === "person" && mine
137
+ ? { label: mine.label, signedInAt: mine.signedInAt.toISOString() }
138
+ : null,
139
+ setUpBy: row.setUpBy,
140
+ setUpAt: row.setUpAt.toISOString(),
141
+ lastUsedAt: row.lastUsedAt?.toISOString() ?? null,
142
+ signedIn: theirs.length,
143
+ };
144
+ }));
145
+ }
146
+ // --- setting up, admins only -----------------------------------------------------------------
147
+ /** The actions named exist on the connector. */
148
+ function knownActions(connector, actions) {
149
+ for (const id of actions) {
150
+ if (!connector.actions.some((a) => a.id === id)) {
151
+ throw new ServiceError("invalid", note("connectorNoAction", { name: connector.name, id }));
152
+ }
153
+ }
154
+ return [...new Set(actions)];
155
+ }
156
+ export async function createSpaceConnection(userId, spaceId, input,
157
+ /** The plugin that sets it up through `server.connections`, where one does. */
158
+ plugin = null) {
159
+ await ownedSpace(userId ?? "", spaceId);
160
+ await requireWritableSpace(spaceId);
161
+ await requireAdmin();
162
+ const found = await resolveConnector(spaceId, input.connectorId);
163
+ if (!found || found.connector.auth.kind === "browser") {
164
+ throw new ServiceError("invalid", note("connectorGone", { id: input.connectorId }));
165
+ }
166
+ const count = await db.$count(schema.spaceConnection, eq(schema.spaceConnection.spaceId, spaceId));
167
+ if (count >= CONNECTION_LIMITS.perSpace) {
168
+ throw new ServiceError("refused", note("tooManyConnections"));
169
+ }
170
+ const [row] = await db
171
+ .insert(schema.spaceConnection)
172
+ .values({
173
+ id: nanoid(14),
174
+ spaceId,
175
+ connectorId: found.connector.id,
176
+ plugin,
177
+ name: input.name,
178
+ signIn: input.signIn,
179
+ audience: input.audience,
180
+ rules: input.rules,
181
+ actions: knownActions(found.connector, input.actions),
182
+ setUpBy: userId,
183
+ })
184
+ .returning();
185
+ return row;
186
+ }
187
+ export async function updateSpaceConnection(userId, id, patch) {
188
+ const row = await spaceConnectionById(id);
189
+ await ownedSpace(userId, row.spaceId);
190
+ await requireWritableSpace(row.spaceId);
191
+ await requireAdmin();
192
+ const actions = patch.actions !== undefined
193
+ ? knownActions(await connectorOfRow(row), patch.actions)
194
+ : undefined;
195
+ const [updated] = await db
196
+ .update(schema.spaceConnection)
197
+ .set({
198
+ ...(patch.name !== undefined ? { name: patch.name } : {}),
199
+ ...(patch.audience !== undefined ? { audience: patch.audience } : {}),
200
+ ...(patch.rules !== undefined ? { rules: patch.rules } : {}),
201
+ ...(actions !== undefined ? { actions } : {}),
202
+ updatedAt: new Date(),
203
+ })
204
+ .where(eq(schema.spaceConnection.id, row.id))
205
+ .returning();
206
+ // Who may use it, and what each kind of action may do: a change there is heard of.
207
+ const rulesChanged = patch.rules !== undefined && JSON.stringify(patch.rules) !== JSON.stringify(row.rules);
208
+ const audienceChanged = patch.audience !== undefined && patch.audience !== row.audience;
209
+ if (rulesChanged || audienceChanged) {
210
+ await logRuleChange({
211
+ userId,
212
+ spaceId: row.spaceId,
213
+ connectionId: row.id,
214
+ summary: {
215
+ ...(audienceChanged ? { audience: `${row.audience} → ${updated.audience}` } : {}),
216
+ ...(rulesChanged ? { rules: changedRules(row.rules, updated.rules) } : {}),
217
+ },
218
+ reason: [
219
+ audienceChanged ? `The audience is now ${updated.audience}.` : "",
220
+ rulesChanged ? `The rules changed: ${changedRules(row.rules, updated.rules)}.` : "",
221
+ ]
222
+ .filter(Boolean)
223
+ .join(" "),
224
+ });
225
+ }
226
+ return updated;
227
+ }
228
+ /** "write: ask → allow, send: ask → deny" */
229
+ function changedRules(before, after) {
230
+ return Object.keys(after)
231
+ .filter((k) => before[k] !== after[k])
232
+ .map((k) => `${k}: ${before[k]} → ${after[k]}`)
233
+ .join(", ");
234
+ }
235
+ export async function removeSpaceConnection(userId, id) {
236
+ const row = await spaceConnectionById(id);
237
+ await ownedSpace(userId, row.spaceId);
238
+ await requireWritableSpace(row.spaceId);
239
+ await requireAdmin();
240
+ await db.delete(schema.spaceConnection).where(eq(schema.spaceConnection.id, row.id));
241
+ }
242
+ /** The admins sign in as the space; a member signs in to a connection in which each person does, if it is for them. */
243
+ async function allowSignIn(row, as) {
244
+ if (as.as === "space") {
245
+ if (row.signIn !== "space") {
246
+ throw new ServiceError("invalid", note("connectionEachPersonSignsIn"));
247
+ }
248
+ await requireAdmin();
249
+ return;
250
+ }
251
+ if (row.signIn !== "person") {
252
+ throw new ServiceError("invalid", note("connectionSignsInAsSpace"));
253
+ }
254
+ const who = { kind: isAdminRole(as.role) ? "admin" : "person", id: as.userId };
255
+ if (!inAudience(row.audience, who)) {
256
+ throw new ServiceError("forbidden", note("connectionNotForYou"));
257
+ }
258
+ }
259
+ /** Keeps a sign-in: the space's in its row, a person's in theirs. */
260
+ async function keepSignIn(row, as, label, stored) {
261
+ if (as.as === "space") {
262
+ await db
263
+ .update(schema.spaceConnection)
264
+ .set({ secret: seal(stored), label, updatedAt: new Date() })
265
+ .where(eq(schema.spaceConnection.id, row.id));
266
+ return;
267
+ }
268
+ await db
269
+ .insert(schema.spaceConnectionSignIn)
270
+ .values({ connectionId: row.id, userId: as.userId, label, secret: seal(stored) })
271
+ .onConflictDoUpdate({
272
+ target: [schema.spaceConnectionSignIn.connectionId, schema.spaceConnectionSignIn.userId],
273
+ set: { label, secret: seal(stored), signedInAt: new Date(), updatedAt: new Date() },
274
+ });
275
+ }
276
+ /** Signs in with what the person typed: the connector tries the keys once, then they are kept sealed. */
277
+ export async function signInWithCredentials(id, as, values) {
278
+ const row = await spaceConnectionById(id);
279
+ await allowSignIn(row, as);
280
+ const connector = await connectorOfRow(row);
281
+ if (connector.auth.kind !== "api_key") {
282
+ throw new ServiceError("invalid", note("connectorSignsIn", { name: connector.name }));
283
+ }
284
+ const credentials = {};
285
+ for (const field of connector.auth.apiKey.fields) {
286
+ const value = String(values[field.key] ?? "").trim();
287
+ if (!value && field.required !== false) {
288
+ throw new ServiceError("invalid", note("fieldMissing", { label: field.label }));
289
+ }
290
+ if (value) {
291
+ credentials[field.key] = value.slice(0, 500);
292
+ }
293
+ }
294
+ let account;
295
+ try {
296
+ account = await connector.auth.apiKey.verify(credentials, connectorFetch);
297
+ }
298
+ catch (err) {
299
+ throw new ServiceError("refused", note("connectingNotWork", {
300
+ host: "",
301
+ detail: String(err?.message ?? err).slice(0, 200),
302
+ }));
303
+ }
304
+ await keepSignIn(row, as, account.label, {
305
+ accessToken: JSON.stringify(credentials),
306
+ refreshToken: null,
307
+ expiresAt: null,
308
+ scopes: [],
309
+ });
310
+ return { label: account.label };
311
+ }
312
+ /** The provider rights the connection's actions need, and the connector's base rights. */
313
+ function scopesOf(connector, actions) {
314
+ const scopes = new Set(connector.auth.kind === "oauth2" ? connector.auth.oauth2.baseScopes : []);
315
+ const wanted = actions.length
316
+ ? connector.actions.filter((a) => actions.includes(a.id))
317
+ : connector.actions;
318
+ for (const action of wanted) {
319
+ for (const scope of action.providerScopes ?? []) {
320
+ scopes.add(scope);
321
+ }
322
+ }
323
+ return [...scopes];
324
+ }
325
+ /** The provider's sign-in page for a connection; the callback (`/api/connect/callback`) finishes it. */
326
+ export async function startSpaceConnectionOAuth(id, as, lang) {
327
+ const row = await spaceConnectionById(id);
328
+ await allowSignIn(row, as);
329
+ const connector = await connectorOfRow(row);
330
+ if (connector.auth.kind !== "oauth2") {
331
+ throw new ServiceError("invalid", note("connectorTakesKeys", { name: connector.name }));
332
+ }
333
+ const scopes = scopesOf(connector, row.actions);
334
+ const base = {
335
+ spaceConnection: row.id,
336
+ tenantId: currentTenant(),
337
+ userId: as.as === "person" ? as.userId : null,
338
+ exp: Date.now() + 15 * 60_000,
339
+ lang,
340
+ };
341
+ if (await viaAccount(connector)) {
342
+ // The Manage-App keeps the PKCE verifier; ours stays empty.
343
+ try {
344
+ return await startThroughAccount(scopes, seal({ ...base, verifier: "" }), redirectUri());
345
+ }
346
+ catch (err) {
347
+ throw err instanceof AccountConnectError ? new ServiceError("refused", err.message) : err;
348
+ }
349
+ }
350
+ await connector.auth.oauth2.registerClient?.();
351
+ const pkce = createOAuth2Pkce();
352
+ return buildAuthorizationUrl({
353
+ connector,
354
+ pkce,
355
+ redirectUri: redirectUri(),
356
+ scopes,
357
+ state: seal({ ...base, verifier: pkce.codeVerifier }),
358
+ resolveEnv,
359
+ });
360
+ }
361
+ /** A state the callback can tell is a space connection's: the tenant to finish it in, or null. */
362
+ export function spaceConnectionStateTenant(rawState) {
363
+ const state = unseal(rawState);
364
+ return state && typeof state.spaceConnection === "string" ? state.tenantId : null;
365
+ }
366
+ /** The provider came back for a connection of the space: keeps the sign-in it started. */
367
+ export async function finishSpaceConnectionOAuth(answer, rawState) {
368
+ const state = unseal(rawState);
369
+ if (!state?.spaceConnection || state.exp < Date.now()) {
370
+ throw new Error("The sign-in has expired. Sign in again.");
371
+ }
372
+ const row = await db.query.spaceConnection.findFirst({
373
+ where: eq(schema.spaceConnection.id, state.spaceConnection),
374
+ });
375
+ if (!row) {
376
+ throw new Error("The connection this sign-in belongs to is gone.");
377
+ }
378
+ const connector = await connectorOfRow(row);
379
+ if (connector.auth.kind !== "oauth2") {
380
+ throw new Error("not an oauth connector");
381
+ }
382
+ const tokens = "ticket" in answer
383
+ ? await redeemTicket(answer.ticket)
384
+ : await exchangeAuthorizationCode({
385
+ code: answer.code,
386
+ codeVerifier: state.verifier,
387
+ config: connector.auth.oauth2,
388
+ redirectUri: redirectUri(),
389
+ resolveEnv,
390
+ });
391
+ // A provider that will not name the account still connected it.
392
+ const account = (await connector.auth.oauth2
393
+ .resolveAccount?.(tokens.accessToken, fetch)
394
+ .catch(() => null)) ?? { label: connector.name };
395
+ const stored = {
396
+ accessToken: tokens.accessToken,
397
+ refreshToken: tokens.refreshToken,
398
+ expiresAt: tokens.expiresAt?.toISOString() ?? null,
399
+ scopes: tokens.grantedScopes,
400
+ ...("ticket" in answer ? { via: "account" } : {}),
401
+ };
402
+ // The person's role was checked when the sign-in started; the state is ours, sealed.
403
+ const as = state.userId === null
404
+ ? { as: "space" }
405
+ : { as: "person", userId: state.userId, role: "member" };
406
+ if (as.as === "space" && row.signIn !== "space") {
407
+ throw new Error("The connection no longer signs in as the space.");
408
+ }
409
+ if (as.as === "person" && row.signIn !== "person") {
410
+ throw new Error("The connection no longer signs in per person.");
411
+ }
412
+ await keepSignIn(row, as, account.label, stored);
413
+ return { connectionId: row.id };
414
+ }
415
+ /** Forgets a sign-in: the space's (admins) or the person's own. */
416
+ export async function removeSignIn(id, as) {
417
+ const row = await spaceConnectionById(id);
418
+ if (as.as === "space") {
419
+ await requireAdmin();
420
+ await db
421
+ .update(schema.spaceConnection)
422
+ .set({ secret: null, label: null, updatedAt: new Date() })
423
+ .where(eq(schema.spaceConnection.id, row.id));
424
+ return;
425
+ }
426
+ await db
427
+ .delete(schema.spaceConnectionSignIn)
428
+ .where(and(eq(schema.spaceConnectionSignIn.connectionId, row.id), eq(schema.spaceConnectionSignIn.userId, as.userId)));
429
+ }
430
+ /**
431
+ * Keeps a sign-in as the space that a plugin or a command already made (`server.connections`
432
+ * after the provider came back): the same account for the same space again replaces the first.
433
+ */
434
+ export async function keepSpaceSignIn(row, label, stored) {
435
+ await keepSignIn(row, { as: "space" }, label, stored);
436
+ }
@@ -13,7 +13,7 @@ import { control, controlDb, openTenantDb } from "./client.js";
13
13
  * and folders stay where they are.
14
14
  */
15
15
  const TABLES = [
16
- "project",
16
+ "space",
17
17
  "wizard",
18
18
  "wizard_version",
19
19
  "wizard_file",
@@ -21,7 +21,7 @@ const TABLES = [
21
21
  "run",
22
22
  "run_event",
23
23
  "asset",
24
- "project_connector",
24
+ "space_connector",
25
25
  "store_holder",
26
26
  "store_row",
27
27
  "store_file",
@@ -54,7 +54,7 @@ export async function adoptLegacyData() {
54
54
  return;
55
55
  }
56
56
  const legacy = createClient({ url: `file:${legacyFile}` });
57
- const hasOwner = (await legacy.execute("PRAGMA table_info(project)")).rows.some((r) => r.name === "owner_id");
57
+ const hasOwner = (await legacy.execute("PRAGMA table_info(space)")).rows.some((r) => r.name === "owner_id");
58
58
  if (!hasOwner) {
59
59
  return;
60
60
  }
@@ -167,6 +167,15 @@ export function tenantDb(id) {
167
167
  return db;
168
168
  }
169
169
  const ready = new Map();
170
+ /** The open client of a tenant's database, for a store of its own beside ours (Mastra's). */
171
+ export async function tenantClient(id) {
172
+ await tenantDb(id);
173
+ const client = clients.get(id);
174
+ if (!client) {
175
+ throw new Error(`The database of tenant ${id} is not open.`);
176
+ }
177
+ return client;
178
+ }
170
179
  /** Closes and forgets an open tenant database (the tenant was deleted or moved). */
171
180
  export function closeTenantDb(id) {
172
181
  opened.delete(id);
@@ -2,16 +2,16 @@
2
2
  * The triggers that fill `live_change` (docs/plans/live-changes.md, 1). One entry per table
3
3
  * names the item a write changes; `pnpm --filter @engenty/wizards-runtime exec tsx
4
4
  * scripts/live-triggers.ts` prints the SQL that migration 0023 carries, or with a table's name
5
- * that table's alone (0026). Unlike the two-way sync's triggers (0022) they have no guard, since
5
+ * that table's alone (0026); 0031 carries all of them, under the space's names. Unlike the two-way sync's triggers (0022) they have no guard, since
6
6
  * a pulled write is a change on this side's screen too, and they count wizard-owned pages and
7
7
  * tables, which the studio shows as shared lists.
8
8
  */
9
- const ofWizard = "(SELECT project_id FROM wizard WHERE id = $.wizard_id)";
9
+ const ofWizard = "(SELECT space_id FROM wizard WHERE id = $.wizard_id)";
10
10
  export const LIVE_TABLES = [
11
- { table: "project", project: "$.id", kind: "'space'", item: "$.id", parent: "NULL", owns: true },
11
+ { table: "space", space: "$.id", kind: "'space'", item: "$.id", parent: "NULL", owns: true },
12
12
  {
13
13
  table: "wizard",
14
- project: "$.project_id",
14
+ space: "$.space_id",
15
15
  kind: "'wizard'",
16
16
  item: "$.id",
17
17
  parent: "NULL",
@@ -19,7 +19,7 @@ export const LIVE_TABLES = [
19
19
  },
20
20
  {
21
21
  table: "wizard_file",
22
- project: ofWizard,
22
+ space: ofWizard,
23
23
  kind: "'wizard'",
24
24
  item: "$.wizard_id",
25
25
  parent: "NULL",
@@ -27,7 +27,7 @@ export const LIVE_TABLES = [
27
27
  },
28
28
  {
29
29
  table: "wizard_translation",
30
- project: ofWizard,
30
+ space: ofWizard,
31
31
  kind: "'translation'",
32
32
  item: "$.wizard_id || ':' || $.lang",
33
33
  parent: "$.wizard_id",
@@ -35,7 +35,7 @@ export const LIVE_TABLES = [
35
35
  },
36
36
  {
37
37
  table: "wizard_message",
38
- project: ofWizard,
38
+ space: ofWizard,
39
39
  kind: "'message'",
40
40
  item: "$.id",
41
41
  parent: "$.wizard_id",
@@ -43,7 +43,7 @@ export const LIVE_TABLES = [
43
43
  },
44
44
  {
45
45
  table: "space_page",
46
- project: "$.project_id",
46
+ space: "$.space_id",
47
47
  kind: "'page'",
48
48
  item: "$.id",
49
49
  parent: "$.wizard_id",
@@ -51,7 +51,7 @@ export const LIVE_TABLES = [
51
51
  },
52
52
  {
53
53
  table: "space_table",
54
- project: "$.project_id",
54
+ space: "$.space_id",
55
55
  kind: "'table'",
56
56
  item: "$.id",
57
57
  parent: "$.wizard_id",
@@ -59,7 +59,7 @@ export const LIVE_TABLES = [
59
59
  },
60
60
  {
61
61
  table: "space_table_row",
62
- project: "(SELECT project_id FROM space_table WHERE id = $.table_id)",
62
+ space: "(SELECT space_id FROM space_table WHERE id = $.table_id)",
63
63
  kind: "'row'",
64
64
  item: "$.id",
65
65
  parent: "$.table_id",
@@ -67,7 +67,7 @@ export const LIVE_TABLES = [
67
67
  },
68
68
  {
69
69
  table: "space_category",
70
- project: "$.project_id",
70
+ space: "$.space_id",
71
71
  kind: "'category'",
72
72
  item: "$.id",
73
73
  parent: "NULL",
@@ -75,7 +75,7 @@ export const LIVE_TABLES = [
75
75
  },
76
76
  {
77
77
  table: "space_category_value",
78
- project: "(SELECT project_id FROM space_category WHERE id = $.category_id)",
78
+ space: "(SELECT space_id FROM space_category WHERE id = $.category_id)",
79
79
  kind: "'category'",
80
80
  item: "$.category_id",
81
81
  parent: "NULL",
@@ -83,32 +83,32 @@ export const LIVE_TABLES = [
83
83
  },
84
84
  {
85
85
  table: "space_item_category",
86
- project: "$.project_id",
86
+ space: "$.space_id",
87
87
  kind: "CASE WHEN $.page_id IS NOT NULL THEN 'page' WHEN $.row_id IS NOT NULL THEN 'row' WHEN $.table_id IS NOT NULL THEN 'table' ELSE 'file' END",
88
88
  item: "COALESCE($.page_id, $.row_id, $.table_id, $.file_id)",
89
89
  parent: "CASE WHEN $.row_id IS NOT NULL THEN (SELECT table_id FROM space_table_row WHERE id = $.row_id) END",
90
90
  owns: false,
91
91
  },
92
92
  {
93
- table: "project_file",
94
- project: "$.project_id",
93
+ table: "space_file",
94
+ space: "$.space_id",
95
95
  kind: "'file'",
96
96
  item: "$.id",
97
97
  parent: "NULL",
98
98
  owns: true,
99
99
  },
100
100
  {
101
- table: "project_connector",
102
- project: "$.project_id",
101
+ table: "space_connector",
102
+ space: "$.space_id",
103
103
  kind: "'connector'",
104
- item: "$.project_id || ':' || $.id",
104
+ item: "$.space_id || ':' || $.id",
105
105
  parent: "NULL",
106
106
  owns: true,
107
107
  },
108
- // Migration 0027.
108
+ // Migration 0030.
109
109
  {
110
110
  table: "space_skill",
111
- project: "$.project_id",
111
+ space: "$.space_id",
112
112
  kind: "'skill'",
113
113
  item: "$.id",
114
114
  parent: "NULL",
@@ -126,13 +126,55 @@ const OPS = [
126
126
  */
127
127
  export const PRESENCE_TABLE = {
128
128
  table: "live_presence",
129
- project: "NULL",
129
+ space: "NULL",
130
130
  kind: "'presence'",
131
131
  item: "$.kind || ':' || $.item",
132
132
  parent: "$.kind",
133
133
  owns: false,
134
134
  updateWhen: "old.state IS NOT new.state OR old.place IS NOT new.place OR old.name IS NOT new.name",
135
135
  };
136
+ /**
137
+ * Work's chats (behind `workMode`, migration 0029): any change of a chat, its members, its held
138
+ * calls or a section of the sidebar is a change of kind `chat` (the item: the chat, or the
139
+ * section). The feed carries no view of it: the stream checks each against the person (a private
140
+ * chat goes to its members only), and the studio reads the chat and the sidebar again. Messages
141
+ * are Mastra's; a new one updates its chat's row (its last message), so it is heard through that.
142
+ */
143
+ const ofChat = "(SELECT space_id FROM chat WHERE id = $.chat_id)";
144
+ export const CHAT_TABLES = [
145
+ {
146
+ table: "chat",
147
+ space: "$.space_id",
148
+ kind: "'chat'",
149
+ item: "$.id",
150
+ parent: "NULL",
151
+ owns: true,
152
+ },
153
+ {
154
+ table: "chat_member",
155
+ space: ofChat,
156
+ kind: "'chat'",
157
+ item: "$.chat_id",
158
+ parent: "NULL",
159
+ owns: false,
160
+ },
161
+ {
162
+ table: "chat_approval",
163
+ space: ofChat,
164
+ kind: "'chat'",
165
+ item: "$.chat_id",
166
+ parent: "NULL",
167
+ owns: false,
168
+ },
169
+ {
170
+ table: "chat_section",
171
+ space: "$.space_id",
172
+ kind: "'chat'",
173
+ item: "$.id",
174
+ parent: "'section'",
175
+ owns: true,
176
+ },
177
+ ];
136
178
  /** The trigger SQL of `tables`, in drizzle's statement-breakpoint form. */
137
179
  export function liveTriggerSql(tables = LIVE_TABLES) {
138
180
  const out = [];
@@ -144,8 +186,8 @@ export function liveTriggerSql(tables = LIVE_TABLES) {
144
186
  const name = t.table.startsWith("live_") ? t.table : `live_${t.table}`;
145
187
  out.push([
146
188
  `CREATE TRIGGER \`${name}_${op.suffix}\` AFTER ${op.event} ON \`${t.table}\`${when} BEGIN`,
147
- "\tINSERT INTO `live_change` (`project_id`, `kind`, `op`, `item`, `parent`, `at`)",
148
- `\tSELECT ${at(t.project)}, ${at(t.kind)}, ${kind}, i, ${at(t.parent)}, unixepoch() * 1000 FROM (SELECT ${at(t.item)} AS i) WHERE i IS NOT NULL;`,
189
+ "\tINSERT INTO `live_change` (`space_id`, `kind`, `op`, `item`, `parent`, `at`)",
190
+ `\tSELECT ${at(t.space)}, ${at(t.kind)}, ${kind}, i, ${at(t.parent)}, unixepoch() * 1000 FROM (SELECT ${at(t.item)} AS i) WHERE i IS NOT NULL;`,
149
191
  "END;",
150
192
  ].join("\n"));
151
193
  }