cogpit 3.5.4 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +11 -5
  2. package/dist/cli-runtime.js +3084 -2382
  3. package/dist/cli.js +1 -1
  4. package/dist/instance-worker.js +625 -276
  5. package/dist/web/assets/AgentCheckDialog-DeSKJqG3.js +1 -0
  6. package/dist/web/assets/{AutomationsPanel-DTiDsq54.js → AutomationsPanel-BWjD657g.js} +1 -1
  7. package/dist/web/assets/{CogpitBlock-Hk57z10V.js → CogpitBlock-DEl4Kxl9.js} +15 -15
  8. package/dist/web/assets/CogpitView-BYDVcso1.js +85 -0
  9. package/dist/web/assets/CommandPaletteHost-BWee2Tov.js +1 -0
  10. package/dist/web/assets/{ConfigBrowser-C77Ydij0.js → ConfigBrowser-CQOlu4Gg.js} +1 -1
  11. package/dist/web/assets/{CrewPanel-BzEJLKMd.js → CrewPanel-Dzyxoj46.js} +1 -1
  12. package/dist/web/assets/{HighlightedEditor-D1S-wotA.js → HighlightedEditor-B-bjFcyU.js} +1 -1
  13. package/dist/web/assets/KeyboardShortcutsDialog-9k4clgVv.js +1 -0
  14. package/dist/web/assets/MissionHome-CIwnHTXt.js +2 -0
  15. package/dist/web/assets/{MobileFileChanges-DovO__Ap.js → MobileFileChanges-B8RaPAmX.js} +1 -1
  16. package/dist/web/assets/OrbitControls-CcXenNM0.js +1861 -0
  17. package/dist/web/assets/{PluginsDialog-o6ySRFLf.js → PluginsDialog-CYiiMArh.js} +1 -1
  18. package/dist/web/assets/{PreviewPanel-kD79kXYD.js → PreviewPanel-CZazqeGT.js} +1 -1
  19. package/dist/web/assets/{ProjectFilesPanel-CwEqOA2q.js → ProjectFilesPanel-oFw09UPd.js} +3 -3
  20. package/dist/web/assets/{ProjectSwitcherModal-BnWbJWEX.js → ProjectSwitcherModal-Bq7zI10J.js} +1 -1
  21. package/dist/web/assets/{TerminalOutput-DsK-7nR8.js → TerminalOutput-BDmdqvpJ.js} +1 -1
  22. package/dist/web/assets/{ThemeSelectorModal-D5SBWDm5.js → ThemeSelectorModal-Crb0YaTK.js} +1 -1
  23. package/dist/web/assets/{WorkflowsPanel-NU49178V.js → WorkflowsPanel-HqdzMBXP.js} +1 -1
  24. package/dist/web/assets/WorktreePanel-DHW4Agwj.js +1 -0
  25. package/dist/web/assets/auto-render.min-BCDUXXLr.js +1 -0
  26. package/dist/web/assets/d3.min-DhuWnDrq.js +1 -0
  27. package/dist/web/assets/{edition-ui-7WkqSCbs.js → edition-ui-Cm-dw9e0.js} +1 -1
  28. package/dist/web/assets/index-BtF9zrz_.css +1 -0
  29. package/dist/web/assets/index-C3zvtMTl.js +1 -0
  30. package/dist/web/assets/{index-BgZ8qUzM.js → index-DGG5ZuyK.js} +2 -2
  31. package/dist/web/assets/{index-CevokSRq.js → index-DUeulx0e.js} +2 -2
  32. package/dist/web/assets/index-Dn2vHUyS.js +2 -0
  33. package/dist/web/assets/index-Dv2TZ38C.js +521 -0
  34. package/dist/web/assets/katex.min-C_ZjXvJu.js +1 -0
  35. package/dist/web/assets/session-parser.worker-tdry_1oJ.js +43 -0
  36. package/dist/web/assets/{switch-DI9dp0Ya.js → switch-mgfHveYR.js} +1 -1
  37. package/dist/web/assets/three.core.min-D_80lYGt.js +1 -0
  38. package/dist/web/assets/three.module.min-CXftPEfC.js +1 -0
  39. package/dist/web/assets/{vendor-ui-Dc_kJXxz.js → vendor-ui-ClPj6-Gu.js} +230 -200
  40. package/dist/web/index.html +4 -4
  41. package/package.json +1 -1
  42. package/dist/web/assets/CommandPaletteHost-BYfieK7H.js +0 -1
  43. package/dist/web/assets/KeyboardShortcutsDialog-B_DSi5JO.js +0 -1
  44. package/dist/web/assets/MissionHome-B3uYgylE.js +0 -2
  45. package/dist/web/assets/WorktreePanel-DPk5b1Os.js +0 -1
  46. package/dist/web/assets/index-Bg4A-xl7.js +0 -510
  47. package/dist/web/assets/index-C2tUYo8z.js +0 -1
  48. package/dist/web/assets/index-DIuobrPN.js +0 -2
  49. package/dist/web/assets/index-DMO9bL9w.css +0 -1
  50. package/dist/web/assets/session-parser.worker-DCsmYUeX.js +0 -41
