wizards 0.6.2 → 0.7.0

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 (86) hide show
  1. package/README.md +6 -2
  2. package/apps/runtime/dist/agents/architect.js +7 -29
  3. package/apps/runtime/dist/agents/studio-assistant.js +7 -24
  4. package/apps/runtime/dist/cli/autostart.js +58 -12
  5. package/apps/runtime/dist/cli/autoupdate.js +221 -0
  6. package/apps/runtime/dist/cli/environment.js +5 -0
  7. package/apps/runtime/dist/cli/main.js +9 -2
  8. package/apps/runtime/dist/cli/menu.js +2 -2
  9. package/apps/runtime/dist/cli/processes.js +72 -0
  10. package/apps/runtime/dist/cli/setup.js +9 -4
  11. package/apps/runtime/dist/cli/start.js +18 -1
  12. package/apps/runtime/dist/cli/status.js +51 -17
  13. package/apps/runtime/dist/cli/uninstall-main.js +20 -0
  14. package/apps/runtime/dist/cli/uninstall.js +231 -0
  15. package/apps/runtime/dist/cli/update.js +25 -2
  16. package/apps/runtime/dist/cli/versions.js +106 -0
  17. package/apps/runtime/dist/docs/user/command-line.md +2 -1
  18. package/apps/runtime/dist/docs/user/data.md +1 -1
  19. package/apps/runtime/dist/docs/user/install.md +29 -6
  20. package/apps/runtime/dist/engine/input.js +4 -5
  21. package/apps/runtime/dist/engine/steps.js +3 -3
  22. package/apps/runtime/dist/engine/template.js +8 -13
  23. package/apps/runtime/dist/env.js +3 -20
  24. package/apps/runtime/dist/features.js +2 -2
  25. package/apps/runtime/dist/index.js +3 -1
  26. package/apps/runtime/dist/manage.js +7 -0
  27. package/apps/runtime/dist/models.js +12 -0
  28. package/apps/runtime/dist/sandbox/docker.js +0 -2
  29. package/apps/runtime/dist/sandbox/index.js +3 -10
  30. package/apps/runtime/dist/services/space-categories.js +3 -25
  31. package/apps/runtime/dist/tools/browser.js +2 -14
  32. package/apps/runtime/dist/tools/index.js +1 -19
  33. package/apps/runtime/dist/tools/mail.js +1 -4
  34. package/apps/runtime/dist/tools/shared.js +30 -3
  35. package/apps/runtime/dist/update.js +10 -19
  36. package/apps/web/dist/assets/AboutDialog-CUVmdhzk.js +1 -0
  37. package/apps/web/dist/assets/{ChangelogDialog-BRiSYyIn.js → ChangelogDialog-DcQqFbiW.js} +1 -1
  38. package/apps/web/dist/assets/ChatView-DTPWjzWF.js +10 -0
  39. package/apps/web/dist/assets/EditorPage-SJHtft7P.js +3 -0
  40. package/apps/web/dist/assets/{FlowPreview-CUOEzoeJ.js → FlowPreview-DvpjuQdC.js} +1 -1
  41. package/apps/web/dist/assets/{Harness-D3kTVsF5.js → Harness-D6fezoWO.js} +2 -2
  42. package/apps/web/dist/assets/{NewWizardChannels-C3PGe_Zd.js → NewWizardChannels-BHeutZ7V.js} +1 -1
  43. package/apps/web/dist/assets/NewWizardPage-CzBxaPhH.js +7 -0
  44. package/apps/web/dist/assets/{OnboardingPage-pOPB5TVZ.js → OnboardingPage-DbR4N2Ms.js} +1 -1
  45. package/apps/web/dist/assets/ProjectPage-DG6_E7kA.js +1 -0
  46. package/apps/web/dist/assets/PublicRunner-19tV_8TR.js +1 -0
  47. package/apps/web/dist/assets/{ReadOnly-CCxZvYrT.js → ReadOnly-BMXFtKs0.js} +1 -1
  48. package/apps/web/dist/assets/RunDrawer-DqwLjFJb.js +4 -0
  49. package/apps/web/dist/assets/{RunnerView-pKik3sdE.js → RunnerView-DRc4J-rg.js} +1 -1
  50. package/apps/web/dist/assets/SettingsPage-CCypPS9L.js +1 -0
  51. package/apps/web/dist/assets/SetupPage-D2Y2rev4.js +1 -0
  52. package/apps/web/dist/assets/{SharePage-CZQqp5JM.js → SharePage-DB5n6Oug.js} +1 -1
  53. package/apps/web/dist/assets/changelog-BDhd7tjO.js +1 -0
  54. package/apps/web/dist/assets/{esm-D4pSRQgT.js → esm-6TNBQNCD.js} +1 -1
  55. package/apps/web/dist/assets/index-mBRI7ZQp.js +14 -0
  56. package/apps/web/dist/assets/{lock-DYnHCyRg.js → lock-HLZib0u9.js} +1 -1
  57. package/apps/web/dist/assets/{phone-DJawY1RF.js → phone-DsxbIcWi.js} +1 -1
  58. package/apps/web/dist/assets/settings-menu-BMMkIVP1.js +1 -0
  59. package/apps/web/dist/assets/ui-Brg2qM1A.js +137 -0
  60. package/apps/web/dist/assets/{upload-DL6NRa4h.js → upload-BaGy0ppG.js} +1 -1
  61. package/apps/web/dist/index.html +2 -2
  62. package/apps/web/dist/install.sh +29 -11
  63. package/apps/web/dist/mcp/flow.html +11 -11
  64. package/bin/wizards.mjs +17 -3
  65. package/node_modules/@engenty-wizards/shared/dist/definition.js +6 -17
  66. package/node_modules/@engenty-wizards/shared/dist/features.d.ts +6 -0
  67. package/node_modules/@engenty-wizards/shared/dist/features.js +12 -0
  68. package/node_modules/@engenty-wizards/shared/dist/numbers.d.ts +24 -0
  69. package/node_modules/@engenty-wizards/shared/dist/numbers.js +54 -0
  70. package/node_modules/@engenty-wizards/shared/dist/store.d.ts +7 -0
  71. package/node_modules/@engenty-wizards/shared/dist/store.js +28 -0
  72. package/package.json +1 -1
  73. package/apps/runtime/dist/sandbox/agentos.js +0 -191
  74. package/apps/web/dist/assets/AboutDialog-BrfbtjmR.js +0 -1
  75. package/apps/web/dist/assets/ChatView-_dYvuuUY.js +0 -10
  76. package/apps/web/dist/assets/EditorPage-CkRjTRMg.js +0 -3
  77. package/apps/web/dist/assets/NewWizardPage-B3ol4K43.js +0 -7
  78. package/apps/web/dist/assets/ProjectPage-Boyptzz_.js +0 -1
  79. package/apps/web/dist/assets/PublicRunner-DcETj9_E.js +0 -1
  80. package/apps/web/dist/assets/RunDrawer-hwruVTDG.js +0 -4
  81. package/apps/web/dist/assets/SettingsPage-BOe6NgFg.js +0 -1
  82. package/apps/web/dist/assets/SetupPage-81QxPnfE.js +0 -1
  83. package/apps/web/dist/assets/changelog-CtyrKHAc.js +0 -1
  84. package/apps/web/dist/assets/index-DnIvQFIg.js +0 -14
  85. package/apps/web/dist/assets/settings-menu-B_-_EAmK.js +0 -1
  86. package/apps/web/dist/assets/ui-rh8TaWvT.js +0 -137
package/bin/wizards.mjs CHANGED
@@ -24,7 +24,8 @@ const home = join(
24
24
  );
25
25
  const runtime = join(home, "runtime");
26
26
  const wrapper = join(home, "bin", "wizards");
27
- const RUN_HERE = ["help", "validate", "mcp"];
27
+ // uninstall: never installs or hands over first; the install it takes away may no longer run.
28
+ const RUN_HERE = ["help", "validate", "mcp", "uninstall"];
28
29
  const tilde = (path) =>
