@engenty/wizards-runtime 0.13.0 → 0.14.1

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 +26 -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/{0027_space_skill.sql → 0030_space_skill.sql} +8 -8
  35. package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
  36. package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
  37. package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
  38. package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
  39. package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
  40. package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
  41. package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
  42. package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
  43. package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
  44. package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
  45. package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
  46. package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
  47. package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
  48. package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
  49. package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
  50. package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
  51. package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
  52. package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
  53. package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
  54. package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
  55. package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
  56. package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
  57. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
  58. package/apps/runtime/dist/db/schema.js +295 -72
  59. package/apps/runtime/dist/docs/dev/architecture.md +215 -0
  60. package/apps/runtime/dist/docs/dev/broker.md +298 -0
  61. package/apps/runtime/dist/docs/dev/index.md +5 -1
  62. package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
  63. package/apps/runtime/dist/docs/dev/meta.json +3 -0
  64. package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
  65. package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
  66. package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
  67. package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
  68. package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
  69. package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
  70. package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
  71. package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
  72. package/apps/runtime/dist/docs/dev/skills.md +16 -9
  73. package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +40 -5
  74. package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
  75. package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
  76. package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
  77. package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
  78. package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
  79. package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
  80. package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
  81. package/apps/runtime/dist/docs/user-guide/index.md +10 -1
  82. package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
  83. package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
  84. package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
  85. package/apps/runtime/dist/docs/user-guide/space.md +5 -4
  86. package/apps/runtime/dist/docs/user-guide/together.md +16 -2
  87. package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
  88. package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
  89. package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
  90. package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
  91. package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
  92. package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
  93. package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
  94. package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
  95. package/apps/runtime/dist/engine/resources.js +43 -12
  96. package/apps/runtime/dist/engine/runner.js +75 -23
  97. package/apps/runtime/dist/engine/steps.js +30 -12
  98. package/apps/runtime/dist/engine/template.js +18 -1
  99. package/apps/runtime/dist/env.js +9 -4
  100. package/apps/runtime/dist/index.js +18 -2
  101. package/apps/runtime/dist/live/feed.js +2 -2
  102. package/apps/runtime/dist/live/origin.js +2 -2
  103. package/apps/runtime/dist/live/views.js +51 -26
  104. package/apps/runtime/dist/manage.js +7 -0
  105. package/apps/runtime/dist/mcp/flow-app.js +1 -1
  106. package/apps/runtime/dist/mcp/tools.js +75 -34
  107. package/apps/runtime/dist/models.js +1 -1
  108. package/apps/runtime/dist/motion-graphics/project.js +8 -8
  109. package/apps/runtime/dist/motion-graphics/tools.js +1 -1
  110. package/apps/runtime/dist/plugins/events.js +2 -2
  111. package/apps/runtime/dist/plugins/jobs.js +4 -1
  112. package/apps/runtime/dist/plugins/loader.js +2 -2
  113. package/apps/runtime/dist/prompts/architect.md +3 -3
  114. package/apps/runtime/dist/prompts/authoring.md +46 -12
  115. package/apps/runtime/dist/prompts/goose.md +7 -7
  116. package/apps/runtime/dist/prompts/mcp.md +6 -6
  117. package/apps/runtime/dist/prompts/services.md +4 -4
  118. package/apps/runtime/dist/prompts/step.md +2 -2
  119. package/apps/runtime/dist/prompts/tools.md +39 -10
  120. package/apps/runtime/dist/routes/api.js +31 -20
  121. package/apps/runtime/dist/routes/broker.js +316 -0
  122. package/apps/runtime/dist/routes/connections.js +71 -0
  123. package/apps/runtime/dist/routes/delivery.js +25 -0
  124. package/apps/runtime/dist/routes/discover.js +17 -0
  125. package/apps/runtime/dist/routes/live.js +11 -1
  126. package/apps/runtime/dist/routes/person.js +4 -1
  127. package/apps/runtime/dist/routes/plugins.js +3 -1
  128. package/apps/runtime/dist/routes/rules.js +26 -0
  129. package/apps/runtime/dist/routes/runs.js +54 -33
  130. package/apps/runtime/dist/routes/skills.js +6 -6
  131. package/apps/runtime/dist/routes/studio.js +153 -144
  132. package/apps/runtime/dist/routes/work.js +199 -0
  133. package/apps/runtime/dist/sandbox/index.js +27 -0
  134. package/apps/runtime/dist/services/access.js +38 -17
  135. package/apps/runtime/dist/services/api.js +38 -13
  136. package/apps/runtime/dist/services/architect.js +3 -3
  137. package/apps/runtime/dist/services/assistant-chats.js +9 -1
  138. package/apps/runtime/dist/services/brand.js +12 -12
  139. package/apps/runtime/dist/services/broker-bell.js +69 -0
  140. package/apps/runtime/dist/services/broker-notify.js +127 -0
  141. package/apps/runtime/dist/services/client-steps.js +79 -0
  142. package/apps/runtime/dist/services/cloud.js +42 -42
  143. package/apps/runtime/dist/services/command-risk.js +51 -0
  144. package/apps/runtime/dist/services/discover.js +85 -0
  145. package/apps/runtime/dist/services/knowledge-model.js +13 -13
  146. package/apps/runtime/dist/services/knowledge.js +117 -80
  147. package/apps/runtime/dist/services/manage-reports.js +74 -7
  148. package/apps/runtime/dist/services/members-studio.js +165 -0
  149. package/apps/runtime/dist/services/onboarding.js +22 -22
  150. package/apps/runtime/dist/services/package-file.js +1 -1
  151. package/apps/runtime/dist/services/package.js +22 -22
  152. package/apps/runtime/dist/services/pages.js +7 -7
  153. package/apps/runtime/dist/services/runs.js +4 -3
  154. package/apps/runtime/dist/services/seen.js +55 -0
  155. package/apps/runtime/dist/services/shares.js +23 -13
  156. package/apps/runtime/dist/services/site.js +23 -23
  157. package/apps/runtime/dist/services/skills-registry.js +15 -15
  158. package/apps/runtime/dist/services/skills.js +44 -44
  159. package/apps/runtime/dist/services/space-categories.js +35 -35
  160. package/apps/runtime/dist/services/space-data.js +130 -111
  161. package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
  162. package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
  163. package/apps/runtime/dist/services/space-origin.js +19 -11
  164. package/apps/runtime/dist/services/spaces.js +478 -612
  165. package/apps/runtime/dist/services/synced-spaces.js +668 -0
  166. package/apps/runtime/dist/services/themes.js +15 -15
  167. package/apps/runtime/dist/services/widgets.js +6 -6
  168. package/apps/runtime/dist/services/wizards.js +112 -38
  169. package/apps/runtime/dist/services/work-ai.js +257 -0
  170. package/apps/runtime/dist/services/work-approvals.js +104 -0
  171. package/apps/runtime/dist/services/work-chats.js +908 -0
  172. package/apps/runtime/dist/services/work-connections.js +90 -0
  173. package/apps/runtime/dist/services/work-files.js +85 -0
  174. package/apps/runtime/dist/services/work-mastra.js +73 -0
  175. package/apps/runtime/dist/services/work-sandbox.js +42 -0
  176. package/apps/runtime/dist/sharing/files.js +14 -4
  177. package/apps/runtime/dist/sharing/index.js +40 -39
  178. package/apps/runtime/dist/sharing/jobs.js +67 -17
  179. package/apps/runtime/dist/sharing/targets/connector.js +10 -6
  180. package/apps/runtime/dist/sharing/targets/email.js +10 -8
  181. package/apps/runtime/dist/sharing/targets/slack.js +10 -8
  182. package/apps/runtime/dist/sharing/targets/storage.js +6 -4
  183. package/apps/runtime/dist/store/index.js +14 -3
  184. package/apps/runtime/dist/store/shared-lists.js +4 -2
  185. package/apps/runtime/dist/sync/apply.js +2 -2
  186. package/apps/runtime/dist/sync/client.js +113 -113
  187. package/apps/runtime/dist/sync/hub.js +41 -41
  188. package/apps/runtime/dist/sync/log.js +12 -12
  189. package/apps/runtime/dist/sync/records.js +118 -120
  190. package/apps/runtime/dist/texts.js +38 -2
  191. package/apps/runtime/dist/tools/connections.js +112 -0
  192. package/apps/runtime/dist/tools/connector.js +157 -67
  193. package/apps/runtime/dist/tools/index.js +28 -13
  194. package/apps/runtime/dist/tools/mail.js +40 -11
  195. package/apps/runtime/dist/tools/pages.js +11 -5
  196. package/apps/runtime/dist/tools/plugin.js +43 -7
  197. package/apps/runtime/dist/tools/skills.js +1 -1
  198. package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
  199. package/apps/runtime/dist/tools/store.js +3 -2
  200. package/apps/runtime/dist/widgets/step.js +10 -10
  201. package/apps/web/dist/assets/AboutDialog-SpDcn8VZ.js +1 -0
  202. package/apps/web/dist/assets/CapabilitiesPage-Bgnm_3dk.js +2 -0
  203. package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-DAnjV6cZ.js} +1 -1
  204. package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
  205. package/apps/web/dist/assets/EditorPage-B98C-9Nv.js +3 -0
  206. package/apps/web/dist/assets/{FlowPreview-DtSpjVTl.js → FlowPreview-aMfwcPul.js} +1 -1
  207. package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
  208. package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
  209. package/apps/web/dist/assets/NewWizardChannels-D8IYLg_S.js +1 -0
  210. package/apps/web/dist/assets/NewWizardPage-DlBt0Mfq.js +7 -0
  211. package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
  212. package/apps/web/dist/assets/PreviewPane-DC1kAi3x.js +9 -0
  213. package/apps/web/dist/assets/PublicRunner-D6lKP0j8.js +1 -0
  214. package/apps/web/dist/assets/ReadOnly-DFsuKPCw.js +1 -0
  215. package/apps/web/dist/assets/SettingsPage-DkHeCO2c.js +2 -0
  216. package/apps/web/dist/assets/SetupPage-DZ8xRkfS.js +1 -0
  217. package/apps/web/dist/assets/SharePage-494ZPsjQ.js +1 -0
  218. package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
  219. package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
  220. package/apps/web/dist/assets/SpacePage-CWlU_BZP.js +2 -0
  221. package/apps/web/dist/assets/UpdateCheck-BKNkNJyG.js +2 -0
  222. package/apps/web/dist/assets/changelog-BhMZS-rs.js +1 -0
  223. package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
  224. package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
  225. package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
  226. package/apps/web/dist/assets/{code-xml-TwKzzMtA.js → code-xml-B4kLFZSj.js} +1 -1
  227. package/apps/web/dist/assets/connection-sign-in-Cngd_QDO.js +1 -0
  228. package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
  229. package/apps/web/dist/assets/{eye-Brd-xPUJ.js → eye-BpoKpIdt.js} +1 -1
  230. package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
  231. package/apps/web/dist/assets/host-C0WQlRKB.js +118 -0
  232. package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
  233. package/apps/web/dist/assets/index-ClVtdDUZ.js +10 -0
  234. package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
  235. package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
  236. package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
  237. package/apps/web/dist/assets/{phone-DhkHteoJ.js → phone-Ctvf-Am-.js} +1 -1
  238. package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
  239. package/apps/web/dist/assets/{runners-G-XYaDgR.js → runners-CyIvJIHr.js} +1 -1
  240. package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
  241. package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
  242. package/apps/web/dist/assets/theme-BCau3f6O.js +11 -0
  243. package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
  244. package/apps/web/dist/assets/{upload-BYZTwJTD.js → upload-BchUnQGV.js} +1 -1
  245. package/apps/web/dist/assets/{useMutation-D0QP_k2-.js → useMutation-DEkZhp5c.js} +1 -1
  246. package/apps/web/dist/assets/{volume-2-CVHoxdGM.js → volume-2-CU_oy81Z.js} +1 -1
  247. package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
  248. package/apps/web/dist/index.html +17 -10
  249. package/apps/web/dist/mcp/flow.html +119 -64
  250. package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
  251. package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +6 -1
  252. package/node_modules/@engenty/wizards-shared/dist/assistant.js +6 -1
  253. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
  254. package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
  255. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +150 -8
  256. package/node_modules/@engenty/wizards-shared/dist/definition.js +46 -11
  257. package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
  258. package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
  259. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +26 -2
  260. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +26 -2
  261. package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
  262. package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
  263. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
  264. package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
  265. package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
  266. package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
  267. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -6
  268. package/node_modules/@engenty/wizards-shared/dist/run.js +85 -0
  269. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
  270. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
  271. package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
  272. package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
  273. package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
  274. package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
  275. package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
  276. package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
  277. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
  278. package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
  279. package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
  280. package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
  281. package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
  282. package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
  283. package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
  284. package/package.json +4 -1
  285. package/plugin/.claude-plugin/plugin.json +1 -1
  286. package/plugin/plugin.json +1 -1
  287. package/plugin/skills/build-wizard/SKILL.md +1 -1
  288. package/apps/runtime/dist/services/projects.js +0 -473
  289. package/apps/web/dist/assets/AboutDialog-B-JxkELB.js +0 -1
  290. package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +0 -3
  291. package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +0 -2
  292. package/apps/web/dist/assets/NewWizardChannels-Tgoexgj4.js +0 -1
  293. package/apps/web/dist/assets/NewWizardPage-B24AF482.js +0 -7
  294. package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +0 -1
  295. package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +0 -10
  296. package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +0 -10
  297. package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +0 -1
  298. package/apps/web/dist/assets/ReadOnly-BXjv-MSv.js +0 -1
  299. package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +0 -2
  300. package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +0 -1
  301. package/apps/web/dist/assets/SharePage-DXGzJSnR.js +0 -1
  302. package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +0 -1
  303. package/apps/web/dist/assets/changelog-BLdS-0Bj.js +0 -1
  304. package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
  305. package/apps/web/dist/assets/i18n-8-Sw11tB.js +0 -55
  306. package/apps/web/dist/assets/index-OsdQFHmh.js +0 -49
  307. package/apps/web/dist/assets/index-QPipX5Fi.css +0 -1
  308. package/apps/web/dist/assets/lock-C0uxcOlq.js +0 -1
  309. package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
  310. package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
  311. package/apps/web/dist/assets/session-BWI-KENJ.js +0 -2
  312. package/apps/web/dist/assets/theme-D7krsx0_.js +0 -11
  313. package/apps/web/dist/assets/ui-DSXG3f49.js +0 -83
