wizards 0.2.48 → 0.2.50

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 (119) hide show
  1. package/README.md +2 -1
  2. package/apps/runtime/dist/apple/wizards-apple +0 -0
  3. package/apps/runtime/dist/cli/status.js +1 -1
  4. package/apps/runtime/dist/db/migrations/tenant/0013_run_origin.sql +1 -0
  5. package/apps/runtime/dist/db/migrations/tenant/meta/0013_snapshot.json +3139 -0
  6. package/apps/runtime/dist/db/migrations/tenant/meta/_journal.json +7 -0
  7. package/apps/runtime/dist/db/schema.js +5 -0
  8. package/apps/runtime/dist/docs/user/meta.json +1 -0
  9. package/apps/runtime/dist/docs/user/models.md +25 -0
  10. package/apps/runtime/dist/docs/user/test-and-share.md +7 -1
  11. package/apps/runtime/dist/docs/user/wordpress.md +103 -0
  12. package/apps/runtime/dist/engine/device.js +182 -0
  13. package/apps/runtime/dist/engine/events.js +3 -0
  14. package/apps/runtime/dist/engine/input.js +3 -0
  15. package/apps/runtime/dist/engine/prepare.js +1 -0
  16. package/apps/runtime/dist/engine/requirements.js +6 -109
  17. package/apps/runtime/dist/engine/runner.js +1 -0
  18. package/apps/runtime/dist/engine/steps.js +2 -1
  19. package/apps/runtime/dist/env.js +1 -1
  20. package/apps/runtime/dist/harness/apple.js +258 -0
  21. package/apps/runtime/dist/harness/model.js +3 -1
  22. package/apps/runtime/dist/mcp/auth.js +3 -0
  23. package/apps/runtime/dist/mcp/scopes.js +11 -2
  24. package/apps/runtime/dist/media/transcribe.js +6 -1
  25. package/apps/runtime/dist/models.js +63 -9
  26. package/apps/runtime/dist/routes/api.js +232 -1
  27. package/apps/runtime/dist/routes/plugins.js +6 -2
  28. package/apps/runtime/dist/routes/runs.js +65 -3
  29. package/apps/runtime/dist/routes/studio.js +11 -1
  30. package/apps/runtime/dist/services/api.js +244 -0
  31. package/apps/runtime/dist/services/engenty-shapes.js +1 -1
  32. package/apps/runtime/dist/services/package.js +77 -9
  33. package/apps/runtime/dist/services/runs.js +4 -3
  34. package/apps/runtime/dist/services/site.js +262 -0
  35. package/apps/web/dist/assets/AboutDialog-BRjyFW7N.js +1 -0
  36. package/apps/web/dist/assets/ChangelogDialog-DU-fYMNG.js +1 -0
  37. package/apps/web/dist/assets/ChatView-Chv8rH9v.js +10 -0
  38. package/apps/web/dist/assets/EditorPage-BEEiRjpL.js +3 -0
  39. package/apps/web/dist/assets/FlowPreview-911P5v6v.js +1 -0
  40. package/apps/web/dist/assets/{Harness-DAR1u4Dk.js → Harness-DE9pS-ZP.js} +2 -2
  41. package/apps/web/dist/assets/Marketplace-DfoRgS49.js +2 -0
  42. package/apps/web/dist/assets/NewWizardPage-BwZ39he_.js +1 -0
  43. package/apps/web/dist/assets/ProjectPage-BB8feiW1.js +2 -0
  44. package/apps/web/dist/assets/PublicRunner-JsgGibnC.js +1 -0
  45. package/apps/web/dist/assets/ReadOnly-ClY8xMQS.js +1 -0
  46. package/apps/web/dist/assets/RunDrawer-CxJtIQlP.js +4 -0
  47. package/apps/web/dist/assets/RunnerView-DvIBDzr1.js +1 -0
  48. package/apps/web/dist/assets/SettingsPage-DJBQvyom.js +1 -0
  49. package/apps/web/dist/assets/SetupPage-BVqbshmT.js +1 -0
  50. package/apps/web/dist/assets/SharePage-ChQxeHFC.js +1 -0
  51. package/apps/web/dist/assets/brand-CNF5NxD9.js +2 -0
  52. package/apps/web/dist/assets/changelog-OdE5-SsX.js +1 -0
  53. package/apps/web/dist/assets/circle-alert-r2qc1Vej.js +1 -0
  54. package/apps/web/dist/assets/engenty-eXZ-EAwd.js +1 -0
  55. package/apps/web/dist/assets/esm-cYET-omK.js +7 -0
  56. package/apps/web/dist/assets/{fluffy-engenty-D7rFrNcJ.js → fluffy-engenty-ClRou7yu.js} +1 -1
  57. package/apps/web/dist/assets/index-CDgxPZY_.js +11 -0
  58. package/apps/web/dist/assets/jsx-runtime-BNakU3Ej.js +1 -0
  59. package/apps/web/dist/assets/lock-N-C6-ZeG.js +1 -0
  60. package/apps/web/dist/assets/logo-C4V2_3Ar.js +1 -0
  61. package/apps/web/dist/assets/oss-credits-BQQX0kvk.js +1 -0
  62. package/apps/web/dist/assets/pdfmake-Cx9scTbD.js +228 -0
  63. package/apps/web/dist/assets/rolldown-runtime-hePW80VL.js +1 -0
  64. package/apps/web/dist/assets/session-Cpg5S8B3.js +1 -0
  65. package/apps/web/dist/assets/settings-menu-B763_KXf.js +1 -0
  66. package/apps/web/dist/assets/ui-DKcggL84.js +133 -0
  67. package/apps/web/dist/assets/upload-D24SDj7W.js +1 -0
  68. package/apps/web/dist/assets/useMutation-DKyQXgyj.js +1 -0
  69. package/apps/web/dist/assets/vfs_fonts-DllDSYt1.js +1 -0
  70. package/apps/web/dist/assets/volume-2-C-Y7-S4b.js +1 -0
  71. package/apps/web/dist/embed.js +57 -8
  72. package/apps/web/dist/index.html +11 -15
  73. package/apps/web/dist/mcp/flow.html +434 -206
  74. package/modules/calls/dist/client.css +1 -1
  75. package/modules/sms/dist/client.css +1 -1
  76. package/modules/whatsapp/dist/client.css +1 -1
  77. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +2 -0
  78. package/node_modules/@engenty-wizards/shared/dist/fit.d.ts +71 -0
  79. package/node_modules/@engenty-wizards/shared/dist/fit.js +381 -0
  80. package/package.json +1 -1
  81. package/apps/web/dist/assets/AboutDialog-CuiVGknS.js +0 -1
  82. package/apps/web/dist/assets/ChangelogDialog-DCEQD3Jd.js +0 -1
  83. package/apps/web/dist/assets/ChatView-DFxrG2PD.js +0 -10
  84. package/apps/web/dist/assets/EditorPage-B5rzKNMy.js +0 -3
  85. package/apps/web/dist/assets/FlowPreview-CYoR5DRY.js +0 -1
  86. package/apps/web/dist/assets/HomePage-BnYdh_Nx.js +0 -1
  87. package/apps/web/dist/assets/Marketplace-BDQNwMDB.js +0 -2
  88. package/apps/web/dist/assets/NewWizardPage-DztTEUlG.js +0 -1
  89. package/apps/web/dist/assets/ProjectPage-B7-Lqx9a.js +0 -2
  90. package/apps/web/dist/assets/PublicRunner-CaH3bHHd.js +0 -1
  91. package/apps/web/dist/assets/ReadOnly-DnB47DQC.js +0 -1
  92. package/apps/web/dist/assets/RunDrawer-Dv0KRqGA.js +0 -4
  93. package/apps/web/dist/assets/RunnerView-Bzwv1u4j.js +0 -2
  94. package/apps/web/dist/assets/SettingsPage-oVO7CKvc.js +0 -1
  95. package/apps/web/dist/assets/SetupPage-D--8cWA0.js +0 -1
  96. package/apps/web/dist/assets/SharePage-DjU08q7T.js +0 -1
  97. package/apps/web/dist/assets/ThemeSwitch-C3EJRN06.js +0 -1
  98. package/apps/web/dist/assets/arrow-right-F7X_SjK9.js +0 -1
  99. package/apps/web/dist/assets/changelog-BRoVI_JJ.js +0 -1
  100. package/apps/web/dist/assets/circle-alert-DdpaAYgd.js +0 -1
  101. package/apps/web/dist/assets/definition-CHacJYmI.js +0 -56
  102. package/apps/web/dist/assets/engenty-Cm8yZLON.js +0 -1
  103. package/apps/web/dist/assets/esm-rJY59Ixx.js +0 -7
  104. package/apps/web/dist/assets/external-link-Dfc1VFvS.js +0 -1
  105. package/apps/web/dist/assets/index-CX_yxZVQ.js +0 -79
  106. package/apps/web/dist/assets/jsx-runtime-D3jfb0Ew.js +0 -1
  107. package/apps/web/dist/assets/lock-Bu1wDFs8.js +0 -1
  108. package/apps/web/dist/assets/logo-C80CWCDM.js +0 -1
  109. package/apps/web/dist/assets/oss-credits-CIxnNZor.js +0 -1
  110. package/apps/web/dist/assets/react-dom-DenslgJm.js +0 -1
  111. package/apps/web/dist/assets/refresh-cw-BUDPOT39.js +0 -1
  112. package/apps/web/dist/assets/session-Blj2os_v.js +0 -1
  113. package/apps/web/dist/assets/settings-menu-BvxRnNtf.js +0 -1
  114. package/apps/web/dist/assets/sparkles-DWGJluyV.js +0 -1
  115. package/apps/web/dist/assets/trash-D9UB6TtS.js +0 -1
  116. package/apps/web/dist/assets/ui-GsuU9WTj.js +0 -9
  117. package/apps/web/dist/assets/upload-BngimDBR.js +0 -1
  118. package/apps/web/dist/assets/useMutation-DKcIz55V.js +0 -1
  119. package/apps/web/dist/assets/volume-2-BZju_bOP.js +0 -1
