@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
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { LANGS } from "@engenty/wizards-shared/definition";
|
|
2
|
+
import { note } from "@engenty/wizards-shared/run";
|
|
3
|
+
import { createUIMessageStreamResponse } from "ai";
|
|
4
|
+
import { Hono } from "hono";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { feature, remoteFeatures } from "../features.js";
|
|
7
|
+
import { reverseGeocode } from "../geocode.js";
|
|
8
|
+
import { bellOpened, criticalsFor } from "../services/broker-bell.js";
|
|
9
|
+
import { ServiceError } from "../services/errors.js";
|
|
10
|
+
import { composerTools } from "../services/work-ai.js";
|
|
11
|
+
import { addMember, attachFile, chatFileContent, createChat, createSection, DEV_CHUNK, decideApproval, deleteChat, deleteSection, followTurn, moveSection, readChat, removeMember, renameSection, seeChat, sendMessage, setChatState, sidebar, stopTurn, updateChat, waitingApprovals, } from "../services/work-chats.js";
|
|
12
|
+
import { FILES_PER_MESSAGE } from "../services/work-files.js";
|
|
13
|
+
import { spaceFileResponse } from "./delivery.js";
|
|
14
|
+
import { say } from "./lang.js";
|
|
15
|
+
import { assistantDevFor } from "./studio.js";
|
|
16
|
+
/**
|
|
17
|
+
* A turn of the AI as `useChat` reads it. The developer mode's chunks (the prompt, each step's
|
|
18
|
+
* tokens) go only to a person it is offered to.
|
|
19
|
+
*/
|
|
20
|
+
async function turnResponse(user, stream) {
|
|
21
|
+
const dev = await assistantDevFor(user);
|
|
22
|
+
const shown = dev
|
|
23
|
+
? stream
|
|
24
|
+
: stream.pipeThrough(new TransformStream({
|
|
25
|
+
transform(chunk, controller) {
|
|
26
|
+
if (!chunk.type?.startsWith(DEV_CHUNK)) {
|
|
27
|
+
controller.enqueue(chunk);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
}));
|
|
31
|
+
return createUIMessageStreamResponse({ stream: shown });
|
|
32
|
+
}
|
|
33
|
+
const name = z.string().trim().min(1).max(120);
|
|
34
|
+
const member = z.object({ kind: z.enum(["person", "engenty"]), id: z.string().min(1).max(80) });
|
|
35
|
+
/** Work's chats and their sections (docs: engenty-dev concepts, work mode), behind `workMode`. */
|
|
36
|
+
export const workRoutes = new Hono()
|
|
37
|
+
.use(async (c, next) => {
|
|
38
|
+
if (!feature("workMode", await remoteFeatures().catch(() => null))) {
|
|
39
|
+
return c.json({ error: say(c, "notFound"), code: "not_found" }, 404);
|
|
40
|
+
}
|
|
41
|
+
await next();
|
|
42
|
+
})
|
|
43
|
+
.get("/chats", async (c) => {
|
|
44
|
+
const { space, q } = z
|
|
45
|
+
.object({ space: z.string().min(1), q: z.string().max(200).optional() })
|
|
46
|
+
.parse(c.req.query());
|
|
47
|
+
return c.json(await sidebar(c.get("user"), space, q));
|
|
48
|
+
})
|
|
49
|
+
.post("/chats", async (c) => {
|
|
50
|
+
const body = z
|
|
51
|
+
.object({
|
|
52
|
+
spaceId: z.string().min(1).optional(),
|
|
53
|
+
title: z.string().max(120).optional(),
|
|
54
|
+
sectionId: z.string().nullable().optional(),
|
|
55
|
+
parentId: z.string().nullable().optional(),
|
|
56
|
+
private: z.boolean().optional(),
|
|
57
|
+
})
|
|
58
|
+
.refine((b) => b.spaceId || b.parentId)
|
|
59
|
+
.parse(await c.req.json());
|
|
60
|
+
return c.json(await createChat(c.get("user"), body));
|
|
61
|
+
})
|
|
62
|
+
.get("/chats/:id", async (c) => c.json(await readChat(c.get("user"), c.req.param("id"))))
|
|
63
|
+
.patch("/chats/:id", async (c) => {
|
|
64
|
+
const patch = z
|
|
65
|
+
.object({
|
|
66
|
+
title: z.string().max(120).optional(),
|
|
67
|
+
sectionId: z.string().nullable().optional(),
|
|
68
|
+
private: z.boolean().optional(),
|
|
69
|
+
})
|
|
70
|
+
.parse(await c.req.json());
|
|
71
|
+
return c.json(await updateChat(c.get("user"), c.req.param("id"), patch));
|
|
72
|
+
})
|
|
73
|
+
.delete("/chats/:id", async (c) => {
|
|
74
|
+
await deleteChat(c.get("user"), c.req.param("id"));
|
|
75
|
+
return c.json({ ok: true });
|
|
76
|
+
})
|
|
77
|
+
.put("/chats/:id/state", async (c) => {
|
|
78
|
+
const patch = z
|
|
79
|
+
.object({
|
|
80
|
+
pinned: z.boolean().optional(),
|
|
81
|
+
archived: z.boolean().optional(),
|
|
82
|
+
read: z.boolean().optional(),
|
|
83
|
+
})
|
|
84
|
+
.parse(await c.req.json());
|
|
85
|
+
await setChatState(c.get("user"), c.req.param("id"), patch);
|
|
86
|
+
return c.json({ ok: true });
|
|
87
|
+
})
|
|
88
|
+
// A file for a message, or for a Field of a view's Form (`uploads`, as the runner's fields call
|
|
89
|
+
// it): it lands in the space's files; the message names it by its id.
|
|
90
|
+
.on("POST", ["/chats/:id/files", "/chats/:id/uploads"], async (c) => {
|
|
91
|
+
const file = (await c.req.formData()).get("file");
|
|
92
|
+
if (!(file instanceof File)) {
|
|
93
|
+
throw new ServiceError("invalid", note("chooseFile"));
|
|
94
|
+
}
|
|
95
|
+
const added = await attachFile(c.get("user"), c.req.param("id"), {
|
|
96
|
+
name: file.name,
|
|
97
|
+
mime: file.type.split(";")[0].trim().toLowerCase(),
|
|
98
|
+
data: new Uint8Array(await file.arrayBuffer()),
|
|
99
|
+
});
|
|
100
|
+
return c.json(added);
|
|
101
|
+
})
|
|
102
|
+
// A file of the chat's space, as a view shows it and a Field's upload shows itself.
|
|
103
|
+
.get("/chats/:id/assets/:file", async (c) => {
|
|
104
|
+
const { row, data } = await chatFileContent(c.get("user"), c.req.param("id"), c.req.param("file"));
|
|
105
|
+
return spaceFileResponse(c, row.mime, data);
|
|
106
|
+
})
|
|
107
|
+
// The address of where the person stands, for a Field asking for the place.
|
|
108
|
+
.post("/chats/:id/geocode", async (c) => {
|
|
109
|
+
const { lat, lng, language } = z
|
|
110
|
+
.object({
|
|
111
|
+
lat: z.number().min(-90).max(90),
|
|
112
|
+
lng: z.number().min(-180).max(180),
|
|
113
|
+
language: z.enum(LANGS).default("en"),
|
|
114
|
+
})
|
|
115
|
+
.parse(await c.req.json());
|
|
116
|
+
await seeChat(c.get("user"), c.req.param("id"));
|
|
117
|
+
return c.json({ label: await reverseGeocode(lat, lng, language) });
|
|
118
|
+
})
|
|
119
|
+
// A person writes; asked, the space's AI answers with a UI message stream (`useChat`).
|
|
120
|
+
.post("/chats/:id/messages", async (c) => {
|
|
121
|
+
const body = z
|
|
122
|
+
.object({
|
|
123
|
+
text: z.string().trim().max(8000).default(""),
|
|
124
|
+
files: z.array(z.string().min(1)).max(FILES_PER_MESSAGE).optional(),
|
|
125
|
+
ask: z.boolean().optional(),
|
|
126
|
+
later: z.boolean().optional(),
|
|
127
|
+
// What the person chose in the composer for the turn (work-ai.ts `TurnChoice`).
|
|
128
|
+
extra: z.boolean().optional(),
|
|
129
|
+
web: z.boolean().optional(),
|
|
130
|
+
pluginsOff: z.array(z.string().min(1).max(80)).max(50).optional(),
|
|
131
|
+
// A view's Form answered: everyone in the chat may send it (work-ai.ts, show_view).
|
|
132
|
+
form: z
|
|
133
|
+
.object({ call: z.string().min(1).max(200), values: z.record(z.string(), z.unknown()) })
|
|
134
|
+
.refine((f) => JSON.stringify(f.values).length <= 20_000)
|
|
135
|
+
.optional(),
|
|
136
|
+
})
|
|
137
|
+
.refine((b) => b.text || b.files?.length)
|
|
138
|
+
.parse(await c.req.json());
|
|
139
|
+
const { extra, web, pluginsOff } = body;
|
|
140
|
+
const sent = await sendMessage(c.get("user"), c.req.param("id"), body.text, {
|
|
141
|
+
...body,
|
|
142
|
+
choice: { extra, web, pluginsOff },
|
|
143
|
+
});
|
|
144
|
+
return sent.kind === "turn"
|
|
145
|
+
? turnResponse(c.get("user"), sent.stream)
|
|
146
|
+
: c.json({ sent: sent.kind });
|
|
147
|
+
})
|
|
148
|
+
.post("/chats/:id/approvals/:approval", async (c) => {
|
|
149
|
+
const { approve } = z.object({ approve: z.boolean() }).parse(await c.req.json());
|
|
150
|
+
const sent = await decideApproval(c.get("user"), c.req.param("id"), c.req.param("approval"), approve);
|
|
151
|
+
return sent.kind === "turn"
|
|
152
|
+
? turnResponse(c.get("user"), sent.stream)
|
|
153
|
+
: c.json({ sent: sent.kind });
|
|
154
|
+
})
|
|
155
|
+
// Follow the AI's running turn from its start, as `useChat`'s resume reads it; 204 when none runs.
|
|
156
|
+
.get("/chats/:id/follow", async (c) => {
|
|
157
|
+
const stream = await followTurn(c.get("user"), c.req.param("id"));
|
|
158
|
+
return stream ? turnResponse(c.get("user"), stream) : c.body(null, 204);
|
|
159
|
+
})
|
|
160
|
+
// What the composer offers for the space's AI's turns: web search, the plugins with tools.
|
|
161
|
+
.get("/composer", async (c) => c.json(await composerTools()))
|
|
162
|
+
// The bell: the calls held for the person, and for an admin the broker's critical lines too.
|
|
163
|
+
.get("/approvals", async (c) => {
|
|
164
|
+
const user = c.get("user");
|
|
165
|
+
const [approvals, criticals] = await Promise.all([waitingApprovals(user), criticalsFor(user)]);
|
|
166
|
+
return c.json({ approvals, ...criticals });
|
|
167
|
+
})
|
|
168
|
+
.post("/approvals/seen", async (c) => {
|
|
169
|
+
await bellOpened(c.get("user"));
|
|
170
|
+
return c.json({ ok: true });
|
|
171
|
+
})
|
|
172
|
+
.post("/chats/:id/stop", async (c) => c.json({ stopped: await stopTurn(c.get("user"), c.req.param("id")) }))
|
|
173
|
+
.post("/chats/:id/members", async (c) => {
|
|
174
|
+
const { kind, id } = member.parse(await c.req.json());
|
|
175
|
+
await addMember(c.get("user"), c.req.param("id"), kind, id);
|
|
176
|
+
return c.json({ ok: true });
|
|
177
|
+
})
|
|
178
|
+
.delete("/chats/:id/members/:kind/:member", async (c) => {
|
|
179
|
+
const { kind, id } = member.parse({ kind: c.req.param("kind"), id: c.req.param("member") });
|
|
180
|
+
await removeMember(c.get("user"), c.req.param("id"), kind, id);
|
|
181
|
+
return c.json({ ok: true });
|
|
182
|
+
})
|
|
183
|
+
.post("/sections", async (c) => {
|
|
184
|
+
const body = z.object({ spaceId: z.string().min(1), name }).parse(await c.req.json());
|
|
185
|
+
return c.json(await createSection(c.get("user"), body.spaceId, body.name));
|
|
186
|
+
})
|
|
187
|
+
.patch("/sections/:id", async (c) => {
|
|
188
|
+
const body = z.object({ name }).parse(await c.req.json());
|
|
189
|
+
return c.json(await renameSection(c.get("user"), c.req.param("id"), body.name));
|
|
190
|
+
})
|
|
191
|
+
.post("/sections/:id/move", async (c) => {
|
|
192
|
+
const { direction } = z.object({ direction: z.enum(["up", "down"]) }).parse(await c.req.json());
|
|
193
|
+
await moveSection(c.get("user"), c.req.param("id"), direction);
|
|
194
|
+
return c.json({ ok: true });
|
|
195
|
+
})
|
|
196
|
+
.delete("/sections/:id", async (c) => {
|
|
197
|
+
await deleteSection(c.get("user"), c.req.param("id"));
|
|
198
|
+
return c.json({ ok: true });
|
|
199
|
+
});
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { note } from "@engenty/wizards-shared/run";
|
|
2
2
|
import { decide } from "./engine/decide.js";
|
|
3
|
+
import { managed, tenantInfo } from "./manage.js";
|
|
3
4
|
import { NotedError } from "./model-errors.js";
|
|
4
5
|
import { prompt } from "./prompts.js";
|
|
6
|
+
import { currentTenant } from "./tenants/tenant.js";
|
|
7
|
+
/**
|
|
8
|
+
* A run of someone without an account: a guest on a public wizard. What it makes is checked
|
|
9
|
+
* against the rules before it is kept, and stays private (docs/plans/guest-content-guards.md).
|
|
10
|
+
*/
|
|
11
|
+
export const guestRun = (run) => run.mode === "live" && !run.userId;
|
|
12
|
+
/**
|
|
13
|
+
* Whether what this tenant's guests make is checked: the Manage-App's abuse checks can switch it
|
|
14
|
+
* off; a runtime without one, or one that cannot reach it, checks.
|
|
15
|
+
*/
|
|
16
|
+
export async function guestChecksOn() {
|
|
17
|
+
if (!managed)
|
|
18
|
+
return true;
|
|
19
|
+
const info = await tenantInfo(currentTenant()).catch(() => null);
|
|
20
|
+
return info?.checks?.guests !== false;
|
|
21
|
+
}
|
|
5
22
|
/** A request the content rules stop. */
|
|
6
23
|
export class ContentBlockedError extends NotedError {
|
|
7
24
|
kind;
|
|
@@ -14,32 +31,57 @@ export class ContentBlockedError extends NotedError {
|
|
|
14
31
|
export function contentPolicy() {
|
|
15
32
|
return prompt("safety", "policy");
|
|
16
33
|
}
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Asks the decision model the questions about a text; the first one answered yes (or not at all)
|
|
36
|
+
* names what stops it. Throws ContentBlockedError then, NotedError when no check could run.
|
|
37
|
+
*/
|
|
38
|
+
async function ask(state, questions, meta) {
|
|
39
|
+
let stopped;
|
|
20
40
|
try {
|
|
21
41
|
const decision = await decide({
|
|
22
|
-
state
|
|
23
|
-
questions:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
call: input.call,
|
|
30
|
-
signal: input.signal,
|
|
42
|
+
state,
|
|
43
|
+
questions: Object.fromEntries(Object.entries(questions).map(([kind, instructions]) => [
|
|
44
|
+
kind,
|
|
45
|
+
{ type: "noul", instructions: instructions ?? "" },
|
|
46
|
+
])),
|
|
47
|
+
call: meta.call,
|
|
48
|
+
signal: meta.signal,
|
|
31
49
|
});
|
|
32
|
-
const answer = decision.answers.breaks;
|
|
33
50
|
// No usable answer counts as a yes: nothing is made unchecked.
|
|
34
|
-
|
|
51
|
+
stopped = Object.keys(questions).find((kind) => {
|
|
52
|
+
const answer = decision.answers[kind];
|
|
53
|
+
return answer?.type === "noul" ? answer.noul >= 0.5 : true;
|
|
54
|
+
});
|
|
35
55
|
}
|
|
36
56
|
catch (err) {
|
|
37
|
-
if (
|
|
57
|
+
if (meta.signal?.aborted)
|
|
38
58
|
throw err;
|
|
39
59
|
throw new NotedError(note("contentCheckFailed", { detail: err.message || String(err) }));
|
|
40
60
|
}
|
|
41
|
-
if (
|
|
42
|
-
console.warn(`[safety] ${
|
|
43
|
-
throw new ContentBlockedError(
|
|
61
|
+
if (stopped) {
|
|
62
|
+
console.warn(`[safety] ${stopped} stopped`);
|
|
63
|
+
throw new ContentBlockedError(stopped);
|
|
44
64
|
}
|
|
45
65
|
}
|
|
66
|
+
/** Throws ContentBlockedError when an image, video or speech request breaks a content rule. */
|
|
67
|
+
export async function checkContent(input) {
|
|
68
|
+
await ask({ kind: input.kind, request: input.text }, { [input.kind]: prompt("safety", "check", { policy: contentPolicy() }) }, input);
|
|
69
|
+
}
|
|
70
|
+
/** Throws ContentBlockedError when what an AI step wrote for a guest breaks a content rule. */
|
|
71
|
+
export async function checkGuestText(input) {
|
|
72
|
+
if (!input.text.trim())
|
|
73
|
+
return;
|
|
74
|
+
await ask({ text: input.text.slice(0, 20_000) }, { text: prompt("safety", "check_text", { policy: contentPolicy() }) }, input);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Throws ContentBlockedError when a guest's answers ask for what the rules forbid (`input`) or
|
|
78
|
+
* try to change what the AI is told to do (`injection`). One call for both.
|
|
79
|
+
*/
|
|
80
|
+
export async function checkGuestInput(input) {
|
|
81
|
+
if (!input.text.trim())
|
|
82
|
+
return;
|
|
83
|
+
await ask({ answers: input.text.slice(0, 20_000) }, {
|
|
84
|
+
input: prompt("safety", "check_input.rules", { policy: contentPolicy() }),
|
|
85
|
+
injection: prompt("safety", "check_input.override"),
|
|
86
|
+
}, input);
|
|
87
|
+
}
|
|
@@ -25,16 +25,43 @@ export function pickEngine(engines, requested) {
|
|
|
25
25
|
}
|
|
26
26
|
return engines.find((e) => e.ready()) ?? null;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The engine for a guest's run, from `SANDBOX_GUESTS`: `off` (the default): none. `agentos`: that
|
|
30
|
+
* engine when it is ready here, else none. Never Docker: a guest's step there could install and
|
|
31
|
+
* send anything (docs/plans/capabilities.md, A1). Anything else is said once and means off.
|
|
32
|
+
*/
|
|
33
|
+
export function pickGuestEngine(engines, requested) {
|
|
34
|
+
if (!requested || requested === "off") {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (requested !== "agentos") {
|
|
38
|
+
console.warn(`SANDBOX_GUESTS=${requested} is no engine for guests (agentos or off): off.`);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const engine = engines.find((e) => e.name === requested) ?? null;
|
|
42
|
+
if (!engine?.ready()) {
|
|
43
|
+
console.warn("SANDBOX_GUESTS=agentos, but agentOS is not installed here: guests get no sandbox.");
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return engine;
|
|
47
|
+
}
|
|
28
48
|
let picked = null;
|
|
49
|
+
let pickedForGuests = null;
|
|
29
50
|
/** The engine of this server, picked once at the first question. */
|
|
30
51
|
export function sandboxEngine() {
|
|
31
52
|
picked ??= { engine: pickEngine(ENGINES, env.sandbox) };
|
|
32
53
|
return picked.engine;
|
|
33
54
|
}
|
|
55
|
+
/** The engine of a guest's runs on this server, picked once at the first question. */
|
|
56
|
+
export function guestSandboxEngine() {
|
|
57
|
+
pickedForGuests ??= { engine: pickGuestEngine(ENGINES, env.sandboxGuests) };
|
|
58
|
+
return pickedForGuests.engine;
|
|
59
|
+
}
|
|
34
60
|
/** What this server's sandbox runs, or null when it is switched off. */
|
|
35
61
|
export function sandboxCapabilities() {
|
|
36
62
|
return sandboxEngine()?.capabilities() ?? null;
|
|
37
63
|
}
|
|
64
|
+
/** A Work chat's sandbox, on the server's engine. A run's goes through its RunResources. */
|
|
38
65
|
export function createSandbox(runId) {
|
|
39
66
|
const engine = sandboxEngine();
|
|
40
67
|
if (!engine) {
|
|
@@ -2,18 +2,18 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
2
2
|
import { note } from "@engenty/wizards-shared/run";
|
|
3
3
|
import { and, eq } from "drizzle-orm";
|
|
4
4
|
import { db, schema } from "../db/client.js";
|
|
5
|
-
import { managed, tenantInfo } from "../manage.js";
|
|
5
|
+
import { managed, tenantInfo, tenantMembers } from "../manage.js";
|
|
6
6
|
import { currentTenant } from "../tenants/tenant.js";
|
|
7
7
|
import { ServiceError } from "./errors.js";
|
|
8
8
|
/**
|
|
9
|
-
* Who may change what on this runtime. A
|
|
9
|
+
* Who may change what on this runtime. A space a local install synced (`origin: "local"`) is
|
|
10
10
|
* changed only by that install's next sync: here it is shown and run. And a tenant the
|
|
11
11
|
* Manage-App gives no building (`limits.build: false`) makes and changes nothing on this
|
|
12
|
-
* runtime. Every write of a
|
|
12
|
+
* runtime. Every write of a space or a wizard asks here, whichever way it came in: studio,
|
|
13
13
|
* MCP client or API.
|
|
14
14
|
*/
|
|
15
15
|
const sync = new AsyncLocalStorage();
|
|
16
|
-
/** Runs the writes of a sync: they are the one way a synced
|
|
16
|
+
/** Runs the writes of a sync: they are the one way a synced space changes. */
|
|
17
17
|
export function asSync(fn) {
|
|
18
18
|
return sync.run(true, fn);
|
|
19
19
|
}
|
|
@@ -32,6 +32,27 @@ export function currentRole() {
|
|
|
32
32
|
}
|
|
33
33
|
export const isAdminRole = (role) => role === "owner" || role === "admin";
|
|
34
34
|
export const MEMBERS_EDIT_ONLY = note("onlyOrganizationAdmins");
|
|
35
|
+
const roles = new Map();
|
|
36
|
+
/**
|
|
37
|
+
* The role of a person in the tenant at hand, for a context that has no session of theirs (a
|
|
38
|
+
* run's job, a Work turn). The one person of a runtime that runs alone is its owner; in an
|
|
39
|
+
* organization, what the Manage-App says, asked once a minute. Unknown there: a member.
|
|
40
|
+
*/
|
|
41
|
+
export async function roleOf(userId) {
|
|
42
|
+
if (!managed) {
|
|
43
|
+
return "owner";
|
|
44
|
+
}
|
|
45
|
+
const tenant = currentTenant();
|
|
46
|
+
let hit = roles.get(tenant);
|
|
47
|
+
if (!hit || Date.now() - hit.at > 60_000) {
|
|
48
|
+
const people = await tenantMembers(tenant).catch(() => null);
|
|
49
|
+
if (people) {
|
|
50
|
+
hit = { at: Date.now(), byUser: new Map(people.members.map((m) => [m.userId, m.role])) };
|
|
51
|
+
roles.set(tenant, hit);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return hit?.byUser.get(userId) ?? "member";
|
|
55
|
+
}
|
|
35
56
|
/** Refuses a member: making and deleting is for the owner and the admins of the organization. */
|
|
36
57
|
export async function requireAdmin() {
|
|
37
58
|
if (syncing() || !managed || isAdminRole(currentRole())) {
|
|
@@ -52,7 +73,7 @@ export async function mayBuild() {
|
|
|
52
73
|
// An older Manage-App does not say: then it builds. One that cannot be reached: nothing changes.
|
|
53
74
|
return info ? info.limits.build !== false : false;
|
|
54
75
|
}
|
|
55
|
-
export const
|
|
76
|
+
export const READ_ONLY_SPACE = note("spaceEditedLocally");
|
|
56
77
|
export const READ_ONLY_TENANT = note("wizardsRunOncePublished");
|
|
57
78
|
/** Refuses when the tenant builds nothing here. */
|
|
58
79
|
export async function requireBuild() {
|
|
@@ -61,28 +82,28 @@ export async function requireBuild() {
|
|
|
61
82
|
}
|
|
62
83
|
throw new ServiceError("read_only", READ_ONLY_TENANT);
|
|
63
84
|
}
|
|
64
|
-
/** Refuses a change of a synced
|
|
65
|
-
export async function requireWritable(
|
|
85
|
+
/** Refuses a change of a synced space, and any change by a tenant that builds nothing here. */
|
|
86
|
+
export async function requireWritable(space) {
|
|
66
87
|
if (syncing()) {
|
|
67
88
|
return;
|
|
68
89
|
}
|
|
69
|
-
if (
|
|
70
|
-
throw new ServiceError("read_only",
|
|
90
|
+
if (space.origin === "local") {
|
|
91
|
+
throw new ServiceError("read_only", READ_ONLY_SPACE);
|
|
71
92
|
}
|
|
72
93
|
await requireBuild();
|
|
73
94
|
}
|
|
74
|
-
export async function
|
|
95
|
+
export async function requireWritableSpace(spaceId) {
|
|
75
96
|
if (syncing()) {
|
|
76
97
|
return;
|
|
77
98
|
}
|
|
78
|
-
const
|
|
79
|
-
where: and(eq(schema.
|
|
99
|
+
const space = await db.query.space.findFirst({
|
|
100
|
+
where: and(eq(schema.space.id, spaceId), eq(schema.space.tenantId, currentTenant())),
|
|
80
101
|
columns: { origin: true },
|
|
81
102
|
});
|
|
82
|
-
// A
|
|
83
|
-
await requireWritable(
|
|
103
|
+
// A space that is not there is the caller's "not found", not ours.
|
|
104
|
+
await requireWritable(space ?? { origin: null });
|
|
84
105
|
}
|
|
85
|
-
/** Whether the person may change this
|
|
86
|
-
export async function
|
|
87
|
-
return
|
|
106
|
+
/** Whether the person may change this space's wizards and settings here. */
|
|
107
|
+
export async function spaceWritable(space) {
|
|
108
|
+
return space.origin !== "local" && (await mayBuild());
|
|
88
109
|
}
|
|
@@ -10,31 +10,43 @@ import { wizardUnavailable } from "../limits.js";
|
|
|
10
10
|
import { codeOf } from "../tenants/control.js";
|
|
11
11
|
import { currentTenant } from "../tenants/tenant.js";
|
|
12
12
|
import { serverText } from "../texts.js";
|
|
13
|
-
import { mayBuild,
|
|
13
|
+
import { mayBuild, READ_ONLY_TENANT, spaceWritable } from "./access.js";
|
|
14
14
|
import { mainLogoId } from "./brand.js";
|
|
15
15
|
import { notFound, ServiceError } from "./errors.js";
|
|
16
16
|
import { knowledgeCounts } from "./knowledge.js";
|
|
17
|
-
import {
|
|
17
|
+
import { closedToMe, requireStudio } from "./members-studio.js";
|
|
18
18
|
import { runReport } from "./runs.js";
|
|
19
19
|
import { shareUrlFor } from "./shares.js";
|
|
20
|
+
import { listSpaces, ownedSpace } from "./spaces.js";
|
|
20
21
|
import { shareUrl, studioUrl } from "./wizards.js";
|
|
21
22
|
/** The spaces the caller works with, as the studio lists them, and whether each may change here. */
|
|
22
23
|
export async function apiSpaces(userId) {
|
|
23
|
-
const
|
|
24
|
-
return Promise.all(
|
|
24
|
+
const spaces = await listSpaces(userId);
|
|
25
|
+
return Promise.all(spaces.map(async (p) => ({
|
|
25
26
|
id: p.id,
|
|
26
27
|
name: p.name,
|
|
27
28
|
title: p.brand.name ?? "",
|
|
28
29
|
wizards: p.wizardCount,
|
|
29
|
-
writable: await
|
|
30
|
+
writable: await spaceWritable(p),
|
|
30
31
|
})));
|
|
31
32
|
}
|
|
32
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* The space a call names, or the one a caller means when it names none: the first one listed
|
|
35
|
+
* whose Studio is open to them. A member is refused a space closed to them (services/members-studio.ts).
|
|
36
|
+
*/
|
|
33
37
|
export async function apiSpace(userId, spaceId) {
|
|
34
38
|
if (spaceId) {
|
|
35
|
-
|
|
39
|
+
const space = await ownedSpace(userId, spaceId);
|
|
40
|
+
await requireStudio("spaces", space.id);
|
|
41
|
+
return space;
|
|
42
|
+
}
|
|
43
|
+
const spaces = await listSpaces(userId);
|
|
44
|
+
for (const p of spaces) {
|
|
45
|
+
if (!(await closedToMe(p.id))) {
|
|
46
|
+
return p;
|
|
47
|
+
}
|
|
36
48
|
}
|
|
37
|
-
const [first] =
|
|
49
|
+
const [first] = spaces;
|
|
38
50
|
if (!first) {
|
|
39
51
|
// A plan that builds nothing here has a space only once its local install synced one.
|
|
40
52
|
if (!(await mayBuild())) {
|
|
@@ -42,6 +54,8 @@ export async function apiSpace(userId, spaceId) {
|
|
|
42
54
|
}
|
|
43
55
|
throw notFound();
|
|
44
56
|
}
|
|
57
|
+
// Every space is closed to them: the studio's answer.
|
|
58
|
+
await requireStudio("spaces", first.id);
|
|
45
59
|
return first;
|
|
46
60
|
}
|
|
47
61
|
/** The space's own details: what it says about itself, and what its wizards look things up in. */
|
|
@@ -57,7 +71,7 @@ export async function apiSpaceDetails(userId, spaceId) {
|
|
|
57
71
|
facts: p.facts.map(({ label, value }) => ({ label, value })),
|
|
58
72
|
logoUrl: logo ? `${env.publicUrl}/api/public/logos/${logo}` : null,
|
|
59
73
|
knowledge: await knowledgeCounts(p.id),
|
|
60
|
-
writable: await
|
|
74
|
+
writable: await spaceWritable(p),
|
|
61
75
|
studioUrl: `${env.appUrl}/studio/space`,
|
|
62
76
|
};
|
|
63
77
|
}
|
|
@@ -66,12 +80,12 @@ export async function apiSpaceDetails(userId, spaceId) {
|
|
|
66
80
|
* embeds it with: its link's token and the ID the mobile app takes.
|
|
67
81
|
*/
|
|
68
82
|
export async function apiWizards(userId, spaceId) {
|
|
69
|
-
const spaces = (await
|
|
83
|
+
const spaces = (await listSpaces(userId)).filter((p) => !spaceId || p.id === spaceId);
|
|
70
84
|
if (!spaces.length) {
|
|
71
85
|
return [];
|
|
72
86
|
}
|
|
73
87
|
const rows = await db.query.wizard.findMany({
|
|
74
|
-
where: and(eq(schema.wizard.tenantId, currentTenant()), inArray(schema.wizard.
|
|
88
|
+
where: and(eq(schema.wizard.tenantId, currentTenant()), inArray(schema.wizard.spaceId, spaces.map((p) => p.id))),
|
|
75
89
|
orderBy: [desc(schema.wizard.updatedAt)],
|
|
76
90
|
});
|
|
77
91
|
const published = rows.filter((w) => w.publishedVersion !== null);
|
|
@@ -87,7 +101,7 @@ export async function apiWizards(userId, spaceId) {
|
|
|
87
101
|
const reason = live ? await wizardUnavailable(w) : null;
|
|
88
102
|
return {
|
|
89
103
|
id: w.id,
|
|
90
|
-
spaceId: w.
|
|
104
|
+
spaceId: w.spaceId,
|
|
91
105
|
title: def.title,
|
|
92
106
|
description: def.description ?? "",
|
|
93
107
|
avatar: def.avatar ?? null,
|
|
@@ -165,7 +179,17 @@ const PAGE = 50;
|
|
|
165
179
|
/** The live runs of the caller's wizards, newest first, by pages of 50: what visitors left. */
|
|
166
180
|
export async function apiRuns(userId, filter = {}) {
|
|
167
181
|
const wizards = await apiWizards(userId, filter.spaceId);
|
|
168
|
-
|
|
182
|
+
// What visitors left is the Studio's: none of a space closed to the person.
|
|
183
|
+
const closed = new Set();
|
|
184
|
+
for (const spaceId of new Set(wizards.map((w) => w.spaceId))) {
|
|
185
|
+
if (await closedToMe(spaceId)) {
|
|
186
|
+
closed.add(spaceId);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const ids = wizards
|
|
190
|
+
.filter((w) => !closed.has(w.spaceId))
|
|
191
|
+
.map((w) => w.id)
|
|
192
|
+
.filter((id) => !filter.wizardId || id === filter.wizardId);
|
|
169
193
|
const page = Math.max(1, filter.page ?? 1);
|
|
170
194
|
if (!ids.length) {
|
|
171
195
|
return { runs: [], page, pages: 0, total: 0 };
|
|
@@ -226,6 +250,7 @@ export async function apiRuns(userId, filter = {}) {
|
|
|
226
250
|
}
|
|
227
251
|
/** One run with everything a reader of the result needs: the answers, the outputs, the downloads. */
|
|
228
252
|
export async function apiRun(userId, runId) {
|
|
253
|
+
await requireStudio("runs", runId);
|
|
229
254
|
// Refuses what is no live run of the tenant.
|
|
230
255
|
const report = await runReport(userId, runId, 0, "live");
|
|
231
256
|
const run = await db.query.run.findFirst({
|
|
@@ -6,7 +6,7 @@ import { db, schema } from "../db/client.js";
|
|
|
6
6
|
import { managed } from "../manage.js";
|
|
7
7
|
import { serverText } from "../texts.js";
|
|
8
8
|
import { draftFiles, readFile } from "./files.js";
|
|
9
|
-
import {
|
|
9
|
+
import { ownedSpace } from "./spaces.js";
|
|
10
10
|
import { addMessage, draftIssues, ownedWizard, wizardMessages, writableWizard } from "./wizards.js";
|
|
11
11
|
/** The formats a model can look at; an SVG it reads as text. */
|
|
12
12
|
const VISIBLE = new Set(["image/png", "image/jpeg", "image/gif", "image/webp"]);
|
|
@@ -36,7 +36,7 @@ lang, extra, io) {
|
|
|
36
36
|
// Asked before the first model call: a wizard that is not changed here costs nothing to refuse.
|
|
37
37
|
const w = await writableWizard(userId, wizardId);
|
|
38
38
|
const history = await wizardMessages(w.id);
|
|
39
|
-
const
|
|
39
|
+
const space = await ownedSpace(userId, w.spaceId);
|
|
40
40
|
const images = await attachedImages(userId, w.id, message);
|
|
41
41
|
const userMessageId = await addMessage(w.id, { role: "user", content: message });
|
|
42
42
|
try {
|
|
@@ -66,7 +66,7 @@ lang, extra, io) {
|
|
|
66
66
|
message,
|
|
67
67
|
extra,
|
|
68
68
|
history: history.map((m) => ({ role: m.role, content: m.content })),
|
|
69
|
-
connectors: await listConnectors(
|
|
69
|
+
connectors: await listConnectors(space.id),
|
|
70
70
|
signal: io.signal,
|
|
71
71
|
onText: io.onText,
|
|
72
72
|
onActivity: io.onActivity,
|
|
@@ -8,7 +8,7 @@ import { textModel } from "../models.js";
|
|
|
8
8
|
import { prompt } from "../prompts.js";
|
|
9
9
|
import { readSetting } from "../settings.js";
|
|
10
10
|
import { ServiceError } from "./errors.js";
|
|
11
|
-
import { trigramQuery } from "./
|
|
11
|
+
import { trigramQuery } from "./space-index.js";
|
|
12
12
|
/**
|
|
13
13
|
* The studio assistant's chats: one open chat per person and tenant, the same on every page and
|
|
14
14
|
* space. "New chat" closes it at once and writes its dense summary meanwhile; every turn of the
|
|
@@ -309,6 +309,14 @@ export async function assistantLayout(user) {
|
|
|
309
309
|
? stored
|
|
310
310
|
: "bottom";
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Where the person put the assistant in each area of the studio (`space`, `capabilities`, `work`
|
|
314
|
+
* …, the address's first part): an area without one takes `assistantLayout`.
|
|
315
|
+
*/
|
|
316
|
+
export async function assistantLayouts(user) {
|
|
317
|
+
const stored = await readSetting(`assistant-layouts:${user.tenantId}:${user.id}`);
|
|
318
|
+
return Object.fromEntries(Object.entries(stored ?? {}).filter(([, layout]) => ASSISTANT_LAYOUTS.includes(layout)));
|
|
319
|
+
}
|
|
312
320
|
/** The sidebar's width the person set with its handle; null: the default. */
|
|
313
321
|
export async function assistantWidth(user) {
|
|
314
322
|
const stored = await readSetting(`assistant-width:${user.tenantId}:${user.id}`);
|