@@ -0,0 +1,316 @@
1
+ import { eq, inArray } from "drizzle-orm";
2
+ import { Hono } from "hono";
3
+ import { z } from "zod";
4
+ import { cursorOf, decide, kindOf, LOG_PAGE, logLine, logOfSpace, readCursor, } from "../broker/index.js";
5
+ import { resolveConnector } from "../connectors/external.js";
6
+ import { connectorOfRow, listSpaceConnections, spaceConnectionById, } from "../connectors/space-connections.js";
7
+ import { db, schema } from "../db/client.js";
8
+ import { managed, tenantMembers } from "../manage.js";
9
+ import { isAdminRole, requireAdmin } from "../services/access.js";
10
+ import { notFound } from "../services/errors.js";
11
+ import { userProfile } from "../services/profile.js";
12
+ import { ownedSpace } from "../services/spaces.js";
13
+ import { currentTenant } from "../tenants/tenant.js";
14
+ const WHO = [
15
+ "guest",
16
+ "person",
17
+ "admin",
18
+ "goose",
19
+ "plugin",
20
+ "step",
21
+ ];
22
+ const askSchema = z.object({
23
+ who: z.enum(WHO),
24
+ /** A fixed step: whom the run is held for. Goose: `admin` for an admin's Goose. */
25
+ for: z.enum(["guest", "person", "admin"]).optional(),
26
+ /** A connection of the space, by its id. */
27
+ resource: z.string().min(1).max(80),
28
+ action: z.string().min(1).max(120),
29
+ /** Where the call would be made: in a run (an AI step), in a chat, or outside both (a plugin's job). */
30
+ in: z.enum(["run", "chat", "none"]).default("run"),
31
+ });
32
+ const flag = z
33
+ .enum(["true", "false"])
34
+ .transform((v) => v === "true")
35
+ .optional();
36
+ const logSchema = z.object({
37
+ connection: z.string().min(1).max(200).optional(),
38
+ who: z.enum(WHO).optional(),
39
+ outcome: z.enum(["allow", "ask", "deny"]).optional(),
40
+ /** What came of the call: `ok`, a refusal (`needs_approval`: held for the admins), an error's class. */
41
+ result: z.string().min(1).max(80).optional(),
42
+ /** Refused by a rule or by the person asked. */
43
+ refused: flag,
44
+ critical: flag,
45
+ since: z.coerce.date().optional(),
46
+ until: z.coerce.date().optional(),
47
+ q: z.string().max(200).optional(),
48
+ /** The `next` of the page before. */
49
+ cursor: z.string().max(80).optional(),
50
+ limit: z.coerce.number().int().min(1).max(LOG_PAGE).optional(),
51
+ });
52
+ /** The caller as the question names them. */
53
+ function whoOfAsk(ask) {
54
+ if (ask.who === "step") {
55
+ return { kind: "step", for: { kind: ask.for ?? "guest" } };
56
+ }
57
+ if (ask.who === "goose") {
58
+ return { kind: "goose", admin: ask.for === "admin" };
59
+ }
60
+ return { kind: ask.who };
61
+ }
62
+ /** A row as the Protokoll page reads it. */
63
+ export function logView(row) {
64
+ return {
65
+ id: row.id,
66
+ at: row.at.toISOString(),
67
+ durationMs: row.durationMs,
68
+ who: { kind: row.whoKind, id: row.whoId },
69
+ runId: row.runId,
70
+ stepId: row.stepId,
71
+ chatId: row.chatId,
72
+ wizardId: row.wizardId,
73
+ connectionId: row.connectionId,
74
+ actionId: row.actionId,
75
+ kind: row.kind,
76
+ input: JSON.parse(row.inputSummary),
77
+ outcome: row.outcome,
78
+ rule: row.rule,
79
+ reason: row.reason,
80
+ result: row.result,
81
+ resultSize: row.resultSize,
82
+ critical: row.critical,
83
+ criticalKind: row.criticalKind,
84
+ };
85
+ }
86
+ /** The organization's people by id, with their role; alone, the one person. */
87
+ async function peopleOf(user) {
88
+ if (!managed) {
89
+ return [{ id: user.id, name: (await userProfile(user)).name, role: "owner" }];
90
+ }
91
+ const people = await tenantMembers(currentTenant()).catch(() => null);
92
+ return (people?.members ?? []).map((m) => ({ id: m.userId, name: m.name, role: m.role }));
93
+ }
94
+ /** A connector, looked up once per request. */
95
+ function connectorCache(spaceId) {
96
+ const found = new Map();
97
+ return (id) => {
98
+ let connector = found.get(id);
99
+ if (!connector) {
100
+ connector = resolveConnector(spaceId, id)
101
+ .then((r) => r?.connector ?? null)
102
+ .catch(() => null);
103
+ found.set(id, connector);
104
+ }
105
+ return connector;
106
+ };
107
+ }
108
+ /**
109
+ * The lines with the names the page shows: who by name (a fixed step: whom its run is held for),
110
+ * the connection and the action by theirs, the wizard of a run, the title of a chat.
111
+ */
112
+ async function describeLines(rows, spaceId, people) {
113
+ const named = new Map(people.map((p) => [p.id, p]));
114
+ const connections = new Map((await listSpaceConnections(spaceId)).map((c) => [c.id, c]));
115
+ const connector = connectorCache(spaceId);
116
+ const ids = (pick) => [
117
+ ...new Set(rows.map(pick).filter((id) => !!id)),
118
+ ];
119
+ const runIds = ids((r) => r.runId);
120
+ const wizardIds = ids((r) => r.wizardId);
121
+ const chatIds = ids((r) => r.chatId);
122
+ const [runs, wizards, chats] = await Promise.all([
123
+ runIds.length
124
+ ? db
125
+ .select({
126
+ id: schema.run.id,
127
+ mode: schema.run.mode,
128
+ userId: schema.run.userId,
129
+ })
130
+ .from(schema.run)
131
+ .where(inArray(schema.run.id, runIds))
132
+ : [],
133
+ wizardIds.length
134
+ ? db
135
+ .select({ id: schema.wizard.id, title: schema.wizard.title, draft: schema.wizard.draft })
136
+ .from(schema.wizard)
137
+ .where(inArray(schema.wizard.id, wizardIds))
138
+ : [],
139
+ chatIds.length
140
+ ? db
141
+ .select({ id: schema.chat.id, title: schema.chat.title })
142
+ .from(schema.chat)
143
+ .where(inArray(schema.chat.id, chatIds))
144
+ : [],
145
+ ]);
146
+ const runOf = new Map(runs.map((r) => [r.id, r]));
147
+ const wizardOf = new Map(wizards.map((w) => [w.id, w]));
148
+ const chatOf = new Map(chats.map((c) => [c.id, c]));
149
+ const person = (id) => (id ? (named.get(id)?.name ?? null) : null);
150
+ return Promise.all(rows.map(async (row) => {
151
+ const view = logView(row);
152
+ const run = row.runId ? runOf.get(row.runId) : undefined;
153
+ const wizard = row.wizardId ? wizardOf.get(row.wizardId) : undefined;
154
+ const space = connections.get(row.connectionId);
155
+ const def = wizard?.draft.connections?.find((c) => c.id === row.connectionId);
156
+ const holder = space
157
+ ? await connector(space.connectorId)
158
+ : def?.connector
159
+ ? await connector(def.connector)
160
+ : null;
161
+ const action = holder?.actions.find((a) => a.id === row.actionId);
162
+ // A fixed step: the run is held for a person who signed in, else for a guest.
163
+ const heldFor = row.whoKind === "step" && run
164
+ ? run.userId
165
+ ? {
166
+ kind: isAdminRole(named.get(run.userId)?.role ?? "member") ? "admin" : "person",
167
+ id: run.userId,
168
+ name: person(run.userId),
169
+ }
170
+ : { kind: "guest", id: null, name: null }
171
+ : null;
172
+ return {
173
+ ...view,
174
+ who: {
175
+ ...view.who,
176
+ name: ["person", "admin", "goose"].includes(row.whoKind) ? person(row.whoId) : null,
177
+ ...(heldFor ? { for: heldFor } : {}),
178
+ },
179
+ connectionName: space?.name ?? def?.title ?? null,
180
+ connectorName: holder?.name ?? null,
181
+ actionName: action?.summary ?? null,
182
+ wizardName: wizard?.title ?? null,
183
+ runMode: run?.mode ?? null,
184
+ chatTitle: row.chatId ? (chatOf.get(row.chatId)?.title ?? null) : null,
185
+ };
186
+ }));
187
+ }
188
+ /** The ids whose names hold the search text: people, the space's connections, its wizards. */
189
+ async function matchesOf(q, spaceId, people) {
190
+ const text = q.trim().toLowerCase();
191
+ if (!text) {
192
+ return undefined;
193
+ }
194
+ const has = (name) => !!name && name.toLowerCase().includes(text);
195
+ const wizards = await db
196
+ .select({ id: schema.wizard.id, title: schema.wizard.title })
197
+ .from(schema.wizard)
198
+ .where(eq(schema.wizard.spaceId, spaceId));
199
+ return {
200
+ who: people.filter((p) => has(p.name)).map((p) => p.id),
201
+ connections: (await listSpaceConnections(spaceId)).filter((c) => has(c.name)).map((c) => c.id),
202
+ wizards: wizards.filter((w) => has(w.title)).map((w) => w.id),
203
+ };
204
+ }
205
+ export const brokerRoutes = new Hono()
206
+ .get("/spaces/:id/broker/ask", async (c) => {
207
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
208
+ await requireAdmin();
209
+ const ask = askSchema.parse(c.req.query());
210
+ const row = await spaceConnectionById(ask.resource).catch(() => null);
211
+ if (!row || row.spaceId !== space.id) {
212
+ throw notFound();
213
+ }
214
+ const connector = await connectorOfRow(row);
215
+ const found = connector.actions.find((a) => a.id === ask.action);
216
+ const kind = found ? kindOf(found.group) : "write";
217
+ const connection = { kind: "space_connection", row, connector };
218
+ const who = whoOfAsk(ask);
219
+ const where = {
220
+ spaceId: space.id,
221
+ guest: who.kind === "guest" || (who.kind === "step" && who.for?.kind === "guest"),
222
+ ...(ask.in === "run" ? { runId: "ask", mode: "live" } : {}),
223
+ ...(ask.in === "chat" ? { chatId: "ask" } : {}),
224
+ };
225
+ const decision = decide({ who, where, connection, actionId: ask.action, kind });
226
+ return c.json({
227
+ who,
228
+ connection: { id: row.id, name: row.name, connector: connector.id },
229
+ action: { id: ask.action, kind, known: Boolean(found) },
230
+ outcome: decision.outcome,
231
+ rule: decision.rule,
232
+ reason: decision.reason,
233
+ ...(decision.refused ? { refused: decision.refused } : {}),
234
+ ...(decision.admins ? { admins: true } : {}),
235
+ });
236
+ })
237
+ // What „Was darf …?“ picks from: the organization's people, the space's connections and their actions.
238
+ .get("/spaces/:id/broker/choices", async (c) => {
239
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
240
+ await requireAdmin();
241
+ const connector = connectorCache(space.id);
242
+ const connections = await Promise.all((await listSpaceConnections(space.id)).map(async (row) => {
243
+ const found = await connector(row.connectorId);
244
+ const actions = (found?.actions ?? []).map((a) => ({
245
+ id: a.id,
246
+ name: a.summary || a.id,
247
+ kind: kindOf(a.group),
248
+ }));
249
+ return {
250
+ id: row.id,
251
+ name: row.name,
252
+ connector: found ? { id: found.id, name: found.name } : null,
253
+ audience: row.audience,
254
+ signIn: row.signIn,
255
+ actions,
256
+ };
257
+ }));
258
+ return c.json({ people: await peopleOf(c.get("user")), connections });
259
+ })
260
+ .get("/spaces/:id/broker/log", async (c) => {
261
+ const user = c.get("user");
262
+ const space = await ownedSpace(user.id, c.req.param("id"));
263
+ await requireAdmin();
264
+ const { cursor, q, ...query } = logSchema.parse(c.req.query());
265
+ const before = cursor ? readCursor(cursor) : null;
266
+ const limit = query.limit ?? LOG_PAGE;
267
+ const people = await peopleOf(user);
268
+ const rows = await logOfSpace(space.id, {
269
+ ...query,
270
+ limit,
271
+ ...(before ? { before } : {}),
272
+ ...(q?.trim() ? { q, matches: await matchesOf(q, space.id, people) } : {}),
273
+ });
274
+ const last = rows.at(-1);
275
+ return c.json({
276
+ lines: await describeLines(rows, space.id, people),
277
+ // A full page may have more behind it.
278
+ next: last && rows.length === limit ? cursorOf(last) : null,
279
+ });
280
+ })
281
+ // One line, with what its run was allowed through that connection or to that host.
282
+ .get("/spaces/:id/broker/log/:line", async (c) => {
283
+ const user = c.get("user");
284
+ const space = await ownedSpace(user.id, c.req.param("id"));
285
+ await requireAdmin();
286
+ const row = await logLine(space.id, c.req.param("line"));
287
+ if (!row) {
288
+ throw notFound();
289
+ }
290
+ const [line] = await describeLines([row], space.id, await peopleOf(user));
291
+ const run = row.runId
292
+ ? await db.query.run.findFirst({
293
+ where: (t, { eq }) => eq(t.id, row.runId),
294
+ columns: { id: true, wizardId: true, mode: true, status: true, grant: true },
295
+ })
296
+ : undefined;
297
+ const host = row.connectionId.startsWith("host:") ? row.connectionId.slice(5) : null;
298
+ return c.json({
299
+ line,
300
+ run: run
301
+ ? {
302
+ id: run.id,
303
+ wizardId: run.wizardId,
304
+ mode: run.mode,
305
+ status: run.status,
306
+ // Null: a run from before grants were kept, or one the grant does not bind (a space's connection).
307
+ grant: run.grant
308
+ ? {
309
+ actions: host ? null : (run.grant.connections[row.connectionId] ?? []),
310
+ hosts: run.grant.hosts,
311
+ }
312
+ : null,
313
+ }
314
+ : null,
315
+ });
316
+ });
@@ -0,0 +1,71 @@
1
+ import { Hono } from "hono";
2
+ import { z } from "zod";
3
+ import { inAudience } from "../broker/index.js";
4
+ import { namesOf } from "../connectors/person-sign-ins.js";
5
+ import { connectionPatchSchema, createSpaceConnection, newConnectionSchema, removeSignIn, removeSpaceConnection, signInWithCredentials, spaceConnectionViews, startSpaceConnectionOAuth, updateSpaceConnection, } from "../connectors/space-connections.js";
6
+ import { isAdminRole } from "../services/access.js";
7
+ import { ownedSpace } from "../services/spaces.js";
8
+ import { requestLang } from "./lang.js";
9
+ /** A sign-in: the keys the person typed, or a request for the provider's sign-in page. */
10
+ const signInSchema = z.union([
11
+ z.object({ credentials: z.record(z.string(), z.string().max(500)) }),
12
+ z.object({ oauth: z.literal(true) }),
13
+ ]);
14
+ const asSpace = { as: "space" };
15
+ /** The connections this person sees, with the name of who set each up. */
16
+ async function views(user, spaceId) {
17
+ const admin = isAdminRole(user.role);
18
+ const all = await spaceConnectionViews(spaceId, user.id);
19
+ const shown = admin
20
+ ? all
21
+ : all.filter((v) => inAudience(v.audience, { kind: "person", id: user.id }));
22
+ const names = shown.some((v) => v.setUpBy) ? await namesOf(user) : null;
23
+ return shown.map((v) => ({
24
+ ...v,
25
+ setUpByName: v.setUpBy ? (names?.get(v.setUpBy) ?? null) : null,
26
+ }));
27
+ }
28
+ const asMe = (user) => ({ as: "person", userId: user.id, role: user.role });
29
+ export const connectionRoutes = new Hono()
30
+ .get("/spaces/:id/connections", async (c) => {
31
+ const space = await ownedSpace(c.get("user").id, c.req.param("id"));
32
+ return c.json({ connections: await views(c.get("user"), space.id) });
33
+ })
34
+ .post("/spaces/:id/connections", async (c) => {
35
+ const user = c.get("user");
36
+ const space = await ownedSpace(user.id, c.req.param("id"));
37
+ const row = await createSpaceConnection(user.id, space.id, newConnectionSchema.parse(await c.req.json()));
38
+ const [view] = (await views(user, space.id)).filter((v) => v.id === row.id);
39
+ return c.json(view);
40
+ })
41
+ .patch("/connections/:id", async (c) => {
42
+ const user = c.get("user");
43
+ const row = await updateSpaceConnection(user.id, c.req.param("id"), connectionPatchSchema.parse(await c.req.json()));
44
+ const [view] = (await views(user, row.spaceId)).filter((v) => v.id === row.id);
45
+ return c.json(view);
46
+ })
47
+ .delete("/connections/:id", async (c) => {
48
+ await removeSpaceConnection(c.get("user").id, c.req.param("id"));
49
+ return c.json({ ok: true });
50
+ })
51
+ // As the space: the admins' sign-in, kept on the connection itself.
52
+ .post("/connections/:id/sign-in", async (c) => signIn(c, asSpace))
53
+ .delete("/connections/:id/sign-in", async (c) => {
54
+ await removeSignIn(c.req.param("id"), asSpace);
55
+ return c.json({ ok: true });
56
+ })
57
+ // Each person themselves: this person's own sign-in.
58
+ .post("/connections/:id/my-sign-in", async (c) => signIn(c, asMe(c.get("user"))))
59
+ .delete("/connections/:id/my-sign-in", async (c) => {
60
+ await removeSignIn(c.req.param("id"), asMe(c.get("user")));
61
+ return c.json({ ok: true });
62
+ });
63
+ async function signIn(c, as) {
64
+ const body = signInSchema.parse(await c.req.json());
65
+ if ("oauth" in body) {
66
+ const url = await startSpaceConnectionOAuth(c.req.param("id") ?? "", as, requestLang(c));
67
+ return c.json({ url });
68
+ }
69
+ const { label } = await signInWithCredentials(c.req.param("id") ?? "", as, body.credentials);
70
+ return c.json({ ok: true, label });
71
+ }
@@ -88,3 +88,28 @@ export function byteRange(header, size) {
88
88
  const end = m[1] && m[2] ? Math.min(Number(m[2]), size - 1) : size - 1;
89
89
  return start > end || start >= size ? "unsatisfiable" : { start, end };
90
90
  }
