@engenty/wizards-runtime 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/agents/architect.js +4 -4
- package/apps/runtime/dist/agents/studio-assistant.js +2 -31
- package/apps/runtime/dist/app.js +4 -4
- package/apps/runtime/dist/assistant/knows.js +2 -2
- package/apps/runtime/dist/auth/index.js +1 -1
- package/apps/runtime/dist/authoring/example.js +1 -1
- package/apps/runtime/dist/authoring/guide.js +35 -6
- package/apps/runtime/dist/broker/account.js +85 -16
- package/apps/runtime/dist/broker/call.js +137 -37
- package/apps/runtime/dist/broker/log.js +19 -5
- package/apps/runtime/dist/broker/rwx.js +12 -9
- package/apps/runtime/dist/connectors/index.js +52 -11
- package/apps/runtime/dist/connectors/person-connections.js +279 -0
- package/apps/runtime/dist/connectors/person-sign-ins.js +74 -3
- package/apps/runtime/dist/connectors/same-service.js +14 -0
- package/apps/runtime/dist/connectors/space-choice.js +116 -0
- package/apps/runtime/dist/connectors/space-connections.js +40 -2
- package/apps/runtime/dist/db/client.js +8 -0
- package/apps/runtime/dist/db/kept-accounts.js +88 -0
- package/apps/runtime/dist/db/migrations/tenant/0075_person_connection.sql +25 -0
- package/apps/runtime/dist/db/migrations/tenant/0076_clients_in_spaces.sql +28 -0
- package/apps/runtime/dist/db/migrations/tenant/0077_client_spaces_at_root.sql +21 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0075_snapshot.json +7859 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0076_snapshot.json +7859 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0077_snapshot.json +7859 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +21 -0
- package/apps/runtime/dist/db/schema.js +67 -16
- package/apps/runtime/dist/docs/dev/api.md +8 -8
- package/apps/runtime/dist/docs/dev/wizard-format/index.md +3 -1
- package/apps/runtime/dist/elements/caller.js +1 -1
- package/apps/runtime/dist/elements/knowledge.js +5 -5
- package/apps/runtime/dist/elements/wizards.js +7 -11
- package/apps/runtime/dist/engine/notices.js +13 -1
- package/apps/runtime/dist/engine/requirements.js +116 -3
- package/apps/runtime/dist/engine/run-needs.js +58 -0
- package/apps/runtime/dist/engine/runner.js +229 -23
- package/apps/runtime/dist/engine/starts.js +9 -0
- package/apps/runtime/dist/engine/types.js +5 -1
- package/apps/runtime/dist/harness/claude.js +3 -1
- package/apps/runtime/dist/manage.js +1 -1
- package/apps/runtime/dist/mcp/tools.js +3 -3
- package/apps/runtime/dist/plugins/runs.js +2 -1
- package/apps/runtime/dist/prompts/architect.md +3 -3
- package/apps/runtime/dist/prompts/authoring.md +17 -6
- package/apps/runtime/dist/prompts/goose.md +0 -5
- package/apps/runtime/dist/routes/api.js +9 -4
- package/apps/runtime/dist/routes/client-contract.js +2 -2
- package/apps/runtime/dist/routes/client-spaces.js +1 -16
- package/apps/runtime/dist/routes/connections.js +6 -1
- package/apps/runtime/dist/routes/marketplace.js +27 -7
- package/apps/runtime/dist/routes/plugins.js +1 -1
- package/apps/runtime/dist/routes/runs.js +157 -11
- package/apps/runtime/dist/routes/studio.js +42 -5
- package/apps/runtime/dist/services/client-portal.js +58 -49
- package/apps/runtime/dist/services/client-spaces.js +57 -125
- package/apps/runtime/dist/services/links.js +3 -3
- package/apps/runtime/dist/services/marketplace.js +6 -2
- package/apps/runtime/dist/services/members-studio.js +1 -1
- package/apps/runtime/dist/services/query-vectors.js +1 -1
- package/apps/runtime/dist/services/runs.js +19 -20
- package/apps/runtime/dist/services/space-parent.js +4 -11
- package/apps/runtime/dist/services/spaces.js +56 -47
- package/apps/runtime/dist/services/work-ai.js +3 -3
- package/apps/runtime/dist/services/work-chats.js +14 -6
- package/apps/runtime/dist/sharing/state.js +7 -3
- package/apps/runtime/dist/store/index.js +28 -8
- package/apps/runtime/dist/store/shared-lists.js +2 -2
- package/apps/runtime/dist/sync/hub.js +9 -5
- package/apps/runtime/dist/tools/connector.js +4 -2
- package/apps/web/dist/assets/{AboutDialog-BxT7chz8.js → AboutDialog-QWzpEK8M.js} +1 -1
- package/apps/web/dist/assets/{BlockEditor-BX8ZxxIc.js → BlockEditor-C44bI_ih.js} +1 -1
- package/apps/web/dist/assets/{Bundle-Dkpi5E6W.js → Bundle-DZyQ1FP7.js} +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-DAr0-gN1.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-j-vHLy-V.js → ChangelogDialog-CdHqJV2P.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-CfM2A-yS.js → CodeEditor-BRufUwu0.js} +1 -1
- package/apps/web/dist/assets/ConnectorsSection-BO6jHrYU.js +1 -0
- package/apps/web/dist/assets/EditorPage-Bx-fKnsY.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-E0kuvM5n.js → FlowPreview-aj58c-gH.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-DhQmCtyY.js → LangSwitch-BNkytlus.js} +1 -1
- package/apps/web/dist/assets/Marketplace-D3hdvrkz.js +2 -0
- package/apps/web/dist/assets/NewWizardChannels-fveQcQlY.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-BTX1g2t1.js +7 -0
- package/apps/web/dist/assets/OnboardingPage-DwF6KdQy.js +1 -0
- package/apps/web/dist/assets/ProtocolSection-YnJcMN9E.js +1 -0
- package/apps/web/dist/assets/PublicRunner-Bp4DxTrD.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-CkToYpY5.js → ReadOnly-C6qmTD35.js} +1 -1
- package/apps/web/dist/assets/{Results-C9qxCpUQ.js → Results-BNuuBiwU.js} +1 -1
- package/apps/web/dist/assets/{RunDrawer-BRXH71U8.js → RunDrawer-CMgN-XTB.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-CuUB26YJ.js +2 -0
- package/apps/web/dist/assets/SetupPage-llGzMVeH.js +1 -0
- package/apps/web/dist/assets/{SharePage-Boj1R928.js → SharePage-CgQp_PT6.js} +1 -1
- package/apps/web/dist/assets/SkillEditor-ARx8QPGp.js +1 -0
- package/apps/web/dist/assets/Skills-frfXXEcF.js +9 -0
- package/apps/web/dist/assets/SpacePage-Dv6ocsc_.js +2 -0
- package/apps/web/dist/assets/StudioHome-B0bZRm1L.js +1 -0
- package/apps/web/dist/assets/TableEditor-CfzTLmJF.js +7 -0
- package/apps/web/dist/assets/{UpdateCheck-DFor0F9T.js → UpdateCheck-D3QhfI5c.js} +2 -2
- package/apps/web/dist/assets/{brand-Ij-I_Lms.js → brand-DKuVyYhH.js} +1 -1
- package/apps/web/dist/assets/changelog-Db3nvWao.js +1 -0
- package/apps/web/dist/assets/{code-editor-BVgSljQq.js → code-editor-BLwDuQLI.js} +2 -2
- package/apps/web/dist/assets/host-C-AAp8Bz.js +69 -0
- package/apps/web/dist/assets/i18n-Dyi0kvaA.js +55 -0
- package/apps/web/dist/assets/index-CduFlFCp.css +1 -0
- package/apps/web/dist/assets/index-CtE0rJEL.js +102 -0
- package/apps/web/dist/assets/{read-aloud-pd-PWi_5.js → read-aloud-DGS8mWgC.js} +1 -1
- package/apps/web/dist/assets/session-EIDP3Wzc.js +1 -0
- package/apps/web/dist/assets/theme-B46aPLtX.js +14 -0
- package/apps/web/dist/assets/ui-DSgksc1H.js +16 -0
- package/apps/web/dist/assets/{useMutation-CUZC19i3.js → useMutation-fT44ij_b.js} +1 -1
- package/apps/web/dist/assets/{viewers-D-8HZrcq.js → viewers-DvA5VsXw.js} +2 -2
- package/apps/web/dist/index.html +18 -13
- package/apps/web/dist/mcp/flow.html +62 -62
- package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -2
- package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +67 -0
- package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10324 -7
- package/node_modules/@engenty/wizards-shared/dist/definition.js +32 -6
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +17 -23
- package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +17 -23
- package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
- package/node_modules/@engenty/wizards-shared/dist/marketplace-search.js +7 -1
- package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +9 -2
- package/node_modules/@engenty/wizards-shared/dist/page-data.d.ts +72 -0
- package/node_modules/@engenty/wizards-shared/dist/page-data.js +5 -0
- package/node_modules/@engenty/wizards-shared/dist/page-look.d.ts +17 -0
- package/node_modules/@engenty/wizards-shared/dist/page-look.js +118 -0
- package/node_modules/@engenty/wizards-shared/dist/page-styles.d.ts +6 -0
- package/node_modules/@engenty/wizards-shared/dist/page-styles.js +98 -0
- package/node_modules/@engenty/wizards-shared/dist/page-texts.d.ts +36 -0
- package/node_modules/@engenty/wizards-shared/dist/page-texts.js +119 -0
- package/node_modules/@engenty/wizards-shared/dist/requires.js +2 -0
- package/node_modules/@engenty/wizards-shared/dist/run.d.ts +56 -1
- package/node_modules/@engenty/wizards-shared/dist/run.js +25 -0
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +27 -1
- package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +26 -0
- package/node_modules/@engenty/wizards-shared/dist/store.d.ts +24 -1
- package/node_modules/@engenty/wizards-shared/dist/transition.d.ts +2 -1
- package/node_modules/@engenty/wizards-shared/dist/transition.js +10 -2
- package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +1 -1
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/plugin.json +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-CfSb23wy.js +0 -2
- package/apps/web/dist/assets/ConnectorsSection-fRBZYfZu.js +0 -1
- package/apps/web/dist/assets/EditorPage-CrFyN_Qn.js +0 -3
- package/apps/web/dist/assets/Marketplace-BdkNOARm.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-BATgI9GR.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-B5V5ScKh.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-DWpDqlCi.js +0 -1
- package/apps/web/dist/assets/PreviewPane-Br2w92Wh.js +0 -7
- package/apps/web/dist/assets/ProtocolSection-DMCojdZu.js +0 -1
- package/apps/web/dist/assets/PublicRunner-Cjhfeqi3.js +0 -1
- package/apps/web/dist/assets/SettingsPage-Dobd7tAA.js +0 -2
- package/apps/web/dist/assets/SetupPage-BkMjwBlV.js +0 -1
- package/apps/web/dist/assets/SkillEditor-DtVRUYqS.js +0 -1
- package/apps/web/dist/assets/Skills-DK1Pv-Xh.js +0 -9
- package/apps/web/dist/assets/SpacePage-CjgBRkkw.js +0 -2
- package/apps/web/dist/assets/StudioHome-B5HcJJ4Q.js +0 -1
- package/apps/web/dist/assets/changelog-n9RARUzp.js +0 -1
- package/apps/web/dist/assets/host-BELYIPMT.js +0 -69
- package/apps/web/dist/assets/i18n-DPqdH1PJ.js +0 -55
- package/apps/web/dist/assets/index-CVZlO0z3.css +0 -1
- package/apps/web/dist/assets/index-wJZVaKLg.js +0 -10
- package/apps/web/dist/assets/runners-D9DHhaD9.js +0 -1
- package/apps/web/dist/assets/session-Mt-n8MI0.js +0 -1
- package/apps/web/dist/assets/theme-BQhQx_UL.js +0 -14
- package/apps/web/dist/assets/ui-D4qQLcbs.js +0 -16
|
@@ -15,14 +15,17 @@ import { claimClientInvites } from "./client-spaces.js";
|
|
|
15
15
|
import { notFound, ServiceError } from "./errors.js";
|
|
16
16
|
import { startRun } from "./runs.js";
|
|
17
17
|
import { spaceFileContent, spaceFiles } from "./space-files.js";
|
|
18
|
+
import { brandSpaceId } from "./space-parent.js";
|
|
18
19
|
import { listSpaces } from "./spaces.js";
|
|
19
20
|
import { listWizards } from "./wizards.js";
|
|
20
21
|
import { createChat, readChat, sendMessage } from "./work-chats.js";
|
|
21
22
|
const clientSubjects = (who) => subjectsOfPerson(who.id, "client");
|
|
22
|
-
/** The contract is there for clients of an organization with
|
|
23
|
+
/** The contract is there for clients of an organization with clients and the broker on. */
|
|
23
24
|
async function requirePortal(who) {
|
|
24
25
|
const features = await currentFeatures();
|
|
25
|
-
if (features.clientSpaces !== true ||
|
|
26
|
+
if (features.clientSpaces !== true ||
|
|
27
|
+
features.orgSpaces !== true ||
|
|
28
|
+
!featureOn(features, "broker")) {
|
|
26
29
|
throw notFound();
|
|
27
30
|
}
|
|
28
31
|
if (who.role !== "client") {
|
|
@@ -35,24 +38,24 @@ async function requirePortal(who) {
|
|
|
35
38
|
* client-portal.md, "Addresses"): both are not found, alike in answer and in time.
|
|
36
39
|
*/
|
|
37
40
|
const asClient = (who) => and(eq(schema.spaceMember.userId, who.id), eq(schema.spaceMember.role, "client"), eq(schema.space.tenantId, currentTenant()));
|
|
38
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* One of the client spaces the client is in, with the spaces whose wizards it runs: its own and
|
|
43
|
+
* the organization's root.
|
|
44
|
+
*/
|
|
39
45
|
async function clientSpace(who, spaceId) {
|
|
40
46
|
await requirePortal(who);
|
|
41
47
|
const [row] = await db
|
|
42
48
|
.select({ space: schema.space })
|
|
43
49
|
.from(schema.space)
|
|
44
50
|
.innerJoin(schema.spaceMember, eq(schema.spaceMember.spaceId, schema.space.id))
|
|
45
|
-
.where(and(eq(schema.space.id, spaceId), asClient(who)))
|
|
51
|
+
.where(and(eq(schema.space.id, spaceId), eq(schema.space.kind, "client"), asClient(who)))
|
|
46
52
|
.limit(1);
|
|
47
|
-
|
|
48
|
-
? await db.query.space.findFirst({ where: eq(schema.space.id, row.space.parentId) })
|
|
49
|
-
: undefined;
|
|
50
|
-
if (!(row && parent)) {
|
|
53
|
+
if (!row?.space.parentId) {
|
|
51
54
|
throw notFound();
|
|
52
55
|
}
|
|
53
|
-
return { space: row.space,
|
|
56
|
+
return { space: row.space, sources: [row.space.id, row.space.parentId] };
|
|
54
57
|
}
|
|
55
|
-
/** Whether the person is one of the
|
|
58
|
+
/** Whether the person is one of the space's clients. */
|
|
56
59
|
async function isClientOf(userId, spaceId) {
|
|
57
60
|
const row = await db.query.spaceMember.findFirst({
|
|
58
61
|
columns: { id: true },
|
|
@@ -61,8 +64,8 @@ async function isClientOf(userId, spaceId) {
|
|
|
61
64
|
return Boolean(row);
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
64
|
-
* Whether a client opens a run: one of their client space's, started by them or shared with them
|
|
65
|
-
*
|
|
67
|
+
* Whether a client opens a run: one of their client space's, started by them or shared with them by the
|
|
68
|
+
* firm. The run's own routes ask it too (routes/runs.ts).
|
|
66
69
|
*/
|
|
67
70
|
export async function clientMayOpen(userId, run) {
|
|
68
71
|
if (!run.clientSpaceId || !(run.userId === userId || run.clientSharedAt)) {
|
|
@@ -72,9 +75,9 @@ export async function clientMayOpen(userId, run) {
|
|
|
72
75
|
}
|
|
73
76
|
/** A logo's address on the runtime, for a page on another origin. */
|
|
74
77
|
const absolute = (path) => (path ? `${env.publicUrl}${path}` : null);
|
|
75
|
-
/** The
|
|
76
|
-
async function firmBrand(
|
|
77
|
-
const brand = await brandView(
|
|
78
|
+
/** The space's brand, its own or the organization's it takes: the client portal wears it. */
|
|
79
|
+
async function firmBrand(spaceId) {
|
|
80
|
+
const brand = await brandView(await brandSpaceId(spaceId));
|
|
78
81
|
return { ...brand, logoUrl: absolute(brand.logoUrl) };
|
|
79
82
|
}
|
|
80
83
|
// --- who and where ---------------------------------------------------------------------------
|
|
@@ -94,42 +97,40 @@ export async function clientMe(who) {
|
|
|
94
97
|
},
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
|
-
/** The
|
|
100
|
+
/** The spaces the client is in, each with the organization's name and the brand it wears. */
|
|
98
101
|
export async function clientSpaces(who) {
|
|
99
102
|
await requirePortal(who);
|
|
100
103
|
await claimClientInvites(who.id, who.email);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const spaces = (await listSpaces(who.id)).filter((s) => s.parentId);
|
|
104
|
-
const parents = spaces.length
|
|
105
|
-
? await db.query.space.findMany({
|
|
106
|
-
columns: { id: true, name: true },
|
|
107
|
-
where: inArray(schema.space.id, spaces.map((s) => s.parentId)),
|
|
108
|
-
})
|
|
109
|
-
: [];
|
|
104
|
+
const spaces = (await listSpaces(who.id)).filter((s) => s.kind === "client" && s.parentId);
|
|
105
|
+
const org = spaces.length ? await tenantInfo(who.tenantId).catch(() => null) : null;
|
|
110
106
|
return Promise.all(spaces.map(async (s) => ({
|
|
111
107
|
id: s.id,
|
|
112
108
|
name: s.name,
|
|
113
|
-
firm: {
|
|
114
|
-
name: parents.find((p) => p.id === s.parentId)?.name ?? "",
|
|
115
|
-
brand: await firmBrand(s.parentId),
|
|
116
|
-
},
|
|
109
|
+
firm: { name: org?.name ?? "", brand: await firmBrand(s.id) },
|
|
117
110
|
})));
|
|
118
111
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const readable = new Set(await readableIds(parent.id, clientSubjects(who), "wizard", ids));
|
|
112
|
+
/**
|
|
113
|
+
* The published wizards the firm opened to its clients, of the space and of the organization's
|
|
114
|
+
* root, each with the space whose rules decide it: read and run.
|
|
115
|
+
*/
|
|
116
|
+
async function openedWizards(who, sources) {
|
|
125
117
|
const open = [];
|
|
126
|
-
for (const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
for (const spaceId of sources) {
|
|
119
|
+
const published = (await listWizards(who.id, spaceId)).filter((w) => w.published);
|
|
120
|
+
const ids = published.map((w) => w.id);
|
|
121
|
+
const readable = new Set(await readableIds(spaceId, clientSubjects(who), "wizard", ids));
|
|
122
|
+
for (const wizard of published) {
|
|
123
|
+
if (readable.has(wizard.id) &&
|
|
124
|
+
(await decide(spaceId, clientSubjects(who), { kind: "wizard", id: wizard.id }, "x")).ok) {
|
|
125
|
+
open.push({ spaceId, wizard });
|
|
126
|
+
}
|
|
130
127
|
}
|
|
131
128
|
}
|
|
132
|
-
return open
|
|
129
|
+
return open;
|
|
130
|
+
}
|
|
131
|
+
/** The opened wizards as the contract lists them. */
|
|
132
|
+
async function openWizards(who, sources) {
|
|
133
|
+
return (await openedWizards(who, sources)).map(({ wizard: w }) => ({
|
|
133
134
|
id: w.id,
|
|
134
135
|
title: w.title,
|
|
135
136
|
description: w.description ?? "",
|
|
@@ -138,15 +139,23 @@ async function openWizards(who, parent) {
|
|
|
138
139
|
}));
|
|
139
140
|
}
|
|
140
141
|
export async function clientWizards(who, spaceId) {
|
|
141
|
-
const {
|
|
142
|
-
return openWizards(who,
|
|
142
|
+
const { sources } = await clientSpace(who, spaceId);
|
|
143
|
+
return openWizards(who, sources);
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
145
|
-
* Starts one of the opened wizards in the
|
|
146
|
-
*
|
|
146
|
+
* Starts one of the opened wizards in the space: the run is the space's, whichever space the
|
|
147
|
+
* wizard is in. A line of the audit like every element call.
|
|
147
148
|
*/
|
|
148
149
|
export async function clientStartWizard(who, spaceId, wizardId) {
|
|
149
|
-
const { space,
|
|
150
|
+
const { space, sources } = await clientSpace(who, spaceId);
|
|
151
|
+
const opened = (await openedWizards(who, sources)).find((o) => o.wizard.id === wizardId);
|
|
152
|
+
// A wizard not opened is refused by the rules of the space it is in, as one opened is decided.
|
|
153
|
+
const home = opened
|
|
154
|
+
? opened.spaceId
|
|
155
|
+
: ((await db.query.wizard.findFirst({
|
|
156
|
+
columns: { spaceId: true },
|
|
157
|
+
where: and(eq(schema.wizard.id, wizardId), eq(schema.wizard.tenantId, currentTenant())),
|
|
158
|
+
}))?.spaceId ?? space.id);
|
|
150
159
|
const caller = personCaller({
|
|
151
160
|
space: { id: space.id, name: space.name },
|
|
152
161
|
userId: who.id,
|
|
@@ -157,11 +166,11 @@ export async function clientStartWizard(who, spaceId, wizardId) {
|
|
|
157
166
|
return elementCall(caller, {
|
|
158
167
|
action: "wizard_start",
|
|
159
168
|
resource: { kind: "wizard", id: wizardId },
|
|
160
|
-
rulesIn:
|
|
169
|
+
rulesIn: sources.includes(home) ? home : space.id,
|
|
161
170
|
perm: "x",
|
|
162
171
|
input: { wizardId },
|
|
163
172
|
}, async () => {
|
|
164
|
-
if (!
|
|
173
|
+
if (!opened) {
|
|
165
174
|
throw notFound();
|
|
166
175
|
}
|
|
167
176
|
const { runId } = await startRun(who.id, wizardId, {}, { clientSpaceId: space.id });
|
|
@@ -232,7 +241,7 @@ export async function clientOpenRun(who, runId) {
|
|
|
232
241
|
* firm shared, the wizards they can start.
|
|
233
242
|
*/
|
|
234
243
|
export async function clientForYou(who, spaceId) {
|
|
235
|
-
const { space,
|
|
244
|
+
const { space, sources } = await clientSpace(who, spaceId);
|
|
236
245
|
const [waiting, shared, wizards] = await Promise.all([
|
|
237
246
|
db.query.run.findMany({
|
|
238
247
|
where: and(eq(schema.run.clientSpaceId, space.id), eq(schema.run.userId, who.id), or(eq(schema.run.status, "waiting_input"), and(eq(schema.run.status, "running"), isNotNull(schema.run.ask)))),
|
|
@@ -244,7 +253,7 @@ export async function clientForYou(who, spaceId) {
|
|
|
244
253
|
orderBy: [desc(schema.run.clientSharedAt)],
|
|
245
254
|
limit: 10,
|
|
246
255
|
}),
|
|
247
|
-
openWizards(who,
|
|
256
|
+
openWizards(who, sources),
|
|
248
257
|
]);
|
|
249
258
|
const titles = await titlesOf([...waiting, ...shared].map((r) => r.wizardId));
|
|
250
259
|
// What the firm's team is asked waits for them, not for the client.
|
|
@@ -1,126 +1,49 @@
|
|
|
1
1
|
import { note } from "@engenty/wizards-shared/run";
|
|
2
|
-
import { and,
|
|
2
|
+
import { and, eq, isNull } from "drizzle-orm";
|
|
3
3
|
import { nanoid } from "nanoid";
|
|
4
4
|
import { openToClients, seedClientRules } from "../broker/rwx.js";
|
|
5
5
|
import { db, schema } from "../db/client.js";
|
|
6
6
|
import { currentFeatures } from "../features.js";
|
|
7
7
|
import { inviteMember, managed } from "../manage.js";
|
|
8
|
-
import { spaceChanged } from "../plugins/events.js";
|
|
9
8
|
import { currentTenant } from "../tenants/tenant.js";
|
|
10
|
-
import { currentRole, requireAdmin
|
|
9
|
+
import { currentRole, requireAdmin } from "./access.js";
|
|
11
10
|
import { notFound, ServiceError } from "./errors.js";
|
|
12
|
-
import { ownedSpace
|
|
11
|
+
import { ownedSpace } from "./spaces.js";
|
|
13
12
|
/*
|
|
14
|
-
* Client spaces (docs/plans/
|
|
15
|
-
*
|
|
16
|
-
* client
|
|
13
|
+
* Client spaces and who is in a space (docs/plans/org-spaces.md): a client is a client space,
|
|
14
|
+
* beside the team spaces under the organization's root; its client's people are in it
|
|
15
|
+
* (`space_member`, role `client`) and see it alone. A team space takes no clients: who of the
|
|
16
|
+
* team is in it decides only where it is shared with its members only. Clients are behind the
|
|
17
|
+
* `clientSpaces` switch and need `orgSpaces`; a team space's members need `orgSpaces` alone.
|
|
17
18
|
*/
|
|
18
|
-
/**
|
|
19
|
+
/** Clients are behind their switch, and in the organization's spaces: else they are not there. */
|
|
19
20
|
export async function requireClientSpaces() {
|
|
20
|
-
|
|
21
|
+
const features = await currentFeatures();
|
|
22
|
+
if (features.clientSpaces !== true || features.orgSpaces !== true) {
|
|
21
23
|
throw notFound();
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Who is in a space is kept where there are client spaces, and with `orgSpaces`, where a space
|
|
26
|
-
* may be shared with its members only (docs/plans/org-spaces.md). Kund:innen need client spaces.
|
|
27
|
-
*/
|
|
26
|
+
/** Who is in a space is kept with `orgSpaces`; a client in it needs `clientSpaces` too. */
|
|
28
27
|
async function requireSpaceMembers(role) {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (role === "client") {
|
|
29
|
+
await requireClientSpaces();
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
/** A space of the firm that may hold client spaces: not a client space itself. */
|
|
36
|
-
async function firmSpace(userId, spaceId) {
|
|
37
|
-
const space = await ownedSpace(userId, spaceId);
|
|
38
|
-
if (space.kind !== "space" || currentRole() === "client") {
|
|
32
|
+
if ((await currentFeatures()).orgSpaces !== true) {
|
|
39
33
|
throw notFound();
|
|
40
34
|
}
|
|
41
|
-
return space;
|
|
42
35
|
}
|
|
43
36
|
/**
|
|
44
|
-
* A space
|
|
45
|
-
*
|
|
37
|
+
* A space with people of its own, under the organization's root: a team space or a client space,
|
|
38
|
+
* never the root or someone's Mein Space. `client`: only a client space.
|
|
46
39
|
*/
|
|
47
|
-
async function
|
|
40
|
+
async function sharedSpace(userId, spaceId, as) {
|
|
48
41
|
const space = await ownedSpace(userId, spaceId);
|
|
49
|
-
|
|
42
|
+
const fits = as === "client" ? space.kind === "client" : space.kind !== "personal";
|
|
43
|
+
if (currentRole() === "client" || !fits || !space.parentId) {
|
|
50
44
|
throw notFound();
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
return space;
|
|
54
|
-
}
|
|
55
|
-
if (space.kind === "space" && space.parentId && (await currentFeatures()).orgSpaces === true) {
|
|
56
|
-
return space;
|
|
57
|
-
}
|
|
58
|
-
throw notFound();
|
|
59
|
-
}
|
|
60
|
-
/** A space that is not a client space gets the clients' rules with its first client. */
|
|
61
|
-
async function openToItsClients(space) {
|
|
62
|
-
if (space.kind !== "client") {
|
|
63
|
-
await seedClientRules(space.id);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/** The client spaces of a space, with how many people are in each, newest first. */
|
|
67
|
-
export async function listClientSpaces(userId, spaceId) {
|
|
68
|
-
await requireClientSpaces();
|
|
69
|
-
const space = await firmSpace(userId, spaceId);
|
|
70
|
-
const rows = await db.query.space.findMany({
|
|
71
|
-
where: and(eq(schema.space.parentId, space.id), eq(schema.space.tenantId, currentTenant())),
|
|
72
|
-
orderBy: (s, { desc }) => [desc(s.createdAt)],
|
|
73
|
-
});
|
|
74
|
-
const counts = rows.length
|
|
75
|
-
? await db
|
|
76
|
-
.select({ spaceId: schema.spaceMember.spaceId, role: schema.spaceMember.role, n: count() })
|
|
77
|
-
.from(schema.spaceMember)
|
|
78
|
-
.where(inArray(schema.spaceMember.spaceId, rows.map((r) => r.id)))
|
|
79
|
-
.groupBy(schema.spaceMember.spaceId, schema.spaceMember.role)
|
|
80
|
-
: [];
|
|
81
|
-
const people = (id, role) => counts.find((c) => c.spaceId === id && c.role === role)?.n ?? 0;
|
|
82
|
-
return rows.map((r) => ({
|
|
83
|
-
id: r.id,
|
|
84
|
-
name: r.name,
|
|
85
|
-
createdAt: r.createdAt.toISOString(),
|
|
86
|
-
clients: people(r.id, "client"),
|
|
87
|
-
members: people(r.id, "member"),
|
|
88
|
-
}));
|
|
89
|
-
}
|
|
90
|
-
/** A new client space under a space of the firm. Its admins make them. */
|
|
91
|
-
export async function createClientSpace(userId, spaceId, name) {
|
|
92
|
-
await requireClientSpaces();
|
|
93
|
-
await requireBuild();
|
|
94
|
-
await requireAdmin();
|
|
95
|
-
const space = await firmSpace(userId, spaceId);
|
|
96
|
-
const trimmed = name.trim();
|
|
97
|
-
if (!trimmed) {
|
|
98
|
-
throw new ServiceError("invalid", "A client space needs a name.");
|
|
99
|
-
}
|
|
100
|
-
const id = nanoid(12);
|
|
101
|
-
await db.insert(schema.space).values({
|
|
102
|
-
id,
|
|
103
|
-
tenantId: currentTenant(),
|
|
104
|
-
name: trimmed,
|
|
105
|
-
brand: {},
|
|
106
|
-
kind: "client",
|
|
107
|
-
parentId: space.id,
|
|
108
|
-
});
|
|
109
|
-
spaceChanged("space.created", id);
|
|
110
|
-
return { id };
|
|
111
|
-
}
|
|
112
|
-
/** Renames a client space. Its admins do. */
|
|
113
|
-
export async function renameClientSpace(userId, spaceId, name) {
|
|
114
|
-
await requireClientSpaces();
|
|
115
|
-
await requireAdmin();
|
|
116
|
-
const space = await clientSpace(userId, spaceId);
|
|
117
|
-
const trimmed = name.trim() || space.name;
|
|
118
|
-
await db
|
|
119
|
-
.update(schema.space)
|
|
120
|
-
.set({ name: trimmed, updatedAt: new Date() })
|
|
121
|
-
.where(eq(schema.space.id, space.id));
|
|
122
|
-
spaceChanged("space.updated", space.id);
|
|
123
|
-
return { name: trimmed };
|
|
46
|
+
return space;
|
|
124
47
|
}
|
|
125
48
|
/**
|
|
126
49
|
* Shares a run of a client space with its clients, on purpose, or takes it back
|
|
@@ -131,32 +54,37 @@ export async function shareWithClient(userId, runId, shared) {
|
|
|
131
54
|
if (currentRole() === "client") {
|
|
132
55
|
throw notFound();
|
|
133
56
|
}
|
|
134
|
-
const run = await db
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
57
|
+
const [run] = await db
|
|
58
|
+
.select({
|
|
59
|
+
id: schema.run.id,
|
|
60
|
+
clientSpaceId: schema.run.clientSpaceId,
|
|
61
|
+
status: schema.run.status,
|
|
62
|
+
wizardSpaceId: schema.wizard.spaceId,
|
|
63
|
+
})
|
|
64
|
+
.from(schema.run)
|
|
65
|
+
.innerJoin(schema.wizard, eq(schema.wizard.id, schema.run.wizardId))
|
|
66
|
+
.where(and(eq(schema.run.id, runId), eq(schema.run.tenantId, currentTenant())))
|
|
67
|
+
.limit(1);
|
|
68
|
+
if (!run) {
|
|
139
69
|
throw notFound();
|
|
140
70
|
}
|
|
141
|
-
|
|
71
|
+
// The space the run is in: the one it carries, else its wizard's.
|
|
72
|
+
const space = await sharedSpace(userId, run.clientSpaceId ?? run.wizardSpaceId, "client");
|
|
142
73
|
if (shared && run.status !== "done") {
|
|
143
74
|
throw new ServiceError("refused", note("onlyFinishedResultsShared"));
|
|
144
75
|
}
|
|
145
76
|
const sharedAt = shared ? new Date() : null;
|
|
146
|
-
|
|
77
|
+
// Shared, it carries its space, where the clients look for it.
|
|
78
|
+
await db
|
|
79
|
+
.update(schema.run)
|
|
80
|
+
.set({ clientSharedAt: sharedAt, clientSpaceId: space.id })
|
|
81
|
+
.where(eq(schema.run.id, run.id));
|
|
147
82
|
return { sharedAt: sharedAt?.toISOString() ?? null };
|
|
148
83
|
}
|
|
149
|
-
/**
|
|
150
|
-
export async function deleteClientSpace(userId, spaceId) {
|
|
151
|
-
await requireClientSpaces();
|
|
152
|
-
await requireAdmin();
|
|
153
|
-
const space = await clientSpace(userId, spaceId);
|
|
154
|
-
await removeSpace(space.id);
|
|
155
|
-
}
|
|
156
|
-
/** Who is in a client space: the client's people and the firm's assigned members. */
|
|
84
|
+
/** Who is in a space: its clients and the people of the organization chosen for it. */
|
|
157
85
|
export async function listSpaceMembers(userId, spaceId) {
|
|
158
86
|
await requireSpaceMembers();
|
|
159
|
-
const space = await
|
|
87
|
+
const space = await sharedSpace(userId, spaceId);
|
|
160
88
|
const rows = await db.query.spaceMember.findMany({
|
|
161
89
|
where: eq(schema.spaceMember.spaceId, space.id),
|
|
162
90
|
orderBy: (m, { asc }) => [asc(m.createdAt)],
|
|
@@ -168,11 +96,11 @@ export async function listSpaceMembers(userId, spaceId) {
|
|
|
168
96
|
addedAt: m.createdAt.toISOString(),
|
|
169
97
|
}));
|
|
170
98
|
}
|
|
171
|
-
/** Puts a person of the organization into a client
|
|
99
|
+
/** Puts a person of the organization into a space: a client into a client space, a member into either. */
|
|
172
100
|
export async function addSpaceMember(userId, spaceId, member) {
|
|
173
101
|
await requireSpaceMembers(member.role);
|
|
174
102
|
await requireAdmin();
|
|
175
|
-
const space = await
|
|
103
|
+
const space = await sharedSpace(userId, spaceId, member.role === "client" ? "client" : undefined);
|
|
176
104
|
await db
|
|
177
105
|
.insert(schema.spaceMember)
|
|
178
106
|
.values({
|
|
@@ -188,14 +116,14 @@ export async function addSpaceMember(userId, spaceId, member) {
|
|
|
188
116
|
set: { role: member.role },
|
|
189
117
|
});
|
|
190
118
|
if (member.role === "client") {
|
|
191
|
-
await
|
|
119
|
+
await seedClientRules(space.id);
|
|
192
120
|
}
|
|
193
121
|
}
|
|
194
|
-
/** Takes a person out of a
|
|
122
|
+
/** Takes a person out of a space. */
|
|
195
123
|
export async function removeSpaceMember(userId, spaceId, memberId) {
|
|
196
124
|
await requireSpaceMembers();
|
|
197
125
|
await requireAdmin();
|
|
198
|
-
const space = await
|
|
126
|
+
const space = await sharedSpace(userId, spaceId);
|
|
199
127
|
await db
|
|
200
128
|
.delete(schema.spaceMember)
|
|
201
129
|
.where(and(eq(schema.spaceMember.spaceId, space.id), eq(schema.spaceMember.userId, memberId)));
|
|
@@ -203,18 +131,22 @@ export async function removeSpaceMember(userId, spaceId, memberId) {
|
|
|
203
131
|
/** What of a space its clients reach: the items of each kind opened to them. */
|
|
204
132
|
export async function clientOpenOf(userId, spaceId) {
|
|
205
133
|
await requireClientSpaces();
|
|
206
|
-
const space = await
|
|
134
|
+
const space = await ownedSpace(userId, spaceId);
|
|
135
|
+
if (currentRole() === "client") {
|
|
136
|
+
throw notFound();
|
|
137
|
+
}
|
|
207
138
|
return openToClients(space.id);
|
|
208
139
|
}
|
|
209
140
|
/**
|
|
210
|
-
* Invites a client into
|
|
211
|
-
* organization as a `client` (taking no seat), and the client space keeps
|
|
212
|
-
* sign in for the first time
|
|
141
|
+
* Invites one of a client's people into their client space by their address: the Manage-App
|
|
142
|
+
* invites them into the organization as a `client` (taking no seat), and the client space keeps
|
|
143
|
+
* the address until they sign in for the first time on the organization's page
|
|
144
|
+
* (`claimClientInvites`). Cloud only: a local install has no accounts.
|
|
213
145
|
*/
|
|
214
146
|
export async function inviteClient(userId, spaceId, input) {
|
|
215
147
|
await requireClientSpaces();
|
|
216
148
|
await requireAdmin();
|
|
217
|
-
const space = await
|
|
149
|
+
const space = await sharedSpace(userId, spaceId, "client");
|
|
218
150
|
if (!managed) {
|
|
219
151
|
throw new ServiceError("refused", note("clientsInCloud"));
|
|
220
152
|
}
|
|
@@ -229,7 +161,7 @@ export async function inviteClient(userId, spaceId, input) {
|
|
|
229
161
|
role: "client",
|
|
230
162
|
addedBy: userId,
|
|
231
163
|
});
|
|
232
|
-
await
|
|
164
|
+
await seedClientRules(space.id);
|
|
233
165
|
}
|
|
234
166
|
/**
|
|
235
167
|
* A person's first sign-in: the client spaces that invited their address take them in. Called
|
|
@@ -16,10 +16,10 @@ export async function forgetWizardLinks(wizardId) {
|
|
|
16
16
|
await dropRuns(runs.map((r) => r.id));
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Takes the runs
|
|
20
|
-
* wizards
|
|
19
|
+
* Takes the runs a space carries away with what they made: a client's, and those of the root's
|
|
20
|
+
* wizards started in it. They belong to it, though their wizards are elsewhere.
|
|
21
21
|
*/
|
|
22
|
-
export async function
|
|
22
|
+
export async function removeRunsIn(spaceId) {
|
|
23
23
|
const runs = await db
|
|
24
24
|
.select({ id: schema.run.id, shareToken: schema.run.shareToken })
|
|
25
25
|
.from(schema.run)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { statSync } from "node:fs";
|
|
3
|
-
import { DEFINITION_VERSION, readable, wizardSchema, } from "@engenty/wizards-shared/definition";
|
|
3
|
+
import { DEFINITION_VERSION, FORMAT_VERSIONS, formatVersionOf, readable, wizardSchema, } from "@engenty/wizards-shared/definition";
|
|
4
4
|
import { capabilitiesOf, costTierOf, effortOf, formatsOf, MARKETPLACE_LANGS, } from "@engenty/wizards-shared/marketplace";
|
|
5
5
|
import { wizardOutline } from "@engenty/wizards-shared/marketplace-entry";
|
|
6
6
|
import { searchEntries } from "@engenty/wizards-shared/marketplace-search";
|
|
@@ -160,6 +160,7 @@ function addFacets(a, b) {
|
|
|
160
160
|
format: add(a.format, b.format),
|
|
161
161
|
capability: add(a.capability, b.capability),
|
|
162
162
|
plan: add(a.plan, b.plan),
|
|
163
|
+
version: add(a.version, b.version),
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
166
|
/**
|
|
@@ -190,8 +191,11 @@ function asEntry(summary, starred, unavailable, optional = new Set()) {
|
|
|
190
191
|
const lacking = summary.capabilities.filter((c) => unavailable.has(c));
|
|
191
192
|
return {
|
|
192
193
|
...summary,
|
|
194
|
+
// A marketplace that still writes the version the earlier way is read as today's.
|
|
195
|
+
version: String(formatVersionOf(summary.version)),
|
|
193
196
|
credits: null,
|
|
194
|
-
|
|
197
|
+
// A format this app reads.
|
|
198
|
+
usable: FORMAT_VERSIONS.includes(formatVersionOf(summary.version)),
|
|
195
199
|
starred: starred.has(summary.id),
|
|
196
200
|
missing: lacking.filter((c) => !optional.has(c)),
|
|
197
201
|
optional: lacking.filter((c) => optional.has(c)),
|
|
@@ -80,7 +80,7 @@ export async function spaceOfItem(kind, id, sub) {
|
|
|
80
80
|
where: and(eq(schema.run.id, id), eq(schema.run.tenantId, tenant)),
|
|
81
81
|
columns: { wizardId: true, clientSpaceId: true },
|
|
82
82
|
});
|
|
83
|
-
// A run
|
|
83
|
+
// A run that carries a space is that space's, though its wizard is the root's.
|
|
84
84
|
if (run?.clientSpaceId) {
|
|
85
85
|
return run.clientSpaceId;
|
|
86
86
|
}
|
|
@@ -4,7 +4,7 @@ import { embeddingModel } from "../models.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* The vector of a search's query. The embedding model is the index's too: in an Ollama that is
|
|
6
6
|
* embedding a folder, a query's call waits behind every passage sent before it (36 s measured).
|
|
7
|
-
* So a query is embedded once (the palette asks twice, a client
|
|
7
|
+
* So a query is embedded once (the palette asks twice, a client's search once per space),
|
|
8
8
|
* the indexers send nothing new while one is on its way (`searchesFirst`), and a search waits
|
|
9
9
|
* only as long as it is given.
|
|
10
10
|
*/
|
|
@@ -450,9 +450,9 @@ export function refusedInput(err) {
|
|
|
450
450
|
}
|
|
451
451
|
/**
|
|
452
452
|
* Runs the published version of a wizard for the admin, from their own AI client: a live run
|
|
453
|
-
* that is theirs — no visitor, no share link needed. With answers the first page is filled.
|
|
454
|
-
*
|
|
455
|
-
* (docs/plans/
|
|
453
|
+
* that is theirs — no visitor, no share link needed. With answers the first page is filled. A run
|
|
454
|
+
* that carries a space (`clientSpaceId`) belongs to it, whichever space its wizard is in
|
|
455
|
+
* (docs/plans/org-spaces.md).
|
|
456
456
|
*/
|
|
457
457
|
export async function startRun(userId, wizardId, answers = {}, { clientSpaceId = null, chatId = null, } = {}) {
|
|
458
458
|
const w = await ownedWizard(userId, wizardId);
|
|
@@ -708,21 +708,20 @@ export async function runTimeline(run, canAct) {
|
|
|
708
708
|
* `filter`; and each wizard with how many it has and when its last one came, the latest first.
|
|
709
709
|
*/
|
|
710
710
|
export async function listResults(spaceId, filter = {}) {
|
|
711
|
-
// A
|
|
712
|
-
// (docs/plans/
|
|
713
|
-
//
|
|
711
|
+
// A space shows its own wizards' runs, a client's among them, and with `orgSpaces` the runs of
|
|
712
|
+
// the root's wizards started in it (docs/plans/org-spaces.md). A run in another space than its
|
|
713
|
+
// wizard's, or a client's, carries that space (`clientSpaceId`).
|
|
714
714
|
const reads = await readsOf(spaceId);
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
:
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
: isNull(schema.run.clientSpaceId);
|
|
715
|
+
const wizardSpaces = reads ? [spaceId, reads.parentId] : [spaceId];
|
|
716
|
+
// In a client space, each result says whether it is shared with its clients.
|
|
717
|
+
const client = await db.query.spaceMember.findFirst({
|
|
718
|
+
columns: { id: true },
|
|
719
|
+
where: and(eq(schema.spaceMember.spaceId, spaceId), eq(schema.spaceMember.role, "client")),
|
|
720
|
+
});
|
|
721
|
+
const here = or(isNull(schema.run.clientSpaceId), eq(schema.run.clientSpaceId, spaceId));
|
|
722
|
+
const inSpace = reads
|
|
723
|
+
? or(and(eq(schema.wizard.spaceId, spaceId), here), and(eq(schema.wizard.spaceId, reads.parentId), eq(schema.run.clientSpaceId, spaceId)))
|
|
724
|
+
: here;
|
|
726
725
|
const wizards = await db
|
|
727
726
|
.select({
|
|
728
727
|
id: schema.wizard.id,
|
|
@@ -745,9 +744,9 @@ export async function listResults(spaceId, filter = {}) {
|
|
|
745
744
|
const ids = wizards.map((w) => w.id).filter((id) => !filter.wizardId || id === filter.wizardId);
|
|
746
745
|
// The runs of this space, by the wizards listed: the root's only those started here.
|
|
747
746
|
const fromRoot = new Set(wizards.filter((w) => w.spaceId !== spaceId).map((w) => w.id));
|
|
748
|
-
const runsHere = reads
|
|
749
|
-
? or(and(inArray(schema.run.wizardId, ids.filter((id) => !fromRoot.has(id)).concat("")),
|
|
750
|
-
:
|
|
747
|
+
const runsHere = reads
|
|
748
|
+
? or(and(inArray(schema.run.wizardId, ids.filter((id) => !fromRoot.has(id)).concat("")), here), and(inArray(schema.run.wizardId, [...fromRoot].concat("")), eq(schema.run.clientSpaceId, spaceId)))
|
|
749
|
+
: here;
|
|
751
750
|
const rows = ids.length
|
|
752
751
|
? await db
|
|
753
752
|
.select({
|
|
@@ -3,19 +3,13 @@ import { db, schema } from "../db/client.js";
|
|
|
3
3
|
import { currentFeatures } from "../features.js";
|
|
4
4
|
export async function readsOf(spaceId) {
|
|
5
5
|
const space = await db.query.space.findFirst({
|
|
6
|
-
columns: {
|
|
6
|
+
columns: { parentId: true },
|
|
7
7
|
where: eq(schema.space.id, spaceId),
|
|
8
8
|
});
|
|
9
|
-
if (!space?.parentId) {
|
|
9
|
+
if (!space?.parentId || (await currentFeatures()).orgSpaces !== true) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
return { parentId: space.parentId, as: "client" };
|
|
14
|
-
}
|
|
15
|
-
if ((await currentFeatures()).orgSpaces === true) {
|
|
16
|
-
return { parentId: space.parentId, as: "root" };
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
12
|
+
return { parentId: space.parentId };
|
|
19
13
|
}
|
|
20
14
|
/**
|
|
21
15
|
* The space whose brand files (logos, patterns, brand assets) a space shows: the root's where the
|
|
@@ -23,12 +17,11 @@ export async function readsOf(spaceId) {
|
|
|
23
17
|
*/
|
|
24
18
|
export async function brandSpaceId(spaceId) {
|
|
25
19
|
const space = await db.query.space.findFirst({
|
|
26
|
-
columns: { brandFrom: true, parentId: true
|
|
20
|
+
columns: { brandFrom: true, parentId: true },
|
|
27
21
|
where: eq(schema.space.id, spaceId),
|
|
28
22
|
});
|
|
29
23
|
if (space?.brandFrom === "root" &&
|
|
30
24
|
space.parentId &&
|
|
31
|
-
space.kind !== "client" &&
|
|
32
25
|
(await currentFeatures()).orgSpaces === true) {
|
|
33
26
|
return space.parentId;
|
|
34
27
|
}
|