@deepseekcode/cli 1.0.37 → 1.0.38

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.
Files changed (40) hide show
  1. package/README.md +10 -1
  2. package/package.json +9 -9
  3. package/web/dist/assets/AssistantsView-Bh6ajWIo.js +1 -0
  4. package/web/dist/assets/AutomationView-D2Z-_4qe.js +1 -0
  5. package/web/dist/assets/{ChannelConfigView-JDljUn42.js → ChannelConfigView-DlakOI5z.js} +5 -5
  6. package/web/dist/assets/ConnectorsView-ELXDmM9m.js +1 -0
  7. package/web/dist/assets/FileTreeView-Ciq1vhTf.js +11 -0
  8. package/web/dist/assets/HookConfigView-DR8TP3QG.js +1 -0
  9. package/web/dist/assets/ModelsView-BW6eRUwf.js +1 -0
  10. package/web/dist/assets/PluginsView-CrHGk_JC.js +1 -0
  11. package/web/dist/assets/SessionGrid-DYYsm2dT.js +52 -0
  12. package/web/dist/assets/SettingsModal-DNxIKsKC.js +10 -0
  13. package/web/dist/assets/SkillsView-DS0nnKig.js +1 -0
  14. package/web/dist/assets/TemplatesTab-pXElHCnz.js +1 -0
  15. package/web/dist/assets/{ThreeScene-CMqkpyKO.js → ThreeScene-DFL_qzB1.js} +1 -1
  16. package/web/dist/assets/ToolsView-Bk4hckku.js +1 -0
  17. package/web/dist/assets/{icons-f1hlMKvD.js → icons-YJcunJnw.js} +195 -140
  18. package/web/dist/assets/index-CtPliI0f.css +1 -0
  19. package/web/dist/assets/index-D1N4vQ9I.js +591 -0
  20. package/web/dist/assets/{markdown-DEtuzEyz.js → markdown-CrVimah5.js} +1 -1
  21. package/web/dist/assets/{panels-Bn-2wCur.js → panels-BykQW6E1.js} +1 -1
  22. package/web/dist/assets/{react-vendor-ClBKp0t-.js → react-vendor-DM-M1fu_.js} +1 -1
  23. package/web/dist/assets/{state-xD58vmym.js → state-D8omNTWe.js} +1 -1
  24. package/web/dist/assets/sttLanguages-D4JbRJc6.js +1 -0
  25. package/web/dist/index.html +7 -7
  26. package/web/dist/assets/AssistantsView-OMdgsTIj.js +0 -1
  27. package/web/dist/assets/AutomationView-BPwjLbkL.js +0 -1
  28. package/web/dist/assets/ConnectorsView-AemNT1Ae.js +0 -1
  29. package/web/dist/assets/FileTreeView-DYx-0jFV.js +0 -11
  30. package/web/dist/assets/HookConfigView-CS1QqgPx.js +0 -1
  31. package/web/dist/assets/ModelsView-B3nHezvJ.js +0 -1
  32. package/web/dist/assets/PluginsView-C4Xc70ec.js +0 -1
  33. package/web/dist/assets/SessionGrid-C9-LeJH0.js +0 -47
  34. package/web/dist/assets/SettingsModal-CjWT1C66.js +0 -4
  35. package/web/dist/assets/SkillsView-DTZyXald.js +0 -1
  36. package/web/dist/assets/TemplatesTab-CE-CfCf2.js +0 -1
  37. package/web/dist/assets/ToolsView-CrEHDTEO.js +0 -1
  38. package/web/dist/assets/index-BCHbHIbw.css +0 -1
  39. package/web/dist/assets/index-u1vYyqna.js +0 -592
  40. package/web/dist/assets/sttLanguages-BNRptAQA.js +0 -1
