@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
@@ -4,7 +4,7 @@ import { isTextMime } from "@engenty/wizards-shared/workspace";
4
4
  import { Agent } from "@mastra/core/agent";
5
5
  import { createTool } from "@mastra/core/tools";
6
6
  import { z } from "zod";
7
- import { exampleWizard, spaceLines, } from "../authoring/guide.js";
7
+ import { exampleWizard, guideMail, spaceLines, } from "../authoring/guide.js";
8
8
  import { wizardOpSchema } from "../authoring/ops.js";
9
9
  import { importFromRegistry, listConnectors, searchRegistry } from "../connectors/external.js";
10
10
  import { guideSpaceConnections } from "../connectors/space-connections.js";
@@ -26,7 +26,7 @@ import { attempt as attemptTool, imageOutput } from "../tools/shared.js";
26
26
  import { runScript } from "../widgets/script.js";
27
27
  import { thoughtLine } from "./thought.js";
28
28
  const MAX_STEPS = 45;
29
- function systemPrompt(connectors, pluginTools, connections, startsOn, on) {
29
+ function systemPrompt(connectors, mail, pluginTools, connections, startsOn, on) {
30
30
  return `${prompt("architect", "system", {
31
31
  persona: prompt("architect", "persona"),
32
32
  starts: startsOn ? prompt("architect", "starts") : "",
@@ -36,7 +36,7 @@ function systemPrompt(connectors, pluginTools, connections, startsOn, on) {
36
36
  principles: prompt("authoring", "principles", { sandbox: sandboxGuideLine() }),
37
37
  widgets: prompt("authoring", "widgets"),
38
38
  surfaces: prompt("authoring", "surfaces"),
39
- space_tools: spaceLines(connectors, pluginTools, connections),
39
+ space_tools: spaceLines(connectors, mail, pluginTools, connections),
40
40
  example: exampleWizard(),
41
41
  how_you_work: prompt("architect", "how_you_work"),
42
42
  })}\n\n${contentPolicy()}`;
@@ -352,7 +352,7 @@ export async function runArchitect(input) {
352
352
  // The system prompt is long and identical on every turn: cache it.
353
353
  instructions: {
354
354
  role: "system",
355
- content: systemPrompt(input.connectors, await pluginToolsOf(currentTenant()), await guideSpaceConnections(w.spaceId), startsOn, features),
355
+ content: systemPrompt(input.connectors, await guideMail(), await pluginToolsOf(currentTenant()), await guideSpaceConnections(w.spaceId), startsOn, features),
356
356
  providerOptions: { anthropic: { cacheControl: { type: "ephemeral" } } },
357
357
  },
358
358
  model: agentModel(resolved),
@@ -190,7 +190,7 @@ async function spaceState(userId, role, spaceId) {
190
190
  })),
191
191
  };
192
192
  }
