diff --git a/ui/dist/assets/PdfPreview-Cu9GJIeU.js b/ui/dist/assets/PdfPreview-D6YVdKN_.js similarity index 99% rename from ui/dist/assets/PdfPreview-Cu9GJIeU.js rename to ui/dist/assets/PdfPreview-D6YVdKN_.js index 2c80adb6..00dd4583 100644 --- a/ui/dist/assets/PdfPreview-Cu9GJIeU.js +++ b/ui/dist/assets/PdfPreview-D6YVdKN_.js @@ -1,4 +1,4 @@ -var a1=Object.defineProperty;var cw=h=>{throw TypeError(h)};var o1=(h,e,t)=>e in h?a1(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var L=(h,e,t)=>o1(h,typeof e!="symbol"?e+"":e,t),By=(h,e,t)=>e.has(h)||cw("Cannot "+t);var a=(h,e,t)=>(By(h,e,"read from private field"),t?t.call(h):e.get(h)),b=(h,e,t)=>e.has(h)?cw("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),g=(h,e,t,n)=>(By(h,e,"write to private field"),n?n.call(h,t):e.set(h,t),t),y=(h,e,t)=>(By(h,e,"access private method"),t);var Zt=(h,e,t,n)=>({set _(i){g(h,e,i,t)},get _(){return a(h,e,n)}});import{g as vy,c as LA,r as gi,M as l1,j as fe,f as ku,I as Bu,a as c1,i as hw,P as h1,b as dw,S as d1,d as u1,C as f1,e as p1,h as g1}from"./index-FxOZ5k4D.js";const m1=()=>"Find in document",v1=()=>"在文档中查找",y1=()=>"جست‌وجو در سند",b1=()=>"البحث في المستند",E1=()=>"Buscar en el documento",w1=()=>"दस्तावेज़ में खोजें",A1=()=>"문서에서 찾기",x1=()=>"文書内を検索",S1=()=>"Znajdź w dokumencie",uw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?v1():t==="fa"?y1():t==="ar"?b1():t==="es"?E1():t==="hi"?w1():t==="ko"?A1():t==="ja"?x1():t==="pl"?S1():m1()}),T1=()=>"Fit to width",C1=()=>"适应宽度",P1=()=>"متناسب با عرض",I1=()=>"ملاءمة العرض",R1=()=>"Ajustar al ancho",O1=()=>"चौड़ाई में फ़िट करें",M1=()=>"너비에 맞추기",D1=()=>"幅に合わせる",L1=()=>"Dopasuj do szerokości",fw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?C1():t==="fa"?P1():t==="ar"?I1():t==="es"?R1():t==="hi"?O1():t==="ko"?M1():t==="ja"?D1():t==="pl"?L1():T1()}),N1=()=>"Next match",F1=()=>"下一个匹配项",k1=()=>"مورد بعدی",B1=()=>"التطابق التالي",j1=()=>"Coincidencia siguiente",U1=()=>"अगला मिलान",$1=()=>"다음 일치 항목",H1=()=>"次の一致",V1=()=>"Następne dopasowanie",pw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?F1():t==="fa"?k1():t==="ar"?B1():t==="es"?j1():t==="hi"?U1():t==="ko"?$1():t==="ja"?H1():t==="pl"?V1():N1()}),z1=()=>"Previous match",W1=()=>"上一个匹配项",G1=()=>"مورد قبلی",_1=()=>"التطابق السابق",X1=()=>"Coincidencia anterior",Y1=()=>"पिछला मिलान",K1=()=>"이전 일치 항목",J1=()=>"前の一致",Z1=()=>"Poprzednie dopasowanie",gw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?W1():t==="fa"?G1():t==="ar"?_1():t==="es"?X1():t==="hi"?Y1():t==="ko"?K1():t==="ja"?J1():t==="pl"?Z1():z1()});/** +var a1=Object.defineProperty;var cw=h=>{throw TypeError(h)};var o1=(h,e,t)=>e in h?a1(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var L=(h,e,t)=>o1(h,typeof e!="symbol"?e+"":e,t),By=(h,e,t)=>e.has(h)||cw("Cannot "+t);var a=(h,e,t)=>(By(h,e,"read from private field"),t?t.call(h):e.get(h)),b=(h,e,t)=>e.has(h)?cw("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(h):e.set(h,t),g=(h,e,t,n)=>(By(h,e,"write to private field"),n?n.call(h,t):e.set(h,t),t),y=(h,e,t)=>(By(h,e,"access private method"),t);var Zt=(h,e,t,n)=>({set _(i){g(h,e,i,t)},get _(){return a(h,e,n)}});import{g as vy,c as LA,r as gi,M as l1,j as fe,f as ku,I as Bu,a as c1,i as hw,P as h1,b as dw,S as d1,d as u1,C as f1,e as p1,h as g1}from"./index-nILKpF0z.js";const m1=()=>"Find in document",v1=()=>"在文档中查找",y1=()=>"جست‌وجو در سند",b1=()=>"البحث في المستند",E1=()=>"Buscar en el documento",w1=()=>"दस्तावेज़ में खोजें",A1=()=>"문서에서 찾기",x1=()=>"文書内を検索",S1=()=>"Znajdź w dokumencie",uw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?v1():t==="fa"?y1():t==="ar"?b1():t==="es"?E1():t==="hi"?w1():t==="ko"?A1():t==="ja"?x1():t==="pl"?S1():m1()}),T1=()=>"Fit to width",C1=()=>"适应宽度",P1=()=>"متناسب با عرض",I1=()=>"ملاءمة العرض",R1=()=>"Ajustar al ancho",O1=()=>"चौड़ाई में फ़िट करें",M1=()=>"너비에 맞추기",D1=()=>"幅に合わせる",L1=()=>"Dopasuj do szerokości",fw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?C1():t==="fa"?P1():t==="ar"?I1():t==="es"?R1():t==="hi"?O1():t==="ko"?M1():t==="ja"?D1():t==="pl"?L1():T1()}),N1=()=>"Next match",F1=()=>"下一个匹配项",k1=()=>"مورد بعدی",B1=()=>"التطابق التالي",j1=()=>"Coincidencia siguiente",U1=()=>"अगला मिलान",$1=()=>"다음 일치 항목",H1=()=>"次の一致",V1=()=>"Następne dopasowanie",pw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?F1():t==="fa"?k1():t==="ar"?B1():t==="es"?j1():t==="hi"?U1():t==="ko"?$1():t==="ja"?H1():t==="pl"?V1():N1()}),z1=()=>"Previous match",W1=()=>"上一个匹配项",G1=()=>"مورد قبلی",_1=()=>"التطابق السابق",X1=()=>"Coincidencia anterior",Y1=()=>"पिछला मिलान",K1=()=>"이전 일치 항목",J1=()=>"前の一致",Z1=()=>"Poprzednie dopasowanie",gw=((h={},e={})=>{const t=e.locale??vy();return t==="zh-CN"?W1():t==="fa"?G1():t==="ar"?_1():t==="es"?X1():t==="hi"?Y1():t==="ko"?K1():t==="ja"?J1():t==="pl"?Z1():z1()});/** * @license lucide-react v1.23.0 - ISC * * This source code is licensed under the ISC license. diff --git a/ui/dist/assets/index-FxOZ5k4D.js b/ui/dist/assets/index-nILKpF0z.js similarity index 99% rename from ui/dist/assets/index-FxOZ5k4D.js rename to ui/dist/assets/index-nILKpF0z.js index 69075ca5..9ba4740f 100644 --- a/ui/dist/assets/index-FxOZ5k4D.js +++ b/ui/dist/assets/index-nILKpF0z.js @@ -1,4 +1,4 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreview-Cu9GJIeU.js","assets/PdfPreview-DNMWzGmA.css"])))=>i.map(i=>d[i]); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreview-D6YVdKN_.js","assets/PdfPreview-DNMWzGmA.css"])))=>i.map(i=>d[i]); var zV=Object.defineProperty;var Kz=e=>{throw TypeError(e)};var EV=(e,r,t)=>r in e?zV(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var jo=(e,r,t)=>EV(e,typeof r!="symbol"?r+"":r,t),ww=(e,r,t)=>r.has(e)||Kz("Cannot "+t);var le=(e,r,t)=>(ww(e,r,"read from private field"),t?t.call(e):r.get(e)),ht=(e,r,t)=>r.has(e)?Kz("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t),Ue=(e,r,t,n)=>(ww(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t),Qt=(e,r,t)=>(ww(e,r,"access private method"),t);var ym=(e,r,t,n)=>({set _(s){Ue(e,r,s,t)},get _(){return le(e,r,n)}});(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))n(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const a of o.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&n(a)}).observe(document,{childList:!0,subtree:!0});function t(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function n(s){if(s.ep)return;s.ep=!0;const o=t(s);fetch(s.href,o)}})();function _0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var kw={exports:{}},xm={};/** * @license React * react-jsx-runtime.production.js @@ -1186,11 +1186,11 @@ ${r.trim()} `)}function UU(e){const r=e==null?void 0:e.replace(/[)'\"]+$/,"");return!r||r==="-"||/^\d+$/.test(r)||/[$`]/.test(r)||mLn(r)?null:r}function GU(e){const r=UU(e);if(!r)return null;const t=jf(r);return r.includes("/")||r.startsWith(".")||/\.[A-Za-z0-9][A-Za-z0-9_-]*$/.test(t)||/^(?:Dockerfile|Makefile|README|LICENSE|NOTICE|CHANGELOG)$/i.test(t)?r:null}function WU(e){var s,o;const r=Cp(e);let t=0;for(;["do","then","else","if","while","until"].includes(r[t]);)t++;for(;/^[A-Za-z_][A-Za-z0-9_]*=/.test(r[t]??"");)t++;if(r[t]==="command")for(t++;(s=r[t])!=null&&s.startsWith("-");)t++;if(r[t]==="env")for(t++;(o=r[t])!=null&&o.startsWith("-")||/^[A-Za-z_][A-Za-z0-9_]*=/.test(r[t]??"");)t++;const n=r[t];return n?{name:n.split("/").pop()??n,args:r.slice(t+1)}:null}function Nes(e){const{name:r,args:t}=e;if(r==="sed"){let s=0,o=!1;for(;s!o.startsWith("-")&&o.includes(":"));if(!r)return null;const t=r.indexOf(":"),n=r.slice(0,t),s=r.slice(t+1);return n&&GU(s)?{ref:n,path:s}:null}function Tes(e){const r=e.match(/\b(?:rg|grep)\b(?:\s+-[^\s]+)*\s+(?:"([^"]+)"|'([^']+)'|([^\s]+))/);return(r==null?void 0:r[1])??(r==null?void 0:r[2])??(r==null?void 0:r[3])??null}function KM(e,r){if(/[$`~]/.test(e)||/[$`~]/.test(r))return null;const t=r.startsWith("/")||!r.startsWith("/")&&e.startsWith("/"),n=r.startsWith("/")?[]:e.split("/").filter(Boolean);for(const o of r.split("/"))if(!(!o||o===".")){if(o===".."){n.length>0&&n[n.length-1]!==".."?n.pop():t||n.push(o);continue}n.push(o)}return`${t?"/":""}${n.join("/")}`||(t?"/":null)}function Res(e,r,t,n){if(e.startsWith("/"))return e;let s=n??"";for(let o=0;o!_.startsWith("-"));if(!i)return null;const c=KM(s,i);if(!c)return null;s=c}return s?KM(s,e):e}const Ac="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",Mes=new RegExp(`\\bchat_(${Ac})\\b`,"gi"),Xf=`(?:${Ac}|[0-9a-f]{8})`;function Oh(e){const r=[];let t="",n="",s=null,o=!1;const a=()=>{(t.trim()||n.trim())&&r.push({raw:t.trim(),code:n.trim()}),t="",n=""},i=_=>{let d=1,f=null,p=!1;for(let m=_;m{let d=!1;for(let f=_;fbLn(t.raw,r))}function mi(e,r){return Ix(e,r).length>0}function Oes(e){if(!e)return[];const r=new Set;for(const t of e.slice(0,FU).matchAll(Mes))if(r.add(t[0].toLowerCase()),r.size>=P_)break;return[...r]}function ij(e,r){if(!e)return[];const t=new Set,n=e.slice(0,FU),s=r==="runs"?[new RegExp(`/runs/(${Ac})`,"gi"),new RegExp(`\\brun(?:_|\\s+)id:\\s*(${Ac})`,"gi"),new RegExp(`^\\s*RUN\\s+(${Ac})\\b`,"gim"),new RegExp(`={3,}\\s*(${Ac})\\s*={3,}`,"gi")]:[new RegExp(`/experiments/(${Ac})`,"gi"),new RegExp(`^\\s*id:\\s*(${Ac})`,"gim"),new RegExp(`={3,}\\s*(${Ac})\\s*={3,}`,"gi")];for(const a of s)for(const i of n.matchAll(a))if(t.add(i[1]),t.size>=P_)return[...t];const o=new RegExp(`^\\s*(${Ac})(?:\\s|$)`,"gim");for(const a of n.matchAll(o))if(t.add(a[1]),t.size>=P_)break;return[...t]}function KU(e,r){let t=0;return r.map(n=>{const s=e.indexOf(n.raw,t),o=s===-1?e.indexOf(n.raw):s;return t=Math.max(t,o+n.raw.length),{invocation:n,offset:Math.max(0,o)}})}function VU(e,r,t,n){const s=new RegExp(`(?:^|[\\s;])(?:export\\s+)?${r}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s;]+))`,"gi");let o="";for(const a of e.matchAll(s)){if((a.index??0)>=t)break;o=a[1]??a[2]??a[3]??""}return[...o.matchAll(new RegExp(n,"gi"))].map(a=>a[0])}function QU(e,r,t,n){const s=new RegExp(`\\bfor\\s+${r}\\s+in\\s+([\\s\\S]*?)(?:;|\\n)\\s*do\\b`,"gi");let o="";for(const a of e.matchAll(s)){const i=a.index??0;if(i>=t)break;const c=i+a[0].length;c<=t&&/\bdone\b/.test(e.slice(c,t))||(o=a[1])}return/\$\(|`/.test(o)?[]:[...o.matchAll(new RegExp(n,"gi"))].map(a=>a[0])}function $es(e,r,t=[],n=[]){const s=Ix(e,"logs"),o=new Set;if(s.length===0){if(!mi(e,"logs"))return[];const i=t.length>0?[]:ij(r,"runs");for(const c of t.length>0?t:i.length>0?i:n)if(o.add(c),o.size>=P_)break;return Mh([...o])}let a=!1;for(const{invocation:i,offset:c}of KU(e,s)){const _=Cg(i.raw);if((_==null?void 0:_[0])!=="logs")continue;const d=_.slice(1);let f=null;for(let v=0;v0?[]:ij(r,"runs"),c=t.length>0?t:i.length>0?i:n;for(const _ of c)if(o.add(_),o.size>=P_)break}return Mh([...o])}function uh(e,r,t=[],n=[]){const s=Ix(e,"exp\\s+(?:status|desc)");if(s.length===0)return[];const o=new Set;let a=!1;for(const{invocation:i,offset:c}of KU(e,s)){const _=Cg(i.raw),d=(_==null?void 0:_[0])==="exp"&&(_[1]==="status"||_[1]==="desc")?_[2]:null;let f=!1;d&&new RegExp(`^${Xf}$`,"i").test(d)&&(o.add(d),f=!0);const p=d?/^\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?$/.exec(d):null;if(p){const m=p[1],x=VU(e,m,c,Xf);if(x.length>0){for(const v of x)o.add(v);f=!0}const k=QU(e,m,c,Xf);for(const v of k)o.add(v);k.length>0&&(f=!0)}f||(a=!0)}if(o.size===0||a){const i=t.length>0?[]:ij(r,"experiments"),c=t.length>0?t:i.length>0?i:n;for(const _ of c)if(o.add(_),o.size>=P_)break}return Mh([...o])}const VM=new WeakMap;function ud(e){const r=z(),t=VM.get(e);if((t==null?void 0:t.locale)===r)return t.activity;const n=Les(e);return VM.set(e,{locale:r,activity:n}),n}function Les(e){var w,b,y,S,E,C;const r=e.tool??"tool",t=((w=e.state)==null?void 0:w.input)??{},n=t.arguments,s=n&&typeof n=="object"&&!Array.isArray(n)?Object.fromEntries(Object.entries(n)):{},o={...t,...s},a=Eo(o,"command","cmd"),i=jes(o,"commandArgv"),c=((b=e.state)==null?void 0:b.output)||((y=e.state)==null?void 0:y.error),_=Mh(c4(o,"targetIds")),d=Mh(c4(o,"runTargetIds")),f=Mh(c4(o,"experimentTargetIds")),p=Eo(o,"filePath","file_path","notebookPath","notebook_path","path"),m=Eo(o,"description"),x=r.toLowerCase().split(/(?::|\.|__)+/),k=x.at(-1)??r.toLowerCase();if(k==="run"&&x.includes("web")){const A=i4(o,"search_query","q"),N=i4(o,"image_query","q"),R=i4(o,"find","pattern");return A?{kind:"web",label:eE({query:A})}:N?{kind:"web",label:Fge({query:N})}:R?{kind:"web",label:G0e({pattern:R})}:Array.isArray(o.open)?{kind:"web",label:VDe()}:Array.isArray(o.weather)?{kind:"web",label:JRe()}:Array.isArray(o.finance)?{kind:"web",label:MRe()}:Array.isArray(o.sports)?{kind:"web",label:qRe()}:Array.isArray(o.time)?{kind:"web",label:kRe()}:{kind:"web",label:pE()}}switch(new Map([["read_file","read"],["write_file","write"],["edit_file","edit"],["exec","bash"],["exec_command","bash"],["run_command","bash"],["agent","task"],["collabagenttoolcall","subagent"],["compacted","contextcompaction"],["imported","importedchat"],["subagentactivity","subagent"]]).get(k)??k){case"bash":{if(!a&&!(i!=null&&i.length))return{kind:"command",label:lPe()};const A=Ces(a??(i==null?void 0:i.join(" "))??""),N=Oh(A);let R=N.map(W=>W.raw);if(i!=null&&i.length){const W=DA(i);R=W===null?[i]:Oh(qU(W)).map(ae=>ae.raw)}let L=null;for(const W of R)if(L=yLn(W),L)break;const $=R.some(W=>{const ae=Cg(W);return ae!==null&&ae[0]!=="discover"&&ae[0]!=="paper"});if(L&&!$){const W=L.kind==="discover"&&!L.query?xLn(i?DA(i)??A:A,c??"",L.strategy):[],ae=L.kind==="discover"?{keyword:Kme(),embedding:nge(),openalex:m0e(),biorxiv:dge(),pubmed:C0e()}[L.strategy]:null,ie=L.kind==="discover"?L.query?J9({activity:ae??U1(),query:L.query}):W.length===1?J9({activity:ae??U1(),query:W[0]}):W.length>1?Y_e({activity:ae??U1(),count:mr(W.length)}):ae??U1():L.id?Sm({target:Te(L.id)}):vhe();return{kind:L.kind==="paper"?"read":"search",label:ie,litCall:L,queries:W}}if(mi(A,"agent\\s+spawn"))return{kind:"agent",label:rOe(),spawnedSessionIds:Oes(c),litCall:L??void 0};const I=N.map(W=>WU(W.raw)),F=mi(A,"exp\\s+status"),B=mi(A,"exp\\s+desc"),V=Ix(A,"exp\\s+desc").some(W=>(Cg(W.raw)??[]).some(ie=>ie==="--set"||ie.startsWith("--set=")||ie==="--stdin")),K=V?ive():che(),ee=V?Fle():Zpe();if(mi(A,"logs")){const W=$es(A,c,d,_);return{kind:"project",label:W.length===1?Rpe():Hpe(),runIds:W,litCall:L??void 0}}if(mi(A,"exp\\s+run"))return{kind:"project",label:IHe(),litCall:L??void 0};if(mi(A,"exp\\s+wait"))return{kind:"project",label:JGe(),litCall:L??void 0};if(mi(A,"exp\\s+cancel"))return{kind:"project",label:ETe(),litCall:L??void 0};const J=mi(A,"project\\s+view");if(J&&F&&B)return{kind:"project",label:ee,experimentIds:uh(A,c,f,_),litCall:L??void 0};if(J&&B)return{kind:"project",label:K,experimentIds:uh(A,c,f,_),litCall:L??void 0};if(J&&F)return{kind:"project",label:mE(),experimentIds:uh(A,c,f,_),litCall:L??void 0};if(J)return{kind:"project",label:QPe(),litCall:L??void 0};if(F&&B)return{kind:"project",label:ee,experimentIds:uh(A,c,f,_),litCall:L??void 0};if(F)return{kind:"project",label:mE(),experimentIds:uh(A,c,f,_),litCall:L??void 0};if(B)return{kind:"project",label:K,experimentIds:uh(A,c,f,_),litCall:L??void 0};if(mi(A,"runs?"))return{kind:"project",label:GLe(),litCall:L??void 0};if(mi(A,"projects"))return{kind:"project",label:tDe(),litCall:L??void 0};if(mi(A,"compute"))return{kind:"project",label:VTe(),litCall:L??void 0};const P=I.map(Aes).find(W=>W!=null);if(P){const W=a4(P.path);return{kind:W?"skill":"read",label:W?Iw({name:Te(W)}):Sm({target:Te(jf(P.path))}),filePath:P.path,fileRef:P.ref,labelTarget:W?`${W} skill`:jf(P.path)}}const D=I.findIndex(W=>W!=null&&["sed","cat","head","tail"].includes(W.name)),q=D>=0?I[D]:null,U=q?Nes(q):null,G=U?Res(U,N,D,Eo(o,"cwd","workdir")):null;if(U&&G){const W=a4(G);return{kind:W?"skill":"read",label:W?Iw({name:Te(W)}):Sm({target:Te(jf(U))}),filePath:G,labelTarget:W?`${W} skill`:jf(U)}}if(I.some(W=>(W==null?void 0:W.name)==="find"||(W==null?void 0:W.name)==="ls"||(W==null?void 0:W.name)==="rg"&&W.args.includes("--files")))return{kind:"search",label:SE()};const oe=I.findIndex(W=>(W==null?void 0:W.name)==="rg"||(W==null?void 0:W.name)==="grep");if(oe>=0){const W=Tes(N[oe].raw);return{kind:"search",label:W?Bw({pattern:Te(W)}):Pw(),searchPattern:W??void 0}}const ce=I.find(W=>(W==null?void 0:W.name)==="git"),ue=ce==null?void 0:ce.args[0];if(ue==="grep"){const W=ce==null?void 0:ce.args.slice(1).find(ae=>!ae.startsWith("-"));return{kind:"search",label:W?Bw({pattern:Te(W)}):Pw(),searchPattern:W}}if(ue==="status")return{kind:"command",label:dRe()};if(ue==="diff")return{kind:"command",label:mFe()};if(ue==="log")return{kind:"command",label:PPe()};const re=W=>I.some(ae=>!ae||!["cargo","pnpm","npm","yarn"].includes(ae.name)?!1:ae.args[0]===W||ae.args[0]==="run"&&ae.args[1]===W);return re("test")?{kind:"command",label:bPe()}:I.some(W=>(W==null?void 0:W.name)==="tsc")||re("typecheck")?{kind:"command",label:lMe()}:re("lint")?{kind:"command",label:ITe()}:re("build")?{kind:"command",label:cTe()}:{kind:"command",label:Rde({command:Te(A)})}}case"skill":{const A=Eo(o,"skill","name"),N=A?kes(r,A):null;return{kind:"skill",label:A?rde({name:Te(A)}):Wfe(),filePath:N??void 0,labelTarget:N&&A?`${A} skill`:void 0}}case"read":{const A=p?jf(p):null,N=p?a4(p):null;return N?{kind:"skill",label:Iw({name:Te(N)}),filePath:p??void 0,labelTarget:`${N} skill`}:A?{kind:"read",label:Sm({target:Te(A)}),filePath:p??void 0,labelTarget:A}:{kind:"read",label:NPe()}}case"edit":case"write":case"notebookedit":{const A=Ses(o),N=p??(A==null?void 0:A.path)??null,R=N?jf(N):null,L=R?(A==null?void 0:A.type)==="add"?Lue({target:Te(R)}):(A==null?void 0:A.type)==="delete"?f_e({target:Te(R)}):T_e({target:Te(R)}):null;return R?{kind:"edit",label:L??xE(),filePath:N??void 0,labelTarget:R}:{kind:"edit",label:xE()}}case"grep":{const A=Eo(o,"pattern");return{kind:"search",label:A?Bw({pattern:Te(A)}):Pw(),searchPattern:A??void 0}}case"glob":{const A=Eo(o,"pattern");return{kind:"search",label:A?Cfe({pattern:Te(A)}):SE()}}case"websearch":{const A=Eo(o,"query"),N=Eo(o,"url"),R=Eo(o,"pattern");return A?{kind:"web",label:eE({query:A})}:R&&N?{kind:"web",label:a0e({pattern:R})}:N?{kind:"web",label:wde({target:Te(N)})}:{kind:"web",label:m??pE()}}case"webfetch":{const A=Eo(o,"url");return{kind:"web",label:A?Sm({target:Te(A)}):m??Whe()}}case"task":return{kind:"agent",label:m??Hde()};case"subagent":return{kind:"agent",label:Des(o)};case"error":return{kind:"command",label:jGe()};case"importedchat":return{kind:"project",label:mfe()};case"contextcompaction":return{kind:"command",label:((S=e.state)==null?void 0:S.status)==="error"?Cue():((E=e.state)==null?void 0:E.status)==="running"?Z9():iue(),progressLabel:Z9()};default:{const A=m??p??a??((C=e.state)==null?void 0:C.title)??"";return{kind:"command",label:A?`${r}: ${A}`:r}}}}function Des(e){const r=typeof e.nickname=="string"&&e.nickname?e.nickname.replace(/[_-]+/g," "):"",t=r&&r.charAt(0).toUpperCase()+r.slice(1);if(t)return t;switch(typeof e.tool=="string"?e.tool:""){case"spawnAgent":return x1e();case"sendInput":return _1e();case"resumeAgent":return fpe();case"wait":return gve();case"closeAgent":return Yle()}switch(typeof e.kind=="string"?e.kind:""){case"started":return Y1e();case"interacted":return _le();case"interrupted":return F1e()}return T1e()}function cy({activity:e,className:r=""}){const t={size:16,strokeWidth:1.75,className:"tool-kind-icon"};let n=u.jsx(R_,{...t});if(e.litCall)n=u.jsx(AH,{source:e.litCall.source,size:16,className:"tool-kind-icon"});else switch(e.kind){case"skill":n=u.jsx(kP,{...t});break;case"read":case"project":n=u.jsx(jP,{...t});break;case"search":n=u.jsx(DP,{...t});break;case"edit":n=u.jsx(Hy,{...t});break;case"web":n=u.jsx(wOn,{...t});break;case"agent":n=u.jsx(PP,{...t});break}return u.jsx("span",{className:`flex h-6 shrink-0 items-center ${r}`,children:n})}function l4({items:e,onOpen:r,onSelect:t,targetType:n}){const[s,o]=T.useState(!1),a=T.useRef(null),i=T.useRef(!1);return T.useEffect(()=>{var c,_;!s||!i.current||(i.current=!1,(_=(c=a.current)==null?void 0:c.querySelector("button"))==null||_.focus())},[s]),u.jsxs("span",{className:"tool-target-overflow inline",children:[s&&u.jsx("span",{className:"tool-target-reveal",ref:a,children:e.map((c,_)=>u.jsxs("span",{children:[_>0&&", ",r||t?u.jsx("button",{className:"tool-target",...r?$n(d=>r(c.id,d),{stopPropagation:!0}):{onClick:d=>{d.stopPropagation(),t==null||t(c.id)}},children:c.label}):u.jsx("span",{children:c.label})]},c.id))}),s&&", ",u.jsx("button",{className:"tool-target-more","aria-expanded":s,"aria-label":s?tee({target:n}):$ne({count:mr(e.length),target:n}),onClick:c=>{c.preventDefault(),c.stopPropagation(),i.current=!s&&c.detail===0,o(_=>!_)},children:s?My():Ett({count:mr(e.length)})})]})}function cj({activity:e,onOpenFile:r,onOpenRun:t,onOpenSpawnedSession:n,runExperimentName:s,onOpenExperiment:o,experimentName:a}){var i,c,_,d;if(e.searchPattern)return e.label;if(((i=e.litCall)==null?void 0:i.kind)==="paper"&&e.litCall.id)return u.jsxs("a",{className:"tool-target",href:SWn(e.litCall.source,e.litCall.id),target:"_blank",rel:"noopener noreferrer",children:[e.label,u.jsx(wMn,{className:"inline ms-1 opacity-50",size:13,"aria-hidden":"true"})]});if(e.filePath&&e.labelTarget&&r){const f=e.filePath;return u.jsx("span",{className:"tool-target",role:"button",tabIndex:0,...$n(p=>r(f,void 0,void 0,e.fileRef,p),{stopPropagation:!0}),children:e.label})}if((c=e.spawnedSessionIds)!=null&&c.length&&n){const f=e.spawnedSessionIds,p=f.slice(0,3),m=f.slice(p.length).map((x,k)=>({id:x,label:cE({number:mr(p.length+k+1)})}));return u.jsxs(u.Fragment,{children:[e.label," — ",p.map((x,k)=>u.jsxs("span",{children:[k>0&&", ",u.jsx("button",{className:"tool-target",title:IDe(),onClick:v=>{v.preventDefault(),v.stopPropagation(),n(x)},children:cE({number:mr(k+1)})})]},x)),m.length>0&&u.jsxs(u.Fragment,{children:[", ",u.jsx(l4,{items:m,onSelect:n,targetType:gSe()})]})]})}if((_=e.runIds)!=null&&_.length){const f=s?e.runIds.filter(x=>!!s(x)):e.runIds;if(f.length===0)return e.label;const p=f.slice(0,3),m=f.slice(p.length).map(x=>({id:x,label:(s==null?void 0:s(x))||ql()}));return u.jsxs(u.Fragment,{children:[e.label," — ",p.map((x,k)=>u.jsxs("span",{children:[k>0&&", ",t?u.jsx("button",{className:"tool-target",title:Ste({run:Te(x)}),...$n(v=>t(x,v),{stopPropagation:!0}),children:(s==null?void 0:s(x))||ql()}):u.jsx("span",{children:(s==null?void 0:s(x))||ql()})]},x)),m.length>0&&u.jsxs(u.Fragment,{children:[", ",u.jsx(l4,{items:m,onOpen:t,targetType:rQe()})]})]})}if((d=e.experimentIds)!=null&&d.length){const f=a?e.experimentIds.filter(x=>!!a(x)):e.experimentIds;if(f.length===0)return e.label;const p=f.slice(0,3),m=f.slice(p.length).map(x=>({id:x,label:(a==null?void 0:a(x))||ql()}));return u.jsxs(u.Fragment,{children:[e.label," — ",p.map((x,k)=>u.jsxs("span",{children:[k>0&&", ",o?u.jsx("button",{className:"tool-target",title:Xee({name:(a==null?void 0:a(x))||Te(x)}),...$n(v=>o(x,v),{stopPropagation:!0}),children:(a==null?void 0:a(x))||ql()}):u.jsx("span",{children:(a==null?void 0:a(x))||ql()})]},x)),m.length>0&&u.jsxs(u.Fragment,{children:[", ",u.jsx(l4,{items:m,onOpen:o,targetType:c8e()})]})]})}return e.label}function TC(e){const r=e.progressLabel??{skill:fde(),read:rpe(),search:t1e(),edit:F_e(),project:cme(),web:Tle(),agent:r_e(),command:XL()}[e.kind];return{...e,label:r}}function XU(e,r){const t=ud({id:"permission-preview",type:"tool",tool:e,state:{status:"running",input:r}});return{skill:Lfe(),read:Zde(),search:Dme(),edit:tS(),project:wpe(),web:xle(),agent:Wue(),command:vme()}[t.kind]}function Ies(e){return e==null?!0:typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length===0}const Pes=250;function Bes(e,r){const[t,n]=T.useState(e),s=T.useRef(Date.now()),o=T.useRef(e);return T.useEffect(()=>{if(o.current=e,(e==null?void 0:e.label)===(t==null?void 0:t.label)||r&&e!=null&&t!=null)return;if(e==null||t==null){s.current=Date.now(),n(e);return}const a=Pes-(Date.now()-s.current);if(a<=0){s.current=Date.now(),n(e);return}const i=window.setTimeout(()=>{s.current=Date.now(),n(o.current)},a);return()=>window.clearTimeout(i)},[e,t,r]),e!=null&&e.label===(t==null?void 0:t.label)?e:t}const Fes=160;function YU(e){const[r,t]=T.useState(!1);return T.useEffect(()=>{if(!e){t(!1);return}const n=window.setTimeout(()=>t(!0),Fes);return()=>window.clearTimeout(n)},[e]),e&&r}function Hes(e){const r=["skill","read","search","edit","project","web","command","agent"];for(const t of r){const n=e.find(s=>s.kind===t);if(n)return n}return e[0]??{kind:"command",label:oD()}}function qes(e,r){var t,n;return((t=e.state)==null?void 0:t.status)!=="completed"?null:JSON.stringify([r.kind,r.label,r.filePath??null,r.fileRef??null,((n=r.litCall)==null?void 0:n.kind)==="paper"?r.litCall.id??null:null,r.runIds??null,r.experimentIds??null,r.spawnedSessionIds??null,r.queries??null])}function Ues(e){const r=[];let t=null;for(const n of e){const s=ud(n),o=qes(n,s),a=r[r.length-1];o&&a&&t===o?a.count++:r.push({part:n,activity:s,count:1}),t=o}return r}function RC({part:e,busy:r,recovering:t,onRecover:n,usageLimited:s=!1,temporaryApiError:o=!1}){var k,v;const a=(k=e.state)==null?void 0:k.input,i=(a==null?void 0:a.nextRetryAt)??null,[c,_]=T.useState(Date.now());if(T.useEffect(()=>{if(typeof i!="number"||(_(Date.now()),i<=Date.now()))return;const w=window.setInterval(()=>{const b=Date.now();_(b),b>=i&&window.clearInterval(w)},1e3);return()=>window.clearInterval(w)},[i]),e.id==="turn-retry"){const w=pWn(a??{},c);return u.jsxs("div",{className:"turn-retry-row flex items-center gap-2 py-1 px-1 text-sm text-subtext",children:[u.jsx(Rt,{}),u.jsx("span",{children:w})]})}const d=EH(a==null?void 0:a.recoveryAction),f=a==null?void 0:a.turnId,p=zH(e)?b9e():s?AQe():o?hGe():BE(),m=o?T$n:s?hOn:LS,x=Dx(((v=e.state)==null?void 0:v.error)||BE());return u.jsxs("details",{className:"turn-usage-limit group/limit text-base text-subtext",children:[u.jsxs("summary",{className:"flex w-fit max-w-full items-center gap-2 cursor-pointer list-none rounded-sm focus-visible:outline-2 focus-visible:outline-text [&::-webkit-details-marker]:hidden",children:[u.jsx(m,{size:18,className:o?"shrink-0 text-subtext":"shrink-0 text-accent-red","aria-hidden":"true"}),u.jsx("span",{children:p}),u.jsx(Ca,{size:16,className:"shrink-0 text-text transition-transform duration-120 ease-standard group-open/limit:rotate-90 motion-reduce:transition-none","aria-hidden":"true"})]}),u.jsx("pre",{className:"mt-2 rounded-md bg-surface p-2 text-sm font-mono whitespace-pre-wrap wrap-anywhere",children:x}),!s&&n&&f&&(d==="retry"||d==="continue")&&u.jsx(Ee,{type:"button",size:"small",className:"mt-2",disabled:r||t,onClick:()=>n(f,d),children:t?aXe():d==="retry"?rs():n7e()})]})}function QM({part:e,activity:r,repeatCount:t=1,onOpenFile:n,onOpenRun:s,onOpenSpawnedSession:o,runExperimentName:a,onOpenExperiment:i,experimentName:c}){const _=e.state,d=(_==null?void 0:_.status)==="error",f=Dx((_==null?void 0:_.error)||(_==null?void 0:_.output)||""),p=d&&!!f,[m,x]=T.useState(!1),k=`tool-error-${e.id.replace(/[^A-Za-z0-9_-]/g,"-")}`;if(e.tool==="error")return u.jsx(RC,{part:e,busy:!1,recovering:!1,usageLimited:E5(e)});const v=u.jsxs(u.Fragment,{children:[d&&u.jsxs("span",{className:"sr-only",children:[nS()," "]}),d?u.jsx("span",{className:"flex h-6 shrink-0 items-center text-accent-red",children:u.jsx(EP,{size:16,strokeWidth:1.75,className:"tool-kind-icon","aria-hidden":"true"})}):u.jsx(cy,{activity:r,className:"text-muted"}),u.jsxs("span",{className:`${PU} ${d?"text-accent-red":"text-subtext"}`,children:[u.jsx(cj,{activity:r,onOpenFile:n,onOpenRun:s,onOpenSpawnedSession:o,runExperimentName:a,onOpenExperiment:i,experimentName:c}),t>1&&u.jsxs("span",{className:"tool-repeat-count ms-1 text-muted font-normal",title:xee({count:mr(t)}),children:["×",t]})]})]});return p?u.jsxs("div",{className:"tool-row tool-row-error flex flex-col min-w-0",children:[u.jsxs("div",{className:"flex items-start gap-2 w-fit max-w-full py-[3px] px-1 min-w-0 rounded-sm",children:[v,u.jsx("button",{type:"button",className:"tool-row-detail-toggle inline-flex h-6 shrink-0 items-center justify-center p-0.5 rounded-sm cursor-pointer hover:bg-surface","aria-expanded":m,"aria-controls":k,"aria-label":m?_ee({activity:r.label}):Sne({activity:r.label}),onClick:()=>x(w=>!w),children:u.jsx(Ca,{size:16,className:`text-accent-red transition-transform duration-120 ease-standard ${m?"rotate-90":""}`})})]}),m&&u.jsx("div",{className:"tool-detail mt-1 me-0 mb-1 ms-6",id:k,children:u.jsx("div",{className:NC,children:f.slice(0,2e4)})})]}):u.jsx("div",{className:"tool-row flex items-start gap-2 min-w-0 py-[3px] px-1",children:v})}function Ges({parts:e,pendingTail:r,onOpenFile:t,onOpenRun:n,onOpenSpawnedSession:s,runExperimentName:o,onOpenExperiment:a,experimentName:i}){var N,R,L,$;const[c,_]=T.useState(!1),[d,f]=T.useState(!1),p=()=>{f(!0),_(I=>!I)},m=Ues(e),x=m.map(({activity:I})=>I),k=r?m.at(-1):void 0,v=k==null?void 0:k.part,w=k==null?void 0:k.activity,b=((N=v==null?void 0:v.state)==null?void 0:N.status)!=="error"?(w&&TC(w))??null:null,y=!!v&&((R=v.state)==null?void 0:R.status)==="running"&&!(b!=null&&b.progressLabel)&&(Ies((L=v.state)==null?void 0:L.input)||(b==null?void 0:b.kind)==="command"&&!Eo((($=v.state)==null?void 0:$.input)??{},"command","cmd")),S=Bes(b,y),E=YU(S!=null),C=S??Hes(x),A=S?S.label:oD();return e.length===1?S?u.jsx("div",{className:"tool-group my-3.5 mx-0",children:u.jsxs("div",{className:"tool-row flex items-start gap-2 min-w-0 py-[3px] px-1 text-base leading-6 text-subtext",children:[u.jsx(cy,{activity:S,className:E?"tool-running-shimmer-icon":"text-muted"}),u.jsx("span",{className:`${E?"tool-running-shimmer":""} min-w-0 line-clamp-2 break-words`,title:A,children:u.jsx(cj,{activity:S,onOpenFile:t,onOpenRun:n,onOpenSpawnedSession:s,runExperimentName:o,onOpenExperiment:a,experimentName:i})})]})}):u.jsx("div",{className:"tool-group my-3.5 mx-0",children:u.jsx(QM,{part:e[0],activity:m[0].activity,onOpenFile:t,onOpenRun:n,onOpenSpawnedSession:s,runExperimentName:o,onOpenExperiment:a,experimentName:i})}):u.jsxs("div",{className:"tool-group my-3.5 mx-0",children:[u.jsxs("div",{className:"tool-group-summary flex items-start gap-2 w-fit max-w-full py-[3px] px-1 text-base leading-6 text-subtext text-start",children:[u.jsx(cy,{activity:C,className:E?"tool-running-shimmer-icon":"text-muted"}),S?u.jsx("span",{className:`tool-group-label min-w-0 line-clamp-2 break-words ${E?"tool-running-shimmer":""}`,title:A,children:u.jsx(cj,{activity:S,onOpenFile:t,onOpenRun:n,onOpenSpawnedSession:s,runExperimentName:o,onOpenExperiment:a,experimentName:i})}):u.jsx("button",{type:"button",className:"tool-group-label min-w-0 whitespace-normal break-words cursor-pointer text-start",onClick:p,"aria-expanded":c,children:A}),u.jsx("button",{type:"button",className:"tool-group-chevron-button inline-flex h-6 shrink-0 items-center justify-center p-px cursor-pointer rounded-sm",onClick:p,"aria-expanded":c,"aria-label":c?zCe():Z7e(),children:u.jsx(Ca,{size:16,className:`tool-chevron text-muted transition-[transform,color] duration-120 ease-standard [&.open]:rotate-90 ${c?"open":""}`})})]}),u.jsx("div",{className:`tool-group-disclosure ${c?"open":""}`,"aria-hidden":!c,inert:!c,children:u.jsx("div",{className:"tool-group-disclosure-inner",children:u.jsx("div",{className:"tool-group-rows flex flex-col gap-px mt-0.5 me-0 mb-1 ms-6",children:d&&m.map(({part:I,count:F,activity:B})=>u.jsx(QM,{part:I,repeatCount:F,activity:B,onOpenFile:t,onOpenRun:n,onOpenSpawnedSession:s,runExperimentName:o,onOpenExperiment:a,experimentName:i},I.id))})})})]})}function Wes({part:e,onRespond:r,onOpenFile:t,onOpenPlan:n}){var d,f;const s=e.prompt,[o,a]=T.useState([]),i=!r,c=p=>r==null?void 0:r({promptId:e.id,...p});if(s.resolved){if(s.kind==="permission")return null;if(s.kind==="plan"){const x=s.approved===!0?{label:hIe(),icon:fo,iconClass:"text-accent-green"}:s.approved===!1&&s.note?{label:UIe(),icon:Hy,iconClass:"text-accent-amber"}:s.approved===!1?{label:jIe(),icon:pn,iconClass:"text-accent-red"}:{label:OIe(),icon:By,iconClass:"text-muted"},k=x.icon;return u.jsxs("details",{className:xes,children:[u.jsxs("summary",{children:[u.jsx("span",{className:"plan-resolved-label text-base font-[375] wrap-anywhere",children:s.synthesized?cD():DE()}),u.jsx(k,{size:17,strokeWidth:1.8,className:`shrink-0 ${x.iconClass}`}),u.jsx("span",{className:"plan-resolved-label prompt-outcome text-base font-[375] wrap-anywhere",children:x.label}),u.jsx(Ca,{size:12,className:"plan-chevron shrink-0 text-muted"})]}),u.jsxs("div",{className:`${UM} ms-6`,children:[u.jsx(Wc,{text:s.plan??"",onOpenFile:t}),s.note&&u.jsx("div",{className:"prompt-collapsed-note mt-1.5 italic",children:s.note})]})]})}const p=(s.answers??[]).join(", ")||s.note||"",m=(s.annotations??[]).map((x,k)=>({id:`${e.id}-annotation-${k}`,text:x.text}));return u.jsxs("div",{className:"flex flex-col items-end gap-1.5",children:[m.length>0&&u.jsx(AC,{annotations:m,variant:"sent"}),u.jsxs("details",{className:yes,children:[u.jsxs("summary",{children:[u.jsx("span",{className:"prompt-collapsed-title font-[375] wrap-anywhere",children:s.header||s.question||xKe()}),u.jsx("span",{className:`prompt-outcome font-[375] text-subtext wrap-anywhere [&.approved]:text-accent-green [&.chosen]:text-accent-green [&.approved::before]:content-['✓_'] [&.chosen::before]:content-['✓_'] [&.revised]:text-accent-amber [&.rejected]:text-accent-amber ${p?"chosen":""}`,children:p||LVe()})]}),u.jsxs("div",{className:UM,children:[s.header&&s.question&&u.jsx("div",{className:"prompt-q text-base font-semibold leading-normal text-text",children:s.question}),(s.options??[]).length>0&&u.jsx("ul",{className:"prompt-collapsed-options mt-1.5 mx-0 mb-0 ps-4.5 [&_.sel]:text-text [&_.sel]:font-medium",children:(s.options??[]).map(x=>{var k;return u.jsx("li",{className:(k=s.answers)!=null&&k.includes(x.label)?"sel":"",children:x.label},x.label)})}),s.note&&s.note!==p&&u.jsx("div",{className:"prompt-collapsed-note mt-1.5 italic",children:s.note})]})]})]})}if(s.kind==="plan"){const p=!!n;return u.jsxs("div",{className:`prompt-card my-2 mx-0 py-3 px-3.5 border border-border border-s-[3px] border-s-border rounded-sm bg-accent-blue-subtle flex flex-col gap-[9px] [&.plan]:border-s-accent-blue [&.permission]:border-s-accent-amber [&.question]:border-s-accent-purple [&.readonly]:opacity-60 plan ${i?"readonly":""}`,children:[u.jsx("div",{className:"prompt-head text-base font-semibold text-text",children:s.synthesized?rKe():DE()}),u.jsx("div",{className:`prompt-plan text-base leading-[1.6] text-text max-h-85 overflow-y-auto [&.clamped]:max-h-[9.5em] [&.clamped]:overflow-hidden [&.clamped]:relative [&.clamped::after]:content-[''] [&.clamped::after]:absolute [&.clamped::after]:inset-x-0 [&.clamped::after]:bottom-0 [&.clamped::after]:top-auto [&.clamped::after]:h-8.5 [&.clamped::after]:bg-[linear-gradient(to_bottom,_transparent,_var(--accent-blue-subtle))] [&.clamped::after]:pointer-events-none ${p?"clamped":""}`,children:u.jsx(Wc,{text:s.plan??"",onOpenFile:t})}),p&&u.jsx("button",{className:"prompt-plan-open self-start border-0 bg-transparent text-accent-blue text-sm p-0 cursor-pointer [&:hover]:underline",...$n(m=>n(s.plan??"",e.id,m)),children:qGe()}),!i&&!p&&u.jsxs("div",{className:aj,children:[u.jsx(Ee,{size:"small",variant:"primary",onClick:()=>c({approve:!0,resumeMode:"auto"}),children:uNe()}),u.jsx(Ee,{size:"small",onClick:()=>c({approve:!0,resumeMode:"bypassPermissions"}),children:yNe()}),u.jsx(Ee,{size:"small",onClick:()=>c({approve:!1}),children:oBe()})]})]})}if(s.kind==="permission"){const p=s.toolInput??{},m=Eo(p,"command","cmd","filePath","file_path","path")||"",x=typeof((d=s.toolInput)==null?void 0:d.reason)=="string"&&s.toolInput.reason||"",k=Eo(p,"description")||"",v=s.header||x||k||XU(s.tool,p),w=`permission-heading-${e.id}`;return u.jsxs("div",{className:`prompt-card permission my-3 w-full max-w-2xl overflow-hidden rounded-md border border-border bg-background shadow-hairline [&.readonly]:opacity-60 ${i?"readonly":""}`,role:"group","aria-labelledby":w,children:[u.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 pt-3 pb-0",children:[u.jsx("span",{className:"flex size-7 shrink-0 items-center justify-center rounded-md bg-accent-amber-subtle text-accent-amber",children:u.jsx(LS,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),u.jsx("span",{id:w,className:"text-base font-semibold text-text",children:aAe()})]}),u.jsxs("div",{className:"flex flex-col gap-3 px-3.5 py-3",children:[u.jsx("div",{className:"prompt-sub text-base font-normal leading-normal text-text wrap-anywhere",children:v}),m&&u.jsx("code",{className:"prompt-command block max-h-36 overflow-auto whitespace-pre-wrap wrap-anywhere rounded-md border border-border-variant bg-surface px-3 py-2 font-mono text-sm leading-relaxed text-text",children:m}),!i&&((f=s.nativeChoices)!=null&&f.length)?u.jsx("div",{className:"prompt-actions flex flex-wrap items-center justify-end gap-2 pt-0.5",children:s.nativeChoices.map(b=>u.jsx(Ee,{size:"small",onClick:()=>c({answers:[b.id],approve:b.kind.startsWith("allow")}),children:b.label},b.id))}):!i&&u.jsxs("div",{className:"prompt-actions flex items-center justify-end gap-2 pt-0.5",children:[u.jsx(Ee,{size:"small",variant:"ghost",onClick:()=>c({approve:!1}),children:TOe()}),u.jsx(Ee,{size:"small",variant:"primary",onClick:()=>c({approve:!0}),children:XNe()})]})]})]})}const _=p=>a(m=>s.multiSelect?m.includes(p)?m.filter(x=>x!==p):[...m,p]:[p]);return u.jsxs("div",{className:`prompt-card my-2 mx-0 py-3 px-3.5 border border-border border-s-[3px] border-s-border rounded-sm bg-accent-purple-subtle flex flex-col gap-[9px] [&.plan]:border-s-accent-blue [&.permission]:border-s-accent-amber [&.question]:border-s-accent-purple [&.readonly]:opacity-60 question ${i?"readonly":""}`,children:[s.header&&u.jsx("div",{className:wes,children:s.header}),s.question&&u.jsx("div",{className:"prompt-q text-base font-semibold leading-normal text-text",children:s.question}),u.jsx("div",{className:"prompt-options flex flex-col gap-1.5",children:(s.options??[]).map(p=>{const m=o.includes(p.label);return u.jsxs("button",{className:`prompt-option flex flex-col items-start gap-0.5 w-full py-2 px-[11px] text-start border border-border rounded-sm bg-background text-text cursor-pointer transition-[border-color,background] duration-80 ease-standard [&:hover:not(:disabled)]:border-border-strong [&:hover:not(:disabled)]:bg-surface [&.sel]:border-primary [&.sel]:bg-primary-subtle [&:disabled]:cursor-default ${m?"sel":""}`,disabled:i,onClick:()=>i?void 0:s.multiSelect?_(p.label):c({answers:[p.label]}),children:[u.jsx("span",{className:"prompt-option-label block text-sm font-medium",children:p.label}),p.description&&u.jsx("span",{className:"prompt-option-desc block text-sm font-normal leading-[1.45] text-subtext",children:p.description})]},p.label)})}),s.multiSelect&&!i&&u.jsx("div",{className:aj,children:u.jsx(Ee,{size:"small",variant:"primary",disabled:o.length===0,onClick:()=>c({answers:o}),children:sGe()})})]})}function Kes(e,r){return e.role==="user"?!0:e.parts.some(t=>up(t,r))}function Ves(e){const r=e.text??"",t=r.startsWith("data:")?r:vAn(r),n=r.startsWith("data:")?"":r.includes("__")?r.slice(r.indexOf("__")+2):r,s=e.name||n||"attachment",o=r.startsWith("data:application/pdf")||/\.pdf$/i.test(s)||/\.pdf$/i.test(r);return{src:t,isPdf:o,name:s}}async function MC(e){try{if(!navigator.clipboard)throw new Error(dD());await navigator.clipboard.writeText(e),Xt(ed(),"success")}catch(r){Xt(r instanceof Error?r.message:String(r),"error")}}function Qes(e,r){const t=URL.createObjectURL(new Blob([r],{type:"text/markdown;charset=utf-8"})),n=document.createElement("a");n.href=t,n.download=e,document.body.append(n),n.click(),n.remove(),window.setTimeout(()=>URL.revokeObjectURL(t),1e3)}function Xes({text:e,createdAt:r,count:t,index:n,prevId:s,nextId:o,onSelect:a,pagerDisabled:i,onEdit:c,editDisabled:_}){const d=t>1,f=new Date(r),p=()=>MC(e);return u.jsxs("div",{className:`fork-controls flex items-center gap-0.5 transition-opacity duration-80 ease-standard ${d?"opacity-100":"opacity-0 group-hover/turn:opacity-100 group-focus-within/turn:opacity-100"}`,children:[d&&u.jsxs(u.Fragment,{children:[u.jsx(kt,{size:"small",title:EE(),"aria-label":EE(),disabled:i||!s,onClick:()=>s&&a(s),children:u.jsx(AS,{size:14})}),u.jsxs("span",{className:"fork-count text-xs text-subtext tabular-nums select-none",children:[n+1,"/",t]}),u.jsx(kt,{size:"small",title:zE(),"aria-label":zE(),disabled:i||!o,onClick:()=>o&&a(o),children:u.jsx(Ca,{size:14})})]}),u.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover/turn:opacity-100 group-focus-within/turn:opacity-100 transition-opacity duration-80 ease-standard",children:[u.jsx("time",{dateTime:f.toISOString(),className:"text-xs text-subtext tabular-nums me-2",children:f.toLocaleTimeString(z(),{hour:"numeric",minute:"2-digit"})}),u.jsx(kt,{size:"small","aria-label":_S(),disabled:!e,onClick:p,children:u.jsx(xd,{size:13})})]}),u.jsx(kt,{size:"small",title:yE(),"aria-label":yE(),disabled:_,onClick:c,children:u.jsx(Hy,{size:13})})]})}const Yes=T.memo(function({message:r,activePermissionId:t,pendingTailToolId:n,onOpenFile:s,onOpenRun:o,onOpenSpawnedSession:a,runExperimentName:i,onOpenExperiment:c,experimentName:_,onRespond:d,onOpenPlan:f,onOpenSubagent:p,busy:m=!1,recoveringTurnId:x,onRecover:k,skills:v,predictTextTail:w=!1,forkCount:b,forkIndex:y=0,forkPrevId:S,forkNextId:E,forkDisabled:C,branchDisabled:A,onFork:N,onSelectFork:R}){var P,D,q;fu();const[L,$]=T.useState(null),I=Jes(r);if(I)return u.jsx(ets,{part:I});if(r.role==="user"){const U=r.parts.filter(W=>W.type==="text").map(W=>W.text??"").join(` `),G=W=>!!(v!=null&&v.some(ae=>ae.name===zC(W))),oe=r.parts.filter(W=>W.type==="image"&&W.text).map(Ves),ce=oe.filter(W=>!W.isPdf),ue=oe.filter(W=>W.isPdf),re=r.parts.filter(W=>W.type==="annotation"&&W.text).map(W=>({id:W.id,text:W.text??""}));if(L!==null){const W=()=>{const ae=L.trim();!ae||C||($(null),N(r.id,ae))};return u.jsx("div",{className:"msg-user-group ms-auto self-end flex w-full max-w-[88%] flex-col items-end gap-1.5",children:u.jsxs("div",{className:"msg-user-edit w-full bg-panel rounded-[16px] py-2.5 px-[15px] flex flex-col gap-2",children:[u.jsx("textarea",{dir:"auto",className:"w-full bg-transparent text-base text-text resize-none outline-none field-sizing-content min-h-16","aria-label":o$e(),value:L,autoFocus:!0,onChange:ae=>$(ae.target.value),onKeyDown:ae=>{if(ae.nativeEvent.isComposing||ae.nativeEvent.keyCode===229){ae.stopPropagation();return}ae.key==="Escape"?(ae.preventDefault(),$(null)):ae.key==="Enter"&&!ae.shiftKey&&(ae.preventDefault(),W())}}),u.jsxs("div",{className:`${aj} justify-end`,children:[u.jsx(Ee,{size:"small",onClick:()=>$(null),children:vTe()}),u.jsx(Ee,{size:"small",variant:"primary",onClick:W,disabled:C||!L.trim(),children:i3()})]})]})})}return u.jsxs("div",{className:"msg-user-group group/turn ms-auto self-end flex max-w-[88%] flex-col items-end gap-1.5",children:[re.length>0&&u.jsx(AC,{annotations:re,variant:"sent"}),u.jsxs("div",{dir:"auto",className:"msg-user max-w-full bg-panel rounded-[16px] py-2.5 px-[15px] text-base whitespace-pre-wrap wrap-anywhere [&_.skill-chip]:align-baseline",children:[u.jsx(AJn,{text:U,isCommand:G}),ce.length>0&&u.jsx("div",{className:"msg-images flex flex-wrap gap-1.5 mt-2 [&_img]:max-w-55 [&_img]:max-h-40 [&_img]:border [&_img]:border-border-variant [&_img]:rounded-xs [&_img]:block",children:ce.map((W,ae)=>u.jsx("a",{href:W.src,target:"_blank",rel:"noreferrer",children:u.jsx("img",{src:W.src,alt:w6e()})},ae))}),ue.length>0&&u.jsx("div",{className:"msg-files flex flex-wrap gap-1.5 mt-2",children:ue.map((W,ae)=>u.jsxs("a",{className:"msg-file inline-flex items-center gap-1.5 max-w-60 py-1.5 px-2.5 border border-border-variant rounded-sm text-text no-underline [&:hover]:border-text [&_span]:overflow-hidden [&_span]:text-ellipsis [&_span]:whitespace-nowrap",href:W.src,target:"_blank",rel:"noreferrer",children:[u.jsx(By,{size:15}),u.jsx("span",{children:W.name})]},ae))})]}),b!==void 0&&u.jsx(Xes,{text:U,createdAt:r.createdAt,count:b,index:y,prevId:S,nextId:E,onSelect:R,pagerDisabled:A,onEdit:()=>$(U),editDisabled:C})]})}const F=r.parts.find(U=>U.type==="tool"&&E5(U)),B=r.parts.find(M0)??F,V=r.parts.filter(U=>U!==B&&!(F&&E5(U))),K=lWn(V,B),ee=K.lengthvoid MC(J),children:u.jsx(xd,{size:13})})})]})});function Zes({message:e,parts:r,options:t}){const n=t.predictTextTail??!1,{work:s,answer:o}=jH(r,n),[a,i]=T.useState(!1),[,c]=T.useState(0);if(T.useEffect(()=>{if(!n||e.completedAt!=null||s.length===0)return;const p=window.setInterval(()=>c(m=>m+1),1e3);return()=>window.clearInterval(p)},[n,e.completedAt,s.length]),s.length===0)return u.jsx(u.Fragment,{children:sb(o,t)});const _=e.completedAt??(n?Date.now():null),d=_===null?null:_-e.createdAt,f=d===null?null:d<6e4||d>=36e5?xg(d):$Ze({minutes:mr(Math.floor(d/6e4)),seconds:mr(Math.floor(d/1e3)%60)});return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"turn-work mb-4",children:[u.jsxs("button",{type:"button",className:"flex w-full items-center gap-1.5 border-b border-border/50 pb-2 text-start text-base text-subtext cursor-pointer hover:text-text focus-visible:outline-2 focus-visible:outline-primary","aria-expanded":a,"data-work-toggle":!0,onClick:()=>i(p=>!p),children:[u.jsx("span",{children:f===null?SZe():GZe({duration:f})}),u.jsx(Ca,{size:16,className:`shrink-0 text-muted transition-transform duration-200 ease-standard motion-reduce:transition-none ${a?"rotate-90":""}`})]}),u.jsx("div",{className:`tool-group-disclosure ${a?"open":""}`,"aria-hidden":!a,inert:!a,children:u.jsx("div",{className:"tool-group-disclosure-inner",children:u.jsx("div",{className:"turn-work-content pt-4",children:sb(s,{...t,predictTextTail:!1,pendingTailToolId:null})})})})]}),u.jsx("div",{className:"turn-answer",children:sb(o,t)})]})}function Jes(e){const r=e.parts.length===1?e.parts[0]:void 0;return e.role==="user"&&(r==null?void 0:r.type)==="tool"&&r.tool===VI?r:null}function ets({part:e}){var c;const r=e.state,t=Eo((r==null?void 0:r.input)??{},"command")??"",n=(r==null?void 0:r.status)==="running",s=(r==null?void 0:r.status)==="error",o=typeof((c=r==null?void 0:r.input)==null?void 0:c.exitCode)=="number"?r.input.exitCode:null,a=[r==null?void 0:r.output,r==null?void 0:r.error].filter(Boolean).join(` -`),i=n?XL():s&&o!==null?cCe({code:mr(o)}):null;return u.jsx("div",{className:"msg-shell ms-auto self-end flex w-full max-w-[88%] flex-col items-stretch gap-1.5",children:u.jsxs("div",{dir:"ltr",className:"max-w-full bg-panel rounded-[16px] py-2.5 px-[15px] text-base",children:[u.jsxs("div",{className:"flex items-start gap-2 font-mono text-sm text-text whitespace-pre-wrap wrap-anywhere",children:[u.jsxs("span",{className:"sr-only",children:[tD()," "]}),u.jsx(R_,{size:16,strokeWidth:1.6,className:`mt-0.5 shrink-0 ${s?"text-accent-red":"text-muted"}`,"aria-hidden":"true"}),u.jsx("span",{children:t})]}),a&&u.jsx("div",{className:`${NC} mt-2`,children:a.slice(0,2e4)}),i&&u.jsx("div",{className:`mt-1.5 text-xs ${s?"text-accent-red":"text-muted"}`,children:i})]})})}function sb(e,r){var b,y;const{activePermissionId:t,pendingTailToolId:n,onOpenFile:s,onOpenRun:o,onOpenSpawnedSession:a,runExperimentName:i,onOpenExperiment:c,experimentName:_,onRespond:d,onOpenPlan:f,onOpenSubagent:p,predictTextTail:m=!1}=r,x=e.filter(S=>S.type!=="steer"&&up(S,t)).at(-1),k=[];let v=[];const w=()=>{v.length!==0&&(k.push(u.jsx(Ges,{parts:v,pendingTail:v.some(S=>S.id===n),onOpenFile:s,onOpenRun:o,onOpenSpawnedSession:a,runExperimentName:i,onOpenExperiment:c,experimentName:_},`tg-${v[0].id}`)),v=[])};for(const S of e)if(up(S,t)){if(S.type==="tool"&&S.tool==="api_error"){w(),k.push(u.jsx(RC,{part:S,busy:!1,recovering:!1,temporaryApiError:!0},S.id));continue}if(S.type==="tool"&&(rts(S.tool)||(((b=S.children)==null?void 0:b.length)??0)>0)){w(),k.push(u.jsx(sts,{part:S,pendingTail:m&&((y=S.state)==null?void 0:y.status)==="running"||S.id===n,onOpenSubagent:p},S.id));continue}if(S.type==="tool"){v.push(S);continue}w(),S.type==="text"?k.push(u.jsx(Wc,{text:S.text,onOpenFile:s,onOpenRun:o,predict:m&&S.id===(x==null?void 0:x.id)},S.id)):S.type==="steer"?k.push(u.jsx("div",{dir:"auto",role:"note","aria-label":EWe(),className:"msg-steer my-2 ms-auto w-fit max-w-[88%] bg-panel rounded-[16px] py-2.5 px-[15px] text-base whitespace-pre-wrap wrap-anywhere",children:S.text},S.id)):S.type==="prompt"&&S.prompt&&k.push(u.jsx(Wes,{part:S,onRespond:d,onOpenFile:s,onOpenPlan:f},S.id))}return w(),k}function tts(e){return ud(e).label}function rts(e){const r=(e??"").toLowerCase();return r==="subagent"||r==="task"||r==="agent"}function ZU(e){var t,n;const r=((t=e.state)==null?void 0:t.status)==="completed"?((n=e.state)==null?void 0:n.output)??"":"";return r.startsWith("Async agent launched")?"":r}function ly(e,r){for(const t of e){if(t.id===r)return t;const n=t.children&&ly(t.children,r);if(n)return n}return null}function nts({spawn:e,onOpenFile:r,onOpenRun:t,runExperimentName:n,onOpenExperiment:s,experimentName:o,onOpenSubagent:a}){var x,k,v,w;const i=e.children??[],c=((x=e.state)==null?void 0:x.status)==="running",_=((k=e.state)==null?void 0:k.status)==="error",d=_?Dx(((v=e.state)==null?void 0:v.error)||((w=e.state)==null?void 0:w.output)||""):"",f=sb(i,{onOpenFile:r,onOpenRun:t,runExperimentName:n,onOpenExperiment:s,experimentName:o,onOpenSubagent:a,predictTextTail:c,pendingTailToolId:c?wH(i):null}),m=i.some(b=>b.type==="text"&&!!b.text)?"":ZU(e);return u.jsxs("div",{className:"msg-assistant text-base leading-[1.62] text-text min-w-0",children:[_&&u.jsxs("span",{className:"sr-only",children:[nS()," "]}),d&&u.jsx("div",{className:NC,children:d.slice(0,2e4)}),f.length===0&&!m&&!d?u.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:c?sS():N9e()}):u.jsxs(u.Fragment,{children:[f,m&&u.jsx(Wc,{text:m,onOpenFile:r,onOpenRun:t})]})]})}function sts({part:e,pendingTail:r,onOpenSubagent:t}){var _,d,f,p;const n=((_=e.state)==null?void 0:_.status)==="error",s=Dx(((d=e.state)==null?void 0:d.error)||((f=e.state)==null?void 0:f.output)||""),o=r&&!n?TC(ud(e)):ud(e),a=YU(!!(r&&!n)),i=(((p=e.children)==null?void 0:p.length)??0)===0&&!n&&!ZU(e),c=u.jsxs(u.Fragment,{children:[n&&u.jsxs("span",{className:"sr-only",children:[nS()," "]}),n?u.jsx("span",{className:"flex h-6 shrink-0 items-center text-accent-red",children:u.jsx(EP,{size:16,strokeWidth:1.75,className:"subagent-icon","aria-hidden":"true"})}):u.jsx(cy,{activity:o,className:`subagent-icon ${a?"tool-running-shimmer-icon":"text-muted"}`}),u.jsx("span",{className:`${PU} ${a?"tool-running-shimmer":n?"text-accent-red":"text-subtext"}`,children:o.label})]});return i?u.jsx("div",{className:"subagent-row flex items-start gap-2 w-full my-3.5 mx-0 py-[3px] px-1 text-text text-base text-start rounded-sm",children:c}):u.jsxs("button",{className:"subagent-row flex items-start gap-2 w-full my-3.5 mx-0 py-[3px] px-1 cursor-pointer text-text text-base text-start rounded-sm [&:hover:not(:disabled)]:bg-surface [&:disabled]:cursor-default",title:n&&s?s:GEe(),...$n(m=>t==null?void 0:t(e.id,o.label,m)),disabled:!t,children:[c,u.jsx("span",{className:"subagent-row-chevron flex h-6 shrink-0 items-center text-muted",children:u.jsx(Ca,{size:12})})]})}function ots(e){const r=new Map;let t;for(let s=e.length-1;s>=0;s--)if(e[s].role==="assistant"){t=e[s];break}if(!t)return{messageId:"",states:r};const n=(s,o)=>{var a,i;for(const c of s){const _=`${o}/${c.id}`;c.type==="tool"&&((a=c.state)!=null&&a.status)&&r.set(_,{status:c.state.status,part:c}),(i=c.children)!=null&&i.length&&n(c.children,_)}};return n(t.parts,t.id),{messageId:t.id,states:r}}function OC(e){const r=(t,n)=>{var s;for(const o of t){const a=o.prompt;if(o.type==="prompt"&&(a==null?void 0:a.kind)==="permission"&&!a.resolved){const i=a.toolInput??{},_=Eo(i,"reason","description")||XU(a.tool,i);return{id:o.id,path:`${n}/${o.id}`,label:_}}if((s=o.children)!=null&&s.length){const i=r(o.children,`${n}/${o.id}`);if(i)return i}}return null};for(const t of e){if(t.role!=="assistant")continue;const n=r(t.parts,t.id);if(n)return n}return null}function ats(e){const[r,t]=T.useState({text:"",sequence:0}),n=T.useRef(null);return T.useEffect(()=>{var x,k,v,w,b;const s=((x=e[0])==null?void 0:x.id)??"",{messageId:o,states:a}=ots(e),i=OC(e);if(!n.current||n.current.transcript!==s){n.current={transcript:s,messageId:o,states:a,permissionPath:(i==null?void 0:i.path)??null},t(y=>({text:i?tE({label:Xl(i.label)}):"",sequence:y.sequence+1}));return}const c=n.current.messageId===o?n.current.states:new Map,_=n.current.permissionPath,d=[...a].filter(([y,S])=>{var E;return((E=c.get(y))==null?void 0:E.status)!==S.status});if(n.current={transcript:s,messageId:o,states:a,permissionPath:(i==null?void 0:i.path)??null},i&&i.path!==_){t(y=>({text:tE({label:Xl(i.label)}),sequence:y.sequence+1}));return}const f=(k=d.find(([,y])=>M0(y.part)))==null?void 0:k[1].part;if((f==null?void 0:f.id)==="turn-recovery"){const y=EH((w=(v=f.state)==null?void 0:v.input)==null?void 0:w.recoveryAction);t(S=>({text:`${Zbe()}${y?` ${y==="retry"?rbe():Wve()}`:""}`,sequence:S.sequence+1}));return}if((f==null?void 0:f.id)==="turn-retry"){t(y=>({text:Lve(),sequence:y.sequence+1}));return}const p=d.filter(([,y])=>y.status==="error");if(p.length>0){const y=p.slice(0,2).map(([,S])=>ud(S.part).label).join(", ");t(S=>({text:p.length===1?Rbe({labels:y}):Hbe({count:mr(p.length),labels:y}),sequence:S.sequence+1}));return}const m=d.filter(([,y])=>y.status==="running");if(m.length>0){const y=(b=m.at(-1))==null?void 0:b[1].part;t(S=>({text:y?TC(ud(y)).label:fbe(),sequence:S.sequence+1}));return}d.some(([,y])=>y.status==="completed")&&t(y=>({text:wbe(),sequence:y.sequence+1}))},[e]),r}const its=T.memo(function({messages:r,scrollRef:t,scrollToEndRef:n,stickToBottom:s,onPinToBottom:o,allMessages:a,canFork:i,onFork:c,onSelectFork:_,busy:d,onOpenFile:f,onOpenRun:p,onOpenSpawnedSession:m,runExperimentName:x,onOpenExperiment:k,experimentName:v,onRespond:w,onOpenPlan:b,onOpenSubagent:y,recoveringTurnId:S,onRecover:E,skills:C}){var P,D,q;fu();const A=((P=OC(r))==null?void 0:P.id)??null,N=T.useMemo(()=>r.filter(U=>Kes(U,A)),[r,A]),R=T.useMemo(()=>{const U=N.filter(G=>G.role==="user"&&!G.id.startsWith(Vf));return aWn(a,r,U,G=>G.startsWith(Vf))},[r,N,a]),L=T.useRef(new Set),[$,I]=T.useState(!1),F=T.useCallback(U=>N[U].id,[N]),B=T.useCallback(U=>{if($)return N.map((oe,ce)=>ce);const G=new Set(eC(U));return N.forEach((oe,ce)=>{L.current.has(oe.id)&&G.add(ce)}),[...G].sort((oe,ce)=>oe-ce)},[N,$]),V=xH({count:N.length,useFlushSync:!1,getScrollElement:()=>t.current,getItemKey:F,estimateSize:()=>400,overscan:1,initialRect:{width:((D=t.current)==null?void 0:D.clientWidth)??0,height:((q=t.current)==null?void 0:q.clientHeight)??0},initialOffset:()=>{var U;return Math.max(0,N.length*400-(((U=t.current)==null?void 0:U.clientHeight)??0))},anchorTo:s.current?"end":"start",followOnAppend:!0,scrollEndThreshold:60,rangeExtractor:B});T.useLayoutEffect(()=>{const U=()=>V.scrollToEnd();return n.current=U,o(),()=>{n.current=null}},[V,n,o]),T.useEffect(()=>{const U=()=>{var ce;const G=window.getSelection();if(!G||G.isCollapsed||!G.rangeCount)return;const oe=G.getRangeAt(0);for(const ue of((ce=t.current)==null?void 0:ce.querySelectorAll("[data-message-id]"))??[])oe.intersectsNode(ue)&&ue.dataset.messageId&&L.current.add(ue.dataset.messageId)};return document.addEventListener("selectionchange",U),()=>document.removeEventListener("selectionchange",U)},[t]);const K=N.at(-1),ee=ats(r),J=d?kH(r):null;return u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"sr-only",role:"status","aria-live":"polite",children:u.jsx("span",{children:ee.text},ee.sequence)}),u.jsx("button",{type:"button",className:"sr-only focus:not-sr-only","aria-pressed":$,onClick:()=>I(U=>!U),children:XQe()}),u.jsx("div",{className:"relative",style:{height:V.getTotalSize()},children:V.getVirtualItems().map(U=>{var re,W,ae,ie,ve,xe;const G=N[U.index],oe=G.parts.find(M0),ce=(W=(re=oe==null?void 0:oe.state)==null?void 0:re.input)==null?void 0:W.turnId,ue=oe?d||S!==null:!1;return u.jsx("div",{"data-index":U.index,"data-message-id":G.id,ref:V.measureElement,className:"absolute left-0 w-full pb-4",style:{top:U.start},onClickCapture:Ce=>{!(Ce.target instanceof Element)||!Ce.target.closest("[data-work-toggle]")||(s.current=!1,V.setOptions({...V.options,anchorTo:"start"}))},onPointerDownCapture:()=>L.current.add(G.id),onFocusCapture:()=>L.current.add(G.id),children:u.jsx(Yes,{message:G,forkCount:(ae=R.get(G.id))==null?void 0:ae.count,forkIndex:(ie=R.get(G.id))==null?void 0:ie.index,forkPrevId:(ve=R.get(G.id))==null?void 0:ve.prevId,forkNextId:(xe=R.get(G.id))==null?void 0:xe.nextId,forkDisabled:!i,branchDisabled:d,onFork:c,onSelectFork:_,activePermissionId:A,pendingTailToolId:(J==null?void 0:J.messageId)===G.id?J.toolId:null,onOpenFile:f,onOpenRun:p,onOpenSpawnedSession:m,runExperimentName:x,onOpenExperiment:k,experimentName:v,onRespond:w,onOpenPlan:b,onOpenSubagent:y,busy:ue,recoveringTurnId:ce===S?S:null,onRecover:E,skills:C,predictTextTail:d&&G===K&&G.role==="assistant"})},G.id)})})]})}),cts=(e,r)=>e==="all"?!0:e==="archived"?r:!r;function u4(e){return e instanceof Element&&e.closest("[data-side-chat]")!==null}const lts=[{id:"archived",label:dE,railLabel:dE},{id:"active",label:ANe,railLabel:lD},{id:"all",label:BNe,railLabel:eD}];function uts({value:e,onChange:r,grouping:t,onGroupingChange:n}){const{open:s,setOpen:o,ref:a}=ta();return u.jsxs("div",{className:"rail-filter relative inline-flex",ref:a,children:[u.jsx(kt,{size:"small",className:"rail-filter-btn text-subtext",active:e!=="active",title:jE(),"aria-label":jE(),onClick:()=>o(i=>!i),children:u.jsx(IP,{size:15,className:"text-subtext"})}),s&&u.jsxs("div",{className:"option-menu absolute bottom-[calc(100%_+_8px)] start-0 max-h-95 flex flex-col bg-background border border-border rounded-lg shadow-menu z-50 overflow-hidden min-w-40 p-1 [&.align-right]:start-auto [&.align-right]:end-0 [&.drop-down]:bottom-auto [&.drop-down]:top-[calc(100%_+_4px)] [&.session-menu]:start-auto [&.session-menu]:end-1.5 [&.session-menu]:top-[calc(100%_-_2px)] [&.session-menu]:min-w-35 drop-down align-right",children:[u.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:Fln()}),["projects","list"].map(i=>u.jsxs(_r,{size:"compact",className:"text-sm",onClick:()=>{n(i),o(!1)},children:[u.jsx("span",{children:i==="projects"?dS():Yln()}),t===i&&u.jsx(fo,{size:13})]},i)),u.jsx("div",{className:"my-1 border-t border-border"}),u.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:Tln()}),lts.map(i=>u.jsxs(_r,{size:"compact",className:"text-sm",onClick:()=>{r(i.id),o(!1)},children:[u.jsx("span",{children:i.label()}),e===i.id&&u.jsx(fo,{size:13})]},i.id))]})]})}const _ts=14,fts=500,dts=1200;function JU({title:e,animate:r}){return r?u.jsx("span",{className:"title-reveal","aria-label":e,children:Array.from(e).map((t,n)=>t===" "?u.jsx("span",{"aria-hidden":!0,children:t},n):u.jsx("span",{"aria-hidden":!0,className:"title-reveal-char inline-block animate-[title-char-in_240ms_ease-out_both] [@media((prefers-reduced-motion:_reduce))]:animate-none",style:{animationDelay:`${Math.min(n*_ts,fts)}ms`},children:t},n))}):u.jsx(u.Fragment,{children:e})}function hts({session:e,active:r,unread:t,busy:n,waiting:s,revealTitle:o,onOpen:a,onRename:i,onSetArchived:c,onDelete:_}){var E;const{open:d,setOpen:f,ref:p}=ta(),m=((E=e.title)==null?void 0:E.trim())||"Untitled",[x,k]=T.useState(!1),[v,w]=T.useState(""),b=T.useRef(null);function y(){var C;w(((C=e.title)==null?void 0:C.trim())||""),k(!0)}function S(){var A;const C=v.trim();k(!1),C&&C!==(((A=e.title)==null?void 0:A.trim())||"")&&i(C)}return T.useEffect(()=>{var C,A;x&&((C=b.current)==null||C.focus(),(A=b.current)==null||A.select())},[x]),u.jsxs("div",{ref:p,role:"button",tabIndex:0,className:`session-row relative flex items-center gap-2 w-full text-start py-[7px] ps-2.5 pe-1.5 rounded-md text-sm text-text cursor-pointer select-none [&:hover:not(.active)]:bg-surface [&.active]:bg-panel [&.active]:font-medium [&_.session-dot:empty]:hidden [&_.session-dot]:w-4 [&_.session-dot]:inline-flex [&_.session-dot]:items-center [&_.session-dot]:justify-center [&_.session-dot]:shrink-0 [&_.session-title]:flex-1 [&_.session-title]:min-w-0 [&_.session-title]:overflow-hidden [&_.session-title]:[mask-image:linear-gradient(to_right,black_calc(100%_-_16px),transparent)] [&_.session-title]:whitespace-nowrap [&_.session-menu-btn]:hidden [&_.session-menu-btn]:items-center [&_.session-menu-btn]:justify-center [&_.session-menu-btn]:w-4 [&_.session-menu-btn]:h-4 [&_.session-menu-btn]:-my-0.5 [&_.session-menu-btn]:mx-0 [&_.session-menu-btn]:rounded-sm [&_.session-menu-btn]:text-muted [&_.session-menu-btn]:shrink-0 [&_.session-menu-btn:hover]:text-text [&_.session-menu-btn:hover]:bg-panel [&:hover_.session-menu-btn]:inline-flex [&:focus-visible_.session-menu-btn]:inline-flex [&_.session-menu-btn:focus-visible]:inline-flex [&.menu-open_.session-menu-btn]:inline-flex [&:hover_.session-dot]:hidden [&:focus-visible_.session-dot]:hidden [&:has(.session-menu-btn:focus-visible)_.session-dot]:hidden [&.menu-open_.session-dot]:hidden [&_.busy-dot]:w-[7px] [&_.busy-dot]:h-[7px] [&_.busy-dot]:rounded-full [&_.busy-dot]:bg-primary [&_.busy-dot]:animate-[or-pulse_1.2s_infinite] [&_.busy-dot]:shrink-0 [&_.unread-dot]:w-[7px] [&_.unread-dot]:h-[7px] [&_.unread-dot]:rounded-full [&_.unread-dot]:bg-primary [&_.unread-dot]:shrink-0 [&_.busy-dot.waiting]:animate-none [&_.session-title-input]:flex-1 [&_.session-title-input]:min-w-0 [&_.session-title-input]:py-px [&_.session-title-input]:px-[5px] [&_.session-title-input]:-my-0.5 [&_.session-title-input]:mx-0 [&_.session-title-input]:[font:inherit] [&_.session-title-input]:text-text [&_.session-title-input]:bg-background [&_.session-title-input]:border [&_.session-title-input]:border-primary [&_.session-title-input]:rounded-sm [&_.session-title-input]:outline-none [&.editing]:bg-surface [&.editing]:cursor-default [&.editing_.session-menu-btn]:hidden [&.editing_.session-dot]:hidden ${r?"active":""} ${t?"unread":""} ${d?"menu-open":""} ${x?"editing":""}`,title:`${Af(e.harness,e.harnessName)}${e.model?` · ${e.model}`:""}`,onClick:()=>{x||(d?f(!1):a())},onKeyDown:C=>{C.target===C.currentTarget&&(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),d?f(!1):a())},children:[x?u.jsx("input",{ref:b,className:"session-title-input","aria-label":bHe(),value:v,onChange:C=>w(C.target.value),onClick:C=>C.stopPropagation(),onBlur:S,onKeyDown:C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),S()):C.key==="Escape"&&(C.preventDefault(),k(!1))}}):u.jsx("span",{className:"session-title",children:u.jsx(JU,{title:m,animate:o!==void 0},o??"static")}),s&&!x&&u.jsx(Va,{content:aD(),className:"shrink-0 text-accent-amber",children:u.jsx(CP,{size:14,"aria-hidden":"true"})}),u.jsx("span",{className:"session-dot",children:n&&!s?u.jsx("span",{className:"busy-dot"}):t&&!s&&u.jsx("span",{className:"unread-dot"})}),u.jsx("button",{className:"session-menu-btn",title:ME(),"aria-label":ME(),onClick:C=>{C.stopPropagation(),f(A=>!A)},children:u.jsx(Sp,{size:14})}),d&&u.jsxs("div",{className:"option-menu absolute bottom-[calc(100%_+_8px)] start-0 max-h-95 flex flex-col bg-background border border-border rounded-lg shadow-menu z-50 overflow-hidden min-w-47.5 p-1.5 [&.align-right]:start-auto [&.align-right]:end-0 [&.drop-down]:bottom-auto [&.drop-down]:top-[calc(100%_+_4px)] [&.session-menu]:start-auto [&.session-menu]:end-1.5 [&.session-menu]:top-[calc(100%_-_2px)] [&.session-menu]:min-w-35 drop-down session-menu",children:[u.jsx(_r,{onClick:C=>{C.stopPropagation(),f(!1),y()},children:u.jsx("span",{children:sD()})}),u.jsx(_r,{onClick:C=>{C.stopPropagation(),f(!1),c(!e.archived)},children:u.jsx("span",{children:e.archived?BYe():WSe()})}),u.jsx(_r,{danger:!0,onClick:C=>{C.stopPropagation(),f(!1),_()},children:u.jsx("span",{children:rD()})})]})]})}const XM=[jP,DP,R_,w0],pts=()=>[{title:sqe(),prompt:VHe()},{title:jqe(),prompt:hqe()},{title:Uqe(),prompt:Oqe()},{title:uUe(),prompt:eUe()}],_4=[{box:"border-accent-blue/45",icon:"text-accent-blue"},{box:"border-accent-green/45",icon:"text-accent-green"},{box:"border-accent-amber/45",icon:"text-accent-amber"},{box:"border-primary/45",icon:"text-primary"}],YM="mt-7 grid w-full max-w-readable grid-cols-1 gap-3 sm:grid-cols-2";function mts(e,r){if(!e)return null;const t=e.model??null;return{...e,model:t,serviceTier:Tb(r,t,e.serviceTier),reasoningLevel:LI(r,t,e.reasoningLevel)}}function ZM({projectId:e,projectName:r,contentLoading:t=!1,contentError:n=null,onRetryContent:s,railHeader:o,railOpen:a,onShowRail:i,onNewProject:c,mainView:_,onSelectMainView:d,onOpenFile:f,onOpenRun:p,runExperimentName:m,onOpenExperiment:x,experimentName:k,onOpenPlan:v,onOpenSubagent:w,runtime:b,onOpenDemoWelcome:y,composerFocusNonce:S=0,activeSessionId:E,onActiveSessionChange:C,preferredAgent:A,onPreferredAgentChange:N,preferredAutonomy:R,onPreferredAutonomyChange:L,embedded:$=!1,onOpenSideChat:I,onRunSetup:F,children:B}){var bs,_n,Nr,Fi,qo,Id,Hi,qp;const V=wr({mutationFn:Y=>hAn(...Y)}),K=wr({mutationFn:Y=>uAn(...Y)}),ee=wr({mutationFn:Y=>dAn(...Y)}),J=wr({mutationFn:Y=>fAn(...Y)}),P=wr({mutationFn:Y=>nAn(...Y)}),D=wr({mutationFn:Y=>aAn(...Y)}),q=wr({mutationFn:Y=>cAn(...Y)}),U=wr({mutationFn:Y=>lAn(...Y)}),G=wr({mutationFn:E3}),oe=h0(),{data:ce=[]}=nt({...A_(),enabled:!$}),{data:ue=[]}=nt({...aA(),enabled:!$}),[re,W]=T.useState(()=>{try{return localStorage.getItem("sidebar-grouping")==="list"?"list":"projects"}catch{return"projects"}}),[ae,ie]=T.useState(()=>{try{const Y=JSON.parse(localStorage.getItem("sidebar-pinned-projects")??"[]");return Array.isArray(Y)?Y.filter(_e=>typeof _e=="string"):[]}catch{return[]}}),[ve,xe]=T.useState(()=>{try{const Y=JSON.parse(localStorage.getItem("sidebar-collapsed-projects")??"[]");return Array.isArray(Y)?Y.filter(_e=>typeof _e=="string"):[]}catch{return[]}}),[Ce,Fe]=T.useState("active"),[Ye,Oe]=T.useState(!1),Ie=T.useRef(null),[ut,jt]=T.useState(0),[Ut,Wt]=T.useState(null),[Pt,mt]=T.useState({});T.useLayoutEffect(()=>{const Y=Ie.current;if(!Y||$)return;const _e=()=>jt(Y.clientHeight),we=new ResizeObserver(_e);return we.observe(Y),_e(),()=>we.disconnect()},[a,$,_]);const wt=new Map(ue.map(Y=>[Y.projectId,Y.lastActivityAt])),Mt=[...ce].sort((Y,_e)=>Number(ae.includes(_e.id))-Number(ae.includes(Y.id))||Math.max(wt.get(_e.id)??0,_e.updatedAt)-Math.max(wt.get(Y.id)??0,Y.updatedAt)),ze=re==="list"||Ye?Mt.length:Math.max(1,Math.ceil(ut/36));let Be=Mt.slice(0,ze);const je=ce.find(Y=>Y.id===e);je&&!Be.some(Y=>Y.id===e)&&(Be=[...Be.slice(0,ze-1),je]);const ot=Y$({queries:(re==="projects"?Be:[]).map(Y=>({...Ao(Y.id),enabled:!$}))}),We=_Q({queryKey:zt("listSidebarChatSessions",Ce),queryFn:({pageParam:Y,signal:_e})=>uTn(Ce,Y,_e),initialPageParam:null,getNextPageParam:Y=>Y.next??void 0,enabled:!$&&re==="list"}),rt=T.useMemo(()=>Ao(e),[e]),{data:ft=WM}=nt(rt),tr=T.useCallback(Y=>{ss(rt.queryKey,_e=>{if(!_e)return;const we=typeof Y=="function"?Y(_e):Y,ye=new Map(_e.map($e=>[$e.id,$e]));for(const $e of we)ye.get($e.id)!==$e&&vi(Xe,rt.queryKey,$e.id),ye.delete($e.id);for(const $e of ye.keys())vi(Xe,rt.queryKey,$e);return we})},[rt]),me=E,Ht=T.useRef(C);Ht.current=C;const Ke=T.useRef({projectId:e});Ke.current.projectId!==e&&(Ke.current={projectId:e});const[or,Lt]=T.useState(new Set),[Zt,Bt]=T.useState(""),[vt,Sn]=T.useState(!1),[Lr,Cr]=T.useState([]),Dr=T.useRef(0),dt=T.useRef({projectId:e,activeId:me,mainView:_});(dt.current.projectId!==e||dt.current.activeId!==me||dt.current.mainView!==_)&&(dt.current={projectId:e,activeId:me,mainView:_});const[gr,jr]=T.useState([]),[nr,sn]=T.useState(null),[Br,zr]=T.useState(null),Fr=me??`${e}:new`,Ot=T.useRef(new Map),Kt=T.useRef(Ck);Kt.current={draft:Zt,attachments:gr,annotations:Lr};const en=e===Cm&&!$&&ft.length>0&&ft.every(Y=>Y.sideParentSessionId||P9n[Y.id]===Y.activeLeafId)?KN:null,Vr=T.useRef(null);en!==null&&Vr.current===null&&me!==null&&(Vr.current=Fr);const Cn=Fr===Vr.current?en:null;T.useLayoutEffect(()=>{const Y=Ot.current.get(Fr)??Ck;return Kt.current=Y,Bt(Y.draft),jr(Y.attachments),Cr(Y.annotations),zr(null),()=>{const _e=vWn(Kt.current,Cn);_e?Ot.current.set(Fr,_e):Ot.current.delete(Fr)}},[Fr,Cn]);const[cn,Gt]=T.useState(null),hs=T.useRef(Promise.resolve()),Kn=T.useRef(0),Ws=T.useRef(0),[Ks,os]=T.useState(null),gn=T.useRef(null),Ve=T.useRef(!1),bt=T.useRef(null),[vr,dr,qr]=mTn(e,_==="chat"?me:null),{data:ar=bts}=nt(cu()),[Ns,ps]=T.useState(A);T.useEffect(()=>ps(A),[A]);const[vn,as]=T.useState({}),[eo,to]=T.useState(Dm),[As,Ni]=T.useState(null),Vs=T.useRef(!1),Ea=T.useRef(null),[Bn,Fn]=T.useState(null),Na=T.useRef(!1),na=T.useRef(null),[oi,Aa]=T.useState(new Map),ro=T.useRef(new Map),Ta=T.useRef(null),Vn=T.useRef(null),mo=T.useRef(null),Qn=T.useRef(!0),[go,vo]=T.useState(!0),ln=T.useRef(null),[ic,Ts]=T.useState(!1),yu=ta(),Nd=T.useCallback(Y=>{var _e;Dr.current+=1,Cr(we=>[...we,{id:`annotation-${Dr.current}`,...Y}]),(_e=ln.current)==null||_e.focus()},[]),Ra=pes(Vn,Nd);mes(Lr,$?aes:oes),T.useEffect(()=>{Ts(!1),Ra.dismiss()},[me,e,Ra.dismiss]);const[rl,cc]=T.useState(0),[Dp,Ma]=T.useState(0),[no,so]=T.useState(!1),[oo,sa]=T.useState(0),[Rs,Ms]=T.useState(0),Os=T.useRef(!1);function xu(Y){if(!is)return;if(!Lo&&Y.source==="command"&&Lx(Y.name)&&Y.name!=="goal"){il(Y.name,Zt,is);return}const _e=Y.name.replace(/@u$/,"^").replace(/@p$/,"~"),we=Y.source==="command"?1:IM(_e,ln.current),ye=kJn(Zt,is,_e,we);Bt(ye.text),window.requestAnimationFrame(()=>{var $e,Et;($e=ln.current)==null||$e.focus(),(Et=ln.current)==null||Et.setSelectionRange(ye.cursor,ye.cursor),Ms(ye.cursor)})}function zn(Y){if(!ii)return;const _e=sWn(Zt,ii,Y);Bt(_e.text),window.requestAnimationFrame(()=>{var we,ye;(we=ln.current)==null||we.focus(),(ye=ln.current)==null||ye.setSelectionRange(_e.cursor,_e.cursor),Ms(_e.cursor)})}function Rn(Y){if(W_)return!1;const _e=Y.selectionStart;if(Os.current||_e!==Y.selectionEnd)return!1;const we=Zt.slice(0,_e).replace(/[ \t]+$/,"").length,ye=t4(Zt,we);if(!ye||ye.end!==we||!mc(ye.query)||_e>we&&_e-we!==IM(ye.query,Y))return!1;const $e=DM(Zt,{...ye,end:_e});return Bt($e.text),Ms($e.cursor),window.requestAnimationFrame(()=>Y.setSelectionRange($e.cursor,$e.cursor)),!0}function $s(Y){sn(null),zr(null);let ye=gr.reduce(($e,Et)=>$e+Et.size,0);for(const $e of Y){if(!/^(image\/(png|jpeg|gif|webp)|application\/pdf)$/.test($e.type))continue;if(Su&&$e.type.startsWith("image/")){zr((Ls==null?void 0:Ls.id)??null);continue}if($e.size>31457280){sn(R6e({name:Te($e.name)}));continue}if(ye+$e.size>41943040){sn(H6e());continue}ye+=$e.size;const Et=dt.current,pt=Fr,ir=new FileReader;ir.onload=()=>{const cr={dataUrl:ir.result,mediaType:$e.type,name:$e.name,size:$e.size};if(dt.current.projectId===Et.projectId&&dt.current.activeId===Et.activeId){jr(wo=>[...wo,cr]);return}const lr=Ot.current.get(pt)??Ck;Ot.current.set(pt,{...lr,attachments:[...lr.attachments,cr]})},ir.readAsDataURL($e)}}function Xn(Y){const _e=Array.from(Y.clipboardData.items).filter(we=>we.kind==="file"&&(we.type.startsWith("image/")||we.type==="application/pdf")).map(we=>we.getAsFile()).filter(we=>we!==null);_e.length>0&&(Y.preventDefault(),$s(_e))}const lt=ft.find(Y=>Y.id===me),nl=Ns??ALn(ar),Oo=lt?{harness:lt.harness,model:vn.model!==void 0?vn.model:lt.model,serviceTier:vn.serviceTier!==void 0?vn.serviceTier:lt.serviceTier,permissionMode:vn.permissionMode??lt.permissionMode,reasoningLevel:vn.reasoningLevel??lt.reasoningLevel}:nl?{...nl,...vn}:null,{data:sl=vts}=nt(HAn(Oo==null?void 0:Oo.harness,e)),wu=Oo?ar.find(Y=>Y.id===Oo.harness):void 0,Ze=kLn(lt,wu),oa=_B(lt==null?void 0:lt.nativeConfiguration,{model:Nh(),mode:_3()}),Yn=oa.find(Y=>Y.category==="model"),Jt=Ze==null?void 0:Ze.options,{data:Ai}=nt({...kS(),enabled:!!F}),Ti=Y=>{if(!Ze)return;const _e=Ai==null?void 0:Ai[Ze.id];if(!(Ze.id==="claude-code"&&Y===(_e==null?void 0:_e.login)&&!Ze.loginEligible))return wU(Ze,_e,Y)},aa=T.useMemo(()=>jJn(sl,Jt==null?void 0:Jt.planActivation),[sl,Jt==null?void 0:Jt.planActivation]),lc=BM(Zt),Ri=lc!==null,is=t4(Zt,Rs),ai=(is==null?void 0:is.query)??null,G_=ai===null?[]:aa.filter(Y=>xJn(Y,ai)),W_=!Ri&&ai!==null&&(is==null?void 0:is.end)===Rs&&G_.length>0,uc=W_&&!no?G_:[],Ad=uc.length>0,Mi=Math.min(rl,Math.max(0,uc.length-1));T.useEffect(()=>cc(0),[ai]);const ii=Ri?null:eWn(Zt,Rs),_c=(ii==null?void 0:ii.end)===Rs?ii.query:null,ci=(bs=nt({...C6(e,me?{sessionId:me}:{}),enabled:_c!==null}).data)==null?void 0:bs.entries,fc=T.useMemo(()=>rWn(ci??[]),[ci]),Oi=T.useMemo(()=>_c!==null&&!no?nWn(fc,_c):[],[fc,_c,no]),Td=Oi.length>0,ku=Math.min(Dp,Math.max(0,Oi.length-1));T.useEffect(()=>Ma(0),[_c]);const hr=mts(Yn&&Oo?{...Oo,model:Yn.currentValue}:Oo,Ze),ju=Dy(Ze,hr==null?void 0:hr.model),Ls=Ze==null?void 0:Ze.models.find(Y=>Y.id===(hr==null?void 0:hr.model)),Su=(Ls==null?void 0:Ls.imageInput)===!1?l9e({model:Te(Wv(Ls))}):null,K_=!!Su&&gr.some(Y=>Y.mediaType.startsWith("image/")),Rd=!!Ls&&Br===Ls.id,Qs=K_||Rd?Su:null;T.useEffect(()=>zr(null),[Ls==null?void 0:Ls.id]);const dc=Y=>{if(lt!=null&<.harness.startsWith("acp:")&&Yn&&Y.model){QN(lt.id,Yn.id,Y.model).catch(ye=>Xt(ye instanceof Error?ye.message:String(ye),"error"));return}if(!hr)return;const _e={...hr,...Y},we={};Y.model!==void 0&&Y.model!==hr.model&&(we.model=Y.model),Y.serviceTier!==void 0&&Y.serviceTier!==hr.serviceTier&&(we.serviceTier=Y.serviceTier),Y.permissionMode!==void 0&&Y.permissionMode!==hr.permissionMode&&(we.permissionMode=Y.permissionMode),Y.reasoningLevel!==void 0&&Y.reasoningLevel!==hr.reasoningLevel&&(we.reasoningLevel=Y.reasoningLevel),to(ye=>({...ye,...we})),ps(_e),N(_e).catch(()=>{}),lt?as(ye=>({...ye,...Y})):Y.harness&&Y.harness!==hr.harness&&as({})},Xs=T.useCallback(Y=>{const _e=hs.current.catch(()=>{}).then(()=>{if(!Kr(rt.queryKey))throw new DOMException("Workspace changed","AbortError");return Y()});return hs.current=_e.then(()=>{},()=>{}),_e},[rt]),ol=Y=>{if(Y==="plan"&&(Ze==null?void 0:Ze.id)==="claude-code"?(to(ye=>({...ye,permissionMode:Y})),as(ye=>({...ye,permissionMode:Y}))):(as(ye=>{const $e={...ye};return delete $e.permissionMode,$e}),dc({permissionMode:Y})),!lt)return;const _e=lt.id,we=++Kn.current;Gt(null),Xs(()=>V.mutateAsync([_e,Y])).then(ye=>{tr($e=>$e.map(Et=>Et.id===ye.id?ye:Et)),Kn.current===we&&as($e=>{const Et={...$e};return delete Et.permissionMode,Et})}).catch(()=>{Kn.current===we&&(as(ye=>{const $e={...ye};return delete $e.permissionMode,$e}),Gt(pZe()))})},V_=Y=>dc({reasoningLevel:Y}),Ip=Y=>{if(!lt){L(Y);return}const _e=lt.id,we=lt.autonomy,ye=++Kn.current,$e=Et=>tr(pt=>pt.map(ir=>ir.id===Et.id?Et:ir));$e({...lt,autonomy:Y}),Gt(null),Xs(()=>ee.mutateAsync([_e,Y])).then(Et=>{$e(Et),L(Et.autonomy)}).catch(()=>{tr(Et=>Et.map(pt=>pt.id===_e&&pt.autonomy===Y?{...pt,autonomy:we}:pt)),Kn.current===ye&&Gt(oZe())})},$i=((_n=lt==null?void 0:lt.goal)==null?void 0:_n.trim())||"",Cu=(hr==null?void 0:hr.harness)==="claude-code"?hr.permissionMode==="plan":(Jt==null?void 0:Jt.planActivation)==="command"?Ks??(lt==null?void 0:lt.planMode)??!1:!1;T.useEffect(()=>{Ks===null||(lt==null?void 0:lt.planMode)!==Ks||(gn.current=null,os(null))},[lt==null?void 0:lt.planMode,Ks]);async function Q_(Y){if(to(ye=>({...ye,planMode:Y})),gn.current=Y,os(Y),!lt)return;const _e=lt.id,we=++Ws.current;Gt(null);try{const ye=await Xs(()=>K.mutateAsync([_e,Y]));tr($e=>$e.map(Et=>Et.id===ye.id?ye:Et)),Ws.current===we&&(gn.current=null,os(null),Gt(null))}catch(ye){throw Ws.current===we&&(gn.current=null,os(null)),ye}}async function X_(){if((hr==null?void 0:hr.harness)==="claude-code"){ol("auto");return}if(lt)try{await Q_(!1)}catch{Gt(H7e())}}async function Y_(){const Y=!Cu;try{if((hr==null?void 0:hr.harness)==="claude-code")ol(Y?"plan":"auto");else if((Jt==null?void 0:Jt.planActivation)==="command")await Q_(Y);else throw new Error(G1())}catch{Gt(PE())}}function ia(Y,_e=""){var we;switch(Y){case"plan":return Y_(),!1;case"new":return $?lt!=null&<.sideParentSessionId&&(I==null||I(lt.sideParentSessionId,"")):Po(),!1;case"resume":return Ts(!0),!0;case"model":return sa(ye=>ye+1),!0;case"compact":return Eu(),!1;case"goal":return al(_e),!1;case"side":return Pp(_e),!1;case"copy":{const ye=gs.at(-1),$e=yr&&(ye==null?void 0:ye.role)==="assistant"&&!ye.completedAt,Et=fWn($e?gs.slice(0,-1):gs);return Et?MC(Et):Xt(pEe(),"info"),!1}case"export":{const ye=((we=lt==null?void 0:lt.title)==null?void 0:we.trim())||Gv(),$e=lt?dWn(ye,gs,{user:v8e(),assistant:Af(lt.harness,lt.harnessName)}):null;return $e?Qes(hWn(ye),$e):Xt(SEe(),"info"),!1}}}function Pp(Y){$?Xt(Lcn(),"info"):!lt||!I?Xt(Ccn(),"info"):I(lt.id,Y)}async function zu(Y){Gt(null);const _e=Ke.current;try{const we=await P.mutateAsync([e,Y]);if(Xe.invalidateQueries({queryKey:KI().queryKey}),Ke.current!==_e)return;tr(ye=>[we,...ye.filter($e=>$e.id!==we.id)]),Fe("all"),C(we.id,{projectId:we.projectId})}catch(we){if(Ke.current!==_e)return;Gt(Mze({error:Te(we instanceof Error?we.message:String(we))}))}}async function al(Y){var pt;const _e=Y.trim();if(!_e){const ir=(pt=lt==null?void 0:lt.goal)==null?void 0:pt.trim();Xt(ir?I8e({goal:Xl(ir)}):nze(),"info");return}const we=dt.current,ye=()=>dt.current.activeId===we.activeId;Gt(null);let $e=me;if(!$e){if(!(Ze!=null&&Ze.agentReady)||!hr){Gt(G1());return}try{$e=(await io(hr,n4(Jt==null?void 0:Jt.planActivation,void 0,gn.current))).id}catch(ir){Gt(_E({error:Te(ir instanceof Error?ir.message:String(ir))}));return}}const Et=/^(clear|none|off)$/i.test(_e);try{const ir=await Xs(()=>J.mutateAsync([$e,Et?null:_e]));tr(cr=>cr.map(lr=>lr.id===ir.id?ir:lr)),Xt(Et?E8e():dze(),"success")}catch(ir){if(!ye())return;Gt(_E({error:Te(ir instanceof Error?ir.message:String(ir))}))}}async function Eu(){const Y=me;if(!Y){Xt(oEe(),"info");return}if(yr){Gt(DCe());return}Gt(null),Ce==="archived"&&Fe("active");const _e=dt.current;try{const{message:we}=await bAn(Y);dr({type:"upsertMessage",sessionId:Y,message:we})}catch(we){if(dt.current.activeId!==_e.activeId)return;Gt(KCe({error:Te(we instanceof Error?we.message:String(we))}))}}function il(Y,_e,we){const ye=DM(_e,we);Bt(ye.text),so(!0),!ia(Y)&&window.requestAnimationFrame(()=>{var $e,Et;($e=ln.current)==null||$e.focus(),(Et=ln.current)==null||Et.setSelectionRange(ye.cursor,ye.cursor),Ms(ye.cursor)})}const li=T.useCallback(async(Y=!1)=>{const _e=Ke.current;if(_e.projectId!==e||!Kr(rt.queryKey))return null;const we=(Xe.getQueryData(rt.queryKey)??[]).map(ye=>ye.id);try{const ye=await Xe.fetchQuery({...rt,...Y?{staleTime:0}:{}});if(Ke.current!==_e||!Kr(rt.queryKey))return null;const $e=ye.filter(pt=>!Bc.has(pt.id)),Et=new Set($e.map(pt=>pt.id));for(const pt of we)Et.has(pt)||ke(pt);return ro.current=new Map($e.map(pt=>[pt.id,pt.title])),$e}catch{return null}},[e]),ms=T.useCallback(async Y=>{Ke.current.projectId!==e||!Kr(rt.queryKey)||await Promise.all([Xe.fetchQuery({...Hc(Y),staleTime:0}),li(!0)]).catch(()=>{})},[e,li]);T.useEffect(()=>{const Y=eB();Lt(e===Cm?new Set([bS,yS].filter(we=>!Y.has(we))):new Set),Sn(!1),Aa(new Map),ro.current=new Map,li();const _e=Ke.current;return()=>{Ke.current===_e&&(Ke.current={projectId:e})}},[e,li]),T.useEffect(()=>{to(Dm),na.current=null},[me]),T.useEffect(()=>wg(Y=>{switch(Y.type){case"session":{if(Y.session.projectId!==e||Bc.has(Y.session.id))return;const _e=ro.current.has(Y.session.id),we=ro.current.get(Y.session.id)!==Y.session.title;ro.current.set(Y.session.id,Y.session.title),_e&&we&&Y.session.titleSource==="generated"&&(Aa(ye=>{const $e=new Map(ye);return $e.set(Y.session.id,(ye.get(Y.session.id)??0)+1),$e}),window.setTimeout(()=>{Aa(ye=>{if(!ye.has(Y.session.id))return ye;const $e=new Map(ye);return $e.delete(Y.session.id),$e})},dts));break}case"sessionDeleted":ke(Y.sessionId);break}}),[e]),T.useEffect(()=>wg(Y=>{Y.type==="reconnected"&&li(!0)}),[li]);const hc=me?vr.messagesBySession[me]??GM:GM,pc=me?vr.activeLeafBySession[me]??null:null;Ea.current=pc;const gs=T.useMemo(()=>mR(hc,pc),[hc,pc]),cl=T.useRef({projectId:e,ids:vr.busySessions});T.useEffect(()=>{const Y=cl.current;cl.current={projectId:e,ids:vr.busySessions},Y.projectId===e&&Lt(_e=>_Wn(_e,Y.ids,vr.busySessions,ft,_==="chat"?me:null))},[e,vr.busySessions,ft,me,_]);const yr=me?vr.busySessions.has(me):!1,ll=!yr&&!!(Ze!=null&&Ze.agentReady),ul=yr&&kH(gs)!=null,Md=yr&&uWn(gs),$o=me?vr.queuedBySession[me]??[]:[],_l=$o.some(Y=>Y.dispatchState==="retrying"),Od=$o.findIndex(Y=>Y.dispatchState==="blocked"),Li=$o.reduce((Y,_e)=>_e.dispatchState!=="retrying"||typeof _e.nextRetryAt!="number"?Y:Y===null?_e.nextRetryAt:Math.min(Y,_e.nextRetryAt),null),[Di,fl]=T.useState(()=>Date.now());T.useEffect(()=>{if(!_l||Li===null||(fl(Date.now()),Li<=Date.now()))return;const Y=window.setInterval(()=>{const _e=Date.now();fl(_e),_e>=Li&&window.clearInterval(Y)},1e3);return()=>window.clearInterval(Y)},[_l,Li]),T.useEffect(()=>{const Y=$o.reduce((_e,we)=>we.planMode??_e,void 0);Y!==void 0?(Ve.current=!0,gn.current=Y,os(Y)):Ve.current&&(Ve.current=!1,gn.current=null,os(null))},[$o]);const Nu=!!me&&qr.isPending,Z_=T.useMemo(()=>{const Y=new Set;for(const[_e,we]of Object.entries(vr.messagesBySession)){const ye=vr.busySessions.has(_e);iWn(mR(we,vr.activeLeafBySession[_e]),ye)&&Y.add(_e)}return Y},[vr.busySessions,vr.messagesBySession,vr.activeLeafBySession]),Au=yr&&gs.some(Y=>Y.parts.some(_e=>_e.type==="prompt"&&_e.prompt&&!_e.prompt.resolved&&_e.prompt.nativeId)),tn=lt,J_=tn?oi.get(tn.id):void 0,ao=T.useMemo(()=>{var Y;for(let _e=gs.length-1;_e>=0;_e--)for(const we of gs[_e].parts)if(we.type==="prompt"&&((Y=we.prompt)==null?void 0:Y.kind)==="plan"&&!we.prompt.resolved)return{promptId:we.id,plan:we.prompt.plan??"",synthesized:!!we.prompt.synthesized};return null},[gs]),Lo=T.useMemo(()=>me?cWn(gs,tn==null?void 0:tn.harness,vr.busySessions.has(me)):null,[gs,tn==null?void 0:tn.harness,me,vr.busySessions]),bn=Ri&&!Lo,mc=Y=>{if(Lo||Ri)return!1;const _e=nj(Y),we=aa.find(ye=>ye.name===zC(_e??Y));return!we||we.source!=="command"?!!we:_e&&r4(_e)?_e==="plan"||Zt.trim().toLowerCase().startsWith(`/${Y}`):Zt.trim().toLowerCase()===`/${Y}`},$d=T.useMemo(()=>aa.filter(Y=>Y.source!=="command"),[aa]),[En,Ur]=T.useState(null),dl=En&&En.sessionId===me?En:null;T.useEffect(()=>{if(!En)return;const Y=vr.busySessions.has(En.sessionId),_e=En.sessionId===me&&ao&&ao.promptId!==En.promptId;(!Y||_e)&&Ur(null)},[En,ao,vr.busySessions,me]);const ef=T.useMemo(()=>OC(gs),[gs]),hl=yr&&!!(Ze!=null&&Ze.supportsSteering)&&!!(Ze!=null&&Ze.agentReady)&&!ao&&!Lo&&!ef&&gr.length===0&&Lr.length===0,Oa=T.useMemo(()=>v&&me?(Y,_e,we)=>v(Y,me,_e,we):void 0,[v,me]),vs=T.useMemo(()=>w&&me?(Y,_e,we)=>w(me,Y,_e,we):void 0,[w,me]),ca=T.useMemo(()=>f&&((Y,_e,we,ye,$e)=>f(Y,me??void 0,_e,we,ye,$e)),[f,me]);T.useEffect(()=>{Kn.current+=1,Ws.current+=1;const Y=(me?vr.queuedBySession[me]??[]:[]).reduce((_e,we)=>we.planMode??_e,void 0);Ve.current=Y!==void 0,gn.current=Y??null,os(Y??null),as({}),Gt(null)},[me]);const Do=_==="chat"&&(gs.length>0||yr),gc=(hr==null?void 0:hr.harness)??null,$a=(hr==null?void 0:hr.model)??null,Io=qr.data?null:qr.error,Ds=_==="chat"&&!$&&!Do&&!t&&!n&&!Nu&&!Io,cs=nt({...vTn(e,gc??"claude-code",$a,z()),enabled:Ds&&gc!==null,subscribed:Ds&&gc!==null}),La=(Nr=cs.data)!=null&&Nr.blank?pts():((Fi=cs.data)==null?void 0:Fi.prompts)??null,Tu=gc!==null&&cs.isPending,Is=e===Cm?"demo":"project",tf=Y=>{Bt(Y),so(!1),window.requestAnimationFrame(()=>{const _e=ln.current;_e&&(_e.focus(),_e.setSelectionRange(Y.length,Y.length),Ms(Y.length))})};T.useEffect(()=>{Cn&&(Bt(Y=>Y||Cn),so(!1),Ms(Cn.length))},[Cn]),T.useEffect(()=>{if(S===0)return;const Y=window.requestAnimationFrame(()=>{const _e=ln.current;_e&&(_e.focus(),_e.setSelectionRange(_e.value.length,_e.value.length),_e.scrollIntoView({block:"nearest"}))});return()=>window.cancelAnimationFrame(Y)},[S]);const Ld=T.useId(),rf=e===Cm&&Zt===KN&&!vt,vc=T.useCallback(Y=>{const _e=Y.scrollHeight-Y.scrollTop-Y.clientHeight<60;Qn.current=_e,vo(_e)},[]),Da=T.useCallback(()=>{var Y;Qn.current=!0,vo(!0),(Y=mo.current)==null||Y.call(mo)},[]);T.useEffect(()=>{const Y=Ta.current,_e=Vn.current;if(!Y||!_e)return;const we=new ResizeObserver(()=>{var ye;Qn.current?(ye=mo.current)==null||ye.call(mo):vo(Y.scrollHeight-Y.scrollTop-Y.clientHeight<60)});return we.observe(Y),we.observe(_e),()=>we.disconnect()},[Do]);const ui=T.useCallback(Y=>{Y.currentTarget.blur(),Da()},[Da]);async function _i({queue:Y=!1,starter:_e}={}){var $u,Bd,xl,wl,U0,Gp;const we=(_e??Zt).trim(),ye=!Lo&&_e===void 0?SJn(we,Jt==null?void 0:Jt.planActivation):null;if(ye&&ye.name!=="plan"){Bt(r4(ye.name)?"":ye.prompt),so(!1),ia(ye.name,ye.prompt);return}if(K_||(_e===void 0&&l_({name:"first_action",surface:Is,action:"typed_prompt"}),Na.current))return;const $e=!!ye,Et=!Cu,pt=n4(Jt==null?void 0:Jt.planActivation,$e?Et:void 0,gn.current),ir=$e&&(Ze==null?void 0:Ze.id)==="claude-code"?Et?"plan":"auto":void 0,cr=ye?ye.prompt:we,lr=gr,wo=Lr,Mu=wo.map(nn=>({text:nn.text})),Ou=e,Pd=_;let yc=me;const yn=()=>{const nn=dt.current;return Kr(rt.queryKey)&&nn.projectId===Ou&&nn.activeId===yc&&nn.mainView===Pd},bl=()=>{yn()&&(Bt(nn=>nn||we),jr(nn=>nn.length?nn:lr),Cr(nn=>nn.length?nn:wo))};if($e&&!cr&&lr.length===0&&wo.length===0){Bt(""),so(!1);try{if((Ze==null?void 0:Ze.id)==="claude-code")ol(Et?"plan":"auto");else if((Jt==null?void 0:Jt.planActivation)==="command")await Q_(Et);else throw new Error(G1())}catch{Gt(PE()),bl()}return}const ys=hr?{...hr,...ir?{permissionMode:ir}:{}}:null;ir&&ol(ir);let Up=null;const q0=gn.current;$e&&(Jt==null?void 0:Jt.planActivation)==="command"&&(Up=++Ws.current,gn.current=Et,os(Et));const of=()=>{!yn()||Up===null||Ws.current!==Up||(gn.current=q0,os(q0))};if(!cr&&lr.length===0&&wo.length===0)return;if((cr||wo.length>0)&&Lo&&lr.length===0){Bt(""),Cr([]),St({promptId:Lo,answers:[],note:cr||void 0,annotations:Mu}).then(nn=>{nn||bl()});return}const Hn=JSON.stringify({text:cr,images:lr.map(nn=>({mediaType:nn.mediaType,name:nn.name,dataUrl:nn.dataUrl})),annotations:Mu,settings:ys?{model:ys.model,serviceTier:ys.serviceTier,permissionMode:ys.permissionMode,planMode:pt,reasoningLevel:ys.reasoningLevel}:null}),yl=(($u=na.current)==null?void 0:$u.signature)===Hn?na.current.id:`ct_${crypto.randomUUID()}`;if(na.current={signature:Hn,id:yl},yr){if(!me||!(Ze!=null&&Ze.agentReady)){of();return}const nn=me;Bt(""),jr([]),Cr([]),sn(null),zr(null);const xc=ys?{model:ys.model,serviceTier:ys.serviceTier,permissionMode:ys.permissionMode,planMode:(Jt==null?void 0:Jt.planActivation)==="command"?pt??(lt==null?void 0:lt.planMode):pt,reasoningLevel:ys.reasoningLevel}:{};yn()&&as({});const Uo=lr.map(us=>({mediaType:us.mediaType,dataBase64:us.dataUrl.slice(us.dataUrl.indexOf(",")+1),name:us.name}));try{(Bd=(await Xs(()=>N3(nn,cr,xc,Uo.length?Uo:void 0,Mu,yl,hl&&!Y&&!$e?"steer":void 0))).turn)!=null&&Bd.existing&&await ms(nn),yn()&&to(Dm),((xl=na.current)==null?void 0:xl.id)===yl&&(na.current=null)}catch{of(),bl()}return}if(!(Ze!=null&&Ze.agentReady)){of();return}if(!ys){of();return}let ko=me;try{Bt(Nn=>Nn===Zt?"":Nn),jr(Nn=>Nn===lr?[]:Nn),Cr(Nn=>Nn===wo?[]:Nn),sn(null),zr(null),Na.current=!0;try{if(!ko){const jl=await io(ys,pt);ko=jl.id,yc=jl.id}if(!Kr(rt.queryKey))return;const Nn=Hc(ko);await Xe.fetchQuery({...Nn,...((wl=Xe.getQueryState(Nn.queryKey))==null?void 0:wl.fetchStatus)==="fetching"?{staleTime:0}:{}})}finally{Na.current=!1}if(!Kr(rt.queryKey))return;dr({type:"optimisticUser",sessionId:ko,text:cr||f6e(),attachments:lr.map(Nn=>({url:Nn.dataUrl,mediaType:Nn.mediaType,name:Nn.name})),annotations:wo}),dr({type:"busy",sessionId:ko,busy:!0}),yn()&&Da(),yn()&&Ce==="archived"&&Fe("active");const nn=ys?{model:ys.model,serviceTier:ys.serviceTier,permissionMode:ys.permissionMode,planMode:pt,reasoningLevel:ys.reasoningLevel}:{};yn()&&as({});const xc=lr.map(Nn=>({mediaType:Nn.mediaType,dataBase64:Nn.dataUrl.slice(Nn.dataUrl.indexOf(",")+1),name:Nn.name})),Uo=ko;if(!Uo)throw new Error(BQe());(U0=(await Xs(()=>N3(Uo,cr,nn,xc.length?xc:void 0,Mu,yl))).turn)!=null&&U0.existing&&await ms(Uo),yn()&&to(Dm),((Gp=na.current)==null?void 0:Gp.id)===yl&&(na.current=null)}catch(nn){if(!Kr(rt.queryKey)||(bl(),of(),!ko))return;const xc=nn instanceof Error?nn.message:String(nn);if(!/session is busy/i.test(xc)&&await Xe.fetchQuery({...Ao(e),staleTime:0}).then(us=>{var kl;return!!((kl=us.find(Nn=>Nn.id===ko))!=null&&kl.busy)}).catch(()=>!1)){yn()&&(Bt(us=>us===cr?"":us),jr(us=>us===lr?[]:us),Cr(us=>us===wo?[]:us));return}dr({type:"busy",sessionId:ko,busy:!1}),dr({type:"localError",sessionId:ko,text:Jze({error:Te(xc)})})}}async function io(Y,_e){const we=dt.current,ye=Ke.current,$e=await D.mutateAsync([e,Y.harness,{model:Y.model,serviceTier:Y.serviceTier,permissionMode:Y.permissionMode,planMode:_e,reasoningLevel:Y.reasoningLevel,autonomy:R}]);return Ke.current===ye&&(tr(Et=>[$e,...Et.filter(pt=>pt.id!==$e.id)]),Xe.getQueryData(rt.queryKey)||li(!0)),Ke.current===ye&&dt.current===we&&(Ht.current($e.id,{replace:!0}),dt.current={...we,activeId:$e.id}),$e}function bc(){const Y=XJn(Zt);Bt(Y),window.requestAnimationFrame(()=>{var _e,we;(_e=ln.current)==null||_e.focus(),(we=ln.current)==null||we.setSelectionRange(Y.length,Y.length),Ms(Y.length)})}async function co(){const Y=lc;if(!Y)return;if(Gt(null),yr){Gt(Z6e());return}const _e=Zt,we=dt.current;let ye=me;const $e=()=>{const cr=dt.current;return cr.projectId===we.projectId&&cr.activeId===ye&&cr.mainView===we.mainView},Et=()=>{$e()&&Bt(cr=>cr||_e)};Bt(""),so(!1);let pt=me;if(!pt){if(!(Ze!=null&&Ze.agentReady)||!hr){Et(),Gt(G1());return}try{const cr=n4(Jt==null?void 0:Jt.planActivation,void 0,gn.current);pt=(await io(hr,cr)).id,ye=pt,$e()&&as({})}catch(cr){Et();const lr=cr instanceof Error?cr.message:String(cr);$e()&&Gt(lE({error:Te(lr)}));return}}$e()&&Ce==="archived"&&Fe("active");const ir=`${Vf}shell-${Date.now()}`;dr({type:"localShell",sessionId:pt,id:ir,command:Y}),$e()&&Da();try{const{message:cr}=await yAn(pt,Y);dr({type:"upsertMessage",sessionId:pt,message:cr})}catch(cr){const lr=cr instanceof Error?cr.message:String(cr);dr({type:"localShell",sessionId:pt,id:ir,command:Y,error:lE({error:Te(lr)})})}}function Ii(){me&&jAn(me).catch(()=>{Gt(CXe())})}const nf=T.useCallback(async(Y,_e)=>{if(!(!me||Vs.current)){Vs.current=!0,Gt(null),Ni(Y);try{const we=gWn({model:eo.model,serviceTier:eo.serviceTier,permissionMode:eo.permissionMode,planMode:eo.planMode,reasoningLevel:eo.reasoningLevel}),ye=me;(await xAn(ye,Y,_e,we)).turn.existing&&await ms(ye),to(Dm)}catch{Gt(aVe())}finally{Vs.current=!1,Ni(null)}}},[me,eo,ms]),pl=T.useCallback((Y,_e)=>{if(!me||yr||!(Ze!=null&&Ze.agentReady))return;const we=me;dr({type:"busy",sessionId:we,busy:!0}),Da(),Xs(()=>wAn(we,Y,_e)).catch(ye=>{dr({type:"busy",sessionId:we,busy:!1});const $e=ye instanceof Error?ye.message:String(ye);dr({type:"localError",sessionId:we,text:CVe({error:Te($e)})})})},[me,yr,Ze==null?void 0:Ze.agentReady,Da,Xs]),ml=T.useCallback(Y=>{if(!me||yr)return;const _e=me,we=Ea.current;dr({type:"activeLeaf",sessionId:_e,leafId:Y}),Xs(()=>kAn(_e,Y)).catch(ye=>{dr({type:"activeLeaf",sessionId:_e,leafId:we});const $e=ye instanceof Error?ye.message:String(ye);dr({type:"localError",sessionId:_e,text:LXe({error:Te($e)})})})},[me,yr,Xs]);function gl(Y){if(!me)return;const _e=me;mAn(_e,Y).then(({removed:we})=>{if(we)return ms(_e)}).catch(()=>Gt(mVe()))}async function Z(Y){if(!me||Bn)return;const _e=me;Gt(null),Fn(Y);try{await gAn(_e,Y),await ms(_e)}catch{Gt(WVe())}finally{Fn(null)}}const fe=T.useRef(!1);T.useEffect(()=>{const Y=_e=>{fe.current=u4(_e.target)};return document.addEventListener("pointerdown",Y,!0),()=>document.removeEventListener("pointerdown",Y,!0)},[]),T.useEffect(()=>{if(!yr||_!=="chat")return;function Y(_e){var ye;_e.key!=="Escape"||_e.defaultPrevented||(_e.target===document.body?fe.current:u4(_e.target))!==$||(_e.preventDefault(),Ii(),(ye=ln.current)==null||ye.focus())}return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[yr,me,_,$]);function ke(Y){Ry(Y),Ot.current.delete(Y),Vr.current===Y&&(Vr.current=null),dt.current.projectId===e&&dt.current.activeId===Y&&dt.current.mainView==="chat"&&(Bt(""),jr([]),Cr([]),Ht.current(null,{replace:!0})),Lt(_e=>{if(!_e.has(Y))return _e;const we=new Set(_e);return we.delete(Y),we}),ro.current.delete(Y)}function Me(Y,_e){const we=Ao(Y.projectId);vi(Xe,we.queryKey,Y.id),ss(we.queryKey,ye=>ye==null?void 0:ye.map($e=>$e.id===Y.id?{...$e,..._e}:$e))}function De(Y,_e){const we=Y.archived;Me(Y,{archived:_e}),q.mutateAsync([Y.id,_e]).catch(()=>{Me(Y,{archived:we})})}function ct(Y,_e){const we=Y.title;Me(Y,{title:_e}),U.mutateAsync([Y.id,_e]).catch(()=>{Me(Y,{title:we})})}async function _t(Y){var we;const _e=((we=Y.title)==null?void 0:we.trim())||Gv();if(window.confirm(w7e({title:Xl(_e)}))){try{await G.mutateAsync(Y.id)}catch(ye){Xt(R7e({title:Xl(_e),error:Te(ye instanceof Error?ye.message:String(ye))}),"error");return}ke(Y.id)}}const St=T.useCallback(Y=>{if(!me)return Promise.resolve(!1);const _e=me;return dr({type:"busy",sessionId:_e,busy:!0}),Xs(()=>SAn(_e,Y)).then(()=>!0).catch(()=>!1).finally(()=>{Kr(rt.queryKey)&&(Xe.fetchQuery({...Hc(_e),staleTime:0}).catch(()=>{}),Xe.fetchQuery({...Ao(e),staleTime:0}).catch(()=>{}))})},[me,e,Xs,rt]),rn=/Mac|iPhone|iPad/.test(navigator.platform),Ys=rn?"⌘ ⇧ ↵":"Ctrl + Shift + ↵",ls=rn?"⌘ Enter":"Ctrl + Enter",bo=T.useCallback(()=>{Fe("active"),C(null)},[C]),Po=T.useCallback(async()=>{try{const _e=(await Xe.fetchQuery({...aA(),staleTime:0})).reduce((we,ye)=>!we||ye.lastActivityAt>we.lastActivityAt?ye:we,void 0);Fe("active"),C(null,{projectId:(_e==null?void 0:_e.projectId)??e})}catch(Y){Xt(Y instanceof Error?Y.message:String(Y),"error")}},[e,C]),vl=T.useCallback(async Y=>{const _e=Ke.current,we=dt.current;try{const ye=await iAn(Y);if(Ke.current!==_e||dt.current!==we)return;Fe("all"),C(Y,{projectId:ye.projectId})}catch(ye){if(Ke.current!==_e||dt.current!==we)return;Xt(ye instanceof Error?ye.message:String(ye),"error")}},[C]);T.useEffect(()=>{if($)return;const Y=_e=>{_e.repeat||_e.key!=="Enter"||!_e.metaKey&&!_e.ctrlKey||_e.altKey||!_e.shiftKey||u4(_e.target)||(_e.preventDefault(),Po())};return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[Po,$]);const Pi=Y=>vr.messagesBySession[Y.id]?Z_.has(Y.id):Y.awaitingInput===!0,Ps=(Y,_e)=>Y.id===e?vr.busySessions.has(_e.id):_e.busy,un=[];if(re==="projects"&&Be.forEach((Y,_e)=>{const we=ot[_e],$e=(Y.id===e?ft:we.data??WM).filter(lr=>!lr.sideParentSessionId&&(cts(Ce,lr.archived)||lr.id===me)).sort((lr,wo)=>wo.updatedAt-lr.updatedAt),Et=Pt[Y.id]??6;let pt=$e.slice(0,Et);const ir=$e.find(lr=>lr.id===me);ir&&!pt.some(lr=>lr.id===me)&&(pt=[...pt.slice(0,Et-1),ir]);const cr=ve.includes(Y.id);un.push({kind:"project",project:Y,collapsed:cr,busy:cr&&$e.some(lr=>Ps(Y,lr)&&!Pi(lr))}),!cr&&(pt.forEach(lr=>un.push({kind:"chat",project:Y,session:lr})),$e.length>Et&&un.push({kind:"more",project:Y}),!pt.length&&(re==="projects"||we.isPending||we.error)&&un.push({kind:"status",project:Y,pending:we.isPending,error:!!we.error,retry:()=>{we.refetch()}}))}),re==="list"){const Y=((qo=We.data)==null?void 0:qo.pages.flatMap(ye=>ye.sessions))??[],_e=ft.find(ye=>ye.id===me);_e&&!Y.some(ye=>ye.id===_e.id)&&Y.push(_e),Y.filter(ye=>!Bc.has(ye.id)).sort((ye,$e)=>$e.updatedAt-ye.updatedAt).forEach(ye=>{const $e=ce.find(Et=>Et.id===ye.projectId);$e&&un.push({kind:"chat",project:$e,session:ye})});const we=je??ce[0];we&&(!un.length||We.isFetchingNextPage||We.isError)&&un.push({kind:"status",project:we,pending:We.isPending||We.isFetchingNextPage,error:We.isError,retry:()=>{We.isFetchNextPageError?We.fetchNextPage():We.refetch()}})}const Bo=re==="list"||Ye,sf=fR(un,ut,me),Ru=sf.lengthY+ag(_e),0),Ho=Y=>Y.kind==="chat"?Y.session.id:`${Y.kind}:${Y.project.id}`,xo=xH({count:un.length,getScrollElement:()=>Ie.current,getItemKey:Y=>Ho(un[Y]),estimateSize:Y=>ag(un[Y]),overscan:5,rangeExtractor:Y=>{const _e=eC(Y),we=un.findIndex(ye=>Ho(ye)===Ut);return we<0||_e.includes(we)?_e:[..._e,we].sort((ye,$e)=>ye-$e)},enabled:Bo&&a&&!$}),fi=xo.getVirtualItems(),Bp=((Id=fi.at(-1))==null?void 0:Id.index)??-1;T.useEffect(()=>{re==="list"&&a&&!$&&Bp>=un.length-6&&We.hasNextPage&&!We.isFetching&&!We.isError&&We.fetchNextPage()},[re,a,$,Bp,un.length,We.hasNextPage,We.isFetching,We.isError,We.fetchNextPage]);const Dd=u.jsxs("aside",{className:"session-rail w-75 shrink-0 flex flex-col mt-5 mac-titlebar:mt-8 me-3.5 mb-5 ms-0 bg-background min-h-0 [&_.rail-body]:flex-1 [&_.rail-body]:min-h-0 [&_.rail-body]:pt-0 [&_.rail-body]:pb-0 [&_.rail-body]:ps-2 [&_.rail-body]:pe-1 border border-border rounded-lg overflow-visible shadow-elevated",children:[o,u.jsxs("nav",{className:"rail-nav flex flex-col gap-0.5 p-2 shrink-0",children:[u.jsxs("button",{className:"rail-nav-item flex items-center gap-2.5 py-[7px] px-2.5 text-base text-text rounded-md text-start hover:bg-surface [&[data-tip]::after]:top-auto [&[data-tip]::after]:bottom-[calc(100%_+_6px)]","data-onboarding":"new-session","data-tip":Ys,"aria-keyshortcuts":"Meta+Shift+Enter Control+Shift+Enter",onClick:Po,children:[u.jsx(du,{size:15}),a3()]}),u.jsxs("button",{className:`rail-nav-item flex items-center gap-2.5 py-[7px] px-2.5 text-base text-text rounded-md text-start [&:hover:not(.active)]:bg-surface [&.active]:bg-panel [&.active]:font-medium ${_==="skills"?"active":""}`,onClick:()=>d("skills"),children:[u.jsx(kP,{size:15}),DMe()]}),mJn.map(Y=>u.jsxs("button",{className:`rail-nav-item flex items-center gap-2.5 py-[7px] px-2.5 text-base text-text rounded-md text-start [&:hover:not(.active)]:bg-surface [&.active]:bg-panel [&.active]:font-medium ${_!=="chat"&&_!=="skills"&&Y.activeTabs.includes(_)?"active":""}`,"data-onboarding":Y.id==="compute"?"nav-compute":void 0,onClick:()=>d(Y.id),children:[Y.icon,Y.label()]},Y.id))]}),u.jsxs("div",{className:"rail-section-head flex items-center justify-between shrink-0 pt-3.5 pe-2.5 pb-0 ps-4.5",children:[u.jsx("div",{className:"rail-section-label p-0 text-sm font-medium text-subtext",children:re==="projects"?dS():eD()}),u.jsxs("div",{className:"rail-section-actions flex items-center gap-0.5",children:[c&&u.jsx(Va,{interactive:!0,content:Cb(),className:"rounded-sm",children:u.jsx(kt,{size:"small",className:"text-subtext","aria-label":Cb(),onClick:c,children:u.jsx(cOn,{size:15,className:"text-subtext"})})}),u.jsx(uts,{value:Ce,onChange:Fe,grouping:re,onGroupingChange:Y=>{W(Y);try{localStorage.setItem("sidebar-grouping",Y)}catch{}Oe(!1),mt({}),Ie.current&&(Ie.current.scrollTop=0)}})]})]}),u.jsxs("div",{className:"relative flex-1 min-h-0",children:[u.jsx("div",{ref:Ie,tabIndex:-1,className:`rail-body h-full overflow-x-hidden ${Bo?"overflow-y-auto":"overflow-y-hidden"}`,children:u.jsxs("div",{className:"relative",style:{height:(Bo?xo.getTotalSize():Bi)+(yo?38:0)+(Ye?46:0)},children:[(Bo?fi.map(Y=>({row:un[Y.index],top:Y.start,index:Y.index})):Fo.map((Y,_e)=>({row:Y,top:0,index:_e}))).map(({row:Y,top:_e,index:we})=>{var Et;const ye=Y.project,$e=Y.kind==="chat"?Y.session:null;return u.jsx("div",{"data-index":we,onFocusCapture:()=>Wt(Ho(Y)),onBlurCapture:pt=>{pt.currentTarget.contains(pt.relatedTarget)||Wt(null)},className:Bo?"absolute top-0 start-0 w-full":"relative",style:{height:ag(Y),transform:Bo?`translateY(${_e}px)`:void 0},children:Y.kind==="project"?u.jsx("div",{className:"group h-9 flex items-end gap-1 rounded-md px-2.5 text-text",children:u.jsx(LGn,{project:ye,chatCount:(Et=ue.find(pt=>pt.projectId===ye.id))==null?void 0:Et.totalAgents,collapsed:Y.collapsed,busy:Y.busy,onToggleCollapsed:()=>{const pt=ve.includes(ye.id)?ve.filter(ir=>ir!==ye.id):[...ve,ye.id];xe(pt);try{localStorage.setItem("sidebar-collapsed-projects",JSON.stringify(pt))}catch{}},pinned:ae.includes(ye.id),onPin:()=>{const pt=ae.includes(ye.id)?ae.filter(ir=>ir!==ye.id):[...ae,ye.id];ie(pt);try{localStorage.setItem("sidebar-pinned-projects",JSON.stringify(pt))}catch{}},onRemoved:()=>{ye.id===e&&oe({to:"/projects"})},onNewChat:()=>{ye.id===e?bo():oe({to:"/projects/$projectId/tasks/new",params:{projectId:ye.id}})}})}):$e?u.jsx("div",{className:re==="projects"?"ms-5.5":void 0,children:u.jsx(hts,{session:$e,active:$e.id===me&&_==="chat",unread:or.has($e.id),busy:Ps(ye,$e),waiting:Pi($e),revealTitle:oi.get($e.id),onOpen:()=>{if(ye.id===e?C($e.id):oe({to:"/projects/$projectId/tasks/$sessionId",params:{projectId:ye.id,sessionId:$e.id}}),ye.id===Cm){uLn($e.id);const pt=I9n[$e.id];pt&&(l_({name:"demo_experiment_started",kind:"curated",experiment:pt}),l_({name:"first_action",surface:"demo",action:"open_experiment"}))}},onRename:pt=>ct($e,pt),onSetArchived:pt=>De($e,pt),onDelete:()=>void _t($e)},$e.id)}):Y.kind==="more"?u.jsx(Ee,{variant:"ghost",size:"small",className:"ms-5.5 font-normal text-subtext",onClick:()=>{Oe(!0),mt(pt=>({...pt,[ye.id]:(pt[ye.id]??6)+6}))},children:c3()}):Y.kind==="status"&&u.jsx("div",{className:`flex h-full items-center px-2.5 text-sm text-subtext ${re==="projects"?"ms-5.5":""}`,children:Y.error?u.jsx(Ee,{size:"small",onClick:Y.retry,children:rs()}):Y.pending?u.jsx(Rt,{}):Ce==="archived"?P9e():Q9e()})},Ho(Y))}),yo&&u.jsx("div",{className:"absolute start-0 flex h-9.5 w-full items-center pt-1",style:{top:Bo?xo.getTotalSize():Bi},children:u.jsx(Ee,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{Oe(!0)},children:c3()})}),Ye&&u.jsx("div",{className:"absolute start-0 w-full pt-1",style:{top:xo.getTotalSize()+(yo?38:0)},children:u.jsx(Ee,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{Oe(!1),mt({}),Wt(null),Ie.current&&(Ie.current.scrollTop=0,Ie.current.focus())},children:My()})})]})}),Bo&&u.jsxs(u.Fragment,{children:[(xo.scrollOffset??0)>0&&u.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-5 h-3 bg-linear-to-b from-background to-transparent"}),u.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-5 h-3 bg-linear-to-t from-background to-transparent"})]})]}),u.jsx(GB,{runtime:b})]}),Fp="chat-header flex items-center gap-2 py-0 px-4 bg-background shrink-0 h-12 relative z-4 w-full max-w-readable my-0 mx-auto [&::after]:content-[''] [&::after]:absolute [&::after]:top-full [&::after]:start-0 [&::after]:end-0 [&::after]:h-6 [&::after]:bg-[linear-gradient(to_bottom,_var(--base),_transparent)] [&::after]:pointer-events-none",Hp=!a&&!$&&u.jsx(kt,{title:OE(),"aria-label":OE(),onClick:i,className:"mac-titlebar:ms-16",children:u.jsx(LP,{size:20})});return _!=="chat"?u.jsxs(u.Fragment,{children:[a&&Dd,u.jsxs("section",{className:"chat-pane flex-1 min-w-0 flex flex-col bg-background min-h-0",children:[!a&&u.jsx("div",{className:"flex h-12 shrink-0 items-center",children:Hp}),u.jsx("div",{className:"settings-view-scroll flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",children:n?u.jsxs("div",{role:"alert",className:"p-6 text-subtext",children:[n,u.jsx(Ee,{onClick:s,children:rs()})]}):t?u.jsxs(ds,{className:"p-6",children:[u.jsx(Rt,{}),CE()]}):B})]})]}):u.jsxs(u.Fragment,{children:[a&&Dd,u.jsxs("section",{"data-side-chat":$||void 0,className:`chat-pane flex-1 min-w-0 flex flex-col bg-background min-h-0 ${$?"":"mt-5"}`,children:[u.jsxs("div",{className:a||$?"contents":"grid shrink-0 grid-cols-[2rem_minmax(0,1fr)_2rem] mac-titlebar:grid-cols-[6rem_minmax(0,1fr)_6rem] items-center",children:[Hp,u.jsxs("div",{className:Fp,children:[u.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:tn&&u.jsxs(u.Fragment,{children:[(Hi=tn.title)!=null&&Hi.trim()?u.jsx(zg,{variant:"header",className:"flex-initial",title:tn.title.trim(),children:u.jsx(JU,{title:tn.title.trim(),animate:J_!==void 0},J_??"static")}):yr?u.jsx(Rt,{}):null,u.jsx("span",{className:"min-w-0 truncate rounded-md border border-border bg-surface px-2.5 py-0.5 text-sm font-normal text-subtext",title:r,children:r})]})}),y&&u.jsx(kt,{"data-tip":fE(),"aria-label":fE(),onClick:y,children:u.jsx(CP,{size:15})})]})]}),n?u.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[u.jsx("p",{children:n}),u.jsx(Ee,{onClick:s,children:rs()})]}):Io?u.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[u.jsx("p",{children:Io.message}),u.jsx(Ee,{onClick:()=>void qr.refetch(),children:rs()})]}):t||Nu?u.jsx("div",{className:"chat-loading flex-1 min-h-0 overflow-hidden [scrollbar-gutter:stable_both-edges]",role:"status","aria-label":CE(),"aria-busy":"true",children:u.jsxs("div",{"aria-hidden":"true",className:"mx-auto flex h-full w-full max-w-readable flex-col gap-6 px-4 pb-8 pt-4 motion-safe:animate-pulse",children:[u.jsx("div",{className:"ms-auto h-14 w-3/5 shrink-0 rounded-lg bg-panel"}),u.jsx("div",{className:"flex shrink-0 flex-col gap-3",children:["w-5/6","w-full","w-11/12","w-2/3","w-full","w-3/4","w-1/2"].map((Y,_e)=>u.jsx("div",{className:`h-3 rounded bg-panel ${Y}`},_e))}),u.jsx("div",{className:"ms-auto h-10 w-2/5 shrink-0 rounded-lg bg-panel"}),u.jsx("div",{className:"flex shrink-0 flex-col gap-3",children:["w-full","w-11/12","w-3/4","w-5/6","w-1/2","w-full","w-5/6","w-11/12","w-2/3","w-3/4","w-1/3"].map((Y,_e)=>u.jsx("div",{className:`h-3 rounded bg-panel ${Y}`},_e))}),u.jsx("div",{className:"ms-auto h-16 w-1/2 shrink-0 rounded-lg bg-panel"})]})}):!Do&&(tn!=null&&tn.sideParentSessionId)?u.jsxs("div",{className:"chat-empty flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center text-subtext",children:[u.jsx(kg,{size:22}),u.jsx("p",{className:"m-0 text-balance",children:mcn()})]}):Do?u.jsx("div",{className:"chat-thread flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",ref:Ta,tabIndex:0,role:"region","aria-label":((qp=tn==null?void 0:tn.title)==null?void 0:qp.trim())||Gv(),onScroll:Y=>{vc(Y.currentTarget),Ra.dismiss()},children:u.jsxs("div",{className:"chat-thread-inner max-w-readable my-0 mx-auto pt-4 px-4 pb-8 flex flex-col gap-4",ref:Vn,children:[u.jsx(mU,{projectId:e,sessionId:me,children:u.jsx(its,{scrollRef:Ta,scrollToEndRef:mo,stickToBottom:Qn,onPinToBottom:Da,messages:gs,allMessages:hc,canFork:ll,onFork:pl,onSelectFork:ml,busy:yr,onOpenFile:ca,onOpenRun:p,onOpenSpawnedSession:vl,runExperimentName:m,onOpenExperiment:x,experimentName:k,onRespond:St,onOpenPlan:Oa,onOpenSubagent:vs,recoveringTurnId:As,onRecover:nf,skills:$d},me)}),yr&&Au&&u.jsx("div",{className:"flex items-center gap-2 text-subtext text-sm pt-0.5 px-0 pb-2 italic",children:aD()}),yr&&!Au&&!ul&&!Md&&u.jsx("div",{className:"text-base pt-0.5 px-1 pb-2",children:u.jsx("span",{className:"tool-running-shimmer",children:rYe()})})]})}):u.jsxs("div",{className:"chat-empty flex-1 flex flex-col items-center justify-center text-text p-8 text-center [&_h2]:m-0 [&_h2]:text-5xl [&_h2]:font-medium [&_h2]:tracking-[-0.015em] [&_h2]:text-text",children:[u.jsx("div",{className:"chat-empty-mark w-10.5 h-10.5 mb-5.5 [&_svg]:block [&_svg]:w-full [&_svg]:h-full",children:u.jsx(Ky,{})}),u.jsx("h2",{children:vWe()}),Tu&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:YM,"aria-hidden":"true",children:XM.map((Y,_e)=>u.jsxs("div",{className:`flex min-h-22 animate-pulse flex-col items-start justify-center gap-2.5 rounded-xl border bg-background px-5 py-4 ${_4[_e].box}`,children:[u.jsxs("span",{className:`flex w-full items-center gap-2.5 ${_4[_e].icon}`,children:[u.jsx(Y,{size:17}),u.jsx("span",{className:"h-3.5 w-2/5 rounded bg-panel"})]}),u.jsx("span",{className:"h-3 w-4/5 rounded bg-panel"})]},_e))}),u.jsxs(ds,{className:"mt-3",role:"status",children:[u.jsx(Rt,{}),u.jsx("span",{children:NUe()})]})]}),La&&La.length>0&&u.jsx("div",{className:YM,role:"group","aria-label":PUe(),children:La.map((Y,_e)=>{const we=XM[_e],ye=_4[_e],$e=Et=>{l_({name:"project_starter_clicked",slot:_e+1}),l_({name:"first_action",surface:Is,action:"starter_click"});const pt=!Zt.trim()&&gr.length===0&&Lr.length===0;Et||!(Ze!=null&&Ze.agentReady)||!pt?tf(Y.prompt):_i({starter:Y.prompt})};return u.jsxs("div",{className:"relative min-w-0",children:[u.jsxs("button",{type:"button",className:`flex h-full min-h-22 w-full min-w-0 cursor-pointer flex-col items-start justify-center gap-1.5 rounded-xl border bg-background py-4 ps-5 pe-11 text-start font-sans transition-colors duration-120 ease-standard hover:bg-surface ${ye.box}`,onClick:()=>$e(!1),children:[u.jsxs("span",{className:"flex items-center gap-2.5 text-base font-medium text-text",children:[u.jsx(we,{size:17,className:ye.icon}),Y.title]}),u.jsx("span",{className:"w-full truncate text-sm text-subtext",children:Y.prompt})]}),u.jsx(kt,{size:"small",className:"absolute end-2.5 top-2.5 [&:hover:not(:disabled)]:bg-surface-bright","aria-label":$E({title:Y.title}),title:$E({title:Y.title}),onClick:()=>$e(!0),children:u.jsx(Hy,{size:13})})]},_e)})})]}),Ra.action&&u.jsxs(Ee,{type:"button",size:"small",className:"chat-selection-action fixed z-50 shadow-control",style:{left:Ra.action.x,top:Ra.action.top,transform:"translateX(-50%)"},onMouseDown:Y=>Y.preventDefault(),onClick:Ra.add,children:[u.jsx(OP,{size:14}),SAe()]}),u.jsxs("div",{inert:t||!!n||Nu,className:"composer px-3 pb-5 shrink-0 relative z-4 bg-background w-full max-w-readable my-0 mx-auto [&_textarea]:border-0 [&_textarea]:bg-none [&_textarea]:bg-transparent [&_textarea]:resize-none [&_textarea]:pt-2.5 [&_textarea]:px-3 [&_textarea]:pb-1 [&_textarea]:text-base [&_textarea]:field-sizing-content [&_textarea]:min-h-18 [&_textarea]:max-h-45",children:[Do&&u.jsx(kt,{className:`absolute bottom-full left-1/2 z-5 mb-6 h-9 w-9 -translate-x-1/2 rounded-full border border-border bg-background shadow-control transition-opacity duration-150 ease-standard ${go?"opacity-0":"opacity-100"}`,title:IE(),"aria-label":IE(),inert:go,onClick:ui,children:yr&&!Au?u.jsx(Sp,{size:18,className:"tool-running-shimmer-icon"}):u.jsx(vMn,{size:16})}),ao&&!(dl&&ao.promptId===dl.promptId)&&u.jsx(wZn,{synthesized:ao.synthesized,agentLabel:tn?Af(tn.harness,tn.harnessName):WXe(),showResumeModes:(tn==null?void 0:tn.harness)==="claude-code",onView:Y=>Oa==null?void 0:Oa(ao.plan,ao.promptId,Y),onApprove:Y=>St({promptId:ao.promptId,approve:!0,...Y?{resumeMode:Y}:{}}),onReject:()=>St({promptId:ao.promptId,approve:!1}),onRevise:Y=>{me&&Ur({sessionId:me,promptId:ao.promptId}),St({promptId:ao.promptId,approve:!1,note:Y})}}),$o.length>0&&u.jsx("div",{className:"composer-queued flex flex-col gap-1 mb-1.5",children:$o.map((Y,_e)=>u.jsxs("div",{className:"queued-chip flex flex-wrap items-center gap-x-2 gap-y-1 py-1.5 px-2.5 text-sm text-subtext bg-background border border-border rounded-sm",title:Y.error?`${Y.text} +`),i=n?XL():s&&o!==null?cCe({code:mr(o)}):null;return u.jsx("div",{className:"msg-shell ms-auto self-end flex w-full max-w-[88%] flex-col items-stretch gap-1.5",children:u.jsxs("div",{dir:"ltr",className:"max-w-full bg-panel rounded-[16px] py-2.5 px-[15px] text-base",children:[u.jsxs("div",{className:"flex items-start gap-2 font-mono text-sm text-text whitespace-pre-wrap wrap-anywhere",children:[u.jsxs("span",{className:"sr-only",children:[tD()," "]}),u.jsx(R_,{size:16,strokeWidth:1.6,className:`mt-0.5 shrink-0 ${s?"text-accent-red":"text-muted"}`,"aria-hidden":"true"}),u.jsx("span",{children:t})]}),a&&u.jsx("div",{className:`${NC} mt-2`,children:a.slice(0,2e4)}),i&&u.jsx("div",{className:`mt-1.5 text-xs ${s?"text-accent-red":"text-muted"}`,children:i})]})})}function sb(e,r){var b,y;const{activePermissionId:t,pendingTailToolId:n,onOpenFile:s,onOpenRun:o,onOpenSpawnedSession:a,runExperimentName:i,onOpenExperiment:c,experimentName:_,onRespond:d,onOpenPlan:f,onOpenSubagent:p,predictTextTail:m=!1}=r,x=e.filter(S=>S.type!=="steer"&&up(S,t)).at(-1),k=[];let v=[];const w=()=>{v.length!==0&&(k.push(u.jsx(Ges,{parts:v,pendingTail:v.some(S=>S.id===n),onOpenFile:s,onOpenRun:o,onOpenSpawnedSession:a,runExperimentName:i,onOpenExperiment:c,experimentName:_},`tg-${v[0].id}`)),v=[])};for(const S of e)if(up(S,t)){if(S.type==="tool"&&S.tool==="api_error"){w(),k.push(u.jsx(RC,{part:S,busy:!1,recovering:!1,temporaryApiError:!0},S.id));continue}if(S.type==="tool"&&(rts(S.tool)||(((b=S.children)==null?void 0:b.length)??0)>0)){w(),k.push(u.jsx(sts,{part:S,pendingTail:m&&((y=S.state)==null?void 0:y.status)==="running"||S.id===n,onOpenSubagent:p},S.id));continue}if(S.type==="tool"){v.push(S);continue}w(),S.type==="text"?k.push(u.jsx(Wc,{text:S.text,onOpenFile:s,onOpenRun:o,predict:m&&S.id===(x==null?void 0:x.id)},S.id)):S.type==="steer"?k.push(u.jsx("div",{dir:"auto",role:"note","aria-label":EWe(),className:"msg-steer my-2 ms-auto w-fit max-w-[88%] bg-panel rounded-[16px] py-2.5 px-[15px] text-base whitespace-pre-wrap wrap-anywhere",children:S.text},S.id)):S.type==="prompt"&&S.prompt&&k.push(u.jsx(Wes,{part:S,onRespond:d,onOpenFile:s,onOpenPlan:f},S.id))}return w(),k}function tts(e){return ud(e).label}function rts(e){const r=(e??"").toLowerCase();return r==="subagent"||r==="task"||r==="agent"}function ZU(e){var t,n;const r=((t=e.state)==null?void 0:t.status)==="completed"?((n=e.state)==null?void 0:n.output)??"":"";return r.startsWith("Async agent launched")?"":r}function ly(e,r){for(const t of e){if(t.id===r)return t;const n=t.children&&ly(t.children,r);if(n)return n}return null}function nts({spawn:e,onOpenFile:r,onOpenRun:t,runExperimentName:n,onOpenExperiment:s,experimentName:o,onOpenSubagent:a}){var x,k,v,w;const i=e.children??[],c=((x=e.state)==null?void 0:x.status)==="running",_=((k=e.state)==null?void 0:k.status)==="error",d=_?Dx(((v=e.state)==null?void 0:v.error)||((w=e.state)==null?void 0:w.output)||""):"",f=sb(i,{onOpenFile:r,onOpenRun:t,runExperimentName:n,onOpenExperiment:s,experimentName:o,onOpenSubagent:a,predictTextTail:c,pendingTailToolId:c?wH(i):null}),m=i.some(b=>b.type==="text"&&!!b.text)?"":ZU(e);return u.jsxs("div",{className:"msg-assistant text-base leading-[1.62] text-text min-w-0",children:[_&&u.jsxs("span",{className:"sr-only",children:[nS()," "]}),d&&u.jsx("div",{className:NC,children:d.slice(0,2e4)}),f.length===0&&!m&&!d?u.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:c?sS():N9e()}):u.jsxs(u.Fragment,{children:[f,m&&u.jsx(Wc,{text:m,onOpenFile:r,onOpenRun:t})]})]})}function sts({part:e,pendingTail:r,onOpenSubagent:t}){var _,d,f,p;const n=((_=e.state)==null?void 0:_.status)==="error",s=Dx(((d=e.state)==null?void 0:d.error)||((f=e.state)==null?void 0:f.output)||""),o=r&&!n?TC(ud(e)):ud(e),a=YU(!!(r&&!n)),i=(((p=e.children)==null?void 0:p.length)??0)===0&&!n&&!ZU(e),c=u.jsxs(u.Fragment,{children:[n&&u.jsxs("span",{className:"sr-only",children:[nS()," "]}),n?u.jsx("span",{className:"flex h-6 shrink-0 items-center text-accent-red",children:u.jsx(EP,{size:16,strokeWidth:1.75,className:"subagent-icon","aria-hidden":"true"})}):u.jsx(cy,{activity:o,className:`subagent-icon ${a?"tool-running-shimmer-icon":"text-muted"}`}),u.jsx("span",{className:`${PU} ${a?"tool-running-shimmer":n?"text-accent-red":"text-subtext"}`,children:o.label})]});return i?u.jsx("div",{className:"subagent-row flex items-start gap-2 w-full my-3.5 mx-0 py-[3px] px-1 text-text text-base text-start rounded-sm",children:c}):u.jsxs("button",{className:"subagent-row flex items-start gap-2 w-full my-3.5 mx-0 py-[3px] px-1 cursor-pointer text-text text-base text-start rounded-sm [&:hover:not(:disabled)]:bg-surface [&:disabled]:cursor-default",title:n&&s?s:GEe(),...$n(m=>t==null?void 0:t(e.id,o.label,m)),disabled:!t,children:[c,u.jsx("span",{className:"subagent-row-chevron flex h-6 shrink-0 items-center text-muted",children:u.jsx(Ca,{size:12})})]})}function ots(e){const r=new Map;let t;for(let s=e.length-1;s>=0;s--)if(e[s].role==="assistant"){t=e[s];break}if(!t)return{messageId:"",states:r};const n=(s,o)=>{var a,i;for(const c of s){const _=`${o}/${c.id}`;c.type==="tool"&&((a=c.state)!=null&&a.status)&&r.set(_,{status:c.state.status,part:c}),(i=c.children)!=null&&i.length&&n(c.children,_)}};return n(t.parts,t.id),{messageId:t.id,states:r}}function OC(e){const r=(t,n)=>{var s;for(const o of t){const a=o.prompt;if(o.type==="prompt"&&(a==null?void 0:a.kind)==="permission"&&!a.resolved){const i=a.toolInput??{},_=Eo(i,"reason","description")||XU(a.tool,i);return{id:o.id,path:`${n}/${o.id}`,label:_}}if((s=o.children)!=null&&s.length){const i=r(o.children,`${n}/${o.id}`);if(i)return i}}return null};for(const t of e){if(t.role!=="assistant")continue;const n=r(t.parts,t.id);if(n)return n}return null}function ats(e){const[r,t]=T.useState({text:"",sequence:0}),n=T.useRef(null);return T.useEffect(()=>{var x,k,v,w,b;const s=((x=e[0])==null?void 0:x.id)??"",{messageId:o,states:a}=ots(e),i=OC(e);if(!n.current||n.current.transcript!==s){n.current={transcript:s,messageId:o,states:a,permissionPath:(i==null?void 0:i.path)??null},t(y=>({text:i?tE({label:Xl(i.label)}):"",sequence:y.sequence+1}));return}const c=n.current.messageId===o?n.current.states:new Map,_=n.current.permissionPath,d=[...a].filter(([y,S])=>{var E;return((E=c.get(y))==null?void 0:E.status)!==S.status});if(n.current={transcript:s,messageId:o,states:a,permissionPath:(i==null?void 0:i.path)??null},i&&i.path!==_){t(y=>({text:tE({label:Xl(i.label)}),sequence:y.sequence+1}));return}const f=(k=d.find(([,y])=>M0(y.part)))==null?void 0:k[1].part;if((f==null?void 0:f.id)==="turn-recovery"){const y=EH((w=(v=f.state)==null?void 0:v.input)==null?void 0:w.recoveryAction);t(S=>({text:`${Zbe()}${y?` ${y==="retry"?rbe():Wve()}`:""}`,sequence:S.sequence+1}));return}if((f==null?void 0:f.id)==="turn-retry"){t(y=>({text:Lve(),sequence:y.sequence+1}));return}const p=d.filter(([,y])=>y.status==="error");if(p.length>0){const y=p.slice(0,2).map(([,S])=>ud(S.part).label).join(", ");t(S=>({text:p.length===1?Rbe({labels:y}):Hbe({count:mr(p.length),labels:y}),sequence:S.sequence+1}));return}const m=d.filter(([,y])=>y.status==="running");if(m.length>0){const y=(b=m.at(-1))==null?void 0:b[1].part;t(S=>({text:y?TC(ud(y)).label:fbe(),sequence:S.sequence+1}));return}d.some(([,y])=>y.status==="completed")&&t(y=>({text:wbe(),sequence:y.sequence+1}))},[e]),r}const its=T.memo(function({messages:r,scrollRef:t,scrollToEndRef:n,stickToBottom:s,onPinToBottom:o,allMessages:a,canFork:i,onFork:c,onSelectFork:_,busy:d,onOpenFile:f,onOpenRun:p,onOpenSpawnedSession:m,runExperimentName:x,onOpenExperiment:k,experimentName:v,onRespond:w,onOpenPlan:b,onOpenSubagent:y,recoveringTurnId:S,onRecover:E,skills:C}){var P,D,q;fu();const A=((P=OC(r))==null?void 0:P.id)??null,N=T.useMemo(()=>r.filter(U=>Kes(U,A)),[r,A]),R=T.useMemo(()=>{const U=N.filter(G=>G.role==="user"&&!G.id.startsWith(Vf));return aWn(a,r,U,G=>G.startsWith(Vf))},[r,N,a]),L=T.useRef(new Set),[$,I]=T.useState(!1),F=T.useCallback(U=>N[U].id,[N]),B=T.useCallback(U=>{if($)return N.map((oe,ce)=>ce);const G=new Set(eC(U));return N.forEach((oe,ce)=>{L.current.has(oe.id)&&G.add(ce)}),[...G].sort((oe,ce)=>oe-ce)},[N,$]),V=xH({count:N.length,useFlushSync:!1,getScrollElement:()=>t.current,getItemKey:F,estimateSize:()=>400,overscan:1,initialRect:{width:((D=t.current)==null?void 0:D.clientWidth)??0,height:((q=t.current)==null?void 0:q.clientHeight)??0},initialOffset:()=>{var U;return Math.max(0,N.length*400-(((U=t.current)==null?void 0:U.clientHeight)??0))},anchorTo:s.current?"end":"start",followOnAppend:!0,scrollEndThreshold:60,rangeExtractor:B});T.useLayoutEffect(()=>{const U=()=>V.scrollToEnd();return n.current=U,o(),()=>{n.current=null}},[V,n,o]),T.useEffect(()=>{const U=()=>{var ce;const G=window.getSelection();if(!G||G.isCollapsed||!G.rangeCount)return;const oe=G.getRangeAt(0);for(const ue of((ce=t.current)==null?void 0:ce.querySelectorAll("[data-message-id]"))??[])oe.intersectsNode(ue)&&ue.dataset.messageId&&L.current.add(ue.dataset.messageId)};return document.addEventListener("selectionchange",U),()=>document.removeEventListener("selectionchange",U)},[t]);const K=N.at(-1),ee=ats(r),J=d?kH(r):null;return u.jsxs(u.Fragment,{children:[u.jsx("span",{className:"sr-only",role:"status","aria-live":"polite",children:u.jsx("span",{children:ee.text},ee.sequence)}),u.jsx("button",{type:"button",className:"sr-only focus:not-sr-only","aria-pressed":$,onClick:()=>I(U=>!U),children:XQe()}),u.jsx("div",{className:"relative",style:{height:V.getTotalSize()},children:V.getVirtualItems().map(U=>{var re,W,ae,ie,ve,xe;const G=N[U.index],oe=G.parts.find(M0),ce=(W=(re=oe==null?void 0:oe.state)==null?void 0:re.input)==null?void 0:W.turnId,ue=oe?d||S!==null:!1;return u.jsx("div",{"data-index":U.index,"data-message-id":G.id,ref:V.measureElement,className:"absolute left-0 w-full pb-4",style:{top:U.start},onClickCapture:Ce=>{!(Ce.target instanceof Element)||!Ce.target.closest("[data-work-toggle]")||(s.current=!1,V.setOptions({...V.options,anchorTo:"start"}))},onPointerDownCapture:()=>L.current.add(G.id),onFocusCapture:()=>L.current.add(G.id),children:u.jsx(Yes,{message:G,forkCount:(ae=R.get(G.id))==null?void 0:ae.count,forkIndex:(ie=R.get(G.id))==null?void 0:ie.index,forkPrevId:(ve=R.get(G.id))==null?void 0:ve.prevId,forkNextId:(xe=R.get(G.id))==null?void 0:xe.nextId,forkDisabled:!i,branchDisabled:d,onFork:c,onSelectFork:_,activePermissionId:A,pendingTailToolId:(J==null?void 0:J.messageId)===G.id?J.toolId:null,onOpenFile:f,onOpenRun:p,onOpenSpawnedSession:m,runExperimentName:x,onOpenExperiment:k,experimentName:v,onRespond:w,onOpenPlan:b,onOpenSubagent:y,busy:ue,recoveringTurnId:ce===S?S:null,onRecover:E,skills:C,predictTextTail:d&&G===K&&G.role==="assistant"})},G.id)})})]})}),cts=(e,r)=>e==="all"?!0:e==="archived"?r:!r;function u4(e){return e instanceof Element&&e.closest("[data-side-chat]")!==null}const lts=[{id:"archived",label:dE,railLabel:dE},{id:"active",label:ANe,railLabel:lD},{id:"all",label:BNe,railLabel:eD}];function uts({value:e,onChange:r,grouping:t,onGroupingChange:n}){const{open:s,setOpen:o,ref:a}=ta();return u.jsxs("div",{className:"rail-filter relative inline-flex",ref:a,children:[u.jsx(kt,{size:"small",className:"rail-filter-btn text-subtext",active:e!=="active",title:jE(),"aria-label":jE(),onClick:()=>o(i=>!i),children:u.jsx(IP,{size:15,className:"text-subtext"})}),s&&u.jsxs("div",{className:"option-menu absolute bottom-[calc(100%_+_8px)] start-0 max-h-95 flex flex-col bg-background border border-border rounded-lg shadow-menu z-50 overflow-hidden min-w-40 p-1 [&.align-right]:start-auto [&.align-right]:end-0 [&.drop-down]:bottom-auto [&.drop-down]:top-[calc(100%_+_4px)] [&.session-menu]:start-auto [&.session-menu]:end-1.5 [&.session-menu]:top-[calc(100%_-_2px)] [&.session-menu]:min-w-35 drop-down align-right",children:[u.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:Fln()}),["projects","list"].map(i=>u.jsxs(_r,{size:"compact",className:"text-sm",onClick:()=>{n(i),o(!1)},children:[u.jsx("span",{children:i==="projects"?dS():Yln()}),t===i&&u.jsx(fo,{size:13})]},i)),u.jsx("div",{className:"my-1 border-t border-border"}),u.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:Tln()}),lts.map(i=>u.jsxs(_r,{size:"compact",className:"text-sm",onClick:()=>{r(i.id),o(!1)},children:[u.jsx("span",{children:i.label()}),e===i.id&&u.jsx(fo,{size:13})]},i.id))]})]})}const _ts=14,fts=500,dts=1200;function JU({title:e,animate:r}){return r?u.jsx("span",{className:"title-reveal","aria-label":e,children:Array.from(e).map((t,n)=>t===" "?u.jsx("span",{"aria-hidden":!0,children:t},n):u.jsx("span",{"aria-hidden":!0,className:"title-reveal-char inline-block animate-[title-char-in_240ms_ease-out_both] [@media((prefers-reduced-motion:_reduce))]:animate-none",style:{animationDelay:`${Math.min(n*_ts,fts)}ms`},children:t},n))}):u.jsx(u.Fragment,{children:e})}function hts({session:e,active:r,unread:t,busy:n,waiting:s,revealTitle:o,onOpen:a,onRename:i,onSetArchived:c,onDelete:_}){var E;const{open:d,setOpen:f,ref:p}=ta(),m=((E=e.title)==null?void 0:E.trim())||"Untitled",[x,k]=T.useState(!1),[v,w]=T.useState(""),b=T.useRef(null);function y(){var C;w(((C=e.title)==null?void 0:C.trim())||""),k(!0)}function S(){var A;const C=v.trim();k(!1),C&&C!==(((A=e.title)==null?void 0:A.trim())||"")&&i(C)}return T.useEffect(()=>{var C,A;x&&((C=b.current)==null||C.focus(),(A=b.current)==null||A.select())},[x]),u.jsxs("div",{ref:p,role:"button",tabIndex:0,className:`session-row relative flex items-center gap-2 w-full text-start py-[7px] ps-2.5 pe-1.5 rounded-md text-sm text-text cursor-pointer select-none [&:hover:not(.active)]:bg-surface [&.active]:bg-panel [&.active]:font-medium [&_.session-dot:empty]:hidden [&_.session-dot]:w-4 [&_.session-dot]:inline-flex [&_.session-dot]:items-center [&_.session-dot]:justify-center [&_.session-dot]:shrink-0 [&_.session-title]:flex-1 [&_.session-title]:min-w-0 [&_.session-title]:overflow-hidden [&_.session-title]:[mask-image:linear-gradient(to_right,black_calc(100%_-_16px),transparent)] [&_.session-title]:whitespace-nowrap [&_.session-menu-btn]:hidden [&_.session-menu-btn]:items-center [&_.session-menu-btn]:justify-center [&_.session-menu-btn]:w-4 [&_.session-menu-btn]:h-4 [&_.session-menu-btn]:-my-0.5 [&_.session-menu-btn]:mx-0 [&_.session-menu-btn]:rounded-sm [&_.session-menu-btn]:text-muted [&_.session-menu-btn]:shrink-0 [&_.session-menu-btn:hover]:text-text [&_.session-menu-btn:hover]:bg-panel [&:hover_.session-menu-btn]:inline-flex [&:focus-visible_.session-menu-btn]:inline-flex [&_.session-menu-btn:focus-visible]:inline-flex [&.menu-open_.session-menu-btn]:inline-flex [&:hover_.session-dot]:hidden [&:focus-visible_.session-dot]:hidden [&:has(.session-menu-btn:focus-visible)_.session-dot]:hidden [&.menu-open_.session-dot]:hidden [&_.busy-dot]:w-[7px] [&_.busy-dot]:h-[7px] [&_.busy-dot]:rounded-full [&_.busy-dot]:bg-primary [&_.busy-dot]:animate-[or-pulse_1.2s_infinite] [&_.busy-dot]:shrink-0 [&_.unread-dot]:w-[7px] [&_.unread-dot]:h-[7px] [&_.unread-dot]:rounded-full [&_.unread-dot]:bg-primary [&_.unread-dot]:shrink-0 [&_.busy-dot.waiting]:animate-none [&_.session-title-input]:flex-1 [&_.session-title-input]:min-w-0 [&_.session-title-input]:py-px [&_.session-title-input]:px-[5px] [&_.session-title-input]:-my-0.5 [&_.session-title-input]:mx-0 [&_.session-title-input]:[font:inherit] [&_.session-title-input]:text-text [&_.session-title-input]:bg-background [&_.session-title-input]:border [&_.session-title-input]:border-primary [&_.session-title-input]:rounded-sm [&_.session-title-input]:outline-none [&.editing]:bg-surface [&.editing]:cursor-default [&.editing_.session-menu-btn]:hidden [&.editing_.session-dot]:hidden ${r?"active":""} ${t?"unread":""} ${d?"menu-open":""} ${x?"editing":""}`,title:`${Af(e.harness,e.harnessName)}${e.model?` · ${e.model}`:""}`,onClick:()=>{x||(d?f(!1):a())},onKeyDown:C=>{C.target===C.currentTarget&&(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),d?f(!1):a())},children:[x?u.jsx("input",{ref:b,className:"session-title-input","aria-label":bHe(),value:v,onChange:C=>w(C.target.value),onClick:C=>C.stopPropagation(),onBlur:S,onKeyDown:C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),S()):C.key==="Escape"&&(C.preventDefault(),k(!1))}}):u.jsx("span",{className:"session-title",children:u.jsx(JU,{title:m,animate:o!==void 0},o??"static")}),s&&!x&&u.jsx(Va,{content:aD(),className:"shrink-0 text-accent-amber",children:u.jsx(CP,{size:14,"aria-hidden":"true"})}),u.jsx("span",{className:"session-dot",children:n&&!s?u.jsx("span",{className:"busy-dot"}):t&&!s&&u.jsx("span",{className:"unread-dot"})}),u.jsx("button",{className:"session-menu-btn",title:ME(),"aria-label":ME(),onClick:C=>{C.stopPropagation(),f(A=>!A)},children:u.jsx(Sp,{size:14})}),d&&u.jsxs("div",{className:"option-menu absolute bottom-[calc(100%_+_8px)] start-0 max-h-95 flex flex-col bg-background border border-border rounded-lg shadow-menu z-50 overflow-hidden min-w-47.5 p-1.5 [&.align-right]:start-auto [&.align-right]:end-0 [&.drop-down]:bottom-auto [&.drop-down]:top-[calc(100%_+_4px)] [&.session-menu]:start-auto [&.session-menu]:end-1.5 [&.session-menu]:top-[calc(100%_-_2px)] [&.session-menu]:min-w-35 drop-down session-menu",children:[u.jsx(_r,{onClick:C=>{C.stopPropagation(),f(!1),y()},children:u.jsx("span",{children:sD()})}),u.jsx(_r,{onClick:C=>{C.stopPropagation(),f(!1),c(!e.archived)},children:u.jsx("span",{children:e.archived?BYe():WSe()})}),u.jsx(_r,{danger:!0,onClick:C=>{C.stopPropagation(),f(!1),_()},children:u.jsx("span",{children:rD()})})]})]})}const XM=[jP,DP,R_,w0],pts=()=>[{title:sqe(),prompt:VHe()},{title:jqe(),prompt:hqe()},{title:Uqe(),prompt:Oqe()},{title:uUe(),prompt:eUe()}],_4=[{box:"border-accent-blue/45",icon:"text-accent-blue"},{box:"border-accent-green/45",icon:"text-accent-green"},{box:"border-accent-amber/45",icon:"text-accent-amber"},{box:"border-primary/45",icon:"text-primary"}],YM="mt-7 grid w-full max-w-readable grid-cols-1 gap-3 sm:grid-cols-2";function mts(e,r){if(!e)return null;const t=e.model??null;return{...e,model:t,serviceTier:Tb(r,t,e.serviceTier),reasoningLevel:LI(r,t,e.reasoningLevel)}}function ZM({projectId:e,projectName:r,contentLoading:t=!1,contentError:n=null,onRetryContent:s,railHeader:o,railOpen:a,onShowRail:i,onNewProject:c,mainView:_,onSelectMainView:d,onOpenFile:f,onOpenRun:p,runExperimentName:m,onOpenExperiment:x,experimentName:k,onOpenPlan:v,onOpenSubagent:w,runtime:b,onOpenDemoWelcome:y,composerFocusNonce:S=0,activeSessionId:E,onActiveSessionChange:C,preferredAgent:A,onPreferredAgentChange:N,preferredAutonomy:R,onPreferredAutonomyChange:L,embedded:$=!1,onOpenSideChat:I,onRunSetup:F,children:B}){var bs,_n,Nr,Fi,qo,Id,Hi,qp;const V=wr({mutationFn:Y=>hAn(...Y)}),K=wr({mutationFn:Y=>uAn(...Y)}),ee=wr({mutationFn:Y=>dAn(...Y)}),J=wr({mutationFn:Y=>fAn(...Y)}),P=wr({mutationFn:Y=>nAn(...Y)}),D=wr({mutationFn:Y=>aAn(...Y)}),q=wr({mutationFn:Y=>cAn(...Y)}),U=wr({mutationFn:Y=>lAn(...Y)}),G=wr({mutationFn:E3}),oe=h0(),{data:ce=[]}=nt({...A_(),enabled:!$}),{data:ue=[]}=nt({...aA(),enabled:!$}),[re,W]=T.useState(()=>{try{return localStorage.getItem("sidebar-grouping")==="list"?"list":"projects"}catch{return"projects"}}),[ae,ie]=T.useState(()=>{try{const Y=JSON.parse(localStorage.getItem("sidebar-pinned-projects")??"[]");return Array.isArray(Y)?Y.filter(_e=>typeof _e=="string"):[]}catch{return[]}}),[ve,xe]=T.useState(()=>{try{const Y=JSON.parse(localStorage.getItem("sidebar-collapsed-projects")??"[]");return Array.isArray(Y)?Y.filter(_e=>typeof _e=="string"):[]}catch{return[]}}),[Ce,Fe]=T.useState("active"),[Ye,Oe]=T.useState(!1),Ie=T.useRef(null),[ut,jt]=T.useState(0),[Ut,Wt]=T.useState(null),[Pt,mt]=T.useState({});T.useLayoutEffect(()=>{const Y=Ie.current;if(!Y||$)return;const _e=()=>jt(Y.clientHeight),we=new ResizeObserver(_e);return we.observe(Y),_e(),()=>we.disconnect()},[a,$,_]);const wt=new Map(ue.map(Y=>[Y.projectId,Y.lastActivityAt])),Mt=[...ce].sort((Y,_e)=>Number(ae.includes(_e.id))-Number(ae.includes(Y.id))||Math.max(wt.get(_e.id)??0,_e.updatedAt)-Math.max(wt.get(Y.id)??0,Y.updatedAt)),ze=re==="list"||Ye?Mt.length:Math.max(1,Math.ceil(ut/36));let Be=Mt.slice(0,ze);const je=ce.find(Y=>Y.id===e);je&&!Be.some(Y=>Y.id===e)&&(Be=[...Be.slice(0,ze-1),je]);const ot=Y$({queries:(re==="projects"?Be:[]).map(Y=>({...Ao(Y.id),enabled:!$}))}),We=_Q({queryKey:zt("listSidebarChatSessions",Ce),queryFn:({pageParam:Y,signal:_e})=>uTn(Ce,Y,_e),initialPageParam:null,getNextPageParam:Y=>Y.next??void 0,enabled:!$&&re==="list"}),rt=T.useMemo(()=>Ao(e),[e]),{data:ft=WM}=nt(rt),tr=T.useCallback(Y=>{ss(rt.queryKey,_e=>{if(!_e)return;const we=typeof Y=="function"?Y(_e):Y,ye=new Map(_e.map($e=>[$e.id,$e]));for(const $e of we)ye.get($e.id)!==$e&&vi(Xe,rt.queryKey,$e.id),ye.delete($e.id);for(const $e of ye.keys())vi(Xe,rt.queryKey,$e);return we})},[rt]),me=E,Ht=T.useRef(C);Ht.current=C;const Ke=T.useRef({projectId:e});Ke.current.projectId!==e&&(Ke.current={projectId:e});const[or,Lt]=T.useState(new Set),[Zt,Bt]=T.useState(""),[vt,Sn]=T.useState(!1),[Lr,Cr]=T.useState([]),Dr=T.useRef(0),dt=T.useRef({projectId:e,activeId:me,mainView:_});(dt.current.projectId!==e||dt.current.activeId!==me||dt.current.mainView!==_)&&(dt.current={projectId:e,activeId:me,mainView:_});const[gr,jr]=T.useState([]),[nr,sn]=T.useState(null),[Br,zr]=T.useState(null),Fr=me??`${e}:new`,Ot=T.useRef(new Map),Kt=T.useRef(Ck);Kt.current={draft:Zt,attachments:gr,annotations:Lr};const en=e===Cm&&!$&&ft.length>0&&ft.every(Y=>Y.sideParentSessionId||P9n[Y.id]===Y.activeLeafId)?KN:null,Vr=T.useRef(null);en!==null&&Vr.current===null&&me!==null&&(Vr.current=Fr);const Cn=Fr===Vr.current?en:null;T.useLayoutEffect(()=>{const Y=Ot.current.get(Fr)??Ck;return Kt.current=Y,Bt(Y.draft),jr(Y.attachments),Cr(Y.annotations),zr(null),()=>{const _e=vWn(Kt.current,Cn);_e?Ot.current.set(Fr,_e):Ot.current.delete(Fr)}},[Fr,Cn]);const[cn,Gt]=T.useState(null),hs=T.useRef(Promise.resolve()),Kn=T.useRef(0),Ws=T.useRef(0),[Ks,os]=T.useState(null),gn=T.useRef(null),Ve=T.useRef(!1),bt=T.useRef(null),[vr,dr,qr]=mTn(e,_==="chat"?me:null),{data:ar=bts}=nt(cu()),[Ns,ps]=T.useState(A);T.useEffect(()=>ps(A),[A]);const[vn,as]=T.useState({}),[eo,to]=T.useState(Dm),[As,Ni]=T.useState(null),Vs=T.useRef(!1),Ea=T.useRef(null),[Bn,Fn]=T.useState(null),Na=T.useRef(!1),na=T.useRef(null),[oi,Aa]=T.useState(new Map),ro=T.useRef(new Map),Ta=T.useRef(null),Vn=T.useRef(null),mo=T.useRef(null),Qn=T.useRef(!0),[go,vo]=T.useState(!0),ln=T.useRef(null),[ic,Ts]=T.useState(!1),yu=ta(),Nd=T.useCallback(Y=>{var _e;Dr.current+=1,Cr(we=>[...we,{id:`annotation-${Dr.current}`,...Y}]),(_e=ln.current)==null||_e.focus()},[]),Ra=pes(Vn,Nd);mes(Lr,$?aes:oes),T.useEffect(()=>{Ts(!1),Ra.dismiss()},[me,e,Ra.dismiss]);const[rl,cc]=T.useState(0),[Dp,Ma]=T.useState(0),[no,so]=T.useState(!1),[oo,sa]=T.useState(0),[Rs,Ms]=T.useState(0),Os=T.useRef(!1);function xu(Y){if(!is)return;if(!Lo&&Y.source==="command"&&Lx(Y.name)&&Y.name!=="goal"){il(Y.name,Zt,is);return}const _e=Y.name.replace(/@u$/,"^").replace(/@p$/,"~"),we=Y.source==="command"?1:IM(_e,ln.current),ye=kJn(Zt,is,_e,we);Bt(ye.text),window.requestAnimationFrame(()=>{var $e,Et;($e=ln.current)==null||$e.focus(),(Et=ln.current)==null||Et.setSelectionRange(ye.cursor,ye.cursor),Ms(ye.cursor)})}function zn(Y){if(!ii)return;const _e=sWn(Zt,ii,Y);Bt(_e.text),window.requestAnimationFrame(()=>{var we,ye;(we=ln.current)==null||we.focus(),(ye=ln.current)==null||ye.setSelectionRange(_e.cursor,_e.cursor),Ms(_e.cursor)})}function Rn(Y){if(W_)return!1;const _e=Y.selectionStart;if(Os.current||_e!==Y.selectionEnd)return!1;const we=Zt.slice(0,_e).replace(/[ \t]+$/,"").length,ye=t4(Zt,we);if(!ye||ye.end!==we||!mc(ye.query)||_e>we&&_e-we!==IM(ye.query,Y))return!1;const $e=DM(Zt,{...ye,end:_e});return Bt($e.text),Ms($e.cursor),window.requestAnimationFrame(()=>Y.setSelectionRange($e.cursor,$e.cursor)),!0}function $s(Y){sn(null),zr(null);let ye=gr.reduce(($e,Et)=>$e+Et.size,0);for(const $e of Y){if(!/^(image\/(png|jpeg|gif|webp)|application\/pdf)$/.test($e.type))continue;if(Su&&$e.type.startsWith("image/")){zr((Ls==null?void 0:Ls.id)??null);continue}if($e.size>31457280){sn(R6e({name:Te($e.name)}));continue}if(ye+$e.size>41943040){sn(H6e());continue}ye+=$e.size;const Et=dt.current,pt=Fr,ir=new FileReader;ir.onload=()=>{const cr={dataUrl:ir.result,mediaType:$e.type,name:$e.name,size:$e.size};if(dt.current.projectId===Et.projectId&&dt.current.activeId===Et.activeId){jr(wo=>[...wo,cr]);return}const lr=Ot.current.get(pt)??Ck;Ot.current.set(pt,{...lr,attachments:[...lr.attachments,cr]})},ir.readAsDataURL($e)}}function Xn(Y){const _e=Array.from(Y.clipboardData.items).filter(we=>we.kind==="file"&&(we.type.startsWith("image/")||we.type==="application/pdf")).map(we=>we.getAsFile()).filter(we=>we!==null);_e.length>0&&(Y.preventDefault(),$s(_e))}const lt=ft.find(Y=>Y.id===me),nl=Ns??ALn(ar),Oo=lt?{harness:lt.harness,model:vn.model!==void 0?vn.model:lt.model,serviceTier:vn.serviceTier!==void 0?vn.serviceTier:lt.serviceTier,permissionMode:vn.permissionMode??lt.permissionMode,reasoningLevel:vn.reasoningLevel??lt.reasoningLevel}:nl?{...nl,...vn}:null,{data:sl=vts}=nt(HAn(Oo==null?void 0:Oo.harness,e)),wu=Oo?ar.find(Y=>Y.id===Oo.harness):void 0,Ze=kLn(lt,wu),oa=_B(lt==null?void 0:lt.nativeConfiguration,{model:Nh(),mode:_3()}),Yn=oa.find(Y=>Y.category==="model"),Jt=Ze==null?void 0:Ze.options,{data:Ai}=nt({...kS(),enabled:!!F}),Ti=Y=>{if(!Ze)return;const _e=Ai==null?void 0:Ai[Ze.id];if(!(Ze.id==="claude-code"&&Y===(_e==null?void 0:_e.login)&&!Ze.loginEligible))return wU(Ze,_e,Y)},aa=T.useMemo(()=>jJn(sl,Jt==null?void 0:Jt.planActivation),[sl,Jt==null?void 0:Jt.planActivation]),lc=BM(Zt),Ri=lc!==null,is=t4(Zt,Rs),ai=(is==null?void 0:is.query)??null,G_=ai===null?[]:aa.filter(Y=>xJn(Y,ai)),W_=!Ri&&ai!==null&&(is==null?void 0:is.end)===Rs&&G_.length>0,uc=W_&&!no?G_:[],Ad=uc.length>0,Mi=Math.min(rl,Math.max(0,uc.length-1));T.useEffect(()=>cc(0),[ai]);const ii=Ri?null:eWn(Zt,Rs),_c=(ii==null?void 0:ii.end)===Rs?ii.query:null,ci=(bs=nt({...C6(e,me?{sessionId:me}:{}),enabled:_c!==null}).data)==null?void 0:bs.entries,fc=T.useMemo(()=>rWn(ci??[]),[ci]),Oi=T.useMemo(()=>_c!==null&&!no?nWn(fc,_c):[],[fc,_c,no]),Td=Oi.length>0,ku=Math.min(Dp,Math.max(0,Oi.length-1));T.useEffect(()=>Ma(0),[_c]);const hr=mts(Yn&&Oo?{...Oo,model:Yn.currentValue}:Oo,Ze),ju=Dy(Ze,hr==null?void 0:hr.model),Ls=Ze==null?void 0:Ze.models.find(Y=>Y.id===(hr==null?void 0:hr.model)),Su=(Ls==null?void 0:Ls.imageInput)===!1?l9e({model:Te(Wv(Ls))}):null,K_=!!Su&&gr.some(Y=>Y.mediaType.startsWith("image/")),Rd=!!Ls&&Br===Ls.id,Qs=K_||Rd?Su:null;T.useEffect(()=>zr(null),[Ls==null?void 0:Ls.id]);const dc=Y=>{if(lt!=null&<.harness.startsWith("acp:")&&Yn&&Y.model){QN(lt.id,Yn.id,Y.model).catch(ye=>Xt(ye instanceof Error?ye.message:String(ye),"error"));return}if(!hr)return;const _e={...hr,...Y},we={};Y.model!==void 0&&Y.model!==hr.model&&(we.model=Y.model),Y.serviceTier!==void 0&&Y.serviceTier!==hr.serviceTier&&(we.serviceTier=Y.serviceTier),Y.permissionMode!==void 0&&Y.permissionMode!==hr.permissionMode&&(we.permissionMode=Y.permissionMode),Y.reasoningLevel!==void 0&&Y.reasoningLevel!==hr.reasoningLevel&&(we.reasoningLevel=Y.reasoningLevel),to(ye=>({...ye,...we})),ps(_e),N(_e).catch(()=>{}),lt?as(ye=>({...ye,...Y})):Y.harness&&Y.harness!==hr.harness&&as({})},Xs=T.useCallback(Y=>{const _e=hs.current.catch(()=>{}).then(()=>{if(!Kr(rt.queryKey))throw new DOMException("Workspace changed","AbortError");return Y()});return hs.current=_e.then(()=>{},()=>{}),_e},[rt]),ol=Y=>{if(Y==="plan"&&(Ze==null?void 0:Ze.id)==="claude-code"?(to(ye=>({...ye,permissionMode:Y})),as(ye=>({...ye,permissionMode:Y}))):(as(ye=>{const $e={...ye};return delete $e.permissionMode,$e}),dc({permissionMode:Y})),!lt)return;const _e=lt.id,we=++Kn.current;Gt(null),Xs(()=>V.mutateAsync([_e,Y])).then(ye=>{tr($e=>$e.map(Et=>Et.id===ye.id?ye:Et)),Kn.current===we&&as($e=>{const Et={...$e};return delete Et.permissionMode,Et})}).catch(()=>{Kn.current===we&&(as(ye=>{const $e={...ye};return delete $e.permissionMode,$e}),Gt(pZe()))})},V_=Y=>dc({reasoningLevel:Y}),Ip=Y=>{if(!lt){L(Y);return}const _e=lt.id,we=lt.autonomy,ye=++Kn.current,$e=Et=>tr(pt=>pt.map(ir=>ir.id===Et.id?Et:ir));$e({...lt,autonomy:Y}),Gt(null),Xs(()=>ee.mutateAsync([_e,Y])).then(Et=>{$e(Et),L(Et.autonomy)}).catch(()=>{tr(Et=>Et.map(pt=>pt.id===_e&&pt.autonomy===Y?{...pt,autonomy:we}:pt)),Kn.current===ye&&Gt(oZe())})},$i=((_n=lt==null?void 0:lt.goal)==null?void 0:_n.trim())||"",Cu=(hr==null?void 0:hr.harness)==="claude-code"?hr.permissionMode==="plan":(Jt==null?void 0:Jt.planActivation)==="command"?Ks??(lt==null?void 0:lt.planMode)??!1:!1;T.useEffect(()=>{Ks===null||(lt==null?void 0:lt.planMode)!==Ks||(gn.current=null,os(null))},[lt==null?void 0:lt.planMode,Ks]);async function Q_(Y){if(to(ye=>({...ye,planMode:Y})),gn.current=Y,os(Y),!lt)return;const _e=lt.id,we=++Ws.current;Gt(null);try{const ye=await Xs(()=>K.mutateAsync([_e,Y]));tr($e=>$e.map(Et=>Et.id===ye.id?ye:Et)),Ws.current===we&&(gn.current=null,os(null),Gt(null))}catch(ye){throw Ws.current===we&&(gn.current=null,os(null)),ye}}async function X_(){if((hr==null?void 0:hr.harness)==="claude-code"){ol("auto");return}if(lt)try{await Q_(!1)}catch{Gt(H7e())}}async function Y_(){const Y=!Cu;try{if((hr==null?void 0:hr.harness)==="claude-code")ol(Y?"plan":"auto");else if((Jt==null?void 0:Jt.planActivation)==="command")await Q_(Y);else throw new Error(G1())}catch{Gt(PE())}}function ia(Y,_e=""){var we;switch(Y){case"plan":return Y_(),!1;case"new":return $?lt!=null&<.sideParentSessionId&&(I==null||I(lt.sideParentSessionId,"")):Po(),!1;case"resume":return Ts(!0),!0;case"model":return sa(ye=>ye+1),!0;case"compact":return Eu(),!1;case"goal":return al(_e),!1;case"side":return Pp(_e),!1;case"copy":{const ye=gs.at(-1),$e=yr&&(ye==null?void 0:ye.role)==="assistant"&&!ye.completedAt,Et=fWn($e?gs.slice(0,-1):gs);return Et?MC(Et):Xt(pEe(),"info"),!1}case"export":{const ye=((we=lt==null?void 0:lt.title)==null?void 0:we.trim())||Gv(),$e=lt?dWn(ye,gs,{user:v8e(),assistant:Af(lt.harness,lt.harnessName)}):null;return $e?Qes(hWn(ye),$e):Xt(SEe(),"info"),!1}}}function Pp(Y){$?Xt(Lcn(),"info"):!lt||!I?Xt(Ccn(),"info"):I(lt.id,Y)}async function zu(Y){Gt(null);const _e=Ke.current;try{const we=await P.mutateAsync([e,Y]);if(Xe.invalidateQueries({queryKey:KI().queryKey}),Ke.current!==_e)return;tr(ye=>[we,...ye.filter($e=>$e.id!==we.id)]),Fe("all"),C(we.id,{projectId:we.projectId})}catch(we){if(Ke.current!==_e)return;Gt(Mze({error:Te(we instanceof Error?we.message:String(we))}))}}async function al(Y){var pt;const _e=Y.trim();if(!_e){const ir=(pt=lt==null?void 0:lt.goal)==null?void 0:pt.trim();Xt(ir?I8e({goal:Xl(ir)}):nze(),"info");return}const we=dt.current,ye=()=>dt.current.activeId===we.activeId;Gt(null);let $e=me;if(!$e){if(!(Ze!=null&&Ze.agentReady)||!hr){Gt(G1());return}try{$e=(await io(hr,n4(Jt==null?void 0:Jt.planActivation,void 0,gn.current))).id}catch(ir){Gt(_E({error:Te(ir instanceof Error?ir.message:String(ir))}));return}}const Et=/^(clear|none|off)$/i.test(_e);try{const ir=await Xs(()=>J.mutateAsync([$e,Et?null:_e]));tr(cr=>cr.map(lr=>lr.id===ir.id?ir:lr)),Xt(Et?E8e():dze(),"success")}catch(ir){if(!ye())return;Gt(_E({error:Te(ir instanceof Error?ir.message:String(ir))}))}}async function Eu(){const Y=me;if(!Y){Xt(oEe(),"info");return}if(yr){Gt(DCe());return}Gt(null),Ce==="archived"&&Fe("active");const _e=dt.current;try{const{message:we}=await bAn(Y);dr({type:"upsertMessage",sessionId:Y,message:we})}catch(we){if(dt.current.activeId!==_e.activeId)return;Gt(KCe({error:Te(we instanceof Error?we.message:String(we))}))}}function il(Y,_e,we){const ye=DM(_e,we);Bt(ye.text),so(!0),!ia(Y)&&window.requestAnimationFrame(()=>{var $e,Et;($e=ln.current)==null||$e.focus(),(Et=ln.current)==null||Et.setSelectionRange(ye.cursor,ye.cursor),Ms(ye.cursor)})}const li=T.useCallback(async(Y=!1)=>{const _e=Ke.current;if(_e.projectId!==e||!Kr(rt.queryKey))return null;const we=(Xe.getQueryData(rt.queryKey)??[]).map(ye=>ye.id);try{const ye=await Xe.fetchQuery({...rt,...Y?{staleTime:0}:{}});if(Ke.current!==_e||!Kr(rt.queryKey))return null;const $e=ye.filter(pt=>!Bc.has(pt.id)),Et=new Set($e.map(pt=>pt.id));for(const pt of we)Et.has(pt)||ke(pt);return ro.current=new Map($e.map(pt=>[pt.id,pt.title])),$e}catch{return null}},[e]),ms=T.useCallback(async Y=>{Ke.current.projectId!==e||!Kr(rt.queryKey)||await Promise.all([Xe.fetchQuery({...Hc(Y),staleTime:0}),li(!0)]).catch(()=>{})},[e,li]);T.useEffect(()=>{const Y=eB();Lt(e===Cm?new Set([bS,yS].filter(we=>!Y.has(we))):new Set),Sn(!1),Aa(new Map),ro.current=new Map,li();const _e=Ke.current;return()=>{Ke.current===_e&&(Ke.current={projectId:e})}},[e,li]),T.useEffect(()=>{to(Dm),na.current=null},[me]),T.useEffect(()=>wg(Y=>{switch(Y.type){case"session":{if(Y.session.projectId!==e||Bc.has(Y.session.id))return;const _e=ro.current.has(Y.session.id),we=ro.current.get(Y.session.id)!==Y.session.title;ro.current.set(Y.session.id,Y.session.title),_e&&we&&Y.session.titleSource==="generated"&&(Aa(ye=>{const $e=new Map(ye);return $e.set(Y.session.id,(ye.get(Y.session.id)??0)+1),$e}),window.setTimeout(()=>{Aa(ye=>{if(!ye.has(Y.session.id))return ye;const $e=new Map(ye);return $e.delete(Y.session.id),$e})},dts));break}case"sessionDeleted":ke(Y.sessionId);break}}),[e]),T.useEffect(()=>wg(Y=>{Y.type==="reconnected"&&li(!0)}),[li]);const hc=me?vr.messagesBySession[me]??GM:GM,pc=me?vr.activeLeafBySession[me]??null:null;Ea.current=pc;const gs=T.useMemo(()=>mR(hc,pc),[hc,pc]),cl=T.useRef({projectId:e,ids:vr.busySessions});T.useEffect(()=>{const Y=cl.current;cl.current={projectId:e,ids:vr.busySessions},Y.projectId===e&&Lt(_e=>_Wn(_e,Y.ids,vr.busySessions,ft,_==="chat"?me:null))},[e,vr.busySessions,ft,me,_]);const yr=me?vr.busySessions.has(me):!1,ll=!yr&&!!(Ze!=null&&Ze.agentReady),ul=yr&&kH(gs)!=null,Md=yr&&uWn(gs),$o=me?vr.queuedBySession[me]??[]:[],_l=$o.some(Y=>Y.dispatchState==="retrying"),Od=$o.findIndex(Y=>Y.dispatchState==="blocked"),Li=$o.reduce((Y,_e)=>_e.dispatchState!=="retrying"||typeof _e.nextRetryAt!="number"?Y:Y===null?_e.nextRetryAt:Math.min(Y,_e.nextRetryAt),null),[Di,fl]=T.useState(()=>Date.now());T.useEffect(()=>{if(!_l||Li===null||(fl(Date.now()),Li<=Date.now()))return;const Y=window.setInterval(()=>{const _e=Date.now();fl(_e),_e>=Li&&window.clearInterval(Y)},1e3);return()=>window.clearInterval(Y)},[_l,Li]),T.useEffect(()=>{const Y=$o.reduce((_e,we)=>we.planMode??_e,void 0);Y!==void 0?(Ve.current=!0,gn.current=Y,os(Y)):Ve.current&&(Ve.current=!1,gn.current=null,os(null))},[$o]);const Nu=!!me&&qr.isPending,Z_=T.useMemo(()=>{const Y=new Set;for(const[_e,we]of Object.entries(vr.messagesBySession)){const ye=vr.busySessions.has(_e);iWn(mR(we,vr.activeLeafBySession[_e]),ye)&&Y.add(_e)}return Y},[vr.busySessions,vr.messagesBySession,vr.activeLeafBySession]),Au=yr&&gs.some(Y=>Y.parts.some(_e=>_e.type==="prompt"&&_e.prompt&&!_e.prompt.resolved&&_e.prompt.nativeId)),tn=lt,J_=tn?oi.get(tn.id):void 0,ao=T.useMemo(()=>{var Y;for(let _e=gs.length-1;_e>=0;_e--)for(const we of gs[_e].parts)if(we.type==="prompt"&&((Y=we.prompt)==null?void 0:Y.kind)==="plan"&&!we.prompt.resolved)return{promptId:we.id,plan:we.prompt.plan??"",synthesized:!!we.prompt.synthesized};return null},[gs]),Lo=T.useMemo(()=>me?cWn(gs,tn==null?void 0:tn.harness,vr.busySessions.has(me)):null,[gs,tn==null?void 0:tn.harness,me,vr.busySessions]),bn=Ri&&!Lo,mc=Y=>{if(Lo||Ri)return!1;const _e=nj(Y),we=aa.find(ye=>ye.name===zC(_e??Y));return!we||we.source!=="command"?!!we:_e&&r4(_e)?_e==="plan"||Zt.trim().toLowerCase().startsWith(`/${Y}`):Zt.trim().toLowerCase()===`/${Y}`},$d=T.useMemo(()=>aa.filter(Y=>Y.source!=="command"),[aa]),[En,Ur]=T.useState(null),dl=En&&En.sessionId===me?En:null;T.useEffect(()=>{if(!En)return;const Y=vr.busySessions.has(En.sessionId),_e=En.sessionId===me&&ao&&ao.promptId!==En.promptId;(!Y||_e)&&Ur(null)},[En,ao,vr.busySessions,me]);const ef=T.useMemo(()=>OC(gs),[gs]),hl=yr&&!!(Ze!=null&&Ze.supportsSteering)&&!!(Ze!=null&&Ze.agentReady)&&!ao&&!Lo&&!ef&&gr.length===0&&Lr.length===0,Oa=T.useMemo(()=>v&&me?(Y,_e,we)=>v(Y,me,_e,we):void 0,[v,me]),vs=T.useMemo(()=>w&&me?(Y,_e,we)=>w(me,Y,_e,we):void 0,[w,me]),ca=T.useMemo(()=>f&&((Y,_e,we,ye,$e)=>f(Y,me??void 0,_e,we,ye,$e)),[f,me]);T.useEffect(()=>{Kn.current+=1,Ws.current+=1;const Y=(me?vr.queuedBySession[me]??[]:[]).reduce((_e,we)=>we.planMode??_e,void 0);Ve.current=Y!==void 0,gn.current=Y??null,os(Y??null),as({}),Gt(null)},[me]);const Do=_==="chat"&&(gs.length>0||yr),gc=(hr==null?void 0:hr.harness)??null,$a=(hr==null?void 0:hr.model)??null,Io=qr.data?null:qr.error,Ds=_==="chat"&&!$&&!Do&&!t&&!n&&!Nu&&!Io,cs=nt({...vTn(e,gc??"claude-code",$a,z()),enabled:Ds&&gc!==null,subscribed:Ds&&gc!==null}),La=(Nr=cs.data)!=null&&Nr.blank?pts():((Fi=cs.data)==null?void 0:Fi.prompts)??null,Tu=gc!==null&&cs.isPending,Is=e===Cm?"demo":"project",tf=Y=>{Bt(Y),so(!1),window.requestAnimationFrame(()=>{const _e=ln.current;_e&&(_e.focus(),_e.setSelectionRange(Y.length,Y.length),Ms(Y.length))})};T.useEffect(()=>{Cn&&(Bt(Y=>Y||Cn),so(!1),Ms(Cn.length))},[Cn]),T.useEffect(()=>{if(S===0)return;const Y=window.requestAnimationFrame(()=>{const _e=ln.current;_e&&(_e.focus(),_e.setSelectionRange(_e.value.length,_e.value.length),_e.scrollIntoView({block:"nearest"}))});return()=>window.cancelAnimationFrame(Y)},[S]);const Ld=T.useId(),rf=e===Cm&&Zt===KN&&!vt,vc=T.useCallback(Y=>{const _e=Y.scrollHeight-Y.scrollTop-Y.clientHeight<60;Qn.current=_e,vo(_e)},[]),Da=T.useCallback(()=>{var Y;Qn.current=!0,vo(!0),(Y=mo.current)==null||Y.call(mo)},[]);T.useEffect(()=>{const Y=Ta.current,_e=Vn.current;if(!Y||!_e)return;const we=new ResizeObserver(()=>{var ye;Qn.current?(ye=mo.current)==null||ye.call(mo):vo(Y.scrollHeight-Y.scrollTop-Y.clientHeight<60)});return we.observe(Y),we.observe(_e),()=>we.disconnect()},[Do]);const ui=T.useCallback(Y=>{Y.currentTarget.blur(),Da()},[Da]);async function _i({queue:Y=!1,starter:_e}={}){var $u,Bd,xl,wl,U0,Gp;const we=(_e??Zt).trim(),ye=!Lo&&_e===void 0?SJn(we,Jt==null?void 0:Jt.planActivation):null;if(ye&&ye.name!=="plan"){Bt(r4(ye.name)?"":ye.prompt),so(!1),ia(ye.name,ye.prompt);return}if(K_||(_e===void 0&&l_({name:"first_action",surface:Is,action:"typed_prompt"}),Na.current))return;const $e=!!ye,Et=!Cu,pt=n4(Jt==null?void 0:Jt.planActivation,$e?Et:void 0,gn.current),ir=$e&&(Ze==null?void 0:Ze.id)==="claude-code"?Et?"plan":"auto":void 0,cr=ye?ye.prompt:we,lr=gr,wo=Lr,Mu=wo.map(nn=>({text:nn.text})),Ou=e,Pd=_;let yc=me;const yn=()=>{const nn=dt.current;return Kr(rt.queryKey)&&nn.projectId===Ou&&nn.activeId===yc&&nn.mainView===Pd},bl=()=>{yn()&&(Bt(nn=>nn||we),jr(nn=>nn.length?nn:lr),Cr(nn=>nn.length?nn:wo))};if($e&&!cr&&lr.length===0&&wo.length===0){Bt(""),so(!1);try{if((Ze==null?void 0:Ze.id)==="claude-code")ol(Et?"plan":"auto");else if((Jt==null?void 0:Jt.planActivation)==="command")await Q_(Et);else throw new Error(G1())}catch{Gt(PE()),bl()}return}const ys=hr?{...hr,...ir?{permissionMode:ir}:{}}:null;ir&&ol(ir);let Up=null;const q0=gn.current;$e&&(Jt==null?void 0:Jt.planActivation)==="command"&&(Up=++Ws.current,gn.current=Et,os(Et));const of=()=>{!yn()||Up===null||Ws.current!==Up||(gn.current=q0,os(q0))};if(!cr&&lr.length===0&&wo.length===0)return;if((cr||wo.length>0)&&Lo&&lr.length===0){Bt(""),Cr([]),St({promptId:Lo,answers:[],note:cr||void 0,annotations:Mu}).then(nn=>{nn||bl()});return}const Hn=JSON.stringify({text:cr,images:lr.map(nn=>({mediaType:nn.mediaType,name:nn.name,dataUrl:nn.dataUrl})),annotations:Mu,settings:ys?{model:ys.model,serviceTier:ys.serviceTier,permissionMode:ys.permissionMode,planMode:pt,reasoningLevel:ys.reasoningLevel}:null}),yl=(($u=na.current)==null?void 0:$u.signature)===Hn?na.current.id:`ct_${crypto.randomUUID()}`;if(na.current={signature:Hn,id:yl},yr){if(!me||!(Ze!=null&&Ze.agentReady)){of();return}const nn=me;Bt(""),jr([]),Cr([]),sn(null),zr(null);const xc=ys?{model:ys.model,serviceTier:ys.serviceTier,permissionMode:ys.permissionMode,planMode:(Jt==null?void 0:Jt.planActivation)==="command"?pt??(lt==null?void 0:lt.planMode):pt,reasoningLevel:ys.reasoningLevel}:{};yn()&&as({});const Uo=lr.map(us=>({mediaType:us.mediaType,dataBase64:us.dataUrl.slice(us.dataUrl.indexOf(",")+1),name:us.name}));try{(Bd=(await Xs(()=>N3(nn,cr,xc,Uo.length?Uo:void 0,Mu,yl,hl&&!Y&&!$e?"steer":void 0))).turn)!=null&&Bd.existing&&await ms(nn),yn()&&to(Dm),((xl=na.current)==null?void 0:xl.id)===yl&&(na.current=null)}catch{of(),bl()}return}if(!(Ze!=null&&Ze.agentReady)){of();return}if(!ys){of();return}let ko=me;try{Bt(Nn=>Nn===Zt?"":Nn),jr(Nn=>Nn===lr?[]:Nn),Cr(Nn=>Nn===wo?[]:Nn),sn(null),zr(null),Na.current=!0;try{if(!ko){const jl=await io(ys,pt);ko=jl.id,yc=jl.id}if(!Kr(rt.queryKey))return;const Nn=Hc(ko);await Xe.fetchQuery({...Nn,...((wl=Xe.getQueryState(Nn.queryKey))==null?void 0:wl.fetchStatus)==="fetching"?{staleTime:0}:{}})}finally{Na.current=!1}if(!Kr(rt.queryKey))return;dr({type:"optimisticUser",sessionId:ko,text:cr||f6e(),attachments:lr.map(Nn=>({url:Nn.dataUrl,mediaType:Nn.mediaType,name:Nn.name})),annotations:wo}),dr({type:"busy",sessionId:ko,busy:!0}),yn()&&Da(),yn()&&Ce==="archived"&&Fe("active");const nn=ys?{model:ys.model,serviceTier:ys.serviceTier,permissionMode:ys.permissionMode,planMode:pt,reasoningLevel:ys.reasoningLevel}:{};yn()&&as({});const xc=lr.map(Nn=>({mediaType:Nn.mediaType,dataBase64:Nn.dataUrl.slice(Nn.dataUrl.indexOf(",")+1),name:Nn.name})),Uo=ko;if(!Uo)throw new Error(BQe());(U0=(await Xs(()=>N3(Uo,cr,nn,xc.length?xc:void 0,Mu,yl))).turn)!=null&&U0.existing&&await ms(Uo),yn()&&to(Dm),((Gp=na.current)==null?void 0:Gp.id)===yl&&(na.current=null)}catch(nn){if(!Kr(rt.queryKey)||(bl(),of(),!ko))return;const xc=nn instanceof Error?nn.message:String(nn);if(!/session is busy/i.test(xc)&&await Xe.fetchQuery({...Ao(e),staleTime:0}).then(us=>{var kl;return!!((kl=us.find(Nn=>Nn.id===ko))!=null&&kl.busy)}).catch(()=>!1)){yn()&&(Bt(us=>us===cr?"":us),jr(us=>us===lr?[]:us),Cr(us=>us===wo?[]:us));return}dr({type:"busy",sessionId:ko,busy:!1}),dr({type:"localError",sessionId:ko,text:Jze({error:Te(xc)})})}}async function io(Y,_e){const we=dt.current,ye=Ke.current,$e=await D.mutateAsync([e,Y.harness,{model:Y.model,serviceTier:Y.serviceTier,permissionMode:Y.permissionMode,planMode:_e,reasoningLevel:Y.reasoningLevel,autonomy:R}]);return Ke.current===ye&&(tr(Et=>[$e,...Et.filter(pt=>pt.id!==$e.id)]),Xe.getQueryData(rt.queryKey)||li(!0)),Ke.current===ye&&dt.current===we&&(Ht.current($e.id,{replace:!0}),dt.current={...we,activeId:$e.id}),$e}function bc(){const Y=XJn(Zt);Bt(Y),window.requestAnimationFrame(()=>{var _e,we;(_e=ln.current)==null||_e.focus(),(we=ln.current)==null||we.setSelectionRange(Y.length,Y.length),Ms(Y.length)})}async function co(){const Y=lc;if(!Y)return;if(Gt(null),yr){Gt(Z6e());return}const _e=Zt,we=dt.current;let ye=me;const $e=()=>{const cr=dt.current;return cr.projectId===we.projectId&&cr.activeId===ye&&cr.mainView===we.mainView},Et=()=>{$e()&&Bt(cr=>cr||_e)};Bt(""),so(!1);let pt=me;if(!pt){if(!(Ze!=null&&Ze.agentReady)||!hr){Et(),Gt(G1());return}try{const cr=n4(Jt==null?void 0:Jt.planActivation,void 0,gn.current);pt=(await io(hr,cr)).id,ye=pt,$e()&&as({})}catch(cr){Et();const lr=cr instanceof Error?cr.message:String(cr);$e()&&Gt(lE({error:Te(lr)}));return}}$e()&&Ce==="archived"&&Fe("active");const ir=`${Vf}shell-${Date.now()}`;dr({type:"localShell",sessionId:pt,id:ir,command:Y}),$e()&&Da();try{const{message:cr}=await yAn(pt,Y);dr({type:"upsertMessage",sessionId:pt,message:cr})}catch(cr){const lr=cr instanceof Error?cr.message:String(cr);dr({type:"localShell",sessionId:pt,id:ir,command:Y,error:lE({error:Te(lr)})})}}function Ii(){me&&jAn(me).catch(()=>{Gt(CXe())})}const nf=T.useCallback(async(Y,_e)=>{if(!(!me||Vs.current)){Vs.current=!0,Gt(null),Ni(Y);try{const we=gWn({model:eo.model,serviceTier:eo.serviceTier,permissionMode:eo.permissionMode,planMode:eo.planMode,reasoningLevel:eo.reasoningLevel}),ye=me;(await xAn(ye,Y,_e,we)).turn.existing&&await ms(ye),to(Dm)}catch{Gt(aVe())}finally{Vs.current=!1,Ni(null)}}},[me,eo,ms]),pl=T.useCallback((Y,_e)=>{if(!me||yr||!(Ze!=null&&Ze.agentReady))return;const we=me;dr({type:"busy",sessionId:we,busy:!0}),Da(),Xs(()=>wAn(we,Y,_e)).catch(ye=>{dr({type:"busy",sessionId:we,busy:!1});const $e=ye instanceof Error?ye.message:String(ye);dr({type:"localError",sessionId:we,text:CVe({error:Te($e)})})})},[me,yr,Ze==null?void 0:Ze.agentReady,Da,Xs]),ml=T.useCallback(Y=>{if(!me||yr)return;const _e=me,we=Ea.current;dr({type:"activeLeaf",sessionId:_e,leafId:Y}),Xs(()=>kAn(_e,Y)).catch(ye=>{dr({type:"activeLeaf",sessionId:_e,leafId:we});const $e=ye instanceof Error?ye.message:String(ye);dr({type:"localError",sessionId:_e,text:LXe({error:Te($e)})})})},[me,yr,Xs]);function gl(Y){if(!me)return;const _e=me;mAn(_e,Y).then(({removed:we})=>{if(we)return ms(_e)}).catch(()=>Gt(mVe()))}async function Z(Y){if(!me||Bn)return;const _e=me;Gt(null),Fn(Y);try{await gAn(_e,Y),await ms(_e)}catch{Gt(WVe())}finally{Fn(null)}}const fe=T.useRef(!1);T.useEffect(()=>{const Y=_e=>{fe.current=u4(_e.target)};return document.addEventListener("pointerdown",Y,!0),()=>document.removeEventListener("pointerdown",Y,!0)},[]),T.useEffect(()=>{if(!yr||_!=="chat")return;function Y(_e){var ye;_e.key!=="Escape"||_e.defaultPrevented||(_e.target===document.body?fe.current:u4(_e.target))!==$||(_e.preventDefault(),Ii(),(ye=ln.current)==null||ye.focus())}return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[yr,me,_,$]);function ke(Y){Ry(Y),Ot.current.delete(Y),Vr.current===Y&&(Vr.current=null),dt.current.projectId===e&&dt.current.activeId===Y&&dt.current.mainView==="chat"&&(Bt(""),jr([]),Cr([]),Ht.current(null,{replace:!0})),Lt(_e=>{if(!_e.has(Y))return _e;const we=new Set(_e);return we.delete(Y),we}),ro.current.delete(Y)}function Me(Y,_e){const we=Ao(Y.projectId);vi(Xe,we.queryKey,Y.id),ss(we.queryKey,ye=>ye==null?void 0:ye.map($e=>$e.id===Y.id?{...$e,..._e}:$e))}function De(Y,_e){const we=Y.archived;Me(Y,{archived:_e}),q.mutateAsync([Y.id,_e]).catch(()=>{Me(Y,{archived:we})})}function ct(Y,_e){const we=Y.title;Me(Y,{title:_e}),U.mutateAsync([Y.id,_e]).catch(()=>{Me(Y,{title:we})})}async function _t(Y){var we;const _e=((we=Y.title)==null?void 0:we.trim())||Gv();if(window.confirm(w7e({title:Xl(_e)}))){try{await G.mutateAsync(Y.id)}catch(ye){Xt(R7e({title:Xl(_e),error:Te(ye instanceof Error?ye.message:String(ye))}),"error");return}ke(Y.id)}}const St=T.useCallback(Y=>{if(!me)return Promise.resolve(!1);const _e=me;return dr({type:"busy",sessionId:_e,busy:!0}),Xs(()=>SAn(_e,Y)).then(()=>!0).catch(()=>!1).finally(()=>{Kr(rt.queryKey)&&(Xe.fetchQuery({...Hc(_e),staleTime:0}).catch(()=>{}),Xe.fetchQuery({...Ao(e),staleTime:0}).catch(()=>{}))})},[me,e,Xs,rt]),rn=/Mac|iPhone|iPad/.test(navigator.platform),Ys=rn?"⌘ ⇧ ↵":"Ctrl + Shift + ↵",ls=rn?"⌘ Enter":"Ctrl + Enter",bo=T.useCallback(()=>{Fe("active"),C(null)},[C]),Po=T.useCallback(async()=>{try{const _e=(await Xe.fetchQuery({...aA(),staleTime:0})).reduce((we,ye)=>!we||ye.lastActivityAt>we.lastActivityAt?ye:we,void 0);Fe("active"),C(null,{projectId:(_e==null?void 0:_e.projectId)??e})}catch(Y){Xt(Y instanceof Error?Y.message:String(Y),"error")}},[e,C]),vl=T.useCallback(async Y=>{const _e=Ke.current,we=dt.current;try{const ye=await iAn(Y);if(Ke.current!==_e||dt.current!==we)return;Fe("all"),C(Y,{projectId:ye.projectId})}catch(ye){if(Ke.current!==_e||dt.current!==we)return;Xt(ye instanceof Error?ye.message:String(ye),"error")}},[C]);T.useEffect(()=>{if($)return;const Y=_e=>{_e.repeat||_e.key!=="Enter"||!_e.metaKey&&!_e.ctrlKey||_e.altKey||!_e.shiftKey||u4(_e.target)||(_e.preventDefault(),Po())};return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[Po,$]);const Pi=Y=>vr.messagesBySession[Y.id]?Z_.has(Y.id):Y.awaitingInput===!0,Ps=(Y,_e)=>Y.id===e?vr.busySessions.has(_e.id):_e.busy,un=[];if(re==="projects"&&Be.forEach((Y,_e)=>{const we=ot[_e],$e=(Y.id===e?ft:we.data??WM).filter(lr=>!lr.sideParentSessionId&&(cts(Ce,lr.archived)||lr.id===me)).sort((lr,wo)=>wo.updatedAt-lr.updatedAt),Et=Pt[Y.id]??6;let pt=$e.slice(0,Et);const ir=$e.find(lr=>lr.id===me);ir&&!pt.some(lr=>lr.id===me)&&(pt=[...pt.slice(0,Et-1),ir]);const cr=ve.includes(Y.id);un.push({kind:"project",project:Y,collapsed:cr,busy:cr&&$e.some(lr=>Ps(Y,lr)&&!Pi(lr))}),!cr&&(pt.forEach(lr=>un.push({kind:"chat",project:Y,session:lr})),$e.length>Et&&un.push({kind:"more",project:Y}),!pt.length&&(re==="projects"||we.isPending||we.error)&&un.push({kind:"status",project:Y,pending:we.isPending,error:!!we.error,retry:()=>{we.refetch()}}))}),re==="list"){const Y=((qo=We.data)==null?void 0:qo.pages.flatMap(ye=>ye.sessions))??[],_e=ft.find(ye=>ye.id===me);_e&&!Y.some(ye=>ye.id===_e.id)&&Y.push(_e),Y.filter(ye=>!Bc.has(ye.id)).sort((ye,$e)=>$e.updatedAt-ye.updatedAt).forEach(ye=>{const $e=ce.find(Et=>Et.id===ye.projectId);$e&&un.push({kind:"chat",project:$e,session:ye})});const we=je??ce[0];we&&(!un.length||We.isFetchingNextPage||We.isError)&&un.push({kind:"status",project:we,pending:We.isPending||We.isFetchingNextPage,error:We.isError,retry:()=>{We.isFetchNextPageError?We.fetchNextPage():We.refetch()}})}const Bo=re==="list"||Ye,sf=fR(un,ut,me),Ru=sf.lengthY+ag(_e),0),Ho=Y=>Y.kind==="chat"?Y.session.id:`${Y.kind}:${Y.project.id}`,xo=xH({count:un.length,getScrollElement:()=>Ie.current,getItemKey:Y=>Ho(un[Y]),estimateSize:Y=>ag(un[Y]),overscan:5,rangeExtractor:Y=>{const _e=eC(Y),we=un.findIndex(ye=>Ho(ye)===Ut);return we<0||_e.includes(we)?_e:[..._e,we].sort((ye,$e)=>ye-$e)},enabled:Bo&&a&&!$}),fi=xo.getVirtualItems(),Bp=((Id=fi.at(-1))==null?void 0:Id.index)??-1;T.useEffect(()=>{re==="list"&&a&&!$&&Bp>=un.length-6&&We.hasNextPage&&!We.isFetching&&!We.isError&&We.fetchNextPage()},[re,a,$,Bp,un.length,We.hasNextPage,We.isFetching,We.isError,We.fetchNextPage]);const Dd=u.jsxs("aside",{className:"session-rail w-75 shrink-0 flex flex-col mt-5 mac-titlebar:mt-8 me-3.5 mb-5 ms-0 bg-background min-h-0 [&_.rail-body]:flex-1 [&_.rail-body]:min-h-0 [&_.rail-body]:pt-0 [&_.rail-body]:pb-0 [&_.rail-body]:ps-2 [&_.rail-body]:pe-1 border border-border rounded-lg overflow-visible shadow-elevated",children:[o,u.jsxs("nav",{className:"rail-nav flex flex-col gap-0.5 p-2 shrink-0",children:[u.jsxs("button",{className:"rail-nav-item flex items-center gap-2.5 py-[7px] px-2.5 text-base text-text rounded-md text-start hover:bg-surface [&[data-tip]::after]:top-auto [&[data-tip]::after]:bottom-[calc(100%_+_6px)]","data-onboarding":"new-session","data-tip":Ys,"aria-keyshortcuts":"Meta+Shift+Enter Control+Shift+Enter",onClick:Po,children:[u.jsx(du,{size:15}),a3()]}),u.jsxs("button",{className:`rail-nav-item flex items-center gap-2.5 py-[7px] px-2.5 text-base text-text rounded-md text-start [&:hover:not(.active)]:bg-surface [&.active]:bg-panel [&.active]:font-medium ${_==="skills"?"active":""}`,onClick:()=>d("skills"),children:[u.jsx(kP,{size:15}),DMe()]}),mJn.map(Y=>u.jsxs("button",{className:`rail-nav-item flex items-center gap-2.5 py-[7px] px-2.5 text-base text-text rounded-md text-start [&:hover:not(.active)]:bg-surface [&.active]:bg-panel [&.active]:font-medium ${_!=="chat"&&_!=="skills"&&Y.activeTabs.includes(_)?"active":""}`,"data-onboarding":Y.id==="compute"?"nav-compute":void 0,onClick:()=>d(Y.id),children:[Y.icon,Y.label()]},Y.id))]}),u.jsxs("div",{className:"rail-section-head flex items-center justify-between shrink-0 pt-3.5 pe-2.5 pb-0 ps-4.5",children:[u.jsx("div",{className:"rail-section-label p-0 text-sm font-medium text-subtext",children:re==="projects"?dS():eD()}),u.jsxs("div",{className:"rail-section-actions flex items-center gap-0.5",children:[c&&u.jsx(Va,{interactive:!0,content:Cb(),className:"rounded-sm",children:u.jsx(kt,{size:"small",className:"text-subtext","aria-label":Cb(),onClick:c,children:u.jsx(cOn,{size:15,className:"text-subtext"})})}),u.jsx(uts,{value:Ce,onChange:Fe,grouping:re,onGroupingChange:Y=>{W(Y);try{localStorage.setItem("sidebar-grouping",Y)}catch{}Oe(!1),mt({}),Ie.current&&(Ie.current.scrollTop=0)}})]})]}),u.jsxs("div",{className:"relative flex-1 min-h-0",children:[u.jsx("div",{ref:Ie,tabIndex:-1,className:`rail-body h-full overflow-x-hidden ${Bo?"overflow-y-auto":"overflow-y-hidden"}`,children:u.jsxs("div",{className:"relative",style:{height:(Bo?xo.getTotalSize():Bi)+(yo?38:0)+(Ye?46:0)},children:[(Bo?fi.map(Y=>({row:un[Y.index],top:Y.start,index:Y.index})):Fo.map((Y,_e)=>({row:Y,top:0,index:_e}))).map(({row:Y,top:_e,index:we})=>{var Et;const ye=Y.project,$e=Y.kind==="chat"?Y.session:null;return u.jsx("div",{"data-index":we,onFocusCapture:()=>Wt(Ho(Y)),onBlurCapture:pt=>{pt.currentTarget.contains(pt.relatedTarget)||Wt(null)},className:Bo?"absolute top-0 start-0 w-full":"relative",style:{height:ag(Y),transform:Bo?`translateY(${_e}px)`:void 0},children:Y.kind==="project"?u.jsx("div",{className:"group h-9 flex items-end gap-1 rounded-md px-2.5 text-text",children:u.jsx(LGn,{project:ye,chatCount:(Et=ue.find(pt=>pt.projectId===ye.id))==null?void 0:Et.totalAgents,collapsed:Y.collapsed,busy:Y.busy,onToggleCollapsed:()=>{const pt=ve.includes(ye.id)?ve.filter(ir=>ir!==ye.id):[...ve,ye.id];xe(pt);try{localStorage.setItem("sidebar-collapsed-projects",JSON.stringify(pt))}catch{}},pinned:ae.includes(ye.id),onPin:()=>{const pt=ae.includes(ye.id)?ae.filter(ir=>ir!==ye.id):[...ae,ye.id];ie(pt);try{localStorage.setItem("sidebar-pinned-projects",JSON.stringify(pt))}catch{}},onRemoved:()=>{ye.id===e&&oe({to:"/projects"})},onNewChat:()=>{ye.id===e?bo():oe({to:"/projects/$projectId/tasks/new",params:{projectId:ye.id}})}})}):$e?u.jsx("div",{className:re==="projects"?"ms-5.5":void 0,children:u.jsx(hts,{session:$e,active:$e.id===me&&_==="chat",unread:or.has($e.id),busy:Ps(ye,$e),waiting:Pi($e),revealTitle:oi.get($e.id),onOpen:()=>{if(ye.id===e?C($e.id):oe({to:"/projects/$projectId/tasks/$sessionId",params:{projectId:ye.id,sessionId:$e.id}}),ye.id===Cm){uLn($e.id);const pt=I9n[$e.id];pt&&(l_({name:"demo_experiment_started",kind:"curated",experiment:pt}),l_({name:"first_action",surface:"demo",action:"open_experiment"}))}},onRename:pt=>ct($e,pt),onSetArchived:pt=>De($e,pt),onDelete:()=>void _t($e)},$e.id)}):Y.kind==="more"?u.jsx(Ee,{variant:"ghost",size:"small",className:"ms-5.5 font-normal text-subtext",onClick:()=>{Oe(!0),mt(pt=>({...pt,[ye.id]:(pt[ye.id]??6)+6}))},children:c3()}):Y.kind==="status"&&u.jsx("div",{className:`flex h-full items-center px-2.5 text-sm text-subtext ${re==="projects"?"ms-5.5":""}`,children:Y.error?u.jsx(Ee,{size:"small",onClick:Y.retry,children:rs()}):Y.pending?u.jsx(Rt,{}):Ce==="archived"?P9e():Q9e()})},Ho(Y))}),yo&&u.jsx("div",{className:"absolute start-0 flex h-9.5 w-full items-center pt-1",style:{top:Bo?xo.getTotalSize():Bi},children:u.jsx(Ee,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{Oe(!0)},children:c3()})}),Ye&&u.jsx("div",{className:"absolute start-0 w-full pt-1",style:{top:xo.getTotalSize()+(yo?38:0)},children:u.jsx(Ee,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{Oe(!1),mt({}),Wt(null),Ie.current&&(Ie.current.scrollTop=0,Ie.current.focus())},children:My()})})]})}),Bo&&u.jsxs(u.Fragment,{children:[(xo.scrollOffset??0)>0&&u.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-5 h-3 bg-linear-to-b from-background to-transparent"}),u.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-5 h-3 bg-linear-to-t from-background to-transparent"})]})]}),u.jsx(GB,{runtime:b})]}),Fp="chat-header flex items-center gap-2 py-0 px-4 bg-background shrink-0 h-12 relative z-4 w-full max-w-readable my-0 mx-auto [&::after]:content-[''] [&::after]:absolute [&::after]:top-full [&::after]:start-0 [&::after]:end-0 [&::after]:h-6 [&::after]:bg-[linear-gradient(to_bottom,_var(--base),_transparent)] [&::after]:pointer-events-none",Hp=!a&&!$&&u.jsx(kt,{title:OE(),"aria-label":OE(),onClick:i,className:"mac-titlebar:ms-16",children:u.jsx(LP,{size:20})});return _!=="chat"?u.jsxs(u.Fragment,{children:[a&&Dd,u.jsxs("section",{className:"chat-pane flex-1 min-w-0 flex flex-col bg-background min-h-0",children:[!a&&u.jsx("div",{className:"flex h-12 shrink-0 items-center",children:Hp}),u.jsx("div",{className:"settings-view-scroll flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",children:n?u.jsxs("div",{role:"alert",className:"p-6 text-subtext",children:[n,u.jsx(Ee,{onClick:s,children:rs()})]}):t?u.jsxs(ds,{className:"p-6",children:[u.jsx(Rt,{}),CE()]}):B},_)]})]}):u.jsxs(u.Fragment,{children:[a&&Dd,u.jsxs("section",{"data-side-chat":$||void 0,className:`chat-pane flex-1 min-w-0 flex flex-col bg-background min-h-0 ${$?"":"mt-5"}`,children:[u.jsxs("div",{className:a||$?"contents":"grid shrink-0 grid-cols-[2rem_minmax(0,1fr)_2rem] mac-titlebar:grid-cols-[6rem_minmax(0,1fr)_6rem] items-center",children:[Hp,u.jsxs("div",{className:Fp,children:[u.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:tn&&u.jsxs(u.Fragment,{children:[(Hi=tn.title)!=null&&Hi.trim()?u.jsx(zg,{variant:"header",className:"flex-initial",title:tn.title.trim(),children:u.jsx(JU,{title:tn.title.trim(),animate:J_!==void 0},J_??"static")}):yr?u.jsx(Rt,{}):null,u.jsx("span",{className:"min-w-0 truncate rounded-md border border-border bg-surface px-2.5 py-0.5 text-sm font-normal text-subtext",title:r,children:r})]})}),y&&u.jsx(kt,{"data-tip":fE(),"aria-label":fE(),onClick:y,children:u.jsx(CP,{size:15})})]})]}),n?u.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[u.jsx("p",{children:n}),u.jsx(Ee,{onClick:s,children:rs()})]}):Io?u.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[u.jsx("p",{children:Io.message}),u.jsx(Ee,{onClick:()=>void qr.refetch(),children:rs()})]}):t||Nu?u.jsx("div",{className:"chat-loading flex-1 min-h-0 overflow-hidden [scrollbar-gutter:stable_both-edges]",role:"status","aria-label":CE(),"aria-busy":"true",children:u.jsxs("div",{"aria-hidden":"true",className:"mx-auto flex h-full w-full max-w-readable flex-col gap-6 px-4 pb-8 pt-4 motion-safe:animate-pulse",children:[u.jsx("div",{className:"ms-auto h-14 w-3/5 shrink-0 rounded-lg bg-panel"}),u.jsx("div",{className:"flex shrink-0 flex-col gap-3",children:["w-5/6","w-full","w-11/12","w-2/3","w-full","w-3/4","w-1/2"].map((Y,_e)=>u.jsx("div",{className:`h-3 rounded bg-panel ${Y}`},_e))}),u.jsx("div",{className:"ms-auto h-10 w-2/5 shrink-0 rounded-lg bg-panel"}),u.jsx("div",{className:"flex shrink-0 flex-col gap-3",children:["w-full","w-11/12","w-3/4","w-5/6","w-1/2","w-full","w-5/6","w-11/12","w-2/3","w-3/4","w-1/3"].map((Y,_e)=>u.jsx("div",{className:`h-3 rounded bg-panel ${Y}`},_e))}),u.jsx("div",{className:"ms-auto h-16 w-1/2 shrink-0 rounded-lg bg-panel"})]})}):!Do&&(tn!=null&&tn.sideParentSessionId)?u.jsxs("div",{className:"chat-empty flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center text-subtext",children:[u.jsx(kg,{size:22}),u.jsx("p",{className:"m-0 text-balance",children:mcn()})]}):Do?u.jsx("div",{className:"chat-thread flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",ref:Ta,tabIndex:0,role:"region","aria-label":((qp=tn==null?void 0:tn.title)==null?void 0:qp.trim())||Gv(),onScroll:Y=>{vc(Y.currentTarget),Ra.dismiss()},children:u.jsxs("div",{className:"chat-thread-inner max-w-readable my-0 mx-auto pt-4 px-4 pb-8 flex flex-col gap-4",ref:Vn,children:[u.jsx(mU,{projectId:e,sessionId:me,children:u.jsx(its,{scrollRef:Ta,scrollToEndRef:mo,stickToBottom:Qn,onPinToBottom:Da,messages:gs,allMessages:hc,canFork:ll,onFork:pl,onSelectFork:ml,busy:yr,onOpenFile:ca,onOpenRun:p,onOpenSpawnedSession:vl,runExperimentName:m,onOpenExperiment:x,experimentName:k,onRespond:St,onOpenPlan:Oa,onOpenSubagent:vs,recoveringTurnId:As,onRecover:nf,skills:$d},me)}),yr&&Au&&u.jsx("div",{className:"flex items-center gap-2 text-subtext text-sm pt-0.5 px-0 pb-2 italic",children:aD()}),yr&&!Au&&!ul&&!Md&&u.jsx("div",{className:"text-base pt-0.5 px-1 pb-2",children:u.jsx("span",{className:"tool-running-shimmer",children:rYe()})})]})}):u.jsxs("div",{className:"chat-empty flex-1 flex flex-col items-center justify-center text-text p-8 text-center [&_h2]:m-0 [&_h2]:text-5xl [&_h2]:font-medium [&_h2]:tracking-[-0.015em] [&_h2]:text-text",children:[u.jsx("div",{className:"chat-empty-mark w-10.5 h-10.5 mb-5.5 [&_svg]:block [&_svg]:w-full [&_svg]:h-full",children:u.jsx(Ky,{})}),u.jsx("h2",{children:vWe()}),Tu&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:YM,"aria-hidden":"true",children:XM.map((Y,_e)=>u.jsxs("div",{className:`flex min-h-22 animate-pulse flex-col items-start justify-center gap-2.5 rounded-xl border bg-background px-5 py-4 ${_4[_e].box}`,children:[u.jsxs("span",{className:`flex w-full items-center gap-2.5 ${_4[_e].icon}`,children:[u.jsx(Y,{size:17}),u.jsx("span",{className:"h-3.5 w-2/5 rounded bg-panel"})]}),u.jsx("span",{className:"h-3 w-4/5 rounded bg-panel"})]},_e))}),u.jsxs(ds,{className:"mt-3",role:"status",children:[u.jsx(Rt,{}),u.jsx("span",{children:NUe()})]})]}),La&&La.length>0&&u.jsx("div",{className:YM,role:"group","aria-label":PUe(),children:La.map((Y,_e)=>{const we=XM[_e],ye=_4[_e],$e=Et=>{l_({name:"project_starter_clicked",slot:_e+1}),l_({name:"first_action",surface:Is,action:"starter_click"});const pt=!Zt.trim()&&gr.length===0&&Lr.length===0;Et||!(Ze!=null&&Ze.agentReady)||!pt?tf(Y.prompt):_i({starter:Y.prompt})};return u.jsxs("div",{className:"relative min-w-0",children:[u.jsxs("button",{type:"button",className:`flex h-full min-h-22 w-full min-w-0 cursor-pointer flex-col items-start justify-center gap-1.5 rounded-xl border bg-background py-4 ps-5 pe-11 text-start font-sans transition-colors duration-120 ease-standard hover:bg-surface ${ye.box}`,onClick:()=>$e(!1),children:[u.jsxs("span",{className:"flex items-center gap-2.5 text-base font-medium text-text",children:[u.jsx(we,{size:17,className:ye.icon}),Y.title]}),u.jsx("span",{className:"w-full truncate text-sm text-subtext",children:Y.prompt})]}),u.jsx(kt,{size:"small",className:"absolute end-2.5 top-2.5 [&:hover:not(:disabled)]:bg-surface-bright","aria-label":$E({title:Y.title}),title:$E({title:Y.title}),onClick:()=>$e(!0),children:u.jsx(Hy,{size:13})})]},_e)})})]}),Ra.action&&u.jsxs(Ee,{type:"button",size:"small",className:"chat-selection-action fixed z-50 shadow-control",style:{left:Ra.action.x,top:Ra.action.top,transform:"translateX(-50%)"},onMouseDown:Y=>Y.preventDefault(),onClick:Ra.add,children:[u.jsx(OP,{size:14}),SAe()]}),u.jsxs("div",{inert:t||!!n||Nu,className:"composer px-3 pb-5 shrink-0 relative z-4 bg-background w-full max-w-readable my-0 mx-auto [&_textarea]:border-0 [&_textarea]:bg-none [&_textarea]:bg-transparent [&_textarea]:resize-none [&_textarea]:pt-2.5 [&_textarea]:px-3 [&_textarea]:pb-1 [&_textarea]:text-base [&_textarea]:field-sizing-content [&_textarea]:min-h-18 [&_textarea]:max-h-45",children:[Do&&u.jsx(kt,{className:`absolute bottom-full left-1/2 z-5 mb-6 h-9 w-9 -translate-x-1/2 rounded-full border border-border bg-background shadow-control transition-opacity duration-150 ease-standard ${go?"opacity-0":"opacity-100"}`,title:IE(),"aria-label":IE(),inert:go,onClick:ui,children:yr&&!Au?u.jsx(Sp,{size:18,className:"tool-running-shimmer-icon"}):u.jsx(vMn,{size:16})}),ao&&!(dl&&ao.promptId===dl.promptId)&&u.jsx(wZn,{synthesized:ao.synthesized,agentLabel:tn?Af(tn.harness,tn.harnessName):WXe(),showResumeModes:(tn==null?void 0:tn.harness)==="claude-code",onView:Y=>Oa==null?void 0:Oa(ao.plan,ao.promptId,Y),onApprove:Y=>St({promptId:ao.promptId,approve:!0,...Y?{resumeMode:Y}:{}}),onReject:()=>St({promptId:ao.promptId,approve:!1}),onRevise:Y=>{me&&Ur({sessionId:me,promptId:ao.promptId}),St({promptId:ao.promptId,approve:!1,note:Y})}}),$o.length>0&&u.jsx("div",{className:"composer-queued flex flex-col gap-1 mb-1.5",children:$o.map((Y,_e)=>u.jsxs("div",{className:"queued-chip flex flex-wrap items-center gap-x-2 gap-y-1 py-1.5 px-2.5 text-sm text-subtext bg-background border border-border rounded-sm",title:Y.error?`${Y.text} ${Y.error}`:Y.text,children:[Y.dispatchState==="blocked"?u.jsx(LS,{size:13,className:"shrink-0 text-accent-amber"}):u.jsx(FMn,{size:13,className:"shrink-0 text-muted"}),u.jsx("span",{className:"flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-text",children:Y.text}),Y.dispatchState!=="blocked"&&u.jsx("span",{className:"shrink-0 text-sm text-muted",children:Y.dispatchState==="retrying"?mWn(Y.nextRetryAt,Di):TKe()}),Y.dispatchState==="blocked"?u.jsxs(u.Fragment,{children:[u.jsx("button",{onClick:()=>void Z(Y.id),"aria-label":Xre({text:Y.text}),disabled:Bn!==null,className:"shrink-0 px-1.5 py-0.5 border border-border rounded-sm text-sm text-text bg-background cursor-pointer disabled:opacity-50 disabled:cursor-default [&:hover:not(:disabled)]:border-text",children:Bn===Y.id?ID():rs()}),u.jsx("button",{onClick:()=>gl(Y.id),"aria-label":Bre({text:Y.text}),disabled:Bn!==null,className:"shrink-0 px-1.5 py-0.5 border-0 text-sm text-muted bg-transparent cursor-pointer disabled:opacity-50 disabled:cursor-default [&:hover:not(:disabled)]:text-text",children:nD()}),_e===Od&&_e<$o.length-1&&u.jsx("span",{className:"basis-full ps-5 text-sm text-muted",children:CLe()})]}):u.jsx("button",{title:TE(),"aria-label":TE(),onClick:()=>gl(Y.id),className:"shrink-0 inline-flex items-center justify-center w-4 h-4 p-0 border-0 rounded-full text-muted cursor-pointer [&:hover]:bg-text [&:hover]:text-background",children:u.jsx(pn,{size:11})})]},Y.id))}),rf&&u.jsxs("div",{id:Ld,role:"note",className:`composer-demo-hint ${gts}`,children:[u.jsxs("span",{className:"flex-1",dir:"auto",children:[u.jsx(w0,{size:16,className:"inline-block align-text-bottom me-2 text-primary"}),xOe()]}),u.jsx(kt,{size:"small","aria-label":bE(),title:bE(),onClick:()=>{var Y;Sn(!0),(Y=ln.current)==null||Y.focus()},children:u.jsx(pn,{size:14})})]}),!$&&!me&&c&&u.jsx($Gn,{projects:ce,activity:ue,projectId:e,projectName:r,onNewProject:c,onSelect:Y=>{Y!==e&&oe({to:"/projects/$projectId/tasks/new",params:{projectId:Y}})}}),u.jsxs("div",{className:`composer-box relative flex flex-col border ${bn?"border-accent-amber":"border-border"} rounded-lg bg-background shadow-elevated`,"data-onboarding":"composer",children:[Ze&&!Ze.agentReady&&u.jsx("div",{className:"composer-harness-warning py-2 px-3 text-subtext text-sm leading-normal border-b border-b-border-variant [&_strong]:text-accent-amber [&_strong]:font-medium [&_code]:font-mono [&_code]:text-text",children:Ze.catalogPending?u.jsxs("span",{children:[Ze.name," — ",td()]}):u.jsxs(u.Fragment,{children:[u.jsxs("strong",{children:[Ze.name," ",mLe()]})," ",Ze.agentNote?M_(Ze.agentNote,F&&{canRun:Y=>Ti(Y)!==void 0,onRun:Y=>{const _e=Ti(Y);_e&&F(Y,_e)}}):XKe()]})}),Ad&&u.jsx(RJn,{skills:uc,activeIndex:Mi,onPick:xu,onHover:cc}),Td&&u.jsx(UJn,{matches:Oi,activeIndex:ku,onPick:zn,onHover:Ma}),ic&&u.jsx(QJn,{activeSessionId:me,onClose:()=>Ts(!1),onResume:Y=>{Ts(!1),Fe("all"),C(Y.id,{projectId:Y.projectId})},onImport:Y=>{Ts(!1),zu(Y)}}),Lr.length>0&&u.jsx(bes,{annotations:Lr,onClear:()=>{Cr([]),window.requestAnimationFrame(()=>{var Y;return(Y=ln.current)==null?void 0:Y.focus()})},onRemove:Y=>{const _e=Lr.filter(we=>we.id!==Y);Cr(_e),_e.length===0&&window.requestAnimationFrame(()=>{var we;return(we=ln.current)==null?void 0:we.focus()})}}),gr.length>0&&u.jsx("div",{className:"composer-attachments flex flex-wrap gap-1.5 pt-2 px-3 pb-0",children:gr.map((Y,_e)=>{const we=()=>jr(ye=>ye.filter(($e,Et)=>Et!==_e));return Y.mediaType==="application/pdf"?u.jsxs("div",{className:"attachment-file [&_button]:absolute [&_button]:-top-[5px] [&_button]:-right-[5px] [&_button]:inline-flex [&_button]:items-center [&_button]:justify-center [&_button]:w-4 [&_button]:h-4 [&_button]:p-0 [&_button]:border [&_button]:border-border [&_button]:rounded-full [&_button]:bg-surface [&_button]:text-text [&_button]:cursor-pointer [&_button:hover]:bg-text [&_button:hover]:text-background relative inline-flex items-center gap-2 max-w-55 py-2 px-2.5 border border-border rounded-sm text-text bg-surface [&_svg]:shrink-0 [&_svg]:text-muted",title:Y.name,children:[u.jsx(By,{size:22}),u.jsx("span",{className:"attachment-file-name overflow-hidden text-ellipsis whitespace-nowrap text-sm",children:Y.name??"document.pdf"}),u.jsx("button",{title:NE(),"aria-label":NE(),onClick:we,children:u.jsx(pn,{size:11})})]},_e):u.jsxs("div",{className:"attachment-thumb relative [&_img]:w-13 [&_img]:h-13 [&_img]:object-cover [&_img]:border [&_img]:border-border [&_img]:rounded-sm [&_img]:block [&_button]:absolute [&_button]:-top-[5px] [&_button]:-right-[5px] [&_button]:inline-flex [&_button]:items-center [&_button]:justify-center [&_button]:w-4 [&_button]:h-4 [&_button]:p-0 [&_button]:border [&_button]:border-border [&_button]:rounded-full [&_button]:bg-surface [&_button]:text-text [&_button]:cursor-pointer [&_button:hover]:bg-text [&_button:hover]:text-background",children:[u.jsx("img",{src:Y.dataUrl,alt:iD()}),u.jsx("button",{title:AE(),"aria-label":AE(),onClick:we,children:u.jsx(pn,{size:11})})]},_e)})}),(Qs??nr)&&u.jsx("div",{className:"composer-attach-error pt-1.5 px-3 pb-0 text-sm text-accent-red",role:"alert",children:Qs??nr}),cn&&u.jsx("div",{className:"composer-settings-error pt-1.5 px-3 pb-0 text-sm text-accent-red",role:"alert",children:cn}),u.jsxs("div",{className:`composer-input relative flex overflow-hidden [&_textarea]:flex-1 ${bn?"[&_textarea]:font-mono [&_textarea]:text-sm":""}`,children:[u.jsx("textarea",{dir:"auto",ref:ln,"aria-describedby":rf?Ld:void 0,className:"relative z-1 bg-transparent",value:Zt,placeholder:Lo?AYe():hl&&Ze?mXe({harness:Te(Ze.name),shortcut:Te(ls)}):hr?Ze!=null&&Ze.agentReady?qze({harness:Te(Af(hr.harness,Ze==null?void 0:Ze.name))}):kze({harness:Te(Af(hr.harness,Ze==null?void 0:Ze.name))}):r6e(),rows:2,onPaste:Xn,onDragOver:Y=>{Y.dataTransfer.types.includes("Files")&&Y.preventDefault()},onDrop:Y=>{Y.dataTransfer.files.length!==0&&(Y.preventDefault(),$s(Array.from(Y.dataTransfer.files)))},onChange:Y=>{const _e=Y.target.value,we=Y.target.selectionStart;Ms(we);const ye=we>0&&/\s/.test(_e[we-1])&&!Lo&&!Os.current&&BM(_e)===null?t4(_e,we-1):null,$e=ye&&nj(ye.query),Et=ye?(_e.slice(0,ye.start)+_e.slice(ye.end)).trim():"";if(ye&&$e&&($e==="plan"||!r4($e)&&!Et)&&aa.some(pt=>pt.name===$e)){il($e,_e,ye);return}Bt(_e),so(!1)},onSelect:Y=>Ms(Y.currentTarget.selectionStart),onCompositionStart:()=>{Os.current=!0},onCompositionEnd:()=>{Os.current=!1},onKeyDown:Y=>{if(Os.current||Y.nativeEvent.isComposing||Y.nativeEvent.keyCode===229){Y.stopPropagation();return}if(Ad){if(Y.key==="ArrowDown"||Y.key==="ArrowUp"){Y.preventDefault();const _e=Y.key==="ArrowDown"?1:-1;cc((Mi+_e+uc.length)%uc.length);return}if(Y.key==="Tab"||Y.key==="Enter"){Y.preventDefault(),xu(uc[Mi]);return}if(Y.key==="Escape"){Y.preventDefault(),so(!0);return}}if(Td){if(Y.key==="ArrowDown"||Y.key==="ArrowUp"){Y.preventDefault();const _e=Y.key==="ArrowDown"?1:-1;Ma((ku+_e+Oi.length)%Oi.length);return}if(Y.key==="Tab"||Y.key==="Enter"&&_c!==""&&!Y.shiftKey&&!Y.metaKey&&!Y.ctrlKey){Y.preventDefault(),zn(Oi[ku]);return}if(Y.key==="Escape"){Y.preventDefault(),so(!0);return}}if(Y.key==="Backspace"&&Rn(Y.currentTarget)){Y.preventDefault();return}if(Y.key==="Enter"&&!Y.shiftKey){if(Y.preventDefault(),bn){co();return}_i({queue:Y.metaKey||Y.ctrlKey})}}}),u.jsx(TJn,{text:Zt,editingTokenEnd:is==null?void 0:is.end,isCommand:mc,skills:aa,projectId:e,textareaRef:ln})]}),u.jsxs("div",{className:"composer-actions flex min-w-0 justify-end items-center gap-2 pt-1.5 px-2 pb-2",children:[u.jsxs("div",{className:"option-picker relative inline-flex shrink-0",ref:yu.ref,children:[u.jsx(kt,{type:"button",className:"composer-bare",title:Fw(),"aria-label":Fw(),"aria-haspopup":"dialog","aria-expanded":yu.open,onClick:()=>yu.setOpen(Y=>!Y),children:u.jsx(w$n,{size:16})}),yu.open&&u.jsxs("div",{className:"composer-sources-menu absolute bottom-[calc(100%_+_8px)] start-0 z-50 flex min-w-55 flex-col gap-1 rounded-md border border-border bg-background p-2 shadow-dropdown",children:[u.jsx("span",{className:"px-1 text-sm font-medium text-muted",children:Fw()}),u.jsx(zWn,{})]})]}),u.jsx("input",{ref:bt,type:"file",accept:"application/pdf,image/png,image/jpeg,image/gif,image/webp",multiple:!0,hidden:!0,onChange:Y=>{$s(Array.from(Y.target.files??[])),Y.target.value=""}}),u.jsx(kt,{type:"button",className:"composer-attach",title:hE(),"aria-label":hE(),onClick:()=>{var Y;return(Y=bt.current)==null?void 0:Y.click()},children:u.jsx(ZOn,{size:16})}),$i&&u.jsxs(Ee,{type:"button",variant:"ghost",active:!0,className:"group max-w-60",title:vE({goal:Xl($i)}),"aria-label":vE({goal:Xl($i)}),onClick:()=>void al("clear"),children:[u.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[u.jsx(RP,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.6}),u.jsx(pn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.8})]}),u.jsx("span",{className:"truncate",children:aLe()})]}),Cu&&u.jsxs(Ee,{type:"button",variant:"ghost",active:!0,className:"group",title:kE(),"aria-label":kE(),onClick:()=>void X_(),children:[u.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[u.jsx(NOn,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.6}),u.jsx(pn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.8})]}),u.jsx("span",{children:sIe()})]}),bn&&u.jsxs(Ee,{type:"button",variant:"ghost",active:!0,className:"group",title:wE(),"aria-label":wE(),onClick:bc,children:[u.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[u.jsx(R_,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.6}),u.jsx(pn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.8})]}),u.jsx("span",{children:tD()})]}),u.jsx("div",{className:"min-w-0 flex-1"}),u.jsxs("div",{className:"flex min-w-0 items-center",children:[u.jsx(TLn,{sessionHarness:lt!=null&<.harness.startsWith("acp:")?Ze:void 0,value:hr,onSelect:dc,onOpenSettings:()=>d("harnesses"),permissionChoices:Ze!=null&&Ze.agentReady?(Jt==null?void 0:Jt.permissionModes)??[]:[],defaultPermissionId:(Jt==null?void 0:Jt.defaultPermissionMode)??null,onSelectPermission:ol,reasoningChoices:Ze!=null&&Ze.agentReady?ju.choices:[],defaultReasoningId:ju.defaultId,onSelectReasoning:V_,autonomy:(lt==null?void 0:lt.autonomy)??R,onSelectAutonomy:Ip,lockHarness:!!lt,openRequest:oo,nativeOptions:lt!=null&<.harness.startsWith("acp:")?oa.filter(Y=>Y.category!=="model"):[],onSelectNativeOption:(Y,_e)=>{lt&&QN(lt.id,Y,_e).catch(we=>Xt(we instanceof Error?we.message:String(we),"error"))}}),u.jsx(WJn,{usage:lt==null?void 0:lt.contextUsage})]}),yr&&!Lo?u.jsx(kt,{className:"send-btn",variant:"stop",title:LE(),"aria-label":LE(),onClick:Ii,children:u.jsx(pn,{size:16})}):u.jsx(kt,{className:`send-btn ${rf&&(Ze!=null&&Ze.agentReady)?"ring-2 ring-primary ring-offset-2 ring-offset-background":""}`,variant:"primary",title:bn?RE():i3(),"aria-label":bn?RE():i3(),onClick:()=>void(bn?co():_i()),disabled:bn?!lc||!me&&!(Ze!=null&&Ze.agentReady):!(Ze!=null&&Ze.agentReady)||!Zt.trim()&&gr.length===0&&Lr.length===0,children:u.jsx(NP,{size:16})})]})]})]})]})]})}const gts="flex items-center gap-2.5 mb-2.5 py-2 ps-3.5 pe-2 rounded-lg border border-border bg-surface text-text text-sm leading-normal",vts=[],bts=[];function ga({className:e,...r}){return u.jsx("div",{className:ns("relative flex min-h-0 flex-1 flex-col",e),...r})}function $h({className:e,...r}){return u.jsx("div",{className:ns("min-h-0 flex-1 overflow-auto bg-background",e),...r})}function Ic({className:e,...r}){return u.jsx("div",{className:ns("shrink-0 border-b border-b-border-variant px-4 py-2 text-sm text-muted",e),...r})}const JM=["pane-content flex-1 min-h-0 relative subagent-tab-content overflow-y-auto","bg-background py-8 px-4"].join(" ");function yts({projectId:e,sessionId:r,spawnPartId:t,onOpenFile:n,onOpenRun:s,runExperimentName:o,onOpenExperiment:a,experimentName:i,onOpenSubagent:c}){var k;const _=nt(Hc(r)),d=((k=_.data)==null?void 0:k.messages)??(_.isError?[]:null),f=T.useRef(null),p=T.useRef(null),m=T.useRef(!0);if(T.useLayoutEffect(()=>{m.current=!0;const v=f.current;v&&(v.scrollTop=v.scrollHeight)},[r,t]),T.useLayoutEffect(()=>{const v=f.current;v&&m.current&&(v.scrollTop=v.scrollHeight)},[d]),T.useEffect(()=>{const v=f.current,w=p.current;if(!v||!w)return;const b=new ResizeObserver(()=>{m.current&&(v.scrollTop=v.scrollHeight)});return b.observe(w),b.observe(v),()=>b.disconnect()},[d===null]),d===null)return u.jsx(ga,{children:u.jsx("div",{className:JM,children:u.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:dI()})})});let x=null;for(const v of d)if(x=ly(v.parts,t),x)break;return u.jsx(ga,{children:u.jsx("div",{className:JM,ref:f,onScroll:v=>{const w=v.currentTarget;m.current=w.scrollHeight-w.scrollTop-w.clientHeight<60},children:u.jsx("div",{ref:p,children:x?u.jsx(mU,{projectId:e,sessionId:r,children:u.jsx(nts,{spawn:x,onOpenFile:n,onOpenRun:s,runExperimentName:o,onOpenExperiment:a,experimentName:i,onOpenSubagent:c})}):u.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:vxn()})})})})}function xts({experiment:e}){var s;const r=nt(eF(e.id)),t=r.data,n=(s=r.error)==null?void 0:s.message;return u.jsx($h,{className:"branch-changes [&_>_.changes-note]:mx-4 [&_>_.changes-note]:my-3.5 [&_>_.diff-explorer]:mx-4 [&_>_.diff-explorer]:mb-0 [&_>_.diff-explorer]:mt-3.5 [&_>_.openresearch-diff]:mx-4 [&_>_.openresearch-diff]:mb-0 [&_>_.openresearch-diff]:mt-3.5 [&_>_.truncated-notice]:mx-4 [&_>_.truncated-notice]:mb-0 [&_>_.truncated-notice]:mt-3.5",children:n&&!t?u.jsxs(Ic,{children:[Rje()," ",Te(n)]}):t?t.diff.trim()?u.jsxs(u.Fragment,{children:[t.truncated&&u.jsx(PF,{bytesRead:t.bytesRead,byteLimit:t.byteLimit}),u.jsx(FF,{diff:t.diff,partial:t.truncated})]}):u.jsx("div",{className:"changes-note text-sm text-muted",children:e.parentExperimentId?Zje():wje()}):u.jsx(Ic,{children:Hje()})})}function eG({view:e,onViewChange:r,showViewToggle:t=!0,branchLabel:n,branchTitle:s,githubHref:o,githubTitle:a,refreshing:i,onRefresh:c}){return u.jsxs("div",{className:"code-tab-header flex items-center gap-2 py-1.5 px-3 border-b border-b-border-variant shrink-0 [&_>_.seg]:p-0.5 [&_>_.seg]:rounded-sm [&_>_.seg_button]:py-0.5 [&_>_.seg_button]:px-2 [&_>_.seg_button]:text-sm [&_>_.seg_button]:font-medium",children:[t&&u.jsxs("div",{className:"seg inline-flex items-center gap-0.5 p-[3px] rounded-md bg-hover-subtle [&_button]:py-[3px] [&_button]:px-3 [&_button]:text-sm [&_button]:font-medium [&_button]:text-text [&_button]:rounded-sm [&_button:not(:disabled):hover]:text-text [&_button.active]:bg-background [&_button.active]:shadow-segment [&_button:disabled]:text-muted [&_button:disabled]:cursor-default",role:"group","aria-label":NJe(),children:[u.jsx("button",{type:"button",className:e==="files"?"active":"","aria-pressed":e==="files",onClick:()=>r("files"),children:PJe()}),u.jsx("button",{type:"button",className:e==="changes"?"active":"","aria-pressed":e==="changes",onClick:()=>r("changes"),children:uD()})]}),n&&u.jsxs("span",{className:"wt-branch-chip inline-flex items-center gap-1 min-w-0 py-0.5 px-2 rounded-full bg-hover-muted text-subtext text-xs [&_>_svg]:shrink-0",title:s,children:[u.jsx(k0,{size:12}),u.jsx("span",{className:"wt-branch-name overflow-hidden text-ellipsis whitespace-nowrap",children:n})]}),o&&u.jsx(kp,{href:o,target:"_blank",rel:"noopener noreferrer",title:a,"aria-label":a,children:u.jsx(P6,{size:13})}),u.jsx("span",{className:"flex-1"}),u.jsx(kt,{title:FE(),"aria-label":FE(),onClick:c,children:i?u.jsx(Rt,{}):u.jsx(l$n,{size:13})})]})}function tG(e,r){const t=navigator.clipboard;if(!t){Xt(dD(),"error");return}t.writeText(`${e.replace(/[\\/]+$/,"")}/${r}`).then(()=>Xt(ed(),"success")).catch(n=>Xt(n instanceof Error?n.message:String(n),"error"))}function rG({name:e,onCommit:r,onCancel:t}){const[n,s]=T.useState(e),o=T.useRef(!1),a=()=>{if(o.current)return;o.current=!0;const i=n.trim();!i||i===e?t():r(i)};return u.jsx(mn,{autoFocus:!0,variant:"inline",className:"min-w-0 flex-1",value:n,"aria-label":Ugt({path:Te(e)}),onFocus:i=>{const c=e.lastIndexOf(".");i.currentTarget.setSelectionRange(0,c>0?c:e.length)},onChange:i=>s(i.target.value),onClick:i=>i.stopPropagation(),onDoubleClick:i=>i.stopPropagation(),onBlur:a,onKeyDown:i=>{i.stopPropagation(),i.key==="Enter"?(i.preventDefault(),i.currentTarget.blur()):i.key==="Escape"&&(i.preventDefault(),o.current=!0,t())}})}function nG(e,r){const t=e.currentTarget.getBoundingClientRect(),n="clientX"in e?e.clientX:0,s="clientY"in e?e.clientY:0;return{path:r,x:n||t.left+16,y:s||t.top+t.height}}function sG({target:e,onOpen:r,onRename:t,onDuplicate:n,onCopyPath:s,onDelete:o,onClose:a}){const i=T.useRef(null),c=T.useRef(a);c.current=a;const[_,d]=T.useState({x:e.x,y:e.y});T.useLayoutEffect(()=>{var k;const m=i.current;if(!m)return;const x=document.activeElement instanceof HTMLElement?document.activeElement:null;return d({x:Math.max(8,Math.min(e.x,window.innerWidth-m.offsetWidth-8)),y:Math.max(8,Math.min(e.y,window.innerHeight-m.offsetHeight-8))}),(k=m.querySelector("button"))==null||k.focus(),()=>{m.contains(document.activeElement)&&(x==null||x.focus())}},[e]),T.useEffect(()=>{const m=()=>c.current(),x=v=>{var w;(w=i.current)!=null&&w.contains(v.target instanceof Node?v.target:null)||c.current()},k=v=>{if(v.key==="Tab"){v.preventDefault(),c.current();return}v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),c.current())};return document.addEventListener("pointerdown",x),window.addEventListener("blur",m),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),document.addEventListener("keydown",k,!0),()=>{document.removeEventListener("pointerdown",x),window.removeEventListener("blur",m),window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0),document.removeEventListener("keydown",k,!0)}},[]);const f=m=>{c.current(),m()},p=(m,x,k=!1)=>u.jsx(_r,{size:"compact",role:"menuitem",danger:k,onClick:()=>f(x),children:u.jsx("span",{children:m})});return po.createPortal(u.jsxs("div",{ref:i,role:"menu","aria-label":jgt({path:Te(e.path)}),className:"option-menu fixed z-100 min-w-44 overflow-hidden rounded-md border border-border bg-background p-1 shadow-menu",style:{left:_.x,top:_.y},onContextMenu:m=>m.preventDefault(),onKeyDown:m=>{var w,b;if(m.key!=="ArrowDown"&&m.key!=="ArrowUp")return;m.preventDefault();const x=[...((w=i.current)==null?void 0:w.querySelectorAll("button"))??[]],k=x.indexOf(document.activeElement instanceof HTMLButtonElement?document.activeElement:x[0]),v=m.key==="ArrowDown"?1:-1;(b=x[(k+v+x.length)%x.length])==null||b.focus()},children:[p(Ogt(),r),t&&p(sD(),t),n&&p(hgt(),n),p(z4e(),s),o&&p(rD(),o,!0)]}),document.body)}const lj=["file-tree-row flex items-center gap-1.5 w-full py-[3px] px-2.5 border-0","bg-transparent text-text text-start cursor-pointer font-[inherit]","[&:hover]:bg-panel [&_>_svg]:shrink-0","[&_>_svg]:text-subtext [&_>_svg.file-tree-chevron]:text-muted"].join(" "),eO=["file-tree-chevron text-muted shrink-0 [button&]:inline-flex","[button&]:items-center [button&]:justify-center [button&]:w-[13px]","[button&]:h-[13px] [button&]:p-0 [button&]:border-0 [button&]:bg-transparent","[button&_>_svg]:transition-transform [button&_>_svg]:duration-120 [button&_>_svg]:ease-standard [button&_>_svg.open]:rotate-90"].join(" ");function tO(){return{dirs:new Map,files:[]}}function oG(e){const r=tO();for(const t of e){const n=t.split("/");let s=r;for(let o=0;oo(t),title:t,children:[p?u.jsx(oc,{size:13,className:eO}):u.jsx(Ca,{size:13,className:eO}),u.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:e})]}),p&&u.jsx($C,{node:r,parentPath:t,depth:n+1,toggled:s,onToggle:o,onOpenFile:a,renamingPath:i,onContextMenu:c,onRename:_,onCancelRename:d})]})}function $C({node:e,parentPath:r,depth:t,toggled:n,onToggle:s,onOpenFile:o,renamingPath:a,onContextMenu:i,onRename:c,onCancelRename:_}){const d=[...e.dirs.keys()].sort((p,m)=>p.localeCompare(m)),f=[...e.files].sort((p,m)=>p.localeCompare(m));return u.jsxs(u.Fragment,{children:[d.map(p=>{const m=r?`${r}/${p}`:p;return u.jsx(wts,{name:p,node:e.dirs.get(p),path:m,depth:t,toggled:n,onToggle:s,onOpenFile:o,renamingPath:a,onContextMenu:i,onRename:c,onCancelRename:_},`d:${m}`)}),f.map(p=>{const m=r?`${r}/${p}`:p;if(a===m&&c&&_)return u.jsxs("div",{className:lj,style:{paddingInlineStart:8+t*14},children:[u.jsx(ld,{name:p}),u.jsx(rG,{name:p,onCommit:k=>c(m,k),onCancel:_})]},`f:${m}`);const x=$n(k=>o(m,k));return u.jsxs("button",{type:"button",className:lj,style:{paddingInlineStart:8+t*14},...x,onContextMenu:k=>{i&&(k.preventDefault(),i(k,m))},onKeyDown:k=>{if(i&&(k.key==="ContextMenu"||k.shiftKey&&k.key==="F10")){k.preventDefault(),i(k,m);return}x.onKeyDown(k)},title:Tee({name:Te(m)}),children:[u.jsx(ld,{name:p}),u.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p})]},`f:${m}`)})]})}function kts({projectId:e,project:r,experiment:t,view:n,toggled:s,onViewChange:o,onToggledChange:a,onOpenFile:i}){var E,C;const c=t.branchName,_=nt({...C6(e,{ref:c}),enabled:n==="files",subscribed:n==="files"}),d=nt({...Hb(t.chatSessionId??""),enabled:n==="files"&&!!t.chatSessionId,subscribed:n==="files"&&!!t.chatSessionId}),f=_.data,p=(E=_.error)==null?void 0:E.message,m=_.isFetching,x=eF(t.id),k=uQ({queryKey:x.queryKey})>0,v=(C=d.data)!=null&&C.exists&&d.data.branch===c?t.chatSessionId??void 0:void 0,w=()=>{_.refetch()},b=T.useMemo(()=>f?oG(f.entries):null,[f]),y=n==="files"?m:k,S=T.useCallback(A=>{const N=new Set(s);N.has(A)?N.delete(A):N.add(A),a(N)},[s,a]);return u.jsxs("div",{className:"code-tab flex flex-col h-full min-h-0",children:[u.jsx(eG,{view:n,onViewChange:o,branchLabel:c,branchTitle:`Committed branch ${c}`,githubHref:r.githubEnabled?Ly(r.githubOwner,r.githubRepo,c):void 0,githubTitle:FL({branch:Te(c)}),refreshing:y,onRefresh:()=>n==="files"?w():void Xe.invalidateQueries(x)}),n==="changes"?u.jsx(xts,{experiment:t},t.id):u.jsxs(u.Fragment,{children:[(f==null?void 0:f.truncated)&&u.jsx(Ic,{children:set()}),p&&b&&u.jsxs(Ic,{children:[Cet()," ",Te(p)]}),u.jsx($h,{children:b?b.dirs.size===0&&b.files.length===0?u.jsx(Ic,{children:pet()}):u.jsx("div",{className:"file-tree py-1.5 px-0 text-sm",children:u.jsx($C,{node:b,parentPath:"",depth:0,toggled:s,onToggle:S,onOpenFile:(A,N)=>v?i(A,v,void 0,N):i(A,void 0,c,N)})}):u.jsx(Ic,{children:p?oS({error:Te(p)}):aS()})})]})]})}function LC({icon:e,title:r,description:t}){return u.jsxs("div",{className:"flex h-full w-full min-w-0 flex-1 flex-col items-center justify-center gap-1.5 bg-background p-6 text-center text-muted",children:[u.jsx(e,{size:36,strokeWidth:1.5,className:"shrink-0"}),u.jsx("h3",{className:"mt-1.5 mb-0 max-w-full wrap-anywhere text-xl font-medium text-text",children:r}),t&&u.jsx("p",{className:"m-0 w-full max-w-105 wrap-anywhere text-base leading-[1.55] text-subtext",children:t})]})}function jts({sessionId:e,project:r,view:t,toggled:n,onViewChange:s,onToggledChange:o,onOpenFile:a,canRenameFile:i}){var P,D,q;const c=r.id,d=((P=nt(Ao(c)).data)==null?void 0:P.some(U=>U.id===e&&U.busy))??!1,f=nt({...Hb(e??""),enabled:!!e,refetchInterval:d?5e3:!1}),p=f.data,m=e&&(p!=null&&p.exists)?{sessionId:e}:{ref:r.baselineBranch},x=nt({...C6(c,m),enabled:!e||f.isSuccess,refetchInterval:d?5e3:!1}),k=x.data,v=(D=f.error??x.error)==null?void 0:D.message,w=f.isFetching||x.isFetching,[b,y]=T.useState(null),[S,E]=T.useState(null),C=T.useCallback(()=>{e&&Xe.invalidateQueries(Hb(e)),Xe.invalidateQueries({queryKey:zt("getCodeTree",c),predicate:U=>!ML(U)})},[e,c]),A=T.useRef(d);T.useEffect(()=>{A.current&&!d&&C(),A.current=d},[d,C]);const N=T.useMemo(()=>k?oG(k.entries):null,[k]),R=T.useCallback(U=>{const G=new Set(n);G.has(U)?G.delete(U):G.add(U),o(G)},[n,o]),L=e&&(p!=null&&p.exists)?p:null,$=(L==null?void 0:L.branch)??(L!=null&&L.baselineBranch?Fzn({branch:Te(L.baselineBranch)}):PD()),I=((q=L==null?void 0:L.files)==null?void 0:q.length)??0,F=L?xzn({branch:Te(`${$}${I>0?"*":""}`)}):Tzn({branch:Te(r.baselineBranch)}),B=L?L.branch:r.baselineBranch,V=(U,G)=>L?a(U,e,void 0,G):a(U,void 0,r.baselineBranch,G),K=(k==null?void 0:k.root)==="worktree",ee=async(U,G)=>{try{await gEn(c,U,G,{sessionId:e}),C()}catch(oe){Xt(oe instanceof Error?oe.message:String(oe),"error")}},J=U=>{const G=(k==null?void 0:k.path)??r.repoPath;tG(G,U)};return u.jsxs("div",{className:"code-tab flex flex-col h-full min-h-0 wt-tab",children:[u.jsx(eG,{view:L?t:"files",onViewChange:s,showViewToggle:!!L,branchLabel:F,branchTitle:F,githubHref:r.githubEnabled&&B?Ly(r.githubOwner,r.githubRepo,B):void 0,githubTitle:B?FL({branch:Te(B)}):void 0,refreshing:w,onRefresh:C}),v&&(p||k)&&u.jsxs(Ic,{children:[D9n()," ",Te(v)]}),!k||e&&!p?u.jsx($h,{children:u.jsx(Ic,{children:v?oS({error:Te(v)}):aS()})}):L&&t==="changes"?u.jsx($h,{className:"wt-changes px-4 pb-6 pt-0 [&_>_:first-child]:mt-3.5",children:I===0||!L.diff?u.jsx("div",{className:"changes-note text-sm text-muted",children:g9n()}):u.jsxs(u.Fragment,{children:[L.diff.truncated&&u.jsx(PF,{bytesRead:L.diff.bytesRead,byteLimit:L.diff.byteLimit}),u.jsx(FF,{diff:L.diff.diff,partial:L.diff.truncated})]})}):u.jsxs($h,{children:[k.truncated&&u.jsx(Ic,{children:Yzn()}),N?N.dirs.size===0&&N.files.length===0?u.jsx(LC,{icon:ki,title:z9n(),description:c4t()}):u.jsx("div",{className:"file-tree py-1.5 px-0 text-sm",children:u.jsx($C,{node:N,parentPath:"",depth:0,toggled:n,onToggle:R,onOpenFile:V,renamingPath:S,onContextMenu:(U,G)=>{y(nG(U,G))},onRename:(U,G)=>{E(null),ee(U,{action:"rename",newName:G})},onCancelRename:()=>E(null)})}):u.jsx(Ic,{children:i9n()})]}),b&&u.jsx(sG,{target:b,onOpen:()=>V(b.path,"keepOpen"),onRename:K&&i(b.path)?()=>E(b.path):void 0,onDuplicate:K?()=>void ee(b.path,{action:"duplicate"}):void 0,onCopyPath:()=>J(b.path),onDelete:K?()=>{window.confirm(sgt({path:Te(b.path)}))&&ee(b.path,{action:"delete"})}:void 0,onClose:()=>y(null)})]})}function aG({text:e,path:r,highlightLine:t,scrollRequest:n,onScrollRequestHandled:s}){const o=T.useMemo(()=>{if(!e)return[];const d=e.replace(/\r\n?/g,` `),f=FB(d,WS(r));return d.endsWith(` -`)?f.slice(0,-1):f},[e,r]),a=t&&o.length>0?Math.min(Math.max(Math.trunc(t),1),o.length):void 0,i=T.useRef(null);T.useEffect(()=>{var d;n!==void 0&&(a?((d=i.current)==null||d.scrollIntoView({block:"center"}),s==null||s()):o.length===0&&(s==null||s()))},[o.length,s,n,a]);const{ruleCh:c}=kB(o.length),_=T.useMemo(()=>o.map((d,f)=>u.jsxs("div",{ref:f+1===a?i:void 0,className:`file-view-line flex items-stretch ${f+1===a?"file-view-line-highlight bg-accent-blue-subtle shadow-file-line":""}`,children:[u.jsx("span",{"data-line":f+1,className:`${wB} before:content-[attr(data-line)] shrink-0 pe-[1ch]`,style:{width:`${c}ch`},"aria-hidden":"true"}),u.jsx("code",{className:`file-view-code flex-1 min-w-0 ps-[2ch] pe-4 ${Bb} ${xB}`,children:HB(d)?u.jsx("br",{}):d})]},f)),[o,c,a]);return u.jsxs("div",{className:`file-view-codewrap relative py-3.5 ${Bb}`,children:[o.length>0&&u.jsx("div",{className:"absolute start-0 top-0 bottom-0 border-e border-e-border-variant pointer-events-none",style:{width:`${c}ch`},"aria-hidden":"true"}),_]})}const uy=T.createContext(null);function Sts({url:e,name:r}){return u.jsx(kp,{size:"small",href:e,download:r,"aria-label":kb({name:Te(r)}),"data-tip":kb({name:Te(r)}),"data-tip-align":"end",children:u.jsx(Py,{size:13})})}const Cts=T.lazy(()=>hQ(()=>import("./PdfPreview-Cu9GJIeU.js"),__vite__mapDeps([0,1])).catch(e=>(console.error("PDF viewer failed to load",e),{default:cG})));function iG(e){return e==="image"||e==="audio"||e==="video"||e==="pdf"?e:null}function cG({url:e,name:r}){return u.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[KRt()," ",u.jsxs("a",{href:e,download:r,children:[u3()," ",Te(r)]})]})}function uj({kind:e,url:r,name:t,download:n=!0}){const[s,o]=T.useState(!1),a=T.useContext(uy);if(T.useEffect(()=>o(!1),[e,r]),s)return u.jsx(cG,{url:r,name:t});let i;return e==="image"?i=u.jsx("div",{className:"fpreview-image flex min-h-0 flex-1 items-start justify-center overflow-auto p-6 [&_img]:max-w-full [&_img]:h-auto [&_img]:border [&_img]:border-border [&_img]:rounded-sm",children:u.jsx("img",{src:r,alt:t,onError:()=>o(!0)})}):e==="audio"?i=u.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:u.jsx("audio",{className:"w-full max-w-160",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):e==="video"?i=u.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:u.jsx("video",{className:"max-h-full max-w-full rounded-sm border border-border",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):i=u.jsx(T.Suspense,{fallback:u.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center",children:u.jsx(Rt,{})}),children:u.jsx(Cts,{url:r,name:t,download:n,onError:()=>o(!0)},r)}),u.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i,n&&e!=="pdf"&&a&&po.createPortal(u.jsx(Sts,{url:r,name:t}),a)]})}const zts=e=>({queryKey:zt("fileVersion",e),staleTime:2e3,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchInterval:2e3,queryFn:async({signal:r})=>{const t=await fetch(e,{method:"HEAD",cache:"no-store",signal:r});if(t.status===404)return"missing";if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.headers.get("etag")??t.headers.get("content-length")}});function lG(e,r=!0){return nt({...zts(e),enabled:r,subscribed:r}).data??null}function Ets(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function Nts(e,r,t){const n=t.indexOf("#"),s=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n),a=s.indexOf("?"),i=a===-1?s:s.slice(0,a),c=a===-1?"":s.slice(a+1),_=i.startsWith("/")?[]:r.split("/").filter(m=>m.length>0);for(const m of i.split("/"))if(!(!m||m==="."))if(m===".."){if(_.length===0)return null;_.pop()}else _.push(m);const d=_.join("/");if(!d)return null;const f=new URLSearchParams(c);f.delete("path");const p=f.toString();return{path:d,url:`${rd(e,d)}${p?`&${p}`:""}${o}`}}function Ats(e){if(!e.startsWith("---"))return e;const r=e.indexOf(` +`)?f.slice(0,-1):f},[e,r]),a=t&&o.length>0?Math.min(Math.max(Math.trunc(t),1),o.length):void 0,i=T.useRef(null);T.useEffect(()=>{var d;n!==void 0&&(a?((d=i.current)==null||d.scrollIntoView({block:"center"}),s==null||s()):o.length===0&&(s==null||s()))},[o.length,s,n,a]);const{ruleCh:c}=kB(o.length),_=T.useMemo(()=>o.map((d,f)=>u.jsxs("div",{ref:f+1===a?i:void 0,className:`file-view-line flex items-stretch ${f+1===a?"file-view-line-highlight bg-accent-blue-subtle shadow-file-line":""}`,children:[u.jsx("span",{"data-line":f+1,className:`${wB} before:content-[attr(data-line)] shrink-0 pe-[1ch]`,style:{width:`${c}ch`},"aria-hidden":"true"}),u.jsx("code",{className:`file-view-code flex-1 min-w-0 ps-[2ch] pe-4 ${Bb} ${xB}`,children:HB(d)?u.jsx("br",{}):d})]},f)),[o,c,a]);return u.jsxs("div",{className:`file-view-codewrap relative py-3.5 ${Bb}`,children:[o.length>0&&u.jsx("div",{className:"absolute start-0 top-0 bottom-0 border-e border-e-border-variant pointer-events-none",style:{width:`${c}ch`},"aria-hidden":"true"}),_]})}const uy=T.createContext(null);function Sts({url:e,name:r}){return u.jsx(kp,{size:"small",href:e,download:r,"aria-label":kb({name:Te(r)}),"data-tip":kb({name:Te(r)}),"data-tip-align":"end",children:u.jsx(Py,{size:13})})}const Cts=T.lazy(()=>hQ(()=>import("./PdfPreview-D6YVdKN_.js"),__vite__mapDeps([0,1])).catch(e=>(console.error("PDF viewer failed to load",e),{default:cG})));function iG(e){return e==="image"||e==="audio"||e==="video"||e==="pdf"?e:null}function cG({url:e,name:r}){return u.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[KRt()," ",u.jsxs("a",{href:e,download:r,children:[u3()," ",Te(r)]})]})}function uj({kind:e,url:r,name:t,download:n=!0}){const[s,o]=T.useState(!1),a=T.useContext(uy);if(T.useEffect(()=>o(!1),[e,r]),s)return u.jsx(cG,{url:r,name:t});let i;return e==="image"?i=u.jsx("div",{className:"fpreview-image flex min-h-0 flex-1 items-start justify-center overflow-auto p-6 [&_img]:max-w-full [&_img]:h-auto [&_img]:border [&_img]:border-border [&_img]:rounded-sm",children:u.jsx("img",{src:r,alt:t,onError:()=>o(!0)})}):e==="audio"?i=u.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:u.jsx("audio",{className:"w-full max-w-160",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):e==="video"?i=u.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:u.jsx("video",{className:"max-h-full max-w-full rounded-sm border border-border",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):i=u.jsx(T.Suspense,{fallback:u.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center",children:u.jsx(Rt,{})}),children:u.jsx(Cts,{url:r,name:t,download:n,onError:()=>o(!0)},r)}),u.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i,n&&e!=="pdf"&&a&&po.createPortal(u.jsx(Sts,{url:r,name:t}),a)]})}const zts=e=>({queryKey:zt("fileVersion",e),staleTime:2e3,refetchOnMount:"always",refetchOnWindowFocus:"always",refetchInterval:2e3,queryFn:async({signal:r})=>{const t=await fetch(e,{method:"HEAD",cache:"no-store",signal:r});if(t.status===404)return"missing";if(!t.ok)throw new Error(`HTTP ${t.status}`);return t.headers.get("etag")??t.headers.get("content-length")}});function lG(e,r=!0){return nt({...zts(e),enabled:r,subscribed:r}).data??null}function Ets(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function Nts(e,r,t){const n=t.indexOf("#"),s=n===-1?t:t.slice(0,n),o=n===-1?"":t.slice(n),a=s.indexOf("?"),i=a===-1?s:s.slice(0,a),c=a===-1?"":s.slice(a+1),_=i.startsWith("/")?[]:r.split("/").filter(m=>m.length>0);for(const m of i.split("/"))if(!(!m||m==="."))if(m===".."){if(_.length===0)return null;_.pop()}else _.push(m);const d=_.join("/");if(!d)return null;const f=new URLSearchParams(c);f.delete("path");const p=f.toString();return{path:d,url:`${rd(e,d)}${p?`&${p}`:""}${o}`}}function Ats(e){if(!e.startsWith("---"))return e;const r=e.indexOf(` ---`,3);return r===-1?e:e.slice(r+4).replace(/^\r?\n/,"")}const uG="orx:files-tree-width",_G="orx:artifacts-collapsed:",fG=180,dG=320,Tts=8,Rts=280;function Mts(){try{const e=Number(localStorage.getItem(uG));if(Number.isFinite(e)&&e>=fG&&e<=dG)return e}catch{}return Rts}function Ots(e){try{const r=localStorage.getItem(`${_G}${e}`);if(!r)return new Set;const t=JSON.parse(r);return Array.isArray(t)?new Set(t.filter(n=>typeof n=="string")):new Set}catch{return new Set}}function Fg(e,r){for(const t of e){if(t.path===r)return t;if(t.isDir&&r.startsWith(t.path+"/")){const n=Fg(t.children??[],r);if(n)return n}}return null}function hG({projectId:e,folder:r,markdown:t,entries:n}){const s=T.useRef(n);s.current=n;const o=T.useMemo(()=>{const a=i=>{if(Ets(i))return i;const c=Nts(e,r,i);if(!c)return null;const _=Fg(s.current,c.path);if(!_)return c.url;const d=c.url.indexOf("#"),f=d===-1?c.url:c.url.slice(0,d),p=d===-1?"":c.url.slice(d);return`${f}&v=${_.modifiedAt}:${_.size}${p}`};return{a:({href:i,children:c,..._})=>{const d=!i||i.startsWith("#"),f=d?i:a(i);return f?u.jsx("a",{..._,href:f,...d?{}:{target:"_blank",rel:"noopener noreferrer"},children:c}):u.jsx("span",{children:c})},img:({src:i,alt:c})=>{if(!i||typeof i!="string")return null;const _=a(i);return _?u.jsxs("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"artifact-img",children:[u.jsx("img",{src:_,alt:c??"",loading:"lazy"}),c&&u.jsx("span",{className:"artifact-img-caption",children:c})]}):null},...bU}},[e,r]);return u.jsx("div",{className:"md min-w-0 wrap-anywhere text-text leading-[1.62] [&_>_*:first-child]:mt-0 [&_>_*:last-child]:mb-0 [&_p]:my-2.5 [&_p]:mx-0 [&_strong]:text-text [&_strong]:font-semibold [&_pre]:bg-surface [&_pre]:border [&_pre]:border-border-muted [&_pre]:rounded-md [&_pre]:py-2 [&_pre]:px-3 [&_pre]:overflow-x-auto [&_pre]:text-sm [&_pre]:text-text [&_code]:font-mono [&_code]:text-sm [&_code]:font-normal [&_code]:text-primary [&_code]:bg-surface [&_code]:border [&_code]:border-border-variant [&_code]:rounded-xs [&_code]:py-px [&_code]:px-[5px] [&_.katex]:text-prose-emphasis [&_.katex-display]:my-3 [&_.katex-display]:mx-0 [&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-0.5 [&_.katex-display]:px-0 [&_.file-chip]:inline-flex [&_.file-chip]:items-center [&_.file-chip]:gap-1 [&_.file-chip]:max-w-full [&_.file-chip]:my-0 [&_.file-chip]:mx-px [&_.file-chip]:py-0 [&_.file-chip]:px-1.5 [&_.file-chip]:align-baseline [&_.file-chip]:font-mono [&_.file-chip]:text-sm [&_.file-chip]:font-medium [&_.file-chip]:text-text [&_.file-chip]:bg-panel [&_.file-chip]:border [&_.file-chip]:border-border-variant [&_.file-chip]:rounded-xs [&_.file-chip]:cursor-pointer [&_.file-chip:hover:not(:disabled)]:bg-surface [&_.file-chip:hover:not(:disabled)]:text-primary [&_.file-chip_svg]:flex-none [&_.file-chip_svg]:opacity-60 [&_.file-chip-label]:max-w-65 [&_.file-chip-label]:overflow-hidden [&_.file-chip-label]:text-ellipsis [&_.file-chip-label]:whitespace-nowrap [&_.run-chip_svg]:opacity-100 [&_.run-chip_svg]:text-primary [&_pre_code]:bg-none [&_pre_code]:bg-transparent [&_pre_code]:border-0 [&_pre_code]:text-inherit [&_pre_code]:p-0 [&_pre_code]:font-normal [&_h1]:text-text [&_h1]:font-semibold [&_h2]:text-text [&_h2]:font-semibold [&_h3]:text-text [&_h3]:font-semibold [&_h4]:text-text [&_h4]:font-semibold [&_ul]:my-1.5 [&_ul]:mx-0 [&_ul]:ps-5.5 [&_ol]:my-1.5 [&_ol]:mx-0 [&_ol]:ps-5.5 [&_li::marker]:text-primary [&_a]:text-primary [&_table]:border-collapse [&_table]:text-sm [&_table]:my-2.5 [&_table]:mx-0 [&_table]:border [&_table]:border-border [&_table]:rounded-md [&_th]:border-b [&_th]:border-b-border-variant [&_th]:py-2 [&_th]:px-3.5 [&_th]:text-start [&_th]:text-text [&_th]:break-normal [&_th]:break-words [&_td]:border-b [&_td]:border-b-border-variant [&_td]:py-2 [&_td]:px-3.5 [&_td]:text-start [&_td]:text-text [&_td]:break-normal [&_td]:break-words [&_tr:last-child_td]:border-b-0 [&_thead_th]:bg-surface [&_thead_th]:font-medium [&_thead_th]:text-text [&_thead_th]:border-b [&_thead_th]:border-b-border [&_tbody_tr:hover_td]:bg-surface [&_blockquote]:my-1.5 [&_blockquote]:mx-0 [&_blockquote]:pt-0.5 [&_blockquote]:pe-0 [&_blockquote]:pb-0.5 [&_blockquote]:ps-2.5 [&_blockquote]:border-s-[3px] [&_blockquote]:border-s-border [&_blockquote]:text-subtext [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:italic [:is(&,_.openresearch-diff,_.file-view)_.token.operator]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.entity]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.url]:text-syntax-cyan [:is(&,_.openresearch-diff,_.file-view)_.token.comment]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.prolog]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.cdata]:text-syntax-comment [:is(&,_.openresearch-diff,_.file-view)_.token.punctuation]:text-syntax-text [:is(&,_.openresearch-diff,_.file-view)_.token.property]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.tag]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.deleted]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.constant]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.symbol]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.boolean]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.number]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.selector]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.attr-name]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.char]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.inserted]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.string]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.builtin]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.atrule]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.attr-value]:text-syntax-orange [:is(&,_.openresearch-diff,_.file-view)_.token.keyword]:text-syntax-purple [:is(&,_.openresearch-diff,_.file-view)_.token.function]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.decorator]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.def]:text-syntax-blue [:is(&,_.openresearch-diff,_.file-view)_.token.class-name]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.namespace]:text-syntax-yellow [:is(&,_.openresearch-diff,_.file-view)_.token.regex]:text-syntax-green [:is(&,_.openresearch-diff,_.file-view)_.token.important]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.variable]:text-syntax-red [:is(&,_.openresearch-diff,_.file-view)_.token.parameter]:text-syntax-text artifact-md text-lg [&_h1]:text-4xl [&_h1]:leading-[1.18] [&_h1]:mt-7 [&_h1]:mx-0 [&_h1]:mb-3.5 [&_h2]:text-3xl [&_h2]:leading-tight [&_h2]:mt-7 [&_h2]:mx-0 [&_h2]:mb-2.5 [&_h3]:text-xl [&_h3]:leading-[1.35] [&_h3]:mt-5.5 [&_h3]:mx-0 [&_h3]:mb-2 [&_h4]:text-lg [&_h4]:leading-[1.4] [&_h4]:mt-4.5 [&_h4]:mx-0 [&_h4]:mb-1.5 [&_table]:block [&_table]:w-max [&_table]:max-w-full [&_table]:overflow-x-auto [&_.artifact-img]:block [&_.artifact-img]:my-3 [&_.artifact-img]:mx-0 [&_.artifact-img_img]:max-w-full [&_.artifact-img_img]:h-auto [&_.artifact-img_img]:border [&_.artifact-img_img]:border-border [&_.artifact-img_img]:rounded-sm [&_.artifact-img-caption]:block [&_.artifact-img-caption]:mt-1 [&_.artifact-img-caption]:text-center [&_.artifact-img-caption]:text-sm [&_.artifact-img-caption]:text-subtext",children:u.jsx(CGn,{remarkPlugins:[uU,[_U,vU]],rehypePlugins:[Pq],components:o,children:dU(Ats(t))})})}function $ts(e){return e.presentation==="text"&&EC(e.name)?"markdown":iG(e.presentation)??(e.presentation==="text"||e.presentation==="unknown"?"text":"download")}function Lts(e,r,t,n){var _;const s=t==="markdown"||t==="text"&&r.size<=OI,o=z6(e,r.path),a=nt({...o,enabled:s,subscribed:s}),i=T.useRef({projectId:e,path:r.path,modifiedAt:r.modifiedAt,size:r.size,version:n});T.useEffect(()=>{const d=i.current;i.current={projectId:e,path:r.path,modifiedAt:r.modifiedAt,size:r.size,version:n},s&&d.projectId===e&&d.path===r.path&&(d.modifiedAt!==r.modifiedAt||d.size!==r.size||d.version!==null&&d.version!==n)&&Xe.invalidateQueries({queryKey:o.queryKey,exact:!0})},[e,r.path,r.modifiedAt,r.size,n,s]);const c=a.data;return{text:c&&!c.binary?c.content:null,binary:(c==null?void 0:c.binary)??!1,truncated:(c==null?void 0:c.truncated)??!1,error:c?null:((_=a.error)==null?void 0:_.message)??(c===null?D4e():null),wantsText:s}}function Dts({projectId:e,entry:r,onDelete:t,artifactEntries:n}){const s=$ts(r),o=lG(rd(e,r.path)),{text:a,binary:i,truncated:c,error:_,wantsText:d}=Lts(e,r,s,o),[f,p]=T.useState(!1),[m,x]=T.useState(null),k=s==="markdown",v=r.path.split("/").slice(0,-1).join("/"),w=`${rd(e,r.path)}&v=${encodeURIComponent(o??`${r.modifiedAt}:${r.size}`)}`;let b;return s==="image"||s==="audio"||s==="video"||s==="pdf"?b=u.jsx(uy.Provider,{value:m,children:u.jsx(uj,{kind:s,url:w,name:r.name})}):s==="download"||!d||i?b=u.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[s==="download"||i?g4e():fje()," ",u.jsx("a",{href:w,...s==="download"||i?{download:r.name}:{target:"_blank",rel:"noopener noreferrer"},children:s==="download"||i?hD():K4e()})]}):_?b=u.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[R3e()," ",Te(_)]}):a===null?b=u.jsxs(ds,{children:[u.jsx(Rt,{})," ",JL()]}):k&&!f?b=u.jsx(hG,{projectId:e,folder:v,markdown:a,entries:n}):b=u.jsx(aG,{text:a,path:r.path}),u.jsxs("div",{className:"fpreview flex-1 min-w-0 bg-background file-view flex flex-col h-full min-h-0 [@container((max-width:_720px))]:hidden",children:[u.jsxs("div",{className:"fpreview-head @container flex w-full min-w-0 min-h-9 items-center gap-1 px-4 py-1 bg-background text-subtext shrink-0",children:[u.jsx(ld,{name:r.name}),u.jsx("span",{className:"fpreview-path flex-1 min-w-0 truncate text-sm text-subtext","data-tip":Te(r.path),children:r.name}),u.jsxs("span",{dir:"auto",className:"fpreview-date text-xs text-muted whitespace-nowrap shrink-0 @max-xl:hidden",children:[z5e()," ",new Date(r.modifiedAt).toLocaleString(z(),{dateStyle:"medium",timeStyle:"short"})]}),u.jsx("div",{ref:x,className:"contents"}),(s==="text"||s==="download")&&u.jsx("span",{className:"fpreview-size text-xs text-muted whitespace-nowrap shrink-0",children:Jl(r.size)}),k&&u.jsx(kt,{size:"small",active:f,"data-tip":f?Sb():bh(),"data-tip-align":"end","aria-label":f?Sb():bh(),onClick:()=>p(y=>!y),children:u.jsx(V3,{size:13})}),u.jsx(kp,{size:"small",href:w,target:"_blank",rel:"noopener noreferrer","data-tip":iE(),"data-tip-align":"end","aria-label":iE(),children:u.jsx(sd,{size:13})}),u.jsx(kt,{size:"small","data-tip":aE(),"data-tip-align":"end","aria-label":aE(),onClick:()=>{window.confirm(rS({path:Te(r.path)}))&&t(r.path)},children:u.jsx(wd,{size:13})})]}),u.jsxs("div",{className:`fpreview-body flex-1 min-h-0 overflow-auto [&.doc]:pt-4.5 [&.doc]:px-7 [&.doc]:pb-12 [&.doc_.artifact-md]:max-w-readable [&.doc_.artifact-md]:my-0 [&.doc_.artifact-md]:mx-auto ${k&&!f?"doc":""}`,children:[b,c&&u.jsx("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:H3e()})]})]})}function pG({entries:e,depth:r,collapsed:t,selected:n,onToggle:s,onSelect:o,onOpenFile:a,onDelete:i,renamingPath:c,onContextMenu:_,onRename:d,onCancelRename:f}){return u.jsx("div",{className:"flex w-full max-w-full min-w-0 flex-col items-stretch",children:e.map(p=>{var x;const m={paddingInlineStart:8+Math.min(r,Tts)*14};if(p.isDir){const k=!t.has(p.path);return u.jsxs("div",{className:"min-w-0 max-w-full",children:[u.jsxs("div",{className:"file-tree-row flex w-full min-w-0 items-center gap-1.5 py-[3px] px-2.5 border-0 bg-transparent text-text text-start cursor-pointer font-[inherit] [&:hover]:bg-panel [&_>_svg]:shrink-0 [&_>_svg]:text-subtext [&_>_svg.file-tree-chevron]:text-muted artifact-tree-row [&.selected]:bg-panel [&.selected:hover]:bg-panel [&:hover_.ft-row-delete]:opacity-100",style:m,onClick:()=>s(p.path),children:[u.jsx("button",{className:"file-tree-chevron text-muted shrink-0 [button&]:inline-flex [button&]:items-center [button&]:justify-center [button&]:w-[13px] [button&]:h-[13px] [button&]:p-0 [button&]:border-0 [button&]:bg-transparent [button&_>_svg]:transition-transform [button&_>_svg]:duration-120 [button&_>_svg]:ease-standard [button&_>_svg.open]:rotate-90","aria-label":k?Rke({name:Te(p.name)}):i4e({name:Te(p.name)}),onClick:v=>{v.stopPropagation(),s(p.path)},children:u.jsx(Ca,{size:13,className:k?"open":""})}),u.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p.name}),u.jsx(kt,{size:"small",className:"ft-row-delete opacity-35 focus-visible:opacity-100","data-tip":w3e(),"data-tip-align":"end","aria-label":Yke({name:Te(p.name)}),onClick:v=>{v.stopPropagation(),window.confirm(rS({path:Te(p.path)}))&&i(p.path)},children:u.jsx(wd,{size:12})})]}),k&&(((x=p.children)==null?void 0:x.length)??0)>0&&u.jsx(pG,{entries:p.children??[],depth:r+1,collapsed:t,selected:n,onToggle:s,onSelect:o,onOpenFile:a,onDelete:i,renamingPath:c,onContextMenu:_,onRename:d,onCancelRename:f})]},p.path)}return c===p.path?u.jsxs("div",{className:"file-tree-row flex w-full min-w-0 items-center gap-1.5 py-[3px] px-2.5 border-0 bg-transparent text-text text-start font-[inherit] artifact-tree-row",style:m,children:[u.jsx(ld,{name:p.name}),u.jsx(rG,{name:p.name,onCommit:k=>d(p.path,k),onCancel:f})]},p.path):u.jsxs("button",{type:"button",className:`file-tree-row flex w-full min-w-0 items-center gap-1.5 py-[3px] px-2.5 border-0 bg-transparent text-text text-start cursor-pointer font-[inherit] [&:hover]:bg-panel [&_>_svg]:shrink-0 [&_>_svg]:text-subtext [&_>_svg.file-tree-chevron]:text-muted artifact-tree-row [&.selected]:bg-panel [&.selected:hover]:bg-panel [&:hover_.ft-row-delete]:opacity-100 ${n===p.path?"selected":""}`,style:m,title:rZ({path:Te(p.path)}),"aria-keyshortcuts":"Space Enter","aria-pressed":n===p.path,onClick:()=>o(p.path),onDoubleClick:()=>a(p.path),onContextMenu:k=>{k.preventDefault(),o(p.path),_(k,p.path)},onAuxClick:k=>{k.button===1&&(k.preventDefault(),o(p.path),a(p.path))},onKeyDown:k=>{if(k.key==="ContextMenu"||k.shiftKey&&k.key==="F10"){k.preventDefault(),o(p.path),_(k,p.path);return}if(k.key===" "){k.preventDefault(),k.stopPropagation(),o(p.path);return}k.key==="Enter"&&(k.preventDefault(),k.stopPropagation(),o(p.path),a(p.path))},children:[u.jsx(ld,{name:p.name}),u.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p.name})]},p.path)})})}function Its({project:e,artifacts:r,onOpenFile:t,canRenameFile:n}){const[s,o]=T.useState(null),[a,i]=T.useState(()=>Ots(e.id)),[c,_]=T.useState(Mts),[d,f]=T.useState(null),[p,m]=T.useState(null),x=T.useRef(null);T.useEffect(()=>{try{localStorage.setItem(`${_G}${e.id}`,JSON.stringify([...a]))}catch{}},[e.id,a]);const k=C=>{var $;C.preventDefault(),C.currentTarget.setPointerCapture(C.pointerId);const A=($=x.current)==null?void 0:$.getBoundingClientRect(),N=document.body.style.userSelect;document.body.style.userSelect="none";const R=I=>{const F=Math.round(I.clientX-((A==null?void 0:A.left)??0)),B=Math.min(Math.max(F,fG),dG);_(B);try{localStorage.setItem(uG,String(B))}catch{}},L=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",L),document.body.style.userSelect=N};window.addEventListener("pointermove",R),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",L)};T.useEffect(()=>{if(!s||!r)return;const C=Fg(r.entries,s);(!C||C.isDir)&&o(null)},[s,r]);const v=C=>i(A=>{const N=new Set(A);return N.has(C)?N.delete(C):N.add(C),N}),w=C=>{(s===C||s!=null&&s.startsWith(C+"/"))&&o(null),jNn(e.id,C).catch(()=>{})},b=async(C,A)=>{try{await SNn(e.id,C,A),A.action==="rename"&&s===C&&o(null)}catch(N){Xt(N instanceof Error?N.message:String(N),"error")}},y=C=>{r&&tG(r.dir,C)};if(!r)return u.jsx("div",{className:"files-tab h-full min-h-0 flex bg-background",children:u.jsxs(ds,{className:"p-5",children:[u.jsx(Rt,{})," ",g5e()]})});const S=C=>u.jsx(pG,{entries:C,depth:0,collapsed:a,selected:s,onToggle:v,onSelect:o,onOpenFile:t,onDelete:w,renamingPath:p,onContextMenu:(A,N)=>{f(nG(A,N))},onRename:(A,N)=>{m(null),b(A,{action:"rename",newName:N})},onCancelRename:()=>m(null)}),E=s?Fg(r.entries,s):null;return r.entries.length===0?u.jsx(LC,{icon:OS,title:D5e(),description:rje()}):u.jsxs("div",{className:"files-tab h-full min-h-0 flex bg-background @container",children:[u.jsxs("div",{className:"ftree-pane relative shrink-0 flex flex-col min-h-0 border-s border-s-border-variant border-e border-e-border-variant bg-background [@container((max-width:_720px))]:!w-full",ref:x,style:{width:c},children:[u.jsx("div",{className:"ftree-resizer absolute -end-[3px] top-0 bottom-0 w-1.5 cursor-col-resize z-30 [&:hover]:bg-resizer-hover [&:active]:bg-resizer-hover [@container((max-width:_720px))]:hidden",onPointerDown:k}),u.jsxs("div",{className:"ftree-scroll flex-1 min-h-0 overflow-y-auto file-tree py-1.5 px-0 text-sm",children:[S(r.entries),r.truncated&&u.jsx("p",{className:"files-truncated m-0 py-2 px-3.5 text-sm text-muted",children:Z3e()})]})]}),E?u.jsx(Dts,{projectId:e.id,entry:E,onDelete:w,artifactEntries:r.entries},E.path):u.jsxs("div",{className:"fpreview flex-1 min-w-0 flex flex-col min-h-0 bg-background fpreview-none items-center justify-center gap-2 text-sm text-muted [@container((max-width:_720px))]:hidden",children:[u.jsx(VOn,{size:22,strokeWidth:1.5}),u.jsx("span",{children:n3e()})]}),d&&u.jsx(sG,{target:d,onOpen:()=>t(d.path),onRename:n(d.path)?()=>m(d.path):void 0,onDuplicate:()=>void b(d.path,{action:"duplicate"}),onCopyPath:()=>y(d.path),onDelete:()=>{window.confirm(rS({path:Te(d.path)}))&&w(d.path)},onClose:()=>f(null)})]})}const mG=20*1024*1024,gG="bg-background border border-border rounded-lg py-4 px-4.5 mb-4 [&_h3]:mt-0 [&_h3]:mx-0 [&_h3]:mb-2.5 [&_h3]:text-base [&_h3]:font-semibold [&_h3]:text-text",vG="mt-0 mx-0 mb-3 text-sm leading-relaxed text-text",Pts="flex items-start gap-3 py-2.5 border-t border-t-border first:border-t-0",Bts="text-sm font-normal text-text",Fts="mt-1 mb-0 text-sm leading-relaxed text-text";function bG(e){return new Promise((r,t)=>{const n=new FileReader;n.onload=()=>{const s=n.result;if(typeof s!="string"){t(new Error("could not read file"));return}const o=s.indexOf(",");r(o>=0?s.slice(o+1):s)},n.onerror=()=>t(n.error??new Error("could not read file")),n.readAsDataURL(e)})}function Hts(e){const r=e.toLowerCase();return r.endsWith(".md")||r.endsWith(".markdown")||r.endsWith(".zip")}function yG({accept:e,busy:r,prompt:t,onFile:n}){const[s,o]=T.useState(!1),a=T.useRef(null);return u.jsxs("div",{className:`flex flex-col items-center justify-center gap-2 py-6.5 px-4.5 border-[1.5px] border-dashed rounded-md text-center text-sm text-text transition-[border-color,background] duration-120 ${r?"cursor-default":"cursor-pointer"} ${s?"border-primary bg-surface text-text":"border-border-variant bg-surface [&:hover]:border-primary"}`,onDragOver:i=>{i.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:i=>{var _;if(i.preventDefault(),o(!1),r)return;const c=(_=i.dataTransfer.files)==null?void 0:_[0];c&&n(c)},onClick:()=>{var i;r||(i=a.current)==null||i.click()},role:"button",tabIndex:0,"aria-disabled":r,"aria-busy":r,onKeyDown:i=>{var c;(i.key==="Enter"||i.key===" ")&&!r&&(i.preventDefault(),(c=a.current)==null||c.click())},children:[u.jsx("input",{ref:a,type:"file",accept:e,hidden:!0,onChange:i=>{var _;const c=(_=i.target.files)==null?void 0:_[0];c&&n(c),i.target.value=""}}),r?u.jsxs(u.Fragment,{children:[u.jsx(Rt,{}),u.jsx("span",{children:Rmn()})]}):u.jsxs(u.Fragment,{children:[u.jsx(C$n,{size:20,strokeWidth:1.5}),u.jsx("span",{children:t})]})]})}function xG({bytes:e,updatedAt:r}){return u.jsxs("div",{className:"shrink-0 text-end whitespace-nowrap pt-0.5 text-xs text-subtext",children:[Jl(e),r>0&&u.jsxs("span",{className:"text-muted",children:[" · ",rc(r)]})]})}function qts({skill:e,onError:r}){const t=wr({mutationFn:eAn}),n=t.isPending;return u.jsxs("div",{className:"flex items-center gap-2 py-1 border-t border-t-border first:border-t-0",children:[u.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[u.jsx("span",{className:Bts,children:e.name}),e.origin&&u.jsx(rr,{size:"small",children:e.origin})]}),u.jsx(xG,{bytes:e.bytes,updatedAt:e.updatedAt}),u.jsx(kt,{size:"small","data-tip":e.origin?Udn():apn(),"data-tip-align":"end","aria-label":e.origin?uhn({name:Te(e.name)}):lfn({name:Te(e.name)}),disabled:n,onClick:()=>{window.confirm(e.origin?ehn({name:Te(e.name)}):J_n({name:Te(e.name)}))&&t.mutateAsync(e.name).catch(s=>{r(s instanceof Error?s.message:String(s))})},children:u.jsx(wd,{size:13})})]})}function Uts({template:e,onError:r}){const t=wr({mutationFn:YNn}),n=t.isPending,s=e.supportFiles.length;return u.jsxs("div",{className:Pts,children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("span",{className:"text-base font-medium text-text",children:e.name}),u.jsxs("p",{className:Fts,children:[e.entry,s>0&&(s===1?jdn():yhn({count:mr(s)}))]})]}),u.jsx(xG,{bytes:e.bytes,updatedAt:e.updatedAt}),u.jsx(kt,{"data-tip":mpn(),"data-tip-align":"end","aria-label":Nfn({name:Te(e.name)}),disabled:n,onClick:()=>{window.confirm(bfn({name:Te(e.name)}))&&t.mutateAsync(e.name).catch(o=>{r(o instanceof Error?o.message:String(o))})},children:u.jsx(wd,{size:13})})]})}function Gts(){var b;const e=wr({mutationFn:JNn}),r=nt(GAn()),t=r.data,n=T.useRef(null),[s,o]=T.useState(!1),[a,i]=T.useState(!1),c=T.useCallback(()=>{const y=n.current;o(!!y&&y.scrollTop>1),i(!!y&&y.scrollHeight-y.scrollTop-y.clientHeight>1)},[]);T.useLayoutEffect(()=>{c();const y=n.current;if(!y)return;const S=new ResizeObserver(c);return S.observe(y),()=>S.disconnect()},[t,c]);const _=r.isFetching,d=(b=r.error)==null?void 0:b.message,[f,p]=T.useState(!1),[m,x]=T.useState(null),k=()=>{r.refetch()},v=T.useRef(!1),w=T.useCallback(async y=>{if(!v.current){if(x(null),!Hts(y.name)){x(Zmn());return}if(y.size>mG){x(cI());return}v.current=!0,p(!0);try{await e.mutateAsync({filename:y.name,contentBase64:await bG(y)})}catch(S){x(S instanceof Error?S.message:String(S))}finally{v.current=!1,p(!1)}}},[]);return u.jsxs("section",{className:gG,children:[u.jsxs("div",{className:"flex items-baseline gap-2.5",children:[u.jsx("h3",{children:wmn()}),u.jsxs(Ee,{className:"ms-auto",size:"small",onClick:k,disabled:_,children:[u.jsx(Ei,{size:12,className:_?"animate-[spin_0.9s_linear_infinite]":""})," ",b0()]})]}),u.jsx("p",{className:vG,children:Pfn()}),u.jsx(yG,{accept:".md,.markdown,.zip",busy:f,prompt:u.jsxs(u.Fragment,{children:[u.jsx("span",{children:Qfn()}),u.jsx("span",{className:"block ps-4 mt-1 text-text",children:q_n()})]}),onFile:y=>void w(y)}),m&&u.jsx("div",{role:"alert",className:"mt-2.5 text-base text-accent-red whitespace-pre-wrap",children:m}),d&&u.jsxs("div",{role:"alert",className:"pt-3 text-base text-accent-red",children:[Ahn()," ",d]}),t===void 0?d?null:u.jsxs("div",{className:"flex items-center gap-2 pt-3 text-sm text-subtext",children:[u.jsx(Rt,{})," ",Lpn()]}):t.length===0?u.jsx("div",{className:"pt-3 text-sm text-subtext",children:rmn()}):u.jsxs("div",{className:"relative mt-1",children:[u.jsx("div",{ref:n,onScroll:c,className:"flex flex-col max-h-120 overflow-y-auto overscroll-contain",children:t.map(y=>u.jsx(qts,{skill:y,onError:x},y.name))}),s&&u.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 h-10 bg-gradient-to-b from-background to-transparent"}),a&&u.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t from-background to-transparent"})]})]})}function Wts(){var d;const e=wr({mutationFn:XNn}),r=nt(UAn()),t=r.data,n=(d=r.error)==null?void 0:d.message,[s,o]=T.useState(!1),[a,i]=T.useState(null),c=T.useRef(!1),_=T.useCallback(async f=>{if(c.current)return;i(null);const p=f.name.toLowerCase();if(!p.endsWith(".tex")&&!p.endsWith(".zip")){i(cgn());return}if(f.size>mG){i(cI());return}c.current=!0,o(!0);try{await e.mutateAsync({filename:f.name,contentBase64:await bG(f)})}catch(m){i(m instanceof Error?m.message:String(m))}finally{c.current=!1,o(!1)}},[]);return u.jsxs("section",{className:gG,children:[u.jsx("h3",{children:Cpn()}),u.jsx("p",{className:vG,children:Hmn()}),u.jsx(yG,{accept:".tex,.zip",busy:s,prompt:u.jsxs(u.Fragment,{children:[u.jsx("span",{children:odn()}),u.jsx("span",{className:"block ps-4 mt-1 text-text",children:Vxn()})]}),onFile:f=>void _(f)}),a&&u.jsx("div",{role:"alert",className:"mt-2.5 text-base text-accent-red whitespace-pre-wrap",children:a}),n&&u.jsxs("div",{role:"alert",className:"pt-3 text-base text-accent-red",children:[Bhn()," ",n]}),t===void 0?n?null:u.jsxs("div",{className:"flex items-center gap-2 pt-3 text-sm text-subtext",children:[u.jsx(Rt,{})," ",Wpn()]}):t.length===0?u.jsx("div",{className:"pt-3 text-sm text-subtext",children:fmn()}):u.jsx("div",{className:"flex flex-col mt-1",children:t.map(f=>u.jsx(Uts,{template:f,onError:i},f.name))})]})}function Kts(){return u.jsxs("div",{className:"settings-view max-w-readable my-0 mx-auto pt-6 px-8 pb-15 [&_h1]:mt-0 [&_h1]:mx-0 [&_h1]:mb-1.5 [&_h1]:text-3xl",children:[u.jsx("h1",{children:Xhn()}),u.jsx("p",{className:"mt-0 mx-0 mb-5 text-base leading-relaxed text-text",children:Odn()}),u.jsx(Gts,{}),u.jsx(Wts,{})]})}const Vts="italic [&_.tab-label_>_span]:pe-1 [&_.tab-label::after]:pe-1";function zc({active:e,label:r,icon:t,shimmer:n=!1,preview:s=!1,onSelect:o,onPromote:a,onClose:i}){return u.jsxs("button",{className:`tab [&.closable]:max-w-60 [&.closable]:pe-1.5 [&_.tab-label]:grid [&_.tab-label]:grid-cols-[minmax(0,_1fr)] [&_.tab-label]:min-w-0 [&_.tab-label]:overflow-hidden [&_.tab-label_>_span]:[grid-area:1_/_1] [&_.tab-label_>_span]:overflow-hidden [&_.tab-label_>_span]:text-ellipsis [&_.tab-label_>_span]:whitespace-nowrap [&_.tab-label::after]:[grid-area:1_/_1] [&_.tab-label::after]:overflow-hidden [&_.tab-label::after]:text-ellipsis [&_.tab-label::after]:whitespace-nowrap [&_.tab-label::after]:content-[attr(data-label)] [&_.tab-label::after]:invisible [&_.tab-label::after]:font-medium [&_.tab-close]:inline-flex [&_.tab-close]:items-center [&_.tab-close]:justify-center [&_.tab-close]:size-5 [&_.tab-close]:rounded-sm [&_.tab-close]:text-muted [&_.tab-close]:shrink-0 [&_.tab-close:hover]:bg-hover-strong [&_.tab-close:hover]:text-text relative inline-flex items-center gap-[5px] h-8 py-0 px-2 border border-transparent border-b-0 rounded-[var(--radius-md)_var(--radius-md)_0_0] text-sm font-normal text-subtext whitespace-nowrap select-none min-w-0 [&:hover]:bg-surface [&:hover]:text-text [&:not(.active)_+_.tab:not(.active)::before]:content-[''] [&:not(.active)_+_.tab:not(.active)::before]:absolute [&:not(.active)_+_.tab:not(.active)::before]:top-2.5 [&:not(.active)_+_.tab:not(.active)::before]:bottom-2.5 [&:not(.active)_+_.tab:not(.active)::before]:-start-px [&:not(.active)_+_.tab:not(.active)::before]:w-px [&:not(.active)_+_.tab:not(.active)::before]:bg-border [&.active]:border-border [&.active]:bg-background [&.active]:text-text [&.active]:font-medium [&.active::after]:content-[''] [&.active::after]:absolute [&.active::after]:end-0 [&.active::after]:-bottom-px [&.active::after]:start-0 [&.active::after]:h-px [&.active::after]:bg-background closable ${e?"active":""} ${s?Vts:""}`,onClick:o,onDoubleClick:a,title:s?Ixn({label:r}):r,"aria-label":s?Exn({label:r}):r,children:[t,u.jsx("span",{className:"tab-label","data-label":r,children:u.jsx("span",{className:n?"tool-running-shimmer":"",children:r})}),u.jsx("span",{role:"button",className:"tab-close",title:uJe(),onPointerDown:c=>c.preventDefault(),onClick:c=>{c.stopPropagation(),i()},children:u.jsx(pn,{size:14})})]})}const rO=["files-pill inline-flex items-center gap-2 min-w-0 border border-border","rounded-md py-[7px] px-[11px] bg-background text-text","no-underline [&_code]:font-mono [&_code]:text-sm","[&_code]:overflow-hidden [&_code]:text-ellipsis [&_code]:whitespace-nowrap","[&_>_svg]:shrink-0 [&_>_svg]:text-muted [a&:hover]:border-muted"].join(" ");function Qts({owner:e,repo:r,branch:t}){return!e||!r?u.jsx("span",{className:rO,children:u.jsx("code",{children:t})}):u.jsxs("a",{className:rO,href:Ly(e,r,t),target:"_blank",rel:"noopener noreferrer",title:s3({name:Te(t)}),children:[u.jsx("code",{children:t}),u.jsx(P6,{size:12})]})}function Xts(e){const r=ka(e);return r==="done"||r==="failed"||r==="cancelled"?r:"running"}const Yts=/^([A-Z][0-9]{0,2}[a-z]?)(?:\s*[:–—-]\s*|\s+)(?=\S)/;function Zts(e){const r=(e.title||e.description||e.slug).split(/\r?\n/)[0].trim(),t=r.match(Yts),n=t?r.slice(t[0].length):r;return{code:t?t[1]:null,label:n.charAt(0).toUpperCase()+n.slice(1)}}function _y(e,r){return e.createdAt-r.createdAt||e.id.localeCompare(r.id)}function wG(e,r){const t=new Map;for(const o of r){const a=t.get(o.experimentId);a?a.push(o):t.set(o.experimentId,[o])}const n=e.map(o=>{const a=(t.get(o.id)??[]).slice().sort((c,_)=>c.createdAt-_.createdAt||c.id.localeCompare(_.id)),i=a.at(-1)??null;return{id:o.id,experiment:o,parent:null,missingParentId:null,children:[],runs:a,latestRun:i,status:i?Xts(i):"none",...Zts(o),task:o.chatSessionId??null,createdAt:o.createdAt}}),s=new Map(n.map(o=>[o.id,o]));for(const o of n){const a=o.experiment.parentExperimentId,i=a?s.get(a):void 0;i?(o.parent=i,i.children.push(o)):a&&(o.missingParentId=a)}for(const o of n)o.children.sort(_y);return n}function Jts(e){const r=[];for(let t=e.parent;t;t=t.parent)r.unshift(t);return r}function ers(e,r=22){return e.code?e.code:e.label.length>r?e.label.slice(0,r-1).trimEnd()+"…":e.label}function trs(e,r={}){const t=new Set(e.nodes.map(m=>m.id)),n=m=>m.children.filter(x=>t.has(x.id)),s=new Map,o=new Map,a=m=>{const x=s.get(m.id);if(x!==void 0)return x;const k=1+n(m).reduce((v,w)=>v+a(w),0);return s.set(m.id,k),k},i=m=>[...m].sort((x,k)=>c(k)-c(x)||a(k)-a(x)||_y(k,x))[0],c=m=>{const x=o.get(m.id);if(x!==void 0)return x;const k=n(m);let v=1;if(k.length){const w=i(k),b=k.filter(y=>y!==w);v=Math.max(c(w),1+Math.max(0,...b.map(c)))}return o.set(m.id,v),v},_=m=>[m,...n(m).flatMap(_)],d=[],f=(m,x,k)=>{var b;if(k&&r.collapseFinished&&!((b=r.expanded)!=null&&b.has(m.id))){const y=_(m);if(y.length>=4&&y.every(S=>S.status==="done")&&!y.some(S=>{var E;return(E=r.keep)==null?void 0:E.has(S.id)})){d.push({kind:"collapsed",head:m,lane:x,hidden:y});return}}d.push({kind:"experiment",node:m,lane:x});const v=n(m);if(!v.length)return;const w=i(v);for(const y of v)y!==w&&f(y,x+1,!0);f(w,x,!1)},p=e.nodes.filter(m=>!m.parent||!t.has(m.parent.id));for(const m of p.sort(_y))m.parent&&d.push({kind:"lead-in",node:m,from:m.parent,lane:0}),f(m,0,!1);return d}function rrs(e,r=!1){const t=[...e.nodes].sort(_y);return r&&t.reverse(),t.map(n=>({kind:"experiment",node:n,lane:0}))}function kG(e){return e.reduce((r,t)=>Math.max(r,t.lane+1),0)}function nrs(e){const r=y0(e.backend);return r?[r,II(e.backend)].filter(Boolean).join(" · "):"—"}function srs(e){var t;const r=(t=e.backend)==null?void 0:t.jobId;return typeof r=="string"||typeof r=="number"?String(r):"—"}const _j=14,jG=15,fy=e=>jG+_j/2+e*_j,nO={done:vS,failed:_I,cancelled:uI,running:fI,none:Q7t},ors={done:"var(--accent-green)",failed:"var(--accent-red)",cancelled:"var(--muted)",running:"var(--accent-teal)",none:"var(--muted)"},kv="var(--lineage)",ars=.48,f4=1;function SG({status:e,cx:r,cy:t,r:n,color:s,background:o="var(--base)"}){const a=Math.max(1.25,n*.38),i=n-a/2;if(e==="done")return u.jsx("circle",{cx:r,cy:t,r:n,fill:s});if(e==="failed"){const _=n*1.18;return u.jsx("path",{d:`M${r} ${t-_}L${r+_} ${t}L${r} ${t+_}L${r-_} ${t}Z`,fill:s})}const c=u.jsx("circle",{cx:r,cy:t,r:i,fill:o,stroke:s,strokeWidth:a});if(e==="running")return u.jsxs("g",{children:[c,u.jsx("path",{d:`M${r} ${t-i}A${i} ${i} 0 0 1 ${r} ${t+i}Z`,fill:s})]});if(e==="cancelled"){const _=(n-a)*.7;return u.jsxs("g",{children:[c,u.jsx("line",{x1:r-_,y1:t+_,x2:r+_,y2:t-_,stroke:s,strokeWidth:a})]})}return c}function irs({status:e,word:r=!0,size:t=12}){return u.jsxs("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-sm text-text",children:[u.jsx("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:"shrink-0","aria-hidden":"true",children:u.jsx(SG,{status:e,cx:t/2,cy:t/2,r:t*.33,color:ors[e]})}),r?nO[e]():u.jsx("span",{className:"sr-only",children:nO[e]()})]})}function crs(e){return new Intl.DateTimeFormat(z(),{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(e)}function lrs({ms:e}){return u.jsx("span",{className:"whitespace-nowrap text-xs tabular-nums text-subtext",title:crs(e),children:rc(e)})}function urs(e,r){const t=fy(e.row.lane),n=fy(r.row.lane);if(t===n)return`M${t} ${e.y+6}V${r.y-6}`;const s=r.top-7;return`M${t} ${e.y+6}V${s}A7 7 0 0 0 ${t+7} ${s+7}H${n-7}A7 7 0 0 1 ${n} ${s+14}V${r.y-6}`}function sO(e){return e.kind==="collapsed"?e.head:e.node}function _rs({placed:e,height:r,path:t,selectedId:n}){const s=new Map;for(const c of e)c.row.kind!=="lead-in"&&s.set(sO(c.row).id,c);const o=[];for(const c of e){if(c.row.kind==="lead-in"){const f=s.get(c.row.node.id);f&&o.push({d:`M${fy(0)} ${c.top+6}V${f.y-6}`,hot:t.has(c.row.node.id)&&t.has(c.row.from.id),dotted:!0});continue}const _=sO(c.row),d=_.parent?s.get(_.parent.id):void 0;d&&o.push({d:urs(d,c),hot:t.has(_.id)&&t.has(_.parent.id),dotted:!1})}const a=jG+_j*kG(e.map(c=>c.row))+8,i=(c,_)=>u.jsx("path",{d:c.d,fill:"none",stroke:c.hot?"var(--primary)":kv,strokeOpacity:c.hot?1:ars,strokeWidth:c.hot?2:1.5,strokeLinecap:"round",strokeDasharray:c.dotted?"1.5 3.5":void 0},_);return u.jsxs("svg",{className:"pointer-events-none absolute left-0 top-0 z-10",width:a,height:r,"aria-hidden":"true",children:[o.filter(c=>!c.hot).map(i),o.filter(c=>c.hot).map(i),e.map((c,_)=>{if(c.row.kind==="lead-in")return null;const d=fy(c.row.lane);if(c.row.kind==="collapsed")return u.jsxs("g",{children:[u.jsx("circle",{cx:d,cy:c.y+2.5,r:3.5,fill:"var(--base)",stroke:kv,strokeOpacity:f4,strokeWidth:1.25}),u.jsx("circle",{cx:d,cy:c.y-1.5,r:3.5,fill:"var(--base)",stroke:kv,strokeOpacity:f4,strokeWidth:1.25})]},_);const f=c.row.node,p=f.id===n,m=t.has(f.id),x=m?"var(--primary)":kv;return u.jsxs("g",{opacity:m?1:f4,children:[!f.parent&&!f.missingParentId&&u.jsx("circle",{cx:d,cy:c.y,r:7,fill:"none",stroke:x,strokeWidth:1,opacity:.7}),p&&u.jsx("circle",{cx:d,cy:c.y,r:8.5,fill:"var(--primary)",fillOpacity:.18}),u.jsx(SG,{status:f.status,cx:d,cy:c.y,r:p?4.6:4,color:x,background:p?"var(--highlight)":"var(--base)"})]},_)})]})}function d4({node:e,current:r,onSelect:t}){return u.jsxs("button",{type:"button",disabled:r,"aria-current":r?"true":void 0,...$n(n=>t(e.id,n)),className:`flex min-w-0 items-center gap-2 rounded-sm px-1.5 py-1 text-start ${r?"bg-highlight":"hover:bg-hover-faint"}`,children:[u.jsx(irs,{status:e.status,word:!1,size:11}),e.code&&u.jsx("span",{className:"w-7 shrink-0 font-mono text-xs text-subtext",children:e.code}),u.jsx("span",{className:`min-w-0 flex-1 truncate text-sm text-text ${r?"font-medium":""}`,children:e.label}),u.jsx(lrs,{ms:e.createdAt})]})}function frs({node:e,onSelect:r}){const[t,n]=T.useState(!1);T.useEffect(()=>n(!1),[e.id]);const s=Jts(e),o=s.slice(0,Math.max(0,s.length-4)),a=t?s:s.slice(-4);return u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h2",{className:"m-0 text-sm font-semibold text-text",children:yD()}),u.jsxs("div",{className:"flex flex-col",children:[s.length>0&&u.jsx("div",{className:"mb-1 text-sm text-subtext",children:mCt()}),o.length>0&&u.jsxs("button",{type:"button","aria-expanded":t,onClick:()=>n(i=>!i),className:"flex min-w-0 items-center gap-1.5 px-1.5 py-1 text-start text-xs text-subtext hover:text-text",title:o.map(i=>i.label).join(" → "),children:[u.jsx(Ca,{size:11,className:`shrink-0 ${t?"rotate-90":""}`}),u.jsx("span",{className:"truncate",children:t?My():WCt({count:mr(o.length),steps:o.map(i=>ers(i,18)).join(" → ")})})]}),a.map(i=>u.jsx(d4,{node:i,onSelect:r},i.id)),u.jsx(d4,{node:e,current:!0,onSelect:r}),e.children.length>0&&u.jsxs("div",{className:"mt-3 flex flex-col gap-1 pt-3",children:[u.jsx("div",{className:"text-sm text-subtext",children:CCt()}),e.children.map(i=>u.jsx(d4,{node:i,onSelect:r},i.id))]})]})]})}const h4=["experiment-overview-section mt-5.5 pt-4.5 border-t border-t-border-variant","[&_h2]:mt-0 [&_h2]:mx-0 [&_h2]:mb-3.5 [&_h2]:text-text [&_h2]:text-sm","[&_h2]:font-semibold"].join(" "),oO=["experiment-overview-command block mt-[13px] text-text text-sm","wrap-anywhere"].join(" ");function aO(e){return new Date(e).toLocaleString(z(),{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}function iO(e,r){return xg((e.endedAt??r)-e.createdAt)}function drs({experiment:e,lineageNode:r,onOpenExperiment:t,parentExperiment:n,project:s,runs:o,onOpenLogs:a,onOpenCode:i,onOpenDiff:c}){const _=o[0]??null,d=wI(o),f=o.some(x=>x.status==="running"||x.status==="starting"),[p,m]=T.useState(()=>Date.now());return T.useEffect(()=>{if(!f)return;m(Date.now());const x=window.setInterval(()=>m(Date.now()),1e3);return()=>window.clearInterval(x)},[f]),u.jsx("div",{className:"experiment-overview absolute inset-0 overflow-y-auto bg-background [&_h1]:m-0 [&_h1]:text-text [&_h1]:text-xl [&_h1]:leading-tight",children:u.jsxs("div",{className:"experiment-overview-inner w-full max-w-230 my-0 mx-auto pt-6.5 px-7 pb-10 [@media((max-width:_720px))]:pt-5 [@media((max-width:_720px))]:px-4.5 [@media((max-width:_720px))]:pb-8",children:[u.jsxs("header",{className:"experiment-overview-head flex items-start justify-between gap-6",children:[u.jsxs("div",{className:"experiment-overview-heading min-w-0",children:[u.jsx("h1",{children:e.title||e.slug}),u.jsx("div",{className:"experiment-overview-slug mt-[5px] text-muted text-sm",children:e.slug})]}),u.jsx(nu,{status:_?ka(_):"idle"})]}),u.jsxs("div",{className:"experiment-overview-actions flex gap-[7px] mt-4.5 [@media((max-width:_720px))]:flex-wrap",children:[_&&u.jsxs(Ee,{...$n(x=>a(_.id,x)),children:[u.jsx(nc,{size:15}),Tdt()]}),u.jsxs(Ee,{...$n(i),children:[u.jsx(Fy,{size:15}),Q_t()]}),u.jsx(Va,{interactive:!0,content:Gft(),children:u.jsxs(Ee,{disabled:!n,...$n(c),children:[u.jsx(bOn,{size:15}),$ft()]})})]}),e.description&&u.jsxs("section",{className:"experiment-overview-section mt-5.5 pt-4.5 border-t border-t-border-variant [&_h2]:mt-0 [&_h2]:mx-0 [&_h2]:mb-3.5 [&_h2]:text-text [&_h2]:text-sm [&_h2]:font-semibold overview-description [&_.md]:text-text [&_.md]:leading-[1.65]",children:[u.jsx("h2",{children:Sft()}),u.jsx(Wc,{text:e.description})]}),u.jsxs("section",{className:h4,children:[u.jsx("h2",{children:_?P_t():ght()}),_&&u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"experiment-overview-meta flex items-center flex-wrap gap-y-2.5 gap-x-4.5 text-text text-sm [&_svg]:text-muted [&_.backend-badge]:text-text [&_.status-badge]:text-text [&_>_span]:inline-flex [&_>_span]:items-center [&_>_span]:gap-[5px] [&_code]:text-text [&_code]:text-xs",children:[u.jsx(nu,{status:ka(_)}),u.jsx(B6,{backend:_.backend}),u.jsxs("span",{title:iht(),children:[u.jsx(CMn,{size:13}),aO(_.createdAt)]}),u.jsxs("span",{title:tdt(),children:[u.jsx(PMn,{size:13}),iO(_,p)]}),_.commitSha&&u.jsxs("span",{title:oft(),children:[u.jsx(gOn,{size:14}),u.jsx("code",{children:_.commitSha.slice(0,7)})]}),_.exitCode!==null&&_.exitCode!==void 0&&_.exitCode!==0&&u.jsxs("span",{children:[_dt()," ",_.exitCode]})]}),_.command&&u.jsxs("code",{className:oO,children:["$ ",_.command]}),d&&u.jsx("p",{className:"experiment-overview-monitoring mt-4 text-accent-amber text-sm wrap-anywhere",children:d}),_.resultMarkdown&&u.jsx("div",{className:`experiment-overview-result mt-4 [&.failed]:text-accent-red ${_.status==="failed"?"failed":""}`,children:u.jsx(Wc,{text:_.resultMarkdown})})]})]}),o.length>0&&u.jsxs("section",{className:h4,children:[u.jsx("h2",{children:Ydt()}),u.jsx("div",{className:"experiment-run-history divide-y divide-border-variant [&_button]:w-full [&_button]:grid [&_button]:grid-cols-[minmax(72px,_0.7fr)_minmax(100px,_1fr)_minmax(70px,_0.7fr)_60px_16px] [&_button]:items-center [&_button]:gap-3.5 [&_button]:py-[11px] [&_button]:px-0.5 [&_button]:text-text [&_button]:text-start [&_button]:text-sm [&_button:hover]:bg-surface [@media((max-width:_720px))]:[&_button]:grid-cols-[65px_1fr_60px_16px] [@media((max-width:_720px))]:[&_button_>_:nth-child(3)]:hidden",children:o.map((x,k)=>u.jsxs("button",{...$n(v=>a(x.id,v)),children:[u.jsxs("span",{className:"experiment-run-number text-xs font-medium",children:[Fdt()," ",o.length-k]}),u.jsx(nu,{status:ka(x)}),u.jsx("span",{children:rc(x.createdAt)}),u.jsx("span",{children:iO(x,p)}),u.jsx(nc,{size:13})]},x.id))})]}),r&&u.jsx("div",{className:"mt-5.5 border-t border-border-variant pt-4.5",children:u.jsx(frs,{node:r,onSelect:t})}),u.jsxs("section",{className:h4,children:[u.jsx("h2",{children:"Git"}),u.jsxs("div",{className:"experiment-overview-meta flex items-center flex-wrap text-text text-sm [&_svg]:text-muted [&_.backend-badge]:text-text [&_.status-badge]:text-text [&_>_span]:inline-flex [&_>_span]:items-center [&_>_span]:gap-[5px] [&_code]:text-text [&_code]:text-xs experiment-overview-git-meta gap-y-[9px] gap-x-3.5 [&_.files-pill]:py-[5px] [&_.files-pill]:px-2 [&_.files-pill]:rounded-sm [&_.files-pill_code]:text-xs",children:[u.jsx(Qts,{owner:s.githubEnabled?s.githubOwner:"",repo:s.githubEnabled?s.githubRepo:"",branch:e.branchName}),n&&u.jsxs("span",{children:[xdt()," ",u.jsx("code",{children:n.slug})]}),u.jsxs("span",{title:aO(e.createdAt),children:[pft()," ",rc(e.createdAt)]})]}),e.runCommand!==(_==null?void 0:_.command)&&u.jsxs("code",{className:oO,children:["$ ",e.runCommand]})]})]})})}function cO(e){const r=atob(e),t=new Uint8Array(r.length);for(let n=0;n{const t=r.current;if(!t)return;const{terminal:n,dispose:s}=Gy(t,!0);let o=!1,a=0,i=!1,c=!1;async function _(){if(i){c=!0;return}i=!0;try{for(;;){const f=await _En(e,a);if(o)return;if(f.dataBase64&&n.write(cO(f.dataBase64)),a=f.nextOffset,f.eof)break}}catch{}finally{i=!1,c&&!o&&(c=!1,_())}}const d=QAn(e,f=>{if(o)return;const p=cO(f.dataBase64);!i&&f.offset===a?(n.write(p),a+=p.length):f.offset+p.length>a&&_()});return _(),()=>{o=!0,d(),s()}},[e]),u.jsx("div",{ref:r,className:"h-full w-full"})}function prs({experiment:e,experiments:r,project:t,view:n,runs:s,selectedRunId:o,onSelectRun:a,parentExperiment:i,onOpenView:c,onOpenCode:_,onOpenExperiment:d}){const f=s.filter(p=>p.experimentId===e.id).sort((p,m)=>m.createdAt-p.createdAt);if(n==="overview"){const p=wG(r,s).find(m=>m.id===e.id);return u.jsx(drs,{lineageNode:p??null,onOpenExperiment:d,experiment:e,parentExperiment:i,project:t,runs:f,onOpenLogs:(m,x)=>c("terminal",m,x),onOpenCode:m=>_("files",m),onOpenDiff:m=>_("changes",m)})}return u.jsx(mrs,{experiment:e,expRuns:f,selectedRunId:o,onSelectRun:a})}function mrs({experiment:e,expRuns:r,selectedRunId:t,onSelectRun:n}){const[s,o]=T.useState(null),[a,i]=T.useState(null),[c,_]=T.useState(!1),d=T.useRef(null),f=t?r.find(b=>b.id===t)??null:r[0]??null,p=(f==null?void 0:f.status)==="running"||(f==null?void 0:f.status)==="starting",m=nt(FI()).data,x=f?MI(m,f):null,k=!!(f&&p&&(f.cancelRequested||a===f.id)),v=b=>{const y=r.findIndex(S=>S.id===b);return y===-1?r.length:r.length-y};T.useEffect(()=>{if(!c)return;const b=y=>{var S;(S=d.current)!=null&&S.contains(y.target)||_(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[c]);async function w(){if(f){o(null),i(f.id);try{await SI(f.id)}catch(b){i(null),o(b instanceof Error?b.message:String(b))}}}return u.jsxs("div",{className:"term-view absolute inset-0 flex flex-col bg-background z-20",children:[u.jsxs("div",{className:"term-bar flex items-center gap-2 h-10 py-0 px-2.5 border-b border-b-border shrink-0 [&_.error]:text-sm [&_.error]:text-accent-red [&_.btn]:inline-flex [&_.btn]:items-center [&_.btn]:gap-[5px]",children:[u.jsx("div",{className:"term-title min-w-0 text-sm font-semibold text-text overflow-hidden text-ellipsis whitespace-nowrap",title:e.title||e.slug,children:e.title||e.slug}),u.jsx("span",{className:"flex-1"}),s&&u.jsx("span",{className:"error",role:"alert",children:s}),x&&u.jsxs(T_,{size:"small",variant:"ghost",title:n3(),href:x,target:"_blank",rel:"noopener noreferrer",children:[u.jsx(SP,{size:13}),"Trackio"]}),p&&u.jsxs(Ee,{size:"small",variant:"ghost",disabled:k,onClick:()=>void w(),children:[u.jsx(zP,{size:13}),k?Let():_D()]}),r.length>0&&f&&u.jsxs("div",{className:"run-history relative shrink-0",ref:d,children:[u.jsxs(Ee,{title:nut(),"aria-expanded":c,onClick:()=>_(b=>!b),children:[u.jsxs("span",{children:[HE()," ",v(f.id)]}),u.jsx(nu,{status:k?"cancelling":ka(f)}),u.jsx(oc,{size:14,className:"run-picker-chev text-muted shrink-0"})]}),c&&u.jsx("div",{className:"history-menu absolute top-[calc(100%_+_6px)] end-0 min-w-57.5 max-h-80 overflow-y-auto bg-background border border-border rounded-lg shadow-menu p-[5px] z-50",children:r.map(b=>u.jsxs(_r,{className:"justify-start",active:b.id===(f==null?void 0:f.id),onClick:()=>{n(b.id),_(!1)},children:[u.jsxs("span",{className:"font-medium",children:[HE()," ",v(b.id)]}),u.jsx(nu,{status:ka(b)}),u.jsx("span",{className:"ms-auto text-xs text-muted",children:rc(b.createdAt)})]},b.id))})]})]}),f&&u.jsxs("div",{className:"term-provenance","aria-label":Klt(),children:[u.jsxs("span",{children:[vlt()," ",u.jsx("code",{children:f.id})]}),u.jsxs("span",{children:[clt()," ",u.jsx("code",{children:f.commitSha||LCt()})]}),u.jsxs("span",{children:[Zct()," ",u.jsx("code",{children:nrs(f)})]}),u.jsxs("span",{children:[Elt()," ",u.jsx("code",{children:srs(f)})]})]}),u.jsx("div",{className:"term-fill flex-1 min-h-0 bg-terminal pt-1 pe-0 pb-1 ps-1.5",children:f?u.jsx(hrs,{runId:f.id},f.id):u.jsx("div",{className:"term-empty h-full flex items-center justify-center p-6 text-center text-sm text-muted",children:t?yi():Hct()})})]})}let fj=!1;function lO(e){fj=!0;try{return window.confirm(e)}finally{fj=!1}}const dj=e=>e.replace(/\r\n/g,` `),uO=(e,r,t)=>{const n=dj(r);return{path:e,draft:n,baseline:n,version:t,crlf:r.includes(`\r `),conflict:null}},Hl=e=>e.draft!==e.baseline,grs=(e,r)=>({...e,draft:r,conflict:r===e.baseline?null:e.conflict}),vrs=e=>e.crlf?e.draft.replace(/\n/g,`\r diff --git a/ui/dist/index.html b/ui/dist/index.html index 869ac4a2..4382499f 100644 --- a/ui/dist/index.html +++ b/ui/dist/index.html @@ -49,7 +49,7 @@ html { background: #ffffff; } html[data-theme="dark"] { background: #0e0c0c; } - + diff --git a/ui/src/components/ChatPanel.tsx b/ui/src/components/ChatPanel.tsx index 62c16c91..dee43c71 100644 --- a/ui/src/components/ChatPanel.tsx +++ b/ui/src/components/ChatPanel.tsx @@ -6487,7 +6487,8 @@ export function ChatPanel({ {railOpen && rail}
{!railOpen &&
{railReopen}
} -
+ {/* Keyed per view so no tab inherits the chat thread's or another tab's scroll offset. */} +
{contentError ?
{contentError}
: contentLoading ? {m.chat_panel_loading_conversation()} : children}