wizards 0.3.7 → 0.4.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 (72) hide show
  1. package/README.md +28 -14
  2. package/apps/runtime/dist/agents/studio-assistant.js +79 -7
  3. package/apps/runtime/dist/assistant/runs.js +24 -0
  4. package/apps/runtime/dist/auth/account.js +36 -4
  5. package/apps/runtime/dist/auth/device.js +101 -0
  6. package/apps/runtime/dist/auth/index.js +4 -4
  7. package/apps/runtime/dist/cli/account.js +289 -0
  8. package/apps/runtime/dist/cli/install-env.js +33 -0
  9. package/apps/runtime/dist/cli/main.js +17 -3
  10. package/apps/runtime/dist/cli/menu.js +19 -5
  11. package/apps/runtime/dist/cli/setup.js +9 -16
  12. package/apps/runtime/dist/cli/status.js +4 -1
  13. package/apps/runtime/dist/cli/ui.js +14 -0
  14. package/apps/runtime/dist/docs/user/assistant.md +25 -7
  15. package/apps/runtime/dist/docs/user/command-line.md +3 -2
  16. package/apps/runtime/dist/docs/user/create-account.md +47 -0
  17. package/apps/runtime/dist/docs/user/first-start.md +9 -1
  18. package/apps/runtime/dist/docs/user/index.md +16 -12
  19. package/apps/runtime/dist/docs/user/install.md +3 -1
  20. package/apps/runtime/dist/docs/user/local-only.md +38 -0
  21. package/apps/runtime/dist/docs/user/meta.json +3 -1
  22. package/apps/runtime/dist/docs/user/models.md +3 -2
  23. package/apps/runtime/dist/env.js +5 -0
  24. package/apps/runtime/dist/manage.js +16 -4
  25. package/apps/runtime/dist/models.js +6 -0
  26. package/apps/runtime/dist/plugins/pro.js +16 -16
  27. package/apps/runtime/dist/routes/studio.js +140 -40
  28. package/apps/runtime/dist/services/assistant-chats.js +49 -6
  29. package/apps/runtime/dist/services/cloud.js +10 -10
  30. package/apps/runtime/dist/services/onboarding.js +152 -0
  31. package/apps/web/dist/assets/{AboutDialog-C0dN86zd.js → AboutDialog-CPQiN7H9.js} +1 -1
  32. package/apps/web/dist/assets/{ChangelogDialog-Cv81t7tj.js → ChangelogDialog-DynvQuuR.js} +1 -1
  33. package/apps/web/dist/assets/ChatView-CKo_9IZD.js +10 -0
  34. package/apps/web/dist/assets/EditorPage-CDIJXC4T.js +3 -0
  35. package/apps/web/dist/assets/{FlowPreview-D4dp1MWS.js → FlowPreview-BZLnG7GV.js} +1 -1
  36. package/apps/web/dist/assets/{Harness-v7r0e6vK.js → Harness-CNh3nbB_.js} +2 -2
  37. package/apps/web/dist/assets/{NewWizardChannels-Be-7VhBi.js → NewWizardChannels-C1Ss9UMY.js} +1 -1
  38. package/apps/web/dist/assets/{NewWizardPage-C8hPvrK8.js → NewWizardPage-2qLAbvDL.js} +2 -2
  39. package/apps/web/dist/assets/OnboardingPage-C1FJwEsT.js +1 -0
  40. package/apps/web/dist/assets/ProjectPage-CGuLUuOs.js +1 -0
  41. package/apps/web/dist/assets/{PublicRunner-DeCpVfZP.js → PublicRunner-BKw1lOW4.js} +1 -1
  42. package/apps/web/dist/assets/{ReadOnly-B-UCgnqW.js → ReadOnly-DTjv2Jzm.js} +1 -1
  43. package/apps/web/dist/assets/RunDrawer-D1I5xqVf.js +4 -0
  44. package/apps/web/dist/assets/RunnerView-BPPmlv9z.js +1 -0
  45. package/apps/web/dist/assets/SettingsPage-zbomQfGy.js +1 -0
  46. package/apps/web/dist/assets/SetupPage-D3F7M6Pz.js +1 -0
  47. package/apps/web/dist/assets/{SharePage-B778xUFo.js → SharePage-BY49IJgT.js} +1 -1
  48. package/apps/web/dist/assets/{changelog-DCJo2mbx.js → changelog-DYZC2E6q.js} +1 -1
  49. package/apps/web/dist/assets/{circle-alert-DLvC9ePT.js → circle-alert-CVOH4wAv.js} +1 -1
  50. package/apps/web/dist/assets/{esm-BJskogLD.js → esm-BfXdeWaI.js} +1 -1
  51. package/apps/web/dist/assets/index-B9xVkr2X.css +1 -0
  52. package/apps/web/dist/assets/index-BH0PYgov.js +15 -0
  53. package/apps/web/dist/assets/{lock-DR7NakPn.js → lock-DHBh62LA.js} +1 -1
  54. package/apps/web/dist/assets/{phone-BORh3jfv.js → phone-Bt1cyWpY.js} +1 -1
  55. package/apps/web/dist/assets/{settings-menu-DV5D91TD.js → settings-menu-ace1vI3i.js} +1 -1
  56. package/apps/web/dist/assets/{ui-BOCXzzHi.js → ui-D2SqIZeQ.js} +2 -2
  57. package/apps/web/dist/assets/{upload-B3yv8gsk.js → upload-CCEq88l4.js} +1 -1
  58. package/apps/web/dist/index.html +3 -3
  59. package/apps/web/dist/install.sh +17 -7
  60. package/apps/web/dist/mcp/flow.html +3 -3
  61. package/node_modules/@engenty-wizards/shared/dist/assistant.d.ts +62 -1
  62. package/node_modules/@engenty-wizards/shared/dist/assistant.js +10 -0
  63. package/package.json +1 -1
  64. package/apps/web/dist/assets/ChatView-uogJ3nht.js +0 -10
  65. package/apps/web/dist/assets/EditorPage-n8YuTh6j.js +0 -3
  66. package/apps/web/dist/assets/ProjectPage-B686ArYy.js +0 -1
  67. package/apps/web/dist/assets/RunDrawer-C6pzi8AJ.js +0 -4
  68. package/apps/web/dist/assets/RunnerView-Deenymq0.js +0 -1
  69. package/apps/web/dist/assets/SettingsPage-CK6L0yEe.js +0 -1
  70. package/apps/web/dist/assets/SetupPage-9CH3qXdH.js +0 -1
  71. package/apps/web/dist/assets/index-D6hUM8NU.css +0 -1
  72. package/apps/web/dist/assets/index-Df6UxElH.js +0 -12
