wizards 0.2.55 → 0.2.57

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 (123) hide show
  1. package/README.md +2 -2
  2. package/apps/runtime/dist/cli/autostart.js +1 -1
  3. package/apps/runtime/dist/cli/machine.js +5 -48
  4. package/apps/runtime/dist/cli/report.js +1 -1
  5. package/apps/runtime/dist/db/control-schema.js +13 -0
  6. package/apps/runtime/dist/db/migrations/control/0008_runner.sql +8 -0
  7. package/apps/runtime/dist/db/migrations/control/meta/0008_snapshot.json +505 -0
  8. package/apps/runtime/dist/db/migrations/control/meta/_journal.json +7 -0
  9. package/apps/runtime/dist/db/migrations/tenant/0014_run_answer.sql +2 -0
  10. package/apps/runtime/dist/db/migrations/tenant/meta/0014_snapshot.json +3154 -0
  11. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
  12. package/apps/runtime/dist/db/schema.js +4 -0
  13. package/apps/runtime/dist/docs/dev/index.md +4 -4
  14. package/apps/runtime/dist/docs/dev/plugins/connections.md +4 -3
  15. package/apps/runtime/dist/docs/dev/plugins/events.md +1 -0
  16. package/apps/runtime/dist/docs/dev/plugins/examples.md +10 -9
  17. package/apps/runtime/dist/docs/dev/plugins/index.md +4 -3
  18. package/apps/runtime/dist/docs/dev/plugins/layout.md +2 -1
  19. package/apps/runtime/dist/docs/dev/plugins/meta.json +0 -1
  20. package/apps/runtime/dist/docs/dev/plugins/quick-start.md +4 -3
  21. package/apps/runtime/dist/docs/dev/plugins/reference.md +36 -14
  22. package/apps/runtime/dist/docs/dev/plugins/reloading.md +5 -5
  23. package/apps/runtime/dist/docs/dev/plugins/routes.md +30 -6
  24. package/apps/runtime/dist/docs/dev/plugins/runners.md +15 -10
  25. package/apps/runtime/dist/docs/dev/plugins/server.md +16 -7
  26. package/apps/runtime/dist/docs/dev/plugins/shipping.md +4 -26
  27. package/apps/runtime/dist/docs/dev/plugins/space.md +66 -53
  28. package/apps/runtime/dist/docs/dev/plugins/starters.md +10 -7
  29. package/apps/runtime/dist/docs/dev/plugins/studio.md +33 -12
  30. package/apps/runtime/dist/docs/dev/plugins/styling.md +19 -9
  31. package/apps/runtime/dist/docs/dev/plugins/tables.md +6 -4
  32. package/apps/runtime/dist/docs/dev/plugins/tools.md +22 -12
  33. package/apps/runtime/dist/docs/dev/wizard-format.md +3 -2
  34. package/apps/runtime/dist/docs/user/ai-apps.md +3 -1
  35. package/apps/runtime/dist/docs/user/assistant.md +5 -3
  36. package/apps/runtime/dist/docs/user/build-a-wizard.md +14 -2
  37. package/apps/runtime/dist/docs/user/command-line.md +16 -14
  38. package/apps/runtime/dist/docs/user/connectors.md +17 -12
  39. package/apps/runtime/dist/docs/user/data.md +14 -9
  40. package/apps/runtime/dist/docs/user/first-start.md +13 -6
  41. package/apps/runtime/dist/docs/user/index.md +2 -1
  42. package/apps/runtime/dist/docs/user/install.md +19 -11
  43. package/apps/runtime/dist/docs/user/models.md +44 -22
  44. package/apps/runtime/dist/docs/user/plugins.md +9 -4
  45. package/apps/runtime/dist/docs/user/run.md +14 -9
  46. package/apps/runtime/dist/docs/user/server.md +7 -5
  47. package/apps/runtime/dist/docs/user/space.md +15 -8
  48. package/apps/runtime/dist/docs/user/steps.md +33 -13
  49. package/apps/runtime/dist/docs/user/test-and-share.md +41 -25
  50. package/apps/runtime/dist/docs/user/troubleshooting.md +15 -7
  51. package/apps/runtime/dist/docs/user/wordpress.md +59 -49
  52. package/apps/runtime/dist/engine/asks.js +53 -33
  53. package/apps/runtime/dist/engine/events.js +45 -1
  54. package/apps/runtime/dist/engine/owner.js +32 -0
  55. package/apps/runtime/dist/engine/runner.js +131 -97
  56. package/apps/runtime/dist/env.js +25 -3
  57. package/apps/runtime/dist/harness/apple.js +36 -21
  58. package/apps/runtime/dist/harness/claude.js +1 -1
  59. package/apps/runtime/dist/harness/model.js +2 -2
  60. package/apps/runtime/dist/index.js +13 -2
  61. package/apps/runtime/dist/limits.js +7 -4
  62. package/apps/runtime/dist/media/conversation.js +6 -5
  63. package/apps/runtime/dist/model-errors.js +22 -1
  64. package/apps/runtime/dist/models.js +30 -7
  65. package/apps/runtime/dist/plugins/pro-keys.js +1 -1
  66. package/apps/runtime/dist/plugins/pro-state.js +1 -1
  67. package/apps/runtime/dist/plugins/pro.js +1 -1
  68. package/apps/runtime/dist/plugins/runs.js +20 -15
  69. package/apps/runtime/dist/render/browser-path.js +54 -0
  70. package/apps/runtime/dist/routes/runs.js +67 -38
  71. package/apps/runtime/dist/routes/studio.js +7 -3
  72. package/apps/runtime/dist/services/api.js +3 -1
  73. package/apps/runtime/dist/services/package-file.js +8 -8
  74. package/apps/runtime/dist/services/runs.js +7 -8
  75. package/apps/runtime/dist/tenants/control.js +85 -7
  76. package/apps/runtime/dist/update.js +1 -1
  77. package/apps/web/dist/assets/AboutDialog-DEZCEQlN.js +1 -0
  78. package/apps/web/dist/assets/{ChangelogDialog-BLmJABe4.js → ChangelogDialog-CgnnJj4G.js} +1 -1
  79. package/apps/web/dist/assets/{ChatView-YAiOT6mt.js → ChatView-BnnKdwk4.js} +1 -1
  80. package/apps/web/dist/assets/{EditorPage-C0zMXwlF.js → EditorPage-CeDWjq4z.js} +2 -2
  81. package/apps/web/dist/assets/{FlowPreview-B4lbmeha.js → FlowPreview-Du028FI3.js} +1 -1
  82. package/apps/web/dist/assets/{Harness-_riwRD-c.js → Harness-CEPy4MEp.js} +1 -1
  83. package/apps/web/dist/assets/{Marketplace-B0Nki6J6.js → Marketplace-ms58DQJ9.js} +2 -2
  84. package/apps/web/dist/assets/{NewWizardPage-DkvGgROv.js → NewWizardPage-CEQSNXeZ.js} +1 -1
  85. package/apps/web/dist/assets/{ProjectPage-CFRIPset.js → ProjectPage-CXDpKoK2.js} +1 -1
  86. package/apps/web/dist/assets/{PublicRunner-QJuQB7ff.js → PublicRunner-DMmtmzBX.js} +1 -1
  87. package/apps/web/dist/assets/{ReadOnly-DiOfNtVr.js → ReadOnly-zQecD9OB.js} +1 -1
  88. package/apps/web/dist/assets/{RunDrawer-LjUX3yIv.js → RunDrawer-BIojYB0g.js} +1 -1
  89. package/apps/web/dist/assets/{RunnerView-DkJVfUeG.js → RunnerView-D8OGEoMl.js} +1 -1
  90. package/apps/web/dist/assets/SettingsPage-BlMZL4_d.js +1 -0
  91. package/apps/web/dist/assets/SetupPage-Doz9T3kv.js +1 -0
  92. package/apps/web/dist/assets/{SharePage-CCimr8XT.js → SharePage-DOJXdsyi.js} +1 -1
  93. package/apps/web/dist/assets/{brand-CwLcF9JR.js → brand-DIKyySmf.js} +1 -1
  94. package/apps/web/dist/assets/changelog-B1jhC7Fv.js +1 -0
  95. package/apps/web/dist/assets/{circle-alert-BEDKtkJy.js → circle-alert-B9b9Vb9k.js} +1 -1
  96. package/apps/web/dist/assets/{esm-BCwno33N.js → esm-D6fM9MdG.js} +1 -1
  97. package/apps/web/dist/assets/{index-Dq-Wj6Yo.js → index-nfRuCdVt.js} +4 -4
  98. package/apps/web/dist/assets/{lock-Ce2ofIWG.js → lock-BNvsUKTg.js} +1 -1
  99. package/apps/web/dist/assets/session-CSbo-pmx.js +1 -0
  100. package/apps/web/dist/assets/{settings-menu-DX0JnPBR.js → settings-menu-BGfn4LJE.js} +1 -1
  101. package/apps/web/dist/assets/{ui-mkL5nF_f.js → ui-FW7ypPI6.js} +1 -1
  102. package/apps/web/dist/assets/{upload-BfrqabpO.js → upload-MQ_24gSb.js} +1 -1
  103. package/apps/web/dist/assets/{volume-2-C3GeMqc-.js → volume-2-B1mj20eS.js} +1 -1
  104. package/apps/web/dist/index.html +6 -6
  105. package/apps/web/dist/install.sh +2 -2
  106. package/apps/web/dist/mcp/flow.html +1 -1
  107. package/modules/calls/dist/client.css +1 -1
  108. package/modules/sms/dist/client.css +1 -1
  109. package/modules/whatsapp/dist/client.css +1 -1
  110. package/node_modules/@engenty-wizards/shared/dist/definition.js +1 -0
  111. package/node_modules/@engenty-wizards/shared/dist/engenty/data-tables/columns.js +1 -0
  112. package/node_modules/@engenty-wizards/shared/dist/fit.js +1 -0
  113. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +152 -2
  114. package/node_modules/@engenty-wizards/shared/dist/run.js +135 -1
  115. package/node_modules/@engenty-wizards/shared/dist/store.js +1 -0
  116. package/node_modules/@engenty-wizards/shared/dist/surface.js +1 -0
  117. package/package.json +2 -2
  118. package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +0 -59
  119. package/apps/web/dist/assets/AboutDialog-BelD7JCn.js +0 -1
  120. package/apps/web/dist/assets/SettingsPage-BKZ1KLfP.js +0 -1
  121. package/apps/web/dist/assets/SetupPage-Rqlo16Lk.js +0 -1
  122. package/apps/web/dist/assets/changelog-Bg5ZBu5p.js +0 -1
  123. package/apps/web/dist/assets/session-BuVghS-e.js +0 -1
