@engenty/wizards-runtime 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/apps/runtime/dist/agents/architect.js +8 -7
  2. package/apps/runtime/dist/agents/goose-connections.js +82 -0
  3. package/apps/runtime/dist/agents/space-agent.js +9 -2
  4. package/apps/runtime/dist/agents/studio-assistant.js +101 -67
  5. package/apps/runtime/dist/agents/website.js +1 -1
  6. package/apps/runtime/dist/app.js +17 -1
  7. package/apps/runtime/dist/assistant/knows.js +6 -5
  8. package/apps/runtime/dist/authoring/guide.js +25 -5
  9. package/apps/runtime/dist/broker/account.js +166 -0
  10. package/apps/runtime/dist/broker/call.js +417 -0
  11. package/apps/runtime/dist/broker/caller.js +10 -0
  12. package/apps/runtime/dist/broker/grant.js +152 -0
  13. package/apps/runtime/dist/broker/host.js +51 -0
  14. package/apps/runtime/dist/broker/index.js +8 -0
  15. package/apps/runtime/dist/broker/kept.js +31 -0
  16. package/apps/runtime/dist/broker/log.js +240 -0
  17. package/apps/runtime/dist/broker/registry.js +9 -0
  18. package/apps/runtime/dist/broker/rwx.js +367 -0
  19. package/apps/runtime/dist/broker/send.js +189 -0
  20. package/apps/runtime/dist/connectors/builtin.js +1 -1
  21. package/apps/runtime/dist/connectors/external.js +38 -37
  22. package/apps/runtime/dist/connectors/index.js +30 -91
  23. package/apps/runtime/dist/connectors/mail.js +0 -8
  24. package/apps/runtime/dist/connectors/person-sign-ins.js +73 -0
  25. package/apps/runtime/dist/connectors/plugin-connections.js +65 -92
  26. package/apps/runtime/dist/connectors/smtp.js +1 -1
  27. package/apps/runtime/dist/connectors/space-connections.js +436 -0
  28. package/apps/runtime/dist/db/adopt.js +3 -3
  29. package/apps/runtime/dist/db/client.js +9 -0
  30. package/apps/runtime/dist/db/live-triggers.js +65 -23
  31. package/apps/runtime/dist/db/migrations/tenant/0027_work_chats.sql +52 -0
  32. package/apps/runtime/dist/db/migrations/tenant/0028_chat_approvals.sql +17 -0
  33. package/apps/runtime/dist/db/migrations/tenant/0029_work_chats_live.sql +49 -0
  34. package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
  35. package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
  36. package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
  37. package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
  38. package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
  39. package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
  40. package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
  41. package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
  42. package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
  43. package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
  44. package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
  45. package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
  46. package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
  47. package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
  48. package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
  49. package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
  50. package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
  51. package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
  52. package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
  53. package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
  54. package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
  55. package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
  56. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
  57. package/apps/runtime/dist/db/schema.js +295 -72
  58. package/apps/runtime/dist/docs/dev/architecture.md +215 -0
  59. package/apps/runtime/dist/docs/dev/broker.md +298 -0
  60. package/apps/runtime/dist/docs/dev/index.md +5 -1
  61. package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
  62. package/apps/runtime/dist/docs/dev/meta.json +3 -0
  63. package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
  64. package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
  65. package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
  66. package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
  67. package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
  68. package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
  69. package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
  70. package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
  71. package/apps/runtime/dist/docs/dev/skills.md +16 -9
  72. package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +40 -5
  73. package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
  74. package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
  75. package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
  76. package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
  77. package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
  78. package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
  79. package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
  80. package/apps/runtime/dist/docs/user-guide/index.md +10 -1
  81. package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
  82. package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
  83. package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
  84. package/apps/runtime/dist/docs/user-guide/space.md +5 -4
  85. package/apps/runtime/dist/docs/user-guide/together.md +16 -2
  86. package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
  87. package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
  88. package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
  89. package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
  90. package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
  91. package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
  92. package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
  93. package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
  94. package/apps/runtime/dist/engine/resources.js +43 -12
  95. package/apps/runtime/dist/engine/runner.js +75 -23
  96. package/apps/runtime/dist/engine/steps.js +30 -12
  97. package/apps/runtime/dist/engine/template.js +18 -1
  98. package/apps/runtime/dist/env.js +9 -4
  99. package/apps/runtime/dist/index.js +18 -2
  100. package/apps/runtime/dist/live/feed.js +2 -2
  101. package/apps/runtime/dist/live/origin.js +2 -2
  102. package/apps/runtime/dist/live/views.js +51 -26
  103. package/apps/runtime/dist/manage.js +7 -0
  104. package/apps/runtime/dist/mcp/flow-app.js +1 -1
  105. package/apps/runtime/dist/mcp/tools.js +75 -34
  106. package/apps/runtime/dist/models.js +1 -1
  107. package/apps/runtime/dist/motion-graphics/project.js +8 -8
  108. package/apps/runtime/dist/motion-graphics/tools.js +1 -1
  109. package/apps/runtime/dist/plugins/events.js +2 -2
  110. package/apps/runtime/dist/plugins/jobs.js +4 -1
  111. package/apps/runtime/dist/plugins/loader.js +2 -2
  112. package/apps/runtime/dist/prompts/architect.md +3 -3
  113. package/apps/runtime/dist/prompts/authoring.md +46 -12
  114. package/apps/runtime/dist/prompts/goose.md +7 -7
  115. package/apps/runtime/dist/prompts/mcp.md +6 -6
  116. package/apps/runtime/dist/prompts/services.md +4 -4
  117. package/apps/runtime/dist/prompts/step.md +2 -2
  118. package/apps/runtime/dist/prompts/tools.md +39 -10
  119. package/apps/runtime/dist/routes/api.js +31 -20
  120. package/apps/runtime/dist/routes/broker.js +316 -0
  121. package/apps/runtime/dist/routes/connections.js +71 -0
  122. package/apps/runtime/dist/routes/delivery.js +25 -0
  123. package/apps/runtime/dist/routes/discover.js +17 -0
  124. package/apps/runtime/dist/routes/live.js +11 -1
  125. package/apps/runtime/dist/routes/person.js +4 -1
  126. package/apps/runtime/dist/routes/plugins.js +3 -1
  127. package/apps/runtime/dist/routes/rules.js +26 -0
  128. package/apps/runtime/dist/routes/runs.js +54 -33
  129. package/apps/runtime/dist/routes/skills.js +6 -6
  130. package/apps/runtime/dist/routes/studio.js +153 -144
  131. package/apps/runtime/dist/routes/work.js +199 -0
  132. package/apps/runtime/dist/sandbox/index.js +27 -0
  133. package/apps/runtime/dist/services/access.js +38 -17
  134. package/apps/runtime/dist/services/api.js +38 -13
  135. package/apps/runtime/dist/services/architect.js +3 -3
  136. package/apps/runtime/dist/services/assistant-chats.js +9 -1
  137. package/apps/runtime/dist/services/brand.js +12 -12
  138. package/apps/runtime/dist/services/broker-bell.js +69 -0
  139. package/apps/runtime/dist/services/broker-notify.js +127 -0
  140. package/apps/runtime/dist/services/client-steps.js +79 -0
  141. package/apps/runtime/dist/services/cloud.js +42 -42
  142. package/apps/runtime/dist/services/command-risk.js +51 -0
  143. package/apps/runtime/dist/services/discover.js +85 -0
  144. package/apps/runtime/dist/services/knowledge-model.js +13 -13
  145. package/apps/runtime/dist/services/knowledge.js +117 -80
  146. package/apps/runtime/dist/services/manage-reports.js +74 -7
  147. package/apps/runtime/dist/services/members-studio.js +165 -0
  148. package/apps/runtime/dist/services/onboarding.js +22 -22
  149. package/apps/runtime/dist/services/package-file.js +1 -1
  150. package/apps/runtime/dist/services/package.js +22 -22
  151. package/apps/runtime/dist/services/pages.js +7 -7
  152. package/apps/runtime/dist/services/runs.js +4 -3
  153. package/apps/runtime/dist/services/seen.js +55 -0
  154. package/apps/runtime/dist/services/shares.js +23 -13
  155. package/apps/runtime/dist/services/site.js +23 -23
  156. package/apps/runtime/dist/services/skills-registry.js +15 -15
  157. package/apps/runtime/dist/services/skills.js +44 -44
  158. package/apps/runtime/dist/services/space-categories.js +35 -35
  159. package/apps/runtime/dist/services/space-data.js +130 -111
  160. package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
  161. package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
  162. package/apps/runtime/dist/services/space-origin.js +19 -11
  163. package/apps/runtime/dist/services/spaces.js +478 -612
  164. package/apps/runtime/dist/services/synced-spaces.js +668 -0
  165. package/apps/runtime/dist/services/themes.js +15 -15
  166. package/apps/runtime/dist/services/widgets.js +6 -6
  167. package/apps/runtime/dist/services/wizards.js +112 -38
  168. package/apps/runtime/dist/services/work-ai.js +257 -0
  169. package/apps/runtime/dist/services/work-approvals.js +104 -0
  170. package/apps/runtime/dist/services/work-chats.js +908 -0
  171. package/apps/runtime/dist/services/work-connections.js +90 -0
  172. package/apps/runtime/dist/services/work-files.js +85 -0
  173. package/apps/runtime/dist/services/work-mastra.js +73 -0
  174. package/apps/runtime/dist/services/work-sandbox.js +42 -0
  175. package/apps/runtime/dist/sharing/files.js +14 -4
  176. package/apps/runtime/dist/sharing/index.js +40 -39
  177. package/apps/runtime/dist/sharing/jobs.js +67 -17
  178. package/apps/runtime/dist/sharing/targets/connector.js +10 -6
  179. package/apps/runtime/dist/sharing/targets/email.js +10 -8
  180. package/apps/runtime/dist/sharing/targets/slack.js +10 -8
  181. package/apps/runtime/dist/sharing/targets/storage.js +6 -4
  182. package/apps/runtime/dist/store/index.js +14 -3
  183. package/apps/runtime/dist/store/shared-lists.js +4 -2
  184. package/apps/runtime/dist/sync/apply.js +2 -2
  185. package/apps/runtime/dist/sync/client.js +113 -113
  186. package/apps/runtime/dist/sync/hub.js +41 -41
  187. package/apps/runtime/dist/sync/log.js +12 -12
  188. package/apps/runtime/dist/sync/records.js +118 -120
  189. package/apps/runtime/dist/texts.js +38 -2
  190. package/apps/runtime/dist/tools/connections.js +112 -0
  191. package/apps/runtime/dist/tools/connector.js +157 -67
  192. package/apps/runtime/dist/tools/index.js +28 -13
  193. package/apps/runtime/dist/tools/mail.js +40 -11
  194. package/apps/runtime/dist/tools/pages.js +11 -5
  195. package/apps/runtime/dist/tools/plugin.js +43 -7
  196. package/apps/runtime/dist/tools/skills.js +1 -1
  197. package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
  198. package/apps/runtime/dist/tools/store.js +3 -2
  199. package/apps/runtime/dist/widgets/step.js +10 -10
  200. package/apps/web/dist/assets/AboutDialog-DgfeipUc.js +1 -0
  201. package/apps/web/dist/assets/CapabilitiesPage-BoYJvgIu.js +2 -0
  202. package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-Duab4zTO.js} +1 -1
  203. package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
  204. package/apps/web/dist/assets/EditorPage-ZrgGpYMC.js +3 -0
  205. package/apps/web/dist/assets/{FlowPreview-DtSpjVTl.js → FlowPreview-aMfwcPul.js} +1 -1
  206. package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
  207. package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
  208. package/apps/web/dist/assets/NewWizardChannels-IB18afWN.js +1 -0
  209. package/apps/web/dist/assets/NewWizardPage-rYbcmPGG.js +7 -0
  210. package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
  211. package/apps/web/dist/assets/PreviewPane-DviWTLfi.js +9 -0
  212. package/apps/web/dist/assets/PublicRunner-C2geZhhM.js +1 -0
  213. package/apps/web/dist/assets/ReadOnly-kSb_Kbdm.js +1 -0
  214. package/apps/web/dist/assets/SettingsPage-DM2h8N0J.js +2 -0
  215. package/apps/web/dist/assets/SetupPage-Wfyz6xH4.js +1 -0
  216. package/apps/web/dist/assets/SharePage-CyWQorWB.js +1 -0
  217. package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
  218. package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
  219. package/apps/web/dist/assets/SpacePage-q4Bk3N7k.js +2 -0
  220. package/apps/web/dist/assets/UpdateCheck-C2CE6CC3.js +2 -0
  221. package/apps/web/dist/assets/changelog-B6hN1Cp7.js +1 -0
  222. package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
  223. package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
  224. package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
  225. package/apps/web/dist/assets/{code-xml-TwKzzMtA.js → code-xml-B4kLFZSj.js} +1 -1
  226. package/apps/web/dist/assets/connection-sign-in-CIiv0t2p.js +1 -0
  227. package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
  228. package/apps/web/dist/assets/{eye-Brd-xPUJ.js → eye-BpoKpIdt.js} +1 -1
  229. package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
  230. package/apps/web/dist/assets/host-DJ7-p0Sc.js +118 -0
  231. package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
  232. package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
  233. package/apps/web/dist/assets/index-D2akynS-.js +10 -0
  234. package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
  235. package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
  236. package/apps/web/dist/assets/{phone-DhkHteoJ.js → phone-Ctvf-Am-.js} +1 -1
  237. package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
  238. package/apps/web/dist/assets/{runners-G-XYaDgR.js → runners-CyIvJIHr.js} +1 -1
  239. package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
  240. package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
  241. package/apps/web/dist/assets/theme-CbTcTFWy.js +11 -0
  242. package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
  243. package/apps/web/dist/assets/{upload-BYZTwJTD.js → upload-BchUnQGV.js} +1 -1
  244. package/apps/web/dist/assets/{useMutation-D0QP_k2-.js → useMutation-DEkZhp5c.js} +1 -1
  245. package/apps/web/dist/assets/{volume-2-CVHoxdGM.js → volume-2-CU_oy81Z.js} +1 -1
  246. package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
  247. package/apps/web/dist/index.html +17 -10
  248. package/apps/web/dist/mcp/flow.html +119 -64
  249. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
  250. package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -1
  251. package/node_modules/@engenty/wizards-shared/dist/assistant.js +6 -1
  252. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
  253. package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
  254. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +150 -8
  255. package/node_modules/@engenty/wizards-shared/dist/definition.js +46 -11
  256. package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
  257. package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
  258. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +26 -2
  259. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +26 -2
  260. package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
  261. package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
  262. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
  263. package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
  264. package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
  265. package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
  266. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -6
  267. package/node_modules/@engenty/wizards-shared/dist/run.js +85 -0
  268. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
  269. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
  270. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
  271. package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
  272. package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
  273. package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
  274. package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
  275. package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
  276. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
  277. package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
  278. package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
  279. package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
  280. package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
  281. package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
  282. package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
  283. package/package.json +4 -1
  284. package/plugin/.claude-plugin/plugin.json +1 -1
  285. package/plugin/plugin.json +1 -1
  286. package/plugin/skills/build-wizard/SKILL.md +1 -1
  287. package/apps/runtime/dist/services/projects.js +0 -473
  288. package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +0 -1
  289. package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +0 -3
  290. package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +0 -2
  291. package/apps/web/dist/assets/NewWizardChannels-Tgoexgj4.js +0 -1
  292. package/apps/web/dist/assets/NewWizardPage-B24AF482.js +0 -7
  293. package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +0 -1
  294. package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +0 -10
  295. package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +0 -10
  296. package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +0 -1
  297. package/apps/web/dist/assets/ReadOnly-BXjv-MSv.js +0 -1
  298. package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +0 -2
  299. package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +0 -1
  300. package/apps/web/dist/assets/SharePage-DXGzJSnR.js +0 -1
  301. package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +0 -1
  302. package/apps/web/dist/assets/changelog-BLdS-0Bj.js +0 -1
  303. package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
  304. package/apps/web/dist/assets/i18n-8-Sw11tB.js +0 -55
  305. package/apps/web/dist/assets/index-OsdQFHmh.js +0 -49
  306. package/apps/web/dist/assets/index-QPipX5Fi.css +0 -1
  307. package/apps/web/dist/assets/lock-C0uxcOlq.js +0 -1
  308. package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
  309. package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
  310. package/apps/web/dist/assets/session-BWI-KENJ.js +0 -2
  311. package/apps/web/dist/assets/theme-D7krsx0_.js +0 -11
  312. package/apps/web/dist/assets/ui-DSXG3f49.js +0 -83
  313. /package/apps/runtime/dist/db/migrations/tenant/{0027_space_skill.sql → 0030_space_skill.sql} +0 -0