@@ -0,0 +1 @@
1
+ import{r as a,c as Ce,j as n}from"./vendor-react-gGw_S5I_.js";import{F as et,dE as tt,Z as nt,_ as mt,dF as Qt,c as Ae,E as Ge,f as Xe,U as Je,h as Ve,i as Pe,aT as qe,B as re,x as ct,bw as Lt,au as Ke,aw as en,ax as tn,ay as nn,az as sn,bX as Bt,bY as Ft,bW as zt,dG as ut,k as He,V as ln,cB as rn,cz as an,cA as on,S as xt,dH as cn,l as Pt,D as $t,j as Ut,ac as gt,at as un,ae as pt,aC as dn,aD as Kt,aE as Ht,n as Wt,o as Yt,aa as fn,a9 as hn,a5 as mn,a2 as xn,a3 as gn,a4 as pn,a7 as wn,a6 as bn,a8 as yn,ad as jn,dI as wt,dJ as vn,db as bt,aZ as yt,dK as Sn}from"./index-Dv2TZ38C.js";import{bv as kn,T as dt,aF as Gt,u as ft,aX as Cn,a5 as ht,dI as Nn,X as Ze,cR as Xt,bz as En,bK as Tn,a6 as Dn,dJ as Rn,cs as Jt,C as An,cr as _n,bl as In,dK as On,b6 as jt,aG as Mn,dL as Ln}from"./vendor-ui-ClPj6-Gu.js";import"./vendor-markdown-BEJ8yVzA.js";const ze="/api/browser",Bn=5e3,Fn="all";function st(s,e=""){return`${ze}/sessions/${encodeURIComponent(s)}${e}`}function lt(s){return{headers:{"content-type":"application/json"},body:JSON.stringify(s)}}function rt(s,e){return s instanceof Error&&s.message?s.message:e}function zn(s){const[e,t]=a.useState(null),[l,r]=a.useState(null),i=a.useRef(!1),o=a.useRef(0),f=a.useRef(!1);a.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]);const c=a.useCallback(async()=>{const m=++o.current;f.current=!0;try{const d=await et(tt(ze)),x=d.ok?await d.json():null;if(!i.current||m!==o.current)return;x?(t(h=>JSON.stringify(h)===JSON.stringify(x)?h:x),r(null)):r(await nt(d,`Could not read the browser list (${d.status})`))}catch(d){i.current&&m===o.current&&r(rt(d,"Could not read the browser list"))}finally{m===o.current&&(f.current=!1)}},[]);a.useEffect(()=>{if(!s)return;c();const m=setInterval(()=>{f.current||c()},Bn);return()=>clearInterval(m)},[s,c]);const p=a.useCallback(async(m,d,x)=>{let h;try{h=await et(tt(m),d)}catch(N){return{ok:!1,error:rt(N,x)}}if(!h.ok)return{ok:!1,error:await nt(h,x)};const g=await mt(h);return c(),{ok:!0,data:g}},[c]),w=a.useCallback(async(m,d,x)=>{const h=await p(m,d,x);return h.ok?{ok:!0}:h},[p]),S=a.useCallback(async(m,d)=>{const x=await p(`${ze}/sessions`,{method:"POST",...lt({name:m,note:d})},`Could not create ${m}`);if(!x.ok)return x;const h=x.data;return(h==null?void 0:h.name)===m&&t(g=>g&&!g.sessions.some(N=>N.name===m)?{...g,sessions:[...g.sessions,h]}:g),{ok:!0}},[p]),b=a.useCallback(m=>w(st(m),{method:"DELETE"},`Could not delete ${m}`),[w]),v=a.useCallback(m=>w(st(m,"/stop"),{method:"POST"},`Could not stop ${m}`),[w]),y=a.useCallback((m,d)=>w(st(m),{method:"PATCH",...lt({archived:d})},`Could not ${d?"archive":"restore"} ${m}`),[w]),k=a.useCallback(async()=>{const m="Could not read where the browser skill is installed";let d;try{d=await et(tt(`${ze}/skill`))}catch(h){return{ok:!1,error:rt(h,m)}}if(!d.ok)return{ok:!1,error:await nt(d,m)};const x=await mt(d);return Array.isArray(x==null?void 0:x.targets)?{ok:!0,targets:x.targets}:{ok:!1,error:m}},[]),O=a.useCallback(async m=>{const d="Could not install the browser skill",x=await p(`${ze}/skill/install`,{method:"POST",...lt({target:m})},d);if(!x.ok)return x;const{paths:h}=x.data??{};return Array.isArray(h)&&h.every(g=>typeof g=="string")?{ok:!0,paths:h}:{ok:!1,error:d}},[p]);return{status:e,error:l,refresh:c,create:S,remove:b,stop:v,setArchived:y,readSkillTargets:k,installSkill:O}}const at=4;new TextEncoder;const Pn=new TextDecoder;function $n(s){if(s.byteLength<at)throw new Error("Frame truncated before header length");const e=new DataView(s.buffer,s.byteOffset,s.byteLength).getUint32(0),t=at+e;if(s.byteLength<t)throw new Error("Frame truncated inside header");return{header:Un(Pn.decode(s.subarray(at,t))),jpeg:s.subarray(t)}}function Un(s){let e;try{e=JSON.parse(s)}catch{throw new Error("Frame header is not valid JSON")}if(typeof e!="object"||e===null)throw new Error("Frame header is not an object");const{deviceWidth:t,deviceHeight:l,pageScaleFactor:r,offsetTop:i,scrollOffsetX:o,scrollOffsetY:f,targetId:c,ts:p}=e;if(typeof t!="number"||typeof l!="number"||typeof r!="number"||typeof i!="number"||typeof o!="number"||typeof f!="number"||typeof c!="string"||typeof p!="number")throw new Error("Frame header is missing fields");return{deviceWidth:t,deviceHeight:l,pageScaleFactor:r,offsetTop:i,scrollOffsetX:o,scrollOffsetY:f,targetId:c,ts:p}}const vt=500,Kn=5e3,St=[];function Hn(s){const e=window.location.protocol==="https:"?"wss:":"ws:",t=Qt();return`${e}//${window.location.host}${t}/__browser?session=${encodeURIComponent(s)}`}function Wn(s){try{return JSON.parse(s)}catch{return null}}function Yn(s,e){return s.state===e.state&&s.session===e.session&&s.message===e.message}function kt(s,e){return s.targetId===e.targetId&&s.url===e.url&&s.title===e.title&&s.canGoBack===e.canGoBack&&s.canGoForward===e.canGoForward}function Gn(s,e){return s.length===e.length&&s.every((t,l)=>t.targetId===e[l].targetId&&t.url===e[l].url&&t.title===e[l].title)}function it(s){s&&s.bitmap.close()}function Xn(s,e){const t=Ce.c(18),[l,r]=a.useState("idle"),[i,o]=a.useState(null),[f,c]=a.useState(null),[p,w]=a.useState(St),[S,b]=a.useState(null),[v,y]=a.useState(null),[k,O]=a.useState(null),[m,d]=a.useState(0),[x,h]=a.useState(null);let g;t[0]===Symbol.for("react.memo_cache_sentinel")?(g={page:null,generation:0},t[0]=g):g=t[0];const N=a.useRef(g),D=a.useRef(null),H=a.useRef(null),C=a.useRef(null),X=a.useRef(e);let W,T;t[1]!==e?(W=()=>{X.current=e},T=[e],t[1]=e,t[2]=W,t[3]=T):(W=t[2],T=t[3]),a.useEffect(W,T);let M,z;t[4]!==s?(M=()=>{if(o(null),c(null),N.current={page:null,generation:N.current.generation+1},d(N.current.generation),w(St),b(null),h(null),y(null),O(null),s===null){r("idle");return}const L=s,B={alive:!0,issued:0,applied:0};let P=vt;const ne=function(A,E){if(!B.alive||E<=B.applied){it(A);return}B.applied=E,H.current=A,y(A),O(Date.now())},J=function(A){let E,te;try{const se=$n(new Uint8Array(A));E=se.header,te=new Blob([se.jpeg],{type:"image/jpeg"})}catch{return}const U=B.issued=B.issued+1,{page:ae,generation:q}=N.current;createImageBitmap(te).then(se=>ne({bitmap:se,header:E,page:ae,pageGeneration:q},U),Jn)},Q=function(A){var te;const E=Wn(A);if(E)e:switch(E.type){case"status":{o(U=>U&&Yn(U,E)?U:E),h(null);break e}case"page":{const U=N.current.page,ae=!U||U.targetId!==E.targetId||U.url!==E.url;N.current={page:U&&kt(U,E)?U:E,generation:N.current.generation+(ae?1:0)},ae&&d(N.current.generation),c(q=>q&&kt(q,E)?q:E);break e}case"tabs":{w(U=>Gn(U,E.tabs)?U:E.tabs),b(E.followed);break e}case"error":{h(E.message);break e}case"clipboard":(te=X.current)==null||te.call(X,E.text)}};function $(){if(!B.alive)return;const V=D.current;if(V&&V.readyState!==WebSocket.CLOSED)return;r("connecting");const A=new WebSocket(Hn(L));A.binaryType="arraybuffer",D.current=A,A.onopen=()=>{if(!B.alive){A.close();return}P=vt,r("connected")},A.onmessage=E=>{B.alive&&(typeof E.data=="string"?Q(E.data):E.data instanceof ArrayBuffer&&J(E.data))},A.onclose=()=>{if(!B.alive)return;D.current=null,r("disconnected");const E=P;P=Math.min(P*2,Kn),C.current=setTimeout($,E)}}return $(),()=>{B.alive=!1,C.current&&(clearTimeout(C.current),C.current=null);const V=D.current;D.current=null,V&&(V.onclose=null,V.close()),it(H.current),H.current=null}},z=[s],t[4]=s,t[5]=M,t[6]=z):(M=t[5],z=t[6]),a.useEffect(M,z);let j;t[7]===Symbol.for("react.memo_cache_sentinel")?(j=L=>{const B=D.current;B&&B.readyState===WebSocket.OPEN&&B.send(JSON.stringify(L))},t[7]=j):j=t[7];const Z=j;let R;return t[8]!==x||t[9]!==S||t[10]!==v||t[11]!==k||t[12]!==f||t[13]!==m||t[14]!==i||t[15]!==l||t[16]!==p?(R={status:l,state:i,page:f,tabs:p,followed:S,frame:v,lastFrameAt:k,pageGeneration:m,error:x,send:Z},t[8]=x,t[9]=S,t[10]=v,t[11]=k,t[12]=f,t[13]=m,t[14]=i,t[15]=l,t[16]=p,t[17]=R):R=t[17],R}function Jn(){}const Vn=6e3;function qn(s){const e=Ce.c(16),{activity:t}=s,[l,r]=a.useState(!0),i=t?`${t.toolCallId}:${t.done}`:null;let o,f;if(e[0]!==i?(o=()=>{if(i===null)return;r(!0);const O=setTimeout(()=>r(!1),Vn);return()=>clearTimeout(O)},f=[i],e[0]=i,e[1]=o,e[2]=f):(o=e[1],f=e[2]),a.useEffect(o,f),!t)return null;const c=l?"opacity-100":"opacity-0";let p;e[3]!==c?(p=Ae("pointer-events-none absolute inset-x-0 bottom-0 flex justify-center px-2 pb-6 pt-8","bg-gradient-to-t from-transparent via-background/70 to-transparent","transition-opacity duration-700 motion-reduce:transition-none",c),e[3]=c,e[4]=p):p=e[4];let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx(kn,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-muted-foreground"}),e[5]=w):w=e[5];let S;e[6]!==t.command?(S=n.jsx("code",{className:"min-w-0 truncate font-mono text-[11px]",children:t.command}),e[6]=t.command,e[7]=S):S=e[7];const b=t.done?"ran":"running";let v;e[8]!==b?(v=n.jsx("span",{className:"shrink-0 text-muted-foreground",children:b}),e[8]=b,e[9]=v):v=e[9];let y;e[10]!==S||e[11]!==v?(y=n.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-full bg-popover px-3 py-1 text-xs shadow-xs",children:[w,S,v]}),e[10]=S,e[11]=v,e[12]=y):y=e[12];let k;return e[13]!==p||e[14]!==y?(k=n.jsx("div",{className:p,children:y}),e[13]=p,e[14]=y,e[15]=k):k=e[15],k}const Ct="npm i -g agent-browser && agent-browser install",Zn=1500;function Qn(s){const e=Ce.c(20),{onOpenSkill:t}=s,[l,r]=a.useState(!1),i=a.useRef(null);let o,f;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>()=>{i.current&&clearTimeout(i.current)},f=[],e[0]=o,e[1]=f):(o=e[0],f=e[1]),a.useEffect(o,f);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=async function(){await Lt(Ct)&&(r(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>r(!1),Zn))},e[2]=c):c=e[2];const p=c;let w,S;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx(Je,{variant:"icon",children:n.jsx(Gt,{})}),S=n.jsx(Ve,{children:"Nothing to show yet"}),e[3]=w,e[4]=S):(w=e[3],S=e[4]);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsxs(Xe,{children:[w,S,n.jsxs(Pe,{children:["This panel streams a real browser the agent drives. That takes the"," ",n.jsx("code",{className:"font-mono",children:"agent-browser"})," command, which is not on this machine yet."]})]}),e[5]=b):b=e[5];let v;e[6]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-xs",children:Ct}),e[6]=v):v=e[6];const y=l?"Copied":"Copy install command";let k;e[7]===Symbol.for("react.memo_cache_sentinel")?(k=()=>void p(),e[7]=k):k=e[7];let O;e[8]!==l?(O=l?n.jsx(ft,{"data-icon":"inline-start",className:"text-emerald-500"}):n.jsx(Cn,{"data-icon":"inline-start"}),e[8]=l,e[9]=O):O=e[9];let m;e[10]!==O||e[11]!==y?(m=n.jsxs("div",{className:"flex w-full items-center gap-1.5 rounded-md border bg-muted/40 py-1 pl-2.5 pr-1 text-left",children:[v,n.jsx(re,{variant:"ghost",size:"icon-xs","aria-label":y,onClick:k,children:O})]}),e[10]=O,e[11]=y,e[12]=m):m=e[12];let d;e[13]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(ht,{"data-icon":"inline-start"}),e[13]=d):d=e[13];let x;e[14]!==t?(x=n.jsxs(re,{variant:"outline",size:"sm",onClick:t,children:[d,"Install the agent skill…"]}),e[14]=t,e[15]=x):x=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Pe,{className:"text-xs",children:"The Cogpit skill teaches the agent when to use a named browser and how this panel follows along. Cogpit installs it on launch for the agent CLIs you have."}),e[16]=h):h=e[16];let g;return e[17]!==m||e[18]!==x?(g=n.jsxs(Ge,{className:"size-full",children:[b,n.jsxs(qe,{children:[m,x,h]})]}),e[17]=m,e[18]=x,e[19]=g):g=e[19],g}function es(s){const e=Ce.c(14),{name:t,lastUrl:l,onOpen:r}=s;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Je,{variant:"icon",children:n.jsx(Nn,{})}),e[0]=i):i=e[0];let o;e[1]!==t?(o=n.jsxs(Ve,{children:[t," isn’t running"]}),e[1]=t,e[2]=o):o=e[2];const f=r?"The agent opens it by itself the moment it browses. You can also open a page here and watch from the start.":"It shows up here as soon as the agent that uses it opens it again.";let c;e[3]!==f?(c=n.jsx(Pe,{children:f}),e[3]=f,e[4]=c):c=e[4];let p;e[5]!==o||e[6]!==c?(p=n.jsxs(Xe,{children:[i,o,c]}),e[5]=o,e[6]=c,e[7]=p):p=e[7];let w;e[8]!==l||e[9]!==r?(w=r&&n.jsx(qe,{children:n.jsx(Vt,{lastUrl:l,onOpen:r})}),e[8]=l,e[9]=r,e[10]=w):w=e[10];let S;return e[11]!==p||e[12]!==w?(S=n.jsxs(Ge,{className:"size-full",children:[p,w]}),e[11]=p,e[12]=w,e[13]=S):S=e[13],S}function Nt(s){const e=Ce.c(5),{onOpen:t}=s;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsxs(Xe,{children:[n.jsx(Je,{variant:"icon",children:n.jsx(Gt,{})}),n.jsx(Ve,{children:"Your agents’ browsers show up here"}),n.jsx(Pe,{children:"When an agent in one of your sessions opens a web page, you can watch it here and take over. Other sessions you can access show their browsers too."})]}),e[0]=l):l=e[0];let r;e[1]!==t?(r=t&&n.jsx(qe,{children:n.jsx(Vt,{lastUrl:null,onOpen:t})}),e[1]=t,e[2]=r):r=e[2];let i;return e[3]!==r?(i=n.jsxs(Ge,{className:"size-full",children:[l,r]}),e[3]=r,e[4]=i):i=e[4],i}function Vt(s){const e=Ce.c(14),{lastUrl:t,onOpen:l}=s,[r,i]=a.useState(null),o=r??t??"";let f;e[0]!==l||e[1]!==o?(f=function(O){O.preventDefault();const m=o.trim();m&&l(m)},e[0]=l,e[1]=o,e[2]=f):f=e[2];const c=f;let p;e[3]===Symbol.for("react.memo_cache_sentinel")?(p=k=>i(k.target.value),e[3]=p):p=e[3];let w;e[4]!==o?(w=n.jsx(Ke,{"aria-label":"Page to open",className:"h-8 text-sm",placeholder:"example.com",spellCheck:!1,autoComplete:"off",value:o,onChange:p}),e[4]=o,e[5]=w):w=e[5];let S;e[6]!==o?(S=o.trim(),e[6]=o,e[7]=S):S=e[7];const b=!S;let v;e[8]!==b?(v=n.jsx(re,{type:"submit",size:"sm",disabled:b,children:"Open"}),e[8]=b,e[9]=v):v=e[9];let y;return e[10]!==c||e[11]!==w||e[12]!==v?(y=n.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:c,children:[w,v]}),e[10]=c,e[11]=w,e[12]=v,e[13]=y):y=e[13],y}function ts({message:s,onRetry:e}){const[t,l]=a.useState(!1);async function r(){l(!0);try{await e()}finally{l(!1)}}return n.jsxs(Ge,{className:"size-full",children:[n.jsxs(Xe,{children:[n.jsx(Je,{variant:"icon",children:n.jsx(dt,{})}),n.jsx(Ve,{children:"Could not load the browsers"}),n.jsx(Pe,{children:s})]}),n.jsx(qe,{children:n.jsxs(re,{variant:"outline",size:"sm",disabled:t,onClick:()=>void r(),children:[t&&n.jsx(ct,{"data-icon":"inline-start"}),"Retry"]})})]})}function Et(s){if(s.url==="about:blank"&&(!s.title.trim()||s.title==="about:blank"))return"New tab";if(s.title.trim())return s.title.trim();try{return new URL(s.url).hostname||s.url}catch{return s.url}}const ns={live:{label:"LIVE",hint:"Streaming the page as it changes",tone:"text-emerald-600 dark:text-emerald-400",dot:"bg-emerald-500"},idle:{label:"IDLE",hint:"The page has not changed for a few seconds",tone:"text-muted-foreground",dot:"ring-1 ring-muted-foreground/50 ring-inset"},offline:{label:"OFFLINE",hint:"The connection dropped — this is the last frame that arrived",tone:"text-amber-600 dark:text-amber-400",dot:"bg-amber-500"}};function ss(s){const e=Ce.c(17),{status:t}=s,l=ns[t];let r;e[0]!==l.tone?(r=Ae("ml-1 flex shrink-0 cursor-default items-center gap-1 text-[10px] font-medium tracking-wide",l.tone),e[0]=l.tone,e[1]=r):r=e[1];let i;e[2]!==r?(i=n.jsx("span",{className:r}),e[2]=r,e[3]=i):i=e[3];let o;e[4]!==l.dot?(o=Ae("size-1.5 rounded-full",l.dot),e[4]=l.dot,e[5]=o):o=e[5];let f;e[6]!==o?(f=n.jsx("span",{"aria-hidden":"true",className:o}),e[6]=o,e[7]=f):f=e[7];let c;e[8]!==l.label||e[9]!==i||e[10]!==f?(c=n.jsxs(Bt,{render:i,children:[f,l.label]}),e[8]=l.label,e[9]=i,e[10]=f,e[11]=c):c=e[11];let p;e[12]!==l.hint?(p=n.jsx(Ft,{children:l.hint}),e[12]=l.hint,e[13]=p):p=e[13];let w;return e[14]!==c||e[15]!==p?(w=n.jsxs(zt,{children:[c,p]}),e[14]=c,e[15]=p,e[16]=w):w=e[16],w}const ls=a.memo(function(e){const t=Ce.c(56),{page:l,tabs:r,followed:i,status:o,readOnly:f,onNavigate:c,onBack:p,onForward:w,onReload:S,onAnnotate:b,onFollow:v,onCloseTab:y}=e,k=f===void 0?!1:f,[O,m]=a.useState(null),d=(l==null?void 0:l.url)??"";let x;t[0]!==O||t[1]!==d||t[2]!==c||t[3]!==k?(x=function(se){if(se.preventDefault(),k)return;const de=(O??d).trim();m(null),de&&c(de)},t[0]=O,t[1]=d,t[2]=c,t[3]=k,t[4]=x):x=t[4];const h=x;let g;t[5]===Symbol.for("react.memo_cache_sentinel")?(g=function(se){se.key==="Escape"&&(se.preventDefault(),m(null),se.currentTarget.blur())},t[5]=g):g=t[5];const N=g,D=k||!(l!=null&&l.canGoBack);let H;t[6]===Symbol.for("react.memo_cache_sentinel")?(H=n.jsx(Xt,{"data-icon":"inline-start"}),t[6]=H):H=t[6];let C;t[7]!==p||t[8]!==D?(C=n.jsx(re,{variant:"ghost",size:"icon-sm","aria-label":"Back",disabled:D,onClick:p,children:H}),t[7]=p,t[8]=D,t[9]=C):C=t[9];const X=k||!(l!=null&&l.canGoForward);let W;t[10]===Symbol.for("react.memo_cache_sentinel")?(W=n.jsx(En,{"data-icon":"inline-start"}),t[10]=W):W=t[10];let T;t[11]!==w||t[12]!==X?(T=n.jsx(re,{variant:"ghost",size:"icon-sm","aria-label":"Forward",disabled:X,onClick:w,children:W}),t[11]=w,t[12]=X,t[13]=T):T=t[13];const M=k||!l;let z;t[14]===Symbol.for("react.memo_cache_sentinel")?(z=n.jsx(Tn,{"data-icon":"inline-start"}),t[14]=z):z=t[14];let j;t[15]!==S||t[16]!==M?(j=n.jsx(re,{variant:"ghost",size:"icon-sm","aria-label":"Reload",disabled:M,onClick:S,children:z}),t[15]=S,t[16]=M,t[17]=j):j=t[17];const Z=O??d;let R;t[18]===Symbol.for("react.memo_cache_sentinel")?(R=q=>m(q.target.value),t[18]=R):R=t[18];let L;t[19]===Symbol.for("react.memo_cache_sentinel")?(L=()=>m(null),t[19]=L):L=t[19];let B;t[20]!==k||t[21]!==Z?(B=n.jsx(en,{"aria-label":"Page URL",className:"text-xs",placeholder:"Enter a URL",spellCheck:!1,autoComplete:"off",readOnly:k,value:Z,onChange:R,onFocus:rs,onBlur:L,onKeyDown:N}),t[20]=k,t[21]=Z,t[22]=B):B=t[22];const P=!d;let ne;t[23]!==d?(ne=()=>window.open(d,"_blank","noopener,noreferrer"),t[23]=d,t[24]=ne):ne=t[24];let J;t[25]===Symbol.for("react.memo_cache_sentinel")?(J=n.jsx(Dn,{"data-icon":"inline-start"}),t[25]=J):J=t[25];let Q;t[26]!==P||t[27]!==ne?(Q=n.jsx(tn,{align:"inline-end",children:n.jsx(nn,{size:"icon-xs","aria-label":"Open in your browser",disabled:P,onClick:ne,children:J})}),t[26]=P,t[27]=ne,t[28]=Q):Q=t[28];let $;t[29]!==B||t[30]!==Q?($=n.jsxs(sn,{className:"h-7",children:[B,Q]}),t[29]=B,t[30]=Q,t[31]=$):$=t[31];let V;t[32]!==h||t[33]!==$?(V=n.jsx("form",{className:"ml-1 min-w-0 flex-1",onSubmit:h,children:$}),t[32]=h,t[33]=$,t[34]=V):V=t[34];let A;t[35]!==b||t[36]!==l?(A=b&&n.jsx(re,{variant:"ghost",size:"icon-sm","aria-label":"Annotate this frame for the message",title:"Annotate for the message",disabled:!l,onClick:b,children:n.jsx(Rn,{"data-icon":"inline-start"})}),t[35]=b,t[36]=l,t[37]=A):A=t[37];let E;t[38]!==o?(E=o&&n.jsx(ss,{status:o}),t[38]=o,t[39]=E):E=t[39];let te;t[40]!==j||t[41]!==V||t[42]!==A||t[43]!==E||t[44]!==C||t[45]!==T?(te=n.jsxs("div",{className:"flex items-center gap-0.5",children:[C,T,j,V,A,E]}),t[40]=j,t[41]=V,t[42]=A,t[43]=E,t[44]=C,t[45]=T,t[46]=te):te=t[46];let U;t[47]!==i||t[48]!==y||t[49]!==v||t[50]!==k||t[51]!==r?(U=r.length>0&&n.jsx("div",{className:"flex items-center gap-1 overflow-x-auto pb-0.5",children:r.map(q=>n.jsxs("div",{className:Ae("flex max-w-48 shrink-0 items-center rounded-md",q.targetId===i&&"bg-secondary"),children:[n.jsx(re,{size:"xs",variant:"ghost",className:Ae("min-w-0 shrink",!k&&"rounded-r-none"),"aria-current":q.targetId===i?"page":void 0,title:q.title||q.url,onClick:()=>v(q.targetId),onMouseDown:as,onAuxClick:se=>{se.button!==1||k||(se.preventDefault(),y(q.targetId))},children:n.jsx("span",{className:"truncate",children:Et(q)})}),!k&&n.jsx(re,{size:"icon-xs",variant:"ghost",className:"rounded-l-none","aria-label":`Close tab: ${Et(q)}`,title:"Close tab",onClick:()=>y(q.targetId),children:n.jsx(Ze,{"data-icon":"inline-start"})})]},q.targetId))}),t[47]=i,t[48]=y,t[49]=v,t[50]=k,t[51]=r,t[52]=U):U=t[52];let ae;return t[53]!==te||t[54]!==U?(ae=n.jsxs("div",{className:"flex shrink-0 flex-col gap-1 border-b px-2 py-1.5",children:[te,U]}),t[53]=te,t[54]=U,t[55]=ae):ae=t[55],ae});function rs(s){return s.target.select()}function as(s){s.button===1&&s.preventDefault()}function is(s){var e;return((e=s.find(t=>t.mine))==null?void 0:e.name)??ut}function We(s){return(s==null?void 0:s.control)??"own"}function os(s){return We(s)!=="watch"}function Ye(s,e){return s!=null&&s.mine?"Your browser":s!=null&&s.account?`${s.account}'s browser`:e}function cs(s,e,t){if(s!==ut||t===null)return s;const l=e.find(r=>(r.mine||r.account)&&r.driverSessionId===t);return(l==null?void 0:l.name)??s}function us(s){if(!s||!Number.isFinite(Date.parse(s)))return null;if(Date.now()-Date.parse(s)>=10080*60*1e3)return new Date(s).toLocaleDateString();const e=ln(s);return e==="now"?"just now":`${e} ago`}function qt(s){const e=Ce.c(4),{running:t}=s,l=t?"bg-emerald-500":"ring-1 ring-muted-foreground/50 ring-inset";let r;e[0]!==l?(r=Ae("size-2 shrink-0 rounded-full",l),e[0]=l,e[1]=r):r=e[1];let i;return e[2]!==r?(i=n.jsx("span",{"aria-hidden":!0,className:r}),e[2]=r,e[3]=i):i=e[3],i}function ds(s){const e=Ce.c(89),{sessions:t,selected:l,home:r,currentSessionId:i,busy:o,onSelect:f,onSetArchived:c,children:p}=s,[w,S]=a.useState(!1),[b,v]=a.useState(""),[y,k]=a.useState(!1),O=a.useRef(null);let m,d,x,h,g,N,D,H,C,X,W,T,M,z,j,Z,R;if(e[0]!==o||e[1]!==i||e[2]!==r||e[3]!==f||e[4]!==c||e[5]!==w||e[6]!==b||e[7]!==l||e[8]!==t||e[9]!==y){let E;e[27]!==l?(E=F=>F.name===l,e[27]=l,e[28]=E):E=e[28];const te=t.find(E),U=b.trim().toLowerCase();let ae;e[29]!==r||e[30]!==l?(ae=F=>!!F.archived&&!F.isDefault&&F.name!==r&&!F.running&&F.name!==l,e[29]=r,e[30]=l,e[31]=ae):ae=e[31];const q=ae,se=F=>`${F.name} ${Ye(F,F.name)} ${F.note??""}`.toLowerCase().includes(U);let de;e[32]!==r?(de=(F,oe)=>+(oe.name===r)-+(F.name===r)||Number(oe.isDefault)-Number(F.isDefault)||Number(oe.running)-Number(F.running),e[32]=r,e[33]=de):de=e[33];const ve=t.filter(F=>!q(F)&&se(F)).sort(de);x=t.filter(q);const ge=x.filter(se);R=y&&!U?[]:ve,Z=y||U?ge:[];let he;e[34]===Symbol.for("react.memo_cache_sentinel")?(he=function(){S(!1)},e[34]=he):he=e[34],h=he;const pe=async function(oe){oe.archived&&!(await c(oe.name,!1)).ok||(f(oe.name),h())},be=async function(oe){var ke;(await c(oe,!0)).ok&&((ke=O.current)==null||ke.focus())};d=rn,j=w,e[35]===Symbol.for("react.memo_cache_sentinel")?(N=F=>{S(F),F&&(v(""),k(!1))},e[35]=N):N=e[35];let fe;e[36]===Symbol.for("react.memo_cache_sentinel")?(fe=n.jsx(re,{variant:"ghost",size:"xs","aria-label":"Switch browser",className:"max-w-40"}),e[36]=fe):fe=e[36];const le=n.jsx(qt,{running:(te==null?void 0:te.running)??!1}),K=Ye(te,l);let Y;e[37]!==K?(Y=n.jsx("span",{className:"truncate",children:K}),e[37]=K,e[38]=Y):Y=e[38];let ce;e[39]===Symbol.for("react.memo_cache_sentinel")?(ce=n.jsx(An,{"data-icon":"inline-end",className:"opacity-60"}),e[39]=ce):ce=e[39],e[40]!==le||e[41]!==Y?(D=n.jsxs(an,{render:fe,children:[le,Y,ce]}),e[40]=le,e[41]=Y,e[42]=D):D=e[42],m=on,X="Browsers",W=O,T="flex max-h-[min(32rem,var(--available-height))] w-80 max-w-[calc(100vw-1rem)] flex-col overflow-hidden";const Se=y&&!U?"Archived browsers":"Browsers";let we;e[43]!==Se?(we=n.jsx("span",{className:"text-sm font-medium",children:Se}),e[43]=Se,e[44]=we):we=e[44];let ye;e[45]===Symbol.for("react.memo_cache_sentinel")?(ye=n.jsx(re,{variant:"ghost",size:"icon-xs","aria-label":"Close browser picker",onClick:h,children:n.jsx(Ze,{"data-icon":"inline-start"})}),e[45]=ye):ye=e[45];let me;e[46]!==we?(me=n.jsxs("div",{className:"flex items-center justify-between pl-1",children:[we,ye]}),e[46]=we,e[47]=me):me=e[47];let je;e[48]===Symbol.for("react.memo_cache_sentinel")?(je=F=>v(F.target.value),e[48]=je):je=e[48];let ie;e[49]!==b?(ie=n.jsx(Ke,{ref:O,"aria-label":"Search browsers",placeholder:"Search browsers…",value:b,onChange:je}),e[49]=b,e[50]=ie):ie=e[50],e[51]!==me||e[52]!==ie?(M=n.jsxs("div",{className:"flex shrink-0 flex-col gap-2 p-2",children:[me,ie]}),e[51]=me,e[52]=ie,e[53]=M):M=e[53],e[54]===Symbol.for("react.memo_cache_sentinel")?(z=n.jsx(xt,{}),e[54]=z):z=e[54],g="min-h-0 max-h-72 overflow-y-auto overscroll-contain p-1",H="Browser list",C=[{label:"Recent browsers",sessions:R,archived:!1},{label:"Archived browsers",sessions:Z,archived:!0}].filter(fs).map(F=>n.jsxs("div",{children:[F.archived&&!!U&&n.jsx("p",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Archived"}),n.jsx("ul",{"aria-label":F.label,children:F.sessions.map(oe=>n.jsx(hs,{session:oe,archived:F.archived,home:r,selected:l,currentSessionId:i,busy:o,onPick:pe,onArchive:be},oe.name))})]},F.label)),e[0]=o,e[1]=i,e[2]=r,e[3]=f,e[4]=c,e[5]=w,e[6]=b,e[7]=l,e[8]=t,e[9]=y,e[10]=m,e[11]=d,e[12]=x,e[13]=h,e[14]=g,e[15]=N,e[16]=D,e[17]=H,e[18]=C,e[19]=X,e[20]=W,e[21]=T,e[22]=M,e[23]=z,e[24]=j,e[25]=Z,e[26]=R}else m=e[10],d=e[11],x=e[12],h=e[13],g=e[14],N=e[15],D=e[16],H=e[17],C=e[18],X=e[19],W=e[20],T=e[21],M=e[22],z=e[23],j=e[24],Z=e[25],R=e[26];let L;e[55]!==Z||e[56]!==R.length?(L=R.length===0&&Z.length===0&&n.jsx("p",{role:"status",className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"No browsers found."}),e[55]=Z,e[56]=R.length,e[57]=L):L=e[57];let B;e[58]!==g||e[59]!==L||e[60]!==H||e[61]!==C?(B=n.jsxs("div",{className:g,"aria-label":H,children:[C,L]}),e[58]=g,e[59]=L,e[60]=H,e[61]=C,e[62]=B):B=e[62];let P;e[63]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsx(xt,{}),e[63]=P):P=e[63];let ne;e[64]!==x.length||e[65]!==y?(ne=(x.length>0||y)&&n.jsxs(re,{variant:"ghost",size:"sm",className:"w-full justify-start","aria-expanded":y,onClick:()=>{k(!y),v("")},children:[y?n.jsx(Xt,{"data-icon":"inline-start"}):n.jsx(Jt,{"data-icon":"inline-start"}),y?"Back to recent":"Archived",!y&&n.jsx(He,{variant:"secondary",children:x.length})]}),e[64]=x.length,e[65]=y,e[66]=ne):ne=e[66];let J;e[67]===Symbol.for("react.memo_cache_sentinel")?(J=n.jsx("p",{className:"px-1 pb-1 text-xs text-muted-foreground",children:"Stopped browsers archive after 24h of inactivity. Saved logins are kept."}),e[67]=J):J=e[67];let Q;e[68]!==p||e[69]!==h?(Q=p(h),e[68]=p,e[69]=h,e[70]=Q):Q=e[70];let $;e[71]!==ne||e[72]!==Q?($=n.jsxs("div",{className:"flex shrink-0 flex-col gap-1 p-2",children:[ne,J,Q]}),e[71]=ne,e[72]=Q,e[73]=$):$=e[73];let V;e[74]!==m||e[75]!==B||e[76]!==$||e[77]!==X||e[78]!==W||e[79]!==T||e[80]!==M||e[81]!==z?(V=n.jsxs(m,{"aria-label":X,initialFocus:W,className:T,children:[M,z,B,P,$]}),e[74]=m,e[75]=B,e[76]=$,e[77]=X,e[78]=W,e[79]=T,e[80]=M,e[81]=z,e[82]=V):V=e[82];let A;return e[83]!==d||e[84]!==N||e[85]!==D||e[86]!==V||e[87]!==j?(A=n.jsxs(d,{open:j,onOpenChange:N,children:[D,V]}),e[83]=d,e[84]=N,e[85]=D,e[86]=V,e[87]=j,e[88]=A):A=e[88],A}function fs(s){return s.sessions.length>0}function hs(s){const e=Ce.c(53),{session:t,archived:l,home:r,selected:i,currentSessionId:o,busy:f,onPick:c,onArchive:p}=s;let w;e[0]!==t.lastUsedAt?(w=us(t.lastUsedAt),e[0]=t.lastUsedAt,e[1]=w):w=e[1];const S=w;let b;e[2]!==t?(b=Ye(t,t.name),e[2]=t,e[3]=b):b=e[3];const v=b,y=t.running&&t.driverSessionId!==null&&t.driverSessionId!==o,k=t.isDefault?r===t.name?"Default":"Host default":null,O=`${l?"Restore and switch to":"Switch to"} ${v}`,m=t.name===i?"true":void 0;let d;e[4]!==c||e[5]!==t?(d=()=>void c(t),e[4]=c,e[5]=t,e[6]=d):d=e[6];let x;e[7]!==t.running?(x=n.jsx(qt,{running:t.running}),e[7]=t.running,e[8]=x):x=e[8];let h;e[9]!==v?(h=n.jsx("span",{className:"truncate",children:v}),e[9]=v,e[10]=h):h=e[10];const g=t.running?"running":"stopped";let N;e[11]!==g?(N=n.jsx("span",{className:"sr-only",children:g}),e[11]=g,e[12]=N):N=e[12];let D;e[13]!==k?(D=k&&n.jsx(He,{variant:"secondary",children:k}),e[13]=k,e[14]=D):D=e[14];let H;e[15]!==t?(H=We(t)==="watch"&&n.jsx(He,{variant:"outline",children:"View only"}),e[15]=t,e[16]=H):H=e[16];let C;e[17]!==S?(C=S&&n.jsx("span",{className:"ml-auto shrink-0 text-xs font-normal text-muted-foreground",children:S}),e[17]=S,e[18]=C):C=e[18];let X;e[19]!==D||e[20]!==H||e[21]!==C||e[22]!==h||e[23]!==N?(X=n.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[h,N,D,H,C]}),e[19]=D,e[20]=H,e[21]=C,e[22]=h,e[23]=N,e[24]=X):X=e[24];let W;e[25]!==y?(W=y&&n.jsx("span",{className:"max-w-full truncate text-xs font-normal text-muted-foreground",children:"driven by another session"}),e[25]=y,e[26]=W):W=e[26];let T;e[27]!==X||e[28]!==W?(T=n.jsxs("span",{className:"flex min-w-0 flex-1 flex-col items-start gap-0.5",children:[X,W]}),e[27]=X,e[28]=W,e[29]=T):T=e[29];let M;e[30]!==i||e[31]!==t.name?(M=t.name===i&&n.jsx(ft,{"data-icon":"inline-end"}),e[30]=i,e[31]=t.name,e[32]=M):M=e[32];let z;e[33]!==l?(z=l&&n.jsx(_n,{"data-icon":"inline-end"}),e[33]=l,e[34]=z):z=e[34];let j;e[35]!==f||e[36]!==T||e[37]!==M||e[38]!==z||e[39]!==O||e[40]!==m||e[41]!==d||e[42]!==x?(j=n.jsxs(re,{variant:"ghost",className:"h-auto min-h-10 min-w-0 flex-1 justify-start px-2 py-2","aria-label":O,"aria-current":m,disabled:f,onClick:d,children:[x,T,M,z]}),e[35]=f,e[36]=T,e[37]=M,e[38]=z,e[39]=O,e[40]=m,e[41]=d,e[42]=x,e[43]=j):j=e[43];let Z;e[44]!==l||e[45]!==f||e[46]!==r||e[47]!==p||e[48]!==t?(Z=!l&&!t.isDefault&&t.name!==r&&!t.running&&We(t)==="own"&&n.jsx(re,{variant:"ghost",size:"icon-sm","aria-label":`Archive ${t.name}`,title:`Archive ${t.name}`,disabled:f,onClick:()=>void p(t.name),children:n.jsx(Jt,{"data-icon":"inline-start"})}),e[44]=l,e[45]=f,e[46]=r,e[47]=p,e[48]=t,e[49]=Z):Z=e[49];let R;return e[50]!==j||e[51]!==Z?(R=n.jsxs("li",{className:"group flex items-center gap-1 rounded-md",children:[j,Z]}),e[50]=j,e[51]=Z,e[52]=R):R=e[52],R}const ms=/^[a-z0-9][a-z0-9_-]{0,39}$/,xs="Lowercase letters, numbers, - and _, starting with a letter or number (40 max).",gs=a.memo(function(e){const t=Ce.c(112),{sessions:l,selected:r,home:i,currentSessionId:o,followAgent:f,busy:c,onSelect:p,onToggleFollow:w,onOpenSkill:S,onCreate:b,onRemove:v,onStop:y,onSetArchived:k,onShowDefault:O,onClose:m}=e,d=c===void 0?!1:c,x=a.useId(),h=a.useId(),[g,N]=a.useState(!1),[D,H]=a.useState(""),[C,X]=a.useState(""),[W,T]=a.useState(null),[M,z]=a.useState(!1),[j,Z]=a.useState(null),R=r===i;let L,B;t[0]!==r||t[1]!==l?(L=l.find(xe=>xe.name===r)??null,B=We(L),t[0]=r,t[1]=l,t[2]=L,t[3]=B):(L=t[2],B=t[3]);const P=B;let ne;if(t[4]!==i||t[5]!==l){let xe;t[7]!==i?(xe=Fe=>Fe.mine&&Fe.name===i,t[7]=i,t[8]=xe):xe=t[8],ne=l.some(xe),t[4]=i,t[5]=l,t[6]=ne}else ne=t[6];const J=ne,Q=!R&&!(L!=null&&L.isDefault)&&P!=="watch",$=!R&&!(L!=null&&L.isDefault)&&P==="own";let V,A;t[9]!==D?(A=D.trim(),V=A.length>0&&!ms.test(A),t[9]=D,t[10]=V,t[11]=A):(V=t[10],A=t[11]);const E=V,te=E?xs:W,U=A.length>0&&!E&&!M;let ae;t[12]===Symbol.for("react.memo_cache_sentinel")?(ae=function(){H(""),X(""),T(null),z(!1),N(!0)},t[12]=ae):ae=t[12];const q=ae;let se;t[13]!==U||t[14]!==C||t[15]!==b||t[16]!==p||t[17]!==A?(se=async function(){if(!U)return;z(!0);const Fe=await b(A,C.trim());if(z(!1),!Fe.ok){T(Fe.error);return}N(!1),p(A)},t[13]=U,t[14]=C,t[15]=b,t[16]=p,t[17]=A,t[18]=se):se=t[18];const de=se,ve=!R&&"border-amber-500/40 bg-amber-500/10";let ge;t[19]!==ve?(ge=Ae("@container/browser-bar flex h-10 shrink-0 items-center gap-2 border-b px-2",ve),t[19]=ve,t[20]=ge):ge=t[20];let he;t[21]!==d||t[22]!==$||t[23]!==Q||t[24]!==S||t[25]!==y||t[26]!==r||t[27]!==(L==null?void 0:L.running)?(he=xe=>n.jsxs(n.Fragment,{children:[n.jsxs(re,{variant:"outline",size:"sm",disabled:d,onClick:()=>{xe(),q()},children:[n.jsx(In,{"data-icon":"inline-start"}),"New browser…"]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(re,{variant:"ghost",size:"xs",onClick:()=>{xe(),S()},children:[n.jsx(ht,{"data-icon":"inline-start"}),"Agent skill…"]}),Q&&n.jsxs(re,{variant:"ghost",size:"xs",disabled:d||!(L!=null&&L.running),onClick:()=>{xe(),y(r)},children:[n.jsx(On,{"data-icon":"inline-start"}),"Stop"]}),$&&n.jsxs(re,{variant:"ghost",size:"xs",disabled:d,onClick:()=>{xe(),Z(r)},children:[n.jsx(jt,{"data-icon":"inline-start"}),"Delete…"]})]})]}),t[21]=d,t[22]=$,t[23]=Q,t[24]=S,t[25]=y,t[26]=r,t[27]=L==null?void 0:L.running,t[28]=he):he=t[28];let pe;t[29]!==d||t[30]!==o||t[31]!==i||t[32]!==p||t[33]!==k||t[34]!==r||t[35]!==l||t[36]!==he?(pe=n.jsx(ds,{sessions:l,selected:r,home:i,currentSessionId:o,busy:d,onSelect:p,onSetArchived:k,children:he}),t[29]=d,t[30]=o,t[31]=i,t[32]=p,t[33]=k,t[34]=r,t[35]=l,t[36]=he,t[37]=pe):pe=t[37];let be;t[38]===Symbol.for("react.memo_cache_sentinel")?(be=n.jsx("span",{className:"flex-1"}),t[38]=be):be=t[38];let fe;t[39]!==P?(fe=P==="watch"&&n.jsxs(He,{variant:"outline",title:"Only someone who can interact with the session driving it can use it",children:[n.jsx(Mn,{"data-icon":"inline-start"}),"View only"]}),t[39]=P,t[40]=fe):fe=t[40];let le;t[41]!==J||t[42]!==R||t[43]!==O?(le=!R&&n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsxs("span",{role:"status",className:"flex min-w-0 items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-300",children:[n.jsx(dt,{"aria-hidden":!0,className:"size-3.5 shrink-0"}),n.jsx("span",{className:"sr-only @sm/browser-bar:not-sr-only @sm/browser-bar:whitespace-nowrap",children:J?"Not your browser":"Not the default browser"})]}),n.jsx(re,{variant:"outline",size:"xs",onClick:O,children:J?"Show yours":"Show default"})]}),t[41]=J,t[42]=R,t[43]=O,t[44]=le):le=t[44];let K;t[45]!==w?(K=xe=>w(xe),t[45]=w,t[46]=K):K=t[46];let Y;t[47]!==f||t[48]!==K?(Y=n.jsx(cn,{size:"sm","aria-label":"Follow agent",pressed:f,onPressedChange:K,className:"text-muted-foreground data-pressed:text-foreground"}),t[47]=f,t[48]=K,t[49]=Y):Y=t[49];let ce,Se;t[50]===Symbol.for("react.memo_cache_sentinel")?(ce=n.jsx(Ln,{"data-icon":"inline-start"}),Se=n.jsx("span",{className:"hidden @md/browser-bar:inline",children:"Follow"}),t[50]=ce,t[51]=Se):(ce=t[50],Se=t[51]);let we;t[52]!==Y?(we=n.jsxs(Bt,{render:Y,children:[ce,Se]}),t[52]=Y,t[53]=we):we=t[53];let ye;t[54]===Symbol.for("react.memo_cache_sentinel")?(ye=n.jsx(Ft,{children:"Switch to whichever browser this session’s agent uses"}),t[54]=ye):ye=t[54];let me;t[55]!==we?(me=n.jsxs(zt,{children:[we,ye]}),t[55]=we,t[56]=me):me=t[56];let je;t[57]===Symbol.for("react.memo_cache_sentinel")?(je=n.jsx(Ze,{"data-icon":"inline-start"}),t[57]=je):je=t[57];let ie;t[58]!==m?(ie=n.jsx(re,{variant:"ghost",size:"icon-sm","aria-label":"Close browser panel",onClick:m,children:je}),t[58]=m,t[59]=ie):ie=t[59];let F;t[60]!==de?(F=xe=>{xe.preventDefault(),de()},t[60]=de,t[61]=F):F=t[61];let oe;t[62]===Symbol.for("react.memo_cache_sentinel")?(oe=n.jsxs(Pt,{children:[n.jsx($t,{children:"New browser"}),n.jsx(Ut,{children:"A named browser keeps its own cookies and logins, and stays out of the default one."})]}),t[62]=oe):oe=t[62];const Ee=!!te;let ke;t[63]!==x?(ke=n.jsx(gt,{htmlFor:x,children:"Name"}),t[63]=x,t[64]=ke):ke=t[64];const Te=!!te;let G;t[65]===Symbol.for("react.memo_cache_sentinel")?(G=xe=>{H(xe.target.value),T(null)},t[65]=G):G=t[65];let u;t[66]!==x||t[67]!==D||t[68]!==Te?(u=n.jsx(Ke,{id:x,autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"shop","aria-invalid":Te,value:D,onChange:G}),t[66]=x,t[67]=D,t[68]=Te,t[69]=u):u=t[69];let _;t[70]!==te?(_=n.jsx(un,{children:te}),t[70]=te,t[71]=_):_=t[71];let ee;t[72]!==Ee||t[73]!==ke||t[74]!==u||t[75]!==_?(ee=n.jsxs(pt,{"data-invalid":Ee,children:[ke,u,_]}),t[72]=Ee,t[73]=ke,t[74]=u,t[75]=_,t[76]=ee):ee=t[76];let I;t[77]===Symbol.for("react.memo_cache_sentinel")?(I=n.jsx("span",{className:"text-muted-foreground/60",children:"(optional)"}),t[77]=I):I=t[77];let ue;t[78]!==h?(ue=n.jsxs(gt,{htmlFor:h,children:["Note ",I]}),t[78]=h,t[79]=ue):ue=t[79];let Ne;t[80]===Symbol.for("react.memo_cache_sentinel")?(Ne=xe=>X(xe.target.value),t[80]=Ne):Ne=t[80];let De;t[81]!==C||t[82]!==h?(De=n.jsx(Ke,{id:h,autoComplete:"off",placeholder:"What this browser is signed in to",value:C,onChange:Ne}),t[81]=C,t[82]=h,t[83]=De):De=t[83];let Re;t[84]!==ue||t[85]!==De?(Re=n.jsxs(pt,{children:[ue,De]}),t[84]=ue,t[85]=De,t[86]=Re):Re=t[86];let Ie;t[87]!==ee||t[88]!==Re?(Ie=n.jsxs(dn,{className:"gap-4",children:[ee,Re]}),t[87]=ee,t[88]=Re,t[89]=Ie):Ie=t[89];let $e;t[90]===Symbol.for("react.memo_cache_sentinel")?($e=n.jsx(Kt,{render:n.jsx(re,{type:"button",variant:"outline"}),children:"Cancel"}),t[90]=$e):$e=t[90];const Qe=!U;let Oe;t[91]!==Qe?(Oe=n.jsxs(Ht,{children:[$e,n.jsx(re,{type:"submit",disabled:Qe,children:"Create browser"})]}),t[91]=Qe,t[92]=Oe):Oe=t[92];let Me;t[93]!==F||t[94]!==Ie||t[95]!==Oe?(Me=n.jsx(Wt,{className:"sm:max-w-sm",children:n.jsxs("form",{className:"flex flex-col gap-4",onSubmit:F,children:[oe,Ie,Oe]})}),t[93]=F,t[94]=Ie,t[95]=Oe,t[96]=Me):Me=t[96];let Le;t[97]!==g||t[98]!==Me?(Le=n.jsx(Yt,{open:g,onOpenChange:N,children:Me}),t[97]=g,t[98]=Me,t[99]=Le):Le=t[99];let Be;t[100]!==j||t[101]!==v?(Be=j!==null&&n.jsx(fn,{open:!0,onOpenChange:xe=>{xe||Z(null)},children:n.jsxs(hn,{size:"sm",children:[n.jsxs(mn,{children:[n.jsx(xn,{className:"bg-destructive/10 text-destructive",children:n.jsx(jt,{})}),n.jsxs(gn,{children:["Delete ",j,"?"]}),n.jsx(pn,{children:"Its profile goes with it, so everything signed in there is signed out. Other browsers are untouched."})]}),n.jsxs(wn,{children:[n.jsx(bn,{size:"sm",children:"Cancel"}),n.jsx(yn,{variant:"destructive",size:"sm",onClick:()=>{v(j),Z(null)},children:"Delete browser"})]})]})}),t[100]=j,t[101]=v,t[102]=Be):Be=t[102];let Ue;return t[103]!==pe||t[104]!==fe||t[105]!==le||t[106]!==me||t[107]!==ie||t[108]!==Le||t[109]!==Be||t[110]!==ge?(Ue=n.jsxs("div",{className:ge,children:[pe,be,fe,le,me,ie,Le,Be]}),t[103]=pe,t[104]=fe,t[105]=le,t[106]=me,t[107]=ie,t[108]=Le,t[109]=Be,t[110]=ge,t[111]=Ue):Ue=t[111],Ue});function ps(s){const e=Ce.c(35),{open:t,onOpenChange:l,readTargets:r,install:i}=s,[o,f]=a.useState(null),[c,p]=a.useState(null),[w,S]=a.useState(null);let b;e[0]!==r?(b=async()=>{const j=await r();j.ok?(f(j.targets),p(null)):p(j.error)},e[0]=r,e[1]=b):b=e[1];const v=b;let y,k;e[2]!==v||e[3]!==t?(y=()=>{t&&(p(null),v())},k=[t,v],e[2]=v,e[3]=t,e[4]=y,e[5]=k):(y=e[4],k=e[5]),a.useEffect(y,k);let O;e[6]!==i||e[7]!==v?(O=async function(Z){S(Z);const R=await i(Z);S(null),R.ok?await v():p(R.error)},e[6]=i,e[7]=v,e[8]=O):O=e[8];const m=O;let d;e[9]!==o?(d=(o==null?void 0:o.some(ws))??!1,e[9]=o,e[10]=d):d=e[10];const x=d;let h;e[11]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsxs(Pt,{children:[n.jsx($t,{children:"Agent skill"}),n.jsx(Ut,{children:"The Cogpit skill teaches an agent how Cogpit works, including when to use a named browser or a throwaway one and that this panel is watching. Cogpit refreshes it on launch for every agent CLI you have. Installing here writes it into that CLI’s configuration directory in your home folder."})]}),e[11]=h):h=e[11];let g;e[12]!==c?(g=c&&n.jsx("p",{role:"alert",className:"text-sm text-destructive",children:c}),e[12]=c,e[13]=g):g=e[13];let N;e[14]!==w||e[15]!==m||e[16]!==o?(N=o===null?n.jsxs("div",{role:"status",className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[n.jsx(ct,{}),"Reading where it is installed…"]}):n.jsx("ul",{className:"flex flex-col gap-2",children:o.map(j=>n.jsxs("li",{className:"flex items-center gap-3 rounded-md border p-2.5",children:[n.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[n.jsx("span",{className:"truncate text-sm font-medium",children:j.label}),n.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:j.configRoot}),j.automatic&&n.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"Refreshed automatically on launch"})]}),j.installed?n.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[n.jsx(ft,{"aria-hidden":!0,className:"size-3.5 text-emerald-500"}),"Installed"]}):n.jsx(re,{size:"xs",variant:"outline","aria-label":`Install for ${j.label}`,disabled:w!==null,onClick:()=>void m(j.kind),children:"Install"})]},j.kind))}),e[14]=w,e[15]=m,e[16]=o,e[17]=N):N=e[17];const D=!x||w!==null;let H;e[18]!==m?(H=()=>void m(Fn),e[18]=m,e[19]=H):H=e[19];let C;e[20]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(ht,{"data-icon":"inline-start"}),e[20]=C):C=e[20];let X;e[21]!==H||e[22]!==D?(X=n.jsxs(re,{variant:"outline",disabled:D,onClick:H,children:[C,"Install for all"]}),e[21]=H,e[22]=D,e[23]=X):X=e[23];let W;e[24]===Symbol.for("react.memo_cache_sentinel")?(W=n.jsx(Kt,{render:n.jsx(re,{type:"button"}),children:"Done"}),e[24]=W):W=e[24];let T;e[25]!==X?(T=n.jsxs(Ht,{children:[X,W]}),e[25]=X,e[26]=T):T=e[26];let M;e[27]!==T||e[28]!==g||e[29]!==N?(M=n.jsxs(Wt,{className:"sm:max-w-md",children:[h,g,N,T]}),e[27]=T,e[28]=g,e[29]=N,e[30]=M):M=e[30];let z;return e[31]!==l||e[32]!==t||e[33]!==M?(z=n.jsx(Yt,{open:t,onOpenChange:l,children:M}),e[31]=l,e[32]=t,e[33]=M,e[34]=z):z=e[34],z}function ws(s){return!s.installed}const bs={x:0,y:0,width:0,height:0,scale:0};function Zt(s,e){if(s.width<=0||s.height<=0||e.width<=0||e.height<=0)return bs;const t=Math.min(1,s.width/e.width,s.height/e.height),l=e.width*t,r=e.height*t;return{x:Math.round((s.width-l)/2),y:Math.round((s.height-r)/2),width:l,height:r,scale:t}}function ot(s,e,t,l,r={}){if(l.scale<=0||l.width<=0||l.height<=0)return null;const i=s-t.left-l.x,o=e-t.top-l.y;return!(i>=0&&o>=0&&i<=l.width&&o<=l.height)&&!r.clamp?null:{x:Tt(i/l.scale,l.width/l.scale),y:Tt(o/l.scale,l.height/l.scale)}}function Tt(s,e){return Math.min(Math.max(s,0),e)}const ys=1,js=2,vs=4,Ss=8;function _e(s){return(s.altKey?ys:0)|(s.ctrlKey?js:0)|(s.metaKey?vs:0)|(s.shiftKey?Ss:0)}const ks=["left","middle","right"];function Dt(s){return ks[s]??"left"}const Cs=150,Rt=2,Ns=500,At=5,Es=1,Ts=2,Ds=16,Rs="Keyboard captured · Esc to release",As=new Set(["F5","F11","F12"]),_s=new Set(["i","j","c"]);function _t(s){return As.has(s.key)||s.metaKey?!0:s.ctrlKey&&s.shiftKey&&_s.has(s.key.toLowerCase())}function Is(s){if(!(s.ctrlKey||s.metaKey))return s.key.length===1?s.key:s.key==="Enter"?"\r":void 0}function It(s,e,t){return e===Es?s*Ds:e===Ts?s*t:s}function Os(s,e,t){try{s.drawImage(e,t.x,t.y,t.width,t.height)}catch{}}function Ms(s){const e=Ce.c(82),{frame:t,send:l,onSizeChange:r,readOnly:i,className:o}=s,f=i===void 0?!1:i,c=a.useRef(null),p=a.useRef(null),w=a.useRef(null),S=a.useRef(null),b=a.useRef(!1);let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v={count:0,at:0,x:0,y:0,button:-1},e[0]=v):v=e[0];const y=a.useRef(v);let k;e[1]===Symbol.for("react.memo_cache_sentinel")?(k=new Map,e[1]=k):k=e[1];const O=a.useRef(k);let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m={width:0,height:0,dpr:1},e[2]=m):m=e[2];const[d,x]=a.useState(m),[h,g]=a.useState(!1),N=t?t.header.deviceWidth:0,D=t?t.header.deviceHeight:0;let H;e[3]!==D||e[4]!==N||e[5]!==d?(H=Zt(d,{width:N,height:D}),e[3]=D,e[4]=N,e[5]=d,e[6]=H):H=e[6];const C=H,X=a.useRef(r);let W,T;e[7]!==r?(W=()=>{X.current=r},T=[r],e[7]=r,e[8]=W,e[9]=T):(W=e[8],T=e[9]),a.useEffect(W,T);let M,z;e[10]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{const G=c.current;if(!G)return;let u=null;const _=()=>{const I=G.getBoundingClientRect(),ue=Math.round(I.width),Ne=Math.round(I.height),De=window.devicePixelRatio||1;x(Re=>Re.width===ue&&Re.height===Ne&&Re.dpr===De?Re:{width:ue,height:Ne,dpr:De}),u&&clearTimeout(u),u=setTimeout(()=>{u=null,ue>0&&Ne>0&&X.current(ue,Ne,De)},Cs)};_();const ee=new ResizeObserver(_);return ee.observe(G),()=>{ee.disconnect(),u&&clearTimeout(u)}},z=[],e[10]=M,e[11]=z):(M=e[10],z=e[11]),a.useEffect(M,z);let j,Z;e[12]!==C||e[13]!==t||e[14]!==d?(j=()=>{const G=p.current,u=G==null?void 0:G.getContext("2d");if(!G||!u)return;const _=Math.round(d.width*d.dpr),ee=Math.round(d.height*d.dpr);G.width!==_&&(G.width=_),G.height!==ee&&(G.height=ee),u.setTransform(d.dpr,0,0,d.dpr,0,0),u.clearRect(0,0,d.width,d.height),!(!t||C.width<=0||C.height<=0)&&Os(u,t.bitmap,C)},Z=[t,C,d],e[12]=C,e[13]=t,e[14]=d,e[15]=j,e[16]=Z):(j=e[15],Z=e[16]),a.useEffect(j,Z);let R,L;e[17]!==t?(R=()=>()=>it(t),L=[t],e[17]=t,e[18]=R,e[19]=L):(R=e[18],L=e[19]),a.useEffect(R,L);let B;e[20]!==C?(B=function(u,_,ee){const I=p.current;return I?ot(u,_,I.getBoundingClientRect(),C,{clamp:ee}):null},e[20]=C,e[21]=B):B=e[21];const P=B;let ne;e[22]!==l?(ne=function(u,_,ee,I,ue){l({type:"mouse",event:u,x:_.x,y:_.y,button:ee,clickCount:I,modifiers:ue})},e[22]=l,e[23]=ne):ne=e[23];const J=ne;let Q;e[24]===Symbol.for("react.memo_cache_sentinel")?(Q=function(u){const _=y.current,ee=Date.now(),I=u.button===_.button&&ee-_.at<Ns&&Math.abs(u.clientX-_.x)<=At&&Math.abs(u.clientY-_.y)<=At;return y.current={count:I?_.count+1:1,at:ee,x:u.clientX,y:u.clientY,button:u.button},y.current.count},e[24]=Q):Q=e[24];const $=Q;let V;e[25]!==P||e[26]!==J?(V=function(){const u=w.current;if(w.current=null,!u)return;const _=P(u.clientX,u.clientY,b.current);_&&J("move",_,"none",0,u.modifiers)},e[25]=P,e[26]=J,e[27]=V):V=e[27];const A=V;let E;e[28]!==A?(E=function(){S.current!==null&&(cancelAnimationFrame(S.current),S.current=null),A()},e[28]=A,e[29]=E):E=e[29];const te=E;let U;e[30]!==P||e[31]!==J?(U=function(u){if(u.currentTarget.focus(),u.button===Rt)return;const _=P(u.clientX,u.clientY,!1);_&&(u.currentTarget.setPointerCapture(u.pointerId),b.current=!0,J("down",_,Dt(u.button),$(u),_e(u)))},e[30]=P,e[31]=J,e[32]=U):U=e[32];const ae=U;let q;e[33]!==A?(q=function(u){w.current={clientX:u.clientX,clientY:u.clientY,modifiers:_e(u)},S.current===null&&(S.current=requestAnimationFrame(()=>{S.current=null,A()}))},e[33]=A,e[34]=q):q=e[34];const se=q;let de;e[35]!==te||e[36]!==P||e[37]!==J?(de=function(u){te();const _=b.current;if(b.current=!1,u.currentTarget.hasPointerCapture(u.pointerId)&&u.currentTarget.releasePointerCapture(u.pointerId),u.button===Rt)return;const ee=P(u.clientX,u.clientY,_);ee&&J("up",ee,Dt(u.button),y.current.count,_e(u))},e[35]=te,e[36]=P,e[37]=J,e[38]=de):de=e[38];const ve=de;let ge;e[39]!==P||e[40]!==J?(ge=function(u){u.preventDefault();const _=P(u.clientX,u.clientY,!1);if(!_)return;const ee=_e(u);J("down",_,"right",1,ee),J("up",_,"right",1,ee)},e[39]=P,e[40]=J,e[41]=ge):ge=e[41];const he=ge;let pe;e[42]!==l?(pe=function(u){if(u.key==="Escape"){u.currentTarget.blur();return}_t(u)||u.preventDefault();const _={type:"key",event:"down",key:u.key,code:u.code,modifiers:_e(u)},ee=Is(u);ee!==void 0&&(_.text=ee),O.current.set(u.code,u.key),l(_)},e[42]=l,e[43]=pe):pe=e[43];const be=pe;let fe;e[44]!==l?(fe=function(u){u.key!=="Escape"&&(_t(u)||u.preventDefault(),O.current.delete(u.code),l({type:"key",event:"up",key:u.key,code:u.code,modifiers:_e(u)}))},e[44]=l,e[45]=fe):fe=e[45];const le=fe;let K,Y;e[46]!==D||e[47]!==N||e[48]!==C||e[49]!==f||e[50]!==l?(K=()=>{const G=p.current;if(!G||f)return;const u=_=>{_.preventDefault();const ee=ot(_.clientX,_.clientY,G.getBoundingClientRect(),C);ee&&l({type:"wheel",x:ee.x,y:ee.y,deltaX:It(_.deltaX,_.deltaMode,N),deltaY:It(_.deltaY,_.deltaMode,D),modifiers:_e(_)})};return G.addEventListener("wheel",u,{passive:!1}),()=>G.removeEventListener("wheel",u)},Y=[l,C,N,D,f],e[46]=D,e[47]=N,e[48]=C,e[49]=f,e[50]=l,e[51]=K,e[52]=Y):(K=e[51],Y=e[52]),a.useEffect(K,Y);let ce,Se;e[53]!==h||e[54]!==l?(ce=()=>{if(!h)return;const G=u=>{var ee;const _=(ee=u.clipboardData)==null?void 0:ee.getData("text/plain");_&&(u.preventDefault(),l({type:"paste",text:_}))};return document.addEventListener("paste",G),()=>document.removeEventListener("paste",G)},Se=[h,l],e[53]=h,e[54]=l,e[55]=ce,e[56]=Se):(ce=e[55],Se=e[56]),a.useEffect(ce,Se);let we,ye;e[57]===Symbol.for("react.memo_cache_sentinel")?(we=()=>()=>{S.current!==null&&cancelAnimationFrame(S.current)},ye=[],e[57]=we,e[58]=ye):(we=e[57],ye=e[58]),a.useEffect(we,ye);let me;e[59]!==l?(me=()=>{for(const[G,u]of O.current)l({type:"key",event:"up",key:u,code:G,modifiers:0});O.current.clear()},e[59]=l,e[60]=me):me=e[60];const je=me;let ie,F;e[61]!==je?(ie=()=>je,F=[je],e[61]=je,e[62]=ie,e[63]=F):(ie=e[62],F=e[63]),a.useEffect(ie,F);let oe;e[64]!==o?(oe=Ae("relative min-h-0 min-w-0 overflow-hidden bg-muted/30",o),e[64]=o,e[65]=oe):oe=e[65];let Ee;e[66]!==h||e[67]!==he||e[68]!==be||e[69]!==le||e[70]!==ae||e[71]!==se||e[72]!==ve||e[73]!==f||e[74]!==je?(Ee=f?n.jsx("canvas",{ref:p,role:"img","aria-label":"Browser viewport, view only",className:"block size-full cursor-default touch-none select-none"}):n.jsx("canvas",{ref:p,role:"application","aria-label":"Browser viewport",tabIndex:0,className:Ae("block size-full cursor-default touch-none select-none outline-none",h&&"ring-2 ring-ring ring-inset"),onFocus:()=>g(!0),onBlur:()=>{g(!1),je()},onPointerDown:ae,onPointerMove:se,onPointerUp:ve,onPointerCancel:ve,onContextMenu:he,onKeyDown:be,onKeyUp:le}),e[66]=h,e[67]=he,e[68]=be,e[69]=le,e[70]=ae,e[71]=se,e[72]=ve,e[73]=f,e[74]=je,e[75]=Ee):Ee=e[75];let ke;e[76]!==h?(ke=h&&n.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-2 flex justify-center",children:n.jsx("span",{className:"rounded-full bg-popover px-2 py-0.5 text-[10px] text-muted-foreground shadow-xs",children:Rs})}),e[76]=h,e[77]=ke):ke=e[77];let Te;return e[78]!==oe||e[79]!==Ee||e[80]!==ke?(Te=n.jsxs("div",{ref:c,className:oe,children:[Ee,ke]}),e[78]=oe,e[79]=Ee,e[80]=ke,e[81]=Te):Te=e[81],Te}function Ls(s,e){try{const t=document.createElement("canvas");t.width=s.width,t.height=s.height;const l=t.getContext("2d");return!l||t.width===0?null:(l.drawImage(s,0,0),{...e,canvas:t})}catch{return null}}function Bs(s,e,t=1568){var f;const l=s.canvas.width/s.deviceWidth,r={x:e.x*l,y:e.y*l,width:Math.max(1,e.width*l),height:Math.max(1,e.height*l)},i=Math.min(1,t/Math.max(r.width,r.height)),o=document.createElement("canvas");return o.width=Math.max(1,Math.round(r.width*i)),o.height=Math.max(1,Math.round(r.height*i)),(f=o.getContext("2d"))==null||f.drawImage(s.canvas,r.x,r.y,r.width,r.height,0,0,o.width,o.height),{id:crypto.randomUUID(),mediaType:"image/jpeg",data:o.toDataURL("image/jpeg",.85).split(",")[1]??""}}function Ot(s,e){return{x:Math.round(Math.min(s.x,e.x)),y:Math.round(Math.min(s.y,e.y)),width:Math.round(Math.abs(s.x-e.x)),height:Math.round(Math.abs(s.y-e.y))}}function Fs(s){const e=Ce.c(85),{frame:t,onAdd:l,onCancel:r}=s,i=a.useRef(null),o=a.useRef(null);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f={width:0,height:0},e[0]=f):f=e[0];const[c,p]=a.useState(f);let w;e[1]!==t.deviceHeight||e[2]!==t.deviceWidth?(w={x:0,y:0,width:t.deviceWidth,height:t.deviceHeight},e[1]=t.deviceHeight,e[2]=t.deviceWidth,e[3]=w):w=e[3];const S=w,[b,v]=a.useState(S),[y,k]=a.useState(null),[O,m]=a.useState(""),[d,x]=a.useState(null);let h;e[4]!==t.deviceHeight||e[5]!==t.deviceWidth||e[6]!==c?(h=Zt(c,{width:t.deviceWidth,height:t.deviceHeight}),e[4]=t.deviceHeight,e[5]=t.deviceWidth,e[6]=c,e[7]=h):h=e[7];const g=h;let N,D;e[8]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{const K=i.current;if(!K)return;const Y=new ResizeObserver(ce=>{const[Se]=ce;Se&&p({width:Se.contentRect.width,height:Se.contentRect.height})});return Y.observe(K),()=>Y.disconnect()},D=[],e[8]=N,e[9]=D):(N=e[8],D=e[9]),a.useEffect(N,D);let H;e[10]!==g.height||e[11]!==g.width||e[12]!==g.x||e[13]!==g.y||e[14]!==t.canvas||e[15]!==c.height||e[16]!==c.width?(H=()=>{const K=o.current;if(!K||g.width<=0)return;const Y=window.devicePixelRatio||1;K.width=Math.round(c.width*Y),K.height=Math.round(c.height*Y);const ce=K.getContext("2d");ce&&(ce.setTransform(Y,0,0,Y,0,0),ce.clearRect(0,0,c.width,c.height),ce.drawImage(t.canvas,g.x,g.y,g.width,g.height))},e[10]=g.height,e[11]=g.width,e[12]=g.x,e[13]=g.y,e[14]=t.canvas,e[15]=c.height,e[16]=c.width,e[17]=H):H=e[17];let C;e[18]!==g||e[19]!==t||e[20]!==c?(C=[t,g,c],e[18]=g,e[19]=t,e[20]=c,e[21]=C):C=e[21],a.useEffect(H,C);let X;e[22]!==g?(X=K=>{const Y=o.current;return Y?ot(K.clientX,K.clientY,Y.getBoundingClientRect(),g,{clamp:!0}):null},e[22]=g,e[23]=X):X=e[23];const W=X;let T;e[24]!==t||e[25]!==O||e[26]!==l||e[27]!==r||e[28]!==b?(T=function(){if(b.width<4||b.height<4){x("Mark a larger region, or use the whole page");return}const Y={id:vn(),kind:"browser",note:O.trim().slice(0,wt.noteChars),url:t.url,title:t.title,viewport:{width:t.deviceWidth,height:t.deviceHeight},region:b,capturedAt:t.capturedAt,browser:t.browser,...t.tab?{tab:t.tab}:{},image:1},ce=l(Y,Bs(t,b));ce?x(ce):r()},e[24]=t,e[25]=O,e[26]=l,e[27]=r,e[28]=b,e[29]=T):T=e[29];const M=T,z=g.x+b.x*g.scale,j=g.y+b.y*g.scale,Z=b.width*g.scale,R=b.height*g.scale;let L;e[30]!==z||e[31]!==j||e[32]!==Z||e[33]!==R?(L={left:z,top:j,width:Z,height:R},e[30]=z,e[31]=j,e[32]=Z,e[33]=R,e[34]=L):L=e[34];const B=L,P=b.x===0&&b.y===0&&b.width===t.deviceWidth&&b.height===t.deviceHeight;let ne;e[35]!==r?(ne=K=>{K.key==="Escape"&&(K.preventDefault(),r())},e[35]=r,e[36]=ne):ne=e[36];const J=`Frozen frame of ${t.title||t.url}. Drag to mark a region; the page does not receive these clicks.`;let Q;e[37]!==c.height||e[38]!==c.width?(Q={width:c.width,height:c.height},e[37]=c.height,e[38]=c.width,e[39]=Q):Q=e[39];let $;e[40]!==W?($=K=>{const Y=W(K);Y&&(K.currentTarget.setPointerCapture(K.pointerId),k(Y),v({x:Math.round(Y.x),y:Math.round(Y.y),width:0,height:0}))},e[40]=W,e[41]=$):$=e[41];let V,A;e[42]!==y||e[43]!==W?(V=K=>{const Y=y&&W(K);y&&Y&&v(Ot(y,Y))},A=K=>{const Y=y&&W(K);y&&Y&&v(Ot(y,Y)),k(null),K.currentTarget.hasPointerCapture(K.pointerId)&&K.currentTarget.releasePointerCapture(K.pointerId)},e[42]=y,e[43]=W,e[44]=V,e[45]=A):(V=e[44],A=e[45]);let E;e[46]!==J||e[47]!==Q||e[48]!==$||e[49]!==V||e[50]!==A?(E=n.jsx("canvas",{ref:o,role:"img","aria-label":J,className:"block size-full cursor-crosshair touch-none select-none",style:Q,onPointerDown:$,onPointerMove:V,onPointerUp:A}),e[46]=J,e[47]=Q,e[48]=$,e[49]=V,e[50]=A,e[51]=E):E=e[51];let te;e[52]!==B||e[53]!==P?(te=!P&&n.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute border-2 border-info bg-info/10",style:B}),e[52]=B,e[53]=P,e[54]=te):te=e[54];let U;e[55]!==E||e[56]!==te?(U=n.jsxs("div",{ref:i,className:"relative min-h-0 flex-1 overflow-hidden bg-muted/30",children:[E,te]}),e[55]=E,e[56]=te,e[57]=U):U=e[57];const ae=P?"Whole page selected. Drag on the frame to mark a region.":`Region ${b.width}×${b.height} at ${b.x},${b.y}`;let q;e[58]!==ae?(q=n.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:ae}),e[58]=ae,e[59]=q):q=e[59];let se;e[60]===Symbol.for("react.memo_cache_sentinel")?(se=K=>m(K.target.value),e[60]=se):se=e[60];let de;e[61]!==O?(de=n.jsx(jn,{value:O,onChange:se,placeholder:"What should the agent look at here?","aria-label":"Annotation note",rows:2,maxLength:wt.noteChars,className:"min-h-0 resize-none text-sm",autoFocus:!0}),e[61]=O,e[62]=de):de=e[62];let ve;e[63]!==d?(ve=d&&n.jsx("p",{role:"alert",className:"text-xs text-destructive",children:d}),e[63]=d,e[64]=ve):ve=e[64];let ge;e[65]!==P||e[66]!==S?(ge=!P&&n.jsx(re,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(S),children:"Use whole page"}),e[65]=P,e[66]=S,e[67]=ge):ge=e[67];let he;e[68]!==r?(he=n.jsx(re,{type:"button",variant:"ghost",size:"sm",onClick:r,children:"Cancel"}),e[68]=r,e[69]=he):he=e[69];let pe;e[70]!==M?(pe=n.jsx(re,{type:"button",size:"sm",onClick:M,children:"Add to message"}),e[70]=M,e[71]=pe):pe=e[71];let be;e[72]!==ge||e[73]!==he||e[74]!==pe?(be=n.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[ge,he,pe]}),e[72]=ge,e[73]=he,e[74]=pe,e[75]=be):be=e[75];let fe;e[76]!==q||e[77]!==de||e[78]!==ve||e[79]!==be?(fe=n.jsxs("div",{className:"flex shrink-0 flex-col gap-2 border-t p-2",children:[q,de,ve,be]}),e[76]=q,e[77]=de,e[78]=ve,e[79]=be,e[80]=fe):fe=e[80];let le;return e[81]!==ne||e[82]!==U||e[83]!==fe?(le=n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",onKeyDown:ne,children:[U,fe]}),e[81]=ne,e[82]=U,e[83]=fe,e[84]=le):le=e[84],le}const zs="browser-panel-session",Ps="browser-panel-follow",$s=1e4,Mt=3e3,Us=[];function qs({context:s,active:e,closePanel:t,onAnnotate:l}){var _,ee;const[r,i]=a.useState(null),[o,f]=bt(yt(zs),ut),[c,p]=bt(yt(Ps),!0),[w,S]=a.useState(!1),[b,v]=a.useState(null),[y,k]=a.useState(null),[O,m]=a.useState(!1),d=a.useRef(0),{status:x,error:h,refresh:g,create:N,remove:D,stop:H,setArchived:C,readSkillTargets:X,installSkill:W}=zn(e),T=(x==null?void 0:x.sessions)??Us,M=is(T),z=x!==null&&T.length>0,j=x===null||T.some(I=>I.name===o)?o:M,Z=a.useCallback(I=>void Lt(I),[]),R=Xn(e&&z?j:null,Z),L=((_=s.session)==null?void 0:_.sessionId)??null,B=a.useMemo(()=>Sn(s.session),[s.session]),P=cs((B==null?void 0:B.session)??null,T,L),ne=T.some(I=>I.name===P&&!I.archived);a.useEffect(()=>{!c||P===null||P===j||!ne||Date.now()-d.current<$s||f(P)},[c,P,ne,j,f]);const J=a.useCallback(I=>{d.current=Date.now(),f(I)},[f]),Q=a.useCallback(async I=>{S(!0);try{const ue=await I();return v(ue.ok?null:ue.error),ue}finally{S(!1)}},[]),{send:$}=R,V=a.useCallback((I,ue,Ne)=>{$({type:"viewport",width:I,height:ue,dpr:Ne})},[$]),A=a.useCallback(I=>{I&&(d.current=0),p(I)},[p]),E=a.useCallback(()=>J(M),[J,M]),te=a.useCallback(()=>m(!0),[]),U=a.useCallback(I=>{J(M),Q(()=>D(I))},[J,M,Q,D]),ae=a.useCallback(I=>void Q(()=>H(I)),[Q,H]),q=a.useCallback(async(I,ue)=>{const Ne=await Q(()=>C(I,ue));return Ne.ok&&ue&&I===j&&J(M),Ne},[Q,C,j,J,M]),se=a.useCallback(I=>$({type:"navigate",url:I}),[$]),de=a.useCallback(()=>$({type:"back"}),[$]),ve=a.useCallback(()=>$({type:"forward"}),[$]),ge=a.useCallback(()=>$({type:"reload"}),[$]),he=a.useCallback(I=>$({type:"follow",targetId:I}),[$]),pe=a.useCallback(I=>$({type:"close-tab",targetId:I}),[$]),be=a.useCallback(I=>$({type:"launch",url:I}),[$]),fe=Ks(R.lastFrameAt),{frame:le,page:K,tabs:Y,pageGeneration:ce}=R,Se=a.useCallback(()=>{if(!K)return;const I=le==null?void 0:le.page;if(!le||!I||le.pageGeneration!==ce||le.header.targetId!==I.targetId){v("The page is still drawing; try again in a moment");return}const ue=Y.find(De=>De.targetId===le.header.targetId),Ne=Ls(le.bitmap,{deviceWidth:le.header.deviceWidth,deviceHeight:le.header.deviceHeight,url:I.url,title:I.title,browser:j,...ue?{tab:ue.title||ue.url}:{},capturedAt:new Date(le.header.ts).toISOString()});Ne?i(Ne):v("The page is still drawing; try again in a moment")},[le,K,Y,ce,j]),we=((ee=R.state)==null?void 0:ee.state)??null,ye=(x==null?void 0:x.installed)===!1||we==="not-installed",me=!ye&&we==="live",je=!ye&&we==="stopped",ie=T.find(I=>I.name===j)??null,F=Ye(ie,j),oe=os(ie),Ee=(ie==null?void 0:ie.mine)===!0&&!ie.running&&ie.lastUsedAt===null,ke=me&&(R.status==="disconnected"||R.status==="connecting"),Te=x===null&&h!==null,G=R.error??b??(Te?null:h),u=G!==null&&G!==y?G:null;return n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.jsx(gs,{sessions:T,selected:j,home:M,currentSessionId:L,followAgent:c,busy:w,onSelect:J,onToggleFollow:A,onOpenSkill:te,onCreate:N,onRemove:U,onStop:ae,onSetArchived:q,onShowDefault:E,onClose:t}),me&&n.jsx(ls,{page:R.page,tabs:R.tabs,followed:R.followed,status:ke?"offline":fe,readOnly:!oe,onNavigate:se,onBack:de,onForward:ve,onReload:ge,onFollow:he,onCloseTab:pe,onAnnotate:l&&!r?Se:void 0}),u&&n.jsx(Ys,{message:u,onDismiss:()=>{v(null),k(G)}}),n.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[Te&&n.jsx(ts,{message:h,onRetry:g}),ye&&n.jsx(Qn,{onOpenSkill:te}),!ye&&x!==null&&!z&&n.jsx(Nt,{}),je&&(Ee?n.jsx(Nt,{onOpen:be}):n.jsx(es,{name:F,lastUrl:(ie==null?void 0:ie.lastUrl)??null,onOpen:oe?be:void 0})),me&&r&&l&&n.jsx(Fs,{frame:r,onAdd:l,onCancel:()=>i(null)}),me&&!r&&n.jsxs(n.Fragment,{children:[n.jsx(Ms,{className:"flex-1",frame:R.frame,send:$,onSizeChange:V,readOnly:!oe}),ke&&n.jsx(Ws,{}),n.jsx(qn,{activity:B&&P===j?B:null})]}),!ye&&!Te&&(x===null||z)&&!je&&!me&&n.jsxs("div",{role:"status",className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(ct,{}),"Connecting to ",F,"…"]})]}),n.jsx(ps,{open:O,onOpenChange:m,readTargets:X,install:W})]})}function Ks(s){const e=Ce.c(5),[,t]=a.useState(0);let l;e[0]!==t||e[1]!==s?(l=()=>{if(s===null)return;const i=s+Mt-Date.now();if(i<=0)return;const o=setTimeout(()=>t(Hs),i);return()=>clearTimeout(o)},e[0]=t,e[1]=s,e[2]=l):l=e[2];let r;return e[3]!==s?(r=[s],e[3]=s,e[4]=r):r=e[4],a.useEffect(l,r),s===null?"idle":Date.now()-s<Mt?"live":"idle"}function Hs(s){return s+1}function Ws(){const s=Ce.c(1);let e;return s[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 flex justify-center p-2",children:n.jsx("span",{role:"status",className:"rounded-full bg-popover px-2.5 py-0.5 text-[11px] text-muted-foreground shadow-xs",children:"Reconnecting…"})}),s[0]=e):e=s[0],e}function Ys(s){const e=Ce.c(9),{message:t,onDismiss:l}=s;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(dt,{"aria-hidden":!0,className:"size-3.5 shrink-0"}),e[0]=r):r=e[0];let i;e[1]!==t?(i=n.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e[1]=t,e[2]=i):i=e[2];let o;e[3]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Ze,{"data-icon":"inline-start"}),e[3]=o):o=e[3];let f;e[4]!==l?(f=n.jsx(re,{variant:"ghost",size:"icon-xs","aria-label":"Dismiss",onClick:l,children:o}),e[4]=l,e[5]=f):f=e[5];let c;return e[6]!==i||e[7]!==f?(c=n.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-destructive/30 bg-destructive/10 px-2 py-1 text-xs text-destructive",children:[r,i,f]}),e[6]=i,e[7]=f,e[8]=c):c=e[8],c}export{qs as BrowserPanel};
@@ -1,3 +1,3 @@
1
- var q=Object.defineProperty;var Q=(o,e,t)=>e in o?q(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var y=(o,e,t)=>Q(o,typeof e!="symbol"?e+"":e,t);import{cH as S,aZ as E,cI as L,cJ as U,cK as M,cL as I,cM as B,cN as F,cO as $,cP as Y,cQ as X,cR as G,cS as C,cT as ee,cU as te,cV as O,cW as D}from"./index-Bg4A-xl7.js";import"./vendor-react-gGw_S5I_.js";import"./vendor-ui-Dc_kJXxz.js";import"./vendor-markdown-BEJ8yVzA.js";const re=35e5,se=U({id:I().min(1),mediaType:F(["image/png","image/jpeg","image/gif","image/webp"]),data:I().min(1).max(re).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine(o=>o.length%4===0),contextId:I().optional()}).strict(),oe=U({v:Y(1),text:I(),context:M(B()),attachments:M(se)}).strict();function T(o){const t=oe.parse(o);if(t.context.length){const n=X(t.context);if(n)throw new Error(n);const i=G(C(t));if(!i||i.context.length!==t.context.length||i.context.some((a,p)=>C({text:"",context:[a]})!==C({text:"",context:[t.context[p]]})))throw new Error("Invalid saved context");for(const a of t.context)if(a.kind==="browser"&&!t.attachments.some(p=>p.contextId===a.id))throw new Error("The saved capture is missing its image bytes. Reattach the capture or restore a backup.")}if(new Set(t.attachments.map(n=>n.id)).size!==t.attachments.length)throw new Error("Duplicate saved attachment");if(t.attachments.some(n=>n.contextId&&!t.context.some(i=>i.id===n.contextId)))throw new Error("A saved image has lost its context. Restore a backup or reattach it.");return structuredClone(t)}function ne(o,e){return JSON.stringify([E("composer-v1"),o??"",e])}const ae=U({v:Y(1),draft:B(),pendingUpload:$().optional(),entries:M(U({id:I(),kind:F(["stash","sending","refused","sent"]),savedAt:I(),draft:B(),createdTarget:I().optional()}).strict())}).strict(),K=new Map,ie=()=>({v:1,draft:structuredClone(L),entries:[]});class ce{constructor(e,t=()=>localStorage){y(this,"listeners",new Set);y(this,"snapshot",{record:ie(),error:null,corrupt:null});y(this,"getSnapshot",()=>this.snapshot);y(this,"subscribe",e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}));y(this,"read",()=>{try{const e=this.storage().getItem(this.key);if(e===null)return;try{const t=ae.parse(JSON.parse(e)),n={v:1,pendingUpload:t.pendingUpload,draft:T(t.draft),entries:t.entries.map(i=>({...i,draft:T(i.draft)}))};this.publish({record:n,error:null,corrupt:null})}catch{this.publish({...this.snapshot,corrupt:e,error:"Saved drafts are damaged or contain expired attachment references. Download the backup before resetting storage; your current draft is kept."})}}catch{this.publish({...this.snapshot,error:"Draft storage is unavailable. Keep this tab open, retry storage or download a backup."})}});y(this,"retry",(e=()=>!0)=>this.snapshot.corrupt!==null||!this.write(this.snapshot.record)?!1:(this.snapshot.record.entries.forEach(t=>this.transferAccepted(t.id,e)),this.snapshot.error===null));y(this,"backup",()=>JSON.stringify({scope:this.key,...this.snapshot.record,...this.snapshot.corrupt!==null?{damagedStorage:this.snapshot.corrupt}:{}},null,2));y(this,"resetAfterBackup",()=>{const e=this.snapshot.record;return this.publish({...this.snapshot,corrupt:null}),this.write(e)});this.key=e,this.storage=t,this.read()}publish(e){this.snapshot=e,this.listeners.forEach(t=>t())}write(e){if(this.snapshot.corrupt!==null)return this.publish({...this.snapshot,record:e}),!1;try{return T(e.draft),e.entries.forEach(t=>T(t.draft)),this.storage().setItem(this.key,JSON.stringify(e)),this.publish({record:e,error:null,corrupt:null}),!0}catch(t){return this.publish({record:e,corrupt:null,error:`Draft was kept in this tab but could not be saved (${t instanceof Error&&t.name==="ZodError"?"invalid or oversized attachment":"storage denied, full, or invalid data"}). Retry or download a backup before leaving.`}),!1}}markUpload(e){return this.write({...this.snapshot.record,pendingUpload:e})}saveDraft(e){return JSON.stringify(e)===JSON.stringify(this.snapshot.record.draft)?this.snapshot.error===null:this.write({...this.snapshot.record,draft:structuredClone(e)})}save(e,t="stash"){if(S(e))return null;const n=crypto.randomUUID(),i=this.snapshot.record,a={id:n,kind:t,savedAt:new Date().toISOString(),draft:structuredClone(e)},p=this.write({...i,draft:structuredClone(L),entries:[...i.entries,a]});return p||this.publish({...this.snapshot,record:i}),p?n:null}copy(e){if(S(e))return null;const t=this.snapshot.record,n=crypto.randomUUID(),i={id:n,kind:"stash",savedAt:new Date().toISOString(),draft:structuredClone(e)};return this.write({...t,entries:[...t.entries,i]})?n:(this.publish({...this.snapshot,record:t}),null)}retainImport(e){const t={id:crypto.randomUUID(),kind:"stash",savedAt:new Date().toISOString(),draft:{v:1,text:e,context:[],attachments:[]}};return this.write({...this.snapshot.record,entries:[...this.snapshot.record.entries,t]})}created(e,t,n=()=>!0){const[i]=JSON.parse(this.key),a=JSON.stringify([i,t.cwd,JSON.stringify([t.dirName,t.sessionId])]),p=this.snapshot.record;this.write({...p,entries:p.entries.map(h=>h.id===e?{...h,createdTarget:a}:h)}),this.transferAccepted(e,n)}transferAccepted(e,t=()=>!0){const n=this.snapshot.record.entries.find(h=>h.id===e);if((n==null?void 0:n.kind)!=="sent"||!n.createdTarget||n.createdTarget===this.key)return;try{const[h,f]=JSON.parse(n.createdTarget);if(h!==JSON.parse(this.key)[0]||!t(f))throw new Error("Target is outside the current draft scope")}catch{this.publish({...this.snapshot,error:"Recall handoff is outside the enabled account or project scope. The original message is kept here."});return}const i=N(n.createdTarget),a={...n,createdTarget:void 0},p=i.getSnapshot().record;p.entries.some(h=>h.id===e)||i.write({...p,entries:[...p.entries,a]})?this.remove(e):this.publish({...this.snapshot,error:"The first prompt was sent, but recall could not be saved in the new session. Its complete journal is kept here; retry storage or download a backup."})}settle(e,t,n=!0,i=()=>!0){const a=this.snapshot.record,p=a.entries.find(h=>h.id===e);if(p)if(!t&&n&&S(a.draft))this.write({...a,draft:p.draft,entries:a.entries.filter(h=>h.id!==e)});else{const h=a.entries.map(w=>w.id===e?{...w,kind:t?"sent":"refused"}:w),f=h.filter(w=>w.kind==="sent").slice(0,-30);this.write({...a,entries:h.filter(w=>!f.includes(w))}),t&&this.transferAccepted(e,i)}}restore(e,t){const n=this.snapshot.record,i=n.entries.find(a=>a.id===e);if(!i||t==="replace"&&!S(n.draft))return null;try{const a=t==="merge"?de(n.draft,i.draft):T(i.draft),p=n.entries.filter(h=>h.id!==e||h.kind==="sent");return t==="swap"&&!S(n.draft)&&p.push({id:crypto.randomUUID(),kind:"stash",savedAt:new Date().toISOString(),draft:n.draft}),this.write({...n,draft:a,entries:p})?a:(this.publish({...this.snapshot,record:n}),null)}catch(a){return this.publish({...this.snapshot,error:a instanceof Error?a.message:"Cannot restore this prompt"}),null}}remove(e){const t=this.snapshot.record;return this.write({...t,entries:t.entries.filter(n=>n.id!==e)})?!0:(this.publish({...this.snapshot,record:t}),!1)}}function N(o){let e=K.get(o);return e||(e=new ce(o),K.set(o,e)),e}function de(o,e){const t=[...o.context],n=[...o.attachments];for(const i of e.context){const a=t.find(p=>p.id===i.id);if(a&&C({text:"",context:[a]})!==C({text:"",context:[i]}))throw new Error("Context changed since saving. Use Swap to preserve both versions.");a||t.push(i)}for(const i of e.attachments){const a=n.find(p=>p.id===i.id);if(a&&JSON.stringify(a)!==JSON.stringify(i))throw new Error("An attachment changed since saving. Use Swap to preserve both versions.");a||n.push(i)}return T({v:1,text:[o.text,e.text].filter(Boolean).join(`
1
+ var $=Object.defineProperty;var q=(o,e,t)=>e in o?$(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var y=(o,e,t)=>q(o,typeof e!="symbol"?e+"":e,t);import{cU as k,aZ as E,cV as U,cW as L,cX as J,cY as A,cZ as M,c_ as F,c$ as X,d0 as Y,d1 as Q,d2 as G,d3 as C,d4 as ee,d5 as te,d6 as O,d7 as D}from"./index-Dv2TZ38C.js";import"./vendor-react-gGw_S5I_.js";import"./vendor-ui-ClPj6-Gu.js";import"./vendor-markdown-BEJ8yVzA.js";const re=35e5,se=L({id:A().min(1),mediaType:F(["image/png","image/jpeg","image/gif","image/webp"]),data:A().min(1).max(re).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine(o=>o.length%4===0),contextId:A().optional()}).strict(),oe=L({v:Y(1),text:A(),context:J(M()),attachments:J(se)}).strict();function T(o){const t=oe.parse(o);if(t.context.length){const n=Q(t.context);if(n)throw new Error(n);const i=G(C(t));if(!i||i.context.length!==t.context.length||i.context.some((a,p)=>C({text:"",context:[a]})!==C({text:"",context:[t.context[p]]})))throw new Error("Invalid saved context");for(const a of t.context)if(a.kind==="browser"&&!t.attachments.some(p=>p.contextId===a.id))throw new Error("The saved capture is missing its image bytes. Reattach the capture or restore a backup.")}if(new Set(t.attachments.map(n=>n.id)).size!==t.attachments.length)throw new Error("Duplicate saved attachment");if(t.attachments.some(n=>n.contextId&&!t.context.some(i=>i.id===n.contextId)))throw new Error("A saved image has lost its context. Restore a backup or reattach it.");return structuredClone(t)}function ne(o,e){return JSON.stringify([E("composer-v1"),o??"",e])}const ae=L({v:Y(1),draft:M(),pendingUpload:X().optional(),entries:J(L({id:A(),kind:F(["stash","sending","refused","sent"]),savedAt:A(),draft:M(),createdTarget:A().optional()}).strict())}).strict(),K=new Map,ie=()=>({v:1,draft:structuredClone(U),entries:[]});class ce{constructor(e,t=()=>localStorage){y(this,"listeners",new Set);y(this,"snapshot",{record:ie(),error:null,corrupt:null});y(this,"getSnapshot",()=>this.snapshot);y(this,"subscribe",e=>(this.listeners.add(e),()=>{this.listeners.delete(e)}));y(this,"read",()=>{try{const e=this.storage().getItem(this.key);if(e===null)return;try{const t=ae.parse(JSON.parse(e)),n={v:1,pendingUpload:t.pendingUpload,draft:T(t.draft),entries:t.entries.map(i=>({...i,draft:T(i.draft)}))};this.publish({record:n,error:null,corrupt:null})}catch{this.publish({...this.snapshot,corrupt:e,error:"Saved drafts are damaged or contain expired attachment references. Download the backup before resetting storage; your current draft is kept."})}}catch{this.publish({...this.snapshot,error:"Draft storage is unavailable. Keep this tab open, retry storage or download a backup."})}});y(this,"retry",(e=()=>!0)=>this.snapshot.corrupt!==null||!this.write(this.snapshot.record)?!1:(this.snapshot.record.entries.forEach(t=>this.transferAccepted(t.id,e)),this.snapshot.error===null));y(this,"backup",()=>JSON.stringify({scope:this.key,...this.snapshot.record,...this.snapshot.corrupt!==null?{damagedStorage:this.snapshot.corrupt}:{}},null,2));y(this,"resetAfterBackup",()=>{const e=this.snapshot.record;return this.publish({...this.snapshot,corrupt:null}),this.write(e)});this.key=e,this.storage=t,this.read()}publish(e){this.snapshot=e,this.listeners.forEach(t=>t())}write(e){if(this.snapshot.corrupt!==null)return this.publish({...this.snapshot,record:e}),!1;try{return T(e.draft),e.entries.forEach(t=>T(t.draft)),this.storage().setItem(this.key,JSON.stringify(e)),this.publish({record:e,error:null,corrupt:null}),!0}catch(t){return this.publish({record:e,corrupt:null,error:`Draft was kept in this tab but could not be saved (${t instanceof Error&&t.name==="ZodError"?"invalid or oversized attachment":"storage denied, full, or invalid data"}). Retry or download a backup before leaving.`}),!1}}markUpload(e){return this.write({...this.snapshot.record,pendingUpload:e})}saveDraft(e){return JSON.stringify(e)===JSON.stringify(this.snapshot.record.draft)?this.snapshot.error===null:this.write({...this.snapshot.record,draft:structuredClone(e)})}save(e,t="stash"){if(k(e))return null;const n=crypto.randomUUID(),i=this.snapshot.record,a={id:n,kind:t,savedAt:new Date().toISOString(),draft:structuredClone(e)},p=this.write({...i,draft:structuredClone(U),entries:[...i.entries,a]});return p||this.publish({...this.snapshot,record:i}),p?n:null}copy(e){if(k(e))return null;const t=this.snapshot.record,n=crypto.randomUUID(),i={id:n,kind:"stash",savedAt:new Date().toISOString(),draft:structuredClone(e)};return this.write({...t,entries:[...t.entries,i]})?n:(this.publish({...this.snapshot,record:t}),null)}retainImport(e){const t={id:crypto.randomUUID(),kind:"stash",savedAt:new Date().toISOString(),draft:{v:1,text:e,context:[],attachments:[]}};return this.write({...this.snapshot.record,entries:[...this.snapshot.record.entries,t]})}created(e,t,n=()=>!0){const[i]=JSON.parse(this.key),a=JSON.stringify([i,t.cwd,JSON.stringify([t.dirName,t.sessionId])]),p=this.snapshot.record;this.write({...p,entries:p.entries.map(h=>h.id===e?{...h,createdTarget:a}:h)}),this.transferAccepted(e,n)}transferAccepted(e,t=()=>!0){const n=this.snapshot.record.entries.find(h=>h.id===e);if((n==null?void 0:n.kind)!=="sent"||!n.createdTarget||n.createdTarget===this.key)return;try{const[h,f]=JSON.parse(n.createdTarget);if(h!==JSON.parse(this.key)[0]||!t(f))throw new Error("Target is outside the current draft scope")}catch{this.publish({...this.snapshot,error:"Recall handoff is outside the enabled account or project scope. The original message is kept here."});return}const i=N(n.createdTarget),a={...n,createdTarget:void 0},p=i.getSnapshot().record;p.entries.some(h=>h.id===e)||i.write({...p,entries:[...p.entries,a]})?this.remove(e):this.publish({...this.snapshot,error:"The first prompt was sent, but recall could not be saved in the new session. Its complete journal is kept here; retry storage or download a backup."})}settle(e,t,n=!0,i=()=>!0){const a=this.snapshot.record,p=a.entries.find(h=>h.id===e);if(p)if(!t&&n&&k(a.draft))this.write({...a,draft:p.draft,entries:a.entries.filter(h=>h.id!==e)});else{const h=a.entries.map(w=>w.id===e?{...w,kind:t?"sent":"refused"}:w),f=h.filter(w=>w.kind==="sent").slice(0,-30);this.write({...a,entries:h.filter(w=>!f.includes(w))}),t&&this.transferAccepted(e,i)}}restore(e,t){const n=this.snapshot.record,i=n.entries.find(a=>a.id===e);if(!i||t==="replace"&&!k(n.draft))return null;try{const a=t==="merge"?de(n.draft,i.draft):T(i.draft),p=n.entries.filter(h=>h.id!==e||h.kind==="sent");return t==="swap"&&!k(n.draft)&&p.push({id:crypto.randomUUID(),kind:"stash",savedAt:new Date().toISOString(),draft:n.draft}),this.write({...n,draft:a,entries:p})?a:(this.publish({...this.snapshot,record:n}),null)}catch(a){return this.publish({...this.snapshot,error:a instanceof Error?a.message:"Cannot restore this prompt"}),null}}remove(e){const t=this.snapshot.record;return this.write({...t,entries:t.entries.filter(n=>n.id!==e)})?!0:(this.publish({...this.snapshot,record:t}),!1)}}function N(o){let e=K.get(o);return e||(e=new ce(o),K.set(o,e)),e}function de(o,e){const t=[...o.context],n=[...o.attachments];for(const i of e.context){const a=t.find(p=>p.id===i.id);if(a&&C({text:"",context:[a]})!==C({text:"",context:[i]}))throw new Error("Context changed since saving. Use Swap to preserve both versions.");a||t.push(i)}for(const i of e.attachments){const a=n.find(p=>p.id===i.id);if(a&&JSON.stringify(a)!==JSON.stringify(i))throw new Error("An attachment changed since saving. Use Swap to preserve both versions.");a||n.push(i)}return T({v:1,text:[o.text,e.text].filter(Boolean).join(`
2
2
 
3
- `),context:t,attachments:n})}function pe(o,e,t,n,i,a){return(o.key==="ArrowUp"||o.key==="ArrowDown")&&!o.shiftKey&&!o.ctrlKey&&!o.metaKey&&!o.altKey&&!o.isComposing&&e===t&&(!i||t===n.text.length)&&!a&&(S(n)||i)}function m(o,e){throw Object.assign(new Error(e),{code:o})}const P=new TextEncoder;function V(o,e){let t=o.slice(0,Math.min(D.previewChars,e));for(;P.encode(t).length>e;)t=t.slice(0,-1);return t}function he(o){return{id:o.id,kind:o.kind,savedAt:o.savedAt,text:V(o.draft.text,2e3),textChars:o.draft.text.length,context:o.draft.context.slice(0,D.contextItems).map(e=>({kind:e.kind,label:V(e.kind==="file"?e.path:e.kind==="quote"?"Quoted message":e.kind==="browser"?e.title||"Browser capture":e.label||"Terminal",128)})),images:o.draft.attachments.slice(0,D.images).map(e=>({mediaType:e.mediaType,bytes:Math.floor(e.data.length*3/4)-(e.data.endsWith("==")?2:e.data.endsWith("=")?1:0)}))}}function le(o){const e=URL.createObjectURL(new Blob([o.backup()],{type:"application/json"})),t=document.createElement("a");t.href=e,t.download="cogpit-drafts-backup.json",t.click(),setTimeout(()=>URL.revokeObjectURL(e),1e3)}function ye(o){o.pluginId!=="cogpit.saved-drafts"&&m("CAPABILITY_UNAVAILABLE","This integration is reserved for Saved drafts"),o.signal.throwIfAborted();const e=E("composer-v1"),t=new Set,n=new Set,i=new Map,a=new Map,p=new Map;let h=!1,f=null;function w(){(h||o.signal.aborted||e!==E("composer-v1"))&&m("STALE_ACTIVATION","Saved drafts is no longer active for this account and device")}function A(r,s=!1){w();const c=O();c||m("CAPABILITY_UNAVAILABLE","Open a message composer to use Saved drafts");const d=c.snapshot();return o.inScope(d.scope.cwd)||m("CAPABILITY_UNAVAILABLE","Saved drafts is not enabled for this project"),(d.scope.key!==ne(d.scope.cwd,d.scope.identity)||r!==void 0&&r!==d.token)&&m("STALE_ACTIVATION","The composer changed. Refresh Saved drafts and try again"),s&&d.busy&&m("CONFLICT","Wait for the image upload or send to finish"),{composer:c,snapshot:d,store:R(d)}}function v(){var s;if(h||o.signal.aborted||e!==E("composer-v1"))return;const r=(s=O())==null?void 0:s.snapshot().token;if(r)for(const c of t)c(r)}function R(r){w(),o.inScope(r.scope.cwd)||m("CAPABILITY_UNAVAILABLE","Saved drafts is not enabled for this project");const s=N(r.scope.key);return i.has(s)||i.set(s,s.subscribe(v)),s}function _(r,s,c){const d=R(s),l=d.getSnapshot().record.draft;c&&S(s.draft)&&!S(l)&&!s.busy&&r.replace(l,s.token)||(d.saveDraft(s.draft),s.uploading?(n.add(s.scope.key),d.getSnapshot().record.pendingUpload||d.markUpload(!0)):n.delete(s.scope.key)&&d.markUpload(!1))}function j(r,s){const{composer:c,snapshot:d,store:l}=A(r,!0);l.saveDraft(d.draft);const u=s?l.save(d.draft):l.copy(d.draft);return u||m("CONFLICT",l.getSnapshot().error||"The composer is empty"),s&&!c.replace(L,r)&&(l.saveDraft(c.snapshot().draft),m("STALE_ACTIVATION","The draft changed; its saved copy was kept")),f=null,c.focus(),{id:u}}const z={"drafts.list"({cursor:r}){const{snapshot:s,store:c}=A(),d=c.getSnapshot(),l=[...d.record.entries].reverse();let u=0;if(r){const k=l.findIndex(b=>b.id===r);k<0&&m("STALE_ACTIVATION","The saved list changed. Refresh it"),u=k+1}const g={token:s.token,items:[],...d.error?{error:d.error.slice(0,512)}:{},corrupt:d.corrupt!==null,pendingUpload:!!d.record.pendingUpload};for(const k of l.slice(u,u+D.page)){const b=he(k);if(P.encode(JSON.stringify({...g,items:[...g.items,b]})).length>48e3)break;g.items.push(b)}return u+g.items.length<l.length&&g.items.length&&(g.next=g.items.at(-1).id),g},"drafts.capture":({token:r,clear:s})=>j(r,s),"drafts.restore"({token:r,id:s,mode:c}){const{composer:d,snapshot:l,store:u}=A(r,!0);u.saveDraft(l.draft);const g=u.restore(s,c);return g||m("CONFLICT",u.getSnapshot().error||"Your current draft has content. Choose Swap or Merge"),d.replace(g,r)||m("STALE_ACTIVATION","The composer changed; refresh before restoring"),f=null,d.focus(),null},"drafts.remove"({token:r,id:s}){const{store:c}=A(r,!0);return c.remove(s)||m("CONFLICT",c.getSnapshot().error||"The draft could not be deleted"),null},"drafts.backup"({token:r}){const{store:s}=A(r);return le(s),p.set(s,s.getSnapshot()),null},"drafts.recover"({token:r,action:s}){const{store:c}=A(r,!0);return s==="reset"&&p.get(c)!==c.getSnapshot()&&m("CONFLICT","Download the current backup before resetting damaged storage"),(s==="retry"?c.retry(o.inScope):s==="reset"?c.resetAfterBackup():c.markUpload(!1))||m("CONFLICT",c.getSnapshot().error||"Storage is unavailable"),null}},H=ee(r=>{if(w(),r.type==="scope"||r.type==="change"){const s=O();s&&o.inScope(r.snapshot.scope.cwd)&&_(s,r.snapshot,r.type==="scope"),f&&f.token!==r.snapshot.token&&(f=null),v()}else if(r.type==="rejected-input"){if(!o.inScope(r.scope.cwd))return;N(r.scope.key).retainImport(r.text),v()}else if(r.type==="before-send"){if(!o.inScope(r.scope.cwd))return;f=null;const s=N(r.scope.key),c=s.save(r.draft,"sending");c&&a.set(r.sendId,{store:s,id:c,cwd:r.scope.cwd,pendingIdentity:JSON.parse(r.scope.identity)[1]==="pending"})}else if(r.type==="created"){const s=a.get(r.sendId);s&&o.inScope(s.cwd)&&(s.store.created(s.id,r.session,o.inScope),s.pendingIdentity=!1,s.settled&&a.delete(r.sendId))}else if(r.type==="settled"){const s=a.get(r.sendId);s&&o.inScope(s.cwd)&&(s.store.settle(s.id,r.sent,!1,o.inScope),s.settled=!0,(!r.sent||!s.pendingIdentity)&&a.delete(r.sendId)),v()}}),W=te((r,s)=>{var b;w();const c=s.snapshot();if(!o.inScope(c.scope.cwd))return!1;if((r.ctrlKey||r.metaKey)&&r.shiftKey&&!r.altKey&&r.key.toLowerCase()==="s"&&!r.isComposing){try{j(c.token,!0)}catch{v()}return!0}const d=(f==null?void 0:f.scope)===c.scope.key&&f.token===c.token;if(c.busy||!pe(r,r.selectionStart,r.selectionEnd,c.draft,d,r.suggestionsOpen))return!1;const l=R(c).getSnapshot().record.entries.filter(Z=>Z.kind==="sent").reverse(),u=d?f.index:null,g=r.key==="ArrowUp"?Math.min((u??-1)+1,l.length-1):Math.max((u??0)-1,-1);if(!l.length||r.key==="ArrowDown"&&u===null)return!1;const k=s.replace(((b=l[g])==null?void 0:b.draft)??L,c.token);return k?(f=g<0?null:{scope:c.scope.key,index:g,token:k.token},s.focus(),!0):!1});function J(){if(!h){h=!0,H(),W();for(const r of i.values())r();i.clear(),t.clear(),a.clear(),p.clear(),o.signal.removeEventListener("abort",J)}}o.signal.addEventListener("abort",J,{once:!0});const x=O();return x&&o.inScope(x.snapshot().scope.cwd)&&_(x,x.snapshot(),!0),{async request(r,s,c){return w(),c.throwIfAborted(),z[r](s)},onTokenChange(r){return t.add(r),()=>{t.delete(r)}},dispose:J}}export{ye as activate};
3
+ `),context:t,attachments:n})}function pe(o,e,t,n,i,a){return(o.key==="ArrowUp"||o.key==="ArrowDown")&&!o.shiftKey&&!o.ctrlKey&&!o.metaKey&&!o.altKey&&!o.isComposing&&e===t&&(!i||t===n.text.length)&&!a&&(k(n)||i)}function m(o,e){throw Object.assign(new Error(e),{code:o})}const z=new TextEncoder;function V(o,e){let t=o.slice(0,Math.min(D.previewChars,e));for(;z.encode(t).length>e;)t=t.slice(0,-1);return t}function he(o){return{id:o.id,kind:o.kind,savedAt:o.savedAt,text:V(o.draft.text,2e3),textChars:o.draft.text.length,context:o.draft.context.slice(0,D.contextItems).map(e=>({kind:e.kind,label:V(e.kind==="file"?e.path:e.kind==="quote"?"Quoted message":e.kind==="browser"?e.title||"Browser capture":e.label||"Terminal",128)})),images:o.draft.attachments.slice(0,D.images).map(e=>({mediaType:e.mediaType,bytes:Math.floor(e.data.length*3/4)-(e.data.endsWith("==")?2:e.data.endsWith("=")?1:0)}))}}function le(o){const e=URL.createObjectURL(new Blob([o.backup()],{type:"application/json"})),t=document.createElement("a");t.href=e,t.download="cogpit-drafts-backup.json",t.click(),setTimeout(()=>URL.revokeObjectURL(e),1e3)}function ye(o){o.pluginId!=="cogpit.saved-drafts"&&m("CAPABILITY_UNAVAILABLE","This integration is reserved for Saved drafts"),o.signal.throwIfAborted();const e=E("composer-v1"),t=new Set,n=new Set,i=new Map,a=new Map,p=new Map;let h=!1,f=null;function w(){(h||o.signal.aborted||e!==E("composer-v1"))&&m("STALE_ACTIVATION","Saved drafts is no longer active for this account and device")}function I(r,s=!1){w();const c=O();c||m("CAPABILITY_UNAVAILABLE","Open a message composer to use Saved drafts");const d=c.snapshot();return o.inScope(d.scope.cwd)||m("CAPABILITY_UNAVAILABLE","Saved drafts is not enabled for this project"),(d.scope.key!==ne(d.scope.cwd,d.scope.identity)||r!==void 0&&r!==d.token)&&m("STALE_ACTIVATION","The composer changed. Refresh Saved drafts and try again"),s&&d.busy&&m("CONFLICT","Wait for the image upload or send to finish"),{composer:c,snapshot:d,store:R(d)}}function v(){var s;if(h||o.signal.aborted||e!==E("composer-v1"))return;const r=(s=O())==null?void 0:s.snapshot().token;if(r)for(const c of t)c(r)}function R(r){w(),o.inScope(r.scope.cwd)||m("CAPABILITY_UNAVAILABLE","Saved drafts is not enabled for this project");const s=N(r.scope.key);return i.has(s)||i.set(s,s.subscribe(v)),s}function _(r,s,c){const d=R(s),l=d.getSnapshot().record.draft;c&&k(s.draft)&&!k(l)&&!s.busy&&r.replace(l,s.token)||(d.saveDraft(s.draft),s.uploading?(n.add(s.scope.key),d.getSnapshot().record.pendingUpload||d.markUpload(!0)):n.delete(s.scope.key)&&d.markUpload(!1))}function j(r,s){const{composer:c,snapshot:d,store:l}=I(r,!0);l.saveDraft(d.draft);const u=s?l.save(d.draft):l.copy(d.draft);return u||m("CONFLICT",l.getSnapshot().error||"The composer is empty"),s&&!c.replace(U,r)&&(l.saveDraft(c.snapshot().draft),m("STALE_ACTIVATION","The draft changed; its saved copy was kept")),f=null,c.focus(),{id:u}}const P={"drafts.list"({cursor:r}){const{snapshot:s,store:c}=I(),d=c.getSnapshot(),l=[...d.record.entries].reverse();let u=0;if(r){const S=l.findIndex(b=>b.id===r);S<0&&m("STALE_ACTIVATION","The saved list changed. Refresh it"),u=S+1}const g={token:s.token,items:[],...d.error?{error:d.error.slice(0,512)}:{},corrupt:d.corrupt!==null,pendingUpload:!!d.record.pendingUpload};for(const S of l.slice(u,u+D.page)){const b=he(S);if(z.encode(JSON.stringify({...g,items:[...g.items,b]})).length>48e3)break;g.items.push(b)}return u+g.items.length<l.length&&g.items.length&&(g.next=g.items.at(-1).id),g},"drafts.capture":({token:r,clear:s})=>j(r,s),"drafts.restore"({token:r,id:s,mode:c}){const{composer:d,snapshot:l,store:u}=I(r,!0);u.saveDraft(l.draft);const g=u.restore(s,c);return g||m("CONFLICT",u.getSnapshot().error||"Your current draft has content. Choose Swap or Merge"),d.replace(g,r)||m("STALE_ACTIVATION","The composer changed; refresh before restoring"),f=null,d.focus(),null},"drafts.remove"({token:r,id:s}){const{store:c}=I(r,!0);return c.remove(s)||m("CONFLICT",c.getSnapshot().error||"The draft could not be deleted"),null},"drafts.backup"({token:r}){const{store:s}=I(r);return le(s),p.set(s,s.getSnapshot()),null},"drafts.recover"({token:r,action:s}){const{store:c}=I(r,!0);return s==="reset"&&p.get(c)!==c.getSnapshot()&&m("CONFLICT","Download the current backup before resetting damaged storage"),(s==="retry"?c.retry(o.inScope):s==="reset"?c.resetAfterBackup():c.markUpload(!1))||m("CONFLICT",c.getSnapshot().error||"Storage is unavailable"),null}},W=ee(r=>{if(w(),r.type==="scope"||r.type==="change"){const s=O();s&&o.inScope(r.snapshot.scope.cwd)&&_(s,r.snapshot,r.type==="scope"),f&&f.token!==r.snapshot.token&&(f=null),v()}else if(r.type==="rejected-input"){if(!o.inScope(r.scope.cwd))return;N(r.scope.key).retainImport(r.text),v()}else if(r.type==="before-send"){if(!o.inScope(r.scope.cwd))return;f=null;const s=N(r.scope.key),c=s.save(r.draft,"sending");c&&a.set(r.sendId,{store:s,id:c,cwd:r.scope.cwd,pendingIdentity:JSON.parse(r.scope.identity)[1]==="pending"})}else if(r.type==="created"){const s=a.get(r.sendId);s&&o.inScope(s.cwd)&&(s.store.created(s.id,r.session,o.inScope),s.pendingIdentity=!1,s.settled&&a.delete(r.sendId))}else if(r.type==="settled"){const s=a.get(r.sendId);s&&o.inScope(s.cwd)&&(s.store.settle(s.id,r.sent,!1,o.inScope),s.settled=!0,(!r.sent||!s.pendingIdentity)&&a.delete(r.sendId)),v()}}),Z=te((r,s)=>{var b;w();const c=s.snapshot();if(!o.inScope(c.scope.cwd))return!1;if((r.ctrlKey||r.metaKey)&&r.shiftKey&&!r.altKey&&r.key.toLowerCase()==="s"&&!r.isComposing){try{j(c.token,!0)}catch{v()}return!0}const d=(f==null?void 0:f.scope)===c.scope.key&&f.token===c.token;if(c.busy||!pe(r,r.selectionStart,r.selectionEnd,c.draft,d,r.suggestionsOpen))return!1;const l=R(c).getSnapshot().record.entries.filter(H=>H.kind==="sent").reverse(),u=d?f.index:null,g=r.key==="ArrowUp"?Math.min((u??-1)+1,l.length-1):Math.max((u??0)-1,-1);if(!l.length||r.key==="ArrowDown"&&u===null)return!1;const S=s.replace(((b=l[g])==null?void 0:b.draft)??U,c.token);return S?(f=g<0?null:{scope:c.scope.key,index:g,token:S.token},s.focus(),!0):!1});function B(){if(!h){h=!0,W(),Z();for(const r of i.values())r();i.clear(),t.clear(),a.clear(),p.clear(),o.signal.removeEventListener("abort",B)}}o.signal.addEventListener("abort",B,{once:!0});const x=O();return x&&o.inScope(x.snapshot().scope.cwd)&&_(x,x.snapshot(),!0),{async request(r,s,c){return w(),c.throwIfAborted(),P[r](s)},onTokenChange(r){return t.add(r),()=>{t.delete(r)}},dispose:B}}export{ye as activate};
@@ -1,5 +1,5 @@
1
- import{c as le,j as t,r as fe}from"./vendor-react-gGw_S5I_.js";import{g as Ne,c as ke,C as ge,a as pe,b as je,d as ve,B as V,e as ye,p as Te,E as be,f as Ce,h as _e,i as Be,D as Me,j as we,k as Ae,l as $e,S as de,m as Se,n as Ie,o as Re}from"./index-Bg4A-xl7.js";import{bJ as me,c9 as Ee,bp as De,A as ze}from"./vendor-ui-Dc_kJXxz.js";import"./vendor-markdown-BEJ8yVzA.js";function He(a){const e=le.c(29),{branches:s,activeBranchIdx:c,branchPointTurnIndex:f}=a,g=s.length;if(g===0)return null;const j=Math.min(f+1,5);let h;e[0]!==s?(h=Math.max(...s.map(Pe),1),e[0]=s,e[1]=h):h=e[1];const o=Math.min(h,6),n=20+j*25,r=Math.min(32,Math.max(20,(300-n)/(o+1))),d=18+(g-1)*27+15,m=`0 0 340 ${d}`,p=`${g} branches from turn ${f+1}`;let l;e[2]!==n?(l=t.jsx("line",{x1:20,y1:18,x2:n,y2:18,stroke:"var(--muted-foreground)",strokeWidth:2}),e[2]=n,e[3]=l):l=e[3];let u;e[4]!==j?(u=Array.from({length:j}).map(Le),e[4]=j,e[5]=u):u=e[5];let k,b;e[6]!==n?(k=t.jsx("circle",{cx:n,cy:18,r:5,fill:"var(--background)",stroke:"var(--foreground)",strokeWidth:2}),b=t.jsx("circle",{cx:n,cy:18,r:2,fill:"var(--foreground)"}),e[6]=n,e[7]=k,e[8]=b):(k=e[7],b=e[8]);let T;if(e[9]!==c||e[10]!==n||e[11]!==s||e[12]!==o||e[13]!==r){let w;e[15]!==c||e[16]!==n||e[17]!==o||e[18]!==r?(w=(i,C)=>{const v=C===c,_=v?"var(--foreground)":"var(--border)",$=v?"var(--foreground)":"var(--border)",N=18+C*27,A=Math.min(i.graphTurnCount,o);return t.jsxs("g",{style:{opacity:v?1:.3},children:[C===0?t.jsx("line",{x1:n,y1:N,x2:n+A*r,y2:N,stroke:_,strokeWidth:2}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:`M ${n} 18 C ${n+10} ${N-5}, ${n+20} ${N}, ${n+r} ${N}`,fill:"none",stroke:_,strokeWidth:2}),A>1&&t.jsx("line",{x1:n+r,y1:N,x2:n+A*r,y2:N,stroke:_,strokeWidth:2})]}),Array.from({length:A}).map((R,S)=>t.jsxs("g",{children:[t.jsx("circle",{cx:n+(S+1)*r,cy:N,r:3.5,fill:"var(--background)",stroke:_,strokeWidth:1.5}),t.jsx("circle",{cx:n+(S+1)*r,cy:N,r:1.5,fill:$})]},S)),i.graphTurnCount>o&&t.jsxs("text",{x:n+(A+.4)*r,y:N+3,fill:v?"var(--foreground)":"var(--border)",fontSize:"8",fontFamily:"monospace",children:["+",i.graphTurnCount-o]})]},i.id)},e[15]=c,e[16]=n,e[17]=o,e[18]=r,e[19]=w):w=e[19],T=s.map(w),e[9]=c,e[10]=n,e[11]=s,e[12]=o,e[13]=r,e[14]=T}else T=e[14];let M;return e[20]!==d||e[21]!==m||e[22]!==p||e[23]!==l||e[24]!==u||e[25]!==k||e[26]!==b||e[27]!==T?(M=t.jsx("div",{className:"rounded-lg border bg-muted/20 px-3 py-2",children:t.jsxs("svg",{width:"100%",height:d,viewBox:m,role:"img","aria-label":p,children:[l,u,k,b,T]})}),e[20]=d,e[21]=m,e[22]=p,e[23]=l,e[24]=u,e[25]=k,e[26]=b,e[27]=T,e[28]=M):M=e[28],M}function Le(a,e){return t.jsxs("g",{children:[t.jsx("circle",{cx:20+e*25,cy:18,r:3.5,fill:"var(--background)",stroke:"var(--muted-foreground)",strokeWidth:1.5}),t.jsx("circle",{cx:20+e*25,cy:18,r:1.5,fill:"var(--muted-foreground)"})]},`s-${e}`)}function Pe(a){return a.graphTurnCount}function We(a){const e=a.input.file_path??a.input.path??"";if(e)return e.split("/").pop()||e;const s=a.input.command;if(s)return s.length>40?s.slice(0,37)+"...":s;const c=a.input.pattern;if(c)return c.length>30?c.slice(0,27)+"...":c;const f=a.input.query;return f?f.length>30?f.slice(0,27)+"...":f:""}function Fe(a){const e=le.c(26),{turn:s,archiveIndex:c,branchId:f,onRedoToHere:g}=a;let j;e[0]!==s.userMessage?(j=typeof s.userMessage=="string"?s.userMessage:Array.isArray(s.userMessage)?s.userMessage.flatMap(qe).join(`
1
+ import{c as le,j as t,r as fe}from"./vendor-react-gGw_S5I_.js";import{g as Ne,c as ke,C as ge,a as pe,b as je,d as ve,B as V,e as ye,p as Te,E as be,f as Ce,h as _e,i as Be,D as Me,j as we,k as Ae,l as $e,S as de,m as Se,n as Ie,o as Re}from"./index-Dv2TZ38C.js";import{bL as me,ca as Ee,br as De,A as ze}from"./vendor-ui-ClPj6-Gu.js";import"./vendor-markdown-BEJ8yVzA.js";function Le(a){const e=le.c(29),{branches:s,activeBranchIdx:c,branchPointTurnIndex:f}=a,g=s.length;if(g===0)return null;const j=Math.min(f+1,5);let h;e[0]!==s?(h=Math.max(...s.map(Pe),1),e[0]=s,e[1]=h):h=e[1];const o=Math.min(h,6),n=20+j*25,r=Math.min(32,Math.max(20,(300-n)/(o+1))),d=18+(g-1)*27+15,m=`0 0 340 ${d}`,p=`${g} branches from turn ${f+1}`;let l;e[2]!==n?(l=t.jsx("line",{x1:20,y1:18,x2:n,y2:18,stroke:"var(--muted-foreground)",strokeWidth:2}),e[2]=n,e[3]=l):l=e[3];let u;e[4]!==j?(u=Array.from({length:j}).map(He),e[4]=j,e[5]=u):u=e[5];let k,b;e[6]!==n?(k=t.jsx("circle",{cx:n,cy:18,r:5,fill:"var(--background)",stroke:"var(--foreground)",strokeWidth:2}),b=t.jsx("circle",{cx:n,cy:18,r:2,fill:"var(--foreground)"}),e[6]=n,e[7]=k,e[8]=b):(k=e[7],b=e[8]);let T;if(e[9]!==c||e[10]!==n||e[11]!==s||e[12]!==o||e[13]!==r){let w;e[15]!==c||e[16]!==n||e[17]!==o||e[18]!==r?(w=(i,C)=>{const v=C===c,_=v?"var(--foreground)":"var(--border)",$=v?"var(--foreground)":"var(--border)",N=18+C*27,A=Math.min(i.graphTurnCount,o);return t.jsxs("g",{style:{opacity:v?1:.3},children:[C===0?t.jsx("line",{x1:n,y1:N,x2:n+A*r,y2:N,stroke:_,strokeWidth:2}):t.jsxs(t.Fragment,{children:[t.jsx("path",{d:`M ${n} 18 C ${n+10} ${N-5}, ${n+20} ${N}, ${n+r} ${N}`,fill:"none",stroke:_,strokeWidth:2}),A>1&&t.jsx("line",{x1:n+r,y1:N,x2:n+A*r,y2:N,stroke:_,strokeWidth:2})]}),Array.from({length:A}).map((R,S)=>t.jsxs("g",{children:[t.jsx("circle",{cx:n+(S+1)*r,cy:N,r:3.5,fill:"var(--background)",stroke:_,strokeWidth:1.5}),t.jsx("circle",{cx:n+(S+1)*r,cy:N,r:1.5,fill:$})]},S)),i.graphTurnCount>o&&t.jsxs("text",{x:n+(A+.4)*r,y:N+3,fill:v?"var(--foreground)":"var(--border)",fontSize:"8",fontFamily:"monospace",children:["+",i.graphTurnCount-o]})]},i.id)},e[15]=c,e[16]=n,e[17]=o,e[18]=r,e[19]=w):w=e[19],T=s.map(w),e[9]=c,e[10]=n,e[11]=s,e[12]=o,e[13]=r,e[14]=T}else T=e[14];let M;return e[20]!==d||e[21]!==m||e[22]!==p||e[23]!==l||e[24]!==u||e[25]!==k||e[26]!==b||e[27]!==T?(M=t.jsx("div",{className:"rounded-lg border bg-muted/20 px-3 py-2",children:t.jsxs("svg",{width:"100%",height:d,viewBox:m,role:"img","aria-label":p,children:[l,u,k,b,T]})}),e[20]=d,e[21]=m,e[22]=p,e[23]=l,e[24]=u,e[25]=k,e[26]=b,e[27]=T,e[28]=M):M=e[28],M}function He(a,e){return t.jsxs("g",{children:[t.jsx("circle",{cx:20+e*25,cy:18,r:3.5,fill:"var(--background)",stroke:"var(--muted-foreground)",strokeWidth:1.5}),t.jsx("circle",{cx:20+e*25,cy:18,r:1.5,fill:"var(--muted-foreground)"})]},`s-${e}`)}function Pe(a){return a.graphTurnCount}function We(a){const e=a.input.file_path??a.input.path??"";if(e)return e.split("/").pop()||e;const s=a.input.command;if(s)return s.length>40?s.slice(0,37)+"...":s;const c=a.input.pattern;if(c)return c.length>30?c.slice(0,27)+"...":c;const f=a.input.query;return f?f.length>30?f.slice(0,27)+"...":f:""}function Fe(a){const e=le.c(26),{turn:s,archiveIndex:c,branchId:f,onRedoToHere:g}=a;let j;e[0]!==s.userMessage?(j=typeof s.userMessage=="string"?s.userMessage:Array.isArray(s.userMessage)?s.userMessage.flatMap(qe).join(`
2
2
  `):null,e[0]=s.userMessage,e[1]=j):j=e[1];const h=j,y=c+1;let o;e[2]!==y?(o=t.jsx(ge,{className:"border-b py-2",children:t.jsxs(pe,{children:["Turn ",y]})}),e[2]=y,e[3]=o):o=e[3];let n;e[4]!==h?(n=h&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"You"}),t.jsx("div",{className:"text-sm text-foreground",children:h})]}),e[4]=h,e[5]=n):n=e[5];let r;e[6]!==s.thinking[0]||e[7]!==s.thinking.length?(r=s.thinking.length>0&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Thinking"}),t.jsxs("div",{className:"text-xs text-muted-foreground italic",children:[s.thinking[0].thinking.slice(0,300),s.thinking[0].thinking.length>300?"...":""]})]}),e[6]=s.thinking[0],e[7]=s.thinking.length,e[8]=r):r=e[8];let d;e[9]!==s.assistantText?(d=s.assistantText.length>0&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-success",children:"Assistant"}),t.jsx("div",{className:"text-sm text-muted-foreground",children:s.assistantText.join(`
3
3
  `)})]}),e[9]=s.assistantText,e[10]=d):d=e[10];let m;e[11]!==s.toolCalls?(m=s.toolCalls.length>0&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Tools"}),t.jsx("div",{className:"flex flex-wrap gap-x-2 gap-y-1",children:s.toolCalls.map(Oe)})]}),e[11]=s.toolCalls,e[12]=m):m=e[12];let p;e[13]!==n||e[14]!==r||e[15]!==d||e[16]!==m?(p=t.jsxs(je,{className:"flex flex-col gap-3 py-3",children:[n,r,d,m]}),e[13]=n,e[14]=r,e[15]=d,e[16]=m,e[17]=p):p=e[17];let l;e[18]!==c||e[19]!==f||e[20]!==g?(l=g&&t.jsx(ve,{className:"justify-end py-2",children:t.jsxs(V,{variant:"ghost",size:"sm",onClick:()=>g(f,c),children:[t.jsx(me,{"data-icon":"inline-start",className:"scale-x-[-1]"}),"Redo to here"]})}),e[18]=c,e[19]=f,e[20]=g,e[21]=l):l=e[21];let u;return e[22]!==o||e[23]!==p||e[24]!==l?(u=t.jsxs(ye,{size:"sm",className:"motion-list-item gap-0 py-0",children:[o,p,l]}),e[22]=o,e[23]=p,e[24]=l,e[25]=u):u=e[25],u}function Oe(a){const e=Ne(a),s=We(a)||e.summary;return t.jsxs("span",{className:ke("font-mono text-xs text-muted-foreground",a.isError&&"text-destructive"),children:[e.label,s?` ${s}`:""]},a.id)}function qe(a){return a.type==="text"?[a.text]:[]}function Ge(a){const e=le.c(27),{turn:s,archiveIndex:c,branchId:f,onRedoToHere:g}=a,j=c+1;let h;e[0]!==j?(h=t.jsx(ge,{className:"border-b py-2",children:t.jsxs(pe,{children:["Turn ",j]})}),e[0]=j,e[1]=h):h=e[1];let y;e[2]!==s.userMessage?(y=s.userMessage&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"You"}),t.jsx("div",{className:"text-sm text-foreground",children:s.userMessage})]}),e[2]=s.userMessage,e[3]=y):y=e[3];let o;e[4]!==s.thinkingBlocks[0]||e[5]!==s.thinkingBlocks.length?(o=s.thinkingBlocks.length>0&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Thinking"}),t.jsxs("div",{className:"text-xs text-muted-foreground italic",children:[s.thinkingBlocks[0].slice(0,300),"..."]})]}),e[4]=s.thinkingBlocks[0],e[5]=s.thinkingBlocks.length,e[6]=o):o=e[6];let n;e[7]!==s.assistantText?(n=s.assistantText.length>0&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-success",children:"Assistant"}),t.jsx("div",{className:"text-sm text-muted-foreground",children:s.assistantText.join(`
4
4
  `)})]}),e[7]=s.assistantText,e[8]=n):n=e[8];let r;e[9]!==s.toolCalls?(r=s.toolCalls.length>0&&t.jsxs("div",{className:"grid grid-cols-[5rem_minmax(0,1fr)] items-start gap-3",children:[t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Tools"}),t.jsx("div",{className:"flex flex-wrap gap-x-2 gap-y-1",children:s.toolCalls.map(Ye)})]}),e[9]=s.toolCalls,e[10]=r):r=e[10];let d;e[11]!==y||e[12]!==o||e[13]!==n||e[14]!==r?(d=t.jsxs(je,{className:"flex flex-col gap-3 py-3",children:[y,o,n,r]}),e[11]=y,e[12]=o,e[13]=n,e[14]=r,e[15]=d):d=e[15];let m;e[16]!==c||e[17]!==f||e[18]!==g?(m=()=>g(f,c),e[16]=c,e[17]=f,e[18]=g,e[19]=m):m=e[19];let p;e[20]===Symbol.for("react.memo_cache_sentinel")?(p=t.jsx(me,{"data-icon":"inline-start",className:"scale-x-[-1]"}),e[20]=p):p=e[20];let l;e[21]!==m?(l=t.jsx(ve,{className:"justify-end py-2",children:t.jsxs(V,{variant:"ghost",size:"sm",onClick:m,children:[p,"Redo to here"]})}),e[21]=m,e[22]=l):l=e[22];let u;return e[23]!==l||e[24]!==h||e[25]!==d?(u=t.jsxs(ye,{size:"sm",className:"motion-list-item gap-0 py-0",children:[h,d,l]}),e[23]=l,e[24]=h,e[25]=d,e[26]=u):u=e[26],u}function Ye(a,e){return t.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[a.type," ",a.filePath.split("/").pop()]},e)}function Ue(a){var xe,he,ue;const e=le.c(88),{open:s,branches:c,branchPointTurnIndex:f,currentTurns:g,onClose:j,onCloseComplete:h,onRedoToTurn:y,onRedoEntireBranch:o}=a,n=s===void 0?!0:s;let r;if(e[0]!==c||e[1]!==g){r=[];let x;e[3]===Symbol.for("react.memo_cache_sentinel")?(x=new Date().toISOString(),e[3]=x):x=e[3];let B;e[4]!==g?(B={kind:"current",id:"__current__",label:"Current branch",createdAt:x,fullTurns:g,archivedTurns:null,graphTurnCount:g.length,branch:null},e[4]=g,e[5]=B):B=e[5],r.push(B);for(const I of c){let U=null;if(I.jsonlLines.length>0)try{U=Te(I.jsonlLines.join(`
5
- `)).turns}catch{}r.push({kind:"archived",id:I.id,label:I.label,createdAt:I.createdAt,fullTurns:U,archivedTurns:U?null:I.turns,graphTurnCount:U?U.length:I.turns.length,branch:I})}e[0]=c,e[1]=g,e[2]=r}else r=e[2];const d=r,[m,p]=fe.useState(0),l=d.length;let u;e[6]!==l?(u=()=>{p(x=>x>0?x-1:l-1)},e[6]=l,e[7]=u):u=e[7];const k=u;let b;e[8]!==l?(b=()=>{p(x=>x<l-1?x+1:0)},e[8]=l,e[9]=b):b=e[9];const T=b;let M,w;e[10]!==T||e[11]!==k?(M=()=>{const x=B=>{B.key==="ArrowLeft"?k():B.key==="ArrowRight"&&T()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},w=[k,T],e[10]=T,e[11]=k,e[12]=M,e[13]=w):(M=e[12],w=e[13]),fe.useEffect(M,w);const i=d[m];if(!i)return null;const C=((xe=i.fullTurns)==null?void 0:xe.length)??((he=i.archivedTurns)==null?void 0:he.length)??0,v=i.kind==="current";let _;e[14]!==j?(_=x=>{x||j()},e[14]=j,e[15]=_):_=e[15];let $;e[16]!==h?($=x=>{x||h==null||h()},e[16]=h,e[17]=$):$=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(Ee,{className:"size-4"}),e[18]=N):N=e[18];const A=f+1;let R;e[19]!==A?(R=t.jsx("div",{className:"flex items-center justify-between gap-3",children:t.jsxs(Me,{className:"flex items-center gap-2",children:[N,"Branches from Turn ",A]})}),e[19]=A,e[20]=R):R=e[20];let S;e[21]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(we,{children:"Compare alternate continuations and resume from an earlier point."}),e[21]=S):S=e[21];const ie=l<=1;let Z;e[22]===Symbol.for("react.memo_cache_sentinel")?(Z=t.jsx(De,{"data-icon":"inline-start"}),e[22]=Z):Z=e[22];let E;e[23]!==k||e[24]!==ie?(E=t.jsx(V,{variant:"ghost",size:"icon-sm",onClick:k,disabled:ie,"aria-label":"Previous branch",children:Z}),e[23]=k,e[24]=ie,e[25]=E):E=e[25];let D;e[26]!==v?(D=v&&t.jsx(Ae,{variant:"secondary",className:"ml-2",children:"Active"}),e[26]=v,e[27]=D):D=e[27];let z;e[28]!==i.label||e[29]!==D?(z=t.jsxs("div",{className:"truncate text-sm font-medium",children:[i.label,D]}),e[28]=i.label,e[29]=D,e[30]=z):z=e[30];const ae=m+1;let H;e[31]!==i.createdAt||e[32]!==v?(H=!v&&t.jsxs(t.Fragment,{children:[" · ",new Date(i.createdAt).toLocaleString()]}),e[31]=i.createdAt,e[32]=v,e[33]=H):H=e[33];let L;e[34]!==ae||e[35]!==H||e[36]!==l?(L=t.jsxs("div",{className:"text-xs text-muted-foreground",children:["Branch ",ae," of ",l,H]}),e[34]=ae,e[35]=H,e[36]=l,e[37]=L):L=e[37];let P;e[38]!==z||e[39]!==L?(P=t.jsxs("div",{className:"flex-1 text-center",children:[z,L]}),e[38]=z,e[39]=L,e[40]=P):P=e[40];const oe=l<=1;let ee;e[41]===Symbol.for("react.memo_cache_sentinel")?(ee=t.jsx(ze,{"data-icon":"inline-start"}),e[41]=ee):ee=e[41];let W;e[42]!==T||e[43]!==oe?(W=t.jsx(V,{variant:"ghost",size:"icon-sm",onClick:T,disabled:oe,"aria-label":"Next branch",children:ee}),e[42]=T,e[43]=oe,e[44]=W):W=e[44];let F;e[45]!==E||e[46]!==P||e[47]!==W?(F=t.jsxs("div",{className:"flex items-center gap-3 pt-3",children:[E,P,W]}),e[45]=E,e[46]=P,e[47]=W,e[48]=F):F=e[48];let O;e[49]!==R||e[50]!==F?(O=t.jsxs($e,{className:"shrink-0 p-5 pb-4 pr-14",children:[R,S,F]}),e[49]=R,e[50]=F,e[51]=O):O=e[51];let te;e[52]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(de,{}),e[52]=te):te=e[52];let q;e[53]!==f||e[54]!==m||e[55]!==d?(q=t.jsx("div",{className:"shrink-0 px-5 py-4",children:t.jsx(He,{branches:d,activeBranchIdx:m,branchPointTurnIndex:f})}),e[53]=f,e[54]=m,e[55]=d,e[56]=q):q=e[56];let se;e[57]===Symbol.for("react.memo_cache_sentinel")?(se=t.jsx(de,{}),e[57]=se):se=e[57];let G;e[58]!==i.archivedTurns||e[59]!==i.fullTurns||e[60]!==i.id||e[61]!==v||e[62]!==y||e[63]!==C?(G=C===0?t.jsx(be,{className:"min-h-40",children:t.jsxs(Ce,{children:[t.jsx(_e,{children:"No turns in this branch"}),t.jsx(Be,{children:"This continuation has no saved turns."})]})}):i.fullTurns?i.fullTurns.map((x,B)=>t.jsx(Fe,{turn:x,archiveIndex:B,branchId:i.id,onRedoToHere:v?void 0:y},x.id)):(ue=i.archivedTurns)==null?void 0:ue.map((x,B)=>t.jsx(Ge,{turn:x,archiveIndex:B,branchId:i.id,onRedoToHere:y},x.index)),e[58]=i.archivedTurns,e[59]=i.fullTurns,e[60]=i.id,e[61]=v,e[62]=y,e[63]=C,e[64]=G):G=e[64];let Y;e[65]!==G?(Y=t.jsx(Se,{className:"min-h-0 flex-1",children:t.jsx("div",{className:"flex flex-col gap-3 p-4",children:G})}),e[65]=G,e[66]=Y):Y=e[66];let ne;e[67]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(de,{}),e[67]=ne):ne=e[67];const ce=C!==1?"s":"";let J;e[68]!==ce||e[69]!==C?(J=t.jsxs("span",{className:"text-xs text-muted-foreground",children:[C," turn",ce," in this branch"]}),e[68]=ce,e[69]=C,e[70]=J):J=e[70];let X;e[71]!==i.id||e[72]!==v||e[73]!==o?(X=!v&&t.jsxs(V,{size:"sm",onClick:()=>o(i.id),children:[t.jsx(me,{"data-icon":"inline-start",className:"scale-x-[-1]"}),"Redo entire branch"]}),e[71]=i.id,e[72]=v,e[73]=o,e[74]=X):X=e[74];let K;e[75]!==J||e[76]!==X?(K=t.jsxs("div",{className:"flex shrink-0 items-center justify-between p-4",children:[J,X]}),e[75]=J,e[76]=X,e[77]=K):K=e[77];let Q;e[78]!==O||e[79]!==q||e[80]!==Y||e[81]!==K?(Q=t.jsxs(Ie,{className:"flex max-h-[80dvh] flex-col gap-0 overflow-hidden p-0 sm:max-w-2xl",children:[O,te,q,se,Y,ne,K]}),e[78]=O,e[79]=q,e[80]=Y,e[81]=K,e[82]=Q):Q=e[82];let re;return e[83]!==n||e[84]!==Q||e[85]!==_||e[86]!==$?(re=t.jsx(Re,{open:n,onOpenChange:_,onOpenChangeComplete:$,children:Q}),e[83]=n,e[84]=Q,e[85]=_,e[86]=$,e[87]=re):re=e[87],re}export{Ue as BranchModal};
5
+ `)).turns}catch{}r.push({kind:"archived",id:I.id,label:I.label,createdAt:I.createdAt,fullTurns:U,archivedTurns:U?null:I.turns,graphTurnCount:U?U.length:I.turns.length,branch:I})}e[0]=c,e[1]=g,e[2]=r}else r=e[2];const d=r,[m,p]=fe.useState(0),l=d.length;let u;e[6]!==l?(u=()=>{p(x=>x>0?x-1:l-1)},e[6]=l,e[7]=u):u=e[7];const k=u;let b;e[8]!==l?(b=()=>{p(x=>x<l-1?x+1:0)},e[8]=l,e[9]=b):b=e[9];const T=b;let M,w;e[10]!==T||e[11]!==k?(M=()=>{const x=B=>{B.key==="ArrowLeft"?k():B.key==="ArrowRight"&&T()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},w=[k,T],e[10]=T,e[11]=k,e[12]=M,e[13]=w):(M=e[12],w=e[13]),fe.useEffect(M,w);const i=d[m];if(!i)return null;const C=((xe=i.fullTurns)==null?void 0:xe.length)??((he=i.archivedTurns)==null?void 0:he.length)??0,v=i.kind==="current";let _;e[14]!==j?(_=x=>{x||j()},e[14]=j,e[15]=_):_=e[15];let $;e[16]!==h?($=x=>{x||h==null||h()},e[16]=h,e[17]=$):$=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=t.jsx(Ee,{className:"size-4"}),e[18]=N):N=e[18];const A=f+1;let R;e[19]!==A?(R=t.jsx("div",{className:"flex items-center justify-between gap-3",children:t.jsxs(Me,{className:"flex items-center gap-2",children:[N,"Branches from Turn ",A]})}),e[19]=A,e[20]=R):R=e[20];let S;e[21]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(we,{children:"Compare alternate continuations and resume from an earlier point."}),e[21]=S):S=e[21];const ie=l<=1;let Z;e[22]===Symbol.for("react.memo_cache_sentinel")?(Z=t.jsx(De,{"data-icon":"inline-start"}),e[22]=Z):Z=e[22];let E;e[23]!==k||e[24]!==ie?(E=t.jsx(V,{variant:"ghost",size:"icon-sm",onClick:k,disabled:ie,"aria-label":"Previous branch",children:Z}),e[23]=k,e[24]=ie,e[25]=E):E=e[25];let D;e[26]!==v?(D=v&&t.jsx(Ae,{variant:"secondary",className:"ml-2",children:"Active"}),e[26]=v,e[27]=D):D=e[27];let z;e[28]!==i.label||e[29]!==D?(z=t.jsxs("div",{className:"truncate text-sm font-medium",children:[i.label,D]}),e[28]=i.label,e[29]=D,e[30]=z):z=e[30];const ae=m+1;let L;e[31]!==i.createdAt||e[32]!==v?(L=!v&&t.jsxs(t.Fragment,{children:[" · ",new Date(i.createdAt).toLocaleString()]}),e[31]=i.createdAt,e[32]=v,e[33]=L):L=e[33];let H;e[34]!==ae||e[35]!==L||e[36]!==l?(H=t.jsxs("div",{className:"text-xs text-muted-foreground",children:["Branch ",ae," of ",l,L]}),e[34]=ae,e[35]=L,e[36]=l,e[37]=H):H=e[37];let P;e[38]!==z||e[39]!==H?(P=t.jsxs("div",{className:"flex-1 text-center",children:[z,H]}),e[38]=z,e[39]=H,e[40]=P):P=e[40];const oe=l<=1;let ee;e[41]===Symbol.for("react.memo_cache_sentinel")?(ee=t.jsx(ze,{"data-icon":"inline-start"}),e[41]=ee):ee=e[41];let W;e[42]!==T||e[43]!==oe?(W=t.jsx(V,{variant:"ghost",size:"icon-sm",onClick:T,disabled:oe,"aria-label":"Next branch",children:ee}),e[42]=T,e[43]=oe,e[44]=W):W=e[44];let F;e[45]!==E||e[46]!==P||e[47]!==W?(F=t.jsxs("div",{className:"flex items-center gap-3 pt-3",children:[E,P,W]}),e[45]=E,e[46]=P,e[47]=W,e[48]=F):F=e[48];let O;e[49]!==R||e[50]!==F?(O=t.jsxs($e,{className:"shrink-0 p-5 pb-4 pr-14",children:[R,S,F]}),e[49]=R,e[50]=F,e[51]=O):O=e[51];let te;e[52]===Symbol.for("react.memo_cache_sentinel")?(te=t.jsx(de,{}),e[52]=te):te=e[52];let q;e[53]!==f||e[54]!==m||e[55]!==d?(q=t.jsx("div",{className:"shrink-0 px-5 py-4",children:t.jsx(Le,{branches:d,activeBranchIdx:m,branchPointTurnIndex:f})}),e[53]=f,e[54]=m,e[55]=d,e[56]=q):q=e[56];let se;e[57]===Symbol.for("react.memo_cache_sentinel")?(se=t.jsx(de,{}),e[57]=se):se=e[57];let G;e[58]!==i.archivedTurns||e[59]!==i.fullTurns||e[60]!==i.id||e[61]!==v||e[62]!==y||e[63]!==C?(G=C===0?t.jsx(be,{className:"min-h-40",children:t.jsxs(Ce,{children:[t.jsx(_e,{children:"No turns in this branch"}),t.jsx(Be,{children:"This continuation has no saved turns."})]})}):i.fullTurns?i.fullTurns.map((x,B)=>t.jsx(Fe,{turn:x,archiveIndex:B,branchId:i.id,onRedoToHere:v?void 0:y},x.id)):(ue=i.archivedTurns)==null?void 0:ue.map((x,B)=>t.jsx(Ge,{turn:x,archiveIndex:B,branchId:i.id,onRedoToHere:y},x.index)),e[58]=i.archivedTurns,e[59]=i.fullTurns,e[60]=i.id,e[61]=v,e[62]=y,e[63]=C,e[64]=G):G=e[64];let Y;e[65]!==G?(Y=t.jsx(Se,{className:"min-h-0 flex-1",children:t.jsx("div",{className:"flex flex-col gap-3 p-4",children:G})}),e[65]=G,e[66]=Y):Y=e[66];let ne;e[67]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(de,{}),e[67]=ne):ne=e[67];const ce=C!==1?"s":"";let X;e[68]!==ce||e[69]!==C?(X=t.jsxs("span",{className:"text-xs text-muted-foreground",children:[C," turn",ce," in this branch"]}),e[68]=ce,e[69]=C,e[70]=X):X=e[70];let J;e[71]!==i.id||e[72]!==v||e[73]!==o?(J=!v&&t.jsxs(V,{size:"sm",onClick:()=>o(i.id),children:[t.jsx(me,{"data-icon":"inline-start",className:"scale-x-[-1]"}),"Redo entire branch"]}),e[71]=i.id,e[72]=v,e[73]=o,e[74]=J):J=e[74];let K;e[75]!==X||e[76]!==J?(K=t.jsxs("div",{className:"flex shrink-0 items-center justify-between p-4",children:[X,J]}),e[75]=X,e[76]=J,e[77]=K):K=e[77];let Q;e[78]!==O||e[79]!==q||e[80]!==Y||e[81]!==K?(Q=t.jsxs(Ie,{className:"flex max-h-[80dvh] flex-col gap-0 overflow-hidden p-0 sm:max-w-2xl",children:[O,te,q,se,Y,ne,K]}),e[78]=O,e[79]=q,e[80]=Y,e[81]=K,e[82]=Q):Q=e[82];let re;return e[83]!==n||e[84]!==Q||e[85]!==_||e[86]!==$?(re=t.jsx(Re,{open:n,onOpenChange:_,onOpenChangeComplete:$,children:Q}),e[83]=n,e[84]=Q,e[85]=_,e[86]=$,e[87]=re):re=e[87],re}export{Ue as BranchModal};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PluginsDialog-CYiiMArh.js","assets/vendor-react-gGw_S5I_.js","assets/index-Dv2TZ38C.js","assets/vendor-ui-ClPj6-Gu.js","assets/vendor-markdown-BEJ8yVzA.js","assets/index-BtF9zrz_.css"])))=>i.map(i=>d[i]);
2
+ import{ae as G,ac as ie,av as B,az as Nt,aw as kt,ax as Ct,ay as Rt,at as Lt,bx as Ft,B as J,z as Ut,by as $t,c as bt,F as le,bz as At,y as lt,A as at,au as gt,Z as ot,k as Pe,bA as Bt,bB as Mt,bC as Ht,bD as Gt,bE as Vt,aH as qt,aY as Wt,bF as Xt,bG as Et,bH as Kt,l as Jt,D as Zt,j as Yt,bI as Qt,aC as es,aE as ts,n as ss,o as ns}from"./index-Dv2TZ38C.js";import{c as M,j as t,r as S}from"./vendor-react-gGw_S5I_.js";import{S as _t}from"./switch-mgfHveYR.js";import{bE as is,aG as ls,dn as as,dp as os,dq as rs,dr as cs,d3 as ds,C as us,A as fs,cW as ms,L as rt,af as hs,ds as xs,V as ps,bv as gs,bo as js,aJ as bs,cZ as vs,c3 as ws,aC as Ss,aZ as ys}from"./vendor-ui-ClPj6-Gu.js";import{P as vt}from"./password-BV9mqUzz.js";import"./vendor-markdown-BEJ8yVzA.js";function Ns(s){const e=M.c(3),{name:n}=s,i=n.toLowerCase();if(i.includes("iphone")||i.includes("android")){let d;return e[0]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(as,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[0]=d):d=e[0],d}if(i.includes("ipad")||i.includes("tablet")){let d;return e[1]===Symbol.for("react.memo_cache_sentinel")?(d=t.jsx(os,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[1]=d):d=e[1],d}let l;return e[2]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx(rs,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[2]=l):l=e[2],l}function jt(s){const e=Math.floor((Date.now()-s)/1e3);if(e<60)return"just now";const n=Math.floor(e/60);if(n<60)return`${n}m ago`;const i=Math.floor(n/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function ks(s){const e=[`Shared ${jt(s.createdAt)}`,s.lastAccessAt>0?`opened ${jt(s.lastAccessAt)}`:"never opened"];return s.guests>0&&e.push(s.guests===1?"1 guest":`${s.guests} guests`),e.join(" · ")}function Cs(){const s=M.c(12),{shares:e,revoke:n,revokeAll:i}=Ft();let l;s[0]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx("p",{className:"text-xs text-muted-foreground",children:"Shared sessions"}),s[0]=l):l=s[0];let d;s[1]!==i||s[2]!==e.length?(d=e.length>0&&t.jsx(J,{variant:"ghost",size:"xs",className:"text-destructive hover:text-destructive",onClick:()=>void i(),children:"Revoke all"}),s[1]=i,s[2]=e.length,s[3]=d):d=s[3];let a;s[4]!==d?(a=t.jsxs("div",{className:"flex h-6 items-center justify-between",children:[l,d]}),s[4]=d,s[5]=a):a=s[5];let u;s[6]!==n||s[7]!==e?(u=e.length===0?t.jsx("p",{className:"text-xs text-muted-foreground",children:"No sessions are shared."}):t.jsx("div",{className:"flex flex-col gap-1.5",children:e.map(r=>{const h=r.title||r.sessionId;return t.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"truncate text-sm text-foreground",children:h}),t.jsx("p",{className:"text-xs text-muted-foreground",children:ks(r)})]}),t.jsx(J,{variant:"ghost",size:"xs","aria-label":`Revoke share of ${h}`,className:"text-destructive hover:text-destructive",onClick:()=>void n(r.sessionId),children:"Revoke"})]},r.sessionId)})}),s[6]=n,s[7]=e,s[8]=u):u=s[8];let c;return s[9]!==a||s[10]!==u?(c=t.jsxs("div",{className:"flex flex-col gap-2",children:[a,u]}),s[9]=a,s[10]=u,s[11]=c):c=s[11],c}function $s(s){const e=M.c(30),{networkAccess:n,setNetworkAccess:i,networkPassword:l,setNetworkPassword:d,showNetworkPassword:a,setShowNetworkPassword:u,hasExistingPassword:c,initialNetworkAccess:r,connectedDevices:h,minPasswordLength:o}=s;let f;e[0]!==n?(f=n?t.jsx(cs,{"data-icon":"inline-start",className:"size-4 text-success"}):t.jsx(ds,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[0]=n,e[1]=f):f=e[1];let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-medium text-foreground",children:"Network Access"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Allow other devices to connect"})]}),e[2]=m):m=e[2];let j;e[3]!==f?(j=t.jsxs("div",{className:"flex items-center gap-2",children:[f,m]}),e[3]=f,e[4]=j):j=e[4];let w;e[5]!==i?(w=v=>i(v),e[5]=i,e[6]=w):w=e[6];let x;e[7]!==n||e[8]!==w?(x=t.jsx(_t,{"aria-label":"Network Access",checked:n,onCheckedChange:w}),e[7]=n,e[8]=w,e[9]=x):x=e[9];let C;e[10]!==j||e[11]!==x?(C=t.jsxs("div",{className:"flex items-center justify-between",children:[j,x]}),e[10]=j,e[11]=x,e[12]=C):C=e[12];let p;e[13]!==c||e[14]!==o||e[15]!==n||e[16]!==l||e[17]!==d||e[18]!==u||e[19]!==a?(p=n&&t.jsxs(G,{"data-invalid":l.length>0&&l.length<o,children:[t.jsx(ie,{htmlFor:"network-password",children:"Password"}),t.jsx(B,{children:c&&l.length===0?"A password is already set. Leave blank to keep it.":`Use at least ${o} characters.`}),t.jsxs(Nt,{children:[t.jsx(kt,{id:"network-password",type:a?"text":"password",value:l,onChange:v=>d(v.target.value),placeholder:c?"Enter new password to change":"Set a password for remote access"}),t.jsx(Ct,{align:"inline-end",children:t.jsx(Rt,{size:"icon-xs","aria-label":a?"Hide password":"Show password",onClick:()=>u(!a),children:a?t.jsx(is,{"data-icon":"inline-start"}):t.jsx(ls,{"data-icon":"inline-start"})})})]}),l.length>0&&l.length<o&&t.jsxs(Lt,{children:["Password must be at least ",o," characters (",l.length,"/",o,")"]}),t.jsx(B,{children:"Requires app restart. Remote browsers need an HTTPS reverse proxy; port 19384 remains available to Cogpit hubs and device clients."})]}),e[13]=c,e[14]=o,e[15]=n,e[16]=l,e[17]=d,e[18]=u,e[19]=a,e[20]=p):p=e[20];let g;e[21]!==h||e[22]!==r||e[23]!==n?(g=n&&r&&h.length>0&&t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:"Connected devices"}),t.jsx("div",{className:"flex flex-col gap-1.5",children:h.map(As)})]}),e[21]=h,e[22]=r,e[23]=n,e[24]=g):g=e[24];let y;e[25]===Symbol.for("react.memo_cache_sentinel")?(y=t.jsx(Cs,{}),e[25]=y):y=e[25];let N;return e[26]!==C||e[27]!==p||e[28]!==g?(N=t.jsxs("div",{className:"flex flex-col gap-4 border-t pt-5",children:[C,p,g,y]}),e[26]=C,e[27]=p,e[28]=g,e[29]=N):N=e[29],N}function As(s,e){return t.jsxs("div",{className:"flex items-center justify-between rounded-lg border px-3 py-2",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(Ns,{name:s.deviceName}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-foreground",children:s.deviceName}),t.jsx("p",{className:"text-xs text-muted-foreground",children:s.ip})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"size-1.5 rounded-full bg-success"}),t.jsx("span",{className:"text-xs text-muted-foreground",children:jt(s.lastActivity)})]})]},`${s.ip}-${e}`)}const Es=["auto","path","npm","bundled","custom"],xt={source:"auto"},_s=["path","npm","bundled"];function Is(s){return Es.includes(s)}function Ts(s){if(!s||typeof s!="object")return;const{source:e,path:n}=s;if(!(!Is(e)||e==="auto"))return e==="custom"?typeof n=="string"&&n.trim()?{source:e,path:n.trim()}:void 0:{source:e}}function ct(s){const e=M.c(16),{icon:n,title:i,summary:l,open:d}=s;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=t.jsx(J,{type:"button",variant:"ghost",className:"h-auto w-full justify-between px-0 font-medium hover:bg-transparent"}),e[0]=a):a=e[0];let u;e[1]!==n?(u=t.jsx(n,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[1]=n,e[2]=u):u=e[2];let c;e[3]!==u||e[4]!==i?(c=t.jsxs("span",{className:"flex items-center gap-2",children:[u,i]}),e[3]=u,e[4]=i,e[5]=c):c=e[5];let r;e[6]!==l?(r=t.jsx("span",{className:"truncate",children:l}),e[6]=l,e[7]=r):r=e[7];let h;e[8]!==d?(h=d?t.jsx(us,{className:"size-4 shrink-0"}):t.jsx(fs,{className:"size-4 shrink-0"}),e[8]=d,e[9]=h):h=e[9];let o;e[10]!==r||e[11]!==h?(o=t.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs font-normal text-muted-foreground",children:[r,h]}),e[10]=r,e[11]=h,e[12]=o):o=e[12];let f;return e[13]!==c||e[14]!==o?(f=t.jsxs(Ut,{render:a,children:[c,o]}),e[13]=c,e[14]=o,e[15]=f):f=e[15],f}const Te={auto:"Automatic",path:"Installed on PATH",npm:"Global npm install",bundled:"Bundled with Cogpit",custom:"Custom path"};function It(s,e){return e?`v${e} · ${s}`:s}function Ps(s,e){return s===null?"Checking installed binaries…":e?e.version===null?`${e.path} did not report a version — check the path.`:`Now running: ${It(e.path,e.version)}`:"No launchable binary for the saved choice — sessions cannot start."}function zs(s){return s!==null&&s.version!==null}function Ds(s){const e=M.c(82),{kind:n,value:i,onChange:l,disabled:d,reportVersion:a}=s;let u;e[0]!==n?(u=$t(n),e[0]=n,e[1]=u):u=e[1];const{displayName:c}=u,[r,h]=S.useState(null),[o,f]=S.useState(!1),m=`agent-executable-${n}`;let j;e[2]!==n?(j=()=>{let Q=!1;return le(`/api/agent-executable/${n}`).then(Ls).then(W=>{Q||h(W)}).catch(Rs),()=>{Q=!0}},e[2]=n,e[3]=j):j=e[3];let w;e[4]!==n||e[5]!==a?(w=[n,a],e[4]=n,e[5]=a,e[6]=w):w=e[6],S.useEffect(j,w);let x,C,p,g,y,N,v,k,$,_,I,O,A;if(e[7]!==d||e[8]!==c||e[9]!==m||e[10]!==l||e[11]!==o||e[12]!==(r==null?void 0:r.active)||e[13]!==(r==null?void 0:r.candidates)||e[14]!==i.path||e[15]!==i.source){const Q=new Map((r==null?void 0:r.candidates.map(Os))??[]);g=(r==null?void 0:r.active)??null;let W;e[29]!==d||e[30]!==m||e[31]!==l||e[32]!==i.path||e[33]!==i.source?(W=(D,ee,ae,oe)=>{const De=oe===void 0?!0:oe,se=`${m}-${D}`;return t.jsxs(G,{orientation:"horizontal",children:[t.jsx("input",{type:"radio",id:se,name:m,className:"mt-1 size-4 shrink-0 accent-primary",checked:i.source===D,disabled:d||!De,onChange:()=>l(D==="custom"?{source:D,path:i.path??""}:{source:D})}),t.jsxs(At,{children:[t.jsx(ie,{htmlFor:se,children:ee}),t.jsx(B,{className:"break-all",children:ae})]})]},D)},e[29]=d,e[30]=m,e[31]=l,e[32]=i.path,e[33]=i.source,e[34]=W):W=e[34],y=W;const dt=D=>{const ee=Q.get(D);return y(D,Te[D],ee?It(ee.path,ee.version):"Not found on this machine.",ee!==void 0||i.source===D)},L=g?`${Te[i.source]} · v${g.version??"?"}`:Te[i.source];p=lt,O=o,A=f,N="flex flex-col gap-2";const Ie=`${c} executable`;e[35]!==o||e[36]!==L||e[37]!==Ie?(v=t.jsx(ct,{icon:ms,title:Ie,summary:L,open:o}),e[35]=o,e[36]=L,e[37]=Ie,e[38]=v):v=e[38],C=at,x=G,e[39]===Symbol.for("react.memo_cache_sentinel")?(I=t.jsx(B,{children:"Which binary new sessions run. Automatic uses your installed CLI unless it is older than the copy bundled with Cogpit."}),e[39]=I):I=e[39],k="flex flex-col gap-2 pl-1",e[40]!==y?($=y("auto",Te.auto,"Recommended."),e[40]=y,e[41]=$):$=e[41],_=_s.map(dt),e[7]=d,e[8]=c,e[9]=m,e[10]=l,e[11]=o,e[12]=r==null?void 0:r.active,e[13]=r==null?void 0:r.candidates,e[14]=i.path,e[15]=i.source,e[16]=x,e[17]=C,e[18]=p,e[19]=g,e[20]=y,e[21]=N,e[22]=v,e[23]=k,e[24]=$,e[25]=_,e[26]=I,e[27]=O,e[28]=A}else x=e[16],C=e[17],p=e[18],g=e[19],y=e[20],N=e[21],v=e[22],k=e[23],$=e[24],_=e[25],I=e[26],O=e[27],A=e[28];const H=`${c} executable path`,V=i.source==="custom"?i.path??"":"",F=d||i.source!=="custom";let E;e[42]!==l?(E=Q=>l({source:"custom",path:Q.target.value}),e[42]=l,e[43]=E):E=e[43];let R;e[44]!==H||e[45]!==V||e[46]!==F||e[47]!==E?(R=t.jsx(gt,{"aria-label":H,value:V,placeholder:"/path/to/binary",disabled:F,onChange:E,className:"mt-1"}),e[44]=H,e[45]=V,e[46]=F,e[47]=E,e[48]=R):R=e[48];let T;e[49]!==y||e[50]!==R?(T=y("custom",Te.custom,R),e[49]=y,e[50]=R,e[51]=T):T=e[51];let U;e[52]!==T||e[53]!==k||e[54]!==$||e[55]!==_?(U=t.jsxs("div",{className:k,children:[$,_,T]}),e[52]=T,e[53]=k,e[54]=$,e[55]=_,e[56]=U):U=e[56];let P;e[57]!==g?(P=zs(g)?"text-muted-foreground":"text-destructive",e[57]=g,e[58]=P):P=e[58];let X;e[59]!==P?(X=bt("text-xs",P),e[59]=P,e[60]=X):X=e[60];let q;e[61]!==g||e[62]!==r?(q=Ps(r,g),e[61]=g,e[62]=r,e[63]=q):q=e[63];let Z;e[64]!==X||e[65]!==q?(Z=t.jsx("p",{className:X,"aria-live":"polite",children:q}),e[64]=X,e[65]=q,e[66]=Z):Z=e[66];let z;e[67]!==x||e[68]!==U||e[69]!==Z||e[70]!==I?(z=t.jsxs(x,{children:[I,U,Z]}),e[67]=x,e[68]=U,e[69]=Z,e[70]=I,e[71]=z):z=e[71];let K;e[72]!==C||e[73]!==z?(K=t.jsx(C,{children:z}),e[72]=C,e[73]=z,e[74]=K):K=e[74];let Y;return e[75]!==p||e[76]!==N||e[77]!==v||e[78]!==K||e[79]!==O||e[80]!==A?(Y=t.jsxs(p,{open:O,onOpenChange:A,className:N,children:[v,K]}),e[75]=p,e[76]=N,e[77]=v,e[78]=K,e[79]=O,e[80]=A,e[81]=Y):Y=e[81],Y}function Os(s){return[s.source,s]}function Rs(){}function Ls(s){return s.ok?s.json():null}function Tt(s){return s instanceof Error?s.message:String(s)}async function wt(s){try{const e=await le(`/api/agent-accounts/${s}`);return e.status===404?{status:"missing"}:e.ok?await e.json():{status:"error",error:await ot(e,`Request failed (${e.status})`)}}catch(e){return{status:"error",error:Tt(e)}}}function Fs(s){const[e,n]=S.useState(null),[i,l]=S.useState(null),[d,a]=S.useState(null);S.useEffect(()=>{let c=!1;return wt(s).then(r=>{c||n(r)}),()=>{c=!0}},[s]);const u=S.useCallback(async c=>{l(c),a(null);try{const r=await le(`/api/agent-accounts/${s}/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slot:c})});if(!r.ok){a({kind:"failed",error:await ot(r,`Request failed (${r.status})`)});return}a({kind:"switched",result:await r.json()}),n(await wt(s))}catch(r){a({kind:"failed",error:Tt(r)})}finally{l(null)}},[s]);return{report:e,switchingSlot:i,outcome:d,switchTo:u}}const Us={token_expired:"Token expired",relogin_required:"Login needed",no_credentials:"No credentials",keychain_unavailable:"Keychain locked",foreign_credential:"Credential mismatch",api_key:"API key",unavailable:"Usage unavailable"};function pt(s){return s.alias??s.email}function St(s){const e=M.c(18),{label:n,window:i}=s;if(!i)return null;const l=i.pct>=80,d=i.resetsIn?`${n} window resets in ${i.resetsIn}`:void 0;let a;e[0]!==n?(a=t.jsx("span",{className:"w-5",children:n}),e[0]=n,e[1]=a):a=e[1];const u=l?"bg-destructive":"bg-primary";let c;e[2]!==u?(c=bt("absolute inset-y-0 left-0 rounded-full",u),e[2]=u,e[3]=c):c=e[3];const r=`${i.pct}%`;let h;e[4]!==r?(h={width:r},e[4]=r,e[5]=h):h=e[5];let o;e[6]!==c||e[7]!==h?(o=t.jsx("span",{className:"relative h-1 w-16 overflow-hidden rounded-full bg-muted",children:t.jsx("span",{className:c,style:h})}),e[6]=c,e[7]=h,e[8]=o):o=e[8];let f;e[9]!==i.pct?(f=Math.round(i.pct),e[9]=i.pct,e[10]=f):f=e[10];let m;e[11]!==f?(m=t.jsxs("span",{className:"tabular-nums",children:[f,"%"]}),e[11]=f,e[12]=m):m=e[12];let j;return e[13]!==d||e[14]!==a||e[15]!==o||e[16]!==m?(j=t.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:d,children:[a,o,m]}),e[13]=d,e[14]=a,e[15]=o,e[16]=m,e[17]=j):j=e[17],j}function yt(s){return/[.!?]$/.test(s)?s:`${s}.`}function Bs(s,e){if(s.kind==="failed")return`Switch failed: ${s.error}`;const{result:n}=s,i=[yt(n.message)];return n.switched&&i.push(n.credentialStore==="keychain"?`Running ${e} sessions pick it up within about 30 seconds; restart one to apply it immediately.`:`New messages in ${e} use it from now on.`),[...i,...n.warnings.map(yt)].join(" ")}function Ms(s){const e=M.c(31),{kind:n,disabled:i}=s;let l;e[0]!==n?(l=$t(n),e[0]=n,e[1]=l):l=e[1];const{displayName:d}=l,{report:a,switchingSlot:u,outcome:c,switchTo:r}=Fs(n),[h,o]=S.useState(!1);if(a===null||a.status==="missing")return null;let f,m;if(e[2]!==a.accounts||e[3]!==a.status){f=a.status==="ok"?a.accounts:[];const k=f.find(Hs)??null;m=a.status==="error"?"Unavailable":k?`${pt(k)} · ${f.length} account${f.length===1?"":"s"}`:`${f.length} account${f.length===1?"":"s"}`,e[2]=a.accounts,e[3]=a.status,e[4]=f,e[5]=m}else f=e[4],m=e[5];const j=m,w=`${d} accounts`;let x;e[6]!==h||e[7]!==j||e[8]!==w?(x=t.jsx(ct,{icon:hs,title:w,summary:j,open:h}),e[6]=h,e[7]=j,e[8]=w,e[9]=x):x=e[9];const C=a.status==="ok"&&`Logins managed by ${a.tool}${a.version?` ${a.version}`:""}. `;let p;e[10]!==d||e[11]!==C?(p=t.jsxs(B,{children:[C,"Switching changes which login ",d," sessions authenticate with."]}),e[10]=d,e[11]=C,e[12]=p):p=e[12];let g;e[13]!==f||e[14]!==i||e[15]!==a.error||e[16]!==a.status||e[17]!==r||e[18]!==u?(g=a.status==="error"?t.jsx("p",{className:"text-xs text-destructive",role:"alert",children:a.error}):t.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border",children:f.map(k=>{const $=u===k.slot,_=Us[k.usageStatus];return t.jsxs("li",{className:"flex items-center gap-3 px-3 py-2",children:[t.jsx("span",{className:"w-5 shrink-0 text-xs tabular-nums text-muted-foreground",children:k.slot}),t.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[t.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",children:[t.jsx("span",{className:"truncate text-sm font-medium",children:pt(k)}),k.alias&&t.jsx("span",{className:"truncate text-xs text-muted-foreground",children:k.email}),k.active&&t.jsx(Pe,{children:"Active"}),k.disabled&&t.jsx(Pe,{variant:"outline",children:"Disabled"}),_&&t.jsx(Pe,{variant:"destructive",children:_})]}),k.organization&&t.jsx("span",{className:"truncate text-xs text-muted-foreground",children:k.organization}),k.usage&&t.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:[t.jsx(St,{label:"5h",window:k.usage.fiveHour}),t.jsx(St,{label:"7d",window:k.usage.sevenDay})]})]}),!i&&!k.active&&t.jsx(J,{type:"button",size:"sm",variant:"outline",disabled:u!==null,onClick:()=>r(k.slot),"aria-label":`Switch to ${pt(k)}`,children:$?t.jsxs(t.Fragment,{children:[t.jsx(rt,{"data-icon":"inline-start",className:"size-3.5 animate-spin"}),"Switching…"]}):"Switch"})]},k.slot)})}),e[13]=f,e[14]=i,e[15]=a.error,e[16]=a.status,e[17]=r,e[18]=u,e[19]=g):g=e[19];let y;e[20]!==d||e[21]!==c?(y=c&&t.jsx("p",{className:bt("text-xs",c.kind==="failed"?"text-destructive":"text-muted-foreground"),"aria-live":"polite",role:c.kind==="failed"?"alert":"status",children:Bs(c,d)}),e[20]=d,e[21]=c,e[22]=y):y=e[22];let N;e[23]!==p||e[24]!==g||e[25]!==y?(N=t.jsx(at,{children:t.jsxs(G,{children:[p,g,y]})}),e[23]=p,e[24]=g,e[25]=y,e[26]=N):N=e[26];let v;return e[27]!==h||e[28]!==x||e[29]!==N?(v=t.jsxs(lt,{open:h,onOpenChange:o,className:"flex flex-col gap-2",children:[x,N]}),e[27]=h,e[28]=x,e[29]=N,e[30]=v):v=e[30],v}function Hs(s){return s.active}function Pt(s){return s instanceof Error?s.message:String(s)}async function Gs(){try{const s=await le("/api/slack");return s.ok?{status:"ok",report:await s.json()}:{status:"error",error:await ot(s,`Request failed (${s.status})`)}}catch(s){return{status:"error",error:Pt(s)}}}function Vs(){const[s,e]=S.useState({status:"loading"}),[n,i]=S.useState(null),[l,d]=S.useState(null),a=S.useRef(0),u=S.useCallback(async()=>{const o=++a.current,f=await Gs();o===a.current&&e(f)},[]);S.useEffect(()=>{const o=a;return u(),()=>{o.current++}},[u]);const c=S.useCallback(async(o,f)=>{i(o),d(null),a.current++;try{const m=await le("/api/slack",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:o,...f})});m.ok||d(await ot(m,`Request failed (${m.status})`)),await u()}catch(m){d(Pt(m))}finally{i(null)}},[u]),r=S.useCallback((o,f)=>c(o,{action:"update",autoPost:f}),[c]),h=S.useCallback(o=>c(o,{action:"unlink"}),[c]);return{state:s,busy:n,error:l,refresh:u,setAutoPost:r,unlink:h}}const zt={connected:{label:"Connected",variant:"default"},connecting:{label:"Connecting",variant:"outline"},reconnecting:{label:"Reconnecting",variant:"outline"},stopped:{label:"Stopped",variant:"destructive"},failed:{label:"Failed",variant:"destructive"}};function ze(s,e){return`${s} ${e}${s===1?"":"s"}`}function qs(s){const e=[ze(s.dms.length,"DM"),...s.channels.length?[ze(s.channels.length,"channel")]:[]].join(" and ");return`Listens to ${s.allow.join(", ")} · posts to ${e} · ${s.postedToday}/${s.dailyCap} posts today`}function Ws(s){var n;const e=[];if(s.connection.lastError&&s.connection.state!=="connected"&&e.push(s.connection.lastError),s.pending.length){const i=(n=s.pending.find(l=>l.lastError))==null?void 0:n.lastError;e.push(`${ze(s.pending.length,"message")} waiting to reach the session${i?`: ${i}`:""}`)}return s.uncertain.length&&e.push(`${ze(s.uncertain.length,"message")} may not have arrived; check the session's queue`),e}function Xs(s){if(!s)return"Unavailable";const{links:e}=s;return e.length===0?"No links":e.length===1?`1 link · ${zt[e[0].connection.state].label}`:`${ze(e.length,"link")} · ${e.filter(n=>n.connection.state==="connected").length} connected`}function Ks(s){const e=M.c(40),{link:n,disabled:i,busy:l,onAutoPost:d,onUnlink:a}=s,u=zt[n.connection.state],c=n.title??n.sessionId;let r;e[0]!==n.sessionId||e[1]!==n.title?(r=n.title??`Session ${n.sessionId.slice(0,8)}`,e[0]=n.sessionId,e[1]=n.title,e[2]=r):r=e[2];let h;e[3]!==n.sessionId||e[4]!==r?(h=t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",title:n.sessionId,children:r}),e[3]=n.sessionId,e[4]=r,e[5]=h):h=e[5];let o;e[6]!==n.bot?(o=t.jsx(Pe,{variant:"outline",children:n.bot}),e[6]=n.bot,e[7]=o):o=e[7];let f;e[8]!==u.label||e[9]!==u.variant?(f=t.jsx(Pe,{variant:u.variant,children:u.label}),e[8]=u.label,e[9]=u.variant,e[10]=f):f=e[10];let m;e[11]!==h||e[12]!==o||e[13]!==f?(m=t.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[h,o,f]}),e[11]=h,e[12]=o,e[13]=f,e[14]=m):m=e[14];let j;e[15]!==n?(j=qs(n),e[15]=n,e[16]=j):j=e[16];let w;e[17]!==j?(w=t.jsx("p",{className:"text-xs text-muted-foreground",children:j}),e[17]=j,e[18]=w):w=e[18];let x;e[19]!==n?(x=Ws(n).map(Js),e[19]=n,e[20]=x):x=e[20];const C=`Post the session’s answer in the thread for ${c}`,p=i||l;let g;e[21]!==n.autoPost||e[22]!==d||e[23]!==p||e[24]!==C?(g=t.jsxs("span",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsx(_t,{size:"sm","aria-label":C,checked:n.autoPost,disabled:p,onCheckedChange:d}),"Post the session’s answer in the thread"]}),e[21]=n.autoPost,e[22]=d,e[23]=p,e[24]=C,e[25]=g):g=e[25];let y;e[26]!==l||e[27]!==i||e[28]!==n.bot||e[29]!==c||e[30]!==a?(y=!i&&t.jsxs(J,{type:"button",size:"sm",variant:"outline",disabled:l,onClick:a,"aria-label":`Unlink ${c} from ${n.bot}`,children:[l&&t.jsx(rt,{"data-icon":"inline-start",className:"size-3.5 animate-spin"}),"Unlink"]}),e[26]=l,e[27]=i,e[28]=n.bot,e[29]=c,e[30]=a,e[31]=y):y=e[31];let N;e[32]!==g||e[33]!==y?(N=t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[g,y]}),e[32]=g,e[33]=y,e[34]=N):N=e[34];let v;return e[35]!==N||e[36]!==m||e[37]!==w||e[38]!==x?(v=t.jsxs("li",{className:"flex flex-col gap-2 px-3 py-2",children:[m,w,x,N]}),e[35]=N,e[36]=m,e[37]=w,e[38]=x,e[39]=v):v=e[39],v}function Js(s){return t.jsx("p",{className:"text-xs text-destructive",children:s},s)}function Zs(s){const e=M.c(62),{disabled:n}=s,{state:i,busy:l,error:d,refresh:a,setAutoPost:u,unlink:c}=Vs(),[r,h]=S.useState(!1);if(i.status==="loading")return null;const o=i.status==="ok"?i.report:null;if(o&&!o.available)return null;let f;e[0]!==(o==null?void 0:o.links)?(f=(o==null?void 0:o.links)??[],e[0]=o==null?void 0:o.links,e[1]=f):f=e[1];const m=f;let j,w,x,C,p,g,y,N,v,k,$;if(e[2]!==l||e[3]!==n||e[4]!==m||e[5]!==r||e[6]!==a||e[7]!==o||e[8]!==u||e[9]!==i.error||e[10]!==i.status||e[11]!==c){let H;e[23]!==m?(H=T=>!m.some(U=>U.bot===T.name),e[23]=m,e[24]=H):H=e[24];const V=((o==null?void 0:o.bots)??[]).filter(H);x=lt,N=r,v=h,k="flex flex-col gap-2";let F;e[25]!==o?(F=Xs(o),e[25]=o,e[26]=F):F=e[26],e[27]!==r||e[28]!==F?($=t.jsx(ct,{icon:xs,title:"Slack links",summary:F,open:r}),e[27]=r,e[28]=F,e[29]=$):$=e[29],w=at,j=G;let E;e[30]===Symbol.for("react.memo_cache_sentinel")?(E=t.jsxs(B,{children:["A linked session receives DMs, Assistant threads, thread replies and mentions from the people it listens to, and may post only to their DMs and the channels it lists. Add bots and link sessions with ",t.jsx("code",{children:"cogpit-session slack"}),"."]}),e[30]=E):E=e[30];let R;e[31]===Symbol.for("react.memo_cache_sentinel")?(R=t.jsx(ps,{className:"size-3.5"}),e[31]=R):R=e[31],e[32]!==a?(C=t.jsxs("div",{className:"flex items-start justify-between gap-2",children:[E,t.jsx(J,{type:"button",size:"icon-sm",variant:"ghost",onClick:a,"aria-label":"Refresh Slack links",children:R})]}),e[32]=a,e[33]=C):C=e[33],e[34]!==i.error||e[35]!==i.status?(p=i.status==="error"&&t.jsx("p",{className:"text-xs text-destructive",role:"alert",children:i.error}),e[34]=i.error,e[35]=i.status,e[36]=p):p=e[36],e[37]!==l||e[38]!==n||e[39]!==m||e[40]!==u||e[41]!==c?(g=m.length>0&&t.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border",children:m.map(T=>t.jsx(Ks,{link:T,disabled:n,busy:l===T.sessionId,onAutoPost:U=>u(T.sessionId,U),onUnlink:()=>c(T.sessionId)},T.sessionId))}),e[37]=l,e[38]=n,e[39]=m,e[40]=u,e[41]=c,e[42]=g):g=e[42],y=V.length>0&&t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not linked: ",V.map(Ys).join(", ")]}),e[2]=l,e[3]=n,e[4]=m,e[5]=r,e[6]=a,e[7]=o,e[8]=u,e[9]=i.error,e[10]=i.status,e[11]=c,e[12]=j,e[13]=w,e[14]=x,e[15]=C,e[16]=p,e[17]=g,e[18]=y,e[19]=N,e[20]=v,e[21]=k,e[22]=$}else j=e[12],w=e[13],x=e[14],C=e[15],p=e[16],g=e[17],y=e[18],N=e[19],v=e[20],k=e[21],$=e[22];let _;e[43]!==d?(_=d&&t.jsx("p",{className:"text-xs text-destructive",role:"alert",children:d}),e[43]=d,e[44]=_):_=e[44];let I;e[45]!==j||e[46]!==_||e[47]!==C||e[48]!==p||e[49]!==g||e[50]!==y?(I=t.jsxs(j,{children:[C,p,g,y,_]}),e[45]=j,e[46]=_,e[47]=C,e[48]=p,e[49]=g,e[50]=y,e[51]=I):I=e[51];let O;e[52]!==w||e[53]!==I?(O=t.jsx(w,{children:I}),e[52]=w,e[53]=I,e[54]=O):O=e[54];let A;return e[55]!==x||e[56]!==O||e[57]!==N||e[58]!==v||e[59]!==k||e[60]!==$?(A=t.jsxs(x,{open:N,onOpenChange:v,className:k,children:[$,O]}),e[55]=x,e[56]=O,e[57]=N,e[58]=v,e[59]=k,e[60]=$,e[61]=A):A=e[61],A}function Ys(s){return`${s.name}${s.teamName?` (${s.teamName})`:""}`}function Qs(s){const e=M.c(18),{active:n,onSignInStarted:i}=s,[l,d]=S.useState(!1),a=Bt(n),u=a.agents;let c;e[0]!==u?(c=(u==null?void 0:u.filter(en).length)??0,e[0]=u,e[1]=c):c=e[1];const h=u?`${c} of ${u.length} ready`:"Checking…";let o;e[2]!==l||e[3]!==h?(o=t.jsx(ct,{icon:gs,title:"Agents",summary:h,open:l}),e[2]=l,e[3]=h,e[4]=o):o=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(B,{children:"The coding agents installed on this computer, and whether you're signed in to each."}),e[5]=f):f=e[5];let m;e[6]!==a||e[7]!==i?(m=t.jsx(Ht,{check:a,onSignInStarted:i}),e[6]=a,e[7]=i,e[8]=m):m=e[8];let j;e[9]!==a?(j=t.jsx("div",{children:t.jsx(Gt,{check:a})}),e[9]=a,e[10]=j):j=e[10];let w;e[11]!==m||e[12]!==j?(w=t.jsx(at,{children:t.jsxs(G,{children:[f,m,j]})}),e[11]=m,e[12]=j,e[13]=w):w=e[13];let x;return e[14]!==l||e[15]!==o||e[16]!==w?(x=t.jsxs(lt,{open:l,onOpenChange:d,className:"flex flex-col gap-2",children:[o,w]}),e[14]=l,e[15]=o,e[16]=w,e[17]=x):x=e[17],x}function en(s){return Mt(s)==="ready"}const tn=S.lazy(()=>Kt(()=>import("./PluginsDialog-CYiiMArh.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.PluginsDialog}))),sn=Et().filter(s=>s.cli.bundledBySdk).map(s=>s.kind),nn=Et().filter(s=>s.capabilities.accountSwitching).map(s=>s.kind);function ln(s,e){return s.source===e.source&&(s.source!=="custom"||s.path===e.path)}function an(s){const e=M.c(5),{status:n,error:i}=s;if(n==="validating"){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(rt,{"data-icon":"inline-start",className:"size-3.5 animate-spin"}),"Checking path..."]}),e[0]=l):l=e[0],l}if(n==="valid"){let l;return e[1]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsxs("div",{className:"flex items-center gap-2 text-sm text-success",children:[t.jsx(Ss,{"data-icon":"inline-start",className:"size-3.5"}),"Folder found"]}),e[1]=l):l=e[1],l}if(n==="invalid"&&i){let l;e[2]===Symbol.for("react.memo_cache_sentinel")?(l=t.jsx(ys,{"data-icon":"inline-start",className:"size-3.5"}),e[2]=l):l=e[2];let d;return e[3]!==i?(d=t.jsxs("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[l,i]}),e[3]=i,e[4]=d):d=e[4],d}return null}function bn(s){const e=M.c(123),{open:n,currentPath:i,onClose:l,onSaved:d}=s,[a,u]=S.useState(i),[c,r]=S.useState(!1),{status:h,error:o,debouncedValidate:f,reset:m,save:j}=Vt();let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=qt(),e[0]=w):w=e[0];const x=w;let C;e[1]===Symbol.for("react.memo_cache_sentinel")?(C=Wt("configWrite"),e[1]=C):C=e[1];const p=C,[g,y]=S.useState(!1),N=Xt(n&&g&&p),[v,k]=S.useState(!1),[$,_]=S.useState(""),[I,O]=S.useState(!1),[A,H]=S.useState(""),[V,F]=S.useState(""),[E,R]=S.useState(""),[T,U]=S.useState(""),[P,X]=S.useState(!1),[q,Z]=S.useState(!1),[z,K]=S.useState(xt),[Y,Q]=S.useState(0),[W,dt]=S.useState(xt),[L,Ie]=S.useState(!1),[D,ee]=S.useState(!1);let ae;e[2]===Symbol.for("react.memo_cache_sentinel")?(ae=[],e[2]=ae):ae=e[2];const[oe,De]=S.useState(ae);let se,Oe;e[3]!==i||e[4]!==n||e[5]!==m?(se=()=>{n&&(u(i),m(),le("/api/config").then(un).then(b=>{const te=(b==null?void 0:b.networkAccess)||!1;k(te),Ie(te),ee(!!(b!=null&&b.networkPassword)),_("");const tt=(b==null?void 0:b.terminalApp)||"";H(tt),F(tt);const st=(b==null?void 0:b.editorApp)||"";R(st),U(st);const nt=(b==null?void 0:b.useBuiltInEditor)===!0;X(nt),Z(nt);const it=Ts(b==null?void 0:b.agentExecutable)??xt;K(it),dt(it),te&&(b!=null&&b.networkPassword)&&!x?le("/api/connected-devices").then(dn).then(_e=>De((_e==null?void 0:_e.devices)||[])).catch(cn):De([])}).catch(rn))},Oe=[n,i,m,x],e[3]=i,e[4]=n,e[5]=m,e[6]=se,e[7]=Oe):(se=e[6],Oe=e[7]),S.useEffect(se,Oe);let Re;e[8]!==f?(Re=b=>{const te=b.target.value;u(te),f(te)},e[8]=f,e[9]=Re):Re=e[9];const ut=Re;let Le;e[10]!==z||e[11]!==E||e[12]!==L||e[13]!==v||e[14]!==$||e[15]!==d||e[16]!==a||e[17]!==j||e[18]!==A||e[19]!==P?(Le=async()=>{r(!0);const b=await j(a,{networkAccess:x?L:v,networkPassword:!x&&v&&$.length>0?$:void 0,terminalApp:A.trim()||void 0,editorApp:E.trim()||void 0,useBuiltInEditor:P,agentExecutable:z});b.success&&b.claudeDir&&(Q(on),d(b.claudeDir)),r(!1)},e[10]=z,e[11]=E,e[12]=L,e[13]=v,e[14]=$,e[15]=d,e[16]=a,e[17]=j,e[18]=A,e[19]=P,e[20]=Le):Le=e[20];const re=Le;let Fe;e[21]!==z||e[22]!==E||e[23]!==D||e[24]!==W||e[25]!==T||e[26]!==L||e[27]!==V||e[28]!==q||e[29]!==v||e[30]!==$||e[31]!==h||e[32]!==A||e[33]!==P?(Fe=function(){var _e;if(h==="validating"||h==="invalid")return!1;const te=h==="valid",tt=!x&&(v!==L||v&&$.length>0),st=A!==V,nt=E!==T||P!==q,it=!ln(z,W);if(!te&&!tt&&!st&&!nt&&!it||z.source==="custom"&&!((_e=z.path)!=null&&_e.trim()))return!1;if(!x&&v){const Dt=$.length>0&&$.length<vt,Ot=!D&&$.length===0;if(Dt||Ot)return!1}return!0},e[21]=z,e[22]=E,e[23]=D,e[24]=W,e[25]=T,e[26]=L,e[27]=V,e[28]=q,e[29]=v,e[30]=$,e[31]=h,e[32]=A,e[33]=P,e[34]=Fe):Fe=e[34];const ne=Fe();let ce;e[35]!==l?(ce=b=>{b||l()},e[35]=l,e[36]=ce):ce=e[36];let Ue;e[37]===Symbol.for("react.memo_cache_sentinel")?(Ue=t.jsxs(Jt,{children:[t.jsx(Zt,{className:"text-foreground",children:"Configuration"}),t.jsx(Yt,{className:"text-muted-foreground",children:"Manage local paths, preferred apps, and remote access."})]}),e[37]=Ue):Ue=e[37];const ft=ne?void 0:l;let de;e[38]!==n||e[39]!==ft?(de=t.jsx(Qs,{active:n,onSignInStarted:ft}),e[38]=n,e[39]=ft,e[40]=de):de=e[40];let Be;e[41]===Symbol.for("react.memo_cache_sentinel")?(Be=p&&t.jsxs(G,{children:[t.jsx(ie,{children:"Plugins"}),t.jsx(B,{children:"Manage installed plugins, their settings, and service connections."}),t.jsx(J,{type:"button",variant:"outline",onClick:()=>y(!0),children:"Manage plugins"})]}),e[41]=Be):Be=e[41];let Me,He;e[42]===Symbol.for("react.memo_cache_sentinel")?(Me=t.jsx(ie,{htmlFor:"claude-directory",children:"Claude directory"}),He=t.jsx(B,{children:"The directory containing your Claude configuration."}),e[42]=Me,e[43]=He):(Me=e[42],He=e[43]);let Ge;e[44]===Symbol.for("react.memo_cache_sentinel")?(Ge=t.jsx(Ct,{children:t.jsx(js,{"data-icon":"inline-start"})}),e[44]=Ge):Ge=e[44];let ue;e[45]!==ne||e[46]!==re||e[47]!==c?(ue=b=>{b.key==="Enter"&&ne&&!c&&re()},e[45]=ne,e[46]=re,e[47]=c,e[48]=ue):ue=e[48];let fe;e[49]!==ut||e[50]!==a||e[51]!==ue?(fe=t.jsxs(Nt,{children:[Ge,t.jsx(kt,{id:"claude-directory",value:a,onChange:ut,placeholder:"/Users/you/.claude",disabled:!p,onKeyDown:ue})]}),e[49]=ut,e[50]=a,e[51]=ue,e[52]=fe):fe=e[52];let me;e[53]!==o||e[54]!==h?(me=t.jsx("div",{"aria-live":"polite",children:t.jsx(an,{status:h,error:o})}),e[53]=o,e[54]=h,e[55]=me):me=e[55];let he;e[56]!==fe||e[57]!==me?(he=t.jsxs(G,{children:[Me,He,fe,me]}),e[56]=fe,e[57]=me,e[58]=he):he=e[58];let Ve,qe;e[59]===Symbol.for("react.memo_cache_sentinel")?(Ve=t.jsxs(ie,{htmlFor:"terminal-application",children:[t.jsx(bs,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Terminal application"]}),qe=t.jsx(B,{children:"Leave blank to use the system default for Ctrl+Cmd+T."}),e[59]=Ve,e[60]=qe):(Ve=e[59],qe=e[60]);let We;e[61]===Symbol.for("react.memo_cache_sentinel")?(We=b=>H(b.target.value),e[61]=We):We=e[61];let xe;e[62]!==A?(xe=t.jsxs(G,{children:[Ve,qe,t.jsx(gt,{id:"terminal-application",value:A,onChange:We,placeholder:"Ghostty, iTerm, or /path/to/binary",disabled:!p})]}),e[62]=A,e[63]=xe):xe=e[63];let Xe;e[64]===Symbol.for("react.memo_cache_sentinel")?(Xe=b=>X(b===!0),e[64]=Xe):Xe=e[64];let pe;e[65]!==P?(pe=t.jsx(Qt,{id:"use-built-in-editor",checked:P,onCheckedChange:Xe,disabled:!p}),e[65]=P,e[66]=pe):pe=e[66];let Ke;e[67]===Symbol.for("react.memo_cache_sentinel")?(Ke=t.jsxs(At,{children:[t.jsxs(ie,{htmlFor:"use-built-in-editor",children:[t.jsx(vs,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Open files in Cogpit"]}),t.jsx(B,{children:"Files and diffs open in Cogpit’s file workspace instead of launching an external editor."})]}),e[67]=Ke):Ke=e[67];let ge;e[68]!==pe?(ge=t.jsxs(G,{orientation:"horizontal",children:[pe,Ke]}),e[68]=pe,e[69]=ge):ge=e[69];let Je;e[70]===Symbol.for("react.memo_cache_sentinel")?(Je=t.jsxs(ie,{htmlFor:"editor-application",children:[t.jsx(ws,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Editor application"]}),e[70]=Je):Je=e[70];const mt=P?"Not used while files open in Cogpit.":"Leave blank to use $VISUAL or automatic detection.";let je;e[71]!==mt?(je=t.jsx(B,{children:mt}),e[71]=mt,e[72]=je):je=e[72];let Ze;e[73]===Symbol.for("react.memo_cache_sentinel")?(Ze=b=>R(b.target.value),e[73]=Ze):Ze=e[73];const ht=!p||P;let be;e[74]!==E||e[75]!==ht?(be=t.jsx(gt,{id:"editor-application",value:E,onChange:Ze,placeholder:"cursor, code, zed, or /path/to/binary",disabled:ht}),e[74]=E,e[75]=ht,e[76]=be):be=e[76];let ve;e[77]!==je||e[78]!==be?(ve=t.jsxs(G,{children:[Je,je,be]}),e[77]=je,e[78]=be,e[79]=ve):ve=e[79];let we;e[80]!==z||e[81]!==Y?(we=sn.map(b=>t.jsx(Ds,{kind:b,value:z,onChange:K,disabled:!p,reportVersion:Y},b)),e[80]=z,e[81]=Y,e[82]=we):we=e[82];let Ye,Qe;e[83]===Symbol.for("react.memo_cache_sentinel")?(Ye=nn.map(b=>t.jsx(Ms,{kind:b,disabled:!p},b)),Qe=t.jsx(Zs,{disabled:!p}),e[83]=Ye,e[84]=Qe):(Ye=e[83],Qe=e[84]);let Se;e[85]!==oe||e[86]!==D||e[87]!==L||e[88]!==v||e[89]!==$||e[90]!==I?(Se=!x&&p&&t.jsx($s,{networkAccess:v,setNetworkAccess:k,networkPassword:$,setNetworkPassword:_,showNetworkPassword:I,setShowNetworkPassword:O,hasExistingPassword:D,initialNetworkAccess:L,connectedDevices:oe,minPasswordLength:vt}),e[85]=oe,e[86]=D,e[87]=L,e[88]=v,e[89]=$,e[90]=I,e[91]=Se):Se=e[91];let ye;e[92]!==de||e[93]!==he||e[94]!==xe||e[95]!==ge||e[96]!==ve||e[97]!==we||e[98]!==Se?(ye=t.jsxs(es,{children:[de,Be,he,xe,ge,ve,we,Ye,Qe,Se]}),e[92]=de,e[93]=he,e[94]=xe,e[95]=ge,e[96]=ve,e[97]=we,e[98]=Se,e[99]=ye):ye=e[99];let Ne;e[100]!==l?(Ne=t.jsx(J,{variant:"outline",onClick:l,children:"Cancel"}),e[100]=l,e[101]=Ne):Ne=e[101];let ke;e[102]!==ne||e[103]!==re||e[104]!==c?(ke=p&&t.jsx(J,{disabled:!ne||c,onClick:re,children:c?t.jsxs(t.Fragment,{children:[t.jsx(rt,{"data-icon":"inline-start",className:"size-4 animate-spin"}),"Saving..."]}):"Save"}),e[102]=ne,e[103]=re,e[104]=c,e[105]=ke):ke=e[105];let Ce;e[106]!==Ne||e[107]!==ke?(Ce=t.jsxs(ts,{children:[Ne,ke]}),e[106]=Ne,e[107]=ke,e[108]=Ce):Ce=e[108];let $e;e[109]!==ye||e[110]!==Ce?($e=t.jsxs(ss,{className:"max-h-[calc(100dvh-2rem)] overflow-y-auto sm:max-w-lg",children:[Ue,ye,Ce]}),e[109]=ye,e[110]=Ce,e[111]=$e):$e=e[111];let Ae;e[112]!==n||e[113]!==$e||e[114]!==ce?(Ae=t.jsx(ns,{open:n,onOpenChange:ce,children:$e}),e[112]=n,e[113]=$e,e[114]=ce,e[115]=Ae):Ae=e[115];let Ee;e[116]!==n||e[117]!==g||e[118]!==N?(Ee=n&&g&&p&&t.jsx(S.Suspense,{fallback:null,children:t.jsx(tn,{client:N.client,state:N,currentPath:null,onClose:()=>y(!1)})}),e[116]=n,e[117]=g,e[118]=N,e[119]=Ee):Ee=e[119];let et;return e[120]!==Ae||e[121]!==Ee?(et=t.jsxs(t.Fragment,{children:[Ae,Ee]}),e[120]=Ae,e[121]=Ee,e[122]=et):et=e[122],et}function on(s){return s+1}function rn(){}function cn(){}function dn(s){return s.json()}function un(s){return s.json()}export{bn as ConfigDialog};