29
30
  path.startsWith(homedir() + sep) ? `~${path.slice(homedir().length)}` : path;
30
31
 
@@ -164,7 +165,7 @@ if (process.platform === "win32" && !checkout && !RUN_HERE.includes(command)) {
164
165
  process.exit(1);
165
166
  }
166
167
  const fromNpm = process.platform !== "win32" && !checkout && !isInstall();
167
- if (fromNpm && (!currentNode || !RUN_HERE.includes(command))) {
168
+ if (fromNpm && command !== "uninstall" && (!currentNode || !RUN_HERE.includes(command))) {
168
169
  const own = versionOf(root) || "0.0.0";
169
170
  const installed = existsSync(wrapper)
170
171
  ? versionOf(join(runtime, "node_modules", "wizards"))
@@ -194,6 +195,14 @@ if (fromNpm && (!currentNode || !RUN_HERE.includes(command))) {
194
195
  process.exit(await handOver());
195
196
  }
196
197
  }
198
+ if (!currentNode && command === "uninstall") {
199
+ // The install's own Node, if it is still there, runs this copy's uninstall.
200
+ const node = join(home, "tools", "node", "bin", "node");
201
+ const result = existsSync(node)
202
+ ? spawnSync(node, [fileURLToPath(import.meta.url), ...args], { stdio: "inherit" })
203
+ : null;
204
+ process.exit(result?.status ?? 1);
205
+ }
197
206
  if (!currentNode) {
198
207
  console.error(
199
208
  `engenty wizards needs Node.js 24.11 or newer. This is ${process.version}.\n` +
@@ -202,4 +211,9 @@ if (!currentNode) {
202
211
  );
203
212
  process.exit(1);
204
213
  }
205
- await import("../apps/runtime/dist/cli/main.js");
214
+ // The uninstall has an entry of its own: main.js makes the install and data folders as it loads.
215
+ await import(
216
+ command === "uninstall"
217
+ ? "../apps/runtime/dist/cli/uninstall-main.js"
218
+ : "../apps/runtime/dist/cli/main.js"
219
+ );
@@ -1,6 +1,7 @@
1
1
  // SPDX-License-Identifier: FSL-1.1-MIT OR MIT
2
2
  import { z } from "zod";
3
3
  import { tableColumnsSchema } from "./engenty/data-tables/index.js";
4
+ import { readNumber } from "./numbers.js";
4
5
  import { outputShapeSchema, shapeOfFields } from "./shape.js";
5
6
  import { CONNECTION_KINDS } from "./store.js";
6
7
  import { surfaceComponentsSchema, validateSurface } from "./surface.js";
@@ -1606,17 +1607,6 @@ function isEmptyValue(v) {
1606
1607
  export function conditionsOf(when) {
1607
1608
  return when === undefined ? [] : Array.isArray(when) ? when : [when];
1608
1609
  }
1609
- /** A typed number as a number: "89,90" from a German number pad counts as 89.9. */
1610
- function numberOf(v) {
1611
- if (typeof v === "number") {
1612
- return Number.isFinite(v) ? v : null;
1613
- }
1614
- if (typeof v !== "string" || !v.trim()) {
1615
- return null;
1616
- }
1617
- const n = Number(v.replace(/\s/g, "").replace(",", "."));
1618
- return Number.isFinite(n) ? n : null;
1619
- }
1620
1610
  export function conditionMatches(c, values) {
1621
1611
  const v = values[c.field];
1622
1612
  switch (c.op) {
@@ -1632,8 +1622,8 @@ export function conditionMatches(c, values) {
1632
1622
  return Array.isArray(c.value) && c.value.map(String).includes(String(v));
1633
1623
  case "gt":
1634
1624
  case "lt": {
1635
- const a = numberOf(v);
1636
- const b = numberOf(c.value);
1625
+ const a = readNumber(v);
1626
+ const b = readNumber(c.value);
1637
1627
  return a !== null && b !== null && (c.op === "gt" ? a > b : a < b);
1638
1628
  }
1639
1629
  case "contains":
@@ -1858,8 +1848,8 @@ export function itemsTotals(field, value, values) {
1858
1848
  let vatRate = field.vat?.rate ?? 0;
1859
1849
  if (field.vat?.field) {
1860
1850
  const raw = values[field.vat.field];
1861
- const parsed = Number.parseFloat(String(raw ?? "").replace(",", "."));
1862
- if (Number.isFinite(parsed)) {
1851
+ const parsed = readNumber(raw, { units: true });
1852
+ if (parsed !== null) {
1863
1853
  vatRate = parsed;
1864
1854
  }
1865
1855
  }
@@ -1875,8 +1865,7 @@ export function itemsTotals(field, value, values) {
1875
1865
  }
1876
1866
  /** A typed amount as a number: a phone's number pad in German gives "89,90". */
1877
1867
  function amountOf(v) {
1878
- const n = typeof v === "string" ? Number(v.replace(/\s/g, "").replace(",", ".")) : Number(v);
1879
- return Number.isFinite(n) ? n : 0;
1868
+ return readNumber(v) ?? 0;
1880
1869
  }
1881
1870
  function round2(n) {
1882
1871
  return Math.round(n * 100) / 100;
@@ -20,6 +20,12 @@ export interface FeatureDeclarationInput {
20
20
  }
21
21
  /** A plugin's declarations under its id: `contacts` + `leadScoring` → `contacts.leadScoring`. */
22
22
  export declare function declaredByPlugin(pluginId: string, features: Record<string, FeatureDeclarationInput | boolean> | undefined): Record<string, FeatureDeclaration>;
23
+ /**
24
+ * Whether a switch is on in resolved values: a switch they do not carry counts as declared – a
25
+ * core flag with its default (`ownKeys` on, `teamPlans` off), anything else off. Every read of a
26
+ * flag goes through this (`useFeature` in the studio), so a missing value means one thing.
27
+ */
28
+ export declare function featureOn(features: Features | null | undefined, name: string): boolean;
23
29
  /** The defaults of these declarations; without any, the core's. */
24
30
  export declare function defaultFeatures(declared?: Record<string, FeatureDeclaration>): Features;
25
31
  /**
@@ -25,6 +25,18 @@ export function declaredByPlugin(pluginId, features) {
25
25
  }
26
26
  return out;
27
27
  }
28
+ /**
29
+ * Whether a switch is on in resolved values: a switch they do not carry counts as declared – a
30
+ * core flag with its default (`ownKeys` on, `teamPlans` off), anything else off. Every read of a
31
+ * flag goes through this (`useFeature` in the studio), so a missing value means one thing.
32
+ */
33
+ export function featureOn(features, name) {
34
+ const value = features?.[name];
35
+ if (typeof value === "boolean") {
36
+ return value;
37
+ }
38
+ return Object.hasOwn(FEATURES, name) ? FEATURES[name].default : false;
39
+ }
28
40
  /** The defaults of these declarations; without any, the core's. */
29
41
  export function defaultFeatures(declared = FEATURES) {
30
42
  const out = {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Numbers as people write and read them: what a phone's number pad, a table cell or a document
3
+ * gives, and an amount or a file's size as a page shows it. The server, the studio and the runner read and
4
+ * show them the same way.
5
+ */
6
+ /**
7
+ * A number as a person types it: digits with at most one decimal mark, a point or a comma
8
+ * alike, as a phone's number pad gives it in either language (`1.5`, `1,5`, `89,90`). There are
9
+ * no thousands separators: `1.234` and `1,234` are 1.234, and anything with two marks
10
+ * (`1.234,50`, `1.234.567`) is no number, since only the writer's language could say which mark
11
+ * is which. Text that is not typed (a document, a website) is read by a model into numbers
12
+ * before it gets here. With `units`, what stands around the number is dropped (`38 h`,
13
+ * `19 %`); without, anything but the number makes it none. Null where there is no number.
14
+ */
15
+ export declare function readNumber(value: unknown, opts?: {
16
+ units?: boolean;
17
+ }): number | null;
18
+ /**
19
+ * A file's size for a list, in decimal units as the operating systems show them: `1 KB` for
20
+ * anything below a kilobyte but nothing (`0 KB`), `340 KB`, `2.4 MB`, `1.2 GB`.
21
+ */
22
+ export declare function formatBytes(bytes: number): string;
23
+ /** An amount in a currency, as the language writes it (`1.234,50 €`); an unknown currency code as `1234.50 XYZ`. */
24
+ export declare function formatMoney(amount: number, currency: string, locale: string): string;
@@ -0,0 +1,54 @@
1
+ // SPDX-License-Identifier: FSL-1.1-MIT OR MIT
2
+ /**
3
+ * Numbers as people write and read them: what a phone's number pad, a table cell or a document
4
+ * gives, and an amount or a file's size as a page shows it. The server, the studio and the runner read and
5
+ * show them the same way.
6
+ */
7
+ /**
8
+ * A number as a person types it: digits with at most one decimal mark, a point or a comma
9
+ * alike, as a phone's number pad gives it in either language (`1.5`, `1,5`, `89,90`). There are
10
+ * no thousands separators: `1.234` and `1,234` are 1.234, and anything with two marks
11
+ * (`1.234,50`, `1.234.567`) is no number, since only the writer's language could say which mark
12
+ * is which. Text that is not typed (a document, a website) is read by a model into numbers
13
+ * before it gets here. With `units`, what stands around the number is dropped (`38 h`,
14
+ * `19 %`); without, anything but the number makes it none. Null where there is no number.
15
+ */
16
+ export function readNumber(value, opts = {}) {
17
+ if (typeof value === "number") {
18
+ return Number.isFinite(value) ? value : null;
19
+ }
20
+ if (typeof value !== "string") {
21
+ return null;
22
+ }
23
+ const s = opts.units ? value.replace(/[^\d,.-]/g, "") : value.trim();
24
+ if (!/^-?(\d+([.,]\d*)?|[.,]\d+)$/.test(s)) {
25
+ return null;
26
+ }
27
+ const n = Number(s.replace(",", "."));
28
+ return Number.isFinite(n) ? n : null;
29
+ }
30
+ /**
31
+ * A file's size for a list, in decimal units as the operating systems show them: `1 KB` for
32
+ * anything below a kilobyte but nothing (`0 KB`), `340 KB`, `2.4 MB`, `1.2 GB`.
33
+ */
34
+ export function formatBytes(bytes) {
35
+ if (!(bytes > 0)) {
36
+ return "0 KB";
37
+ }
38
+ if (bytes < 999_500) {
39
+ return `${Math.max(1, Math.round(bytes / 1000))} KB`;
40
+ }
41
+ if (bytes < 999_950_000) {
42
+ return `${(bytes / 1_000_000).toFixed(1)} MB`;
43
+ }
44
+ return `${(bytes / 1_000_000_000).toFixed(1)} GB`;
45
+ }
46
+ /** An amount in a currency, as the language writes it (`1.234,50 €`); an unknown currency code as `1234.50 XYZ`. */
47
+ export function formatMoney(amount, currency, locale) {
48
+ try {
49
+ return new Intl.NumberFormat(locale, { style: "currency", currency }).format(amount);
50
+ }
51
+ catch {
52
+ return `${amount.toFixed(2)} ${currency}`;
53
+ }
54
+ }
@@ -108,3 +108,10 @@ export declare function rowKey(def: ListDef, cells: Record<string, unknown>): st
108
108
  export declare function newCells(def: ListDef, input: Record<string, unknown>): Record<string, unknown>;
109
109
  /** An existing row's cells with some columns changed; cells of columns the list no longer has are dropped. */
110
110
  export declare function patchCells(def: ListDef, current: Record<string, unknown>, patch: Record<string, unknown>): Record<string, unknown>;
111
+ /**
112
+ * What a person typed into a cell, as the value sent for its column; the runtime still checks it
113
+ * against the column. Blank is null; a number or a duration (in the column's input unit) is read
114
+ * as people write it ("12,5"); a date and time from the browser's picker, in local time, becomes
115
+ * ISO. What cannot be read goes as typed, for the runtime to refuse and name.
116
+ */
117
+ export declare function cellValue(column: TableColumn, text: string): unknown;
@@ -1,5 +1,6 @@
1
1
  // SPDX-License-Identifier: FSL-1.1-MIT OR MIT
2
2
  import { coerceRowValues, mergeRowValues } from "./engenty/data-tables/index.js";
3
+ import { readNumber } from "./numbers.js";
3
4
  export const STORE_LIMITS = {
4
5
  fileBytes: 15_000_000,
5
6
  totalBytes: 200_000_000,
@@ -51,3 +52,30 @@ export function patchCells(def, current, patch) {
51
52
  const kept = Object.fromEntries(Object.entries(current).filter(([id]) => known.has(id)));
52
53
  return mergeRowValues(def.columns, kept, patch);
53
54
  }
55
+ /**
56
+ * What a person typed into a cell, as the value sent for its column; the runtime still checks it
57
+ * against the column. Blank is null; a number or a duration (in the column's input unit) is read
58
+ * as people write it ("12,5"); a date and time from the browser's picker, in local time, becomes
59
+ * ISO. What cannot be read goes as typed, for the runtime to refuse and name.
60
+ */
61
+ export function cellValue(column, text) {
62
+ if (text.trim() === "") {
63
+ return null;
64
+ }
65
+ switch (column.type) {
66
+ case "number":
67
+ case "duration":
68
+ return readNumber(text) ?? text;
69
+ case "boolean":
70
+ return text === "true";
71
+ case "date": {
72
+ if (column.format.kind !== "datetime") {
73
+ return text;
74
+ }
75
+ const at = new Date(text);
76
+ return Number.isNaN(at.getTime()) ? text : at.toISOString();
77
+ }
78
+ default:
79
+ return text;
80
+ }
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wizards",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "Make a wish. Get your wizard. It guides you step by step. Let AI do the work. Runs on your machine, on the AI subscription you already have.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "homepage": "https://engenty.ai",
@@ -1,191 +0,0 @@
1
- import { posix } from "node:path";
2
- const WORKDIR = "/workspace";
3
- const EXEC_TIMEOUT_MS = 120_000;
4
- const INSTALL_TIMEOUT_MS = 300_000;
5
- /** The only hosts the VM reaches: where npm and Python packages come from. */
6
- const REGISTRIES = ["registry.npmjs.org", "pypi.org", "files.pythonhosted.org"];
7
- /** python at the start of a command, after an operator, or behind VAR=value assignments. */
8
- const PYTHON_IN_SHELL = /(?:^|[;&|(\n`]|\$\()\s*(?:\w+=\S*\s+)*python3?(?:\.\d+)?(?=\s|$)/;
9
- /**
10
- * What an agentOS VM runs: a WASM userland (a POSIX shell and coreutils, no native binaries),
11
- * Node in a V8 isolate and Python as Pyodide. Python started from the shell never returns, so
12
- * it is offered as its own tool; of the compiled wheels only numpy loads reliably.
13
- */
14
- export const AGENTOS_CAPABILITIES = {
15
- commands: [
16
- "sh",
17
- "ls",
18
- "cat",
19
- "head",
20
- "tail",
21
- "sort",
22
- "wc",
23
- "grep",
24
- "sed",
25
- "awk",
26
- "find",
27
- "diff",
28
- "tar",
29
- "gzip",
30
- "base64",
31
- "node",
32
- "npm",
33
- ],
34
- python: "tool",
35
- pythonPackages: "Python 3.13 standard library; `packages` installs numpy and pure-Python packages from PyPI such as openpyxl or pypdf — no pandas, pillow or matplotlib",
36
- network: "none, except the npm and PyPI registries",
37
- uses: "calculations or file conversion",
38
- workdir: WORKDIR,
39
- };
40
- let runtime = null;
41
- /** One native sidecar process hosts the VM of every run; the first sandbox starts it. */
42
- function agentOsRuntime() {
43
- runtime ??= (async () => {
44
- const [core, runtimeCore] = await Promise.all([
45
- import("@rivet-dev/agentos-core"),
46
- import("@rivet-dev/agentos-runtime-core"),
47
- ]).catch((err) => {
48
- throw new Error(`SANDBOX=agentos needs @rivet-dev/agentos-core in this build: ${err.message}`);
49
- });
50
- keepRuntimeCommands(runtimeCore.SidecarProcess);
51
- return { AgentOs: core.AgentOs, sidecar: await core.AgentOs.createSidecar() };
52
- })().catch((err) => {
53
- runtime = null;
54
- throw err;
55
- });
56
- return runtime;
57
- }
58
- const patched = new WeakSet();
59
- /**
60
- * agentOS registers `python` as a kernel command when it creates a VM and leaves it out when
61
- * it configures that VM; naming the runtime commands there again is what makes Python start.
62
- */
63
- function keepRuntimeCommands(SidecarProcess) {
64
- const proto = SidecarProcess.prototype;
65
- if (patched.has(proto)) {
66
- return;
67
- }
68
- patched.add(proto);
69
- const configureVm = proto.configureVm;
70
- proto.configureVm = function (session, vm, options) {
71
- const commands = [
72
- "node",
73
- "npm",
74
- "npx",
75
- "python",
76
- "python3",
77
- ...(options?.bootstrapCommands ?? []),
78
- ];
79
- return configureVm.call(this, session, vm, {
80
- ...options,
81
- bootstrapCommands: [...new Set(commands)],
82
- });
83
- };
84
- }
85
- /** Stops the sidecar process. The next sandbox starts a new one. */
86
- export async function stopAgentOs() {
87
- const current = runtime;
88
- runtime = null;
89
- await (await current?.catch(() => null))?.sidecar.dispose();
90
- }
91
- function toResult(result, python = false) {
92
- const stdout = result.stdout ?? "";
93
- let stderr = result.stderr ?? "";
94
- if (python) {
95
- // A Python traceback arrives with the interpreter's own JavaScript stack behind it.
96
- stderr = stderr.replace(/\n\s+at [\s\S]*$/, "\n");
97
- }
98
- if (result.outcome === "timed_out") {
99
- stderr = `${stderr}\ntimed out`.trim();
100
- }
101
- else if (result.outcome !== "succeeded" && !stdout && !stderr) {
102
- stderr = result.error.message;
103
- }
104
- return { exitCode: result.exitCode ?? (result.outcome === "succeeded" ? 0 : 1), stdout, stderr };
105
- }
106
- /** One agentOS VM per run, inside the server process's sidecar: no Docker, no container. */
107
- export class AgentOsSandbox {
108
- capabilities = AGENTOS_CAPABILITIES;
109
- machine = null;
110
- installed = new Set();
111
- vm() {
112
- this.machine ??= (async () => {
113
- const { AgentOs, sidecar } = await agentOsRuntime();
114
- return AgentOs.create({
115
- sidecar: { kind: "explicit", handle: sidecar },
116
- // Anything not listed is refused, the host's own loopback included.
117
- permissions: {
118
- fs: "allow",
119
- childProcess: "allow",
120
- process: "allow",
121
- env: "allow",
122
- network: {
123
- default: "deny",
124
- rules: [
125
- {
126
- mode: "allow",
127
- operations: ["*"],
128
- patterns: REGISTRIES.flatMap((host) => [`dns://${host}`, `tcp://${host}:443`]),
129
- },
130
- ],
131
- },
132
- },
133
- });
134
- })();
135
- return this.machine;
136
- }
137
- async exec(command, options = {}) {
138
- if (PYTHON_IN_SHELL.test(command)) {
139
- return {
140
- exitCode: 127,
141
- stdout: "",
142
- stderr: "python is not a shell command in this sandbox; run Python with run_python.",
143
- };
144
- }
145
- const vm = await this.vm();
146
- return toResult(await vm.process.exec(command, {
147
- cwd: options.cwd ?? WORKDIR,
148
- env: options.env,
149
- timeoutMs: options.timeoutMs ?? EXEC_TIMEOUT_MS,
150
- output: { capture: "all" },
151
- }));
152
- }
153
- async runPython(source, options = {}) {
154
- const vm = await this.vm();
155
- const missing = (options.packages ?? []).filter((name) => !this.installed.has(name));
156
- if (missing.length) {
157
- const install = toResult(await vm.python.install(missing, {
158
- timeoutMs: INSTALL_TIMEOUT_MS,
159
- output: { capture: "all" },
160
- }));
161
- // A wheel that is listed but not shipped "installs" and then fails to load.
162
- if (install.exitCode !== 0 || /Failed to load/.test(install.stdout)) {
163
- return { ...install, exitCode: install.exitCode || 1 };
164
- }
165
- for (const name of missing) {
166
- this.installed.add(name);
167
- }
168
- }
169
- return toResult(await vm.python.execute(source, {
170
- // Python starts in its HOME whatever cwd says, and only /workspace is shared with the shell.
171
- env: { ...options.env, HOME: WORKDIR },
172
- timeoutMs: options.timeoutMs ?? EXEC_TIMEOUT_MS,
173
- output: { capture: "all" },
174
- }), true);
175
- }
176
- async writeFile(path, data) {
177
- const vm = await this.vm();
178
- const target = posix.resolve(WORKDIR, path);
179
- await vm.filesystem.mkdir(posix.dirname(target), { recursive: true });
180
- await vm.filesystem.writeFile(target, data);
181
- }
182
- async readFile(path) {
183
- const vm = await this.vm();
184
- return vm.filesystem.readFile(posix.resolve(WORKDIR, path));
185
- }
186
- async destroy() {
187
- const machine = this.machine;
188
- this.machine = null;
189
- await (await machine?.catch(() => null))?.dispose();
190
- }
191
- }
@@ -1 +0,0 @@
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,Vt as l,Wt as u,hr as d,lr as f,zn as p}from"./ui-rh8TaWvT.js";import{t as m}from"./preload-helper-CNEI7N0N.js";import{G as h,U as g,W as _,bt as v}from"./index-DnIvQFIg.js";import{c as y,f as b}from"./settings-menu-B_-_EAmK.js";import{ReleaseNotes as x,loadReleases as S,releaseDate as C,releaseLabel as w}from"./ChangelogDialog-BRiSYyIn.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:`agentOS`,description:`credit.agentos`,homepage:`https://github.com/rivet-dev/agentos`,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)(f,{"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-BJrR7BR1.js`).then(e=>{r||n(e.default)}),[]),()=>{r=!0}},[e,t]),(0,T.useEffect)(()=>{e||o(``)},[e]);let s=i.trim().toLowerCase(),u=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=u(E),p=u(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)(l,{})}):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:f}=h(a&&e),[m,E]=(0,T.useState)(null),[D,k]=(0,T.useState)(`new`),A=b(F.indexOf(D)),j=c?.newer&&f?f:_;(0,T.useEffect)(()=>{if(!e)return;let t=!1;return E(null),S(j===`0.6.2`?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)(p,{className:`size-4`})})}),(0,O.jsxs)(`div`,{className:`flex flex-col items-center pt-4 text-center`,children:[(0,O.jsx)(v,{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:_}),R?` · ${r(`about.kind.${R}`)}`:``]})]}),a?(0,O.jsx)(`div`,{className:`mt-5`,children:(0,O.jsx)(g,{enabled:e})}):null,(0,O.jsx)(`div`,{className:`mt-6 flex justify-center`,children:(0,O.jsx)(u,{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)(l,{})}):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)(d,{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,10 +0,0 @@
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,$t as i,Bn as a,Fn as o,Ft as s,Gt as c,Hn as l,Ir as u,Jt as d,Kt as f,Rt as p,Tn as m,Tr as h,Un as g,Vt as _,W as v,Wn as y,Zn as b,bt as x,dt as S,er as C,ft as w,lt as T,mt as E,nn as D,nr as O,nt as k,p as A,pt as j,qn as M,qt as N,rt as P,st as F,tt as I,un as L,ut as ee,vr as R,vt as z,xr as te,xt as ne,yt as re}from"./ui-rh8TaWvT.js";import{t as ie}from"./phone-DJawY1RF.js";import{$ as ae,Pt as oe,Q as se,St as ce,Z as le,ht as ue,jt as de,t as fe}from"./index-DnIvQFIg.js";import{n as pe}from"./RunnerView-pKik3sdE.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=h(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=h(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 ye=h(ve),be={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`}]]};be.node;var xe=h(be),Se=u(),B=e(t(),1),V=e(n(),1),Ce=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function we({since:e}){let[t,n]=(0,B.useState)(Date.now());if((0,B.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,V.jsxs)(`span`,{className:`font-mono text-[0.8125rem] text-white/60 tabular-nums`,children:[i,`:`,a]})}function H({label:e,on:t,danger:n,busy:r,onClick:i,children:a}){return(0,V.jsx)(`button`,{type:`button`,"aria-label":e,title:e,"aria-pressed":t,disabled:r,onClick:i,className:f(`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,V.jsx)(_,{className:`size-5`}):a})}function Te({voice:e}){let t=(0,B.useRef)(null),{captions:n}=e;return(0,B.useEffect)(()=>{n.length&&t.current?.scrollIntoView({block:`end`})},[n]),n.length?(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 sm:px-5`,children:(0,V.jsxs)(`ol`,{className:`mx-auto flex max-w-[720px] flex-col gap-2 py-2`,children:[n.map(e=>(0,V.jsx)(`li`,{className:f(`text-[0.9375rem] leading-snug`,e.who===`bot`?`text-white/95`:`text-right text-white/50`),children:e.text},e.id)),(0,V.jsx)(`div`,{ref:t})]})}):null}function Ee({voice:e,view:t,video:n,className:r}){let o=e.state===`live`,s=e.state===`connecting`,[c,u]=(0,B.useState)(null),[d,p]=(0,B.useState)(!1);(0,B.useEffect)(()=>{u(o?Date.now():null)},[o]);let m=async()=>{p(!1),await e.start(),n&&await e.startCamera()},h=()=>{e.stop(),p(!0)},g=n||e.camera,v=[...e.captions].reverse().find(e=>e.who===`bot`),y=[...e.captions].reverse().find(e=>e.who===`me`),b=e.speaking?i(`talk.speaking`):e.listening?i(`talk.listening`):o?i(`talk.live`):s?i(`talk.connecting`):d?i(`video.ended`):``;return(0,V.jsxs)(`section`,{className:f(`relative flex min-h-0 flex-col bg-neutral-950 text-white`,`safe-top`,r),children:[(0,V.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4 sm:px-5`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1rem] tracking-tight`,children:t?.wizard.title??``}),b?(0,V.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[o?(0,V.jsx)(`span`,{className:f(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,b]}):null,(0,V.jsx)(we,{since:c})]}),(0,V.jsxs)(`div`,{className:f(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,g?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!g&&o&&e.captions.length?`h-[38%]`:g?``:`flex-1`),children:[(0,V.jsxs)(`div`,{className:f(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!g&&`hidden`),children:[(0,V.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:f(`absolute inset-0 h-full w-full object-cover`,e.facing===`user`&&`-scale-x-100`,e.camera?`block`:`hidden`)}),e.camera?null:(0,V.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/50`,children:[(0,V.jsx)(ye,{className:`size-8`}),(0,V.jsx)(`span`,{className:`text-[0.8125rem]`,children:i(`video.cameraOff`)})]}),(0,V.jsxs)(`span`,{className:`absolute bottom-2 left-3 rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:[i(`video.you`),e.muted?(0,V.jsx)(oe,{className:`ml-1.5 inline size-3`}):null]})]}),(0,V.jsxs)(`div`,{className:f(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,g?`bg-neutral-900`:`bg-transparent`,g&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,V.jsx)(`div`,{className:f(`rounded-full transition-shadow duration-500`,!g&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!g&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,V.jsx)(ue,{kind:t?.wizard.avatar??`round`,size:g?140:200,fluffy:!0,interactive:!1})}),g?(0,V.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]})]}),o&&!g?(0,V.jsx)(Te,{voice:e}):o&&(v||y)?(0,V.jsx)(`div`,{className:`shrink-0 px-4 pb-2 sm:px-5`,children:(0,V.jsxs)(`div`,{className:`mx-auto max-w-[720px] space-y-1 text-center`,children:[y?(0,V.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:y.text}):null,v?(0,V.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:v.text}):null]})}):null,e.error?(0,V.jsx)(`p`,{className:`shrink-0 px-5 pb-2 text-center text-[0.8125rem] text-rose`,children:e.error}):null,(0,V.jsx)(`div`,{className:`flex shrink-0 items-center justify-center gap-3 px-4 pt-1 pb-4`,children:o?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(H,{label:i(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,V.jsx)(oe,{className:`size-5`}):(0,V.jsx)(O,{className:`size-5`})}),(0,V.jsx)(H,{label:i(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,V.jsx)(a,{className:`size-5`}):(0,V.jsx)(ye,{className:`size-5`})}),e.camera&&Ce?(0,V.jsx)(H,{label:i(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,V.jsx)(l,{className:`size-5`})}):null,(0,V.jsx)(H,{label:i(`video.leave`),danger:!0,onClick:h,children:(0,V.jsx)(de,{className:`size-5`})})]}):(0,V.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,V.jsxs)(`button`,{type:`button`,disabled:s||!t?.talk,onClick:()=>void m(),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:[s?(0,V.jsx)(_,{className:`size-4`}):n?(0,V.jsx)(a,{className:`size-5`}):(0,V.jsx)(O,{className:`size-5`}),i(d?`video.rejoin`:n?`video.join`:`talk.start`)]}),!d&&!e.error?(0,V.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:i(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var De=e=>L[e.kind]!==`device`,Oe=1024,ke=4e3;function U(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function W(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: ${N(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}: ${U(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=De(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?` = ${U(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}": ${U(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 Ae(e,t,n,r){let[a,o]=(0,B.useState)(`off`),[s,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(!1),[h,g]=(0,B.useState)(`environment`),[_,y]=(0,B.useState)(!1),[b,x]=(0,B.useState)([]),S=(0,B.useRef)(null),C=(0,B.useRef)(null),w=(0,B.useRef)(0),T=(0,B.useRef)(!1);T.current=p;let E=(0,B.useRef)(null),D=(0,B.useRef)(null),O=(0,B.useRef)(null),k=(0,B.useRef)(null),A=(0,B.useRef)(t);A.current=t;let j=(0,B.useRef)(r);j.current=r;let M=(0,B.useRef)(n);M.current=n;let N=(0,B.useRef)(``),P=(0,B.useCallback)(e=>{let t=D.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,B.useCallback)(()=>{let e=S.current;if(!T.current||!e||e.videoWidth===0)return null;let t=Math.min(1,Oe/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,B.useCallback)(()=>{for(let e of C.current?.getTracks()??[])e.stop();C.current=null,S.current&&(S.current.srcObject=null),m(!1)},[]),L=(0,B.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`?i(`talk.cameraDenied`):e.message)}},[]),ee=(0,B.useCallback)(async()=>{let e=h===`user`?`environment`:`user`;I(),await L(e)},[h,I,L]),R=(0,B.useCallback)(()=>{y(e=>{for(let t of k.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),z=(0,B.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),y(!1),o(`off`)},[I]);(0,B.useEffect)(()=>()=>z(),[z]);let te=(0,B.useCallback)(async(t,n)=>{let r=A.current,i=j.current,a=M.current;switch(t){case`get_state`:return r?W(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 v.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&&De(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 v.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]),ne=(0,B.useCallback)(async()=>{if(!E.current){c(null),x([]),o(`connecting`);try{let t=await v.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 a=document.createElement(`audio`);a.autoplay=!0,a.setAttribute(`playsinline`,``),document.body.append(a),O.current=a,r.ontrack=e=>{a.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>ke?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{}te(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=W(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(`${i(`talk.failed`)} (${d.status})`);await r.setRemoteDescription({type:`answer`,sdp:await d.text()})}catch(e){z(),c(e.name===`NotAllowedError`?i(`chat.micDenied`):e.message),o(`error`)}}},[e,te,F,P,z]);return(0,B.useEffect)(()=>{if(a!==`live`||!t)return;let e=W(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`})},[a,t,r,p,P]),{state:a,error:s,speaking:l,listening:d,start:ne,stop:z,camera:p,facing:h,startCamera:L,stopCamera:I,flipCamera:ee,muted:_,toggleMute:R,captions:b,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}),je=(0,B.createContext)(null),q=(0,B.createContext)(null);function Me(){return(0,B.useContext)(q)?.voice??null}function Ne({children:e}){let t=(0,B.useContext)(je);return t?(0,Se.createPortal)(e,t):null}function Pe({header:e,footer:t,children:n}){let[r,i]=(0,B.useState)(null),a=(0,B.useRef)(null),o=(0,B.useRef)(null),s=(0,B.useRef)(!0);return(0,B.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,V.jsx)(je.Provider,{value:r,children:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[e,(0,V.jsx)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,V.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,V.jsxs)(`div`,{className:`shrink-0 border-border-soft border-t bg-background`,onPointerDownCapture:()=>{s.current=!0},onKeyDownCapture:()=>{s.current=!0},children:[(0,V.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,B.useContext)(q),r=(0,B.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),a=(0,B.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);ae(!!n?.readAloud,n?.lang??d,r,a);let o=[];for(let e of t){let t=o.at(-1);t&&t.who===`bot`&&e.who===`bot`?t.lines.push(e):o.push({who:e.who,lines:[e]})}return o.map((t,n)=>t.who===`bot`?(0,V.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,V.jsx)(`div`,{className:`sticky top-1 shrink-0 pt-0.5`,children:(0,V.jsx)(ue,{kind:e,size:30,interactive:n>=o.length-2})}),(0,V.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:t.lines.map(e=>(0,V.jsx)(`div`,{"data-anchor":e.anchor?``:void 0,"data-say":e.key,className:f(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?f(`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,V.jsxs)(`div`,{className:`flex animate-rise flex-col items-end gap-1 pl-10`,children:[(0,V.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,V.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,V.jsx)(b,{className:`size-3`}),` `,i(`chat.change`)]}):null]},e.key)))}function Fe(){return(0,V.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":i(`run.working`),children:[0,1,2].map(e=>(0,V.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,V.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}var X=(e,t)=>G(e,(0,V.jsx)(Y,{children:t}),{bare:!0});function Z({onClick:e,children:t,primary:n,on:r,disabled:i,busy:a}){return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":r,disabled:i||a,onClick:e,className:f(`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,V.jsx)(_,{className:`size-4`}):null,t]})}function Ie({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:o,disabled:l,inputRef:u,onSend:d}){let[p,m]=(0,B.useState)(e),h=(0,B.useRef)(null),v=u??h,y=(0,B.useContext)(q),b=A(p,m,{endpoint:y?`/api/runs/${y.runId}/transcribe`:void 0}),x=!!y&&b.supported&&!l;(0,B.useEffect)(()=>{if(!x)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),b.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x,b.toggle]),(0,B.useEffect)(()=>{!z&&!l&&v.current?.focus()},[l,v]);let S=()=>{o||l||(b.listening&&b.toggle(),d(p)!==!1&&m(``))},C=b.listening?i(`chat.listening`):b.processing?i(`chat.transcribing`):t,w=y?.voice??null,T=!!y?.call,E=y&&!T&&(le||x||w)?(0,V.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[w?(0,V.jsx)(s,{label:i(w.state===`live`?`talk.stop`:w.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":w.state===`live`,disabled:w.state===`connecting`,onClick:()=>w.state===`live`?w.stop():void w.start(),className:f(`size-9`,w.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,w.state===`off`&&y.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:w.state===`connecting`?(0,V.jsx)(_,{className:`size-4`}):w.state===`live`?(0,V.jsx)(de,{className:`size-4`}):(0,V.jsx)(ie,{className:`size-4`})}):null,w?.state===`live`?(0,V.jsx)(s,{label:i(w.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":w.camera,onClick:()=>w.camera?w.stopCamera():void w.startCamera(),className:f(`size-9`,w.camera&&`text-ink`),children:w.camera?(0,V.jsx)(a,{className:`size-4`}):(0,V.jsx)(ye,{className:`size-4`})}):null,le?(0,V.jsx)(s,{label:i(y.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":y.readAloud,onClick:()=>y.setReadAloud(!y.readAloud),className:f(`size-9`,y.readAloud&&`text-ink`),children:y.readAloud?(0,V.jsx)(ce,{className:`size-4`}):(0,V.jsx)(xe,{className:`size-4`})}):null,x?(0,V.jsx)(s,{label:i(b.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":b.listening,disabled:b.processing,onClick:b.toggle,className:f(`size-9`,b.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:b.processing?(0,V.jsx)(_,{className:`size-4`}):b.listening?(0,V.jsx)(g,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,V.jsx)(O,{className:`size-4`})}):null]}):null;return(0,V.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),S()},children:[w&&!T?(0,V.jsx)(`video`,{ref:w.video,muted:!0,playsInline:!0,autoPlay:!0,className:f(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,w.camera?`block`:`hidden`)}):null,(0,V.jsxs)(`div`,{className:f(`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`,l&&`opacity-60`),children:[E,n?(0,V.jsx)(c,{ref:v,minRows:1,maxRows:6,value:p,disabled:l,placeholder:C,autoCapitalize:`sentences`,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!z&&!e.nativeEvent.isComposing&&(e.preventDefault(),S())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,V.jsx)(`input`,{ref:v,...r,value:p,disabled:l,placeholder:C,enterKeyHint:`send`,onChange:e=>m(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,V.jsx)(`button`,{type:`submit`,"aria-label":i(`chat.send`),title:i(`chat.send`),disabled:o||l,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:o?(0,V.jsx)(_,{className:`size-4`}):(0,V.jsx)(te,{className:`size-4`})})]}),b.error?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:b.error===`denied`?i(`chat.micDenied`):b.error}):T?null:w?.error?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:w.error}):w?.state===`live`?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:w.speaking?i(`talk.speaking`):w.listening?i(`talk.listening`):i(`talk.live`)}):y?.talk&&w?.state===`off`?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:i(`talk.hint`)}):null]})}function Q({placeholder:e=i(`chat.above`)}){return(0,V.jsx)(Ne,{children:(0,V.jsx)(Ie,{disabled:!0,placeholder:e,onSend:()=>!1})})}function Le(e){let t=L[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Re=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function ze(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Re(t))return e.required&&!n?i(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return i(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return i(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?i(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?i(`run.filesMin`,{n:t.length,min:e.min}):null}function Be(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 Ve({field:e}){return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e.label}),e.help?(0,V.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.help}):null]})}function He({step:e,only:t}){return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e.title}),e.description?(0,V.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:e.description}):null,t?.help?(0,V.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:t.help}):null]})}function Ue({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,V.jsx)(V.Fragment,{children:typeof t==`string`&&t?t:i(`chat.connected`)});if(e.kind===`list`)return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(R,{className:`size-4`}),` `,i(`chat.checked`)]});if(e.kind===`toggle`)return(0,V.jsx)(V.Fragment,{children:i(t===!0?`run.yes`:`run.no`)});if(Re(t))return(0,V.jsx)(`span`,{className:`italic opacity-80`,children:i(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,V.jsx)(V.Fragment,{children:t.map(D).join(`, `)});case`select`:return(0,V.jsx)(V.Fragment,{children:D(String(t))});case`date`:{let e=new Date(`${String(t)}T00:00`);return(0,V.jsx)(V.Fragment,{children:Number.isNaN(e.getTime())?String(t):new Intl.DateTimeFormat(d,{dateStyle:`long`}).format(e)})}case`color`:return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`size-4 rounded-full ring-1 ring-white/50`,style:{background:String(t)}}),String(t)]});case`image`:case`signature`:return(0,V.jsx)(`span`,{className:`-mx-1.5 flex flex-wrap gap-1.5`,children:(Array.isArray(t)?t:[String(t)]).map(t=>(0,V.jsx)(`img`,{src:r(`/api/runs/${n}/assets/${t}`),alt:``,className:f(`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,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(C,{className:`size-4`}),` `,i(e===1?`chat.file`:`chat.files`,{n:e})]})}case`audio`:{let e=t.seconds;return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(O,{className:`size-4`}),` `,i(`chat.voice`),e?` · ${Math.round(e)} s`:``]})}case`location`:{let e=t;return(0,V.jsx)(V.Fragment,{children:e.label||`${e.lat?.toFixed(5)}, ${e.lng?.toFixed(5)}`})}case`items`:return(0,V.jsx)(V.Fragment,{children:i(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,V.jsx)(V.Fragment,{children:String(t)})}}function We(e,t,n,r,i,a){let o=[G(t,(0,V.jsx)(He,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,V.jsx)(Ve,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,V.jsx)(Ue,{field:e,value:n[e.id],runId:r})));return o}var Ge=(e,t)=>e.fields.filter(e=>!e.when&&!m(e)||t[e.id]!==void 0&&t[e.id]!==null);function Ke(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 a=`${t}:${r.id}`;if(r.type===`page`){let t=r.fields.length===1?r.fields[0]:void 0;n.push(...We(r,a,e.values,e.id,Ge(r,e.values),t))}else r.type===`review`&&(n.push(G(a,(0,V.jsx)(`span`,{className:`font-medium`,children:r.title}))),n.push(K(`${a}:a`,i(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function qe(e,t){return e.fields.filter(e=>!m(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function Je({view:e,run:t,step:n,before:r}){let a=(0,B.useMemo)(()=>qe(n,e),[n,e]),s=e.known??{},[c,l]=(0,B.useState)(()=>I(n,e)),[u,d]=(0,B.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?o(qe(n,e),e.known??{},I(n,e)).slice(0,-1).map(e=>e.id):[]),[f,p]=(0,B.useState)({}),[m,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)(!1),v=o(a,s,c),y=v.filter(e=>u.includes(e.id)),b=v.find(e=>!u.includes(e.id)),x=a.length===1?a[0]:void 0,S=y.at(-1),C=S?()=>d(e=>e.filter(e=>e!==S.id)):void 0;(0,B.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=o(a,s,c),r=n.findIndex(t=>e.includes(t.id));r>=0&&(d(n.slice(0,r).map(e=>e.id)),p(t.fieldErrors))},[t.fieldErrors]);let w=e=>{t.submitPage(n.id,e).then(_)},E=(0,B.useContext)(q),D=(0,B.useRef)(c);D.current=c;let O=E?.bindPage,k=(0,B.useRef)(w);k.current=w,(0,B.useEffect)(()=>{if(!O)return;let e=o(a,s,c);return O({step:n,fields:e,values:c,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?ze(r,n)||(l(e=>({...e,[t]:n})),d(e=>e.includes(t)?e:[...e,t]),p({}),null):`no such field on this page`},submit:()=>k.current(D.current)}),()=>O(null)},[O,n,a,s,c]);let A=e=>{if(!b)return!1;let t=ze(b,e);if(t)return p({[b.id]:t}),!1;let n={...c,[b.id]:e},r=[...u,b.id];return l(n),d(r),p({}),o(a,s,n).some(e=>!r.includes(e.id))||w(n),!0},j=[...r.map(e=>u.length?{...e,onEdit:void 0}:e),...We(n,`now:${n.id}`,c,e.id,y,x).map((e,t,n)=>t===n.length-1&&e.who===`me`&&b?{...e,onEdit:C}:e)];b?(Le(b)===`control`?j.push(G(`now:${n.id}:${b.id}:control`,(0,V.jsx)(T,{field:b,value:c[b.id],values:c,runId:e.id,view:e,closed:e.closed?.[b.id],onChange:e=>l(t=>({...t,[b.id]:e})),onBusy:h}),{wide:!0})):x||j.push(G(`now:${n.id}:${b.id}`,(0,V.jsx)(Ve,{field:b}))),f[b.id]&&j.push(G(`now:${n.id}:${b.id}:error`,f[b.id],{tone:`error`}))):t.busy||g?j.push(G(`sending`,(0,V.jsx)(Fe,{}))):t.error&&j.push(G(`send-error`,t.error,{tone:`error`}));let M=(0,V.jsx)(Q,{});if(g||!b&&u.length>0&&t.busy)M=(0,V.jsx)(Q,{placeholder:i(`run.working`)});else if(!b)j.push(X(`now:${n.id}:go`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>w(c),children:n.cta||i(`run.next`)}),C?(0,V.jsx)(Z,{onClick:C,disabled:t.busy,children:i(`run.back`)}):null]})));else{let r=Le(b),a=!b.required&&b.kind!==`connection`&&b.kind!==`list`?(0,V.jsx)(Z,{onClick:()=>A(void 0),children:i(`chat.skip`)}):null;if(r===`typed`){a&&j.push(X(`now:${n.id}:${b.id}:replies`,a));let e=c[b.id];M=(0,V.jsx)(Ne,{children:(0,V.jsx)(Ie,{initial:Re(e)?``:String(e),multiline:b.kind===`textarea`,placeholder:b.placeholder||(x?b.label:i(`chat.placeholder`)),inputProps:Ye(b),busy:t.busy,onSend:e=>A(Be(b,e))},b.id)})}else if(r===`tapped`)j.push(G(`now:${n.id}:${b.id}:replies`,(0,V.jsx)(Xe,{field:b,view:e,value:c[b.id],onAnswer:A}),{bare:!0}));else{let e=v.filter(e=>!u.includes(e.id)).length===1;j.push(X(`now:${n.id}:${b.id}:replies`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,disabled:m,onClick:()=>A(c[b.id]),children:e&&n.cta?n.cta:i(`chat.send`)}),a]})))}}return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:j}),M]})}function Ye(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 ee(e)}}function Xe({field:e,view:t,value:n,onAnswer:r}){let a=new Set(t.closed?.[e.id]?.values.map(String)),[o,s]=(0,B.useState)(Array.isArray(n)?n:[]);if(e.kind===`toggle`)return(0,V.jsxs)(Y,{children:[(0,V.jsx)(Z,{on:n===!1,disabled:a.has(`false`),onClick:()=>r(!1),children:i(`run.no`)}),(0,V.jsx)(Z,{on:n===!0,disabled:a.has(`true`),onClick:()=>r(!0),children:i(`run.yes`)})]});let c=e.options??[];return e.kind===`multiselect`?(0,V.jsxs)(Y,{children:[c.map(e=>(0,V.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:D(e)},e)),(0,V.jsx)(Z,{primary:!0,disabled:e.required&&!o.length,onClick:()=>r(o),children:o.length||e.required?i(`chat.send`):i(`chat.skip`)})]}):(0,V.jsxs)(Y,{children:[c.map(e=>(0,V.jsx)(Z,{on:n===e,disabled:a.has(e),onClick:()=>r(e),children:D(e)},e)),e.required?null:(0,V.jsx)(Z,{onClick:()=>r(void 0),children:i(`chat.skip`)})]})}function Ze({view:e}){let t=(0,B.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(),[a,o]=(0,B.useState)(Date.now());(0,B.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($e),u=[...new Set(s.map(e=>e.asset).filter(e=>!!e))];return(0,V.jsxs)(`div`,{className:f(`flex max-w-full flex-col gap-1`,l?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??i(`run.working`),children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(Fe,{}),(0,V.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??i(`run.working`)}),(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:i(`run.elapsed`,{s:Math.max(0,Math.round((a-n)/1e3))})})]}),c&&c!==l?(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(y,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,V.jsx)(`span`,{className:`truncate`,children:N(c)})]}):null,l&&e.status===`running`?(0,V.jsx)(tt,{runId:e.id,event:l}):null,u.length?(0,V.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:u.slice(-6).map(t=>(0,V.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 Qe=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function $e(e){return!!e.note&&Qe.has(e.note.code)}var et=1e4;function tt({runId:e,event:t}){let[n,r]=(0,B.useState)(null),[a,o]=(0,B.useState)(`agent`),[s,c]=(0,B.useState)(!1),l=t.note?.code;if((0,B.useEffect)(()=>{l===`personDrives`?o(`person`):l===`agentDrives`&&o(`agent`)},[l]),(0,B.useEffect)(()=>{let t=()=>v.get(`/api/runs/${e}/browser/seat`).then(e=>o(e.seat)).catch(()=>void 0);if(t(),a!==`person`)return;let n=setInterval(t,et);return()=>clearInterval(n)},[e,a]),n!==null&&n>=t.id)return null;let u=a===`person`,d=async()=>{c(!0);try{let t=await v.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});o(t.seat)}catch{}finally{c(!1)}};return(0,V.jsx)(ne,{runId:e,driving:u,caption:N(t),hint:i(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,V.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void d(),className:f(`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,V.jsx)(_e,{className:`size-3.5`}):(0,V.jsx)(he,{className:`size-3.5`}),i(u?`browser.handBack`:`browser.takeOver`)]})},n??0)}function $({children:e,end:t}){return(0,V.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,V.jsx)(`h3`,{className:`font-display font-semibold text-[1rem]`,children:e}),t]})}function nt({view:e,run:t,step:n,before:r,asked:a,onNote:o}){let s=e.shown.filter(e=>e.output),[c,l]=(0,B.useState)(s.length===1?s[0].step.id:null),u=(0,B.useRef)(null),d=[...r,...a.map((e,t)=>K(`review:${n.id}:asked:${t}`,e)),G(`review:${n.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:n.title}),n.description?(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{children:t.title}),(0,V.jsx)(F,{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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{children:t.def.title}),t.def.check?(0,V.jsx)(S,{runId:e.id,list:t}):(0,V.jsx)(j,{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,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(Z,{primary:!0,busy:t.busy,onClick:()=>void t.accept(n.id),children:[(0,V.jsx)(R,{className:`size-4`}),` `,i(`run.accept`)]}),f&&s.length>1?s.map(({step:e})=>(0,V.jsx)(Z,{on:c===e.id,onClick:()=>l(e.id),children:e.title},e.id)):null]}))),(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:d}),f?(0,V.jsx)(Ne,{children:(0,V.jsx)(Ie,{multiline:!0,inputRef:u,busy:t.busy,placeholder:s.length>1&&!c?i(`run.feedbackPick`):i(`run.feedbackPlaceholder`),disabled:!c,onSend:e=>{let r=e.trim();return!r||!c?!1:(o(r),t.regenerate(n.id,c,r),!0)}})}):(0,V.jsx)(Q,{})]})}function rt({view:e,run:t,step:n,before:r,onRestart:a}){let o=e.shown.filter(e=>e.output),s=`/api/runs/${e.id}`,c=[...r,G(`result:${n.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem]`,children:n.title}),n.message?(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{end:(0,V.jsx)(P,{base:s,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,V.jsx)(F,{base:s,step:e,output:t}),t?.assets?.some(e=>e.ai)?(0,V.jsx)(`p`,{className:`mt-3 text-[0.75rem] text-ink-3 leading-relaxed`,children:i(`ai.publish`)}):null]}),{wide:!0})),...e.lists.map(t=>G(`result:list:${t.def.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{end:(0,V.jsx)(w,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,V.jsx)(j,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return c.push(X(`result:replies`,(0,V.jsxs)(V.Fragment,{children:[o.length?(0,V.jsx)(fe,{runId:e.id,title:`${n.title} · ${e.wizard.title}`,initial:e.shareUrl?{url:e.shareUrl,expiresAt:e.expiresAt}:null}):null,a?(0,V.jsxs)(Z,{onClick:a,children:[(0,V.jsx)(M,{className:`size-4`}),` `,i(`run.again`)]}):null,e.canBack?(0,V.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:i(`run.back`)}):null,e.keeps?(0,V.jsx)(`span`,{className:`ml-1`,children:(0,V.jsx)(E,{runId:e.id})}):null]}))),(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:c})}function it({runId:e,onRestart:t,onView:n,header:r,footer:a,talk:o=!1,call:s=!1}){let c=pe(e),{view:l}=c,[u,f]=(0,B.useState)(null),m=Ae(e,l,c,u);(0,B.useEffect)(()=>{n?.(l)},[l,n]);let[h,g]=se(),v=(0,B.useMemo)(()=>({runId:e,lang:l?.lang??d,readAloud:h,setReadAloud:g,voice:l?.talk?m:null,talk:o,call:!!s,bindPage:f}),[e,l?.lang,l?.talk,h,g,m,o,s]);re(l?.status===`running`&&!l.ask),k(l);let[y,b]=(0,B.useState)({}),[S,C]=(0,B.useState)(null);(0,B.useEffect)(()=>{l&&l.status!==`running`&&C(null)},[l]);let w;if(c.notFound)w=(0,V.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:i(`run.notFound`)});else if(!l)w=(0,V.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,V.jsx)(_,{})});else{let e=l.step,n=l.status===`waiting_input`,r=Ke(l,l.canBack&&n&&!c.busy?()=>void c.back():void 0);if(l.status===`running`&&l.ask)w=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,V.jsx)(x,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,V.jsx)(Q,{})]});else if(l.status===`running`)w=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...S?[K(`note`,S)]:[],G(`working:${e?.id}`,(0,V.jsx)(Ze,{view:l}),{wide:l.events.some(t=>t.stepId===e?.id&&$e(t))?`most`:void 0})]}),(0,V.jsx)(Q,{placeholder:i(`run.working`)})]});else if(l.status===`failed`)w=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`failed`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:i(`run.failed`)}),l.error?(0,V.jsx)(`span`,{className:`mt-0.5 block`,children:(0,V.jsx)(p,{text:l.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(Z,{primary:!0,busy:c.busy,onClick:()=>void c.retry(),children:[(0,V.jsx)(M,{className:`size-4`}),` `,i(`run.retry`)]}),l.canBack?(0,V.jsx)(Z,{onClick:()=>void c.back(),disabled:c.busy,children:i(`run.back`)}):null]}))]}),(0,V.jsx)(Q,{})]});else if(l.status===`cancelled`)w=(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,i(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,V.jsxs)(Z,{primary:!0,onClick:t,children:[(0,V.jsx)(M,{className:`size-4`}),` `,i(`run.again`)]}))]:[]]});else if(e?.type===`page`)w=(0,V.jsx)(Je,{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(`|`);w=(0,V.jsx)(nt,{view:l,run:c,step:e,before:r,asked:y[e.id]??[],onNote:t=>{C(t),b(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else w=e?.type===`result`?(0,V.jsx)(rt,{view:l,run:c,step:e,before:r,onRestart:t}):(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:r})}return s?(0,V.jsx)(q.Provider,{value:v,children:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,V.jsx)(Ee,{voice:m,view:l,video:s===`video`,className:`h-[46dvh] shrink-0 lg:h-auto lg:min-h-0 lg:flex-1`}),(0,V.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,V.jsx)(Pe,{footer:a,children:w})})]})}):(0,V.jsx)(q.Provider,{value:v,children:(0,V.jsx)(Pe,{header:r,footer:a,children:w})})}export{J as a,Z as i,Pe as n,X as o,Q as r,Me as s,it as t};