@@ -1,10 +1,12 @@
1
+ import { CONNECTION_AUDIENCES, CONNECTION_SIGN_INS, } from "@engenty/wizards-shared/connectors";
2
+ import { RWX_FLAGS, RWX_RESOURCE_KINDS, RWX_SUBJECT_KINDS } from "@engenty/wizards-shared/rwx";
1
3
  import { SKILL_MODES, SKILL_SOURCES, } from "@engenty/wizards-shared/skills";
2
4
  import { sql } from "drizzle-orm";
3
5
  import { blob, index, integer, primaryKey, real, sqliteTable, text, uniqueIndex, } from "drizzle-orm/sqlite-core";
4
6
  const now = sql `(unixepoch() * 1000)`;
5
7
  const createdAt = () => integer("created_at", { mode: "timestamp_ms" }).notNull().default(now);
6
8
  const updatedAt = () => integer("updated_at", { mode: "timestamp_ms" }).notNull().default(now);
7
- export const project = sqliteTable("project", {
9
+ export const space = sqliteTable("space", {
8
10
  id: text("id").primaryKey(),
9
11
  tenantId: text("tenant_id").notNull(),
10
12
  name: text("name").notNull(),
@@ -15,19 +17,40 @@ export const project = sqliteTable("project", {
15
17
  /** The space's public page at `<organization>.wizards.page/<slug>`; null until it is set up. */
16
18
  page: text("page", { mode: "json" }).$type(),
17
19
  /**
18
- * `local`: the project of a local install, synced here when that install publishes. It keeps
20
+ * The space's own mail domains (`firma.at`): a guest's run may send to an address in one of
21
+ * them, besides the address the run itself collected (broker/send.ts). Admins set them.
22
+ */
23
+ mailDomains: text("mail_domains", { mode: "json" }).$type().notNull().default([]),
24
+ /**
25
+ * How the space's admins hear of the broker's critical lines (docs/plans/broker.md,
26
+ * "Notifications"): under Work's bell, and by mail once an hour where nobody of them was in
27
+ * the app. Set through `PATCH /api/studio/spaces/:id`, on Fähigkeiten › Protokoll.
28
+ */
29
+ notify: text("notify", { mode: "json" })
30
+ .$type()
31
+ .notNull()
32
+ .default({ bell: true, mail: "hourly" }),
33
+ /** When the hourly mail last went out, or was skipped because an admin had seen the bell. */
34
+ criticalMailedAt: integer("critical_mailed_at", { mode: "timestamp_ms" }),
35
+ /**
36
+ * „Mitglieder dürfen ins Studio“: the organization's members build here too, with less than
37
+ * its admins (services/members-studio.ts). One rule for all members; admins set it.
38
+ */
39
+ membersStudio: integer("members_studio", { mode: "boolean" }).notNull().default(false),
40
+ /**
41
+ * `local`: the space of a local install, synced here when that install publishes. It keeps
19
42
  * the ids it has there and is changed only by the next sync. Null: made on this runtime.
20
43
  */
21
44
  origin: text("origin", { enum: ["local"] }),
22
45
  syncedAt: integer("synced_at", { mode: "timestamp_ms" }),
23
46
  createdAt: createdAt(),
24
47
  updatedAt: updatedAt(),
25
- }, (t) => [index("project_tenant").on(t.tenantId)]);
48
+ }, (t) => [index("space_tenant").on(t.tenantId)]);
26
49
  export const wizard = sqliteTable("wizard", {
27
50
  id: text("id").primaryKey(),
28
- projectId: text("project_id")
51
+ spaceId: text("space_id")
29
52
  .notNull()
30
- .references(() => project.id, { onDelete: "cascade" }),
53
+ .references(() => space.id, { onDelete: "cascade" }),
31
54
  tenantId: text("tenant_id").notNull(),
32
55
  title: text("title").notNull(),
33
56
  draft: text("draft", { mode: "json" }).$type().notNull(),
@@ -35,6 +58,8 @@ export const wizard = sqliteTable("wizard", {
35
58
  shareToken: text("share_token").notNull(),
36
59
  shareEnabled: integer("share_enabled", { mode: "boolean" }).notNull().default(true),
37
60
  dailyRunLimit: integer("daily_run_limit").notNull().default(50),
61
+ /** How many emails guests' runs of this wizard send per day, from any address (broker/send.ts). */
62
+ dailyMailLimit: integer("daily_mail_limit").notNull().default(50),
38
63
  starter: text("starter"),
39
64
  /** The revision of the marketplace entry the wizard was made from. */
40
65
  starterRevision: integer("starter_revision"),
@@ -46,10 +71,7 @@ export const wizard = sqliteTable("wizard", {
46
71
  translate: integer("translate", { mode: "boolean" }).notNull().default(true),
47
72
  createdAt: createdAt(),
48
73
  updatedAt: updatedAt(),
49
- }, (t) => [
50
- uniqueIndex("wizard_share_token").on(t.shareToken),
51
- index("wizard_project").on(t.projectId),
52
- ]);
74
+ }, (t) => [uniqueIndex("wizard_share_token").on(t.shareToken), index("wizard_space").on(t.spaceId)]);
53
75
  export const wizardVersion = sqliteTable("wizard_version", {
54
76
  id: text("id").primaryKey(),
55
77
  wizardId: text("wizard_id")
@@ -114,6 +136,11 @@ export const run = sqliteTable("run", {
114
136
  definition: text("definition", { mode: "json" }).$type().notNull(),
115
137
  /** The workspace the run started with. */
116
138
  files: text("files", { mode: "json" }).$type().notNull().default([]),
139
+ /**
140
+ * What the run may reach outside, from the definition it started on (broker/grant.ts); null
141
+ * on a run from before grants were kept, filled from its definition on first use.
142
+ */
143
+ grant: text("grant", { mode: "json" }).$type(),
117
144
  version: integer("version"),
118
145
  mode: text("mode", { enum: ["test", "live"] }).notNull(),
119
146
  /** The door the run came through: steps, chat, or a plugin's runner. Null: the page. */
@@ -235,24 +262,24 @@ export const asset = sqliteTable("asset", {
235
262
  * A service imported as a connector, from the integrations registry or a pasted OpenAPI spec /
236
263
  * MCP endpoint. The record is engenty's: actions, auth and source, normalised at import time.
237
264
  */
238
- export const projectConnector = sqliteTable("project_connector", {
239
- projectId: text("project_id")
265
+ export const spaceConnector = sqliteTable("space_connector", {
266
+ spaceId: text("space_id")
240
267
  .notNull()
241
- .references(() => project.id, { onDelete: "cascade" }),
268
+ .references(() => space.id, { onDelete: "cascade" }),
242
269
  id: text("id").notNull(),
243
270
  record: text("record", { mode: "json" }).$type().notNull(),
244
271
  createdAt: createdAt(),
245
272
  updatedAt: updatedAt(),
246
- }, (t) => [primaryKey({ columns: [t.projectId, t.id] })]);
273
+ }, (t) => [primaryKey({ columns: [t.spaceId, t.id] })]);
247
274
  /**
248
- * What a project holds for all its wizards: logos, assets (images, graphics, videos) and
275
+ * What a space holds for all its wizards: logos, assets (images, graphics, videos) and
249
276
  * documents. `id` is the asset the content lives in. The first logo is the one end users see.
250
277
  */
251
- export const projectFile = sqliteTable("project_file", {
278
+ export const spaceFile = sqliteTable("space_file", {
252
279
  id: text("id").primaryKey(),
253
- projectId: text("project_id")
280
+ spaceId: text("space_id")
254
281
  .notNull()
255
- .references(() => project.id, { onDelete: "cascade" }),
282
+ .references(() => space.id, { onDelete: "cascade" }),
256
283
  kind: text("kind", { enum: ["logo", "asset", "document", "pattern"] }).notNull(),
257
284
  name: text("name").notNull(),
258
285
  mime: text("mime").notNull(),
@@ -279,24 +306,24 @@ export const projectFile = sqliteTable("project_file", {
279
306
  createdAt: createdAt(),
280
307
  updatedAt: updatedAt(),
281
308
  }, (t) => [
282
- index("project_file_project").on(t.projectId, t.kind, t.position),
283
- uniqueIndex("project_file_origin").on(t.projectId, t.origin, t.originKey),
309
+ index("space_file_space").on(t.spaceId, t.kind, t.position),
310
+ uniqueIndex("space_file_origin").on(t.spaceId, t.origin, t.originKey),
284
311
  ]);
285
312
  /**
286
313
  * The index of Knowledge: one unit per section of a page, row of a table, file, summary of a
287
314
  * category's value, passage of a document read before pages, and passage of a plugin's text
288
315
  * (`server.index`). Each unit's text starts with where it stands and its categories. Keywords
289
- * live in two FTS5 tables, words (`project_chunk_fts`) and trigrams (`project_chunk_tri`), which
316
+ * live in two FTS5 tables, words (`space_chunk_fts`) and trigrams (`space_chunk_tri`), which
290
317
  * triggers keep in step (see the migrations); `embedding` is the unit's vector as float32
291
318
  * bytes, compared with libSQL's `vector_distance_cos`.
292
319
  */
293
- export const projectChunk = sqliteTable("project_chunk", {
320
+ export const spaceChunk = sqliteTable("space_chunk", {
294
321
  id: integer("id").primaryKey({ autoIncrement: true }),
295
- projectId: text("project_id")
322
+ spaceId: text("space_id")
296
323
  .notNull()
297
- .references(() => project.id, { onDelete: "cascade" }),
324
+ .references(() => space.id, { onDelete: "cascade" }),
298
325
  /** The document the passage is of; null for a plugin's text. */
299
- fileId: text("file_id").references(() => projectFile.id, { onDelete: "cascade" }),
326
+ fileId: text("file_id").references(() => spaceFile.id, { onDelete: "cascade" }),
300
327
  /** What the unit is of: a page, a row (with its table), a table (FAQ format: a row), a value. */
301
328
  pageId: text("page_id").references(() => spacePage.id, {
302
329
  onDelete: "cascade",
@@ -325,13 +352,13 @@ export const projectChunk = sqliteTable("project_chunk", {
325
352
  /** The model the vector was made with; only vectors of one model are compared. */
326
353
  model: text("model"),
327
354
  }, (t) => [
328
- index("project_chunk_project").on(t.projectId, t.model),
329
- index("project_chunk_file").on(t.fileId),
330
- index("project_chunk_ref").on(t.projectId, t.plugin, t.ref),
331
- index("project_chunk_page").on(t.pageId),
332
- index("project_chunk_row").on(t.rowId),
333
- index("project_chunk_table").on(t.tableId),
334
- index("project_chunk_value").on(t.valueId),
355
+ index("space_chunk_space").on(t.spaceId, t.model),
356
+ index("space_chunk_file").on(t.fileId),
357
+ index("space_chunk_ref").on(t.spaceId, t.plugin, t.ref),
358
+ index("space_chunk_page").on(t.pageId),
359
+ index("space_chunk_row").on(t.rowId),
360
+ index("space_chunk_table").on(t.tableId),
361
+ index("space_chunk_value").on(t.valueId),
335
362
  ]);
336
363
  // --- The space's data -------------------------------------------------------
337
364
  // Tables and pages a space keeps, its own or one of its wizards'. Shared by everyone who works
@@ -340,9 +367,9 @@ export const projectChunk = sqliteTable("project_chunk", {
340
367
  export const spaceTable = sqliteTable("space_table", {
341
368
  id: text("id").primaryKey(),
342
369
  tenantId: text("tenant_id").notNull(),
343
- projectId: text("project_id")
370
+ spaceId: text("space_id")
344
371
  .notNull()
345
- .references(() => project.id, { onDelete: "cascade" }),
372
+ .references(() => space.id, { onDelete: "cascade" }),
346
373
  /** The wizard it belongs to; null: the space's own. */
347
374
  wizardId: text("wizard_id").references(() => wizard.id, { onDelete: "cascade" }),
348
375
  /**
@@ -370,13 +397,13 @@ export const spaceTable = sqliteTable("space_table", {
370
397
  /** Why a person should look at it ("hardly readable"); null when nothing is in doubt. */
371
398
  review: text("review"),
372
399
  /** The file it was read from, kept as the evidence. */
373
- fileId: text("file_id").references(() => projectFile.id, { onDelete: "set null" }),
400
+ fileId: text("file_id").references(() => spaceFile.id, { onDelete: "set null" }),
374
401
  createdAt: createdAt(),
375
402
  updatedAt: updatedAt(),
376
403
  }, (t) => [
377
- index("space_table_project").on(t.projectId, t.wizardId),
404
+ index("space_table_space").on(t.spaceId, t.wizardId),
378
405
  uniqueIndex("space_table_list").on(t.wizardId, t.list),
379
- uniqueIndex("space_table_origin").on(t.projectId, t.origin, t.originKey),
406
+ uniqueIndex("space_table_origin").on(t.spaceId, t.origin, t.originKey),
380
407
  ]);
381
408
  /** A row of a table: cells by column id. Rows stand in the order they were added. */
382
409
  export const spaceTableRow = sqliteTable("space_table_row", {
@@ -400,9 +427,9 @@ export const spaceTableRow = sqliteTable("space_table_row", {
400
427
  export const spacePage = sqliteTable("space_page", {
401
428
  id: text("id").primaryKey(),
402
429
  tenantId: text("tenant_id").notNull(),
403
- projectId: text("project_id")
430
+ spaceId: text("space_id")
404
431
  .notNull()
405
- .references(() => project.id, { onDelete: "cascade" }),
432
+ .references(() => space.id, { onDelete: "cascade" }),
406
433
  wizardId: text("wizard_id").references(() => wizard.id, { onDelete: "cascade" }),
407
434
  parentId: text("parent_id").references(() => spacePage.id, {
408
435
  onDelete: "cascade",
@@ -425,13 +452,13 @@ export const spacePage = sqliteTable("space_page", {
425
452
  /** Why a person should look at it ("hardly readable"); null when nothing is in doubt. */
426
453
  review: text("review"),
427
454
  /** The file it was read from, kept as the evidence. */
428
- fileId: text("file_id").references(() => projectFile.id, { onDelete: "set null" }),
455
+ fileId: text("file_id").references(() => spaceFile.id, { onDelete: "set null" }),
429
456
  createdAt: createdAt(),
430
457
  updatedAt: updatedAt(),
431
458
  }, (t) => [
432
- index("space_page_project").on(t.projectId, t.wizardId),
459
+ index("space_page_space").on(t.spaceId, t.wizardId),
433
460
  index("space_page_parent").on(t.parentId, t.position),
434
- uniqueIndex("space_page_origin").on(t.projectId, t.origin, t.originKey),
461
+ uniqueIndex("space_page_origin").on(t.spaceId, t.origin, t.originKey),
435
462
  ]);
436
463
  // --- Categories -----------------------------------------------------------------
437
464
  // Typed properties that run across Knowledge: set on pages, rows, tables and files, any number of
@@ -440,9 +467,9 @@ export const spacePage = sqliteTable("space_page", {
440
467
  export const spaceCategory = sqliteTable("space_category", {
441
468
  id: text("id").primaryKey(),
442
469
  tenantId: text("tenant_id").notNull(),
443
- projectId: text("project_id")
470
+ spaceId: text("space_id")
444
471
  .notNull()
445
- .references(() => project.id, { onDelete: "cascade" }),
472
+ .references(() => space.id, { onDelete: "cascade" }),
446
473
  name: text("name").notNull(),
447
474
  type: text("type", { enum: ["choice", "date", "number", "text", "boolean"] }).notNull(),
448
475
  /** A number's unit: `h`, `€`, `kg`. */
@@ -463,7 +490,7 @@ export const spaceCategory = sqliteTable("space_category", {
463
490
  position: integer("position").notNull().default(0),
464
491
  createdAt: createdAt(),
465
492
  updatedAt: updatedAt(),
466
- }, (t) => [uniqueIndex("space_category_name").on(t.projectId, t.name)]);
493
+ }, (t) => [uniqueIndex("space_category_name").on(t.spaceId, t.name)]);
467
494
  /** A value of a choice: grows as items arrive; its summary is the summary of its items. */
468
495
  export const spaceCategoryValue = sqliteTable("space_category_value", {
469
496
  id: text("id").primaryKey(),
@@ -484,16 +511,16 @@ export const spaceCategoryValue = sqliteTable("space_category_value", {
484
511
  */
485
512
  export const spaceItemCategory = sqliteTable("space_item_category", {
486
513
  id: integer("id").primaryKey({ autoIncrement: true }),
487
- projectId: text("project_id")
514
+ spaceId: text("space_id")
488
515
  .notNull()
489
- .references(() => project.id, { onDelete: "cascade" }),
516
+ .references(() => space.id, { onDelete: "cascade" }),
490
517
  categoryId: text("category_id")
491
518
  .notNull()
492
519
  .references(() => spaceCategory.id, { onDelete: "cascade" }),
493
520
  pageId: text("page_id").references(() => spacePage.id, { onDelete: "cascade" }),
494
521
  rowId: text("row_id").references(() => spaceTableRow.id, { onDelete: "cascade" }),
495
522
  tableId: text("table_id").references(() => spaceTable.id, { onDelete: "cascade" }),
496
- fileId: text("file_id").references(() => projectFile.id, { onDelete: "cascade" }),
523
+ fileId: text("file_id").references(() => spaceFile.id, { onDelete: "cascade" }),
497
524
  valueId: text("value_id").references(() => spaceCategoryValue.id, { onDelete: "cascade" }),
498
525
  text: text("text"),
499
526
  num: real("num"),
@@ -516,9 +543,9 @@ export const spaceItemCategory = sqliteTable("space_item_category", {
516
543
  export const spaceSkill = sqliteTable("space_skill", {
517
544
  id: text("id").primaryKey(),
518
545
  tenantId: text("tenant_id").notNull(),
519
- projectId: text("project_id")
546
+ spaceId: text("space_id")
520
547
  .notNull()
521
- .references(() => project.id, { onDelete: "cascade" }),
548
+ .references(() => space.id, { onDelete: "cascade" }),
522
549
  /** Its name in the format: lower case and hyphens, unique in the space. */
523
550
  name: text("name").notNull(),
524
551
  description: text("description").notNull(),
@@ -539,7 +566,34 @@ export const spaceSkill = sqliteTable("space_skill", {
539
566
  originHash: text("origin_hash"),
540
567
  createdAt: createdAt(),
541
568
  updatedAt: updatedAt(),
542
- }, (t) => [uniqueIndex("space_skill_name").on(t.projectId, t.name)]);
569
+ }, (t) => [uniqueIndex("space_skill_name").on(t.spaceId, t.name)]);
570
+ // --- The broker: RWX ---------------------------------------------------------------
571
+ // One table of permissions per space (docs/plans/broker.md, "First: RWX"): who (a guest, a
572
+ // person, a role, Goose for a person, a wizard, a plugin) may read, write or execute what (a
573
+ // document, a table, a page …; `*` for all of a kind). Each flag is allow, deny or unset; unset
574
+ // means deny, and a deny wins over every allow. The runtime asks in broker/rwx.ts.
575
+ export const rwxRule = sqliteTable("rwx_rule", {
576
+ id: text("id").primaryKey(),
577
+ tenantId: text("tenant_id").notNull(),
578
+ spaceId: text("space_id")
579
+ .notNull()
580
+ .references(() => space.id, { onDelete: "cascade" }),
581
+ subjectKind: text("subject_kind", { enum: RWX_SUBJECT_KINDS }).notNull(),
582
+ /** `member`, `admin` or `owner` for a role; a user's, a wizard's or a plugin's id; null for a guest. */
583
+ subjectId: text("subject_id"),
584
+ resourceKind: text("resource_kind", { enum: RWX_RESOURCE_KINDS }).notNull(),
585
+ /** The resource's id, or `*` for every resource of the kind. */
586
+ resourceId: text("resource_id").notNull(),
587
+ r: text("r", { enum: RWX_FLAGS }),
588
+ w: text("w", { enum: RWX_FLAGS }),
589
+ x: text("x", { enum: RWX_FLAGS }),
590
+ /** Who wrote the row: a user's id, or `seed` for the rows every space starts with. */
591
+ createdBy: text("created_by").notNull(),
592
+ createdAt: createdAt(),
593
+ }, (t) => [
594
+ uniqueIndex("rwx_rule_key").on(t.spaceId, t.subjectKind, t.subjectId, t.resourceKind, t.resourceId),
595
+ index("rwx_rule_space").on(t.spaceId),
596
+ ]);
543
597
  export const assistantChat = sqliteTable("assistant_chat", {
544
598
  id: text("id").primaryKey(),
545
599
  tenantId: text("tenant_id").notNull(),
@@ -570,6 +624,102 @@ export const assistantMessage = sqliteTable("assistant_message", {
570
624
  changed: integer("changed", { mode: "boolean" }).notNull().default(false),
571
625
  createdAt: createdAt(),
572
626
  }, (t) => [index("assistant_message_chat").on(t.chatId, t.createdAt)]);
627
+ // --- Work's chats (behind `workMode`) --------------------------------------------
628
+ // A chat belongs to a space, has members (people, later engenties) and lives in a section of
629
+ // the space's sidebar or in none. A sub-thread is a chat with a parent. A private chat is seen by
630
+ // its members only; any other chat by everyone of the tenant. The messages are Mastra's: a
631
+ // memory thread per chat (thread id = chat id, resource id = the space), in Mastra's tables of
632
+ // the same database (services/work-mastra.ts). The chat row keeps what the sidebar shows.
633
+ export const chatSection = sqliteTable("chat_section", {
634
+ id: text("id").primaryKey(),
635
+ tenantId: text("tenant_id").notNull(),
636
+ spaceId: text("space_id")
637
+ .notNull()
638
+ .references(() => space.id, { onDelete: "cascade" }),
639
+ name: text("name").notNull(),
640
+ position: integer("position").notNull().default(0),
641
+ createdBy: text("created_by").notNull(),
642
+ createdAt: createdAt(),
643
+ }, (t) => [index("chat_section_space").on(t.spaceId, t.position)]);
644
+ export const chat = sqliteTable("chat", {
645
+ id: text("id").primaryKey(),
646
+ tenantId: text("tenant_id").notNull(),
647
+ spaceId: text("space_id")
648
+ .notNull()
649
+ .references(() => space.id, { onDelete: "cascade" }),
650
+ title: text("title").notNull(),
651
+ sectionId: text("section_id").references(() => chatSection.id, { onDelete: "set null" }),
652
+ parentId: text("parent_id").references(() => chat.id, {
653
+ onDelete: "cascade",
654
+ }),
655
+ private: integer("private", { mode: "boolean" }).notNull().default(false),
656
+ createdBy: text("created_by").notNull(),
657
+ createdAt: createdAt(),
658
+ /** The last message's time, else when it was made: the sidebar's order. */
659
+ updatedAt: updatedAt(),
660
+ /** The last message for the sidebar: who wrote it ("ai" for the space's AI), its start. */
661
+ lastAuthorId: text("last_author_id"),
662
+ lastAuthorName: text("last_author_name"),
663
+ lastText: text("last_text"),
664
+ /** Since when the space's AI answers here; null while it doesn't. Others follow the turn. */
665
+ answeringSince: integer("answering_since", { mode: "timestamp_ms" }),
666
+ }, (t) => [index("chat_space").on(t.spaceId, t.updatedAt), index("chat_parent").on(t.parentId)]);
667
+ export const chatMember = sqliteTable("chat_member", {
668
+ chatId: text("chat_id")
669
+ .notNull()
670
+ .references(() => chat.id, { onDelete: "cascade" }),
671
+ kind: text("kind", { enum: ["person", "engenty"] }).notNull(),
672
+ /** A person's user id, an engenty's id. */
673
+ memberId: text("member_id").notNull(),
674
+ joinedAt: integer("joined_at", { mode: "timestamp_ms" }).notNull().default(now),
675
+ }, (t) => [
676
+ primaryKey({ columns: [t.chatId, t.kind, t.memberId] }),
677
+ index("chat_member_member").on(t.kind, t.memberId),
678
+ ]);
679
+ /** What one person did with a chat: pinned it, archived it for themselves, read it up to when. */
680
+ export const chatState = sqliteTable("chat_state", {
681
+ chatId: text("chat_id")
682
+ .notNull()
683
+ .references(() => chat.id, { onDelete: "cascade" }),
684
+ userId: text("user_id").notNull(),
685
+ pinnedAt: integer("pinned_at", { mode: "timestamp_ms" }),
686
+ archivedAt: integer("archived_at", { mode: "timestamp_ms" }),
687
+ /** Null: never opened, or marked unread. */
688
+ readAt: integer("read_at", { mode: "timestamp_ms" }),
689
+ }, (t) => [primaryKey({ columns: [t.chatId, t.userId] })]);
690
+ /**
691
+ * A call of a tool that reaches past the space, held for a person's approval (Work chats, step 3
692
+ * piece 4). Approve runs the stored call once with the stored arguments; Deny doesn't. Either way
693
+ * the AI hears of it in the chat and goes on.
694
+ */
695
+ export const chatApproval = sqliteTable("chat_approval", {
696
+ id: text("id").primaryKey(),
697
+ tenantId: text("tenant_id").notNull(),
698
+ chatId: text("chat_id")
699
+ .notNull()
700
+ .references(() => chat.id, { onDelete: "cascade" }),
701
+ toolName: text("tool_name").notNull(),
702
+ input: text("input", { mode: "json" }).$type(),
703
+ /** Who the turn was for: the call runs with their access, and they may decide. */
704
+ askedBy: text("asked_by").notNull(),
705
+ /**
706
+ * Whose decision it waits for: the asker's (a confirmed action, a plugin's tool), or the
707
+ * space's admins' („Mit Freigabe“ on a connection that signs in as the space, A7).
708
+ */
709
+ heldFor: text("held_for", { enum: ["asker", "admins"] })
710
+ .notNull()
711
+ .default("asker"),
712
+ state: text("state", { enum: ["pending", "approved", "denied", "failed"] })
713
+ .notNull()
714
+ .default("pending"),
715
+ output: text("output", { mode: "json" }).$type(),
716
+ decidedBy: text("decided_by"),
717
+ decidedAt: integer("decided_at", { mode: "timestamp_ms" }),
718
+ createdAt: createdAt(),
719
+ }, (t) => [
720
+ index("chat_approval_chat").on(t.chatId, t.createdAt),
721
+ index("chat_approval_state").on(t.tenantId, t.state),
722
+ ]);
573
723
  // --- The wizard's store ------------------------------------------------------
574
724
  // What a wizard keeps between runs for one person. `holder` is that person: "u:<userId>" for a
575
725
  // signed-in admin, "v:<visitorId>" for an end user on a shared link.
@@ -634,26 +784,99 @@ export const marketplaceStar = sqliteTable("marketplace_star", {
634
784
  createdAt: createdAt(),
635
785
  }, (t) => [primaryKey({ columns: [t.tenantId, t.entryId] })]);
636
786
  /**
637
- * An account a plugin connected for a space (`server.connections`): a calendar, a mailbox. Not
638
- * a wizard's: it outlives runs and people. `data` is encrypted.
787
+ * A connection of a space (docs/plans/capabilities.md, "Connections"): a service the space's
788
+ * admins set up, with how it signs in, who may use it and what each kind of action may do. One
789
+ * that signs in as the space keeps its secret here, sealed; one each person signs in to keeps
790
+ * theirs in `space_connection_sign_in`. Nobody owns it: `set_up_by` only records who did.
639
791
  */
640
- export const pluginConnection = sqliteTable("plugin_connection", {
792
+ export const spaceConnection = sqliteTable("space_connection", {
641
793
  id: text("id").primaryKey(),
642
- plugin: text("plugin").notNull(),
643
- projectId: text("project_id")
794
+ spaceId: text("space_id")
644
795
  .notNull()
645
- .references(() => project.id, { onDelete: "cascade" }),
646
- /** The built-in connector: `google-calendar`, `microsoft-outlook`. */
647
- connector: text("connector").notNull(),
648
- /** Shown to the person: the account's address. */
796
+ .references(() => space.id, { onDelete: "cascade" }),
797
+ /** A built-in connector's id (`google-calendar`, `hubspot`) or a `space_connector` of the space. */
798
+ connectorId: text("connector_id").notNull(),
799
+ /** The plugin that set it up through `server.connections`, where one did. */
800
+ plugin: text("plugin"),
801
+ /** What people call it: „Vertrieb“, „Bestellungen“. */
802
+ name: text("name").notNull(),
803
+ /** A `space` sign-in: the account as the provider names it; null until signed in. */
804
+ label: text("label"),
805
+ signIn: text("sign_in", { enum: CONNECTION_SIGN_INS }).notNull(),
806
+ audience: text("audience", { enum: CONNECTION_AUDIENCES }).notNull(),
807
+ rules: text("rules", { mode: "json" }).$type().notNull(),
808
+ /** The connector's actions it is made for (the provider granted what they need); empty: every action. */
809
+ actions: text("actions", { mode: "json" }).$type().notNull().default([]),
810
+ /** A `space` sign-in's tokens or keys, sealed; the broker alone unseals them. */
811
+ secret: text("secret"),
812
+ setUpBy: text("set_up_by"),
813
+ setUpAt: integer("set_up_at", { mode: "timestamp_ms" }).notNull().default(now),
814
+ updatedAt: updatedAt(),
815
+ lastUsedAt: integer("last_used_at", { mode: "timestamp_ms" }),
816
+ }, (t) => [index("space_connection_space").on(t.spaceId)]);
817
+ /** A person's own sign-in to a connection in which each person signs in. `secret` is sealed. */
818
+ export const spaceConnectionSignIn = sqliteTable("space_connection_sign_in", {
819
+ connectionId: text("connection_id")
820
+ .notNull()
821
+ .references(() => spaceConnection.id, { onDelete: "cascade" }),
822
+ userId: text("user_id").notNull(),
823
+ /** The account as the provider names it. */
649
824
  label: text("label").notNull(),
650
- /** The connector's actions it was connected for. */
651
- actions: text("actions", { mode: "json" }).$type().notNull(),
652
- data: text("data").notNull(),
653
- createdBy: text("created_by"),
654
- createdAt: createdAt(),
825
+ secret: text("secret").notNull(),
826
+ signedInAt: integer("signed_in_at", { mode: "timestamp_ms" }).notNull().default(now),
655
827
  updatedAt: updatedAt(),
656
- }, (t) => [index("plugin_connection_space").on(t.plugin, t.projectId)]);
828
+ }, (t) => [primaryKey({ columns: [t.connectionId, t.userId] })]);
829
+ /**
830
+ * Every call that reaches outside through the broker (`broker/call.ts`): who called, where, which
831
+ * connection and action, what was decided and how it went. Append-only; a secret never goes in.
832
+ */
833
+ export const brokerLog = sqliteTable("broker_log", {
834
+ id: text("id").primaryKey(),
835
+ at: integer("at", { mode: "timestamp_ms" }).notNull(),
836
+ durationMs: integer("duration_ms").notNull(),
837
+ /** guest, person, admin, goose, plugin, step. */
838
+ whoKind: text("who_kind").notNull(),
839
+ whoId: text("who_id"),
840
+ runId: text("run_id"),
841
+ /** The step of the run that called; null outside a step. */
842
+ stepId: text("step_id"),
843
+ chatId: text("chat_id"),
844
+ wizardId: text("wizard_id"),
845
+ spaceId: text("space_id"),
846
+ connectionId: text("connection_id").notNull(),
847
+ actionId: text("action_id").notNull(),
848
+ /** read, write, destructive, send. */
849
+ kind: text("kind").notNull(),
850
+ /** The input's field names and sizes, one clipped value that is no secret, a hash of the whole. */
851
+ inputSummary: text("input_summary").notNull(),
852
+ /** allow, ask, deny. */
853
+ outcome: text("outcome").notNull(),
854
+ /** Which rule decided (broker/call.ts `decide`): `grant`, `audience`, `rules.write`, `policy`, …; null where none did. */
855
+ rule: text("rule"),
856
+ reason: text("reason"),
857
+ /** ok, declined, nobody, not_connected, or the error's class. */
858
+ result: text("result"),
859
+ resultSize: integer("result_size"),
860
+ critical: integer("critical", { mode: "boolean" }).notNull().default(false),
861
+ /** Which of the critical kinds (broker/log.ts `CriticalKind`); null where the row is not critical. */
862
+ criticalKind: text("critical_kind"),
863
+ }, (t) => [
864
+ index("broker_log_connection").on(t.connectionId, t.at),
865
+ index("broker_log_space").on(t.spaceId, t.at),
866
+ index("broker_log_critical").on(t.spaceId, t.critical, t.at),
867
+ index("broker_log_run").on(t.runId),
868
+ index("broker_log_wizard").on(t.wizardId, t.kind, t.at),
869
+ ]);
870
+ /**
871
+ * When a person of the tenant was last in the app, and when they last opened Work's bell. The
872
+ * hourly mail of the broker's critical lines goes out only where no admin was in the app since
873
+ * the last one (broker/notify.ts); the bell's count is what came in since the bell was opened.
874
+ */
875
+ export const personSeen = sqliteTable("person_seen", {
876
+ userId: text("user_id").primaryKey(),
877
+ seenAt: integer("seen_at", { mode: "timestamp_ms" }).notNull(),
878
+ bellSeenAt: integer("bell_seen_at", { mode: "timestamp_ms" }),
879
+ });
657
880
  // --- The two-way sync -----------------------------------------------------------
658
881
  // A space that syncs with the organization in the cloud (docs/plans/tenant-sync.md). Triggers
659
882
  // on the synced tables note every write in `sync_change` (see the migration); the cloud numbers
@@ -661,13 +884,13 @@ export const pluginConnection = sqliteTable("plugin_connection", {
661
884
  /** One change of an item: which space, which kind of item, which one. */
662
885
  export const syncChange = sqliteTable("sync_change", {
663
886
  seq: integer("seq").primaryKey({ autoIncrement: true }),
664
- projectId: text("project_id").notNull(),
887
+ spaceId: text("space_id").notNull(),
665
888
  kind: text("kind").notNull(),
666
889
  item: text("item").notNull(),
667
890
  at: integer("at", { mode: "timestamp_ms" }).notNull().default(now),
668
891
  }, (t) => [
669
892
  index("sync_change_item").on(t.kind, t.item),
670
- index("sync_change_project").on(t.projectId, t.seq),
893
+ index("sync_change_space").on(t.spaceId, t.seq),
671
894
  ]);
672
895
  /**
673
896
  * Live changes (docs/plans/live-changes.md): triggers (`db/live-triggers.ts`) number every write
@@ -675,7 +898,7 @@ export const syncChange = sqliteTable("sync_change", {
675
898
  */
676
899
  export const liveChange = sqliteTable("live_change", {
677
900
  seq: integer("seq").primaryKey({ autoIncrement: true }),
678
- projectId: text("project_id"),
901
+ spaceId: text("space_id"),
679
902
  kind: text("kind").notNull(),
680
903
  /** `put` or `del`. */
681
904
  op: text("op").notNull(),
@@ -722,14 +945,14 @@ export const syncGuard = sqliteTable("sync_guard", {
722
945
  export const syncBase = sqliteTable("sync_base", {
723
946
  kind: text("kind").notNull(),
724
947
  item: text("item").notNull(),
725
- projectId: text("project_id").notNull(),
948
+ spaceId: text("space_id").notNull(),
726
949
  seq: integer("seq").notNull(),
727
950
  record: text("record", { mode: "json" }).$type(),
728
- }, (t) => [primaryKey({ columns: [t.kind, t.item] }), index("sync_base_project").on(t.projectId)]);
951
+ }, (t) => [primaryKey({ columns: [t.kind, t.item] }), index("sync_base_space").on(t.spaceId)]);
729
952
  /** An item both sides changed, where the merge was not clean: it waits for the person. */
730
953
  export const syncConflict = sqliteTable("sync_conflict", {
731
954
  id: text("id").primaryKey(),
732
- projectId: text("project_id").notNull(),
955
+ spaceId: text("space_id").notNull(),
733
956
  kind: text("kind").notNull(),
734
957
  item: text("item").notNull(),
735
958
  /** The cloud's number of its version. */
@@ -742,7 +965,7 @@ export const syncConflict = sqliteTable("sync_conflict", {
742
965
  /** A merge the sync made by itself: the notice on the item, and what undoes it. */
743
966
  export const syncMerge = sqliteTable("sync_merge", {
744
967
  id: text("id").primaryKey(),
745
- projectId: text("project_id").notNull(),
968
+ spaceId: text("space_id").notNull(),
746
969
  kind: text("kind").notNull(),
747
970
  item: text("item").notNull(),
748
971
  /** Labels of the places each side changed. */