wizards 0.7.2 → 0.7.4

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 (91) hide show
  1. package/README.md +7 -6
  2. package/apps/runtime/dist/assistant/primer.js +1 -1
  3. package/apps/runtime/dist/auth/device.js +13 -2
  4. package/apps/runtime/dist/cli/account.js +114 -21
  5. package/apps/runtime/dist/cli/connect.js +12 -7
  6. package/apps/runtime/dist/cli/machine.js +6 -5
  7. package/apps/runtime/dist/cli/main.js +1 -1
  8. package/apps/runtime/dist/cli/menu.js +1 -1
  9. package/apps/runtime/dist/cli/setup.js +6 -0
  10. package/apps/runtime/dist/cli/ui.js +26 -0
  11. package/apps/runtime/dist/docs/dev/plugins/examples.md +1 -1
  12. package/apps/runtime/dist/docs/dev/plugins/index.md +1 -1
  13. package/apps/runtime/dist/docs/dev/plugins/layout.md +1 -1
  14. package/apps/runtime/dist/docs/dev/plugins/quick-start.md +2 -2
  15. package/apps/runtime/dist/docs/dev/plugins/reference.md +4 -4
  16. package/apps/runtime/dist/docs/dev/plugins/runners.md +1 -1
  17. package/apps/runtime/dist/docs/dev/plugins/server.md +2 -2
  18. package/apps/runtime/dist/docs/dev/plugins/studio.md +2 -2
  19. package/apps/runtime/dist/docs/user/ai-apps.md +1 -1
  20. package/apps/runtime/dist/docs/user/command-line.md +1 -1
  21. package/apps/runtime/dist/docs/user/create-account.md +1 -1
  22. package/apps/runtime/dist/docs/user/first-start.md +7 -2
  23. package/apps/runtime/dist/docs/user/index.md +1 -1
  24. package/apps/runtime/dist/docs/user/install.md +2 -2
  25. package/apps/runtime/dist/docs/user/models.md +1 -1
  26. package/apps/runtime/dist/harness/antigravity.js +129 -0
  27. package/apps/runtime/dist/harness/apple.js +1 -0
  28. package/apps/runtime/dist/harness/index.js +2 -2
  29. package/apps/runtime/dist/harness/model.js +13 -5
  30. package/apps/runtime/dist/harness/types.js +2 -2
  31. package/apps/runtime/dist/mcp/seen.js +1 -1
  32. package/apps/runtime/dist/models.js +60 -2
  33. package/apps/runtime/dist/plugins/loader.js +10 -3
  34. package/apps/runtime/dist/routes/studio.js +34 -5
  35. package/apps/runtime/dist/texts.js +4 -0
  36. package/apps/web/dist/assets/AboutDialog-BI6487_s.js +1 -0
  37. package/apps/web/dist/assets/{ChangelogDialog-BqwKOr3c.js → ChangelogDialog-B63QWuUV.js} +1 -1
  38. package/apps/web/dist/assets/ChatView-BjQVHGjn.js +10 -0
  39. package/apps/web/dist/assets/EditorPage-DrprS19h.js +3 -0
  40. package/apps/web/dist/assets/{FlowPreview-CpA_aX8t.js → FlowPreview-CusP7ci9.js} +1 -1
  41. package/apps/web/dist/assets/{Harness-BdBBdTrI.js → Harness-CCMqhtuk.js} +2 -2
  42. package/apps/web/dist/assets/{NewWizardChannels-B48OYt7I.js → NewWizardChannels-DpcWsST7.js} +1 -1
  43. package/apps/web/dist/assets/NewWizardPage-BXePNBa9.js +7 -0
  44. package/apps/web/dist/assets/OnboardingPage-BtZ6sHJi.js +1 -0
  45. package/apps/web/dist/assets/ProjectPage-DHOL8FXt.js +1 -0
  46. package/apps/web/dist/assets/PublicRunner-BLRVe7G0.js +1 -0
  47. package/apps/web/dist/assets/{ReadOnly-CaxuDkrN.js → ReadOnly-BV8o_HtK.js} +1 -1
  48. package/apps/web/dist/assets/RunDrawer-D-T8pYfB.js +4 -0
  49. package/apps/web/dist/assets/{RunnerView-UGOmm2-Z.js → RunnerView-BinlRsGF.js} +1 -1
  50. package/apps/web/dist/assets/SettingsPage-B6M-jFJw.js +1 -0
  51. package/apps/web/dist/assets/SetupPage-DI6c--4V.js +1 -0
  52. package/apps/web/dist/assets/{SharePage-BTiFkz8h.js → SharePage-C4cESaes.js} +1 -1
  53. package/apps/web/dist/assets/changelog-Dj_yd2vG.js +1 -0
  54. package/apps/web/dist/assets/{esm-CY-A_13f.js → esm-DXeMu8Lb.js} +1 -1
  55. package/apps/web/dist/assets/{index-B_aM-qZk.css → index-AfUa8xKD.css} +1 -1
  56. package/apps/web/dist/assets/index-yiE9Lun0.js +14 -0
  57. package/apps/web/dist/assets/{lock--JFmtLDU.js → lock-R_CfU0Xo.js} +1 -1
  58. package/apps/web/dist/assets/oss-credits-cZ9NUaLZ.js +1 -0
  59. package/apps/web/dist/assets/{phone-DMtADQ4-.js → phone-CgrIS4_-.js} +1 -1
  60. package/apps/web/dist/assets/settings-menu-2IMOOlLl.js +1 -0
  61. package/apps/web/dist/assets/ui-dzGvc3xk.js +137 -0
  62. package/apps/web/dist/assets/{upload-Bcpc3mDn.js → upload-BSuTilFF.js} +1 -1
  63. package/apps/web/dist/index.html +3 -3
  64. package/apps/web/dist/mcp/flow.html +2 -2
  65. package/node_modules/@engenty/wizards/package.json +11 -0
  66. package/node_modules/@engenty-wizards/shared/dist/run.d.ts +1 -0
  67. package/node_modules/@engenty-wizards/shared/dist/run.js +2 -0
  68. package/package.json +3 -3
  69. package/apps/runtime/dist/harness/gemini.js +0 -126
  70. package/apps/web/dist/assets/AboutDialog-BQ4jGHij.js +0 -1
  71. package/apps/web/dist/assets/ChatView-Q-Mk0N17.js +0 -10
  72. package/apps/web/dist/assets/EditorPage-_ZrAipdL.js +0 -3
  73. package/apps/web/dist/assets/NewWizardPage-Djq-7i5b.js +0 -7
  74. package/apps/web/dist/assets/OnboardingPage-BLkXK6mf.js +0 -1
  75. package/apps/web/dist/assets/ProjectPage-Tp7oavbh.js +0 -1
  76. package/apps/web/dist/assets/PublicRunner-nh8U3BWB.js +0 -1
  77. package/apps/web/dist/assets/RunDrawer-DhlEkTSh.js +0 -4
  78. package/apps/web/dist/assets/SettingsPage-BkYXyrdN.js +0 -1
  79. package/apps/web/dist/assets/SetupPage-Bw6Hen_A.js +0 -1
  80. package/apps/web/dist/assets/changelog-B3yrut-H.js +0 -1
  81. package/apps/web/dist/assets/index-FEmK7XOw.js +0 -14
  82. package/apps/web/dist/assets/oss-credits-BJrR7BR1.js +0 -1
  83. package/apps/web/dist/assets/settings-menu-Dac4JUiM.js +0 -1
  84. package/apps/web/dist/assets/ui-CTXSFCzc.js +0 -137
  85. package/node_modules/@engenty-wizards/plugin-sdk/package.json +0 -11
  86. /package/node_modules/{@engenty-wizards/plugin-sdk/dist → @engenty/wizards/dist/plugin}/index.d.ts +0 -0
  87. /package/node_modules/{@engenty-wizards/plugin-sdk/dist → @engenty/wizards/dist/plugin}/index.js +0 -0
  88. /package/node_modules/{@engenty-wizards/plugin-sdk/dist → @engenty/wizards/dist/plugin}/studio.d.ts +0 -0
  89. /package/node_modules/{@engenty-wizards/plugin-sdk/dist → @engenty/wizards/dist/plugin}/studio.js +0 -0
  90. /package/node_modules/{@engenty-wizards/plugin-sdk/dist → @engenty/wizards/dist/plugin}/thread.d.ts +0 -0
  91. /package/node_modules/{@engenty-wizards/plugin-sdk/dist → @engenty/wizards/dist/plugin}/thread.js +0 -0
