From 426e2ed0142c8ceefd990479eaa2579120650ad2 Mon Sep 17 00:00:00 2001 From: Daniel Kim Date: Thu, 22 Oct 2026 16:58:28 -0700 Subject: [PATCH] Fix sidebar menu stacking in virtualized lists --- .../{PdfPreview-CsvPNokB.js => PdfPreview-MpaSwii-.js} | 2 +- ui/dist/assets/{index-BsYgd7Kt.js => index-DqGRu4wp.js} | 6 +++--- ui/dist/index.html | 2 +- ui/src/components/ChatPanel.tsx | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename ui/dist/assets/{PdfPreview-CsvPNokB.js => PdfPreview-MpaSwii-.js} (99%) rename ui/dist/assets/{index-BsYgd7Kt.js => index-DqGRu4wp.js} (99%) diff --git a/ui/dist/assets/PdfPreview-CsvPNokB.js b/ui/dist/assets/PdfPreview-MpaSwii-.js similarity index 99% rename from ui/dist/assets/PdfPreview-CsvPNokB.js rename to ui/dist/assets/PdfPreview-MpaSwii-.js index 5ce8792d6..35b644a07 100644 --- a/ui/dist/assets/PdfPreview-CsvPNokB.js +++ b/ui/dist/assets/PdfPreview-MpaSwii-.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-BsYgd7Kt.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-DqGRu4wp.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-BsYgd7Kt.js b/ui/dist/assets/index-DqGRu4wp.js similarity index 99% rename from ui/dist/assets/index-BsYgd7Kt.js rename to ui/dist/assets/index-DqGRu4wp.js index b86dc303d..af13e9acf 100644 --- a/ui/dist/assets/index-BsYgd7Kt.js +++ b/ui/dist/assets/index-DqGRu4wp.js @@ -1,4 +1,4 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreview-CsvPNokB.js","assets/PdfPreview-DNMWzGmA.css"])))=>i.map(i=>d[i]); +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PdfPreview-MpaSwii-.js","assets/PdfPreview-DNMWzGmA.css"])))=>i.map(i=>d[i]); var KV=Object.defineProperty;var n9=e=>{throw TypeError(e)};var VV=(e,r,t)=>r in e?KV(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var jo=(e,r,t)=>VV(e,typeof r!="symbol"?r+"":r,t),Iw=(e,r,t)=>r.has(e)||n9("Cannot "+t);var _e=(e,r,t)=>(Iw(e,r,"read from private field"),t?t.call(e):r.get(e)),mt=(e,r,t)=>r.has(e)?n9("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t),We=(e,r,t,n)=>(Iw(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t),Zt=(e,r,t)=>(Iw(e,r,"access private method"),t);var Tm=(e,r,t,n)=>({set _(s){We(e,r,s,t)},get _(){return _e(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 C0(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Pw={exports:{}},Rm={};/** * @license React * react-jsx-runtime.production.js @@ -1196,11 +1196,11 @@ ${r.trim()} `);if(i.approved===!1&&!C)return l.jsxs("details",{className:"group/question py-1 text-base text-subtext",children:[l.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:[l.jsxs("span",{children:[XE()," — ",YVe()]}),l.jsx(_o,{size:16,className:"shrink-0 text-text transition-transform duration-120 ease-standard group-open/question:rotate-90 motion-reduce:transition-none","aria-hidden":"true"})]}),l.jsx("div",{className:"mt-1 leading-normal text-subtext whitespace-pre-line wrap-anywhere",children:r})]});const R=(i.annotations??[]).map(($,L)=>({id:`${e.id}-annotation-${L}`,text:$.text}));return C?l.jsxs("div",{className:"flex flex-col gap-3 py-1",children:[r&&l.jsx("div",{className:"text-base text-text leading-normal whitespace-pre-line wrap-anywhere",children:r}),!t&&l.jsxs("div",{className:"ms-auto max-w-[88%] rounded-2xl bg-panel px-4 py-3 text-base text-text whitespace-pre-wrap wrap-anywhere",children:[r&&l.jsx("div",{className:"mb-1 truncate text-subtext",children:r}),C]}),R.length>0&&l.jsx(wy,{annotations:R,variant:"sent"})]}):R.length>0?l.jsx(wy,{annotations:R,variant:"sent"}):null}if(i.kind==="plan"){const C=!!o;return l.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 ${w?"readonly":""}`,children:[l.jsx("div",{className:"prompt-head text-base font-semibold text-text",children:i.synthesized?sVe():QE()}),l.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 ${C?"clamped":""}`,children:l.jsx(dc,{text:i.plan??"",onOpenFile:s})}),C&&l.jsx("button",{className:"prompt-plan-open self-start border-0 bg-transparent text-accent-blue text-sm p-0 cursor-pointer [&:hover]:underline",...dn(R=>o(i.plan??"",e.id,R)),children:GWe()}),!w&&!C&&l.jsxs("div",{className:iG,children:[l.jsx(Se,{size:"small",variant:"primary",onClick:()=>y({approve:!0,resumeMode:"auto"}),children:kAe()}),l.jsx(Se,{size:"small",onClick:()=>y({approve:!0,resumeMode:"bypassPermissions"}),children:MAe()}),l.jsx(Se,{size:"small",onClick:()=>y({approve:!1}),children:gFe()})]})]})}if(i.kind==="permission"){const C=i.toolInput??{},R=Eo(C,"command","cmd","filePath","file_path","path")||"",$=typeof((b=i.toolInput)==null?void 0:b.reason)=="string"&&i.toolInput.reason||"",L=Eo(C,"description")||"",I=i.header||$||L||(R?"":pG(i.tool,C)),P=`permission-heading-${e.id}`;return l.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 ${w?"readonly":""}`,role:"group","aria-labelledby":P,children:[l.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 pt-3 pb-0",children:[l.jsx("span",{className:"flex size-7 shrink-0 items-center justify-center rounded-md bg-accent-amber-subtle text-accent-amber",children:l.jsx(XS,{size:15,strokeWidth:1.8,"aria-hidden":"true"})}),l.jsx("span",{id:P,className:"text-base font-semibold text-text",children:bTe()})]}),l.jsxs("div",{className:"flex flex-col gap-3 px-3.5 py-3",children:[I&&l.jsx("div",{className:"prompt-sub text-base font-normal leading-normal text-text wrap-anywhere",children:I}),R&&l.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:R}),!w&&((S=i.nativeChoices)!=null&&S.length)?l.jsx("div",{className:"prompt-actions flex flex-wrap items-center justify-end gap-2 pt-0.5",children:i.nativeChoices.map(B=>l.jsx(Se,{size:"small",onClick:()=>y({answers:[B.id],approve:B.kind.startsWith("allow")}),children:B.label},B.id))}):!w&&l.jsxs("div",{className:"prompt-actions flex items-center justify-end gap-2 pt-0.5",children:[l.jsx(Se,{size:"small",variant:"ghost",onClick:()=>y({approve:!1}),children:U$e()}),l.jsx(Se,{size:"small",variant:"primary",onClick:()=>y({approve:!0}),children:lTe()})]})]})]})}const v=C=>{f(""),_(R=>i.multiSelect?R.includes(C)?R.filter($=>$!==C):[...R,C]:[C])},x=()=>{!w&&(d.trim()||c.length>0)&&y({answers:c,note:d.trim()||void 0})},k=()=>void y({approve:!1});return l.jsxs("div",{className:"prompt-card question flex flex-col gap-2 rounded-2xl border border-border bg-surface p-3",role:"group","aria-labelledby":`question-${e.id}`,children:[l.jsxs("div",{className:"flex items-center gap-2 text-subtext",children:[l.jsx(qP,{size:18,"aria-hidden":"true"}),l.jsx("span",{className:"flex-1 text-sm",children:i.header||XE()}),n&&l.jsx(jt,{"aria-label":YE(),disabled:w,onClick:k,children:l.jsx(fn,{size:16})})]}),l.jsx("div",{id:`question-${e.id}`,className:"text-base font-medium leading-snug text-text whitespace-pre-line wrap-anywhere",children:(z=i.question)==null?void 0:z.replace(/\n\s*\n/g,` `)}),(((N=i.options)==null?void 0:N.length)??0)>0&&l.jsx("div",{className:"prompt-options flex flex-col",children:(T=i.options)==null?void 0:T.map((C,R)=>{const $=c.includes(C.label);return l.jsxs("button",{type:"button","aria-pressed":$,className:`prompt-option flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-start text-text cursor-pointer transition-colors duration-120 ease-standard enabled:hover:bg-highlight focus-visible:bg-highlight focus-visible:outline-2 focus-visible:outline-text disabled:cursor-default ${$?"bg-panel":""}`,disabled:w,onClick:()=>v(C.label),children:[l.jsx("span",{className:`flex size-6 shrink-0 items-center justify-center rounded-md border text-sm ${$?"border-primary bg-primary-subtle text-text":"border-border bg-background text-subtext"}`,children:$?l.jsx(so,{size:14}):R+1}),l.jsxs("span",{className:"min-w-0 text-base",children:[l.jsx("span",{children:C.label}),C.description&&l.jsx("span",{className:"ms-2 text-sm text-subtext",children:C.description})]})]},C.label)})}),n&&l.jsxs("form",{className:"flex flex-wrap items-end gap-2",onSubmit:C=>{C.preventDefault(),x()},children:[l.jsxs("div",{className:"flex min-w-0 basis-48 grow items-start gap-2",children:[l.jsx(Lg,{size:18,className:"mt-2 shrink-0 text-subtext","aria-hidden":"true"}),l.jsx(ULn,{variant:"inline","aria-label":iQe(),placeholder:RVe(),value:d,onChange:C=>{f(C.target.value),_([])},onKeyDown:C=>{C.key==="Enter"&&!C.shiftKey&&!C.nativeEvent.isComposing&&C.nativeEvent.keyCode!==229&&(C.preventDefault(),x())},disabled:w,rows:1})]}),l.jsxs("div",{className:"ms-auto flex items-center gap-2",children:[l.jsx(Se,{type:"button",className:"rounded-full",disabled:w,onClick:k,children:YE()}),l.jsx(Se,{type:"submit",variant:"primary",className:"rounded-full",disabled:w||!d.trim()&&c.length===0,children:Db()})]})]})]})}function yos(e,r){return e.role==="user"?!0:e.parts.some(t=>D_(t,r))}function xos(e){const r=e.text??"",t=r.startsWith("data:")?r:ROn(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 KC(e){try{if(!navigator.clipboard)throw new Error(yS());await navigator.clipboard.writeText(e),Qt(ld(),"success")}catch(r){Qt(r instanceof Error?r.message:String(r),"error")}}function wos(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 kos({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=()=>KC(e);return l.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&&l.jsxs(l.Fragment,{children:[l.jsx(jt,{size:"small",title:BE(),"aria-label":BE(),disabled:i||!s,onClick:()=>s&&a(s),children:l.jsx(GS,{size:14})}),l.jsxs("span",{className:"fork-count text-xs text-subtext tabular-nums select-none",children:[n+1,"/",t]}),l.jsx(jt,{size:"small",title:PE(),"aria-label":PE(),disabled:i||!o,onClick:()=>o&&a(o),children:l.jsx(_o,{size:14})})]}),l.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:[l.jsx("time",{dateTime:f.toISOString(),className:"text-xs text-subtext tabular-nums me-2",children:f.toLocaleTimeString(E(),{hour:"numeric",minute:"2-digit"})}),l.jsx(jt,{size:"small","aria-label":SS(),disabled:!e,onClick:p,children:l.jsx(Ad,{size:13})})]}),l.jsx(jt,{size:"small",title:TE(),"aria-label":TE(),disabled:_,onClick:c,children:l.jsx(Lg,{size:13})})]})}const jos=A.memo(function({message:r,responseMessages:t,replies:n,activePermissionId:s,pendingTailToolId:o,onOpenFile:a,onOpenRun:i,onOpenSpawnedSession:c,runExperimentName:_,onOpenExperiment:d,experimentName:f,onRespond:p,onOpenPlan:m,onOpenSubagent:w,busy:y=!1,recoveringTurnId:v,onRecover:x,skills:k,predictTextTail:b=!1,forkCount:S,forkIndex:z=0,forkPrevId:N,forkNextId:T,forkDisabled:C,branchDisabled:R,onFork:$,onSelectFork:L}){mu();const[I,P]=A.useState(null),B=Cos(r);if(B)return l.jsx(zos,{part:B});if(r.role==="user"){const D=(n==null?void 0:n.textById.get(r.id))??r.parts.filter(ie=>ie.type==="text").map(ie=>ie.text??"").join(` `),q=ie=>!!(k!=null&&k.some(ee=>ee.name===HC(ie))),Q=r.parts.filter(ie=>ie.type==="image"&&ie.text).map(xos),W=Q.filter(ie=>!ie.isPdf),ae=Q.filter(ie=>ie.isPdf),le=r.parts.filter(ie=>ie.type==="annotation"&&ie.text).map(ie=>({id:ie.id,text:ie.text??""}));if(I!==null){const ie=()=>{const ee=I.trim();!ee||C||(P(null),$(r.id,ee))};return l.jsx("div",{className:"msg-user-group ms-auto self-end flex w-full max-w-[88%] flex-col items-end gap-1.5",children:l.jsxs("div",{className:"msg-user-edit w-full bg-panel rounded-[16px] py-2.5 px-[15px] flex flex-col gap-2",children:[l.jsx("textarea",{dir:"auto",writingsuggestions:"false",className:"w-full bg-transparent text-base text-text resize-none outline-none field-sizing-content min-h-16","aria-label":vLe(),value:I,autoFocus:!0,onChange:ee=>P(ee.target.value),onKeyDown:ee=>{if(ee.nativeEvent.isComposing||ee.nativeEvent.keyCode===229){ee.stopPropagation();return}ee.key==="Escape"?(ee.preventDefault(),P(null)):ee.key==="Enter"&&!ee.shiftKey&&(ee.preventDefault(),ie())}}),l.jsxs("div",{className:`${iG} justify-end`,children:[l.jsx(Se,{size:"small",onClick:()=>P(null),children:TRe()}),l.jsx(Se,{size:"small",variant:"primary",onClick:ie,disabled:C||!I.trim(),children:Db()})]})]})})}return l.jsxs("div",{className:"msg-user-group group/turn ms-auto self-end flex max-w-[88%] flex-col items-end gap-1.5",children:[le.length>0&&l.jsx(wy,{annotations:le,variant:"sent"}),l.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:[(n==null?void 0:n.questionById.has(r.id))&&l.jsx("div",{className:"mb-1 truncate text-subtext",children:n.questionById.get(r.id)}),l.jsx(lss,{text:D,isCommand:q}),W.length>0&&l.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:W.map((ie,ee)=>l.jsx("a",{href:ie.src,target:"_blank",rel:"noreferrer",children:l.jsx("img",{src:ie.src,alt:oCe()})},ee))}),ae.length>0&&l.jsx("div",{className:"msg-files flex flex-wrap gap-1.5 mt-2",children:ae.map((ie,ee)=>l.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:ie.src,target:"_blank",rel:"noreferrer",children:[l.jsx(nx,{size:15}),l.jsx("span",{children:ie.name})]},ee))})]}),S!==void 0&&l.jsx(kos,{text:D,createdAt:r.createdAt,count:S,index:z,prevId:N,nextId:T,onSelect:L,pagerDisabled:R,onEdit:()=>P(D),editDisabled:C})]})}const U=(t??[r]).map(PXn),G=U.map(D=>D.message),J=qXn(G,b,n),F=b&&J.answerMessageId===r.id&&!r.completedAt?"":qH({...r,parts:J.answer});return l.jsxs("div",{className:"msg-assistant group/turn text-base leading-[1.62] text-text min-w-0",children:[l.jsx(Sos,{messages:G,response:J,options:{replies:n,activePermissionId:s,pendingTailToolId:o,onOpenFile:a,onOpenRun:i,onOpenSpawnedSession:c,runExperimentName:_,onOpenExperiment:d,experimentName:f,onRespond:p,onOpenPlan:m,onOpenSubagent:w,predictTextTail:b}}),U.map(({message:D,turnStatus:q,usageLimit:Q,temporaryApiError:W})=>{var ae,le;return q&&l.jsx(WC,{part:q,usageLimited:!!Q,temporaryApiError:W,busy:y,recovering:v===((le=(ae=q.state)==null?void 0:ae.input)==null?void 0:le.turnId),onRecover:x},D.id)}),F&&l.jsx("div",{className:"mt-2 flex justify-end opacity-0 transition-opacity duration-80 ease-standard group-hover/turn:opacity-100 group-focus-within/turn:opacity-100",children:l.jsx(jt,{size:"small",title:wE(),"aria-label":wE(),onClick:()=>void KC(F),children:l.jsx(Ad,{size:13})})})]})});function Sos({messages:e,response:r,options:t}){const n=t.predictTextTail??!1,{work:s,answer:o,answerMessageId:a}=r,i=e[e.length-1],c={...t,predictTextTail:n&&a===i.id},[_,d]=A.useState(!1),[,f]=A.useState(0);if(A.useEffect(()=>{if(!n||i.completedAt!=null||s.length===0)return;const w=window.setInterval(()=>f(y=>y+1),1e3);return()=>window.clearInterval(w)},[n,i.completedAt,s.length]),s.length===0)return l.jsx(l.Fragment,{children:hb(o,c)});const p=e.reduce((w,y)=>{const v=y.completedAt??(n&&y.id===i.id?Date.now():null);return v===null?w:(w??0)+Math.max(0,v-y.createdAt)},null),m=p===null?null:p<6e4||p>=36e5?Mg(p):tet({minutes:hr(Math.floor(p/6e4)),seconds:hr(Math.floor(p/1e3)%60)});return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"turn-work mb-4",children:[l.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":_,"data-work-toggle":!0,onClick:()=>d(w=>!w),children:[l.jsx("span",{children:m===null?GJe():fet({duration:m})}),l.jsx(_o,{size:16,className:`shrink-0 text-muted transition-transform duration-200 ease-standard motion-reduce:transition-none ${_?"rotate-90":""}`})]}),l.jsx("div",{className:`tool-group-disclosure ${_?"open":""}`,"aria-hidden":!_,inert:!_,children:l.jsx("div",{className:"tool-group-disclosure-inner",children:l.jsx("div",{className:"turn-work-content flex flex-col gap-4 pt-4",children:s.map(w=>l.jsx("div",{children:hb(w.parts,{...t,predictTextTail:!1,pendingTailToolId:w.id===i.id?t.pendingTailToolId:null})},w.id))})})})]}),l.jsx("div",{className:"turn-answer",children:hb(o,c)})]})}function Cos(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===fP?r:null}function zos({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?dD():s&&o!==null?GCe({code:hr(o)}):null;return l.jsx("div",{className:"msg-shell ms-auto self-end flex w-full max-w-[88%] flex-col items-stretch gap-1.5",children:l.jsxs("div",{dir:"ltr",className:"max-w-full bg-panel rounded-[16px] py-2.5 px-[15px] text-base",children:[l.jsxs("div",{className:"flex items-start gap-2 font-mono text-sm text-text whitespace-pre-wrap wrap-anywhere",children:[l.jsxs("span",{className:"sr-only",children:[vD()," "]}),l.jsx(O_,{size:16,strokeWidth:1.6,className:`mt-0.5 shrink-0 ${s?"text-accent-red":"text-muted"}`,"aria-hidden":"true"}),l.jsx("span",{children:t})]}),a&&l.jsx("div",{className:`${UC} mt-2`,children:a.slice(0,2e4)}),i&&l.jsx("div",{className:`mt-1.5 text-xs ${s?"text-accent-red":"text-muted"}`,children:i})]})})}function hb(e,r){var S;const{replies:t,expansionState:n,activePermissionId:s,pendingTailToolId:o,onOpenFile:a,onOpenRun:i,onOpenSpawnedSession:c,runExperimentName:_,onOpenExperiment:d,experimentName:f,onRespond:p,onOpenPlan:m,onOpenSubagent:w,predictTextTail:y=!1}=r,v=e.filter(z=>z.type!=="steer"&&D_(z,s)).at(-1),x=[];let k=[];const b=()=>{k.length!==0&&(x.push(l.jsx(bos,{parts:k,expansionState:n,pendingTail:k.some(z=>z.id===o),streaming:y,onOpenSubagent:w,onOpenFile:a,onOpenRun:i,onOpenSpawnedSession:c,runExperimentName:_,onOpenExperiment:d,experimentName:f},`tg-${k[0].id}`)),k=[])};for(const z of e)if(D_(z,s)){if(z.type==="tool"&&z.tool==="api_error"){b(),x.push(l.jsx(WC,{part:z,busy:!1,recovering:!1,temporaryApiError:!0},z.id));continue}if(z.type==="tool"){k.push(z);continue}if(b(),z.type==="text")x.push(l.jsx(dc,{text:z.text,onOpenFile:a,onOpenRun:i,predict:y&&z.id===(v==null?void 0:v.id)},z.id));else if(z.type==="steer")x.push(l.jsxs("div",{dir:"auto",role:"note","aria-label":AKe(),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:[(t==null?void 0:t.questionById.has(z.id))&&l.jsx("div",{className:"mb-1 truncate text-subtext",children:t.questionById.get(z.id)}),(t==null?void 0:t.textById.get(z.id))??z.text]},z.id));else{if(z.type==="prompt"&&((S=z.prompt)==null?void 0:S.kind)==="question"&&!z.prompt.resolved)continue;z.type==="prompt"&&z.prompt&&x.push(l.jsx(gG,{part:z,questionText:t==null?void 0:t.questionById.get(z.id),answerInTranscript:t==null?void 0:t.prompts.has(z.id),onRespond:p,onOpenFile:a,onOpenPlan:m},z.id))}}return b(),x}function Eos(e){return vd(e).label}function Nos(e){const r=(e??"").toLowerCase();return r==="subagent"||r==="task"||r==="agent"}function pb(e){var r,t;return e.type==="tool"&&(Bp(e)||Nos(e.tool)||((r=e.state)==null?void 0:r.title)==="subagent"||(((t=e.children)==null?void 0:t.length)??0)>0)}function Aos(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.startsWith("The subagent is working in the background")?"":r}function wj(e,r){for(const t of e){if(t.id===r)return t;const n=t.children&&wj(t.children,r);if(n)return n}return null}function Tos({spawn:e,expansionState:r,onOpenFile:t,onOpenRun:n,runExperimentName:s,onOpenExperiment:o,experimentName:a,onOpenSubagent:i}){var y,v,x,k;if(Bp(e))return l.jsx(vG,{part:e});const c=e.children??[],_=((y=e.state)==null?void 0:y.status)==="running",d=((v=e.state)==null?void 0:v.status)==="error",f=d?e2(((x=e.state)==null?void 0:x.error)||((k=e.state)==null?void 0:k.output)||""):"",p=hb(c,{expansionState:r,onOpenFile:t,onOpenRun:n,runExperimentName:s,onOpenExperiment:o,experimentName:a,onOpenSubagent:i,predictTextTail:_,pendingTailToolId:_?PH(c):null}),w=c.some(b=>b.type==="text"&&!!b.text)?"":Aos(e);return l.jsxs("div",{className:"msg-assistant text-base leading-[1.62] text-text min-w-0",children:[d&&l.jsxs("span",{className:"sr-only",children:[mS()," "]}),f&&l.jsx("div",{className:UC,children:f.slice(0,2e4)}),p.length===0&&!w&&!f?l.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:_?gS():YEe()}):l.jsxs(l.Fragment,{children:[p,w&&l.jsx(dc,{text:w,onOpenFile:t,onOpenRun:n})]})]})}function vG({part:e}){const r=OXn(e),t=l.jsxs(l.Fragment,{children:[l.jsx(t0,{activity:{kind:"agent",label:w3()},className:"text-muted"}),l.jsx("span",{className:`${qC} text-subtext`,children:w3()})]});return r?l.jsxs("details",{className:"min-w-0 [&[open]_.update-chevron]:rotate-90",children:[l.jsxs("summary",{className:"tool-row flex cursor-pointer list-none items-center gap-2 min-w-0 py-[3px] px-1 rounded-sm focus-visible:outline-2 focus-visible:outline-text [&::-webkit-details-marker]:hidden",children:[t,l.jsx(_o,{size:12,className:"update-chevron text-muted","aria-hidden":"true"})]}),l.jsx("div",{className:"ps-7 py-2 text-sm",children:l.jsx(dc,{text:r})})]}):l.jsx("div",{className:"tool-row flex items-start gap-2 min-w-0 py-[3px] px-1",children:t})}function fO({part:e,pendingTail:r,onOpenSubagent:t}){var c,_,d;const n=((c=e.state)==null?void 0:c.status)==="error",s=e2(((_=e.state)==null?void 0:_.error)||((d=e.state)==null?void 0:d.output)||""),o=r&&!n?GC(vd(e)):vd(e),a=mG(!!(r&&!n));if(Bp(e))return l.jsx(vG,{part:e});const i=l.jsxs(l.Fragment,{children:[n&&l.jsxs("span",{className:"sr-only",children:[mS()," "]}),n?l.jsx("span",{className:"flex h-6 shrink-0 items-center text-accent-red",children:l.jsx(GP,{size:16,strokeWidth:1.75,className:"subagent-icon","aria-hidden":"true"})}):l.jsx(t0,{activity:o,className:`subagent-icon ${a?"tool-running-shimmer-icon":"text-muted"}`}),l.jsx("span",{className:`${qC} ${a?"tool-running-shimmer":n?"text-accent-red":"text-subtext"}`,children:o.label})]});return l.jsxs("button",{className:"subagent-row flex items-start gap-2 w-full 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:dAe(),...dn(f=>t==null?void 0:t(e.id,o.label,f)),disabled:!t,children:[i,l.jsx("span",{className:"subagent-row-chevron flex h-6 shrink-0 items-center text-muted",children:l.jsx(_o,{size:12})})]})}function Ros(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 VC(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")||pG(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 Mos(e){const[r,t]=A.useState({text:"",sequence:0}),n=A.useRef(null);return A.useEffect(()=>{var w,y,v,x,k;const s=((w=e[0])==null?void 0:w.id)??"",{messageId:o,states:a}=Ros(e),i=VC(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(b=>({text:i?dE({label:tu(i.label)}):"",sequence:b.sequence+1}));return}const c=n.current.messageId===o?n.current.states:new Map,_=n.current.permissionPath,d=[...a].filter(([b,S])=>{var z;return((z=c.get(b))==null?void 0:z.status)!==S.status});if(n.current={transcript:s,messageId:o,states:a,permissionPath:(i==null?void 0:i.path)??null},i&&i.path!==_){t(b=>({text:dE({label:tu(i.label)}),sequence:b.sequence+1}));return}const f=(y=d.find(([,b])=>Dx(b.part)))==null?void 0:y[1].part;if((f==null?void 0:f.id)==="turn-recovery"){const b=GH((x=(v=f.state)==null?void 0:v.input)==null?void 0:x.recoveryAction);t(S=>({text:`${$ye()}${b?` ${b==="retry"?Pbe():Nbe()}`:""}`,sequence:S.sequence+1}));return}if((f==null?void 0:f.id)==="turn-retry"){t(b=>({text:bbe(),sequence:b.sequence+1}));return}const p=d.filter(([,b])=>b.status==="error");if(p.length>0){const b=p.slice(0,2).map(([,S])=>vd(S.part).label).join(", ");t(S=>({text:p.length===1?pye({labels:b}):Sye({count:hr(p.length),labels:b}),sequence:S.sequence+1}));return}const m=d.filter(([,b])=>b.status==="running");if(m.length>0){const b=(k=m.at(-1))==null?void 0:k[1].part;t(S=>({text:b?GC(vd(b)).label:Qbe(),sequence:S.sequence+1}));return}d.some(([,b])=>b.status==="completed")&&t(b=>({text:oye(),sequence:b.sequence+1}))},[e]),r}const Oos=A.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:w,onOpenExperiment:y,experimentName:v,onRespond:x,onOpenPlan:k,onOpenSubagent:b,recoveringTurnId:S,onRecover:z,skills:N}){var q,Q,W;mu();const T=A.useMemo(()=>DXn(r),[r]),C=((q=VC(r))==null?void 0:q.id)??null,R=A.useRef([]),$=A.useMemo(()=>(R.current=HXn(r,R.current),R.current.filter(ae=>ae.some(le=>yos(le,C)))),[r,C]),L=A.useMemo(()=>{const ae=$.filter(le=>le[0].role==="user"&&!le[0].id.startsWith(nd));return MXn(a,r,ae.map(le=>le[0]),le=>le.startsWith(nd))},[r,$,a]),I=A.useRef(new Set),[P,B]=A.useState(!1),U=A.useCallback(ae=>$[ae][0].id,[$]),G=A.useCallback(ae=>{if(P)return $.map((ie,ee)=>ee);const le=new Set(pC(ae));return $.forEach((ie,ee)=>{I.current.has(ie[0].id)&&le.add(ee)}),[...le].sort((ie,ee)=>ie-ee)},[$,P]),J=IH({count:$.length,useFlushSync:!1,getScrollElement:()=>t.current,getItemKey:U,estimateSize:()=>400,overscan:1,initialRect:{width:((Q=t.current)==null?void 0:Q.clientWidth)??0,height:((W=t.current)==null?void 0:W.clientHeight)??0},initialOffset:()=>{var ae;return Math.max(0,$.length*400-(((ae=t.current)==null?void 0:ae.clientHeight)??0))},anchorTo:s.current?"end":"start",followOnAppend:!0,scrollEndThreshold:60,rangeExtractor:G});A.useLayoutEffect(()=>{const ae=()=>J.scrollToEnd();return n.current=ae,o(),()=>{n.current=null}},[J,n,o]),A.useEffect(()=>{const ae=()=>{var ee;const le=window.getSelection();if(!le||le.isCollapsed||!le.rangeCount)return;const ie=le.getRangeAt(0);for(const K of((ee=t.current)==null?void 0:ee.querySelectorAll("[data-message-id]"))??[])ie.intersectsNode(K)&&K.dataset.messageId&&I.current.add(K.dataset.messageId)};return document.addEventListener("selectionchange",ae),()=>document.removeEventListener("selectionchange",ae)},[t]);const te=r.at(-1),F=Mos(r),D=d?BH(r):null;return l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"sr-only",role:"status","aria-live":"polite",children:l.jsx("span",{children:F.text},F.sequence)}),l.jsx("button",{type:"button",className:"sr-only focus:not-sr-only","aria-pressed":P,onClick:()=>B(ae=>!ae),children:CYe()}),l.jsx("div",{className:"relative",style:{height:J.getTotalSize()},children:J.getVirtualItems().map(ae=>{var ne,ce,me,ye;const le=$[ae.index],ie=le[le.length-1],ee=le[0].id,K=d||S!==null;return l.jsx("div",{"data-index":ae.index,"data-message-id":ee,ref:J.measureElement,className:"absolute left-0 w-full pb-4",style:{top:ae.start},onClickCapture:Ce=>{!(Ce.target instanceof Element)||!Ce.target.closest("[data-work-toggle]")||(s.current=!1,J.setOptions({...J.options,anchorTo:"start"}))},onPointerDownCapture:()=>I.current.add(ee),onFocusCapture:()=>I.current.add(ee),children:l.jsx(jos,{message:ie,responseMessages:le,replies:T,forkCount:(ne=L.get(ie.id))==null?void 0:ne.count,forkIndex:(ce=L.get(ie.id))==null?void 0:ce.index,forkPrevId:(me=L.get(ie.id))==null?void 0:me.prevId,forkNextId:(ye=L.get(ie.id))==null?void 0:ye.nextId,forkDisabled:!i,branchDisabled:d,onFork:c,onSelectFork:_,activePermissionId:C,pendingTailToolId:(D==null?void 0:D.messageId)===ie.id?D.toolId:null,onOpenFile:f,onOpenRun:p,onOpenSpawnedSession:m,runExperimentName:w,onOpenExperiment:y,experimentName:v,onRespond:x,onOpenPlan:k,onOpenSubagent:b,busy:K,recoveringTurnId:S,onRecover:z,skills:N,predictTextTail:d&&ie===te&&ie.role==="assistant"})},ee)})})]})}),$os=(e,r)=>e==="all"?!0:e==="archived"?r:!r;function E4(e){return e instanceof Element&&e.closest("[data-side-chat]")!==null}const Los=[{id:"archived",label:jE,railLabel:jE},{id:"active",label:qAe,railLabel:CD},{id:"all",label:JAe,railLabel:gD}];function Dos({value:e,onChange:r,grouping:t,onGroupingChange:n}){const{open:s,setOpen:o,ref:a}=ka();return l.jsxs("div",{className:"rail-filter relative inline-flex",ref:a,children:[l.jsx(jt,{size:"small",className:"rail-filter-btn text-subtext",active:e!=="active",title:$E(),"aria-label":$E(),onClick:()=>o(i=>!i),children:l.jsx(tB,{size:15,className:"text-subtext"})}),s&&l.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:[l.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:ehn()}),["projects","list"].map(i=>l.jsxs(pr,{size:"compact",className:"text-sm",onClick:()=>{n(i),o(!1)},children:[l.jsx("span",{children:i==="projects"?zS():uhn()}),t===i&&l.jsx(so,{size:13})]},i)),l.jsx("div",{className:"my-1 border-t border-border"}),l.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:Udn()}),Los.map(i=>l.jsxs(pr,{size:"compact",className:"text-sm",onClick:()=>{r(i.id),o(!1)},children:[l.jsx("span",{children:i.label()}),e===i.id&&l.jsx(so,{size:13})]},i.id))]})]})}const Ios=14,Pos=500,Bos=1200;function bG({title:e,animate:r}){return r?l.jsx("span",{className:"title-reveal","aria-label":e,children:Array.from(e).map((t,n)=>t===" "?l.jsx("span",{"aria-hidden":!0,children:t},n):l.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*Ios,Pos)}ms`},children:t},n))}):l.jsx(l.Fragment,{children:e})}function Fos({session:e,active:r,unread:t,busy:n,waiting:s,experimentRunning:o,revealTitle:a,onOpen:i,onRename:c,onSetArchived:_,onDelete:d}){var N;const{open:f,setOpen:p,ref:m}=ka(),w=((N=e.title)==null?void 0:N.trim())||"Untitled",[y,v]=A.useState(!1),[x,k]=A.useState(""),b=A.useRef(null);function S(){var T;k(((T=e.title)==null?void 0:T.trim())||""),v(!0)}function z(){var C;const T=x.trim();v(!1),T&&T!==(((C=e.title)==null?void 0:C.trim())||"")&&c(T)}return A.useEffect(()=>{var T,C;y&&((T=b.current)==null||T.focus(),(C=b.current)==null||C.select())},[y]),l.jsxs("div",{ref:m,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":""} ${f?"menu-open":""} ${y?"editing":""}`,title:`${Pf(e.harness,e.harnessName)}${e.model?` · ${e.model}`:""}`,onClick:()=>{y||(f?p(!1):i())},onKeyDown:T=>{T.target===T.currentTarget&&(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),f?p(!1):i())},children:[y?l.jsx("input",{ref:b,className:"session-title-input","aria-label":Tqe(),value:x,onChange:T=>k(T.target.value),onClick:T=>T.stopPropagation(),onBlur:z,onKeyDown:T=>{T.stopPropagation(),T.key==="Enter"?(T.preventDefault(),z()):T.key==="Escape"&&(T.preventDefault(),v(!1))}}):l.jsx("span",{className:"session-title",children:l.jsx(bG,{title:w,animate:a!==void 0},a??"static")}),o&&!y&&l.jsx(va,{content:j3(),className:"shrink-0 text-accent-green",children:l.jsx(M_,{size:14,className:"motion-safe:animate-[or-experiment-pulse_3s_ease-in-out_infinite]","aria-label":j3()})}),s&&!y&&l.jsx(va,{content:kD(),className:"shrink-0 text-accent-amber",children:l.jsx(qP,{size:14,"aria-hidden":"true"})}),l.jsx("span",{className:"session-dot",children:n&&!s?l.jsx("span",{className:"busy-dot"}):t&&!s&&l.jsx("span",{className:"unread-dot"})}),l.jsx("button",{className:"session-menu-btn",title:GE(),"aria-label":GE(),onClick:T=>{T.stopPropagation(),p(C=>!C)},children:l.jsx(L0,{size:14})}),f&&l.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:[l.jsx(pr,{onClick:T=>{T.stopPropagation(),p(!1),S()},children:l.jsx("span",{children:xD()})}),l.jsx(pr,{onClick:T=>{T.stopPropagation(),p(!1),_(!e.archived)},children:l.jsx("span",{children:e.archived?aJe():N6e()})}),l.jsx(pr,{danger:!0,onClick:T=>{T.stopPropagation(),p(!1),d()},children:l.jsx("span",{children:bD()})})]})]})}const dO=[HP,eB,O_,M_],Hos=()=>[{title:mUe(),prompt:aUe()},{title:LUe(),prompt:CUe()},{title:rGe(),prompt:WUe()},{title:wGe(),prompt:fGe()}],N4=[{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"}],hO="mt-7 grid w-full max-w-readable grid-cols-1 gap-3 sm:grid-cols-2";function qos(e,r){if(!e)return null;const t=e.model??null;return{...e,model:t,serviceTier:Gb(r,t,e.serviceTier),reasoningLevel:eP(r,t,e.reasoningLevel)}}function pO({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:w,experimentName:y,onOpenPlan:v,onOpenSubagent:x,runtime:k,composerFocusNonce:b=0,activeSessionId:S,onActiveSessionChange:z,preferredAgent:N,onPreferredAgentChange:T,preferredAutonomy:C,onPreferredAutonomyChange:R,embedded:$=!1,sideParentSessionId:L,onOpenSideChat:I,onRunSetup:P,children:B}){var Yp,zl,Ec,Qd,Ou,Xd,Nc,yi;const U=vr({mutationFn:X=>EOn(...X)}),G=vr({mutationFn:X=>SOn(...X)}),J=vr({mutationFn:X=>zOn(...X)}),te=vr({mutationFn:X=>COn(...X)}),F=vr({mutationFn:X=>gOn(...X)}),D=vr({mutationFn:rP}),q=vr({mutationFn:X=>yOn(...X)}),Q=vr({mutationFn:X=>kOn(...X)}),W=vr({mutationFn:X=>jOn(...X)}),ae=vr({mutationFn:wOn}),le=N0(),{data:ie=[]}=rt({...A_(),enabled:!$}),{data:ee=[]}=rt({...bA(),enabled:!$}),[K,ne]=A.useState(()=>{try{return localStorage.getItem("sidebar-grouping")==="list"?"list":"projects"}catch{return"projects"}}),[ce,me]=A.useState(()=>{try{const X=JSON.parse(localStorage.getItem("sidebar-pinned-projects")??"[]");return Array.isArray(X)?X.filter(ue=>typeof ue=="string"):[]}catch{return[]}}),[ye,Ce]=A.useState(()=>{try{const X=JSON.parse(localStorage.getItem("sidebar-collapsed-projects")??"[]");return Array.isArray(X)?X.filter(ue=>typeof ue=="string"):[]}catch{return[]}}),[Fe,Ve]=A.useState("active"),[Me,He]=A.useState(!1),pt=A.useRef(null),[$t,Xt]=A.useState(0),[sr,Dt]=A.useState(null),[vt,ht]=A.useState({});A.useLayoutEffect(()=>{const X=pt.current;if(!X||$)return;const ue=()=>Xt(X.clientHeight),xe=new ResizeObserver(ue);return xe.observe(X),ue(),()=>xe.disconnect()},[a,$,_]);const St=new Map(ee.map(X=>[X.projectId,X.lastActivityAt])),ze=[...ie].sort((X,ue)=>Number(ce.includes(ue.id))-Number(ce.includes(X.id))||Math.max(St.get(ue.id)??0,ue.updatedAt)-Math.max(St.get(X.id)??0,X.updatedAt)),Pe=K==="list"||Me?ze.length:Math.max(1,Math.ceil($t/36));let ke=ze.slice(0,Pe);const Ye=ie.find(X=>X.id===e);Ye&&!ke.some(X=>X.id===e)&&(ke=[...ke.slice(0,Pe-1),Ye]);const it=hL({queries:(K==="projects"?ke:[]).map(X=>({...uo(X.id),enabled:!$}))}),ft=TQ({queryKey:xt("listSidebarChatSessions",Fe),queryFn:({pageParam:X,signal:ue})=>z$n(Fe,X,ue),initialPageParam:null,getNextPageParam:X=>X.next??void 0,enabled:!$&&K==="list"}),Ze=A.useMemo(()=>uo(e),[e]),{data:ir=cO}=rt(Ze),De=A.useCallback(X=>{ms(Ze.queryKey,ue=>{if(!ue)return;const xe=typeof X=="function"?X(ue):X,be=new Map(ue.map(Te=>[Te.id,Te]));for(const Te of xe)be.get(Te.id)!==Te&&Ci(Qe,Ze.queryKey,Te.id),be.delete(Te.id);for(const Te of be.keys())Ci(Qe,Ze.queryKey,Te);return xe})},[Ze]),Ie=S,dt=A.useRef(z);dt.current=z;const Et=A.useRef({projectId:e});Et.current.projectId!==e&&(Et.current={projectId:e});const[Vt,Kr]=A.useState(new Set),[qt,Wt]=A.useState(""),[Tt,hn]=A.useState(!1),[fr,kr]=A.useState([]),Rt=A.useRef(0),Bt=A.useRef({projectId:e,activeId:Ie,mainView:_});(Bt.current.projectId!==e||Bt.current.activeId!==Ie||Bt.current.mainView!==_)&&(Bt.current={projectId:e,activeId:Ie,mainView:_});const[Ur,Yt]=A.useState(null),Tn=Ur===Bt.current,[mr,Mr]=A.useState([]),[Lr,os]=A.useState(null),[xn,pn]=A.useState(null),En=Ie??`${e}:new`,Zr=A.useRef(new Map),Br=A.useRef(Uk);Br.current={draft:qt,attachments:mr,annotations:fr};const Nt=e===Dm&&!$&&ir.length>0&&ir.every(X=>X.sideParentSessionId||ZTn[X.id]===X.activeLeafId)?aA:null,Jt=A.useRef(null);Nt!==null&&Jt.current===null&&Ie!==null&&(Jt.current=En);const sn=En===Jt.current?Nt:null;A.useLayoutEffect(()=>{const X=Zr.current.get(En)??Uk;return Br.current=X,Wt(X.draft),Mr(X.attachments),kr(X.annotations),pn(null),()=>{const ue=XXn(Br.current,sn);ue?Zr.current.set(En,ue):Zr.current.delete(En)}},[En,sn]);const[Ln,lr]=A.useState(null),Sa=A.useRef(Promise.resolve()),ks=A.useRef(0),js=A.useRef(0),[Ge,gt]=A.useState(null),Cr=A.useRef(null),Fr=A.useRef(!1),or=A.useRef(null),{data:wn=[]}=rt(gA()),[jr,br,Mo]=M$n(e,_==="chat"?Ie:null),{data:Ca=Wos}=rt(tl()),[Di,Ss]=A.useState(N);A.useEffect(()=>Ss(N),[N]);const[ho,as]=A.useState({}),[za,is]=A.useState(null);A.useEffect(()=>is(null),[L]);const[Nn,Ds]=A.useState(Vm),[Ii,Ea]=A.useState(null),Na=A.useRef(!1),Aa=A.useRef(null),[Pi,gs]=A.useState(null),ea=A.useRef(!1),Is=A.useRef(null),[Bi,Qn]=A.useState(new Map),Cs=A.useRef(new Map),vc=A.useRef(null),ta=A.useRef(null),Oo=A.useRef(null),ra=A.useRef(!0),[Q_,fl]=A.useState(!0),Dn=A.useRef(null),[X_,$o]=A.useState(!1),po=ka(),bc=A.useCallback(X=>{var ue;Rt.current+=1,kr(xe=>[...xe,{id:`annotation-${Rt.current}`,...X}]),(ue=Dn.current)==null||ue.focus()},[]),Lo=Uss(ta,bc);Gss(fr,$?$ss:Oss),A.useEffect(()=>{$o(!1),Lo.dismiss()},[Ie,e,Lo.dismiss]);const[li,cs]=A.useState(0),[yc,Do]=A.useState(0),[Ta,An]=A.useState(!1),[na,ls]=A.useState(0),[Xn,on]=A.useState(0),Rn=A.useRef(!1);function ui(X){if(!Qs)return;if(X.source==="command"&&Jx(X.name)){In(X.name,qt,Qs);return}const ue=X.name.replace(/@u$/,"^").replace(/@p$/,"~"),xe=X.source==="command"?1:eO(ue,Dn.current),be=rss(qt,Qs,ue,xe);Wt(be.text),window.requestAnimationFrame(()=>{var Te,kt;(Te=Dn.current)==null||Te.focus(),(kt=Dn.current)==null||kt.setSelectionRange(be.cursor,be.cursor),on(be.cursor)})}function ku(X){if(!Fi)return;const ue=TXn(qt,Fi,X);Wt(ue.text),window.requestAnimationFrame(()=>{var xe,be;(xe=Dn.current)==null||xe.focus(),(be=Dn.current)==null||be.setSelectionRange(ue.cursor,ue.cursor),on(ue.cursor)})}function ju(X){if(Oa)return!1;const ue=X.selectionStart;if(Rn.current||ue!==X.selectionEnd)return!1;const xe=qt.slice(0,ue).replace(/[ \t]+$/,"").length,be=b4(qt,xe);if(!be||be.end!==xe||!Vi(be.query)||ue>xe&&ue-xe!==eO(be.query,X))return!1;const Te=JM(qt,{...be,end:ue});return Wt(Te.text),on(Te.cursor),window.requestAnimationFrame(()=>X.setSelectionRange(Te.cursor,Te.cursor)),!0}function _i(X){os(null),pn(null);let be=mr.reduce((Te,kt)=>Te+kt.size,0);for(const Te of X){if(!/^(image\/(png|jpeg|gif|webp)|application\/pdf)$/.test(Te.type))continue;if(dl&&Te.type.startsWith("image/")){pn((bo==null?void 0:bo.id)??null);continue}if(Te.size>31457280){os(pCe({name:Ae(Te.name)}));continue}if(be+Te.size>41943040){os(SCe());continue}be+=Te.size;const kt=Bt.current,lt=En,Gt=new FileReader;Gt.onload=()=>{const Nr={dataUrl:Gt.result,mediaType:Te.type,name:Te.name,size:Te.size};if(Bt.current.projectId===kt.projectId&&Bt.current.activeId===kt.activeId){Mr(ko=>[...ko,Nr]);return}const Vr=Zr.current.get(lt)??Uk;Zr.current.set(lt,{...Vr,attachments:[...Vr.attachments,Nr]})},Gt.readAsDataURL(Te)}}function Dd(X){const ue=Array.from(X.clipboardData.items).filter(xe=>xe.kind==="file"&&(xe.type.startsWith("image/")||xe.type==="application/pdf")).map(xe=>xe.getAsFile()).filter(xe=>xe!==null);ue.length>0&&(X.preventDefault(),_i(ue))}const at=ir.find(X=>X.id===Ie),Ps=Di??RB(Ca),mo=at?{harness:at.harness,model:ho.model!==void 0?ho.model:at.model,serviceTier:ho.serviceTier!==void 0?ho.serviceTier:at.serviceTier,permissionMode:ho.permissionMode??at.permissionMode,reasoningLevel:ho.reasoningLevel??at.reasoningLevel}:Ps?{...Ps,...ho}:null,{data:fi=Gos}=rt(o$n(mo==null?void 0:mo.harness,e)),Id=mo?Ca.find(X=>X.id===mo.harness):void 0,Je=qBn(at,Id),Ra=zB(at==null?void 0:at.nativeConfiguration,{model:Ph(),mode:N3()}),Ma=Ra.find(X=>X.category==="model"),Vs=Ra.find(X=>X.category==="mode"&&X.choices.some(ue=>ue.id==="plan")),Io=Je==null?void 0:Je.options,go=Vs?"command":Io==null?void 0:Io.planActivation,{data:Y_}=rt({...IS(),enabled:!!P}),Z_=X=>{if(!Je)return;const ue=Y_==null?void 0:Y_[Je.id];if(!(Je.id==="claude-code"&&X===(ue==null?void 0:ue.login)&&!Je.loginEligible))return PU(Je,ue,X)},di=A.useMemo(()=>nss(fi,go),[fi,go]),J_=nO(qt),vo=J_!==null,Qs=b4(qt,Xn),Su=(Qs==null?void 0:Qs.query)??null,zr=Su===null?[]:di.filter(X=>ess(X,Su)),Oa=!vo&&Su!==null&&(Qs==null?void 0:Qs.end)===Xn&&zr.length>0,sa=Oa&&!Ta?zr:[],Pd=sa.length>0,ef=Math.min(li,Math.max(0,sa.length-1));A.useEffect(()=>cs(0),[Su]);const Fi=vo?null:zXn(qt,Xn),$a=(Fi==null?void 0:Fi.end)===Xn?Fi.query:null,tf=(Yp=rt({...F6(e,Ie?{sessionId:Ie}:{}),enabled:$a!==null}).data)==null?void 0:Yp.entries,rf=A.useMemo(()=>NXn(tf??[]),[tf]),hi=A.useMemo(()=>$a!==null&&!Ta?AXn(rf,$a):[],[rf,$a,Ta]),nf=hi.length>0,Xs=Math.min(yc,Math.max(0,hi.length-1));A.useEffect(()=>Do(0),[$a]);const cr=qos(Ma&&mo?{...mo,model:Ma.currentValue}:mo,Je),Cu=Zy(Je,cr==null?void 0:cr.model),bo=Je==null?void 0:Je.models.find(X=>X.id===(cr==null?void 0:cr.model)),dl=(bo==null?void 0:bo.imageInput)===!1?TEe({model:Ae(rb(bo))}):null,Fd=!!dl&&mr.some(X=>X.mediaType.startsWith("image/")),hl=!!bo&&xn===bo.id,sf=Fd||hl?dl:null;A.useEffect(()=>pn(null),[bo==null?void 0:bo.id]);const pl=X=>{if(at!=null&&at.harness.startsWith("acp:")&&Ma&&X.model){fk(at.id,Ma.id,X.model).catch(be=>Qt(be instanceof Error?be.message:String(be),"error"));return}if(!cr)return;const ue={...cr,...X},xe={};X.model!==void 0&&X.model!==cr.model&&(xe.model=X.model),X.serviceTier!==void 0&&X.serviceTier!==cr.serviceTier&&(xe.serviceTier=X.serviceTier),X.permissionMode!==void 0&&X.permissionMode!==cr.permissionMode&&(xe.permissionMode=X.permissionMode),X.reasoningLevel!==void 0&&X.reasoningLevel!==cr.reasoningLevel&&(xe.reasoningLevel=X.reasoningLevel),Ds(be=>({...be,...xe})),Ss(ue),T(ue).catch(()=>{}),at?as(be=>({...be,...X})):X.harness&&X.harness!==cr.harness&&as({})},Yn=A.useCallback(X=>{const ue=Sa.current.catch(()=>{}).then(()=>{if(!Ir(Ze.queryKey))throw new DOMException("Workspace changed","AbortError");return X()});return Sa.current=ue.then(()=>{},()=>{}),ue},[Ze]),ml=X=>{if(X==="plan"&&(Je==null?void 0:Je.id)==="claude-code"?(Ds(be=>({...be,permissionMode:X})),as(be=>({...be,permissionMode:X}))):(as(be=>{const Te={...be};return delete Te.permissionMode,Te}),pl({permissionMode:X})),!at)return;const ue=at.id,xe=++ks.current;lr(null),Yn(()=>U.mutateAsync([ue,X])).then(be=>{De(Te=>Te.map(kt=>kt.id===be.id?be:kt)),ks.current===xe&&as(Te=>{const kt={...Te};return delete kt.permissionMode,kt})}).catch(()=>{ks.current===xe&&(as(be=>{const Te={...be};return delete Te.permissionMode,Te}),lr($Je()))})},xc=X=>pl({reasoningLevel:X}),Hd=X=>{if(!at){L?is(X):R(X);return}const ue=at.id,xe=at.autonomy,be=++ks.current,Te=kt=>De(lt=>lt.map(Gt=>Gt.id===kt.id?kt:Gt));Te({...at,autonomy:X}),lr(null),Yn(()=>J.mutateAsync([ue,X])).then(kt=>{Te(kt),R(kt.autonomy)}).catch(()=>{De(kt=>kt.map(lt=>lt.id===ue&<.autonomy===X?{...lt,autonomy:xe}:lt)),ks.current===be&&lr(SJe())})},Hi=((zl=at==null?void 0:at.goal)==null?void 0:zl.trim())||"",wc=Vs?Vs.currentValue==="plan":(cr==null?void 0:cr.harness)==="claude-code"?cr.permissionMode==="plan":go==="command"?Ge??(at==null?void 0:at.planMode)??!1:!1;A.useEffect(()=>{Ge===null||(at==null?void 0:at.planMode)!==Ge||(Cr.current=null,gt(null))},[at==null?void 0:at.planMode,Ge]);async function qi(X){var be;if(Vs&&at){const Te=X?"plan":(be=Vs.choices.find(kt=>kt.id!=="plan"))==null?void 0:be.id;if(!Te)throw new Error(ev());await Yn(()=>fk(at.id,Vs.id,Te));return}if(Ds(Te=>({...Te,planMode:X})),Cr.current=X,gt(X),!at)return;const ue=at.id,xe=++js.current;lr(null);try{const Te=await Yn(()=>G.mutateAsync([ue,X]));De(kt=>kt.map(lt=>lt.id===Te.id?Te:lt)),js.current===xe&&(Cr.current=null,gt(null),lr(null))}catch(Te){throw js.current===xe&&(Cr.current=null,gt(null)),Te}}async function pi(){if((cr==null?void 0:cr.harness)==="claude-code"){ml("auto");return}if(at)try{await qi(!1)}catch{lr(Sze())}}async function Wp(){const X=!wc;try{if((cr==null?void 0:cr.harness)==="claude-code")ml(X?"plan":"auto");else if(go==="command")await qi(X);else throw new Error(J1())}catch{lr(ev())}}function Ui(X,ue=""){var xe;switch(X){case"plan":return Wp(),!1;case"new":if($){const be=(at==null?void 0:at.sideParentSessionId)??L;be&&(I==null||I(be,""))}else bs();return!1;case"resume":return $o(!0),!0;case"model":return ls(be=>be+1),!0;case"compact":return Gi(),!1;case"goal":return Yt(Bt.current),!1;case"side":return zu(ue),!1;case"copy":{const be=Pn.at(-1),Te=Gr&&(be==null?void 0:be.role)==="assistant"&&!be.completedAt,kt=UXn(Te?Pn.slice(0,-1):Pn);return kt?KC(kt):Qt(DNe(),"info"),!1}case"export":{const be=((xe=at==null?void 0:at.title)==null?void 0:xe.trim())||eb(),Te=at?GXn(be,Pn,{user:B8e(),assistant:Pf(at.harness,at.harnessName)}):null;return Te?wos(WXn(be),Te):Qt(KNe(),"info"),!1}}}function zu(X){$?Qt(yfn(),"info"):!at||!I?Qt(ufn(),"info"):I(at.id,X)}async function gl(X){lr(null);const ue=Et.current;try{const xe=await F.mutateAsync([e,X]);if(Qe.invalidateQueries({queryKey:_P().queryKey}),Et.current!==ue)return;De(be=>[xe,...be.filter(Te=>Te.id!==xe.id)]),Ve("all"),z(xe.id,{projectId:xe.projectId})}catch(xe){if(Et.current!==ue)return;lr(tEe({error:Ae(xe instanceof Error?xe.message:String(xe))}))}}async function of(X){var lt;const ue=X.trim();if(!ue){const Gt=(lt=at==null?void 0:at.goal)==null?void 0:lt.trim();Qt(Gt?a9e({goal:tu(Gt)}):S9e(),"info");return}const xe=Bt.current,be=()=>Bt.current.activeId===xe.activeId;lr(null);let Te=Ie;if(!Te){if(!(Je!=null&&Je.agentReady)||!cr){lr(J1());return}try{Te=(await Ia(cr,x4(go,void 0,Cr.current))).id}catch(Gt){lr(kE({error:Ae(Gt instanceof Error?Gt.message:String(Gt))}));return}}const kt=/^(clear|none|off)$/i.test(ue);try{const Gt=await Yn(()=>te.mutateAsync([Te,kt?null:ue]));De(Nr=>Nr.map(Vr=>Vr.id===Gt.id?Gt:Vr)),Qt(kt?X8e():$9e(),"success")}catch(Gt){if(!be())return;lr(kE({error:Ae(Gt instanceof Error?Gt.message:String(Gt))}))}}async function Gi(){const X=Ie;if(!X){Qt(zNe(),"info");return}if(Gr){lr(y7e());return}lr(null),Fe==="archived"&&Ve("active");const ue=Bt.current;try{const{message:xe}=await MOn(X);br({type:"upsertMessage",sessionId:X,message:xe})}catch(xe){if(Bt.current.activeId!==ue.activeId)return;lr(A7e({error:Ae(xe instanceof Error?xe.message:String(xe))}))}}function In(X,ue,xe){const be=JM(ue,xe);Wt(be.text),An(!0),!Ui(X)&&window.requestAnimationFrame(()=>{var Te,kt,lt;((Te=Dn.current)==null?void 0:Te.value)===be.text&&((kt=Dn.current)==null||kt.focus(),(lt=Dn.current)==null||lt.setSelectionRange(be.cursor,be.cursor),on(be.cursor))})}const Wi=A.useCallback(async(X=!1)=>{const ue=Et.current;if(ue.projectId!==e||!Ir(Ze.queryKey))return null;const xe=(Qe.getQueryData(Ze.queryKey)??[]).map(be=>be.id);try{const be=await Qe.fetchQuery({...Ze,...X?{staleTime:0}:{}});if(Et.current!==ue||!Ir(Ze.queryKey))return null;const Te=be.filter(lt=>!Ai.has(lt.id)),kt=new Set(Te.map(lt=>lt.id));for(const lt of xe)kt.has(lt)||ct(lt);return Cs.current=new Map(Te.map(lt=>[lt.id,lt.title])),Te}catch{return null}},[e]),La=A.useCallback(async X=>{Et.current.projectId!==e||!Ir(Ze.queryKey)||await Promise.all([Qe.fetchQuery({...Zc(X),staleTime:0}),Wi(!0)]).catch(()=>{})},[e,Wi]);A.useEffect(()=>{const X=mB();Kr(e===Dm?new Set([MS,OS].filter(xe=>!X.has(xe))):new Set),hn(!1),Qn(new Map),Cs.current=new Map,Wi();const ue=Et.current;return()=>{Et.current===ue&&(Et.current={projectId:e})}},[e,Wi]),A.useEffect(()=>{Ds(Vm),Is.current=null},[Ie]),A.useEffect(()=>Og(X=>{switch(X.type){case"session":{if(X.session.projectId!==e||Ai.has(X.session.id))return;const ue=Cs.current.has(X.session.id),xe=Cs.current.get(X.session.id)!==X.session.title;Cs.current.set(X.session.id,X.session.title),ue&&xe&&X.session.titleSource==="generated"&&(Qn(be=>{const Te=new Map(be);return Te.set(X.session.id,(be.get(X.session.id)??0)+1),Te}),window.setTimeout(()=>{Qn(be=>{if(!be.has(X.session.id))return be;const Te=new Map(be);return Te.delete(X.session.id),Te})},Bos));break}case"sessionDeleted":ct(X.sessionId);break}}),[e]),A.useEffect(()=>Og(X=>{X.type==="reconnected"&&Wi(!0),(X.type==="runsChanged"||X.type==="reconnected")&&Qe.invalidateQueries({queryKey:gA().queryKey})}),[Wi]);const vl=Ie?jr.messagesBySession[Ie]??iO:iO,Eu=Ie?jr.activeLeafBySession[Ie]??null:null;Aa.current=Eu;const Pn=A.useMemo(()=>AR(vl,Eu),[vl,Eu]),Nu=A.useRef({projectId:e,ids:jr.busySessions});A.useEffect(()=>{const X=Nu.current;Nu.current={projectId:e,ids:jr.busySessions},X.projectId===e&&Kr(ue=>FXn(ue,X.ids,jr.busySessions,ir,_==="chat"?Ie:null))},[e,jr.busySessions,ir,Ie,_]);const Gr=Ie?jr.busySessions.has(Ie):!1,bl=!Gr&&!!(Je!=null&&Je.agentReady),Au=Gr&&BH(Pn)!=null,Kp=Gr&&BXn(Pn),Da=Ie?jr.queuedBySession[Ie]??[]:[],af=Da.some(X=>X.dispatchState==="retrying"),cf=Da.findIndex(X=>X.dispatchState==="blocked"),yl=Da.reduce((X,ue)=>ue.dispatchState!=="retrying"||typeof ue.nextRetryAt!="number"?X:X===null?ue.nextRetryAt:Math.min(X,ue.nextRetryAt),null),[ao,Ki]=A.useState(()=>Date.now());A.useEffect(()=>{if(!af||yl===null||(Ki(Date.now()),yl<=Date.now()))return;const X=window.setInterval(()=>{const ue=Date.now();Ki(ue),ue>=yl&&window.clearInterval(X)},1e3);return()=>window.clearInterval(X)},[af,yl]),A.useEffect(()=>{const X=Da.reduce((ue,xe)=>xe.planMode??ue,void 0);X!==void 0?(Fr.current=!0,Cr.current=X,gt(X)):Fr.current&&(Fr.current=!1,Cr.current=null,gt(null))},[Da]);const mi=!!Ie&&Mo.isPending,qd=A.useMemo(()=>{const X=new Set;for(const[ue,xe]of Object.entries(jr.messagesBySession)){const be=jr.busySessions.has(ue);LXn(AR(xe,jr.activeLeafBySession[ue]),be)&&X.add(ue)}return X},[jr.busySessions,jr.messagesBySession,jr.activeLeafBySession]),xl=Gr&&Pn.some(X=>X.parts.some(ue=>ue.type==="prompt"&&ue.prompt&&!ue.prompt.resolved&&ue.prompt.nativeId)),Bs=A.useMemo(()=>Pn.flatMap(X=>X.parts.filter(ue=>{var xe;return ue.type==="prompt"&&((xe=ue.prompt)==null?void 0:xe.kind)==="question"&&!ue.prompt.resolved&&(!ue.prompt.nativeId||Gr)})),[Pn,Gr]),er=at,Tu=er?Bi.get(er.id):void 0,us=A.useMemo(()=>{var X;for(let ue=Pn.length-1;ue>=0;ue--)for(const xe of Pn[ue].parts)if(xe.type==="prompt"&&((X=xe.prompt)==null?void 0:X.kind)==="plan"&&!xe.prompt.resolved)return{promptId:xe.id,plan:xe.prompt.plan??"",synthesized:!!xe.prompt.synthesized};return null},[Pn]),Vi=X=>{if(vo)return!1;const ue=gj(X),xe=di.find(be=>be.name===HC(ue??X));return!xe||xe.source!=="command"?!!xe:ue&&y4(ue)?ue==="plan"||qt.trim().toLowerCase().startsWith(`/${X}`):qt.trim().toLowerCase()===`/${X}`},wl=A.useMemo(()=>di.filter(X=>X.source!=="command"),[di]),[kn,gi]=A.useState(null),yo=kn&&kn.sessionId===Ie?kn:null;A.useEffect(()=>{if(!kn)return;const X=jr.busySessions.has(kn.sessionId),ue=kn.sessionId===Ie&&us&&us.promptId!==kn.promptId;(!X||ue)&&gi(null)},[kn,us,jr.busySessions,Ie]);const Qi=A.useMemo(()=>VC(Pn),[Pn]),kc=Gr&&!!(Je!=null&&Je.supportsSteering)&&!!(Je!=null&&Je.agentReady)&&!us&&!xl&&!Qi&&mr.length===0&&fr.length===0,vi=A.useMemo(()=>v&&Ie?(X,ue,xe)=>v(X,Ie,ue,xe):void 0,[v,Ie]),Zn=A.useMemo(()=>x&&Ie?(X,ue,xe)=>x(Ie,X,ue,xe):void 0,[x,Ie]),Bn=A.useMemo(()=>f&&((X,ue,xe,be,Te)=>f(X,Ie??void 0,ue,xe,be,Te)),[f,Ie]);A.useEffect(()=>{ks.current+=1,js.current+=1;const X=(Ie?jr.queuedBySession[Ie]??[]:[]).reduce((ue,xe)=>xe.planMode??ue,void 0);Fr.current=X!==void 0,Cr.current=X??null,gt(X??null),as({}),lr(null)},[Ie]);const jc=_==="chat"&&(Pn.length>0||Gr),Wr=(cr==null?void 0:cr.harness)??null,Vp=(cr==null?void 0:cr.model)??null,kl=Mo.data?null:Mo.error,Ys=_==="chat"&&!$&&!jc&&!t&&!n&&!mi&&!kl,jl=rt({...$$n(e,Wr??"claude-code",Vp,E()),enabled:Ys&&Wr!==null,subscribed:Ys&&Wr!==null}),Ru=(Ec=jl.data)!=null&&Ec.blank?Hos():((Qd=jl.data)==null?void 0:Qd.prompts)??null,lf=Wr!==null&&jl.isPending,vs=e===Dm?"demo":"project",Sl=X=>{Wt(X),An(!1),window.requestAnimationFrame(()=>{const ue=Dn.current;ue&&(ue.focus(),ue.setSelectionRange(X.length,X.length),on(X.length))})};A.useEffect(()=>{sn&&(Wt(X=>X||sn),An(!1),on(sn.length))},[sn]),A.useEffect(()=>{if(b===0)return;const X=window.requestAnimationFrame(()=>{const ue=Dn.current;ue&&(ue.focus(),ue.setSelectionRange(ue.value.length,ue.value.length),ue.scrollIntoView({block:"nearest"}))});return()=>window.cancelAnimationFrame(X)},[b]);const Jn=A.useId(),Po=e===Dm&&qt===aA&&!Tt,uf=A.useCallback(X=>{const ue=X.scrollHeight-X.scrollTop-X.clientHeight<60;ra.current=ue,fl(ue)},[]),xo=A.useCallback(()=>{var X;ra.current=!0,fl(!0),(X=Oo.current)==null||X.call(Oo)},[]);A.useEffect(()=>{const X=vc.current,ue=ta.current;if(!X||!ue)return;const xe=new ResizeObserver(()=>{var be;ra.current?(be=Oo.current)==null||be.call(Oo):fl(X.scrollHeight-X.scrollTop-X.clientHeight<60)});return xe.observe(X),xe.observe(ue),()=>xe.disconnect()},[jc]);const Mu=A.useCallback(X=>{X.currentTarget.blur(),xo()},[xo]);async function Cl({queue:X=!1,starter:ue}={}){var rm,Al,Yd,hf,pf,nm;const xe=(ue??qt).trim(),be=ue===void 0?sss(xe,go):null,Te=(be==null?void 0:be.name)==="goal";if(Te&&!be.prompt){Wt(""),An(!1),Yt(Bt.current);return}if((Te||Tn)&&/^(clear|none|off)$/i.test(Te?be.prompt:xe)){Wt(""),Yt(null),await of("clear");return}if(be&&be.name!=="plan"&&!Te){Wt(y4(be.name)?"":be.prompt),An(!1),Ui(be.name,be.prompt);return}if(Fd||(ue===void 0&&l_({name:"first_action",surface:vs,action:"typed_prompt"}),ea.current))return;const kt=(be==null?void 0:be.name)==="plan",lt=Te||Tn,Gt=!wc,Nr=x4(Vs?void 0:go,kt?Gt:void 0,Cr.current),Vr=kt&&(Je==null?void 0:Je.id)==="claude-code"?Gt?"plan":"auto":void 0,ko=be?be.prompt:xe,Zi=mr,El=fr,Fn=El.map(Qr=>({text:Qr.text})),Zp=e,ff=_;let $u=Ie;const oa=()=>{const Qr=Bt.current;return Ir(Ze.queryKey)&&Qr.projectId===Zp&&Qr.activeId===$u&&Qr.mainView===ff},Ac=()=>{oa()&&(Wt(Qr=>Qr||xe),lt&&Yt(Bt.current),Mr(Qr=>Qr.length?Qr:Zi),kr(Qr=>Qr.length?Qr:El))};if(kt&&!ko&&Zi.length===0&&El.length===0){Wt(""),An(!1);try{if((Je==null?void 0:Je.id)==="claude-code")ml(Gt?"plan":"auto");else if(go==="command")await qi(Gt);else throw new Error(J1())}catch{lr(ev()),Ac()}return}if(kt&&Vs)try{await qi(Gt)}catch{oa()&&lr(ev());return}const Hn=cr?{...cr,...Vr?{permissionMode:Vr}:{}}:null;Vr&&ml(Vr);let Jp=null;const em=Cr.current;kt&&!Vs&&go==="command"&&(Jp=++js.current,Cr.current=Gt,gt(Gt));const df=()=>{!oa()||Jp===null||js.current!==Jp||(Cr.current=em,gt(em))};if(!ko&&Zi.length===0&&El.length===0||lt&&!ko)return;const tm=async Qr=>{if(!lt)return;const eo=await te.mutateAsync([Qr,ko]);De(to=>to.map(es=>es.id===eo.id?eo:es))},Tc=JSON.stringify({text:ko,goal:lt?ko:void 0,images:Zi.map(Qr=>({mediaType:Qr.mediaType,name:Qr.name,dataUrl:Qr.dataUrl})),annotations:Fn,settings:Hn?{model:Hn.model,serviceTier:Hn.serviceTier,permissionMode:Hn.permissionMode,planMode:Nr,reasoningLevel:Hn.reasoningLevel}:null}),Nl=((rm=Is.current)==null?void 0:rm.signature)===Tc?Is.current.id:`ct_${crypto.randomUUID()}`;if(Is.current={signature:Tc,id:Nl},Gr){if(!Ie||!(Je!=null&&Je.agentReady)){df();return}const Qr=Ie;Wt(""),Mr([]),kr([]),os(null),pn(null);const eo=Hn?{model:Hn.model,serviceTier:Hn.serviceTier,permissionMode:Hn.permissionMode,planMode:go==="command"?Nr??(at==null?void 0:at.planMode):Nr,reasoningLevel:Hn.reasoningLevel}:{};oa()&&as({});const to=Zi.map(es=>({mediaType:es.mediaType,dataBase64:es.dataUrl.slice(es.dataUrl.indexOf(",")+1),name:es.name}));try{(Al=(await Yn(async()=>(await tm(Qr),U3(Qr,ko,eo,to.length?to:void 0,Fn,Nl,kc&&!X&&!kt&&!lt?"steer":void 0)))).turn)!=null&&Al.existing&&await La(Qr),oa()&&(Ds(Vm),lt&&Yt(null)),((Yd=Is.current)==null?void 0:Yd.id)===Nl&&(Is.current=null)}catch{df(),Ac()}return}if(!(Je!=null&&Je.agentReady)){df();return}if(!Hn){df();return}let Fo=Ie;try{Wt(ln=>ln===qt?"":ln),Mr(ln=>ln===Zi?[]:ln),kr(ln=>ln===El?[]:ln),os(null),pn(null),ea.current=!0;try{if(!Fo){const Lu=await Ia(Hn,Nr);Fo=Lu.id,$u=Lu.id}if(!Ir(Ze.queryKey))return;const ln=Zc(Fo);await Qe.fetchQuery({...ln,...((hf=Qe.getQueryState(ln.queryKey))==null?void 0:hf.fetchStatus)==="fetching"?{staleTime:0}:{}})}finally{ea.current=!1}if(!Ir(Ze.queryKey))return;br({type:"optimisticUser",sessionId:Fo,text:ko||Q6e(),attachments:Zi.map(ln=>({url:ln.dataUrl,mediaType:ln.mediaType,name:ln.name})),annotations:El}),br({type:"busy",sessionId:Fo,busy:!0}),oa()&&xo(),oa()&&Fe==="archived"&&Ve("active");const Qr=Hn?{model:Hn.model,serviceTier:Hn.serviceTier,permissionMode:Hn.permissionMode,planMode:Nr,reasoningLevel:Hn.reasoningLevel}:{};oa()&&as({});const eo=Zi.map(ln=>({mediaType:ln.mediaType,dataBase64:ln.dataUrl.slice(ln.dataUrl.indexOf(",")+1),name:ln.name})),to=Fo;if(!to)throw new Error(mYe());(pf=(await Yn(async()=>(await tm(to),U3(to,ko,Qr,eo.length?eo:void 0,Fn,Nl)))).turn)!=null&&pf.existing&&await La(to),oa()&&(Ds(Vm),lt&&Yt(null)),((nm=Is.current)==null?void 0:nm.id)===Nl&&(Is.current=null)}catch(Qr){if(!Ir(Ze.queryKey)||(Ac(),df(),!Fo))return;const eo=Qr instanceof Error?Qr.message:String(Qr);if(!/session is busy/i.test(eo)&&await Qe.fetchQuery({...uo(e),staleTime:0}).then(es=>{var mf;return!!((mf=es.find(ln=>ln.id===Fo))!=null&&mf.busy)}).catch(()=>!1)){oa()&&(Wt(es=>es===ko?"":es),Mr(es=>es===Zi?[]:es),kr(es=>es===El?[]:es));return}br({type:"busy",sessionId:Fo,busy:!1}),br({type:"localError",sessionId:Fo,text:xEe({error:Ae(eo)})})}}async function Ia(X,ue){const xe=Bt.current,be=Et.current;let Te=L?await D.mutateAsync(L):await q.mutateAsync([e,X.harness,{model:X.model,serviceTier:X.serviceTier,permissionMode:X.permissionMode,planMode:ue,reasoningLevel:X.reasoningLevel,autonomy:C}]);return L&&za!==null&&Te.autonomy!==za&&(Te=await J.mutateAsync([Te.id,za])),Ir(Ze.queryKey)&&Et.current===be&&(De(kt=>[Te,...kt.filter(lt=>lt.id!==Te.id)]),Qe.getQueryData(Ze.queryKey)||Wi(!0)),Ir(Ze.queryKey)&&Et.current===be&&Bt.current===xe&&(dt.current(Te.id,{replace:!0}),Bt.current={...xe,activeId:Te.id}),Te}function _f(){const X=Sss(qt);Wt(X),window.requestAnimationFrame(()=>{var ue,xe;(ue=Dn.current)==null||ue.focus(),(xe=Dn.current)==null||xe.setSelectionRange(X.length,X.length),on(X.length)})}async function Sc(){const X=J_;if(!X)return;if(lr(null),Gr){lr($Ce());return}const ue=qt,xe=Bt.current;let be=Ie;const Te=()=>{const Nr=Bt.current;return Nr.projectId===xe.projectId&&Nr.activeId===be&&Nr.mainView===xe.mainView},kt=()=>{Te()&&Wt(Nr=>Nr||ue)};Wt(""),An(!1);let lt=Ie;if(!lt){if(!(Je!=null&&Je.agentReady)||!cr){kt(),lr(J1());return}try{const Nr=x4(go,void 0,Cr.current);lt=(await Ia(cr,Nr)).id,be=lt,Te()&&as({})}catch(Nr){kt();const Vr=Nr instanceof Error?Nr.message:String(Nr);Te()&&lr(xE({error:Ae(Vr)}));return}}Te()&&Fe==="archived"&&Ve("active");const Gt=`${nd}shell-${Date.now()}`;br({type:"localShell",sessionId:lt,id:Gt,command:X}),Te()&&xo();try{const{message:Nr}=await OOn(lt,X);br({type:"upsertMessage",sessionId:lt,message:Nr})}catch(Nr){const Vr=Nr instanceof Error?Nr.message:String(Nr);br({type:"localShell",sessionId:lt,id:Gt,command:X,error:xE({error:Ae(Vr)})})}}function bi(){Ie&&IOn(Ie).catch(()=>{lr(rZe())})}const Ud=A.useCallback(async(X,ue)=>{if(!(!Ie||Na.current)){Na.current=!0,lr(null),Ea(X);try{const xe=QXn({model:Nn.model,serviceTier:Nn.serviceTier,permissionMode:Nn.permissionMode,planMode:Nn.planMode,reasoningLevel:Nn.reasoningLevel}),be=Ie;(await $On(be,X,ue,xe)).turn.existing&&await La(be),Ds(Vm)}catch{lr(WQe())}finally{Na.current=!1,Ea(null)}}},[Ie,Nn,La]),Z=A.useCallback((X,ue)=>{if(!Ie||Gr||!(Je!=null&&Je.agentReady))return;const xe=Ie;br({type:"busy",sessionId:xe,busy:!0}),xo(),Yn(()=>LOn(xe,X,ue)).catch(be=>{br({type:"busy",sessionId:xe,busy:!1});const Te=be instanceof Error?be.message:String(be);br({type:"localError",sessionId:xe,text:fXe({error:Ae(Te)})})})},[Ie,Gr,Je==null?void 0:Je.agentReady,xo,Yn]),fe=A.useCallback(X=>{if(!Ie||Gr)return;const ue=Ie,xe=Aa.current;br({type:"activeLeaf",sessionId:ue,leafId:X}),Yn(()=>DOn(ue,X)).catch(be=>{br({type:"activeLeaf",sessionId:ue,leafId:xe});const Te=be instanceof Error?be.message:String(be);br({type:"localError",sessionId:ue,text:fZe({error:Ae(Te)})})})},[Ie,Gr,Yn]);function we(X){if(!Ie)return;const ue=Ie;AOn(ue,X).then(({removed:xe})=>{if(xe)return La(ue)}).catch(()=>lr(rXe()))}async function $e(X){if(!Ie||Pi)return;const ue=Ie;lr(null),gs(X);try{await TOn(ue,X),await La(ue)}catch{lr(wXe())}finally{gs(null)}}const Oe=A.useRef(!1);A.useEffect(()=>{const X=ue=>{Oe.current=E4(ue.target)};return document.addEventListener("pointerdown",X,!0),()=>document.removeEventListener("pointerdown",X,!0)},[]),A.useEffect(()=>{if(!Gr||_!=="chat")return;function X(ue){var be;ue.key!=="Escape"||ue.defaultPrevented||(ue.target===document.body?Oe.current:E4(ue.target))!==$||(ue.preventDefault(),bi(),(be=Dn.current)==null||be.focus())}return document.addEventListener("keydown",X),()=>document.removeEventListener("keydown",X)},[Gr,Ie,_,$]);function ct(X){Wy(X),Zr.current.delete(X),Jt.current===X&&(Jt.current=null),Bt.current.projectId===e&&Bt.current.activeId===X&&Bt.current.mainView==="chat"&&(Wt(""),Mr([]),kr([]),dt.current(null,{replace:!0})),Kr(ue=>{if(!ue.has(X))return ue;const xe=new Set(ue);return xe.delete(X),xe}),Cs.current.delete(X)}function st(X,ue){const xe=uo(X.projectId);Ci(Qe,xe.queryKey,X.id),ms(xe.queryKey,be=>be==null?void 0:be.map(Te=>Te.id===X.id?{...Te,...ue}:Te))}function It(X,ue){const xe=X.archived;st(X,{archived:ue}),Q.mutateAsync([X.id,ue]).catch(()=>{st(X,{archived:xe})})}function Hr(X,ue){const xe=X.title;st(X,{title:ue}),W.mutateAsync([X.id,ue]).catch(()=>{st(X,{title:xe})})}async function Fs(X){var xe;const ue=((xe=X.title)==null?void 0:xe.trim())||eb();if(window.confirm(oze({title:tu(ue)}))){try{await ae.mutateAsync(X.id)}catch(be){Qt(pze({title:tu(ue),error:Ae(be instanceof Error?be.message:String(be))}),"error");return}ct(X.id)}}const an=A.useCallback(X=>{if(!Ie)return Promise.resolve(!1);const ue=Ie;return br({type:"busy",sessionId:ue,busy:!0}),Yn(()=>POn(ue,X)).then(()=>!0).catch(xe=>(Qt(xe instanceof Error?xe.message:String(xe),"error"),!1)).finally(()=>{Ir(Ze.queryKey)&&(Qe.fetchQuery({...Zc(ue),staleTime:0}).catch(()=>{}),Qe.fetchQuery({...uo(e),staleTime:0}).catch(()=>{}))})},[Ie,e,Yn,Ze]),zs=/Mac|iPhone|iPad/.test(navigator.platform),wo=zs?"⌘ ⇧ ↵":"Ctrl + Shift + ↵",Cc=zs?"⌘ Enter":"Ctrl + Enter",Pa=A.useCallback(()=>{Ve("active"),z(null)},[z]),bs=A.useCallback(async()=>{try{const ue=(await Qe.fetchQuery({...bA(),staleTime:0})).reduce((xe,be)=>!xe||be.lastActivityAt>xe.lastActivityAt?be:xe,void 0);Ve("active"),z(null,{projectId:(ue==null?void 0:ue.projectId)??e})}catch(X){Qt(X instanceof Error?X.message:String(X),"error")}},[e,z]),Zs=A.useCallback(async X=>{const ue=Et.current,xe=Bt.current;try{const be=await xOn(X);if(Et.current!==ue||Bt.current!==xe)return;Ve("all"),z(X,{projectId:be.projectId})}catch(be){if(Et.current!==ue||Bt.current!==xe)return;Qt(be instanceof Error?be.message:String(be),"error")}},[z]);A.useEffect(()=>{if($)return;const X=ue=>{ue.repeat||ue.key!=="Enter"||!ue.metaKey&&!ue.ctrlKey||ue.altKey||!ue.shiftKey||E4(ue.target)||(ue.preventDefault(),bs())};return document.addEventListener("keydown",X),()=>document.removeEventListener("keydown",X)},[bs,$]);const Xi=X=>jr.messagesBySession[X.id]?qd.has(X.id):X.awaitingInput===!0,Ba=(X,ue)=>X.id===e?jr.busySessions.has(ue.id):ue.busy,mn=[];if(K==="projects"&&ke.forEach((X,ue)=>{const xe=it[ue],Te=(X.id===e?ir:xe.data??cO).filter(Vr=>!Vr.sideParentSessionId&&($os(Fe,Vr.archived)||Vr.id===Ie)).sort((Vr,ko)=>ko.updatedAt-Vr.updatedAt),kt=vt[X.id]??6;let lt=Te.slice(0,kt);const Gt=Te.find(Vr=>Vr.id===Ie);Gt&&!lt.some(Vr=>Vr.id===Ie)&&(lt=[...lt.slice(0,kt-1),Gt]);const Nr=ye.includes(X.id);mn.push({kind:"project",project:X,collapsed:Nr,busy:Nr&&Te.some(Vr=>Ba(X,Vr)&&!Xi(Vr))}),!Nr&&(lt.forEach(Vr=>mn.push({kind:"chat",project:X,session:Vr})),Te.length>kt&&mn.push({kind:"more",project:X}),!lt.length&&(K==="projects"||xe.isPending||xe.error)&&mn.push({kind:"status",project:X,pending:xe.isPending,error:!!xe.error,retry:()=>{xe.refetch()}}))}),K==="list"){const X=((Ou=ft.data)==null?void 0:Ou.pages.flatMap(be=>be.sessions))??[],ue=ir.find(be=>be.id===Ie);ue&&!X.some(be=>be.id===ue.id)&&X.push(ue),X.filter(be=>!Ai.has(be.id)).sort((be,Te)=>Te.updatedAt-be.updatedAt).forEach(be=>{const Te=ie.find(kt=>kt.id===be.projectId);Te&&mn.push({kind:"chat",project:Te,session:be})});const xe=Ye??ie[0];xe&&(!mn.length||ft.isFetchingNextPage||ft.isError)&&mn.push({kind:"status",project:xe,pending:ft.isPending||ft.isFetchingNextPage,error:ft.isError,retry:()=>{ft.isFetchNextPageError?ft.fetchNextPage():ft.refetch()}})}const Js=K==="list"||Me,Qp=CR(mn,$t,Ie),Gd=Qp.lengthX+gg(ue),0),cn=X=>X.kind==="chat"?X.session.id:`${X.kind}:${X.project.id}`,yr=IH({count:mn.length,getScrollElement:()=>pt.current,getItemKey:X=>cn(mn[X]),estimateSize:X=>gg(mn[X]),overscan:5,rangeExtractor:X=>{const ue=pC(X),xe=mn.findIndex(be=>cn(be)===sr);return xe<0||ue.includes(xe)?ue:[...ue,xe].sort((be,Te)=>be-Te)},enabled:Js&&a&&!$}),Yi=yr.getVirtualItems(),Bo=((Xd=Yi.at(-1))==null?void 0:Xd.index)??-1;A.useEffect(()=>{K==="list"&&a&&!$&&Bo>=mn.length-6&&ft.hasNextPage&&!ft.isFetching&&!ft.isError&&ft.fetchNextPage()},[K,a,$,Bo,mn.length,ft.hasNextPage,ft.isFetching,ft.isError,ft.fetchNextPage]);const Vd=l.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,l.jsxs("nav",{className:"rail-nav flex flex-col gap-0.5 p-2 shrink-0",children:[l.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":wo,"aria-keyshortcuts":"Meta+Shift+Enter Control+Shift+Enter",onClick:bs,children:[l.jsx(mc,{size:15}),S3()]}),l.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:[l.jsx(FP,{size:15}),XOe()]}),Qns.map(X=>l.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"&&X.activeTabs.includes(_)?"active":""}`,"data-onboarding":X.id==="compute"?"nav-compute":void 0,onClick:()=>d(X.id),children:[X.icon,X.label()]},X.id))]}),l.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:[l.jsx("div",{className:"rail-section-label p-0 text-sm font-medium text-subtext",children:K==="projects"?zS():gD()}),l.jsxs("div",{className:"rail-section-actions flex items-center gap-0.5",children:[c&&l.jsx(va,{interactive:!0,content:Tg(),className:"rounded-sm",children:l.jsx(jt,{size:"small",className:"text-subtext","aria-label":Tg(),onClick:c,children:l.jsx(EIn,{size:15,className:"text-subtext"})})}),l.jsx(Dos,{value:Fe,onChange:Ve,grouping:K,onGroupingChange:X=>{ne(X);try{localStorage.setItem("sidebar-grouping",X)}catch{}He(!1),ht({}),pt.current&&(pt.current.scrollTop=0)}})]})]}),l.jsxs("div",{className:"relative flex-1 min-h-0",children:[l.jsx("div",{ref:pt,tabIndex:-1,className:`rail-body h-full overflow-x-hidden ${Js?"overflow-y-auto":"overflow-y-hidden"}`,children:l.jsxs("div",{className:"relative",style:{height:(Js?yr.getTotalSize():Es)+(Kd?38:0)+(Me?46:0)},children:[(Js?Yi.map(X=>({row:mn[X.index],top:X.start,index:X.index})):Wd.map((X,ue)=>({row:X,top:0,index:ue}))).map(({row:X,top:ue,index:xe})=>{var kt;const be=X.project,Te=X.kind==="chat"?X.session:null;return l.jsx("div",{"data-index":xe,onFocusCapture:()=>Dt(cn(X)),onBlurCapture:lt=>{lt.currentTarget.contains(lt.relatedTarget)||Dt(null)},className:Js?"absolute top-0 start-0 w-full":"relative",style:{height:gg(X),transform:Js?`translateY(${ue}px)`:void 0},children:X.kind==="project"?l.jsx("div",{className:"group h-9 flex items-end gap-1 rounded-md px-2.5 text-text",children:l.jsx(cXn,{project:be,chatCount:(kt=ee.find(lt=>lt.projectId===be.id))==null?void 0:kt.totalAgents,collapsed:X.collapsed,busy:X.busy,onToggleCollapsed:()=>{const lt=ye.includes(be.id)?ye.filter(Gt=>Gt!==be.id):[...ye,be.id];Ce(lt);try{localStorage.setItem("sidebar-collapsed-projects",JSON.stringify(lt))}catch{}},pinned:ce.includes(be.id),onPin:()=>{const lt=ce.includes(be.id)?ce.filter(Gt=>Gt!==be.id):[...ce,be.id];me(lt);try{localStorage.setItem("sidebar-pinned-projects",JSON.stringify(lt))}catch{}},onRemoved:()=>{be.id===e&&le({to:"/projects"})},onNewChat:()=>{be.id===e?Pa():le({to:"/projects/$projectId/tasks/new",params:{projectId:be.id}})}})}):Te?l.jsx("div",{className:K==="projects"?"ms-5.5":void 0,children:l.jsx(Fos,{session:Te,active:Te.id===Ie&&_==="chat",unread:Vt.has(Te.id),busy:Ba(be,Te),waiting:Xi(Te),experimentRunning:wn.some(lt=>lt.sessionId===Te.id),revealTitle:Bi.get(Te.id),onOpen:()=>{if(be.id===e?z(Te.id):le({to:"/projects/$projectId/tasks/$sessionId",params:{projectId:be.id,sessionId:Te.id}}),be.id===Dm){ABn(Te.id);const lt=YTn[Te.id];lt&&(l_({name:"demo_experiment_started",kind:"curated",experiment:lt}),l_({name:"first_action",surface:"demo",action:"open_experiment"}))}},onRename:lt=>Hr(Te,lt),onSetArchived:lt=>It(Te,lt),onDelete:()=>void Fs(Te)},Te.id)}):X.kind==="more"?l.jsx(Se,{variant:"ghost",size:"small",className:"ms-5.5 font-normal text-subtext",onClick:()=>{He(!0),ht(lt=>({...lt,[be.id]:(lt[be.id]??6)+6}))},children:C3()}):X.kind==="status"&&l.jsx("div",{className:`flex h-full items-center px-2.5 text-sm text-subtext ${K==="projects"?"ms-5.5":""}`,children:X.error?l.jsx(Se,{size:"small",onClick:X.retry,children:ps()}):X.pending?l.jsx(Ot,{}):Fe==="archived"?iNe():gNe()})},cn(X))}),Kd&&l.jsx("div",{className:"absolute start-0 flex h-9.5 w-full items-center pt-1",style:{top:Js?yr.getTotalSize():Es},children:l.jsx(Se,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{He(!0)},children:C3()})}),Me&&l.jsx("div",{className:"absolute start-0 w-full pt-1",style:{top:yr.getTotalSize()+(Kd?38:0)},children:l.jsx(Se,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{He(!1),ht({}),Dt(null),pt.current&&(pt.current.scrollTop=0,pt.current.focus())},children:Vy()})})]})}),Js&&l.jsxs(l.Fragment,{children:[(yr.scrollOffset??0)>0&&l.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"}),l.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"})]})]}),l.jsx(lF,{runtime:k})]}),zc="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",Xp=!a&&!$&&l.jsx(jt,{title:WE(),"aria-label":WE(),onClick:i,className:"mac-titlebar:ms-16",children:l.jsx(JP,{size:20})});return _!=="chat"?l.jsxs(l.Fragment,{children:[a&&Vd,l.jsxs("section",{className:"chat-pane flex-1 min-w-0 flex flex-col bg-background min-h-0",children:[!a&&l.jsx("div",{className:"flex h-12 shrink-0 items-center",children:Xp}),l.jsx("div",{className:"settings-view-scroll flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",children:n?l.jsxs("div",{role:"alert",className:"p-6 text-subtext",children:[n,l.jsx(Se,{onClick:s,children:ps()})]}):t?l.jsxs(ws,{className:"p-6",children:[l.jsx(Ot,{}),IE()]}):B},_)]})]}):l.jsxs(l.Fragment,{children:[a&&Vd,l.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:[l.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:[Xp,l.jsxs("div",{className:zc,children:[l.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:er&&l.jsxs(l.Fragment,{children:[(Nc=er.title)!=null&&Nc.trim()?l.jsx(Bg,{variant:"header",className:"flex-initial",title:er.title.trim(),children:l.jsx(bG,{title:er.title.trim(),animate:Tu!==void 0},Tu??"static")}):Gr?l.jsx(Ot,{}):null,l.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})]})}),$&&er&&l.jsx(jt,{"aria-label":rA(),"data-tip":rA(),onClick:()=>void Fs(er),children:l.jsx(G_,{size:15})})]})]}),n?l.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[l.jsx("p",{children:n}),l.jsx(Se,{onClick:s,children:ps()})]}):kl?l.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[l.jsx("p",{children:kl.message}),l.jsx(Se,{onClick:()=>void Mo.refetch(),children:ps()})]}):t||mi?l.jsx("div",{className:"chat-loading flex-1 min-h-0 overflow-hidden [scrollbar-gutter:stable_both-edges]",role:"status","aria-label":IE(),"aria-busy":"true",children:l.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:[l.jsx("div",{className:"ms-auto h-14 w-3/5 shrink-0 rounded-lg bg-panel"}),l.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((X,ue)=>l.jsx("div",{className:`h-3 rounded bg-panel ${X}`},ue))}),l.jsx("div",{className:"ms-auto h-10 w-2/5 shrink-0 rounded-lg bg-panel"}),l.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((X,ue)=>l.jsx("div",{className:`h-3 rounded bg-panel ${X}`},ue))}),l.jsx("div",{className:"ms-auto h-16 w-1/2 shrink-0 rounded-lg bg-panel"})]})}):!jc&&(er!=null&&er.sideParentSessionId||L)?l.jsxs("div",{className:"chat-empty flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center text-subtext",children:[l.jsx($g,{size:22}),l.jsx("p",{className:"m-0 text-balance",children:U_n()})]}):jc?l.jsx("div",{className:"chat-thread flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",ref:vc,tabIndex:0,role:"region","aria-label":((yi=er==null?void 0:er.title)==null?void 0:yi.trim())||eb(),onScroll:X=>{uf(X.currentTarget),Lo.dismiss()},children:l.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:ta,children:[l.jsx(MU,{projectId:e,sessionId:Ie,children:l.jsx(Oos,{scrollRef:vc,scrollToEndRef:Oo,stickToBottom:ra,onPinToBottom:xo,messages:Pn,allMessages:vl,canFork:bl,onFork:Z,onSelectFork:fe,busy:Gr,onOpenFile:Bn,onOpenRun:p,onOpenSpawnedSession:Zs,runExperimentName:m,onOpenExperiment:w,experimentName:y,onRespond:an,onOpenPlan:vi,onOpenSubagent:Zn,recoveringTurnId:Ii,onRecover:Ud,skills:wl},Ie)}),Gr&&xl&&l.jsx("div",{className:"flex items-center gap-2 text-subtext text-sm pt-0.5 px-0 pb-2 italic",children:kD()}),Gr&&!xl&&!Au&&!Kp&&l.jsx("div",{className:"text-base pt-0.5 px-1 pb-2",children:l.jsx("span",{className:"tool-running-shimmer",children:RZe()})})]})}):l.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:[l.jsx("div",{className:"chat-empty-mark w-10.5 h-10.5 mb-5.5 [&_svg]:block [&_svg]:w-full [&_svg]:h-full",children:l.jsx(ux,{})}),l.jsx("h2",{children:yKe()}),lf&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:hO,"aria-hidden":"true",children:dO.map((X,ue)=>l.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 ${N4[ue].box}`,children:[l.jsxs("span",{className:`flex w-full items-center gap-2.5 ${N4[ue].icon}`,children:[l.jsx(X,{size:17}),l.jsx("span",{className:"h-3.5 w-2/5 rounded bg-panel"})]}),l.jsx("span",{className:"h-3 w-4/5 rounded bg-panel"})]},ue))}),l.jsxs(ws,{className:"mt-3",role:"status",children:[l.jsx(Ot,{}),l.jsx("span",{children:FGe()})]})]}),Ru&&Ru.length>0&&l.jsx("div",{className:hO,role:"group","aria-label":YGe(),children:Ru.map((X,ue)=>{const xe=dO[ue],be=N4[ue],Te=kt=>{l_({name:"project_starter_clicked",slot:ue+1}),l_({name:"first_action",surface:vs,action:"starter_click"});const lt=!qt.trim()&&mr.length===0&&fr.length===0;kt||!(Je!=null&&Je.agentReady)||!lt?Sl(X.prompt):Cl({starter:X.prompt})};return l.jsxs("div",{className:"relative min-w-0",children:[l.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 ${be.box}`,onClick:()=>Te(!1),children:[l.jsxs("span",{className:"flex items-center gap-2.5 text-base font-medium text-text",children:[l.jsx(xe,{size:17,className:be.icon}),X.title]}),l.jsx("span",{className:"w-full truncate text-sm text-subtext",children:X.prompt})]}),l.jsx(jt,{size:"small",className:"absolute end-2.5 top-2.5 [&:hover:not(:disabled)]:bg-surface-bright","aria-label":KE({title:X.title}),title:KE({title:X.title}),onClick:()=>Te(!0),children:l.jsx(Lg,{size:13})})]},ue)})})]}),Lo.action&&l.jsxs(Se,{type:"button",size:"small",className:"chat-selection-action fixed z-50 shadow-control",style:{left:Lo.action.x,top:Lo.action.top,transform:"translateX(-50%)"},onMouseDown:X=>X.preventDefault(),onClick:Lo.add,children:[l.jsx(YP,{size:14}),ITe()]}),Bs.length>0&&l.jsx("div",{inert:t||!!n||mi,className:"mx-auto mb-2 flex max-h-96 w-full max-w-readable shrink-0 flex-col gap-2 overflow-y-auto px-3",children:Bs.map(X=>l.jsx(gG,{part:X,onRespond:an},`${Ie}-${X.id}`))}),l.jsxs("div",{inert:t||!!n||mi,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:[jc&&l.jsx(jt,{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 ${Q_?"opacity-0":"opacity-100"}`,title:ZE(),"aria-label":ZE(),inert:Q_,onClick:Mu,children:Gr&&!xl?l.jsx(L0,{size:18,className:"tool-running-shimmer-icon"}):l.jsx(IDn,{size:16})}),l.jsx(tns,{runs:wn.filter(X=>X.sessionId===Ie),onOpenRun:p},Ie),us&&!(yo&&us.promptId===yo.promptId)&&l.jsx(ens,{synthesized:us.synthesized,agentLabel:er?Pf(er.harness,er.harnessName):wZe(),showResumeModes:(er==null?void 0:er.harness)==="claude-code",onView:X=>vi==null?void 0:vi(us.plan,us.promptId,X),onApprove:X=>an({promptId:us.promptId,approve:!0,...X?{resumeMode:X}:{}}),onReject:()=>an({promptId:us.promptId,approve:!1}),onRevise:X=>{Ie&&gi({sessionId:Ie,promptId:us.promptId}),an({promptId:us.promptId,approve:!1,note:X})}}),Da.length>0&&l.jsx("div",{className:"composer-queued flex flex-col gap-1 mb-1.5",children:Da.map((X,ue)=>l.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:X.error?`${X.text} +`),i=n?dD():s&&o!==null?GCe({code:hr(o)}):null;return l.jsx("div",{className:"msg-shell ms-auto self-end flex w-full max-w-[88%] flex-col items-stretch gap-1.5",children:l.jsxs("div",{dir:"ltr",className:"max-w-full bg-panel rounded-[16px] py-2.5 px-[15px] text-base",children:[l.jsxs("div",{className:"flex items-start gap-2 font-mono text-sm text-text whitespace-pre-wrap wrap-anywhere",children:[l.jsxs("span",{className:"sr-only",children:[vD()," "]}),l.jsx(O_,{size:16,strokeWidth:1.6,className:`mt-0.5 shrink-0 ${s?"text-accent-red":"text-muted"}`,"aria-hidden":"true"}),l.jsx("span",{children:t})]}),a&&l.jsx("div",{className:`${UC} mt-2`,children:a.slice(0,2e4)}),i&&l.jsx("div",{className:`mt-1.5 text-xs ${s?"text-accent-red":"text-muted"}`,children:i})]})})}function hb(e,r){var S;const{replies:t,expansionState:n,activePermissionId:s,pendingTailToolId:o,onOpenFile:a,onOpenRun:i,onOpenSpawnedSession:c,runExperimentName:_,onOpenExperiment:d,experimentName:f,onRespond:p,onOpenPlan:m,onOpenSubagent:w,predictTextTail:y=!1}=r,v=e.filter(z=>z.type!=="steer"&&D_(z,s)).at(-1),x=[];let k=[];const b=()=>{k.length!==0&&(x.push(l.jsx(bos,{parts:k,expansionState:n,pendingTail:k.some(z=>z.id===o),streaming:y,onOpenSubagent:w,onOpenFile:a,onOpenRun:i,onOpenSpawnedSession:c,runExperimentName:_,onOpenExperiment:d,experimentName:f},`tg-${k[0].id}`)),k=[])};for(const z of e)if(D_(z,s)){if(z.type==="tool"&&z.tool==="api_error"){b(),x.push(l.jsx(WC,{part:z,busy:!1,recovering:!1,temporaryApiError:!0},z.id));continue}if(z.type==="tool"){k.push(z);continue}if(b(),z.type==="text")x.push(l.jsx(dc,{text:z.text,onOpenFile:a,onOpenRun:i,predict:y&&z.id===(v==null?void 0:v.id)},z.id));else if(z.type==="steer")x.push(l.jsxs("div",{dir:"auto",role:"note","aria-label":AKe(),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:[(t==null?void 0:t.questionById.has(z.id))&&l.jsx("div",{className:"mb-1 truncate text-subtext",children:t.questionById.get(z.id)}),(t==null?void 0:t.textById.get(z.id))??z.text]},z.id));else{if(z.type==="prompt"&&((S=z.prompt)==null?void 0:S.kind)==="question"&&!z.prompt.resolved)continue;z.type==="prompt"&&z.prompt&&x.push(l.jsx(gG,{part:z,questionText:t==null?void 0:t.questionById.get(z.id),answerInTranscript:t==null?void 0:t.prompts.has(z.id),onRespond:p,onOpenFile:a,onOpenPlan:m},z.id))}}return b(),x}function Eos(e){return vd(e).label}function Nos(e){const r=(e??"").toLowerCase();return r==="subagent"||r==="task"||r==="agent"}function pb(e){var r,t;return e.type==="tool"&&(Bp(e)||Nos(e.tool)||((r=e.state)==null?void 0:r.title)==="subagent"||(((t=e.children)==null?void 0:t.length)??0)>0)}function Aos(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.startsWith("The subagent is working in the background")?"":r}function wj(e,r){for(const t of e){if(t.id===r)return t;const n=t.children&&wj(t.children,r);if(n)return n}return null}function Tos({spawn:e,expansionState:r,onOpenFile:t,onOpenRun:n,runExperimentName:s,onOpenExperiment:o,experimentName:a,onOpenSubagent:i}){var y,v,x,k;if(Bp(e))return l.jsx(vG,{part:e});const c=e.children??[],_=((y=e.state)==null?void 0:y.status)==="running",d=((v=e.state)==null?void 0:v.status)==="error",f=d?e2(((x=e.state)==null?void 0:x.error)||((k=e.state)==null?void 0:k.output)||""):"",p=hb(c,{expansionState:r,onOpenFile:t,onOpenRun:n,runExperimentName:s,onOpenExperiment:o,experimentName:a,onOpenSubagent:i,predictTextTail:_,pendingTailToolId:_?PH(c):null}),w=c.some(b=>b.type==="text"&&!!b.text)?"":Aos(e);return l.jsxs("div",{className:"msg-assistant text-base leading-[1.62] text-text min-w-0",children:[d&&l.jsxs("span",{className:"sr-only",children:[mS()," "]}),f&&l.jsx("div",{className:UC,children:f.slice(0,2e4)}),p.length===0&&!w&&!f?l.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:_?gS():YEe()}):l.jsxs(l.Fragment,{children:[p,w&&l.jsx(dc,{text:w,onOpenFile:t,onOpenRun:n})]})]})}function vG({part:e}){const r=OXn(e),t=l.jsxs(l.Fragment,{children:[l.jsx(t0,{activity:{kind:"agent",label:w3()},className:"text-muted"}),l.jsx("span",{className:`${qC} text-subtext`,children:w3()})]});return r?l.jsxs("details",{className:"min-w-0 [&[open]_.update-chevron]:rotate-90",children:[l.jsxs("summary",{className:"tool-row flex cursor-pointer list-none items-center gap-2 min-w-0 py-[3px] px-1 rounded-sm focus-visible:outline-2 focus-visible:outline-text [&::-webkit-details-marker]:hidden",children:[t,l.jsx(_o,{size:12,className:"update-chevron text-muted","aria-hidden":"true"})]}),l.jsx("div",{className:"ps-7 py-2 text-sm",children:l.jsx(dc,{text:r})})]}):l.jsx("div",{className:"tool-row flex items-start gap-2 min-w-0 py-[3px] px-1",children:t})}function fO({part:e,pendingTail:r,onOpenSubagent:t}){var c,_,d;const n=((c=e.state)==null?void 0:c.status)==="error",s=e2(((_=e.state)==null?void 0:_.error)||((d=e.state)==null?void 0:d.output)||""),o=r&&!n?GC(vd(e)):vd(e),a=mG(!!(r&&!n));if(Bp(e))return l.jsx(vG,{part:e});const i=l.jsxs(l.Fragment,{children:[n&&l.jsxs("span",{className:"sr-only",children:[mS()," "]}),n?l.jsx("span",{className:"flex h-6 shrink-0 items-center text-accent-red",children:l.jsx(GP,{size:16,strokeWidth:1.75,className:"subagent-icon","aria-hidden":"true"})}):l.jsx(t0,{activity:o,className:`subagent-icon ${a?"tool-running-shimmer-icon":"text-muted"}`}),l.jsx("span",{className:`${qC} ${a?"tool-running-shimmer":n?"text-accent-red":"text-subtext"}`,children:o.label})]});return l.jsxs("button",{className:"subagent-row flex items-start gap-2 w-full 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:dAe(),...dn(f=>t==null?void 0:t(e.id,o.label,f)),disabled:!t,children:[i,l.jsx("span",{className:"subagent-row-chevron flex h-6 shrink-0 items-center text-muted",children:l.jsx(_o,{size:12})})]})}function Ros(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 VC(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")||pG(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 Mos(e){const[r,t]=A.useState({text:"",sequence:0}),n=A.useRef(null);return A.useEffect(()=>{var w,y,v,x,k;const s=((w=e[0])==null?void 0:w.id)??"",{messageId:o,states:a}=Ros(e),i=VC(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(b=>({text:i?dE({label:tu(i.label)}):"",sequence:b.sequence+1}));return}const c=n.current.messageId===o?n.current.states:new Map,_=n.current.permissionPath,d=[...a].filter(([b,S])=>{var z;return((z=c.get(b))==null?void 0:z.status)!==S.status});if(n.current={transcript:s,messageId:o,states:a,permissionPath:(i==null?void 0:i.path)??null},i&&i.path!==_){t(b=>({text:dE({label:tu(i.label)}),sequence:b.sequence+1}));return}const f=(y=d.find(([,b])=>Dx(b.part)))==null?void 0:y[1].part;if((f==null?void 0:f.id)==="turn-recovery"){const b=GH((x=(v=f.state)==null?void 0:v.input)==null?void 0:x.recoveryAction);t(S=>({text:`${$ye()}${b?` ${b==="retry"?Pbe():Nbe()}`:""}`,sequence:S.sequence+1}));return}if((f==null?void 0:f.id)==="turn-retry"){t(b=>({text:bbe(),sequence:b.sequence+1}));return}const p=d.filter(([,b])=>b.status==="error");if(p.length>0){const b=p.slice(0,2).map(([,S])=>vd(S.part).label).join(", ");t(S=>({text:p.length===1?pye({labels:b}):Sye({count:hr(p.length),labels:b}),sequence:S.sequence+1}));return}const m=d.filter(([,b])=>b.status==="running");if(m.length>0){const b=(k=m.at(-1))==null?void 0:k[1].part;t(S=>({text:b?GC(vd(b)).label:Qbe(),sequence:S.sequence+1}));return}d.some(([,b])=>b.status==="completed")&&t(b=>({text:oye(),sequence:b.sequence+1}))},[e]),r}const Oos=A.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:w,onOpenExperiment:y,experimentName:v,onRespond:x,onOpenPlan:k,onOpenSubagent:b,recoveringTurnId:S,onRecover:z,skills:N}){var q,Q,W;mu();const T=A.useMemo(()=>DXn(r),[r]),C=((q=VC(r))==null?void 0:q.id)??null,R=A.useRef([]),$=A.useMemo(()=>(R.current=HXn(r,R.current),R.current.filter(ae=>ae.some(le=>yos(le,C)))),[r,C]),L=A.useMemo(()=>{const ae=$.filter(le=>le[0].role==="user"&&!le[0].id.startsWith(nd));return MXn(a,r,ae.map(le=>le[0]),le=>le.startsWith(nd))},[r,$,a]),I=A.useRef(new Set),[P,B]=A.useState(!1),U=A.useCallback(ae=>$[ae][0].id,[$]),G=A.useCallback(ae=>{if(P)return $.map((ie,ee)=>ee);const le=new Set(pC(ae));return $.forEach((ie,ee)=>{I.current.has(ie[0].id)&&le.add(ee)}),[...le].sort((ie,ee)=>ie-ee)},[$,P]),J=IH({count:$.length,useFlushSync:!1,getScrollElement:()=>t.current,getItemKey:U,estimateSize:()=>400,overscan:1,initialRect:{width:((Q=t.current)==null?void 0:Q.clientWidth)??0,height:((W=t.current)==null?void 0:W.clientHeight)??0},initialOffset:()=>{var ae;return Math.max(0,$.length*400-(((ae=t.current)==null?void 0:ae.clientHeight)??0))},anchorTo:s.current?"end":"start",followOnAppend:!0,scrollEndThreshold:60,rangeExtractor:G});A.useLayoutEffect(()=>{const ae=()=>J.scrollToEnd();return n.current=ae,o(),()=>{n.current=null}},[J,n,o]),A.useEffect(()=>{const ae=()=>{var ee;const le=window.getSelection();if(!le||le.isCollapsed||!le.rangeCount)return;const ie=le.getRangeAt(0);for(const K of((ee=t.current)==null?void 0:ee.querySelectorAll("[data-message-id]"))??[])ie.intersectsNode(K)&&K.dataset.messageId&&I.current.add(K.dataset.messageId)};return document.addEventListener("selectionchange",ae),()=>document.removeEventListener("selectionchange",ae)},[t]);const te=r.at(-1),F=Mos(r),D=d?BH(r):null;return l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"sr-only",role:"status","aria-live":"polite",children:l.jsx("span",{children:F.text},F.sequence)}),l.jsx("button",{type:"button",className:"sr-only focus:not-sr-only","aria-pressed":P,onClick:()=>B(ae=>!ae),children:CYe()}),l.jsx("div",{className:"relative",style:{height:J.getTotalSize()},children:J.getVirtualItems().map(ae=>{var ne,ce,me,ye;const le=$[ae.index],ie=le[le.length-1],ee=le[0].id,K=d||S!==null;return l.jsx("div",{"data-index":ae.index,"data-message-id":ee,ref:J.measureElement,className:"absolute left-0 w-full pb-4",style:{top:ae.start},onClickCapture:Ce=>{!(Ce.target instanceof Element)||!Ce.target.closest("[data-work-toggle]")||(s.current=!1,J.setOptions({...J.options,anchorTo:"start"}))},onPointerDownCapture:()=>I.current.add(ee),onFocusCapture:()=>I.current.add(ee),children:l.jsx(jos,{message:ie,responseMessages:le,replies:T,forkCount:(ne=L.get(ie.id))==null?void 0:ne.count,forkIndex:(ce=L.get(ie.id))==null?void 0:ce.index,forkPrevId:(me=L.get(ie.id))==null?void 0:me.prevId,forkNextId:(ye=L.get(ie.id))==null?void 0:ye.nextId,forkDisabled:!i,branchDisabled:d,onFork:c,onSelectFork:_,activePermissionId:C,pendingTailToolId:(D==null?void 0:D.messageId)===ie.id?D.toolId:null,onOpenFile:f,onOpenRun:p,onOpenSpawnedSession:m,runExperimentName:w,onOpenExperiment:y,experimentName:v,onRespond:x,onOpenPlan:k,onOpenSubagent:b,busy:K,recoveringTurnId:S,onRecover:z,skills:N,predictTextTail:d&&ie===te&&ie.role==="assistant"})},ee)})})]})}),$os=(e,r)=>e==="all"?!0:e==="archived"?r:!r;function E4(e){return e instanceof Element&&e.closest("[data-side-chat]")!==null}const Los=[{id:"archived",label:jE,railLabel:jE},{id:"active",label:qAe,railLabel:CD},{id:"all",label:JAe,railLabel:gD}];function Dos({value:e,onChange:r,grouping:t,onGroupingChange:n}){const{open:s,setOpen:o,ref:a}=ka();return l.jsxs("div",{className:"rail-filter relative inline-flex",ref:a,children:[l.jsx(jt,{size:"small",className:"rail-filter-btn text-subtext",active:e!=="active",title:$E(),"aria-label":$E(),onClick:()=>o(i=>!i),children:l.jsx(tB,{size:15,className:"text-subtext"})}),s&&l.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:[l.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:ehn()}),["projects","list"].map(i=>l.jsxs(pr,{size:"compact",className:"text-sm",onClick:()=>{n(i),o(!1)},children:[l.jsx("span",{children:i==="projects"?zS():uhn()}),t===i&&l.jsx(so,{size:13})]},i)),l.jsx("div",{className:"my-1 border-t border-border"}),l.jsx("div",{className:"px-2 py-0.5 text-sm text-subtext",children:Udn()}),Los.map(i=>l.jsxs(pr,{size:"compact",className:"text-sm",onClick:()=>{r(i.id),o(!1)},children:[l.jsx("span",{children:i.label()}),e===i.id&&l.jsx(so,{size:13})]},i.id))]})]})}const Ios=14,Pos=500,Bos=1200;function bG({title:e,animate:r}){return r?l.jsx("span",{className:"title-reveal","aria-label":e,children:Array.from(e).map((t,n)=>t===" "?l.jsx("span",{"aria-hidden":!0,children:t},n):l.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*Ios,Pos)}ms`},children:t},n))}):l.jsx(l.Fragment,{children:e})}function Fos({session:e,active:r,unread:t,busy:n,waiting:s,experimentRunning:o,revealTitle:a,onOpen:i,onRename:c,onSetArchived:_,onDelete:d}){var N;const{open:f,setOpen:p,ref:m}=ka(),w=((N=e.title)==null?void 0:N.trim())||"Untitled",[y,v]=A.useState(!1),[x,k]=A.useState(""),b=A.useRef(null);function S(){var T;k(((T=e.title)==null?void 0:T.trim())||""),v(!0)}function z(){var C;const T=x.trim();v(!1),T&&T!==(((C=e.title)==null?void 0:C.trim())||"")&&c(T)}return A.useEffect(()=>{var T,C;y&&((T=b.current)==null||T.focus(),(C=b.current)==null||C.select())},[y]),l.jsxs("div",{ref:m,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":""} ${f?"menu-open":""} ${y?"editing":""}`,title:`${Pf(e.harness,e.harnessName)}${e.model?` · ${e.model}`:""}`,onClick:()=>{y||(f?p(!1):i())},onKeyDown:T=>{T.target===T.currentTarget&&(T.key==="Enter"||T.key===" ")&&(T.preventDefault(),f?p(!1):i())},children:[y?l.jsx("input",{ref:b,className:"session-title-input","aria-label":Tqe(),value:x,onChange:T=>k(T.target.value),onClick:T=>T.stopPropagation(),onBlur:z,onKeyDown:T=>{T.stopPropagation(),T.key==="Enter"?(T.preventDefault(),z()):T.key==="Escape"&&(T.preventDefault(),v(!1))}}):l.jsx("span",{className:"session-title",children:l.jsx(bG,{title:w,animate:a!==void 0},a??"static")}),o&&!y&&l.jsx(va,{content:j3(),className:"shrink-0 text-accent-green",children:l.jsx(M_,{size:14,className:"motion-safe:animate-[or-experiment-pulse_3s_ease-in-out_infinite]","aria-label":j3()})}),s&&!y&&l.jsx(va,{content:kD(),className:"shrink-0 text-accent-amber",children:l.jsx(qP,{size:14,"aria-hidden":"true"})}),l.jsx("span",{className:"session-dot",children:n&&!s?l.jsx("span",{className:"busy-dot"}):t&&!s&&l.jsx("span",{className:"unread-dot"})}),l.jsx("button",{className:"session-menu-btn",title:GE(),"aria-label":GE(),onClick:T=>{T.stopPropagation(),p(C=>!C)},children:l.jsx(L0,{size:14})}),f&&l.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:[l.jsx(pr,{onClick:T=>{T.stopPropagation(),p(!1),S()},children:l.jsx("span",{children:xD()})}),l.jsx(pr,{onClick:T=>{T.stopPropagation(),p(!1),_(!e.archived)},children:l.jsx("span",{children:e.archived?aJe():N6e()})}),l.jsx(pr,{danger:!0,onClick:T=>{T.stopPropagation(),p(!1),d()},children:l.jsx("span",{children:bD()})})]})]})}const dO=[HP,eB,O_,M_],Hos=()=>[{title:mUe(),prompt:aUe()},{title:LUe(),prompt:CUe()},{title:rGe(),prompt:WUe()},{title:wGe(),prompt:fGe()}],N4=[{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"}],hO="mt-7 grid w-full max-w-readable grid-cols-1 gap-3 sm:grid-cols-2";function qos(e,r){if(!e)return null;const t=e.model??null;return{...e,model:t,serviceTier:Gb(r,t,e.serviceTier),reasoningLevel:eP(r,t,e.reasoningLevel)}}function pO({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:w,experimentName:y,onOpenPlan:v,onOpenSubagent:x,runtime:k,composerFocusNonce:b=0,activeSessionId:S,onActiveSessionChange:z,preferredAgent:N,onPreferredAgentChange:T,preferredAutonomy:C,onPreferredAutonomyChange:R,embedded:$=!1,sideParentSessionId:L,onOpenSideChat:I,onRunSetup:P,children:B}){var Yp,zl,Ec,Qd,Ou,Xd,Nc,yi;const U=vr({mutationFn:X=>EOn(...X)}),G=vr({mutationFn:X=>SOn(...X)}),J=vr({mutationFn:X=>zOn(...X)}),te=vr({mutationFn:X=>COn(...X)}),F=vr({mutationFn:X=>gOn(...X)}),D=vr({mutationFn:rP}),q=vr({mutationFn:X=>yOn(...X)}),Q=vr({mutationFn:X=>kOn(...X)}),W=vr({mutationFn:X=>jOn(...X)}),ae=vr({mutationFn:wOn}),le=N0(),{data:ie=[]}=rt({...A_(),enabled:!$}),{data:ee=[]}=rt({...bA(),enabled:!$}),[K,ne]=A.useState(()=>{try{return localStorage.getItem("sidebar-grouping")==="list"?"list":"projects"}catch{return"projects"}}),[ce,me]=A.useState(()=>{try{const X=JSON.parse(localStorage.getItem("sidebar-pinned-projects")??"[]");return Array.isArray(X)?X.filter(ue=>typeof ue=="string"):[]}catch{return[]}}),[ye,Ce]=A.useState(()=>{try{const X=JSON.parse(localStorage.getItem("sidebar-collapsed-projects")??"[]");return Array.isArray(X)?X.filter(ue=>typeof ue=="string"):[]}catch{return[]}}),[Fe,Ve]=A.useState("active"),[Me,He]=A.useState(!1),pt=A.useRef(null),[$t,Xt]=A.useState(0),[sr,Dt]=A.useState(null),[vt,ht]=A.useState({});A.useLayoutEffect(()=>{const X=pt.current;if(!X||$)return;const ue=()=>Xt(X.clientHeight),xe=new ResizeObserver(ue);return xe.observe(X),ue(),()=>xe.disconnect()},[a,$,_]);const St=new Map(ee.map(X=>[X.projectId,X.lastActivityAt])),ze=[...ie].sort((X,ue)=>Number(ce.includes(ue.id))-Number(ce.includes(X.id))||Math.max(St.get(ue.id)??0,ue.updatedAt)-Math.max(St.get(X.id)??0,X.updatedAt)),Pe=K==="list"||Me?ze.length:Math.max(1,Math.ceil($t/36));let ke=ze.slice(0,Pe);const Ye=ie.find(X=>X.id===e);Ye&&!ke.some(X=>X.id===e)&&(ke=[...ke.slice(0,Pe-1),Ye]);const it=hL({queries:(K==="projects"?ke:[]).map(X=>({...uo(X.id),enabled:!$}))}),ft=TQ({queryKey:xt("listSidebarChatSessions",Fe),queryFn:({pageParam:X,signal:ue})=>z$n(Fe,X,ue),initialPageParam:null,getNextPageParam:X=>X.next??void 0,enabled:!$&&K==="list"}),Ze=A.useMemo(()=>uo(e),[e]),{data:ir=cO}=rt(Ze),De=A.useCallback(X=>{ms(Ze.queryKey,ue=>{if(!ue)return;const xe=typeof X=="function"?X(ue):X,be=new Map(ue.map(Te=>[Te.id,Te]));for(const Te of xe)be.get(Te.id)!==Te&&Ci(Qe,Ze.queryKey,Te.id),be.delete(Te.id);for(const Te of be.keys())Ci(Qe,Ze.queryKey,Te);return xe})},[Ze]),Ie=S,dt=A.useRef(z);dt.current=z;const Et=A.useRef({projectId:e});Et.current.projectId!==e&&(Et.current={projectId:e});const[Vt,Kr]=A.useState(new Set),[qt,Wt]=A.useState(""),[Tt,hn]=A.useState(!1),[fr,kr]=A.useState([]),Rt=A.useRef(0),Bt=A.useRef({projectId:e,activeId:Ie,mainView:_});(Bt.current.projectId!==e||Bt.current.activeId!==Ie||Bt.current.mainView!==_)&&(Bt.current={projectId:e,activeId:Ie,mainView:_});const[Ur,Yt]=A.useState(null),Tn=Ur===Bt.current,[mr,Mr]=A.useState([]),[Lr,os]=A.useState(null),[xn,pn]=A.useState(null),En=Ie??`${e}:new`,Zr=A.useRef(new Map),Br=A.useRef(Uk);Br.current={draft:qt,attachments:mr,annotations:fr};const Nt=e===Dm&&!$&&ir.length>0&&ir.every(X=>X.sideParentSessionId||ZTn[X.id]===X.activeLeafId)?aA:null,Jt=A.useRef(null);Nt!==null&&Jt.current===null&&Ie!==null&&(Jt.current=En);const sn=En===Jt.current?Nt:null;A.useLayoutEffect(()=>{const X=Zr.current.get(En)??Uk;return Br.current=X,Wt(X.draft),Mr(X.attachments),kr(X.annotations),pn(null),()=>{const ue=XXn(Br.current,sn);ue?Zr.current.set(En,ue):Zr.current.delete(En)}},[En,sn]);const[Ln,lr]=A.useState(null),Sa=A.useRef(Promise.resolve()),ks=A.useRef(0),js=A.useRef(0),[Ge,gt]=A.useState(null),Cr=A.useRef(null),Fr=A.useRef(!1),or=A.useRef(null),{data:wn=[]}=rt(gA()),[jr,br,Mo]=M$n(e,_==="chat"?Ie:null),{data:Ca=Wos}=rt(tl()),[Di,Ss]=A.useState(N);A.useEffect(()=>Ss(N),[N]);const[ho,as]=A.useState({}),[za,is]=A.useState(null);A.useEffect(()=>is(null),[L]);const[Nn,Ds]=A.useState(Vm),[Ii,Ea]=A.useState(null),Na=A.useRef(!1),Aa=A.useRef(null),[Pi,gs]=A.useState(null),ea=A.useRef(!1),Is=A.useRef(null),[Bi,Qn]=A.useState(new Map),Cs=A.useRef(new Map),vc=A.useRef(null),ta=A.useRef(null),Oo=A.useRef(null),ra=A.useRef(!0),[Q_,fl]=A.useState(!0),Dn=A.useRef(null),[X_,$o]=A.useState(!1),po=ka(),bc=A.useCallback(X=>{var ue;Rt.current+=1,kr(xe=>[...xe,{id:`annotation-${Rt.current}`,...X}]),(ue=Dn.current)==null||ue.focus()},[]),Lo=Uss(ta,bc);Gss(fr,$?$ss:Oss),A.useEffect(()=>{$o(!1),Lo.dismiss()},[Ie,e,Lo.dismiss]);const[li,cs]=A.useState(0),[yc,Do]=A.useState(0),[Ta,An]=A.useState(!1),[na,ls]=A.useState(0),[Xn,on]=A.useState(0),Rn=A.useRef(!1);function ui(X){if(!Qs)return;if(X.source==="command"&&Jx(X.name)){In(X.name,qt,Qs);return}const ue=X.name.replace(/@u$/,"^").replace(/@p$/,"~"),xe=X.source==="command"?1:eO(ue,Dn.current),be=rss(qt,Qs,ue,xe);Wt(be.text),window.requestAnimationFrame(()=>{var Te,kt;(Te=Dn.current)==null||Te.focus(),(kt=Dn.current)==null||kt.setSelectionRange(be.cursor,be.cursor),on(be.cursor)})}function ku(X){if(!Fi)return;const ue=TXn(qt,Fi,X);Wt(ue.text),window.requestAnimationFrame(()=>{var xe,be;(xe=Dn.current)==null||xe.focus(),(be=Dn.current)==null||be.setSelectionRange(ue.cursor,ue.cursor),on(ue.cursor)})}function ju(X){if(Oa)return!1;const ue=X.selectionStart;if(Rn.current||ue!==X.selectionEnd)return!1;const xe=qt.slice(0,ue).replace(/[ \t]+$/,"").length,be=b4(qt,xe);if(!be||be.end!==xe||!Vi(be.query)||ue>xe&&ue-xe!==eO(be.query,X))return!1;const Te=JM(qt,{...be,end:ue});return Wt(Te.text),on(Te.cursor),window.requestAnimationFrame(()=>X.setSelectionRange(Te.cursor,Te.cursor)),!0}function _i(X){os(null),pn(null);let be=mr.reduce((Te,kt)=>Te+kt.size,0);for(const Te of X){if(!/^(image\/(png|jpeg|gif|webp)|application\/pdf)$/.test(Te.type))continue;if(dl&&Te.type.startsWith("image/")){pn((bo==null?void 0:bo.id)??null);continue}if(Te.size>31457280){os(pCe({name:Ae(Te.name)}));continue}if(be+Te.size>41943040){os(SCe());continue}be+=Te.size;const kt=Bt.current,lt=En,Gt=new FileReader;Gt.onload=()=>{const Nr={dataUrl:Gt.result,mediaType:Te.type,name:Te.name,size:Te.size};if(Bt.current.projectId===kt.projectId&&Bt.current.activeId===kt.activeId){Mr(ko=>[...ko,Nr]);return}const Vr=Zr.current.get(lt)??Uk;Zr.current.set(lt,{...Vr,attachments:[...Vr.attachments,Nr]})},Gt.readAsDataURL(Te)}}function Dd(X){const ue=Array.from(X.clipboardData.items).filter(xe=>xe.kind==="file"&&(xe.type.startsWith("image/")||xe.type==="application/pdf")).map(xe=>xe.getAsFile()).filter(xe=>xe!==null);ue.length>0&&(X.preventDefault(),_i(ue))}const at=ir.find(X=>X.id===Ie),Ps=Di??RB(Ca),mo=at?{harness:at.harness,model:ho.model!==void 0?ho.model:at.model,serviceTier:ho.serviceTier!==void 0?ho.serviceTier:at.serviceTier,permissionMode:ho.permissionMode??at.permissionMode,reasoningLevel:ho.reasoningLevel??at.reasoningLevel}:Ps?{...Ps,...ho}:null,{data:fi=Gos}=rt(o$n(mo==null?void 0:mo.harness,e)),Id=mo?Ca.find(X=>X.id===mo.harness):void 0,Je=qBn(at,Id),Ra=zB(at==null?void 0:at.nativeConfiguration,{model:Ph(),mode:N3()}),Ma=Ra.find(X=>X.category==="model"),Vs=Ra.find(X=>X.category==="mode"&&X.choices.some(ue=>ue.id==="plan")),Io=Je==null?void 0:Je.options,go=Vs?"command":Io==null?void 0:Io.planActivation,{data:Y_}=rt({...IS(),enabled:!!P}),Z_=X=>{if(!Je)return;const ue=Y_==null?void 0:Y_[Je.id];if(!(Je.id==="claude-code"&&X===(ue==null?void 0:ue.login)&&!Je.loginEligible))return PU(Je,ue,X)},di=A.useMemo(()=>nss(fi,go),[fi,go]),J_=nO(qt),vo=J_!==null,Qs=b4(qt,Xn),Su=(Qs==null?void 0:Qs.query)??null,zr=Su===null?[]:di.filter(X=>ess(X,Su)),Oa=!vo&&Su!==null&&(Qs==null?void 0:Qs.end)===Xn&&zr.length>0,sa=Oa&&!Ta?zr:[],Pd=sa.length>0,ef=Math.min(li,Math.max(0,sa.length-1));A.useEffect(()=>cs(0),[Su]);const Fi=vo?null:zXn(qt,Xn),$a=(Fi==null?void 0:Fi.end)===Xn?Fi.query:null,tf=(Yp=rt({...F6(e,Ie?{sessionId:Ie}:{}),enabled:$a!==null}).data)==null?void 0:Yp.entries,rf=A.useMemo(()=>NXn(tf??[]),[tf]),hi=A.useMemo(()=>$a!==null&&!Ta?AXn(rf,$a):[],[rf,$a,Ta]),nf=hi.length>0,Xs=Math.min(yc,Math.max(0,hi.length-1));A.useEffect(()=>Do(0),[$a]);const cr=qos(Ma&&mo?{...mo,model:Ma.currentValue}:mo,Je),Cu=Zy(Je,cr==null?void 0:cr.model),bo=Je==null?void 0:Je.models.find(X=>X.id===(cr==null?void 0:cr.model)),dl=(bo==null?void 0:bo.imageInput)===!1?TEe({model:Ae(rb(bo))}):null,Fd=!!dl&&mr.some(X=>X.mediaType.startsWith("image/")),hl=!!bo&&xn===bo.id,sf=Fd||hl?dl:null;A.useEffect(()=>pn(null),[bo==null?void 0:bo.id]);const pl=X=>{if(at!=null&&at.harness.startsWith("acp:")&&Ma&&X.model){fk(at.id,Ma.id,X.model).catch(be=>Qt(be instanceof Error?be.message:String(be),"error"));return}if(!cr)return;const ue={...cr,...X},xe={};X.model!==void 0&&X.model!==cr.model&&(xe.model=X.model),X.serviceTier!==void 0&&X.serviceTier!==cr.serviceTier&&(xe.serviceTier=X.serviceTier),X.permissionMode!==void 0&&X.permissionMode!==cr.permissionMode&&(xe.permissionMode=X.permissionMode),X.reasoningLevel!==void 0&&X.reasoningLevel!==cr.reasoningLevel&&(xe.reasoningLevel=X.reasoningLevel),Ds(be=>({...be,...xe})),Ss(ue),T(ue).catch(()=>{}),at?as(be=>({...be,...X})):X.harness&&X.harness!==cr.harness&&as({})},Yn=A.useCallback(X=>{const ue=Sa.current.catch(()=>{}).then(()=>{if(!Ir(Ze.queryKey))throw new DOMException("Workspace changed","AbortError");return X()});return Sa.current=ue.then(()=>{},()=>{}),ue},[Ze]),ml=X=>{if(X==="plan"&&(Je==null?void 0:Je.id)==="claude-code"?(Ds(be=>({...be,permissionMode:X})),as(be=>({...be,permissionMode:X}))):(as(be=>{const Te={...be};return delete Te.permissionMode,Te}),pl({permissionMode:X})),!at)return;const ue=at.id,xe=++ks.current;lr(null),Yn(()=>U.mutateAsync([ue,X])).then(be=>{De(Te=>Te.map(kt=>kt.id===be.id?be:kt)),ks.current===xe&&as(Te=>{const kt={...Te};return delete kt.permissionMode,kt})}).catch(()=>{ks.current===xe&&(as(be=>{const Te={...be};return delete Te.permissionMode,Te}),lr($Je()))})},xc=X=>pl({reasoningLevel:X}),Hd=X=>{if(!at){L?is(X):R(X);return}const ue=at.id,xe=at.autonomy,be=++ks.current,Te=kt=>De(lt=>lt.map(Gt=>Gt.id===kt.id?kt:Gt));Te({...at,autonomy:X}),lr(null),Yn(()=>J.mutateAsync([ue,X])).then(kt=>{Te(kt),R(kt.autonomy)}).catch(()=>{De(kt=>kt.map(lt=>lt.id===ue&<.autonomy===X?{...lt,autonomy:xe}:lt)),ks.current===be&&lr(SJe())})},Hi=((zl=at==null?void 0:at.goal)==null?void 0:zl.trim())||"",wc=Vs?Vs.currentValue==="plan":(cr==null?void 0:cr.harness)==="claude-code"?cr.permissionMode==="plan":go==="command"?Ge??(at==null?void 0:at.planMode)??!1:!1;A.useEffect(()=>{Ge===null||(at==null?void 0:at.planMode)!==Ge||(Cr.current=null,gt(null))},[at==null?void 0:at.planMode,Ge]);async function qi(X){var be;if(Vs&&at){const Te=X?"plan":(be=Vs.choices.find(kt=>kt.id!=="plan"))==null?void 0:be.id;if(!Te)throw new Error(ev());await Yn(()=>fk(at.id,Vs.id,Te));return}if(Ds(Te=>({...Te,planMode:X})),Cr.current=X,gt(X),!at)return;const ue=at.id,xe=++js.current;lr(null);try{const Te=await Yn(()=>G.mutateAsync([ue,X]));De(kt=>kt.map(lt=>lt.id===Te.id?Te:lt)),js.current===xe&&(Cr.current=null,gt(null),lr(null))}catch(Te){throw js.current===xe&&(Cr.current=null,gt(null)),Te}}async function pi(){if((cr==null?void 0:cr.harness)==="claude-code"){ml("auto");return}if(at)try{await qi(!1)}catch{lr(Sze())}}async function Wp(){const X=!wc;try{if((cr==null?void 0:cr.harness)==="claude-code")ml(X?"plan":"auto");else if(go==="command")await qi(X);else throw new Error(J1())}catch{lr(ev())}}function Ui(X,ue=""){var xe;switch(X){case"plan":return Wp(),!1;case"new":if($){const be=(at==null?void 0:at.sideParentSessionId)??L;be&&(I==null||I(be,""))}else bs();return!1;case"resume":return $o(!0),!0;case"model":return ls(be=>be+1),!0;case"compact":return Gi(),!1;case"goal":return Yt(Bt.current),!1;case"side":return zu(ue),!1;case"copy":{const be=Pn.at(-1),Te=Gr&&(be==null?void 0:be.role)==="assistant"&&!be.completedAt,kt=UXn(Te?Pn.slice(0,-1):Pn);return kt?KC(kt):Qt(DNe(),"info"),!1}case"export":{const be=((xe=at==null?void 0:at.title)==null?void 0:xe.trim())||eb(),Te=at?GXn(be,Pn,{user:B8e(),assistant:Pf(at.harness,at.harnessName)}):null;return Te?wos(WXn(be),Te):Qt(KNe(),"info"),!1}}}function zu(X){$?Qt(yfn(),"info"):!at||!I?Qt(ufn(),"info"):I(at.id,X)}async function gl(X){lr(null);const ue=Et.current;try{const xe=await F.mutateAsync([e,X]);if(Qe.invalidateQueries({queryKey:_P().queryKey}),Et.current!==ue)return;De(be=>[xe,...be.filter(Te=>Te.id!==xe.id)]),Ve("all"),z(xe.id,{projectId:xe.projectId})}catch(xe){if(Et.current!==ue)return;lr(tEe({error:Ae(xe instanceof Error?xe.message:String(xe))}))}}async function of(X){var lt;const ue=X.trim();if(!ue){const Gt=(lt=at==null?void 0:at.goal)==null?void 0:lt.trim();Qt(Gt?a9e({goal:tu(Gt)}):S9e(),"info");return}const xe=Bt.current,be=()=>Bt.current.activeId===xe.activeId;lr(null);let Te=Ie;if(!Te){if(!(Je!=null&&Je.agentReady)||!cr){lr(J1());return}try{Te=(await Ia(cr,x4(go,void 0,Cr.current))).id}catch(Gt){lr(kE({error:Ae(Gt instanceof Error?Gt.message:String(Gt))}));return}}const kt=/^(clear|none|off)$/i.test(ue);try{const Gt=await Yn(()=>te.mutateAsync([Te,kt?null:ue]));De(Nr=>Nr.map(Vr=>Vr.id===Gt.id?Gt:Vr)),Qt(kt?X8e():$9e(),"success")}catch(Gt){if(!be())return;lr(kE({error:Ae(Gt instanceof Error?Gt.message:String(Gt))}))}}async function Gi(){const X=Ie;if(!X){Qt(zNe(),"info");return}if(Gr){lr(y7e());return}lr(null),Fe==="archived"&&Ve("active");const ue=Bt.current;try{const{message:xe}=await MOn(X);br({type:"upsertMessage",sessionId:X,message:xe})}catch(xe){if(Bt.current.activeId!==ue.activeId)return;lr(A7e({error:Ae(xe instanceof Error?xe.message:String(xe))}))}}function In(X,ue,xe){const be=JM(ue,xe);Wt(be.text),An(!0),!Ui(X)&&window.requestAnimationFrame(()=>{var Te,kt,lt;((Te=Dn.current)==null?void 0:Te.value)===be.text&&((kt=Dn.current)==null||kt.focus(),(lt=Dn.current)==null||lt.setSelectionRange(be.cursor,be.cursor),on(be.cursor))})}const Wi=A.useCallback(async(X=!1)=>{const ue=Et.current;if(ue.projectId!==e||!Ir(Ze.queryKey))return null;const xe=(Qe.getQueryData(Ze.queryKey)??[]).map(be=>be.id);try{const be=await Qe.fetchQuery({...Ze,...X?{staleTime:0}:{}});if(Et.current!==ue||!Ir(Ze.queryKey))return null;const Te=be.filter(lt=>!Ai.has(lt.id)),kt=new Set(Te.map(lt=>lt.id));for(const lt of xe)kt.has(lt)||ct(lt);return Cs.current=new Map(Te.map(lt=>[lt.id,lt.title])),Te}catch{return null}},[e]),La=A.useCallback(async X=>{Et.current.projectId!==e||!Ir(Ze.queryKey)||await Promise.all([Qe.fetchQuery({...Zc(X),staleTime:0}),Wi(!0)]).catch(()=>{})},[e,Wi]);A.useEffect(()=>{const X=mB();Kr(e===Dm?new Set([MS,OS].filter(xe=>!X.has(xe))):new Set),hn(!1),Qn(new Map),Cs.current=new Map,Wi();const ue=Et.current;return()=>{Et.current===ue&&(Et.current={projectId:e})}},[e,Wi]),A.useEffect(()=>{Ds(Vm),Is.current=null},[Ie]),A.useEffect(()=>Og(X=>{switch(X.type){case"session":{if(X.session.projectId!==e||Ai.has(X.session.id))return;const ue=Cs.current.has(X.session.id),xe=Cs.current.get(X.session.id)!==X.session.title;Cs.current.set(X.session.id,X.session.title),ue&&xe&&X.session.titleSource==="generated"&&(Qn(be=>{const Te=new Map(be);return Te.set(X.session.id,(be.get(X.session.id)??0)+1),Te}),window.setTimeout(()=>{Qn(be=>{if(!be.has(X.session.id))return be;const Te=new Map(be);return Te.delete(X.session.id),Te})},Bos));break}case"sessionDeleted":ct(X.sessionId);break}}),[e]),A.useEffect(()=>Og(X=>{X.type==="reconnected"&&Wi(!0),(X.type==="runsChanged"||X.type==="reconnected")&&Qe.invalidateQueries({queryKey:gA().queryKey})}),[Wi]);const vl=Ie?jr.messagesBySession[Ie]??iO:iO,Eu=Ie?jr.activeLeafBySession[Ie]??null:null;Aa.current=Eu;const Pn=A.useMemo(()=>AR(vl,Eu),[vl,Eu]),Nu=A.useRef({projectId:e,ids:jr.busySessions});A.useEffect(()=>{const X=Nu.current;Nu.current={projectId:e,ids:jr.busySessions},X.projectId===e&&Kr(ue=>FXn(ue,X.ids,jr.busySessions,ir,_==="chat"?Ie:null))},[e,jr.busySessions,ir,Ie,_]);const Gr=Ie?jr.busySessions.has(Ie):!1,bl=!Gr&&!!(Je!=null&&Je.agentReady),Au=Gr&&BH(Pn)!=null,Kp=Gr&&BXn(Pn),Da=Ie?jr.queuedBySession[Ie]??[]:[],af=Da.some(X=>X.dispatchState==="retrying"),cf=Da.findIndex(X=>X.dispatchState==="blocked"),yl=Da.reduce((X,ue)=>ue.dispatchState!=="retrying"||typeof ue.nextRetryAt!="number"?X:X===null?ue.nextRetryAt:Math.min(X,ue.nextRetryAt),null),[ao,Ki]=A.useState(()=>Date.now());A.useEffect(()=>{if(!af||yl===null||(Ki(Date.now()),yl<=Date.now()))return;const X=window.setInterval(()=>{const ue=Date.now();Ki(ue),ue>=yl&&window.clearInterval(X)},1e3);return()=>window.clearInterval(X)},[af,yl]),A.useEffect(()=>{const X=Da.reduce((ue,xe)=>xe.planMode??ue,void 0);X!==void 0?(Fr.current=!0,Cr.current=X,gt(X)):Fr.current&&(Fr.current=!1,Cr.current=null,gt(null))},[Da]);const mi=!!Ie&&Mo.isPending,qd=A.useMemo(()=>{const X=new Set;for(const[ue,xe]of Object.entries(jr.messagesBySession)){const be=jr.busySessions.has(ue);LXn(AR(xe,jr.activeLeafBySession[ue]),be)&&X.add(ue)}return X},[jr.busySessions,jr.messagesBySession,jr.activeLeafBySession]),xl=Gr&&Pn.some(X=>X.parts.some(ue=>ue.type==="prompt"&&ue.prompt&&!ue.prompt.resolved&&ue.prompt.nativeId)),Bs=A.useMemo(()=>Pn.flatMap(X=>X.parts.filter(ue=>{var xe;return ue.type==="prompt"&&((xe=ue.prompt)==null?void 0:xe.kind)==="question"&&!ue.prompt.resolved&&(!ue.prompt.nativeId||Gr)})),[Pn,Gr]),er=at,Tu=er?Bi.get(er.id):void 0,us=A.useMemo(()=>{var X;for(let ue=Pn.length-1;ue>=0;ue--)for(const xe of Pn[ue].parts)if(xe.type==="prompt"&&((X=xe.prompt)==null?void 0:X.kind)==="plan"&&!xe.prompt.resolved)return{promptId:xe.id,plan:xe.prompt.plan??"",synthesized:!!xe.prompt.synthesized};return null},[Pn]),Vi=X=>{if(vo)return!1;const ue=gj(X),xe=di.find(be=>be.name===HC(ue??X));return!xe||xe.source!=="command"?!!xe:ue&&y4(ue)?ue==="plan"||qt.trim().toLowerCase().startsWith(`/${X}`):qt.trim().toLowerCase()===`/${X}`},wl=A.useMemo(()=>di.filter(X=>X.source!=="command"),[di]),[kn,gi]=A.useState(null),yo=kn&&kn.sessionId===Ie?kn:null;A.useEffect(()=>{if(!kn)return;const X=jr.busySessions.has(kn.sessionId),ue=kn.sessionId===Ie&&us&&us.promptId!==kn.promptId;(!X||ue)&&gi(null)},[kn,us,jr.busySessions,Ie]);const Qi=A.useMemo(()=>VC(Pn),[Pn]),kc=Gr&&!!(Je!=null&&Je.supportsSteering)&&!!(Je!=null&&Je.agentReady)&&!us&&!xl&&!Qi&&mr.length===0&&fr.length===0,vi=A.useMemo(()=>v&&Ie?(X,ue,xe)=>v(X,Ie,ue,xe):void 0,[v,Ie]),Zn=A.useMemo(()=>x&&Ie?(X,ue,xe)=>x(Ie,X,ue,xe):void 0,[x,Ie]),Bn=A.useMemo(()=>f&&((X,ue,xe,be,Te)=>f(X,Ie??void 0,ue,xe,be,Te)),[f,Ie]);A.useEffect(()=>{ks.current+=1,js.current+=1;const X=(Ie?jr.queuedBySession[Ie]??[]:[]).reduce((ue,xe)=>xe.planMode??ue,void 0);Fr.current=X!==void 0,Cr.current=X??null,gt(X??null),as({}),lr(null)},[Ie]);const jc=_==="chat"&&(Pn.length>0||Gr),Wr=(cr==null?void 0:cr.harness)??null,Vp=(cr==null?void 0:cr.model)??null,kl=Mo.data?null:Mo.error,Ys=_==="chat"&&!$&&!jc&&!t&&!n&&!mi&&!kl,jl=rt({...$$n(e,Wr??"claude-code",Vp,E()),enabled:Ys&&Wr!==null,subscribed:Ys&&Wr!==null}),Ru=(Ec=jl.data)!=null&&Ec.blank?Hos():((Qd=jl.data)==null?void 0:Qd.prompts)??null,lf=Wr!==null&&jl.isPending,vs=e===Dm?"demo":"project",Sl=X=>{Wt(X),An(!1),window.requestAnimationFrame(()=>{const ue=Dn.current;ue&&(ue.focus(),ue.setSelectionRange(X.length,X.length),on(X.length))})};A.useEffect(()=>{sn&&(Wt(X=>X||sn),An(!1),on(sn.length))},[sn]),A.useEffect(()=>{if(b===0)return;const X=window.requestAnimationFrame(()=>{const ue=Dn.current;ue&&(ue.focus(),ue.setSelectionRange(ue.value.length,ue.value.length),ue.scrollIntoView({block:"nearest"}))});return()=>window.cancelAnimationFrame(X)},[b]);const Jn=A.useId(),Po=e===Dm&&qt===aA&&!Tt,uf=A.useCallback(X=>{const ue=X.scrollHeight-X.scrollTop-X.clientHeight<60;ra.current=ue,fl(ue)},[]),xo=A.useCallback(()=>{var X;ra.current=!0,fl(!0),(X=Oo.current)==null||X.call(Oo)},[]);A.useEffect(()=>{const X=vc.current,ue=ta.current;if(!X||!ue)return;const xe=new ResizeObserver(()=>{var be;ra.current?(be=Oo.current)==null||be.call(Oo):fl(X.scrollHeight-X.scrollTop-X.clientHeight<60)});return xe.observe(X),xe.observe(ue),()=>xe.disconnect()},[jc]);const Mu=A.useCallback(X=>{X.currentTarget.blur(),xo()},[xo]);async function Cl({queue:X=!1,starter:ue}={}){var rm,Al,Yd,hf,pf,nm;const xe=(ue??qt).trim(),be=ue===void 0?sss(xe,go):null,Te=(be==null?void 0:be.name)==="goal";if(Te&&!be.prompt){Wt(""),An(!1),Yt(Bt.current);return}if((Te||Tn)&&/^(clear|none|off)$/i.test(Te?be.prompt:xe)){Wt(""),Yt(null),await of("clear");return}if(be&&be.name!=="plan"&&!Te){Wt(y4(be.name)?"":be.prompt),An(!1),Ui(be.name,be.prompt);return}if(Fd||(ue===void 0&&l_({name:"first_action",surface:vs,action:"typed_prompt"}),ea.current))return;const kt=(be==null?void 0:be.name)==="plan",lt=Te||Tn,Gt=!wc,Nr=x4(Vs?void 0:go,kt?Gt:void 0,Cr.current),Vr=kt&&(Je==null?void 0:Je.id)==="claude-code"?Gt?"plan":"auto":void 0,ko=be?be.prompt:xe,Zi=mr,El=fr,Fn=El.map(Qr=>({text:Qr.text})),Zp=e,ff=_;let $u=Ie;const oa=()=>{const Qr=Bt.current;return Ir(Ze.queryKey)&&Qr.projectId===Zp&&Qr.activeId===$u&&Qr.mainView===ff},Ac=()=>{oa()&&(Wt(Qr=>Qr||xe),lt&&Yt(Bt.current),Mr(Qr=>Qr.length?Qr:Zi),kr(Qr=>Qr.length?Qr:El))};if(kt&&!ko&&Zi.length===0&&El.length===0){Wt(""),An(!1);try{if((Je==null?void 0:Je.id)==="claude-code")ml(Gt?"plan":"auto");else if(go==="command")await qi(Gt);else throw new Error(J1())}catch{lr(ev()),Ac()}return}if(kt&&Vs)try{await qi(Gt)}catch{oa()&&lr(ev());return}const Hn=cr?{...cr,...Vr?{permissionMode:Vr}:{}}:null;Vr&&ml(Vr);let Jp=null;const em=Cr.current;kt&&!Vs&&go==="command"&&(Jp=++js.current,Cr.current=Gt,gt(Gt));const df=()=>{!oa()||Jp===null||js.current!==Jp||(Cr.current=em,gt(em))};if(!ko&&Zi.length===0&&El.length===0||lt&&!ko)return;const tm=async Qr=>{if(!lt)return;const eo=await te.mutateAsync([Qr,ko]);De(to=>to.map(es=>es.id===eo.id?eo:es))},Tc=JSON.stringify({text:ko,goal:lt?ko:void 0,images:Zi.map(Qr=>({mediaType:Qr.mediaType,name:Qr.name,dataUrl:Qr.dataUrl})),annotations:Fn,settings:Hn?{model:Hn.model,serviceTier:Hn.serviceTier,permissionMode:Hn.permissionMode,planMode:Nr,reasoningLevel:Hn.reasoningLevel}:null}),Nl=((rm=Is.current)==null?void 0:rm.signature)===Tc?Is.current.id:`ct_${crypto.randomUUID()}`;if(Is.current={signature:Tc,id:Nl},Gr){if(!Ie||!(Je!=null&&Je.agentReady)){df();return}const Qr=Ie;Wt(""),Mr([]),kr([]),os(null),pn(null);const eo=Hn?{model:Hn.model,serviceTier:Hn.serviceTier,permissionMode:Hn.permissionMode,planMode:go==="command"?Nr??(at==null?void 0:at.planMode):Nr,reasoningLevel:Hn.reasoningLevel}:{};oa()&&as({});const to=Zi.map(es=>({mediaType:es.mediaType,dataBase64:es.dataUrl.slice(es.dataUrl.indexOf(",")+1),name:es.name}));try{(Al=(await Yn(async()=>(await tm(Qr),U3(Qr,ko,eo,to.length?to:void 0,Fn,Nl,kc&&!X&&!kt&&!lt?"steer":void 0)))).turn)!=null&&Al.existing&&await La(Qr),oa()&&(Ds(Vm),lt&&Yt(null)),((Yd=Is.current)==null?void 0:Yd.id)===Nl&&(Is.current=null)}catch{df(),Ac()}return}if(!(Je!=null&&Je.agentReady)){df();return}if(!Hn){df();return}let Fo=Ie;try{Wt(ln=>ln===qt?"":ln),Mr(ln=>ln===Zi?[]:ln),kr(ln=>ln===El?[]:ln),os(null),pn(null),ea.current=!0;try{if(!Fo){const Lu=await Ia(Hn,Nr);Fo=Lu.id,$u=Lu.id}if(!Ir(Ze.queryKey))return;const ln=Zc(Fo);await Qe.fetchQuery({...ln,...((hf=Qe.getQueryState(ln.queryKey))==null?void 0:hf.fetchStatus)==="fetching"?{staleTime:0}:{}})}finally{ea.current=!1}if(!Ir(Ze.queryKey))return;br({type:"optimisticUser",sessionId:Fo,text:ko||Q6e(),attachments:Zi.map(ln=>({url:ln.dataUrl,mediaType:ln.mediaType,name:ln.name})),annotations:El}),br({type:"busy",sessionId:Fo,busy:!0}),oa()&&xo(),oa()&&Fe==="archived"&&Ve("active");const Qr=Hn?{model:Hn.model,serviceTier:Hn.serviceTier,permissionMode:Hn.permissionMode,planMode:Nr,reasoningLevel:Hn.reasoningLevel}:{};oa()&&as({});const eo=Zi.map(ln=>({mediaType:ln.mediaType,dataBase64:ln.dataUrl.slice(ln.dataUrl.indexOf(",")+1),name:ln.name})),to=Fo;if(!to)throw new Error(mYe());(pf=(await Yn(async()=>(await tm(to),U3(to,ko,Qr,eo.length?eo:void 0,Fn,Nl)))).turn)!=null&&pf.existing&&await La(to),oa()&&(Ds(Vm),lt&&Yt(null)),((nm=Is.current)==null?void 0:nm.id)===Nl&&(Is.current=null)}catch(Qr){if(!Ir(Ze.queryKey)||(Ac(),df(),!Fo))return;const eo=Qr instanceof Error?Qr.message:String(Qr);if(!/session is busy/i.test(eo)&&await Qe.fetchQuery({...uo(e),staleTime:0}).then(es=>{var mf;return!!((mf=es.find(ln=>ln.id===Fo))!=null&&mf.busy)}).catch(()=>!1)){oa()&&(Wt(es=>es===ko?"":es),Mr(es=>es===Zi?[]:es),kr(es=>es===El?[]:es));return}br({type:"busy",sessionId:Fo,busy:!1}),br({type:"localError",sessionId:Fo,text:xEe({error:Ae(eo)})})}}async function Ia(X,ue){const xe=Bt.current,be=Et.current;let Te=L?await D.mutateAsync(L):await q.mutateAsync([e,X.harness,{model:X.model,serviceTier:X.serviceTier,permissionMode:X.permissionMode,planMode:ue,reasoningLevel:X.reasoningLevel,autonomy:C}]);return L&&za!==null&&Te.autonomy!==za&&(Te=await J.mutateAsync([Te.id,za])),Ir(Ze.queryKey)&&Et.current===be&&(De(kt=>[Te,...kt.filter(lt=>lt.id!==Te.id)]),Qe.getQueryData(Ze.queryKey)||Wi(!0)),Ir(Ze.queryKey)&&Et.current===be&&Bt.current===xe&&(dt.current(Te.id,{replace:!0}),Bt.current={...xe,activeId:Te.id}),Te}function _f(){const X=Sss(qt);Wt(X),window.requestAnimationFrame(()=>{var ue,xe;(ue=Dn.current)==null||ue.focus(),(xe=Dn.current)==null||xe.setSelectionRange(X.length,X.length),on(X.length)})}async function Sc(){const X=J_;if(!X)return;if(lr(null),Gr){lr($Ce());return}const ue=qt,xe=Bt.current;let be=Ie;const Te=()=>{const Nr=Bt.current;return Nr.projectId===xe.projectId&&Nr.activeId===be&&Nr.mainView===xe.mainView},kt=()=>{Te()&&Wt(Nr=>Nr||ue)};Wt(""),An(!1);let lt=Ie;if(!lt){if(!(Je!=null&&Je.agentReady)||!cr){kt(),lr(J1());return}try{const Nr=x4(go,void 0,Cr.current);lt=(await Ia(cr,Nr)).id,be=lt,Te()&&as({})}catch(Nr){kt();const Vr=Nr instanceof Error?Nr.message:String(Nr);Te()&&lr(xE({error:Ae(Vr)}));return}}Te()&&Fe==="archived"&&Ve("active");const Gt=`${nd}shell-${Date.now()}`;br({type:"localShell",sessionId:lt,id:Gt,command:X}),Te()&&xo();try{const{message:Nr}=await OOn(lt,X);br({type:"upsertMessage",sessionId:lt,message:Nr})}catch(Nr){const Vr=Nr instanceof Error?Nr.message:String(Nr);br({type:"localShell",sessionId:lt,id:Gt,command:X,error:xE({error:Ae(Vr)})})}}function bi(){Ie&&IOn(Ie).catch(()=>{lr(rZe())})}const Ud=A.useCallback(async(X,ue)=>{if(!(!Ie||Na.current)){Na.current=!0,lr(null),Ea(X);try{const xe=QXn({model:Nn.model,serviceTier:Nn.serviceTier,permissionMode:Nn.permissionMode,planMode:Nn.planMode,reasoningLevel:Nn.reasoningLevel}),be=Ie;(await $On(be,X,ue,xe)).turn.existing&&await La(be),Ds(Vm)}catch{lr(WQe())}finally{Na.current=!1,Ea(null)}}},[Ie,Nn,La]),Z=A.useCallback((X,ue)=>{if(!Ie||Gr||!(Je!=null&&Je.agentReady))return;const xe=Ie;br({type:"busy",sessionId:xe,busy:!0}),xo(),Yn(()=>LOn(xe,X,ue)).catch(be=>{br({type:"busy",sessionId:xe,busy:!1});const Te=be instanceof Error?be.message:String(be);br({type:"localError",sessionId:xe,text:fXe({error:Ae(Te)})})})},[Ie,Gr,Je==null?void 0:Je.agentReady,xo,Yn]),fe=A.useCallback(X=>{if(!Ie||Gr)return;const ue=Ie,xe=Aa.current;br({type:"activeLeaf",sessionId:ue,leafId:X}),Yn(()=>DOn(ue,X)).catch(be=>{br({type:"activeLeaf",sessionId:ue,leafId:xe});const Te=be instanceof Error?be.message:String(be);br({type:"localError",sessionId:ue,text:fZe({error:Ae(Te)})})})},[Ie,Gr,Yn]);function we(X){if(!Ie)return;const ue=Ie;AOn(ue,X).then(({removed:xe})=>{if(xe)return La(ue)}).catch(()=>lr(rXe()))}async function $e(X){if(!Ie||Pi)return;const ue=Ie;lr(null),gs(X);try{await TOn(ue,X),await La(ue)}catch{lr(wXe())}finally{gs(null)}}const Oe=A.useRef(!1);A.useEffect(()=>{const X=ue=>{Oe.current=E4(ue.target)};return document.addEventListener("pointerdown",X,!0),()=>document.removeEventListener("pointerdown",X,!0)},[]),A.useEffect(()=>{if(!Gr||_!=="chat")return;function X(ue){var be;ue.key!=="Escape"||ue.defaultPrevented||(ue.target===document.body?Oe.current:E4(ue.target))!==$||(ue.preventDefault(),bi(),(be=Dn.current)==null||be.focus())}return document.addEventListener("keydown",X),()=>document.removeEventListener("keydown",X)},[Gr,Ie,_,$]);function ct(X){Wy(X),Zr.current.delete(X),Jt.current===X&&(Jt.current=null),Bt.current.projectId===e&&Bt.current.activeId===X&&Bt.current.mainView==="chat"&&(Wt(""),Mr([]),kr([]),dt.current(null,{replace:!0})),Kr(ue=>{if(!ue.has(X))return ue;const xe=new Set(ue);return xe.delete(X),xe}),Cs.current.delete(X)}function st(X,ue){const xe=uo(X.projectId);Ci(Qe,xe.queryKey,X.id),ms(xe.queryKey,be=>be==null?void 0:be.map(Te=>Te.id===X.id?{...Te,...ue}:Te))}function It(X,ue){const xe=X.archived;st(X,{archived:ue}),Q.mutateAsync([X.id,ue]).catch(()=>{st(X,{archived:xe})})}function Hr(X,ue){const xe=X.title;st(X,{title:ue}),W.mutateAsync([X.id,ue]).catch(()=>{st(X,{title:xe})})}async function Fs(X){var xe;const ue=((xe=X.title)==null?void 0:xe.trim())||eb();if(window.confirm(oze({title:tu(ue)}))){try{await ae.mutateAsync(X.id)}catch(be){Qt(pze({title:tu(ue),error:Ae(be instanceof Error?be.message:String(be))}),"error");return}ct(X.id)}}const an=A.useCallback(X=>{if(!Ie)return Promise.resolve(!1);const ue=Ie;return br({type:"busy",sessionId:ue,busy:!0}),Yn(()=>POn(ue,X)).then(()=>!0).catch(xe=>(Qt(xe instanceof Error?xe.message:String(xe),"error"),!1)).finally(()=>{Ir(Ze.queryKey)&&(Qe.fetchQuery({...Zc(ue),staleTime:0}).catch(()=>{}),Qe.fetchQuery({...uo(e),staleTime:0}).catch(()=>{}))})},[Ie,e,Yn,Ze]),zs=/Mac|iPhone|iPad/.test(navigator.platform),wo=zs?"⌘ ⇧ ↵":"Ctrl + Shift + ↵",Cc=zs?"⌘ Enter":"Ctrl + Enter",Pa=A.useCallback(()=>{Ve("active"),z(null)},[z]),bs=A.useCallback(async()=>{try{const ue=(await Qe.fetchQuery({...bA(),staleTime:0})).reduce((xe,be)=>!xe||be.lastActivityAt>xe.lastActivityAt?be:xe,void 0);Ve("active"),z(null,{projectId:(ue==null?void 0:ue.projectId)??e})}catch(X){Qt(X instanceof Error?X.message:String(X),"error")}},[e,z]),Zs=A.useCallback(async X=>{const ue=Et.current,xe=Bt.current;try{const be=await xOn(X);if(Et.current!==ue||Bt.current!==xe)return;Ve("all"),z(X,{projectId:be.projectId})}catch(be){if(Et.current!==ue||Bt.current!==xe)return;Qt(be instanceof Error?be.message:String(be),"error")}},[z]);A.useEffect(()=>{if($)return;const X=ue=>{ue.repeat||ue.key!=="Enter"||!ue.metaKey&&!ue.ctrlKey||ue.altKey||!ue.shiftKey||E4(ue.target)||(ue.preventDefault(),bs())};return document.addEventListener("keydown",X),()=>document.removeEventListener("keydown",X)},[bs,$]);const Xi=X=>jr.messagesBySession[X.id]?qd.has(X.id):X.awaitingInput===!0,Ba=(X,ue)=>X.id===e?jr.busySessions.has(ue.id):ue.busy,mn=[];if(K==="projects"&&ke.forEach((X,ue)=>{const xe=it[ue],Te=(X.id===e?ir:xe.data??cO).filter(Vr=>!Vr.sideParentSessionId&&($os(Fe,Vr.archived)||Vr.id===Ie)).sort((Vr,ko)=>ko.updatedAt-Vr.updatedAt),kt=vt[X.id]??6;let lt=Te.slice(0,kt);const Gt=Te.find(Vr=>Vr.id===Ie);Gt&&!lt.some(Vr=>Vr.id===Ie)&&(lt=[...lt.slice(0,kt-1),Gt]);const Nr=ye.includes(X.id);mn.push({kind:"project",project:X,collapsed:Nr,busy:Nr&&Te.some(Vr=>Ba(X,Vr)&&!Xi(Vr))}),!Nr&&(lt.forEach(Vr=>mn.push({kind:"chat",project:X,session:Vr})),Te.length>kt&&mn.push({kind:"more",project:X}),!lt.length&&(K==="projects"||xe.isPending||xe.error)&&mn.push({kind:"status",project:X,pending:xe.isPending,error:!!xe.error,retry:()=>{xe.refetch()}}))}),K==="list"){const X=((Ou=ft.data)==null?void 0:Ou.pages.flatMap(be=>be.sessions))??[],ue=ir.find(be=>be.id===Ie);ue&&!X.some(be=>be.id===ue.id)&&X.push(ue),X.filter(be=>!Ai.has(be.id)).sort((be,Te)=>Te.updatedAt-be.updatedAt).forEach(be=>{const Te=ie.find(kt=>kt.id===be.projectId);Te&&mn.push({kind:"chat",project:Te,session:be})});const xe=Ye??ie[0];xe&&(!mn.length||ft.isFetchingNextPage||ft.isError)&&mn.push({kind:"status",project:xe,pending:ft.isPending||ft.isFetchingNextPage,error:ft.isError,retry:()=>{ft.isFetchNextPageError?ft.fetchNextPage():ft.refetch()}})}const Js=K==="list"||Me,Qp=CR(mn,$t,Ie),Gd=Qp.lengthX+gg(ue),0),cn=X=>X.kind==="chat"?X.session.id:`${X.kind}:${X.project.id}`,yr=IH({count:mn.length,getScrollElement:()=>pt.current,getItemKey:X=>cn(mn[X]),estimateSize:X=>gg(mn[X]),overscan:5,rangeExtractor:X=>{const ue=pC(X),xe=mn.findIndex(be=>cn(be)===sr);return xe<0||ue.includes(xe)?ue:[...ue,xe].sort((be,Te)=>be-Te)},enabled:Js&&a&&!$}),Yi=yr.getVirtualItems(),Bo=((Xd=Yi.at(-1))==null?void 0:Xd.index)??-1;A.useEffect(()=>{K==="list"&&a&&!$&&Bo>=mn.length-6&&ft.hasNextPage&&!ft.isFetching&&!ft.isError&&ft.fetchNextPage()},[K,a,$,Bo,mn.length,ft.hasNextPage,ft.isFetching,ft.isError,ft.fetchNextPage]);const Vd=l.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,l.jsxs("nav",{className:"rail-nav flex flex-col gap-0.5 p-2 shrink-0",children:[l.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":wo,"aria-keyshortcuts":"Meta+Shift+Enter Control+Shift+Enter",onClick:bs,children:[l.jsx(mc,{size:15}),S3()]}),l.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:[l.jsx(FP,{size:15}),XOe()]}),Qns.map(X=>l.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"&&X.activeTabs.includes(_)?"active":""}`,"data-onboarding":X.id==="compute"?"nav-compute":void 0,onClick:()=>d(X.id),children:[X.icon,X.label()]},X.id))]}),l.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:[l.jsx("div",{className:"rail-section-label p-0 text-sm font-medium text-subtext",children:K==="projects"?zS():gD()}),l.jsxs("div",{className:"rail-section-actions flex items-center gap-0.5",children:[c&&l.jsx(va,{interactive:!0,content:Tg(),className:"rounded-sm",children:l.jsx(jt,{size:"small",className:"text-subtext","aria-label":Tg(),onClick:c,children:l.jsx(EIn,{size:15,className:"text-subtext"})})}),l.jsx(Dos,{value:Fe,onChange:Ve,grouping:K,onGroupingChange:X=>{ne(X);try{localStorage.setItem("sidebar-grouping",X)}catch{}He(!1),ht({}),pt.current&&(pt.current.scrollTop=0)}})]})]}),l.jsxs("div",{className:"relative flex-1 min-h-0",children:[l.jsx("div",{ref:pt,tabIndex:-1,className:`rail-body h-full overflow-x-hidden ${Js?"overflow-y-auto":"overflow-y-hidden"}`,children:l.jsxs("div",{className:"relative",style:{height:(Js?yr.getTotalSize():Es)+(Kd?38:0)+(Me?46:0)},children:[(Js?Yi.map(X=>({row:mn[X.index],top:X.start,index:X.index})):Wd.map((X,ue)=>({row:X,top:0,index:ue}))).map(({row:X,top:ue,index:xe})=>{var kt;const be=X.project,Te=X.kind==="chat"?X.session:null;return l.jsx("div",{"data-index":xe,onFocusCapture:()=>Dt(cn(X)),onBlurCapture:lt=>{lt.currentTarget.contains(lt.relatedTarget)||Dt(null)},className:Js?"absolute top-0 start-0 w-full":"relative",style:{height:gg(X),top:Js?ue:void 0},children:X.kind==="project"?l.jsx("div",{className:"group h-9 flex items-end gap-1 rounded-md px-2.5 text-text",children:l.jsx(cXn,{project:be,chatCount:(kt=ee.find(lt=>lt.projectId===be.id))==null?void 0:kt.totalAgents,collapsed:X.collapsed,busy:X.busy,onToggleCollapsed:()=>{const lt=ye.includes(be.id)?ye.filter(Gt=>Gt!==be.id):[...ye,be.id];Ce(lt);try{localStorage.setItem("sidebar-collapsed-projects",JSON.stringify(lt))}catch{}},pinned:ce.includes(be.id),onPin:()=>{const lt=ce.includes(be.id)?ce.filter(Gt=>Gt!==be.id):[...ce,be.id];me(lt);try{localStorage.setItem("sidebar-pinned-projects",JSON.stringify(lt))}catch{}},onRemoved:()=>{be.id===e&&le({to:"/projects"})},onNewChat:()=>{be.id===e?Pa():le({to:"/projects/$projectId/tasks/new",params:{projectId:be.id}})}})}):Te?l.jsx("div",{className:K==="projects"?"ms-5.5":void 0,children:l.jsx(Fos,{session:Te,active:Te.id===Ie&&_==="chat",unread:Vt.has(Te.id),busy:Ba(be,Te),waiting:Xi(Te),experimentRunning:wn.some(lt=>lt.sessionId===Te.id),revealTitle:Bi.get(Te.id),onOpen:()=>{if(be.id===e?z(Te.id):le({to:"/projects/$projectId/tasks/$sessionId",params:{projectId:be.id,sessionId:Te.id}}),be.id===Dm){ABn(Te.id);const lt=YTn[Te.id];lt&&(l_({name:"demo_experiment_started",kind:"curated",experiment:lt}),l_({name:"first_action",surface:"demo",action:"open_experiment"}))}},onRename:lt=>Hr(Te,lt),onSetArchived:lt=>It(Te,lt),onDelete:()=>void Fs(Te)},Te.id)}):X.kind==="more"?l.jsx(Se,{variant:"ghost",size:"small",className:"ms-5.5 font-normal text-subtext",onClick:()=>{He(!0),ht(lt=>({...lt,[be.id]:(lt[be.id]??6)+6}))},children:C3()}):X.kind==="status"&&l.jsx("div",{className:`flex h-full items-center px-2.5 text-sm text-subtext ${K==="projects"?"ms-5.5":""}`,children:X.error?l.jsx(Se,{size:"small",onClick:X.retry,children:ps()}):X.pending?l.jsx(Ot,{}):Fe==="archived"?iNe():gNe()})},cn(X))}),Kd&&l.jsx("div",{className:"absolute start-0 flex h-9.5 w-full items-center pt-1",style:{top:Js?yr.getTotalSize():Es},children:l.jsx(Se,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{He(!0)},children:C3()})}),Me&&l.jsx("div",{className:"absolute start-0 w-full pt-1",style:{top:yr.getTotalSize()+(Kd?38:0)},children:l.jsx(Se,{variant:"ghost",size:"small",className:"text-subtext",onClick:()=>{He(!1),ht({}),Dt(null),pt.current&&(pt.current.scrollTop=0,pt.current.focus())},children:Vy()})})]})}),Js&&l.jsxs(l.Fragment,{children:[(yr.scrollOffset??0)>0&&l.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"}),l.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"})]})]}),l.jsx(lF,{runtime:k})]}),zc="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",Xp=!a&&!$&&l.jsx(jt,{title:WE(),"aria-label":WE(),onClick:i,className:"mac-titlebar:ms-16",children:l.jsx(JP,{size:20})});return _!=="chat"?l.jsxs(l.Fragment,{children:[a&&Vd,l.jsxs("section",{className:"chat-pane flex-1 min-w-0 flex flex-col bg-background min-h-0",children:[!a&&l.jsx("div",{className:"flex h-12 shrink-0 items-center",children:Xp}),l.jsx("div",{className:"settings-view-scroll flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",children:n?l.jsxs("div",{role:"alert",className:"p-6 text-subtext",children:[n,l.jsx(Se,{onClick:s,children:ps()})]}):t?l.jsxs(ws,{className:"p-6",children:[l.jsx(Ot,{}),IE()]}):B},_)]})]}):l.jsxs(l.Fragment,{children:[a&&Vd,l.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:[l.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:[Xp,l.jsxs("div",{className:zc,children:[l.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:er&&l.jsxs(l.Fragment,{children:[(Nc=er.title)!=null&&Nc.trim()?l.jsx(Bg,{variant:"header",className:"flex-initial",title:er.title.trim(),children:l.jsx(bG,{title:er.title.trim(),animate:Tu!==void 0},Tu??"static")}):Gr?l.jsx(Ot,{}):null,l.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})]})}),$&&er&&l.jsx(jt,{"aria-label":rA(),"data-tip":rA(),onClick:()=>void Fs(er),children:l.jsx(G_,{size:15})})]})]}),n?l.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[l.jsx("p",{children:n}),l.jsx(Se,{onClick:s,children:ps()})]}):kl?l.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-5 text-subtext",role:"alert",children:[l.jsx("p",{children:kl.message}),l.jsx(Se,{onClick:()=>void Mo.refetch(),children:ps()})]}):t||mi?l.jsx("div",{className:"chat-loading flex-1 min-h-0 overflow-hidden [scrollbar-gutter:stable_both-edges]",role:"status","aria-label":IE(),"aria-busy":"true",children:l.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:[l.jsx("div",{className:"ms-auto h-14 w-3/5 shrink-0 rounded-lg bg-panel"}),l.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((X,ue)=>l.jsx("div",{className:`h-3 rounded bg-panel ${X}`},ue))}),l.jsx("div",{className:"ms-auto h-10 w-2/5 shrink-0 rounded-lg bg-panel"}),l.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((X,ue)=>l.jsx("div",{className:`h-3 rounded bg-panel ${X}`},ue))}),l.jsx("div",{className:"ms-auto h-16 w-1/2 shrink-0 rounded-lg bg-panel"})]})}):!jc&&(er!=null&&er.sideParentSessionId||L)?l.jsxs("div",{className:"chat-empty flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center text-subtext",children:[l.jsx($g,{size:22}),l.jsx("p",{className:"m-0 text-balance",children:U_n()})]}):jc?l.jsx("div",{className:"chat-thread flex-1 min-h-0 overflow-y-auto [scrollbar-gutter:stable_both-edges]",ref:vc,tabIndex:0,role:"region","aria-label":((yi=er==null?void 0:er.title)==null?void 0:yi.trim())||eb(),onScroll:X=>{uf(X.currentTarget),Lo.dismiss()},children:l.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:ta,children:[l.jsx(MU,{projectId:e,sessionId:Ie,children:l.jsx(Oos,{scrollRef:vc,scrollToEndRef:Oo,stickToBottom:ra,onPinToBottom:xo,messages:Pn,allMessages:vl,canFork:bl,onFork:Z,onSelectFork:fe,busy:Gr,onOpenFile:Bn,onOpenRun:p,onOpenSpawnedSession:Zs,runExperimentName:m,onOpenExperiment:w,experimentName:y,onRespond:an,onOpenPlan:vi,onOpenSubagent:Zn,recoveringTurnId:Ii,onRecover:Ud,skills:wl},Ie)}),Gr&&xl&&l.jsx("div",{className:"flex items-center gap-2 text-subtext text-sm pt-0.5 px-0 pb-2 italic",children:kD()}),Gr&&!xl&&!Au&&!Kp&&l.jsx("div",{className:"text-base pt-0.5 px-1 pb-2",children:l.jsx("span",{className:"tool-running-shimmer",children:RZe()})})]})}):l.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:[l.jsx("div",{className:"chat-empty-mark w-10.5 h-10.5 mb-5.5 [&_svg]:block [&_svg]:w-full [&_svg]:h-full",children:l.jsx(ux,{})}),l.jsx("h2",{children:yKe()}),lf&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:hO,"aria-hidden":"true",children:dO.map((X,ue)=>l.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 ${N4[ue].box}`,children:[l.jsxs("span",{className:`flex w-full items-center gap-2.5 ${N4[ue].icon}`,children:[l.jsx(X,{size:17}),l.jsx("span",{className:"h-3.5 w-2/5 rounded bg-panel"})]}),l.jsx("span",{className:"h-3 w-4/5 rounded bg-panel"})]},ue))}),l.jsxs(ws,{className:"mt-3",role:"status",children:[l.jsx(Ot,{}),l.jsx("span",{children:FGe()})]})]}),Ru&&Ru.length>0&&l.jsx("div",{className:hO,role:"group","aria-label":YGe(),children:Ru.map((X,ue)=>{const xe=dO[ue],be=N4[ue],Te=kt=>{l_({name:"project_starter_clicked",slot:ue+1}),l_({name:"first_action",surface:vs,action:"starter_click"});const lt=!qt.trim()&&mr.length===0&&fr.length===0;kt||!(Je!=null&&Je.agentReady)||!lt?Sl(X.prompt):Cl({starter:X.prompt})};return l.jsxs("div",{className:"relative min-w-0",children:[l.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 ${be.box}`,onClick:()=>Te(!1),children:[l.jsxs("span",{className:"flex items-center gap-2.5 text-base font-medium text-text",children:[l.jsx(xe,{size:17,className:be.icon}),X.title]}),l.jsx("span",{className:"w-full truncate text-sm text-subtext",children:X.prompt})]}),l.jsx(jt,{size:"small",className:"absolute end-2.5 top-2.5 [&:hover:not(:disabled)]:bg-surface-bright","aria-label":KE({title:X.title}),title:KE({title:X.title}),onClick:()=>Te(!0),children:l.jsx(Lg,{size:13})})]},ue)})})]}),Lo.action&&l.jsxs(Se,{type:"button",size:"small",className:"chat-selection-action fixed z-50 shadow-control",style:{left:Lo.action.x,top:Lo.action.top,transform:"translateX(-50%)"},onMouseDown:X=>X.preventDefault(),onClick:Lo.add,children:[l.jsx(YP,{size:14}),ITe()]}),Bs.length>0&&l.jsx("div",{inert:t||!!n||mi,className:"mx-auto mb-2 flex max-h-96 w-full max-w-readable shrink-0 flex-col gap-2 overflow-y-auto px-3",children:Bs.map(X=>l.jsx(gG,{part:X,onRespond:an},`${Ie}-${X.id}`))}),l.jsxs("div",{inert:t||!!n||mi,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:[jc&&l.jsx(jt,{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 ${Q_?"opacity-0":"opacity-100"}`,title:ZE(),"aria-label":ZE(),inert:Q_,onClick:Mu,children:Gr&&!xl?l.jsx(L0,{size:18,className:"tool-running-shimmer-icon"}):l.jsx(IDn,{size:16})}),l.jsx(tns,{runs:wn.filter(X=>X.sessionId===Ie),onOpenRun:p},Ie),us&&!(yo&&us.promptId===yo.promptId)&&l.jsx(ens,{synthesized:us.synthesized,agentLabel:er?Pf(er.harness,er.harnessName):wZe(),showResumeModes:(er==null?void 0:er.harness)==="claude-code",onView:X=>vi==null?void 0:vi(us.plan,us.promptId,X),onApprove:X=>an({promptId:us.promptId,approve:!0,...X?{resumeMode:X}:{}}),onReject:()=>an({promptId:us.promptId,approve:!1}),onRevise:X=>{Ie&&gi({sessionId:Ie,promptId:us.promptId}),an({promptId:us.promptId,approve:!1,note:X})}}),Da.length>0&&l.jsx("div",{className:"composer-queued flex flex-col gap-1 mb-1.5",children:Da.map((X,ue)=>l.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:X.error?`${X.text} ${X.error}`:X.text,children:[X.dispatchState==="blocked"?l.jsx(XS,{size:13,className:"shrink-0 text-accent-amber"}):l.jsx(iIn,{size:13,className:"shrink-0 text-muted"}),l.jsx("span",{className:"flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-text",children:X.text}),X.dispatchState!=="blocked"&&l.jsx("span",{className:"shrink-0 text-sm text-muted",children:X.dispatchState==="retrying"?VXn(X.nextRetryAt,ao):gQe()}),X.dispatchState==="blocked"?l.jsxs(l.Fragment,{children:[l.jsx("button",{onClick:()=>void $e(X.id),"aria-label":mne({text:X.text}),disabled:Pi!==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:Pi===X.id?rI():ps()}),l.jsx("button",{onClick:()=>we(X.id),"aria-label":ane({text:X.text}),disabled:Pi!==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:yD()}),ue===cf&&uewe(X.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:l.jsx(fn,{size:11})})]},X.id))}),Po&&l.jsxs("div",{id:Jn,role:"note",className:`composer-demo-hint ${Uos}`,children:[l.jsxs("span",{className:"flex-1",dir:"auto",children:[l.jsx(M_,{size:16,className:"inline-block align-text-bottom me-2 text-primary"}),O$e()]}),l.jsx(jt,{size:"small","aria-label":AE(),title:AE(),onClick:()=>{var X;hn(!0),(X=Dn.current)==null||X.focus()},children:l.jsx(fn,{size:14})})]}),!$&&!Ie&&c&&l.jsx(aXn,{projects:ie,activity:ee,projectId:e,projectName:r,onNewProject:c,onSelect:X=>{X!==e&&le({to:"/projects/$projectId/tasks/new",params:{projectId:X}})}}),l.jsxs("div",{className:`composer-box relative flex flex-col border ${vo?"border-accent-amber":"border-border"} rounded-lg bg-background shadow-elevated`,"data-onboarding":"composer",children:[Je&&!Je.agentReady&&l.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:Je.catalogPending?l.jsxs("span",{children:[Je.name," — ",ud()]}):l.jsxs(l.Fragment,{children:[l.jsxs("strong",{children:[Je.name," ",EDe()]})," ",Je.agentNote?$_(Je.agentNote,P&&{canRun:X=>Z_(X)!==void 0,onRun:X=>{const ue=Z_(X);ue&&P(X,ue)}}):LQe()]})}),Pd&&l.jsx(_ss,{skills:sa,activeIndex:ef,onPick:ui,onHover:cs}),nf&&l.jsx(bss,{matches:hi,activeIndex:Xs,onPick:ku,onHover:Do}),X_&&l.jsx(jss,{activeSessionId:Ie,onClose:()=>$o(!1),onResume:X=>{$o(!1),Ve("all"),z(X.id,{projectId:X.projectId})},onImport:X=>{$o(!1),gl(X)}}),fr.length>0&&l.jsx(Vss,{annotations:fr,onClear:()=>{kr([]),window.requestAnimationFrame(()=>{var X;return(X=Dn.current)==null?void 0:X.focus()})},onRemove:X=>{const ue=fr.filter(xe=>xe.id!==X);kr(ue),ue.length===0&&window.requestAnimationFrame(()=>{var xe;return(xe=Dn.current)==null?void 0:xe.focus()})}}),mr.length>0&&l.jsx("div",{className:"composer-attachments flex flex-wrap gap-1.5 pt-2 px-3 pb-0",children:mr.map((X,ue)=>{const xe=()=>Mr(be=>be.filter((Te,kt)=>kt!==ue));return X.mediaType==="application/pdf"?l.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:X.name,children:[l.jsx(nx,{size:22}),l.jsx("span",{className:"attachment-file-name overflow-hidden text-ellipsis whitespace-nowrap text-sm",children:X.name??"document.pdf"}),l.jsx("button",{title:FE(),"aria-label":FE(),onClick:xe,children:l.jsx(fn,{size:11})})]},ue):l.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:[l.jsx("img",{src:X.dataUrl,alt:jD()}),l.jsx("button",{title:HE(),"aria-label":HE(),onClick:xe,children:l.jsx(fn,{size:11})})]},ue)})}),(sf??Lr)&&l.jsx("div",{className:"composer-attach-error pt-1.5 px-3 pb-0 text-sm text-accent-red",role:"alert",children:sf??Lr}),Ln&&l.jsx("div",{className:"composer-settings-error pt-1.5 px-3 pb-0 text-sm text-accent-red",role:"alert",children:Ln}),l.jsxs("div",{className:`composer-input relative flex overflow-hidden [&_textarea]:flex-1 ${vo?"[&_textarea]:font-mono [&_textarea]:text-sm":""}`,children:[l.jsx("textarea",{dir:"auto",writingsuggestions:"false",ref:Dn,"aria-describedby":Po?Jn:void 0,className:"relative z-1 bg-transparent",value:qt,placeholder:kc&&Je?WYe({harness:Ae(Je.name),shortcut:Ae(Cc)}):cr?Je!=null&&Je.agentReady?_Ee({harness:Ae(Pf(cr.harness,Je==null?void 0:Je.name))}):G9e({harness:Ae(Pf(cr.harness,Je==null?void 0:Je.name))}):P6e(),rows:2,onPaste:Dd,onDragOver:X=>{X.dataTransfer.types.includes("Files")&&X.preventDefault()},onDrop:X=>{X.dataTransfer.files.length!==0&&(X.preventDefault(),_i(Array.from(X.dataTransfer.files)))},onChange:X=>{const ue=X.target.value,xe=X.target.selectionStart;on(xe);const be=xe>0&&/\s/.test(ue[xe-1])&&!Rn.current&&nO(ue)===null?b4(ue,xe-1):null,Te=be&&gj(be.query),kt=be?(ue.slice(0,be.start)+ue.slice(be.end)).trim():"";if(be&&Te&&(Te==="plan"||Te==="goal"||!y4(Te)&&!kt)&&di.some(lt=>lt.name===Te)){In(Te,ue,be);return}Wt(ue),An(!1)},onSelect:X=>on(X.currentTarget.selectionStart),onCompositionStart:()=>{Rn.current=!0},onCompositionEnd:()=>{Rn.current=!1},onKeyDown:X=>{if(Rn.current||X.nativeEvent.isComposing||X.nativeEvent.keyCode===229){X.stopPropagation();return}if(Pd){if(X.key==="ArrowDown"||X.key==="ArrowUp"){X.preventDefault();const ue=X.key==="ArrowDown"?1:-1;cs((ef+ue+sa.length)%sa.length);return}if(X.key==="Tab"||X.key==="Enter"){X.preventDefault(),ui(sa[ef]);return}if(X.key==="Escape"){X.preventDefault(),An(!0);return}}if(nf){if(X.key==="ArrowDown"||X.key==="ArrowUp"){X.preventDefault();const ue=X.key==="ArrowDown"?1:-1;Do((Xs+ue+hi.length)%hi.length);return}if(X.key==="Tab"||X.key==="Enter"&&$a!==""&&!X.shiftKey&&!X.metaKey&&!X.ctrlKey){X.preventDefault(),ku(hi[Xs]);return}if(X.key==="Escape"){X.preventDefault(),An(!0);return}}if(X.key==="Backspace"&&ju(X.currentTarget)){X.preventDefault();return}if(X.key==="Enter"&&!X.shiftKey){if(X.preventDefault(),vo){Sc();return}Cl({queue:X.metaKey||X.ctrlKey})}}}),l.jsx(uss,{text:qt,editingTokenEnd:Qs==null?void 0:Qs.end,isCommand:Vi,skills:di,projectId:e,textareaRef:Dn})]}),l.jsxs("div",{className:"composer-actions flex min-w-0 justify-end items-center gap-2 pt-1.5 px-2 pb-2",children:[l.jsxs("div",{className:"option-picker relative inline-flex shrink-0",ref:po.ref,children:[l.jsx(jt,{type:"button",className:"composer-bare",title:nk(),"aria-label":nk(),"aria-haspopup":"dialog","aria-expanded":po.open,onClick:()=>po.setOpen(X=>!X),children:l.jsx(HPn,{size:16})}),po.open&&l.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:[l.jsx("span",{className:"px-1 text-sm font-medium text-muted",children:nk()}),l.jsx(oYn,{})]})]}),l.jsx("input",{ref:or,type:"file",accept:"application/pdf,image/png,image/jpeg,image/gif,image/webp",multiple:!0,hidden:!0,onChange:X=>{_i(Array.from(X.target.files??[])),X.target.value=""}}),l.jsx(jt,{type:"button",className:"composer-attach",title:SE(),"aria-label":SE(),onClick:()=>{var X;return(X=or.current)==null?void 0:X.click()},children:l.jsx(vPn,{size:16})}),(Hi||Tn)&&l.jsxs(Se,{type:"button",variant:"purple",active:!0,className:"group max-w-60",title:Tn?$D():NE({goal:tu(Hi)}),"aria-label":Tn?LE():NE({goal:tu(Hi)}),onClick:()=>{Yt(null),Hi&&of("clear")},children:[l.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[l.jsx(QP,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.6}),l.jsx(fn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.8})]}),l.jsx("span",{className:"truncate",children:LE()})]}),wc&&l.jsxs(Se,{type:"button",variant:"amber",active:!0,className:"group",title:OE(),"aria-label":OE(),onClick:()=>void pi(),children:[l.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[l.jsx(QIn,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.6}),l.jsx(fn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.8})]}),l.jsx("span",{children:mPe()})]}),vo&&l.jsxs(Se,{type:"button",variant:"ghost",active:!0,className:"group",title:ME(),"aria-label":ME(),onClick:_f,children:[l.jsxs("span",{className:"relative size-4","aria-hidden":"true",children:[l.jsx(O_,{className:"absolute inset-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0",size:16,strokeWidth:1.6}),l.jsx(fn,{className:"absolute inset-0 opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",size:16,strokeWidth:1.8})]}),l.jsx("span",{children:vD()})]}),l.jsx("div",{className:"min-w-0 flex-1"}),l.jsxs("div",{className:"flex min-w-0 items-center",children:[l.jsx(XBn,{sessionHarness:at!=null&&at.harness.startsWith("acp:")?Je:void 0,value:cr,onSelect:pl,onOpenSettings:()=>d("harnesses"),permissionChoices:Je!=null&&Je.agentReady?(Io==null?void 0:Io.permissionModes)??[]:[],defaultPermissionId:(Io==null?void 0:Io.defaultPermissionMode)??null,onSelectPermission:ml,reasoningChoices:Je!=null&&Je.agentReady?Cu.choices:[],defaultReasoningId:Cu.defaultId,onSelectReasoning:xc,autonomy:(at==null?void 0:at.autonomy)??za??C,onSelectAutonomy:Hd,lockHarness:!!at||!!L,openRequest:na,nativeOptions:at!=null&&at.harness.startsWith("acp:")?Ra.filter(X=>X.category!=="model"):[],onSelectNativeOption:(X,ue)=>{at&&fk(at.id,X,ue).catch(xe=>Qt(xe instanceof Error?xe.message:String(xe),"error"))}}),l.jsx(xss,{usage:at==null?void 0:at.contextUsage})]}),Gr?l.jsx(jt,{className:"send-btn",variant:"stop",title:VE(),"aria-label":VE(),onClick:bi,children:l.jsx(fn,{size:16})}):l.jsx(jt,{className:`send-btn ${Po&&(Je!=null&&Je.agentReady)?"ring-2 ring-primary ring-offset-2 ring-offset-background":""}`,variant:"primary",title:vo?UE():Db(),"aria-label":vo?UE():Db(),onClick:()=>void(vo?Sc():Cl()),disabled:vo?!J_||!Ie&&!(Je!=null&&Je.agentReady):!(Je!=null&&Je.agentReady)||!qt.trim()&&mr.length===0&&fr.length===0,children:l.jsx(WP,{size:16})})]})]})]})]})]})}const Uos="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",Gos=[],Wos=[];function ha({className:e,...r}){return l.jsx("div",{className:$n("relative flex min-h-0 flex-1 flex-col",e),...r})}function Gh({className:e,...r}){return l.jsx("div",{className:$n("min-h-0 flex-1 overflow-auto bg-background",e),...r})}function Qc({className:e,...r}){return l.jsx("div",{className:$n("shrink-0 border-b border-b-border-variant px-4 py-2 text-sm text-muted",e),...r})}const mO=["pane-content flex-1 min-h-0 relative subagent-tab-content overflow-y-auto","bg-background py-8 px-4"].join(" ");function Kos({projectId:e,sessionId:r,spawnPartId:t,expansionState:n,onOpenFile:s,onOpenRun:o,runExperimentName:a,onOpenExperiment:i,experimentName:c,onOpenSubagent:_}){var b,S,z,N,T,C;const d=rt(Zc(r)),f=((b=d.data)==null?void 0:b.messages)??(d.isError?[]:null),p=$Xn(f??[],t),m=rt({queryKey:xt("getSubagentTranscript",r,t,((z=(S=p==null?void 0:p.state)==null?void 0:S.input)==null?void 0:z.nativeTranscript)??null,((C=(T=(N=p==null?void 0:p.state)==null?void 0:N.output)==null?void 0:T.match(/\(sessionID: (ses_\w+)\)/))==null?void 0:C[1])??null),queryFn:({signal:R})=>WOn(r,t,R),refetchInterval:R=>{var $,L;return((L=($=R.state.data)==null?void 0:$.state)==null?void 0:L.status)==="running"?1500:!1},refetchIntervalInBackground:!0,refetchOnMount:"always"}),w=f===null||m.isPending,y=A.useRef(null),v=A.useRef(null),x=A.useRef(!0);if(A.useLayoutEffect(()=>{x.current=!0;const R=y.current;R&&(R.scrollTop=R.scrollHeight)},[r,t]),A.useLayoutEffect(()=>{const R=y.current;R&&x.current&&(R.scrollTop=R.scrollHeight)},[f,m.data]),A.useEffect(()=>{const R=y.current,$=v.current;if(!R||!$)return;const L=new ResizeObserver(()=>{x.current&&(R.scrollTop=R.scrollHeight)});return L.observe($),L.observe(R),()=>L.disconnect()},[w]),w)return l.jsx(ha,{children:l.jsx("div",{className:mO,children:l.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:MI()})})});const k=m.data??p;return l.jsx(ha,{children:l.jsx("div",{className:mO,ref:y,onScroll:R=>{const $=R.currentTarget;x.current=$.scrollHeight-$.scrollTop-$.clientHeight<60},children:l.jsx("div",{ref:v,children:k?l.jsx(MU,{projectId:e,sessionId:r,children:l.jsx(Tos,{spawn:k,expansionState:n,onOpenFile:s,onOpenRun:o,runExperimentName:a,onOpenExperiment:i,experimentName:c,onOpenSubagent:_})}):l.jsx("div",{className:"subagent-empty py-[3px] px-1 text-sm text-muted",children:B4n()})})})})}function Vos({experiment:e}){var s;const r=rt(vF(e.id)),t=r.data,n=(s=r.error)==null?void 0:s.message;return l.jsx(Gh,{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?l.jsxs(Qc,{children:[pSe()," ",Ae(n)]}):t?t.diff.trim()?l.jsxs(l.Fragment,{children:[t.truncated&&l.jsx(nH,{bytesRead:t.bytesRead,byteLimit:t.byteLimit}),l.jsx(oH,{diff:t.diff,partial:t.truncated})]}):l.jsx("div",{className:"changes-note text-sm text-muted",children:e.parentExperimentId?$Se():oSe()}):l.jsx(Qc,{children:SSe()})})}function yG({view:e,onViewChange:r,showViewToggle:t=!0,branchLabel:n,branchTitle:s,githubHref:o,githubTitle:a,refreshing:i,onRefresh:c}){return l.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&&l.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":Yet(),children:[l.jsx("button",{type:"button",className:e==="files"?"active":"","aria-pressed":e==="files",onClick:()=>r("files"),children:itt()}),l.jsx("button",{type:"button",className:e==="changes"?"active":"","aria-pressed":e==="changes",onClick:()=>r("changes"),children:zD()})]}),n&&l.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:[l.jsx(D0,{size:12}),l.jsx("span",{className:"wt-branch-name overflow-hidden text-ellipsis whitespace-nowrap",children:n})]}),o&&l.jsx(Rp,{href:o,target:"_blank",rel:"noopener noreferrer",title:a,"aria-label":a,children:l.jsx(eC,{size:13})}),l.jsx("span",{className:"flex-1"}),l.jsx(jt,{title:eN(),"aria-label":eN(),onClick:c,children:i?l.jsx(Ot,{}):l.jsx(NPn,{size:13})})]})}function xG(e,r){const t=navigator.clipboard;if(!t){Qt(yS(),"error");return}t.writeText(`${e.replace(/[\\/]+$/,"")}/${r}`).then(()=>Qt(ld(),"success")).catch(n=>Qt(n instanceof Error?n.message:String(n),"error"))}function wG({name:e,onCommit:r,onCancel:t}){const[n,s]=A.useState(e),o=A.useRef(!1),a=()=>{if(o.current)return;o.current=!0;const i=n.trim();!i||i===e?t():r(i)};return l.jsx(yn,{autoFocus:!0,variant:"inline",className:"min-w-0 flex-1",value:n,"aria-label":E1t({path:Ae(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 kG(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 jG({target:e,onOpen:r,onRename:t,onDuplicate:n,onCopyPath:s,onDelete:o,onClose:a}){const i=A.useRef(null),c=A.useRef(a);c.current=a;const[_,d]=A.useState({x:e.x,y:e.y});A.useLayoutEffect(()=>{var y;const m=i.current;if(!m)return;const w=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))}),(y=m.querySelector("button"))==null||y.focus(),()=>{m.contains(document.activeElement)&&(w==null||w.focus())}},[e]),A.useEffect(()=>{const m=()=>c.current(),w=v=>{var x;(x=i.current)!=null&&x.contains(v.target instanceof Node?v.target:null)||c.current()},y=v=>{if(v.key==="Tab"){v.preventDefault(),c.current();return}v.key==="Escape"&&(v.preventDefault(),v.stopPropagation(),c.current())};return document.addEventListener("pointerdown",w),window.addEventListener("blur",m),window.addEventListener("resize",m),window.addEventListener("scroll",m,!0),document.addEventListener("keydown",y,!0),()=>{document.removeEventListener("pointerdown",w),window.removeEventListener("blur",m),window.removeEventListener("resize",m),window.removeEventListener("scroll",m,!0),document.removeEventListener("keydown",y,!0)}},[]);const f=m=>{c.current(),m()},p=(m,w,y=!1)=>l.jsx(pr,{size:"compact",role:"menuitem",danger:y,onClick:()=>f(w),children:l.jsx("span",{children:m})});return oo.createPortal(l.jsxs("div",{ref:i,role:"menu","aria-label":c1t({path:Ae(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 x,k;if(m.key!=="ArrowDown"&&m.key!=="ArrowUp")return;m.preventDefault();const w=[...((x=i.current)==null?void 0:x.querySelectorAll("button"))??[]],y=w.indexOf(document.activeElement instanceof HTMLButtonElement?document.activeElement:w[0]),v=m.key==="ArrowDown"?1:-1;(k=w[(y+v+w.length)%w.length])==null||k.focus()},children:[p(v1t(),r),t&&p(xD(),t),n&&p(Z0t(),n),p(u3e(),s),o&&p(bD(),o,!0)]}),document.body)}const kj=["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(" "),gO=["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 vO(){return{dirs:new Map,files:[]}}function SG(e){const r=vO();for(const t of e){const n=t.split("/");let s=r;for(let o=0;oo(t),title:t,children:[p?l.jsx(pc,{size:13,className:gO}):l.jsx(_o,{size:13,className:gO}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:e})]}),p&&l.jsx(QC,{node:r,parentPath:t,depth:n+1,toggled:s,onToggle:o,onOpenFile:a,renamingPath:i,onContextMenu:c,onRename:_,onCancelRename:d})]})}function QC({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 l.jsxs(l.Fragment,{children:[d.map(p=>{const m=r?`${r}/${p}`:p;return l.jsx(Qos,{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 l.jsxs("div",{className:kj,style:{paddingInlineStart:8+t*14},children:[l.jsx(gd,{name:p}),l.jsx(wG,{name:p,onCommit:y=>c(m,y),onCancel:_})]},`f:${m}`);const w=dn(y=>o(m,y));return l.jsxs("button",{type:"button",className:kj,style:{paddingInlineStart:8+t*14},...w,onContextMenu:y=>{i&&(y.preventDefault(),i(y,m))},onKeyDown:y=>{if(i&&(y.key==="ContextMenu"||y.shiftKey&&y.key==="F10")){y.preventDefault(),i(y,m);return}w.onKeyDown(y)},title:Yee({name:Ae(m)}),children:[l.jsx(gd,{name:p}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p})]},`f:${m}`)})]})}function Xos({projectId:e,project:r,experiment:t,view:n,toggled:s,onViewChange:o,onToggledChange:a,onOpenFile:i}){var z,N;const c=t.branchName,_=rt({...F6(e,{ref:c}),enabled:n==="files",subscribed:n==="files"}),d=rt({...ry(t.chatSessionId??""),enabled:n==="files"&&!!t.chatSessionId,subscribed:n==="files"&&!!t.chatSessionId}),f=_.data,p=(z=_.error)==null?void 0:z.message,m=_.isFetching,w=vF(t.id),y=AQ({queryKey:w.queryKey})>0,v=(N=d.data)!=null&&N.exists&&d.data.branch===c?t.chatSessionId??void 0:void 0,x=()=>{_.refetch()},k=A.useMemo(()=>f?SG(f.entries):null,[f]),b=n==="files"?m:y,S=A.useCallback(T=>{const C=new Set(s);C.has(T)?C.delete(T):C.add(T),a(C)},[s,a]);return l.jsxs("div",{className:"code-tab flex flex-col h-full min-h-0",children:[l.jsx(yG,{view:n,onViewChange:o,branchLabel:c,branchTitle:`Committed branch ${c}`,githubHref:r.githubEnabled?Yy(r.githubOwner,r.githubRepo,c):void 0,githubTitle:sD({branch:Ae(c)}),refreshing:b,onRefresh:()=>n==="files"?x():void Qe.invalidateQueries(w)}),n==="changes"?l.jsx(Vos,{experiment:t},t.id):l.jsxs(l.Fragment,{children:[(f==null?void 0:f.truncated)&&l.jsx(Qc,{children:Ctt()}),p&&k&&l.jsxs(Qc,{children:[Wtt()," ",Ae(p)]}),l.jsx(Gh,{children:k?k.dirs.size===0&&k.files.length===0?l.jsx(Qc,{children:Ltt()}):l.jsx("div",{className:"file-tree py-1.5 px-0 text-sm",children:l.jsx(QC,{node:k,parentPath:"",depth:0,toggled:s,onToggle:S,onOpenFile:(T,C)=>v?i(T,v,void 0,C):i(T,void 0,c,C)})}):l.jsx(Qc,{children:p?vS({error:Ae(p)}):Ky()})})]})]})}function XC({icon:e,title:r,description:t}){return l.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:[l.jsx(e,{size:36,strokeWidth:1.5,className:"shrink-0"}),l.jsx("h3",{className:"mt-1.5 mb-0 max-w-full wrap-anywhere text-xl font-medium text-text",children:r}),t&&l.jsx("p",{className:"m-0 w-full max-w-105 wrap-anywhere text-base leading-[1.55] text-subtext",children:t})]})}function Yos({sessionId:e,project:r,view:t,toggled:n,onViewChange:s,onToggledChange:o,onOpenFile:a,canRenameFile:i}){var F,D,q;const c=r.id,d=((F=rt(uo(c)).data)==null?void 0:F.some(Q=>Q.id===e&&Q.busy))??!1,f=rt({...ry(e??""),enabled:!!e,refetchInterval:d?5e3:!1}),p=f.data,m=e&&(p!=null&&p.exists)?{sessionId:e}:{ref:r.baselineBranch},w=rt({...F6(c,m),enabled:!e||f.isSuccess,refetchInterval:d?5e3:!1}),y=w.data,v=(D=f.error??w.error)==null?void 0:D.message,x=f.isFetching||w.isFetching,[k,b]=A.useState(null),[S,z]=A.useState(null),N=A.useCallback(()=>{e&&Qe.invalidateQueries(ry(e)),Qe.invalidateQueries({queryKey:xt("getCodeTree",c),predicate:Q=>!XL(Q)})},[e,c]),T=A.useRef(d);A.useEffect(()=>{T.current&&!d&&N(),T.current=d},[d,N]);const C=A.useMemo(()=>y?SG(y.entries):null,[y]),R=A.useCallback(Q=>{const W=new Set(n);W.has(Q)?W.delete(Q):W.add(Q),o(W)},[n,o]),$=e&&(p!=null&&p.exists)?p:null,L=($==null?void 0:$.branch)??($!=null&&$.baselineBranch?eTn({branch:Ae($.baselineBranch)}):nI()),I=((q=$==null?void 0:$.files)==null?void 0:q.length)??0,P=$?OAn({branch:Ae(`${L}${I>0?"*":""}`)}):UAn({branch:Ae(r.baselineBranch)}),B=$?$.branch:r.baselineBranch,U=(Q,W)=>$?a(Q,e,void 0,W):a(Q,void 0,r.baselineBranch,W),G=(y==null?void 0:y.root)==="worktree",J=async(Q,W)=>{try{await TRn(c,Q,W,{sessionId:e}),N()}catch(ae){Qt(ae instanceof Error?ae.message:String(ae),"error")}},te=Q=>{const W=(y==null?void 0:y.path)??r.repoPath;xG(W,Q)};return l.jsxs("div",{className:"code-tab flex flex-col h-full min-h-0 wt-tab",children:[l.jsx(yG,{view:$?t:"files",onViewChange:s,showViewToggle:!!$,branchLabel:P,branchTitle:P,githubHref:r.githubEnabled&&B?Yy(r.githubOwner,r.githubRepo,B):void 0,githubTitle:B?sD({branch:Ae(B)}):void 0,refreshing:x,onRefresh:N}),v&&(p||y)&&l.jsxs(Qc,{children:[XTn()," ",Ae(v)]}),!y||e&&!p?l.jsx(Gh,{children:l.jsx(Qc,{children:v?vS({error:Ae(v)}):Ky()})}):$&&t==="changes"?l.jsx(Gh,{className:"wt-changes px-4 pb-6 pt-0 [&_>_:first-child]:mt-3.5",children:I===0||!$.diff?l.jsx("div",{className:"changes-note text-sm text-muted",children:ATn()}):l.jsxs(l.Fragment,{children:[$.diff.truncated&&l.jsx(nH,{bytesRead:$.diff.bytesRead,byteLimit:$.diff.byteLimit}),l.jsx(oH,{diff:$.diff.diff,partial:$.diff.truncated})]})}):l.jsxs(Gh,{children:[y.truncated&&l.jsx(Qc,{children:uTn()}),C?C.dirs.size===0&&C.files.length===0?l.jsx(XC,{icon:ni,title:BTn(),description:W3t()}):l.jsx("div",{className:"file-tree py-1.5 px-0 text-sm",children:l.jsx(QC,{node:C,parentPath:"",depth:0,toggled:n,onToggle:R,onOpenFile:U,renamingPath:S,onContextMenu:(Q,W)=>{b(kG(Q,W))},onRename:(Q,W)=>{z(null),J(Q,{action:"rename",newName:W})},onCancelRename:()=>z(null)})}):l.jsx(Qc,{children:yTn()})]}),k&&l.jsx(jG,{target:k,onOpen:()=>U(k.path,"keepOpen"),onRename:G&&i(k.path)?()=>z(k.path):void 0,onDuplicate:G?()=>void J(k.path,{action:"duplicate"}):void 0,onCopyPath:()=>te(k.path),onDelete:G?()=>{window.confirm(H0t({path:Ae(k.path)}))&&J(k.path,{action:"delete"})}:void 0,onClose:()=>b(null)})]})}function CG({text:e,path:r,highlightLine:t,scrollRequest:n,onScrollRequestHandled:s}){const o=A.useMemo(()=>{if(!e)return[];const d=e.replace(/\r\n?/g,` `),f=oF(d,i6(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=A.useRef(null);A.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}=FB(o.length),_=A.useMemo(()=>o.map((d,f)=>l.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:[l.jsx("span",{"data-line":f+1,className:`${BB} before:content-[attr(data-line)] shrink-0 pe-[1ch]`,style:{width:`${c}ch`},"aria-hidden":"true"}),l.jsx("code",{className:`file-view-code flex-1 min-w-0 ps-[2ch] pe-4 ${ey} ${PB}`,children:aF(d)?l.jsx("br",{}):d})]},f)),[o,c,a]);return l.jsxs("div",{className:`file-view-codewrap relative py-3.5 ${ey}`,children:[o.length>0&&l.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 ky=A.createContext(null);function Zos({url:e,name:r}){return l.jsx(Rp,{size:"small",href:e,download:r,"aria-label":Ob({name:Ae(r)}),"data-tip":Ob({name:Ae(r)}),"data-tip-align":"end",children:l.jsx(rx,{size:13})})}const Jos=A.lazy(()=>OQ(()=>import("./PdfPreview-CsvPNokB.js"),__vite__mapDeps([0,1])).catch(e=>(console.error("PDF viewer failed to load",e),{default:EG})));function zG(e){return e==="image"||e==="audio"||e==="video"||e==="pdf"?e:null}function EG({url:e,name:r}){return l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[AOt()," ",l.jsxs("a",{href:e,download:r,children:[E3()," ",Ae(r)]})]})}function jj({kind:e,url:r,name:t,download:n=!0}){const[s,o]=A.useState(!1),a=A.useContext(ky);if(A.useEffect(()=>o(!1),[e,r]),s)return l.jsx(EG,{url:r,name:t});let i;return e==="image"?i=l.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:l.jsx("img",{src:r,alt:t,onError:()=>o(!0)})}):e==="audio"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.jsx("audio",{className:"w-full max-w-160",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):e==="video"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.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=l.jsx(A.Suspense,{fallback:l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center",children:l.jsx(Ot,{})}),children:l.jsx(Jos,{url:r,name:t,download:n,onError:()=>o(!0)},r)}),l.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i,n&&e!=="pdf"&&a&&oo.createPortal(l.jsx(Zos,{url:r,name:t}),a)]})}const eas=e=>({queryKey:xt("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 NG(e,r=!0){return rt({...eas(e),enabled:r,subscribed:r}).data??null}function tas(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function ras(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:`${_d(e,d)}${p?`&${p}`:""}${o}`}}function nas(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=A.useRef(null);A.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}=FB(o.length),_=A.useMemo(()=>o.map((d,f)=>l.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:[l.jsx("span",{"data-line":f+1,className:`${BB} before:content-[attr(data-line)] shrink-0 pe-[1ch]`,style:{width:`${c}ch`},"aria-hidden":"true"}),l.jsx("code",{className:`file-view-code flex-1 min-w-0 ps-[2ch] pe-4 ${ey} ${PB}`,children:aF(d)?l.jsx("br",{}):d})]},f)),[o,c,a]);return l.jsxs("div",{className:`file-view-codewrap relative py-3.5 ${ey}`,children:[o.length>0&&l.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 ky=A.createContext(null);function Zos({url:e,name:r}){return l.jsx(Rp,{size:"small",href:e,download:r,"aria-label":Ob({name:Ae(r)}),"data-tip":Ob({name:Ae(r)}),"data-tip-align":"end",children:l.jsx(rx,{size:13})})}const Jos=A.lazy(()=>OQ(()=>import("./PdfPreview-MpaSwii-.js"),__vite__mapDeps([0,1])).catch(e=>(console.error("PDF viewer failed to load",e),{default:EG})));function zG(e){return e==="image"||e==="audio"||e==="video"||e==="pdf"?e:null}function EG({url:e,name:r}){return l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[AOt()," ",l.jsxs("a",{href:e,download:r,children:[E3()," ",Ae(r)]})]})}function jj({kind:e,url:r,name:t,download:n=!0}){const[s,o]=A.useState(!1),a=A.useContext(ky);if(A.useEffect(()=>o(!1),[e,r]),s)return l.jsx(EG,{url:r,name:t});let i;return e==="image"?i=l.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:l.jsx("img",{src:r,alt:t,onError:()=>o(!0)})}):e==="audio"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.jsx("audio",{className:"w-full max-w-160",controls:!0,preload:"metadata",src:r,"aria-label":t,onError:()=>o(!0)})}):e==="video"?i=l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:l.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=l.jsx(A.Suspense,{fallback:l.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center",children:l.jsx(Ot,{})}),children:l.jsx(Jos,{url:r,name:t,download:n,onError:()=>o(!0)},r)}),l.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[i,n&&e!=="pdf"&&a&&oo.createPortal(l.jsx(Zos,{url:r,name:t}),a)]})}const eas=e=>({queryKey:xt("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 NG(e,r=!0){return rt({...eas(e),enabled:r,subscribed:r}).data??null}function tas(e){return/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")}function ras(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:`${_d(e,d)}${p?`&${p}`:""}${o}`}}function nas(e){if(!e.startsWith("---"))return e;const r=e.indexOf(` ---`,3);return r===-1?e:e.slice(r+4).replace(/^\r?\n/,"")}const AG="orx:files-tree-width",TG="orx:artifacts-collapsed:",RG=180,MG=320,sas=8,oas=280;function aas(){try{const e=Number(localStorage.getItem(AG));if(Number.isFinite(e)&&e>=RG&&e<=MG)return e}catch{}return oas}function ias(e){try{const r=localStorage.getItem(`${TG}${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 r0(e,r){for(const t of e){if(t.path===r)return t;if(t.isDir&&r.startsWith(t.path+"/")){const n=r0(t.children??[],r);if(n)return n}}return null}function OG({projectId:e,folder:r,markdown:t,entries:n}){const s=A.useRef(n);s.current=n;const o=A.useMemo(()=>{const a=i=>{if(tas(i))return i;const c=ras(e,r,i);if(!c)return null;const _=r0(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?l.jsx("a",{..._,href:f,...d?{}:{target:"_blank",rel:"noopener noreferrer"},children:c}):l.jsx("span",{children:c})},img:({src:i,alt:c})=>{if(!i||typeof i!="string")return null;const _=a(i);return _?l.jsxs("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"artifact-img",children:[l.jsx("img",{src:_,alt:c??"",loading:"lazy"}),c&&l.jsx("span",{className:"artifact-img-caption",children:c})]}):null},...LU}},[e,r]);return l.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:l.jsx(XQn,{remarkPlugins:[zU,[EU,$U]],rehypePlugins:[rU],components:o,children:AU(nas(t))})})}function cas(e){return e.presentation==="text"&&nG(e.name)?"markdown":zG(e.presentation)??(e.presentation==="text"||e.presentation==="unknown"?"text":"download")}function las(e,r,t,n){var _;const s=t==="markdown"||t==="text"&&r.size<=ZI,o=H6(e,r.path),a=rt({...o,enabled:s,subscribed:s}),i=A.useRef({projectId:e,path:r.path,modifiedAt:r.modifiedAt,size:r.size,version:n});A.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)&&Qe.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?y3e():null),wantsText:s}}function uas({projectId:e,entry:r,onDelete:t,artifactEntries:n}){const s=cas(r),o=NG(_d(e,r.path)),{text:a,binary:i,truncated:c,error:_,wantsText:d}=las(e,r,s,o),[f,p]=A.useState(!1),[m,w]=A.useState(null),y=s==="markdown",v=r.path.split("/").slice(0,-1).join("/"),x=`${_d(e,r.path)}&v=${encodeURIComponent(o??`${r.modifiedAt}:${r.size}`)}`;let k;return s==="image"||s==="audio"||s==="video"||s==="pdf"?k=l.jsx(ky.Provider,{value:m,children:l.jsx(jj,{kind:s,url:x,name:r.name})}):s==="download"||!d||i?k=l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[s==="download"||i?e3e():Qje()," ",l.jsx("a",{href:x,...s==="download"||i?{download:r.name}:{target:"_blank",rel:"noopener noreferrer"},children:s==="download"||i?TD():A3e()})]}):_?k=l.jsxs("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:[p5e()," ",Ae(_)]}):a===null?k=l.jsxs(ws,{children:[l.jsx(Ot,{})," ",mD()]}):y&&!f?k=l.jsx(OG,{projectId:e,folder:v,markdown:a,entries:n}):k=l.jsx(CG,{text:a,path:r.path}),l.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:[l.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:[l.jsx(gd,{name:r.name}),l.jsx("span",{className:"fpreview-path flex-1 min-w-0 truncate text-sm text-subtext","data-tip":Ae(r.path),children:r.name}),l.jsxs("span",{dir:"auto",className:"fpreview-date text-xs text-muted whitespace-nowrap shrink-0 @max-xl:hidden",children:[uje()," ",new Date(r.modifiedAt).toLocaleString(E(),{dateStyle:"medium",timeStyle:"short"})]}),l.jsx("div",{ref:w,className:"contents"}),(s==="text"||s==="download")&&l.jsx("span",{className:"fpreview-size text-xs text-muted whitespace-nowrap shrink-0",children:su(r.size)}),y&&l.jsx(jt,{size:"small",active:f,"data-tip":f?Ib():Nh(),"data-tip-align":"end","aria-label":f?Ib():Nh(),onClick:()=>p(b=>!b),children:l.jsx(l5,{size:13})}),l.jsx(Rp,{size:"small",href:x,target:"_blank",rel:"noopener noreferrer","data-tip":bE(),"data-tip-align":"end","aria-label":bE(),children:l.jsx(R_,{size:13})}),l.jsx(jt,{size:"small","data-tip":vE(),"data-tip-align":"end","aria-label":vE(),onClick:()=>{window.confirm(pS({path:Ae(r.path)}))&&t(r.path)},children:l.jsx(G_,{size:13})})]}),l.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 ${y&&!f?"doc":""}`,children:[k,c&&l.jsx("div",{className:"file-view-note py-2.5 px-4 text-sm text-muted",children:S5e()})]})]})}function $G({entries:e,depth:r,collapsed:t,selected:n,onToggle:s,onSelect:o,onOpenFile:a,onDelete:i,renamingPath:c,onContextMenu:_,onRename:d,onCancelRename:f}){return l.jsx("div",{className:"flex w-full max-w-full min-w-0 flex-col items-stretch",children:e.map(p=>{var w;const m={paddingInlineStart:8+Math.min(r,sas)*14};if(p.isDir){const y=!t.has(p.path);return l.jsxs("div",{className:"min-w-0 max-w-full",children:[l.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:[l.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":y?p4e({name:Ae(p.name)}):U4e({name:Ae(p.name)}),onClick:v=>{v.stopPropagation(),s(p.path)},children:l.jsx(_o,{size:13,className:y?"open":""})}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p.name}),l.jsx(jt,{size:"small",className:"ft-row-delete opacity-35 focus-visible:opacity-100","data-tip":o5e(),"data-tip-align":"end","aria-label":O4e({name:Ae(p.name)}),onClick:v=>{v.stopPropagation(),window.confirm(pS({path:Ae(p.path)}))&&i(p.path)},children:l.jsx(G_,{size:12})})]}),y&&(((w=p.children)==null?void 0:w.length)??0)>0&&l.jsx($G,{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?l.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:[l.jsx(gd,{name:p.name}),l.jsx(wG,{name:p.name,onCommit:y=>d(p.path,y),onCancel:f})]},p.path):l.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:wZ({path:Ae(p.path)}),"aria-keyshortcuts":"Space Enter","aria-pressed":n===p.path,onClick:()=>o(p.path),onDoubleClick:()=>a(p.path),onContextMenu:y=>{y.preventDefault(),o(p.path),_(y,p.path)},onAuxClick:y=>{y.button===1&&(y.preventDefault(),o(p.path),a(p.path))},onKeyDown:y=>{if(y.key==="ContextMenu"||y.shiftKey&&y.key==="F10"){y.preventDefault(),o(p.path),_(y,p.path);return}if(y.key===" "){y.preventDefault(),y.stopPropagation(),o(p.path);return}y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),o(p.path),a(p.path))},children:[l.jsx(gd,{name:p.name}),l.jsx("span",{className:"file-tree-name flex-1 min-w-0 overflow-hidden text-ellipsis whitespace-nowrap",children:p.name})]},p.path)})})}function _as({project:e,artifacts:r,onOpenFile:t,canRenameFile:n}){const[s,o]=A.useState(null),[a,i]=A.useState(()=>ias(e.id)),[c,_]=A.useState(aas),[d,f]=A.useState(null),[p,m]=A.useState(null),w=A.useRef(null);A.useEffect(()=>{try{localStorage.setItem(`${TG}${e.id}`,JSON.stringify([...a]))}catch{}},[e.id,a]);const y=N=>{var L;N.preventDefault(),N.currentTarget.setPointerCapture(N.pointerId);const T=(L=w.current)==null?void 0:L.getBoundingClientRect(),C=document.body.style.userSelect;document.body.style.userSelect="none";const R=I=>{const P=Math.round(I.clientX-((T==null?void 0:T.left)??0)),B=Math.min(Math.max(P,RG),MG);_(B);try{localStorage.setItem(AG,String(B))}catch{}},$=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",$),window.removeEventListener("pointercancel",$),document.body.style.userSelect=C};window.addEventListener("pointermove",R),window.addEventListener("pointerup",$),window.addEventListener("pointercancel",$)};A.useEffect(()=>{if(!s||!r)return;const N=r0(r.entries,s);(!N||N.isDir)&&o(null)},[s,r]);const v=N=>i(T=>{const C=new Set(T);return C.has(N)?C.delete(N):C.add(N),C}),x=N=>{(s===N||s!=null&&s.startsWith(N+"/"))&&o(null),IMn(e.id,N).catch(()=>{})},k=async(N,T)=>{try{await PMn(e.id,N,T),T.action==="rename"&&s===N&&o(null)}catch(C){Qt(C instanceof Error?C.message:String(C),"error")}},b=N=>{r&&xG(r.dir,N)};if(!r)return l.jsx("div",{className:"files-tab h-full min-h-0 flex bg-background",children:l.jsxs(ws,{className:"p-5",children:[l.jsx(Ot,{})," ",eje()]})});const S=N=>l.jsx($G,{entries:N,depth:0,collapsed:a,selected:s,onToggle:v,onSelect:o,onOpenFile:t,onDelete:x,renamingPath:p,onContextMenu:(T,C)=>{f(kG(T,C))},onRename:(T,C)=>{m(null),k(T,{action:"rename",newName:C})},onCancelRename:()=>m(null)}),z=s?r0(r.entries,s):null;return r.entries.length===0?l.jsx(XC,{icon:QS,title:yje(),description:Pje()}):l.jsxs("div",{className:"files-tab h-full min-h-0 flex bg-background @container",children:[l.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:w,style:{width:c},children:[l.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:y}),l.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&&l.jsx("p",{className:"files-truncated m-0 py-2 px-3.5 text-sm text-muted",children:$5e()})]})]}),z?l.jsx(uas,{projectId:e.id,entry:z,onDelete:x,artifactEntries:r.entries},z.path):l.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:[l.jsx(hPn,{size:22,strokeWidth:1.5}),l.jsx("span",{children:B3e()})]}),d&&l.jsx(jG,{target:d,onOpen:()=>t(d.path),onRename:n(d.path)?()=>m(d.path):void 0,onDuplicate:()=>void k(d.path,{action:"duplicate"}),onCopyPath:()=>b(d.path),onDelete:()=>{window.confirm(pS({path:Ae(d.path)}))&&x(d.path)},onClose:()=>f(null)})]})}const LG=20*1024*1024,DG="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",IG="mt-0 mx-0 mb-3 text-sm leading-relaxed text-text",fas="flex items-start gap-3 py-2.5 border-t border-t-border first:border-t-0",das="text-sm font-normal text-text",has="mt-1 mb-0 text-sm leading-relaxed text-text";function PG(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 pas(e){const r=e.toLowerCase();return r.endsWith(".md")||r.endsWith(".markdown")||r.endsWith(".zip")}function BG({accept:e,busy:r,prompt:t,onFile:n}){const[s,o]=A.useState(!1),a=A.useRef(null);return l.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:[l.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?l.jsxs(l.Fragment,{children:[l.jsx(Ot,{}),l.jsx("span",{children:Gvn()})]}):l.jsxs(l.Fragment,{children:[l.jsx(WPn,{size:20,strokeWidth:1.5}),l.jsx("span",{children:t})]})]})}function FG({bytes:e,updatedAt:r}){return l.jsxs("div",{className:"shrink-0 text-end whitespace-nowrap pt-0.5 text-xs text-subtext",children:[su(e),r>0&&l.jsxs("span",{className:"text-muted",children:[" · ",Ti(r)]})]})}function mas({skill:e,onError:r}){const t=vr({mutationFn:hOn}),n=t.isPending;return l.jsxs("div",{className:"flex items-center gap-2 py-1 border-t border-t-border first:border-t-0",children:[l.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[l.jsx("span",{className:das,children:e.name}),e.origin&&l.jsx(nr,{size:"small",children:e.origin})]}),l.jsx(FG,{bytes:e.bytes,updatedAt:e.updatedAt}),l.jsx(jt,{size:"small","data-tip":e.origin?n0n():b1n(),"data-tip-align":"end","aria-label":e.origin?k0n({name:Ae(e.name)}):wmn({name:Ae(e.name)}),disabled:n,onClick:()=>{window.confirm(e.origin?d0n({name:Ae(e.name)}):fmn({name:Ae(e.name)}))&&t.mutateAsync(e.name).catch(s=>{r(s instanceof Error?s.message:String(s))})},children:l.jsx(G_,{size:13})})]})}function gas({template:e,onError:r}){const t=vr({mutationFn:_On}),n=t.isPending,s=e.supportFiles.length;return l.jsxs("div",{className:fas,children:[l.jsxs("div",{className:"flex-1 min-w-0",children:[l.jsx("span",{className:"text-base font-medium text-text",children:e.name}),l.jsxs("p",{className:has,children:[e.entry,s>0&&(s===1?Dgn():M0n({count:hr(s)}))]})]}),l.jsx(FG,{bytes:e.bytes,updatedAt:e.updatedAt}),l.jsx(jt,{"data-tip":N1n(),"data-tip-align":"end","aria-label":Hmn({name:Ae(e.name)}),disabled:n,onClick:()=>{window.confirm(Rmn({name:Ae(e.name)}))&&t.mutateAsync(e.name).catch(o=>{r(o instanceof Error?o.message:String(o))})},children:l.jsx(G_,{size:13})})]})}function vas(){var k;const e=vr({mutationFn:dOn}),r=rt(c$n()),t=r.data,n=A.useRef(null),[s,o]=A.useState(!1),[a,i]=A.useState(!1),c=A.useCallback(()=>{const b=n.current;o(!!b&&b.scrollTop>1),i(!!b&&b.scrollHeight-b.scrollTop-b.clientHeight>1)},[]);A.useLayoutEffect(()=>{c();const b=n.current;if(!b)return;const S=new ResizeObserver(c);return S.observe(b),()=>S.disconnect()},[t,c]);const _=r.isFetching,d=(k=r.error)==null?void 0:k.message,[f,p]=A.useState(!1),[m,w]=A.useState(null),y=()=>{r.refetch()},v=A.useRef(!1),x=A.useCallback(async b=>{if(!v.current){if(w(null),!pas(b.name)){w(_bn());return}if(b.size>LG){w(zI());return}v.current=!0,p(!0);try{await e.mutateAsync({filename:b.name,contentBase64:await PG(b)})}catch(S){w(S instanceof Error?S.message:String(S))}finally{v.current=!1,p(!1)}}},[]);return l.jsxs("section",{className:DG,children:[l.jsxs("div",{className:"flex items-baseline gap-2.5",children:[l.jsx("h3",{children:$vn()}),l.jsxs(Se,{className:"ms-auto",size:"small",onClick:y,disabled:_,children:[l.jsx(Li,{size:12,className:_?"animate-[spin_0.9s_linear_infinite]":""})," ",O0()]})]}),l.jsx("p",{className:IG,children:Zmn()}),l.jsx(BG,{accept:".md,.markdown,.zip",busy:f,prompt:l.jsxs(l.Fragment,{children:[l.jsx("span",{children:cgn()}),l.jsx("span",{className:"block ps-4 mt-1 text-text",children:rmn()})]}),onFile:b=>void x(b)}),m&&l.jsx("div",{role:"alert",className:"mt-2.5 text-base text-accent-red whitespace-pre-wrap",children:m}),d&&l.jsxs("div",{role:"alert",className:"pt-3 text-base text-accent-red",children:[q0n()," ",d]}),t===void 0?d?null:l.jsxs("div",{className:"flex items-center gap-2 pt-3 text-sm text-subtext",children:[l.jsx(Ot,{})," ",Q1n()]}):t.length===0?l.jsx("div",{className:"pt-3 text-sm text-subtext",children:pvn()}):l.jsxs("div",{className:"relative mt-1",children:[l.jsx("div",{ref:n,onScroll:c,className:"flex flex-col max-h-120 overflow-y-auto overscroll-contain",children:t.map(b=>l.jsx(mas,{skill:b,onError:w},b.name))}),s&&l.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&&l.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 bas(){var d;const e=vr({mutationFn:uOn}),r=rt(i$n()),t=r.data,n=(d=r.error)==null?void 0:d.message,[s,o]=A.useState(!1),[a,i]=A.useState(null),c=A.useRef(!1),_=A.useCallback(async f=>{if(c.current)return;i(null);const p=f.name.toLowerCase();if(!p.endsWith(".tex")&&!p.endsWith(".zip")){i(xbn());return}if(f.size>LG){i(zI());return}c.current=!0,o(!0);try{await e.mutateAsync({filename:f.name,contentBase64:await PG(f)})}catch(m){i(m instanceof Error?m.message:String(m))}finally{c.current=!1,o(!1)}},[]);return l.jsxs("section",{className:DG,children:[l.jsx("h3",{children:P1n()}),l.jsx("p",{className:IG,children:tbn()}),l.jsx(BG,{accept:".tex,.zip",busy:s,prompt:l.jsxs(l.Fragment,{children:[l.jsx("span",{children:vgn()}),l.jsx("span",{className:"block ps-4 mt-1 text-text",children:m3n()})]}),onFile:f=>void _(f)}),a&&l.jsx("div",{role:"alert",className:"mt-2.5 text-base text-accent-red whitespace-pre-wrap",children:a}),n&&l.jsxs("div",{role:"alert",className:"pt-3 text-base text-accent-red",children:[J0n()," ",n]}),t===void 0?n?null:l.jsxs("div",{className:"flex items-center gap-2 pt-3 text-sm text-subtext",children:[l.jsx(Ot,{})," ",ovn()]}):t.length===0?l.jsx("div",{className:"pt-3 text-sm text-subtext",children:Svn()}):l.jsx("div",{className:"flex flex-col mt-1",children:t.map(f=>l.jsx(gas,{template:f,onError:i},f.name))})]})}function yas(){return l.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:[l.jsx("h1",{children:l1n()}),l.jsx("p",{className:"mt-0 mx-0 mb-5 text-base leading-relaxed text-text",children:Kgn()}),l.jsx(vas,{}),l.jsx(bas,{})]})}const xas="italic [&_.tab-label_>_span]:pe-1 [&_.tab-label::after]:pe-1";function Ic({active:e,label:r,icon:t,shimmer:n=!1,preview:s=!1,onSelect:o,onPromote:a,onClose:i}){return l.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?xas:""}`,onClick:o,onDoubleClick:a,title:s?a3n({label:r}):r,"aria-label":s?X4n({label:r}):r,children:[t,l.jsx("span",{className:"tab-label","data-label":r,children:l.jsx("span",{className:n?"tool-running-shimmer":"",children:r})}),l.jsx("span",{role:"button",className:"tab-close",title:Ret(),onPointerDown:c=>c.preventDefault(),onClick:c=>{c.stopPropagation(),i()},children:l.jsx(fn,{size:14})})]})}function was({activeKey:e,children:r}){const t=A.useRef(null),n=A.useRef(null),[s,o]=A.useState(!1),[a,i]=A.useState(!1),c=A.useRef(!1),_=A.useRef(void 0),d=A.useRef(null),f=A.useRef(!0),p=A.useCallback(()=>{const y=t.current;if(!y)return;const v=y.clientWidth/y.scrollWidth;o(v<1);const x=n.current;x&&(x.style.width=`${y.clientWidth*v}px`,x.style.transform=`translateX(${y.scrollLeft*v}px)`)},[]),m=A.useCallback(()=>{const y=t.current,v=y==null?void 0:y.querySelector(".tab.active");!y||!v||(v.offsetLefty.scrollLeft+y.clientWidth&&(y.scrollLeft=v.offsetLeft+v.offsetWidth-y.clientWidth))},[]),w=A.useCallback(()=>{i(!0),window.clearTimeout(_.current),_.current=window.setTimeout(()=>{c.current||i(!1)},1e3)},[]);return A.useEffect(()=>()=>window.clearTimeout(_.current),[]),A.useEffect(()=>{const y=t.current,v=y==null?void 0:y.firstElementChild;if(!y||!v)return;const x=new ResizeObserver(p),k=new ResizeObserver(()=>{f.current&&m(),p()});return x.observe(y),k.observe(v),()=>{x.disconnect(),k.disconnect()}},[p,m]),A.useEffect(()=>{if(s){p(),i(c.current);return}d.current=null,window.clearTimeout(_.current),i(!1)},[s,p]),A.useEffect(()=>{f.current=!0,m()},[e,m]),l.jsxs("div",{className:"relative flex-1 min-w-0",onPointerEnter:()=>{c.current=!0,window.clearTimeout(_.current),i(!0)},onPointerLeave:()=>{c.current=!1,w()},children:[l.jsx("div",{ref:t,className:"tab-strip relative overflow-x-auto overflow-y-hidden [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",onScroll:()=>{p(),w()},onWheel:y=>{if(y.ctrlKey||(f.current=!1,Math.abs(y.deltaY)<=Math.abs(y.deltaX)))return;const v=y.currentTarget;v.scrollLeft+=y.deltaY*(y.deltaMode===1?16:y.deltaMode===2?v.clientWidth:1)},children:l.jsx("div",{className:"flex items-end w-max",children:r})}),s&&l.jsx("div",{ref:n,"aria-hidden":"true",className:`absolute start-0 -bottom-px flex items-end h-0.5 ${a?"":"pointer-events-none"}`,onPointerDown:y=>{const v=t.current;v&&(y.preventDefault(),f.current=!1,y.currentTarget.setPointerCapture(y.pointerId),d.current={x:y.clientX,scrollLeft:v.scrollLeft})},onPointerMove:y=>{const v=t.current;if(!v||!d.current)return;const x=v.scrollWidth/v.clientWidth;v.scrollLeft=d.current.scrollLeft+(y.clientX-d.current.x)*x},onLostPointerCapture:()=>{d.current=null},children:l.jsx("div",{className:`h-0.5 w-full rounded-full bg-muted transition-opacity duration-300 motion-reduce:transition-none ${a?"opacity-100":"opacity-0"}`})})]})}const bO=["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 kas({owner:e,repo:r,branch:t}){return!e||!r?l.jsx("span",{className:bO,children:l.jsx("code",{children:t})}):l.jsxs("a",{className:bO,href:Yy(e,r,t),target:"_blank",rel:"noopener noreferrer",title:x3({name:Ae(t)}),children:[l.jsx("code",{children:t}),l.jsx(eC,{size:12})]})}function jas(e){const r=xa(e);return r==="done"||r==="failed"||r==="cancelled"||r==="lost"?r:"running"}const Sas=/^([A-Z][0-9]{0,2}[a-z]?)(?:\s*[:–—-]\s*|\s+)(?=\S)/;function Cas(e){const r=(e.title||e.description||e.slug).split(/\r?\n/)[0].trim(),t=r.match(Sas),n=t?r.slice(t[0].length):r;return{code:t?t[1]:null,label:n.charAt(0).toUpperCase()+n.slice(1)}}function jy(e,r){return e.createdAt-r.createdAt||e.id.localeCompare(r.id)}function HG(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?jas(i):"none",...Cas(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(jy);return n}function zas(e){const r=[];for(let t=e.parent;t;t=t.parent)r.unshift(t);return r}function Eas(e,r=22){return e.code?e.code:e.label.length>r?e.label.slice(0,r-1).trimEnd()+"…":e.label}function Nas(e,r={}){const t=new Set(e.nodes.map(m=>m.id)),n=m=>m.children.filter(w=>t.has(w.id)),s=new Map,o=new Map,a=m=>{const w=s.get(m.id);if(w!==void 0)return w;const y=1+n(m).reduce((v,x)=>v+a(x),0);return s.set(m.id,y),y},i=m=>[...m].sort((w,y)=>c(y)-c(w)||a(y)-a(w)||jy(y,w))[0],c=m=>{const w=o.get(m.id);if(w!==void 0)return w;const y=n(m);let v=1;if(y.length){const x=i(y),k=y.filter(b=>b!==x);v=Math.max(c(x),1+Math.max(0,...k.map(c)))}return o.set(m.id,v),v},_=m=>[m,...n(m).flatMap(_)],d=[],f=(m,w,y)=>{var k;if(y&&r.collapseFinished&&!((k=r.expanded)!=null&&k.has(m.id))){const b=_(m);if(b.length>=4&&b.every(S=>S.status==="done")&&!b.some(S=>{var z;return(z=r.keep)==null?void 0:z.has(S.id)})){d.push({kind:"collapsed",head:m,lane:w,hidden:b});return}}d.push({kind:"experiment",node:m,lane:w});const v=n(m);if(!v.length)return;const x=i(v);for(const b of v)b!==x&&f(b,w+1,!0);f(x,w,!1)},p=e.nodes.filter(m=>!m.parent||!t.has(m.parent.id));for(const m of p.sort(jy))m.parent&&d.push({kind:"lead-in",node:m,from:m.parent,lane:0}),f(m,0,!1);return d}function Aas(e,r=!1){const t=[...e.nodes].sort(jy);return r&&t.reverse(),t.map(n=>({kind:"experiment",node:n,lane:0}))}function qG(e){return e.reduce((r,t)=>Math.max(r,t.lane+1),0)}function Tas(e){const r=Jy(e.backend);return r?[r,nP(e.backend)].filter(Boolean).join(" · "):"—"}function Ras(e){var t;const r=(t=e.backend)==null?void 0:t.jobId;return typeof r=="string"||typeof r=="number"?String(r):"—"}const Sj=14,UG=15,Sy=e=>UG+Sj/2+e*Sj,yO={done:RS,failed:AI,cancelled:NI,lost:TI,running:RI,none:R8t},Mas={done:"var(--accent-green)",failed:"var(--accent-red)",cancelled:"var(--muted)",lost:"var(--muted)",running:"var(--accent-teal)",none:"var(--muted)"},Mv="var(--lineage)",Oas=.48,A4=1;function GG({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 l.jsx("circle",{cx:r,cy:t,r:n,fill:s});if(e==="failed"){const _=n*1.18;return l.jsx("path",{d:`M${r} ${t-_}L${r+_} ${t}L${r} ${t+_}L${r-_} ${t}Z`,fill:s})}const c=l.jsx("circle",{cx:r,cy:t,r:i,fill:o,stroke:s,strokeWidth:a});if(e==="running")return l.jsxs("g",{children:[c,l.jsx("path",{d:`M${r} ${t-i}A${i} ${i} 0 0 1 ${r} ${t+i}Z`,fill:s})]});if(e==="cancelled"||e==="lost"){const _=(n-a)*.7;return l.jsxs("g",{children:[c,l.jsx("line",{x1:r-_,y1:t+_,x2:r+_,y2:t-_,stroke:s,strokeWidth:a})]})}return c}function $as({status:e,word:r=!0,size:t=12}){return l.jsxs("span",{className:"inline-flex items-center gap-1.5 whitespace-nowrap text-sm text-text",children:[l.jsx("svg",{width:t,height:t,viewBox:`0 0 ${t} ${t}`,className:"shrink-0","aria-hidden":"true",children:l.jsx(GG,{status:e,cx:t/2,cy:t/2,r:t*.33,color:Mas[e]})}),r?yO[e]():l.jsx("span",{className:"sr-only",children:yO[e]()})]})}function Las(e){return new Intl.DateTimeFormat(E(),{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(e)}function Das({ms:e}){return l.jsx("span",{className:"whitespace-nowrap text-xs tabular-nums text-subtext",title:Las(e),children:Ti(e)})}function Ias(e,r){const t=Sy(e.row.lane),n=Sy(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 xO(e){return e.kind==="collapsed"?e.head:e.node}function Pas({placed:e,height:r,path:t,selectedId:n}){const s=new Map;for(const c of e)c.row.kind!=="lead-in"&&s.set(xO(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${Sy(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 _=xO(c.row),d=_.parent?s.get(_.parent.id):void 0;d&&o.push({d:Ias(d,c),hot:t.has(_.id)&&t.has(_.parent.id),dotted:!1})}const a=UG+Sj*qG(e.map(c=>c.row))+8,i=(c,_)=>l.jsx("path",{d:c.d,fill:"none",stroke:c.hot?"var(--primary)":Mv,strokeOpacity:c.hot?1:Oas,strokeWidth:c.hot?2:1.5,strokeLinecap:"round",strokeDasharray:c.dotted?"1.5 3.5":void 0},_);return l.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=Sy(c.row.lane);if(c.row.kind==="collapsed")return l.jsxs("g",{children:[l.jsx("circle",{cx:d,cy:c.y+2.5,r:3.5,fill:"var(--base)",stroke:Mv,strokeOpacity:A4,strokeWidth:1.25}),l.jsx("circle",{cx:d,cy:c.y-1.5,r:3.5,fill:"var(--base)",stroke:Mv,strokeOpacity:A4,strokeWidth:1.25})]},_);const f=c.row.node,p=f.id===n,m=t.has(f.id),w=m?"var(--primary)":Mv;return l.jsxs("g",{opacity:m?1:A4,children:[!f.parent&&!f.missingParentId&&l.jsx("circle",{cx:d,cy:c.y,r:7,fill:"none",stroke:w,strokeWidth:1,opacity:.7}),p&&l.jsx("circle",{cx:d,cy:c.y,r:8.5,fill:"var(--primary)",fillOpacity:.18}),l.jsx(GG,{status:f.status,cx:d,cy:c.y,r:p?4.6:4,color:w,background:p?"var(--highlight)":"var(--base)"})]},_)})]})}function T4({node:e,current:r,onSelect:t}){return l.jsxs("button",{type:"button",disabled:r,"aria-current":r?"true":void 0,...dn(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:[l.jsx($as,{status:e.status,word:!1,size:11}),e.code&&l.jsx("span",{className:"w-7 shrink-0 font-mono text-xs text-subtext",children:e.code}),l.jsx("span",{className:`min-w-0 flex-1 truncate text-sm text-text ${r?"font-medium":""}`,children:e.label}),l.jsx(Das,{ms:e.createdAt})]})}function Bas({node:e,onSelect:r}){const[t,n]=A.useState(!1);A.useEffect(()=>n(!1),[e.id]);const s=zas(e),o=s.slice(0,Math.max(0,s.length-4)),a=t?s:s.slice(-4);return l.jsxs("section",{className:"flex flex-col gap-2",children:[l.jsx("h2",{className:"m-0 text-sm font-semibold text-text",children:ID()}),l.jsxs("div",{className:"flex flex-col",children:[s.length>0&&l.jsx("div",{className:"mb-1 text-sm text-subtext",children:J7t()}),o.length>0&&l.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:[l.jsx(_o,{size:11,className:`shrink-0 ${t?"rotate-90":""}`}),l.jsx("span",{className:"truncate",children:t?Vy():Nzt({count:hr(o.length),steps:o.map(i=>Eas(i,18)).join(" → ")})})]}),a.map(i=>l.jsx(T4,{node:i,onSelect:r},i.id)),l.jsx(T4,{node:e,current:!0,onSelect:r}),e.children.length>0&&l.jsxs("div",{className:"mt-3 flex flex-col gap-1 pt-3",children:[l.jsx("div",{className:"text-sm text-subtext",children:lzt()}),e.children.map(i=>l.jsx(T4,{node:i,onSelect:r},i.id))]})]})]})}const R4=["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(" "),wO=["experiment-overview-command block mt-[13px] text-text text-sm","wrap-anywhere"].join(" ");function kO(e){return new Date(e).toLocaleString(E(),{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}function jO(e,r){return Mg((e.endedAt??r)-e.createdAt)}function Fas({experiment:e,lineageNode:r,onOpenExperiment:t,parentExperiment:n,project:s,runs:o,onOpenLogs:a,onOpenTrackio:i,onOpenCode:c,onOpenDiff:_}){const d=o[0]??null,f=HI(o),p=o.some(x=>x.status==="running"||x.status==="starting"),[m,w]=A.useState(()=>Date.now()),y=DS(e.projectId,p).data,v=d!==null&&qb(y,d.id)!==null;return A.useEffect(()=>{if(!p)return;w(Date.now());const x=window.setInterval(()=>w(Date.now()),1e3);return()=>window.clearInterval(x)},[p]),l.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:l.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:[l.jsxs("header",{className:"experiment-overview-head flex items-start justify-between gap-6",children:[l.jsxs("div",{className:"experiment-overview-heading min-w-0",children:[l.jsx("h1",{children:e.title||e.slug}),l.jsx("div",{className:"experiment-overview-slug mt-[5px] text-muted text-sm",children:e.slug})]}),l.jsx(cu,{status:d?xa(d):"idle"})]}),l.jsxs("div",{className:"experiment-overview-actions flex gap-[7px] mt-4.5 [@media((max-width:_720px))]:flex-wrap",children:[d&&l.jsxs(Se,{...dn(x=>a(d.id,x)),children:[l.jsx(fc,{size:15}),AD()]}),d&&v&&l.jsxs(Se,{title:$b(),...dn(x=>i(d.id,x)),children:[l.jsx(tx,{size:15}),bS()]}),l.jsxs(Se,{...dn(c),children:[l.jsx(sx,{size:15}),Sdt()]}),l.jsx(va,{interactive:!0,content:xht(),children:l.jsxs(Se,{disabled:!n,...dn(_),children:[l.jsx(PIn,{size:15}),_ht()]})})]}),e.description&&l.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:[l.jsx("h2",{children:tht()}),l.jsx(dc,{text:e.description})]}),l.jsxs("section",{className:R4,children:[l.jsx("h2",{children:d?pdt():tmt()}),d&&l.jsxs(l.Fragment,{children:[l.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:[l.jsx(cu,{status:xa(d)}),l.jsx(tC,{backend:d.backend}),l.jsxs("span",{title:Lpt(),children:[l.jsx(WDn,{size:13}),kO(d.createdAt)]}),l.jsxs("span",{title:Tht(),children:[l.jsx(oIn,{size:13}),jO(d,m)]}),d.commitSha&&l.jsxs("span",{title:$dt(),children:[l.jsx(DIn,{size:14}),l.jsx("code",{children:d.commitSha.slice(0,7)})]}),d.exitCode!==null&&d.exitCode!==void 0&&d.exitCode!==0&&l.jsxs("span",{children:[Fht()," ",d.exitCode]})]}),d.command&&l.jsxs("code",{className:wO,children:["$ ",d.command]}),f&&l.jsx("p",{className:"experiment-overview-monitoring mt-4 text-accent-amber text-sm wrap-anywhere",children:f}),d.resultMarkdown&&l.jsx("div",{className:`experiment-overview-result mt-4 [&.failed]:text-accent-red ${d.status==="failed"?"failed":""}`,children:l.jsx(dc,{text:d.resultMarkdown})})]})]}),o.length>0&&l.jsxs("section",{className:`${R4} @container`,children:[l.jsx("h2",{children:Cpt()}),l.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 @max-lg:[&_button]:grid-cols-[48px_minmax(0,_1fr)_40px_16px] @max-lg:[&_button_>_:nth-child(3)]:hidden",children:o.map((x,k)=>l.jsxs("button",{...dn(b=>a(x.id,b)),children:[l.jsxs("span",{className:"experiment-run-number text-xs font-medium",children:[mpt()," ",o.length-k]}),l.jsx(cu,{status:xa(x),className:"min-w-0"}),l.jsx("span",{children:Ti(x.createdAt)}),l.jsx("span",{children:jO(x,m)}),l.jsx(fc,{size:13})]},x.id))})]}),r&&l.jsx("div",{className:"mt-5.5 border-t border-border-variant pt-4.5",children:l.jsx(Bas,{node:r,onSelect:t})}),l.jsxs("section",{className:R4,children:[l.jsx("h2",{children:"Git"}),l.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:[l.jsx(kas,{owner:s.githubEnabled?s.githubOwner:"",repo:s.githubEnabled?s.githubRepo:"",branch:e.branchName}),n&&l.jsxs("span",{children:[Yht()," ",l.jsx("code",{children:n.slug})]}),l.jsxs("span",{title:kO(e.createdAt),children:[Gdt()," ",Ti(e.createdAt)]})]}),e.runCommand!==(d==null?void 0:d.command)&&l.jsxs("code",{className:wO,children:["$ ",e.runCommand]})]})]})})}function SO(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}=cx(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 SRn(e,a);if(o)return;if(f.dataBase64&&n.write(SO(f.dataBase64)),a=f.nextOffset,f.eof)break}}catch{}finally{i=!1,c&&!o&&(c=!1,_())}}const d=f$n(e,f=>{if(o)return;const p=SO(f.dataBase64);!i&&f.offset===a?(n.write(p),a+=p.length):f.offset+p.length>a&&_()});return _(),()=>{o=!0,d(),s()}},[e]),l.jsx("div",{ref:r,className:"h-full w-full"})}function qas({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=HG(r,s).find(m=>m.id===e.id);return l.jsx(Fas,{lineageNode:p??null,onOpenExperiment:d,experiment:e,parentExperiment:i,project:t,runs:f,onOpenLogs:(m,w)=>c("terminal",m,w),onOpenTrackio:(m,w)=>c("trackio",m,w),onOpenCode:m=>_("files",m),onOpenDiff:m=>_("changes",m)})}return l.jsx(Uas,{experiment:e,expRuns:f,view:n,selectedRunId:o,onSelectRun:a,onOpenView:c})}function Uas({experiment:e,expRuns:r,view:t,selectedRunId:n,onSelectRun:s,onOpenView:o}){var T;const[a,i]=A.useState(null),[c,_]=A.useState(null),[d,f]=A.useState(!1),p=A.useRef(null),m=n?r.find(C=>C.id===n)??null:r[0]??null,w=(m==null?void 0:m.status)==="running"||(m==null?void 0:m.status)==="starting",y=U$n(),v=DS(e.projectId,w),x=v.data,k=m?qb(x,m.id):null,b=t==="trackio"&&m?qb(x,m.id,{theme:y}):null,S=!!(m&&w&&(m.cancelRequested||c===m.id)),z=C=>{const R=r.findIndex($=>$.id===C);return R===-1?r.length:r.length-R};A.useEffect(()=>{if(!d)return;const C=R=>{var $;($=p.current)!=null&&$.contains(R.target)||f(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[d]);async function N(){if(m){i(null),_(m.id);try{await UI(m.id)}catch(C){_(null),i(C instanceof Error?C.message:String(C))}}}return l.jsxs("div",{className:"term-view absolute inset-0 flex flex-col bg-background z-20",children:[l.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:[l.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}),l.jsx("span",{className:"flex-1"}),a&&l.jsx("span",{className:"error",role:"alert",children:a}),t==="trackio"?l.jsxs(l.Fragment,{children:[k&&l.jsx(T_,{size:"small",variant:"ghost",title:iE(),"aria-label":iE(),href:k,target:"_blank",rel:"noopener noreferrer",children:l.jsx(R_,{size:13})}),l.jsxs(Se,{size:"small",variant:"ghost",...dn(C=>o("terminal",m==null?void 0:m.id,C)),children:[l.jsx(ox,{size:13}),AD()]})]}):k&&l.jsxs(Se,{size:"small",variant:"ghost",title:$b(),...dn(C=>o("trackio",m==null?void 0:m.id,C)),children:[l.jsx(tx,{size:13}),bS()]}),w&&l.jsxs(Se,{size:"small",variant:"ghost",disabled:S,onClick:()=>void N(),children:[l.jsx(UP,{size:13}),S?rrt():ED()]}),r.length>0&&m&&l.jsxs("div",{className:"run-history relative shrink-0",ref:p,children:[l.jsxs(Se,{title:k_t(),"aria-expanded":d,onClick:()=>f(C=>!C),children:[l.jsxs("span",{children:[tN()," ",z(m.id)]}),l.jsx(cu,{status:S?"cancelling":xa(m)}),l.jsx(pc,{size:14,className:"run-picker-chev text-muted shrink-0"})]}),d&&l.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(C=>l.jsxs(pr,{className:"justify-start",active:C.id===(m==null?void 0:m.id),onClick:()=>{s(C.id),f(!1)},children:[l.jsxs("span",{className:"font-medium",children:[tN()," ",z(C.id)]}),l.jsx(cu,{status:xa(C)}),l.jsx("span",{className:"ms-auto text-xs text-muted",children:Ti(C.createdAt)})]},C.id))})]})]}),m&&l.jsxs("div",{className:"term-provenance","aria-label":d_t(),children:[l.jsxs("span",{children:[Iut()," ",l.jsx("code",{children:m.id})]}),l.jsxs("span",{children:[Eut()," ",l.jsx("code",{children:m.commitSha||bzt()})]}),l.jsxs("span",{children:[vut()," ",l.jsx("code",{children:Tas(m)})]}),l.jsxs("span",{children:[Vut()," ",l.jsx("code",{children:Ras(m)})]})]}),l.jsx("div",{className:`term-fill flex-1 min-h-0 ${t==="trackio"?"bg-background":"bg-terminal pt-1 pe-0 pb-1 ps-1.5"}`,children:b?l.jsx("iframe",{className:"block w-full h-full border-0",title:$b(),src:b,referrerPolicy:"no-referrer",sandbox:"allow-scripts allow-same-origin allow-popups allow-forms allow-downloads"},b):t==="trackio"?l.jsx("div",{className:"term-empty h-full flex items-center justify-center p-6 text-center text-sm text-muted",children:v.isPending?Ky():((T=v.error)==null?void 0:T.message)??M_t()}):m?l.jsx(Has,{runId:m.id},m.id):l.jsx("div",{className:"term-empty h-full flex items-center justify-center p-6 text-center text-sm text-muted",children:n?Ei():cut()})})]})}let Cj=!1;function CO(e){Cj=!0;try{return window.confirm(e)}finally{Cj=!1}}const zj=e=>e.replace(/\r\n/g,` `),zO=(e,r,t)=>{const n=zj(r);return{path:e,draft:n,baseline:n,version:t,crlf:r.includes(`\r `),conflict:null}},Kl=e=>e.draft!==e.baseline,Gas=(e,r)=>({...e,draft:r,conflict:r===e.baseline?null:e.conflict}),Was=e=>e.crlf?e.draft.replace(/\n/g,`\r diff --git a/ui/dist/index.html b/ui/dist/index.html index 648ac9c7b..c37764fd2 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 5324783e3..0b30e64c3 100644 --- a/ui/src/components/ChatPanel.tsx +++ b/ui/src/components/ChatPanel.tsx @@ -6478,7 +6478,7 @@ export function ChatPanel({ if (!event.currentTarget.contains(event.relatedTarget)) setFocusedSidebarRow(null); }} className={sidebarScrollable ? "absolute top-0 start-0 w-full" : "relative"} - style={{ height: sidebarRowHeight(row), transform: sidebarScrollable ? `translateY(${top}px)` : undefined }} + style={{ height: sidebarRowHeight(row), top: sidebarScrollable ? top : undefined }} > {row.kind === "project" ? (