@engenty/wizards-runtime 0.19.1 → 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 +209 -16
- 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/authoring.md +13 -3
- 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/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-BUWu36Mb.js → AboutDialog-QWzpEK8M.js} +1 -1
- package/apps/web/dist/assets/{BlockEditor-1-EvUIta.js → BlockEditor-C44bI_ih.js} +1 -1
- package/apps/web/dist/assets/{Bundle-RNkjBwAL.js → Bundle-DZyQ1FP7.js} +1 -1
- package/apps/web/dist/assets/CapabilitiesPage-DAr0-gN1.js +2 -0
- package/apps/web/dist/assets/{ChangelogDialog-C_ZZLRZT.js → ChangelogDialog-CdHqJV2P.js} +1 -1
- package/apps/web/dist/assets/{CodeEditor-BEJKIMd0.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-ptI86Ogs.js → FlowPreview-aj58c-gH.js} +1 -1
- package/apps/web/dist/assets/{LangSwitch-BNa_H8AR.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-YF0RkR7P.js → ReadOnly-C6qmTD35.js} +1 -1
- package/apps/web/dist/assets/{Results-DJRLiVo0.js → Results-BNuuBiwU.js} +1 -1
- package/apps/web/dist/assets/{RunDrawer-CSpTNJp-.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-OiKEnmL1.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-BpdsLIOc.js → UpdateCheck-D3QhfI5c.js} +2 -2
- package/apps/web/dist/assets/{brand-ByQY-UcL.js → brand-DKuVyYhH.js} +1 -1
- package/apps/web/dist/assets/changelog-Db3nvWao.js +1 -0
- package/apps/web/dist/assets/{code-editor-B8zG80PA.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-D18zQ05f.css → index-CduFlFCp.css} +1 -1
- package/apps/web/dist/assets/index-CtE0rJEL.js +102 -0
- package/apps/web/dist/assets/{read-aloud-spC7eEBp.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-CoEdB_9_.js → useMutation-fT44ij_b.js} +1 -1
- package/apps/web/dist/assets/{viewers-BmcrgvXX.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 +54 -1
- package/node_modules/@engenty/wizards-shared/dist/run.js +23 -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 +5 -1
- 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-fgTP28Mn.js +0 -2
- package/apps/web/dist/assets/ConnectorsSection-iLrduYak.js +0 -1
- package/apps/web/dist/assets/EditorPage-CRZte0O1.js +0 -3
- package/apps/web/dist/assets/Marketplace-9aGWG2pJ.js +0 -2
- package/apps/web/dist/assets/NewWizardChannels-BFDm9vCT.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-ueGFlLDo.js +0 -7
- package/apps/web/dist/assets/OnboardingPage-DtDd7k_O.js +0 -1
- package/apps/web/dist/assets/PreviewPane-CEltrf_-.js +0 -7
- package/apps/web/dist/assets/ProtocolSection-Bb3c44Te.js +0 -1
- package/apps/web/dist/assets/PublicRunner-BaTg24s3.js +0 -1
- package/apps/web/dist/assets/SettingsPage--_ap3omw.js +0 -2
- package/apps/web/dist/assets/SetupPage-ELKHbmnE.js +0 -1
- package/apps/web/dist/assets/SkillEditor-C1_zwNOQ.js +0 -1
- package/apps/web/dist/assets/Skills-_pLGtOjH.js +0 -9
- package/apps/web/dist/assets/SpacePage-r4EbxEJe.js +0 -2
- package/apps/web/dist/assets/StudioHome-CwvxI29m.js +0 -1
- package/apps/web/dist/assets/changelog-Dt-V-BKp.js +0 -1
- package/apps/web/dist/assets/host-Ckjz94Ea.js +0 -69
- package/apps/web/dist/assets/i18n-ClCOlfx2.js +0 -55
- package/apps/web/dist/assets/index-BHKh0A9F.js +0 -10
- package/apps/web/dist/assets/runners-DNqzwMQ0.js +0 -1
- package/apps/web/dist/assets/session-Dd9duhPc.js +0 -1
- package/apps/web/dist/assets/theme-DumM6FI_.js +0 -14
- package/apps/web/dist/assets/ui-BjhZhw8x.js +0 -16
|
@@ -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
|
}
|