@engenty/wizards-runtime 0.12.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/agents/architect.js +8 -7
- package/apps/runtime/dist/agents/goose-connections.js +82 -0
- package/apps/runtime/dist/agents/space-agent.js +9 -2
- package/apps/runtime/dist/agents/studio-assistant.js +126 -71
- package/apps/runtime/dist/agents/website.js +1 -1
- package/apps/runtime/dist/app.js +28 -3
- package/apps/runtime/dist/assistant/knows.js +6 -5
- package/apps/runtime/dist/authoring/guide.js +25 -5
- package/apps/runtime/dist/broker/account.js +166 -0
- package/apps/runtime/dist/broker/call.js +417 -0
- package/apps/runtime/dist/broker/caller.js +10 -0
- package/apps/runtime/dist/broker/grant.js +152 -0
- package/apps/runtime/dist/broker/host.js +51 -0
- package/apps/runtime/dist/broker/index.js +8 -0
- package/apps/runtime/dist/broker/kept.js +31 -0
- package/apps/runtime/dist/broker/log.js +240 -0
- package/apps/runtime/dist/broker/registry.js +9 -0
- package/apps/runtime/dist/broker/rwx.js +367 -0
- package/apps/runtime/dist/broker/send.js +189 -0
- package/apps/runtime/dist/connectors/builtin.js +1 -1
- package/apps/runtime/dist/connectors/external.js +38 -37
- package/apps/runtime/dist/connectors/index.js +30 -91
- package/apps/runtime/dist/connectors/mail.js +0 -8
- package/apps/runtime/dist/connectors/person-sign-ins.js +73 -0
- package/apps/runtime/dist/connectors/plugin-connections.js +65 -92
- package/apps/runtime/dist/connectors/smtp.js +1 -1
- package/apps/runtime/dist/connectors/space-connections.js +436 -0
- package/apps/runtime/dist/credits/estimate.js +3 -3
- package/apps/runtime/dist/db/adopt.js +3 -3
- package/apps/runtime/dist/db/client.js +9 -0
- package/apps/runtime/dist/db/live-triggers.js +65 -23
- package/apps/runtime/dist/db/migrations/tenant/0027_work_chats.sql +52 -0
- package/apps/runtime/dist/db/migrations/tenant/0028_chat_approvals.sql +17 -0
- package/apps/runtime/dist/db/migrations/tenant/0029_work_chats_live.sql +49 -0
- package/apps/runtime/dist/db/migrations/tenant/0031_space.sql +624 -0
- package/apps/runtime/dist/db/migrations/tenant/0032_rwx_rule.sql +18 -0
- package/apps/runtime/dist/db/migrations/tenant/0033_broker_log.sql +23 -0
- package/apps/runtime/dist/db/migrations/tenant/0034_space_connection.sql +35 -0
- package/apps/runtime/dist/db/migrations/tenant/0035_run_grant.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0036_approval_held_for.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0037_ways_out.sql +5 -0
- package/apps/runtime/dist/db/migrations/tenant/0038_heard.sql +11 -0
- package/apps/runtime/dist/db/migrations/tenant/0039_members_studio.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0027_snapshot.json +383 -155
- package/apps/runtime/dist/db/migrations/tenant/meta/0028_snapshot.json +4468 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0029_snapshot.json +4475 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0030_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0031_snapshot.json +4629 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0032_snapshot.json +4757 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0033_snapshot.json +5039 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0034_snapshot.json +5022 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0035_snapshot.json +5029 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0036_snapshot.json +5037 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0037_snapshot.json +5076 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0038_snapshot.json +5145 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0039_snapshot.json +5153 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +86 -2
- package/apps/runtime/dist/db/schema.js +295 -72
- package/apps/runtime/dist/docs/dev/architecture.md +215 -0
- package/apps/runtime/dist/docs/dev/broker.md +298 -0
- package/apps/runtime/dist/docs/dev/index.md +5 -1
- package/apps/runtime/dist/docs/dev/integration/index.md +2 -0
- package/apps/runtime/dist/docs/dev/meta.json +3 -0
- package/apps/runtime/dist/docs/dev/plugins/connections.md +8 -5
- package/apps/runtime/dist/docs/dev/plugins/events.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -0
- package/apps/runtime/dist/docs/dev/plugins/index.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/reference.md +3 -2
- package/apps/runtime/dist/docs/dev/plugins/space.md +16 -6
- package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
- package/apps/runtime/dist/docs/dev/plugins/tools.md +0 -1
- package/apps/runtime/dist/docs/dev/skills.md +16 -9
- package/apps/runtime/dist/docs/dev/wizard-format/agent-steps.md +59 -6
- package/apps/runtime/dist/docs/dev/wizard-format/lists-and-connections.md +17 -2
- package/apps/runtime/dist/docs/dev/wizard-format/templates.md +2 -0
- package/apps/runtime/dist/docs/dev/wizard-format/views-and-widgets.md +22 -2
- package/apps/runtime/dist/docs/user-guide/capabilities.md +132 -0
- package/apps/runtime/dist/docs/user-guide/cloud-sync.md +2 -0
- package/apps/runtime/dist/docs/user-guide/command-line.md +1 -0
- package/apps/runtime/dist/docs/user-guide/connectors.md +63 -7
- package/apps/runtime/dist/docs/user-guide/index.md +10 -1
- package/apps/runtime/dist/docs/user-guide/meta.json +6 -1
- package/apps/runtime/dist/docs/user-guide/models.md +105 -30
- package/apps/runtime/dist/docs/user-guide/protocol.md +80 -0
- package/apps/runtime/dist/docs/user-guide/skills.md +8 -4
- package/apps/runtime/dist/docs/user-guide/space.md +5 -4
- package/apps/runtime/dist/docs/user-guide/together.md +29 -2
- package/apps/runtime/dist/docs/user-guide/troubleshooting.md +2 -2
- package/apps/runtime/dist/docs/user-guide/work-mode.md +128 -0
- package/apps/runtime/dist/engenty/connections-external/build-connector.js +2 -5
- package/apps/runtime/dist/engenty/connections-external/importer/classify.js +72 -0
- package/apps/runtime/dist/engenty/connections-google/connectors/gmail.js +1 -1
- package/apps/runtime/dist/engenty/connections-microsoft/outlook.js +3 -2
- package/apps/runtime/dist/engenty/connections-sdk/types.js +2 -0
- package/apps/runtime/dist/engenty/connections-slack/connector.js +2 -1
- package/apps/runtime/dist/engine/decide.js +1 -1
- package/apps/runtime/dist/engine/requirements.js +139 -11
- package/apps/runtime/dist/engine/resources.js +43 -12
- package/apps/runtime/dist/engine/runner.js +121 -27
- package/apps/runtime/dist/engine/steps.js +42 -16
- package/apps/runtime/dist/engine/template.js +35 -1
- package/apps/runtime/dist/env.js +9 -4
- package/apps/runtime/dist/index.js +18 -2
- package/apps/runtime/dist/link-preview.js +9 -0
- package/apps/runtime/dist/live/feed.js +2 -2
- package/apps/runtime/dist/live/origin.js +2 -2
- package/apps/runtime/dist/live/views.js +51 -26
- package/apps/runtime/dist/manage.js +32 -0
- package/apps/runtime/dist/mcp/flow-app.js +1 -1
- package/apps/runtime/dist/mcp/handler.js +55 -1
- package/apps/runtime/dist/mcp/seen.js +47 -0
- package/apps/runtime/dist/mcp/tools.js +75 -34
- package/apps/runtime/dist/models.js +203 -12
- package/apps/runtime/dist/motion-graphics/project.js +8 -8
- package/apps/runtime/dist/motion-graphics/step.js +2 -2
- package/apps/runtime/dist/motion-graphics/tools.js +1 -1
- package/apps/runtime/dist/plugins/events.js +2 -2
- package/apps/runtime/dist/plugins/jobs.js +4 -1
- package/apps/runtime/dist/plugins/loader.js +2 -2
- package/apps/runtime/dist/prompts/architect.md +3 -3
- package/apps/runtime/dist/prompts/authoring.md +46 -12
- package/apps/runtime/dist/prompts/goose.md +14 -13
- package/apps/runtime/dist/prompts/mcp.md +6 -6
- package/apps/runtime/dist/prompts/safety.md +18 -0
- package/apps/runtime/dist/prompts/services.md +4 -4
- package/apps/runtime/dist/prompts/step.md +3 -3
- package/apps/runtime/dist/prompts/tools.md +39 -10
- package/apps/runtime/dist/routes/api.js +31 -20
- package/apps/runtime/dist/routes/broker.js +316 -0
- package/apps/runtime/dist/routes/connections.js +71 -0
- package/apps/runtime/dist/routes/delivery.js +25 -0
- package/apps/runtime/dist/routes/discover.js +17 -0
- package/apps/runtime/dist/routes/live.js +11 -1
- package/apps/runtime/dist/routes/marketplace.js +3 -3
- package/apps/runtime/dist/routes/person.js +4 -1
- package/apps/runtime/dist/routes/plugins.js +3 -1
- package/apps/runtime/dist/routes/rules.js +26 -0
- package/apps/runtime/dist/routes/runs.js +59 -33
- package/apps/runtime/dist/routes/skills.js +6 -6
- package/apps/runtime/dist/routes/studio.js +256 -148
- package/apps/runtime/dist/routes/work.js +199 -0
- package/apps/runtime/dist/safety.js +60 -18
- package/apps/runtime/dist/sandbox/index.js +27 -0
- package/apps/runtime/dist/services/access.js +38 -17
- package/apps/runtime/dist/services/api.js +38 -13
- package/apps/runtime/dist/services/architect.js +3 -3
- package/apps/runtime/dist/services/assistant-chats.js +9 -1
- package/apps/runtime/dist/services/brand.js +12 -12
- package/apps/runtime/dist/services/broker-bell.js +69 -0
- package/apps/runtime/dist/services/broker-notify.js +127 -0
- package/apps/runtime/dist/services/client-steps.js +79 -0
- package/apps/runtime/dist/services/cloud.js +42 -42
- package/apps/runtime/dist/services/command-risk.js +51 -0
- package/apps/runtime/dist/services/discover.js +85 -0
- package/apps/runtime/dist/services/knowledge-model.js +13 -13
- package/apps/runtime/dist/services/knowledge.js +117 -80
- package/apps/runtime/dist/services/manage-reports.js +77 -7
- package/apps/runtime/dist/services/marketplace.js +7 -31
- package/apps/runtime/dist/services/members-studio.js +165 -0
- package/apps/runtime/dist/services/onboarding.js +22 -22
- package/apps/runtime/dist/services/package-file.js +1 -1
- package/apps/runtime/dist/services/package.js +22 -22
- package/apps/runtime/dist/services/pages.js +13 -9
- package/apps/runtime/dist/services/runs.js +4 -3
- package/apps/runtime/dist/services/seen.js +55 -0
- package/apps/runtime/dist/services/shares.js +28 -13
- package/apps/runtime/dist/services/site.js +23 -23
- package/apps/runtime/dist/services/skills-registry.js +15 -15
- package/apps/runtime/dist/services/skills.js +44 -44
- package/apps/runtime/dist/services/space-categories.js +35 -35
- package/apps/runtime/dist/services/space-data.js +130 -111
- package/apps/runtime/dist/services/{project-files.js → space-files.js} +84 -75
- package/apps/runtime/dist/services/{project-index.js → space-index.js} +116 -73
- package/apps/runtime/dist/services/space-origin.js +19 -11
- package/apps/runtime/dist/services/spaces.js +478 -598
- package/apps/runtime/dist/services/synced-spaces.js +668 -0
- package/apps/runtime/dist/services/themes.js +15 -15
- package/apps/runtime/dist/services/widgets.js +6 -6
- package/apps/runtime/dist/services/wizards.js +112 -38
- package/apps/runtime/dist/services/work-ai.js +257 -0
- package/apps/runtime/dist/services/work-approvals.js +104 -0
- package/apps/runtime/dist/services/work-chats.js +908 -0
- package/apps/runtime/dist/services/work-connections.js +90 -0
- package/apps/runtime/dist/services/work-files.js +85 -0
- package/apps/runtime/dist/services/work-mastra.js +73 -0
- package/apps/runtime/dist/services/work-sandbox.js +42 -0
- package/apps/runtime/dist/sharing/files.js +14 -4
- package/apps/runtime/dist/sharing/index.js +40 -39
- package/apps/runtime/dist/sharing/jobs.js +67 -17
- package/apps/runtime/dist/sharing/targets/connector.js +10 -6
- package/apps/runtime/dist/sharing/targets/email.js +10 -8
- package/apps/runtime/dist/sharing/targets/slack.js +10 -8
- package/apps/runtime/dist/sharing/targets/storage.js +6 -4
- package/apps/runtime/dist/store/index.js +14 -3
- package/apps/runtime/dist/store/shared-lists.js +4 -2
- package/apps/runtime/dist/sync/apply.js +2 -2
- package/apps/runtime/dist/sync/client.js +113 -113
- package/apps/runtime/dist/sync/hub.js +41 -41
- package/apps/runtime/dist/sync/log.js +12 -12
- package/apps/runtime/dist/sync/records.js +118 -120
- package/apps/runtime/dist/texts.js +44 -2
- package/apps/runtime/dist/tools/connections.js +112 -0
- package/apps/runtime/dist/tools/connector.js +157 -67
- package/apps/runtime/dist/tools/index.js +31 -15
- package/apps/runtime/dist/tools/mail.js +40 -11
- package/apps/runtime/dist/tools/pages.js +11 -5
- package/apps/runtime/dist/tools/plugin.js +43 -7
- package/apps/runtime/dist/tools/skills.js +1 -1
- package/apps/runtime/dist/tools/{project.js → space.js} +30 -25
- package/apps/runtime/dist/tools/store.js +3 -2
- package/apps/runtime/dist/widgets/step.js +10 -10
- package/apps/web/dist/assets/AboutDialog-DgfeipUc.js +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-BoYJvgIu.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-CKLgFL6r.js → ChangelogDialog-Duab4zTO.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-B3nto_26.js → CodeEditor-nxoOt8ge.js} +1 -1
- package/apps/web/dist/assets/EditorPage-ZrgGpYMC.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-zJCtixSi.js → FlowPreview-aMfwcPul.js} +1 -1
- package/apps/web/dist/assets/LangSwitch-DpD0inR4.js +1 -0
- package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +2 -0
- package/apps/web/dist/assets/NewWizardChannels-IB18afWN.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-rYbcmPGG.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +1 -0
- package/apps/web/dist/assets/PreviewPane-DviWTLfi.js +9 -0
- package/apps/web/dist/assets/PublicRunner-C2geZhhM.js +1 -0
- package/apps/web/dist/assets/ReadOnly-kSb_Kbdm.js +1 -0
- package/apps/web/dist/assets/SettingsPage-DM2h8N0J.js +2 -0
- package/apps/web/dist/assets/SetupPage-Wfyz6xH4.js +1 -0
- package/apps/web/dist/assets/SharePage-CyWQorWB.js +1 -0
- package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +1 -0
- package/apps/web/dist/assets/Skills-CnhpgoOA.js +9 -0
- package/apps/web/dist/assets/SpacePage-q4Bk3N7k.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-C2CE6CC3.js +2 -0
- package/apps/web/dist/assets/changelog-B6hN1Cp7.js +1 -0
- package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +1 -0
- package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +1 -0
- package/apps/web/dist/assets/code-editor-CfTGqOpp.js +2 -0
- package/apps/web/dist/assets/{code-xml-Hx7YxCg0.js → code-xml-B4kLFZSj.js} +1 -1
- package/apps/web/dist/assets/connection-sign-in-CIiv0t2p.js +1 -0
- package/apps/web/dist/assets/esm-Xwn4GtqG.js +7 -0
- package/apps/web/dist/assets/{eye-BkMFLnYu.js → eye-BpoKpIdt.js} +1 -1
- package/apps/web/dist/assets/host-BrP-ENHg.css +1 -0
- package/apps/web/dist/assets/host-DJ7-p0Sc.js +118 -0
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +55 -0
- package/apps/web/dist/assets/index-D18DvnxX.css +1 -0
- package/apps/web/dist/assets/index-D2akynS-.js +10 -0
- package/apps/web/dist/assets/logo-BpnjXTRy.js +1 -0
- package/apps/web/dist/assets/oss-credits-IdX5bc71.js +1 -0
- package/apps/web/dist/assets/{phone-DMfwuh9V.js → phone-Ctvf-Am-.js} +1 -1
- package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +1 -0
- package/apps/web/dist/assets/{runners-D5qz6b_s.js → runners-CyIvJIHr.js} +1 -1
- package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +1 -0
- package/apps/web/dist/assets/session-SXPtTWRK.js +2 -0
- package/apps/web/dist/assets/theme-CbTcTFWy.js +11 -0
- package/apps/web/dist/assets/ui-Uqnx1UpK.js +82 -0
- package/apps/web/dist/assets/{upload-DQJwLSGj.js → upload-BchUnQGV.js} +1 -1
- package/apps/web/dist/assets/{useMutation-C20c2EH3.js → useMutation-DEkZhp5c.js} +1 -1
- package/apps/web/dist/assets/{volume-2-CC5qamYT.js → volume-2-CU_oy81Z.js} +1 -1
- package/apps/web/dist/assets/with-selector-CoMyWBAX.js +1 -0
- package/apps/web/dist/index.html +17 -10
- package/apps/web/dist/mcp/flow.html +119 -64
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +20 -10
- package/node_modules/@engenty/wizards-shared/dist/assistant.d.ts +7 -1
- package/node_modules/@engenty/wizards-shared/dist/assistant.js +11 -1
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +236 -2
- package/node_modules/@engenty/wizards-shared/dist/connectors.js +52 -2
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +257 -8
- package/node_modules/@engenty/wizards-shared/dist/definition.js +113 -15
- package/node_modules/@engenty/wizards-shared/dist/discover.d.ts +21 -0
- package/node_modules/@engenty/wizards-shared/dist/discover.js +1 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +38 -2
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +38 -2
- package/node_modules/@engenty/wizards-shared/dist/fit.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/json-schema.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/live.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/live.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +0 -5
- package/node_modules/@engenty/wizards-shared/dist/marketplace.js +3 -1
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +115 -6
- package/node_modules/@engenty/wizards-shared/dist/run.js +135 -0
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +15 -1
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +14 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +42 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +29 -0
- package/node_modules/@engenty/wizards-shared/dist/skills.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/space-data.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/{projects.d.ts → spaces.d.ts} +39 -15
- package/node_modules/@engenty/wizards-shared/dist/{projects.js → spaces.js} +16 -9
- package/node_modules/@engenty/wizards-shared/dist/store.d.ts +7 -2
- package/node_modules/@engenty/wizards-shared/dist/surface.d.ts +35 -4
- package/node_modules/@engenty/wizards-shared/dist/surface.js +121 -3
- package/node_modules/@engenty/wizards-shared/dist/sync.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/theme-look.js +1 -1
- package/node_modules/@engenty/wizards-shared/dist/tiers.d.ts +195 -0
- package/node_modules/@engenty/wizards-shared/dist/tiers.js +98 -0
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.d.ts +2 -2
- package/node_modules/@engenty/wizards-shared/dist/wizard-package.js +3 -3
- package/package.json +4 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/plugin/skills/build-wizard/SKILL.md +1 -1
- package/apps/runtime/dist/services/projects.js +0 -473
- package/apps/web/dist/assets/AboutDialog-CLgnoYTI.js +0 -1
- package/apps/web/dist/assets/EditorPage-D9JDdAAI.js +0 -3
- package/apps/web/dist/assets/Marketplace-D4e0Oac9.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-B4N7GIYh.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-Dpt0Mzk8.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-CDoYVjRC.js +0 -1
- package/apps/web/dist/assets/PreviewPane-DPB5nEd5.js +0 -10
- package/apps/web/dist/assets/ProjectPage-408YOoNa.js +0 -10
- package/apps/web/dist/assets/PublicRunner-BZ66xdRX.js +0 -1
- package/apps/web/dist/assets/ReadOnly-C9oGMkUB.js +0 -1
- package/apps/web/dist/assets/SettingsPage-Dq3AZwJS.js +0 -2
- package/apps/web/dist/assets/SetupPage-CP3lbyZc.js +0 -1
- package/apps/web/dist/assets/SharePage-DdMm1Y8K.js +0 -1
- package/apps/web/dist/assets/SkillEditor-b5NMFB90.js +0 -1
- package/apps/web/dist/assets/changelog-82-DHogQ.js +0 -1
- package/apps/web/dist/assets/esm-BdxDT9Km.js +0 -7
- package/apps/web/dist/assets/i18n-CKKh3Pn0.js +0 -55
- package/apps/web/dist/assets/index-Cy2NHzAx.js +0 -49
- package/apps/web/dist/assets/index-wR_-1hfN.css +0 -1
- package/apps/web/dist/assets/lock-CGXM95Mi.js +0 -1
- package/apps/web/dist/assets/logo-CGNoptDg.js +0 -1
- package/apps/web/dist/assets/oss-credits-DpRWUPjD.js +0 -1
- package/apps/web/dist/assets/session-DRy0k0nh.js +0 -2
- package/apps/web/dist/assets/theme-DNPm6r4e.js +0 -11
- package/apps/web/dist/assets/ui-CwFQAfE-.js +0 -83
- /package/apps/runtime/dist/db/migrations/tenant/{0027_space_skill.sql → 0030_space_skill.sql} +0 -0
|
@@ -173,14 +173,14 @@ async function belongHere(ids) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
/** The organization a space synced with, when it is not the one the account is signed in to now. */
|
|
176
|
-
async function otherOrganization(
|
|
176
|
+
async function otherOrganization(spaceId) {
|
|
177
177
|
const account = await linkedAccount();
|
|
178
|
-
const owner = (await spaceOrganizations())[
|
|
178
|
+
const owner = (await spaceOrganizations())[spaceId];
|
|
179
179
|
return owner && account && owner.id !== account.tenantId ? owner : null;
|
|
180
180
|
}
|
|
181
181
|
/** A space of another organization stays here and never goes up to this one. */
|
|
182
|
-
export async function refuseOtherOrganization(
|
|
183
|
-
const owner = await otherOrganization(
|
|
182
|
+
export async function refuseOtherOrganization(spaceId) {
|
|
183
|
+
const owner = await otherOrganization(spaceId);
|
|
184
184
|
if (owner) {
|
|
185
185
|
throw new ServiceError("refused", note("spaceOfOtherOrganization", { organization: owner.name ?? owner.id }), { reason: "other_organization" });
|
|
186
186
|
}
|
|
@@ -196,8 +196,8 @@ export async function syncedSpaceIds() {
|
|
|
196
196
|
return rows.map((r) => r.key.slice("sync:space:".length));
|
|
197
197
|
}
|
|
198
198
|
/** Whether a space of this install syncs both ways. */
|
|
199
|
-
export async function spaceSyncs(
|
|
200
|
-
return twoWayActive() && (await readState(
|
|
199
|
+
export async function spaceSyncs(spaceId) {
|
|
200
|
+
return twoWayActive() && (await readState(spaceId)) !== null;
|
|
201
201
|
}
|
|
202
202
|
/** The two-way sync can run here: a runtime alone, an account linked, the switch on. */
|
|
203
203
|
export async function twoWayAvailable() {
|
|
@@ -213,7 +213,7 @@ async function overview(force = false) {
|
|
|
213
213
|
}
|
|
214
214
|
const value = await transport.overview();
|
|
215
215
|
overviewCache = { at: Date.now(), value };
|
|
216
|
-
setCloudSpaceLimit(value.limits.
|
|
216
|
+
setCloudSpaceLimit(value.limits.spaces);
|
|
217
217
|
return value;
|
|
218
218
|
}
|
|
219
219
|
// --- bases, conflicts, merges ---------------------------------------------------------------
|
|
@@ -222,13 +222,13 @@ async function baseOf(kind, item) {
|
|
|
222
222
|
where: and(eq(schema.syncBase.kind, kind), eq(schema.syncBase.item, item)),
|
|
223
223
|
})) ?? null);
|
|
224
224
|
}
|
|
225
|
-
async function setBase(
|
|
225
|
+
async function setBase(spaceId, kind, item, seq, record) {
|
|
226
226
|
await db
|
|
227
227
|
.insert(schema.syncBase)
|
|
228
|
-
.values({ kind, item,
|
|
228
|
+
.values({ kind, item, spaceId, seq, record })
|
|
229
229
|
.onConflictDoUpdate({
|
|
230
230
|
target: [schema.syncBase.kind, schema.syncBase.item],
|
|
231
|
-
set: {
|
|
231
|
+
set: { spaceId, seq, record },
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
234
|
const nameOf = (x) => {
|
|
@@ -311,31 +311,31 @@ async function mergeItem(kind, base, local, remote) {
|
|
|
311
311
|
* as it was, the delete counts; a clean merge that passes the checks is written here (and goes
|
|
312
312
|
* up with the next push) and noted; anything else waits as a conflict.
|
|
313
313
|
*/
|
|
314
|
-
async function reconcile(
|
|
314
|
+
async function reconcile(spaceId, kind, item, local, remote, remoteSeq) {
|
|
315
315
|
const base = await baseOf(kind, item);
|
|
316
316
|
const baseRecord = base?.record ?? null;
|
|
317
317
|
if (same(local, remote)) {
|
|
318
|
-
await setBase(
|
|
318
|
+
await setBase(spaceId, kind, item, remoteSeq, remote);
|
|
319
319
|
return "same";
|
|
320
320
|
}
|
|
321
321
|
if (base && same(local, baseRecord)) {
|
|
322
|
-
await applyItems([{ kind, item,
|
|
323
|
-
await setBase(
|
|
322
|
+
await applyItems([{ kind, item, spaceId, record: remote }], { quiet: true });
|
|
323
|
+
await setBase(spaceId, kind, item, remoteSeq, remote);
|
|
324
324
|
return "remote";
|
|
325
325
|
}
|
|
326
326
|
if (base && same(remote, baseRecord)) {
|
|
327
|
-
await setBase(
|
|
328
|
-
await notePending(
|
|
327
|
+
await setBase(spaceId, kind, item, remoteSeq, remote);
|
|
328
|
+
await notePending(spaceId, kind, item);
|
|
329
329
|
return "local";
|
|
330
330
|
}
|
|
331
331
|
if (local && remote) {
|
|
332
332
|
const m = await mergeItem(kind, baseRecord, local, remote);
|
|
333
333
|
if (!m.conflicts.length && !m.issues.length) {
|
|
334
|
-
await applyItems([{ kind, item,
|
|
335
|
-
await setBase(
|
|
334
|
+
await applyItems([{ kind, item, spaceId, record: m.value }], { quiet: false });
|
|
335
|
+
await setBase(spaceId, kind, item, remoteSeq, remote);
|
|
336
336
|
await db.insert(schema.syncMerge).values({
|
|
337
337
|
id: nanoid(12),
|
|
338
|
-
|
|
338
|
+
spaceId,
|
|
339
339
|
kind,
|
|
340
340
|
item,
|
|
341
341
|
local: placesChanged(baseRecord ?? {}, local),
|
|
@@ -349,7 +349,7 @@ async function reconcile(projectId, kind, item, local, remote, remoteSeq) {
|
|
|
349
349
|
.insert(schema.syncConflict)
|
|
350
350
|
.values({
|
|
351
351
|
id: nanoid(12),
|
|
352
|
-
|
|
352
|
+
spaceId,
|
|
353
353
|
kind,
|
|
354
354
|
item,
|
|
355
355
|
seq: remoteSeq,
|
|
@@ -364,15 +364,15 @@ async function reconcile(projectId, kind, item, local, remote, remoteSeq) {
|
|
|
364
364
|
return "conflict";
|
|
365
365
|
}
|
|
366
366
|
// --- push and pull --------------------------------------------------------------------------
|
|
367
|
-
async function conflicted(
|
|
367
|
+
async function conflicted(spaceId) {
|
|
368
368
|
const rows = await db.query.syncConflict.findMany({
|
|
369
|
-
where: eq(schema.syncConflict.
|
|
369
|
+
where: eq(schema.syncConflict.spaceId, spaceId),
|
|
370
370
|
columns: { kind: true, item: true },
|
|
371
371
|
});
|
|
372
372
|
return new Set(rows.map((r) => seqKey(r.kind, r.item)));
|
|
373
373
|
}
|
|
374
374
|
/** What this install changed in the space and has not pushed: from its log, or all of it the first time. */
|
|
375
|
-
async function pending(
|
|
375
|
+
async function pending(spaceId, st) {
|
|
376
376
|
const out = new Map();
|
|
377
377
|
const logged = await db
|
|
378
378
|
.select({
|
|
@@ -381,7 +381,7 @@ async function pending(projectId, st) {
|
|
|
381
381
|
seq: schema.syncChange.seq,
|
|
382
382
|
})
|
|
383
383
|
.from(schema.syncChange)
|
|
384
|
-
.where(and(eq(schema.syncChange.
|
|
384
|
+
.where(and(eq(schema.syncChange.spaceId, spaceId), gt(schema.syncChange.seq, st.pushed)));
|
|
385
385
|
for (const x of logged) {
|
|
386
386
|
const key = seqKey(x.kind, x.item);
|
|
387
387
|
out.set(key, {
|
|
@@ -392,7 +392,7 @@ async function pending(projectId, st) {
|
|
|
392
392
|
}
|
|
393
393
|
if (!st.full) {
|
|
394
394
|
for (const kind of KIND_ORDER) {
|
|
395
|
-
for (const item of await KINDS[kind].list(
|
|
395
|
+
for (const item of await KINDS[kind].list(spaceId)) {
|
|
396
396
|
if (!out.has(seqKey(kind, item))) {
|
|
397
397
|
out.set(seqKey(kind, item), { kind, item, seq: 0 });
|
|
398
398
|
}
|
|
@@ -402,10 +402,10 @@ async function pending(projectId, st) {
|
|
|
402
402
|
return [...out.values()];
|
|
403
403
|
}
|
|
404
404
|
const CHUNK = 300;
|
|
405
|
-
async function push(
|
|
405
|
+
async function push(spaceId, st) {
|
|
406
406
|
for (let round = 0; round < 5; round++) {
|
|
407
|
-
const waiting = await conflicted(
|
|
408
|
-
const changed = (await pending(
|
|
407
|
+
const waiting = await conflicted(spaceId);
|
|
408
|
+
const changed = (await pending(spaceId, st)).filter((x) => !waiting.has(seqKey(x.kind, x.item)));
|
|
409
409
|
if (!changed.length) {
|
|
410
410
|
st.full = true;
|
|
411
411
|
return;
|
|
@@ -414,7 +414,7 @@ async function push(projectId, st) {
|
|
|
414
414
|
const items = [];
|
|
415
415
|
for (const x of changed) {
|
|
416
416
|
const read = await KINDS[x.kind].read(x.item);
|
|
417
|
-
if (read === "skip" || (read && read.
|
|
417
|
+
if (read === "skip" || (read && read.spaceId !== spaceId)) {
|
|
418
418
|
continue;
|
|
419
419
|
}
|
|
420
420
|
const base = await baseOf(x.kind, x.item);
|
|
@@ -430,21 +430,21 @@ async function push(projectId, st) {
|
|
|
430
430
|
...new Set(items.flatMap((x) => (x.record ? (KINDS[x.kind].blobs?.(x.record) ?? []) : []))),
|
|
431
431
|
];
|
|
432
432
|
for (let i = 0; i < hashes.length; i += 1000) {
|
|
433
|
-
for (const hash of await transport.missing(
|
|
434
|
-
await transport.putBlob(
|
|
433
|
+
for (const hash of await transport.missing(spaceId, hashes.slice(i, i + 1000))) {
|
|
434
|
+
await transport.putBlob(spaceId, hash, new Uint8Array(await getBlob(hash)));
|
|
435
435
|
}
|
|
436
436
|
}
|
|
437
437
|
const refusals = [];
|
|
438
438
|
for (let i = 0; i < items.length; i += CHUNK) {
|
|
439
439
|
const chunk = items.slice(i, i + CHUNK);
|
|
440
|
-
const answer = await transport.push(
|
|
440
|
+
const answer = await transport.push(spaceId, { schema: tenantSchemaVersion, items: chunk });
|
|
441
441
|
for (const r of answer.results) {
|
|
442
442
|
const sent = chunk.find((x) => x.kind === r.kind && x.item === r.item);
|
|
443
443
|
if (r.status === "taken") {
|
|
444
|
-
await setBase(
|
|
444
|
+
await setBase(spaceId, r.kind, r.item, r.seq, sent?.record ?? null);
|
|
445
445
|
}
|
|
446
446
|
else if (r.status === "conflict") {
|
|
447
|
-
await reconcile(
|
|
447
|
+
await reconcile(spaceId, r.kind, r.item, sent?.record ?? null, r.record, r.seq);
|
|
448
448
|
}
|
|
449
449
|
else {
|
|
450
450
|
refusals.push(`${KINDS[r.kind].title(sent?.record ?? null, r.item)}: ${r.message}`);
|
|
@@ -453,26 +453,26 @@ async function push(projectId, st) {
|
|
|
453
453
|
}
|
|
454
454
|
st.pushed = top;
|
|
455
455
|
st.full = true;
|
|
456
|
-
await dropPushed(
|
|
456
|
+
await dropPushed(spaceId, top);
|
|
457
457
|
if (refusals.length) {
|
|
458
458
|
st.error = {
|
|
459
459
|
message: noteText(note("syncChangeRefused", { detail: refusals.slice(0, 3).join("; ") }), "en"),
|
|
460
460
|
reason: "refused",
|
|
461
461
|
at: new Date().toISOString(),
|
|
462
462
|
};
|
|
463
|
-
lastRefusals.set(
|
|
463
|
+
lastRefusals.set(spaceId, refusals);
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
}
|
|
467
467
|
/** Why the last push of a space was not taken, item by item, for the studio. */
|
|
468
468
|
const lastRefusals = new Map();
|
|
469
|
-
async function pull(
|
|
469
|
+
async function pull(spaceId, st) {
|
|
470
470
|
const changes = new Map();
|
|
471
471
|
let since = st.pulled;
|
|
472
472
|
let cursor;
|
|
473
473
|
let next = since;
|
|
474
474
|
for (;;) {
|
|
475
|
-
const answer = await transport.pull(
|
|
475
|
+
const answer = await transport.pull(spaceId, since, cursor);
|
|
476
476
|
for (const c of answer.changes) {
|
|
477
477
|
changes.set(seqKey(c.kind, c.item), c);
|
|
478
478
|
}
|
|
@@ -494,18 +494,18 @@ async function pull(projectId, st) {
|
|
|
494
494
|
for (const c of changes.values()) {
|
|
495
495
|
for (const hash of c.record ? (KINDS[c.kind].blobs?.(c.record) ?? []) : []) {
|
|
496
496
|
if (!(await hasBlob(hash))) {
|
|
497
|
-
await putBlobOf(hash, await transport.getBlob(
|
|
497
|
+
await putBlobOf(hash, await transport.getBlob(spaceId, hash));
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
|
-
const waiting = await conflicted(
|
|
502
|
-
const mine = new Set((await pending(
|
|
501
|
+
const waiting = await conflicted(spaceId);
|
|
502
|
+
const mine = new Set((await pending(spaceId, { ...st, full: true })).map((x) => seqKey(x.kind, x.item)));
|
|
503
503
|
const direct = [];
|
|
504
504
|
for (const c of changes.values()) {
|
|
505
505
|
const key = seqKey(c.kind, c.item);
|
|
506
|
-
if (c.kind === "space" && c.item ===
|
|
506
|
+
if (c.kind === "space" && c.item === spaceId && c.record === null) {
|
|
507
507
|
// The space went in the cloud: the copy here stays, and syncs no more.
|
|
508
|
-
await stopSpace(
|
|
508
|
+
await stopSpace(spaceId);
|
|
509
509
|
return;
|
|
510
510
|
}
|
|
511
511
|
if (waiting.has(key)) {
|
|
@@ -521,18 +521,18 @@ async function pull(projectId, st) {
|
|
|
521
521
|
}
|
|
522
522
|
const local = read?.record ?? null;
|
|
523
523
|
if (mine.has(key)) {
|
|
524
|
-
await reconcile(
|
|
524
|
+
await reconcile(spaceId, c.kind, c.item, local, c.record, c.seq);
|
|
525
525
|
continue;
|
|
526
526
|
}
|
|
527
527
|
if (same(local, c.record)) {
|
|
528
|
-
await setBase(
|
|
528
|
+
await setBase(spaceId, c.kind, c.item, c.seq, c.record);
|
|
529
529
|
continue;
|
|
530
530
|
}
|
|
531
|
-
direct.push({ kind: c.kind, item: c.item,
|
|
531
|
+
direct.push({ kind: c.kind, item: c.item, spaceId, record: c.record, seq: c.seq });
|
|
532
532
|
}
|
|
533
533
|
await applyItems(direct, { quiet: true });
|
|
534
534
|
for (const x of direct) {
|
|
535
|
-
await setBase(
|
|
535
|
+
await setBase(spaceId, x.kind, x.item, x.seq, x.record);
|
|
536
536
|
}
|
|
537
537
|
st.pulled = Math.max(st.pulled, next);
|
|
538
538
|
}
|
|
@@ -541,25 +541,25 @@ const running = new Map();
|
|
|
541
541
|
const again = new Map();
|
|
542
542
|
const widen = (a, b) => (!a || a === b ? b : "both");
|
|
543
543
|
/** Pushes and pulls a space; one run at a time, a call meanwhile runs once more after it. */
|
|
544
|
-
export function syncSpace(
|
|
545
|
-
const busy = running.get(
|
|
544
|
+
export function syncSpace(spaceId, what = "both") {
|
|
545
|
+
const busy = running.get(spaceId);
|
|
546
546
|
if (busy) {
|
|
547
|
-
again.set(
|
|
547
|
+
again.set(spaceId, widen(again.get(spaceId), what));
|
|
548
548
|
return busy;
|
|
549
549
|
}
|
|
550
550
|
const run = (async () => {
|
|
551
551
|
let next = what;
|
|
552
552
|
while (next) {
|
|
553
|
-
again.delete(
|
|
554
|
-
await runSync(
|
|
555
|
-
next = again.get(
|
|
553
|
+
again.delete(spaceId);
|
|
554
|
+
await runSync(spaceId, next);
|
|
555
|
+
next = again.get(spaceId);
|
|
556
556
|
}
|
|
557
|
-
})().finally(() => running.delete(
|
|
558
|
-
running.set(
|
|
557
|
+
})().finally(() => running.delete(spaceId));
|
|
558
|
+
running.set(spaceId, run);
|
|
559
559
|
return run;
|
|
560
560
|
}
|
|
561
|
-
async function runSync(
|
|
562
|
-
const st = await readState(
|
|
561
|
+
async function runSync(spaceId, what) {
|
|
562
|
+
const st = await readState(spaceId);
|
|
563
563
|
if (!st) {
|
|
564
564
|
return;
|
|
565
565
|
}
|
|
@@ -574,25 +574,25 @@ async function runSync(projectId, what) {
|
|
|
574
574
|
};
|
|
575
575
|
return;
|
|
576
576
|
}
|
|
577
|
-
const here = await db.query.
|
|
578
|
-
where: eq(schema.
|
|
577
|
+
const here = await db.query.space.findFirst({
|
|
578
|
+
where: eq(schema.space.id, spaceId),
|
|
579
579
|
columns: { id: true },
|
|
580
580
|
});
|
|
581
|
-
const inCloud = ov.spaces.some((s) => s.id ===
|
|
581
|
+
const inCloud = ov.spaces.some((s) => s.id === spaceId);
|
|
582
582
|
if (!here && !inCloud) {
|
|
583
583
|
return;
|
|
584
584
|
}
|
|
585
585
|
st.error = null;
|
|
586
|
-
lastRefusals.delete(
|
|
586
|
+
lastRefusals.delete(spaceId);
|
|
587
587
|
// A space this install has goes up as a whole once before anything comes down for it.
|
|
588
588
|
if (what !== "push" && inCloud && (st.full || !here)) {
|
|
589
|
-
await pull(
|
|
589
|
+
await pull(spaceId, st);
|
|
590
590
|
if (!here) {
|
|
591
591
|
st.full = true;
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
if (what !== "pull") {
|
|
595
|
-
await push(
|
|
595
|
+
await push(spaceId, st);
|
|
596
596
|
if (!inCloud) {
|
|
597
597
|
overviewCache = null;
|
|
598
598
|
}
|
|
@@ -606,13 +606,13 @@ async function runSync(projectId, what) {
|
|
|
606
606
|
at: new Date().toISOString(),
|
|
607
607
|
};
|
|
608
608
|
if (!(err instanceof ServiceError)) {
|
|
609
|
-
console.error(`[sync] ${
|
|
609
|
+
console.error(`[sync] ${spaceId}:`, err);
|
|
610
610
|
}
|
|
611
611
|
}
|
|
612
612
|
finally {
|
|
613
613
|
// The space may have been turned off meanwhile.
|
|
614
|
-
if (await readState(
|
|
615
|
-
await writeState(
|
|
614
|
+
if (await readState(spaceId)) {
|
|
615
|
+
await writeState(spaceId, st);
|
|
616
616
|
}
|
|
617
617
|
changed();
|
|
618
618
|
}
|
|
@@ -631,7 +631,7 @@ export async function syncAll() {
|
|
|
631
631
|
}
|
|
632
632
|
const excluded = new Set((await readSetting(EXCLUDED)) ?? []);
|
|
633
633
|
const known = new Set(await syncedSpaceIds());
|
|
634
|
-
const local = await db.query.
|
|
634
|
+
const local = await db.query.space.findMany({ columns: { id: true } });
|
|
635
635
|
const ov = await overview(true).catch(() => null);
|
|
636
636
|
const ids = [...new Set([...local.map((p) => p.id), ...(ov?.spaces ?? []).map((s) => s.id)])];
|
|
637
637
|
// Spaces that synced before their organization was noted.
|
|
@@ -653,31 +653,31 @@ export async function startTwoWay() {
|
|
|
653
653
|
await syncAll();
|
|
654
654
|
}
|
|
655
655
|
/** A space starts to sync both ways: one this install synced one way becomes the cloud's own. */
|
|
656
|
-
export async function startSpace(
|
|
657
|
-
await refuseOtherOrganization(
|
|
658
|
-
const excluded = ((await readSetting(EXCLUDED)) ?? []).filter((x) => x !==
|
|
656
|
+
export async function startSpace(spaceId) {
|
|
657
|
+
await refuseOtherOrganization(spaceId);
|
|
658
|
+
const excluded = ((await readSetting(EXCLUDED)) ?? []).filter((x) => x !== spaceId);
|
|
659
659
|
await writeSetting(EXCLUDED, excluded);
|
|
660
|
-
if (!(await readState(
|
|
661
|
-
const here = await db.query.
|
|
662
|
-
where: eq(schema.
|
|
660
|
+
if (!(await readState(spaceId))) {
|
|
661
|
+
const here = await db.query.space.findFirst({
|
|
662
|
+
where: eq(schema.space.id, spaceId),
|
|
663
663
|
columns: { id: true },
|
|
664
664
|
});
|
|
665
665
|
if (here) {
|
|
666
|
-
await transport.adopt(
|
|
666
|
+
await transport.adopt(spaceId).catch(() => undefined);
|
|
667
667
|
}
|
|
668
|
-
await writeState(
|
|
668
|
+
await writeState(spaceId, { pushed: 0, pulled: 0, full: false, at: null, error: null });
|
|
669
669
|
}
|
|
670
|
-
await belongHere([
|
|
671
|
-
await syncSpace(
|
|
670
|
+
await belongHere([spaceId]);
|
|
671
|
+
await syncSpace(spaceId);
|
|
672
672
|
}
|
|
673
673
|
/** The space syncs no more; what it holds here stays. */
|
|
674
|
-
export async function stopSpace(
|
|
674
|
+
export async function stopSpace(spaceId) {
|
|
675
675
|
const excluded = new Set((await readSetting(EXCLUDED)) ?? []);
|
|
676
|
-
excluded.add(
|
|
676
|
+
excluded.add(spaceId);
|
|
677
677
|
await writeSetting(EXCLUDED, [...excluded]);
|
|
678
|
-
await deleteSetting(stateKey(
|
|
678
|
+
await deleteSetting(stateKey(spaceId));
|
|
679
679
|
for (const table of [schema.syncBase, schema.syncConflict, schema.syncMerge, schema.syncChange]) {
|
|
680
|
-
await db.delete(table).where(eq(table.
|
|
680
|
+
await db.delete(table).where(eq(table.spaceId, spaceId));
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
683
|
// --- the studio's saves and loads -------------------------------------------------------------
|
|
@@ -719,16 +719,16 @@ export async function beforeStudioLoad() {
|
|
|
719
719
|
await Promise.race([work, new Promise((r) => setTimeout(r, LOAD_WAIT_MS).unref?.())]);
|
|
720
720
|
}
|
|
721
721
|
/** Pushes the space, then has the cloud publish its draft, which is now this install's. */
|
|
722
|
-
export async function publishInCloud(
|
|
723
|
-
await syncSpace(
|
|
724
|
-
const st = await readState(
|
|
722
|
+
export async function publishInCloud(spaceId, wizardId) {
|
|
723
|
+
await syncSpace(spaceId, "push");
|
|
724
|
+
const st = await readState(spaceId);
|
|
725
725
|
if (st?.error) {
|
|
726
726
|
throw new ServiceError("refused", st.error.message, { reason: st.error.reason ?? "refused" });
|
|
727
727
|
}
|
|
728
|
-
return transport.publish(
|
|
728
|
+
return transport.publish(spaceId, wizardId);
|
|
729
729
|
}
|
|
730
|
-
export function rotateInCloudSpace(
|
|
731
|
-
return transport.rotate(
|
|
730
|
+
export function rotateInCloudSpace(spaceId, wizardId) {
|
|
731
|
+
return transport.rotate(spaceId, wizardId);
|
|
732
732
|
}
|
|
733
733
|
// --- what the studio shows and asks ---------------------------------------------------------
|
|
734
734
|
function sayError(e) {
|
|
@@ -743,7 +743,7 @@ async function conflictView(row) {
|
|
|
743
743
|
: [];
|
|
744
744
|
return {
|
|
745
745
|
id: row.id,
|
|
746
|
-
spaceId: row.
|
|
746
|
+
spaceId: row.spaceId,
|
|
747
747
|
kind: row.kind,
|
|
748
748
|
item: row.item,
|
|
749
749
|
title: def.title(local ?? remote, row.item),
|
|
@@ -757,7 +757,7 @@ export async function syncView() {
|
|
|
757
757
|
if (!available) {
|
|
758
758
|
return { available, spaces: [], conflicts: [], merges: [], refusals: {} };
|
|
759
759
|
}
|
|
760
|
-
const local = await db.query.
|
|
760
|
+
const local = await db.query.space.findMany({ columns: { id: true, name: true } });
|
|
761
761
|
const cloud = await overview().catch(() => null);
|
|
762
762
|
const account = await linkedAccount();
|
|
763
763
|
const owners = await spaceOrganizations();
|
|
@@ -783,8 +783,8 @@ export async function syncView() {
|
|
|
783
783
|
on: st !== null,
|
|
784
784
|
syncedAt: st?.at ?? null,
|
|
785
785
|
waiting,
|
|
786
|
-
conflicts: conflicts.filter((c) => c.
|
|
787
|
-
merges: merges.filter((m) => m.
|
|
786
|
+
conflicts: conflicts.filter((c) => c.spaceId === id).length,
|
|
787
|
+
merges: merges.filter((m) => m.spaceId === id).length,
|
|
788
788
|
error: sayError(st?.error ?? null),
|
|
789
789
|
organization: owners[id] && owners[id].id !== account?.tenantId
|
|
790
790
|
? (owners[id].name ?? owners[id].id)
|
|
@@ -797,7 +797,7 @@ export async function syncView() {
|
|
|
797
797
|
conflicts: await Promise.all(conflicts.map(conflictView)),
|
|
798
798
|
merges: merges.map((m) => ({
|
|
799
799
|
id: m.id,
|
|
800
|
-
spaceId: m.
|
|
800
|
+
spaceId: m.spaceId,
|
|
801
801
|
kind: m.kind,
|
|
802
802
|
item: m.item,
|
|
803
803
|
title: KINDS[m.kind].title(m.before.local ?? m.before.remote, m.item),
|
|
@@ -823,8 +823,8 @@ export async function resolveConflict(id, how) {
|
|
|
823
823
|
const local = row.local ?? null;
|
|
824
824
|
const remote = row.remote ?? null;
|
|
825
825
|
const settle = async (record, quiet) => {
|
|
826
|
-
await applyItems([{ kind, item: row.item,
|
|
827
|
-
await setBase(row.
|
|
826
|
+
await applyItems([{ kind, item: row.item, spaceId: row.spaceId, record }], { quiet });
|
|
827
|
+
await setBase(row.spaceId, kind, row.item, row.seq, remote);
|
|
828
828
|
await db.delete(schema.syncConflict).where(eq(schema.syncConflict.id, row.id));
|
|
829
829
|
};
|
|
830
830
|
if ("take" in how && how.take === "remote") {
|
|
@@ -835,9 +835,9 @@ export async function resolveConflict(id, how) {
|
|
|
835
835
|
.where(and(eq(schema.syncChange.kind, kind), eq(schema.syncChange.item, row.item)));
|
|
836
836
|
}
|
|
837
837
|
else if ("take" in how) {
|
|
838
|
-
await setBase(row.
|
|
838
|
+
await setBase(row.spaceId, kind, row.item, row.seq, remote);
|
|
839
839
|
await db.delete(schema.syncConflict).where(eq(schema.syncConflict.id, row.id));
|
|
840
|
-
await notePending(row.
|
|
840
|
+
await notePending(row.spaceId, kind, row.item);
|
|
841
841
|
}
|
|
842
842
|
else {
|
|
843
843
|
let record;
|
|
@@ -857,12 +857,12 @@ export async function resolveConflict(id, how) {
|
|
|
857
857
|
}
|
|
858
858
|
await settle(record, false);
|
|
859
859
|
}
|
|
860
|
-
await syncSpace(row.
|
|
860
|
+
await syncSpace(row.spaceId, "push");
|
|
861
861
|
}
|
|
862
862
|
/** Every conflict of a space settled with the cloud's version. */
|
|
863
|
-
export async function keepCloudForAll(
|
|
863
|
+
export async function keepCloudForAll(spaceId) {
|
|
864
864
|
const rows = await db.query.syncConflict.findMany({
|
|
865
|
-
where: eq(schema.syncConflict.
|
|
865
|
+
where: eq(schema.syncConflict.spaceId, spaceId),
|
|
866
866
|
columns: { id: true },
|
|
867
867
|
});
|
|
868
868
|
for (const r of rows) {
|
|
@@ -876,9 +876,9 @@ export async function undoMerge(id, take) {
|
|
|
876
876
|
if (!m) {
|
|
877
877
|
throw new ServiceError("not_found", note("notFound"));
|
|
878
878
|
}
|
|
879
|
-
await applyItems([{ kind: m.kind, item: m.item,
|
|
879
|
+
await applyItems([{ kind: m.kind, item: m.item, spaceId: m.spaceId, record: m.before[take] }], { quiet: false });
|
|
880
880
|
await db.delete(schema.syncMerge).where(eq(schema.syncMerge.id, id));
|
|
881
|
-
await syncSpace(m.
|
|
881
|
+
await syncSpace(m.spaceId, "push");
|
|
882
882
|
}
|
|
883
883
|
export async function mergesSeen(ids) {
|
|
884
884
|
if (ids.length) {
|
|
@@ -959,8 +959,8 @@ export async function sendBeforeSwitch() {
|
|
|
959
959
|
const st = await readState(id);
|
|
960
960
|
const waiting = st ? (await pending(id, st)).filter((x) => x.seq > 0 || !st.full).length : 0;
|
|
961
961
|
if (st?.error || waiting) {
|
|
962
|
-
const here = await db.query.
|
|
963
|
-
where: eq(schema.
|
|
962
|
+
const here = await db.query.space.findFirst({
|
|
963
|
+
where: eq(schema.space.id, id),
|
|
964
964
|
columns: { name: true },
|
|
965
965
|
});
|
|
966
966
|
stuck.push({
|
|
@@ -983,11 +983,11 @@ export async function noteSyncedSpaces() {
|
|
|
983
983
|
.where(like(control.setting.key, "cloud:%"));
|
|
984
984
|
const wizards = sent.length
|
|
985
985
|
? await db
|
|
986
|
-
.select({
|
|
986
|
+
.select({ spaceId: schema.wizard.spaceId })
|
|
987
987
|
.from(schema.wizard)
|
|
988
988
|
.where(inArray(schema.wizard.id, sent.map((r) => r.key.slice("cloud:".length))))
|
|
989
989
|
: [];
|
|
990
|
-
await belongHere([...new Set([...(await syncedSpaceIds()), ...wizards.map((w) => w.
|
|
990
|
+
await belongHere([...new Set([...(await syncedSpaceIds()), ...wizards.map((w) => w.spaceId)])]);
|
|
991
991
|
}
|
|
992
992
|
/**
|
|
993
993
|
* After a switch: spaces that never synced with any organization stay on this computer only,
|
|
@@ -995,7 +995,7 @@ export async function noteSyncedSpaces() {
|
|
|
995
995
|
*/
|
|
996
996
|
export async function keepUnsyncedHere() {
|
|
997
997
|
const owners = await spaceOrganizations();
|
|
998
|
-
const local = await db.query.
|
|
998
|
+
const local = await db.query.space.findMany({ columns: { id: true } });
|
|
999
999
|
await writeSetting(EXCLUDED, local.map((p) => p.id).filter((id) => !owners[id]));
|
|
1000
1000
|
}
|
|
1001
1001
|
/** The account was unlinked: nothing syncs any more, and what was kept of the cloud goes. */
|
|
@@ -1013,18 +1013,18 @@ const LIVE_SEQ = "sync:live-seq";
|
|
|
1013
1013
|
const LIVE_PULL_MS = 2000;
|
|
1014
1014
|
const livePulled = new Map();
|
|
1015
1015
|
const livePending = new Map();
|
|
1016
|
-
function pullSoon(tenant,
|
|
1017
|
-
if (livePending.has(
|
|
1016
|
+
function pullSoon(tenant, spaceId) {
|
|
1017
|
+
if (livePending.has(spaceId)) {
|
|
1018
1018
|
return;
|
|
1019
1019
|
}
|
|
1020
|
-
const wait = Math.max(0, LIVE_PULL_MS - (Date.now() - (livePulled.get(
|
|
1020
|
+
const wait = Math.max(0, LIVE_PULL_MS - (Date.now() - (livePulled.get(spaceId) ?? 0)));
|
|
1021
1021
|
const timer = setTimeout(() => {
|
|
1022
|
-
livePending.delete(
|
|
1023
|
-
livePulled.set(
|
|
1024
|
-
void withTenantOf(tenant, () => syncSpace(
|
|
1022
|
+
livePending.delete(spaceId);
|
|
1023
|
+
livePulled.set(spaceId, Date.now());
|
|
1024
|
+
void withTenantOf(tenant, () => syncSpace(spaceId, "pull")).catch((err) => console.error(`[sync] live pull of ${spaceId}:`, err));
|
|
1025
1025
|
}, wait);
|
|
1026
1026
|
timer.unref?.();
|
|
1027
|
-
livePending.set(
|
|
1027
|
+
livePending.set(spaceId, timer);
|
|
1028
1028
|
}
|
|
1029
1029
|
/** What the cloud's live call said: pulls the spaces that sync here and changed there. */
|
|
1030
1030
|
async function heardFromCloud(tenant, e) {
|