91
+ /**
92
+ * A file of the space as it is opened (the studio's files, a Work chat's): shown, never run, and
93
+ * a clip or recording by the byte range a phone asks for. A PDF is left to the browser's own
94
+ * viewer, which a sandbox would keep from starting.
95
+ */
96
+ export function spaceFileResponse(c, mime, data) {
97
+ const headers = {
98
+ "content-type": bareMime(mime) ?? "application/octet-stream",
99
+ "cache-control": "private, max-age=3600",
100
+ "x-content-type-options": "nosniff",
101
+ ...(mime === "application/pdf" ? {} : { "content-security-policy": "sandbox" }),
102
+ };
103
+ if (/^(audio|video)\//.test(mime)) {
104
+ headers["accept-ranges"] = "bytes";
105
+ const range = byteRange(c.req.header("range"), data.byteLength);
106
+ if (range === "unsatisfiable") {
107
+ return c.body(null, 416, { "content-range": `bytes */${data.byteLength}` });
108
+ }
109
+ if (range) {
110
+ headers["content-range"] = `bytes ${range.start}-${range.end}/${data.byteLength}`;
111
+ return c.body(new Uint8Array(data.subarray(range.start, range.end + 1)), 206, headers);
112
+ }
113
+ }
114
+ return c.body(new Uint8Array(data), 200, headers);
115
+ }
@@ -0,0 +1,17 @@
1
+ import { Hono } from "hono";
2
+ import { z } from "zod";
3
+ import { discover } from "../services/discover.js";
4
+ import { say } from "./lang.js";
5
+ export const discoverRoutes = new Hono().get("/spaces/:id/discover", async (c) => {
6
+ const q = z.string().max(200).catch("").parse(c.req.query("q"));
7
+ const found = await discover(c.get("user").id, c.req.param("id"), q);
8
+ const answer = {
9
+ skills: found.skills,
10
+ connectors: found.connectors,
11
+ errors: {
12
+ ...(found.errors.skills ? { skills: say(c, found.errors.skills) } : {}),
13
+ ...(found.errors.connectors ? { connectors: say(c, found.errors.connectors) } : {}),
14
+ },
15
+ };
16
+ return c.json(answer);
17
+ });
@@ -1,9 +1,11 @@
1
1
  import { Hono } from "hono";
