@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.
Files changed (162) 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/connectors/index.js +52 -11
  13. package/apps/runtime/dist/connectors/person-connections.js +279 -0
  14. package/apps/runtime/dist/connectors/person-sign-ins.js +74 -3
  15. package/apps/runtime/dist/connectors/same-service.js +14 -0
  16. package/apps/runtime/dist/connectors/space-choice.js +116 -0
  17. package/apps/runtime/dist/connectors/space-connections.js +40 -2
  18. package/apps/runtime/dist/db/client.js +8 -0
  19. package/apps/runtime/dist/db/kept-accounts.js +88 -0
  20. package/apps/runtime/dist/db/migrations/tenant/0075_person_connection.sql +25 -0
  21. package/apps/runtime/dist/db/migrations/tenant/0076_clients_in_spaces.sql +28 -0
  22. package/apps/runtime/dist/db/migrations/tenant/0077_client_spaces_at_root.sql +21 -0
  23. package/apps/runtime/dist/db/migrations/tenant/meta/0075_snapshot.json +7859 -0
  24. package/apps/runtime/dist/db/migrations/tenant/meta/0076_snapshot.json +7859 -0
  25. package/apps/runtime/dist/db/migrations/tenant/meta/0077_snapshot.json +7859 -0
  26. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +21 -0
  27. package/apps/runtime/dist/db/schema.js +67 -16
  28. package/apps/runtime/dist/docs/dev/api.md +8 -8
  29. package/apps/runtime/dist/docs/dev/wizard-format/index.md +3 -1
  30. package/apps/runtime/dist/elements/caller.js +1 -1
  31. package/apps/runtime/dist/elements/knowledge.js +5 -5
  32. package/apps/runtime/dist/elements/wizards.js +7 -11
  33. package/apps/runtime/dist/engine/notices.js +13 -1
  34. package/apps/runtime/dist/engine/requirements.js +116 -3
  35. package/apps/runtime/dist/engine/run-needs.js +58 -0
  36. package/apps/runtime/dist/engine/runner.js +209 -16
  37. package/apps/runtime/dist/engine/starts.js +9 -0
  38. package/apps/runtime/dist/engine/types.js +5 -1
  39. package/apps/runtime/dist/harness/claude.js +3 -1
  40. package/apps/runtime/dist/manage.js +1 -1
  41. package/apps/runtime/dist/mcp/tools.js +3 -3
  42. package/apps/runtime/dist/plugins/runs.js +2 -1
  43. package/apps/runtime/dist/prompts/authoring.md +13 -3
  44. package/apps/runtime/dist/prompts/goose.md +0 -5
  45. package/apps/runtime/dist/routes/api.js +9 -4
  46. package/apps/runtime/dist/routes/client-contract.js +2 -2
  47. package/apps/runtime/dist/routes/client-spaces.js +1 -16
  48. package/apps/runtime/dist/routes/connections.js +6 -1
  49. package/apps/runtime/dist/routes/marketplace.js +27 -7
  50. package/apps/runtime/dist/routes/plugins.js +1 -1
  51. package/apps/runtime/dist/routes/runs.js +157 -11
  52. package/apps/runtime/dist/routes/studio.js +42 -5
  53. package/apps/runtime/dist/services/client-portal.js +58 -49
  54. package/apps/runtime/dist/services/client-spaces.js +57 -125
  55. package/apps/runtime/dist/services/links.js +3 -3
  56. package/apps/runtime/dist/services/marketplace.js +6 -2
  57. package/apps/runtime/dist/services/members-studio.js +1 -1
  58. package/apps/runtime/dist/services/query-vectors.js +1 -1
  59. package/apps/runtime/dist/services/runs.js +19 -20
  60. package/apps/runtime/dist/services/space-parent.js +4 -11
  61. package/apps/runtime/dist/services/spaces.js +56 -47
  62. package/apps/runtime/dist/services/work-ai.js +3 -3
  63. package/apps/runtime/dist/store/index.js +28 -8
  64. package/apps/runtime/dist/store/shared-lists.js +2 -2
  65. package/apps/runtime/dist/sync/hub.js +9 -5
  66. package/apps/runtime/dist/tools/connector.js +4 -2
  67. package/apps/web/dist/assets/{AboutDialog-BUWu36Mb.js → AboutDialog-QWzpEK8M.js} +1 -1
  68. package/apps/web/dist/assets/{BlockEditor-1-EvUIta.js → BlockEditor-C44bI_ih.js} +1 -1
  69. package/apps/web/dist/assets/{Bundle-RNkjBwAL.js → Bundle-DZyQ1FP7.js} +1 -1
  70. package/apps/web/dist/assets/CapabilitiesPage-DAr0-gN1.js +2 -0
  71. package/apps/web/dist/assets/{ChangelogDialog-C_ZZLRZT.js → ChangelogDialog-CdHqJV2P.js} +1 -1
  72. package/apps/web/dist/assets/{CodeEditor-BEJKIMd0.js → CodeEditor-BRufUwu0.js} +1 -1
  73. package/apps/web/dist/assets/ConnectorsSection-BO6jHrYU.js +1 -0
  74. package/apps/web/dist/assets/EditorPage-Bx-fKnsY.js +3 -0
  75. package/apps/web/dist/assets/{FlowPreview-ptI86Ogs.js → FlowPreview-aj58c-gH.js} +1 -1
  76. package/apps/web/dist/assets/{LangSwitch-BNa_H8AR.js → LangSwitch-BNkytlus.js} +1 -1
  77. package/apps/web/dist/assets/Marketplace-D3hdvrkz.js +2 -0
  78. package/apps/web/dist/assets/NewWizardChannels-fveQcQlY.js +1 -0
  79. package/apps/web/dist/assets/NewWizardPage-BTX1g2t1.js +7 -0
  80. package/apps/web/dist/assets/OnboardingPage-DwF6KdQy.js +1 -0
  81. package/apps/web/dist/assets/ProtocolSection-YnJcMN9E.js +1 -0
  82. package/apps/web/dist/assets/PublicRunner-Bp4DxTrD.js +1 -0
  83. package/apps/web/dist/assets/{ReadOnly-YF0RkR7P.js → ReadOnly-C6qmTD35.js} +1 -1
  84. package/apps/web/dist/assets/{Results-DJRLiVo0.js → Results-BNuuBiwU.js} +1 -1
  85. package/apps/web/dist/assets/{RunDrawer-CSpTNJp-.js → RunDrawer-CMgN-XTB.js} +1 -1
  86. package/apps/web/dist/assets/SettingsPage-CuUB26YJ.js +2 -0
  87. package/apps/web/dist/assets/SetupPage-llGzMVeH.js +1 -0
  88. package/apps/web/dist/assets/{SharePage-OiKEnmL1.js → SharePage-CgQp_PT6.js} +1 -1
  89. package/apps/web/dist/assets/SkillEditor-ARx8QPGp.js +1 -0
  90. package/apps/web/dist/assets/Skills-frfXXEcF.js +9 -0
  91. package/apps/web/dist/assets/SpacePage-Dv6ocsc_.js +2 -0
  92. package/apps/web/dist/assets/StudioHome-B0bZRm1L.js +1 -0
  93. package/apps/web/dist/assets/TableEditor-CfzTLmJF.js +7 -0
  94. package/apps/web/dist/assets/{UpdateCheck-BpdsLIOc.js → UpdateCheck-D3QhfI5c.js} +2 -2
  95. package/apps/web/dist/assets/{brand-ByQY-UcL.js → brand-DKuVyYhH.js} +1 -1
  96. package/apps/web/dist/assets/changelog-Db3nvWao.js +1 -0
  97. package/apps/web/dist/assets/{code-editor-B8zG80PA.js → code-editor-BLwDuQLI.js} +2 -2
  98. package/apps/web/dist/assets/host-C-AAp8Bz.js +69 -0
  99. package/apps/web/dist/assets/i18n-Dyi0kvaA.js +55 -0
  100. package/apps/web/dist/assets/{index-D18zQ05f.css → index-CduFlFCp.css} +1 -1
  101. package/apps/web/dist/assets/index-CtE0rJEL.js +102 -0
  102. package/apps/web/dist/assets/{read-aloud-spC7eEBp.js → read-aloud-DGS8mWgC.js} +1 -1
  103. package/apps/web/dist/assets/session-EIDP3Wzc.js +1 -0
  104. package/apps/web/dist/assets/theme-B46aPLtX.js +14 -0
  105. package/apps/web/dist/assets/ui-DSgksc1H.js +16 -0
  106. package/apps/web/dist/assets/{useMutation-CoEdB_9_.js → useMutation-fT44ij_b.js} +1 -1
  107. package/apps/web/dist/assets/{viewers-BmcrgvXX.js → viewers-DvA5VsXw.js} +2 -2
  108. package/apps/web/dist/index.html +18 -13
  109. package/apps/web/dist/mcp/flow.html +62 -62
  110. package/node_modules/@engenty/wizards-shared/dist/catalog-prompt.js +2 -2
  111. package/node_modules/@engenty/wizards-shared/dist/connectors.d.ts +67 -0
  112. package/node_modules/@engenty/wizards-shared/dist/definition.d.ts +10324 -7
  113. package/node_modules/@engenty/wizards-shared/dist/definition.js +32 -6
  114. package/node_modules/@engenty/wizards-shared/dist/feature-flags.d.ts +17 -23
  115. package/node_modules/@engenty/wizards-shared/dist/feature-flags.js +17 -23
  116. package/node_modules/@engenty/wizards-shared/dist/json-schema.js +3 -3
  117. package/node_modules/@engenty/wizards-shared/dist/marketplace-search.js +7 -1
  118. package/node_modules/@engenty/wizards-shared/dist/marketplace.d.ts +9 -2
  119. package/node_modules/@engenty/wizards-shared/dist/page-data.d.ts +72 -0
  120. package/node_modules/@engenty/wizards-shared/dist/page-data.js +5 -0
  121. package/node_modules/@engenty/wizards-shared/dist/page-look.d.ts +17 -0
  122. package/node_modules/@engenty/wizards-shared/dist/page-look.js +118 -0
  123. package/node_modules/@engenty/wizards-shared/dist/page-styles.d.ts +6 -0
  124. package/node_modules/@engenty/wizards-shared/dist/page-styles.js +98 -0
  125. package/node_modules/@engenty/wizards-shared/dist/page-texts.d.ts +36 -0
  126. package/node_modules/@engenty/wizards-shared/dist/page-texts.js +119 -0
  127. package/node_modules/@engenty/wizards-shared/dist/requires.js +2 -0
  128. package/node_modules/@engenty/wizards-shared/dist/run.d.ts +54 -1
  129. package/node_modules/@engenty/wizards-shared/dist/run.js +23 -0
  130. package/node_modules/@engenty/wizards-shared/dist/runner-texts.d.ts +27 -1
  131. package/node_modules/@engenty/wizards-shared/dist/runner-texts.js +26 -0
  132. package/node_modules/@engenty/wizards-shared/dist/store.d.ts +24 -1
  133. package/node_modules/@engenty/wizards-shared/dist/transition.d.ts +2 -1
  134. package/node_modules/@engenty/wizards-shared/dist/transition.js +5 -1
  135. package/node_modules/@engenty/wizards-shared/dist/wizard-text.js +1 -1
  136. package/package.json +1 -1
  137. package/plugin/.claude-plugin/plugin.json +1 -1
  138. package/plugin/plugin.json +1 -1
  139. package/apps/web/dist/assets/CapabilitiesPage-fgTP28Mn.js +0 -2
  140. package/apps/web/dist/assets/ConnectorsSection-iLrduYak.js +0 -1
  141. package/apps/web/dist/assets/EditorPage-CRZte0O1.js +0 -3
  142. package/apps/web/dist/assets/Marketplace-9aGWG2pJ.js +0 -2
  143. package/apps/web/dist/assets/NewWizardChannels-BFDm9vCT.js +0 -1
  144. package/apps/web/dist/assets/NewWizardPage-ueGFlLDo.js +0 -7
  145. package/apps/web/dist/assets/OnboardingPage-DtDd7k_O.js +0 -1
  146. package/apps/web/dist/assets/PreviewPane-CEltrf_-.js +0 -7
  147. package/apps/web/dist/assets/ProtocolSection-Bb3c44Te.js +0 -1
  148. package/apps/web/dist/assets/PublicRunner-BaTg24s3.js +0 -1
  149. package/apps/web/dist/assets/SettingsPage--_ap3omw.js +0 -2
  150. package/apps/web/dist/assets/SetupPage-ELKHbmnE.js +0 -1
  151. package/apps/web/dist/assets/SkillEditor-C1_zwNOQ.js +0 -1
  152. package/apps/web/dist/assets/Skills-_pLGtOjH.js +0 -9
  153. package/apps/web/dist/assets/SpacePage-r4EbxEJe.js +0 -2
  154. package/apps/web/dist/assets/StudioHome-CwvxI29m.js +0 -1
  155. package/apps/web/dist/assets/changelog-Dt-V-BKp.js +0 -1
  156. package/apps/web/dist/assets/host-Ckjz94Ea.js +0 -69
  157. package/apps/web/dist/assets/i18n-ClCOlfx2.js +0 -55
  158. package/apps/web/dist/assets/index-BHKh0A9F.js +0 -10
  159. package/apps/web/dist/assets/runners-DNqzwMQ0.js +0 -1
  160. package/apps/web/dist/assets/session-Dd9duhPc.js +0 -1
  161. package/apps/web/dist/assets/theme-DumM6FI_.js +0 -14
  162. package/apps/web/dist/assets/ui-BjhZhw8x.js +0 -16