193
- export function gooseSpaceTools(input, space, wrote, on) {
193
+ export function gooseSpaceTools(input, space, wrote) {
194
194
  const { signal } = input;
195
195
  const userId = input.user.id;
196
196
  const spaceId = space.id;
@@ -340,9 +340,6 @@ export function gooseSpaceTools(input, space, wrote, on) {
340
340
  }),
341
341
  execute: ({ colors, sections }) => attempt(() => inTurn(async () => {
342
342
  doing("set_colors");
343
- if (!on.brandSections && (sections || colors.some((c) => c.section))) {
344
- throw new Error("Colour sections are not available in this studio: pass the colours without them.");
345
- }
346
343
  const p = await ownedSpace(userId, spaceId);
347
344
  const groups = sections
348
345
  ? sections.map((s) => ({
@@ -664,16 +661,6 @@ export function gooseSpaceTools(input, space, wrote, on) {
664
661
  toModelOutput: imageOutput("image", (rest) => String(rest.name)),
665
662
  }),
666
663
  };
667
- if (!on.brandSections) {
668
- delete tools.set_logo_sections;
669
- delete tools.set_gradients;
670
- }
671
- if (!on.brandRules) {
672
- delete tools.set_rules;
673
- }
674
- if (!on.typography) {
675
- delete tools.set_typography;
676
- }
677
664
  // Every write to the space's setup is the broker's: `w` on it, for Goose for its person
678
665
  // (docs/plans/modular.md, B4). An admin's deny for Goose stops it; each write is a log line.
679
666
  for (const name of SETUP_WRITES) {
@@ -818,11 +805,6 @@ export async function runStudioAssistant(input) {
818
805
  const { space } = input;
819
806
  const writable = space && input.writable ? space : null;
820
807
  const switches = await currentFeatures();
821
- const brandOn = {
822
- brandSections: switches.brandSections === true,
823
- brandRules: switches.brandRules === true,
824
- typography: switches.typography === true,
825
- };
826
808
  const tools = {
827
809
  ...knowsTools({
828
810
  user: input.user,
@@ -835,7 +817,7 @@ export async function runStudioAssistant(input) {
835
817
  input.onCard?.(card);
836
818
  },
837
819
  }),
838
- ...(writable ? gooseSpaceTools(input, writable, wrote, brandOn) : {}),
820
+ ...(writable ? gooseSpaceTools(input, writable, wrote) : {}),
839
821
  };
840
822
  // On everyday effort the chat can offer extra effort for work that asks for more: a card with
841
823
  // a button, while it goes on answering.
@@ -1038,17 +1020,6 @@ export async function runStudioAssistant(input) {
1038
1020
  : part === "skills"
1039
1021
  ? prompt("goose", "turn.skills_empty")
1040
1022
  : "",
1041
- writable && !(brandOn.brandSections && brandOn.brandRules && brandOn.typography)
1042
- ? prompt("goose", "turn.off", {
1043
- missing: [
1044
- brandOn.brandSections ? "" : "sections of logos and colours, gradients and patterns",
1045
- brandOn.brandRules ? "" : "rules for logos, colours and type",
1046
- brandOn.typography ? "" : "typography (fonts, type scale)",
1047
- ]
1048
- .filter(Boolean)
1049
- .join("; "),
1050
- })
1051
- : "",
1052
1023
  input.message,
1053
1024
  ]
1054
1025
  .filter(Boolean)
@@ -250,7 +250,7 @@ if (serves.doors) {
250
250
  ]);
251
251
  });
252
252
  }
253
- /** What a client of the organization may ask the studio's routes for: who they are, their client spaces. */
253
+ /** What a client of the organization may ask the studio's routes for: who they are, their spaces. */
254
254
  const CLIENT_OPEN = /\/api\/studio\/(me|spaces)$/;
255
255
  /** The studio's requests that open an item: a wizard, a page, a table, a skill, a space. */
256
256
  const STUDIO_LOADS = /\/api\/studio\/(wizards\/[^/]+|pages\/[^/]+|tables\/[^/]+|skills\/[^/]+|spaces(\/[^/]+(\/(data|knowledge|files|wizards|page|skills))?)?)$/;
@@ -304,8 +304,8 @@ if (serves.studio) {
304
304
  });
305
305
  // A member reaches a space's studio only where its admins opened it (behind `capabilities`).
306
306
  app.use("/api/studio/*", membersStudioGate);
307
- // A client of the organization reaches no Studio and no Work (docs/plans/client-spaces.md):
308
- // who they are and their own client spaces, until the client portal brings its own routes.
307
+ // A client of the organization reaches no Studio and no Work (docs/plans/org-spaces.md):
308
+ // who they are and their client spaces, until the client portal brings its own routes.
309
309
  app.use("/api/studio/*", async (c, next) => {
310
310
  const user = c.get("user");
311
311
  if (user?.role !== "client" || (c.req.method === "GET" && CLIENT_OPEN.test(c.req.path))) {
@@ -319,7 +319,7 @@ if (serves.api) {
319
319
  const mcp = mcpHandler();
320
320
  app.on(["GET", "POST", "DELETE"], "/api/mcp", (c) => mcp(c.req.raw));
321
321
  app.route("/api/v1", elementRoutes);
322
- // The client contract: a client's own client spaces, for the client portal.
322
+ // The client contract: a client's client spaces, for the client portal.
323
323
  app.route("/api/v1", clientContractRoutes);
324
324
  app.route("/api/v1", apiRoutes);
325
325
  }
@@ -2,7 +2,7 @@ import { createTool } from "@mastra/core/tools";
2
2
  import { and, desc, eq, inArray } from "drizzle-orm";
3
3
  import { z } from "zod";
4
4
  import { accountOverview, accountToken, linkedAccount } from "../auth/account.js";
5
- import { authoringGuide } from "../authoring/guide.js";
5
+ import { authoringGuide, guideMail } from "../authoring/guide.js";
6
6
  import { listConnectors } from "../connectors/external.js";
7
7
  import { guideSpaceConnections } from "../connectors/space-connections.js";
8
8
  import { db, schema } from "../db/client.js";
@@ -71,7 +71,7 @@ export function knowsTools(ctx) {
71
71
  inputSchema: z.object({ from: z.number().int().min(0).optional() }),
72
72
  execute: ({ from }) => attempt(async () => {
73
73
  ctx.doing(serverText(ctx.lang, "doingAuthoringGuide"));
74
- const guide = authoringGuide(ctx.space ? await listConnectors(ctx.space.id) : [], await pluginToolsOf(user.tenantId), ctx.space ? await guideSpaceConnections(ctx.space.id) : [], await currentFeatures());
74
+ const guide = authoringGuide(ctx.space ? await listConnectors(ctx.space.id) : [], await guideMail(), await pluginToolsOf(user.tenantId), ctx.space ? await guideSpaceConnections(ctx.space.id) : [], await currentFeatures());
75
75
  const start = Math.min(from ?? 0, guide.length);
76
76
  return {
77
77
  text: guide.slice(start, start + 14_000),
@@ -401,7 +401,7 @@ export const authRoutes = new Hono()
401
401
  impersonatedBy: admin?.id ?? null,
402
402
  impersonatorEmail: admin?.email ?? null,
403
403
  });
404
- // A client's first sign-in: the client spaces that invited their address take them in.
404
+ // A client's first sign-in: the spaces that invited their address take them in.
405
405
  if (claims.role === "client" && !admin) {
406
406
  await withTenant(claims.tenantId, () => claimClientInvites(claims.userId, claims.email)).catch((err) => console.error("[clients] claiming invitations:", err));
407
407
  }
@@ -3,7 +3,7 @@
3
3
  * the guide's own, not a marketplace entry, so the guide never depends on the marketplace.
4
4
  */
5
5
  export const EXAMPLE_WIZARD = {
6
- version: 1,
6
+ version: "0.2.0",
7
7
  title: "X post with an image",
8
8
  description: "Turns a topic into a finished post with an image.",
9
9
  avatar: "flame",
@@ -1,7 +1,18 @@
1
1
  import { WIZARD_SCHEMA_URL } from "@engenty/wizards-shared/wizard-package";
2
+ import { MAIL_CONNECTORS, missingSetup, usable } from "../connectors/builtin.js";
2
3
  import { prompt } from "../prompts.js";
3
4
  import { sandboxGuideLine } from "../sandbox/index.js";
4
5
  import { EXAMPLE_WIZARD } from "./example.js";
6
+ /** After a connector that can't connect here: that it can't, and what the server's owner sets. */
7
+ function notSetUp(c) {
8
+ if (c.usable) {
9
+ return "";
10
+ }
11
+ const settings = c.missingSetup
12
+ ? ` ${prompt("authoring", "line.connectors.settings", { settings: c.missingSetup })}`
13
+ : "";
14
+ return ` — ${prompt("authoring", "line.connectors.not_set_up")}${settings}`;
15
+ }
5
16
  function connectorsLine(connectors) {
6
17
  const lines = connectors.map((c) => {
7
18
  const actions = c.actions
@@ -9,11 +20,25 @@ function connectorsLine(connectors) {
9
20
  .map((a) => `${a.id}${a.group === "read" ? "" : ` (${a.group})`}`)
10
21
  .join(", ");
11
22
  const more = c.actions.length > 40 ? `, … ${c.actions.length - 40} more (list_connectors)` : "";
12
- const state = c.usable ? "" : ` — ${prompt("authoring", "line.connectors.not_set_up")}`;
13
- return `- ${c.id} — ${c.name}${state}, tools ${c.toolPrefix}_*: ${actions || prompt("authoring", "line.connectors.no_actions")}${more}`;
23
+ return `- ${c.id} — ${c.name}${notSetUp(c)}, tools ${c.toolPrefix}_*: ${actions || prompt("authoring", "line.connectors.no_actions")}${more}`;
14
24
  });
15
25
  return prompt("authoring", "line.connectors", { connectors: lines.join("\n") });
16
26
  }
27
+ /** The connectors behind kind "mail" on this server, each with whether it connects. */
28
+ export async function guideMail() {
29
+ return Promise.all(MAIL_CONNECTORS.map(async (c) => {
30
+ const ready = await usable(c);
31
+ return { name: c.name, usable: ready, missingSetup: ready ? null : missingSetup(c) };
32
+ }));
33
+ }
34
+ /** How kind "mail" connects here: one line per connector. */
35
+ function mailLine(mail) {
36
+ if (!mail.length) {
37
+ return "";
38
+ }
39
+ const lines = mail.map((c) => `- ${c.name}${notSetUp(c)}`);
40
+ return prompt("authoring", "line.connectors.mail", { connectors: lines.join("\n") });
41
+ }
17
42
  function spaceConnectionsLine(connections) {
18
43
  if (!connections.length) {
19
44
  return "";
@@ -36,10 +61,14 @@ function pluginToolsLine(tools) {
36
61
  const lines = tools.map((t) => `- ${t.id} — ${t.description}`);
37
62
  return prompt("authoring", "line.plugin_tools", { tools: lines.join("\n") });
38
63
  }
39
- /** What the space offers agent steps: its connectors, its connections and plugin tools. */
40
- export function spaceLines(connectors, pluginTools, connections = []) {
64
+ /**
65
+ * What the space offers agent steps: its connectors, how kind "mail" connects here, its
66
+ * connections and plugin tools.
67
+ */
68
+ export function spaceLines(connectors, mail, pluginTools, connections = []) {
41
69
  return [
42
70
  connectorsLine(connectors),
71
+ mailLine(mail),
43
72
  spaceConnectionsLine(connections),
44
73
  pluginToolsLine(pluginTools),
45
74
  ]
@@ -50,7 +79,7 @@ export function exampleWizard() {
50
79
  return JSON.stringify(EXAMPLE_WIZARD, null, 2);
51
80
  }
52
81
  /** The guide an MCP client reads before it writes a wizard. */
53
- export function authoringGuide(connectors = [], pluginTools = [], connections = [],
82
+ export function authoringGuide(connectors = [], mail = [], pluginTools = [], connections = [],
54
83
  /** Switches whose part of the format is in the guide only while a run can do it. */
55
84
  on = {}) {
56
85
  return prompt("authoring", "guide", {
@@ -60,7 +89,7 @@ on = {}) {
60
89
  principles: prompt("authoring", "principles", { sandbox: sandboxGuideLine() }),
61
90
  widgets: prompt("authoring", "widgets"),
62
91
  surfaces: prompt("authoring", "surfaces"),
63
- space_tools: spaceLines(connectors, pluginTools, connections),
92
+ space_tools: spaceLines(connectors, mail, pluginTools, connections),
64
93
  schema_url: WIZARD_SCHEMA_URL,
65
94
  example: exampleWizard(),
66
95
  });
@@ -1,35 +1,93 @@
1
1
  import { and, eq } from "drizzle-orm";
2
2
  import { connectorFetch, resolveEnv, signInFetch } from "../connectors/builtin.js";
3
- import { candidates, connectorFor, open, slot, } from "../connectors/index.js";
3
+ import { candidates, open } from "../connectors/index.js";
4
+ import { connectionsFor, remember, runConnectionsOn } from "../connectors/person-connections.js";
5
+ import { sameService } from "../connectors/same-service.js";
6
+ import { listSpaceConnections, } from "../connectors/space-connections.js";
4
7
  import { refreshThroughAccount } from "../connectors/via-account.js";
5
8
  import { db, schema } from "../db/client.js";
6
9
  import { refreshAccessToken } from "../engenty/connections-sdk/oauth2.js";
7
10
  import { seal, unseal } from "../secrets/crypto.js";
8
- import { getSecret, putSecret } from "../store/index.js";
11
+ import { getSecret } from "../store/index.js";
9
12
  import { currentTenant } from "../tenants/tenant.js";
13
+ import { spaceRulesOf } from "./call.js";
10
14
  /**
11
- * The account a wizard's connection (or a share target's) holds for this store: the person who
12
- * runs the wizard connected it. `null` when nothing is connected.
15
+ * The account a wizard's connection (or a share target's) uses in this run: the person's own
16
+ * connection the lookup finds (`connectionsFor`). The only candidate is remembered once used.
17
+ * `null` when there is none to use. A connection of the space is resolved before
18
+ * (`heldConnection`), so that its rules count.
13
19
  */
14
20
  export async function wizardAccount(scope, connection, spaceId) {
15
- const stored = await getSecret(scope, slot(connection.id));
16
- if (!stored) {
21
+ const found = await connectionsFor(scope, spaceId, connection);
22
+ const chosen = found.chosen?.kind === "person" ? found.chosen : null;
23
+ if (!chosen) {
17
24
  const only = connection.connector ? (await candidates(connection, spaceId))[0] : undefined;
18
- return only && open(only)
25
+ return !found.chosen && only && open(only)
19
26
  ? { connector: only, label: only.name, ctx: actionContext(scope, connection, only, "{}", []) }
20
27
  : null;
21
28
  }
22
- const connector = await connectorFor(connection, stored.provider, spaceId);
23
- let data = stored.data;
29
+ const row = await db.query.personConnection.findFirst({
30
+ where: eq(schema.personConnection.id, chosen.row.id),
31
+ });
32
+ let data = row ? unseal(row.secret) : null;
33
+ if (!data) {
34
+ throw new Error("The connection's keys cannot be read here. Connect it again.");
35
+ }
36
+ if (found.by === "only") {
37
+ await remember(scope.wizardId, connection.id, scope.holder, chosen);
38
+ }
39
+ const { connector } = chosen;
24
40
  const fresh = await refreshed(connector, data);
25
41
  if (fresh) {
26
42
  data = fresh;
27
- await putSecret(scope, slot(connection.id), connector.id, stored.label, data);
43
+ await db
44
+ .update(schema.personConnection)
45
+ .set({ secret: seal(data), updatedAt: new Date() })
46
+ .where(eq(schema.personConnection.id, chosen.row.id));
28
47
  }
29
48
  return {
30
49
  connector,
31
- label: stored.label,
32
- ctx: actionContext(scope, connection, connector, data.accessToken, data.scopes, stored),
50
+ label: chosen.row.label,
51
+ ctx: actionContext(scope, connection, connector, data.accessToken, data.scopes, chosen.row),
52
+ person: true,
53
+ };
54
+ }
55
+ /**
56
+ * The space's rules for a person's own account of this connector used in a run of the space
57
+ * (behind `runConnections`): those of the space's connections of the same connector or the same
58
+ * service, read on every call so that a pause or a changed rule binds at once. Null where the
59
+ * space has none, or the switch is off: the wizard's `policy` counts then.
60
+ */
61
+ export async function spaceRulesFor(spaceId, connectorId) {
62
+ if (!(await runConnectionsOn())) {
63
+ return null;
64
+ }
65
+ const service = sameService(connectorId);
66
+ const rows = await listSpaceConnections(spaceId);
67
+ return spaceRulesOf(rows.filter((row) => service.includes(row.connectorId)));
68
+ }
69
+ /**
70
+ * A wizard's connection as the broker holds it: where the run uses a connection of the space for
71
+ * the need (behind `runConnections`), that connection, under the space's rules.
72
+ */
73
+ export async function heldConnection(connection) {
74
+ if (connection.kind !== "store_secret" || !(await runConnectionsOn())) {
75
+ return connection;
76
+ }
77
+ const found = await connectionsFor(connection.scope, connection.spaceId, connection.def);
78
+ if (found.chosen?.kind !== "space") {
79
+ return connection;
80
+ }
81
+ if (found.by === "only") {
82
+ await remember(connection.scope.wizardId, connection.def.id, connection.scope.holder, found.chosen);
83
+ }
84
+ return {
85
+ kind: "space_connection",
86
+ row: found.chosen.row,
87
+ connector: found.chosen.connector,
88
+ need: connection.def,
89
+ // `connectionsFor` gives a run nobody watches only the space's choice.
90
+ ...(connection.scope.unwatched ? { chosenForUnwatched: true } : {}),
33
91
  };
34
92
  }
35
93
  function actionContext(scope, connection, connector, accessToken, scopes, stored) {
@@ -80,8 +138,18 @@ async function refreshed(connector, data) {
80
138
  scopes: tokens.grantedScopes.length ? tokens.grantedScopes : data.scopes,
81
139
  };
82
140
  }
83
- /** Whose sign-in a `person` connection opens for: a person, an admin, or Goose for its person. */
84
- const signsInThemselves = (who) => (who.kind === "person" || who.kind === "admin" || who.kind === "goose") && Boolean(who.id);
141
+ /**
142
+ * Whose sign-in a `person` connection opens for: a person, an admin, Goose for its person, or a
143
+ * fixed step for the person its run is held for. A guest, or a step nobody's run, has none.
144
+ */
145
+ function signedInAs(who) {
146
+ const asked = who.kind === "step" ? who.for : who;
147
+ return asked &&
148
+ (asked.kind === "person" || asked.kind === "admin" || asked.kind === "goose") &&
149
+ asked.id
150
+ ? asked.id
151
+ : null;
152
+ }
85
153
  /**
86
154
  * The account a connection of the space holds for this caller: the space's own sign-in, or the
87
155
  * caller's where each person signs in. `null` when nobody has signed in yet. Tokens that run out
@@ -102,11 +170,12 @@ export async function spaceAccount(row, connector, who) {
102
170
  .where(eq(schema.spaceConnection.id, row.id));
103
171
  }
104
172
  else {
105
- if (!signsInThemselves(who)) {
173
+ const userId = signedInAs(who);
174
+ if (!userId) {
106
175
  return null;
107
176
  }
108
177
  const own = await db.query.spaceConnectionSignIn.findFirst({
109
- where: and(eq(schema.spaceConnectionSignIn.connectionId, row.id), eq(schema.spaceConnectionSignIn.userId, who.id)),
178
+ where: and(eq(schema.spaceConnectionSignIn.connectionId, row.id), eq(schema.spaceConnectionSignIn.userId, userId)),
110
179
  });
111
180
  if (!own) {
112
181
  return null;