@@ -2,10 +2,11 @@ import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { release } from "node:os";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
+ import { noteText } from "@engenty-wizards/shared/run";
5
6
  import { nanoid } from "nanoid";
6
7
  import { env } from "../env.js";
7
8
  import { ffmpeg, hasFfmpeg } from "../media/ffmpeg.js";
8
- import { ModelUnavailableError } from "../model-errors.js";
9
+ import { ModelUnavailableError, NotedError } from "../model-errors.js";
9
10
  import { HarnessModel, lastJson, runClient, } from "./model.js";
10
11
  /**
11
12
  * Apple Intelligence on this Mac as a model: the on-device foundation model of macOS 26, run
@@ -87,45 +88,56 @@ async function detectApple() {
87
88
  return { supported: true, available: false, reason: "missing" };
88
89
  }
89
90
  }
90
- /** What to tell the person when Apple Intelligence cannot answer. */
91
- export function appleUnavailable(status) {
91
+ /** What to tell the person when Apple Intelligence cannot answer, as a note of `RUN_NOTES`. */
92
+ export function appleUnavailableNote(status) {
92
93
  switch (status.reason) {
93
94
  case "off":
94
- return "Apple Intelligence ist auf diesem Mac ausgeschaltet. Einschalten unter Systemeinstellungen → Apple Intelligence & Siri.";
95
+ return { code: "appleOff" };
95
96
  case "loading":
96
- return "Apple lädt das Modell für Apple Intelligence noch auf diesen Mac. Gleich noch einmal versuchen.";
97
+ return { code: "appleLoading" };
97
98
  case "missing":
98
- return "Der Helfer für Apple Intelligence (wizards-apple) fehlt in dieser Installation.";
99
+ return { code: "appleMissing" };
99
100
  case "os":
100
- return "Apple Intelligence braucht macOS 26 oder neuer.";
101
+ return { code: "appleOs" };
101
102
  default:
102
- return "Apple Intelligence gibt es nur auf einem Mac mit Apple Silicon.";
103
+ return { code: "appleDevice" };
103
104
  }
104
105
  }
105
- /** The failure the helper reports, as the person should read it. */
106
+ /** What to tell the person when Apple Intelligence cannot answer, in German (the settings). */
107
+ export function appleUnavailable(status) {
108
+ return noteText(appleUnavailableNote(status), "de");
109
+ }
110
+ /**
111
+ * The failure the helper reports, as the person should read it: a note, so a run shows it in the
112
+ * wizard's language.
113
+ */
106
114
  export function appleFailure(error) {
107
115
  switch (error.kind) {
108
116
  case "unavailable":
109
- return new ModelUnavailableError(appleUnavailable({
117
+ return new ModelUnavailableError(appleUnavailableNote({
110
118
  supported: true,
111
119
  available: false,
112
120
  reason: appleReasonOf(error.message),
113
121
  }));
114
122
  case "rateLimited":
115
- return new ModelUnavailableError("Apple Intelligence nimmt gerade keine weiteren Anfragen an. Gleich noch einmal versuchen.");
123
+ return new ModelUnavailableError({ code: "appleBusy" });
116
124
  case "contextWindow":
117
- return new Error("Apple Intelligence: Der Text ist zu lang für das Modell auf diesem Mac (4.096 Tokens für Frage und Antwort). Diese Klasse in den Einstellungen unter „Modelle & Konto“ auf ein anderes Modell legen.");
125
+ return new NotedError({ code: "appleTooLong" });
118
126
  case "guardrail":
119
127
  case "refusal":
120
- return new Error("Apple Intelligence hat die Anfrage abgelehnt: Apples Inhaltsregeln lassen sie nicht zu.");
128
+ return new NotedError({ code: "appleRefused" });
121
129
  case "language":
122
- return new Error("Apple Intelligence versteht die Sprache dieser Anfrage nicht.");
130
+ return new NotedError({ code: "appleLanguage" });
123
131
  case "schema":
124
- return new Error(`Apple Intelligence kann dieses Antwortformat nicht liefern: ${error.message}`);
132
+ return new NotedError({ code: "appleFormat", params: { detail: error.message } });
125
133
  default:
126
- return new Error(`Apple Intelligence: ${error.message}`.slice(0, 500));
134
+ return appleFailed(error.message);
127
135
  }
128
136
  }
137
+ /** Anything else the helper says, in its own words. */
138
+ function appleFailed(detail) {
139
+ return new NotedError({ code: "appleFailed", params: { detail: detail.slice(0, 480) } });
140
+ }
129
141
  class AppleModel extends HarnessModel {
130
142
  provider = "apple";
131
143
  /** The model keeps to the schema itself (guided generation). */
@@ -146,7 +158,7 @@ class AppleModel extends HarnessModel {
146
158
  });
147
159
  const answer = lastJson(stdout);
148
160
  if (!answer) {
149
- throw new Error(`Apple Intelligence: ${stderr.trim() || `exit ${code}`}`.slice(0, 500));
161
+ throw appleFailed(stderr.trim() || `exit ${code}`);
150
162
  }
151
163
  if (answer.error) {
152
164
  throw appleFailure(answer.error);
@@ -204,7 +216,7 @@ class AppleTranscriptionModel {
204
216
  let path = given;
205
217
  if (!native) {
206
218
  if (!(await hasFfmpeg())) {
207
- throw new Error(`Apple Intelligence liest ${options.mediaType} nicht; ohne ffmpeg bleibt die Aufnahme so. ffmpeg installieren oder im Browser als MP4 aufnehmen.`);
219
+ throw new NotedError({ code: "appleNoFfmpeg", params: { type: options.mediaType } });
208
220
  }
209
221
  path = join(dir, "note.wav");
210
222
  const { code, stderr } = await ffmpeg([
@@ -218,7 +230,10 @@ class AppleTranscriptionModel {
218
230
  path,
219
231
  ]);
220
232
  if (code !== 0) {
221
- throw new Error(`Apple Intelligence: die Aufnahme ließ sich nicht wandeln: ${stderr.slice(-300)}`);
233
+ throw new NotedError({
234
+ code: "appleNotConverted",
235
+ params: { detail: stderr.slice(-300) },
236
+ });
222
237
  }
223
238
  }
224
239
  const { stdout, stderr, code } = await runClient(APPLE_BIN, ["transcribe", path, locale], {
@@ -228,7 +243,7 @@ class AppleTranscriptionModel {
228
243
  });
229
244
  const answer = lastJson(stdout);
230
245
  if (!answer) {
231
- throw new Error(`Apple Intelligence: ${stderr.trim() || `exit ${code}`}`.slice(0, 500));
246
+ throw appleFailed(stderr.trim() || `exit ${code}`);
232
247
  }
233
248
  if (answer.error) {
234
249
  throw appleFailure(answer.error);
@@ -244,7 +259,7 @@ class AppleTranscriptionModel {
244
259
  }
245
260
  catch (err) {
246
261
  if (err.code === "ENOENT") {
247
- throw new ModelUnavailableError(appleUnavailable({ supported: false, available: false, reason: "missing" }));
262
+ throw new ModelUnavailableError(appleUnavailableNote({ supported: false, available: false, reason: "missing" }));
248
263
  }
249
264
  throw err;
250
265
  }
@@ -142,5 +142,5 @@ export const claude = {
142
142
  },
143
143
  login: { args: ["auth", "login"], interactive: false },
144
144
  model: (alias, effort) => new ClaudeCodeModel(claude, alias || "sonnet", effort),
145
- exhausted: "Das Anthropic-Konto, mit dem Claude Code angemeldet ist, hat kein Guthaben. Melde Claude Code mit deinem Abo an: in den Einstellungen unter „Modelle & Konto“.",
145
+ exhausted: "Das Anthropic-Konto, mit dem Claude Code angemeldet ist, hat kein Guthaben. Melde Claude Code mit deinem Abo an: in den Einstellungen unter „Modelle“.",
146
146
  };
@@ -7,8 +7,8 @@ import { openBridge } from "../mcp/bridge.js";
7
7
  import { ModelUnavailableError } from "../model-errors.js";
8
8
  import { extensionOf, jsonInstruction, parseJsonAnswer, renderPrompt } from "./prompt.js";
9
9
  const workDir = join(env.dataDir, "harness");
10
- export const signedOut = (h) => `${h.name} ist auf diesem Gerät nicht angemeldet. Melde dich in den Einstellungen unter „Modelle & Konto“ an.`;
11
- export const notInstalled = (h) => `${h.name} ist auf diesem Gerät nicht installiert. Installiere es in den Einstellungen unter „Modelle & Konto“.`;
10
+ export const signedOut = (h) => `${h.name} ist auf diesem Gerät nicht angemeldet. Melde dich in den Einstellungen unter „Modelle“ an.`;
11
+ export const notInstalled = (h) => `${h.name} ist auf diesem Gerät nicht installiert. Installiere es in den Einstellungen unter „Modelle“.`;
12
12
  export const exhausted = (h) => h.exhausted ??
13
13
  `Das Konto, mit dem ${h.name} angemeldet ist, hat kein Guthaben oder Kontingent mehr.`;
14
14
  /** The failure a client reports, as the person should read it. */
@@ -2,7 +2,7 @@ import { serve } from "@hono/node-server";
2
2
  import { localEntryUrl, purgeSessions } from "./auth/index.js";
3
3
  import { adoptLegacyData } from "./db/adopt.js";
4
4
  import { knownTenants, migrateAllTenants, migrateControlDb, openTenantDb, withTenant, } from "./db/client.js";
5
- import { resumeInterruptedRuns } from "./engine/runner.js";
5
+ import { startRunner, stopRunner } from "./engine/runner.js";
6
6
  import { basePath, env } from "./env.js";
7
7
  import { hookConsole } from "./log.js";
8
8
  import { managed } from "./manage.js";
@@ -15,6 +15,7 @@ import { clearRunning, writeRunning } from "./running.js";
15
15
  import { syncMarketplace } from "./services/marketplace.js";
16
16
  import { purgeExpiredRuns } from "./services/shares.js";
17
17
  import { purgeUnusedStores } from "./store/index.js";
18
+ import { forgetRunner, registerRunner } from "./tenants/control.js";
18
19
  import { LOCAL_TENANT } from "./tenants/tenant.js";
19
20
  import { onRestart, RESTART_EXIT } from "./update.js";
20
21
  // Before anything prints: the last lines stay in memory for a look from afar (debug.ts).
@@ -68,7 +69,12 @@ const server = serve({ fetch: withoutBasePath, port: env.port, hostname: env.hos
68
69
  });
69
70
  }
70
71
  });
71
- await resumeInterruptedRuns();
72
+ // A runner takes the runs in line, those a stopped process left behind first (RUNTIME_ROLE).
73
+ if (env.role !== "web") {
74
+ await registerRunner();
75
+ setInterval(() => void registerRunner().catch(() => undefined), 10_000).unref();
76
+ startRunner();
77
+ }
72
78
  // End-user results are kept RESULT_TTL_DAYS; expired runs and their files go once an hour.
73
79
  // What a wizard keeps for a person goes once nobody used it for STORE_TTL_DAYS.
74
80
  async function purge() {
@@ -88,6 +94,11 @@ if (!managed) {
88
94
  async function shutdown(code = 0) {
89
95
  clearRunning(env.dataDir);
90
96
  server.close();
97
+ if (env.role !== "web") {
98
+ // The runs go back in line for another runner; their steps start afresh there.
99
+ await stopRunner();
100
+ await forgetRunner().catch(() => undefined);
101
+ }
91
102
  await closeBrowser();
92
103
  process.exit(code);
93
104
  }
@@ -14,20 +14,23 @@ function startOfDay() {
14
14
  d.setUTCHours(0, 0, 0, 0);
15
15
  return d;
16
16
  }
17
- /** Why a shared wizard cannot start a run right now, or null when it can. */
17
+ /**
18
+ * Why a shared wizard cannot start a run right now, or null when it can: a note, to answer in the
19
+ * wizard's language (`noteText(reason, wizardLang(def))`).
20
+ */
18
21
  export async function wizardUnavailable(w) {
19
22
  if (!w.shareEnabled || w.publishedVersion === null) {
20
- return "Dieser Wizard ist gerade nicht verfügbar.";
23
+ return { code: "wizardUnavailable" };
21
24
  }
22
25
  const [{ n }] = await db
23
26
  .select({ n: count() })
24
27
  .from(schema.run)
25
28
  .where(and(eq(schema.run.wizardId, w.id), eq(schema.run.mode, "live"), gte(schema.run.createdAt, startOfDay())));
26
29
  if (n >= w.dailyRunLimit) {
27
- return "Für heute ist das Limit dieses Wizards erreicht. Bitte morgen wieder versuchen.";
30
+ return { code: "wizardLimit" };
28
31
  }
29
32
  if (!(await canSpend())) {
30
- return "Dieser Wizard ist gerade nicht verfügbar.";
33
+ return { code: "wizardUnavailable" };
31
34
  }
32
35
  return null;
33
36
  }
@@ -1,3 +1,4 @@
1
+ import { NotedError } from "../model-errors.js";
1
2
  import { conversationAccess } from "../models.js";
2
3
  /**
3
4
  * A live conversation with a wizard: the browser talks to a realtime speech model directly
@@ -133,7 +134,7 @@ export function conversationInstructions(view) {
133
134
  ];
134
135
  return `${about}\n\n${rules.join("\n")}`;
135
136
  }
136
- /** Mints the secret a browser opens a session with. */
137
+ /** Mints the secret a browser opens a session with; a failure carries a note for the run's language. */
137
138
  export async function mintConversation(view) {
138
139
  const { apiKey, model } = await conversationAccess();
139
140
  const res = await fetch(SECRETS_URL, {
@@ -160,13 +161,13 @@ export async function mintConversation(view) {
160
161
  // The provider's answer goes to the log; the page hears only that it did not work, and why in a word.
161
162
  const detail = (await res.text()).slice(0, 500);
162
163
  console.error(`[talk] the provider refused the session (${res.status}):`, detail);
163
- throw new Error(res.status === 401 || res.status === 403
164
- ? "The conversation could not be started: the OpenAI API key was refused."
165
- : `The conversation could not be started (${res.status}).`);
164
+ throw new NotedError(res.status === 401 || res.status === 403
165
+ ? { code: "talkKeyRefused" }
166
+ : { code: "talkFailed", params: { status: res.status } });
166
167
  }
167
168
  const body = (await res.json());
168
169
  if (!body.value) {
169
- throw new Error("The conversation could not be started: no secret came back.");
170
+ throw new NotedError({ code: "talkNoSecret" });
170
171
  }
171
172
  return {
172
173
  clientSecret: body.value,
@@ -1,3 +1,24 @@
1
+ import { noteText } from "@engenty-wizards/shared/run";
2
+ /**
3
+ * A failure the person reads, given as a note of `RUN_NOTES` where it has one: a run shows it in
4
+ * the wizard's language, the message keeps the German line for the log. Free text has no note.
5
+ */
6
+ export class NotedError extends Error {
7
+ note;
8
+ constructor(said) {
9
+ super(typeof said === "string" ? said : noteText(said, "de"));
10
+ this.note = typeof said === "string" ? null : said;
11
+ }
12
+ }
1
13
  /** A class has nothing to run on: no key, no account, no installed client — the person can fix it in the settings. */
2
- export class ModelUnavailableError extends Error {
14
+ export class ModelUnavailableError extends NotedError {
15
+ }
16
+ /** The note a failure carries, or null. */
17
+ export function noteOf(err) {
18
+ return err instanceof NotedError ? err.note : null;
19
+ }
20
+ /** A failure in a language: its note where it has one, else its message as it is. */
21
+ export function errorText(err, lang) {
22
+ const note = noteOf(err);
23
+ return note ? noteText(note, lang) : (err?.message ?? String(err));
3
24
  }
@@ -12,9 +12,10 @@ import { generateSpeech, generateText, } from "ai";
12
12
  import { accountToken, linkedAccount } from "./auth/account.js";
13
13
  import { DeviceModel, deviceThinks } from "./engine/device.js";
14
14
  import { env } from "./env.js";
15
- import { appleModel, appleStatus, appleTranscriptionModel, appleUnavailable, } from "./harness/apple.js";
15
+ import { appleModel, appleStatus, appleTranscriptionModel, appleUnavailable, appleUnavailableNote, } from "./harness/apple.js";
16
16
  import { detectHarness, HarnessModel, harness, isHarnessVendor, notInstalled, signedOut, } from "./harness/index.js";
17
17
  import { managed } from "./manage.js";
18
+ import { hasFfmpeg } from "./media/ffmpeg.js";
18
19
  import { ModelUnavailableError } from "./model-errors.js";
19
20
  import { seal, unseal } from "./secrets/crypto.js";
20
21
  import { vaultDelete, vaultGet, vaultSet } from "./secrets/vault.js";
@@ -201,6 +202,11 @@ function reachable(cfg, ref) {
201
202
  /** What a class runs on without credits: a client, an own key or a local model. "" = no way of its own. */
202
203
  function ownRef(cfg, cls) {
203
204
  const bound = cfg.settings.bindings[cls];
205
+ // A text class bound to Apple Intelligence (Classifier, Standard) thinks on this Mac whatever
206
+ // the source is: the others keep the installed client, the account's credits or the keys.
207
+ if (isText(cls) && bound && parse(bound).provider === "apple") {
208
+ return reachable(cfg, bound) ? bound : "";
209
+ }
204
210
  const client = managed ? null : harness(cfg.settings.source);
205
211
  if (isText(cls) && client) {
206
212
  // Text thinks on the installed client; a binding counts only where it names that client.
@@ -378,7 +384,7 @@ async function ownLanguageModel(cfg, ref, meta) {
378
384
  case "apple": {
379
385
  const status = await appleStatus();
380
386
  if (!status.available) {
381
- throw new ModelUnavailableError(appleUnavailable(status));
387
+ throw new ModelUnavailableError(appleUnavailableNote(status));
382
388
  }
383
389
  return { model: appleModel(id), gateway: false };
384
390
  }
@@ -834,8 +840,12 @@ export async function filmClient(cls) {
834
840
  if (status.auth === "none") {
835
841
  return { problem: signedOut(client) };
836
842
  }
843
+ // A class that thinks on Apple Intelligence makes its films on the client's model of the class.
837
844
  const ref = ownRef(cfg, cls);
838
- return { client, alias: ref.slice(client.id.length + 1) || client.classes[cls] };
845
+ return {
846
+ client,
847
+ alias: ref.startsWith(`${client.id}/`) ? ref.slice(client.id.length + 1) : client.classes[cls],
848
+ };
839
849
  }
840
850
  /** Whether any text model can answer at all: the studio says so before the first chat turn. */
841
851
  export async function hasTextModel() {
@@ -868,7 +878,7 @@ export async function classWays() {
868
878
  problem: client
869
879
  ? null
870
880
  : provider === "apple"
871
- ? await appleProblem()
881
+ ? await appleProblem(cls)
872
882
  : await gatewayProblem(cls, ref),
873
883
  };
874
884
  continue;
@@ -891,10 +901,23 @@ export async function classWays() {
891
901
  }
892
902
  return ways;
893
903
  }
894
- /** Why Apple Intelligence does not answer right now; null while it does. */
895
- async function appleProblem() {
904
+ /**
905
+ * Why this Mac's models do not take a class right now; null while they do. Text needs Apple
906
+ * Intelligence switched on. A voice note needs only the Mac (macOS 26 on Apple silicon, the
907
+ * helper; the system fetches a language on its first note), and ffmpeg for a recording it
908
+ * cannot read itself: a browser's WebM or Ogg.
909
+ */
910
+ async function appleProblem(cls) {
896
911
  const status = await appleStatus();
897
- return status.available ? null : appleUnavailable(status);
912
+ if (cls !== "audio") {
913
+ return status.available ? null : appleUnavailable(status);
914
+ }
915
+ if (!status.supported || status.reason === "missing") {
916
+ return appleUnavailable(status);
917
+ }
918
+ return (await hasFfmpeg())
919
+ ? null
920
+ : "Aufnahmen aus Chrome oder Firefox (WebM, Ogg) schreibt dieser Mac erst mit ffmpeg auf; Safari und die App brauchen es nicht. ffmpeg installieren, z. B. mit „brew install ffmpeg“.";
898
921
  }
899
922
  /** At start the ways are asked once, so a model the key cannot reach shows before a run meets it. */
900
923
  export async function checkModelsAtStart() {
@@ -1,7 +1,7 @@
1
1
  import { createPublicKey, verify } from "node:crypto";
2
2
  import { env } from "../env.js";
3
3
  /**
4
- * The keys a Pro module's package must be signed with (docs/content/dev/plugins/pro-modules).
4
+ * The keys a Pro module's package must be signed with (docs/pro-modules.md).
5
5
  * Only the public halves are here; the private one signs in the build of the closed plugins and
6
6
  * is kept nowhere else. A new key is added beside the old one, which goes a release later.
7
7
  */
@@ -4,7 +4,7 @@ import { packageVersion } from "../cli/home.js";
4
4
  import { env } from "../env.js";
5
5
  import { managed } from "../manage.js";
6
6
  /**
7
- * Which Pro modules may load (docs/content/dev/plugins/pro-modules). A Pro module is a closed
7
+ * Which Pro modules may load (docs/pro-modules.md). A Pro module is a closed
8
8
  * plugin the linked account's plan includes, installed by pro.ts into a folder of its own. It
9
9
  * loads while the entitlement the account's Manage-App signed lists it and has not ended, and
10
10
  * only in the release it was built for. Kept apart from pro.ts, so the loader needs no network.
@@ -13,7 +13,7 @@ import { signedByUs } from "./pro-keys.js";
13
13
  import { currentEntitlement, ENTITLEMENT_SETTING, heldBackModules, INSTALLED_FILE, installedModule, proModulesDir, runtimeTag, setEntitlement, } from "./pro-state.js";
14
14
  import { loadedPlugin } from "./registry.js";
15
15
  /*
16
- * Pro modules on a runtime that runs alone (docs/content/dev/plugins/pro-modules): the closed
16
+ * Pro modules on a runtime that runs alone (docs/pro-modules.md): the closed
17
17
  * plugins the linked account's plan includes, fetched from its Manage-App.
18
18
  *
19
19
  * GET /v1/modules?runtime=<release> what is built for this release, the plan's
@@ -4,12 +4,12 @@ import { noteText } from "@engenty-wizards/shared/run";
4
4
  import { and, asc, eq, inArray, isNotNull } from "drizzle-orm";
5
5
  import { db, schema, withTenant } from "../db/client.js";
6
6
  import { answerAsk } from "../engine/asks.js";
7
- import { subscribe } from "../engine/events.js";
7
+ import { watchRun } from "../engine/events.js";
8
8
  import { cancel, createRun, goBack, NoCreditsError, RunInputError, retry, reviewStep, submitPage, } from "../engine/runner.js";
9
9
  import { saveAsset } from "../files/storage.js";
10
10
  import { wizardUnavailable } from "../limits.js";
11
11
  import { transcribeAudio } from "../media/transcribe.js";
12
- import { ModelUnavailableError } from "../model-errors.js";
12
+ import { errorText, ModelUnavailableError } from "../model-errors.js";
13
13
  import { runTicket } from "../secrets/signing.js";
14
14
  import { notFound, ServiceError } from "../services/errors.js";
15
15
  import { runnerSettingsOf, runnersOf } from "../services/runners.js";
@@ -38,20 +38,20 @@ export function runsApiFor(pluginId) {
38
38
  if (!w || w.publishedVersion === null) {
39
39
  throw notFound();
40
40
  }
41
+ const version = await db.query.wizardVersion.findFirst({
42
+ where: and(eq(schema.wizardVersion.wizardId, w.id), eq(schema.wizardVersion.version, w.publishedVersion)),
43
+ });
44
+ if (!version) {
45
+ throw notFound();
46
+ }
41
47
  const reason = await wizardUnavailable(w);
42
48
  if (reason) {
43
- throw new ServiceError("refused", reason);
49
+ throw new ServiceError("refused", noteText(reason, wizardLang(version.definition)));
44
50
  }
45
51
  const visitorId = visitorOf(input.person);
46
52
  if (await visitorOverLimit(visitorId, null)) {
47
53
  throw new ServiceError("refused", "This person started many runs lately. Try again in an hour.");
48
54
  }
49
- const version = await db.query.wizardVersion.findFirst({
50
- where: and(eq(schema.wizardVersion.wizardId, w.id), eq(schema.wizardVersion.version, w.publishedVersion)),
51
- });
52
- if (!version) {
53
- throw notFound();
54
- }
55
55
  const runId = await createRun({
56
56
  wizardId: w.id,
57
57
  definition: version.definition,
@@ -62,7 +62,7 @@ export function runsApiFor(pluginId) {
62
62
  runner: input.runner ?? pluginId,
63
63
  }).catch((err) => {
64
64
  if (err instanceof ModelUnavailableError) {
65
- throw new ServiceError("refused", err.message);
65
+ throw new ServiceError("refused", errorText(err, wizardLang(version.definition)));
66
66
  }
67
67
  if (err instanceof NoCreditsError) {
68
68
  throw new ServiceError("no_credits", "The wizard's credits are used up.");
@@ -126,7 +126,7 @@ export function runsApiFor(pluginId) {
126
126
  },
127
127
  async answerAsk(runId, askId, answer) {
128
128
  await pluginRun(runId);
129
- if (!answerAsk(runId, askId, answer === "allow" ? { type: "done" } : { type: "skip" })) {
129
+ if (!(await answerAsk(runId, askId, answer === "allow" ? { type: "done" } : { type: "skip" }))) {
130
130
  throw new ServiceError("refused", "This question is no longer open.");
131
131
  }
132
132
  },
@@ -138,10 +138,15 @@ export function runsApiFor(pluginId) {
138
138
  subscribe(runId, listener) {
139
139
  // The listener runs inside the tenant the subscription was made in, as the events do.
140
140
  const tenantId = currentTenant();
141
- return subscribe(runId, (signal) => {
142
- const event = signal.event;
141
+ return watchRun(runId, (signal) => {
142
+ // The runtime asking the phone around the runner to think is not a change of the run.
143
+ if (signal?.device) {
144
+ return;
145
+ }
146
+ // No signal: the run changed in another process (the runner), which tells no event.
147
+ const event = signal?.event;
143
148
  const shaped = {
144
- runId: signal.runId,
149
+ runId,
145
150
  event: event
146
151
  ? {
147
152
  id: event.id,
@@ -195,7 +200,7 @@ export function runsApiFor(pluginId) {
195
200
  call: { runId: run.id },
196
201
  }).catch((err) => {
197
202
  if (err instanceof ModelUnavailableError) {
198
- throw new ServiceError("refused", err.message);
203
+ throw new ServiceError("refused", errorText(err, wizardLang(run.definition)));
199
204
  }
200
205
  throw err;
201
206
  });
@@ -0,0 +1,54 @@
1
+ import { accessSync, constants, existsSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { delimiter, join } from "node:path";
4
+ /** The first executable called `name` in the folders of `path` (a PATH value). */
5
+ export function findOnPath(name, path) {
6
+ for (const dir of path.split(delimiter)) {
7
+ if (!dir) {
8
+ continue;
9
+ }
10
+ const file = join(dir, name);
11
+ try {
12
+ accessSync(file, constants.X_OK);
13
+ return file;
14
+ }
15
+ catch {
16
+ // not here
17
+ }
18
+ }
19
+ return null;
20
+ }
21
+ /**
22
+ * The browser the runtime renders PDF and PNG with and drives for websites: `CHROME_PATH`, else
23
+ * the first Chromium-based browser installed (Chrome, Edge, Chromium, Brave). The setup and
24
+ * `wizards doctor` report this one, and env.ts starts it, so a browser they show is the one used.
25
+ */
26
+ export function findChrome(env = process.env) {
27
+ if (env.CHROME_PATH) {
28
+ return existsSync(env.CHROME_PATH) ? env.CHROME_PATH : null;
29
+ }
30
+ if (process.platform === "darwin") {
31
+ const apps = [
32
+ "Google Chrome.app/Contents/MacOS/Google Chrome",
33
+ "Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
34
+ "Chromium.app/Contents/MacOS/Chromium",
35
+ "Brave Browser.app/Contents/MacOS/Brave Browser",
36
+ ];
37
+ const roots = ["/Applications", join(homedir(), "Applications")];
38
+ for (const app of apps) {
39
+ for (const root of roots) {
40
+ if (existsSync(join(root, app))) {
41
+ return join(root, app);
42
+ }
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+ for (const name of ["google-chrome", "chromium", "chromium-browser", "microsoft-edge"]) {
48
+ const file = findOnPath(name, env.PATH ?? "");
49
+ if (file) {
50
+ return file;
51
+ }
52
+ }
53
+ return null;
54
+ }