@@ -92,6 +92,13 @@
92
92
  "when": 1791669018302,
93
93
  "tag": "0012_assistant_chat",
94
94
  "breakpoints": true
95
+ },
96
+ {
97
+ "idx": 13,
98
+ "version": "6",
99
+ "when": 1791728617995,
100
+ "tag": "0013_run_origin",
101
+ "breakpoints": true
95
102
  }
96
103
  ]
97
104
  }
@@ -102,6 +102,11 @@ export const run = sqliteTable("run", {
102
102
  visitorId: text("visitor_id"),
103
103
  userId: text("user_id"),
104
104
  ipHash: text("ip_hash"),
105
+ /**
106
+ * Where a visitor started the run: the address of the website page that embeds the wizard
107
+ * (`data-page` of the embed tag, else the page's own address); null on the wizard's link.
108
+ */
109
+ origin: text("origin"),
105
110
  status: text("status", {
106
111
  enum: ["waiting_input", "running", "done", "failed", "cancelled"],
107
112
  }).notNull(),
@@ -12,6 +12,7 @@
12
12
  "build-a-wizard",
13
13
  "steps",
14
14
  "test-and-share",
15
+ "wordpress",
15
16
  "run",
16
17
  "space",
17
18
  "assistant",
@@ -25,6 +25,7 @@ A capability's page asks "Who does it?":
25
25
  |---|---|---|
26
26
  | Your subscription | Claude Code, Codex, Gemini CLI or Cursor Agent on this computer, on your sign-in there (text; Codex also images) | Your subscription |
27
27
  | Own API key | OpenAI, Anthropic, Google Gemini, fal.ai, ElevenLabs, Replicate or Vercel AI Gateway | The provider bills your key |
28
+ | Apple Intelligence | The model of Apple Intelligence on this Mac (text: Classifier and Standard) — shown on a Mac with Apple silicon on macOS 26 or later | Nothing |
28
29
  | Local model | [Ollama](https://ollama.com) on this computer (text) | Nothing |
29
30
  | engenty credits | Your account's credits; engenty picks the model, or you pick one it offers (FLUX on fal, ElevenLabs voices, Veo …) | Credits |
30
31
 
@@ -35,6 +36,30 @@ With an account, credits step in where nothing of your own is set up — videos
35
36
  your own, say. The switch under "engenty credits" turns that off; then a capability without a way
36
37
  of its own does not run.
37
38
 
39
+ ## Apple Intelligence
40
+
41
+ On a Mac with Apple silicon and macOS 26 or later, "Text & reasoning" offers Apple Intelligence:
42
+ the model Apple keeps on the Mac. Nothing leaves the machine, nothing is signed in and nothing
43
+ is paid. It needs Apple Intelligence switched on (System Settings → Apple Intelligence & Siri);
44
+ until then the choice says why it waits.
45
+
46
+ The model is small and reads at most 4,096 tokens for a prompt and its answer together. So it
47
+ takes the classes Classifier and Standard — decisions, picking values out of text, short copy —
48
+ while High and Highest keep the way they had (a key, an installed client or the credits). A
49
+ step whose text is too long for it fails with a note that says so; bind that class elsewhere.
50
+ The binding is `apple:default`; `apple:tagging` is Apple's adapter for tagging and extraction.
51
+
52
+ "Voice notes" offers Apple Intelligence on the same Macs: the Mac writes a recording down
53
+ itself (`apple:transcribe`), in the language the runner was in, for nothing. The first note in a
54
+ language waits while Apple fetches it. A recording from Chrome or Firefox (WebM) needs ffmpeg on
55
+ the Mac, which turns it into WAV first; Safari's and the app's recordings need nothing.
56
+
57
+ **In the app.** On an iPhone with iOS 26 the engenty wizards app writes voice notes down on the
58
+ phone, and once Apple Intelligence is switched on it also answers a run's short text calls —
59
+ Classifier and Standard steps without tools or files of their own — so a run in the cloud
60
+ spends no credits on them and that text never leaves the phone. Where the phone does not
61
+ answer, the run thinks the way these settings say.
62
+
38
63
  ## Keys
39
64
 
40
65
  A key is checked with its provider before it is kept. On your computer keys stay in the Keychain
@@ -186,17 +186,23 @@ The share dialog gives a tag to paste into a page's HTML:
186
186
  | Inline | The wizard in that place of the page, as tall as its content |
187
187
  | Button + modal | A button in that place that opens the wizard in a window over the page |
188
188
  | Chat button | The wizard's engenty in the lower right corner; the chat opens above it |
189
+ | Bubble | A round button at the bottom right of the page that opens the wizard in the window |
189
190
 
190
191
  ```html
191
192
  <script async src="https://example.com/embed.js" data-wizard="TOKEN"></script>
192
193
  <script async src="https://example.com/embed.js" data-wizard="TOKEN" data-mode="modal" data-label="Start"></script>
193
194
  <script async src="https://example.com/embed.js" data-wizard="TOKEN" data-runner="chat"></script>
194
195
  <script async src="https://example.com/embed.js" data-wizard="TOKEN" data-mode="popout"></script>
196
+ <script async src="https://example.com/embed.js" data-wizard="TOKEN" data-mode="bubble" data-label="Fragen?" data-text="Angebot in 2 Minuten"></script>
195
197
  ```
196
198
 
197
199
  A chat that is switched off for the wizard shows the page instead.
198
200
 
199
- The button takes your website's own styles through the class `engenty-wizard-button`.
201
+ The button takes your website's own styles through the class `engenty-wizard-button`, the bubble
202
+ through `engenty-wizard-bubble`; `data-color` gives the bubble a colour. `data-page` names the
203
+ page a run is started on (the page's own address when left out): the results show it.
204
+
205
+ On WordPress the plugin writes this tag for you: see [WordPress](./wordpress.md).
200
206
 
201
207
  ## Results people share
202
208
 
@@ -0,0 +1,103 @@
1
+ ---
2
+ title: WordPress
3
+ description: Put wizards on a WordPress site with the plugin "engenty wizards" — connect, read the site in, place a wizard, read results in the admin.
4
+ ---
5
+
6
+ The plugin **engenty wizards** puts the wizards of an engenty.ai account on a WordPress site and
7
+ shows what visitors left in the WordPress admin. The wizards run on engenty.ai: WordPress keeps
8
+ its settings and the connection, no answers.
9
+
10
+ | | |
11
+ |---|---|
12
+ | WordPress | 6.6 or newer |
13
+ | PHP | 8.1 or newer, nothing else on the host |
14
+ | Account | Free or above on engenty.ai; Kontakte and Termine need Pro |
15
+
16
+ ## Install
17
+
18
+ Download `engenty-wizards.zip` (Settings → Integrate → WordPress, or the
19
+ [releases](https://github.com/engenty/engenty-wizards-wordpress/releases/latest)) and upload it in
20
+ WordPress under **Plugins → Add New → Upload Plugin**. After activating it the menu **engenty**
21
+ opens.
22
+
23
+ ## Connect
24
+
25
+ On **engenty → Übersicht**:
26
+
27
+ - **Eigene KI erstellen** makes a free account on engenty.ai, with the admin's e-mail filled in.
28
+ - **Anmelden** uses an account you have.
29
+
30
+ engenty.ai asks you to allow the site access and sends you back. The site is connected as you,
31
+ in the team you picked; **Einstellungen → Trennen** ends it and revokes the access.
32
+
33
+ **By hand:** for your own engenty server, or where signing in through the browser is not possible,
34
+ enter an address and an API Key under **Einstellungen → Von Hand verbinden**. On engenty.ai the key
35
+ is made under Konto, on your own server in the studio under Einbinden.
36
+
37
+ ## Set up
38
+
39
+ After connecting, the overview walks through three steps.
40
+
41
+ | Step | What happens |
42
+ |---|---|
43
+ | Website einlesen | The plugin reads the site from inside WordPress: name, tagline, logo, the theme's colours, e-mail and phone from the imprint and contact pages, the shop's address with WooCommerce, and the published pages as text. You untick what should not go; the rest fills the space's details where they are empty and goes into its Wissen as pages. The space assistant then reads the imprint for address, VAT id and who runs the business |
44
+ | Ersten Wizard anlegen | A template becomes a wizard and goes live in one click |
45
+ | Auf die Website bringen | The bubble on every page, a new draft page with the wizard, or by hand (below) |
46
+
47
+ Reading the site and making wizards here needs a plan that builds on engenty.ai (Pro). On Free
48
+ you build in the [app on your computer](./install.md) and publish; the wizards then show in
49
+ WordPress.
50
+
51
+ ## Put a wizard on a page
52
+
53
+ | Way | |
54
+ |---|---|
55
+ | Block **engenty Wizard** | Pick the wizard and how it shows: in the text, button + window, bubble. The editor shows the wizard itself |
56
+ | Shortcode | `[engenty_wizard id="ID" mode="modal" label="Anfrage starten"]` — `id` is the wizard's ID or the token of its link; `mode` is `inline`, `modal` or `bubble` |
57
+ | Elementor | The widget **engenty Wizard** with the block's choices |
58
+ | PHP | `<?php engenty_wizard( 'ID', [ 'mode' => 'inline' ] ); ?>` in a theme template |
59
+ | Bubble | **Einstellungen → Blase auf jeder Seite**: one wizard at the bottom right of every page but the ones you leave out, with an optional line beside it and your colour |
60
+
61
+ Each way writes the same tag as the share dialog's [website snippet](./test-and-share.md#embed-in-a-website),
62
+ with the page's address: a result says which page it was started on.
63
+
64
+ ## Results, contacts, bookings
65
+
66
+ | Page | Shows | Plan |
67
+ |---|---|---|
68
+ | Ergebnisse | What visitors left: when, which wizard, the e-mail and first answers, the page; a result opens with all answers, what the wizard made and its downloads | every plan |
69
+ | Kontakte | The leads your wizards collected, with search and the wizard they came through | Pro, Team |
70
+ | Termine | Coming, past and cancelled bookings of the space's calendar | Pro, Team |
71
+
72
+ Who sees these pages is set under **Einstellungen → Zugriff** (administrators always, editors at
73
+ the start). Results of runs without an account are kept 7 days.
74
+
75
+ ## Without an account
76
+
77
+ A WordPress 7.0 site with its own AI provider (WordPress → **Einstellungen → Connectors**: OpenAI,
78
+ Anthropic, Google, or Ollama through a provider plugin) runs wizards by itself: no account, no
79
+ credits, the provider bills the site's key. On **engenty → Übersicht**, "Eigene KI erstellen"
80
+ offers the account first and, below it, **Lokal, mit eigenem KI-Anbieter**.
81
+
82
+ | | |
83
+ |---|---|
84
+ | Wizards | The templates that ship with the plugin, picked from the gallery on the local setup's second step; or a package (`.wizard`) imported under **Wizards → Importieren**, downloaded from a wizard's share dialog in the studio |
85
+ | What runs | Pages with every field but voice notes, accounts and appointment times; thinking steps, with a web page or a public API as their tools where the step names `web_fetch` or `http` (WordPress abilities the site runs itself; off under **Einstellungen → Eigenständige Wizards**); decisions, branches and surfaces; reviews; documents and dashboards as HTML; results as HTML, Markdown, text, CSV or JSON, a PDF as the browser's print. Photos go to the provider where it takes images |
86
+ | What does not | Web search, the browser and code tools, connected accounts, the Pro plugins, films, images, video and voice made by a model, lists and memory, Word and Excel downloads |
87
+ | The check | The share dialog's WordPress section and the plugin's import say per wizard whether it runs there as is, with less or only with an account, in the gallery's words ("nicht eingerichtet", "geht auch ohne"). With less: a choice on a page that leads to something the site lacks is closed there ("Hier gerade nicht verfügbar"), a format falls away |
88
+ | Knowledge | The share dialog's **Wissen mitnehmen** puts the project's pages into the package as files (up to 2 MB); on the site the wizard reads them as it reads its own files, a snapshot of the day it was packed |
89
+ | From the account | On a connected site with a provider, a published wizard's drawer offers **Hier laufen lassen**: the package comes over with the site's key and runs on the site without credits; **Über engenty.ai laufen lassen** switches back, **Neu laden** fetches the published version again |
90
+ | Results | Kept in WordPress under **Ergebnisse** for as long as the settings say; nothing goes to engenty.ai |
91
+ | Limits | 6 runs an hour per visitor and 50 a day per wizard (**Einstellungen → Eigenständige Wizards**), a honeypot; 60 seconds per thinking step, more for a local model (the setting reaches the Ollama provider plugin's own limit too) |
92
+
93
+ The browser follows the wizard's flow and draws every page; WordPress keeps the wizard's
94
+ prompts and the run and asks the provider once per thinking step through the AI Client. Both
95
+ kinds can be on one site: a connected site keeps contacts, bookings and files, a site without an
96
+ account still runs the simple ones.
97
+
98
+ ## Privacy
99
+
100
+ Visitors talk to engenty.ai directly from the frame the wizard runs in. Name engenty in your
101
+ privacy statement; **Einstellungen → Datenschutz** has a sentence to start from. Standalone
102
+ wizards send the visitors' answers to the site's AI provider instead: the settings name it in
103
+ the sentence.
@@ -0,0 +1,182 @@
1
+ import { nanoid } from "nanoid";
2
+ import { parseJsonAnswer, renderPrompt } from "../harness/prompt.js";
3
+ import { signalDevice } from "./events.js";
4
+ /** An offer not renewed for this long is forgotten: the person left the run. */
5
+ const OFFER_TTL_MS = 30 * 60_000;
6
+ /** How long the phone has to answer before the runtime thinks on its own. */
7
+ export const DEVICE_TIMEOUT_MS = 60_000;
8
+ const offers = new Map();
9
+ const pending = new Map();
10
+ /** The runner says what the device around it can do; renewed on every (re)connect. */
11
+ export function offerDevice(runId, offer) {
12
+ if (offer.think?.classes.length) {
13
+ offers.set(runId, { offer, at: Date.now() });
14
+ }
15
+ else {
16
+ offers.delete(runId);
17
+ }
18
+ }
19
+ export function forgetDevice(runId) {
20
+ offers.delete(runId);
21
+ }
22
+ /** Whether the device of this run thinks the class, and how much it takes. */
23
+ export function deviceThinks(runId, cls) {
24
+ const hit = offers.get(runId);
25
+ if (!hit || Date.now() - hit.at > OFFER_TTL_MS) {
26
+ offers.delete(runId);
27
+ return null;
28
+ }
29
+ const think = hit.offer.think;
30
+ return think?.classes.includes(cls) ? { maxChars: think.maxChars } : null;
31
+ }
32
+ /** Sends one call to the device and waits for its answer. */
33
+ export function askDevice(runId, request, timeoutMs = DEVICE_TIMEOUT_MS) {
34
+ const id = nanoid(10);
35
+ return new Promise((resolve, reject) => {
36
+ const timer = setTimeout(() => {
37
+ pending.delete(id);
38
+ reject(new Error("the device did not answer in time"));
39
+ }, timeoutMs);
40
+ pending.set(id, {
41
+ runId,
42
+ resolve: (text) => {
43
+ clearTimeout(timer);
44
+ resolve(text);
45
+ },
46
+ reject: (err) => {
47
+ clearTimeout(timer);
48
+ reject(err);
49
+ },
50
+ });
51
+ signalDevice(runId, { id, ...request });
52
+ });
53
+ }
54
+ /** The device's answer to one call; false when the call is unknown or not this run's. */
55
+ export function answerDevice(runId, reqId, answer) {
56
+ const hit = pending.get(reqId);
57
+ if (!hit || hit.runId !== runId) {
58
+ return false;
59
+ }
60
+ pending.delete(reqId);
61
+ if (typeof answer.text === "string") {
62
+ console.log(`[run ${runId}] the device answered a ${answer.text.length}-character call`);
63
+ hit.resolve(answer.text);
64
+ }
65
+ else {
66
+ hit.reject(new Error(answer.error || "the device could not answer"));
67
+ }
68
+ return true;
69
+ }
70
+ /**
71
+ * The run's device first, the runtime's own model where the device cannot: a call with tools
72
+ * or attachments, a prompt beyond what the phone takes, no answer in time, or an error there.
73
+ */
74
+ export class DeviceModel {
75
+ runId;
76
+ fallback;
77
+ maxChars;
78
+ timeoutMs;
79
+ specificationVersion = "v3";
80
+ provider = "device";
81
+ modelId;
82
+ supportedUrls = {};
83
+ constructor(runId, fallback, maxChars, timeoutMs = DEVICE_TIMEOUT_MS) {
84
+ this.runId = runId;
85
+ this.fallback = fallback;
86
+ this.maxChars = maxChars;
87
+ this.timeoutMs = timeoutMs;
88
+ this.modelId = `device:${this.own().modelId}`;
89
+ }
90
+ own() {
91
+ return this.fallback;
92
+ }
93
+ /** Whether the step's tools may be left out: it declared none, and nothing was uploaded. */
94
+ ignorable = false;
95
+ attach(tools, ignorable = false) {
96
+ this.ignorable = ignorable;
97
+ this.fallback.attach?.(tools);
98
+ }
99
+ /** What the device can take: the prompt as text alone, short enough, without tools it needs. */
100
+ request(options) {
101
+ if (options.tools?.length && !this.ignorable) {
102
+ return null;
103
+ }
104
+ const format = options.responseFormat?.type ?? "text";
105
+ if (format !== "text" && format !== "json") {
106
+ return null;
107
+ }
108
+ const { system, prompt, warnings } = renderPrompt(options.prompt);
109
+ if (warnings.length || system.length + prompt.length > this.maxChars) {
110
+ return null;
111
+ }
112
+ return {
113
+ kind: "think",
114
+ system,
115
+ prompt,
116
+ schema: options.responseFormat?.type === "json" ? (options.responseFormat.schema ?? null) : null,
117
+ };
118
+ }
119
+ async doGenerate(options) {
120
+ const request = this.request(options);
121
+ if (request) {
122
+ try {
123
+ const text = await askDevice(this.runId, request, this.timeoutMs);
124
+ return {
125
+ content: [
126
+ {
127
+ type: "text",
128
+ text: request.schema ? JSON.stringify(parseJsonAnswer(text)) : text,
129
+ },
130
+ ],
131
+ finishReason: { unified: "stop", raw: "device" },
132
+ usage: {
133
+ inputTokens: { total: 0, noCache: 0, cacheRead: 0, cacheWrite: 0 },
134
+ outputTokens: { total: 0, text: 0, reasoning: undefined },
135
+ raw: {},
136
+ },
137
+ providerMetadata: { device: { answered: true } },
138
+ response: { modelId: this.modelId },
139
+ warnings: [],
140
+ };
141
+ }
142
+ catch (err) {
143
+ console.warn(`[run ${this.runId}] device: ${err.message}; own model instead`);
144
+ }
145
+ }
146
+ return this.own().doGenerate(options);
147
+ }
148
+ async doStream(options) {
149
+ const request = this.request(options);
150
+ if (!request) {
151
+ return this.own().doStream(options);
152
+ }
153
+ const result = await this.doGenerate(options);
154
+ if (result.providerMetadata?.device?.answered !== true) {
155
+ // The device did not answer: the own model's answer is already here, as one piece.
156
+ }
157
+ const text = result.content.find((c) => c.type === "text");
158
+ const parts = [
159
+ { type: "stream-start", warnings: result.warnings },
160
+ { type: "response-metadata", ...result.response },
161
+ { type: "text-start", id: "0" },
162
+ { type: "text-delta", id: "0", delta: text?.type === "text" ? text.text : "" },
163
+ { type: "text-end", id: "0" },
164
+ {
165
+ type: "finish",
166
+ usage: result.usage,
167
+ finishReason: result.finishReason,
168
+ providerMetadata: result.providerMetadata,
169
+ },
170
+ ];
171
+ return {
172
+ stream: new ReadableStream({
173
+ start(controller) {
174
+ for (const part of parts) {
175
+ controller.enqueue(part);
176
+ }
177
+ controller.close();
178
+ },
179
+ }),
180
+ };
181
+ }
182
+ }
@@ -5,6 +5,9 @@ import { and, desc, eq, gt } from "drizzle-orm";
5
5
  import { db, schema } from "../db/client.js";
6
6
  const bus = new EventEmitter();
7
7
  bus.setMaxListeners(0);
8
+ export function signalDevice(runId, request) {
9
+ bus.emit(runId, { runId, event: null, device: request });
10
+ }
8
11
  export async function emitEvent(runId, stepId, type, said, asset) {
9
12
  const note = typeof said === "string" ? null : said;
10
13
  const message = note ? noteText(note, "de") : said;
@@ -115,6 +115,9 @@ function readAudio(raw) {
115
115
  if (typeof input.transcript === "string") {
116
116
  out.transcript = input.transcript.slice(0, 20_000);
117
117
  }
118
+ if (input.lang === "de" || input.lang === "en") {
119
+ out.lang = input.lang;
120
+ }
118
121
  return out;
119
122
  }
120
123
  /**
@@ -39,6 +39,7 @@ export async function prepareInputs(ctx) {
39
39
  mediaType: found.row.mime,
40
40
  abortSignal: ctx.signal,
41
41
  call: ctx.call,
42
+ language: value.lang,
42
43
  });
43
44
  await ctx.chargeUsd(transcript.costUsd);
44
45
  values[field.id] = { ...value, transcript: transcript.text };
@@ -1,5 +1,9 @@
1
- import { conditionMatches, conditionsOf, isDecidedField, isDecisionStep, isOtherwise, MODEL_CLASSES, ruleMatches, } from "@engenty-wizards/shared/definition";
1
+ import { conditionMatches, conditionsOf, isDecidedField, isDecisionStep, isOtherwise, MODEL_CLASSES, } from "@engenty-wizards/shared/definition";
2
+ import { closedChoicesFor, openValue, otherwiseIndex, unavoidableFrom, unavoidableSteps, } from "@engenty-wizards/shared/fit";
2
3
  import { classProblem, filmClient } from "../models.js";
4
+ // The steps every run passes through, and the choices that lead around a missing model, are
5
+ // pure and shared (packages/shared/src/fit.ts): the standalone check uses the same.
6
+ export { openValue, unavoidableFrom, unavoidableSteps };
3
7
  /**
4
8
  * What a wizard needs of the models before a run starts: each class its steps call, and whether
5
9
  * this runtime can serve it. A step every run passes through blocks the start when its class is
@@ -65,69 +69,6 @@ export function optionalStepClasses(step) {
65
69
  ? ["audio"]
66
70
  : [];
67
71
  }
68
- /** The steps every run passes through: without one of them the end is not reachable. */
69
- export function unavoidableSteps(def) {
70
- return def.steps.length ? unavoidableFrom(def, def.steps[0].id, {}) : new Set();
71
- }
72
- /**
73
- * The steps every path from `from` to the end passes through. A rule on an answer in `known`
74
- * goes one way; a rule on anything else may go either way.
75
- */
76
- export function unavoidableFrom(def, from, known) {
77
- const index = new Map(def.steps.map((s, i) => [s.id, i]));
78
- const start = index.get(from) ?? 0;
79
- const successors = (i) => {
80
- const out = [];
81
- for (const rule of def.steps[i].next ?? []) {
82
- if (isOtherwise(rule)) {
83
- continue;
84
- }
85
- const target = rule.goto === "end" ? def.steps.length : (index.get(rule.goto) ?? -1);
86
- if (rule.ask || !conditionsOf(rule.when).every((c) => c.field in known)) {
87
- if (target >= 0) {
88
- out.push(target);
89
- }
90
- continue;
91
- }
92
- if (ruleMatches(rule, known)) {
93
- // The first rule that matches decides; nothing after it is tried.
94
- return target >= 0 ? [...out, target] : out;
95
- }
96
- }
97
- // No rule matching goes on to the "otherwise" step, else the next (or ends after the last).
98
- out.push(otherwiseIndex(def, i, index));
99
- return out;
100
- };
101
- const reachesEnd = (without) => {
102
- if (without === start) {
103
- return false;
104
- }
105
- const seen = new Set([start]);
106
- const queue = [start];
107
- while (queue.length) {
108
- const i = queue.shift();
109
- if (i >= def.steps.length) {
110
- return true;
111
- }
112
- for (const j of successors(i)) {
113
- if (j !== without && !seen.has(j)) {
114
- seen.add(j);
115
- queue.push(j);
116
- }
117
- }
118
- }
119
- return false;
120
- };
121
- return new Set(def.steps.filter((_, i) => !reachesEnd(i)).map((s) => s.id));
122
- }
123
- /** Where step `i` goes when none of its rules holds, as an index; the length = the end. */
124
- function otherwiseIndex(def, i, index) {
125
- const goto = def.steps[i].next?.find(isOtherwise)?.goto;
126
- if (goto === undefined) {
127
- return i + 1;
128
- }
129
- return goto === "end" ? def.steps.length : (index.get(goto) ?? i + 1);
130
- }
131
72
  /** Whether a rule matches given what is known: true, false, or null = it may go either way. */
132
73
  function ruleHolds(rule, facts) {
133
74
  // A decision may go either way.
@@ -390,17 +331,6 @@ export function optionalCapabilities(def) {
390
331
  }
391
332
  return optional;
392
333
  }
393
- function choicesOf(step) {
394
- return step.fields.flatMap((f) => {
395
- if (f.kind === "select" && f.options?.length) {
396
- return [{ field: f.id, values: f.options }];
397
- }
398
- if (f.kind === "toggle") {
399
- return [{ field: f.id, values: [true, false] }];
400
- }
401
- return [];
402
- });
403
- }
404
334
  /**
405
335
  * The answers on a page that lead to a step this runtime has no model for: with them the run
406
336
  * would stop there, after what came before was paid for. The answers given already count; the
@@ -413,38 +343,5 @@ export async function closedChoices(def, step, values) {
413
343
  if (!missing.size) {
414
344
  return {};
415
345
  }
416
- const byId = new Map(def.steps.map((s) => [s.id, s]));
417
- const known = Object.fromEntries(Object.entries(values).filter(([id]) => !step.fields.some((f) => f.id === id)));
418
- const out = {};
419
- // A voice note nothing here can listen to: the field is closed as a whole.
420
- if (missing.has("audio")) {
421
- for (const field of step.fields) {
422
- if (field.kind === "audio") {
423
- out[field.id] = { values: [], classes: ["audio"] };
424
- }
425
- }
426
- }
427
- for (const choice of choicesOf(step)) {
428
- const closed = { values: [], classes: [] };
429
- for (const value of choice.values) {
430
- const ahead = unavoidableFrom(def, step.id, { ...known, [choice.field]: value });
431
- const lacking = [...ahead].flatMap((id) => {
432
- const s = byId.get(id);
433
- return s ? stepClasses(s).filter((cls) => missing.has(cls)) : [];
434
- });
435
- if (lacking.length) {
436
- closed.values.push(value);
437
- closed.classes = [...new Set([...closed.classes, ...lacking])];
438
- }
439
- }
440
- if (closed.values.length && closed.values.length < choice.values.length) {
441
- out[choice.field] = closed;
442
- }
443
- }
444
- return out;
445
- }
446
- /** The answer a closed choice gets instead: its first value that stays open. */
447
- export function openValue(step, field, closed) {
448
- const choice = choicesOf(step).find((c) => c.field === field);
449
- return choice?.values.find((v) => !closed.values.some((c) => String(c) === String(v)));
346
+ return closedChoicesFor(def, step, values, (s) => stepClasses(s).filter((cls) => missing.has(cls)), (field) => (missing.has("audio") && field.kind === "audio" ? ["audio"] : null));
450
347
  }
@@ -184,6 +184,7 @@ export async function createRun(input) {
184
184
  visitorId: input.visitorId ?? null,
185
185
  userId: input.userId ?? null,
186
186
  ipHash: input.ipHash ?? null,
187
+ origin: input.origin ?? null,
187
188
  status: first.type === "page" ? "waiting_input" : "running",
188
189
  cursor: first.id,
189
190
  state,
@@ -459,7 +459,8 @@ export async function runAgentStep(step, ctx) {
459
459
  const resolved = await textModel(step.model ?? "high", { ...ctx.call, effort: step.effort });
460
460
  const uploads = await personUploads(ctx);
461
461
  const { tools, assets, close } = await buildStepTools(step, ctx, resolved, uploads);
462
- attachTools(resolved, tools);
462
+ // A step without tools of its own and without uploads: the run's device may answer it alone.
463
+ attachTools(resolved, tools, step.tools.length === 0 && uploads.length === 0);
463
464
  try {
464
465
  const photos = await seenPhotos(step, ctx, resolved, uploads);
465
466
  const others = uploads.filter((u) => !photos.some((p) => p.upload === u));
@@ -203,7 +203,7 @@ export const env = {
203
203
  },
204
204
  turnstile: { siteKey: str("TURNSTILE_SITE_KEY"), secret: str("TURNSTILE_SECRET_KEY") },
205
205
  /**
206
- * The mobile app (apps/mobile): a phone opens this runtime's `/w/` and `/s/` links in it.
206
+ * The mobile app (the apps repo engenty-wizards-apps, mobile/): a phone opens this runtime's `/w/` and `/s/` links in it.
207
207
  * Served as /.well-known/apple-app-site-association and /.well-known/assetlinks.json.
208
208
  */
209
209
  mobile: {