wizards 0.2.42 → 0.2.44

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/app.js +37 -3
  2. package/apps/runtime/dist/authoring/guide.js +5 -2
  3. package/apps/runtime/dist/browser/fast/action-space.js +162 -0
  4. package/apps/runtime/dist/browser/fast/classifier.js +91 -0
  5. package/apps/runtime/dist/browser/fast/decide.js +171 -0
  6. package/apps/runtime/dist/browser/fast/driver.js +141 -0
  7. package/apps/runtime/dist/browser/fast/instructions.js +33 -0
  8. package/apps/runtime/dist/browser/fast/run.js +249 -0
  9. package/apps/runtime/dist/browser/fast/span-picker.js +153 -0
  10. package/apps/runtime/dist/browser/fast/text-helper.js +178 -0
  11. package/apps/runtime/dist/browser/snapshot.js +335 -0
  12. package/apps/runtime/dist/db/migrations/tenant/0011_runners.sql +2 -0
  13. package/apps/runtime/dist/db/migrations/tenant/meta/0011_snapshot.json +2956 -0
  14. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
  15. package/apps/runtime/dist/db/schema.js +4 -0
  16. package/apps/runtime/dist/engine/resources.js +109 -0
  17. package/apps/runtime/dist/engine/runner.js +7 -3
  18. package/apps/runtime/dist/engine/steps.js +89 -10
  19. package/apps/runtime/dist/env.js +9 -0
  20. package/apps/runtime/dist/harness/claude.js +9 -1
  21. package/apps/runtime/dist/link-preview.js +4 -3
  22. package/apps/runtime/dist/mcp/tools.js +1 -1
  23. package/apps/runtime/dist/media/conversation.js +177 -0
  24. package/apps/runtime/dist/models.js +17 -0
  25. package/apps/runtime/dist/plugins/loader.js +48 -2
  26. package/apps/runtime/dist/plugins/registry.js +1 -0
  27. package/apps/runtime/dist/plugins/runs.js +205 -0
  28. package/apps/runtime/dist/routes/runs.js +206 -22
  29. package/apps/runtime/dist/routes/studio.js +12 -1
  30. package/apps/runtime/dist/services/cloud.js +1 -0
  31. package/apps/runtime/dist/services/runners.js +138 -0
  32. package/apps/runtime/dist/services/runs.js +83 -45
  33. package/apps/runtime/dist/services/wizard-icon.js +12 -0
  34. package/apps/runtime/dist/services/wizards.js +5 -1
  35. package/apps/runtime/dist/tools/browser.js +426 -97
  36. package/apps/runtime/dist/tools/index.js +50 -3
  37. package/apps/web/dist/assets/ChangelogDialog-C1_ZvuwE.js +1 -0
  38. package/apps/web/dist/assets/ChatView-DLG771z6.js +10 -0
  39. package/apps/web/dist/assets/{CreditsDialog-DPglouDr.js → CreditsDialog-Ce7Czhxq.js} +1 -1
  40. package/apps/web/dist/assets/EditorPage-CXx32-a7.js +3 -0
  41. package/apps/web/dist/assets/{FlowPreview-CQN5acxA.js → FlowPreview-DgZiepFR.js} +1 -1
  42. package/apps/web/dist/assets/{Harness-BFxUFB7B.js → Harness-ffZUxkbb.js} +2 -2
  43. package/apps/web/dist/assets/HomePage-B3RVPuUu.js +1 -0
  44. package/apps/web/dist/assets/ImportWizard-CHlCjPEo.js +1 -0
  45. package/apps/web/dist/assets/NewWizardPage-BQW7PoZq.js +2 -0
  46. package/apps/web/dist/assets/ProjectPage-D-_A4iZz.js +2 -0
  47. package/apps/web/dist/assets/PublicRunner-sbya6PXg.js +1 -0
  48. package/apps/web/dist/assets/RunDrawer-BgLxai9C.js +4 -0
  49. package/apps/web/dist/assets/RunnerView-BVm9fL62.js +2 -0
  50. package/apps/web/dist/assets/SettingsPage-Ce6k9xDs.js +1 -0
  51. package/apps/web/dist/assets/SetupPage-CLymFxat.js +1 -0
  52. package/apps/web/dist/assets/SharePage-1Ni5ejt6.js +1 -0
  53. package/apps/web/dist/assets/ThemeSwitch-DN42WOTx.js +1 -0
  54. package/apps/web/dist/assets/arrow-right-BgKM1Npq.js +1 -0
  55. package/apps/web/dist/assets/changelog-CH4sN8Dm.js +1 -0
  56. package/apps/web/dist/assets/{circle-alert-B0rwkpC7.js → circle-alert-D_6s0Xgw.js} +1 -1
  57. package/apps/web/dist/assets/{copy-DgbMaHoj.js → copy-BAtcCufT.js} +1 -1
  58. package/apps/web/dist/assets/definition-CfFlylCM.js +56 -0
  59. package/apps/web/dist/assets/{external-link-pP6YfR9-.js → external-link-DitV3n6l.js} +1 -1
  60. package/apps/web/dist/assets/globe-CoQ1BSyl.js +1 -0
  61. package/apps/web/dist/assets/{image-D2X6TWdq.js → image-B1a1ax-P.js} +1 -1
  62. package/apps/web/dist/assets/index-B8VsYgck.js +78 -0
  63. package/apps/web/dist/assets/index-mB3Du8ho.css +1 -0
  64. package/apps/web/dist/assets/{lock-BG4mi_lJ.js → lock-DSPinlFN.js} +1 -1
  65. package/apps/web/dist/assets/{meta-BD9yulXs.js → meta-Bpe6vzmM.js} +1 -1
  66. package/apps/web/dist/assets/mouse-pointer-click-SHJL7g1i.js +1 -0
  67. package/apps/web/dist/assets/{pen-line-D54vxrGl.js → pen-line-DgSzJ60H.js} +1 -1
  68. package/apps/web/dist/assets/{refresh-cw-DvTgdpdf.js → refresh-cw-CWRkEENy.js} +1 -1
  69. package/apps/web/dist/assets/{session-CT1AZIlE.js → session-C24kIPr-.js} +1 -1
  70. package/apps/web/dist/assets/{settings-menu-DJATAPGg.js → settings-menu-e8OMChHm.js} +1 -1
  71. package/apps/web/dist/assets/star-ClV5w6K4.js +1 -0
  72. package/apps/web/dist/assets/{trash-DAcf34LR.js → trash-t3O7FdUR.js} +1 -1
  73. package/apps/web/dist/assets/{type-BU0mWqf3.js → type-BbMmv2qL.js} +1 -1
  74. package/apps/web/dist/assets/ui-C4b__6Oo.js +9 -0
  75. package/apps/web/dist/assets/{video-C6qoFAAs.js → video-D04-GeyG.js} +1 -1
  76. package/apps/web/dist/assets/volume-2-FUU7z0rq.js +1 -0
  77. package/apps/web/dist/assets/{wand-sparkles-Bw4tu2An.js → wand-sparkles-BsD2e8V6.js} +1 -1
  78. package/apps/web/dist/embed.js +119 -4
  79. package/apps/web/dist/index.html +12 -11
  80. package/apps/web/dist/mcp/flow.html +45 -45
  81. package/modules/calls/dist/client.css +3 -0
  82. package/modules/calls/dist/client.js +1 -0
  83. package/modules/calls/engenty.plugin.json +8 -0
  84. package/modules/calls/migrations/0001_init.sql +26 -0
  85. package/modules/calls/package.json +25 -0
  86. package/modules/calls/src/openai.ts +155 -0
  87. package/modules/calls/src/plugin.ts +407 -0
  88. package/modules/calls/src/rules.ts +226 -0
  89. package/modules/calls/src/schema.ts +39 -0
  90. package/modules/calls/src/session.ts +353 -0
  91. package/modules/calls/src/store.ts +124 -0
  92. package/modules/calls/src/twilio.ts +90 -0
  93. package/modules/calls/tsconfig.json +10 -0
  94. package/modules/calls/ui/Settings.tsx +137 -0
  95. package/modules/calls/ui/app.ts +50 -0
  96. package/modules/calls/ui/messages.ts +81 -0
  97. package/modules/calls/ui/parts.tsx +36 -0
  98. package/modules/calls/ui/plugin.tsx +15 -0
  99. package/modules/sms/dist/client.css +3 -0
  100. package/modules/sms/dist/client.js +1 -0
  101. package/modules/sms/engenty.plugin.json +8 -0
  102. package/modules/sms/migrations/0001_init.sql +26 -0
  103. package/modules/sms/package.json +25 -0
  104. package/modules/sms/src/plugin.ts +324 -0
  105. package/modules/sms/src/schema.ts +26 -0
  106. package/modules/sms/src/store.ts +140 -0
  107. package/modules/sms/src/surface.ts +70 -0
  108. package/modules/sms/src/twilio.ts +130 -0
  109. package/modules/sms/tsconfig.json +10 -0
  110. package/modules/sms/ui/Settings.tsx +113 -0
  111. package/modules/sms/ui/Share.tsx +78 -0
  112. package/modules/sms/ui/app.ts +51 -0
  113. package/modules/sms/ui/messages.ts +72 -0
  114. package/modules/sms/ui/parts.tsx +36 -0
  115. package/modules/sms/ui/plugin.tsx +20 -0
  116. package/modules/whatsapp/dist/client.css +3 -0
  117. package/modules/whatsapp/dist/client.js +1 -0
  118. package/modules/whatsapp/engenty.plugin.json +8 -0
  119. package/modules/whatsapp/migrations/0001_init.sql +30 -0
  120. package/modules/whatsapp/package.json +25 -0
  121. package/modules/whatsapp/src/graph.ts +271 -0
  122. package/modules/whatsapp/src/inbound.ts +143 -0
  123. package/modules/whatsapp/src/plugin.ts +369 -0
  124. package/modules/whatsapp/src/schema.ts +32 -0
  125. package/modules/whatsapp/src/store.ts +156 -0
  126. package/modules/whatsapp/src/surface.ts +127 -0
  127. package/modules/whatsapp/tsconfig.json +10 -0
  128. package/modules/whatsapp/ui/Settings.tsx +141 -0
  129. package/modules/whatsapp/ui/Share.tsx +78 -0
  130. package/modules/whatsapp/ui/app.ts +54 -0
  131. package/modules/whatsapp/ui/messages.ts +82 -0
  132. package/modules/whatsapp/ui/parts.tsx +36 -0
  133. package/modules/whatsapp/ui/plugin.tsx +20 -0
  134. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +259 -0
  135. package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +17 -0
  136. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.d.ts +174 -0
  137. package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.js +816 -0
  138. package/node_modules/@engenty-wizards/plugin-sdk/package.json +2 -1
  139. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +8 -0
  140. package/node_modules/@engenty-wizards/shared/dist/definition.js +21 -0
  141. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +61 -3
  142. package/node_modules/@engenty-wizards/shared/dist/run.js +16 -0
  143. package/node_modules/@engenty-wizards/shared/dist/runners.d.ts +81 -0
  144. package/node_modules/@engenty-wizards/shared/dist/runners.js +146 -0
  145. package/package.json +1 -1
  146. package/apps/web/dist/assets/ChangelogDialog-BxRBTR8P.js +0 -1
  147. package/apps/web/dist/assets/EditorPage-BKAFzzWk.js +0 -3
  148. package/apps/web/dist/assets/HomePage-BZuwrr-b.js +0 -1
  149. package/apps/web/dist/assets/ImportWizard-JGMemER4.js +0 -1
  150. package/apps/web/dist/assets/NewWizardPage-BwHAsJwj.js +0 -2
  151. package/apps/web/dist/assets/ProjectPage--ijr1jPE.js +0 -2
  152. package/apps/web/dist/assets/PublicRunner-D9Oe-_vs.js +0 -1
  153. package/apps/web/dist/assets/RunDrawer-BfociUm2.js +0 -4
  154. package/apps/web/dist/assets/RunnerView-D2b84UTY.js +0 -2
  155. package/apps/web/dist/assets/SettingsPage-9rk9IRdr.js +0 -1
  156. package/apps/web/dist/assets/SetupPage-BUJh_v9q.js +0 -1
  157. package/apps/web/dist/assets/SharePage-sNJ_s1RE.js +0 -1
  158. package/apps/web/dist/assets/ThemeSwitch-NDTEeh0R.js +0 -1
  159. package/apps/web/dist/assets/arrow-right-C1xLSnNa.js +0 -1
  160. package/apps/web/dist/assets/changelog-BSVi9hHS.js +0 -1
  161. package/apps/web/dist/assets/definition-FVgbAXOo.js +0 -56
  162. package/apps/web/dist/assets/index-CBjgitjd.js +0 -78
  163. package/apps/web/dist/assets/index-gTcC8eX6.css +0 -1
  164. package/apps/web/dist/assets/star-CaOg5c-D.js +0 -1
  165. package/apps/web/dist/assets/ui-Bxf6zX5k.js +0 -9
  166. package/apps/web/dist/assets/volume-2-Dw4p9Ln4.js +0 -1
