@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,165 @@
1
+ import { featureOn } from "@engenty/wizards-shared/features";
2
+ import { note } from "@engenty/wizards-shared/run";
3
+ import { and, eq } from "drizzle-orm";
4
+ import { db, schema } from "../db/client.js";
5
+ import { currentFeatures } from "../features.js";
6
+ import { managed } from "../manage.js";
7
+ import { currentTenant } from "../tenants/tenant.js";
8
+ import { currentRole, isAdminRole, requireAdmin } from "./access.js";
9
+ import { ServiceError } from "./errors.js";
10
+ /**
11
+ * Members in the Studio, one rule per space (docs/plans/capabilities.md, "Who sees the place"):
12
+ * „Mitglieder dürfen ins Studio“. Behind the `capabilities` switch; while it is off, a member
13
+ * reaches every space's studio API as before and edits what is there.
14
+ *
15
+ * With the switch on, a member of an organization reaches a space's studio API only where its
16
+ * admins opened the Studio to members. There they build and test wizards and add and change
17
+ * skills, knowledge and data. They publish nothing and share nothing outside the space, and they
18
+ * set up no connection and change no rule: those stay with the admins (their own guards). Work
19
+ * keeps what it reads in every space: the space's wizards to start, its files, its connectors and
20
+ * connections.
21
+ */
22
+ const CLOSED = () => new ServiceError("forbidden", note("studioClosedToMembers"));
23
+ const PUBLISH = () => new ServiceError("forbidden", note("onlyAdminsPublish"));
24
+ /** Whether the rule counts here: an organization's member, with `capabilities` on. */
25
+ async function ruledMember() {
26
+ return (managed && !isAdminRole(currentRole()) && featureOn(await currentFeatures(), "capabilities"));
27
+ }
28
+ /** Whether the person at hand builds in this space's Studio: always, but for a member by the rule. */
29
+ export async function studioOpen(space) {
30
+ return space.membersStudio || !(await ruledMember());
31
+ }
32
+ /**
33
+ * Making a wizard in a space: the admins', and with the switch on also the members' where the
34
+ * Studio is open to them.
35
+ */
36
+ export async function requireMaker(space) {
37
+ if (!(await ruledMember())) {
38
+ return requireAdmin();
39
+ }
40
+ if (!(await openToMembers(await space()))) {
41
+ throw CLOSED();
42
+ }
43
+ }
44
+ async function openToMembers(spaceId) {
45
+ const space = await db.query.space.findFirst({
46
+ where: and(eq(schema.space.id, spaceId), eq(schema.space.tenantId, currentTenant())),
47
+ columns: { membersStudio: true },
48
+ });
49
+ // A space that is not there is the route's "not found", not ours.
50
+ return space?.membersStudio ?? true;
51
+ }
52
+ /** What Work reads in any space of the organization, whatever the rule says. */
53
+ const WORK_READS = /^\/spaces\/[^/]+\/(wizards|files(\/[^/]+\/(content|text))?|connectors|connections)$/;
54
+ /** Publishing and sharing outside the space: the admins' alone. */
55
+ const PUBLISHING = [
56
+ ["POST", /^\/wizards\/[^/]+\/(publish|rotate-link|cloud)$/],
57
+ // Its settings: the link on or off, its limits, its channels, its translation, its space.
58
+ ["PATCH", /^\/wizards\/[^/]+$/],
59
+ ["PUT", /^\/wizards\/[^/]+\/translations\/[^/]+$/],
60
+ ["DELETE", /^\/wizards\/[^/]+\/translations\/[^/]+$/],
61
+ ];
62
+ /**
63
+ * The space of an item, by the kind and id the studio's addresses name it with
64
+ * (`/spaces/:id`, `/wizards/:id`, …; `runs` for a run's wizard), and what follows them.
65
+ */
66
+ async function spaceOfItem(kind, id, sub) {
67
+ const one = async (found) => (await found)?.spaceId ?? null;
68
+ const tenant = currentTenant();
69
+ switch (kind) {
70
+ case "spaces":
71
+ return id;
72
+ case "wizards":
73
+ return one(db.query.wizard.findFirst({
74
+ where: and(eq(schema.wizard.id, id), eq(schema.wizard.tenantId, tenant)),
75
+ columns: { spaceId: true },
76
+ }));
77
+ case "runs": {
78
+ const run = await db.query.run.findFirst({
79
+ where: and(eq(schema.run.id, id), eq(schema.run.tenantId, tenant)),
80
+ columns: { wizardId: true },
81
+ });
82
+ return run ? spaceOfItem("wizards", run.wizardId) : null;
83
+ }
84
+ case "tables":
85
+ return one(db.query.spaceTable.findFirst({
86
+ where: eq(schema.spaceTable.id, id),
87
+ columns: { spaceId: true },
88
+ }));
89
+ case "pages":
90
+ return one(db.query.spacePage.findFirst({
91
+ where: eq(schema.spacePage.id, id),
92
+ columns: { spaceId: true },
93
+ }));
94
+ case "categories":
95
+ return one(db.query.spaceCategory.findFirst({
96
+ where: eq(schema.spaceCategory.id, id),
97
+ columns: { spaceId: true },
98
+ }));
99
+ case "values": {
100
+ const value = await db.query.spaceCategoryValue.findFirst({
101
+ where: eq(schema.spaceCategoryValue.id, id),
102
+ columns: { categoryId: true },
103
+ });
104
+ return value ? spaceOfItem("categories", value.categoryId) : null;
105
+ }
106
+ case "skills":
107
+ return one(db.query.spaceSkill.findFirst({
108
+ where: eq(schema.spaceSkill.id, id),
109
+ columns: { spaceId: true },
110
+ }));
111
+ case "connections":
112
+ // A person's own sign-in is theirs, in their menu.
113
+ return sub === "my-sign-in"
114
+ ? null
115
+ : one(db.query.spaceConnection.findFirst({
116
+ where: eq(schema.spaceConnection.id, id),
117
+ columns: { spaceId: true },
118
+ }));
119
+ default:
120
+ return null;
121
+ }
122
+ }
123
+ /**
124
+ * Whether this space's Studio is closed to the person at hand: a member, where its admins did not
125
+ * open it. What a list leaves out for them.
126
+ */
127
+ export async function closedToMe(spaceId) {
128
+ return (await ruledMember()) && !(await openToMembers(spaceId));
129
+ }
130
+ /**
131
+ * The studio's „closed“ answer for an item of a space closed to the person at hand: the same 403
132
+ * through every door (the studio API, MCP, `/api/v1`, Goose). `kind` as the studio's addresses
133
+ * name it: `spaces`, `wizards`, `runs`, `tables`, `pages`, `skills`, `connections`, ….
134
+ */
135
+ export async function requireStudio(kind, id, sub) {
136
+ if (!(await ruledMember())) {
137
+ return;
138
+ }
139
+ const spaceId = await spaceOfItem(kind, id, sub);
140
+ if (spaceId && !(await openToMembers(spaceId))) {
141
+ throw CLOSED();
142
+ }
143
+ }
144
+ /**
145
+ * The studio API for a member, after the guard in app.ts set who they are: refuses a space whose
146
+ * Studio is closed to members, and publishing anywhere. Admins and owners pass untouched.
147
+ */
148
+ export async function membersStudioGate(c, next) {
149
+ if (!(await ruledMember())) {
150
+ return next();
151
+ }
152
+ const method = c.req.method;
153
+ const path = c.req.path.slice(c.req.path.indexOf("/api/studio") + "/api/studio".length);
154
+ if (PUBLISHING.some(([m, re]) => m === method && re.test(path))) {
155
+ throw PUBLISH();
156
+ }
157
+ if (method === "GET" && WORK_READS.test(path)) {
158
+ return next();
159
+ }
160
+ const [, kind = "", id, sub] = path.split("/");
161
+ if (id) {
162
+ await requireStudio(kind, id, sub);
163
+ }
164
+ return next();
165
+ }
@@ -1,6 +1,6 @@
1
1
  import { ADDRESS_NAMES, addressKind, addressUrl } from "@engenty/wizards-shared/addresses";
