wizards 0.2.45 → 0.2.47

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 (70) hide show
  1. package/apps/runtime/dist/app.js +34 -1
  2. package/apps/runtime/dist/cli/features.js +50 -0
  3. package/apps/runtime/dist/cli/main.js +12 -2
  4. package/apps/runtime/dist/cli/report.js +81 -0
  5. package/apps/runtime/dist/debug.js +196 -0
  6. package/apps/runtime/dist/features.js +123 -0
  7. package/apps/runtime/dist/harness/model.js +2 -0
  8. package/apps/runtime/dist/index.js +3 -0
  9. package/apps/runtime/dist/log.js +106 -0
  10. package/apps/runtime/dist/manage.js +13 -0
  11. package/apps/runtime/dist/plugins/discovery.js +11 -0
  12. package/apps/runtime/dist/plugins/loader.js +10 -0
  13. package/apps/runtime/dist/routes/debug.js +42 -0
  14. package/apps/runtime/dist/routes/internal.js +21 -5
  15. package/apps/runtime/dist/routes/runs.js +1 -1
  16. package/apps/runtime/dist/routes/studio.js +7 -5
  17. package/apps/runtime/dist/tenants/control.js +7 -0
  18. package/apps/web/dist/assets/{AboutDialog-Dx_ged8B.js → AboutDialog-t7bpiasT.js} +1 -1
  19. package/apps/web/dist/assets/{ChangelogDialog-CbEGxGZG.js → ChangelogDialog-B87yS6aN.js} +1 -1
  20. package/apps/web/dist/assets/{ChatView-DZm3GK6k.js → ChatView-Dm764bYy.js} +4 -4
  21. package/apps/web/dist/assets/EditorPage-BG_Ue2iC.js +3 -0
  22. package/apps/web/dist/assets/{FlowPreview-t7hVutQM.js → FlowPreview-ChXfiMn_.js} +1 -1
  23. package/apps/web/dist/assets/{Harness-DnUFOVKn.js → Harness-zKMptCzB.js} +2 -2
  24. package/apps/web/dist/assets/HomePage-BXSg5P5k.js +1 -0
  25. package/apps/web/dist/assets/{Marketplace-SLjncUHh.js → Marketplace-BWhUJ4UX.js} +2 -2
  26. package/apps/web/dist/assets/{NewWizardPage-D24mz6nu.js → NewWizardPage-C3NqEGmg.js} +1 -1
  27. package/apps/web/dist/assets/ProjectPage-D6Fy7uTV.js +2 -0
  28. package/apps/web/dist/assets/PublicRunner-ChgJs0C9.js +1 -0
  29. package/apps/web/dist/assets/{ReadOnly-BokOQXGX.js → ReadOnly-C9P9aiU6.js} +1 -1
  30. package/apps/web/dist/assets/{RunDrawer-BLxTUquf.js → RunDrawer-CvIKLphz.js} +3 -3
  31. package/apps/web/dist/assets/RunnerView-Bmayop7s.js +2 -0
  32. package/apps/web/dist/assets/SettingsPage-QkwtRFoD.js +1 -0
  33. package/apps/web/dist/assets/SetupPage-B3IOQLO3.js +1 -0
  34. package/apps/web/dist/assets/{SharePage-D30PD4st.js → SharePage-C3QEzicl.js} +1 -1
  35. package/apps/web/dist/assets/ThemeSwitch-3IzIOlNz.js +1 -0
  36. package/apps/web/dist/assets/arrow-right-Dpp_mpHe.js +1 -0
  37. package/apps/web/dist/assets/changelog-Du2gWzlN.js +1 -0
  38. package/apps/web/dist/assets/{circle-alert-DmnHyrXp.js → circle-alert-CPo3Naay.js} +1 -1
  39. package/apps/web/dist/assets/{definition-TTirPrTQ.js → definition-CQGiBQ4X.js} +1 -1
  40. package/apps/web/dist/assets/{external-link-CbsKNS8Z.js → external-link-CpU8aJY2.js} +1 -1
  41. package/apps/web/dist/assets/index-Cz6c1S5g.js +78 -0
  42. package/apps/web/dist/assets/{lock-CjhgdsXt.js → lock-C_WlXIQ0.js} +1 -1
  43. package/apps/web/dist/assets/{refresh-cw-Obopmbfz.js → refresh-cw-Cli5WGnW.js} +1 -1
  44. package/apps/web/dist/assets/{session-OPJXuQ-4.js → session-miDEdw2c.js} +1 -1
  45. package/apps/web/dist/assets/{settings-menu-Dme1HWda.js → settings-menu-ROT8Lbbj.js} +1 -1
  46. package/apps/web/dist/assets/{sparkles-DQnR0qxG.js → sparkles-CP5H-O1E.js} +1 -1
  47. package/apps/web/dist/assets/{trash-CDGh6DEg.js → trash-DU-hZpV0.js} +1 -1
  48. package/apps/web/dist/assets/ui-D92EkdEB.js +9 -0
  49. package/apps/web/dist/assets/{upload-BzfKj43F.js → upload-DMq5N6Fw.js} +1 -1
  50. package/apps/web/dist/assets/{volume-2-Dca_TstC.js → volume-2-0SfkvOho.js} +1 -1
  51. package/apps/web/dist/index.html +10 -10
  52. package/apps/web/dist/mcp/flow.html +41 -41
  53. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +21 -0
  54. package/node_modules/@engenty-wizards/shared/dist/feature-flags.d.ts +54 -0
  55. package/node_modules/@engenty-wizards/shared/dist/feature-flags.js +46 -0
  56. package/node_modules/@engenty-wizards/shared/dist/features.d.ts +36 -0
  57. package/node_modules/@engenty-wizards/shared/dist/features.js +78 -0
  58. package/package.json +1 -1
  59. package/apps/web/dist/assets/EditorPage-DYmr37s6.js +0 -3
  60. package/apps/web/dist/assets/HomePage-BtDteNOG.js +0 -1
  61. package/apps/web/dist/assets/ProjectPage-BrJp7tGj.js +0 -2
  62. package/apps/web/dist/assets/PublicRunner-c3A01WoK.js +0 -1
  63. package/apps/web/dist/assets/RunnerView-BCXVgQJg.js +0 -2
  64. package/apps/web/dist/assets/SettingsPage-CUZcrDWr.js +0 -1
  65. package/apps/web/dist/assets/SetupPage-DVM5r96i.js +0 -1
  66. package/apps/web/dist/assets/ThemeSwitch-BeoISyt6.js +0 -1
  67. package/apps/web/dist/assets/arrow-right-BeQQ3XNo.js +0 -1
  68. package/apps/web/dist/assets/changelog-CpOw96D-.js +0 -1
  69. package/apps/web/dist/assets/index-C67UNafO.js +0 -78
  70. package/apps/web/dist/assets/ui-BJwZ9JV4.js +0 -9
