@engenty/wizards-runtime 0.19.1 → 0.20.1

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.
Files changed (166) hide show
  1. package/apps/runtime/dist/agents/architect.js +4 -4
  2. package/apps/runtime/dist/agents/studio-assistant.js +2 -31
  3. package/apps/runtime/dist/app.js +4 -4
  4. package/apps/runtime/dist/assistant/knows.js +2 -2
  5. package/apps/runtime/dist/auth/index.js +1 -1
  6. package/apps/runtime/dist/authoring/example.js +1 -1
  7. package/apps/runtime/dist/authoring/guide.js +35 -6
  8. package/apps/runtime/dist/broker/account.js +85 -16
  9. package/apps/runtime/dist/broker/call.js +137 -37
  10. package/apps/runtime/dist/broker/log.js +19 -5
  11. package/apps/runtime/dist/broker/rwx.js +12 -9
  12. package/apps/runtime/dist/cli/main.js +2 -0
  13. package/apps/runtime/dist/connectors/index.js +52 -11
  14. package/apps/runtime/dist/connectors/person-connections.js +279 -0
  15. package/apps/runtime/dist/connectors/person-sign-ins.js +74 -3
  16. package/apps/runtime/dist/connectors/same-service.js +14 -0
  17. package/apps/runtime/dist/connectors/space-choice.js +116 -0
  18. package/apps/runtime/dist/connectors/space-connections.js +40 -2
  19. package/apps/runtime/dist/db/client.js +8 -0
  20. package/apps/runtime/dist/db/kept-accounts.js +88 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0075_person_connection.sql +25 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0076_clients_in_spaces.sql +28 -0
  23. package/apps/runtime/dist/db/migrations/tenant/0077_client_spaces_at_root.sql +21 -0
  24. package/apps/runtime/dist/db/migrations/tenant/meta/0075_snapshot.json +7859 -0
  25. package/apps/runtime/dist/db/migrations/tenant/meta/0076_snapshot.json +7859 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/0077_snapshot.json +7859 -0
  27. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +21 -0
  28. package/apps/runtime/dist/db/schema.js +67 -16
  29. package/apps/runtime/dist/docs/dev/api.md +8 -8
  30. package/apps/runtime/dist/docs/dev/wizard-format/index.md +3 -1
  31. package/apps/runtime/dist/docs/user-guide/command-line.md +2 -1
  32. package/apps/runtime/dist/elements/caller.js +1 -1
  33. package/apps/runtime/dist/elements/knowledge.js +5 -5
  34. package/apps/runtime/dist/elements/wizards.js +7 -11
  35. package/apps/runtime/dist/engine/notices.js +13 -1
  36. package/apps/runtime/dist/engine/requirements.js +116 -3
  37. package/apps/runtime/dist/engine/run-needs.js +58 -0
  38. package/apps/runtime/dist/engine/runner.js +209 -16
  39. package/apps/runtime/dist/engine/starts.js +9 -0
  40. package/apps/runtime/dist/engine/types.js +5 -1
  41. package/apps/runtime/dist/harness/claude.js +3 -1
  42. package/apps/runtime/dist/manage.js +1 -1
  43. package/apps/runtime/dist/mcp/tools.js +3 -3
  44. package/apps/runtime/dist/plugins/runs.js +2 -1
  45. package/apps/runtime/dist/prompts/authoring.md +13 -3
  46. package/apps/runtime/dist/prompts/goose.md +0 -5
  47. package/apps/runtime/dist/routes/api.js +9 -4
  48. package/apps/runtime/dist/routes/client-contract.js +2 -2
  49. package/apps/runtime/dist/routes/client-spaces.js +1 -16
  50. package/apps/runtime/dist/routes/connections.js +6 -1
  51. package/apps/runtime/dist/routes/marketplace.js +27 -7
  52. package/apps/runtime/dist/routes/plugins.js +1 -1
  53. package/apps/runtime/dist/routes/runs.js +157 -11
  54. package/apps/runtime/dist/routes/studio.js +42 -5
  55. package/apps/runtime/dist/services/client-portal.js +58 -49
  56. package/apps/runtime/dist/services/client-spaces.js +57 -125
  57. package/apps/runtime/dist/services/links.js +3 -3
  58. package/apps/runtime/dist/services/marketplace.js +6 -2
  59. package/apps/runtime/dist/services/members-studio.js +1 -1
  60. package/apps/runtime/dist/services/query-vectors.js +1 -1
  61. package/apps/runtime/dist/services/runs.js +19 -20
  62. package/apps/runtime/dist/services/space-parent.js +4 -11
  63. package/apps/runtime/dist/services/spaces.js +56 -47
  64. package/apps/runtime/dist/services/work-ai.js +3 -3
  65. package/apps/runtime/dist/store/index.js +28 -8
  66. package/apps/runtime/dist/store/shared-lists.js +2 -2
  67. package/apps/runtime/dist/sync/hub.js +9 -5
  68. package/apps/runtime/dist/tools/connector.js +4 -2
  69. package/apps/web/dist/assets/{AboutDialog-BUWu36Mb.js → AboutDialog-BFi6vOyJ.js} +1 -1
  70. package/apps/web/dist/assets/{BlockEditor-1-EvUIta.js → BlockEditor-C44bI_ih.js} +1 -1
  71. package/apps/web/dist/assets/{Bundle-RNkjBwAL.js → Bundle-DZyQ1FP7.js} +1 -1
  72. package/apps/web/dist/assets/CapabilitiesPage-DAX03vkY.js +2 -0
  73. package/apps/web/dist/assets/{ChangelogDialog-C_ZZLRZT.js → ChangelogDialog-CdchxTO8.js} +1 -1
  74. package/apps/web/dist/assets/{CodeEditor-BEJKIMd0.js → CodeEditor-BRufUwu0.js} +1 -1
  75. package/apps/web/dist/assets/ConnectorsSection-CNpieoyT.js +1 -0
  76. package/apps/web/dist/assets/EditorPage-CxABBMqo.js +3 -0
  77. package/apps/web/dist/assets/{FlowPreview-ptI86Ogs.js → FlowPreview-aj58c-gH.js} +1 -1
  78. package/apps/web/dist/assets/{LangSwitch-BNa_H8AR.js → LangSwitch-BNkytlus.js} +1 -1
  79. package/apps/web/dist/assets/Marketplace-D3hdvrkz.js +2 -0
  80. package/apps/web/dist/assets/NewWizardChannels-0aZoziks.js +1 -0
  81. package/apps/web/dist/assets/NewWizardPage-Bn2BPaUB.js +7 -0
  82. package/apps/web/dist/assets/OnboardingPage-DwF6KdQy.js +1 -0
  83. package/apps/web/dist/assets/ProtocolSection-Ce5LBBzL.js +1 -0
  84. package/apps/web/dist/assets/PublicRunner-Bp4DxTrD.js +1 -0
  85. package/apps/web/dist/assets/{ReadOnly-YF0RkR7P.js → ReadOnly-BFVaKM3w.js} +1 -1
  86. package/apps/web/dist/assets/{Results-DJRLiVo0.js → Results--mJFsNH2.js} +1 -1
  87. package/apps/web/dist/assets/{RunDrawer-CSpTNJp-.js → RunDrawer-DtbxGBIm.js} +1 -1
  88. package/apps/web/dist/assets/SettingsPage-Cytcl_9w.js +2 -0
  89. package/apps/web/dist/assets/SetupPage-B5zCrIKT.js +1 -0
  90. package/apps/web/dist/assets/{SharePage-OiKEnmL1.js → SharePage-CgQp_PT6.js} +1 -1
  91. package/apps/web/dist/assets/SkillEditor-ARx8QPGp.js +1 -0
  92. package/apps/web/dist/assets/Skills-frfXXEcF.js +9 -0
  93. package/apps/web/dist/assets/SpacePage-Bd5-wBUc.js +2 -0
  94. package/apps/web/dist/assets/StudioHome-DzVpWMrD.js +1 -0
  95. package/apps/web/dist/assets/TableEditor-CRhc6jI6.js +7 -0
  96. package/apps/web/dist/assets/{UpdateCheck-BpdsLIOc.js → UpdateCheck-BEruHgs0.js} +2 -2
  97. package/apps/web/dist/assets/{brand-ByQY-UcL.js → brand-DKuVyYhH.js} +1 -1
  98. package/apps/web/dist/assets/changelog-BgFhbmMa.js +1 -0
  99. package/apps/web/dist/assets/{code-editor-B8zG80PA.js → code-editor-BLwDuQLI.js} +2 -2
  100. package/apps/web/dist/assets/host-B2ZzDrkc.js +69 -0
  101. package/apps/web/dist/assets/i18n-Dyi0kvaA.js +55 -0
  102. package/apps/web/dist/assets/index-C1m_S1ls.js +102 -0
  103. package/apps/web/dist/assets/{index-D18zQ05f.css → index-CduFlFCp.css} +1 -1
  104. package/apps/web/dist/assets/{read-aloud-spC7eEBp.js → read-aloud-DGS8mWgC.js} +1 -1
  105. package/apps/web/dist/assets/session-EIDP3Wzc.js +1 -0
  106. package/apps/web/dist/assets/theme-B46aPLtX.js +14 -0
  107. package/apps/web/dist/assets/ui-DSgksc1H.js +16 -0
  108. package/apps/web/dist/assets/{useMutation-CoEdB_9_.js → useMutation-fT44ij_b.js} +1 -1
  109. package/apps/web/dist/assets/{viewers-BmcrgvXX.js → viewers-DvA5VsXw.js} +2 -2
  110. package/apps/web/dist/index.html +18 -13
  111. package/apps/web/dist/mcp/flow.html +62 -62
  112. package/bin/bot.mjs +1120 -0
  113. package/bin/wizards.mjs +6 -0
  114. package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -2
  115. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +67 -0
  116. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10324 -7
  117. package/node_modules/@engenty/wizards-shared/dist/definition.js +32 -6
  118. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +17 -23
  119. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +17 -23
  120. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
  121. package/node_modules/@engenty/wizards-shared/dist/marketplace-search.js +7 -1
  122. package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +9 -2
  123. package/node_modules/@engenty/wizards-shared/dist/page-data.d.ts +72 -0
  124. package/node_modules/@engenty/wizards-shared/dist/page-data.js +5 -0
  125. package/node_modules/@engenty/wizards-shared/dist/page-look.d.ts +17 -0
  126. package/node_modules/@engenty/wizards-shared/dist/page-look.js +118 -0
  127. package/node_modules/@engenty/wizards-shared/dist/page-styles.d.ts +6 -0
  128. package/node_modules/@engenty/wizards-shared/dist/page-styles.js +98 -0
  129. package/node_modules/@engenty/wizards-shared/dist/page-texts.d.ts +36 -0
  130. package/node_modules/@engenty/wizards-shared/dist/page-texts.js +119 -0
  131. package/node_modules/@engenty/wizards-shared/dist/requires.js +2 -0
  132. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -1
  133. package/node_modules/@engenty/wizards-shared/dist/run.js +23 -0
  134. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +27 -1
  135. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +26 -0
  136. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +24 -1
  137. package/node_modules/@engenty/wizards-shared/dist/transition.d.ts +2 -1
  138. package/node_modules/@engenty/wizards-shared/dist/transition.js +5 -1
  139. package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +1 -1
  140. package/package.json +1 -1
  141. package/plugin/.claude-plugin/plugin.json +1 -1
  142. package/plugin/plugin.json +1 -1
  143. package/apps/web/dist/assets/CapabilitiesPage-fgTP28Mn.js +0 -2
  144. package/apps/web/dist/assets/ConnectorsSection-iLrduYak.js +0 -1
  145. package/apps/web/dist/assets/EditorPage-CRZte0O1.js +0 -3
  146. package/apps/web/dist/assets/Marketplace-9aGWG2pJ.js +0 -2
  147. package/apps/web/dist/assets/NewWizardChannels-BFDm9vCT.js +0 -1
  148. package/apps/web/dist/assets/NewWizardPage-ueGFlLDo.js +0 -7
  149. package/apps/web/dist/assets/OnboardingPage-DtDd7k_O.js +0 -1
  150. package/apps/web/dist/assets/PreviewPane-CEltrf_-.js +0 -7
  151. package/apps/web/dist/assets/ProtocolSection-Bb3c44Te.js +0 -1
  152. package/apps/web/dist/assets/PublicRunner-BaTg24s3.js +0 -1
  153. package/apps/web/dist/assets/SettingsPage--_ap3omw.js +0 -2
  154. package/apps/web/dist/assets/SetupPage-ELKHbmnE.js +0 -1
  155. package/apps/web/dist/assets/SkillEditor-C1_zwNOQ.js +0 -1
  156. package/apps/web/dist/assets/Skills-_pLGtOjH.js +0 -9
  157. package/apps/web/dist/assets/SpacePage-r4EbxEJe.js +0 -2
  158. package/apps/web/dist/assets/StudioHome-CwvxI29m.js +0 -1
  159. package/apps/web/dist/assets/changelog-Dt-V-BKp.js +0 -1
  160. package/apps/web/dist/assets/host-Ckjz94Ea.js +0 -69
  161. package/apps/web/dist/assets/i18n-ClCOlfx2.js +0 -55
  162. package/apps/web/dist/assets/index-BHKh0A9F.js +0 -10
  163. package/apps/web/dist/assets/runners-DNqzwMQ0.js +0 -1
  164. package/apps/web/dist/assets/session-Dd9duhPc.js +0 -1
  165. package/apps/web/dist/assets/theme-DumM6FI_.js +0 -14
  166. 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, count, eq, inArray, isNull } from "drizzle-orm";
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, requireBuild } from "./access.js";
9
+ import { currentRole, requireAdmin } from "./access.js";
11
10
  import { notFound, ServiceError } from "./errors.js";
