wizards 0.3.5 → 0.3.7

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 (69) hide show
  1. package/apps/runtime/dist/agents/studio-assistant.js +285 -31
  2. package/apps/runtime/dist/agents/website.js +256 -34
  3. package/apps/runtime/dist/db/schema.js +1 -1
  4. package/apps/runtime/dist/docs/user/test-and-share.md +21 -11
  5. package/apps/runtime/dist/documents/parse.js +14 -0
  6. package/apps/runtime/dist/engine/steps.js +42 -6
  7. package/apps/runtime/dist/engine/template.js +50 -3
  8. package/apps/runtime/dist/film/project.js +54 -4
  9. package/apps/runtime/dist/routes/studio.js +52 -3
  10. package/apps/runtime/dist/services/brand.js +6 -3
  11. package/apps/runtime/dist/services/project-files.js +59 -3
  12. package/apps/runtime/dist/services/projects.js +150 -2
  13. package/apps/runtime/dist/services/wizards.js +25 -0
  14. package/apps/web/dist/assets/AboutDialog-C0dN86zd.js +1 -0
  15. package/apps/web/dist/assets/{ChangelogDialog-VEBTlC3f.js → ChangelogDialog-Cv81t7tj.js} +1 -1
  16. package/apps/web/dist/assets/ChatView-uogJ3nht.js +10 -0
  17. package/apps/web/dist/assets/EditorPage-n8YuTh6j.js +3 -0
  18. package/apps/web/dist/assets/{FlowPreview-86xWWfdk.js → FlowPreview-D4dp1MWS.js} +1 -1
  19. package/apps/web/dist/assets/{Harness-CF6H2TYJ.js → Harness-v7r0e6vK.js} +2 -2
  20. package/apps/web/dist/assets/NewWizardChannels-Be-7VhBi.js +1 -0
  21. package/apps/web/dist/assets/NewWizardPage-C8hPvrK8.js +7 -0
  22. package/apps/web/dist/assets/ProjectPage-B686ArYy.js +1 -0
  23. package/apps/web/dist/assets/PublicRunner-DeCpVfZP.js +1 -0
  24. package/apps/web/dist/assets/{ReadOnly-mhKW496R.js → ReadOnly-B-UCgnqW.js} +1 -1
  25. package/apps/web/dist/assets/RunDrawer-C6pzi8AJ.js +4 -0
  26. package/apps/web/dist/assets/{RunnerView-CTRFgyu5.js → RunnerView-Deenymq0.js} +1 -1
  27. package/apps/web/dist/assets/SettingsPage-CK6L0yEe.js +1 -0
  28. package/apps/web/dist/assets/SetupPage-9CH3qXdH.js +1 -0
  29. package/apps/web/dist/assets/SharePage-B778xUFo.js +1 -0
  30. package/apps/web/dist/assets/changelog-DCJo2mbx.js +1 -0
  31. package/apps/web/dist/assets/{circle-alert-CYs622_r.js → circle-alert-DLvC9ePT.js} +1 -1
  32. package/apps/web/dist/assets/{esm-B52LIMhP.js → esm-BJskogLD.js} +1 -1
  33. package/apps/web/dist/assets/index-D6hUM8NU.css +1 -0
  34. package/apps/web/dist/assets/index-Df6UxElH.js +12 -0
  35. package/apps/web/dist/assets/{lock-BvSWZOin.js → lock-DR7NakPn.js} +1 -1
  36. package/apps/web/dist/assets/{phone-CI2Flerg.js → phone-BORh3jfv.js} +1 -1
  37. package/apps/web/dist/assets/{settings-menu-BOOPxcJH.js → settings-menu-DV5D91TD.js} +1 -1
  38. package/apps/web/dist/assets/{ui-CMdSOoUZ.js → ui-BOCXzzHi.js} +1 -1
  39. package/apps/web/dist/assets/{upload-Cz9HgBT9.js → upload-B3yv8gsk.js} +1 -1
  40. package/apps/web/dist/index.html +3 -8
  41. package/apps/web/dist/mcp/flow.html +2 -2
  42. package/node_modules/@engenty-wizards/plugin-sdk/dist/index.d.ts +3 -3
  43. package/node_modules/@engenty-wizards/shared/dist/changes.d.ts +22 -0
  44. package/node_modules/@engenty-wizards/shared/dist/changes.js +61 -0
  45. package/node_modules/@engenty-wizards/shared/dist/definition.d.ts +8 -8
  46. package/node_modules/@engenty-wizards/shared/dist/marketplace.d.ts +1 -1
  47. package/node_modules/@engenty-wizards/shared/dist/projects.d.ts +138 -3
  48. package/node_modules/@engenty-wizards/shared/dist/projects.js +153 -4
  49. package/node_modules/@engenty-wizards/shared/dist/wizard-package.d.ts +1 -1
  50. package/package.json +1 -1
  51. package/apps/web/dist/assets/AboutDialog-D1N4-3FE.js +0 -1
  52. package/apps/web/dist/assets/ChatView-DSRUEpb6.js +0 -10
  53. package/apps/web/dist/assets/EditorPage-UkaHDklX.js +0 -3
  54. package/apps/web/dist/assets/Marketplace-C-Vz3yEk.js +0 -2
  55. package/apps/web/dist/assets/NewWizardChannels-Cc7gDitg.js +0 -1
  56. package/apps/web/dist/assets/NewWizardPage-sY5q-l99.js +0 -7
  57. package/apps/web/dist/assets/ProjectPage-iSdpJAZS.js +0 -2
  58. package/apps/web/dist/assets/PublicRunner-BgRXMUxS.js +0 -1
  59. package/apps/web/dist/assets/RunDrawer-B0gJzdxH.js +0 -4
  60. package/apps/web/dist/assets/SettingsPage-CBF8i6j6.js +0 -1
  61. package/apps/web/dist/assets/SetupPage-Fpz9aSLN.js +0 -1
  62. package/apps/web/dist/assets/SharePage-Dv3Csh4A.js +0 -1
  63. package/apps/web/dist/assets/brand-BamUjXVr.js +0 -2
  64. package/apps/web/dist/assets/changelog-ViHoNW7e.js +0 -1
  65. package/apps/web/dist/assets/index-Bdx1Qity.js +0 -11
  66. package/apps/web/dist/assets/index-CDdJDojq.css +0 -1
  67. package/apps/web/dist/assets/session-BEHF6g4Y.js +0 -1
  68. package/apps/web/dist/assets/useMutation-DKyQXgyj.js +0 -1
  69. package/apps/web/dist/assets/volume-2-CyQuz1nn.js +0 -1
