cogpit 2.6.6 → 2.7.4
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 +16883 -10322
- package/dist/web/assets/{CommandPaletteHost-iiTEkWGR.js → CommandPaletteHost-ByD_7YRK.js} +1 -1
- package/dist/web/assets/ConfigBrowser-vXK8JNMg.js +1 -0
- package/dist/web/assets/{HighlightedEditor-7K1IXoMd.js → HighlightedEditor-BwET41dr.js} +1 -1
- package/dist/web/assets/{KeyboardShortcutsDialog-C7QHuM2e.js → KeyboardShortcutsDialog-DQuepxQo.js} +1 -1
- package/dist/web/assets/{MobileFileChanges-qnY-uxZ_.js → MobileFileChanges-B6rggNR6.js} +1 -1
- package/dist/web/assets/PluginsDialog-DTF9NnK7.js +1 -0
- package/dist/web/assets/{PreviewPanel-DBIaGXu0.js → PreviewPanel-BaXxki5D.js} +1 -1
- package/dist/web/assets/ProjectFilesPanel-CO6Znhgi.js +4 -0
- package/dist/web/assets/{ProjectSwitcherModal-BhevYH6F.js → ProjectSwitcherModal-Chi-U3vv.js} +1 -1
- package/dist/web/assets/{TerminalOutput-DnTT9ONj.js → TerminalOutput-CUmbXM9h.js} +1 -1
- package/dist/web/assets/{ThemeSelectorModal-GimQk0yY.js → ThemeSelectorModal-B2m42_1f.js} +1 -1
- package/dist/web/assets/WorkflowsPanel-CiYzHaQg.js +1 -0
- package/dist/web/assets/{WorktreePanel-DbSH2Fyv.js → WorktreePanel-CldMZY3n.js} +1 -1
- package/dist/web/assets/{index-7fgSFumo.js → index-BA1eUNuR.js} +4 -4
- package/dist/web/assets/{index-j1RyyaFQ.js → index-C-0I_ZqI.js} +1 -1
- package/dist/web/assets/index-C6wvrmo0.js +221 -0
- package/dist/web/assets/index-CYN2JttE.js +1 -0
- package/dist/web/assets/index-DYWsIgvZ.css +1 -0
- package/dist/web/assets/index-QH_v3Ygj.js +1 -0
- package/dist/web/assets/session-parser.worker-CnA52U1J.js +29 -0
- package/dist/web/assets/vendor-ui-ZKZkD5k3.js +887 -0
- package/dist/web/index.html +3 -3
- package/package.json +8 -2
- package/dist/web/assets/ConfigBrowser-CV_FDTPG.js +0 -1
- package/dist/web/assets/ProjectFilesPanel-DdllBXuv.js +0 -4
- package/dist/web/assets/WorkflowsPanel-BTeZdY1F.js +0 -1
- package/dist/web/assets/index-Bl7YHn3e.js +0 -1
- package/dist/web/assets/index-C640apmk.css +0 -1
- package/dist/web/assets/index-CVF75nuK.js +0 -153
- package/dist/web/assets/index-CmAiGDkv.js +0 -1
- package/dist/web/assets/session-parser.worker-DlF00ZHH.js +0 -29
- package/dist/web/assets/vendor-ui-C4lFQWec.js +0 -937
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r,c as ye,j as s}from"./vendor-react-gGw_S5I_.js";import{w as Me,bP as Pe,b2 as $e,bQ as Ve,bR as Ft,_ as Re,av as xt,z as pt,G as gt,y as bt,H as He,B as Z,E as wt,bS as yt,b1 as Be,n as Mt,I as Pt,W as $t,m as zt,br as jt,bs as St,bq as kt,a4 as vt,a5 as Kt,bT as Ut,bU as Yt,bV as Ht,l as qe,bW as Gt,i as Ct,j as Nt,k as Et,aY as Qe,X as Xt,V as Ze,U as Wt,bX as Tt,aF as Dt,h as _t,D as At,aa as Jt,ab as Vt,ac as qt,ad as Qt,ae as Zt,af as es,ag as ts,ah as ss,ai as ns,am as Rt,bM as et,$ as tt,bY as ls}from"./index-C6wvrmo0.js";import{a5 as rs,o as as,J as Xe,A as os,h as We,ay as is,X as Fe,Q as It,az as cs,aA as us,c as ds,aB as Lt,a3 as fs,aC as ms,P as hs,aD as xs,j as st,N as Ot,aE as ps}from"./vendor-ui-ZKZkD5k3.js";import"./vendor-shiki-DOn6sF-i.js";import"./vendor-markdown-BE1gYnO9.js";const Le="/api/browser",gs=5e3,bs="all";function ze(n,e=""){return`${Le}/sessions/${encodeURIComponent(n)}${e}`}function Ke(n){return{headers:{"content-type":"application/json"},body:JSON.stringify(n)}}function Ue(n,e){return n instanceof Error&&n.message?n.message:e}function ws(n){const[e,t]=r.useState(null),[l,a]=r.useState(null),u=r.useRef(!1),d=r.useRef(0),f=r.useRef(!1);r.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const x=r.useCallback(async()=>{const c=++d.current;f.current=!0;try{const i=await Me(Pe(Le)),h=i.ok?await i.json():null;if(!u.current||c!==d.current)return;h?(t(m=>JSON.stringify(m)===JSON.stringify(h)?m:h),a(null)):a(await $e(i,`Could not read the browser list (${i.status})`))}catch(i){u.current&&c===d.current&&a(Ue(i,"Could not read the browser list"))}finally{c===d.current&&(f.current=!1)}},[]);r.useEffect(()=>{if(!n)return;x();const c=setInterval(()=>{f.current||x()},gs);return()=>clearInterval(c)},[n,x]);const b=r.useCallback(async(c,i,h)=>{let m;try{m=await Me(Pe(c),i)}catch(N){return{ok:!1,error:Ue(N,h)}}if(!m.ok)return{ok:!1,error:await $e(m,h)};const S=await Ve(m);return x(),{ok:!0,data:S}},[x]),y=r.useCallback(async(c,i,h)=>{const m=await b(c,i,h);return m.ok?{ok:!0}:m},[b]),k=r.useCallback((c,i)=>y(`${Le}/sessions`,{method:"POST",...Ke({name:c,note:i})},`Could not create ${c}`),[y]),_=r.useCallback(c=>y(ze(c),{method:"DELETE"},`Could not delete ${c}`),[y]),p=r.useCallback(c=>y(ze(c,"/stop"),{method:"POST"},`Could not stop ${c}`),[y]),C=r.useCallback((c,i)=>y(ze(c),{method:"PATCH",...Ke({archived:i})},`Could not ${i?"archive":"restore"} ${c}`),[y]),j=r.useCallback(async()=>{const c="Could not read where the browser skill is installed";let i;try{i=await Me(Pe(`${Le}/skill`))}catch(m){return{ok:!1,error:Ue(m,c)}}if(!i.ok)return{ok:!1,error:await $e(i,c)};const h=await Ve(i);return Array.isArray(h==null?void 0:h.targets)?{ok:!0,targets:h.targets}:{ok:!1,error:c}},[]),g=r.useCallback(async c=>{const i="Could not install the browser skill",h=await b(`${Le}/skill/install`,{method:"POST",...Ke({target:c})},i);if(!h.ok)return h;const{paths:m}=h.data??{};return Array.isArray(m)&&m.every(S=>typeof S=="string")?{ok:!0,paths:m}:{ok:!1,error:i}},[b]);return{status:e,error:l,create:k,remove:_,stop:p,setArchived:C,readSkillTargets:j,installSkill:g}}const Ye=4;new TextEncoder;const ys=new TextDecoder;function js(n){if(n.byteLength<Ye)throw new Error("Frame truncated before header length");const e=new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0),t=Ye+e;if(n.byteLength<t)throw new Error("Frame truncated inside header");return{header:Ss(ys.decode(n.subarray(Ye,t))),jpeg:n.subarray(t)}}function Ss(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:u,scrollOffsetX:d,scrollOffsetY:f,targetId:x,ts:b}=e;if(typeof t!="number"||typeof l!="number"||typeof a!="number"||typeof u!="number"||typeof d!="number"||typeof f!="number"||typeof x!="string"||typeof b!="number")throw new Error("Frame header is missing fields");return{deviceWidth:t,deviceHeight:l,pageScaleFactor:a,offsetTop:u,scrollOffsetX:d,scrollOffsetY:f,targetId:x,ts:b}}const nt=500,ks=5e3,lt=[];function vs(n){const e=window.location.protocol==="https:"?"wss:":"ws:",t=Ft();return`${e}//${window.location.host}${t}/__browser?session=${encodeURIComponent(n)}`}function Cs(n){try{return JSON.parse(n)}catch{return null}}function Ns(n,e){return n.state===e.state&&n.session===e.session&&n.message===e.message}function Es(n,e){return n.targetId===e.targetId&&n.url===e.url&&n.title===e.title&&n.canGoBack===e.canGoBack&&n.canGoForward===e.canGoForward}function Ts(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 Ge(n){n&&n.bitmap.close()}function Ds(n,e){const t=ye.c(16),[l,a]=r.useState("idle"),[u,d]=r.useState(null),[f,x]=r.useState(null),[b,y]=r.useState(lt),[k,_]=r.useState(null),[p,C]=r.useState(null),[j,g]=r.useState(null),[c,i]=r.useState(null),h=r.useRef(null),m=r.useRef(null),S=r.useRef(null),N=r.useRef(e);let v,B;t[0]!==e?(v=()=>{N.current=e},B=[e],t[0]=e,t[1]=v,t[2]=B):(v=t[1],B=t[2]),r.useEffect(v,B);let E,P;t[3]!==n?(E=()=>{if(d(null),x(null),y(lt),_(null),i(null),C(null),g(null),n===null){a("idle");return}const F=n,T={alive:!0,issued:0,applied:0};let w=nt;const V=function(z,D){if(!T.alive||D<=T.applied){Ge(z);return}T.applied=D,m.current=z,C(z),g(Date.now())},L=function(z){let D,G;try{const q=js(new Uint8Array(z));D=q.header,G=new Blob([q.jpeg],{type:"image/jpeg"})}catch{return}const K=T.issued=T.issued+1;createImageBitmap(G).then(q=>V({bitmap:q,header:D},K),_s)},Q=function(z){var G;const D=Cs(z);if(D)e:switch(D.type){case"status":{d(K=>K&&Ns(K,D)?K:D),i(null);break e}case"page":{x(K=>K&&Es(K,D)?K:D);break e}case"tabs":{y(K=>Ts(K,D.tabs)?K:D.tabs),_(D.followed);break e}case"error":{i(D.message);break e}case"clipboard":(G=N.current)==null||G.call(N,D.text)}};function O(){if(!T.alive)return;const X=h.current;if(X&&X.readyState!==WebSocket.CLOSED)return;a("connecting");const z=new WebSocket(vs(F));z.binaryType="arraybuffer",h.current=z,z.onopen=()=>{if(!T.alive){z.close();return}w=nt,a("connected")},z.onmessage=D=>{T.alive&&(typeof D.data=="string"?Q(D.data):D.data instanceof ArrayBuffer&&L(D.data))},z.onclose=()=>{if(!T.alive)return;h.current=null,a("disconnected");const D=w;w=Math.min(w*2,ks),S.current=setTimeout(O,D)}}return O(),()=>{T.alive=!1,S.current&&(clearTimeout(S.current),S.current=null);const X=h.current;h.current=null,X&&(X.onclose=null,X.close()),Ge(m.current),m.current=null}},P=[n],t[3]=n,t[4]=E,t[5]=P):(E=t[4],P=t[5]),r.useEffect(E,P);let R;t[6]===Symbol.for("react.memo_cache_sentinel")?(R=F=>{const T=h.current;T&&T.readyState===WebSocket.OPEN&&T.send(JSON.stringify(F))},t[6]=R):R=t[6];const $=R;let Y;return t[7]!==c||t[8]!==k||t[9]!==p||t[10]!==j||t[11]!==f||t[12]!==u||t[13]!==l||t[14]!==b?(Y={status:l,state:u,page:f,tabs:b,followed:k,frame:p,lastFrameAt:j,error:c,send:$},t[7]=c,t[8]=k,t[9]=p,t[10]=j,t[11]=f,t[12]=u,t[13]=l,t[14]=b,t[15]=Y):Y=t[15],Y}function _s(){}const As=6e3;function Rs(n){const e=ye.c(16),{activity:t}=n,[l,a]=r.useState(!0),u=t?`${t.toolCallId}:${t.done}`:null;let d,f;if(e[0]!==u?(d=()=>{if(u===null)return;a(!0);const g=setTimeout(()=>a(!1),As);return()=>clearTimeout(g)},f=[u],e[0]=u,e[1]=d,e[2]=f):(d=e[1],f=e[2]),r.useEffect(d,f),!t)return null;const x=l?"opacity-100":"opacity-0";let b;e[3]!==x?(b=Re("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",x),e[3]=x,e[4]=b):b=e[4];let y;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(rs,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-muted-foreground"}),e[5]=y):y=e[5];let k;e[6]!==t.command?(k=s.jsx("code",{className:"min-w-0 truncate font-mono text-[11px]",children:t.command}),e[6]=t.command,e[7]=k):k=e[7];const _=t.done?"ran":"running";let p;e[8]!==_?(p=s.jsx("span",{className:"shrink-0 text-muted-foreground",children:_}),e[8]=_,e[9]=p):p=e[9];let C;e[10]!==k||e[11]!==p?(C=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:[y,k,p]}),e[10]=k,e[11]=p,e[12]=C):C=e[12];let j;return e[13]!==b||e[14]!==C?(j=s.jsx("div",{className:b,children:C}),e[13]=b,e[14]=C,e[15]=j):j=e[15],j}const rt="npm i -g agent-browser && agent-browser install",Is=1500;function Ls(n){const e=ye.c(20),{onOpenSkill:t}=n,[l,a]=r.useState(!1),u=r.useRef(null);let d,f;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=()=>()=>{u.current&&clearTimeout(u.current)},f=[],e[0]=d,e[1]=f):(d=e[0],f=e[1]),r.useEffect(d,f);let x;e[2]===Symbol.for("react.memo_cache_sentinel")?(x=async function(){await xt(rt)&&(a(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>a(!1),Is))},e[2]=x):x=e[2];const b=x;let y,k;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(pt,{variant:"icon",children:s.jsx(as,{})}),k=s.jsx(gt,{children:"Nothing to show yet"}),e[3]=y,e[4]=k):(y=e[3],k=e[4]);let _;e[5]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsxs(bt,{children:[y,k,s.jsxs(He,{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]=_):_=e[5];let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-xs",children:rt}),e[6]=p):p=e[6];const C=l?"Copied":"Copy install command";let j;e[7]===Symbol.for("react.memo_cache_sentinel")?(j=()=>void b(),e[7]=j):j=e[7];let g;e[8]!==l?(g=l?s.jsx(Xe,{"data-icon":"inline-start",className:"text-emerald-500"}):s.jsx(os,{"data-icon":"inline-start"}),e[8]=l,e[9]=g):g=e[9];let c;e[10]!==g||e[11]!==C?(c=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:[p,s.jsx(Z,{variant:"ghost",size:"icon-xs","aria-label":C,onClick:j,children:g})]}),e[10]=g,e[11]=C,e[12]=c):c=e[12];let i;e[13]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx(We,{"data-icon":"inline-start"}),e[13]=i):i=e[13];let h;e[14]!==t?(h=s.jsxs(Z,{variant:"outline",size:"sm",onClick:t,children:[i,"Install the agent skill…"]}),e[14]=t,e[15]=h):h=e[15];let m;e[16]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(He,{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]=m):m=e[16];let S;return e[17]!==c||e[18]!==h?(S=s.jsxs(wt,{className:"size-full",children:[_,s.jsxs(yt,{children:[c,h,m]})]}),e[17]=c,e[18]=h,e[19]=S):S=e[19],S}function Os(n){const e=ye.c(23),{name:t,lastUrl:l,onOpen:a}=n,[u,d]=r.useState(null),f=u??l??"";let x;e[0]!==a||e[1]!==f?(x=function(N){N.preventDefault();const v=f.trim();v&&a(v)},e[0]=a,e[1]=f,e[2]=x):x=e[2];const b=x;let y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(pt,{variant:"icon",children:s.jsx(is,{})}),e[3]=y):y=e[3];let k;e[4]!==t?(k=s.jsxs(gt,{children:[t," isn’t running"]}),e[4]=t,e[5]=k):k=e[5];let _;e[6]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(He,{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]=_):_=e[6];let p;e[7]!==k?(p=s.jsxs(bt,{children:[y,k,_]}),e[7]=k,e[8]=p):p=e[8];let C;e[9]===Symbol.for("react.memo_cache_sentinel")?(C=S=>d(S.target.value),e[9]=C):C=e[9];let j;e[10]!==f?(j=s.jsx(Be,{"aria-label":"Page to open",className:"h-8 text-sm",placeholder:"example.com",spellCheck:!1,autoComplete:"off",value:f,onChange:C}),e[10]=f,e[11]=j):j=e[11];let g;e[12]!==f?(g=f.trim(),e[12]=f,e[13]=g):g=e[13];const c=!g;let i;e[14]!==c?(i=s.jsx(Z,{type:"submit",size:"sm",disabled:c,children:"Open"}),e[14]=c,e[15]=i):i=e[15];let h;e[16]!==b||e[17]!==i||e[18]!==j?(h=s.jsx(yt,{children:s.jsxs("form",{className:"flex w-full items-center gap-2",onSubmit:b,children:[j,i]})}),e[16]=b,e[17]=i,e[18]=j,e[19]=h):h=e[19];let m;return e[20]!==h||e[21]!==p?(m=s.jsxs(wt,{className:"size-full",children:[p,h]}),e[20]=h,e[21]=p,e[22]=m):m=e[22],m}function at(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 Bs={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 Fs(n){const e=ye.c(17),{status:t}=n,l=Bs[t];let a;e[0]!==l.tone?(a=Re("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 u;e[2]!==a?(u=s.jsx("span",{className:a}),e[2]=a,e[3]=u):u=e[3];let d;e[4]!==l.dot?(d=Re("size-1.5 rounded-full",l.dot),e[4]=l.dot,e[5]=d):d=e[5];let f;e[6]!==d?(f=s.jsx("span",{"aria-hidden":"true",className:d}),e[6]=d,e[7]=f):f=e[7];let x;e[8]!==l.label||e[9]!==u||e[10]!==f?(x=s.jsxs(jt,{render:u,children:[f,l.label]}),e[8]=l.label,e[9]=u,e[10]=f,e[11]=x):x=e[11];let b;e[12]!==l.hint?(b=s.jsx(St,{children:l.hint}),e[12]=l.hint,e[13]=b):b=e[13];let y;return e[14]!==x||e[15]!==b?(y=s.jsxs(kt,{children:[x,b]}),e[14]=x,e[15]=b,e[16]=y):y=e[16],y}const Ms=r.memo(function(e){const t=ye.c(49),{page:l,tabs:a,followed:u,status:d,onNavigate:f,onBack:x,onForward:b,onReload:y,onFollow:k,onCloseTab:_}=e,[p,C]=r.useState(null),j=(l==null?void 0:l.url)??"";let g;t[0]!==p||t[1]!==j||t[2]!==f?(g=function(J){J.preventDefault();const te=(p??j).trim();C(null),te&&f(te)},t[0]=p,t[1]=j,t[2]=f,t[3]=g):g=t[3];const c=g;let i;t[4]===Symbol.for("react.memo_cache_sentinel")?(i=function(J){J.key==="Escape"&&(J.preventDefault(),C(null),J.currentTarget.blur())},t[4]=i):i=t[4];const h=i,m=!(l!=null&&l.canGoBack);let S;t[5]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(It,{"data-icon":"inline-start"}),t[5]=S):S=t[5];let N;t[6]!==x||t[7]!==m?(N=s.jsx(Z,{variant:"ghost",size:"icon-sm","aria-label":"Back",disabled:m,onClick:x,children:S}),t[6]=x,t[7]=m,t[8]=N):N=t[8];const v=!(l!=null&&l.canGoForward);let B;t[9]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(cs,{"data-icon":"inline-start"}),t[9]=B):B=t[9];let E;t[10]!==b||t[11]!==v?(E=s.jsx(Z,{variant:"ghost",size:"icon-sm","aria-label":"Forward",disabled:v,onClick:b,children:B}),t[10]=b,t[11]=v,t[12]=E):E=t[12];const P=!l;let R;t[13]===Symbol.for("react.memo_cache_sentinel")?(R=s.jsx(us,{"data-icon":"inline-start"}),t[13]=R):R=t[13];let $;t[14]!==y||t[15]!==P?($=s.jsx(Z,{variant:"ghost",size:"icon-sm","aria-label":"Reload",disabled:P,onClick:y,children:R}),t[14]=y,t[15]=P,t[16]=$):$=t[16];const Y=p??j;let F;t[17]===Symbol.for("react.memo_cache_sentinel")?(F=W=>C(W.target.value),t[17]=F):F=t[17];let T;t[18]===Symbol.for("react.memo_cache_sentinel")?(T=()=>C(null),t[18]=T):T=t[18];let w;t[19]!==Y?(w=s.jsx(Mt,{"aria-label":"Page URL",className:"text-xs",placeholder:"Enter a URL",spellCheck:!1,autoComplete:"off",value:Y,onChange:F,onFocus:Ps,onBlur:T,onKeyDown:h}),t[19]=Y,t[20]=w):w=t[20];const V=!j;let L;t[21]!==j?(L=()=>window.open(j,"_blank","noopener,noreferrer"),t[21]=j,t[22]=L):L=t[22];let Q;t[23]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(ds,{"data-icon":"inline-start"}),t[23]=Q):Q=t[23];let O;t[24]!==V||t[25]!==L?(O=s.jsx(Pt,{align:"inline-end",children:s.jsx($t,{size:"icon-xs","aria-label":"Open in your browser",disabled:V,onClick:L,children:Q})}),t[24]=V,t[25]=L,t[26]=O):O=t[26];let X;t[27]!==w||t[28]!==O?(X=s.jsxs(zt,{className:"h-7",children:[w,O]}),t[27]=w,t[28]=O,t[29]=X):X=t[29];let z;t[30]!==c||t[31]!==X?(z=s.jsx("form",{className:"ml-1 min-w-0 flex-1",onSubmit:c,children:X}),t[30]=c,t[31]=X,t[32]=z):z=t[32];let D;t[33]!==d?(D=d&&s.jsx(Fs,{status:d}),t[33]=d,t[34]=D):D=t[34];let G;t[35]!==$||t[36]!==z||t[37]!==D||t[38]!==N||t[39]!==E?(G=s.jsxs("div",{className:"flex items-center gap-0.5",children:[N,E,$,z,D]}),t[35]=$,t[36]=z,t[37]=D,t[38]=N,t[39]=E,t[40]=G):G=t[40];let K;t[41]!==u||t[42]!==_||t[43]!==k||t[44]!==a?(K=a.length>0&&s.jsx("div",{className:"flex items-center gap-1 overflow-x-auto pb-0.5",children:a.map(W=>s.jsxs("div",{className:Re("flex max-w-48 shrink-0 items-center rounded-md",W.targetId===u&&"bg-secondary"),children:[s.jsx(Z,{size:"xs",variant:"ghost",className:"min-w-0 shrink rounded-r-none","aria-current":W.targetId===u?"page":void 0,title:W.title||W.url,onClick:()=>k(W.targetId),onMouseDown:$s,onAuxClick:J=>{J.button===1&&(J.preventDefault(),_(W.targetId))},children:s.jsx("span",{className:"truncate",children:at(W)})}),s.jsx(Z,{size:"icon-xs",variant:"ghost",className:"rounded-l-none","aria-label":`Close tab: ${at(W)}`,title:"Close tab",onClick:()=>_(W.targetId),children:s.jsx(Fe,{"data-icon":"inline-start"})})]},W.targetId))}),t[41]=u,t[42]=_,t[43]=k,t[44]=a,t[45]=K):K=t[45];let q;return t[46]!==G||t[47]!==K?(q=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1 border-b px-2 py-1.5",children:[G,K]}),t[46]=G,t[47]=K,t[48]=q):q=t[48],q});function Ps(n){return n.target.select()}function $s(n){n.button===1&&n.preventDefault()}function zs(n){if(!n||!Number.isFinite(Date.parse(n)))return null;if(Date.now()-Date.parse(n)>=10080*60*1e3)return new Date(n).toLocaleDateString();const e=Kt(n);return e==="now"?"just now":`${e} ago`}function Bt(n){const e=ye.c(4),{running:t}=n,l=t?"bg-emerald-500":"ring-1 ring-muted-foreground/50 ring-inset";let a;e[0]!==l?(a=Re("size-2 shrink-0 rounded-full",l),e[0]=l,e[1]=a):a=e[1];let u;return e[2]!==a?(u=s.jsx("span",{"aria-hidden":!0,className:a}),e[2]=a,e[3]=u):u=e[3],u}function Ks(n){const e=ye.c(91),{sessions:t,selected:l,currentSessionId:a,busy:u,onSelect:d,onSetArchived:f,children:x}=n,[b,y]=r.useState(!1),[k,_]=r.useState(""),[p,C]=r.useState(!1),j=r.useRef(null);let g;if(e[0]!==l||e[1]!==t){let J;e[3]!==l?(J=te=>te.name===l,e[3]=l,e[4]=J):J=e[4],g=t.find(J),e[0]=l,e[1]=t,e[2]=g}else g=e[2];const c=g;let i,h,m,S,N,v,B,E,P,R,$,Y,F,T,w,V,L;if(e[5]!==u||e[6]!==a||e[7]!==d||e[8]!==f||e[9]!==b||e[10]!==k||e[11]!==l||e[12]!==(c==null?void 0:c.running)||e[13]!==t||e[14]!==p){const J=k.trim().toLowerCase();let te;e[32]!==l?(te=H=>!!H.archived&&!H.isDefault&&!H.running&&H.name!==l,e[32]=l,e[33]=te):te=e[33];const ge=te,ce=H=>`${H.name} ${H.note??""}`.toLowerCase().includes(J),he=t.filter(H=>!ge(H)&&ce(H)).sort(Ys);m=t.filter(ge);const ue=m.filter(ce);L=p&&!J?[]:he,V=p||J?ue:[];let de;e[34]===Symbol.for("react.memo_cache_sentinel")?(de=function(){y(!1)},e[34]=de):de=e[34],S=de;const fe=async function(le){le.archived&&!(await f(le.name,!1)).ok||(d(le.name),S())},Se=async function(le){var xe;(await f(le,!0)).ok&&((xe=j.current)==null||xe.focus())};h=Ut,N=b,e[35]===Symbol.for("react.memo_cache_sentinel")?(v=H=>{y(H),H&&(_(""),C(!1))},e[35]=v):v=e[35];let ae;e[36]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(Z,{variant:"ghost",size:"xs","aria-label":"Switch browser",className:"max-w-40"}),e[36]=ae):ae=e[36];const me=(c==null?void 0:c.running)??!1;let oe;e[37]!==me?(oe=s.jsx(Bt,{running:me}),e[37]=me,e[38]=oe):oe=e[38];let re;e[39]!==l?(re=s.jsx("span",{className:"truncate",children:l}),e[39]=l,e[40]=re):re=e[40];let I;e[41]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(fs,{"data-icon":"inline-end",className:"opacity-60"}),e[41]=I):I=e[41],e[42]!==oe||e[43]!==re?(B=s.jsxs(Yt,{render:ae,children:[oe,re,I]}),e[42]=oe,e[43]=re,e[44]=B):B=e[44],i=Ht,$="Browsers",Y=j,F="flex max-h-[min(32rem,var(--available-height))] w-80 max-w-[calc(100vw-1rem)] flex-col overflow-hidden";const ee=p&&!J?"Archived browsers":"Browsers";let se;e[45]!==ee?(se=s.jsx("span",{className:"text-sm font-medium",children:ee}),e[45]=ee,e[46]=se):se=e[46];let je;e[47]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx(Z,{variant:"ghost",size:"icon-xs","aria-label":"Close browser picker",onClick:S,children:s.jsx(Fe,{"data-icon":"inline-start"})}),e[47]=je):je=e[47];let be;e[48]!==se?(be=s.jsxs("div",{className:"flex items-center justify-between pl-1",children:[se,je]}),e[48]=se,e[49]=be):be=e[49];let ie;e[50]===Symbol.for("react.memo_cache_sentinel")?(ie=H=>_(H.target.value),e[50]=ie):ie=e[50];let we;e[51]!==k?(we=s.jsx(Be,{ref:j,"aria-label":"Search browsers",placeholder:"Search browsers…",value:k,onChange:ie}),e[51]=k,e[52]=we):we=e[52],e[53]!==be||e[54]!==we?(T=s.jsxs("div",{className:"flex shrink-0 flex-col gap-2 p-2",children:[be,we]}),e[53]=be,e[54]=we,e[55]=T):T=e[55],e[56]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx(qe,{}),e[56]=w):w=e[56],E="min-h-0 max-h-72 overflow-y-auto overscroll-contain p-1",P="Browser list",R=[{label:"Recent browsers",sessions:L,archived:!1},{label:"Archived browsers",sessions:V,archived:!0}].filter(Us).map(H=>s.jsxs("div",{children:[H.archived&&!!J&&s.jsx("p",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Archived"}),s.jsx("ul",{"aria-label":H.label,children:H.sessions.map(le=>s.jsx(Hs,{session:le,archived:H.archived,selected:l,currentSessionId:a,busy:u,onPick:fe,onArchive:Se},le.name))})]},H.label)),e[5]=u,e[6]=a,e[7]=d,e[8]=f,e[9]=b,e[10]=k,e[11]=l,e[12]=c==null?void 0:c.running,e[13]=t,e[14]=p,e[15]=i,e[16]=h,e[17]=m,e[18]=S,e[19]=N,e[20]=v,e[21]=B,e[22]=E,e[23]=P,e[24]=R,e[25]=$,e[26]=Y,e[27]=F,e[28]=T,e[29]=w,e[30]=V,e[31]=L}else i=e[15],h=e[16],m=e[17],S=e[18],N=e[19],v=e[20],B=e[21],E=e[22],P=e[23],R=e[24],$=e[25],Y=e[26],F=e[27],T=e[28],w=e[29],V=e[30],L=e[31];let Q;e[57]!==V||e[58]!==L.length?(Q=L.length===0&&V.length===0&&s.jsx("p",{role:"status",className:"px-3 py-6 text-center text-sm text-muted-foreground",children:"No browsers found."}),e[57]=V,e[58]=L.length,e[59]=Q):Q=e[59];let O;e[60]!==Q||e[61]!==E||e[62]!==P||e[63]!==R?(O=s.jsxs("div",{className:E,"aria-label":P,children:[R,Q]}),e[60]=Q,e[61]=E,e[62]=P,e[63]=R,e[64]=O):O=e[64];let X;e[65]===Symbol.for("react.memo_cache_sentinel")?(X=s.jsx(qe,{}),e[65]=X):X=e[65];let z;e[66]!==m.length||e[67]!==p?(z=(m.length>0||p)&&s.jsxs(Z,{variant:"ghost",size:"sm",className:"w-full justify-start","aria-expanded":p,onClick:()=>{C(!p),_("")},children:[p?s.jsx(It,{"data-icon":"inline-start"}):s.jsx(Lt,{"data-icon":"inline-start"}),p?"Back to recent":"Archived",!p&&s.jsx(vt,{variant:"secondary",children:m.length})]}),e[66]=m.length,e[67]=p,e[68]=z):z=e[68];let D;e[69]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx("p",{className:"px-1 pb-1 text-xs text-muted-foreground",children:"Stopped browsers archive after 24h of inactivity. Saved logins are kept."}),e[69]=D):D=e[69];let G;e[70]!==x||e[71]!==S?(G=x(S),e[70]=x,e[71]=S,e[72]=G):G=e[72];let K;e[73]!==z||e[74]!==G?(K=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1 p-2",children:[z,D,G]}),e[73]=z,e[74]=G,e[75]=K):K=e[75];let q;e[76]!==i||e[77]!==O||e[78]!==K||e[79]!==$||e[80]!==Y||e[81]!==F||e[82]!==T||e[83]!==w?(q=s.jsxs(i,{"aria-label":$,initialFocus:Y,className:F,children:[T,w,O,X,K]}),e[76]=i,e[77]=O,e[78]=K,e[79]=$,e[80]=Y,e[81]=F,e[82]=T,e[83]=w,e[84]=q):q=e[84];let W;return e[85]!==h||e[86]!==N||e[87]!==v||e[88]!==B||e[89]!==q?(W=s.jsxs(h,{open:N,onOpenChange:v,children:[B,q]}),e[85]=h,e[86]=N,e[87]=v,e[88]=B,e[89]=q,e[90]=W):W=e[90],W}function Us(n){return n.sessions.length>0}function Ys(n,e){return Number(e.isDefault)-Number(n.isDefault)||Number(e.running)-Number(n.running)}function Hs(n){const e=ye.c(49),{session:t,archived:l,selected:a,currentSessionId:u,busy:d,onPick:f,onArchive:x}=n;let b;e[0]!==t.lastUsedAt?(b=zs(t.lastUsedAt),e[0]=t.lastUsedAt,e[1]=b):b=e[1];const y=b,k=t.running&&t.driverSessionId!==null&&t.driverSessionId!==u,_=`${l?"Restore and switch to":"Switch to"} ${t.name}`,p=t.name===a?"true":void 0;let C;e[2]!==f||e[3]!==t?(C=()=>void f(t),e[2]=f,e[3]=t,e[4]=C):C=e[4];let j;e[5]!==t.running?(j=s.jsx(Bt,{running:t.running}),e[5]=t.running,e[6]=j):j=e[6];let g;e[7]!==t.name?(g=s.jsx("span",{className:"truncate",children:t.name}),e[7]=t.name,e[8]=g):g=e[8];const c=t.running?"running":"stopped";let i;e[9]!==c?(i=s.jsx("span",{className:"sr-only",children:c}),e[9]=c,e[10]=i):i=e[10];let h;e[11]!==t.isDefault?(h=t.isDefault&&s.jsx(vt,{variant:"secondary",children:"Default"}),e[11]=t.isDefault,e[12]=h):h=e[12];let m;e[13]!==y?(m=y&&s.jsx("span",{className:"ml-auto shrink-0 text-xs font-normal text-muted-foreground",children:y}),e[13]=y,e[14]=m):m=e[14];let S;e[15]!==m||e[16]!==g||e[17]!==i||e[18]!==h?(S=s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[g,i,h,m]}),e[15]=m,e[16]=g,e[17]=i,e[18]=h,e[19]=S):S=e[19];let N;e[20]!==k?(N=k&&s.jsx("span",{className:"max-w-full truncate text-xs font-normal text-muted-foreground",children:"driven by another session"}),e[20]=k,e[21]=N):N=e[21];let v;e[22]!==S||e[23]!==N?(v=s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col items-start gap-0.5",children:[S,N]}),e[22]=S,e[23]=N,e[24]=v):v=e[24];let B;e[25]!==a||e[26]!==t.name?(B=t.name===a&&s.jsx(Xe,{"data-icon":"inline-end"}),e[25]=a,e[26]=t.name,e[27]=B):B=e[27];let E;e[28]!==l?(E=l&&s.jsx(ms,{"data-icon":"inline-end"}),e[28]=l,e[29]=E):E=e[29];let P;e[30]!==d||e[31]!==v||e[32]!==B||e[33]!==E||e[34]!==_||e[35]!==p||e[36]!==C||e[37]!==j?(P=s.jsxs(Z,{variant:"ghost",className:"h-auto min-h-10 min-w-0 flex-1 justify-start px-2 py-2","aria-label":_,"aria-current":p,disabled:d,onClick:C,children:[j,v,B,E]}),e[30]=d,e[31]=v,e[32]=B,e[33]=E,e[34]=_,e[35]=p,e[36]=C,e[37]=j,e[38]=P):P=e[38];let R;e[39]!==l||e[40]!==d||e[41]!==x||e[42]!==t.isDefault||e[43]!==t.name||e[44]!==t.running?(R=!l&&!t.isDefault&&!t.running&&s.jsx(Z,{variant:"ghost",size:"icon-sm","aria-label":`Archive ${t.name}`,title:`Archive ${t.name}`,disabled:d,onClick:()=>void x(t.name),children:s.jsx(Lt,{"data-icon":"inline-start"})}),e[39]=l,e[40]=d,e[41]=x,e[42]=t.isDefault,e[43]=t.name,e[44]=t.running,e[45]=R):R=e[45];let $;return e[46]!==P||e[47]!==R?($=s.jsxs("li",{className:"group flex items-center gap-1 rounded-md",children:[P,R]}),e[46]=P,e[47]=R,e[48]=$):$=e[48],$}const Oe="default",Gs=/^[a-z0-9][a-z0-9_-]{0,39}$/,Xs="Lowercase letters, numbers, - and _, starting with a letter or number (40 max).",Ws=r.memo(function(e){const t=ye.c(100),{sessions:l,selected:a,currentSessionId:u,followAgent:d,busy:f,onSelect:x,onToggleFollow:b,onOpenSkill:y,onCreate:k,onRemove:_,onStop:p,onSetArchived:C,onShowDefault:j,onClose:g}=e,c=f===void 0?!1:f,i=r.useId(),h=r.useId(),[m,S]=r.useState(!1),[N,v]=r.useState(""),[B,E]=r.useState(""),[P,R]=r.useState(null),[$,Y]=r.useState(!1),[F,T]=r.useState(null),w=a===Oe;let V;t[0]!==a||t[1]!==l?(V=l.find(ne=>ne.name===a)??null,t[0]=a,t[1]=l,t[2]=V):V=t[2];const L=V;let Q,O;t[3]!==N?(O=N.trim(),Q=O.length>0&&!Gs.test(O),t[3]=N,t[4]=Q,t[5]=O):(Q=t[4],O=t[5]);const X=Q,z=X?Xs:P,D=O.length>0&&!X&&!$;let G;t[6]===Symbol.for("react.memo_cache_sentinel")?(G=function(){v(""),E(""),R(null),Y(!1),S(!0)},t[6]=G):G=t[6];const K=G;let q;t[7]!==D||t[8]!==B||t[9]!==k||t[10]!==x||t[11]!==O?(q=async function(){if(!D)return;Y(!0);const Je=await k(O,B.trim());if(Y(!1),!Je.ok){R(Je.error);return}S(!1),x(O)},t[7]=D,t[8]=B,t[9]=k,t[10]=x,t[11]=O,t[12]=q):q=t[12];const W=q,J=!w&&"border-amber-500/40 bg-amber-500/10";let te;t[13]!==J?(te=Re("@container/browser-bar flex h-10 shrink-0 items-center gap-2 border-b px-2",J),t[13]=J,t[14]=te):te=t[14];let ge;t[15]!==c||t[16]!==w||t[17]!==y||t[18]!==p||t[19]!==a||t[20]!==(L==null?void 0:L.running)?(ge=ne=>s.jsxs(s.Fragment,{children:[s.jsxs(Z,{variant:"outline",size:"sm",disabled:c,onClick:()=>{ne(),K()},children:[s.jsx(hs,{"data-icon":"inline-start"}),"New browser…"]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(Z,{variant:"ghost",size:"xs",onClick:()=>{ne(),y()},children:[s.jsx(We,{"data-icon":"inline-start"}),"Agent skill…"]}),!w&&s.jsxs(s.Fragment,{children:[s.jsxs(Z,{variant:"ghost",size:"xs",disabled:c||!(L!=null&&L.running),onClick:()=>{ne(),p(a)},children:[s.jsx(xs,{"data-icon":"inline-start"}),"Stop"]}),s.jsxs(Z,{variant:"ghost",size:"xs",disabled:c,onClick:()=>{ne(),T(a)},children:[s.jsx(st,{"data-icon":"inline-start"}),"Delete…"]})]})]})]}),t[15]=c,t[16]=w,t[17]=y,t[18]=p,t[19]=a,t[20]=L==null?void 0:L.running,t[21]=ge):ge=t[21];let ce;t[22]!==c||t[23]!==u||t[24]!==x||t[25]!==C||t[26]!==a||t[27]!==l||t[28]!==ge?(ce=s.jsx(Ks,{sessions:l,selected:a,currentSessionId:u,busy:c,onSelect:x,onSetArchived:C,children:ge}),t[22]=c,t[23]=u,t[24]=x,t[25]=C,t[26]=a,t[27]=l,t[28]=ge,t[29]=ce):ce=t[29];let he;t[30]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx("span",{className:"flex-1"}),t[30]=he):he=t[30];let ue;t[31]!==w||t[32]!==j?(ue=!w&&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(Ot,{"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(Z,{variant:"outline",size:"xs",onClick:j,children:"Show default"})]}),t[31]=w,t[32]=j,t[33]=ue):ue=t[33];let de;t[34]!==b?(de=ne=>b(ne),t[34]=b,t[35]=de):de=t[35];let fe;t[36]!==d||t[37]!==de?(fe=s.jsx(Gt,{size:"sm","aria-label":"Follow agent",pressed:d,onPressedChange:de,className:"text-muted-foreground data-pressed:text-foreground"}),t[36]=d,t[37]=de,t[38]=fe):fe=t[38];let Se,ae;t[39]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(ps,{"data-icon":"inline-start"}),ae=s.jsx("span",{className:"hidden @md/browser-bar:inline",children:"Follow"}),t[39]=Se,t[40]=ae):(Se=t[39],ae=t[40]);let me;t[41]!==fe?(me=s.jsxs(jt,{render:fe,children:[Se,ae]}),t[41]=fe,t[42]=me):me=t[42];let oe;t[43]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(St,{children:"Switch to whichever browser this session’s agent uses"}),t[43]=oe):oe=t[43];let re;t[44]!==me?(re=s.jsxs(kt,{children:[me,oe]}),t[44]=me,t[45]=re):re=t[45];let I;t[46]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(Fe,{"data-icon":"inline-start"}),t[46]=I):I=t[46];let ee;t[47]!==g?(ee=s.jsx(Z,{variant:"ghost",size:"icon-sm","aria-label":"Close browser panel",onClick:g,children:I}),t[47]=g,t[48]=ee):ee=t[48];let se;t[49]!==W?(se=ne=>{ne.preventDefault(),W()},t[49]=W,t[50]=se):se=t[50];let je;t[51]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsxs(Ct,{children:[s.jsx(Nt,{children:"New browser"}),s.jsx(Et,{children:"A named browser keeps its own cookies and logins, and stays out of the default one."})]}),t[51]=je):je=t[51];const be=!!z;let ie;t[52]!==i?(ie=s.jsx(Qe,{htmlFor:i,children:"Name"}),t[52]=i,t[53]=ie):ie=t[53];const we=!!z;let H;t[54]===Symbol.for("react.memo_cache_sentinel")?(H=ne=>{v(ne.target.value),R(null)},t[54]=H):H=t[54];let le;t[55]!==i||t[56]!==N||t[57]!==we?(le=s.jsx(Be,{id:i,autoFocus:!0,autoComplete:"off",spellCheck:!1,placeholder:"shop","aria-invalid":we,value:N,onChange:H}),t[55]=i,t[56]=N,t[57]=we,t[58]=le):le=t[58];let Ne;t[59]!==z?(Ne=s.jsx(Xt,{children:z}),t[59]=z,t[60]=Ne):Ne=t[60];let xe;t[61]!==be||t[62]!==ie||t[63]!==le||t[64]!==Ne?(xe=s.jsxs(Ze,{"data-invalid":be,children:[ie,le,Ne]}),t[61]=be,t[62]=ie,t[63]=le,t[64]=Ne,t[65]=xe):xe=t[65];let _e;t[66]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx("span",{className:"text-muted-foreground/60",children:"(optional)"}),t[66]=_e):_e=t[66];let ke;t[67]!==h?(ke=s.jsxs(Qe,{htmlFor:h,children:["Note ",_e]}),t[67]=h,t[68]=ke):ke=t[68];let Ee;t[69]===Symbol.for("react.memo_cache_sentinel")?(Ee=ne=>E(ne.target.value),t[69]=Ee):Ee=t[69];let ve;t[70]!==B||t[71]!==h?(ve=s.jsx(Be,{id:h,autoComplete:"off",placeholder:"What this browser is signed in to",value:B,onChange:Ee}),t[70]=B,t[71]=h,t[72]=ve):ve=t[72];let Te;t[73]!==ke||t[74]!==ve?(Te=s.jsxs(Ze,{children:[ke,ve]}),t[73]=ke,t[74]=ve,t[75]=Te):Te=t[75];let M;t[76]!==xe||t[77]!==Te?(M=s.jsxs(Wt,{className:"gap-4",children:[xe,Te]}),t[76]=xe,t[77]=Te,t[78]=M):M=t[78];let o;t[79]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(Tt,{render:s.jsx(Z,{type:"button",variant:"outline"}),children:"Cancel"}),t[79]=o):o=t[79];const A=!D;let U;t[80]!==A?(U=s.jsxs(Dt,{children:[o,s.jsx(Z,{type:"submit",disabled:A,children:"Create browser"})]}),t[80]=A,t[81]=U):U=t[81];let pe;t[82]!==se||t[83]!==M||t[84]!==U?(pe=s.jsx(_t,{className:"sm:max-w-sm",children:s.jsxs("form",{className:"flex flex-col gap-4",onSubmit:se,children:[je,M,U]})}),t[82]=se,t[83]=M,t[84]=U,t[85]=pe):pe=t[85];let Ce;t[86]!==m||t[87]!==pe?(Ce=s.jsx(At,{open:m,onOpenChange:S,children:pe}),t[86]=m,t[87]=pe,t[88]=Ce):Ce=t[88];let De;t[89]!==F||t[90]!==_?(De=F!==null&&s.jsx(Jt,{open:!0,onOpenChange:ne=>{ne||T(null)},children:s.jsxs(Vt,{size:"sm",children:[s.jsxs(qt,{children:[s.jsx(Qt,{className:"bg-destructive/10 text-destructive",children:s.jsx(st,{})}),s.jsxs(Zt,{children:["Delete ",F,"?"]}),s.jsx(es,{children:"Its profile goes with it, so everything signed in there is signed out. Other browsers are untouched."})]}),s.jsxs(ts,{children:[s.jsx(ss,{size:"sm",children:"Cancel"}),s.jsx(ns,{variant:"destructive",size:"sm",onClick:()=>{_(F),T(null)},children:"Delete browser"})]})]})}),t[89]=F,t[90]=_,t[91]=De):De=t[91];let Ae;return t[92]!==ue||t[93]!==re||t[94]!==ee||t[95]!==Ce||t[96]!==De||t[97]!==te||t[98]!==ce?(Ae=s.jsxs("div",{className:te,children:[ce,he,ue,re,ee,Ce,De]}),t[92]=ue,t[93]=re,t[94]=ee,t[95]=Ce,t[96]=De,t[97]=te,t[98]=ce,t[99]=Ae):Ae=t[99],Ae});function Js(n){const e=ye.c(36),{open:t,onOpenChange:l,readTargets:a,install:u}=n,[d,f]=r.useState(null),[x,b]=r.useState(null),[y,k]=r.useState(null);let _;e[0]!==a?(_=async()=>{const w=await a();w.ok?(f(w.targets),b(null)):b(w.error)},e[0]=a,e[1]=_):_=e[1];const p=_;let C,j;e[2]!==p||e[3]!==t?(C=()=>{t&&(b(null),p())},j=[t,p],e[2]=p,e[3]=t,e[4]=C,e[5]=j):(C=e[4],j=e[5]),r.useEffect(C,j);let g;e[6]!==u||e[7]!==p?(g=async function(V){k(V);const L=await u(V);k(null),L.ok?await p():b(L.error)},e[6]=u,e[7]=p,e[8]=g):g=e[8];const c=g;let i;e[9]!==d?(i=(d==null?void 0:d.some(Vs))??!1,e[9]=d,e[10]=i):i=e[10];const h=i;let m;e[11]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Nt,{children:"Agent skill"}),e[11]=m):m=e[11];let S;e[12]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsxs(Ct,{children:[m,s.jsxs(Et,{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]=S):S=e[12];let N;e[13]!==x?(N=x&&s.jsx("p",{role:"alert",className:"text-sm text-destructive",children:x}),e[13]=x,e[14]=N):N=e[14];let v;e[15]!==y||e[16]!==c||e[17]!==d?(v=d===null?s.jsxs("div",{role:"status",className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[s.jsx(Rt,{}),"Reading where it is installed…"]}):s.jsx("ul",{className:"flex flex-col gap-2",children:d.map(w=>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:w.label}),s.jsx("span",{className:"truncate font-mono text-xs text-muted-foreground",children:w.configRoot}),w.automatic&&s.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"Already automatic in the sessions Cogpit starts"})]}),w.installed?s.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-xs text-muted-foreground",children:[s.jsx(Xe,{"aria-hidden":!0,className:"size-3.5 text-emerald-500"}),"Installed"]}):s.jsx(Z,{size:"xs",variant:"outline","aria-label":`Install for ${w.label}`,disabled:y!==null,onClick:()=>void c(w.kind),children:"Install"})]},w.kind))}),e[15]=y,e[16]=c,e[17]=d,e[18]=v):v=e[18];const B=!h||y!==null;let E;e[19]!==c?(E=()=>void c(bs),e[19]=c,e[20]=E):E=e[20];let P;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx(We,{"data-icon":"inline-start"}),e[21]=P):P=e[21];let R;e[22]!==B||e[23]!==E?(R=s.jsxs(Z,{variant:"outline",disabled:B,onClick:E,children:[P,"Install for all"]}),e[22]=B,e[23]=E,e[24]=R):R=e[24];let $;e[25]===Symbol.for("react.memo_cache_sentinel")?($=s.jsx(Tt,{render:s.jsx(Z,{type:"button"}),children:"Done"}),e[25]=$):$=e[25];let Y;e[26]!==R?(Y=s.jsxs(Dt,{children:[R,$]}),e[26]=R,e[27]=Y):Y=e[27];let F;e[28]!==Y||e[29]!==N||e[30]!==v?(F=s.jsxs(_t,{className:"sm:max-w-md",children:[S,N,v,Y]}),e[28]=Y,e[29]=N,e[30]=v,e[31]=F):F=e[31];let T;return e[32]!==l||e[33]!==t||e[34]!==F?(T=s.jsx(At,{open:t,onOpenChange:l,children:F}),e[32]=l,e[33]=t,e[34]=F,e[35]=T):T=e[35],T}function Vs(n){return!n.installed}const qs={x:0,y:0,width:0,height:0,scale:0};function Qs(n,e){if(n.width<=0||n.height<=0||e.width<=0||e.height<=0)return qs;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 ot(n,e,t,l,a={}){if(l.scale<=0||l.width<=0||l.height<=0)return null;const u=n-t.left-l.x,d=e-t.top-l.y;return!(u>=0&&d>=0&&u<=l.width&&d<=l.height)&&!a.clamp?null:{x:it(u/l.scale,l.width/l.scale),y:it(d/l.scale,l.height/l.scale)}}function it(n,e){return Math.min(Math.max(n,0),e)}const Zs=1,en=2,tn=4,sn=8;function Ie(n){return(n.altKey?Zs:0)|(n.ctrlKey?en:0)|(n.metaKey?tn:0)|(n.shiftKey?sn:0)}const nn=["left","middle","right"];function ct(n){return nn[n]??"left"}const ln=150,ut=2,rn=500,dt=5,an=1,on=2,cn=16,un="Keyboard captured · Esc to release",dn=new Set(["F5","F11","F12"]),fn=new Set(["i","j","c"]);function ft(n){return dn.has(n.key)||n.metaKey?!0:n.ctrlKey&&n.shiftKey&&fn.has(n.key.toLowerCase())}function mn(n){if(!(n.ctrlKey||n.metaKey))return n.key.length===1?n.key:n.key==="Enter"?"\r":void 0}function mt(n,e,t){return e===an?n*cn:e===on?n*t:n}function hn(n,e,t){try{n.drawImage(e,t.x,t.y,t.width,t.height)}catch{}}function xn(n){const e=ye.c(85),{frame:t,send:l,onSizeChange:a,className:u}=n,d=r.useRef(null),f=r.useRef(null),x=r.useRef(null),b=r.useRef(null),y=r.useRef(!1);let k;e[0]===Symbol.for("react.memo_cache_sentinel")?(k={count:0,at:0,x:0,y:0,button:-1},e[0]=k):k=e[0];const _=r.useRef(k);let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[1]=p):p=e[1];const C=r.useRef(p);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j={width:0,height:0,dpr:1},e[2]=j):j=e[2];const[g,c]=r.useState(j),[i,h]=r.useState(!1),m=t?t.header.deviceWidth:0,S=t?t.header.deviceHeight:0;let N;e[3]!==S||e[4]!==m||e[5]!==g?(N=Qs(g,{width:m,height:S}),e[3]=S,e[4]=m,e[5]=g,e[6]=N):N=e[6];const v=N,B=r.useRef(a);let E,P;e[7]!==a?(E=()=>{B.current=a},P=[a],e[7]=a,e[8]=E,e[9]=P):(E=e[8],P=e[9]),r.useEffect(E,P);let R,$;e[10]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const M=d.current;if(!M)return;let o=null;const A=()=>{const pe=M.getBoundingClientRect(),Ce=Math.round(pe.width),De=Math.round(pe.height),Ae=window.devicePixelRatio||1;c(ne=>ne.width===Ce&&ne.height===De&&ne.dpr===Ae?ne:{width:Ce,height:De,dpr:Ae}),o&&clearTimeout(o),o=setTimeout(()=>{o=null,Ce>0&&De>0&&B.current(Ce,De,Ae)},ln)};A();const U=new ResizeObserver(A);return U.observe(M),()=>{U.disconnect(),o&&clearTimeout(o)}},$=[],e[10]=R,e[11]=$):(R=e[10],$=e[11]),r.useEffect(R,$);let Y,F;e[12]!==v||e[13]!==t||e[14]!==g?(F=()=>{const M=f.current,o=M==null?void 0:M.getContext("2d");if(!M||!o)return;const A=Math.round(g.width*g.dpr),U=Math.round(g.height*g.dpr);M.width!==A&&(M.width=A),M.height!==U&&(M.height=U),o.setTransform(g.dpr,0,0,g.dpr,0,0),o.clearRect(0,0,g.width,g.height),!(!t||v.width<=0||v.height<=0)&&hn(o,t.bitmap,v)},Y=[t,v,g],e[12]=v,e[13]=t,e[14]=g,e[15]=Y,e[16]=F):(Y=e[15],F=e[16]),r.useEffect(F,Y);let T,w;e[17]!==t?(T=()=>()=>Ge(t),w=[t],e[17]=t,e[18]=T,e[19]=w):(T=e[18],w=e[19]),r.useEffect(T,w);let V;e[20]!==v?(V=function(o,A,U){const pe=f.current;return pe?ot(o,A,pe.getBoundingClientRect(),v,{clamp:U}):null},e[20]=v,e[21]=V):V=e[21];const L=V;let Q;e[22]!==l?(Q=function(o,A,U,pe,Ce){l({type:"mouse",event:o,x:A.x,y:A.y,button:U,clickCount:pe,modifiers:Ce})},e[22]=l,e[23]=Q):Q=e[23];const O=Q;let X;e[24]===Symbol.for("react.memo_cache_sentinel")?(X=function(o){const A=_.current,U=Date.now(),pe=o.button===A.button&&U-A.at<rn&&Math.abs(o.clientX-A.x)<=dt&&Math.abs(o.clientY-A.y)<=dt;return _.current={count:pe?A.count+1:1,at:U,x:o.clientX,y:o.clientY,button:o.button},_.current.count},e[24]=X):X=e[24];const z=X;let D;e[25]!==L||e[26]!==O?(D=function(){const o=x.current;if(x.current=null,!o)return;const A=L(o.clientX,o.clientY,y.current);A&&O("move",A,"none",0,o.modifiers)},e[25]=L,e[26]=O,e[27]=D):D=e[27];const G=D;let K;e[28]!==G?(K=function(){b.current!==null&&(cancelAnimationFrame(b.current),b.current=null),G()},e[28]=G,e[29]=K):K=e[29];const q=K;let W;e[30]!==L||e[31]!==O?(W=function(o){if(o.currentTarget.focus(),o.button===ut)return;const A=L(o.clientX,o.clientY,!1);A&&(o.currentTarget.setPointerCapture(o.pointerId),y.current=!0,O("down",A,ct(o.button),z(o),Ie(o)))},e[30]=L,e[31]=O,e[32]=W):W=e[32];const J=W;let te;e[33]!==G?(te=function(o){x.current={clientX:o.clientX,clientY:o.clientY,modifiers:Ie(o)},b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null,G()}))},e[33]=G,e[34]=te):te=e[34];const ge=te;let ce;e[35]!==q||e[36]!==L||e[37]!==O?(ce=function(o){q();const A=y.current;if(y.current=!1,o.currentTarget.hasPointerCapture(o.pointerId)&&o.currentTarget.releasePointerCapture(o.pointerId),o.button===ut)return;const U=L(o.clientX,o.clientY,A);U&&O("up",U,ct(o.button),_.current.count,Ie(o))},e[35]=q,e[36]=L,e[37]=O,e[38]=ce):ce=e[38];const he=ce;let ue;e[39]!==L||e[40]!==O?(ue=function(o){o.preventDefault();const A=L(o.clientX,o.clientY,!1);if(!A)return;const U=Ie(o);O("down",A,"right",1,U),O("up",A,"right",1,U)},e[39]=L,e[40]=O,e[41]=ue):ue=e[41];const de=ue;let fe;e[42]!==l?(fe=function(o){if(o.key==="Escape"){o.currentTarget.blur();return}ft(o)||o.preventDefault();const A={type:"key",event:"down",key:o.key,code:o.code,modifiers:Ie(o)},U=mn(o);U!==void 0&&(A.text=U),C.current.set(o.code,o.key),l(A)},e[42]=l,e[43]=fe):fe=e[43];const Se=fe;let ae;e[44]!==l?(ae=function(o){o.key!=="Escape"&&(ft(o)||o.preventDefault(),C.current.delete(o.code),l({type:"key",event:"up",key:o.key,code:o.code,modifiers:Ie(o)}))},e[44]=l,e[45]=ae):ae=e[45];const me=ae;let oe,re;e[46]!==S||e[47]!==m||e[48]!==v||e[49]!==l?(oe=()=>{const M=f.current;if(!M)return;const o=A=>{A.preventDefault();const U=ot(A.clientX,A.clientY,M.getBoundingClientRect(),v);U&&l({type:"wheel",x:U.x,y:U.y,deltaX:mt(A.deltaX,A.deltaMode,m),deltaY:mt(A.deltaY,A.deltaMode,S),modifiers:Ie(A)})};return M.addEventListener("wheel",o,{passive:!1}),()=>M.removeEventListener("wheel",o)},re=[l,v,m,S],e[46]=S,e[47]=m,e[48]=v,e[49]=l,e[50]=oe,e[51]=re):(oe=e[50],re=e[51]),r.useEffect(oe,re);let I,ee;e[52]!==i||e[53]!==l?(I=()=>{if(!i)return;const M=o=>{var U;const A=(U=o.clipboardData)==null?void 0:U.getData("text/plain");A&&(o.preventDefault(),l({type:"paste",text:A}))};return document.addEventListener("paste",M),()=>document.removeEventListener("paste",M)},ee=[i,l],e[52]=i,e[53]=l,e[54]=I,e[55]=ee):(I=e[54],ee=e[55]),r.useEffect(I,ee);let se,je;e[56]===Symbol.for("react.memo_cache_sentinel")?(se=()=>()=>{b.current!==null&&cancelAnimationFrame(b.current)},je=[],e[56]=se,e[57]=je):(se=e[56],je=e[57]),r.useEffect(se,je);let be;e[58]!==l?(be=()=>{for(const[M,o]of C.current)l({type:"key",event:"up",key:o,code:M,modifiers:0});C.current.clear()},e[58]=l,e[59]=be):be=e[59];const ie=be;let we,H;e[60]!==ie?(we=()=>ie,H=[ie],e[60]=ie,e[61]=we,e[62]=H):(we=e[61],H=e[62]),r.useEffect(we,H);let le;e[63]!==u?(le=Re("relative min-h-0 min-w-0 overflow-hidden bg-muted/30",u),e[63]=u,e[64]=le):le=e[64];const Ne=i&&"ring-2 ring-ring ring-inset";let xe;e[65]!==Ne?(xe=Re("block size-full cursor-default touch-none select-none outline-none",Ne),e[65]=Ne,e[66]=xe):xe=e[66];let _e;e[67]===Symbol.for("react.memo_cache_sentinel")?(_e=()=>h(!0),e[67]=_e):_e=e[67];let ke;e[68]!==ie?(ke=()=>{h(!1),ie()},e[68]=ie,e[69]=ke):ke=e[69];let Ee;e[70]!==de||e[71]!==Se||e[72]!==me||e[73]!==J||e[74]!==ge||e[75]!==he||e[76]!==xe||e[77]!==ke?(Ee=s.jsx("canvas",{ref:f,role:"application","aria-label":"Browser viewport",tabIndex:0,className:xe,onFocus:_e,onBlur:ke,onPointerDown:J,onPointerMove:ge,onPointerUp:he,onPointerCancel:he,onContextMenu:de,onKeyDown:Se,onKeyUp:me}),e[70]=de,e[71]=Se,e[72]=me,e[73]=J,e[74]=ge,e[75]=he,e[76]=xe,e[77]=ke,e[78]=Ee):Ee=e[78];let ve;e[79]!==i?(ve=i&&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:un})}),e[79]=i,e[80]=ve):ve=e[80];let Te;return e[81]!==le||e[82]!==Ee||e[83]!==ve?(Te=s.jsxs("div",{ref:d,className:le,children:[Ee,ve]}),e[81]=le,e[82]=Ee,e[83]=ve,e[84]=Te):Te=e[84],Te}const pn="browser-panel-session",gn="browser-panel-follow",bn=1e4,ht=3e3,wn=[];function Dn({context:n,active:e,closePanel:t}){var oe,re;const[l,a]=et(tt(pn),Oe),[u,d]=et(tt(gn),!0),[f,x]=r.useState(!1),[b,y]=r.useState(null),[k,_]=r.useState(null),[p,C]=r.useState(!1),j=r.useRef(0),{status:g,error:c,create:i,remove:h,stop:m,setArchived:S,readSkillTargets:N,installSkill:v}=ws(e),B=r.useCallback(I=>void xt(I),[]),E=Ds(e?l:null,B),P=(g==null?void 0:g.sessions)??wn,R=r.useMemo(()=>ls(n.session),[n.session]),$=(R==null?void 0:R.session)??null,Y=P.some(I=>I.name===$&&!I.archived);r.useEffect(()=>{!u||$===null||$===l||!Y||Date.now()-j.current<bn||a($)},[u,$,Y,l,a]);const F=r.useCallback(I=>{j.current=Date.now(),a(I)},[a]),T=r.useCallback(async I=>{x(!0);try{const ee=await I();return y(ee.ok?null:ee.error),ee}finally{x(!1)}},[]),{send:w}=E,V=r.useCallback((I,ee,se)=>{w({type:"viewport",width:I,height:ee,dpr:se})},[w]),L=r.useCallback(I=>{I&&(j.current=0),d(I)},[d]),Q=r.useCallback(()=>F(Oe),[F]),O=r.useCallback(()=>C(!0),[]),X=r.useCallback(I=>{F(Oe),T(()=>h(I))},[F,T,h]),z=r.useCallback(I=>void T(()=>m(I)),[T,m]),D=r.useCallback(async(I,ee)=>{const se=await T(()=>S(I,ee));return se.ok&&ee&&I===l&&F(Oe),se},[T,S,l,F]),G=r.useCallback(I=>w({type:"navigate",url:I}),[w]),K=r.useCallback(()=>w({type:"back"}),[w]),q=r.useCallback(()=>w({type:"forward"}),[w]),W=r.useCallback(()=>w({type:"reload"}),[w]),J=r.useCallback(I=>w({type:"follow",targetId:I}),[w]),te=r.useCallback(I=>w({type:"close-tab",targetId:I}),[w]),ge=yn(E.lastFrameAt),ce=((oe=E.state)==null?void 0:oe.state)??null,he=(g==null?void 0:g.installed)===!1||ce==="not-installed",ue=!he&&ce==="live",de=!he&&ce==="stopped",fe=P.find(I=>I.name===l)??null,Se=ue&&(E.status==="disconnected"||E.status==="connecting"),ae=E.error??b??c,me=ae!==null&&ae!==k?ae:null;return s.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[s.jsx(Ws,{sessions:P,selected:l,currentSessionId:((re=n.session)==null?void 0:re.sessionId)??null,followAgent:u,busy:f,onSelect:F,onToggleFollow:L,onOpenSkill:O,onCreate:i,onRemove:X,onStop:z,onSetArchived:D,onShowDefault:Q,onClose:t}),ue&&s.jsx(Ms,{page:E.page,tabs:E.tabs,followed:E.followed,status:Se?"offline":ge,onNavigate:G,onBack:K,onForward:q,onReload:W,onFollow:J,onCloseTab:te}),me&&s.jsx(kn,{message:me,onDismiss:()=>{y(null),_(ae)}}),s.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[he&&s.jsx(Ls,{onOpenSkill:O}),de&&s.jsx(Os,{name:l,lastUrl:(fe==null?void 0:fe.lastUrl)??null,onOpen:I=>w({type:"launch",url:I})}),ue&&s.jsxs(s.Fragment,{children:[s.jsx(xn,{className:"flex-1",frame:E.frame,send:w,onSizeChange:V}),Se&&s.jsx(Sn,{}),s.jsx(Rs,{activity:R&&R.session===l?R:null})]}),!he&&!de&&!ue&&s.jsxs("div",{role:"status",className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(Rt,{}),"Connecting to ",l,"…"]})]}),s.jsx(Js,{open:p,onOpenChange:C,readTargets:N,install:v})]})}function yn(n){const e=ye.c(5),[,t]=r.useState(0);let l;e[0]!==t||e[1]!==n?(l=()=>{if(n===null)return;const u=n+ht-Date.now();if(u<=0)return;const d=setTimeout(()=>t(jn),u);return()=>clearTimeout(d)},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],r.useEffect(l,a),n===null?"idle":Date.now()-n<ht?"live":"idle"}function jn(n){return n+1}function Sn(){const n=ye.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 kn(n){const e=ye.c(9),{message:t,onDismiss:l}=n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=s.jsx(Ot,{"aria-hidden":!0,className:"size-3.5 shrink-0"}),e[0]=a):a=e[0];let u;e[1]!==t?(u=s.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e[1]=t,e[2]=u):u=e[2];let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(Fe,{"data-icon":"inline-start"}),e[3]=d):d=e[3];let f;e[4]!==l?(f=s.jsx(Z,{variant:"ghost",size:"icon-xs","aria-label":"Dismiss",onClick:l,children:d}),e[4]=l,e[5]=f):f=e[5];let x;return e[6]!==u||e[7]!==f?(x=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,u,f]}),e[6]=u,e[7]=f,e[8]=x):x=e[8],x}export{Dn as BrowserPanel};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
(function(){"use strict";const mt=["codex","copilot","claude"],gt="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";function Pe(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 wt(t){return{lossy:!1,owns:e=>typeof e=="string"&&e.startsWith(t),encode:e=>Pe(t,e),decode:e=>Re(t,e)}}function Mt(t){const e=new RegExp(`(${gt})\\.jsonl$`,"i").exec(t);return e?e[1]:null}const Et={urlId:t=>t.replace(/\.jsonl$/,""),fileNameFromUrlId:t=>t.endsWith(".jsonl")?t:`${t}.jsonl`};function Nt(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}",vt="codex__",Bt="copilot__",Fe=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(vt)&&!t.startsWith(Bt),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:Mt,...Et},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"]:[...Fe.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,configurableContextWindow:!1,fastTier:!0,lowPriorityInTerminal:!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}},Pt={appServerValue:"priority",cliConfigValue:"fast"},$e={kind:"codex",displayName:"Codex",binName:"codex",dirName:wt(vt),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:Mt,...Et},metadataFromHead:!1,resume:{command:(t,e)=>e?`codex -C ${Nt(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"]:e==="auto"?["--approve-for-me"]:["--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(Pt.cliConfigValue)}`,"--enable","fast_mode"]:[]},serviceTier:Pt,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:!0,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,configurableContextWindow:!0,fastTier:!0,lowPriorityInTerminal:!1,imageInput:!0,midTurnSteering:!0,stopSession:!1,ultracode:!1,contextWindow:!1,externalProcesses:!1,accountSwitching:!1,modelFallbackNotices:!1,autoPermissionMode:"always",settingsApply:"next-turn",turnLiveness:"runtime",tokenStreaming:!0,nativeFork:!1,namedSessions:!1}},De={kind:"copilot",displayName:"GitHub Copilot CLI",binName:"copilot",dirName:wt(Bt),sessionFile:{name:t=>`${t}/events.jsonl`,sessionId:t=>{const e=new RegExp(`^(${gt})/events\\.jsonl$`,"i").exec(t);return e?e[1]:null},urlId:t=>{const e=new RegExp(`^(${gt})/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 ${Nt(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,configurableContextWindow:!1,fastTier:!1,lowPriorityInTerminal:!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}},Oe=Object.freeze({claude:Ue,codex:$e,copilot:De});function ht(t){return Oe[t]}const Rt={0:"\0",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" ",v:"\v"};function Ft(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 g=t.slice(o+1,o+5);if(/^[0-9a-fA-F]{4}$/.test(g)){s+=String.fromCharCode(Number.parseInt(g,16)),o+=5;continue}}s+=l,o++}return null}function yt(t){return t.type==="user"}function _t(t){return t.type==="assistant"}function Ut(t){return t.type==="progress"}function $t(t){return t.type==="system"}function Dt(t){return t.type==="summary"}function je(t){return t.type==="queue-operation"}function Ot(t){return t.type==="attachment"}function We(t){return t.type==="user"&&t.isCompactSummary===!0}function jt(t){return t.type==="system"&&t.subtype==="compact_boundary"}function Wt(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+=Wt(n.toolCalls,e.toolCallCounts);for(const s of n.subAgentActivity)e.errorCount+=Wt(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,qe=[/\bteammate_id=(?:"([^"]*)"|'([^']*)')/,/\bfrom=(?:"([^"]*)"|'([^']*)')/];function ze(t){for(const e of qe){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 kt(t){let e=null,n=!1;const s=t.replace(Le,(o,i,l,f)=>(n=!0,e===null&&(e=ze(l)),f.trim()));return{sender:e,matched:n,body:n?s.trim():t}}function at(t){return t&&typeof t=="object"?t:{}}function Je(t,e){const n=at(e);if(t==="Edit"||t==="Write")return n.staged===!0?{awaitingReview:!0}:{};if(t!=="Bash")return{};const s=at(n.bashEditDiff);if(!Array.isArray(s.files))return{};const o=[];for(const l of s.files){const f=at(l);if(typeof f.filePath!="string"||!f.filePath||!Array.isArray(f.hunks))continue;const g=[];for(const b of f.hunks){const T=at(b),{oldStart:y,oldLines:_,newStart:d,newLines:N,lines:E}=T;[y,_,d,N].every(w=>typeof w=="number"&&Number.isInteger(w)&&w>=0)&&(!Array.isArray(E)||!E.every(w=>typeof w=="string"&&/^[ +\\-]/.test(w))||g.push({oldStart:y,oldLines:_,newStart:d,newLines:N,lines:E}))}g.length&&o.push({filePath:f.filePath,hunks:g})}const i=typeof s.moreFiles=="number"&&Number.isInteger(s.moreFiles)&&s.moreFiles>0?s.moreFiles:0;return{fileDiffs:o,...i?{additionalFileDiffs:i}:{}}}function lt(t){return typeof t=="string"?t:t.filter(e=>e.type==="text").map(e=>e.text).join(`
|
|
5
|
+
`)}function qt(t){return t?typeof t=="string"?t:t.map(e=>e.type==="text"?e.text:"").filter(Boolean).join(`
|
|
6
|
+
`):""}function zt(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 Qe=/<task-notification>[\s\S]*?<\/task-notification>/g,Ve=/<[^>]*>/g;function Ke(t){var n;if(((n=t.origin)==null?void 0:n.kind)==="task-notification")return!0;const e=lt(t.message.content);return e.includes("<task-notification>")?e.replace(Qe,"").replace(Ve,"").trim()==="":!1}function Ge(t){if(!Ot(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:lt(n);if(!zt(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??kt(s).body}}if((o==null?void 0:o.kind)==="human")return{raw:s,sender:null,body:s};const i=kt(s);return{raw:s,sender:i.sender,body:i.body}}const He=[["attributionAgent","agent"],["attributionSkill","skill"],["attributionPlugin","plugin"],["attributionMcpServer","mcpServer"],["attributionMcpTool","mcpTool"]];function Xe(t,e){let n=t;for(const[s,o]of He){const i=e[s];typeof i!="string"||!i||(n={...n,[o]:i})}return n}const Ze=/^This session is being continued from a previous conversation[\s\S]*?\n\nSummary:\s*\n/,Ye=/\n+(?:If you need specific details from before compaction|(?:Please c|C)ontinue the conversation from where it left off)[\s\S]*$/;function tn(t){return lt(t).trim().replace(Ze,"").replace(Ye,"").trim()}function en(t){if(t)return{trigger:t.trigger,preTokens:t.preTokens,postTokens:t.postTokens}}function ct(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 nn(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,g=s.toolCalls.slice(0,o);g.length>0&&e.push({kind:"tool_calls",toolCalls:g,timestamp:s.timestamp});const b=[],T=s.toolCalls.slice(o+1),y=T.findIndex(_=>_.name==="ExitPlanMode");if(y!==-1){b.push(...T.slice(0,y));const _=T[y],d=_.input.path?String(_.input.path):void 0;let N="pending";_.result!==null&&(N=_.isError?"rejected":"approved"),e.push({kind:"plan_mode",plan:l,planFilePath:d,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 _,d,N="pending",E=n+1;const w=[];for(;E<t.length;){const v=t[E];if(v.kind==="tool_calls"){const P=v.toolCalls.findIndex($=>$.name==="ExitPlanMode");if(P!==-1){b.push(...v.toolCalls.slice(0,P)),_=v.toolCalls[P],d=_.input.path?String(_.input.path):void 0,_.result!==null&&(N=_.isError?"rejected":"approved");const $=v.toolCalls.slice(P+1);e.push({kind:"plan_mode",plan:l,planFilePath:d,status:N,toolCalls:b,timestamp:f}),e.push(...w),$.length>0&&e.push({kind:"tool_calls",toolCalls:$,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")w.push(v),E++;else break}_||(e.push({kind:"plan_mode",plan:l,planFilePath:void 0,status:"pending",toolCalls:b,timestamp:f}),e.push(...w),n=E);continue}}}e.push(s),n++}return e}function sn(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 Jt(t){var s;const e=t.map(sn),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 g=(s=n.get(f))==null?void 0:s.shift();if(!g)continue;const b=l.input.summary;g.reply={summary:typeof b=="string"?b:"",timestamp:l.timestamp||i.timestamp||""}}}return e}function on(t){const e=[];let n=!1;for(let s=0;s<t.length;s++){const o=t[s];if(Dt(o)||jt(o)){n=!1;continue}if(yt(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}_t(o)&&!n&&(e.push(s),n=!0)}return e}function Qt(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 g=null;const b=new Map,T=new Set,y=new Map,_=new Map,d=new Set,N=new Map,E=[],w=new Map;function v(r,c){let m=w.get(r);m||(m=new Map,w.set(r,m)),m.set(c,(m.get(c)??0)+1)}function P(r,c){const m=w.get(r),p=m==null?void 0:m.get(c);return!m||!p?!1:(p===1?m.delete(c):m.set(c,p-1),!0)}function $(){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=d.has(r)?"background_agent":"sub_agent",p=_.get(r);if(p)p.messages.push(...c);else{const a={kind:m,messages:[...c]};i.contentBlocks.push(a),_.set(r,a)}}function W(){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 p=i.toolCalls.find(a=>a.id===c.toolUseId);p&&(c.updatedToolOutput&&(p.outputReplacedByHook=!0),c.durationMs!==void 0&&(p.hookDurationMs=(p.hookDurationMs??0)+c.durationMs))}i.contentBlocks=nn(i.contentBlocks),e.push(i),s!==null&&n.push(s),s=null,i=null,_.clear()}}for(o=0;o<t.length;o++){const r=t[o];if(Dt(r)){W(),l={summary:r.summary};continue}if(jt(r)){W(),l={meta:en(r.compactMetadata)};continue}if(We(r)){W(),s=o,i=ct(r,null),i.compactionSummary=tn(r.message.content),i.compactionMeta=l==null?void 0:l.meta,l=null;continue}if($t(r)&&r.subtype==="away_summary"&&r.content){g={content:r.content,timestamp:r.timestamp};continue}if(je(r)){if(i&&r.operation==="enqueue"&&zt(r.content)){const c=kt(r.content);E.push({turn:i,content:r.content,timestamp:r.timestamp,sender:c.sender,body:c.body}),v(i,r.content)}continue}if(Ot(r)){const c=Ge(r);i&&c!==null&&!P(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=yt(r)&&!r.isMeta?r.message.content:null;if(typeof c=="string"){const m=E.findIndex(p=>p.content===c);if(m>=0){const[p]=E.splice(m,1);P(p.turn,p.content)}}$()}if(yt(r)&&!r.isMeta){const c=r.message.content;if(typeof c!="string"&&Array.isArray(c)&&c.some(p=>p.type==="tool_result")&&i){for(const a of c)if(a.type==="tool_result"){const k=b.get(a.tool_use_id);if(k){k.turn.toolCalls[k.index].result=qt(a.content),k.turn.toolCalls[k.index].isError=a.is_error===!0;const u=k.turn.toolCalls[k.index];Object.assign(u,Je(u.name,r.toolUseResult)),b.delete(a.tool_use_id)}}const p=r.toolUseResult;if(p!=null&&p.agentId){const a=((S=c.find(I=>I.type==="tool_result"))==null?void 0:S.tool_use_id)??"",k=N.get(a),u=d.has(a),C=[];if(Array.isArray(p.content))for(const I of p.content)I.type==="text"&&C.push(I.text);const h={agentId:p.agentId,parentToolUseId:a||void 0,agentName:(k==null?void 0:k.name)??null,subagentType:(k==null?void 0:k.subagentType)??null,type:"assistant",content:p.content,toolCalls:[],thinking:[],text:C,timestamp:r.timestamp??"",tokenUsage:p.usage?{input_tokens:p.usage.input_tokens??0,output_tokens:p.usage.output_tokens??0,cache_creation_input_tokens:p.usage.cache_creation_input_tokens??0,cache_read_input_tokens:p.usage.cache_read_input_tokens??0}:null,model:null,isBackground:u,prompt:p.prompt,status:p.status,durationMs:p.totalDurationMs,toolUseCount:p.totalToolUseCount};if(!_.get(a)){i.subAgentActivity.push(h);const M={kind:u?"background_agent":"sub_agent",messages:[h]};i.contentBlocks.push(M),_.set(a,M)}}continue}if(Ke(r)){const m={kind:"task_notification",content:lt(c),timestamp:r.timestamp};if(i){i.contentBlocks.push(m);continue}s=o,i=ct(r,null),i.contentBlocks.push(m),f(i);continue}W(),s=o,i=ct(r,r.message.content),f(i),g&&(i.contentBlocks.push({kind:"recap",content:g.content,timestamp:g.timestamp}),g=null);continue}if(_t(r)){let c=function(){u.length>0&&(C.contentBlocks.push({kind:"tool_calls",toolCalls:[...u],timestamp:a}),u.length=0)},m=function(){if(k.length>0){const h=C.contentBlocks[C.contentBlocks.length-1];h&&h.kind==="thinking"?h.blocks.push(...k):C.contentBlocks.push({kind:"thinking",blocks:[...k],timestamp:a}),k.length=0}};i||(s=o,i=ct(r,null),f(i)),i.model=r.message.model,r.effort&&(i.effort=r.effort),i.attribution=Xe(i.attribution,r);const p=r.message.id;T.has(p)||(T.add(p),i.tokenUsage=Q(i.tokenUsage,r.message.usage));const a=r.timestamp??"",k=[],u=[],C=i;for(const h of r.message.content)if(h.type==="thinking"){c();const x=h;if(!x.thinking)continue;i.thinking.push(x),k.push(x)}else if(h.type==="text"){c(),m();const x=/<thinking>([\s\S]*?)<\/thinking>/g;let I=h.text,M;for(;(M=x.exec(h.text))!==null;){const U=M[1].trim();if(U){const B={type:"thinking",thinking:U,signature:""};i.thinking.push(B),i.contentBlocks.push({kind:"thinking",blocks:[B],timestamp:a})}I=I.replace(M[0],"")}if(I=I.trim(),I){i.assistantText.push(I);const U=i.contentBlocks[i.contentBlocks.length-1];U&&U.kind==="text"?U.text.push(I):i.contentBlocks.push({kind:"text",text:[I],timestamp:a})}}else if(h.type==="tool_use"){m();const x={id:h.id,name:h.name,input:h.input,result:null,isError:!1,timestamp:r.timestamp??""},I=i.toolCalls.length;if(i.toolCalls.push(x),u.push(x),b.set(h.id,{turn:i,index:I}),h.name==="Task"||h.name==="Agent"){const M=h.input;M.run_in_background===!0&&d.add(h.id),N.set(h.id,{name:M.name??null,subagentType:M.subagent_type??null})}}m(),c();continue}if(Ut(r)&&r.data.type==="agent_progress"){const c=r.data,m=r.parentToolUseID??"";let p=null;if(c.message.type==="assistant"){const h=c.message.message,x=h.id,I=h.usage;I&&x&&!T.has(x)&&(T.add(x),p={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,k=N.get(m),u={agentId:c.agentId,parentToolUseId:m||void 0,agentName:(k==null?void 0:k.name)??null,subagentType:(k==null?void 0:k.subagentType)??null,type:c.message.type,content:c.message.message.content,toolCalls:[],thinking:[],text:[],timestamp:c.message.timestamp??r.timestamp??"",tokenUsage:p,model:a,isBackground:d.has(m)};if(c.message.type==="assistant"){const h=c.message.message.content;if(Array.isArray(h))for(const x of h)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 h=c.message.message.content;if(Array.isArray(h)){for(const x of h)if(x.type==="tool_result"){const I=y.get(m);if(I)for(const M of I){const U=M.toolCalls.find(B=>B.id===x.tool_use_id);U&&(U.result=qt(x.content),U.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"),p=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:(p==null?void 0:p.updatedToolOutput)!==void 0?String(p.updatedToolOutput):void 0,sessionTitle:(p==null?void 0:p.sessionTitle)!==void 0?String(p.sessionTitle):void 0,worktreePath:(p==null?void 0:p.worktreePath)!==void 0?String(p.worktreePath):void 0,timestamp:r.timestamp??""};if(i){const k=i.contentBlocks[i.contentBlocks.length-1];k&&k.kind==="hook_event"?k.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 $(),W(),{turns:Jt(e),turnStartIndices:n}}function Vt(t){return Qt(t).turns}function Kt(){return!0}function Gt(t){const e=[];for(const n of t){const s=n.trim();if(s)try{e.push(JSON.parse(s))}catch{}}return e}function Ht(t){return Gt(t.split(`
|
|
7
|
+
`))}function Xt(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),_t(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 rn(t){return Xt(Gt(t))}function an(t,e){const n=Ht(t),s=Xt(n),o=Vt(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 ln(t,e){const n=Ht(e);if(n.length===0)return t;const s=t.rawMessages,o=[...s,...n],i=on(s),l=Math.max(0,t.turns.length-i.length);let f=Math.max(0,i.length-1);const g=new Set;for(const N of n)if(N.type==="progress"){const E=N.parentToolUseID;E&&g.add(E)}if(g.size>0)for(let N=f-1;N>=0;N--){const E=t.turns[l+N];if(E!=null&&E.toolCalls.some(w=>g.has(w.id))){f=N;break}}const b=i[f]??s.length,T=t.turns.slice(0,l+f),y=Vt(o.slice(b)),_=Jt([...T,...y]),d=rt(_);return{sessionId:t.sessionId,version:t.version,gitBranch:t.gitBranch,cwd:t.cwd,slug:t.slug,name:t.name,model:t.model||_.length>0&&_[_.length-1].model||"",turns:_,stats:d,rawMessages:o,branchedFrom:t.branchedFrom,agentKind:t.agentKind}}const Zt="<task-notification>",cn=/<task-id>([^<]+)<\/task-id>/g,un=/<tool-use-id>([^<]+)<\/tool-use-id>/g;function L(t){return typeof t=="object"&&t!==null}function dn(t){const e=L(t.message)?t.message:null,n=e==null?void 0:e.content;return typeof n=="string"?[n]:Array.isArray(n)?n.filter(s=>L(s)&&typeof s.text=="string").map(s=>s.text):[]}function pn(t){const e=[],n=new Set,s=new Set,o=new Set;function i(l,f){if(l.includes(Zt)){for(const g of l.matchAll(cn))n.add(g[1]),f==null||f.add(g[1]);for(const g of l.matchAll(un))n.add(g[1]),f==null||f.add(g[1])}}for(const l of t){if(l.type==="user"){const f=L(l.toolUseResult)?l.toolUseResult:null;if((f==null?void 0:f.status)==="async_launched"){const g=L(l.message)?l.message:null,T=(Array.isArray(g==null?void 0:g.content)?g.content:[]).filter(d=>L(d)&&d.type==="tool_result").map(d=>d.tool_use_id),y=[f.agentId,f.taskId,...T].filter(d=>typeof d=="string"&&d.length>0),_=[f.description,f.workflowName,f.summary].find(d=>typeof d=="string"&&d.length>0)??"";y.length>0&&e.push({ids:y,description:_})}for(const g of dn(l))i(g,o);continue}if(l.type==="assistant"){const f=L(l.message)?l.message:null,g=Array.isArray(f==null?void 0:f.content)?f.content:[];for(const b of g){if(!L(b)||b.type!=="tool_use"||b.name!=="TaskStop")continue;const T=L(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=L(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 fn(t,e){return{status:"awaiting_agents",pendingQueue:e,pendingAgents:t.length,pendingAgentDescriptions:t.filter(n=>n.length>0)}}function mn(t){var l,f;let e=0,n=null,s=!1;function o(g,b){const T={status:g,pendingQueue:Math.max(0,e)};return b&&(T.toolName=b),T}function i(){return n??(n=pn(t))}for(let g=t.length-1;g>=0;g--){const b=t[g];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 g=t.length-1;g>=0;g--){const b=t[g];if(b.type==="queue-operation"){if(typeof b.content=="string"&&b.content.includes(Zt))continue;const T=b.operation;T==="enqueue"?e++:(T==="dequeue"||T==="remove")&&e--;continue}if(b.type==="attachment"){const T=L(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 _=i();if(s||_.undeliveredNotifications>0)return o("processing");if(_.pendingDescriptions.length>0)return fn(_.pendingDescriptions,Math.max(0,e));let d=!1;for(let N=g-1;N>=0;N--){const E=t[N];if(E.type==="user"&&!E.isMeta){d=!0;break}}return o(d?"completed":"idle")}if(y==="tool_use"){const _=T==null?void 0:T.content,d=(f=_==null?void 0:_.findLast)==null?void 0:f.call(_,N=>N.type==="tool_use");return o("tool_use",d==null?void 0:d.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 gn(t,e,n){const s=typeof t.sessionId=="string"?t.sessionId:"";return{record:{...t,sessionId:e,branchedFrom:{sessionId:s,turnIndex:n}},originalId:s}}function hn(t){return Qt(t).turnStartIndices}function Yt(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 te(t){return t.includes("*** Begin Patch")&&t.includes("*** End Patch")}function yn(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=Ft(t,l);if(f){if(te(f.value)){const g=t.slice(0,l).match(/(?:^|[;\n])\s*(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*$/);g&&e.set(g[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=Ft(t,l),g=f?null:t.slice(l).match(/^([A-Za-z_$][\w$]*)/),b=(f==null?void 0:f.value)??(g?e.get(g[1]):void 0);!b||!te(b)||s.has(b)||(s.add(b),n.push(b))}return n}function ee(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 ne(t,e,n,s=""){var g,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],_=T+1<l.length?l[T+1].headerIdx:t.length,d=t.slice(y.startIdx,_),N=(b=(g=d.match(/^\*\*\*\s+Move to:\s*(.+)$/m))==null?void 0:g[1])==null?void 0:b.trim(),E=ee(y.filePath,s),w=ee(N||y.filePath,s),v=d.split(/^@@.*$/m).filter(W=>W.trim()),P=[],$=[];for(const W of v)for(const D of W.split(`
|
|
8
|
+
`))D.startsWith("-")?P.push(D.slice(1)):D.startsWith("+")?$.push(D.slice(1)):D.startsWith(" ")&&(P.push(D.slice(1)),$.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:w,content:$.join(`
|
|
9
|
+
`)},result:null,isError:!1,timestamp:n}):y.action==="Delete File"?o.push({id:j,name:"Edit",input:{file_path:w,old_string:P.join(`
|
|
10
|
+
`),new_string:""},result:null,isError:!1,timestamp:n}):o.push({id:j,name:"Edit",input:{file_path:w,...N?{old_path:E}:{},old_string:P.join(`
|
|
11
|
+
`),new_string:$.join(`
|
|
12
|
+
`)},result:null,isError:!1,timestamp:n})}return o}function _n(t,e,n,s,o=""){return t==="apply_patch"?ne(e,n,s,o):yn(e).flatMap((i,l)=>ne(i,`${n}:patch-${l}`,s,o))}function kn(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 g of n){const b=(f=g.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(g),s.set(T,y)}if(s.size===0)return new Set(n.map(g=>g.id));const o=t.toLowerCase().replaceAll("\\","/"),i=new Set;for(const[g,b]of s)b.some(T=>{const y=String(T.input.file_path??"").toLowerCase().replaceAll("\\","/");if(!y)return!1;const d=y.split("/").filter(Boolean).slice(-2).join("/");return o.includes(y)||d.includes("/")&&o.includes(d)})&&i.add(g);for(const g of o.matchAll(/\bpatch\s*(?:#|-)?\s*(\d+)\b/g)){const b=Number(g[1]);s.has(b)&&i.add(b)}i.size===0&&i.add(Math.max(...s.keys()));const l=Math.min(...i);for(const g of s.keys())g>=l&&i.add(g);return new Set([...i].flatMap(g=>{var b;return((b=s.get(g))==null?void 0:b.map(T=>T.id))??[]}))}function q(t){return typeof t=="object"&&t!==null}const bn=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"]]),Tn=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 bn.get(e)??(Tn.has(e)?e:t)}function Cn(t){const e=t==null?void 0:t.match(/Process exited with code (\d+)/);return e?e[1]!=="0":!1}function xn(t){return t==="request_user_input"||t==="request_user_input_async"}function In(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 An(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 Sn(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 se(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=Sn(s);o&&n.push(o)}return{parts:e,text:e.join(""),images:n}}const wn=/^Script (?:completed|failed|running)\b/;function oe(t,e){q(t)&&(t.status==="rejected"?e.push(1):t.status==="fulfilled"?oe(t.value,e):typeof t.exit_code=="number"&&e.push(t.exit_code))}function Mn(t){const e=t[0]??"";if(!wn.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])oe(i,n)}return n.length>0?n.some(s=>s!==0):void 0}function bt(t){const e=se(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)?se(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,g=f===!0||(typeof l=="number"?l!==0:f??Mn(e.parts)??Cn(s.text));return{text:s.text,isError:g,...o.length>0?{images:o}:{}}}const En=["# AGENTS.md instructions for ","<recommended_plugins>","<environment_context>","<permissions instructions>","<collaboration_mode>","<skills_instructions>"];function Nn(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 Tt(t){try{return JSON.parse(t)}catch{return null}}function F(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 ut(t,e){const n=t==null?void 0:t.content;return Array.isArray(n)?n.filter(s=>F(s)&&s.type===e&&typeof s.text=="string").map(s=>s.text).join(`
|
|
13
|
+
`).trim():""}const vn=/^data:(image\/(?:png|jpeg|gif|webp));base64,(.+)$/is,Bn=/^data:(audio\/(?:wav|x-wav|mpeg|mp4|webm|ogg));base64,(.+)$/is;function ie(t){if(typeof t!="string")return null;const e=vn.exec(t);return!(e!=null&&e[1])||!e[2]?null:{type:"image",source:{type:"base64",media_type:e[1].toLowerCase(),data:e[2]}}}function re(t){if(typeof t!="string")return null;const e=Bn.exec(t);return!(e!=null&&e[1])||!e[2]?null:{type:"audio",source:{type:"base64",media_type:e[1].toLowerCase(),data:e[2]}}}function Pn(t){return Array.isArray(t.images)?t.images.map(ie).filter(e=>e!==null):[]}function Rn(t){return Array.isArray(t.audio)?t.audio.map(re).filter(e=>e!==null):[]}function ae(t){return Array.isArray(t.content)?t.content.filter(e=>F(e)&&e.type==="input_image").map(e=>ie(e.image_url)).filter(e=>e!==null):[]}function le(t){return Array.isArray(t.content)?t.content.filter(e=>F(e)&&e.type==="input_audio").map(e=>re(e.audio_url)).filter(e=>e!==null):[]}function ce(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 Fn(t){var l,f;const e=ut(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 Un(t){if(typeof t!="string")return"";const e=t.trim();return/^gAAAAA[A-Za-z0-9_-]+$/.test(e)?"":e}function Ct(t){const e=t.trim();return!e||En.some(n=>e.startsWith(n))?"":e}function $n(t){if(!F(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 Dn(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 On(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 ue(t){if(typeof t!="string"||!t.trim())return{};try{const e=JSON.parse(t);return F(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 de(...t){return t.find(e=>typeof e=="string")}function jn(t){return t.startsWith("exec-")}function Wn(t){var o;if(!F(t))return{text:Y(t),isError:!1};if("Err"in t)return{text:Y(t.Err),isError:!0};const e=F(t.Ok)?t.Ok:null;if(!e)return{text:Y(t),isError:!1};const n=bt({...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 Ln(t,e,n){return{id:t?`${t}@${e}`:Nn("codex-turn"),userMessage:null,contentBlocks:[],thinking:[],assistantText:[],toolCalls:[],subAgentActivity:[],timestamp:e,durationMs:null,tokenUsage:null,model:n}}function pe(t){return t.type==="event_msg"&&F(t.payload)&&t.payload.type==="user_message"&&typeof t.payload.message=="string"?Ct(t.payload.message):t.type==="response_item"&&F(t.payload)&&t.payload.type==="message"&&t.payload.role==="user"?Ct(ut(t.payload,"input_text")):""}function qn(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 pe(t)!==""||ae(e).length>0||le(e).length>0}return!0}function fe(t){let e="",n="",s="",o="",i="",l,f="",g="",b="",T="",y=0,_=!1,d=null,N="/root",E="";for(const w of t){if(!F(w.payload))continue;if(w.type==="session_meta"){if(e||(e=typeof w.payload.id=="string"?w.payload.id:""),n||(n=typeof w.payload.cli_version=="string"?w.payload.cli_version:""),o||(o=typeof w.payload.cwd=="string"?w.payload.cwd:""),!l&&F(w.payload.branchedFrom)){const j=typeof w.payload.branchedFrom.sessionId=="string"?w.payload.branchedFrom.sessionId:"";j&&(l={sessionId:j,turnIndex:typeof w.payload.branchedFrom.turnIndex=="number"?w.payload.branchedFrom.turnIndex:null})}const P=F(w.payload.source)?w.payload.source:null;if(P&&F(P.subagent)){_=!0;const j=F(P.subagent.thread_spawn)?P.subagent.thread_spawn:null;j&&typeof j.agent_path=="string"&&(N=j.agent_path)}typeof w.payload.forked_from_id=="string"&&w.payload.forked_from_id&&(d=w.payload.forked_from_id);const $=F(w.payload.git)?w.payload.git:null;s||(s=$&&typeof $.branch=="string"?$.branch:"")}w.type==="turn_context"&&(i||(i=typeof w.payload.model=="string"?w.payload.model:""),o||(o=typeof w.payload.cwd=="string"?w.payload.cwd:""));const v=pe(w);v&&v!==E&&(f||(f=v),g=v,E=v,y++,b||(b=w.timestamp??""),T=w.timestamp??T)}return T===""&&(T=b),{sessionId:e,version:n,gitBranch:s,cwd:o,model:i,slug:"",name:"",branchedFrom:l,firstUserMessage:f,lastUserMessage:g,timestamp:b,lastTimestamp:T,turnCount:y,isSubagent:_,parentSessionId:d,agentPath:N}}function zn(t){for(const e of t.split(`
|
|
16
|
+
`)){const n=e.trim();if(n)return K(Tt(n))}return!1}function Jn(t){return K(t[0]??null)}function Qn(t){const e=t.map(Tt).filter(K);return fe(e)}function me(t,e){const n=fe(t.filter(K)),s=[],o=new Map,i=new Map,l=new Map,f=new Map,g=new Map,b=new Map,T=new Map,y=new Map;function _(m,p,a,k={}){const u=g.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:k.status??"running"};p.subAgentActivity.push(x);const I=p.contentBlocks[p.contentBlocks.length-1];(I==null?void 0:I.kind)==="sub_agent"?I.messages.push(x):p.contentBlocks.push({kind:"sub_agent",messages:[x],timestamp:a}),C={message:x,turn:p},y.set(m,C)}const h=C.message;if(u&&(h.parentToolUseId=u.parentToolCallId||h.parentToolUseId,h.agentName=u.nickname??(u.agentPath?Z(u.agentPath):h.agentName),h.subagentType=u.agentType,h.model=u.model,h.prompt=u.message||h.prompt),k.text&&!h.text.includes(k.text)&&(h.text.push(k.text),h.content=h.text.join(`
|
|
17
|
+
|
|
18
|
+
`)),k.status){const x=new Set(["completed","failed","interrupted"]);if(k.status==="running"&&h.status&&x.has(h.status)||(h.status=k.status),x.has(k.status)&&h.timestamp&&a){const I=new Date(h.timestamp).getTime(),M=new Date(a).getTime();Number.isFinite(I)&&Number.isFinite(M)&&M>=I&&(h.durationMs=M-I)}}return h}let d=null,N=null,E=n.model||null,w="",v=null,P=!1;const $=[];let j=0,W=null,D=null;function S(m){const p=s.length,a=On(s,m,w);return s.length>p&&D!==null&&$.push(D),D=null,a}function r(m,p,a){const k=Ln(m,p,a);return D=W??j,W=null,P||(k.isFragment=!0),v&&(k.compactionSummary=v,v=null),k}function c(m,p,a,k,u){const C=i.get(p);if(C){C.input={...C.input,...a},C.result=k,C.isError=k==="failed";return}const h={id:p,name:"WebSearch",input:a,result:k,isError:k==="failed",timestamp:u};i.set(p,h),G(m,h,u)}for(let m=0;m<t.length;m++){const p=t[m];if(!K(p))continue;j=m;const a=F(p.payload)?p.payload:void 0,k=p.timestamp??"";if(p.type==="compacted"){d=S(d),v="Conversation compacted",w=k;continue}if(p.type!=="world_state"){if(p.type==="turn_context"){d=S(d),W=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,w=k,P=!0;continue}if(p.type==="event_msg"&&(a==null?void 0:a.type)==="user_message"&&typeof a.message=="string"){d&&(d.assistantText.length>0||d.toolCalls.length>0||d.thinking.length>0)&&(d=S(d)),P=!0,d??(d=r(N,k,E));const u=(Array.isArray(a.local_images)?a.local_images:[]).filter(h=>typeof h=="string"&&h.length>0),C=(Array.isArray(a.local_audio)?a.local_audio:[]).filter(h=>typeof h=="string"&&h.length>0);d.userMessage=ce(a.message,Pn(a),Rn(a),u,C),d.isFragment=!1,d.timestamp=d.timestamp||k,w=k;continue}if(!(!d&&!qn(p,a))){if(d??(d=r(N,k,E)),!d.model&&E&&(d.model=E),d.timestamp||(d.timestamp=k),k&&(w=k),p.type==="event_msg"&&(a==null?void 0:a.type)==="token_count"){const u=F(a.info)?a.info:null,C=u?$n(u.last_token_usage):null;C&&(d.tokenUsage=Q(d.tokenUsage,C));continue}if(p.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),F(a.action)&&(u.action=a.action),c(d,a.call_id,u,"completed",k);continue}if(p.type==="event_msg"&&(a==null?void 0:a.type)==="mcp_tool_call_end"&&typeof a.call_id=="string"&&F(a.invocation)){const u=a.invocation,C=typeof u.server=="string"?u.server:"mcp",h=typeof u.tool=="string"?u.tool:"tool",x=F(u.arguments)?u.arguments:{},I=Wn(a.result),M=o.get(a.call_id);M?(M.result=I.text,M.isError=I.isError,I.images&&(M.resultImages=I.images),o.delete(a.call_id)):jn(a.call_id)||G(d,{id:a.call_id,name:`mcp__${C}__${h}`,input:x,result:I.text,isError:I.isError,...I.images?{resultImages:I.images}:{},timestamp:k},k);continue}if(p.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:"",h=typeof a.kind=="string"?a.kind:"started",x=C?f.get(C):void 0,I=b.get(a.agent_path),M=g.get(u)??(I?g.get(I):void 0);if(h!=="started"&&!M&&!x)continue;if(I&&I!==u&&!y.has(u)){const R=y.get(I);R&&(R.message.agentId=u,y.delete(I),y.set(u,R)),g.delete(I)}const U={agentId:u,nickname:(M==null?void 0:M.nickname)??Z(a.agent_path)??(x==null?void 0:x.taskName)??null,agentPath:a.agent_path,message:(M==null?void 0:M.message)??(x==null?void 0:x.message)??"",model:(M==null?void 0:M.model)??(x==null?void 0:x.model)??null,agentType:(M==null?void 0:M.agentType)??(x==null?void 0:x.agentType)??null,timestamp:(M==null?void 0:M.timestamp)??(k||(x==null?void 0:x.timestamp)||""),parentToolCallId:(M==null?void 0:M.parentToolCallId)??C};g.set(u,U),b.set(a.agent_path,u),C&&(h==="started"||x)&&T.set(C,u),_(u,d,k,{status:h==="interrupted"?"interrupted":"running"});continue}if(!(p.type!=="response_item"||!a)){if(a.type==="reasoning"){const u=Array.isArray(a.summary)?a.summary.filter(C=>typeof C=="string").join(`
|
|
19
|
+
`):"";Dn(d,u.trim(),k);continue}if(a.type==="message"&&a.role==="assistant"){Yt(d,ut(a,"output_text"),k);continue}if(a.type==="message"&&a.role==="user"&&d.userMessage===null){const u=Ct(ut(a,"input_text")),C=ae(a),h=le(a);(u||C.length>0||h.length>0)&&(d.userMessage=ce(u,C,h),d.isFragment=!1,P=!0);continue}if(a.type==="web_search_call"&&typeof a.id=="string"){const u={};F(a.action)&&(u.action=a.action);const C=typeof a.status=="string"?a.status:"completed";c(d,a.id,u,C,k);continue}if(a.type==="tool_search_call"){const u=de(a.call_id,a.id)??"";if(u){const C={id:u,name:"ToolSearch",input:F(a.arguments)?a.arguments:{},result:null,isError:!1,timestamp:k};o.set(u,C),G(d,C,k)}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:[],h=C.filter(F).map(M=>de(M.name)??"").filter(Boolean),x=h.length>0?h.length:C.length,I=`Found ${x} tool${x===1?"":"s"}`;u.result=h.length>0?`${I}: ${h.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,h=Fn(a);if(h.messageType==="NEW_TASK")continue;const x=b.get(u),I=u.startsWith(`${n.agentPath}/`)&&(C===null||C===n.agentPath);if(!x&&!I)continue;const M=x??u;x||(g.set(M,{agentId:M,nickname:Z(u),agentPath:u,message:"",model:null,agentType:null,timestamp:k,parentToolCallId:""}),b.set(u,M));let U;h.messageType==="FINAL_ANSWER"?U="completed":h.messageType==="ERROR"||h.messageType==="FAILED"?U="failed":h.messageType==="INTERRUPTED"?U="interrupted":h.messageType==="MESSAGE"&&(U="running"),_(M,d,k,{status:U,text:h.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),h=ue(a.arguments);let x=C,I=h;C==="exec_command"?x="Bash":C==="update_plan"?(x="TodoWrite",I=An(h)):xn(C)&&(x="AskUserQuestion",I=In(h)),C==="spawn_agent"&&f.set(a.call_id,{callId:a.call_id,message:Un(h.message),taskName:typeof h.task_name=="string"?h.task_name:null,model:typeof h.model=="string"?h.model:null,agentType:typeof h.agent_type=="string"?h.agent_type:null,timestamp:k});const M={id:a.call_id,name:x,input:I,result:null,isError:!1,timestamp:k,...C==="request_user_input_async"?{asyncQuestion:!0}:{}};o.set(M.id,M),G(d,M,k);continue}if(a.type==="function_call_output"&&typeof a.call_id=="string"){const u=o.get(a.call_id);if(!u)continue;const C=bt(a.output),h=C.text;if(u.result=h,u.isError=C.isError,C.images&&(u.resultImages=C.images),o.delete(a.call_id),u.name==="spawn_agent"&&h)try{const x=JSON.parse(h),I=typeof x.agent_id=="string"?x.agent_id:T.get(u.id)??"",M=typeof x.task_name=="string"?x.task_name:null,U=typeof x.nickname=="string"?x.nickname:M?Z(M):null;if(I){const B=f.get(u.id),R=g.get(I),H={agentId:I,nickname:U??(R==null?void 0:R.nickname)??(B==null?void 0:B.taskName)??null,agentPath:M??(R==null?void 0:R.agentPath)??null,message:(R==null?void 0:R.message)??(B==null?void 0:B.message)??"",model:(R==null?void 0:R.model)??(B==null?void 0:B.model)??null,agentType:(R==null?void 0:R.agentType)??(B==null?void 0:B.agentType)??null,timestamp:(R==null?void 0:R.timestamp)??(B==null?void 0:B.timestamp)??k,parentToolCallId:(R==null?void 0:R.parentToolCallId)??u.id};g.set(I,H),T.set(u.id,I),H.agentPath&&b.set(H.agentPath,I),_(I,d,k,{status:"running"})}}catch{}if(u.name==="wait_agent"&&h&&d)try{const x=JSON.parse(h),I=F(x.status)?x.status:{};for(const[M,U]of Object.entries(I)){const B=F(U)?U:{},R=typeof B.completed=="string"?B.completed:"",H=typeof B.failed=="string"?B.failed:typeof B.error=="string"?B.error:"",Be=typeof B.interrupted=="string"?B.interrupted:"",ws=R?"completed":H?"failed":Be?"interrupted":typeof B.status=="string"?B.status:"running";g.has(M)||g.set(M,{agentId:M,nickname:null,agentPath:null,message:"",model:null,agentType:null,timestamp:k,parentToolCallId:""}),_(M,d,k,{status:ws,text:R||H||Be||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:"",h=a.call_id,x=C?_n(u,C,h,k,n.cwd):[];if(u!=="apply_patch"){const I={id:h,name:u==="exec_command"?"Bash":u,input:ue(C),result:null,isError:!1,timestamp:k};o.set(I.id,I),G(d,I,k)}for(const I of x)o.set(I.id,I),G(d,I,k);x.length>0&&l.set(h,{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:h,images:x}=bt(a.output),I=l.get(u);if(I){const U=I.direct&&h?new Set(I.calls.map(B=>B.id)):kn(C,h,I.calls);for(const B of I.calls){const R=o.get(B.id);R&&(R.result=C,R.isError=U.has(R.id),o.delete(R.id))}l.delete(u)}const M=o.get(u);M&&(M.result=C,M.isError=h,x&&(M.resultImages=x),o.delete(u));continue}}}}}return S(d),{turnStartIndices:$,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 ge(t,e){const n=t.split(`
|
|
20
|
+
`).map(i=>i.trim()).filter(Boolean).map(Tt).filter(K),{turnStartIndices:s,...o}=me(n,e);return o}function Vn(t,e){const n=t.rawMessages.map(s=>JSON.stringify(s)).join(`
|
|
21
|
+
`);return ge(n?`${n}
|
|
22
|
+
${e}`:e)}const Kn=new Set(["FINAL_ANSWER","ERROR","FAILED","INTERRUPTED"]);function Gn(t){const e=t.content;return Array.isArray(e)?e.filter(n=>F(n)&&n.type==="input_text"&&typeof n.text=="string").map(n=>n.text).join(`
|
|
23
|
+
`):""}function dt(t){if(typeof t!="string")return null;try{const e=JSON.parse(t);return F(e)?e:null}catch{return null}}function Hn(t){var g,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=F(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 _=y.agent_thread_id,d=typeof y.kind=="string"?y.kind:"started",N=typeof y.event_id=="string"?y.event_id:"",E=s.get(y.agent_path),w=e.has(_)||n.has(_)||E!==void 0||o.has(N);if(d!=="started"&&!w)continue;E&&E!==_&&(e.has(E)&&(f(_,e.get(E)??""),e.delete(E)),n.has(E)&&n.add(_)),s.set(y.agent_path,_),d==="interrupted"?(n.add(_),e.delete(_)):f(_,o.get(N)??"");continue}if(T.type==="response_item"){if(y.type==="function_call"&&typeof y.call_id=="string"){const _=V(typeof y.name=="string"?y.name:"");if(_==="spawn_agent"){const d=dt(y.arguments);o.set(y.call_id,typeof(d==null?void 0:d.task_name)=="string"?d.task_name:"")}else if(_==="wait_agent")i.add(y.call_id);else if(_==="interrupt_agent"){const d=dt(y.arguments),N=[d==null?void 0:d.agent_id,...Array.isArray(d==null?void 0:d.agent_ids)?d.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 _=y.call_id;if(o.has(_)){const d=dt(y.output),N=typeof(d==null?void 0:d.agent_id)=="string"?d.agent_id:"";if(N){f(N,o.get(_)??"");const E=typeof(d==null?void 0:d.task_name)=="string"?d.task_name:"";E&&!s.has(E)&&s.set(E,N)}}else if(i.has(_)){const d=dt(y.output),N=F(d==null?void 0:d.status)?d.status:{};for(const[E,w]of Object.entries(N)){const v=F(w)?w:{},P=typeof v.status=="string"?v.status:"";(typeof v.completed=="string"||typeof v.failed=="string"||typeof v.error=="string"||typeof v.interrupted=="string"||P==="completed"||P==="failed"||P==="interrupted")&&(n.add(E),e.delete(E))}}else if(l.has(_))for(const d of l.get(_)??[])n.add(d),e.delete(d);continue}if(y.type==="agent_message"&&typeof y.author=="string"){const d=((b=(g=Gn(y).match(/^Message Type:\s*([^\r\n]+)/))==null?void 0:g[1])==null?void 0:b.trim().toUpperCase())??"";if(!Kn.has(d))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 Xn(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=Hn(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 Zn(t,e,n){const s=F(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 Yn(t){return me(t,{skipStats:!0}).turnStartIndices}const ts=/^(?: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 he(t){return typeof t.agentId!="string"||t.agentId.length===0}function ye(t){return!O(t)||typeof t.type!="string"||!O(t.data)?!1:t.type==="abort"||t.type==="binary_asset"||t.type==="user.message"||ts.test(t.type)}function _e(t){try{const e=JSON.parse(t);return ye(e)?e:null}catch{return null}}function es(t){return t.split(`
|
|
24
|
+
`).map(e=>e.trim()).filter(Boolean).map(_e).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 ke(t){const e=J(t,"copilot-turn"),n=A(t.data.turnId);return n?`${n}@${e}`:e}function xt(t,e){if(!O(t))return;const n=A(t.cwd),s=A(t.branch);n&&(e.cwd=n),s&&(e.gitBranch=s)}function be(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(!he(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))),xt(s.context,e),e.model=A(s.selectedModel)||e.model;continue}if(n.type==="session.resume"){xt(s.context,e),e.model=A(s.selectedModel)||e.model;continue}if(n.type==="session.context_changed"){xt(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 ns(t){for(const e of t.split(`
|
|
25
|
+
`)){const n=e.trim();if(n)try{const s=JSON.parse(n);if(ye(s))return!0}catch{}}return!1}function ss(t){var e;return ys((e=t[0])==null?void 0:e.type)}function os(t){const e=t.map(n=>_e(n.trim())).filter(n=>n!==null);return be(e)}function It(t){if(typeof t=="string")return t;if(t===void 0)return"";try{return JSON.stringify(t)}catch{return String(t)}}function Te(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 is(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 rs(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 Ce(t,e){if(!Array.isArray(t))return[];const n=[],s=new Set;for(const o of t){const i=rs(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 as(t,e){const n=A(t.content),s=Ce(t.attachments,e);return s.length===0?n:[...s,...n?[{type:"text",text:n}]:[]]}function ls(t,e){return O(t.result)?Ce([...Array.isArray(t.result.contents)?t.result.contents:[],...Array.isArray(t.result.binaryResultsForLlm)?t.result.binaryResultsForLlm:[]],e):[]}function At(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 cs(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=At(n.usage,!0);s&&(e=Q(e,s))}return e}function us(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 ds(t){return Array.isArray(t)?t.map(us).filter(e=>e!==null):[]}function ps(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:ds(t.options??t.choices),...s===void 0?{}:{multiSelect:s}}}function fs(t){const n=(Array.isArray(t.questions)?t.questions:[t]).map(ps).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 pt(t,e){const n=O(e)?e:e===void 0?{}:{value:e};return t==="AskUserQuestion"?fs(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 ms(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?"":It(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?It(n.structuredContent):It(n)}function xe(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 ft(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 Ie(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,pt(f,o.arguments),e))}return s}function Ae(t,e,n,s){t.name=e,t.input=pt(e,n),t.timestamp=s||t.timestamp}function Se(t,e,n){t.result=ms(e);const s=ls(e,n);s.length>0&&(t.resultImages=s),t.isError=e.success===!1||e.error!==void 0&&e.error!==null}function we(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 gs(t){return t.userMessage!==null||t.assistantText.length>0||t.thinking.length>0||t.toolCalls.length>0||t.subAgentActivity.length>0}function Me(t,e){const n=es(t),s=be(n),o=is(n),i=[],l=new Map,f=new Map,g=new Map,b=new WeakMap,T=new WeakMap;let y=null,_=null,d,N=!1,E=!1,w=null;function v(S,r){r&&b.set(S,r)}function P(S){return y||(y=we(ke(S),tt(S),null,_,d,!0)),y}function $(){y&&(gs(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,p=A(m.toolCallId),a=p?((C=l.get(p))==null?void 0:C.turn)??y:y;if(!a)return null;const k=A(m.executionMode),u={agentId:r,...p?{parentToolUseId:p}:{},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:k==="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 W(S){if(he(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 p=A(c.error,c.message);return p&&!r.text.includes(p)&&r.text.push(p),!0}if(S.type==="user.message")return r.prompt||(r.prompt=A(c.content)||void 0),!0;if(S.type==="assistant.reasoning"){const p=A(c.content);return p&&!r.thinking.includes(p)&&r.thinking.push(p),!0}if(S.type==="assistant.message"){r.model=A(c.model)||r.model;const p=A(c.reasoningText);p&&!r.thinking.includes(p)&&r.thinking.push(p);const a=Te(c.content);a&&!r.text.includes(a)&&r.text.push(a);for(const k of Ie(c.toolRequests,m,u=>g.has(u)))r.toolCalls.push(k),g.set(k.id,{call:k,message:r});return!0}if(S.type==="assistant.usage"){r.model=A(c.model)||r.model;const p=At(c);return p&&(r.tokenUsage=Q(r.tokenUsage,p)),!0}if(S.type==="tool.execution_start"){const p=A(c.toolCallId)||J(S,"copilot-agent-tool"),a=A(c.toolName)||"Tool",k=et(a),u=g.get(p);if(u)Ae(u.call,k,c.arguments,m);else{const C=nt(p,k,pt(k,c.arguments),m);r.toolCalls.push(C),g.set(p,{call:C,message:r})}return!0}if(S.type==="tool.execution_complete"){const p=A(c.toolCallId)||J(S,"copilot-agent-tool");let a=g.get(p);if(!a){const k=A(c.toolName)||"Tool",u=et(k),C=nt(p,u,{},m);r.toolCalls.push(C),a={call:C,message:r}}return Se(a.call,c,o),g.delete(p),!0}return!0}for(const S of n){if(W(S))continue;const{data:r}=S,c=tt(S);if(S.type==="session.start"||S.type==="session.resume"){_=A(r.selectedModel)||_,d=A(r.reasoningEffort)||d;continue}if(S.type==="session.auto_mode_resolved"){_=A(r.chosenModel)||_,y&&(y.model=_);continue}if(S.type==="session.model_change"){_=A(r.newModel)||_;const m=r.reasoningEffort;typeof m=="string"&&(d=m),y&&(y.model=_,d&&(y.effort=d));continue}if(S.type==="session.shutdown"){_=A(r.currentModel)||_,y&&!y.model&&(y.model=_),w=cs(r)??w;const m=z(r.totalApiDurationMs);y&&!E&&m&&T.set(y,m);continue}if(S.type==="user.message"){$(),y=we(ke(S),c,as(r,o),_,d,!1),v(y,c);continue}if(S.type==="assistant.turn_start"){_=A(r.model)||_;const m=P(S);m.model=_,d&&(m.effort=d),v(m,c);continue}if(S.type==="assistant.reasoning"){const m=P(S);xe(m,A(r.content),c,A(r.reasoningId)||J(S,"copilot-thinking")),v(m,c);continue}if(S.type==="assistant.message"){_=A(r.model)||_;const m=P(S);m.model=_,d&&(m.effort=d),xe(m,A(r.reasoningText),c,J(S,"copilot-thinking")),Yt(m,Te(r.content),c);for(const p of Ie(r.toolRequests,c,a=>l.has(a)))ft(m,p,c),l.set(p.id,{call:p,turn:m});v(m,c);continue}if(S.type==="assistant.usage"){_=A(r.model)||_,d=A(r.reasoningEffort)||d;const m=At(r),p=z(r.duration);m&&(N=!0),p&&(E=!0);const a=P(S);a.model=_,d&&(a.effort=d),m&&(a.tokenUsage=Q(a.tokenUsage,m)),p&&T.set(a,(T.get(a)??0)+p),v(a,c);continue}if(S.type==="tool.execution_start"){_=A(r.model)||_;const m=P(S);m.model=_;const p=A(r.toolCallId)||J(S,"copilot-tool"),a=A(r.toolName)||"Tool",k=et(a),u=l.get(p);if(u)Ae(u.call,k,r.arguments,c);else{const C=nt(p,k,pt(k,r.arguments),c);ft(m,C,c),l.set(p,{call:C,turn:m})}v(m,c);continue}if(S.type==="tool.execution_complete"){_=A(r.model)||_;const m=A(r.toolCallId)||J(S,"copilot-tool");let p=l.get(m);if(!p){const a=P(S),k=A(r.toolName)||"Tool",u=et(k),C=nt(m,u,{},c);ft(a,C,c),p={call:C,turn:a}}Se(p.call,r,o),l.delete(m),v(p.turn,c);continue}if(S.type==="session.error"){const m=P(S),a={errorType:A(r.errorType)||"unknown"};typeof r.statusCode=="number"&&(a.statusCode=r.statusCode),typeof r.errorCode=="string"&&(a.errorCode=r.errorCode),ft(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($(),!N&&w&&i.length===1&&(i[0].tokenUsage=Q(i[0].tokenUsage,w)),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 p=T.get(S)??0;p&&(S.durationMs=p)}}const D=e!=null&&e.skipStats?it(i.length):rt(i);return!(e!=null&&e.skipStats)&&!N&&w&&i.length>1&&(D.totalInputTokens=w.input_tokens,D.totalOutputTokens=w.output_tokens,D.totalCacheCreationTokens=w.cache_creation_input_tokens??0,D.totalCacheReadTokens=w.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 hs(t,e){const n=t.rawMessages.map(s=>JSON.stringify(s)).join(`
|
|
28
|
+
`);return Me(n?`${n}
|
|
29
|
+
${e}`:e)}function ys(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 _s(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(g=>typeof g=="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 g=t[f];if(typeof g.agentId=="string"&&g.agentId)continue;if(g.type==="user.message")break;if(g.type==="abort")return{status:"completed"};if(g.type!=="assistant.message")continue;const b=O(g.data)?g.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 ks(){throw new Error("Copilot sessions branch through the CLI's fork API, not by copying the transcript")}function bs(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 Ee=mt[mt.length-1],Ts={kind:"codex",descriptor:ht("codex"),detectsText:zn,detectsRecords:Jn,parse:ge,append:Vn,metadataFromLines:Qn,status:Xn,brandBranch:Zn,turnBoundaries:Yn},Cs={kind:"copilot",descriptor:ht("copilot"),detectsText:ns,detectsRecords:ss,parse:Me,append:hs,metadataFromLines:os,status:_s,brandBranch:ks,turnBoundaries:bs},xs={kind:"claude",descriptor:ht("claude"),detectsText:Kt,detectsRecords:Kt,parse:an,append:ln,metadataFromLines:rn,status:mn,brandBranch:gn,turnBoundaries:hn},St=Object.freeze({claude:xs,codex:Ts,copilot:Cs});function Ne(t){for(const e of mt)if(t(St[e]))return St[e];return St[Ee]}function ve(t){return Ne(e=>e.detectsText(t))}function Is(t){return Ne(e=>e.detectsRecords(t))}function As(t,e){return ve(t).parse(t,e)}function Ss(t,e){const n=Is(t.rawMessages);return(n.kind===Ee?ve(e):n).append(t,e)}self.onmessage=t=>{const e=t.data;try{let n;e.type==="parse"?n=As(e.text):n=Ss(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)})}}})();
|