wizards 0.2.54 → 0.2.56
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.
- package/README.md +2 -2
- package/apps/runtime/dist/cli/autostart.js +1 -1
- package/apps/runtime/dist/cli/machine.js +5 -48
- package/apps/runtime/dist/cli/report.js +1 -1
- package/apps/runtime/dist/docs/dev/index.md +4 -4
- package/apps/runtime/dist/docs/dev/plugins/connections.md +4 -3
- package/apps/runtime/dist/docs/dev/plugins/events.md +1 -0
- package/apps/runtime/dist/docs/dev/plugins/examples.md +10 -9
- package/apps/runtime/dist/docs/dev/plugins/index.md +4 -3
- package/apps/runtime/dist/docs/dev/plugins/layout.md +2 -1
- package/apps/runtime/dist/docs/dev/plugins/meta.json +0 -1
- package/apps/runtime/dist/docs/dev/plugins/quick-start.md +4 -3
- package/apps/runtime/dist/docs/dev/plugins/reference.md +36 -14
- package/apps/runtime/dist/docs/dev/plugins/reloading.md +5 -5
- package/apps/runtime/dist/docs/dev/plugins/routes.md +30 -6
- package/apps/runtime/dist/docs/dev/plugins/runners.md +15 -10
- package/apps/runtime/dist/docs/dev/plugins/server.md +16 -7
- package/apps/runtime/dist/docs/dev/plugins/shipping.md +4 -26
- package/apps/runtime/dist/docs/dev/plugins/space.md +66 -53
- package/apps/runtime/dist/docs/dev/plugins/starters.md +10 -7
- package/apps/runtime/dist/docs/dev/plugins/studio.md +33 -12
- package/apps/runtime/dist/docs/dev/plugins/styling.md +19 -9
- package/apps/runtime/dist/docs/dev/plugins/tables.md +6 -4
- package/apps/runtime/dist/docs/dev/plugins/tools.md +22 -12
- package/apps/runtime/dist/docs/dev/wizard-format.md +3 -2
- package/apps/runtime/dist/docs/user/ai-apps.md +3 -1
- package/apps/runtime/dist/docs/user/assistant.md +5 -3
- package/apps/runtime/dist/docs/user/build-a-wizard.md +14 -2
- package/apps/runtime/dist/docs/user/command-line.md +16 -14
- package/apps/runtime/dist/docs/user/connectors.md +17 -12
- package/apps/runtime/dist/docs/user/data.md +14 -9
- package/apps/runtime/dist/docs/user/first-start.md +13 -6
- package/apps/runtime/dist/docs/user/index.md +2 -1
- package/apps/runtime/dist/docs/user/install.md +19 -11
- package/apps/runtime/dist/docs/user/models.md +44 -22
- package/apps/runtime/dist/docs/user/plugins.md +9 -4
- package/apps/runtime/dist/docs/user/run.md +14 -9
- package/apps/runtime/dist/docs/user/server.md +7 -5
- package/apps/runtime/dist/docs/user/space.md +15 -8
- package/apps/runtime/dist/docs/user/steps.md +33 -13
- package/apps/runtime/dist/docs/user/test-and-share.md +41 -25
- package/apps/runtime/dist/docs/user/troubleshooting.md +15 -7
- package/apps/runtime/dist/docs/user/wordpress.md +59 -49
- package/apps/runtime/dist/engine/runner.js +40 -18
- package/apps/runtime/dist/env.js +6 -3
- package/apps/runtime/dist/harness/apple.js +36 -21
- package/apps/runtime/dist/harness/claude.js +1 -1
- package/apps/runtime/dist/harness/model.js +2 -2
- package/apps/runtime/dist/limits.js +7 -4
- package/apps/runtime/dist/mcp/handler.js +2 -1
- package/apps/runtime/dist/mcp/tools.js +24 -11
- package/apps/runtime/dist/media/conversation.js +6 -5
- package/apps/runtime/dist/model-errors.js +22 -1
- package/apps/runtime/dist/models.js +30 -7
- package/apps/runtime/dist/plugins/pro-keys.js +1 -1
- package/apps/runtime/dist/plugins/pro-state.js +1 -1
- package/apps/runtime/dist/plugins/pro.js +1 -1
- package/apps/runtime/dist/plugins/runs.js +14 -10
- package/apps/runtime/dist/render/browser-path.js +54 -0
- package/apps/runtime/dist/routes/runs.js +51 -31
- package/apps/runtime/dist/routes/studio.js +7 -3
- package/apps/runtime/dist/services/api.js +3 -1
- package/apps/runtime/dist/services/package-file.js +8 -8
- package/apps/runtime/dist/update.js +1 -1
- package/apps/web/dist/assets/AboutDialog-Bv7p9iGr.js +1 -0
- package/apps/web/dist/assets/{ChangelogDialog-Da3M36M6.js → ChangelogDialog-D4sBrhi-.js} +1 -1
- package/apps/web/dist/assets/{ChatView-BGpIFoML.js → ChatView-Bntm0u8V.js} +1 -1
- package/apps/web/dist/assets/{EditorPage-DH6SrKPQ.js → EditorPage-DaVeNzHU.js} +2 -2
- package/apps/web/dist/assets/{FlowPreview-Cy_oSpCG.js → FlowPreview-C0tTz51A.js} +1 -1
- package/apps/web/dist/assets/{Harness-0TcBTo1Z.js → Harness-De-PsLFA.js} +1 -1
- package/apps/web/dist/assets/{Marketplace-D1iet5FD.js → Marketplace-7Bdv7Gd5.js} +2 -2
- package/apps/web/dist/assets/{NewWizardPage-CsuU51QL.js → NewWizardPage-CV7jrSkz.js} +1 -1
- package/apps/web/dist/assets/{ProjectPage-DCPKr4sC.js → ProjectPage-CBCd24oM.js} +1 -1
- package/apps/web/dist/assets/{PublicRunner-B6Er82D3.js → PublicRunner-CVmkHSnC.js} +1 -1
- package/apps/web/dist/assets/{ReadOnly-DiOfNtVr.js → ReadOnly-zQecD9OB.js} +1 -1
- package/apps/web/dist/assets/{RunDrawer-BbyQVQLN.js → RunDrawer-CvzuYc0d.js} +1 -1
- package/apps/web/dist/assets/{RunnerView-DdEKXIDX.js → RunnerView-BtZp1FD6.js} +1 -1
- package/apps/web/dist/assets/SettingsPage--Zj2pTgf.js +1 -0
- package/apps/web/dist/assets/SetupPage-F_e8f1to.js +1 -0
- package/apps/web/dist/assets/{SharePage-Bxnu_cet.js → SharePage-DLivbYu6.js} +1 -1
- package/apps/web/dist/assets/{brand-CwLcF9JR.js → brand-DIKyySmf.js} +1 -1
- package/apps/web/dist/assets/changelog-CWualFcc.js +1 -0
- package/apps/web/dist/assets/{circle-alert-BEDKtkJy.js → circle-alert-B9b9Vb9k.js} +1 -1
- package/apps/web/dist/assets/{esm-D2JnXDyS.js → esm-BMtXxAe0.js} +1 -1
- package/apps/web/dist/assets/{index-Cl4LqF22.js → index-MlQy_Qoy.js} +4 -4
- package/apps/web/dist/assets/{lock-Ce2ofIWG.js → lock-BNvsUKTg.js} +1 -1
- package/apps/web/dist/assets/session-CSbo-pmx.js +1 -0
- package/apps/web/dist/assets/{settings-menu-BT8cRZym.js → settings-menu-JtMfy9en.js} +1 -1
- package/apps/web/dist/assets/{ui-mkL5nF_f.js → ui-FW7ypPI6.js} +1 -1
- package/apps/web/dist/assets/{upload-BfrqabpO.js → upload-MQ_24gSb.js} +1 -1
- package/apps/web/dist/assets/{volume-2-C3GeMqc-.js → volume-2-B1mj20eS.js} +1 -1
- package/apps/web/dist/index.html +6 -6
- package/apps/web/dist/install.sh +2 -2
- package/apps/web/dist/mcp/flow.html +1 -1
- package/modules/calls/dist/client.css +1 -1
- package/modules/sms/dist/client.css +1 -1
- package/modules/whatsapp/dist/client.css +1 -1
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +152 -2
- package/node_modules/@engenty-wizards/shared/dist/run.js +135 -1
- package/package.json +2 -2
- package/apps/runtime/dist/docs/dev/plugins/pro-modules.md +0 -59
- package/apps/web/dist/assets/AboutDialog-BXpMzzUl.js +0 -1
- package/apps/web/dist/assets/SettingsPage-D6KuKcBL.js +0 -1
- package/apps/web/dist/assets/SetupPage-DuD0AD0f.js +0 -1
- package/apps/web/dist/assets/changelog-Cu_CVR3H.js +0 -1
- package/apps/web/dist/assets/session-BuVghS-e.js +0 -1
|
@@ -48,6 +48,10 @@ function failure(err) {
|
|
|
48
48
|
}
|
|
49
49
|
return { isError: true, content: [{ type: "text", text: JSON.stringify(body) }] };
|
|
50
50
|
}
|
|
51
|
+
/** Where a space comes from, as the person knows it: sent by their local install, or made here. */
|
|
52
|
+
function spaceFrom(p) {
|
|
53
|
+
return p.origin === "local" ? "your computer" : "here";
|
|
54
|
+
}
|
|
51
55
|
export function registerTools(server, who) {
|
|
52
56
|
const writer = { source: "mcp", client: who.client };
|
|
53
57
|
const tool = (name, scope, config, run) => {
|
|
@@ -173,28 +177,37 @@ export function registerTools(server, who) {
|
|
|
173
177
|
});
|
|
174
178
|
tool("list_projects", "wizards:read", {
|
|
175
179
|
title: "List projects",
|
|
176
|
-
description: "The admin's projects. Each holds wizards, a brand and MCP servers.",
|
|
180
|
+
description: "The admin's projects, called spaces in the studio. Each holds wizards, a brand and MCP servers. Name a space by its name; where two share one, add where it comes from (`from`). Ids are for the tools: never show them to the person.",
|
|
177
181
|
input: z.object({}),
|
|
178
182
|
readOnly: true,
|
|
179
183
|
}, async () => (await listProjects(who.userId)).map((p) => ({
|
|
180
184
|
id: p.id,
|
|
181
185
|
name: p.name,
|
|
186
|
+
from: spaceFrom(p),
|
|
182
187
|
wizardCount: p.wizardCount,
|
|
183
188
|
})));
|
|
184
189
|
tool("list_wizards", "wizards:read", {
|
|
185
190
|
title: "List wizards",
|
|
186
|
-
description: "The admin's wizards, newest first.",
|
|
191
|
+
description: "The admin's wizards, newest first, each with its space's name and where that space comes from. Ids are for the tools: never show them to the person.",
|
|
187
192
|
input: z.object({ projectId: z.string().optional() }),
|
|
188
193
|
readOnly: true,
|
|
189
|
-
}, async ({ projectId }) =>
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
}, async ({ projectId }) => {
|
|
195
|
+
const spaces = new Map((await listProjects(who.userId)).map((p) => [p.id, p]));
|
|
196
|
+
return (await listWizards(who.userId, projectId)).map((w) => {
|
|
197
|
+
const space = spaces.get(w.projectId);
|
|
198
|
+
return {
|
|
199
|
+
id: w.id,
|
|
200
|
+
projectId: w.projectId,
|
|
201
|
+
space: space?.name ?? null,
|
|
202
|
+
spaceFrom: space ? spaceFrom(space) : null,
|
|
203
|
+
title: w.title,
|
|
204
|
+
revision: w.revision,
|
|
205
|
+
published: w.published,
|
|
206
|
+
updatedAt: w.updatedAt,
|
|
207
|
+
studioUrl: studioUrl(w.id),
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
});
|
|
198
211
|
tool("get_wizard", "wizards:read", {
|
|
199
212
|
title: "Get wizard",
|
|
200
213
|
description: "A wizard's draft with its revision and validator issues, whether it differs from the published version, and its links.",
|
|
@@ -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
|
|
164
|
-
?
|
|
165
|
-
:
|
|
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
|
|
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
|
|
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(
|
|
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 {
|
|
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
|
-
/**
|
|
895
|
-
|
|
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
|
-
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
@@ -9,7 +9,7 @@ import { cancel, createRun, goBack, NoCreditsError, RunInputError, retry, review
|
|
|
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.
|
|
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.");
|
|
@@ -139,6 +139,10 @@ export function runsApiFor(pluginId) {
|
|
|
139
139
|
// The listener runs inside the tenant the subscription was made in, as the events do.
|
|
140
140
|
const tenantId = currentTenant();
|
|
141
141
|
return subscribe(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
|
+
}
|
|
142
146
|
const event = signal.event;
|
|
143
147
|
const shaped = {
|
|
144
148
|
runId: signal.runId,
|
|
@@ -195,7 +199,7 @@ export function runsApiFor(pluginId) {
|
|
|
195
199
|
call: { runId: run.id },
|
|
196
200
|
}).catch((err) => {
|
|
197
201
|
if (err instanceof ModelUnavailableError) {
|
|
198
|
-
throw new ServiceError("refused", err.
|
|
202
|
+
throw new ServiceError("refused", errorText(err, wizardLang(run.definition)));
|
|
199
203
|
}
|
|
200
204
|
throw err;
|
|
201
205
|
});
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FORMATS, LIST_FORMATS, TEXT_CLASSES } from "@engenty-wizards/shared/definition";
|
|
2
2
|
import { TableColumnValueError } from "@engenty-wizards/shared/engenty/data-tables";
|
|
3
|
+
import { noteText } from "@engenty-wizards/shared/run";
|
|
3
4
|
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
4
5
|
import { and, eq } from "drizzle-orm";
|
|
5
6
|
import { Hono } from "hono";
|
|
@@ -17,14 +18,14 @@ import { answerDevice, offerDevice } from "../engine/device.js";
|
|
|
17
18
|
import { emitEvent, signalChanged, subscribe } from "../engine/events.js";
|
|
18
19
|
import { pushAvailable, setPushDevice } from "../engine/push.js";
|
|
19
20
|
import { liveResources } from "../engine/resources.js";
|
|
20
|
-
import { cancel, createRun, goBack, NoCreditsError, projectIdOf, RunConflict, RunInputError, retry, reviewStep, runView, submitPage, } from "../engine/runner.js";
|
|
21
|
+
import { cancel, createRun, goBack, NoCreditsError, projectIdOf, RunConflict, RunInputError, retry, reviewStep, runView, submitPage, talkAllowed, } from "../engine/runner.js";
|
|
21
22
|
import { basePath, env } from "../env.js";
|
|
22
23
|
import { loadAsset, saveAsset } from "../files/storage.js";
|
|
23
24
|
import { reverseGeocode } from "../geocode.js";
|
|
24
25
|
import { allowed, hashIp, verifyTurnstile, wizardUnavailable } from "../limits.js";
|
|
25
26
|
import { mintConversation } from "../media/conversation.js";
|
|
26
27
|
import { transcribeAudio } from "../media/transcribe.js";
|
|
27
|
-
import { ModelUnavailableError } from "../model-errors.js";
|
|
28
|
+
import { errorText, ModelUnavailableError, noteOf } from "../model-errors.js";
|
|
28
29
|
import { listDownload, renderDownload, stepHtml } from "../render/downloads.js";
|
|
29
30
|
import { HTML_RESPONSE_CSP } from "../render/guard.js";
|
|
30
31
|
import { runTicketValid, verifySignedUrl } from "../secrets/signing.js";
|
|
@@ -51,6 +52,19 @@ export function clientIp(c) {
|
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* The language a visitor's request asks for: what the runner around it speaks, the browser's
|
|
57
|
+
* first language (apps/web: `navigator.language`) — German for "de…", else English; German
|
|
58
|
+
* without one, as the runner starts.
|
|
59
|
+
*/
|
|
60
|
+
function requestLang(c) {
|
|
61
|
+
const asked = c.req.header("accept-language")?.trim().toLowerCase();
|
|
62
|
+
return !asked || asked.startsWith("de") ? "de" : "en";
|
|
63
|
+
}
|
|
64
|
+
/** A refusal the visitor reads, in the language their request asks for. */
|
|
65
|
+
function refuse(c, note, status) {
|
|
66
|
+
return c.json({ error: noteText(note, requestLang(c)) }, status);
|
|
67
|
+
}
|
|
54
68
|
/**
|
|
55
69
|
* The mobile app's own requests (a run's view, downloads) name the visitor in a header: iOS
|
|
56
70
|
* merges a Cookie header the app sets with its own cookie store (`wz_vid=a,wz_vid=a`). The header
|
|
@@ -125,10 +139,10 @@ async function viewOf(run) {
|
|
|
125
139
|
}
|
|
126
140
|
function commandError(c, err) {
|
|
127
141
|
if (err instanceof RunInputError) {
|
|
128
|
-
return c.json({ error: err
|
|
142
|
+
return c.json({ error: errorText(err, requestLang(c)), fields: err.errors }, 422);
|
|
129
143
|
}
|
|
130
144
|
if (err instanceof RunConflict) {
|
|
131
|
-
return c.json({ error: err
|
|
145
|
+
return c.json({ error: errorText(err, requestLang(c)) }, 409);
|
|
132
146
|
}
|
|
133
147
|
throw err;
|
|
134
148
|
}
|
|
@@ -143,7 +157,7 @@ function tenantFrom(find) {
|
|
|
143
157
|
return c.json({ error: "not found" }, 404);
|
|
144
158
|
}
|
|
145
159
|
if ((await tenantStatus(tenant)) === "suspended") {
|
|
146
|
-
return c
|
|
160
|
+
return refuse(c, { code: "wizardUnavailable" }, 403);
|
|
147
161
|
}
|
|
148
162
|
return withTenant(tenant, next);
|
|
149
163
|
};
|
|
@@ -227,7 +241,7 @@ export const publicRoutes = new Hono()
|
|
|
227
241
|
brand: await brandView(w.projectId),
|
|
228
242
|
turnstileSiteKey: env.turnstile.siteKey || null,
|
|
229
243
|
available: !reason,
|
|
230
|
-
unavailableReason: reason,
|
|
244
|
+
unavailableReason: reason && noteText(reason, requestLang(c)),
|
|
231
245
|
runners: await publicRunners(w, def),
|
|
232
246
|
};
|
|
233
247
|
return c.json(body);
|
|
@@ -241,7 +255,7 @@ export const publicRoutes = new Hono()
|
|
|
241
255
|
}
|
|
242
256
|
const reason = await wizardUnavailable(w);
|
|
243
257
|
if (reason) {
|
|
244
|
-
return c
|
|
258
|
+
return refuse(c, reason, 403);
|
|
245
259
|
}
|
|
246
260
|
const body = z
|
|
247
261
|
.object({
|
|
@@ -253,14 +267,12 @@ export const publicRoutes = new Hono()
|
|
|
253
267
|
.parse(await c.req.json().catch(() => ({})));
|
|
254
268
|
const ip = clientIp(c);
|
|
255
269
|
if (!(await verifyTurnstile(body.turnstileToken, ip))) {
|
|
256
|
-
return c
|
|
270
|
+
return refuse(c, { code: "confirmHuman" }, 403);
|
|
257
271
|
}
|
|
258
272
|
const vid = visitorId(c, true, body.embedded);
|
|
259
273
|
const ipHash = hashIp(ip);
|
|
260
274
|
if (await visitorOverLimit(vid, ipHash)) {
|
|
261
|
-
return c
|
|
262
|
-
error: "Du hast gerade viele Durchläufe gestartet. Bitte versuche es in einer Stunde wieder.",
|
|
263
|
-
}, 429);
|
|
275
|
+
return refuse(c, { code: "tooManyRuns" }, 429);
|
|
264
276
|
}
|
|
265
277
|
const version = await db.query.wizardVersion.findFirst({
|
|
266
278
|
where: and(eq(schema.wizardVersion.wizardId, w.id), eq(schema.wizardVersion.version, w.publishedVersion)),
|
|
@@ -280,7 +292,7 @@ export const publicRoutes = new Hono()
|
|
|
280
292
|
}
|
|
281
293
|
catch (err) {
|
|
282
294
|
if (err instanceof NoCreditsError || err instanceof ModelUnavailableError) {
|
|
283
|
-
return c
|
|
295
|
+
return refuse(c, { code: "wizardUnavailable" }, 403);
|
|
284
296
|
}
|
|
285
297
|
throw err;
|
|
286
298
|
}
|
|
@@ -526,10 +538,13 @@ export const runRoutes = new Hono()
|
|
|
526
538
|
return c.json({ error: "not found" }, 404);
|
|
527
539
|
}
|
|
528
540
|
if (run.status === "done" || run.status === "cancelled" || run.status === "failed") {
|
|
529
|
-
return c
|
|
541
|
+
return refuse(c, { code: "runOver" }, 409);
|
|
542
|
+
}
|
|
543
|
+
if (!(await talkAllowed(run))) {
|
|
544
|
+
return refuse(c, { code: "talkOff" }, 403);
|
|
530
545
|
}
|
|
531
546
|
if (!allowed(`talk:${run.id}`, 20, 3600_000)) {
|
|
532
|
-
return c
|
|
547
|
+
return refuse(c, { code: "tryLater" }, 429);
|
|
533
548
|
}
|
|
534
549
|
try {
|
|
535
550
|
const view = await viewOf(run);
|
|
@@ -537,10 +552,10 @@ export const runRoutes = new Hono()
|
|
|
537
552
|
}
|
|
538
553
|
catch (err) {
|
|
539
554
|
if (err instanceof ModelUnavailableError) {
|
|
540
|
-
return c.json({ error: err
|
|
555
|
+
return c.json({ error: errorText(err, requestLang(c)) }, 403);
|
|
541
556
|
}
|
|
542
557
|
console.error("[talk]", err);
|
|
543
|
-
return c.json({ error: err
|
|
558
|
+
return c.json({ error: errorText(err, requestLang(c)) }, 502);
|
|
544
559
|
}
|
|
545
560
|
})
|
|
546
561
|
// What the person says into the chat's composer, written down — where the browser cannot do it itself.
|
|
@@ -550,14 +565,14 @@ export const runRoutes = new Hono()
|
|
|
550
565
|
return c.json({ error: "not found" }, 404);
|
|
551
566
|
}
|
|
552
567
|
if (run.status === "done" || run.status === "cancelled" || run.status === "failed") {
|
|
553
|
-
return c
|
|
568
|
+
return refuse(c, { code: "runOver" }, 409);
|
|
554
569
|
}
|
|
555
570
|
if (!allowed(`transcribe:${run.id}`, 60, 3600_000)) {
|
|
556
|
-
return c
|
|
571
|
+
return refuse(c, { code: "tryLater" }, 429);
|
|
557
572
|
}
|
|
558
573
|
const file = (await c.req.formData()).get("file");
|
|
559
574
|
if (!(file instanceof File) || !file.size || file.size > 10_000_000) {
|
|
560
|
-
return c
|
|
575
|
+
return refuse(c, { code: "recordingTooLarge" }, 400);
|
|
561
576
|
}
|
|
562
577
|
try {
|
|
563
578
|
const { text } = await transcribeAudio({
|
|
@@ -569,7 +584,11 @@ export const runRoutes = new Hono()
|
|
|
569
584
|
}
|
|
570
585
|
catch (err) {
|
|
571
586
|
if (err instanceof ModelUnavailableError) {
|
|
572
|
-
return c.json({ error: err
|
|
587
|
+
return c.json({ error: errorText(err, requestLang(c)) }, 403);
|
|
588
|
+
}
|
|
589
|
+
// Apple Intelligence on this Mac says why in a note (harness/apple.ts).
|
|
590
|
+
if (noteOf(err)) {
|
|
591
|
+
return c.json({ error: errorText(err, requestLang(c)) }, 502);
|
|
573
592
|
}
|
|
574
593
|
throw err;
|
|
575
594
|
}
|
|
@@ -585,7 +604,7 @@ export const runRoutes = new Hono()
|
|
|
585
604
|
const mime = file instanceof File ? file.type.split(";")[0].trim().toLowerCase() : "";
|
|
586
605
|
const limit = uploadLimit(mime);
|
|
587
606
|
if (!(file instanceof File) || file.size > limit) {
|
|
588
|
-
return c
|
|
607
|
+
return refuse(c, { code: "fileTooLarge", params: { mb: Math.round(limit / 1_000_000) } }, 400);
|
|
589
608
|
}
|
|
590
609
|
const ref = await saveAsset({
|
|
591
610
|
runId: run.id,
|
|
@@ -643,7 +662,7 @@ export const runRoutes = new Hono()
|
|
|
643
662
|
])
|
|
644
663
|
.parse(await c.req.json());
|
|
645
664
|
if (!answerAsk(run.id, c.req.param("askId"), answer)) {
|
|
646
|
-
return c
|
|
665
|
+
return refuse(c, { code: "askClosed" }, 409);
|
|
647
666
|
}
|
|
648
667
|
return c.json({ ok: true });
|
|
649
668
|
})
|
|
@@ -662,7 +681,7 @@ export const runRoutes = new Hono()
|
|
|
662
681
|
const run = await accessibleRun(c, c.req.param("id"));
|
|
663
682
|
const resources = run?.status === "running" ? liveResources(run.id) : null;
|
|
664
683
|
if (!(run && resources?.openPage())) {
|
|
665
|
-
return c
|
|
684
|
+
return refuse(c, { code: "noBrowser" }, 409);
|
|
666
685
|
}
|
|
667
686
|
const { to } = z.object({ to: z.enum(["person", "agent"]) }).parse(await c.req.json());
|
|
668
687
|
if (resources.seatHolder() !== to) {
|
|
@@ -752,7 +771,7 @@ export const runRoutes = new Hono()
|
|
|
752
771
|
const theirs = run && (pendingAsk(run.id) || resources?.seatHolder() === "person");
|
|
753
772
|
const page = theirs ? resources?.openPage() : null;
|
|
754
773
|
if (!(run && resources && page)) {
|
|
755
|
-
return c
|
|
774
|
+
return refuse(c, { code: "notWaiting" }, 409);
|
|
756
775
|
}
|
|
757
776
|
resources.touchSeat();
|
|
758
777
|
const act = z
|
|
@@ -794,7 +813,7 @@ export const runRoutes = new Hono()
|
|
|
794
813
|
await page.waitForLoadState("domcontentloaded", { timeout: 3000 }).catch(() => undefined);
|
|
795
814
|
}
|
|
796
815
|
catch {
|
|
797
|
-
return c
|
|
816
|
+
return refuse(c, { code: "pageActFailed" }, 422);
|
|
798
817
|
}
|
|
799
818
|
return c.json({ ok: true });
|
|
800
819
|
})
|
|
@@ -1039,9 +1058,9 @@ export const connectCallback = new Hono().get("/callback", async (c) => {
|
|
|
1039
1058
|
const ticket = c.req.query("ticket");
|
|
1040
1059
|
const state = c.req.query("state");
|
|
1041
1060
|
let ok = false;
|
|
1042
|
-
let
|
|
1043
|
-
?
|
|
1044
|
-
:
|
|
1061
|
+
let said = c.req.query("error") === "exchange_failed"
|
|
1062
|
+
? { code: "connectFailed" }
|
|
1063
|
+
: { code: "connectCancelled" };
|
|
1045
1064
|
// A plugin's sign-in (server.connections) names its tenant; a wizard's names its run.
|
|
1046
1065
|
const pluginTenant = state ? pluginStateTenant(state) : null;
|
|
1047
1066
|
const tenant = state ? (pluginTenant ?? (await tenantOfRun(oauthStateRun(state) ?? ""))) : null;
|
|
@@ -1056,13 +1075,14 @@ export const connectCallback = new Hono().get("/callback", async (c) => {
|
|
|
1056
1075
|
signalChanged(done.runId);
|
|
1057
1076
|
}
|
|
1058
1077
|
ok = true;
|
|
1059
|
-
|
|
1078
|
+
said = { code: "connected" };
|
|
1060
1079
|
}
|
|
1061
1080
|
catch (err) {
|
|
1062
1081
|
console.error("[connect]", err);
|
|
1063
|
-
|
|
1082
|
+
said = { code: "connectFailed" };
|
|
1064
1083
|
}
|
|
1065
1084
|
}
|
|
1085
|
+
const message = noteText(said, requestLang(c));
|
|
1066
1086
|
return c.html(`<!doctype html><meta charset="utf-8"><title>engenty wizards</title>
|
|
1067
1087
|
<body style="font:16px system-ui;display:grid;place-items:center;height:100vh;margin:0;color:#333">
|
|
1068
1088
|
<p>${message}</p>
|
|
@@ -1141,7 +1161,7 @@ export const shareRoutes = new Hono()
|
|
|
1141
1161
|
.get("/:token", async (c) => {
|
|
1142
1162
|
const run = await sharedRun(c.req.param("token"));
|
|
1143
1163
|
if (!run) {
|
|
1144
|
-
return c
|
|
1164
|
+
return refuse(c, { code: "linkGone" }, 404);
|
|
1145
1165
|
}
|
|
1146
1166
|
return c.json(await shareView(run));
|
|
1147
1167
|
})
|
|
@@ -64,13 +64,17 @@ async function testedSources() {
|
|
|
64
64
|
const tested = await readSetting("setup-done");
|
|
65
65
|
return Array.isArray(tested) ? tested : [];
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* The chosen source has passed a test call and can still answer: its client is there and signed
|
|
69
|
+
* in. Where Apple Intelligence thinks the short classes, the test ran there; a client behind High
|
|
70
|
+
* and Highest is no condition then.
|
|
71
|
+
*/
|
|
68
72
|
async function setupDone() {
|
|
69
|
-
const source = localModelSettings()
|
|
73
|
+
const { source, bindings } = localModelSettings();
|
|
70
74
|
if (!(await testedSources()).includes(source)) {
|
|
71
75
|
return false;
|
|
72
76
|
}
|
|
73
|
-
const client = harness(source);
|
|
77
|
+
const client = bindings.standard.startsWith("apple:") ? null : harness(source);
|
|
74
78
|
if (client) {
|
|
75
79
|
const status = await detectHarness(client.id);
|
|
76
80
|
return Boolean(status?.version) && status?.auth !== "none";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { wizardLang } from "@engenty-wizards/shared/definition";
|
|
1
2
|
import { standaloneEntry } from "@engenty-wizards/shared/fit";
|
|
2
3
|
import { pluginsOf } from "@engenty-wizards/shared/marketplace";
|
|
4
|
+
import { noteText } from "@engenty-wizards/shared/run";
|
|
3
5
|
import { and, count, desc, eq, gte, inArray, isNotNull, or, sql } from "drizzle-orm";
|
|
4
6
|
import { MICROS_PER_CREDIT } from "../credits/credits.js";
|
|
5
7
|
import { db, schema } from "../db/client.js";
|
|
@@ -98,7 +100,7 @@ export async function apiWizards(userId, spaceId) {
|
|
|
98
100
|
? `${env.appUrl}/api/public/wizards/${w.shareToken}/icons/icon-192.png`
|
|
99
101
|
: null,
|
|
100
102
|
available: Boolean(live) && !reason,
|
|
101
|
-
unavailableReason: reason,
|
|
103
|
+
unavailableReason: reason && noteText(reason, wizardLang(def)),
|
|
102
104
|
dailyRunLimit: w.dailyRunLimit,
|
|
103
105
|
/** The plugins its steps call: a wizard that books needs `appointments`. */
|
|
104
106
|
plugins: pluginsOf(def),
|