@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
|
@@ -4,23 +4,24 @@ import { editCells, SPACE_DATA_LIMITS, } from "@engenty/wizards-shared/space-dat
|
|
|
4
4
|
import { rowKey } from "@engenty/wizards-shared/store";
|
|
5
5
|
import { and, asc, count, desc, eq, inArray, isNotNull, isNull, max } from "drizzle-orm";
|
|
6
6
|
import { nanoid } from "nanoid";
|
|
7
|
+
import { assertRwx, pageResources, readable, tableResources } from "../broker/rwx.js";
|
|
7
8
|
import { db, schema } from "../db/client.js";
|
|
8
9
|
import { saidOf } from "../model-errors.js";
|
|
9
10
|
import { currentTenant } from "../tenants/tenant.js";
|
|
10
11
|
import { serverText } from "../texts.js";
|
|
11
|
-
import {
|
|
12
|
+
import { requireWritableSpace, spaceWritable } from "./access.js";
|
|
12
13
|
import { notFound, ServiceError } from "./errors.js";
|
|
13
14
|
import { filePaths, freeSlug, knowledgePage, pageTree, tablePaths } from "./knowledge.js";
|
|
14
|
-
import { queueIndex } from "./project-index.js";
|
|
15
|
-
import { ownedProject } from "./projects.js";
|
|
16
15
|
import { itemCategoriesOf, setItemCategories, syncTableRowCategories } from "./space-categories.js";
|
|
16
|
+
import { queueIndex } from "./space-index.js";
|
|
17
|
+
import { ownedSpace } from "./spaces.js";
|
|
17
18
|
/** A wizard of the space, or null for the space's own. */
|
|
18
|
-
async function ownerOf(
|
|
19
|
+
async function ownerOf(spaceId, wizardId) {
|
|
19
20
|
if (!wizardId) {
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
const w = await db.query.wizard.findFirst({
|
|
23
|
-
where: and(eq(schema.wizard.id, wizardId), eq(schema.wizard.
|
|
24
|
+
where: and(eq(schema.wizard.id, wizardId), eq(schema.wizard.spaceId, spaceId)),
|
|
24
25
|
columns: { id: true },
|
|
25
26
|
});
|
|
26
27
|
if (!w) {
|
|
@@ -41,12 +42,15 @@ export function checkColumns(columns) {
|
|
|
41
42
|
}
|
|
42
43
|
return parsed.data;
|
|
43
44
|
}
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Data: the tables and pages the space's wizards keep that `who` may read, and the wizards to
|
|
47
|
+
* name whose they are.
|
|
48
|
+
*/
|
|
49
|
+
export async function listSpaceData(userId, spaceId, who) {
|
|
50
|
+
const space = await ownedSpace(userId, spaceId);
|
|
47
51
|
const [tables, rows, pages, wizards] = await Promise.all([
|
|
48
52
|
db.query.spaceTable.findMany({
|
|
49
|
-
where: and(eq(schema.spaceTable.
|
|
53
|
+
where: and(eq(schema.spaceTable.spaceId, space.id), isNotNull(schema.spaceTable.wizardId)),
|
|
50
54
|
orderBy: [asc(schema.spaceTable.title)],
|
|
51
55
|
columns: { id: true, wizardId: true, list: true, title: true, updatedAt: true },
|
|
52
56
|
}),
|
|
@@ -54,26 +58,34 @@ export async function listSpaceData(userId, projectId) {
|
|
|
54
58
|
.select({ tableId: schema.spaceTableRow.tableId, n: count() })
|
|
55
59
|
.from(schema.spaceTableRow)
|
|
56
60
|
.innerJoin(schema.spaceTable, eq(schema.spaceTable.id, schema.spaceTableRow.tableId))
|
|
57
|
-
.where(eq(schema.spaceTable.
|
|
61
|
+
.where(eq(schema.spaceTable.spaceId, space.id))
|
|
58
62
|
.groupBy(schema.spaceTableRow.tableId),
|
|
59
63
|
db.query.spacePage.findMany({
|
|
60
|
-
where: and(eq(schema.spacePage.
|
|
64
|
+
where: and(eq(schema.spacePage.spaceId, space.id), isNotNull(schema.spacePage.wizardId)),
|
|
61
65
|
orderBy: [asc(schema.spacePage.title)],
|
|
62
66
|
columns: { id: true, wizardId: true, title: true, updatedAt: true },
|
|
63
67
|
}),
|
|
64
68
|
db.query.wizard.findMany({
|
|
65
|
-
where: eq(schema.wizard.
|
|
69
|
+
where: eq(schema.wizard.spaceId, space.id),
|
|
66
70
|
orderBy: [desc(schema.wizard.updatedAt)],
|
|
67
71
|
columns: { id: true, title: true },
|
|
68
72
|
}),
|
|
69
73
|
]);
|
|
74
|
+
const [okTables, okPages] = await Promise.all([
|
|
75
|
+
readable(space.id, who, await tableResources(tables.map((t) => t.id))),
|
|
76
|
+
readable(space.id, who, await pageResources(pages.map((p) => p.id))),
|
|
77
|
+
]);
|
|
70
78
|
return {
|
|
71
|
-
tables: tables
|
|
79
|
+
tables: tables
|
|
80
|
+
.filter((t) => okTables.has(t.id))
|
|
81
|
+
.map((t) => ({
|
|
72
82
|
...t,
|
|
73
83
|
rows: rows.find((r) => r.tableId === t.id)?.n ?? 0,
|
|
74
84
|
updatedAt: t.updatedAt.toISOString(),
|
|
75
85
|
})),
|
|
76
|
-
pages: pages
|
|
86
|
+
pages: pages
|
|
87
|
+
.filter((p) => okPages.has(p.id))
|
|
88
|
+
.map((p) => ({ ...p, updatedAt: p.updatedAt.toISOString() })),
|
|
77
89
|
wizards,
|
|
78
90
|
};
|
|
79
91
|
}
|
|
@@ -89,7 +101,7 @@ async function tableRow(tableId) {
|
|
|
89
101
|
}
|
|
90
102
|
async function writableTable(tableId) {
|
|
91
103
|
const table = await tableRow(tableId);
|
|
92
|
-
await
|
|
104
|
+
await requireWritableSpace(table.spaceId);
|
|
93
105
|
return table;
|
|
94
106
|
}
|
|
95
107
|
/** A person changed a table: when a plugin wrote it, the plugin no longer does. */
|
|
@@ -99,19 +111,19 @@ async function touchTable(table) {
|
|
|
99
111
|
.set({ updatedAt: new Date(), ...(table.origin && !table.kept ? { kept: true } : {}) })
|
|
100
112
|
.where(eq(schema.spaceTable.id, table.id));
|
|
101
113
|
}
|
|
102
|
-
async function tableCount(
|
|
114
|
+
async function tableCount(spaceId) {
|
|
103
115
|
const [{ n }] = await db
|
|
104
116
|
.select({ n: count() })
|
|
105
117
|
.from(schema.spaceTable)
|
|
106
|
-
.where(eq(schema.spaceTable.
|
|
118
|
+
.where(eq(schema.spaceTable.spaceId, spaceId));
|
|
107
119
|
if (n >= SPACE_DATA_LIMITS.tables) {
|
|
108
120
|
throw new ServiceError("refused", note("spaceMostTables", { count: SPACE_DATA_LIMITS.tables }));
|
|
109
121
|
}
|
|
110
122
|
}
|
|
111
|
-
export async function createTable(userId,
|
|
112
|
-
const
|
|
113
|
-
await
|
|
114
|
-
await tableCount(
|
|
123
|
+
export async function createTable(userId, spaceId, input, lang = "en") {
|
|
124
|
+
const space = await ownedSpace(userId, spaceId);
|
|
125
|
+
await requireWritableSpace(space.id);
|
|
126
|
+
await tableCount(space.id);
|
|
115
127
|
const columns = input.columns
|
|
116
128
|
? checkColumns(input.columns)
|
|
117
129
|
: input.format === "faq"
|
|
@@ -126,15 +138,15 @@ export async function createTable(userId, projectId, input, lang = "en") {
|
|
|
126
138
|
]
|
|
127
139
|
: [{ id: "name", name: "Name", type: "text" }];
|
|
128
140
|
const id = nanoid(12);
|
|
129
|
-
const wizardId = await ownerOf(
|
|
141
|
+
const wizardId = await ownerOf(space.id, input.wizardId);
|
|
130
142
|
const title = input.title.trim() || serverText(lang, "tableTitle");
|
|
131
143
|
await db.insert(schema.spaceTable).values({
|
|
132
144
|
id,
|
|
133
145
|
tenantId: currentTenant(),
|
|
134
|
-
|
|
146
|
+
spaceId: space.id,
|
|
135
147
|
wizardId,
|
|
136
148
|
title,
|
|
137
|
-
slug: wizardId ? null : await freeSlug(
|
|
149
|
+
slug: wizardId ? null : await freeSlug(space.id, title, "table"),
|
|
138
150
|
format: input.format ?? null,
|
|
139
151
|
columns,
|
|
140
152
|
});
|
|
@@ -145,13 +157,13 @@ async function tableKnowledge(table) {
|
|
|
145
157
|
return null;
|
|
146
158
|
}
|
|
147
159
|
const file = table.fileId
|
|
148
|
-
? await db.query.
|
|
149
|
-
where: eq(schema.
|
|
160
|
+
? await db.query.spaceFile.findFirst({
|
|
161
|
+
where: eq(schema.spaceFile.id, table.fileId),
|
|
150
162
|
columns: { id: true, name: true, mime: true },
|
|
151
163
|
})
|
|
152
164
|
: undefined;
|
|
153
165
|
return {
|
|
154
|
-
path: (await tablePaths(table.
|
|
166
|
+
path: (await tablePaths(table.spaceId)).get(table.id) ?? "",
|
|
155
167
|
categories: (await itemCategoriesOf([{ tableId: table.id }])).get(`t:${table.id}`) ?? [],
|
|
156
168
|
origin: table.origin,
|
|
157
169
|
originLabel: table.originLabel,
|
|
@@ -160,8 +172,8 @@ async function tableKnowledge(table) {
|
|
|
160
172
|
file: file ?? null,
|
|
161
173
|
};
|
|
162
174
|
}
|
|
163
|
-
export async function getTable(userId, tableId) {
|
|
164
|
-
const header = await getTableHeader(userId, tableId);
|
|
175
|
+
export async function getTable(userId, tableId, who) {
|
|
176
|
+
const header = await getTableHeader(userId, tableId, who);
|
|
165
177
|
const rows = await db.query.spaceTableRow.findMany({
|
|
166
178
|
where: eq(schema.spaceTableRow.tableId, header.id),
|
|
167
179
|
orderBy: [asc(schema.spaceTableRow.createdAt), asc(schema.spaceTableRow.id)],
|
|
@@ -169,24 +181,26 @@ export async function getTable(userId, tableId) {
|
|
|
169
181
|
return { ...header, rows: rows.map(rowView) };
|
|
170
182
|
}
|
|
171
183
|
/** A table without its rows: what a change of its title or columns needs (live/views.ts). */
|
|
172
|
-
export async function getTableHeader(userId, tableId) {
|
|
184
|
+
export async function getTableHeader(userId, tableId, who) {
|
|
173
185
|
const table = await tableRow(tableId);
|
|
174
|
-
const
|
|
186
|
+
const space = await ownedSpace(userId, table.spaceId);
|
|
187
|
+
await assertRwx(space.id, who, { kind: "table", id: table.id, fileId: table.fileId }, "r");
|
|
175
188
|
return {
|
|
176
189
|
id: table.id,
|
|
177
|
-
|
|
190
|
+
spaceId: table.spaceId,
|
|
178
191
|
wizardId: table.wizardId,
|
|
179
192
|
list: table.list,
|
|
180
193
|
title: table.title,
|
|
181
194
|
format: table.format,
|
|
182
195
|
columns: table.columns,
|
|
183
|
-
readOnly: !(await
|
|
196
|
+
readOnly: !(await spaceWritable(space)),
|
|
184
197
|
knowledge: await tableKnowledge(table),
|
|
185
198
|
};
|
|
186
199
|
}
|
|
187
200
|
/** One row of a table, as the table shows it; null when it is gone. */
|
|
188
|
-
export async function getRow(_userId, tableId, rowId) {
|
|
189
|
-
await tableRow(tableId);
|
|
201
|
+
export async function getRow(_userId, tableId, rowId, who) {
|
|
202
|
+
const table = await tableRow(tableId);
|
|
203
|
+
await assertRwx(table.spaceId, who, { kind: "table", id: table.id, fileId: table.fileId }, "r");
|
|
190
204
|
const row = await db.query.spaceTableRow.findFirst({
|
|
191
205
|
where: and(eq(schema.spaceTableRow.id, rowId), eq(schema.spaceTableRow.tableId, tableId)),
|
|
192
206
|
});
|
|
@@ -207,7 +221,7 @@ export async function updateTable(_userId, tableId, patch) {
|
|
|
207
221
|
throw new ServiceError("refused", note("tableBelongsOneWizard"));
|
|
208
222
|
}
|
|
209
223
|
const title = patch.title !== undefined ? patch.title.trim() || table.title : table.title;
|
|
210
|
-
const wizardId = patch.wizardId !== undefined ? await ownerOf(table.
|
|
224
|
+
const wizardId = patch.wizardId !== undefined ? await ownerOf(table.spaceId, patch.wizardId) : table.wizardId;
|
|
211
225
|
const changed = title !== table.title || patch.columns !== undefined || patch.format !== undefined;
|
|
212
226
|
await db
|
|
213
227
|
.update(schema.spaceTable)
|
|
@@ -215,7 +229,7 @@ export async function updateTable(_userId, tableId, patch) {
|
|
|
215
229
|
title,
|
|
216
230
|
wizardId,
|
|
217
231
|
...(title !== table.title || wizardId !== table.wizardId
|
|
218
|
-
? { slug: wizardId ? null : await freeSlug(table.
|
|
232
|
+
? { slug: wizardId ? null : await freeSlug(table.spaceId, title, "table", table.id) }
|
|
219
233
|
: {}),
|
|
220
234
|
...(patch.columns !== undefined ? { columns: checkColumns(patch.columns) } : {}),
|
|
221
235
|
...(patch.format !== undefined ? { format: patch.format } : {}),
|
|
@@ -242,8 +256,8 @@ async function dropOriginal(item) {
|
|
|
242
256
|
columns: { id: true },
|
|
243
257
|
}));
|
|
244
258
|
if (!used) {
|
|
245
|
-
const {
|
|
246
|
-
await
|
|
259
|
+
const { removeSpaceFile } = await import("./space-files.js");
|
|
260
|
+
await removeSpaceFile(item.spaceId, item.fileId).catch(() => undefined);
|
|
247
261
|
}
|
|
248
262
|
}
|
|
249
263
|
export async function deleteTable(_userId, tableId) {
|
|
@@ -358,22 +372,22 @@ function checkMarkdown(markdown) {
|
|
|
358
372
|
}
|
|
359
373
|
return markdown;
|
|
360
374
|
}
|
|
361
|
-
async function pageCount(
|
|
375
|
+
async function pageCount(spaceId, more = 1) {
|
|
362
376
|
const [{ n }] = await db
|
|
363
377
|
.select({ n: count() })
|
|
364
378
|
.from(schema.spacePage)
|
|
365
|
-
.where(eq(schema.spacePage.
|
|
379
|
+
.where(eq(schema.spacePage.spaceId, spaceId));
|
|
366
380
|
if (n + more > SPACE_DATA_LIMITS.pages) {
|
|
367
381
|
throw new ServiceError("refused", note("spaceMostPages", { count: SPACE_DATA_LIMITS.pages }));
|
|
368
382
|
}
|
|
369
383
|
}
|
|
370
384
|
/** A page of the space's own that a sub-page may stand under: never one of its own sub-pages. */
|
|
371
|
-
async function parentOf(
|
|
385
|
+
async function parentOf(spaceId, parentId, pageId) {
|
|
372
386
|
if (!parentId) {
|
|
373
387
|
return null;
|
|
374
388
|
}
|
|
375
389
|
const parent = await db.query.spacePage.findFirst({
|
|
376
|
-
where: and(eq(schema.spacePage.id, parentId), eq(schema.spacePage.
|
|
390
|
+
where: and(eq(schema.spacePage.id, parentId), eq(schema.spacePage.spaceId, spaceId)),
|
|
377
391
|
columns: { id: true, wizardId: true, parentId: true },
|
|
378
392
|
});
|
|
379
393
|
if (!parent || parent.wizardId) {
|
|
@@ -391,30 +405,30 @@ async function parentOf(projectId, parentId, pageId) {
|
|
|
391
405
|
}
|
|
392
406
|
return parent.id;
|
|
393
407
|
}
|
|
394
|
-
async function nextPosition(
|
|
408
|
+
async function nextPosition(spaceId, parentId) {
|
|
395
409
|
const [{ last }] = await db
|
|
396
410
|
.select({ last: max(schema.spacePage.position) })
|
|
397
411
|
.from(schema.spacePage)
|
|
398
|
-
.where(and(eq(schema.spacePage.
|
|
412
|
+
.where(and(eq(schema.spacePage.spaceId, spaceId), isNull(schema.spacePage.wizardId), parentId ? eq(schema.spacePage.parentId, parentId) : isNull(schema.spacePage.parentId)));
|
|
399
413
|
return (last ?? -1) + 1;
|
|
400
414
|
}
|
|
401
|
-
export async function createPage(userId,
|
|
402
|
-
const
|
|
403
|
-
await
|
|
404
|
-
await pageCount(
|
|
415
|
+
export async function createPage(userId, spaceId, input) {
|
|
416
|
+
const space = await ownedSpace(userId, spaceId);
|
|
417
|
+
await requireWritableSpace(space.id);
|
|
418
|
+
await pageCount(space.id);
|
|
405
419
|
const id = nanoid(12);
|
|
406
|
-
const wizardId = await ownerOf(
|
|
407
|
-
const parentId = wizardId ? null : await parentOf(
|
|
420
|
+
const wizardId = await ownerOf(space.id, input.wizardId);
|
|
421
|
+
const parentId = wizardId ? null : await parentOf(space.id, input.parentId);
|
|
408
422
|
const title = input.title.trim() || "Seite";
|
|
409
423
|
await db.insert(schema.spacePage).values({
|
|
410
424
|
id,
|
|
411
425
|
tenantId: currentTenant(),
|
|
412
|
-
|
|
426
|
+
spaceId: space.id,
|
|
413
427
|
wizardId,
|
|
414
428
|
parentId,
|
|
415
|
-
position: wizardId ? 0 : await nextPosition(
|
|
429
|
+
position: wizardId ? 0 : await nextPosition(space.id, parentId),
|
|
416
430
|
title,
|
|
417
|
-
slug: wizardId ? null : await freeSlug(
|
|
431
|
+
slug: wizardId ? null : await freeSlug(space.id, title, { parentId }),
|
|
418
432
|
markdown: checkMarkdown(input.markdown ?? ""),
|
|
419
433
|
});
|
|
420
434
|
if (!wizardId) {
|
|
@@ -422,17 +436,22 @@ export async function createPage(userId, projectId, input) {
|
|
|
422
436
|
}
|
|
423
437
|
return { id };
|
|
424
438
|
}
|
|
425
|
-
export async function getPage(userId, pageId) {
|
|
439
|
+
export async function getPage(userId, pageId, who) {
|
|
426
440
|
const page = await pageRow(pageId);
|
|
427
|
-
const
|
|
441
|
+
const space = await ownedSpace(userId, page.spaceId);
|
|
442
|
+
await assertRwx(space.id, who, { kind: "page", id: page.id, fileId: page.fileId }, "r");
|
|
443
|
+
return pageView(page, space);
|
|
444
|
+
}
|
|
445
|
+
/** A page as the studio shows it, for one that was just read or written. */
|
|
446
|
+
async function pageView(page, space) {
|
|
428
447
|
return {
|
|
429
448
|
id: page.id,
|
|
430
|
-
|
|
449
|
+
spaceId: page.spaceId,
|
|
431
450
|
wizardId: page.wizardId,
|
|
432
451
|
title: page.title,
|
|
433
452
|
markdown: page.markdown,
|
|
434
453
|
updatedAt: page.updatedAt.toISOString(),
|
|
435
|
-
readOnly: !(await
|
|
454
|
+
readOnly: !(await spaceWritable(space)),
|
|
436
455
|
knowledge: page.wizardId ? null : await knowledgePage(page),
|
|
437
456
|
};
|
|
438
457
|
}
|
|
@@ -442,18 +461,18 @@ export async function getPage(userId, pageId) {
|
|
|
442
461
|
*/
|
|
443
462
|
export async function updatePage(_userId, pageId, patch) {
|
|
444
463
|
const page = await pageRow(pageId);
|
|
445
|
-
await
|
|
464
|
+
await requireWritableSpace(page.spaceId);
|
|
446
465
|
if (patch.baseUpdatedAt && page.updatedAt.getTime() > Date.parse(patch.baseUpdatedAt)) {
|
|
447
466
|
throw new ServiceError("revision_conflict", note("itemChangedMeantime"), {
|
|
448
|
-
page: await
|
|
467
|
+
page: await pageView(page, await ownedSpace(_userId, page.spaceId)),
|
|
449
468
|
});
|
|
450
469
|
}
|
|
451
470
|
const title = patch.title !== undefined ? patch.title.trim() || page.title : page.title;
|
|
452
|
-
const wizardId = patch.wizardId !== undefined ? await ownerOf(page.
|
|
471
|
+
const wizardId = patch.wizardId !== undefined ? await ownerOf(page.spaceId, patch.wizardId) : page.wizardId;
|
|
453
472
|
const parentId = wizardId !== null
|
|
454
473
|
? null
|
|
455
474
|
: patch.parentId !== undefined
|
|
456
|
-
? await parentOf(page.
|
|
475
|
+
? await parentOf(page.spaceId, patch.parentId, page.id)
|
|
457
476
|
: page.parentId;
|
|
458
477
|
const moved = title !== page.title || wizardId !== page.wizardId || parentId !== page.parentId;
|
|
459
478
|
const edited = moved || (patch.markdown !== undefined && patch.markdown !== page.markdown);
|
|
@@ -466,9 +485,9 @@ export async function updatePage(_userId, pageId, patch) {
|
|
|
466
485
|
parentId,
|
|
467
486
|
...(moved
|
|
468
487
|
? {
|
|
469
|
-
slug: wizardId ? null : await freeSlug(page.
|
|
488
|
+
slug: wizardId ? null : await freeSlug(page.spaceId, title, { parentId }, page.id),
|
|
470
489
|
...(parentId !== page.parentId
|
|
471
|
-
? { position: await nextPosition(page.
|
|
490
|
+
? { position: await nextPosition(page.spaceId, parentId) }
|
|
472
491
|
: {}),
|
|
473
492
|
}
|
|
474
493
|
: {}),
|
|
@@ -488,14 +507,14 @@ export async function updatePage(_userId, pageId, patch) {
|
|
|
488
507
|
}
|
|
489
508
|
export async function deletePage(_userId, pageId) {
|
|
490
509
|
const page = await pageRow(pageId);
|
|
491
|
-
await
|
|
510
|
+
await requireWritableSpace(page.spaceId);
|
|
492
511
|
await db.delete(schema.spacePage).where(eq(schema.spacePage.id, page.id));
|
|
493
512
|
await dropOriginal(page);
|
|
494
513
|
}
|
|
495
514
|
/** Puts a page's sub-pages into the order of `ids`. */
|
|
496
515
|
export async function orderSubPages(_userId, pageId, ids) {
|
|
497
516
|
const page = await pageRow(pageId);
|
|
498
|
-
await
|
|
517
|
+
await requireWritableSpace(page.spaceId);
|
|
499
518
|
for (const [position, id] of ids.entries()) {
|
|
500
519
|
await db
|
|
501
520
|
.update(schema.spacePage)
|
|
@@ -508,21 +527,21 @@ export async function orderSubPages(_userId, pageId, ids) {
|
|
|
508
527
|
// the server's, also in a space a local install synced, which the studio there only shows. It
|
|
509
528
|
// reads its wizard's pages; the space's own are Knowledge, read by path.
|
|
510
529
|
/** The pages of a run's wizard. */
|
|
511
|
-
export async function runPages(
|
|
530
|
+
export async function runPages(spaceId, wizardId) {
|
|
512
531
|
return db.query.spacePage.findMany({
|
|
513
|
-
where: and(eq(schema.spacePage.
|
|
532
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.wizardId, wizardId)),
|
|
514
533
|
columns: { id: true, wizardId: true, title: true, markdown: true, updatedAt: true },
|
|
515
534
|
orderBy: [asc(schema.spacePage.title)],
|
|
516
535
|
});
|
|
517
536
|
}
|
|
518
537
|
/** Writes a page of the run's wizard: a new one, or the one with this title, replaced or added to. */
|
|
519
|
-
export async function writeRunPage(
|
|
538
|
+
export async function writeRunPage(spaceId, wizardId, input) {
|
|
520
539
|
const title = input.title.trim();
|
|
521
540
|
if (!title) {
|
|
522
541
|
throw new ServiceError("invalid", note("pageNeedsTitle"));
|
|
523
542
|
}
|
|
524
543
|
const existing = (await db.query.spacePage.findMany({
|
|
525
|
-
where: and(eq(schema.spacePage.
|
|
544
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.wizardId, wizardId)),
|
|
526
545
|
})).find((p) => p.title.toLowerCase() === title.toLowerCase());
|
|
527
546
|
const markdown = existing && input.append
|
|
528
547
|
? `${existing.markdown.trimEnd()}\n\n${input.markdown.trim()}`
|
|
@@ -538,7 +557,7 @@ export async function writeRunPage(projectId, wizardId, input) {
|
|
|
538
557
|
const [{ n }] = await db
|
|
539
558
|
.select({ n: count() })
|
|
540
559
|
.from(schema.spacePage)
|
|
541
|
-
.where(eq(schema.spacePage.
|
|
560
|
+
.where(eq(schema.spacePage.spaceId, spaceId));
|
|
542
561
|
if (n >= SPACE_DATA_LIMITS.pages) {
|
|
543
562
|
throw new ServiceError("refused", note("spaceMostPages", { count: SPACE_DATA_LIMITS.pages }));
|
|
544
563
|
}
|
|
@@ -546,7 +565,7 @@ export async function writeRunPage(projectId, wizardId, input) {
|
|
|
546
565
|
await db.insert(schema.spacePage).values({
|
|
547
566
|
id,
|
|
548
567
|
tenantId: currentTenant(),
|
|
549
|
-
|
|
568
|
+
spaceId,
|
|
550
569
|
wizardId,
|
|
551
570
|
title: title.slice(0, 200),
|
|
552
571
|
markdown,
|
|
@@ -554,21 +573,21 @@ export async function writeRunPage(projectId, wizardId, input) {
|
|
|
554
573
|
return { id, title, chars: markdown.length, made: true };
|
|
555
574
|
}
|
|
556
575
|
async function originSpace(space) {
|
|
557
|
-
const
|
|
558
|
-
where: and(eq(schema.
|
|
576
|
+
const row = await db.query.space.findFirst({
|
|
577
|
+
where: and(eq(schema.space.id, space), eq(schema.space.tenantId, currentTenant())),
|
|
559
578
|
columns: { id: true },
|
|
560
579
|
});
|
|
561
|
-
if (!
|
|
580
|
+
if (!row) {
|
|
562
581
|
throw new ServiceError("not_found", note("unknownSpace", { space }));
|
|
563
582
|
}
|
|
564
|
-
await
|
|
565
|
-
return
|
|
583
|
+
await requireWritableSpace(row.id);
|
|
584
|
+
return row.id;
|
|
566
585
|
}
|
|
567
586
|
/** Keeps the original of what a plugin wrote: a document of the space under the same key. */
|
|
568
|
-
async function originalFile(origin,
|
|
569
|
-
const { putOriginFile } = await import("./
|
|
587
|
+
async function originalFile(origin, spaceId, key, label, original, text) {
|
|
588
|
+
const { putOriginFile } = await import("./space-files.js");
|
|
570
589
|
return putOriginFile(origin, {
|
|
571
|
-
space:
|
|
590
|
+
space: spaceId,
|
|
572
591
|
key,
|
|
573
592
|
label,
|
|
574
593
|
name: original.name,
|
|
@@ -578,17 +597,17 @@ async function originalFile(origin, projectId, key, label, original, text) {
|
|
|
578
597
|
});
|
|
579
598
|
}
|
|
580
599
|
export async function putOriginPage(origin, input) {
|
|
581
|
-
const
|
|
600
|
+
const spaceId = await originSpace(input.space);
|
|
582
601
|
const key = input.key.trim().slice(0, 300);
|
|
583
602
|
const existing = await db.query.spacePage.findFirst({
|
|
584
|
-
where: and(eq(schema.spacePage.
|
|
603
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.originKey, key)),
|
|
585
604
|
});
|
|
586
605
|
if (existing?.kept) {
|
|
587
606
|
return { id: existing.id, state: "kept" };
|
|
588
607
|
}
|
|
589
608
|
const parent = input.parent
|
|
590
609
|
? await db.query.spacePage.findFirst({
|
|
591
|
-
where: and(eq(schema.spacePage.
|
|
610
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.originKey, input.parent)),
|
|
592
611
|
columns: { id: true },
|
|
593
612
|
})
|
|
594
613
|
: null;
|
|
@@ -600,9 +619,9 @@ export async function putOriginPage(origin, input) {
|
|
|
600
619
|
const label = input.label?.trim().slice(0, 120) || null;
|
|
601
620
|
const parentId = parent?.id ?? null;
|
|
602
621
|
const fileId = input.original
|
|
603
|
-
? await originalFile(origin,
|
|
622
|
+
? await originalFile(origin, spaceId, key, label, input.original, markdown)
|
|
604
623
|
: (existing?.fileId ?? null);
|
|
605
|
-
const position = input.position ?? existing?.position ?? (await nextPosition(
|
|
624
|
+
const position = input.position ?? existing?.position ?? (await nextPosition(spaceId, parentId));
|
|
606
625
|
let id = existing?.id;
|
|
607
626
|
const moved = !existing || existing.title !== title || existing.parentId !== parentId;
|
|
608
627
|
if (existing) {
|
|
@@ -616,22 +635,22 @@ export async function putOriginPage(origin, input) {
|
|
|
616
635
|
originLabel: label,
|
|
617
636
|
fileId,
|
|
618
637
|
review: input.review ?? null,
|
|
619
|
-
...(moved ? { slug: await freeSlug(
|
|
638
|
+
...(moved ? { slug: await freeSlug(spaceId, title, { parentId }, existing.id) } : {}),
|
|
620
639
|
updatedAt: new Date(),
|
|
621
640
|
})
|
|
622
641
|
.where(eq(schema.spacePage.id, existing.id));
|
|
623
642
|
}
|
|
624
643
|
else {
|
|
625
|
-
await pageCount(
|
|
644
|
+
await pageCount(spaceId);
|
|
626
645
|
id = nanoid(12);
|
|
627
646
|
await db.insert(schema.spacePage).values({
|
|
628
647
|
id,
|
|
629
648
|
tenantId: currentTenant(),
|
|
630
|
-
|
|
649
|
+
spaceId,
|
|
631
650
|
parentId,
|
|
632
651
|
position,
|
|
633
652
|
title,
|
|
634
|
-
slug: await freeSlug(
|
|
653
|
+
slug: await freeSlug(spaceId, title, { parentId }),
|
|
635
654
|
markdown,
|
|
636
655
|
origin,
|
|
637
656
|
originKey: key,
|
|
@@ -641,16 +660,16 @@ export async function putOriginPage(origin, input) {
|
|
|
641
660
|
});
|
|
642
661
|
}
|
|
643
662
|
const set = input.categories
|
|
644
|
-
? await setItemCategories(
|
|
663
|
+
? await setItemCategories(spaceId, { pageId: id }, input.categories, "origin")
|
|
645
664
|
: { changed: false };
|
|
646
665
|
queueIndex(`${moved || set.changed ? "P" : "p"}:${id}`);
|
|
647
666
|
return { id: id, state: "written" };
|
|
648
667
|
}
|
|
649
668
|
export async function putOriginTable(origin, input) {
|
|
650
|
-
const
|
|
669
|
+
const spaceId = await originSpace(input.space);
|
|
651
670
|
const key = input.key.trim().slice(0, 300);
|
|
652
671
|
const existing = await db.query.spaceTable.findFirst({
|
|
653
|
-
where: and(eq(schema.spaceTable.
|
|
672
|
+
where: and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.originKey, key)),
|
|
654
673
|
});
|
|
655
674
|
if (existing?.kept) {
|
|
656
675
|
return { id: existing.id, state: "kept" };
|
|
@@ -673,7 +692,7 @@ export async function putOriginTable(origin, input) {
|
|
|
673
692
|
...cells.map((r) => columns.map((c) => String(r[c.id] ?? "")).join(",")),
|
|
674
693
|
].join("\n");
|
|
675
694
|
const fileId = input.original
|
|
676
|
-
? await originalFile(origin,
|
|
695
|
+
? await originalFile(origin, spaceId, key, label, input.original, csv)
|
|
677
696
|
: (existing?.fileId ?? null);
|
|
678
697
|
let id = existing?.id;
|
|
679
698
|
if (existing) {
|
|
@@ -687,7 +706,7 @@ export async function putOriginTable(origin, input) {
|
|
|
687
706
|
fileId,
|
|
688
707
|
review: input.review ?? null,
|
|
689
708
|
...(existing.title !== title
|
|
690
|
-
? { slug: await freeSlug(
|
|
709
|
+
? { slug: await freeSlug(spaceId, title, "table", existing.id) }
|
|
691
710
|
: {}),
|
|
692
711
|
updatedAt: new Date(),
|
|
693
712
|
})
|
|
@@ -695,14 +714,14 @@ export async function putOriginTable(origin, input) {
|
|
|
695
714
|
await db.delete(schema.spaceTableRow).where(eq(schema.spaceTableRow.tableId, existing.id));
|
|
696
715
|
}
|
|
697
716
|
else {
|
|
698
|
-
await tableCount(
|
|
717
|
+
await tableCount(spaceId);
|
|
699
718
|
id = nanoid(12);
|
|
700
719
|
await db.insert(schema.spaceTable).values({
|
|
701
720
|
id,
|
|
702
721
|
tenantId: currentTenant(),
|
|
703
|
-
|
|
722
|
+
spaceId,
|
|
704
723
|
title,
|
|
705
|
-
slug: await freeSlug(
|
|
724
|
+
slug: await freeSlug(spaceId, title, "table"),
|
|
706
725
|
format: input.format ?? null,
|
|
707
726
|
columns,
|
|
708
727
|
origin,
|
|
@@ -723,7 +742,7 @@ export async function putOriginTable(origin, input) {
|
|
|
723
742
|
})));
|
|
724
743
|
}
|
|
725
744
|
if (input.categories) {
|
|
726
|
-
await setItemCategories(
|
|
745
|
+
await setItemCategories(spaceId, { tableId: id }, input.categories, "origin");
|
|
727
746
|
}
|
|
728
747
|
await syncTableRowCategories(id);
|
|
729
748
|
queueIndex(`t:${id}`);
|
|
@@ -731,11 +750,11 @@ export async function putOriginTable(origin, input) {
|
|
|
731
750
|
}
|
|
732
751
|
/** What a plugin wrote into a space, by its keys. */
|
|
733
752
|
export async function listOrigin(origin, space) {
|
|
734
|
-
const
|
|
753
|
+
const spaceId = await originSpace(space);
|
|
735
754
|
const [pages, tables, files] = await Promise.all([
|
|
736
755
|
// What a document of the plugin was read into stands behind the document, not on its own.
|
|
737
756
|
db.query.spacePage.findMany({
|
|
738
|
-
where: and(eq(schema.spacePage.
|
|
757
|
+
where: and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), isNotNull(schema.spacePage.originKey)),
|
|
739
758
|
columns: {
|
|
740
759
|
id: true,
|
|
741
760
|
originKey: true,
|
|
@@ -746,7 +765,7 @@ export async function listOrigin(origin, space) {
|
|
|
746
765
|
},
|
|
747
766
|
}),
|
|
748
767
|
db.query.spaceTable.findMany({
|
|
749
|
-
where: and(eq(schema.spaceTable.
|
|
768
|
+
where: and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.origin, origin), isNotNull(schema.spaceTable.originKey)),
|
|
750
769
|
columns: {
|
|
751
770
|
id: true,
|
|
752
771
|
originKey: true,
|
|
@@ -756,15 +775,15 @@ export async function listOrigin(origin, space) {
|
|
|
756
775
|
updatedAt: true,
|
|
757
776
|
},
|
|
758
777
|
}),
|
|
759
|
-
db.query.
|
|
760
|
-
where: and(eq(schema.
|
|
778
|
+
db.query.spaceFile.findMany({
|
|
779
|
+
where: and(eq(schema.spaceFile.spaceId, spaceId), eq(schema.spaceFile.origin, origin)),
|
|
761
780
|
columns: { id: true, originKey: true, name: true, updatedAt: true },
|
|
762
781
|
}),
|
|
763
782
|
]);
|
|
764
783
|
const [tree, tPaths, fPaths] = await Promise.all([
|
|
765
|
-
pageTree(
|
|
766
|
-
tablePaths(
|
|
767
|
-
filePaths(
|
|
784
|
+
pageTree(spaceId),
|
|
785
|
+
tablePaths(spaceId),
|
|
786
|
+
filePaths(spaceId),
|
|
768
787
|
]);
|
|
769
788
|
return [
|
|
770
789
|
...pages.map((p) => ({
|
|
@@ -804,16 +823,16 @@ export async function listOrigin(origin, space) {
|
|
|
804
823
|
* space. What a person changed since stays. Returns how many items went.
|
|
805
824
|
*/
|
|
806
825
|
export async function removeOrigin(origin, space, key) {
|
|
807
|
-
const
|
|
826
|
+
const spaceId = await originSpace(space);
|
|
808
827
|
const pages = await db
|
|
809
828
|
.delete(schema.spacePage)
|
|
810
|
-
.where(and(eq(schema.spacePage.
|
|
829
|
+
.where(and(eq(schema.spacePage.spaceId, spaceId), eq(schema.spacePage.origin, origin), eq(schema.spacePage.kept, false), key === undefined ? undefined : eq(schema.spacePage.originKey, key)))
|
|
811
830
|
.returning({ id: schema.spacePage.id });
|
|
812
831
|
const tables = await db
|
|
813
832
|
.delete(schema.spaceTable)
|
|
814
|
-
.where(and(eq(schema.spaceTable.
|
|
833
|
+
.where(and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.origin, origin), eq(schema.spaceTable.kept, false), key === undefined ? undefined : eq(schema.spaceTable.originKey, key)))
|
|
815
834
|
.returning({ id: schema.spaceTable.id });
|
|
816
|
-
const { removeOriginFiles } = await import("./
|
|
817
|
-
const files = await removeOriginFiles(origin,
|
|
835
|
+
const { removeOriginFiles } = await import("./space-files.js");
|
|
836
|
+
const files = await removeOriginFiles(origin, spaceId, key);
|
|
818
837
|
return pages.length + tables.length + files;
|
|
819
838
|
}
|