@@ -0,0 +1,10 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{A as r,Dt as i,E as a,Et as o,Ft as s,It as c,J as l,Kt as u,Lt as d,M as f,Mt as p,N as m,O as h,Pt as g,S as _,Tt as v,Vt as y,Wt as b,_t as x,an as S,at as C,b as w,bt as T,dn as E,et as D,it as O,j as k,k as A,kt as j,l as M,mt as N,nt as P,rt as F,s as I,sn as L,v as ee,wt as te,x as R,z}from"./ui-BOCXzzHi.js";import{t as ne}from"./phone-BORh3jfv.js";import{$t as re,Ht as ie,It as ae,bt as oe,nn as se,t as ce,vn as le,xt as ue,yt as de}from"./index-Df6UxElH.js";import{n as fe}from"./RunnerView-Deenymq0.js";var pe={name:`hand`,size:24,node:[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]};pe.node;var me=E(pe),he={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};he.node;var ge=E(he),_e={name:`video-off`,size:24,node:[[`path`,{d:`M10.66 6H14a2 2 0 0 1 2 2v2.5l5.248-3.062A.5.5 0 0 1 22 7.87v8.196`,key:`w8jjjt`}],[`path`,{d:`M16 16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2`,key:`1xawa7`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]};_e.node;var ve=E(_e),ye={name:`volume-x`,size:24,node:[[`path`,{d:`M11 4.702a.7.7 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.7.7 0 0 0 11 19.298z`,key:`1p7khw`}],[`path`,{d:`m16.5 14.5 5-5`,key:`cul3yw`}],[`path`,{d:`m16.5 9.5 5 5`,key:`1akey5`}]]};ye.node;var be=E(ye),xe=le(),B=e(t(),1),V=e(n(),1),Se=typeof window<`u`&&window.matchMedia(`(pointer: coarse)`).matches;function Ce({since:e}){let[t,n]=(0,B.useState)(Date.now());if((0,B.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),!e)return null;let r=Math.max(0,Math.floor((t-e)/1e3)),i=String(Math.floor(r/60)).padStart(2,`0`),a=String(r%60).padStart(2,`0`);return(0,V.jsxs)(`span`,{className:`font-mono text-[0.8125rem] text-white/60 tabular-nums`,children:[i,`:`,a]})}function H({label:e,on:t,danger:n,busy:r,onClick:i,children:a}){return(0,V.jsx)(`button`,{type:`button`,"aria-label":e,title:e,"aria-pressed":t,disabled:r,onClick:i,className:v(`flex size-12 items-center justify-center rounded-full transition disabled:opacity-50`,n?`bg-rose text-white hover:brightness-110`:t===!1?`bg-white text-neutral-900 hover:bg-white/90`:`bg-white/15 text-white hover:bg-white/25`),children:r?(0,V.jsx)(T,{className:`size-5`}):a})}function we({voice:e}){let t=(0,B.useRef)(null),{captions:n}=e;return(0,B.useEffect)(()=>{n.length&&t.current?.scrollIntoView({block:`end`})},[n]),n.length?(0,V.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 sm:px-5`,children:(0,V.jsxs)(`ol`,{className:`mx-auto flex max-w-[720px] flex-col gap-2 py-2`,children:[n.map(e=>(0,V.jsx)(`li`,{className:v(`text-[0.9375rem] leading-snug`,e.who===`bot`?`text-white/95`:`text-right text-white/50`),children:e.text},e.id)),(0,V.jsx)(`div`,{ref:t})]})}):null}function Te({voice:e,view:t,video:n,className:r}){let i=e.state===`live`,a=e.state===`connecting`,[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!1);(0,B.useEffect)(()=>{s(i?Date.now():null)},[i]);let d=async()=>{l(!1),await e.start(),n&&await e.startCamera()},f=()=>{e.stop(),l(!0)},m=n||e.camera,h=[...e.captions].reverse().find(e=>e.who===`bot`),_=[...e.captions].reverse().find(e=>e.who===`me`),y=e.speaking?j(`talk.speaking`):e.listening?j(`talk.listening`):i?j(`talk.live`):a?j(`talk.connecting`):c?j(`video.ended`):``;return(0,V.jsxs)(`section`,{className:v(`relative flex min-h-0 flex-col bg-neutral-950 text-white`,`safe-top`,r),children:[(0,V.jsxs)(`div`,{className:`flex h-14 shrink-0 items-center gap-3 px-4 sm:px-5`,children:[(0,V.jsx)(`div`,{className:`min-w-0 flex-1 truncate font-display font-semibold text-[1rem] tracking-tight`,children:t?.wizard.title??``}),y?(0,V.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-white/70`,children:[i?(0,V.jsx)(`span`,{className:v(`size-2 rounded-full`,e.speaking?`animate-pulse-dot bg-emerald-400`:`bg-rose`)}):null,y]}):null,(0,V.jsx)(Ce,{since:o})]}),(0,V.jsxs)(`div`,{className:v(`grid min-h-0 gap-2 px-3 pb-2 sm:px-4`,m?`flex-1 grid-cols-1 sm:grid-cols-2`:`shrink-0 grid-cols-1`,!m&&i&&e.captions.length?`h-[38%]`:m?``:`flex-1`),children:[(0,V.jsxs)(`div`,{className:v(`relative min-h-0 overflow-hidden rounded-2xl bg-neutral-900`,!m&&`hidden`),children:[(0,V.jsx)(`video`,{ref:e.video,muted:!0,playsInline:!0,autoPlay:!0,className:v(`absolute inset-0 h-full w-full object-cover`,e.facing===`user`&&`-scale-x-100`,e.camera?`block`:`hidden`)}),e.camera?null:(0,V.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center gap-2 text-white/50`,children:[(0,V.jsx)(ve,{className:`size-8`}),(0,V.jsx)(`span`,{className:`text-[0.8125rem]`,children:j(`video.cameraOff`)})]}),(0,V.jsxs)(`span`,{className:`absolute bottom-2 left-3 rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:[j(`video.you`),e.muted?(0,V.jsx)(se,{className:`ml-1.5 inline size-3`}):null]})]}),(0,V.jsxs)(`div`,{className:v(`relative flex min-h-0 items-center justify-center overflow-hidden rounded-2xl transition-shadow`,m?`bg-neutral-900`:`bg-transparent`,m&&e.speaking&&`ring-2 ring-emerald-400/70`),children:[(0,V.jsx)(`div`,{className:v(`rounded-full transition-shadow duration-500`,!m&&e.listening&&`shadow-[0_0_80px_20px_rgba(244,63,94,0.25)]`,!m&&e.speaking&&`shadow-[0_0_80px_20px_rgba(52,211,153,0.3)]`,e.speaking&&`animate-breathe`),children:(0,V.jsx)(ae,{kind:t?.wizard.avatar??`round`,size:m?140:200,fluffy:!0,interactive:!1})}),m?(0,V.jsx)(`span`,{className:`absolute bottom-2 left-3 max-w-[85%] truncate rounded-md bg-black/50 px-2 py-0.5 text-[0.75rem]`,children:t?.wizard.title??``}):null]})]}),i&&!m?(0,V.jsx)(we,{voice:e}):i&&(h||_)?(0,V.jsx)(`div`,{className:`shrink-0 px-4 pb-2 sm:px-5`,children:(0,V.jsxs)(`div`,{className:`mx-auto max-w-[720px] space-y-1 text-center`,children:[_?(0,V.jsx)(`p`,{className:`line-clamp-1 text-[0.8125rem] text-white/50`,children:_.text}):null,h?(0,V.jsx)(`p`,{className:`line-clamp-3 text-[0.9375rem] text-white/95 leading-snug`,children:h.text}):null]})}):null,e.error?(0,V.jsx)(`p`,{className:`shrink-0 px-5 pb-2 text-center text-[0.8125rem] text-rose`,children:e.error}):null,(0,V.jsx)(`div`,{className:`flex shrink-0 items-center justify-center gap-3 px-4 pt-1 pb-4`,children:i?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(H,{label:j(e.muted?`video.unmute`:`video.mute`),on:!e.muted,onClick:e.toggleMute,children:e.muted?(0,V.jsx)(se,{className:`size-5`}):(0,V.jsx)(u,{className:`size-5`})}),(0,V.jsx)(H,{label:j(e.camera?`talk.cameraOff`:`talk.camera`),on:e.camera,onClick:()=>e.camera?e.stopCamera():void e.startCamera(),children:e.camera?(0,V.jsx)(p,{className:`size-5`}):(0,V.jsx)(ve,{className:`size-5`})}),e.camera&&Se?(0,V.jsx)(H,{label:j(`video.flip`),onClick:()=>void e.flipCamera(),children:(0,V.jsx)(g,{className:`size-5`})}):null,(0,V.jsx)(H,{label:j(`video.leave`),danger:!0,onClick:f,children:(0,V.jsx)(re,{className:`size-5`})})]}):(0,V.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,V.jsxs)(`button`,{type:`button`,disabled:a||!t?.talk,onClick:()=>void d(),className:`flex h-12 items-center gap-2 rounded-full bg-emerald-500 px-6 font-medium text-[0.9375rem] text-white transition hover:brightness-110 disabled:opacity-50`,children:[a?(0,V.jsx)(T,{className:`size-4`}):n?(0,V.jsx)(p,{className:`size-5`}):(0,V.jsx)(u,{className:`size-5`}),j(c?`video.rejoin`:n?`video.join`:`talk.start`)]}),!c&&!e.error?(0,V.jsx)(`p`,{className:`max-w-sm text-center text-[0.75rem] text-white/50`,children:j(n?`video.hint`:`talk.joinHint`)}):null]})})]})}var Ee=e=>z[e.kind]!==`device`,De=1024,Oe=4e3;function U(e,t){return e?e.length>t?`${e.slice(0,t)} …`:e:``}function W(e,t,n=!1){let r=[`status: ${e.status}`,`camera: ${n?`on`:`off`}`];if(e.ask)return r.push(e.ask.kind===`confirm`?`question: the step wants to "${e.ask.action.summary}" in ${e.ask.service}; answer_ask allows or skips it`:`question: a sign-in at ${e.ask.site.host}; the person types it on the screen, wait`),r.join(`
2
+ `);if(e.status===`running`){let t=[...e.events].reverse().find(e=>e.type===`tool`||e.type===`info`||e.type===`step_started`);return r.push(`working on: ${e.step?.title??``}`),t&&r.push(`doing: ${o(t)}`),r.join(`
3
+ `)}if(e.status===`done`){r.push(`done. made:`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.title}: ${U(n?.text,400)||`(a file, on the screen)`}`);return r.join(`
4
+ `)}if(e.status===`failed`)return r.push(`failed: ${e.error??``}; go_back or the person retries on the screen`),r.join(`
5
+ `);if(t){r.push(`page: ${t.step.title}`);for(let e of t.fields){let n=t.values[e.id],i=n!=null&&n!==``,a=Ee(e)?`by voice`:e.kind===`image`?`with the camera (take_photo) or on the screen`:`on the screen only`,o=e.options?.length?`; options: ${e.options.join(` | `)}`:``;r.push(`- field ${e.id} (${e.kind}${e.required?`, required`:``}, ${a}): ${e.label}${e.help?` – ${e.help}`:``}${o}${i?` = ${U(String(Array.isArray(n)?n.join(`, `):n),120)}`:` = (open)`}`)}return r.join(`
6
+ `)}if(e.step?.type===`review`){r.push(`review: ${e.step.title}`);for(let{step:t,output:n}of e.shown)r.push(`- ${t.id} "${t.title}": ${U(n?.text,600)||`(a picture or file, on the screen)`}`);return r.push(`regenerate allowed: ${e.step.regenerate?`yes`:`no`}`),r.join(`
7
+ `)}return r.push(`step: ${e.step?.title??``}`),r.join(`
8
+ `)}function ke(e,t,n,r){let[i,a]=(0,B.useState)(`off`),[o,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(!1),[m,h]=(0,B.useState)(`environment`),[g,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)([]),b=(0,B.useRef)(null),x=(0,B.useRef)(null),S=(0,B.useRef)(0),C=(0,B.useRef)(!1);C.current=f;let w=(0,B.useRef)(null),T=(0,B.useRef)(null),E=(0,B.useRef)(null),D=(0,B.useRef)(null),O=(0,B.useRef)(t);O.current=t;let k=(0,B.useRef)(r);k.current=r;let A=(0,B.useRef)(n);A.current=n;let N=(0,B.useRef)(``),P=(0,B.useCallback)(e=>{let t=T.current;t&&t.readyState===`open`&&t.send(JSON.stringify(e))},[]),F=(0,B.useCallback)(()=>{let e=b.current;if(!C.current||!e||e.videoWidth===0)return null;let t=Math.min(1,De/e.videoWidth),n=document.createElement(`canvas`);return n.width=Math.round(e.videoWidth*t),n.height=Math.round(e.videoHeight*t),n.getContext(`2d`)?.drawImage(e,0,0,n.width,n.height),n.toDataURL(`image/jpeg`,.75)},[]),I=(0,B.useCallback)(()=>{for(let e of x.current?.getTracks()??[])e.stop();x.current=null,b.current&&(b.current.srcObject=null),p(!1)},[]),L=(0,B.useCallback)(async e=>{if(x.current)return;let t=e??`environment`;try{let e=await navigator.mediaDevices.getUserMedia({video:{facingMode:{ideal:t},width:{ideal:1280}},audio:!1});x.current=e;let n=e.getVideoTracks()[0]?.getSettings().facingMode;h(n===`user`||n===`environment`?n:t),b.current&&(b.current.srcObject=e,await b.current.play().catch(()=>void 0)),p(!0)}catch(e){s(e.name===`NotAllowedError`?j(`talk.cameraDenied`):e.message)}},[]),ee=(0,B.useCallback)(async()=>{let e=m===`user`?`environment`:`user`;I(),await L(e)},[m,I,L]),te=(0,B.useCallback)(()=>{_(e=>{for(let t of D.current?.getAudioTracks()??[])t.enabled=e;return!e})},[]),R=(0,B.useCallback)(()=>{I(),T.current?.close(),T.current=null,w.current?.close(),w.current=null;for(let e of D.current?.getTracks()??[])e.stop();D.current=null,E.current&&=(E.current.srcObject=null,E.current.remove(),null),N.current=``,l(!1),d(!1),_(!1),a(`off`)},[I]);(0,B.useEffect)(()=>()=>R(),[R]);let z=(0,B.useCallback)(async(t,n)=>{let r=O.current,i=k.current,a=A.current;switch(t){case`get_state`:return r?W(r,i,C.current):`no run`;case`look`:{let e=F();return e?(P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[camera] what the person shows right now`},{type:`input_image`,image_url:e}]}}),`a picture arrived as the next message`):`the camera is off; ask the person to switch it on`}case`take_photo`:{if(!i)return`no page is open`;let t=i.fields.find(e=>e.id===String(n.field??``));if(t?.kind!==`image`)return`no such photo field on this page`;let r=F();if(!r)return`the camera is off; ask the person to switch it on`;try{let n=await(await fetch(r)).blob(),a=new File([n],`photo-${Date.now()}.jpg`,{type:`image/jpeg`}),o=await M.upload(`/api/runs/${e}/uploads`,a),s=i.values[t.id],c=t.multiple?[...Array.isArray(s)?s:s?[s]:[],o.id]:o.id,l=i.setField(t.id,c);return l?`refused: ${l}`:`the photo is in the field`}catch(e){return`failed: ${e.message}`}}case`set_field`:{if(!i)return`no page is open`;let e=i.setField(String(n.field??``),n.value);return e?`refused: ${e}`:`kept`}case`submit_page`:{if(!i)return`no page is open`;let e=i.fields.filter(e=>e.required&&Ee(e)&&e.kind!==`toggle`&&(i.values[e.id]===void 0||i.values[e.id]===null||i.values[e.id]===``));return e.length?`still open: ${e.map(e=>e.id).join(`, `)}`:(i.submit(),`sent; wait for the next state`)}case`accept_review`:return r?.step?.type===`review`?await a.accept(r.step.id)?`accepted`:a.error??`refused`:`no review is open`;case`regenerate`:return r?.step?.type===`review`?await a.regenerate(r.step.id,String(n.target??``),String(n.note??``))?`the wizard makes it again; wait`:a.error??`refused`:`no review is open`;case`answer_ask`:if(!r?.ask)return`no question is open`;try{return await M.post(`/api/runs/${e}/ask/${r.ask.id}`,{type:n.allow?`done`:`skip`}),n.allow?`allowed`:`skipped`}catch(e){return`refused: ${e.message}`}case`go_back`:return await a.back()?`went back; wait for the state`:a.error??`refused`;default:return`unknown tool ${t}`}},[e,F,P]),ne=(0,B.useCallback)(async()=>{if(!w.current){s(null),y([]),a(`connecting`);try{let t=await M.post(`/api/runs/${e}/talk`),n=await navigator.mediaDevices.getUserMedia({audio:!0});D.current=n;let r=new RTCPeerConnection;w.current=r;let i=document.createElement(`audio`);i.autoplay=!0,i.setAttribute(`playsinline`,``),document.body.append(i),E.current=i,r.ontrack=e=>{i.srcObject=e.streams[0]};for(let e of n.getTracks())r.addTrack(e,n);let o=r.createDataChannel(`oai-events`);T.current=o,o.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case`output_audio_buffer.started`:l(!0);break;case`output_audio_buffer.stopped`:case`output_audio_buffer.cleared`:l(!1);break;case`input_audio_buffer.speech_started`:{d(!0);let e=Date.now()-S.current>Oe?F():null;e&&(S.current=Date.now(),P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[camera] what the person shows while speaking`},{type:`input_image`,image_url:e}]}}));break}case`input_audio_buffer.speech_stopped`:d(!1);break;case`response.output_audio_transcript.done`:case`conversation.item.input_audio_transcription.completed`:{let e=String(t.transcript??``).trim();if(e){let n=t.type===`response.output_audio_transcript.done`?`bot`:`me`;y(t=>[...t.slice(-199),{id:`${Date.now()}:${n}`,who:n,text:e}])}break}case`response.function_call_arguments.done`:{let e=String(t.name??``),n=String(t.call_id??``),r={};try{r=JSON.parse(String(t.arguments??`{}`))}catch{}z(e,r).then(e=>{P({type:`conversation.item.create`,item:{type:`function_call_output`,call_id:n,output:e}}),P({type:`response.create`})});break}case`error`:s(String(t.error?.message??`error`))}},o.onopen=()=>{a(`live`);let e=O.current;e&&(N.current=W(e,k.current,C.current),P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[state]\n${N.current}\n\nGreet the person in one sentence and ask the first open field.`}]}}),P({type:`response.create`}))},o.onclose=()=>{w.current===r&&R()};let c=await r.createOffer();await r.setLocalDescription(c);let u=await fetch(t.endpoint,{method:`POST`,headers:{authorization:`Bearer ${t.clientSecret}`,"content-type":`application/sdp`},body:c.sdp});if(!u.ok)throw Error(`${j(`talk.failed`)} (${u.status})`);await r.setRemoteDescription({type:`answer`,sdp:await u.text()})}catch(e){R(),s(e.name===`NotAllowedError`?j(`chat.micDenied`):e.message),a(`error`)}}},[e,z,F,P,R]);return(0,B.useEffect)(()=>{if(i!==`live`||!t)return;let e=W(t,r,f);if(e===N.current)return;let n=N.current;N.current=e,P({type:`conversation.item.create`,item:{type:`message`,role:`user`,content:[{type:`input_text`,text:`[state]\n${e}`}]}}),(t.status===`running`&&n.startsWith(`status: running`)&&!n.includes(`working on: `)||t.status!==`running`||n.split(`
9
+ `)[1]!==e.split(`
10
+ `)[1])&&P({type:`response.create`})},[i,t,r,f,P]),{state:i,error:o,speaking:c,listening:u,start:ne,stop:R,camera:f,facing:m,startCamera:L,stopCamera:I,flipCamera:ee,muted:g,toggleMute:te,captions:v,video:b}}var G=(e,t,n)=>({key:e,who:`bot`,node:t,...n}),K=(e,t,n)=>({key:e,who:`me`,node:t,...n}),Ae=(0,B.createContext)(null),q=(0,B.createContext)(null);function je(){return(0,B.useContext)(q)?.voice??null}function Me({children:e}){let t=(0,B.useContext)(Ae);return t?(0,xe.createPortal)(e,t):null}function Ne({header:e,footer:t,children:n}){let[r,i]=(0,B.useState)(null),a=(0,B.useRef)(null),o=(0,B.useRef)(null),s=(0,B.useRef)(!0);return(0,B.useLayoutEffect)(()=>{let e=a.current,t=o.current;if(!e||!t)return;let n=e.scrollTop,r=()=>{e.scrollHeight-e.scrollTop-e.clientHeight<120?s.current=!0:e.scrollTop<n&&(s.current=!1),n=e.scrollTop},i=null,c=new ResizeObserver(()=>{let r=t.querySelector(`[data-anchor]`);r&&r!==i?(i=r,e.scrollTop+=r.getBoundingClientRect().top-e.getBoundingClientRect().top-12,s.current=!1,n=e.scrollTop):s.current&&(e.scrollTop=e.scrollHeight)});return e.scrollTop=e.scrollHeight,e.addEventListener(`scroll`,r,{passive:!0}),c.observe(t),c.observe(e),()=>{c.disconnect(),e.removeEventListener(`scroll`,r)}},[]),(0,V.jsx)(Ae.Provider,{value:r,children:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[e,(0,V.jsx)(`div`,{ref:a,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,V.jsx)(`div`,{ref:o,className:`mx-auto flex w-full max-w-[760px] flex-col gap-3 px-3 pt-5 pb-4 sm:px-6`,children:n})}),(0,V.jsxs)(`div`,{className:`shrink-0 border-border-soft border-t bg-background`,onPointerDownCapture:()=>{s.current=!0},onKeyDownCapture:()=>{s.current=!0},children:[(0,V.jsx)(`div`,{ref:i,className:`mx-auto w-full max-w-[760px] px-3 pt-3 sm:px-6`}),t]})]})})}function J({avatar:e,lines:t}){let n=(0,B.useContext)(q),r=(0,B.useMemo)(()=>t.map(e=>({key:e.key,who:e.who,spoken:!e.bare&&!e.wide})),[t]),a=(0,B.useCallback)(e=>{let t=document.querySelector(`[data-say="${CSS.escape(e)}"]`);return t?.querySelector(`[data-say-text]`)?.getAttribute(`data-say-text`)??t?.innerText??null},[]);ue(!!n?.readAloud,n?.lang??i,r,a);let o=[];for(let e of t){let t=o.at(-1);t&&t.who===`bot`&&e.who===`bot`?t.lines.push(e):o.push({who:e.who,lines:[e]})}return o.map((t,n)=>t.who===`bot`?(0,V.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,V.jsx)(`div`,{className:`sticky top-1 shrink-0 pt-0.5`,children:(0,V.jsx)(ae,{kind:e,size:30,interactive:n>=o.length-2})}),(0,V.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col items-start gap-1.5`,children:t.lines.map(e=>(0,V.jsx)(`div`,{"data-anchor":e.anchor?``:void 0,"data-say":e.key,className:v(`animate-rise`,e.bare?`w-full pt-1`:`rounded-2xl rounded-tl-md text-[0.9375rem] text-ink leading-relaxed`,!e.bare&&(e.wide?v(`w-full bg-card p-4 shadow-soft ring-1 ring-border-soft`,e.wide===`most`&&`md:w-4/5`):`max-w-[min(36rem,100%)] bg-card px-4 py-2.5 shadow-soft ring-1 ring-border-soft`),e.tone===`error`&&`bg-rose-tint text-rose shadow-none ring-0`),children:e.node},e.key))})]},t.lines[0].key):t.lines.map(e=>(0,V.jsxs)(`div`,{className:`flex animate-rise flex-col items-end gap-1 pl-10`,children:[(0,V.jsx)(`div`,{className:`max-w-[min(32rem,100%)] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-primary px-4 py-2.5 text-[0.9375rem] text-primary-foreground leading-relaxed`,children:e.node}),e.onEdit?(0,V.jsxs)(`button`,{type:`button`,onClick:e.onEdit,className:`inline-flex items-center gap-1 px-1 text-[0.75rem] text-ink-4 transition hover:text-ink-2 coarse:min-h-9`,children:[(0,V.jsx)(y,{className:`size-3`}),` `,j(`chat.change`)]}):null]},e.key)))}function Pe(){return(0,V.jsx)(`span`,{className:`inline-flex items-center gap-1 py-1.5`,role:`status`,"aria-label":j(`run.working`),children:[0,1,2].map(e=>(0,V.jsx)(`span`,{className:`size-1.5 animate-typing rounded-full bg-ink-3`,style:{animationDelay:`${e*160}ms`}},e))})}function Y({children:e}){return(0,V.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:e})}var X=(e,t)=>G(e,(0,V.jsx)(Y,{children:t}),{bare:!0});function Z({onClick:e,children:t,primary:n,on:r,disabled:i,busy:a}){return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":r,disabled:i||a,onClick:e,className:v(`inline-flex h-10 items-center gap-1.5 rounded-full px-4 font-medium text-[0.875rem] transition active:scale-[0.98] disabled:pointer-events-none disabled:opacity-50 coarse:h-11`,n?`bg-primary text-primary-foreground hover:brightness-[1.06]`:r?`bg-ember-tint text-ink ring-1 ring-ember`:`bg-card text-ink-2 ring-1 ring-input hover:text-ink hover:ring-ink-4`),children:[a?(0,V.jsx)(T,{className:`size-4`}):null,t]})}function Fe({initial:e=``,placeholder:t,multiline:n,inputProps:r,busy:i,disabled:a,inputRef:o,onSend:c}){let[l,d]=(0,B.useState)(e),f=(0,B.useRef)(null),m=o??f,h=(0,B.useContext)(q),g=I(l,d,{endpoint:h?`/api/runs/${h.runId}/transcribe`:void 0}),_=!!h&&g.supported&&!a;(0,B.useEffect)(()=>{if(!_)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),g.toggle())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,g.toggle]),(0,B.useEffect)(()=>{!P&&!a&&m.current?.focus()},[a,m]);let y=()=>{i||a||(g.listening&&g.toggle(),c(l)!==!1&&d(``))},b=g.listening?j(`chat.listening`):g.processing?j(`chat.transcribing`):t,x=h?.voice??null,S=!!h?.call,C=h&&!S&&(de||_||x)?(0,V.jsxs)(`div`,{className:`mb-1 flex shrink-0 items-center`,children:[x?(0,V.jsx)(N,{label:j(x.state===`live`?`talk.stop`:x.state===`connecting`?`talk.connecting`:`talk.start`),"aria-pressed":x.state===`live`,disabled:x.state===`connecting`,onClick:()=>x.state===`live`?x.stop():void x.start(),className:v(`size-9`,x.state===`live`&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`,x.state===`off`&&h.talk&&`bg-primary text-primary-foreground hover:bg-primary`),children:x.state===`connecting`?(0,V.jsx)(T,{className:`size-4`}):x.state===`live`?(0,V.jsx)(re,{className:`size-4`}):(0,V.jsx)(ne,{className:`size-4`})}):null,x?.state===`live`?(0,V.jsx)(N,{label:j(x.camera?`talk.cameraOff`:`talk.camera`),"aria-pressed":x.camera,onClick:()=>x.camera?x.stopCamera():void x.startCamera(),className:v(`size-9`,x.camera&&`text-ink`),children:x.camera?(0,V.jsx)(p,{className:`size-4`}):(0,V.jsx)(ve,{className:`size-4`})}):null,de?(0,V.jsx)(N,{label:j(h.readAloud?`chat.readAloudOff`:`chat.readAloud`),"aria-pressed":h.readAloud,onClick:()=>h.setReadAloud(!h.readAloud),className:v(`size-9`,h.readAloud&&`text-ink`),children:h.readAloud?(0,V.jsx)(ie,{className:`size-4`}):(0,V.jsx)(be,{className:`size-4`})}):null,_?(0,V.jsx)(N,{label:j(g.listening?`chat.dictateStop`:`chat.dictate`),"aria-pressed":g.listening,disabled:g.processing,onClick:g.toggle,className:v(`size-9`,g.listening&&`bg-rose-tint text-rose hover:bg-rose-tint hover:text-rose`),children:g.processing?(0,V.jsx)(T,{className:`size-4`}):g.listening?(0,V.jsx)(s,{className:`size-3.5 animate-pulse-dot fill-current`}):(0,V.jsx)(u,{className:`size-4`})}):null]}):null;return(0,V.jsxs)(`form`,{className:`pb-3`,onSubmit:e=>{e.preventDefault(),y()},children:[x&&!S?(0,V.jsx)(`video`,{ref:x.video,muted:!0,playsInline:!0,autoPlay:!0,className:v(`mb-2 ml-auto w-32 rounded-xl bg-black object-cover shadow-soft ring-1 ring-border-soft`,x.camera?`block`:`hidden`)}):null,(0,V.jsxs)(`div`,{className:v(`flex items-end gap-1 rounded-[1.375rem] border border-input bg-card pr-1.5 pl-1 transition focus-within:border-focus focus-within:ring-4 focus-within:ring-focus-glow`,a&&`opacity-60`),children:[C,n?(0,V.jsx)(te,{ref:m,minRows:1,maxRows:6,value:l,disabled:a,placeholder:b,autoCapitalize:`sentences`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!P&&!e.nativeEvent.isComposing&&(e.preventDefault(),y())},className:`min-h-11 border-0 bg-transparent py-2.5 shadow-none focus:ring-0`}):(0,V.jsx)(`input`,{ref:m,...r,value:l,disabled:a,placeholder:b,enterKeyHint:`send`,onChange:e=>d(e.target.value),className:`h-11 min-w-0 flex-1 bg-transparent px-3 text-[0.9375rem] text-ink outline-none placeholder:text-ink-4`}),(0,V.jsx)(`button`,{type:`submit`,"aria-label":j(`chat.send`),title:j(`chat.send`),disabled:i||a,className:`mb-1 flex size-9 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition hover:brightness-[1.06] disabled:opacity-40`,children:i?(0,V.jsx)(T,{className:`size-4`}):(0,V.jsx)(L,{className:`size-4`})})]}),g.error?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:g.error===`denied`?j(`chat.micDenied`):g.error}):S?null:x?.error?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-rose`,children:x.error}):x?.state===`live`?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:x.speaking?j(`talk.speaking`):x.listening?j(`talk.listening`):j(`talk.live`)}):h?.talk&&x?.state===`off`?(0,V.jsx)(`p`,{className:`mt-1.5 px-3 text-[0.75rem] text-ink-3`,children:j(`talk.hint`)}):null]})}function Q({placeholder:e=j(`chat.above`)}){return(0,V.jsx)(Me,{children:(0,V.jsx)(Fe,{disabled:!0,placeholder:e,onSend:()=>!1})})}function Ie(e){let t=z[e.kind];return t===`typed`&&!e.scan?`typed`:t===`tapped`?`tapped`:`control`}var Le=e=>e==null||e===``||Array.isArray(e)&&e.length===0;function Re(e,t){let n=e.kind===`toggle`||e.kind===`connection`||e.kind===`list`;if(Le(t))return e.required&&!n?j(`chat.required`):null;let r=String(t).trim();if(e.kind===`email`&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r))return j(`chat.badEmail`);if(e.kind===`url`)try{new URL(r)}catch{return j(`chat.badUrl`)}return e.kind===`number`&&!Number.isFinite(Number(r.replace(`,`,`.`)))?j(`chat.badNumber`):Array.isArray(t)&&e.multiple&&e.min&&t.length<e.min?j(`run.filesMin`,{n:t.length,min:e.min}):null}function ze(e,t){let n=e.kind===`textarea`?t.replace(/\s+$/,``):t.trim();if(n)return e.kind===`url`&&!/^[a-z][a-z0-9+.-]*:/i.test(n)?`https://${n}`:n}function Be({field:e}){return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e.label}),e.help?(0,V.jsx)(`span`,{className:`mt-0.5 block text-[0.8125rem] text-ink-3`,children:e.help}):null]})}function Ve({step:e,only:t}){return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:e.title}),e.description?(0,V.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:e.description}):null,t?.help?(0,V.jsx)(`span`,{className:`mt-1 block text-[0.8125rem] text-ink-3`,children:t.help}):null]})}function He({field:e,value:t,runId:n}){if(e.kind===`connection`)return(0,V.jsx)(V.Fragment,{children:typeof t==`string`&&t?t:j(`chat.connected`)});if(e.kind===`list`)return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(S,{className:`size-4`}),` `,j(`chat.checked`)]});if(e.kind===`toggle`)return(0,V.jsx)(V.Fragment,{children:j(t===!0?`run.yes`:`run.no`)});if(Le(t))return(0,V.jsx)(`span`,{className:`italic opacity-80`,children:j(`chat.skipped`)});switch(e.kind){case`multiselect`:return(0,V.jsx)(V.Fragment,{children:t.join(`, `)});case`date`:{let e=new Date(`${String(t)}T00:00`);return(0,V.jsx)(V.Fragment,{children:Number.isNaN(e.getTime())?String(t):new Intl.DateTimeFormat(i,{dateStyle:`long`}).format(e)})}case`color`:return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`size-4 rounded-full ring-1 ring-white/50`,style:{background:String(t)}}),String(t)]});case`image`:case`signature`:return(0,V.jsx)(`span`,{className:`-mx-1.5 flex flex-wrap gap-1.5`,children:(Array.isArray(t)?t:[String(t)]).map(t=>(0,V.jsx)(`img`,{src:ee(`/api/runs/${n}/assets/${t}`),alt:``,className:v(`h-16 rounded-lg bg-white`,e.kind===`image`?`w-16 object-cover`:`object-contain px-1`)},t))});case`file`:{let e=Array.isArray(t)?t.length:1;return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(b,{className:`size-4`}),` `,j(e===1?`chat.file`:`chat.files`,{n:e})]})}case`audio`:{let e=t.seconds;return(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,V.jsx)(u,{className:`size-4`}),` `,j(`chat.voice`),e?` · ${Math.round(e)} s`:``]})}case`location`:{let e=t;return(0,V.jsx)(V.Fragment,{children:e.label||`${e.lat?.toFixed(5)}, ${e.lng?.toFixed(5)}`})}case`items`:return(0,V.jsx)(V.Fragment,{children:j(`chat.rows`,{n:Array.isArray(t)?t.length:0})});default:return(0,V.jsx)(V.Fragment,{children:String(t)})}}function Ue(e,t,n,r,i,a){let o=[G(t,(0,V.jsx)(Ve,{step:e,only:a}))];for(let e of i)a||o.push(G(`${t}:${e.id}`,(0,V.jsx)(Be,{field:e}))),o.push(K(`${t}:${e.id}:a`,(0,V.jsx)(He,{field:e,value:n[e.id],runId:r})));return o}var We=(e,t)=>e.fields.filter(e=>!e.when&&!l(e)||t[e.id]!==void 0&&t[e.id]!==null);function Ge(e,t){let n=[];e.wizard.description&&n.push(G(`hello`,e.wizard.description)),e.wizard.intro&&n.push(G(`intro`,e.wizard.intro));for(let[t,r]of e.answered.entries()){let i=`${t}:${r.id}`;if(r.type===`page`){let t=r.fields.length===1?r.fields[0]:void 0;n.push(...Ue(r,i,e.values,e.id,We(r,e.values),t))}else r.type===`review`&&(n.push(G(i,(0,V.jsx)(`span`,{className:`font-medium`,children:r.title}))),n.push(K(`${i}:a`,j(`run.accept`))))}let r=n.at(-1);return t&&r?.who===`me`&&(n[n.length-1]={...r,onEdit:t}),n}function Ke(e,t){return e.fields.filter(e=>!l(e)||t.decidedFields?.includes(e.id)).map(e=>t.options?.[e.id]?.length?{...e,options:t.options[e.id]}:e)}function qe({view:e,run:t,step:n,before:r}){let i=(0,B.useMemo)(()=>Ke(n,e),[n,e]),a=e.known??{},[o,s]=(0,B.useState)(()=>w(n,e)),[c,l]=(0,B.useState)(()=>n.fields.some(t=>e.values[t.id]!==void 0)?D(Ke(n,e),e.known??{},w(n,e)).slice(0,-1).map(e=>e.id):[]),[u,d]=(0,B.useState)({}),[f,p]=(0,B.useState)(!1),[m,g]=(0,B.useState)(!1),_=D(i,a,o),v=_.filter(e=>c.includes(e.id)),y=_.find(e=>!c.includes(e.id)),b=i.length===1?i[0]:void 0,x=v.at(-1),S=x?()=>l(e=>e.filter(e=>e!==x.id)):void 0;(0,B.useEffect)(()=>{let e=Object.keys(t.fieldErrors),n=D(i,a,o),r=n.findIndex(t=>e.includes(t.id));r>=0&&(l(n.slice(0,r).map(e=>e.id)),d(t.fieldErrors))},[t.fieldErrors]);let C=e=>{t.submitPage(n.id,e).then(g)},T=(0,B.useContext)(q),E=(0,B.useRef)(o);E.current=o;let O=T?.bindPage,k=(0,B.useRef)(C);k.current=C,(0,B.useEffect)(()=>{if(!O)return;let e=D(i,a,o);return O({step:n,fields:e,values:o,setField:(t,n)=>{let r=e.find(e=>e.id===t);return r?Re(r,n)||(s(e=>({...e,[t]:n})),l(e=>e.includes(t)?e:[...e,t]),d({}),null):`no such field on this page`},submit:()=>k.current(E.current)}),()=>O(null)},[O,n,i,a,o]);let A=e=>{if(!y)return!1;let t=Re(y,e);if(t)return d({[y.id]:t}),!1;let n={...o,[y.id]:e},r=[...c,y.id];return s(n),l(r),d({}),D(i,a,n).some(e=>!r.includes(e.id))||C(n),!0},M=[...r.map(e=>c.length?{...e,onEdit:void 0}:e),...Ue(n,`now:${n.id}`,o,e.id,v,b).map((e,t,n)=>t===n.length-1&&e.who===`me`&&y?{...e,onEdit:S}:e)];y?(Ie(y)===`control`?M.push(G(`now:${n.id}:${y.id}:control`,(0,V.jsx)(h,{field:y,value:o[y.id],values:o,runId:e.id,view:e,closed:e.closed?.[y.id],onChange:e=>s(t=>({...t,[y.id]:e})),onBusy:p}),{wide:!0})):b||M.push(G(`now:${n.id}:${y.id}`,(0,V.jsx)(Be,{field:y}))),u[y.id]&&M.push(G(`now:${n.id}:${y.id}:error`,u[y.id],{tone:`error`}))):t.busy||m?M.push(G(`sending`,(0,V.jsx)(Pe,{}))):t.error&&M.push(G(`send-error`,t.error,{tone:`error`}));let N=(0,V.jsx)(Q,{});if(m||!y&&c.length>0&&t.busy)N=(0,V.jsx)(Q,{placeholder:j(`run.working`)});else if(!y)M.push(X(`now:${n.id}:go`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,busy:t.busy,onClick:()=>C(o),children:n.cta||j(`run.next`)}),S?(0,V.jsx)(Z,{onClick:S,disabled:t.busy,children:j(`run.back`)}):null]})));else{let r=Ie(y),i=!y.required&&y.kind!==`connection`&&y.kind!==`list`?(0,V.jsx)(Z,{onClick:()=>A(void 0),children:j(`chat.skip`)}):null;if(r===`typed`){i&&M.push(X(`now:${n.id}:${y.id}:replies`,i));let e=o[y.id];N=(0,V.jsx)(Me,{children:(0,V.jsx)(Fe,{initial:Le(e)?``:String(e),multiline:y.kind===`textarea`,placeholder:y.placeholder||(b?y.label:j(`chat.placeholder`)),inputProps:Je(y),busy:t.busy,onSend:e=>A(ze(y,e))},y.id)})}else if(r===`tapped`)M.push(G(`now:${n.id}:${y.id}:replies`,(0,V.jsx)(Ye,{field:y,view:e,value:o[y.id],onAnswer:A}),{bare:!0}));else{let e=_.filter(e=>!c.includes(e.id)).length===1;M.push(X(`now:${n.id}:${y.id}:replies`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z,{primary:!0,disabled:f,onClick:()=>A(o[y.id]),children:e&&n.cta?n.cta:j(`chat.send`)}),i]})))}}return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:M}),N]})}function Je(e){switch(e.kind){case`number`:return{inputMode:`decimal`,autoComplete:`off`};case`email`:return{type:`email`,inputMode:`email`,autoComplete:`email`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1};case`url`:return{inputMode:`url`,autoComplete:`url`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1};case`date`:return{type:`date`};default:return A(e)}}function Ye({field:e,view:t,value:n,onAnswer:r}){let i=new Set(t.closed?.[e.id]?.values.map(String)),[a,o]=(0,B.useState)(Array.isArray(n)?n:[]);if(e.kind===`toggle`)return(0,V.jsxs)(Y,{children:[(0,V.jsx)(Z,{on:n===!1,disabled:i.has(`false`),onClick:()=>r(!1),children:j(`run.no`)}),(0,V.jsx)(Z,{on:n===!0,disabled:i.has(`true`),onClick:()=>r(!0),children:j(`run.yes`)})]});let s=e.options??[];return e.kind===`multiselect`?(0,V.jsxs)(Y,{children:[s.map(e=>(0,V.jsx)(Z,{on:a.includes(e),onClick:()=>o(t=>t.includes(e)?t.filter(t=>t!==e):s.filter(n=>n===e||t.includes(n))),children:e},e)),(0,V.jsx)(Z,{primary:!0,disabled:e.required&&!a.length,onClick:()=>r(a),children:a.length||e.required?j(`chat.send`):j(`chat.skip`)})]}):(0,V.jsxs)(Y,{children:[s.map(e=>(0,V.jsx)(Z,{on:n===e,disabled:i.has(e),onClick:()=>r(e),children:e},e)),e.required?null:(0,V.jsx)(Z,{onClick:()=>r(void 0),children:j(`chat.skip`)})]})}function Xe({view:e}){let t=(0,B.useMemo)(()=>[...e.events].reverse().find(t=>t.type===`step_started`&&t.stepId===e.step?.id),[e.events,e.step?.id]),n=t?new Date(t.at).getTime():Date.now(),[r,i]=(0,B.useState)(Date.now());(0,B.useEffect)(()=>{let e=setInterval(()=>i(Date.now()),1e3);return()=>clearInterval(e)},[]);let a=e.events.filter(e=>(e.type===`tool`||e.type===`info`)&&new Date(e.at).getTime()>=n-500),s=a.at(-1),l=[...a].reverse().find(Qe),u=[...new Set(a.map(e=>e.asset).filter(e=>!!e))];return(0,V.jsxs)(`div`,{className:v(`flex max-w-full flex-col gap-1`,l?`w-full`:`w-96`),"data-say-text":t?.message??e.step?.title??j(`run.working`),children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(Pe,{}),(0,V.jsx)(`span`,{className:`font-medium`,children:t?.message??e.step?.title??j(`run.working`)}),(0,V.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:j(`run.elapsed`,{s:Math.max(0,Math.round((r-n)/1e3))})})]}),s&&s!==l?(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[0.8125rem] text-ink-3`,children:[(0,V.jsx)(c,{className:`size-3.5 shrink-0 animate-breathe text-ember`}),(0,V.jsx)(`span`,{className:`truncate`,children:o(s)})]}):null,l&&e.status===`running`?(0,V.jsx)(et,{runId:e.id,event:l}):null,u.length?(0,V.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5`,children:u.slice(-6).map(t=>(0,V.jsx)(`img`,{src:ee(`/api/runs/${e.id}/assets/${t}`),alt:``,className:`size-14 rounded-lg bg-paper-2 object-cover ring-1 ring-border-soft`},t))}):null]})}var Ze=new Set([`opens`,`clicks`,`clicksOn`,`types`,`typesText`,`selects`,`scrolls`,`presses`,`goesBack`,`waitsForPage`,`fastLoop`,`looksAtPage`,`personDrives`,`agentDrives`]);function Qe(e){return!!e.note&&Ze.has(e.note.code)}var $e=1e4;function et({runId:e,event:t}){let[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(`agent`),[s,c]=(0,B.useState)(!1),l=t.note?.code;if((0,B.useEffect)(()=>{l===`personDrives`?a(`person`):l===`agentDrives`&&a(`agent`)},[l]),(0,B.useEffect)(()=>{let t=()=>M.get(`/api/runs/${e}/browser/seat`).then(e=>a(e.seat)).catch(()=>void 0);if(t(),i!==`person`)return;let n=setInterval(t,$e);return()=>clearInterval(n)},[e,i]),n!==null&&n>=t.id)return null;let u=i===`person`,d=async()=>{c(!0);try{let t=await M.post(`/api/runs/${e}/browser/seat`,{to:u?`agent`:`person`});a(t.seat)}catch{}finally{c(!1)}};return(0,V.jsx)(C,{runId:e,driving:u,caption:o(t),hint:j(`browser.driving`),onBroken:()=>r(t.id),className:`mt-1.5`,action:(0,V.jsxs)(`button`,{type:`button`,disabled:s,onClick:()=>void d(),className:v(`flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[0.8125rem] shadow-soft transition-colors disabled:opacity-60`,u?`bg-primary text-primary-foreground hover:bg-primary/90`:`bg-card/90 text-ink ring-1 ring-border-soft backdrop-blur hover:bg-card`),children:[u?(0,V.jsx)(ge,{className:`size-3.5`}):(0,V.jsx)(me,{className:`size-3.5`}),j(u?`browser.handBack`:`browser.takeOver`)]})},n??0)}function $({children:e,end:t}){return(0,V.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,V.jsx)(`h3`,{className:`font-display font-semibold text-[1rem]`,children:e}),t]})}function tt({view:e,run:t,step:n,before:i,asked:o,onNote:s}){let c=e.shown.filter(e=>e.output),[l,u]=(0,B.useState)(c.length===1?c[0].step.id:null),d=(0,B.useRef)(null),p=[...i,...o.map((e,t)=>K(`review:${n.id}:asked:${t}`,e)),G(`review:${n.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:n.title}),n.description?(0,V.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.description}):null]}),{anchor:!0}),...c.map(({step:t,output:r})=>G(`review:${n.id}:${t.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{children:t.title}),(0,V.jsx)(a,{base:`/api/runs/${e.id}`,step:t,output:r,onSurfaceAction:n.regenerate?()=>{u(t.id),d.current?.focus()}:void 0})]}),{wide:!0})),...e.lists.map(t=>G(`review:${n.id}:list:${t.def.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{children:t.def.title}),t.def.check?(0,V.jsx)(r,{runId:e.id,list:t}):(0,V.jsx)(f,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];t.error&&p.push(G(`review-error`,t.error,{tone:`error`}));let m=n.regenerate&&c.length>0;return p.push(X(`review:${n.id}:replies`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(Z,{primary:!0,busy:t.busy,onClick:()=>void t.accept(n.id),children:[(0,V.jsx)(S,{className:`size-4`}),` `,j(`run.accept`)]}),m&&c.length>1?c.map(({step:e})=>(0,V.jsx)(Z,{on:l===e.id,onClick:()=>u(e.id),children:e.title},e.id)):null]}))),(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:p}),m?(0,V.jsx)(Me,{children:(0,V.jsx)(Fe,{multiline:!0,inputRef:d,busy:t.busy,placeholder:c.length>1&&!l?j(`run.feedbackPick`):j(`run.feedbackPlaceholder`),disabled:!l,onSend:e=>{let r=e.trim();return!r||!l?!1:(s(r),t.regenerate(n.id,l,r),!0)}})}):(0,V.jsx)(Q,{})]})}function nt({view:e,run:t,step:n,before:r,onRestart:i}){let o=e.shown.filter(e=>e.output),s=`/api/runs/${e.id}`,c=[...r,G(`result:${n.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem]`,children:n.title}),n.message?(0,V.jsx)(`span`,{className:`mt-0.5 block text-ink-2`,children:n.message}):null]}),{anchor:!0}),...o.map(({step:e,output:t,formats:n,label:r})=>G(`result:${e.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{end:(0,V.jsx)(_,{base:s,stepId:e.id,formats:n,title:r??e.title}),children:r??e.title}),(0,V.jsx)(a,{base:s,step:e,output:t}),t?.assets?.some(e=>e.ai)?(0,V.jsx)(`p`,{className:`mt-3 text-[0.75rem] text-ink-3 leading-relaxed`,children:j(`ai.publish`)}):null]}),{wide:!0})),...e.lists.map(t=>G(`result:list:${t.def.id}`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{end:(0,V.jsx)(k,{runId:e.id,list:t}),children:t.label??t.def.title}),(0,V.jsx)(f,{runId:e.id,list:t,editable:!0})]}),{wide:!0}))];return c.push(X(`result:replies`,(0,V.jsxs)(V.Fragment,{children:[o.length?(0,V.jsx)(ce,{runId:e.id,title:`${n.title} · ${e.wizard.title}`,initial:e.shareUrl?{url:e.shareUrl,expiresAt:e.expiresAt}:null}):null,i?(0,V.jsxs)(Z,{onClick:i,children:[(0,V.jsx)(d,{className:`size-4`}),` `,j(`run.again`)]}):null,e.canBack?(0,V.jsx)(Z,{onClick:()=>void t.back(),disabled:t.busy,children:j(`run.back`)}):null,e.keeps?(0,V.jsx)(`span`,{className:`ml-1`,children:(0,V.jsx)(m,{runId:e.id})}):null]}))),(0,V.jsx)(J,{avatar:e.wizard.avatar,lines:c})}function rt({runId:e,onRestart:t,onView:n,header:r,footer:a,talk:o=!1,call:s=!1}){let c=fe(e),{view:l}=c,[u,f]=(0,B.useState)(null),p=ke(e,l,c,u);(0,B.useEffect)(()=>{n?.(l)},[l,n]);let[m,h]=oe(),g=(0,B.useMemo)(()=>({runId:e,lang:l?.lang??i,readAloud:m,setReadAloud:h,voice:l?.talk?p:null,talk:o,call:!!s,bindPage:f}),[e,l?.lang,l?.talk,m,h,p,o,s]);F(l?.status===`running`&&!l.ask),R(l);let[_,v]=(0,B.useState)({}),[y,b]=(0,B.useState)(null);(0,B.useEffect)(()=>{l&&l.status!==`running`&&b(null)},[l]);let S;if(c.notFound)S=(0,V.jsx)(`div`,{className:`py-24 text-center text-ink-3`,children:j(`run.notFound`)});else if(!l)S=(0,V.jsx)(`div`,{className:`flex justify-center py-24 text-ink-4`,children:(0,V.jsx)(T,{})});else{let e=l.step,n=l.status===`waiting_input`,r=Ge(l,l.canBack&&n&&!c.busy?()=>void c.back():void 0);if(l.status===`running`&&l.ask)S=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`ask:${l.ask.id}`,(0,V.jsx)(O,{runId:l.id,ask:l.ask}),{wide:!0})]}),(0,V.jsx)(Q,{})]});else if(l.status===`running`)S=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,...y?[K(`note`,y)]:[],G(`working:${e?.id}`,(0,V.jsx)(Xe,{view:l}),{wide:l.events.some(t=>t.stepId===e?.id&&Qe(t))?`most`:void 0})]}),(0,V.jsx)(Q,{placeholder:j(`run.working`)})]});else if(l.status===`failed`)S=(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`failed`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`font-medium`,children:j(`run.failed`)}),l.error?(0,V.jsx)(`span`,{className:`mt-0.5 block`,children:(0,V.jsx)(x,{text:l.error})}):null]}),{tone:`error`}),X(`failed:replies`,(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(Z,{primary:!0,busy:c.busy,onClick:()=>void c.retry(),children:[(0,V.jsx)(d,{className:`size-4`}),` `,j(`run.retry`)]}),l.canBack?(0,V.jsx)(Z,{onClick:()=>void c.back(),disabled:c.busy,children:j(`run.back`)}):null]}))]}),(0,V.jsx)(Q,{})]});else if(l.status===`cancelled`)S=(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:[...r,G(`cancelled`,j(`run.cancelled`)),...t?[X(`cancelled:replies`,(0,V.jsxs)(Z,{primary:!0,onClick:t,children:[(0,V.jsx)(d,{className:`size-4`}),` `,j(`run.again`)]}))]:[]]});else if(e?.type===`page`)S=(0,V.jsx)(qe,{view:l,run:c,step:e,before:r},e.id);else if(e?.type===`review`){let t=l.shown.map(e=>e.output?.at??``).join(`|`);S=(0,V.jsx)(tt,{view:l,run:c,step:e,before:r,asked:_[e.id]??[],onNote:t=>{b(t),v(n=>({...n,[e.id]:[...n[e.id]??[],t]}))}},`${e.id}:${t}`)}else S=e?.type===`result`?(0,V.jsx)(nt,{view:l,run:c,step:e,before:r,onRestart:t}):(0,V.jsx)(J,{avatar:l.wizard.avatar,lines:r})}return s?(0,V.jsx)(q.Provider,{value:g,children:(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col lg:flex-row`,children:[(0,V.jsx)(Te,{voice:p,view:l,video:s===`video`,className:`h-[46dvh] shrink-0 lg:h-auto lg:min-h-0 lg:flex-1`}),(0,V.jsx)(`aside`,{className:`flex min-h-0 flex-1 flex-col border-border-soft border-t lg:w-[420px] lg:flex-none lg:border-t-0 lg:border-l`,children:(0,V.jsx)(Ne,{footer:a,children:S})})]})}):(0,V.jsx)(q.Provider,{value:g,children:(0,V.jsx)(Ne,{header:r,footer:a,children:S})})}export{J as a,Z as i,Ne as n,X as o,Q as r,je as s,rt as t};
@@ -0,0 +1,3 @@
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{O as r,r as i}from"./logo-C4V2_3Ar.js";import{$ as a,Bt as o,C as s,D as c,Dt as l,F as u,G as d,H as f,I as p,It as m,Jt as h,K as g,L as _,Nt as v,P as y,Q as b,Qt as x,R as S,Rt as C,St as w,Tt as T,U as ee,V as te,Vt as E,W as ne,X as D,Xt as re,Y as O,Z as k,_t as ie,an as A,bn as ae,bt as j,dn as M,dt as N,en as oe,ft as se,gt as P,ht as F,in as ce,jt as le,kt as I,l as L,ln as ue,lt as R,mt as z,nn as de,pn as fe,pt as B,q as pe,rn as me,sn as he,st as ge,tt as _e,un as V,v as ve,vt as H,w as ye,wt as U,xn as be,yn as xe,yt as W,zt as Se}from"./ui-BOCXzzHi.js";import{a as G,c as Ce,i as we,l as Te,n as Ee,r as De,t as Oe}from"./RunDrawer-C6pzi8AJ.js";import{t as ke}from"./circle-alert-DLvC9ePT.js";import{t as Ae}from"./ChatView-uogJ3nht.js";import{t as je}from"./lock-DR7NakPn.js";import{c as Me,n as Ne,r as Pe,s as Fe,t as Ie,u as Le}from"./NewWizardChannels-Be-7VhBi.js";import{t as Re}from"./upload-B3yv8gsk.js";import{A as ze,C as Be,Ct as Ve,D as He,Dt as Ue,E as We,Et as Ge,It as Ke,Jt as qe,M as Je,Mt as Ye,N as Xe,Nt as Ze,O as Qe,P as $e,Qt as et,T as tt,Vt as nt,Xt as rt,Zt as it,_n as at,_t as ot,cn as st,dn as ct,gn as lt,gt as ut,hn as dt,in as ft,j as pt,l as mt,ln as ht,m as gt,on as _t,pn as vt,qt as yt,s as bt,sn as xt,un as St,vt as Ct,w as wt,yn as Tt}from"./index-Df6UxElH.js";import{t as Et}from"./RunnerView-Deenymq0.js";import{a as Dt,c as Ot,i as kt,l as At,o as jt,r as Mt,s as Nt,t as Pt}from"./esm-BJskogLD.js";var Ft={name:`calendar-clock`,size:24,node:[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`path`,{d:`M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338`,key:`7hb8p4`}],[`path`,{d:`M3 9h5.859`,key:`numkqi`}],[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]};Ft.node;var It=M(Ft),Lt={name:`circle-check`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 9-5.5 5.5L8 12`,key:`xofnsj`}]],aliases:[`check-circle-2`]};Lt.node;var Rt=M(Lt),zt={name:`circle-minus`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}]],aliases:[`minus-circle`]};zt.node;var Bt=M(zt),Vt={name:`code-xml`,size:24,node:[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]],aliases:[`code-2`]};Vt.node;var Ht=M(Vt),Ut={name:`code`,size:24,node:[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]};Ut.node;var Wt=M(Ut),Gt={name:`file-braces`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]],aliases:[`file-json`]};Gt.node;var Kt=M(Gt),qt={name:`file-code-corner`,size:24,node:[[`path`,{d:`M4 12.15V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3.35`,key:`1wthlu`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`m5 16-3 3 3 3`,key:`331omg`}],[`path`,{d:`m9 22 3-3-3-3`,key:`lsp7cz`}]],aliases:[`file-code-2`]};qt.node;var Jt=M(qt),Yt={name:`git-merge`,size:24,node:[[`circle`,{cx:`18`,cy:`18`,r:`3`,key:`1xkwt0`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`path`,{d:`M6 21V9a9 9 0 0 0 9 9`,key:`7kw0sc`}]]};Yt.node;var Xt=M(Yt),Zt={name:`info`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]};Zt.node;var Qt=M(Zt),$t={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};$t.node;var en=M($t),tn={name:`play`,size:24,node:[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]};tn.node;var nn=M(tn),rn={name:`qr-code`,size:24,node:[[`rect`,{width:`5`,height:`5`,x:`3`,y:`3`,rx:`1`,key:`1tu5fj`}],[`rect`,{width:`5`,height:`5`,x:`16`,y:`3`,rx:`1`,key:`1v8r4q`}],[`rect`,{width:`5`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`1x03jg`}],[`path`,{d:`M21 16h-3a2 2 0 0 0-2 2v3`,key:`177gqh`}],[`path`,{d:`M21 21v.01`,key:`ents32`}],[`path`,{d:`M12 7v3a2 2 0 0 1-2 2H7`,key:`8crl2c`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M12 3h.01`,key:`n36tog`}],[`path`,{d:`M12 16v.01`,key:`133mhm`}],[`path`,{d:`M16 12h1`,key:`1slzba`}],[`path`,{d:`M21 12v.01`,key:`1lwtk9`}],[`path`,{d:`M12 21v-1`,key:`1880an`}]]};rn.node;var an=M(rn),on={name:`scan`,size:24,node:[[`path`,{d:`M3 7V5a2 2 0 0 1 2-2h2`,key:`aa7l1z`}],[`path`,{d:`M17 3h2a2 2 0 0 1 2 2v2`,key:`4qcy5o`}],[`path`,{d:`M21 17v2a2 2 0 0 1-2 2h-2`,key:`6vwrx8`}],[`path`,{d:`M7 21H5a2 2 0 0 1-2-2v-2`,key:`ioqczr`}]]};on.node;var sn=M(on),K=e(t(),1),q=e(n(),1),cn=[`auto`,`page`,`agent`,`generate`,`surface`,`widget`],ln=[`page`,`agent`,`generate`,`widget`],un={auto:m,page:_t,agent:lt,generate:ht,surface:xt,widget:at},dn=e=>I(e===`auto`?`addStep.auto`:`type.${e}`);function fn(e,t){let n=e.steps[t-1],r=e.steps[t];return n&&r?I(`addStep.between`,{before:n.title,after:r.title}):n?I(`addStep.after`,{title:n.title}):I(`addStep.first`,{title:r?.title??``})}function pn(e,{at:t,kind:n,prompt:r,when:i}){let a=fn(e,t);return`${n===`auto`?I(`addStep.message`,{place:a}):I(`addStep.messageAs`,{place:a,kind:dn(n)})}${i?`\n${I(i.mode===`if`?`addStep.messageIf`:`addStep.messageAsk`,{text:i.text.trim(),from:e.steps[t-1]?.title??``})}`:``}\n${r.trim()}`}function mn({place:e,branchable:t,onAdd:n,onEmpty:r,onCancel:i}){let[a,o]=(0,K.useState)(`auto`),[s,c]=(0,K.useState)(``),[l,u]=(0,K.useState)(null),[d,f]=(0,K.useState)(!1),[p,h]=(0,K.useState)(`always`),[g,_]=(0,K.useState)(``),v=(0,K.useRef)(null);(0,K.useEffect)(()=>v.current?.focus(),[]);let y=()=>{if(!s.trim()){u(I(`addStep.empty`));return}if(p!==`always`&&!g.trim()){u(I(`addStep.whenEmpty`));return}n(a,s,p===`always`?void 0:{mode:p,text:g})||u(I(`addStep.busy`))};return(0,q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-card p-4 ring-1 ring-border`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`font-medium text-[0.875rem]`,children:I(`addStep.title`)}),(0,q.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:e})]}),(0,q.jsx)(U,{ref:v,minRows:3,maxRows:10,"aria-label":I(`addStep.title`),placeholder:I(`addStep.placeholder`),value:s,onChange:e=>{c(e.target.value),u(null)},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)?(e.preventDefault(),y()):e.key===`Escape`&&i()}}),l?(0,q.jsx)(`p`,{className:`-mt-1.5 text-[0.75rem] text-rose`,children:l}):null,(0,q.jsx)(`fieldset`,{className:`flex flex-wrap gap-1.5`,"aria-label":I(`addStep.kind`),children:cn.map(e=>{let t=un[e];return(0,q.jsxs)(`button`,{type:`button`,"aria-pressed":a===e,onClick:()=>o(e),className:T(`inline-flex h-8 items-center gap-1.5 whitespace-nowrap rounded-full px-3 text-[0.75rem] ring-1 transition`,a===e?`bg-ember-tint text-ember-strong ring-ember/40`:`text-ink-2 ring-border hover:bg-accent`),children:[(0,q.jsx)(t,{className:`size-3.5`}),` `,dn(e)]},e)})}),t?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`fieldset`,{className:`flex flex-wrap items-center gap-1.5`,"aria-label":I(`addStep.when`),children:[(0,q.jsx)(`span`,{className:`mr-1 text-[0.75rem] text-ink-3`,children:I(`addStep.when`)}),[`always`,`if`,`ask`].map(e=>(0,q.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>{h(e),u(null)},className:T(`inline-flex h-7 items-center whitespace-nowrap rounded-full px-3 text-[0.75rem] ring-1 transition`,p===e?`bg-ember-tint text-ember-strong ring-ember/40`:`text-ink-2 ring-border hover:bg-accent`),children:I(e===`always`?`addStep.always`:e===`if`?`addStep.onlyIf`:`addStep.aiDecides`)},e))]}),p===`always`?null:(0,q.jsx)(F,{"aria-label":I(p===`if`?`addStep.onlyIf`:`addStep.aiDecides`),placeholder:I(p===`if`?`addStep.ifPlaceholder`:`addStep.askPlaceholder`),value:g,onChange:e=>{_(e.target.value),u(null)}})]}):null,(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[r?(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsxs)(`button`,{type:`button`,"aria-expanded":d,onClick:()=>f(e=>!e),className:`inline-flex h-8 items-center gap-1 rounded-full px-2 text-[0.75rem] text-ink-3 hover:bg-accent hover:text-ink`,children:[I(`addStep.emptyStep`),` `,(0,q.jsx)(ce,{className:`size-3.5`})]}),d?(0,q.jsx)(`div`,{className:`absolute bottom-full left-0 z-20 mb-1 flex min-w-40 flex-col rounded-xl bg-card p-1 shadow-elevated ring-1 ring-border`,children:ln.map(e=>{let t=un[e];return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(e),className:`inline-flex h-8 items-center gap-2 rounded-lg px-2.5 text-left text-[0.8125rem] text-ink-2 hover:bg-accent`,children:[(0,q.jsx)(t,{className:`size-3.5`}),` `,dn(e)]},e)})}):null]}):null,(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,q.jsx)(R,{variant:`ghost`,size:`sm`,onClick:i,children:I(`addStep.cancel`)}),(0,q.jsxs)(R,{size:`sm`,onClick:y,children:[(0,q.jsx)(m,{className:`size-3.5`}),` `,I(`addStep.create`)]})]})]})]})}function hn({adding:e,place:t,working:n,onShowChat:r}){let i=un[e.kind];return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-border-strong border-dashed bg-card p-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`inline-flex size-6 items-center justify-center rounded-md bg-paper-2 text-ink-3`,children:(0,q.jsx)(i,{className:`size-3.5`})}),(0,q.jsx)(`span`,{className:`font-medium text-[0.8125rem]`,children:I(`addStep.building`)})]}),(0,q.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:t}),e.when?(0,q.jsxs)(`p`,{className:`text-[0.75rem] text-ember-strong`,children:[I(e.when.mode===`if`?`addStep.onlyIf`:`addStep.aiDecides`),` `,e.when.text]}):null,(0,q.jsx)(`p`,{className:`line-clamp-3 whitespace-pre-wrap text-[0.8125rem] text-ink-2`,children:e.prompt}),(0,q.jsx)(`div`,{className:`text-[0.75rem] text-ink-3`,children:n}),r?(0,q.jsxs)(`button`,{type:`button`,onClick:r,className:`inline-flex h-8 items-center gap-1.5 self-start rounded-full px-2.5 text-[0.75rem] text-ink-2 hover:bg-accent`,children:[(0,q.jsx)(ft,{className:`size-3.5`}),` `,I(`addStep.showChat`)]}):null]})}function gn(e,t){let n=new Set([...e.steps.map(e=>e.id),...e.steps.flatMap(e=>e.type===`page`?e.fields.map(e=>e.id):[])]),r=1,i=t;for(;n.has(i);)r+=1,i=`${t}${r}`;return i}var _n={page:e=>({id:e,type:`page`,title:`Neue Seite`,fields:[{id:`${e}Text`,label:`Neue Frage`,kind:`text`}]}),agent:e=>({id:e,type:`agent`,title:`KI-Schritt`,instructions:`Beschreibe die Aufgabe …`,tools:[],output:{format:`markdown`}}),generate:e=>({id:e,type:`generate`,title:`Bild erzeugen`,asset:`image`,prompt:`Beschreibe das Bild …`}),widget:e=>({id:e,type:`widget`,title:`Widget`,entry:`${e}/index.html`,data:{},sample:`${e}/sample.json`})};function vn(e,t,n){let r=gn(e,n===`page`?`seite`:n===`agent`?`ki`:n===`widget`?`widget`:`erzeugen`),i=[...e.steps];return i.splice(t,0,_n[n](r)),{def:{...e,steps:i},id:r}}function yn(e){return e.mime.startsWith(`image/`)?ht:e.mime.includes(`json`)?Kt:e.mime===`text/html`||e.mime.includes(`javascript`)||e.mime===`text/css`?Jt:re}function bn(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function xn({wizardId:e,files:t,readOnly:n}){let i=r(),a=(0,K.useRef)(null),[o,s]=(0,K.useState)(!1),c=(0,K.useRef)(0),[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(null),p=`/api/studio/wizards/${e}/files`,m=()=>i.invalidateQueries({queryKey:[`wizard`,e]}),h=async e=>{if(e?.length){s(!0),f(null);try{for(let t of Array.from(e)){let e=await fetch(`${p}/${encodeURIComponent(t.name).replace(/%2F/g,`/`)}`,{method:`PUT`,credentials:`include`,headers:{"content-type":t.type||`application/octet-stream`},body:t});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??e.statusText)}}}catch(e){f(e.message)}finally{s(!1),await m()}}},g=async e=>{if(window.confirm(I(`files.confirmDelete`,{path:e}))){f(null);try{await L.del(`${p}/${e}`)}catch(e){f(e.message)}await m()}},_=t.reduce((e,t)=>e+t.size,0);return(0,q.jsxs)(`div`,{className:`relative flex min-h-full flex-col px-5 py-5`,onDragEnter:e=>{!n&&e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),c.current+=1,u(!0))},onDragOver:e=>{!n&&e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:()=>{c.current=Math.max(0,c.current-1),c.current===0&&u(!1)},onDrop:e=>{e.preventDefault(),c.current=0,u(!1),n||h(e.dataTransfer.files)},children:[l?(0,q.jsxs)(`div`,{className:`pointer-events-none absolute inset-3 z-10 flex flex-col items-center justify-center gap-2 rounded-2xl border-2 border-ember border-dashed bg-ember-veil text-[0.875rem] text-ember-strong`,children:[(0,q.jsx)(Re,{className:`size-6`}),I(`files.drop`)]}):null,(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n?null:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a.current?.click(),className:`inline-flex h-9 items-center gap-1.5 rounded-full bg-paper-2 px-3.5 font-medium text-[0.8125rem] text-ink-2 hover:bg-paper-3 hover:text-ink`,children:[o?(0,q.jsx)(j,{className:`size-3.5`}):(0,q.jsx)(Re,{className:`size-3.5`}),I(`files.upload`)]}),(0,q.jsx)(`span`,{className:`ml-auto text-[0.75rem] text-ink-4`,children:I(`files.count`,{n:t.length,size:bn(_)})}),(0,q.jsx)(`input`,{ref:a,type:`file`,multiple:!0,hidden:!0,onChange:e=>void h(e.target.files)})]}),d?(0,q.jsx)(`div`,{className:`mt-3 rounded-lg bg-rose-tint px-3 py-2 text-[0.8125rem] text-rose`,children:d}):null,(0,q.jsx)(`ul`,{className:`mt-4 flex flex-col`,children:t.map(e=>{let t=yn(e);return(0,q.jsxs)(`li`,{className:`group flex items-center gap-3 rounded-lg px-2 py-1.5 hover:bg-paper-2`,children:[(0,q.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[0.75rem]`,children:e.path}),(0,q.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:bn(e.size)}),(0,q.jsx)(`a`,{href:`${p}/${e.path}`,className:`inline-flex size-8 items-center justify-center rounded-full text-ink-3 opacity-0 hover:text-ink group-hover:opacity-100`,"aria-label":I(`files.download`),children:(0,q.jsx)(x,{className:`size-4`})}),n?null:(0,q.jsx)(z,{label:I(`files.delete`),className:`opacity-0 hover:text-rose group-hover:opacity-100`,onClick:()=>void g(e.path),children:(0,q.jsx)(v,{className:`size-4`})})]},e.path)})}),t.length===0?(0,q.jsx)(`div`,{className:`mt-6 rounded-xl border border-border border-dashed px-4 py-8 text-center text-[0.8125rem] text-ink-4`,children:I(n?`files.none`:`files.empty`)}):null,n?null:(0,q.jsx)(`p`,{className:`mt-auto pt-6 text-[0.6875rem] text-ink-4 leading-relaxed`,children:I(`files.explain`)})]})}var Sn=Object.defineProperty,Cn=(e,t,n)=>t in e?Sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wn=(e,t)=>{for(var n in t)Sn(e,n,{get:t[n],enumerable:!0})},Tn=(e,t,n)=>Cn(e,typeof t==`symbol`?t:t+``,n),En={};wn(En,{Graph:()=>J,alg:()=>zn});var Dn=Object.defineProperty,On=(e,t)=>{for(var n in t)Dn(e,n,{get:t[n],enumerable:!0})},kn=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=`directed`in e?e.directed:!0,this._isMultigraph=`multigraph`in e&&e.multigraph,this._isCompound=`compound`in e&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[`\0`]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=typeof e==`function`?e:()=>e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(e=>{t===void 0?this.setNode(e):this.setNode(e,t)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=`\0`,this._children[e]={},this._children[`\0`][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw Error(`Cannot set parent in a non-compound graph`);if(t===void 0)t=`\0`;else{t+=``;for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw Error(`Setting `+t+` as parent of `+e+` would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!==`\0`)return t}}children(e=`\0`){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e===`\0`)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t),r=this.successors(e);if(r)for(let e of r)n.add(e);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),(t?.length??0)===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i,i):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=typeof e==`function`?e:()=>e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(t===void 0?this.setEdge(e,n):this.setEdge(e,n,t),n)),this}setEdge(e,t,n,r){let i,a,o,s,c=!1;typeof e==`object`&&e&&`v`in e?(i=e.v,a=e.w,o=e.name,arguments.length===2&&(s=t,c=!0)):(i=e,a=t,o=r,arguments.length>2&&(s=n,c=!0)),i=``+i,a=``+a,o!==void 0&&(o=``+o);let l=Mn(this._isDirected,i,a,o);if(l in this._edgeLabels)return c&&(this._edgeLabels[l]=s),this;if(o!==void 0&&!this._isMultigraph)throw Error(`Cannot set a named edge when isMultigraph = false`);this.setNode(i),this.setNode(a),this._edgeLabels[l]=c?s:this._defaultEdgeLabelFn(i,a,o);let u=Nn(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,An(this._preds[a],i),An(this._sucs[i],a),this._in[a][l]=u,this._out[i][l]=u,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?Pn(this._isDirected,e):Mn(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r!=`object`||!r?{label:r}:r}hasEdge(e,t,n){return(arguments.length===1?Pn(this._isDirected,e):Mn(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?Pn(this._isDirected,e):Mn(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],jn(this._preds[t],e),jn(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function An(e,t){e[t]?e[t]++:e[t]=1}function jn(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function Mn(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}return i+``+a+``+(r===void 0?`\0`:r)}function Nn(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}let o={v:i,w:a};return r&&(o.name=r),o}function Pn(e,t){return Mn(e,t.v,t.w,t.name)}On({},{read:()=>Rn,write:()=>Fn});function Fn(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:In(e),edges:Ln(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function In(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function Ln(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function Rn(e){let t=new kn(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}var zn={};On(zn,{CycleException:()=>er,bellmanFord:()=>Vn,components:()=>Un,dijkstra:()=>Kn,dijkstraAll:()=>Jn,findCycles:()=>Xn,floydWarshall:()=>Qn,isAcyclic:()=>nr,postorder:()=>or,preorder:()=>sr,prim:()=>cr,shortestPaths:()=>lr,tarjan:()=>Yn,topsort:()=>tr});var Bn=()=>1;function Vn(e,t,n,r){return Hn(e,String(t),n||Bn,r||function(t){return e.outEdges(t)??[]})}function Hn(e,t,n,r){let i={},a,o=0,s=e.nodes(),c=function(e){let t=i[e.v],r=i[e.w];if(!t||!r)return;let o=n(e);t.distance+o<r.distance&&(i[e.w]={distance:t.distance+o,predecessor:e.v},a=!0)},l=function(){s.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;c({v:n,w:r})})})};s.forEach(function(e){i[e]={distance:e===t?0:1/0,predecessor:``}});let u=s.length;for(let e=1;e<u&&(a=!1,o++,l(),a);e++);if(o===u-1&&(a=!1,l(),a))throw Error(`The graph contains a negative weight cycle`);return i}function Un(e){let t={},n=[],r;function i(n){var a,o;n in t||(t[n]=!0,r.push(n),(a=e.successors(n))==null||a.forEach(i),(o=e.predecessors(n))==null||o.forEach(i))}return e.nodes().forEach(function(e){r=[],i(e),r.length&&n.push(r)}),n}var Wn=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw Error(`Queue underflow`);return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){if(this.size()===0)throw Error(`Queue underflow`);this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],a=n[t];n[e]=a,n[t]=i,r[a.key]=e,r[i.key]=t}},Gn=()=>1;function Kn(e,t,n,r){return qn(e,String(t),n||Gn,r||function(t){return e.outEdges(t)??[]})}function qn(e,t,n,r){let i={},a=new Wn,o,s,c=function(e){let t=e.v===o?e.w:e.v,r=i[t];if(!r)return;let c=n(e),l=s.distance+c;if(c<0)throw Error(`dijkstra does not allow negative edge weights. Bad edge: `+e+` Weight: `+c);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:1/0;i[e]={distance:n,predecessor:``},a.add(e,n)});a.size()>0;){o=a.removeMin();let e=i[o];if(!e||e.distance===1/0)break;s=e,r(o).forEach(c)}return i}function Jn(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=Kn(e,i,t,n),r},{})}function Yn(e){let t=0,n=[],r={},i=[];function a(o){var s;let c=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),(s=e.successors(o))==null||s.forEach(function(e){if(e in r){let t=r[e];t!=null&&t.onStack&&(c.lowlink=Math.min(c.lowlink,t.index))}else{a(e);let t=r[e];t&&(c.lowlink=Math.min(c.lowlink,t.lowlink))}}),c.lowlink===c.index){let e=[],t;do{t=n.pop();let i=r[t];i&&(i.onStack=!1),e.push(t)}while(o!==t);i.push(e)}}return e.nodes().forEach(function(e){e in r||a(e)}),i}function Xn(e){return Yn(e).filter(function(t){let n=t[0];return n?t.length>1||t.length===1&&(e.outEdges(n,n)??[]).length>0:!1})}var Zn=()=>1;function Qn(e,t,n){return $n(e,t||Zn,n||function(t){return e.outEdges(t)??[]})}function $n(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){let a={};r[e]=a,a[e]={distance:0,predecessor:``},i.forEach(function(t){e!==t&&(a[t]={distance:1/0,predecessor:``})}),n(e).forEach(function(n){let r=n.v===e?n.w:n.v,i=t(n);a[r]={distance:i,predecessor:e}})}),i.forEach(function(e){let t=r[e];t&&i.forEach(function(n){let a=r[n];a&&i.forEach(function(n){let r=a[e],i=t[n],o=a[n];if(r&&i&&o){let e=r.distance+i.distance;e<o.distance&&(o.distance=e,o.predecessor=i.predecessor)}})})}),r}var er=class extends Error{constructor(e){super(e),this.name=`CycleException`}};function tr(e){let t={},n={},r=[];function i(a){var o;if(a in n)throw new er;a in t||(n[a]=!0,t[a]=!0,(o=e.predecessors(a))==null||o.forEach(i),delete n[a],r.push(a))}if(e.sinks().forEach(i),Object.keys(t).length!==e.nodeCount())throw new er;return r}function nr(e){try{tr(e)}catch(e){if(e instanceof er)return!1;throw e}return!0}function rr(e,t,n,r,i){Array.isArray(t)||(t=[t]);let a=(t=>(e.isDirected()?e.successors(t):e.neighbors(t))??[]),o={};return t.forEach(function(t){if(!e.hasNode(t))throw Error(`Graph does not have node: `+t);i=ir(e,t,n===`post`,o,a,r,i)}),i}function ir(e,t,n,r,i,a,o){return t in r||(r[t]=!0,n||(o=a(o,t)),i(t).forEach(function(t){o=ir(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function ar(e,t,n){return rr(e,t,n,function(e,t){return e.push(t),e},[])}function or(e,t){return ar(e,t,`post`)}function sr(e,t){return ar(e,t,`pre`)}function cr(e,t){var n;let r=new kn,i={},a=new Wn,o;function s(e){let n=e.v===o?e.w:e.v,r=a.priority(n);if(r!==void 0){let s=t(e);s<r&&(i[n]=o,a.decrease(n,s))}}if(e.nodeCount()===0)return r;e.nodes().forEach(function(e){a.add(e,1/0),r.setNode(e)});let c=e.nodes()[0];c!==void 0&&a.decrease(c,0);let l=!1;for(;a.size()>0;){if(o=a.removeMin(),o in i)r.setEdge(o,i[o]);else{if(l)throw Error(`Input graph is not connected: `+e);l=!0}(n=e.nodeEdges(o))==null||n.forEach(s)}return r}function lr(e,t,n,r){return ur(e,t,n,r??(t=>e.outEdges(t)??[]))}function ur(e,t,n,r){if(n===void 0)return Kn(e,t,n,r);let i=!1,a=e.nodes();for(let o=0;o<a.length;o++){let s=a[o];if(s===void 0)continue;let c=r(s);for(let e=0;e<c.length;e++){let t=c[e];if(!t)continue;let r=t.v===s?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return Vn(e,t,n,r)}return Kn(e,t,n,r)}var J=kn;function dr(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Er(r);return n.dummy=t,e.setNode(i,n),i}function fr(e){let t=new J().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function pr(e){let t=new J({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function mr(e,t){let n=e.x,r=e.y,i=t.x-n,a=t.y-r,o=e.width/2,s=e.height/2;if(!i&&!a)throw Error(`Not possible to find intersection inside of the rectangle`);let c,l;return Math.abs(a)*o>Math.abs(i)*s?(a<0&&(s=-s),c=s*i/a,l=s):(i<0&&(o=-o),c=o,l=o*a/i),{x:n+c,y:r+l}}function hr(e){let t=Dr(xr(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function gr(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=Y(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function _r(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=Y(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{t===void 0&&n%a!==0?--i:t!==void 0&&i&&t.forEach(t=>e.node(t).rank+=i)})}function vr(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),dr(e,`border`,i,t)}function yr(e,t=br){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var br=65535;function Y(e,t){return t.length>br?e(...yr(t).map(t=>e(...t))):e(...t)}function xr(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return Y(Math.max,t)}function Sr(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Cr(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function wr(e,t){return t()}var Tr=0;function Er(e){return e+(``+ ++Tr)}function Dr(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let t=e;r(t);t+=n)i.push(t);return i}function Or(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function kr(e,t){let n;return n=typeof t==`string`?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}function Ar(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var jr=`\0`;function Mr(e,t,n){if(!(e&&t&&n&&t.dummy===`edge`&&n.dummy===`edge`&&t.edgeObj&&n.edgeObj&&e[t.edgeObj.v]&&e[n.edgeObj.v]&&e[t.edgeObj.w]&&e[n.edgeObj.w]))return 0;let r=!0;t.edgeObj.w===n.edgeObj.w&&(r=!1);let i=r?e[t.edgeObj.v]?.rank??NaN:e[t.edgeObj.w]?.rank??NaN,a=Object.entries(e).find(e=>e[1].edgeObj?.v===t.edgeObj.v&&e[1].edgeObj?.w===t.edgeObj.w&&e[1].rank===i),o=Object.entries(e).find(e=>e[1].edgeObj?.v===n.edgeObj.v&&e[1].edgeObj?.w===n.edgeObj.w&&e[1].rank===i);if(!a||!o)return 0;let s=a[1].order??NaN,c=o[1].order??NaN;return isNaN(s-c)?0:s-c}var Nr=`3.1.1`,Pr=class{constructor(){Tn(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Fr(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Fr(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,Ir)),n=n._prev;return`[`+e.join(`, `)+`]`}};function Fr(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function Ir(e,t){if(e!==`_next`&&e!==`_prev`)return t}var Lr=Pr,Rr=()=>1;function zr(e,t){if(e.nodeCount()<=1)return[];let n=Hr(e,t||Rr);return Br(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function Br(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)Vr(e,t,n,o);for(;o=i.dequeue();)Vr(e,t,n,o);if(e.nodeCount()){for(let i=t.length-2;i>0;--i)if(o=t[i]?.dequeue(),o){r=r.concat(Vr(e,t,n,o,!0)||[]);break}}}return r}function Vr(e,t,n,r,i){let a=[],o=i?a:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),s=e.node(r.v);i&&a.push({v:r.v,w:r.w}),s.out-=o,Ur(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,Ur(t,n,o)}),e.removeNode(r.v),o}function Hr(e,t){let n=new J,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let a=n.edge(e.v,e.w)||0,o=t(e),s=a+o;n.setEdge(e.v,e.w,s);let c=n.node(e.v),l=n.node(e.w);i=Math.max(i,c.out+=o),r=Math.max(r,l.in+=o)});let a=Wr(i+r+3).map(()=>new Lr),o=r+1;return n.nodes().forEach(e=>{Ur(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function Ur(e,t,n){var r,i,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(i=e[e.length-1])==null||i.enqueue(n):(r=e[0])==null||r.enqueue(n)}function Wr(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function Gr(e,t){(e.graph().acyclicer===`greedy`?zr(e,n(e)):Kr(e,t??null)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,Er(`rev`))});function n(e){return t=>e.edge(t).weight}}function Kr(e,t){let n=[],r={},i={};function a(t){Object.hasOwn(i,t)||(i[t]=!0,r[t]=!0,e.outEdges(t).forEach(e=>{Object.hasOwn(r,e.w)?n.push(e):a(e.w)}),delete r[t])}function o(a){var s;Object.hasOwn(i,a)||(i[a]=!0,r[a]=!0,(s=e.outEdges(a))==null||s.forEach(i=>{Object.hasOwn(r,i.w)||t.node(a)?.rank>t.node(i.w)?.rank&&Jr(e,i.w,i)?n.push(i):o(i.w)}),delete r[a])}let s=a;return t&&typeof t.node==`function`&&(s=o),e.sources().forEach(s),e.nodes().forEach(s),n}function qr(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function Jr(e,t,n){let r=new Set;function i(t){if(e.sources().includes(t))return!0;r.add(t);for(let a of e.inEdges(t)??[])if((a.v!==n.v||a.w!==n.w)&&!r.has(a.v)&&i(a.v))return!0;return!1}return i(t)}function Yr(e){e.graph().dummyChains=[],e.edges().forEach(t=>Xr(e,t))}function Xr(e,t){let n=t.v,r=e.node(n).rank,i=t.w,a=e.node(i).rank,o=t.name,s=e.edge(t),c=s.labelRank;if(a===r+1)return;e.removeEdge(t);let l,u,d=0;for(++r;r<a;++d,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},l=dr(e,`edge`,u,`_d`),r===c&&(u.width=s.width,u.height=s.height,u.dummy=`edge-label`,u.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},o),d===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},o)}function Zr(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy===`edge-label`&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}function Qr(e){let t={};function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let a=e.outEdges(r),o=a?a.map(t=>t==null?1/0:n(t.w)-e.edge(t).minlen):[],s=Y(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function $r(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var ei=ti;function ti(e){let t=new J({directed:!1}),n=e.nodes();if(n.length===0)throw Error(`Graph must have at least one node`);let r=n[0],i=e.nodeCount();t.setNode(r,{});let a,o;for(;ni(t,e)<i&&(a=ri(t,e),a);)o=t.hasNode(a.v)?$r(e,a):-$r(e,a),ii(t,e,o);return t}function ni(e,t){function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let a=i.v,o=r===a?i.w:a;!e.hasNode(o)&&!$r(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function ri(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=$r(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function ii(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:ai,postorder:oi}=zn,si=ci;ci.initLowLimValues=fi,ci.initCutValues=li,ci.calcCutValue=di,ci.leaveEdge=mi,ci.enterEdge=hi,ci.exchangeEdges=gi;function ci(e){e=fr(e),Qr(e);let t=ei(e);fi(t),li(t,e);let n,r;for(;n=mi(t);)r=hi(t,e,n),gi(t,e,n,r)}function li(e,t){let n=oi(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>ui(e,t,n))}function ui(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=di(e,t,n)}function di(e,t,n){let r=e.node(n).parent,i=!0,a=t.edge(n,r),o=0;a||=(i=!1,t.edge(r,n)),o=a.weight;let s=t.nodeEdges(n);return s&&s.forEach(a=>{let s=a.v===n,c=s?a.w:a.v;if(c!==r){let r=s===i,l=t.edge(a).weight;if(o+=r?l:-l,vi(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function fi(e,t){arguments.length<2&&(t=e.nodes()[0]),pi(e,{},1,t)}function pi(e,t,n,r,i){let a=n,o=e.node(r);t[r]=!0;let s=e.neighbors(r);return s&&s.forEach(i=>{Object.hasOwn(t,i)||(n=pi(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function mi(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function hi(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let a=e.node(r),o=e.node(i),s=a,c=!1;return a.lim>o.lim&&(s=o,c=!0),t.edges().filter(t=>c===yi(e,e.node(t.v),s)&&c!==yi(e,e.node(t.w),s)).reduce((e,n)=>$r(t,n)<$r(t,e)?n:e)}function gi(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),fi(e),li(e,t),_i(e,t)}function _i(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=ai(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),a=!1;i||(i=t.edge(r,n),a=!0),t.node(n).rank=t.node(r).rank+(a?i.minlen:-i.minlen)})}function vi(e,t,n){return e.hasEdge(t,n)}function yi(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var bi=xi;function xi(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:wi(e);break;case`tight-tree`:Ci(e);break;case`longest-path`:Si(e);break;case`none`:break;default:wi(e)}}var Si=Qr;function Ci(e){Qr(e),ei(e)}function wi(e){si(e)}var Ti=Ei;function Ei(e){let t=Oi(e),n=e.graph();Array.isArray(n.dummyChains)&&n.dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=Di(e,t,i.v,i.w),o=a.path,s=a.lca,c=0,l=o[c],u=!0;for(;n!==i.w;){if(r=e.node(n),u){for(;(l=o[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(u=!1)}if(!u){for(;c<o.length-1&&e.node(o[c+1]).minRank<=r.rank;)c++;l=o[c]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function Di(e,t,n,r){let i=[],a=[],o=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),i.push(c);while(c&&(t[c].low>o||s>t[c].lim));let l=c,u=r;for(;(u=e.parent(u))!==l;)a.push(u);return{path:i.concat(a.reverse()),lca:l}}function Oi(e){let t={},n=0;function r(i){let a=n;e.children(i).forEach(r),t[i]={low:a,lim:n++}}return e.children(jr).forEach(r),t}function ki(e){let t=dr(e,`root`,{},`_root`),n=ji(e),r=Object.values(n),i=Y(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=Mi(e)+1;e.children(jr).forEach(r=>{Ai(e,t,a,o,i,n,r)}),e.graph().nodeRankFactor=a}function Ai(e,t,n,r,i,a,o){let s=e.children(o);if(!s.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=vr(e,`_bt`),l=vr(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{Ai(e,t,n,r,i,a,s);let u=e.node(s),d=u.borderTop?u.borderTop:s,f=u.borderBottom?u.borderBottom:s,p=u.borderTop?r:2*r,m=d===f?i-(a[o]??0)+1:1;e.setEdge(c,d,{weight:p,minlen:m,nestingEdge:!0}),e.setEdge(f,l,{weight:p,minlen:m,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:i+(a[o]??0)})}function ji(e){let t={};function n(r,i){let a=e.children(r);a&&a.length&&a.forEach(e=>n(e,i+1)),t[r]=i}return e.children(jr).forEach(e=>n(e,1)),t}function Mi(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function Ni(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var Pi=Fi;function Fi(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),i&&Object.hasOwn(i,`minRank`)){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)Ii(e,`borderLeft`,`_bl`,n,i,t),Ii(e,`borderRight`,`_br`,n,i,t)}}e.children(jr).forEach(t)}function Ii(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=dr(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function Li(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&zi(e)}function Ri(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&Vi(e),(t===`lr`||t===`rl`)&&(Ui(e),zi(e))}function zi(e){e.nodes().forEach(t=>Bi(e.node(t))),e.edges().forEach(t=>Bi(e.edge(t)))}function Bi(e){let t=e.width;e.width=e.height,e.height=t}function Vi(e){e.nodes().forEach(t=>Hi(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(Hi),Object.hasOwn(r,`y`)&&Hi(r)})}function Hi(e){e.y=-e.y}function Ui(e){e.nodes().forEach(t=>Wi(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(Wi),Object.hasOwn(r,`x`)&&Wi(r)})}function Wi(e){let t=e.x;e.x=e.y,e.y=t}function Gi(e,t=null){let n={},r=e.nodes().filter(t=>!e.children(t).length),i=r.map(t=>e.node(t).rank),a=Dr(Y(Math.max,i)+1).map(()=>[]);function o(t){if(n[t])return;n[t]=!0;let r=e.node(t);a[r.rank].push(t);let i=e.successors(t);i&&[...i].sort((e,t)=>s(e,t)).forEach(o)}r.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(o);function s(n,r){return Mr(t,e.node(n),e.node(r))}return a}function Ki(e,t){let n=0;for(let r=1;r<t.length;++r)n+=qi(e,t[r-1],t[r]);return n}function qi(e,t,n){let r=Ar(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),a=1;for(;a<n.length;)a<<=1;let o=2*a-1;--a;let s=Array(o).fill(0),c=0;return i.forEach(e=>{let t=e.pos+a;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;c+=e.weight*n}),c}function Ji(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}function Yi(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};e.barycenter!==void 0&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];t!==void 0&&r!==void 0&&(r.indegree++,t.out.push(r))}),Xi(Object.values(n).filter(e=>!e.indegree))}function Xi(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&Zi(e,t)}}function r(t){return n=>{n.in.push(t),--n.indegree===0&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>Or(e,[`vs`,`i`,`barycenter`,`weight`]))}function Zi(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function Qi(e,t,n,r,i){let a={},o=null,s=null,c=i;typeof t==`boolean`?(c=t,a={}):t&&(a=t,o=n??null,s=r??null);let l=Sr(e,e=>Object.hasOwn(e,`barycenter`)),u=l.lhs,d=l.rhs.sort((e,t)=>t.i-e.i),f=[],p=0,m=0,h=0;u.sort(ea(s,o,!!c));for(let[e,t]of Object.entries(a)){let n=u.findIndex(t=>t.vs[0]===e);u.splice(n+1,0,t)}h=$i(f,d,h),u.forEach(e=>{h+=e.vs.length,f.push(e.vs),p+=e.barycenter*e.weight,m+=e.weight,h=$i(f,d,h)});let g={vs:f.flat(1)};return m&&(g.barycenter=p/m,g.weight=m),g}function $i(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function ea(e,t,n){return(r,i)=>{if(r.barycenter<i.barycenter)return-1;if(r.barycenter>i.barycenter)return 1;if(e&&(typeof r.vs[0]==`string`||typeof i.vs[0]==`string`)){let n=Mr(t,e.node(r.vs[0]),e.node(i.vs[0]));if(n!==0)return n}return n?i.i-r.i:r.i-i.i}}function ta(e,t,n,r,i){var a,o;let s=null,c=i;typeof r==`boolean`?(c=r,s=null):r!==void 0&&(s=r);let l=e.children(t),u=e.node(t),d=u?u.borderLeft:void 0,f=u?u.borderRight:void 0,p={};d&&(l=l.filter(e=>e!==d&&e!==f));let m=Ji(e,l);m.forEach(t=>{if(e.children(t.v).length){let{result:r}=ta(e,t.v,n,s,c);p[t.v]=r,Object.hasOwn(r,`barycenter`)&&ra(t,r)}});let h=Yi(m,n);na(h,p);let g={},_=!1;for(let t=0;t<h.length;t++)for(let n=t+1;n<h.length;n++)if(h[t]&&h[n]&&(a=h[t])!=null&&a.barycenter&&(o=h[n])!=null&&o.barycenter&&h[t]?.barycenter===h[n].barycenter){let r=h[t]?.vs[0]??``,i=h[n]?.vs[0]??``,a=e.node(r),o=e.node(i);if(a.dummy===`edge`&&o.dummy===`edge`&&a.edgeObj?.v===o.edgeObj?.v&&a.edgeObj?.w===o.edgeObj?.w){if(a.edgeLabel.reversed){g[i]=h[t],h.splice(t,1),t--;break}g[r]=h[n],h.splice(n,1),n--}else _=!0}let v=Qi(h,g,s,e,c);if(d&&f){v.vs=[d,v.vs,f].flat(1);let t=e.predecessors(d);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(f),i=e.node(r[0]);Object.hasOwn(v,`barycenter`)||(v.barycenter=0,v.weight=0),v.barycenter=(v.barycenter*v.weight+n.order+i.order)/(v.weight+2),v.weight+=2}}return Object.defineProperty(v,"result",{value:v,enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(v,"usedBias",{value:_,enumerable:!1,configurable:!0,writable:!0}),v}function na(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function ra(e,t){e.barycenter===void 0?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}function ia(e,t,n,r){r||=e.nodes();let i=aa(e),a=new J({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let o=e.node(r),s=e.parent(r);if(o.rank===t||o.minRank<=t&&t<=o.maxRank){a.setNode(r),a.setParent(r,s||i);let c=e[n](r);c&&c.forEach(t=>{let n=t.v===r?t.w:t.v,i=a.edge(n,r),o=i===void 0?0:i.weight;a.setEdge(n,r,{weight:e.edge(t).weight+o})}),Object.hasOwn(o,`minRank`)&&a.setNode(r,{borderLeft:o.borderLeft[t],borderRight:o.borderRight[t]})}}),a}function aa(e){let t;for(;e.hasNode(t=Er(`_root`)););return t}function oa(e,t,n){let r={},i;n.forEach(n=>{let a=e.parent(n),o,s;for(;a;){if(o=e.parent(a),o?(s=r[o],r[o]=a):(s=i,i=a),s&&s!==a){t.setEdge(s,a);return}a=o}})}function sa(e,t={},n=null){if(typeof t.customOrder==`function`){t.customOrder(e,sa);return}let r=xr(e),i=ca(e,Dr(1,r+1),`inEdges`),a=ca(e,Dr(r-1,-1,-1),`outEdges`),o=Gi(e,n);if(ua(e,o),t.disableOptimalOrderHeuristic)return;let s=1/0,c,l=t.constraints||[];for(let t=0,r=0;r<4;++t,++r){la(t%2?i:a,t%4>=2,l,n),o=hr(e);let u=Ki(e,o);u<s?(r=0,c=Object.assign({},o),s=u):u===s&&(c=structuredClone(o))}ua(e,c)}function ca(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if(typeof n.rank==`number`&&i(n.rank,t),typeof n.minRank==`number`&&typeof n.maxRank==`number`)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&i(e,t)}return t.map(function(t){return ia(e,t,n,r.get(t)||[])})}function la(e,t,n,r){let i=!0,a=new J;e.forEach(function(e){n.forEach(e=>a.setEdge(e.left,e.right));let o=e.graph().root,{result:s,usedBias:c}=ta(e,o,a,r,i);t&&c&&(i=!i),s.vs.forEach((t,n)=>e.node(t).order=n),oa(e,a,s.vs)})}function ua(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function da(e,t){let n={};function r(t,r){let i=0,a=0,o=t.length,s=r[r.length-1];return r.forEach((t,c)=>{let l=pa(e,t),u=l?e.node(l).order:o;(l||t===s)&&(r.slice(a,c+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let a=e.node(r),o=a.order;(o<i||u<o)&&!(a.dummy&&e.node(t).dummy)&&ma(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function fa(e,t){let n={};function r(t,r,i,a,o){Dr(r,i).forEach(r=>{let i=t[r];if(i!==void 0&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(t===void 0)return;let r=e.node(t);r.dummy&&(r.order<a||r.order>o)&&ma(n,t,i)})}})}function i(t,n){let i=-1,a=-1,o=0;return n.forEach((s,c)=>{if(e.node(s).dummy===`border`){let t=e.predecessors(s);if(t&&t.length){let s=t[0];if(s===void 0)return;a=e.node(s).order,r(n,o,c,i,a),o=c,i=a}}r(n,o,n.length,a,t.length)}),n}return t.length&&t.reduce(i),n}function pa(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function ma(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function ha(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function ga(e,t,n,r,i){let a={},o={},s={};return t.forEach(e=>{e.forEach((e,t)=>{a[e]=e,o[e]=e,s[e]=t})}),t.forEach(t=>{let c=-1,l=-1,u=!1,d=t,f=t.findIndex(t=>i?.includes(t)||Ta(t,e,i));f>0&&(d=[t[f],...t.slice(0,f),...t.slice(f+1)],u=!0),d.forEach(t=>{let d=r(t);if(d&&d.length){i!=null&&i.includes(t)&&(d=d.filter(t=>Ta(t,e,i)));let r=d.sort((e,t)=>{let n=s[e],r=s[t];return(n===void 0?0:n)-(r===void 0?0:r)}),f=(r.length-1)/2;for(let e=Math.floor(f),i=Math.ceil(f);e<=i;++e){let i=r[e];if(i===void 0)continue;let d=s[i];if(d!==void 0&&o[t]===t&&c<d&&s[i]!==l&&!ha(n,t,i)){let e=a[i];e!==void 0&&(o[i]=t,o[t]=a[t]=e,c=d,u&&=(c=-1,l=s[i]??-1,!1))}}}})}),{root:a,align:o}}function _a(e,t,n,r,i=!1){let a={},o=va(e,t,n,i),s=i?`borderLeft`:`borderRight`;function c(e,t){let n=o.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}function l(e){let t=o.inEdges(e);t?a[e]=t.reduce((e,t)=>{let n=a[t.v]??0,r=o.edge(t);return Math.max(e,n+(r===void 0?0:r))},0):a[e]=0}function u(t){let n=o.outEdges(t),r=1/0;n&&(r=n.reduce((e,t)=>{let n=a[t.w],r=o.edge(t);return Math.min(e,(n===void 0?0:n)-(r===void 0?0:r))},1/0));let i=e.node(t);r!==1/0&&i.borderType!==s&&(a[t]=Math.max(a[t]===void 0?0:a[t],r))}function d(e){return o.predecessors(e)||[]}function f(e){return o.successors(e)||[]}return c(l,d),c(u,f),Object.keys(r).forEach(e=>{let t=n[e];t!==void 0&&(a[e]=a[t]??0)}),a}function va(e,t,n,r){let i=new J,a=e.graph(),o=Ca(a.nodesep,a.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let a=n[t];if(a!==void 0){if(i.setNode(a),r!==void 0){let s=n[r];if(s!==void 0){let n=i.edge(s,a);i.setEdge(s,a,Math.max(o(e,t,r),n||0))}}r=t}})}),i}function ya(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=wa(e,t)/2;r=Math.max(n+a,r),i=Math.min(n-a,i)});let a=r-i;return a<t[0]&&(t=[a,n]),t},[1/0,null])[1]}function ba(e,t){let n=Object.values(t),r=Y(Math.min,n),i=Y(Math.max,n);[`u`,`d`].forEach(n=>{[`l`,`r`].forEach(a=>{let o=n+a,s=e[o];if(!s||s===t)return;let c=Object.values(s),l=r-Y(Math.min,c);a!==`l`&&(l=i-Y(Math.max,c)),l&&(e[o]=kr(s,e=>e+l))})})}function xa(e,t=void 0){let n=e.ul;return n?kr(n,(n,r)=>{if(t){let n=e[t.toLowerCase()];if(n&&n[r]!==void 0)return n[r]}let i=Object.values(e).map(e=>{let t=e[r];return t===void 0?0:t}).sort((e,t)=>e-t);return((i[1]??0)+(i[2]??0))/2}):{}}function Sa(e,t){let n=hr(e),r=Object.assign(da(e,n),fa(e,n)),i={},a;return[`u`,`d`].forEach(o=>{a=o===`u`?n:Object.values(n).reverse(),[`l`,`r`].forEach(n=>{n===`r`&&(a=a.map(e=>Object.values(e).reverse()));let s=ga(e,a,r,t=>(o===`u`?e.predecessors(t):e.successors(t))||[],t),c=_a(e,a,s.root,s.align,n===`r`);n===`r`&&(c=kr(c,e=>-e)),i[o+n]=c})}),ba(i,ya(e,i)),xa(i,e.graph().align)}function Ca(e,t,n){return(r,i,a)=>{let o=r.node(i),s=r.node(a),c=0,l;if(c+=o.width/2,Object.hasOwn(o,`labelpos`))switch(o.labelpos.toLowerCase()){case`l`:l=-o.width/2;break;case`r`:l=o.width/2}if(l&&(c+=n?l:-l),l=void 0,c+=(o.dummy?t:e)/2,c+=(s.dummy?t:e)/2,c+=s.width/2,Object.hasOwn(s,`labelpos`))switch(s.labelpos.toLowerCase()){case`l`:l=s.width/2;break;case`r`:l=-s.width/2}return l&&(c+=n?l:-l),c}}function wa(e,t){return e.node(t).width}function Ta(e,t,n){if(!n)return!1;let r=t.node(e)?.edgeObj;if(!r||t.node(e).edgeLabel.reversed)return!1;let i=n.indexOf(r?.v),a=n.indexOf(r?.w);return i!==-1&&a!==-1&&i===(a+1)%n.length||i===(a-1)%n.length}function Ea(e,t){e=pr(e),Da(e),Object.entries(Sa(e,t)).forEach(([t,n])=>e.node(t).x=n)}function Da(e){let t=hr(e),n=e.graph(),r=n.ranksep,i=n.rankalign,a=0;t.forEach(t=>{let n=t.reduce((t,n)=>{let r=e.node(n).height??0;return t>r?t:r},0);t.forEach(t=>{let r=e.node(t);r.y=i===`top`?a+r.height/2:i===`bottom`?a+n-r.height/2:a+n/2}),a+=n+r})}var Oa=new WeakMap;function ka(e,t={}){return ja(e,wr,t),e}function Aa(e,t,n){let r=t;for(;r!==void 0;){let t=e.parent(r);if(t===n)return r;r=t}}function ja(e,t,n){let r=e.nodes().filter(t=>e.children(t).length),i={};r.forEach(r=>{let a=e.node(r);if(a&&a.rankdir){let o=new J({multigraph:!0,compound:!0});o.setGraph({rankdir:a.rankdir});let s=e.children(r);s.forEach(t=>{let n={...e.node(t)};o.setNode(t,n);let i=e.parent(t);i&&i!==r&&s.includes(i)&&o.setParent(t,i)});let c=new Set;e.edges().forEach(t=>{let n=Aa(e,t.v,r),i=Aa(e,t.w,r);if(n&&i&&n!==i){let r=`${n}\0${i}`;c.has(r)||(c.add(r),o.setEdge(n,i,{...e.edge(t)}))}}),ja(o,t,n);let l=Ha(o);Ma(l,t,n,null),Na(o,l);let u=1/0,d=1/0,f=-1/0,p=-1/0;o.nodes().forEach(e=>{if(e===r)return;let t=o.node(e);t&&typeof t.x==`number`&&typeof t.y==`number`&&typeof t.width==`number`&&typeof t.height==`number`&&(u=Math.min(u,t.x-t.width/2),f=Math.max(f,t.x+t.width/2),d=Math.min(d,t.y-t.height/2),p=Math.max(p,t.y+t.height/2))}),(!isFinite(u)||!isFinite(d)||!isFinite(f)||!isFinite(p))&&(u=d=0,f=p=0);let m=f-u,h=p-d;i[r]={minX:u,minY:d,maxX:f,maxY:p,width:m,height:h,offsetX:u,offsetY:d},a._dagreClusterSubgraph=o}});let a=[],o=t=>{let n=[],r=(e.children(t)||[]).filter(e=>e!==t);for(;r.length>0;){let t=r.shift();n.push(t),(e.children(t)||[]).filter(e=>e!==t).forEach(e=>r.push(e))}return n},s=new Map;r.forEach(t=>{let n=e.node(t);n&&n.rankdir&&i[t]&&s.set(t,(e.children(t)||[]).filter(e=>e!==t))});let c=new Set([...s.values()].flat()),l=new Map;s.forEach((e,t)=>{c.has(t)||l.set(t,o(t))});let u=new Set([...l.values()].flat()),d=e=>{for(let[t,n]of l)if(n.includes(e))return t;return e},f=[];e.edges().forEach(t=>{(u.has(t.v)||u.has(t.w))&&f.push({edge:t,label:e.edge(t)})});let p=new Map;u.forEach(t=>{let n=e.parent(t);p.set(t,typeof n==`string`?n:void 0)}),l.forEach((t,n)=>{let r=e.node(n),o=[];t.forEach(t=>{let n=e.node(t);n&&(o.push({id:t,node:n,parent:p.get(t)}),e.removeNode(t))});let s=f.filter(({edge:e})=>t.includes(e.v)||t.includes(e.w)),c=i[n];r&&(a.push({clusterId:n,subgraph:r._dagreClusterSubgraph,bounds:c,children:t,removedNodes:o,removedEdges:s}),r.width=c.width,r.height=c.height)});let m=new Set;f.forEach(({edge:t,label:n})=>{let r=d(t.v),i=d(t.w);if(r!==i&&e.hasNode(r)&&e.hasNode(i)){let t=`${r}\0${i}`;m.has(t)||(m.add(t),e.setEdge(r,i,{...n,width:0,height:0}))}});let h=Ha(e),g=Ma(h,t,n,Oa.get(e)??null);Oa.set(e,g),Na(e,h),m.forEach(t=>{let n=t.indexOf(`\0`),r=t.slice(0,n),i=t.slice(n+1);e.hasEdge(r,i)&&e.removeEdge(r,i)}),a.forEach(({clusterId:t,subgraph:n,bounds:r,removedNodes:i,removedEdges:a})=>{let o=e.node(t),s=o?.x??0,c=o?.y??0,l=(r.minX+r.maxX)/2,u=(r.minY+r.maxY)/2;i.forEach(({id:t,node:n,parent:r})=>{e.setNode(t,n),r!==void 0&&e.setParent(t,r)}),a.forEach(({edge:t,label:n})=>{e.setEdge(t,n)}),n.nodes().forEach(r=>{if(r===t)return;let i=n.node(r),a=e.node(r);a&&i&&typeof i.x==`number`&&typeof i.y==`number`&&(a.x=s+(i.x-l),a.y=c+(i.y-u))}),delete o._dagreClusterSubgraph}),r.forEach(t=>{let n=e.node(t),r=i[t];if(n&&n.rankdir&&n._dagreClusterSubgraph&&r){let i=n._dagreClusterSubgraph,a=n.x??0,o=n.y??0,s=(r.minX+r.maxX)/2,c=(r.minY+r.maxY)/2;i.nodes().forEach(n=>{if(n===t)return;let r=i.node(n),l=e.node(n);if(l&&r&&typeof r.x==`number`&&typeof r.y==`number`){let e=r.x-s,t=r.y-c;l.x=a+e,l.y=o+t}}),delete n._dagreClusterSubgraph}})}function Ma(e,t,n,r=null){var i,a;let o=n?.useDynamic!==!1,s=o&&(i=r?.graph)!=null?i:null,c=o&&(a=r?.rawNodes)!=null?a:null;t(` makeSpaceForEdgeLabels`,()=>Ua(e)),t(` removeSelfEdges`,()=>Qa(e)),t(` acyclic`,()=>Gr(e,s)),t(` nestingGraph.run`,()=>ki(e)),t(` rank`,()=>bi(pr(e))),t(` injectEdgeLabelProxies`,()=>Wa(e)),t(` removeEmptyRanks`,()=>_r(e)),t(` nestingGraph.cleanup`,()=>Ni(e)),t(` normalizeRanks`,()=>gr(e)),t(` assignRankMinMax`,()=>Ga(e)),t(` removeEdgeLabelProxies`,()=>Ka(e)),t(` normalize.run`,()=>Yr(e)),t(` parentDummyChains`,()=>Ti(e)),t(` addBorderSegments`,()=>Pi(e)),t(` order`,()=>sa(e,n,c)),t(` insertSelfEdges`,()=>$a(e)),t(` adjustCoordinateSystem`,()=>Li(e)),t(` position`,()=>Ea(e,n.corePath)),t(` positionSelfEdges`,()=>eo(e));let l=JSON.parse(JSON.stringify(e._nodes));return t(` removeBorderNodes`,()=>Za(e)),t(` normalize.undo`,()=>Zr(e)),t(` fixupEdgeLabelCoords`,()=>Ya(e)),t(` undoCoordinateSystem`,()=>Ri(e)),t(` translateGraph`,()=>qa(e)),t(` assignNodeIntersects`,()=>Ja(e)),t(` reversePoints`,()=>Xa(e)),t(` acyclic.undo`,()=>qr(e)),{graph:e,rawNodes:l}}function Na(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,`x`)&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var Pa=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],Fa={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},Ia=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],La=[`width`,`height`,`rank`],Ra={width:0,height:0},za=[`minlen`,`weight`,`width`,`height`,`labeloffset`],Ba={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},Va=[`labelpos`];function Ha(e){let t=new J({multigraph:!0,compound:!0}),n=no(e.graph());return t.setGraph(Object.assign({},Fa,to(n,Pa),Or(n,Ia))),e.nodes().forEach(n=>{let r=to(no(e.node(n)),La);Object.keys(Ra).forEach(e=>{r[e]===void 0&&(r[e]=Ra[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=no(e.edge(n));t.setEdge(n,Object.assign({},Ba,to(r,za),Or(r,Va)))}),t}function Ua(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,(r.labelpos??`r`).toLowerCase()!==`c`&&(t.rankdir===`TB`||t.rankdir===`BT`?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function Wa(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);dr(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function Ga(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function Ka(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`edge-proxy`){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function qa(e){let t=1/0,n=0,r=1/0,i=0,a=e.graph(),o=a.marginx||0,s=a.marginy||0;function c(e){let a=e.x,o=e.y,s=e.width,c=e.height;t=Math.min(t,a-s/2),n=Math.max(n,a+s/2),r=Math.min(r,o-c/2),i=Math.max(i,o+c/2)}e.nodes().forEach(t=>c(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,`x`)&&c(n)}),t-=o,r-=s,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,`x`)&&(i.x-=t),Object.hasOwn(i,`y`)&&(i.y-=r)}),a.width=n-t+o,a.height=i-r+s}function Ja(e){e.edges().forEach(t=>{if(t.v===t.w)return;let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),a,o;n.points?(a=n.points[0],o=n.points[n.points.length-1]):(n.points=[],a=i,o=r),n.points.unshift(mr(r,a)),n.points.push(mr(i,o))})}function Ya(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,`x`))switch((n.labelpos===`l`||n.labelpos===`r`)&&(n.width-=n.labeloffset),n.labelpos){case`l`:n.x-=n.width/2+n.labeloffset;break;case`r`:n.x+=n.width/2+n.labeloffset}})}function Xa(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Za(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-a.x),n.height=Math.abs(i.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy===`border`&&e.removeNode(t)})}function Qa(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||=[],n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function $a(e){hr(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);typeof i.rank!=`number`&&(i.rank=0),i.order=r+n,(i.selfEdges||[]).forEach(t=>{dr(e,`selfedge`,{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,edgeLabel:t.label},`_se`),(!Array.isArray(t.label.points)||t.label.points.length!==7)&&(t.label.points=[{x:0,y:-10},{x:0,y:-10},{x:0,y:0},{x:0,y:10},{x:0,y:10},{x:0,y:0},{x:0,y:0}])}),delete i.selfEdges})})}function eo(e){e.nodes().forEach(t=>{let n=e.node(t),r=e=>typeof e==`number`&&isFinite(e);if(n.dummy===`selfedge`){let i=n,a=e.node(i.e.v),o=r(a?.x)?a.x:0,s=r(a?.y)?a.y:0,c=r(a?.width)?a.width:0,l=r(a?.height)?a.height:0,u=r(n.x)?n.x:o,d=r(n.y)?n.y:s,f=c/2,p=l/2;i.edgeLabel.points=[{x:u+f,y:d-p},{x:u+f,y:d-p},{x:u,y:d},{x:u-f,y:d+p},{x:u-f,y:d+p},{x:u,y:d},{x:u,y:d}],i.edgeLabel.x=u,i.edgeLabel.y=d,e.setEdge(i.e,i.edgeLabel),e.removeNode(t)}else n&&Array.isArray(n.selfEdges)&&n.selfEdges.forEach(e=>{if(!Array.isArray(e.label.points)||e.label.points.length!==7){let t=r(n.x)?n.x:0,i=r(n.y)?n.y:0,a=r(n.width)?n.width:0,o=r(n.height)?n.height:0,s=a/2,c=o/2;e.label.points=[{x:t+s,y:i-c},{x:t+s,y:i-c},{x:t,y:i},{x:t-s,y:i+c},{x:t-s,y:i+c},{x:t,y:i},{x:t,y:i}]}})})}function to(e,t){return kr(Or(e,t),Number)}function no(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}function ro(e){let t=hr(e),n=new J({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{n.setNode(t,{label:t}),n.setParent(t,`layer`+e.node(t).rank)}),e.edges().forEach(e=>n.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r=`layer`+t;n.setNode(r,{rank:`same`}),e.reduce((e,t)=>(n.setEdge(e,t,{style:`invis`}),t))}),n}var io={graphlib:En,version:Nr,layout:ka,debug:ro,util:{time:Cr,notime:wr}};function ao(e,t){let n=t.steps.map(e=>e.type===`agent`?`${e.id}:${e.model??``}:${e.tools.join(`+`)}:${e.output.format}`:e.type===`generate`?`${e.id}:${e.asset}:${e.model??``}:${e.options?.duration??``}`:e.id).join(`|`);return i({queryKey:[`estimate`,e,n],queryFn:()=>L.get(`/api/studio/wizards/${e}/estimate`),staleTime:3e4,refetchOnMount:`always`})}var oo=e=>e<10?e.toLocaleString(void 0,{maximumFractionDigits:1}):Math.round(e).toLocaleString();function so({estimate:e,stepId:t}){let n=e?.available?e.steps[t]:void 0;return n?(0,q.jsxs)(`p`,{className:`text-[0.75rem] text-ink-3 tabular-nums`,children:[I(`estimate.step`,{n:oo(n.credits),high:oo(n.high)}),` · `,n.measured?I(`estimate.measured`):I(`estimate.formula`)]}):null}function co({model:e,effort:t,onChange:n}){let r=I(`class.effortAuto`);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(P,{children:I(`class.label`)}),(0,q.jsx)(W,{value:e??`high`,onChange:e=>n({model:e,effort:t}),options:te.map(e=>({value:e,label:I(`class.${e}`)}))}),(0,q.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:I(`class.${e??`high`}.hint`)}),(0,q.jsx)(P,{children:I(`class.effort`)}),(0,q.jsx)(H,{value:t?I(`class.effort.${t}`):r,options:[r,...p.map(e=>I(`class.effort.${e}`))],onChange:t=>n({model:e,effort:p.find(e=>I(`class.effort.${e}`)===t)})})]})}var lo=280,uo=92;function fo({data:e}){let{step:t,selected:n,issue:r,active:i,pulse:a,cost:o,passed:s,onAddAfter:c}=e,l=wt(t);return(0,q.jsxs)(`div`,{className:T(`group relative w-[280px] cursor-pointer rounded-xl bg-card px-4 py-3 text-left shadow-soft ring-1 transition`,n?`shadow-elevated ring-2 ring-ember`:i?`ring-2 ring-moss`:a?`ring-2 ring-ember/60`:`ring-border-soft hover:shadow-elevated`),children:[i?(0,q.jsx)(`span`,{className:`-top-1 -right-1 absolute size-3 animate-breathe rounded-full bg-moss`}):a?(0,q.jsx)(`span`,{className:`-top-1 -right-1 absolute size-3 animate-breathe rounded-full bg-ember`}):null,(0,q.jsx)(Mt,{type:`target`,position:Ot.Top}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:T(`inline-flex size-6 items-center justify-center rounded-md`,Be[t.type]),children:(0,q.jsx)(l,{className:`size-3.5`})}),(0,q.jsx)(`span`,{className:`font-medium text-[0.6875rem] text-ink-3 uppercase tracking-[0.07em]`,children:He(t)}),r?(0,q.jsx)(ke,{className:`ml-auto size-4 text-rose`}):s&&!i?(0,q.jsx)(A,{className:`ml-auto size-4 text-moss`}):o===null?null:(0,q.jsxs)(`span`,{className:`ml-auto text-[0.6875rem] text-ink-3 tabular-nums`,children:[`≈`,` `,I(`nav.credits`,{n:o<10?o.toLocaleString(void 0,{maximumFractionDigits:1}):Math.round(o)})]})]}),(0,q.jsx)(`div`,{className:`mt-1.5 truncate font-display font-semibold text-[0.9375rem] text-ink`,children:t.title}),(0,q.jsx)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:tt(t)||`\xA0`}),(0,q.jsx)(Mt,{type:`source`,position:Ot.Bottom}),c?(0,q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},className:T(`nodrag nopan -translate-x-1/2 -translate-y-1/2 absolute top-full left-1/2 z-10 inline-flex h-7 items-center gap-1.5 whitespace-nowrap rounded-full bg-card px-3 text-[0.75rem] text-ember-strong shadow-soft ring-1 ring-ember/40 transition hover:bg-ember-tint focus-visible:opacity-100`,n?`opacity-100`:`pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100`),children:[(0,q.jsx)(m,{className:`size-3.5`}),` `,I(`addStep.add`)]}):null]})}function po({data:e}){return(0,q.jsxs)(`div`,{className:T(`flex w-[280px] cursor-pointer items-center gap-3 rounded-full bg-paper-2 py-1.5 pr-5 pl-2 transition`,e.selected?`ring-2 ring-ember`:`hover:bg-paper-3`),children:[(0,q.jsx)(Ke,{kind:e.avatar,size:40,interactive:!1}),(0,q.jsx)(`span`,{className:`truncate font-display font-semibold text-[0.9375rem]`,children:e.title}),(0,q.jsx)(Mt,{type:`source`,position:Ot.Bottom})]})}function mo({data:e}){return(0,q.jsxs)(`div`,{className:`w-[280px] rounded-xl border border-ember/50 border-dashed bg-card/70 px-4 py-3 text-left`,children:[(0,q.jsx)(Mt,{type:`target`,position:Ot.Top}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[0.75rem] text-ember-strong`,children:[(0,q.jsx)(j,{className:`size-3.5`}),` `,I(`addStep.building`)]}),(0,q.jsx)(`div`,{className:`mt-1.5 line-clamp-2 text-[0.8125rem] text-ink-2`,children:e.prompt}),(0,q.jsx)(Mt,{type:`source`,position:Ot.Bottom})]})}function ho(e){let{data:t,sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o,targetPosition:s}=e,c={label:e.label,labelStyle:e.labelStyle,labelBgStyle:e.labelBgStyle,labelBgPadding:e.labelBgPadding,labelBgBorderRadius:e.labelBgBorderRadius,style:e.style,markerEnd:e.markerEnd};if(!t?.points.length){let[e,t,l]=At({sourceX:n,sourceY:r,targetX:i,targetY:a,sourcePosition:o,targetPosition:s});return(0,q.jsx)(Pt,{path:e,labelX:t,labelY:l,...c})}let l=[{x:n,y:r},...t.points,{x:i,y:a}],u=l.map((e,t)=>{let n=l[t-1];if(!n)return`M ${e.x} ${e.y}`;let r=(n.y+e.y)/2;return`C ${n.x} ${r} ${e.x} ${r} ${e.x} ${e.y}`}).join(` `);return(0,q.jsx)(Pt,{path:u,labelX:t.labelX,labelY:t.labelY,...c})}var go={step:fo,start:po,adding:mo},_o={branch:ho},X=`__adding`,vo=34,yo={},bo={};function xo(e,t){if(t)return Object.fromEntries(Object.entries(t).filter(([t,n])=>JSON.stringify(e.steps.find(e=>e.id===t)?.next??[])===JSON.stringify(n.over)))}function So(e){return`${Math.round(e*100)} %`}function Co(e){let t=e.ask?I(`editor.whenAsk`,{text:e.ask}):D(e)?I(`editor.otherwise`):d(e.when).map(wo).join(` · `);return e.max?`${t} (${I(`editor.atMost`,{count:e.max})})`:t}function wo(e){let t=Array.isArray(e.value)?e.value.join(` / `):String(e.value??``);switch(e.op){case`equals`:return`${e.field} = ${t}`;case`notEquals`:return`${e.field} ≠ ${t}`;case`in`:return`${e.field} ∈ ${t}`;case`notEmpty`:return I(`editor.whenFilled`,{field:e.field});case`empty`:return I(`editor.whenEmpty`,{field:e.field});case`gt`:return`${e.field} > ${t}`;case`lt`:return`${e.field} < ${t}`;case`contains`:return I(`editor.whenContains`,{field:e.field,value:t})}}function To(e,t,n,r,i,a,o,s,c,l){let u=new io.graphlib.Graph;u.setGraph({rankdir:`TB`,nodesep:48,ranksep:46,marginx:20,marginy:20}),u.setDefaultEdgeLabel(()=>({})),u.setNode(`__start`,{width:lo,height:52});for(let t of e.steps)u.setNode(t.id,{width:lo,height:uo});let d=[],f={markerEnd:{type:Nt.ArrowClosed,width:14,height:14,color:`var(--ink-4)`}};c&&u.setNode(X,{width:lo,height:uo});let p=(t,n,r,i={})=>{let a=e.steps[r]?.id;if(c?.at===r){u.setEdge(n,X),d.push({id:t,source:n,target:X,...i,...f}),a&&(u.setEdge(X,a),d.push({id:`${t}-adding`,source:X,target:a,...f}));return}a&&(u.hasEdge(n,a)||u.setEdge(n,a),d.push({id:t,source:n,target:a,...i,...f}))};(e.steps[0]||c)&&p(`e-start`,`__start`,0),e.steps.forEach((t,n)=>{let r=e.steps[n+1],i=s[t.id],a=i&&i.rule!==null?t.next?.[i.rule]?.goto:void 0,o=new Map;for(let n of t.next??[])n.goto!==`end`&&e.steps.some(e=>e.id===n.goto)&&o.set(n.goto,[...o.get(n.goto)??[],Co(n)]);for(let[e,n]of o){let r=n.join(` · `),o=r.length>vo?`${r.slice(0,33)}…`:r,s=a===e?i?.probabilities?.[`r${i.rule}`]:void 0,c=a===e,l=c?`✓ ${o}${s===void 0?``:` · ${So(s)}`}`:o;u.setEdge(t.id,e,{width:l.length*6.2+16,height:22,labelpos:`c`}),d.push({id:`b-${t.id}-${e}`,type:`branch`,source:t.id,target:e,label:l,className:`cursor-pointer`,labelStyle:{fontSize:11,fill:c?`var(--moss)`:`var(--ink-2)`},labelBgStyle:{fill:`var(--paper-2)`},labelBgPadding:[6,3],labelBgBorderRadius:8,style:c?{strokeDasharray:`5 4`,stroke:`var(--moss)`,strokeWidth:2}:{strokeDasharray:`5 4`},...f})}if((r||c?.at===n+1)&&t.type!==`result`&&!t.next?.some(D)){let e=i?.rule===null,r=e?i?.probabilities?.none:void 0;p(`n-${t.id}`,t.id,n+1,{...t.next?.length?{label:e?`✓ ${I(`editor.otherwise`)}${r===void 0?``:` · ${So(r)}`}`:I(`editor.otherwise`),className:`cursor-pointer`,labelStyle:{fontSize:11,fill:e?`var(--moss)`:`var(--ink-3)`},labelBgStyle:{fill:`var(--background)`},...e?{style:{stroke:`var(--moss)`,strokeWidth:2}}:{}}:{}})}}),io.layout(u);for(let e of d){if(e.type!==`branch`)continue;let t=u.edge(e.source,e.target),n=(t.points??[]).slice(1,-1);n.length&&t.x!==void 0&&t.y!==void 0&&(e.data={points:n,labelX:t.x,labelY:t.y})}return{nodes:[{id:`__start`,type:`start`,position:{x:u.node(`__start`).x-lo/2,y:u.node(`__start`).y-26},data:{title:e.title,avatar:e.avatar,selected:t===`__wizard`},draggable:!1},...e.steps.map((e,s)=>{let c=u.node(e.id);return{id:e.id,type:`step`,position:{x:c.x-lo/2,y:c.y-uo/2},data:{step:e,selected:t===e.id,issue:n.has(e.id),index:s,active:r===e.id,pulse:i.includes(e.id),cost:a[e.id]?.credits??null,passed:o.has(e.id),onAddAfter:l&&e.type!==`result`?()=>l(s+1):void 0},draggable:!1}}),...c?[{id:X,type:`adding`,position:{x:u.node(X).x-lo/2,y:u.node(X).y-uo/2},data:{prompt:c.prompt},draggable:!1,selectable:!1}]:[]],edges:d}}function Eo(){let e=jt(),t=`inline-flex size-8 items-center justify-center rounded-full text-ink-3 hover:bg-accent hover:text-ink`;return(0,q.jsxs)(`div`,{className:`absolute bottom-4 left-4 z-10 flex items-center gap-0.5 rounded-full bg-card p-1 shadow-soft ring-1 ring-border-soft`,children:[(0,q.jsx)(`button`,{type:`button`,className:t,onClick:()=>e.zoomOut(),"aria-label":`Zoom out`,children:(0,q.jsx)(en,{className:`size-4`})}),(0,q.jsx)(`button`,{type:`button`,className:t,onClick:()=>e.fitView({padding:.2,duration:300}),"aria-label":`Fit`,children:(0,q.jsx)(sn,{className:`size-4`})}),(0,q.jsx)(`button`,{type:`button`,className:t,onClick:()=>e.zoomIn(),"aria-label":`Zoom in`,children:(0,q.jsx)(o,{className:`size-4`})})]})}var Do=.8,Oo=new Set;function ko({def:e,selected:t,onSelect:n,issueSteps:r,activeStep:i,pulse:a,costs:o=yo,passed:s=Oo,minFitZoom:c=Do,fitKey:l,decisions:u=bo,onBranch:d,adding:f=null,onInsert:p}){let{nodes:m,edges:h}=(0,K.useMemo)(()=>To(e,t,r,i,a??[],o,s,u,f,p),[e,t,r,i,a,o,s,u,f,p]),g=jt(),_=(0,K.useRef)(null),v=e.steps.map(e=>e.id).join(`|`)+(f?`+${f.at}`:``);return(0,K.useEffect)(()=>{let e=requestAnimationFrame(()=>{let e=_.current;if(!e||!m.length)return;let t=m.map(e=>e.position.x),n=m.map(e=>e.position.y),r={x:Math.min(...t),y:Math.min(...n),width:Math.max(...t)+lo-Math.min(...t),height:Math.max(...n)+uo-Math.min(...n)},i=Math.min(e.clientWidth/(r.width*1.2),e.clientHeight/(r.height*1.15),1),a=Math.max(i,c),o=(e.clientWidth-r.width*a)/2-r.x*a,s=i>=c?(e.clientHeight-r.height*a)/2-r.y*a:24-r.y*a;g.setViewport({x:o,y:s,zoom:a},{duration:400})});return()=>cancelAnimationFrame(e)},[v,l,g]),(0,q.jsx)(`div`,{ref:_,className:`h-full w-full`,children:(0,q.jsx)(Dt,{nodes:m,edges:h,nodeTypes:go,edgeTypes:_o,onNodeClick:(e,t)=>{t.id!==X&&n(t.id===`__start`?`__wizard`:t.id)},onEdgeClick:(t,r)=>{let i=e.steps.find(e=>e.id===(r.source===X?``:r.source));i?.next?.length&&d?d(i.id):i&&n(i.id)},onPaneClick:()=>n(null),nodesConnectable:!1,nodesDraggable:!1,elementsSelectable:!1,panOnScroll:!0,zoomOnScroll:!1,zoomOnPinch:!0,minZoom:.3,maxZoom:1.4,proOptions:{hideAttribution:!0},children:(0,q.jsx)(Eo,{})})})}function Ao(e){return(0,q.jsx)(kt,{children:(0,q.jsx)(ko,{...e})})}function jo({wizardId:e,...t}){let n=ao(e,t.def);return(0,q.jsx)(Ao,{...t,costs:n.data?.available?n.data.steps:yo})}var Mo=1200;function No({label:e,onDelete:t}){let[n,r]=(0,K.useState)(!1),[i,a]=(0,K.useState)(!1),o=(0,K.useRef)(null),s=(0,K.useRef)(null),c=(0,K.useRef)(!1);(0,K.useEffect)(()=>()=>{for(let e of[o.current,s.current])e&&clearTimeout(e)},[]);let l=()=>{o.current||=(c.current=!1,a(!1),r(!0),setTimeout(()=>{o.current=null,c.current=!0,r(!1),t()},Mo))},u=()=>{o.current&&(clearTimeout(o.current),o.current=null,r(!1),c.current||(a(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>a(!1),1800)))},d=n||i;return(0,q.jsxs)(`button`,{type:`button`,"aria-label":`${e} – ${I(`editor.holdToDelete`)}`,title:I(`editor.holdToDelete`),onPointerDown:e=>{e.button===0&&l()},onPointerUp:u,onPointerLeave:u,onPointerCancel:u,onContextMenu:e=>e.preventDefault(),onKeyDown:e=>{(e.key===` `||e.key===`Enter`)&&!e.repeat&&(e.preventDefault(),l())},onKeyUp:e=>{(e.key===` `||e.key===`Enter`)&&u()},onBlur:u,className:T(`relative inline-flex h-9 shrink-0 touch-none select-none items-center justify-center gap-1.5 overflow-hidden rounded-full text-[0.75rem] transition-[width,background,color] duration-150`,d?`w-auto px-3 text-rose ring-1 ring-rose/40`:`w-9 text-ink-3 hover:bg-accent hover:text-rose`),children:[(0,q.jsx)(`span`,{"aria-hidden":!0,className:T(`absolute inset-y-0 left-0 bg-rose/25`,n?`w-full transition-[width] ease-linear`:`w-0`),style:n?{transitionDuration:`${Mo}ms`}:void 0}),(0,q.jsx)(v,{className:`relative size-4`}),d?(0,q.jsx)(`span`,{className:`relative whitespace-nowrap`,children:I(n?`editor.deleting`:`editor.holdToDelete`)}):null]})}var Po=/preis|price|umsatz|revenue|betrag|amount|anzahl|count|summe|sum|total|wert|value|menge|score|punkte|kosten|cost/i;function Fo(e){return new Set(e.flatMap(e=>{let t=e.valueKey;return typeof t==`string`?[t]:[]}))}var Io=[1240,860,420,310];function Lo(e){return Io.slice(0,3).map((t,n)=>Object.fromEntries(e.map(e=>[e.key,e.number?t:`${e.label} ${n+1}`])))}function Ro(e,t,n){let r=Fo(n),i=e=>r.has(e)||Po.test(e),a=e.steps.flatMap(e=>e.type===`page`?e.fields:[]),o=t=>{let n=g(t),r=k(n);if(r)return Lo((e.lists?.find(e=>e.id===r)?.columns??[]).map(e=>({key:e.id,label:e.name,number:e.type===`number`||i(e.id)})));if(n===`today`)return new Date().toLocaleDateString();if(n.startsWith(`brand.`))return I(`surface.sampleBrand`);let[o,s,c]=n.split(`.`);if(o===`steps`){let t=e.steps.find(e=>e.id===s);if(t?.type!==`agent`)return null;let n=t.output.fields??[],r=e=>{switch(e.kind){case`number`:return 42;case`list`:return[1,2,3].map(t=>`${e.id} ${t}`);case`table`:return Lo((e.columns??[`name`]).map(e=>({key:e,label:e,number:i(e)})));case`yesno`:return!0;case`choice`:case`score`:return e.options?.[0]??``;default:return I(`surface.sampleText`)}};if(c){let e=n.find(e=>e.id===c);return e?r(e):null}return n.length?Object.fromEntries(n.map(e=>[e.id,r(e)])):I(`surface.sampleText`)}let l=a.find(e=>e.id===n);return l?l.kind===`number`?42:l.options?.[0]??l.label:null};return Object.fromEntries(Object.entries(t.data).map(([e,t])=>[e,o(t)]))}function zo(e){let t=[],n=/("(?:\\.|[^"\\])*")(\s*:)?|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)|(\btrue\b|\bfalse\b|\bnull\b)|([{}[\],])/g,r=0;for(let i of e.matchAll(n)){let n=i.index??0;n>r&&t.push(e.slice(r,n));let[a,o,s,c,l,u]=i;o===void 0?c===void 0?l===void 0?u===void 0?t.push(a):t.push((0,q.jsx)(`span`,{className:`text-slate-400`,children:u},n)):t.push((0,q.jsx)(`span`,{className:`text-violet-300`,children:l},n)):t.push((0,q.jsx)(`span`,{className:`text-emerald-300`,children:c},n)):(t.push((0,q.jsx)(`span`,{className:s?`text-sky-300`:`text-amber-200`,children:o},n)),s&&t.push((0,q.jsx)(`span`,{className:`text-slate-400`,children:s},`${n}:`))),r=n+a.length}return t.push(e.slice(r)),t}function Bo({value:e,onChange:t,onBlur:n}){let r=(0,K.useRef)(null),i=(0,K.useRef)(null),a=()=>{r.current&&i.current&&(r.current.scrollTop=i.current.scrollTop,r.current.scrollLeft=i.current.scrollLeft)},o=`m-0 whitespace-pre break-normal px-3 py-2.5 font-mono text-[0.75rem] leading-[1.6] [tab-size:2]`;return(0,q.jsxs)(`div`,{className:`relative h-[28rem] overflow-hidden rounded-lg bg-[oklch(20%_0.03_260)] ring-1 ring-border focus-within:ring-focus`,children:[(0,q.jsxs)(`pre`,{ref:r,"aria-hidden":!0,className:T(o,`absolute inset-0 overflow-hidden text-slate-200`),children:[zo(e),`
2
+ `]}),(0,q.jsx)(`textarea`,{ref:i,spellCheck:!1,"aria-label":I(`editor.surfaceJson`),value:e,onChange:e=>t(e.target.value),onBlur:n,onScroll:a,className:T(o,`absolute inset-0 h-full w-full resize-none overflow-auto bg-transparent text-transparent caret-white outline-none selection:bg-sky-400/30`)})]})}function Vo({def:e,step:t,set:n,section:r}){let i={...t.components?{components:t.components}:{},...t.candidates?{candidates:t.candidates,groups:t.groups}:{},data:t.data},a=JSON.stringify(i,null,2),[o,s]=(0,K.useState)(a),[l,u]=(0,K.useState)(null),[d,f]=(0,K.useState)(`preview`);(0,K.useEffect)(()=>{document.activeElement?.getAttribute(`aria-label`)!==I(`editor.surfaceJson`)&&(s(a),u(null))},[a]);let p=(0,K.useMemo)(()=>t.components??ne(t.candidates??[],(t.candidates??[]).map(e=>e.id)),[t.components,t.candidates]),m=(0,K.useMemo)(()=>Ro(e,t,p),[e,t,p]),h=()=>{if(o===a)return!0;try{let e=JSON.parse(o);return u(null),n({...t,...e}),!0}catch(e){return u(e.message),!1}},g=d===`preview`?(0,q.jsx)(z,{label:I(`surface.code`),className:`absolute top-2 right-2 z-10 size-8`,onClick:()=>f(`code`),children:(0,q.jsx)(Ht,{className:`size-4`})}):(0,q.jsx)(z,{label:I(`surface.preview`),className:`absolute top-2 right-4 z-10 size-8 text-slate-300 hover:bg-white/10 hover:text-white`,onClick:()=>{h()&&f(`preview`)},children:(0,q.jsx)(ct,{className:`size-4`})});return r(I(`type.surface`),d===`preview`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`relative rounded-xl bg-paper p-4 ring-1 ring-border-soft`,children:[g,(0,q.jsx)(c,{surface:{components:p,data:m},assetUrl:()=>``})]}),(0,q.jsx)(`p`,{className:`text-[0.75rem] text-ink-4`,children:I(`surface.sampleNote`)})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`relative`,children:[g,(0,q.jsx)(Bo,{value:o,onChange:s,onBlur:()=>void h()})]}),l?(0,q.jsx)(`p`,{className:`text-[0.75rem] text-rose`,children:l}):null]}))}var Ho=(0,K.createContext)(void 0),Uo={text:`Kurzer Text`,textarea:`Langer Text`,number:`Zahl`,select:`Auswahl`,multiselect:`Mehrfachauswahl`,date:`Datum`,email:`E-Mail`,url:`Link`,toggle:`Ja/Nein`,color:`Farbe`,image:`Bild-Upload`,file:`Datei-Upload`,items:`Positionen (Tabelle)`,connection:`Konto verbinden`,list:`Gespeicherte Liste`,location:`Standort`,audio:`Sprachnotiz`,signature:`Unterschrift`,slot:`Termin`},Wo={slot:It};function Go(e,t){let n=t===`image`||t===`file`;return{...e,kind:t,multiple:n?e.multiple:void 0,camera:t===`file`?e.camera:void 0,video:t===`file`?e.video:void 0,scan:t===`text`?e.scan:void 0}}var Ko=(0,K.createContext)(!1);function qo({className:e,children:t}){return(0,K.useContext)(Ko)?(0,q.jsx)(`fieldset`,{disabled:!0,className:T(`min-w-0`,e),children:t}):(0,q.jsx)(`div`,{className:e,children:t})}function Z({title:e,children:t,loose:n}){let r=`flex flex-col gap-4`;return(0,q.jsxs)(`div`,{className:`border-border-soft border-t px-5 py-5 first:border-t-0`,children:[e?(0,q.jsx)(`h4`,{className:`mb-3 font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.07em]`,children:e}):null,n?(0,q.jsx)(`div`,{className:r,children:t}):(0,q.jsx)(qo,{className:r,children:t})]})}function Jo(e,t,n){let r=e.steps.indexOf(t),i=[];for(let t of e.steps.slice(0,r))t.type===`page`?i.push(...t.fields.map(e=>e.id)):t.type===`agent`&&i.push(...(t.output.fields??[]).map(e=>`steps.${t.id}.${e.id}`));return i.push(...t.fields.filter(e=>e.id!==n.id).map(e=>e.id)),i.push(...(e.lists??[]).map(e=>`lists.${e.id}.count`)),i}function Yo(e,t){let n=e.steps.indexOf(t),r=[];for(let t of e.steps.slice(0,n))if(t.type===`agent`)for(let e of t.output.fields??[])e.kind===`list`?r.push(`steps.${t.id}.${e.id}`):e.kind===`table`&&r.push(...(e.columns??[]).map(n=>`steps.${t.id}.${e.id}.${n}`));for(let t of e.lists??[])t.shared||r.push(...t.columns.map(e=>`lists.${t.id}.${e.id}`));return r}function Xo(e,t){let n=e.steps.flatMap(e=>e.type===`page`?e.fields:[]).find(e=>e.id===t);return n?n.label:t}function Zo({def:e,when:t,sources:n,onChange:r,label:i=I(`editor.shownWhen`),noneLabel:a=I(`editor.shownAlways`)}){let[o,...s]=d(t),c=e=>r(e?s.length?[e,...s]:e:s.length?s:void 0),l=o&&o.op!==`empty`&&o.op!==`notEmpty`;return(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:i}),(0,q.jsx)(W,{value:o?.field??``,placeholder:a,onChange:e=>c(e?{field:e,op:o?.op??`equals`,value:o?.value??``}:null),options:[{value:``,label:a},...n.map(t=>({value:t,label:Xo(e,t)}))]}),o?(0,q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,q.jsx)(W,{value:o.op,onChange:e=>{let t=e,n=t===`empty`||t===`notEmpty`?void 0:t===`in`?String(o.value??``).split(`,`).map(e=>e.trim()).filter(Boolean):t===`gt`||t===`lt`?Number(o.value)||0:Array.isArray(o.value)?o.value.join(`, `):o.value??``;c({field:o.field,op:t,...n===void 0?{}:{value:n}})},options:u.map(e=>({value:e,label:I(`editor.op.${e}`)}))}),l?(0,q.jsx)(F,{"aria-label":I(`editor.conditionValue`),placeholder:I(`editor.conditionValue`),value:Array.isArray(o.value)?o.value.join(`, `):String(o.value??``),onChange:e=>{let t=e.target.value,n=o.op===`in`?t.split(`,`).map(e=>e.trim()):o.op===`gt`||o.op===`lt`?Number(t.replace(`,`,`.`))||0:t===`true`||t===`false`?t===`true`:t;c({...o,value:n})}}):null]}):null,s.length?(0,q.jsx)(`span`,{className:`text-[0.75rem] text-ink-4`,children:I(`editor.conditionsMore`,{count:s.length})}):null]})}function Qo({def:e,page:t,field:n,onChange:r,onRemove:i,onMove:a}){let[o,s]=(0,K.useState)(!1),c=Wo[n.kind];return(0,q.jsxs)(`div`,{className:`rounded-lg bg-paper ring-1 ring-border-soft`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left`,children:[(0,q.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:[n.label,n.required?(0,q.jsx)(`span`,{className:`ml-1 text-ember`,children:`*`}):null]}),(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[0.75rem] text-ink-4`,children:[c?(0,q.jsx)(c,{className:`size-3.5`}):null,Uo[n.kind]]}),(0,q.jsx)(ce,{className:T(`size-4 text-ink-4 transition`,o&&`rotate-180`)})]}),o?(0,q.jsxs)(qo,{className:`flex flex-col gap-3 border-border-soft border-t px-3 py-3`,children:[(0,q.jsx)(F,{value:n.label,onChange:e=>r({...n,label:e.target.value})}),(0,q.jsx)(W,{value:n.kind,onChange:e=>r(Go(n,e)),options:S.filter(e=>e!==`items`||n.kind===`items`).map(e=>({value:e,label:Uo[e]}))}),(n.kind===`select`||n.kind===`multiselect`||n.kind===`slot`)&&(n.optionsFrom||Yo(e,t).length)?(0,q.jsx)(W,{value:n.optionsFrom??``,onChange:e=>r({...n,optionsFrom:e||void 0}),options:[{value:``,label:I(`editor.optionsFixed`)},...Yo(e,t).map(e=>({value:e,label:`${I(`editor.optionsFrom`)}: ${e}`}))]}):null,n.kind===`select`||n.kind===`multiselect`||n.kind===`slot`?(0,q.jsx)(F,{placeholder:n.kind===`slot`?`2026-10-12T09:00:00+02:00, 2026-10-12T09:30:00+02:00`:`Option A, Option B, Option C`,value:(n.options??[]).join(`, `),onChange:e=>r({...n,options:e.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)})}):null,n.kind===`connection`?(0,q.jsx)(W,{value:n.connection??``,placeholder:`Welches Konto?`,onChange:e=>r({...n,connection:e}),options:(e.connections??[]).map(e=>({value:e.id,label:e.title??e.id}))}):null,n.kind===`list`?(0,q.jsx)(W,{value:n.list??``,placeholder:`Welche Liste?`,onChange:e=>r({...n,list:e}),options:(e.lists??[]).map(e=>({value:e.id,label:e.title}))}):null,n.kind===`image`||n.kind===`file`?(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`Mehrere Dateien`}),(0,q.jsx)(w,{checked:!!n.multiple,onChange:e=>r({...n,multiple:e||void 0,...e?{}:{min:void 0,max:void 0}})})]}):null,(n.kind===`image`||n.kind===`file`)&&n.multiple?(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`Wie viele?`}),(0,q.jsx)(`div`,{className:`flex items-center gap-1.5`,children:[`min`,`max`].map(e=>(0,q.jsx)(F,{type:`number`,min:1,max:30,"aria-label":e===`min`?`Mindestens`:`Höchstens`,placeholder:e===`min`?`min.`:`max.`,value:n[e]??``,onChange:t=>{let i=Math.round(Number(t.target.value));r({...n,[e]:t.target.value&&i>=1?Math.min(i,30):void 0})},className:`h-8 w-16 text-right`},e))})]}):null,n.kind===`file`?(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`Auch mit der Kamera aufnehmen`}),(0,q.jsx)(w,{checked:!!n.camera,onChange:e=>r({...n,camera:e||void 0})})]}):null,n.kind===`file`?(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`Kamera nimmt auch kurze Videos auf`}),(0,q.jsx)(w,{checked:!!n.video,onChange:e=>r({...n,video:e||void 0})})]}):null,n.kind===`text`?(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`QR- oder Barcode scannen`}),(0,q.jsx)(w,{checked:!!n.scan,onChange:e=>r({...n,scan:e||void 0})})]}):null,[`text`,`textarea`,`number`,`email`,`url`,`location`].includes(n.kind)?(0,q.jsx)(F,{placeholder:`Platzhalter`,value:n.placeholder??``,onChange:e=>r({...n,placeholder:e.target.value||void 0})}):null,(0,q.jsx)(F,{placeholder:`Hilfetext`,value:n.help??``,onChange:e=>r({...n,help:e.target.value||void 0})}),(0,q.jsx)(Zo,{def:e,when:n.when,sources:Jo(e,t,n),onChange:e=>r({...n,when:e})}),n.group?null:(0,q.jsx)(F,{"aria-label":I(`editor.fieldAsk`),placeholder:I(`editor.fieldAsk`),value:n.ask??``,onChange:e=>r({...n,ask:e.target.value||void 0})}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:I(`run.required`)}),(0,q.jsx)(w,{checked:!!n.required,onChange:e=>r({...n,required:e})})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`font-mono text-[0.6875rem] text-ink-4`,children:`{{${n.id}}}`}),(0,q.jsxs)(`div`,{className:`flex`,children:[(0,q.jsx)(z,{label:I(`editor.moveUp`),onClick:()=>a(-1),className:`size-8`,children:(0,q.jsx)(he,{className:`size-3.5`})}),(0,q.jsx)(z,{label:I(`editor.moveDown`),onClick:()=>a(1),className:`size-8`,children:(0,q.jsx)(V,{className:`size-3.5`})}),(0,q.jsx)(z,{label:`Entfernen`,onClick:i,className:`size-8 hover:text-rose`,children:(0,q.jsx)(v,{className:`size-3.5`})})]})]})]}):null]})}var $o=[{label:`16:9`,width:1280,height:720},{label:`1:1`,width:1080,height:1080},{label:`4:5`,width:1080,height:1350},{label:`9:16`,width:1080,height:1920}];function es(e,t){let n=[];for(let r of e.steps.slice(0,t))r.type===`page`?n.push(...r.fields.map(e=>e.id)):r.type===`agent`?n.push(`steps.${r.id}`,...(r.output.fields??[]).map(e=>`steps.${r.id}.${e.id}`)):(r.type===`generate`||r.type===`widget`||r.type===`surface`)&&n.push(`steps.${r.id}`);return[...n,`brand.name`,`today`]}function ts({def:e,step:t,set:n,files:r,wizardId:i}){let a=r.filter(e=>e.mime===`text/html`),s=r.filter(e=>e.mime===`application/json`),c=t.size??$o[0],l=es(e,e.steps.indexOf(t)),u=Object.entries(t.data),d=e=>n({...t,data:Object.fromEntries(e)}),f=[r.find(e=>e.path===t.entry)?.hash.slice(0,8),r.find(e=>e.path===t.sample)?.hash.slice(0,8),c.width,c.height].join(`-`),p=r.some(e=>e.path===t.entry);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Z,{title:`Vorschau mit Beispieldaten`,children:p?(0,q.jsx)(ye,{src:ve(`/api/studio/wizards/${i}/widgets/${t.id}/preview?v=${f}`),page:c.width,height:c.height,fit:!0}):(0,q.jsx)(ns,{step:t,wizardId:i})}),(0,q.jsxs)(Z,{title:`Widget`,children:[(0,q.jsx)(P,{children:`HTML-Datei`}),(0,q.jsx)(W,{value:t.entry,onChange:e=>n({...t,entry:e}),options:(a.some(e=>e.path===t.entry)?a:[{path:t.entry},...a]).map(e=>({value:e.path,label:e.path}))}),(0,q.jsx)(P,{children:`Beispieldaten`}),(0,q.jsx)(W,{value:t.sample??``,onChange:e=>n({...t,sample:e||void 0}),options:[{value:``,label:`keine`},...s.map(e=>({value:e.path,label:e.path}))]}),(0,q.jsx)(P,{children:`Größe`}),(0,q.jsx)(H,{value:$o.find(e=>e.width===c.width&&e.height===c.height)?.label??``,options:$o.map(e=>e.label),onChange:e=>{let r=$o.find(t=>t.label===e);r&&n({...t,size:{width:r.width,height:r.height}})}})]}),(0,q.jsxs)(Z,{title:`Daten für das Widget`,children:[(0,q.jsx)(`datalist`,{id:`sources-${t.id}`,children:l.map(e=>(0,q.jsx)(`option`,{value:e},e))}),u.map(([e,n],r)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(F,{value:e,className:`w-28 font-mono text-[0.75rem]`,onChange:e=>d(u.map((t,n)=>n===r?[e.target.value,t[1]]:t))}),(0,q.jsx)(`span`,{className:`text-ink-4`,children:`←`}),(0,q.jsx)(F,{value:n,list:`sources-${t.id}`,className:`flex-1 font-mono text-[0.75rem]`,onChange:e=>d(u.map((t,n)=>n===r?[t[0],e.target.value]:t))}),(0,q.jsx)(z,{label:I(`editor.deleteStep`),onClick:()=>d(u.filter((e,t)=>t!==r)),children:(0,q.jsx)(v,{className:`size-4`})})]},r)),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>d([...u,[`wert${u.length+1}`,l[0]??`today`]]),className:`inline-flex h-8 items-center gap-1 self-start rounded-full px-2.5 text-[0.75rem] text-ink-2 hover:bg-accent`,children:[(0,q.jsx)(o,{className:`size-3.5`}),` Wert`]})]})]})}function ns({step:e,wizardId:t}){let n=(0,K.useContext)(Ho),i=(0,K.useContext)(Ko),a=r(),o=(0,K.useRef)(null),[s,c]=(0,K.useState)(``),[l,u]=(0,K.useState)(!1),[d,f]=(0,K.useState)(null);if(i)return(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`widget.missing`)});let p=()=>{if(!n)return;let t=I(`widget.buildMessage`,{title:e.title,what:s.trim()}).trim();n.ask(t)?(c(``),f(null)):f(I(`addStep.busy`))},h=async n=>{if(n){u(!0),f(null);try{let r=encodeURIComponent(e.entry).replace(/%2F/g,`/`),i=await fetch(ve(`/api/studio/wizards/${t}/files/${r}`),{method:`PUT`,credentials:`include`,headers:{"content-type":`text/html`},body:n});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error??i.statusText)}}catch(e){f(e.message)}finally{u(!1),await a.invalidateQueries({queryKey:[`wizard`,t]})}}};return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-border-strong border-dashed p-4`,children:[(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:I(`widget.missing`)}),n?(0,q.jsx)(U,{minRows:2,"aria-label":I(`widget.what`),placeholder:I(`widget.what`),value:s,onChange:e=>c(e.target.value)}):null,d?(0,q.jsx)(`p`,{className:`text-[0.75rem] text-rose`,children:d}):null,(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n?(0,q.jsxs)(R,{size:`sm`,onClick:p,children:[(0,q.jsx)(m,{className:`size-3.5`}),` `,I(`widget.build`)]}):null,(0,q.jsxs)(R,{variant:`ghost`,size:`sm`,busy:l,onClick:()=>o.current?.click(),children:[(0,q.jsx)(Re,{className:`size-3.5`}),` `,I(`widget.upload`)]}),(0,q.jsx)(`input`,{ref:o,type:`file`,accept:`text/html,.html,.htm`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,h(t)}})]})]})}function rs({def:e,step:t,set:n,mcpServers:r,files:i,wizardId:a}){let s=e.steps.indexOf(t),c=(0,K.useContext)(Ko),l=mt().plugins.flatMap(e=>e.tools),u=e.steps.slice(0,s).filter(e=>e.type===`agent`||e.type===`generate`||e.type===`widget`||e.type===`surface`);switch(t.type){case`widget`:return(0,q.jsx)(ts,{def:e,step:t,set:n,files:i,wizardId:a});case`surface`:return(0,q.jsx)(Vo,{def:e,step:t,set:n,section:(e,t)=>(0,q.jsx)(Z,{title:e,children:t})});case`page`:return(0,q.jsxs)(Z,{title:`Fragen`,loose:!0,children:[(0,q.jsx)(`div`,{className:`flex flex-col gap-2`,children:t.fields.map((r,i)=>(0,q.jsx)(Qo,{def:e,page:t,field:r,onChange:e=>n({...t,fields:t.fields.map((t,n)=>n===i?e:t)}),onRemove:()=>t.fields.length>1&&n({...t,fields:t.fields.filter((e,t)=>t!==i)}),onMove:e=>{let r=i+e;if(r<0||r>=t.fields.length)return;let a=[...t.fields];[a[i],a[r]]=[a[r],a[i]],n({...t,fields:a})}},r.id))}),c?null:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n({...t,fields:[...t.fields,{id:gn(e,`frage`),label:`Neue Frage`,kind:`text`}]}),className:`inline-flex h-9 items-center gap-1.5 self-start rounded-full px-3 text-[0.8125rem] text-ink-2 hover:bg-accent`,children:[(0,q.jsx)(o,{className:`size-4`}),` Frage hinzufügen`]})]});case`agent`:return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Z,{title:`Auftrag`,children:[(0,q.jsx)(U,{value:t.instructions,minRows:6,maxRows:20,onChange:e=>n({...t,instructions:e.target.value}),className:`text-[0.875rem]`}),(0,q.jsxs)(`p`,{className:`text-[0.75rem] text-ink-4`,children:[`Antworten einsetzen mit `,(0,q.jsx)(`code`,{className:`font-mono`,children:`{{feld}}`}),`, frühere Ergebnisse mit `,(0,q.jsx)(`code`,{className:`font-mono`,children:`{{steps.id}}`}),`.`]})]}),(0,q.jsxs)(Z,{title:`Werkzeuge`,children:[(0,q.jsx)(H,{multi:!0,value:t.tools,options:[...new Set([...f,...l.map(e=>e.id),...t.tools])],onChange:e=>n({...t,tools:e})}),(0,q.jsxs)(`div`,{className:`-mt-2 flex flex-wrap gap-x-3 text-[0.75rem] text-ink-4`,children:[f.map(e=>(0,q.jsxs)(`span`,{children:[e,` = `,We(e)]},e)),l.map(e=>(0,q.jsxs)(`span`,{children:[e.id,` = `,e.title]},e.id))]}),e.connections?.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{hint:`Konten, die die Person im Durchlauf verbindet. Der Schritt liest darin, er schreibt nie.`,children:`Konten der Person`}),(0,q.jsx)(H,{multi:!0,value:t.connections??[],options:e.connections.map(e=>e.id),onChange:e=>n({...t,connections:e.length?e:void 0})})]}):null,r.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{hint:`Nur freigegebene Systeme sind in diesem Schritt erreichbar.`,children:`Verbundene Systeme`}),(0,q.jsx)(H,{multi:!0,value:t.mcp??[],options:r.map(e=>e.id),onChange:e=>n({...t,mcp:e.length?e:void 0})})]}):null]}),(0,q.jsxs)(Z,{title:`Ergebnis`,children:[(0,q.jsx)(H,{value:t.output.format,options:[`text`,`markdown`,`json`],onChange:e=>n({...t,output:{...t.output,format:e}})}),(0,q.jsx)(co,{model:t.model,effort:t.effort,onChange:e=>n({...t,...e})}),(0,q.jsx)(F,{placeholder:`Text während der Arbeit, z. B. „Recherchiert …“`,value:t.working??``,onChange:e=>n({...t,working:e.target.value||void 0})})]})]});case`generate`:return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Z,{title:`Was wird erzeugt?`,children:[(0,q.jsx)(H,{value:t.asset,options:[`image`,`video`,`voice`,`document`,`dashboard`],onChange:e=>n({...t,asset:e})}),(0,q.jsx)(U,{value:t.prompt,minRows:5,maxRows:18,onChange:e=>n({...t,prompt:e.target.value}),className:`text-[0.875rem]`})]}),(0,q.jsxs)(Z,{title:`Optionen`,children:[t.asset===`document`||t.asset===`dashboard`?(0,q.jsx)(co,{model:t.model,effort:t.effort,onChange:e=>n({...t,...e})}):null,t.asset===`image`||t.asset===`video`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{children:`Format`}),(0,q.jsx)(H,{value:t.options?.aspectRatio??``,options:[...y],onChange:e=>n({...t,options:{...t.options,aspectRatio:e}})}),(0,q.jsx)(F,{placeholder:`Stil, z. B. „helle Fotografie, minimalistisch“`,value:t.options?.style??``,onChange:e=>n({...t,options:{...t.options,style:e.target.value||void 0}})})]}):null,t.asset===`video`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{children:`Länge (Sekunden)`}),(0,q.jsx)(H,{value:String(t.options?.duration??8),options:[`4`,`6`,`8`,`10`],onChange:e=>n({...t,options:{...t.options,duration:Number(e)}})}),(0,q.jsx)(P,{children:`Auflösung`}),(0,q.jsx)(H,{value:t.options?.resolution??`720p`,options:[...ee],onChange:e=>n({...t,options:{...t.options,resolution:e}})})]}):null,t.asset===`document`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(P,{children:`Vorlage`}),(0,q.jsx)(W,{value:t.options?.template??`free`,onChange:e=>n({...t,options:{...t.options,template:e}}),options:[`free`,`invoice`,`offer`,`briefing`,`letter`,`report`].map(e=>({value:e,label:e}))})]}):null]})]});case`review`:return(0,q.jsxs)(Z,{title:`Was wird gezeigt?`,children:[(0,q.jsx)(H,{multi:!0,value:t.show,options:u.map(e=>e.id),onChange:e=>e.length&&n({...t,show:e})}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`Text direkt bearbeitbar`}),(0,q.jsx)(w,{checked:!!t.edit,onChange:e=>n({...t,edit:e})})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-2`,children:`Neue Variante anfordern`}),(0,q.jsx)(w,{checked:!!t.regenerate,onChange:e=>n({...t,regenerate:e})})]})]});case`result`:return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Z,{title:`Abschluss`,children:(0,q.jsx)(U,{minRows:2,placeholder:`Nachricht am Ende`,value:t.message??``,onChange:e=>n({...t,message:e.target.value||void 0})})}),(0,q.jsx)(Z,{title:`Downloads`,children:u.map(e=>{let r=t.deliverables.find(t=>t.from===e.id),i=pe(e);return(0,q.jsxs)(`div`,{className:`rounded-lg bg-paper p-3 ring-1 ring-border-soft`,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`truncate text-[0.875rem]`,children:e.title}),(0,q.jsx)(w,{checked:!!r,onChange:r=>n({...t,deliverables:r?[...t.deliverables,{from:e.id,label:e.title,formats:[i[0]]}]:t.deliverables.filter(t=>t.from!==e.id)})})]}),r?(0,q.jsx)(H,{multi:!0,value:r.formats,options:i,onChange:r=>r.length&&n({...t,deliverables:t.deliverables.map(t=>t.from===e.id?{...t,formats:r}:t)})}):null]},e.id)})})]})}}function is({def:e,update:t}){return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(Z,{children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(P,{children:`Titel`}),(0,q.jsx)(F,{value:e.title,onChange:n=>t({...e,title:n.target.value})})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(P,{children:`Beschreibung`}),(0,q.jsx)(U,{minRows:2,value:e.description,onChange:n=>t({...e,description:n.target.value})})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(P,{hint:`Steht über der ersten Seite.`,children:`Begrüßung`}),(0,q.jsx)(U,{minRows:2,value:e.intro??``,onChange:n=>t({...e,intro:n.target.value||void 0})})]})]}),(0,q.jsx)(Z,{title:`Avatar`,children:(0,q.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:_.map(n=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>t({...e,avatar:n}),className:T(`flex aspect-square items-center justify-center rounded-xl transition`,e.avatar===n?`bg-ember-tint ring-2 ring-ember`:`bg-paper hover:bg-paper-2`),"aria-label":n,children:(0,q.jsx)(Ke,{kind:n,size:44,interactive:!1})},n))})}),e.lists?.length||e.connections?.length?(0,q.jsxs)(Z,{title:`Merkt sich für jede Person`,children:[(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:`Bleibt zwischen den Durchläufen erhalten – getrennt für jede Person, die den Wizard nutzt. Ändern kannst du das im Gespräch.`}),(e.connections??[]).map(e=>(0,q.jsxs)(`div`,{className:`rounded-lg bg-paper px-3 py-2.5 ring-1 ring-border-soft`,children:[(0,q.jsx)(`div`,{className:`text-[0.875rem]`,children:e.title??e.id}),(0,q.jsxs)(`div`,{className:`text-[0.75rem] text-ink-4`,children:[`Konto · `,e.kind]})]},e.id)),(e.lists??[]).map(e=>(0,q.jsxs)(`div`,{className:`rounded-lg bg-paper px-3 py-2.5 ring-1 ring-border-soft`,children:[(0,q.jsx)(`div`,{className:`text-[0.875rem]`,children:e.title}),(0,q.jsxs)(`div`,{className:`text-[0.75rem] text-ink-4`,children:[`Liste · `,e.columns.map(e=>e.name).join(`, `)]}),(0,q.jsx)(`div`,{className:`mt-1 font-mono text-[0.6875rem] text-ink-4`,children:`{{lists.${e.id}}}`})]},e.id))]}):null]})}var as=`__wizard`;function os({def:e,selected:t,onSelect:n,issues:r}){let i=[as,...e.steps.map(e=>e.id)],a=t?i.indexOf(t):-1,o=(0,K.useRef)(null);(0,K.useEffect)(()=>{o.current?.scrollIntoView({block:`nearest`,inline:`center`,behavior:`smooth`})},[t]);let s=e=>{let t=a===-1?e===1?1:i.length-1:a+e;t>=0&&t<i.length&&n(i[t])},c=(0,K.useRef)(s);c.current=s,(0,K.useEffect)(()=>{let e=e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.target?.closest(`input, textarea, select, [contenteditable=""], [contenteditable="true"], [role="separator"], [role="slider"], [role="dialog"], .react-flow`)||(e.preventDefault(),c.current(e.key===`ArrowLeft`?-1:1)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let l=`inline-flex size-8 shrink-0 items-center justify-center rounded-full transition`;return(0,q.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-1 border-border-soft border-b bg-card/95 px-2 py-2 backdrop-blur`,children:[(0,q.jsx)(z,{label:I(`editor.prevStep`),className:`size-8 shrink-0`,disabled:a===0,onClick:()=>s(-1),children:(0,q.jsx)(me,{className:`size-4`})}),(0,q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center overflow-x-auto p-1 [scrollbar-width:none]`,children:[(0,q.jsx)(`button`,{ref:t===as?o:void 0,type:`button`,title:e.title,"aria-label":e.title,"aria-current":t===as?`step`:void 0,onClick:()=>n(as),className:T(l,`bg-paper-2 text-ink-2`,t===as?`ring-2 ring-ember`:`hover:ring-2 hover:ring-border-soft`),children:(0,q.jsx)(nt,{className:`size-4`})}),e.steps.map((e,i)=>{let a=wt(e),s=e.id===t,c=r.some(t=>t.stepId===e.id);return(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center`,children:[(0,q.jsx)(`span`,{className:`h-px w-3 bg-border-soft`}),(0,q.jsxs)(`button`,{ref:s?o:void 0,type:`button`,title:`${i+1}. ${e.title}`,"aria-label":`${i+1}. ${e.title}`,"aria-current":s?`step`:void 0,onClick:()=>n(e.id),className:T(l,`relative`,Be[e.type],s?`ring-2 ring-ember`:`opacity-70 hover:opacity-100`),children:[(0,q.jsx)(a,{className:`size-4`}),c?(0,q.jsx)(`span`,{className:`-top-0.5 -right-0.5 absolute size-2.5 rounded-full bg-rose ring-2 ring-card`}):null]})]},e.id)})]}),(0,q.jsx)(`span`,{className:`shrink-0 px-1 text-[0.75rem] text-ink-4 tabular-nums`,children:a>0?`${a} / ${e.steps.length}`:``}),(0,q.jsx)(z,{label:I(`editor.nextStep`),className:`size-8 shrink-0`,disabled:a===i.length-1,onClick:()=>s(1),children:(0,q.jsx)(de,{className:`size-4`})})]})}function ss({def:e,onSelect:t,issues:n}){return(0,q.jsx)(`div`,{className:`flex flex-col gap-1 p-3`,children:e.steps.map((e,r)=>{let i=wt(e),a=n.some(t=>t.stepId===e.id);return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),className:`flex items-center gap-3 rounded-lg px-3 py-2.5 text-left transition hover:bg-paper-2`,children:[(0,q.jsx)(`span`,{className:`w-4 text-right text-[0.75rem] text-ink-4 tabular-nums`,children:r+1}),(0,q.jsx)(`span`,{className:T(`inline-flex size-7 shrink-0 items-center justify-center rounded-md`,Be[e.type]),children:(0,q.jsx)(i,{className:`size-4`})}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block truncate text-[0.875rem]`,children:e.title}),(0,q.jsx)(`span`,{className:`block text-[0.75rem] text-ink-4`,children:He(e)})]}),a?(0,q.jsx)(`span`,{className:`size-2 shrink-0 rounded-full bg-rose`}):null]},e.id)})})}function cs(e){let{def:t,selected:n,onSelect:r,issues:i,readOnly:a=!1}=e,o=a?()=>{}:e.update,s=t.steps.find(e=>e.id===n);return(0,q.jsx)(Ko,{value:a,children:(0,q.jsx)(Ho.Provider,{value:e.assistant,children:(0,q.jsxs)(`div`,{children:[(0,q.jsx)(os,{def:t,selected:n,onSelect:r,issues:i}),n===as?(0,q.jsx)(is,{def:t,update:o}):s?(0,q.jsx)(ls,{...e,update:o,step:s}):(0,q.jsx)(ss,{def:t,onSelect:r,issues:i})]})})})}function ls({def:e,step:t,update:n,onSelect:r,issues:i,mcpServers:a,files:s,wizardId:c,decisions:l,branchFocus:u,assistant:d}){let f=e.steps.indexOf(t),p=t.type===`result`?f:f+1,[m,h]=(0,K.useState)(!1);(0,K.useEffect)(()=>h(!1),[t.id]);let g=wt(t),_=r=>n({...e,steps:e.steps.map(e=>e.id===t.id?r:e)}),v=r=>{let i=f+r;if(i<0||i>=e.steps.length-(t.type===`result`?0:1)||e.steps[i].type===`result`)return;let a=[...e.steps];[a[f],a[i]]=[a[i],a[f]],n({...e,steps:a})},y=t=>{let i=vn(e,p,t);n(i.def),h(!1),r(i.id)},b=(e,t,n)=>d?.add({at:p,kind:e,prompt:t,when:n})?(h(!1),!0):!1,x=i.filter(e=>e.stepId===t.id),S=ao(c,e),C=(0,K.useContext)(Ko);return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-5 py-4`,children:[(0,q.jsx)(`span`,{className:T(`inline-flex size-7 items-center justify-center rounded-md`,Be[t.type]),children:(0,q.jsx)(g,{className:`size-4`})}),(0,q.jsx)(`span`,{className:`font-medium text-[0.75rem] text-ink-3 uppercase tracking-[0.07em]`,children:He(t)}),(0,q.jsx)(`span`,{className:`ml-auto font-mono text-[0.6875rem] text-ink-4`,children:t.id})]}),x.length?(0,q.jsx)(`div`,{className:`mx-5 mb-4 rounded-lg bg-rose-tint px-3 py-2 text-[0.8125rem] text-rose`,children:x.map((e,t)=>(0,q.jsx)(`div`,{children:e.message},t))}):null,(0,q.jsxs)(Z,{children:[(0,q.jsx)(F,{value:t.title,onChange:e=>_({...t,title:e.target.value}),className:`font-display font-semibold text-[1rem]`}),t.type===`page`||t.type===`review`?(0,q.jsx)(U,{minRows:1,placeholder:`Erklärung unter dem Titel (optional)`,value:t.description??``,onChange:e=>_({...t,description:e.target.value||void 0})}):null,(0,q.jsx)(so,{estimate:S.data,stepId:t.id})]}),(0,q.jsx)(rs,{def:e,step:t,set:_,mcpServers:a,files:s,wizardId:c}),t.type===`result`?null:(0,q.jsx)(ms,{def:e,step:t,set:_,onSelect:r,decision:l?.[t.id],focus:u,estimate:S.data}),C?null:(0,q.jsxs)(Z,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t.type===`result`?null:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(z,{label:I(`editor.moveUp`),onClick:()=>v(-1),children:(0,q.jsx)(he,{className:`size-4`})}),(0,q.jsx)(z,{label:I(`editor.moveDown`),onClick:()=>v(1),children:(0,q.jsx)(V,{className:`size-4`})}),(0,q.jsx)(No,{label:I(`editor.deleteStep`),onDelete:()=>{n({...e,steps:e.steps.filter(e=>e.id!==t.id)}),r(null)}})]}),(0,q.jsxs)(R,{variant:`secondary`,size:`sm`,className:`ml-auto`,"aria-expanded":m,onClick:()=>h(e=>!e),children:[(0,q.jsx)(o,{className:`size-3.5`}),` `,I(`addStep.add`)]})]}),d?.adding&&d.adding.at===p?(0,q.jsx)(hn,{adding:d.adding,place:fn(e,p),working:d.working,onShowChat:d.showChat}):m?(0,q.jsx)(mn,{place:fn(e,p),branchable:p>0,onAdd:b,onEmpty:y,onCancel:()=>h(!1)}):null]})]})}function us({value:e,onChange:t}){let[n,r]=(0,K.useState)(e);return(0,K.useEffect)(()=>r(e),[e]),(0,q.jsx)(U,{minRows:1,"aria-label":I(`editor.branch.statement`),value:n,onChange:e=>{r(e.target.value),e.target.value.trim()&&t(e.target.value)},onBlur:()=>r(e)})}function ds(e,t){let n=e.steps.indexOf(t),r=[];for(let t of e.steps.slice(0,n+1))if(t.type===`page`)r.push(...t.fields.map(e=>e.id));else if(t.type===`agent`)for(let e of t.output.fields??[])r.push(`steps.${t.id}.${e.id}`),O(t)&&r.push(`steps.${t.id}.${e.id}.p`);return r.push(...(e.lists??[]).map(e=>`lists.${e.id}.count`)),r}function fs(e,t){return`${He(t)} · ${e.steps.indexOf(t)+1} / ${e.steps.length}`}function ps({def:e,target:t,estimate:n,onSelect:r}){let[i,a]=(0,K.useState)(!1),o=wt(t),s=n?.available?n.steps[t.id]?.credits:void 0,c=e.steps.indexOf(t),l=e.steps[c+1];return(0,q.jsxs)(`div`,{className:`rounded-lg bg-paper-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2.5`,children:[(0,q.jsx)(`span`,{className:T(`inline-flex size-7 shrink-0 items-center justify-center rounded-md`,Be[t.type]),children:(0,q.jsx)(o,{className:`size-4`})}),(0,q.jsxs)(`button`,{type:`button`,className:`min-w-0 flex-1 text-left`,onClick:()=>r(t.id),title:I(`editor.next.open`),children:[(0,q.jsx)(`span`,{className:`block text-[0.6875rem] text-ink-4`,children:fs(e,t)}),(0,q.jsx)(`span`,{className:`block truncate font-medium text-[0.875rem] text-ink hover:underline`,children:t.title})]}),(0,q.jsx)(z,{label:I(i?`editor.next.fold`:`editor.next.unfold`),className:`size-8 shrink-0`,onClick:()=>a(!i),children:i?(0,q.jsx)(dt,{className:`size-4`}):(0,q.jsx)(ce,{className:`size-4`})})]}),i?(0,q.jsxs)(`div`,{className:`flex flex-col gap-1 border-border-soft border-t px-3 py-2.5 text-[0.75rem] text-ink-3`,children:[tt(t)?(0,q.jsx)(`span`,{className:`text-ink-2`,children:tt(t)}):null,s===void 0?null:(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[`≈`,` `,I(`nav.credits`,{n:s<10?s.toLocaleString(void 0,{maximumFractionDigits:1}):Math.round(s)})]}),(0,q.jsxs)(`span`,{children:[I(`editor.next.then`),` →`,` `,t.type===`result`?I(`editor.branch.end`):t.next?.length?I(`editor.next.ways`,{count:t.next.length+1}):l?l.title:I(`editor.branch.end`)]}),(0,q.jsxs)(`button`,{type:`button`,className:`mt-1 self-start font-medium text-ember hover:underline`,onClick:()=>r(t.id),children:[I(`editor.next.open`),` →`]})]}):null]})}function ms({def:e,step:t,set:n,onSelect:r,decision:i,focus:a,estimate:s}){let c=(0,K.useRef)(null);(0,K.useEffect)(()=>{a&&c.current?.scrollIntoView({block:`start`,behavior:`smooth`})},[a]);let[l,u]=(0,K.useState)(null);(0,K.useEffect)(()=>u(null),[t.id]);let f=t.next??[],p=e.steps.indexOf(t),h=e.steps[p+1],g=t=>e.steps.find(e=>e.id===t)?.title??I(`editor.branch.end`),_=[...e.steps.filter(e=>e.id!==t.id).map(t=>({value:t.id,label:`${e.steps.indexOf(t)+1}. ${t.title}`})),{value:`end`,label:I(`editor.branch.end`)}],y=ds(e,t),b=(e,r)=>{n({...t,next:r?f.map((t,n)=>n===e?r:t):f.length>1?f.filter((t,n)=>n!==e):void 0}),r||u(null)},x=e=>{let r=e.ask?f.length:f.filter(e=>e.when!==void 0).length;n({...t,next:[...f.slice(0,r),e,...f.slice(r)]}),u(r)},S=t=>{let n=e.steps.findIndex(e=>e.id===t);return n>=0&&n<=p},C=e=>i?.probabilities?.[e],w=f.some(e=>e.ask),ee=[...f.map((e,t)=>({rule:e,i:t})).filter(({rule:e})=>e.when!==void 0),...f.map((e,t)=>({rule:e,i:t})).filter(({rule:e})=>e.ask)],te=f.findIndex(D),E=te>=0?f[te].goto:h?.id??`end`,ne=e.steps.find(e=>e.id===E),re=e=>{let r=f.filter(e=>!D(e)),i=e===(h?.id??`end`)?r:[...r,{goto:e}];n({...t,next:i.length?i:void 0})},O=`${I(`editor.branch.how`)} ${i?I(`editor.branch.lastRun`,{source:i.source===`systemone`?I(`editor.branch.bySystemOne`):I(`editor.branch.byLlm`)}):I(`editor.branch.notYet`)}`,k=e=>e?(0,q.jsxs)(`span`,{className:`inline-flex shrink-0 cursor-help items-center gap-1 rounded-full bg-paper-3 px-2 py-0.5 font-medium text-[0.6875rem] text-ink-2`,title:O,children:[(0,q.jsx)(m,{className:`size-3 text-ember`}),` `,I(`editor.branch.ai`),(0,q.jsx)(Qt,{className:`size-3 text-ink-4`})]}):null,ie=(e,t)=>e===void 0?null:(0,q.jsx)(`span`,{className:T(`shrink-0 text-[0.75rem] tabular-nums`,t?`font-medium text-moss`:`text-ink-3`),children:So(e)}),A=(e,t,n,i,a,o)=>{let s=l===e||e===`otherwise`&&l===-1;return(0,q.jsxs)(`div`,{className:T(`rounded-lg bg-paper-2 ring-1`,i?`ring-moss`:`ring-transparent`),children:[(0,q.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 pt-2.5 text-left`,onClick:()=>u(s?null:e===`otherwise`?-1:e),children:[t,ie(a,i),s?(0,q.jsx)(dt,{className:`size-4 shrink-0 text-ink-4`}):(0,q.jsx)(ce,{className:`size-4 shrink-0 text-ink-4`})]}),(0,q.jsxs)(`div`,{className:`px-3 pt-1 pb-2.5 text-[0.75rem] text-ink-3`,children:[`→`,` `,n===`end`?I(`editor.branch.end`):(0,q.jsx)(`button`,{type:`button`,className:`text-ink-2 hover:text-ink hover:underline`,onClick:()=>r(n),children:g(n)}),i?(0,q.jsx)(`span`,{className:`ml-1.5 text-moss`,children:`✓`}):null]}),s?(0,q.jsx)(`div`,{className:`flex flex-col gap-2 border-border-soft border-t px-3 py-3`,children:o}):null]},e)},ae=(t,n)=>(0,q.jsxs)(q.Fragment,{children:[t.ask?(0,q.jsx)(us,{value:t.ask,onChange:e=>b(n,{...t,ask:e})}):(0,q.jsx)(Zo,{def:e,when:t.when,sources:y,label:I(`editor.branch.when`),noneLabel:I(`editor.branch.pick`),onChange:e=>{e&&b(n,{...t,when:e})}}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`shrink-0 text-[0.8125rem] text-ink-3`,children:`→`}),(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,q.jsx)(W,{value:t.goto,onChange:e=>b(n,{...t,goto:e}),options:_})}),S(t.goto)?(0,q.jsx)(F,{type:`number`,min:1,max:50,className:`w-20 shrink-0`,"aria-label":I(`editor.branch.max`),title:I(`editor.branch.max`),placeholder:`10`,value:t.max??``,onChange:e=>{let r=Math.round(Number(e.target.value));b(n,{...t,max:r>=1?Math.min(r,50):void 0})}}):null,(0,q.jsx)(z,{label:I(`editor.branch.remove`),className:`shrink-0 hover:text-rose`,onClick:()=>b(n,null),children:(0,q.jsx)(v,{className:`size-4`})})]})]}),j=(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[(0,q.jsxs)(`button`,{type:`button`,disabled:!y.length,onClick:()=>x({when:{field:y[0]??``,op:`notEmpty`},goto:h?.id??`end`}),className:`inline-flex h-8 items-center gap-1 rounded-full px-2.5 text-[0.75rem] text-ink-2 hover:bg-accent disabled:opacity-50`,children:[(0,q.jsx)(o,{className:`size-3.5`}),` `,I(`editor.branch.addWhen`)]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>x({ask:I(`editor.branch.newAsk`),goto:h?.id??`end`}),className:`inline-flex h-8 items-center gap-1 rounded-full px-2.5 text-[0.75rem] text-ink-2 hover:bg-accent`,children:[(0,q.jsx)(m,{className:`size-3.5`}),` `,I(`editor.branch.addAsk`)]})]});return(0,q.jsx)(`div`,{ref:c,className:`scroll-mt-14`,children:(0,q.jsxs)(Z,{title:ee.length?I(`editor.next.ways`,{count:ee.length+1}):I(`editor.next.title`),loose:!0,children:[f.length?(0,q.jsxs)(q.Fragment,{children:[ee.map(({rule:e,i:t})=>A(t,(0,q.jsxs)(q.Fragment,{children:[k(!!e.ask),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.8125rem] text-ink`,children:e.ask??d(e.when).map(wo).join(` ${I(`editor.branch.and`)} `)})]}),e.goto,i?.rule===t,C(`r${t}`),ae(e,t))),A(`otherwise`,(0,q.jsx)(`span`,{className:`min-w-0 flex-1 text-[0.8125rem] text-ink-3`,children:I(w?`editor.branch.none`:`editor.otherwise`)}),E,i?.rule===null,C(`none`),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`shrink-0 text-[0.8125rem] text-ink-3`,children:`→`}),(0,q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,q.jsx)(W,{value:E,onChange:re,options:_})})]}),ne?(0,q.jsx)(ps,{def:e,target:ne,estimate:s,onSelect:r}):null]}))]}):h?(0,q.jsx)(ps,{def:e,target:h,estimate:s,onSelect:r}):(0,q.jsx)(`span`,{className:`text-[0.8125rem] text-ink-3`,children:I(`editor.branch.end`)}),j]})})}var hs={title:`live.part.title`,description:`live.part.description`,fields:`live.part.fields`,groups:`live.part.fields`,cta:`live.part.cta`,instructions:`live.part.instructions`,tools:`live.part.tools`,mcp:`live.part.connections`,connections:`live.part.connections`,call:`live.part.tools`,output:`live.part.output`,model:`live.part.model`,effort:`live.part.model`,next:`live.part.next`,each:`live.part.each`,intro:`live.part.intro`,avatar:`live.part.avatar`,lists:`live.part.lists`};function gs(e=[]){let t=[...new Set(e.map(e=>I(hs[e]??`live.part.other`)))],n=` ${I(`live.and`)} `;return t.length<=1?t[0]??I(`live.part.other`):`${t.slice(0,-1).join(`, `)}${n}${t[t.length-1]}`}function _s(e){let t=e.name??``;switch(e.kind){case`wizard`:return I(`live.wizardChanged`,{parts:gs(e.parts)});case`order`:return I(`live.order`);case`file`:return I(e.change===`added`?`live.fileAdded`:e.change===`removed`?`live.fileRemoved`:`live.fileChanged`,{name:t});default:return e.change===`added`?I(`live.stepAdded`,{name:t}):e.change===`removed`?I(`live.stepRemoved`,{name:t}):I(`live.stepChanged`,{name:t,parts:gs(e.parts)})}}function vs({change:e}){let t=e.change===`added`?`bg-moss-tint text-moss`:e.change===`removed`?`bg-rose-tint text-rose`:`bg-paper-2 text-ink-2`,n=e.change===`added`?o:e.change===`removed`?en:E;return e.kind===`file`?n=re:e.kind===`order`&&(n=rt),(0,q.jsx)(`span`,{className:T(`flex size-7 shrink-0 items-center justify-center rounded-lg`,t),children:(0,q.jsx)(n,{className:`size-3.5`})})}function ys(e){let t=new Intl.RelativeTimeFormat(l,{numeric:`auto`}),n=Math.round((new Date(e).getTime()-Date.now())/6e4);if(n===0)return I(`live.justNow`);if(Math.abs(n)<60)return t.format(n,`minute`);let r=Math.round(n/60);return Math.abs(r)<24?t.format(r,`hour`):t.format(Math.round(r/24),`day`)}function bs({wizard:e,actions:t,cloud:n,onClose:r}){let a=i({queryKey:[`wizard-changes`,e.id,e.revision],queryFn:()=>L.get(`/api/studio/wizards/${e.id}/changes`)}),[o,s]=(0,K.useState)(null),[c,u]=(0,K.useState)(null),d=a.data?.version??e.publishedVersion??0,f=d+1;if(o)return(0,q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-6 text-center`,children:[(0,q.jsx)(`span`,{className:`flex size-16 items-center justify-center rounded-full bg-moss-tint text-moss`,children:(0,q.jsx)(A,{className:`size-7`,strokeWidth:2.25})}),(0,q.jsx)(`h3`,{className:`font-display font-semibold text-xl`,children:I(`live.done`,{v:o.version})}),(0,q.jsx)(`p`,{className:`max-w-sm text-[0.9375rem] text-ink-2`,children:I(n?`live.doneCloud`:`live.doneHint`,{v:o.version,was:d})}),o.cloud?.error?(0,q.jsx)(`p`,{className:`max-w-sm rounded-lg bg-amber-tint px-3 py-2 text-[0.8125rem]`,children:o.cloud.error.message}):null]}),(0,q.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2 max-sm:flex-col-reverse max-sm:items-stretch`,children:[(0,q.jsx)(R,{variant:`ghost`,onClick:r,children:I(`live.close`)}),(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsx)(R,{onClick:t.share,children:I(`editor.share`)})]})]});let p=e.issues,m=a.data?.tested??null,h=a.data?.cost,g=[I(`live.keepRunning`,{v:d}),h&&Math.round(h.after)!==Math.round(h.before)?I(`live.cost`,{before:Math.round(h.before).toLocaleString(l),after:Math.round(h.after).toLocaleString(l)}):null,n?I(`live.cloud`,{v:f}):null].filter(e=>!!e);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,q.jsx)(`p`,{className:`text-[0.9375rem] text-ink-2`,children:I(`live.intro`,{v:d,next:f})}),(0,q.jsxs)(`section`,{className:`flex flex-col gap-1.5`,children:[(0,q.jsx)(`h3`,{className:`font-medium text-[0.8125rem] text-ink-3`,children:I(`live.changed`)}),a.data?a.data.changes.length?(0,q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:a.data.changes.map((e,t)=>(0,q.jsxs)(`li`,{className:`flex min-h-10 items-center gap-3 text-[0.875rem]`,children:[(0,q.jsx)(vs,{change:e}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1`,children:_s(e)})]},t))}):(0,q.jsx)(`p`,{className:`text-[0.875rem] text-ink-3`,children:I(`live.nothing`)}):a.error?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:a.error.message}):(0,q.jsx)(j,{className:`size-4 text-ink-4`})]}),p.length?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl bg-amber-tint px-3.5 py-3 text-[0.875rem]`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,q.jsx)(ke,{className:`mt-0.5 size-4 shrink-0 text-amber`}),(0,q.jsx)(`span`,{className:`font-medium`,children:I(`live.fixFirst`)})]}),(0,q.jsx)(`ul`,{className:`list-disc pl-12 text-[0.8125rem] text-ink-2`,children:p.slice(0,4).map((e,t)=>(0,q.jsx)(`li`,{children:e.message},t))}),t.fix?(0,q.jsx)(`div`,{className:`pl-7`,children:(0,q.jsx)(R,{size:`sm`,variant:`secondary`,onClick:t.fix,children:I(`editor.fixWithChat`)})}):null]}):m?(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-xl bg-moss-tint px-3.5 py-3 text-[0.875rem]`,children:[(0,q.jsx)(Rt,{className:`size-4 shrink-0 text-moss`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-[1_1_14rem]`,children:I(m.status===`failed`?`live.testedFailed`:`live.tested`,{when:ys(m.at)})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t.openRun(m.runId),className:`text-[0.8125rem] text-ink-2 underline underline-offset-2 hover:text-ink`,children:I(`live.seeRun`)})]}):a.data?(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 rounded-xl bg-paper-2 px-3.5 py-3 text-[0.875rem]`,children:[(0,q.jsx)(nn,{className:`size-4 shrink-0 text-ink-3`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-[1_1_14rem]`,children:I(`live.untested`)}),(0,q.jsx)(R,{size:`sm`,variant:`secondary`,onClick:t.test,children:I(`live.test`)})]}):null,(0,q.jsx)(`ul`,{className:`flex flex-col gap-1.5 text-[0.8125rem] text-ink-3`,children:g.map(e=>(0,q.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,q.jsx)(Qt,{className:`mt-0.5 size-3.5 shrink-0`}),(0,q.jsx)(`span`,{children:e})]},e))}),c?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:c}):null,(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-border-soft border-t pt-4 max-sm:flex-col-reverse max-sm:items-stretch`,children:[(0,q.jsx)(R,{variant:`ghost`,onClick:r,children:I(`live.cancel`)}),(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsx)(R,{busy:t.busy,disabled:t.disabled,onClick:()=>{u(null),t.publish().then(s).catch(e=>u(e.message))},children:t.busy?I(`live.going`):I(`live.go`)})]})]})}function xs({wizard:e,open:t,onClose:n,actions:r,cloud:i}){return(0,q.jsx)(se,{open:t,onClose:n,title:I(`live.title`),children:(0,q.jsx)(bs,{wizard:e,actions:r,cloud:i,onClose:n})})}function Ss({wizardId:e,projectId:t,def:n,readOnly:i}){let a=r(),s=Ce(t),[c,u]=(0,K.useState)(null),[d,f]=(0,K.useState)(!1),[p,m]=(0,K.useState)(null),h=[...(s.data?.pages??[]).filter(t=>t.wizardId===e).map(e=>({key:`p:${e.id}`,kind:`page`,title:e.title,at:e.updatedAt})),...(s.data?.tables??[]).filter(t=>t.wizardId===e).map(e=>({key:`t:${e.id}`,kind:`table`,title:e.title,at:e.updatedAt,rows:e.rows}))],g=n.steps.some(e=>e.type===`agent`&&e.tools.includes(`pages`)),_=(n.lists??[]).some(e=>e.shared),v=new Intl.DateTimeFormat(l,{dateStyle:`medium`}),y=()=>a.invalidateQueries({queryKey:[`space-data`,t]});if(c){let e=c.slice(2);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-5`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{u(null),y()},className:`inline-flex h-8 items-center gap-1.5 self-start rounded-full px-2.5 text-[0.8125rem] text-ink-2 hover:bg-accent`,children:[(0,q.jsx)(ue,{className:`size-4`}),` `,I(`memory.back`)]}),c.startsWith(`p:`)?(0,q.jsx)(Te,{pageId:e,onGone:()=>{u(null),y()}}):(0,q.jsx)(we,{tableId:e,onGone:()=>{u(null),y()}})]})}let b=async()=>{f(!0),m(null);try{let{id:n}=await L.post(`/api/studio/projects/${t}/pages`,{title:I(`memory.newNote`),wizardId:e});await y(),u(`p:${n}`)}catch(e){m(e.message)}finally{f(!1)}};return(0,q.jsxs)(`div`,{className:`flex min-h-full flex-col gap-4 px-5 py-5`,children:[g||_?null:(0,q.jsx)(`p`,{className:`rounded-lg bg-paper-2 px-3 py-2 text-[0.8125rem] text-ink-2`,children:I(`memory.unused`)}),s.isLoading?(0,q.jsx)(j,{className:`size-4 text-ink-4`}):h.length?(0,q.jsx)(`ul`,{className:`flex flex-col gap-1`,children:h.map(e=>{let t=G[e.kind];return(0,q.jsx)(`li`,{children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>u(e.key),className:`flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left hover:bg-paper-2`,children:[(0,q.jsx)(t,{className:`size-4 shrink-0 text-ink-3`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[0.875rem]`,children:e.title}),(0,q.jsxs)(`span`,{className:`shrink-0 text-[0.75rem] text-ink-4 tabular-nums`,children:[e.kind===`table`?`${I(`data.rows`,{n:e.rows??0})} · `:``,v.format(new Date(e.at))]})]})},e.key)})}):(0,q.jsx)(`div`,{className:`rounded-xl border border-border border-dashed px-4 py-8 text-center text-[0.8125rem] text-ink-4`,children:I(`memory.none`)}),p?(0,q.jsx)(`p`,{className:`text-[0.75rem] text-rose`,children:p}):null,i?null:(0,q.jsxs)(`button`,{type:`button`,disabled:d,onClick:()=>void b(),className:T(`inline-flex h-9 items-center gap-1.5 self-start rounded-full bg-paper-2 px-3.5 font-medium text-[0.8125rem] text-ink-2 hover:bg-paper-3 hover:text-ink`,d&&`opacity-60`),children:[d?(0,q.jsx)(j,{className:`size-3.5`}):(0,q.jsx)(o,{className:`size-3.5`}),I(`memory.add`)]}),(0,q.jsxs)(`div`,{className:`mt-auto flex flex-col gap-1.5 pt-6 text-[0.6875rem] text-ink-4 leading-relaxed`,children:[(0,q.jsx)(`p`,{children:I(`memory.explain`)}),(0,q.jsx)(`p`,{children:I(`memory.testCopy`)})]})]})}var Cs={waiting_input:`wartet`,running:`läuft`,done:`fertig`,failed:`Fehler`,cancelled:`abgebrochen`};function ws({wizardId:e,onOpen:t}){let n=i({queryKey:[`runs`,e],queryFn:()=>L.get(`/api/studio/wizards/${e}/runs`),refetchInterval:1e4});if(n.data&&!n.data.length)return(0,q.jsx)(B,{children:I(`editor.noRuns`)});let r=new Intl.DateTimeFormat(l,{dateStyle:`short`,timeStyle:`short`});return(0,q.jsx)(`div`,{className:`flex flex-col p-2`,children:n.data?.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>t(e.id),className:`flex items-center gap-3 rounded-lg px-3 py-3 text-left hover:bg-accent`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[0.875rem]`,children:[r.format(new Date(e.createdAt)),e.mode===`test`?(0,q.jsx)(N,{children:`Test`}):(0,q.jsxs)(N,{tone:`live`,children:[`Live v`,e.version]})]}),(0,q.jsxs)(`div`,{className:`truncate text-[0.75rem] text-ink-3`,children:[Cs[e.status]??e.status,e.stepTitle&&e.status!==`done`?` · ${e.stepTitle}`:``]})]}),(0,q.jsx)(`span`,{className:`text-[0.75rem] text-ink-4 tabular-nums`,children:I(`nav.credits`,{n:e.credits})})]},e.id))})}var Ts=new Set([`html`,`md`,`txt`,`csv`,`json`]),Es=new Set([`web_search`,`browser`,`sandbox`,`image`]),Ds=new Set([`web_fetch`,`http`]),Os=/\{\{\s*memory\b/;function ks(e){switch(e.type){case`agent`:return[e.instructions,e.call?JSON.stringify(e.call.input):``];case`generate`:return[e.prompt,e.options?.style??``];case`film`:return[e.brief];case`widget`:case`surface`:return Object.values(e.data).map(e=>`{{${g(e)}}}`);default:return[]}}function As(e,t){return e.steps.slice(t+1).some(e=>e.type===`agent`&&!e.call||e.type===`generate`||e.type===`film`)}function js(e,t){let n=[],r=(t,r)=>{let i=n.find(e=>e.need===t);i?i.hard||=r:n.push({stepId:e.id,need:t,hard:r})},i=t.steps.indexOf(e);for(let t of ks(e))Os.test(t)&&r(`memory`,!0),_e(t).some(e=>e.startsWith(`lists.`))&&r(`lists`,!0);switch(e.type){case`page`:for(let n of e.fields){switch(n.kind){case`audio`:r(`field:audio`,!!n.required);break;case`connection`:r(`field:connection`,!0);break;case`slot`:r(`field:slot`,!0);break;case`list`:r(`lists`,!0);break;case`location`:r(`field:location`,!1);break;case`image`:r(`field:image`,!1);break;case`file`:As(t,i)?r(`field:file-read`,!0):r(`field:file`,!1)}n.optionsFrom&&k(g(n.optionsFrom).split(`.`).slice(0,2).join(`.`))&&r(`lists`,!0)}break;case`agent`:{let t=e.call?[...e.tools,e.call.tool]:e.tools;for(let e of t){let t=b(e);t?r(`plugin:${t.plugin}`,!0):Ds.has(e)||(Es.has(e)?r(`tool:${e}`,!0):r(`tool:${e}`,!1))}e.mcp?.length&&r(`mcp`,!0),e.connections?.length&&r(`connections`,!0),e.each&&(k(g(e.each))?r(`lists`,!0):r(`each`,!1));break}case`generate`:e.asset!==`document`&&e.asset!==`dashboard`&&r(`asset:${e.asset}`,!0);break;case`film`:r(`film`,!0);break;case`widget`:r(e.video?`widget:video`:`widget`,!0);break;case`surface`:Object.values(e.data).some(e=>k(g(e)))&&r(`lists`,!0);break;case`review`:e.show.some(e=>k(e))&&r(`lists`,!0);break;case`result`:for(let n of e.deliverables){if(k(n.from)){r(`lists`,!0);continue}let e=t.steps.find(e=>e.id===n.from);if(e?.type!==`agent`&&(e?.type!==`generate`||e.asset!==`document`&&e.asset!==`dashboard`))continue;let i=n.formats.some(e=>Ts.has(e));for(let t of n.formats)Ts.has(t)||(t!==`pdf`||e?.type!==`agent`)&&r(`format:${t}`,t!==`pdf`&&!i)}}return n}function Ms(e){let t=e.steps.flatMap(t=>js(t,e));e.lists?.length&&!t.some(e=>e.need===`lists`)&&t.push({stepId:e.steps[0]?.id??``,need:`lists`,hard:!0}),e.connections?.length&&!t.some(e=>e.need===`connections`)&&t.push({stepId:e.steps[0]?.id??``,need:`connections`,hard:!0});let n=Fs(e);return{fit:t.some(e=>e.hard&&n.has(e.stepId))?`no`:t.length?`less`:`full`,notes:t}}function Ns(e){switch(e){case`tool:web_search`:case`tool:web_fetch`:return`web`;case`tool:browser`:return`browser`;case`tool:sandbox`:return`code`;case`tool:image`:case`asset:image`:return`image`;case`asset:video`:case`film`:case`widget:video`:return`video`;case`asset:voice`:return`speech`;case`field:audio`:return`listening`;case`tool:http`:case`mcp`:case`connections`:case`field:connection`:return`connectors`;case`field:image`:case`field:file`:case`field:file-read`:return`documents`;default:return null}}function Ps(e){let t=Ms(e),n=Fs(e),r=new Set,i=new Set,a=new Set,o=new Set;for(let e of t.notes){if(e.need.startsWith(`plugin:`)){a.add(e.need.slice(7));continue}if(e.need.startsWith(`format:`)){o.add(e.need.slice(7));continue}let t=Ns(e.need);t&&(e.hard&&n.has(e.stepId)?r.add(t):i.add(t))}for(let e of r)i.delete(e);return{...t,missing:[...r],optional:[...i],needs:[...a].sort(),without:[...o]}}function Fs(e){return e.steps.length?Is(e,e.steps[0].id,{}):new Set}function Is(e,t,n){let r=new Map(e.steps.map((e,t)=>[e.id,t])),i=r.get(t)??0,o=t=>{let i=[];for(let o of e.steps[t].next??[]){if(D(o))continue;let t=o.goto===`end`?e.steps.length:r.get(o.goto)??-1;if(o.ask||!d(o.when).every(e=>e.field in n)){t>=0&&i.push(t);continue}if(a(o,n))return t>=0?[...i,t]:i}return i.push(Ls(e,t,r)),i},s=t=>{if(t===i)return!1;let n=new Set([i]),r=[i];for(;r.length;){let i=r.shift();if(i>=e.steps.length)return!0;for(let e of o(i))e!==t&&!n.has(e)&&(n.add(e),r.push(e))}return!1};return new Set(e.steps.filter((e,t)=>!s(t)).map(e=>e.id))}function Ls(e,t,n){let r=e.steps[t].next?.find(D)?.goto;return r===void 0?t+1:r===`end`?e.steps.length:n.get(r)??t+1}function Rs(e){return(0,K.useMemo)(()=>Ps(e),[e])}function zs({fit:e}){return(0,q.jsx)(N,{tone:e===`full`?`live`:e===`less`?`warn`:`neutral`,children:I(e===`full`?`share.wpFull`:e===`less`?`share.wpLess`:`share.wpNo`)})}var Bs={lists:`need.lists`,memory:`need.memory`,each:`need.each`,"field:slot":`need.field:slot`,"asset:document":`need.asset:document`,"asset:dashboard":`need.asset:dashboard`,"tool:pages":`need.tool:pages`};function Vs(e,t){let n=[],r=new Set,i=(e,t)=>{r.has(e)||(r.add(e),n.push(t))};e.steps.some(e=>e.type===`agent`&&!e.call)&&i(`text`,{text:Qe.text[l],tone:`ok`});for(let e of t.missing)i(e,{text:Qe[e][l],tone:`missing`});for(let e of t.optional)i(e,{text:Qe[e][l],tone:`optional`});for(let e of t.notes){let t=Bs[e.need];t&&!Ns(e.need)&&i(e.need,{text:I(t),tone:e.hard?`missing`:`optional`})}for(let e of t.without)i(`format:${e}`,{text:I(`need.format`,{format:s[e]}),tone:`optional`});return n}function Hs({def:e,fit:t}){let n=Vs(e,t);return(0,q.jsxs)(`ul`,{className:`flex flex-col gap-1.5 text-[0.8125rem]`,children:[n.map(e=>(0,q.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.tone===`ok`?(0,q.jsx)(A,{className:`size-4 shrink-0 text-cobalt`}):e.tone===`missing`?(0,q.jsx)(Bt,{className:`size-4 shrink-0 text-rose`}):(0,q.jsx)(ke,{className:`size-4 shrink-0 text-amber`}),(0,q.jsx)(`span`,{className:T(e.tone===`missing`&&`text-ink-2`),children:e.text}),e.tone===`ok`?null:(0,q.jsx)(`span`,{className:T(`text-[0.75rem]`,e.tone===`missing`?`text-rose`:`text-amber`),children:I(e.tone===`missing`?`need.missing`:`need.optional`)})]},e.text)),t.needs.length?(0,q.jsxs)(`li`,{className:`flex items-center gap-2 text-ink-2`,children:[(0,q.jsx)(Bt,{className:`size-4 shrink-0 text-rose`}),I(`share.wpNeedsAccount`,{list:t.needs.join(`, `)})]}):null]})}var Us=(e=>(e[e.Border=-1]=`Border`,e[e.Data=0]=`Data`,e[e.Function=1]=`Function`,e[e.Position=2]=`Position`,e[e.Timing=3]=`Timing`,e[e.Alignment=4]=`Alignment`,e))(Us||{}),Ws=[0,1],Gs=[1,0],Ks=[2,3],qs=[3,2],Js={L:Ws,M:Gs,Q:Ks,H:qs},Ys=/^\d*$/,Xs=/^[A-Z0-9 $%*+./:-]*$/,Zs=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,Qs=1,$s=40,ec=3,tc=3,nc=40,rc=10,ic=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],ac=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],oc=class{constructor(e,t,n,r){if(this.version=e,this.ecc=t,e<Qs||e>$s)throw RangeError(`Version value out of range`);if(r<-1||r>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let i=Array.from({length:this.size}).fill(!1);for(let e=0;e<this.size;e++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let a=this.addEccAndInterleave(n);if(this.drawCodewords(a),r===-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(r=t,e=n),this.applyMask(t)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(e,t){return e>=0&&e<this.size&&t>=0&&t<this.size&&this.modules[t][e]}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0,Us.Timing),this.setFunctionModule(e,6,e%2==0,Us.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n===0&&r===0||n===0&&r===t-1||n===t-1&&r===0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.ecc[1]<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let r=(t<<10|n)^21522;for(let e=0;e<=5;e++)this.setFunctionModule(8,e,$(r,e));this.setFunctionModule(8,7,$(r,6)),this.setFunctionModule(8,8,$(r,7)),this.setFunctionModule(7,8,$(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,$(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,$(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,$(r,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;for(let e=0;e<18;e++){let n=$(t,e),r=this.size-11+e%3,i=Math.floor(e/3);this.setFunctionModule(r,i,n),this.setFunctionModule(i,r,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;a>=0&&a<this.size&&o>=0&&o<this.size&&this.setFunctionModule(a,o,i!==2&&i!==4,Us.Position)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!==1,Us.Alignment)}setFunctionModule(e,t,n,r=Us.Function){this.modules[t][e]=n,this.types[t][e]=r}addEccAndInterleave(e){let t=this.version,n=this.ecc;if(e.length!==xc(t,n))throw RangeError(`Invalid argument`);let r=ac[n[0]][t],i=ic[n[0]][t],a=Math.floor(bc(t)/8),o=r-a%r,s=Math.floor(a/r),c=[],l=Sc(i);for(let t=0,n=0;t<r;t++){let r=e.slice(n,n+s-i+(t<o?0:1));n+=r.length;let a=Cc(r,l);t<o&&r.push(0),c.push(r.concat(a))}let u=[];for(let e=0;e<c[0].length;e++)c.forEach((t,n)=>{(e!==s-i||n>=o)&&u.push(t[e])});return u}drawCodewords(e){if(e.length!==Math.floor(bc(this.version)/8))throw RangeError(`Invalid argument`);let t=0;for(let n=this.size-1;n>=1;n-=2){n===6&&(n=5);for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let a=n-i,o=n+1&2?r:this.size-1-r;!this.types[o][a]&&t<e.length*8&&(this.modules[o][a]=$(e[t>>>3],7-(t&7)),t++)}}}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.types[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[t][a]===n?(r++,r===5?e+=ec:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*nc),n=this.modules[t][a],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*nc}for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][t]===n?(r++,r===5?e+=ec:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*nc),n=this.modules[a][t],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*nc}for(let t=0;t<this.size-1;t++)for(let n=0;n<this.size-1;n++){let r=this.modules[t][n];r===this.modules[t][n+1]&&r===this.modules[t+1][n]&&r===this.modules[t+1][n+1]&&(e+=tc)}let t=0;for(let e of this.modules)t=e.reduce((e,t)=>e+ +!!t,t);let n=this.size*this.size,r=Math.ceil(Math.abs(t*20-n*10)/n)-1;return e+=r*rc,e}getAlignmentPatternPositions(){if(this.version===1)return[];{let e=Math.floor(this.version/7)+2,t=this.version===32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(e){let t=e[1],n=t>0&&e[2]===t&&e[3]===t*3&&e[4]===t&&e[5]===t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]===0&&(e+=this.size),t.pop(),t.unshift(e)}};function Q(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function $(e,t){return!!(e>>>t&1)}var sc=class{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}getData(){return this.bitData.slice()}},cc=[1,10,12,14],lc=[2,9,11,13],uc=[4,8,16,16];function dc(e,t){return e[Math.floor((t+7)/17)+1]}function fc(e){let t=[];for(let n of e)Q(n,8,t);return new sc(uc,e.length,t)}function pc(e){if(!gc(e))throw RangeError(`String contains non-numeric characters`);let t=[];for(let n=0;n<e.length;){let r=Math.min(e.length-n,3);Q(Number.parseInt(e.substring(n,n+r),10),r*3+1,t),n+=r}return new sc(cc,e.length,t)}function mc(e){if(!_c(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],n=0;for(;n+2<=e.length;n+=2){let r=Zs.indexOf(e.charAt(n))*45;r+=Zs.indexOf(e.charAt(n+1)),Q(r,11,t)}return n<e.length&&Q(Zs.indexOf(e.charAt(n)),6,t),new sc(lc,e.length,t)}function hc(e){return e===``?[]:gc(e)?[pc(e)]:_c(e)?[mc(e)]:[fc(yc(e))]}function gc(e){return Ys.test(e)}function _c(e){return Xs.test(e)}function vc(e,t){let n=0;for(let r of e){let e=dc(r.mode,t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}function yc(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)===`%`?(t.push(Number.parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}function bc(e){if(e<Qs||e>$s)throw RangeError(`Version number out of range`);let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function xc(e,t){return Math.floor(bc(e)/8)-ic[t[0]][e]*ac[t[0]][e]}function Sc(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let t=[];for(let n=0;n<e-1;n++)t.push(0);t.push(1);let n=1;for(let r=0;r<e;r++){for(let e=0;e<t.length;e++)t[e]=wc(t[e],n),e+1<t.length&&(t[e]^=t[e+1]);n=wc(n,2)}return t}function Cc(e,t){let n=t.map(e=>0);for(let r of e){let e=r^n.shift();n.push(0),t.forEach((t,r)=>n[r]^=wc(t,e))}return n}function wc(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n}function Tc(e,t,n=1,r=40,i=-1,a=!0){if(!(Qs<=n&&n<=r&&r<=$s)||i<-1||i>7)throw RangeError(`Invalid value`);let o,s;for(o=n;;o++){let n=xc(o,t)*8,i=vc(e,o);if(i<=n){s=i;break}if(o>=r)throw RangeError(`Data too long`)}for(let e of[Gs,Ks,qs])a&&s<=xc(o,e)*8&&(t=e);let c=[];for(let t of e){Q(t.mode[0],4,c),Q(t.numChars,dc(t.mode,o),c);for(let e of t.getData())c.push(e)}let l=xc(o,t)*8;Q(0,Math.min(4,l-c.length),c),Q(0,(8-c.length%8)%8,c);for(let e=236;c.length<l;e^=253)Q(e,8,c);let u=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((e,t)=>u[t>>>3]|=e<<7-(t&7)),new oc(o,t,u,i)}function Ec(e,t){let{ecc:n=`L`,boostEcc:r=!1,minVersion:i=1,maxVersion:a=40,maskPattern:o=-1,border:s=1}=t||{},c=typeof e==`string`?hc(e):Array.isArray(e)?[fc(e)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);let l=Tc(c,Js[n],i,a,o,r),u=Dc({version:l.version,maskPattern:l.mask,size:l.size,data:l.modules,types:l.types},s);return t?.invert&&(u.data=u.data.map(e=>e.map(e=>!e))),t?.onEncoded?.(u),u}function Dc(e,t=1){if(!t)return e;let{size:n}=e,r=n+t*2;e.size=r,e.data.forEach(e=>{for(let n=0;n<t;n++)e.unshift(!1),e.push(!1)});for(let n=0;n<t;n++)e.data.unshift(Array.from({length:r},e=>!1)),e.data.push(Array.from({length:r},e=>!1));let i=Us.Border;e.types.forEach(e=>{for(let n=0;n<t;n++)e.unshift(i),e.push(i)});for(let n=0;n<t;n++)e.types.unshift(Array.from({length:r},e=>i)),e.types.push(Array.from({length:r},e=>i));return e}function Oc(e){return e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function kc(e,t={}){let n=Ec(e,t),{pixelSize:r=10,whiteColor:i=`white`,blackColor:a=`black`}=t,o=n.size*r,s=n.size*r,c=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${s} ${o}">`,l=[];for(let e=0;e<n.size;e++)for(let t=0;t<n.size;t++){let i=t*r,a=e*r;n.data[e][t]&&l.push(`M${i},${a}h${r}v${r}h-${r}z`)}return c+=`<rect fill="${Oc(i)}" width="${s}" height="${o}"/>`,c+=`<path fill="${Oc(a)}" d="${l.join(``)}"/>`,c+=`</svg>`,c}var Ac=e=>`${e.slice(0,4)} ${e.slice(4)}`,jc=e=>kc(e,{ecc:`M`,border:2,pixelSize:8}),Mc=e=>`${(e.trim()||`wizard`).replace(/[^\p{L}\p{N}]+/gu,`-`).toLowerCase()}-qr`;function Nc(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}async function Pc(e,t){let n=new Image,r=URL.createObjectURL(new Blob([e],{type:`image/svg+xml`}));try{n.src=r,await n.decode();let e=document.createElement(`canvas`);e.width=1024,e.height=1024;let i=e.getContext(`2d`);if(!i)return;i.imageSmoothingEnabled=!1,i.drawImage(n,0,0,1024,1024);let a=await new Promise(t=>e.toBlob(t,`image/png`));a&&Nc(a,`${Mc(t)}.png`)}finally{URL.revokeObjectURL(r)}}function Fc(e,t){let n=window.open(``,`_blank`,`width=520,height=680`);if(!n)return;let r=n.document;r.title=t;let i=r.createElement(`style`);i.textContent=`body{margin:0;min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:24px;font:600 28px system-ui,sans-serif}svg{width:12cm;height:12cm}`,r.head.append(i);let a=new DOMParser().parseFromString(e,`image/svg+xml`).documentElement,o=r.createElement(`div`);o.textContent=t,r.body.append(r.importNode(a,!0),o),n.addEventListener(`afterprint`,()=>n.close()),n.focus(),n.print()}function Ic({svg:e,label:t,className:n}){return(0,q.jsx)(`div`,{role:`img`,"aria-label":t,className:T(`overflow-hidden rounded-xl bg-white [&>svg]:size-full`,n),dangerouslySetInnerHTML:{__html:e}})}var Lc=`https://github.com/engenty/engenty-wizards-wp-plugin/releases/latest/download/engenty-wizards.zip`,Rc={qr:`share.qr`,website:`share.onWebsite`,package:`share.wpLocal`,settings:`share.settings`,channels:`new.where`};function zc(e,t){let{settings:n}=e,r=Ie.map(e=>e.id);return e.runners.filter(e=>n.enabled.includes(e.id)).map(e=>{let r=Fe(e.id),i=r?.group??(e.kind===`page`?`web`:`message`),a=e.fit.outcome===`no`?I(`share.fit.no`,{steps:e.fit.steps.map(e=>e.title).join(`, `)}):null,o={id:e.id,group:i,name:r?I(r.label):e.label[l],icon:r?(0,q.jsx)(Ne,{channel:r}):(0,q.jsx)(it,{className:`size-4`}),problem:e.problem??null,plugin:e.plugin};if(e.kind===`page`){let r=t?e.id===n.default?t:`${t}/${e.id}`:null;return{...o,note:a,copy:r?{text:r,number:!1}:null,link:r}}let s=e.address,c=s?.keyword&&s.number?I(`share.keywordTo`,{keyword:s.keyword,number:s.number}):s?.number??null,u=null;return s?.link?u={text:s.link,number:!1}:s?.number&&(u={text:s.number,number:!0}),{...o,note:a??c,copy:u,link:s?.link??null}}).sort((e,t)=>r.indexOf(e.group)-r.indexOf(t.group))}function Bc(){let[e,t]=(0,K.useState)(null),n=(0,K.useRef)(void 0);return(0,K.useEffect)(()=>()=>clearTimeout(n.current),[]),{copied:e,copy:(e,r)=>{navigator.clipboard.writeText(r).then(()=>{t(e),clearTimeout(n.current),n.current=setTimeout(()=>t(null),1500)}).catch(()=>t(null))}}}function Vc({children:e,className:t}){return(0,q.jsx)(`div`,{className:T(`min-h-0 flex-1 overflow-y-auto px-4 pt-2 pb-5 sm:px-6`,t),children:e})}function Hc({children:e}){return(0,q.jsx)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-border-soft border-t px-4 py-3.5 sm:px-5`,children:e})}var Uc=`text-[0.8125rem] font-medium text-ink-3`;function Wc({warn:e,done:t,title:n,children:r,action:i}){return(0,q.jsxs)(`div`,{className:T(`flex flex-wrap items-center gap-x-3 gap-y-2 rounded-xl px-3.5 py-3 text-[0.875rem]`,e?`bg-amber-tint`:t?`bg-moss-tint`:`bg-paper-2`),children:[e?(0,q.jsx)(ke,{className:`size-4 shrink-0 self-start text-amber sm:mt-0.5`}):null,t?(0,q.jsx)(Rt,{className:`size-4 shrink-0 self-start text-moss sm:mt-0.5`}):null,(0,q.jsxs)(`div`,{className:`min-w-0 flex-[1_1_14rem]`,children:[n?(0,q.jsx)(`div`,{className:`font-medium`,children:n}):null,r?(0,q.jsx)(`div`,{className:T(n&&`text-[0.8125rem] text-ink-2`),children:r}):null]}),i]})}var Gc={sandbox:`cloud.problem.sandbox`,mcp:`cloud.problem.mcp`,model:`cloud.problem.model`,connector:`cloud.problem.connector`,invalid:`cloud.problem.invalid`};function Kc({problems:e}){return(0,q.jsx)(`ul`,{className:`flex flex-col gap-2 text-[0.8125rem] text-ink-2`,children:e.map((e,t)=>(0,q.jsxs)(`li`,{children:[e.steps.length?(0,q.jsxs)(`span`,{className:`font-medium text-ink`,children:[e.steps.map(e=>I(`cloud.stepName`,{title:e.title})).join(`, `),`:`,` `]}):null,I(Gc[e.code]??`cloud.problem.invalid`,{detail:e.detail}),e.detail&&e.code!==`mcp`&&e.code!==`sandbox`?(0,q.jsxs)(`details`,{className:`mt-0.5`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer text-[0.75rem] text-ink-4 hover:text-ink-3`,children:I(`share.details`)}),(0,q.jsx)(`span`,{className:`mt-0.5 block break-words font-mono text-[0.6875rem] text-ink-4`,children:e.detail})]}):null]},t))})}var qc=()=>new Intl.DateTimeFormat(l,{timeStyle:`short`});function Jc({error:e}){let t=r(),n=e.reason===`space_limit`,a=i({queryKey:[`cloud-spaces`],queryFn:()=>L.get(`/api/studio/cloud/spaces`),enabled:n,retry:!1}),o=Tt({mutationFn:()=>L.post(`/api/studio/cloud/replace`),onSettled:()=>Promise.all([t.invalidateQueries({queryKey:[`cloud`]}),t.invalidateQueries({queryKey:[`cloud-spaces`]}),t.invalidateQueries({queryKey:[`wizards`]})])});if(!n)return(0,q.jsxs)(`p`,{children:[e.message,` `,e.reason===`signed_out`?(0,q.jsx)(fe,{to:`/settings/account`,className:`font-medium underline underline-offset-2`,children:I(`local.toAccount`)}):null,e.again?(0,q.jsx)(`span`,{className:`text-ink-3`,children:I(`cloud.again`,{when:qc().format(new Date(e.again))})}):null]});let s=(a.data?.spaces??[]).map(e=>e.name);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`p`,{children:e.message}),(0,q.jsx)(`p`,{className:`text-ink-2`,children:I(`cloud.spaceLimit`)}),s.length?(0,q.jsx)(`ul`,{className:`list-disc pl-5`,children:s.map((e,t)=>(0,q.jsx)(`li`,{children:e},t))}):null,(0,q.jsx)(`div`,{children:(0,q.jsx)(R,{variant:`secondary`,size:`sm`,busy:o.isPending,onClick:()=>window.confirm(I(`cloud.replaceConfirm`))&&o.mutate(),children:I(`cloud.replace`)})}),o.error?(0,q.jsx)(`p`,{className:`text-rose`,children:o.error.message}):null]})}function Yc({wizard:e,where:t,cloud:n}){let i=r(),a=Tt({mutationFn:()=>L.post(`/api/studio/wizards/${e.id}/cloud`),onSuccess:t=>{i.setQueryData([`cloud`,e.id],t),i.invalidateQueries({queryKey:[`wizards`]})}});if(t.kind!==`missing`&&t.kind!==`sending`)return null;let o=n?.copy??null,s=n?.error??null,c=o&&!o.runnable?o.problems.filter(e=>e.blocking):[],l=(!o||o.version<(e.publishedVersion??0)||s)&&s?.reason!==`space_limit`&&s?.reason!==`signed_out`;return(0,q.jsx)(Wc,{warn:!0,action:l?(0,q.jsx)(R,{variant:`secondary`,size:`sm`,busy:a.isPending,onClick:()=>a.mutate(),children:I(o||s?`cloud.resend`:`cloud.send`)}):null,children:(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[s?(0,q.jsx)(Jc,{error:s}):t.kind===`missing`?(0,q.jsx)(`p`,{children:t.why}):null,s&&t.runs!==null?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`cloud.keepsRunning`,{v:t.runs})}):null,c.length?(0,q.jsx)(Kc,{problems:c}):null,a.error?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:a.error.message}):null]})})}function Xc({account:e}){let t=xe(),n=pt(!1);return e?(0,q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-paper-2 px-3.5 py-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,q.jsx)(vt,{className:`mt-0.5 size-4 shrink-0 text-ink-3`}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:I(`share.others`)}),(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:I(`share.localHint`)})]})]}),(0,q.jsxs)(`div`,{className:`flex flex-wrap gap-2 pl-7`,children:[(0,q.jsx)(R,{size:`sm`,busy:n.link.isPending,onClick:()=>n.link.mutate({}),children:I(`account.signIn`)}),(0,q.jsx)(R,{size:`sm`,variant:`secondary`,onClick:()=>t(`/settings/account`),children:I(`account.create`)})]}),(0,q.jsx)(ze,{...n})]}):(0,q.jsx)(Wc,{children:I(`where.hereHint`)})}function Zc({wizard:e,here:t,onChange:n}){let[r,i]=(0,K.useState)(!1),a=(0,K.useRef)(null),o=(0,K.useId)();(0,K.useEffect)(()=>{if(!r)return;let e=e=>{a.current?.contains(e.target)||i(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[r]);let s=e.shareEnabled,c=[{on:!0,label:I(`share.anyone`),hint:I(`share.anyoneMenu`),Icon:St},{on:!1,label:I(`share.onlyYou`),hint:I(`share.onlyYouHint`),Icon:je}],u=s?St:je,d=I(s?`share.anyone`:`share.onlyYou`),f=s?I(`share.anyoneHint`,{n:e.dailyRunLimit.toLocaleString(l)}):I(`share.onlyYouHint`);return t&&(u=st,d=I(`share.thisComputer`),f=I(`share.thisComputerHint`)),(0,q.jsxs)(`section`,{"aria-labelledby":o,className:`flex flex-col gap-2`,children:[(0,q.jsx)(`h3`,{id:o,className:Uc,children:I(`share.access`)}),(0,q.jsxs)(`div`,{ref:a,className:`relative flex items-center gap-3`,children:[(0,q.jsx)(`span`,{className:T(`flex size-10 shrink-0 items-center justify-center rounded-full`,s&&!t?`bg-moss-tint text-moss`:`bg-paper-2 text-ink-2`),children:(0,q.jsx)(u,{className:`size-[1.125rem]`})}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[t||e.readOnly?(0,q.jsx)(`div`,{className:`font-medium text-[0.9375rem]`,children:d}):(0,q.jsxs)(`button`,{type:`button`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>i(e=>!e),className:`-ml-1 inline-flex min-h-7 items-center gap-1 rounded-md px-1 font-medium text-[0.9375rem] hover:bg-accent`,children:[d,(0,q.jsx)(ce,{className:`size-4 text-ink-3`})]}),(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:f})]}),r?(0,q.jsx)(`div`,{role:`menu`,"aria-label":I(`share.access`),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),i(!1))},className:`absolute top-full left-10 z-10 mt-1 flex w-[min(21rem,calc(100%-2.5rem))] origin-top-left animate-unfold flex-col gap-0.5 rounded-xl bg-card p-1.5 shadow-overlay ring-1 ring-border`,children:c.map(e=>(0,q.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":e.on===s,onClick:()=>{i(!1),e.on!==s&&n(e.on)},className:T(`flex min-h-14 items-center gap-3 rounded-lg px-2.5 py-2 text-left transition hover:bg-accent`,e.on===s&&`bg-paper-2`),children:[(0,q.jsx)(e.Icon,{className:`size-4 shrink-0 text-ink-3`}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block font-medium text-[0.875rem]`,children:e.label}),(0,q.jsx)(`span`,{className:`block text-[0.8125rem] text-ink-3`,children:e.hint})]}),(0,q.jsx)(`span`,{className:`flex w-4 shrink-0 justify-center`,children:e.on===s?(0,q.jsx)(A,{className:`size-4`}):null})]},e.label))}):null]})]})}function Qc({ways:e,blocked:t,locked:n,note:r,copied:i,copy:a,onChange:o}){let s=xe(),{sections:c}=mt(),l=(0,K.useId)(),u=e=>{let t=c.find(t=>t.plugin===e.plugin);s(t?`/settings/${t.id}`:`/settings/models`)},d=Ie.filter(t=>e.some(e=>e.group===t.id));return(0,q.jsxs)(`section`,{"aria-labelledby":l,className:`flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,q.jsx)(`h3`,{id:l,className:Uc,children:I(`share.ways`)}),n?null:(0,q.jsx)(`button`,{type:`button`,onClick:o,className:`min-h-8 text-[0.8125rem] text-ink-2 underline underline-offset-[3px] hover:text-ink`,children:I(`share.change`)})]}),d.map(r=>(0,q.jsxs)(`div`,{className:T(`flex flex-col`,t&&`opacity-50`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 pt-2 pb-0.5 text-[0.75rem] text-ink-3`,children:[(0,q.jsx)(r.icon,{className:`size-3.5`}),` `,I(r.label)]}),(0,q.jsx)(`ul`,{className:`flex flex-col`,children:e.filter(e=>e.group===r.id).map(e=>{let r=i===e.id,o=null;if(e.problem)o=n?null:(0,q.jsx)(R,{size:`sm`,variant:`quiet`,onClick:()=>u(e),children:I(`share.setUp`)});else if(e.copy){let{text:n,number:i}=e.copy;o=(0,q.jsxs)(R,{size:`sm`,variant:`secondary`,disabled:t,"aria-label":I(i?`share.copyNumberFor`:`share.copyLinkFor`,{name:e.name}),onClick:()=>a(e.id,n),children:[r?(0,q.jsx)(A,{className:`size-3.5`}):(0,q.jsx)(oe,{className:`size-3.5`}),I(r?`share.copied`:i?`share.copyNumber`:`share.copyLink`)]})}return(0,q.jsxs)(`li`,{className:`flex min-h-13 items-center gap-3 py-1`,children:[(0,q.jsx)(`span`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-paper-2 text-ink-2`,children:e.icon}),(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:`block text-[0.9375rem]`,children:e.name}),e.problem?(0,q.jsx)(`span`,{className:`block text-[0.8125rem] text-amber`,title:e.problem,children:I(`share.unset`)}):e.note?(0,q.jsx)(`span`,{className:`block truncate text-[0.8125rem] text-ink-3`,title:e.note,children:e.note}):null]}),o]},e.id)})})]},r.id)),r?(0,q.jsx)(`p`,{className:`mt-2.5 text-[0.8125rem] text-ink-3`,children:r}):null]})}function $c({ways:e,title:t,code:n,base:r}){let i=e.filter(e=>e.link&&!e.problem),a=i.find(e=>e.link===r)??i[0],[o,s]=(0,K.useState)(a?.id),c=i.find(e=>e.id===o)??a,l=c?.link??r??``,u=(0,K.useMemo)(()=>jc(l),[l]);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Vc,{className:`flex flex-col items-center gap-3`,children:[i.length>1?(0,q.jsxs)(`fieldset`,{className:`m-0 flex flex-wrap items-center gap-1.5 self-stretch border-0 p-0`,children:[(0,q.jsx)(`legend`,{className:`sr-only`,children:I(`share.qrOpens`)}),(0,q.jsx)(`span`,{"aria-hidden":`true`,className:`mr-1 text-[0.8125rem] text-ink-3`,children:I(`share.qrOpens`)}),i.map(e=>(0,q.jsx)(`button`,{type:`button`,"aria-pressed":e.id===c?.id,onClick:()=>s(e.id),className:T(`h-8 rounded-full px-3 font-medium text-[0.8125rem] transition coarse:h-10`,e.id===c?.id?`bg-ink text-paper`:`text-ink ring-1 ring-border hover:bg-accent`),children:e.name},e.id))]}):null,(0,q.jsx)(Ic,{svg:u,label:I(`share.qr`),className:`mt-2 size-56 p-1`}),(0,q.jsx)(`div`,{className:`font-medium`,children:t}),(0,q.jsx)(`p`,{className:`max-w-sm text-center text-[0.8125rem] text-ink-3`,children:c?.group===`web`||!c?I(`share.qrHint`):I(`share.qrMessage`,{name:c.name})}),n&&l===r?(0,q.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:[I(`share.code`),` `,(0,q.jsx)(`span`,{className:`select-all font-mono text-[0.9375rem] text-ink tracking-wider`,children:Ac(n)})]}):null]}),(0,q.jsxs)(Hc,{children:[(0,q.jsxs)(R,{variant:`ghost`,className:`max-sm:flex-1`,onClick:()=>Fc(u,t),children:[(0,q.jsx)(Se,{className:`size-4`}),` `,I(`share.print`)]}),(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsxs)(R,{className:`max-sm:order-first max-sm:w-full`,onClick:()=>void Pc(u,t),children:[(0,q.jsx)(x,{className:`size-4`}),` `,I(`share.download`)]})]})]})}var el=e=>e.replace(/&/g,`&amp;`).replace(/"/g,`&quot;`).replace(/</g,`&lt;`),tl={inline:{label:`share.place.inline`,hint:`share.place.inlineHint`},button:{label:`share.place.button`,hint:`share.place.buttonHint`},bubble:{label:`share.place.bubble`,hint:`share.place.bubbleHint`},popout:{label:`share.place.popout`,hint:`share.place.popoutHint`}};function nl({place:e}){return(0,q.jsxs)(`span`,{"aria-hidden":`true`,className:`relative block h-16 overflow-hidden rounded-lg bg-paper ring-1 ring-border-soft`,children:[(0,q.jsx)(`span`,{className:`absolute inset-x-2 top-2 h-1.5 rounded-full bg-paper-3`}),(0,q.jsx)(`span`,{className:`absolute top-5 left-2 h-1 w-1/2 rounded-full bg-paper-3`}),e===`inline`?(0,q.jsx)(`span`,{className:`absolute inset-x-2 top-8 bottom-2 rounded-md bg-primary`}):null,e===`button`?(0,q.jsx)(`span`,{className:`absolute top-9 left-2 h-3.5 w-12 rounded-full bg-primary`}):null,e===`bubble`||e===`popout`?(0,q.jsx)(`span`,{className:`absolute right-2 bottom-2 size-[1.125rem] rounded-full bg-primary`}):null]})}function rl({url:e,title:t,enabled:n,wordpress:r,onPackage:i}){let{copied:a,copy:o}=Bc(),s=[`steps`,`chat`].filter(e=>n.includes(e)),c=s.length?s:[`steps`],[l,u]=(0,K.useState)(c[0]),[d,f]=(0,K.useState)(`inline`),p=l===`chat`,m=p?[`inline`,`popout`]:[`inline`,`button`,`bubble`],h=m.includes(d)?d:`inline`,[,g,_]=e?.match(/^(.*)\/w\/([^/]+)$/)??[],v=``;p?v=h===`popout`?` data-mode="popout"`:` data-runner="chat"`:h!==`inline`&&(v=` data-mode="${h===`button`?`modal`:`bubble`}" data-label="${el(t)}"`);let y=_?`<script async src="${g}/embed.js" data-wizard="${_}"${v}><\/script>`:null;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Vc,{className:`flex flex-col gap-5`,children:[y?(0,q.jsxs)(q.Fragment,{children:[c.length>1?(0,q.jsxs)(`fieldset`,{className:`m-0 border-0 p-0`,children:[(0,q.jsx)(`legend`,{className:T(Uc,`mb-2 p-0`),children:I(`share.webShows`)}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>(0,q.jsx)(`button`,{type:`button`,"aria-pressed":e===l,onClick:()=>u(e),className:T(`h-8 rounded-full px-3.5 font-medium text-[0.8125rem] transition coarse:h-10`,e===l?`bg-ink text-paper`:`text-ink ring-1 ring-border hover:bg-accent`),children:I(e===`chat`?`new.ch.chat`:`new.ch.steps`)},e))})]}):null,(0,q.jsxs)(`fieldset`,{className:`m-0 border-0 p-0`,children:[(0,q.jsx)(`legend`,{className:T(Uc,`mb-2 p-0`),children:I(`share.webWhere`)}),(0,q.jsx)(`div`,{className:T(`grid gap-2.5`,m.length===3?`grid-cols-2 sm:grid-cols-3`:`grid-cols-2`),children:m.map(e=>(0,q.jsxs)(`button`,{type:`button`,"aria-pressed":e===h,onClick:()=>f(e),className:T(`flex flex-col gap-2 rounded-xl p-2 pb-2.5 text-left font-medium text-[0.8125rem] transition`,e===h?`bg-paper-2 ring-2 ring-ink`:`ring-1 ring-border hover:bg-accent`),children:[(0,q.jsx)(nl,{place:e}),I(tl[e].label)]},e))}),(0,q.jsx)(`p`,{className:`mt-2 text-[0.8125rem] text-ink-3`,children:I(tl[h].hint)})]}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`h3`,{className:Uc,children:I(`share.webCode`)}),(0,q.jsx)(`pre`,{className:`select-all whitespace-pre-wrap break-all rounded-lg bg-paper-2 px-3 py-2.5 font-mono text-[0.75rem] text-ink-2 leading-relaxed`,children:y})]})]}):(0,q.jsx)(`p`,{className:`text-[0.875rem] text-ink-2`,children:I(`share.webNeedsLink`)}),r?(0,q.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:[I(`share.wpLine`),` `,(0,q.jsx)(`a`,{href:Lc,target:`_blank`,rel:`noreferrer`,className:`font-medium text-ink-2 underline underline-offset-2 hover:text-ink`,children:I(`share.wpPlugin`)}),` · `,(0,q.jsx)(`button`,{type:`button`,onClick:i,className:`font-medium text-ink-2 underline underline-offset-2 hover:text-ink`,children:I(`share.wpPackageLink`)})]}):null]}),y?(0,q.jsxs)(Hc,{children:[(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsxs)(R,{className:`max-sm:w-full`,onClick:()=>o(`code`,y),children:[a===`code`?(0,q.jsx)(A,{className:`size-4`}):(0,q.jsx)(oe,{className:`size-4`}),I(a===`code`?`share.copied`:`share.copyCode`)]})]}):null]})}function il({wizard:e}){let t=Rs(e.draft),[n,r]=(0,K.useState)(!1),i=[e.published?`published=1`:``,n?`knowledge=1`:``].filter(Boolean).join(`&`),a=`/api/studio/wizards/${e.id}/export${i?`?${i}`:``}`;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Vc,{className:`flex flex-col gap-4`,children:[(0,q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,q.jsx)(zs,{fit:t.fit})}),(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-2`,children:I(`share.wpLocalHint`)}),(0,q.jsx)(Hs,{def:e.draft,fit:t}),t.fit===`no`?null:(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-[0.875rem]`,children:I(`share.wpKnowledge`)}),(0,q.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:I(`share.wpKnowledgeHint`)})]}),(0,q.jsx)(w,{checked:n,onChange:r,label:I(`share.wpKnowledge`)})]}),(0,q.jsx)(`p`,{className:`text-[0.75rem] text-ink-3`,children:I(`share.wpHelp`)})]}),t.fit===`no`?null:(0,q.jsxs)(Hc,{children:[(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsxs)(R,{className:`max-sm:w-full`,onClick:()=>window.open(ve(a),`_blank`),children:[(0,q.jsx)(x,{className:`size-4`}),I(e.published?`share.wpPackage`:`share.wpPackageDraft`)]})]})]})}function al({wizard:e,ways:t,cloudCopy:n,onDone:i}){let a=r(),o=(0,K.useId)(),[s,c]=(0,K.useState)(String(e.dailyRunLimit)),{shareSections:l}=mt(),u=()=>Promise.all([a.invalidateQueries({queryKey:[`wizard`,e.id]}),a.invalidateQueries({queryKey:[`wizards`]}),a.invalidateQueries({queryKey:[`wizard-runners`,e.id]})]),d=Tt({mutationFn:t=>L.patch(`/api/studio/wizards/${e.id}`,t),onSuccess:u}),f=Tt({mutationFn:()=>L.post(`/api/studio/wizards/${e.id}/rotate-link`),onSuccess:({cloud:t})=>(t&&a.setQueryData([`cloud`,e.id],{linked:!0,...t}),u())}),p=e.readOnly,m=d.error??f.error,h=ao(e.id,e.draft),g=h.data?.available&&h.data.reserve>0?Math.round(h.data.reserve*(Number(s)||e.dailyRunLimit)):null,_=t.flatMap(e=>{let t=e.problem?null:l.find(t=>t.runner===e.id);return t?[{way:e,section:t}]:[]});return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Vc,{className:`flex flex-col gap-6`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(`label`,{htmlFor:o,className:`font-medium text-[0.875rem]`,children:I(`share.limit`)}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,q.jsx)(F,{id:o,inputMode:`numeric`,className:`w-24 text-right`,disabled:p,value:s,onChange:e=>c(e.target.value.replace(/\D/g,``)),onBlur:()=>{let t=Number(s);t>=1&&t!==e.dailyRunLimit&&d.mutate({dailyRunLimit:t})}}),(0,q.jsx)(`span`,{className:`text-[0.875rem] text-ink-2`,children:I(`share.runs`)})]}),g!==null&&h.data?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3 tabular-nums`,children:I(`estimate.share`,{run:Math.round(h.data.credits).toLocaleString(),day:g.toLocaleString()})}):null]}),p?null:_.map(({way:t,section:n})=>(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[0.75rem] text-ink-3`,children:[t.icon,` `,t.name]}),(0,q.jsx)(bt,{of:n,children:(0,q.jsx)(n.component,{wizard:{id:e.id,title:e.draft.title}})})]},t.id)),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-3 border-border-soft border-t pt-5`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-[1_1_14rem]`,children:[(0,q.jsx)(`div`,{className:`font-medium text-[0.875rem]`,children:I(`share.newLink`)}),(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(n?`share.rotateCloud`:`share.rotateHint`)})]}),(0,q.jsxs)(R,{variant:`secondary`,size:`sm`,busy:f.isPending,disabled:p,onClick:()=>f.mutate(),children:[f.isSuccess?(0,q.jsx)(A,{className:`size-3.5`}):(0,q.jsx)(C,{className:`size-3.5`}),I(f.isSuccess?`share.rotated`:`share.rotate`)]})]}),p?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`share.readOnly`)}):null,m?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:m.message}):null]}),(0,q.jsxs)(Hc,{children:[(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsx)(R,{className:`max-sm:w-full`,onClick:i,children:I(`share.done`)})]})]})}function ol({wizard:e,answer:t,onDone:n}){let i=r(),a=Tt({mutationFn:t=>L.patch(`/api/studio/wizards/${e.id}`,{runners:t}),onSuccess:()=>Promise.all([i.invalidateQueries({queryKey:[`wizard-runners`,e.id]}),i.invalidateQueries({queryKey:[`wizard`,e.id]}),i.invalidateQueries({queryKey:[`wizards`]})])}),o=Me(a.variables?.enabled??t?.settings.enabled??[]);return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Vc,{children:[(0,q.jsx)(Pe,{value:o,onChange:e=>a.mutate(Le(e)),runners:t?.runners,without:[`wacall`],disabled:e.readOnly}),a.error?(0,q.jsx)(`p`,{className:`mt-3 text-[0.8125rem] text-rose`,children:a.error.message}):null]}),(0,q.jsxs)(Hc,{children:[(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsx)(R,{className:`max-sm:w-full`,onClick:n,children:I(`share.done`)})]})]})}function sl({wizard:e,onClose:t,publish:n}){let a=r(),o=Ve(`account`),s=Ye(),c=s.data?.mode===`local`&&!!s.data?.account,l=Ue(e.id,c),u=s.data?$e(e,s.data,c?l.data:null):{kind:`unknown`},d=Xe(u),f=u.kind===`here`,p=s.data?.mode===`managed`&&e.published,m=i({queryKey:[`wizard-code`,e.id,e.shareToken],queryFn:()=>L.get(`/api/studio/wizards/${e.id}/code`),enabled:p}),g=i({queryKey:[`wizard-runners`,e.id,e.revision],queryFn:()=>L.get(`/api/studio/wizards/${e.id}/runners`)}),_=Tt({mutationFn:t=>L.patch(`/api/studio/wizards/${e.id}`,{shareEnabled:t}),onSuccess:()=>Promise.all([a.invalidateQueries({queryKey:[`wizard`,e.id]}),a.invalidateQueries({queryKey:[`wizards`]})])}),[v,y]=(0,K.useState)(`main`),{copied:b,copy:x}=Bc(),[S,C]=(0,K.useState)(null),[w,ee]=(0,K.useState)(null),te=(0,K.useRef)(!1);(0,K.useEffect)(()=>{te.current||e.published||e.readOnly||!n||n.disabled||(te.current=!0,C(`publishing`),n.run().then(()=>C(`done`)).catch(e=>{C(null),ee(e.message)}))},[e.published,e.readOnly,n]);let E=(0,K.useMemo)(()=>g.data?zc(g.data,d):[],[g.data,d]),ne=!e.published||f||!e.shareEnabled||!d,D=E.find(e=>e.copy?.text===d),re=new Set(E.map(e=>e.group)).size,O=Math.min(720,Math.max(580,300+re*28+E.length*52+(e.published&&!e.dirty?0:96))),[k,ie]=(0,K.useState)(O);(0,K.useEffect)(()=>ie(e=>Math.max(e,O)),[O]);let ae=null;if(e.published&&!f&&!e.shareEnabled)ae=I(`share.offNote`);else if(D&&E.length>1){let e=D.id===`steps`?I(`share.opensSteps`):I(`share.opensAs`,{name:D.name});ae=I(`share.linkNote`,{how:e})}let M=()=>y(v===`package`?`website`:`main`),N=e.draft.title;return(0,q.jsxs)(`div`,{style:{"--share-h":`${k}px`},className:`mx-auto flex w-full flex-col overflow-hidden bg-card text-ink shadow-overlay max-sm:h-dvh max-sm:pt-[env(safe-area-inset-top)] max-sm:pb-[env(safe-area-inset-bottom)] sm:h-[min(var(--share-h),calc(100dvh-32px))] sm:max-w-[34rem] sm:rounded-2xl`,children:[(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 px-2 pt-3 pb-1 sm:px-3 sm:pt-4`,children:[v===`main`?null:(0,q.jsx)(z,{label:I(`share.back`),onClick:M,children:(0,q.jsx)(me,{className:`size-5`})}),(0,q.jsx)(`h2`,{className:T(`min-w-0 flex-1 truncate font-display font-semibold text-xl`,v===`main`&&`pl-2 sm:pl-3`),children:v===`main`?I(`share.titleOf`,{title:N}):I(Rc[v])}),v===`main`?(0,q.jsx)(z,{label:I(`share.settings`),onClick:()=>y(`settings`),children:(0,q.jsx)(qe,{className:`size-[1.125rem]`})}):null,(0,q.jsx)(z,{label:I(`share.close`),onClick:t,children:(0,q.jsx)(le,{className:`size-5`})})]}),v===`main`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(Vc,{className:`flex flex-col gap-6`,children:[S===`publishing`?(0,q.jsx)(Wc,{children:(0,q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(j,{className:`size-4 text-ink-3`}),` `,I(`share.publishing`)]})}):null,S===`done`&&e.published?(0,q.jsx)(Wc,{done:!0,title:I(`share.firstTitle`),children:I(`share.firstText`,{v:e.publishedVersion??1})}):null,!e.published&&!S?(0,q.jsx)(Wc,{warn:!0,title:I(e.issues.length?`share.notReady`:`share.notPublished`),action:e.issues.length&&n?.fix?(0,q.jsx)(R,{size:`sm`,variant:`secondary`,onClick:n.fix,children:I(`editor.fixWithChat`)}):null,children:e.issues.length?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{children:I(`share.notReadyHint`)}),(0,q.jsx)(`ul`,{className:`mt-1 list-disc pl-5`,children:e.issues.slice(0,4).map((e,t)=>(0,q.jsx)(`li`,{children:e.message},t))})]}):w??I(e.readOnly?`share.readOnly`:`share.stillBuilding`)}):null,e.published&&e.dirty&&!e.readOnly&&!S?(0,q.jsx)(Wc,{action:n?(0,q.jsx)(R,{size:`sm`,onClick:n.goLive,children:I(`live.open`)}):null,children:I(`share.changes`,{v:e.publishedVersion??0})}):null,f&&e.published?(0,q.jsx)(Xc,{account:o}):null,c&&e.published?(0,q.jsx)(Yc,{wizard:e,where:u,cloud:l.data}):null,l.isError?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-rose`,children:l.error.message}):null,(0,q.jsx)(Zc,{wizard:e,here:f,onChange:e=>_.mutate(e)}),_.error?(0,q.jsx)(`p`,{className:`-mt-4 text-[0.8125rem] text-rose`,children:_.error.message}):null,g.data?(0,q.jsx)(Qc,{ways:E,blocked:ne,locked:e.readOnly,note:ae,copied:b,copy:x,onChange:()=>y(`channels`)}):null]}),(0,q.jsxs)(Hc,{children:[(0,q.jsxs)(R,{variant:`ghost`,className:`max-sm:flex-1`,disabled:ne,onClick:()=>y(`qr`),children:[(0,q.jsx)(an,{className:`size-4`}),` `,I(`share.qr`)]}),(0,q.jsxs)(R,{variant:`ghost`,className:`max-sm:flex-1`,onClick:()=>y(`website`),children:[(0,q.jsx)(Wt,{className:`size-4`}),` `,I(`share.website`)]}),(0,q.jsx)(`span`,{className:`flex-1 max-sm:hidden`}),(0,q.jsxs)(R,{className:`max-sm:order-first max-sm:w-full`,disabled:ne,onClick:()=>d&&x(`main`,d),children:[b===`main`?(0,q.jsx)(A,{className:`size-4`}):(0,q.jsx)(h,{className:`size-4`}),I(b===`main`?`share.copied`:`share.copyMain`)]})]})]}):null,v===`qr`?(0,q.jsx)($c,{ways:E,title:N,base:d,code:p?m.data?.code:l.data?.copy?.code}):null,v===`website`?(0,q.jsx)(rl,{url:ne?null:d,title:N,enabled:g.data?.settings.enabled??[],wordpress:o,onPackage:()=>y(`package`)}):null,v===`package`?(0,q.jsx)(il,{wizard:e}):null,v===`settings`?(0,q.jsx)(al,{wizard:e,ways:E,cloudCopy:!!l.data?.copy,onDone:()=>y(`main`)}):null,v===`channels`?(0,q.jsx)(ol,{wizard:e,answer:g.data,onDone:()=>y(`main`)}):null]})}function cl({wizard:e,open:t,onClose:n,publish:r}){return(0,q.jsx)(se,{open:t,onClose:n,bare:!0,wide:!0,children:(0,q.jsx)(sl,{wizard:e,onClose:n,publish:r})})}var ll=[`title`,`description`,`avatar`,`intro`,`lists`,`connections`],ul=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function dl(e,t,n){let r={...n};for(let n of ll)ul(t[n],e[n])||Object.assign(r,{[n]:t[n]});let i=new Map(e.steps.map(e=>[e.id,e])),a=new Set(t.steps.map(e=>e.id)),o=n.steps.filter(e=>{let t=i.get(e.id);return a.has(e.id)||!t||!ul(t,e)});return t.steps.forEach((e,n)=>{let r=i.get(e.id);if(r&&ul(r,e))return;let a=o.findIndex(t=>t.id===e.id);if(a!==-1){o[a]=e;return}let s=t.steps.slice(0,n).reverse().find(e=>o.some(t=>t.id===e.id));o.splice(s?o.findIndex(e=>e.id===s.id)+1:0,0,e)}),{...r,steps:o}}function fl(e){let t=r(),n=(0,K.useMemo)(()=>[`wizard`,e],[e]),i=`/api/studio/wizards/${e}`,a=(0,K.useRef)(null),o=(0,K.useRef)(Promise.resolve()),s=(0,K.useRef)(null),c=(0,K.useRef)(null),l=(0,K.useRef)(!1),[u,d]=(0,K.useState)(!1),[f,p]=(0,K.useState)(0),[m,h]=(0,K.useState)(null),[g,_]=(0,K.useState)(null),v=(0,K.useCallback)(()=>!!(a.current||l.current||s.current),[]),y=(0,K.useCallback)(async()=>{let e=await L.get(i);t.setQueryData(n,t=>t&&v()?{...e,draft:t.draft,title:t.title,revision:t.revision,dirty:!0}:e)},[t,n,i,v]),b=(0,K.useCallback)(()=>{o.current=o.current.then(async()=>{let e=s.current,r=t.getQueryData(n);if(e&&r){s.current=null,l.current=!0,d(!0);try{let a=await L.put(`${i}/draft`,{definition:e,baseRevision:r.revision});c.current=s.current?e:null,t.setQueryData(n,e=>e&&{...e,revision:a.revision,issues:a.issues})}catch(r){let a=Ge(r);if(a){s.current=null,c.current=null,_(a);let e=await L.get(i).catch(()=>null);e&&t.setQueryData(n,e);return}if(!(r instanceof ge&&r.status===409)){s.current??=e,console.error(`[draft] save failed`,r);return}let o=await L.get(i),l=dl(c.current??o.draft,s.current??e,o.draft);c.current=o.draft,s.current=l,t.setQueryData(n,{...o,draft:l,title:l.title,dirty:!0}),p(Date.now()),b()}finally{l.current=!1,d(!1)}}})},[t,n,i]),x=(0,K.useCallback)(r=>{e&&(v()||(c.current=t.getQueryData(n)?.draft??null),s.current=r,t.setQueryData(n,e=>e&&{...e,draft:r,title:r.title,dirty:!0}),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{a.current=null,b()},600))},[t,n,e,v,b]);return(0,K.useEffect)(()=>{if(!e)return;let r=new EventSource(ve(`/api/studio/wizards/${e}/stream`));return r.addEventListener(`change`,e=>{let r=JSON.parse(e.data),i=t.getQueryData(n);r.kind===`draft`&&i&&r.revision<=i.revision||(y(),r.kind===`draft`&&r.source===`mcp`&&h({client:r.client??`MCP`,steps:r.touched,at:Date.now()}))}),r.addEventListener(`hello`,e=>{let{revision:r}=JSON.parse(e.data),i=t.getQueryData(n);i&&r!==i.revision&&y()}),()=>r.close()},[t,n,e,y]),(0,K.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>h(null),6e3);return()=>clearTimeout(e)},[m]),(0,K.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>p(0),4e3);return()=>clearTimeout(e)},[f]),{save:x,saving:u,remote:m,merged:f>0,refused:g}}function pl({remote:e,merged:t}){return e?(0,q.jsxs)(N,{tone:`ember`,children:[(0,q.jsx)(et,{className:`size-3`}),` `,I(`editor.changedVia`,{client:e.client})]}):t?(0,q.jsxs)(N,{children:[(0,q.jsx)(Xt,{className:`size-3`}),` `,I(`editor.merged`)]}):null}var ml=[...te,`image`,`video`],hl={chat:`editor.chat`,step:`editor.step`,files:`editor.files`,memory:`editor.memory`,runs:`editor.runs`},gl=`wizards.editor.pane`,_l=420,vl=340,yl=()=>Math.max(vl,window.innerWidth-480);function bl(){try{let e=Number(localStorage.getItem(gl));return e?Math.min(Math.max(e,vl),yl()):_l}catch{return _l}}function xl(){let[e,t]=(0,K.useState)(bl),n=(0,K.useCallback)(e=>{let n=Math.round(Math.min(Math.max(e,vl),yl()));t(n);try{localStorage.setItem(gl,String(n))}catch{}},[]);return{width:e,onPointerDown:t=>{t.preventDefault();let r=t.clientX,i=e,a=e=>n(i+r-e.clientX),o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`)};document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)},onKeyDown:t=>{let r=t.shiftKey?64:16;t.key===`ArrowLeft`?(t.preventDefault(),n(e+r)):t.key===`ArrowRight`&&(t.preventDefault(),n(e-r))},reset:()=>n(_l)}}var Sl=`wizards.editor.sheet`,Cl=55,wl=76,Tl=96,El=6;function Dl(){try{let e=localStorage.getItem(Sl),t=e===null?NaN:Number(e);return Number.isFinite(t)?Math.min(Math.max(t,0),100):Cl}catch{return Cl}}function Ol(){let[e,t]=(0,K.useState)(Dl),[n,r]=(0,K.useState)(!1),i=(0,K.useRef)(null),a=(0,K.useRef)(e||Cl),o=(0,K.useCallback)((e,n=!0)=>{let r=Math.round(Math.min(Math.max(e,0),100)*10)/10;r>0&&n&&(a.current=r),t(r);try{localStorage.setItem(Sl,String(r))}catch{}},[]),s=e===0,c=()=>o(s?a.current:0);return{ref:i,percent:e,height:`clamp(${wl}px, ${e}%, calc(100% - ${Tl}px))`,folded:s,dragging:n,unfold:()=>{s&&o(a.current)},onPointerDown:t=>{let n=i.current,a=n?.parentElement;if(!(n&&a)||t.button!==0)return;t.preventDefault();let s=t.clientY,l=n.getBoundingClientRect().height,u=a.getBoundingClientRect().height,d=!1,f=e,p=e=>{if(!d&&Math.abs(e.clientY-s)<El)return;d||(d=!0,r(!0));let t=Math.min(l+s-e.clientY,u-Tl);f=t<92?0:t/u*100,o(f,!1)},m=e=>{window.removeEventListener(`pointermove`,p),window.removeEventListener(`pointerup`,m),window.removeEventListener(`pointercancel`,m),document.body.style.removeProperty(`cursor`),document.body.style.removeProperty(`user-select`),r(!1),d?o(f):e.type===`pointerup`&&c()};document.body.style.cursor=`row-resize`,document.body.style.userSelect=`none`,window.addEventListener(`pointermove`,p),window.addEventListener(`pointerup`,m),window.addEventListener(`pointercancel`,m)},onKeyDown:t=>{let n=t.shiftKey?25:10;t.key===`ArrowUp`?(t.preventDefault(),o(e+n)):t.key===`ArrowDown`?(t.preventDefault(),o(e-n<15?0:e-n)):(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),c())}}}function kl(){let e=Ve(`account`),{id:t}=ae(),n=xe(),a=r(),o=Ye(),[s,c]=be(),l=i({queryKey:[`wizard`,t],queryFn:()=>L.get(`/api/studio/wizards/${t}`),refetchOnWindowFocus:!1}),[u,d]=(0,K.useState)(null),[f,p]=(0,K.useState)(`chat`),m=xl(),h=Ol(),[g,_]=(0,K.useState)(!1),[v,y]=(0,K.useState)(!1),[b,S]=(0,K.useState)(null),[C,w]=De(),[ee,te]=(0,K.useState)(null),[E,ne]=(0,K.useState)(),[D,re]=(0,K.useState)(0),[O,k]=(0,K.useState)(null),[A,M]=(0,K.useState)(null),oe=(0,K.useCallback)(e=>M(e),[]),se=(0,K.useCallback)(e=>{te(e&&e.status!==`done`?e.step?.id??null:null),e&&ne(e.decisions)},[]),{save:P,saving:F,remote:ce,merged:le,refused:de}=fl(t),fe=Ze(),B=Ct(l.data,(e,n)=>{a.setQueryData([`wizard`,t],t=>t&&{...t,draft:e,revision:n,title:e.title,blank:!1})}),pe=(0,K.useRef)(!1);(0,K.useEffect)(()=>{let e=s.get(`prompt`);e&&l.data&&!pe.current&&(pe.current=!0,c({},{replace:!0}),B.send(e))},[s,l.data,B,c]);let me=i({queryKey:[`wizard-models`,t,l.data?.revision],queryFn:()=>L.get(`/api/studio/wizards/${t}/models`),enabled:!!l.data}).data?.missing??[],he=o.data?.mode===`local`&&!!o.data.account,ge=Ue(t??``,!!t&&he),_e=me.some(e=>e.blocking),V=Tt({mutationFn:()=>L.post(`/api/studio/wizards/${t}/test-runs`),onSuccess:({runId:e})=>S(e)}),H=Tt({mutationFn:()=>L.post(`/api/studio/wizards/${t}/publish`),onSuccess:async({cloud:e})=>{e&&a.setQueryData([`cloud`,t],{linked:!0,...e}),await Promise.all([a.invalidateQueries({queryKey:[`wizard`,t]}),a.invalidateQueries({queryKey:[`cloud`,t]}),a.invalidateQueries({queryKey:[`wizards`]})])}}),ye=(0,K.useMemo)(()=>new Set((l.data?.issues??[]).map(e=>e.stepId).filter(Boolean)),[l.data?.issues]);if(l.isLoading||!o.data)return(0,q.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-ink-4`,children:(0,q.jsx)(j,{})});if(!l.data)return(0,q.jsx)(`div`,{className:`p-10 text-center text-ink-3`,children:I(`run.notFound`)});let U=l.data,W=U.draft,Se=xo(W,E),G=B.phase!==`idle`&&U.blank&&!O,Ce=U.issues.length>0,we=()=>{_(!1),y(!1),p(`chat`),B.send(`Bitte behebe diese Probleme im Wizard:\n${U.issues.map(e=>`- ${e.message}`).join(`
3
+ `)}`)},Te=fe.data?.find(e=>e.id===U.projectId),ke=Te?Te.origin===`local`:o.data.limits.build||fe.isLoading,Me=U.readOnly?I(ke?`readonly.wizard`:`readonly.server`):null,Ne=o.data.mode===`local`&&e&&me.some(e=>ml.includes(e.cls))?o.data.account?o.data.models?.source===`account`?null:`use`:`connect`:null,Pe=de??(H.error?H.error.message:null),Fe=e=>{d(e),e&&(p(`step`),h.unfold())},Ie=e=>{if(B.phase!==`idle`)return!1;let n=new Set(W.steps.map(e=>e.id));return k(e),B.send(pn(W,e)).then(()=>{k(null);let e=(a.getQueryData([`wizard`,t])?.draft)?.steps.find(e=>!n.has(e.id));e&&(d(e.id),p(e=>e===`chat`?e:`step`))}),!0},Le=U.readOnly?void 0:{adding:O,add:Ie,ask:e=>B.phase===`idle`&&(B.send(e),!0),working:(0,q.jsx)(ot,{chat:B}),showChat:()=>{p(`chat`),h.unfold()}};return(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[Me?(0,q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 border-border-soft border-b bg-paper-2 px-4 py-2 text-[0.8125rem] text-ink-2 sm:px-6`,children:[(0,q.jsx)(je,{className:`size-4 shrink-0 text-ink-3`}),(0,q.jsx)(`p`,{className:`min-w-0 flex-1`,children:Me})]}):null,Pe?(0,q.jsx)(`div`,{className:`shrink-0 bg-rose-tint px-4 py-2 text-[0.8125rem] text-rose sm:px-6`,children:Pe}):null,(0,q.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center gap-2 px-3 coarse:h-14 sm:px-4`,children:[(0,q.jsx)(z,{label:`Zurück`,onClick:()=>n(`/`),children:(0,q.jsx)(ue,{className:`size-5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>Fe(`__wizard`),className:`min-w-0 truncate rounded-md px-2 py-1 text-left hover:bg-accent`,children:(0,q.jsx)(`span`,{className:`font-display font-semibold text-[1.0625rem] tracking-tight`,children:W.title})}),(0,q.jsx)(`span`,{className:`hidden sm:inline-flex`,children:U.published?(0,q.jsx)(Je,{where:$e(U,o.data,he?ge.data:null),me:o.data,version:U.publishedVersion}):(0,q.jsx)(N,{children:I(`editor.notPublished`)})}),F?(0,q.jsx)(j,{className:`size-4 text-ink-4`}):null,(0,q.jsx)(`span`,{className:`hidden md:inline-flex`,children:(0,q.jsx)(pl,{remote:ce,merged:le})}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,q.jsx)(`a`,{href:ve(`/api/studio/wizards/${U.id}/export`),download:!0,"aria-label":I(`editor.export`),title:I(`editor.export`),className:`hidden size-9 shrink-0 items-center justify-center rounded-full text-ink-3 transition hover:bg-accent hover:text-ink sm:inline-flex`,children:(0,q.jsx)(x,{className:`size-4`})}),(0,q.jsxs)(R,{variant:`secondary`,size:`sm`,disabled:Ce||G||_e,busy:V.isPending,onClick:()=>V.mutate(),children:[(0,q.jsx)(nn,{className:`size-3.5`}),` `,I(`editor.test`)]}),U.published&&U.dirty&&!U.readOnly?(0,q.jsxs)(R,{variant:`secondary`,size:`sm`,onClick:()=>y(!0),children:[(0,q.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-primary`,"aria-hidden":`true`}),(0,q.jsx)(`span`,{className:`max-sm:hidden`,children:I(`live.open`)}),(0,q.jsx)(`span`,{className:`sm:hidden`,children:I(`live.openShort`)})]}):null,(0,q.jsxs)(R,{size:`sm`,onClick:()=>_(!0),children:[(0,q.jsx)(yt,{className:`size-3.5`}),` `,I(`editor.share`)]}),(0,q.jsx)(`span`,{className:`ml-2 hidden md:inline-flex`,children:(0,q.jsx)(gt,{me:o.data})})]})]}),(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col lg:flex-row`,children:[(0,q.jsxs)(`section`,{className:`relative min-h-0 flex-1 overflow-hidden`,children:[Ce&&!G?(0,q.jsxs)(`div`,{className:`absolute top-3 right-3 left-3 z-10 mx-auto max-w-xl animate-rise rounded-xl bg-card p-4 shadow-elevated ring-1 ring-rose/30`,children:[(0,q.jsx)(`p`,{className:`text-[0.875rem]`,children:I(`editor.issues`)}),(0,q.jsx)(`ul`,{className:`mt-2 list-disc pl-5 text-[0.8125rem] text-ink-2`,children:U.issues.slice(0,4).map((e,t)=>(0,q.jsx)(`li`,{children:e.message},t))}),U.readOnly?null:(0,q.jsx)(R,{size:`sm`,variant:`quiet`,className:`mt-3`,disabled:B.phase!==`idle`,onClick:we,children:I(`editor.fixWithChat`)})]}):null,!Ce&&!G&&me.length?(0,q.jsxs)(`div`,{className:T(`absolute top-3 right-3 left-3 z-10 mx-auto max-w-xl animate-rise rounded-xl bg-card p-4 shadow-elevated ring-1`,_e?`ring-rose/30`:`ring-amber/30`),children:[(0,q.jsx)(`p`,{className:`text-[0.875rem]`,children:I(_e?`editor.models.blocking`:`editor.models.optional`)}),(0,q.jsx)(`ul`,{className:`mt-2 list-disc pl-5 text-[0.8125rem] text-ink-2`,children:me.map(e=>(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`text-ink`,children:I(`class.${e.cls}`)}),` (`,e.steps.map(e=>`„${e.title}“`).join(`, `),`):`,` `,(0,q.jsx)(ie,{text:e.problem})]},e.cls))}),(0,q.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-3 gap-y-2`,children:[(0,q.jsx)(R,{size:`sm`,variant:`quiet`,onClick:()=>n(`/settings/models`),children:I(`editor.models.settings`)}),Ne===`connect`?(0,q.jsxs)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:[I(`teaser.models`),` `,(0,q.jsx)(`button`,{type:`button`,className:`font-medium text-ink underline underline-offset-2`,onClick:()=>n(`/settings/account`),children:I(`teaser.connect`)})]}):Ne===`use`?(0,q.jsx)(`p`,{className:`text-[0.8125rem] text-ink-3`,children:I(`teaser.modelsLinked`)}):null]})]}):null,A!==null&&Le&&!G?(0,q.jsx)(`div`,{className:`absolute top-3 right-3 left-3 z-20 mx-auto max-w-xl animate-rise rounded-xl shadow-elevated`,children:(0,q.jsx)(mn,{place:fn(W,A),branchable:A>0,onAdd:(e,t,n)=>Ie({at:A,kind:e,prompt:t,when:n})?(M(null),!0):!1,onEmpty:e=>{let t=vn(W,A,e);P(t.def),M(null),Fe(t.id)},onCancel:()=>M(null)})}):null,G?(0,q.jsx)(`div`,{className:`flex h-full items-center justify-center px-6 text-[0.875rem] text-ink-3`,children:(0,q.jsx)(ot,{chat:B,spinner:`size-4 text-ember`})}):(0,q.jsx)(jo,{def:W,selected:u,onSelect:Fe,issueSteps:ye,activeStep:b?ee:null,pulse:ce?.steps,wizardId:U.id,decisions:Se,onBranch:e=>{Fe(e),re(e=>e+1)},adding:O,onInsert:U.readOnly||O?void 0:oe})]}),(0,q.jsxs)(`aside`,{ref:h.ref,className:T(`relative flex h-(--sheet) min-h-0 w-full shrink-0 flex-col rounded-t-3xl bg-card shadow-[0_0_0_1px_var(--border-soft)] lg:h-auto lg:w-(--pane) lg:rounded-tr-none`,!h.dragging&&`max-lg:motion-safe:transition-[height] max-lg:motion-safe:duration-200`),style:{"--pane":`${m.width}px`,"--sheet":h.height},children:[(0,q.jsx)(`div`,{role:`separator`,"aria-orientation":`horizontal`,"aria-label":I(`editor.resizeSheet`),"aria-valuenow":h.percent,"aria-valuemin":0,"aria-valuemax":100,tabIndex:0,title:I(`editor.resizeSheet`),onPointerDown:h.onPointerDown,onKeyDown:h.onKeyDown,className:`group before:-top-4 relative z-10 flex h-7 shrink-0 cursor-row-resize touch-none select-none items-center justify-center outline-none before:absolute before:inset-x-0 before:h-4 lg:hidden`,children:(0,q.jsx)(`span`,{className:`h-1.5 w-10 rounded-full bg-ink-4/40 transition-all group-hover:bg-ember/70 group-focus-visible:bg-ember group-active:w-14 group-active:bg-ember`})}),(0,q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":I(`editor.resize`),"aria-valuenow":m.width,tabIndex:0,title:I(`editor.resize`),onPointerDown:m.onPointerDown,onKeyDown:m.onKeyDown,onDoubleClick:m.reset,className:`group -left-5 absolute inset-y-0 z-10 hidden w-5 cursor-col-resize outline-none lg:block`,children:(0,q.jsx)(`span`,{className:`-translate-y-1/2 absolute top-1/2 left-[7px] h-12 w-1.5 rounded-full bg-ink-4/40 transition group-hover:bg-ember/70 group-focus-visible:bg-ember group-active:h-16 group-active:bg-ember`})}),(0,q.jsx)(`nav`,{className:`flex shrink-0 gap-1 px-3 lg:pt-3`,children:[`chat`,`step`,`files`,`memory`,`runs`].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>{p(e),h.unfold()},className:T(`h-9 rounded-full px-4 font-medium text-[0.8125rem] transition`,f===e?`bg-paper-2 text-ink`:`text-ink-3 hover:text-ink`),children:I(hl[e])},e))}),(0,q.jsx)(`div`,{className:T(`min-h-0 flex-1 overflow-y-auto`,h.folded&&`max-lg:hidden`),children:f===`chat`?(0,q.jsx)(ut,{chat:B,avatar:W.avatar,closed:Me??void 0}):f===`step`?(0,q.jsx)(cs,{def:W,selected:u,update:P,onSelect:Fe,issues:U.issues,mcpServers:U.mcpServers,files:U.files,wizardId:U.id,readOnly:U.readOnly,decisions:Se,branchFocus:D,assistant:Le}):f===`files`?(0,q.jsx)(xn,{wizardId:U.id,files:U.files,readOnly:U.readOnly}):f===`memory`?(0,q.jsx)(Ss,{wizardId:U.id,projectId:U.projectId,def:W,readOnly:U.readOnly}):(0,q.jsx)(ws,{wizardId:U.id,onOpen:S})})]})]}),b?(0,q.jsx)(Ee,{header:(0,q.jsx)(N,{children:`Test`}),actions:(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Oe,{look:C,onChange:w}),(0,q.jsx)(R,{variant:`ghost`,size:`sm`,busy:V.isPending,disabled:Ce,onClick:()=>V.mutate(),children:I(`editor.restart`)})]}),onClose:()=>S(null),children:C===`chat`?(0,q.jsx)(Ae,{runId:b,onRestart:()=>V.mutate(),onView:se},b):(0,q.jsx)(Et,{runId:b,compact:!0,onRestart:()=>V.mutate(),onView:se},b)}):null,(0,q.jsx)(cl,{wizard:U,open:g,onClose:()=>_(!1),publish:U.readOnly?void 0:{run:()=>H.mutateAsync(),busy:H.isPending,disabled:Ce||G,fix:we,goLive:()=>{_(!1),y(!0)}}}),U.readOnly?null:(0,q.jsx)(xs,{wizard:U,open:v,onClose:()=>y(!1),cloud:he,actions:{publish:()=>H.mutateAsync(),busy:H.isPending,disabled:Ce||G,test:()=>{y(!1),V.mutate()},openRun:e=>{y(!1),S(e)},fix:we,share:()=>{y(!1),_(!0)}}})]})}export{kl as EditorPage};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{Tt as r}from"./ui-CMdSOoUZ.js";import{a as i,c as a,i as o,n as s,r as c,s as l,t as u}from"./esm-B52LIMhP.js";var d=e(t(),1),f=e(n(),1),p=208,m=42,h=26,g=22,_=132;function v({data:e}){let t=e.icon;return(0,f.jsxs)(`div`,{style:{width:p,height:m},className:r(`flex cursor-default items-center gap-2.5 rounded-xl px-2.5`,e.optional?`border border-ink-4 border-dashed`:`bg-paper-2 ring-1 ring-border-soft`),children:[(0,f.jsx)(c,{type:`target`,position:a.Top}),(0,f.jsx)(c,{type:`target`,id:`in`,position:a.Right}),(0,f.jsx)(`span`,{className:r(`inline-flex size-6 shrink-0 items-center justify-center rounded-md`,e.tone),children:(0,f.jsx)(t,{className:`size-3.5`})}),(0,f.jsx)(`span`,{className:`truncate font-medium text-[0.8125rem] text-ink`,children:e.title}),(0,f.jsx)(c,{type:`source`,position:a.Bottom}),(0,f.jsx)(c,{type:`source`,id:`out`,position:a.Right})]})}function y({sourceX:e,sourceY:t,targetX:n,targetY:r,label:i,markerEnd:a}){let o=Math.max(e,n)+g,c=[`M ${e} ${t}`,`H ${o-8}`,`Q ${o} ${t} ${o} ${t+8}`,`V ${r-8}`,`Q ${o} ${r} ${o-8} ${r}`,`H ${n}`].join(` `);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(u,{path:c,markerEnd:a,style:{strokeDasharray:`5 4`}}),(0,f.jsx)(s,{children:(0,f.jsx)(`div`,{style:{width:_,transform:`translate(${o+8}px, ${(t+r)/2}px) translateY(-50%)`},className:`absolute text-[0.6875rem] text-ink-2 leading-snug`,children:i})})]})}var b={step:v},x={branch:y};function S(e){let t={markerEnd:{type:l.ArrowClosed,width:14,height:14,color:`var(--ink-4)`}},n=e.map((e,t)=>({id:e.id,type:`step`,position:{x:0,y:t*68},data:{title:e.title,icon:e.icon,tone:e.tone,optional:e.optional},draggable:!1})),r=[],i=!1;return e.forEach((n,a)=>{let o=e[a+1];for(let[a,o]of(n.branches??[]).entries())e.some(e=>e.id===o.to)&&(i=!0,r.push({id:`b-${n.id}-${a}`,type:`branch`,source:n.id,sourceHandle:`out`,target:o.to,targetHandle:`in`,label:o.when,...t}));o&&r.push({id:`n-${n.id}`,type:`straight`,source:n.id,target:o.id,...t})}),{nodes:n,edges:r,width:p+(i?162:0),height:e.length*68-h}}function C({steps:e}){let{nodes:t,edges:n,width:r,height:a}=(0,d.useMemo)(()=>S(e),[e]);return e.length?(0,f.jsx)(`div`,{className:`max-w-full`,style:{width:r,height:a+4},children:(0,f.jsx)(o,{children:(0,f.jsx)(i,{nodes:t,edges:n,nodeTypes:b,edgeTypes:x,defaultViewport:{x:1,y:2,zoom:1},minZoom:1,maxZoom:1,nodesConnectable:!1,nodesDraggable:!1,nodesFocusable:!1,edgesFocusable:!1,elementsSelectable:!1,panOnDrag:!1,panOnScroll:!1,zoomOnScroll:!1,zoomOnPinch:!1,zoomOnDoubleClick:!1,preventScrolling:!1,proOptions:{hideAttribution:!0}})})}):null}export{C as default};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-BNakU3Ej.js";import{Tt as r}from"./ui-BOCXzzHi.js";import{a as i,c as a,i as o,n as s,r as c,s as l,t as u}from"./esm-BJskogLD.js";var d=e(t(),1),f=e(n(),1),p=208,m=42,h=26,g=22,_=132;function v({data:e}){let t=e.icon;return(0,f.jsxs)(`div`,{style:{width:p,height:m},className:r(`flex cursor-default items-center gap-2.5 rounded-xl px-2.5`,e.optional?`border border-ink-4 border-dashed`:`bg-paper-2 ring-1 ring-border-soft`),children:[(0,f.jsx)(c,{type:`target`,position:a.Top}),(0,f.jsx)(c,{type:`target`,id:`in`,position:a.Right}),(0,f.jsx)(`span`,{className:r(`inline-flex size-6 shrink-0 items-center justify-center rounded-md`,e.tone),children:(0,f.jsx)(t,{className:`size-3.5`})}),(0,f.jsx)(`span`,{className:`truncate font-medium text-[0.8125rem] text-ink`,children:e.title}),(0,f.jsx)(c,{type:`source`,position:a.Bottom}),(0,f.jsx)(c,{type:`source`,id:`out`,position:a.Right})]})}function y({sourceX:e,sourceY:t,targetX:n,targetY:r,label:i,markerEnd:a}){let o=Math.max(e,n)+g,c=[`M ${e} ${t}`,`H ${o-8}`,`Q ${o} ${t} ${o} ${t+8}`,`V ${r-8}`,`Q ${o} ${r} ${o-8} ${r}`,`H ${n}`].join(` `);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(u,{path:c,markerEnd:a,style:{strokeDasharray:`5 4`}}),(0,f.jsx)(s,{children:(0,f.jsx)(`div`,{style:{width:_,transform:`translate(${o+8}px, ${(t+r)/2}px) translateY(-50%)`},className:`absolute text-[0.6875rem] text-ink-2 leading-snug`,children:i})})]})}var b={step:v},x={branch:y};function S(e){let t={markerEnd:{type:l.ArrowClosed,width:14,height:14,color:`var(--ink-4)`}},n=e.map((e,t)=>({id:e.id,type:`step`,position:{x:0,y:t*68},data:{title:e.title,icon:e.icon,tone:e.tone,optional:e.optional},draggable:!1})),r=[],i=!1;return e.forEach((n,a)=>{let o=e[a+1];for(let[a,o]of(n.branches??[]).entries())e.some(e=>e.id===o.to)&&(i=!0,r.push({id:`b-${n.id}-${a}`,type:`branch`,source:n.id,sourceHandle:`out`,target:o.to,targetHandle:`in`,label:o.when,...t}));o&&r.push({id:`n-${n.id}`,type:`straight`,source:n.id,target:o.id,...t})}),{nodes:n,edges:r,width:p+(i?162:0),height:e.length*68-h}}function C({steps:e}){let{nodes:t,edges:n,width:r,height:a}=(0,d.useMemo)(()=>S(e),[e]);return e.length?(0,f.jsx)(`div`,{className:`max-w-full`,style:{width:r,height:a+4},children:(0,f.jsx)(o,{children:(0,f.jsx)(i,{nodes:t,edges:n,nodeTypes:b,edgeTypes:x,defaultViewport:{x:1,y:2,zoom:1},minZoom:1,maxZoom:1,nodesConnectable:!1,nodesDraggable:!1,nodesFocusable:!1,edgesFocusable:!1,elementsSelectable:!1,panOnDrag:!1,panOnScroll:!1,zoomOnScroll:!1,zoomOnPinch:!1,zoomOnDoubleClick:!1,preventScrolling:!1,proOptions:{hideAttribution:!0}})})}):null}export{C as default};