@engenty/wizards-runtime 0.15.0 → 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 +138 -9
- package/apps/runtime/dist/agents/website.js +10 -5
- package/apps/runtime/dist/app.js +18 -0
- package/apps/runtime/dist/auth/index.js +5 -0
- package/apps/runtime/dist/broker/account.js +5 -0
- package/apps/runtime/dist/broker/index.js +5 -0
- package/apps/runtime/dist/broker/rwx.js +255 -7
- 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/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/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 +98 -0
- package/apps/runtime/dist/db/schema.js +294 -5
- package/apps/runtime/dist/docs/dev/api.md +25 -0
- 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 +5 -3
- package/apps/runtime/dist/elements/gate.js +1 -1
- package/apps/runtime/dist/elements/knowledge.js +181 -12
- package/apps/runtime/dist/elements/specs.js +1 -1
- package/apps/runtime/dist/elements/wizards.js +15 -2
- 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 +6 -0
- 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/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/goose.md +13 -1
- package/apps/runtime/dist/prompts/tools.md +5 -2
- package/apps/runtime/dist/render/convert.js +188 -1
- package/apps/runtime/dist/routes/api.js +6 -1
- 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 +2 -2
- 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 +29 -8
- package/apps/runtime/dist/services/work-chats.js +3 -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/pages.js +1 -1
- 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-Do7pwmFv.js → ChangelogDialog-CDN7kMs1.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-Cdox-51M.js → CodeEditor-D-Y16fdk.js} +1 -1
- package/apps/web/dist/assets/EditorPage-CrMVsgUt.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-BPS86xzA.js → FlowPreview-DXnk7m9P.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-BRHbi_Sd.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-PKHX8a8a.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-BoPaPsjN.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-7_FOHoEl.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 +3 -0
- package/node_modules/@engenty/wizards-shared/dist/run.js +6 -0
- package/node_modules/@engenty/wizards-shared/dist/rwx.d.ts +21 -4
- package/node_modules/@engenty/wizards-shared/dist/rwx.js +27 -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/plugin.json +1 -1
- package/apps/web/dist/assets/AboutDialog-DaWEIHFN.js +0 -1
- package/apps/web/dist/assets/CapabilitiesPage-Dt91U_sK.js +0 -2
- package/apps/web/dist/assets/EditorPage-DS_a5K3s.js +0 -3
- package/apps/web/dist/assets/Marketplace-CS7JTgiv.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-D-OLsex6.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-BM_pkk41.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-Cpn5pubC.js +0 -1
- package/apps/web/dist/assets/PreviewPane-BOk1-yO4.js +0 -9
- package/apps/web/dist/assets/PublicRunner-CgzMZb0r.js +0 -1
- package/apps/web/dist/assets/ReadOnly-8DEx-ly3.js +0 -1
- package/apps/web/dist/assets/SettingsPage-CcrknFcI.js +0 -2
- package/apps/web/dist/assets/SetupPage-D5nzjgPU.js +0 -1
- package/apps/web/dist/assets/SkillEditor-BsXTqNli.js +0 -1
- package/apps/web/dist/assets/Skills-C_X1ZsKg.js +0 -9
- package/apps/web/dist/assets/SpacePage-wZGqUoSQ.js +0 -2
- package/apps/web/dist/assets/UpdateCheck-D6x7MqEl.js +0 -2
- package/apps/web/dist/assets/changelog-M-eOBqgu.js +0 -1
- package/apps/web/dist/assets/circle-alert-DJbCyxcg.js +0 -1
- package/apps/web/dist/assets/circle-check-jqtsKi_b.js +0 -1
- package/apps/web/dist/assets/code-editor-BpCEnf8H.js +0 -2
- package/apps/web/dist/assets/code-xml-q88cSTV8.js +0 -1
- package/apps/web/dist/assets/connection-sign-in-UJ6xk-TD.js +0 -1
- package/apps/web/dist/assets/dist-EBVTpvRr.js +0 -10
- package/apps/web/dist/assets/eye-CgkvVlba.js +0 -1
- package/apps/web/dist/assets/host-Bd_bon_c.js +0 -118
- package/apps/web/dist/assets/i18n-0fUKyVRE.js +0 -55
- package/apps/web/dist/assets/index-D18DvnxX.css +0 -1
- package/apps/web/dist/assets/index-DOgwxnto.js +0 -10
- package/apps/web/dist/assets/oss-credits-IdX5bc71.js +0 -1
- package/apps/web/dist/assets/phone-CjPvZ0nk.js +0 -1
- package/apps/web/dist/assets/read-aloud-CLXo_asN.js +0 -1
- package/apps/web/dist/assets/scroll-text-2BhJO_W7.js +0 -1
- package/apps/web/dist/assets/session-CpYa5hwd.js +0 -2
- package/apps/web/dist/assets/theme-Bj3wNQR0.js +0 -11
- package/apps/web/dist/assets/ui-CktezodE.js +0 -82
- package/apps/web/dist/assets/upload-CHGCFVZK.js +0 -1
- package/apps/web/dist/assets/volume-2-Bw5KASy8.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) {
|
|
@@ -34,8 +34,10 @@ 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, knowledge) => [
|
|
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
|
|
41
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."
|
|
@@ -116,12 +118,30 @@ export const showView = () => createTool({
|
|
|
116
118
|
});
|
|
117
119
|
/** Whether the model can search the web itself: on Anthropic's API, or through the gateway. */
|
|
118
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
|
+
}
|
|
119
134
|
/**
|
|
120
135
|
* The space's tools for a turn: its knowledge, its skills, the chat's sandbox, the space's
|
|
121
136
|
* connections open to the person (work-connections.ts), the plugins' tools, the web; the plugins
|
|
122
|
-
* 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.
|
|
123
139
|
*/
|
|
124
|
-
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
|
+
}
|
|
125
145
|
const sandbox = sandboxTools(chatId);
|
|
126
146
|
const connections = await workConnectionTools({
|
|
127
147
|
space,
|
|
@@ -134,7 +154,7 @@ async function toolsFor(resolved, space, userId, signal, choice = {}, chatId = n
|
|
|
134
154
|
const caller = personCaller({
|
|
135
155
|
space,
|
|
136
156
|
userId,
|
|
137
|
-
role
|
|
157
|
+
role,
|
|
138
158
|
signal,
|
|
139
159
|
chatId: chatId ?? approved?.chatId ?? null,
|
|
140
160
|
sandbox: sandbox.skill,
|
|
@@ -234,17 +254,18 @@ export async function toolToRun(space, userId, name, signal, approved) {
|
|
|
234
254
|
*/
|
|
235
255
|
export async function workTurn(turn, signal, steps, choice = {}) {
|
|
236
256
|
const resolved = await chatModel(await chatTurnWay(managed), choice.extra ? "high" : "standard");
|
|
237
|
-
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);
|
|
238
259
|
const tools = resolved.model instanceof HarnessModel ? steps.wrap(made) : made;
|
|
239
260
|
attachTools(resolved, tools);
|
|
240
|
-
const skills = await spaceSkills(turn.space.id);
|
|
261
|
+
const skills = client ? null : await spaceSkills(turn.space.id);
|
|
241
262
|
const block = skills
|
|
242
263
|
? skillsBlock(skills, { tools: true, sandbox: sandboxCapabilities() !== null })
|
|
243
264
|
: "";
|
|
244
265
|
return {
|
|
245
266
|
resolved,
|
|
246
267
|
tools,
|
|
247
|
-
instructions: instructionsFor(turn.space.name, block, "space_search" in tools),
|
|
268
|
+
instructions: instructionsFor(turn.space.name, block, "space_search" in tools, client),
|
|
248
269
|
};
|
|
249
270
|
}
|
|
250
271
|
export function lazyTurn(turn, choice = {}) {
|
|
@@ -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);
|
|
@@ -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
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { validateWizard } from "@engenty/wizards-shared/definition";
|
|
2
2
|
import { tableColumnsSchema } from "@engenty/wizards-shared/engenty/data-tables";
|
|
3
3
|
import { SKILL_MODES, SKILL_SOURCES, } from "@engenty/wizards-shared/skills";
|
|
4
|
+
import { SPACE_FILE_KINDS } from "@engenty/wizards-shared/spaces";
|
|
4
5
|
import { themeSchema } from "@engenty/wizards-shared/theme";
|
|
5
6
|
import { and, asc, eq, inArray, isNull, ne, sql } from "drizzle-orm";
|
|
6
7
|
import { nanoid } from "nanoid";
|
|
7
8
|
import { z } from "zod";
|
|
8
9
|
import { db, schema } from "../db/client.js";
|
|
9
|
-
import {
|
|
10
|
-
import { objects } from "../files/objects.js";
|
|
11
|
-
import { extFor } from "../files/storage.js";
|
|
10
|
+
import { blobThumb, hasBlob, releaseBlob } from "../files/blobs.js";
|
|
12
11
|
import { spaceChanged } from "../plugins/events.js";
|
|
13
12
|
import { asSync } from "../services/access.js";
|
|
14
13
|
import { emitDraftChanged } from "../services/draft-events.js";
|
|
@@ -452,6 +451,8 @@ const table = {
|
|
|
452
451
|
spaceId: t.spaceId,
|
|
453
452
|
title: t.title,
|
|
454
453
|
slug: t.slug,
|
|
454
|
+
parentId: t.parentId,
|
|
455
|
+
position: t.position,
|
|
455
456
|
format: t.format,
|
|
456
457
|
columns: t.columns,
|
|
457
458
|
origin: t.origin,
|
|
@@ -470,6 +471,8 @@ const table = {
|
|
|
470
471
|
spaceId,
|
|
471
472
|
title: str(r.title) ?? "",
|
|
472
473
|
slug: str(r.slug),
|
|
474
|
+
parentId: str(r.parentId),
|
|
475
|
+
position: num(r.position) ?? 0,
|
|
473
476
|
format: (r.format === "faq" ? "faq" : null),
|
|
474
477
|
columns: tableColumnsSchema.parse(r.columns ?? []),
|
|
475
478
|
origin: str(r.origin),
|
|
@@ -720,7 +723,6 @@ const category = {
|
|
|
720
723
|
},
|
|
721
724
|
title: (r, item) => str(r?.name) ?? item,
|
|
722
725
|
};
|
|
723
|
-
const assetKey = (path) => `assets/${path}`;
|
|
724
726
|
const file = {
|
|
725
727
|
async read(id) {
|
|
726
728
|
const f = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, id) });
|
|
@@ -737,9 +739,7 @@ const file = {
|
|
|
737
739
|
if (f.status !== "ready") {
|
|
738
740
|
return "skip";
|
|
739
741
|
}
|
|
740
|
-
|
|
741
|
-
const bytes = asset ? await objects.get(assetKey(asset.path)) : null;
|
|
742
|
-
if (!bytes) {
|
|
742
|
+
if (!f.hash || !(await hasBlob(f.hash))) {
|
|
743
743
|
return "skip";
|
|
744
744
|
}
|
|
745
745
|
return {
|
|
@@ -753,13 +753,14 @@ const file = {
|
|
|
753
753
|
description: f.description,
|
|
754
754
|
source: f.source,
|
|
755
755
|
position: f.position,
|
|
756
|
+
parentId: f.parentId,
|
|
756
757
|
textHash: f.textHash,
|
|
757
758
|
pages: f.pages,
|
|
758
759
|
chars: f.chars,
|
|
759
760
|
origin: f.origin,
|
|
760
761
|
originKey: f.originKey,
|
|
761
762
|
originLabel: f.originLabel,
|
|
762
|
-
content:
|
|
763
|
+
content: f.hash,
|
|
763
764
|
categories: await categoriesOf("fileId", id),
|
|
764
765
|
},
|
|
765
766
|
};
|
|
@@ -768,31 +769,24 @@ const file = {
|
|
|
768
769
|
await clearOrigin(schema.spaceFile, spaceId, id, r);
|
|
769
770
|
const mime = str(r.mime) ?? "application/octet-stream";
|
|
770
771
|
const name = str(r.name) ?? "file";
|
|
771
|
-
const kind = (
|
|
772
|
-
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
mime,
|
|
779
|
-
name,
|
|
780
|
-
path,
|
|
781
|
-
size: bytes.byteLength,
|
|
782
|
-
};
|
|
783
|
-
await db
|
|
784
|
-
.insert(schema.asset)
|
|
785
|
-
.values({ id, tenantId: currentTenant(), ...assetValues })
|
|
786
|
-
.onConflictDoUpdate({ target: schema.asset.id, set: assetValues });
|
|
772
|
+
const kind = (SPACE_FILE_KINDS.includes(r.kind) ? r.kind : "asset");
|
|
773
|
+
// The bytes came ahead of the record, by their hash (client.ts, hub.ts).
|
|
774
|
+
const hash = String(r.content);
|
|
775
|
+
if (!(await hasBlob(hash))) {
|
|
776
|
+
throw new Error("blob missing");
|
|
777
|
+
}
|
|
778
|
+
const before = await db.query.spaceFile.findFirst({ where: eq(schema.spaceFile.id, id) });
|
|
787
779
|
const values = {
|
|
788
780
|
spaceId,
|
|
789
781
|
kind,
|
|
790
782
|
name,
|
|
791
783
|
mime,
|
|
792
|
-
size:
|
|
784
|
+
size: num(r.size) ?? 0,
|
|
785
|
+
hash,
|
|
793
786
|
description: str(r.description) ?? "",
|
|
794
787
|
source: str(r.source),
|
|
795
788
|
position: num(r.position) ?? 0,
|
|
789
|
+
parentId: str(r.parentId),
|
|
796
790
|
status: "ready",
|
|
797
791
|
error: null,
|
|
798
792
|
textHash: str(r.textHash),
|
|
@@ -811,8 +805,9 @@ const file = {
|
|
|
811
805
|
});
|
|
812
806
|
await writeCategories(spaceId, "fileId", id, r.categories);
|
|
813
807
|
return async () => {
|
|
814
|
-
if (before
|
|
815
|
-
await
|
|
808
|
+
if (before?.hash !== hash) {
|
|
809
|
+
await releaseBlob(before?.hash);
|
|
810
|
+
void blobThumb(hash, mime).catch(() => null);
|
|
816
811
|
}
|
|
817
812
|
if (kind === "logo") {
|
|
818
813
|
await putLink(id, "logo", id);
|
|
@@ -61,6 +61,7 @@ const EN = {
|
|
|
61
61
|
doingLookAtFile: "Looking at a file…",
|
|
62
62
|
doingReadSkill: "Reading the skill {name}…",
|
|
63
63
|
doingDescribeFile: "Describing a file…",
|
|
64
|
+
doingWriteKnowledgePage: "Writing a page into Knowledge…",
|
|
64
65
|
doingWebSearch: "Searching the web…",
|
|
65
66
|
doingReadSite: "Reading {host}…",
|
|
66
67
|
doingReadWebsite: "Reading the website…",
|
|
@@ -97,6 +98,7 @@ const EN = {
|
|
|
97
98
|
invalidInput: "Invalid input",
|
|
98
99
|
internalError: "Internal error",
|
|
99
100
|
notSignedIn: "You’re not signed in.",
|
|
101
|
+
clientsNotHere: "This is for the team. Your client space is open to you in the client view.",
|
|
100
102
|
accountSuspended: "This account is suspended.",
|
|
101
103
|
tooLarge: "That is too large.",
|
|
102
104
|
tooManyStreams: "Too many studio windows are open. Close one, or reload in a moment.",
|
|
@@ -289,6 +291,7 @@ const DE = {
|
|
|
289
291
|
doingLookAtFile: "Sieht sich eine Datei an …",
|
|
290
292
|
doingReadSkill: "Liest den Skill {name} …",
|
|
291
293
|
doingDescribeFile: "Beschreibt eine Datei …",
|
|
294
|
+
doingWriteKnowledgePage: "Schreibt eine Seite ins Wissen …",
|
|
292
295
|
doingWebSearch: "Sucht im Web …",
|
|
293
296
|
doingReadSite: "Liest {host} …",
|
|
294
297
|
doingReadWebsite: "Liest die Website …",
|
|
@@ -326,6 +329,7 @@ const DE = {
|
|
|
326
329
|
internalError: "Interner Fehler",
|
|
327
330
|
schemaMismatch: "Der Wizard passt nicht zum Schema.",
|
|
328
331
|
notSignedIn: "Du bist nicht angemeldet.",
|
|
332
|
+
clientsNotHere: "Das ist für das Team. Dein Space ist für dich in der Ansicht für Kund:innen offen.",
|
|
329
333
|
accountSuspended: "Dieses Konto ist gesperrt.",
|
|
330
334
|
tooLarge: "Das ist zu groß.",
|
|
331
335
|
tooManyStreams: "Zu viele Fenster des Studios sind offen. Schließ eines, oder lade gleich neu.",
|
|
@@ -12,7 +12,7 @@ import { pageReadInput, readKnowledgePage } from "./space.js";
|
|
|
12
12
|
* writes into a copy of its own in the run's state, which goes with the run.
|
|
13
13
|
*/
|
|
14
14
|
export function pageTools(ctx) {
|
|
15
|
-
const spaceId = ctx.
|
|
15
|
+
const spaceId = ctx.dataSpace.id;
|
|
16
16
|
const wizardId = ctx.store.wizardId;
|
|
17
17
|
/**
|
|
18
18
|
* The wizard's pages as this run sees them: those its holder may read, a test run's own
|
|
@@ -8,11 +8,12 @@ import { snapshotDataImages } from "../files/web-images.js";
|
|
|
8
8
|
import { markMedia } from "../media/marking.js";
|
|
9
9
|
import { mainLogoId } from "../services/brand.js";
|
|
10
10
|
import { snapshotFile } from "../services/files.js";
|
|
11
|
+
import { spaceFileContent } from "../services/space-files.js";
|
|
11
12
|
import { bundleWidget } from "./bundle.js";
|
|
12
13
|
import { MOTION_MEDIA_ORIGIN, probeWidget, renderMotion } from "./render.js";
|
|
13
14
|
export async function widgetBrand(space) {
|
|
14
15
|
const logoId = await mainLogoId(space.id);
|
|
15
|
-
const logo = logoId ? await
|
|
16
|
+
const logo = logoId ? await spaceFileContent(space.id, logoId).catch(() => null) : null;
|
|
16
17
|
const colors = space.brand.colors ?? [];
|
|
17
18
|
return {
|
|
18
19
|
name: space.brand.name ?? "",
|