@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,127 @@
|
|
|
1
|
+
import { and, eq, inArray, isNotNull } from "drizzle-orm";
|
|
2
|
+
import { linkedAccount } from "../auth/account.js";
|
|
3
|
+
import { brokerCall } from "../broker/index.js";
|
|
4
|
+
import { MAIL_SENDERS, sendAsAccount, sendFromServer, serverSender, } from "../connectors/smtp.js";
|
|
5
|
+
import { connectorOfRow } from "../connectors/space-connections.js";
|
|
6
|
+
import { db, schema } from "../db/client.js";
|
|
7
|
+
import { env } from "../env.js";
|
|
8
|
+
import { managed, tenantMembers } from "../manage.js";
|
|
9
|
+
import { currentTenant } from "../tenants/tenant.js";
|
|
10
|
+
import { serverText } from "../texts.js";
|
|
11
|
+
import { isAdminRole } from "./access.js";
|
|
12
|
+
import { criticalOfSpace } from "./broker-bell.js";
|
|
13
|
+
import { anySeenSince } from "./seen.js";
|
|
14
|
+
/**
|
|
15
|
+
* The hourly mail to a space's admins (docs/plans/broker.md, "Notifications"): the broker's
|
|
16
|
+
* critical lines since the last mail, sent only where none of the admins was in the app
|
|
17
|
+
* meanwhile – they saw the bell then. Through the space's own mail connection where one signs in
|
|
18
|
+
* as the space, else from the server's address; where there is neither, nothing goes out. The
|
|
19
|
+
* space's `notify.mail` turns it off.
|
|
20
|
+
*/
|
|
21
|
+
const HOUR_MS = 3600_000;
|
|
22
|
+
/** How many lines one mail carries at most. */
|
|
23
|
+
const LINES = 50;
|
|
24
|
+
/** The tenant's owners and admins: what the Manage-App says; on a computer, the linked account. */
|
|
25
|
+
async function adminsOf() {
|
|
26
|
+
if (managed) {
|
|
27
|
+
const people = await tenantMembers(currentTenant());
|
|
28
|
+
return people.members
|
|
29
|
+
.filter((m) => isAdminRole(m.role) && m.email)
|
|
30
|
+
.map((m) => ({ userId: m.userId, email: m.email }));
|
|
31
|
+
}
|
|
32
|
+
const account = await linkedAccount();
|
|
33
|
+
return account?.email ? [{ userId: account.userId, email: account.email }] : [];
|
|
34
|
+
}
|
|
35
|
+
/** One line of the mail: when, who, what, which rule. */
|
|
36
|
+
function lineOf(row, lang) {
|
|
37
|
+
const at = row.at.toISOString().slice(11, 16);
|
|
38
|
+
const who = row.whoId ? `${row.whoKind} ${row.whoId}` : row.whoKind;
|
|
39
|
+
const kind = serverText(lang, `criticalKind.${row.criticalKind ?? "refused_write"}`);
|
|
40
|
+
const what = `${row.connectionId} · ${row.actionId}`;
|
|
41
|
+
return `${at} ${kind}: ${who} → ${what}${row.reason ? ` – ${row.reason}` : ""}`;
|
|
42
|
+
}
|
|
43
|
+
/** The mail for a space's lines. */
|
|
44
|
+
export function criticalMail(space, rows, to, lang) {
|
|
45
|
+
const shown = rows.slice(0, LINES);
|
|
46
|
+
const lines = shown.map((r) => `- ${lineOf(r, lang)}`).join("\n");
|
|
47
|
+
const more = rows.length > shown.length
|
|
48
|
+
? `\n${serverText(lang, "criticalMailMore", { count: rows.length - shown.length })}`
|
|
49
|
+
: "";
|
|
50
|
+
return {
|
|
51
|
+
to,
|
|
52
|
+
subject: serverText(lang, "criticalMailSubject", { space: space.name, count: rows.length }),
|
|
53
|
+
text: `${serverText(lang, "criticalMailIntro", { space: space.name })}\n\n${lines}${more}\n\n${serverText(lang, "criticalMailOutro", { url: `${env.publicUrl}/work/waiting` })}`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** The space's mail connection the mail goes through: signs in as the space, signed in, a mail sender. */
|
|
57
|
+
async function mailConnectionOf(spaceId) {
|
|
58
|
+
return db.query.spaceConnection.findFirst({
|
|
59
|
+
where: and(eq(schema.spaceConnection.spaceId, spaceId), eq(schema.spaceConnection.signIn, "space"), inArray(schema.spaceConnection.connectorId, [...MAIL_SENDERS]), isNotNull(schema.spaceConnection.secret)),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** Sends through the space's mail connection, as the admins; else from the server's address. */
|
|
63
|
+
async function deliver(spaceId, message) {
|
|
64
|
+
const row = await mailConnectionOf(spaceId);
|
|
65
|
+
if (row) {
|
|
66
|
+
const sent = await brokerCall({
|
|
67
|
+
who: { kind: "admin" },
|
|
68
|
+
where: { spaceId },
|
|
69
|
+
connection: { kind: "space_connection", row, connector: await connectorOfRow(row) },
|
|
70
|
+
action: { id: "send_message", kind: "send" },
|
|
71
|
+
input: { to: message.to, subject: message.subject },
|
|
72
|
+
ctx: { approved: true, confirmed: true },
|
|
73
|
+
handler: (held) => sendAsAccount(held.connector, held.ctx, message),
|
|
74
|
+
}).catch((err) => {
|
|
75
|
+
console.warn(`[broker] the mail through ${row.name} failed:`, err.message);
|
|
76
|
+
return null;
|
|
77
|
+
});
|
|
78
|
+
if (sent?.ok) {
|
|
79
|
+
return "connection";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (serverSender()) {
|
|
83
|
+
await sendFromServer(message);
|
|
84
|
+
return "server";
|
|
85
|
+
}
|
|
86
|
+
return "nobody";
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* One round for the current tenant: each space with the mail on, its lines since the last round,
|
|
90
|
+
* the mail where no admin was here since. A round sets the space's mark whether it mailed or
|
|
91
|
+
* skipped, so the next one starts there.
|
|
92
|
+
*/
|
|
93
|
+
export async function sendCriticalMails(now = new Date()) {
|
|
94
|
+
const round = { sent: [], skipped: [] };
|
|
95
|
+
const spaces = await db.query.space.findMany({
|
|
96
|
+
where: eq(schema.space.tenantId, currentTenant()),
|
|
97
|
+
columns: { id: true, name: true, notify: true, criticalMailedAt: true, page: true },
|
|
98
|
+
});
|
|
99
|
+
let admins = null;
|
|
100
|
+
for (const space of spaces) {
|
|
101
|
+
if (space.notify.mail !== "hourly") {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const since = space.criticalMailedAt ?? new Date(now.getTime() - HOUR_MS);
|
|
105
|
+
const rows = (await criticalOfSpace(space.id, since)).filter((r) => r.at <= now);
|
|
106
|
+
if (!rows.length) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
admins ??= await adminsOf().catch(() => []);
|
|
110
|
+
const mark = () => db.update(schema.space).set({ criticalMailedAt: now }).where(eq(schema.space.id, space.id));
|
|
111
|
+
if (!admins.length ||
|
|
112
|
+
(await anySeenSince(admins.map((a) => a.userId), since))) {
|
|
113
|
+
await mark();
|
|
114
|
+
round.skipped.push(space.id);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const lang = space.page?.lang === "de" ? "de" : "en";
|
|
118
|
+
const message = criticalMail(space, rows, admins.map((a) => a.email), lang);
|
|
119
|
+
const via = await deliver(space.id, message).catch((err) => {
|
|
120
|
+
console.warn(`[broker] the hourly mail for ${space.name} was not sent:`, err.message);
|
|
121
|
+
return "nobody";
|
|
122
|
+
});
|
|
123
|
+
await mark();
|
|
124
|
+
(via === "nobody" ? round.skipped : round.sent).push(space.id);
|
|
125
|
+
}
|
|
126
|
+
return round;
|
|
127
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { nanoid } from "nanoid";
|
|
2
|
+
export class ClientSteps {
|
|
3
|
+
list = [];
|
|
4
|
+
listeners = new Set();
|
|
5
|
+
on(listener) {
|
|
6
|
+
this.listeners.add(listener);
|
|
7
|
+
return () => this.listeners.delete(listener);
|
|
8
|
+
}
|
|
9
|
+
tell(step) {
|
|
10
|
+
for (const listener of this.listeners) {
|
|
11
|
+
listener(step);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The tools with each call recorded; tools the provider runs itself stay as they are. */
|
|
15
|
+
wrap(tools) {
|
|
16
|
+
return Object.fromEntries(Object.entries(tools).map(([name, tool]) => {
|
|
17
|
+
const t = tool;
|
|
18
|
+
if (typeof t?.execute !== "function") {
|
|
19
|
+
return [name, tool];
|
|
20
|
+
}
|
|
21
|
+
const execute = t.execute.bind(t);
|
|
22
|
+
return [
|
|
23
|
+
name,
|
|
24
|
+
Object.assign(Object.create(Object.getPrototypeOf(t)), t, {
|
|
25
|
+
execute: async (input, context) => {
|
|
26
|
+
const step = {
|
|
27
|
+
toolCallId: `client-${nanoid(10)}`,
|
|
28
|
+
toolName: name,
|
|
29
|
+
input,
|
|
30
|
+
state: "running",
|
|
31
|
+
};
|
|
32
|
+
this.list.push(step);
|
|
33
|
+
this.tell(step);
|
|
34
|
+
try {
|
|
35
|
+
step.output = await execute(input, context);
|
|
36
|
+
step.state = "done";
|
|
37
|
+
return step.output;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
step.state = "failed";
|
|
41
|
+
step.errorText = err instanceof Error ? err.message : String(err);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
this.tell(step);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
];
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** A step as a chunk of the AI SDK's UI message stream. */
|
|
54
|
+
export function stepChunk(step) {
|
|
55
|
+
if (step.state === "running") {
|
|
56
|
+
return {
|
|
57
|
+
type: "tool-input-available",
|
|
58
|
+
toolCallId: step.toolCallId,
|
|
59
|
+
toolName: step.toolName,
|
|
60
|
+
input: step.input,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return step.state === "done"
|
|
64
|
+
? { type: "tool-output-available", toolCallId: step.toolCallId, output: step.output }
|
|
65
|
+
: { type: "tool-output-error", toolCallId: step.toolCallId, errorText: step.errorText ?? "" };
|
|
66
|
+
}
|
|
67
|
+
/** The steps as the parts of a stored message (Mastra's format, which the chat converts). */
|
|
68
|
+
export function stepParts(steps) {
|
|
69
|
+
return steps.map((step) => ({
|
|
70
|
+
type: "tool-invocation",
|
|
71
|
+
toolInvocation: {
|
|
72
|
+
state: "result",
|
|
73
|
+
toolCallId: step.toolCallId,
|
|
74
|
+
toolName: step.toolName,
|
|
75
|
+
args: step.input,
|
|
76
|
+
result: step.state === "failed" ? { error: step.errorText ?? "" } : (step.output ?? null),
|
|
77
|
+
},
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
@@ -11,8 +11,8 @@ import { forgetTwoWay, publishInCloud, refuseOtherOrganization, rotateInCloudSpa
|
|
|
11
11
|
import { currentTenant } from "../tenants/tenant.js";
|
|
12
12
|
import { mainLogoId } from "./brand.js";
|
|
13
13
|
import { ServiceError } from "./errors.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { spaceFileContent, spaceFiles } from "./space-files.js";
|
|
15
|
+
import { ownedSpace } from "./spaces.js";
|
|
16
16
|
import { themesOf } from "./themes.js";
|
|
17
17
|
import { ownedWizard, publishedVersion, publishWizard } from "./wizards.js";
|
|
18
18
|
const key = (wizardId) => `cloud:${wizardId}`;
|
|
@@ -75,19 +75,19 @@ function nextTry(tries, from) {
|
|
|
75
75
|
const minutes = Math.min(60, 2 ** (tries - 1));
|
|
76
76
|
return new Date(from.getTime() + minutes * 60_000).toISOString();
|
|
77
77
|
}
|
|
78
|
-
/** The
|
|
79
|
-
async function spaceOf(userId,
|
|
80
|
-
const
|
|
81
|
-
const logoId = await mainLogoId(
|
|
82
|
-
const logo = logoId ? await
|
|
78
|
+
/** The space as the cloud keeps it: its name, what it says about itself, its logo. */
|
|
79
|
+
async function spaceOf(userId, spaceId) {
|
|
80
|
+
const space = await ownedSpace(userId, spaceId);
|
|
81
|
+
const logoId = await mainLogoId(space.id);
|
|
82
|
+
const logo = logoId ? await spaceFileContent(space.id, logoId).catch(() => null) : null;
|
|
83
83
|
return {
|
|
84
|
-
name:
|
|
84
|
+
name: space.name,
|
|
85
85
|
brand: {
|
|
86
|
-
name:
|
|
87
|
-
about:
|
|
88
|
-
colors:
|
|
86
|
+
name: space.brand.name,
|
|
87
|
+
about: space.brand.about,
|
|
88
|
+
colors: space.brand.colors,
|
|
89
89
|
},
|
|
90
|
-
facts:
|
|
90
|
+
facts: space.facts,
|
|
91
91
|
logo: logo
|
|
92
92
|
? {
|
|
93
93
|
name: logo.row.name,
|
|
@@ -99,8 +99,8 @@ async function spaceOf(userId, projectId) {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
/** The space's own tables and pages, as they are sent: not what a wizard's runs keep. */
|
|
102
|
-
async function spaceDataOf(
|
|
103
|
-
const own = (table) => and(eq(table.
|
|
102
|
+
async function spaceDataOf(spaceId) {
|
|
103
|
+
const own = (table) => and(eq(table.spaceId, spaceId), isNull(table.wizardId));
|
|
104
104
|
const tables = await db.query.spaceTable.findMany({
|
|
105
105
|
where: own(schema.spaceTable),
|
|
106
106
|
orderBy: [asc(schema.spaceTable.id)],
|
|
@@ -116,7 +116,7 @@ async function spaceDataOf(projectId) {
|
|
|
116
116
|
orderBy: [asc(schema.spacePage.id)],
|
|
117
117
|
});
|
|
118
118
|
const categories = await db.query.spaceCategory.findMany({
|
|
119
|
-
where: and(eq(schema.spaceCategory.
|
|
119
|
+
where: and(eq(schema.spaceCategory.spaceId, spaceId), eq(schema.spaceCategory.proposed, false)),
|
|
120
120
|
orderBy: [asc(schema.spaceCategory.position), asc(schema.spaceCategory.id)],
|
|
121
121
|
});
|
|
122
122
|
const values = categories.length
|
|
@@ -127,7 +127,7 @@ async function spaceDataOf(projectId) {
|
|
|
127
127
|
: [];
|
|
128
128
|
const assignments = categories.length
|
|
129
129
|
? await db.query.spaceItemCategory.findMany({
|
|
130
|
-
where: and(eq(schema.spaceItemCategory.
|
|
130
|
+
where: and(eq(schema.spaceItemCategory.spaceId, spaceId), isNull(schema.spaceItemCategory.fileId)),
|
|
131
131
|
orderBy: [asc(schema.spaceItemCategory.id)],
|
|
132
132
|
})
|
|
133
133
|
: [];
|
|
@@ -187,15 +187,15 @@ async function spaceDataOf(projectId) {
|
|
|
187
187
|
* Sends the space's own tables and pages along with a wizard, when they changed since they last
|
|
188
188
|
* arrived. A sending that fails is tried with the next wizard; the wizard is there either way.
|
|
189
189
|
*/
|
|
190
|
-
async function syncSpaceDataToCloud(
|
|
191
|
-
const data = await spaceDataOf(
|
|
190
|
+
async function syncSpaceDataToCloud(spaceId) {
|
|
191
|
+
const data = await spaceDataOf(spaceId);
|
|
192
192
|
const hash = createHash("sha256").update(JSON.stringify(data)).digest("hex");
|
|
193
|
-
const sent = `cloud-data:${
|
|
193
|
+
const sent = `cloud-data:${spaceId}`;
|
|
194
194
|
if ((await readSetting(sent)) === hash) {
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
197
|
try {
|
|
198
|
-
const answer = await call("PUT", `/spaces/${
|
|
198
|
+
const answer = await call("PUT", `/spaces/${spaceId}/data`, data, 120_000);
|
|
199
199
|
if (answer.ok) {
|
|
200
200
|
await writeSetting(sent, hash);
|
|
201
201
|
}
|
|
@@ -219,13 +219,13 @@ export async function syncToCloud(userId, wizardId) {
|
|
|
219
219
|
throw new ServiceError("refused", note("publishWizardFirst"));
|
|
220
220
|
}
|
|
221
221
|
const before = await cloudState(w.id);
|
|
222
|
-
const twoWay = await spaceSyncs(w.
|
|
222
|
+
const twoWay = await spaceSyncs(w.spaceId);
|
|
223
223
|
try {
|
|
224
224
|
// A space of the organization the account was signed in to before stays out of this one.
|
|
225
|
-
await refuseOtherOrganization(w.
|
|
225
|
+
await refuseOtherOrganization(w.spaceId);
|
|
226
226
|
if (twoWay) {
|
|
227
227
|
// The space syncs both ways: its draft goes up with the space, then the cloud publishes it.
|
|
228
|
-
const published = await publishInCloud(w.
|
|
228
|
+
const published = await publishInCloud(w.spaceId, w.id);
|
|
229
229
|
const state = {
|
|
230
230
|
copy: {
|
|
231
231
|
shareUrl: published.shareUrl,
|
|
@@ -246,14 +246,14 @@ export async function syncToCloud(userId, wizardId) {
|
|
|
246
246
|
mime: f.mime,
|
|
247
247
|
data: (await getBlob(f.hash)).toString("base64"),
|
|
248
248
|
})));
|
|
249
|
-
const answer = await call("PUT", `/spaces/${w.
|
|
250
|
-
space: await spaceOf(userId, w.
|
|
249
|
+
const answer = await call("PUT", `/spaces/${w.spaceId}/wizards/${w.id}`, {
|
|
250
|
+
space: await spaceOf(userId, w.spaceId),
|
|
251
251
|
version: version.version,
|
|
252
252
|
definition: version.definition,
|
|
253
253
|
files,
|
|
254
254
|
shareEnabled: w.shareEnabled,
|
|
255
255
|
dailyRunLimit: w.dailyRunLimit,
|
|
256
|
-
themes: themesOf(version.definition.themes, (await
|
|
256
|
+
themes: themesOf(version.definition.themes, (await ownedSpace(userId, w.spaceId)).themes),
|
|
257
257
|
}, 120_000);
|
|
258
258
|
if (!answer.ok || !answer.body.shareUrl) {
|
|
259
259
|
throw refusal(answer, "The cloud did not take the wizard.");
|
|
@@ -271,7 +271,7 @@ export async function syncToCloud(userId, wizardId) {
|
|
|
271
271
|
error: null,
|
|
272
272
|
};
|
|
273
273
|
await writeSetting(key(w.id), state);
|
|
274
|
-
await syncSpaceDataToCloud(w.
|
|
274
|
+
await syncSpaceDataToCloud(w.spaceId);
|
|
275
275
|
return state;
|
|
276
276
|
}
|
|
277
277
|
catch (err) {
|
|
@@ -310,7 +310,7 @@ export async function pushSharing(userId, wizardId) {
|
|
|
310
310
|
}
|
|
311
311
|
// A space that syncs both ways takes the settings along with the wizard.
|
|
312
312
|
const own = await ownedWizard(userId, wizardId).catch(() => null);
|
|
313
|
-
if (own && (await spaceSyncs(own.
|
|
313
|
+
if (own && (await spaceSyncs(own.spaceId))) {
|
|
314
314
|
return;
|
|
315
315
|
}
|
|
316
316
|
const state = await cloudState(wizardId);
|
|
@@ -318,7 +318,7 @@ export async function pushSharing(userId, wizardId) {
|
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
const w = await ownedWizard(userId, wizardId);
|
|
321
|
-
await call("PATCH", `/spaces/${w.
|
|
321
|
+
await call("PATCH", `/spaces/${w.spaceId}/wizards/${w.id}`, {
|
|
322
322
|
shareEnabled: w.shareEnabled,
|
|
323
323
|
dailyRunLimit: w.dailyRunLimit,
|
|
324
324
|
translate: w.translate,
|
|
@@ -339,11 +339,11 @@ export async function rotateInCloud(userId, wizardId) {
|
|
|
339
339
|
}
|
|
340
340
|
const w = await ownedWizard(userId, wizardId);
|
|
341
341
|
let link;
|
|
342
|
-
if (await spaceSyncs(w.
|
|
343
|
-
link = await rotateInCloudSpace(w.
|
|
342
|
+
if (await spaceSyncs(w.spaceId)) {
|
|
343
|
+
link = await rotateInCloudSpace(w.spaceId, w.id);
|
|
344
344
|
}
|
|
345
345
|
else {
|
|
346
|
-
const answer = await call("POST", `/spaces/${w.
|
|
346
|
+
const answer = await call("POST", `/spaces/${w.spaceId}/wizards/${w.id}/rotate-link`);
|
|
347
347
|
if (!answer.ok || !answer.body.shareUrl) {
|
|
348
348
|
throw refusal(answer, "The link in the cloud could not be renewed.");
|
|
349
349
|
}
|
|
@@ -365,10 +365,10 @@ export async function removeFromCloud(userId, wizardId) {
|
|
|
365
365
|
const w = await ownedWizard(userId, wizardId).catch(() => null);
|
|
366
366
|
await deleteSetting(key(wizardId));
|
|
367
367
|
// A space that syncs both ways deletes the copy with the next push.
|
|
368
|
-
if (!w || !state.copy || !(await cloudLinked()) || (await spaceSyncs(w.
|
|
368
|
+
if (!w || !state.copy || !(await cloudLinked()) || (await spaceSyncs(w.spaceId))) {
|
|
369
369
|
return;
|
|
370
370
|
}
|
|
371
|
-
await call("DELETE", `/spaces/${w.
|
|
371
|
+
await call("DELETE", `/spaces/${w.spaceId}/wizards/${w.id}`).catch((err) => console.error("[cloud] copy not removed:", err.message));
|
|
372
372
|
}
|
|
373
373
|
/**
|
|
374
374
|
* Sends again what did not arrive and is due for another try. Called every minute by the
|
|
@@ -418,9 +418,9 @@ export async function syncAllToCloud(userId) {
|
|
|
418
418
|
const owners = await spaceOrganizations();
|
|
419
419
|
const account = await linkedAccount();
|
|
420
420
|
const wizards = (await db
|
|
421
|
-
.select({ id: schema.wizard.id,
|
|
421
|
+
.select({ id: schema.wizard.id, spaceId: schema.wizard.spaceId })
|
|
422
422
|
.from(schema.wizard)
|
|
423
|
-
.where(and(eq(schema.wizard.tenantId, currentTenant()), isNotNull(schema.wizard.publishedVersion)))).filter((w) => !owners[w.
|
|
423
|
+
.where(and(eq(schema.wizard.tenantId, currentTenant()), isNotNull(schema.wizard.publishedVersion)))).filter((w) => !owners[w.spaceId] || owners[w.spaceId].id === account?.tenantId);
|
|
424
424
|
let sent = 0;
|
|
425
425
|
let failed = 0;
|
|
426
426
|
for (const [i, { id }] of wizards.entries()) {
|
|
@@ -460,13 +460,13 @@ export async function checkForCloud(userId, wizardId) {
|
|
|
460
460
|
if (!answer.ok) {
|
|
461
461
|
throw refusal(answer, "The cloud did not answer.");
|
|
462
462
|
}
|
|
463
|
-
const documents = await
|
|
463
|
+
const documents = await spaceFiles(w.spaceId, "document");
|
|
464
464
|
return {
|
|
465
465
|
problems: answer.body.problems ?? [],
|
|
466
466
|
documents: documents.length > 0 && w.draft.steps.some((s) => s.type === "agent"),
|
|
467
467
|
};
|
|
468
468
|
}
|
|
469
|
-
/** The
|
|
469
|
+
/** The spaces the account's cloud holds of local installs: this one's, or another machine's. */
|
|
470
470
|
export async function cloudSpaces() {
|
|
471
471
|
const answer = await call("GET", "/spaces");
|
|
472
472
|
if (!answer.ok) {
|
|
@@ -475,15 +475,15 @@ export async function cloudSpaces() {
|
|
|
475
475
|
return answer.body.spaces ?? [];
|
|
476
476
|
}
|
|
477
477
|
/**
|
|
478
|
-
* Makes room for this install's
|
|
478
|
+
* Makes room for this install's space: the spaces of other installs go from the cloud, with
|
|
479
479
|
* their links, then everything published here is sent. For the person who moved to a new
|
|
480
480
|
* machine or installed anew.
|
|
481
481
|
*/
|
|
482
482
|
export async function replaceCloudSpaces(userId) {
|
|
483
483
|
const mine = new Set((await db
|
|
484
|
-
.select({ id: schema.
|
|
485
|
-
.from(schema.
|
|
486
|
-
.where(eq(schema.
|
|
484
|
+
.select({ id: schema.space.id })
|
|
485
|
+
.from(schema.space)
|
|
486
|
+
.where(eq(schema.space.tenantId, currentTenant()))).map((p) => p.id));
|
|
487
487
|
for (const space of await cloudSpaces()) {
|
|
488
488
|
if (!mine.has(space.id)) {
|
|
489
489
|
const answer = await call("DELETE", `/spaces/${space.id}`);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a shell command on the space's computer may run without asking (docs/plans/work-chats.md,
|
|
3
|
+
* "The space's computer and browser"): what stays in the container runs; what sends data out,
|
|
4
|
+
* deletes or moves the space's files, or can't be read asks; what is unclear goes to a classifier
|
|
5
|
+
* that fails closed (asks). The space's computer (piece 5) calls it before each command.
|
|
6
|
+
*/
|
|
7
|
+
/** Where the space's own files are mounted in the computer. */
|
|
8
|
+
const SPACE_PATHS = ["/space", "/files"];
|
|
9
|
+
const rules = [
|
|
10
|
+
// Can't be read before it runs: what it does is decided while it runs.
|
|
11
|
+
{
|
|
12
|
+
why: "runs code it builds while it runs",
|
|
13
|
+
test: /\beval\b|`|\$\(|\|\s*(ba|z|da)?sh\b|\bsource\s+<\(/,
|
|
14
|
+
},
|
|
15
|
+
// Sends data out of the computer.
|
|
16
|
+
{
|
|
17
|
+
why: "pushes to a remote",
|
|
18
|
+
test: /\bgit\s+push\b|\b(npm|pnpm|yarn)\s+publish\b|\bdocker\s+push\b/,
|
|
19
|
+
},
|
|
20
|
+
{ why: "connects to another computer", test: /\b(ssh|scp|sftp|rsync|ftp|telnet|nc|ncat)\b/ },
|
|
21
|
+
{ why: "sends mail", test: /\b(mail|mailx|sendmail|mutt)\b/ },
|
|
22
|
+
{
|
|
23
|
+
why: "sends data to a web address",
|
|
24
|
+
test: /\bcurl\b[^|;&]*(\s-(d|F|T)\b|\s--(data|data-\w+|form|upload-file|json)\b|\s-X\s*(POST|PUT|PATCH|DELETE)\b)|\bwget\b[^|;&]*--(post|body|method)/i,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
const touchesSpace = (command) => SPACE_PATHS.some((path) => new RegExp(`(^|[\\s='"])${path.replace("/", "\\/")}(\\/|\\s|$|['"])`).test(command));
|
|
28
|
+
export function classifyCommand(command) {
|
|
29
|
+
const line = command.trim();
|
|
30
|
+
if (!line) {
|
|
31
|
+
return { verdict: "runs" };
|
|
32
|
+
}
|
|
33
|
+
for (const rule of rules) {
|
|
34
|
+
if (rule.test.test(line)) {
|
|
35
|
+
return { verdict: "asks", why: rule.why };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (touchesSpace(line)) {
|
|
39
|
+
if (/(^|[;&|]\s*)(rm|rmdir|mv|truncate|shred|unlink)\b/.test(line) ||
|
|
40
|
+
/\bfind\b.*\s-delete\b/.test(line)) {
|
|
41
|
+
return { verdict: "asks", why: "deletes or moves the space's files" };
|
|
42
|
+
}
|
|
43
|
+
// Writing into the space's files by redirect or copy: not plainly harmless, not plainly not.
|
|
44
|
+
if (/>\s*['"]?\/(space|files)\b|\b(cp|tee|sed\s+-i|dd)\b/.test(line)) {
|
|
45
|
+
return { verdict: "unclear", why: "writes into the space's files" };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return { verdict: "runs" };
|
|
49
|
+
}
|
|
50
|
+
/** What happens with a command: an unclear one is asked about until a classifier says otherwise. */
|
|
51
|
+
export const asksBeforeRunning = (risk) => risk.verdict !== "runs";
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { featureOn } from "@engenty/wizards-shared/features";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { searchRegistry } from "../connectors/external.js";
|
|
4
|
+
import { db, schema } from "../db/client.js";
|
|
5
|
+
import { currentFeatures } from "../features.js";
|
|
6
|
+
import { notFound } from "./errors.js";
|
|
7
|
+
import { skillsOn } from "./skills.js";
|
|
8
|
+
import { searchSkills } from "./skills-registry.js";
|
|
9
|
+
import { ownedSpace } from "./spaces.js";
|
|
10
|
+
/**
|
|
11
|
+
* Fähigkeiten › Entdecken (docs/plans/capabilities.md, part B6): one search over skills.sh and
|
|
12
|
+
* integrations.sh. Both are asked at once, each with its own time to answer; one that fails or
|
|
13
|
+
* takes too long leaves its list empty and says so, and the other still shows what it found.
|
|
14
|
+
*/
|
|
15
|
+
/** How long one directory may take before the search goes on without it. */
|
|
16
|
+
const WAIT_MS = 10_000;
|
|
17
|
+
function within(work) {
|
|
18
|
+
let timer;
|
|
19
|
+
const late = new Promise((_, reject) => {
|
|
20
|
+
timer = setTimeout(() => reject(new Error("too late")), WAIT_MS);
|
|
21
|
+
});
|
|
22
|
+
return Promise.race([work, late]).finally(() => clearTimeout(timer));
|
|
23
|
+
}
|
|
24
|
+
/** `www.Notion.so` and `notion.so` are one service. */
|
|
25
|
+
const plainDomain = (domain) => domain
|
|
26
|
+
.trim()
|
|
27
|
+
.toLowerCase()
|
|
28
|
+
.replace(/^www\./, "");
|
|
29
|
+
/**
|
|
30
|
+
* The services the space has: the domains of the definitions it imported, and the built-in
|
|
31
|
+
* connectors it has a connection to (a built-in's id is its service's name: `hubspot`, `github`).
|
|
32
|
+
*/
|
|
33
|
+
async function spaceServices(spaceId) {
|
|
34
|
+
const [imported, connections] = await Promise.all([
|
|
35
|
+
db.query.spaceConnector.findMany({
|
|
36
|
+
where: eq(schema.spaceConnector.spaceId, spaceId),
|
|
37
|
+
columns: { record: true },
|
|
38
|
+
}),
|
|
39
|
+
db
|
|
40
|
+
.select({ connectorId: schema.spaceConnection.connectorId })
|
|
41
|
+
.from(schema.spaceConnection)
|
|
42
|
+
.where(eq(schema.spaceConnection.spaceId, spaceId)),
|
|
43
|
+
]);
|
|
44
|
+
return {
|
|
45
|
+
domains: new Set(imported.map((r) => plainDomain(r.record.domain ?? ""))),
|
|
46
|
+
connected: new Set(connections.map((c) => c.connectorId)),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function markSetUp(spaceId, hits) {
|
|
50
|
+
const has = await spaceServices(spaceId);
|
|
51
|
+
return hits.map((hit) => {
|
|
52
|
+
const domain = plainDomain(hit.domain);
|
|
53
|
+
const name = domain.split(".")[0] ?? "";
|
|
54
|
+
return { ...hit, setUp: has.domains.has(domain) || has.connected.has(name) };
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** Skills and connectors for a few words, what the space has marked. */
|
|
58
|
+
export async function discover(userId, spaceId, query) {
|
|
59
|
+
// Part of Fähigkeiten: not there while its switch is off.
|
|
60
|
+
if (!featureOn(await currentFeatures(), "capabilities")) {
|
|
61
|
+
throw notFound();
|
|
62
|
+
}
|
|
63
|
+
const space = await ownedSpace(userId, spaceId);
|
|
64
|
+
const q = query.trim().slice(0, 100);
|
|
65
|
+
if (q.length < 2) {
|
|
66
|
+
return { skills: [], connectors: [], errors: {} };
|
|
67
|
+
}
|
|
68
|
+
const [skills, connectors] = await Promise.allSettled([
|
|
69
|
+
// Skills stay out while their own switch is off.
|
|
70
|
+
skillsOn().then(async (on) => on ? (await within(searchSkills(userId, space.id, q))).hits : []),
|
|
71
|
+
within(searchRegistry(q)).then((hits) => markSetUp(space.id, hits)),
|
|
72
|
+
]);
|
|
73
|
+
const errors = {};
|
|
74
|
+
if (skills.status === "rejected") {
|
|
75
|
+
errors.skills = "skillsRegistryDown";
|
|
76
|
+
}
|
|
77
|
+
if (connectors.status === "rejected") {
|
|
78
|
+
errors.connectors = "connectorsRegistryDown";
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
skills: skills.status === "fulfilled" ? skills.value : [],
|
|
82
|
+
connectors: connectors.status === "fulfilled" ? connectors.value : [],
|
|
83
|
+
errors,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -14,8 +14,8 @@ import { prompt } from "../prompts.js";
|
|
|
14
14
|
import { currentTenant } from "../tenants/tenant.js";
|
|
15
15
|
import { ServiceError } from "./errors.js";
|
|
16
16
|
import { freeSlug, pageTree } from "./knowledge.js";
|
|
17
|
-
import { keepText, queueIndex } from "./project-index.js";
|
|
18
17
|
import { categoryRow, categoryRows, numberOf, setItemCategories, } from "./space-categories.js";
|
|
18
|
+
import { keepText, queueIndex } from "./space-index.js";
|
|
19
19
|
const XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
20
20
|
// --- tables from sheets ------------------------------------------------------------------
|
|
21
21
|
const NUMBER = /^-?[\d\s.,']+\s*(€|eur|%|kg|t|h|mm|cm|m|km|stk\.?|stück)?$/i;
|
|
@@ -233,11 +233,11 @@ async function insertPage(file, input) {
|
|
|
233
233
|
await db.insert(schema.spacePage).values({
|
|
234
234
|
id,
|
|
235
235
|
tenantId: currentTenant(),
|
|
236
|
-
|
|
236
|
+
spaceId: file.spaceId,
|
|
237
237
|
parentId: input.parentId,
|
|
238
238
|
position: input.position,
|
|
239
239
|
title: input.title,
|
|
240
|
-
slug: await freeSlug(file.
|
|
240
|
+
slug: await freeSlug(file.spaceId, input.title, { parentId: input.parentId }),
|
|
241
241
|
markdown: input.markdown.slice(0, 200_000),
|
|
242
242
|
fileId: file.id,
|
|
243
243
|
origin: file.origin,
|
|
@@ -278,9 +278,9 @@ export async function convertDocument(file, data) {
|
|
|
278
278
|
await db.insert(schema.spaceTable).values({
|
|
279
279
|
id,
|
|
280
280
|
tenantId: currentTenant(),
|
|
281
|
-
|
|
281
|
+
spaceId: file.spaceId,
|
|
282
282
|
title,
|
|
283
|
-
slug: await freeSlug(file.
|
|
283
|
+
slug: await freeSlug(file.spaceId, title, "table"),
|
|
284
284
|
columns,
|
|
285
285
|
fileId: file.id,
|
|
286
286
|
origin: file.origin,
|
|
@@ -351,7 +351,7 @@ export async function convertDocument(file, data) {
|
|
|
351
351
|
}));
|
|
352
352
|
}
|
|
353
353
|
// References to other parts become links, now that each part has its path.
|
|
354
|
-
const tree = await pageTree(file.
|
|
354
|
+
const tree = await pageTree(file.spaceId);
|
|
355
355
|
const targets = new Map();
|
|
356
356
|
ids.forEach((id, k) => {
|
|
357
357
|
const ref = referenceKey(split.parts[k].title);
|
|
@@ -392,9 +392,9 @@ export async function convertDocument(file, data) {
|
|
|
392
392
|
* Fills the space's categories of an item from its text, where the space has any and nothing
|
|
393
393
|
* set them yet. Values a person set are never touched. True when anything was set.
|
|
394
394
|
*/
|
|
395
|
-
export async function fillCategories(
|
|
395
|
+
export async function fillCategories(spaceId, ref, text, name) {
|
|
396
396
|
// A column's category comes from its cells, not from a model.
|
|
397
|
-
const categories = (await categoryRows(
|
|
397
|
+
const categories = (await categoryRows(spaceId)).filter((c) => !(c.proposed || c.tableId));
|
|
398
398
|
if (!(categories.length && text.trim())) {
|
|
399
399
|
return false;
|
|
400
400
|
}
|
|
@@ -447,7 +447,7 @@ export async function fillCategories(projectId, ref, text, name) {
|
|
|
447
447
|
if (!Object.keys(input).length) {
|
|
448
448
|
return false;
|
|
449
449
|
}
|
|
450
|
-
const { changed } = await setItemCategories(
|
|
450
|
+
const { changed } = await setItemCategories(spaceId, ref, input, "model");
|
|
451
451
|
return changed;
|
|
452
452
|
}
|
|
453
453
|
// --- the summary of a value -----------------------------------------------------------------
|
|
@@ -492,8 +492,8 @@ async function itemsOfValue(valueId) {
|
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
494
|
else if (r.fileId) {
|
|
495
|
-
const file = await db.query.
|
|
496
|
-
where: eq(schema.
|
|
495
|
+
const file = await db.query.spaceFile.findFirst({
|
|
496
|
+
where: eq(schema.spaceFile.id, r.fileId),
|
|
497
497
|
});
|
|
498
498
|
if (file) {
|
|
499
499
|
out.push({ title: file.name, text: file.description });
|
|
@@ -540,8 +540,8 @@ export async function writeSummary(valueId) {
|
|
|
540
540
|
return summary;
|
|
541
541
|
}
|
|
542
542
|
/** After a source wrote: the values it filled that have three items or more get their summary. */
|
|
543
|
-
export async function summarizeValues(
|
|
544
|
-
const categories = (await categoryRows(
|
|
543
|
+
export async function summarizeValues(spaceId, categoryName, value) {
|
|
544
|
+
const categories = (await categoryRows(spaceId)).filter((c) => c.type === "choice" &&
|
|
545
545
|
!c.proposed &&
|
|
546
546
|
(!categoryName || c.name.toLowerCase() === categoryName.trim().toLowerCase()));
|
|
547
547
|
let written = 0;
|