@@ -28,8 +28,8 @@ have is left alone), installs engenty wizards into `~/.engenty/wizards` (about 6
28
28
 
29
29
  | Step | What it does |
30
30
  |---|---|
31
- | Your engenty account | Asks “Sign in now?”. If you say yes, it shows a link and a code and opens your browser for the sign-in at account.engenty.ai (if you have no account yet, the page takes an invitation code). Once you are signed in, what you publish on this computer runs in the cloud too. If you say no, `wizards account sign-in` does it any time. `--local` leaves the account out altogether: see [Local only](./local-only.md) |
32
- | An AI client | Looks for Codex, Claude Code, Gemini CLI and Cursor Agent and offers to install the ones that are missing. It puts first the one whose app (ChatGPT, Claude, Cursor) is on your Mac, as you most likely have that subscription already. You can also use your account’s credits, an API key, [Ollama](https://ollama.com) or, on a Mac with Apple silicon and macOS 26, Apple Intelligence: the studio’s [first page](./first-start.md) offers them |
31
+ | Your engenty account | Asks “Sign in or create your account now?”. If you say yes, it shows a link and a code and opens your browser for the sign-in at account.engenty.ai; check that the page shows the same code (if you have no account yet, the page creates one with your invitation code, or puts you on the waitlist). While it waits, Enter opens the page again and Esc goes on without an account. Once you are signed in, what you publish on this computer runs in the cloud too. If you say no, `wizards account sign-in` does it any time. Setting it up again with `--local` signs an account out. `--local` leaves the account out altogether: see [Local only](./local-only.md) |
32
+ | An AI client | Looks for Codex, Claude Code, Antigravity and Cursor Agent and offers to install the ones that are missing. It puts first the one whose app (ChatGPT, Claude, Antigravity, Cursor) is on your Mac, as you most likely have that subscription already. You can also use your account’s credits, an API key, [Ollama](https://ollama.com) or, on a Mac with Apple silicon and macOS 26, Apple Intelligence: the studio’s [first page](./first-start.md) offers them |
33
33
  | A browser and ffmpeg | Names the browser for PDF and PNG exports and steps on websites: the first of Chrome, Edge and Chromium it finds (on a Mac also Brave). engenty wizards uses that one; [`CHROME_PATH`](./command-line.md#settings) picks another. It also says whether ffmpeg is there for MP4 videos of animated widgets, and with Homebrew it offers to install it |
34
34
  | Start at login (optional) | engenty wizards starts in the background when you log in, so links and AI apps can always reach it. It is a LaunchAgent on a Mac and a systemd user service on Linux |
35
35
  | Your AI apps (optional) | Offers to add your wizards to the [AI apps](./ai-apps.md) it finds, such as Claude Desktop, Cursor or Codex |
@@ -24,7 +24,7 @@ A capability’s page asks “Who does it?”:
24
24
 
25
25
  | Choice | What it is | Cost |
26
26
  |---|---|---|
27
- | Your subscription | Claude Code, Codex, Gemini CLI or Cursor Agent on this computer, using your sign-in there (text; Codex also makes images) | Your subscription |
27
+ | Your subscription | Claude Code, Codex, Antigravity or Cursor Agent on this computer, using your sign-in there (text; Codex also makes images; Antigravity runs steps without their tools) | Your subscription |
28
28
  | Your own API key | OpenAI, Anthropic, Google Gemini, fal.ai, ElevenLabs, Replicate or Vercel AI Gateway | The provider bills your key |
29
29
  | Apple Intelligence | The model on this Mac: short texts and decisions (Classifier, Standard) and voice notes. See [Apple Intelligence](#apple-intelligence) | Nothing |
30
30
  | Local model | [Ollama](https://ollama.com) on this computer (text) | Nothing |
@@ -0,0 +1,129 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { resolveEnv, run } from "./env.js";
4
+ import { failureOf, HarnessModel, runClient, } from "./model.js";
5
+ /**
6
+ * Antigravity CLI: `agy` answers on the Google sign-in it cached — the Google AI subscription,
7
+ * which Gemini CLI no longer serves. The prompt goes on stdin as one stream-json message, the
8
+ * instructions in front of it: the client reads no system prompt and no rules of a folder it
9
+ * does not trust. It searches the web and reads the call's files with its own tools; the step's
10
+ * tools it cannot take, as it reads MCP servers only from the person's own config. The answer
11
+ * is checked against the schema by the client itself.
12
+ */
13
+ export const AGY_BIN = process.env.AGY_BIN?.trim() || "agy";
14
+ /** The models carry their effort in the name: `gemini-3.8-flash-<low|medium|high>`. */
15
+ const CLASSES = {
16
+ classifier: "gemini-3.8-flash-low",
17
+ standard: "gemini-3.8-flash-medium",
18
+ high: "gemini-3.8-flash-high",
19
+ highest: "gemini-3.8-flash-high",
20
+ };
21
+ /** The model of that name at the effort a step asks for, where the name carries one. */
22
+ export function withEffort(model, effort) {
23
+ return effort ? model.replace(/-(low|medium|high)$/, `-${effort}`) : model;
24
+ }
25
+ const spec = {
26
+ id: "antigravity",
27
+ passThrough: /^(AGY_ADC_AUTH|GOOGLE_APPLICATION_CREDENTIALS|GOOGLE_CLOUD_PROJECT)$/,
28
+ keyVars: [],
29
+ // No status command, and a call without a sign-in waits a minute for one in the browser:
30
+ // listing the models is quick, and refuses at once when nobody is signed in.
31
+ async auth(env) {
32
+ try {
33
+ await run(AGY_BIN, ["models"], { timeout: 20_000, env });
34
+ return "subscription";
35
+ }
36
+ catch {
37
+ return "none";
38
+ }
39
+ },
40
+ };
41
+ /** The client's result among the events it prints; null when it printed none. */
42
+ export function antigravityAnswer(stdout) {
43
+ for (const line of stdout.trim().split("\n").reverse()) {
44
+ try {
45
+ const event = JSON.parse(line);
46
+ if (event?.event === "result" && event.result) {
47
+ return event.result;
48
+ }
49
+ }
50
+ catch {
51
+ // a line it logs
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+ /** The instructions in front of the prompt: the client takes one message and nothing besides. */
57
+ export function antigravityMessage(system, prompt) {
58
+ const content = system ? `<instructions>\n${system}\n</instructions>\n\n${prompt}` : prompt;
59
+ return `${JSON.stringify({ event: "user", message: { content } })}\n`;
60
+ }
61
+ class AntigravityModel extends HarnessModel {
62
+ provider = "antigravity";
63
+ nativeSchema = true;
64
+ usesTools = false;
65
+ async invoke(call) {
66
+ const { env, auth } = await resolveEnv(spec);
67
+ if (auth === "none") {
68
+ throw failureOf(this.harness, "not logged in");
69
+ }
70
+ const args = [
71
+ "--input-format",
72
+ "stream-json",
73
+ "--output-format",
74
+ "stream-json",
75
+ "--model",
76
+ withEffort(this.modelId, call.effort),
77
+ "--disable-slash-commands",
78
+ ];
79
+ if (call.schema) {
80
+ const schemaFile = join(call.dir, "schema.json");
81
+ writeFileSync(schemaFile, JSON.stringify(call.schema));
82
+ args.push("--json-schema", schemaFile);
83
+ }
84
+ const { stdout, stderr, code } = await runClient(AGY_BIN, args, {
85
+ cwd: call.dir,
86
+ env: { ...env, NO_COLOR: "1" },
87
+ signal: call.signal,
88
+ stdin: antigravityMessage(call.system, call.prompt),
89
+ });
90
+ const result = antigravityAnswer(stdout);
91
+ if (!result) {
92
+ throw failureOf(this.harness, stderr.trim() || `exit ${code}`);
93
+ }
94
+ if (result.status !== "SUCCESS") {
95
+ throw failureOf(this.harness, result.error || stderr.trim() || result.status || "error");
96
+ }
97
+ const u = result.usage ?? {};
98
+ return {
99
+ text: result.structured_output !== undefined
100
+ ? JSON.stringify(result.structured_output)
101
+ : (result.response ?? ""),
102
+ usage: {
103
+ input: u.input_tokens ?? 0,
104
+ cacheRead: u.cache_read_tokens ?? 0,
105
+ output: (u.output_tokens ?? 0) + (u.thinking_tokens ?? 0),
106
+ },
107
+ sessionId: result.conversation_id,
108
+ meta: { turns: result.num_turns ?? 0, seconds: result.duration_seconds ?? 0 },
109
+ };
110
+ }
111
+ }
112
+ export const antigravity = {
113
+ ...spec,
114
+ name: "Antigravity",
115
+ bin: AGY_BIN,
116
+ classes: CLASSES,
117
+ async version(env) {
118
+ try {
119
+ const { stdout } = await run(AGY_BIN, ["--version"], { timeout: 10_000, env });
120
+ return stdout.trim().split("\n").pop()?.trim() || null;
121
+ }
122
+ catch {
123
+ return null;
124
+ }
125
+ },
126
+ // No login command: the client asks for the Google sign-in when it starts without one.
127
+ login: { args: [], interactive: true },
128
+ model: (alias, effort) => new AntigravityModel(antigravity, alias || CLASSES.standard, effort),
129
+ };
@@ -140,6 +140,7 @@ class AppleModel extends HarnessModel {
140
140
  nativeSchema = true;
141
141
  /** The helper calls no tools: a call with tools answers from the prompt alone. */
142
142
  usesTools = false;
143
+ searchesWeb = false;
143
144
  async invoke(call) {
144
145
  const { stdout, stderr, code } = await runClient(APPLE_BIN, ["generate"], {
145
146
  cwd: call.dir,
@@ -3,18 +3,18 @@ import { installCommand } from "../cli/clients.js";
3
3
  import { inherited, runtimePath } from "../cli/environment.js";
4
4
  import { layout } from "../cli/home.js";
5
5
  import { CLIENTS, vendorApp } from "../cli/machine.js";
6
+ import { antigravity } from "./antigravity.js";
6
7
  import { claude } from "./claude.js";
7
8
  import { codex } from "./codex.js";
8
9
  import { cursor } from "./cursor.js";
9
10
  import { forgetEnv, loginShellEnv, resolveEnv } from "./env.js";
10
- import { gemini } from "./gemini.js";
11
11
  export { HarnessModel, notInstalled, signedOut } from "./model.js";
12
12
  export { HARNESS_IDS } from "./types.js";
13
13
  /**
14
14
  * The AI clients this runtime can run as a model, in the order the setup offers them. The first
15
15
  * one installed is the one the setup recommends.
16
16
  */
17
- export const HARNESSES = [codex, claude, gemini, cursor];
17
+ export const HARNESSES = [codex, claude, antigravity, cursor];
18
18
  export function harness(id) {
19
19
  return HARNESSES.find((h) => h.id === id) ?? null;
20
20
  }
@@ -10,6 +10,7 @@ import { extensionOf, jsonInstruction, parseJsonAnswer, renderPrompt } from "./p
10
10
  const workDir = join(env.dataDir, "harness");
11
11
  export const signedOut = (h) => note("clientNotSignedIn", { name: h.name });
12
12
  export const notInstalled = (h) => note("clientNotInstalled", { name: h.name });
13
+ export const notServed = (h) => note("clientAccountNotServed", { name: h.name });
13
14
  export const exhausted = (h) => h.exhausted ?? note("clientNoCredit", { name: h.name });
14
15
  /** The failure a client reports, as the person should read it. */
15
16
  export function failureOf(h, detail) {
@@ -18,6 +19,11 @@ export function failureOf(h, detail) {
18
19
  if (/credit balance|billing|too low|usage limit|quota|insufficient|rate.?limit|\b429\b/i.test(detail)) {
19
20
  return new ModelUnavailableError(exhausted(h));
20
21
  }
22
+ // Signed in, but the vendor no longer serves that account with this client: signing in again
23
+ // with the same account changes nothing.
24
+ if (/IneligibleTier|no longer supported|UNSUPPORTED_CLIENT|not eligible/i.test(detail)) {
25
+ return new ModelUnavailableError(notServed(h));
26
+ }
21
27
  if (/authenticat|log ?in|logged in|oauth|credential|unauthori[sz]ed|\b401\b|api key/i.test(detail)) {
22
28
  return new ModelUnavailableError(signedOut(h));
23
29
  }
@@ -71,6 +77,8 @@ export class HarnessModel {
71
77
  nativeSchema = false;
72
78
  /** Whether the client runs a call's tools (over the bridge); else they are left out, with a warning. */
73
79
  usesTools = true;
80
+ /** Whether the client searches the web with a tool of its own, tools of the call or not. */
81
+ searchesWeb = true;
74
82
  effort;
75
83
  harness;
76
84
  executors = new Map();
@@ -98,15 +106,15 @@ export class HarnessModel {
98
106
  const bridged = [];
99
107
  let webSearch = false;
100
108
  for (const tool of options.tools ?? []) {
101
- if (tool.type !== "function" || !this.usesTools) {
102
- warnings.push({ type: "unsupported", feature: `tool ${tool.name}` });
103
- continue;
104
- }
105
109
  // The client searches with its own tool; naming `web_search` is what switches it on.
106
- if (tool.name === "web_search") {
110
+ if (tool.type === "function" && tool.name === "web_search" && this.searchesWeb) {
107
111
  webSearch = true;
108
112
  continue;
109
113
  }
114
+ if (tool.type !== "function" || !this.usesTools) {
115
+ warnings.push({ type: "unsupported", feature: `tool ${tool.name}` });
116
+ continue;
117
+ }
110
118
  const executor = this.executors.get(tool.name);
111
119
  if (!executor?.execute) {
112
120
  warnings.push({
@@ -1,7 +1,7 @@
1
1
  /**
2
- * A harness is an AI client installed on this machine — Claude Code, Codex, Gemini CLI, Cursor
2
+ * A harness is an AI client installed on this machine — Claude Code, Codex, Antigravity, Cursor
3
3
  * Agent — that answers on the person's own subscription or sign-in. The runtime runs it headless
4
4
  * as a model (./model.ts) and signs it in through the inline terminal (./terminal.ts). Nothing of
5
5
  * this process reaches it: no key of ours, no session of a parent client.
6
6
  */
7
- export const HARNESS_IDS = ["claude", "codex", "gemini", "cursor"];
7
+ export const HARNESS_IDS = ["claude", "codex", "antigravity", "cursor"];
@@ -15,7 +15,7 @@ const CLIENT_NAMES = [
15
15
  // Cursor calls itself cursor-vscode.
16
16
  ["vscode", /^(?!.*cursor).*(visual studio code|vs ?code)/i],
17
17
  ["windsurf", /windsurf|codeium/i],
18
- ["gemini", /gemini/i],
18
+ ["antigravity", /antigravity|\bagy\b/i],
19
19
  ["goose", /goose/i],
20
20
  ["openclaw", /openclaw/i],
21
21
  ["lm-studio", /lm[- ]?studio/i],
@@ -7,7 +7,7 @@ import { createGoogle } from "@ai-sdk/google";
7
7
  import { createOpenAI } from "@ai-sdk/openai";
8
8
  import { createReplicate } from "@ai-sdk/replicate";
9
9
  import { MODEL_CLASSES, TEXT_CLASSES, } from "@engenty-wizards/shared/definition";
10
- import { creditsModelOf, isCreditsRef, PROVIDER_IDS, providerInfo, providerOfRef, } from "@engenty-wizards/shared/providers";
10
+ import { CAPABILITY_CLASSES, creditsModelOf, isCreditsRef, PROVIDER_IDS, providerInfo, providerOfRef, } from "@engenty-wizards/shared/providers";
11
11
  import { note, saidText } from "@engenty-wizards/shared/run";
12
12
  import { generateSpeech, generateText, } from "ai";
13
13
  import { accountToken, linkedAccount } from "./auth/account.js";
@@ -26,7 +26,7 @@ import { serverText } from "./texts.js";
26
26
  export { isHarnessVendor } from "./harness/index.js";
27
27
  /**
28
28
  * A step names a model class, never a model. Where the class runs is decided here, in this order:
29
- * 1. its own way: an AI client installed on the machine (Claude Code, Codex, Gemini CLI, Cursor
29
+ * 1. its own way: an AI client installed on the machine (Claude Code, Codex, Antigravity, Cursor
30
30
  * Agent — on its subscription), an API key the person brought (OpenAI, Anthropic, Google,
31
31
  * fal.ai, ElevenLabs, Replicate, AI Gateway) or a local model;
32
32
  * 2. credits: the model-gateway binds `wizards/<class>`, meters the call and books it — on the
@@ -1000,6 +1000,64 @@ export async function checkKey(name, key, lang = "en") {
1000
1000
  };
1001
1001
  }
1002
1002
  }
1003
+ /**
1004
+ * Of these bindings, the ones for classes that run on nothing of this machine's own yet: a key
1005
+ * the setup tested is a key in use. Classes on a key, a client or a local model keep theirs —
1006
+ * choosing between them is for the settings.
1007
+ */
1008
+ function freeClasses(bindings) {
1009
+ return Object.fromEntries(Object.entries(bindings).filter(([cls]) => !ownRef(local, cls)));
1010
+ }
1011
+ const setupOutcome = () => ({
1012
+ ok: true,
1013
+ message: null,
1014
+ text: ownRef(local, "standard") || null,
1015
+ });
1016
+ /** The setup's test of one key: checked with the provider, stored, and put to use. */
1017
+ export async function setUpKey(name, key, lang = "en") {
1018
+ const value = key?.trim() || local.keys[name];
1019
+ if (!value) {
1020
+ return { ok: false, message: serverText(lang, "keyUnknown"), text: null };
1021
+ }
1022
+ const checked = await checkKey(name, value, lang);
1023
+ if (!checked.ok) {
1024
+ return { ...checked, text: null };
1025
+ }
1026
+ const provider = providerInfo(name);
1027
+ const offered = { ...provider?.text };
1028
+ for (const [cap, models] of Object.entries(provider?.models ?? {})) {
1029
+ const first = models?.[0]?.ref;
1030
+ if (cap !== "text" && first) {
1031
+ for (const cls of CAPABILITY_CLASSES[cap]) {
1032
+ offered[cls] = first;
1033
+ }
1034
+ }
1035
+ }
1036
+ // Free before the key is stored: a key can make a default reachable that it would not name.
1037
+ await saveLocalModels({ keys: { [name]: value }, bindings: freeClasses(offered) });
1038
+ return setupOutcome();
1039
+ }
1040
+ /** The setup's test of Ollama: it answers at the address and has a model to think with. */
1041
+ export async function setUpOllama(url, lang = "en") {
1042
+ const base = url.trim().replace(/\/+$/, "");
1043
+ let models;
1044
+ try {
1045
+ const res = await fetch(`${base}/models`, { signal: AbortSignal.timeout(5_000) });
1046
+ const body = (await res.json());
1047
+ models = (body.data ?? []).map((m) => m.id);
1048
+ }
1049
+ catch {
1050
+ return { ok: false, message: serverText(lang, "ollamaUnreachable"), text: null };
1051
+ }
1052
+ if (!models.length) {
1053
+ return { ok: false, message: serverText(lang, "ollamaNoModel"), text: null };
1054
+ }
1055
+ const bound = local.settings.bindings.standard?.replace(/^ollama:/, "");
1056
+ const model = bound && models.includes(bound) ? bound : models[0];
1057
+ const text = Object.fromEntries(TEXT_CLASSES.map((c) => [c, `ollama:${model}`]));
1058
+ await saveLocalModels({ ollamaUrl: base, bindings: freeClasses(text) });
1059
+ return setupOutcome();
1060
+ }
1003
1061
  let catalog = new Map();
1004
1062
  let catalogLoadedAt = 0;
1005
1063
  /** Public prices of the AI Gateway: what a runtime that runs alone shows as the cost of a run. */
@@ -39,11 +39,18 @@ export function pluginDirs() {
39
39
  return [join(packageRoot, "modules"), ...env.plugins.dirs];
40
40
  }
41
41
  const own = (specifier) => fileURLToPath(import.meta.resolve(specifier));
42
- /** The longer name first: an alias also matches what begins with it. */
42
+ /**
43
+ * The longer name first: an alias also matches what begins with it. `@engenty-wizards/plugin-sdk`
44
+ * is the name plugins written before `@engenty/wizards/plugin` import.
45
+ */
43
46
  function aliases() {
47
+ const thread = own("@engenty/wizards/plugin/thread");
48
+ const plugin = own("@engenty/wizards/plugin");
44
49
  return {
45
- "@engenty-wizards/plugin-sdk/thread": own("@engenty-wizards/plugin-sdk/thread"),
46
- "@engenty-wizards/plugin-sdk": own("@engenty-wizards/plugin-sdk"),
50
+ "@engenty/wizards/plugin/thread": thread,
51
+ "@engenty/wizards/plugin": plugin,
52
+ "@engenty-wizards/plugin-sdk/thread": thread,
53
+ "@engenty-wizards/plugin-sdk": plugin,
47
54
  "drizzle-orm/sqlite-core": own("drizzle-orm/sqlite-core"),
48
55
  "drizzle-orm": own("drizzle-orm"),
49
56
  zod: own("zod"),
@@ -37,7 +37,7 @@ import { seenApps } from "../mcp/seen.js";
37
37
  import { generateImageMedia, generateSpeechMedia, generateVideoMedia } from "../media/generate.js";
38
38
  import { transcribeAudio } from "../media/transcribe.js";
39
39
  import { errorText, saidOf } from "../model-errors.js";
40
- import { checkKey, classProblem, classWays, embeddingModel, hasTextModel, LOCAL_KEYS, localModelSettings, ModelUnavailableError, modelSettings, saveLocalModels, saveModels, storedKey, textModel, } from "../models.js";
40
+ import { checkKey, classProblem, classWays, embeddingModel, hasTextModel, LOCAL_KEYS, localModelSettings, ModelUnavailableError, modelSettings, saveLocalModels, saveModels, setUpKey, setUpOllama, storedKey, textModel, } from "../models.js";
41
41
  import { refreshPro } from "../plugins/pro.js";
42
42
  import { HTML_RESPONSE_CSP } from "../render/guard.js";
43
43
  import { isAdminRole, mayBuild, mayCreate, projectWritable, requireAdmin, requireWritable, } from "../services/access.js";
@@ -74,6 +74,12 @@ async function testedSources() {
74
74
  const tested = await readSetting("setup-done");
75
75
  return Array.isArray(tested) ? tested : [];
76
76
  }
77
+ async function markTested(source) {
78
+ const tested = await testedSources();
79
+ if (!tested.includes(source)) {
80
+ await writeSetting("setup-done", [...tested, source]);
81
+ }
82
+ }
77
83
  /**
78
84
  * The chosen source has passed a test call and can still answer: its client is there and signed
79
85
  * in. Where Apple Intelligence thinks the short classes, the test ran there; a client behind High
@@ -1358,6 +1364,32 @@ export const studio = new Hono()
1358
1364
  .object({ cls: z.enum(MODEL_CLASSES), lang: z.enum(LANGS).default("en") })
1359
1365
  .parse(await c.req.json());
1360
1366
  return c.json(await testClass(cls, lang));
1367
+ })
1368
+ // The setup's test of one key, or of Ollama: a working one is put to use and ends the setup.
1369
+ .post("/local/keys/:provider", async (c) => {
1370
+ if (managed) {
1371
+ return c.notFound();
1372
+ }
1373
+ const provider = z.enum(LOCAL_KEYS).parse(c.req.param("provider"));
1374
+ const { key } = z
1375
+ .object({ key: z.string().max(400).optional() })
1376
+ .parse(await c.req.json().catch(() => ({})));
1377
+ const result = await setUpKey(provider, key, requestLang(c));
1378
+ if (result.ok && result.text) {
1379
+ await markTested("own");
1380
+ }
1381
+ return c.json(result);
1382
+ })
1383
+ .post("/local/ollama", async (c) => {
1384
+ if (managed) {
1385
+ return c.notFound();
1386
+ }
1387
+ const { url } = z.object({ url: z.string().url().max(200) }).parse(await c.req.json());
1388
+ const result = await setUpOllama(url, requestLang(c));
1389
+ if (result.ok) {
1390
+ await markTested("own");
1391
+ }
1392
+ return c.json(result);
1361
1393
  })
1362
1394
  // One short call on a class, as a run would make it: shows that the way to the model is open.
1363
1395
  .post("/local/models/test", async (c) => {
@@ -1379,10 +1411,7 @@ export const studio = new Hono()
1379
1411
  abortSignal: AbortSignal.timeout(120_000),
1380
1412
  });
1381
1413
  // A working call is what ends the setup — for the source it ran on.
1382
- const tested = await testedSources();
1383
- if (!tested.includes(source)) {
1384
- await writeSetting("setup-done", [...tested, source]);
1385
- }
1414
+ await markTested(source);
1386
1415
  return c.json({
1387
1416
  ok: true,
1388
1417
  ref: resolved.ref,
@@ -9,6 +9,8 @@ const EN = {
9
9
  schemaMismatch: "The wizard doesn’t match the schema.",
10
10
  providerError: "The provider answered with error {status}.",
11
11
  providerUnreachable: "The provider cannot be reached right now.",
12
+ ollamaUnreachable: "Nothing answers at this address. Is Ollama running?",
13
+ ollamaNoModel: "Ollama runs, but has no model yet: `ollama pull qwen3` fetches one.",
12
14
  importedFrom: "Imported from “{name}”: {steps}, {files}.",
13
15
  imported: "Imported: {steps}, {files}.",
14
16
  stepCount: { one: "{count} step", other: "{count} steps" },
@@ -104,6 +106,8 @@ const DE = {
104
106
  keyUnknown: "Der Anbieter kennt diesen API-Key nicht.",
105
107
  providerError: "Der Anbieter antwortet mit Fehler {status}.",
106
108
  providerUnreachable: "Der Anbieter ist gerade nicht erreichbar.",
109
+ ollamaUnreachable: "Unter dieser Adresse antwortet nichts. Läuft Ollama?",
110
+ ollamaNoModel: "Ollama läuft, hat aber noch kein Modell: `ollama pull qwen3` holt eines.",
107
111
  importedFrom: "Importiert aus „{name}“: {steps}, {files}.",
108
112
  imported: "Importiert: {steps}, {files}.",
109
113
  stepCount: { one: "{count} Schritt", other: "{count} Schritte" },
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,Ft as i,It as a,Kt as o,Nt as s,Pt as c,Vn as l,Vt as u,Wt as d,_r as f,dr as p}from"./ui-dzGvc3xk.js";import{t as m}from"./preload-helper-CNEI7N0N.js";import{Nt as h,nt as g,rt as _,tt as v}from"./index-yiE9Lun0.js";import{c as y,f as b}from"./settings-menu-2IMOOlLl.js";import{ReleaseNotes as x,loadReleases as S,releaseDate as C,releaseLabel as w}from"./ChangelogDialog-B63QWuUV.js";var T=e(t(),1),E=[{name:`engenty wizards`,description:`credit.engenty-wizards`,homepage:`https://github.com/engenty/wizards`,license:`FSL-1.1-MIT`},{name:`engenty`,description:`credit.engenty`,homepage:`https://github.com/engenty/engenty`,license:`FSL-1.1-MIT`}],D=[{name:`Mastra`,description:`credit.mastra`,homepage:`https://github.com/mastra-ai/mastra`,license:`Apache-2.0`},{name:`AI SDK`,description:`credit.ai-sdk`,homepage:`https://github.com/vercel/ai`,license:`Apache-2.0`},{name:`Model Context Protocol`,description:`credit.model-context-protocol`,homepage:`https://github.com/modelcontextprotocol/typescript-sdk`,license:`MIT`},{name:`Hono`,description:`credit.hono`,homepage:`https://github.com/honojs/hono`,license:`MIT`},{name:`Drizzle ORM`,description:`credit.drizzle-orm`,homepage:`https://github.com/drizzle-team/drizzle-orm`,license:`Apache-2.0`},{name:`libSQL`,description:`credit.libsql`,homepage:`https://github.com/tursodatabase/libsql`,license:`MIT`},{name:`Playwright`,description:`credit.playwright`,homepage:`https://github.com/microsoft/playwright`,license:`Apache-2.0`},{name:`React`,description:`credit.react`,homepage:`https://github.com/facebook/react`,license:`MIT`},{name:`Vite`,description:`credit.vite`,homepage:`https://github.com/vitejs/vite`,license:`MIT`},{name:`Tailwind CSS`,description:`credit.tailwind-css`,homepage:`https://github.com/tailwindlabs/tailwindcss`,license:`MIT`},{name:`React Flow`,description:`credit.react-flow`,homepage:`https://github.com/xyflow/xyflow`,license:`MIT`},{name:`TanStack Query`,description:`credit.tanstack-query`,homepage:`https://github.com/TanStack/query`,license:`MIT`},{name:`xterm.js`,description:`credit.xterm-js`,homepage:`https://github.com/xtermjs/xterm.js`,license:`MIT`},{name:`Lucide`,description:`credit.lucide`,homepage:`https://github.com/lucide-icons/lucide`,license:`ISC`},{name:`Geist & Geist Mono`,description:`credit.geist-geist-mono`,homepage:`https://github.com/vercel/geist-font`,license:`OFL-1.1`},{name:`Space Grotesk`,description:`credit.space-grotesk`,homepage:`https://github.com/floriankarsten/space-grotesk`,license:`OFL-1.1`},{name:`git-cliff`,description:`credit.git-cliff`,homepage:`https://github.com/orhun/git-cliff`,license:`MIT OR Apache-2.0`}],O=e(n(),1),k=(e,...t)=>t.some(t=>t?.toLowerCase().includes(e));function A({name:e,homepage:t,version:n,license:r,description:i}){return(0,O.jsxs)(`li`,{className:`py-2.5`,children:[(0,O.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2.5 gap-y-0.5`,children:[t?(0,O.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 font-medium text-[0.875rem] text-ink underline-offset-4 hover:underline`,children:[e,(0,O.jsx)(p,{"aria-hidden":!0,className:`size-3 text-ink-4`})]}):(0,O.jsx)(`span`,{className:`font-medium text-[0.875rem] text-ink`,children:e}),n?(0,O.jsx)(`span`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:n}):null,(0,O.jsx)(`span`,{className:`text-[0.75rem] text-ink-3`,children:r})]}),i?(0,O.jsx)(`p`,{className:`mt-0.5 text-[0.8125rem] text-ink-3`,children:i}):null]})}function j({title:e,hint:t,children:n}){return(0,O.jsxs)(`section`,{className:`mt-6`,children:[(0,O.jsx)(`h3`,{className:`border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:e}),t?(0,O.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-ink-3`,children:t}):null,n]})}function M({credits:e}){return(0,O.jsx)(`ul`,{className:`divide-y divide-border-soft`,children:e.map(e=>(0,O.jsx)(A,{name:e.name,homepage:e.homepage,license:e.license,description:r(e.description)},e.name))})}function N({label:e,packages:t}){return(0,O.jsxs)(`div`,{className:`mt-4`,children:[(0,O.jsx)(`h4`,{className:`font-medium text-[0.75rem] text-ink-3 tracking-wide`,children:e}),(0,O.jsx)(`ul`,{className:`divide-y divide-border-soft`,children:t.map(e=>(0,O.jsx)(A,{...e},e.name))})]})}function P({active:e}){let[t,n]=(0,T.useState)(null),[i,o]=(0,T.useState)(``);(0,T.useEffect)(()=>{if(!e||t)return;let r=!1;return m(()=>import(`./oss-credits-cZ9NUaLZ.js`).then(e=>{r||n(e.default)}),[]),()=>{r=!0}},[e,t]),(0,T.useEffect)(()=>{e||o(``)},[e]);let s=i.trim().toLowerCase(),l=e=>s?e.filter(e=>k(s,e.name,e.license,r(e.description))):e,d=e=>s?e.filter(e=>k(s,e.name,e.license,e.version)):e,f=l(E),p=l(D),h=t?[{id:`shared`,label:r(`about.creditsShared`),packages:d(t.shared)},...t.groups.map(e=>({id:e.id,label:e.label,packages:d(e.packages)}))].filter(e=>e.packages.length>0):[],g=f.length===0&&p.length===0&&h.length===0;return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`p`,{className:`mb-4 text-[0.875rem] text-ink-3`,children:r(`about.creditsHint`)}),(0,O.jsx)(a,{type:`search`,value:i,placeholder:r(`about.search`),onChange:e=>o(e.target.value)}),f.length>0?(0,O.jsx)(j,{title:r(`about.creditsProduct`),children:(0,O.jsx)(M,{credits:f})}):null,p.length>0?(0,O.jsx)(j,{title:r(`about.creditsBuiltWith`),children:(0,O.jsx)(M,{credits:p})}):null,t===null?(0,O.jsx)(`div`,{className:`flex justify-center py-10 text-ink-3`,children:(0,O.jsx)(u,{})}):h.length>0?(0,O.jsx)(j,{title:r(`about.creditsDeps`),hint:s?void 0:r(`about.creditsDepsHint`),children:h.map(e=>(0,O.jsx)(N,{label:e.label,packages:e.packages},e.id))}):null,t!==null&&g?(0,O.jsx)(c,{children:r(`about.noMatches`)}):null]})}var F=[`new`,`earlier`,`credits`],I=e=>r(e===`new`?`about.tab.new`:e===`earlier`?`about.tab.earlier`:`about.credits`),L=e=>e===1?r(`about.change`):r(`about.changes`,{n:e});function R({open:e,onClose:t,me:n}){let a=n?.mode===`local`,{data:c,latest:p}=_(a&&e),[m,E]=(0,T.useState)(null),[D,k]=(0,T.useState)(`new`),A=b(F.indexOf(D)),j=c?.newer&&p?p:g;(0,T.useEffect)(()=>{if(!e)return;let t=!1;return E(null),S(j===`0.7.4`?void 0:j).then(e=>{t||E(e)}),()=>{t=!0}},[e,j]);let M=m?.find(e=>e.version===`v${j}`)??m?.[0]??null,N=m?.filter(e=>e!==M)??[],R=a?c?.kind??null:`cloud`;return(0,O.jsxs)(s,{open:e,onClose:t,wide:!0,height:`tall`,children:[(0,O.jsx)(`div`,{className:`-mt-2 -mr-2 sticky top-0 z-10 flex h-0 justify-end`,children:(0,O.jsx)(i,{label:r(`common.close`),onClick:t,children:(0,O.jsx)(l,{className:`size-4`})})}),(0,O.jsxs)(`div`,{className:`flex flex-col items-center pt-4 text-center`,children:[(0,O.jsx)(h,{size:96}),(0,O.jsxs)(`div`,{className:`mt-4 font-display font-semibold text-[1.5rem] tracking-tight`,children:[`engenty`,(0,O.jsx)(`span`,{className:`text-ember`,children:`.`}),(0,O.jsx)(`span`,{className:`ml-1.5 font-normal text-ink-3`,children:`wizards`})]}),(0,O.jsxs)(`div`,{className:`mt-1 text-[0.9375rem] text-ink-3 tabular-nums`,children:[r(`about.version`,{v:g}),R?` · ${r(`about.kind.${R}`)}`:``]})]}),a?(0,O.jsx)(`div`,{className:`mt-5`,children:(0,O.jsx)(v,{enabled:e})}):null,(0,O.jsx)(`div`,{className:`mt-6 flex justify-center`,children:(0,O.jsx)(d,{value:D,onChange:k,options:F.map(e=>({id:e,label:I(e)})),label:r(`about.title`)})}),(0,O.jsxs)(`div`,{className:o(`mt-5`,y(A)),children:[D===`new`?m===null?(0,O.jsx)(`div`,{className:`flex justify-center py-6 text-ink-3`,children:(0,O.jsx)(u,{})}):M?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`h3`,{className:`flex items-baseline gap-3 border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:[w(M),(0,O.jsx)(`span`,{className:`font-normal font-sans text-[0.8125rem] text-ink-3 tabular-nums`,children:C(M)})]}),(0,O.jsx)(`div`,{className:`mt-3`,children:(0,O.jsx)(x,{release:M})})]}):(0,O.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:r(`about.changelogEmpty`)}):null,D===`earlier`?(0,O.jsx)(`div`,{className:`flex flex-col divide-y divide-border-soft`,children:N.map(e=>(0,O.jsxs)(`details`,{className:`group/r py-2`,children:[(0,O.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-baseline gap-3 text-[0.875rem] [&::-webkit-details-marker]:hidden`,children:[(0,O.jsx)(f,{className:`size-3.5 shrink-0 self-center text-ink-4 transition group-open/r:rotate-90`}),(0,O.jsx)(`span`,{className:`font-medium text-ink tabular-nums`,children:w(e)}),(0,O.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:C(e)}),(0,O.jsx)(`span`,{className:`ml-auto text-[0.8125rem] text-ink-4`,children:L(e.commits.length)})]}),(0,O.jsx)(`div`,{className:`mt-2 pl-6`,children:(0,O.jsx)(x,{release:e})})]},e.version??`unreleased`))}):null,D===`credits`?(0,O.jsx)(P,{active:!0}):null]},D)]})}export{R as AboutDialog};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,It as i,Kt as a,Nt as o,Pt as s,Vt as c}from"./ui-CTXSFCzc.js";import{t as l}from"./preload-helper-CNEI7N0N.js";var u=e(t(),1),d=e(n(),1);function f(e){switch(e.group){case`Added`:return{label:`NEW`,dot:`bg-moss`};case`Fixed`:return{label:`FIXED`,dot:`bg-amber`};case`Changed`:return{label:`CHANGED`,dot:`bg-cobalt`};case`Performance`:return{label:`PERFORMANCE`,dot:`bg-ember`};case`Deploy`:return{label:`DEPLOY`,dot:`bg-ink-4`};case`Docs`:return{label:`DOCS`,dot:`bg-ink-4`};default:return{label:`OTHER`,dot:`bg-ink-4`}}}var p=e=>e.version?e.version.replace(/^v/,``):r(`about.unreleased`),m=e=>e.timestamp?new Date(e.timestamp*1e3).toISOString().slice(0,10):``,h=e=>e.charAt(0).toUpperCase()+e.slice(1);function g(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=[];for(let t of e){if(`${p(t)} ${m(t)}`.toLowerCase().includes(n)){r.push(t);continue}let e=t.commits.filter(e=>`${f(e).label} ${e.scope??``} ${e.message}`.toLowerCase().includes(n));e.length>0&&r.push({...t,commits:e})}return r}async function _(e){if(e)try{let t=await fetch(`https://raw.githubusercontent.com/engenty/engenty-wizards/v${e}/apps/web/src/about/changelog.json`,{signal:AbortSignal.timeout(5e3)});if(t.ok)return await t.json()}catch{}return(await l(async()=>{let{default:e}=await import(`./changelog-B3yrut-H.js`);return{default:e}},[])).default}function v({release:e}){return(0,d.jsx)(`ul`,{className:`flex flex-col gap-2`,children:e.commits.map(e=>{let t=f(e);return(0,d.jsxs)(`li`,{className:`flex items-start gap-2.5 text-[0.875rem]`,children:[(0,d.jsx)(`span`,{className:a(`mt-[7px] size-1.5 shrink-0 rounded-full`,t.dot)}),(0,d.jsxs)(`span`,{className:`min-w-0 text-ink-2`,children:[(0,d.jsxs)(`span`,{className:`font-semibold text-[0.75rem] text-ink tracking-wide`,children:[t.label,e.scope?` [${e.scope}]`:``]}),` `,h(e.message),e.breaking?(0,d.jsx)(`span`,{className:`ml-1.5 rounded-full bg-rose-tint px-1.5 py-0.5 font-medium text-[0.75rem] text-rose`,children:r(`about.breaking`)}):null]})]},e.id)})})}function y({open:e,onClose:t,version:n}){let[a,l]=(0,u.useState)(null),[f,h]=(0,u.useState)(``);(0,u.useEffect)(()=>{if(!e||a)return;let t=!1;return _(n).then(e=>{t||l(e)}),()=>{t=!0}},[e,a,n]),(0,u.useEffect)(()=>{e||h(``)},[e]);let y=a?g(a,f):[];return(0,d.jsxs)(o,{open:e,onClose:t,title:r(`about.changelog`),wide:!0,height:`tall`,children:[(0,d.jsx)(`p`,{className:`-mt-3 mb-4 text-[0.875rem] text-ink-3`,children:r(`about.changelogHint`)}),a===null?(0,d.jsx)(`div`,{className:`flex justify-center py-10 text-ink-3`,children:(0,d.jsx)(c,{})}):a.length===0?(0,d.jsx)(s,{children:r(`about.changelogEmpty`)}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i,{type:`search`,value:f,placeholder:r(`about.search`),onChange:e=>h(e.target.value)}),y.length===0?(0,d.jsx)(s,{children:r(`about.noMatches`)}):null,y.map(e=>(0,d.jsxs)(`section`,{className:`mt-6`,children:[(0,d.jsxs)(`h3`,{className:`flex items-baseline gap-3 border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:[p(e),(0,d.jsx)(`span`,{className:`font-normal font-sans text-[0.8125rem] text-ink-3 tabular-nums`,children:m(e)})]}),(0,d.jsx)(`div`,{className:`mt-3`,children:(0,d.jsx)(v,{release:e})})]},e.version??`unreleased`))]})]})}export{y as ChangelogDialog,v as ReleaseNotes,_ as loadReleases,m as releaseDate,p as releaseLabel};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$t as r,It as i,Kt as a,Nt as o,Pt as s,Vt as c}from"./ui-dzGvc3xk.js";import{t as l}from"./preload-helper-CNEI7N0N.js";var u=e(t(),1),d=e(n(),1);function f(e){switch(e.group){case`Added`:return{label:`NEW`,dot:`bg-moss`};case`Fixed`:return{label:`FIXED`,dot:`bg-amber`};case`Changed`:return{label:`CHANGED`,dot:`bg-cobalt`};case`Performance`:return{label:`PERFORMANCE`,dot:`bg-ember`};case`Deploy`:return{label:`DEPLOY`,dot:`bg-ink-4`};case`Docs`:return{label:`DOCS`,dot:`bg-ink-4`};default:return{label:`OTHER`,dot:`bg-ink-4`}}}var p=e=>e.version?e.version.replace(/^v/,``):r(`about.unreleased`),m=e=>e.timestamp?new Date(e.timestamp*1e3).toISOString().slice(0,10):``,h=e=>e.charAt(0).toUpperCase()+e.slice(1);function g(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=[];for(let t of e){if(`${p(t)} ${m(t)}`.toLowerCase().includes(n)){r.push(t);continue}let e=t.commits.filter(e=>`${f(e).label} ${e.scope??``} ${e.message}`.toLowerCase().includes(n));e.length>0&&r.push({...t,commits:e})}return r}async function _(e){if(e)try{let t=await fetch(`https://raw.githubusercontent.com/engenty/engenty-wizards/v${e}/apps/web/src/about/changelog.json`,{signal:AbortSignal.timeout(5e3)});if(t.ok)return await t.json()}catch{}return(await l(async()=>{let{default:e}=await import(`./changelog-Dj_yd2vG.js`);return{default:e}},[])).default}function v({release:e}){return(0,d.jsx)(`ul`,{className:`flex flex-col gap-2`,children:e.commits.map(e=>{let t=f(e);return(0,d.jsxs)(`li`,{className:`flex items-start gap-2.5 text-[0.875rem]`,children:[(0,d.jsx)(`span`,{className:a(`mt-[7px] size-1.5 shrink-0 rounded-full`,t.dot)}),(0,d.jsxs)(`span`,{className:`min-w-0 text-ink-2`,children:[(0,d.jsxs)(`span`,{className:`font-semibold text-[0.75rem] text-ink tracking-wide`,children:[t.label,e.scope?` [${e.scope}]`:``]}),` `,h(e.message),e.breaking?(0,d.jsx)(`span`,{className:`ml-1.5 rounded-full bg-rose-tint px-1.5 py-0.5 font-medium text-[0.75rem] text-rose`,children:r(`about.breaking`)}):null]})]},e.id)})})}function y({open:e,onClose:t,version:n}){let[a,l]=(0,u.useState)(null),[f,h]=(0,u.useState)(``);(0,u.useEffect)(()=>{if(!e||a)return;let t=!1;return _(n).then(e=>{t||l(e)}),()=>{t=!0}},[e,a,n]),(0,u.useEffect)(()=>{e||h(``)},[e]);let y=a?g(a,f):[];return(0,d.jsxs)(o,{open:e,onClose:t,title:r(`about.changelog`),wide:!0,height:`tall`,children:[(0,d.jsx)(`p`,{className:`-mt-3 mb-4 text-[0.875rem] text-ink-3`,children:r(`about.changelogHint`)}),a===null?(0,d.jsx)(`div`,{className:`flex justify-center py-10 text-ink-3`,children:(0,d.jsx)(c,{})}):a.length===0?(0,d.jsx)(s,{children:r(`about.changelogEmpty`)}):(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(i,{type:`search`,value:f,placeholder:r(`about.search`),onChange:e=>h(e.target.value)}),y.length===0?(0,d.jsx)(s,{children:r(`about.noMatches`)}):null,y.map(e=>(0,d.jsxs)(`section`,{className:`mt-6`,children:[(0,d.jsxs)(`h3`,{className:`flex items-baseline gap-3 border-border-soft border-b pb-2 font-display font-semibold text-[1rem]`,children:[p(e),(0,d.jsx)(`span`,{className:`font-normal font-sans text-[0.8125rem] text-ink-3 tabular-nums`,children:m(e)})]}),(0,d.jsx)(`div`,{className:`mt-3`,children:(0,d.jsx)(v,{release:e})})]},e.version??`unreleased`))]})]})}export{y as ChangelogDialog,v as ReleaseNotes,_ as loadReleases,m as releaseDate,p as releaseLabel};
@@ -0,0 +1,10 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{$ as r,$n as i,$t as a,Bn as o,Cr as s,Dr as c,Ft as l,Gn as u,Gt as d,Hn as f,Jt as p,Kn as m,Kt as h,Pn as g,Rr as _,Rt as v,Vt as y,W as b,Wn as x,Yn as S,br as C,bt as w,dt as T,ft as E,ir as D,lt as O,m as k,mt as A,nn as j,nr as M,nt as N,pt as P,qt as F,rt as I,st as L,tt as ee,un as R,ut as z,vt as B,wn as te,xt as ne,yt as re}from"./ui-dzGvc3xk.js";import{t as ie}from"./phone-CgrIS4_-.js";import{Ft as ae,Ot as oe,Wt as se,dt as ce,lt as le,qt as ue,t as de,ut as fe}from"./index-yiE9Lun0.js";import{n as pe}from"./RunnerView-BinlRsGF.js";var me={name:`hand`,size:24,node:[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]};me.node;var he=c(me),ge={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};ge.node;var _e=c(ge),ve={name:`video-off`,size:24,node:[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};ve.node;var V=c(ve),ye={name:`volume-x`,size:24,node:[[`path`,{d:`M11 4.702a.7.7 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.7.7 0 0 0 11 19.298z`,key:`1p7khw`}],[`path`,{d:`m16.5 14.5 5-5`,key:`cul3yw`}],[`path`,{d:`m16.5 9.5 5 5`,key:`1akey5`}]]};ye.node;var be=c(ye),xe=_(),H=e(t(),1),U=e(n(),1),Se=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function Ce({since:e}){let[t,n]=(0,H.useState)(Date.now());if((0,H.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),!e)return null;let r=Math.max(0,Math.floor((t-e)/1e3)),i=String(Math.floor(r/60)).padStart(2,`0`),a=String(r%60).padStart(2,`0`);return(0,U.jsxs)(`span`,{className:`font-mono text-[0.8125rem] text-white/60 tabular-nums`,children:[i,`:`,a]})}function W({label:e,on:t,danger:n,busy:r,onClick:i,children:a}){return(0,U.jsx)(`button`,{type:`button`,"aria-label":e,title:e,"aria-pressed":t,disabled:r,onClick:i,className:h(`flex size-12 items-center justify-center rounded-full transition disabled:opacity-50`,n?`bg-rose text-white hover:brightness-110`:t===!1?`bg-white text-neutral-900 hover:bg-white/90`:`bg-white/15 text-white hover:bg-white/25`),children:r?(0,U.jsx)(y,{className:`size-5`}):a})}function we({voice:e}){let t=(0,H.useRef)(null),{captions:n}=e;return(0,H.useEffect)(()=>{n.length&&t.current?.scrollIntoView({block:`end`})},[n]),n.length?(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 sm:px-5`,children:(0,U.jsxs)(`ol`,{className:`mx-auto flex max-w-[720px] flex-col gap-2 py-2`,children:[n.map(e=>(0,U.jsx)(`li`,{className:h(`text-[0.9375rem] leading-snug`,e.who===`bot`?`text-white/95`:`text-right text-white/50`),children:e.text},e.id)),(0,U.jsx)(`div`,{ref:t})]})}):null}function Te({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,o=e.state===`connecting`,[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(!1);(0,H.useEffect)(()=>{c(i?Date.now():null)},[i]);let d=async()=>{u(!1),await e.start(),n&&await e.startCamera()},p=()=>{e.stop(),u(!0)},m=n||e.camera,g=[...e.captions].reverse().find(e=>e.who===`bot`),_=[...e.captions].reverse().find(e=>e.who===`me`),v=e.speaking?a(`talk.speaking`):e.listening?a(`talk.listening`):i?a(`talk.live`):o?a(`talk.connecting`):l?a(`video.ended`):``;return(0,U.jsxs)(`section`,{className:h(`relative flex min-h-0 flex-col bg-neutral-950 text-white`,`safe-top`,r),children:[(0,U.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4 sm:px-5`,children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1rem] tracking-tight`,children:t?.wizard.title??``}),v?(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,U.jsx)(`span`,{className:h(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,v]}):null,(0,U.jsx)(Ce,{since:s})]}),(0,U.jsxs)(`div`,{className:h(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,m?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!m&&i&&e.captions.length?`h-[38%]`:m?``:`flex-1`),children:[(0,U.jsxs)(`div`,{className:h(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!m&&`hidden`),children:[(0,U.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:h(`absolute inset-0 h-full w-full object-cover`,e.facing===`user`&&`-scale-x-100`,e.camera?`block`:`hidden`)}),e.camera?null:(0,U.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/50`,children:[(0,U.jsx)(V,{className:`size-8`}),(0,U.jsx)(`span`,{className:`text-[0.8125rem]`,children:a(`video.cameraOff`)})]}),(0,U.jsxs)(`span`,{className:`absolute bottom-2 left-3 rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:[a(`video.you`),e.muted?(0,U.jsx)(ue,{className:`ml-1.5 inline size-3`}):null]})]}),(0,U.jsxs)(`div`,{className:h(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,m?`bg-neutral-900`:`bg-transparent`,m&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,U.jsx)(`div`,{className:h(`rounded-full transition-shadow duration-500`,!m&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!m&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,U.jsx)(oe,{kind:t?.wizard.avatar??`round`,size:m?140:200,fluffy:!0,interactive:!1})}),m?(0,U.jsx)(`span`,{className:`absolute bottom-2 left-3 max-w-[85%] truncate rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:t?.wizard.title??``}):null]})]}),i&&!m?(0,U.jsx)(we,{voice:e}):i&&(g||_)?(0,U.jsx)(`div`,{className:`shrink-0 px-4 pb-2 sm:px-5`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-[720px] space-y-1 text-center`,children:[_?(0,U.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:_.text}):null,g?(0,U.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:g.text}):null]})}):null,e.error?(0,U.jsx)(`p`,{className:`shrink-0 px-5 pb-2 text-center text-[0.8125rem] text-rose`,children:e.error}):null,(0,U.jsx)(`div`,{className:`flex shrink-0 items-center justify-center gap-3 px-4 pt-1 pb-4`,children:i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(W,{label:a(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,U.jsx)(ue,{className:`size-5`}):(0,U.jsx)(D,{className:`size-5`})}),(0,U.jsx)(W,{label:a(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,U.jsx)(f,{className:`size-5`}):(0,U.jsx)(V,{className:`size-5`})}),e.camera&&Se?(0,U.jsx)(W,{label:a(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,U.jsx)(x,{className:`size-5`})}):null,(0,U.jsx)(W,{label:a(`video.leave`),danger:!0,onClick:p,children:(0,U.jsx)(se,{className:`size-5`})})]}):(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:o||!t?.talk,onClick:()=>void d(),className:`flex h-12 items-center gap-2 rounded-full bg-emerald-500 px-6 font-medium text-[0.9375rem] text-white transition hover:brightness-110 disabled:opacity-50`,children:[o?(0,U.jsx)(y,{className:`size-4`}):n?(0,U.jsx)(f,{className:`size-5`}):(0,U.jsx)(D,{className:`size-5`}),a(l?`video.rejoin`:n?`video.join`:`talk.start`)]}),!l&&!e.error?(0,U.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:a(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var Ee=e=>R[e.kind]!==`device`,De=1024,Oe=4e3;function ke(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function Ae(e,t,n=!1){let r=[`status: ${e.status}`,`camera: ${n?`on`:`off`}`];if(e.ask)return r.push(e.ask.kind===`confirm`?`question: the step wants to "${e.ask.action.summary}" in ${e.ask.service}; answer_ask allows or skips it`:`question: a sign-in at ${e.ask.site.host}; the person types it on the screen, wait`),r.join(`
2
+ `);if(e.status===`running`){let t=[...e.events].reverse().find(e=>e.type===`tool`||e.type===`info`||e.type===`step_started`);return r.push(`working on: ${e.step?.title??``}`),t&&r.push(`doing: ${F(t)}`),r.join(`
3
+ `)}if(e.status===`done`){r.push(`done. made:`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.title}: ${ke(n?.text,400)||`(a file, on the screen)`}`);return r.join(`
4
+ `)}if(e.status===`failed`)return r.push(`failed: ${e.error??``}; go_back or the person retries on the screen`),r.join(`
5
+ `);if(t){r.push(`page: ${t.step.title}`);for(let e of t.fields){let n=t.values[e.id],i=n!=null&&n!==``,a=Ee(e)?`by voice`:e.kind===`image`?`with the camera (take_photo) or on the screen`:`on the screen only`,o=e.options?.length?`; options: ${e.options.join(` | `)}`:``;r.push(`- field ${e.id} (${e.kind}${e.required?`, required`:``}, ${a}): ${e.label}${e.help?` – ${e.help}`:``}${o}${i?` = ${ke(String(Array.isArray(n)?n.join(`, `):n),120)}`:` = (open)`}`)}return r.join(`
6
+ `)}if(e.step?.type===`review`){r.push(`review: ${e.step.title}`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.id} "${t.title}": ${ke(n?.text,600)||`(a picture or file, on the screen)`}`);return r.push(`regenerate allowed: ${e.step.regenerate?`yes`:`no`}`),r.join(`
7
+ `)}return r.push(`step: ${e.step?.title??``}`),r.join(`
8
+ `)}function je(e,t,n,r){let[i,o]=(0,H.useState)(`off`),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(!1),[h,g]=(0,H.useState)(`environment`),[_,v]=(0,H.useState)(!1),[y,x]=(0,H.useState)([]),S=(0,H.useRef)(null),C=(0,H.useRef)(null),w=(0,H.useRef)(0),T=(0,H.useRef)(!1);T.current=p;let E=(0,H.useRef)(null),D=(0,H.useRef)(null),O=(0,H.useRef)(null),k=(0,H.useRef)(null),A=(0,H.useRef)(t);A.current=t;let j=(0,H.useRef)(r);j.current=r;let M=(0,H.useRef)(n);M.current=n;let N=(0,H.useRef)(``),P=(0,H.useCallback)(e=>{let t=D.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,H.useCallback)(()=>{let e=S.current;if(!T.current||!e||e.videoWidth===0)return null;let t=Math.min(1,De/e.videoWidth),n=document.createElement(`canvas`);return n.width=Math.round(e.videoWidth*t),n.height=Math.round(e.videoHeight*t),n.getContext(`2d`)?.drawImage(e,0,0,n.width,n.height),n.toDataURL(`image/jpeg`,.75)},[]),I=(0,H.useCallback)(()=>{for(let e of C.current?.getTracks()??[])e.stop();C.current=null,S.current&&(S.current.srcObject=null),m(!1)},[]),L=(0,H.useCallback)(async e=>{if(C.current)return;let t=e??`environment`;try{let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:t},width:{ideal:1280}},audio:!1});C.current=e;let n=e.getVideoTracks()[0]?.getSettings().facingMode;g(n===`user`||n===`environment`?n:t),S.current&&(S.current.srcObject=e,await S.current.play().catch(()=>void 0)),m(!0)}catch(e){c(e.name===`NotAllowedError`?a(`talk.cameraDenied`):e.message)}},[]),ee=(0,H.useCallback)(async()=>{let e=h===`user`?`environment`:`user`;I(),await L(e)},[h,I,L]),R=(0,H.useCallback)(()=>{v(e=>{for(let t of k.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),z=(0,H.useCallback)(()=>{I(),D.current?.close(),D.current=null,E.current?.close(),E.current=null;for(let e of k.current?.getTracks()??[])e.stop();k.current=null,O.current&&=(O.current.srcObject=null,O.current.remove(),null),N.current=``,u(!1),f(!1),v(!1),o(`off`)},[I]);(0,H.useEffect)(()=>()=>z(),[z]);let B=(0,H.useCallback)(async(t,n)=>{let r=A.current,i=j.current,a=M.current;switch(t){case`get_state`:return r?Ae(r,i,T.current):`no run`;case`look`:{let e=F();return e?(P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[camera] what the person shows right now`},{type:`input_image`,image_url:e}]}}),`a picture arrived as the next message`):`the camera is off; ask the person to switch it on`}case`take_photo`:{if(!i)return`no page is open`;let t=i.fields.find(e=>e.id===String(n.field??``));if(t?.kind!==`image`)return`no such photo field on this page`;let r=F();if(!r)return`the camera is off; ask the person to switch it on`;try{let n=await(await fetch(r)).blob(),a=new File([n],`photo-${Date.now()}.jpg`,{type:`image/jpeg`}),o=await b.upload(`/api/runs/${e}/uploads`,a),s=i.values[t.id],c=t.multiple?[...Array.isArray(s)?s:s?[s]:[],o.id]:o.id,l=i.setField(t.id,c);return l?`refused: ${l}`:`the photo is in the field`}catch(e){return`failed: ${e.message}`}}case`set_field`:{if(!i)return`no page is open`;let e=i.setField(String(n.field??``),n.value);return e?`refused: ${e}`:`kept`}case`submit_page`:{if(!i)return`no page is open`;let e=i.fields.filter(e=>e.required&&Ee(e)&&e.kind!==`toggle`&&(i.values[e.id]===void 0||i.values[e.id]===null||i.values[e.id]===``));return e.length?`still open: ${e.map(e=>e.id).join(`, `)}`:(i.submit(),`sent; wait for the next state`)}case`accept_review`:return r?.step?.type===`review`?await a.accept(r.step.id)?`accepted`:a.error??`refused`:`no review is open`;case`regenerate`:return r?.step?.type===`review`?await a.regenerate(r.step.id,String(n.target??``),String(n.note??``))?`the wizard makes it again; wait`:a.error??`refused`:`no review is open`;case`answer_ask`:if(!r?.ask)return`no question is open`;try{return await b.post(`/api/runs/${e}/ask/${r.ask.id}`,{type:n.allow?`done`:`skip`}),n.allow?`allowed`:`skipped`}catch(e){return`refused: ${e.message}`}case`go_back`:return await a.back()?`went back; wait for the state`:a.error??`refused`;default:return`unknown tool ${t}`}},[e,F,P]),te=(0,H.useCallback)(async()=>{if(!E.current){c(null),x([]),o(`connecting`);try{let t=await b.post(`/api/runs/${e}/talk`),n=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}});k.current=n;let r=new RTCPeerConnection;E.current=r;let i=document.createElement(`audio`);i.autoplay=!0,i.setAttribute(`playsinline`,``),document.body.append(i),O.current=i,r.ontrack=e=>{i.srcObject=e.streams[0]};for(let e of n.getTracks())r.addTrack(e,n);let s=r.createDataChannel(`oai-events`);D.current=s,s.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case`output_audio_buffer.started`:u(!0);break;case`output_audio_buffer.stopped`:case`output_audio_buffer.cleared`:u(!1);break;case`input_audio_buffer.speech_started`:{f(!0);let e=Date.now()-w.current>Oe?F():null;e&&(w.current=Date.now(),P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[camera] what the person shows while speaking`},{type:`input_image`,image_url:e}]}}));break}case`input_audio_buffer.speech_stopped`:f(!1);break;case`response.output_audio_transcript.done`:case`conversation.item.input_audio_transcription.completed`:{let e=String(t.transcript??``).trim();if(e){let n=t.type===`response.output_audio_transcript.done`?`bot`:`me`;x(t=>[...t.slice(-199),{id:`${Date.now()}:${n}`,who:n,text:e}])}break}case`response.function_call_arguments.done`:{let e=String(t.name??``),n=String(t.call_id??``),r={};try{r=JSON.parse(String(t.arguments??`{}`))}catch{}B(e,r).then(e=>{P({type:`conversation.item.create`,item:{type:`function_call_output`,call_id:n,output:e}}),P({type:`response.create`})});break}case`error`:c(String(t.error?.message??`error`))}},s.onopen=()=>{o(`live`);let e=A.current;e&&(N.current=Ae(e,j.current,T.current),P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[state]\n${N.current}\n\nGreet the person in one sentence and ask the first open field.`}]}}),P({type:`response.create`}))},s.onclose=()=>{E.current===r&&z()};let l=await r.createOffer();await r.setLocalDescription(l);let d=await fetch(t.endpoint,{method:`POST`,headers:{authorization:`Bearer ${t.clientSecret}`,"content-type":`application/sdp`},body:l.sdp});if(!d.ok)throw Error(`${a(`talk.failed`)} (${d.status})`);await r.setRemoteDescription({type:`answer`,sdp:await d.text()})}catch(e){z(),c(e.name===`NotAllowedError`?a(`chat.micDenied`):e.message),o(`error`)}}},[e,B,F,P,z]);return(0,H.useEffect)(()=>{if(i!==`live`||!t)return;let e=Ae(t,r,p);if(e===N.current)return;let n=N.current;N.current=e,P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[state]\n${e}`}]}}),(t.status===`running`&&n.startsWith(`status: running`)&&!n.includes(`working on: `)||t.status!==`running`||n.split(`
9
+ `)[1]!==e.split(`
10
+ `)[1])&&P({type:`response.create`})},[i,t,r,p,P]),{state:i,error:s,speaking:l,listening:d,start:te,stop:z,camera:p,facing:h,startCamera:L,stopCamera:I,flipCamera:ee,muted:_,toggleMute:R,captions:y,video:S}}var G=(e,t,n)=>({key:e,who:`bot`,node:t,...n}),K=(e,t,n)=>({key:e,who:`me`,node:t,...n}),Me=(0,H.createContext)(null),q=(0,H.createContext)(null);function Ne(){return(0,H.useContext)(q)?.voice??null}function Pe({children:e}){let t=(0,H.useContext)(Me);return t?(0,xe.createPortal)(e,t):null}function Fe({header:e,footer:t,children:n}){let[r,i]=(0,H.useState)(null),a=(0,H.useRef)(null),o=(0,H.useRef)(null),s=(0,H.useRef)(!0);return(0,H.useLayoutEffect)(()=>{let e=a.current,t=o.current;if(!e||!t)return;let n=e.scrollTop,r=()=>{e.scrollHeight-e.scrollTop-e.clientHeight<120?s.current=!0:e.scrollTop<n&&(s.current=!1),n=e.scrollTop},i=null,c=new ResizeObserver(()=>{let r=t.querySelector(`[data-anchor]`);r&&r!==i?(i=r,e.scrollTop+=r.getBoundingClientRect().top-e.getBoundingClientRect().top-12,s.current=!1,n=e.scrollTop):s.current&&(e.scrollTop=e.scrollHeight)});return e.scrollTop=e.scrollHeight,e.addEventListener(`scroll`,r,{passive:!0}),c.observe(t),c.observe(e),()=>{c.disconnect(),e.removeEventListener(`scroll`,r)}},[]),(0,U.jsx)(Me.Provider,{value:r,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[e,(0,U.jsx)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,U.jsx)(`div`,{ref:o,className:`mx-auto flex w-full max-w-[760px] flex-col gap-3 px-3 pt-5 pb-4 sm:px-6`,children:n})}),(0,U.jsxs)(`div`,{className:`shrink-0 border-border-soft border-t bg-background`,onPointerDownCapture:()=>{s.current=!0},onKeyDownCapture:()=>{s.current=!0},children:[(0,U.jsx)(`div`,{ref:i,className:`mx-auto w-full max-w-[760px] px-3 pt-3 sm:px-6`}),t]})]})})}function J({avatar:e,lines:t}){let n=(0,H.useContext)(q),r=(0,H.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),o=(0,H.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);ce(!!n?.readAloud,n?.lang??p,r,o);let s=[];for(let e of t){let t=s.at(-1);t&&t.who===`bot`&&e.who===`bot`?t.lines.push(e):s.push({who:e.who,lines:[e]})}return s.map((t,n)=>t.who===`bot`?(0,U.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,U.jsx)(`div`,{className:`sticky top-1 shrink-0 pt-0.5`,children:(0,U.jsx)(oe,{kind:e,size:30,interactive:n>=s.length-2})}),(0,U.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:t.lines.map(e=>(0,U.jsx)(`div`,{"data-anchor":e.anchor?``:void 0,"data-say":e.key,className:h(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?h(`w-full bg-card p-4 shadow-soft ring-1 ring-border-soft`,e.wide===`most`&&`md:w-4/5`):`max-w-[min(36rem,100%)] bg-card px-4 py-2.5 shadow-soft ring-1 ring-border-soft`),e.tone===`error`&&`bg-rose-tint text-rose shadow-none ring-0`),children:e.node},e.key))})]},t.lines[0].key):t.lines.map(e=>(0,U.jsxs)(`div`,{className:`flex animate-rise flex-col items-end gap-1 pl-10`,children:[(0,U.jsx)(`div`,{className:`max-w-[min(32rem,100%)] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-primary px-4 py-2.5 text-[0.9375rem] text-primary-foreground leading-relaxed`,children:e.node}),e.onEdit?(0,U.jsxs)(`button`,{type:`button`,onClick:e.onEdit,className:`inline-flex items-center gap-1 px-1 text-[0.75rem] text-ink-4 transition hover:text-ink-2 coarse:min-h-9`,children:[(0,U.jsx)(i,{className:`size-3`}),` `,a(`chat.change`)]}):null]},e.key)))}function Ie(){return(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":a(`run.working`),children:[0,1,2].map(e=>(0,U.jsx)(`span`,{className:`size-1.5 animate-typing rounded-full bg-ink-3`,style:{animationDelay:`${e*160}ms`}},e))})}function Y({children:e}){return(0,U.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}var X=(e,t)=>G(e,(0,U.jsx)(Y,{children:t}),{bare:!0});function Z({onClick:e,children:t,primary:n,on:r,disabled:i,busy:a}){return(0,U.jsxs)(`button`,{type:`button`,"aria-pressed":r,disabled:i||a,onClick:e,className:h(`inline-flex h-10 items-center gap-1.5 rounded-full px-4 font-medium text-[0.875rem] transition active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 coarse:h-11`,n?`bg-primary text-primary-foreground hover:brightness-[1.06]`:r?`bg-ember-tint text-ink ring-1 ring-ember`:`bg-card text-ink-2 ring-1 ring-input hover:text-ink hover:ring-ink-4`),children:[a?(0,U.jsx)(y,{className:`size-4`}):null,t]})}function Le({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:o,inputRef:c,onSend:p}){let[m,g]=(0,H.useState)(e),_=(0,H.useRef)(null),v=c??_,b=(0,H.useContext)(q),x=k(m,g,{endpoint:b?`/api/runs/${b.runId}/transcribe`:void 0}),S=!!b&&x.supported&&!o;(0,H.useEffect)(()=>{if(!S)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),x.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,x.toggle]),(0,H.useEffect)(()=>{!B&&!o&&v.current?.focus()},[o,v]);let C=()=>{i||o||(x.listening&&x.toggle(),p(m)!==!1&&g(``))},w=x.listening?a(`chat.listening`):x.processing?a(`chat.transcribing`):t,T=b?.voice??null,E=!!b?.call,O=b&&!E&&(le||S||T)?(0,U.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[T?(0,U.jsx)(l,{label:a(T.state===`live`?`talk.stop`:T.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":T.state===`live`,disabled:T.state===`connecting`,onClick:()=>T.state===`live`?T.stop():void T.start(),className:h(`size-9`,T.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,T.state===`off`&&b.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:T.state===`connecting`?(0,U.jsx)(y,{className:`size-4`}):T.state===`live`?(0,U.jsx)(se,{className:`size-4`}):(0,U.jsx)(ie,{className:`size-4`})}):null,T?.state===`live`?(0,U.jsx)(l,{label:a(T.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":T.camera,onClick:()=>T.camera?T.stopCamera():void T.startCamera(),className:h(`size-9`,T.camera&&`text-ink`),children:T.camera?(0,U.jsx)(f,{className:`size-4`}):(0,U.jsx)(V,{className:`size-4`})}):null,le?(0,U.jsx)(l,{label:a(b.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":b.readAloud,onClick:()=>b.setReadAloud(!b.readAloud),className:h(`size-9`,b.readAloud&&`text-ink`),children:b.readAloud?(0,U.jsx)(ae,{className:`size-4`}):(0,U.jsx)(be,{className:`size-4`})}):null,S?(0,U.jsx)(l,{label:a(x.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":x.listening,disabled:x.processing,onClick:x.toggle,className:h(`size-9`,x.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:x.processing?(0,U.jsx)(y,{className:`size-4`}):x.listening?(0,U.jsx)(u,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,U.jsx)(D,{className:`size-4`})}):null]}):null;return(0,U.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),C()},children:[T&&!E?(0,U.jsx)(`video`,{ref:T.video,muted:!0,playsInline:!0,autoPlay:!0,className:h(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,T.camera?`block`:`hidden`)}):null,(0,U.jsxs)(`div`,{className:h(`flex items-end gap-1 rounded-[1.375rem] border border-input bg-card pr-1.5 pl-1 transition focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,o&&`opacity-60`),children:[O,n?(0,U.jsx)(d,{ref:v,minRows:1,maxRows:6,value:m,disabled:o,placeholder:w,autoCapitalize:`sentences`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!B&&!e.nativeEvent.isComposing&&(e.preventDefault(),C())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,U.jsx)(`input`,{ref:v,...r,value:m,disabled:o,placeholder:w,enterKeyHint:`send`,onChange:e=>g(e.target.value),className:`h-11 min-w-0 flex-1 bg-transparent px-3 text-[0.9375rem] text-ink outline-none placeholder:text-ink-4`}),(0,U.jsx)(`button`,{type:`submit`,"aria-label":a(`chat.send`),title:a(`chat.send`),disabled:i||o,className:`mb-1 flex size-9 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:brightness-[1.06] disabled:opacity-40`,children:i?(0,U.jsx)(y,{className:`size-4`}):(0,U.jsx)(s,{className:`size-4`})})]}),x.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:x.error===`denied`?a(`chat.micDenied`):x.error}):E?null:T?.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:T.error}):T?.state===`live`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:T.speaking?a(`talk.speaking`):T.listening?a(`talk.listening`):a(`talk.live`)}):b?.talk&&T?.state===`off`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:a(`talk.hint`)}):null]})}function Q({placeholder:e=a(`chat.above`)}){return(0,U.jsx)(Pe,{children:(0,U.jsx)(Le,{disabled:!0,placeholder:e,onSend:()=>!1})})}function Re(e){let t=R[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var ze=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Be(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(ze(t))return e.required&&!n?a(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return a(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return a(`chat.badUrl`)}return e.kind===`number`&&o(r)===null?a(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?a(`run.filesMin`,{n:t.length,min:e.min}):null}function Ve(e,t){let n=e.kind===`textarea`?t.replace(/\s+$/,``):t.trim();if(n)return e.kind===`url`&&!/^[a-z][a-z0-9+.-]*:/i.test(n)?`https://${n}`:n}function He({field:e}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.label}),e.help?(0,U.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.help}):null]})}function Ue({step:e,only:t}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.title}),e.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:e.description}):null,t?.help?(0,U.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:t.help}):null]})}function We({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,U.jsx)(U.Fragment,{children:typeof t==`string`&&t?t:a(`chat.connected`)});if(e.kind===`list`)return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(C,{className:`size-4`}),` `,a(`chat.checked`)]});if(e.kind===`toggle`)return(0,U.jsx)(U.Fragment,{children:a(t===!0?`run.yes`:`run.no`)});if(ze(t))return(0,U.jsx)(`span`,{className:`italic opacity-80`,children:a(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,U.jsx)(U.Fragment,{children:t.map(j).join(`, `)});case`select`:return(0,U.jsx)(U.Fragment,{children:j(String(t))});case`date`:{let e=new Date(`${String(t)}T00:00`);return(0,U.jsx)(U.Fragment,{children:Number.isNaN(e.getTime())?String(t):new Intl.DateTimeFormat(p,{dateStyle:`long`}).format(e)})}case`color`:return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`size-4 rounded-full ring-1 ring-white/50`,style:{background:String(t)}}),String(t)]});case`image`:case`signature`:return(0,U.jsx)(`span`,{className:`-mx-1.5 flex flex-wrap gap-1.5`,children:(Array.isArray(t)?t:[String(t)]).map(t=>(0,U.jsx)(`img`,{src:r(`/api/runs/${n}/assets/${t}`),alt:``,className:h(`h-16 rounded-lg bg-white`,e.kind===`image`?`w-16 object-cover`:`object-contain px-1`)},t))});case`file`:{let e=Array.isArray(t)?t.length:1;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(M,{className:`size-4`}),` `,a(e===1?`chat.file`:`chat.files`,{n:e})]})}case`audio`:{let e=t.seconds;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(D,{className:`size-4`}),` `,a(`chat.voice`),e?` · ${Math.round(e)} s`:``]})}case`location`:{let e=t;return(0,U.jsx)(U.Fragment,{children:e.label||`${e.lat?.toFixed(5)}, ${e.lng?.toFixed(5)}`})}case`items`:return(0,U.jsx)(U.Fragment,{children:a(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,U.jsx)(U.Fragment,{children:String(t)})}}function Ge(e,t,n,r,i,a){let o=[G(t,(0,U.jsx)(Ue,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,U.jsx)(He,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,U.jsx)(We,{field:e,value:n[e.id],runId:r})));return o}var Ke=(e,t)=>e.fields.filter(e=>!e.when&&!te(e)||t[e.id]!==void 0&&t[e.id]!==null);function qe(e,t){let n=[];e.wizard.description&&n.push(G(`hello`,e.wizard.description)),e.wizard.intro&&n.push(G(`intro`,e.wizard.intro));for(let[t,r]of e.answered.entries()){let i=`${t}:${r.id}`;if(r.type===`page`){let t=r.fields.length===1?r.fields[0]:void 0;n.push(...Ge(r,i,e.values,e.id,Ke(r,e.values),t))}else r.type===`review`&&(n.push(G(i,(0,U.jsx)(`span`,{className:`font-medium`,children:r.title}))),n.push(K(`${i}:a`,a(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function Je(e,t){return e.fields.filter(e=>!te(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function Ye({view:e,run:t,step:n,before:r}){let i=(0,H.useMemo)(()=>Je(n,e),[n,e]),o=e.known??{},[s,c]=(0,H.useState)(()=>ee(n,e)),[l,u]=(0,H.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?g(Je(n,e),e.known??{},ee(n,e)).slice(0,-1).map(e=>e.id):[]),[d,f]=(0,H.useState)({}),[p,m]=(0,H.useState)(!1),[h,_]=(0,H.useState)(!1),v=g(i,o,s),y=v.filter(e=>l.includes(e.id)),b=v.find(e=>!l.includes(e.id)),x=i.length===1?i[0]:void 0,S=y.at(-1),C=S?()=>u(e=>e.filter(e=>e!==S.id)):void 0;(0,H.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=g(i,o,s),r=n.findIndex(t=>e.includes(t.id));r>=0&&(u(n.slice(0,r).map(e=>e.id)),f(t.fieldErrors))},[t.fieldErrors]);let w=e=>{t.submitPage(n.id,e).then(_)},T=(0,H.useContext)(q),E=(0,H.useRef)(s);E.current=s;let D=T?.bindPage,k=(0,H.useRef)(w);k.current=w,(0,H.useEffect)(()=>{if(!D)return;let e=g(i,o,s);return D({step:n,fields:e,values:s,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Be(r,n)||(c(e=>({...e,[t]:n})),u(e=>e.includes(t)?e:[...e,t]),f({}),null):`no such field on this page`},submit:()=>k.current(E.current)}),()=>D(null)},[D,n,i,o,s]);let A=e=>{if(!b)return!1;let t=Be(b,e);if(t)return f({[b.id]:t}),!1;let n={...s,[b.id]:e},r=[...l,b.id];return c(n),u(r),f({}),g(i,o,n).some(e=>!r.includes(e.id))||w(n),!0},j=[...r.map(e=>l.length?{...e,onEdit:void 0}:e),...Ge(n,`now:${n.id}`,s,e.id,y,x).map((e,t,n)=>t===n.length-1&&e.who===`me`&&b?{...e,onEdit:C}:e)];b?(Re(b)===`control`?j.push(G(`now:${n.id}:${b.id}:control`,(0,U.jsx)(O,{field:b,value:s[b.id],values:s,runId:e.id,view:e,closed:e.closed?.[b.id],onChange:e=>c(t=>({...t,[b.id]:e})),onBusy:m}),{wide:!0})):x||j.push(G(`now:${n.id}:${b.id}`,(0,U.jsx)(He,{field:b}))),d[b.id]&&j.push(G(`now:${n.id}:${b.id}:error`,d[b.id],{tone:`error`}))):t.busy||h?j.push(G(`sending`,(0,U.jsx)(Ie,{}))):t.error&&j.push(G(`send-error`,t.error,{tone:`error`}));let M=(0,U.jsx)(Q,{});if(h||!b&&l.length>0&&t.busy)M=(0,U.jsx)(Q,{placeholder:a(`run.working`)});else if(!b)j.push(X(`now:${n.id}:go`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>w(s),children:n.cta||a(`run.next`)}),C?(0,U.jsx)(Z,{onClick:C,disabled:t.busy,children:a(`run.back`)}):null]})));else{let r=Re(b),i=!b.required&&b.kind!==`connection`&&b.kind!==`list`?(0,U.jsx)(Z,{onClick:()=>A(void 0),children:a(`chat.skip`)}):null;if(r===`typed`){i&&j.push(X(`now:${n.id}:${b.id}:replies`,i));let e=s[b.id];M=(0,U.jsx)(Pe,{children:(0,U.jsx)(Le,{initial:ze(e)?``:String(e),multiline:b.kind===`textarea`,placeholder:b.placeholder||(x?b.label:a(`chat.placeholder`)),inputProps:Xe(b),busy:t.busy,onSend:e=>A(Ve(b,e))},b.id)})}else if(r===`tapped`)j.push(G(`now:${n.id}:${b.id}:replies`,(0,U.jsx)(Ze,{field:b,view:e,value:s[b.id],onAnswer:A}),{bare:!0}));else{let e=v.filter(e=>!l.includes(e.id)).length===1;j.push(X(`now:${n.id}:${b.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,disabled:p,onClick:()=>A(s[b.id]),children:e&&n.cta?n.cta:a(`chat.send`)}),i]})))}}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:j}),M]})}function Xe(e){switch(e.kind){case`number`:return{inputMode:`decimal`,autoComplete:`off`};case`email`:return{type:`email`,inputMode:`email`,autoComplete:`email`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1};case`url`:return{inputMode:`url`,autoComplete:`url`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1};case`date`:return{type:`date`};default:return z(e)}}function Ze({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[o,s]=(0,H.useState)(Array.isArray(n)?n:[]);if(e.kind===`toggle`)return(0,U.jsxs)(Y,{children:[(0,U.jsx)(Z,{on:n===!1,disabled:i.has(`false`),onClick:()=>r(!1),children:a(`run.no`)}),(0,U.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:a(`run.yes`)})]});let c=e.options??[];return e.kind===`multiselect`?(0,U.jsxs)(Y,{children:[c.map(e=>(0,U.jsx)(Z,{on:o.includes(e),onClick:()=>s(t=>t.includes(e)?t.filter(t=>t!==e):c.filter(n=>n===e||t.includes(n))),children:j(e)},e)),(0,U.jsx)(Z,{primary:!0,disabled:e.required&&!o.length,onClick:()=>r(o),children:o.length||e.required?a(`chat.send`):a(`chat.skip`)})]}):(0,U.jsxs)(Y,{children:[c.map(e=>(0,U.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:j(e)},e)),e.required?null:(0,U.jsx)(Z,{onClick:()=>r(void 0),children:a(`chat.skip`)})]})}function Qe({view:e}){let t=(0,H.useMemo)(()=>[...e.events].reverse().find(t=>t.type===`step_started`&&t.stepId===e.step?.id),[e.events,e.step?.id]),n=t?new Date(t.at).getTime():Date.now(),[i,o]=(0,H.useState)(Date.now());(0,H.useEffect)(()=>{let e=setInterval(()=>o(Date.now()),1e3);return()=>clearInterval(e)},[]);let s=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),c=s.at(-1),l=[...s].reverse().find(et),u=[...new Set(s.map(e=>e.asset).filter(e=>!!e))];return(0,U.jsxs)(`div`,{className:h(`flex max-w-full flex-col gap-1`,l?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??a(`run.working`),children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(Ie,{}),(0,U.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??a(`run.working`)}),(0,U.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:a(`run.elapsed`,{s:Math.max(0,Math.round((i-n)/1e3))})})]}),c&&c!==l?(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,U.jsx)(m,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,U.jsx)(`span`,{className:`truncate`,children:F(c)})]}):null,l&&e.status===`running`?(0,U.jsx)(nt,{runId:e.id,event:l}):null,u.length?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:u.slice(-6).map(t=>(0,U.jsx)(`img`,{src:r(`/api/runs/${e.id}/assets/${t}`),alt:``,className:`size-14 rounded-lg bg-paper-2 object-cover ring-1 ring-border-soft`},t))}):null]})}var $e=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function et(e){return!!e.note&&$e.has(e.note.code)}var tt=1e4;function nt({runId:e,event:t}){let[n,r]=(0,H.useState)(null),[i,o]=(0,H.useState)(`agent`),[s,c]=(0,H.useState)(!1),l=t.note?.code;if((0,H.useEffect)(()=>{l===`personDrives`?o(`person`):l===`agentDrives`&&o(`agent`)},[l]),(0,H.useEffect)(()=>{let t=()=>b.get(`/api/runs/${e}/browser/seat`).then(e=>o(e.seat)).catch(()=>void 0);if(t(),i!==`person`)return;let n=setInterval(t,tt);return()=>clearInterval(n)},[e,i]),n!==null&&n>=t.id)return null;let u=i===`person`,d=async()=>{c(!0);try{let t=await b.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});o(t.seat)}catch{}finally{c(!1)}};return(0,U.jsx)(ne,{runId:e,driving:u,caption:F(t),hint:a(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,U.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void d(),className:h(`flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[0.8125rem] shadow-soft transition-colors disabled:opacity-60`,u?`bg-primary text-primary-foreground hover:bg-primary/90`:`bg-card/90 text-ink ring-1 ring-border-soft backdrop-blur hover:bg-card`),children:[u?(0,U.jsx)(_e,{className:`size-3.5`}):(0,U.jsx)(he,{className:`size-3.5`}),a(u?`browser.handBack`:`browser.takeOver`)]})},n??0)}function $({children:e,end:t}){return(0,U.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`h3`,{className:`font-display font-semibold text-[1rem]`,children:e}),t]})}function rt({view:e,run:t,step:n,before:r,asked:i,onNote:o}){let s=e.shown.filter(e=>e.output),[c,l]=(0,H.useState)(s.length===1?s[0].step.id:null),u=(0,H.useRef)(null),d=[...r,...i.map((e,t)=>K(`review:${n.id}:asked:${t}`,e)),G(`review:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:n.title}),n.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.description}):null]}),{anchor:!0}),...s.map(({step:t,output:r})=>G(`review:${n.id}:${t.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.title}),(0,U.jsx)(L,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{l(t.id),u.current?.focus()}:void 0})]}),{wide:!0})),...e.lists.map(t=>G(`review:${n.id}:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.def.title}),t.def.check?(0,U.jsx)(T,{runId:e.id,list:t}):(0,U.jsx)(P,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&d.push(G(`review-error`,t.error,{tone:`error`}));let f=n.regenerate&&s.length>0;return d.push(X(`review:${n.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:t.busy,onClick:()=>void t.accept(n.id),children:[(0,U.jsx)(C,{className:`size-4`}),` `,a(`run.accept`)]}),f&&s.length>1?s.map(({step:e})=>(0,U.jsx)(Z,{on:c===e.id,onClick:()=>l(e.id),children:e.title},e.id)):null]}))),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:d}),f?(0,U.jsx)(Pe,{children:(0,U.jsx)(Le,{multiline:!0,inputRef:u,busy:t.busy,placeholder:s.length>1&&!c?a(`run.feedbackPick`):a(`run.feedbackPlaceholder`),disabled:!c,onSend:e=>{let r=e.trim();return!r||!c?!1:(o(r),t.regenerate(n.id,c,r),!0)}})}):(0,U.jsx)(Q,{})]})}function it({view:e,run:t,step:n,before:r,onRestart:i}){let o=e.shown.filter(e=>e.output),s=`/api/runs/${e.id}`,c=[...r,G(`result:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem]`,children:n.title}),n.message?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.message}):null]}),{anchor:!0}),...o.map(({step:e,output:t,formats:n,label:r})=>G(`result:${e.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(I,{base:s,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,U.jsx)(L,{base:s,step:e,output:t}),t?.assets?.some(e=>e.ai)?(0,U.jsx)(`p`,{className:`mt-3 text-[0.75rem] text-ink-3 leading-relaxed`,children:a(`ai.publish`)}):null]}),{wide:!0})),...e.lists.map(t=>G(`result:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(E,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,U.jsx)(P,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return c.push(X(`result:replies`,(0,U.jsxs)(U.Fragment,{children:[o.length?(0,U.jsx)(de,{runId:e.id,title:`${n.title} · ${e.wizard.title}`,initial:e.shareUrl?{url:e.shareUrl,expiresAt:e.expiresAt}:null}):null,i?(0,U.jsxs)(Z,{onClick:i,children:[(0,U.jsx)(S,{className:`size-4`}),` `,a(`run.again`)]}):null,e.canBack?(0,U.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:a(`run.back`)}):null,e.keeps?(0,U.jsx)(`span`,{className:`ml-1`,children:(0,U.jsx)(A,{runId:e.id})}):null]}))),(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:c})}function at({runId:e,onRestart:t,onView:n,header:r,footer:i,talk:o=!1,call:s=!1}){let c=pe(e),{view:l}=c,[u,d]=(0,H.useState)(null),f=je(e,l,c,u);(0,H.useEffect)(()=>{n?.(l)},[l,n]);let[m,h]=fe(),g=(0,H.useMemo)(()=>({runId:e,lang:l?.lang??p,readAloud:m,setReadAloud:h,voice:l?.talk?f:null,talk:o,call:!!s,bindPage:d}),[e,l?.lang,l?.talk,m,h,f,o,s]);re(l?.status===`running`&&!l.ask),N(l);let[_,b]=(0,H.useState)({}),[x,C]=(0,H.useState)(null);(0,H.useEffect)(()=>{l&&l.status!==`running`&&C(null)},[l]);let T;if(c.notFound)T=(0,U.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:a(`run.notFound`)});else if(!l)T=(0,U.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,U.jsx)(y,{})});else{let e=l.step,n=l.status===`waiting_input`,r=qe(l,l.canBack&&n&&!c.busy?()=>void c.back():void 0);if(l.status===`running`&&l.ask)T=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,U.jsx)(w,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,U.jsx)(Q,{})]});else if(l.status===`running`)T=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...x?[K(`note`,x)]:[],G(`working:${e?.id}`,(0,U.jsx)(Qe,{view:l}),{wide:l.events.some(t=>t.stepId===e?.id&&et(t))?`most`:void 0})]}),(0,U.jsx)(Q,{placeholder:a(`run.working`)})]});else if(l.status===`failed`)T=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`failed`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:a(`run.failed`)}),l.error?(0,U.jsx)(`span`,{className:`mt-0.5 block`,children:(0,U.jsx)(v,{text:l.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:c.busy,onClick:()=>void c.retry(),children:[(0,U.jsx)(S,{className:`size-4`}),` `,a(`run.retry`)]}),l.canBack?(0,U.jsx)(Z,{onClick:()=>void c.back(),disabled:c.busy,children:a(`run.back`)}):null]}))]}),(0,U.jsx)(Q,{})]});else if(l.status===`cancelled`)T=(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,a(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,U.jsxs)(Z,{primary:!0,onClick:t,children:[(0,U.jsx)(S,{className:`size-4`}),` `,a(`run.again`)]}))]:[]]});else if(e?.type===`page`)T=(0,U.jsx)(Ye,{view:l,run:c,step:e,before:r},e.id);else if(e?.type===`review`){let t=l.shown.map(e=>e.output?.at??``).join(`|`);T=(0,U.jsx)(rt,{view:l,run:c,step:e,before:r,asked:_[e.id]??[],onNote:t=>{C(t),b(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else T=e?.type===`result`?(0,U.jsx)(it,{view:l,run:c,step:e,before:r,onRestart:t}):(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:r})}return s?(0,U.jsx)(q.Provider,{value:g,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,U.jsx)(Te,{voice:f,view:l,video:s===`video`,className:`h-[46dvh] shrink-0 lg:h-auto lg:min-h-0 lg:flex-1`}),(0,U.jsx)(`aside`,{className:`flex min-h-0 flex-1 flex-col border-border-soft border-t lg:w-[420px] lg:flex-none lg:border-t-0 lg:border-l`,children:(0,U.jsx)(Fe,{footer:i,children:T})})]})}):(0,U.jsx)(q.Provider,{value:g,children:(0,U.jsx)(Fe,{header:r,footer:i,children:T})})}export{J as a,Z as i,Fe as n,X as o,Q as r,Ne as s,at as t};