@@ -63,11 +63,58 @@ export declare const assistantTurnSchema: z.ZodObject<{
63
63
  description: z.ZodString;
64
64
  parameters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
65
65
  }, z.core.$strip>>>;
66
+ debug: z.ZodOptional<z.ZodBoolean>;
66
67
  }, z.core.$strip>;
67
68
  export type AssistantTurn = z.input<typeof assistantTurnSchema>;
69
+ /**
70
+ * A message the person writes while a turn runs (POST /api/studio/assistant/run/:runId/signal):
71
+ * the turn takes it before its next step, or after its answer. `ref` is the browser's id for it.
72
+ */
73
+ export declare const assistantSignalSchema: z.ZodObject<{
74
+ ref: z.ZodString;
75
+ message: z.ZodString;
76
+ }, z.core.$strip>;
77
+ export type AssistantSignal = z.infer<typeof assistantSignalSchema>;
78
+ /** One model step of a turn, in developer mode. */
79
+ export interface AssistantStep {
80
+ /** Counted over the turn, from 1. */
81
+ step: number;
82
+ /** The model the class is bound to, e.g. `anthropic/claude-sonnet-4.6` or `claude:sonnet`. */
83
+ model: string;
84
+ inputTokens: number;
85
+ outputTokens: number;
86
+ cachedInputTokens: number;
87
+ /** From the step's start to its end, tools included. */
88
+ ms: number;
89
+ costUsd: number;
90
+ /** The tools the model called in the step. */
91
+ tools: string[];
92
+ /** The model's context window in tokens, where the catalog knows it. */
93
+ window: number | null;
94
+ }
95
+ /** What a turn sent to the model, in developer mode: its parts and their size. */
96
+ export interface AssistantPrompt {
97
+ model: string;
98
+ system: string;
99
+ /** The turn's own message: earlier chats, the page, the space, what the person wrote. */
100
+ context: string;
101
+ /** The open chat's messages sent along. */
102
+ history: {
103
+ role: "user" | "assistant";
104
+ chars: number;
105
+ }[];
106
+ /** Each tool's description and schema, in characters. */
107
+ tools: {
108
+ name: string;
109
+ chars: number;
110
+ }[];
111
+ }
68
112
  /** The events of a turn, by SSE event name. */