@@ -291,6 +291,7 @@ export async function pushSharing(userId, wizardId) {
291
291
  await call("PATCH", `/spaces/${w.projectId}/wizards/${w.id}`, {
292
292
  shareEnabled: w.shareEnabled,
293
293
  dailyRunLimit: w.dailyRunLimit,
294
+ ...(w.runners ? { runners: w.runners } : {}),
294
295
  }).catch((err) => console.error("[cloud] sharing not sent:", err.message));
295
296
  }
296
297
  /**
@@ -0,0 +1,138 @@
1
+ import { wizardLang } from "@engenty-wizards/shared/definition";
2
+ import { BUILT_IN_RUNNERS, CONVERSATION_RUNNERS, DEFAULT_RUNNER, DEFAULT_RUNNER_SETTINGS, runnerFit, } from "@engenty-wizards/shared/runners";
3
+ import { env } from "../env.js";
4
+ import { conversationAccess, conversationAvailable } from "../models.js";
5
+ import { pluginsOf } from "../plugins/registry.js";
6
+ import { currentTenant } from "../tenants/tenant.js";
7
+ import { ServiceError } from "./errors.js";
8
+ import { shareUrl } from "./wizards.js";
9
+ /**
10
+ * The runners a wizard can run through: the built-in page and chat, and the ones the tenant's
11
+ * plugins add. Which of them a wizard offers is set per wizard (`wizard.runners`): the one its
12
+ * link opens, and the ones switched on beside it.
13
+ */
14
+ /** The runners this tenant has, built-ins first. */
15
+ export async function runnersOf(tenantId = currentTenant()) {
16
+ const plugins = await pluginsOf(tenantId);
17
+ const talk = (await conversationAvailable())
18
+ ? null
19
+ : await conversationAccess()
20
+ .then(() => null)
21
+ .catch((err) => err.message);
22
+ // A plugin's runner says per tenant whether it is ready (a number connected, a key set).
23
+ const ofPlugins = await Promise.all(plugins.flatMap((p) => [...p.runners.values()].map(async (r) => ({
24
+ ...r.info,
25
+ problem: r.problem
26
+ ? await Promise.resolve()
27
+ .then(() => r.problem?.() ?? null)
28
+ .catch((err) => err.message || "The runner is not ready.")
29
+ : null,
30
+ }))));
31
+ return [
32
+ ...BUILT_IN_RUNNERS.map((r) => CONVERSATION_RUNNERS.includes(r.id) ? { ...r, problem: talk } : r),
33
+ ...ofPlugins,
34
+ ];
35
+ }
36
+ /**
37
+ * How a wizard is offered, on the runners there are: a runner switched on that is gone (a
38
+ * plugin the tenant lost) is left out, and the link opens the first one left.
39
+ */
40
+ export function runnerSettingsOf(w, available) {
41
+ const ids = new Set(available.map((r) => r.id));
42
+ const wanted = w.runners ?? DEFAULT_RUNNER_SETTINGS;
43
+ const enabled = wanted.enabled.filter((id) => ids.has(id));
44
+ if (!enabled.includes(DEFAULT_RUNNER) && ids.has(DEFAULT_RUNNER) && !enabled.length) {
45
+ enabled.push(DEFAULT_RUNNER);
46
+ }
47
+ const fallback = enabled[0] ?? DEFAULT_RUNNER;
48
+ return {
49
+ default: enabled.includes(wanted.default) ? wanted.default : fallback,
50
+ enabled,
51
+ };
52
+ }
53
+ /** Checks what the owner wants to set, against the runners the tenant has. */
54
+ export async function checkRunnerSettings(settings) {
55
+ const available = await runnersOf();
56
+ const ids = new Set(available.map((r) => r.id));
57
+ const unknown = settings.enabled.find((id) => !ids.has(id));
58
+ if (unknown) {
59
+ throw new ServiceError("invalid", `There is no runner "${unknown}" here.`);
60
+ }
61
+ const enabled = [...new Set(settings.enabled)];
62
+ if (!enabled.length) {
63
+ throw new ServiceError("invalid", "At least one runner stays on.");
64
+ }
65
+ if (!enabled.includes(settings.default)) {
66
+ throw new ServiceError("invalid", "The link opens a runner that is switched on.");
67
+ }
68
+ return { default: settings.default, enabled };
69
+ }
70
+ /** The runners with how each fits the draft, and how the wizard is offered. */
71
+ export async function wizardRunners(w) {
72
+ const available = await runnersOf();
73
+ return {
74
+ runners: available.map((r) => ({ ...r, fit: runnerFit(w.draft, r) })),
75
+ settings: runnerSettingsOf(w, available),
76
+ };
77
+ }
78
+ /** The address a runner opens the wizard at: the link itself for the default, else its sub-path. */
79
+ export function runnerUrl(w, runner, settings) {
80
+ if (runner.kind !== "page") {
81
+ return null;
82
+ }
83
+ if (runner.plugin && env.fromSource) {
84
+ // From source Vite serves /w/*: a plugin's page is reached on this server's own address.
85
+ return `${env.appUrl}/api/public/wizards/${w.shareToken}/runners/${runner.id}`;
86
+ }
87
+ return runner.id === settings.default
88
+ ? shareUrl(w.shareToken)
89
+ : `${shareUrl(w.shareToken)}/${runner.id}`;
90
+ }
91
+ /** A plugin's page runner, where the tenant has it and the wizard switched it on. */
92
+ export async function pageRunnerOf(w, runnerId) {
93
+ for (const plugin of await pluginsOf(currentTenant())) {
94
+ const found = plugin.runners.get(runnerId);
95
+ if (found?.info.kind === "page" && found.page) {
96
+ const settings = runnerSettingsOf(w, await runnersOf());
97
+ return settings.enabled.includes(runnerId) ? found : null;
98
+ }
99
+ }
100
+ return null;
101
+ }
102
+ /** Serves a plugin's page runner for a wizard; null where there is none to serve. */
103
+ export async function servePageRunner(w, def, runnerId, rest, request) {
104
+ const runner = await pageRunnerOf(w, runnerId);
105
+ if (!runner?.page) {
106
+ return null;
107
+ }
108
+ const input = {
109
+ request,
110
+ tenantId: currentTenant(),
111
+ wizard: { id: w.id, token: w.shareToken, title: def.title },
112
+ path: rest || "/",
113
+ query: new URL(request.url).searchParams,
114
+ };
115
+ try {
116
+ return await runner.page(input);
117
+ }
118
+ catch (err) {
119
+ console.error(`[plugin ${runner.info.plugin}] runner ${runnerId}:`, err);
120
+ return new Response("The plugin failed.", { status: 500 });
121
+ }
122
+ }
123
+ /** What the wizard's public page offers: the runners switched on, the link's first. */
124
+ export async function publicRunners(w, def) {
125
+ const available = await runnersOf();
126
+ const settings = runnerSettingsOf(w, available);
127
+ const lang = wizardLang(def);
128
+ return settings.enabled
129
+ .map((id) => available.find((r) => r.id === id))
130
+ .filter((r) => Boolean(r) && !r?.problem)
131
+ .sort((a, b) => Number(b.id === settings.default) - Number(a.id === settings.default))
132
+ .map((r) => ({
133
+ id: r.id,
134
+ label: r.label[lang],
135
+ kind: r.kind,
136
+ url: runnerUrl(w, r, settings),
137
+ }));
138
+ }
@@ -1,10 +1,10 @@
1
- import { formatsFor, optionsFromData, slotText, wizardLang, } from "@engenty-wizards/shared/definition";
1
+ import { FIELD_WAYS, formatsFor, isDecidedField, shownFields, slotText, wizardLang, } from "@engenty-wizards/shared/definition";
2
2
  import { and, count, desc, eq, gte, inArray, max, or, sql } from "drizzle-orm";