@@ -1,8 +1,10 @@
1
+ import { FORMAT_VERSIONS } from "@engenty/wizards-shared/definition";
1
2
  import { CAPABILITY_IDS } from "@engenty/wizards-shared/fit";
2
3
  import { INDUSTRY_IDS, ITEM_FORMAT_IDS, MARKETPLACE_PLAN_IDS, USE_CASE_IDS, } from "@engenty/wizards-shared/marketplace";
3
4
  import { sectorOf } from "@engenty/wizards-shared/sectors";
4
5
  import { Hono } from "hono";
5
6
  import { z } from "zod";
7
+ import { feature, remoteFeatures } from "../features.js";
6
8
  import { asLang, featuredFirst, marketplaceDetail, searchMarketplace, searchMarketplaceAsGuest, starEntry, } from "../services/marketplace.js";
7
9
  import { byFit, organizationContext } from "../services/organization-context.js";
8
10
  import { notFoundAnswer } from "./lang.js";
@@ -14,6 +16,7 @@ const searchSchema = z.object({
14
16
  format: z.enum(ITEM_FORMAT_IDS).optional(),
15
17
  capability: z.enum(CAPABILITY_IDS).optional(),
16
18
  plan: z.enum(MARKETPLACE_PLAN_IDS).optional(),
19
+ version: z.enum(FORMAT_VERSIONS).optional(),
17
20
  starred: z
18
21
  .enum(["1", "0"])
19
22
  .optional()
@@ -26,22 +29,33 @@ const searchSchema = z.object({
26
29
  .optional()
27
30
  .transform((v) => v === "1"),
28
31
  });
32
+ /** The version of a wizard's format is offered while the kernel switch is on. */
33
+ const versionsOffered = async () => feature("kernel", await remoteFeatures().catch(() => null));
34
+ /** The filters' counts, without the versions of the format while those are not offered. */
35
+ const facetsShown = (facets, versions) => {
36
+ if (versions)
37
+ return facets;
38
+ const { version: _version, ...rest } = facets;
39
+ return rest;
40
+ };
29
41
  /** The marketplace for someone signed in: the search on "new", an entry, and the stars. */
30
42
  export const marketplaceStudio = new Hono()
31
43
  .get("/", async (c) => {
32
- const { lang, fit, ...search } = searchSchema.parse(c.req.query());
44
+ const { lang, fit, ...asked } = searchSchema.parse(c.req.query());
45
+ const versions = await versionsOffered();
46
+ const { version, ...rest } = asked;
47
+ const search = versions ? asked : rest;
33
48
  const context = fit ? await organizationContext(c.get("user").tenantId) : null;
34
49
  if (!context) {
35
- return c.json({
36
- ...featuredFirst(await searchMarketplace({ ...search, lang: asLang(lang) }), search),
37
- context: null,
38
- });
50
+ const found = featuredFirst(await searchMarketplace({ ...search, lang: asLang(lang) }), search);
51
+ return c.json({ ...found, facets: facetsShown(found.facets, versions), context: null });
39
52
  }
40
53
  // The whole catalog in the order that fits, then the page of it.
41
54
  const all = featuredFirst(await searchMarketplace({ lang: asLang(lang), limit: 100, offset: 0 }), {});
42
55
  const sector = sectorOf(context.sector);
43
56
  return c.json({
44
57
  ...all,
58
+ facets: facetsShown(all.facets, versions),
45
59
  entries: byFit(all.entries, context).slice(search.offset, search.offset + search.limit),
46
60
  context: {
47
61
  sector: sector?.id ?? null,
@@ -63,6 +77,12 @@ export const marketplaceStudio = new Hono()
63
77
  });
64
78
  /** The gallery for someone not signed in (the studio's start page for guests): only the search. */
65
79
  export const marketplaceGuest = new Hono().get("/", async (c) => {
66
- const { lang, starred: _starred, ...search } = searchSchema.parse(c.req.query());
67
- return c.json(await searchMarketplaceAsGuest({ ...search, lang: asLang(lang) }));
80
+ const { lang, starred: _starred, ...asked } = searchSchema.parse(c.req.query());
81
+ const versions = await versionsOffered();
82
+ const { version: _version, ...rest } = asked;
83
+ const found = await searchMarketplaceAsGuest({
84
+ ...(versions ? asked : rest),
85
+ lang: asLang(lang),
86
+ });
87
+ return c.json({ ...found, facets: facetsShown(found.facets, versions) });
68
88
  });
@@ -54,7 +54,7 @@ export function answerOf(err) {
54
54
  export async function dispatchAs(c, user) {
55
55
  const id = c.req.param("id") ?? "";
56
56
  const plugin = (await pluginIdsOf(user.tenantId)).has(id) ? loadedPlugin(id) : undefined;
57
- // A client of the organization reaches no plugin's studio routes (docs/plans/client-spaces.md).
57
+ // A client of the organization reaches no plugin's studio routes (docs/plans/org-spaces.md).
58
58
  if (!plugin || user.role === "client") {
59
59
  return c.json(notFoundAnswer(c), 404);
60
60
  }
@@ -15,9 +15,10 @@ import { principalOf } from "../auth/index.js";
15
15
  import { keptStepIds } from "../broker/index.js";
16
16
  import { MARK_FOCUSED_PERSONAL } from "../browser/snapshot.js";
17
17
  import { clientOf, clientRefused } from "../clients.js";
18
- import { ConnectError, connectionViews, connectWithCredentials, disconnect, findConnection, finishOAuth, oauthStateLang, oauthStateRun, startOAuth, } from "../connectors/index.js";
18
+ import { ConnectError, choose, connectionViews, connectorFor, connectWithCredentials, disconnect, findConnection, finishOAuth, oauthStateLang, oauthStateRun, startOAuth, } from "../connectors/index.js";
19
+ import { runConnectionsOn } from "../connectors/person-connections.js";
19
20
  import { finishPluginOAuth, pluginStateTenant } from "../connectors/plugin-connections.js";
20
- import { finishSpaceConnectionOAuth, spaceConnectionStateTenant, } from "../connectors/space-connections.js";
21
+ import { finishSpaceConnectionOAuth, signInWithCredentials, spaceConnectionForNeed, spaceConnectionOf, spaceConnectionStateTenant, spaceConnectorFor, startSpaceConnectionOAuth, } from "../connectors/space-connections.js";
21
22
  import { db, schema, withTenant } from "../db/client.js";
22
23
  import { answerersOf, answeringNarrowed, hiddenWhileAsked, mayAct, mayAnswerStep, mayGoBackFrom, mayWithdraw, stepOfRun, viewFor, } from "../engine/answerers.js";
23
24
  import { answerAsk, pendingAsk } from "../engine/asks.js";
@@ -27,7 +28,7 @@ import { fieldErrorsIn } from "../engine/input.js";
27
28
  import { fromOwner } from "../engine/owner.js";
28
29
  import { pushAvailable, setPushDevice, setRunViewed } from "../engine/push.js";
29
30
  import { liveResources } from "../engine/resources.js";
30
- import { answerTurn, cancel, createRun, durableRunsOn, editOutput, GuestBudgetError, goBack, keepUnsent, NoCreditsError, RunConflict, RunInputError, retry, reviewStep, runView, spaceIdOf, stopRun, submitPage, talkAllowed, wakeNow, writeRunState, } from "../engine/runner.js";
31
+ import { answerTurn, cancel, createRun, durableRunsOn, editOutput, GuestBudgetError, goBack, keepUnsent, NoCreditsError, ownsRun, RunConflict, RunInputError, retry, reviewStep, runView, signedIn, spaceIdOf, stopRun, submitPage, talkAllowed, wakeNow, writeRunState, } from "../engine/runner.js";
31
32
  import { basePath, env } from "../env.js";
32
33
  import { loadAsset, saveAsset } from "../files/storage.js";
33
34
  import { checkUpload } from "../files/upload-check.js";
@@ -40,7 +41,7 @@ import { errorText, ModelUnavailableError, noteOf } from "../model-errors.js";
40
41
  import { listDownload, renderDownload, stepHtml } from "../render/downloads.js";
41
42
  import { HTML_RESPONSE_CSP } from "../render/guard.js";
42
43
  import { runTicketValid, runViewTicketValid, runWaitTicketValid, verifySignedUrl, } from "../secrets/signing.js";
43
- import { isAdminRole, MEMBERS_EDIT_ONLY } from "../services/access.js";
44
+ import { asRole, isAdminRole, MEMBERS_EDIT_ONLY } from "../services/access.js";
44
45
  import { brandView } from "../services/brand.js";
45
46
  import { clientMayOpen } from "../services/client-portal.js";
46
47
  import { ServiceError } from "../services/errors.js";
@@ -205,7 +206,7 @@ async function openedRun(c, runId, opts) {
205
206
  }
206
207
  const user = await principalOf(c);
207
208
  if (user && user.tenantId === run.tenantId) {
208
- // A client of the organization opens only the runs of their client spaces that are theirs
209
+ // A client of the organization opens only the runs of their spaces that are theirs
209
210
  // or shared with them (docs/plans/client-portal.md); the firm opens every run.
210
211
  if (user.role === "client" && !(await clientMayOpen(user.id, run))) {
211
212
  return null;
@@ -243,9 +244,74 @@ async function hiddenFrom(c, run) {
243
244
  }
244
245
  async function viewOf(run, hide = new Set(), caller) {
245
246
  const w = await db.query.wizard.findFirst({ where: eq(schema.wizard.id, run.wizardId) });
246
- const view = await runView(run, await brandView(w?.spaceId ?? "", run.definition.themes), hide);
247
+ const view = await runView(run, await brandView(w?.spaceId ?? "", run.definition.themes), hide, caller);
247
248
  return caller ? viewFor(view, run, caller) : view;
248
249
  }
250
+ /**
251
+ * A wizard's connection that is a connection of the space: the run's person signs in to it
252
+ * themselves, as from their menu, with what that connection takes. Only the person whose run it
253
+ * is, signed in to the organization; whether it is open to them the space's own rules say
254
+ * (`allowSignIn`). Null: the connection is the wizard's own.
255
+ */
256
+ async function spaceSignIn(c, run, connection) {
257
+ if (!connection.spaceConnection) {
258
+ return null;
259
+ }
260
+ const row = await spaceConnectionOf(await spaceIdOf(run), connection.spaceConnection);
261
+ if (!row || row.connectorId !== c.req.param("connectorId")) {
262
+ throw new HTTPException(404, { res: c.json(notFoundAnswer(c), 404) });
263
+ }
264
+ const user = await principalOf(c);
265
+ if (!(user && user.tenantId === run.tenantId && user.id === run.userId)) {
266
+ throw new HTTPException(403, { res: refuse(c, { code: "connectionNotForYou" }, 403) });
267
+ }
268
+ return {
269
+ id: row.id,
270
+ connectorId: row.connectorId,
271
+ as: { as: "person", userId: user.id, role: user.role },
272
+ };
273
+ }
274
+ /** Whether a connect from the run is for the space (decision 2 in docs/plans/run-connections.md). */
275
+ async function wantsForSpace(c) {
276
+ const body = await c.req.json().catch(() => ({}));
277
+ return z
278
+ .object({
279
+ forSpace: z.boolean().optional().default(false),
280
+ values: z.record(z.string(), z.string().max(500)).optional(),
281
+ })
282
+ .parse(body ?? {});
283
+ }
284
+ /**
285
+ * An admin of the space connects the account for the space from the run they run themselves: a
286
+ * connection of the space, signed in as the space, and the space's choice for the need. Nobody
287
+ * else, never a guest. Returns the connection to sign in, as the space.
288
+ */
289
+ async function spaceConnectionFromRun(c, run, connection) {
290
+ const user = await principalOf(c);
291
+ const admin = user &&
292
+ user.tenantId === run.tenantId &&
293
+ user.id === run.userId &&
294
+ isAdminRole(user.role) &&
295
+ !connection.spaceConnection &&
296
+ (await runConnectionsOn());
297
+ if (!admin) {
298
+ throw new HTTPException(403, { res: refuse(c, MEMBERS_EDIT_ONLY, 403) });
299
+ }
300
+ const spaceId = await spaceIdOf(run);
301
+ const home = run.clientSpaceId ?? spaceId;
302
+ const connector = await connectorFor(connection, c.req.param("connectorId") ?? "", spaceId);
303
+ const kept = await spaceConnectorFor(home, connector.id);
304
+ if (!kept) {
305
+ throw new HTTPException(404, { res: c.json(notFoundAnswer(c), 404) });
306
+ }
307
+ const row = await asRole(user.role, () => spaceConnectionForNeed(user.id, home, {
308
+ wizardId: run.wizardId,
309
+ id: connection.id,
310
+ name: connection.title ?? connector.name,
311
+ holder: scopeOf(run).holder,
312
+ }, kept));
313
+ return { id: row.id, role: user.role };
314
+ }
249
315
  /**
250
316
  * Who may use "Continue now" and "Stop": the owner and the admins of the organization, and on a
251
317
  * test run whoever started it. The wait of a live run may be meant, and stays theirs.
@@ -1422,6 +1488,25 @@ export const runRoutes = new Hono()
1422
1488
  if (!run || !connection) {
1423
1489
  return c.json(notFoundAnswer(c), 404);
1424
1490
  }
1491
+ const space = await spaceSignIn(c, run, connection);
1492
+ if (space) {
1493
+ return c.json({
1494
+ url: await startSpaceConnectionOAuth(space.id, space.as, requestLang(c), run.id),
1495
+ });
1496
+ }
1497
+ if ((await wantsForSpace(c)).forSpace) {
1498
+ try {
1499
+ const made = await spaceConnectionFromRun(c, run, connection);
1500
+ const url = await asRole(made.role, () => startSpaceConnectionOAuth(made.id, { as: "space" }, requestLang(c), run.id));
1501
+ return c.json({ url });
1502
+ }
1503
+ catch (err) {
1504
+ if (err instanceof ServiceError) {
1505
+ return c.json(err.toJSON(requestLang(c)), err.status);
1506
+ }
1507
+ throw err;
1508
+ }
1509
+ }
1425
1510
  try {
1426
1511
  const url = await startOAuth(scopeOf(run), await spaceIdOf(run), run.id, connection, c.req.param("connectorId"), requestLang(c));
1427
1512
  return c.json({ url });
@@ -1440,12 +1525,32 @@ export const runRoutes = new Hono()
1440
1525
  if (!run || !connection) {
1441
1526
  return c.json(notFoundAnswer(c), 404);
1442
1527
  }
1443
- const { values } = z
1444
- .object({ values: z.record(z.string(), z.string().max(500)) })
1445
- .parse(await c.req.json());
1528
+ const { values = {}, forSpace } = await wantsForSpace(c);
1529
+ const space = await spaceSignIn(c, run, connection);
1530
+ if (space) {
1531
+ const { label } = await signInWithCredentials(space.id, space.as, values);
1532
+ await signedIn(run.id);
1533
+ return c.json({ ok: true, label });
1534
+ }
1535
+ if (forSpace) {
1536
+ try {
1537
+ const made = await spaceConnectionFromRun(c, run, connection);
1538
+ const { label } = await asRole(made.role, () => signInWithCredentials(made.id, { as: "space" }, values));
1539
+ signalChanged(run.id);
1540
+ await signedIn(run.id);
1541
+ return c.json({ ok: true, label });
1542
+ }
1543
+ catch (err) {
1544
+ if (err instanceof ServiceError) {
1545
+ return c.json(err.toJSON(requestLang(c)), err.status);
1546
+ }
1547
+ throw err;
1548
+ }
1549
+ }
1446
1550
  try {
1447
1551
  const label = await connectWithCredentials(scopeOf(run), spaceId, connection, c.req.param("connectorId"), values);
1448
1552
  signalChanged(run.id);
1553
+ await signedIn(run.id);
1449
1554
  return c.json({ ok: true, label });
1450
1555
  }
1451
1556
  catch (err) {
@@ -1454,6 +1559,38 @@ export const runRoutes = new Hono()
1454
1559
  }
1455
1560
  throw err;
1456
1561
  }
1562
+ })
1563
+ // The provider's window said the person signed in: a run that waits for it looks again now.
1564
+ .post("/:id/signed-in", async (c) => {
1565
+ const run = await accessibleRun(c, c.req.param("id"));
1566
+ if (!run) {
1567
+ return c.json(notFoundAnswer(c), 404);
1568
+ }
1569
+ signalChanged(run.id);
1570
+ await signedIn(run.id);
1571
+ return c.json({ ok: true });
1572
+ })
1573
+ // The person picks which account the wizard uses for a need: on the card, or to change it.
1574
+ // The choice is theirs alone: someone reading along (an admin too) changes nothing.
1575
+ .put("/:id/connections/:connectionId/choice", async (c) => {
1576
+ const run = await accessibleRun(c, c.req.param("id"));
1577
+ const spaceId = run ? await spaceIdOf(run) : "";
1578
+ const connection = run ? await findConnection(run, c.req.param("connectionId"), spaceId) : null;
1579
+ if (!run || !connection) {
1580
+ return c.json(notFoundAnswer(c), 404);
1581
+ }
1582
+ if (!ownsRun(run, await callerOf(c, run))) {
1583
+ return refuse(c, { code: "connectionNotForYou" }, 403);
1584
+ }
1585
+ const pick = z
1586
+ .object({ owner: z.enum(["person", "space"]), id: z.string().min(1).max(100) })
1587
+ .parse(await c.req.json());
1588
+ if (!(await choose(scopeOf(run), spaceId, connection, pick))) {
1589
+ return c.json(notFoundAnswer(c), 404);
1590
+ }
1591
+ signalChanged(run.id);
1592
+ await signedIn(run.id);
1593
+ return c.json({ ok: true });
1457
1594
  })
1458
1595
  .delete("/:id/connections/:connectionId", async (c) => {
1459
1596
  const run = await accessibleRun(c, c.req.param("id"));
@@ -1555,13 +1692,14 @@ export const runRoutes = new Hono()
1555
1692
  title: null,
1556
1693
  description: null,
1557
1694
  account: { connector: x.provider, label: x.label, connectedAt: x.createdAt },
1695
+ candidates: [],
1558
1696
  connectors: [],
1559
1697
  }));
1560
1698
  return c.json({
1561
1699
  lists,
1562
1700
  files: await storeFiles(scope),
1563
1701
  connections: [
1564
- ...(await connectionViews(run.definition.connections ?? [], scope, await spaceIdOf(run), requestLang(c))).filter((x) => x.account),
1702
+ ...(await connectionViews(run.definition.connections ?? [], scope, await spaceIdOf(run), requestLang(c))).filter((x) => x.account || x.candidates.length),
1565
1703
  ...forSharing,
1566
1704
  ],
1567
1705
  keepsSignIns: secrets.some((s) => s.slot === "browser"),
@@ -1797,11 +1935,19 @@ export const connectCallback = new Hono().get("/callback", async (c) => {
1797
1935
  await withTenant(tenant, () => finishPluginOAuth(answer, state));
1798
1936
  }
1799
1937
  else if (spaceTenant) {
1800
- await withTenant(tenant, () => finishSpaceConnectionOAuth(answer, state));
1938
+ const done = await withTenant(tenant, () => finishSpaceConnectionOAuth(answer, state));
1939
+ // Signed in from a run's connect card: the run looks again now.
1940
+ if (done.runId) {
1941
+ const runId = done.runId;
1942
+ signalChanged(runId);
1943
+ await withTenant(tenant, () => signedIn(runId)).catch((err) => console.error("[connect] wake", err));
1944
+ }
1801
1945
  }
1802
1946
  else {
1803
1947
  const done = await withTenant(tenant, () => finishOAuth(answer, state));
1804
1948
  signalChanged(done.runId);
1949
+ // The account is kept: a wake that fails leaves the run to its next look.
1950
+ await withTenant(tenant, () => signedIn(done.runId)).catch((err) => console.error("[connect] wake", err));
1805
1951
  }
1806
1952
  ok = true;
1807
1953
  said = { code: "connected" };
@@ -5,7 +5,7 @@ import { LANGS, MODEL_CLASSES, TEXT_CLASSES, } from "@engenty/wizards-shared/def
5
5
  import { CATEGORY_TYPES, whereSchema } from "@engenty/wizards-shared/knowledge";
6
6
  import { PRESENCE_KINDS } from "@engenty/wizards-shared/live";
7
7
  import { CLASS_NAMES, isCreditsRef, modelLabel } from "@engenty/wizards-shared/providers";
8
- import { note } from "@engenty/wizards-shared/run";
8
+ import { note, saidText } from "@engenty/wizards-shared/run";
9
9
  import { AUDIENCES } from "@engenty/wizards-shared/rwx";
10
10
  import { SPACE_FILE_KINDS } from "@engenty/wizards-shared/spaces";
11
11
  import { MAX_MASK_LABEL_CHARS, MAX_MASK_LABELS, modelPolicySchema, } from "@engenty/wizards-shared/tiers";
@@ -26,11 +26,13 @@ import { assertRwx, folderAudience, setFolderAudience, subjectsOfPerson } from "
26
26
  import { appStates, connectApps } from "../cli/connect.js";
27
27
  import { layout } from "../cli/home.js";
28
28
  import { actionKindsPatchSchema, connectorImportSchema, connectorPreviewSchema, importConnector, previewSource, registryService, removeConnector, searchRegistry, setActionKinds, } from "../connectors/external.js";
29
+ import { unwatchedScope } from "../connectors/person-connections.js";
29
30
  import { reloadConnector } from "../connectors/reload.js";
31
+ import { chooseForSpace, clearForSpace, wizardNeeds } from "../connectors/space-choice.js";
30
32
  import { balanceCredits, canSpend } from "../credits/credits.js";
31
33
  import { estimateRun } from "../credits/estimate.js";
32
34
  import { listNotices, markNoticesRead } from "../engine/notices.js";
33
- import { missingModels, stepsWithoutModel } from "../engine/requirements.js";
35
+ import { missingConnections, missingModels, stepsWithoutModel, unwatchedConnectionsSaid, } from "../engine/requirements.js";
34
36
  import { env } from "../env.js";
35
37
  import { feature, features, forgetAccountFeatures } from "../features.js";
36
38
  import { appleStatus } from "../harness/apple.js";
@@ -655,9 +657,10 @@ export const studio = new Hono()
655
657
  .object({
656
658
  name: z.string().min(1).max(80),
657
659
  access: z.enum(["all", "members"]).default("all"),
660
+ kind: z.enum(["space", "client"]).default("space"),
658
661
  })
659
662
  .parse(await c.req.json());
660
- return c.json(await createSpace(c.get("user").id, body.name, body.access));
663
+ return c.json(await createSpace(c.get("user").id, body.name, body.access, body.kind));
661
664
  })
662
665
  .patch("/spaces/:id", async (c) => {
663
666
  const patch = spacePatchSchema.parse(await c.req.json());
@@ -1395,10 +1398,44 @@ export const studio = new Hono()
1395
1398
  const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1396
1399
  return c.json(await wizardRunners(w));
1397
1400
  })
1398
- // The models the draft needs that this runtime cannot serve, by class, with the steps that call them.
1401
+ // The models the draft needs that this runtime cannot serve, by class, with the steps that call
1402
+ // them; and its connections whose connectors can't connect here. An admin reads what the
1403
+ // server's owner has to set.
1399
1404
  .get("/wizards/:id/models", async (c) => {
1405
+ const user = c.get("user");
1406
+ const w = await ownedWizard(user.id, c.req.param("id"));
1407
+ const lang = requestLang(c);
1408
+ // A start nobody owns runs with nobody there: it needs the space's choice for each need.
1409
+ const unwatched = w.starts.some((s) => s.on && !s.owner)
1410
+ ? await unwatchedConnectionsSaid(w.draft, unwatchedScope(w.id), w.spaceId)
1411
+ : [];
1412
+ return c.json({
1413
+ missing: await missingModels(w.draft, lang),
1414
+ connections: [
1415
+ ...(await missingConnections(w.draft, w.spaceId, lang, isAdminRole(user.role))),
1416
+ ...unwatched.map((m) => ({ ...m, problem: saidText(m.problem, lang) })),
1417
+ ],
1418
+ });
1419
+ })
1420
+ // The wizard's needs (docs/plans/run-connections.md, step 4): how each resolves for the person
1421
+ // looking; for the space's admins also the space's choice for runs nobody watches.
1422
+ .get("/wizards/:id/needs", async (c) => {
1423
+ const user = c.get("user");
1424
+ const w = await ownedWizard(user.id, c.req.param("id"));
1425
+ return c.json({
1426
+ needs: await wizardNeeds(w, { userId: user.id, admin: isAdminRole(user.role) }, requestLang(c)),
1427
+ });
1428
+ })
1429
+ .put("/wizards/:id/needs/:need/space-choice", async (c) => {
1400
1430
  const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1401
- return c.json({ missing: await missingModels(w.draft, requestLang(c)) });
1431
+ const { connection } = z.object({ connection: z.string().min(1) }).parse(await c.req.json());
1432
+ await chooseForSpace(w, c.req.param("need"), connection);
1433
+ return c.json({ ok: true });
1434
+ })
1435
+ .delete("/wizards/:id/needs/:need/space-choice", async (c) => {
1436
+ const w = await ownedWizard(c.get("user").id, c.req.param("id"));
1437
+ await clearForSpace(w, c.req.param("need"));
1438
+ return c.json({ ok: true });
1402
1439
  })
1403
1440
  // A runtime that runs alone: the wizard's copy in the cloud of the linked account.
1404
1441
  .get("/wizards/:id/cloud", async (c) => {
@@ -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 client spaces and the broker on. */
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 || !featureOn(features, "broker")) {
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
- /** One of the client's client spaces, with its parent. */
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
- const parent = row?.space.parentId
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, parent };
56
+ return { space: row.space, sources: [row.space.id, row.space.parentId] };
54
57
  }
55
- /** Whether the person is one of the client space's clients. */
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
- * by the firm. The run's own routes ask it too (routes/runs.ts).
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 firm's brand, as its space shows it: the client portal wears it. */
76
- async function firmBrand(parentId) {
77
- const brand = await brandView(parentId);
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 client's client spaces, each with the firm's space and brand. */
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
- // A client space, or with `orgSpaces` any space under the root shared with them: both have a
102
- // parent whose brand the portal wears.
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
- // --- wizards ---------------------------------------------------------------------------------
120
- /** The parent's published wizards the firm opened to its clients: read and run. */
121
- async function openWizards(who, parent) {
122
- const published = (await listWizards(who.id, parent.id)).filter((w) => w.published);
123
- const ids = published.map((w) => w.id);
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 w of published) {
127
- if (readable.has(w.id) &&
128
- (await decide(parent.id, clientSubjects(who), { kind: "wizard", id: w.id }, "x")).ok) {
129
- open.push(w);
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.map((w) => ({
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 { parent } = await clientSpace(who, spaceId);
142
- return openWizards(who, parent);
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 client space: the wizard is the parent's, the run the
146
- * client space's. A line of the audit like every element call.
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, parent } = await clientSpace(who, spaceId);
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: parent.id,
169
+ rulesIn: sources.includes(home) ? home : space.id,
161
170
  perm: "x",
162
171
  input: { wizardId },
163
172
  }, async () => {
164
- if (!(await openWizards(who, parent)).some((w) => w.id === wizardId)) {
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, parent } = await clientSpace(who, spaceId);
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, parent),
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.