@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,417 @@
1
+ import { keptSecret, markUsed, spaceAccount, wizardAccount } from "./account.js";
2
+ import { inGrant, runGrant } from "./grant.js";
3
+ import { SIGN_IN_FAILED, summarizeInput, writeLog } from "./log.js";
4
+ import { guestSendCheck, recipientsOf } from "./send.js";
5
+ /**
6
+ * A wizard's step calls as the person running it: the store's holder says who that is, their
7
+ * role in the organization whether they count as an admin.
8
+ */
9
+ export function whoOf(holder, role) {
10
+ if (holder.startsWith("u:")) {
11
+ const admin = role === "owner" || role === "admin";
12
+ return { kind: admin ? "admin" : "person", id: holder.slice(2) };
13
+ }
14
+ if (holder.startsWith("v:")) {
15
+ return { kind: "guest", id: holder.slice(2) };
16
+ }
17
+ // `r:<run>`: a run nobody signed in for and no visitor cookie names.
18
+ return { kind: "guest", id: holder.replace(/^r:/, "") };
19
+ }
20
+ /** Where a step's call is made. */
21
+ export function whereOf(ctx) {
22
+ return {
23
+ ...whereOfRun({ id: ctx.runId, wizardId: ctx.store.wizardId, mode: ctx.test ? "test" : "live" }, ctx.store.holder, ctx.space.id),
24
+ stepId: ctx.stepId,
25
+ };
26
+ }
27
+ /** Where a call about a run is made (a share job, a step). */
28
+ export function whereOfRun(run, holder, spaceId) {
29
+ const mode = run.mode === "test" ? "test" : "live";
30
+ return {
31
+ runId: run.id,
32
+ wizardId: run.wizardId,
33
+ spaceId,
34
+ mode,
35
+ guest: mode === "live" && !holder.startsWith("u:"),
36
+ };
37
+ }
38
+ /** The rules' view of a connector action's group. */
39
+ export function kindOf(group) {
40
+ return group === "destructive" || group === "write" || group === "send" ? group : "read";
41
+ }
42
+ /** Whether this caller is in a connection's audience: Admins, Mitglieder or alle. */
43
+ export function inAudience(audience, who) {
44
+ if (audience === "all") {
45
+ return true;
46
+ }
47
+ // A fixed step is in the audience its run's holder is in; a plugin's job works for the space.
48
+ const asked = who.kind === "step" && who.for ? who.for : who;
49
+ if (audience === "members") {
50
+ return asked.kind !== "guest";
51
+ }
52
+ return asked.kind === "admin" || (asked.kind === "goose" && asked.admin === true);
53
+ }
54
+ /**
55
+ * The decision, with no side effect: the same function „Was darf …?“ will show. The run's grant
56
+ * comes first: a wizard's connection outside it, or an action the grant does not name, is denied
57
+ * whatever the rules say.
58
+ *
59
+ * A connection of the space: outside its audience nothing runs, nor an action the connection is
60
+ * not for. Its rules say per kind of action Erlaubt, Mit Freigabe or Nie. On a connection that
61
+ * signs in as the space an AI step only reads: a write there comes from a fixed `call` step (the
62
+ * wizard's fields, no model) or a Work chat's confirmed action, and never asks the person running;
63
+ * „Mit Freigabe“ there asks the space's admins (`admins`). Where each person signs in, „Mit
64
+ * Freigabe“ asks that person. A plugin's own job on a connection it set up runs as before.
65
+ *
66
+ * A wizard's own connection: reads run, writes and sends ask the person running, deleting always
67
+ * asks; the wizard's author may settle an action's ask per `connection.policy`.
68
+ */
69
+ export function decide(call) {
70
+ const { connection, kind, who } = call;
71
+ if (call.grant && connection.kind === "store_secret") {
72
+ if (!inGrant(call.grant, connection.def.id, call.actionId, kind)) {
73
+ return {
74
+ outcome: "deny",
75
+ rule: "grant",
76
+ reason: `The run's grant does not include "${call.actionId}" through ${connection.def.id}.`,
77
+ };
78
+ }
79
+ }
80
+ if (connection.kind === "space_connection") {
81
+ const { row } = connection;
82
+ const ownJob = who.kind === "plugin" && row.plugin === who.id && !call.where.runId && !call.where.chatId;
83
+ if (ownJob) {
84
+ return { outcome: "allow", rule: "own_job", reason: "The plugin's own connection." };
85
+ }
86
+ if (!inAudience(row.audience, who)) {
87
+ return {
88
+ outcome: "deny",
89
+ rule: "audience",
90
+ reason: `The connection is for ${AUDIENCE[row.audience]}.`,
91
+ };
92
+ }
93
+ if (row.actions.length && !row.actions.includes(call.actionId)) {
94
+ return {
95
+ outcome: "deny",
96
+ rule: "actions",
97
+ reason: `The connection is not for "${call.actionId}".`,
98
+ };
99
+ }
100
+ if (row.signIn === "space" && kind !== "read" && aiStep(who, call.where)) {
101
+ return {
102
+ outcome: "deny",
103
+ rule: "ai_step_writes",
104
+ refused: "ai_step_writes",
105
+ reason: `An AI step only reads as the space: ${VERB[kind]} goes in a fixed step with "call".`,
106
+ };
107
+ }
108
+ const rule = row.rules[kind] ?? "deny";
109
+ const named = `rules.${kind}`;
110
+ if (rule === "deny") {
111
+ return {
112
+ outcome: "deny",
113
+ rule: named,
114
+ reason: `The connection's rule: ${VERB[kind]} never.`,
115
+ };
116
+ }
117
+ if (rule === "allow") {
118
+ return {
119
+ outcome: "allow",
120
+ rule: named,
121
+ reason: `The connection's rule: ${VERB[kind]} allowed.`,
122
+ };
123
+ }
124
+ if (row.signIn === "person") {
125
+ return {
126
+ outcome: "ask",
127
+ rule: named,
128
+ reason: `The connection's rule: ${VERB[kind]} asks the person.`,
129
+ };
130
+ }
131
+ return {
132
+ outcome: "ask",
133
+ rule: named,
134
+ admins: true,
135
+ reason: `The connection's rule: ${VERB[kind]} asks the space's admins.`,
136
+ };
137
+ }
138
+ if (kind === "destructive") {
139
+ return { outcome: "ask", rule: "destructive", reason: "Deleting always asks the person." };
140
+ }
141
+ const set = connection.def.policy?.[call.actionId];
142
+ const policy = set ?? (kind === "read" ? "allow" : "ask");
143
+ const named = set ? `policy.${call.actionId}` : kind === "read" ? "read" : "policy";
144
+ if (policy === "ask") {
145
+ return {
146
+ outcome: "ask",
147
+ rule: named,
148
+ reason: "A change asks the person running the wizard.",
149
+ };
150
+ }
151
+ return {
152
+ outcome: "allow",
153
+ rule: named,
154
+ reason: kind === "read" ? "Reading is allowed." : "The wizard allows this action.",
155
+ };
156
+ }
157
+ /**
158
+ * Whether a call in a run comes from an AI step: a model's tool call, made as the person running
159
+ * (a guest, a person, an admin), or a plugin tool it called. A fixed step calls as `step`; a
160
+ * plugin's own job and a Work chat are no run.
161
+ */
162
+ function aiStep(who, where) {
163
+ return !!where.runId && who.kind !== "step";
164
+ }
165
+ /**
166
+ * Whether a run's grant binds this call: a wizard's own connection, called in a run. A plugin's
167
+ * connection is the space's, under its own rules (A4, A5); a share target's connection
168
+ * (`def.target`) is the person's own request after the run, never in the definition.
169
+ */
170
+ export function grantBinds(where, connection) {
171
+ return !!where.runId && connection.kind === "store_secret" && !connection.def.target;
172
+ }
173
+ const AUDIENCE = {
174
+ admins: "the space's admins",
175
+ members: "the space's members",
176
+ all: "everyone",
177
+ };
178
+ const VERB = {
179
+ read: "reading",
180
+ write: "writing",
181
+ destructive: "deleting",
182
+ send: "sending",
183
+ };
184
+ /** The log's id of a connection: a plugin's row, a wizard's connection id. */
185
+ function connectionIdOf(connection) {
186
+ return connection.kind === "space_connection" ? connection.row.id : connection.def.id;
187
+ }
188
+ async function accountOf(connection, who) {
189
+ return connection.kind === "space_connection"
190
+ ? spaceAccount(connection.row, connection.connector, who)
191
+ : wizardAccount(connection.scope, connection.def, connection.spaceId);
192
+ }
193
+ /** Nobody in particular: for what a wizard's connection holds, which asks for no caller. */
194
+ const NOBODY = { kind: "guest" };
195
+ /**
196
+ * The account a connection holds, without its secret: whether and as whom it is connected. A
197
+ * connection in which each person signs in needs the caller to say whose.
198
+ */
199
+ export async function brokerConnected(connection, who = NOBODY) {
200
+ const account = await accountOf(connection, who);
201
+ return account ? { connector: account.connector, label: account.label } : null;
202
+ }
203
+ /** The widest the person sees of an input they are asked about. */
204
+ const ASK_INPUT = 4000;
205
+ /**
206
+ * One call through the broker: who, where, which connection and action, with what. Reads the
207
+ * account, decides, asks where the rules say so, runs the action (the connector's, or `handler`)
208
+ * and logs the call, whatever came of it. An error the action throws is logged and thrown on.
209
+ */
210
+ export async function brokerCall(call) {
211
+ const started = Date.now();
212
+ const { who, where, connection, ctx = {} } = call;
213
+ const connectionId = connectionIdOf(connection);
214
+ // A connection of the space used for the first time is heard of (log.ts, `first_use`).
215
+ const firstUse = connection.kind === "space_connection" && !connection.row.lastUsedAt;
216
+ const line = (kind, outcome, rule, reason, result, size = null, context = {}) => writeLog({
217
+ at: new Date(started),
218
+ durationMs: Date.now() - started,
219
+ whoKind: who.kind,
220
+ whoId: who.id ?? null,
221
+ runId: where.runId ?? null,
222
+ stepId: where.stepId ?? null,
223
+ chatId: where.chatId ?? null,
224
+ wizardId: where.wizardId ?? null,
225
+ spaceId: where.spaceId ?? null,
226
+ connectionId,
227
+ actionId: call.action.id,
228
+ kind,
229
+ inputSummary: summarizeInput(call.input),
230
+ outcome,
231
+ rule,
232
+ reason,
233
+ result,
234
+ resultSize: size,
235
+ }, context);
236
+ // The account says what kind the action is; its secret stays inside the broker. A sign-in
237
+ // that ran out and cannot be renewed, or that the service refuses, is heard of.
238
+ let account;
239
+ try {
240
+ account = await accountOf(connection, who);
241
+ }
242
+ catch (err) {
243
+ const reason = `The sign-in could not be renewed: ${err instanceof Error ? err.message : String(err)}`;
244
+ await line(call.action.kind ?? "read", "deny", null, reason, SIGN_IN_FAILED);
245
+ return { ok: false, refused: "not_connected", reason };
246
+ }
247
+ const found = account?.connector.actions.find((a) => a.id === call.action.id);
248
+ const kind = call.action.kind ?? (found ? kindOf(found.group) : "write");
249
+ // The grant first: what the run's definition gave it, fixed when it started.
250
+ let grant;
251
+ if (grantBinds(where, connection)) {
252
+ grant = await runGrant(where.runId);
253
+ if (!grant) {
254
+ const reason = "The run is not known here.";
255
+ await line(kind, "deny", "grant", reason, "not_in_grant");
256
+ return { ok: false, refused: "not_in_grant", reason };
257
+ }
258
+ if (!inGrant(grant, connectionId, call.action.id, kind)) {
259
+ const decision = decide({ who, where, connection, actionId: call.action.id, kind, grant });
260
+ await line(kind, "deny", decision.rule, decision.reason, "not_in_grant");
261
+ return { ok: false, refused: "not_in_grant", reason: decision.reason };
262
+ }
263
+ }
264
+ if (!account) {
265
+ const reason = connection.kind === "space_connection" && connection.row.signIn === "person"
266
+ ? "You have not signed in to this connection."
267
+ : "Nothing is connected.";
268
+ await line(kind, "deny", null, reason, "not_connected");
269
+ return { ok: false, refused: "not_connected", reason };
270
+ }
271
+ if (!(found || call.handler)) {
272
+ const reason = `${account.connector.name} has no action "${call.action.id}".`;
273
+ await line(kind, "deny", null, reason, "no_action");
274
+ return { ok: false, refused: "no_action", reason };
275
+ }
276
+ const decision = decide({ who, where, connection, actionId: call.action.id, kind, grant });
277
+ const { rule } = decision;
278
+ if (decision.outcome === "deny") {
279
+ const refused = decision.refused ?? "denied";
280
+ await line(kind, "deny", rule, decision.reason, refused);
281
+ return { ok: false, refused, reason: decision.reason };
282
+ }
283
+ // A guest's send goes only to the run's own address or the space's domains, a few per run and day.
284
+ if (kind === "send" && where.guest) {
285
+ const sent = await guestSendCheck(where, recipientsOf(call.input));
286
+ if (!sent.ok) {
287
+ await line(kind, "deny", "guest_send", sent.reason, sent.refused);
288
+ return { ok: false, refused: sent.refused, reason: sent.reason };
289
+ }
290
+ }
291
+ if (decision.outcome === "ask" && decision.admins) {
292
+ // „Mit Freigabe“ as the space: the person's own yes is not enough; an admin's is.
293
+ if (ctx.approved) {
294
+ decision.reason = "An admin of the space approved it.";
295
+ }
296
+ else {
297
+ await line(kind, "ask", rule, decision.reason, "needs_approval");
298
+ return { ok: false, refused: "needs_approval", reason: decision.reason };
299
+ }
300
+ }
301
+ else if (decision.outcome === "ask") {
302
+ const key = `${connectionId}:${call.action.id}`;
303
+ if (ctx.allowed?.has(key)) {
304
+ decision.reason = "The person allowed it for the rest of the run.";
305
+ }
306
+ else if (ctx.confirmed && kind !== "destructive") {
307
+ decision.reason = "The person asked for it themselves.";
308
+ }
309
+ else if (!ctx.ask) {
310
+ await line(kind, "ask", rule, decision.reason, "nobody");
311
+ return { ok: false, refused: "nobody", reason: "Nobody is there to ask." };
312
+ }
313
+ else {
314
+ const answer = await ctx.ask({
315
+ kind: "confirm",
316
+ reason: found?.summary || call.action.id,
317
+ service: account.label,
318
+ action: {
319
+ id: call.action.id,
320
+ summary: found?.summary ?? call.action.id,
321
+ destructive: kind === "destructive",
322
+ },
323
+ input: JSON.stringify(call.input ?? {}, null, 2).slice(0, ASK_INPUT),
324
+ });
325
+ if (!answer) {
326
+ await line(kind, "ask", rule, decision.reason, "nobody");
327
+ return { ok: false, refused: "nobody", reason: "Nobody is there to ask." };
328
+ }
329
+ if (answer.type !== "done") {
330
+ await line(kind, "ask", rule, decision.reason, "declined");
331
+ return { ok: false, refused: "declined", reason: "The person did not allow it." };
332
+ }
333
+ if (answer.remember) {
334
+ ctx.allowed?.add(key);
335
+ }
336
+ }
337
+ }
338
+ try {
339
+ const result = call.handler
340
+ ? await call.handler(account)
341
+ : (await found.handler(call.input ?? {}, account.ctx));
342
+ await line(kind, decision.outcome, rule, decision.reason, "ok", sizeOf(result), { firstUse });
343
+ if (connection.kind === "space_connection") {
344
+ await markUsed(connection.row);
345
+ }
346
+ return { ok: true, result, account: { connector: account.connector, label: account.label } };
347
+ }
348
+ catch (err) {
349
+ // The service turned the sign-in down: heard of, like a sign-in that ran out.
350
+ const result = signInRefused(err)
351
+ ? SIGN_IN_FAILED
352
+ : err instanceof Error
353
+ ? err.constructor.name || "Error"
354
+ : "Error";
355
+ await line(kind, decision.outcome, rule, decision.reason, result);
356
+ throw err;
357
+ }
358
+ }
359
+ /** Whether the service answered a call with "who are you?": its 401, or an OAuth grant gone. */
360
+ export function signInRefused(err) {
361
+ const text = err instanceof Error ? err.message : String(err);
362
+ return /(^|\D)401(\D|$)|invalid_grant|unauthori[sz]ed|token (has )?expired/i.test(text);
363
+ }
364
+ /**
365
+ * A secret of a run's store that is no connection (the browser's kept sign-ins), read through
366
+ * the broker as a `read`: the handler alone sees it, and the call is logged like any other.
367
+ */
368
+ export async function brokerSecret(call) {
369
+ const started = Date.now();
370
+ const kept = await keptSecret(call.scope, call.slot);
371
+ const line = (result) => writeLog({
372
+ at: new Date(started),
373
+ durationMs: Date.now() - started,
374
+ whoKind: call.who.kind,
375
+ whoId: call.who.id ?? null,
376
+ runId: call.where.runId ?? null,
377
+ stepId: call.where.stepId ?? null,
378
+ chatId: call.where.chatId ?? null,
379
+ wizardId: call.where.wizardId ?? null,
380
+ spaceId: call.where.spaceId ?? null,
381
+ connectionId: call.slot,
382
+ actionId: "read_secret",
383
+ kind: "read",
384
+ inputSummary: summarizeInput({}),
385
+ outcome: "allow",
386
+ rule: "read",
387
+ reason: "Reading is allowed.",
388
+ result,
389
+ resultSize: null,
390
+ });
391
+ try {
392
+ const result = await call.handler(kept?.data ?? null);
393
+ await line(kept ? "ok" : "not_connected");
394
+ return result;
395
+ }
396
+ catch (err) {
397
+ await line(err instanceof Error ? err.constructor.name || "Error" : "Error");
398
+ throw err;
399
+ }
400
+ }
401
+ function sizeOf(result) {
402
+ if (result === undefined || result === null) {
403
+ return 0;
404
+ }
405
+ if (typeof result === "string") {
406
+ return result.length;
407
+ }
408
+ if (typeof result !== "object") {
409
+ return null;
410
+ }
411
+ try {
412
+ return JSON.stringify(result)?.length ?? null;
413
+ }
414
+ catch {
415
+ return null;
416
+ }
417
+ }
@@ -0,0 +1,10 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ const current = new AsyncLocalStorage();
3
+ /** Runs `fn` as this caller: every broker call inside carries it. */
4
+ export function withCaller(caller, fn) {
5
+ return current.run(caller, fn);
6
+ }
7
+ /** The caller the code runs for, or null outside any run or chat (a plugin's own job). */
8
+ export function currentCaller() {
9
+ return current.getStore() ?? null;
10
+ }
@@ -0,0 +1,152 @@
1
+ import { note } from "@engenty/wizards-shared/run";
2
+ import { eq } from "drizzle-orm";
3
+ import { db, schema } from "../db/client.js";
4
+ /** The grant a definition gives its runs. Pure: the same definition, the same grant. */
5
+ export function grantOf(definition) {
6
+ const connections = {};
7
+ const tools = new Set();
8
+ const hosts = new Set();
9
+ const defs = new Map((definition.connections ?? []).map((c) => [c.id, c]));
10
+ for (const step of definition.steps) {
11
+ if (step.type !== "agent") {
12
+ continue;
13
+ }
14
+ for (const tool of step.tools) {
15
+ tools.add(tool);
16
+ }
17
+ if (step.call && "connection" in step.call && defs.has(step.call.connection)) {
18
+ const have = new Set(connections[step.call.connection] ?? []);
19
+ have.add(step.call.action);
20
+ connections[step.call.connection] = [...have].sort();
21
+ }
22
+ for (const host of step.hosts ?? []) {
23
+ hosts.add(host.trim().toLowerCase());
24
+ }
25
+ for (const id of step.connections ?? []) {
26
+ const def = defs.get(id);
27
+ if (!def) {
28
+ continue;
29
+ }
30
+ const have = new Set(connections[id] ?? []);
31
+ for (const action of def.actions ?? ["read"]) {
32
+ have.add(action);
33
+ }
34
+ connections[id] = [...have].sort();
35
+ }
36
+ }
37
+ return { connections, hosts: [...hosts].sort(), tools: [...tools].sort() };
38
+ }
39
+ /**
40
+ * Whether the grant lets `http_request` reach this host: named as it is, or below a `*.` entry
41
+ * (`*.example.org` takes `api.example.org`, not `example.org` itself).
42
+ */
43
+ export function hostInGrant(grant, hostname) {
44
+ const host = hostname
45
+ .replace(/^\[|\]$/g, "")
46
+ .toLowerCase()
47
+ .replace(/\.$/, "");
48
+ return grant.hosts.some((entry) => entry.startsWith("*.")
49
+ ? host.endsWith(entry.slice(1)) && host.length > entry.length - 1
50
+ : entry === host);
51
+ }
52
+ /**
53
+ * Whether the grant lets this action run through this connection: the action by its id, or by
54
+ * its kind where the grant names kinds. A connection in the grant may always list its connector's
55
+ * tools (`list_tools`): that reads the connector, not the account's data.
56
+ */
57
+ export function inGrant(grant, connectionId, actionId, kind) {
58
+ const allowed = grant.connections[connectionId];
59
+ if (!allowed) {
60
+ return false;
61
+ }
62
+ return actionId === "list_tools" || allowed.includes(actionId) || allowed.includes(kind);
63
+ }
64
+ /**
65
+ * The grant a run holds. A run from before grants were kept gets one from the definition it
66
+ * started on, written once on first use; null for a run this tenant does not have.
67
+ */
68
+ export async function runGrant(runId) {
69
+ const run = await db.query.run.findFirst({
70
+ where: eq(schema.run.id, runId),
71
+ columns: { grant: true, definition: true },
72
+ });
73
+ if (!run) {
74
+ return null;
75
+ }
76
+ if (run.grant) {
77
+ return run.grant;
78
+ }
79
+ const grant = grantOf(run.definition);
80
+ await db.update(schema.run).set({ grant }).where(eq(schema.run.id, runId));
81
+ return grant;
82
+ }
83
+ /** What a built-in tool lets a run do, in the run's log. */
84
+ const TOOL_NOTES = {
85
+ web_search: note("grantSearchesWeb"),
86
+ web_fetch: note("grantReadsWeb"),
87
+ browser: note("grantBrowser"),
88
+ sandbox: note("grantRunsCode"),
89
+ code: note("grantRunsCode"),
90
+ image: note("grantDrawsImages"),
91
+ http: note("grantCallsApis"),
92
+ pages: note("grantWritesPages"),
93
+ };
94
+ /**
95
+ * The line the run's log opens with: what the run may do, in words. `connectors` says, by
96
+ * connection id, what the connector is called and what kind each of its actions is, where the
97
+ * space has it; an unknown connector's actions are named as they are. Null when the run reaches
98
+ * nothing outside.
99
+ */
100
+ export function grantNote(grant, definition, connectors = {}) {
101
+ const what = [];
102
+ const defs = new Map((definition.connections ?? []).map((c) => [c.id, c]));
103
+ for (const [id, actions] of Object.entries(grant.connections)) {
104
+ const def = defs.get(id);
105
+ const name = def?.title ?? connectors[id]?.name ?? def?.connector ?? def?.kind ?? id;
106
+ const known = connectors[id]?.kinds ?? {};
107
+ const byKind = new Set();
108
+ const unknown = [];
109
+ for (const action of actions) {
110
+ if (action === "read" ||
111
+ action === "write" ||
112
+ action === "send" ||
113
+ action === "destructive") {
114
+ byKind.add(action);
115
+ }
116
+ else if (known[action]) {
117
+ byKind.add(known[action]);
118
+ }
119
+ else {
120
+ unknown.push(action);
121
+ }
122
+ }
123
+ if (byKind.has("read")) {
124
+ what.push(note("grantReads", { name }));
125
+ }
126
+ if (byKind.has("write")) {
127
+ what.push(note("grantWrites", { name }));
128
+ }
129
+ if (byKind.has("send")) {
130
+ what.push(note("grantSends", { name }));
131
+ }
132
+ if (byKind.has("destructive")) {
133
+ what.push(note("grantDeletes", { name }));
134
+ }
135
+ if (unknown.length) {
136
+ what.push(note("grantCalls", { name, actions: unknown }));
137
+ }
138
+ }
139
+ for (const [tool, own] of Object.entries(TOOL_NOTES)) {
140
+ if (grant.tools.includes(tool) && !what.some((w) => w.code === own.code)) {
141
+ // With hosts listed the run calls those, not "APIs on the web".
142
+ what.push(tool === "http" && grant.hosts.length
143
+ ? note("grantCallsHosts", { hosts: grant.hosts })
144
+ : own);
145
+ }
146
+ }
147
+ const plugins = new Set(grant.tools.filter((tool) => !TOOL_NOTES[tool]).map((tool) => tool.split(".")[0]));
148
+ for (const plugin of plugins) {
149
+ what.push(note("grantPlugin", { name: plugin }));
150
+ }
151
+ return what.length ? note("grant", { what }) : null;
152
+ }
@@ -0,0 +1,51 @@
1
+ import { hostInGrant, runGrant } from "./grant.js";
2
+ import { summarizeInput, writeLog } from "./log.js";
3
+ import { brokerOn } from "./rwx.js";
4
+ export async function brokerHost(call) {
5
+ const started = Date.now();
6
+ const { who, where, url } = call;
7
+ const host = url.hostname.toLowerCase();
8
+ const line = (outcome, reason, result) => writeLog({
9
+ at: new Date(started),
10
+ durationMs: Date.now() - started,
11
+ whoKind: who.kind,
12
+ whoId: who.id ?? null,
13
+ runId: where.runId ?? null,
14
+ stepId: where.stepId ?? null,
15
+ chatId: where.chatId ?? null,
16
+ wizardId: where.wizardId ?? null,
17
+ spaceId: where.spaceId ?? null,
18
+ connectionId: `host:${host}`,
19
+ actionId: "http_request",
20
+ kind: "send",
21
+ // The path without its query: a query may carry a key.
22
+ inputSummary: summarizeInput({ method: call.method, host, path: url.pathname }),
23
+ outcome,
24
+ rule: "grant",
25
+ reason,
26
+ result,
27
+ resultSize: null,
28
+ });
29
+ const bound = where.guest || (await brokerOn());
30
+ let reason = "Members reach every public host.";
31
+ if (bound) {
32
+ const grant = where.runId ? await runGrant(where.runId) : null;
33
+ if (!grant || !hostInGrant(grant, host)) {
34
+ const why = grant
35
+ ? `The run's grant does not include the host ${host}.`
36
+ : "The run is not known here.";
37
+ await line("deny", why, "not_in_grant");
38
+ return { ok: false, refused: "not_in_grant", reason: why };
39
+ }
40
+ reason = "The host is in the run's grant.";
41
+ }
42
+ try {
43
+ const result = await call.handler();
44
+ await line("allow", reason, "ok");
45
+ return { ok: true, result };
46
+ }
47
+ catch (err) {
48
+ await line("allow", reason, err instanceof Error ? err.constructor.name || "Error" : "Error");
49
+ throw err;
50
+ }
51
+ }
@@ -0,0 +1,8 @@
1
+ export { brokerCall, brokerConnected, brokerSecret, decide, grantBinds, inAudience, kindOf, signInRefused, whereOf, whereOfRun, whoOf, } from "./call.js";
2
+ export { currentCaller, withCaller } from "./caller.js";
3
+ export { grantNote, grantOf, hostInGrant, inGrant, runGrant, } from "./grant.js";
4
+ export { brokerHost } from "./host.js";
5
+ export { keptStepIds } from "./kept.js";
6
+ export { CRITICAL_KINDS, criticalOf, criticalSince, cursorOf, LOG_PAGE, lastUseOf, logLine, logOfSpace, logRuleChange, onCritical, RULE_CHANGE_ACTION, readCursor, SIGN_IN_FAILED, summarizeInput, } from "./log.js";
7
+ export { outsideReaches, reachesOutside } from "./registry.js";
8
+ export { brokerSend, GUEST_MAILS_PER_RUN, guestSendCheck, recipientsOf, runAddresses, } from "./send.js";
@@ -0,0 +1,31 @@
1
+ import { and, eq, inArray, isNotNull, ne } from "drizzle-orm";
2
+ import { db, schema } from "../db/client.js";
3
+ import { guestRun } from "../safety.js";
4
+ /*
5
+ * Results that stay in the space (docs/plans/capabilities.md, A6; rule 5 of the connections
6
+ * plan): a step of a guest's run that read a connection the space keeps for its members or admins
7
+ * made its output with the space's data. The output is kept with the run — Ergebnisse in the
8
+ * studio shows it — and the guest's result page and share link show a note in its place. The
9
+ * broker's log says which step read which connection; the connection's audience is read as it is
10
+ * now, so narrowing it afterwards keeps the results too.
11
+ */
12
+ /** The steps of this run whose output stays in the space; empty for a member's run. */
13
+ export async function keptStepIds(run) {
14
+ if (!guestRun(run)) {
15
+ return new Set();
16
+ }
17
+ const reads = await db
18
+ .select({ stepId: schema.brokerLog.stepId, connectionId: schema.brokerLog.connectionId })
19
+ .from(schema.brokerLog)
20
+ .where(and(eq(schema.brokerLog.runId, run.id), eq(schema.brokerLog.outcome, "allow"), eq(schema.brokerLog.result, "ok"), isNotNull(schema.brokerLog.stepId)));
21
+ const connectionIds = [...new Set(reads.map((r) => r.connectionId))];
22
+ if (!connectionIds.length) {
23
+ return new Set();
24
+ }
25
+ const members = await db
26
+ .select({ id: schema.spaceConnection.id })
27
+ .from(schema.spaceConnection)
28
+ .where(and(inArray(schema.spaceConnection.id, connectionIds), ne(schema.spaceConnection.audience, "all")));
29
+ const kept = new Set(members.map((c) => c.id));
30
+ return new Set(reads.filter((r) => kept.has(r.connectionId)).map((r) => r.stepId));
31
+ }