cogpit 2.6.1 → 2.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2323 -2393
- package/dist/web/assets/{CommandPaletteHost-DLho8Ydr.js → CommandPaletteHost-iiTEkWGR.js} +1 -1
- package/dist/web/assets/{ConfigBrowser-DcRITnFh.js → ConfigBrowser-CV_FDTPG.js} +1 -1
- package/dist/web/assets/{HighlightedEditor-DIp1oA0P.js → HighlightedEditor-7K1IXoMd.js} +1 -1
- package/dist/web/assets/{KeyboardShortcutsDialog-BbU77pdm.js → KeyboardShortcutsDialog-C7QHuM2e.js} +1 -1
- package/dist/web/assets/{MobileFileChanges-GkG76Ztq.js → MobileFileChanges-qnY-uxZ_.js} +1 -1
- package/dist/web/assets/{PreviewPanel-B8DbD395.js → PreviewPanel-DBIaGXu0.js} +1 -1
- package/dist/web/assets/ProjectFilesPanel-DdllBXuv.js +4 -0
- package/dist/web/assets/{ProjectSwitcherModal-HW-WAt1o.js → ProjectSwitcherModal-BhevYH6F.js} +1 -1
- package/dist/web/assets/{TerminalOutput-Cpqldw8o.js → TerminalOutput-DnTT9ONj.js} +1 -1
- package/dist/web/assets/{ThemeSelectorModal-BZ9ceBWr.js → ThemeSelectorModal-GimQk0yY.js} +1 -1
- package/dist/web/assets/WorkflowsPanel-BTeZdY1F.js +1 -0
- package/dist/web/assets/WorktreePanel-DbSH2Fyv.js +1 -0
- package/dist/web/assets/{index-L4keTj_3.js → index-7fgSFumo.js} +1 -1
- package/dist/web/assets/{index-De7cnbso.js → index-Bl7YHn3e.js} +1 -1
- package/dist/web/assets/index-C640apmk.css +1 -0
- package/dist/web/assets/index-CVF75nuK.js +153 -0
- package/dist/web/assets/index-CmAiGDkv.js +1 -0
- package/dist/web/assets/index-j1RyyaFQ.js +1 -0
- package/dist/web/assets/session-parser.worker-DlF00ZHH.js +29 -0
- package/dist/web/assets/vendor-ui-C4lFQWec.js +937 -0
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/dist/web/assets/ProjectFilesPanel-nG1bZOL7.js +0 -4
- package/dist/web/assets/WorkflowsPanel-DOOg6Hqp.js +0 -1
- package/dist/web/assets/WorktreePanel-JHMvhzQu.js +0 -1
- package/dist/web/assets/index-9nniVy_T.js +0 -157
- package/dist/web/assets/index-BDtY-qce.css +0 -1
- package/dist/web/assets/index-BhAAK3QZ.js +0 -1
- package/dist/web/assets/index-D2-ty4Xm.js +0 -1
- package/dist/web/assets/session-parser.worker-CnmfpqaO.js +0 -29
- package/dist/web/assets/vendor-ui-CKSkT7i9.js +0 -912
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as u,c as _e,j as s}from"./vendor-react-gGw_S5I_.js";import{w as Ze,bw as Qe,b2 as et,bx as ct,by as Vt,_ as Ue,z as Dt,G as Rt,H as nt,y as It,b1 as lt,B as ue,bz as At,E as Lt,av as Ot,n as qt,I as Zt,W as Qt,m as es,b8 as Mt,b9 as Ft,b7 as Bt,bA as Ve,bB as ts,bC as ss,a4 as ns,bD as ls,bE as rs,bF as os,bG as as,bH as is,i as Pt,j as zt,k as $t,aY as ut,X as cs,V as ft,U as us,bI as Kt,aF as Ut,h as Yt,D as Gt,aa as fs,ab as ds,ac as ms,ad as hs,ae as ps,af as xs,ag as gs,ah as bs,ai as ws,a5 as ys,am as Ht,$ as dt,bt as mt,bJ as js}from"./index-CVF75nuK.js";import{a4 as Ss,aw as ks,o as Ns,J as Xt,A as Cs,h as ot,X as at,ax as Es,ay as _s,az as Ts,c as vs,aA as Ds,j as ht,a2 as Rs,P as Is,N as Wt,aB as As}from"./vendor-ui-C4lFQWec.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const We="/api/browser",Ls=5e3,Os="all";function pt(n,e=""){return`${We}/sessions/${encodeURIComponent(n)}${e}`}function xt(n){return{headers:{"content-type":"application/json"},body:JSON.stringify(n)}}function tt(n,e){return n instanceof Error&&n.message?n.message:e}function Ms(n){const[e,t]=u.useState(null),[l,a]=u.useState(null),i=u.useRef(!1),o=u.useRef(0),f=u.useRef(!1);u.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]);const d=u.useCallback(async()=>{const c=++o.current;f.current=!0;try{const p=await Ze(Qe(We)),m=p.ok?await p.json():null;if(!i.current||c!==o.current)return;m?(t(g=>JSON.stringify(g)===JSON.stringify(m)?g:m),a(null)):a(await et(p,`Could not read the browser list (${p.status})`))}catch(p){i.current&&c===o.current&&a(tt(p,"Could not read the browser list"))}finally{c===o.current&&(f.current=!1)}},[]);u.useEffect(()=>{if(!n)return;d();const c=setInterval(()=>{f.current||d()},Ls);return()=>clearInterval(c)},[n,d]);const h=u.useCallback(async(c,p,m)=>{let g;try{g=await Ze(Qe(c),p)}catch(D){return{ok:!1,error:tt(D,m)}}if(!g.ok)return{ok:!1,error:await et(g,m)};const E=await ct(g);return d(),{ok:!0,data:E}},[d]),w=u.useCallback(async(c,p,m)=>{const g=await h(c,p,m);return g.ok?{ok:!0}:g},[h]),_=u.useCallback((c,p)=>w(`${We}/sessions`,{method:"POST",...xt({name:c,note:p})},`Could not create ${c}`),[w]),I=u.useCallback(c=>w(pt(c),{method:"DELETE"},`Could not delete ${c}`),[w]),y=u.useCallback(c=>w(pt(c,"/stop"),{method:"POST"},`Could not stop ${c}`),[w]),v=u.useCallback(async()=>{const c="Could not read where the browser skill is installed";let p;try{p=await Ze(Qe(`${We}/skill`))}catch(g){return{ok:!1,error:tt(g,c)}}if(!p.ok)return{ok:!1,error:await et(p,c)};const m=await ct(p);return Array.isArray(m==null?void 0:m.targets)?{ok:!0,targets:m.targets}:{ok:!1,error:c}},[]),j=u.useCallback(async c=>{const p="Could not install the browser skill",m=await h(`${We}/skill/install`,{method:"POST",...xt({target:c})},p);if(!m.ok)return m;const{paths:g}=m.data??{};return Array.isArray(g)&&g.every(E=>typeof E=="string")?{ok:!0,paths:g}:{ok:!1,error:p}},[h]);return{status:e,error:l,create:_,remove:I,stop:y,readSkillTargets:v,installSkill:j}}const st=4;new TextEncoder;const Fs=new TextDecoder;function Bs(n){if(n.byteLength<st)throw new Error("Frame truncated before header length");const e=new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0),t=st+e;if(n.byteLength<t)throw new Error("Frame truncated inside header");return{header:Ps(Fs.decode(n.subarray(st,t))),jpeg:n.subarray(t)}}function Ps(n){let e;try{e=JSON.parse(n)}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:a,offsetTop:i,scrollOffsetX:o,scrollOffsetY:f,targetId:d,ts:h}=e;if(typeof t!="number"||typeof l!="number"||typeof a!="number"||typeof i!="number"||typeof o!="number"||typeof f!="number"||typeof d!="string"||typeof h!="number")throw new Error("Frame header is missing fields");return{deviceWidth:t,deviceHeight:l,pageScaleFactor:a,offsetTop:i,scrollOffsetX:o,scrollOffsetY:f,targetId:d,ts:h}}const gt=500,zs=5e3,bt=[];function $s(n){const e=window.location.protocol==="https:"?"wss:":"ws:",t=Vt();return`${e}//${window.location.host}${t}/__browser?session=${encodeURIComponent(n)}`}function Ks(n){try{return JSON.parse(n)}catch{return null}}function Us(n,e){return n.state===e.state&&n.session===e.session&&n.message===e.message}function Ys(n,e){return n.targetId===e.targetId&&n.url===e.url&&n.title===e.title&&n.canGoBack===e.canGoBack&&n.canGoForward===e.canGoForward}function Gs(n,e){return n.length===e.length&&n.every((t,l)=>t.targetId===e[l].targetId&&t.url===e[l].url&&t.title===e[l].title)}function rt(n){n&&n.bitmap.close()}function Hs(n,e){const t=_e.c(16),[l,a]=u.useState("idle"),[i,o]=u.useState(null),[f,d]=u.useState(null),[h,w]=u.useState(bt),[_,I]=u.useState(null),[y,v]=u.useState(null),[j,c]=u.useState(null),[p,m]=u.useState(null),g=u.useRef(null),E=u.useRef(null),D=u.useRef(null),F=u.useRef(e);let T,V;t[0]!==e?(T=()=>{F.current=e},V=[e],t[0]=e,t[1]=T,t[2]=V):(T=t[1],V=t[2]),u.useEffect(T,V);let K,H;t[3]!==n?(K=()=>{if(o(null),d(null),w(bt),I(null),m(null),v(null),c(null),n===null){a("idle");return}const U=n,k={alive:!0,issued:0,applied:0};let N=gt;const P=function(L,C){if(!k.alive||C<=k.applied){rt(L);return}k.applied=C,E.current=L,v(L),c(Date.now())},M=function(L){let C,W;try{const q=Bs(new Uint8Array(L));C=q.header,W=new Blob([q.jpeg],{type:"image/jpeg"})}catch{return}const x=k.issued=k.issued+1;createImageBitmap(W).then(q=>P({bitmap:q,header:C},x),Xs)},Y=function(L){var W;const C=Ks(L);if(C)e:switch(C.type){case"status":{o(x=>x&&Us(x,C)?x:C),m(null);break e}case"page":{d(x=>x&&Ys(x,C)?x:C);break e}case"tabs":{w(x=>Gs(x,C.tabs)?x:C.tabs),I(C.followed);break e}case"error":{m(C.message);break e}case"clipboard":(W=F.current)==null||W.call(F,C.text)}};function z(){if(!k.alive)return;const B=g.current;if(B&&B.readyState!==WebSocket.CLOSED)return;a("connecting");const L=new WebSocket($s(U));L.binaryType="arraybuffer",g.current=L,L.onopen=()=>{if(!k.alive){L.close();return}N=gt,a("connected")},L.onmessage=C=>{k.alive&&(typeof C.data=="string"?Y(C.data):C.data instanceof ArrayBuffer&&M(C.data))},L.onclose=()=>{if(!k.alive)return;g.current=null,a("disconnected");const C=N;N=Math.min(N*2,zs),D.current=setTimeout(z,C)}}return z(),()=>{k.alive=!1,D.current&&(clearTimeout(D.current),D.current=null);const B=g.current;g.current=null,B&&(B.onclose=null,B.close()),rt(E.current),E.current=null}},H=[n],t[3]=n,t[4]=K,t[5]=H):(K=t[4],H=t[5]),u.useEffect(K,H);let X;t[6]===Symbol.for("react.memo_cache_sentinel")?(X=U=>{const k=g.current;k&&k.readyState===WebSocket.OPEN&&k.send(JSON.stringify(U))},t[6]=X):X=t[6];const R=X;let O;return t[7]!==p||t[8]!==_||t[9]!==y||t[10]!==j||t[11]!==f||t[12]!==i||t[13]!==l||t[14]!==h?(O={status:l,state:i,page:f,tabs:h,followed:_,frame:y,lastFrameAt:j,error:p,send:R},t[7]=p,t[8]=_,t[9]=y,t[10]=j,t[11]=f,t[12]=i,t[13]=l,t[14]=h,t[15]=O):O=t[15],O}function Xs(){}const Ws=6e3;function Js(n){const e=_e.c(16),{activity:t}=n,[l,a]=u.useState(!0),i=t?`${t.toolCallId}:${t.done}`:null;let o,f;if(e[0]!==i?(o=()=>{if(i===null)return;a(!0);const c=setTimeout(()=>a(!1),Ws);return()=>clearTimeout(c)},f=[i],e[0]=i,e[1]=o,e[2]=f):(o=e[1],f=e[2]),u.useEffect(o,f),!t)return null;const d=l?"opacity-100":"opacity-0";let h;e[3]!==d?(h=Ue("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",d),e[3]=d,e[4]=h):h=e[4];let w;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Ss,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-muted-foreground"}),e[5]=w):w=e[5];let _;e[6]!==t.command?(_=s.jsx("code",{className:"min-w-0 truncate font-mono text-[11px]",children:t.command}),e[6]=t.command,e[7]=_):_=e[7];const I=t.done?"ran":"running";let y;e[8]!==I?(y=s.jsx("span",{className:"shrink-0 text-muted-foreground",children:I}),e[8]=I,e[9]=y):y=e[9];let v;e[10]!==_||e[11]!==y?(v=s.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-full bg-background/85 px-3 py-1 text-xs shadow-xs backdrop-blur-sm",children:[w,_,y]}),e[10]=_,e[11]=y,e[12]=v):v=e[12];let j;return e[13]!==h||e[14]!==v?(j=s.jsx("div",{className:h,children:v}),e[13]=h,e[14]=v,e[15]=j):j=e[15],j}const wt="npm i -g agent-browser && agent-browser install",Vs=1500;function qs(n){const e=_e.c(20),{onOpenSkill:t}=n,[l,a]=u.useState(!1),i=u.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]),u.useEffect(o,f);let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=async function(){await Ot(wt)&&(a(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),Vs))},e[2]=d):d=e[2];const h=d;let w,_;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Dt,{variant:"icon",children:s.jsx(Ns,{})}),_=s.jsx(Rt,{children:"Nothing to show yet"}),e[3]=w,e[4]=_):(w=e[3],_=e[4]);let I;e[5]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsxs(It,{children:[w,_,s.jsxs(nt,{children:["This panel streams a real browser the agent drives. That takes the"," ",s.jsx("code",{className:"font-mono",children:"agent-browser"})," command, which is not on this machine yet."]})]}),e[5]=I):I=e[5];let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-xs",children:wt}),e[6]=y):y=e[6];const v=l?"Copied":"Copy install command";let j;e[7]===Symbol.for("react.memo_cache_sentinel")?(j=()=>void h(),e[7]=j):j=e[7];let c;e[8]!==l?(c=l?s.jsx(Xt,{"data-icon":"inline-start",className:"text-emerald-500"}):s.jsx(Cs,{"data-icon":"inline-start"}),e[8]=l,e[9]=c):c=e[9];let p;e[10]!==c||e[11]!==v?(p=s.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:[y,s.jsx(ue,{variant:"ghost",size:"icon-xs","aria-label":v,onClick:j,children:c})]}),e[10]=c,e[11]=v,e[12]=p):p=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(ot,{"data-icon":"inline-start"}),e[13]=m):m=e[13];let g;e[14]!==t?(g=s.jsxs(ue,{variant:"outline",size:"sm",onClick:t,children:[m,"Install the agent skill…"]}),e[14]=t,e[15]=g):g=e[15];let E;e[16]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(nt,{className:"text-xs",children:"The skill teaches the agent when to use a named browser and how this panel follows along. Installing writes it into your home directory, so it is never done for you."}),e[16]=E):E=e[16];let D;return e[17]!==p||e[18]!==g?(D=s.jsxs(Lt,{className:"size-full",children:[I,s.jsxs(At,{children:[p,g,E]})]}),e[17]=p,e[18]=g,e[19]=D):D=e[19],D}function Zs(n){const e=_e.c(23),{name:t,lastUrl:l,onOpen:a}=n,[i,o]=u.useState(null),f=i??l??"";let d;e[0]!==a||e[1]!==f?(d=function(F){F.preventDefault();const T=f.trim();T&&a(T)},e[0]=a,e[1]=f,e[2]=d):d=e[2];const h=d;let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(Dt,{variant:"icon",children:s.jsx(ks,{})}),e[3]=w):w=e[3];let _;e[4]!==t?(_=s.jsxs(Rt,{children:[t," isn’t running"]}),e[4]=t,e[5]=_):_=e[5];let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(nt,{children:"The agent opens it by itself the moment it browses. You can also open a page here and watch from the start."}),e[6]=I):I=e[6];let y;e[7]!==_?(y=s.jsxs(It,{children:[w,_,I]}),e[7]=_,e[8]=y):y=e[8];let v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=D=>o(D.target.value),e[9]=v):v=e[9];let j;e[10]!==f?(j=s.jsx(lt,{"aria-label":"Page to open",className:"h-8 text-sm",placeholder:"example.com",spellCheck:!1,autoComplete:"off",value:f,onChange:v}),e[10]=f,e[11]=j):j=e[11];let c;e[12]!==f?(c=f.trim(),e[12]=f,e[13]=c):c=e[13];const p=!c;let m;e[14]!==p?(m=s.jsx(ue,{type:"submit",size:"sm",disabled:p,children:"Open"}),e[14]=p,e[15]=m):m=e[15];let g;e[16]!==h||e[17]!==m||e[18]!==j?(g=s.jsx(At,{children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:h,children:[j,m]})}),e[16]=h,e[17]=m,e[18]=j,e[19]=g):g=e[19];let E;return e[20]!==g||e[21]!==y?(E=s.jsxs(Lt,{className:"size-full",children:[y,g]}),e[20]=g,e[21]=y,e[22]=E):E=e[22],E}function yt(n){if(n.url==="about:blank"&&(!n.title.trim()||n.title==="about:blank"))return"New tab";if(n.title.trim())return n.title.trim();try{return new URL(n.url).hostname||n.url}catch{return n.url}}const Qs={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 en(n){const e=_e.c(17),{status:t}=n,l=Qs[t];let a;e[0]!==l.tone?(a=Ue("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]=a):a=e[1];let i;e[2]!==a?(i=s.jsx("span",{className:a}),e[2]=a,e[3]=i):i=e[3];let o;e[4]!==l.dot?(o=Ue("size-1.5 rounded-full",l.dot),e[4]=l.dot,e[5]=o):o=e[5];let f;e[6]!==o?(f=s.jsx("span",{"aria-hidden":"true",className:o}),e[6]=o,e[7]=f):f=e[7];let d;e[8]!==l.label||e[9]!==i||e[10]!==f?(d=s.jsxs(Mt,{render:i,children:[f,l.label]}),e[8]=l.label,e[9]=i,e[10]=f,e[11]=d):d=e[11];let h;e[12]!==l.hint?(h=s.jsx(Ft,{children:l.hint}),e[12]=l.hint,e[13]=h):h=e[13];let w;return e[14]!==d||e[15]!==h?(w=s.jsxs(Bt,{children:[d,h]}),e[14]=d,e[15]=h,e[16]=w):w=e[16],w}const tn=u.memo(function(e){const t=_e.c(49),{page:l,tabs:a,followed:i,status:o,onNavigate:f,onBack:d,onForward:h,onReload:w,onFollow:_,onCloseTab:I}=e,[y,v]=u.useState(null),j=(l==null?void 0:l.url)??"";let c;t[0]!==y||t[1]!==j||t[2]!==f?(c=function(J){J.preventDefault();const fe=(y??j).trim();v(null),fe&&f(fe)},t[0]=y,t[1]=j,t[2]=f,t[3]=c):c=t[3];const p=c;let m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=function(J){J.key==="Escape"&&(J.preventDefault(),v(null),J.currentTarget.blur())},t[4]=m):m=t[4];const g=m,E=!(l!=null&&l.canGoBack);let D;t[5]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(Es,{"data-icon":"inline-start"}),t[5]=D):D=t[5];let F;t[6]!==d||t[7]!==E?(F=s.jsx(ue,{variant:"ghost",size:"icon-sm","aria-label":"Back",disabled:E,onClick:d,children:D}),t[6]=d,t[7]=E,t[8]=F):F=t[8];const T=!(l!=null&&l.canGoForward);let V;t[9]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(_s,{"data-icon":"inline-start"}),t[9]=V):V=t[9];let K;t[10]!==h||t[11]!==T?(K=s.jsx(ue,{variant:"ghost",size:"icon-sm","aria-label":"Forward",disabled:T,onClick:h,children:V}),t[10]=h,t[11]=T,t[12]=K):K=t[12];const H=!l;let X;t[13]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(Ts,{"data-icon":"inline-start"}),t[13]=X):X=t[13];let R;t[14]!==w||t[15]!==H?(R=s.jsx(ue,{variant:"ghost",size:"icon-sm","aria-label":"Reload",disabled:H,onClick:w,children:X}),t[14]=w,t[15]=H,t[16]=R):R=t[16];const O=y??j;let U;t[17]===Symbol.for("react.memo_cache_sentinel")?(U=G=>v(G.target.value),t[17]=U):U=t[17];let k;t[18]===Symbol.for("react.memo_cache_sentinel")?(k=()=>v(null),t[18]=k):k=t[18];let N;t[19]!==O?(N=s.jsx(qt,{"aria-label":"Page URL",className:"text-xs",placeholder:"Enter a URL",spellCheck:!1,autoComplete:"off",value:O,onChange:U,onFocus:sn,onBlur:k,onKeyDown:g}),t[19]=O,t[20]=N):N=t[20];const P=!j;let M;t[21]!==j?(M=()=>window.open(j,"_blank","noopener,noreferrer"),t[21]=j,t[22]=M):M=t[22];let Y;t[23]===Symbol.for("react.memo_cache_sentinel")?(Y=s.jsx(vs,{"data-icon":"inline-start"}),t[23]=Y):Y=t[23];let z;t[24]!==P||t[25]!==M?(z=s.jsx(Zt,{align:"inline-end",children:s.jsx(Qt,{size:"icon-xs","aria-label":"Open in your browser",disabled:P,onClick:M,children:Y})}),t[24]=P,t[25]=M,t[26]=z):z=t[26];let B;t[27]!==N||t[28]!==z?(B=s.jsxs(es,{className:"h-7",children:[N,z]}),t[27]=N,t[28]=z,t[29]=B):B=t[29];let L;t[30]!==p||t[31]!==B?(L=s.jsx("form",{className:"ml-1 min-w-0 flex-1",onSubmit:p,children:B}),t[30]=p,t[31]=B,t[32]=L):L=t[32];let C;t[33]!==o?(C=o&&s.jsx(en,{status:o}),t[33]=o,t[34]=C):C=t[34];let W;t[35]!==R||t[36]!==L||t[37]!==C||t[38]!==F||t[39]!==K?(W=s.jsxs("div",{className:"flex items-center gap-0.5",children:[F,K,R,L,C]}),t[35]=R,t[36]=L,t[37]=C,t[38]=F,t[39]=K,t[40]=W):W=t[40];let x;t[41]!==i||t[42]!==I||t[43]!==_||t[44]!==a?(x=a.length>0&&s.jsx("div",{className:"flex items-center gap-1 overflow-x-auto pb-0.5",children:a.map(G=>s.jsxs("div",{className:Ue("flex max-w-48 shrink-0 items-center rounded-md",G.targetId===i&&"bg-secondary"),children:[s.jsx(ue,{size:"xs",variant:"ghost",className:"min-w-0 shrink rounded-r-none","aria-current":G.targetId===i?"page":void 0,title:G.title||G.url,onClick:()=>_(G.targetId),onMouseDown:nn,onAuxClick:J=>{J.button===1&&(J.preventDefault(),I(G.targetId))},children:s.jsx("span",{className:"truncate",children:yt(G)})}),s.jsx(ue,{size:"icon-xs",variant:"ghost",className:"rounded-l-none","aria-label":`Close tab: ${yt(G)}`,title:"Close tab",onClick:()=>I(G.targetId),children:s.jsx(at,{"data-icon":"inline-start"})})]},G.targetId))}),t[41]=i,t[42]=I,t[43]=_,t[44]=a,t[45]=x):x=t[45];let q;return t[46]!==W||t[47]!==x?(q=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1 border-b px-2 py-1.5",children:[W,x]}),t[46]=W,t[47]=x,t[48]=q):q=t[48],q});function sn(n){return n.target.select()}function nn(n){n.button===1&&n.preventDefault()}const qe="default",ln=/^[a-z0-9][a-z0-9_-]{0,39}$/,rn="Lowercase letters, numbers, - and _, starting with a letter or number (40 max).",on=10080*60*1e3;function an(n){if(!n)return null;const e=new Date(n).getTime();if(Number.isNaN(e))return null;if(Date.now()-e>=on)return new Date(e).toLocaleDateString();const t=ys(n);return t==="now"?"just now":`${t} ago`}function jt(n){const e=_e.c(5),{running:t,className:l}=n,a=t?"bg-emerald-500":"ring-1 ring-muted-foreground/50 ring-inset";let i;e[0]!==l||e[1]!==a?(i=Ue("size-2 shrink-0 rounded-full",a,l),e[0]=l,e[1]=a,e[2]=i):i=e[2];let o;return e[3]!==i?(o=s.jsx("span",{"aria-hidden":"true",className:i}),e[3]=i,e[4]=o):o=e[4],o}const cn=u.memo(function(e){const t=_e.c(126),{sessions:l,selected:a,currentSessionId:i,followAgent:o,busy:f,onSelect:d,onToggleFollow:h,onOpenSkill:w,onCreate:_,onRemove:I,onStop:y,onShowDefault:v,onClose:j}=e,c=f===void 0?!1:f,p=u.useId(),m=u.useId(),[g,E]=u.useState(!1),[D,F]=u.useState(""),[T,V]=u.useState(""),[K,H]=u.useState(null),[X,R]=u.useState(!1),[O,U]=u.useState(null),k=a===qe;let N;t[0]!==a||t[1]!==l?(N=l.find(ne=>ne.name===a)??null,t[0]=a,t[1]=l,t[2]=N):N=t[2];const P=N;let M,Y;t[3]!==D?(Y=D.trim(),M=Y.length>0&&!ln.test(Y),t[3]=D,t[4]=M,t[5]=Y):(M=t[4],Y=t[5]);const z=M,B=z?rn:K,L=Y.length>0&&!z&&!X;let C;t[6]===Symbol.for("react.memo_cache_sentinel")?(C=function(){F(""),V(""),H(null),R(!1),E(!0)},t[6]=C):C=t[6];const W=C;let x;t[7]!==L||t[8]!==T||t[9]!==_||t[10]!==d||t[11]!==Y?(x=async function(){if(!L)return;R(!0);const Fe=await _(Y,T.trim());if(R(!1),!Fe.ok){H(Fe.error);return}E(!1),d(Y)},t[7]=L,t[8]=T,t[9]=_,t[10]=d,t[11]=Y,t[12]=x):x=t[12];const q=x,G=!k&&"border-amber-500/40 bg-amber-500/10";let J;t[13]!==G?(J=Ue("@container/browser-bar flex h-10 shrink-0 items-center gap-2 border-b px-2",G),t[13]=G,t[14]=J):J=t[14];let fe;t[15]===Symbol.for("react.memo_cache_sentinel")?(fe=s.jsx(ue,{variant:"ghost",size:"xs","aria-label":"Switch browser",className:"max-w-40"}),t[15]=fe):fe=t[15];const Le=(P==null?void 0:P.running)??!1;let be;t[16]!==Le?(be=s.jsx(jt,{running:Le}),t[16]=Le,t[17]=be):be=t[17];let de;t[18]!==a?(de=s.jsx("span",{className:"truncate",children:a}),t[18]=a,t[19]=de):de=t[19];let Oe;t[20]===Symbol.for("react.memo_cache_sentinel")?(Oe=s.jsx(Rs,{"data-icon":"inline-end",className:"opacity-60"}),t[20]=Oe):Oe=t[20];let we;t[21]!==be||t[22]!==de?(we=s.jsxs(ts,{render:fe,children:[be,de,Oe]}),t[21]=be,t[22]=de,t[23]=we):we=t[23];let ye;t[24]!==d?(ye=ne=>d(ne),t[24]=d,t[25]=ye):ye=t[25];let je;if(t[26]!==i||t[27]!==l){let ne;t[29]!==i?(ne=Fe=>{const it=an(Fe.lastUsedAt),Jt=Fe.driverSessionId!==null&&Fe.driverSessionId!==i;return s.jsxs(ss,{value:Fe.name,className:"items-start py-1.5",children:[s.jsx(jt,{running:Fe.running,className:"mt-[0.4rem]"}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"truncate",children:Fe.name}),s.jsx("span",{className:"sr-only",children:Fe.running?"running":"stopped"}),Fe.isDefault&&s.jsx(ns,{variant:"secondary",className:"h-4 px-1.5 text-[0.65rem] font-normal",children:"Default"}),it&&s.jsx("span",{className:"ml-auto shrink-0 text-xs text-muted-foreground",children:it})]}),Jt&&s.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"driven by another session"})]})]},Fe.name)},t[29]=i,t[30]=ne):ne=t[30],je=l.map(ne),t[26]=i,t[27]=l,t[28]=je}else je=t[28];let Se;t[31]!==a||t[32]!==ye||t[33]!==je?(Se=s.jsx(ls,{value:a,onValueChange:ye,children:je}),t[31]=a,t[32]=ye,t[33]=je,t[34]=Se):Se=t[34];let Te;t[35]===Symbol.for("react.memo_cache_sentinel")?(Te=s.jsx(rs,{}),t[35]=Te):Te=t[35];let ve;t[36]===Symbol.for("react.memo_cache_sentinel")?(ve=s.jsx(Is,{}),t[36]=ve):ve=t[36];let me;t[37]!==c?(me=s.jsxs(Ve,{disabled:c,onClick:W,children:[ve,"New browser…"]}),t[37]=c,t[38]=me):me=t[38];let De;t[39]===Symbol.for("react.memo_cache_sentinel")?(De=s.jsx(ot,{}),t[39]=De):De=t[39];let he;t[40]!==w?(he=s.jsxs(Ve,{onClick:w,children:[De,"Agent skill…"]}),t[40]=w,t[41]=he):he=t[41];let ke;t[42]!==c||t[43]!==k||t[44]!==y||t[45]!==a||t[46]!==(P==null?void 0:P.running)?(ke=!k&&s.jsxs(s.Fragment,{children:[s.jsxs(Ve,{disabled:c||!(P!=null&&P.running),onClick:()=>y(a),children:[s.jsx(Ds,{}),"Stop"]}),s.jsxs(Ve,{variant:"destructive",disabled:c,onClick:()=>U(a),children:[s.jsx(ht,{}),"Delete…"]})]}),t[42]=c,t[43]=k,t[44]=y,t[45]=a,t[46]=P==null?void 0:P.running,t[47]=ke):ke=t[47];let pe;t[48]!==Se||t[49]!==me||t[50]!==he||t[51]!==ke?(pe=s.jsxs(os,{align:"start",sideOffset:6,className:"w-72",children:[Se,Te,me,he,ke]}),t[48]=Se,t[49]=me,t[50]=he,t[51]=ke,t[52]=pe):pe=t[52];let Ne;t[53]!==we||t[54]!==pe?(Ne=s.jsxs(as,{children:[we,pe]}),t[53]=we,t[54]=pe,t[55]=Ne):Ne=t[55];let ae;t[56]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx("span",{className:"flex-1"}),t[56]=ae):ae=t[56];let Ce;t[57]!==k||t[58]!==v?(Ce=!k&&s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.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:[s.jsx(Wt,{"aria-hidden":!0,className:"size-3.5 shrink-0"}),s.jsx("span",{className:"sr-only @sm/browser-bar:not-sr-only @sm/browser-bar:whitespace-nowrap",children:"Not the default browser"})]}),s.jsx(ue,{variant:"outline",size:"xs",onClick:v,children:"Show default"})]}),t[57]=k,t[58]=v,t[59]=Ce):Ce=t[59];let xe;t[60]!==h?(xe=ne=>h(ne),t[60]=h,t[61]=xe):xe=t[61];let ie;t[62]!==o||t[63]!==xe?(ie=s.jsx(is,{size:"sm","aria-label":"Follow agent",pressed:o,onPressedChange:xe,className:"text-muted-foreground data-pressed:text-foreground"}),t[62]=o,t[63]=xe,t[64]=ie):ie=t[64];let Me,Ee;t[65]===Symbol.for("react.memo_cache_sentinel")?(Me=s.jsx(As,{"data-icon":"inline-start"}),Ee=s.jsx("span",{className:"hidden @md/browser-bar:inline",children:"Follow"}),t[65]=Me,t[66]=Ee):(Me=t[65],Ee=t[66]);let ee;t[67]!==ie?(ee=s.jsxs(Mt,{render:ie,children:[Me,Ee]}),t[67]=ie,t[68]=ee):ee=t[68];let Z;t[69]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(Ft,{children:"Switch to whichever browser this session’s agent uses"}),t[69]=Z):Z=t[69];let te;t[70]!==ee?(te=s.jsxs(Bt,{children:[ee,Z]}),t[70]=ee,t[71]=te):te=t[71];let ge;t[72]===Symbol.for("react.memo_cache_sentinel")?(ge=s.jsx(at,{"data-icon":"inline-start"}),t[72]=ge):ge=t[72];let Q;t[73]!==j?(Q=s.jsx(ue,{variant:"ghost",size:"icon-sm","aria-label":"Close browser panel",onClick:j,children:ge}),t[73]=j,t[74]=Q):Q=t[74];let S;t[75]!==q?(S=ne=>{ne.preventDefault(),q()},t[75]=q,t[76]=S):S=t[76];let r;t[77]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs(Pt,{children:[s.jsx(zt,{children:"New browser"}),s.jsx($t,{children:"A named browser keeps its own cookies and logins, and stays out of the default one."})]}),t[77]=r):r=t[77];const b=!!B;let A;t[78]!==p?(A=s.jsx(ut,{htmlFor:p,children:"Name"}),t[78]=p,t[79]=A):A=t[79];const se=!!B;let le;t[80]===Symbol.for("react.memo_cache_sentinel")?(le=ne=>{F(ne.target.value),H(null)},t[80]=le):le=t[80];let re;t[81]!==p||t[82]!==D||t[83]!==se?(re=s.jsx(lt,{id:p,autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"shop","aria-invalid":se,value:D,onChange:le}),t[81]=p,t[82]=D,t[83]=se,t[84]=re):re=t[84];let ce;t[85]!==B?(ce=s.jsx(cs,{children:B}),t[85]=B,t[86]=ce):ce=t[86];let oe;t[87]!==b||t[88]!==A||t[89]!==re||t[90]!==ce?(oe=s.jsxs(ft,{"data-invalid":b,children:[A,re,ce]}),t[87]=b,t[88]=A,t[89]=re,t[90]=ce,t[91]=oe):oe=t[91];let Be;t[92]===Symbol.for("react.memo_cache_sentinel")?(Be=s.jsx("span",{className:"text-muted-foreground/60",children:"(optional)"}),t[92]=Be):Be=t[92];let Re;t[93]!==m?(Re=s.jsxs(ut,{htmlFor:m,children:["Note ",Be]}),t[93]=m,t[94]=Re):Re=t[94];let Pe;t[95]===Symbol.for("react.memo_cache_sentinel")?(Pe=ne=>V(ne.target.value),t[95]=Pe):Pe=t[95];let Ie;t[96]!==T||t[97]!==m?(Ie=s.jsx(lt,{id:m,autoComplete:"off",placeholder:"What this browser is signed in to",value:T,onChange:Pe}),t[96]=T,t[97]=m,t[98]=Ie):Ie=t[98];let ze;t[99]!==Re||t[100]!==Ie?(ze=s.jsxs(ft,{children:[Re,Ie]}),t[99]=Re,t[100]=Ie,t[101]=ze):ze=t[101];let $e;t[102]!==oe||t[103]!==ze?($e=s.jsxs(us,{className:"gap-4",children:[oe,ze]}),t[102]=oe,t[103]=ze,t[104]=$e):$e=t[104];let Ye;t[105]===Symbol.for("react.memo_cache_sentinel")?(Ye=s.jsx(Kt,{render:s.jsx(ue,{type:"button",variant:"outline"}),children:"Cancel"}),t[105]=Ye):Ye=t[105];const $=!L;let Ae;t[106]!==$?(Ae=s.jsxs(Ut,{children:[Ye,s.jsx(ue,{type:"submit",disabled:$,children:"Create browser"})]}),t[106]=$,t[107]=Ae):Ae=t[107];let Ke;t[108]!==S||t[109]!==$e||t[110]!==Ae?(Ke=s.jsx(Yt,{className:"sm:max-w-sm",children:s.jsxs("form",{className:"flex flex-col gap-4",onSubmit:S,children:[r,$e,Ae]})}),t[108]=S,t[109]=$e,t[110]=Ae,t[111]=Ke):Ke=t[111];let He;t[112]!==g||t[113]!==Ke?(He=s.jsx(Gt,{open:g,onOpenChange:E,children:Ke}),t[112]=g,t[113]=Ke,t[114]=He):He=t[114];let Xe;t[115]!==O||t[116]!==I?(Xe=O!==null&&s.jsx(fs,{open:!0,onOpenChange:ne=>{ne||U(null)},children:s.jsxs(ds,{size:"sm",children:[s.jsxs(ms,{children:[s.jsx(hs,{className:"bg-destructive/10 text-destructive",children:s.jsx(ht,{})}),s.jsxs(ps,{children:["Delete ",O,"?"]}),s.jsx(xs,{children:"Its profile goes with it, so everything signed in there is signed out. Other browsers are untouched."})]}),s.jsxs(gs,{children:[s.jsx(bs,{size:"sm",children:"Cancel"}),s.jsx(ws,{variant:"destructive",size:"sm",onClick:()=>{I(O),U(null)},children:"Delete browser"})]})]})}),t[115]=O,t[116]=I,t[117]=Xe):Xe=t[117];let Je;return t[118]!==Ne||t[119]!==Ce||t[120]!==te||t[121]!==Q||t[122]!==He||t[123]!==Xe||t[124]!==J?(Je=s.jsxs("div",{className:J,children:[Ne,ae,Ce,te,Q,He,Xe]}),t[118]=Ne,t[119]=Ce,t[120]=te,t[121]=Q,t[122]=He,t[123]=Xe,t[124]=J,t[125]=Je):Je=t[125],Je});function un(n){const e=_e.c(36),{open:t,onOpenChange:l,readTargets:a,install:i}=n,[o,f]=u.useState(null),[d,h]=u.useState(null),[w,_]=u.useState(null);let I;e[0]!==a?(I=async()=>{const N=await a();N.ok?(f(N.targets),h(null)):h(N.error)},e[0]=a,e[1]=I):I=e[1];const y=I;let v,j;e[2]!==y||e[3]!==t?(v=()=>{t&&(h(null),y())},j=[t,y],e[2]=y,e[3]=t,e[4]=v,e[5]=j):(v=e[4],j=e[5]),u.useEffect(v,j);let c;e[6]!==i||e[7]!==y?(c=async function(P){_(P);const M=await i(P);_(null),M.ok?await y():h(M.error)},e[6]=i,e[7]=y,e[8]=c):c=e[8];const p=c;let m;e[9]!==o?(m=(o==null?void 0:o.some(fn))??!1,e[9]=o,e[10]=m):m=e[10];const g=m;let E;e[11]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(zt,{children:"Agent skill"}),e[11]=E):E=e[11];let D;e[12]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsxs(Pt,{children:[E,s.jsxs($t,{children:["The skill teaches an agent how Cogpit’s browsers work: when to use a named one, when to keep to a throwaway, and that this panel is watching. Install it for agents you run outside Cogpit — it writes a"," ",s.jsx("code",{className:"font-mono",children:"SKILL.md"})," into that CLI’s configuration directory in your home folder."]})]}),e[12]=D):D=e[12];let F;e[13]!==d?(F=d&&s.jsx("p",{role:"alert",className:"text-sm text-destructive",children:d}),e[13]=d,e[14]=F):F=e[14];let T;e[15]!==w||e[16]!==p||e[17]!==o?(T=o===null?s.jsxs("div",{role:"status",className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[s.jsx(Ht,{}),"Reading where it is installed…"]}):s.jsx("ul",{className:"flex flex-col gap-2",children:o.map(N=>s.jsxs("li",{className:"flex items-center gap-3 rounded-md border p-2.5",children:[s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate text-sm font-medium",children:N.label}),s.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:N.configRoot}),N.automatic&&s.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"Already automatic in the sessions Cogpit starts"})]}),N.installed?s.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[s.jsx(Xt,{"aria-hidden":!0,className:"size-3.5 text-emerald-500"}),"Installed"]}):s.jsx(ue,{size:"xs",variant:"outline","aria-label":`Install for ${N.label}`,disabled:w!==null,onClick:()=>void p(N.kind),children:"Install"})]},N.kind))}),e[15]=w,e[16]=p,e[17]=o,e[18]=T):T=e[18];const V=!g||w!==null;let K;e[19]!==p?(K=()=>void p(Os),e[19]=p,e[20]=K):K=e[20];let H;e[21]===Symbol.for("react.memo_cache_sentinel")?(H=s.jsx(ot,{"data-icon":"inline-start"}),e[21]=H):H=e[21];let X;e[22]!==V||e[23]!==K?(X=s.jsxs(ue,{variant:"outline",disabled:V,onClick:K,children:[H,"Install for all"]}),e[22]=V,e[23]=K,e[24]=X):X=e[24];let R;e[25]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(Kt,{render:s.jsx(ue,{type:"button"}),children:"Done"}),e[25]=R):R=e[25];let O;e[26]!==X?(O=s.jsxs(Ut,{children:[X,R]}),e[26]=X,e[27]=O):O=e[27];let U;e[28]!==O||e[29]!==F||e[30]!==T?(U=s.jsxs(Yt,{className:"sm:max-w-md",children:[D,F,T,O]}),e[28]=O,e[29]=F,e[30]=T,e[31]=U):U=e[31];let k;return e[32]!==l||e[33]!==t||e[34]!==U?(k=s.jsx(Gt,{open:t,onOpenChange:l,children:U}),e[32]=l,e[33]=t,e[34]=U,e[35]=k):k=e[35],k}function fn(n){return!n.installed}const dn={x:0,y:0,width:0,height:0,scale:0};function mn(n,e){if(n.width<=0||n.height<=0||e.width<=0||e.height<=0)return dn;const t=Math.min(1,n.width/e.width,n.height/e.height),l=e.width*t,a=e.height*t;return{x:Math.round((n.width-l)/2),y:Math.round((n.height-a)/2),width:l,height:a,scale:t}}function St(n,e,t,l,a={}){if(l.scale<=0||l.width<=0||l.height<=0)return null;const i=n-t.left-l.x,o=e-t.top-l.y;return!(i>=0&&o>=0&&i<=l.width&&o<=l.height)&&!a.clamp?null:{x:kt(i/l.scale,l.width/l.scale),y:kt(o/l.scale,l.height/l.scale)}}function kt(n,e){return Math.min(Math.max(n,0),e)}const hn=1,pn=2,xn=4,gn=8;function Ge(n){return(n.altKey?hn:0)|(n.ctrlKey?pn:0)|(n.metaKey?xn:0)|(n.shiftKey?gn:0)}const bn=["left","middle","right"];function Nt(n){return bn[n]??"left"}const wn=150,Ct=2,yn=500,Et=5,jn=1,Sn=2,kn=16,Nn="Keyboard captured · Esc to release",Cn=new Set(["F5","F11","F12"]),En=new Set(["i","j","c"]);function _t(n){return Cn.has(n.key)||n.metaKey?!0:n.ctrlKey&&n.shiftKey&&En.has(n.key.toLowerCase())}function _n(n){if(!(n.ctrlKey||n.metaKey))return n.key.length===1?n.key:n.key==="Enter"?"\r":void 0}function Tt(n,e,t){return e===jn?n*kn:e===Sn?n*t:n}function Tn(n,e,t){try{n.drawImage(e,t.x,t.y,t.width,t.height)}catch{}}function vn(n){const e=_e.c(85),{frame:t,send:l,onSizeChange:a,className:i}=n,o=u.useRef(null),f=u.useRef(null),d=u.useRef(null),h=u.useRef(null),w=u.useRef(!1);let _;e[0]===Symbol.for("react.memo_cache_sentinel")?(_={count:0,at:0,x:0,y:0,button:-1},e[0]=_):_=e[0];const I=u.useRef(_);let y;e[1]===Symbol.for("react.memo_cache_sentinel")?(y=new Map,e[1]=y):y=e[1];const v=u.useRef(y);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j={width:0,height:0,dpr:1},e[2]=j):j=e[2];const[c,p]=u.useState(j),[m,g]=u.useState(!1),E=t?t.header.deviceWidth:0,D=t?t.header.deviceHeight:0;let F;e[3]!==D||e[4]!==E||e[5]!==c?(F=mn(c,{width:E,height:D}),e[3]=D,e[4]=E,e[5]=c,e[6]=F):F=e[6];const T=F,V=u.useRef(a);let K,H;e[7]!==a?(K=()=>{V.current=a},H=[a],e[7]=a,e[8]=K,e[9]=H):(K=e[8],H=e[9]),u.useEffect(K,H);let X,R;e[10]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{const S=o.current;if(!S)return;let r=null;const b=()=>{const se=S.getBoundingClientRect(),le=Math.round(se.width),re=Math.round(se.height),ce=window.devicePixelRatio||1;p(oe=>oe.width===le&&oe.height===re&&oe.dpr===ce?oe:{width:le,height:re,dpr:ce}),r&&clearTimeout(r),r=setTimeout(()=>{r=null,le>0&&re>0&&V.current(le,re,ce)},wn)};b();const A=new ResizeObserver(b);return A.observe(S),()=>{A.disconnect(),r&&clearTimeout(r)}},R=[],e[10]=X,e[11]=R):(X=e[10],R=e[11]),u.useEffect(X,R);let O,U;e[12]!==T||e[13]!==t||e[14]!==c?(U=()=>{const S=f.current,r=S==null?void 0:S.getContext("2d");if(!S||!r)return;const b=Math.round(c.width*c.dpr),A=Math.round(c.height*c.dpr);S.width!==b&&(S.width=b),S.height!==A&&(S.height=A),r.setTransform(c.dpr,0,0,c.dpr,0,0),r.clearRect(0,0,c.width,c.height),!(!t||T.width<=0||T.height<=0)&&Tn(r,t.bitmap,T)},O=[t,T,c],e[12]=T,e[13]=t,e[14]=c,e[15]=O,e[16]=U):(O=e[15],U=e[16]),u.useEffect(U,O);let k,N;e[17]!==t?(k=()=>()=>rt(t),N=[t],e[17]=t,e[18]=k,e[19]=N):(k=e[18],N=e[19]),u.useEffect(k,N);let P;e[20]!==T?(P=function(r,b,A){const se=f.current;return se?St(r,b,se.getBoundingClientRect(),T,{clamp:A}):null},e[20]=T,e[21]=P):P=e[21];const M=P;let Y;e[22]!==l?(Y=function(r,b,A,se,le){l({type:"mouse",event:r,x:b.x,y:b.y,button:A,clickCount:se,modifiers:le})},e[22]=l,e[23]=Y):Y=e[23];const z=Y;let B;e[24]===Symbol.for("react.memo_cache_sentinel")?(B=function(r){const b=I.current,A=Date.now(),se=r.button===b.button&&A-b.at<yn&&Math.abs(r.clientX-b.x)<=Et&&Math.abs(r.clientY-b.y)<=Et;return I.current={count:se?b.count+1:1,at:A,x:r.clientX,y:r.clientY,button:r.button},I.current.count},e[24]=B):B=e[24];const L=B;let C;e[25]!==M||e[26]!==z?(C=function(){const r=d.current;if(d.current=null,!r)return;const b=M(r.clientX,r.clientY,w.current);b&&z("move",b,"none",0,r.modifiers)},e[25]=M,e[26]=z,e[27]=C):C=e[27];const W=C;let x;e[28]!==W?(x=function(){h.current!==null&&(cancelAnimationFrame(h.current),h.current=null),W()},e[28]=W,e[29]=x):x=e[29];const q=x;let G;e[30]!==M||e[31]!==z?(G=function(r){if(r.currentTarget.focus(),r.button===Ct)return;const b=M(r.clientX,r.clientY,!1);b&&(r.currentTarget.setPointerCapture(r.pointerId),w.current=!0,z("down",b,Nt(r.button),L(r),Ge(r)))},e[30]=M,e[31]=z,e[32]=G):G=e[32];const J=G;let fe;e[33]!==W?(fe=function(r){d.current={clientX:r.clientX,clientY:r.clientY,modifiers:Ge(r)},h.current===null&&(h.current=requestAnimationFrame(()=>{h.current=null,W()}))},e[33]=W,e[34]=fe):fe=e[34];const Le=fe;let be;e[35]!==q||e[36]!==M||e[37]!==z?(be=function(r){q();const b=w.current;if(w.current=!1,r.currentTarget.hasPointerCapture(r.pointerId)&&r.currentTarget.releasePointerCapture(r.pointerId),r.button===Ct)return;const A=M(r.clientX,r.clientY,b);A&&z("up",A,Nt(r.button),I.current.count,Ge(r))},e[35]=q,e[36]=M,e[37]=z,e[38]=be):be=e[38];const de=be;let Oe;e[39]!==M||e[40]!==z?(Oe=function(r){r.preventDefault();const b=M(r.clientX,r.clientY,!1);if(!b)return;const A=Ge(r);z("down",b,"right",1,A),z("up",b,"right",1,A)},e[39]=M,e[40]=z,e[41]=Oe):Oe=e[41];const we=Oe;let ye;e[42]!==l?(ye=function(r){if(r.key==="Escape"){r.currentTarget.blur();return}_t(r)||r.preventDefault();const b={type:"key",event:"down",key:r.key,code:r.code,modifiers:Ge(r)},A=_n(r);A!==void 0&&(b.text=A),v.current.set(r.code,r.key),l(b)},e[42]=l,e[43]=ye):ye=e[43];const je=ye;let Se;e[44]!==l?(Se=function(r){r.key!=="Escape"&&(_t(r)||r.preventDefault(),v.current.delete(r.code),l({type:"key",event:"up",key:r.key,code:r.code,modifiers:Ge(r)}))},e[44]=l,e[45]=Se):Se=e[45];const Te=Se;let ve,me;e[46]!==D||e[47]!==E||e[48]!==T||e[49]!==l?(ve=()=>{const S=f.current;if(!S)return;const r=b=>{b.preventDefault();const A=St(b.clientX,b.clientY,S.getBoundingClientRect(),T);A&&l({type:"wheel",x:A.x,y:A.y,deltaX:Tt(b.deltaX,b.deltaMode,E),deltaY:Tt(b.deltaY,b.deltaMode,D),modifiers:Ge(b)})};return S.addEventListener("wheel",r,{passive:!1}),()=>S.removeEventListener("wheel",r)},me=[l,T,E,D],e[46]=D,e[47]=E,e[48]=T,e[49]=l,e[50]=ve,e[51]=me):(ve=e[50],me=e[51]),u.useEffect(ve,me);let De,he;e[52]!==m||e[53]!==l?(De=()=>{if(!m)return;const S=r=>{var A;const b=(A=r.clipboardData)==null?void 0:A.getData("text/plain");b&&(r.preventDefault(),l({type:"paste",text:b}))};return document.addEventListener("paste",S),()=>document.removeEventListener("paste",S)},he=[m,l],e[52]=m,e[53]=l,e[54]=De,e[55]=he):(De=e[54],he=e[55]),u.useEffect(De,he);let ke,pe;e[56]===Symbol.for("react.memo_cache_sentinel")?(ke=()=>()=>{h.current!==null&&cancelAnimationFrame(h.current)},pe=[],e[56]=ke,e[57]=pe):(ke=e[56],pe=e[57]),u.useEffect(ke,pe);let Ne;e[58]!==l?(Ne=()=>{for(const[S,r]of v.current)l({type:"key",event:"up",key:r,code:S,modifiers:0});v.current.clear()},e[58]=l,e[59]=Ne):Ne=e[59];const ae=Ne;let Ce,xe;e[60]!==ae?(Ce=()=>ae,xe=[ae],e[60]=ae,e[61]=Ce,e[62]=xe):(Ce=e[61],xe=e[62]),u.useEffect(Ce,xe);let ie;e[63]!==i?(ie=Ue("relative min-h-0 min-w-0 overflow-hidden bg-muted/30",i),e[63]=i,e[64]=ie):ie=e[64];const Me=m&&"ring-2 ring-ring ring-inset";let Ee;e[65]!==Me?(Ee=Ue("block size-full cursor-default touch-none select-none outline-none",Me),e[65]=Me,e[66]=Ee):Ee=e[66];let ee;e[67]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>g(!0),e[67]=ee):ee=e[67];let Z;e[68]!==ae?(Z=()=>{g(!1),ae()},e[68]=ae,e[69]=Z):Z=e[69];let te;e[70]!==we||e[71]!==je||e[72]!==Te||e[73]!==J||e[74]!==Le||e[75]!==de||e[76]!==Ee||e[77]!==Z?(te=s.jsx("canvas",{ref:f,role:"application","aria-label":"Browser viewport",tabIndex:0,className:Ee,onFocus:ee,onBlur:Z,onPointerDown:J,onPointerMove:Le,onPointerUp:de,onPointerCancel:de,onContextMenu:we,onKeyDown:je,onKeyUp:Te}),e[70]=we,e[71]=je,e[72]=Te,e[73]=J,e[74]=Le,e[75]=de,e[76]=Ee,e[77]=Z,e[78]=te):te=e[78];let ge;e[79]!==m?(ge=m&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-2 flex justify-center",children:s.jsx("span",{className:"rounded-full bg-background/80 px-2 py-0.5 text-[10px] text-muted-foreground shadow-xs backdrop-blur-sm",children:Nn})}),e[79]=m,e[80]=ge):ge=e[80];let Q;return e[81]!==ie||e[82]!==te||e[83]!==ge?(Q=s.jsxs("div",{ref:o,className:ie,children:[te,ge]}),e[81]=ie,e[82]=te,e[83]=ge,e[84]=Q):Q=e[84],Q}const Dn="browser-panel-session",Rn="browser-panel-follow",In=1e4,vt=3e3,An=[];function Yn(n){var $e,Ye;const e=_e.c(110),{context:t,active:l,closePanel:a}=n;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=dt(Dn),e[0]=i):i=e[0];const[o,f]=mt(i,qe);let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=dt(Rn),e[1]=d):d=e[1];const[h,w]=mt(d,!0),[_,I]=u.useState(!1),[y,v]=u.useState(null),[j,c]=u.useState(null),[p,m]=u.useState(!1),g=u.useRef(0),{status:E,error:D,create:F,remove:T,stop:V,readSkillTargets:K,installSkill:H}=Ms(l),R=Hs(l?o:null,Ln),O=(E==null?void 0:E.sessions)??An;let U;e[2]!==t.session?(U=js(t.session),e[2]=t.session,e[3]=U):U=e[3];const k=U,N=(k==null?void 0:k.session)??null;let P;if(e[4]!==N||e[5]!==O){let $;e[7]!==N?($=Ae=>Ae.name===N,e[7]=N,e[8]=$):$=e[8],P=O.some($),e[4]=N,e[5]=O,e[6]=P}else P=e[6];const M=P;let Y,z;e[9]!==N||e[10]!==M||e[11]!==h||e[12]!==o||e[13]!==f?(Y=()=>{!h||N===null||N===o||!M||Date.now()-g.current<In||f(N)},z=[h,N,M,o,f],e[9]=N,e[10]=M,e[11]=h,e[12]=o,e[13]=f,e[14]=Y,e[15]=z):(Y=e[14],z=e[15]),u.useEffect(Y,z);let B;e[16]!==f?(B=$=>{g.current=Date.now(),f($)},e[16]=f,e[17]=B):B=e[17];const L=B;let C;e[18]===Symbol.for("react.memo_cache_sentinel")?(C=async $=>{I(!0);const Ae=await $();I(!1),Ae.ok||v(Ae.error)},e[18]=C):C=e[18];const W=C,{send:x}=R;let q;e[19]!==x?(q=($,Ae,Ke)=>{x({type:"viewport",width:$,height:Ae,dpr:Ke})},e[19]=x,e[20]=q):q=e[20];const G=q;let J;e[21]!==w?(J=$=>{$&&(g.current=0),w($)},e[21]=w,e[22]=J):J=e[22];const fe=J;let Le;e[23]!==L?(Le=()=>L(qe),e[23]=L,e[24]=Le):Le=e[24];const be=Le;let de;e[25]===Symbol.for("react.memo_cache_sentinel")?(de=()=>m(!0),e[25]=de):de=e[25];const Oe=de;let we;e[26]!==T||e[27]!==L?(we=$=>{L(qe),W(()=>T($))},e[26]=T,e[27]=L,e[28]=we):we=e[28];const ye=we;let je;e[29]!==V?(je=$=>void W(()=>V($)),e[29]=V,e[30]=je):je=e[30];const Se=je;let Te;e[31]!==x?(Te=$=>x({type:"navigate",url:$}),e[31]=x,e[32]=Te):Te=e[32];const ve=Te;let me;e[33]!==x?(me=()=>x({type:"back"}),e[33]=x,e[34]=me):me=e[34];const De=me;let he;e[35]!==x?(he=()=>x({type:"forward"}),e[35]=x,e[36]=he):he=e[36];const ke=he;let pe;e[37]!==x?(pe=()=>x({type:"reload"}),e[37]=x,e[38]=pe):pe=e[38];const Ne=pe;let ae;e[39]!==x?(ae=$=>x({type:"follow",targetId:$}),e[39]=x,e[40]=ae):ae=e[40];const Ce=ae;let xe;e[41]!==x?(xe=$=>x({type:"close-tab",targetId:$}),e[41]=x,e[42]=xe):xe=e[42];const ie=xe,Me=On(R.lastFrameAt),Ee=(($e=R.state)==null?void 0:$e.state)??null,ee=(E==null?void 0:E.installed)===!1||Ee==="not-installed",Z=!ee&&Ee==="live",te=!ee&&Ee==="stopped";let ge;e[43]!==o||e[44]!==O?(ge=O.find($=>$.name===o)??null,e[43]=o,e[44]=O,e[45]=ge):ge=e[45];const Q=ge,S=Z&&(R.status==="disconnected"||R.status==="connecting"),r=R.error??y??D,b=r!==null&&r!==j?r:null,A=((Ye=t.session)==null?void 0:Ye.sessionId)??null;let se;e[46]!==_||e[47]!==a||e[48]!==F||e[49]!==h||e[50]!==ye||e[51]!==Se||e[52]!==L||e[53]!==o||e[54]!==O||e[55]!==be||e[56]!==A||e[57]!==fe?(se=s.jsx(cn,{sessions:O,selected:o,currentSessionId:A,followAgent:h,busy:_,onSelect:L,onToggleFollow:fe,onOpenSkill:Oe,onCreate:F,onRemove:ye,onStop:Se,onShowDefault:be,onClose:a}),e[46]=_,e[47]=a,e[48]=F,e[49]=h,e[50]=ye,e[51]=Se,e[52]=L,e[53]=o,e[54]=O,e[55]=be,e[56]=A,e[57]=fe,e[58]=se):se=e[58];let le;e[59]!==ie||e[60]!==Ce||e[61]!==Me||e[62]!==De||e[63]!==ke||e[64]!==Z||e[65]!==ve||e[66]!==S||e[67]!==Ne||e[68]!==R.followed||e[69]!==R.page||e[70]!==R.tabs?(le=Z&&s.jsx(tn,{page:R.page,tabs:R.tabs,followed:R.followed,status:S?"offline":Me,onNavigate:ve,onBack:De,onForward:ke,onReload:Ne,onFollow:Ce,onCloseTab:ie}),e[59]=ie,e[60]=Ce,e[61]=Me,e[62]=De,e[63]=ke,e[64]=Z,e[65]=ve,e[66]=S,e[67]=Ne,e[68]=R.followed,e[69]=R.page,e[70]=R.tabs,e[71]=le):le=e[71];let re;e[72]!==r||e[73]!==b?(re=b&&s.jsx(Bn,{message:b,onDismiss:()=>{v(null),c(r)}}),e[72]=r,e[73]=b,e[74]=re):re=e[74];let ce;e[75]!==ee?(ce=ee&&s.jsx(qs,{onOpenSkill:Oe}),e[75]=ee,e[76]=ce):ce=e[76];let oe;e[77]!==o||e[78]!==(Q==null?void 0:Q.lastUrl)||e[79]!==x||e[80]!==te?(oe=te&&s.jsx(Zs,{name:o,lastUrl:(Q==null?void 0:Q.lastUrl)??null,onOpen:$=>x({type:"launch",url:$})}),e[77]=o,e[78]=Q==null?void 0:Q.lastUrl,e[79]=x,e[80]=te,e[81]=oe):oe=e[81];let Be;e[82]!==k||e[83]!==G||e[84]!==Z||e[85]!==S||e[86]!==o||e[87]!==x||e[88]!==R.frame?(Be=Z&&s.jsxs(s.Fragment,{children:[s.jsx(vn,{className:"flex-1",frame:R.frame,send:x,onSizeChange:G}),S&&s.jsx(Fn,{}),s.jsx(Js,{activity:k&&k.session===o?k:null})]}),e[82]=k,e[83]=G,e[84]=Z,e[85]=S,e[86]=o,e[87]=x,e[88]=R.frame,e[89]=Be):Be=e[89];let Re;e[90]!==Z||e[91]!==ee||e[92]!==o||e[93]!==te?(Re=!ee&&!te&&!Z&&s.jsxs("div",{role:"status",className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(Ht,{}),"Connecting to ",o,"…"]}),e[90]=Z,e[91]=ee,e[92]=o,e[93]=te,e[94]=Re):Re=e[94];let Pe;e[95]!==ce||e[96]!==oe||e[97]!==Be||e[98]!==Re?(Pe=s.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[ce,oe,Be,Re]}),e[95]=ce,e[96]=oe,e[97]=Be,e[98]=Re,e[99]=Pe):Pe=e[99];let Ie;e[100]!==H||e[101]!==K||e[102]!==p?(Ie=s.jsx(un,{open:p,onOpenChange:m,readTargets:K,install:H}),e[100]=H,e[101]=K,e[102]=p,e[103]=Ie):Ie=e[103];let ze;return e[104]!==se||e[105]!==le||e[106]!==re||e[107]!==Pe||e[108]!==Ie?(ze=s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[se,le,re,Pe,Ie]}),e[104]=se,e[105]=le,e[106]=re,e[107]=Pe,e[108]=Ie,e[109]=ze):ze=e[109],ze}function Ln(n){return void Ot(n)}function On(n){const e=_e.c(5),[,t]=u.useState(0);let l;e[0]!==t||e[1]!==n?(l=()=>{if(n===null)return;const i=n+vt-Date.now();if(i<=0)return;const o=setTimeout(()=>t(Mn),i);return()=>clearTimeout(o)},e[0]=t,e[1]=n,e[2]=l):l=e[2];let a;return e[3]!==n?(a=[n],e[3]=n,e[4]=a):a=e[4],u.useEffect(l,a),n===null?"idle":Date.now()-n<vt?"live":"idle"}function Mn(n){return n+1}function Fn(){const n=_e.c(1);let e;return n[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 flex justify-center p-2",children:s.jsx("span",{role:"status",className:"rounded-full bg-background/85 px-2.5 py-0.5 text-[11px] text-muted-foreground shadow-xs backdrop-blur-sm",children:"Reconnecting…"})}),n[0]=e):e=n[0],e}function Bn(n){const e=_e.c(9),{message:t,onDismiss:l}=n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(Wt,{"aria-hidden":!0,className:"size-3.5 shrink-0"}),e[0]=a):a=e[0];let i;e[1]!==t?(i=s.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=s.jsx(at,{"data-icon":"inline-start"}),e[3]=o):o=e[3];let f;e[4]!==l?(f=s.jsx(ue,{variant:"ghost",size:"icon-xs","aria-label":"Dismiss",onClick:l,children:o}),e[4]=l,e[5]=f):f=e[5];let d;return e[6]!==i||e[7]!==f?(d=s.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:[a,i,f]}),e[6]=i,e[7]=f,e[8]=d):d=e[8],d}export{Yn as BrowserPanel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as Y,j as t,r as v}from"./vendor-react-gGw_S5I_.js";import{_ as Ye,V as le,aY as Ee,aZ as J,m as dt,n as ut,I as ft,W as Ct,X as _t,a_ as $t,B as ce,a$ as mt,w as Ie,b0 as ht,a6 as xt,a7 as pt,a9 as gt,b1 as nt,b2 as bt,a4 as et,b3 as At,aq as Et,ar as zt,b4 as jt,i as Tt,j as It,k as Dt,b5 as Pt,U as Lt,aF as Ft,h as Rt,D as Ut}from"./index-CVF75nuK.js";import{a7 as Bt,a8 as Ot,a9 as Mt,aa as Vt,e as Ht,T as Gt,M as Wt,ab as Xt,ac as qt,ad as Kt,a2 as vt,C as wt,ae as it,af as Jt,F as Yt,y as Zt,ag as Qt,D as es,ah as ts,ai as ss}from"./vendor-ui-C4lFQWec.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";function ns(s){const e=Y.c(11);let n,a,i;e[0]!==s?({className:n,size:i,...a}=s,e[0]=s,e[1]=n,e[2]=a,e[3]=i):(n=e[1],a=e[2],i=e[3]);const r=i===void 0?"default":i;let l;e[4]!==n?(l=Ye("peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50",n),e[4]=n,e[5]=l):l=e[5];let f;e[6]===Symbol.for("react.memo_cache_sentinel")?(f=t.jsx(Ot,{"data-slot":"switch-thumb",className:"pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground"}),e[6]=f):f=e[6];let c;return e[7]!==a||e[8]!==r||e[9]!==l?(c=t.jsx(Bt,{"data-slot":"switch","data-size":r,className:l,...a,children:f}),e[7]=a,e[8]=r,e[9]=l,e[10]=c):c=e[10],c}function as(s){const e=Y.c(3),{name:n}=s,a=n.toLowerCase();if(a.includes("iphone")||a.includes("android")){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(Ht,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[0]=r):r=e[0],r}if(a.includes("ipad")||a.includes("tablet")){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=t.jsx(Gt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[1]=r):r=e[1],r}let i;return e[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(Wt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[2]=i):i=e[2],i}function at(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 a=Math.floor(n/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function is(s){const e=[`Shared ${at(s.createdAt)}`,s.lastAccessAt>0?`opened ${at(s.lastAccessAt)}`:"never opened"];return s.guests>0&&e.push(s.guests===1?"1 guest":`${s.guests} guests`),e.join(" · ")}function ls(){const s=Y.c(12),{shares:e,revoke:n,revokeAll:a}=$t();let i;s[0]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx("p",{className:"text-xs text-muted-foreground",children:"Shared sessions"}),s[0]=i):i=s[0];let r;s[1]!==a||s[2]!==e.length?(r=e.length>0&&t.jsx(ce,{variant:"ghost",size:"xs",className:"text-destructive hover:text-destructive",onClick:()=>void a(),children:"Revoke all"}),s[1]=a,s[2]=e.length,s[3]=r):r=s[3];let l;s[4]!==r?(l=t.jsxs("div",{className:"flex h-6 items-center justify-between",children:[i,r]}),s[4]=r,s[5]=l):l=s[5];let f;s[6]!==n||s[7]!==e?(f=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(o=>{const m=o.title||o.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:m}),t.jsx("p",{className:"text-xs text-muted-foreground",children:is(o)})]}),t.jsx(ce,{variant:"ghost",size:"xs","aria-label":`Revoke share of ${m}`,className:"text-destructive hover:text-destructive",onClick:()=>void n(o.sessionId),children:"Revoke"})]},o.sessionId)})}),s[6]=n,s[7]=e,s[8]=f):f=s[8];let c;return s[9]!==l||s[10]!==f?(c=t.jsxs("div",{className:"flex flex-col gap-2",children:[l,f]}),s[9]=l,s[10]=f,s[11]=c):c=s[11],c}function rs(s){const e=Y.c(30),{networkAccess:n,setNetworkAccess:a,networkPassword:i,setNetworkPassword:r,showNetworkPassword:l,setShowNetworkPassword:f,hasExistingPassword:c,initialNetworkAccess:o,connectedDevices:m,minPasswordLength:j}=s;let x;e[0]!==n?(x=n?t.jsx(Xt,{"data-icon":"inline-start",className:"size-4 text-success"}):t.jsx(qt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[0]=n,e[1]=x):x=e[1];let b;e[2]===Symbol.for("react.memo_cache_sentinel")?(b=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]=b):b=e[2];let y;e[3]!==x?(y=t.jsxs("div",{className:"flex items-center gap-2",children:[x,b]}),e[3]=x,e[4]=y):y=e[4];let C;e[5]!==a?(C=_=>a(_),e[5]=a,e[6]=C):C=e[6];let w;e[7]!==n||e[8]!==C?(w=t.jsx(ns,{"aria-label":"Network Access",checked:n,onCheckedChange:C}),e[7]=n,e[8]=C,e[9]=w):w=e[9];let N;e[10]!==y||e[11]!==w?(N=t.jsxs("div",{className:"flex items-center justify-between",children:[y,w]}),e[10]=y,e[11]=w,e[12]=N):N=e[12];let p;e[13]!==c||e[14]!==j||e[15]!==n||e[16]!==i||e[17]!==r||e[18]!==f||e[19]!==l?(p=n&&t.jsxs(le,{"data-invalid":i.length>0&&i.length<j,children:[t.jsx(Ee,{htmlFor:"network-password",children:"Password"}),t.jsx(J,{children:c&&i.length===0?"A password is already set. Leave blank to keep it.":`Use at least ${j} characters.`}),t.jsxs(dt,{children:[t.jsx(ut,{id:"network-password",type:l?"text":"password",value:i,onChange:_=>r(_.target.value),placeholder:c?"Enter new password to change":"Set a password for remote access"}),t.jsx(ft,{align:"inline-end",children:t.jsx(Ct,{size:"icon-xs","aria-label":l?"Hide password":"Show password",onClick:()=>f(!l),children:l?t.jsx(Mt,{"data-icon":"inline-start"}):t.jsx(Vt,{"data-icon":"inline-start"})})})]}),i.length>0&&i.length<j&&t.jsxs(_t,{children:["Password must be at least ",j," characters (",i.length,"/",j,")"]}),t.jsx(J,{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]=j,e[15]=n,e[16]=i,e[17]=r,e[18]=f,e[19]=l,e[20]=p):p=e[20];let u;e[21]!==m||e[22]!==o||e[23]!==n?(u=n&&o&&m.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:m.map(os)})]}),e[21]=m,e[22]=o,e[23]=n,e[24]=u):u=e[24];let S;e[25]===Symbol.for("react.memo_cache_sentinel")?(S=t.jsx(ls,{}),e[25]=S):S=e[25];let h;return e[26]!==N||e[27]!==p||e[28]!==u?(h=t.jsxs("div",{className:"flex flex-col gap-4 border-t pt-5",children:[N,p,u,S]}),e[26]=N,e[27]=p,e[28]=u,e[29]=h):h=e[29],h}function os(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(as,{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:at(s.lastActivity)})]})]},`${s.ip}-${e}`)}const cs=["auto","path","npm","bundled","custom"],tt={source:"auto"},ds=["path","npm","bundled"];function us(s){return cs.includes(s)}function fs(s){if(!s||typeof s!="object")return;const{source:e,path:n}=s;if(!(!us(e)||e==="auto"))return e==="custom"?typeof n=="string"&&n.trim()?{source:e,path:n.trim()}:void 0:{source:e}}const Te={auto:"Automatic",path:"Installed on PATH",npm:"Global npm install",bundled:"Bundled with Cogpit",custom:"Custom path"};function Nt(s,e){return e?`v${e} · ${s}`:s}function ms(s,e){return s===null?"Checking installed binaries…":e?e.version===null?`${e.path} did not report a version — check the path.`:`Now running: ${Nt(e.path,e.version)}`:"No launchable binary for the saved choice — sessions cannot start."}function hs(s){return s!==null&&s.version!==null}function xs(s){const e=Y.c(92),{kind:n,value:a,onChange:i,disabled:r,reportVersion:l}=s;let f;e[0]!==n?(f=mt(n),e[0]=n,e[1]=f):f=e[1];const{displayName:c}=f,[o,m]=v.useState(null),[j,x]=v.useState(!1),b=`agent-executable-${n}`;let y;e[2]!==n?(y=()=>{let I=!1;return Ie(`/api/agent-executable/${n}`).then(bs).then(te=>{I||m(te)}).catch(gs),()=>{I=!0}},e[2]=n,e[3]=y):y=e[3];let C;e[4]!==n||e[5]!==l?(C=[n,l],e[4]=n,e[5]=l,e[6]=C):C=e[6],v.useEffect(y,C);let w,N,p,u,S,h,_,z,T,k,$,D,g;if(e[7]!==r||e[8]!==c||e[9]!==b||e[10]!==i||e[11]!==j||e[12]!==(o==null?void 0:o.active)||e[13]!==(o==null?void 0:o.candidates)||e[14]!==a.path||e[15]!==a.source){const I=new Map((o==null?void 0:o.candidates.map(ps))??[]);u=(o==null?void 0:o.active)??null;let te;e[29]!==r||e[30]!==b||e[31]!==i||e[32]!==a.path||e[33]!==a.source?(te=(L,B,ae,oe)=>{const lt=oe===void 0?!0:oe,K=`${b}-${L}`;return t.jsxs(le,{orientation:"horizontal",children:[t.jsx("input",{type:"radio",id:K,name:b,className:"mt-1 size-4 shrink-0 accent-primary",checked:a.source===L,disabled:r||!lt,onChange:()=>i(L==="custom"?{source:L,path:a.path??""}:{source:L})}),t.jsxs(ht,{children:[t.jsx(Ee,{htmlFor:K,children:B}),t.jsx(J,{className:"break-all",children:ae})]})]},L)},e[29]=r,e[30]=b,e[31]=i,e[32]=a.path,e[33]=a.source,e[34]=te):te=e[34],S=te;const se=L=>{const B=I.get(L);return S(L,Te[L],B?Nt(B.path,B.version):"Not found on this machine.",B!==void 0||a.source===L)},ze=u?`${Te[a.source]} · v${u.version??"?"}`:Te[a.source];p=xt,D=j,g=x,h="flex flex-col gap-2";let X;e[35]===Symbol.for("react.memo_cache_sentinel")?(X=t.jsx(ce,{type:"button",variant:"ghost",className:"h-auto w-full justify-between px-0 font-medium hover:bg-transparent"}),e[35]=X):X=e[35];let ne;e[36]===Symbol.for("react.memo_cache_sentinel")?(ne=t.jsx(Kt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[36]=ne):ne=e[36];let q;e[37]!==c?(q=t.jsxs("span",{className:"flex items-center gap-2",children:[ne,c," executable"]}),e[37]=c,e[38]=q):q=e[38];let F;e[39]!==ze?(F=t.jsx("span",{className:"truncate",children:ze}),e[39]=ze,e[40]=F):F=e[40];let R;e[41]!==j?(R=j?t.jsx(vt,{className:"size-4 shrink-0"}):t.jsx(wt,{className:"size-4 shrink-0"}),e[41]=j,e[42]=R):R=e[42];let U;e[43]!==F||e[44]!==R?(U=t.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs font-normal text-muted-foreground",children:[F,R]}),e[43]=F,e[44]=R,e[45]=U):U=e[45],e[46]!==q||e[47]!==U?(_=t.jsxs(pt,{render:X,children:[q,U]}),e[46]=q,e[47]=U,e[48]=_):_=e[48],N=gt,w=le,e[49]===Symbol.for("react.memo_cache_sentinel")?($=t.jsx(J,{children:"Which binary new sessions run. Automatic uses your installed CLI unless it is older than the copy bundled with Cogpit."}),e[49]=$):$=e[49],z="flex flex-col gap-2 pl-1",e[50]!==S?(T=S("auto",Te.auto,"Recommended."),e[50]=S,e[51]=T):T=e[51],k=ds.map(se),e[7]=r,e[8]=c,e[9]=b,e[10]=i,e[11]=j,e[12]=o==null?void 0:o.active,e[13]=o==null?void 0:o.candidates,e[14]=a.path,e[15]=a.source,e[16]=w,e[17]=N,e[18]=p,e[19]=u,e[20]=S,e[21]=h,e[22]=_,e[23]=z,e[24]=T,e[25]=k,e[26]=$,e[27]=D,e[28]=g}else w=e[16],N=e[17],p=e[18],u=e[19],S=e[20],h=e[21],_=e[22],z=e[23],T=e[24],k=e[25],$=e[26],D=e[27],g=e[28];const P=`${c} executable path`,H=a.source==="custom"?a.path??"":"",re=r||a.source!=="custom";let Z;e[52]!==i?(Z=I=>i({source:"custom",path:I.target.value}),e[52]=i,e[53]=Z):Z=e[53];let A;e[54]!==P||e[55]!==H||e[56]!==re||e[57]!==Z?(A=t.jsx(nt,{"aria-label":P,value:H,placeholder:"/path/to/binary",disabled:re,onChange:Z,className:"mt-1"}),e[54]=P,e[55]=H,e[56]=re,e[57]=Z,e[58]=A):A=e[58];let G;e[59]!==S||e[60]!==A?(G=S("custom",Te.custom,A),e[59]=S,e[60]=A,e[61]=G):G=e[61];let O;e[62]!==G||e[63]!==z||e[64]!==T||e[65]!==k?(O=t.jsxs("div",{className:z,children:[T,k,G]}),e[62]=G,e[63]=z,e[64]=T,e[65]=k,e[66]=O):O=e[66];let Q;e[67]!==u?(Q=hs(u)?"text-muted-foreground":"text-destructive",e[67]=u,e[68]=Q):Q=e[68];let E;e[69]!==Q?(E=Ye("text-xs",Q),e[69]=Q,e[70]=E):E=e[70];let W;e[71]!==u||e[72]!==o?(W=ms(o,u),e[71]=u,e[72]=o,e[73]=W):W=e[73];let M;e[74]!==E||e[75]!==W?(M=t.jsx("p",{className:E,"aria-live":"polite",children:W}),e[74]=E,e[75]=W,e[76]=M):M=e[76];let ee;e[77]!==w||e[78]!==O||e[79]!==M||e[80]!==$?(ee=t.jsxs(w,{children:[$,O,M]}),e[77]=w,e[78]=O,e[79]=M,e[80]=$,e[81]=ee):ee=e[81];let V;e[82]!==N||e[83]!==ee?(V=t.jsx(N,{children:ee}),e[82]=N,e[83]=ee,e[84]=V):V=e[84];let de;return e[85]!==p||e[86]!==h||e[87]!==_||e[88]!==V||e[89]!==D||e[90]!==g?(de=t.jsxs(p,{open:D,onOpenChange:g,className:h,children:[_,V]}),e[85]=p,e[86]=h,e[87]=_,e[88]=V,e[89]=D,e[90]=g,e[91]=de):de=e[91],de}function ps(s){return[s.source,s]}function gs(){}function bs(s){return s.ok?s.json():null}function St(s){return s instanceof Error?s.message:String(s)}async function rt(s){try{const e=await Ie(`/api/agent-accounts/${s}`);return e.status===404?{status:"missing"}:e.ok?await e.json():{status:"error",error:await bt(e,`Request failed (${e.status})`)}}catch(e){return{status:"error",error:St(e)}}}function js(s){const[e,n]=v.useState(null),[a,i]=v.useState(null),[r,l]=v.useState(null);v.useEffect(()=>{let c=!1;return rt(s).then(o=>{c||n(o)}),()=>{c=!0}},[s]);const f=v.useCallback(async c=>{i(c),l(null);try{const o=await Ie(`/api/agent-accounts/${s}/switch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slot:c})});if(!o.ok){l({kind:"failed",error:await bt(o,`Request failed (${o.status})`)});return}l({kind:"switched",result:await o.json()}),n(await rt(s))}catch(o){l({kind:"failed",error:St(o)})}finally{i(null)}},[s]);return{report:e,switchingSlot:a,outcome:r,switchTo:f}}const vs={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 st(s){return s.alias??s.email}function ot(s){const e=Y.c(18),{label:n,window:a}=s;if(!a)return null;const i=a.pct>=80,r=a.resetsIn?`${n} window resets in ${a.resetsIn}`:void 0;let l;e[0]!==n?(l=t.jsx("span",{className:"w-5",children:n}),e[0]=n,e[1]=l):l=e[1];const f=i?"bg-destructive":"bg-primary";let c;e[2]!==f?(c=Ye("absolute inset-y-0 left-0 rounded-full",f),e[2]=f,e[3]=c):c=e[3];const o=`${a.pct}%`;let m;e[4]!==o?(m={width:o},e[4]=o,e[5]=m):m=e[5];let j;e[6]!==c||e[7]!==m?(j=t.jsx("span",{className:"relative h-1 w-16 overflow-hidden rounded-full bg-muted",children:t.jsx("span",{className:c,style:m})}),e[6]=c,e[7]=m,e[8]=j):j=e[8];let x;e[9]!==a.pct?(x=Math.round(a.pct),e[9]=a.pct,e[10]=x):x=e[10];let b;e[11]!==x?(b=t.jsxs("span",{className:"tabular-nums",children:[x,"%"]}),e[11]=x,e[12]=b):b=e[12];let y;return e[13]!==r||e[14]!==l||e[15]!==j||e[16]!==b?(y=t.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:r,children:[l,j,b]}),e[13]=r,e[14]=l,e[15]=j,e[16]=b,e[17]=y):y=e[17],y}function ct(s){return/[.!?]$/.test(s)?s:`${s}.`}function ws(s,e){if(s.kind==="failed")return`Switch failed: ${s.error}`;const{result:n}=s,a=[ct(n.message)];return n.switched&&a.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.`),[...a,...n.warnings.map(ct)].join(" ")}function Ns(s){const e=Y.c(41),{kind:n,disabled:a}=s;let i;e[0]!==n?(i=mt(n),e[0]=n,e[1]=i):i=e[1];const{displayName:r}=i,{report:l,switchingSlot:f,outcome:c,switchTo:o}=js(n),[m,j]=v.useState(!1);if(l===null||l.status==="missing")return null;let x,b;if(e[2]!==l.accounts||e[3]!==l.status){x=l.status==="ok"?l.accounts:[];const g=x.find(Ss)??null;b=l.status==="error"?"Unavailable":g?`${st(g)} · ${x.length} account${x.length===1?"":"s"}`:`${x.length} account${x.length===1?"":"s"}`,e[2]=l.accounts,e[3]=l.status,e[4]=x,e[5]=b}else x=e[4],b=e[5];const y=b;let C;e[6]===Symbol.for("react.memo_cache_sentinel")?(C=t.jsx(ce,{type:"button",variant:"ghost",className:"h-auto w-full justify-between px-0 font-medium hover:bg-transparent"}),e[6]=C):C=e[6];let w;e[7]===Symbol.for("react.memo_cache_sentinel")?(w=t.jsx(Jt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),e[7]=w):w=e[7];let N;e[8]!==r?(N=t.jsxs("span",{className:"flex items-center gap-2",children:[w,r," accounts"]}),e[8]=r,e[9]=N):N=e[9];let p;e[10]!==y?(p=t.jsx("span",{className:"truncate",children:y}),e[10]=y,e[11]=p):p=e[11];let u;e[12]!==m?(u=m?t.jsx(vt,{className:"size-4 shrink-0"}):t.jsx(wt,{className:"size-4 shrink-0"}),e[12]=m,e[13]=u):u=e[13];let S;e[14]!==p||e[15]!==u?(S=t.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-xs font-normal text-muted-foreground",children:[p,u]}),e[14]=p,e[15]=u,e[16]=S):S=e[16];let h;e[17]!==N||e[18]!==S?(h=t.jsxs(pt,{render:C,children:[N,S]}),e[17]=N,e[18]=S,e[19]=h):h=e[19];const _=l.status==="ok"&&`Logins managed by ${l.tool}${l.version?` ${l.version}`:""}. `;let z;e[20]!==r||e[21]!==_?(z=t.jsxs(J,{children:[_,"Switching changes which login ",r," sessions authenticate with."]}),e[20]=r,e[21]=_,e[22]=z):z=e[22];let T;e[23]!==x||e[24]!==a||e[25]!==l.error||e[26]!==l.status||e[27]!==o||e[28]!==f?(T=l.status==="error"?t.jsx("p",{className:"text-xs text-destructive",role:"alert",children:l.error}):t.jsx("ul",{className:"flex flex-col divide-y divide-border rounded-md border border-border",children:x.map(g=>{const P=f===g.slot,H=vs[g.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:g.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:st(g)}),g.alias&&t.jsx("span",{className:"truncate text-xs text-muted-foreground",children:g.email}),g.active&&t.jsx(et,{children:"Active"}),g.disabled&&t.jsx(et,{variant:"outline",children:"Disabled"}),H&&t.jsx(et,{variant:"destructive",children:H})]}),g.organization&&t.jsx("span",{className:"truncate text-xs text-muted-foreground",children:g.organization}),g.usage&&t.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1",children:[t.jsx(ot,{label:"5h",window:g.usage.fiveHour}),t.jsx(ot,{label:"7d",window:g.usage.sevenDay})]})]}),!a&&!g.active&&t.jsx(ce,{type:"button",size:"sm",variant:"outline",disabled:f!==null,onClick:()=>o(g.slot),"aria-label":`Switch to ${st(g)}`,children:P?t.jsxs(t.Fragment,{children:[t.jsx(it,{"data-icon":"inline-start",className:"size-3.5 animate-spin"}),"Switching…"]}):"Switch"})]},g.slot)})}),e[23]=x,e[24]=a,e[25]=l.error,e[26]=l.status,e[27]=o,e[28]=f,e[29]=T):T=e[29];let k;e[30]!==r||e[31]!==c?(k=c&&t.jsx("p",{className:Ye("text-xs",c.kind==="failed"?"text-destructive":"text-muted-foreground"),"aria-live":"polite",role:c.kind==="failed"?"alert":"status",children:ws(c,r)}),e[30]=r,e[31]=c,e[32]=k):k=e[32];let $;e[33]!==z||e[34]!==T||e[35]!==k?($=t.jsx(gt,{children:t.jsxs(le,{children:[z,T,k]})}),e[33]=z,e[34]=T,e[35]=k,e[36]=$):$=e[36];let D;return e[37]!==m||e[38]!==$||e[39]!==h?(D=t.jsxs(xt,{open:m,onOpenChange:j,className:"flex flex-col gap-2",children:[h,$]}),e[37]=m,e[38]=$,e[39]=h,e[40]=D):D=e[40],D}function Ss(s){return s.active}const ys=jt().filter(s=>s.cli.bundledBySdk).map(s=>s.kind),ks=jt().filter(s=>s.capabilities.accountSwitching).map(s=>s.kind);function Cs(s,e){return s.source===e.source&&(s.source!=="custom"||s.path===e.path)}function _s(s){const e=Y.c(5),{status:n,error:a}=s;if(n==="validating"){let i;return e[0]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(it,{"data-icon":"inline-start",className:"size-3.5 animate-spin"}),"Checking path..."]}),e[0]=i):i=e[0],i}if(n==="valid"){let i;return e[1]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsxs("div",{className:"flex items-center gap-2 text-sm text-success",children:[t.jsx(ts,{"data-icon":"inline-start",className:"size-3.5"}),"Valid .claude directory found"]}),e[1]=i):i=e[1],i}if(n==="invalid"&&a){let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=t.jsx(ss,{"data-icon":"inline-start",className:"size-3.5"}),e[2]=i):i=e[2];let r;return e[3]!==a?(r=t.jsxs("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[i,a]}),e[3]=a,e[4]=r):r=e[4],r}return null}function Rs(s){const e=Y.c(110),{open:n,currentPath:a,onClose:i,onSaved:r}=s,[l,f]=v.useState(a),[c,o]=v.useState(!1),{status:m,error:j,debouncedValidate:x,reset:b,save:y}=At();let C;e[0]===Symbol.for("react.memo_cache_sentinel")?(C=Et(),e[0]=C):C=e[0];const w=C;let N;e[1]===Symbol.for("react.memo_cache_sentinel")?(N=zt("configWrite"),e[1]=N):N=e[1];const p=N,[u,S]=v.useState(!1),[h,_]=v.useState(""),[z,T]=v.useState(!1),[k,$]=v.useState(""),[D,g]=v.useState(""),[P,H]=v.useState(""),[re,Z]=v.useState(""),[A,G]=v.useState(!1),[O,Q]=v.useState(!1),[E,W]=v.useState(tt),[M,ee]=v.useState(0),[V,de]=v.useState(tt),[I,te]=v.useState(!1),[se,ze]=v.useState(!1);let X;e[2]===Symbol.for("react.memo_cache_sentinel")?(X=[],e[2]=X):X=e[2];const[ne,q]=v.useState(X);let F,R;e[3]!==a||e[4]!==n||e[5]!==b?(F=()=>{n&&(f(a),b(),Ie("/api/config").then(Ts).then(d=>{const ie=(d==null?void 0:d.networkAccess)||!1;S(ie),te(ie),ze(!!(d!=null&&d.networkPassword)),_("");const Xe=(d==null?void 0:d.terminalApp)||"";$(Xe),g(Xe);const qe=(d==null?void 0:d.editorApp)||"";H(qe),Z(qe);const Ke=(d==null?void 0:d.useBuiltInEditor)===!0;G(Ke),Q(Ke);const Je=fs(d==null?void 0:d.agentExecutable)??tt;W(Je),de(Je),ie&&(d!=null&&d.networkPassword)&&!w?Ie("/api/connected-devices").then(zs).then(Ae=>q((Ae==null?void 0:Ae.devices)||[])).catch(Es):q([])}).catch(As))},R=[n,a,b,w],e[3]=a,e[4]=n,e[5]=b,e[6]=F,e[7]=R):(F=e[6],R=e[7]),v.useEffect(F,R);let U;e[8]!==x?(U=d=>{const ie=d.target.value;f(ie),x(ie)},e[8]=x,e[9]=U):U=e[9];const L=U;let B;e[10]!==E||e[11]!==P||e[12]!==I||e[13]!==u||e[14]!==h||e[15]!==r||e[16]!==l||e[17]!==y||e[18]!==k||e[19]!==A?(B=async()=>{o(!0);const d=await y(l,{networkAccess:w?I:u,networkPassword:!w&&u&&h.length>0?h:void 0,terminalApp:k.trim()||void 0,editorApp:P.trim()||void 0,useBuiltInEditor:A,agentExecutable:E});d.success&&d.claudeDir&&(ee($s),r(d.claudeDir)),o(!1)},e[10]=E,e[11]=P,e[12]=I,e[13]=u,e[14]=h,e[15]=r,e[16]=l,e[17]=y,e[18]=k,e[19]=A,e[20]=B):B=e[20];const ae=B;let oe;e[21]!==E||e[22]!==P||e[23]!==se||e[24]!==V||e[25]!==re||e[26]!==I||e[27]!==D||e[28]!==O||e[29]!==u||e[30]!==h||e[31]!==m||e[32]!==k||e[33]!==A?(oe=function(){var Ae;if(m==="validating"||m==="invalid")return!1;const ie=m==="valid",Xe=!w&&(u!==I||u&&h.length>0),qe=k!==D,Ke=P!==re||A!==O,Je=!Cs(E,V);if(!ie&&!Xe&&!qe&&!Ke&&!Je||E.source==="custom"&&!((Ae=E.path)!=null&&Ae.trim()))return!1;if(!w&&u){const yt=h.length>0&&h.length<16,kt=!se&&h.length===0;if(yt||kt)return!1}return!0},e[21]=E,e[22]=P,e[23]=se,e[24]=V,e[25]=re,e[26]=I,e[27]=D,e[28]=O,e[29]=u,e[30]=h,e[31]=m,e[32]=k,e[33]=A,e[34]=oe):oe=e[34];const K=oe();let ue;e[35]!==i?(ue=d=>{d||i()},e[35]=i,e[36]=ue):ue=e[36];let De;e[37]===Symbol.for("react.memo_cache_sentinel")?(De=t.jsxs(Tt,{children:[t.jsx(It,{className:"text-foreground",children:"Configuration"}),t.jsx(Dt,{className:"text-muted-foreground",children:"Manage local paths, preferred apps, and remote access."})]}),e[37]=De):De=e[37];let Pe,Le;e[38]===Symbol.for("react.memo_cache_sentinel")?(Pe=t.jsx(Ee,{htmlFor:"claude-directory",children:"Claude directory"}),Le=t.jsx(J,{children:"The directory containing your Claude configuration."}),e[38]=Pe,e[39]=Le):(Pe=e[38],Le=e[39]);let Fe;e[40]===Symbol.for("react.memo_cache_sentinel")?(Fe=t.jsx(ft,{children:t.jsx(Yt,{"data-icon":"inline-start"})}),e[40]=Fe):Fe=e[40];let fe;e[41]!==K||e[42]!==ae||e[43]!==c?(fe=d=>{d.key==="Enter"&&K&&!c&&ae()},e[41]=K,e[42]=ae,e[43]=c,e[44]=fe):fe=e[44];let me;e[45]!==L||e[46]!==l||e[47]!==fe?(me=t.jsxs(dt,{children:[Fe,t.jsx(ut,{id:"claude-directory",value:l,onChange:L,placeholder:"/Users/you/.claude",disabled:!p,onKeyDown:fe})]}),e[45]=L,e[46]=l,e[47]=fe,e[48]=me):me=e[48];let he;e[49]!==j||e[50]!==m?(he=t.jsx("div",{"aria-live":"polite",children:t.jsx(_s,{status:m,error:j})}),e[49]=j,e[50]=m,e[51]=he):he=e[51];let xe;e[52]!==me||e[53]!==he?(xe=t.jsxs(le,{children:[Pe,Le,me,he]}),e[52]=me,e[53]=he,e[54]=xe):xe=e[54];let Re,Ue;e[55]===Symbol.for("react.memo_cache_sentinel")?(Re=t.jsxs(Ee,{htmlFor:"terminal-application",children:[t.jsx(Zt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Terminal application"]}),Ue=t.jsx(J,{children:"Leave blank to use the system default for Ctrl+Cmd+T."}),e[55]=Re,e[56]=Ue):(Re=e[55],Ue=e[56]);let Be;e[57]===Symbol.for("react.memo_cache_sentinel")?(Be=d=>$(d.target.value),e[57]=Be):Be=e[57];let pe;e[58]!==k?(pe=t.jsxs(le,{children:[Re,Ue,t.jsx(nt,{id:"terminal-application",value:k,onChange:Be,placeholder:"Ghostty, iTerm, or /path/to/binary",disabled:!p})]}),e[58]=k,e[59]=pe):pe=e[59];let Oe;e[60]===Symbol.for("react.memo_cache_sentinel")?(Oe=d=>G(d===!0),e[60]=Oe):Oe=e[60];let ge;e[61]!==A?(ge=t.jsx(Pt,{id:"use-built-in-editor",checked:A,onCheckedChange:Oe,disabled:!p}),e[61]=A,e[62]=ge):ge=e[62];let Me;e[63]===Symbol.for("react.memo_cache_sentinel")?(Me=t.jsxs(ht,{children:[t.jsxs(Ee,{htmlFor:"use-built-in-editor",children:[t.jsx(Qt,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Open files in Cogpit"]}),t.jsx(J,{children:"Files and diffs open in Cogpit’s file workspace instead of launching an external editor."})]}),e[63]=Me):Me=e[63];let be;e[64]!==ge?(be=t.jsxs(le,{orientation:"horizontal",children:[ge,Me]}),e[64]=ge,e[65]=be):be=e[65];let Ve;e[66]===Symbol.for("react.memo_cache_sentinel")?(Ve=t.jsxs(Ee,{htmlFor:"editor-application",children:[t.jsx(es,{"data-icon":"inline-start",className:"size-4 text-muted-foreground"}),"Editor application"]}),e[66]=Ve):Ve=e[66];const Ze=A?"Not used while files open in Cogpit.":"Leave blank to use $VISUAL or automatic detection.";let je;e[67]!==Ze?(je=t.jsx(J,{children:Ze}),e[67]=Ze,e[68]=je):je=e[68];let He;e[69]===Symbol.for("react.memo_cache_sentinel")?(He=d=>H(d.target.value),e[69]=He):He=e[69];const Qe=!p||A;let ve;e[70]!==P||e[71]!==Qe?(ve=t.jsx(nt,{id:"editor-application",value:P,onChange:He,placeholder:"cursor, code, zed, or /path/to/binary",disabled:Qe}),e[70]=P,e[71]=Qe,e[72]=ve):ve=e[72];let we;e[73]!==je||e[74]!==ve?(we=t.jsxs(le,{children:[Ve,je,ve]}),e[73]=je,e[74]=ve,e[75]=we):we=e[75];let Ne;e[76]!==E||e[77]!==M?(Ne=ys.map(d=>t.jsx(xs,{kind:d,value:E,onChange:W,disabled:!p,reportVersion:M},d)),e[76]=E,e[77]=M,e[78]=Ne):Ne=e[78];let Ge;e[79]===Symbol.for("react.memo_cache_sentinel")?(Ge=ks.map(d=>t.jsx(Ns,{kind:d,disabled:!p},d)),e[79]=Ge):Ge=e[79];let Se;e[80]!==ne||e[81]!==se||e[82]!==I||e[83]!==u||e[84]!==h||e[85]!==z?(Se=!w&&p&&t.jsx(rs,{networkAccess:u,setNetworkAccess:S,networkPassword:h,setNetworkPassword:_,showNetworkPassword:z,setShowNetworkPassword:T,hasExistingPassword:se,initialNetworkAccess:I,connectedDevices:ne,minPasswordLength:16}),e[80]=ne,e[81]=se,e[82]=I,e[83]=u,e[84]=h,e[85]=z,e[86]=Se):Se=e[86];let ye;e[87]!==xe||e[88]!==pe||e[89]!==be||e[90]!==we||e[91]!==Ne||e[92]!==Se?(ye=t.jsxs(Lt,{children:[xe,pe,be,we,Ne,Ge,Se]}),e[87]=xe,e[88]=pe,e[89]=be,e[90]=we,e[91]=Ne,e[92]=Se,e[93]=ye):ye=e[93];let ke;e[94]!==i?(ke=t.jsx(ce,{variant:"outline",onClick:i,children:"Cancel"}),e[94]=i,e[95]=ke):ke=e[95];let Ce;e[96]!==K||e[97]!==ae||e[98]!==c?(Ce=p&&t.jsx(ce,{disabled:!K||c,onClick:ae,children:c?t.jsxs(t.Fragment,{children:[t.jsx(it,{"data-icon":"inline-start",className:"size-4 animate-spin"}),"Saving..."]}):"Save"}),e[96]=K,e[97]=ae,e[98]=c,e[99]=Ce):Ce=e[99];let _e;e[100]!==ke||e[101]!==Ce?(_e=t.jsxs(Ft,{children:[ke,Ce]}),e[100]=ke,e[101]=Ce,e[102]=_e):_e=e[102];let $e;e[103]!==ye||e[104]!==_e?($e=t.jsxs(Rt,{className:"max-h-[calc(100dvh-2rem)] overflow-y-auto sm:max-w-lg",children:[De,ye,_e]}),e[103]=ye,e[104]=_e,e[105]=$e):$e=e[105];let We;return e[106]!==n||e[107]!==$e||e[108]!==ue?(We=t.jsx(Ut,{open:n,onOpenChange:ue,children:$e}),e[106]=n,e[107]=$e,e[108]=ue,e[109]=We):We=e[109],We}function $s(s){return s+1}function As(){}function Es(){}function zs(s){return s.json()}function Ts(s){return s.json()}export{Rs as ConfigDialog};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
(function(){"use strict";const ft=["codex","copilot","claude"],mt="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";function Be(t,e){const n=new TextEncoder().encode(e);let s="";for(const i of n)s+=String.fromCharCode(i);const o=btoa(s).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`${t}${o}`}function Re(t,e){if(!e.startsWith(t))return null;try{const n=e.slice(t.length).replace(/-/g,"+").replace(/_/g,"/"),s=atob(n),o=Uint8Array.from(s,i=>i.charCodeAt(0));return new TextDecoder().decode(o)}catch{return null}}function St(t){return{lossy:!1,owns:e=>typeof e=="string"&&e.startsWith(t),encode:e=>Be(t,e),decode:e=>Re(t,e)}}function wt(t){const e=new RegExp(`(${mt})\\.jsonl$`,"i").exec(t);return e?e[1]:null}const Mt={urlId:t=>t.replace(/\.jsonl$/,""),fileNameFromUrlId:t=>t.endsWith(".jsonl")?t:`${t}.jsonl`};function Et(t){return`'${t.replace(/'/g,"'\\''")}'`}function X(t,e){return e?[t,e]:[]}function st(t,e){var n;return((n=e.exec(t))==null?void 0:n[1])??null}const ot="[0-9a-f-]{36}",Nt="codex__",vt="copilot__",Pe=new Set(["default","plan","acceptEdits","dontAsk","auto"]),Ue={kind:"claude",displayName:"Claude Code",binName:"claude",dirName:{lossy:!0,owns:t=>typeof t=="string"&&!t.startsWith(Nt)&&!t.startsWith(vt),encode:t=>(t.replace(/[\\/]+$/,"")||t).replace(/[^a-zA-Z0-9]/g,"-"),decode:t=>{const e=/^([A-Za-z])--(.*)$/.exec(t);return e?`${e[1]}:\\${e[2].replace(/-/g,"\\")}`:"/"+t.replace(/^-/,"").replace(/-/g,"/")}},sessionFile:{name:t=>`${t}.jsonl`,sessionId:wt,...Mt},metadataFromHead:!0,resume:{command:t=>`claude --resume ${t}`,args:t=>["--resume",t]},launchArgs:{permissions:t=>t!=null&&t.mode?t.mode==="bypassPermissions"?["--dangerously-skip-permissions"]:[...Pe.has(t.mode)?["--permission-mode",t.mode]:[],...(t.allowedTools??[]).flatMap(e=>["--allowedTools",e]),...(t.disallowedTools??[]).flatMap(e=>["--disallowedTools",e])]:["--permission-mode","default"],model:t=>X("--model",t),effort:t=>X("--effort",t),fastTier:()=>[]},serviceTier:null,cli:{packageName:"@anthropic-ai/claude-code",homebrew:{name:"claude-code",cask:!1},wingetId:null,versionArgs:["--version"],selfUpdate:{args:["update"],matches:t=>t.endsWith("/.local/bin/claude")||t.endsWith("/.local/bin/claude.exe")||t.includes("/.local/share/claude/")},bundledBySdk:!0,homeDirName:".claude",homeEnvVar:null,installMarker:"projects",homeIsDiscoverable:!1,process:{by:"command",sessionIdFromCommand:t=>st(t,new RegExp(`--resume(?:=|\\s+)(${ot})`))??st(t,new RegExp(`--session-id(?:=|\\s+)(${ot})`))}},config:{rootDirName:".claude",instructions:[{in:"scope",path:"CLAUDE.md",scopes:["global","project"]},{in:"root",path:"CLAUDE.md",label:".claude/CLAUDE.md",scopes:["project"]}],settings:[{in:"root",path:"settings.json",scopes:["global"]},{in:"root",path:"settings.local.json",scopes:["project"]}],skillsDir:"skills",agentsDir:"agents",commandsDir:"commands",themesDir:"themes",pluginsDir:"plugins",pluginManifestDir:".claude-plugin"},contextWindow:{defaultLimit:1e6,limits:[{match:"claude-haiku-4-5",limit:2e5},{match:"claude-haiku-4-1",limit:2e5},{match:"claude-sonnet-4-5",limit:2e5},{match:"claude-opus-4-5",limit:2e5},{match:"claude-opus-4-1",limit:2e5}],compactBuffer:33e3,extendedContext:{marker:"[1m]",limit:1e6}},capabilities:{worktrees:!0,mcp:!0,slashCommands:!0,workflows:!0,agentTeams:!0,subagentTranscripts:!0,nestedSubagents:!1,sharing:!0,goals:"transcript",undo:!0,redo:!0,nativeRewind:!1,fileCheckpoints:!0,reasoningEffort:!0,fastTier:!0,imageInput:!0,midTurnSteering:!1,stopSession:!0,ultracode:!0,contextWindow:!0,externalProcesses:!1,accountSwitching:!0,modelFallbackNotices:!0,autoPermissionMode:"per-model",settingsApply:"live",turnLiveness:"transcript",tokenStreaming:!0,nativeFork:!1,namedSessions:!0}},Bt={appServerValue:"priority",cliConfigValue:"fast"},$e={kind:"codex",displayName:"Codex",binName:"codex",dirName:St(Nt),sessionFile:{name:(t,e=new Date)=>{const n=String(e.getFullYear()),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),i=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),f=String(e.getSeconds()).padStart(2,"0");return`${n}/${s}/${o}/rollout-${n}-${s}-${o}T${i}-${l}-${f}-${t}.jsonl`},sessionId:wt,...Mt},metadataFromHead:!1,resume:{command:(t,e)=>e?`codex -C ${Et(e)} resume ${t}`:`codex resume ${t}`,args:t=>["resume",t]},launchArgs:{permissions:t=>{const e=(t==null?void 0:t.mode)||"default";return e==="bypassPermissions"?["--dangerously-bypass-approvals-and-sandbox"]:["--sandbox",e==="plan"?"read-only":"workspace-write","-c",'approval_policy="never"']},model:t=>X("-m",t),effort:t=>t?["-c",`model_reasoning_effort=${JSON.stringify(t)}`]:[],fastTier:t=>t?["-c",`service_tier=${JSON.stringify(Bt.cliConfigValue)}`,"--enable","fast_mode"]:[]},serviceTier:Bt,cli:{packageName:"@openai/codex",homebrew:{name:"codex",cask:!1},wingetId:null,versionArgs:["--version"],selfUpdate:null,bundledBySdk:!1,homeDirName:".codex",homeEnvVar:"CODEX_HOME",installMarker:"",homeIsDiscoverable:!0,process:{by:"command",sessionIdFromCommand:t=>st(t,new RegExp(`codex(?:\\s+\\S+)*\\s+exec\\s+resume\\s+(${ot})`))}},config:{rootDirName:".codex",instructions:[{in:"scope",path:"AGENTS.md",scopes:["global","project"]}],settings:[{in:"root",path:"config.toml",scopes:["global","project"]}],skillsDir:"skills",agentsDir:"agents",commandsDir:"prompts",themesDir:null,pluginsDir:null,pluginManifestDir:null},contextWindow:{defaultLimit:272e3,limits:[],compactBuffer:0,extendedContext:null},capabilities:{worktrees:!1,mcp:!1,slashCommands:!1,workflows:!1,agentTeams:!1,subagentTranscripts:!0,nestedSubagents:!0,sharing:!1,goals:"thread-api",undo:!0,redo:!0,nativeRewind:!1,fileCheckpoints:!1,reasoningEffort:!0,fastTier:!0,imageInput:!0,midTurnSteering:!0,stopSession:!1,ultracode:!1,contextWindow:!1,externalProcesses:!1,accountSwitching:!1,modelFallbackNotices:!1,autoPermissionMode:"never",settingsApply:"next-turn",turnLiveness:"runtime",tokenStreaming:!0,nativeFork:!1,namedSessions:!1}},Fe={kind:"copilot",displayName:"GitHub Copilot CLI",binName:"copilot",dirName:St(vt),sessionFile:{name:t=>`${t}/events.jsonl`,sessionId:t=>{const e=new RegExp(`^(${mt})/events\\.jsonl$`,"i").exec(t);return e?e[1]:null},urlId:t=>{const e=new RegExp(`^(${mt})/events\\.jsonl$`,"i").exec(t);return e?e[1]:t.replace(/\.jsonl$/,"")},fileNameFromUrlId:t=>t.endsWith(".jsonl")?t:`${t}/events.jsonl`},metadataFromHead:!0,resume:{command:(t,e)=>e?`copilot -C ${Et(e)} --resume ${t}`:`copilot --resume ${t}`,args:t=>[`--resume=${t}`]},launchArgs:{permissions:t=>(t==null?void 0:t.mode)==="bypassPermissions"||(t==null?void 0:t.mode)==="auto"?["--allow-all"]:[],model:t=>X("--model",t),effort:t=>X("--reasoning-effort",t),fastTier:()=>[]},serviceTier:null,cli:{packageName:"@github/copilot",homebrew:{name:"copilot-cli",cask:!0},wingetId:"GitHub.Copilot",versionArgs:["--version"],selfUpdate:{args:["update"],matches:t=>t.endsWith("/.local/bin/copilot")||t==="/usr/local/bin/copilot"},bundledBySdk:!1,homeDirName:".copilot",homeEnvVar:"COPILOT_HOME",installMarker:"session-state",homeIsDiscoverable:!0,process:{by:"executable",sessionIdFromCommand:t=>st(t,new RegExp(`--resume(?:=|\\s+)(${ot})`))}},config:{rootDirName:".copilot",instructions:[{in:"scope",path:"AGENTS.md",scopes:["global","project"]}],settings:[{in:"root",path:"config.json",scopes:["global"]}],skillsDir:"skills",agentsDir:null,commandsDir:null,themesDir:null,pluginsDir:null,pluginManifestDir:null},contextWindow:{defaultLimit:2e5,limits:[],compactBuffer:0,extendedContext:null},capabilities:{worktrees:!1,mcp:!1,slashCommands:!1,workflows:!1,agentTeams:!1,subagentTranscripts:!1,nestedSubagents:!1,sharing:!1,goals:!1,undo:!0,redo:!1,nativeRewind:!0,fileCheckpoints:!1,reasoningEffort:!1,fastTier:!1,imageInput:!1,midTurnSteering:!0,stopSession:!0,ultracode:!1,contextWindow:!1,externalProcesses:!0,accountSwitching:!1,modelFallbackNotices:!1,autoPermissionMode:"always",settingsApply:"next-turn",turnLiveness:"runtime",tokenStreaming:!1,nativeFork:!0,namedSessions:!0}},De=Object.freeze({claude:Ue,codex:$e,copilot:Fe});function gt(t){return De[t]}const Rt={0:"\0",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" ",v:"\v"};function Pt(t,e){const n=t[e];if(n!=='"'&&n!=="'"&&n!=="`")return null;let s="",o=e+1;for(;o<t.length;){const i=t[o];if(i===n)return{endIndex:o+1,value:s};if(i!=="\\"){s+=i,o++;continue}if(o++,o>=t.length)return null;const l=t[o];if(l in Rt){s+=Rt[l],o++;continue}if(l===`
|
|
3
|
+
`){o++;continue}if(l==="\r"){o+=t[o+1]===`
|
|
4
|
+
`?2:1;continue}if(l==="x"&&/^[0-9a-fA-F]{2}$/.test(t.slice(o+1,o+3))){s+=String.fromCharCode(Number.parseInt(t.slice(o+1,o+3),16)),o+=3;continue}if(l==="u"){const f=t.slice(o+1).match(/^\{([0-9a-fA-F]+)\}/);if(f){const b=Number.parseInt(f[1],16);if(Number.isFinite(b)&&b<=1114111){s+=String.fromCodePoint(b),o+=f[0].length+1;continue}}const h=t.slice(o+1,o+5);if(/^[0-9a-fA-F]{4}$/.test(h)){s+=String.fromCharCode(Number.parseInt(h,16)),o+=5;continue}}s+=l,o++}return null}function ht(t){return t.type==="user"}function yt(t){return t.type==="assistant"}function Ut(t){return t.type==="progress"}function $t(t){return t.type==="system"}function Ft(t){return t.type==="summary"}function Oe(t){return t.type==="queue-operation"}function Dt(t){return t.type==="attachment"}function je(t){return t.type==="user"&&t.isCompactSummary===!0}function Ot(t){return t.type==="system"&&t.subtype==="compact_boundary"}function jt(t,e){let n=0;for(const s of t)e[s.name]=(e[s.name]??0)+1,s.isError&&n++;return n}function Lt(t,e){t.totalInputTokens+=e.input_tokens,t.totalOutputTokens+=e.output_tokens,t.totalCacheCreationTokens+=e.cache_creation_input_tokens??0,t.totalCacheReadTokens+=e.cache_read_input_tokens??0}function it(t){return{totalInputTokens:0,totalOutputTokens:0,totalCacheCreationTokens:0,totalCacheReadTokens:0,toolCallCounts:{},errorCount:0,totalDurationMs:0,turnCount:t}}function rt(t){const e=it(t.length);for(const n of t){n.tokenUsage&&Lt(e,n.tokenUsage),n.durationMs&&(e.totalDurationMs+=n.durationMs),e.errorCount+=jt(n.toolCalls,e.toolCallCounts);for(const s of n.subAgentActivity)e.errorCount+=jt(s.toolCalls,e.toolCallCounts),s.tokenUsage&&Lt(e,s.tokenUsage)}return e}function Q(t,e){var s,o;if(!t)return{...e};const n=(((s=t.output_tokens_details)==null?void 0:s.thinking_tokens)??0)+(((o=e.output_tokens_details)==null?void 0:o.thinking_tokens)??0);return{input_tokens:t.input_tokens+e.input_tokens,output_tokens:t.output_tokens+e.output_tokens,cache_creation_input_tokens:(t.cache_creation_input_tokens??0)+(e.cache_creation_input_tokens??0),cache_read_input_tokens:(t.cache_read_input_tokens??0)+(e.cache_read_input_tokens??0),speed:e.speed??t.speed,...t.output_tokens_details||e.output_tokens_details?{output_tokens_details:{thinking_tokens:n}}:{}}}const Le=/<(agent-message|teammate-message)([^>]*)>([\s\S]*?)<\/\1>/g,We=[/\bteammate_id=(?:"([^"]*)"|'([^']*)')/,/\bfrom=(?:"([^"]*)"|'([^']*)')/];function qe(t){for(const e of We){const n=t.match(e),s=(n==null?void 0:n[1])??(n==null?void 0:n[2]);if(s)return s}return null}function _t(t){let e=null,n=!1;const s=t.replace(Le,(o,i,l,f)=>(n=!0,e===null&&(e=qe(l)),f.trim()));return{sender:e,matched:n,body:n?s.trim():t}}function at(t){return typeof t=="string"?t:t.filter(e=>e.type==="text").map(e=>e.text).join(`
|
|
5
|
+
`)}function Wt(t){return t?typeof t=="string"?t:t.map(e=>e.type==="text"?e.text:"").filter(Boolean).join(`
|
|
6
|
+
`):""}function qt(t){if(!(t!=null&&t.trim()))return!1;const e=t.trimStart();return e.startsWith("<")?!e.includes("<task-notification>")&&!e.startsWith("<system-reminder>")&&!e.startsWith("<local-command-"):!0}const ze=/<task-notification>[\s\S]*?<\/task-notification>/g,Je=/<[^>]*>/g;function Qe(t){var n;if(((n=t.origin)==null?void 0:n.kind)==="task-notification")return!0;const e=at(t.message.content);return e.includes("<task-notification>")?e.replace(ze,"").replace(Je,"").trim()==="":!1}function Ve(t){if(!Dt(t))return null;const e=t.attachment;if(!e||e.type!=="queued_command"||e.commandMode!=="prompt")return null;const n=e.prompt;if(n==null)return null;const s=typeof n=="string"?n:at(n);if(!qt(s))return null;const o=e.origin;if((o==null?void 0:o.kind)==="peer"){const l=o.name??o.from??null;if(l)return{raw:s,sender:l,body:o.body??_t(s).body}}if((o==null?void 0:o.kind)==="human")return{raw:s,sender:null,body:s};const i=_t(s);return{raw:s,sender:i.sender,body:i.body}}const Ke=[["attributionAgent","agent"],["attributionSkill","skill"],["attributionPlugin","plugin"],["attributionMcpServer","mcpServer"],["attributionMcpTool","mcpTool"]];function Ge(t,e){let n=t;for(const[s,o]of Ke){const i=e[s];typeof i!="string"||!i||(n={...n,[o]:i})}return n}const He=/^This session is being continued from a previous conversation[\s\S]*?\n\nSummary:\s*\n/,Xe=/\n+(?:If you need specific details from before compaction|(?:Please c|C)ontinue the conversation from where it left off)[\s\S]*$/;function Ze(t){return at(t).trim().replace(He,"").replace(Xe,"").trim()}function Ye(t){if(t)return{trigger:t.trigger,preTokens:t.preTokens,postTokens:t.postTokens}}function lt(t,e){return{id:t.uuid??crypto.randomUUID(),userMessage:e,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:t.timestamp??"",durationMs:null,tokenUsage:null,model:null}}function tn(t){const e=[];let n=0;for(;n<t.length;){const s=t[n];if(s.kind==="tool_calls"){const o=s.toolCalls.findIndex(i=>i.name==="EnterPlanMode");if(o!==-1){const i=s.toolCalls[o],l=String(i.input.plan??""),f=s.timestamp,h=s.toolCalls.slice(0,o);h.length>0&&e.push({kind:"tool_calls",toolCalls:h,timestamp:s.timestamp});const b=[],T=s.toolCalls.slice(o+1),y=T.findIndex(k=>k.name==="ExitPlanMode");if(y!==-1){b.push(...T.slice(0,y));const k=T[y],p=k.input.path?String(k.input.path):void 0;let N="pending";k.result!==null&&(N=k.isError?"rejected":"approved"),e.push({kind:"plan_mode",plan:l,planFilePath:p,status:N,toolCalls:b,timestamp:f});const E=T.slice(y+1);E.length>0&&e.push({kind:"tool_calls",toolCalls:E,timestamp:s.timestamp}),n++;continue}else{b.push(...T);let k,p,N="pending",E=n+1;const M=[];for(;E<t.length;){const v=t[E];if(v.kind==="tool_calls"){const R=v.toolCalls.findIndex(F=>F.name==="ExitPlanMode");if(R!==-1){b.push(...v.toolCalls.slice(0,R)),k=v.toolCalls[R],p=k.input.path?String(k.input.path):void 0,k.result!==null&&(N=k.isError?"rejected":"approved");const F=v.toolCalls.slice(R+1);e.push({kind:"plan_mode",plan:l,planFilePath:p,status:N,toolCalls:b,timestamp:f}),e.push(...M),F.length>0&&e.push({kind:"tool_calls",toolCalls:F,timestamp:v.timestamp}),n=E+1;break}else b.push(...v.toolCalls),E++}else if(v.kind==="hook_event"||v.kind==="text"||v.kind==="queued_prompt"||v.kind==="agent_message")M.push(v),E++;else break}k||(e.push({kind:"plan_mode",plan:l,planFilePath:void 0,status:"pending",toolCalls:b,timestamp:f}),e.push(...M),n=E);continue}}}e.push(s),n++}return e}function en(t){return t.contentBlocks.some(e=>e.kind==="agent_message")?{...t,contentBlocks:t.contentBlocks.map(e=>{if(e.kind!=="agent_message")return e;const{reply:n,...s}=e;return s})}:t}function zt(t){var s;const e=t.map(en),n=new Map;for(const o of e)for(const i of o.contentBlocks){if(i.kind==="agent_message"){const l=n.get(i.sender);l?l.push(i):n.set(i.sender,[i]);continue}if(i.kind==="tool_calls")for(const l of i.toolCalls){if(l.name!=="SendMessage")continue;const f=l.input.to;if(typeof f!="string"||!f)continue;const h=(s=n.get(f))==null?void 0:s.shift();if(!h)continue;const b=l.input.summary;h.reply={summary:typeof b=="string"?b:"",timestamp:l.timestamp||i.timestamp||""}}}return e}function nn(t){const e=[];let n=!1;for(let s=0;s<t.length;s++){const o=t[s];if(Ft(o)||Ot(o)){n=!1;continue}if(ht(o)&&!o.isMeta){const i=o.message.content;if(n&&Array.isArray(i)&&i.some(f=>f.type==="tool_result"))continue;e.push(s),n=!0;continue}yt(o)&&!n&&(e.push(s),n=!0)}return e}function Jt(t){var D,S;const e=[],n=[];let s=null,o=0,i=null,l=null;function f(r){l&&(r.compactionSummary=l.summary,r.compactionMeta=l.meta,l=null)}let h=null;const b=new Map,T=new Set,y=new Map,k=new Map,p=new Set,N=new Map,E=[],M=new Map;function v(r,c){let m=M.get(r);m||(m=new Map,M.set(r,m)),m.set(c,(m.get(c)??0)+1)}function R(r,c){const m=M.get(r),d=m==null?void 0:m.get(c);return!m||!d?!1:(d===1?m.delete(c):m.set(c,d-1),!0)}function F(){for(const r of E)r.turn.contentBlocks.push(r.sender?{kind:"agent_message",sender:r.sender,body:r.body,timestamp:r.timestamp}:{kind:"queued_prompt",content:r.content,timestamp:r.timestamp});E.length=0}function j(r){if(!i)return;const c=y.get(r);if(!c||c.length===0)return;i.subAgentActivity.push(...c),y.delete(r);const m=p.has(r)?"background_agent":"sub_agent",d=k.get(r);if(d)d.messages.push(...c);else{const a={kind:m,messages:[...c]};i.contentBlocks.push(a),k.set(r,a)}}function L(){if(i){for(const r of i.toolCalls)j(r.id);for(const[r]of y)j(r);for(const r of i.contentBlocks)if(r.kind==="hook_event")for(const c of r.events){if(!(c.eventName==="PostToolUse"||c.eventName.startsWith("PostToolUse:"))||!c.toolUseId)continue;const d=i.toolCalls.find(a=>a.id===c.toolUseId);d&&(c.updatedToolOutput&&(d.outputReplacedByHook=!0),c.durationMs!==void 0&&(d.hookDurationMs=(d.hookDurationMs??0)+c.durationMs))}i.contentBlocks=tn(i.contentBlocks),e.push(i),s!==null&&n.push(s),s=null,i=null,k.clear()}}for(o=0;o<t.length;o++){const r=t[o];if(Ft(r)){L(),l={summary:r.summary};continue}if(Ot(r)){L(),l={meta:Ye(r.compactMetadata)};continue}if(je(r)){L(),s=o,i=lt(r,null),i.compactionSummary=Ze(r.message.content),i.compactionMeta=l==null?void 0:l.meta,l=null;continue}if($t(r)&&r.subtype==="away_summary"&&r.content){h={content:r.content,timestamp:r.timestamp};continue}if(Oe(r)){if(i&&r.operation==="enqueue"&&qt(r.content)){const c=_t(r.content);E.push({turn:i,content:r.content,timestamp:r.timestamp,sender:c.sender,body:c.body}),v(i,r.content)}continue}if(Dt(r)){const c=Ve(r);i&&c!==null&&!R(i,c.raw)&&E.push({turn:i,content:c.raw,timestamp:((D=r.attachment)==null?void 0:D.timestamp)??r.timestamp,sender:c.sender,body:c.body});continue}if(E.length>0){const c=ht(r)&&!r.isMeta?r.message.content:null;if(typeof c=="string"){const m=E.findIndex(d=>d.content===c);if(m>=0){const[d]=E.splice(m,1);R(d.turn,d.content)}}F()}if(ht(r)&&!r.isMeta){const c=r.message.content;if(typeof c!="string"&&Array.isArray(c)&&c.some(d=>d.type==="tool_result")&&i){for(const a of c)if(a.type==="tool_result"){const _=b.get(a.tool_use_id);_&&(_.turn.toolCalls[_.index].result=Wt(a.content),_.turn.toolCalls[_.index].isError=a.is_error===!0,b.delete(a.tool_use_id))}const d=r.toolUseResult;if(d!=null&&d.agentId){const a=((S=c.find(I=>I.type==="tool_result"))==null?void 0:S.tool_use_id)??"",_=N.get(a),u=p.has(a),C=[];if(Array.isArray(d.content))for(const I of d.content)I.type==="text"&&C.push(I.text);const g={agentId:d.agentId,parentToolUseId:a||void 0,agentName:(_==null?void 0:_.name)??null,subagentType:(_==null?void 0:_.subagentType)??null,type:"assistant",content:d.content,toolCalls:[],thinking:[],text:C,timestamp:r.timestamp??"",tokenUsage:d.usage?{input_tokens:d.usage.input_tokens??0,output_tokens:d.usage.output_tokens??0,cache_creation_input_tokens:d.usage.cache_creation_input_tokens??0,cache_read_input_tokens:d.usage.cache_read_input_tokens??0}:null,model:null,isBackground:u,prompt:d.prompt,status:d.status,durationMs:d.totalDurationMs,toolUseCount:d.totalToolUseCount};if(!k.get(a)){i.subAgentActivity.push(g);const w={kind:u?"background_agent":"sub_agent",messages:[g]};i.contentBlocks.push(w),k.set(a,w)}}continue}if(Qe(r)){const m={kind:"task_notification",content:at(c),timestamp:r.timestamp};if(i){i.contentBlocks.push(m);continue}s=o,i=lt(r,null),i.contentBlocks.push(m),f(i);continue}L(),s=o,i=lt(r,r.message.content),f(i),h&&(i.contentBlocks.push({kind:"recap",content:h.content,timestamp:h.timestamp}),h=null);continue}if(yt(r)){let c=function(){u.length>0&&(C.contentBlocks.push({kind:"tool_calls",toolCalls:[...u],timestamp:a}),u.length=0)},m=function(){if(_.length>0){const g=C.contentBlocks[C.contentBlocks.length-1];g&&g.kind==="thinking"?g.blocks.push(..._):C.contentBlocks.push({kind:"thinking",blocks:[..._],timestamp:a}),_.length=0}};i||(s=o,i=lt(r,null),f(i)),i.model=r.message.model,r.effort&&(i.effort=r.effort),i.attribution=Ge(i.attribution,r);const d=r.message.id;T.has(d)||(T.add(d),i.tokenUsage=Q(i.tokenUsage,r.message.usage));const a=r.timestamp??"",_=[],u=[],C=i;for(const g of r.message.content)if(g.type==="thinking"){c();const x=g;if(!x.thinking)continue;i.thinking.push(x),_.push(x)}else if(g.type==="text"){c(),m();const x=/<thinking>([\s\S]*?)<\/thinking>/g;let I=g.text,w;for(;(w=x.exec(g.text))!==null;){const $=w[1].trim();if($){const B={type:"thinking",thinking:$,signature:""};i.thinking.push(B),i.contentBlocks.push({kind:"thinking",blocks:[B],timestamp:a})}I=I.replace(w[0],"")}if(I=I.trim(),I){i.assistantText.push(I);const $=i.contentBlocks[i.contentBlocks.length-1];$&&$.kind==="text"?$.text.push(I):i.contentBlocks.push({kind:"text",text:[I],timestamp:a})}}else if(g.type==="tool_use"){m();const x={id:g.id,name:g.name,input:g.input,result:null,isError:!1,timestamp:r.timestamp??""},I=i.toolCalls.length;if(i.toolCalls.push(x),u.push(x),b.set(g.id,{turn:i,index:I}),g.name==="Task"||g.name==="Agent"){const w=g.input;w.run_in_background===!0&&p.add(g.id),N.set(g.id,{name:w.name??null,subagentType:w.subagent_type??null})}}m(),c();continue}if(Ut(r)&&r.data.type==="agent_progress"){const c=r.data,m=r.parentToolUseID??"";let d=null;if(c.message.type==="assistant"){const g=c.message.message,x=g.id,I=g.usage;I&&x&&!T.has(x)&&(T.add(x),d={input_tokens:I.input_tokens??0,output_tokens:I.output_tokens??0,cache_creation_input_tokens:I.cache_creation_input_tokens??0,cache_read_input_tokens:I.cache_read_input_tokens??0})}const a=c.message.type==="assistant"?c.message.message.model??null:null,_=N.get(m),u={agentId:c.agentId,parentToolUseId:m||void 0,agentName:(_==null?void 0:_.name)??null,subagentType:(_==null?void 0:_.subagentType)??null,type:c.message.type,content:c.message.message.content,toolCalls:[],thinking:[],text:[],timestamp:c.message.timestamp??r.timestamp??"",tokenUsage:d,model:a,isBackground:p.has(m)};if(c.message.type==="assistant"){const g=c.message.message.content;if(Array.isArray(g))for(const x of g)x.type==="thinking"?u.thinking.push(x.thinking):x.type==="text"?u.text.push(x.text):x.type==="tool_use"&&u.toolCalls.push({id:x.id,name:x.name,input:x.input,result:null,isError:!1,timestamp:c.message.timestamp??r.timestamp??""})}else if(c.message.type==="user"){const g=c.message.message.content;if(Array.isArray(g)){for(const x of g)if(x.type==="tool_result"){const I=y.get(m);if(I)for(const w of I){const $=w.toolCalls.find(B=>B.id===x.tool_use_id);$&&($.result=Wt(x.content),$.isError=x.is_error===!0)}}}}let C=y.get(m);C||(C=[],y.set(m,C)),C.push(u),i&&j(m);continue}if(Ut(r)&&r.data.type==="hook_progress"){const c=r.data,m=String(c.hook_event_name??c.hookEvent??"unknown"),d=c.hookSpecificOutput,a={eventName:m,source:c.source!==void 0?String(c.source):void 0,toolName:c.tool_name!==void 0?String(c.tool_name):void 0,toolUseId:c.tool_use_id!==void 0?String(c.tool_use_id):void 0,command:c.command!==void 0?String(c.command):void 0,output:c.output!==void 0?String(c.output):void 0,stderr:c.stderr!==void 0?String(c.stderr):void 0,exitCode:c.exit_code!==void 0?Number(c.exit_code):void 0,decision:c.decision!==void 0?String(c.decision):void 0,durationMs:c.duration_ms!==void 0?Number(c.duration_ms):void 0,updatedToolOutput:(d==null?void 0:d.updatedToolOutput)!==void 0?String(d.updatedToolOutput):void 0,sessionTitle:(d==null?void 0:d.sessionTitle)!==void 0?String(d.sessionTitle):void 0,worktreePath:(d==null?void 0:d.worktreePath)!==void 0?String(d.worktreePath):void 0,timestamp:r.timestamp??""};if(i){const _=i.contentBlocks[i.contentBlocks.length-1];_&&_.kind==="hook_event"?_.events.push(a):i.contentBlocks.push({kind:"hook_event",events:[a],timestamp:r.timestamp})}continue}if($t(r)&&r.subtype==="turn_duration"&&i){r.durationMs!==void 0&&r.durationMs!==null&&(i.durationMs=(i.durationMs??0)+r.durationMs);continue}}return F(),L(),{turns:zt(e),turnStartIndices:n}}function Qt(t){return Jt(t).turns}function Vt(){return!0}function Kt(t){const e=[];for(const n of t){const s=n.trim();if(s)try{e.push(JSON.parse(s))}catch{}}return e}function Gt(t){return Kt(t.split(`
|
|
7
|
+
`))}function Ht(t){const e={sessionId:"",version:"",gitBranch:"",cwd:"",slug:"",name:"",model:"",branchedFrom:void 0};for(const n of t)if(n.sessionId&&!e.sessionId&&(e.sessionId=n.sessionId),n.version&&!e.version&&(e.version=n.version),n.gitBranch&&!e.gitBranch&&(e.gitBranch=n.gitBranch),n.cwd&&!e.cwd&&(e.cwd=n.cwd),n.slug&&!e.slug&&(e.slug=n.slug),n.name&&!e.name&&(e.name=n.name),n.branchedFrom&&!e.branchedFrom&&(e.branchedFrom=n.branchedFrom),yt(n)&&n.message.model&&!e.model&&(e.model=n.message.model),e.sessionId&&e.version&&e.gitBranch&&e.cwd&&e.model)break;return e}function sn(t){return Ht(Kt(t))}function on(t,e){const n=Gt(t),s=Ht(n),o=Qt(n),i=e!=null&&e.skipStats?it(o.length):rt(o);return{...s,turns:o,stats:i,rawMessages:e!=null&&e.skipStats?[]:n,agentKind:"claude"}}function rn(t,e){const n=Gt(e);if(n.length===0)return t;const s=t.rawMessages,o=[...s,...n],i=nn(s),l=Math.max(0,t.turns.length-i.length);let f=Math.max(0,i.length-1);const h=new Set;for(const N of n)if(N.type==="progress"){const E=N.parentToolUseID;E&&h.add(E)}if(h.size>0)for(let N=f-1;N>=0;N--){const E=t.turns[l+N];if(E!=null&&E.toolCalls.some(M=>h.has(M.id))){f=N;break}}const b=i[f]??s.length,T=t.turns.slice(0,l+f),y=Qt(o.slice(b)),k=zt([...T,...y]),p=rt(k);return{sessionId:t.sessionId,version:t.version,gitBranch:t.gitBranch,cwd:t.cwd,slug:t.slug,name:t.name,model:t.model||k.length>0&&k[k.length-1].model||"",turns:k,stats:p,rawMessages:o,branchedFrom:t.branchedFrom,agentKind:t.agentKind}}const Xt="<task-notification>",an=/<task-id>([^<]+)<\/task-id>/g,ln=/<tool-use-id>([^<]+)<\/tool-use-id>/g;function W(t){return typeof t=="object"&&t!==null}function cn(t){const e=W(t.message)?t.message:null,n=e==null?void 0:e.content;return typeof n=="string"?[n]:Array.isArray(n)?n.filter(s=>W(s)&&typeof s.text=="string").map(s=>s.text):[]}function un(t){const e=[],n=new Set,s=new Set,o=new Set;function i(l,f){if(l.includes(Xt)){for(const h of l.matchAll(an))n.add(h[1]),f==null||f.add(h[1]);for(const h of l.matchAll(ln))n.add(h[1]),f==null||f.add(h[1])}}for(const l of t){if(l.type==="user"){const f=W(l.toolUseResult)?l.toolUseResult:null;if((f==null?void 0:f.status)==="async_launched"){const h=W(l.message)?l.message:null,T=(Array.isArray(h==null?void 0:h.content)?h.content:[]).filter(p=>W(p)&&p.type==="tool_result").map(p=>p.tool_use_id),y=[f.agentId,f.taskId,...T].filter(p=>typeof p=="string"&&p.length>0),k=[f.description,f.workflowName,f.summary].find(p=>typeof p=="string"&&p.length>0)??"";y.length>0&&e.push({ids:y,description:k})}for(const h of cn(l))i(h,o);continue}if(l.type==="assistant"){const f=W(l.message)?l.message:null,h=Array.isArray(f==null?void 0:f.content)?f.content:[];for(const b of h){if(!W(b)||b.type!=="tool_use"||b.name!=="TaskStop")continue;const T=W(b.input)?b.input:null,y=(T==null?void 0:T.task_id)??(T==null?void 0:T.shell_id);typeof y=="string"&&n.add(y)}continue}if(l.type==="attachment"){const f=W(l.attachment)?l.attachment:null;typeof(f==null?void 0:f.prompt)=="string"&&i(f.prompt,o);continue}if(l.type==="queue-operation"&&typeof l.content=="string"){const f=l.operation;i(l.content,f==="enqueue"?s:o)}}return{pendingDescriptions:e.filter(l=>!l.ids.some(f=>n.has(f))).map(l=>l.description),undeliveredNotifications:[...s].filter(l=>!o.has(l)).length}}function dn(t,e){return{status:"awaiting_agents",pendingQueue:e,pendingAgents:t.length,pendingAgentDescriptions:t.filter(n=>n.length>0)}}function pn(t){var l,f;let e=0,n=null,s=!1;function o(h,b){const T={status:h,pendingQueue:Math.max(0,e)};return b&&(T.toolName=b),T}function i(){return n??(n=un(t))}for(let h=t.length-1;h>=0;h--){const b=t[h];if(b.type!=="queue-operation"){if(b.type==="progress"){const T=b.data;if((T==null?void 0:T.type)==="hook_progress"&&(T.decision??((l=T.hookSpecificOutput)==null?void 0:l.permissionDecision))==="defer")return o("deferred");break}break}}for(let h=t.length-1;h>=0;h--){const b=t[h];if(b.type==="queue-operation"){if(typeof b.content=="string"&&b.content.includes(Xt))continue;const T=b.operation;T==="enqueue"?e++:(T==="dequeue"||T==="remove")&&e--;continue}if(b.type==="attachment"){const T=W(b.attachment)?b.attachment:null;(T==null?void 0:T.commandMode)==="task-notification"&&(s=!0);continue}if(b.type==="assistant"){const T=b.message,y=T==null?void 0:T.stop_reason;if(y==="end_turn"){const k=i();if(s||k.undeliveredNotifications>0)return o("processing");if(k.pendingDescriptions.length>0)return dn(k.pendingDescriptions,Math.max(0,e));let p=!1;for(let N=h-1;N>=0;N--){const E=t[N];if(E.type==="user"&&!E.isMeta){p=!0;break}}return o(p?"completed":"idle")}if(y==="tool_use"){const k=T==null?void 0:T.content,p=(f=k==null?void 0:k.findLast)==null?void 0:f.call(k,N=>N.type==="tool_use");return o("tool_use",p==null?void 0:p.name)}return o("thinking")}if(b.type==="user"){if(b.isMeta)continue;return o("processing")}if(b.type==="system"&&b.subtype==="terminal_reason"){const T=b.reason;if(T)return{status:"completed",terminalReason:T,pendingQueue:Math.max(0,e)};continue}b.type!=="summary"&&b.type==="system"&&b.subtype}return{status:"idle"}}function fn(t,e,n){const s=typeof t.sessionId=="string"?t.sessionId:"";return{record:{...t,sessionId:e,branchedFrom:{sessionId:s,turnIndex:n}},originalId:s}}function mn(t){return Jt(t).turnStartIndices}function Zt(t,e,n){if(!e)return;t.assistantText.push(e);const s=t.contentBlocks[t.contentBlocks.length-1];if((s==null?void 0:s.kind)==="text"){s.text.push(e);return}t.contentBlocks.push({kind:"text",text:[e],timestamp:n})}function Yt(t){return t.includes("*** Begin Patch")&&t.includes("*** End Patch")}function gn(t){if(!t.includes("apply_patch")||!t.includes("*** Begin Patch"))return[];const e=new Map;for(let l=0;l<t.length;l++){const f=Pt(t,l);if(f){if(Yt(f.value)){const h=t.slice(0,l).match(/(?:^|[;\n])\s*(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*$/);h&&e.set(h[1],f.value)}l=f.endIndex-1}}const n=[],s=new Set,o=/\btools\s*\.\s*apply_patch\s*\(/g;let i;for(;(i=o.exec(t))!==null;){let l=i.index+i[0].length;for(;/\s/.test(t[l]??"");)l++;const f=Pt(t,l),h=f?null:t.slice(l).match(/^([A-Za-z_$][\w$]*)/),b=(f==null?void 0:f.value)??(h?e.get(h[1]):void 0);!b||!Yt(b)||s.has(b)||(s.add(b),n.push(b))}return n}function te(t,e){if(!e||t.startsWith("/")||/^[A-Za-z]:[\\/]/.test(t))return t;const n=e.replace(/[\\/]+$/,""),s=t.replace(/^\.[\\/]/,"");return/^[A-Za-z]:[\\/]/.test(e)?`${n}\\${s.replace(/\//g,"\\")}`:`${n}/${s}`}function ee(t,e,n,s=""){var h,b;const o=[],i=/^\*\*\*\s+(Update File|Add File|Delete File):\s*(.+)$/gm,l=[];let f;for(;(f=i.exec(t))!==null;)l.push({action:f[1],filePath:f[2].trim(),headerIdx:f.index,startIdx:f.index+f[0].length});for(let T=0;T<l.length;T++){const y=l[T],k=T+1<l.length?l[T+1].headerIdx:t.length,p=t.slice(y.startIdx,k),N=(b=(h=p.match(/^\*\*\*\s+Move to:\s*(.+)$/m))==null?void 0:h[1])==null?void 0:b.trim(),E=te(y.filePath,s),M=te(N||y.filePath,s),v=p.split(/^@@.*$/m).filter(L=>L.trim()),R=[],F=[];for(const L of v)for(const D of L.split(`
|
|
8
|
+
`))D.startsWith("-")?R.push(D.slice(1)):D.startsWith("+")?F.push(D.slice(1)):D.startsWith(" ")&&(R.push(D.slice(1)),F.push(D.slice(1)));const j=l.length>1?`${e}:file-${T}`:e;y.action==="Add File"?o.push({id:j,name:"Write",input:{file_path:M,content:F.join(`
|
|
9
|
+
`)},result:null,isError:!1,timestamp:n}):y.action==="Delete File"?o.push({id:j,name:"Edit",input:{file_path:M,old_string:R.join(`
|
|
10
|
+
`),new_string:""},result:null,isError:!1,timestamp:n}):o.push({id:j,name:"Edit",input:{file_path:M,...N?{old_path:E}:{},old_string:R.join(`
|
|
11
|
+
`),new_string:F.join(`
|
|
12
|
+
`)},result:null,isError:!1,timestamp:n})}return o}function hn(t,e,n,s,o=""){return t==="apply_patch"?ee(e,n,s,o):gn(e).flatMap((i,l)=>ee(i,`${n}:patch-${l}`,s,o))}function yn(t,e,n){var f;if(!e||!/(?:apply[_ ]patch|invalid patch|invalid context|failed to (?:apply|find)|could not apply)/i.test(t))return new Set;const s=new Map;for(const h of n){const b=(f=h.id.match(/:patch-(\d+)(?::file-\d+)?$/))==null?void 0:f[1];if(b===void 0)continue;const T=Number(b),y=s.get(T)??[];y.push(h),s.set(T,y)}if(s.size===0)return new Set(n.map(h=>h.id));const o=t.toLowerCase().replaceAll("\\","/"),i=new Set;for(const[h,b]of s)b.some(T=>{const y=String(T.input.file_path??"").toLowerCase().replaceAll("\\","/");if(!y)return!1;const p=y.split("/").filter(Boolean).slice(-2).join("/");return o.includes(y)||p.includes("/")&&o.includes(p)})&&i.add(h);for(const h of o.matchAll(/\bpatch\s*(?:#|-)?\s*(\d+)\b/g)){const b=Number(h[1]);s.has(b)&&i.add(b)}i.size===0&&i.add(Math.max(...s.keys()));const l=Math.min(...i);for(const h of s.keys())h>=l&&i.add(h);return new Set([...i].flatMap(h=>{var b;return((b=s.get(h))==null?void 0:b.map(T=>T.id))??[]}))}function q(t){return typeof t=="object"&&t!==null}const _n=new Map([["spawn_agent","spawn_agent"],["spawnAgent","spawn_agent"],["wait_agent","wait_agent"],["waitAgent","wait_agent"],["send_message","send_message"],["sendMessage","send_message"],["followup_task","followup_task"],["followupTask","followup_task"],["list_agents","list_agents"],["listAgents","list_agents"],["interrupt_agent","interrupt_agent"],["interruptAgent","interrupt_agent"]]),kn=new Set(["exec","exec_command","write_stdin","apply_patch","update_plan","view_image","request_user_input","request_user_input_async","tool_search","list_mcp_resources","list_mcp_resource_templates","read_mcp_resource","request_plugin_install","create_goal","get_goal","update_goal","wait"]);function V(t){if(t.startsWith("mcp__"))return t;const e=t.split(/(?:__|[.:/])+/).filter(Boolean).at(-1)??t;return _n.get(e)??(kn.has(e)?e:t)}function bn(t){const e=t==null?void 0:t.match(/Process exited with code (\d+)/);return e?e[1]!=="0":!1}function Tn(t){return t==="request_user_input"||t==="request_user_input_async"}function Cn(t){const n=(Array.isArray(t.questions)?t.questions:[t]).filter(s=>q(s)).map(s=>{const o=typeof s.question=="string"?s.question:typeof s.title=="string"?s.title:"",i=Array.isArray(s.options)?s.options:[];return{question:o,...typeof s.header=="string"&&s.header?{header:s.header}:{},options:i.map(l=>typeof l=="string"?{label:l}:!q(l)||typeof l.label!="string"?null:{label:l.label,...typeof l.description=="string"&&l.description?{description:l.description}:{}}).filter(l=>l!==null)}}).filter(s=>s.question);return n.length>0?{...t,questions:n}:t}function xn(t){return{todos:(Array.isArray(t.plan)?t.plan:[]).filter(s=>q(s)).map(s=>({content:typeof s.step=="string"?s.step:"",status:typeof s.status=="string"?s.status:"pending",activeForm:typeof s.step=="string"?s.step:""}))}}function In(t){if(t.type!=="image"&&t.type!=="input_image"&&t.type!=="image_url")return null;const e=q(t.source)?t.source:t,n=e.media_type??e.mimeType;if(typeof n=="string"&&n.startsWith("image/")&&typeof e.data=="string"&&e.data)return{type:"image",source:{type:"base64",media_type:n,data:e.data}};const s=q(t.image_url)?t.image_url.url:t.image_url,o=typeof s=="string"?/^data:(image\/[^;,]+);base64,(.+)$/is.exec(s):null;return o?{type:"image",source:{type:"base64",media_type:o[1].toLowerCase(),data:o[2]}}:null}function ne(t){if(typeof t=="string")return{parts:[t],text:t,images:[]};if(!Array.isArray(t)){const s=t==null?"":JSON.stringify(t);return{parts:[s],text:s,images:[]}}const e=[],n=[];for(const s of t){if(!q(s))continue;typeof s.text=="string"&&e.push(s.text);const o=In(s);o&&n.push(o)}return{parts:e,text:e.join(""),images:n}}const An=/^Script (?:completed|failed|running)\b/;function se(t,e){q(t)&&(t.status==="rejected"?e.push(1):t.status==="fulfilled"?se(t.value,e):typeof t.exit_code=="number"&&e.push(t.exit_code))}function Sn(t){const e=t[0]??"";if(!An.test(e))return;if(e.startsWith("Script failed"))return!0;const n=[];for(const s of t.slice(1)){let o;try{o=JSON.parse(s)}catch{continue}for(const i of Array.isArray(o)?o:[o])se(i,n)}return n.length>0?n.some(s=>s!==0):void 0}function kt(t){const e=ne(t);let n=q(t)&&!Array.isArray(t)?t:null;try{const b=n??JSON.parse(e.text);q(b)&&!Array.isArray(b)&&(n=b)}catch{}const s=n&&("output"in n||"content"in n)?ne(n.output??n.content):e,o=s===e?e.images:[...e.images,...s.images],i=q(n==null?void 0:n.metadata)?n.metadata:null,l=(i==null?void 0:i.exit_code)??(n==null?void 0:n.exit_code),f=typeof(n==null?void 0:n.isError)=="boolean"?n.isError:typeof(n==null?void 0:n.is_error)=="boolean"?n.is_error:void 0,h=f===!0||(typeof l=="number"?l!==0:f??Sn(e.parts)??bn(s.text));return{text:s.text,isError:h,...o.length>0?{images:o}:{}}}const wn=["# AGENTS.md instructions for ","<recommended_plugins>","<environment_context>","<permissions instructions>","<collaboration_mode>","<skills_instructions>"];function Mn(t){var e,n;return((n=(e=globalThis.crypto)==null?void 0:e.randomUUID)==null?void 0:n.call(e))??`${t}-${Math.random().toString(36).slice(2,10)}`}function bt(t){try{return JSON.parse(t)}catch{return null}}function U(t){return typeof t=="object"&&t!==null}function K(t){return!t||typeof t.type!="string"?!1:t.type==="session_meta"||t.type==="turn_context"||t.type==="event_msg"||t.type==="response_item"||t.type==="inter_agent_communication_metadata"||t.type==="compacted"||t.type==="world_state"}function ct(t,e){const n=t==null?void 0:t.content;return Array.isArray(n)?n.filter(s=>U(s)&&s.type===e&&typeof s.text=="string").map(s=>s.text).join(`
|
|
13
|
+
`).trim():""}const En=/^data:(image\/(?:png|jpeg|gif|webp));base64,(.+)$/is,Nn=/^data:(audio\/(?:wav|x-wav|mpeg|mp4|webm|ogg));base64,(.+)$/is;function oe(t){if(typeof t!="string")return null;const e=En.exec(t);return!(e!=null&&e[1])||!e[2]?null:{type:"image",source:{type:"base64",media_type:e[1].toLowerCase(),data:e[2]}}}function ie(t){if(typeof t!="string")return null;const e=Nn.exec(t);return!(e!=null&&e[1])||!e[2]?null:{type:"audio",source:{type:"base64",media_type:e[1].toLowerCase(),data:e[2]}}}function vn(t){return Array.isArray(t.images)?t.images.map(oe).filter(e=>e!==null):[]}function Bn(t){return Array.isArray(t.audio)?t.audio.map(ie).filter(e=>e!==null):[]}function re(t){return Array.isArray(t.content)?t.content.filter(e=>U(e)&&e.type==="input_image").map(e=>oe(e.image_url)).filter(e=>e!==null):[]}function ae(t){return Array.isArray(t.content)?t.content.filter(e=>U(e)&&e.type==="input_audio").map(e=>ie(e.audio_url)).filter(e=>e!==null):[]}function le(t,e,n=[],s=[],o=[]){const i=[...s.map(f=>`
|
|
14
|
+
`),...o.map(f=>`
|
|
15
|
+
[audio attachment](<${f}>)`)].join(""),l=t+i;return e.length===0&&n.length===0?l:[...e,...n,...l?[{type:"text",text:l}]:[]]}function Rn(t){var l,f;const e=ct(t,"input_text");if(!e)return{messageType:null,text:""};const n=e.match(/\r?\nPayload:\s*(?:\r?\n|$)/);if(!e.startsWith("Message Type:")||!n||n.index===void 0)return{messageType:null,text:e.trim()};const o=((f=(l=e.slice(0,n.index).match(/^Message Type:\s*([^\r\n]+)/))==null?void 0:l[1])==null?void 0:f.trim().toUpperCase())??null,i=e.slice(n.index+n[0].length).trim();return{messageType:o,text:i}}function Z(t){return t.split(/[\\/]/).filter(Boolean).at(-1)??null}function Pn(t){if(typeof t!="string")return"";const e=t.trim();return/^gAAAAA[A-Za-z0-9_-]+$/.test(e)?"":e}function Tt(t){const e=t.trim();return!e||wn.some(n=>e.startsWith(n))?"":e}function Un(t){if(!U(t))return null;const e=typeof t.input_tokens=="number"?t.input_tokens:0,n=typeof t.output_tokens=="number"?t.output_tokens:0,s=typeof t.cache_write_input_tokens=="number"?t.cache_write_input_tokens:typeof t.cache_creation_input_tokens=="number"?t.cache_creation_input_tokens:0,o=typeof t.cached_input_tokens=="number"?Math.max(0,t.cached_input_tokens):null,i=o??(typeof t.cache_read_input_tokens=="number"?t.cache_read_input_tokens:0),l=o===null?e:Math.max(0,e-o);return l===0&&n===0&&s===0&&i===0?null:{input_tokens:l,output_tokens:n,cache_creation_input_tokens:s,cache_read_input_tokens:i}}function $n(t,e,n){if(!e)return;const s={type:"thinking",thinking:e,signature:""};t.thinking.push(s);const o=t.contentBlocks[t.contentBlocks.length-1];if(o&&o.kind==="thinking"){o.blocks.push(s);return}t.contentBlocks.push({kind:"thinking",blocks:[s],timestamp:n})}function G(t,e,n){t.toolCalls.push(e);const s=t.contentBlocks[t.contentBlocks.length-1];if(s&&s.kind==="tool_calls"&&s.timestamp===n){s.toolCalls.push(e);return}t.contentBlocks.push({kind:"tool_calls",toolCalls:[e],timestamp:n})}function Fn(t,e,n){if(!e||!(e.userMessage!==null||e.assistantText.length>0||e.toolCalls.length>0||e.thinking.length>0||e.subAgentActivity.length>0))return null;if(e.timestamp&&n){const o=new Date(e.timestamp).getTime(),i=new Date(n).getTime();Number.isFinite(o)&&Number.isFinite(i)&&i>=o&&(e.durationMs=i-o)}return t.push(e),null}function ce(t){if(typeof t!="string"||!t.trim())return{};try{const e=JSON.parse(t);return U(e)?e:{value:e}}catch{return{raw:t}}}function Y(t){if(typeof t=="string")return t;try{return JSON.stringify(t)}catch{return String(t??"")}}function ue(...t){return t.find(e=>typeof e=="string")}function Dn(t){return t.startsWith("exec-")}function On(t){var o;if(!U(t))return{text:Y(t),isError:!1};if("Err"in t)return{text:Y(t.Err),isError:!0};const e=U(t.Ok)?t.Ok:null;if(!e)return{text:Y(t),isError:!1};const n=kt({...e,content:e.content}),s=n.text||((o=n.images)!=null&&o.length?"":e.structuredContent!==void 0?Y(e.structuredContent):Y(e));return{...n,text:s,isError:n.isError}}function jn(t,e,n){return{id:t?`${t}@${e}`:Mn("codex-turn"),userMessage:null,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:e,durationMs:null,tokenUsage:null,model:n}}function de(t){return t.type==="event_msg"&&U(t.payload)&&t.payload.type==="user_message"&&typeof t.payload.message=="string"?Tt(t.payload.message):t.type==="response_item"&&U(t.payload)&&t.payload.type==="message"&&t.payload.role==="user"?Tt(ct(t.payload,"input_text")):""}function Ln(t,e){if(t.type==="session_meta"||t.type==="event_msg"&&(e==null?void 0:e.type)==="task_started")return!1;if(t.type==="response_item"&&(e==null?void 0:e.type)==="message"){if(e.role==="developer"||e.role==="system")return!1;if(e.role==="user")return de(t)!==""||re(e).length>0||ae(e).length>0}return!0}function pe(t){let e="",n="",s="",o="",i="",l,f="",h="",b="",T="",y=0,k=!1,p=null,N="/root",E="";for(const M of t){if(!U(M.payload))continue;if(M.type==="session_meta"){if(e||(e=typeof M.payload.id=="string"?M.payload.id:""),n||(n=typeof M.payload.cli_version=="string"?M.payload.cli_version:""),o||(o=typeof M.payload.cwd=="string"?M.payload.cwd:""),!l&&U(M.payload.branchedFrom)){const j=typeof M.payload.branchedFrom.sessionId=="string"?M.payload.branchedFrom.sessionId:"";j&&(l={sessionId:j,turnIndex:typeof M.payload.branchedFrom.turnIndex=="number"?M.payload.branchedFrom.turnIndex:null})}const R=U(M.payload.source)?M.payload.source:null;if(R&&U(R.subagent)){k=!0;const j=U(R.subagent.thread_spawn)?R.subagent.thread_spawn:null;j&&typeof j.agent_path=="string"&&(N=j.agent_path)}typeof M.payload.forked_from_id=="string"&&M.payload.forked_from_id&&(p=M.payload.forked_from_id);const F=U(M.payload.git)?M.payload.git:null;s||(s=F&&typeof F.branch=="string"?F.branch:"")}M.type==="turn_context"&&(i||(i=typeof M.payload.model=="string"?M.payload.model:""),o||(o=typeof M.payload.cwd=="string"?M.payload.cwd:""));const v=de(M);v&&v!==E&&(f||(f=v),h=v,E=v,y++,b||(b=M.timestamp??""),T=M.timestamp??T)}return T===""&&(T=b),{sessionId:e,version:n,gitBranch:s,cwd:o,model:i,slug:"",name:"",branchedFrom:l,firstUserMessage:f,lastUserMessage:h,timestamp:b,lastTimestamp:T,turnCount:y,isSubagent:k,parentSessionId:p,agentPath:N}}function Wn(t){for(const e of t.split(`
|
|
16
|
+
`)){const n=e.trim();if(n)return K(bt(n))}return!1}function qn(t){return K(t[0]??null)}function zn(t){const e=t.map(bt).filter(K);return pe(e)}function fe(t,e){const n=pe(t.filter(K)),s=[],o=new Map,i=new Map,l=new Map,f=new Map,h=new Map,b=new Map,T=new Map,y=new Map;function k(m,d,a,_={}){const u=h.get(m);let C=y.get(m);if(!C){const x={agentId:m,parentToolUseId:(u==null?void 0:u.parentToolCallId)||void 0,agentName:(u==null?void 0:u.nickname)??(u!=null&&u.agentPath?Z(u.agentPath):null),subagentType:(u==null?void 0:u.agentType)??null,type:"assistant",content:null,toolCalls:[],thinking:[],text:[],timestamp:(u==null?void 0:u.timestamp)??a,tokenUsage:null,model:(u==null?void 0:u.model)??null,isBackground:!1,prompt:(u==null?void 0:u.message)||void 0,status:_.status??"running"};d.subAgentActivity.push(x);const I=d.contentBlocks[d.contentBlocks.length-1];(I==null?void 0:I.kind)==="sub_agent"?I.messages.push(x):d.contentBlocks.push({kind:"sub_agent",messages:[x],timestamp:a}),C={message:x,turn:d},y.set(m,C)}const g=C.message;if(u&&(g.parentToolUseId=u.parentToolCallId||g.parentToolUseId,g.agentName=u.nickname??(u.agentPath?Z(u.agentPath):g.agentName),g.subagentType=u.agentType,g.model=u.model,g.prompt=u.message||g.prompt),_.text&&!g.text.includes(_.text)&&(g.text.push(_.text),g.content=g.text.join(`
|
|
17
|
+
|
|
18
|
+
`)),_.status){const x=new Set(["completed","failed","interrupted"]);if(_.status==="running"&&g.status&&x.has(g.status)||(g.status=_.status),x.has(_.status)&&g.timestamp&&a){const I=new Date(g.timestamp).getTime(),w=new Date(a).getTime();Number.isFinite(I)&&Number.isFinite(w)&&w>=I&&(g.durationMs=w-I)}}return g}let p=null,N=null,E=n.model||null,M="",v=null,R=!1;const F=[];let j=0,L=null,D=null;function S(m){const d=s.length,a=Fn(s,m,M);return s.length>d&&D!==null&&F.push(D),D=null,a}function r(m,d,a){const _=jn(m,d,a);return D=L??j,L=null,R||(_.isFragment=!0),v&&(_.compactionSummary=v,v=null),_}function c(m,d,a,_,u){const C=i.get(d);if(C){C.input={...C.input,...a},C.result=_,C.isError=_==="failed";return}const g={id:d,name:"WebSearch",input:a,result:_,isError:_==="failed",timestamp:u};i.set(d,g),G(m,g,u)}for(let m=0;m<t.length;m++){const d=t[m];if(!K(d))continue;j=m;const a=U(d.payload)?d.payload:void 0,_=d.timestamp??"";if(d.type==="compacted"){p=S(p),v="Conversation compacted",M=_;continue}if(d.type!=="world_state"){if(d.type==="turn_context"){p=S(p),L=m,N=typeof(a==null?void 0:a.turn_id)=="string"?a.turn_id:null,E=typeof(a==null?void 0:a.model)=="string"?a.model:E,M=_,R=!0;continue}if(d.type==="event_msg"&&(a==null?void 0:a.type)==="user_message"&&typeof a.message=="string"){p&&(p.assistantText.length>0||p.toolCalls.length>0||p.thinking.length>0)&&(p=S(p)),R=!0,p??(p=r(N,_,E));const u=(Array.isArray(a.local_images)?a.local_images:[]).filter(g=>typeof g=="string"&&g.length>0),C=(Array.isArray(a.local_audio)?a.local_audio:[]).filter(g=>typeof g=="string"&&g.length>0);p.userMessage=le(a.message,vn(a),Bn(a),u,C),p.isFragment=!1,p.timestamp=p.timestamp||_,M=_;continue}if(!(!p&&!Ln(d,a))){if(p??(p=r(N,_,E)),!p.model&&E&&(p.model=E),p.timestamp||(p.timestamp=_),_&&(M=_),d.type==="event_msg"&&(a==null?void 0:a.type)==="token_count"){const u=U(a.info)?a.info:null,C=u?Un(u.last_token_usage):null;C&&(p.tokenUsage=Q(p.tokenUsage,C));continue}if(d.type==="event_msg"&&(a==null?void 0:a.type)==="web_search_end"&&typeof a.call_id=="string"){const u={};typeof a.query=="string"&&a.query&&(u.query=a.query),U(a.action)&&(u.action=a.action),c(p,a.call_id,u,"completed",_);continue}if(d.type==="event_msg"&&(a==null?void 0:a.type)==="mcp_tool_call_end"&&typeof a.call_id=="string"&&U(a.invocation)){const u=a.invocation,C=typeof u.server=="string"?u.server:"mcp",g=typeof u.tool=="string"?u.tool:"tool",x=U(u.arguments)?u.arguments:{},I=On(a.result),w=o.get(a.call_id);w?(w.result=I.text,w.isError=I.isError,I.images&&(w.resultImages=I.images),o.delete(a.call_id)):Dn(a.call_id)||G(p,{id:a.call_id,name:`mcp__${C}__${g}`,input:x,result:I.text,isError:I.isError,...I.images?{resultImages:I.images}:{},timestamp:_},_);continue}if(d.type==="event_msg"&&(a==null?void 0:a.type)==="sub_agent_activity"&&typeof a.agent_thread_id=="string"&&typeof a.agent_path=="string"){const u=a.agent_thread_id,C=typeof a.event_id=="string"?a.event_id:"",g=typeof a.kind=="string"?a.kind:"started",x=C?f.get(C):void 0,I=b.get(a.agent_path),w=h.get(u)??(I?h.get(I):void 0);if(g!=="started"&&!w&&!x)continue;if(I&&I!==u&&!y.has(u)){const P=y.get(I);P&&(P.message.agentId=u,y.delete(I),y.set(u,P)),h.delete(I)}const $={agentId:u,nickname:(w==null?void 0:w.nickname)??Z(a.agent_path)??(x==null?void 0:x.taskName)??null,agentPath:a.agent_path,message:(w==null?void 0:w.message)??(x==null?void 0:x.message)??"",model:(w==null?void 0:w.model)??(x==null?void 0:x.model)??null,agentType:(w==null?void 0:w.agentType)??(x==null?void 0:x.agentType)??null,timestamp:(w==null?void 0:w.timestamp)??(_||(x==null?void 0:x.timestamp)||""),parentToolCallId:(w==null?void 0:w.parentToolCallId)??C};h.set(u,$),b.set(a.agent_path,u),C&&(g==="started"||x)&&T.set(C,u),k(u,p,_,{status:g==="interrupted"?"interrupted":"running"});continue}if(!(d.type!=="response_item"||!a)){if(a.type==="reasoning"){const u=Array.isArray(a.summary)?a.summary.filter(C=>typeof C=="string").join(`
|
|
19
|
+
`):"";$n(p,u.trim(),_);continue}if(a.type==="message"&&a.role==="assistant"){Zt(p,ct(a,"output_text"),_);continue}if(a.type==="message"&&a.role==="user"&&p.userMessage===null){const u=Tt(ct(a,"input_text")),C=re(a),g=ae(a);(u||C.length>0||g.length>0)&&(p.userMessage=le(u,C,g),p.isFragment=!1,R=!0);continue}if(a.type==="web_search_call"&&typeof a.id=="string"){const u={};U(a.action)&&(u.action=a.action);const C=typeof a.status=="string"?a.status:"completed";c(p,a.id,u,C,_);continue}if(a.type==="tool_search_call"){const u=ue(a.call_id,a.id)??"";if(u){const C={id:u,name:"ToolSearch",input:U(a.arguments)?a.arguments:{},result:null,isError:!1,timestamp:_};o.set(u,C),G(p,C,_)}continue}if(a.type==="tool_search_output"&&typeof a.call_id=="string"){const u=o.get(a.call_id);if(u){const C=Array.isArray(a.tools)?a.tools:[],g=C.filter(U).map(w=>ue(w.name)??"").filter(Boolean),x=g.length>0?g.length:C.length,I=`Found ${x} tool${x===1?"":"s"}`;u.result=g.length>0?`${I}: ${g.join(", ")}`:I,u.isError=a.status==="failed",o.delete(a.call_id)}continue}if(a.type==="agent_message"&&typeof a.author=="string"){const u=a.author,C=typeof a.recipient=="string"?a.recipient:null,g=Rn(a);if(g.messageType==="NEW_TASK")continue;const x=b.get(u),I=u.startsWith(`${n.agentPath}/`)&&(C===null||C===n.agentPath);if(!x&&!I)continue;const w=x??u;x||(h.set(w,{agentId:w,nickname:Z(u),agentPath:u,message:"",model:null,agentType:null,timestamp:_,parentToolCallId:""}),b.set(u,w));let $;g.messageType==="FINAL_ANSWER"?$="completed":g.messageType==="ERROR"||g.messageType==="FAILED"?$="failed":g.messageType==="INTERRUPTED"?$="interrupted":g.messageType==="MESSAGE"&&($="running"),k(w,p,_,{status:$,text:g.text||void 0});continue}if(a.type==="function_call"&&typeof a.call_id=="string"){const u=typeof a.name=="string"?a.name:"tool",C=V(u),g=ce(a.arguments);let x=C,I=g;C==="exec_command"?x="Bash":C==="update_plan"?(x="TodoWrite",I=xn(g)):Tn(C)&&(x="AskUserQuestion",I=Cn(g)),C==="spawn_agent"&&f.set(a.call_id,{callId:a.call_id,message:Pn(g.message),taskName:typeof g.task_name=="string"?g.task_name:null,model:typeof g.model=="string"?g.model:null,agentType:typeof g.agent_type=="string"?g.agent_type:null,timestamp:_});const w={id:a.call_id,name:x,input:I,result:null,isError:!1,timestamp:_,...C==="request_user_input_async"?{asyncQuestion:!0}:{}};o.set(w.id,w),G(p,w,_);continue}if(a.type==="function_call_output"&&typeof a.call_id=="string"){const u=o.get(a.call_id);if(!u)continue;const C=kt(a.output),g=C.text;if(u.result=g,u.isError=C.isError,C.images&&(u.resultImages=C.images),o.delete(a.call_id),u.name==="spawn_agent"&&g)try{const x=JSON.parse(g),I=typeof x.agent_id=="string"?x.agent_id:T.get(u.id)??"",w=typeof x.task_name=="string"?x.task_name:null,$=typeof x.nickname=="string"?x.nickname:w?Z(w):null;if(I){const B=f.get(u.id),P=h.get(I),H={agentId:I,nickname:$??(P==null?void 0:P.nickname)??(B==null?void 0:B.taskName)??null,agentPath:w??(P==null?void 0:P.agentPath)??null,message:(P==null?void 0:P.message)??(B==null?void 0:B.message)??"",model:(P==null?void 0:P.model)??(B==null?void 0:B.model)??null,agentType:(P==null?void 0:P.agentType)??(B==null?void 0:B.agentType)??null,timestamp:(P==null?void 0:P.timestamp)??(B==null?void 0:B.timestamp)??_,parentToolCallId:(P==null?void 0:P.parentToolCallId)??u.id};h.set(I,H),T.set(u.id,I),H.agentPath&&b.set(H.agentPath,I),k(I,p,_,{status:"running"})}}catch{}if(u.name==="wait_agent"&&g&&p)try{const x=JSON.parse(g),I=U(x.status)?x.status:{};for(const[w,$]of Object.entries(I)){const B=U($)?$:{},P=typeof B.completed=="string"?B.completed:"",H=typeof B.failed=="string"?B.failed:typeof B.error=="string"?B.error:"",ve=typeof B.interrupted=="string"?B.interrupted:"",As=P?"completed":H?"failed":ve?"interrupted":typeof B.status=="string"?B.status:"running";h.has(w)||h.set(w,{agentId:w,nickname:null,agentPath:null,message:"",model:null,agentType:null,timestamp:_,parentToolCallId:""}),k(w,p,_,{status:As,text:P||H||ve||void 0})}}catch{}continue}if(a.type==="custom_tool_call"&&typeof a.call_id=="string"){const u=V(typeof a.name=="string"?a.name:"tool"),C=typeof a.input=="string"?a.input:"",g=a.call_id,x=C?hn(u,C,g,_,n.cwd):[];if(u!=="apply_patch"){const I={id:g,name:u==="exec_command"?"Bash":u,input:ce(C),result:null,isError:!1,timestamp:_};o.set(I.id,I),G(p,I,_)}for(const I of x)o.set(I.id,I),G(p,I,_);x.length>0&&l.set(g,{calls:x,direct:u==="apply_patch"});continue}if(a.type==="custom_tool_call_output"&&typeof a.call_id=="string"){const u=a.call_id,{text:C,isError:g,images:x}=kt(a.output),I=l.get(u);if(I){const $=I.direct&&g?new Set(I.calls.map(B=>B.id)):yn(C,g,I.calls);for(const B of I.calls){const P=o.get(B.id);P&&(P.result=C,P.isError=$.has(P.id),o.delete(P.id))}l.delete(u)}const w=o.get(u);w&&(w.result=C,w.isError=g,x&&(w.resultImages=x),o.delete(u));continue}}}}}return S(p),{turnStartIndices:F,sessionId:n.sessionId,version:n.version,gitBranch:n.gitBranch,cwd:n.cwd,slug:n.slug,name:"",model:n.model,turns:s,stats:e!=null&&e.skipStats?it(s.length):rt(s),rawMessages:e!=null&&e.skipStats?[]:t,branchedFrom:n.branchedFrom,agentKind:"codex"}}function me(t,e){const n=t.split(`
|
|
20
|
+
`).map(i=>i.trim()).filter(Boolean).map(bt).filter(K),{turnStartIndices:s,...o}=fe(n,e);return o}function Jn(t,e){const n=t.rawMessages.map(s=>JSON.stringify(s)).join(`
|
|
21
|
+
`);return me(n?`${n}
|
|
22
|
+
${e}`:e)}const Qn=new Set(["FINAL_ANSWER","ERROR","FAILED","INTERRUPTED"]);function Vn(t){const e=t.content;return Array.isArray(e)?e.filter(n=>U(n)&&n.type==="input_text"&&typeof n.text=="string").map(n=>n.text).join(`
|
|
23
|
+
`):""}function ut(t){if(typeof t!="string")return null;try{const e=JSON.parse(t);return U(e)?e:null}catch{return null}}function Kn(t){var h,b;const e=new Map,n=new Set,s=new Map,o=new Map,i=new Set,l=new Map;function f(T,y){n.has(T)||e.set(T,e.get(T)||y)}for(const T of t){const y=U(T.payload)?T.payload:null;if(y){if(T.type==="event_msg"&&y.type==="sub_agent_activity"&&typeof y.agent_thread_id=="string"&&typeof y.agent_path=="string"){const k=y.agent_thread_id,p=typeof y.kind=="string"?y.kind:"started",N=typeof y.event_id=="string"?y.event_id:"",E=s.get(y.agent_path),M=e.has(k)||n.has(k)||E!==void 0||o.has(N);if(p!=="started"&&!M)continue;E&&E!==k&&(e.has(E)&&(f(k,e.get(E)??""),e.delete(E)),n.has(E)&&n.add(k)),s.set(y.agent_path,k),p==="interrupted"?(n.add(k),e.delete(k)):f(k,o.get(N)??"");continue}if(T.type==="response_item"){if(y.type==="function_call"&&typeof y.call_id=="string"){const k=V(typeof y.name=="string"?y.name:"");if(k==="spawn_agent"){const p=ut(y.arguments);o.set(y.call_id,typeof(p==null?void 0:p.task_name)=="string"?p.task_name:"")}else if(k==="wait_agent")i.add(y.call_id);else if(k==="interrupt_agent"){const p=ut(y.arguments),N=[p==null?void 0:p.agent_id,...Array.isArray(p==null?void 0:p.agent_ids)?p.agent_ids:[]].filter(E=>typeof E=="string");l.set(y.call_id,N)}continue}if(y.type==="function_call_output"&&typeof y.call_id=="string"){const k=y.call_id;if(o.has(k)){const p=ut(y.output),N=typeof(p==null?void 0:p.agent_id)=="string"?p.agent_id:"";if(N){f(N,o.get(k)??"");const E=typeof(p==null?void 0:p.task_name)=="string"?p.task_name:"";E&&!s.has(E)&&s.set(E,N)}}else if(i.has(k)){const p=ut(y.output),N=U(p==null?void 0:p.status)?p.status:{};for(const[E,M]of Object.entries(N)){const v=U(M)?M:{},R=typeof v.status=="string"?v.status:"";(typeof v.completed=="string"||typeof v.failed=="string"||typeof v.error=="string"||typeof v.interrupted=="string"||R==="completed"||R==="failed"||R==="interrupted")&&(n.add(E),e.delete(E))}}else if(l.has(k))for(const p of l.get(k)??[])n.add(p),e.delete(p);continue}if(y.type==="agent_message"&&typeof y.author=="string"){const p=((b=(h=Vn(y).match(/^Message Type:\s*([^\r\n]+)/))==null?void 0:h[1])==null?void 0:b.trim().toUpperCase())??"";if(!Qn.has(p))continue;const N=s.get(y.author)??y.author;n.add(N),e.delete(N)}}}}return[...e.entries()].filter(([T])=>!n.has(T)).map(([,T])=>T)}function Gn(t){for(let e=t.length-1;e>=0;e--){const n=t[e];if(n.type==="event_msg"){const s=n.payload;switch(s==null?void 0:s.type){case"task_complete":{const o=Kn(t);return o.length>0?{status:"awaiting_agents",pendingQueue:0,pendingAgents:o.length,pendingAgentDescriptions:o.filter(i=>i.length>0)}:{status:"completed"}}case"task_started":return{status:"processing"};case"agent_message":return{status:"thinking"};case"token_count":continue}}if(n.type==="response_item"){const s=n.payload;if(!s)continue;if(s.type==="function_call")return{status:"tool_use",toolName:s.name?V(s.name):s.name};if(s.type==="message"){if(s.role==="assistant")return{status:"thinking"};if(s.role==="user")return{status:"processing"}}}}return{status:"idle"}}function Hn(t,e,n){const s=U(t.payload)?{...t.payload}:{},o=typeof s.id=="string"?s.id:"";return s.id=e,s.branchedFrom={sessionId:o,turnIndex:n},{record:{...t,payload:s},originalId:o}}function Xn(t){return fe(t,{skipStats:!0}).turnStartIndices}const Zn=/^(?:assistant|auto_mode|auto_mode_switch|background_tasks|canvas|command|custom|elicitation|exit_plan_mode|extensions|external_tool|factory|hook|managed_settings|mcp|model|pending_messages|permission|sampling|session|skill|subagent|system|tool|ui|user_input)\./;function O(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function ge(t){return typeof t.agentId!="string"||t.agentId.length===0}function he(t){return!O(t)||typeof t.type!="string"||!O(t.data)?!1:t.type==="abort"||t.type==="binary_asset"||t.type==="user.message"||Zn.test(t.type)}function ye(t){try{const e=JSON.parse(t);return he(e)?e:null}catch{return null}}function Yn(t){return t.split(`
|
|
24
|
+
`).map(e=>e.trim()).filter(Boolean).map(ye).filter(e=>e!==null)}function A(...t){return t.find(e=>typeof e=="string")??""}function z(t){return typeof t=="number"&&Number.isFinite(t)?t:0}function tt(t){return typeof t.timestamp=="string"?t.timestamp:""}function J(t,e){var n,s;return typeof t.id=="string"&&t.id?t.id:((s=(n=globalThis.crypto)==null?void 0:n.randomUUID)==null?void 0:s.call(n))??`${e}-${Math.random().toString(36).slice(2,10)}`}function _e(t){const e=J(t,"copilot-turn"),n=A(t.data.turnId);return n?`${n}@${e}`:e}function Ct(t,e){if(!O(t))return;const n=A(t.cwd),s=A(t.branch);n&&(e.cwd=n),s&&(e.gitBranch=s)}function ke(t){const e={sessionId:"",version:"",gitBranch:"",cwd:"",model:"",slug:"",name:"",firstUserMessage:"",lastUserMessage:"",timestamp:"",lastTimestamp:"",turnCount:0,isSubagent:!1,parentSessionId:null};for(const n of t){if(!ge(n))continue;const{data:s}=n,o=tt(n);if(o&&(e.lastTimestamp=o),n.type==="session.start"){e.sessionId||(e.sessionId=A(s.sessionId)),e.version||(e.version=A(s.copilotVersion)||(typeof s.version=="number"?String(s.version):A(s.version))),Ct(s.context,e),e.model=A(s.selectedModel)||e.model;continue}if(n.type==="session.resume"){Ct(s.context,e),e.model=A(s.selectedModel)||e.model;continue}if(n.type==="session.context_changed"){Ct(s,e);continue}if(n.type==="session.auto_mode_resolved"){e.model=A(s.chosenModel)||e.model;continue}if(n.type==="session.model_change"){e.model=A(s.newModel)||e.model;continue}if(n.type==="session.title_changed"){e.name=A(s.title)||e.name;continue}if(n.type==="session.shutdown"){e.model=A(s.currentModel)||e.model;continue}if((n.type==="assistant.turn_start"||n.type==="assistant.turn_end"||n.type==="assistant.message"||n.type==="assistant.usage"||n.type==="tool.execution_start"||n.type==="tool.execution_complete")&&(e.model=A(s.model)||e.model),n.type!=="user.message")continue;e.turnCount++,e.timestamp||(e.timestamp=o);const i=A(s.content).trim();i&&(e.firstUserMessage||(e.firstUserMessage=i),e.lastUserMessage=i)}return e.lastTimestamp||(e.lastTimestamp=e.timestamp),e}function ts(t){for(const e of t.split(`
|
|
25
|
+
`)){const n=e.trim();if(n)try{const s=JSON.parse(n);if(he(s))return!0}catch{}}return!1}function es(t){var e;return gs((e=t[0])==null?void 0:e.type)}function ns(t){const e=t.map(n=>ye(n.trim())).filter(n=>n!==null);return ke(e)}function xt(t){if(typeof t=="string")return t;if(t===void 0)return"";try{return JSON.stringify(t)}catch{return String(t)}}function be(t){return typeof t=="string"?t:Array.isArray(t)?t.flatMap(e=>{const n=typeof e=="string"?e:O(e)?A(e.text,e.content):"";return n?[n]:[]}).join(`
|
|
26
|
+
`):""}function ss(t){const e=new Map;for(const n of t){if(n.type!=="session.binary_asset"&&n.type!=="binary_asset")continue;const s=A(n.data.assetId),o=A(n.data.data),i=A(n.data.mimeType);s&&o&&i&&e.set(s,{data:o,mimeType:i})}return e}function os(t,e){if(!O(t))return null;const n=e.get(A(t.assetId)),s=A(t.mimeType,n==null?void 0:n.mimeType).toLowerCase(),o=A(t.data,n==null?void 0:n.data);return!s.startsWith("image/")||!o?null:{type:"image",source:{type:"base64",media_type:s,data:o}}}function Te(t,e){if(!Array.isArray(t))return[];const n=[],s=new Set;for(const o of t){const i=os(o,e);if(!i)continue;const l=`${i.source.media_type}:${i.source.data}`;s.has(l)||(s.add(l),n.push(i))}return n}function is(t,e){const n=A(t.content),s=Te(t.attachments,e);return s.length===0?n:[...s,...n?[{type:"text",text:n}]:[]]}function rs(t,e){return O(t.result)?Te([...Array.isArray(t.result.contents)?t.result.contents:[],...Array.isArray(t.result.binaryResultsForLlm)?t.result.binaryResultsForLlm:[]],e):[]}function It(t,e=!1){const n=z(t.cacheWriteTokens),s=z(t.cacheReadTokens),o=z(t.inputTokens),i={input_tokens:e?Math.max(0,o-n-s):o,output_tokens:z(t.outputTokens),cache_creation_input_tokens:n,cache_read_input_tokens:s},l=z(t.reasoningTokens);return l&&(i.output_tokens_details={thinking_tokens:l}),i.input_tokens===0&&i.output_tokens===0&&i.cache_creation_input_tokens===0&&i.cache_read_input_tokens===0&&l===0?null:i}function as(t){if(!O(t.modelMetrics))return null;let e=null;for(const n of Object.values(t.modelMetrics)){if(!O(n)||!O(n.usage))continue;const s=It(n.usage,!0);s&&(e=Q(e,s))}return e}function ls(t){if(typeof t=="string")return{label:t};if(!O(t))return null;const e=A(t.label,t.title,t.value,t.name);if(!e)return null;const n=A(t.description);return n?{label:e,description:n}:{label:e}}function cs(t){return Array.isArray(t)?t.map(ls).filter(e=>e!==null):[]}function us(t){if(!O(t))return null;const e=A(t.question,t.prompt,t.text,t.message);if(!e)return null;const n=A(t.header,t.title),s=typeof t.multiSelect=="boolean"?t.multiSelect:typeof t.multi_select=="boolean"?t.multi_select:void 0;return{question:e,...n?{header:n}:{},options:cs(t.options??t.choices),...s===void 0?{}:{multiSelect:s}}}function ds(t){const n=(Array.isArray(t.questions)?t.questions:[t]).map(us).filter(s=>s!==null);return n.length>0?{...t,questions:n}:t}function et(t){switch(t.toLowerCase().replace(/-/g,"_")){case"ask_user":return"AskUserQuestion";case"bash":case"powershell":case"shell":return"Bash";case"create":return"Write";case"edit":return"Edit";default:return t}}function dt(t,e){const n=O(e)?e:e===void 0?{}:{value:e};return t==="AskUserQuestion"?ds(n):t==="Edit"?{...n,file_path:A(n.file_path,n.path),old_string:A(n.old_string,n.old_str),new_string:A(n.new_string,n.new_str)}:t==="Write"?{...n,file_path:A(n.file_path,n.path),content:A(n.content,n.file_text)}:t==="Bash"&&typeof n.command!="string"&&typeof n.cmd=="string"?{...n,command:n.cmd}:n}function ps(t){const e=t.error;if(typeof e=="string")return e;if(O(e)){const s=A(e.message,e.code);if(s)return s}const n=t.result;if(typeof n=="string")return n;if(!O(n))return n===void 0?"":xt(n);if(typeof n.detailedContent=="string")return n.detailedContent;if(typeof n.content=="string")return n.content;if(Array.isArray(n.contents)){const s=n.contents.flatMap(o=>{const i=typeof o=="string"?o:O(o)?A(o.text,o.content,o.output):"";return i?[i]:[]}).join(`
|
|
27
|
+
`);if(s)return s}return n.structuredContent!==void 0?xt(n.structuredContent):xt(n)}function Ce(t,e,n,s){if(!e||t.thinking.some(l=>l.thinking===e))return;const o={type:"thinking",thinking:e,signature:s};t.thinking.push(o);const i=t.contentBlocks[t.contentBlocks.length-1];if((i==null?void 0:i.kind)==="thinking"){i.blocks.push(o);return}t.contentBlocks.push({kind:"thinking",blocks:[o],timestamp:n})}function pt(t,e,n){t.toolCalls.push(e);const s=t.contentBlocks[t.contentBlocks.length-1];if((s==null?void 0:s.kind)==="tool_calls"){s.toolCalls.push(e);return}t.contentBlocks.push({kind:"tool_calls",toolCalls:[e],timestamp:n})}function nt(t,e,n,s){return{id:t,name:e,input:n,result:null,isError:!1,timestamp:s}}function xe(t,e,n){if(!Array.isArray(t))return[];const s=[];for(const o of t){if(!O(o))continue;const i=A(o.toolCallId),l=A(o.name);if(!i||!l||n(i))continue;const f=et(l);s.push(nt(i,f,dt(f,o.arguments),e))}return s}function Ie(t,e,n,s){t.name=e,t.input=dt(e,n),t.timestamp=s||t.timestamp}function Ae(t,e,n){t.result=ps(e);const s=rs(e,n);s.length>0&&(t.resultImages=s),t.isError=e.success===!1||e.error!==void 0&&e.error!==null}function Se(t,e,n,s,o,i){return{id:t,userMessage:n,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:e,durationMs:null,tokenUsage:null,model:s,...o?{effort:o}:{},...i?{isFragment:!0}:{}}}function fs(t){return t.userMessage!==null||t.assistantText.length>0||t.thinking.length>0||t.toolCalls.length>0||t.subAgentActivity.length>0}function we(t,e){const n=Yn(t),s=ke(n),o=ss(n),i=[],l=new Map,f=new Map,h=new Map,b=new WeakMap,T=new WeakMap;let y=null,k=null,p,N=!1,E=!1,M=null;function v(S,r){r&&b.set(S,r)}function R(S){return y||(y=Se(_e(S),tt(S),null,k,p,!0)),y}function F(){y&&(fs(y)&&i.push(y),y=null)}function j(S){var C;const r=typeof S.agentId=="string"?S.agentId:"";if(!r)return null;const c=f.get(r);if(c)return c.message;const m=S.data,d=A(m.toolCallId),a=d?((C=l.get(d))==null?void 0:C.turn)??y:y;if(!a)return null;const _=A(m.executionMode),u={agentId:r,...d?{parentToolUseId:d}:{},agentName:A(m.agentDisplayName,m.agentName)||null,subagentType:A(m.agentType,m.agentName)||null,type:"assistant",content:null,toolCalls:[],thinking:[],text:[],timestamp:tt(S),tokenUsage:null,model:A(m.model)||null,isBackground:_==="background",...A(m.description)?{prompt:A(m.description)}:{},status:"running"};return a.subAgentActivity.push(u),a.contentBlocks.push({kind:u.isBackground?"background_agent":"sub_agent",messages:[u],timestamp:u.timestamp}),f.set(r,{message:u,turn:a}),u}function L(S){if(ge(S))return!1;const r=j(S);if(!r)return!0;const{data:c}=S,m=tt(S);if(S.type==="subagent.started"||S.type==="subagent.configured")return r.parentToolUseId||(r.parentToolUseId=A(c.toolCallId)||void 0),r.agentName=A(c.agentDisplayName,c.agentName)||r.agentName,r.subagentType=A(c.agentType,c.agentName)||r.subagentType,r.model=A(c.model)||r.model,r.prompt||(r.prompt=A(c.description)||void 0),r.isBackground||(r.isBackground=A(c.executionMode)==="background"),r.status="running",!0;if(S.type==="subagent.completed"||S.type==="subagent.failed"){r.agentName=A(c.agentDisplayName,c.agentName)||r.agentName,r.subagentType=A(c.agentType,c.agentName)||r.subagentType,r.model=A(c.model)||r.model,r.durationMs=z(c.durationMs)||r.durationMs,r.toolUseCount=z(c.totalToolCalls)||r.toolUseCount,r.status=S.type==="subagent.completed"?"completed":"failed";const d=A(c.error,c.message);return d&&!r.text.includes(d)&&r.text.push(d),!0}if(S.type==="user.message")return r.prompt||(r.prompt=A(c.content)||void 0),!0;if(S.type==="assistant.reasoning"){const d=A(c.content);return d&&!r.thinking.includes(d)&&r.thinking.push(d),!0}if(S.type==="assistant.message"){r.model=A(c.model)||r.model;const d=A(c.reasoningText);d&&!r.thinking.includes(d)&&r.thinking.push(d);const a=be(c.content);a&&!r.text.includes(a)&&r.text.push(a);for(const _ of xe(c.toolRequests,m,u=>h.has(u)))r.toolCalls.push(_),h.set(_.id,{call:_,message:r});return!0}if(S.type==="assistant.usage"){r.model=A(c.model)||r.model;const d=It(c);return d&&(r.tokenUsage=Q(r.tokenUsage,d)),!0}if(S.type==="tool.execution_start"){const d=A(c.toolCallId)||J(S,"copilot-agent-tool"),a=A(c.toolName)||"Tool",_=et(a),u=h.get(d);if(u)Ie(u.call,_,c.arguments,m);else{const C=nt(d,_,dt(_,c.arguments),m);r.toolCalls.push(C),h.set(d,{call:C,message:r})}return!0}if(S.type==="tool.execution_complete"){const d=A(c.toolCallId)||J(S,"copilot-agent-tool");let a=h.get(d);if(!a){const _=A(c.toolName)||"Tool",u=et(_),C=nt(d,u,{},m);r.toolCalls.push(C),a={call:C,message:r}}return Ae(a.call,c,o),h.delete(d),!0}return!0}for(const S of n){if(L(S))continue;const{data:r}=S,c=tt(S);if(S.type==="session.start"||S.type==="session.resume"){k=A(r.selectedModel)||k,p=A(r.reasoningEffort)||p;continue}if(S.type==="session.auto_mode_resolved"){k=A(r.chosenModel)||k,y&&(y.model=k);continue}if(S.type==="session.model_change"){k=A(r.newModel)||k;const m=r.reasoningEffort;typeof m=="string"&&(p=m),y&&(y.model=k,p&&(y.effort=p));continue}if(S.type==="session.shutdown"){k=A(r.currentModel)||k,y&&!y.model&&(y.model=k),M=as(r)??M;const m=z(r.totalApiDurationMs);y&&!E&&m&&T.set(y,m);continue}if(S.type==="user.message"){F(),y=Se(_e(S),c,is(r,o),k,p,!1),v(y,c);continue}if(S.type==="assistant.turn_start"){k=A(r.model)||k;const m=R(S);m.model=k,p&&(m.effort=p),v(m,c);continue}if(S.type==="assistant.reasoning"){const m=R(S);Ce(m,A(r.content),c,A(r.reasoningId)||J(S,"copilot-thinking")),v(m,c);continue}if(S.type==="assistant.message"){k=A(r.model)||k;const m=R(S);m.model=k,p&&(m.effort=p),Ce(m,A(r.reasoningText),c,J(S,"copilot-thinking")),Zt(m,be(r.content),c);for(const d of xe(r.toolRequests,c,a=>l.has(a)))pt(m,d,c),l.set(d.id,{call:d,turn:m});v(m,c);continue}if(S.type==="assistant.usage"){k=A(r.model)||k,p=A(r.reasoningEffort)||p;const m=It(r),d=z(r.duration);m&&(N=!0),d&&(E=!0);const a=R(S);a.model=k,p&&(a.effort=p),m&&(a.tokenUsage=Q(a.tokenUsage,m)),d&&T.set(a,(T.get(a)??0)+d),v(a,c);continue}if(S.type==="tool.execution_start"){k=A(r.model)||k;const m=R(S);m.model=k;const d=A(r.toolCallId)||J(S,"copilot-tool"),a=A(r.toolName)||"Tool",_=et(a),u=l.get(d);if(u)Ie(u.call,_,r.arguments,c);else{const C=nt(d,_,dt(_,r.arguments),c);pt(m,C,c),l.set(d,{call:C,turn:m})}v(m,c);continue}if(S.type==="tool.execution_complete"){k=A(r.model)||k;const m=A(r.toolCallId)||J(S,"copilot-tool");let d=l.get(m);if(!d){const a=R(S),_=A(r.toolName)||"Tool",u=et(_),C=nt(m,u,{},c);pt(a,C,c),d={call:C,turn:a}}Ae(d.call,r,o),l.delete(m),v(d.turn,c);continue}if(S.type==="session.error"){const m=R(S),a={errorType:A(r.errorType)||"unknown"};typeof r.statusCode=="number"&&(a.statusCode=r.statusCode),typeof r.errorCode=="string"&&(a.errorCode=r.errorCode),pt(m,{id:J(S,"copilot-error"),name:"Error",input:a,result:A(r.message)||"Copilot session error",isError:!0,timestamp:c},c),v(m,c);continue}(S.type==="assistant.turn_end"||S.type==="assistant.idle"||S.type==="session.idle")&&y&&v(y,c)}if(F(),!N&&M&&i.length===1&&(i[0].tokenUsage=Q(i[0].tokenUsage,M)),s.model)for(const S of i)S.model||(S.model=s.model);for(const S of i){const r=b.get(S),c=Date.parse(S.timestamp),m=r?Date.parse(r):Number.NaN;if(Number.isFinite(c)&&Number.isFinite(m)&&m>=c)S.durationMs=m-c;else{const d=T.get(S)??0;d&&(S.durationMs=d)}}const D=e!=null&&e.skipStats?it(i.length):rt(i);return!(e!=null&&e.skipStats)&&!N&&M&&i.length>1&&(D.totalInputTokens=M.input_tokens,D.totalOutputTokens=M.output_tokens,D.totalCacheCreationTokens=M.cache_creation_input_tokens??0,D.totalCacheReadTokens=M.cache_read_input_tokens??0),{sessionId:s.sessionId,version:s.version,gitBranch:s.gitBranch,cwd:s.cwd,slug:s.slug,name:s.name,model:s.model,turns:i,stats:D,rawMessages:e!=null&&e.skipStats?[]:n,agentKind:"copilot"}}function ms(t,e){const n=t.rawMessages.map(s=>JSON.stringify(s)).join(`
|
|
28
|
+
`);return we(n?`${n}
|
|
29
|
+
${e}`:e)}function gs(t){return typeof t=="string"&&(t==="abort"||t==="binary_asset"||t==="user.message"||t.startsWith("assistant.")||t.startsWith("permission.")||t.startsWith("session.")||t.startsWith("subagent.")||t.startsWith("tool.")||t.startsWith("user_input."))}function hs(t){const e=new Map;for(const o of t){const i=typeof o.agentId=="string"?o.agentId:"";if(!i&&(o.type==="abort"||o.type==="session.shutdown"||o.type==="session.error")){e.clear();continue}if(!i||!o.type.startsWith("subagent."))continue;const l=O(o.data)?o.data:{};if(o.type==="subagent.completed"||o.type==="subagent.failed"){e.delete(i);continue}if(o.type==="subagent.started"||o.type==="subagent.configured"){const f=[l.agentDisplayName,l.description,l.agentName].find(h=>typeof h=="string")??"";e.set(i,f||e.get(i)||"")}}if(e.size>0){const o=[...e.values()];return{status:"awaiting_agents",pendingQueue:0,pendingAgents:o.length,pendingAgentDescriptions:o.filter(i=>i.length>0)}}let n=!1;const s=new Set;for(let o=t.length-1;o>=0;o--){const i=t[o];if(typeof i.agentId=="string"&&i.agentId)continue;const l=O(i.data)?i.data:{};switch(i.type){case"abort":case"session.shutdown":return{status:"completed"};case"assistant.turn_end":{for(let f=o-1;f>=0;f--){const h=t[f];if(typeof h.agentId=="string"&&h.agentId)continue;if(h.type==="user.message")break;if(h.type==="abort")return{status:"completed"};if(h.type!=="assistant.message")continue;const b=O(h.data)?h.data:{};return Array.isArray(b.toolRequests)&&b.toolRequests.length>0?{status:"processing"}:{status:"completed"}}return{status:"processing"}}case"session.error":return{status:"completed",terminalReason:typeof l.message=="string"?l.message:"Copilot session error"};case"assistant.idle":case"session.idle":return{status:n?"completed":"idle"};case"permission.completed":{const f=typeof l.requestId=="string"?l.requestId:"";f&&s.add(f);continue}case"permission.requested":{const f=typeof l.requestId=="string"?l.requestId:"";if(f&&s.has(f))continue;return{status:"deferred"}}case"user_input.requested":return{status:"tool_use",toolName:"AskUserQuestion"};case"tool.execution_start":return s.size>0?{status:"thinking"}:{status:"tool_use",toolName:typeof l.toolName=="string"?V(l.toolName):typeof l.name=="string"?V(l.name):void 0};case"tool.execution_complete":return{status:"thinking"};case"assistant.turn_start":return{status:"processing"};case"assistant.message":case"assistant.message_delta":case"assistant.reasoning":case"assistant.reasoning_delta":return{status:"thinking"};case"user.message":return n=!0,{status:"processing"};case"session.start":case"session.resume":return{status:n?"processing":"idle"}}}return{status:"idle"}}function ys(){throw new Error("Copilot sessions branch through the CLI's fork API, not by copying the transcript")}function _s(t){const e=[];for(let n=0;n<t.length;n++){const s=t[n];if(s.type!=="user.message"||typeof s.agentId=="string")continue;const o=s.data;!o||typeof o!="object"||Array.isArray(o)||typeof s.id!="string"||!s.id||e.push(n)}return e}const Me=ft[ft.length-1],ks={kind:"codex",descriptor:gt("codex"),detectsText:Wn,detectsRecords:qn,parse:me,append:Jn,metadataFromLines:zn,status:Gn,brandBranch:Hn,turnBoundaries:Xn},bs={kind:"copilot",descriptor:gt("copilot"),detectsText:ts,detectsRecords:es,parse:we,append:ms,metadataFromLines:ns,status:hs,brandBranch:ys,turnBoundaries:_s},Ts={kind:"claude",descriptor:gt("claude"),detectsText:Vt,detectsRecords:Vt,parse:on,append:rn,metadataFromLines:sn,status:pn,brandBranch:fn,turnBoundaries:mn},At=Object.freeze({claude:Ts,codex:ks,copilot:bs});function Ee(t){for(const e of ft)if(t(At[e]))return At[e];return At[Me]}function Ne(t){return Ee(e=>e.detectsText(t))}function Cs(t){return Ee(e=>e.detectsRecords(t))}function xs(t,e){return Ne(t).parse(t,e)}function Is(t,e){const n=Cs(t.rawMessages);return(n.kind===Me?Ne(e):n).append(t,e)}self.onmessage=t=>{const e=t.data;try{let n;e.type==="parse"?n=xs(e.text):n=Is(e.existing,e.newText),self.postMessage({type:"result",id:e.id,session:n})}catch(n){self.postMessage({type:"error",id:e.id,error:n instanceof Error?n.message:String(n)})}}})();
|