3
3
  import { canSpend, MICROS_PER_CREDIT } from "../credits/credits.js";
4
4
  import { db, schema } from "../db/client.js";
5
5
  import { answerAsk, unattended } from "../engine/asks.js";
6
6
  import { emitEvent, recentEvents, subscribe } from "../engine/events.js";
7
- import { cancel, createRun, goBack, NoCreditsError, RunConflict, RunInputError, retry, reviewStep, submitPage, } from "../engine/runner.js";
7
+ import { cancel, createRun, goBack, NoCreditsError, pageContext, RunConflict, RunInputError, retry, reviewStep, submitPage, } from "../engine/runner.js";
8
8
  import { ModelUnavailableError } from "../model-errors.js";
9
9
  import { signedUrl } from "../secrets/signing.js";
10
10
  import { currentTenant } from "../tenants/tenant.js";
@@ -114,6 +114,36 @@ async function ownedRun(userId, runId, only) {
114
114
  function moving(run) {
115
115
  return run.status === "running" || (run.status === "waiting_input" && autopilots.has(run.id));
116
116
  }
117
+ /** A run a plugin's door may drive: any run of the current tenant, by id. */
118
+ export async function pluginRun(runId) {
119
+ const run = await db.query.run.findFirst({
120
+ where: and(eq(schema.run.id, runId), eq(schema.run.tenantId, currentTenant())),
121
+ });
122
+ if (!run) {
123
+ throw notFound();
124
+ }
125
+ return run;
126
+ }
127
+ /** Loads the run again while it works, up to `seconds` (at most 45), and gives it as it stands. */
128
+ export async function waitRun(load, seconds) {
129
+ const deadline = Date.now() + Math.min(45, Math.max(0, seconds)) * 1000;
130
+ let run = await load();
131
+ while (moving(run) && Date.now() < deadline) {
132
+ await new Promise((resolve) => {
133
+ const unsubscribe = subscribe(run.id, () => {
134
+ unsubscribe();
135
+ clearTimeout(timer);
136
+ resolve();
137
+ });
138
+ const timer = setTimeout(() => {
139
+ unsubscribe();
140
+ resolve();
141
+ }, deadline - Date.now());
142
+ });
143
+ run = await load();
144
+ }
145
+ return run;
146
+ }
117
147
  async function waitWhileMoving(userId, runId, seconds, only) {
118
148
  const deadline = Date.now() + seconds * 1000;
119
149
  let run = await ownedRun(userId, runId, only);
@@ -145,27 +175,6 @@ function deliverableFormats(run, step) {
145
175
  .find((d) => d.from === step.id);
146
176
  return listed ? listed.formats.filter((f) => possible.includes(f)) : [];
147
177
  }
148
- /** Field kinds an MCP client can answer with plain values; the others need the run page. */
149
- const CHAT_KINDS = new Set([
150
- "text",
151
- "textarea",
152
- "number",
153
- "select",
154
- "multiselect",
155
- "date",
156
- "email",
157
- "url",
158
- "toggle",
159
- "color",
160
- "items",
161
- "location",
162
- "slot",
163
- ]);
164
- /** A field's choices in this run: what its `optionsFrom` finds in earlier steps, else the fixed ones. */
165
- function choicesOf(run, field) {
166
- const found = field.optionsFrom ? optionsFromData(field.optionsFrom, run.state.outputs) : [];
167
- return found.length ? found : field.options;
168
- }
169
178
  /**
170
179
  * What a client needs besides the plain field: a slot's times as the person reads them, and the
171
180
  * one value of them to send back.
@@ -193,7 +202,11 @@ async function browserUrl(run) {
193
202
  const w = await db.query.wizard.findFirst({ where: eq(schema.wizard.id, run.wizardId) });
194
203
  return w ? `${shareUrl(w.shareToken)}/${run.id}` : null;
195
204
  }
196
- function waitingFor(run, current) {
205
+ /**
206
+ * What a run waits for. `draft`: what a door that asks one field at a time has so far, so a
207
+ * field's `shown` follows those answers as it follows the form on the screen.
208
+ */
209
+ async function waitingFor(run, current, draft) {
197
210
  if (run.status === "running" && run.ask) {
198
211
  const ask = run.ask;
199
212
  return ask.kind === "confirm"
@@ -218,27 +231,42 @@ function waitingFor(run, current) {
218
231
  return undefined;
219
232
  }
220
233
  if (current.type === "page") {
234
+ // What the page knows from before it, the choices its fields take from data, the fields a
235
+ // decision kept: a field left out here is not asked, as the run page leaves it out.
236
+ const ctx = await pageContext(run, current);
237
+ const fields = current.fields
238
+ .filter((f) => !isDecidedField(f) || ctx.decided.includes(f.id))
239
+ .map((f) => (ctx.options[f.id]?.length ? { ...f, options: ctx.options[f.id] } : f));
240
+ const page = {
241
+ ...Object.fromEntries(fields.filter((f) => f.id in run.state.values).map((f) => [f.id, run.state.values[f.id]])),
242
+ ...draft,
243
+ };
244
+ const shown = new Set(shownFields(fields, ctx.known, page).map((f) => f.id));
221
245
  return {
222
246
  page: current.id,
223
247
  title: current.title,
224
- fields: current.fields.map((f) => {
225
- const options = choicesOf(run, f);
226
- return {
227
- id: f.id,
228
- label: f.label,
229
- kind: f.kind,
230
- required: Boolean(f.required),
231
- options,
232
- placeholder: f.placeholder,
233
- help: f.help,
234
- default: f.default,
235
- value: run.state.values[f.id],
236
- columns: f.columns,
237
- // A file, a recording or a signature comes from the person's device: the run page.
238
- inChat: CHAT_KINDS.has(f.kind),
239
- ...slotHints(run, f, options),
240
- };
241
- }),
248
+ /** What the fields' conditions read from before the page, by reference. */
249
+ known: ctx.known,
250
+ fields: fields.map((f) => ({
251
+ id: f.id,
252
+ label: f.label,
253
+ kind: f.kind,
254
+ required: Boolean(f.required),
255
+ options: f.options,
256
+ placeholder: f.placeholder,
257
+ help: f.help,
258
+ default: f.default,
259
+ value: run.state.values[f.id],
260
+ columns: f.columns,
261
+ ...slotHints(run, f, f.options),
262
+ ...(f.multiple ? { multiple: true } : {}),
263
+ // A file, a recording or a signature comes from the person's device: the run page.
264
+ inChat: FIELD_WAYS[f.kind] !== "device",
265
+ // A field with a condition is asked only while it holds; one on another field of this
266
+ // page holds or not as the person answers. `shown` says so for what is known now.
267
+ ...(f.when ? { when: f.when, shown: shown.has(f.id) } : {}),
268
+ })),
269
+ hint: "Ask the fields in order; skip a field whose `when` does not hold on the answers so far (a hidden one is not required and not kept).",
242
270
  };
243
271
  }
244
272
  if (current.type === "review") {
@@ -254,7 +282,10 @@ function waitingFor(run, current) {
254
282
  }
255
283
  /** What a run did so far, for a client without the run page: outputs, links, cost, errors. */
256
284
  export async function runReport(userId, runId, waitSeconds = 0, only) {
257
- const run = await waitWhileMoving(userId, runId, waitSeconds, only);
285
+ return runReportOf(await waitWhileMoving(userId, runId, waitSeconds, only));
286
+ }
287
+ /** The report of a run as it stands; `draft` as for `waitingFor`. */
288
+ export async function runReportOf(run, draft) {
258
289
  const current = run.definition.steps.find((s) => s.id === run.cursor) ?? null;
259
290
  const base = `/api/runs/${run.id}`;
260
291
  const outputs = run.definition.steps.flatMap((step) => {
@@ -262,6 +293,11 @@ export async function runReport(userId, runId, waitSeconds = 0, only) {
262
293
  if (!output) {
263
294
  return [];
264
295
  }
296
+ // A document, a dashboard or a widget drawn as one picture: for a door that shows pictures
297
+ // with a link. A generated image is a picture already.
298
+ const picture = formatsFor(step).includes("png") && !(step.type === "generate" && step.asset === "image")
299
+ ? signedUrl(`${base}/steps/${step.id}/download?format=png`)
300
+ : null;
265
301
  return [
266
302
  {
267
303
  stepId: step.id,
@@ -277,6 +313,7 @@ export async function runReport(userId, runId, waitSeconds = 0, only) {
277
313
  f,
278
314
  signedUrl(`${base}/steps/${step.id}/download?format=${f}`),
279
315
  ])),
316
+ picture,
280
317
  },
281
318
  ];
282
319
  });
@@ -284,6 +321,7 @@ export async function runReport(userId, runId, waitSeconds = 0, only) {
284
321
  runId: run.id,
285
322
  wizardId: run.wizardId,
286
323
  mode: run.mode,
324
+ lang: wizardLang(run.definition),
287
325
  status: moving(run) ? "running" : run.status,
288
326
  step: current ? { id: current.id, type: current.type, title: current.title } : null,
289
327
  /** Steps behind the run: answered pages and reviews, every step with a result, the end. */
@@ -292,7 +330,7 @@ export async function runReport(userId, runId, waitSeconds = 0, only) {
292
330
  run.state.outputs[s.id] ||
293
331
  (run.status === "done" && s.id === run.cursor))
294
332
  .map((s) => s.id),
295
- waitingFor: waitingFor(run, current),
333
+ waitingFor: await waitingFor(run, current, draft),
296
334
  error: run.error,
297
335
  credits: Math.ceil(run.costMicros / MICROS_PER_CREDIT),
298
336
  events: (await recentEvents(run.id, 0, 15)).map((e) => ({
@@ -307,7 +345,7 @@ export async function runReport(userId, runId, waitSeconds = 0, only) {
307
345
  }
308
346
  export const testRunReport = (userId, runId, waitSeconds = 0) => runReport(userId, runId, waitSeconds, "test");
309
347
  /** A command the run refused, as a tool error the client can act on. */
310
- function refusedInput(err) {
348
+ export function refusedInput(err) {
311
349
  if (err instanceof RunInputError) {
312
350
  throw new ServiceError("invalid", err.message, { fields: err.errors });
313
351
  }
@@ -69,6 +69,18 @@ function engentySvg(kind, labelled, safe, size) {
69
69
  const y = labelled ? 60 - 46 * safe - 0.08 * s : (120 - s) / 2 - 1.5 * scale;
70
70
  return `${open}<defs><linearGradient id="bg" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="${top}"/><stop offset="1" stop-color="${bottom}"/></linearGradient></defs><rect width="120" height="120" fill="url(#bg)"/><g transform="translate(${x} ${y}) scale(${scale})"><ellipse cx="60" cy="${shadow.cy}" rx="${shadow.rx}" ry="4.5" fill="#000" opacity="0.14"/>${inner}</g></svg>`;
71
71
  }
72
+ /**
73
+ * The engenty filling the circle a round button cuts from the square, on the pale ground of its
74
+ * hue: the chat button a website shows the wizard behind (`embed.js`). Its body (y 16–100 of the
75
+ * shapes) sits in the middle.
76
+ */
77
+ export function wizardAvatarSvg(avatar) {
78
+ const kind = Object.hasOwn(ENGENTY_SVG, avatar) ? avatar : "round";
79
+ const inner = ENGENTY_SVG[kind].replace(/^<svg[^>]*>/, "").replace(/<\/svg>$/, "");
80
+ const { top, bottom } = palette(kind);
81
+ const scale = 1.1;
82
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120"><defs><linearGradient id="bg" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="${top}"/><stop offset="1" stop-color="${bottom}"/></linearGradient></defs><rect width="120" height="120" fill="url(#bg)"/><g transform="translate(${60 - 60 * scale} ${60 - 58 * scale}) scale(${scale})">${inner}</g></svg>`;
83
+ }
72
84
  /**
73
85
  * The name in capitals, as many whole words as fit; a lone long word gets a smaller font, then
74
86
  * an ellipsis. A cut never ends on a short filler word ("aus", "für").
@@ -15,6 +15,7 @@ import { copyFiles, draftFiles, sameFiles, seedFiles } from "./files.js";
15
15
  import { forgetWizardLinks } from "./links.js";
16
16
  import { asLang, countInstall, marketplaceWizard } from "./marketplace.js";
17
17
  import { defaultProject, ownedProject } from "./projects.js";
18
+ import { checkRunnerSettings } from "./runners.js";
18
19
  const BLANK = {
19
20
  version: 1,
20
21
  title: "Neuer Wizard",
@@ -61,6 +62,8 @@ export function wizardSummary(w) {
61
62
  shareToken: w.shareToken,
62
63
  shareEnabled: w.shareEnabled,
63
64
  dailyRunLimit: w.dailyRunLimit,
65
+ /** How it is offered; null: the link opens the page, the chat is on beside it. */
66
+ runners: w.runners,
64
67
  stepCount: w.draft.steps.length,
65
68
  updatedAt: w.updatedAt.toISOString(),
66
69
  };
@@ -315,9 +318,10 @@ export async function updateWizardSettings(userId, wizardId, patch) {
315
318
  if (patch.projectId) {
316
319
  await requireWritable(await ownedProject(userId, patch.projectId));
317
320
  }
321
+ const runners = patch.runners ? await checkRunnerSettings(patch.runners) : undefined;
318
322
  await db
319
323
  .update(schema.wizard)
320
- .set({ ...patch, updatedAt: new Date() })
324
+ .set({ ...patch, ...(runners ? { runners } : {}), updatedAt: new Date() })
321
325
  .where(eq(schema.wizard.id, w.id));
322
326
  return wizardSummary(await ownedWizard(userId, wizardId));
323
327
  }