wizards 0.2.41 → 0.2.43
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/apps/runtime/dist/app.js +37 -3
- package/apps/runtime/dist/authoring/guide.js +5 -2
- package/apps/runtime/dist/browser/fast/action-space.js +162 -0
- package/apps/runtime/dist/browser/fast/classifier.js +91 -0
- package/apps/runtime/dist/browser/fast/decide.js +171 -0
- package/apps/runtime/dist/browser/fast/driver.js +141 -0
- package/apps/runtime/dist/browser/fast/instructions.js +33 -0
- package/apps/runtime/dist/browser/fast/run.js +249 -0
- package/apps/runtime/dist/browser/fast/span-picker.js +153 -0
- package/apps/runtime/dist/browser/fast/text-helper.js +178 -0
- package/apps/runtime/dist/browser/snapshot.js +335 -0
- package/apps/runtime/dist/db/migrations/tenant/0011_runners.sql +2 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/0011_snapshot.json +2956 -0
- package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
- package/apps/runtime/dist/db/schema.js +4 -0
- package/apps/runtime/dist/engine/resources.js +109 -0
- package/apps/runtime/dist/engine/runner.js +7 -3
- package/apps/runtime/dist/engine/steps.js +89 -10
- package/apps/runtime/dist/env.js +9 -0
- package/apps/runtime/dist/harness/claude.js +9 -1
- package/apps/runtime/dist/link-preview.js +4 -3
- package/apps/runtime/dist/mcp/tools.js +1 -1
- package/apps/runtime/dist/media/conversation.js +177 -0
- package/apps/runtime/dist/models.js +17 -0
- package/apps/runtime/dist/plugins/loader.js +48 -2
- package/apps/runtime/dist/plugins/registry.js +1 -0
- package/apps/runtime/dist/plugins/runs.js +205 -0
- package/apps/runtime/dist/routes/runs.js +206 -22
- package/apps/runtime/dist/routes/studio.js +12 -1
- package/apps/runtime/dist/services/cloud.js +1 -0
- package/apps/runtime/dist/services/runners.js +138 -0
- package/apps/runtime/dist/services/runs.js +83 -45
- package/apps/runtime/dist/services/wizard-icon.js +12 -0
- package/apps/runtime/dist/services/wizards.js +5 -1
- package/apps/runtime/dist/tools/browser.js +426 -97
- package/apps/runtime/dist/tools/index.js +50 -3
- package/apps/web/dist/assets/ChangelogDialog-8qS5utcR.js +1 -0
- package/apps/web/dist/assets/ChatView-Bx1KVCEf.js +10 -0
- package/apps/web/dist/assets/{CreditsDialog-DnI1-cxI.js → CreditsDialog-BCuDsatt.js} +1 -1
- package/apps/web/dist/assets/EditorPage-_Sbj-mSD.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-8sN-J3Wt.js → FlowPreview-COgjib4H.js} +1 -1
- package/apps/web/dist/assets/{Harness-BQIznJjo.js → Harness-BaxjV1Ng.js} +2 -2
- package/apps/web/dist/assets/HomePage-BlD0wZB0.js +1 -0
- package/apps/web/dist/assets/ImportWizard-BZDtNJg1.js +1 -0
- package/apps/web/dist/assets/NewWizardPage-Ci_x__p9.js +2 -0
- package/apps/web/dist/assets/ProjectPage-NwFut2Z-.js +2 -0
- package/apps/web/dist/assets/PublicRunner-rHdvK18v.js +1 -0
- package/apps/web/dist/assets/RunDrawer-Dp-JowDX.js +4 -0
- package/apps/web/dist/assets/RunnerView-DSlReODC.js +2 -0
- package/apps/web/dist/assets/SettingsPage-2Bw-D3hC.js +1 -0
- package/apps/web/dist/assets/SetupPage-DHESCsTb.js +1 -0
- package/apps/web/dist/assets/SharePage-DdJ-qD-B.js +1 -0
- package/apps/web/dist/assets/ThemeSwitch-BkodFy16.js +1 -0
- package/apps/web/dist/assets/arrow-right-pf8p4FIz.js +1 -0
- package/apps/web/dist/assets/changelog-cmQb-lZW.js +1 -0
- package/apps/web/dist/assets/{circle-alert-BAwp-sT4.js → circle-alert-Gn4D6etf.js} +1 -1
- package/apps/web/dist/assets/{copy-DbRfBUN6.js → copy-C3D7PBYL.js} +1 -1
- package/apps/web/dist/assets/{definition-pJhOorRU.js → definition-AlI4g-wR.js} +2 -2
- package/apps/web/dist/assets/{external-link-Ckgj8QwI.js → external-link-M3mEgZA-.js} +1 -1
- package/apps/web/dist/assets/globe-BnaeE83w.js +1 -0
- package/apps/web/dist/assets/{image-D9msyNQi.js → image-BuasG4Jr.js} +1 -1
- package/apps/web/dist/assets/index-BdrX1tJ4.js +78 -0
- package/apps/web/dist/assets/index-D6vcOCCh.css +1 -0
- package/apps/web/dist/assets/{lock-B5ky3SKB.js → lock-CrB_z7n3.js} +1 -1
- package/apps/web/dist/assets/{meta-BZ2z-OsJ.js → meta-CT4LmQ7g.js} +1 -1
- package/apps/web/dist/assets/mouse-pointer-click-BurvPVO8.js +1 -0
- package/apps/web/dist/assets/{pen-line-nCoUBOra.js → pen-line-BA6l84zC.js} +1 -1
- package/apps/web/dist/assets/{refresh-cw-Q00Jfvvq.js → refresh-cw-DEKCEuIO.js} +1 -1
- package/apps/web/dist/assets/{session-CjfNwKNU.js → session-DCcgTTmG.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-DA3a4Ys5.js → settings-menu-C9fE9M0f.js} +1 -1
- package/apps/web/dist/assets/star-BwhVXiJM.js +1 -0
- package/apps/web/dist/assets/{trash-BlT75Cyj.js → trash-WwlTeE_V.js} +1 -1
- package/apps/web/dist/assets/{type-BmqZVGnw.js → type-kpWj7Zf1.js} +1 -1
- package/apps/web/dist/assets/ui-Wxaw_APn.js +9 -0
- package/apps/web/dist/assets/{video-BGwhi8uR.js → video-U-idAC66.js} +1 -1
- package/apps/web/dist/assets/volume-2-BwidpioC.js +1 -0
- package/apps/web/dist/assets/{wand-sparkles-7vcrrSnD.js → wand-sparkles-DaINku4r.js} +1 -1
- package/apps/web/dist/embed.js +119 -4
- package/apps/web/dist/index.html +13 -11
- package/apps/web/dist/mcp/flow.html +45 -45
- package/modules/calls/dist/client.css +3 -0
- package/modules/calls/dist/client.js +1 -0
- package/modules/calls/engenty.plugin.json +8 -0
- package/modules/calls/migrations/0001_init.sql +26 -0
- package/modules/calls/package.json +25 -0
- package/modules/calls/src/openai.ts +155 -0
- package/modules/calls/src/plugin.ts +407 -0
- package/modules/calls/src/rules.ts +226 -0
- package/modules/calls/src/schema.ts +39 -0
- package/modules/calls/src/session.ts +353 -0
- package/modules/calls/src/store.ts +124 -0
- package/modules/calls/src/twilio.ts +90 -0
- package/modules/calls/tsconfig.json +10 -0
- package/modules/calls/ui/Settings.tsx +137 -0
- package/modules/calls/ui/app.ts +50 -0
- package/modules/calls/ui/messages.ts +81 -0
- package/modules/calls/ui/parts.tsx +36 -0
- package/modules/calls/ui/plugin.tsx +15 -0
- package/modules/sms/dist/client.css +3 -0
- package/modules/sms/dist/client.js +1 -0
- package/modules/sms/engenty.plugin.json +8 -0
- package/modules/sms/migrations/0001_init.sql +26 -0
- package/modules/sms/package.json +25 -0
- package/modules/sms/src/plugin.ts +324 -0
- package/modules/sms/src/schema.ts +26 -0
- package/modules/sms/src/store.ts +140 -0
- package/modules/sms/src/surface.ts +70 -0
- package/modules/sms/src/twilio.ts +130 -0
- package/modules/sms/tsconfig.json +10 -0
- package/modules/sms/ui/Settings.tsx +113 -0
- package/modules/sms/ui/Share.tsx +78 -0
- package/modules/sms/ui/app.ts +51 -0
- package/modules/sms/ui/messages.ts +72 -0
- package/modules/sms/ui/parts.tsx +36 -0
- package/modules/sms/ui/plugin.tsx +20 -0
- package/modules/whatsapp/dist/client.css +3 -0
- package/modules/whatsapp/dist/client.js +1 -0
- package/modules/whatsapp/engenty.plugin.json +8 -0
- package/modules/whatsapp/migrations/0001_init.sql +30 -0
- package/modules/whatsapp/package.json +25 -0
- package/modules/whatsapp/src/graph.ts +271 -0
- package/modules/whatsapp/src/inbound.ts +143 -0
- package/modules/whatsapp/src/plugin.ts +369 -0
- package/modules/whatsapp/src/schema.ts +32 -0
- package/modules/whatsapp/src/store.ts +156 -0
- package/modules/whatsapp/src/surface.ts +127 -0
- package/modules/whatsapp/tsconfig.json +10 -0
- package/modules/whatsapp/ui/Settings.tsx +141 -0
- package/modules/whatsapp/ui/Share.tsx +78 -0
- package/modules/whatsapp/ui/app.ts +54 -0
- package/modules/whatsapp/ui/messages.ts +82 -0
- package/modules/whatsapp/ui/parts.tsx +36 -0
- package/modules/whatsapp/ui/plugin.tsx +20 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +259 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/studio.d.ts +17 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.d.ts +174 -0
- package/node_modules/@engenty-wizards/plugin-sdk/dist/thread.js +816 -0
- package/node_modules/@engenty-wizards/plugin-sdk/package.json +2 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +8 -0
- package/node_modules/@engenty-wizards/shared/dist/definition.js +21 -0
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +61 -3
- package/node_modules/@engenty-wizards/shared/dist/run.js +16 -0
- package/node_modules/@engenty-wizards/shared/dist/runners.d.ts +81 -0
- package/node_modules/@engenty-wizards/shared/dist/runners.js +146 -0
- package/package.json +1 -1
- package/apps/web/dist/assets/ChangelogDialog-D3nkBHzo.js +0 -1
- package/apps/web/dist/assets/EditorPage-Bl6kef8d.js +0 -3
- package/apps/web/dist/assets/HomePage-BRz-wGtK.js +0 -1
- package/apps/web/dist/assets/ImportWizard-B2STI62b.js +0 -1
- package/apps/web/dist/assets/NewWizardPage-3Bl7JPTj.js +0 -2
- package/apps/web/dist/assets/ProjectPage-CuurGBsI.js +0 -2
- package/apps/web/dist/assets/PublicRunner-DDFg4Dfr.js +0 -1
- package/apps/web/dist/assets/RunDrawer-CMr7z8PZ.js +0 -4
- package/apps/web/dist/assets/RunnerView-DyMVB56S.js +0 -2
- package/apps/web/dist/assets/SettingsPage-VeFv2IjG.js +0 -1
- package/apps/web/dist/assets/SetupPage-Db4fhE5q.js +0 -1
- package/apps/web/dist/assets/SharePage-zCPxDPTo.js +0 -1
- package/apps/web/dist/assets/ThemeSwitch-BOlH2F42.js +0 -1
- package/apps/web/dist/assets/arrow-right-CtFLf9GU.js +0 -1
- package/apps/web/dist/assets/changelog-BKYvAkhc.js +0 -1
- package/apps/web/dist/assets/index-CBRcxIRM.js +0 -78
- package/apps/web/dist/assets/index-gTcC8eX6.css +0 -1
- package/apps/web/dist/assets/star-CUJ_2U_I.js +0 -1
- package/apps/web/dist/assets/ui-CPp6zNQ9.js +0 -9
- package/apps/web/dist/assets/volume-2-BjoY3RjZ.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,
|
|
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
|
-
|
|
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
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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
|
-
|
|
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
|
}
|