2
2
  import { streamSSE } from "hono/streaming";
3
+ import { subjectsOfPerson } from "../broker/rwx.js";
3
4
  import { feature, remoteFeatures } from "../features.js";
4
5
  import { openStreams, subscribe } from "../live/hub.js";
5
6
  import { itemView } from "../live/views.js";
6
7
  import { asRole } from "../services/access.js";
8
+ import { chatChangesFor } from "../services/work-chats.js";
7
9
  import { requestLang, say } from "./lang.js";
8
10
  /** At most this many streams per person and per tenant in one process. */
9
11
  export const STREAM_LIMITS = { person: 20, tenant: 200 };
@@ -44,6 +46,10 @@ export const liveRoutes = new Hono().get("/", async (c) => {
44
46
  if (!next || closed) {
45
47
  return;
46
48
  }
49
+ // A private chat's changes go to its members only (Work's chats).
50
+ if (next.event === "changes" && next.items.some((i) => i.kind === "chat")) {
51
+ next.items = await chatChangesFor(user, next.items);
52
+ }
47
53
  const { event, ...data } = next;
48
54
  await stream.writeSSE({
49
55
  event,
@@ -52,7 +58,11 @@ export const liveRoutes = new Hono().get("/", async (c) => {
52
58
  });
53
59
  });
54
60
  };
55
- const reader = { userId: user.id, lang: requestLang(c) };
61
+ const reader = {
62
+ userId: user.id,
63
+ lang: requestLang(c),
64
+ who: subjectsOfPerson(user.id, user.role),
65
+ };
56
66
  const unsubscribe = await subscribe(user.tenantId, since, send, {
57
67
  key: `${user.role}|${reader.lang}`,
58
68
  read: (x) => asRole(user.role, () => itemView(reader, x)),
@@ -1,6 +1,7 @@
1
1
  import { Hono } from "hono";
2
2
  import { z } from "zod";
3
3
  import { renameSessions } from "../auth/index.js";
4
+ import { personSignIns } from "../connectors/person-sign-ins.js";
4
5
  import { disconnectPersonApp, ManageError, managed, personConnections, renamePerson, signOutPersonComputer, } from "../manage.js";
5
6
  import { say } from "./lang.js";
6
7
  async function answer(c, work) {
@@ -16,9 +17,11 @@ async function answer(c, work) {
16
17
  }
17
18
  /**
18
19
  * The person's Konto in the cloud studio, behind the avatar: their name and what holds a sign-in
19
- * of theirs, kept at the Manage-App for every organization (docs/manage-contract.md).
20
+ * of theirs, kept at the Manage-App for every organization (docs/manage-contract.md). Their
21
+ * sign-ins to the connections of their spaces are the runtime's, also on a local install.
20
22
  */
21
23
  export const personRoutes = new Hono()
24
+ .get("/sign-ins", async (c) => c.json(await personSignIns(c.get("user"))))
22
25
  .use(async (c, next) => {
23
26
  if (!managed) {
24
27
  return c.json({ error: say(c, "onlyAvailableCloud"), code: "not_managed" }, 404);
@@ -3,6 +3,7 @@ import { dirname } from "node:path";
3
3
  import { Hono } from "hono";
4
4
  import { streamSSE } from "hono/streaming";
5
5
  import { z } from "zod";
6
+ import { readingAs, subjectsOfPerson } from "../broker/rwx.js";
6
7
  import { switchOn } from "../features.js";
7
8
  import { managed } from "../manage.js";
8
9
  import { installedHere, installPluginFolder, installPluginZip, MAX_PLUGIN, removeInstalledPlugin, } from "../plugins/install.js";
@@ -84,7 +85,8 @@ export async function dispatchAs(c, user) {
84
85
  },
85
86
  };
86
87
  try {
87
- const result = await route.handler(request);
88
+ // What the plugin reads of the space's Knowledge, it reads as this person (broker/rwx.ts).
89
+ const result = await readingAs(subjectsOfPerson(user.id, user.role), async () => route.handler(request));
88
90
  return result instanceof Response ? result : c.json(result ?? null);
89
91
  }
90
92
  catch (err) {
@@ -0,0 +1,26 @@
1
+ import { RWX_FLAGS, RWX_LIMITS, RWX_RESOURCE_KINDS, RWX_SUBJECT_KINDS, } from "@engenty/wizards-shared/rwx";
2
+ import { Hono } from "hono";
3
+ import { z } from "zod";
4
+ import { deleteRule, listRules, putRules } from "../broker/rwx.js";
5
+ const flag = z.enum(RWX_FLAGS).nullable();
6
+ const ruleSchema = z.object({
7
+ subjectKind: z.enum(RWX_SUBJECT_KINDS),
8
+ subjectId: z.string().min(1).max(RWX_LIMITS.id).nullable(),
9
+ resourceKind: z.enum(RWX_RESOURCE_KINDS),
10
+ resourceId: z.string().min(1).max(RWX_LIMITS.id),
11
+ r: flag.default(null),
12
+ w: flag.default(null),
13
+ x: flag.default(null),
14
+ });
15
+ export const ruleRoutes = new Hono()
16
+ .get("/spaces/:id/rules", async (c) => c.json({ rules: await listRules(c.get("user").id, c.req.param("id")) }))
17
+ .put("/spaces/:id/rules", async (c) => {
18
+ const { rules } = z
19
+ .object({ rules: z.array(ruleSchema).max(RWX_LIMITS.rules) })
20
+ .parse(await c.req.json());
21
+ return c.json({ rules: await putRules(c.get("user").id, c.req.param("id"), rules) });
22
+ })
23
+ .delete("/spaces/:id/rules/:ruleId", async (c) => {
24
+ await deleteRule(c.get("user").id, c.req.param("id"), c.req.param("ruleId"));
25
+ return c.json({ ok: true });
26
+ });