@engenty/wizards-runtime 0.14.2 → 0.16.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/studio-assistant.js +180 -4
- package/apps/runtime/dist/agents/website.js +10 -5
- package/apps/runtime/dist/app.js +27 -2
- package/apps/runtime/dist/auth/index.js +5 -0
- package/apps/runtime/dist/broker/account.js +5 -0
- package/apps/runtime/dist/broker/call.js +2 -0
- package/apps/runtime/dist/broker/host.js +1 -0
- package/apps/runtime/dist/broker/index.js +5 -0
- package/apps/runtime/dist/broker/rwx.js +293 -11
- package/apps/runtime/dist/cli/main.js +7 -0
- package/apps/runtime/dist/cli/move-files.js +68 -0
- package/apps/runtime/dist/cli/move-folder-sources.js +120 -0
- package/apps/runtime/dist/connectors/plugin-connections.js +74 -4
- package/apps/runtime/dist/db/migrations/tenant/0040_rwx_elements.sql +21 -0
- package/apps/runtime/dist/db/migrations/tenant/0041_broker_log_client.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0042_client_spaces.sql +16 -0
- package/apps/runtime/dist/db/migrations/tenant/0043_space_member_invite.sql +19 -0
- package/apps/runtime/dist/db/migrations/tenant/0044_client_portal.sql +8 -0
- package/apps/runtime/dist/db/migrations/tenant/0045_client_portal_no_slug.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/0046_space_file_hash.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/0047_knowledge_folders.sql +3 -0
- package/apps/runtime/dist/db/migrations/tenant/0048_space_chunk_kind.sql +1 -0
- package/apps/runtime/dist/db/migrations/tenant/0049_knowledge_sources.sql +57 -0
- package/apps/runtime/dist/db/migrations/tenant/0050_dateien.sql +71 -0
- package/apps/runtime/dist/db/migrations/tenant/0051_dateien_drafts.sql +23 -0
- package/apps/runtime/dist/db/migrations/tenant/0052_dateien_plugin_kinds.sql +5 -0
- package/apps/runtime/dist/db/migrations/tenant/0053_dateien_file_title.sql +3 -0
- package/apps/runtime/dist/db/migrations/tenant/0054_dateien_ocr.sql +14 -0
- package/apps/runtime/dist/db/migrations/tenant/0055_dateien_doc_reread.sql +3 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0040_snapshot.json +5153 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0041_snapshot.json +5160 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0042_snapshot.json +5286 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0043_snapshot.json +5293 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0044_snapshot.json +5344 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0045_snapshot.json +5329 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0046_snapshot.json +5343 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0047_snapshot.json +5391 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0048_snapshot.json +5398 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0049_snapshot.json +5793 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0050_snapshot.json +6288 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0051_snapshot.json +6461 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0052_snapshot.json +6497 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0053_snapshot.json +6504 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0054_snapshot.json +6504 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0055_snapshot.json +6504 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +112 -0
- package/apps/runtime/dist/db/schema.js +296 -5
- package/apps/runtime/dist/docs/dev/api.md +49 -2
- package/apps/runtime/dist/docs/dev/architecture.md +13 -2
- package/apps/runtime/dist/docs/dev/plugins/connections.md +30 -2
- package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
- package/apps/runtime/dist/docs/dev/plugins/reference.md +7 -4
- package/apps/runtime/dist/docs/dev/plugins/server.md +11 -5
- package/apps/runtime/dist/docs/dev/plugins/space.md +130 -4
- package/apps/runtime/dist/docs/dev/plugins/studio.md +13 -3
- package/apps/runtime/dist/docs/user-guide/command-line.md +2 -0
- package/apps/runtime/dist/docs/user-guide/plugins.md +1 -1
- package/apps/runtime/dist/docs/user-guide/space.md +6 -6
- package/apps/runtime/dist/docs/user-guide/steps.md +1 -1
- package/apps/runtime/dist/documents/ocr.js +72 -0
- package/apps/runtime/dist/documents/parse.js +81 -12
- package/apps/runtime/dist/elements/caller.js +47 -0
- package/apps/runtime/dist/elements/catalogue.js +14 -0
- package/apps/runtime/dist/elements/connections.js +60 -0
- package/apps/runtime/dist/elements/gate.js +81 -0
- package/apps/runtime/dist/elements/knowledge.js +308 -0
- package/apps/runtime/dist/elements/outside.js +103 -0
- package/apps/runtime/dist/elements/specs.js +102 -0
- package/apps/runtime/dist/elements/wizards.js +72 -0
- package/apps/runtime/dist/engenty/connections-google/connectors/drive.js +3 -0
- package/apps/runtime/dist/engenty/connections-microsoft/onedrive.js +3 -0
- package/apps/runtime/dist/engenty/connections-s3/s3.js +6 -0
- package/apps/runtime/dist/engine/runner.js +19 -2
- package/apps/runtime/dist/engine/steps.js +1 -1
- package/apps/runtime/dist/env.js +11 -2
- package/apps/runtime/dist/files/blobs.js +57 -1
- package/apps/runtime/dist/files/objects.js +1 -0
- package/apps/runtime/dist/files/pictures.js +41 -0
- package/apps/runtime/dist/files/storage.js +14 -26
- package/apps/runtime/dist/files/thumbs.js +77 -0
- package/apps/runtime/dist/files/upload-check.js +2 -2
- package/apps/runtime/dist/index.js +22 -0
- package/apps/runtime/dist/live/views.js +2 -1
- package/apps/runtime/dist/manage.js +4 -1
- package/apps/runtime/dist/mcp/elements.js +88 -0
- package/apps/runtime/dist/mcp/handler.js +2 -0
- package/apps/runtime/dist/mcp/scopes.js +5 -0
- package/apps/runtime/dist/mcp/tools.js +5 -0
- package/apps/runtime/dist/models.js +82 -13
- package/apps/runtime/dist/mounts/cache.js +71 -0
- package/apps/runtime/dist/mounts/drafts.js +367 -0
- package/apps/runtime/dist/mounts/folder.js +148 -0
- package/apps/runtime/dist/mounts/mounts.js +1315 -0
- package/apps/runtime/dist/mounts/source.js +179 -0
- package/apps/runtime/dist/mounts/units.js +97 -0
- package/apps/runtime/dist/move-files.js +4 -0
- package/apps/runtime/dist/plugins/loader.js +73 -1
- package/apps/runtime/dist/plugins/registry.js +2 -0
- package/apps/runtime/dist/prompts/authoring.md +2 -2
- package/apps/runtime/dist/prompts/goose.md +13 -1
- package/apps/runtime/dist/prompts/tools.md +8 -2
- package/apps/runtime/dist/render/convert.js +188 -1
- package/apps/runtime/dist/routes/api.js +7 -2
- package/apps/runtime/dist/routes/client-contract.js +164 -0
- package/apps/runtime/dist/routes/client-spaces.js +58 -0
- package/apps/runtime/dist/routes/dateien.js +173 -0
- package/apps/runtime/dist/routes/elements.js +76 -0
- package/apps/runtime/dist/routes/plugins.js +2 -1
- package/apps/runtime/dist/routes/runs.js +24 -10
- package/apps/runtime/dist/routes/studio.js +168 -8
- package/apps/runtime/dist/secrets/signing.js +16 -0
- package/apps/runtime/dist/services/client-portal.js +439 -0
- package/apps/runtime/dist/services/client-spaces.js +228 -0
- package/apps/runtime/dist/services/cloud.js +2 -0
- package/apps/runtime/dist/services/knowledge-model.js +24 -8
- package/apps/runtime/dist/services/knowledge.js +72 -42
- package/apps/runtime/dist/services/links.js +17 -0
- package/apps/runtime/dist/services/members-studio.js +5 -1
- package/apps/runtime/dist/services/page-pictures.js +162 -0
- package/apps/runtime/dist/services/runs.js +22 -6
- package/apps/runtime/dist/services/space-categories.js +41 -5
- package/apps/runtime/dist/services/space-data.js +165 -8
- package/apps/runtime/dist/services/space-files.js +102 -19
- package/apps/runtime/dist/services/space-index.js +384 -41
- package/apps/runtime/dist/services/space-origin.js +25 -1
- package/apps/runtime/dist/services/space-sources.js +937 -0
- package/apps/runtime/dist/services/spaces.js +60 -12
- package/apps/runtime/dist/services/synced-spaces.js +10 -1
- package/apps/runtime/dist/services/work-ai.js +53 -24
- package/apps/runtime/dist/services/work-chats.js +3 -2
- package/apps/runtime/dist/services/work-connections.js +2 -2
- package/apps/runtime/dist/sharing/index.js +2 -0
- package/apps/runtime/dist/store/index.js +29 -8
- package/apps/runtime/dist/store/shared-lists.js +30 -17
- package/apps/runtime/dist/sync/records.js +22 -27
- package/apps/runtime/dist/texts.js +4 -0
- package/apps/runtime/dist/tools/index.js +5 -4
- package/apps/runtime/dist/tools/pages.js +1 -1
- package/apps/runtime/dist/tools/skills.js +80 -54
- package/apps/runtime/dist/tools/space.js +8 -152
- package/apps/runtime/dist/widgets/step.js +2 -1
- package/apps/web/dist/assets/AboutDialog-0q4P80yv.js +1 -0
- package/apps/web/dist/assets/BlockEditor-CUYFH_CU.js +173 -0
- package/apps/web/dist/assets/BlockEditor-CtW6lw0y.css +1 -0
- package/apps/web/dist/assets/CapabilitiesPage-BlZP8DYb.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-D_dQOMIq.js → ChangelogDialog-CDN7kMs1.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-nxoOt8ge.js → CodeEditor-D-Y16fdk.js} +1 -1
- package/apps/web/dist/assets/EditorPage-CrMVsgUt.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-aMfwcPul.js → FlowPreview-DXnk7m9P.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-DpD0inR4.js → LangSwitch-Dkd0FBIH.js} +1 -1
- package/apps/web/dist/assets/Marketplace-Cty40VwG.js +2 -0
- package/apps/web/dist/assets/NewWizardChannels-Czool7s1.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-CfVe_4a2.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-D3SEpTmt.js +1 -0
- package/apps/web/dist/assets/PreviewPane-CQDKQO6z.js +7 -0
- package/apps/web/dist/assets/PublicRunner-BDZNnlQw.js +1 -0
- package/apps/web/dist/assets/ReadOnly-B7MUySpC.js +1 -0
- package/apps/web/dist/assets/SettingsPage-Bgurv3l2.js +2 -0
- package/apps/web/dist/assets/SetupPage-C3km8vqv.js +1 -0
- package/apps/web/dist/assets/{SharePage-N80EhoD7.js → SharePage-UwEJBIzq.js} +1 -1
- package/apps/web/dist/assets/SkillEditor-BaEiqqXl.js +1 -0
- package/apps/web/dist/assets/Skills-Bv6XbKxc.js +9 -0
- package/apps/web/dist/assets/SpacePage-D9PXLSU_.js +2 -0
- package/apps/web/dist/assets/UpdateCheck-C7I43zFZ.js +2 -0
- package/apps/web/dist/assets/changelog-DwgWiSZb.js +1 -0
- package/apps/web/dist/assets/circle-check-DDLzlcXP.js +1 -0
- package/apps/web/dist/assets/code-DsnwzN1x.js +1 -0
- package/apps/web/dist/assets/code-editor-Ca5EAxmd.js +2 -0
- package/apps/web/dist/assets/code-xml-S4IFi5Jc.js +1 -0
- package/apps/web/dist/assets/connection-sign-in-hI3HXhq4.js +1 -0
- package/apps/web/dist/assets/{dist-H1UN89OA.js → dist-B3Ray2U5.js} +1 -1
- package/apps/web/dist/assets/dist-CQpLJoQZ.js +10 -0
- package/apps/web/dist/assets/{dist-GlRRx9Xl.js → dist-D1uGQ_tB.js} +1 -1
- package/apps/web/dist/assets/{dist-BdDd1FxP.js → dist-DFI-tsfx.js} +1 -1
- package/apps/web/dist/assets/eye-TJSuiHHO.js +1 -0
- package/apps/web/dist/assets/floating-ui.dom-pwdNGv4b.js +1 -0
- package/apps/web/dist/assets/host-D5hNHbhF.js +125 -0
- package/apps/web/dist/assets/i18n-BBzMbGoo.js +55 -0
- package/apps/web/dist/assets/index-CyBrvupM.js +10 -0
- package/apps/web/dist/assets/index-w-3J3ZJ9.css +1 -0
- package/apps/web/dist/assets/{json-CEsfHdlZ.js → json-Ce3iHrtf.js} +1 -1
- package/apps/web/dist/assets/link-CPL8pB1P.js +1 -0
- package/apps/web/dist/assets/list-checks-DaxmUPqK.js +1 -0
- package/apps/web/dist/assets/{markdown-5-I9_izp.js → markdown-hqKQy2pp.js} +1 -1
- package/apps/web/dist/assets/marked.esm-DQ7XA7AC.js +67 -0
- package/apps/web/dist/assets/oss-credits-BrwV0a4F.js +1 -0
- package/apps/web/dist/assets/pdf-Dg-raaUo.js +54 -0
- package/apps/web/dist/assets/pdf.worker.min-68CMzziE.js +1 -0
- package/apps/web/dist/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
- package/apps/web/dist/assets/phone-B4uKDBFq.js +1 -0
- package/apps/web/dist/assets/read-aloud-Bfp9_bUY.js +1 -0
- package/apps/web/dist/assets/{runners-CyIvJIHr.js → runners-CUpBpSji.js} +1 -1
- package/apps/web/dist/assets/scroll-text-BEnPzQEi.js +1 -0
- package/apps/web/dist/assets/session-CMQo8P-G.js +2 -0
- package/apps/web/dist/assets/table-5B9G3oA6.js +1 -0
- package/apps/web/dist/assets/theme-CdX0marK.js +11 -0
- package/apps/web/dist/assets/ui-BCfu5sia.js +16 -0
- package/apps/web/dist/assets/upload-CAlHC232.js +1 -0
- package/apps/web/dist/assets/{useMutation-DEkZhp5c.js → useMutation-1fV4Nnxq.js} +1 -1
- package/apps/web/dist/assets/viewers-ChriFcRy.js +2 -0
- package/apps/web/dist/assets/volume-2-BqlBtCIJ.js +1 -0
- package/apps/web/dist/assets/w3c-keyname-BOAvb0qz.js +1 -0
- package/apps/web/dist/assets/xlsx-CuSbHU4R.js +141 -0
- package/apps/web/dist/index.html +19 -14
- package/apps/web/dist/mcp/flow.html +2 -2
- package/node_modules/@engenty/wizards/dist/plugin/index.d.ts +223 -4
- package/node_modules/@engenty/wizards/dist/plugin/mount.d.ts +123 -0
- package/node_modules/@engenty/wizards/dist/plugin/mount.js +7 -0
- package/node_modules/@engenty/wizards/dist/plugin/studio.d.ts +110 -1
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +1 -1
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +24 -0
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +24 -0
- package/node_modules/@engenty/wizards-shared/dist/knowledge.d.ts +33 -4
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +12 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +21 -4
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +30 -3
- package/node_modules/@engenty/wizards-shared/dist/spaces.d.ts +11 -1
- package/node_modules/@engenty/wizards-shared/dist/spaces.js +9 -2
- package/node_modules/@engenty/wizards-shared/dist/text-merge.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/text-merge.js +25 -0
- package/package.json +3 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/README.md +3 -0
- package/plugin/plugin.json +1 -1
- package/plugin/skills/work-in-space/SKILL.md +16 -0
- package/apps/web/dist/assets/AboutDialog-Cag3RJuT.js +0 -1
- package/apps/web/dist/assets/CapabilitiesPage-BQYiN0gT.js +0 -2
- package/apps/web/dist/assets/EditorPage-C4_8LsQN.js +0 -3
- package/apps/web/dist/assets/Marketplace-CpzD9pNQ.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-CcE3UMVb.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-BzN7zrQx.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-ztHT01ah.js +0 -1
- package/apps/web/dist/assets/PreviewPane-BabMbBZI.js +0 -9
- package/apps/web/dist/assets/PublicRunner-D-JmtqCi.js +0 -1
- package/apps/web/dist/assets/ReadOnly-GAORKKqV.js +0 -1
- package/apps/web/dist/assets/SettingsPage-BKAiYmXl.js +0 -2
- package/apps/web/dist/assets/SetupPage-C1EZZHIp.js +0 -1
- package/apps/web/dist/assets/SkillEditor-CqQMg2MC.js +0 -1
- package/apps/web/dist/assets/Skills-CnhpgoOA.js +0 -9
- package/apps/web/dist/assets/SpacePage-CRR8JvV1.js +0 -2
- package/apps/web/dist/assets/UpdateCheck-CfXZBQNv.js +0 -2
- package/apps/web/dist/assets/changelog-6MqC8Vy8.js +0 -1
- package/apps/web/dist/assets/circle-alert-C8Ma-bPY.js +0 -1
- package/apps/web/dist/assets/circle-check-Bu9Z3mlJ.js +0 -1
- package/apps/web/dist/assets/code-editor-CfTGqOpp.js +0 -2
- package/apps/web/dist/assets/code-xml-B4kLFZSj.js +0 -1
- package/apps/web/dist/assets/connection-sign-in-B2D0O8W-.js +0 -1
- package/apps/web/dist/assets/dist-EBVTpvRr.js +0 -10
- package/apps/web/dist/assets/eye-BpoKpIdt.js +0 -1
- package/apps/web/dist/assets/host-BlKXX7YK.js +0 -118
- package/apps/web/dist/assets/i18n-BJ7Ld6O6.js +0 -55
- package/apps/web/dist/assets/index-66tE1oti.js +0 -10
- package/apps/web/dist/assets/index-D18DvnxX.css +0 -1
- package/apps/web/dist/assets/oss-credits-IdX5bc71.js +0 -1
- package/apps/web/dist/assets/phone-Ctvf-Am-.js +0 -1
- package/apps/web/dist/assets/read-aloud-Da_RSm2S.js +0 -1
- package/apps/web/dist/assets/scroll-text-ChrjRu9Y.js +0 -1
- package/apps/web/dist/assets/session-SXPtTWRK.js +0 -2
- package/apps/web/dist/assets/theme-Br1S0j5h.js +0 -11
- package/apps/web/dist/assets/ui-Uqnx1UpK.js +0 -82
- package/apps/web/dist/assets/upload-BchUnQGV.js +0 -1
- package/apps/web/dist/assets/volume-2-CU_oy81Z.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { note } from "@engenty/wizards-shared/run";
|
|
2
|
-
import { COLOR_SECTION_KINDS, cleanAssetSections, cleanLogoSections, FACT_TYPES, FONT_USES, FONT_WEIGHTS, GRADIENT_TYPES, NOTIFY_MAIL, orderColors, PAGE_LANGS, PAGE_LIMITS, PAGE_SLUG, RULE_MARKS, SPACE_LIMITS, } from "@engenty/wizards-shared/spaces";
|
|
2
|
+
import { COLOR_SECTION_KINDS, cleanAssetSections, cleanLogoSections, FACT_TYPES, FONT_USES, FONT_WEIGHTS, GRADIENT_TYPES, NOTIFY_MAIL, orderColors, PAGE_LANGS, PAGE_LIMITS, PAGE_SLUG, RESERVED_PAGE_SLUGS, RULE_MARKS, SPACE_LIMITS, } from "@engenty/wizards-shared/spaces";
|
|
3
3
|
import { and, count, eq, isNull, ne } from "drizzle-orm";
|
|
4
4
|
import { nanoid } from "nanoid";
|
|
5
5
|
import { z } from "zod";
|
|
@@ -11,9 +11,9 @@ import { cloudSpaceLimit, twoWayActive } from "../sync/state.js";
|
|
|
11
11
|
import { putLink } from "../tenants/control.js";
|
|
12
12
|
import { currentTenant } from "../tenants/tenant.js";
|
|
13
13
|
import { serverText } from "../texts.js";
|
|
14
|
-
import { mayBuild, requireAdmin, requireBuild, requireWritable } from "./access.js";
|
|
14
|
+
import { currentRole, mayBuild, requireAdmin, requireBuild, requireWritable } from "./access.js";
|
|
15
15
|
import { notFound, ServiceError } from "./errors.js";
|
|
16
|
-
import { forgetWizardLinks } from "./links.js";
|
|
16
|
+
import { forgetWizardLinks, removeClientSpaceRuns } from "./links.js";
|
|
17
17
|
import { pushPages } from "./pages.js";
|
|
18
18
|
import { removeSpaceFiles } from "./space-files.js";
|
|
19
19
|
const sectionId = z.string().regex(/^[A-Za-z0-9_-]{1,40}$/);
|
|
@@ -200,15 +200,28 @@ export async function spaceLimitOrNull() {
|
|
|
200
200
|
const limit = await spaceLimit();
|
|
201
201
|
return Number.isFinite(limit) ? limit : null;
|
|
202
202
|
}
|
|
203
|
-
export async function ownedSpace(
|
|
203
|
+
export async function ownedSpace(userId, spaceId) {
|
|
204
204
|
const p = await db.query.space.findFirst({
|
|
205
205
|
where: and(eq(schema.space.id, spaceId), eq(schema.space.tenantId, currentTenant())),
|
|
206
206
|
});
|
|
207
207
|
if (!p) {
|
|
208
208
|
throw notFound();
|
|
209
209
|
}
|
|
210
|
+
// A client of the organization reaches only the client spaces they are in
|
|
211
|
+
// (docs/plans/client-spaces.md); every other space is not there for them.
|
|
212
|
+
if (currentRole() === "client" && !(p.kind === "client" && (await inSpace(userId, p.id)))) {
|
|
213
|
+
throw notFound();
|
|
214
|
+
}
|
|
210
215
|
return p;
|
|
211
216
|
}
|
|
217
|
+
/** Whether the person is a member of the space, as a client or as the firm's (`space_member`). */
|
|
218
|
+
async function inSpace(userId, spaceId) {
|
|
219
|
+
const row = await db.query.spaceMember.findFirst({
|
|
220
|
+
columns: { id: true },
|
|
221
|
+
where: and(eq(schema.spaceMember.spaceId, spaceId), eq(schema.spaceMember.userId, userId)),
|
|
222
|
+
});
|
|
223
|
+
return Boolean(row);
|
|
224
|
+
}
|
|
212
225
|
/** The tenant's spaces that were made here, not synced from a local install. */
|
|
213
226
|
const madeHere = () => and(eq(schema.space.tenantId, currentTenant()), isNull(schema.space.origin));
|
|
214
227
|
/** The tenant's spaces a local install synced. */
|
|
@@ -235,13 +248,20 @@ async function ensureSpace(lang = "en") {
|
|
|
235
248
|
* The space a caller means when it names none: the oldest one made here, where a wizard
|
|
236
249
|
* lands; for a tenant that builds nothing here, the one its local install synced.
|
|
237
250
|
*/
|
|
238
|
-
export async function defaultSpace(
|
|
251
|
+
export async function defaultSpace(userId) {
|
|
252
|
+
if (currentRole() === "client") {
|
|
253
|
+
const [first] = await clientSpacesOf(userId);
|
|
254
|
+
if (!first) {
|
|
255
|
+
throw notFound();
|
|
256
|
+
}
|
|
257
|
+
return first;
|
|
258
|
+
}
|
|
239
259
|
const build = await mayBuild();
|
|
240
260
|
if (build) {
|
|
241
261
|
await ensureSpace();
|
|
242
262
|
}
|
|
243
263
|
const p = await db.query.space.findFirst({
|
|
244
|
-
where: build ? madeHere() : synced(),
|
|
264
|
+
where: and(build ? madeHere() : synced(), eq(schema.space.kind, "space")),
|
|
245
265
|
orderBy: [schema.space.createdAt],
|
|
246
266
|
});
|
|
247
267
|
if (!p) {
|
|
@@ -253,15 +273,20 @@ export async function defaultSpace(_userId) {
|
|
|
253
273
|
* The spaces the studio shows. A tenant that builds here: its own and the synced ones, up to
|
|
254
274
|
* its number. One that does not: only what its local install synced — possibly nothing yet.
|
|
255
275
|
*/
|
|
256
|
-
export async function listSpaces(
|
|
276
|
+
export async function listSpaces(userId, lang) {
|
|
277
|
+
// A client sees the client spaces they are in, nothing else (docs/plans/client-spaces.md).
|
|
278
|
+
if (currentRole() === "client") {
|
|
279
|
+
return clientSpacesOf(userId);
|
|
280
|
+
}
|
|
257
281
|
const build = await mayBuild();
|
|
258
282
|
if (build) {
|
|
259
283
|
await ensureSpace(lang);
|
|
260
284
|
}
|
|
261
|
-
// The oldest come first: with a limit of one, that is the space everything lands in.
|
|
285
|
+
// The oldest come first: with a limit of one, that is the space everything lands in. Client
|
|
286
|
+
// spaces stay out: they are a part of their space, never a space of the menu.
|
|
262
287
|
const limit = await spaceLimit();
|
|
263
288
|
const spaces = await db.query.space.findMany({
|
|
264
|
-
where: build ? eq(schema.space.tenantId, currentTenant()) : synced(),
|
|
289
|
+
where: and(build ? eq(schema.space.tenantId, currentTenant()) : synced(), eq(schema.space.kind, "space")),
|
|
265
290
|
orderBy: [schema.space.createdAt],
|
|
266
291
|
...(Number.isFinite(limit) ? { limit } : {}),
|
|
267
292
|
});
|
|
@@ -275,13 +300,23 @@ export async function listSpaces(_userId, lang) {
|
|
|
275
300
|
wizardCount: counts.find((x) => x.spaceId === p.id)?.n ?? 0,
|
|
276
301
|
}));
|
|
277
302
|
}
|
|
303
|
+
/** The client spaces a client is in, as the space list shows them. */
|
|
304
|
+
async function clientSpacesOf(userId) {
|
|
305
|
+
const rows = await db
|
|
306
|
+
.select({ space: schema.space })
|
|
307
|
+
.from(schema.spaceMember)
|
|
308
|
+
.innerJoin(schema.space, eq(schema.space.id, schema.spaceMember.spaceId))
|
|
309
|
+
.where(and(eq(schema.spaceMember.userId, userId), eq(schema.space.tenantId, currentTenant()), eq(schema.space.kind, "client")));
|
|
310
|
+
return rows.map((r) => ({ ...r.space, wizardCount: 0 }));
|
|
311
|
+
}
|
|
278
312
|
export async function createSpace(_userId, name) {
|
|
279
313
|
await requireBuild();
|
|
280
314
|
await requireAdmin();
|
|
315
|
+
// Client spaces do not count as spaces of the plan.
|
|
281
316
|
const [{ n }] = await db
|
|
282
317
|
.select({ n: count() })
|
|
283
318
|
.from(schema.space)
|
|
284
|
-
.where(eq(schema.space.tenantId, currentTenant()));
|
|
319
|
+
.where(and(eq(schema.space.tenantId, currentTenant()), eq(schema.space.kind, "space")));
|
|
285
320
|
const limit = await spaceLimit();
|
|
286
321
|
if (n >= limit) {
|
|
287
322
|
throw new ServiceError("refused", limit === 1 ? note("onlyOneSpaceAllowed") : note("mostSpaces", { count: limit }));
|
|
@@ -330,6 +365,9 @@ async function checkedPage(p, page) {
|
|
|
330
365
|
if (!PAGE_SLUG.test(page.slug)) {
|
|
331
366
|
throw new ServiceError("invalid", note("pageSlugInvalid"));
|
|
332
367
|
}
|
|
368
|
+
if (RESERVED_PAGE_SLUGS.includes(page.slug)) {
|
|
369
|
+
throw new ServiceError("invalid", note("pageSlugReserved"));
|
|
370
|
+
}
|
|
333
371
|
const others = await db.query.space.findMany({
|
|
334
372
|
where: and(eq(schema.space.tenantId, currentTenant()), ne(schema.space.id, p.id)),
|
|
335
373
|
columns: { id: true, name: true, page: true },
|
|
@@ -510,14 +548,23 @@ export function spaceProfile(p) {
|
|
|
510
548
|
export async function deleteSpace(userId, spaceId) {
|
|
511
549
|
await requireWritable(await ownedSpace(userId, spaceId));
|
|
512
550
|
await requireAdmin();
|
|
513
|
-
const all = await db.query.space.findMany({
|
|
551
|
+
const all = await db.query.space.findMany({
|
|
552
|
+
where: and(madeHere(), eq(schema.space.kind, "space")),
|
|
553
|
+
});
|
|
514
554
|
if (all.length <= 1) {
|
|
515
555
|
throw new ServiceError("refused", note("notDeleteLastSpace"));
|
|
516
556
|
}
|
|
517
557
|
await removeSpace(spaceId);
|
|
518
558
|
}
|
|
519
|
-
/** Takes a space away with its wizards' links and its files. */
|
|
559
|
+
/** Takes a space away with its wizards' links and its files, and its client spaces first. */
|
|
520
560
|
export async function removeSpace(spaceId) {
|
|
561
|
+
const clients = await db
|
|
562
|
+
.select({ id: schema.space.id })
|
|
563
|
+
.from(schema.space)
|
|
564
|
+
.where(and(eq(schema.space.parentId, spaceId), eq(schema.space.tenantId, currentTenant())));
|
|
565
|
+
for (const c of clients) {
|
|
566
|
+
await removeSpace(c.id);
|
|
567
|
+
}
|
|
521
568
|
const wizards = await db
|
|
522
569
|
.select({ id: schema.wizard.id })
|
|
523
570
|
.from(schema.wizard)
|
|
@@ -525,6 +572,7 @@ export async function removeSpace(spaceId) {
|
|
|
525
572
|
for (const w of wizards) {
|
|
526
573
|
await forgetWizardLinks(w.id);
|
|
527
574
|
}
|
|
575
|
+
await removeClientSpaceRuns(spaceId);
|
|
528
576
|
await removeSpaceFiles(spaceId);
|
|
529
577
|
await db
|
|
530
578
|
.delete(schema.space)
|
|
@@ -434,6 +434,8 @@ export const syncDataSchema = z.object({
|
|
|
434
434
|
title: z.string().min(1).max(120),
|
|
435
435
|
format: z.enum(["faq"]).nullish(),
|
|
436
436
|
originLabel: z.string().max(120).nullish(),
|
|
437
|
+
parentId: syncedId.nullish(),
|
|
438
|
+
position: z.number().int().min(0).optional(),
|
|
437
439
|
columns: tableColumnsSchema,
|
|
438
440
|
rows: z
|
|
439
441
|
.array(z.object({ id: syncedId, cells: z.record(z.string(), z.unknown()) }))
|
|
@@ -576,7 +578,14 @@ export async function syncSpaceData(rawSpaceId, input) {
|
|
|
576
578
|
for (const table of input.tables) {
|
|
577
579
|
await db
|
|
578
580
|
.update(schema.spaceTable)
|
|
579
|
-
.set({
|
|
581
|
+
.set({
|
|
582
|
+
format: table.format ?? null,
|
|
583
|
+
originLabel: table.originLabel ?? null,
|
|
584
|
+
slug: null,
|
|
585
|
+
// Its folder, once every page is there.
|
|
586
|
+
parentId: table.parentId && pagesThere.has(table.parentId) ? table.parentId : null,
|
|
587
|
+
position: table.position ?? 0,
|
|
588
|
+
})
|
|
580
589
|
.where(eq(schema.spaceTable.id, table.id));
|
|
581
590
|
}
|
|
582
591
|
if (input.categories) {
|
|
@@ -4,7 +4,8 @@ import { createTool } from "@mastra/core/tools";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { sortedTools } from "../agents/space-agent.js";
|
|
6
6
|
import { chatTurnWay } from "../agents/subscription.js";
|
|
7
|
-
import {
|
|
7
|
+
import { personCaller } from "../elements/caller.js";
|
|
8
|
+
import { elementTools } from "../elements/catalogue.js";
|
|
8
9
|
import { currentFeatures } from "../features.js";
|
|
9
10
|
import { HarnessModel } from "../harness/index.js";
|
|
10
11
|
import { managed } from "../manage.js";
|
|
@@ -15,11 +16,10 @@ import { sandboxCapabilities, shellToolDescription } from "../sandbox/index.js";
|
|
|
15
16
|
import { currentTenant } from "../tenants/tenant.js";
|
|
16
17
|
import { assistantToolPlugin, assistantToolRisk, assistantToolsOf } from "../tools/plugin.js";
|
|
17
18
|
import { clip } from "../tools/shared.js";
|
|
18
|
-
import { skillsBlock
|
|
19
|
+
import { skillsBlock } from "../tools/skills.js";
|
|
19
20
|
import { roleOf } from "./access.js";
|
|
20
21
|
import { ClientSteps } from "./client-steps.js";
|
|
21
22
|
import { activeSkills } from "./skills.js";
|
|
22
|
-
import { searchKnowledge } from "./space-index.js";
|
|
23
23
|
import { holdCall } from "./work-approvals.js";
|
|
24
24
|
import { workConnectionTools } from "./work-connections.js";
|
|
25
25
|
import { chatSandbox } from "./work-sandbox.js";
|
|
@@ -34,10 +34,14 @@ export const TURN_KEY = "workTurn";
|
|
|
34
34
|
export const TURN_MS = 20 * 60_000;
|
|
35
35
|
/** Steps one turn may take. */
|
|
36
36
|
export const MAX_STEPS = 16;
|
|
37
|
-
const instructionsFor = (space, skills) => [
|
|
38
|
-
|
|
37
|
+
const instructionsFor = (space, skills, knowledge, client) => [
|
|
38
|
+
client
|
|
39
|
+
? `You are the AI of the firm that runs the client space "${space}" in engenty wizards, and you answer one of the firm's clients there. The firm's people read this chat too. Answer from the client space and what the firm opened to its clients; where you can't know, say so and suggest asking the firm. When one of the firm's wizards fits the request, run it with wizard_run. In German, say du, as the client portal does.`
|
|
40
|
+
: `You are the AI of the space "${space}" in engenty wizards. The team of the space talks with you and with each other in this chat.`,
|
|
39
41
|
'Each message of a person comes as <user name="…">; answer the person who asked you, in their language, and call them by their name only when it helps.',
|
|
40
|
-
|
|
42
|
+
knowledge
|
|
43
|
+
? "Before you answer about the space (its clients, matters, files, data), look it up with space_search; say where you found it. When you can't find it, say so."
|
|
44
|
+
: "The space has no knowledge yet: say so when you're asked about its clients, matters, files or data.",
|
|
41
45
|
"Write short, plain answers. Use lists or a table where they help. Rows, figures, a comparison or a few questions to the team can be a view instead: show_view.",
|
|
42
46
|
skills,
|
|
43
47
|
]
|
|
@@ -114,12 +118,30 @@ export const showView = () => createTool({
|
|
|
114
118
|
});
|
|
115
119
|
/** Whether the model can search the web itself: on Anthropic's API, or through the gateway. */
|
|
116
120
|
const searches = (resolved) => resolved.vendor === "anthropic" || resolved.gateway;
|
|
121
|
+
/**
|
|
122
|
+
* A client's turn (docs/plans/client-portal.md, phase 1): the client space's Knowledge with what
|
|
123
|
+
* the firm opened to clients, the wizards opened to them (a run lands in the client space) and
|
|
124
|
+
* views. No skills, sandbox, connections, plugins or web: nothing that reaches past the client
|
|
125
|
+
* space or spends on the firm's sign-ins.
|
|
126
|
+
*/
|
|
127
|
+
async function clientTools(space, userId, signal, chatId) {
|
|
128
|
+
const caller = personCaller({ space, userId, role: "client", signal, chatId });
|
|
129
|
+
return sortedTools({
|
|
130
|
+
...(await elementTools(caller, { knowledge: true, wizards: true })),
|
|
131
|
+
show_view: showView(),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
117
134
|
/**
|
|
118
135
|
* The space's tools for a turn: its knowledge, its skills, the chat's sandbox, the space's
|
|
119
136
|
* connections open to the person (work-connections.ts), the plugins' tools, the web; the plugins
|
|
120
|
-
* and the web the person turned off (`choice`) left out.
|
|
137
|
+
* and the web the person turned off (`choice`) left out. A client gets `clientTools` alone.
|
|
138
|
+
* `role`: the person's, where the session knows it; else the organization's list says.
|
|
121
139
|
*/
|
|
122
|
-
async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = null, approved = null) {
|
|
140
|
+
async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = null, approved = null, known = null) {
|
|
141
|
+
const role = known ?? (await roleOf(userId));
|
|
142
|
+
if (role === "client") {
|
|
143
|
+
return clientTools(space, userId, signal, chatId ?? approved?.chatId ?? null);
|
|
144
|
+
}
|
|
123
145
|
const sandbox = sandboxTools(chatId);
|
|
124
146
|
const connections = await workConnectionTools({
|
|
125
147
|
space,
|
|
@@ -127,22 +149,24 @@ async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = n
|
|
|
127
149
|
chatId: chatId ?? approved?.chatId ?? null,
|
|
128
150
|
byAdmin: approved?.byAdmin,
|
|
129
151
|
});
|
|
130
|
-
|
|
131
|
-
//
|
|
132
|
-
const
|
|
152
|
+
// The turn reads as the person who asked: what they may not read, the AI does not find. Its
|
|
153
|
+
// Knowledge and skills come from the tool catalogue (elements/), as a step's and Goose's do.
|
|
154
|
+
const caller = personCaller({
|
|
155
|
+
space,
|
|
156
|
+
userId,
|
|
157
|
+
role,
|
|
158
|
+
signal,
|
|
159
|
+
chatId: chatId ?? approved?.chatId ?? null,
|
|
160
|
+
sandbox: sandbox.skill,
|
|
161
|
+
});
|
|
133
162
|
const tools = {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const found = await searchKnowledge(space.id, query, { limit: 8, signal, who });
|
|
140
|
-
return { hits: found.hits };
|
|
141
|
-
},
|
|
142
|
-
}),
|
|
163
|
+
...(await elementTools(caller, {
|
|
164
|
+
knowledge: true,
|
|
165
|
+
skills: await spaceSkills(space.id),
|
|
166
|
+
wizards: true,
|
|
167
|
+
})),
|
|
143
168
|
show_view: showView(),
|
|
144
169
|
...sandbox.tools,
|
|
145
|
-
...(skills ? skillToolsOf(skills, () => { }, sandbox.skill) : {}),
|
|
146
170
|
...connections.tools,
|
|
147
171
|
...(await assistantToolsOf({
|
|
148
172
|
tenantId: currentTenant(),
|
|
@@ -230,14 +254,19 @@ export async function toolToRun(space, userId, name, signal, approved) {
|
|
|
230
254
|
*/
|
|
231
255
|
export async function workTurn(turn, signal, steps, choice = {}) {
|
|
232
256
|
const resolved = await chatModel(await chatTurnWay(managed), choice.extra ? "high" : "standard");
|
|
233
|
-
const
|
|
257
|
+
const client = turn.role === "client";
|
|
258
|
+
const made = gated(await toolsFor(resolved, turn.space, turn.userId, signal, choice, turn.chatId, null, turn.role ?? null), turn);
|
|
234
259
|
const tools = resolved.model instanceof HarnessModel ? steps.wrap(made) : made;
|
|
235
260
|
attachTools(resolved, tools);
|
|
236
|
-
const skills = await spaceSkills(turn.space.id);
|
|
261
|
+
const skills = client ? null : await spaceSkills(turn.space.id);
|
|
237
262
|
const block = skills
|
|
238
263
|
? skillsBlock(skills, { tools: true, sandbox: sandboxCapabilities() !== null })
|
|
239
264
|
: "";
|
|
240
|
-
return {
|
|
265
|
+
return {
|
|
266
|
+
resolved,
|
|
267
|
+
tools,
|
|
268
|
+
instructions: instructionsFor(turn.space.name, block, "space_search" in tools, client),
|
|
269
|
+
};
|
|
241
270
|
}
|
|
242
271
|
export function lazyTurn(turn, choice = {}) {
|
|
243
272
|
const controller = new AbortController();
|
|
@@ -380,7 +380,7 @@ options = {}) {
|
|
|
380
380
|
return { kind: "kept" };
|
|
381
381
|
}
|
|
382
382
|
// Asking the AI is a signal that isn't stored: the stored message is what it answers.
|
|
383
|
-
const { turn, streamOptions } = await turnFor(chat, user.id, options.choice);
|
|
383
|
+
const { turn, streamOptions } = await turnFor(chat, user.id, options.choice, user.role);
|
|
384
384
|
const asked = {
|
|
385
385
|
type: "reactive",
|
|
386
386
|
tagName: "asked",
|
|
@@ -412,12 +412,13 @@ options = {}) {
|
|
|
412
412
|
* A turn for the person, made when it really starts (Mastra resolves the agent's model then):
|
|
413
413
|
* input taken into a running turn builds nothing, and a queued one's 20 minutes start with it.
|
|
414
414
|
*/
|
|
415
|
-
async function turnFor(chat, userId, choice = {}) {
|
|
415
|
+
async function turnFor(chat, userId, choice = {}, role) {
|
|
416
416
|
const space = await db.query.space.findFirst({ where: eq(schema.space.id, chat.spaceId) });
|
|
417
417
|
const turn = lazyTurn({
|
|
418
418
|
space: { id: chat.spaceId, name: space?.name ?? "" },
|
|
419
419
|
chatId: chat.id,
|
|
420
420
|
userId,
|
|
421
|
+
role,
|
|
421
422
|
}, choice);
|
|
422
423
|
const requestContext = new RequestContext();
|
|
423
424
|
requestContext.set(TURN_KEY, turn);
|
|
@@ -15,7 +15,7 @@ import { holdCall } from "./work-approvals.js";
|
|
|
15
15
|
* again, for the space's admins under the bell; an admin's yes runs it.
|
|
16
16
|
*/
|
|
17
17
|
/** Who a chat's turn calls as: the person, an admin where their role in the organization says so. */
|
|
18
|
-
async function chatWho(userId) {
|
|
18
|
+
export async function chatWho(userId) {
|
|
19
19
|
const role = await roleOf(userId);
|
|
20
20
|
return { kind: isAdminRole(role) ? "admin" : "person", id: userId };
|
|
21
21
|
}
|
|
@@ -23,7 +23,7 @@ async function chatWho(userId) {
|
|
|
23
23
|
* The connections of the space this person reaches in a chat: those open to their role, and of
|
|
24
24
|
* the ones in which each person signs in, only those they signed in to.
|
|
25
25
|
*/
|
|
26
|
-
async function chatConnectionTools(spaceId, userId, who) {
|
|
26
|
+
export async function chatConnectionTools(spaceId, userId, who) {
|
|
27
27
|
const rows = await listSpaceConnections(spaceId);
|
|
28
28
|
const own = rows.some((r) => r.signIn === "person")
|
|
29
29
|
? new Set((await db.query.spaceConnectionSignIn.findMany({
|
|
@@ -18,13 +18,17 @@ export function holderOf(run) {
|
|
|
18
18
|
return run.visitorId ? `v:${run.visitorId}` : `r:${run.id}`;
|
|
19
19
|
}
|
|
20
20
|
export function scopeOf(run) {
|
|
21
|
-
return {
|
|
21
|
+
return {
|
|
22
|
+
wizardId: run.wizardId,
|
|
23
|
+
holder: holderOf(run),
|
|
24
|
+
...(run.clientSpaceId ? { clientSpaceId: run.clientSpaceId } : {}),
|
|
25
|
+
};
|
|
22
26
|
}
|
|
23
27
|
/** Marks the store as in use; stores nobody came back to are cleaned up. */
|
|
24
28
|
export async function touchStore(scope) {
|
|
25
29
|
await db
|
|
26
30
|
.insert(schema.storeHolder)
|
|
27
|
-
.values({
|
|
31
|
+
.values({ wizardId: scope.wizardId, holder: scope.holder, usedAt: new Date() })
|
|
28
32
|
.onConflictDoUpdate({
|
|
29
33
|
target: [schema.storeHolder.wizardId, schema.storeHolder.holder],
|
|
30
34
|
set: { usedAt: new Date() },
|
|
@@ -41,7 +45,7 @@ function toRow(r) {
|
|
|
41
45
|
*/
|
|
42
46
|
export async function listRows(scope, def, who = []) {
|
|
43
47
|
if (def.shared) {
|
|
44
|
-
return sharedRows(scope
|
|
48
|
+
return sharedRows(scope, def, who);
|
|
45
49
|
}
|
|
46
50
|
const rows = await db.query.storeRow.findMany({
|
|
47
51
|
where: inList(scope, def.id),
|
|
@@ -56,7 +60,7 @@ export async function listRows(scope, def, who = []) {
|
|
|
56
60
|
*/
|
|
57
61
|
export async function saveRows(scope, def, input) {
|
|
58
62
|
if (def.shared) {
|
|
59
|
-
return saveSharedRows(scope
|
|
63
|
+
return saveSharedRows(scope, def, input);
|
|
60
64
|
}
|
|
61
65
|
let added = 0;
|
|
62
66
|
let updated = 0;
|
|
@@ -86,7 +90,8 @@ export async function saveRows(scope, def, input) {
|
|
|
86
90
|
}
|
|
87
91
|
const row = {
|
|
88
92
|
id: nanoid(14),
|
|
89
|
-
|
|
93
|
+
wizardId: scope.wizardId,
|
|
94
|
+
holder: scope.holder,
|
|
90
95
|
list: def.id,
|
|
91
96
|
key,
|
|
92
97
|
cells,
|
|
@@ -132,7 +137,7 @@ export async function updateRow(scope, def, rowId, patch) {
|
|
|
132
137
|
/** Deletes rows by id, or by the value of the key column. */
|
|
133
138
|
export async function deleteRows(scope, def, idsOrKeys) {
|
|
134
139
|
if (def.shared) {
|
|
135
|
-
return deleteSharedRows(scope
|
|
140
|
+
return deleteSharedRows(scope, def, idsOrKeys);
|
|
136
141
|
}
|
|
137
142
|
if (!idsOrKeys.length) {
|
|
138
143
|
return 0;
|
|
@@ -227,7 +232,15 @@ export async function writeStoreFile(scope, rawPath, content, meta = {}) {
|
|
|
227
232
|
const updatedAt = new Date();
|
|
228
233
|
await db
|
|
229
234
|
.insert(schema.storeFile)
|
|
230
|
-
.values({
|
|
235
|
+
.values({
|
|
236
|
+
wizardId: scope.wizardId,
|
|
237
|
+
holder: scope.holder,
|
|
238
|
+
path,
|
|
239
|
+
hash,
|
|
240
|
+
mime,
|
|
241
|
+
size: data.byteLength,
|
|
242
|
+
source: meta.source ?? null,
|
|
243
|
+
})
|
|
231
244
|
.onConflictDoUpdate({
|
|
232
245
|
target: [schema.storeFile.wizardId, schema.storeFile.holder, schema.storeFile.path],
|
|
233
246
|
set: { hash, mime, size: data.byteLength, source: meta.source ?? null, updatedAt },
|
|
@@ -264,7 +277,15 @@ export async function putSecret(scope, slot, provider, label, data) {
|
|
|
264
277
|
const sealed = seal(data);
|
|
265
278
|
await db
|
|
266
279
|
.insert(schema.storeSecret)
|
|
267
|
-
.values({
|
|
280
|
+
.values({
|
|
281
|
+
id: nanoid(14),
|
|
282
|
+
wizardId: scope.wizardId,
|
|
283
|
+
holder: scope.holder,
|
|
284
|
+
slot,
|
|
285
|
+
provider,
|
|
286
|
+
label,
|
|
287
|
+
data: sealed,
|
|
288
|
+
})
|
|
268
289
|
.onConflictDoUpdate({
|
|
269
290
|
target: [schema.storeSecret.wizardId, schema.storeSecret.holder, schema.storeSecret.slot],
|
|
270
291
|
set: { provider, label, data: sealed, updatedAt: new Date() },
|
|
@@ -5,9 +5,22 @@ import { assertRwx } from "../broker/rwx.js";
|
|
|
5
5
|
import { db, schema } from "../db/client.js";
|
|
6
6
|
import { StoreError } from "./errors.js";
|
|
7
7
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The table a shared list is kept in: made the first time, following the list as it changes. A
|
|
10
|
+
* run of a client space keeps it in the client space (docs/plans/client-portal.md): the firm's
|
|
11
|
+
* clients never share a list.
|
|
12
|
+
*/
|
|
13
|
+
export async function sharedTable(scope, def) {
|
|
14
|
+
const { wizardId } = scope;
|
|
15
|
+
const wizard = await db.query.wizard.findFirst({
|
|
16
|
+
where: eq(schema.wizard.id, wizardId),
|
|
17
|
+
columns: { spaceId: true, tenantId: true },
|
|
18
|
+
});
|
|
19
|
+
if (!wizard) {
|
|
20
|
+
throw new StoreError("The wizard is gone.");
|
|
21
|
+
}
|
|
22
|
+
const spaceId = scope.clientSpaceId ?? wizard.spaceId;
|
|
23
|
+
const where = and(eq(schema.spaceTable.spaceId, spaceId), eq(schema.spaceTable.wizardId, wizardId), eq(schema.spaceTable.list, def.id));
|
|
11
24
|
const found = await db.query.spaceTable.findFirst({ where });
|
|
12
25
|
const shape = { title: def.title, columns: def.columns, keyColumn: def.key ?? null };
|
|
13
26
|
if (found) {
|
|
@@ -22,17 +35,17 @@ export async function sharedTable(wizardId, def) {
|
|
|
22
35
|
}
|
|
23
36
|
return found;
|
|
24
37
|
}
|
|
25
|
-
const wizard = await db.query.wizard.findFirst({
|
|
26
|
-
where: eq(schema.wizard.id, wizardId),
|
|
27
|
-
columns: { spaceId: true, tenantId: true },
|
|
28
|
-
});
|
|
29
|
-
if (!wizard) {
|
|
30
|
-
throw new StoreError("The wizard is gone.");
|
|
31
|
-
}
|
|
32
38
|
// Two runs that start at once make it once.
|
|
33
39
|
await db
|
|
34
40
|
.insert(schema.spaceTable)
|
|
35
|
-
.values({
|
|
41
|
+
.values({
|
|
42
|
+
id: nanoid(12),
|
|
43
|
+
spaceId,
|
|
44
|
+
tenantId: wizard.tenantId,
|
|
45
|
+
wizardId,
|
|
46
|
+
list: def.id,
|
|
47
|
+
...shape,
|
|
48
|
+
})
|
|
36
49
|
.onConflictDoNothing();
|
|
37
50
|
const made = await db.query.spaceTable.findFirst({ where });
|
|
38
51
|
if (!made) {
|
|
@@ -49,8 +62,8 @@ async function touch(tableId) {
|
|
|
49
62
|
function toRow(r) {
|
|
50
63
|
return { id: r.id, cells: r.cells, updatedAt: r.updatedAt.toISOString() };
|
|
51
64
|
}
|
|
52
|
-
export async function sharedRows(
|
|
53
|
-
const table = await sharedTable(
|
|
65
|
+
export async function sharedRows(scope, def, who) {
|
|
66
|
+
const table = await sharedTable(scope, def);
|
|
54
67
|
await assertRwx(table.spaceId, who, { kind: "table", id: table.id }, "r");
|
|
55
68
|
const rows = await db.query.spaceTableRow.findMany({
|
|
56
69
|
where: eq(schema.spaceTableRow.tableId, table.id),
|
|
@@ -59,8 +72,8 @@ export async function sharedRows(wizardId, def, who) {
|
|
|
59
72
|
return rows.map(toRow);
|
|
60
73
|
}
|
|
61
74
|
/** As `saveRows` does for one person's list: a row with a known key updates that row. */
|
|
62
|
-
export async function saveSharedRows(
|
|
63
|
-
const table = await sharedTable(
|
|
75
|
+
export async function saveSharedRows(scope, def, input) {
|
|
76
|
+
const table = await sharedTable(scope, def);
|
|
64
77
|
const existing = await db.query.spaceTableRow.findMany({
|
|
65
78
|
where: eq(schema.spaceTableRow.tableId, table.id),
|
|
66
79
|
});
|
|
@@ -103,11 +116,11 @@ export async function saveSharedRows(wizardId, def, input) {
|
|
|
103
116
|
return { added, updated };
|
|
104
117
|
}
|
|
105
118
|
/** Deletes rows by id, or by the value of the key column. */
|
|
106
|
-
export async function deleteSharedRows(
|
|
119
|
+
export async function deleteSharedRows(scope, def, idsOrKeys) {
|
|
107
120
|
if (!idsOrKeys.length) {
|
|
108
121
|
return 0;
|
|
109
122
|
}
|
|
110
|
-
const table = await sharedTable(
|
|
123
|
+
const table = await sharedTable(scope, def);
|
|
111
124
|
const keys = idsOrKeys.map((k) => k.trim().toLowerCase());
|
|
112
125
|
const inTable = eq(schema.spaceTableRow.tableId, table.id);
|
|
113
126
|
const byId = await db
|