@@ -1,10 +1,10 @@
1
- import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{t as r}from"./react-dom-DenslgJm.js";import{A as i,C as a,G as o,I as s,N as c,R as l,W as u,_ as d,f,g as p,j as m,k as h,l as g,o as _,q as v,x as y,z as b}from"./ui-BJwZ9JV4.js";import{_ as x,a as S,c as C,d as w,f as T,g as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,u as F,v as I}from"./RunnerView-BCXVgQJg.js";import{t as L}from"./sparkles-DQnR0qxG.js";import{n as R,t as ee}from"./volume-2-Dca_TstC.js";import{O as z,S as B,g as te,o as ne}from"./definition-TTirPrTQ.js";import{T as re,b as ie,f as ae,h as oe}from"./index-C67UNafO.js";var se={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`}]]};se.node;var ce=v(se),le={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};le.node;var ue=v(le),de={name:`phone-off`,size:24,node:[[`path`,{d:`M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272`,key:`1wngk7`}],[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}],[`path`,{d:`M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473`,key:`10hv5p`}]]};de.node;var fe=v(de),pe={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`}]]};pe.node;var me=v(pe),he={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`}]]};he.node;var ge=v(he),_e={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`}]]};_e.node;var ve=v(_e),ye=r(),V=e(t(),1),be=`wz.readAloud`,H=typeof window<`u`&&`speechSynthesis`in window&&`SpeechSynthesisUtterance`in window;function xe(){try{return localStorage.getItem(be)===`1`}catch{return!1}}function Se(e){try{localStorage.setItem(be,e?`1`:`0`)}catch{}}function Ce(e){let t=window.speechSynthesis.getVoices(),n=e.slice(0,2);return t.find(t=>t.lang===e&&t.default)??t.find(t=>t.lang===e)??t.find(e=>e.lang.startsWith(n)&&e.default)??t.find(e=>e.lang.startsWith(n))??null}function we(e,t=m,n=!1){if(!H||!e.trim())return;let r=window.speechSynthesis;n&&r.cancel();let i=t===`de`?`de-DE`:`en-US`,a=new SpeechSynthesisUtterance(e.trim().slice(0,2e3));a.lang=i;let o=Ce(i);o&&(a.voice=o),r.speak(a)}function Te(){H&&window.speechSynthesis.cancel()}function Ee(){let[e,t]=(0,V.useState)(()=>H&&xe()),n=(0,V.useCallback)(e=>{t(e),Se(e),e||Te()},[]);return(0,V.useEffect)(()=>{H&&window.speechSynthesis.getVoices()},[]),(0,V.useEffect)(()=>()=>Te(),[]),[e,n]}function De(e,t,n,r){let i=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!e){i.current=null;return}let a=n.map(e=>e.key);if(!i.current){i.current=new Set(a);let e=[...n].reverse().find(e=>e.who===`bot`&&e.spoken!==!1);if(e){let n=r(e.key);n&&we(n,t,!0)}return}let o=n.filter(e=>!i.current?.has(e.key));for(let e of a)i.current.add(e);o.some(e=>e.who===`me`)&&Te();for(let e of o)if(e.who===`bot`&&e.spoken!==!1){let n=r(e.key);n&&we(n,t)}},[e,t,n,r])}var U=e(n(),1),Oe=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function ke({since:e}){let[t,n]=(0,V.useState)(Date.now());if((0,V.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),!e)return null;let r=Math.max(0,Math.floor((t-e)/1e3)),i=String(Math.floor(r/60)).padStart(2,`0`),a=String(r%60).padStart(2,`0`);return(0,U.jsxs)(`span`,{className:`font-mono text-[0.8125rem] text-white/60 tabular-nums`,children:[i,`:`,a]})}function W({label:e,on:t,danger:n,busy:r,onClick:i,children:a}){return(0,U.jsx)(`button`,{type:`button`,"aria-label":e,title:e,"aria-pressed":t,disabled:r,onClick:i,className: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,U.jsx)(f,{className:`size-5`}):a})}function Ae({voice:e}){let t=(0,V.useRef)(null),{captions:n}=e;return(0,V.useEffect)(()=>{n.length&&t.current?.scrollIntoView({block:`end`})},[n]),n.length?(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 sm:px-5`,children:(0,U.jsxs)(`ol`,{className:`mx-auto flex max-w-[720px] flex-col gap-2 py-2`,children:[n.map(e=>(0,U.jsx)(`li`,{className:d(`text-[0.9375rem] leading-snug`,e.who===`bot`?`text-white/95`:`text-right text-white/50`),children:e.text},e.id)),(0,U.jsx)(`div`,{ref:t})]})}):null}function je({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,a=e.state===`connecting`,[o,s]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1);(0,V.useEffect)(()=>{s(i?Date.now():null)},[i]);let p=async()=>{u(!1),await e.start(),n&&await e.startCamera()},m=()=>{e.stop(),u(!0)},h=n||e.camera,g=[...e.captions].reverse().find(e=>e.who===`bot`),_=[...e.captions].reverse().find(e=>e.who===`me`),v=e.speaking?c(`talk.speaking`):e.listening?c(`talk.listening`):i?c(`talk.live`):a?c(`talk.connecting`):l?c(`video.ended`):``;return(0,U.jsxs)(`section`,{className:d(`relative flex min-h-0 flex-col bg-neutral-950 text-white`,`safe-top`,r),children:[(0,U.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4 sm:px-5`,children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1rem] tracking-tight`,children:t?.wizard.title??``}),v?(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,U.jsx)(`span`,{className:d(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,v]}):null,(0,U.jsx)(ke,{since:o})]}),(0,U.jsxs)(`div`,{className:d(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,h?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!h&&i&&e.captions.length?`h-[38%]`:h?``:`flex-1`),children:[(0,U.jsxs)(`div`,{className:d(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!h&&`hidden`),children:[(0,U.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,U.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/50`,children:[(0,U.jsx)(ge,{className:`size-8`}),(0,U.jsx)(`span`,{className:`text-[0.8125rem]`,children:c(`video.cameraOff`)})]}),(0,U.jsxs)(`span`,{className:`absolute bottom-2 left-3 rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:[c(`video.you`),e.muted?(0,U.jsx)(ue,{className:`ml-1.5 inline size-3`}):null]})]}),(0,U.jsxs)(`div`,{className:d(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,h?`bg-neutral-900`:`bg-transparent`,h&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,U.jsx)(`div`,{className:d(`rounded-full transition-shadow duration-500`,!h&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!h&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,U.jsx)(z,{kind:t?.wizard.avatar??`round`,size:h?140:200,fluffy:!0,interactive:!1})}),h?(0,U.jsx)(`span`,{className:`absolute bottom-2 left-3 max-w-[85%] truncate rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:t?.wizard.title??``}):null]})]}),i&&!h?(0,U.jsx)(Ae,{voice:e}):i&&(g||_)?(0,U.jsx)(`div`,{className:`shrink-0 px-4 pb-2 sm:px-5`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-[720px] space-y-1 text-center`,children:[_?(0,U.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:_.text}):null,g?(0,U.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:g.text}):null]})}):null,e.error?(0,U.jsx)(`p`,{className:`shrink-0 px-5 pb-2 text-center text-[0.8125rem] text-rose`,children:e.error}):null,(0,U.jsx)(`div`,{className:`flex shrink-0 items-center justify-center gap-3 px-4 pt-1 pb-4`,children:i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(W,{label:c(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,U.jsx)(ue,{className:`size-5`}):(0,U.jsx)(b,{className:`size-5`})}),(0,U.jsx)(W,{label:c(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,U.jsx)(R,{className:`size-5`}):(0,U.jsx)(ge,{className:`size-5`})}),e.camera&&Oe?(0,U.jsx)(W,{label:c(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,U.jsx)(k,{className:`size-5`})}):null,(0,U.jsx)(W,{label:c(`video.leave`),danger:!0,onClick:m,children:(0,U.jsx)(fe,{className:`size-5`})})]}):(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:a||!t?.talk,onClick:()=>void p(),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,U.jsx)(f,{className:`size-4`}):n?(0,U.jsx)(R,{className:`size-5`}):(0,U.jsx)(b,{className:`size-5`}),c(l?`video.rejoin`:n?`video.join`:`talk.start`)]}),!l&&!e.error?(0,U.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:c(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var Me=e=>ne[e.kind]!==`device`,Ne=1024,Pe=4e3;function Fe(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function Ie(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: ${i(t)}`),r.join(`
1
+ import{a as e,n as t,t as n}from"./jsx-runtime-D3jfb0Ew.js";import{t as r}from"./react-dom-DenslgJm.js";import{A as i,B as a,C as o,G as s,J as c,K as l,L as u,M as d,P as f,_ as p,f as m,g as h,j as g,l as _,o as v,x as y,z as b}from"./ui-D92EkdEB.js";import{_ as x,a as S,c as C,d as w,f as T,g as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,u as F,v as I}from"./RunnerView-Bmayop7s.js";import{t as L}from"./sparkles-CP5H-O1E.js";import{n as R,t as ee}from"./volume-2-0SfkvOho.js";import{O as z,S as B,g as te,o as ne}from"./definition-CQGiBQ4X.js";import{T as re,b as ie,f as ae,h as oe}from"./index-Cz6c1S5g.js";var se={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`}]]};se.node;var ce=c(se),le={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};le.node;var ue=c(le),de={name:`phone-off`,size:24,node:[[`path`,{d:`M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272`,key:`1wngk7`}],[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}],[`path`,{d:`M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473`,key:`10hv5p`}]]};de.node;var fe=c(de),pe={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`}]]};pe.node;var me=c(pe),he={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`}]]};he.node;var ge=c(he),_e={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`}]]};_e.node;var ve=c(_e),ye=r(),V=e(t(),1),be=`wz.readAloud`,H=typeof window<`u`&&`speechSynthesis`in window&&`SpeechSynthesisUtterance`in window;function xe(){try{return localStorage.getItem(be)===`1`}catch{return!1}}function Se(e){try{localStorage.setItem(be,e?`1`:`0`)}catch{}}function Ce(e){let t=window.speechSynthesis.getVoices(),n=e.slice(0,2);return t.find(t=>t.lang===e&&t.default)??t.find(t=>t.lang===e)??t.find(e=>e.lang.startsWith(n)&&e.default)??t.find(e=>e.lang.startsWith(n))??null}function we(e,t=d,n=!1){if(!H||!e.trim())return;let r=window.speechSynthesis;n&&r.cancel();let i=t===`de`?`de-DE`:`en-US`,a=new SpeechSynthesisUtterance(e.trim().slice(0,2e3));a.lang=i;let o=Ce(i);o&&(a.voice=o),r.speak(a)}function Te(){H&&window.speechSynthesis.cancel()}function Ee(){let[e,t]=(0,V.useState)(()=>H&&xe()),n=(0,V.useCallback)(e=>{t(e),Se(e),e||Te()},[]);return(0,V.useEffect)(()=>{H&&window.speechSynthesis.getVoices()},[]),(0,V.useEffect)(()=>()=>Te(),[]),[e,n]}function De(e,t,n,r){let i=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!e){i.current=null;return}let a=n.map(e=>e.key);if(!i.current){i.current=new Set(a);let e=[...n].reverse().find(e=>e.who===`bot`&&e.spoken!==!1);if(e){let n=r(e.key);n&&we(n,t,!0)}return}let o=n.filter(e=>!i.current?.has(e.key));for(let e of a)i.current.add(e);o.some(e=>e.who===`me`)&&Te();for(let e of o)if(e.who===`bot`&&e.spoken!==!1){let n=r(e.key);n&&we(n,t)}},[e,t,n,r])}var U=e(n(),1),Oe=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function ke({since:e}){let[t,n]=(0,V.useState)(Date.now());if((0,V.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),!e)return null;let r=Math.max(0,Math.floor((t-e)/1e3)),i=String(Math.floor(r/60)).padStart(2,`0`),a=String(r%60).padStart(2,`0`);return(0,U.jsxs)(`span`,{className:`font-mono text-[0.8125rem] text-white/60 tabular-nums`,children:[i,`:`,a]})}function W({label:e,on:t,danger:n,busy:r,onClick:i,children:a}){return(0,U.jsx)(`button`,{type:`button`,"aria-label":e,title:e,"aria-pressed":t,disabled:r,onClick:i,className:p(`flex size-12 items-center justify-center rounded-full transition disabled:opacity-50`,n?`bg-rose text-white hover:brightness-110`:t===!1?`bg-white text-neutral-900 hover:bg-white/90`:`bg-white/15 text-white hover:bg-white/25`),children:r?(0,U.jsx)(m,{className:`size-5`}):a})}function Ae({voice:e}){let t=(0,V.useRef)(null),{captions:n}=e;return(0,V.useEffect)(()=>{n.length&&t.current?.scrollIntoView({block:`end`})},[n]),n.length?(0,U.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 sm:px-5`,children:(0,U.jsxs)(`ol`,{className:`mx-auto flex max-w-[720px] flex-col gap-2 py-2`,children:[n.map(e=>(0,U.jsx)(`li`,{className:p(`text-[0.9375rem] leading-snug`,e.who===`bot`?`text-white/95`:`text-right text-white/50`),children:e.text},e.id)),(0,U.jsx)(`div`,{ref:t})]})}):null}function je({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,o=e.state===`connecting`,[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1);(0,V.useEffect)(()=>{c(i?Date.now():null)},[i]);let d=async()=>{u(!1),await e.start(),n&&await e.startCamera()},h=()=>{e.stop(),u(!0)},g=n||e.camera,_=[...e.captions].reverse().find(e=>e.who===`bot`),v=[...e.captions].reverse().find(e=>e.who===`me`),y=e.speaking?f(`talk.speaking`):e.listening?f(`talk.listening`):i?f(`talk.live`):o?f(`talk.connecting`):l?f(`video.ended`):``;return(0,U.jsxs)(`section`,{className:p(`relative flex min-h-0 flex-col bg-neutral-950 text-white`,`safe-top`,r),children:[(0,U.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4 sm:px-5`,children:[(0,U.jsx)(`div`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1rem] tracking-tight`,children:t?.wizard.title??``}),y?(0,U.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,U.jsx)(`span`,{className:p(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,y]}):null,(0,U.jsx)(ke,{since:s})]}),(0,U.jsxs)(`div`,{className:p(`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&&i&&e.captions.length?`h-[38%]`:g?``:`flex-1`),children:[(0,U.jsxs)(`div`,{className:p(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!g&&`hidden`),children:[(0,U.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:p(`absolute inset-0 h-full w-full object-cover`,e.facing===`user`&&`-scale-x-100`,e.camera?`block`:`hidden`)}),e.camera?null:(0,U.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/50`,children:[(0,U.jsx)(ge,{className:`size-8`}),(0,U.jsx)(`span`,{className:`text-[0.8125rem]`,children:f(`video.cameraOff`)})]}),(0,U.jsxs)(`span`,{className:`absolute bottom-2 left-3 rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:[f(`video.you`),e.muted?(0,U.jsx)(ue,{className:`ml-1.5 inline size-3`}):null]})]}),(0,U.jsxs)(`div`,{className:p(`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,U.jsx)(`div`,{className:p(`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,U.jsx)(z,{kind:t?.wizard.avatar??`round`,size:g?140:200,fluffy:!0,interactive:!1})}),g?(0,U.jsx)(`span`,{className:`absolute bottom-2 left-3 max-w-[85%] truncate rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:t?.wizard.title??``}):null]})]}),i&&!g?(0,U.jsx)(Ae,{voice:e}):i&&(_||v)?(0,U.jsx)(`div`,{className:`shrink-0 px-4 pb-2 sm:px-5`,children:(0,U.jsxs)(`div`,{className:`mx-auto max-w-[720px] space-y-1 text-center`,children:[v?(0,U.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:v.text}):null,_?(0,U.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:_.text}):null]})}):null,e.error?(0,U.jsx)(`p`,{className:`shrink-0 px-5 pb-2 text-center text-[0.8125rem] text-rose`,children:e.error}):null,(0,U.jsx)(`div`,{className:`flex shrink-0 items-center justify-center gap-3 px-4 pt-1 pb-4`,children:i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(W,{label:f(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,U.jsx)(ue,{className:`size-5`}):(0,U.jsx)(a,{className:`size-5`})}),(0,U.jsx)(W,{label:f(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,U.jsx)(R,{className:`size-5`}):(0,U.jsx)(ge,{className:`size-5`})}),e.camera&&Oe?(0,U.jsx)(W,{label:f(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,U.jsx)(k,{className:`size-5`})}):null,(0,U.jsx)(W,{label:f(`video.leave`),danger:!0,onClick:h,children:(0,U.jsx)(fe,{className:`size-5`})})]}):(0,U.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,U.jsxs)(`button`,{type:`button`,disabled:o||!t?.talk,onClick:()=>void d(),className:`flex h-12 items-center gap-2 rounded-full bg-emerald-500 px-6 font-medium text-[0.9375rem] text-white transition hover:brightness-110 disabled:opacity-50`,children:[o?(0,U.jsx)(m,{className:`size-4`}):n?(0,U.jsx)(R,{className:`size-5`}):(0,U.jsx)(a,{className:`size-5`}),f(l?`video.rejoin`:n?`video.join`:`talk.start`)]}),!l&&!e.error?(0,U.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:f(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var Me=e=>ne[e.kind]!==`device`,Ne=1024,Pe=4e3;function Fe(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function Ie(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: ${g(t)}`),r.join(`
3
3
  `)}if(e.status===`done`){r.push(`done. made:`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.title}: ${Fe(n?.text,400)||`(a file, on the screen)`}`);return r.join(`
4
4
  `)}if(e.status===`failed`)return r.push(`failed: ${e.error??``}; go_back or the person retries on the screen`),r.join(`
5
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=Me(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?` = ${Fe(String(Array.isArray(n)?n.join(`, `):n),120)}`:` = (open)`}`)}return r.join(`
6
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}": ${Fe(n?.text,600)||`(a picture or file, on the screen)`}`);return r.push(`regenerate allowed: ${e.step.regenerate?`yes`:`no`}`),r.join(`
7
7
  `)}return r.push(`step: ${e.step?.title??``}`),r.join(`
8
- `)}function Le(e,t,n,r){let[i,o]=(0,V.useState)(`off`),[s,l]=(0,V.useState)(null),[u,d]=(0,V.useState)(!1),[f,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(`environment`),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)([]),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=(0,V.useRef)(0),T=(0,V.useRef)(!1);T.current=m;let E=(0,V.useRef)(null),D=(0,V.useRef)(null),O=(0,V.useRef)(null),k=(0,V.useRef)(null),A=(0,V.useRef)(t);A.current=t;let j=(0,V.useRef)(r);j.current=r;let M=(0,V.useRef)(n);M.current=n;let N=(0,V.useRef)(``),P=(0,V.useCallback)(e=>{let t=D.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,V.useCallback)(()=>{let e=S.current;if(!T.current||!e||e.videoWidth===0)return null;let t=Math.min(1,Ne/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,V.useCallback)(()=>{for(let e of C.current?.getTracks()??[])e.stop();C.current=null,S.current&&(S.current.srcObject=null),h(!1)},[]),L=(0,V.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;_(n===`user`||n===`environment`?n:t),S.current&&(S.current.srcObject=e,await S.current.play().catch(()=>void 0)),h(!0)}catch(e){l(e.name===`NotAllowedError`?c(`talk.cameraDenied`):e.message)}},[]),R=(0,V.useCallback)(async()=>{let e=g===`user`?`environment`:`user`;I(),await L(e)},[g,I,L]),ee=(0,V.useCallback)(()=>{y(e=>{for(let t of k.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),z=(0,V.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=``,d(!1),p(!1),y(!1),o(`off`)},[I]);(0,V.useEffect)(()=>()=>z(),[z]);let B=(0,V.useCallback)(async(t,n)=>{let r=A.current,i=j.current,o=M.current;switch(t){case`get_state`:return r?Ie(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(),o=new File([n],`photo-${Date.now()}.jpg`,{type:`image/jpeg`}),s=await a.upload(`/api/runs/${e}/uploads`,o),c=i.values[t.id],l=t.multiple?[...Array.isArray(c)?c:c?[c]:[],s.id]:s.id,u=i.setField(t.id,l);return u?`refused: ${u}`:`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&&Me(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 o.accept(r.step.id)?`accepted`:o.error??`refused`:`no review is open`;case`regenerate`:return r?.step?.type===`review`?await o.regenerate(r.step.id,String(n.target??``),String(n.note??``))?`the wizard makes it again; wait`:o.error??`refused`:`no review is open`;case`answer_ask`:if(!r?.ask)return`no question is open`;try{return await a.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 o.back()?`went back; wait for the state`:o.error??`refused`;default:return`unknown tool ${t}`}},[e,F,P]),te=(0,V.useCallback)(async()=>{if(!E.current){l(null),x([]),o(`connecting`);try{let t=await a.post(`/api/runs/${e}/talk`),n=await navigator.mediaDevices.getUserMedia({audio:!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`:d(!0);break;case`output_audio_buffer.stopped`:case`output_audio_buffer.cleared`:d(!1);break;case`input_audio_buffer.speech_started`:{p(!0);let e=Date.now()-w.current>Pe?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`:p(!1);break;case`response.output_audio_transcript.done`:case`conversation.item.input_audio_transcription.completed`:{let e=String(t.transcript??``).trim();if(e){let n=t.type===`response.output_audio_transcript.done`?`bot`:`me`;x(t=>[...t.slice(-199),{id:`${Date.now()}:${n}`,who:n,text:e}])}break}case`response.function_call_arguments.done`:{let e=String(t.name??``),n=String(t.call_id??``),r={};try{r=JSON.parse(String(t.arguments??`{}`))}catch{}B(e,r).then(e=>{P({type:`conversation.item.create`,item:{type:`function_call_output`,call_id:n,output:e}}),P({type:`response.create`})});break}case`error`:l(String(t.error?.message??`error`))}},s.onopen=()=>{o(`live`);let e=A.current;e&&(N.current=Ie(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 u=await r.createOffer();await r.setLocalDescription(u);let f=await fetch(t.endpoint,{method:`POST`,headers:{authorization:`Bearer ${t.clientSecret}`,"content-type":`application/sdp`},body:u.sdp});if(!f.ok)throw Error(`${c(`talk.failed`)} (${f.status})`);await r.setRemoteDescription({type:`answer`,sdp:await f.text()})}catch(e){z(),l(e.name===`NotAllowedError`?c(`chat.micDenied`):e.message),o(`error`)}}},[e,B,F,P,z]);return(0,V.useEffect)(()=>{if(i!==`live`||!t)return;let e=Ie(t,r,m);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(`
8
+ `)}function Le(e,t,n,r){let[i,a]=(0,V.useState)(`off`),[s,c]=(0,V.useState)(null),[l,u]=(0,V.useState)(!1),[d,p]=(0,V.useState)(!1),[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(`environment`),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)([]),S=(0,V.useRef)(null),C=(0,V.useRef)(null),w=(0,V.useRef)(0),T=(0,V.useRef)(!1);T.current=m;let E=(0,V.useRef)(null),D=(0,V.useRef)(null),O=(0,V.useRef)(null),k=(0,V.useRef)(null),A=(0,V.useRef)(t);A.current=t;let j=(0,V.useRef)(r);j.current=r;let M=(0,V.useRef)(n);M.current=n;let N=(0,V.useRef)(``),P=(0,V.useCallback)(e=>{let t=D.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,V.useCallback)(()=>{let e=S.current;if(!T.current||!e||e.videoWidth===0)return null;let t=Math.min(1,Ne/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,V.useCallback)(()=>{for(let e of C.current?.getTracks()??[])e.stop();C.current=null,S.current&&(S.current.srcObject=null),h(!1)},[]),L=(0,V.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;_(n===`user`||n===`environment`?n:t),S.current&&(S.current.srcObject=e,await S.current.play().catch(()=>void 0)),h(!0)}catch(e){c(e.name===`NotAllowedError`?f(`talk.cameraDenied`):e.message)}},[]),R=(0,V.useCallback)(async()=>{let e=g===`user`?`environment`:`user`;I(),await L(e)},[g,I,L]),ee=(0,V.useCallback)(()=>{y(e=>{for(let t of k.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),z=(0,V.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),p(!1),y(!1),a(`off`)},[I]);(0,V.useEffect)(()=>()=>z(),[z]);let B=(0,V.useCallback)(async(t,n)=>{let r=A.current,i=j.current,a=M.current;switch(t){case`get_state`:return r?Ie(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`}),s=await o.upload(`/api/runs/${e}/uploads`,a),c=i.values[t.id],l=t.multiple?[...Array.isArray(c)?c:c?[c]:[],s.id]:s.id,u=i.setField(t.id,l);return u?`refused: ${u}`:`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&&Me(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 o.post(`/api/runs/${e}/ask/${r.ask.id}`,{type:n.allow?`done`:`skip`}),n.allow?`allowed`:`skipped`}catch(e){return`refused: ${e.message}`}case`go_back`:return await a.back()?`went back; wait for the state`:a.error??`refused`;default:return`unknown tool ${t}`}},[e,F,P]),te=(0,V.useCallback)(async()=>{if(!E.current){c(null),x([]),a(`connecting`);try{let t=await o.post(`/api/runs/${e}/talk`),n=await navigator.mediaDevices.getUserMedia({audio:!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`:{p(!0);let e=Date.now()-w.current>Pe?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`:p(!1);break;case`response.output_audio_transcript.done`:case`conversation.item.input_audio_transcription.completed`:{let e=String(t.transcript??``).trim();if(e){let n=t.type===`response.output_audio_transcript.done`?`bot`:`me`;x(t=>[...t.slice(-199),{id:`${Date.now()}:${n}`,who:n,text:e}])}break}case`response.function_call_arguments.done`:{let e=String(t.name??``),n=String(t.call_id??``),r={};try{r=JSON.parse(String(t.arguments??`{}`))}catch{}B(e,r).then(e=>{P({type:`conversation.item.create`,item:{type:`function_call_output`,call_id:n,output:e}}),P({type:`response.create`})});break}case`error`:c(String(t.error?.message??`error`))}},s.onopen=()=>{a(`live`);let e=A.current;e&&(N.current=Ie(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(`${f(`talk.failed`)} (${d.status})`);await r.setRemoteDescription({type:`answer`,sdp:await d.text()})}catch(e){z(),c(e.name===`NotAllowedError`?f(`chat.micDenied`):e.message),a(`error`)}}},[e,B,F,P,z]);return(0,V.useEffect)(()=>{if(i!==`live`||!t)return;let e=Ie(t,r,m);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
9
  `)[1]!==e.split(`
10
- `)[1])&&P({type:`response.create`})},[i,t,r,m,P]),{state:i,error:s,speaking:u,listening:f,start:te,stop:z,camera:m,facing:g,startCamera:L,stopCamera:I,flipCamera:R,muted:v,toggleMute:ee,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}),Re=(0,V.createContext)(null),q=(0,V.createContext)(null);function ze(){return(0,V.useContext)(q)?.voice??null}function Be({children:e}){let t=(0,V.useContext)(Re);return t?(0,ye.createPortal)(e,t):null}function Ve({header:e,footer:t,children:n}){let[r,i]=(0,V.useState)(null),a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=(0,V.useRef)(!0);return(0,V.useLayoutEffect)(()=>{let e=a.current,t=o.current;if(!e||!t)return;let n=e.scrollTop,r=()=>{e.scrollHeight-e.scrollTop-e.clientHeight<120?s.current=!0:e.scrollTop<n&&(s.current=!1),n=e.scrollTop},i=null,c=new ResizeObserver(()=>{let r=t.querySelector(`[data-anchor]`);r&&r!==i?(i=r,e.scrollTop+=r.getBoundingClientRect().top-e.getBoundingClientRect().top-12,s.current=!1,n=e.scrollTop):s.current&&(e.scrollTop=e.scrollHeight)});return e.scrollTop=e.scrollHeight,e.addEventListener(`scroll`,r,{passive:!0}),c.observe(t),c.observe(e),()=>{c.disconnect(),e.removeEventListener(`scroll`,r)}},[]),(0,U.jsx)(Re.Provider,{value:r,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[e,(0,U.jsx)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,U.jsx)(`div`,{ref:o,className:`mx-auto flex w-full max-w-[760px] flex-col gap-3 px-3 pt-5 pb-4 sm:px-6`,children:n})}),(0,U.jsxs)(`div`,{className:`shrink-0 border-border-soft border-t bg-background`,onPointerDownCapture:()=>{s.current=!0},onKeyDownCapture:()=>{s.current=!0},children:[(0,U.jsx)(`div`,{ref:i,className:`mx-auto w-full max-w-[760px] px-3 pt-3 sm:px-6`}),t]})]})})}function J({avatar:e,lines:t}){let n=(0,V.useContext)(q),r=(0,V.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),i=(0,V.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);De(!!n?.readAloud,n?.lang??m,r,i);let a=[];for(let e of t){let t=a.at(-1);t&&t.who===`bot`&&e.who===`bot`?t.lines.push(e):a.push({who:e.who,lines:[e]})}return a.map((t,n)=>t.who===`bot`?(0,U.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,U.jsx)(`div`,{className:`sticky top-1 shrink-0 pt-0.5`,children:(0,U.jsx)(z,{kind:e,size:30,interactive:n>=a.length-2})}),(0,U.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:t.lines.map(e=>(0,U.jsx)(`div`,{"data-anchor":e.anchor?``:void 0,"data-say":e.key,className: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,U.jsxs)(`div`,{className:`flex animate-rise flex-col items-end gap-1 pl-10`,children:[(0,U.jsx)(`div`,{className:`max-w-[min(32rem,100%)] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-primary px-4 py-2.5 text-[0.9375rem] text-primary-foreground leading-relaxed`,children:e.node}),e.onEdit?(0,U.jsxs)(`button`,{type:`button`,onClick:e.onEdit,className:`inline-flex items-center gap-1 px-1 text-[0.75rem] text-ink-4 transition hover:text-ink-2 coarse:min-h-9`,children:[(0,U.jsx)(I,{className:`size-3`}),` `,c(`chat.change`)]}):null]},e.key)))}function He(){return(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":c(`run.working`),children:[0,1,2].map(e=>(0,U.jsx)(`span`,{className:`size-1.5 animate-typing rounded-full bg-ink-3`,style:{animationDelay:`${e*160}ms`}},e))})}function Y({children:e}){return(0,U.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}var X=(e,t)=>G(e,(0,U.jsx)(Y,{children:t}),{bare:!0});function Z({onClick:e,children:t,primary:n,on:r,disabled:i,busy:a}){return(0,U.jsxs)(`button`,{type:`button`,"aria-pressed":r,disabled:i||a,onClick:e,className: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,U.jsx)(f,{className:`size-4`}):null,t]})}function Ue({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:a,inputRef:l,onSend:u}){let[m,h]=(0,V.useState)(e),g=(0,V.useRef)(null),v=l??g,S=(0,V.useContext)(q),C=y(m,h,{endpoint:S?`/api/runs/${S.runId}/transcribe`:void 0}),w=!!S&&C.supported&&!a;(0,V.useEffect)(()=>{if(!w)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),C.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,C.toggle]),(0,V.useEffect)(()=>{!ie&&!a&&v.current?.focus()},[a,v]);let T=()=>{i||a||(C.listening&&C.toggle(),u(m)!==!1&&h(``))},E=C.listening?c(`chat.listening`):C.processing?c(`chat.transcribing`):t,D=S?.voice??null,O=!!S?.call,k=S&&!O&&(H||w||D)?(0,U.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[D?(0,U.jsx)(_,{label:c(D.state===`live`?`talk.stop`:D.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":D.state===`live`,disabled:D.state===`connecting`,onClick:()=>D.state===`live`?D.stop():void D.start(),className:d(`size-9`,D.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,D.state===`off`&&S.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:D.state===`connecting`?(0,U.jsx)(f,{className:`size-4`}):D.state===`live`?(0,U.jsx)(fe,{className:`size-4`}):(0,U.jsx)(x,{className:`size-4`})}):null,D?.state===`live`?(0,U.jsx)(_,{label:c(D.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":D.camera,onClick:()=>D.camera?D.stopCamera():void D.startCamera(),className:d(`size-9`,D.camera&&`text-ink`),children:D.camera?(0,U.jsx)(R,{className:`size-4`}):(0,U.jsx)(ge,{className:`size-4`})}):null,H?(0,U.jsx)(_,{label:c(S.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":S.readAloud,onClick:()=>S.setReadAloud(!S.readAloud),className:d(`size-9`,S.readAloud&&`text-ink`),children:S.readAloud?(0,U.jsx)(ee,{className:`size-4`}):(0,U.jsx)(ve,{className:`size-4`})}):null,w?(0,U.jsx)(_,{label:c(C.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":C.listening,disabled:C.processing,onClick:C.toggle,className:d(`size-9`,C.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:C.processing?(0,U.jsx)(f,{className:`size-4`}):C.listening?(0,U.jsx)(s,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,U.jsx)(b,{className:`size-4`})}):null]}):null;return(0,U.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),T()},children:[D&&!O?(0,U.jsx)(`video`,{ref:D.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`,D.camera?`block`:`hidden`)}):null,(0,U.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`,a&&`opacity-60`),children:[k,n?(0,U.jsx)(p,{ref:v,minRows:1,maxRows:6,value:m,disabled:a,placeholder:E,autoCapitalize:`sentences`,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!ie&&!e.nativeEvent.isComposing&&(e.preventDefault(),T())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,U.jsx)(`input`,{ref:v,...r,value:m,disabled:a,placeholder:E,enterKeyHint:`send`,onChange:e=>h(e.target.value),className:`h-11 min-w-0 flex-1 bg-transparent px-3 text-[0.9375rem] text-ink outline-none placeholder:text-ink-4`}),(0,U.jsx)(`button`,{type:`submit`,"aria-label":c(`chat.send`),title:c(`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,U.jsx)(f,{className:`size-4`}):(0,U.jsx)(o,{className:`size-4`})})]}),C.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:C.error===`denied`?c(`chat.micDenied`):C.error}):O?null:D?.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:D.error}):D?.state===`live`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:D.speaking?c(`talk.speaking`):D.listening?c(`talk.listening`):c(`talk.live`)}):S?.talk&&D?.state===`off`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:c(`talk.hint`)}):null]})}function Q({placeholder:e=c(`chat.above`)}){return(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{disabled:!0,placeholder:e,onSend:()=>!1})})}function We(e){let t=ne[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Ge=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Ke(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Ge(t))return e.required&&!n?c(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return c(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return c(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?c(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?c(`run.filesMin`,{n:t.length,min:e.min}):null}function qe(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 Je({field:e}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.label}),e.help?(0,U.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.help}):null]})}function Ye({step:e,only:t}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.title}),e.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:e.description}):null,t?.help?(0,U.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:t.help}):null]})}function Xe({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,U.jsx)(U.Fragment,{children:typeof t==`string`&&t?t:c(`chat.connected`)});if(e.kind===`list`)return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(u,{className:`size-4`}),` `,c(`chat.checked`)]});if(e.kind===`toggle`)return(0,U.jsx)(U.Fragment,{children:c(t===!0?`run.yes`:`run.no`)});if(Ge(t))return(0,U.jsx)(`span`,{className:`italic opacity-80`,children:c(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,U.jsx)(U.Fragment,{children:t.join(`, `)});case`date`:{let e=new Date(`${String(t)}T00:00`);return(0,U.jsx)(U.Fragment,{children:Number.isNaN(e.getTime())?String(t):new Intl.DateTimeFormat(m,{dateStyle:`long`}).format(e)})}case`color`:return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`size-4 rounded-full ring-1 ring-white/50`,style:{background:String(t)}}),String(t)]});case`image`:case`signature`:return(0,U.jsx)(`span`,{className:`-mx-1.5 flex flex-wrap gap-1.5`,children:(Array.isArray(t)?t:[String(t)]).map(t=>(0,U.jsx)(`img`,{src:h(`/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,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(l,{className:`size-4`}),` `,c(e===1?`chat.file`:`chat.files`,{n:e})]})}case`audio`:{let e=t.seconds;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(b,{className:`size-4`}),` `,c(`chat.voice`),e?` · ${Math.round(e)} s`:``]})}case`location`:{let e=t;return(0,U.jsx)(U.Fragment,{children:e.label||`${e.lat?.toFixed(5)}, ${e.lng?.toFixed(5)}`})}case`items`:return(0,U.jsx)(U.Fragment,{children:c(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,U.jsx)(U.Fragment,{children:String(t)})}}function Ze(e,t,n,r,i,a){let o=[G(t,(0,U.jsx)(Ye,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,U.jsx)(Je,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,U.jsx)(Xe,{field:e,value:n[e.id],runId:r})));return o}var Qe=(e,t)=>e.fields.filter(e=>!e.when&&!te(e)||t[e.id]!==void 0&&t[e.id]!==null);function $e(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(...Ze(r,i,e.values,e.id,Qe(r,e.values),t))}else r.type===`review`&&(n.push(G(i,(0,U.jsx)(`span`,{className:`font-medium`,children:r.title}))),n.push(K(`${i}:a`,c(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function et(e,t){return e.fields.filter(e=>!te(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function tt({view:e,run:t,step:n,before:r}){let i=(0,V.useMemo)(()=>et(n,e),[n,e]),a=e.known??{},[o,s]=(0,V.useState)(()=>A(n,e)),[l,u]=(0,V.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?B(et(n,e),e.known??{},A(n,e)).slice(0,-1).map(e=>e.id):[]),[d,f]=(0,V.useState)({}),[p,m]=(0,V.useState)(!1),[h,g]=(0,V.useState)(!1),_=B(i,a,o),v=_.filter(e=>l.includes(e.id)),y=_.find(e=>!l.includes(e.id)),b=i.length===1?i[0]:void 0,x=v.at(-1),C=x?()=>u(e=>e.filter(e=>e!==x.id)):void 0;(0,V.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=B(i,a,o),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(g)},T=(0,V.useContext)(q),E=(0,V.useRef)(o);E.current=o;let D=T?.bindPage,O=(0,V.useRef)(w);O.current=w,(0,V.useEffect)(()=>{if(!D)return;let e=B(i,a,o);return D({step:n,fields:e,values:o,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Ke(r,n)||(s(e=>({...e,[t]:n})),u(e=>e.includes(t)?e:[...e,t]),f({}),null):`no such field on this page`},submit:()=>O.current(E.current)}),()=>D(null)},[D,n,i,a,o]);let k=e=>{if(!y)return!1;let t=Ke(y,e);if(t)return f({[y.id]:t}),!1;let n={...o,[y.id]:e},r=[...l,y.id];return s(n),u(r),f({}),B(i,a,n).some(e=>!r.includes(e.id))||w(n),!0},j=[...r.map(e=>l.length?{...e,onEdit:void 0}:e),...Ze(n,`now:${n.id}`,o,e.id,v,b).map((e,t,n)=>t===n.length-1&&e.who===`me`&&y?{...e,onEdit:C}:e)];y?(We(y)===`control`?j.push(G(`now:${n.id}:${y.id}:control`,(0,U.jsx)(S,{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:m}),{wide:!0})):b||j.push(G(`now:${n.id}:${y.id}`,(0,U.jsx)(Je,{field:y}))),d[y.id]&&j.push(G(`now:${n.id}:${y.id}:error`,d[y.id],{tone:`error`}))):t.busy||h?j.push(G(`sending`,(0,U.jsx)(He,{}))):t.error&&j.push(G(`send-error`,t.error,{tone:`error`}));let M=(0,U.jsx)(Q,{});if(h||!y&&l.length>0&&t.busy)M=(0,U.jsx)(Q,{placeholder:c(`run.working`)});else if(!y)j.push(X(`now:${n.id}:go`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>w(o),children:n.cta||c(`run.next`)}),C?(0,U.jsx)(Z,{onClick:C,disabled:t.busy,children:c(`run.back`)}):null]})));else{let r=We(y),i=!y.required&&y.kind!==`connection`&&y.kind!==`list`?(0,U.jsx)(Z,{onClick:()=>k(void 0),children:c(`chat.skip`)}):null;if(r===`typed`){i&&j.push(X(`now:${n.id}:${y.id}:replies`,i));let e=o[y.id];M=(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{initial:Ge(e)?``:String(e),multiline:y.kind===`textarea`,placeholder:y.placeholder||(b?y.label:c(`chat.placeholder`)),inputProps:nt(y),busy:t.busy,onSend:e=>k(qe(y,e))},y.id)})}else if(r===`tapped`)j.push(G(`now:${n.id}:${y.id}:replies`,(0,U.jsx)(rt,{field:y,view:e,value:o[y.id],onAnswer:k}),{bare:!0}));else{let e=_.filter(e=>!l.includes(e.id)).length===1;j.push(X(`now:${n.id}:${y.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,disabled:p,onClick:()=>k(o[y.id]),children:e&&n.cta?n.cta:c(`chat.send`)}),i]})))}}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:j}),M]})}function nt(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 j(e)}}function rt({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[a,o]=(0,V.useState)(Array.isArray(n)?n:[]);if(e.kind===`toggle`)return(0,U.jsxs)(Y,{children:[(0,U.jsx)(Z,{on:n===!1,disabled:i.has(`false`),onClick:()=>r(!1),children:c(`run.no`)}),(0,U.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:c(`run.yes`)})]});let s=e.options??[];return e.kind===`multiselect`?(0,U.jsxs)(Y,{children:[s.map(e=>(0,U.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,U.jsx)(Z,{primary:!0,disabled:e.required&&!a.length,onClick:()=>r(a),children:a.length||e.required?c(`chat.send`):c(`chat.skip`)})]}):(0,U.jsxs)(Y,{children:[s.map(e=>(0,U.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:e},e)),e.required?null:(0,U.jsx)(Z,{onClick:()=>r(void 0),children:c(`chat.skip`)})]})}function it({view:e}){let t=(0,V.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,a]=(0,V.useState)(Date.now());(0,V.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},[]);let o=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),s=o.at(-1),l=[...o].reverse().find(ot),u=[...new Set(o.map(e=>e.asset).filter(e=>!!e))];return(0,U.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??c(`run.working`),children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(He,{}),(0,U.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??c(`run.working`)}),(0,U.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:c(`run.elapsed`,{s:Math.max(0,Math.round((r-n)/1e3))})})]}),s&&s!==l?(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,U.jsx)(L,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,U.jsx)(`span`,{className:`truncate`,children:i(s)})]}):null,l&&e.status===`running`?(0,U.jsx)(ct,{runId:e.id,event:l}):null,u.length?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:u.slice(-6).map(t=>(0,U.jsx)(`img`,{src:h(`/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 at=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function ot(e){return!!e.note&&at.has(e.note.code)}var st=1e4;function ct({runId:e,event:t}){let[n,r]=(0,V.useState)(null),[o,s]=(0,V.useState)(`agent`),[l,u]=(0,V.useState)(!1),f=t.note?.code;if((0,V.useEffect)(()=>{f===`personDrives`?s(`person`):f===`agentDrives`&&s(`agent`)},[f]),(0,V.useEffect)(()=>{let t=()=>a.get(`/api/runs/${e}/browser/seat`).then(e=>s(e.seat)).catch(()=>void 0);if(t(),o!==`person`)return;let n=setInterval(t,st);return()=>clearInterval(n)},[e,o]),n!==null&&n>=t.id)return null;let p=o===`person`,m=async()=>{u(!0);try{let t=await a.post(`/api/runs/${e}/browser/seat`,{to:p?`agent`:`person`});s(t.seat)}catch{}finally{u(!1)}};return(0,U.jsx)(T,{runId:e,driving:p,caption:i(t),hint:c(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,U.jsxs)(`button`,{type:`button`,disabled:l,onClick:()=>void m(),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`,p?`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:[p?(0,U.jsx)(me,{className:`size-3.5`}):(0,U.jsx)(ce,{className:`size-3.5`}),c(p?`browser.handBack`:`browser.takeOver`)]})},n??0)}function $({children:e,end:t}){return(0,U.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`h3`,{className:`font-display font-semibold text-[1rem]`,children:e}),t]})}function lt({view:e,run:t,step:n,before:r,asked:i,onNote:a}){let o=e.shown.filter(e=>e.output),[s,l]=(0,V.useState)(o.length===1?o[0].step.id:null),d=(0,V.useRef)(null),f=[...r,...i.map((e,t)=>K(`review:${n.id}:asked:${t}`,e)),G(`review:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:n.title}),n.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.description}):null]}),{anchor:!0}),...o.map(({step:t,output:r})=>G(`review:${n.id}:${t.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.title}),(0,U.jsx)(oe,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{l(t.id),d.current?.focus()}:void 0})]}),{wide:!0})),...e.lists.map(t=>G(`review:${n.id}:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.def.title}),t.def.check?(0,U.jsx)(P,{runId:e.id,list:t}):(0,U.jsx)(O,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&f.push(G(`review-error`,t.error,{tone:`error`}));let p=n.regenerate&&o.length>0;return f.push(X(`review:${n.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:t.busy,onClick:()=>void t.accept(n.id),children:[(0,U.jsx)(u,{className:`size-4`}),` `,c(`run.accept`)]}),p&&o.length>1?o.map(({step:e})=>(0,U.jsx)(Z,{on:s===e.id,onClick:()=>l(e.id),children:e.title},e.id)):null]}))),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:f}),p?(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{multiline:!0,inputRef:d,busy:t.busy,placeholder:o.length>1&&!s?c(`run.feedbackPick`):c(`run.feedbackPlaceholder`),disabled:!s,onSend:e=>{let r=e.trim();return!r||!s?!1:(a(r),t.regenerate(n.id,s,r),!0)}})}):(0,U.jsx)(Q,{})]})}function ut({view:e,run:t,step:n,before:r,onRestart:i}){let a=e.shown.filter(e=>e.output),o=`/api/runs/${e.id}`,s=[...r,G(`result:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem]`,children:n.title}),n.message?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.message}):null]}),{anchor:!0}),...a.map(({step:e,output:t,formats:n,label:r})=>G(`result:${e.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(ae,{base:o,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,U.jsx)(oe,{base:o,step:e,output:t}),t?.assets?.some(e=>e.ai)?(0,U.jsx)(`p`,{className:`mt-3 text-[0.75rem] text-ink-3 leading-relaxed`,children:c(`ai.publish`)}):null]}),{wide:!0})),...e.lists.map(t=>G(`result:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(C,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,U.jsx)(O,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return s.push(X(`result:replies`,(0,U.jsxs)(U.Fragment,{children:[a.length?(0,U.jsx)(M,{runId:e.id,title:`${n.title} · ${e.wizard.title}`,initial:e.shareUrl?{url:e.shareUrl,expiresAt:e.expiresAt}:null}):null,i?(0,U.jsxs)(Z,{onClick:i,children:[(0,U.jsx)(E,{className:`size-4`}),` `,c(`run.again`)]}):null,e.canBack?(0,U.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:c(`run.back`)}):null,e.keeps?(0,U.jsx)(`span`,{className:`ml-1`,children:(0,U.jsx)(F,{runId:e.id})}):null]}))),(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:s})}function dt({runId:e,onRestart:t,onView:n,header:r,footer:i,talk:a=!1,call:o=!1}){let s=D(e),{view:l}=s,[u,d]=(0,V.useState)(null),p=Le(e,l,s,u);(0,V.useEffect)(()=>{n?.(l)},[l,n]);let[h,_]=Ee(),v=(0,V.useMemo)(()=>({runId:e,lang:l?.lang??m,readAloud:h,setReadAloud:_,voice:l?.talk?p:null,talk:a,call:!!o,bindPage:d}),[e,l?.lang,l?.talk,h,_,p,a,o]);re(l?.status===`running`&&!l.ask),N(l);let[y,b]=(0,V.useState)({}),[x,S]=(0,V.useState)(null);(0,V.useEffect)(()=>{l&&l.status!==`running`&&S(null)},[l]);let C;if(s.notFound)C=(0,U.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:c(`run.notFound`)});else if(!l)C=(0,U.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,U.jsx)(f,{})});else{let e=l.step,n=l.status===`waiting_input`,r=$e(l,l.canBack&&n&&!s.busy?()=>void s.back():void 0);if(l.status===`running`&&l.ask)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,U.jsx)(w,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,U.jsx)(Q,{})]});else if(l.status===`running`)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...x?[K(`note`,x)]:[],G(`working:${e?.id}`,(0,U.jsx)(it,{view:l}),{wide:l.events.some(t=>t.stepId===e?.id&&ot(t))?`most`:void 0})]}),(0,U.jsx)(Q,{placeholder:c(`run.working`)})]});else if(l.status===`failed`)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`failed`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:c(`run.failed`)}),l.error?(0,U.jsx)(`span`,{className:`mt-0.5 block`,children:(0,U.jsx)(g,{text:l.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:s.busy,onClick:()=>void s.retry(),children:[(0,U.jsx)(E,{className:`size-4`}),` `,c(`run.retry`)]}),l.canBack?(0,U.jsx)(Z,{onClick:()=>void s.back(),disabled:s.busy,children:c(`run.back`)}):null]}))]}),(0,U.jsx)(Q,{})]});else if(l.status===`cancelled`)C=(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,c(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,U.jsxs)(Z,{primary:!0,onClick:t,children:[(0,U.jsx)(E,{className:`size-4`}),` `,c(`run.again`)]}))]:[]]});else if(e?.type===`page`)C=(0,U.jsx)(tt,{view:l,run:s,step:e,before:r},e.id);else if(e?.type===`review`){let t=l.shown.map(e=>e.output?.at??``).join(`|`);C=(0,U.jsx)(lt,{view:l,run:s,step:e,before:r,asked:y[e.id]??[],onNote:t=>{S(t),b(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else C=e?.type===`result`?(0,U.jsx)(ut,{view:l,run:s,step:e,before:r,onRestart:t}):(0,U.jsx)(J,{avatar:l.wizard.avatar,lines:r})}return o?(0,U.jsx)(q.Provider,{value:v,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,U.jsx)(je,{voice:p,view:l,video:o===`video`,className:`h-[46dvh] shrink-0 lg:h-auto lg:min-h-0 lg:flex-1`}),(0,U.jsx)(`aside`,{className:`flex min-h-0 flex-1 flex-col border-border-soft border-t lg:w-[420px] lg:flex-none lg:border-t-0 lg:border-l`,children:(0,U.jsx)(Ve,{footer:i,children:C})})]})}):(0,U.jsx)(q.Provider,{value:v,children:(0,U.jsx)(Ve,{header:r,footer:i,children:C})})}export{J as a,Z as i,Ve as n,X as o,Q as r,ze as s,dt as t};
10
+ `)[1])&&P({type:`response.create`})},[i,t,r,m,P]),{state:i,error:s,speaking:l,listening:d,start:te,stop:z,camera:m,facing:g,startCamera:L,stopCamera:I,flipCamera:R,muted:v,toggleMute:ee,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}),Re=(0,V.createContext)(null),q=(0,V.createContext)(null);function ze(){return(0,V.useContext)(q)?.voice??null}function Be({children:e}){let t=(0,V.useContext)(Re);return t?(0,ye.createPortal)(e,t):null}function Ve({header:e,footer:t,children:n}){let[r,i]=(0,V.useState)(null),a=(0,V.useRef)(null),o=(0,V.useRef)(null),s=(0,V.useRef)(!0);return(0,V.useLayoutEffect)(()=>{let e=a.current,t=o.current;if(!e||!t)return;let n=e.scrollTop,r=()=>{e.scrollHeight-e.scrollTop-e.clientHeight<120?s.current=!0:e.scrollTop<n&&(s.current=!1),n=e.scrollTop},i=null,c=new ResizeObserver(()=>{let r=t.querySelector(`[data-anchor]`);r&&r!==i?(i=r,e.scrollTop+=r.getBoundingClientRect().top-e.getBoundingClientRect().top-12,s.current=!1,n=e.scrollTop):s.current&&(e.scrollTop=e.scrollHeight)});return e.scrollTop=e.scrollHeight,e.addEventListener(`scroll`,r,{passive:!0}),c.observe(t),c.observe(e),()=>{c.disconnect(),e.removeEventListener(`scroll`,r)}},[]),(0,U.jsx)(Re.Provider,{value:r,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[e,(0,U.jsx)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,U.jsx)(`div`,{ref:o,className:`mx-auto flex w-full max-w-[760px] flex-col gap-3 px-3 pt-5 pb-4 sm:px-6`,children:n})}),(0,U.jsxs)(`div`,{className:`shrink-0 border-border-soft border-t bg-background`,onPointerDownCapture:()=>{s.current=!0},onKeyDownCapture:()=>{s.current=!0},children:[(0,U.jsx)(`div`,{ref:i,className:`mx-auto w-full max-w-[760px] px-3 pt-3 sm:px-6`}),t]})]})})}function J({avatar:e,lines:t}){let n=(0,V.useContext)(q),r=(0,V.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),i=(0,V.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);De(!!n?.readAloud,n?.lang??d,r,i);let a=[];for(let e of t){let t=a.at(-1);t&&t.who===`bot`&&e.who===`bot`?t.lines.push(e):a.push({who:e.who,lines:[e]})}return a.map((t,n)=>t.who===`bot`?(0,U.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,U.jsx)(`div`,{className:`sticky top-1 shrink-0 pt-0.5`,children:(0,U.jsx)(z,{kind:e,size:30,interactive:n>=a.length-2})}),(0,U.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:t.lines.map(e=>(0,U.jsx)(`div`,{"data-anchor":e.anchor?``:void 0,"data-say":e.key,className:p(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?p(`w-full bg-card p-4 shadow-soft ring-1 ring-border-soft`,e.wide===`most`&&`md:w-4/5`):`max-w-[min(36rem,100%)] bg-card px-4 py-2.5 shadow-soft ring-1 ring-border-soft`),e.tone===`error`&&`bg-rose-tint text-rose shadow-none ring-0`),children:e.node},e.key))})]},t.lines[0].key):t.lines.map(e=>(0,U.jsxs)(`div`,{className:`flex animate-rise flex-col items-end gap-1 pl-10`,children:[(0,U.jsx)(`div`,{className:`max-w-[min(32rem,100%)] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-primary px-4 py-2.5 text-[0.9375rem] text-primary-foreground leading-relaxed`,children:e.node}),e.onEdit?(0,U.jsxs)(`button`,{type:`button`,onClick:e.onEdit,className:`inline-flex items-center gap-1 px-1 text-[0.75rem] text-ink-4 transition hover:text-ink-2 coarse:min-h-9`,children:[(0,U.jsx)(I,{className:`size-3`}),` `,f(`chat.change`)]}):null]},e.key)))}function He(){return(0,U.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":f(`run.working`),children:[0,1,2].map(e=>(0,U.jsx)(`span`,{className:`size-1.5 animate-typing rounded-full bg-ink-3`,style:{animationDelay:`${e*160}ms`}},e))})}function Y({children:e}){return(0,U.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}var X=(e,t)=>G(e,(0,U.jsx)(Y,{children:t}),{bare:!0});function Z({onClick:e,children:t,primary:n,on:r,disabled:i,busy:a}){return(0,U.jsxs)(`button`,{type:`button`,"aria-pressed":r,disabled:i||a,onClick:e,className:p(`inline-flex h-10 items-center gap-1.5 rounded-full px-4 font-medium text-[0.875rem] transition active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 coarse:h-11`,n?`bg-primary text-primary-foreground hover:brightness-[1.06]`:r?`bg-ember-tint text-ink ring-1 ring-ember`:`bg-card text-ink-2 ring-1 ring-input hover:text-ink hover:ring-ink-4`),children:[a?(0,U.jsx)(m,{className:`size-4`}):null,t]})}function Ue({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:o,inputRef:s,onSend:c}){let[d,g]=(0,V.useState)(e),_=(0,V.useRef)(null),b=s??_,S=(0,V.useContext)(q),C=y(d,g,{endpoint:S?`/api/runs/${S.runId}/transcribe`:void 0}),w=!!S&&C.supported&&!o;(0,V.useEffect)(()=>{if(!w)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),C.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,C.toggle]),(0,V.useEffect)(()=>{!ie&&!o&&b.current?.focus()},[o,b]);let T=()=>{i||o||(C.listening&&C.toggle(),c(d)!==!1&&g(``))},E=C.listening?f(`chat.listening`):C.processing?f(`chat.transcribing`):t,D=S?.voice??null,O=!!S?.call,k=S&&!O&&(H||w||D)?(0,U.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[D?(0,U.jsx)(v,{label:f(D.state===`live`?`talk.stop`:D.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":D.state===`live`,disabled:D.state===`connecting`,onClick:()=>D.state===`live`?D.stop():void D.start(),className:p(`size-9`,D.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,D.state===`off`&&S.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:D.state===`connecting`?(0,U.jsx)(m,{className:`size-4`}):D.state===`live`?(0,U.jsx)(fe,{className:`size-4`}):(0,U.jsx)(x,{className:`size-4`})}):null,D?.state===`live`?(0,U.jsx)(v,{label:f(D.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":D.camera,onClick:()=>D.camera?D.stopCamera():void D.startCamera(),className:p(`size-9`,D.camera&&`text-ink`),children:D.camera?(0,U.jsx)(R,{className:`size-4`}):(0,U.jsx)(ge,{className:`size-4`})}):null,H?(0,U.jsx)(v,{label:f(S.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":S.readAloud,onClick:()=>S.setReadAloud(!S.readAloud),className:p(`size-9`,S.readAloud&&`text-ink`),children:S.readAloud?(0,U.jsx)(ee,{className:`size-4`}):(0,U.jsx)(ve,{className:`size-4`})}):null,w?(0,U.jsx)(v,{label:f(C.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":C.listening,disabled:C.processing,onClick:C.toggle,className:p(`size-9`,C.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:C.processing?(0,U.jsx)(m,{className:`size-4`}):C.listening?(0,U.jsx)(u,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,U.jsx)(a,{className:`size-4`})}):null]}):null;return(0,U.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),T()},children:[D&&!O?(0,U.jsx)(`video`,{ref:D.video,muted:!0,playsInline:!0,autoPlay:!0,className:p(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,D.camera?`block`:`hidden`)}):null,(0,U.jsxs)(`div`,{className:p(`flex items-end gap-1 rounded-[1.375rem] border border-input bg-card pr-1.5 pl-1 transition focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,o&&`opacity-60`),children:[k,n?(0,U.jsx)(h,{ref:b,minRows:1,maxRows:6,value:d,disabled:o,placeholder:E,autoCapitalize:`sentences`,onChange:e=>g(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!ie&&!e.nativeEvent.isComposing&&(e.preventDefault(),T())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,U.jsx)(`input`,{ref:b,...r,value:d,disabled:o,placeholder:E,enterKeyHint:`send`,onChange:e=>g(e.target.value),className:`h-11 min-w-0 flex-1 bg-transparent px-3 text-[0.9375rem] text-ink outline-none placeholder:text-ink-4`}),(0,U.jsx)(`button`,{type:`submit`,"aria-label":f(`chat.send`),title:f(`chat.send`),disabled:i||o,className:`mb-1 flex size-9 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:brightness-[1.06] disabled:opacity-40`,children:i?(0,U.jsx)(m,{className:`size-4`}):(0,U.jsx)(l,{className:`size-4`})})]}),C.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:C.error===`denied`?f(`chat.micDenied`):C.error}):O?null:D?.error?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:D.error}):D?.state===`live`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:D.speaking?f(`talk.speaking`):D.listening?f(`talk.listening`):f(`talk.live`)}):S?.talk&&D?.state===`off`?(0,U.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:f(`talk.hint`)}):null]})}function Q({placeholder:e=f(`chat.above`)}){return(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{disabled:!0,placeholder:e,onSend:()=>!1})})}function We(e){let t=ne[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Ge=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Ke(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Ge(t))return e.required&&!n?f(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return f(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return f(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?f(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?f(`run.filesMin`,{n:t.length,min:e.min}):null}function qe(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 Je({field:e}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.label}),e.help?(0,U.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.help}):null]})}function Ye({step:e,only:t}){return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:e.title}),e.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:e.description}):null,t?.help?(0,U.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:t.help}):null]})}function Xe({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,U.jsx)(U.Fragment,{children:typeof t==`string`&&t?t:f(`chat.connected`)});if(e.kind===`list`)return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(s,{className:`size-4`}),` `,f(`chat.checked`)]});if(e.kind===`toggle`)return(0,U.jsx)(U.Fragment,{children:f(t===!0?`run.yes`:`run.no`)});if(Ge(t))return(0,U.jsx)(`span`,{className:`italic opacity-80`,children:f(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,U.jsx)(U.Fragment,{children:t.join(`, `)});case`date`:{let e=new Date(`${String(t)}T00:00`);return(0,U.jsx)(U.Fragment,{children:Number.isNaN(e.getTime())?String(t):new Intl.DateTimeFormat(d,{dateStyle:`long`}).format(e)})}case`color`:return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,U.jsx)(`span`,{className:`size-4 rounded-full ring-1 ring-white/50`,style:{background:String(t)}}),String(t)]});case`image`:case`signature`:return(0,U.jsx)(`span`,{className:`-mx-1.5 flex flex-wrap gap-1.5`,children:(Array.isArray(t)?t:[String(t)]).map(t=>(0,U.jsx)(`img`,{src:i(`/api/runs/${n}/assets/${t}`),alt:``,className:p(`h-16 rounded-lg bg-white`,e.kind===`image`?`w-16 object-cover`:`object-contain px-1`)},t))});case`file`:{let e=Array.isArray(t)?t.length:1;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(b,{className:`size-4`}),` `,f(e===1?`chat.file`:`chat.files`,{n:e})]})}case`audio`:{let e=t.seconds;return(0,U.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,U.jsx)(a,{className:`size-4`}),` `,f(`chat.voice`),e?` · ${Math.round(e)} s`:``]})}case`location`:{let e=t;return(0,U.jsx)(U.Fragment,{children:e.label||`${e.lat?.toFixed(5)}, ${e.lng?.toFixed(5)}`})}case`items`:return(0,U.jsx)(U.Fragment,{children:f(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,U.jsx)(U.Fragment,{children:String(t)})}}function Ze(e,t,n,r,i,a){let o=[G(t,(0,U.jsx)(Ye,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,U.jsx)(Je,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,U.jsx)(Xe,{field:e,value:n[e.id],runId:r})));return o}var Qe=(e,t)=>e.fields.filter(e=>!e.when&&!te(e)||t[e.id]!==void 0&&t[e.id]!==null);function $e(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(...Ze(r,i,e.values,e.id,Qe(r,e.values),t))}else r.type===`review`&&(n.push(G(i,(0,U.jsx)(`span`,{className:`font-medium`,children:r.title}))),n.push(K(`${i}:a`,f(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function et(e,t){return e.fields.filter(e=>!te(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function tt({view:e,run:t,step:n,before:r}){let i=(0,V.useMemo)(()=>et(n,e),[n,e]),a=e.known??{},[o,s]=(0,V.useState)(()=>A(n,e)),[c,l]=(0,V.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?B(et(n,e),e.known??{},A(n,e)).slice(0,-1).map(e=>e.id):[]),[u,d]=(0,V.useState)({}),[p,m]=(0,V.useState)(!1),[h,g]=(0,V.useState)(!1),_=B(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),C=x?()=>l(e=>e.filter(e=>e!==x.id)):void 0;(0,V.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=B(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 w=e=>{t.submitPage(n.id,e).then(g)},T=(0,V.useContext)(q),E=(0,V.useRef)(o);E.current=o;let D=T?.bindPage,O=(0,V.useRef)(w);O.current=w,(0,V.useEffect)(()=>{if(!D)return;let e=B(i,a,o);return D({step:n,fields:e,values:o,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Ke(r,n)||(s(e=>({...e,[t]:n})),l(e=>e.includes(t)?e:[...e,t]),d({}),null):`no such field on this page`},submit:()=>O.current(E.current)}),()=>D(null)},[D,n,i,a,o]);let k=e=>{if(!y)return!1;let t=Ke(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({}),B(i,a,n).some(e=>!r.includes(e.id))||w(n),!0},j=[...r.map(e=>c.length?{...e,onEdit:void 0}:e),...Ze(n,`now:${n.id}`,o,e.id,v,b).map((e,t,n)=>t===n.length-1&&e.who===`me`&&y?{...e,onEdit:C}:e)];y?(We(y)===`control`?j.push(G(`now:${n.id}:${y.id}:control`,(0,U.jsx)(S,{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:m}),{wide:!0})):b||j.push(G(`now:${n.id}:${y.id}`,(0,U.jsx)(Je,{field:y}))),u[y.id]&&j.push(G(`now:${n.id}:${y.id}:error`,u[y.id],{tone:`error`}))):t.busy||h?j.push(G(`sending`,(0,U.jsx)(He,{}))):t.error&&j.push(G(`send-error`,t.error,{tone:`error`}));let M=(0,U.jsx)(Q,{});if(h||!y&&c.length>0&&t.busy)M=(0,U.jsx)(Q,{placeholder:f(`run.working`)});else if(!y)j.push(X(`now:${n.id}:go`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>w(o),children:n.cta||f(`run.next`)}),C?(0,U.jsx)(Z,{onClick:C,disabled:t.busy,children:f(`run.back`)}):null]})));else{let r=We(y),i=!y.required&&y.kind!==`connection`&&y.kind!==`list`?(0,U.jsx)(Z,{onClick:()=>k(void 0),children:f(`chat.skip`)}):null;if(r===`typed`){i&&j.push(X(`now:${n.id}:${y.id}:replies`,i));let e=o[y.id];M=(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{initial:Ge(e)?``:String(e),multiline:y.kind===`textarea`,placeholder:y.placeholder||(b?y.label:f(`chat.placeholder`)),inputProps:nt(y),busy:t.busy,onSend:e=>k(qe(y,e))},y.id)})}else if(r===`tapped`)j.push(G(`now:${n.id}:${y.id}:replies`,(0,U.jsx)(rt,{field:y,view:e,value:o[y.id],onAnswer:k}),{bare:!0}));else{let e=_.filter(e=>!c.includes(e.id)).length===1;j.push(X(`now:${n.id}:${y.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(Z,{primary:!0,disabled:p,onClick:()=>k(o[y.id]),children:e&&n.cta?n.cta:f(`chat.send`)}),i]})))}}return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:j}),M]})}function nt(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 j(e)}}function rt({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[a,o]=(0,V.useState)(Array.isArray(n)?n:[]);if(e.kind===`toggle`)return(0,U.jsxs)(Y,{children:[(0,U.jsx)(Z,{on:n===!1,disabled:i.has(`false`),onClick:()=>r(!1),children:f(`run.no`)}),(0,U.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:f(`run.yes`)})]});let s=e.options??[];return e.kind===`multiselect`?(0,U.jsxs)(Y,{children:[s.map(e=>(0,U.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,U.jsx)(Z,{primary:!0,disabled:e.required&&!a.length,onClick:()=>r(a),children:a.length||e.required?f(`chat.send`):f(`chat.skip`)})]}):(0,U.jsxs)(Y,{children:[s.map(e=>(0,U.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:e},e)),e.required?null:(0,U.jsx)(Z,{onClick:()=>r(void 0),children:f(`chat.skip`)})]})}function it({view:e}){let t=(0,V.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,a]=(0,V.useState)(Date.now());(0,V.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(e)},[]);let o=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),s=o.at(-1),c=[...o].reverse().find(ot),l=[...new Set(o.map(e=>e.asset).filter(e=>!!e))];return(0,U.jsxs)(`div`,{className:p(`flex max-w-full flex-col gap-1`,c?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??f(`run.working`),children:[(0,U.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,U.jsx)(He,{}),(0,U.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??f(`run.working`)}),(0,U.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:f(`run.elapsed`,{s:Math.max(0,Math.round((r-n)/1e3))})})]}),s&&s!==c?(0,U.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,U.jsx)(L,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,U.jsx)(`span`,{className:`truncate`,children:g(s)})]}):null,c&&e.status===`running`?(0,U.jsx)(ct,{runId:e.id,event:c}):null,l.length?(0,U.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:l.slice(-6).map(t=>(0,U.jsx)(`img`,{src:i(`/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 at=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function ot(e){return!!e.note&&at.has(e.note.code)}var st=1e4;function ct({runId:e,event:t}){let[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(`agent`),[s,c]=(0,V.useState)(!1),l=t.note?.code;if((0,V.useEffect)(()=>{l===`personDrives`?a(`person`):l===`agentDrives`&&a(`agent`)},[l]),(0,V.useEffect)(()=>{let t=()=>o.get(`/api/runs/${e}/browser/seat`).then(e=>a(e.seat)).catch(()=>void 0);if(t(),i!==`person`)return;let n=setInterval(t,st);return()=>clearInterval(n)},[e,i]),n!==null&&n>=t.id)return null;let u=i===`person`,d=async()=>{c(!0);try{let t=await o.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});a(t.seat)}catch{}finally{c(!1)}};return(0,U.jsx)(T,{runId:e,driving:u,caption:g(t),hint:f(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,U.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void d(),className:p(`flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[0.8125rem] shadow-soft transition-colors disabled:opacity-60`,u?`bg-primary text-primary-foreground hover:bg-primary/90`:`bg-card/90 text-ink ring-1 ring-border-soft backdrop-blur hover:bg-card`),children:[u?(0,U.jsx)(me,{className:`size-3.5`}):(0,U.jsx)(ce,{className:`size-3.5`}),f(u?`browser.handBack`:`browser.takeOver`)]})},n??0)}function $({children:e,end:t}){return(0,U.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,U.jsx)(`h3`,{className:`font-display font-semibold text-[1rem]`,children:e}),t]})}function lt({view:e,run:t,step:n,before:r,asked:i,onNote:a}){let o=e.shown.filter(e=>e.output),[c,l]=(0,V.useState)(o.length===1?o[0].step.id:null),u=(0,V.useRef)(null),d=[...r,...i.map((e,t)=>K(`review:${n.id}:asked:${t}`,e)),G(`review:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:n.title}),n.description?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.description}):null]}),{anchor:!0}),...o.map(({step:t,output:r})=>G(`review:${n.id}:${t.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.title}),(0,U.jsx)(oe,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{l(t.id),u.current?.focus()}:void 0})]}),{wide:!0})),...e.lists.map(t=>G(`review:${n.id}:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{children:t.def.title}),t.def.check?(0,U.jsx)(P,{runId:e.id,list:t}):(0,U.jsx)(O,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&d.push(G(`review-error`,t.error,{tone:`error`}));let p=n.regenerate&&o.length>0;return d.push(X(`review:${n.id}:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:t.busy,onClick:()=>void t.accept(n.id),children:[(0,U.jsx)(s,{className:`size-4`}),` `,f(`run.accept`)]}),p&&o.length>1?o.map(({step:e})=>(0,U.jsx)(Z,{on:c===e.id,onClick:()=>l(e.id),children:e.title},e.id)):null]}))),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:d}),p?(0,U.jsx)(Be,{children:(0,U.jsx)(Ue,{multiline:!0,inputRef:u,busy:t.busy,placeholder:o.length>1&&!c?f(`run.feedbackPick`):f(`run.feedbackPlaceholder`),disabled:!c,onSend:e=>{let r=e.trim();return!r||!c?!1:(a(r),t.regenerate(n.id,c,r),!0)}})}):(0,U.jsx)(Q,{})]})}function ut({view:e,run:t,step:n,before:r,onRestart:i}){let a=e.shown.filter(e=>e.output),o=`/api/runs/${e.id}`,s=[...r,G(`result:${n.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem]`,children:n.title}),n.message?(0,U.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.message}):null]}),{anchor:!0}),...a.map(({step:e,output:t,formats:n,label:r})=>G(`result:${e.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(ae,{base:o,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,U.jsx)(oe,{base:o,step:e,output:t}),t?.assets?.some(e=>e.ai)?(0,U.jsx)(`p`,{className:`mt-3 text-[0.75rem] text-ink-3 leading-relaxed`,children:f(`ai.publish`)}):null]}),{wide:!0})),...e.lists.map(t=>G(`result:list:${t.def.id}`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)($,{end:(0,U.jsx)(C,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,U.jsx)(O,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return s.push(X(`result:replies`,(0,U.jsxs)(U.Fragment,{children:[a.length?(0,U.jsx)(M,{runId:e.id,title:`${n.title} · ${e.wizard.title}`,initial:e.shareUrl?{url:e.shareUrl,expiresAt:e.expiresAt}:null}):null,i?(0,U.jsxs)(Z,{onClick:i,children:[(0,U.jsx)(E,{className:`size-4`}),` `,f(`run.again`)]}):null,e.canBack?(0,U.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:f(`run.back`)}):null,e.keeps?(0,U.jsx)(`span`,{className:`ml-1`,children:(0,U.jsx)(F,{runId:e.id})}):null]}))),(0,U.jsx)(J,{avatar:e.wizard.avatar,lines:s})}function dt({runId:e,onRestart:t,onView:n,header:r,footer:i,talk:a=!1,call:o=!1}){let s=D(e),{view:c}=s,[l,u]=(0,V.useState)(null),p=Le(e,c,s,l);(0,V.useEffect)(()=>{n?.(c)},[c,n]);let[h,g]=Ee(),v=(0,V.useMemo)(()=>({runId:e,lang:c?.lang??d,readAloud:h,setReadAloud:g,voice:c?.talk?p:null,talk:a,call:!!o,bindPage:u}),[e,c?.lang,c?.talk,h,g,p,a,o]);re(c?.status===`running`&&!c.ask),N(c);let[y,b]=(0,V.useState)({}),[x,S]=(0,V.useState)(null);(0,V.useEffect)(()=>{c&&c.status!==`running`&&S(null)},[c]);let C;if(s.notFound)C=(0,U.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:f(`run.notFound`)});else if(!c)C=(0,U.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,U.jsx)(m,{})});else{let e=c.step,n=c.status===`waiting_input`,r=$e(c,c.canBack&&n&&!s.busy?()=>void s.back():void 0);if(c.status===`running`&&c.ask)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,G(`ask:${c.ask.id}`,(0,U.jsx)(w,{runId:c.id,ask:c.ask}),{wide:!0})]}),(0,U.jsx)(Q,{})]});else if(c.status===`running`)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,...x?[K(`note`,x)]:[],G(`working:${e?.id}`,(0,U.jsx)(it,{view:c}),{wide:c.events.some(t=>t.stepId===e?.id&&ot(t))?`most`:void 0})]}),(0,U.jsx)(Q,{placeholder:f(`run.working`)})]});else if(c.status===`failed`)C=(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,G(`failed`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`span`,{className:`font-medium`,children:f(`run.failed`)}),c.error?(0,U.jsx)(`span`,{className:`mt-0.5 block`,children:(0,U.jsx)(_,{text:c.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(Z,{primary:!0,busy:s.busy,onClick:()=>void s.retry(),children:[(0,U.jsx)(E,{className:`size-4`}),` `,f(`run.retry`)]}),c.canBack?(0,U.jsx)(Z,{onClick:()=>void s.back(),disabled:s.busy,children:f(`run.back`)}):null]}))]}),(0,U.jsx)(Q,{})]});else if(c.status===`cancelled`)C=(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:[...r,G(`cancelled`,f(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,U.jsxs)(Z,{primary:!0,onClick:t,children:[(0,U.jsx)(E,{className:`size-4`}),` `,f(`run.again`)]}))]:[]]});else if(e?.type===`page`)C=(0,U.jsx)(tt,{view:c,run:s,step:e,before:r},e.id);else if(e?.type===`review`){let t=c.shown.map(e=>e.output?.at??``).join(`|`);C=(0,U.jsx)(lt,{view:c,run:s,step:e,before:r,asked:y[e.id]??[],onNote:t=>{S(t),b(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else C=e?.type===`result`?(0,U.jsx)(ut,{view:c,run:s,step:e,before:r,onRestart:t}):(0,U.jsx)(J,{avatar:c.wizard.avatar,lines:r})}return o?(0,U.jsx)(q.Provider,{value:v,children:(0,U.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,U.jsx)(je,{voice:p,view:c,video:o===`video`,className:`h-[46dvh] shrink-0 lg:h-auto lg:min-h-0 lg:flex-1`}),(0,U.jsx)(`aside`,{className:`flex min-h-0 flex-1 flex-col border-border-soft border-t lg:w-[420px] lg:flex-none lg:border-t-0 lg:border-l`,children:(0,U.jsx)(Ve,{footer:i,children:C})})]})}):(0,U.jsx)(q.Provider,{value:v,children:(0,U.jsx)(Ve,{header:r,footer:i,children:C})})}export{J as a,Z as i,Ve as n,X as o,Q as r,ze as s,dt as t};