2
- import { factKey, PROJECT_LIMITS, } from "@engenty/wizards-shared/projects";
3
2
  import { matchSectors } from "@engenty/wizards-shared/sectors";
3
+ import { factKey, SPACE_LIMITS, } from "@engenty/wizards-shared/spaces";
4
4
  import { nanoid } from "nanoid";
5
5
  import { readCompany } from "../agents/company.js";
6
6
  import { readContact, readWebsite } from "../agents/website.js";
@@ -8,8 +8,8 @@ import { managed } from "../manage.js";
8
8
  import { readSetting, writeSetting } from "../settings.js";
9
9
  import { serverText } from "../texts.js";
10
10
  import { isAdminRole } from "./access.js";
11
- import { addProjectFileFromUrl, projectFiles } from "./project-files.js";
12
- import { listProjects, ownedProject, updateProject } from "./projects.js";
11
+ import { addSpaceFileFromUrl, spaceFiles } from "./space-files.js";
12
+ import { listSpaces, ownedSpace, updateSpace } from "./spaces.js";
13
13
  const organizationKey = (tenantId) => `onboarding:${tenantId}`;
14
14
  const personKey = (userId) => `onboarding:person:${userId}`;
15
15
  const visitKey = (tenantId, userId) => `onboarding:visit:${tenantId}:${userId}`;