69
113
  export interface AssistantEvents {
70
- /** The turn started; `messageId` is the stored message of the person. */
114
+ /**
115
+ * The turn started; `messageId` is the stored message of the person. Messages written meanwhile
116
+ * go to `runId` as signals.
117
+ */
71
118
  run_started: {
72
119
  threadId: string;
73
120
  runId: string;
@@ -99,6 +146,20 @@ export interface AssistantEvents {
99
146
  };
100
147
  /** The space or a plugin's data changed: the page reads its data again. */
101
148
  changed: Record<string, never>;
149
+ /**
150
+ * The turn took a message written meanwhile (`ref`, stored as `messageId`). What the answer said
151
+ * before it was stored as `answerId` (null when it had said nothing); the answer goes on after it.
152
+ */
153
+ signal: {
154
+ ref: string;
155
+ messageId: string;
156
+ content: string;
157
+ answerId: string | null;
158
+ };
159
+ /** Developer mode: what went to the model. */
160
+ prompt: AssistantPrompt;
161
+ /** Developer mode: a model step ended. */
162
+ step: AssistantStep;
102
163
  done: {
103
164
  messageId: string;
104
165
  reply: string;
@@ -50,6 +50,16 @@ export const assistantTurnSchema = z.object({
50
50
  projectId: z.string().max(80).optional(),
51
51
  page: assistantPageSchema.optional(),
52
52
  tools: z.array(browserToolSchema).max(40).default([]),
53
+ /** Developer mode: the turn also sends its prompt and each step (`prompt`, `step`). */
54
+ debug: z.boolean().optional(),
55
+ });
56
+ /**
57
+ * A message the person writes while a turn runs (POST /api/studio/assistant/run/:runId/signal):
58
+ * the turn takes it before its next step, or after its answer. `ref` is the browser's id for it.
59
+ */
60
+ export const assistantSignalSchema = z.object({
61
+ ref: z.string().min(1).max(40),
62
+ message: z.string().min(1).max(8000),
53
63
  });
54
64
  /** Where the assistant stands on the screen, per person. */
55
65
  export const ASSISTANT_LAYOUTS = ["bottom", "sidebar", "avatar"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wizards",
3
- "version": "0.3.7",
3
+ "version": "0.4.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,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{A as r,Dt as i,E as a,Et as o,Ft as s,It as c,J as l,Kt as u,Lt as d,M as f,Mt as p,N as m,O as h,Pt as g,S as _,Tt as v,Vt as y,Wt as b,_t as x,an as S,at as C,b as w,bt as T,dn as E,et as D,it as O,j as k,k as A,kt as j,l as M,mt as N,nt as P,rt as F,s as I,sn as L,v as ee,wt as te,x as R,z}from"./ui-BOCXzzHi.js";import{t as ne}from"./phone-BORh3jfv.js";import{$t as re,Ht as ie,It as ae,bt as oe,nn as se,t as ce,vn as le,xt as ue,yt as de}from"./index-Df6UxElH.js";import{n as fe}from"./RunnerView-Deenymq0.js";var pe={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`}]]};pe.node;var me=E(pe),he={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`}]]};he.node;var ge=E(he),_e={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`}]]};_e.node;var ve=E(_e),ye={name:`volume-x`,size:24,node:[[`path`,{d:`M11 4.702a.7.7 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.7.7 0 0 0 11 19.298z`,key:`1p7khw`}],[`path`,{d:`m16.5 14.5 5-5`,key:`cul3yw`}],[`path`,{d:`m16.5 9.5 5 5`,key:`1akey5`}]]};ye.node;var be=E(ye),xe=le(),B=e(t(),1),V=e(n(),1),Se=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function Ce({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:v(`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)(T,{className:`size-5`}):a})}function we({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:v(`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 Te({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,a=e.state===`connecting`,[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!1);(0,B.useEffect)(()=>{s(i?Date.now():null)},[i]);let d=async()=>{l(!1),await e.start(),n&&await e.startCamera()},f=()=>{e.stop(),l(!0)},m=n||e.camera,h=[...e.captions].reverse().find(e=>e.who===`bot`),_=[...e.captions].reverse().find(e=>e.who===`me`),y=e.speaking?j(`talk.speaking`):e.listening?j(`talk.listening`):i?j(`talk.live`):a?j(`talk.connecting`):c?j(`video.ended`):``;return(0,V.jsxs)(`section`,{className:v(`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??``}),y?(0,V.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,V.jsx)(`span`,{className:v(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,y]}):null,(0,V.jsx)(Ce,{since:o})]}),(0,V.jsxs)(`div`,{className:v(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,m?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!m&&i&&e.captions.length?`h-[38%]`:m?``:`flex-1`),children:[(0,V.jsxs)(`div`,{className:v(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!m&&`hidden`),children:[(0,V.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:v(`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)(ve,{className:`size-8`}),(0,V.jsx)(`span`,{className:`text-[0.8125rem]`,children:j(`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:[j(`video.you`),e.muted?(0,V.jsx)(se,{className:`ml-1.5 inline size-3`}):null]})]}),(0,V.jsxs)(`div`,{className:v(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,m?`bg-neutral-900`:`bg-transparent`,m&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,V.jsx)(`div`,{className:v(`rounded-full transition-shadow duration-500`,!m&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!m&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,V.jsx)(ae,{kind:t?.wizard.avatar??`round`,size:m?140:200,fluffy:!0,interactive:!1})}),m?(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]})]}),i&&!m?(0,V.jsx)(we,{voice:e}):i&&(h||_)?(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:[_?(0,V.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:_.text}):null,h?(0,V.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:h.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:i?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(H,{label:j(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,V.jsx)(se,{className:`size-5`}):(0,V.jsx)(u,{className:`size-5`})}),(0,V.jsx)(H,{label:j(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,V.jsx)(p,{className:`size-5`}):(0,V.jsx)(ve,{className:`size-5`})}),e.camera&&Se?(0,V.jsx)(H,{label:j(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,V.jsx)(g,{className:`size-5`})}):null,(0,V.jsx)(H,{label:j(`video.leave`),danger:!0,onClick:f,children:(0,V.jsx)(re,{className:`size-5`})})]}):(0,V.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,V.jsxs)(`button`,{type:`button`,disabled:a||!t?.talk,onClick:()=>void d(),className:`flex h-12 items-center gap-2 rounded-full bg-emerald-500 px-6 font-medium text-[0.9375rem] text-white transition hover:brightness-110 disabled:opacity-50`,children:[a?(0,V.jsx)(T,{className:`size-4`}):n?(0,V.jsx)(p,{className:`size-5`}):(0,V.jsx)(u,{className:`size-5`}),j(c?`video.rejoin`:n?`video.join`:`talk.start`)]}),!c&&!e.error?(0,V.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:j(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var Ee=e=>z[e.kind]!==`device`,De=1024,Oe=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: ${o(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=Ee(e)?`by voice`:e.kind===`image`?`with the camera (take_photo) or on the screen`:`on the screen only`,o=e.options?.length?`; options: ${e.options.join(` | `)}`:``;r.push(`- field ${e.id} (${e.kind}${e.required?`, required`:``}, ${a}): ${e.label}${e.help?` – ${e.help}`:``}${o}${i?` = ${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 ke(e,t,n,r){let[i,a]=(0,B.useState)(`off`),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(!1),[m,h]=(0,B.useState)(`environment`),[g,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)([]),b=(0,B.useRef)(null),x=(0,B.useRef)(null),S=(0,B.useRef)(0),C=(0,B.useRef)(!1);C.current=f;let w=(0,B.useRef)(null),T=(0,B.useRef)(null),E=(0,B.useRef)(null),D=(0,B.useRef)(null),O=(0,B.useRef)(t);O.current=t;let k=(0,B.useRef)(r);k.current=r;let A=(0,B.useRef)(n);A.current=n;let N=(0,B.useRef)(``),P=(0,B.useCallback)(e=>{let t=T.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,B.useCallback)(()=>{let e=b.current;if(!C.current||!e||e.videoWidth===0)return null;let t=Math.min(1,De/e.videoWidth),n=document.createElement(`canvas`);return n.width=Math.round(e.videoWidth*t),n.height=Math.round(e.videoHeight*t),n.getContext(`2d`)?.drawImage(e,0,0,n.width,n.height),n.toDataURL(`image/jpeg`,.75)},[]),I=(0,B.useCallback)(()=>{for(let e of x.current?.getTracks()??[])e.stop();x.current=null,b.current&&(b.current.srcObject=null),p(!1)},[]),L=(0,B.useCallback)(async e=>{if(x.current)return;let t=e??`environment`;try{let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:t},width:{ideal:1280}},audio:!1});x.current=e;let n=e.getVideoTracks()[0]?.getSettings().facingMode;h(n===`user`||n===`environment`?n:t),b.current&&(b.current.srcObject=e,await b.current.play().catch(()=>void 0)),p(!0)}catch(e){s(e.name===`NotAllowedError`?j(`talk.cameraDenied`):e.message)}},[]),ee=(0,B.useCallback)(async()=>{let e=m===`user`?`environment`:`user`;I(),await L(e)},[m,I,L]),te=(0,B.useCallback)(()=>{_(e=>{for(let t of D.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),R=(0,B.useCallback)(()=>{I(),T.current?.close(),T.current=null,w.current?.close(),w.current=null;for(let e of D.current?.getTracks()??[])e.stop();D.current=null,E.current&&=(E.current.srcObject=null,E.current.remove(),null),N.current=``,l(!1),d(!1),_(!1),a(`off`)},[I]);(0,B.useEffect)(()=>()=>R(),[R]);let z=(0,B.useCallback)(async(t,n)=>{let r=O.current,i=k.current,a=A.current;switch(t){case`get_state`:return r?W(r,i,C.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 M.upload(`/api/runs/${e}/uploads`,a),s=i.values[t.id],c=t.multiple?[...Array.isArray(s)?s:s?[s]:[],o.id]:o.id,l=i.setField(t.id,c);return l?`refused: ${l}`:`the photo is in the field`}catch(e){return`failed: ${e.message}`}}case`set_field`:{if(!i)return`no page is open`;let e=i.setField(String(n.field??``),n.value);return e?`refused: ${e}`:`kept`}case`submit_page`:{if(!i)return`no page is open`;let e=i.fields.filter(e=>e.required&&Ee(e)&&e.kind!==`toggle`&&(i.values[e.id]===void 0||i.values[e.id]===null||i.values[e.id]===``));return e.length?`still open: ${e.map(e=>e.id).join(`, `)}`:(i.submit(),`sent; wait for the next state`)}case`accept_review`:return r?.step?.type===`review`?await a.accept(r.step.id)?`accepted`:a.error??`refused`:`no review is open`;case`regenerate`:return r?.step?.type===`review`?await a.regenerate(r.step.id,String(n.target??``),String(n.note??``))?`the wizard makes it again; wait`:a.error??`refused`:`no review is open`;case`answer_ask`:if(!r?.ask)return`no question is open`;try{return await M.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(!w.current){s(null),y([]),a(`connecting`);try{let t=await M.post(`/api/runs/${e}/talk`),n=await navigator.mediaDevices.getUserMedia({audio:!0});D.current=n;let r=new RTCPeerConnection;w.current=r;let i=document.createElement(`audio`);i.autoplay=!0,i.setAttribute(`playsinline`,``),document.body.append(i),E.current=i,r.ontrack=e=>{i.srcObject=e.streams[0]};for(let e of n.getTracks())r.addTrack(e,n);let o=r.createDataChannel(`oai-events`);T.current=o,o.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case`output_audio_buffer.started`:l(!0);break;case`output_audio_buffer.stopped`:case`output_audio_buffer.cleared`:l(!1);break;case`input_audio_buffer.speech_started`:{d(!0);let e=Date.now()-S.current>Oe?F():null;e&&(S.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`:d(!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`;y(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{}z(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`:s(String(t.error?.message??`error`))}},o.onopen=()=>{a(`live`);let e=O.current;e&&(N.current=W(e,k.current,C.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`}))},o.onclose=()=>{w.current===r&&R()};let c=await r.createOffer();await r.setLocalDescription(c);let u=await fetch(t.endpoint,{method:`POST`,headers:{authorization:`Bearer ${t.clientSecret}`,"content-type":`application/sdp`},body:c.sdp});if(!u.ok)throw Error(`${j(`talk.failed`)} (${u.status})`);await r.setRemoteDescription({type:`answer`,sdp:await u.text()})}catch(e){R(),s(e.name===`NotAllowedError`?j(`chat.micDenied`):e.message),a(`error`)}}},[e,z,F,P,R]);return(0,B.useEffect)(()=>{if(i!==`live`||!t)return;let e=W(t,r,f);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,f,P]),{state:i,error:o,speaking:c,listening:u,start:ne,stop:R,camera:f,facing:m,startCamera:L,stopCamera:I,flipCamera:ee,muted:g,toggleMute:te,captions:v,video:b}}var G=(e,t,n)=>({key:e,who:`bot`,node:t,...n}),K=(e,t,n)=>({key:e,who:`me`,node:t,...n}),Ae=(0,B.createContext)(null),q=(0,B.createContext)(null);function je(){return(0,B.useContext)(q)?.voice??null}function Me({children:e}){let t=(0,B.useContext)(Ae);return t?(0,xe.createPortal)(e,t):null}function Ne({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)(Ae.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},[]);ue(!!n?.readAloud,n?.lang??i,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)(ae,{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:v(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?v(`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)(y,{className:`size-3`}),` `,j(`chat.change`)]}):null]},e.key)))}function Pe(){return(0,V.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":j(`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:v(`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)(T,{className:`size-4`}):null,t]})}function Fe({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:a,inputRef:o,onSend:c}){let[l,d]=(0,B.useState)(e),f=(0,B.useRef)(null),m=o??f,h=(0,B.useContext)(q),g=I(l,d,{endpoint:h?`/api/runs/${h.runId}/transcribe`:void 0}),_=!!h&&g.supported&&!a;(0,B.useEffect)(()=>{if(!_)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),g.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,g.toggle]),(0,B.useEffect)(()=>{!P&&!a&&m.current?.focus()},[a,m]);let y=()=>{i||a||(g.listening&&g.toggle(),c(l)!==!1&&d(``))},b=g.listening?j(`chat.listening`):g.processing?j(`chat.transcribing`):t,x=h?.voice??null,S=!!h?.call,C=h&&!S&&(de||_||x)?(0,V.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[x?(0,V.jsx)(N,{label:j(x.state===`live`?`talk.stop`:x.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":x.state===`live`,disabled:x.state===`connecting`,onClick:()=>x.state===`live`?x.stop():void x.start(),className:v(`size-9`,x.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,x.state===`off`&&h.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:x.state===`connecting`?(0,V.jsx)(T,{className:`size-4`}):x.state===`live`?(0,V.jsx)(re,{className:`size-4`}):(0,V.jsx)(ne,{className:`size-4`})}):null,x?.state===`live`?(0,V.jsx)(N,{label:j(x.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":x.camera,onClick:()=>x.camera?x.stopCamera():void x.startCamera(),className:v(`size-9`,x.camera&&`text-ink`),children:x.camera?(0,V.jsx)(p,{className:`size-4`}):(0,V.jsx)(ve,{className:`size-4`})}):null,de?(0,V.jsx)(N,{label:j(h.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":h.readAloud,onClick:()=>h.setReadAloud(!h.readAloud),className:v(`size-9`,h.readAloud&&`text-ink`),children:h.readAloud?(0,V.jsx)(ie,{className:`size-4`}):(0,V.jsx)(be,{className:`size-4`})}):null,_?(0,V.jsx)(N,{label:j(g.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":g.listening,disabled:g.processing,onClick:g.toggle,className:v(`size-9`,g.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:g.processing?(0,V.jsx)(T,{className:`size-4`}):g.listening?(0,V.jsx)(s,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,V.jsx)(u,{className:`size-4`})}):null]}):null;return(0,V.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),y()},children:[x&&!S?(0,V.jsx)(`video`,{ref:x.video,muted:!0,playsInline:!0,autoPlay:!0,className:v(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,x.camera?`block`:`hidden`)}):null,(0,V.jsxs)(`div`,{className:v(`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`,a&&`opacity-60`),children:[C,n?(0,V.jsx)(te,{ref:m,minRows:1,maxRows:6,value:l,disabled:a,placeholder:b,autoCapitalize:`sentences`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!P&&!e.nativeEvent.isComposing&&(e.preventDefault(),y())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,V.jsx)(`input`,{ref:m,...r,value:l,disabled:a,placeholder:b,enterKeyHint:`send`,onChange:e=>d(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":j(`chat.send`),title:j(`chat.send`),disabled:i||a,className:`mb-1 flex size-9 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:brightness-[1.06] disabled:opacity-40`,children:i?(0,V.jsx)(T,{className:`size-4`}):(0,V.jsx)(L,{className:`size-4`})})]}),g.error?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:g.error===`denied`?j(`chat.micDenied`):g.error}):S?null:x?.error?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:x.error}):x?.state===`live`?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:x.speaking?j(`talk.speaking`):x.listening?j(`talk.listening`):j(`talk.live`)}):h?.talk&&x?.state===`off`?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:j(`talk.hint`)}):null]})}function Q({placeholder:e=j(`chat.above`)}){return(0,V.jsx)(Me,{children:(0,V.jsx)(Fe,{disabled:!0,placeholder:e,onSend:()=>!1})})}function Ie(e){let t=z[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Le=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Re(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Le(t))return e.required&&!n?j(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return j(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return j(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?j(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?j(`run.filesMin`,{n:t.length,min:e.min}):null}function ze(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 Be({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 Ve({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 He({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,V.jsx)(V.Fragment,{children:typeof t==`string`&&t?t:j(`chat.connected`)});if(e.kind===`list`)return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(S,{className:`size-4`}),` `,j(`chat.checked`)]});if(e.kind===`toggle`)return(0,V.jsx)(V.Fragment,{children:j(t===!0?`run.yes`:`run.no`)});if(Le(t))return(0,V.jsx)(`span`,{className:`italic opacity-80`,children:j(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,V.jsx)(V.Fragment,{children:t.join(`, `)});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(i,{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:ee(`/api/runs/${n}/assets/${t}`),alt:``,className:v(`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)(b,{className:`size-4`}),` `,j(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)(u,{className:`size-4`}),` `,j(`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:j(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,V.jsx)(V.Fragment,{children:String(t)})}}function Ue(e,t,n,r,i,a){let o=[G(t,(0,V.jsx)(Ve,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,V.jsx)(Be,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,V.jsx)(He,{field:e,value:n[e.id],runId:r})));return o}var We=(e,t)=>e.fields.filter(e=>!e.when&&!l(e)||t[e.id]!==void 0&&t[e.id]!==null);function Ge(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(...Ue(r,i,e.values,e.id,We(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`,j(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function Ke(e,t){return e.fields.filter(e=>!l(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function qe({view:e,run:t,step:n,before:r}){let i=(0,B.useMemo)(()=>Ke(n,e),[n,e]),a=e.known??{},[o,s]=(0,B.useState)(()=>w(n,e)),[c,l]=(0,B.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?D(Ke(n,e),e.known??{},w(n,e)).slice(0,-1).map(e=>e.id):[]),[u,d]=(0,B.useState)({}),[f,p]=(0,B.useState)(!1),[m,g]=(0,B.useState)(!1),_=D(i,a,o),v=_.filter(e=>c.includes(e.id)),y=_.find(e=>!c.includes(e.id)),b=i.length===1?i[0]:void 0,x=v.at(-1),S=x?()=>l(e=>e.filter(e=>e!==x.id)):void 0;(0,B.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=D(i,a,o),r=n.findIndex(t=>e.includes(t.id));r>=0&&(l(n.slice(0,r).map(e=>e.id)),d(t.fieldErrors))},[t.fieldErrors]);let C=e=>{t.submitPage(n.id,e).then(g)},T=(0,B.useContext)(q),E=(0,B.useRef)(o);E.current=o;let O=T?.bindPage,k=(0,B.useRef)(C);k.current=C,(0,B.useEffect)(()=>{if(!O)return;let e=D(i,a,o);return O({step:n,fields:e,values:o,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Re(r,n)||(s(e=>({...e,[t]:n})),l(e=>e.includes(t)?e:[...e,t]),d({}),null):`no such field on this page`},submit:()=>k.current(E.current)}),()=>O(null)},[O,n,i,a,o]);let A=e=>{if(!y)return!1;let t=Re(y,e);if(t)return d({[y.id]:t}),!1;let n={...o,[y.id]:e},r=[...c,y.id];return s(n),l(r),d({}),D(i,a,n).some(e=>!r.includes(e.id))||C(n),!0},M=[...r.map(e=>c.length?{...e,onEdit:void 0}:e),...Ue(n,`now:${n.id}`,o,e.id,v,b).map((e,t,n)=>t===n.length-1&&e.who===`me`&&y?{...e,onEdit:S}:e)];y?(Ie(y)===`control`?M.push(G(`now:${n.id}:${y.id}:control`,(0,V.jsx)(h,{field:y,value:o[y.id],values:o,runId:e.id,view:e,closed:e.closed?.[y.id],onChange:e=>s(t=>({...t,[y.id]:e})),onBusy:p}),{wide:!0})):b||M.push(G(`now:${n.id}:${y.id}`,(0,V.jsx)(Be,{field:y}))),u[y.id]&&M.push(G(`now:${n.id}:${y.id}:error`,u[y.id],{tone:`error`}))):t.busy||m?M.push(G(`sending`,(0,V.jsx)(Pe,{}))):t.error&&M.push(G(`send-error`,t.error,{tone:`error`}));let N=(0,V.jsx)(Q,{});if(m||!y&&c.length>0&&t.busy)N=(0,V.jsx)(Q,{placeholder:j(`run.working`)});else if(!y)M.push(X(`now:${n.id}:go`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>C(o),children:n.cta||j(`run.next`)}),S?(0,V.jsx)(Z,{onClick:S,disabled:t.busy,children:j(`run.back`)}):null]})));else{let r=Ie(y),i=!y.required&&y.kind!==`connection`&&y.kind!==`list`?(0,V.jsx)(Z,{onClick:()=>A(void 0),children:j(`chat.skip`)}):null;if(r===`typed`){i&&M.push(X(`now:${n.id}:${y.id}:replies`,i));let e=o[y.id];N=(0,V.jsx)(Me,{children:(0,V.jsx)(Fe,{initial:Le(e)?``:String(e),multiline:y.kind===`textarea`,placeholder:y.placeholder||(b?y.label:j(`chat.placeholder`)),inputProps:Je(y),busy:t.busy,onSend:e=>A(ze(y,e))},y.id)})}else if(r===`tapped`)M.push(G(`now:${n.id}:${y.id}:replies`,(0,V.jsx)(Ye,{field:y,view:e,value:o[y.id],onAnswer:A}),{bare:!0}));else{let e=_.filter(e=>!c.includes(e.id)).length===1;M.push(X(`now:${n.id}:${y.id}:replies`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,disabled:f,onClick:()=>A(o[y.id]),children:e&&n.cta?n.cta:j(`chat.send`)}),i]})))}}return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:M}),N]})}function Je(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 A(e)}}function Ye({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[a,o]=(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:j(`run.no`)}),(0,V.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:j(`run.yes`)})]});let s=e.options??[];return e.kind===`multiselect`?(0,V.jsxs)(Y,{children:[s.map(e=>(0,V.jsx)(Z,{on:a.includes(e),onClick:()=>o(t=>t.includes(e)?t.filter(t=>t!==e):s.filter(n=>n===e||t.includes(n))),children:e},e)),(0,V.jsx)(Z,{primary:!0,disabled:e.required&&!a.length,onClick:()=>r(a),children:a.length||e.required?j(`chat.send`):j(`chat.skip`)})]}):(0,V.jsxs)(Y,{children:[s.map(e=>(0,V.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:e},e)),e.required?null:(0,V.jsx)(Z,{onClick:()=>r(void 0),children:j(`chat.skip`)})]})}function Xe({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(),[r,i]=(0,B.useState)(Date.now());(0,B.useEffect)(()=>{let e=setInterval(()=>i(Date.now()),1e3);return()=>clearInterval(e)},[]);let a=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),s=a.at(-1),l=[...a].reverse().find(Qe),u=[...new Set(a.map(e=>e.asset).filter(e=>!!e))];return(0,V.jsxs)(`div`,{className:v(`flex max-w-full flex-col gap-1`,l?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??j(`run.working`),children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(Pe,{}),(0,V.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??j(`run.working`)}),(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:j(`run.elapsed`,{s:Math.max(0,Math.round((r-n)/1e3))})})]}),s&&s!==l?(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(c,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,V.jsx)(`span`,{className:`truncate`,children:o(s)})]}):null,l&&e.status===`running`?(0,V.jsx)(et,{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:ee(`/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 Ze=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function Qe(e){return!!e.note&&Ze.has(e.note.code)}var $e=1e4;function et({runId:e,event:t}){let[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(`agent`),[s,c]=(0,B.useState)(!1),l=t.note?.code;if((0,B.useEffect)(()=>{l===`personDrives`?a(`person`):l===`agentDrives`&&a(`agent`)},[l]),(0,B.useEffect)(()=>{let t=()=>M.get(`/api/runs/${e}/browser/seat`).then(e=>a(e.seat)).catch(()=>void 0);if(t(),i!==`person`)return;let n=setInterval(t,$e);return()=>clearInterval(n)},[e,i]),n!==null&&n>=t.id)return null;let u=i===`person`,d=async()=>{c(!0);try{let t=await M.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});a(t.seat)}catch{}finally{c(!1)}};return(0,V.jsx)(C,{runId:e,driving:u,caption:o(t),hint:j(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,V.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void d(),className:v(`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)(ge,{className:`size-3.5`}):(0,V.jsx)(me,{className:`size-3.5`}),j(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 tt({view:e,run:t,step:n,before:i,asked:o,onNote:s}){let c=e.shown.filter(e=>e.output),[l,u]=(0,B.useState)(c.length===1?c[0].step.id:null),d=(0,B.useRef)(null),p=[...i,...o.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}),...c.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)(a,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{u(t.id),d.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)(r,{runId:e.id,list:t}):(0,V.jsx)(f,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&p.push(G(`review-error`,t.error,{tone:`error`}));let m=n.regenerate&&c.length>0;return p.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)(S,{className:`size-4`}),` `,j(`run.accept`)]}),m&&c.length>1?c.map(({step:e})=>(0,V.jsx)(Z,{on:l===e.id,onClick:()=>u(e.id),children:e.title},e.id)):null]}))),(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:p}),m?(0,V.jsx)(Me,{children:(0,V.jsx)(Fe,{multiline:!0,inputRef:d,busy:t.busy,placeholder:c.length>1&&!l?j(`run.feedbackPick`):j(`run.feedbackPlaceholder`),disabled:!l,onSend:e=>{let r=e.trim();return!r||!l?!1:(s(r),t.regenerate(n.id,l,r),!0)}})}):(0,V.jsx)(Q,{})]})}function nt({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)(_,{base:s,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,V.jsx)(a,{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:j(`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)(k,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,V.jsx)(f,{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)(ce,{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)(d,{className:`size-4`}),` `,j(`run.again`)]}):null,e.canBack?(0,V.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:j(`run.back`)}):null,e.keeps?(0,V.jsx)(`span`,{className:`ml-1`,children:(0,V.jsx)(m,{runId:e.id})}):null]}))),(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:c})}function rt({runId:e,onRestart:t,onView:n,header:r,footer:a,talk:o=!1,call:s=!1}){let c=fe(e),{view:l}=c,[u,f]=(0,B.useState)(null),p=ke(e,l,c,u);(0,B.useEffect)(()=>{n?.(l)},[l,n]);let[m,h]=oe(),g=(0,B.useMemo)(()=>({runId:e,lang:l?.lang??i,readAloud:m,setReadAloud:h,voice:l?.talk?p:null,talk:o,call:!!s,bindPage:f}),[e,l?.lang,l?.talk,m,h,p,o,s]);F(l?.status===`running`&&!l.ask),R(l);let[_,v]=(0,B.useState)({}),[y,b]=(0,B.useState)(null);(0,B.useEffect)(()=>{l&&l.status!==`running`&&b(null)},[l]);let S;if(c.notFound)S=(0,V.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:j(`run.notFound`)});else if(!l)S=(0,V.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,V.jsx)(T,{})});else{let e=l.step,n=l.status===`waiting_input`,r=Ge(l,l.canBack&&n&&!c.busy?()=>void c.back():void 0);if(l.status===`running`&&l.ask)S=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,V.jsx)(O,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,V.jsx)(Q,{})]});else if(l.status===`running`)S=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...y?[K(`note`,y)]:[],G(`working:${e?.id}`,(0,V.jsx)(Xe,{view:l}),{wide:l.events.some(t=>t.stepId===e?.id&&Qe(t))?`most`:void 0})]}),(0,V.jsx)(Q,{placeholder:j(`run.working`)})]});else if(l.status===`failed`)S=(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:j(`run.failed`)}),l.error?(0,V.jsx)(`span`,{className:`mt-0.5 block`,children:(0,V.jsx)(x,{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)(d,{className:`size-4`}),` `,j(`run.retry`)]}),l.canBack?(0,V.jsx)(Z,{onClick:()=>void c.back(),disabled:c.busy,children:j(`run.back`)}):null]}))]}),(0,V.jsx)(Q,{})]});else if(l.status===`cancelled`)S=(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,j(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,V.jsxs)(Z,{primary:!0,onClick:t,children:[(0,V.jsx)(d,{className:`size-4`}),` `,j(`run.again`)]}))]:[]]});else if(e?.type===`page`)S=(0,V.jsx)(qe,{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(`|`);S=(0,V.jsx)(tt,{view:l,run:c,step:e,before:r,asked:_[e.id]??[],onNote:t=>{b(t),v(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else S=e?.type===`result`?(0,V.jsx)(nt,{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:g,children:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,V.jsx)(Te,{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)(Ne,{footer:a,children:S})})]})}):(0,V.jsx)(q.Provider,{value:g,children:(0,V.jsx)(Ne,{header:r,footer:a,children:S})})}export{J as a,Z as i,Ne as n,X as o,Q as r,je as s,rt as t};