12
- import { ownedSpace, removeSpace } from "./spaces.js";
11
+ import { ownedSpace } from "./spaces.js";
13
12
  /*
14
- * Client spaces (docs/plans/client-spaces.md): a space's clients, each in a client space under it.
15
- * The firm makes them in its space; who is in one (`space_member`) decides which client spaces a
16
- * client of the organization sees. Behind the `clientSpaces` switch.
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
- /** Client spaces are behind their switch: while it is off, they are not there. */
19
+ /** Clients are behind their switch, and in the organization's spaces: else they are not there. */
19
20
  export async function requireClientSpaces() {
20
- if ((await currentFeatures()).clientSpaces !== true) {
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
- const features = await currentFeatures();
30
- if (features.clientSpaces === true || (role !== "client" && features.orgSpaces === true)) {
28
+ if (role === "client") {
29
+ await requireClientSpaces();
31
30
  return;
32
31
  }
33
- throw notFound();
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 the firm shares with people: a client space, and with `orgSpaces` any space under the
45
- * organization's root (docs/plans/org-spaces.md) — not the root, not someone's Mein Space.
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 clientSpace(userId, spaceId) {
40
+ async function sharedSpace(userId, spaceId, as) {
48
41
  const space = await ownedSpace(userId, spaceId);
49
- if (currentRole() === "client") {
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
- if (space.kind === "client") {
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.query.run.findFirst({
135
- columns: { id: true, clientSpaceId: true, status: true },
136
- where: and(eq(schema.run.id, runId), eq(schema.run.tenantId, currentTenant())),
137
- });
138
- if (!run?.clientSpaceId) {
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
- await clientSpace(userId, run.clientSpaceId);
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
- await db.update(schema.run).set({ clientSharedAt: sharedAt }).where(eq(schema.run.id, run.id));
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
- /** Closes a client space: its data, results and chats go with it. */
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 clientSpace(userId, spaceId);
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 space, as a client or as the firm's. */
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 clientSpace(userId, spaceId);
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 openToItsClients(space);
119
+ await seedClientRules(space.id);
192
120
  }
193
121
  }
194
- /** Takes a person out of a client space. */
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 clientSpace(userId, spaceId);
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 firmSpace(userId, spaceId);
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 a client space by their address: the Manage-App invites them into the
211
- * organization as a `client` (taking no seat), and the client space keeps the address until they
212
- * sign in for the first time (`claimClientInvites`). Cloud only: a local install has no accounts.
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 clientSpace(userId, spaceId);
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 openToItsClients(space);
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 of a client space away with what they made: they belong to it, though their
20
- * wizards stay the parent's (docs/plans/client-portal.md).
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 removeClientSpaceRuns(spaceId) {
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
- usable: summary.version <= DEFINITION_VERSION,
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 of a client space is the client space's, though its wizard is the parent's.
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 space's search once per space),
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. In a
454
- * client space the wizard is its parent's and the run belongs to the client space
455
- * (docs/plans/client-portal.md).
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 client space shows the runs started in it, of its parent's wizards; a space only its own
712
- // (docs/plans/client-portal.md). With `orgSpaces` a space under the root shows its own wizards'
713
- // runs and the runs of the root's wizards started in it (docs/plans/org-spaces.md).
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 client = reads?.as === "client" ? spaceId : null;
716
- const wizardSpaces = reads?.as === "client"
717
- ? [reads.parentId]
718
- : reads?.as === "root"
719
- ? [spaceId, reads.parentId]
720
- : [spaceId];
721
- const inSpace = client
722
- ? eq(schema.run.clientSpaceId, client)
723
- : reads?.as === "root"
724
- ? or(and(eq(schema.wizard.spaceId, spaceId), isNull(schema.run.clientSpaceId)), and(eq(schema.wizard.spaceId, reads.parentId), eq(schema.run.clientSpaceId, spaceId)))
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?.as === "root"
749
- ? or(and(inArray(schema.run.wizardId, ids.filter((id) => !fromRoot.has(id)).concat("")), isNull(schema.run.clientSpaceId)), and(inArray(schema.run.wizardId, [...fromRoot].concat("")), eq(schema.run.clientSpaceId, spaceId)))
750
- : inSpace;
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: { kind: true, parentId: true },
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
- if (space.kind === "client") {
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, kind: 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
  }