@@ -18,8 +18,8 @@ async function setUp(user) {
18
18
  if (await readSetting(organizationKey(user.tenantId))) {
19
19
  return true;
20
20
  }
21
- const projects = await listProjects(user.id);
22
- return projects.some((p) => p.wizardCount > 0);
21
+ const spaces = await listSpaces(user.id);
22
+ return spaces.some((p) => p.wizardCount > 0);
23
23
  }
24
24
  /**
25
25
  * The person went through the studio's first visit before: their own mark, or, from before
@@ -276,7 +276,7 @@ export function withFacts(facts, found, lang, more = []) {
276
276
  // Beyond the basics, a value the space has under another label is not added twice.
277
277
  (i >= FACTS.length && next.some((f) => sameValue(f.value, value))) ||
278
278
  (at >= 0 && next[at].value.trim()) ||
279
- (at < 0 && next.length >= PROJECT_LIMITS.facts)) {
279
+ (at < 0 && next.length >= SPACE_LIMITS.facts)) {
280
280
  continue;
281
281
  }
282
282
  if (at >= 0) {
@@ -305,7 +305,7 @@ const ASSETS = 4;
305
305
  * completes name, about, facts and fonts; without a model or credits the patterns' reading
306
306
  * stands.
307
307
  */
308
- export async function applyWebsite(userId, projectId, url, lang) {
308
+ export async function applyWebsite(userId, spaceId, url, lang) {
309
309
  const signal = AbortSignal.timeout(30_000);
310
310
  const reading = await readWebsite(url, signal, { inline: true });
311
311
  const colors = brandColors(reading.brand);
@@ -336,15 +336,15 @@ export async function applyWebsite(userId, projectId, url, lang) {
336
336
  const name = read?.name ?? found.name;
337
337
  const about = read?.about ?? found.about;
338
338
  const company = read?.company ?? contact.company;
339
- const project = await ownedProject(userId, projectId);
340
- const fonts = project.brand.fonts?.length ? [] : read?.fonts.length ? read.fonts : found.fonts;
341
- const facts = withFacts(project.facts, {
339
+ const space = await ownedSpace(userId, spaceId);
340
+ const fonts = space.brand.fonts?.length ? [] : read?.fonts.length ? read.fonts : found.fonts;
341
+ const facts = withFacts(space.facts, {
342
342
  ...contact,
343
343
  // The full name only where it says more than the name the space goes by.
344
344
  company: company?.toLowerCase() === name.toLowerCase() ? undefined : company,
345
345
  website,
346
346
  }, lang, read?.facts);
347
- await updateProject(userId, projectId, {
347
+ await updateSpace(userId, spaceId, {
348
348
  brand: {
349
349
  name,
350
350
  ...(about ? { about } : {}),
@@ -357,13 +357,13 @@ export async function applyWebsite(userId, projectId, url, lang) {
357
357
  const [logo, assets] = await Promise.all([
358
358
  (async () => {
359
359
  const first = reading.brand.logos[0];
360
- if (!first || (await projectFiles(projectId, "logo")).length > 0) {
360
+ if (!first || (await spaceFiles(spaceId, "logo")).length > 0) {
361
361
  return false;
362
362
  }
363
- return keep(projectId, first.url, "logo", first.hint);
363
+ return keep(spaceId, first.url, "logo", first.hint);
364
364
  })(),
365
365
  (async () => {
366
- if ((await projectFiles(projectId, "asset")).length > 0) {
366
+ if ((await spaceFiles(spaceId, "asset")).length > 0) {
367
367
  return 0;
368
368
  }
369
369
  const pictures = reading.brand.images.filter((i) => i.hero).slice(0, ASSETS);
@@ -374,7 +374,7 @@ export async function applyWebsite(userId, projectId, url, lang) {
374
374
  const description = picture.alt.startsWith("share image")
375
375
  ? `share image of ${host}`
376
376
  : picture.alt || `picture on the home page of ${host}`;
377
- kept += Number(await keep(projectId, picture.url, "asset", description, until));
377
+ kept += Number(await keep(spaceId, picture.url, "asset", description, until));
378
378
  }
379
379
  return kept;
380
380
  })(),
@@ -395,13 +395,13 @@ export async function applyWebsite(userId, projectId, url, lang) {
395
395
  * `applyWebsite` does, every other address (profiles, a blog, a second site) as a fact under its
396
396
  * name. Null where none of them is a website.
397
397
  */
398
- export async function applyAddresses(userId, projectId, raw, lang) {
398
+ export async function applyAddresses(userId, spaceId, raw, lang) {
399
399
  const urls = [...new Set(raw.flatMap((r) => addressUrl(r) ?? []))].slice(0, 10);
400
400
  const site = urls.find((u) => addressKind(u) === "website");
401
- const outcome = site ? await applyWebsite(userId, projectId, site, lang) : null;
401
+ const outcome = site ? await applyWebsite(userId, spaceId, site, lang) : null;
402
402
  const rest = urls.filter((u) => u !== site);
403
403
  if (rest.length) {
404
- const project = await ownedProject(userId, projectId);
404
+ const space = await ownedSpace(userId, spaceId);
405
405
  const named = rest.map((url) => {
406
406
  const kind = addressKind(url);
407
407
  const count = rest.filter((u) => addressKind(u) === kind).indexOf(url);
@@ -410,9 +410,9 @@ export async function applyAddresses(userId, projectId, raw, lang) {
410
410
  value: url,
411
411
  };
412
412
  });
413
- const facts = withFacts(project.facts, {}, lang, named);
413
+ const facts = withFacts(space.facts, {}, lang, named);
414
414
  if (facts.added) {
415
- await updateProject(userId, projectId, { facts: facts.facts });
415
+ await updateSpace(userId, spaceId, { facts: facts.facts });
416
416
  }
417
417
  if (outcome) {
418
418
  outcome.facts += facts.added;
@@ -421,9 +421,9 @@ export async function applyAddresses(userId, projectId, raw, lang) {
421
421
  return outcome;
422
422
  }
423
423
  /** A picture of the site kept in the space; one that cannot be fetched is no loss. */
424
- async function keep(projectId, url, kind, description, signal = AbortSignal.timeout(15_000)) {
424
+ async function keep(spaceId, url, kind, description, signal = AbortSignal.timeout(15_000)) {
425
425
  try {
426
- await addProjectFileFromUrl(projectId, { url, kind, description, signal });
426
+ await addSpaceFileFromUrl(spaceId, { url, kind, description, signal });
427
427
  return true;
428
428
  }
429
429
  catch {
@@ -4,7 +4,7 @@ import { cleanPath, WORKSPACE_LIMITS } from "@engenty/wizards-shared/workspace";
4
4
  import { strFromU8, unzipSync } from "fflate";
5
5
  import { ServiceError } from "./errors.js";
6
6
  /**
7
- * Reading a `.wizard` package, with nothing of a project or a database: the studio's import and
7
+ * Reading a `.wizard` package, with nothing of a space or a database: the studio's import and
8
8
  * `wizards validate` both start here.
9
9
  */
10
10
  const invalid = (said) => new ServiceError("invalid", said);
@@ -5,17 +5,17 @@ import { listConnectors } from "../connectors/external.js";
5
5
  import { db, schema } from "../db/client.js";
6
6
  import { getBlob } from "../files/blobs.js";
7
7
  import { serverText } from "../texts.js";
8
- import { requireAdmin } from "./access.js";
9
8
  import { draftFiles, writeFile } from "./files.js";
10
9
  import { pageTree } from "./knowledge.js";
10
+ import { requireMaker } from "./members-studio.js";
11
11
  import { readPackage } from "./package-file.js";
12
- import { ownedProject } from "./projects.js";
12
+ import { ownedSpace } from "./spaces.js";
13
13
  import { importThemes, themesOf } from "./themes.js";
14
14
  import { createWizard, deleteWizard, draftIssues, ownedWizard, parseDraft } from "./wizards.js";
15
15
  /** A wizard as a file — the format is `@engenty/wizards-shared/wizard-package`'s. */
16
- /** Where the project's pages go in a package, as Markdown the standalone runner reads inline. */
16
+ /** Where the space's pages go in a package, as Markdown the standalone runner reads inline. */
17
17
  export const KNOWLEDGE_DIR = "knowledge/";
18
- /** How much of the project's knowledge a package takes along: enough pages, never the whole space. */
18
+ /** How much of the space's knowledge a package takes along: enough pages, never the whole space. */
19
19
  export const KNOWLEDGE_MAX_CHARS = 2_000_000;
20
20
  /** What one page may hold in the package (the plugin hands a file to the model up to there). */
21
21
  export const KNOWLEDGE_PAGE_CHARS = 60_000;
@@ -44,7 +44,7 @@ export async function exportWizard(userId, wizardId, options = {}) {
44
44
  return null;
45
45
  }
46
46
  const definition = live ? live.definition : w.draft;
47
- const project = await ownedProject(userId, w.projectId);
47
+ const space = await ownedSpace(userId, w.spaceId);
48
48
  const named = new Set((definition.connections ?? []).map((c) => c.connector));
49
49
  const manifest = {
50
50
  $schema: PACKAGE_SCHEMA_URL,
@@ -52,7 +52,7 @@ export async function exportWizard(userId, wizardId, options = {}) {
52
52
  version: 1,
53
53
  exportedAt: new Date().toISOString(),
54
54
  definition,
55
- connectors: (await listConnectors(project.id))
55
+ connectors: (await listConnectors(space.id))
56
56
  .filter((c) => c.sourceKind !== "builtin" && named.has(c.id))
57
57
  .map((c) => ({
58
58
  id: c.id,
@@ -60,14 +60,14 @@ export async function exportWizard(userId, wizardId, options = {}) {
60
60
  domain: c.domain,
61
61
  sourceKind: c.sourceKind,
62
62
  })),
63
- themes: themesOf(definition.themes, project.themes),
63
+ themes: themesOf(definition.themes, space.themes),
64
64
  };
65
65
  const entries = {};
66
66
  for (const f of live ? live.files : await draftFiles(w.id)) {
67
67
  entries[PACKAGE_FILES + f.path] = new Uint8Array(await getBlob(f.hash));
68
68
  }
69
69
  if (options.knowledge) {
70
- const snapshot = await knowledgeSnapshot(project.id);
70
+ const snapshot = await knowledgeSnapshot(space.id);
71
71
  manifest.knowledge = { pages: snapshot.pages.length, truncated: snapshot.truncated };
72
72
  for (const page of snapshot.pages) {
73
73
  entries[PACKAGE_FILES + KNOWLEDGE_DIR + page.path] = strToU8(page.text);
@@ -77,15 +77,15 @@ export async function exportWizard(userId, wizardId, options = {}) {
77
77
  return { name: fileName(definition.title), zip: zipSync(entries, { level: 6 }) };
78
78
  }
79
79
  /**
80
- * The project's pages as Markdown files, one per page at its path (`pages/<a>/<b>` becomes
80
+ * The space's pages as Markdown files, one per page at its path (`pages/<a>/<b>` becomes
81
81
  * `a/b.md`), each with its title in front: what a wizard that ran with `pages` reads inline on
82
82
  * a site without the space. Opt-in, and capped: a page is cut at its own limit, and the pages
83
83
  * stop where the whole would pass the snapshot's; `truncated` says so.
84
84
  */
85
- export async function knowledgeSnapshot(projectId) {
86
- const tree = await pageTree(projectId);
85
+ export async function knowledgeSnapshot(spaceId) {
86
+ const tree = await pageTree(spaceId);
87
87
  const rows = await db.query.spacePage.findMany({
88
- where: and(eq(schema.spacePage.projectId, projectId), isNull(schema.spacePage.wizardId)),
88
+ where: and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId)),
89
89
  columns: { id: true, markdown: true },
90
90
  });
91
91
  const markdown = new Map(rows.map((r) => [r.id, r.markdown]));
@@ -114,10 +114,10 @@ export async function knowledgeSnapshot(projectId) {
114
114
  function yamlValue(s) {
115
115
  return JSON.stringify(s);
116
116
  }
117
- /** What the wizard names that the project does not have, in words for the chat. */
118
- async function missing(userId, projectId, draft, manifest) {
119
- const project = await ownedProject(userId, projectId);
120
- const connectors = await listConnectors(project.id);
117
+ /** What the wizard names that the space does not have, in words for the chat. */
118
+ async function missing(userId, spaceId, draft, manifest) {
119
+ const space = await ownedSpace(userId, spaceId);
120
+ const connectors = await listConnectors(space.id);
121
121
  const wanted = [...new Set((draft.connections ?? []).flatMap((c) => c.connector ?? []))];
122
122
  return [
123
123
  ...wanted
@@ -128,17 +128,17 @@ async function missing(userId, projectId, draft, manifest) {
128
128
  }),
129
129
  ];
130
130
  }
131
- /** Makes a new wizard of a package in the project: the draft and its workspace, not published. */
132
- export async function importWizard(userId, projectId, data, name,
131
+ /** Makes a new wizard of a package in the space: the draft and its workspace, not published. */
132
+ export async function importWizard(userId, spaceId, data, name,
133
133
  /** The language the admin reads the import's note in. */
134
134
  lang = "en") {
135
- await requireAdmin();
135
+ await requireMaker(async () => spaceId);
136
136
  const { manifest, files } = readPackage(data);
137
137
  // The shape is checked before anything is written; a wrong one leaves no wizard behind.
138
138
  const { draft } = parseDraft(manifest.definition, files.map((f) => f.path));
139
- const lacks = await missing(userId, projectId, draft, manifest);
139
+ const lacks = await missing(userId, spaceId, draft, manifest);
140
140
  // The wizard's looks come into the space; one whose id is taken by another look is renamed.
141
- const renamed = await importThemes(projectId, manifest.themes);
141
+ const renamed = await importThemes(spaceId, manifest.themes);
142
142
  if (draft.themes) {
143
143
  draft.themes = draft.themes.map((id) => renamed[id] ?? id);
144
144
  }
@@ -153,7 +153,7 @@ lang = "en") {
153
153
  ]
154
154
  .filter(Boolean)
155
155
  .join("\n\n");
156
- const { id } = await createWizard(userId, { projectId, definition: draft, note });
156
+ const { id } = await createWizard(userId, { spaceId, definition: draft, note });
157
157
  try {
158
158
  for (const file of files) {
159
159
  await writeFile(userId, id, file.path, file.data);
@@ -1,7 +1,7 @@
1
1
  import { langOf, wizardLang, } from "@engenty/wizards-shared/definition";
2
2
  import { effortOf } from "@engenty/wizards-shared/marketplace";
3
3
  import { resultsOf } from "@engenty/wizards-shared/marketplace-entry";
4
- import { factType, pageSlugOf, runTheme, } from "@engenty/wizards-shared/projects";
4
+ import { factType, pageSlugOf, runTheme, } from "@engenty/wizards-shared/spaces";
5
5
  import { and, eq, inArray } from "drizzle-orm";
6
6
  import { db, schema } from "../db/client.js";
7
7
  import { env } from "../env.js";
@@ -125,9 +125,9 @@ export async function pageOrganization() {
125
125
  }
126
126
  const tenantId = currentTenant();
127
127
  const organization = await tenantInfo(tenantId);
128
- // Only one space of an organization has its page on (services/projects.ts).
129
- const spaces = await db.query.project.findMany({
130
- where: eq(schema.project.tenantId, tenantId),
128
+ // Only one space of an organization has its page on (services/spaces.ts).
129
+ const spaces = await db.query.space.findMany({
130
+ where: eq(schema.space.tenantId, tenantId),
131
131
  });
132
132
  // Behind its switch the organization has no page: what Manage holds is sent as none.
133
133
  const space = feature("pages", organization.features)
@@ -141,7 +141,7 @@ export async function pageOrganization() {
141
141
  }
142
142
  const listed = page.wizards.length
143
143
  ? await db.query.wizard.findMany({
144
- where: and(eq(schema.wizard.projectId, space.id), inArray(schema.wizard.id, page.wizards), eq(schema.wizard.shareEnabled, true)),
144
+ where: and(eq(schema.wizard.spaceId, space.id), inArray(schema.wizard.id, page.wizards), eq(schema.wizard.shareEnabled, true)),
145
145
  })
146
146
  : [];
147
147
  // Addresses made before hold; a wizard new to the page gets one that is free among them.
@@ -195,9 +195,9 @@ export async function pageOrganization() {
195
195
  }
196
196
  if (Object.keys(made).length) {
197
197
  await db
198
- .update(schema.project)
198
+ .update(schema.space)
199
199
  .set({ page: { ...page, slugs: { ...kept, ...made } } })
200
- .where(eq(schema.project.id, space.id));
200
+ .where(eq(schema.space.id, space.id));
201
201
  }
202
202
  if (!wizards.length) {
203
203
  return { ...base, space: null };
@@ -470,6 +470,7 @@ export async function draftStepView(userId, wizardId, stepId, lang) {
470
470
  wizardId: w.id,
471
471
  tenantId: w.tenantId,
472
472
  files: [],
473
+ grant: null,
473
474
  version: null,
474
475
  mode: "test",
475
476
  runner: null,
@@ -497,7 +498,7 @@ export async function draftStepView(userId, wizardId, stepId, lang) {
497
498
  answer: null,
498
499
  shareToken: null,
499
500
  };
500
- const view = await runView(run, await brandView(w.projectId, def.themes));
501
+ const view = await runView(run, await brandView(w.spaceId, def.themes));
501
502
  // What the latest run said while it worked, and when, is its own: nothing works here.
502
503
  return { ...view, events: [] };
503
504
  }
@@ -532,7 +533,7 @@ export async function listRuns(userId, wizardId) {
532
533
  * The results of a space: its wizards' runs that reached their result, newest first, narrowed by
533
534
  * `filter`; and each wizard with how many it has and when its last one came, the latest first.
534
535
  */
535
- export async function listResults(projectId, filter = {}) {
536
+ export async function listResults(spaceId, filter = {}) {
536
537
  const wizards = await db
537
538
  .select({
538
539
  id: schema.wizard.id,
@@ -542,7 +543,7 @@ export async function listResults(projectId, filter = {}) {
542
543
  })
543
544
  .from(schema.wizard)
544
545
  .leftJoin(schema.run, and(eq(schema.run.wizardId, schema.wizard.id), eq(schema.run.status, "done")))
545
- .where(and(eq(schema.wizard.projectId, projectId), eq(schema.wizard.tenantId, currentTenant())))
546
+ .where(and(eq(schema.wizard.spaceId, spaceId), eq(schema.wizard.tenantId, currentTenant())))
546
547
  .groupBy(schema.wizard.id)
547
548
  // Wizards without a result last: SQLite sorts null below every time.
548
549
  .orderBy(desc(max(schema.run.updatedAt)), desc(schema.wizard.updatedAt));
@@ -0,0 +1,55 @@
1
+ import { eq, gt, inArray } from "drizzle-orm";
2
+ import { db, schema } from "../db/client.js";
3
+ /**
4
+ * When a person of the tenant was last in the app, and when they last opened Work's bell
5
+ * (`person_seen`). Every studio request marks the person, once a minute at most; the hourly mail
6
+ * of the broker's critical lines (broker/notify.ts) is skipped while an admin was here, and the
7
+ * bell counts what came in since it was opened (services/broker-bell.ts).
8
+ */
9
+ /** Marked again within this long, a request writes nothing. */
10
+ const AGAIN_MS = 60_000;
11
+ const marked = new Map();
12
+ /** Here, now. */
13
+ export async function markSeen(userId, at = new Date()) {
14
+ const key = `${userId}`;
15
+ const before = marked.get(key) ?? 0;
16
+ if (at.getTime() - before < AGAIN_MS) {
17
+ return;
18
+ }
19
+ marked.set(key, at.getTime());
20
+ await db
21
+ .insert(schema.personSeen)
22
+ .values({ userId, seenAt: at })
23
+ .onConflictDoUpdate({ target: schema.personSeen.userId, set: { seenAt: at } });
24
+ }
25
+ /** The person opened the bell: what is there counts as seen. */
26
+ export async function markBellSeen(userId, at = new Date()) {
27
+ await db
28
+ .insert(schema.personSeen)
29
+ .values({ userId, seenAt: at, bellSeenAt: at })
30
+ .onConflictDoUpdate({
31
+ target: schema.personSeen.userId,
32
+ set: { seenAt: at, bellSeenAt: at },
33
+ });
34
+ }
35
+ /** When the person last opened the bell; null: never. */
36
+ export async function bellSeenAt(userId) {
37
+ const row = await db.query.personSeen.findFirst({
38
+ where: eq(schema.personSeen.userId, userId),
39
+ });
40
+ return row?.bellSeenAt ?? null;
41
+ }
42
+ /** Whether any of these people was in the app after this time. */
43
+ export async function anySeenSince(userIds, since) {
44
+ if (!userIds.length) {
45
+ return false;
46
+ }
47
+ const row = await db.query.personSeen.findFirst({
48
+ where: (t, { and }) => and(inArray(t.userId, userIds), gt(t.seenAt, since)),
49
+ });
50
+ return Boolean(row);
51
+ }
52
+ /** For tests: the throttle forgets. */
53
+ export function forgetSeen() {
54
+ marked.clear();
55
+ }
@@ -1,6 +1,7 @@
1
1
  import { note } from "@engenty/wizards-shared/run";
2
2
  import { and, eq, isNotNull, lt } from "drizzle-orm";
3
3
  import { nanoid } from "nanoid";
4
+ import { keptStepIds } from "../broker/index.js";
4
5
  import { db, schema } from "../db/client.js";
5
6
  import { availableFormats } from "../engine/runner.js";
6
7
  import { env } from "../env.js";
@@ -49,20 +50,24 @@ export async function shareView(run) {
49
50
  const result = def.steps.find((s) => s.id === run.cursor && s.type === "result") ??
50
51
  def.steps.findLast((s) => s.type === "result");
51
52
  const deliverables = result?.type === "result" ? result.deliverables : [];
52
- const shown = await Promise.all(deliverables.flatMap((d) => {
53
+ // A guest's link shows nothing a step made from a connection the space keeps for its members.
54
+ const kept = await keptStepIds(run);
55
+ const shown = [];
56
+ for (const d of deliverables) {
53
57
  const step = def.steps.find((s) => s.id === d.from);
54
58
  const output = run.state.outputs[d.from];
55
- return step && output
56
- ? [
57
- (async () => ({
58
- step,
59
- output,
60
- formats: await availableFormats(step, run, d.formats),
61
- label: d.label ?? null,
62
- }))(),
63
- ]
64
- : [];
65
- }));
59
+ if (!(step && output)) {
60
+ continue;
61
+ }
62
+ shown.push(kept.has(step.id)
63
+ ? { step, output: null, formats: [], label: d.label ?? null, kept: true }
64
+ : {
65
+ step,
66
+ output,
67
+ formats: await availableFormats(step, run, d.formats),
68
+ label: d.label ?? null,
69
+ });
70
+ }
66
71
  const w = await db.query.wizard.findFirst({ where: eq(schema.wizard.id, run.wizardId) });
67
72
  return {
68
73
  token: run.shareToken ?? "",
@@ -74,13 +79,18 @@ export async function shareView(run) {
74
79
  avatar: def.avatar,
75
80
  costume: def.costume,
76
81
  },
77
- brand: await brandView(w?.projectId ?? "", def.themes),
82
+ brand: await brandView(w?.spaceId ?? "", def.themes),
78
83
  shown,
79
84
  createdAt: run.createdAt.toISOString(),
80
85
  expiresAt: run.expiresAt?.toISOString() ?? null,
81
86
  wizardUrl: w?.shareEnabled && w.publishedVersion !== null ? `${env.publicUrl}/w/${w.shareToken}` : null,
82
87
  };
83
88
  }
89
+ /** The steps of a shared run whose files the link may serve: its deliverables, less what stays in the space. */
90
+ export async function sharedStepIds(run) {
91
+ const kept = await keptStepIds(run);
92
+ return new Set(run.definition.steps.flatMap((s) => s.type === "result" ? s.deliverables.map((d) => d.from).filter((id) => !kept.has(id)) : []));
93
+ }
84
94
  /**
85
95
  * The picture link previews (X, LinkedIn, WhatsApp, Slack) show: the first image of the result,
86
96
  * a widget's poster, or a document's first screen. Rendered once and kept.