@@ -1,47 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ThreeScene-CMqkpyKO.js","assets/markdown-DEtuzEyz.js","assets/icons-f1hlMKvD.js","assets/ThreeScene-DvOrMIoG.css"])))=>i.map(i=>d[i]);
2
- var Lr=Object.defineProperty;var Fr=(t,s,n)=>s in t?Lr(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Tt=(t,s,n)=>Fr(t,typeof s!="symbol"?s+"":s,n);import{j as e}from"./markdown-DEtuzEyz.js";import{a as o,at as Br,b0 as Hr,b1 as Kr,Q as qr,af as ft,F as ut,ag as Wr,b2 as Dn,E as zn,ay as ht,d as et,k as Ye,X as $e,b3 as vs,$ as Cs,A as Te,s as zt,L as Me,Z as Ts,Y as js,aV as Ur,a2 as Gr,q as $n,au as On,aJ as Jr,b4 as ys,b5 as Vr,h as mt,az as Xr,N as $t,b6 as Pn,ad as Oe,b7 as Qr,b as Yr,aE as Zr,b8 as ea,a5 as ta,am as Ln,b9 as sa,ah as na,ba as ra,bb as aa,al as sn,z as ia,aD as oa,bc as la,v as Fn,a$ as Is,a_ as ca,bd as Bn,be as Hn,aq as da,an as Kn,bf as ua,bg as ha,j as ma,bh as xa,f as fa,o as pa,p as nn,O as ga,bi as Qe,a4 as ba,aU as ka,u as va,bj as ja,J as ya,K as wa,t as Na,a9 as Sa,bk as Ea}from"./icons-f1hlMKvD.js";import{d as de,u as ee,r as ws,e as qn,g as pt,D as Ma,i as As,o as Bt,h as xt,j as Wn,w as pe,k as Ns,b as qe,R as Un,a as fe,t as he,l as Gn,m as Ca,n as Ta,p as Ia,q as Aa,s as Jn,v as Ot,x as xe,y as Ra,z as _a,_ as Da,A as Vn,E as za,F as Xn,G as rn,W as $a,H as Oa,J as Ss,c as _t,K as ct,L as Qn,N as Pa,O as La,Q as Fa,S as Ba,T as Ha,M as Yn,U as Ka,V as qa,X as Wa,Y as Ua,Z as Zn,$ as Ga,a0 as Ja,a1 as It,a2 as Va,a3 as er}from"./index-u1vYyqna.js";import{n as an,s as Xa,S as Qa}from"./sttLanguages-BNRptAQA.js";import"./react-vendor-ClBKp0t-.js";import"./state-xD58vmym.js";import"./panels-Bn-2wCur.js";function on({value:t,max:s=100,size:n="md",variant:r="default",showLabel:i=!1,className:a}){const l=Math.min(Math.max(t/s*100,0),100),c={sm:"h-1",md:"h-2",lg:"h-3"},d={default:"bg-accent-blue",success:"bg-accent-green",warning:"bg-accent-yellow",error:"bg-accent-red"};return e.jsxs("div",{className:de("w-full",a),children:[e.jsx("div",{className:de("w-full bg-dark-border rounded-full overflow-hidden",c[n]),children:e.jsx("div",{className:de("h-full rounded-full transition-all duration-300",d[r]),style:{width:`${l}%`}})}),i&&e.jsxs("span",{className:"text-xs text-dark-muted mt-1",children:[Math.round(l),"%"]})]})}function Ya(t){const s=o.useRef(null),n=o.useRef(0);return o.useEffect(()=>{if(!t){n.current=0;return}n.current=Date.now();const r=s.current;if(!r)return;const i=()=>{const l=Math.floor((Date.now()-n.current)/1e3),c=l>=60?`${Math.floor(l/60)}m ${l%60}s`:`${l}s`;r.textContent=c};i();const a=setInterval(i,1e3);return()=>clearInterval(a)},[t]),s}function Se(t,s){let n=null;if(typeof t=="string")try{const r=JSON.parse(t);r&&typeof r=="object"&&!Array.isArray(r)&&(n=r)}catch{return""}else t&&typeof t=="object"&&!Array.isArray(t)&&(n=t);if(!n)return"";for(const r of s){const i=n[r];if(typeof i=="string"&&i)return i}return""}function Ae(t){return typeof t=="string"?t:t&&typeof t=="object"?JSON.stringify(t,null,2):String(t??"")}function Za(t){for(const s of t.split(`
3
- `)){const n=s.trim();if(n)return n}return""}function Ie({label:t,tone:s="text-dark-muted",children:n}){return e.jsxs("div",{className:"px-2 py-1",children:[e.jsx("div",{className:`mb-0.5 text-[10px] ${s}`,children:t}),e.jsx("div",{className:"max-h-56 overflow-y-auto custom-scrollbar rounded border border-dark-border bg-dark-bg",children:n})]})}function ei({toolCall:t}){const{t:s}=ee(),n=Se(t.args,["command","cmd","script"]),r=t.status==="error",i=Ae(t.result);return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[n&&e.jsx(Ie,{label:s("step.params"),children:e.jsxs("pre",{className:"tv-pre",children:[e.jsx("span",{className:"select-none text-accent-green",children:"$ "}),n]})}),t.result!==void 0&&t.result!==null&&e.jsx(Ie,{label:s(r?"step.error":"step.result"),tone:r?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${r?"text-accent-red":""}`,children:i})})]})}function ti({toolCall:t}){const s=pt(t.args),n=Ae(t.result),r=t.diff||(n&&(n.includes("@@")||n.includes("+++")||n.includes("---"))?n:void 0);return!r&&!n?e.jsx(tr,{toolCall:t}):e.jsx("div",{className:"px-2 py-1",children:e.jsx(Ma,{filePath:s,content:r||n})})}function si({toolCall:t}){const{t:s}=ee(),n=pt(t.args),r=t.status==="error",i=Ae(t.result);return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[n&&e.jsx("div",{className:"flex items-center gap-1.5 px-2 pt-1 font-mono text-[10.5px] text-accent-blue",title:n,children:e.jsx("span",{className:"truncate",children:n})}),t.result!==void 0&&t.result!==null&&e.jsx(Ie,{label:s(r?"step.error":"step.result"),tone:r?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${r?"text-accent-red":""}`,children:i})})]})}const ln=20,ni=/\b(grep|search_contents)\b/i;function ri(t){return t===""?0:t.split(`
4
- `).length}function ai({toolCall:t}){const{t:s}=ee(),n=Se(t.args,["pattern","query","regex"]),r=t.status==="error",i=t.result!==void 0&&t.result!==null,a=i?Ae(t.result):"",l=i?ri(a):0,c=ni.test(t.name),d=t.noTruncate!==!0&&c&&i&&!r&&l>ln,[h,u]=o.useState(!1),x=d&&!h?a.split(`
5
- `).slice(0,ln).join(`
6
- `)+`
7
- ${s("toolCall.linesTotal",{n:l})}`:a;return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[n&&e.jsx("div",{className:"flex items-center gap-1.5 px-2 pt-1 text-[10.5px] text-dark-muted",children:e.jsx("span",{className:"font-mono text-accent-blue",children:n})}),i&&e.jsx(Ie,{label:s(r?"step.error":"step.result"),tone:r?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${r?"text-accent-red":""}`,children:x})}),d&&e.jsx("div",{className:"px-2 pb-1",children:e.jsx("button",{type:"button","data-testid":"grep-result-toggle",onClick:()=>u(g=>!g),className:"text-[10px] text-accent-blue hover:underline",children:h?s("toolCall.collapse"):s("toolCall.expandAll",{n:l})})})]})}function ii({toolCall:t}){const{t:s}=ee(),n=Se(t.args,["url","query"]),r=t.status==="error",i=Ae(t.result);return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[n&&e.jsx("div",{className:"truncate px-2 pt-1 font-mono text-[10.5px] text-accent-blue",title:n,children:n}),t.result!==void 0&&t.result!==null&&e.jsx(Ie,{label:s(r?"step.error":"step.result"),tone:r?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${r?"text-accent-red":""}`,children:i})})]})}function tr({toolCall:t}){const{t:s}=ee(),n=t.status==="error",r=t.result!==void 0&&t.result!==null;return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[e.jsx(Ie,{label:s("step.params"),children:e.jsx("pre",{className:"tv-pre",children:typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2)})}),r&&e.jsx(Ie,{label:s(n?"step.error":"step.result"),tone:n?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${n?"text-accent-red":""}`,children:Ae(t.result)})})]})}function oi({toolCall:t}){const{t:s}=ee(),n=t.status==="error",r=Ae(t.result),i=(t.attachments??[]).filter(a=>a.mime.startsWith("image/"));return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[i.length>0&&e.jsxs("div",{className:"px-2 pt-1",children:[e.jsx("div",{className:"mb-0.5 text-[10px] text-dark-muted",children:s("step.screenshot","Screenshot")}),e.jsx("div",{className:"max-h-72 overflow-y-auto custom-scrollbar rounded border border-dark-border bg-dark-bg",children:i.slice(0,4).map((a,l)=>e.jsx("img",{src:a.url,alt:a.filename??`computer screenshot ${l+1}`,className:"block w-full object-contain",loading:"lazy"},l))})]}),t.result!==void 0&&t.result!==null&&e.jsx(Ie,{label:s(n?"step.error":"step.result"),tone:n?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${n?"text-accent-red":""}`,children:r})})]})}function li({toolCall:t}){const{t:s}=ee(),n=t.status==="error",r=Ae(t.result),i=(t.generatedImages??[]).filter(c=>c.length>0),[a,l]=o.useState(null);return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 px-2 pt-1",children:i.map((c,d)=>e.jsx("button",{onClick:()=>l(ws(c)),title:s("fileJob.imagePreview"),className:"cursor-zoom-in overflow-hidden rounded-lg border border-dark-border transition-colors hover:border-accent-blue/40",children:e.jsx("img",{src:ws(c),alt:`generated image ${d+1}`,loading:"lazy",className:"h-28 w-auto max-w-[220px] object-cover"})},`${c}-${d}`))}),t.result!==void 0&&t.result!==null&&e.jsx(Ie,{label:s(n?"step.error":"step.result"),tone:n?"text-accent-red":"text-accent-green",children:e.jsx("pre",{className:`tv-pre ${n?"text-accent-red":""}`,children:r})}),a&&e.jsx(qn,{src:a,alt:s("fileJob.imagePreview"),onClose:()=>l(null)})]})}const ci=/(?:^|[_\W])(bash|powershell|pwsh|cmd|command|shell|exec|terminal)(?:[_\W]|$)/i,di=/(?:^|[_\W])(read|cat|view|open)(?:[_\W]|$)/i,ui=/(?:^|[_\W])(grep|glob|search|find|list)(?:[_\W]|$)/i,hi=/(?:^|[_\W])(webfetch|websearch|fetch|web|http|curl|url)(?:[_\W]|$)/i,mi=/(?:^|[_\W])(computer)(?:[_\W]|$)/i,xi=/generate[-_]?image|imagegen|create[-_]?image/i;function Rs(t){return xi.test(t)?"image":As(t)?"diff":ci.test(t)?"terminal":mi.test(t)?"computer":hi.test(t)?"web":ui.test(t)?"search":di.test(t)?"read":"generic"}function fi(t,s){const n=Rs(t);let r="";switch(n){case"terminal":r=Se(s,["command","cmd","script"]);break;case"computer":if(r=Se(s,["action"])||Se(s,["scope"]),r){const a=r,l=a==="type"||a==="key"?Se(s,["text"]):a==="focus"?Se(s,["keyword"]):a==="scroll"?Se(s,["direction"]):"";r=l?`${a} ${l}`:a}break;case"diff":case"read":r=pt(s)??"";break;case"search":r=Se(s,["pattern","query","regex","glob"]);break;case"web":r=Se(s,["url","query"]);break;case"image":r=Se(s,["prompt"]);break;default:try{const a=typeof s=="string"?JSON.parse(s):s;r=a&&typeof a=="object"?JSON.stringify(a):String(s??"")}catch{r=typeof s=="string"?s:""}}const i=r.replace(/\s+/g," ").trim();return i.length>64?`${i.slice(0,63)}…`:i}function pi({toolCall:t}){switch(Rs(t.name)){case"terminal":return e.jsx(ei,{toolCall:t});case"diff":return e.jsx(ti,{toolCall:t});case"read":return e.jsx(si,{toolCall:t});case"search":return e.jsx(ai,{toolCall:t});case"web":return e.jsx(ii,{toolCall:t});case"computer":return e.jsx(oi,{toolCall:t});case"image":return e.jsx(li,{toolCall:t});default:return e.jsx(tr,{toolCall:t})}}const gi={terminal:Dn,diff:Wr,read:ut,search:ft,web:qr,computer:Kr,image:Hr,generic:Br},bi=o.memo(function({toolCall:s,defaultCollapsed:n=!0}){const r=s.status==="running",i=Ya(r),a=s.result!==void 0&&s.result!==null,l=s.status==="error",c=As(s.name),d=a?Ae(s.result):"",h=pt(s.args),u=fi(s.name,s.args),x=l&&a?Za(d):"",[g,p]=o.useState(n),b=o.useRef(s.status);o.useEffect(()=>{b.current==="running"&&s.status!=="running"&&(s.diff||s.name==="exit_plan_mode"||p(!0)),b.current=s.status},[s.status,s.diff,s.name]);const j=s.duration??0,y=j>0?j>=60?`${Math.floor(j/60)}m ${j%60}s`:`${j}s`:"",f=r?"bg-accent-blue":l?"bg-accent-red":"bg-accent-green",k=r?"running":l?"error":"success",D=gi[Rs(s.name)];return e.jsxs("div",{className:"tl-row group rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"toolcall-row",children:[e.jsx("span",{className:"tl-line","aria-hidden":"true"}),e.jsxs("div",{className:"relative flex items-center gap-2 px-2 py-1 cursor-pointer select-none",onClick:()=>p(!g),"data-testid":"toolcall-row-header",children:[e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:r?e.jsx("span",{className:"inline-block h-3 w-3 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:`tl-node ${f}`,"data-status":k})}),e.jsx("span",{className:`shrink-0 ${l?"text-accent-red":"text-dark-muted"}`,children:e.jsx(D,{size:12,"aria-hidden":"true"})}),e.jsx("span",{className:`font-medium text-[13px] shrink-0 truncate ${r?"text-shimmer":"text-dark-text"}`,children:s.name}),l&&x?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"shrink-0 text-dark-muted/50",children:"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] text-accent-red",title:d,children:x})]}):u?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"shrink-0 text-dark-muted/50",children:"·"}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px] text-dark-muted",title:u,children:u})]}):e.jsx("span",{className:"min-w-0 flex-1"}),c&&h&&!l&&e.jsxs("button",{type:"button",onClick:S=>{S.stopPropagation(),Bt(h)},className:`flex max-w-[16rem] shrink-0 items-center gap-1 truncate rounded-full border border-dark-border/70 px-2 py-0.5 text-[11px] font-mono text-accent-blue
8
- transition-colors hover:border-accent-blue/40 hover:bg-dark-hover`,title:h,children:[e.jsx(zn,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:h})]}),r&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[11px] tabular-nums text-accent-blue",children:[e.jsx(ht,{size:10}),e.jsx("span",{ref:i,children:"0s"})]}),!r&&y&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[10px] tabular-nums text-dark-muted",children:[e.jsx(ht,{size:10}),e.jsx("span",{children:y})]}),e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${g?"opacity-0 group-hover:opacity-100":"rotate-180"}`,children:e.jsx(et,{size:13})})]}),!g&&e.jsx("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25",children:e.jsx(pi,{toolCall:s})})]})});function sr(t){const s=t??"";let n=s,r=null,i=null;try{const a=JSON.parse(s);if(a&&typeof a=="object")if("payload"in a){i=typeof a.toolName=="string"?a.toolName:null;const l=a.payload;typeof l=="string"?n=l:l&&typeof l=="object"?(r=l,n=JSON.stringify(l,null,2)):n=""}else Array.isArray(a)||(r=a)}catch{n=s}if(!r&&n.length>0&&/^[\s]*[{[]/.test(n))try{const a=JSON.parse(n);a&&typeof a=="object"&&!Array.isArray(a)&&(r=a)}catch{}return{toolName:i,payloadText:n,args:r}}const _s=/\b(bash|shell|exec|cmd|powershell|terminal)\b/i,nr=/write_file|write|save|create|upload|deploy|publish/i,rr=/edit_file|edit|patch|apply|update|replace/i,ar=/read_file|read|view|cat|open|list|dir\b/i,ki=/file_delete|delete|remove|unlink|\brm\b|\bdel\b/i,vi=/\b(glob|find|locate)\b/i,ji=/\b(grep|rg|search_contents)\b/i,yi=/web_search|search_web|browse/i,ir=/web_fetch|fetch|http|curl|wget|download|request|api/i,wi=/git|commit|merge|rebase|push|checkout/i,Ni=/install|uninstall|npm|pnpm|yarn|pip|cargo|gem|apt|brew|choco/i,Ds=/send_message|send_file|message|notify|post/i;function or(t){const s=t.toLowerCase();return _s.test(s)?"verbRunCommand":yi.test(s)?"verbSearchWeb":nr.test(s)?"verbWriteFile":rr.test(s)?"verbEditFile":ki.test(s)?"verbDeleteFile":ar.test(s)?"verbReadFile":ji.test(s)?"verbSearchContents":vi.test(s)?"verbFindFiles":ir.test(s)?"verbFetchUrl":wi.test(s)?"verbGit":Ni.test(s)?"verbInstall":Ds.test(s)?"verbSendMessage":"verbRunTool"}function ts(t,s){const n=(t??"").replace(/\s+/g," ").trim();return n.length>s?`${n.slice(0,s-1)}…`:n}function Si(t){if(!t)return null;for(const s of["file_path","filePath","path","file","target"]){const n=t[s];if(typeof n=="string"&&n.length>0)return n}return null}function lr(t,s){const{payloadText:n,args:r}=sr(s),i=t.toLowerCase();if(_s.test(i))return"";const a=Si(r);if(a)return a;const l=n.match(/(?:file_path|path|file)["\s:=]+([^\s",}]+)/i);if(l!=null&&l[1])return l[1];if(ir.test(i)&&typeof(r==null?void 0:r.url)=="string"&&r.url)return ts(r.url,48);if(Ds.test(i)){const c=typeof(r==null?void 0:r.text)=="string"?r.text:typeof(r==null?void 0:r.message)=="string"?r.message:n;return ts(c,48)}return ts(n,48)}function cr(t,s){const{payloadText:n,args:r}=sr(s),i=t.toLowerCase();if(_s.test(i)){const a=typeof(r==null?void 0:r.command)=="string"?r.command:n;return a?{text:a,mono:!0}:null}if(nr.test(i)||rr.test(i)){const a=typeof(r==null?void 0:r.content)=="string"?r.content:typeof(r==null?void 0:r.data)=="string"?r.data:"";if(a)return{text:a,mono:!0};if(r){const l=cn(r);if(l)return{text:l,mono:!0}}return n?{text:n,mono:!0}:null}if(Ds.test(i)){const a=typeof(r==null?void 0:r.text)=="string"?r.text:typeof(r==null?void 0:r.message)=="string"?r.message:n;return a?{text:a,mono:!1}:null}if(ar.test(i))return null;if(r){const a=cn(r);if(a)return{text:a,mono:!0}}return n?{text:n,mono:!0}:null}function cn(t){return t?Object.entries(t).filter(([,s])=>s!=null).map(([s,n])=>{let r=typeof n=="string"?n:JSON.stringify(n);return r.length>96&&(r=`${r.slice(0,95)}…`),`${s}=${r.replace(/\n/g," ")}`}).join(" "):""}function dr(t,s){const n=xt(s);return n?{path:n,external:!0}:{key:"scopeLocal",external:!1}}function ur({pre:t,obj:s}){return e.jsxs("span",{className:"min-w-0 text-sm text-dark-muted",children:[e.jsx("span",{children:t}),s&&e.jsx("b",{className:"font-semibold text-dark-text",children:s})]})}const ss=5,ns=420;function Es({text:t,mono:s=!0}){const{t:n}=ee("hook"),[r,i]=o.useState(!1),a=t.split(`
9
- `),l=a.length>ss||t.length>ns;let c=t;!r&&l&&(c=a.slice(0,ss).join(`
10
- `),c.length>ns&&(c=`${c.slice(0,ns).trimEnd()}…`));const d=r?n("showLess"):a.length>ss?n("showAllLines",{n:a.length}):n("showAll");return e.jsxs("div",{className:`rounded-lg border border-dark-border bg-dark-surface p-2.5 text-xs leading-relaxed break-all whitespace-pre-wrap ${s?"font-mono":""} text-dark-text`,children:[c,l&&e.jsx("button",{type:"button",onClick:()=>i(h=>!h),className:"mt-1 block text-[11px] text-accent-blue hover:underline",children:d})]})}const rs=15,Ei=o.memo(function({approval:s,onResolved:n}){const{t:r}=ee("hook"),[i,a]=o.useState(!1),[l,c]=o.useState(rs),d=o.useRef(null),h=s.status==="pending",{level:u,reasonKey:x}=Wn(s.toolName,s.askPayload),g=Un[u],p=cr(s.toolName,s.askPayload),b=dr(s.toolName,s.askPayload),j=xt(s.askPayload)!==null;o.useEffect(()=>{if(h)return c(rs),d.current=setInterval(()=>{c(C=>C<=1?(d.current&&clearInterval(d.current),0):C-1)},1e3),()=>{d.current&&clearInterval(d.current)}},[h,s.approvalId]),o.useEffect(()=>{const C=(s.timeoutMs??15e3)>0;l===0&&h&&!i&&C&&y()},[l]);const y=o.useCallback(()=>{!h||i||(a(!0),d.current&&clearInterval(d.current),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:s.approvalId})}),n==null||n(s.approvalId,"approved"))},[h,i,s.approvalId,n]),f=o.useCallback(()=>{!h||i||(a(!0),d.current&&clearInterval(d.current),pe.send({type:"hook_deny",data:JSON.stringify({approvalId:s.approvalId})}),n==null||n(s.approvalId,"denied"))},[h,i,s.approvalId,n]),k=o.useCallback(()=>{if(!h||i)return;a(!0),d.current&&clearInterval(d.current);const C=Ns.getState(),A=xt(s.askPayload);A?(C.addToSessionAllowList(s.toolName,A),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:s.approvalId,sessionAllow:!0})})):(C.addToSessionAllowList(s.toolName),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:s.approvalId})})),n==null||n(s.approvalId,"approved")},[h,i,s.approvalId,s.toolName,s.askPayload,n]),D=o.useCallback(()=>{!h||i||(a(!0),d.current&&clearInterval(d.current),Ns.getState().setAutoMode(!0),qe.getState().setAuto(!0),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:s.approvalId})}),n==null||n(s.approvalId,"approved"))},[h,i,s.approvalId,n]);if(!h){const C=s.status==="approved";return e.jsx("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${C?"bg-accent-green/10 border border-accent-green/30 text-accent-green":"bg-accent-red/10 border border-accent-red/30 text-accent-red"}`,children:C?e.jsxs(e.Fragment,{children:[e.jsx(Ye,{size:14}),e.jsxs("span",{children:[r("alreadyAllowed"),s.toolName]})]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{size:14}),e.jsxs("span",{children:[r("alreadyDenied"),s.toolName]})]})})}const S=l/rs*100,N=l<=5,R=[{id:"allow",index:1,label:r("optionAllow"),hint:r("optionAllowHint"),action:y,kind:"primary"},{id:"allow_session",index:3,label:r("optionAllowAlways"),hint:j?r("optionAllowPathHint"):r("optionAllowAlwaysHint",{tool:s.toolName}),action:k,kind:"secondary"},{id:"auto_mode",index:4,label:r("optionAutoMode"),hint:r("optionAutoModeHint"),action:D,kind:"secondary"},{id:"deny",index:2,label:r("optionDeny"),hint:r("optionDenyHint"),action:f,kind:"danger"}],O={primary:"bg-accent-blue text-white hover:opacity-90 shadow-sm",secondary:"border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover",danger:"text-dark-muted hover:bg-red-500/10 hover:text-red-400"};return e.jsxs("div",{className:`bg-dark-bg border rounded-xl overflow-hidden ${b.external?"border-amber-500/40":g.border}`,children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 border-b ${g.bg} ${b.external?"border-amber-500/30":g.border}`,children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${rc.badge}",children:[g.icon," ",u]}),e.jsx("span",{className:"flex-none w-6 h-6 rounded-md bg-accent-blue/10 text-accent-blue inline-flex items-center justify-center",children:e.jsx(vs,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ur,{pre:r(or(s.toolName)),obj:lr(s.toolName,s.askPayload)})}),b.external&&b.path?e.jsxs("span",{className:"flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/30 shrink-0",title:b.path,children:[e.jsx(Cs,{size:10}),b.path.length>32?`${b.path.slice(0,31)}…`:b.path]}):e.jsx("span",{className:"text-[10px] text-dark-muted/60 shrink-0",children:r("scopeLocal")}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-1 shrink-0",children:[e.jsx(ht,{size:11,className:N?"text-accent-red":"text-dark-muted"}),e.jsxs("span",{className:`text-[11px] font-mono ${N?"text-accent-red animate-pulse":"text-dark-muted"}`,children:[l,"s"]}),e.jsx("div",{className:"w-10 h-1 bg-dark-border rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-1000 ${N?"bg-accent-red":l<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${S}%`}})})]})]}),e.jsxs("div",{className:"px-3 py-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-dark-muted shrink-0",children:r("tool")}),e.jsx("code",{className:"text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded",children:s.toolName}),e.jsx("span",{className:"text-[10px] text-dark-muted/50",children:r(x)})]}),p&&e.jsx(Es,{text:p.text,mono:p.mono}),(u==="CRITICAL"||u==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-[11px] px-2 py-1 rounded ${g.bg} ${g.text}`,children:[e.jsx(Te,{size:12}),e.jsx("span",{children:r(u==="CRITICAL"?"highRiskWarning":"mediumRiskConfirm")})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:R.map(C=>e.jsxs("button",{onClick:C.action,disabled:i,className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs transition-colors disabled:opacity-50 ${O[C.kind]}`,children:[e.jsx("span",{className:`text-[9px] font-mono rounded px-0.5 ${C.kind==="primary"?"bg-white/20":"bg-dark-surface text-dark-muted"}`,children:C.index}),e.jsx("span",{children:C.label}),e.jsx("span",{className:`text-[10px] ${C.kind==="primary"?"text-white/70":"text-dark-muted/60"} hidden sm:inline`,children:C.hint})]},C.id))}),e.jsx("div",{className:"text-[10px] text-dark-muted/50 pt-0.5 border-t border-dark-border/50",children:r("clickToSelect")})]})]})}),At={xlsx:{icon:js},xls:{icon:js},csv:{icon:ut},docx:{icon:ut},text:{icon:Ts}};function dn(t){return!t&&t!==0?"—":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/1024/1024).toFixed(2)} MB`}const Mi=o.memo(function({job:s}){var g,p;const{t:n}=ee(),{stage:r}=s,i=o.useCallback(b=>{switch(b){case"xlsx":case"xls":return"Excel";case"csv":return"CSV";case"docx":return"Word";default:return n("fileJob.kindText")}},[n]),a=o.useCallback(b=>{fe.files.download(b).then(j=>{j.success||he.error(j.error||n("fileJob.downloadFailed"))})},[n]),l=o.useMemo(()=>s.attachments||[],[s.attachments]),c=o.useMemo(()=>s.parsedFiles||[],[s.parsedFiles]),d=o.useMemo(()=>s.mapping||[],[s.mapping]),h=o.useMemo(()=>s.result||[],[s.result]),u=s.renderProgress??(r==="rendering"?0:100),x=s.parseProgress??(r==="parsing"?0:100);return e.jsxs("div",{className:"mt-2 rounded-xl border border-dark-border bg-dark-surface/60 overflow-hidden max-w-2xl",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3.5 py-2.5 border-b border-dark-border/60 bg-dark-surface",children:[r==="complete"?e.jsx(zt,{size:15,className:"text-accent-green shrink-0"}):r==="error"?e.jsx(Te,{size:15,className:"text-accent-red shrink-0"}):e.jsx(Me,{size:15,className:"text-accent-blue animate-spin shrink-0"}),e.jsx("span",{className:"text-[13px] font-medium text-dark-text",children:Ci(r,n)}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-[10px] font-mono text-dark-muted/60",children:s.jobId})]}),e.jsxs("div",{className:"px-3.5 py-3 space-y-3",children:[l.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:l.map((b,j)=>{const f=(At[b.kind]||At.text).icon;return e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-dark-border bg-dark-bg px-2.5 py-1.5",children:[e.jsx(f,{size:14,className:"text-accent-blue shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-dark-text truncate max-w-[160px]",children:b.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[dn(b.size)," · ",i(b.kind),b.role&&b.role!=="unknown"&&e.jsxs("span",{className:de("ml-1",b.role==="data"?"text-accent-green":"text-accent-purple"),children:["· ",b.role==="data"?n("fileJob.roleData"):n("fileJob.roleTemplate")]})]})]})]},`${b.fileName}-${j}`)})}),r==="parsing"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:n("fileJob.parsing",{file:((g=l[0])==null?void 0:g.fileName)||((p=c[0])==null?void 0:p.fileName)||""})}),e.jsx(on,{value:x,size:"sm",showLabel:!0})]}),c.length>0&&r!=="error"&&e.jsxs("div",{className:"space-y-1.5",children:[c.map(b=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(zt,{size:13,className:"text-accent-green shrink-0"}),e.jsx("span",{className:"truncate",children:b.fileName}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:n("fileJob.parsedSummary",{rows:b.rowCount,fields:b.fields.length})})]},b.fileName)),c[0]&&e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[c[0].fields.slice(0,12).map(b=>e.jsx("span",{className:"rounded bg-dark-bg border border-dark-border/60 px-1.5 py-0.5 text-[10px] font-mono text-dark-muted",children:b},b)),c[0].fields.length>12&&e.jsxs("span",{className:"text-[10px] text-dark-muted/60",children:["+",c[0].fields.length-12]})]})]}),d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-[11px] text-dark-muted",children:n("fileJob.mappingTitle")}),e.jsx("div",{className:"overflow-hidden rounded-lg border border-dark-border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-dark-bg text-dark-muted",children:[e.jsx("th",{className:"text-left px-2.5 py-1.5 font-medium",children:n("fileJob.templatePlaceholder")}),e.jsx("th",{className:"px-2 py-1.5"}),e.jsx("th",{className:"text-left px-2.5 py-1.5 font-medium",children:n("fileJob.dataField")})]})}),e.jsx("tbody",{children:d.slice(0,8).map(b=>e.jsxs("tr",{className:"border-t border-dark-border/50",children:[e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-purple",children:"{{"+b.placeholder+"}}"}),e.jsx("td",{className:"px-2 py-1.5 text-dark-muted",children:e.jsx(Ur,{size:11})}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-blue",children:b.field})]},b.placeholder))})]})}),d.length>8&&e.jsx("div",{className:"text-[10px] text-dark-muted/60",children:n("fileJob.mappingMore",{n:d.length-8})})]}),r==="rendering"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:n("fileJob.rendering",{current:s.currentRow||0,total:s.totalRows||0})}),e.jsx(on,{value:u,size:"sm",variant:"warning",showLabel:!0})]}),h.length>0&&r==="complete"&&e.jsx("div",{className:"space-y-1.5",children:h.map(b=>{const y=(At[b.format]||At.text).icon,f=b.failedRows.length>0;return e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{size:15,className:"text-accent-green shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs text-dark-text truncate",children:b.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[dn(b.size)," · ",n("fileJob.rowsDone",{done:b.successCount,total:b.rowCount}),f&&e.jsxs("span",{className:"text-accent-red",children:[" · ",n("fileJob.rowsFailed",{n:b.failedRows.length})]})]})]}),e.jsxs("button",{onClick:()=>Bt(b.path),className:"flex items-center gap-1 rounded-md bg-dark-surface border border-dark-border text-dark-muted px-2 py-1 text-[11px] hover:bg-dark-hover hover:text-dark-text transition-colors",title:n("chat.previewInPanel"),children:[e.jsx(zn,{size:12}),n("chat.previewInPanel")]}),e.jsxs("button",{onClick:()=>a(b.path),className:"flex items-center gap-1 rounded-md bg-accent-blue/10 text-accent-blue px-2 py-1 text-[11px] hover:bg-accent-blue/20 transition-colors",title:n("fileJob.download"),children:[e.jsx(Gr,{size:12}),n("fileJob.download")]})]}),f&&e.jsxs("div",{className:"mt-1.5 space-y-0.5 border-t border-dark-border/50 pt-1.5",children:[b.failedRows.slice(0,3).map(k=>e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-accent-red",children:[e.jsx($n,{size:10,className:"shrink-0"}),e.jsxs("span",{children:["#",k.index+1]}),e.jsx("span",{className:"truncate",children:k.error})]},k.index)),b.failedRows.length>3&&e.jsx("div",{className:"text-[10px] text-dark-muted/70",children:n("fileJob.moreRows",{n:b.failedRows.length-3})})]})]},b.path)})}),r==="error"&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/30 bg-accent-red/5 px-3 py-2.5",children:[e.jsx(Te,{size:15,className:"text-accent-red shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-medium text-accent-red",children:s.error||n("fileJob.error")}),s.errorDetail&&e.jsx("div",{className:"mt-0.5 text-[11px] text-dark-muted break-words",children:s.errorDetail})]})]})]})]})});function Ci(t,s){switch(t){case"uploaded":return s("fileJob.stageUploaded");case"parsing":return s("fileJob.stageParsing");case"mapping":return s("fileJob.stageMapping");case"rendering":return s("fileJob.stageRendering");case"complete":return s("fileJob.stageComplete");case"error":return s("fileJob.stageError");default:return s("fileJob.stageUploaded")}}const un={auth:{icon:Vr,color:"text-accent-red"},rate_limit:{icon:ys,color:"text-accent-yellow"},timeout:{icon:ys,color:"text-accent-yellow"},network:{icon:Jr,color:"text-accent-yellow"},model:{icon:On,color:"text-accent-red"},tool:{icon:Te,color:"text-accent-yellow"},unknown:{icon:Te,color:"text-accent-red"}},Ti=o.memo(function({error:s,onRetry:n}){const{t:r}=ee(),[i,a]=o.useState(!1),l=un[s.category]||un.unknown,c=l.icon,d=()=>{window.dispatchEvent(new CustomEvent("switch-tab",{detail:"models"}))};return e.jsxs("div",{className:"mt-2 max-w-2xl overflow-hidden rounded-xl border border-accent-red/30 bg-dark-surface",children:[e.jsxs("div",{className:"flex items-start gap-3 px-3.5 py-3",children:[e.jsx(c,{size:18,className:de("shrink-0 mt-0.5",l.color)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-dark-text",children:s.summary}),s.detail&&s.detail!==s.summary&&e.jsx("div",{className:"mt-0.5 text-[11px] text-dark-muted/80 break-words",children:s.detail.slice(0,160)}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[s.retryable&&n&&e.jsxs("button",{onClick:n,className:"flex items-center gap-1 rounded-md bg-accent-blue/10 text-accent-blue px-2 py-1 text-[11px] hover:bg-accent-blue/20 transition-colors",children:[e.jsx(mt,{size:11}),r("errorCard.retry")]}),s.category==="auth"&&e.jsxs("button",{onClick:d,className:"flex items-center gap-1 rounded-md bg-dark-hover text-dark-text px-2 py-1 text-[11px] hover:bg-dark-border transition-colors",children:[e.jsx(Xr,{size:11}),r("errorCard.modelSettings")]}),s.detail&&e.jsxs("button",{onClick:()=>a(h=>!h),className:"flex items-center gap-0.5 text-[11px] text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(et,{size:11,className:de("transition-transform",i&&"rotate-180")}),r("errorCard.details")]})]})]})]}),i&&s.detail&&e.jsx("div",{className:"border-t border-dark-border/60 bg-dark-bg px-3.5 py-2.5 text-[11px] font-mono text-dark-muted break-words max-h-40 overflow-y-auto custom-scrollbar",children:s.detail})]})});function Ii({info:t}){const{t:s}=ee(),n=t.stdout.length>0,r=t.stderr.length>0,i=n||r,a=!t.running&&(!!t.error||t.timedOut===!0||t.exitCode!==null&&t.exitCode!==0);return e.jsxs("div",{className:"min-w-0 text-dark-text",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"select-none pt-[1px] font-mono text-[13px] leading-relaxed text-accent-green",children:"$"}),e.jsx("code",{className:"min-w-0 flex-1 break-all whitespace-pre-wrap font-mono text-[13px] leading-relaxed",children:t.command})]}),t.running?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-dark-muted",children:[e.jsx(Me,{size:12,className:"animate-spin","aria-hidden":"true"}),s("chat.shellRunning")]}):e.jsxs(e.Fragment,{children:[i&&e.jsxs("pre",{className:"mt-2 max-h-[420px] overflow-auto rounded-lg border border-dark-border/40 bg-dark-bg/70 px-3 py-2 font-mono text-[12.5px] leading-relaxed whitespace-pre-wrap break-all custom-scrollbar",children:[n&&e.jsx("span",{children:t.stdout}),r&&e.jsxs("span",{className:"text-accent-red",children:[n?t.stdout.endsWith(`
11
- `)?"":`
12
- `:"",t.stderr]})]}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-2.5 gap-y-1 text-[11px]",children:[t.error?e.jsxs("span",{className:"flex items-center gap-1 text-accent-red",children:[e.jsx(Te,{size:11,"aria-hidden":"true"}),s("chat.shellRequestFailed",{message:t.error})]}):e.jsx("span",{className:a?"text-accent-red":"text-accent-green",children:t.exitCode===null?s("chat.shellNoExitCode"):s("chat.shellExitCode",{code:t.exitCode})}),t.durationMs>0&&e.jsx("span",{className:"tabular-nums text-dark-muted/70",children:t.durationMs>=1e3?`${(t.durationMs/1e3).toFixed(1)}s`:`${t.durationMs}ms`}),t.timedOut&&e.jsx("span",{className:"text-accent-red",children:s("chat.shellTimedOut")}),t.truncated&&e.jsx("span",{className:"text-dark-muted/70",children:s("chat.shellTruncated")}),t.shellKind&&e.jsx("span",{className:"text-dark-muted/60",children:t.shellKind})]}),!i&&!t.error&&e.jsx("div",{className:"mt-1.5 text-[11px] text-dark-muted/70",children:s("chat.shellNoOutput")})]}),!t.running&&t.cwd&&e.jsx("div",{className:"mt-1 truncate font-mono text-[10.5px] text-dark-muted/50",title:t.cwd,children:t.cwd})]})}const as=360,is=300,Ai=180,Ce=8;function zs({src:t,alt:s,children:n,className:r}){const i=o.useRef(null),a=o.useRef(null),[l,c]=o.useState(null),d=o.useCallback(()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},[]),h=o.useCallback(()=>{d(),a.current=window.setTimeout(()=>{var p;a.current=null;const g=(p=i.current)==null?void 0:p.getBoundingClientRect();g&&g.width>0&&c(g)},Ai)},[d]),u=o.useCallback(()=>{d(),c(null)},[d]);o.useEffect(()=>()=>d(),[d]),o.useEffect(()=>{if(!l)return;const g=()=>c(null);return window.addEventListener("scroll",g,!0),window.addEventListener("resize",g),()=>{window.removeEventListener("scroll",g,!0),window.removeEventListener("resize",g)}},[l]);let x=null;if(l){const g=window.innerWidth,p=window.innerHeight,b=l.top>=is+Ce+Ce,j=b?l.top-Ce:l.bottom+Ce,y=l.left+l.width/2-as/2,f=Math.max(Ce,Math.min(y,Math.max(Ce,g-as-Ce))),k=b?j:Math.min(j,Math.max(Ce,p-is-Ce));x={left:f,top:k,transform:b?"translateY(-100%)":void 0}}return e.jsxs("span",{ref:i,className:de("inline-flex min-w-0",r),onMouseEnter:h,onMouseLeave:u,onFocus:h,onBlur:u,children:[n,l&&x&&e.jsx("div",{role:"tooltip","data-testid":"image-hover-preview",className:"pointer-events-none fixed z-[70] overflow-hidden rounded-lg border border-dark-border bg-dark-surface p-1 shadow-xl",style:x,children:e.jsx("img",{src:t,alt:s,draggable:!1,className:"block rounded object-contain",style:{maxWidth:as-8,maxHeight:is}})})]})}function Ri({src:t,name:s,path:n,size:r=13,className:i,hoverPreview:a=!0}){const{t:l}=ee(),c=o.useCallback(()=>{Gn({src:t,name:s,path:n})},[t,s,n]);if(!t)return e.jsx($t,{size:r,className:"shrink-0 text-dark-muted","aria-hidden":"true"});const d=e.jsx("button",{type:"button",onClick:c,title:`${s} · ${l("fileJob.openInPanel")}`,"aria-label":`${s} — ${l("fileJob.openInPanel")}`,className:de("cursor-zoom-in rounded p-0.5 text-dark-muted transition-colors hover:bg-accent-blue/10 hover:text-accent-blue","focus:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60",i),children:e.jsx($t,{size:r,"aria-hidden":"true"})});return a?e.jsx(zs,{src:t,alt:s,className:"shrink-0",children:d}):d}function _i({src:t,name:s,path:n,className:r}){const{t:i}=ee(),a=o.useCallback(()=>{Gn({src:t,name:s,path:n})},[t,s,n]);return e.jsx(zs,{src:t,alt:s,className:r,children:e.jsxs("button",{type:"button",onClick:a,title:`${s} · ${i("fileJob.openInPanel")}`,className:"inline-flex max-w-full cursor-zoom-in items-center gap-1.5 rounded-lg border border-dark-border/60 bg-dark-bg/60 px-2 py-1 text-xs transition-colors hover:border-accent-blue/40 hover:bg-dark-hover",children:[e.jsx($t,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:s})]})})}const Di=/<attachment\s+path="([^"]*)"\s*\/>/g,zi=/<image\s+name="([^"]*)"\s*\/>/g,$i=new RegExp("(?<![\\w@.])@((?:[\\w@.()[\\]{}$%-]+[\\\\/])+[\\w@.()[\\]{}$%-]+|[\\w@.()[\\]{}$%-]*[\\w@()[\\]{}$%-]\\.[A-Za-z0-9]{1,12})","g");function Oi(t){return!t||t.length>400?!1:t.includes("/")||t.includes("\\")?Jn(t):/\.[A-Za-z0-9]{1,12}$/.test(t)}function Pi(t){if(!t)return[];const s=[],n=i=>{i&&s.push({kind:"text",value:i})};return t.split($i).forEach((i,a)=>{if(a%2===1){Oi(i)?s.push({kind:"mention",value:i}):n(`@${i??""}`);return}i.split(Ia).forEach((c,d)=>{if(d%2===1){const{path:h,tail:u}=Aa(c);if(h&&Jn(h)){s.push({kind:"path",value:h}),n(u);return}}n(c)})}),s}function Li(t){const s=[],n=[];let r=(t||"").replace(Di,(i,a)=>(a&&s.push(a),"")).replace(zi,(i,a)=>(a&&n.push(a),""));return(s.length>0||n.length>0)&&(r=r.replace(/^(?:[ \t]*\n)+/,"")),{attachments:s,imageNames:n,segments:Pi(r.replace(/\n{3,}/g,`
13
-
14
- `))}}function Fi({path:t}){const s=t.split(/[\\/]/).pop()||t;return e.jsxs("button",{type:"button",title:t,onClick:()=>Bt(t),className:"mr-1 inline-flex max-w-full items-center gap-1.5 rounded-lg border border-dark-border bg-dark-bg/60 px-2 py-1 align-middle text-xs transition-colors hover:border-accent-blue/40 hover:bg-dark-hover",children:[e.jsx(Pn,{size:11,className:"shrink-0 text-dark-muted"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:s}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-accent-blue",children:"<attachment>"})]})}function Bi({content:t,images:s}){const{t:n}=ee(),r=o.useMemo(()=>Li(t),[t]),i=o.useMemo(()=>(s??[]).map((a,l)=>{const c=r.imageNames[l],d=a.startsWith("data:")||a.startsWith("blob:"),h=d?n("fileJob.imageN",{n:l+1}):(a.split(/[?#]/)[0]??"").split(/[\\/]/).pop()||n("fileJob.imageN",{n:l+1});return{key:`${l}-${a.slice(0,48)}`,src:Ca(a),name:c||h,path:d?void 0:a}}),[s,r.imageNames,n]);return e.jsxs("div",{className:"whitespace-pre-wrap break-words text-[14.5px] leading-relaxed",children:[r.attachments.map((a,l)=>e.jsx(Fi,{path:a},`${a}-${l}`)),i.map(a=>e.jsx(_i,{src:a.src,name:a.name,path:a.path,className:"mr-1 align-middle"},a.key)),r.segments.map((a,l)=>a.kind==="text"?e.jsx("span",{children:a.value},l):a.kind==="mention"?e.jsxs("button",{type:"button",onClick:()=>Bt(a.value),title:a.value,className:"inline-flex items-baseline rounded px-0.5 font-mono text-[0.9em] text-accent-blue underline decoration-accent-blue/40 underline-offset-2 hover:bg-accent-blue/10 transition-colors cursor-pointer",children:[e.jsx("span",{className:"text-dark-muted",children:"@"}),e.jsx("span",{className:"break-all",children:a.value})]},l):e.jsx(Ta,{path:a.value},l))]})}const hn=12;function mn(t){const s=t.slice(0,hn).join(`
15
- `),n=t.length-hn;return n>0?`${s}
16
- … (${n})`:s}const Hi=o.memo(function({created:s,modified:n,onOpenArtifacts:r,onOpenChanges:i}){const{t:a}=ee();if(s.length===0&&n.length===0)return null;const l="inline-flex items-center gap-0.5 text-dark-muted hover:text-dark-text transition-colors focus:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/50 rounded";return e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-0.5 text-[11px]","data-testid":"turn-result-footer",children:[s.length>0&&e.jsxs("button",{type:"button",onClick:r,className:l,"data-testid":"turn-result-artifacts",title:mn(s),children:[a("chat.viewAllArtifacts",{n:s.length}),e.jsx(Oe,{size:11,className:"shrink-0 opacity-70"})]}),n.length>0&&e.jsxs("button",{type:"button",onClick:i,className:l,"data-testid":"turn-result-changes",title:mn(n),children:[a("chat.viewAllChanges",{n:n.length}),e.jsx(Oe,{size:11,className:"shrink-0 opacity-70"})]})]})});function Ki(t){for(const s of t.split(`
17
- `)){const n=s.trim();if(n)return n}return""}function qi(t){var n;const s=t.split(`
18
- `);for(let r=s.length-1;r>=0;r--){const i=(n=s[r])==null?void 0:n.trim();if(i)return i}return""}function Wi({index:t,text:s,isStreaming:n,collapsed:r,onToggle:i}){const{t:a}=ee(),l=r?n?qi(s):Ki(s):"";return e.jsxs("div",{children:[e.jsxs("button",{className:"flex w-full cursor-pointer select-none items-center gap-1.5 py-0.5 text-left text-xs",onClick:()=>i(t),"data-testid":"thinking-toggle",children:[e.jsx(Oe,{size:12,className:`shrink-0 text-dark-muted transition-transform ${r?"":"rotate-90"}`}),e.jsx("span",{className:`shrink-0 ${n?"text-shimmer":"text-dark-muted"}`,children:n?`${a("chat.thinking")}…`:a("chat.thoughtProcess")}),l&&e.jsx("span",{"data-testid":"thinking-summary",className:"min-w-0 flex-1 truncate text-dark-muted/60",title:l,children:l})]}),!r&&e.jsx("div",{"data-testid":"thinking-body",className:"mt-1 whitespace-pre-wrap break-words border-l border-dark-border/25 pl-3 text-xs text-dark-muted",children:s.replace(/\n{3,}/g,`
19
-
20
- `)})]})}const hr=5,Ui=30,Gi=["让我","我先","我现在","我发现","我注意到","我决定","我重新","我重试","我继续","我现在要","让我现在","let me","let's","i should","i need","i will","i'll","i am","i notice","i see","i try","i retry","i think","i continue","i re-","now i","first i","first, i"];function Ji(t){const s=t.charCodeAt(0);return s>=19968&&s<=40959}function Vi(t){let s="",n=!1;for(const r of t)r===" "||r===" "||r===" "?(n||(s+=" "),n=!0):(s+=r,n=!1);return s}function Xi(t){return t>=97&&t<=122||t>=48&&t<=57||t===95}function mr(t){const s=Vi(t.trimStart().toLowerCase());return Gi.some(n=>{if(!s.startsWith(n))return!1;const r=s[n.length];return r===void 0||Ji(n)||n==="i re-"?!0:!Xi(r.charCodeAt(0))})}function Qi(t){if(!t)return!1;const s=t.split(/\r?\n/).slice(0,Ui);let n=0;for(const r of s)if(r.trim())if(mr(r)){if(n++,n>=hr)return!0}else return!1;return!1}function Yi(t,s){if(!t)return{body:t||"",absorbed:""};if(!Qi(t))return{body:t,absorbed:""};const n=t.split(/\r?\n/);let r=0,i=0;for(const l of n){if(!l.trim()){i++;continue}if(mr(l)){r++,i++;continue}break}if(r<hr)return{body:t,absorbed:""};let a=0;for(const l of n.slice(0,i)){if(a+=l.length,a>=t.length)break;t.startsWith(`\r
21
- `,a)?a+=2:(t[a]===`
22
- `||t[a]==="\r")&&(a+=1)}return{body:t.slice(a),absorbed:t.slice(0,a)}}const Zi=new Set(["edit_file","file_edit","file_append","notebook_edit","apply_patch","git_apply_patch","Edit","EditTool","NotebookEditTool"]);function xn(t){return t.replace(/\\/g,"/").replace(/^\.\//,"")}function eo(t){return typeof t.diff=="string"&&t.diff.trim().length>0}function to(t){var a;const s=new Map,n=new Map,r=l=>{const c=xn(l);s.has(c)||(n.delete(c),s.set(c,l))},i=l=>{const c=xn(l);s.has(c)||n.has(c)||n.set(c,l)};for(const l of((a=t.fileJob)==null?void 0:a.result)??[])l!=null&&l.path&&r(l.path);for(const l of t.toolCalls??[]){if(!l||l.status==="error"||!As(l.name))continue;const c=pt(l.args);c&&(Zi.has(l.name)||eo(l)?i(c):r(c))}return{created:Array.from(s.values()),modified:Array.from(n.values())}}const fn={thinking:0,tool:1,text:2};function so(t){return t.thinkingBlocks&&t.thinkingBlocks.length>0?t.thinkingBlocks:t.thinking?[{index:Number.MIN_SAFE_INTEGER,text:t.thinking}]:[]}function no(t){return t.textBlocks&&t.textBlocks.length>0?t.textBlocks:t.content?[{index:Number.MAX_SAFE_INTEGER,text:t.content}]:[]}function ro(t,s,n){const r=[];for(const i of t)r.push({kind:"thinking",key:`thinking-${i.index}`,index:i.index,block:i});for(const i of s)r.push({kind:"text",key:`text-${i.index}`,index:i.index,block:i});for(const i of n??[])r.push({kind:"tool",key:`tool-${i.id}`,index:i.index??Number.MAX_SAFE_INTEGER,toolCall:i});return r.sort((i,a)=>i.index-a.index||fn[i.kind]-fn[a.kind]),r}function ao(t){let s=Number.MIN_SAFE_INTEGER;for(const n of t)s=Math.max(s,n.index);return s}function io(t,s){return t.some(n=>n.index>s)}function oo(t){return!!(t.status==="running"||t.diff||t.name==="exit_plan_mode")}function os({onClick:t,title:s,children:n,danger:r=!1}){return e.jsx("button",{onClick:t,title:s,"aria-label":s,className:`inline-flex items-center justify-center rounded-md p-1.5 transition-colors ${r?"text-dark-muted hover:bg-accent-red/10 hover:text-accent-red":"text-dark-muted hover:bg-dark-hover hover:text-dark-text"}`,children:n})}function ls({message:t,sessionId:s,onRegenerate:n,onDeleteMessage:r}){const{t:i}=ee(),[a,l]=o.useState(!1),c=o.useRef(null);o.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const d=o.useCallback(async()=>{try{await navigator.clipboard.writeText(t.content||t.thinking||""),l(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),2e3)}catch(h){console.error("Failed to copy message:",h)}},[t.content,t.thinking]);return s?e.jsxs("div",{className:"absolute bottom-2 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-dark-border/60 bg-dark-bg/85 px-1 py-0.5 opacity-0 shadow-md backdrop-blur-sm transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100",children:[e.jsx(os,{onClick:d,title:i("chat.copyMessage"),children:a?e.jsx(Ye,{size:13,className:"text-accent-green"}):e.jsx(Yr,{size:13})}),t.type==="assistant"&&n&&e.jsx(os,{onClick:()=>n(t.id),title:i("chat.regenerate"),children:e.jsx(mt,{size:13})}),r&&e.jsx(os,{onClick:()=>r(t.id),title:i("chat.deleteMessage"),danger:!0,children:e.jsx(Zr,{size:13})})]}):null}function cs({ts:t,children:s}){const{i18n:n}=ee(),r=n.language==="en"?"en-US":"zh-CN";return e.jsxs("div",{className:"absolute bottom-2 left-3 select-none z-10 flex items-center gap-0.5 text-[10.5px] leading-none whitespace-nowrap opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity duration-150",children:[e.jsx("span",{className:"pr-1 text-[10px] text-dark-muted/50",children:new Date(t).toLocaleTimeString(r,{hour:"2-digit",minute:"2-digit"})}),s]})}const lo=o.memo(function({message:s,sessionId:n,onRegenerate:r,onDeleteMessage:i,onOpenSidebarView:a}){var C;const{t:l}=ee(),c=Ot(A=>A.developerView),d=xe(A=>{var _;if(!n||!A.generatingSessions.includes(n))return!1;const B=A.messagesBySession[n];return B?((_=B[B.length-1])==null?void 0:_.id)===s.id:!1}),h=xe(A=>{var _;if(!n)return!1;const B=A.messagesBySession[n];return B?((_=B[B.length-1])==null?void 0:_.id)===s.id:!1}),u=o.useMemo(()=>to(s),[s.toolCalls,s.fileJob]),x=o.useMemo(()=>so(s),[s.thinkingBlocks,s.thinking]),g=o.useMemo(()=>no(s),[s.textBlocks,s.content]),p=o.useMemo(()=>ro(x,g,s.toolCalls),[x,g,s.toolCalls]),b=o.useMemo(()=>ao(p),[p]),[j,y]=o.useState({}),f=o.useCallback(A=>!c&&(!d||io(p,A)),[c,d,p]),k=o.useCallback(A=>{y(B=>({...B,[A]:!(B[A]??f(A))}))},[f]),D=x.length>0,S=o.useCallback(A=>{if(!D)return A;const{body:B}=Yi(A);return B||A},[D]),N=s.type==="user",R=s.type==="system",O=o.useCallback((A,B)=>{if(!n)return;const H=xe.getState().getMessages(n),G=H.findIndex(w=>w.id===s.id);if(G===-1)return;const ne=H[G];if(!ne)return;const te={...ne,hookApproval:ne.hookApproval?{...ne.hookApproval,status:B}:void 0},V=[...H];V[G]=te,xe.setState({messagesBySession:{...xe.getState().messagesBySession,[n]:V}})},[n,s.id]);return s.deleted?null:s.shellRun?e.jsxs("div",{className:"chat-msg","data-role":"shell",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(Dn,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group relative",children:[e.jsx(cs,{ts:s.timestamp}),e.jsx(ls,{message:s,sessionId:n,onRegenerate:r,onDeleteMessage:i}),e.jsx(Ii,{info:s.shellRun})]})]}):N?e.jsxs("div",{className:"chat-msg","data-role":"user",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(Qr,{size:14,strokeWidth:2.4})}),e.jsx("div",{className:"max-w-[78%] flex flex-col",children:e.jsxs("div",{className:"group relative inline-block self-end rounded-2xl border border-dark-border/40 bg-dark-surface px-4 pb-8 pt-2.5 text-dark-text shadow-sm",style:{borderBottomRightRadius:"0.375rem"},children:[e.jsx(cs,{ts:s.timestamp}),e.jsx(ls,{message:s,sessionId:n,onRegenerate:r,onDeleteMessage:i}),e.jsx(Bi,{content:((C=s.content)==null?void 0:C.replace(/\n{3,}/g,`
23
-
24
- `))??"",images:s.images})]})})]}):R?e.jsx("div",{className:"chat-msg","data-role":"system",children:e.jsx("div",{className:"text-[11px] text-dark-muted bg-dark-surface border border-dark-border/60 rounded-full px-3.5 py-1 max-w-[90%] text-center",children:s.content})}):e.jsxs("div",{className:"chat-msg","data-role":"assistant",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(On,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group relative",children:[e.jsx(cs,{ts:s.timestamp}),e.jsx(ls,{message:s,sessionId:n,onRegenerate:r,onDeleteMessage:i}),p.length>0&&!s.hookApproval&&e.jsx("div",{className:"mb-1 space-y-1","data-testid":"message-chronology",children:p.map(A=>A.kind==="thinking"?e.jsx(Wi,{index:A.block.index,text:A.block.text,isStreaming:d&&A.block.index===b,collapsed:j[A.block.index]??f(A.block.index),onToggle:k},A.key):A.kind==="text"?e.jsx("div",{className:"leading-relaxed",children:e.jsx(Ra,{content:S(A.block.text).replace(/\n{3,}/g,`
25
-
26
- `)})},A.key):e.jsx(bi,{toolCall:A.toolCall,defaultCollapsed:c?!1:!oo(A.toolCall)},A.key))}),p.length===0&&!s.hookApproval&&d&&e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs text-dark-muted","data-testid":"thinking-typing",children:[e.jsxs("span",{className:"chat-typing-dots",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsxs("span",{children:[l("chat.thinking"),"…"]})]}),s.summary&&!d&&e.jsx("div",{className:"mt-1.5 text-[11px] text-dark-muted/70","data-testid":"turn-summary",children:_a(s.summary)}),h&&!d&&!s.hookApproval&&e.jsx(Hi,{created:u.created,modified:u.modified,onOpenArtifacts:()=>a==null?void 0:a("artifacts"),onOpenChanges:()=>a==null?void 0:a("changes")}),s.fileJob&&e.jsx("div",{className:"mt-3",children:e.jsx(Mi,{job:s.fileJob})}),s.errorCard&&e.jsx("div",{className:"mt-3",children:e.jsx(Ti,{error:s.errorCard,onRetry:n&&r?()=>r(s.id):void 0})}),s.hookApproval&&e.jsx("div",{className:"mt-3 border-l-2 border-accent-yellow/50 pl-3",children:e.jsx(Ei,{approval:s.hookApproval,onResolved:O})})]})]})});function co(t,s=28){const n=t.replace(/\s+/g," ").trim();return n.length>s?`${n.slice(0,s)}…`:n}const uo="cubic-bezier(0.34, 1.56, 0.64, 1)",ho=o.memo(function({items:s,activeId:n,onJump:r}){const{t:i}=ee(),[a,l]=o.useState(!1),c=o.useRef(null),d=o.useCallback(()=>{c.current&&window.clearTimeout(c.current),l(!0)},[]),h=o.useCallback(()=>{c.current&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>l(!1),180)},[]);return s.length===0?null:e.jsx("div",{role:"list","aria-label":i("chat.messageRail"),className:"pointer-events-none absolute right-4 top-1/2 z-30 hidden -translate-y-1/2 md:block",children:e.jsxs("div",{onMouseEnter:d,onMouseLeave:h,"data-testid":"rail-trigger",className:"pointer-events-auto relative flex items-center py-3",children:[e.jsxs("div",{"aria-hidden":!a,inert:!a,"data-testid":"rail-panel",className:`absolute right-full top-1/2 flex w-72 -translate-y-1/2 origin-right flex-col overflow-hidden rounded-xl border border-dark-border/70 bg-dark-bg/90 shadow-xl shadow-black/10 backdrop-blur-xl transition-all duration-300 ${a?"translate-x-0 scale-100 opacity-100":"pointer-events-none translate-x-4 scale-95 opacity-0"}`,style:{transitionTimingFunction:a?uo:"ease"},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-dark-border/60 px-3 py-2",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-dark-muted",children:[e.jsx(ea,{size:12,className:"text-accent-blue","aria-hidden":"true"}),i("chat.messageIndex")]}),e.jsx("span",{className:"rounded-full bg-dark-hover px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-dark-muted",children:s.length})]}),e.jsx("div",{className:"max-h-[55vh] overflow-y-auto p-1.5 custom-scrollbar",children:s.map((u,x)=>{const g=u.id===n;return e.jsxs("button",{type:"button",role:"listitem",onClick:()=>r(u.id),title:u.content,"aria-current":g?"true":void 0,tabIndex:a?0:-1,className:`group/item flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition-all duration-200 ${a?"translate-x-0 opacity-100":"translate-x-2 opacity-0"} ${g?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{transitionDelay:a?`${Math.min(x*24,264)}ms`:"0ms"},children:[e.jsx("span",{className:`mt-px flex h-4 w-4 shrink-0 items-center justify-center rounded text-[10px] font-semibold tabular-nums transition-colors duration-200 ${g?"bg-accent-blue text-white":"bg-dark-hover text-dark-muted group-hover/item:bg-dark-border/80 group-hover/item:text-dark-text"}`,children:x+1}),e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{"data-testid":"rail-entry-content",className:`block break-words text-xs leading-snug line-clamp-2 group-hover/item:line-clamp-none transition-colors duration-200 ${g?"font-medium text-accent-blue":"text-dark-text/90"}`,children:u.content})}),e.jsx(Oe,{size:12,"aria-hidden":"true",className:"mt-0.5 shrink-0 -translate-x-1 text-dark-muted/50 opacity-0 transition-all duration-200 group-hover/item:translate-x-0 group-hover/item:opacity-100"})]},u.id)})})]}),e.jsx("div",{"data-testid":"rail-dots",className:"flex flex-col items-end gap-1",children:s.map((u,x)=>{const g=co(u.content),p=u.id===n;return e.jsx("button",{type:"button",role:"listitem",onClick:()=>r(u.id),title:u.content,"aria-label":`${x+1}. ${g}`,"aria-current":p?"true":void 0,className:"group/dot pointer-events-auto flex h-6 w-5 items-center justify-center rounded-full transition-colors duration-200 hover:bg-dark-surface/80",children:e.jsx("span",{className:p?"h-2 w-2 rounded-full bg-accent-blue ring-2 ring-accent-blue/25 transition-all duration-300 ease-out group-hover/dot:scale-125":"h-1.5 w-1.5 rounded-full bg-dark-muted/35 transition-all duration-300 ease-out group-hover/dot:scale-150 group-hover/dot:bg-dark-muted"})},u.id)})})]})})}),mo=o.lazy(()=>Da(()=>import("./ThreeScene-CMqkpyKO.js"),__vite__mapDeps([0,1,2,3])));function xo(){try{const t=document.createElement("canvas");return!!(t.getContext("webgl2")??t.getContext("webgl"))}catch{return!1}}function fo(){return o.useMemo(xo,[])?e.jsxs("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-0 hidden overflow-hidden dark:block [&_.threeui-background]:bg-transparent",children:[e.jsx(o.Suspense,{fallback:null,children:e.jsx(mo,{})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-black/30 via-transparent to-black/40"})]}):null}const ds=24;function po({label:t}){const s=o.useRef(Date.now()),n=o.useRef(null),[r,i]=o.useState(!1);return o.useEffect(()=>{const a=window.setTimeout(()=>i(!0),15e3);return()=>window.clearTimeout(a)},[]),o.useEffect(()=>{if(!r)return;const a=()=>{const c=n.current;if(!c)return;const d=Math.floor((Date.now()-s.current)/1e3);c.textContent=d>=60?`${Math.floor(d/60)}m ${d%60}s`:`${d}s`};a();const l=window.setInterval(a,1e3);return()=>window.clearInterval(l)},[r]),e.jsxs("div",{className:"chat-col flex items-center gap-2 px-4 py-3 text-xs text-dark-muted sm:px-6",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-blue animate-blink"}),e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-blue animate-blink",style:{animationDelay:"0.2s"}}),e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent-blue animate-blink",style:{animationDelay:"0.4s"}})]}),e.jsx("span",{className:"text-shimmer",children:t}),r&&e.jsxs("span",{className:"flex items-center gap-1 tabular-nums text-dark-muted/70",children:[e.jsx(ht,{size:10}),e.jsx("span",{ref:n,children:"15s"})]})]})}const go=o.memo(function({messages:s,isGenerating:n,sessionId:r,centered:i=!1,onSendSuggestion:a,onRegenerate:l,onDeleteMessage:c,onOpenSidebarView:d}){const{t:h}=ee(),u=o.useRef(null),x=o.useRef(new Map),[g,p]=o.useState(!0),[b,j]=o.useState(null),[y,f]=o.useState(null),[k,D]=o.useState(0),S=o.useRef(null),N=o.useRef(!1),R=o.useRef(null),O=o.useRef(n);O.current=n;const C=o.useMemo(()=>s.filter(M=>!M.deleted),[s]),A=o.useMemo(()=>{if(!n)return!1;const M=C[C.length-1];return!M||M.type!=="assistant"?!1:!M.content},[n,C]),B=o.useMemo(()=>C.filter(M=>Vn(M)).map(M=>({id:M.id,content:M.content})),[C]),_=o.useMemo(()=>B.map(M=>M.id),[B]),H=o.useCallback(M=>{if(M){const W=M.dataset.mid;W&&x.current.set(W,M)}},[]);o.useEffect(()=>{const M=new Set(_);for(const W of x.current.keys())M.has(W)||x.current.delete(W)},[_]);const G=o.useCallback(()=>{const M=u.current;if(!M||_.length===0){j(null);return}const W=M.getBoundingClientRect(),z=W.top+W.height*.35;let $=_[0]??null;for(const K of _){const Z=x.current.get(K);if(!(!Z||!Z.isConnected))if(Z.getBoundingClientRect().top<=z)$=K;else break}M.scrollHeight-M.scrollTop-M.clientHeight<ds&&($=_[_.length-1]??$),j($)},[_]),ne=o.useCallback(()=>{const M=u.current;if(!M)return;const W=M.scrollHeight-M.scrollTop-M.clientHeight;N.current?W>=ds&&(N.current=!1):p(W<ds),G()},[G]);o.useEffect(()=>{G()},[s,G]);const te=o.useCallback(M=>{const W=u.current,z=x.current.get(M);if(!W||!z||!z.isConnected)return;p(!1),f(M),D(ue=>ue+1),S.current&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>f(null),1600);const $=W.getBoundingClientRect(),K=z.getBoundingClientRect(),Z=W.scrollTop+(K.top-$.top)-W.clientHeight/2+K.height/2;R.current&&window.clearTimeout(R.current),N.current=!0,W.scrollTo({top:Math.max(0,Z),behavior:"smooth"});const oe=()=>{N.current=!1};"onscrollend"in W&&W.addEventListener("scrollend",oe,{once:!0}),R.current=window.setTimeout(()=>{N.current=!1},1500)},[]);o.useEffect(()=>()=>{S.current&&window.clearTimeout(S.current),R.current&&window.clearTimeout(R.current)},[]);const V=o.useCallback(()=>{R.current&&window.clearTimeout(R.current),N.current=!1;const M=u.current;M&&(M.scrollTop=M.scrollHeight)},[]),w=o.useCallback(()=>{R.current&&window.clearTimeout(R.current),N.current=!1,p(!0);const M=u.current;M&&M.scrollTo({top:M.scrollHeight,behavior:"smooth"})},[]);o.useEffect(()=>{n&&(p(!0),V())},[n,V]);const U=o.useMemo(()=>{var W,z,$,K,Z;const M=C[C.length-1];return`${C.length}:${(M==null?void 0:M.id)??""}:${((W=M==null?void 0:M.content)==null?void 0:W.length)??0}:${((z=M==null?void 0:M.textBlocks)==null?void 0:z.length)??0}:${(($=M==null?void 0:M.toolCalls)==null?void 0:$.length)??0}:${((K=M==null?void 0:M.thinkingBlocks)==null?void 0:K.length)??0}:${((Z=M==null?void 0:M.thinking)==null?void 0:Z.length)??0}`},[C]),Q=o.useRef(U);o.useEffect(()=>{if(!g){Q.current=U;return}U!==Q.current&&(Q.current=U,V())},[U,g,V]);const se=o.useMemo(()=>[{icon:ta,label:h("chat.suggestionCode"),prompt:h("chat.suggestionCodePrompt")},{icon:ft,label:h("chat.suggestionAnalyze"),prompt:h("chat.suggestionAnalyzePrompt")},{icon:Ln,label:h("chat.suggestionAutomate"),prompt:h("chat.suggestionAutomatePrompt")}],[h]);return e.jsxs("div",{className:i?"relative w-full":"relative flex-1 min-h-0",children:[e.jsxs("div",{ref:u,onScroll:ne,className:i?"custom-scrollbar":"h-full overflow-y-auto custom-scrollbar",children:[C.length===0?e.jsxs("div",{className:i?"relative flex items-center justify-center px-4 pb-1 pt-0 sm:px-6":"relative flex min-h-[55vh] items-center justify-center px-4 py-10 sm:px-6",children:[e.jsx(fo,{}),e.jsxs("div",{className:"relative w-full max-w-2xl px-1 text-center",children:[e.jsx("div",{className:"chat-empty-orb",children:e.jsx("img",{src:"/logo.svg",alt:"deepseekcode",className:"relative h-10 w-10"})}),e.jsx("h2",{className:"text-xl font-semibold tracking-tight mb-2",children:h("chat.welcome")}),e.jsx("p",{className:"text-dark-muted text-sm mb-8",children:h("chat.welcomeDesc")}),a&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2.5 text-left",children:se.map(M=>e.jsxs("button",{onClick:()=>a(M.prompt),className:"ui-card-interactive group w-full px-4 py-3.5 text-left",children:[e.jsx(M.icon,{size:16,"aria-hidden":"true",className:"text-accent-blue mb-2"}),e.jsx("div",{className:"text-[13px] font-medium text-dark-text",children:M.label}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-dark-muted line-clamp-2",children:M.prompt})]},M.label))})]})]}):e.jsx("div",{className:"chat-stack flex flex-col pb-8 pt-5",children:C.map((M,W)=>{const z=C[W-1],$=z?z.type===M.type?"mt-2":"mt-5":"";return e.jsxs("div",{"data-mid":M.id,ref:H,className:`relative w-full ${$}`,children:[y===M.id&&e.jsx("div",{className:"animate-rail-flash pointer-events-none absolute inset-0"},k),e.jsx(lo,{message:M,sessionId:r,onRegenerate:l,onDeleteMessage:c,onOpenSidebarView:d})]},M.id)})}),n&&!A&&e.jsx(po,{label:h("chat.thinkingEllipsis")},r)]}),B.length>0&&e.jsx(ho,{items:B,activeId:b,onJump:te}),!g&&C.length>0&&e.jsx("button",{type:"button",onClick:w,title:h("chat.backToBottom"),"aria-label":h("chat.backToBottom"),className:"absolute bottom-5 right-5 z-20 flex h-8 w-8 animate-fade-in-up items-center justify-center rounded-full border border-dark-border/70 bg-dark-surface/90 text-dark-muted shadow-lg backdrop-blur transition-all duration-200 hover:scale-110 hover:text-dark-text hover:shadow-xl",children:e.jsx(et,{size:15})})]})});function Ze(t){return t.recordId!==void 0?t.recordId:t.callId!==void 0?`${t.kind}\0call\0${t.callId}`:t.sourceSeq!==void 0?`${t.kind}\0seq\0${t.sourceSeq}`:`${t.kind}\0index\0${t.index}`}function xr(t){return t===null||!Number.isFinite(t)?"—":`${String(Math.round(t)).replace(/\B(?=(\d{3})+(?!\d))/g,",")} ms`}function $s(t){return xr(t===null?null:t*1e3)}const bo=2048,ko=512;function vo(t){return t.replace(/```[^\n]*\n([\s\S]*?)```/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/!\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/^#{1,6}\s+/gm,"").replace(/^[ \t]*[-*+]\s+/gm,"").replace(/^[ \t]*>\s?/gm,"").replace(/(\*\*|__)(.*?)\1/g,"$2").replace(/(\*|_)(.*?)\1/g,"$2").replace(/~~(.*?)~~/g,"$1")}function Pt(t){const s=t.slice(0,bo),n=vo(s).replace(/\s+/g," ").trim(),r=n.slice(0,ko).trimEnd();return s.length<t.length||r.length<n.length?`${r}…`:r}function pn(t){if(Number.isFinite(t))return $s(t)}function at(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function jo(t){if(typeof t=="string")return t;try{return JSON.stringify(t,null,2)}catch{return""}}function Ms(t){if(typeof t=="string")return t;if(t==null)return"";try{return JSON.stringify(t,null,2)}catch{return String(t)}}function yo(t){if(t.status==="error")return{result:t.result===void 0?"error":Ms(t.result)};const s=Ms(t.result);return s===""?{result:"No output"}:{result:"",resultPreviewMarkdown:s}}function wo(t,s){var a;const n=(s==null?void 0:s.get(t.id))??null,r=((a=t.summary)==null?void 0:a.durationMs)!==void 0?(n??t.timestamp)+t.summary.durationMs:null,i=n!==null||r!==null;if(i)return{timingRecorded:i,stepStartTime:t.timestamp,firstTokenTime:n,completedTime:r,usageProvided:!1,outputTokens:null}}function No(t,s,n){var l;const r=t.thinkingBlocks?t.thinkingBlocks.map(c=>c.text).join(`
27
- `):t.thinking??"",i=wo(t,n),a=(l=t.summary)==null?void 0:l.durationMs;return{index:s,kind:"message",text:"",...t.content===""?{}:{previewMarkdown:t.content},sourceSeq:s,inputDetail:t.content,...r===""?{}:{thinkingDetail:r},...i===void 0?{}:{assistantMetrics:i},timeSeconds:a===void 0?null:a/1e3,startedAt:t.timestamp}}function gn(t,s){const n=jo(t.args),r=Ms(t.result),i=yo(t);return{index:s,kind:"tool",text:t.name,...n===""?{}:{previewMarkdown:n},sourceSeq:s,callId:t.id,...n===""?{}:{inputDetail:n},...r===""?{}:{outputDetail:r},...i,isError:t.status==="error",timeSeconds:t.duration??null,startedAt:t.timestamp}}function bn(t,s){return{index:s,kind:"user",text:"",...t.content===""?{}:{previewMarkdown:t.content},sourceSeq:s,inputDetail:t.content,opensTurn:!0,timeSeconds:0,startedAt:t.timestamp}}function So(t,s){const n=[t.originalCount!==void 0?`original ${t.originalCount} msgs`:"",t.compressedCount!==void 0?`compressed ${t.compressedCount} msgs`:"",t.tokensSaved!==void 0?`freed ${t.tokensSaved} tokens`:""].filter(Boolean).join(", ");return{index:s,kind:"compacted",text:"Context compressed",sourceSeq:t.seq,...n===""?{}:{outputDetail:n},timeSeconds:0,startedAt:t.timestamp}}function Eo(t){var i;const s=[],n=[];for(const a of t)a.absTime===null||!Number.isFinite(a.absTime)||(n.push(a.absTime),a.cell.kind==="tool"&&a.cell.timeSeconds!==null&&Number.isFinite(a.cell.timeSeconds)&&n.push(a.absTime+a.cell.timeSeconds*1e3));if(n.length>=2){const a=pn((Math.max(...n)-Math.min(...n))/1e3);a!==void 0&&s.push(a)}else if(n.length===1){const a=(i=t.find(c=>c.absTime===n[0]))==null?void 0:i.cell.timeSeconds,l=a!=null?pn(a):void 0;l!==void 0&&s.push(l)}const r=new Map;for(const a of t)a.toolName===void 0||a.cell.kind!=="tool"||r.set(a.toolName,(r.get(a.toolName)??0)+1);for(const[a,l]of r)s.push(l>1?`${a}×${l}`:a);return s.length===0?void 0:s.join(" ")}function kn(t,s){const n=s.groups.map(({title:r,laid:i})=>{const a=Eo(i);return{title:r,...a!==void 0?{description:a}:{},cells:i.map(l=>l.cell)}});return{turn:t,groups:n}}function vn(t){return Math.min(...t.groups.flatMap(s=>s.cells.map(n=>n.index)),Number.POSITIVE_INFINITY)}function Mo(t){const{messages:s,compacted:n=[],ttft:r}=t,i=new Map,a=[];let l=0,c=0,d=null;const h=p=>{let b=i.get(p);return b===void 0&&(b={groups:[]},i.set(p,b)),b},u=(p,b)=>{const j=h(p).groups,y=j[j.length-1];if((y==null?void 0:y.title)==="Message"){y.laid.push(b);return}j.push({title:"Message",laid:[b]})},x=(p,b,j)=>{if(j.length===0)return;const y=h(p).groups,f=`Step ${b}`,k=y.find(D=>D.title===f);if(k!==void 0){k.laid.push(...j);return}y.push({title:f,laid:[...j]})},g=[...s.map(p=>({kind:"message",message:p})),...n.map(p=>({kind:"compacted",record:p}))].sort((p,b)=>{const j=p.kind==="message"?p.message.timestamp:p.record.timestamp,y=b.kind==="message"?b.message.timestamp:b.record.timestamp;return j-y});for(const p of g){if(p.kind==="compacted"){const f=So(p.record,++l);a.push({groups:[{title:`Compaction ${p.record.seq}`,laid:[{absTime:at(p.record.timestamp),cell:f}]}]});continue}const b=p.message;if(Vn(b)){c+=1;const f=bn(b,++l);u(c,{absTime:at(b.timestamp),cell:f});continue}const j=c>0?c:d??1,y=za(b)?bn(b,++l):No(b,++l,r);u(j,{absTime:at(b.timestamp),cell:y}),d=j;for(const f of b.toolCalls??[]){const k=gn(f,++l);u(j,{absTime:at(f.timestamp),toolName:f.name,callId:f.id,cell:k})}for(const[f,k]of(b.steps??[]).entries()){const D=(k.toolCalls??[]).map(S=>{const N=gn(S,++l);return{absTime:at(S.timestamp),toolName:S.name,callId:S.id,cell:N}});x(j,f+1,D)}}return[...[...i.entries()].map(([p,b])=>kn(p,b)),...a.map(p=>kn(null,p))].sort((p,b)=>vn(p)-vn(b))}function Ht(t){if(t.text!=="")return t.text;if(t.previewMarkdown!==void 0){const s=Pt(t.previewMarkdown);if(s!=="")return s}if(t.result!==void 0&&t.result!=="")return t.result;if(t.resultPreviewMarkdown!==void 0){const s=Pt(t.resultPreviewMarkdown);if(s!=="")return s}return t.kind}function us(t){return xr(t)}function fr(t){return t==="tool"||t==="subtool"?2:t==="message"||t==="compacted"?1:0}function jn(t){return t!=null&&Number.isFinite(t)}function Co(t){if(!jn(t.startedAt))return null;const s=jn(t.timeSeconds)?Math.max(0,t.timeSeconds*1e3):0;return{start:t.startedAt,end:t.startedAt+s}}function pr(t,s="sequence"){if(s!=="sequence")return To(t,s==="duration");const n=[],r=[];for(const i of t){const a=i.groups.flatMap(l=>l.cells.filter(c=>c.requestOnly!==!0));a.length!==0&&(i.turn!==null&&r.push({turn:i.turn,time:n.length}),n.push(...a.map((l,c)=>({start:n.length+c,end:n.length+c+1,index:l.index,isError:l.isError===!0,kind:l.kind,label:l.text,lane:fr(l.kind)}))))}return n.length===0?null:{start:0,end:n.length,spans:n,turnBoundaries:r}}function To(t,s){const n=t.flatMap(h=>{const u=h.groups.flatMap(x=>x.cells.flatMap(g=>{if(g.requestOnly===!0)return[];const p=Co(g);return p===null?[]:[{...p,index:g.index,isError:g.isError===!0,kind:g.kind,label:g.text,lane:fr(g.kind)}]}));return u.length===0?[]:[{turn:h.turn,rawSpans:u}]}),r=n.flatMap(h=>h.rawSpans);if(r.length===0)return null;const i=new Map;let a=0,l=null;for(const h of[...r].sort((u,x)=>u.start-x.start||u.end-x.end))s&&l!==null&&h.start>l&&(a+=h.start-l),i.set(h,a),l=l===null?h.end:Math.max(l,h.end);const c=[],d=[];for(const h of n){const u=h.rawSpans.map(x=>{const g=i.get(x)??0;return{...x,start:x.start-g,end:x.end-g}});c.push(...u),h.turn!==null&&d.push({turn:h.turn,time:Math.min(...u.map(x=>x.start))})}return{start:Math.min(...c.map(h=>h.start)),end:Math.max(...c.map(h=>h.end)),spans:c,turnBoundaries:d}}function Io(t,s,n="sequence"){const r=pr(t,n);return new Set(r==null?void 0:r.spans.filter(i=>i.start<=s.end&&i.end>=s.start).map(i=>i.index))}function Ao(t,s){return t.length===s.length&&t.every((n,r)=>n===s[r])}function Ro(t){if(t.previewMarkdown===void 0)return"";const s=Pt(t.previewMarkdown);return t.text===""?s:s===""?t.text:`${t.text} · ${s}`}function _o(t){return t.resultPreviewMarkdown===void 0?t.result??"":Pt(t.resultPreviewMarkdown)}function Do(t,s,n){const r=[...n.sourceBlocks??[],...n.outputBlocks??[]];return[t===null?"between turns":`turn ${t}`,s,n.kind,n.kind==="message"?"assistant":"",n.text,n.previewMarkdown??"",n.inputDetail??"",n.outputDetail??"",n.thinkingDetail??"",n.schemaDetail??"",n.result??"",n.resultPreviewMarkdown??"",n.callId??"",...r.flatMap(i=>[i.type,i.content,i.callId??"",i.toolName??"",i.imageAlt??""])]}class zo{constructor(){Tt(this,"entries",new Map);Tt(this,"layouts")}update(s){if(this.layouts===s)return!1;this.layouts=s;const n=new Set;for(const r of s)for(const i of r)for(const a of i.groups)for(const l of a.cells){if(l.requestOnly===!0)continue;const c=Ze(l),d=Do(i.turn,a.title,l),h=this.entries.get(c),u=h!==void 0&&Ao(h.sources,d)?h:{sources:d,text:[...d,Ro(l),_o(l)].join(`
28
- `).toLocaleLowerCase()};this.entries.set(c,u),n.add(c)}for(const r of this.entries.keys())n.has(r)||this.entries.delete(r);return!0}search(s){const n=s.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return null;const r=new Set;for(const[i,a]of this.entries)n.every(l=>a.text.includes(l))&&r.add(i);return r}}const $o=o.memo(function({actualDuration:s,onActualDurationChange:n,allTurnsCollapsed:r,onToggleAllTurns:i,allAssistantsCollapsed:a,onToggleAllAssistants:l,searchQuery:c,onSearchQueryChange:d}){const{t:h}=ee();return e.jsxs("div",{className:"flex h-9 shrink-0 items-center gap-1 border-b border-dark-border/40 px-2",role:"toolbar",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":s,title:h(s?"trajectory.toolbar.equalWidth":"trajectory.toolbar.actualDuration"),onClick:()=>n(!s),children:[e.jsx(ys,{size:13}),h("trajectory.toolbar.duration")]}),e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":r,title:h(r?"trajectory.toolbar.expandTurns":"trajectory.toolbar.collapseTurns"),onClick:i,children:[r?e.jsx(sa,{size:13}):e.jsx(na,{size:13}),h("trajectory.toolbar.turns")]}),e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":a,title:h(a?"trajectory.toolbar.expandCalls":"trajectory.toolbar.collapseCalls"),onClick:l,children:[e.jsx(ra,{size:13}),h("trajectory.toolbar.calls")]}),e.jsx("div",{className:"ml-auto flex min-w-0 flex-1 items-center justify-end",children:e.jsxs("div",{className:"relative flex w-56 items-center",children:[e.jsx(ft,{size:12,className:"pointer-events-none absolute left-2 text-dark-muted/50"}),e.jsx("input",{type:"search",className:"h-7 w-full rounded border border-dark-border/40 bg-dark-surface/60 pl-7 pr-2 text-xs text-dark-text outline-none placeholder:text-dark-muted/40 focus:border-accent-blue/50","aria-label":h("trajectory.toolbar.search"),placeholder:h("trajectory.toolbar.searchPlaceholder"),value:c,onChange:u=>d(u.currentTarget.value)})]})})]})}),Oo=3,Po=500;function Lo(t){const s=t==null?void 0:t.stepStartTime,n=t==null?void 0:t.firstTokenTime,r=t==null?void 0:t.completedTime;return(t==null?void 0:t.timingRecorded)!==!0||typeof s!="number"||typeof n!="number"||typeof r!="number"||!Number.isFinite(s)||!Number.isFinite(n)||!Number.isFinite(r)||n<s||r<n?{}:{ttftMs:n-s,decodingMs:r-n}}function Fo(t){const s=t.timeSeconds===null||!Number.isFinite(t.timeSeconds)?void 0:Math.max(0,t.timeSeconds*1e3),n=t.startedAt===null||!Number.isFinite(t.startedAt)?void 0:t.startedAt;return{...s===void 0?{}:{durationMs:s},...n===void 0?{}:{startedAt:n},...Lo(t.assistantMetrics)}}function Bo(t){switch(t){case"system":return"SYSTEM";case"user":return"USER";case"context":return"CONTEXT";case"compacted":return"COMPACTED";case"message":return"ASSISTANT";case"tool":return"TOOL";case"subtool":return"SUBTOOL"}}function hs(t){const s=new Date(t),n=i=>String(i).padStart(2,"0"),r=i=>String(i).padStart(3,"0");return`${n(s.getHours())}:${n(s.getMinutes())}:${n(s.getSeconds())}.${r(s.getMilliseconds())}`}function Ho(t,s){const n=Bo(t);if(s===void 0)return n;const r=s.durationMs===void 0?null:`Total ${us(s.durationMs)}`,i=s.startedAt===void 0?null:s.durationMs===void 0?`Started ${hs(s.startedAt)}`:`${hs(s.startedAt)} → ${hs(s.startedAt+s.durationMs)}`,a=s.ttftMs===void 0||s.decodingMs===void 0?null:`TTFT ${us(s.ttftMs)} · Decoding ${us(s.decodingMs)}`,l=[r,a].filter(c=>c!==null).join(" · ");return[n,i,l].filter(c=>c!==null&&c!=="").join(`
29
- `)}function Ko(t,s){return t<=s?{start:t,end:s}:{start:s,end:t}}function qo(t){return Math.min(1,Math.max(0,t))}const Wo=o.memo(function({turns:s,mode:n,range:r,selectedIndex:i=null,searchMatchIndexes:a=null,onRangeChange:l,onRecordSelect:c}){const d=o.useMemo(()=>pr(s,n),[n,s]),h=o.useMemo(()=>new Map(s.flatMap(w=>w.groups.flatMap(U=>U.cells.map(Q=>[Q.index,Fo(Q)])))),[s]),u=o.useMemo(()=>new Map(s.flatMap(w=>w.groups.flatMap(U=>U.cells.map(Q=>[Q.index,Ht(Q)])))),[s]),x=o.useRef(null),g=o.useRef(null),[p,b]=o.useState(null),[j,y]=o.useState(null),f=o.useRef(null),[k,D]=o.useState(null);if(o.useEffect(()=>{d!==null&&r!==null&&(r.end<d.start||r.start>d.end)&&l(null)},[d,l,r]),o.useEffect(()=>{d!==null&&D(w=>w!==null&&(w.end<d.start||w.start>d.end)?null:w)},[d]),d===null)return e.jsxs("div",{className:"traj-root","data-empty":"",children:[e.jsxs("div",{className:"traj-labels","aria-hidden":"true",children:[e.jsx("span",{children:"Input"}),e.jsx("span",{children:"Model"}),e.jsx("span",{children:"Tools"})]}),e.jsx("div",{className:"traj-track"})]});const S=Math.max(1,d.end-d.start),N=(k==null?void 0:k.start)??d.start,R=k===null?S:Math.max(1,k.end-k.start),O=w=>{const U=x.current;if(!U)return 0;const Q=U.getBoundingClientRect();return qo((w-Q.left)/Math.max(1,Q.width))},C=w=>N+w*R,A=w=>{if(w.button===2){l(null);return}const Q=w.target.closest("[data-timeline-record-index]"),se=Q===null?null:Number(Q.dataset.timelineRecordIndex);if(se!==null&&Number.isFinite(se)){c==null||c(se);return}g.current={pointerId:w.pointerId,anchorFraction:O(w.clientX),anchorClientX:w.clientX,recordIndex:null},w.currentTarget.setPointerCapture(w.pointerId)},B=w=>{const U=g.current;if(U!==null&&w.pointerId===U.pointerId){const W=O(w.clientX);if(Math.abs(w.clientX-U.anchorClientX)>=Oo){const z=C(U.anchorFraction),$=C(W);b(Ko(z,$))}return}const Q=O(w.clientX),se=w.target.closest("[data-timeline-record-index]"),M=se===null?null:Number(se.dataset.timelineRecordIndex);f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{y({fraction:Q,recordIndex:Number.isFinite(M)?M:null})},Po)},_=w=>{const U=g.current;U===null||w.pointerId!==U.pointerId||(g.current=null,p!==null&&(l(p),b(null)))},H=w=>{var U;((U=g.current)==null?void 0:U.pointerId)===w.pointerId&&(g.current=null,b(null))},G=w=>{if(d===null)return;const U=O(w.clientX),Q=C(U),se=w.deltaY<0?.75:1.35,M=Math.min(S,Math.max(1,R*se)),W=Math.min(Math.max(Q-M/2,d.start),d.end-M);D({start:W,end:W+M})},ne=o.useRef(()=>{});ne.current=G,o.useEffect(()=>{const w=x.current;if(!w)return;const U=Q=>{Q.preventDefault(),ne.current(Q)};return w.addEventListener("wheel",U,{passive:!1}),()=>w.removeEventListener("wheel",U)},[d]);const te=p??r,V=j==null?void 0:j.recordIndex;return e.jsxs("div",{className:"traj-root",children:[e.jsxs("div",{className:"traj-labels","aria-hidden":"true",children:[e.jsx("span",{children:"Input"}),e.jsx("span",{children:"Model"}),e.jsx("span",{children:"Tools"})]}),e.jsxs("div",{ref:x,className:"traj-track",role:"slider","aria-label":"Trajectory timeline",tabIndex:0,onKeyDown:w=>{w.key==="Escape"&&l(null)},onPointerDown:A,onPointerMove:B,onPointerUp:_,onPointerCancel:H,onPointerLeave:()=>{f.current&&clearTimeout(f.current),f.current=null,g.current===null&&y(null)},onDoubleClick:w=>{w.preventDefault(),l(null)},onContextMenu:w=>{w.preventDefault(),l(null)},children:[j!==null&&j.recordIndex===null&&p===null&&e.jsx("div",{className:"traj-hoverLine","aria-hidden":"true",style:{"--trajectory-hover-left":`${j.fraction*100}%`}}),te!==null&&e.jsx("div",{className:"traj-selection","data-dragging":p===null?void 0:"true","aria-hidden":"true",style:{"--trajectory-selection-left":`${(te.start-N)/R*100}%`,"--trajectory-selection-width":`${(te.end-te.start)/R*100}%`}}),e.jsx("div",{className:"traj-turnBoundaries","aria-hidden":"true",children:d.turnBoundaries.filter(w=>w.time>d.start&&w.time>=N&&w.time<=N+R).map(w=>e.jsx("span",{className:"traj-turnBoundary","data-turn":w.turn,style:{"--trajectory-turn-left":`${(w.time-d.start)/S*100}%`}},w.turn))}),e.jsx("div",{className:"traj-lanes","data-timeline-domain":"",children:d.spans.filter(w=>w.index===i||w.end>=N&&w.start<=N+R).map(w=>{const U=(w.start-d.start)/S,se=(w.end-w.start)/S*100,M=h.get(w.index),W=M==null?void 0:M.ttftMs,z=M==null?void 0:M.decodingMs,$=W===void 0||z===void 0||W+z<=0?null:W/(W+z),K=u.get(w.index)??w.label;return e.jsx("span",{"aria-hidden":"true",className:"traj-span","data-timeline-span":w.kind,"data-timeline-record-index":w.index,"data-assistant-timing":$===null?void 0:"true","data-error":w.isError||void 0,"data-current":w.index===i||void 0,"data-hovered":V===w.index||void 0,"data-search-match":a===null?void 0:a.has(w.index)?"true":"false","data-selected":te===null?void 0:w.start<=te.end&&w.end>=te.start?"true":"false",title:Ho(w.kind,M),style:{"--trajectory-span-left":`${U*100}%`,"--trajectory-span-width":`${se}%`,"--trajectory-span-lane":w.lane,...$===null?{}:{"--trajectory-assistant-ttft":`${$*100}%`}},children:K},w.index)})})]})]})});function Uo(t,s,n){const r=new Array(t);return new Proxy(r,{get(i,a,l){if(typeof a=="string"){const c=a.charCodeAt(0);if(c>=48&&c<=57){const d=+a;if(Number.isInteger(d)&&d>=0&&d<t){let h=i[d];if(!h){const u=s[d*2];h=i[d]={index:d,key:n(d),start:u,size:s[d*2+1],end:u+s[d*2+1],lane:0}}return h}}if(a==="length")return t}return Reflect.get(i,a,l)}})}function Xe(t,s,n){let r=n.initialDeps??[],i,a=!0;function l(){const c=t();return(c.length!==r.length||c.some((h,u)=>r[u]!==h))&&(r=c,i=s(...c),n!=null&&n.onChange&&!(a&&n.skipInitialOnChange)&&n.onChange(i),a=!1),i}return l.updateDeps=c=>{r=c},l}function yn(t,s){if(t===void 0)throw new Error("Unexpected undefined");return t}const Go=(t,s)=>Math.abs(t-s)<1.01,Jo=(t,s,n)=>{let r;return Object.assign(function(...i){t.clearTimeout(r),r=t.setTimeout(()=>s.apply(this,i),n)},{cancel:()=>{t.clearTimeout(r)}})};let it;const ms=()=>{if(it!==void 0)return it;if(typeof navigator>"u")return it=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return it=!0;const t=navigator.maxTouchPoints;return it=navigator.platform==="MacIntel"&&t!==void 0&&t>0},wn=t=>{const{offsetWidth:s,offsetHeight:n}=t;return{width:s,height:n}},Vo=t=>t,Xo=t=>{const s=Math.max(t.startIndex-t.overscan,0),r=Math.min(t.endIndex+t.overscan,t.count-1)-s+1,i=new Array(r);for(let a=0;a<r;a++)i[a]=s+a;return i},Qo=(t,s)=>{const n=t.scrollElement;if(!n)return;const r=t.targetWindow;if(!r)return;const i=l=>{const{width:c,height:d}=l;s({width:Math.round(c),height:Math.round(d)})};if(i(wn(n)),!r.ResizeObserver)return()=>{};const a=new r.ResizeObserver(l=>{const c=()=>{const d=l[0];if(d!=null&&d.borderBoxSize){const h=d.borderBoxSize[0];if(h){i({width:h.inlineSize,height:h.blockSize});return}}i(wn(n))};t.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return a.observe(n,{box:"border-box"}),()=>{a.unobserve(n)}},Lt={passive:!0},Yo=typeof window>"u"?!0:"onscrollend"in window,Zo=(t,s,n)=>{const r=t.scrollElement;if(!r)return;const i=t.targetWindow;if(!i)return;const a=t.options.useScrollendEvent&&Yo;let l=0;const c=a?null:Jo(i,()=>s(l,!1),t.options.isScrollingResetDelay),d=x=>()=>{l=n(r),c==null||c(),s(l,x)},h=d(!0),u=d(!1);return r.addEventListener("scroll",h,Lt),a&&r.addEventListener("scrollend",u,Lt),()=>{r.removeEventListener("scroll",h),a&&r.removeEventListener("scrollend",u),c==null||c.cancel()}},el=(t,s)=>Zo(t,s,n=>{const{horizontal:r,isRtl:i}=t.options;return r?n.scrollLeft*(i&&-1||1):n.scrollTop}),tl=(t,s,n)=>{if(n.options.useCachedMeasurements){const r=n.indexFromElement(t),i=n.options.getItemKey(r);return n.itemSizeCache.get(i)??n.options.estimateSize(r)}if(s!=null&&s.borderBoxSize){const r=s.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!s){const r=n.indexFromElement(t),i=n.options.getItemKey(r),a=n.itemSizeCache.get(i);if(a!==void 0)return a}return t[n.options.horizontal?"offsetWidth":"offsetHeight"]},sl=(t,{adjustments:s=0,behavior:n},r)=>{var i,a;(a=(i=r.scrollElement)==null?void 0:i.scrollTo)==null||a.call(i,{[r.options.horizontal?"left":"top"]:t+s,behavior:n})},nl=sl;class rl{constructor(s){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._flatMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._intendedScrollOffset=null,this.elementsCache=new Map,this.now=()=>{var n,r,i;return((i=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:i.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(i=>{i.forEach(a=>{const l=()=>{const c=a.target,d=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[h,u]of this.elementsCache)if(u===c){this.elementsCache.delete(h);break}return}this.isIndexInRange(d)&&this.shouldMeasureDuringScroll(d)&&this.resizeItem(d,this.options.measureElement(c,a,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()})}));return{disconnect:()=>{var i;(i=r())==null||i.disconnect(),n=null},observe:i=>{var a;return(a=r())==null?void 0:a.observe(i,{box:"border-box"})},unobserve:i=>{var a;return(a=r())==null?void 0:a.unobserve(i)}}})(),this.range=null,this.setOptions=n=>{var r,i;const a={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Vo,rangeExtractor:Xo,onChange:()=>{},measureElement:tl,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const g in n){const p=n[g];p!==void 0&&(a[g]=p)}const l=this.options;let c=null,d=null,h=!1;if(l!==void 0&&l.enabled&&a.enabled&&a.anchorTo==="end"&&this.scrollElement!==null){const g=l.count,p=a.count,b=this.getMeasurements(),j=g>0?((r=b[0])==null?void 0:r.key)??l.getItemKey(0):null,y=g>0?((i=b[g-1])==null?void 0:i.key)??l.getItemKey(g-1):null;if(p!==g||g>0&&p>0&&(a.getItemKey(0)!==j||a.getItemKey(p-1)!==y)){h=!0;const D=g>0?this.getVirtualItemForOffset(this.getScrollOffset())??b[0]:null;D&&(c=[D.key,this.getScrollOffset()-D.start]);const S=a.followOnAppend===!0?"auto":a.followOnAppend||null;S&&p>g&&this.isAtEnd(l.scrollEndThreshold)&&(g===0||a.getItemKey(p-1)!==y)&&(d=S)}}this.options=a,h&&(this.pendingMin=0,this.itemSizeCacheVersion++);let u=!1,x=0;if(c&&this.scrollOffset!==null){const[g,p]=c,b=this.getMeasurements(),{count:j,getItemKey:y}=this.options;let f=0;for(;f<j&&y(f)!==g;)f++;if(f<j){const k=b[f];if(k){const D=Math.max(0,k.start+p);D!==this.scrollOffset&&(x=D-this.scrollOffset,this.scrollOffset=D,u=!0)}}}(u||d)&&(this.pendingScrollAnchor=[u?c[0]:null,u?c[1]:0,d,x])},this.notify=n=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,n)},this.maybeNotify=Xe(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),n=>{this.notify(n)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(n=>n()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.isScrolling=!1,this.scrollDirection=null,this._iosDeferredAdjustment=0,this._iosTouching=!1,this._iosJustTouchEnded=!1,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var n;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}if(this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((n=this.scrollElement)==null?void 0:n.window)??null,this.elementsCache.forEach(a=>{this.observer.observe(a)}),this.unsubs.push(this.options.observeElementRect(this,a=>{this.scrollRect=a,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(a,l)=>{if(l&&this._intendedScrollOffset===null&&a===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(a-this._intendedScrollOffset)<1.5&&(a=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const c=this.getScrollOffset();this.scrollDirection=l?c===a?this.scrollDirection:c<a?"forward":"backward":null,this.scrollOffset=a,this.isScrolling=l,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const a=this.scrollElement,l=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},c=()=>{this._iosTouching=!1,!(!ms()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};a.addEventListener("touchstart",l,Lt),a.addEventListener("touchend",c,Lt),this.unsubs.push(()=>{a.removeEventListener("touchstart",l),a.removeEventListener("touchend",c),this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)})}this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}const i=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,i&&this.scrollElement&&this.options.enabled){const[a,l,c,d]=i;a!==null&&!c&&(ms()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?d!==0&&(this._iosDeferredAdjustment+=d):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),c&&this.scrollToEnd({behavior:c})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;if(this._iosDeferredAdjustment<0&&n>=r-1){this._iosDeferredAdjustment=0;return}const i=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=i,behavior:void 0})},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=Xe(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap],(n,r,i,a,l,c,d,h)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:i,getItemKey:a,enabled:l,lanes:c,laneAssignmentMode:d,gap:h}),{key:!1}),this.isIndexInRange=n=>n>=0&&n<this.options.count,this.getMeasurements=Xe(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:i,getItemKey:a,enabled:l,lanes:c,laneAssignmentMode:d,gap:h},u)=>{const x=this.itemSizeCache;if(!l)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const f of this.laneAssignments.keys())f>=n&&this.laneAssignments.delete(f);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(f=>{this.itemSizeCache.set(f.key,f.size)}));const g=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),c===1){const f=n*2;let k=this._flatMeasurements;if(!k||k.length<f){const N=new Float64Array(f);k&&g>0&&N.set(k.subarray(0,g*2)),k=N,this._flatMeasurements=k}let D;if(g===0)D=r+i;else{const N=g-1;D=k[N*2]+k[N*2+1]+h}for(let N=g;N<n;N++){const R=a(N),O=x.get(R),C=typeof O=="number"?O:this.options.estimateSize(N);k[N*2]=D,k[N*2+1]=C,D+=C+h}const S=Uo(n,k,a);return this.measurementsCache=S,S}const p=this.measurementsCache.slice(0,g),b=new Array(c).fill(void 0),j=new Float64Array(c);let y=0;for(let f=0;f<g;f++){const k=p[f];k&&(b[k.lane]===void 0&&y++,b[k.lane]=f,j[k.lane]=k.end)}for(let f=g;f<n;f++){const k=a(f),D=this.laneAssignments.get(f);let S,N;const R=d==="estimate"||x.has(k);if(D!==void 0&&this.options.lanes>1){S=D;const B=b[S],_=B!==void 0?p[B]:void 0;N=_?_.end+h:r+i}else if(y===c){let B=0,_=j[0],H=b[0];for(let G=1;G<c;G++){const ne=j[G];(ne<_||ne===_&&b[G]<H)&&(B=G,_=ne,H=b[G])}S=B,N=_+h,R&&this.laneAssignments.set(f,S)}else S=f%this.options.lanes,N=r+i,R&&this.laneAssignments.set(f,S);const O=x.get(k),C=typeof O=="number"?O:this.options.estimateSize(f),A=N+C;p[f]={index:f,start:N,size:C,end:A,key:k,lane:S},b[S]===void 0&&y++,b[S]=f,j[S]=A}return this.measurementsCache=p,p},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Xe(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,i,a)=>n.length===0||r===0?(this.range=null,null):(this.range=il(n,r,i,a,a===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Xe(()=>{let n=null,r=null;const i=this.calculateRange();return i&&(n=i.startIndex,r=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,i,a,l)=>a===null||l===null?[]:n({startIndex:a,endIndex:l,overscan:r,count:i}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,i=n.getAttribute(r);return i?parseInt(i,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=n=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const i=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(i!==void 0&&this.range){const a=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),l=Math.max(0,i-a),c=Math.min(this.options.count-1,i+a);return n>=l&&n<=c}return!0},this.measureElement=n=>{if(!n){this.elementsCache.forEach((l,c)=>{l.isConnected||(this.observer.unobserve(l),this.elementsCache.delete(c))});return}const r=this.indexFromElement(n);if(!this.isIndexInRange(r))return;const i=this.options.getItemKey(r),a=this.elementsCache.get(i);a!==n&&(a&&this.observer.unobserve(a),this.observer.observe(n),this.elementsCache.set(i,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var i,a;if(!this.isIndexInRange(n))return;let l,c,d;const h=this._flatMeasurements;if(this.options.lanes===1&&h!==null)d=this.options.getItemKey(n),c=h[n*2],l=h[n*2+1];else{const g=this.measurementsCache[n];if(!g)return;d=g.key,c=g.start,l=g.size}const u=this.itemSizeCache.get(d)??l,x=r-u;if(x!==0){const g=this.options.anchorTo==="end"&&((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,p=g?this.getTotalSize():0,b=this.getScrollOffset()+this.scrollAdjustments,y=!this.itemSizeCache.has(d)?c<b:c+u<=b&&this.scrollDirection!=="backward",f=((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:d,start:c,size:l,end:c+l,lane:0},x,this):y);(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(d,r),this.itemSizeCacheVersion++;let k=!1;g?k=this.applyScrollAdjustment(this.getTotalSize()-p):f&&(k=this.applyScrollAdjustment(x)),this.notify(k)}},this.getVirtualItems=Xe(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const i=[];for(let a=0,l=n.length;a<l;a++){const c=n[a],d=r[c];i.push(d)}return i},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length===0)return;const i=this._flatMeasurements,a=this.options.lanes===1&&i!=null,l=gr(0,r.length-1,a?c=>i[c*2]:c=>yn(r[c]).start,n);return yn(r[l])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const n=this.scrollElement.document.documentElement;return this.options.horizontal?n.scrollWidth-this.scrollElement.innerWidth:n.scrollHeight-this.scrollElement.innerHeight}},this.getVirtualDistanceFromEnd=()=>Math.max(this.getTotalSize()-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(n=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=n,this.getOffsetForAlignment=(n,r,i=0)=>{if(!this.scrollElement)return 0;const a=this.getSize(),l=this.getScrollOffset();r==="auto"&&(r=n>=l+a?"end":"start"),r==="center"?n+=(i-a)/2:r==="end"&&(n-=a);const c=this.getMaxScrollOffset();return Math.max(Math.min(c,n),0)},this.getOffsetForIndex=(n,r="auto")=>{n=Math.max(0,Math.min(n,this.options.count-1));const i=this.getSize(),a=this.getScrollOffset(),l=this.measurementsCache[n];if(!l)return;if(r==="auto")if(l.end>=a+i-this.options.scrollPaddingEnd)r="end";else if(l.start<=a+this.options.scrollPaddingStart)r="start";else return[a,r];if(r==="end"&&n===this.options.count-1)return[this.getMaxScrollOffset(),r];const c=r==="end"?l.end+this.options.scrollPaddingEnd:l.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(c,r,l.size),r]},this.scrollToOffset=(n,{align:r="start",behavior:i="auto"}={})=>{this._iosDeferredAdjustment=0;const a=this.getOffsetForAlignment(n,r),l=this.now();this.scrollState={index:null,align:r,behavior:i,startedAt:l,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:i="auto"}={})=>{this._iosDeferredAdjustment=0,n=Math.max(0,Math.min(n,this.options.count-1));const a=this.getOffsetForIndex(n,r);if(!a)return;const[l,c]=a,d=this.now();this.scrollState={index:n,align:c,behavior:i,startedAt:d,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const i=this.getScrollOffset()+n,a=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:a,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.scrollToEnd=({behavior:n="auto"}={})=>{if(this.options.count>0){this.scrollToIndex(this.options.count-1,{align:"end",behavior:n});return}this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:n})},this.getTotalSize=()=>{var n;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1){const a=r.length-1,l=this._flatMeasurements;l!=null?i=l[a*2]+l[a*2+1]:i=((n=r[a])==null?void 0:n.end)??0}else{const a=Array(this.options.lanes).fill(null);let l=r.length-1;for(;l>=0&&a.some(c=>c===null);){const c=r[l];a[c.lane]===null&&(a[c.lane]=c.end),l--}i=Math.max(...a.filter(c=>c!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const r=this.getMeasurements();for(const i of r)i&&this.itemSizeCache.has(i.key)&&n.push({index:i.index,key:i.key,start:i.start,size:i.size,end:i.end,lane:i.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:i})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:i,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(s)}applyScrollAdjustment(s,n){return s===0?!1:ms()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?(this._iosDeferredAdjustment+=s,!1):(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=s,behavior:n}),this.scrollOffset!==null&&(this.scrollOffset+=this.scrollAdjustments,this.scrollOffset<0&&(this.scrollOffset=0),this.scrollAdjustments=0),!0)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=r?r[0]:this.scrollState.lastTargetOffset,a=1,l=i!==this.scrollState.lastTargetOffset;if(!l&&Go(i,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=a){this.getScrollOffset()!==i&&this._scrollToOffset(i,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,l){const c=this.getSize()||600,d=Math.abs(i-this.getScrollOffset()),h=this.scrollState.behavior==="smooth"&&d>c;this.scrollState.lastTargetOffset=i,h||(this.scrollState.behavior="auto"),this._scrollToOffset(i,{adjustments:void 0,behavior:h?"smooth":"auto"})}this.scheduleScrollReconcile()}}const gr=(t,s,n,r)=>{for(;t<=s;){const i=(t+s)/2|0,a=n(i);if(a<r)t=i+1;else if(a>r)s=i-1;else return i}return t>0?t-1:0};function al(t,s,n){let r=0;for(;r<=s;){const i=(r+s)/2|0,a=t[i*2];if(a<n)r=i+1;else if(a>n)s=i-1;else return i}return r>0?r-1:0}function il(t,s,n,r,i){const a=t.length-1;if(t.length<=r)return{startIndex:0,endIndex:a};if(r===1&&i!==null){const h=al(i,a,n);let u=h;const x=n+s;for(;u<a&&i[u*2]+i[u*2+1]<x;)u++;return{startIndex:h,endIndex:u}}let c=gr(0,a,h=>t[h].start,n),d=c;if(r===1)for(;d<a&&t[d].end<n+s;)d++;else if(r>1){const h=Array(r).fill(0);for(;d<a&&h.some(x=>x<n+s);){const x=t[d];h[x.lane]=x.end,d++}const u=Array(r).fill(n+s);for(;c>=0&&u.some(x=>x>=n);){const x=t[c];u[x.lane]=x.start,c--}c=Math.max(0,c-c%r),d=Math.min(a,d+(r-1-d%r))}return{startIndex:c,endIndex:d}}const xs=typeof document<"u"?o.useLayoutEffect:o.useEffect;function ol({useFlushSync:t=!0,directDomUpdates:s=!1,directDomUpdatesMode:n="transform",...r}){const i=o.useReducer(u=>u+1,0)[1],a=o.useRef({enabled:s,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=s,a.current.mode=n;const l=u=>{const x=a.current;if(!x.enabled||!x.container)return;const g=u.getTotalSize();if(g!==x.lastSize){x.lastSize=g;const p=u.options.horizontal?"width":"height";x.container.style[p]=`${g}px`}},c=u=>{const x=a.current;if(!x.enabled||!x.container)return;l(u);const g=!!u.options.horizontal,p=x.mode==="transform",b=g?"left":"top",j=u.options.scrollMargin,y=u.getVirtualItems();for(const f of y){const k=f.start-j,D=u.elementsCache.get(f.key);D&&x.lastPositions.get(D)!==k&&(x.lastPositions.set(D,k),p?D.style.transform=g?`translate3d(${k}px, 0, 0)`:`translate3d(0, ${k}px, 0)`:D.style[b]=`${k}px`)}},d={...r,onChange:(u,x)=>{var g;const p=a.current;let b=!0;if(p.enabled){c(u);const j=u.range,y=p.prevRange;b=!y||y.isScrolling!==u.isScrolling||y.startIndex!==(j==null?void 0:j.startIndex)||y.endIndex!==(j==null?void 0:j.endIndex),b&&(p.prevRange=j?{startIndex:j.startIndex,endIndex:j.endIndex,isScrolling:u.isScrolling}:null)}b&&(t&&x?Xn.flushSync(i):i()),(g=r.onChange)==null||g.call(r,u,x)}},[h]=o.useState(()=>{const u=new rl(d);return Object.assign(u,{containerRef:x=>{const g=a.current;if(g.container=x,g.lastSize=null,x&&g.enabled){const p=u.getTotalSize();g.lastSize=p;const b=u.options.horizontal?"width":"height";x.style[b]=`${p}px`}}})});return h.setOptions(d),xs(()=>h._didMount(),[]),xs(()=>(l(h),h._willUpdate())),xs(()=>{c(h)}),h}function ll(t){return ol({observeElementRect:Qo,observeElementOffset:el,scrollToFn:nl,...t})}const cl=30,dl=20,ul=9;function Ft(t){const s=encodeURIComponent(Ze(t.cell));return t.collapsedSummaryKind===void 0?s:`${s}\0summary\0${t.collapsedSummaryKind}`}function hl(t){const s=[];let n=[];for(const[r,i]of t.entries()){const a={logicalIndex:r,record:i};if(i.cell.requestOnly===!0){n.push(a);continue}const l=[...n,a];n=[],s.push({entries:l,height:i.collapsedSummaryKind===void 0?cl:dl,key:Ft(i)})}return n.length>0&&s.push({entries:n,height:ul,key:n.map(r=>Ft(r.record)).join("|")}),s}const ml=["Input","Output","Think","Time"],xl=o.memo(function({turn:s}){return e.jsxs("div",{className:"sticky top-0 z-10 flex h-[26px] items-center border-b border-dark-border/40 bg-dark-surface/95 px-2 backdrop-blur",children:[e.jsxs("span",{className:"text-[11px] font-semibold text-dark-text",children:["Turn ",s]}),e.jsx("div",{className:"ml-auto flex items-center gap-3 pr-1 text-[10px] text-dark-muted/50","aria-hidden":"true",children:ml.map(n=>e.jsx("span",{className:"w-12 text-right",children:n},n))})]})}),fl=o.memo(function({title:s,description:n}){return e.jsxs("div",{className:"flex h-[22px] items-center gap-2 px-2 text-[11px]",children:[e.jsx("span",{className:"font-medium text-dark-muted",children:s}),n!==void 0&&n!==""&&e.jsx("span",{className:"truncate text-dark-muted/50",children:n})]})}),pl={system:"System",user:"User",context:"Context",compacted:"Compacted",message:"Message",tool:"Tool",subtool:"Sub"},gl={system:"bg-dark-surface text-dark-muted border-dark-border/40",user:"bg-accent-blue/10 text-accent-blue border-accent-blue/30",context:"bg-dark-surface text-dark-muted border-dark-border/40",compacted:"bg-amber-500/10 text-amber-500 border-amber-500/30",message:"bg-accent-green/10 text-accent-green border-accent-green/30",tool:"bg-accent-purple/10 text-accent-purple border-accent-purple/30",subtool:"bg-dark-surface text-dark-muted border-dark-border/40"},bl=o.memo(function({cell:s,selected:n=!1,onClick:r}){const{index:i,kind:a,timeSeconds:l,input:c,output:d,think:h}=s,u=Ht(s),x=a==="message";return e.jsxs("div",{className:["flex h-[30px] items-center gap-2 border-b border-dark-border/20 px-2 text-xs cursor-pointer select-none",n?"bg-accent-blue/10":"hover:bg-dark-surface/40"].join(" "),"data-kind":a,"data-selected":n||void 0,onClick:()=>r==null?void 0:r(i),children:[e.jsxs("span",{className:"w-10 shrink-0 text-right tabular-nums text-dark-muted/50",children:["#",i]}),e.jsx("span",{className:"w-[74px] shrink-0",children:e.jsx("span",{className:["inline-block rounded border px-1 py-px text-[10px] leading-none",gl[a]].join(" "),children:pl[a]})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-text",title:u,children:u}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2 tabular-nums text-dark-muted/60",children:[x&&e.jsxs(e.Fragment,{children:[c!==void 0&&e.jsx("span",{title:"Input tokens",children:c}),d!==void 0&&e.jsx("span",{title:"Output tokens",children:d}),h!==void 0&&e.jsx("span",{title:"Reasoning tokens",children:h})]}),e.jsx("span",{className:"w-16 text-right",children:$s(l)})]})]})}),kl=100,vl=12,jl=600,yl=2;function wl(t){const s=o.useRef({rows:[],structure:[]});if(s.current.rows===t)return s.current.structure;const n=s.current.structure.length===t.length&&t.every((r,i)=>{const a=s.current.structure[i];return(a==null?void 0:a.key)===r.key&&a.height===r.height})?s.current.structure:t.map(r=>({key:r.key,height:r.height}));return s.current={rows:t,structure:n},n}function Nl(t){const s=[];for(const n of t){const r=[];for(const i of n.groups)i.cells.forEach((a,l)=>{r.push({turn:n.turn,group:i.title,groupDescription:i.description,groupStart:l===0,turnStart:r.length===0,cell:a,turnEnd:!1})});if(r.length>0){const i=r[r.length-1];i&&(i.turnEnd=!0)}s.push(...r)}return s}function Sl(t,s){const n=[];let r=[],i=null;const a=()=>{if(r.length!==0){if(i!==null&&s.has(i)){const l=r.filter(d=>d.cell.requestOnly!==!0&&d.cell.kind!=="system"),c=r[0];n.push({...c,groupStart:!0,turnStart:!0,turnEnd:!0,collapsedSummary:`Turn ${i} · ${l.length} records`,collapsedSummaryKind:"turn",cell:{...c.cell,index:c.cell.index}})}else n.push(...r);r=[],i=null}};for(const l of t)l.turnStart&&a(),i=l.turn,r.push(l);return a(),n}function El(t,s){var i;const n=[];let r=0;for(;r<t.length;){const a=t[r],l=t[r+1];if(a.cell.kind==="message"&&l!==void 0&&(l.cell.kind==="tool"||l.cell.kind==="subtool")&&s.has(Ze(a.cell))){let c=r+1;for(;c<t.length&&(t[c].cell.kind==="tool"||t[c].cell.kind==="subtool");)c+=1;const d=c-r-1;n.push({...a,groupStart:!0,turnEnd:((i=t[c-1])==null?void 0:i.turnEnd)??a.turnEnd,collapsedSummary:`${Ht(a.cell)||"Message"} · ${d} tool call${d>1?"s":""}`,collapsedSummaryKind:"assistant"}),r=c;continue}n.push(a),r+=1}return n}function Ml(t,s){const n=[];let r=null,i=null;for(const a of t)a.turnStart&&(r=a),a.groupStart&&(i=a),s.has(a.cell.index)&&(r!==null&&n.length===0&&(n.push({...r,groupStart:!0,turnStart:!0}),r=null),i!==null&&n.length>0&&n[n.length-1].group!==a.group&&(n.push({...i,groupStart:!0,turnStart:!1}),i=null),n.push(a));return n}function fs(t){if(t===null||!Number.isFinite(t))return"Not available";const s=new Date(t),n=l=>String(l).padStart(2,"0"),r=l=>String(l).padStart(3,"0"),i=`${n(s.getHours())}:${n(s.getMinutes())}:${n(s.getSeconds())}.${r(s.getMilliseconds())}`;return`${`${s.getFullYear()}-${n(s.getMonth()+1)}-${n(s.getDate())}`} ${i}`}function Cl(t){const s=[{id:"overview",label:"Summary"}];return t.inputDetail!==void 0&&t.inputDetail!==""&&s.push({id:"input",label:"Input"}),t.outputDetail!==void 0&&t.outputDetail!==""&&s.push({id:"output",label:"Output"}),t.thinkingDetail!==void 0&&t.thinkingDetail!==""&&s.push({id:"thinking",label:"Thinking"}),t.assistantMetrics!==void 0&&s.push({id:"timing",label:"Timing"}),(t.input!==void 0||t.output!==void 0||t.think!==void 0)&&s.push({id:"usage",label:"Usage"}),s}function Tl({cell:t,onClose:s}){var c;const n=Cl(t),[r,i]=o.useState(((c=n[0])==null?void 0:c.id)??"overview"),a=Ht(t),l=()=>{switch(r){case"overview":return e.jsxs("dl",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Kind"}),e.jsx("dd",{className:"traj-detailValue",children:t.kind})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Index"}),e.jsxs("dd",{className:"traj-detailValue",children:["#",t.index]})]}),t.callId!==void 0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Call ID"}),e.jsx("dd",{className:"traj-detailValue break-all",children:t.callId})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Duration"}),e.jsx("dd",{className:"traj-detailValue",children:$s(t.timeSeconds)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Started"}),e.jsx("dd",{className:"traj-detailValue",children:fs(t.startedAt??null)})]}),t.isError===!0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-20 shrink-0",children:"Status"}),e.jsx("dd",{className:"traj-detailValue text-red-400",children:"error"})]}),a!==""&&e.jsxs("div",{className:"pt-1",children:[e.jsx("dt",{className:"traj-detailKey mb-1",children:"Summary"}),e.jsx("dd",{className:"traj-detailBody",children:a})]})]});case"input":return e.jsx("div",{className:"traj-detailBody",children:t.inputDetail});case"output":return e.jsx("div",{className:"traj-detailBody",children:t.outputDetail});case"thinking":return e.jsx("div",{className:"traj-detailBody",children:t.thinkingDetail});case"timing":{const d=t.assistantMetrics;if(!d)return null;const h=d.firstTokenTime!==null&&d.stepStartTime!==null?d.firstTokenTime-d.stepStartTime:null,u=d.completedTime!==null&&d.firstTokenTime!==null?d.completedTime-d.firstTokenTime:null;return e.jsxs("dl",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Step start"}),e.jsx("dd",{className:"traj-detailValue",children:fs(d.stepStartTime)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"First token"}),e.jsx("dd",{className:"traj-detailValue",children:fs(d.firstTokenTime)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"TTFT"}),e.jsx("dd",{className:"traj-detailValue",children:h===null?"—":`${h} ms`})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Decoding"}),e.jsx("dd",{className:"traj-detailValue",children:u===null?"—":`${u} ms`})]})]})}case"usage":return e.jsxs("dl",{className:"space-y-1.5",children:[t.input!==void 0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Input"}),e.jsx("dd",{className:"traj-detailValue",children:t.input})]}),t.output!==void 0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Output"}),e.jsx("dd",{className:"traj-detailValue",children:t.output})]}),t.think!==void 0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Reasoning"}),e.jsx("dd",{className:"traj-detailValue",children:t.think})]}),t.input===void 0&&t.output===void 0&&t.think===void 0&&e.jsx("div",{className:"traj-detailValue",children:"Token usage not reported by provider yet."})]});default:return null}};return e.jsxs("div",{className:"flex h-full w-[360px] shrink-0 flex-col border-l border-dark-border/40 bg-dark-surface/40",children:[e.jsxs("div",{className:"flex h-9 shrink-0 items-center justify-between border-b border-dark-border/40 px-3",children:[e.jsxs("span",{className:"text-xs font-medium text-dark-text",children:["Record #",t.index]}),e.jsx("button",{type:"button",className:"rounded p-1 text-dark-muted hover:bg-dark-surface/60",onClick:s,"aria-label":"Close details",children:e.jsx($e,{size:14})})]}),e.jsx("div",{className:"flex shrink-0 flex-wrap gap-1 border-b border-dark-border/40 px-2 py-1.5",children:n.map(d=>e.jsx("button",{type:"button",className:"traj-detailTab","data-active":r===d.id||void 0,onClick:()=>i(d.id),children:d.label},d.id))}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-3",children:l()})]})}function Il({turns:t,searchMatchIndexes:s=null,selectedIndex:n,onSelectIndex:r,onDeselect:i,onClearSelection:a,collapsedTurns:l,onToggleTurn:c,collapsedAssistants:d,onToggleAssistant:h}){var B;const u=o.useRef(null),x=o.useMemo(()=>Nl(t),[t]),g=o.useMemo(()=>n===null?void 0:x.find(_=>_.cell.index===n),[x,n]),p=o.useMemo(()=>{if(s!==null)return Ml(x,s);const _=l.size===0?x:Sl(x,l);return d.size===0?_:El(_,d)},[x,d,l,s]),b=o.useMemo(()=>hl(p),[p]),j=wl(b),y=p.length>kl,f=o.useCallback(_=>{var H;return((H=j[_])==null?void 0:H.height)??30},[j]),k=o.useCallback(_=>{var H;return((H=j[_])==null?void 0:H.key)??_},[j]),D=o.useCallback(()=>u.current,[]),S=ll({count:y?j.length:0,enabled:y,estimateSize:f,getItemKey:k,getScrollElement:D,initialRect:{width:0,height:jl},anchorTo:"end",overscan:vl,scrollEndThreshold:yl}),N=y?S.getVirtualItems():[],R=((B=N[0])==null?void 0:B.start)??0,O=y?S.getTotalSize():0,C=_=>{r(_)},A=_=>_.collapsedSummary!==void 0?e.jsxs("div",{className:"flex h-[20px] cursor-pointer items-center gap-2 px-2 text-xs text-dark-muted hover:bg-dark-surface/40",onClick:()=>{_.collapsedSummaryKind==="turn"&&_.turn!==null?c(_.turn):_.collapsedSummaryKind==="assistant"&&h(Ze(_.cell))},children:[e.jsx("span",{className:"text-dark-muted/50",children:"▸"}),e.jsx("span",{className:"truncate",children:_.collapsedSummary})]}):e.jsxs(e.Fragment,{children:[_.turnStart&&_.turn!==null&&e.jsx(xl,{turn:_.turn}),_.groupStart&&e.jsx(fl,{title:_.group,description:_.groupDescription}),e.jsx(bl,{cell:_.cell,selected:n===_.cell.index,onClick:C})]});return e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx("div",{ref:u,className:"min-w-0 flex-1 overflow-auto",onClick:_=>{_.target===_.currentTarget&&(a==null||a())},children:y?e.jsx("div",{style:{height:O,position:"relative"},children:N.map(_=>{const H=b[_.index];return H?e.jsx("div",{"data-virtual-row-key":H.key,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${_.start-R}px)`,height:H.height},children:H.entries.map(G=>e.jsx("div",{children:A(G.record)},Ft(G.record)))},H.key):null})}):p.map(_=>e.jsx("div",{children:A(_)},Ft(_)))}),g!==void 0&&e.jsx(Tl,{cell:g.cell,onClose:i},g.cell.index)]})}const Al=new Set,Rl=new Set,_l=3e3;function Dl({sessionId:t,messages:s}){const[n,r]=o.useState(Al),[i,a]=o.useState(Rl),[l,c]=o.useState(null),[d,h]=o.useState(!1),[u,x]=o.useState(""),[g]=o.useState(()=>new zo),[p,b]=o.useState(0),j=o.useRef(null),y=o.useRef(!1),[f,k]=o.useState(null),D=rn(z=>z.compactedBySession[t]??zl),S=rn(z=>z.ttftBySession[t]),N=o.useMemo(()=>{if(S!==void 0)return new Map(Object.entries(S))},[S]),R=o.useMemo(()=>Mo({messages:s,compacted:D,ttft:N}),[s,D,N]),O=d?"duration":"sequence";o.useEffect(()=>(j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{g.update([R]),b(z=>z+1),y.current=!0},y.current?_l:0),()=>{j.current&&clearTimeout(j.current)}),[R,g]);const C=o.useMemo(()=>u.trim()===""?null:g.search(u),[u,p]),A=o.useMemo(()=>{if(C===null)return null;const z=new Set;for(const $ of R)for(const K of $.groups)for(const Z of K.cells)C.has(Ze(Z))&&z.add(Z.index);return z},[R,C]),B=o.useMemo(()=>l===null?null:Io(R,l,O),[R,O,l]),_=o.useMemo(()=>R.filter(z=>z.turn!==null&&z.groups.reduce(($,K)=>$+K.cells.filter(Z=>Z.requestOnly!==!0&&Z.kind!=="system").length,0)>1).flatMap(z=>z.turn===null?[]:[z.turn]),[R]),H=_.length>0&&_.every(z=>n.has(z)),G=o.useMemo(()=>{const z=[];for(const $ of R){const K=$.groups.flatMap(Z=>Z.cells);for(let Z=0;Z<K.length;Z++){const oe=K[Z];if((oe==null?void 0:oe.kind)!=="message")continue;const ue=K[Z+1];((ue==null?void 0:ue.kind)==="tool"||(ue==null?void 0:ue.kind)==="subtool")&&z.push(Ze(oe))}}return z},[R]),ne=G.length>0&&G.every(z=>i.has(z)),te=o.useCallback(z=>{r($=>{const K=new Set($);return K.has(z)?K.delete(z):K.add(z),K})},[]),V=o.useCallback(()=>{r(z=>{const $=new Set(z);if(H)for(const K of _)$.delete(K);else for(const K of _)$.add(K);return $})},[H,_]),w=o.useCallback(z=>{a($=>{const K=new Set($);return K.has(z)?K.delete(z):K.add(z),K})},[]),U=o.useCallback(()=>{a(z=>{const $=new Set(z);if(ne)for(const K of G)$.delete(K);else for(const K of G)$.add(K);return $})},[ne,G]),Q=o.useCallback(z=>{c(z)},[]),se=o.useCallback(z=>{B!==null&&!B.has(z)&&c(null),k($=>$===z?null:z)},[B]),M=o.useCallback(()=>{k(null)},[]),W=o.useCallback(()=>{c(null),k(null)},[]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-conversation-composer-overlay":"",children:[e.jsx($o,{actualDuration:d,onActualDurationChange:z=>{h(z),c(null)},allTurnsCollapsed:H,onToggleAllTurns:V,allAssistantsCollapsed:ne,onToggleAllAssistants:U,searchQuery:u,onSearchQueryChange:x}),e.jsx(Wo,{turns:R,mode:O,range:l,selectedIndex:f,searchMatchIndexes:A,onRangeChange:Q,onRecordSelect:se}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Il,{turns:R,searchMatchIndexes:A,selectedIndex:f,onSelectIndex:se,onDeselect:M,onClearSelection:W,collapsedTurns:n,onToggleTurn:te,collapsedAssistants:i,onToggleAssistant:w})})]})}const zl=[],$l={plan:"border-accent-blue/30 text-accent-blue bg-accent-blue/10","auto-plan":"border-accent-cyan/30 text-accent-cyan bg-accent-cyan/10",act:"border-accent-green/30 text-accent-green bg-accent-green/10","auto-act":"border-accent-yellow/30 text-accent-yellow bg-accent-yellow/10",goal:"border-accent-purple/30 text-accent-purple bg-accent-purple/10","auto-goal":"border-accent-red/30 text-accent-red bg-accent-red/10",normal:"border-accent-green/30 text-accent-green"},Ol=o.memo(function(){const{t:s}=ee(),n=qe(d=>d.mode),r=qe(d=>d.setBaseMode),i=qe(d=>d.toggleAuto),a=n==="normal"?"act":n,l=_t(a),c=Ss(a);return e.jsxs("div",{className:"flex items-center gap-1",children:[$a.map(d=>{const h=l===d,u=Oa[d],x=n!=="normal"&&h?$l[n]??"border-dark-border text-dark-muted":"border-dark-border text-dark-muted hover:bg-dark-hover";return e.jsx("button",{type:"button",onClick:()=>r(d),className:de("px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",x),title:s("chat.clickToSwitchMode"),"aria-pressed":h,children:u.label},d)}),e.jsxs("button",{type:"button",role:"switch","aria-checked":c,onClick:()=>i(),className:de("flex items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",c?"border-accent-yellow/40 text-accent-yellow bg-accent-yellow/10":"border-dark-border text-dark-muted hover:bg-dark-hover"),title:s("plan.autoApprove"),children:[e.jsx(mt,{size:11,className:de(c?"text-accent-yellow":"text-dark-muted")}),e.jsx("span",{children:s("plan.autoApprove")})]})]})}),Nn={off:{labelKey:"chat.effortOff",color:"text-dark-muted"},low:{labelKey:"chat.effortLow",color:"text-accent-green"},medium:{labelKey:"chat.effortMedium",color:"text-accent-yellow"},high:{labelKey:"chat.effortHigh",color:"text-accent-red"},extra_high:{labelKey:"chat.effortExtraHigh",color:"text-accent-purple"},max:{labelKey:"chat.effortMax",color:"text-accent-blue"}},Pl=o.memo(function(){const{t:s}=ee(),n=ct(E=>E.model),r=ct(E=>E.modelRef),i=ct(E=>E.setModel),a=ct(E=>E.setModelRef),l=qe(E=>E.mode),c=Ot(E=>E.effort),d=Ot(E=>E.setEffort),[h,u]=o.useState([]),[x,g]=o.useState(!1),p=o.useRef(null),[b,j]=o.useState("global"),y=Qn(E=>E.activeSessionId),[f,k]=o.useState(!1),[D,S]=o.useState(""),[N,R]=o.useState(""),[O,C]=o.useState([]),[A,B]=o.useState(new Set),[_,H]=o.useState("none"),[G,ne]=o.useState(!1),[te,V]=o.useState(null),[w,U]=o.useState(null),Q=o.useMemo(()=>Array.from(new Set(h.map(E=>E.provider))),[h]),se=o.useCallback(async()=>{try{const E=await fe.models.list();E.success&&E.data&&Array.isArray(E.data.models)&&u(E.data.models.filter(re=>re.enabled!==!1))}catch{}},[]),M=o.useCallback(()=>{var re,F;const E=Pa(r)||((re=h.find(ve=>ve.isGlobalDefault))==null?void 0:re.provider)||((F=h[0])==null?void 0:F.provider)||"";S(E),R(""),V(null),k(!0)},[r,h]),W=o.useCallback(()=>{k(!1),C([]),V(null)},[]),z=o.useCallback(async(E,re)=>{if(E){ne(!0),V(null);try{const F=await fe.models.byProvider(E,re||void 0);F.success&&F.data?(C(F.data.models||[]),B(new Set(F.data.existing||[])),H(F.data.source)):(C([]),B(new Set),V(F.error||s("chat.loadModelsFailed")))}catch{C([]),B(new Set),V(s("chat.loadModelsFailed"))}finally{ne(!1)}}},[s]);o.useEffect(()=>{if(!f)return;const E=setTimeout(()=>{z(D,N)},N?300:0);return()=>clearTimeout(E)},[f,D,N,z]),o.useEffect(()=>{se()},[se]),o.useEffect(()=>{const E=()=>{se()};return window.addEventListener("models-updated",E),()=>window.removeEventListener("models-updated",E)},[se]);const $=o.useCallback(()=>g(!1),[]);o.useEffect(()=>{if(!x)return;const E=F=>{p.current&&!p.current.contains(F.target)&&$()},re=F=>{F.key==="Escape"&&$()};return document.addEventListener("mousedown",E),document.addEventListener("keydown",re),()=>{document.removeEventListener("mousedown",E),document.removeEventListener("keydown",re)}},[x,$]);const K=async E=>{if($(),b==="session"){if(!y)return;try{(await fe.models.setSessionModel(y,E.provider,E.id)).success&&(i(E.id),a(`${E.provider}:${E.id}`))}catch{}return}const re=_t(l==="normal"?"act":l),F=`${E.provider}:${E.id}`,ve=re==="plan"?{plan:F}:re==="goal"?{goal:F}:{global:F,act:F};try{(await fe.models.setDefaults(ve)).success&&(i(E.id),a(`${E.provider}:${E.id}`),await se())}catch{}},Z=async E=>{const re=A.has(E.id),F=`${D}:${E.id}`;U(E.id);try{if(!re){const ge=await fe.models.create({provider:D,model:{id:E.id,name:E.name||E.id}});if(!ge.success){V(ge.error||s("chat.addModelFailed"));return}}const ve=_t(l==="normal"?"act":l),we=ve==="plan"?{plan:F}:ve==="goal"?{goal:F}:{global:F,act:F},gt=await fe.models.setDefaults(we);gt.success?(i(E.id),a(F),W(),await se()):V(gt.error||s("chat.switchModelFailed"))}catch{V(s("chat.addModelFailed"))}finally{U(null)}},oe=_t(l==="normal"?"act":l),ue=oe==="plan"?"isPlanDefault":oe==="goal"?"isGoalDefault":"isActDefault",ae=E=>{const re=`${E.provider}:${E.id}`;if(r)return r===re;if(n===re)return!0;if(n!==E.id)return!1;const F=h.filter(we=>we.id===E.id);return F.length<=1?!0:(F.find(we=>we[ue]===!0)??F.find(we=>we.isGlobalDefault)??F[0])===E},le=h.some(E=>E[ue]===!0),T=h.find(E=>E.isGlobalDefault),X=async()=>{$();const E=oe==="plan"?{plan:null}:oe==="goal"?{goal:null}:{act:null};try{(await fe.models.setDefaults(E)).success&&(T?(i(T.id),a(`${T.provider}:${T.id}`)):(i(""),a("")),await se())}catch{}},ce=o.useMemo(()=>La(h),[h]),je=Fa(n,r),ye=Nn[c];return e.jsxs("div",{className:"relative min-w-0",ref:p,children:[e.jsxs("button",{type:"button",onClick:()=>g(E=>!E),className:"flex w-full items-center gap-1 px-2 py-0.5 rounded-full border border-dark-border text-dark-muted whitespace-nowrap transition-colors hover:bg-dark-hover cursor-pointer",title:je||s("chat.clickToSelectModel"),"aria-haspopup":"listbox","aria-expanded":x,children:[e.jsx(aa,{size:12,className:"shrink-0"}),e.jsx("span",{className:"font-medium max-w-[8rem] truncate",children:je||s("chat.selectModel")}),e.jsx("span",{className:"h-3 w-px bg-dark-border shrink-0","aria-hidden":"true"}),e.jsx(sn,{size:12,className:`shrink-0 ${ye.color}`}),e.jsx("span",{className:`text-xs font-medium ${ye.color}`,children:s(ye.labelKey)}),e.jsx(et,{size:12,className:de("transition-transform",x&&"rotate-180")})]}),x&&e.jsxs("div",{role:"listbox","aria-label":s("chat.selectModel"),className:"absolute bottom-full left-0 mb-1 z-50 min-w-[260px] bg-dark-surface border border-dark-border rounded-lg shadow-xl overflow-hidden",children:[e.jsx("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-dark-muted border-b border-dark-border",children:s("chat.selectModel")}),e.jsx("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-dark-border",children:[{key:"global",label:s("chat.applyScopeGlobal")},{key:"session",label:s("chat.applyScopeSession")}].map(({key:E,label:re})=>e.jsx("button",{type:"button",onClick:()=>j(E),title:E==="session"?s("chat.sessionScopeHint"):void 0,className:de("text-[11px] px-2 py-0.5 rounded-full border transition-colors cursor-pointer",b===E?"border-accent-blue text-accent-blue bg-accent-blue/10 font-medium":"border-dark-border text-dark-muted hover:text-dark-text hover:bg-dark-hover"),children:re},E))}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-2 py-1.5 border-b border-dark-border flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:W,title:s("chat.backToModels"),"aria-label":s("chat.backToModels"),className:"p-1 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text shrink-0",children:e.jsx(ia,{size:12})}),Q.length>1?e.jsx("select",{value:D,onChange:E=>S(E.target.value),"aria-label":s("chat.selectProvider"),className:"max-w-[9rem] min-w-0 bg-dark-surface text-dark-text text-xs px-1.5 py-1 rounded border border-dark-border focus:outline-none focus:border-accent-blue",children:Q.map(E=>e.jsx("option",{value:E,children:E},E))}):e.jsx("span",{className:"flex-1 min-w-0 text-xs font-medium text-dark-text truncate",children:D||s("chat.noConfiguredProviders")}),e.jsx("input",{value:N,onChange:E=>R(E.target.value),placeholder:s("chat.searchModels"),"aria-label":s("chat.searchModels"),className:"flex-1 min-w-0 bg-dark-bg text-dark-text text-xs px-2 py-1 rounded border border-dark-border placeholder-dark-muted/60 focus:outline-none focus:border-accent-blue"})]}),e.jsx("div",{className:"py-1 max-h-[32vh] overflow-y-auto custom-scrollbar",children:G?e.jsxs("div",{className:"px-3 py-2 text-xs text-dark-muted flex items-center gap-1.5",children:[e.jsx(oa,{size:11,className:"animate-spin"}),s("chat.loadingModels")]}):te?e.jsx("div",{className:"px-3 py-2 text-xs text-accent-red",children:te}):D?O.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:s(N?"chat.noModelsFound":"chat.noProviderModels")}):e.jsxs(e.Fragment,{children:[_!=="none"&&e.jsx("div",{className:"px-3 pt-1.5 pb-0.5 text-[10px] text-dark-muted/70",children:s(_==="provider-api"?"chat.modelsSourceProviderApi":"chat.modelsSourceCatalog")}),O.map(E=>{const re=A.has(E.id),F=r===`${D}:${E.id}`;return e.jsxs("button",{type:"button",role:"option","aria-selected":F,onClick:()=>Z(E),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors hover:bg-dark-hover",children:[e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-medium text-dark-text truncate",children:E.name||E.id}),F&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-green/20 text-accent-green shrink-0",children:s("chat.currentModel")})]}),e.jsx("span",{className:"block text-[10px] text-dark-muted truncate mt-0.5",children:E.id})]}),re?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green shrink-0",children:s("chat.alreadyAdded")}):e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue shrink-0 whitespace-nowrap",children:w===E.id?s("chat.addingModel"):s("chat.addAndSwitch")})]},E.id)})]}):e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:s("chat.noConfiguredProviders")})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"py-1 max-h-[32vh] overflow-y-auto custom-scrollbar",children:[le&&e.jsx("button",{type:"button",role:"option","aria-selected":!1,onClick:X,title:s("chat.followGlobalDefaultHint"),className:"w-full flex items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-dark-hover border-b border-dark-border/60",children:e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"text-xs font-semibold text-accent-green flex items-center gap-1.5",children:[e.jsx(la,{size:11}),s("chat.followGlobalDefault")]}),e.jsx("span",{className:"block text-[10px] text-dark-muted mt-0.5 truncate",children:T?T.name||T.id:s("chat.noGlobalDefault")})]})}),ce.map(([E,re])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-dark-border/60 bg-dark-bg/40",children:[e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-dark-muted truncate",children:E}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:re.length})]}),re.map(F=>{const ve=ae(F);return e.jsx("button",{type:"button",role:"option","aria-selected":ve,onClick:()=>K(F),className:de("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors",ve?"bg-dark-hover":"hover:bg-dark-hover"),children:e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:de("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",ve?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Ye,{size:11,strokeWidth:3})}),e.jsx("span",{className:"text-xs font-semibold text-dark-text truncate",children:F.name||F.id})]}),e.jsxs("span",{className:"flex items-center gap-1 mt-0.5 flex-wrap",children:[e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:F.id}),F.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-red/20 text-accent-red",children:s("chat.globalDefault")}),F.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-blue/20 text-accent-blue",children:s("chat.planDefault")}),F.isActDefault&&!F.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-yellow/20 text-accent-yellow",children:s("chat.actDefault")}),F.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-purple/20 text-accent-purple",children:s("chat.goalDefault")})]})]})},`${F.provider}:${F.id}`)})]},E)),h.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:s("chat.noEnabledModels")})]}),e.jsxs("button",{type:"button",onClick:M,className:"w-full flex items-center gap-2 px-3 py-2 text-left border-t border-dark-border/60 text-[11px] font-medium text-accent-blue transition-colors hover:bg-dark-hover",children:[e.jsx(ft,{size:11}),s("chat.browseMoreModels")]})]}),e.jsx("div",{className:"border-t border-dark-border","aria-hidden":"true"}),e.jsxs("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-dark-muted border-b border-dark-border flex items-center gap-1",children:[e.jsx(sn,{size:11}),s("chat.effort")]}),e.jsx("div",{className:"py-1",children:Ba.map(E=>{const re=Nn[E],F=E===c;return e.jsxs("button",{type:"button",role:"option","aria-selected":F,onClick:()=>{d(E),$()},className:de("w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors",F?"bg-dark-hover":"hover:bg-dark-hover"),children:[e.jsx("span",{className:de("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",F?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Ye,{size:11,strokeWidth:3})}),e.jsx("span",{className:`text-xs font-medium ${F?re.color:"text-dark-text"}`,children:s(re.labelKey)})]},E)})})]})]})});function Ll(t,s){if(!t)return s;const n=t.includes("\\")?"\\":"/";return t.endsWith(n)?t+s:t+n+s}function Fl(t){const s=t.replace(/[\\/]+$/,""),n=Math.max(s.lastIndexOf("\\"),s.lastIndexOf("/"));return n===-1?s:s.slice(n+1)}function Bl({initial:t,onClose:s,onConfirm:n}){const{t:r}=ee(),[i,a]=o.useState(t),[l,c]=o.useState(null),[d,h]=o.useState([]),[u,x]=o.useState(!1),[g,p]=o.useState(""),[b,j]=o.useState(t),y=o.useRef(null),f=o.useCallback(async S=>{x(!0),p("");try{const N=await fe.dirs.list(S);if(!N.success||!N.data){p(N.error||r("chat.dirPickerLoadError"));return}a(N.data.path),c(N.data.parent),h(N.data.dirs||[]),j(N.data.path)}catch(N){p(N instanceof Error?N.message:r("chat.dirPickerLoadError"))}finally{x(!1)}},[r]);o.useEffect(()=>{f(t)},[t,f]),o.useEffect(()=>{var S;(S=y.current)==null||S.focus()},[]),o.useEffect(()=>{const S=N=>{N.key==="Escape"&&(N.preventDefault(),N.stopPropagation(),s())};return document.addEventListener("keydown",S),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",S),document.body.style.overflow=""}},[s]);const k=o.useCallback(()=>{const S=b.trim();S&&f(S)},[b,f]),D=o.useCallback(()=>{l&&f(l)},[l,f]);return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center overflow-hidden p-4",role:"dialog","aria-modal":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:s}),e.jsxs("div",{className:"relative w-full max-w-lg mx-4 bg-dark-surface border border-dark-border rounded-xl shadow-2xl animate-fade-in flex flex-col max-h-[70vh]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-dark-border shrink-0",children:[e.jsxs("span",{className:"flex items-center gap-2 text-[13px] font-semibold text-dark-text",children:[e.jsx(Fn,{size:15,className:"text-accent-blue","aria-hidden":"true"}),r("chat.dirPickerTitle")]}),e.jsx("button",{type:"button",onClick:s,className:"rounded p-1 text-dark-muted hover:bg-dark-hover hover:text-dark-text transition-colors","aria-label":r("a11y.close"),children:e.jsx($e,{size:15,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"p-4 flex flex-col gap-3 min-h-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ca,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60","aria-hidden":"true"}),e.jsx("input",{ref:y,value:b,onChange:S=>j(S.target.value),onKeyDown:S=>{S.key==="Enter"&&k()},placeholder:r("chat.dirPickerEnterPath"),spellCheck:!1,className:`w-full rounded-lg border border-dark-border bg-dark-bg pl-8 pr-2.5 py-1.5 text-xs font-mono text-dark-text
30
- placeholder-dark-muted/50 focus:outline-none focus:border-accent-blue/50 focus:ring-2 focus:ring-accent-blue/10`})]}),e.jsx("button",{type:"button",onClick:k,disabled:u||!b.trim(),className:`shrink-0 rounded-lg border border-dark-border px-2.5 py-1.5 text-xs text-dark-muted
31
- hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:r("chat.dirPickerGo")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 truncate font-mono text-[11px] text-dark-muted bg-dark-bg rounded-md px-2 py-1 border border-dark-border",title:i,children:i||r("chat.noWorkspaceDir")}),e.jsxs("button",{type:"button",onClick:()=>void D(),disabled:u||!i,className:`shrink-0 flex items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-[11px] text-dark-muted
32
- hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:[e.jsx(Bn,{size:12,"aria-hidden":"true"}),r("chat.dirPickerUp")]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-bg divide-y divide-dark-border/60",children:u?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-xs text-dark-muted",children:[e.jsx(Me,{size:14,className:"animate-spin","aria-hidden":"true"}),r("chat.loading")]}):g?e.jsx("div",{className:"px-3 py-4 text-xs text-accent-red",children:g}):d.length===0?e.jsx("div",{className:"px-3 py-4 text-xs text-dark-muted/60 text-center",children:r("chat.dirPickerNoDirs")}):d.map(S=>{const N=Ll(i,S);return e.jsxs("button",{type:"button",onClick:()=>void f(N),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs text-dark-text
33
- hover:bg-dark-hover transition-colors group`,children:[e.jsx(Is,{size:13,className:"shrink-0 text-accent-yellow/80 group-hover:text-accent-yellow","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:S}),e.jsx(Oe,{size:12,className:"shrink-0 ml-auto text-dark-muted/40","aria-hidden":"true"})]},S)})}),e.jsx("button",{type:"button",onClick:()=>n(i),disabled:!i||u,className:`w-full rounded-lg bg-accent-blue/90 text-white text-xs font-medium py-2
34
- hover:bg-accent-blue disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:r("chat.dirPickerConfirm")})]})]})]})}const Hl=o.memo(function({workspaceDir:s,onSelect:n}){const{t:r}=ee(),i=Ot(x=>x.recentDirs),[a,l]=o.useState(!1),[c,d]=o.useState(!1),h=o.useRef(null);o.useEffect(()=>{if(!a)return;const x=p=>{h.current&&!h.current.contains(p.target)&&l(!1)},g=p=>{p.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",x),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",g)}},[a]);const u=o.useCallback(x=>{var p;const g=((p=x==null?void 0:x.trim)==null?void 0:p.call(x))||"";g&&(l(!1),d(!1),n(g))},[n]);return e.jsxs("div",{className:"relative max-w-[180px] min-w-0",ref:h,children:[e.jsxs("button",{type:"button",onClick:()=>l(x=>!x),className:de("flex w-full items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",a?"border-accent-blue/40 text-accent-blue bg-accent-blue/10":"border-dark-border text-dark-muted hover:bg-dark-hover hover:text-dark-text"),title:r("chat.clickToSwitchDir"),"aria-label":r("chat.clickToSwitchDir"),"aria-expanded":a,"aria-haspopup":"menu",children:[e.jsx(Fn,{size:12,className:"shrink-0 text-accent-blue/80","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:s?Fl(s):r("chat.noWorkspaceDir")}),e.jsx(et,{size:11,className:de("shrink-0 transition-transform",a&&"rotate-180"),"aria-hidden":"true"})]}),a&&e.jsxs("div",{role:"menu",className:"absolute bottom-full left-0 mb-2 w-72 max-w-[calc(100vw-1.5rem)] rounded-xl border border-dark-border bg-dark-surface shadow-2xl z-40 overflow-hidden animate-fade-in",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 text-[10px] font-semibold uppercase tracking-wide text-dark-muted/50 select-none",children:r("chat.recentDirs")}),i.length===0?e.jsx("div",{className:"px-3 pb-2 text-[11px] text-dark-muted/50 select-none",children:r("chat.noRecentDirs")}):e.jsx("div",{className:"max-h-56 overflow-y-auto custom-scrollbar",children:i.map(x=>{const g=x===s;return e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>u(x),className:de("w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors group",g?"text-accent-blue bg-accent-blue/5":"text-dark-text hover:bg-dark-hover"),title:x,children:[e.jsx(Is,{size:12,className:de("shrink-0",g?"text-accent-blue":"text-accent-yellow/80 group-hover:text-accent-yellow"),"aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:x}),g&&e.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-accent-blue",children:"✓"})]},x)})}),e.jsx("div",{className:"border-t border-dark-border"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d(!0)},className:"w-full flex items-center gap-2 px-3 py-2 text-left text-xs text-accent-blue hover:bg-dark-hover transition-colors",children:[e.jsx(Oe,{size:13,"aria-hidden":"true"}),r("chat.chooseOtherDir")]})]}),c&&Xn.createPortal(e.jsx(Bl,{initial:s||"",onClose:()=>d(!1),onConfirm:u}),document.body)]})}),He="__files__",Kl="__sessions__";function ql(t){return t==="enqueue"?"next-step":t==="next-step"?"direct":"enqueue"}function Wl(t){return t.replace(/[\\/]+$/,"").replace(/\\/g,"/").toLowerCase()}function Ul(t){return[{key:He,label:t.files},{key:Kl,label:t.sessions}]}function Sn(t){return t?Wl(t):"￿"}function Gl(t,s){return s===He?t.filter(r=>r.kind==="file"):[...t.filter(r=>r.kind==="session")].sort((r,i)=>Sn(r.kind==="session"?r.dir:"").localeCompare(Sn(i.kind==="session"?i.dir:"")))}function Jl(t,s,n){if(t.length===0)return s;const r=t.indexOf(s),i=r<0?-1:r;if(n)return t[(i+1)%t.length];const a=i<0?t.length:i;return t[(a-1+t.length)%t.length]}const Vl=new Set(["running"]);function Xl(t){return Vl.has(String(t.status||""))?!0:t.live===!0}function Ql(t,s){const n=[];for(const r of t){const i=String(r.id||r.sessionId||"");if(!i||i===s)continue;const a=String(r.title||i.slice(0,8));n.push({kind:"session",key:i,label:a,detail:i.slice(0,8),dir:String(r.workspaceDir||""),status:r.status===void 0?void 0:String(r.status),updatedAt:r.updatedAt===void 0?void 0:String(r.updatedAt),messageCount:typeof r.messageCount=="number"?r.messageCount:void 0})}return n}function En(t,s,n="active"){const r=Ql(t,s);if(n==="all")return r;const i=new Map(t.map(a=>[String(a.id||a.sessionId||""),a]));return r.filter(a=>{const l=i.get(a.key);return l?Xl(l):!1})}function Yl(t){return t==="running"?"bg-accent-green/15 text-accent-green":t==="paused"||t==="interrupted"||t==="error"?"bg-accent-yellow/15 text-accent-yellow":"bg-dark-hover text-dark-muted"}function Zl(t){return t==="running"?"chat.mentionStatusRunning":t==="paused"||t==="interrupted"?"chat.mentionStatusPaused":t==="error"?"chat.mentionStatusError":t==="stopped"?"chat.mentionStatusStopped":"chat.mentionStatusIdle"}function ec(t){return t?/^\d{12,}$/.test(t)?Number(t):t:0}function tc({isOpen:t,items:s,selectedIndex:n,query:r,isSearching:i,onSelect:a,onHover:l,selectedCount:c=0,onFinish:d,tabs:h,activeTab:u,onTabChange:x,scope:g="active",onToggleScope:p,deliveryMode:b="enqueue",onToggleDelivery:j}){const{t:y}=ee();if(!t)return null;const f=!!(x&&h&&h.length>1);return e.jsxs("div",{className:"absolute bottom-full left-0 right-0 mb-2 bg-dark-surface border border-dark-border rounded-lg shadow-xl overflow-hidden z-50",children:[e.jsxs("div",{className:"max-h-60 overflow-y-auto custom-scrollbar",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 text-[11px] text-dark-muted border-b border-dark-border bg-dark-bg",children:[e.jsx("span",{className:"font-medium text-dark-text",children:r?`@${r}`:`@ ${y("chat.mentionFilesGroup")} / ${y("chat.mentionSessionsGroup")}`}),e.jsxs("span",{className:"opacity-70 flex items-center gap-2",children:[c>0&&e.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-accent-blue/20 text-accent-blue font-medium",children:y("chat.selectedCountShort",{n:c})}),e.jsx("span",{children:y(f?"chat.mentionTabHint":"chat.fileMentionHelpMulti")})]})]}),f&&e.jsx("div",{className:"flex items-center gap-1 px-3 py-1.5 border-b border-dark-border bg-dark-bg overflow-x-auto custom-scrollbar",children:h.map(k=>{const D=k.key===u;return e.jsx("button",{type:"button",onMouseDown:S=>{S.preventDefault(),x(k.key)},className:`px-2 py-0.5 rounded text-[11px] whitespace-nowrap transition-colors ${D?"bg-accent-blue/20 text-accent-blue font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children:k.label},k.key)})}),s.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-dark-muted text-xs flex flex-col items-center gap-1",children:i?e.jsxs(e.Fragment,{children:[e.jsx(Me,{size:16,className:"animate-spin"}),e.jsx("span",{children:y("chat.searchingFiles")})]}):e.jsx("span",{children:y(f&&u!==He?"chat.mentionEmptySessions":"chat.noMatchingFiles")})}):s.map((k,D)=>{const S=s[D-1],N=S&&S.kind==="session"?S.dir||"":null,R=k.kind==="session"?k.dir||"":null,O=!S||S.kind!==k.kind||R!==null&&N!==R,C=R!==null?`📁 ${R||y("chat.mentionTabUnknownDir")}`:y("chat.mentionFilesGroup");return e.jsxs("div",{children:[O&&e.jsx("div",{className:"px-3 pt-2 pb-1 text-[10px] uppercase tracking-wide text-dark-muted/70 bg-dark-bg/40 truncate",title:C,children:C}),e.jsxs("button",{onClick:()=>a(k),onMouseEnter:()=>l(D),className:`w-full px-3 py-1.5 flex items-center gap-2 text-left text-xs transition-colors border-l-2 ${D===n?"bg-accent-blue/20 text-accent-blue border-accent-blue":"hover:bg-dark-hover text-dark-text border-transparent"}`,children:[k.kind==="session"?e.jsx(Hn,{size:12,className:"text-accent-blue shrink-0"}):k.isDir?e.jsx(Is,{size:12,className:"text-accent-yellow shrink-0"}):e.jsx(Ts,{size:12,className:"text-dark-muted shrink-0"}),e.jsx("span",{className:"truncate",children:k.label}),k.kind==="session"?e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[k.detail&&e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:k.detail}),k.updatedAt&&e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:Ha(ec(k.updatedAt),Date.now(),y)}),k.messageCount!==void 0&&e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:y("chat.mentionMsgCount",{count:k.messageCount})}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] whitespace-nowrap ${Yl(k.status)}`,children:y(Zl(k.status))})]}):k.detail&&e.jsx("span",{className:"text-[10px] text-dark-muted truncate ml-auto",children:k.detail})]})]},k.key)})]}),d&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-dark-border bg-dark-bg",children:[e.jsxs("span",{className:"flex items-center gap-2 text-[10px] text-dark-muted",children:[f&&p&&e.jsxs("button",{type:"button",onMouseDown:k=>k.preventDefault(),onClick:p,className:`px-1.5 py-0.5 rounded text-[10px] transition-colors ${g==="all"?"bg-accent-blue/20 text-accent-blue font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,title:y("chat.mentionScopeHint"),children:[y("chat.mentionScopeLabel"),y(g==="all"?"chat.mentionScopeAll":"chat.mentionScopeActive")]}),f&&j&&e.jsxs("button",{type:"button",onMouseDown:k=>k.preventDefault(),onClick:j,className:`px-1.5 py-0.5 rounded text-[10px] transition-colors ${b==="next-step"?"bg-accent-blue/20 text-accent-blue font-medium":b==="direct"?"bg-accent-green/20 text-accent-green font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,title:y("chat.mentionDeliveryHint"),children:[y("chat.mentionDeliveryLabel"),y(b==="direct"?"chat.mentionDeliveryDirect":b==="next-step"?"chat.mentionDeliveryNextStep":"chat.mentionDeliveryEnqueue")]}),e.jsx("span",{children:c>0?y("chat.selectedFilesCount",{n:c}):y("chat.enterInsertMulti")})]}),e.jsx("button",{onClick:d,className:"px-3 py-1 text-[11px] rounded bg-accent-blue text-white hover:opacity-90 transition-opacity",children:y("chat.finishMention")})]})]})}function sc({open:t,onClose:s,onSelect:n}){const{t:r}=ee(),[i,a]=o.useState([]),[l,c]=o.useState(!1),[d,h]=o.useState("");o.useEffect(()=>{t&&(h(""),c(!0),fe.skills.list().then(x=>{const g=Array.isArray(x.data)?x.data:[];a(g.filter(p=>p.enabled!==!1))}).catch(()=>a([])).finally(()=>c(!1)))},[t]);const u=o.useMemo(()=>{const x=d.trim().toLowerCase();return x?i.filter(g=>[g.id,g.name,g.description,g.category,...g.tags||[]].join(" ").toLowerCase().includes(x)):i},[i,d]);return e.jsx(Yn,{isOpen:t,onClose:s,title:r("skills.pickTitle"),size:"lg",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-dark-bg border border-dark-border focus-within:border-accent-blue",children:[e.jsx(ft,{size:14,className:"text-dark-muted shrink-0"}),e.jsx("input",{value:d,onChange:x=>h(x.target.value),placeholder:r("skills.pickPlaceholder"),autoFocus:!0,className:"flex-1 bg-transparent outline-none text-sm placeholder-dark-muted/60"}),l&&e.jsx(mt,{size:13,className:"animate-spin text-dark-muted"})]}),l?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(mt,{size:20,className:"animate-spin text-accent-blue"})}):u.length===0?e.jsx("div",{className:"text-center py-12 text-sm text-dark-muted",children:r("skills.pickEmpty")}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:u.map(x=>e.jsxs("button",{onClick:()=>n(x),className:"text-left rounded-lg border border-dark-border p-3 flex flex-col gap-1 transition-colors hover:border-accent-blue/50 hover:bg-dark-hover",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("span",{className:"font-medium text-sm truncate",children:[x.icon||"⭐"," ",x.name]}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted shrink-0",children:x.injection||"lazy"})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate font-mono",children:["$",x.id]}),x.description&&e.jsx("div",{className:"text-xs text-dark-muted line-clamp-2",children:x.description}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-1",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate",children:x.category||"—"}),e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-accent-blue shrink-0",children:[e.jsx(Ln,{size:11}),r("skills.pickUse")]})]})]},x.id))})]})})}const nc=800,dt=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g;let rc=0;const Kt=new Map;function ac(t){const s=++rc;return Kt.set(s,t),s}function ic(t){Kt.delete(t)}function oc(t){return t.length>nc||br(t)>0}function br(t){return(t.match(/\r\n|\r|\n/g)||[]).length}function lc(t){const s=ac(t),n=br(t);return n===0?{id:s,label:`[Pasted text #${s}]`}:{id:s,label:`[Pasted text #${s} +${n} lines]`}}function cc(t){return dt.lastIndex=0,t.replace(dt,(s,n)=>{const r=parseInt(n,10),i=Kt.get(r);return i!==void 0?i:s})}function dc(t){dt.lastIndex=0;const s=[];let n;for(;(n=dt.exec(t))!==null;){const r=n[1];r!==void 0&&s.push(parseInt(r,10))}return dt.lastIndex=0,s}function uc(t){for(const s of t)Kt.delete(s)}function hc(t){const s=t.match(/\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]$/);return s?s[0]??null:null}function mc(t){const s=t.match(/^\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]/);return s?s[0]??null:null}function Mn(t){const s=t.match(/#(\d+)/);s&&ic(parseInt(s[1]??"",10))}class Ke extends Error{constructor(n,r){super(r??n);Tt(this,"code");this.code=n,this.name="ScreenshotError"}}function xc(t){const s=document.createElement("canvas");s.width=t.videoWidth,s.height=t.videoHeight;const n=s.getContext("2d");if(!n)throw new Ke("failed","Canvas 2D context unavailable");return n.drawImage(t,0,0,s.width,s.height),new Promise((r,i)=>{s.toBlob(a=>a?r(a):i(new Ke("failed","canvas.toBlob returned null")),"image/png")})}async function fc(){var n;if(!((n=navigator.mediaDevices)!=null&&n.getDisplayMedia))throw new Ke("unsupported","Screen capture is not supported in this browser");const t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1}).catch(r=>{const i=r instanceof DOMException?r.name:"";throw i==="NotAllowedError"||i==="AbortError"?new Ke("cancelled","User dismissed the screen picker"):new Ke("failed",r instanceof Error?r.message:String(r))}),s=t.getTracks();try{const r=document.createElement("video");r.srcObject=t,r.muted=!0,r.playsInline=!0,await r.play().catch(()=>{}),r.readyState<2&&await new Promise(d=>{const h=()=>d();r.addEventListener("loadeddata",h,{once:!0}),setTimeout(h,1e3)}),await new Promise(d=>requestAnimationFrame(()=>d()));const i=r.videoWidth,a=r.videoHeight;if(!i||!a)throw new Ke("failed","Captured video frame has no pixels");const l=await xc(r);r.srcObject=null;const c=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);return new File([l],`screenshot-${c}.png`,{type:"image/png"})}finally{for(const r of s)r.stop()}}const Dt=16e3;function ps(){const t=["audio/webm;codecs=opus","audio/webm","audio/mp4"];if(typeof MediaRecorder>"u")return"";for(const s of t)if(MediaRecorder.isTypeSupported(s))return s;return""}async function pc(t){if(t.sampleRate===Dt&&t.numberOfChannels===1)return t.getChannelData(0);const s=Math.max(1,Math.ceil(t.length*Dt/t.sampleRate)),n=new OfflineAudioContext(1,s,Dt),r=n.createBufferSource();return r.buffer=t,r.connect(n.destination),r.start(0),(await n.startRendering()).getChannelData(0)}function gc(t,s){const n=new ArrayBuffer(44+t.length*2),r=new DataView(n),i=(l,c)=>{for(let d=0;d<c.length;d++)r.setUint8(l+d,c.charCodeAt(d))};i(0,"RIFF"),r.setUint32(4,36+t.length*2,!0),i(8,"WAVE"),i(12,"fmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,s,!0),r.setUint32(28,s*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),i(36,"data"),r.setUint32(40,t.length*2,!0);let a=44;for(let l=0;l<t.length;l++){const c=Math.max(-1,Math.min(1,t[l]??0));r.setInt16(a,c<0?c*32768:c*32767,!0),a+=2}return n}function bc(t){return new Promise((s,n)=>{const r=new FileReader;r.onload=()=>{const i=String(r.result||""),a=i.indexOf(",");s(a>=0?i.slice(a+1):i)},r.onerror=()=>n(r.error),r.readAsDataURL(t)})}function kc(t){const[s,n]=o.useState("idle"),[r,i]=o.useState(0),a=o.useRef(null),l=o.useRef(null),c=o.useRef([]),d=o.useRef(null),h=o.useRef(0),u=o.useCallback(()=>{var j;(j=l.current)==null||j.getTracks().forEach(y=>y.stop()),l.current=null},[]),x=o.useCallback(()=>{d.current&&(clearInterval(d.current),d.current=null)},[]);o.useEffect(()=>()=>{x(),a.current&&a.current.state!=="inactive"&&a.current.stop(),u()},[x,u]);const g=o.useCallback(async()=>{if(s!=="idle")return;if(typeof MediaRecorder>"u")throw new Error("当前浏览器不支持语音输入(需要 MediaRecorder)。请使用 Chrome/Edge/Firefox 或桌面版。");let j;try{j=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}})}catch(f){throw f instanceof DOMException&&f.name==="NotAllowedError"?new Error("麦克风权限被拒绝。请在浏览器地址栏允许麦克风权限后重试。"):new Error("无法访问麦克风:"+(f instanceof Error?f.message:String(f)))}l.current=j,c.current=[];const y=new MediaRecorder(j,ps()?{mimeType:ps()}:void 0);y.ondataavailable=f=>{f.data&&f.data.size>0&&c.current.push(f.data)},a.current=y,y.start(),h.current=Date.now(),i(0),n("recording"),d.current=setInterval(()=>i(Date.now()-h.current),100)},[s]),p=o.useCallback(async()=>{var f;const j=a.current;if(!j||j.state==="inactive")throw new Error("当前没有进行中的录音。");const y=new Promise(k=>{j.onstop=()=>k()});j.stop(),await y,x(),u(),a.current=null,n("transcribing");try{const k=new Blob(c.current,{type:ps()||"audio/webm"});c.current=[];const D=await k.arrayBuffer(),S=new AudioContext;let N;try{N=await S.decodeAudioData(D)}finally{S.close()}if(N.duration<.25)return n("idle"),"";const O=await pc(N),C=gc(O,Dt),A=await bc(new Blob([C],{type:"audio/wav"})),B=await fe.stt.transcribe(t,A,"wav");if(!B.success)throw new Error(B.error||"语音转写失败");return((f=B.data)==null?void 0:f.text)??""}finally{n("idle")}},[t,x,u]),b=o.useCallback(()=>{const j=a.current;j&&j.state!=="inactive"&&j.stop(),a.current=null,c.current=[],x(),u(),n("idle")},[x,u]);return{state:s,elapsedMs:r,start:g,stop:p,cancel:b}}const vc=({isOpen:t,commands:s,selectedIndex:n,filter:r,onSelect:i,onHover:a,containerRef:l})=>{const{t:c}=ee();return!t||s.length===0?null:e.jsxs("div",{ref:l,className:"absolute bottom-full left-0 right-0 mb-2 bg-dark-surface border border-dark-border rounded-lg shadow-xl overflow-hidden z-50 max-h-72 overflow-y-auto custom-scrollbar",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 text-[11px] text-dark-muted border-b border-dark-border bg-dark-bg",children:[e.jsx("span",{className:"font-medium text-dark-text",children:r?`/${r}`:c("slashCommands.quickCommands")}),e.jsx("span",{className:"opacity-70",children:c("slashCommands.help")})]}),s.map((d,h)=>e.jsxs("button",{"data-index":h,onClick:()=>i(d),onMouseEnter:()=>a(h),className:`w-full px-3 py-2 flex items-start gap-3 text-left transition-colors border-l-2 ${h===n?"bg-accent-blue/10 border-accent-blue":"border-transparent hover:bg-dark-hover"}`,children:[e.jsx("span",{className:"text-lg leading-none shrink-0","aria-hidden":"true",children:d.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-dark-text",children:["/",d.name]}),d.args&&e.jsx("span",{className:"text-xs text-dark-muted",children:d.args}),!d.local&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue shrink-0",children:c("slashCommands.backend")})]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:d.description})]}),h===n&&e.jsx(da,{size:14,className:"text-dark-muted shrink-0 mt-0.5","aria-hidden":"true"})]},d.id))]})},Cn="packages/cli/.playwright-mcp/slash-toggle/steps.json";function jc({isOpen:t,onClose:s}){const[n,r]=o.useState(Cn),[i,a]=o.useState("Terminal rendering verdict"),[l,c]=o.useState("Replay the captured ANSI stream through xterm.js"),[d,h]=o.useState(!1),[u,x]=o.useState(!1),[g,p]=o.useState(null),[b,j]=o.useState(!1),y=o.useMemo(()=>g?ws(g.path):"",[g]),f=o.useCallback(async()=>{const k=n.trim(),D=i.trim();if(!k||!D){he.warning("Steps path and title are required.");return}x(!0),p(null);try{const S=await fe.terminalFigure.generate({steps:k,title:D,subtitle:l.trim()||void 0,scrollTop:d,cols:2});if(!S.success||!S.data){he.error(S.error||"Could not generate the terminal figure.");return}p(S.data),he.success("Terminal verdict figure generated.")}finally{x(!1)}},[d,n,l,i]);return e.jsxs(Yn,{isOpen:t,onClose:s,title:"Generate terminal verdict figure",size:"2xl",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-xs leading-5 text-dark-muted",children:["Replay a captured ",e.jsx("code",{className:"text-dark-text",children:"steps.json"})," through xterm.js, then compose the annotated PNG. The capture stage is kept separate because it depends on the specific TUI under test."]}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("label",{htmlFor:"terminal-figure-steps",className:"text-xs font-medium text-dark-text",children:"steps.json path"}),e.jsx("input",{id:"terminal-figure-steps",value:n,onChange:k=>r(k.target.value),placeholder:Cn,className:"w-full rounded-lg border border-dark-border bg-dark-bg px-3 py-2 text-sm text-dark-text outline-none focus:border-accent-blue",spellCheck:!1}),e.jsx("span",{className:"text-[11px] text-dark-muted",children:"Workspace-relative path; the file must be produced by the capture stage."})]}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("label",{htmlFor:"terminal-figure-title",className:"text-xs font-medium text-dark-text",children:"Title"}),e.jsx("input",{id:"terminal-figure-title",value:i,onChange:k=>a(k.target.value),className:"w-full rounded-lg border border-dark-border bg-dark-bg px-3 py-2 text-sm text-dark-text outline-none focus:border-accent-blue"})]}),e.jsxs("label",{className:"block space-y-1.5",children:[e.jsx("label",{htmlFor:"terminal-figure-subtitle",className:"text-xs font-medium text-dark-text",children:"Subtitle"}),e.jsx("input",{id:"terminal-figure-subtitle",value:l,onChange:k=>c(k.target.value),className:"w-full rounded-lg border border-dark-border bg-dark-bg px-3 py-2 text-sm text-dark-text outline-none focus:border-accent-blue"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx("input",{id:"terminal-figure-scrolltop",type:"checkbox",checked:d,onChange:k=>h(k.target.checked),className:"rounded border-dark-border"}),e.jsx("span",{children:"Also capture the top of scrollback to expose hidden residue"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:s,className:"rounded-lg px-3 py-2 text-xs text-dark-muted hover:bg-dark-hover hover:text-dark-text",children:"Close"}),e.jsxs("button",{type:"button",onClick:()=>void f(),disabled:u,className:"inline-flex items-center gap-2 rounded-lg bg-accent-blue px-3 py-2 text-xs font-medium text-white hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-50",children:[u?e.jsx(Me,{size:14,className:"animate-spin"}):e.jsx($t,{size:14}),u?"Generating…":"Generate figure"]})]}),g&&e.jsxs("div",{className:"overflow-hidden rounded-xl border border-dark-border bg-dark-bg",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-dark-border px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-dark-text",children:g.filename}),e.jsxs("div",{className:"text-[11px] text-dark-muted",children:[g.bytes.toLocaleString()," bytes · ",g.panels.length," panels"]})]}),e.jsxs("button",{type:"button",onClick:()=>j(!0),className:"inline-flex items-center gap-1 rounded-md px-2 py-1 text-[11px] text-dark-muted hover:bg-dark-hover hover:text-dark-text",children:[e.jsx(Cs,{size:12}),"Open preview"]})]}),e.jsx("button",{type:"button",className:"block w-full cursor-zoom-in",onClick:()=>j(!0),children:e.jsx("img",{src:y,alt:i,className:"max-h-[46vh] w-full object-contain"})})]})]}),b&&g&&e.jsx(qn,{src:y,alt:g.filename,onClose:()=>j(!1)})]})}const kr=["xlsx","xls","csv","docx","txt","md","mdx","rst","adoc","ts","tsx","js","jsx","mjs","cjs","mts","cts","json","jsonc","yaml","yml","toml","xml","html","css","scss","less","py","rb","go","rs","java","kt","swift","c","h","cpp","hpp","cc","cs","sh","bash","zsh","ps1","bat","cmd","sql","graphql","proto","vue","svelte","astro","env","gitignore","gitattributes","editorconfig"],yc=new RegExp(`(?:\\.(${kr.join("|")})|dockerfile|makefile)$`,"i"),vr=["png","jpg","jpeg","webp","gif","bmp","svg"],wc=Object.freeze([]),Nc=new RegExp(`\\.(${vr.join("|")})$`,"i"),Sc=10*1024*1024,Ec=kr.map(t=>`.${t}`).join(",")+",.Dockerfile,.Makefile,"+vr.map(t=>`.${t}`).join(","),Mc=".deepseekcode/attachments",Cc=50*1024*1024,gs=10,Rt="chat-col",Tc=/["<>]/g;function Ic(t){return`<image name="${(t||"image").replace(Tc,"")}" />`}const Ac=t=>/\.xlsx?$/i.test(t)?js:/\.(csv|docx|txt|md|mdx|rst|adoc|json|jsonc|yaml|yml|toml|xml|html|css|scss|less|env|gitignore|gitattributes|editorconfig)$/i.test(t)?ut:/\.(ts|tsx|js|jsx|mjs|cjs|mts|cts|py|rb|go|rs|java|kt|swift|c|h|cpp|hpp|cc|cs|sh|bash|zsh|ps1|bat|cmd|sql|graphql|proto|vue|svelte|astro|dockerfile|makefile)$/i.test(t)?ga:Ts,bs=3e3,Tn=5,ot=50,Rc=5e3;function _c(t,s){const n=t.slice(0,s),r=n.lastIndexOf("@");if(r===-1)return{active:!1,query:"",start:-1};const i=n.slice(r+1);return/^[\p{L}\p{N}_\-./]*$/u.test(i)?{active:!0,query:i,start:r}:{active:!1,query:"",start:-1}}function Dc(t,s){const n=t.lastIndexOf(`
35
- `,s-1)+1,r=t.slice(n,s);return r.startsWith("/")?/\s/.test(r)?{active:!1,query:""}:{active:!0,query:r.slice(1)}:{active:!1,query:""}}const zc=o.memo(function({sessionId:s,onSend:n,onRunShell:r,onStop:i,onPause:a,onResume:l,slashOptions:c,workspaceDir:d,onWorkspaceSelect:h}){var en,tn;const{t:u}=ee(),x=xe(m=>{var v;return((v=m.sessionInputs)==null?void 0:v[s])??""}),g=xe(m=>m.setSessionInput),p=xe(m=>{var v;return((v=m.generatingSessions)==null?void 0:v.includes(s))??!1}),b=xe(m=>{var v;return((v=m.pausedSessions)==null?void 0:v.includes(s))??!1}),j=xe(m=>{var v;return(v=m.pendingBySession)==null?void 0:v[s]})??wc,y=j.length,f=o.useRef(null),k=o.useRef(null),D=o.useRef(!1),S=o.useRef(0),[N,R]=o.useState([]),[O,C]=o.useState(!1),[A,B]=o.useState(!1),[_,H]=o.useState(!1),[G,ne]=o.useState(!1),te=o.useCallback(()=>{const m=xe.getState().clearPending(s);m>0&&he.info(u("toast.queueRevoked",{count:m}))},[s,u]),V=o.useCallback(m=>{g(s,m)},[s,g]),[w,U]=o.useState(()=>{try{return an(localStorage.getItem("dsc.stt.lang"))}catch{return"en"}}),[Q,se]=o.useState(!1),M=o.useRef(null),W=o.useCallback(m=>{U(m);try{localStorage.setItem("dsc.stt.lang",m)}catch{}se(!1)},[]);o.useEffect(()=>{if(!Q)return;const m=I=>{M.current&&!M.current.contains(I.target)&&se(!1)},v=I=>{I.key==="Escape"&&se(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",v)}},[Q]);const z=kc(w),$=o.useRef(null),K=o.useCallback(async()=>{var m;try{if(!$.current){const P=await fe.stt.status();P.success&&P.data&&($.current=P.data)}const v=$.current;if(!v)return!0;if(v.service!=="ok"&&v.service!=="stopped")return he.warning(u("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1;const I=(m=v.backends)==null?void 0:m[w];return I&&!I.installed?(he.warning(u("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1):!0}catch{return!0}},[u,w]);o.useEffect(()=>{const m=()=>{$.current=null};return window.addEventListener("stt-backends-changed",m),()=>window.removeEventListener("stt-backends-changed",m)},[]),o.useEffect(()=>{const m=v=>{var P;const I=an((P=v.detail)==null?void 0:P.lang);U(I)};return window.addEventListener("stt-lang-changed",m),()=>window.removeEventListener("stt-lang-changed",m)},[]);const Z=o.useCallback(m=>{const v=f.current,I=(v==null?void 0:v.selectionStart)??x.length,P=x.slice(0,I)+m+x.slice(I);V(P),requestAnimationFrame(()=>{v==null||v.focus();const L=I+m.length;v&&(v.selectionStart=v.selectionEnd=L)})},[x,V]),oe=o.useCallback(async()=>{if(p){he.info(u("stt.generatingTitle"));return}if(z.state==="recording"){try{const v=await z.stop();v?Z(v):he.info(u("stt.noSpeech"))}catch(v){he.error(v instanceof Error?v.message:String(v))}return}if(!(z.state!=="idle"||!await K()))try{await z.start()}catch(v){he.error(v instanceof Error?v.message:String(v))}},[z,Z,K,u,p]),ue=Ka(c),{isOpen:ae,filter:le,filteredCommands:T,selectedIndex:X,setSelectedIndex:ce,selectNext:je,selectPrev:ye,executeCommand:E,openMenu:re,closeMenu:F,setFilter:ve,allCommands:we,containerRef:gt}=ue,[ge,Ee]=o.useState(!1),[bt,We]=o.useState(""),[qt,Os]=o.useState([]),[Wt,Pe]=o.useState(0),[yr,Ps]=o.useState(!1),[wr,Ue]=o.useState(0),Ge=o.useRef(-1),[Ls,Nr]=o.useState("active"),kt=o.useRef("active"),[tt,Sr]=o.useState("enqueue"),vt=o.useRef("enqueue");vt.current=tt;const[Fs,Er]=o.useState([]),jt=o.useCallback(()=>{Er(Array.from(_e.current.values()))},[]);kt.current=Ls;const Re=o.useRef(new Set),_e=o.useRef(new Map),st=o.useRef(null),yt=o.useRef(null),wt=o.useRef([]),De=o.useRef(!1),Bs=o.useRef([]),[Hs,Nt]=o.useState(He),nt=o.useRef([]),Je=o.useRef([]),Ut=o.useRef(0),Ks=o.useRef("");Ks.current=bt;const Le=o.useCallback((m,v)=>{const I=m.map(J=>({kind:"file",key:J.path,label:J.name,detail:J.path,isDir:J.type==="directory"})),P=nt.current,L=v.toLowerCase(),q=(L?P.filter(J=>J.label.toLowerCase().includes(L)||J.key.toLowerCase().includes(L)):P).slice(0,ot);return[...I,...q]},[]),St=o.useCallback(async()=>{const m=Date.now();if(Je.current.length>0&&m-Ut.current<Rc)return Je.current;try{const v=await fe.sessions.list(),I=v.success&&v.data?v.data:[];(I.length>0||Je.current.length===0)&&(Je.current=I),Ut.current=Date.now()}catch{}return Je.current},[]),Gt=o.useCallback(async()=>{const m=await St();return nt.current=En(m,s,kt.current),nt.current},[St,s]),Fe=o.useCallback(m=>{Bs.current=m,Os(m)},[]),Jt=o.useCallback(()=>{const m=kt.current==="active"?"all":"active";kt.current=m,Nr(m),(async()=>{const v=await St();nt.current=En(v,s,m);const I=Ks.current.toLowerCase(),P=wt.current.filter(L=>!I||L.path.toLowerCase().includes(I)).slice(0,ot);Fe(Le(P,I))})()},[St,s,Fe,Le]),Et=o.useCallback(()=>{let m=ql(vt.current);m==="direct"&&Re.current.size>0&&(m="enqueue"),vt.current=m,Sr(m)},[]),Be=o.useMemo(()=>Ul({files:u("chat.mentionTabFiles"),sessions:u("chat.mentionTabSessions")}),[u]),Vt=Be.some(m=>m.key===Hs)?Hs:He,Ve=o.useMemo(()=>Gl(qt,Vt),[qt,Vt]);o.useEffect(()=>{Re.current=new Set,_e.current=new Map,jt(),De.current=!1,Nt(He),nt.current=[],Je.current=[],Ut.current=0,Ee(!1),We(""),Os([]),Bs.current=[],Ue(0),F()},[s,F,jt]);const qs=o.useDeferredValue(x),Ws=ct(m=>m.estimateTokens),Xt=o.useMemo(()=>Ws(qs),[qs,Ws]),Us=o.useCallback(()=>{const m=f.current;m&&(m.style.height="auto",m.style.height=Math.min(m.scrollHeight,200)+"px")},[]);o.useEffect(()=>{Us()},[x,N.length,Us]);const Qt=o.useCallback(()=>{if(st.current)return Promise.resolve(st.current);if(yt.current)return yt.current;Ps(!0);const m=(async()=>{try{const v=await fe.files.list(),I=v.success&&v.data?v.data[0]:void 0;if(!I)return st.current=[],[];const P=[],L=new Set,q=async(J,ie)=>{if(ie>Tn||P.length>=bs)return;const me=[];for(const Y of J||[]){if(P.length>=bs)return;const ke=Y.path.replace(/\\/g,"/");L.has(ke)||(L.add(ke),Y.type==="file"?P.push({...Y,path:ke}):Y.children&&Y.children.length>0?await q(Y.children,ie+1):ie<Tn&&me.push(Y))}if(me.length===0)return;const be=await Promise.all(me.map(async Y=>{var ke;try{const Ne=await fe.files.list(Y.path.replace(/\\/g,"/"));return Ne.success&&Ne.data?((ke=Ne.data[0])==null?void 0:ke.children)||[]:[]}catch{return[]}}));for(const Y of be){if(P.length>=bs)return;await q(Y,ie+1)}};return await q(I.children,1),st.current=P,P}catch{return st.current=[],[]}finally{yt.current=null,Ps(!1)}})();return yt.current=m,m},[]),Gs=o.useCallback(async(m,v)=>{if(De.current){const J=Ge.current;if(J<0||v<J){De.current=!1,Ee(!1);return}const ie=m.slice(J,v);if(/\s/.test(ie)){De.current=!1,Ee(!1);return}Ge.current=J,We(ie),Ee(!0),Pe(0);const[me]=await Promise.all([Qt(),Gt()]);wt.current=me;const be=ie.toLowerCase(),Y=me.filter(ke=>!be||ke.path.toLowerCase().includes(be)).slice(0,ot);Fe(Le(Y,be));return}const I=_c(m,v);if(!I.active){ge&&Ee(!1);return}Ge.current=I.start,We(I.query),Ee(!0),Pe(0);const[P]=await Promise.all([Qt(),Gt()]);wt.current=P;const L=I.query.toLowerCase(),q=P.filter(J=>!L||J.path.toLowerCase().includes(L)).slice(0,ot);Fe(Le(q,L))},[ge,Qt,Gt,Le,Fe]),Mr=o.useCallback(m=>{const v=m.target.value,I=m.target.selectionStart??v.length;V(v),Gs(v,I);const P=Dc(v,I);P.active?(ae||re(),ve(P.query),ce(0)):ae&&F()},[V,Gs,ae,re,ve,ce,F]),Yt=o.useCallback(m=>{const v=f.current,I=x,P=Ge.current>=0?Ge.current:(v==null?void 0:v.selectionStart)??I.length,L=Math.min(I.length,P+1+bt.length);let q,J;if(m.kind==="session"){const me=m.label||m.key;q=/\s/.test(me)?m.key:me,_e.current.set(m.key,me),jt(),J=`@${q} `}else q=m.key,Re.current.add(q),J=`@${q} `;const ie=I.slice(0,P)+J+I.slice(L);V(ie),Ee(!0),We(""),Fe(Le(wt.current.slice(0,ot),"")),Pe(0),Ue(Re.current.size+_e.current.size),Ge.current=P+J.length,De.current=!0,requestAnimationFrame(()=>{v==null||v.focus(),v&&(v.selectionStart=v.selectionEnd=P+J.length)})},[x,bt,V,Le,Fe]),rt=o.useCallback(()=>{De.current=!1,Ee(!1),We(""),Ue(0),Nt(He)},[]),Zt=o.useCallback(m=>{if(!m.args){const q=E(m,"");q!=null&&q.message&&(q.success?he.success(q.message):he.error(q.message)),V("");return}const v=f.current,I=(v==null?void 0:v.selectionStart)??x.length,P=x.lastIndexOf(`
36
- `,I-1)+1,L=x.slice(0,P)+`/${m.name} `+x.slice(I);V(L),F(),requestAnimationFrame(()=>{v==null||v.focus();const q=P+m.name.length+2;v&&(v.selectionStart=v.selectionEnd=q)})},[x,V,E,F]),Cr=o.useCallback(m=>{const v=f.current,I=(v==null?void 0:v.selectionStart)??x.length,P=`$${m.id} `,L=x.slice(0,I)+P+x.slice(I);V(L),H(!1),De.current=!1,Ee(!1),We(""),requestAnimationFrame(()=>{v==null||v.focus();const q=I+P.length;v&&(v.selectionStart=v.selectionEnd=q)})},[x,V]),Js=2048,Vs=o.useCallback(m=>new Promise((v,I)=>{const P=()=>{const L=new FileReader;L.onload=()=>v(String(L.result??"")),L.onerror=()=>I(new Error("Failed to read image")),L.readAsDataURL(m)};(async()=>{let L=null;try{L=await createImageBitmap(m)}catch{P();return}try{const q=Math.max(L.width,L.height);if(q<=Js){L.close(),P();return}const J=Js/q,ie=document.createElement("canvas");ie.width=Math.max(1,Math.round(L.width*J)),ie.height=Math.max(1,Math.round(L.height*J));const me=ie.getContext("2d");if(!me){L.close(),P();return}me.drawImage(L,0,0,ie.width,ie.height),L.close();const be=m.type==="image/jpeg"?"image/jpeg":"image/png";v(ie.toDataURL(be,be==="image/jpeg"?.9:void 0))}catch{L==null||L.close(),P()}})()}),[]),ze=o.useCallback(m=>{const v=Array.from(m);R(I=>{const P=gs-I.length,L=I.slice();for(const q of v.slice(0,P)){const J=Nc.test(q.name);if(!J&&!yc.test(q.name)){he.warning(u("fileJob.unsupportedType",{name:q.name}));continue}if(q.size>(J?Sc:Cc)){he.error(u("fileJob.fileTooLarge",{name:q.name}));continue}if(L.some(me=>me.name===q.name&&me.size===q.size)){he.warning(u("fileJob.duplicateFile",{name:q.name}));continue}const ie={id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,file:q,name:q.name,size:q.size,uploading:!1};J&&Vs(q).then(me=>{R(be=>be.map(Y=>Y.id===ie.id?{...Y,imageDataUri:me}:Y))}).catch(()=>{R(me=>me.filter(be=>be.id!==ie.id)),he.error(u("fileJob.uploadFailed",{name:q.name}))}),L.push(ie)}return L.length>=gs&&he.warning(u("fileJob.maxAttachments",{n:gs})),L})},[u,Vs]),Tr=o.useCallback(m=>{m.target.files&&m.target.files.length>0&&(ze(m.target.files),m.target.value="")},[ze]),Ir=o.useCallback(()=>{var m;(m=k.current)==null||m.click()},[]),Mt=o.useCallback(async()=>{if(!(A||p)){B(!0);try{const m=await fc();ze([m])}catch(m){m instanceof Ke&&m.code==="cancelled"||he.error(u("fileJob.screenshotFailed"))}finally{B(!1)}}},[ze,u,A,p]),Xs=o.useRef(Mt);o.useEffect(()=>{Xs.current=Mt},[Mt]),o.useEffect(()=>{const m=v=>{!(v.ctrlKey||v.metaKey)||!v.shiftKey||v.key!=="s"&&v.key!=="S"||(v.preventDefault(),Xs.current())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[]);const Ar=o.useCallback(m=>{R(v=>v.filter(I=>I.id!==m))},[]),Rr=o.useCallback(m=>{m.preventDefault(),C(!0)},[]),_r=o.useCallback(m=>{m.preventDefault(),C(!1)},[]),Dr=o.useCallback(m=>{m.preventDefault(),C(!1),m.dataTransfer.files&&m.dataTransfer.files.length>0&&ze(m.dataTransfer.files)},[ze]),Qs=o.useCallback(async()=>{var v;if(N.length===0)return"";const m=[];for(const I of N){if(I.imageDataUri)continue;if(I.path){m.push(`<attachment path="${I.path}" />`);continue}if(!I.file)continue;R(q=>q.map(J=>J.id===I.id?{...J,uploading:!0,error:void 0}:J));const P=`${Mc}/${I.name}`,L=await fe.files.upload(I.file,P);if(L.success&&((v=L.data)!=null&&v.path)){const q=L.data.path.replace(/\\/g,"/");R(J=>J.map(ie=>ie.id===I.id?{...ie,uploading:!1,path:q}:ie)),m.push(`<attachment path="${q}" />`)}else R(q=>q.map(J=>J.id===I.id?{...J,uploading:!1,error:L.error||u("fileJob.uploadFailed")}:J)),he.error(`${I.name}: ${L.error||u("fileJob.uploadFailed")}`)}return m.length>0?`${m.join(`
37
- `)}
38
-
39
- `:""},[N,u]),zr=o.useCallback(m=>{const v=m.clipboardData.getData("text/plain");if(m.clipboardData.files&&m.clipboardData.files.length>0){m.preventDefault(),ze(m.clipboardData.files);return}if(!v||!oc(v))return;m.preventDefault();const{label:I}=lc(v),P=f.current;if(!P)return;const L=P.selectionStart,q=P.selectionEnd,J=P.value,ie=J.slice(0,L)+I+J.slice(q);V(ie),requestAnimationFrame(()=>{P.selectionStart=P.selectionEnd=L+I.length})},[V,ze]),Ct=o.useCallback(async()=>{const m=cc(x);uc(dc(m)),De.current=!1,Ee(!1),F();const v=m.trim(),I=N.length>0;if(!v&&!I)return;const P=m.trim();if(P.startsWith("/")&&!I){const Y=qa(P);if(Y){const ke=we.find(Ne=>Ne.name===Y.command);if(ke){const Ne=E(ke,Y.args);Ne!=null&&Ne.message&&(Ne.success?he.success(Ne.message):he.error(Ne.message)),V(""),R([]),Re.current=new Set,_e.current=new Map,jt(),Ue(0);return}he.error(u("slashCommands.unknownCommand",{cmd:`/${Y.command}`}));return}}if(P.startsWith("!")&&!I){const Y=P.slice(1).trim();if(!Y)return;r==null||r(Y),V(""),R([]),Re.current=new Set,_e.current=new Map,Ue(0);return}const L=Array.from(Re.current).filter(Y=>m.includes(`@${Y}`)),q=Array.from(_e.current.entries()).map(([Y,ke])=>({id:Y,title:ke})).filter(Y=>m.includes(`@${Y.title}`)||m.includes(`@${Y.id}`));let J="";if(I){if(N.some(Y=>Y.uploading)){he.warning(u("fileJob.stillUploading"));return}J=await Qs()}const ie=N.filter(Y=>Y.imageDataUri),me=ie.map(Y=>Y.imageDataUri);if(ie.length>0){const Y=ie.map(ke=>Ic(ke.name)).join(`
40
- `);J=J?`${J}${Y}
41
-
42
- `:`${Y}
43
-
44
- `}const be=(J+m).trim();!be&&!I||(n(be||J.trim(),L.length>0?L:void 0,me.length>0?me:void 0,q.length>0?q:void 0,q.length>0?vt.current:void 0),V(""),R([]),Re.current=new Set,_e.current=new Map,Ue(0))},[x,N,n,r,V,Qs,u,F,we,E]),$r=o.useCallback(m=>{if(!m.nativeEvent.isComposing){if((m.key==="Backspace"||m.key==="Delete")&&!m.ctrlKey&&!m.metaKey&&!m.altKey&&!m.shiftKey){const v=f.current;if(v&&v.selectionStart===v.selectionEnd){const I=v.selectionStart,P=v.value;if(m.key==="Backspace"&&I>0){const L=hc(P.slice(0,I));if(L){m.preventDefault(),V(P.slice(0,I-L.length)+P.slice(I)),Mn(L),requestAnimationFrame(()=>{v.focus();const q=I-L.length;v.selectionStart=v.selectionEnd=q});return}}else if(m.key==="Delete"&&I<P.length){const L=mc(P.slice(I));if(L){m.preventDefault(),V(P.slice(0,I)+P.slice(I+L.length)),Mn(L),requestAnimationFrame(()=>{v.focus(),v.selectionStart=v.selectionEnd=I});return}}}}if(ge&&Be.length>1&&m.key==="Tab"){m.preventDefault();const v=Be.map(I=>I.key);Nt(I=>Jl(v,I,!m.shiftKey)),Pe(0);return}if(ge&&Be.length>1&&m.key==="S"&&!m.ctrlKey&&!m.metaKey&&!m.altKey){m.preventDefault(),Jt();return}if(ge&&Be.length>1&&m.key==="M"&&!m.ctrlKey&&!m.metaKey&&!m.altKey){m.preventDefault(),Et();return}if(ge&&Ve.length>0){if(m.key==="ArrowDown"){m.preventDefault(),Pe(v=>(v+1)%Ve.length);return}if(m.key==="ArrowUp"){m.preventDefault(),Pe(v=>(v-1+Ve.length)%Ve.length);return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const v=Ve[Wt];v&&(m.preventDefault(),Yt(v));return}if(m.key==="Escape"){m.preventDefault(),rt();return}}else if(ge&&m.key==="Escape"){m.preventDefault(),rt();return}if(ae&&T.length>0){if(m.key==="ArrowDown"){m.preventDefault(),je();return}if(m.key==="ArrowUp"){m.preventDefault(),ye();return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const v=T[X];v&&(m.preventDefault(),Zt(v));return}if(m.key==="Escape"){m.preventDefault(),F();return}}else if(ae&&m.key==="Escape"){m.preventDefault(),F();return}if(m.key==="Escape"&&p){m.preventDefault();const v=Date.now(),I=Wa(y,b,S.current,v);S.current=v,I==="revokeQueue"?(te(),S.current=0):I==="stop"?i():a();return}if(m.key==="Enter"&&(m.ctrlKey||m.metaKey)){m.preventDefault(),Ct();return}m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Ct())}},[p,b,y,te,Ct,a,l,i,ge,qt,Wt,Yt,rt,Be,Jt,Et,ae,T,X,je,ye,Zt,F,V]),Or=o.useCallback(()=>{D.current=!0},[]),Pr=o.useCallback(()=>{D.current=!1},[]),Ys=Xt>8e3,Zs=x.trim().length>0||N.length>0,es=/mac/i.test(navigator.platform||"")?"⌘":"Ctrl";return e.jsxs("div",{className:"chat-composer-shell shrink-0 px-3 pb-3 pt-2 sm:px-4",onDragOver:Rr,onDragLeave:_r,onDrop:Dr,children:[j.length>0&&e.jsxs("div",{className:`${Rt} mb-2 flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs text-dark-muted`,children:[e.jsx("span",{"aria-hidden":"true",children:"⏳"}),e.jsx("span",{className:"font-medium text-dark-text",children:u("chat.queuedCount",{count:j.length})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:(en=j[0])==null?void 0:en.content,children:(tn=j[0])==null?void 0:tn.content}),e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted/60",children:u("chat.queuedEscHint")}),e.jsx("button",{onClick:te,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:u("chat.queuedRevoke"),"aria-label":u("chat.queuedRevoke"),children:e.jsx($e,{size:12,"aria-hidden":"true"})})]}),N.length>0&&e.jsx("div",{className:`${Rt} mb-2 flex flex-wrap gap-1.5`,children:N.map(m=>{const v=Ac(m.name),I=m.imageDataUri,P=e.jsxs(e.Fragment,{children:[I?e.jsx(Ri,{src:I,name:m.name,size:13,hoverPreview:!1}):m.uploading?e.jsx(Me,{size:13,className:"animate-spin"}):e.jsx(v,{size:13}),e.jsx("span",{className:"max-w-[140px] truncate",children:m.name}),e.jsx("span",{className:"text-[10px] text-dark-muted",children:m.size>1024*1024?`${(m.size/1024/1024).toFixed(1)} MB`:`${Math.max(1,Math.round(m.size/1024))} KB`}),!m.uploading&&e.jsx("button",{onClick:()=>Ar(m.id),className:"rounded p-0.5 text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors","aria-label":u("a11y.close"),children:e.jsx($e,{size:11})})]}),L=de("flex items-center gap-1.5 rounded-lg border px-2 py-1 text-xs transition-colors",m.error?"border-accent-red/40 bg-accent-red/5 text-accent-red":m.uploading?"border-accent-blue/40 bg-accent-blue/5 text-accent-blue":"border-dark-border bg-dark-surface text-dark-text",I&&"cursor-zoom-in hover:border-accent-blue/40");return I?e.jsx(zs,{src:I,alt:m.name,className:"min-w-0",children:e.jsx("div",{className:L,children:P})},m.id):e.jsx("div",{className:L,children:P},m.id)})}),O&&e.jsx("div",{className:`${Rt} mb-2 rounded-xl border-2 border-dashed border-accent-blue/50 bg-accent-blue/5 py-3 text-center text-xs text-accent-blue`,children:u("fileJob.dropHint")}),e.jsxs("div",{className:`chat-composer-card relative rounded-xl border transition-all duration-150 ${Rt}`,children:[ge&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!ge,children:e.jsx(tc,{isOpen:ge,items:Ve,selectedIndex:Wt,query:bt,isSearching:yr,onSelect:Yt,onHover:Pe,selectedCount:wr,onFinish:rt,tabs:Be,activeTab:Vt,onTabChange:Nt,scope:Ls,onToggleScope:Jt,deliveryMode:tt,onToggleDelivery:Et})}),ae&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!ae,children:e.jsx(vc,{isOpen:ae,commands:T,selectedIndex:X,filter:le,onSelect:Zt,onHover:ce,containerRef:gt})}),e.jsx("textarea",{ref:f,value:x,onChange:Mr,onKeyDown:$r,onPaste:zr,onBlur:()=>{ge&&rt(),F()},onCompositionStart:Or,onCompositionEnd:Pr,placeholder:u(p?"chat.generatingPlaceholder":"chat.inputPlaceholder"),rows:1,"aria-label":"Message input",className:`w-full bg-transparent px-4 pt-4 pb-3 text-sm text-dark-text placeholder-dark-muted/60
45
- resize-none focus:outline-none min-h-[72px] max-h-[40vh] leading-relaxed`}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5 px-3 pb-3 lg:flex-nowrap",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-x-2",children:[h&&e.jsx(Hl,{workspaceDir:d,onSelect:h}),e.jsx(Ol,{}),e.jsx("span",{className:"hidden min-w-0 sm:block",children:e.jsx(Pl,{})}),Fs.length>0&&e.jsx("button",{type:"button",onClick:Et,className:de("flex h-8 min-w-0 items-center rounded-full px-2.5 text-[11px] font-medium transition-colors",tt==="enqueue"?"text-dark-muted hover:bg-dark-hover hover:text-dark-text":"bg-accent-blue/10 text-accent-blue"),title:u("chat.mentionDeliveryHint"),children:e.jsx("span",{className:"max-w-[180px] truncate",children:u("chat.mentionDeliveryChip",{titles:Fs.join("、"),mode:u(tt==="direct"?"chat.mentionDeliveryDirect":tt==="next-step"?"chat.mentionDeliveryNextStep":"chat.mentionDeliveryEnqueue")})})})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[Xt>0&&x.length>0&&e.jsxs("span",{className:`text-[10px] tabular-nums ${Ys?"text-accent-red font-medium":"text-dark-muted/60"}`,children:["~",Xt," tokens",Ys?` · ${u("chat.nearLimit")}`:""]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("div",{ref:M,className:"relative",children:[e.jsxs("button",{onClick:()=>se(m=>!m),disabled:z.state!=="idle"||p,className:`flex h-8 items-center justify-center gap-0.5 rounded-full px-2 text-[11px] font-semibold text-dark-muted transition-colors
46
- hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed`,title:u(p?"stt.generatingTitle":"stt.langToggle"),"aria-label":u(p?"stt.generatingTitle":"stt.langToggle"),"aria-haspopup":"listbox","aria-expanded":Q,children:[Xa(w).short,e.jsx(Kn,{size:11,"aria-hidden":"true"})]}),Q&&e.jsxs("div",{role:"listbox","aria-label":u("stt.langToggle"),className:"absolute bottom-full right-0 mb-2 z-50 w-44 rounded-lg border border-dark-border bg-dark-surface shadow-lg py-1 max-h-72 overflow-auto custom-scrollbar",children:[Qa.map(m=>e.jsxs("button",{role:"option","aria-selected":m.code===w,onClick:()=>W(m.code),className:de("flex w-full items-center justify-between gap-2 px-3 py-1.5 text-xs transition-colors",m.code===w?"text-accent-blue bg-accent-blue/10":"text-dark-text hover:bg-dark-hover"),children:[e.jsx("span",{className:"font-medium",children:m.label}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-dark-muted",children:[m.code==="zh"?"FunASR":"Whisper",m.code===w&&e.jsx(Ye,{size:12,"aria-hidden":"true"})]})]},m.code)),e.jsx("div",{className:"mt-1 border-t border-dark-border px-3 pt-1.5 pb-0.5 text-[10px] leading-relaxed text-dark-muted/70",children:u("stt.multiHint")})]})]}),e.jsx("button",{onClick:()=>void oe(),disabled:z.state==="transcribing"||p,className:de("flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors",z.state==="recording"?"bg-accent-red/15 text-accent-red animate-pulse":"hover:bg-dark-hover hover:text-dark-text","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent"),title:p?u("stt.generatingTitle"):z.state==="recording"?u("stt.stopTitle"):u("stt.title"),"aria-label":p?u("stt.generatingTitle"):z.state==="recording"?u("stt.stopTitle"):u("stt.title"),children:z.state==="transcribing"?e.jsx(Me,{size:15,className:"animate-spin","aria-hidden":"true"}):z.state==="recording"?e.jsx(ua,{size:15,"aria-hidden":"true"}):e.jsx(ha,{size:15,"aria-hidden":"true"})}),z.state==="recording"&&e.jsxs("span",{className:"text-[10px] tabular-nums text-accent-red","aria-hidden":"true",children:[(z.elapsedMs/1e3).toFixed(0),"s"]})]}),!p&&e.jsx("button",{onClick:()=>H(!0),className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:u("skills.pickTitle"),"aria-label":u("skills.pickTitle"),children:e.jsx(ma,{size:15,"aria-hidden":"true"})}),!p&&e.jsx("button",{onClick:()=>void Mt(),disabled:A,className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed",title:`${u("fileJob.screenshot")} (${es}+Shift+S)`,"aria-label":`${u("fileJob.screenshot")} (${es}+Shift+S)`,children:A?e.jsx(Me,{size:15,className:"animate-spin","aria-hidden":"true"}):e.jsx(xa,{size:15,"aria-hidden":"true"})}),!p&&e.jsx("button",{onClick:()=>ne(!0),className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:"Generate terminal verdict figure","aria-label":"Generate terminal verdict figure",children:e.jsx(ut,{size:15,"aria-hidden":"true"})}),!p&&e.jsx("button",{onClick:()=>void Ir(),className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:u("fileJob.attach"),"aria-label":u("fileJob.attach"),children:e.jsx(Pn,{size:15,"aria-hidden":"true"})}),e.jsx("input",{ref:k,type:"file",multiple:!0,accept:Ec,className:"hidden",onChange:Tr}),p&&!Zs?e.jsxs("div",{className:"flex items-center gap-1.5",children:[b?e.jsx("button",{onClick:l,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-green text-white transition-all hover:opacity-85 active:scale-95",title:u("chat.resumeGen"),"aria-label":u("chat.resumeGen"),children:e.jsx(fa,{size:14,"aria-hidden":"true"})}):e.jsx("button",{onClick:a,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-yellow text-white transition-all hover:opacity-85 active:scale-95",title:u("chat.pauseGen"),"aria-label":u("chat.pauseGen"),children:e.jsx(pa,{size:14,"aria-hidden":"true"})}),e.jsx("button",{onClick:i,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-red text-white transition-all hover:opacity-85 active:scale-95",title:u("chat.stopGen"),"aria-label":u("chat.stopGen"),children:e.jsx(nn,{size:13,"aria-hidden":"true"})})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[p&&e.jsx("button",{onClick:i,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-red/80 text-white transition-all hover:opacity-85 active:scale-95",title:u("chat.stopGen"),"aria-label":u("chat.stopGen"),children:e.jsx(nn,{size:13,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>void Ct(),disabled:!Zs,className:`flex h-8 w-8 items-center justify-center rounded-full bg-dark-text text-dark-bg transition-all
47
- hover:opacity-80 active:scale-95 disabled:opacity-25 disabled:cursor-not-allowed`,title:u(p?"chat.sendQueuedBtn":"chat.sendBtn"),"aria-label":u(p?"chat.sendQueuedBtn":"chat.sendBtn"),children:e.jsx(Bn,{size:15,"aria-hidden":"true"})})]})]})]})]}),e.jsxs("div",{className:"mt-1.5 hidden select-none items-center justify-center gap-3 text-[10px] text-dark-muted/55 sm:flex",children:[e.jsx("span",{children:u("chat.shiftEnter")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:u("chat.escHint")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:`${es}+Shift+S ${u("shortcuts.screenshot")}`}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:u("chat.bangHint")})]}),e.jsx(jc,{isOpen:G,onClose:()=>ne(!1)}),e.jsx(sc,{open:_,onClose:()=>H(!1),onSelect:Cr})]})}),$c=o.memo(function({activeSessionId:s}){const{t:n}=ee(),i=Ua(a=>a.observed).filter(a=>a.id!==s);return i.length===0?null:e.jsxs("div",{className:"mb-2 flex flex-col gap-1.5",children:[i.map(a=>e.jsx(Oc,{id:a.id,title:a.title},a.id)),e.jsx("span",{className:"sr-only",children:n("chat.observedTitle")})]})});function Oc({id:t,title:s}){const{t:n}=ee(),r=xe(c=>{var d;return((d=c.generatingSessions)==null?void 0:d.includes(t))??!1}),i=xe(c=>{const d=c.messagesBySession[t],h=d&&d.length>0?d[d.length-1]:void 0;return!!(h!=null&&h.errorCard)}),a=xe(c=>{const d=c.messagesBySession[t];if(!d||d.length===0)return"";for(let h=d.length-1;h>=0;h--){const u=d[h];if(u.type==="user")continue;const x=u.content||"";if(x.trim())return x.trim().slice(-160)}return""}),l=n(r?"chat.observedRunning":i?"chat.observedFailed":"chat.observedDone");return e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs",children:[e.jsx(Hn,{size:13,className:"shrink-0 text-accent-blue","aria-hidden":"true"}),e.jsx("span",{className:"max-w-[180px] truncate font-medium text-dark-text",title:s,children:s}),e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted",children:t.slice(0,8)}),r?e.jsx(Me,{size:12,className:"shrink-0 animate-spin text-accent-yellow","aria-hidden":"true"}):i?e.jsx($n,{size:12,className:"shrink-0 text-accent-red","aria-hidden":"true"}):e.jsx(zt,{size:12,className:"shrink-0 text-accent-green","aria-hidden":"true"}),e.jsx("span",{className:`shrink-0 text-[10px] ${i?"text-accent-red":r?"text-accent-yellow":"text-accent-green"}`,children:l}),a&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:a,children:a})]})}const Pc=15e3,Lc=300;function jr(t){const{t:s}=ee();return o.useMemo(()=>{const n=s("chat.askOtherLabel"),r=s("chat.askProceedLabel"),i=t.options||[],a=i.some(u=>u.label===n),l=i.some(u=>u.label===r),c=[...i];l||c.push({label:r,description:s("chat.askProceedDesc")}),a||c.push({label:n,description:s("chat.askCustomDesc")});const d=a?c.findIndex(u=>u.label===n):c.length-1,h=l?c.findIndex(u=>u.label===r):c.length-(a?1:2);return{allItems:c,otherIdx:d,proceedIdx:h,displayItems:c}},[t,s])}function In({item:t,answered:s,selectedIdx:n,multiSelected:r,customInput:i,showCustomInput:a,onSelect:l,onToggleMulti:c,onProceed:d,onEnterCustom:h,onCancelCustom:u,onSubmitCustom:x,onCustomChange:g,inputRef:p}){const{t:b}=ee(),{otherIdx:j,proceedIdx:y,displayItems:f}=jr(t),k=!!t.multiSelect,D=S=>{if(S===y){d();return}if(S===j){h();return}if(k){c(S);return}l(S)};return e.jsxs("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:[f.map((S,N)=>{const R=n===N,O=r.has(N),C=N===j;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:`w-full text-left px-3 py-2 rounded-md text-sm transition-colors ${R?"bg-blue-50 dark:bg-blue-900/20 border border-blue-300 dark:border-blue-700":"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-750"}`,onClick:()=>D(N),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[k&&e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center text-[10px] ${O?"bg-blue-600 border-blue-600 text-white":"border-gray-400 dark:border-gray-500"}`,children:O&&e.jsx(Ye,{size:10})}),e.jsxs("span",{className:`font-medium ${R?"text-blue-700 dark:text-blue-300":"text-gray-800 dark:text-gray-200"}`,children:[k?"":`${N+1}. `,S.label]}),N===y&&e.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:b("chat.askDirectTag")}),C&&e.jsx("span",{className:"text-xs text-gray-400",children:b("chat.askCustomTag")})]}),S.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 ml-6",children:S.description})]}),C&&R&&a&&e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("textarea",{ref:p,className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none",rows:3,value:i,onChange:A=>g(A.target.value),onKeyDown:A=>{A.key==="Enter"&&!A.shiftKey&&(A.preventDefault(),x()),A.key==="Escape"&&u()},placeholder:b("chat.askAnswerPlaceholder"),autoFocus:!0}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700",onClick:x,children:[e.jsx(Qe,{size:12}),b("chat.askSubmit")]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium text-gray-600 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 rounded-md hover:bg-gray-200 dark:hover:bg-gray-600",onClick:u,children:[e.jsx($e,{size:12}),b("common.cancel")]})]})]})]},`opt-${N}`)}),s&&e.jsx("div",{className:"text-xs text-emerald-600 dark:text-emerald-400 font-medium",children:b("chat.askAnswered")})]})}function Fc({isOpen:t,onClose:s}){const{t:n}=ee(),[r,i]=o.useState(null),[a,l]=o.useState(-1),[c,d]=o.useState(new Set),[h,u]=o.useState(""),[x,g]=o.useState(!1),[p,b]=o.useState(!1),[j,y]=o.useState(!1),[f,k]=o.useState(0),[D,S]=o.useState([]),[N,R]=o.useState(!1),O=o.useRef(null),C=o.useRef(null),A=o.useMemo(()=>r?r.questions&&r.questions.length>0?r.questions:[{question:r.question,header:r.header,options:r.options,multiSelect:r.multiSelect}]:[],[r]),B=A.length>1,_=o.useCallback(T=>{i(T),l(T.multiSelect?-1:0),d(new Set),u(""),g(!1),b(!1),y(!1),k(0),R(!1);const X=T.questions&&T.questions.length>0?T.questions:[T];S(X.map(()=>null))},[]);o.useEffect(()=>{C.current=r}),o.useEffect(()=>{if(t){const T=window.__pendingQuestion;T&&_(T)}},[t,_]),o.useEffect(()=>{const T=X=>{var E;const ce=X.detail,je=((E=C.current)==null?void 0:E.questionId)??null;if(ce&&je&&ce!==je)return;const ye=je;b(!0),setTimeout(()=>{var F;const re=((F=C.current)==null?void 0:F.questionId)??null;ye&&re&&re!==ye||(s(),i(null),b(!1))},Lc)};return window.addEventListener("ask-question-dismiss",T),()=>window.removeEventListener("ask-question-dismiss",T)},[s]),o.useEffect(()=>{if(!p)return;const T=setTimeout(()=>{b(!1),y(!0)},Pc);return()=>clearTimeout(T)},[p]),o.useEffect(()=>{const T=()=>y(!1);return window.addEventListener("ask-question-dismiss",T),()=>window.removeEventListener("ask-question-dismiss",T)},[]),o.useEffect(()=>{const T=()=>{const X=window.__pendingQuestion;X&&_(X)};return window.addEventListener("ask-question-required",T),()=>window.removeEventListener("ask-question-required",T)},[_]),o.useEffect(()=>{l(0),d(new Set),u(""),g(!1)},[f,N,r]);const H=A[f]||null,{allItems:G,otherIdx:ne}=jr(H||{question:""}),te=o.useCallback((T,X)=>{p||!r||(y(!1),b(!0),pe.send({type:"question_answer",sessionId:r.sessionId||pe.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answer:T,selectedOptions:X})}))},[p,r]),V=o.useCallback(()=>{p||!r||(y(!1),b(!0),pe.send({type:"question_answer",sessionId:r.sessionId||pe.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:A.map((T,X)=>D[X]||{answer:n("chat.askUnansweredValue")})})}))},[p,r,A,D,n]),w=o.useCallback((T,X,ce)=>{S(je=>{const ye=je.slice();return ye[T]={answer:X,selectedOptions:ce},ye}),T<A.length-1?k(T+1):R(!0)},[A.length]),U=o.useCallback(T=>{if(p||!r)return;const X=G[T];X&&(l(T),te(X.label,[X.label]))},[p,r,G,te]),Q=o.useCallback(()=>{if(p||!r||a<0)return;const T=G[a];T&&te(T.label,[T.label])},[p,r,a,G,te]),se=o.useCallback(()=>{if(p||a<0)return;const T=G[a];T&&w(f,T.label,[T.label])},[p,a,G,w,f]),M=o.useCallback(T=>{if(p)return;const X=G[T];X&&w(f,X.label,[X.label])},[p,G,w,f]),W=o.useCallback(T=>{p||d(X=>{const ce=new Set(X);return ce.has(T)?ce.delete(T):ce.add(T),ce})},[p]),z=o.useCallback(()=>{if(p)return;const T=[...c].map(X=>{var ce;return((ce=G[X])==null?void 0:ce.label)||""});B?w(f,T.join(", "),T):te(T.join(", "),T)},[p,c,G,B,w,f,te]),$=o.useCallback(()=>{if(p)return;const T=n("chat.askProceedLabel");B?w(f,T,[T]):te(T,[T])},[p,B,w,f,te,n]),K=o.useCallback(()=>{p||(l(ne),g(!0),setTimeout(()=>{var T;return(T=O.current)==null?void 0:T.focus()},100))},[p,ne]),Z=o.useCallback(()=>{g(!1),u("")},[]),oe=o.useCallback(()=>{if(p)return;const T=h||n("chat.askEmptyInputValue");B?w(f,T):te(T)},[p,h,B,w,f,te,n]),ue=o.useCallback(()=>{p||!r||(y(!1),b(!0),pe.send({type:"question_answer",sessionId:r.sessionId||pe.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:A.map(()=>({answer:"(cancelled)"}))})}))},[p,r,A]),ae=o.useCallback(()=>{if(!p){if(B){if(x){g(!1),u("");return}if(N){R(!1),k(A.length-1);return}ue();return}if(x){g(!1),u("");return}te("(cancelled)")}},[p,B,x,N,A.length,ue,te]);if(!t||!r)return null;const le=D.filter(T=>!T).length;return e.jsx(Zn,{isOpen:t,onClose:ae,title:r.header||n(B?"chat.askBatchTitle":"chat.askSingleTitle"),badge:e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-accent-blue shrink-0",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-blue animate-pulse"}),n("chat.askPendingBadge"),B?` · ${D.filter(Boolean).length}/${A.length}`:""]}),collapsedSummary:e.jsx("span",{className:"truncate",children:(H==null?void 0:H.question)||r.question}),maxHeight:"50vh",children:B?e.jsxs("div",{className:"flex flex-col gap-4",children:[r.autoResolutionMs&&r.autoResolutionMs>0&&e.jsx("div",{className:"flex items-center gap-2 text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-md px-3 py-1.5",children:n("chat.askAutoContinue",{seconds:Math.max(1,Math.round(r.autoResolutionMs/1e3))})}),e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[A.map((T,X)=>{const ce=!!D[X],je=!N&&f===X;return e.jsxs("button",{type:"button",onClick:()=>{k(X),R(!1)},className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${je?"bg-blue-600 text-white":ce?"bg-emerald-50 dark:bg-emerald-900/20 text-emerald-700 dark:text-emerald-300":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:["Q",X+1," ",ce?"✓":""]},`nav-${X}`)}),e.jsx("button",{type:"button",onClick:()=>R(!0),className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${N?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:n("chat.askSubmit")})]}),N?e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-gray-800 dark:text-gray-200",children:n("chat.askReviewTitle")}),A.map((T,X)=>{const ce=D[X];return e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed min-w-0",children:[e.jsxs("span",{className:"font-medium",children:[X+1,". "]}),T.question]}),e.jsx("div",{className:`text-xs shrink-0 max-w-[45%] text-right break-words ${ce?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dark:text-amber-400"}`,children:ce?ce.answer:n("chat.askNotAnswered")})]},`rev-${X}`)}),le>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-md px-3 py-2",children:[e.jsx(Te,{size:14}),n("chat.askUnansweredWarning",{count:le})]}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50",onClick:V,disabled:p,children:[e.jsx(Qe,{size:14}),n("chat.askSubmitAll")]}),e.jsx("button",{type:"button",className:"inline-flex items-center gap-1 px-4 py-2 text-sm font-medium text-gray-600 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 rounded-md hover:bg-gray-200 dark:hover:bg-gray-600",onClick:()=>{R(!1),k(A.length-1)},disabled:p,children:n("chat.askBackToEdit")})]})]}):H?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed min-w-0",children:H.question}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-0.5 px-2 py-1 text-xs text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-800 rounded-md hover:bg-gray-200 dark:hover:bg-gray-700 disabled:opacity-40",onClick:()=>{k(T=>Math.max(0,T-1)),R(!1)},disabled:f===0,children:[e.jsx(ba,{size:12}),n("chat.askPrevQuestion")]}),f<A.length-1?e.jsxs("button",{type:"button",className:"inline-flex items-center gap-0.5 px-2 py-1 text-xs text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-gray-800 rounded-md hover:bg-gray-200 dark:hover:bg-gray-700",onClick:()=>{k(T=>Math.min(A.length-1,T+1)),R(!1)},children:[n("chat.askNextQuestion"),e.jsx(Oe,{size:12})]}):e.jsxs("button",{type:"button",className:"inline-flex items-center gap-0.5 px-2 py-1 text-xs font-medium text-blue-700 dark:text-blue-300 bg-blue-50 dark:bg-blue-900/20 rounded-md hover:bg-blue-100 dark:hover:bg-blue-900/30",onClick:()=>R(!0),children:[n("chat.askViewSubmit"),e.jsx(Oe,{size:12})]})]})]}),e.jsx(In,{item:H,answered:!!D[f],selectedIdx:a,multiSelected:c,customInput:h,showCustomInput:x,onSelect:M,onToggleMulti:W,onProceed:$,onEnterCustom:K,onCancelCustom:Z,onSubmitCustom:oe,onCustomChange:u,inputRef:O}),!x&&e.jsx("div",{className:"flex items-center gap-2",children:H.multiSelect?e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",onClick:z,disabled:p||c.size===0,children:[e.jsx(Qe,{size:14}),n("chat.askFinishQuestion",{count:c.size})]}):e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",onClick:se,disabled:p||a<0,children:[e.jsx(Qe,{size:14}),n("chat.askConfirmQuestion")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:x?e.jsx("span",{children:n("chat.askEnterHint")}):H.multiSelect?e.jsx("span",{children:n("chat.askMultiHintBatch")}):e.jsx("span",{children:n("chat.askSingleHintBatch")})})]}):null]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[r.autoResolutionMs&&r.autoResolutionMs>0&&e.jsx("div",{className:"flex items-center gap-2 text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-md px-3 py-1.5",children:n("chat.askAutoContinue",{seconds:Math.max(1,Math.round(r.autoResolutionMs/1e3))})}),e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed",children:r.question}),e.jsx(In,{item:A[0],answered:!1,selectedIdx:a,multiSelected:c,customInput:h,showCustomInput:x,onSelect:U,onToggleMulti:W,onProceed:$,onEnterCustom:K,onCancelCustom:Z,onSubmitCustom:oe,onCustomChange:u,inputRef:O}),!x&&e.jsx("div",{className:"flex items-center gap-2",children:r.multiSelect?e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",onClick:z,disabled:p||c.size===0,children:[e.jsx(Qe,{size:14}),n("chat.askSubmitSelected",{count:c.size})]}):e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",onClick:Q,disabled:p||a<0,children:[e.jsx(Qe,{size:14}),n("chat.askSubmit")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:p?e.jsx("span",{children:n("chat.askSubmitting")}):j?e.jsxs("span",{className:"flex items-center gap-1.5 text-amber-600 dark:text-amber-400",children:[e.jsx(Te,{size:12}),n("chat.askSubmitRetry")]}):x?e.jsx("span",{children:n("chat.askEnterHint")}):r.multiSelect?e.jsx("span",{children:n("chat.askMultiHintSingle")}):e.jsx("span",{children:n("chat.askSingleHintSingle")})})]})})}const lt=15;function Bc({isOpen:t,onCloseModal:s}){const{t:n}=ee("hook"),r=Ns(),i=r.pendingApprovals,a=r.autoMode,l=r.setAutoMode,[c,d]=o.useState(0),[h,u]=o.useState(!1),[x,g]=o.useState(lt),[p,b]=o.useState(!0),j=o.useRef(null),y=o.useRef(!1);o.useEffect(()=>{if(i.length!==0){if(a){i.forEach(le=>{pe.send({type:"hook_allow",data:JSON.stringify({approvalId:le.approvalId})})}),r.clearApprovals();return}d(le=>Math.min(le,i.length-1))}},[i.length,a]);const f=i[c]??null,k=i.length>0&&f!==null,D=i.length,S=k?D-c-1:0;o.useEffect(()=>{if(!(!k||h||!t||!f))return g(lt),j.current=setInterval(()=>{g(le=>le<=1?(j.current&&clearInterval(j.current),0):le-1)},1e3),()=>{j.current&&clearInterval(j.current)}},[k,h,t,f==null?void 0:f.approvalId]);const N=f?Wn(f.toolName,f.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},R=Un[N.level],O=Ga[N.level==="CRITICAL"?"critical":N.level==="HIGH"?"high":N.level==="LOW"?"low":"medium"],C=f?cr(f.toolName,f.askPayload):null,A=f?Ja(f.toolName,f.askPayload):null,B=f?{verb:or(f.toolName),target:lr(f.toolName,f.askPayload)}:null,_=f?xt(f.askPayload)!==null:!1,H=f?dr(f.toolName,f.askPayload):null,G=x/lt*100,ne=x<=5,te=Va(lt-x),V=o.useCallback((le,T)=>{const X=Qn.getState().activeSessionId;X&&xe.getState().updateHookApprovalStatus(X,le,T)},[]),w=o.useCallback(le=>{f&&(le&&V(f.approvalId,le),u(!0),setTimeout(()=>{r.removeApproval(f.approvalId),d(0),u(!1),y.current=!1,g(lt)},200))},[f==null?void 0:f.approvalId,r,V]),U=o.useCallback(()=>{!f||h||y.current||(y.current=!0,j.current&&clearInterval(j.current),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:f.approvalId})}),w("approved"))},[f,w,h]),Q=o.useCallback(()=>{!f||h||y.current||(y.current=!0,j.current&&clearInterval(j.current),pe.send({type:"hook_deny",data:JSON.stringify({approvalId:f.approvalId})}),w("denied"))},[f,w,h]),se=o.useCallback(()=>{if(!f||h||y.current)return;y.current=!0,j.current&&clearInterval(j.current);const le=xt(f.askPayload);le?(r.addToSessionAllowList(f.toolName,le),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:f.approvalId,sessionAllow:!0})})):(r.addToSessionAllowList(f.toolName),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:f.approvalId})})),w("approved")},[f,w,r,h]),M=o.useCallback(()=>{!f||h||y.current||(y.current=!0,j.current&&clearInterval(j.current),l(!0),qe.getState().setAuto(!0),pe.send({type:"hook_allow",data:JSON.stringify({approvalId:f.approvalId})}),w("approved"))},[f,w,h,l]),W=((f==null?void 0:f.timeoutMs)??15e3)>0,z=(f==null?void 0:f.timeoutAction)==="deny"?Q:U;if(o.useEffect(()=>{x===0&&t&&!h&&f&&W&&z()},[x,t,h,f,z,W]),o.useEffect(()=>{if(!t||!p)return;const le=T=>{const X=T.target;X&&typeof X.closest=="function"&&X.closest('input, textarea, select, [contenteditable="true"]')||(T.key==="Escape"?(T.preventDefault(),T.stopPropagation(),Q()):T.key==="Enter"?(T.preventDefault(),U()):T.key==="1"?U():T.key==="2"?Q():T.key==="3"?se():T.key==="4"&&M())};return window.addEventListener("keydown",le),()=>window.removeEventListener("keydown",le)},[t,p,U,Q,se,M]),!k||!f)return null;const $=n("optionAllowHint"),K=n("optionDenyHint"),Z=_?n("optionAllowPathHint"):n("optionAllowAlwaysHint",{tool:f.toolName}),oe=n("optionAutoModeHint"),ue=(C==null?void 0:C.text)??A??null,ae=ue?e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("code",{className:"font-mono text-[11px] bg-dark-surface text-accent-blue px-1 py-0.5 rounded shrink-0",children:f.toolName}),e.jsx("span",{className:"truncate",children:ue})]}):null;return e.jsx(Zn,{isOpen:t,onClose:()=>s==null?void 0:s(),title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vs,{className:"w-4 h-4 text-yellow-400"}),e.jsx("span",{children:n("hookApproval")}),e.jsxs("span",{className:"text-xs text-dark-muted",children:["(",c+1,"/",D,")"]})]}),badge:e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${R.badge}`,children:[R.icon," ",N.level]}),collapsedSummary:ae,onExpandedChange:b,maxHeight:"50vh",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${R.bg} border ${R.border}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${R.badge}`,children:[R.icon," ",N.level]}),e.jsx("span",{className:"text-xs text-dark-muted truncate",children:n(N.reasonKey)}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[e.jsx(ht,{size:12,className:ne?"text-accent-red":"text-dark-muted"}),e.jsx("span",{className:`text-xs font-mono ${ne?"text-accent-red animate-pulse":"text-dark-muted"}`,children:W?`${x}s`:"∞"}),e.jsx("div",{className:"w-12 h-1.5 bg-dark-border rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${ne?"bg-accent-red":x<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${G}%`}})})]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx("span",{className:"flex-none w-7 h-7 rounded-lg bg-accent-blue/10 text-accent-blue inline-flex items-center justify-center",children:e.jsx(vs,{size:15})}),B&&e.jsx(ur,{pre:n(B.verb),obj:B.target})]}),H&&(H.external&&H.path?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/30 shrink-0",title:H.path,children:[e.jsx(Cs,{size:10}),n("scopeExternal"),": ",H.path.length>48?`${H.path.slice(0,47)}…`:H.path]}):e.jsx("span",{className:"text-[11px] text-dark-muted/60 shrink-0",children:n("scopeLocal")}))]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-dark-muted shrink-0",children:n("tool")}),e.jsx("code",{className:"text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate",children:f.toolName}),e.jsx("span",{className:"text-dark-muted/50",children:te}),e.jsx("span",{className:"text-dark-muted/50",children:O.label}),f.timeoutAction&&e.jsxs("span",{className:`text-xs ${f.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",W?`${f.timeoutAction==="allow"?"auto-allow":"auto-deny"}${f.timeoutMs?` (${(f.timeoutMs/1e3).toFixed(0)}s)`:""}`:n("timeoutWaitUser")]})]}),C?e.jsx(Es,{text:C.text,mono:C.mono}):A?e.jsx(Es,{text:A}):null,(N.level==="CRITICAL"||N.level==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${R.bg} ${R.text}`,children:[e.jsx(Te,{size:13}),e.jsx("span",{children:N.level==="CRITICAL"?n("highRiskWarning"):n("mediumRiskConfirm")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:U,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-accent-blue text-white text-sm font-medium hover:opacity-90 shadow-sm transition-all disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono bg-white/20 rounded px-1",children:"1"}),e.jsx("span",{children:It.allow.label}),e.jsx("span",{className:"text-[11px] text-white/70 hidden sm:inline",children:$})]}),e.jsxs("button",{onClick:se,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono text-dark-muted bg-dark-surface rounded px-1",children:"3"}),e.jsx("span",{children:It.allow_session.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:Z})]}),e.jsxs("button",{onClick:M,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono text-dark-muted bg-dark-surface rounded px-1",children:"4"}),e.jsx("span",{children:It.auto.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:oe})]}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:Q,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-dark-muted hover:bg-red-500/10 hover:text-red-400 text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono text-dark-muted/60 rounded px-1",children:"2"}),e.jsx("span",{children:It.deny.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:K})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-dark-muted/60",children:[e.jsx("span",{children:n("shortcutHint")}),e.jsx("span",{children:S>0?n("morePending",{n:S}):n("lastItem")})]})]})})}const ks="dsc-auto-access-banner-dismissed",Hc=o.memo(function(){const{t:s}=ee(),n=qe(c=>c.mode),[r,i]=o.useState(()=>localStorage.getItem(ks)==="1");o.useEffect(()=>{Ss(n==="normal"?"act":n)||localStorage.getItem(ks)==="1"&&i(!1)},[n]);const a=o.useCallback(c=>{c&&localStorage.setItem(ks,"1"),i(!0)},[]);return!(n!=="normal"&&Ss(n))||r?null:e.jsxs("div",{className:"flex items-center gap-1.5 px-4 py-1 text-[10.5px] leading-snug text-accent-yellow/75 bg-accent-yellow/[0.05] border-b border-accent-yellow/10 select-none",role:"note",title:s("autoAccess.desc"),children:[e.jsx(ka,{size:11,className:"shrink-0 text-accent-yellow/70"}),e.jsxs("div",{className:"min-w-0 flex-1 truncate",children:[e.jsx("span",{className:"font-medium",children:s("autoAccess.title")}),e.jsxs("span",{className:"text-accent-yellow/60",children:[" · ",s("autoAccess.desc")]})]}),e.jsx("button",{onClick:()=>a(!1),className:"shrink-0 rounded p-0.5 text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors",title:s("autoAccess.dismiss"),"aria-label":s("autoAccess.dismiss"),children:e.jsx($e,{size:11})}),e.jsx("button",{onClick:()=>a(!0),className:"shrink-0 rounded px-1 py-px text-[9.5px] text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors whitespace-nowrap",children:s("autoAccess.neverShow")})]})}),An=24,Rn=320,Kc={pending:{color:"text-gray-400",bg:"bg-gray-500/10",label:"Pending"},running:{color:"text-blue-400",bg:"bg-blue-500/10",label:"Running"},completed:{color:"text-green-400",bg:"bg-green-500/10",label:"Done"},failed:{color:"text-red-400",bg:"bg-red-500/10",label:"Failed"},skipped:{color:"text-gray-500",bg:"bg-gray-500/5",label:"Skipped"}},qc=({status:t})=>t==="running"?e.jsx(Me,{size:12,className:"animate-spin text-accent-blue"}):t==="completed"?e.jsx(zt,{size:12,className:"text-accent-green"}):t==="failed"?e.jsx(ya,{size:12,className:"text-accent-red"}):t==="skipped"?e.jsx(wa,{size:12,className:"text-dark-muted"}):e.jsx(Na,{size:12,className:"text-dark-muted"}),_n={workflow:"WF",goal:"Goal",plan:"Plan",task:"Task",todo:"Todo",agent:"Agent"};function Wc(t){const s=new Map;for(const a of t)s.set(a.id,a);const n=new Map,r=[];for(const a of t){const c=a.source==="goal"&&a.dependencies&&a.dependencies[0]||void 0;if(c&&s.has(c)){const d=n.get(c)??[];d.push(a),n.set(c,d)}else r.push(a)}const i=(a,l)=>{const c=(n.get(a.id)??[]).filter(d=>!l.has(d.id)).map(d=>i(d,new Set(l).add(a.id)));return{task:a,children:c}};return r.map(a=>i(a,new Set))}const Uc=o.memo(function t({node:s,depth:n}){const{task:r,children:i}=s,a=Kc[r.status],l=o.useMemo(()=>{if(!r.startedAt)return"";const c=(r.completedAt||Date.now())-r.startedAt;return c<1e3?`${c}ms`:`${(c/1e3).toFixed(1)}s`},[r.startedAt,r.completedAt]);return e.jsxs("li",{className:"min-w-0",children:[e.jsx("div",{className:`rounded border p-2 transition-colors ${a.bg} border-dark-border`,style:{marginLeft:n*14},children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qc,{status:r.status}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-medium text-dark-text break-words",children:r.title}),r.agentType&&e.jsx("span",{className:"rounded bg-dark-surface px-1 py-px font-mono text-[9.5px] text-accent-blue/90",children:r.agentType}),e.jsx("span",{className:`text-[10px] ${a.color} shrink-0`,children:a.label}),r.source&&_n[r.source]&&e.jsx("span",{className:"rounded bg-dark-surface/80 px-1 py-px text-[9px] text-dark-muted",children:_n[r.source]}),l&&e.jsx("span",{className:"text-[10px] text-dark-muted",children:l})]}),r.description&&e.jsx("p",{className:"mt-1 text-[11px] leading-snug text-dark-muted break-words",children:r.description}),r.status==="running"&&r.progress!==void 0&&e.jsx("div",{className:"mt-1.5",children:e.jsx("div",{className:"w-full h-1 bg-dark-bg rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent-blue rounded-full transition-all duration-500",style:{width:`${Math.max(0,Math.min(100,r.progress))}%`}})})}),r.result&&r.status==="completed"&&e.jsxs("p",{className:"mt-1 text-[11px] leading-snug text-accent-green/80 break-words",children:["→ ",r.result]}),r.error&&e.jsxs("p",{className:"mt-1 text-[11px] leading-snug text-accent-red/90 break-words",children:["✗ ",r.error]})]})]})}),i.length>0&&e.jsx("ul",{className:"mt-1 space-y-1",children:i.map(c=>e.jsx(t,{node:c,depth:n+1},c.task.id))})]})}),Gc=o.memo(function({sessionId:s,defaultExpanded:n,onClose:r}){const{t:i}=ee(),[a,l]=o.useState(n??!0),c=er(O=>O.getTasksForSession(s)),[d,h]=o.useState(null),u=o.useRef(null),x=o.useRef(!1),g=o.useRef(null),p=o.useCallback(O=>{var C;O.button===0&&(O.target.closest("[data-taskboard-close]")||(x.current=!1,u.current={y:O.clientY,expanded:a,bodyHeight:((C=g.current)==null?void 0:C.offsetHeight)??0},O.currentTarget.setPointerCapture(O.pointerId)))},[a]),b=o.useCallback(O=>{const C=u.current;C&&(Math.abs(O.clientY-C.y)>4&&(x.current=!0),h(O.clientY-C.y))},[]),j=o.useCallback(O=>{const C=u.current;if(!C)return;const A=O.clientY-C.y;C.expanded&&A<-An?l(!1):!C.expanded&&A>An&&l(!0),u.current=null,h(null),setTimeout(()=>{x.current=!1},0)},[]),y=o.useCallback(()=>{if(x.current){x.current=!1;return}l(O=>!O)},[]),f=o.useCallback(O=>{(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),l(C=>!C))},[]),k=d!==null,D=o.useMemo(()=>{const O=u.current;return d===null||!O?null:O.expanded?Math.min(Rn,Math.max(0,O.bodyHeight+d)):Math.min(Rn,Math.max(0,d))},[d]),S=o.useMemo(()=>{const O=c.length,C=c.filter(H=>H.status==="completed").length,A=c.filter(H=>H.status==="running").length,B=c.filter(H=>H.status==="failed").length,_=O>0?Math.round(C/O*100):0;return{total:O,completed:C,running:A,failed:B,progress:_}},[c]),N=o.useMemo(()=>Wc(c),[c]),R=a||k;return c.length===0?null:e.jsxs("div",{className:"w-full shrink-0 mb-2 border border-dark-border rounded-lg bg-dark-bg/70 overflow-hidden",children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":a,onClick:y,onKeyDown:f,onPointerDown:p,onPointerMove:b,onPointerUp:j,onPointerCancel:j,onLostPointerCapture:j,className:"w-full flex items-center justify-between px-2.5 py-1.5 hover:bg-dark-hover transition-colors cursor-pointer select-none touch-none",title:i("chat.taskBoardDragHint"),children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(va,{size:14,className:"text-accent-blue shrink-0"}),e.jsx("span",{className:"text-xs font-medium text-dark-text",children:"Task Board"}),e.jsxs("span",{className:"text-[10px] text-dark-muted shrink-0",children:[S.completed,"/",S.total]}),S.total>0&&e.jsx("div",{className:"w-16 h-1.5 bg-dark-surface rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${S.running>0?"bg-accent-blue":S.failed>0?"bg-accent-red":"bg-accent-green"}`,style:{width:`${S.progress}%`}})}),S.running>0&&e.jsx("span",{className:"w-1.5 h-1.5 bg-accent-blue rounded-full animate-pulse shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[r&&e.jsx("span",{role:"button",tabIndex:0,"data-taskboard-close":!0,onClick:O=>{O.stopPropagation(),r()},onKeyDown:O=>{O.key==="Enter"&&(O.stopPropagation(),r())},className:"p-0.5 rounded hover:bg-dark-hover transition-colors cursor-pointer",title:"Hide task drawer",children:e.jsx($e,{size:12,className:"text-dark-muted"})}),e.jsx(ja,{size:12,className:"text-dark-muted/40 shrink-0","aria-hidden":"true"}),a?e.jsx(Kn,{size:14,className:"text-dark-muted"}):e.jsx(et,{size:14,className:"text-dark-muted"})]})]}),R&&e.jsx("div",{ref:g,className:"border-t border-dark-border",style:D!==null?{height:D,overflow:"hidden"}:void 0,children:e.jsx("div",{className:"px-2.5 py-2 max-h-[320px] overflow-y-auto custom-scrollbar",children:N.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:i("chat.noTasks")}):e.jsx("ul",{className:"space-y-1.5",children:N.map(O=>e.jsx(Uc,{node:O,depth:0},O.task.id))})})})]})}),Jc=[{mode:"chat",Icon:Sa,labelKey:"trajectory.viewChat"},{mode:"trajectory",Icon:Ea,labelKey:"trajectory.viewTrajectory"}],nd=o.memo(function({tabs:s,activeSessionId:n,onSend:r,onStop:i,onPause:a,onResume:l,activeTab:c,setActiveTab:d,createNewSession:h,clearMessages:u,setTheme:x,setThemePreset:g,setLogs:p,setUnreadLogs:b,showTaskBoard:j=!0,onToggleTaskBoard:y,onRegenerate:f,onDeleteMessage:k,onOpenSidebarView:D,hookDrawerOpen:S,onCloseHookDrawer:N,questionDrawerOpen:R,onCloseQuestionDrawer:O,workspaceDir:C,onWorkspaceSelect:A}){const B=o.useMemo(()=>({setActiveTab:d,createNewSession:h,clearMessages:u,setTheme:x,setThemePreset:g,setLogs:p,setUnreadLogs:b}),[d,h,u,x,g,p,b]),[_,H]=o.useState("chat"),{t:G}=ee(),ne=xe($=>n?$.messagesBySession[n]||[]:[]),te=xe($=>n?$.generatingSessions.includes(n):!1),V=xe($=>n?$.pausedSessions.includes(n):!1),w=s.find($=>$.id===n)||null,U=o.useMemo(()=>ne.filter($=>!$.deleted).length===0,[ne]);o.useEffect(()=>{if(!n)return;let $=!1;return fe.tasks.list(n).then(K=>{if($||!K.success||!Array.isArray(K.data))return;const Z={PENDING:"pending",RUNNING:"running",COMPLETED:"completed",FAILED:"failed",CANCELLED:"skipped"},oe=Date.now(),ue=K.data.filter(ae=>ae.sessionId===n).map(ae=>{const le=new Date(ae.createdAt).getTime()||oe,T=new Date(ae.updatedAt).getTime()||oe;return{id:ae.id,sessionId:n,title:ae.title,status:Z[ae.status]||"pending",source:"task",description:ae.description,progress:ae.progress,createdAt:le,updatedAt:T,raw:ae}});er.getState().setTasks(n,ue,"task")}).catch(()=>{}),()=>{$=!0}},[n]);const Q=o.useCallback(($,K,Z,oe,ue)=>{n&&r(n,$,K,Z,oe?{mentions:oe,mentionDeliveryMode:ue}:void 0)},[r,n]),se=o.useCallback($=>{n&&r(n,$)},[r,n]),M=o.useCallback(async $=>{const K=n;if(!K)return;const Z=`shell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,oe=Date.now();xe.getState().addMessage(K,{id:Z,type:"user",content:`!${$}`,timestamp:oe,noTruncate:!0,shellRun:{command:$,stdout:"",stderr:"",exitCode:null,durationMs:0,running:!0}});const ae=await fe.shell.exec($,C),le=ae.success&&ae.data?{...ae.data,running:!1}:{command:$,stdout:"",stderr:"",exitCode:null,durationMs:Date.now()-oe,running:!1,error:ae.error||G("chat.shellRequestFailedGeneric")};xe.getState().updateMessage(K,Z,{shellRun:le})},[n,C,G]),W=o.useCallback($=>{n&&f&&f(n,$)},[f,n]),z=o.useCallback($=>{n&&k&&k(n,$)},[k,n]);return e.jsx("div",{className:"flex-1 flex min-h-0",children:e.jsxs("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[e.jsx(Hc,{}),w&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex h-7 shrink-0 items-center justify-end px-3",children:e.jsxs("div",{role:"radiogroup","aria-label":G("trajectory.viewToggleTitle"),className:"relative inline-grid grid-cols-2 items-center rounded-full border border-dark-border bg-dark-surface/60 p-0.5 text-[11px] leading-none",children:[e.jsx("span",{"aria-hidden":"true",className:`pointer-events-none absolute inset-y-0.5 left-0.5 w-[calc(50%-2px)] rounded-full ring-1 transition-transform duration-200 ease-out motion-reduce:transition-none ${_==="trajectory"?"translate-x-full bg-accent-blue/20 ring-accent-blue/40":"translate-x-0 bg-dark-hover ring-dark-border"}`}),Jc.map(({mode:$,Icon:K,labelKey:Z})=>{const oe=_===$;return e.jsxs("button",{type:"button",role:"radio","aria-checked":oe,title:G("trajectory.viewToggleTitle"),onClick:()=>H($),className:`relative z-10 flex items-center justify-center gap-1 whitespace-nowrap rounded-full px-2.5 py-1 transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-accent-blue/60 ${oe?"text-dark-text":"text-dark-muted hover:text-dark-text"}`,children:[e.jsx(K,{size:11}),G(Z)]},$)})]})}),e.jsxs("div",{className:`flex min-h-0 flex-1 flex-col ${U&&_==="chat"?"justify-center overflow-y-auto custom-scrollbar py-2":""}`,children:[_==="chat"?e.jsxs(e.Fragment,{children:[e.jsx(go,{messages:ne,isGenerating:te,isPaused:V,sessionId:w.id,centered:U,onSendSuggestion:se,onRegenerate:f?W:void 0,onDeleteMessage:k?z:void 0,onOpenSidebarView:D}),e.jsx(Bc,{isOpen:!!S,onCloseModal:N}),e.jsx(Fc,{isOpen:!!R,onClose:O??(()=>{})}),j&&e.jsx(Gc,{sessionId:w.id,defaultExpanded:!1,onClose:y},w.id)]}):e.jsx(Dl,{sessionId:w.id,messages:ne}),e.jsx($c,{activeSessionId:w.id}),e.jsx(zc,{sessionId:w.id,onSend:Q,onRunShell:M,onStop:()=>i(w.id),onPause:()=>a(w.id),onResume:()=>l(w.id),slashOptions:B,workspaceDir:C,onWorkspaceSelect:A})]})]})]})})});export{nd as SessionGrid};