wizards 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apps/runtime/dist/authoring/guide.js +1 -1
- package/apps/runtime/dist/docs/dev/wizard-format.md +6 -4
- package/apps/runtime/dist/engine/runner.js +5 -5
- package/apps/runtime/dist/engine/steps.js +2 -2
- package/apps/runtime/dist/engine/template.js +2 -2
- package/apps/runtime/dist/media/conversation.js +2 -2
- package/apps/runtime/dist/plugins/runs.js +4 -4
- package/apps/runtime/dist/routes/runs.js +4 -2
- package/apps/runtime/dist/services/api.js +2 -2
- package/apps/runtime/dist/services/runners.js +2 -2
- package/apps/runtime/dist/services/translations.js +7 -4
- package/apps/web/dist/assets/{AboutDialog-CTuI-l3p.js → AboutDialog-BrfbtjmR.js} +1 -1
- package/apps/web/dist/assets/{ChangelogDialog-jQk_bQpP.js → ChangelogDialog-BRiSYyIn.js} +1 -1
- package/apps/web/dist/assets/ChatView-_dYvuuUY.js +10 -0
- package/apps/web/dist/assets/EditorPage-CkRjTRMg.js +3 -0
- package/apps/web/dist/assets/{FlowPreview-DA0sHtr7.js → FlowPreview-CUOEzoeJ.js} +1 -1
- package/apps/web/dist/assets/{Harness-DmYkwU4x.js → Harness-D3kTVsF5.js} +1 -1
- package/apps/web/dist/assets/{NewWizardChannels-BLS9sKhT.js → NewWizardChannels-C3PGe_Zd.js} +1 -1
- package/apps/web/dist/assets/NewWizardPage-B3ol4K43.js +7 -0
- package/apps/web/dist/assets/{OnboardingPage-CREvCCdX.js → OnboardingPage-pOPB5TVZ.js} +1 -1
- package/apps/web/dist/assets/ProjectPage-Boyptzz_.js +1 -0
- package/apps/web/dist/assets/PublicRunner-DcETj9_E.js +1 -0
- package/apps/web/dist/assets/{ReadOnly-b7TjjRAk.js → ReadOnly-CCxZvYrT.js} +1 -1
- package/apps/web/dist/assets/RunDrawer-hwruVTDG.js +4 -0
- package/apps/web/dist/assets/{RunnerView-CLfZzbKn.js → RunnerView-pKik3sdE.js} +1 -1
- package/apps/web/dist/assets/SettingsPage-BOe6NgFg.js +1 -0
- package/apps/web/dist/assets/SetupPage-81QxPnfE.js +1 -0
- package/apps/web/dist/assets/{SharePage-B21QI97K.js → SharePage-CZQqp5JM.js} +1 -1
- package/apps/web/dist/assets/changelog-CtyrKHAc.js +1 -0
- package/apps/web/dist/assets/{esm-DqRvG-PU.js → esm-D4pSRQgT.js} +1 -1
- package/apps/web/dist/assets/index-DnIvQFIg.js +14 -0
- package/apps/web/dist/assets/{lock-D_KjsGfU.js → lock-DYnHCyRg.js} +1 -1
- package/apps/web/dist/assets/{phone-YRxkPQk6.js → phone-DJawY1RF.js} +1 -1
- package/apps/web/dist/assets/{settings-menu-CQgehwEX.js → settings-menu-B_-_EAmK.js} +1 -1
- package/apps/web/dist/assets/ui-rh8TaWvT.js +137 -0
- package/apps/web/dist/assets/{upload-DDo14e2p.js → upload-DL6NRa4h.js} +1 -1
- package/apps/web/dist/index.html +2 -2
- package/apps/web/dist/mcp/flow.html +1 -1
- package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +18 -7
- package/node_modules/@engenty-wizards/shared/dist/definition.js +44 -4
- package/node_modules/@engenty-wizards/shared/dist/run.d.ts +4 -4
- package/package.json +1 -1
- package/apps/web/dist/assets/ChatView-9TLi0B7K.js +0 -10
- package/apps/web/dist/assets/EditorPage-BVrzOfF3.js +0 -3
- package/apps/web/dist/assets/NewWizardPage-DWYZYiBF.js +0 -7
- package/apps/web/dist/assets/ProjectPage-BQkd55xR.js +0 -1
- package/apps/web/dist/assets/PublicRunner-sOlOC0zD.js +0 -1
- package/apps/web/dist/assets/RunDrawer-BPIVaan7.js +0 -4
- package/apps/web/dist/assets/SettingsPage-BO6TPmoj.js +0 -1
- package/apps/web/dist/assets/SetupPage-DlJHBYWH.js +0 -1
- package/apps/web/dist/assets/changelog-DeSoCsai.js +0 -1
- package/apps/web/dist/assets/index-CAUeJXCg.js +0 -14
- package/apps/web/dist/assets/ui-DDUCc_4v.js +0 -137
|
@@ -20,6 +20,11 @@ export declare const SPEECH_LOCALES: Record<Lang, string>;
|
|
|
20
20
|
export declare function isLang(value: unknown): value is Lang;
|
|
21
21
|
/** The language of a tag such as "de-AT", "fr" or "pt_BR", where engenty speaks it. */
|
|
22
22
|
export declare function langOf(tag: string | null | undefined): Lang | null;
|
|
23
|
+
/**
|
|
24
|
+
* The languages a wizard is offered in when its author picks one: English, German and the main
|
|
25
|
+
* languages of Europe. A wizard may name any other real language by its code as well.
|
|
26
|
+
*/
|
|
27
|
+
export declare const WIZARD_LANGS: readonly string[];
|
|
23
28
|
/**
|
|
24
29
|
* The person's own language beside English: the first of their languages (the browser's, in
|
|
25
30
|
* its order) that engenty speaks, else the main language of the country their time zone lies
|
|
@@ -33,6 +38,13 @@ export declare function localLang(languages: readonly string[], timeZone?: strin
|
|
|
33
38
|
export declare const LANG_CODE: RegExp;
|
|
34
39
|
/** The code of a tag such as "fr-CA" or "pt_BR"; null where it names no language. */
|
|
35
40
|
export declare function langCodeOf(tag: string | null | undefined): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* A real language, as the platform's own language data knows it: "it" and "nb" are, "xx" is
|
|
43
|
+
* not. The schema only checks the shape of a code; this checks that it names a language.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isRealLanguage(code: string): boolean;
|
|
46
|
+
/** The language engenty's own strings are read in for any language: itself where they are written, else English. */
|
|
47
|
+
export declare function textLang(code: string): Lang;
|
|
36
48
|
/**
|
|
37
49
|
* The language the person reads, for a wizard translated on request: the first of their
|
|
38
50
|
* languages (the browser's, in its order), else the main language of the country their time
|
|
@@ -45,6 +57,8 @@ export declare function langName(code: string): string;
|
|
|
45
57
|
export declare function langNameEn(code: string): string;
|
|
46
58
|
/** The locale amounts, dates and plural forms are written in for any language. */
|
|
47
59
|
export declare function localeOf(code: string): string;
|
|
60
|
+
/** The locale speech is recognised and read aloud in for any language. */
|
|
61
|
+
export declare function speechLocaleOf(code: string): string;
|
|
48
62
|
export declare const FIELD_KINDS: readonly ["text", "textarea", "number", "select", "multiselect", "date", "email", "url", "toggle", "color", "image", "file", "items", "connection", "list", "location", "audio", "signature", "slot"];
|
|
49
63
|
export type FieldKind = (typeof FIELD_KINDS)[number];
|
|
50
64
|
/**
|
|
@@ -1937,10 +1951,7 @@ export declare const wizardSchema: z.ZodObject<{
|
|
|
1937
1951
|
wedge: "wedge";
|
|
1938
1952
|
}>>;
|
|
1939
1953
|
intro: z.ZodOptional<z.ZodString>;
|
|
1940
|
-
lang: z.ZodOptional<z.
|
|
1941
|
-
de: "de";
|
|
1942
|
-
en: "en";
|
|
1943
|
-
}>>;
|
|
1954
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
1944
1955
|
lists: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1945
1956
|
id: z.ZodString;
|
|
1946
1957
|
title: z.ZodString;
|
|
@@ -2884,9 +2895,9 @@ export interface SlotTime {
|
|
|
2884
2895
|
*/
|
|
2885
2896
|
export declare function slotTime(iso: string): SlotTime | null;
|
|
2886
2897
|
/** The weekday and date of a slot's day: "Montag, 12. Oktober" / "Monday, 12 October". */
|
|
2887
|
-
export declare function slotDayText(iso: string, lang?:
|
|
2898
|
+
export declare function slotDayText(iso: string, lang?: string): string;
|
|
2888
2899
|
/** A chosen slot as a person reads it back: "Di 13.10.2026, 10:30" / "Tue 13/10/2026, 10:30". */
|
|
2889
|
-
export declare function slotText(iso: string, lang?:
|
|
2900
|
+
export declare function slotText(iso: string, lang?: string): string;
|
|
2890
2901
|
/**
|
|
2891
2902
|
* The slot among `options` that is the same moment as `value`, written as offered — so an answer
|
|
2892
2903
|
* in another offset ("…T07:00:00Z" for "…T09:00:00+02:00") picks the offered time.
|
|
@@ -2906,6 +2917,6 @@ export declare function allFields(def: WizardDefinition): Field[];
|
|
|
2906
2917
|
* The language a wizard speaks to people: the one it names, else read from its own words
|
|
2907
2918
|
* (titles, labels, intro) — English where they are not clearly German.
|
|
2908
2919
|
*/
|
|
2909
|
-
export declare function wizardLang(def: WizardDefinition):
|
|
2920
|
+
export declare function wizardLang(def: WizardDefinition): string;
|
|
2910
2921
|
/** True when this app's schema reads the definition without losing anything of it. */
|
|
2911
2922
|
export declare function readable(definition: unknown): boolean;
|
|
@@ -81,6 +81,13 @@ const COUNTRY_LANGUAGE = {
|
|
|
81
81
|
UA: "uk",
|
|
82
82
|
VA: "it",
|
|
83
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* The languages a wizard is offered in when its author picks one: English, German and the main
|
|
86
|
+
* languages of Europe. A wizard may name any other real language by its code as well.
|
|
87
|
+
*/
|
|
88
|
+
export const WIZARD_LANGS = [
|
|
89
|
+
...new Set(["en", "de", ...Object.values(COUNTRY_LANGUAGE)]),
|
|
90
|
+
];
|
|
84
91
|
/** The country of each European time zone (IANA names, as `Intl` gives them). */
|
|
85
92
|
const ZONE_COUNTRY = {
|
|
86
93
|
"Europe/Amsterdam": "NL",
|
|
@@ -151,6 +158,25 @@ export function langCodeOf(tag) {
|
|
|
151
158
|
const code = tag?.trim().toLowerCase().split(/[-_]/)[0] ?? "";
|
|
152
159
|
return LANG_CODE.test(code) ? code : null;
|
|
153
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* A real language, as the platform's own language data knows it: "it" and "nb" are, "xx" is
|
|
163
|
+
* not. The schema only checks the shape of a code; this checks that it names a language.
|
|
164
|
+
*/
|
|
165
|
+
export function isRealLanguage(code) {
|
|
166
|
+
if (!LANG_CODE.test(code)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
return Boolean(new Intl.DisplayNames(["en"], { type: "language", fallback: "none" }).of(code));
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** The language engenty's own strings are read in for any language: itself where they are written, else English. */
|
|
177
|
+
export function textLang(code) {
|
|
178
|
+
return isLang(code) ? code : "en";
|
|
179
|
+
}
|
|
154
180
|
/**
|
|
155
181
|
* The language the person reads, for a wizard translated on request: the first of their
|
|
156
182
|
* languages (the browser's, in its order), else the main language of the country their time
|
|
@@ -192,6 +218,10 @@ export function langNameEn(code) {
|
|
|
192
218
|
export function localeOf(code) {
|
|
193
219
|
return isLang(code) ? LOCALES[code] : code;
|
|
194
220
|
}
|
|
221
|
+
/** The locale speech is recognised and read aloud in for any language. */
|
|
222
|
+
export function speechLocaleOf(code) {
|
|
223
|
+
return isLang(code) ? SPEECH_LOCALES[code] : code;
|
|
224
|
+
}
|
|
195
225
|
export const FIELD_KINDS = [
|
|
196
226
|
"text",
|
|
197
227
|
"textarea",
|
|
@@ -793,9 +823,14 @@ export const wizardSchema = z.object({
|
|
|
793
823
|
intro: z.string().optional(),
|
|
794
824
|
/**
|
|
795
825
|
* The language the wizard speaks to people: its texts, the runner's words, its numbers and
|
|
796
|
-
* dates
|
|
826
|
+
* dates, by its two-letter code ("en", "de", "it"). Any language, not only those engenty's own
|
|
827
|
+
* strings are written in; `validateWizard` checks it names a real one. Without one it is read
|
|
828
|
+
* from the wizard's own words (`wizardLang`).
|
|
797
829
|
*/
|
|
798
|
-
lang: z
|
|
830
|
+
lang: z
|
|
831
|
+
.string()
|
|
832
|
+
.regex(/^[a-z]{2}$/)
|
|
833
|
+
.optional(),
|
|
799
834
|
/** Tabular data the wizard keeps between runs, per person — or for all runs (`shared`). */
|
|
800
835
|
lists: z.array(listSchema).max(12).optional(),
|
|
801
836
|
/** Accounts the person connects; kept between runs, per person. */
|
|
@@ -875,6 +910,11 @@ export function validateWizard(def, files) {
|
|
|
875
910
|
const sharedLists = new Set();
|
|
876
911
|
const connectionIds = new Set();
|
|
877
912
|
const notShown = (id) => `List "${id}" is shared: every run writes it, so the person running the wizard never sees it.`;
|
|
913
|
+
if (def.lang && !isRealLanguage(def.lang)) {
|
|
914
|
+
issues.push({
|
|
915
|
+
message: `"${def.lang}" isn't a language code. Use a two-letter code such as "en", "de" or "it".`,
|
|
916
|
+
});
|
|
917
|
+
}
|
|
878
918
|
for (const list of def.lists ?? []) {
|
|
879
919
|
if (listIds.has(list.id)) {
|
|
880
920
|
issues.push({ message: `Duplicate list id "${list.id}".` });
|
|
@@ -1769,7 +1809,7 @@ export function slotDayText(iso, lang = "en") {
|
|
|
1769
1809
|
if (!slot) {
|
|
1770
1810
|
return iso;
|
|
1771
1811
|
}
|
|
1772
|
-
const locale =
|
|
1812
|
+
const locale = localeOf(lang);
|
|
1773
1813
|
const weekday = slot.wall.toLocaleDateString(locale, { weekday: "long", timeZone: "UTC" });
|
|
1774
1814
|
const date = slot.wall.toLocaleDateString(locale, {
|
|
1775
1815
|
day: "numeric",
|
|
@@ -1784,7 +1824,7 @@ export function slotText(iso, lang = "en") {
|
|
|
1784
1824
|
if (!slot) {
|
|
1785
1825
|
return iso;
|
|
1786
1826
|
}
|
|
1787
|
-
const locale =
|
|
1827
|
+
const locale = localeOf(lang);
|
|
1788
1828
|
const weekday = slot.wall
|
|
1789
1829
|
.toLocaleDateString(locale, { weekday: "short", timeZone: "UTC" })
|
|
1790
1830
|
.replace(/\.$/, "");
|
|
@@ -501,8 +501,8 @@ export interface RunView {
|
|
|
501
501
|
status: RunStatus;
|
|
502
502
|
mode: "test" | "live";
|
|
503
503
|
wizard: Pick<WizardDefinition, "title" | "description" | "avatar" | "intro">;
|
|
504
|
-
/** The language the wizard speaks: what is read aloud, and in which voice. */
|
|
505
|
-
lang:
|
|
504
|
+
/** The language the wizard speaks, by its code: what is read aloud, and in which voice. */
|
|
505
|
+
lang: string;
|
|
506
506
|
/**
|
|
507
507
|
* The run in the viewer's language (a wizard translated on request): every text of the view
|
|
508
508
|
* is written in it, the choices keep their values and show `labels[value]`. Null: the
|
|
@@ -627,8 +627,8 @@ export interface PublicWizard {
|
|
|
627
627
|
kind: "page" | "channel";
|
|
628
628
|
url: string | null;
|
|
629
629
|
}[];
|
|
630
|
-
/** The language the wizard is written in: the page opens in it. */
|
|
631
|
-
lang:
|
|
630
|
+
/** The language the wizard is written in, by its code: the page opens in it. */
|
|
631
|
+
lang: string;
|
|
632
632
|
/** The author offers the wizard in the viewer's language, translated on request. */
|
|
633
633
|
translatable: boolean;
|
|
634
634
|
/** The page in the viewer's language, where it was asked for (`?lang=`); null: the original. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wizards",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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,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,$n as i,$t as a,Bn as o,Ft as s,Gt as c,Jn as l,Jt as u,Kt as d,Ln as f,Nn as p,Nr as m,Rt as h,Sr as g,Vn as _,Vt as v,W as y,Wn as b,Zn as x,bt as S,dt as C,ft as w,hr as T,lt as E,mt as D,nn as O,nt as k,p as A,pt as j,qt as M,rt as N,st as P,tt as F,un as I,ut as L,vr as ee,vt as R,wn as z,xt as te,yt as ne,zn as re}from"./ui-DDUCc_4v.js";import{t as ie}from"./phone-YRxkPQk6.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-CAUeJXCg.js";import{n as pe}from"./RunnerView-CLfZzbKn.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=g(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=g(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=g(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=g(be),Se=m(),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:d(`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)(v,{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:d(`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,l]=(0,B.useState)(null),[u,p]=(0,B.useState)(!1);(0,B.useEffect)(()=>{l(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,_=[...e.captions].reverse().find(e=>e.who===`bot`),y=[...e.captions].reverse().find(e=>e.who===`me`),b=e.speaking?a(`talk.speaking`):e.listening?a(`talk.listening`):o?a(`talk.live`):s?a(`talk.connecting`):u?a(`video.ended`):``;return(0,V.jsxs)(`section`,{className:d(`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:d(`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:d(`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:d(`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:d(`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:a(`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:[a(`video.you`),e.muted?(0,V.jsx)(oe,{className:`ml-1.5 inline size-3`}):null]})]}),(0,V.jsxs)(`div`,{className:d(`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:d(`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&&(_||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,_?(0,V.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:_.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:a(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)(i,{className:`size-5`})}),(0,V.jsx)(H,{label:a(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,V.jsx)(f,{className:`size-5`}):(0,V.jsx)(ye,{className:`size-5`})}),e.camera&&Ce?(0,V.jsx)(H,{label:a(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,V.jsx)(re,{className:`size-5`})}):null,(0,V.jsx)(H,{label:a(`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)(v,{className:`size-4`}):n?(0,V.jsx)(f,{className:`size-5`}):(0,V.jsx)(i,{className:`size-5`}),a(u?`video.rejoin`:n?`video.join`:`talk.start`)]}),!u&&!e.error?(0,V.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:a(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var De=e=>I[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: ${M(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[i,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`),[_,v]=(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`?a(`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)(()=>{v(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),v(!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 y.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 y.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 y.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>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(`${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,te,F,P,z]);return(0,B.useEffect)(()=>{if(i!==`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`})},[i,t,r,p,P]),{state:i,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]),i=(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??u,r,i);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:d(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?d(`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)(l,{className:`size-3`}),` `,a(`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":a(`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:d(`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)(v,{className:`size-4`}):null,t]})}function Ie({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:l,disabled:u,inputRef:p,onSend:m}){let[h,g]=(0,B.useState)(e),_=(0,B.useRef)(null),y=p??_,b=(0,B.useContext)(q),x=A(h,g,{endpoint:b?`/api/runs/${b.runId}/transcribe`:void 0}),S=!!b&&x.supported&&!u;(0,B.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,B.useEffect)(()=>{!R&&!u&&y.current?.focus()},[u,y]);let C=()=>{l||u||(x.listening&&x.toggle(),m(h)!==!1&&g(``))},w=x.listening?a(`chat.listening`):x.processing?a(`chat.transcribing`):t,T=b?.voice??null,E=!!b?.call,D=b&&!E&&(le||S||T)?(0,V.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[T?(0,V.jsx)(s,{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:d(`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,V.jsx)(v,{className:`size-4`}):T.state===`live`?(0,V.jsx)(de,{className:`size-4`}):(0,V.jsx)(ie,{className:`size-4`})}):null,T?.state===`live`?(0,V.jsx)(s,{label:a(T.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":T.camera,onClick:()=>T.camera?T.stopCamera():void T.startCamera(),className:d(`size-9`,T.camera&&`text-ink`),children:T.camera?(0,V.jsx)(f,{className:`size-4`}):(0,V.jsx)(ye,{className:`size-4`})}):null,le?(0,V.jsx)(s,{label:a(b.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":b.readAloud,onClick:()=>b.setReadAloud(!b.readAloud),className:d(`size-9`,b.readAloud&&`text-ink`),children:b.readAloud?(0,V.jsx)(ce,{className:`size-4`}):(0,V.jsx)(xe,{className:`size-4`})}):null,S?(0,V.jsx)(s,{label:a(x.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":x.listening,disabled:x.processing,onClick:x.toggle,className:d(`size-9`,x.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:x.processing?(0,V.jsx)(v,{className:`size-4`}):x.listening?(0,V.jsx)(o,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,V.jsx)(i,{className:`size-4`})}):null]}):null;return(0,V.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),C()},children:[T&&!E?(0,V.jsx)(`video`,{ref:T.video,muted:!0,playsInline:!0,autoPlay:!0,className:d(`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,V.jsxs)(`div`,{className:d(`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`,u&&`opacity-60`),children:[D,n?(0,V.jsx)(c,{ref:y,minRows:1,maxRows:6,value:h,disabled:u,placeholder:w,autoCapitalize:`sentences`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!R&&!e.nativeEvent.isComposing&&(e.preventDefault(),C())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,V.jsx)(`input`,{ref:y,...r,value:h,disabled:u,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,V.jsx)(`button`,{type:`submit`,"aria-label":a(`chat.send`),title:a(`chat.send`),disabled:l||u,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:l?(0,V.jsx)(v,{className:`size-4`}):(0,V.jsx)(ee,{className:`size-4`})})]}),x.error?(0,V.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,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:T.error}):T?.state===`live`?(0,V.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,V.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,V.jsx)(Ne,{children:(0,V.jsx)(Ie,{disabled:!0,placeholder:e,onSend:()=>!1})})}function Le(e){let t=I[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?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`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?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 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:a(`chat.connected`)});if(e.kind===`list`)return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(T,{className:`size-4`}),` `,a(`chat.checked`)]});if(e.kind===`toggle`)return(0,V.jsx)(V.Fragment,{children:a(t===!0?`run.yes`:`run.no`)});if(Re(t))return(0,V.jsx)(`span`,{className:`italic opacity-80`,children:a(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,V.jsx)(V.Fragment,{children:t.map(O).join(`, `)});case`select`:return(0,V.jsx)(V.Fragment,{children:O(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(u,{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:d(`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)(x,{className:`size-4`}),` `,a(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)(i,{className:`size-4`}),` `,a(`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:a(`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&&!z(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 i=`${t}:${r.id}`;if(r.type===`page`){let t=r.fields.length===1?r.fields[0]:void 0;n.push(...We(r,i,e.values,e.id,Ge(r,e.values),t))}else r.type===`review`&&(n.push(G(i,(0,V.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 qe(e,t){return e.fields.filter(e=>!z(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 i=(0,B.useMemo)(()=>qe(n,e),[n,e]),o=e.known??{},[s,c]=(0,B.useState)(()=>F(n,e)),[l,u]=(0,B.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?p(qe(n,e),e.known??{},F(n,e)).slice(0,-1).map(e=>e.id):[]),[d,f]=(0,B.useState)({}),[m,h]=(0,B.useState)(!1),[g,_]=(0,B.useState)(!1),v=p(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,B.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=p(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,B.useContext)(q),D=(0,B.useRef)(s);D.current=s;let O=T?.bindPage,k=(0,B.useRef)(w);k.current=w,(0,B.useEffect)(()=>{if(!O)return;let e=p(i,o,s);return O({step:n,fields:e,values:s,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?ze(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(D.current)}),()=>O(null)},[O,n,i,o,s]);let A=e=>{if(!b)return!1;let t=ze(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({}),p(i,o,n).some(e=>!r.includes(e.id))||w(n),!0},j=[...r.map(e=>l.length?{...e,onEdit:void 0}:e),...We(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?(Le(b)===`control`?j.push(G(`now:${n.id}:${b.id}:control`,(0,V.jsx)(E,{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:h}),{wide:!0})):x||j.push(G(`now:${n.id}:${b.id}`,(0,V.jsx)(Ve,{field:b}))),d[b.id]&&j.push(G(`now:${n.id}:${b.id}:error`,d[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&&l.length>0&&t.busy)M=(0,V.jsx)(Q,{placeholder:a(`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(s),children:n.cta||a(`run.next`)}),C?(0,V.jsx)(Z,{onClick:C,disabled:t.busy,children:a(`run.back`)}):null]})));else{let r=Le(b),i=!b.required&&b.kind!==`connection`&&b.kind!==`list`?(0,V.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,V.jsx)(Ne,{children:(0,V.jsx)(Ie,{initial:Re(e)?``:String(e),multiline:b.kind===`textarea`,placeholder:b.placeholder||(x?b.label:a(`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: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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,disabled:m,onClick:()=>A(s[b.id]),children:e&&n.cta?n.cta:a(`chat.send`)}),i]})))}}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 L(e)}}function Xe({field:e,view:t,value:n,onAnswer:r}){let i=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:i.has(`false`),onClick:()=>r(!1),children:a(`run.no`)}),(0,V.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,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:O(e)},e)),(0,V.jsx)(Z,{primary:!0,disabled:e.required&&!o.length,onClick:()=>r(o),children:o.length||e.required?a(`chat.send`):a(`chat.skip`)})]}):(0,V.jsxs)(Y,{children:[c.map(e=>(0,V.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:O(e)},e)),e.required?null:(0,V.jsx)(Z,{onClick:()=>r(void 0),children:a(`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(),[i,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:d(`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,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??a(`run.working`)}),(0,V.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,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(_,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,V.jsx)(`span`,{className:`truncate`,children:M(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),[i,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=()=>y.get(`/api/runs/${e}/browser/seat`).then(e=>o(e.seat)).catch(()=>void 0);if(t(),i!==`person`)return;let n=setInterval(t,et);return()=>clearInterval(n)},[e,i]),n!==null&&n>=t.id)return null;let u=i===`person`,f=async()=>{c(!0);try{let t=await y.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});o(t.seat)}catch{}finally{c(!1)}};return(0,V.jsx)(te,{runId:e,driving:u,caption:M(t),hint:a(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,V.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void f(),className:d(`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`}),a(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:i,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,...i.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)(P,{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)(C,{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)(T,{className:`size-4`}),` `,a(`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?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,V.jsx)(Q,{})]})}function rt({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,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)(N,{base:s,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,V.jsx)(P,{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:a(`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,i?(0,V.jsxs)(Z,{onClick:i,children:[(0,V.jsx)(b,{className:`size-4`}),` `,a(`run.again`)]}):null,e.canBack?(0,V.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:a(`run.back`)}):null,e.keeps?(0,V.jsx)(`span`,{className:`ml-1`,children:(0,V.jsx)(D,{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:i,talk:o=!1,call:s=!1}){let c=pe(e),{view:l}=c,[d,f]=(0,B.useState)(null),p=Ae(e,l,c,d);(0,B.useEffect)(()=>{n?.(l)},[l,n]);let[m,g]=se(),_=(0,B.useMemo)(()=>({runId:e,lang:l?.lang??u,readAloud:m,setReadAloud:g,voice:l?.talk?p:null,talk:o,call:!!s,bindPage:f}),[e,l?.lang,l?.talk,m,g,p,o,s]);ne(l?.status===`running`&&!l.ask),k(l);let[y,x]=(0,B.useState)({}),[C,w]=(0,B.useState)(null);(0,B.useEffect)(()=>{l&&l.status!==`running`&&w(null)},[l]);let T;if(c.notFound)T=(0,V.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:a(`run.notFound`)});else if(!l)T=(0,V.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,V.jsx)(v,{})});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)T=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,V.jsx)(S,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,V.jsx)(Q,{})]});else if(l.status===`running`)T=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...C?[K(`note`,C)]:[],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:a(`run.working`)})]});else if(l.status===`failed`)T=(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:a(`run.failed`)}),l.error?(0,V.jsx)(`span`,{className:`mt-0.5 block`,children:(0,V.jsx)(h,{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)(b,{className:`size-4`}),` `,a(`run.retry`)]}),l.canBack?(0,V.jsx)(Z,{onClick:()=>void c.back(),disabled:c.busy,children:a(`run.back`)}):null]}))]}),(0,V.jsx)(Q,{})]});else if(l.status===`cancelled`)T=(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,a(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,V.jsxs)(Z,{primary:!0,onClick:t,children:[(0,V.jsx)(b,{className:`size-4`}),` `,a(`run.again`)]}))]:[]]});else if(e?.type===`page`)T=(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(`|`);T=(0,V.jsx)(nt,{view:l,run:c,step:e,before:r,asked:y[e.id]??[],onNote:t=>{w(t),x(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else T=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:_,children:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,V.jsx)(Ee,{voice:p,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:i,children:T})})]})}):(0,V.jsx)(q.Provider,{value:_,children:(0,V.jsx)(Pe,{header:r,footer:i,children:T})})}export{J as a,Z as i,Pe as n,X as o,Q as r,Me as s,it as t};
|