@engenty/wizards-runtime 0.12.2 → 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.
- package/apps/runtime/dist/agents/architect.js +8 -7
- package/apps/runtime/dist/agents/goose-connections.js +82 -0
- package/apps/runtime/dist/agents/space-agent.js +9 -2
- package/apps/runtime/dist/agents/studio-assistant.js +126 -71
- package/apps/runtime/dist/agents/website.js +1 -1
- package/apps/runtime/dist/app.js +28 -3
- package/apps/runtime/dist/assistant/knows.js +6 -5
- package/apps/runtime/dist/authoring/guide.js +25 -5
- package/apps/runtime/dist/broker/account.js +166 -0
- package/apps/runtime/dist/broker/call.js +417 -0
- package/apps/runtime/dist/broker/caller.js +10 -0
- package/apps/runtime/dist/broker/grant.js +152 -0
- package/apps/runtime/dist/broker/host.js +51 -0
- package/apps/runtime/dist/broker/index.js +8 -0
- package/apps/runtime/dist/broker/kept.js +31 -0
- package/apps/runtime/dist/broker/log.js +240 -0
- package/apps/runtime/dist/broker/registry.js +9 -0
- package/apps/runtime/dist/broker/rwx.js +367 -0
- package/apps/runtime/dist/broker/send.js +189 -0
- package/apps/runtime/dist/connectors/builtin.js +1 -1
- package/apps/runtime/dist/connectors/external.js +38 -37
- package/apps/runtime/dist/connectors/index.js +30 -91
- package/apps/runtime/dist/connectors/mail.js +0 -8
- package/apps/runtime/dist/connectors/person-sign-ins.js +73 -0
- package/apps/runtime/dist/connectors/plugin-connections.js +65 -92
- package/apps/runtime/dist/connectors/smtp.js +1 -1
- package/apps/runtime/dist/connectors/space-connections.js +436 -0
- package/apps/runtime/dist/credits/estimate.js +3 -3
- package/apps/runtime/dist/db/adopt.js +3 -3
- package/apps/runtime/dist/db/client.js +9 -0
- package/apps/runtime/dist/db/live-triggers.js +65 -23
- package/apps/runtime/dist/db/migrations/tenant/0027_work_chats.sql +52 -0
- package/apps/runtime/dist/db/migrations/tenant/0028_chat_approvals.sql +17 -0
- package/apps/runtime/dist/db/migrations/tenant/0029_work_chats_live.sql +49 -0
- package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
- package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
- package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
- package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
- package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
- package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
- package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
- package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
- package/apps/runtime/dist/db/schema.js +295 -72
- package/apps/runtime/dist/docs/dev/architecture.md +215 -0
- package/apps/runtime/dist/docs/dev/broker.md +298 -0
- package/apps/runtime/dist/docs/dev/index.md +5 -1
- package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
- package/apps/runtime/dist/docs/dev/meta.json +3 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
- package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
- package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
- package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
- package/apps/runtime/dist/docs/dev/skills.md +16 -9
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +59 -6
- package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
- package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
- package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
- package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
- package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
- package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
- package/apps/runtime/dist/docs/user-guide/index.md +10 -1
- package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
- package/apps/runtime/dist/docs/user-guide/models.md +105 -30
- package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
- package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
- package/apps/runtime/dist/docs/user-guide/space.md +5 -4
- package/apps/runtime/dist/docs/user-guide/together.md +29 -2
- package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
- package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
- package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
- package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
- package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
- package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
- package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
- package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
- package/apps/runtime/dist/engine/decide.js +1 -1
- package/apps/runtime/dist/engine/requirements.js +139 -11
- package/apps/runtime/dist/engine/resources.js +43 -12
- package/apps/runtime/dist/engine/runner.js +121 -27
- package/apps/runtime/dist/engine/steps.js +42 -16
- package/apps/runtime/dist/engine/template.js +35 -1
- package/apps/runtime/dist/env.js +9 -4
- package/apps/runtime/dist/index.js +18 -2
- package/apps/runtime/dist/link-preview.js +9 -0
- package/apps/runtime/dist/live/feed.js +2 -2
- package/apps/runtime/dist/live/origin.js +2 -2
- package/apps/runtime/dist/live/views.js +51 -26
- package/apps/runtime/dist/manage.js +32 -0
- package/apps/runtime/dist/mcp/flow-app.js +1 -1
- package/apps/runtime/dist/mcp/handler.js +55 -1
- package/apps/runtime/dist/mcp/seen.js +47 -0
- package/apps/runtime/dist/mcp/tools.js +75 -34
- package/apps/runtime/dist/models.js +203 -12
- package/apps/runtime/dist/motion-graphics/project.js +8 -8
- package/apps/runtime/dist/motion-graphics/step.js +2 -2
- package/apps/runtime/dist/motion-graphics/tools.js +1 -1
- package/apps/runtime/dist/plugins/events.js +2 -2
- package/apps/runtime/dist/plugins/jobs.js +4 -1
- package/apps/runtime/dist/plugins/loader.js +2 -2
- package/apps/runtime/dist/prompts/architect.md +3 -3
- package/apps/runtime/dist/prompts/authoring.md +46 -12
- package/apps/runtime/dist/prompts/goose.md +14 -13
- package/apps/runtime/dist/prompts/mcp.md +6 -6
- package/apps/runtime/dist/prompts/safety.md +18 -0
- package/apps/runtime/dist/prompts/services.md +4 -4
- package/apps/runtime/dist/prompts/step.md +3 -3
- package/apps/runtime/dist/prompts/tools.md +39 -10
- package/apps/runtime/dist/routes/api.js +31 -20
- package/apps/runtime/dist/routes/broker.js +316 -0
- package/apps/runtime/dist/routes/connections.js +71 -0
- package/apps/runtime/dist/routes/delivery.js +25 -0
- package/apps/runtime/dist/routes/discover.js +17 -0
- package/apps/runtime/dist/routes/live.js +11 -1
- package/apps/runtime/dist/routes/marketplace.js +3 -3
- package/apps/runtime/dist/routes/person.js +4 -1
- package/apps/runtime/dist/routes/plugins.js +3 -1
- package/apps/runtime/dist/routes/rules.js +26 -0
- package/apps/runtime/dist/routes/runs.js +59 -33
- package/apps/runtime/dist/routes/skills.js +6 -6
- package/apps/runtime/dist/routes/studio.js +256 -148
- package/apps/runtime/dist/routes/work.js +199 -0
- package/apps/runtime/dist/safety.js +60 -18
- package/apps/runtime/dist/sandbox/index.js +27 -0
- package/apps/runtime/dist/services/access.js +38 -17
- package/apps/runtime/dist/services/api.js +38 -13
- package/apps/runtime/dist/services/architect.js +3 -3
- package/apps/runtime/dist/services/assistant-chats.js +9 -1
- package/apps/runtime/dist/services/brand.js +12 -12
- package/apps/runtime/dist/services/broker-bell.js +69 -0
- package/apps/runtime/dist/services/broker-notify.js +127 -0
- package/apps/runtime/dist/services/client-steps.js +79 -0
- package/apps/runtime/dist/services/cloud.js +42 -42
- package/apps/runtime/dist/services/command-risk.js +51 -0
- package/apps/runtime/dist/services/discover.js +85 -0
- package/apps/runtime/dist/services/knowledge-model.js +13 -13
- package/apps/runtime/dist/services/knowledge.js +117 -80
- package/apps/runtime/dist/services/manage-reports.js +77 -7
- package/apps/runtime/dist/services/marketplace.js +7 -31
- package/apps/runtime/dist/services/members-studio.js +165 -0
- package/apps/runtime/dist/services/onboarding.js +22 -22
- package/apps/runtime/dist/services/package-file.js +1 -1
- package/apps/runtime/dist/services/package.js +22 -22
- package/apps/runtime/dist/services/pages.js +13 -9
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/seen.js +55 -0
- package/apps/runtime/dist/services/shares.js +28 -13
- package/apps/runtime/dist/services/site.js +23 -23
- package/apps/runtime/dist/services/skills-registry.js +15 -15
- package/apps/runtime/dist/services/skills.js +44 -44
- package/apps/runtime/dist/services/space-categories.js +35 -35
- package/apps/runtime/dist/services/space-data.js +130 -111
- package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
- package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
- package/apps/runtime/dist/services/space-origin.js +19 -11
- package/apps/runtime/dist/services/spaces.js +478 -598
- package/apps/runtime/dist/services/synced-spaces.js +668 -0
- package/apps/runtime/dist/services/themes.js +15 -15
- package/apps/runtime/dist/services/widgets.js +6 -6
- package/apps/runtime/dist/services/wizards.js +112 -38
- package/apps/runtime/dist/services/work-ai.js +257 -0
- package/apps/runtime/dist/services/work-approvals.js +104 -0
- package/apps/runtime/dist/services/work-chats.js +908 -0
- package/apps/runtime/dist/services/work-connections.js +90 -0
- package/apps/runtime/dist/services/work-files.js +85 -0
- package/apps/runtime/dist/services/work-mastra.js +73 -0
- package/apps/runtime/dist/services/work-sandbox.js +42 -0
- package/apps/runtime/dist/sharing/files.js +14 -4
- package/apps/runtime/dist/sharing/index.js +40 -39
- package/apps/runtime/dist/sharing/jobs.js +67 -17
- package/apps/runtime/dist/sharing/targets/connector.js +10 -6
- package/apps/runtime/dist/sharing/targets/email.js +10 -8
- package/apps/runtime/dist/sharing/targets/slack.js +10 -8
- package/apps/runtime/dist/sharing/targets/storage.js +6 -4
- package/apps/runtime/dist/store/index.js +14 -3
- package/apps/runtime/dist/store/shared-lists.js +4 -2
- package/apps/runtime/dist/sync/apply.js +2 -2
- package/apps/runtime/dist/sync/client.js +113 -113
- package/apps/runtime/dist/sync/hub.js +41 -41
- package/apps/runtime/dist/sync/log.js +12 -12
- package/apps/runtime/dist/sync/records.js +118 -120
- package/apps/runtime/dist/texts.js +44 -2
- package/apps/runtime/dist/tools/connections.js +112 -0
- package/apps/runtime/dist/tools/connector.js +157 -67
- package/apps/runtime/dist/tools/index.js +31 -15
- package/apps/runtime/dist/tools/mail.js +40 -11
- package/apps/runtime/dist/tools/pages.js +11 -5
- package/apps/runtime/dist/tools/plugin.js +43 -7
- package/apps/runtime/dist/tools/skills.js +1 -1
- package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
- package/apps/runtime/dist/tools/store.js +3 -2
- package/apps/runtime/dist/widgets/step.js +10 -10
- package/apps/web/dist/assets/AboutDialog-DgfeipUc.js +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-BoYJvgIu.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-CKLgFL6r.js → ChangelogDialog-Duab4zTO.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-B3nto_26.js → CodeEditor-nxoOt8ge.js} +1 -1
- package/apps/web/dist/assets/EditorPage-ZrgGpYMC.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-zJCtixSi.js → FlowPreview-aMfwcPul.js} +1 -1
- package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
- package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
- package/apps/web/dist/assets/NewWizardChannels-IB18afWN.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-rYbcmPGG.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
- package/apps/web/dist/assets/PreviewPane-DviWTLfi.js +9 -0
- package/apps/web/dist/assets/PublicRunner-C2geZhhM.js +1 -0
- package/apps/web/dist/assets/ReadOnly-kSb_Kbdm.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DM2h8N0J.js +2 -0
- package/apps/web/dist/assets/SetupPage-Wfyz6xH4.js +1 -0
- package/apps/web/dist/assets/SharePage-CyWQorWB.js +1 -0
- package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
- package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
- package/apps/web/dist/assets/SpacePage-q4Bk3N7k.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-C2CE6CC3.js +2 -0
- package/apps/web/dist/assets/changelog-B6hN1Cp7.js +1 -0
- package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
- package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
- package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
- package/apps/web/dist/assets/{code-xml-Hx7YxCg0.js → code-xml-B4kLFZSj.js} +1 -1
- package/apps/web/dist/assets/connection-sign-in-CIiv0t2p.js +1 -0
- package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
- package/apps/web/dist/assets/{eye-BkMFLnYu.js → eye-BpoKpIdt.js} +1 -1
- package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
- package/apps/web/dist/assets/host-DJ7-p0Sc.js +118 -0
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
- package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
- package/apps/web/dist/assets/index-D2akynS-.js +10 -0
- package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
- package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
- package/apps/web/dist/assets/{phone-DMfwuh9V.js → phone-Ctvf-Am-.js} +1 -1
- package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
- package/apps/web/dist/assets/{runners-D5qz6b_s.js → runners-CyIvJIHr.js} +1 -1
- package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
- package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
- package/apps/web/dist/assets/theme-CbTcTFWy.js +11 -0
- package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
- package/apps/web/dist/assets/{upload-DQJwLSGj.js → upload-BchUnQGV.js} +1 -1
- package/apps/web/dist/assets/{useMutation-C20c2EH3.js → useMutation-DEkZhp5c.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CC5qamYT.js → volume-2-CU_oy81Z.js} +1 -1
- package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
- package/apps/web/dist/index.html +17 -10
- package/apps/web/dist/mcp/flow.html +119 -64
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +7 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +11 -1
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
- package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +257 -8
- package/node_modules/@engenty/wizards-shared/dist/definition.js +113 -15
- package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
- package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +38 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +38 -2
- package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +0 -5
- package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +115 -6
- package/node_modules/@engenty/wizards-shared/dist/run.js +135 -0
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
- package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
- package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
- package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
- package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/tiers.d.ts +195 -0
- package/node_modules/@engenty/wizards-shared/dist/tiers.js +98 -0
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
- package/package.json +4 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/plugin/skills/build-wizard/SKILL.md +1 -1
- package/apps/runtime/dist/services/projects.js +0 -473
- package/apps/web/dist/assets/AboutDialog-CLgnoYTI.js +0 -1
- package/apps/web/dist/assets/EditorPage-D9JDdAAI.js +0 -3
- package/apps/web/dist/assets/Marketplace-D4e0Oac9.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-B4N7GIYh.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-Dpt0Mzk8.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-CDoYVjRC.js +0 -1
- package/apps/web/dist/assets/PreviewPane-DPB5nEd5.js +0 -10
- package/apps/web/dist/assets/ProjectPage-408YOoNa.js +0 -10
- package/apps/web/dist/assets/PublicRunner-BZ66xdRX.js +0 -1
- package/apps/web/dist/assets/ReadOnly-C9oGMkUB.js +0 -1
- package/apps/web/dist/assets/SettingsPage-Dq3AZwJS.js +0 -2
- package/apps/web/dist/assets/SetupPage-CP3lbyZc.js +0 -1
- package/apps/web/dist/assets/SharePage-DdMm1Y8K.js +0 -1
- package/apps/web/dist/assets/SkillEditor-b5NMFB90.js +0 -1
- package/apps/web/dist/assets/changelog-82-DHogQ.js +0 -1
- package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
- package/apps/web/dist/assets/i18n-CKKh3Pn0.js +0 -55
- package/apps/web/dist/assets/index-Cy2NHzAx.js +0 -49
- package/apps/web/dist/assets/index-wR_-1hfN.css +0 -1
- package/apps/web/dist/assets/lock-CGXM95Mi.js +0 -1
- package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
- package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
- package/apps/web/dist/assets/session-DRy0k0nh.js +0 -2
- package/apps/web/dist/assets/theme-DNPm6r4e.js +0 -11
- package/apps/web/dist/assets/ui-CwFQAfE-.js +0 -83
- /package/apps/runtime/dist/db/migrations/tenant/{0027_space_skill.sql → 0030_space_skill.sql} +0 -0
|
@@ -14,6 +14,20 @@ function connectorsLine(connectors) {
|
|
|
14
14
|
});
|
|
15
15
|
return prompt("authoring", "line.connectors", { connectors: lines.join("\n") });
|
|
16
16
|
}
|
|
17
|
+
function spaceConnectionsLine(connections) {
|
|
18
|
+
if (!connections.length) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
const lines = connections.map((c) => {
|
|
22
|
+
const actions = c.actions
|
|
23
|
+
.slice(0, 40)
|
|
24
|
+
.map((a) => `${a.id}${a.group === "read" ? "" : ` (${a.group})`}`)
|
|
25
|
+
.join(", ");
|
|
26
|
+
const who = c.signIn === "space" ? "signs in as the space" : "each person signs in";
|
|
27
|
+
return `- ${c.id} — ${c.name} (${c.connector}), ${who}, actions: ${actions || prompt("authoring", "line.connectors.no_actions")}`;
|
|
28
|
+
});
|
|
29
|
+
return prompt("authoring", "line.space_connections", { connections: lines.join("\n") });
|
|
30
|
+
}
|
|
17
31
|
/** The tools this app's plugins add; nothing where there are none. */
|
|
18
32
|
function pluginToolsLine(tools) {
|
|
19
33
|
if (!tools.length) {
|
|
@@ -22,21 +36,27 @@ function pluginToolsLine(tools) {
|
|
|
22
36
|
const lines = tools.map((t) => `- ${t.id} — ${t.description}`);
|
|
23
37
|
return prompt("authoring", "line.plugin_tools", { tools: lines.join("\n") });
|
|
24
38
|
}
|
|
25
|
-
/** What the
|
|
26
|
-
export function
|
|
27
|
-
return [
|
|
39
|
+
/** What the space offers agent steps: its connectors, its connections and plugin tools. */
|
|
40
|
+
export function spaceLines(connectors, pluginTools, connections = []) {
|
|
41
|
+
return [
|
|
42
|
+
connectorsLine(connectors),
|
|
43
|
+
spaceConnectionsLine(connections),
|
|
44
|
+
pluginToolsLine(pluginTools),
|
|
45
|
+
]
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.join("\n\n");
|
|
28
48
|
}
|
|
29
49
|
export function exampleWizard() {
|
|
30
50
|
return JSON.stringify(EXAMPLE_WIZARD, null, 2);
|
|
31
51
|
}
|
|
32
52
|
/** The guide an MCP client reads before it writes a wizard. */
|
|
33
|
-
export function authoringGuide(connectors = [], pluginTools = []) {
|
|
53
|
+
export function authoringGuide(connectors = [], pluginTools = [], connections = []) {
|
|
34
54
|
return prompt("authoring", "guide", {
|
|
35
55
|
schema: prompt("authoring", "schema"),
|
|
36
56
|
principles: prompt("authoring", "principles", { sandbox: sandboxGuideLine() }),
|
|
37
57
|
widgets: prompt("authoring", "widgets"),
|
|
38
58
|
surfaces: prompt("authoring", "surfaces"),
|
|
39
|
-
|
|
59
|
+
space_tools: spaceLines(connectors, pluginTools, connections),
|
|
40
60
|
schema_url: WIZARD_SCHEMA_URL,
|
|
41
61
|
example: exampleWizard(),
|
|
42
62
|
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { and, eq } from "drizzle-orm";
|
|
2
|
+
import { connectorFetch, resolveEnv } from "../connectors/builtin.js";
|
|
3
|
+
import { candidates, connectorFor, open, slot, } from "../connectors/index.js";
|
|
4
|
+
import { refreshThroughAccount } from "../connectors/via-account.js";
|
|
5
|
+
import { db, schema } from "../db/client.js";
|
|
6
|
+
import { refreshAccessToken } from "../engenty/connections-sdk/oauth2.js";
|
|
7
|
+
import { seal, unseal } from "../secrets/crypto.js";
|
|
8
|
+
import { getSecret, putSecret } from "../store/index.js";
|
|
9
|
+
import { currentTenant } from "../tenants/tenant.js";
|
|
10
|
+
/**
|
|
11
|
+
* The account a wizard's connection (or a share target's) holds for this store: the person who
|
|
12
|
+
* runs the wizard connected it. `null` when nothing is connected.
|
|
13
|
+
*/
|
|
14
|
+
export async function wizardAccount(scope, connection, spaceId) {
|
|
15
|
+
const stored = await getSecret(scope, slot(connection.id));
|
|
16
|
+
if (!stored) {
|
|
17
|
+
const only = connection.connector ? (await candidates(connection, spaceId))[0] : undefined;
|
|
18
|
+
return only && open(only)
|
|
19
|
+
? { connector: only, label: only.name, ctx: actionContext(scope, connection, only, "{}", []) }
|
|
20
|
+
: null;
|
|
21
|
+
}
|
|
22
|
+
const connector = await connectorFor(connection, stored.provider, spaceId);
|
|
23
|
+
let data = stored.data;
|
|
24
|
+
const fresh = await refreshed(connector, data);
|
|
25
|
+
if (fresh) {
|
|
26
|
+
data = fresh;
|
|
27
|
+
await putSecret(scope, slot(connection.id), connector.id, stored.label, data);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
connector,
|
|
31
|
+
label: stored.label,
|
|
32
|
+
ctx: actionContext(scope, connection, connector, data.accessToken, data.scopes, stored),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function actionContext(scope, connection, connector, accessToken, scopes, stored) {
|
|
36
|
+
return {
|
|
37
|
+
accessToken,
|
|
38
|
+
fetchImpl: connectorFetch,
|
|
39
|
+
log: () => undefined,
|
|
40
|
+
connection: {
|
|
41
|
+
id: connection.id,
|
|
42
|
+
connector_id: connector.id,
|
|
43
|
+
auth_kind: connector.auth.kind,
|
|
44
|
+
autonomous_mode: "read_only",
|
|
45
|
+
connected_by: null,
|
|
46
|
+
created_at: (stored?.createdAt ?? new Date()).toISOString(),
|
|
47
|
+
display_name: stored?.label ?? connector.name,
|
|
48
|
+
error_message: null,
|
|
49
|
+
external_account: stored?.label ?? null,
|
|
50
|
+
granted_scopes: scopes,
|
|
51
|
+
owner_user_id: null,
|
|
52
|
+
space_id: null,
|
|
53
|
+
status: "active",
|
|
54
|
+
tenant_id: scope.wizardId,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Fresh tokens where the ones kept run out within five minutes; the same ones else. */
|
|
59
|
+
async function refreshed(connector, data) {
|
|
60
|
+
const expires = data.expiresAt ? Date.parse(data.expiresAt) : null;
|
|
61
|
+
if (connector.auth.kind !== "oauth2" ||
|
|
62
|
+
!data.refreshToken ||
|
|
63
|
+
expires === null ||
|
|
64
|
+
expires - Date.now() >= 5 * 60_000) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const tokens = data.via === "account"
|
|
68
|
+
? await refreshThroughAccount(data.refreshToken)
|
|
69
|
+
: await refreshAccessToken({
|
|
70
|
+
config: connector.auth.oauth2,
|
|
71
|
+
refreshToken: data.refreshToken,
|
|
72
|
+
resolveEnv,
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
...(data.via ? { via: data.via } : {}),
|
|
76
|
+
accessToken: tokens.accessToken,
|
|
77
|
+
refreshToken: tokens.refreshToken ?? data.refreshToken,
|
|
78
|
+
expiresAt: tokens.expiresAt?.toISOString() ?? null,
|
|
79
|
+
scopes: tokens.grantedScopes.length ? tokens.grantedScopes : data.scopes,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** Whose sign-in a `person` connection opens for: a person, an admin, or Goose for its person. */
|
|
83
|
+
const signsInThemselves = (who) => (who.kind === "person" || who.kind === "admin" || who.kind === "goose") && Boolean(who.id);
|
|
84
|
+
/**
|
|
85
|
+
* The account a connection of the space holds for this caller: the space's own sign-in, or the
|
|
86
|
+
* caller's where each person signs in. `null` when nobody has signed in yet. Tokens that run out
|
|
87
|
+
* within five minutes are refreshed and written back.
|
|
88
|
+
*/
|
|
89
|
+
export async function spaceAccount(row, connector, who) {
|
|
90
|
+
let sealed;
|
|
91
|
+
let label;
|
|
92
|
+
let signedInAt;
|
|
93
|
+
let write;
|
|
94
|
+
if (row.signIn === "space") {
|
|
95
|
+
sealed = row.secret;
|
|
96
|
+
label = row.label ?? connector.name;
|
|
97
|
+
signedInAt = row.setUpAt;
|
|
98
|
+
write = (secret) => db
|
|
99
|
+
.update(schema.spaceConnection)
|
|
100
|
+
.set({ secret, updatedAt: new Date() })
|
|
101
|
+
.where(eq(schema.spaceConnection.id, row.id));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (!signsInThemselves(who)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
const own = await db.query.spaceConnectionSignIn.findFirst({
|
|
108
|
+
where: and(eq(schema.spaceConnectionSignIn.connectionId, row.id), eq(schema.spaceConnectionSignIn.userId, who.id)),
|
|
109
|
+
});
|
|
110
|
+
if (!own) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
sealed = own.secret;
|
|
114
|
+
label = own.label;
|
|
115
|
+
signedInAt = own.signedInAt;
|
|
116
|
+
write = (secret) => db
|
|
117
|
+
.update(schema.spaceConnectionSignIn)
|
|
118
|
+
.set({ secret, updatedAt: new Date() })
|
|
119
|
+
.where(and(eq(schema.spaceConnectionSignIn.connectionId, row.id), eq(schema.spaceConnectionSignIn.userId, own.userId)));
|
|
120
|
+
}
|
|
121
|
+
if (!sealed) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
let data = unseal(sealed);
|
|
125
|
+
if (!data) {
|
|
126
|
+
throw new Error("The connection's keys cannot be read here. Sign in again.");
|
|
127
|
+
}
|
|
128
|
+
const fresh = await refreshed(connector, data);
|
|
129
|
+
if (fresh) {
|
|
130
|
+
data = fresh;
|
|
131
|
+
await write(seal(data));
|
|
132
|
+
}
|
|
133
|
+
const ctx = {
|
|
134
|
+
accessToken: data.accessToken,
|
|
135
|
+
fetchImpl: connectorFetch,
|
|
136
|
+
log: () => undefined,
|
|
137
|
+
connection: {
|
|
138
|
+
id: row.id,
|
|
139
|
+
connector_id: connector.id,
|
|
140
|
+
auth_kind: connector.auth.kind,
|
|
141
|
+
autonomous_mode: "read_only",
|
|
142
|
+
connected_by: row.setUpBy,
|
|
143
|
+
created_at: signedInAt.toISOString(),
|
|
144
|
+
display_name: row.name,
|
|
145
|
+
error_message: null,
|
|
146
|
+
external_account: label,
|
|
147
|
+
granted_scopes: data.scopes,
|
|
148
|
+
owner_user_id: null,
|
|
149
|
+
space_id: row.spaceId,
|
|
150
|
+
status: "active",
|
|
151
|
+
tenant_id: currentTenant(),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
return { connector, ctx, label };
|
|
155
|
+
}
|
|
156
|
+
/** „Letzte Nutzung“: the connection was just used. */
|
|
157
|
+
export async function markUsed(row) {
|
|
158
|
+
await db
|
|
159
|
+
.update(schema.spaceConnection)
|
|
160
|
+
.set({ lastUsedAt: new Date() })
|
|
161
|
+
.where(eq(schema.spaceConnection.id, row.id));
|
|
162
|
+
}
|
|
163
|
+
/** A secret of a store that is no connection: the browser's kept sign-ins. */
|
|
164
|
+
export function keptSecret(scope, slot) {
|
|
165
|
+
return getSecret(scope, slot);
|
|
166
|
+
}
|
|
@@ -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
|
+
}
|