@engenty/wizards-runtime 0.13.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +101 -67
- package/apps/runtime/dist/agents/website.js +1 -1
- package/apps/runtime/dist/app.js +17 -1
- 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/db/adopt.js +3 -3
- package/apps/runtime/dist/db/client.js +26 -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/{0027_space_skill.sql → 0030_space_skill.sql} +8 -8
- 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 +40 -5
- 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/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 +16 -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/resources.js +43 -12
- package/apps/runtime/dist/engine/runner.js +75 -23
- package/apps/runtime/dist/engine/steps.js +30 -12
- package/apps/runtime/dist/engine/template.js +18 -1
- package/apps/runtime/dist/env.js +9 -4
- package/apps/runtime/dist/index.js +18 -2
- 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 +7 -0
- package/apps/runtime/dist/mcp/flow-app.js +1 -1
- package/apps/runtime/dist/mcp/tools.js +75 -34
- package/apps/runtime/dist/models.js +1 -1
- package/apps/runtime/dist/motion-graphics/project.js +8 -8
- 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 +7 -7
- package/apps/runtime/dist/prompts/mcp.md +6 -6
- package/apps/runtime/dist/prompts/services.md +4 -4
- package/apps/runtime/dist/prompts/step.md +2 -2
- 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/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 +54 -33
- package/apps/runtime/dist/routes/skills.js +6 -6
- package/apps/runtime/dist/routes/studio.js +153 -144
- package/apps/runtime/dist/routes/work.js +199 -0
- 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 +74 -7
- 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 +7 -7
- 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 +23 -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 -612
- 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 +38 -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 +28 -13
- 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-SpDcn8VZ.js +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-Bgnm_3dk.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-SwyId00t.js → ChangelogDialog-DAnjV6cZ.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BwZsk5Al.js → CodeEditor-nxoOt8ge.js} +1 -1
- package/apps/web/dist/assets/EditorPage-B98C-9Nv.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DtSpjVTl.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-D8IYLg_S.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-DlBt0Mfq.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
- package/apps/web/dist/assets/PreviewPane-DC1kAi3x.js +9 -0
- package/apps/web/dist/assets/PublicRunner-D6lKP0j8.js +1 -0
- package/apps/web/dist/assets/ReadOnly-DFsuKPCw.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DkHeCO2c.js +2 -0
- package/apps/web/dist/assets/SetupPage-DZ8xRkfS.js +1 -0
- package/apps/web/dist/assets/SharePage-494ZPsjQ.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-CWlU_BZP.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-BKNkNJyG.js +2 -0
- package/apps/web/dist/assets/changelog-BhMZS-rs.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-TwKzzMtA.js → code-xml-B4kLFZSj.js} +1 -1
- package/apps/web/dist/assets/connection-sign-in-Cngd_QDO.js +1 -0
- package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
- package/apps/web/dist/assets/{eye-Brd-xPUJ.js → eye-BpoKpIdt.js} +1 -1
- package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
- package/apps/web/dist/assets/host-C0WQlRKB.js +118 -0
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
- package/apps/web/dist/assets/index-ClVtdDUZ.js +10 -0
- package/apps/web/dist/assets/index-D18DvnxX.css +1 -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-DhkHteoJ.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-G-XYaDgR.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-BCau3f6O.js +11 -0
- package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
- package/apps/web/dist/assets/{upload-BYZTwJTD.js → upload-BchUnQGV.js} +1 -1
- package/apps/web/dist/assets/{useMutation-D0QP_k2-.js → useMutation-DEkZhp5c.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CVHoxdGM.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 +6 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +6 -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 +150 -8
- package/node_modules/@engenty/wizards-shared/dist/definition.js +46 -11
- 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 +26 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +26 -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.js +3 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -6
- package/node_modules/@engenty/wizards-shared/dist/run.js +85 -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/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-B-JxkELB.js +0 -1
- package/apps/web/dist/assets/EditorPage-DQ_2FOzI.js +0 -3
- package/apps/web/dist/assets/Marketplace-DoH4YO3D.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-Tgoexgj4.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-B24AF482.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-BEvq4slJ.js +0 -1
- package/apps/web/dist/assets/PreviewPane-B_v7Y8R7.js +0 -10
- package/apps/web/dist/assets/ProjectPage-ClRuhFJo.js +0 -10
- package/apps/web/dist/assets/PublicRunner-MicrpVsv.js +0 -1
- package/apps/web/dist/assets/ReadOnly-BXjv-MSv.js +0 -1
- package/apps/web/dist/assets/SettingsPage-DY8O1r43.js +0 -2
- package/apps/web/dist/assets/SetupPage-BOVkVpMu.js +0 -1
- package/apps/web/dist/assets/SharePage-DXGzJSnR.js +0 -1
- package/apps/web/dist/assets/SkillEditor-BzzTDeaU.js +0 -1
- package/apps/web/dist/assets/changelog-BLdS-0Bj.js +0 -1
- package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
- package/apps/web/dist/assets/i18n-8-Sw11tB.js +0 -55
- package/apps/web/dist/assets/index-OsdQFHmh.js +0 -49
- package/apps/web/dist/assets/index-QPipX5Fi.css +0 -1
- package/apps/web/dist/assets/lock-C0uxcOlq.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-BWI-KENJ.js +0 -2
- package/apps/web/dist/assets/theme-D7krsx0_.js +0 -11
- package/apps/web/dist/assets/ui-DSXG3f49.js +0 -83
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { and, eq, gte, notLike } from "drizzle-orm";
|
|
2
|
+
import { db, schema } from "../db/client.js";
|
|
3
|
+
import { summarizeInput, writeLog } from "./log.js";
|
|
4
|
+
/*
|
|
5
|
+
* Sends from a guest's run (docs/plans/capabilities.md, A6; rule 7 of the connections plan): a
|
|
6
|
+
* mail leaves only for an address the run itself collected — what the person typed into a page
|
|
7
|
+
* field of kind `email` — or for an address in one of the space's own mail domains. A run sends a
|
|
8
|
+
* few, a wizard's guests a number per day the wizard sets. Everything beyond is refused and
|
|
9
|
+
* logged as critical. Members' runs are not bound: they send as they always did.
|
|
10
|
+
*/
|
|
11
|
+
/** Mails one guest's run sends, from any address. */
|
|
12
|
+
export const GUEST_MAILS_PER_RUN = 3;
|
|
13
|
+
const ADDRESS = /^[^\s@<>,;]+@[^\s@<>,;]+\.[^\s@<>,;]+$/;
|
|
14
|
+
/** The addresses a send's input names: `to`, `cc`, `bcc`, `recipients`, as strings, lists or objects. */
|
|
15
|
+
export function recipientsOf(input) {
|
|
16
|
+
if (!input || typeof input !== "object") {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const found = new Set();
|
|
20
|
+
const take = (value) => {
|
|
21
|
+
if (typeof value === "string") {
|
|
22
|
+
for (const part of value.split(/[\s,;]+/)) {
|
|
23
|
+
const address = part
|
|
24
|
+
.replace(/^.*<|>$/g, "")
|
|
25
|
+
.trim()
|
|
26
|
+
.toLowerCase();
|
|
27
|
+
if (address) {
|
|
28
|
+
found.add(address);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (Array.isArray(value)) {
|
|
33
|
+
value.forEach(take);
|
|
34
|
+
}
|
|
35
|
+
else if (value && typeof value === "object") {
|
|
36
|
+
const o = value;
|
|
37
|
+
take(o.email ?? o.address ?? o.emailAddress);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
for (const key of ["to", "cc", "bcc", "recipients", "recipient"]) {
|
|
41
|
+
take(input[key]);
|
|
42
|
+
}
|
|
43
|
+
return [...found];
|
|
44
|
+
}
|
|
45
|
+
/** The domain of an address, lower case; null for what is no address. */
|
|
46
|
+
const domainOf = (address) => ADDRESS.test(address) ? address.slice(address.lastIndexOf("@") + 1).toLowerCase() : null;
|
|
47
|
+
/**
|
|
48
|
+
* The addresses a run collected: what its page fields of kind `email` hold. Nothing confirms an
|
|
49
|
+
* address today, so the field's value counts as the run's own.
|
|
50
|
+
*/
|
|
51
|
+
export function runAddresses(run) {
|
|
52
|
+
const own = new Set();
|
|
53
|
+
for (const step of run.definition.steps) {
|
|
54
|
+
if (step.type !== "page") {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
for (const field of step.fields ?? []) {
|
|
58
|
+
const value = run.state.values[field.id];
|
|
59
|
+
if (field.kind === "email" && typeof value === "string" && ADDRESS.test(value.trim())) {
|
|
60
|
+
own.add(value.trim().toLowerCase());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...own];
|
|
65
|
+
}
|
|
66
|
+
/** Whether an address is in one of the space's mail domains, or below one. */
|
|
67
|
+
export function inMailDomains(address, domains) {
|
|
68
|
+
const domain = domainOf(address);
|
|
69
|
+
return (!!domain &&
|
|
70
|
+
domains.some((d) => {
|
|
71
|
+
const own = d.trim().toLowerCase();
|
|
72
|
+
return own && (domain === own || domain.endsWith(`.${own}`));
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
/** Today's first moment, as the per-day count sees it. */
|
|
76
|
+
const startOfToday = () => {
|
|
77
|
+
const now = new Date();
|
|
78
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
|
|
79
|
+
};
|
|
80
|
+
/** How many mails guests sent through this run, and through this wizard today. */
|
|
81
|
+
async function guestMailsSent(where) {
|
|
82
|
+
// Mails only: a request to a host is a send too, counted nowhere here.
|
|
83
|
+
const sent = and(eq(schema.brokerLog.whoKind, "guest"), eq(schema.brokerLog.kind, "send"), eq(schema.brokerLog.result, "ok"), notLike(schema.brokerLog.connectionId, "host:%"));
|
|
84
|
+
const [inRun, today] = await Promise.all([
|
|
85
|
+
where.runId
|
|
86
|
+
? db.$count(schema.brokerLog, and(sent, eq(schema.brokerLog.runId, where.runId)))
|
|
87
|
+
: 0,
|
|
88
|
+
where.wizardId
|
|
89
|
+
? db.$count(schema.brokerLog, and(sent, eq(schema.brokerLog.wizardId, where.wizardId), gte(schema.brokerLog.at, startOfToday())))
|
|
90
|
+
: 0,
|
|
91
|
+
]);
|
|
92
|
+
return { run: inRun, day: today };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Whether a guest's run may send to these addresses now: each one the run's own or in the space's
|
|
96
|
+
* domains, and the run and the wizard under their caps. The run, the wizard and the space are
|
|
97
|
+
* read here; a run or wizard not known refuses.
|
|
98
|
+
*/
|
|
99
|
+
export async function guestSendCheck(where, recipients) {
|
|
100
|
+
const refuse = (refused, reason) => ({
|
|
101
|
+
ok: false,
|
|
102
|
+
refused,
|
|
103
|
+
reason,
|
|
104
|
+
});
|
|
105
|
+
if (!recipients.length) {
|
|
106
|
+
return refuse("not_allowed_recipient", "The send names no recipient.");
|
|
107
|
+
}
|
|
108
|
+
const run = where.runId
|
|
109
|
+
? await db.query.run.findFirst({
|
|
110
|
+
where: eq(schema.run.id, where.runId),
|
|
111
|
+
columns: { definition: true, state: true, wizardId: true },
|
|
112
|
+
})
|
|
113
|
+
: null;
|
|
114
|
+
if (!run) {
|
|
115
|
+
return refuse("not_allowed_recipient", "The run is not known here.");
|
|
116
|
+
}
|
|
117
|
+
const wizard = await db.query.wizard.findFirst({
|
|
118
|
+
where: eq(schema.wizard.id, run.wizardId),
|
|
119
|
+
columns: { spaceId: true, dailyMailLimit: true },
|
|
120
|
+
});
|
|
121
|
+
const space = wizard
|
|
122
|
+
? await db.query.space.findFirst({
|
|
123
|
+
where: eq(schema.space.id, wizard.spaceId),
|
|
124
|
+
columns: { mailDomains: true },
|
|
125
|
+
})
|
|
126
|
+
: null;
|
|
127
|
+
const own = runAddresses(run);
|
|
128
|
+
const domains = space?.mailDomains ?? [];
|
|
129
|
+
const foreign = recipients.find((address) => !(own.includes(address.toLowerCase()) || inMailDomains(address, domains)));
|
|
130
|
+
if (foreign) {
|
|
131
|
+
return refuse("not_allowed_recipient", `A guest's run sends only to its own address or the space's domains, not to ${foreign}.`);
|
|
132
|
+
}
|
|
133
|
+
const sent = await guestMailsSent({ ...where, wizardId: where.wizardId ?? run.wizardId });
|
|
134
|
+
if (sent.run >= GUEST_MAILS_PER_RUN) {
|
|
135
|
+
return refuse("run_limit", `This run has sent its ${GUEST_MAILS_PER_RUN} mails.`);
|
|
136
|
+
}
|
|
137
|
+
const perDay = wizard?.dailyMailLimit ?? 50;
|
|
138
|
+
if (sent.day >= perDay) {
|
|
139
|
+
return refuse("day_limit", `This wizard's guests have sent today's ${perDay} mails.`);
|
|
140
|
+
}
|
|
141
|
+
return { ok: true };
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* A mail from the server's own address, which no account holds: the one send that is not a
|
|
145
|
+
* connector's action. A guest's run is bound by the rules above; the call is logged like any
|
|
146
|
+
* other, under the connection `mail:server`.
|
|
147
|
+
*/
|
|
148
|
+
export async function brokerSend(call) {
|
|
149
|
+
const started = Date.now();
|
|
150
|
+
const { who, where } = call;
|
|
151
|
+
const line = (outcome, reason, result) => writeLog({
|
|
152
|
+
at: new Date(started),
|
|
153
|
+
durationMs: Date.now() - started,
|
|
154
|
+
whoKind: who.kind,
|
|
155
|
+
whoId: who.id ?? null,
|
|
156
|
+
runId: where.runId ?? null,
|
|
157
|
+
stepId: where.stepId ?? null,
|
|
158
|
+
chatId: where.chatId ?? null,
|
|
159
|
+
wizardId: where.wizardId ?? null,
|
|
160
|
+
spaceId: where.spaceId ?? null,
|
|
161
|
+
connectionId: "mail:server",
|
|
162
|
+
actionId: "send_message",
|
|
163
|
+
kind: "send",
|
|
164
|
+
inputSummary: summarizeInput(call.input),
|
|
165
|
+
outcome,
|
|
166
|
+
rule: "guest_send",
|
|
167
|
+
reason,
|
|
168
|
+
result,
|
|
169
|
+
resultSize: null,
|
|
170
|
+
});
|
|
171
|
+
let reason = "The server's address sends for members.";
|
|
172
|
+
if (where.guest) {
|
|
173
|
+
const check = await guestSendCheck(where, call.recipients);
|
|
174
|
+
if (!check.ok) {
|
|
175
|
+
await line("deny", check.reason, check.refused);
|
|
176
|
+
return check;
|
|
177
|
+
}
|
|
178
|
+
reason = "The recipients are the run's own or the space's.";
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const result = await call.handler();
|
|
182
|
+
await line("allow", reason, "ok");
|
|
183
|
+
return { ok: true, result };
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
await line("allow", reason, err instanceof Error ? err.constructor.name || "Error" : "Error");
|
|
187
|
+
throw err;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -17,7 +17,7 @@ import { smtpConnector } from "./smtp.js";
|
|
|
17
17
|
import { googleThroughAccount } from "./via-account.js";
|
|
18
18
|
/**
|
|
19
19
|
* engenty's own connectors, as engenty ships them: Gmail, Drive, Calendar, Contacts, Outlook,
|
|
20
|
-
* OneDrive, Slack, GitHub, HubSpot, S3 — and SMTP, for sending from any mailbox. Every
|
|
20
|
+
* OneDrive, Slack, GitHub, HubSpot, S3 — and SMTP, for sending from any mailbox. Every space
|
|
21
21
|
* has them; an OAuth one can be connected once its client is configured.
|
|
22
22
|
*/
|
|
23
23
|
export const BUILTIN_CONNECTORS = [
|
|
@@ -5,12 +5,13 @@ import { db, schema } from "../db/client.js";
|
|
|
5
5
|
import { buildImportedConnector, mcpHeaders, } from "../engenty/connections-external/build-connector.js";
|
|
6
6
|
import { ImportValidationError } from "../engenty/connections-external/errors.js";
|
|
7
7
|
import { assembleRecord, connectorIdFromSlug, prepareSource, resolveRequiredHeaders, surfaceRequiresAuth, toolPrefixFromSlug, } from "../engenty/connections-external/import-service.js";
|
|
8
|
+
import { groupOf } from "../engenty/connections-external/importer/classify.js";
|
|
8
9
|
import { createGuardedFetch } from "../engenty/connections-external/net/guarded-fetch.js";
|
|
9
10
|
import { discoverImportableSources, discoverOAuthFacts, registryDiscover, registrySearch, resolveMcpTransport, } from "../engenty/connections-external/registry-client.js";
|
|
10
11
|
import { resolveRegistrySource } from "../engenty/connections-external/registry-source.js";
|
|
11
12
|
import { encryptToken } from "../engenty/shims/connections-sdk.js";
|
|
12
13
|
import { env } from "../env.js";
|
|
13
|
-
import { requireAdmin,
|
|
14
|
+
import { requireAdmin, requireWritableSpace } from "../services/access.js";
|
|
14
15
|
import { ServiceError } from "../services/errors.js";
|
|
15
16
|
import { BUILTIN_CONNECTORS, builtinConnector, missingSetup, usable } from "./builtin.js";
|
|
16
17
|
/**
|
|
@@ -22,24 +23,24 @@ import { BUILTIN_CONNECTORS, builtinConnector, missingSetup, usable } from "./bu
|
|
|
22
23
|
// engenty's dynamic client registration reads the redirect from this variable.
|
|
23
24
|
process.env.CONNECTIONS_REDIRECT_URI ??=
|
|
24
25
|
env.connectRedirectUrl || `${env.appUrl}/api/connect/callback`;
|
|
25
|
-
const where = (
|
|
26
|
-
async function load(
|
|
27
|
-
const row = await db.query.
|
|
26
|
+
const where = (spaceId, id) => and(eq(schema.spaceConnector.spaceId, spaceId), eq(schema.spaceConnector.id, id));
|
|
27
|
+
async function load(spaceId, id) {
|
|
28
|
+
const row = await db.query.spaceConnector.findFirst({ where: where(spaceId, id) });
|
|
28
29
|
return row?.record ?? null;
|
|
29
30
|
}
|
|
30
|
-
async function save(
|
|
31
|
+
async function save(spaceId, record) {
|
|
31
32
|
await db
|
|
32
|
-
.insert(schema.
|
|
33
|
-
.values({
|
|
33
|
+
.insert(schema.spaceConnector)
|
|
34
|
+
.values({ spaceId, id: record.id, record })
|
|
34
35
|
.onConflictDoUpdate({
|
|
35
|
-
target: [schema.
|
|
36
|
+
target: [schema.spaceConnector.spaceId, schema.spaceConnector.id],
|
|
36
37
|
set: { record, updatedAt: new Date() },
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
const actionView = (a) => ({
|
|
40
41
|
id: a.id,
|
|
41
42
|
summary: (a.summary || a.description).slice(0, 160),
|
|
42
|
-
group: a
|
|
43
|
+
group: groupOf(a),
|
|
43
44
|
});
|
|
44
45
|
function view(record) {
|
|
45
46
|
const auth = record.auth_config;
|
|
@@ -206,7 +207,7 @@ export async function previewSource(input) {
|
|
|
206
207
|
toolsPending: prepared.deferred_mcp_tools === true,
|
|
207
208
|
};
|
|
208
209
|
}
|
|
209
|
-
// --- a
|
|
210
|
+
// --- a space's connectors --------------------------------------------------------
|
|
210
211
|
async function builtinView(connector) {
|
|
211
212
|
const ready = await usable(connector);
|
|
212
213
|
return {
|
|
@@ -230,11 +231,11 @@ async function builtinView(connector) {
|
|
|
230
231
|
refreshedAt: null,
|
|
231
232
|
};
|
|
232
233
|
}
|
|
233
|
-
/** Every connector a wizard of the
|
|
234
|
-
export async function listConnectors(
|
|
235
|
-
const rows = await db.query.
|
|
236
|
-
where: eq(schema.
|
|
237
|
-
orderBy: [asc(schema.
|
|
234
|
+
/** Every connector a wizard of the space can name: the built-in ones, then its imports. */
|
|
235
|
+
export async function listConnectors(spaceId) {
|
|
236
|
+
const rows = await db.query.spaceConnector.findMany({
|
|
237
|
+
where: eq(schema.spaceConnector.spaceId, spaceId),
|
|
238
|
+
orderBy: [asc(schema.spaceConnector.createdAt)],
|
|
238
239
|
});
|
|
239
240
|
return [
|
|
240
241
|
...(await Promise.all(BUILTIN_CONNECTORS.map(builtinView))),
|
|
@@ -243,9 +244,9 @@ export async function listConnectors(projectId) {
|
|
|
243
244
|
}
|
|
244
245
|
/**
|
|
245
246
|
* A connector by id, ready to run, with the JSON schema of each action's input: a built-in one,
|
|
246
|
-
* or one the
|
|
247
|
+
* or one the space imported.
|
|
247
248
|
*/
|
|
248
|
-
export async function resolveConnector(
|
|
249
|
+
export async function resolveConnector(spaceId, id) {
|
|
249
250
|
const builtin = builtinConnector(id);
|
|
250
251
|
if (builtin) {
|
|
251
252
|
return {
|
|
@@ -262,7 +263,7 @@ export async function resolveConnector(projectId, id) {
|
|
|
262
263
|
},
|
|
263
264
|
};
|
|
264
265
|
}
|
|
265
|
-
const found = await importedConnector(
|
|
266
|
+
const found = await importedConnector(spaceId, id);
|
|
266
267
|
return found
|
|
267
268
|
? {
|
|
268
269
|
connector: found.connector,
|
|
@@ -271,10 +272,10 @@ export async function resolveConnector(projectId, id) {
|
|
|
271
272
|
}
|
|
272
273
|
: null;
|
|
273
274
|
}
|
|
274
|
-
export async function importConnector(userId,
|
|
275
|
-
await
|
|
275
|
+
export async function importConnector(userId, spaceId, input) {
|
|
276
|
+
await requireWritableSpace(spaceId);
|
|
276
277
|
await requireAdmin();
|
|
277
|
-
if (await load(
|
|
278
|
+
if (await load(spaceId, input.id)) {
|
|
278
279
|
throw new ServiceError("invalid", note("connectorAlreadyExistsSpace", { id: input.id }));
|
|
279
280
|
}
|
|
280
281
|
try {
|
|
@@ -295,14 +296,14 @@ export async function importConnector(userId, projectId, input) {
|
|
|
295
296
|
sourceKind: input.sourceKind,
|
|
296
297
|
sourceUrl: input.sourceUrl,
|
|
297
298
|
surface,
|
|
298
|
-
tenantId:
|
|
299
|
+
tenantId: spaceId,
|
|
299
300
|
toolPrefix: input.toolPrefix,
|
|
300
301
|
});
|
|
301
302
|
const { skippedActions } = buildImportedConnector(record);
|
|
302
303
|
if (skippedActions.length) {
|
|
303
304
|
warnings.push(`${skippedActions.length} action(s) have an input the tools cannot express`);
|
|
304
305
|
}
|
|
305
|
-
await save(
|
|
306
|
+
await save(spaceId, record);
|
|
306
307
|
return { connector: view(record), warnings };
|
|
307
308
|
}
|
|
308
309
|
catch (err) {
|
|
@@ -314,8 +315,8 @@ export async function importConnector(userId, projectId, input) {
|
|
|
314
315
|
* architect, MCP clients): the first importable source of the wanted kind, MCP before OpenAPI —
|
|
315
316
|
* an MCP server is the service's own, curated set of actions.
|
|
316
317
|
*/
|
|
317
|
-
export async function importFromRegistry(userId,
|
|
318
|
-
await
|
|
318
|
+
export async function importFromRegistry(userId, spaceId, input) {
|
|
319
|
+
await requireWritableSpace(spaceId);
|
|
319
320
|
await requireAdmin();
|
|
320
321
|
const service = await registryService(input.domain);
|
|
321
322
|
const order = input.kind ? [input.kind] : ["mcp", "openapi"];
|
|
@@ -326,11 +327,11 @@ export async function importFromRegistry(userId, projectId, input) {
|
|
|
326
327
|
const why = service.sources.map((s) => `${s.sourceKind}: ${s.blocked}`).join("; ");
|
|
327
328
|
throw new ServiceError("invalid", `${input.domain} has nothing that can be imported${why ? ` (${why})` : ""}.`);
|
|
328
329
|
}
|
|
329
|
-
const taken = (await listConnectors(
|
|
330
|
+
const taken = (await listConnectors(spaceId)).find((c) => c.id === source.suggestedId);
|
|
330
331
|
if (taken) {
|
|
331
332
|
return { connector: taken, warnings: ["already imported"] };
|
|
332
333
|
}
|
|
333
|
-
return importConnector(userId,
|
|
334
|
+
return importConnector(userId, spaceId, {
|
|
334
335
|
domain: service.domain,
|
|
335
336
|
sourceKind: source.sourceKind,
|
|
336
337
|
sourceUrl: source.sourceUrl,
|
|
@@ -339,18 +340,18 @@ export async function importFromRegistry(userId, projectId, input) {
|
|
|
339
340
|
...(source.name ? { name: source.name } : {}),
|
|
340
341
|
});
|
|
341
342
|
}
|
|
342
|
-
export async function removeConnector(
|
|
343
|
-
await
|
|
343
|
+
export async function removeConnector(spaceId, id) {
|
|
344
|
+
await requireWritableSpace(spaceId);
|
|
344
345
|
await requireAdmin();
|
|
345
|
-
await db.delete(schema.
|
|
346
|
+
await db.delete(schema.spaceConnector).where(where(spaceId, id));
|
|
346
347
|
}
|
|
347
348
|
/**
|
|
348
349
|
* Re-reads the source and replaces the connector's actions. An MCP server that only lists its
|
|
349
350
|
* tools to a signed-in account needs that account's token.
|
|
350
351
|
*/
|
|
351
|
-
export async function refreshConnector(
|
|
352
|
-
await
|
|
353
|
-
const record = await load(
|
|
352
|
+
export async function refreshConnector(spaceId, id, accessToken) {
|
|
353
|
+
await requireWritableSpace(spaceId);
|
|
354
|
+
const record = await load(spaceId, id);
|
|
354
355
|
if (!record) {
|
|
355
356
|
throw new ServiceError("not_found", note("connectorNotExist"));
|
|
356
357
|
}
|
|
@@ -382,7 +383,7 @@ export async function refreshConnector(projectId, id, accessToken) {
|
|
|
382
383
|
required_headers: requiredHeaders,
|
|
383
384
|
spec_hash: prepared.spec_hash,
|
|
384
385
|
};
|
|
385
|
-
await save(
|
|
386
|
+
await save(spaceId, updated);
|
|
386
387
|
return view(updated);
|
|
387
388
|
}
|
|
388
389
|
catch (err) {
|
|
@@ -390,8 +391,8 @@ export async function refreshConnector(projectId, id, accessToken) {
|
|
|
390
391
|
}
|
|
391
392
|
}
|
|
392
393
|
/** The connector as engenty's framework runs it: actions with handlers, auth with its flows. */
|
|
393
|
-
export async function importedConnector(
|
|
394
|
-
const record = await load(
|
|
394
|
+
export async function importedConnector(spaceId, id) {
|
|
395
|
+
const record = await load(spaceId, id);
|
|
395
396
|
if (!record) {
|
|
396
397
|
return null;
|
|
397
398
|
}
|
|
@@ -403,7 +404,7 @@ export async function importedConnector(projectId, id) {
|
|
|
403
404
|
client_id_enc: encryptToken(client.clientId),
|
|
404
405
|
client_secret_enc: client.clientSecret ? encryptToken(client.clientSecret) : null,
|
|
405
406
|
};
|
|
406
|
-
await save(
|
|
407
|
+
await save(spaceId, current);
|
|
407
408
|
});
|
|
408
409
|
return { connector, record };
|
|
409
410
|
}
|
|
@@ -2,16 +2,16 @@ import { isLang } from "@engenty/wizards-shared/definition";
|
|
|
2
2
|
import { note } from "@engenty/wizards-shared/run";
|
|
3
3
|
import { eq } from "drizzle-orm";
|
|
4
4
|
import { db, schema } from "../db/client.js";
|
|
5
|
-
import { buildAuthorizationUrl, createOAuth2Pkce, exchangeAuthorizationCode,
|
|
6
|
-
import { scopesForGroups
|
|
5
|
+
import { buildAuthorizationUrl, createOAuth2Pkce, exchangeAuthorizationCode, } from "../engenty/connections-sdk/oauth2.js";
|
|
6
|
+
import { scopesForGroups } from "../engenty/connections-sdk/types.js";
|
|
7
7
|
import { env } from "../env.js";
|
|
8
8
|
import { NotedError } from "../model-errors.js";
|
|
9
9
|
import { seal, unseal } from "../secrets/crypto.js";
|
|
10
|
-
import { deleteSecret,
|
|
10
|
+
import { deleteSecret, peekSecret, putSecret } from "../store/index.js";
|
|
11
11
|
import { serverText } from "../texts.js";
|
|
12
12
|
import { connectorFetch, MAIL_CONNECTORS, resolveEnv, usable, viaAccount } from "./builtin.js";
|
|
13
13
|
import { resolveConnector } from "./external.js";
|
|
14
|
-
import { AccountConnectError, redeemTicket,
|
|
14
|
+
import { AccountConnectError, redeemTicket, startThroughAccount } from "./via-account.js";
|
|
15
15
|
/** The connectors a person can pick for each kind of connection. */
|
|
16
16
|
const CONNECTORS = { mail: MAIL_CONNECTORS };
|
|
17
17
|
const HINTS = { imap: "imapHint", smtp: "imapHint" };
|
|
@@ -51,13 +51,13 @@ export function registerConnectionSource(source) {
|
|
|
51
51
|
sources.push(source);
|
|
52
52
|
}
|
|
53
53
|
/** A connection of a run by id: one the wizard declares, or one of a share target. */
|
|
54
|
-
export async function findConnection(run, connectionId,
|
|
54
|
+
export async function findConnection(run, connectionId, spaceId) {
|
|
55
55
|
const declared = run.definition.connections?.find((c) => c.id === connectionId);
|
|
56
56
|
if (declared) {
|
|
57
57
|
return declared;
|
|
58
58
|
}
|
|
59
59
|
for (const source of sources) {
|
|
60
|
-
const found = await source(run, connectionId,
|
|
60
|
+
const found = await source(run, connectionId, spaceId);
|
|
61
61
|
if (found) {
|
|
62
62
|
return found;
|
|
63
63
|
}
|
|
@@ -68,27 +68,28 @@ export async function findConnection(run, connectionId, projectId) {
|
|
|
68
68
|
export function connectRedirectUri() {
|
|
69
69
|
return env.connectRedirectUrl || `${env.appUrl}/api/connect/callback`;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
/** The store slot of a connection's account. */
|
|
72
|
+
export const slot = (connectionId) => `connection:${connectionId}`;
|
|
72
73
|
/** A connector that needs no credential: there is nothing for the person to connect. */
|
|
73
|
-
const open = (connector) => connector.auth.kind === "api_key" && connector.auth.apiKey.fields.length === 0;
|
|
74
|
+
export const open = (connector) => connector.auth.kind === "api_key" && connector.auth.apiKey.fields.length === 0;
|
|
74
75
|
/**
|
|
75
76
|
* The connectors behind a connection: the built-in ones of its kind, the one it names, or the
|
|
76
77
|
* ones a share target lets the person pick from.
|
|
77
78
|
*/
|
|
78
|
-
async function candidates(connection,
|
|
79
|
+
export async function candidates(connection, spaceId) {
|
|
79
80
|
if (connection.target) {
|
|
80
|
-
const found = await Promise.all(connection.target.connectors.map((id) => resolveConnector(
|
|
81
|
+
const found = await Promise.all(connection.target.connectors.map((id) => resolveConnector(spaceId, id)));
|
|
81
82
|
return found.flatMap((f) => (f ? [f.connector] : []));
|
|
82
83
|
}
|
|
83
84
|
if (connection.connector) {
|
|
84
|
-
const found = await resolveConnector(
|
|
85
|
+
const found = await resolveConnector(spaceId, connection.connector);
|
|
85
86
|
return found ? [found.connector] : [];
|
|
86
87
|
}
|
|
87
88
|
return connection.kind ? CONNECTORS[connection.kind] : [];
|
|
88
89
|
}
|
|
89
|
-
export async function connectorOptions(connection,
|
|
90
|
+
export async function connectorOptions(connection, spaceId, lang = "en") {
|
|
90
91
|
const out = [];
|
|
91
|
-
for (const c of await candidates(connection,
|
|
92
|
+
for (const c of await candidates(connection, spaceId)) {
|
|
92
93
|
if (!(await usable(c))) {
|
|
93
94
|
continue;
|
|
94
95
|
}
|
|
@@ -107,19 +108,19 @@ export async function connectorOptions(connection, projectId, lang = "en") {
|
|
|
107
108
|
}
|
|
108
109
|
return out;
|
|
109
110
|
}
|
|
110
|
-
async function connectorFor(connection, connectorId,
|
|
111
|
-
const connector = (await candidates(connection,
|
|
111
|
+
export async function connectorFor(connection, connectorId, spaceId) {
|
|
112
|
+
const connector = (await candidates(connection, spaceId)).find((c) => c.id === connectorId);
|
|
112
113
|
if (!connector) {
|
|
113
114
|
throw new Error(`Unknown connector "${connectorId}".`);
|
|
114
115
|
}
|
|
115
116
|
return connector;
|
|
116
117
|
}
|
|
117
|
-
export async function connectionViews(connections, scope,
|
|
118
|
+
export async function connectionViews(connections, scope, spaceId,
|
|
118
119
|
/** The language the person reads the connectors' fields in. */
|
|
119
120
|
lang = "en") {
|
|
120
121
|
return Promise.all(connections.map(async (c) => {
|
|
121
|
-
const stored = await
|
|
122
|
-
const only = c.connector ? (await candidates(c,
|
|
122
|
+
const stored = await peekSecret(scope, slot(c.id));
|
|
123
|
+
const only = c.connector ? (await candidates(c, spaceId))[0] : undefined;
|
|
123
124
|
return {
|
|
124
125
|
id: c.id,
|
|
125
126
|
kind: c.kind ?? null,
|
|
@@ -135,12 +136,12 @@ lang = "en") {
|
|
|
135
136
|
: only && open(only)
|
|
136
137
|
? { connector: only.id, label: only.name, connectedAt: new Date(0).toISOString() }
|
|
137
138
|
: null,
|
|
138
|
-
connectors: await connectorOptions(c,
|
|
139
|
+
connectors: await connectorOptions(c, spaceId, lang),
|
|
139
140
|
};
|
|
140
141
|
}));
|
|
141
142
|
}
|
|
142
|
-
export async function startOAuth(scope,
|
|
143
|
-
const connector = await connectorFor(connection, connectorId,
|
|
143
|
+
export async function startOAuth(scope, spaceId, runId, connection, connectorId, lang) {
|
|
144
|
+
const connector = await connectorFor(connection, connectorId, spaceId);
|
|
144
145
|
if (connector.auth.kind !== "oauth2") {
|
|
145
146
|
throw new Error(`${connector.name} is not connected by signing in.`);
|
|
146
147
|
}
|
|
@@ -148,7 +149,7 @@ export async function startOAuth(scope, projectId, runId, connection, connectorI
|
|
|
148
149
|
// The Manage-App keeps the PKCE verifier; ours stays empty.
|
|
149
150
|
const state = {
|
|
150
151
|
scope,
|
|
151
|
-
|
|
152
|
+
spaceId,
|
|
152
153
|
runId,
|
|
153
154
|
connectionId: connection.id,
|
|
154
155
|
connectorId,
|
|
@@ -168,7 +169,7 @@ export async function startOAuth(scope, projectId, runId, connection, connectorI
|
|
|
168
169
|
const pkce = createOAuth2Pkce();
|
|
169
170
|
const state = {
|
|
170
171
|
scope,
|
|
171
|
-
|
|
172
|
+
spaceId,
|
|
172
173
|
runId,
|
|
173
174
|
connectionId: connection.id,
|
|
174
175
|
connectorId,
|
|
@@ -204,11 +205,11 @@ export async function finishOAuth(answer, rawState) {
|
|
|
204
205
|
throw new Error("The sign-in has expired. Connect again.");
|
|
205
206
|
}
|
|
206
207
|
const run = await db.query.run.findFirst({ where: eq(schema.run.id, state.runId) });
|
|
207
|
-
const connection = run ? await findConnection(run, state.connectionId, state.
|
|
208
|
+
const connection = run ? await findConnection(run, state.connectionId, state.spaceId) : null;
|
|
208
209
|
if (!connection) {
|
|
209
210
|
throw new Error("The run this sign-in belongs to is gone.");
|
|
210
211
|
}
|
|
211
|
-
const connector = await connectorFor(connection, state.connectorId, state.
|
|
212
|
+
const connector = await connectorFor(connection, state.connectorId, state.spaceId);
|
|
212
213
|
if (connector.auth.kind !== "oauth2") {
|
|
213
214
|
throw new Error("not an oauth connector");
|
|
214
215
|
}
|
|
@@ -236,8 +237,8 @@ export async function finishOAuth(answer, rawState) {
|
|
|
236
237
|
return state;
|
|
237
238
|
}
|
|
238
239
|
/** Connects an `api_key` connector with what the person typed; the connector checks it first. */
|
|
239
|
-
export async function connectWithCredentials(scope,
|
|
240
|
-
const connector = await connectorFor(connection, connectorId,
|
|
240
|
+
export async function connectWithCredentials(scope, spaceId, connection, connectorId, values) {
|
|
241
|
+
const connector = await connectorFor(connection, connectorId, spaceId);
|
|
241
242
|
if (connector.auth.kind !== "api_key") {
|
|
242
243
|
throw new Error(`${connector.name} is connected by signing in.`);
|
|
243
244
|
}
|
|
@@ -290,67 +291,5 @@ export function disconnect(scope, connectionId) {
|
|
|
290
291
|
return deleteSecret(scope, slot(connectionId));
|
|
291
292
|
}
|
|
292
293
|
// --- using ---------------------------------------------------------------------
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
* connected — with a fresh access token. `null` when nothing is connected.
|
|
296
|
-
*/
|
|
297
|
-
export async function connectionContext(scope, connection, projectId) {
|
|
298
|
-
const stored = await getSecret(scope, slot(connection.id));
|
|
299
|
-
if (!stored) {
|
|
300
|
-
const only = connection.connector ? (await candidates(connection, projectId))[0] : undefined;
|
|
301
|
-
return only && open(only)
|
|
302
|
-
? { connector: only, label: only.name, ctx: actionContext(scope, connection, only, "{}", []) }
|
|
303
|
-
: null;
|
|
304
|
-
}
|
|
305
|
-
const connector = await connectorFor(connection, stored.provider, projectId);
|
|
306
|
-
let data = stored.data;
|
|
307
|
-
const expires = data.expiresAt ? Date.parse(data.expiresAt) : null;
|
|
308
|
-
if (connector.auth.kind === "oauth2" &&
|
|
309
|
-
data.refreshToken &&
|
|
310
|
-
expires !== null &&
|
|
311
|
-
expires - Date.now() < 5 * 60_000) {
|
|
312
|
-
const tokens = data.via === "account"
|
|
313
|
-
? await refreshThroughAccount(data.refreshToken)
|
|
314
|
-
: await refreshAccessToken({
|
|
315
|
-
config: connector.auth.oauth2,
|
|
316
|
-
refreshToken: data.refreshToken,
|
|
317
|
-
resolveEnv,
|
|
318
|
-
});
|
|
319
|
-
data = {
|
|
320
|
-
...(data.via ? { via: data.via } : {}),
|
|
321
|
-
accessToken: tokens.accessToken,
|
|
322
|
-
refreshToken: tokens.refreshToken ?? data.refreshToken,
|
|
323
|
-
expiresAt: tokens.expiresAt?.toISOString() ?? null,
|
|
324
|
-
scopes: tokens.grantedScopes.length ? tokens.grantedScopes : data.scopes,
|
|
325
|
-
};
|
|
326
|
-
await putSecret(scope, slot(connection.id), connector.id, stored.label, data);
|
|
327
|
-
}
|
|
328
|
-
return {
|
|
329
|
-
connector,
|
|
330
|
-
label: stored.label,
|
|
331
|
-
ctx: actionContext(scope, connection, connector, data.accessToken, data.scopes, stored),
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function actionContext(scope, connection, connector, accessToken, scopes, stored) {
|
|
335
|
-
return {
|
|
336
|
-
accessToken,
|
|
337
|
-
fetchImpl: connectorFetch,
|
|
338
|
-
log: () => undefined,
|
|
339
|
-
connection: {
|
|
340
|
-
id: connection.id,
|
|
341
|
-
connector_id: connector.id,
|
|
342
|
-
auth_kind: connector.auth.kind,
|
|
343
|
-
autonomous_mode: "read_only",
|
|
344
|
-
connected_by: null,
|
|
345
|
-
created_at: (stored?.createdAt ?? new Date()).toISOString(),
|
|
346
|
-
display_name: stored?.label ?? connector.name,
|
|
347
|
-
error_message: null,
|
|
348
|
-
external_account: stored?.label ?? null,
|
|
349
|
-
granted_scopes: scopes,
|
|
350
|
-
owner_user_id: null,
|
|
351
|
-
space_id: null,
|
|
352
|
-
status: "active",
|
|
353
|
-
tenant_id: scope.wizardId,
|
|
354
|
-
},
|
|
355
|
-
};
|
|
356
|
-
}
|
|
294
|
+
// An account is read by the broker alone (`broker/account.ts`): a connector call goes through
|
|
295
|
+
// `brokerCall`, which knows who calls, decides, runs the action and logs it.
|
|
@@ -54,14 +54,6 @@ export function mailActions(backend, providerScopes) {
|
|
|
54
54
|
},
|
|
55
55
|
];
|
|
56
56
|
}
|
|
57
|
-
/** Calls one of a mail connector's actions. */
|
|
58
|
-
export async function mailAction(connector, actionId, input, ctx) {
|
|
59
|
-
const action = connector.actions.find((a) => a.id === actionId);
|
|
60
|
-
if (!action) {
|
|
61
|
-
throw new Error(`${connector.name} has no action "${actionId}".`);
|
|
62
|
-
}
|
|
63
|
-
return (await action.handler(input, ctx));
|
|
64
|
-
}
|
|
65
57
|
export function snippetOf(text, length = 240) {
|
|
66
58
|
return text.replace(/\s+/g, " ").trim().slice(0, length);
|
|
67
59
|
}
|