@edspencer/paddock 0.83.0 → 0.83.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/server/dist/cli/busy.js +1 -1
- package/packages/server/dist/cli/exit-codes.js +1 -1
- package/packages/server/dist/cli/output.js +1 -1
- package/packages/server/dist/cli/service/index.d.ts +6 -1
- package/packages/server/dist/cli/service/index.js +7 -7
- package/packages/server/dist/cli/service/launchd.js +1 -1
- package/packages/server/dist/cli/service/logs.js +1 -1
- package/packages/server/dist/cli/service/manager.js +1 -1
- package/packages/server/dist/cli/service/path-env.js +1 -1
- package/packages/server/dist/cli/service/systemd.js +1 -1
- package/packages/server/dist/cli/update/health.js +1 -1
- package/packages/server/dist/cli/update/install-method.js +1 -1
- package/packages/server/dist/cli/update/lock.js +1 -1
- package/packages/server/dist/cli/update/package-manager.js +1 -1
- package/packages/server/dist/cli/update/registry.js +1 -1
- package/packages/server/dist/cli/update/semver.js +1 -1
- package/packages/server/dist/cli/update/update-check.js +1 -1
- package/packages/server/dist/cli/update/update.js +1 -1
- package/packages/server/dist/runtime-file.js +1 -1
- package/packages/server/package.json +1 -1
- package/packages/web/dist/assets/{DeleteProjectDialog-B07MKgv4.js → DeleteProjectDialog-BPwSkY3s.js} +1 -1
- package/packages/web/dist/assets/DiscoverPage-DVoF9Vil.js +2 -0
- package/packages/web/dist/assets/{DiscoverView-DpAAyBEf.js → DiscoverView-Bz4Rxg-V.js} +1 -1
- package/packages/web/dist/assets/{InstanceConfigPage-YX0I_jVA.js → InstanceConfigPage-CXHem0Ab.js} +1 -1
- package/packages/web/dist/assets/{MarkdownRenderer-C-CUuFhT.js → MarkdownRenderer-2vrOdDh7.js} +1 -1
- package/packages/web/dist/assets/{ProjectRedirect-qyXbTK56.js → ProjectRedirect-V77rycxm.js} +1 -1
- package/packages/web/dist/assets/{ProjectView-CguNOv8k.js → ProjectView-C1qr6nlt.js} +3 -3
- package/packages/web/dist/assets/{ProjectsGrid-CH2Lz2Hf.js → ProjectsGrid-Jq1LRFcs.js} +1 -1
- package/packages/web/dist/assets/{RootHome-CUGUc8za.js → RootHome-H2k4p0ry.js} +1 -1
- package/packages/web/dist/assets/{Surfaces-11or1q_3.js → Surfaces-By65IjL4.js} +1 -1
- package/packages/web/dist/assets/{arc-CQHeCzrk.js → arc-BzdIzLZ7.js} +1 -1
- package/packages/web/dist/assets/{architectureDiagram-3BPJPVTR-dGcuFxAa.js → architectureDiagram-3BPJPVTR-DT9cGrnU.js} +1 -1
- package/packages/web/dist/assets/{blockDiagram-GPEHLZMM-CGc9h97S.js → blockDiagram-GPEHLZMM-BjD-1DXr.js} +1 -1
- package/packages/web/dist/assets/{c4Diagram-AAUBKEIU-BpX0sqhH.js → c4Diagram-AAUBKEIU-DV5q5E08.js} +1 -1
- package/packages/web/dist/assets/channel-D0zKU6oW.js +2 -0
- package/packages/web/dist/assets/{chunk-2J33WTMH-uORGdO9D.js → chunk-2J33WTMH-mzG-wWrp.js} +1 -1
- package/packages/web/dist/assets/{chunk-4BX2VUAB-C8zI2PFy.js → chunk-4BX2VUAB-BJijOYsf.js} +1 -1
- package/packages/web/dist/assets/{chunk-55IACEB6-D22Iv6j6.js → chunk-55IACEB6-CSHJ3zhe.js} +1 -1
- package/packages/web/dist/assets/{chunk-727SXJPM-DdbHXAtS.js → chunk-727SXJPM-BfdGsNJG.js} +1 -1
- package/packages/web/dist/assets/{chunk-AQP2D5EJ-BeKbob3a.js → chunk-AQP2D5EJ-2OJN-ttV.js} +1 -1
- package/packages/web/dist/assets/{chunk-FMBD7UC4-DtLvFU_y.js → chunk-FMBD7UC4-bvjojDsP.js} +1 -1
- package/packages/web/dist/assets/{chunk-ND2GUHAM-BWJFo6B1.js → chunk-ND2GUHAM-DnDJhgvR.js} +1 -1
- package/packages/web/dist/assets/{chunk-QZHKN3VN-DeFkNg3S.js → chunk-QZHKN3VN-Bw6DAHLR.js} +1 -1
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-bF2OmpN6.js +2 -0
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-bF2OmpN6.js +2 -0
- package/packages/web/dist/assets/{core-CTNNIHx5.js → core-BKN_gaN-.js} +1 -1
- package/packages/web/dist/assets/{cose-bilkent-S5V4N54A-BmtlyA-v.js → cose-bilkent-S5V4N54A-BUfjSTaX.js} +1 -1
- package/packages/web/dist/assets/{dagre-BM42HDAG-oS3rC9CI.js → dagre-BM42HDAG-LwxKA-3H.js} +1 -1
- package/packages/web/dist/assets/{diagram-2AECGRRQ-BzIBqz6A.js → diagram-2AECGRRQ-DHS0Xgf9.js} +1 -1
- package/packages/web/dist/assets/{diagram-5GNKFQAL-BgIT2g8R.js → diagram-5GNKFQAL-CNDLt1m9.js} +1 -1
- package/packages/web/dist/assets/{diagram-KO2AKTUF-DACT41Re.js → diagram-KO2AKTUF-D7eVz-kU.js} +1 -1
- package/packages/web/dist/assets/{diagram-LMA3HP47-BstA3UkI.js → diagram-LMA3HP47-Cc0shYXj.js} +1 -1
- package/packages/web/dist/assets/{diagram-OG6HWLK6-Dp3Cn5n_.js → diagram-OG6HWLK6-CdiThnZF.js} +1 -1
- package/packages/web/dist/assets/{documentTitle-DRSQmA8q.js → documentTitle-BgvYvKAe.js} +1 -1
- package/packages/web/dist/assets/{erDiagram-TEJ5UH35-wf8PyGx_.js → erDiagram-TEJ5UH35--YKwrR0M.js} +1 -1
- package/packages/web/dist/assets/{flowDiagram-I6XJVG4X-CJ4xx6EQ.js → flowDiagram-I6XJVG4X-BuWFXtpn.js} +1 -1
- package/packages/web/dist/assets/{ganttDiagram-6RSMTGT7-z9obPrPM.js → ganttDiagram-6RSMTGT7-F6CLJBJ1.js} +1 -1
- package/packages/web/dist/assets/{gitGraphDiagram-PVQCEYII-Cf4Cu7Tk.js → gitGraphDiagram-PVQCEYII-BXrk9SVF.js} +1 -1
- package/packages/web/dist/assets/{index-Bsv-raz2.js → index-2MWb3aF0.js} +2 -2
- package/packages/web/dist/assets/{infoDiagram-5YYISTIA-BIfuiYxX.js → infoDiagram-5YYISTIA-D9iTq2aK.js} +1 -1
- package/packages/web/dist/assets/{ishikawaDiagram-YF4QCWOH-1pACxMTX.js → ishikawaDiagram-YF4QCWOH-CE2vjaAw.js} +1 -1
- package/packages/web/dist/assets/{journeyDiagram-JHISSGLW-XGbzfw-v.js → journeyDiagram-JHISSGLW-CyuASyD1.js} +1 -1
- package/packages/web/dist/assets/{kanban-definition-UN3LZRKU-Bvl-nMak.js → kanban-definition-UN3LZRKU-C-JcQkTl.js} +1 -1
- package/packages/web/dist/assets/{linear-uNToO4bv.js → linear-vd9dAgq3.js} +1 -1
- package/packages/web/dist/assets/{mermaid.core-CrChvyj6.js → mermaid.core-C-uiHBIT.js} +4 -4
- package/packages/web/dist/assets/{mindmap-definition-RKZ34NQL-C6DaQ4Fm.js → mindmap-definition-RKZ34NQL-CQQKVCUB.js} +1 -1
- package/packages/web/dist/assets/{pieDiagram-4H26LBE5-CEh8lKyF.js → pieDiagram-4H26LBE5-CB92bTxC.js} +1 -1
- package/packages/web/dist/assets/{quadrantDiagram-W4KKPZXB-z4zvICSM.js → quadrantDiagram-W4KKPZXB-Cu5Ux2WT.js} +1 -1
- package/packages/web/dist/assets/{requirementDiagram-4Y6WPE33-BBltkjsj.js → requirementDiagram-4Y6WPE33-FJxTktFV.js} +1 -1
- package/packages/web/dist/assets/{sankeyDiagram-5OEKKPKP-D0s95wQ4.js → sankeyDiagram-5OEKKPKP-Bkxk5fIB.js} +1 -1
- package/packages/web/dist/assets/{sequenceDiagram-3UESZ5HK-kQa65Nbt.js → sequenceDiagram-3UESZ5HK-gw8EPzuw.js} +1 -1
- package/packages/web/dist/assets/{stateDiagram-AJRCARHV-BqVIoyED.js → stateDiagram-AJRCARHV-CIHq9Q4N.js} +1 -1
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-Bp8j_o9f.js +2 -0
- package/packages/web/dist/assets/{timeline-definition-PNZ67QCA-Bo5L62WI.js → timeline-definition-PNZ67QCA-CI_99nZc.js} +1 -1
- package/packages/web/dist/assets/{vennDiagram-CIIHVFJN-CN9rH4lT.js → vennDiagram-CIIHVFJN-D5e169vs.js} +1 -1
- package/packages/web/dist/assets/{wardley-L42UT6IY-BKhnD_W_.js → wardley-L42UT6IY-C-EFyR0g.js} +1 -1
- package/packages/web/dist/assets/{wardleyDiagram-YWT4CUSO-XHTbZzXj.js → wardleyDiagram-YWT4CUSO-Cp6Fld6d.js} +1 -1
- package/packages/web/dist/assets/{xychartDiagram-2RQKCTM6--t9XJLbR.js → xychartDiagram-2RQKCTM6-D0iq_qGw.js} +1 -1
- package/packages/web/dist/index.html +1 -1
- package/packages/web/dist/sw.js +1 -1
- package/packages/web/dist/assets/DiscoverPage-D5C2fkeQ.js +0 -2
- package/packages/web/dist/assets/channel-BAeygx-e.js +0 -2
- package/packages/web/dist/assets/classDiagram-4FO5ZUOK-Cq2-sBMa.js +0 -2
- package/packages/web/dist/assets/classDiagram-v2-Q7XG4LA2-Cq2-sBMa.js +0 -2
- package/packages/web/dist/assets/stateDiagram-v2-BHNVJYJU-B6OXxEra.js +0 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-
|
|
2
|
-
import{r as a,a as B,_ as je,j as e,aa as $n,A as pe,ab as Gs,ac as Qt,X as Oe,n as Xe,ad as Mt,L as rn,ae as ma,C as Yt,af as fa,B as ft,i as rt,a5 as qs,ag as wr,ah as vr,ai as yr,aj as Nr,ak as kr,al as Cr,am as Sr,an as Tr,v as At,a8 as Qs,ao as In,S as Jt,ap as $r,J as fs,a6 as Xt,aq as xa,P as bs,ar as pa,as as ga,at as ba,au as ce,Y as It,av as Ir,aw as Ps,ax as ja,ay as Er,p as Et,az as wa,aA as xs,U as va,aB as ya,aC as be,aD as Rr,aE as Mr,aF as _s,aG as ps,aH as Na,T as js,aI as Ys,aJ as Ar,aK as Dr,a2 as Pr,c as $t,aL as ge,aM as _r,aN as Lr,aO as Fr,aP as Or,aQ as Ur,aR as Br,aS as Vr,aT as En,aU as Rn,aV as zr,aW as Hr,aX as Wr,e as ws,aY as Kr,aZ as Gr,a_ as qr,a$ as ka,d as Ca,b0 as Qr,u as Yr,R as Jr,b1 as Xr,h as Zr,a1 as ei,b2 as ti,b3 as si,b4 as ni,Q as ai,b5 as ri,l as ii,b6 as oi}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownRenderer-2vrOdDh7.js","assets/index-2MWb3aF0.js","assets/index-CLhTRqgs.css","assets/queued-CagZVfWU.js","assets/DeleteProjectDialog-BPwSkY3s.js","assets/lastTab-CU1zsF0j.js","assets/Surfaces-By65IjL4.js","assets/DiscoverView-Bz4Rxg-V.js","assets/documentTitle-BgvYvKAe.js","assets/core-BKN_gaN-.js","assets/mermaid.core-C-uiHBIT.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as a,a as B,_ as je,j as e,aa as $n,A as pe,ab as Gs,ac as Qt,X as Oe,n as Xe,ad as Mt,L as rn,ae as ma,C as Yt,af as fa,B as ft,i as rt,a5 as qs,ag as wr,ah as vr,ai as yr,aj as Nr,ak as kr,al as Cr,am as Sr,an as Tr,v as At,a8 as Qs,ao as In,S as Jt,ap as $r,J as fs,a6 as Xt,aq as xa,P as bs,ar as pa,as as ga,at as ba,au as ce,Y as It,av as Ir,aw as Ps,ax as ja,ay as Er,p as Et,az as wa,aA as xs,U as va,aB as ya,aC as be,aD as Rr,aE as Mr,aF as _s,aG as ps,aH as Na,T as js,aI as Ys,aJ as Ar,aK as Dr,a2 as Pr,c as $t,aL as ge,aM as _r,aN as Lr,aO as Fr,aP as Or,aQ as Ur,aR as Br,aS as Vr,aT as En,aU as Rn,aV as zr,aW as Hr,aX as Wr,e as ws,aY as Kr,aZ as Gr,a_ as qr,a$ as ka,d as Ca,b0 as Qr,u as Yr,R as Jr,b1 as Xr,h as Zr,a1 as ei,b2 as ti,b3 as si,b4 as ni,Q as ai,b5 as ri,l as ii,b6 as oi}from"./index-2MWb3aF0.js";import{readQueued as li,readQueuedId as ci,readQueuedAttachments as di,writeQueued as ui,writeQueuedId as hi,writeQueuedAttachments as mi,newQueuedId as fi}from"./queued-CagZVfWU.js";import{C as on,d as xi,D as pi}from"./DeleteProjectDialog-BPwSkY3s.js";import{S as mt,C as gi,E as Sa}from"./Surfaces-By65IjL4.js";import{t as dt,w as bi}from"./lastTab-CU1zsF0j.js";import{D as ji}from"./DiscoverView-Bz4Rxg-V.js";import{u as wi}from"./documentTitle-BgvYvKAe.js";const vi=500,yi=9e4,Ls="paddock:cancel",Mn="paddock:timeout";function Ni(){return typeof window<"u"&&window.isSecureContext===!0&&typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getUserMedia=="function"&&typeof window.MediaRecorder<"u"}function ki(){const t=[{mimeType:"audio/webm;codecs=opus",ext:"webm"},{mimeType:"audio/webm",ext:"webm"},{mimeType:"audio/ogg;codecs=opus",ext:"ogg"},{mimeType:"audio/mp4",ext:"mp4"}],s=window.MediaRecorder;for(const n of t)if(typeof s.isTypeSupported!="function"||s.isTypeSupported(n.mimeType))return n;return{mimeType:"",ext:"webm"}}function Ci({onText:t,timeoutMs:s=yi}){const[n,r]=a.useState("idle"),[i,o]=a.useState(null),[l,c]=a.useState(null),[m]=a.useState(Ni),u=a.useRef(null),b=a.useRef(null),f=a.useRef([]),h=a.useRef("webm"),j=a.useRef(null),x=a.useRef(null),k=a.useRef(!0);a.useEffect(()=>{k.current=!0;let y=!1;return B.transcriptionStatus().then(T=>{y||o(T.available)}).catch(()=>{y||o(!1)}),()=>{var T;y=!0,k.current=!1,(T=x.current)==null||T.abort(Ls),d()}},[]);const d=()=>{var y;(y=b.current)==null||y.getTracks().forEach(T=>T.stop()),b.current=null,u.current=null},p=a.useCallback(async()=>{if(!m||n==="recording"||n==="transcribing")return;c(null),j.current=null;let y;try{y=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(O){r("error"),c(Ii(O));return}b.current=y;const{mimeType:T,ext:w}=ki();h.current=w;const F=T?new MediaRecorder(y,{mimeType:T}):new MediaRecorder(y);f.current=[],F.ondataavailable=O=>{O.data&&O.data.size>0&&f.current.push(O.data)},F.onstop=()=>{d();const O=F.mimeType||T||"audio/webm",z=new Blob(f.current,{type:O});f.current=[],j.current=z,D(z)},u.current=F,F.start(),r("recording")},[m,n]),D=a.useCallback(async(y,T=!1)=>{if(y.size===0){j.current=null,k.current&&r("idle");return}k.current&&r("transcribing");const w=new AbortController;x.current=w;const F=setTimeout(()=>w.abort(Mn),s);try{const O=await B.transcribe(y,`dictation.${h.current}`,w.signal);O.trim()&&t(O.trim()),j.current=null,k.current&&(c(null),r("idle"))}catch(O){if(w.signal.aborted&&w.signal.reason===Ls){j.current=null,k.current&&(c(null),r("idle"));return}if(w.signal.aborted&&w.signal.reason===Mn){k.current&&(r("error"),c("Transcription timed out — try again."));return}if(Si(O)&&!T)return await $i(vi),D(y,!0);k.current&&(r("error"),c(Ti(O)))}finally{clearTimeout(F),x.current===w&&(x.current=null)}},[t,s]),$=a.useCallback(()=>{var y;(y=x.current)==null||y.abort(Ls)},[]),I=a.useCallback(()=>{const y=u.current;y&&y.state!=="inactive"&&y.stop()},[]),C=a.useCallback(()=>{n==="recording"?I():p()},[n,p,I]),S=a.useCallback(()=>{if(n==="recording"||n==="transcribing")return;const y=j.current;y?D(y):p()},[n,D,p]),M=a.useCallback(()=>{j.current=null,c(null),r("idle")},[]);return{state:n,available:i,supported:m,error:l,start:p,stop:I,toggle:C,retry:S,dismiss:M,cancel:$}}function Si(t){return t instanceof je?t.status>=500:!0}function Ti(t){return t instanceof je?t.status>=500?t.message||"Transcription service error — try again.":t.status===400?t.message||"Didn't catch any audio — try again.":t.message||"Transcription failed.":"Couldn't reach the transcription service — check your connection and retry."}function $i(t){return new Promise(s=>setTimeout(s,t))}function Ii(t){switch(t==null?void 0:t.name){case"NotAllowedError":case"SecurityError":return"Microphone permission denied.";case"NotFoundError":case"DevicesNotFoundError":return"No microphone found.";case"NotReadableError":return"Microphone is already in use.";default:return t instanceof Error?t.message:"Could not access the microphone."}}function Ei({onText:t}){const{state:s,available:n,supported:r,error:i,toggle:o,retry:l,dismiss:c,cancel:m}=Ci({onText:t});if(n!==!0)return null;const u=s==="recording",b=s==="transcribing",f=s==="error";if(!r)return e.jsx("button",{type:"button",disabled:!0,"aria-label":"Voice dictation unavailable",title:"Voice dictation needs a secure context (HTTPS or localhost). It's blocked over plain HTTP.",className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-fg-subtle",children:e.jsx($n,{width:18,height:18})});const h=u?"Stop recording":b?"Transcribing… — click to cancel":f?"Transcription failed — click to record again":"Record a voice message",j=()=>{b?m():o()};return e.jsxs("div",{className:"relative flex items-center",children:[f&&i&&e.jsxs("div",{role:"alert",className:"absolute bottom-full right-0 z-10 mb-2 flex max-w-[240px] items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-2.5 py-1.5 text-xs text-danger shadow-md",children:[e.jsx(pe,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"min-w-0 break-words",children:i}),e.jsx("button",{type:"button",onClick:l,className:"shrink-0 font-medium text-danger underline underline-offset-2 hover:opacity-80",children:"Retry"}),e.jsx("button",{type:"button",onClick:c,"aria-label":"Dismiss error",className:"shrink-0 text-danger/70 hover:text-danger",children:"✕"})]}),e.jsxs("button",{type:"button",onClick:j,"aria-label":u?"Stop recording":b?"Cancel transcription":"Record a voice message","aria-pressed":u,title:h,"data-state":s,className:["group flex h-9 w-9 shrink-0 items-center justify-center rounded-full transition-colors",u?"bg-danger-soft text-danger":b?"cursor-pointer text-accent can-hover:hover:bg-danger-soft can-hover:hover:text-danger":f?"bg-danger-soft text-danger":"text-fg-muted can-hover:hover:bg-surface-hover can-hover:hover:text-fg"].filter(Boolean).join(" "),children:[b?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex can-hover:group-hover:hidden group-focus-visible:hidden",children:e.jsx(Ri,{})}),e.jsx(Gs,{width:15,height:15,className:"hidden can-hover:group-hover:block group-focus-visible:block"})]}):u?e.jsx(Gs,{width:16,height:16}):e.jsx($n,{width:18,height:18}),u&&e.jsx("span",{className:"sr-only",children:"recording"})]})]})}function Ri(){return e.jsx("span",{className:"h-[18px] w-[18px] animate-spin rounded-full border-2 border-accent/25 border-t-accent",role:"status","aria-label":"Transcribing"})}const Mi="paddock:chatModel:";function Ta(t,s){return Mi+(t??`new:${s}`)}function Ai(t,s){try{const n=localStorage.getItem(Ta(t,s));return n&&n.length>0?n:null}catch{return null}}function Js(t,s,n){try{localStorage.setItem(Ta(t,s),n)}catch{}}const Di="paddock:draft:";function $a(t,s){return Di+(t??`new:${s}`)}function Pi(t,s){try{return localStorage.getItem($a(t,s))??""}catch{return""}}function _i(t,s,n){try{const r=$a(t,s);n.length>0?localStorage.setItem(r,n):localStorage.removeItem(r)}catch{}}const An="<paddock-attachments>",Xs="</paddock-attachments>",Dn=`${Xs}
|
|
3
3
|
|
|
4
4
|
`;function Ia(t){return`/api/chat-files/${encodeURIComponent(t)}`}function Li(t){const s=t.indexOf(An);if(s===-1)return{attachments:[],text:t};const n=s+An.length,r=t.indexOf(Xs,n);if(r===-1)return{attachments:[],text:t};const i=t.slice(n,r),o=[];for(const m of i.split(`
|
|
5
5
|
`)){const u=m.split(" ");if(u.length<3)continue;const[b,f,h]=u;!(b!=null&&b.trim())||!(h!=null&&h.trim())||o.push({id:b.trim(),kind:(f==null?void 0:f.trim())||"file",filename:h.trim()})}const l=t.slice(0,s),c=t.startsWith(Dn,r)?t.slice(r+Dn.length):t.slice(r+Xs.length).replace(/^\n+/,"");return{attachments:o,text:l+c}}function Fi(t){const s=t.slice(t.lastIndexOf("/")+1),n=s.lastIndexOf(".");return n>0?s.slice(n).toLowerCase():""}function Ea(t){if(t===void 0||!Number.isFinite(t)||t<0)return"";if(t<1024)return`${t} B`;const s=t/1024;if(s<1024)return`${s<10?s.toFixed(1):Math.round(s)} KB`;const n=s/1024;return`${n<10?n.toFixed(1):Math.round(n)} MB`}function Oi(t){return t.some(s=>s==="*"||s==="*/*")?"":t.filter(s=>s&&s!=="*").join(",")}function Ui(t,s,n){const r=(s??"").trim().toLowerCase(),i=Fi(n??"");for(const o of t){const l=o.trim().toLowerCase();if(l){if(l==="*"||l==="*/*")return!0;if(l.includes("/")){if(!r)continue;const[c,m]=l.split("/",2),[u,b]=r.split("/",2);if((c==="*"||c===u)&&(m==="*"||m===b))return!0}else if(l.startsWith(".")){if(i&&i===l)return!0}else if(i&&i===`.${l}`)return!0}}return!1}function Bi({attachments:t}){return t.length===0?null:e.jsx("div",{className:"mb-1 flex flex-wrap justify-end gap-2","data-testid":"message-attachments",children:t.map(s=>e.jsx(Vi,{attachment:s},s.id))})}function Vi({attachment:t}){const s=Ia(t.id);if(t.kind==="image")return e.jsx(Hi,{src:s,filename:t.filename});const n=Ea(t.size);return e.jsxs("a",{href:s,target:"_blank",rel:"noreferrer",title:t.filename,"data-testid":"attachment-chip",className:"flex max-w-[14rem] items-center gap-2 rounded-xl bg-surface-raised px-3 py-2 text-left text-xs shadow-sm ring-1 ring-edge hover:ring-accent",children:[e.jsx(Qt,{width:16,height:16,className:"shrink-0 text-fg-subtle"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"truncate font-medium text-fg",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-3xs text-fg-subtle",children:[t.kind,n?` · ${n}`:""]})]})]})}function zi({attachment:t,onRemove:s}){const n=Ia(t.id),[r,i]=a.useState(!1),o=t.kind==="image"&&!r,l=Ea(t.size);return e.jsxs("span",{"data-testid":"attachment-tray-item",className:"group relative flex items-center gap-2 rounded-xl bg-surface-raised py-2 pl-2 pr-7 text-xs shadow-sm ring-1 ring-edge",children:[o?e.jsx("img",{src:n,alt:t.filename,onError:()=>i(!0),className:"h-9 w-9 shrink-0 rounded-md object-cover"}):e.jsx(Qt,{width:16,height:16,className:"shrink-0 text-fg-subtle"}),e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{className:"max-w-[10rem] truncate font-medium text-fg",children:t.filename}),e.jsxs("span",{className:"uppercase tracking-wide text-3xs text-fg-subtle",children:[t.kind,l?` · ${l}`:""]})]}),e.jsx("button",{type:"button",onClick:()=>s(t.id),"aria-label":`Remove ${t.filename}`,title:"Remove","data-testid":"attachment-remove",className:"absolute right-1 top-1 rounded-full p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg",children:e.jsx(Oe,{width:12,height:12})})]})}function Hi({src:t,filename:s}){const[n,r]=a.useState(!1),[i,o]=a.useState(!1);return i?e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-surface-raised px-3 py-2 text-xs text-danger shadow-sm ring-1 ring-edge",children:[e.jsx(pe,{width:14,height:14}),s]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>r(!0),title:s,"data-testid":"attachment-thumb",className:"block overflow-hidden rounded-xl ring-1 ring-edge hover:ring-accent",children:e.jsx("img",{src:t,alt:s,onError:()=>o(!0),className:"h-24 w-24 object-cover"})}),n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-overlay p-4",onClick:()=>r(!1),role:"dialog","aria-label":s,children:e.jsx("img",{src:t,alt:s,className:"max-h-full max-w-full rounded-lg object-contain shadow-2xl"})}):null]})}function Wi(t){if(t.type==="event")return`the ${t.event} event`;if(t.type==="webhook")return`a webhook (${t.path??"reserved"})`;const s=t.cron??t.interval??"";return`a ${t.cron!==void 0?"cron":"interval"} schedule (${s})`}function Ki({trigger:t,projectSlug:s}){const n=t.allowedTools??[],r=n.length===0,i=r?t.type==="schedule"?"runs as Claude (full tools)":"no tools declared":`${n.length} tool${n.length===1?"":"s"} granted`,o=t.type==="schedule"?Xe:Mt;return e.jsx("div",{"data-testid":"trigger-capability-banner",className:"sticky top-0 z-10 mb-4 rounded-xl border border-info-edge bg-info-soft/95 px-3 py-2.5 text-info shadow-sm backdrop-blur",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx("span",{"aria-hidden":!0,className:"mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-lg bg-info-solid/15 text-info",children:e.jsx(o,{width:15,height:15})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 text-sm",children:[e.jsx("span",{className:"font-semibold",children:"Trigger agent"}),e.jsx("span",{"data-trigger-type":t.type,className:"rounded bg-info-solid/15 px-1.5 py-px text-2xs font-medium uppercase tracking-wide text-info",children:t.type}),e.jsx("span",{className:"font-mono text-sm text-info",children:t.name}),!t.enabled&&e.jsx("span",{title:"This trigger is currently disabled — it won't fire again until re-enabled. This chat is one of its past runs.",className:"rounded bg-info-solid/15 px-1.5 py-px text-2xs font-medium uppercase tracking-wide text-info",children:"disabled"})]}),e.jsxs("p",{className:"mt-0.5 text-xs text-info",children:["Fired by ",e.jsx("span",{className:"font-medium",children:Wi(t)})," · ",i,". A reply you type here runs at this trigger's capability, not Claude's."]}),e.jsxs("details",{className:"group mt-1.5 text-xs",children:[e.jsxs("summary",{className:"inline-flex cursor-pointer select-none items-center gap-1 text-info hover:underline",children:[e.jsx("span",{className:"transition group-open:rotate-90","aria-hidden":!0,children:"▸"}),"Capabilities"]}),e.jsxs("div",{className:"mt-2 space-y-2 border-l-2 border-info-edge pl-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 font-medium",children:"Allowed tools"}),r?e.jsx("p",{className:"text-info",children:t.type==="schedule"?"None declared — this schedule runs as Claude with its full toolset.":"None declared. An empty list is not a restriction: no allow-list is passed to the runtime, so this agent falls back to Claude's default tools. Its prompt and max turns are the real bounds."}):e.jsx("ul",{className:"flex flex-wrap gap-1","data-testid":"trigger-allowed-tools",children:n.map(l=>e.jsx("li",{className:"rounded bg-info-solid/10 px-1.5 py-px font-mono text-2xs text-info",children:l},l))})]}),e.jsxs("dl",{className:"grid grid-cols-[auto,1fr] gap-x-3 gap-y-0.5 text-info",children:[t.permissionMode&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Permission mode"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.permissionMode})]}),t.model&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"font-medium",children:"Model"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.model})]}),e.jsx("dt",{className:"font-medium",children:"Max turns"}),e.jsx("dd",{className:"font-mono text-2xs",children:t.maxTurns}),e.jsx("dt",{className:"font-medium",children:"Agent"}),e.jsx("dd",{className:"truncate font-mono text-2xs",children:t.agentName})]}),e.jsx(rn,{to:`/projects/${encodeURIComponent(s)}/triggers`,className:"inline-flex items-center gap-1 font-medium text-info hover:underline",title:"Manage this project's triggers",children:"Edit trigger →"})]})]})]})]})})}const Gi=new Set(["paddock","paddock_manage"]);function qi(t){const s=t.replace(/_/g," ").trim();return s?s.charAt(0).toUpperCase()+s.slice(1):t}function Qi(t){if(!t.startsWith("mcp__"))return{isMcp:!1,server:"",isPaddock:!1,display:t,tool:t};const s=t.slice(5),n=s.indexOf("__"),r=n===-1?s:s.slice(0,n),i=n===-1?"":s.slice(n+2);return{isMcp:!0,server:r,isPaddock:Gi.has(r),display:qi(i||r),tool:i}}const Pn="mcp__paddock_manage__",Wt=(t,s)=>typeof t=="number"&&Number.isFinite(t)?t:s,kt=t=>{if(typeof t!="string")return;const s=t.trim();return s.length>0?s:void 0};function Ra(t,s=80){var r;const n=((r=t.split(`
|
|
6
6
|
`).find(i=>i.trim().length>0))==null?void 0:r.trim())??t.trim();return n.length>s?`${n.slice(0,s).trimEnd()}…`:n}function Ma(t,s){return t||(s?Ra(s):"untitled chat")}function Yi(t,s){if(!t.startsWith(Pn)||!s)return null;const n=t.slice(Pn.length);let r;try{r=JSON.parse(s)}catch{return null}if(!r||typeof r!="object")return null;switch(n){case"list_projects":{if(!Array.isArray(r.projects))return null;const i=r.projects;return{tool:n,count:Wt(r.count,i.length),projects:i}}case"list_chats":{if(!Array.isArray(r.chats))return null;const i=r.chats;return{tool:n,count:Wt(r.count,i.length),project:r.project??null,chats:i}}case"read_chat":{if(!Array.isArray(r.messages))return null;const i=r.messages;return{tool:n,project:String(r.project??""),sessionId:String(r.sessionId??""),total:Wt(r.total,i.length),returned:Wt(r.returned,i.length),messages:i}}case"create_chat":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),name:kt(r.name),prompt:kt(r.prompt)}:null;case"send_message":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),prompt:kt(r.prompt)}:null;case"fork_chat":return r.sessionId?{tool:n,project:String(r.project??""),sessionId:String(r.sessionId),from:kt(r.from),name:kt(r.name),prompt:kt(r.prompt)}:null;case"fork_chat_batch":{if(!Array.isArray(r.forks))return null;const i=r.forks;return{tool:n,count:Wt(r.count,i.length),source:String(r.source??""),forks:i}}default:return null}}function Ji(t){switch(t.tool){case"list_projects":return`${t.count} ${t.count===1?"project":"projects"}`;case"list_chats":return`${t.count} ${t.count===1?"chat":"chats"}`+(t.project?` in ${t.project}`:" across all projects");case"read_chat":return`${t.project} · ${t.returned}/${t.total} messages`;case"create_chat":case"fork_chat":return Ma(t.name,t.prompt);case"send_message":return t.prompt?Ra(t.prompt):`message to ${t.project}`;case"fork_chat_batch":return`fanned out ${t.count} ${t.count===1?"chat":"chats"}`}}const Aa=a.createContext(null),Xi=(t,s)=>`/projects/${encodeURIComponent(t)}/chat/${encodeURIComponent(s)}`,Zs=t=>t.length>8?`${t.slice(0,8)}…`:t;function Gt({project:t,sessionId:s,label:n}){return e.jsxs(rn,{to:Xi(t,s),className:"inline-flex items-center gap-1 rounded-md bg-accent-soft px-2 py-0.5 font-mono text-2xs font-medium text-accent no-underline ring-1 ring-accent/20 transition-colors hover:bg-accent/20",title:`Open ${s}`,children:[e.jsx(ma,{width:10,height:10,className:"shrink-0"}),n??Zs(s)]})}const Ct="border-t border-edge px-3 py-2.5",St="text-fg-muted";function _n({children:t}){return e.jsx("span",{className:"rounded bg-surface-active px-1.5 py-0.5 text-3xs font-medium text-fg-muted",children:t})}function Ln({label:t,text:s}){return e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"mb-1 text-3xs font-semibold uppercase tracking-wide text-fg-subtle",children:t}),e.jsx("div",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md bg-surface-sunken px-2.5 py-1.5 text-2xs leading-relaxed text-fg-muted",children:s})]})}function Zi({chat:t}){return e.jsxs("li",{className:"flex items-center gap-2 py-1",children:[t.running?e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-success-solid",title:"running"}):e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-edge-strong"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg",children:t.name||"(untitled)"}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId})]})}function eo({data:t}){const s=a.useContext(Aa)??"";switch(t.tool){case"list_projects":return e.jsx("div",{className:Ct,children:e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.projects.map(n=>e.jsxs("li",{className:"flex items-center gap-1.5 rounded-md bg-surface-sunken px-2 py-1",children:[e.jsx("span",{className:"text-2xs font-medium text-fg",children:n.name}),n.area&&e.jsx(_n,{children:n.area}),n.status&&n.status!=="active"&&e.jsx(_n,{children:n.status})]},n.slug))})});case"list_chats":return e.jsx("div",{className:Ct,children:e.jsx("ul",{className:"max-h-72 divide-y divide-edge-subtle overflow-auto text-2xs",children:t.chats.map(n=>e.jsx(Zi,{chat:n},n.sessionId))})});case"read_chat":return e.jsxs("div",{className:Ct,children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:[e.jsxs("span",{className:St,children:[t.returned," of ",t.total," messages"]}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),e.jsx("ul",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.messages.map((n,r)=>e.jsxs("li",{className:"text-2xs leading-relaxed",children:[e.jsx("span",{className:`mr-1.5 font-mono text-3xs font-semibold uppercase ${n.role==="assistant"?"text-accent":"text-fg-subtle"}`,children:n.role}),e.jsx("span",{className:"whitespace-pre-wrap break-words text-fg-muted",children:n.text})]},r))})]});case"create_chat":case"fork_chat":{const n=t.tool==="create_chat"?"Created chat":"Forked chat",r=Ma(t.name,t.prompt);return e.jsxs("div",{className:Ct,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:St,children:n}),e.jsx("span",{className:"font-medium text-fg",children:r}),e.jsxs("span",{className:St,children:["in ",t.project]}),t.tool==="fork_chat"&&t.from&&e.jsxs("span",{className:`font-mono ${St}`,children:["from ",Zs(t.from)]}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&t.name&&e.jsx(Ln,{label:"Kickoff",text:t.prompt})]})}case"send_message":return e.jsxs("div",{className:Ct,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs",children:[e.jsx("span",{className:St,children:"Sent to"}),e.jsx("span",{className:"font-medium text-fg",children:t.project}),e.jsx(Gt,{project:t.project,sessionId:t.sessionId,label:"open chat"})]}),t.prompt&&e.jsx(Ln,{label:"Message",text:t.prompt})]});case"fork_chat_batch":return e.jsxs("div",{className:Ct,children:[e.jsx("div",{className:"mb-2 flex items-center gap-2 text-2xs",children:e.jsxs("span",{className:St,children:[t.count," ",t.count===1?"fork":"forks"," from ",Zs(t.source)]})}),e.jsx("ol",{className:"max-h-72 space-y-1.5 overflow-auto",children:t.forks.map((n,r)=>e.jsxs("li",{className:"flex items-start gap-2 rounded-md bg-surface-sunken px-2 py-1.5",children:[e.jsx("span",{className:"mt-0.5 shrink-0 font-mono text-3xs font-semibold text-fg-subtle",children:r+1}),e.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:n.prompt}),e.jsx(Gt,{project:s,sessionId:n.sessionId})]},n.sessionId))})]})}}const vs=new Set(["Task","Agent"]);function to(t,s){return vs.has(t.toolName)&&s&&t.subagentDurationMs==null}const so="mcp__paddock__send_file",no=new Set(["BashOutput","TaskOutput","TaskStop","KillShell"]),ao=/running in (?:the )?background with ID: [A-Za-z0-9]+/i;function ro(t){return t.background||t.toolName==="Monitor"||no.has(t.toolName)?!0:ao.test(t.output??"")}function io(t){switch(t){case"completed":return"bg-success-soft text-success";case"killed":case"timed out":return"bg-warn-soft text-warn";case"running":case"persistent":return"bg-info-soft text-info";default:return"bg-surface-active text-fg-muted"}}function oo(t){switch(t){case"list_projects":return qs;case"create_chat":return rt;case"fork_chat":case"fork_chat_batch":return ft;case"send_message":return fa;default:return Yt}}function Da(t){if(t.toolName!==so||!t.output)return null;let s;try{s=JSON.parse(t.output)}catch{return null}return!s||s.paddockSendFile!==1||typeof s.filename!="string"?null:{filename:s.filename,kind:s.kind,language:s.language,message:s.message,source:s.source,content:s.source==="inline"?s.content:void 0,rawUrl:s.source==="file"&&s.attachmentId?B.chatFileRawUrl(s.attachmentId):void 0}}function lo(t){return t==="+"?"bg-success-soft text-success":t==="-"?"bg-danger-soft text-danger":"text-fg-muted"}function Fn(t){return t===void 0?"":String(t)}function co(t){switch(t){case"completed":case"done":return"bg-success-soft text-success";case"in_progress":return"bg-info-soft text-info";case"blocked":case"failed":case"cancelled":return"bg-danger-soft text-danger";default:return"bg-surface-active text-fg-muted"}}function uo(t){const s=[];if(t.kind==="grep")t.numLines!==void 0&&s.push(`${t.numLines} line${t.numLines===1?"":"s"}`),t.numFiles!==void 0&&s.push(`${t.numFiles} file${t.numFiles===1?"":"s"}`);else{const n=t.totalMatches??t.numFiles;n!==void 0&&s.push(`${n} match${n===1?"":"es"}`)}return s.length?(t.truncated?"≥":"")+s.join(" · "):null}function ho(t){if(t.startLine===void 0||t.numLines===void 0)return null;const s=t.startLine+Math.max(0,t.numLines-1),n=t.totalLines!==void 0?` of ${t.totalLines}`:"";return`lines ${t.startLine}–${s}${n}`}let mo=0;const Je=()=>`t${++mo}`;function fo(t,s){t(n=>{const r=n[n.length-1];return r&&r.kind==="assistant"&&r.streaming?[...n.slice(0,-1),{...r,content:r.content+s}]:[...n,{kind:"assistant",id:Je(),content:s,streaming:!0}]})}function Fe(t){return t.some(s=>s.kind==="assistant"&&s.streaming)?t.map(s=>s.kind==="assistant"&&s.streaming?{...s,streaming:!1}:s):t}function On(t){return t.some(s=>s.kind==="tool"&&s.tool.pending)?t.map(s=>s.kind==="tool"&&s.tool.pending?{...s,tool:{...s.tool,pending:!1}}:s):t}function xo(t,s){if(t.notice)return{kind:"notice",id:s,notice:t.notice};if(t.role==="tool"&&t.toolCall){const o=Da(t.toolCall);return o?{kind:"file",id:s,file:o}:{kind:"tool",id:s,tool:t.toolCall}}if(t.role==="assistant")return{kind:"assistant",id:s,content:t.content,streaming:!1};if(wr(t.content))return{kind:"compact",id:s,summary:t.content};const n=vr(t.content);if(n)return{kind:"command",id:s,command:n};if(yr(t.content))return{kind:"commandOutput",id:s,content:Nr(t.content)??""};if(kr(t.content))return{kind:"commandOutput",id:s,content:""};if(Cr(t.content))return{kind:"notification",id:s,summary:Tr(t.content),status:Sr(t.content)};const{attachments:r,text:i}=Li(t.content);return{kind:"user",id:s,content:i,...t.sender?{sender:t.sender}:{},...r.length>0?{attachments:r}:{}}}const po="/compact";function go(t){return t.kind==="commandOutput"&&t.content===""}function bo(t){if(!t.some(n=>n.kind==="compact"))return t;const s=[];for(let n=0;n<t.length;n++){const r=t[n];if(r.kind!=="compact"){s.push(r);continue}let i=n+1;for(;i<t.length&&go(t[i]);)i++;const o=t[i];(o==null?void 0:o.kind)==="command"&&o.command===po?(s.push(...t.slice(n+1,i+1),r),n=i):s.push(r)}return s}function Tt(t){const s=new Map,n=t.filter(r=>!r.bgConsumed).map(r=>{let i;if(r.uuid){const l=s.get(r.uuid)??0;s.set(r.uuid,l+1),i=l===0?r.uuid:`${r.uuid}#${l}`}else i=Je();const o=xo(r,i);return o.timestamp=r.timestamp,r.contextTokens!=null&&(o.contextTokens=r.contextTokens),o});return bo(n)}function Un(t){switch(t.kind){case"user":return`user:${t.content}`;case"command":return`command:${t.command}`;case"commandOutput":return`commandOutput:${t.content}`;case"compact":return`compact:${t.summary}`;case"notification":return`notification:${t.status??""}:${t.summary}`;case"notice":return`notice:${t.notice.kind}`;case"file":return`file:${t.file.filename}:${t.file.source}`;default:return`${t.kind}:${t.id}`}}function Fs(t,s){if(s.length===0)return t;if(t.length===0)return s;const n=[...t],r=new Map,i=new Map,o=[];n.forEach((l,c)=>{l.kind==="tool"&&l.tool.toolUseId?r.set(l.tool.toolUseId,c):l.kind==="assistant"?o.push(c):i.set(Un(l),c)});for(const l of s){if(l.kind==="tool"&&l.tool.toolUseId){const m=r.get(l.tool.toolUseId);if(m===void 0){r.set(l.tool.toolUseId,n.length),n.push(l);continue}const u=n[m];if(u.kind!=="tool")continue;n[m]={...u,tool:{...u.tool,...l.tool,pending:l.tool.pending===!0}};continue}if(l.kind==="assistant"){const m=o.find(b=>{const f=n[b];return f.kind==="assistant"&&(f.content===l.content||f.content.startsWith(l.content)||l.content.startsWith(f.content))});if(m===void 0){o.push(n.length),n.push(l);continue}const u=n[m];if(u.kind!=="assistant")continue;l.content.length>u.content.length&&(n[m]={...u,content:l.content,streaming:l.streaming});continue}const c=Un(l);i.has(c)||(i.set(c,n.length),n.push(l))}return n}const Pa=a.createContext(null),_a=a.createContext(!1),ln=a.createContext(null),La=a.createContext(null),Fa=a.createContext(null),cn=a.createContext(null),Oa=a.createContext(null),Ua=a.createContext(null),Bn=4;function jo(t){const[,s]=a.useState(0);a.useEffect(()=>{if(!t)return;const n=setInterval(()=>s(r=>r+1),1e3);return()=>clearInterval(n)},[t])}const ht=t=>t.role??t.type;function wo({role:t}){const s="shrink-0 text-info";return t==="shell"?e.jsx(Xt,{width:12,height:12,className:s}):t==="workflow"?e.jsx(xa,{width:12,height:12,className:s}):t==="subagent"?e.jsx(Jt,{width:12,height:12,className:"shrink-0 text-accent"}):e.jsx(Xe,{width:12,height:12,className:s})}function Os(t){const s=ht(t);return s==="subagent"?t.agentType??"sub-agent":s==="workflow"?t.workflowName??"workflow":s==="monitor"?t.tool??"monitor":s}function Ba(t,s){var r,i;if(ht(t)!=="shell")return;const n=(r=t.command)==null?void 0:r.trim();if(n)return n;if(t.toolUseId)return((i=s==null?void 0:s.get(t.toolUseId))==null?void 0:i.trim())||void 0}function Vn(t,s){const n=Ba(t,s);return n||(ht(t)==="shell"?t.description:t.lastToolName?t.lastToolName:t.description)}const Va={subagent:"sub-agent",shell:"shell",monitor:"monitor",workflow:"workflow",task:"task"};function cs(t,s){const n=Va[t];return n?`${s} ${n}${s===1?"":"s"}`:`${s} ${t}`}const vo=t=>t==="subagent";function zn({taskId:t,label:s,stopping:n,failed:r,onStop:i}){return!i||!t?null:e.jsx("button",{type:"button",onClick:i,disabled:n,"data-testid":"running-task-cancel","data-stop-state":r?"failed":n?"stopping":"idle",title:r?`Could not stop: ${r}`:`Stop ${s}`,"aria-label":r?`Retry stopping ${s}`:`Stop ${s}`,className:`mr-1.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md transition-colors disabled:opacity-40 ${r?"text-danger can-hover:hover:bg-danger-soft":"text-fg-subtle can-hover:hover:bg-danger-soft can-hover:hover:text-danger"}`,children:e.jsx(Oe,{width:12,height:12})})}function yo({running:t,activity:s,tasks:n,commands:r,onReveal:i,onCancel:o,stopping:l,stopFailed:c}){var L;const m=new Set(t.map(v=>v.toolUseId)),u=n.filter(v=>!v.skipTranscript),b=u.filter(v=>!(v.toolUseId!=null&&m.has(v.toolUseId))),f=new Map(u.filter(v=>v.toolUseId!=null).map(v=>[v.toolUseId,v])),h=t.length+b.length,[j,x]=a.useState(()=>h>Bn),k=a.useRef(h===0);a.useLayoutEffect(()=>{h===0?k.current=!0:k.current&&(k.current=!1,x(h>Bn))},[h]);const d=a.useId(),[p,D]=a.useState(null);if(a.useEffect(()=>{h===0&&D(null)},[h]),jo(h>0),h===0)return null;const $=new Map;t.length&&$.set("subagent",t.length);for(const v of b){const A=ht(v);$.set(A,($.get(A)??0)+1)}const I=[...$.entries()].sort((v,A)=>A[1]-v[1]),C=I.length===1&&Va[I[0][0]]?I[0][0]:null,S=C?`${cs(C,h)} running`:`${h} ${h===1?"thing":"things"} running`,M=b.reduce((v,A)=>v==null||A.startedAt>v.startedAt?A:v,null),y=t.length?t[t.length-1]:null,T=I.length>1?I.map(([v,A])=>cs(v,A)).join(" · "):M?Vn(M,r)||S:y?((L=s.get(y.toolUseId))==null?void 0:L.latestStep)??y.label:S,w=b.reduce((v,A)=>v==null||A.startedAt<v?A.startedAt:v,null),F=j?At:Qs,O=u.filter(v=>v.stoppable!==!1&&!(l!=null&&l.has(v.id))).map(v=>v.id),z=(v,A,W)=>{if(!(!o||!v))return()=>{if(!vo(A))return o(v);D({taskIds:[v],title:`Stop ${W}?`,body:"This sub-agent and everything it started will be stopped. Work already in progress is lost, and it cannot be resumed from where it got to.",confirmLabel:"Stop sub-agent"})}},X=()=>{const v=u.filter(A=>O.includes(A.id)&&ht(A)==="subagent").length;D({taskIds:O,title:"Stop all running work?",body:`${cs("task",O.length)} will be stopped`+(v>0?`, including ${cs("subagent",v)} and everything they started.`:".")+" Work already in progress is lost.",confirmLabel:"Stop all"})};return e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4","data-testid":"running-work",children:[e.jsxs("div",{className:"mb-2 overflow-hidden rounded-lg border border-accent-edge bg-accent-soft",children:[e.jsxs("div",{className:"flex items-center border-b border-accent/20",children:[e.jsxs("button",{type:"button",onClick:()=>x(v=>!v),"aria-expanded":!j,"aria-controls":d,"data-testid":"running-work-toggle",title:j?"Show each running item":"Collapse to a summary",className:"flex min-w-0 flex-1 items-center gap-1.5 px-3 py-1.5 text-left transition-colors can-hover:hover:bg-accent/10 focus-visible:focus-ring",children:[e.jsx("span",{className:"h-2.5 w-2.5 shrink-0 animate-spin rounded-full border-2 border-accent/30 border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 truncate text-3xs font-semibold uppercase tracking-wide text-accent",children:S}),e.jsx(F,{width:12,height:12,"aria-hidden":"true",className:"ml-auto shrink-0 text-accent/70"})]}),o&&h>1&&O.length>0&&e.jsx("button",{type:"button",onClick:X,"data-testid":"running-work-stop-all",title:"Stop every running task",className:"shrink-0 px-3 py-1.5 text-3xs font-semibold uppercase tracking-wide text-fg-subtle transition-colors can-hover:hover:text-danger focus-visible:focus-ring",children:"Stop all"})]}),j?e.jsxs("div",{id:d,className:"flex items-center gap-2 px-3 py-1.5","data-testid":"running-work-summary",children:[e.jsx(Xe,{width:12,height:12,"aria-hidden":"true",className:"shrink-0 text-info"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-2xs text-info",title:T,children:T}),w!=null&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:["oldest ",In(Date.now()-w)]})]}):e.jsxs("ul",{id:d,className:"divide-y divide-accent/15",children:[t.map(v=>{const A=s.get(v.toolUseId),W=f.get(v.toolUseId),Q=W&&W.stoppable!==!1?W.id:void 0,ie=Q!=null&&(l==null?void 0:l.has(Q))===!0,K=Q!=null?c==null?void 0:c.get(Q):void 0,q=z(Q,"subagent",v.label);return e.jsxs("li",{className:"flex items-center",children:[e.jsxs("button",{type:"button","data-testid":"running-subagent-row",onClick:()=>i(v.toolUseId),title:"Show this sub-agent in the transcript",className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-3 text-left transition-colors can-hover:hover:bg-accent/10 ${q?"pr-1":"pr-3"} ${ie?"opacity-50":""}`,children:[e.jsx(Jt,{width:12,height:12,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-2xs font-semibold text-fg",children:v.label}),v.description&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted",children:v.description}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-2xs ${K?"text-danger":"text-accent/90"}`,title:K??(A==null?void 0:A.latestStep),children:K?"can't stop":ie?"stopping…":(A==null?void 0:A.latestStep)??"starting…"}),A!=null&&A.stepCount>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[A.stepCount," step",A.stepCount===1?"":"s"]})]}),e.jsx(zn,{taskId:Q,label:v.label,stopping:ie,failed:K,onStop:q})]},v.toolUseId)}),b.map(v=>{const A=Vn(v,r),W=Ba(v,r)?v.description.trim():"",Q=v.toolUseId,ie=Q?"button":"div",K=(l==null?void 0:l.has(v.id))===!0,q=c==null?void 0:c.get(v.id),N=v.stoppable!==!1?v.id:void 0,U=z(N,ht(v),Os(v));return e.jsxs("li",{className:"flex items-center",children:[e.jsxs(ie,{...Q?{type:"button",onClick:()=>i(Q),title:"Show this task in the transcript"}:{},"data-testid":"running-task-row","data-task-type":v.type,className:`flex min-w-0 flex-1 items-center gap-2 py-1.5 pl-3 text-left transition-colors ${U?"pr-1":"pr-3"} ${Q?"can-hover:hover:bg-accent/10":""} ${K?"opacity-50":""}`,children:[e.jsx(wo,{role:ht(v)}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-2xs font-semibold text-fg",children:Os(v)}),W&&e.jsx("span",{className:"shrink-0 max-w-[10rem] truncate text-2xs text-fg-muted","data-testid":"running-task-intent",children:W}),e.jsx("span",{className:`min-w-0 flex-1 truncate font-mono text-2xs ${q?"text-danger":"text-info"}`,"data-testid":"running-task-detail",title:q??A,children:q?"can't stop":K?"stopping…":A||"starting…"}),v.toolUses!=null&&v.toolUses>0&&e.jsxs("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle",children:[v.toolUses," step",v.toolUses===1?"":"s"]}),e.jsx("span",{className:"shrink-0 whitespace-nowrap text-3xs tabular-nums text-fg-subtle","data-testid":"running-task-elapsed",children:In(Date.now()-v.startedAt)})]}),e.jsx(zn,{taskId:N,label:Os(v),stopping:K,failed:q,onStop:U})]},v.id)})]})]}),e.jsx($r,{open:p!=null,onClose:()=>D(null),role:"alertdialog",size:"sm",title:(p==null?void 0:p.title)??"",description:p==null?void 0:p.body,footer:e.jsxs(e.Fragment,{children:[e.jsx(fs,{variant:"ghost",onClick:()=>D(null),children:"Keep running"}),e.jsx(fs,{variant:"danger","data-testid":"running-work-confirm-stop",onClick:()=>{const v=(p==null?void 0:p.taskIds)??[];D(null),v.forEach(A=>o==null?void 0:o(A))},children:(p==null?void 0:p.confirmLabel)??"Stop"})]})})]})}const No=2e3,ko=6,za=new Set;function Co(t){const s=t.toolCall;if(!s)return null;const n=vs.has(s.toolName)?`${s.subagentType??s.toolName} ▸`:s.toolName,r=(s.description??s.inputSummary??"").trim();return r?`${n} ${r}`:n}function So(t){var r,i;if(t.length===0)return;const s=Date.parse(((r=t[0])==null?void 0:r.timestamp)??""),n=Date.parse(((i=t[t.length-1])==null?void 0:i.timestamp)??"");if(!(!Number.isFinite(s)||!Number.isFinite(n)||n<s))return n-s}function To(t){var s;return`${t.length}:${((s=t[t.length-1])==null?void 0:s.timestamp)??""}`}function $o(t,s,n,r=za){const[i,o]=a.useState(new Map),l=a.useRef(new Set),c=a.useRef(new Map),m=a.useRef(s);m.current=s;const u=a.useRef(n);u.current=n;const b=t.map(h=>h.toolUseId).sort().join(","),f=[...r].sort().join(",");return a.useEffect(()=>{const h=f?f.split(","):[];if(h.length!==0){for(const j of h)l.current.add(j);o(j=>{let x=null;for(const k of h){const d=j.get(k);d&&!d.running||(x??(x=new Map(j)),x.set(k,{...d,stepCount:(d==null?void 0:d.stepCount)??0,running:!1}))}return x??j})}},[f]),a.useEffect(()=>{const h=b?b.split(","):[];if(h.length===0||!m.current)return;let j=!1,x;const k=async()=>{const d=m.current;if(!d)return;const p=h.filter($=>!l.current.has($));if(p.length===0)return;const D=await Promise.all(p.map($=>d($).then(I=>({id:$,messages:I})).catch(()=>null)));j||(o($=>{const I=new Map($);for(const C of D){if(!C||l.current.has(C.id))continue;const S=To(C.messages),M=c.current.get(C.id),y=M&&M.sig===S?M.ticks+1:0;c.current.set(C.id,{sig:S,ticks:y});const T=!u.current&&y>=ko;T&&l.current.add(C.id);const w=C.messages.map(Co).filter(F=>!!F);I.set(C.id,{latestStep:w[w.length-1],stepCount:w.length,messages:C.messages,elapsedMs:So(C.messages),running:!T})}return I}),j||(x=setTimeout(k,No)))};return k(),()=>{j=!0,x&&clearTimeout(x)}},[b]),i}function Io(t){const[s,n]=a.useState(za),r=a.useRef(new Set),i=t.map(o=>o.toolUseId).filter(o=>!!o).sort().join(",");return a.useEffect(()=>{const o=new Set(i?i.split(","):[]);for(const l of o)r.current.add(l);n(l=>{let c=null;for(const m of r.current)o.has(m)||l.has(m)||(c??(c=new Set(l)),c.add(m));return c??l})},[i]),s}function Eo(t){return a.useMemo(()=>{const s=[];for(const n of t){const r=n.kind==="tool"?n.tool:void 0;r!=null&&r.toolUseId&&vs.has(r.toolName)&&r.hasSubagent&&r.subagentDurationMs==null&&s.push({toolUseId:r.toolUseId,label:r.subagentType??r.toolName,description:r.description})}return s},[t])}function Ro(t){return a.useMemo(()=>{var n;const s=new Map;for(const r of t){const i=r.kind==="tool"?r.tool:void 0;if(!(i!=null&&i.toolUseId)||i.toolName!=="Bash"&&i.toolName!=="bash")continue;const o=(n=i.inputSummary)==null?void 0:n.trim();o&&s.set(i.toolUseId,o)}return s},[t])}function Mo({checked:t,available:s,onChange:n}){return e.jsxs("label",{className:`group mb-2 inline-flex w-fit items-center gap-2 rounded-lg px-1 py-0.5 text-xs ${s?"cursor-pointer text-fg-muted":"cursor-not-allowed text-fg-subtle"}`,title:s?"Inject this project's curated OVERVIEW.md (current state) and CHANGELOG.md (history) as context on the first message of this new chat, so the agent starts already knowing the project's state and narrative.":"No project overview yet — a sweep writes OVERVIEW.md after some activity. The agent will still see the project's files.",children:[e.jsx("input",{type:"checkbox",checked:t,disabled:!s,onChange:r=>n(r.target.checked),className:"h-3.5 w-3.5 rounded border-edge-strong accent-[var(--accent-solid)] focus:ring-accent/30 disabled:opacity-50"}),e.jsx("span",{className:"font-medium",children:"Preload project context"}),e.jsx("span",{className:"hidden text-fg-subtle transition-opacity sm:inline",children:s?"(injects OVERVIEW.md + CHANGELOG.md)":"(no overview yet)"})]})}function Ao({models:t,model:s,onSelectModel:n,usage:r,sessionUsage:i,forkParent:o,onOpenForkParent:l}){return e.jsxs("div",{className:"mb-2 flex items-center gap-3 px-1 text-2xs text-fg-subtle",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-fg-muted",children:"Model"}),e.jsxs("select",{value:s??"",onChange:c=>n(c.target.value),disabled:t.length===0,title:"Model for this chat (sent on every message; remembered per chat)",className:"rounded-md border border-edge-strong bg-surface-raised px-1.5 py-0.5 text-2xs text-fg-muted outline-none focus:border-accent focus:ring-1 focus:ring-accent/20 disabled:opacity-50",children:[s&&!t.some(c=>c.id===s)&&e.jsx("option",{value:s,children:s}),t.map(c=>e.jsx("option",{value:c.id,children:c.label},c.id))]})]}),e.jsx(Do,{usage:r}),e.jsx(Po,{usage:i}),o&&e.jsxs("span",{className:"ml-auto inline-flex min-w-0 items-center gap-1",children:[e.jsx(ft,{width:11,height:11,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"shrink-0",children:"Fork of"}),e.jsx("button",{type:"button",onClick:()=>l==null?void 0:l(o.sessionId),title:`Open the chat this was forked from: ${o.name}`,className:"truncate font-medium text-accent underline-offset-2 hover:underline",children:o.name})]})]})}function Do({usage:t}){if(!t||t.contextLimit<=0)return e.jsx("span",{className:"text-fg-subtle",children:"context: —"});const s=Math.min(100,Math.max(0,t.contextTokens/t.contextLimit*100)),n=s>=80,r=Math.round(t.contextTokens/1e3),i=Math.round(t.contextLimit/1e3);return e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",title:`Context window used as of the last completed turn (${t.contextTokens.toLocaleString()} / ${t.contextLimit.toLocaleString()} tokens)`,children:[e.jsx("span",{className:"h-1 w-20 overflow-hidden rounded-full bg-surface-active",children:e.jsx("span",{className:`motion-base block h-full rounded-full transition-[width,background-color] ${n?"bg-warn-solid":"bg-accent-solid"}`,style:{width:`${s}%`}})}),e.jsxs("span",{className:n?"text-warn":void 0,children:[r,"k / ",i,"k (",Math.round(s),"%)"]})]})}function Po({usage:t}){if(!t||t.totalTokens<=0)return null;const s=t.costUsd!=null?`~${pa(t.costUsd)}`:ga(t.totalTokens);return e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1",title:`Session so far: ${ba(t)}`,children:[e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:s})]})}const Hn=["working","thinking","reticulating splines","consulting Claude","herding electrons","tending the paddock"];function _o(){const[t,s]=a.useState(0);return a.useEffect(()=>{const n=setInterval(()=>s(r=>(r+1)%Hn.length),2600);return()=>clearInterval(n)},[]),e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-edge bg-surface-active px-3 py-1 text-xs text-fg-muted",children:[e.jsx("span",{className:"inline-flex h-1.5 w-1.5 rounded-full bg-accent-solid","aria-hidden":"true"}),e.jsxs("span",{children:[Hn[t],"…"]})]})})}function Lo({text:t,attachments:s=[],onEdit:n,onClear:r}){const i=t.split(`
|
|
7
|
-
`,1)[0],o=t.length-i.length;return e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"group flex items-center gap-2 rounded-lg border border-accent-edge bg-accent-soft px-3 py-1.5 text-xs",children:[e.jsx(Xe,{width:13,height:13,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 font-semibold uppercase tracking-wide text-accent",children:"queued"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-muted",title:t||s.map(l=>l.filename).join(", "),children:i||(s.length>0?e.jsx("span",{className:"italic text-fg-muted",children:s.length===1?"1 attachment":`${s.length} attachments`}):null)}),i&&s.length>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle","data-testid":"queued-attachment-count",title:s.map(l=>l.filename).join(", "),children:["📎 ",s.length]}),o>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle",title:`${o} more character${o===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",o," character",o===1?"":"s"]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100",children:[e.jsxs("button",{type:"button",onClick:n,title:"Edit this message (cancels the pending auto-send)",className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active",children:[e.jsx(bs,{width:12,height:12}),"Edit"]}),e.jsx("button",{type:"button",onClick:r,title:"Remove queued message","aria-label":"Remove queued message",className:"inline-flex items-center rounded p-1 text-fg-muted hover:bg-surface-active hover:text-danger",children:e.jsx(Oe,{width:12,height:12})})]})]})})}function Fo({state:t}){const s={open:{c:"bg-success-solid",t:"connected"},connecting:{c:"bg-warn-solid animate-pulse",t:"connecting"},closed:{c:"bg-danger-solid",t:"offline"}}[t];return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${s.c}`}),s.t]})}const Oo=a.lazy(()=>ce(()=>import("./MarkdownRenderer-C-CUuFhT.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Zt=a.memo(function({children:s,mermaid:n=!1}){return e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(Oo,{mermaid:n,children:s})})}),Uo=new Set(["markdown","code","text","html","mermaid"]);function us(t){return Uo.has(t)}function Ha(t){const s=t.source==="file"&&us(t.kind)?t.rawUrl:void 0,[n,r]=a.useState(null);return a.useEffect(()=>{if(t.source!=="file"||!us(t.kind))return;if(!s){r({error:!0});return}let i=!1;return r(null),fetch(s).then(o=>o.ok?o.text():Promise.reject(new Error(String(o.status)))).then(o=>!i&&r({text:o})).catch(()=>!i&&r({error:!0})),()=>{i=!0}},[s,t.source,t.kind]),us(t.kind)?t.source==="inline"?{text:t.content??""}:n:null}const Bo={markdown:"text/markdown",html:"text/html"},hs="flex items-center px-2.5 text-fg-subtle motion-fast transition-colors hover:bg-surface-hover hover:text-fg focus-visible:focus-ring disabled:pointer-events-none disabled:opacity-40";function Vo({file:t,text:s}){return e.jsxs(e.Fragment,{children:[us(t.kind)?e.jsx(zo,{filename:t.filename,text:s}):null,t.kind==="image"||t.kind==="pdf"?null:e.jsx(Ho,{file:t,failed:s!==null&&"error"in s})]})}function zo({filename:t,text:s}){const[n,r]=a.useState("idle");a.useEffect(()=>{if(n==="idle")return;const c=setTimeout(()=>r("idle"),1600);return()=>clearTimeout(c)},[n]);const i=s!==null&&"text"in s,o=()=>{if(!i)return;const c=navigator.clipboard;if(!c){r("failed");return}c.writeText(s.text).then(()=>r("copied"),()=>r("failed"))},l=n==="copied"?"Copied":n==="failed"?"Couldn't copy":s===null?"Loading…":"error"in s?"Couldn't load this file":"Copy source";return e.jsxs("button",{type:"button",onClick:o,disabled:!i,"aria-label":`Copy ${t}`,title:l,className:hs,children:[n==="copied"?e.jsx(It,{width:13,height:13,className:"text-success"}):n==="failed"?e.jsx(pe,{width:13,height:13,className:"text-danger"}):e.jsx(Ir,{width:13,height:13}),e.jsx("span",{className:"sr-only",role:"status",children:n==="copied"?"Copied":n==="failed"?"Couldn't copy":""})]})}function Ho({file:t,failed:s}){const n=`Download ${t.filename}`;if(t.source==="file")return t.rawUrl?s?e.jsx("button",{type:"button",disabled:!0,"aria-label":n,title:"Couldn't load this file",className:hs,children:e.jsx(Ps,{width:13,height:13})}):e.jsx("a",{href:t.rawUrl,download:t.filename,"aria-label":n,title:"Download",className:hs,children:e.jsx(Ps,{width:13,height:13})}):null;const r=()=>{const i=`${Bo[t.kind]??"text/plain"};charset=utf-8`,o=URL.createObjectURL(new Blob([t.content??""],{type:i})),l=document.createElement("a");l.href=o,l.download=t.filename,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(o),1e3)};return e.jsx("button",{type:"button",onClick:r,"aria-label":n,title:"Download",className:hs,children:e.jsx(Ps,{width:13,height:13})})}const Wo={tsx:"typescript",jsx:"javascript",html:"xml"};function Ko(t){if(!t)return;const s=t.toLowerCase();return Wo[s]??s}let Us=null;async function Go(){return Us||(Us=(async()=>{const{default:t}=await ce(async()=>{const{default:S}=await import("./core-CTNNIHx5.js");return{default:S}},__vite__mapDeps([9,1,2])),[s,n,r,i,o,l,c,m,u,b,f,h,j,x,k,d,p,D,$,I,C]=await Promise.all([ce(()=>import("./typescript-C2FFdlUC.js"),[]),ce(()=>import("./javascript-BKRaQes9.js"),[]),ce(()=>import("./python-kSlZHhJb.js"),[]),ce(()=>import("./ruby-7T4ktxyv.js"),[]),ce(()=>import("./go-BPx_y7j8.js"),[]),ce(()=>import("./rust-HC3MBUhY.js"),[]),ce(()=>import("./java-B5VKqtH2.js"),[]),ce(()=>import("./c-D2F1sQUL.js"),[]),ce(()=>import("./cpp-Bm3ii6kY.js"),[]),ce(()=>import("./csharp-BNpuYZMG.js"),[]),ce(()=>import("./php-CRdd4dfS.js"),[]),ce(()=>import("./swift-Dn8kKO_1.js"),[]),ce(()=>import("./kotlin-Cw-eF_bm.js"),[]),ce(()=>import("./bash-I8pq0VWm.js"),[]),ce(()=>import("./sql-BC88IN-V.js"),[]),ce(()=>import("./json-DIYVocXf.js"),[]),ce(()=>import("./yaml-drsDnIKT.js"),[]),ce(()=>import("./ini-B3BVgEsG.js"),[]),ce(()=>import("./css-DazXZka4.js"),[]),ce(()=>import("./scss-DZLA7YXz.js"),[]),ce(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",n.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",i.default),t.registerLanguage("go",o.default),t.registerLanguage("rust",l.default),t.registerLanguage("java",c.default),t.registerLanguage("c",m.default),t.registerLanguage("cpp",u.default),t.registerLanguage("csharp",b.default),t.registerLanguage("php",f.default),t.registerLanguage("swift",h.default),t.registerLanguage("kotlin",j.default),t.registerLanguage("bash",x.default),t.registerLanguage("sql",k.default),t.registerLanguage("json",d.default),t.registerLanguage("yaml",p.default),t.registerLanguage("toml",D.default),t.registerLanguage("css",$.default),t.registerLanguage("scss",I.default),t.registerLanguage("xml",C.default),t})()),Us}function qo({code:t,language:s}){const[n,r]=a.useState(null),i=Ko(s);a.useEffect(()=>{if(!i){r(null);return}let l=!1;return r(null),(async()=>{try{const c=await Go();if(l||!c.getLanguage(i))return;const{value:m}=c.highlight(t,{language:i});l||r(m)}catch{}})(),()=>{l=!0}},[t,i]);const o="overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg";return n!==null?e.jsx("pre",{className:o,children:e.jsx("code",{className:`hljs language-${i}`,dangerouslySetInnerHTML:{__html:n}})}):e.jsx("pre",{className:o,children:e.jsx("code",{children:t})})}let Bs=null;function Qo(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function Yo(){return Bs||(Bs=ce(()=>import("./mermaid.core-CrChvyj6.js").then(t=>t.bm),__vite__mapDeps([10,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:Qo()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),Bs}function Jo({code:t}){const n="mmd-"+a.useId().replace(/[^a-zA-Z0-9-]/g,""),r=a.useRef(null),[i,o]=a.useState(null);return a.useEffect(()=>{let l=!1;return o(null),(async()=>{try{const c=await Yo();await c.parse(t);const{svg:m,bindFunctions:u}=await c.render(n+"-svg",t);if(l||!r.current)return;r.current.innerHTML=m,u==null||u(r.current)}catch(c){if(l)return;o(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{l=!0}},[t,n]),i?e.jsxs("div",{className:"my-3 rounded-lg border border-warn-edge bg-warn-soft p-3 text-xs",children:[e.jsx("p",{className:"font-semibold text-warn",children:"Couldn't render this Mermaid diagram"}),e.jsx("p",{className:"mt-1 text-warn",children:i}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-surface-sunken p-2 font-mono text-2xs text-fg-muted",children:t})]}):e.jsx("div",{ref:r,"data-testid":"mermaid",className:"mermaid-host my-3 flex justify-center overflow-x-auto rounded-lg border border-edge bg-surface-raised p-3"})}const Xo="paddock:itemHeight:";function dn(t){return Xo+t}function Wn(t){try{const s=localStorage.getItem(dn(t));if(s==null)return null;const n=Number(s);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function Zo(t,s){try{const n=dn(t);Number.isFinite(s)&&s>0?localStorage.setItem(n,String(Math.round(s))):localStorage.removeItem(n)}catch{}}function el(t){try{localStorage.removeItem(dn(t))}catch{}}function tl({itemId:t,children:s,defaultMaxHeight:n=360,minHeight:r=80}){const i=a.useRef(null),[o,l]=a.useState(0),[c,m]=a.useState(()=>Wn(t));a.useEffect(()=>{m(Wn(t))},[t]),a.useEffect(()=>{if(!i.current)return;const j=()=>{var k;return l(((k=i.current)==null?void 0:k.scrollHeight)||0)};if(j(),typeof ResizeObserver>"u")return;const x=new ResizeObserver(j);return x.observe(i.current),()=>x.disconnect()},[s]);const u=o>0,b=u?o:Number.POSITIVE_INFINITY;let f=!1,h=0;return c!=null?(f=!0,h=Wa(c,r,b)):u&&o>n&&(f=!0,h=n),e.jsxs("div",{className:f?"group relative":void 0,style:f?{height:h}:void 0,children:[e.jsx("div",{className:f?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:i,children:s})}),f?e.jsx(sl,{appliedHeight:h,onResize:j=>m(j),onCommit:j=>Zo(t,j),onReset:()=>{el(t),m(null)},minHeight:r,maxHeight:b}):null]})}function sl({appliedHeight:t,onResize:s,onCommit:n,onReset:r,minHeight:i,maxHeight:o}){const l=a.useRef(null),c=a.useRef(t);c.current=t;const m=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:u=>{l.current={startY:u.clientY,startHeight:t},u.currentTarget.setPointerCapture(u.pointerId)},onPointerMove:u=>{if(!l.current)return;const b=Kn(l.current.startHeight,u.clientY-l.current.startY,i,o);s(b)},onPointerUp:u=>{if(l.current){l.current=null;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}n(c.current)}},onDoubleClick:r,onKeyDown:u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const b=u.key==="ArrowDown"?m:-m,f=Kn(t,b,i,o);s(f),n(f)}},className:"absolute inset-x-0 bottom-0 flex h-2 cursor-ns-resize touch-none items-center justify-center border-t border-edge-subtle bg-surface-sunken opacity-60 transition hover:bg-surface-hover hover:opacity-100",children:e.jsx("span",{className:"h-0.5 w-8 rounded-full bg-edge-strong group-hover:bg-fg-subtle"})})}function Kn(t,s,n,r){return Wa(t+s,n,r)}function Wa(t,s,n){return Math.min(Math.max(t,s),n)}function Ka({src:t,filename:s,message:n,onMaximize:r}){const[i,o]=a.useState(!1),[l,c]=a.useState(!1),m=r??(()=>c(!0)),u="repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px";return!t||i?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsxs("div",{className:"group relative flex items-center justify-center overflow-auto p-4",style:{background:u},children:[e.jsx("img",{src:t,alt:s,onError:()=>o(!0),onClick:m,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),m())},role:"button",tabIndex:0,"aria-label":`Open ${s} full screen`,className:"max-h-[480px] max-w-full cursor-zoom-in object-contain shadow-sm"}),e.jsx(Ga,{src:t,filename:s,onMaximize:m}),l?e.jsx(nl,{src:t,filename:s,message:n,onClose:()=>c(!1)}):null]})}function Ga({src:t,filename:s,onMaximize:n}){const r="pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/55 text-white shadow-sm transition-colors hover:bg-black/75 focus-visible:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";return e.jsxs("div",{className:"pointer-events-none absolute bottom-2 right-2 z-10 flex items-center gap-1.5 opacity-100 transition-opacity can-hover:opacity-0 can-hover:group-hover:opacity-100 can-hover:group-focus-within:opacity-100",children:[e.jsx("a",{href:t,download:s,className:r,"aria-label":`Download ${s}`,title:"Download",children:e.jsx(al,{})}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:r,"aria-label":`Open ${s} in new tab`,title:"Open in new tab",children:e.jsx(rl,{})}),n?e.jsx("button",{type:"button",onClick:n,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(il,{})}):null]})}function nl({src:t,filename:s,message:n,onClose:r}){const i=a.useRef(null);return a.useEffect(()=>{var c;const o=m=>{m.key==="Escape"&&r()};document.addEventListener("keydown",o);const l=document.body.style.overflow;return document.body.style.overflow="hidden",(c=i.current)==null||c.focus(),()=>{document.removeEventListener("keydown",o),document.body.style.overflow=l}},[r]),ja.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:r,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-4 bg-overlay-strong p-6",children:[e.jsx("button",{ref:i,type:"button",onClick:r,"aria-label":"Close",title:"Close",className:"absolute right-4 top-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70",children:e.jsx(ol,{})}),e.jsx("img",{src:t,alt:s,onClick:o=>o.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:o=>o.stopPropagation(),className:"max-w-[95vw] text-center text-sm text-white/90",children:[e.jsx("div",{className:"font-mono text-white/70",children:s}),n?e.jsx("div",{className:"mt-1",children:n}):null]})]}),document.body)}function ys({children:t}){return e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}function al(){return e.jsxs(ys,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function rl(){return e.jsxs(ys,{children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function il(){return e.jsx(ys,{children:e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M16 21h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}function ol(){return e.jsx(ys,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function un({src:t,filename:s,className:n="h-[600px] w-full"}){return t?e.jsxs("div",{className:`group relative ${n}`,children:[e.jsx("object",{data:t,type:"application/pdf","aria-label":s,className:"h-full w-full bg-surface-sunken",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center text-sm text-fg-muted",children:[e.jsx(Qt,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-fg",children:s}),e.jsx("span",{className:"text-xs text-fg-muted",children:"This browser can’t show the PDF inline."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:"rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-surface motion-fast transition-colors hover:bg-fg-muted",children:"Open in new tab"}),e.jsx("a",{href:t,download:s,className:"rounded-md px-3 py-1.5 text-xs font-medium text-fg-muted ring-1 ring-edge-strong hover:bg-surface-hover",children:"Download"})]})]})}),e.jsx(Ga,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function ll({file:t,turnId:s}){const[n,r]=a.useState(!0),i=a.useContext(Ua),o=i&&s?()=>i.open(s,t):void 0,l=gs(t),c=Ha(t);return e.jsx("div",{className:"flex animate-fade-in justify-start","data-sent-file-turn":s,children:e.jsxs("div",{className:"w-full max-w-[92%] overflow-hidden rounded-2xl rounded-bl-md bg-surface-raised shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"flex items-stretch border-b border-edge bg-surface-sunken text-2xs text-fg-muted",children:[e.jsxs("button",{type:"button",onClick:()=>r(m=>!m),"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 px-4 py-2 text-left",children:[e.jsx(hl,{open:n}),e.jsx(ml,{}),e.jsx("span",{className:"truncate font-mono text-fg-muted",children:t.filename}),e.jsx("span",{className:"ml-auto uppercase tracking-wide text-3xs text-fg-subtle",children:t.language??t.kind})]}),e.jsx(Vo,{file:t,text:c}),o?e.jsx("button",{type:"button",onClick:o,"aria-label":`Maximize ${t.filename}`,title:"Maximize",className:"flex items-center px-3 text-fg-subtle motion-fast transition-colors hover:bg-surface-hover hover:text-fg",children:e.jsx(fl,{})}):null]}),t.message?e.jsx("div",{className:"border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted",children:t.message}):null,n?e.jsx(qa,{file:t,itemId:l,onMaximize:o,text:c}):null]})})}function gs(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${cl(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function cl(t){let s=5381;for(let n=0;n<t.length;n++)s=(s<<5)+s+t.charCodeAt(n)|0;return(s>>>0).toString(36)}function qa({file:t,itemId:s,onMaximize:n,fill:r=!1,text:i}){return t.kind==="image"?e.jsx(Ka,{src:t.rawUrl,filename:t.filename,message:t.message,onMaximize:n}):t.kind==="video"?e.jsx(ul,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(un,{src:t.rawUrl,filename:t.filename,className:r?"h-full w-full":void 0}):t.source==="inline"?e.jsx(Qa,{kind:t.kind,text:t.content??"",language:t.language,itemId:s,fill:r}):i!==void 0?e.jsx(Ya,{state:i,kind:t.kind,language:t.language,itemId:s,fill:r}):e.jsx(dl,{file:t,itemId:s,fill:r})}function Qa({kind:t,text:s,language:n,itemId:r,fill:i=!1}){return t==="html"?e.jsx("iframe",{title:"sent-file",sandbox:"allow-scripts",srcDoc:s,className:`html-preview w-full ${i?"h-full":"min-h-[360px]"}`}):t==="mermaid"?e.jsx("div",{className:"p-4",children:e.jsx(Jo,{code:s})}):t==="markdown"?e.jsx(Vs,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Zt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(Vs,{itemId:r,children:e.jsx(qo,{code:s,language:n})}):e.jsx(Vs,{itemId:r,children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg",children:s})})}function Vs({itemId:t,children:s}){return t?e.jsx(tl,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function dl({file:t,itemId:s,fill:n}){const r=Ha(t);return e.jsx(Ya,{state:r,kind:t.kind,language:t.language,itemId:s,fill:n})}function Ya({state:t,kind:s,language:n,itemId:r,fill:i}){return t===null?e.jsx("div",{className:"px-4 py-3 text-xs text-fg-subtle",children:"Loading…"}):"error"in t?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(Qa,{kind:s,text:t.text,language:n,itemId:r,fill:i})}function ul({src:t,filename:s}){return t?e.jsx("div",{className:"flex items-center justify-center overflow-hidden bg-surface-sunken p-4",children:e.jsx("video",{src:t,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[480px] w-full rounded-sm shadow-sm",children:e.jsxs("p",{className:"p-4 text-sm text-fg-muted",children:["Your browser can’t play this video."," ",e.jsxs("a",{href:t,download:s,className:"underline",children:["Download ",s]})]})})}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function hl({open:t}){return e.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-subtle transition-transform ${t?"rotate-90":""}`,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})}function ml(){return e.jsxs("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("path",{d:"M14 2v6h6"})]})}function fl(){return e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M16 21h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}const hn=a.memo(function({turn:s}){return s.kind==="user"?e.jsxs("div",{className:"flex animate-fade-in flex-col items-end",children:[s.sender?e.jsx(wl,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(Bi,{attachments:s.attachments}):null,s.content?e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-accent-solid px-4 py-2.5 text-sm text-accent-fg shadow-sm",children:s.content}):null]}):s.kind==="file"?e.jsx(ll,{file:s.file,turnId:s.id}):s.kind==="tool"?e.jsx(Nl,{tool:s.tool}):s.kind==="command"?e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"rounded-full bg-surface-active px-2.5 py-0.5 font-mono text-xs text-fg-muted ring-1 ring-edge",children:s.command})}):s.kind==="commandOutput"?s.content?e.jsx(bl,{content:s.content}):null:s.kind==="compact"?e.jsx(jl,{summary:s.summary}):s.kind==="notice"?e.jsx(yl,{notice:s.notice}):s.kind==="notification"?Er(s.status)?e.jsx(vl,{summary:s.summary}):e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"max-w-[85%] truncate rounded-full bg-surface-sunken px-2.5 py-0.5 text-xs italic text-fg-muted ring-1 ring-edge",title:s.summary,children:s.summary})}):e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsx("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-raised px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:s.content?e.jsx("div",{className:s.streaming?"streaming-caret":void 0,children:e.jsx(Zt,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"})]})})})}),xl=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function pl({turn:t}){const s=a.useContext(Oa);return!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&xl.test(t.id)?e.jsx(gl,{turn:t,actions:s}):e.jsx(hn,{turn:t})}function gl({turn:t,actions:s}){var p;const n=t.id.split("#")[0],r=t.id===n,i=s.linkTo(n),o=a.useRef(null),[l,c]=a.useState(!1),[m,u]=a.useState(!1),b=r&&((p=s.focused)==null?void 0:p.uuid)===n?s.focused.nonce:null;a.useEffect(()=>{var $;if(b==null)return;($=o.current)==null||$.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const D=setTimeout(()=>u(!1),3200);return()=>clearTimeout(D)},[b]),a.useEffect(()=>{if(!l)return;const D=setTimeout(()=>c(!1),1600);return()=>clearTimeout(D)},[l]);const f=D=>{var $;D.metaKey||D.ctrlKey||D.shiftKey||D.altKey||D.button!==0||(D.preventDefault(),($=navigator.clipboard)==null||$.writeText(i).then(()=>c(!0)).catch(()=>c(!1)))},h=t.contextTokens,j=s.contextLimit,x=h!=null&&j?Math.min(100,Math.round(h/j*100)):null,k="flex items-center rounded-full bg-surface/95 shadow-sm ring-1 ring-edge backdrop-blur",d=`${k} h-6 w-6 justify-center text-fg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`;return e.jsxs("div",{ref:o,id:r?wa(n):void 0,className:`group relative rounded-lg ${m?"reveal-flash":""}`,children:[e.jsxs("div",{className:"pointer-events-none absolute -top-3 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100",children:[e.jsx("a",{href:i,onClick:f,title:`Copy a link to this message · ${new Date(t.timestamp).toLocaleString()}`,"aria-label":`Copy a link to this message (${Et(t.timestamp)})`,className:`${k} gap-1 px-2 py-0.5 text-2xs text-fg-muted transition-colors hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:l?e.jsx("span",{className:"text-accent",children:"Link copied"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:Et(t.timestamp)}),h!=null?e.jsxs("span",{className:"text-fg-subtle tabular",title:"Context-window fill as of this message",children:["· ",ga(h),x!=null?` · ${x}%`:""]}):null]})}),e.jsx("button",{type:"button",onClick:()=>s.onFork(n),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${d} hover:text-accent`,children:e.jsx(ft,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(n),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${d} hover:text-danger`,children:e.jsx(Xe,{width:13,height:13})})]}),e.jsx(hn,{turn:t})]})}function Me({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-fg-subtle",style:{animationDelay:t}})}function bl({content:t}){return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-sunken px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-2xs italic text-fg-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"⌨"}),e.jsx("span",{children:"command output"})]}),e.jsx(Zt,{children:t})]})})}function jl({summary:t}){return e.jsx("div",{className:"animate-fade-in py-1",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-3 text-xs text-fg-muted",children:[e.jsx("span",{className:"h-px flex-1 bg-edge"}),e.jsx("span",{className:"whitespace-nowrap",children:"🗜️ conversation compacted"}),e.jsx("span",{className:"h-px flex-1 bg-edge"})]}),e.jsx("div",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:t})]})})}function wl({sender:t}){var r;const s="mb-1 flex items-center gap-1 text-2xs italic text-fg-muted";if(t.kind==="schedule")return e.jsxs("div",{className:s,"data-sender":"schedule",children:[e.jsx("span",{"aria-hidden":!0,children:"⏰"}),e.jsxs("span",{children:["scheduled by ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="hook")return e.jsxs("div",{className:s,"data-sender":"hook",children:[e.jsx("span",{"aria-hidden":!0,children:"⚡"}),e.jsxs("span",{children:["triggered by hook ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="recovery")return e.jsxs("div",{className:s,"data-sender":"recovery",children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:"continued after a background task was terminated"})]});if(t.kind==="agent")return e.jsxs("div",{className:s,"data-sender":"agent",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsx("span",{children:"sent by an agent"})]});const n=((r=t.name)==null?void 0:r.trim())||t.sessionId.slice(0,8);return e.jsxs("div",{className:s,"data-sender":"chat",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsxs("span",{children:["sent by"," ",e.jsx(rn,{to:`/projects/${encodeURIComponent(t.project)}/chat/${encodeURIComponent(t.sessionId)}`,className:"font-medium not-italic text-accent hover:underline",title:`Open ${n} in ${t.project}`,children:n})]})]})}function vl({summary:t}){const s=a.useContext(cn),n=!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy);return e.jsx("div",{className:"flex animate-fade-in justify-center","data-recovery":"killed-task",children:e.jsxs("div",{className:"flex max-w-[90%] flex-col gap-1.5 rounded-lg border border-warn-edge bg-warn-soft px-3 py-2 text-xs text-warn",children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:"⚠"}),e.jsxs("span",{className:"leading-snug",children:["A background task was terminated at the turn boundary — Claude is idle and will not continue on its own.",e.jsx("span",{className:"mt-0.5 block text-2xs text-warn",children:t})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-recovery-action":"continue",className:"motion-fast rounded-md bg-warn-solid px-2.5 py-1 text-2xs font-medium text-warn-fg shadow-sm transition-[filter,box-shadow,opacity] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50",children:r?"Continuing…":"Continue"})})]})})}function yl({notice:t}){const s=a.useContext(cn),n=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),i=t.kind==="error",o=i?"border-danger-edge bg-danger-soft text-danger":"border-warn-edge bg-warn-soft text-warn",l=i?"bg-danger-solid text-danger-fg hover:brightness-110":"bg-warn-solid text-warn-fg hover:brightness-110",c=i?"text-danger":"text-warn",m=t.kind==="usage_limit"?"Session limit reached":t.kind==="max_turns"?"Turn limit reached":"The turn failed";return e.jsx("div",{className:"flex animate-fade-in justify-center","data-notice":t.kind,children:e.jsxs("div",{className:`flex max-w-[90%] flex-col gap-1.5 rounded-lg border px-3 py-2 text-xs ${o}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:i?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[m,"."]})," ",t.message,t.kind==="usage_limit"&&t.resetTime&&e.jsxs("span",{className:`mt-0.5 block text-2xs ${c}`,children:["Resets ",t.resetTime,". Claude will respond again after the quota resets."]}),i&&t.detail&&e.jsx("span",{className:`mt-0.5 block break-words font-mono text-2xs ${c}`,children:t.detail})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-notice-action":"retry",className:`motion-fast rounded-md px-2.5 py-1 text-2xs font-medium shadow-sm transition-[filter,box-shadow,opacity] disabled:cursor-not-allowed disabled:opacity-50 ${l}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function Nl({tool:t}){var N,U;const s=Qi(t.toolName),n=Yi(t.toolName,t.output),r=s.isPaddock?oo(s.tool):null,i=n!=null&&(n.tool==="create_chat"||n.tool==="fork_chat"||n.tool==="send_message"||n.tool==="fork_chat_batch"),[o,l]=a.useState(i),c=a.useContext(Fa),m=a.useContext(La),u=a.useRef(null),[b,f]=a.useState(!1),h=m!=null&&m.focused&&m.focused.toolUseId===t.toolUseId?m.focused.nonce:null;a.useEffect(()=>{var E;if(h==null)return;l(!0),(E=u.current)==null||E.scrollIntoView({behavior:"smooth",block:"center"}),f(!0);const Z=setTimeout(()=>f(!1),3200);return()=>clearTimeout(Z)},[h]);const j=a.useContext(_a),x=a.useContext(ln),k=!!t.pending,d=vs.has(t.toolName),p=t.toolUseId?x==null?void 0:x.get(t.toolUseId):void 0,D=d?xs(t.subagentDurationMs??(p==null?void 0:p.elapsedMs)):xs(t.durationMs),$=t.subagentCostUsd!=null?`~${pa(t.subagentCostUsd)}`:null,I=!d&&ro(t),C=t.monitorEvents??[],S=t.editDiff,M=!!S,y=t.toolName==="Read"?t.readInfo:void 0,T=y!=null&&y.isImage&&y.projectRelPath&&c?c(y.projectRelPath):null,w=t.toolName==="Bash"?t.bashDetails:void 0,F=t.searchInfo,O=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,z=t.toolName==="TaskCreate"?t.taskCreate:void 0,X=!!(w&&w.stderr),L=F?uo(F):null,v=y?ho(y):null,A=p!=null?p.running:to(t,j),W=!!(d&&t.hasSubagent&&t.toolUseId),Q=A&&t.toolUseId?(N=x==null?void 0:x.get(t.toolUseId))==null?void 0:N.latestStep:void 0,ie=d?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,K=d?Q??t.description:n?Ji(n):M?((U=S.filePath)==null?void 0:U.split("/").pop())??S.filePath:y?y.basename??y.filePath??t.inputSummary:z?z.subject:t.inputSummary,q=(y==null?void 0:y.filePath)??(z==null?void 0:z.description)??(Q?t.description:void 0)??K??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:u,className:`motion-fast w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-[color,background-color,border-color] ${b?"reveal-flash ":""}${t.isError?"border-danger-edge bg-danger-soft":d?"border-accent-edge bg-accent-soft":I?"border-info-edge bg-info-soft":"border-edge bg-surface-raised"}`,children:[e.jsxs("button",{type:"button",onClick:()=>l(Z=>!Z),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(At,{width:13,height:13,className:`motion-fast shrink-0 text-fg-subtle transition-transform ${o?"rotate-90":""}`}),d?e.jsx(Jt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):I?e.jsx(Xe,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-info"}`}):r?e.jsx(r,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):M?e.jsx(bs,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):y?e.jsx(Qt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):F?e.jsx(va,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):O||z?e.jsx(It,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):e.jsx(ya,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono font-semibold text-fg",children:ie}),d&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:"sub-agent"}),I&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-info-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-info",children:"background"}),s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:n&&"project"in n&&n.project?n.project:"Paddock"}),s.isMcp&&!s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-fg-muted",children:"MCP"}),O?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-fg-muted",children:[O.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",O.taskId]}),O.from&&O.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Gn,{status:O.from}),e.jsx("span",{className:"text-fg-subtle",children:"→"}),e.jsx(Gn,{status:O.to})]}):O.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:O.updatedFields.join(", ")})]}):K&&e.jsx("span",{className:`min-w-0 truncate font-mono ${Q?"text-accent":"text-fg-muted"}`,title:q,children:K}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[t.isError&&e.jsx("span",{className:"rounded bg-danger-soft px-1.5 py-0.5 text-3xs font-semibold text-danger",children:"error"}),k||A?e.jsxs("span",{className:"flex items-center gap-1.5 text-accent",title:"Sub-agent is running",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-accent-edge border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"text-3xs font-semibold uppercase tracking-wide",children:"running"})]}):e.jsxs(e.Fragment,{children:[I&&C.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-3xs text-info",children:[C.length," event",C.length===1?"":"s"]}),I&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${io(t.taskStatus)}`,children:t.taskStatus}),M&&(S.additions>0||S.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-3xs font-semibold tabular",children:[S.additions>0&&e.jsxs("span",{className:"text-success",children:["+",S.additions]}),S.additions>0&&S.deletions>0&&" ",S.deletions>0&&e.jsxs("span",{className:"text-danger",children:["−",S.deletions]})]}),v&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs text-fg-subtle tabular",children:v}),L&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs font-medium text-fg-muted tabular",children:L}),(w==null?void 0:w.gitHint)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 font-mono text-3xs text-fg-muted",children:w.gitHint}),(w==null?void 0:w.interrupted)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-warn-soft px-1.5 py-0.5 text-3xs font-semibold text-warn",children:"interrupted"}),(w==null?void 0:w.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-3xs italic text-fg-subtle",children:w.returnCodeInterpretation}),D&&e.jsx("span",{className:"text-fg-subtle tabular",children:D}),$&&e.jsx("span",{className:"text-fg-subtle tabular",children:$})]})]})]}),o&&(W?e.jsx(Tl,{toolUseId:t.toolUseId,live:A}):I&&C.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-info-edge bg-info-soft",children:C.map((Z,E)=>e.jsx("div",{className:"whitespace-pre-wrap break-words border-b border-info-edge px-3 py-1.5 font-mono text-2xs leading-relaxed text-fg-muted last:border-b-0",children:Z},E))}):n?e.jsx(eo,{data:n}):M?e.jsx(kl,{diff:S}):T?e.jsx("div",{className:"border-t border-edge",children:e.jsx(Ka,{src:T,filename:(y==null?void 0:y.basename)??"image"})}):X?e.jsx(Cl,{bash:w}):z&&z.description?e.jsx(Sl,{info:z}):e.jsxs("div",{className:"border-t border-edge",children:[I&&t.taskResultSummary&&e.jsx("div",{className:"border-b border-edge bg-info-soft px-3 py-2 text-2xs font-medium text-fg",children:t.taskResultSummary}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:k?"Running…":t.output||"(no output)"})]}))]})})}function kl({diff:t}){return e.jsxs("div",{className:"max-h-96 overflow-auto border-t border-edge bg-surface-sunken font-mono text-2xs leading-relaxed",children:[t.hunks.map((s,n)=>e.jsxs("div",{className:n>0?"border-t border-edge":"",children:[e.jsxs("div",{className:"bg-surface-active px-3 py-1 font-mono text-3xs font-semibold text-lineage",children:["@@ -",s.oldStart,",",s.oldLines," +",s.newStart,",",s.newLines," @@"]}),s.lines.map((r,i)=>e.jsxs("div",{className:`flex ${lo(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:Fn(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:Fn(r.newLine)}),e.jsx("span",{className:"w-3 shrink-0 select-none text-center opacity-60",children:r.t===" "?"":r.t}),e.jsx("span",{className:"whitespace-pre-wrap break-words pr-3",children:r.text||" "})]},i))]},n)),t.truncated&&e.jsx("div",{className:"px-3 py-1.5 text-2xs italic text-fg-subtle",children:"… diff truncated (see the file for the full change)"})]})}function Gn({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${co(t)}`,children:t})}function Cl({bash:t}){return e.jsxs("div",{className:"max-h-72 overflow-auto border-t border-edge",children:[t.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:t.stdout}),t.stderr&&e.jsx("pre",{className:"whitespace-pre-wrap break-words border-t border-danger-edge bg-danger-soft px-3 py-2 font-mono text-2xs leading-relaxed text-danger first:border-t-0",children:t.stderr})]})}function Sl({info:t}){return e.jsxs("div",{className:"border-t border-edge bg-surface-sunken px-3 py-2",children:[t.subject&&e.jsx("div",{className:"text-xs font-semibold text-fg",children:t.subject}),t.description&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:t.description})]})}const qn=2e3;function Tl({toolUseId:t,live:s=!1}){var b,f;const n=a.useContext(Pa),[r,i]=a.useState(null),[o,l]=a.useState(!1),c=(f=(b=a.useContext(ln))==null?void 0:b.get(t))==null?void 0:f.messages;a.useEffect(()=>{i(null),l(!1)},[t]),a.useEffect(()=>{if(c)return;if(!n){l(!0);return}let h=!1,j;const x=()=>{n(t).then(k=>{h||(i(k),s&&(j=setTimeout(x,qn)))}).catch(()=>{h||(s?j=setTimeout(x,qn):l(!0))})};return x(),()=>{h=!0,j&&clearTimeout(j)}},[n,t,s,!!c]);const m=c??r,u=a.useMemo(()=>Tt(m??[]),[m]);return e.jsx("div",{"data-testid":"subagent-steps",className:"border-t border-edge bg-surface-sunken px-3 py-3",children:o?e.jsx("div",{className:"text-2xs text-danger",children:"couldn't load sub-agent steps"}):m==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):u.length===0?e.jsx("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"waiting for sub-agent steps…"})]}):e.jsx("span",{children:"(no recorded steps)"})}):e.jsxs("div",{className:"space-y-3 border-l-2 border-accent-edge pl-3",children:[u.map(h=>e.jsx(hn,{turn:h},h.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-accent",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function $l(t){const{projectSlug:s,initialSessionId:n,loadHistory:r,onSessionEstablished:i,onSessionStarted:o,onTurnComplete:l,sessionRef:c,jobRef:m,pendingCancelRef:u,streamingRef:b,awaitingSessionRef:f,isNewSessionRef:h,startedNotifiedRef:j,establishedHereRef:x,modelRef:k,cancelledRef:d,noticeThisTurnRef:p,seenInjectionsRef:D,onQueuedFlushedRef:$,onQueuedStateRef:I,onQueuedReturnedRef:C,setTurns:S,setStreaming:M,setUsage:y,setSessionUsage:T,setError:w}=t;a.useEffect(()=>{const F=L=>{const v=c.current;return v?L.sessionId===v?!0:L.sessionId==null&&b.current:f.current},O=L=>{c.current=L,f.current=!1,X.setSessionId(L),h.current&&!j.current&&(j.current=!0,x.current=L,k.current&&Js(L,s,k.current),o==null||o(L))},z=L=>{m.current=L,u.current&&(u.current=!1,be.cancel(L))},X=be.subscribe(s,c.current,{onResponse:(L,v)=>{F(v)&&(v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId),fo(S,L))},onToolStart:(L,v)=>{F(v)&&(v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId),S(A=>L.toolUseId&&A.some(W=>W.kind==="tool"&&W.tool.toolUseId===L.toolUseId)?A:[...Fe(A),{kind:"tool",id:Je(),tool:L}]))},onToolCall:(L,v)=>{if(!F(v))return;v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId);const A=Da(L);S(W=>{if(L.toolUseId){const ie=W.findIndex(K=>K.kind==="tool"&&K.tool.toolUseId===L.toolUseId);if(ie!==-1){const K=W[ie].id,q=W.slice();return q[ie]=A?{kind:"file",id:K,file:A}:{kind:"tool",id:K,tool:L},q}}const Q=A?{kind:"file",id:Je(),file:A}:{kind:"tool",id:Je(),tool:L};return[...Fe(W),Q]})},onMessageBoundary:L=>{F(L)&&(L.jobId&&z(L.jobId),S(v=>Fe(v)))},onComplete:L=>{if(F(L)){L.jobId&&z(L.jobId),b.current=!1,M(!1),S(v=>On(Fe(v))),L.usage&&y(L.usage);{const v=L.sessionId??c.current;v&&B.chatContext(s,v).then(A=>T(A)).catch(()=>{})}if(L.sessionId){const v=h.current&&c.current!==L.sessionId;O(L.sessionId),(v||h.current)&&(h.current=!1,k.current&&Js(L.sessionId,s,k.current),x.current=L.sessionId,i==null||i(L.sessionId))}!L.success&&L.error&&!p.current&&w(L.error);{const v=L.sessionId??c.current;l==null||l(v&&L.usage?{sessionId:v,usage:L.usage}:void 0)}d.current=!1}},onError:L=>{b.current&&(b.current=!1,M(!1),m.current=null,S(v=>On(Fe(v))),w(L),d.current=!1)},onResync:()=>{const L=c.current;!L||!r||r(L).then(({messages:v})=>S(Tt(v))).catch(()=>{})},onActive:({turnRunning:L,jobId:v})=>{L?(v&&z(v),b.current=!0,M(!0)):(b.current=!1,M(!1),m.current=null,S(A=>Fe(A)),d.current=!1,u.current=!1)},onQueuedFlushed:({text:L,attachments:v})=>{$.current(L,v)},onQueuedState:({text:L,qid:v,reason:A,attachments:W})=>{I.current(L,v,A,W)},onQueuedReturned:({text:L,attachments:v})=>{C.current(L,v)},onInjected:(L,v)=>{if(!F(v))return;v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId);const A=`${L.timestamp} ${L.content}`;D.current.has(A)||(D.current.add(A),S(W=>[...Fe(W),{kind:"user",id:Je(),content:L.content,sender:L.sender}]))},onKilledTask:({summary:L,timestamp:v})=>{const A=`killed ${v}`;D.current.has(A)||(D.current.add(A),S(W=>[...Fe(W),{kind:"notification",id:Je(),summary:L,status:"killed"}]))},onNotice:(L,v)=>{F(v)&&(p.current=!0,S(A=>[...Fe(A),{kind:"notice",id:Je(),notice:L}]))}});return()=>{X.unsubscribe()}},[s,n,r,i,o,l])}function Il({turns:t,omitted:s,loadEarlier:n,reveal:r}){const i=a.useMemo(()=>t.flatMap(S=>S.kind==="file"?[{id:S.id,file:S.file}]:[]),[t]),o=a.useRef(i);o.current=i;const[l,c]=a.useState(null),[m,u]=a.useState("idle"),[b,f]=a.useState(!1),[h,j]=a.useState(null),x=a.useMemo(()=>{if(!l||l.single)return-1;const S=i.findIndex(y=>y.id===l.id);if(S!==-1)return S;const M=gs(l.file);return i.findIndex(y=>gs(y.file)===M)},[i,l]);a.useEffect(()=>{l&&!l.single&&x===-1&&c(null)},[l,x]);const k=a.useCallback(S=>{const M=o.current[S];M&&(c({id:M.id,file:M.file,single:!1}),u("idle"),j(y=>({id:M.id,nonce:((y==null?void 0:y.nonce)??0)+1})))},[]);a.useEffect(()=>{h&&r(h.id)},[h,r]);const d=s>0&&!!n,p=a.useCallback(()=>{if(!(!l||l.single)){if(x>0)return k(x-1);x!==0||!d||m==="loading"||(u("loading"),n().then(()=>f(!0)).catch(()=>u("error")))}},[l,x,k,d,m,n]);a.useEffect(()=>{b&&(f(!1),x>0?k(x-1):u("none"))},[b,x,k]);const D=a.useCallback(()=>{l&&!l.single&&x<i.length-1&&k(x+1)},[l,x,i.length,k]),$=a.useCallback(()=>{c(null),u("idle")},[]),I=a.useMemo(()=>({open:(S,M)=>{const y=!o.current.some(T=>T.id===S);c({id:S,file:M,single:y}),u("idle")}}),[]),C=l?{file:x===-1?l.file:i[x].file,position:x===-1?null:{index:x,total:i.length},canPrev:x>0||x===0&&d,canNext:x!==-1&&x<i.length-1,earlier:x===0?d&&m==="idle"?"withheld":m:"idle",onPrev:p,onNext:D,onClose:$}:null;return{context:I,viewer:C}}const El={idle:null,withheld:"Earlier messages aren’t loaded — ← loads them",loading:"Loading earlier messages…",none:"No earlier files in this chat",error:"Couldn’t load earlier messages — ← to retry"};function Rl({file:t,position:s,canPrev:n,canNext:r,earlier:i,onPrev:o,onNext:l,onClose:c}){const m=a.useRef(null),u=a.useRef({onPrev:o,onNext:l,onClose:c,canPrev:n,canNext:r});u.current={onPrev:o,onNext:l,onClose:c,canPrev:n,canNext:r},a.useEffect(()=>{var k;const h=d=>{const p=u.current;if(d.key==="Escape")return p.onClose();d.key!=="ArrowLeft"&&d.key!=="ArrowRight"||d.altKey||d.ctrlKey||d.metaKey||d.shiftKey||Al(d.target)||(d.preventDefault(),d.key==="ArrowLeft"&&p.canPrev&&p.onPrev(),d.key==="ArrowRight"&&p.canNext&&p.onNext())};document.addEventListener("keydown",h);const j=document.body.style.overflow;document.body.style.overflow="hidden";const x=document.activeElement;return(k=m.current)==null||k.focus(),()=>{var d;document.removeEventListener("keydown",h),document.body.style.overflow=j,(d=x==null?void 0:x.focus)==null||d.call(x,{preventScroll:!0})}},[]);const b=El[i],f=h=>h.stopPropagation();return ja.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t.filename,onClick:c,className:"fixed inset-0 z-50 flex flex-col gap-3 bg-overlay-strong p-3 backdrop-blur-sm sm:p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm text-white/90",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-white/80",onClick:f,children:t.filename}),s?e.jsxs("span",{className:"shrink-0 tabular-nums text-xs text-white/60","aria-live":"polite",children:[s.index+1," / ",s.total]}):null,b?e.jsx("span",{className:"min-w-0 truncate text-xs text-white/60",role:"status",children:b}):null,e.jsx("button",{ref:m,type:"button",onClick:c,"aria-label":"Close",title:"Close (Esc)",className:`${Ja} ml-auto h-9 w-9 shrink-0`,children:e.jsx(Xa,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 items-center gap-2 sm:gap-3",children:[s?e.jsx(Qn,{side:"left",disabled:!n,onClick:o}):null,e.jsx("div",{className:"flex h-full min-w-0 flex-1 items-center justify-center",children:e.jsx(Ml,{file:t},gs(t))}),s?e.jsx(Qn,{side:"right",disabled:!r,onClick:l}):null]}),t.message?e.jsx("div",{onClick:f,className:"mx-auto max-w-3xl text-center text-sm text-white/90",children:t.message}):null]}),document.body)}function Ml({file:t}){const s=r=>r.stopPropagation();if(t.kind==="image"&&t.rawUrl)return e.jsx("img",{src:t.rawUrl,alt:t.filename,onClick:s,className:"max-h-full max-w-full object-contain"});if(t.kind==="video"&&t.rawUrl)return e.jsx("video",{src:t.rawUrl,controls:!0,playsInline:!0,preload:"metadata",onClick:s,className:"h-full w-full object-contain"});const n=t.kind==="pdf"||t.kind==="html";return e.jsx("div",{onClick:s,className:`w-full overflow-auto rounded-lg bg-surface-raised shadow-lg ring-1 ring-edge ${n?"h-full max-w-6xl":"max-h-full max-w-4xl"}`,children:e.jsx(qa,{file:t,fill:!0})})}const Ja="flex items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";function Qn({side:t,disabled:s,onClick:n}){const r=t==="left"?"Previous file":"Next file";return e.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),n()},disabled:s,"aria-label":r,title:`${r} (${t==="left"?"←":"→"})`,className:`${Ja} h-10 w-10 shrink-0 disabled:pointer-events-none disabled:opacity-30`,children:e.jsx(Xa,{children:e.jsx("path",{d:t==="left"?"M15 18l-6-6 6-6":"M9 18l6-6-6-6"})})})}function Al(t){return t instanceof HTMLElement?t.isContentEditable?!0:["INPUT","TEXTAREA","SELECT","VIDEO","AUDIO"].includes(t.tagName):!1}function Xa({children:t}){return e.jsx("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}const Za="paddock:attachments:",er="paddock:newchat-instance:";function Dl(){try{return crypto.randomUUID()}catch{return`n-${Math.random().toString(36).slice(2)}-${Date.now()}`}}function Pl(t){try{const s=er+t,n=sessionStorage.getItem(s);if(n)return n;const r=Dl();sessionStorage.setItem(s,r);try{localStorage.removeItem(`${Za}new:${t}`)}catch{}return r}catch{return"shared"}}function _l(t){try{localStorage.removeItem(qt(null,t))}catch{}try{sessionStorage.removeItem(er+t)}catch{}}function qt(t,s){return Za+(t??`new:${s}:${Pl(s)}`)}function Ll(t){if(!t||typeof t!="object")return null;const s=t;if(typeof s.id!="string"||!s.id||typeof s.filename!="string"||!s.filename)return null;const n={id:s.id,filename:s.filename,kind:typeof s.kind=="string"?s.kind:"file"};return typeof s.size=="number"&&Number.isFinite(s.size)&&(n.size=s.size),n}function Fl(t,s){try{const n=localStorage.getItem(qt(t,s));if(!n)return[];const r=JSON.parse(n);return Array.isArray(r)?r.map(Ll).filter(i=>i!==null):[]}catch{return[]}}function Ol(t,s,n){try{const r=qt(t,s);n.length>0?localStorage.setItem(r,JSON.stringify(n)):localStorage.removeItem(r)}catch{}}function Ul({projectSlug:t,initialSessionId:s,attachmentsDefault:n,projectAttachments:r,sessionRef:i,setError:o}){const[l,c]=a.useState(()=>Fl(s,t)),m=a.useRef([]);m.current=l;const[u,b]=a.useState(!1),[f,h]=a.useState(!1),j=a.useRef(null);a.useEffect(()=>{Ol(s,t,l)},[l,s,t]);const x=a.useRef(null);a.useEffect(()=>{if(!s){x.current=qt(null,t);return}const T=x.current;if(x.current=null,!(!T||T===qt(s,t)))try{localStorage.removeItem(T)}catch{}},[s,t]);const k=a.useMemo(()=>{const T=n??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},w=r??{};return{enabled:w.enabled??T.enabled,maxFileSizeMb:w.maxFileSizeMb??T.maxFileSizeMb,maxFilesPerMessage:w.maxFilesPerMessage??T.maxFilesPerMessage,allowedTypes:w.allowedTypes??T.allowedTypes}},[n,r]),d=k.enabled,p=a.useCallback(async T=>{if(!d||T.length===0)return;const w=k.maxFileSizeMb*1024*1024,F=k.maxFilesPerMessage-m.current.length;if(F<=0){o(`You can attach at most ${k.maxFilesPerMessage} files per message.`);return}const O=[];for(const z of T.slice(0,F)){if(!Ui(k.allowedTypes,z.type,z.name)){o(`File type not allowed: ${z.name}`);continue}if(z.size>w){o(`File too large (max ${k.maxFileSizeMb} MB): ${z.name}`);continue}O.push(z)}if(T.length>F&&o(`You can attach at most ${k.maxFilesPerMessage} files per message.`),O.length!==0){b(!0);try{const{files:z}=await B.uploadAttachments(t,i.current??"new",O);c(X=>[...X,...z])}catch(z){o(z instanceof Error?z.message:"Upload failed.")}finally{b(!1)}}},[d,k,t]),D=a.useCallback(T=>{c(w=>w.filter(F=>F.id!==T))},[]),$=a.useCallback(()=>{c([])},[]),I=a.useCallback(T=>{var F;if(!d)return;const w=Array.from(((F=T.clipboardData)==null?void 0:F.files)??[]);w.length>0&&(T.preventDefault(),p(w))},[d,p]),C=a.useCallback(T=>{var w;d&&Array.from(((w=T.dataTransfer)==null?void 0:w.types)??[]).includes("Files")&&(T.preventDefault(),h(!0))},[d]),S=a.useCallback(T=>{T.currentTarget===T.target&&h(!1)},[]),M=a.useCallback(T=>{var F;if(!d)return;const w=Array.from(((F=T.dataTransfer)==null?void 0:F.files)??[]);w.length>0&&(T.preventDefault(),h(!1),p(w))},[d,p]),y=a.useCallback(T=>{const w=Array.from(T.target.files??[]);w.length>0&&p(w),T.target.value=""},[p]);return{attachments:l,attachRef:m,setAttachments:c,uploading:u,dragOver:f,fileInputRef:j,attachConfig:k,attachEnabled:d,addFiles:p,removeAttachment:D,clearAttachments:$,onComposerPaste:I,onComposerDragOver:C,onComposerDragLeave:S,onComposerDrop:M,onPickFiles:y}}const Bl=15e3,Vl="no response — try again";function zl({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,preloadAvailable:l=!1,projectModel:c,projectModels:m,forkParent:u,onOpenForkParent:b,autoFocus:f,emptyHint:h,placeholder:j,trigger:x,projectRecovery:k,projectAttachments:d,onForkFromMessage:p,onRevertToMessage:D,onMessageLink:$,focusMessageUuid:I}){const[C,S]=a.useState([]),[M,y]=a.useState(0),[T,w]=a.useState(()=>Pi(s,t)),F=a.useRef(null),[O,z]=a.useState(!1),[X,L]=a.useState(!1),[v,A]=a.useState(null),[W,Q]=a.useState(null),[ie,K]=a.useState(be.state),[q,N]=a.useState(null),[U,Z]=a.useState(()=>li(s,t)),E=a.useRef(U),H=a.useRef(ci(s,t)),[de,we]=a.useState(()=>di(s,t)),le=a.useRef(de);le.current=de;const he=U!=null||de.length>0,Ne=a.useRef(!1),Ue=a.useRef(!1),[Ae,re]=a.useState(!0),Be=!s,ve=a.useRef(!1),[Te,se]=a.useState([]),[Ve,De]=a.useState(null),[$e,J]=a.useState(null),[me,Ie]=a.useState(null),[Dt,Ze]=a.useState(null),[ze,et]=a.useState([]),[He,We]=a.useState(0),[ke,P]=a.useState(!1),ee=a.useRef(null),[ae,ue]=a.useState(null),[ye,Ke]=a.useState(null),Pt=c??Ve,_t=a.useMemo(()=>m&&m.length>0?Te.filter(g=>m.includes(g.id)):Te,[Te,m]),Ee=a.useRef(s??null),it=a.useRef(null),Lt=a.useRef(!1),{attachments:Pe,attachRef:tt,setAttachments:ot,uploading:lt,dragOver:es,fileInputRef:Ft,attachConfig:Ot,attachEnabled:st,removeAttachment:Ns,clearAttachments:ks,onComposerPaste:Cs,onComposerDragOver:Ss,onComposerDragLeave:Ts,onComposerDrop:$s,onPickFiles:Is}=Ul({projectSlug:t,initialSessionId:s,attachmentsDefault:Dt,projectAttachments:d,sessionRef:Ee,setError:A}),xt=a.useRef(null),ts=a.useRef(Pe.length);a.useEffect(()=>{const g=Pe.length>ts.current;ts.current=Pe.length,g&&xt.current&&(xt.current.scrollTop=xt.current.scrollHeight)},[Pe.length]);const ss=a.useCallback(g=>Ee.current?B.subagentMessages(t,Ee.current,g):Promise.resolve([]),[t]),Ut=Eo(C),[ct,ns]=a.useState([]);a.useEffect(()=>{const g=s??null;if(!g){ns([]);return}return be.onBackgroundWork(g,ns)},[s]);const Bt=Io(ct),pt=$o(Ut,ss,O,Bt),[as,gt]=a.useState(new Set),[Es,bt]=a.useState(new Map),nt=a.useRef(new Map),at=a.useCallback(g=>{const R=nt.current.get(g);R!==void 0&&(clearTimeout(R),nt.current.delete(g))},[]);a.useEffect(()=>{const g=nt.current;return()=>{for(const R of g.values())clearTimeout(R);g.clear()}},[]),a.useEffect(()=>{const g=s??null;if(g)return be.onStopTaskResult(g,({taskId:R,outcome:G,message:V})=>{G!=="stopping"&&(at(R),gt(Y=>{if(!Y.has(R))return Y;const fe=new Set(Y);return fe.delete(R),fe}),G==="error"&&bt(Y=>new Map(Y).set(R,V||"the runtime refused the stop")))})},[s,at]);const Rs=a.useCallback(g=>{const R=s??null;if(!R)return;let G=!1;gt(V=>V.has(g)?(G=!0,V):new Set(V).add(g)),!G&&(bt(V=>{if(!V.has(g))return V;const Y=new Map(V);return Y.delete(g),Y}),at(g),nt.current.set(g,setTimeout(()=>{nt.current.delete(g),gt(V=>{if(!V.has(g))return V;const Y=new Set(V);return Y.delete(g),Y}),bt(V=>new Map(V).set(g,Vl))},Bl)),be.stopTask(R,g))},[s,at]);a.useEffect(()=>{const g=new Set(ct.map(R=>R.id));for(const R of[...nt.current.keys()])g.has(R)||at(R);gt(R=>{const G=new Set([...R].filter(V=>g.has(V)));return G.size===R.size?R:G}),bt(R=>{const G=new Map([...R].filter(([V])=>g.has(V)));return G.size===R.size?R:G})},[ct,at]);const jt=Ro(C),Ms=a.useMemo(()=>Ut.filter(g=>{var R;return!Bt.has(g.toolUseId)&&(((R=pt.get(g.toolUseId))==null?void 0:R.running)??O)}),[Ut,pt,O,Bt]),As=a.useMemo(()=>t?g=>B.projectFileRawUrl(t,g):null,[t]),wt=a.useRef(!s),vt=a.useRef(!1),yt=a.useRef(!1),_e=a.useRef(!1),rs=a.useRef(null),Nt=a.useRef(null),Ge=a.useRef(!0),is=a.useRef(new Set),xn=a.useCallback(()=>{const g=Nt.current;g&&(Ge.current=g.scrollHeight-g.scrollTop-g.clientHeight<80)},[]);a.useLayoutEffect(()=>{const g=Nt.current;g&&Ge.current&&(g.scrollTop=g.scrollHeight)},[C]);const[Vt,os]=a.useState(null),zt=a.useMemo(()=>({focused:Vt,focus:g=>{Ge.current=!1,os(R=>({toolUseId:g,nonce:((R==null?void 0:R.nonce)??0)+1}))}}),[Vt]);a.useEffect(()=>be.onState(K),[]),a.useEffect(()=>{let g=!1;return B.getModels().then(R=>{g||(se(R.models),De(R.defaultModel),Ie(R.recoveryDefault),Ze(R.attachmentsDefault))}).catch(()=>{}),()=>{g=!0}},[]),a.useEffect(()=>{let g=!1;return B.projectCommands(t).then(R=>{g||et(R)}).catch(()=>{}),()=>{g=!0}},[t]);const qe=a.useMemo(()=>{if(!T.startsWith("/"))return null;const g=T.slice(1);return/\s/.test(g)?null:g},[T]),Qe=a.useMemo(()=>{if(qe===null)return[];const g=qe.toLowerCase();return ze.filter(R=>R.name.toLowerCase().includes(g))},[qe,ze]),Ht=qe!==null&&!ke&&Qe.length>0;a.useEffect(()=>{We(0)},[qe]),a.useEffect(()=>{P(!1)},[qe]);const _=a.useCallback(g=>{w(`/${g.name} `),requestAnimationFrame(()=>{var R;return(R=F.current)==null?void 0:R.focus()})},[]),te=a.useCallback(g=>{J(g),ee.current=g,Js(Ee.current??s,t,g)},[t,s]);a.useEffect(()=>{if(s&&s===rs.current){wt.current=!1;return}let g=!1;return Ee.current=s??null,wt.current=!s,it.current=null,vt.current=!1,yt.current=!1,_e.current=!1,A(null),z(!1),s&&n?(L(!0),S([]),n(s).then(({messages:R,total:G,truncated:V})=>{g||(y(V?G-R.length:0),S(Y=>Fs(Tt(R),Y)))}).catch(()=>{g||A("Could not load this chat's history.")}).finally(()=>{g||L(!1)})):(S([]),L(!1)),s&&B.chatContext(t,s).then(R=>{g||!R||(ue({inputTokens:R.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:R.contextTokens,contextLimit:R.contextLimit}),Ke(R))}).catch(()=>{}),()=>{g=!0}},[t,s,n]);const oe=a.useCallback(async()=>{if(!(!s||!n)){try{const{messages:g,total:R,truncated:G}=await n(s);S(Tt(g)),y(G?R-g.length:0)}catch{A("Could not reload this chat's history.")}try{const g=await B.chatContext(t,s);g&&(ue({inputTokens:g.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:g.contextTokens,contextLimit:g.contextLimit}),Ke(g))}catch{}}},[s,n,t]),Ye=a.useCallback(g=>{if(!D)return;const R=C.findIndex(Se=>Se.id.split("#")[0]===g),G=R>=0&&C[R].kind==="user";let V=R+1;if(G){let Se=R-1;for(;Se>=0&&C[Se].kind!=="assistant";)Se--;V=Se+1}else for(;V<C.length&&(C[V].kind==="tool"||C[V].kind==="file");)V++;const Y=R>=0?C.slice(V):[],fe=Y.filter(Se=>Se.kind==="tool").length;N({uuid:g,count:Y.length,toolCount:fe,anchorIsUser:G})},[D,C]),Ce=a.useCallback(async()=>{if(q){try{await(D==null?void 0:D(q.uuid)),await oe()}catch{throw new Error("Could not revert this chat.")}N(null)}},[q,D,oe]),[Le,or]=a.useState(null),pn=a.useRef(null);a.useEffect(()=>{if(!I||X||C.length===0)return;const g=`${s??""}:${I}`;if(pn.current===g)return;pn.current=g;const R=V=>V.some(Y=>Y.id.split("#")[0]===I),G=()=>{Ge.current=!1,or(V=>({uuid:I,nonce:((V==null?void 0:V.nonce)??0)+1}))};if(R(C)){G();return}if(M>0&&n){let V=!1;return n(s??"",0).then(({messages:Y})=>{if(V)return;const fe=Tt(Y);if(!R(fe)){Q("That link points at a message that isn't in this chat any more.");return}S(Se=>Fs(fe,Se)),y(0),G()}).catch(()=>{V||Q("Could not load the rest of this chat's history.")}),()=>{V=!0}}Q("That link points at a message that isn't in this chat any more.")},[I,X,C,s,M,n]);const lr=a.useCallback(async()=>{if(!s||!n)return;const{messages:g}=await n(s,0);S(R=>Fs(Tt(g),R)),y(0)},[s,n]),cr=a.useCallback(g=>{var G;const R=Array.from(((G=Nt.current)==null?void 0:G.querySelectorAll("[data-sent-file-turn]"))??[]).find(V=>V.dataset.sentFileTurn===g);R&&(Ge.current=!1,R.scrollIntoView({behavior:"smooth",block:"center"}))},[]),Ds=Il({turns:C,omitted:M,loadEarlier:s&&n?lr:void 0,reveal:cr}),gn=a.useCallback(g=>($==null?void 0:$(g))??`${window.location.origin}${window.location.pathname}#${wa(g)}`,[$]),dr=a.useMemo(()=>p&&D?{onFork:p,onRevert:Ye,contextLimit:ae==null?void 0:ae.contextLimit,linkTo:gn,focused:Le}:null,[p,D,Ye,ae==null?void 0:ae.contextLimit,gn,Le]);a.useEffect(()=>{const R=Ai(s,t)??Pt;R&&(J(R),ee.current=R)},[t,s,Pt]),a.useEffect(()=>{s&&s===rs.current||(ue(null),Ke(null))},[t,s]),a.useEffect(()=>{_i(s,t,T)},[T,s,t]),a.useEffect(()=>{if(W==null)return;const g=setTimeout(()=>Q(null),8e3);return()=>clearTimeout(g)},[W]),a.useEffect(()=>{ui(s,t,U),hi(s,t,he?H.current:null),mi(s,t,de)},[U,de,he,s,t]),a.useEffect(()=>{s&&be.setQueued(t,s,U,he?H.current:null,de)},[U,de,he,s,t,be]),a.useEffect(()=>{var g;(f||!s)&&((g=F.current)==null||g.focus())},[]);const bn=a.useCallback((g,R)=>{const G=R??[];(g||G.length>0)&&(Ge.current=!0,S(V=>[...Fe(V),{kind:"user",id:Je(),content:g??"",...G.length>0?{attachments:G}:{}}])),E.current=null,H.current=null,Z(null),we([])},[]),jn=a.useCallback((g,R,G,V)=>{R&&(H.current=R);const Y=g&&g.length>0?g:null,fe=V??[];G==="returned"&&(E.current!=null||le.current.length)&&Q("Stopped — the queued message went back to the composer that stopped the turn.");const Se=fe.length===le.current.length&&fe.every((br,jr)=>{var Tn;return br.id===((Tn=le.current[jr])==null?void 0:Tn.id)});E.current===Y&&Se||(E.current=Y,Y===null&&fe.length===0&&(H.current=null),Z(Y),Se||we(fe))},[]),wn=a.useRef(jn);wn.current=jn;const ls=a.useCallback((g,R)=>{E.current=null,H.current=null,Z(null);const G=R??le.current;G.length>0&&ot(V=>{const Y=new Set(V.map(fe=>fe.id));return[...V,...G.filter(fe=>!Y.has(fe.id))]}),we([]),w(V=>V.trim()?`${g}
|
|
7
|
+
`,1)[0],o=t.length-i.length;return e.jsx("div",{className:"mx-auto mb-2 w-full max-w-3xl px-4",children:e.jsxs("div",{className:"group flex items-center gap-2 rounded-lg border border-accent-edge bg-accent-soft px-3 py-1.5 text-xs",children:[e.jsx(Xe,{width:13,height:13,className:"shrink-0 text-accent"}),e.jsx("span",{className:"shrink-0 font-semibold uppercase tracking-wide text-accent",children:"queued"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-muted",title:t||s.map(l=>l.filename).join(", "),children:i||(s.length>0?e.jsx("span",{className:"italic text-fg-muted",children:s.length===1?"1 attachment":`${s.length} attachments`}):null)}),i&&s.length>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle","data-testid":"queued-attachment-count",title:s.map(l=>l.filename).join(", "),children:["📎 ",s.length]}),o>0&&e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-subtle",title:`${o} more character${o===1?"":"s"} not shown — hover Edit to see the full message`,children:["+",o," character",o===1?"":"s"]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100",children:[e.jsxs("button",{type:"button",onClick:n,title:"Edit this message (cancels the pending auto-send)",className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active",children:[e.jsx(bs,{width:12,height:12}),"Edit"]}),e.jsx("button",{type:"button",onClick:r,title:"Remove queued message","aria-label":"Remove queued message",className:"inline-flex items-center rounded p-1 text-fg-muted hover:bg-surface-active hover:text-danger",children:e.jsx(Oe,{width:12,height:12})})]})]})})}function Fo({state:t}){const s={open:{c:"bg-success-solid",t:"connected"},connecting:{c:"bg-warn-solid animate-pulse",t:"connecting"},closed:{c:"bg-danger-solid",t:"offline"}}[t];return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${s.c}`}),s.t]})}const Oo=a.lazy(()=>ce(()=>import("./MarkdownRenderer-2vrOdDh7.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),Zt=a.memo(function({children:s,mermaid:n=!1}){return e.jsx(a.Suspense,{fallback:e.jsx("div",{className:"md whitespace-pre-wrap",children:s}),children:e.jsx(Oo,{mermaid:n,children:s})})}),Uo=new Set(["markdown","code","text","html","mermaid"]);function us(t){return Uo.has(t)}function Ha(t){const s=t.source==="file"&&us(t.kind)?t.rawUrl:void 0,[n,r]=a.useState(null);return a.useEffect(()=>{if(t.source!=="file"||!us(t.kind))return;if(!s){r({error:!0});return}let i=!1;return r(null),fetch(s).then(o=>o.ok?o.text():Promise.reject(new Error(String(o.status)))).then(o=>!i&&r({text:o})).catch(()=>!i&&r({error:!0})),()=>{i=!0}},[s,t.source,t.kind]),us(t.kind)?t.source==="inline"?{text:t.content??""}:n:null}const Bo={markdown:"text/markdown",html:"text/html"},hs="flex items-center px-2.5 text-fg-subtle motion-fast transition-colors hover:bg-surface-hover hover:text-fg focus-visible:focus-ring disabled:pointer-events-none disabled:opacity-40";function Vo({file:t,text:s}){return e.jsxs(e.Fragment,{children:[us(t.kind)?e.jsx(zo,{filename:t.filename,text:s}):null,t.kind==="image"||t.kind==="pdf"?null:e.jsx(Ho,{file:t,failed:s!==null&&"error"in s})]})}function zo({filename:t,text:s}){const[n,r]=a.useState("idle");a.useEffect(()=>{if(n==="idle")return;const c=setTimeout(()=>r("idle"),1600);return()=>clearTimeout(c)},[n]);const i=s!==null&&"text"in s,o=()=>{if(!i)return;const c=navigator.clipboard;if(!c){r("failed");return}c.writeText(s.text).then(()=>r("copied"),()=>r("failed"))},l=n==="copied"?"Copied":n==="failed"?"Couldn't copy":s===null?"Loading…":"error"in s?"Couldn't load this file":"Copy source";return e.jsxs("button",{type:"button",onClick:o,disabled:!i,"aria-label":`Copy ${t}`,title:l,className:hs,children:[n==="copied"?e.jsx(It,{width:13,height:13,className:"text-success"}):n==="failed"?e.jsx(pe,{width:13,height:13,className:"text-danger"}):e.jsx(Ir,{width:13,height:13}),e.jsx("span",{className:"sr-only",role:"status",children:n==="copied"?"Copied":n==="failed"?"Couldn't copy":""})]})}function Ho({file:t,failed:s}){const n=`Download ${t.filename}`;if(t.source==="file")return t.rawUrl?s?e.jsx("button",{type:"button",disabled:!0,"aria-label":n,title:"Couldn't load this file",className:hs,children:e.jsx(Ps,{width:13,height:13})}):e.jsx("a",{href:t.rawUrl,download:t.filename,"aria-label":n,title:"Download",className:hs,children:e.jsx(Ps,{width:13,height:13})}):null;const r=()=>{const i=`${Bo[t.kind]??"text/plain"};charset=utf-8`,o=URL.createObjectURL(new Blob([t.content??""],{type:i})),l=document.createElement("a");l.href=o,l.download=t.filename,document.body.appendChild(l),l.click(),l.remove(),setTimeout(()=>URL.revokeObjectURL(o),1e3)};return e.jsx("button",{type:"button",onClick:r,"aria-label":n,title:"Download",className:hs,children:e.jsx(Ps,{width:13,height:13})})}const Wo={tsx:"typescript",jsx:"javascript",html:"xml"};function Ko(t){if(!t)return;const s=t.toLowerCase();return Wo[s]??s}let Us=null;async function Go(){return Us||(Us=(async()=>{const{default:t}=await ce(async()=>{const{default:S}=await import("./core-BKN_gaN-.js");return{default:S}},__vite__mapDeps([9,1,2])),[s,n,r,i,o,l,c,m,u,b,f,h,j,x,k,d,p,D,$,I,C]=await Promise.all([ce(()=>import("./typescript-C2FFdlUC.js"),[]),ce(()=>import("./javascript-BKRaQes9.js"),[]),ce(()=>import("./python-kSlZHhJb.js"),[]),ce(()=>import("./ruby-7T4ktxyv.js"),[]),ce(()=>import("./go-BPx_y7j8.js"),[]),ce(()=>import("./rust-HC3MBUhY.js"),[]),ce(()=>import("./java-B5VKqtH2.js"),[]),ce(()=>import("./c-D2F1sQUL.js"),[]),ce(()=>import("./cpp-Bm3ii6kY.js"),[]),ce(()=>import("./csharp-BNpuYZMG.js"),[]),ce(()=>import("./php-CRdd4dfS.js"),[]),ce(()=>import("./swift-Dn8kKO_1.js"),[]),ce(()=>import("./kotlin-Cw-eF_bm.js"),[]),ce(()=>import("./bash-I8pq0VWm.js"),[]),ce(()=>import("./sql-BC88IN-V.js"),[]),ce(()=>import("./json-DIYVocXf.js"),[]),ce(()=>import("./yaml-drsDnIKT.js"),[]),ce(()=>import("./ini-B3BVgEsG.js"),[]),ce(()=>import("./css-DazXZka4.js"),[]),ce(()=>import("./scss-DZLA7YXz.js"),[]),ce(()=>import("./xml-BXBhIUeX.js"),[])]);return t.registerLanguage("typescript",s.default),t.registerLanguage("javascript",n.default),t.registerLanguage("python",r.default),t.registerLanguage("ruby",i.default),t.registerLanguage("go",o.default),t.registerLanguage("rust",l.default),t.registerLanguage("java",c.default),t.registerLanguage("c",m.default),t.registerLanguage("cpp",u.default),t.registerLanguage("csharp",b.default),t.registerLanguage("php",f.default),t.registerLanguage("swift",h.default),t.registerLanguage("kotlin",j.default),t.registerLanguage("bash",x.default),t.registerLanguage("sql",k.default),t.registerLanguage("json",d.default),t.registerLanguage("yaml",p.default),t.registerLanguage("toml",D.default),t.registerLanguage("css",$.default),t.registerLanguage("scss",I.default),t.registerLanguage("xml",C.default),t})()),Us}function qo({code:t,language:s}){const[n,r]=a.useState(null),i=Ko(s);a.useEffect(()=>{if(!i){r(null);return}let l=!1;return r(null),(async()=>{try{const c=await Go();if(l||!c.getLanguage(i))return;const{value:m}=c.highlight(t,{language:i});l||r(m)}catch{}})(),()=>{l=!0}},[t,i]);const o="overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg";return n!==null?e.jsx("pre",{className:o,children:e.jsx("code",{className:`hljs language-${i}`,dangerouslySetInnerHTML:{__html:n}})}):e.jsx("pre",{className:o,children:e.jsx("code",{children:t})})}let Bs=null;function Qo(){return typeof document>"u"?!0:document.documentElement.classList.contains("dark")}async function Yo(){return Bs||(Bs=ce(()=>import("./mermaid.core-C-uiHBIT.js").then(t=>t.bm),__vite__mapDeps([10,1,2])).then(t=>{const s=t.default;return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:Qo()?"dark":"default",fontFamily:"Inter, system-ui, sans-serif"}),s})),Bs}function Jo({code:t}){const n="mmd-"+a.useId().replace(/[^a-zA-Z0-9-]/g,""),r=a.useRef(null),[i,o]=a.useState(null);return a.useEffect(()=>{let l=!1;return o(null),(async()=>{try{const c=await Yo();await c.parse(t);const{svg:m,bindFunctions:u}=await c.render(n+"-svg",t);if(l||!r.current)return;r.current.innerHTML=m,u==null||u(r.current)}catch(c){if(l)return;o(c instanceof Error?c.message:"Failed to render diagram")}})(),()=>{l=!0}},[t,n]),i?e.jsxs("div",{className:"my-3 rounded-lg border border-warn-edge bg-warn-soft p-3 text-xs",children:[e.jsx("p",{className:"font-semibold text-warn",children:"Couldn't render this Mermaid diagram"}),e.jsx("p",{className:"mt-1 text-warn",children:i}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-surface-sunken p-2 font-mono text-2xs text-fg-muted",children:t})]}):e.jsx("div",{ref:r,"data-testid":"mermaid",className:"mermaid-host my-3 flex justify-center overflow-x-auto rounded-lg border border-edge bg-surface-raised p-3"})}const Xo="paddock:itemHeight:";function dn(t){return Xo+t}function Wn(t){try{const s=localStorage.getItem(dn(t));if(s==null)return null;const n=Number(s);return Number.isFinite(n)&&n>0?n:null}catch{return null}}function Zo(t,s){try{const n=dn(t);Number.isFinite(s)&&s>0?localStorage.setItem(n,String(Math.round(s))):localStorage.removeItem(n)}catch{}}function el(t){try{localStorage.removeItem(dn(t))}catch{}}function tl({itemId:t,children:s,defaultMaxHeight:n=360,minHeight:r=80}){const i=a.useRef(null),[o,l]=a.useState(0),[c,m]=a.useState(()=>Wn(t));a.useEffect(()=>{m(Wn(t))},[t]),a.useEffect(()=>{if(!i.current)return;const j=()=>{var k;return l(((k=i.current)==null?void 0:k.scrollHeight)||0)};if(j(),typeof ResizeObserver>"u")return;const x=new ResizeObserver(j);return x.observe(i.current),()=>x.disconnect()},[s]);const u=o>0,b=u?o:Number.POSITIVE_INFINITY;let f=!1,h=0;return c!=null?(f=!0,h=Wa(c,r,b)):u&&o>n&&(f=!0,h=n),e.jsxs("div",{className:f?"group relative":void 0,style:f?{height:h}:void 0,children:[e.jsx("div",{className:f?"h-full overflow-y-auto":void 0,children:e.jsx("div",{ref:i,children:s})}),f?e.jsx(sl,{appliedHeight:h,onResize:j=>m(j),onCommit:j=>Zo(t,j),onReset:()=>{el(t),m(null)},minHeight:r,maxHeight:b}):null]})}function sl({appliedHeight:t,onResize:s,onCommit:n,onReset:r,minHeight:i,maxHeight:o}){const l=a.useRef(null),c=a.useRef(t);c.current=t;const m=24;return e.jsx("div",{role:"slider","aria-label":"Resize","aria-orientation":"vertical","aria-valuenow":Math.round(t),tabIndex:0,onPointerDown:u=>{l.current={startY:u.clientY,startHeight:t},u.currentTarget.setPointerCapture(u.pointerId)},onPointerMove:u=>{if(!l.current)return;const b=Kn(l.current.startHeight,u.clientY-l.current.startY,i,o);s(b)},onPointerUp:u=>{if(l.current){l.current=null;try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}n(c.current)}},onDoubleClick:r,onKeyDown:u=>{if(u.key==="ArrowDown"||u.key==="ArrowUp"){u.preventDefault();const b=u.key==="ArrowDown"?m:-m,f=Kn(t,b,i,o);s(f),n(f)}},className:"absolute inset-x-0 bottom-0 flex h-2 cursor-ns-resize touch-none items-center justify-center border-t border-edge-subtle bg-surface-sunken opacity-60 transition hover:bg-surface-hover hover:opacity-100",children:e.jsx("span",{className:"h-0.5 w-8 rounded-full bg-edge-strong group-hover:bg-fg-subtle"})})}function Kn(t,s,n,r){return Wa(t+s,n,r)}function Wa(t,s,n){return Math.min(Math.max(t,s),n)}function Ka({src:t,filename:s,message:n,onMaximize:r}){const[i,o]=a.useState(!1),[l,c]=a.useState(!1),m=r??(()=>c(!0)),u="repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px";return!t||i?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsxs("div",{className:"group relative flex items-center justify-center overflow-auto p-4",style:{background:u},children:[e.jsx("img",{src:t,alt:s,onError:()=>o(!0),onClick:m,onKeyDown:b=>{(b.key==="Enter"||b.key===" ")&&(b.preventDefault(),m())},role:"button",tabIndex:0,"aria-label":`Open ${s} full screen`,className:"max-h-[480px] max-w-full cursor-zoom-in object-contain shadow-sm"}),e.jsx(Ga,{src:t,filename:s,onMaximize:m}),l?e.jsx(nl,{src:t,filename:s,message:n,onClose:()=>c(!1)}):null]})}function Ga({src:t,filename:s,onMaximize:n}){const r="pointer-events-auto flex h-7 w-7 items-center justify-center rounded-full bg-black/55 text-white shadow-sm transition-colors hover:bg-black/75 focus-visible:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";return e.jsxs("div",{className:"pointer-events-none absolute bottom-2 right-2 z-10 flex items-center gap-1.5 opacity-100 transition-opacity can-hover:opacity-0 can-hover:group-hover:opacity-100 can-hover:group-focus-within:opacity-100",children:[e.jsx("a",{href:t,download:s,className:r,"aria-label":`Download ${s}`,title:"Download",children:e.jsx(al,{})}),e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:r,"aria-label":`Open ${s} in new tab`,title:"Open in new tab",children:e.jsx(rl,{})}),n?e.jsx("button",{type:"button",onClick:n,className:r,"aria-label":"Maximize",title:"Maximize",children:e.jsx(il,{})}):null]})}function nl({src:t,filename:s,message:n,onClose:r}){const i=a.useRef(null);return a.useEffect(()=>{var c;const o=m=>{m.key==="Escape"&&r()};document.addEventListener("keydown",o);const l=document.body.style.overflow;return document.body.style.overflow="hidden",(c=i.current)==null||c.focus(),()=>{document.removeEventListener("keydown",o),document.body.style.overflow=l}},[r]),ja.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":s,onClick:r,className:"fixed inset-0 z-50 flex flex-col items-center justify-center gap-4 bg-overlay-strong p-6",children:[e.jsx("button",{ref:i,type:"button",onClick:r,"aria-label":"Close",title:"Close",className:"absolute right-4 top-4 flex h-9 w-9 items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70",children:e.jsx(ol,{})}),e.jsx("img",{src:t,alt:s,onClick:o=>o.stopPropagation(),className:"max-h-[90vh] max-w-[95vw] object-contain"}),e.jsxs("div",{onClick:o=>o.stopPropagation(),className:"max-w-[95vw] text-center text-sm text-white/90",children:[e.jsx("div",{className:"font-mono text-white/70",children:s}),n?e.jsx("div",{className:"mt-1",children:n}):null]})]}),document.body)}function ys({children:t}){return e.jsx("svg",{width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}function al(){return e.jsxs(ys,{children:[e.jsx("path",{d:"M12 3v12M7 10l5 5 5-5"}),e.jsx("path",{d:"M5 21h14"})]})}function rl(){return e.jsxs(ys,{children:[e.jsx("path",{d:"M15 3h6v6"}),e.jsx("path",{d:"M10 14 21 3"}),e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]})}function il(){return e.jsx(ys,{children:e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M16 21h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}function ol(){return e.jsx(ys,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})}function un({src:t,filename:s,className:n="h-[600px] w-full"}){return t?e.jsxs("div",{className:`group relative ${n}`,children:[e.jsx("object",{data:t,type:"application/pdf","aria-label":s,className:"h-full w-full bg-surface-sunken",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center text-sm text-fg-muted",children:[e.jsx(Qt,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-fg",children:s}),e.jsx("span",{className:"text-xs text-fg-muted",children:"This browser can’t show the PDF inline."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:t,target:"_blank",rel:"noreferrer noopener",className:"rounded-md bg-fg px-3 py-1.5 text-xs font-medium text-surface motion-fast transition-colors hover:bg-fg-muted",children:"Open in new tab"}),e.jsx("a",{href:t,download:s,className:"rounded-md px-3 py-1.5 text-xs font-medium text-fg-muted ring-1 ring-edge-strong hover:bg-surface-hover",children:"Download"})]})]})}),e.jsx(Ga,{src:t,filename:s})]}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this PDF."})]})}function ll({file:t,turnId:s}){const[n,r]=a.useState(!0),i=a.useContext(Ua),o=i&&s?()=>i.open(s,t):void 0,l=gs(t),c=Ha(t);return e.jsx("div",{className:"flex animate-fade-in justify-start","data-sent-file-turn":s,children:e.jsxs("div",{className:"w-full max-w-[92%] overflow-hidden rounded-2xl rounded-bl-md bg-surface-raised shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"flex items-stretch border-b border-edge bg-surface-sunken text-2xs text-fg-muted",children:[e.jsxs("button",{type:"button",onClick:()=>r(m=>!m),"aria-expanded":n,className:"flex min-w-0 flex-1 items-center gap-2 px-4 py-2 text-left",children:[e.jsx(hl,{open:n}),e.jsx(ml,{}),e.jsx("span",{className:"truncate font-mono text-fg-muted",children:t.filename}),e.jsx("span",{className:"ml-auto uppercase tracking-wide text-3xs text-fg-subtle",children:t.language??t.kind})]}),e.jsx(Vo,{file:t,text:c}),o?e.jsx("button",{type:"button",onClick:o,"aria-label":`Maximize ${t.filename}`,title:"Maximize",className:"flex items-center px-3 text-fg-subtle motion-fast transition-colors hover:bg-surface-hover hover:text-fg",children:e.jsx(fl,{})}):null]}),t.message?e.jsx("div",{className:"border-b border-edge-subtle px-4 py-2 text-xs text-fg-muted",children:t.message}):null,n?e.jsx(qa,{file:t,itemId:l,onMaximize:o,text:c}):null]})})}function gs(t){return t.source==="file"&&t.rawUrl?`file:${t.rawUrl}`:`inline:${cl(`${t.filename}\0${t.kind}\0${t.content??""}`)}`}function cl(t){let s=5381;for(let n=0;n<t.length;n++)s=(s<<5)+s+t.charCodeAt(n)|0;return(s>>>0).toString(36)}function qa({file:t,itemId:s,onMaximize:n,fill:r=!1,text:i}){return t.kind==="image"?e.jsx(Ka,{src:t.rawUrl,filename:t.filename,message:t.message,onMaximize:n}):t.kind==="video"?e.jsx(ul,{src:t.rawUrl,filename:t.filename}):t.kind==="pdf"?e.jsx(un,{src:t.rawUrl,filename:t.filename,className:r?"h-full w-full":void 0}):t.source==="inline"?e.jsx(Qa,{kind:t.kind,text:t.content??"",language:t.language,itemId:s,fill:r}):i!==void 0?e.jsx(Ya,{state:i,kind:t.kind,language:t.language,itemId:s,fill:r}):e.jsx(dl,{file:t,itemId:s,fill:r})}function Qa({kind:t,text:s,language:n,itemId:r,fill:i=!1}){return t==="html"?e.jsx("iframe",{title:"sent-file",sandbox:"allow-scripts",srcDoc:s,className:`html-preview w-full ${i?"h-full":"min-h-[360px]"}`}):t==="mermaid"?e.jsx("div",{className:"p-4",children:e.jsx(Jo,{code:s})}):t==="markdown"?e.jsx(Vs,{itemId:r,children:e.jsx("article",{className:"prose-doc max-w-none px-4 py-3",children:e.jsx(Zt,{mermaid:!0,children:s})})}):t==="code"?e.jsx(Vs,{itemId:r,children:e.jsx(qo,{code:s,language:n})}):e.jsx(Vs,{itemId:r,children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-xs leading-relaxed text-fg",children:s})})}function Vs({itemId:t,children:s}){return t?e.jsx(tl,{itemId:t,children:s}):e.jsx(e.Fragment,{children:s})}function dl({file:t,itemId:s,fill:n}){const r=Ha(t);return e.jsx(Ya,{state:r,kind:t.kind,language:t.language,itemId:s,fill:n})}function Ya({state:t,kind:s,language:n,itemId:r,fill:i}){return t===null?e.jsx("div",{className:"px-4 py-3 text-xs text-fg-subtle",children:"Loading…"}):"error"in t?e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not load this file."})]}):e.jsx(Qa,{kind:s,text:t.text,language:n,itemId:r,fill:i})}function ul({src:t,filename:s}){return t?e.jsx("div",{className:"flex items-center justify-center overflow-hidden bg-surface-sunken p-4",children:e.jsx("video",{src:t,controls:!0,playsInline:!0,preload:"metadata",className:"max-h-[480px] w-full rounded-sm shadow-sm",children:e.jsxs("p",{className:"p-4 text-sm text-fg-muted",children:["Your browser can’t play this video."," ",e.jsxs("a",{href:t,download:s,className:"underline",children:["Download ",s]})]})})}):e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this video."})]})}function hl({open:t}){return e.jsx("svg",{width:12,height:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-subtle transition-transform ${t?"rotate-90":""}`,children:e.jsx("path",{d:"M9 18l6-6-6-6"})})}function ml(){return e.jsxs("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("path",{d:"M14 2v6h6"})]})}function fl(){return e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:e.jsx("path",{d:"M8 3H5a2 2 0 0 0-2 2v3M21 8V5a2 2 0 0 0-2-2h-3M16 21h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"})})}const hn=a.memo(function({turn:s}){return s.kind==="user"?e.jsxs("div",{className:"flex animate-fade-in flex-col items-end",children:[s.sender?e.jsx(wl,{sender:s.sender}):null,s.attachments&&s.attachments.length>0?e.jsx(Bi,{attachments:s.attachments}):null,s.content?e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap break-words rounded-2xl rounded-br-md bg-accent-solid px-4 py-2.5 text-sm text-accent-fg shadow-sm",children:s.content}):null]}):s.kind==="file"?e.jsx(ll,{file:s.file,turnId:s.id}):s.kind==="tool"?e.jsx(Nl,{tool:s.tool}):s.kind==="command"?e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"rounded-full bg-surface-active px-2.5 py-0.5 font-mono text-xs text-fg-muted ring-1 ring-edge",children:s.command})}):s.kind==="commandOutput"?s.content?e.jsx(bl,{content:s.content}):null:s.kind==="compact"?e.jsx(jl,{summary:s.summary}):s.kind==="notice"?e.jsx(yl,{notice:s.notice}):s.kind==="notification"?Er(s.status)?e.jsx(vl,{summary:s.summary}):e.jsx("div",{className:"flex animate-fade-in justify-center",children:e.jsx("span",{className:"max-w-[85%] truncate rounded-full bg-surface-sunken px-2.5 py-0.5 text-xs italic text-fg-muted ring-1 ring-edge",title:s.summary,children:s.summary})}):e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsx("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-raised px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:s.content?e.jsx("div",{className:s.streaming?"streaming-caret":void 0,children:e.jsx(Zt,{children:s.content})}):e.jsxs("div",{className:"flex gap-1 py-1",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"})]})})})}),xl=/^[0-9a-f]{8}-[0-9a-f]{4}-/;function pl({turn:t}){const s=a.useContext(Oa);return!!s&&(t.kind==="user"||t.kind==="assistant")&&typeof t.timestamp=="string"&&xl.test(t.id)?e.jsx(gl,{turn:t,actions:s}):e.jsx(hn,{turn:t})}function gl({turn:t,actions:s}){var p;const n=t.id.split("#")[0],r=t.id===n,i=s.linkTo(n),o=a.useRef(null),[l,c]=a.useState(!1),[m,u]=a.useState(!1),b=r&&((p=s.focused)==null?void 0:p.uuid)===n?s.focused.nonce:null;a.useEffect(()=>{var $;if(b==null)return;($=o.current)==null||$.scrollIntoView({behavior:"smooth",block:"center"}),u(!0);const D=setTimeout(()=>u(!1),3200);return()=>clearTimeout(D)},[b]),a.useEffect(()=>{if(!l)return;const D=setTimeout(()=>c(!1),1600);return()=>clearTimeout(D)},[l]);const f=D=>{var $;D.metaKey||D.ctrlKey||D.shiftKey||D.altKey||D.button!==0||(D.preventDefault(),($=navigator.clipboard)==null||$.writeText(i).then(()=>c(!0)).catch(()=>c(!1)))},h=t.contextTokens,j=s.contextLimit,x=h!=null&&j?Math.min(100,Math.round(h/j*100)):null,k="flex items-center rounded-full bg-surface/95 shadow-sm ring-1 ring-edge backdrop-blur",d=`${k} h-6 w-6 justify-center text-fg-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`;return e.jsxs("div",{ref:o,id:r?wa(n):void 0,className:`group relative rounded-lg ${m?"reveal-flash":""}`,children:[e.jsxs("div",{className:"pointer-events-none absolute -top-3 right-1 z-10 flex items-center gap-1 opacity-0 transition-opacity duration-150 group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100",children:[e.jsx("a",{href:i,onClick:f,title:`Copy a link to this message · ${new Date(t.timestamp).toLocaleString()}`,"aria-label":`Copy a link to this message (${Et(t.timestamp)})`,className:`${k} gap-1 px-2 py-0.5 text-2xs text-fg-muted transition-colors hover:text-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:l?e.jsx("span",{className:"text-accent",children:"Link copied"}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:Et(t.timestamp)}),h!=null?e.jsxs("span",{className:"text-fg-subtle tabular",title:"Context-window fill as of this message",children:["· ",ga(h),x!=null?` · ${x}%`:""]}):null]})}),e.jsx("button",{type:"button",onClick:()=>s.onFork(n),title:"Fork a new chat from here","aria-label":"Fork a new chat from here",className:`${d} hover:text-accent`,children:e.jsx(ft,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>s.onRevert(n),title:"Revert conversation back to here","aria-label":"Revert conversation back to here",className:`${d} hover:text-danger`,children:e.jsx(Xe,{width:13,height:13})})]}),e.jsx(hn,{turn:t})]})}function Me({delay:t}){return e.jsx("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-fg-subtle",style:{animationDelay:t}})}function bl({content:t}){return e.jsx("div",{className:"flex animate-fade-in justify-start",children:e.jsxs("div",{className:"max-w-[92%] rounded-2xl rounded-bl-md bg-surface-sunken px-4 py-2.5 text-fg shadow-sm ring-1 ring-edge",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1 text-2xs italic text-fg-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"⌨"}),e.jsx("span",{children:"command output"})]}),e.jsx(Zt,{children:t})]})})}function jl({summary:t}){return e.jsx("div",{className:"animate-fade-in py-1",children:e.jsxs("details",{className:"group",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-3 text-xs text-fg-muted",children:[e.jsx("span",{className:"h-px flex-1 bg-edge"}),e.jsx("span",{className:"whitespace-nowrap",children:"🗜️ conversation compacted"}),e.jsx("span",{className:"h-px flex-1 bg-edge"})]}),e.jsx("div",{className:"mt-2 max-h-64 overflow-auto whitespace-pre-wrap break-words rounded-lg bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:t})]})})}function wl({sender:t}){var r;const s="mb-1 flex items-center gap-1 text-2xs italic text-fg-muted";if(t.kind==="schedule")return e.jsxs("div",{className:s,"data-sender":"schedule",children:[e.jsx("span",{"aria-hidden":!0,children:"⏰"}),e.jsxs("span",{children:["scheduled by ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="hook")return e.jsxs("div",{className:s,"data-sender":"hook",children:[e.jsx("span",{"aria-hidden":!0,children:"⚡"}),e.jsxs("span",{children:["triggered by hook ",e.jsx("span",{className:"font-medium not-italic",children:t.name})]})]});if(t.kind==="recovery")return e.jsxs("div",{className:s,"data-sender":"recovery",children:[e.jsx("span",{"aria-hidden":!0,children:"⚠"}),e.jsx("span",{children:"continued after a background task was terminated"})]});if(t.kind==="agent")return e.jsxs("div",{className:s,"data-sender":"agent",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsx("span",{children:"sent by an agent"})]});const n=((r=t.name)==null?void 0:r.trim())||t.sessionId.slice(0,8);return e.jsxs("div",{className:s,"data-sender":"chat",children:[e.jsx("span",{"aria-hidden":!0,children:"↩"}),e.jsxs("span",{children:["sent by"," ",e.jsx(rn,{to:`/projects/${encodeURIComponent(t.project)}/chat/${encodeURIComponent(t.sessionId)}`,className:"font-medium not-italic text-accent hover:underline",title:`Open ${n} in ${t.project}`,children:n})]})]})}function vl({summary:t}){const s=a.useContext(cn),n=!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy);return e.jsx("div",{className:"flex animate-fade-in justify-center","data-recovery":"killed-task",children:e.jsxs("div",{className:"flex max-w-[90%] flex-col gap-1.5 rounded-lg border border-warn-edge bg-warn-soft px-3 py-2 text-xs text-warn",children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:"⚠"}),e.jsxs("span",{className:"leading-snug",children:["A background task was terminated at the turn boundary — Claude is idle and will not continue on its own.",e.jsx("span",{className:"mt-0.5 block text-2xs text-warn",children:t})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-recovery-action":"continue",className:"motion-fast rounded-md bg-warn-solid px-2.5 py-1 text-2xs font-medium text-warn-fg shadow-sm transition-[filter,box-shadow,opacity] hover:brightness-110 disabled:cursor-not-allowed disabled:opacity-50",children:r?"Continuing…":"Continue"})})]})})}function yl({notice:t}){const s=a.useContext(cn),n=t.retryable&&!!(s!=null&&s.enabled),r=!!(s!=null&&s.busy),i=t.kind==="error",o=i?"border-danger-edge bg-danger-soft text-danger":"border-warn-edge bg-warn-soft text-warn",l=i?"bg-danger-solid text-danger-fg hover:brightness-110":"bg-warn-solid text-warn-fg hover:brightness-110",c=i?"text-danger":"text-warn",m=t.kind==="usage_limit"?"Session limit reached":t.kind==="max_turns"?"Turn limit reached":"The turn failed";return e.jsx("div",{className:"flex animate-fade-in justify-center","data-notice":t.kind,children:e.jsxs("div",{className:`flex max-w-[90%] flex-col gap-1.5 rounded-lg border px-3 py-2 text-xs ${o}`,children:[e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"leading-tight",children:i?"⚠":"⏳"}),e.jsxs("span",{className:"leading-snug",children:[e.jsxs("span",{className:"font-medium",children:[m,"."]})," ",t.message,t.kind==="usage_limit"&&t.resetTime&&e.jsxs("span",{className:`mt-0.5 block text-2xs ${c}`,children:["Resets ",t.resetTime,". Claude will respond again after the quota resets."]}),i&&t.detail&&e.jsx("span",{className:`mt-0.5 block break-words font-mono text-2xs ${c}`,children:t.detail})]})]}),n&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:s==null?void 0:s.onContinue,disabled:r,"data-notice-action":"retry",className:`motion-fast rounded-md px-2.5 py-1 text-2xs font-medium shadow-sm transition-[filter,box-shadow,opacity] disabled:cursor-not-allowed disabled:opacity-50 ${l}`,children:r?"Retrying…":t.kind==="max_turns"?"Continue":"Retry"})})]})})}function Nl({tool:t}){var N,U;const s=Qi(t.toolName),n=Yi(t.toolName,t.output),r=s.isPaddock?oo(s.tool):null,i=n!=null&&(n.tool==="create_chat"||n.tool==="fork_chat"||n.tool==="send_message"||n.tool==="fork_chat_batch"),[o,l]=a.useState(i),c=a.useContext(Fa),m=a.useContext(La),u=a.useRef(null),[b,f]=a.useState(!1),h=m!=null&&m.focused&&m.focused.toolUseId===t.toolUseId?m.focused.nonce:null;a.useEffect(()=>{var E;if(h==null)return;l(!0),(E=u.current)==null||E.scrollIntoView({behavior:"smooth",block:"center"}),f(!0);const Z=setTimeout(()=>f(!1),3200);return()=>clearTimeout(Z)},[h]);const j=a.useContext(_a),x=a.useContext(ln),k=!!t.pending,d=vs.has(t.toolName),p=t.toolUseId?x==null?void 0:x.get(t.toolUseId):void 0,D=d?xs(t.subagentDurationMs??(p==null?void 0:p.elapsedMs)):xs(t.durationMs),$=t.subagentCostUsd!=null?`~${pa(t.subagentCostUsd)}`:null,I=!d&&ro(t),C=t.monitorEvents??[],S=t.editDiff,M=!!S,y=t.toolName==="Read"?t.readInfo:void 0,T=y!=null&&y.isImage&&y.projectRelPath&&c?c(y.projectRelPath):null,w=t.toolName==="Bash"?t.bashDetails:void 0,F=t.searchInfo,O=t.toolName==="TaskUpdate"?t.taskUpdate:void 0,z=t.toolName==="TaskCreate"?t.taskCreate:void 0,X=!!(w&&w.stderr),L=F?uo(F):null,v=y?ho(y):null,A=p!=null?p.running:to(t,j),W=!!(d&&t.hasSubagent&&t.toolUseId),Q=A&&t.toolUseId?(N=x==null?void 0:x.get(t.toolUseId))==null?void 0:N.latestStep:void 0,ie=d?t.subagentType??t.toolName:s.isMcp?s.display:t.toolName,K=d?Q??t.description:n?Ji(n):M?((U=S.filePath)==null?void 0:U.split("/").pop())??S.filePath:y?y.basename??y.filePath??t.inputSummary:z?z.subject:t.inputSummary,q=(y==null?void 0:y.filePath)??(z==null?void 0:z.description)??(Q?t.description:void 0)??K??void 0;return e.jsx("div",{className:"flex justify-start",children:e.jsxs("div",{ref:u,className:`motion-fast w-full max-w-[92%] overflow-hidden rounded-xl border text-xs transition-[color,background-color,border-color] ${b?"reveal-flash ":""}${t.isError?"border-danger-edge bg-danger-soft":d?"border-accent-edge bg-accent-soft":I?"border-info-edge bg-info-soft":"border-edge bg-surface-raised"}`,children:[e.jsxs("button",{type:"button",onClick:()=>l(Z=>!Z),className:"flex w-full items-center gap-2 px-3 py-2 text-left",children:[e.jsx(At,{width:13,height:13,className:`motion-fast shrink-0 text-fg-subtle transition-transform ${o?"rotate-90":""}`}),d?e.jsx(Jt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):I?e.jsx(Xe,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-info"}`}):r?e.jsx(r,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-accent"}`}):M?e.jsx(bs,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):y?e.jsx(Qt,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):F?e.jsx(va,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):O||z?e.jsx(It,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}):e.jsx(ya,{width:13,height:13,className:`shrink-0 ${t.isError?"text-danger":"text-fg-muted"}`}),e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono font-semibold text-fg",children:ie}),d&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:"sub-agent"}),I&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-info-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-info",children:"background"}),s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-accent-soft px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-accent",children:n&&"project"in n&&n.project?n.project:"Paddock"}),s.isMcp&&!s.isPaddock&&e.jsx("span",{className:"shrink-0 whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 text-3xs font-semibold uppercase tracking-wide text-fg-muted",children:"MCP"}),O?e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 truncate font-mono text-fg-muted",children:[O.taskId&&e.jsxs("span",{className:"shrink-0",children:["Task #",O.taskId]}),O.from&&O.to?e.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Gn,{status:O.from}),e.jsx("span",{className:"text-fg-subtle",children:"→"}),e.jsx(Gn,{status:O.to})]}):O.updatedFields&&e.jsx("span",{className:"shrink-0 truncate",children:O.updatedFields.join(", ")})]}):K&&e.jsx("span",{className:`min-w-0 truncate font-mono ${Q?"text-accent":"text-fg-muted"}`,title:q,children:K}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-2",children:[t.isError&&e.jsx("span",{className:"rounded bg-danger-soft px-1.5 py-0.5 text-3xs font-semibold text-danger",children:"error"}),k||A?e.jsxs("span",{className:"flex items-center gap-1.5 text-accent",title:"Sub-agent is running",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-accent-edge border-t-accent","aria-hidden":"true"}),e.jsx("span",{className:"text-3xs font-semibold uppercase tracking-wide",children:"running"})]}):e.jsxs(e.Fragment,{children:[I&&C.length>0&&e.jsxs("span",{className:"whitespace-nowrap text-3xs text-info",children:[C.length," event",C.length===1?"":"s"]}),I&&t.taskStatus&&e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${io(t.taskStatus)}`,children:t.taskStatus}),M&&(S.additions>0||S.deletions>0)&&e.jsxs("span",{className:"whitespace-nowrap font-mono text-3xs font-semibold tabular",children:[S.additions>0&&e.jsxs("span",{className:"text-success",children:["+",S.additions]}),S.additions>0&&S.deletions>0&&" ",S.deletions>0&&e.jsxs("span",{className:"text-danger",children:["−",S.deletions]})]}),v&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs text-fg-subtle tabular",children:v}),L&&e.jsx("span",{className:"whitespace-nowrap font-mono text-3xs font-medium text-fg-muted tabular",children:L}),(w==null?void 0:w.gitHint)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-surface-active px-1.5 py-0.5 font-mono text-3xs text-fg-muted",children:w.gitHint}),(w==null?void 0:w.interrupted)&&e.jsx("span",{className:"whitespace-nowrap rounded bg-warn-soft px-1.5 py-0.5 text-3xs font-semibold text-warn",children:"interrupted"}),(w==null?void 0:w.returnCodeInterpretation)&&e.jsx("span",{className:"max-w-[12rem] truncate whitespace-nowrap text-3xs italic text-fg-subtle",children:w.returnCodeInterpretation}),D&&e.jsx("span",{className:"text-fg-subtle tabular",children:D}),$&&e.jsx("span",{className:"text-fg-subtle tabular",children:$})]})]})]}),o&&(W?e.jsx(Tl,{toolUseId:t.toolUseId,live:A}):I&&C.length>0?e.jsx("div",{className:"max-h-72 overflow-auto border-t border-info-edge bg-info-soft",children:C.map((Z,E)=>e.jsx("div",{className:"whitespace-pre-wrap break-words border-b border-info-edge px-3 py-1.5 font-mono text-2xs leading-relaxed text-fg-muted last:border-b-0",children:Z},E))}):n?e.jsx(eo,{data:n}):M?e.jsx(kl,{diff:S}):T?e.jsx("div",{className:"border-t border-edge",children:e.jsx(Ka,{src:T,filename:(y==null?void 0:y.basename)??"image"})}):X?e.jsx(Cl,{bash:w}):z&&z.description?e.jsx(Sl,{info:z}):e.jsxs("div",{className:"border-t border-edge",children:[I&&t.taskResultSummary&&e.jsx("div",{className:"border-b border-edge bg-info-soft px-3 py-2 text-2xs font-medium text-fg",children:t.taskResultSummary}),e.jsx("pre",{className:"max-h-72 overflow-auto whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:k?"Running…":t.output||"(no output)"})]}))]})})}function kl({diff:t}){return e.jsxs("div",{className:"max-h-96 overflow-auto border-t border-edge bg-surface-sunken font-mono text-2xs leading-relaxed",children:[t.hunks.map((s,n)=>e.jsxs("div",{className:n>0?"border-t border-edge":"",children:[e.jsxs("div",{className:"bg-surface-active px-3 py-1 font-mono text-3xs font-semibold text-lineage",children:["@@ -",s.oldStart,",",s.oldLines," +",s.newStart,",",s.newLines," @@"]}),s.lines.map((r,i)=>e.jsxs("div",{className:`flex ${lo(r.t)}`,children:[e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:Fn(r.oldLine)}),e.jsx("span",{className:"w-8 shrink-0 select-none pr-1 text-right tabular opacity-40",children:Fn(r.newLine)}),e.jsx("span",{className:"w-3 shrink-0 select-none text-center opacity-60",children:r.t===" "?"":r.t}),e.jsx("span",{className:"whitespace-pre-wrap break-words pr-3",children:r.text||" "})]},i))]},n)),t.truncated&&e.jsx("div",{className:"px-3 py-1.5 text-2xs italic text-fg-subtle",children:"… diff truncated (see the file for the full change)"})]})}function Gn({status:t}){return e.jsx("span",{className:`whitespace-nowrap rounded px-1.5 py-0.5 text-3xs font-semibold ${co(t)}`,children:t})}function Cl({bash:t}){return e.jsxs("div",{className:"max-h-72 overflow-auto border-t border-edge",children:[t.stdout&&e.jsx("pre",{className:"whitespace-pre-wrap break-words bg-surface-sunken px-3 py-2 font-mono text-2xs leading-relaxed text-fg-muted",children:t.stdout}),t.stderr&&e.jsx("pre",{className:"whitespace-pre-wrap break-words border-t border-danger-edge bg-danger-soft px-3 py-2 font-mono text-2xs leading-relaxed text-danger first:border-t-0",children:t.stderr})]})}function Sl({info:t}){return e.jsxs("div",{className:"border-t border-edge bg-surface-sunken px-3 py-2",children:[t.subject&&e.jsx("div",{className:"text-xs font-semibold text-fg",children:t.subject}),t.description&&e.jsx("div",{className:"mt-1 whitespace-pre-wrap break-words text-2xs leading-relaxed text-fg-muted",children:t.description})]})}const qn=2e3;function Tl({toolUseId:t,live:s=!1}){var b,f;const n=a.useContext(Pa),[r,i]=a.useState(null),[o,l]=a.useState(!1),c=(f=(b=a.useContext(ln))==null?void 0:b.get(t))==null?void 0:f.messages;a.useEffect(()=>{i(null),l(!1)},[t]),a.useEffect(()=>{if(c)return;if(!n){l(!0);return}let h=!1,j;const x=()=>{n(t).then(k=>{h||(i(k),s&&(j=setTimeout(x,qn)))}).catch(()=>{h||(s?j=setTimeout(x,qn):l(!0))})};return x(),()=>{h=!0,j&&clearTimeout(j)}},[n,t,s,!!c]);const m=c??r,u=a.useMemo(()=>Tt(m??[]),[m]);return e.jsx("div",{"data-testid":"subagent-steps",className:"border-t border-edge bg-surface-sunken px-3 py-3",children:o?e.jsx("div",{className:"text-2xs text-danger",children:"couldn't load sub-agent steps"}):m==null?e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"loading sub-agent steps…"})]}):u.length===0?e.jsx("div",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"waiting for sub-agent steps…"})]}):e.jsx("span",{children:"(no recorded steps)"})}):e.jsxs("div",{className:"space-y-3 border-l-2 border-accent-edge pl-3",children:[u.map(h=>e.jsx(hn,{turn:h},h.id)),s&&e.jsxs("div",{className:"flex items-center gap-1.5 text-2xs text-accent",children:[e.jsx(Me,{})," ",e.jsx(Me,{delay:"150ms"})," ",e.jsx(Me,{delay:"300ms"}),e.jsx("span",{className:"ml-1",children:"sub-agent working…"})]})]})})}function $l(t){const{projectSlug:s,initialSessionId:n,loadHistory:r,onSessionEstablished:i,onSessionStarted:o,onTurnComplete:l,sessionRef:c,jobRef:m,pendingCancelRef:u,streamingRef:b,awaitingSessionRef:f,isNewSessionRef:h,startedNotifiedRef:j,establishedHereRef:x,modelRef:k,cancelledRef:d,noticeThisTurnRef:p,seenInjectionsRef:D,onQueuedFlushedRef:$,onQueuedStateRef:I,onQueuedReturnedRef:C,setTurns:S,setStreaming:M,setUsage:y,setSessionUsage:T,setError:w}=t;a.useEffect(()=>{const F=L=>{const v=c.current;return v?L.sessionId===v?!0:L.sessionId==null&&b.current:f.current},O=L=>{c.current=L,f.current=!1,X.setSessionId(L),h.current&&!j.current&&(j.current=!0,x.current=L,k.current&&Js(L,s,k.current),o==null||o(L))},z=L=>{m.current=L,u.current&&(u.current=!1,be.cancel(L))},X=be.subscribe(s,c.current,{onResponse:(L,v)=>{F(v)&&(v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId),fo(S,L))},onToolStart:(L,v)=>{F(v)&&(v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId),S(A=>L.toolUseId&&A.some(W=>W.kind==="tool"&&W.tool.toolUseId===L.toolUseId)?A:[...Fe(A),{kind:"tool",id:Je(),tool:L}]))},onToolCall:(L,v)=>{if(!F(v))return;v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId);const A=Da(L);S(W=>{if(L.toolUseId){const ie=W.findIndex(K=>K.kind==="tool"&&K.tool.toolUseId===L.toolUseId);if(ie!==-1){const K=W[ie].id,q=W.slice();return q[ie]=A?{kind:"file",id:K,file:A}:{kind:"tool",id:K,tool:L},q}}const Q=A?{kind:"file",id:Je(),file:A}:{kind:"tool",id:Je(),tool:L};return[...Fe(W),Q]})},onMessageBoundary:L=>{F(L)&&(L.jobId&&z(L.jobId),S(v=>Fe(v)))},onComplete:L=>{if(F(L)){L.jobId&&z(L.jobId),b.current=!1,M(!1),S(v=>On(Fe(v))),L.usage&&y(L.usage);{const v=L.sessionId??c.current;v&&B.chatContext(s,v).then(A=>T(A)).catch(()=>{})}if(L.sessionId){const v=h.current&&c.current!==L.sessionId;O(L.sessionId),(v||h.current)&&(h.current=!1,k.current&&Js(L.sessionId,s,k.current),x.current=L.sessionId,i==null||i(L.sessionId))}!L.success&&L.error&&!p.current&&w(L.error);{const v=L.sessionId??c.current;l==null||l(v&&L.usage?{sessionId:v,usage:L.usage}:void 0)}d.current=!1}},onError:L=>{b.current&&(b.current=!1,M(!1),m.current=null,S(v=>On(Fe(v))),w(L),d.current=!1)},onResync:()=>{const L=c.current;!L||!r||r(L).then(({messages:v})=>S(Tt(v))).catch(()=>{})},onActive:({turnRunning:L,jobId:v})=>{L?(v&&z(v),b.current=!0,M(!0)):(b.current=!1,M(!1),m.current=null,S(A=>Fe(A)),d.current=!1,u.current=!1)},onQueuedFlushed:({text:L,attachments:v})=>{$.current(L,v)},onQueuedState:({text:L,qid:v,reason:A,attachments:W})=>{I.current(L,v,A,W)},onQueuedReturned:({text:L,attachments:v})=>{C.current(L,v)},onInjected:(L,v)=>{if(!F(v))return;v.jobId&&z(v.jobId),v.sessionId&&O(v.sessionId);const A=`${L.timestamp} ${L.content}`;D.current.has(A)||(D.current.add(A),S(W=>[...Fe(W),{kind:"user",id:Je(),content:L.content,sender:L.sender}]))},onKilledTask:({summary:L,timestamp:v})=>{const A=`killed ${v}`;D.current.has(A)||(D.current.add(A),S(W=>[...Fe(W),{kind:"notification",id:Je(),summary:L,status:"killed"}]))},onNotice:(L,v)=>{F(v)&&(p.current=!0,S(A=>[...Fe(A),{kind:"notice",id:Je(),notice:L}]))}});return()=>{X.unsubscribe()}},[s,n,r,i,o,l])}function Il({turns:t,omitted:s,loadEarlier:n,reveal:r}){const i=a.useMemo(()=>t.flatMap(S=>S.kind==="file"?[{id:S.id,file:S.file}]:[]),[t]),o=a.useRef(i);o.current=i;const[l,c]=a.useState(null),[m,u]=a.useState("idle"),[b,f]=a.useState(!1),[h,j]=a.useState(null),x=a.useMemo(()=>{if(!l||l.single)return-1;const S=i.findIndex(y=>y.id===l.id);if(S!==-1)return S;const M=gs(l.file);return i.findIndex(y=>gs(y.file)===M)},[i,l]);a.useEffect(()=>{l&&!l.single&&x===-1&&c(null)},[l,x]);const k=a.useCallback(S=>{const M=o.current[S];M&&(c({id:M.id,file:M.file,single:!1}),u("idle"),j(y=>({id:M.id,nonce:((y==null?void 0:y.nonce)??0)+1})))},[]);a.useEffect(()=>{h&&r(h.id)},[h,r]);const d=s>0&&!!n,p=a.useCallback(()=>{if(!(!l||l.single)){if(x>0)return k(x-1);x!==0||!d||m==="loading"||(u("loading"),n().then(()=>f(!0)).catch(()=>u("error")))}},[l,x,k,d,m,n]);a.useEffect(()=>{b&&(f(!1),x>0?k(x-1):u("none"))},[b,x,k]);const D=a.useCallback(()=>{l&&!l.single&&x<i.length-1&&k(x+1)},[l,x,i.length,k]),$=a.useCallback(()=>{c(null),u("idle")},[]),I=a.useMemo(()=>({open:(S,M)=>{const y=!o.current.some(T=>T.id===S);c({id:S,file:M,single:y}),u("idle")}}),[]),C=l?{file:x===-1?l.file:i[x].file,position:x===-1?null:{index:x,total:i.length},canPrev:x>0||x===0&&d,canNext:x!==-1&&x<i.length-1,earlier:x===0?d&&m==="idle"?"withheld":m:"idle",onPrev:p,onNext:D,onClose:$}:null;return{context:I,viewer:C}}const El={idle:null,withheld:"Earlier messages aren’t loaded — ← loads them",loading:"Loading earlier messages…",none:"No earlier files in this chat",error:"Couldn’t load earlier messages — ← to retry"};function Rl({file:t,position:s,canPrev:n,canNext:r,earlier:i,onPrev:o,onNext:l,onClose:c}){const m=a.useRef(null),u=a.useRef({onPrev:o,onNext:l,onClose:c,canPrev:n,canNext:r});u.current={onPrev:o,onNext:l,onClose:c,canPrev:n,canNext:r},a.useEffect(()=>{var k;const h=d=>{const p=u.current;if(d.key==="Escape")return p.onClose();d.key!=="ArrowLeft"&&d.key!=="ArrowRight"||d.altKey||d.ctrlKey||d.metaKey||d.shiftKey||Al(d.target)||(d.preventDefault(),d.key==="ArrowLeft"&&p.canPrev&&p.onPrev(),d.key==="ArrowRight"&&p.canNext&&p.onNext())};document.addEventListener("keydown",h);const j=document.body.style.overflow;document.body.style.overflow="hidden";const x=document.activeElement;return(k=m.current)==null||k.focus(),()=>{var d;document.removeEventListener("keydown",h),document.body.style.overflow=j,(d=x==null?void 0:x.focus)==null||d.call(x,{preventScroll:!0})}},[]);const b=El[i],f=h=>h.stopPropagation();return ja.createPortal(e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":t.filename,onClick:c,className:"fixed inset-0 z-50 flex flex-col gap-3 bg-overlay-strong p-3 backdrop-blur-sm sm:p-5",children:[e.jsxs("div",{className:"flex items-center gap-3 text-sm text-white/90",children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-white/80",onClick:f,children:t.filename}),s?e.jsxs("span",{className:"shrink-0 tabular-nums text-xs text-white/60","aria-live":"polite",children:[s.index+1," / ",s.total]}):null,b?e.jsx("span",{className:"min-w-0 truncate text-xs text-white/60",role:"status",children:b}):null,e.jsx("button",{ref:m,type:"button",onClick:c,"aria-label":"Close",title:"Close (Esc)",className:`${Ja} ml-auto h-9 w-9 shrink-0`,children:e.jsx(Xa,{children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 items-center gap-2 sm:gap-3",children:[s?e.jsx(Qn,{side:"left",disabled:!n,onClick:o}):null,e.jsx("div",{className:"flex h-full min-w-0 flex-1 items-center justify-center",children:e.jsx(Ml,{file:t},gs(t))}),s?e.jsx(Qn,{side:"right",disabled:!r,onClick:l}):null]}),t.message?e.jsx("div",{onClick:f,className:"mx-auto max-w-3xl text-center text-sm text-white/90",children:t.message}):null]}),document.body)}function Ml({file:t}){const s=r=>r.stopPropagation();if(t.kind==="image"&&t.rawUrl)return e.jsx("img",{src:t.rawUrl,alt:t.filename,onClick:s,className:"max-h-full max-w-full object-contain"});if(t.kind==="video"&&t.rawUrl)return e.jsx("video",{src:t.rawUrl,controls:!0,playsInline:!0,preload:"metadata",onClick:s,className:"h-full w-full object-contain"});const n=t.kind==="pdf"||t.kind==="html";return e.jsx("div",{onClick:s,className:`w-full overflow-auto rounded-lg bg-surface-raised shadow-lg ring-1 ring-edge ${n?"h-full max-w-6xl":"max-h-full max-w-4xl"}`,children:e.jsx(qa,{file:t,fill:!0})})}const Ja="flex items-center justify-center rounded-full bg-black/55 text-white transition-colors hover:bg-black/75 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white/70";function Qn({side:t,disabled:s,onClick:n}){const r=t==="left"?"Previous file":"Next file";return e.jsx("button",{type:"button",onClick:i=>{i.stopPropagation(),n()},disabled:s,"aria-label":r,title:`${r} (${t==="left"?"←":"→"})`,className:`${Ja} h-10 w-10 shrink-0 disabled:pointer-events-none disabled:opacity-30`,children:e.jsx(Xa,{children:e.jsx("path",{d:t==="left"?"M15 18l-6-6 6-6":"M9 18l6-6-6-6"})})})}function Al(t){return t instanceof HTMLElement?t.isContentEditable?!0:["INPUT","TEXTAREA","SELECT","VIDEO","AUDIO"].includes(t.tagName):!1}function Xa({children:t}){return e.jsx("svg",{width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0",children:t})}const Za="paddock:attachments:",er="paddock:newchat-instance:";function Dl(){try{return crypto.randomUUID()}catch{return`n-${Math.random().toString(36).slice(2)}-${Date.now()}`}}function Pl(t){try{const s=er+t,n=sessionStorage.getItem(s);if(n)return n;const r=Dl();sessionStorage.setItem(s,r);try{localStorage.removeItem(`${Za}new:${t}`)}catch{}return r}catch{return"shared"}}function _l(t){try{localStorage.removeItem(qt(null,t))}catch{}try{sessionStorage.removeItem(er+t)}catch{}}function qt(t,s){return Za+(t??`new:${s}:${Pl(s)}`)}function Ll(t){if(!t||typeof t!="object")return null;const s=t;if(typeof s.id!="string"||!s.id||typeof s.filename!="string"||!s.filename)return null;const n={id:s.id,filename:s.filename,kind:typeof s.kind=="string"?s.kind:"file"};return typeof s.size=="number"&&Number.isFinite(s.size)&&(n.size=s.size),n}function Fl(t,s){try{const n=localStorage.getItem(qt(t,s));if(!n)return[];const r=JSON.parse(n);return Array.isArray(r)?r.map(Ll).filter(i=>i!==null):[]}catch{return[]}}function Ol(t,s,n){try{const r=qt(t,s);n.length>0?localStorage.setItem(r,JSON.stringify(n)):localStorage.removeItem(r)}catch{}}function Ul({projectSlug:t,initialSessionId:s,attachmentsDefault:n,projectAttachments:r,sessionRef:i,setError:o}){const[l,c]=a.useState(()=>Fl(s,t)),m=a.useRef([]);m.current=l;const[u,b]=a.useState(!1),[f,h]=a.useState(!1),j=a.useRef(null);a.useEffect(()=>{Ol(s,t,l)},[l,s,t]);const x=a.useRef(null);a.useEffect(()=>{if(!s){x.current=qt(null,t);return}const T=x.current;if(x.current=null,!(!T||T===qt(s,t)))try{localStorage.removeItem(T)}catch{}},[s,t]);const k=a.useMemo(()=>{const T=n??{enabled:!0,maxFileSizeMb:25,maxFilesPerMessage:10,allowedTypes:["*"]},w=r??{};return{enabled:w.enabled??T.enabled,maxFileSizeMb:w.maxFileSizeMb??T.maxFileSizeMb,maxFilesPerMessage:w.maxFilesPerMessage??T.maxFilesPerMessage,allowedTypes:w.allowedTypes??T.allowedTypes}},[n,r]),d=k.enabled,p=a.useCallback(async T=>{if(!d||T.length===0)return;const w=k.maxFileSizeMb*1024*1024,F=k.maxFilesPerMessage-m.current.length;if(F<=0){o(`You can attach at most ${k.maxFilesPerMessage} files per message.`);return}const O=[];for(const z of T.slice(0,F)){if(!Ui(k.allowedTypes,z.type,z.name)){o(`File type not allowed: ${z.name}`);continue}if(z.size>w){o(`File too large (max ${k.maxFileSizeMb} MB): ${z.name}`);continue}O.push(z)}if(T.length>F&&o(`You can attach at most ${k.maxFilesPerMessage} files per message.`),O.length!==0){b(!0);try{const{files:z}=await B.uploadAttachments(t,i.current??"new",O);c(X=>[...X,...z])}catch(z){o(z instanceof Error?z.message:"Upload failed.")}finally{b(!1)}}},[d,k,t]),D=a.useCallback(T=>{c(w=>w.filter(F=>F.id!==T))},[]),$=a.useCallback(()=>{c([])},[]),I=a.useCallback(T=>{var F;if(!d)return;const w=Array.from(((F=T.clipboardData)==null?void 0:F.files)??[]);w.length>0&&(T.preventDefault(),p(w))},[d,p]),C=a.useCallback(T=>{var w;d&&Array.from(((w=T.dataTransfer)==null?void 0:w.types)??[]).includes("Files")&&(T.preventDefault(),h(!0))},[d]),S=a.useCallback(T=>{T.currentTarget===T.target&&h(!1)},[]),M=a.useCallback(T=>{var F;if(!d)return;const w=Array.from(((F=T.dataTransfer)==null?void 0:F.files)??[]);w.length>0&&(T.preventDefault(),h(!1),p(w))},[d,p]),y=a.useCallback(T=>{const w=Array.from(T.target.files??[]);w.length>0&&p(w),T.target.value=""},[p]);return{attachments:l,attachRef:m,setAttachments:c,uploading:u,dragOver:f,fileInputRef:j,attachConfig:k,attachEnabled:d,addFiles:p,removeAttachment:D,clearAttachments:$,onComposerPaste:I,onComposerDragOver:C,onComposerDragLeave:S,onComposerDrop:M,onPickFiles:y}}const Bl=15e3,Vl="no response — try again";function zl({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,preloadAvailable:l=!1,projectModel:c,projectModels:m,forkParent:u,onOpenForkParent:b,autoFocus:f,emptyHint:h,placeholder:j,trigger:x,projectRecovery:k,projectAttachments:d,onForkFromMessage:p,onRevertToMessage:D,onMessageLink:$,focusMessageUuid:I}){const[C,S]=a.useState([]),[M,y]=a.useState(0),[T,w]=a.useState(()=>Pi(s,t)),F=a.useRef(null),[O,z]=a.useState(!1),[X,L]=a.useState(!1),[v,A]=a.useState(null),[W,Q]=a.useState(null),[ie,K]=a.useState(be.state),[q,N]=a.useState(null),[U,Z]=a.useState(()=>li(s,t)),E=a.useRef(U),H=a.useRef(ci(s,t)),[de,we]=a.useState(()=>di(s,t)),le=a.useRef(de);le.current=de;const he=U!=null||de.length>0,Ne=a.useRef(!1),Ue=a.useRef(!1),[Ae,re]=a.useState(!0),Be=!s,ve=a.useRef(!1),[Te,se]=a.useState([]),[Ve,De]=a.useState(null),[$e,J]=a.useState(null),[me,Ie]=a.useState(null),[Dt,Ze]=a.useState(null),[ze,et]=a.useState([]),[He,We]=a.useState(0),[ke,P]=a.useState(!1),ee=a.useRef(null),[ae,ue]=a.useState(null),[ye,Ke]=a.useState(null),Pt=c??Ve,_t=a.useMemo(()=>m&&m.length>0?Te.filter(g=>m.includes(g.id)):Te,[Te,m]),Ee=a.useRef(s??null),it=a.useRef(null),Lt=a.useRef(!1),{attachments:Pe,attachRef:tt,setAttachments:ot,uploading:lt,dragOver:es,fileInputRef:Ft,attachConfig:Ot,attachEnabled:st,removeAttachment:Ns,clearAttachments:ks,onComposerPaste:Cs,onComposerDragOver:Ss,onComposerDragLeave:Ts,onComposerDrop:$s,onPickFiles:Is}=Ul({projectSlug:t,initialSessionId:s,attachmentsDefault:Dt,projectAttachments:d,sessionRef:Ee,setError:A}),xt=a.useRef(null),ts=a.useRef(Pe.length);a.useEffect(()=>{const g=Pe.length>ts.current;ts.current=Pe.length,g&&xt.current&&(xt.current.scrollTop=xt.current.scrollHeight)},[Pe.length]);const ss=a.useCallback(g=>Ee.current?B.subagentMessages(t,Ee.current,g):Promise.resolve([]),[t]),Ut=Eo(C),[ct,ns]=a.useState([]);a.useEffect(()=>{const g=s??null;if(!g){ns([]);return}return be.onBackgroundWork(g,ns)},[s]);const Bt=Io(ct),pt=$o(Ut,ss,O,Bt),[as,gt]=a.useState(new Set),[Es,bt]=a.useState(new Map),nt=a.useRef(new Map),at=a.useCallback(g=>{const R=nt.current.get(g);R!==void 0&&(clearTimeout(R),nt.current.delete(g))},[]);a.useEffect(()=>{const g=nt.current;return()=>{for(const R of g.values())clearTimeout(R);g.clear()}},[]),a.useEffect(()=>{const g=s??null;if(g)return be.onStopTaskResult(g,({taskId:R,outcome:G,message:V})=>{G!=="stopping"&&(at(R),gt(Y=>{if(!Y.has(R))return Y;const fe=new Set(Y);return fe.delete(R),fe}),G==="error"&&bt(Y=>new Map(Y).set(R,V||"the runtime refused the stop")))})},[s,at]);const Rs=a.useCallback(g=>{const R=s??null;if(!R)return;let G=!1;gt(V=>V.has(g)?(G=!0,V):new Set(V).add(g)),!G&&(bt(V=>{if(!V.has(g))return V;const Y=new Map(V);return Y.delete(g),Y}),at(g),nt.current.set(g,setTimeout(()=>{nt.current.delete(g),gt(V=>{if(!V.has(g))return V;const Y=new Set(V);return Y.delete(g),Y}),bt(V=>new Map(V).set(g,Vl))},Bl)),be.stopTask(R,g))},[s,at]);a.useEffect(()=>{const g=new Set(ct.map(R=>R.id));for(const R of[...nt.current.keys()])g.has(R)||at(R);gt(R=>{const G=new Set([...R].filter(V=>g.has(V)));return G.size===R.size?R:G}),bt(R=>{const G=new Map([...R].filter(([V])=>g.has(V)));return G.size===R.size?R:G})},[ct,at]);const jt=Ro(C),Ms=a.useMemo(()=>Ut.filter(g=>{var R;return!Bt.has(g.toolUseId)&&(((R=pt.get(g.toolUseId))==null?void 0:R.running)??O)}),[Ut,pt,O,Bt]),As=a.useMemo(()=>t?g=>B.projectFileRawUrl(t,g):null,[t]),wt=a.useRef(!s),vt=a.useRef(!1),yt=a.useRef(!1),_e=a.useRef(!1),rs=a.useRef(null),Nt=a.useRef(null),Ge=a.useRef(!0),is=a.useRef(new Set),xn=a.useCallback(()=>{const g=Nt.current;g&&(Ge.current=g.scrollHeight-g.scrollTop-g.clientHeight<80)},[]);a.useLayoutEffect(()=>{const g=Nt.current;g&&Ge.current&&(g.scrollTop=g.scrollHeight)},[C]);const[Vt,os]=a.useState(null),zt=a.useMemo(()=>({focused:Vt,focus:g=>{Ge.current=!1,os(R=>({toolUseId:g,nonce:((R==null?void 0:R.nonce)??0)+1}))}}),[Vt]);a.useEffect(()=>be.onState(K),[]),a.useEffect(()=>{let g=!1;return B.getModels().then(R=>{g||(se(R.models),De(R.defaultModel),Ie(R.recoveryDefault),Ze(R.attachmentsDefault))}).catch(()=>{}),()=>{g=!0}},[]),a.useEffect(()=>{let g=!1;return B.projectCommands(t).then(R=>{g||et(R)}).catch(()=>{}),()=>{g=!0}},[t]);const qe=a.useMemo(()=>{if(!T.startsWith("/"))return null;const g=T.slice(1);return/\s/.test(g)?null:g},[T]),Qe=a.useMemo(()=>{if(qe===null)return[];const g=qe.toLowerCase();return ze.filter(R=>R.name.toLowerCase().includes(g))},[qe,ze]),Ht=qe!==null&&!ke&&Qe.length>0;a.useEffect(()=>{We(0)},[qe]),a.useEffect(()=>{P(!1)},[qe]);const _=a.useCallback(g=>{w(`/${g.name} `),requestAnimationFrame(()=>{var R;return(R=F.current)==null?void 0:R.focus()})},[]),te=a.useCallback(g=>{J(g),ee.current=g,Js(Ee.current??s,t,g)},[t,s]);a.useEffect(()=>{if(s&&s===rs.current){wt.current=!1;return}let g=!1;return Ee.current=s??null,wt.current=!s,it.current=null,vt.current=!1,yt.current=!1,_e.current=!1,A(null),z(!1),s&&n?(L(!0),S([]),n(s).then(({messages:R,total:G,truncated:V})=>{g||(y(V?G-R.length:0),S(Y=>Fs(Tt(R),Y)))}).catch(()=>{g||A("Could not load this chat's history.")}).finally(()=>{g||L(!1)})):(S([]),L(!1)),s&&B.chatContext(t,s).then(R=>{g||!R||(ue({inputTokens:R.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:R.contextTokens,contextLimit:R.contextLimit}),Ke(R))}).catch(()=>{}),()=>{g=!0}},[t,s,n]);const oe=a.useCallback(async()=>{if(!(!s||!n)){try{const{messages:g,total:R,truncated:G}=await n(s);S(Tt(g)),y(G?R-g.length:0)}catch{A("Could not reload this chat's history.")}try{const g=await B.chatContext(t,s);g&&(ue({inputTokens:g.contextTokens,outputTokens:0,cacheReadTokens:0,cacheCreationTokens:0,contextTokens:g.contextTokens,contextLimit:g.contextLimit}),Ke(g))}catch{}}},[s,n,t]),Ye=a.useCallback(g=>{if(!D)return;const R=C.findIndex(Se=>Se.id.split("#")[0]===g),G=R>=0&&C[R].kind==="user";let V=R+1;if(G){let Se=R-1;for(;Se>=0&&C[Se].kind!=="assistant";)Se--;V=Se+1}else for(;V<C.length&&(C[V].kind==="tool"||C[V].kind==="file");)V++;const Y=R>=0?C.slice(V):[],fe=Y.filter(Se=>Se.kind==="tool").length;N({uuid:g,count:Y.length,toolCount:fe,anchorIsUser:G})},[D,C]),Ce=a.useCallback(async()=>{if(q){try{await(D==null?void 0:D(q.uuid)),await oe()}catch{throw new Error("Could not revert this chat.")}N(null)}},[q,D,oe]),[Le,or]=a.useState(null),pn=a.useRef(null);a.useEffect(()=>{if(!I||X||C.length===0)return;const g=`${s??""}:${I}`;if(pn.current===g)return;pn.current=g;const R=V=>V.some(Y=>Y.id.split("#")[0]===I),G=()=>{Ge.current=!1,or(V=>({uuid:I,nonce:((V==null?void 0:V.nonce)??0)+1}))};if(R(C)){G();return}if(M>0&&n){let V=!1;return n(s??"",0).then(({messages:Y})=>{if(V)return;const fe=Tt(Y);if(!R(fe)){Q("That link points at a message that isn't in this chat any more.");return}S(Se=>Fs(fe,Se)),y(0),G()}).catch(()=>{V||Q("Could not load the rest of this chat's history.")}),()=>{V=!0}}Q("That link points at a message that isn't in this chat any more.")},[I,X,C,s,M,n]);const lr=a.useCallback(async()=>{if(!s||!n)return;const{messages:g}=await n(s,0);S(R=>Fs(Tt(g),R)),y(0)},[s,n]),cr=a.useCallback(g=>{var G;const R=Array.from(((G=Nt.current)==null?void 0:G.querySelectorAll("[data-sent-file-turn]"))??[]).find(V=>V.dataset.sentFileTurn===g);R&&(Ge.current=!1,R.scrollIntoView({behavior:"smooth",block:"center"}))},[]),Ds=Il({turns:C,omitted:M,loadEarlier:s&&n?lr:void 0,reveal:cr}),gn=a.useCallback(g=>($==null?void 0:$(g))??`${window.location.origin}${window.location.pathname}#${wa(g)}`,[$]),dr=a.useMemo(()=>p&&D?{onFork:p,onRevert:Ye,contextLimit:ae==null?void 0:ae.contextLimit,linkTo:gn,focused:Le}:null,[p,D,Ye,ae==null?void 0:ae.contextLimit,gn,Le]);a.useEffect(()=>{const R=Ai(s,t)??Pt;R&&(J(R),ee.current=R)},[t,s,Pt]),a.useEffect(()=>{s&&s===rs.current||(ue(null),Ke(null))},[t,s]),a.useEffect(()=>{_i(s,t,T)},[T,s,t]),a.useEffect(()=>{if(W==null)return;const g=setTimeout(()=>Q(null),8e3);return()=>clearTimeout(g)},[W]),a.useEffect(()=>{ui(s,t,U),hi(s,t,he?H.current:null),mi(s,t,de)},[U,de,he,s,t]),a.useEffect(()=>{s&&be.setQueued(t,s,U,he?H.current:null,de)},[U,de,he,s,t,be]),a.useEffect(()=>{var g;(f||!s)&&((g=F.current)==null||g.focus())},[]);const bn=a.useCallback((g,R)=>{const G=R??[];(g||G.length>0)&&(Ge.current=!0,S(V=>[...Fe(V),{kind:"user",id:Je(),content:g??"",...G.length>0?{attachments:G}:{}}])),E.current=null,H.current=null,Z(null),we([])},[]),jn=a.useCallback((g,R,G,V)=>{R&&(H.current=R);const Y=g&&g.length>0?g:null,fe=V??[];G==="returned"&&(E.current!=null||le.current.length)&&Q("Stopped — the queued message went back to the composer that stopped the turn.");const Se=fe.length===le.current.length&&fe.every((br,jr)=>{var Tn;return br.id===((Tn=le.current[jr])==null?void 0:Tn.id)});E.current===Y&&Se||(E.current=Y,Y===null&&fe.length===0&&(H.current=null),Z(Y),Se||we(fe))},[]),wn=a.useRef(jn);wn.current=jn;const ls=a.useCallback((g,R)=>{E.current=null,H.current=null,Z(null);const G=R??le.current;G.length>0&&ot(V=>{const Y=new Set(V.map(fe=>fe.id));return[...V,...G.filter(fe=>!Y.has(fe.id))]}),we([]),w(V=>V.trim()?`${g}
|
|
8
8
|
${V}`:g),requestAnimationFrame(()=>{const V=F.current;V&&(V.style.height="auto",V.style.height=`${Math.min(V.scrollHeight,192)}px`,V.focus())})},[ot]),vn=a.useCallback((g,R)=>ls(g,R),[ls]),yn=a.useRef(vn);yn.current=vn;const Nn=a.useRef(bn);Nn.current=bn,$l({projectSlug:t,initialSessionId:s,loadHistory:n,onSessionEstablished:r,onSessionStarted:i,onTurnComplete:o,sessionRef:Ee,jobRef:it,pendingCancelRef:Lt,streamingRef:vt,awaitingSessionRef:yt,isNewSessionRef:wt,startedNotifiedRef:_e,establishedHereRef:rs,modelRef:ee,cancelledRef:Ne,noticeThisTurnRef:Ue,seenInjectionsRef:is,onQueuedFlushedRef:Nn,onQueuedStateRef:wn,onQueuedReturnedRef:yn,setTurns:S,setStreaming:z,setUsage:ue,setSessionUsage:Ke,setError:A});const kn=a.useCallback(g=>{A(null),Ge.current=!0;const R=g.startsWith("/")?[]:tt.current;if(S(Y=>[...Fe(Y),{kind:"user",id:Je(),content:g,...R.length>0?{attachments:R}:{}}]),R.length>0&&(ot([]),tt.current=[]),F.current&&(F.current.style.height="auto"),z(!0),vt.current=!0,Ue.current=!1,it.current=null,Lt.current=!1,Ee.current===null&&(yt.current=!0),g.startsWith("/")){ve.current=!0,be.sendCommand(t,g,Ee.current);return}const V=wt.current&&!ve.current&&Ae;ve.current=!0,be.send(t,g,Ee.current,{preloadContext:V,model:ee.current??void 0,attachments:R.map(Y=>({id:Y.id,filename:Y.filename,kind:Y.kind}))})},[t,Ae]),Cn=a.useCallback(()=>{const g=T.trim();if(!(!g&&tt.current.length===0)){if(O){const G=(E.current??g).startsWith("/")?[]:tt.current;G.length>0&&(we(V=>{const Y=new Set(V.map(fe=>fe.id));return[...V,...G.filter(fe=>!Y.has(fe.id))]}),ot([]),tt.current=[]),Z(V=>{const Y=g?V?`${V}
|
|
9
9
|
${g}`:g:V;return E.current=Y,(V==null||H.current==null)&&(H.current=fi()),Y}),w(""),F.current&&(F.current.style.height="auto");return}w(""),kn(g)}},[T,O,kn,tt,ot]),ur=a.useCallback(()=>{const g=E.current;g==null&&le.current.length===0||ls(g??"")},[ls]),hr=a.useCallback(()=>{E.current=null,H.current=null,Z(null),we([])},[]),mr=a.useCallback(()=>{Ne.current=!0,it.current?be.cancel(it.current):Lt.current=!0},[]),Sn=a.useCallback(()=>{const g=Ee.current;g&&(vt.current||(z(!0),be.continueChat(t,g)))},[t]),fr=a.useMemo(()=>({enabled:(k==null?void 0:k.surfaceKilledTask)??(me==null?void 0:me.surfaceKilledTask)??!0,busy:O,onContinue:Sn}),[t,k,me,O,Sn]),xr=g=>{if(Ht){if(g.key==="ArrowDown"){g.preventDefault(),We(R=>(R+1)%Qe.length);return}if(g.key==="ArrowUp"){g.preventDefault(),We(R=>(R-1+Qe.length)%Qe.length);return}if(g.key==="Tab"){g.preventDefault(),_(Qe[He]);return}if(g.key==="Enter"){const R=Qe[He];if(R&&R.name!==qe){g.preventDefault(),_(R);return}}if(g.key==="Escape"){g.preventDefault(),P(!0);return}}g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),Cn())},pr=a.useCallback(g=>{w(G=>G.trim()?`${G.trimEnd()} ${g}`:g);const R=F.current;R&&requestAnimationFrame(()=>{R.style.height="auto",R.style.height=`${Math.min(R.scrollHeight,192)}px`,R.focus()})},[]),gr=C.length===0&&!X;return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{ref:Nt,onScroll:xn,className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-4 py-6",children:[x&&e.jsx(Ki,{trigger:x,projectSlug:t}),X&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-surface-active"})]}),gr&&e.jsxs("div",{className:"mt-16 flex flex-col items-center text-center",children:[e.jsx("div",{className:"mb-3 flex h-12 w-12 items-center justify-center rounded-2xl bg-accent-soft text-accent",children:e.jsx(Jt,{width:22,height:22})}),e.jsx("p",{className:"max-w-sm text-sm text-fg-subtle",children:h??"Start the conversation. Messages stream live from Claude and persist as a resumable session."})]}),M>0&&!X&&e.jsxs("p",{className:"pb-4 text-center text-2xs text-fg-subtle",children:[M.toLocaleString()," earlier"," ",M===1?"message is":"messages are"," not shown. They are still saved — reopening this chat always shows the most recent messages first."]}),e.jsx(Ua.Provider,{value:Ds.context,children:e.jsx(Pa.Provider,{value:ss,children:e.jsx(_a.Provider,{value:O,children:e.jsx(ln.Provider,{value:pt,children:e.jsx(La.Provider,{value:zt,children:e.jsx(Fa.Provider,{value:As,children:e.jsx(Aa.Provider,{value:t,children:e.jsx(cn.Provider,{value:fr,children:e.jsx(Oa.Provider,{value:dr,children:e.jsx("div",{className:"space-y-4",children:C.map(g=>e.jsx(pl,{turn:g},g.id))})})})})})})})})})}),Ds.viewer?e.jsx(Rl,{...Ds.viewer}):null]})}),O&&e.jsx(_o,{}),e.jsx(yo,{running:Ms,activity:pt,tasks:ct,commands:jt,onReveal:zt.focus,onCancel:s?Rs:void 0,stopping:as,stopFailed:Es}),v&&e.jsx("div",{className:"mx-auto mb-2 flex w-full max-w-3xl items-start gap-2 px-4",children:e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:v})]})}),W&&e.jsx("div",{className:"mx-auto mb-2 flex w-full max-w-3xl items-start gap-2 px-4",children:e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-lg border border-edge bg-surface-hover px-3 py-2 text-sm text-fg-muted",children:[e.jsx(Xe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:W})]})}),he&&e.jsx(Lo,{text:U??"",attachments:de,onEdit:ur,onClear:hr}),e.jsx("div",{className:"border-t border-edge bg-surface/80 backdrop-blur",children:e.jsxs("div",{className:"pb-safe mx-auto w-full max-w-3xl px-4 pt-3",children:[Be&&e.jsx(Mo,{checked:Ae,available:l,onChange:re}),e.jsx(Ao,{models:_t,model:$e,onSelectModel:te,usage:ae,sessionUsage:ye,forkParent:u,onOpenForkParent:b}),st&&(Pe.length>0||lt)&&e.jsxs("div",{className:"mb-2",children:[Pe.length>1&&e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2 px-1 text-2xs text-fg-subtle",children:[e.jsxs("span",{"data-testid":"attachment-tray-count",children:[Pe.length," files attached"]}),e.jsx("button",{type:"button",onClick:ks,"data-testid":"attachment-tray-clear",title:"Unstage every file from this message",className:"rounded px-1.5 py-0.5 font-medium text-fg-muted hover:bg-surface-active hover:text-danger",children:"Clear all"})]}),e.jsxs("div",{ref:xt,className:"flex max-h-[min(9rem,28vh)] flex-wrap gap-2 overflow-y-auto overscroll-contain","data-testid":"attachment-tray",children:[Pe.map(g=>e.jsx(zi,{attachment:g,onRemove:Ns},g.id)),lt&&e.jsxs("span",{className:"flex items-center gap-1.5 rounded-xl bg-surface-sunken px-3 py-2 text-xs text-fg-muted ring-1 ring-edge",children:[e.jsx("span",{className:"h-3 w-3 animate-spin rounded-full border-2 border-edge-strong border-t-accent"}),"Uploading…"]})]})]}),e.jsxs("div",{className:`relative flex items-end gap-2 rounded-2xl border bg-surface-raised p-2 shadow-sm focus-within:border-accent focus-within:ring-2 focus-within:ring-accent/20 ${es?"border-accent ring-2 ring-accent/30":"border-edge-strong"}`,onDragOver:st?Ss:void 0,onDragLeave:st?Ts:void 0,onDrop:st?$s:void 0,children:[es&&e.jsx("div",{className:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-2xl bg-accent-soft text-sm font-medium text-accent",children:"Drop files to attach"}),Ht&&e.jsx("div",{className:"menu bottom-full left-0 mb-2 max-h-64 w-full overflow-y-auto",role:"menu","aria-label":"Slash commands",children:Qe.map((g,R)=>e.jsx("button",{type:"button",role:"menuitem",className:`menu-item ${R===He?"bg-surface-selected":""}`,onMouseEnter:()=>We(R),onMouseDown:G=>{G.preventDefault(),_(g)},children:e.jsxs("span",{className:"flex w-full items-baseline gap-2",children:[e.jsxs("span",{className:"font-mono font-medium text-accent",children:["/",g.name]}),g.argumentHint&&e.jsx("span",{className:"shrink-0 text-fg-subtle",children:g.argumentHint}),g.description&&e.jsx("span",{className:"ml-auto truncate text-fg-muted",children:g.description})]})},g.name))}),e.jsx("textarea",{ref:F,className:"max-h-48 min-h-[40px] flex-1 resize-none bg-transparent px-2 py-2 text-sm outline-none",rows:1,autoCapitalize:"sentences",value:T,placeholder:O?"Queue a message to send next…":j??"Message Claude…",onChange:g=>{w(g.target.value);const R=g.target;R.style.height="auto",R.style.height=`${Math.min(R.scrollHeight,192)}px`},onKeyDown:xr,onPaste:st?Cs:void 0}),st&&e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:Ft,type:"file",multiple:!0,accept:Oi(Ot.allowedTypes)||void 0,className:"hidden","data-testid":"attachment-input",onChange:Is}),e.jsx("button",{type:"button",onClick:()=>{var g;return(g=Ft.current)==null?void 0:g.click()},title:"Attach files","aria-label":"Attach files","data-testid":"attachment-button",className:"btn bg-transparent text-fg-muted hover:bg-surface-hover hover:text-fg",children:e.jsx(Rr,{width:16,height:16})})]}),e.jsx(Ei,{onText:pr}),O?e.jsxs("button",{type:"button",onClick:mr,title:"Stop generating","aria-label":"Stop",className:"btn bg-surface-active text-fg-muted hover:bg-surface-selected",children:[e.jsx(Gs,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Stop"})]}):e.jsxs("button",{type:"button",onClick:Cn,disabled:!T.trim()&&Pe.length===0||lt,className:"btn-primary",title:"Send (Enter)","aria-label":"Send",children:[e.jsx(fa,{width:15,height:15}),e.jsx("span",{className:"hidden sm:inline",children:"Send"})]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between px-1 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[e.jsx("kbd",{className:"font-sans",children:"Enter"})," to ",O?"queue":"send"," ·"," ",e.jsx("kbd",{className:"font-sans",children:"Shift+Enter"})," for newline"]}),e.jsx(Fo,{state:ie})]})]})}),e.jsx(on,{open:q!==null,wide:!0,dismissOnBackdrop:!1,title:"Revert this chat back to here?",confirmLabel:"Revert chat",message:q&&e.jsxs(e.Fragment,{children:[q.anchorIsUser&&e.jsx("p",{className:"mb-2",children:"This rewinds to the assistant's previous reply."}),e.jsxs("p",{children:[e.jsxs("span",{className:"font-medium text-fg",children:[q.count," message",q.count===1?"":"s"]})," ","will be removed",q.toolCount>0?e.jsxs(e.Fragment,{children:[", including"," ",e.jsxs("span",{className:"font-medium text-fg",children:[q.toolCount," tool call",q.toolCount===1?"":"s"]}),"."]}):"."]}),q.toolCount>0&&e.jsxs("p",{className:"mt-3 rounded-lg bg-warn-soft px-3 py-2 text-warn",children:[e.jsx("span",{className:"font-medium",children:"Those actions are not undone."})," Files written, PRs opened and messages sent stay as they are — only the conversation is rewound."]}),e.jsx("p",{className:"mt-3",children:"The removed messages are backed up, and this chat keeps its id."})]}),onConfirm:Ce,onClose:()=>N(null)})]})}function Hl(t){var r;const s=t.untracked?"??":(t.status||"").trim(),n=((r=s[0])==null?void 0:r.toUpperCase())??"";return t.untracked||n==="?"?{label:"??",cls:"bg-surface-active text-fg-muted"}:n==="A"?{label:"A",cls:"bg-success-soft text-success"}:n==="D"?{label:"D",cls:"bg-danger-soft text-danger"}:n==="R"?{label:"R",cls:"bg-lineage-soft text-lineage"}:n==="M"?{label:"M",cls:"bg-warn-soft text-warn"}:{label:n||s||"•",cls:"bg-surface-active text-fg-muted"}}function Wl({slug:t,status:s,onStatusChange:n,selectedFile:r,onSelectFile:i}){var Z;const[o,l]=a.useState(null),[c,m]=a.useState(null),u=i!==void 0,b=u?r??null:c,f=a.useCallback(E=>{u?i==null||i(E):m(E)},[u,i]),[h,j]=a.useState(""),[x,k]=a.useState(!1),[d,p]=a.useState(!1),[D,$]=a.useState(null),[I,C]=a.useState(null),[S,M]=a.useState(new Set),y=s.files,T=y.length,w=y.filter(E=>!S.has(E.path)).map(E=>E.path),F=w.length,O=F===y.length&&y.length>0,z=a.useCallback(E=>{M(H=>{const de=new Set(H);return de.has(E)?de.delete(E):de.add(E),de})},[]),X=a.useCallback(()=>M(new Set),[]),L=a.useCallback(()=>M(new Set(y.map(E=>E.path))),[y]),v=a.useCallback(async()=>{const E=await B.gitProjectInfo(t).catch(()=>null);E&&l(E)},[t]);a.useEffect(()=>{v()},[v]);const A=a.useCallback(async()=>{const E=await B.gitStatus(t).catch(()=>null);E&&n(E)},[t,n]),W=b&&y.some(E=>E.path===b)?b:((Z=y[0])==null?void 0:Z.path)??null,Q=y.find(E=>E.path===W)??null,ie=a.useCallback(async()=>{const E=h.trim();if(!(!E||x||w.length===0)){k(!0),$(null),C(null);try{const H=O?await B.gitCommit(t,E):await B.gitCommit(t,E,w);H.committed?(j(""),M(new Set),C(H.hash?`Committed ${H.hash.slice(0,7)}`:"Committed"),await A(),await v()):C(H.error??"Nothing to commit")}catch(H){$(H instanceof je?H.message:"Commit failed")}finally{k(!1)}}},[h,x,w,O,t,A,v]),K=(o==null?void 0:o.ahead)??0,q=(o==null?void 0:o.configured)??!1,N=q&&K>0&&!d,U=a.useCallback(async()=>{if(N){p(!0),$(null),C(null);try{const E=await B.gitPush(t);E.pushed?(C("Pushed to remote"),await v()):$(E.error??"Push failed")}catch(E){$(E instanceof je?E.message:"Push failed")}finally{p(!1)}}},[N,v,t]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-edge px-4 py-2.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-medium text-fg-muted",children:[e.jsx(ft,{width:14,height:14,className:"text-fg-subtle"}),s.branch??"—"]}),s.clean?e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-fg-subtle",children:[e.jsx(It,{width:12,height:12}),"clean"]}):e.jsxs("span",{className:"rounded-md bg-warn-soft px-1.5 py-0.5 text-2xs font-medium text-warn",children:[T," uncommitted"]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(Jl,{info:o,onChanged:v}),e.jsxs("button",{type:"button",onClick:()=>void U(),disabled:!N,title:q?K>0?`Push ${K} commit${K===1?"":"s"} to the remote`:"Nothing to push":"No remote configured",className:"btn-ghost py-1.5 text-xs",children:[e.jsx(Mr,{width:13,height:13}),d?"Pushing…":"Push",q&&K>0&&e.jsxs("span",{className:"text-2xs font-semibold text-accent",children:["↑",K]})]})]})]}),(D||I)&&e.jsxs("div",{className:"px-4 pt-2",children:[D&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{className:"break-words",children:D})]}),!D&&I&&e.jsx("p",{className:"text-xs text-fg-muted",children:I})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:flex-row",children:[e.jsxs("div",{className:"flex w-full shrink-0 flex-col border-b border-edge lg:w-72 lg:border-b-0 lg:border-r",children:[e.jsxs("div",{className:"mb-1 mt-3 flex items-center justify-between gap-2 px-3",children:[e.jsx("span",{className:"section-label px-0",children:"Changed files"}),y.length>0&&e.jsxs("span",{className:"flex items-center gap-1.5 text-2xs text-fg-subtle",children:[e.jsxs("span",{children:[F,"/",y.length," selected"]}),e.jsx("button",{type:"button",onClick:O?L:X,className:"rounded px-1 py-0.5 font-medium text-accent hover:bg-accent/10",title:O?"Deselect all files":"Select all files",children:O?"None":"All"})]})]}),e.jsx("div",{className:"max-h-[35vh] overflow-y-auto px-2 pb-2 lg:max-h-none lg:flex-1",children:y.length===0?e.jsx("p",{className:"px-2 py-2 text-sm italic text-fg-subtle",children:"No uncommitted changes. Files you author surface here for a checkpoint."}):y.map(E=>e.jsx(Kl,{file:E,active:W===E.path,selected:!S.has(E.path),onSelect:()=>f(E.path),onToggleSelect:()=>z(E.path)},E.path))}),e.jsxs("div",{className:"border-t border-edge p-3",children:[e.jsx("textarea",{rows:2,value:h,placeholder:"Commit message…",onChange:E=>j(E.target.value),className:"max-h-40 min-h-[44px] w-full resize-none rounded-lg border border-edge-strong bg-surface-sunken px-2.5 py-2 text-sm text-fg outline-none transition-colors focus:border-accent focus:ring-2 focus:ring-accent/20"}),e.jsxs("button",{type:"button",onClick:()=>void ie(),disabled:!h.trim()||x||F===0,className:"btn-primary mt-2 w-full py-1.5 text-xs",title:y.length===0?"Nothing to commit":F===0?"Select at least one file to commit":O?"Commit all changed files":`Commit ${F} selected file${F===1?"":"s"}`,children:[e.jsx(It,{width:13,height:13}),x?"Committing…":F>0&&!O?`Commit ${F} selected`:"Commit"]})]})]}),e.jsx("div",{className:"min-h-0 min-w-0 flex-1",children:e.jsx(Gl,{slug:t,file:Q})})]})]})}function mn({file:t}){if(t.binary)return e.jsx("span",{className:"text-fg-subtle",children:"binary"});const{added:s,removed:n}=t;return s==null&&n==null?null:!s&&!n?e.jsx("span",{className:"text-fg-subtle",children:"0"}):e.jsxs("span",{className:"inline-flex items-center gap-1 font-mono tabular",children:[s?e.jsxs("span",{className:"text-success",children:["+",s]}):null,n?e.jsxs("span",{className:"text-danger",children:["−",n]}):null]})}function Kl({file:t,active:s,selected:n,onSelect:r,onToggleSelect:i}){const o=Hl(t),l=t.untracked?"untracked":t.staged?"staged":"unstaged";return e.jsxs("div",{className:`mb-0.5 flex items-center gap-2 rounded-lg pl-2 pr-2.5 transition-colors ${s?"bg-surface-selected":"hover:bg-surface-hover"}`,children:[e.jsx("input",{type:"checkbox",checked:n,onChange:i,"aria-label":`Stage ${t.path}`,title:n?"Included in commit — click to exclude":"Excluded — click to include",className:"h-3.5 w-3.5 shrink-0 cursor-pointer accent-[var(--accent-solid)]"}),e.jsxs("button",{type:"button",onClick:r,title:t.path,className:"flex min-w-0 flex-1 items-center gap-2 py-2 text-left text-sm",children:[e.jsx("span",{className:`inline-flex h-5 w-6 shrink-0 items-center justify-center rounded font-mono text-3xs font-semibold ${o.cls}`,children:o.label}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate font-mono text-xs text-fg-muted",children:t.path}),e.jsxs("span",{className:"flex items-center gap-2 text-3xs text-fg-subtle",children:[e.jsx("span",{children:l}),e.jsx(mn,{file:t})]})]})]})]})}function Gl({slug:t,file:s}){const n=(s==null?void 0:s.path)??null,r=(s==null?void 0:s.untracked)??!1,[i,o]=a.useState(""),[l,c]=a.useState(!1),[m,u]=a.useState(null);if(a.useEffect(()=>{if(!n||r){o(""),u(null),c(!1);return}let f=!1;return c(!0),u(null),B.gitDiff(t,n).then(h=>{f||o(h)}).catch(h=>{f||u(h instanceof je?h.message:"Failed to load diff")}).finally(()=>{f||c(!1)}),()=>{f=!0}},[t,n,r]),!s)return e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-sm text-fg-subtle",children:"Select a file to view its diff."});if(r)return e.jsx(Yl,{slug:t,file:s});if(l)return e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-surface-active"})]});if(m)return e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:m})]})});if(!i.trim())return e.jsxs("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm text-fg-subtle",children:["No textual diff for this file",e.jsx("br",{}),"(e.g. a mode or binary change)."]});const b=i.split(`
|
|
10
10
|
`);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx(ql,{file:s}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken",children:e.jsx("pre",{className:"min-w-full whitespace-pre px-4 py-3 font-mono text-xs leading-relaxed",children:b.map((f,h)=>e.jsx("div",{className:Ql(f),children:f||" "},h))})})]})}function ql({file:t}){return e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-muted",children:t.path}),e.jsx(mn,{file:t})]})}function Ql(t){return t.startsWith("+++")||t.startsWith("---")||t.startsWith("diff ")||t.startsWith("index ")?"text-fg-subtle":t.startsWith("@@")?"text-lineage":t.startsWith("+")?"bg-success-soft text-success":t.startsWith("-")?"bg-danger-soft text-danger":"text-fg-muted"}function Yl({slug:t,file:s}){const n=s.path,[r,i]=a.useState(null),[o,l]=a.useState(!0),[c,m]=a.useState(null);a.useEffect(()=>{let b=!1;return l(!0),m(null),i(null),B.gitUntrackedFile(t,n).then(f=>{b||i(f)}).catch(f=>{b||m(f instanceof je?f.message:"Failed to load file")}).finally(()=>{b||l(!1)}),()=>{b=!0}},[t,n]);const u=e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-muted",children:n}),e.jsx(mn,{file:s}),e.jsx("span",{className:"rounded bg-success-soft px-1.5 py-0.5 font-medium text-success",children:"new file · untracked"})]});return o?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-3.5 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-1/2 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-3.5 w-3/5 animate-pulse rounded bg-surface-active"})]}):c||!r?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:c??"File not found."})]})}):r.kind==="image"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",children:e.jsx("img",{src:B.gitUntrackedFileRawUrl(t,n),alt:n,className:"max-h-full max-w-full object-contain shadow-sm"})})]}):r.kind==="pdf"?e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(un,{src:B.gitUntrackedFileRawUrl(t,n),filename:n,className:"h-full min-h-[480px] w-full"})})]}):e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[u,e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken",children:e.jsx("pre",{className:"min-w-full whitespace-pre-wrap break-words border-l-2 border-success-edge px-4 py-3 font-mono text-xs leading-relaxed text-fg-muted",children:r.content})})]})}function Jl({info:t,onChanged:s}){const[n,r]=a.useState(!1),[i,o]=a.useState(null),[l,c]=a.useState(!1),[m,u]=a.useState(null),[b,f]=a.useState(!1),h=a.useRef(!1);a.useEffect(()=>(h.current=!1,()=>{h.current=!0}),[]);const j=t==null?void 0:t.github,x=a.useCallback(async()=>{r(!0),u(null);try{const d=await B.githubConnect();o({userCode:d.userCode,verificationUri:d.verificationUri}),c(!0),h.current=!1;const p=Date.now()+d.expiresIn*1e3;let D=Math.max(1,d.interval)*1e3;const $=async()=>{if(!h.current){if(Date.now()>=p){c(!1),o(null),u("The code expired before authorization. Try again.");return}try{const I=await B.githubPoll(d.deviceCode);if(h.current)return;if(I.status==="authorized"){c(!1),o(null),await s();return}if(I.status==="error"){c(!1),o(null),u(I.error??"Authorization failed.");return}I.status==="slow_down"&&(D+=5e3),window.setTimeout(()=>void $(),D)}catch(I){if(h.current)return;c(!1),o(null),u(I instanceof je?I.message:"Polling failed.")}}};window.setTimeout(()=>void $(),D)}catch(d){u(d instanceof je?d.message:"Could not start the GitHub connection.")}finally{r(!1)}},[s]),k=a.useCallback(async()=>{f(!0);try{await B.githubDisconnect(),await s()}catch{}finally{f(!1)}},[s]);return j?j.configured?j.connected?e.jsxs("span",{className:"inline-flex items-center gap-2 text-2xs text-fg-muted",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(_s,{width:13,height:13}),"@",j.login??"github"]}),e.jsx("button",{type:"button",onClick:()=>void k(),disabled:b,className:"btn-subtle px-2 py-1 text-2xs",title:"Disconnect GitHub",children:b?"…":"Disconnect"})]}):e.jsxs("span",{className:"inline-flex items-center gap-2",children:[i?e.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5 text-2xs text-fg-muted",children:[e.jsx("span",{className:"text-fg-muted",children:"Enter"}),e.jsx("code",{className:"rounded bg-surface-active px-1.5 py-0.5 font-mono text-xs font-semibold tracking-widest text-fg",children:i.userCode}),e.jsx("span",{className:"text-fg-muted",children:"at"}),e.jsxs("a",{href:i.verificationUri,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-accent underline underline-offset-2 hover:text-accent-solid-hover",children:[e.jsx(ma,{width:11,height:11}),"github.com"]}),l&&e.jsx("span",{className:"text-fg-subtle",children:"· waiting…"})]}):e.jsxs("button",{type:"button",onClick:()=>void x(),disabled:n,className:"btn-ghost py-1.5 text-xs",title:"Authorize paddock to push to GitHub on your behalf (device flow).",children:[e.jsx(_s,{width:13,height:13}),n?"Starting…":"Connect GitHub"]}),m&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-2xs text-danger",children:[e.jsx(pe,{width:12,height:12}),m]})]}):e.jsxs("span",{className:"hidden items-center gap-1.5 text-2xs text-fg-subtle sm:inline-flex",title:"Set PADDOCK_GITHUB_CLIENT_ID on the server to enable in-app GitHub auth.",children:[e.jsx(_s,{width:13,height:13}),"GitHub not configured"]}):null}function Xl(t){return t==="scheduled"?{label:"Scheduled",icon:e.jsx(Xe,{width:12,height:12}),cls:"bg-warn-soft text-warn"}:t==="spawned"?{label:"Spawned",icon:e.jsx(ft,{width:12,height:12}),cls:"bg-lineage-soft text-lineage"}:t==="adopted"?{label:"Adopted",icon:e.jsx(Xt,{width:12,height:12}),cls:"bg-success-soft text-success"}:{label:"You",icon:e.jsx(Yt,{width:12,height:12}),cls:"bg-surface-active text-fg-muted"}}function Zl(t){switch(t){case"completed":return{label:"completed",cls:"bg-success-soft text-success"};case"failed":return{label:"failed",cls:"bg-danger-soft text-danger"};case"running":return{label:"running",cls:"bg-info-soft text-info"};case"cancelled":return{label:"cancelled",cls:"bg-surface-active text-fg-muted"};case"pending":return{label:"pending",cls:"bg-warn-soft text-warn"};default:return{label:t,cls:"bg-surface-active text-fg-muted"}}}function ec(t){if(t.durationSeconds!=null)return xs(t.durationSeconds*1e3)??"—";if(t.status==="running"){const s=Date.parse(t.startedAt);if(Number.isFinite(s))return`${xs(Date.now()-s)??"—"}…`}return"—"}function zs(t){return t.origin!=="human"&&t.origin!=="adopted"}function tc(t){return t.origin==="scheduled"?t.schedule?`schedule · ${t.schedule}`:"schedule":t.origin==="spawned"?t.depth>1?`spawned · ${t.depth} levels deep`:"spawned by another chat":t.origin==="adopted"?"adopted from the Claude Code CLI":"you"}function sc({run:t,title:s,onOpen:n}){var c,m;const r=Xl(t.origin),i=Zl(t.status),o=t.sessionId!=null,l=((c=t.prompt)==null?void 0:c.trim())||((m=t.summary)==null?void 0:m.trim())||s;return e.jsxs("button",{type:"button",onClick:o?n:void 0,disabled:!o,"data-run-origin":t.origin,"data-run-new":t.isNew?"true":void 0,className:`flex w-full items-start gap-3 border-t border-edge px-4 py-3 text-left first:border-t-0 ${o?"hover:bg-surface-hover":"cursor-default"} ${t.isNew?"bg-accent-soft":""}`,children:[e.jsx("span",{className:"mt-1.5 w-1.5 shrink-0",children:t.isNew&&e.jsx("span",{"data-run-unread":"true","aria-label":"New since your last visit",title:"Ran while you were away",className:"block h-1.5 w-1.5 rounded-full bg-accent-solid"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-2xs font-medium ${r.cls}`,children:[r.icon,r.label]}),e.jsx("span",{className:`inline-flex items-center rounded px-1.5 py-0.5 text-2xs font-medium ${i.cls}`,children:i.label})]}),e.jsx("p",{className:"mt-1 truncate text-sm text-fg",children:l}),e.jsx("p",{className:"mt-0.5 truncate text-xs text-fg-muted",children:tc(t)})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-0.5 text-xs text-fg-muted",children:[e.jsx("span",{title:new Date(t.startedAt).toLocaleString(),children:Et(t.startedAt)}),e.jsx("span",{className:"font-mono tabular",children:ec(t)}),e.jsx("span",{className:"font-mono text-fg-subtle",title:"Per-run cost is coming soon",children:"—"})]})]})}function nc({slug:t,state:s,chats:n,onOpenChat:r}){const{data:i,loading:o,error:l,refresh:c,markSeen:m}=s,[u,b]=a.useState("unattended");a.useEffect(()=>{m()},[t]);const f=a.useMemo(()=>{const d=new Map;for(const p of n)d.set(p.sessionId,p.name);return p=>p&&d.get(p)||(p?p.slice(0,8):"unknown chat")},[n]),h=(i==null?void 0:i.runs)??[],j=a.useMemo(()=>h.filter(zs).length,[h]),x=a.useMemo(()=>u==="unattended"?h.filter(zs):h,[h,u]),k=a.useMemo(()=>h.filter(d=>d.isNew&&zs(d)).length,[h]);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-edge px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Run history"}),e.jsx("button",{type:"button",onClick:()=>void c(),className:"text-xs text-fg-muted hover:text-fg",children:"Refresh"})]}),e.jsxs("div",{className:"inline-flex overflow-hidden rounded-lg border border-edge text-xs",children:[e.jsxs(Yn,{active:u==="unattended",onClick:()=>b("unattended"),children:["Unattended",j>0?` (${j})`:""]}),e.jsx(Yn,{active:u==="all",onClick:()=>b("all"),children:"All"})]})]}),k>0&&e.jsxs("div",{"data-since-last-visit":k,className:"border-b border-accent-edge bg-accent-soft px-4 py-2 text-sm text-fg",children:[e.jsxs("span",{className:"font-medium",children:[k," new ",k===1?"run":"runs"]})," ","ran while you were away."]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:l?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-danger",children:l}):o&&h.length===0?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-fg-muted",children:"Loading run history…"}):x.length===0?e.jsx(ac,{filter:u,hasAny:h.length>0}):e.jsx("div",{children:x.map(d=>e.jsx(sc,{run:d,title:f(d.sessionId),onOpen:()=>d.sessionId&&r(d.sessionId)},d.jobId))})})]})}function Yn({active:t,onClick:s,children:n}){return e.jsx("button",{type:"button",onClick:s,className:`motion-fast px-2.5 py-1 font-medium transition-colors ${t?"bg-accent-soft text-accent":"text-fg-muted hover:text-fg"}`,children:n})}function ac({filter:t,hasAny:s}){return e.jsxs("div",{className:"px-4 py-12 text-center",children:[e.jsx("p",{className:"text-sm font-medium text-fg",children:t==="unattended"?"No unattended runs yet":"No runs yet"}),e.jsx("p",{className:"mx-auto mt-1 max-w-sm text-xs text-fg-muted",children:t==="unattended"?s?"Scheduled and spawned runs will show up here. Switch to All to see your own runs.":"Scheduled and spawned runs — the ones that happen while you're not watching — will show up here.":"Runs appear here once Claude starts finishing turns."})]})}function rc(t){const[s,n]=a.useState(null),[r,i]=a.useState(!0),[o,l]=a.useState(null),[c,m]=a.useState(!1),u=a.useCallback(async()=>{i(!0),m(!1);try{const h=await B.projectRuns(t);n(h),l(null)}catch(h){l(h instanceof Error?h.message:"Failed to load run history")}finally{i(!1)}},[t]);a.useEffect(()=>{u()},[u]);const b=a.useCallback(async()=>{m(!0),await B.markRunsSeen(t).catch(()=>{})},[t]),f=c?0:(s==null?void 0:s.newUnattended)??0;return{data:s,loading:r,error:o,newUnattended:f,refresh:u,markSeen:b}}function ic({slug:t,name:s}){const[n,r]=a.useState(null),[i,o]=a.useState(null),[l,c]=a.useState(!0);return a.useEffect(()=>{let m=!1;return c(!0),o(null),r(null),B.getProjectFile(t,s).then(u=>{m||r(u)}).catch(u=>{m||o(u instanceof Error?u.message:"Failed to load file")}).finally(()=>{m||c(!1)}),()=>{m=!0}},[t,s]),l?e.jsxs("div",{className:"space-y-3 p-6",children:[e.jsx("div",{className:"h-4 w-1/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-2/3 animate-pulse rounded bg-surface-active"}),e.jsx("div",{className:"h-4 w-1/2 animate-pulse rounded bg-surface-active"})]}):i||!n?e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:i??"File not found."})]})}):n.kind==="image"?e.jsx(lc,{slug:t,name:n.name}):n.kind==="pdf"?e.jsx(cc,{slug:t,name:n.name}):n.kind==="html"?e.jsx(oc,{name:n.name,content:n.content}):n.kind==="text"?e.jsx("div",{className:"overflow-auto p-6",children:e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-lg border border-edge bg-surface-sunken p-4 font-mono text-xs leading-relaxed text-fg",children:n.content})}):e.jsx("article",{className:"prose-doc mx-auto max-w-3xl px-6 py-6",children:e.jsx(Zt,{mermaid:!0,children:n.content})})}function oc({name:t,content:s}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:[e.jsx(dc,{}),e.jsxs("span",{children:[e.jsx("span",{className:"font-mono text-fg-muted",children:t})," renders in a sandboxed frame (scripts allowed, isolated from the app)."]})]}),e.jsx("iframe",{title:t,sandbox:"allow-scripts",srcDoc:s,className:"html-preview min-h-[480px] w-full flex-1"})]})}function lc({slug:t,name:s}){const[n,r]=a.useState(!1);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:e.jsx("span",{className:"font-mono text-fg-muted",children:s})}),e.jsx("div",{className:"flex flex-1 items-center justify-center overflow-auto p-6",style:{background:"repeating-conic-gradient(color-mix(in oklab, var(--text) 6%, transparent) 0% 25%, transparent 0% 50%) 50% / 20px 20px"},children:n?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"shrink-0"}),e.jsx("span",{children:"Could not display this image."})]}):e.jsx("img",{src:B.projectFileRawUrl(t,s),alt:s,onError:()=>r(!0),className:"max-h-full max-w-full object-contain shadow-sm"})})]})}function cc({slug:t,name:s}){return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 border-b border-edge bg-surface-sunken px-4 py-2 text-2xs text-fg-muted",children:e.jsx("span",{className:"font-mono text-fg-muted",children:s})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(un,{src:B.projectFileRawUrl(t,s),filename:s,className:"h-full min-h-[480px] w-full"})})]})}function dc(){return e.jsx("svg",{width:13,height:13,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-fg-subtle",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10Z"})})}function uc({project:t,path:s,onNavigate:n,onTogglePin:r}){const i=t.slug,[o,l]=a.useState(null),[c,m]=a.useState(!1),[u,b]=a.useState(null),[f,h]=a.useState(!0);a.useEffect(()=>{let d=!1;return h(!0),b(null),l(null),m(!1),B.listProjectDir(i,s).then(p=>{d||(p.kind==="file"?m(!0):l(p))}).catch(p=>{d||b(p instanceof Error?p.message:"Failed to load files")}).finally(()=>{d||h(!1)}),()=>{d=!0}},[i,s]);const j=s.includes("/")?s.slice(0,s.lastIndexOf("/")):"",x=e.jsx(hc,{path:s,isFile:c,onNavigate:n});if(f)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[x,e.jsx("div",{className:"space-y-2",children:[0,1,2].map(d=>e.jsx("div",{className:"h-10 animate-pulse rounded-lg bg-surface-active"},d))})]})});if(u)return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[x,e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-danger-edge bg-danger-soft px-3 py-2 text-sm text-danger",children:[e.jsx(pe,{width:16,height:16,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:u})]})]})});if(c){const d=t.pinned.includes(s);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-edge px-4 py-2",children:[e.jsx("div",{className:"min-w-0 flex-1",children:x}),e.jsxs("button",{onClick:()=>r(s),className:`ml-auto inline-flex shrink-0 items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs font-medium transition-colors ${d?"bg-accent/10 text-accent":"text-fg-muted hover:bg-surface-hover"}`,title:d?"Unpin (remove tab)":"Pin as a tab",children:[e.jsx(ps,{width:13,height:13}),d?"Pinned":"Pin as tab"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsx(ic,{slug:i,name:s})})]})}const k=(o==null?void 0:o.entries)??[];return e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[x,k.length===0&&s===""?e.jsx("div",{className:"card",children:e.jsx("p",{className:"text-sm italic text-fg-subtle",children:"No files yet. Files Claude writes (and sweep-curated OVERVIEW.md) will appear here."})}):e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-edge",children:[s!==""&&e.jsxs("button",{onClick:()=>n(j),className:"flex w-full items-center gap-2 px-3 py-2.5 text-left transition-colors hover:bg-surface-hover",children:[e.jsx(qs,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:"font-mono text-sm text-fg-muted",children:".."})]}),k.length===0&&s!==""&&e.jsx("div",{className:"px-3 py-2.5 text-sm italic text-fg-subtle",children:"This folder is empty."}),k.map((d,p)=>{const D=s?`${s}/${d.name}`:d.name,$=d.kind==="dir",I=t.pinned.includes(D),C=!$,S=p>0||s!==""?"border-t border-edge":"";return e.jsxs("div",{className:`group/file flex items-center gap-2 px-3 py-2.5 transition-colors hover:bg-surface-hover ${S}`,children:[e.jsxs("button",{onClick:()=>n(D),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[$?e.jsx(qs,{width:15,height:15,className:"shrink-0 text-accent/80"}):e.jsx(Qt,{width:15,height:15,className:"shrink-0 text-fg-subtle"}),e.jsx("span",{className:`truncate font-mono text-sm ${$?"font-medium text-fg":"text-fg"}`,children:d.name}),$&&e.jsx(At,{width:14,height:14,className:"ml-auto shrink-0 text-fg-subtle"})]}),C&&e.jsxs("button",{type:"button","aria-label":I?`Unpin ${d.name}`:`Pin ${d.name}`,title:I?"Unpin (remove tab)":"Pin as a sibling tab",onClick:()=>r(D),className:`flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-2xs font-medium transition ${I?"bg-accent/10 text-accent":"text-fg-subtle opacity-0 hover:bg-surface-active hover:text-fg-muted focus:opacity-100 group-hover/file:opacity-100"}`,children:[e.jsx(ps,{width:12,height:12}),I?"Pinned":"Pin"]})]},d.name)})]})]})})}function hc({path:t,isFile:s,onNavigate:n}){const r=t?t.split("/"):[];return e.jsxs("nav",{"aria-label":"File path",className:"mb-3 flex flex-wrap items-center gap-x-1 gap-y-0.5 text-sm",children:[e.jsx(Jn,{label:"Files",isLast:r.length===0,onClick:()=>n("")}),r.map((i,o)=>{const l=o===r.length-1,c=r.slice(0,o+1).join("/");return e.jsxs("span",{className:"flex items-center gap-x-1",children:[e.jsx(At,{width:13,height:13,className:"shrink-0 text-fg-subtle"}),e.jsx(Jn,{label:i,isLast:l,mono:!0,muted:l&&s,onClick:()=>n(c)})]},c)})]})}function Jn({label:t,isLast:s,mono:n,muted:r,onClick:i}){const o=n?"font-mono":"";return s?e.jsx("span",{"aria-current":"page",className:`${o} font-medium ${r?"text-fg-muted":"text-fg"}`,children:t}):e.jsx("button",{type:"button",onClick:i,className:`${o} rounded text-fg-muted transition-colors hover:text-accent`,children:t})}function xe({children:t}){return e.jsx("p",{className:"mt-1 text-xs leading-snug text-fg-muted",children:t})}function Xn({children:t}){return e.jsxs("p",{className:"mt-1 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(pe,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsx("span",{children:t})]})}function Rt({label:t,value:s}){return e.jsxs("div",{children:[e.jsx("dt",{className:"text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:t}),e.jsx("dd",{className:"mt-0.5 text-sm text-fg-muted",children:s})]})}function mc({project:t,onDeleted:s}){const[n,r]=a.useState(!1);if(Na(t.slug))return null;const i=xi(t);return e.jsxs(mt,{title:"Danger zone",description:i?"Deleting unlinks this project: Paddock’s notes, settings and chats go, and the directory it works in is left untouched.":"Deleting removes this project’s directory — its notes, settings, chats and files.",children:[e.jsxs("button",{type:"button",className:"btn btn-danger gap-1.5",onClick:()=>r(!0),children:[e.jsx(js,{width:14,height:14}),"Delete project…"]}),n&&e.jsx(pi,{project:t,open:!0,onClose:()=>r(!1),onDeleted:s})]})}function fc({project:t}){return e.jsx(mt,{title:"Derived",description:"Read-only state Claude and sweeps maintain.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3 sm:grid-cols-2",children:[e.jsx(Rt,{label:"Overview",value:t.hasOverview?e.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[e.jsx(It,{width:12,height:12})," OVERVIEW.md written by a sweep"]}):e.jsx("span",{className:"text-fg-subtle",children:"No OVERVIEW.md yet"})}),e.jsx(Rt,{label:"Pinned files",value:t.pinned.length>0?e.jsx("span",{className:"flex flex-wrap gap-1.5",children:t.pinned.map(s=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-surface-active px-1.5 py-0.5 font-mono text-xs text-fg-muted",children:[e.jsx(ps,{width:11,height:11,className:"text-accent"}),s]},s))}):e.jsx("span",{className:"text-fg-subtle",children:"None — pin files from the Files tab"})})]})})}function xc({project:t,onSaved:s}){const[n,r]=a.useState(""),[i,o]=a.useState(!1),[l,c]=a.useState(!1),[m,u]=a.useState(null);if(a.useEffect(()=>{r(""),o(!1),u(null)},[t.slug,t.managed]),!t.managed||t.path)return e.jsx(mt,{title:"Backing",description:t.managed?"Claude works in the directory below, and Paddock curates this project's notes there.":"Claude works in the directory below. Paddock does not write project files into it — its notes stay in the project's own folder.",children:e.jsxs("dl",{className:"grid grid-cols-1 gap-y-3",children:[t.repo&&e.jsx(Rt,{label:t.path?"Repository (recorded)":"Repository",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.repo})}),e.jsx(Rt,{label:"Working directory",value:e.jsx("span",{className:"break-all font-mono text-sm",children:t.workingDir})})]})});const b=n.trim(),f=b.length>0&&!pc(b),h=async()=>{if(!(!b||f)){c(!0),u(null);try{const j=await B.promoteProject(t.slug,b);s(j),o(!1),r("")}catch(j){u(j instanceof je?j.message:"Failed to promote project")}finally{c(!1)}}};return e.jsxs(mt,{title:"Repository backing",description:"Notebook project. Promote it to repo-backed to work directly in an external git repo — keeping all of this project's chats and notes.",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Git repository URL"}),e.jsx("input",{className:"input font-mono text-sm",value:n,onChange:j=>{r(j.target.value),o(!1)},placeholder:"https://github.com/owner/repo.git","aria-invalid":f,"aria-label":"Git repository URL"}),f?e.jsx(xe,{children:e.jsx("span",{className:"text-danger",children:"That doesn’t look like a git URL (https://, git@…, ssh://, git://)."})}):e.jsxs(xe,{children:["Paddock clones this repo into a nested checkout and points Claude at it. The repo’s own ",e.jsx("code",{children:"CLAUDE.md"})," and git tooling take over."]})]}),m&&e.jsx("p",{className:"mt-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:m}),i?e.jsxs("div",{className:"mt-4 rounded-lg border border-warn-edge bg-warn-soft p-3",children:[e.jsxs("p",{className:"flex items-start gap-1.5 text-sm leading-snug text-warn",children:[e.jsx(pe,{width:14,height:14,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:["Promote ",e.jsx("span",{className:"font-semibold",children:t.name})," to repo-backed? This clones ",e.jsx("span",{className:"break-all font-mono",children:b}),", moves Claude into that checkout, and stops curating this project’s ",e.jsx("code",{children:"CLAUDE.md"})," (the repo’s own takes over). Your ",e.jsx("span",{className:"font-medium",children:"chats and notes are kept"}),". This is ",e.jsx("span",{className:"font-medium",children:"one-way"}),"."]})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"btn-primary",disabled:l,onClick:h,children:l?"Promoting…":"Yes, promote"}),e.jsx("button",{type:"button",className:"btn-subtle",disabled:l,onClick:()=>o(!1),children:"Cancel"})]})]}):e.jsx("button",{type:"button",className:"btn-primary mt-4",disabled:l||!b||f,onClick:()=>o(!0),children:"Promote to repo-backed…"})]})}function pc(t){const s=t.trim();return s.length>0&&s.length<=512&&/^(?:https?:\/\/|git:\/\/|ssh:\/\/|file:\/\/|\/|git@[^\s]+:).+/i.test(s)}const gc=["idea","active","paused","blocked","done","abandoned"];function Hs(t,s,n){const r={};return t!==""&&(r.overviewMaxTokens=Number(t)),s!==""&&(r.changelogMaxTokens=Number(s)),n!==""&&(r.claudeMaxTokens=Number(n)),Object.keys(r).length>0?r:null}const Zn=[{value:"default",label:"Default (ask each time)"},{value:"acceptEdits",label:"Accept edits"},{value:"plan",label:"Plan only"},{value:"bypassPermissions",label:"Bypass all (use with care)"}],Kt="loading…";function bc({project:t,onSaved:s,onDeleted:n}){var He,We,ke;const[r,i]=a.useState(t.name),[o,l]=a.useState(t.summary),[c,m]=a.useState(t.domain.join(", ")),[u,b]=a.useState(t.group??""),[f,h]=a.useState(t.status),[j,x]=a.useState(t.visibility),[k,d]=a.useState(t.links??[]),[p,D]=a.useState(t.model),[$,I]=a.useState(t.models??[]),[C,S]=a.useState(t.permissionMode),[M,y]=a.useState(String(t.maxTurns)),[T,w]=a.useState(t.docker),[F,O]=a.useState(t.driveMode??""),[z,X]=a.useState(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),[L,v]=a.useState(((He=t.curation)==null?void 0:He.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),[A,W]=a.useState(((We=t.curation)==null?void 0:We.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),[Q,ie]=a.useState(((ke=t.curation)==null?void 0:ke.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),[K,q]=a.useState([]),[N,U]=a.useState(null),[Z,E]=a.useState(null),[H,de]=a.useState(null),[we,le]=a.useState(!1),[he,Ne]=a.useState(null),[Ue,Ae]=a.useState(0);a.useEffect(()=>{var P,ee,ae;i(t.name),l(t.summary),m(t.domain.join(", ")),b(t.group??""),h(t.status),x(t.visibility),d(t.links??[]),D(t.model),I(t.models??[]),S(t.permissionMode),y(String(t.maxTurns)),w(t.docker),O(t.driveMode??""),X(t.maxSpawnDepth!=null?String(t.maxSpawnDepth):""),v(((P=t.curation)==null?void 0:P.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):""),W(((ee=t.curation)==null?void 0:ee.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):""),ie(((ae=t.curation)==null?void 0:ae.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):""),Ne(null)},[t]),a.useEffect(()=>{let P=!1;return B.getModels().then(ee=>{P||(q(ee.models),U(ee.driveModeDefault),E(ee.maxSpawnDepthDefault),de(ee.curationDefault))}).catch(()=>{}),()=>{P=!0}},[]);const re=a.useMemo(()=>k.map(P=>({label:P.label.trim(),url:P.url.trim()})).filter(P=>P.url.length>0),[k]),Be=a.useMemo(()=>c.split(",").map(P=>P.trim()).filter(Boolean),[c]),ve=a.useMemo(()=>({name:r.trim(),status:f,group:u,summary:o.trim(),domain:Be,visibility:j,links:re,model:p,models:$.length>0?$:null,permissionMode:C,maxTurns:Number(M),docker:T,driveMode:F===""?null:F,maxSpawnDepth:z===""?null:Number(z),curation:Hs(L,A,Q)}),[r,f,u,o,Be,j,re,p,$,C,M,T,F,z,L,A,Q]),Te=a.useMemo(()=>{var ee,ae,ue;const P={name:t.name.trim(),status:t.status,group:t.group??"",summary:t.summary.trim(),domain:t.domain,visibility:t.visibility,links:(t.links??[]).map(ye=>({label:ye.label,url:ye.url})),model:t.model,models:t.models&&t.models.length>0?t.models:null,permissionMode:t.permissionMode,maxTurns:t.maxTurns,docker:t.docker,driveMode:t.driveMode??null,maxSpawnDepth:t.maxSpawnDepth??null,curation:Hs(((ee=t.curation)==null?void 0:ee.overviewMaxTokens)!=null?String(t.curation.overviewMaxTokens):"",((ae=t.curation)==null?void 0:ae.changelogMaxTokens)!=null?String(t.curation.changelogMaxTokens):"",((ue=t.curation)==null?void 0:ue.claudeMaxTokens)!=null?String(t.curation.claudeMaxTokens):"")};return JSON.stringify(ve)!==JSON.stringify(P)},[ve,t]),se=ve.name.length===0,Ve=Number(M),De=!Number.isInteger(Ve)||Ve<1||Ve>1e3,$e=Number(z),J=z!==""&&(!Number.isInteger($e)||$e<0||$e>8),me=P=>P!==""&&(!Number.isInteger(Number(P))||Number(P)<1),Ie=me(L)||me(A)||me(Q),Dt=async P=>{if(P.preventDefault(),!(se||De||J||Ie)){le(!0),Ne(null);try{const ee=await B.updateProject(t.slug,ve);s(ee),Ae(ae=>ae+1)}catch(ee){Ne(ee instanceof je?ee.message:"Failed to save changes")}finally{le(!1)}}},Ze=N===null?Kt:N==="session"?"Session":"Batch",ze=$.length>0?K.filter(P=>$.includes(P.id)):K,et=(P,ee)=>I(ae=>ee?[...ae.filter(ue=>ue!==P),P]:ae.filter(ue=>ue!==P));return e.jsxs("form",{onSubmit:Dt,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-3 border-b border-edge bg-surface/80 px-4 py-2.5 backdrop-blur sm:px-6",children:[e.jsx("span",{className:"text-sm font-medium text-fg-muted",children:"Settings"}),Te&&!we&&e.jsx("span",{className:"text-xs text-warn",children:"Unsaved changes"}),Ue>0&&!Te&&!we&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-success",children:[e.jsx(It,{width:12,height:12}),"Saved"]}),e.jsx("button",{type:"submit",className:"btn-primary ml-auto",disabled:we||!Te||se||De||J||Ie,children:we?"Saving…":"Save changes"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:e.jsxs("div",{className:"mx-auto max-w-3xl px-6 py-6",children:[he&&e.jsx("p",{className:"mb-4 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:he}),e.jsxs(mt,{title:"Identity & metadata",description:"How this project is named, grouped, and described across the app.",children:[e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",value:r,onChange:P=>i(P.target.value),placeholder:"Display name","aria-invalid":se}),se&&e.jsx(xe,{children:"Name can’t be empty."})]}),e.jsxs("label",{className:"mb-4 block",children:[e.jsx("span",{className:"field-label",children:"Summary"}),e.jsx("input",{className:"input",value:o,onChange:P=>l(P.target.value),placeholder:"One line on what this project is about"})]}),e.jsxs("div",{className:"mb-4 grid grid-cols-2 gap-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Status"}),e.jsx("select",{className:"input capitalize",value:f,onChange:P=>h(P.target.value),children:gc.map(P=>e.jsx("option",{value:P,className:"capitalize",children:P},P))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Area"}),e.jsxs("select",{className:"input",value:u,onChange:P=>b(P.target.value),children:[e.jsx("option",{value:"",children:"Unsorted"}),Ys.map(P=>e.jsx("option",{value:P.slug,children:P.label},P.slug)),u&&!Ys.some(P=>P.slug===u)&&e.jsx("option",{value:u,children:u})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Visibility"}),e.jsxs("select",{className:"input capitalize",value:j,onChange:P=>x(P.target.value),children:[e.jsx("option",{value:"public",children:"Public"}),e.jsx("option",{value:"private",children:"Private"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Domain tags"}),e.jsx("input",{className:"input",value:c,onChange:P=>m(P.target.value),placeholder:"home, plumbing"})]})]}),e.jsxs("div",{className:"mb-1",children:[e.jsx("span",{className:"field-label",children:"Links"}),k.length===0&&e.jsx("p",{className:"mb-2 text-xs italic text-fg-subtle",children:"No links yet."}),e.jsx("div",{className:"space-y-2",children:k.map((P,ee)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"input w-1/3",value:P.label,onChange:ae=>d(ue=>ue.map((ye,Ke)=>Ke===ee?{...ye,label:ae.target.value}:ye)),placeholder:"Label","aria-label":`Link ${ee+1} label`}),e.jsx("input",{className:"input flex-1",value:P.url,onChange:ae=>d(ue=>ue.map((ye,Ke)=>Ke===ee?{...ye,url:ae.target.value}:ye)),placeholder:"https://…","aria-label":`Link ${ee+1} URL`}),e.jsx("button",{type:"button",onClick:()=>d(ae=>ae.filter((ue,ye)=>ye!==ee)),"aria-label":`Remove link ${ee+1}`,title:"Remove link",className:"motion-fast flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-fg-subtle transition-[color,background-color,border-color,box-shadow,transform] hover:bg-danger-soft hover:text-danger",children:e.jsx(js,{width:14,height:14})})]},ee))}),e.jsxs("button",{type:"button",onClick:()=>d(P=>[...P,{label:"",url:""}]),className:"btn-subtle mt-2 gap-1.5 px-2 py-1 text-xs",children:[e.jsx(rt,{width:13,height:13}),"Add link"]})]}),e.jsxs("dl",{className:"mt-4 grid grid-cols-2 gap-x-4 gap-y-3 border-t border-edge pt-4 sm:grid-cols-3",children:[e.jsx(Rt,{label:"Slug",value:Na(t.slug)?e.jsx("span",{className:"italic text-fg-subtle",title:"The root workspace has no slug",children:"(root)"}):e.jsx("span",{className:"font-mono",children:t.slug})}),e.jsx(Rt,{label:"Started",value:t.started})]})]}),e.jsx(mt,{title:"Claude",description:"How Claude runs in this workspace. Changes take effect on the next turn.",children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-4",children:[e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsxs("select",{className:"input",value:p,onChange:P=>D(P.target.value),children:[!ze.some(P=>P.id===p)&&e.jsx("option",{value:p,children:p}),ze.map(P=>e.jsx("option",{value:P.id,children:P.label},P.id))]})]}),e.jsx(xe,{children:"Larger context windows (Opus/Fable/Sonnet: 1M; Haiku: 200K) fit longer chats."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsxs("select",{className:"input",value:C,onChange:P=>S(P.target.value),children:[!Zn.some(P=>P.value===C)&&e.jsx("option",{value:C,children:C}),Zn.map(P=>e.jsx("option",{value:P.value,children:P.label},P.value))]})]}),C==="bypassPermissions"?e.jsx(Xn,{children:"Claude runs every tool without asking — it can edit files and run commands unprompted."}):e.jsx(xe,{children:"How much Claude asks before acting."})]}),e.jsxs("div",{className:"block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,max:1e3,step:1,className:"input",value:M,onChange:P=>y(P.target.value),"aria-invalid":De})]}),De?e.jsx(xe,{children:e.jsx("span",{className:"text-danger",children:"Must be a whole number 1–1000."})}):e.jsx(xe,{children:"Upper bound on agent turns in a single run."})]}),e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Docker sandbox"}),e.jsxs("label",{className:"mt-1 flex cursor-pointer items-center gap-2",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:T,onChange:P=>w(P.target.checked)}),e.jsx("span",{className:"text-sm text-fg-muted",children:"Run Claude in a Docker sandbox"})]}),T?e.jsx(Xn,{children:"Requires a working Docker daemon on the box, or Claude won’t start."}):e.jsx(xe,{children:"Isolate Claude's tool calls in a container."})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Offered models"}),K.length===0?e.jsx("p",{className:"mt-1 text-xs italic text-fg-subtle",children:"Loading the instance model list…"}):e.jsx("div",{className:"mt-1 flex flex-wrap gap-x-4 gap-y-1.5",children:K.map(P=>{const ee=$.length===0||$.includes(P.id);return e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 text-sm text-fg-muted",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:ee,onChange:ae=>{$.length===0?I(ae.target.checked?[]:K.filter(ue=>ue.id!==P.id).map(ue=>ue.id)):et(P.id,ae.target.checked)},"aria-label":P.label}),e.jsx("span",{children:P.label})]},P.id)})}),$.length===0?e.jsx(xe,{children:"Offering all instance models. Uncheck any to restrict this project's picker to a subset; the model default above is then constrained to it."}):e.jsxs(xe,{children:["Restricting this project's picker to ",$.length," of ",K.length," ","instance models."," ",e.jsx("button",{type:"button",onClick:()=>I([]),className:"font-medium text-accent hover:underline",children:"Offer all instance models"}),"."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Drive mode"}),e.jsxs("select",{className:"input",value:F,onChange:P=>O(P.target.value),children:[e.jsxs("option",{value:"",children:["Global default (",Ze,")"]}),e.jsx("option",{value:"batch",children:"Batch (one-shot per turn)"}),e.jsx("option",{value:"session",children:"Session (cross-turn autonomy)"})]})]}),F===""&&N===null?e.jsx(xe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the box-wide drive-mode default…"})}):F===""?e.jsxs(xe,{children:["Inheriting the box-wide default:"," ",e.jsx("span",{className:"font-medium text-fg",children:Ze}),". ",e.jsx("span",{className:"font-medium",children:"Session"})," enables cross-turn autonomy (ScheduleWakeup / ",e.jsx("code",{children:"/loop"}),"); ",e.jsx("span",{className:"font-medium",children:"Batch"})," ","is the legacy one-shot path."]}):e.jsxs(xe,{children:["Overriding the global default."," ",e.jsx("button",{type:"button",onClick:()=>O(""),className:"font-medium text-accent hover:underline",children:"Reset to global default"}),"."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsxs("select",{className:"input",value:z,onChange:P=>X(P.target.value),children:[e.jsxs("option",{value:"",children:["Instance default (",Z??Kt,")"]}),e.jsx("option",{value:"0",children:"0 — no spawned children get tools"}),e.jsx("option",{value:"1",children:"1 — children can report back (grandchildren can't)"}),e.jsx("option",{value:"2",children:"2"}),e.jsx("option",{value:"3",children:"3"}),e.jsx("option",{value:"4",children:"4"})]})]}),z===""&&Z===null?e.jsx(xe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance max-spawn-depth default…"})}):z===""?e.jsxs(xe,{children:["Inheriting the instance default:"," ",e.jsx("span",{className:"font-medium text-fg",children:Z}),". A chat spawned via ",e.jsx("code",{children:"create_chat"}),"/",e.jsx("code",{children:"fork_chat"})," gets the self-management tools (so it can ",e.jsx("code",{children:"send_message"})," back to its parent and spawn its own) only while its depth stays within this bound."," ",e.jsx("span",{className:"font-medium",children:"0"})," disables spawned tooling entirely."]}):e.jsxs(xe,{children:["Overriding the instance default."," ",e.jsx("button",{type:"button",onClick:()=>X(""),className:"font-medium text-accent hover:underline",children:"Reset to instance default"}),"."]})]})]})}),e.jsxs(mt,{title:"Curation budgets",description:"Per-file token limits the post-turn sweeper keeps this project's OVERVIEW.md, CHANGELOG.md and CLAUDE.md under. Leave a field blank to inherit the instance default.",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"OVERVIEW.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.overviewMaxTokens)??Kt})`,value:L,onChange:P=>v(P.target.value),"aria-label":"OVERVIEW.md token budget"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"CHANGELOG.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.changelogMaxTokens)??Kt})`,value:A,onChange:P=>W(P.target.value),"aria-label":"CHANGELOG.md token budget"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"CLAUDE.md (tokens)"}),e.jsx("input",{type:"number",min:1,className:"input",placeholder:`Instance default (${(H==null?void 0:H.claudeMaxTokens)??Kt})`,value:Q,onChange:P=>ie(P.target.value),"aria-label":"CLAUDE.md token budget"})]})]}),Ie?e.jsx(xe,{children:"Each budget must be a whole number of tokens (1 or more), or blank to inherit."}):Hs(L,A,Q)?e.jsxs(xe,{children:["Overriding the instance defaults",H&&e.jsxs(e.Fragment,{children:[" ","(",H.overviewMaxTokens,"/",H.changelogMaxTokens,"/",H.claudeMaxTokens,")"]})," ","for the fields set above."," ",e.jsx("button",{type:"button",onClick:()=>{v(""),W(""),ie("")},className:"font-medium text-accent hover:underline",children:"Reset all to instance defaults"}),". Repo-backed projects never have their CLAUDE.md curated, so that budget is moot for them."]}):H===null?e.jsx(xe,{children:e.jsx("span",{className:"italic text-fg-subtle",children:"Loading the instance curation budgets…"})}):e.jsxs(xe,{children:["Inheriting the instance defaults:"," ",e.jsxs("span",{className:"tabular font-medium text-fg",children:[H.overviewMaxTokens,"/",H.changelogMaxTokens,"/",H.claudeMaxTokens]})," ","tokens (OVERVIEW/CHANGELOG/CLAUDE). Lower a budget to shrink the context this project injects into every chat."]})]}),e.jsx(xc,{project:t,onSaved:s}),e.jsx(fc,{project:t}),e.jsx(mc,{project:t,onDeleted:n})]})})]})}const jc=/^[A-Za-z0-9._-]+$/,wc={onArchive:"On archive — a chat is archived",afterTurn:"After turn — a user turn completes"},vc={schedule:"Schedule — a cron / interval fires it",event:"Event — a lifecycle event fires it",webhook:"Webhook — an inbound HTTP call fires it"},yc=[{value:"",label:"Default (fleet default)"},{value:"acceptEdits",label:"Accept edits"},{value:"plan",label:"Plan only"},{value:"default",label:"Ask each time"},{value:"bypassPermissions",label:"Bypass all (use with care)"}],Nc={read:"Read",write:"Write & execute",web:"Web",orchestration:"Orchestration",browser:"Browser"},kc=["read","write","web","orchestration","browser"];function Cc(t,s){return{name:"",type:t,scheduleKind:"interval",expr:"",event:s,path:"",promptMode:"inline",prompt:"",promptFile:"",resumeSession:!1,allowedTools:new Set,permissionMode:"",model:"",maxTurns:"",maxSpawnDepth:"",enabled:!1}}function Sc(t){const s=t.trigger,n=t.run;return{name:t.name,type:s.type,scheduleKind:s.type==="schedule"&&s.interval!==void 0?"interval":"cron",expr:s.type==="schedule"?s.cron!==void 0?s.cron:s.interval??"":"",event:s.type==="event"?s.on:"onArchive",path:s.type==="webhook"?s.path:"",promptMode:n.promptFile?"file":"inline",prompt:n.prompt??"",promptFile:n.promptFile??"",resumeSession:n.session==="resume",allowedTools:new Set(n.tools??[]),permissionMode:n.permissionMode??"",model:n.model??"",maxTurns:n.maxTurns!=null?String(n.maxTurns):"",maxSpawnDepth:n.maxSpawnDepth!=null?String(n.maxSpawnDepth):"",enabled:t.enabled===!0}}function Tc(t){let s;t.type==="event"?s={type:"event",on:t.event}:t.type==="webhook"?s={type:"webhook",path:t.path.trim()}:s=t.scheduleKind==="cron"?{type:"schedule",cron:t.expr.trim()}:{type:"schedule",interval:t.expr.trim()};const n={session:t.resumeSession?"resume":"new",tools:[...t.allowedTools]};t.promptMode==="file"?n.promptFile=t.promptFile.trim():n.prompt=t.prompt,t.permissionMode&&(n.permissionMode=t.permissionMode),t.model.trim()&&(n.model=t.model.trim());const r=Number(t.maxTurns);t.maxTurns.trim()&&Number.isFinite(r)&&r>0&&(n.maxTurns=Math.floor(r));const i=Number(t.maxSpawnDepth);return t.maxSpawnDepth.trim()&&Number.isFinite(i)&&i>=0&&(n.maxSpawnDepth=Math.floor(i)),{trigger:s,run:n,enabled:t.enabled}}function $c(t){const s=t.run.tools??[];return s.length===0?t.trigger.type==="schedule"?"Claude's tools":"No tools":`${s.length} tool${s.length===1?"":"s"}`}function ea(t){return t.trigger.type==="event"&&t.trigger.on==="afterTurn"}function Ic(t){return t.type==="event"?t.on:t.type==="webhook"?t.path:t.cron??t.interval??""}function Ec({project:t}){const s=t.slug,[n,r]=a.useState([]),[i,o]=a.useState([]),[l,c]=a.useState(["onArchive","afterTurn"]),[m,u]=a.useState(["schedule","event","webhook"]),[b,f]=a.useState(!0),[h,j]=a.useState(null),[x,k]=a.useState(null),[d,p]=a.useState(null),[D,$]=a.useState(null),[I,C]=a.useState(null),[S,M]=a.useState({}),y=a.useCallback(async()=>{f(!0);try{const N=await B.listTriggers(s);r(N.triggers),o(N.grantableTools),N.events.length>0&&c(N.events),N.triggerTypes.length>0&&u(N.triggerTypes),j(null)}catch(N){j(N instanceof je?N.message:"Failed to load triggers")}finally{f(!1)}},[s]),T=a.useCallback(async()=>{try{const N=await B.triggerRuntime(s);M(Object.fromEntries(N.runtime.map(U=>[U.name,U])))}catch{}},[s]);a.useEffect(()=>{y()},[y]),a.useEffect(()=>{T();const N=setInterval(()=>{document.visibilityState==="visible"&&T()},1e4);return()=>clearInterval(N)},[T]),a.useEffect(()=>{if(!x)return;const N=setTimeout(()=>k(null),4e3);return()=>clearTimeout(N)},[x]);const w=d==null?void 0:d.draft,F=a.useMemo(()=>d!=null&&d.isNew?n.some(N=>N.name===(w==null?void 0:w.name.trim())):!1,[d,w,n]),O=!!w&&(!jc.test(w.name.trim())||w.name.trim().length>64),z=!!w&&(w.type==="schedule"?w.expr.trim().length===0:w.type==="webhook"?w.path.trim().length===0:!1),X=!!w&&(w.promptMode==="file"?w.promptFile.trim().length===0||!w.promptFile.trim().toLowerCase().endsWith(".md"):w.prompt.trim().length===0),L=!!w&&w.type==="webhook",v=O||F||z||X||L,A=N=>p(U=>U&&{...U,draft:{...U.draft,...N}}),W=N=>p(U=>{if(!U)return U;const Z=new Set(U.draft.allowedTools);return Z.has(N)?Z.delete(N):Z.add(N),{...U,draft:{...U.draft,allowedTools:Z}}}),Q=async()=>{if(!d||v)return;const N=d.draft.name.trim();$(N);try{await B.putTrigger(s,N,Tc(d.draft)),p(null),k(`Saved “${N}”.`),await y()}catch(U){j(U instanceof je?U.message:"Failed to save trigger")}finally{$(null)}},ie=async N=>{$(N.name);try{const U=await B.putTrigger(s,N.name,{trigger:N.trigger,run:N.run,enabled:!N.enabled});r(Z=>Z.map(E=>E.name===N.name?U:E))}catch(U){j(U instanceof je?U.message:"Failed to update trigger")}finally{$(null)}},K=async()=>{const N=I;if(N){$(N.name);try{await B.deleteTrigger(s,N.name),r(U=>U.filter(Z=>Z.name!==N.name)),k(`Deleted “${N.name}”.`),C(null)}catch(U){throw new Error(U instanceof je?U.message:"Failed to delete trigger")}finally{$(null)}}},q=async N=>{$(N.name);try{await B.runTrigger(s,N.name),k(`Ran “${N.name}” — a new chat is starting.`),await T()}catch(U){j(U instanceof je?U.message:"Failed to run trigger")}finally{$(null)}};return e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain","data-testid":"triggers-pane",children:[e.jsx("div",{className:"mx-auto max-w-3xl px-6 py-6",children:e.jsxs("section",{className:"mb-6",children:[e.jsxs("h3",{className:"flex items-center gap-1.5 text-sm font-semibold uppercase tracking-wide text-fg-muted",children:[e.jsx(Mt,{width:14,height:14}),"Triggers"]}),e.jsxs("p",{className:"mb-3 mt-0.5 text-sm text-fg-muted",children:["A trigger runs an agent turn when something happens — a"," ",e.jsx("span",{className:"font-medium",children:"schedule"})," (a cron/interval fires), an"," ",e.jsx("span",{className:"font-medium",children:"event"})," (a lifecycle event like a chat being archived), or a ",e.jsx("span",{className:"font-medium",children:"webhook"})," (reserved). Each trigger's granted tools ",e.jsx("em",{children:"are"})," its capability. New triggers are created disabled; enable one when you’re ready for it to fire."]}),e.jsxs("div",{className:"card",children:[h&&e.jsx("p",{className:"mb-3 rounded-lg bg-danger-soft px-3 py-2 text-sm text-danger",children:h}),x&&e.jsx("p",{className:"mb-3 rounded-lg bg-success-soft px-3 py-2 text-sm text-success",children:x}),b?e.jsx("p",{className:"py-4 text-center text-sm text-fg-subtle",children:"Loading triggers…"}):n.length===0?e.jsx("p",{className:"py-4 text-center text-sm italic text-fg-subtle",children:"No triggers yet."}):e.jsx("div",{className:"-mx-1 overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[54rem] border-collapse text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-edge text-left text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:[e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Trigger"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Type"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"When"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Capability"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Last run"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Next run"}),e.jsx("th",{className:"px-2 py-2 font-semibold",children:"Status"}),e.jsx("th",{className:"px-2 py-2 text-right font-semibold",children:"Actions"})]})}),e.jsx("tbody",{children:n.map(N=>{var Z;const U=S[N.name];return e.jsxs("tr",{"data-trigger":N.name,className:"border-b border-edge-subtle last:border-0",children:[e.jsxs("td",{className:"px-2 py-2.5 align-top",children:[e.jsx("span",{className:"font-medium text-fg",children:N.name}),N.run.promptFile?e.jsx("span",{className:"mt-0.5 block font-mono text-2xs text-fg-subtle",title:"Prompt read from this file at fire time",children:N.run.promptFile}):N.run.prompt&&e.jsx("span",{className:"mt-0.5 block max-w-[16rem] truncate text-2xs text-fg-subtle",children:N.run.prompt})]}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Rc,{type:N.trigger.type})}),e.jsx("td",{className:"px-2 py-2.5 align-top font-mono text-xs text-fg-muted",children:Ic(N.trigger)}),e.jsxs("td",{className:"px-2 py-2.5 align-top text-xs text-fg-muted",children:[e.jsx("span",{title:((Z=N.run.tools)==null?void 0:Z.join(", "))||"No tools declared — an empty list is not enforced as a deny-all",children:$c(N)}),N.run.permissionMode&&e.jsx("span",{className:"mt-0.5 block text-2xs text-fg-subtle",children:N.run.permissionMode})]}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-lastrun":N.name,children:e.jsx(Dc,{rt:U})}),e.jsx("td",{className:"px-2 py-2.5 align-top","data-trigger-nextrun":N.name,children:e.jsx(Pc,{rt:U,trigger:N})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsx(Mc,{enabled:N.enabled===!0,running:(U==null?void 0:U.running)===!0})}),e.jsx("td",{className:"px-2 py-2.5 align-top",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>q(N),disabled:D===N.name||ea(N),title:ea(N)?"The post-turn curator runs automatically after each turn — it can’t be run on demand.":"Run now","aria-label":`Run ${N.name} now`,"data-testid":`run-trigger-${N.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-accent transition hover:bg-accent-soft disabled:opacity-40",children:e.jsx(Ar,{width:13,height:13})}),e.jsx("button",{type:"button",onClick:()=>ie(N),disabled:D===N.name,className:"rounded-md px-1.5 py-1 text-xs font-medium text-fg-muted transition hover:bg-surface-hover disabled:opacity-40",title:N.enabled?"Disable":"Enable",children:N.enabled?"Disable":"Enable"}),e.jsx("button",{type:"button",onClick:()=>p({isNew:!1,draft:Sc(N)}),disabled:D===N.name,title:"Edit","aria-label":`Edit ${N.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-muted transition hover:bg-surface-hover disabled:opacity-40",children:e.jsx(bs,{width:14,height:14})}),e.jsx("button",{type:"button",onClick:()=>C(N),disabled:D===N.name,title:"Delete","aria-label":`Delete ${N.name}`,className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-subtle transition hover:bg-danger-soft hover:text-danger disabled:opacity-40",children:e.jsx(js,{width:14,height:14})})]})})]},N.name)})})]})}),!d&&e.jsxs("button",{type:"button",onClick:()=>p({isNew:!0,draft:Cc(m[0]??"schedule",l[0]??"onArchive")}),className:"btn-subtle mt-3 gap-1.5 px-2 py-1 text-xs","data-testid":"add-trigger",children:[e.jsx(rt,{width:13,height:13}),"Add trigger"]}),d&&w&&e.jsxs("div",{className:"mt-4 rounded-xl border border-edge bg-surface-sunken p-4","data-testid":"trigger-editor",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-semibold text-fg",children:d.isNew?"New trigger":`Edit “${w.name}”`}),e.jsx("button",{type:"button",onClick:()=>p(null),"aria-label":"Cancel",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-subtle hover:bg-surface-hover",children:e.jsx(Oe,{width:14,height:14})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Name"}),e.jsx("input",{className:"input",value:w.name,onChange:N=>A({name:N.target.value}),placeholder:"daily-manager",disabled:!d.isNew,"aria-invalid":O||F,"data-testid":"trigger-name"}),d.isNew&&F?e.jsx("p",{className:"mt-1 text-xs text-danger",children:"A trigger with that name exists."}):d.isNew&&w.name.trim()&&O?e.jsxs("p",{className:"mt-1 text-xs text-danger",children:["Letters, numbers, ",e.jsx("code",{children:". _ -"})," only (max 64)."]}):!d.isNew&&e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"Rename by deleting and recreating."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Type"}),e.jsx("select",{className:"input",value:w.type,onChange:N=>A({type:N.target.value}),"data-testid":"trigger-type",children:m.map(N=>e.jsx("option",{value:N,children:vc[N]??N},N))})]}),w.type==="schedule"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Timer"}),e.jsxs("select",{className:"input",value:w.scheduleKind,onChange:N=>A({scheduleKind:N.target.value,expr:""}),"data-testid":"trigger-schedule-kind",children:[e.jsx("option",{value:"interval",children:"Interval (every N)"}),e.jsx("option",{value:"cron",children:"Cron"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:w.scheduleKind==="cron"?"Cron expression":"Interval"}),e.jsx("input",{className:"input font-mono",value:w.expr,onChange:N=>A({expr:N.target.value}),placeholder:w.scheduleKind==="cron"?"0 9 * * *":"30m","aria-invalid":z,"data-testid":"trigger-expr"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:w.scheduleKind==="cron"?"5-field cron (or @daily / @hourly), host-local time.":"A duration like 30m, 1h, or 6h."})]})]}),w.type==="event"&&e.jsxs("label",{className:"col-span-1 block",children:[e.jsx("span",{className:"field-label",children:"Event"}),e.jsx("select",{className:"input",value:w.event,onChange:N=>A({event:N.target.value}),"data-testid":"trigger-event",children:l.map(N=>e.jsx("option",{value:N,children:wc[N]??N},N))})]}),w.type==="webhook"&&e.jsxs("label",{className:"col-span-1 block",children:[e.jsx("span",{className:"field-label",children:"Path"}),e.jsx("input",{className:"input font-mono",value:w.path,onChange:N=>A({path:N.target.value}),placeholder:"/gh/issues","data-testid":"trigger-path"})]}),L&&e.jsxs("p",{className:"col-span-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(pe,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsxs("span",{"data-testid":"trigger-webhook-reserved",children:["Webhook triggers are ",e.jsx("strong",{children:"reserved"})," — the inbound HTTP ingress isn’t built yet, so a webhook trigger can’t be created here. The shape is shown for reference."]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Prompt"}),e.jsxs("div",{className:"mb-2 flex gap-3 text-sm",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-[var(--accent-solid)]",checked:w.promptMode==="inline",onChange:()=>A({promptMode:"inline"})}),"Inline text"]}),e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5",children:[e.jsx("input",{type:"radio",className:"accent-[var(--accent-solid)]",checked:w.promptMode==="file",onChange:()=>A({promptMode:"file"})}),"Prompt file"]})]}),w.promptMode==="inline"?e.jsx("textarea",{className:"input min-h-[5rem] resize-y",value:w.prompt,onChange:N=>A({prompt:N.target.value}),placeholder:"What should this trigger do when it fires?","aria-invalid":X,"data-testid":"trigger-prompt"}):e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"input font-mono",value:w.promptFile,onChange:N=>A({promptFile:N.target.value}),placeholder:"daily-manager.md","aria-invalid":X,"data-testid":"trigger-prompt-file"}),e.jsxs("p",{className:"mt-1 text-xs text-fg-subtle",children:["A ",e.jsx("code",{children:".md"})," file under ",e.jsx("code",{children:".paddock/triggers/"}),", read fresh each fire (git-tracked, Claude-editable)."]})]})]}),e.jsxs("div",{className:"col-span-2 block",children:[e.jsx("span",{className:"field-label",children:"Tools"}),e.jsxs("p",{className:"mb-2 text-xs text-fg-subtle",children:["The trigger agent can use exactly the tools you check here — nothing else.",w.type==="schedule"?" Leave all unchecked and the schedule runs as Claude with its full toolset.":" Leaving all unchecked declares no tools, but is not a deny-all: an empty list is not passed to the runtime, so the agent falls back to Claude's default tools."]}),e.jsx("div",{className:"space-y-3","data-testid":"trigger-tools",children:kc.filter(N=>i.some(U=>U.group===N)).map(N=>e.jsxs("fieldset",{children:[e.jsx("legend",{className:"mb-1 text-2xs font-semibold uppercase tracking-wide text-fg-subtle",children:Nc[N]}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-2",children:i.filter(U=>U.group===N).map(U=>e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 rounded-md px-1.5 py-1 text-sm hover:bg-surface-hover",title:U.description,children:[e.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent-solid)]",checked:w.allowedTools.has(U.name),onChange:()=>W(U.name),"data-tool":U.name}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono text-xs font-medium text-fg",children:U.name}),e.jsx("span",{className:"block text-2xs leading-snug text-fg-subtle",children:U.description})]})]},U.name))})]},N))}),w.allowedTools.has("Bash")&&e.jsxs("p",{className:"mt-2 flex items-start gap-1.5 text-xs leading-snug text-warn",children:[e.jsx(pe,{width:13,height:13,className:"mt-0.5 shrink-0"}),e.jsxs("span",{children:[e.jsx("code",{children:"Bash"})," lets this trigger run arbitrary shell commands in the project working dir. Grant it only when the trigger genuinely needs it."]})]})]}),e.jsxs("div",{className:"col-span-2 flex flex-wrap items-center gap-x-6 gap-y-2",children:[e.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:w.resumeSession,onChange:N=>A({resumeSession:N.target.checked}),"data-testid":"trigger-session"}),e.jsx("span",{className:"text-fg",children:"Accrete into one session"})]}),e.jsx("span",{className:"text-xs text-fg-subtle",children:w.resumeSession?"One long-lived chat that accretes across fires.":"A fresh chat each fire."})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Permission mode"}),e.jsx("select",{className:"input",value:w.permissionMode,onChange:N=>A({permissionMode:N.target.value}),"data-testid":"trigger-permission-mode",children:yc.map(N=>e.jsx("option",{value:N.value,children:N.label},N.value))})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max turns"}),e.jsx("input",{type:"number",min:1,step:1,className:"input",value:w.maxTurns,onChange:N=>A({maxTurns:N.target.value}),placeholder:"30","data-testid":"trigger-max-turns"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Model"}),e.jsx("input",{className:"input",value:w.model,onChange:N=>A({model:N.target.value}),placeholder:"Workspace default","data-testid":"trigger-model"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"field-label",children:"Max spawn depth"}),e.jsx("input",{type:"number",min:0,step:1,className:"input",value:w.maxSpawnDepth,onChange:N=>A({maxSpawnDepth:N.target.value}),placeholder:"Inherit","data-testid":"trigger-max-spawn-depth"}),e.jsx("p",{className:"mt-1 text-xs text-fg-subtle",children:"0 = may not spawn children."})]}),e.jsxs("label",{className:"col-span-2 inline-flex cursor-pointer items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",className:"h-4 w-4 accent-[var(--accent-solid)]",checked:w.enabled,onChange:N=>A({enabled:N.target.checked}),"data-testid":"trigger-enabled"}),e.jsx("span",{className:"text-fg",children:"Enabled (fires on its trigger)"})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:Q,disabled:v||D===w.name.trim(),className:"btn-primary","data-testid":"trigger-save",children:D===w.name.trim()?"Saving…":d.isNew?"Create trigger":"Save"}),e.jsx("button",{type:"button",onClick:()=>p(null),className:"btn-ghost",children:"Cancel"})]})]})]})]})}),e.jsx(on,{open:I!==null,title:"Delete trigger?",confirmLabel:"Delete trigger",message:I&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-fg",children:I.name})," ","will be removed from this project. This can't be undone."]}),onConfirm:K,onClose:()=>C(null)})]})}function Rc({type:t}){const s={schedule:"bg-lineage-soft text-lineage",event:"bg-info-soft text-info",webhook:"bg-surface-active text-fg-muted"},n=t==="schedule"?Xe:Mt;return e.jsxs("span",{"data-trigger-type":t,className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-2xs font-medium capitalize ${s[t]}`,children:[e.jsx(n,{width:11,height:11}),t]})}function Mc({enabled:t,running:s}){return s?e.jsxs("span",{"data-trigger-status":"running",className:"inline-flex items-center gap-1 rounded-full bg-warn-soft px-2 py-0.5 text-2xs font-medium text-warn",children:[e.jsx("span",{className:"h-1.5 w-1.5 animate-pulse rounded-full bg-warn-solid"}),"Running"]}):e.jsx("span",{"data-trigger-status":t?"enabled":"disabled",className:`inline-flex items-center rounded-full px-2 py-0.5 text-2xs font-medium ${t?"bg-success-soft text-success":"bg-surface-active text-fg-muted"}`,children:t?"Enabled":"Disabled"})}function Ac(t){return t==="completed"?"bg-success-solid":t==="failed"||t==="cancelled"?"bg-danger-solid":t==="running"||t==="pending"?"bg-warn-solid":"bg-fg-subtle"}function Dc({rt:t}){const s=t==null?void 0:t.lastRun;if(!s)return e.jsx("span",{className:"text-xs text-fg-subtle",children:"—"});const n=s.startedAt,r=[n?new Date(n).toLocaleString():null,`status: ${s.status}${s.exitReason?` (${s.exitReason})`:""}`,s.summary??null].filter(Boolean).join(`
|