@deepseekcode/cli 1.0.38 → 1.0.39

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 (47) hide show
  1. package/package.json +9 -9
  2. package/web/dist/assets/{AssistantsView-Bh6ajWIo.js → AssistantsView-0aLB_cG6.js} +1 -1
  3. package/web/dist/assets/AutomationView-CAMjPhJ2.js +1 -0
  4. package/web/dist/assets/{ChannelConfigView-DlakOI5z.js → ChannelConfigView-FcioeeYb.js} +6 -6
  5. package/web/dist/assets/ConnectorsView-DERP7zAW.js +1 -0
  6. package/web/dist/assets/{FileTreeView-Ciq1vhTf.js → FileTreeView-hBtHBbAV.js} +3 -3
  7. package/web/dist/assets/HookConfigView-NModtSB8.js +1 -0
  8. package/web/dist/assets/ModelsView-BPpO50C_.js +1 -0
  9. package/web/dist/assets/PluginsView-D0NE7zrt.js +1 -0
  10. package/web/dist/assets/ProjectsView-PIv7Gx4q.js +1 -0
  11. package/web/dist/assets/SessionGrid-BsDL3lov.js +47 -0
  12. package/web/dist/assets/SettingsModal-DdebvEmv.js +10 -0
  13. package/web/dist/assets/SkillsView-BNoigImJ.js +1 -0
  14. package/web/dist/assets/TemplatesTab-D8Pa68fj.js +1 -0
  15. package/web/dist/assets/ToolsView-NY-yk5YX.js +1 -0
  16. package/web/dist/assets/WorkspaceDirPicker-C5knnArH.js +6 -0
  17. package/web/dist/assets/{icons-YJcunJnw.js → icons-BxNxyk-c.js} +154 -129
  18. package/web/dist/assets/index-DaiVo1RY.css +1 -0
  19. package/web/dist/assets/index-RB5ffy32.js +620 -0
  20. package/web/dist/assets/{markdown-CrVimah5.js → markdown-B2L4Mq-x.js} +1 -1
  21. package/web/dist/assets/{panels-BykQW6E1.js → panels-P_I7Q72_.js} +1 -1
  22. package/web/dist/assets/{sttLanguages-D4JbRJc6.js → profileChange-C7Jg9C61.js} +1 -1
  23. package/web/dist/assets/{react-vendor-DM-M1fu_.js → react-vendor-B2V_5iSS.js} +1 -1
  24. package/web/dist/assets/{state-D8omNTWe.js → state-0T92JV0u.js} +1 -1
  25. package/web/dist/fonts/OFL-Inter.txt +93 -0
  26. package/web/dist/fonts/inter-latin-400-normal.woff2 +0 -0
  27. package/web/dist/fonts/inter-latin-600-normal.woff2 +0 -0
  28. package/web/dist/icons/icon-180.png +0 -0
  29. package/web/dist/icons/icon-192.png +0 -0
  30. package/web/dist/icons/icon-512.png +0 -0
  31. package/web/dist/icons/icon-maskable-512.png +0 -0
  32. package/web/dist/index.html +38 -8
  33. package/web/dist/manifest.webmanifest +16 -0
  34. package/web/dist/assets/AutomationView-D2Z-_4qe.js +0 -1
  35. package/web/dist/assets/ConnectorsView-ELXDmM9m.js +0 -1
  36. package/web/dist/assets/HookConfigView-DR8TP3QG.js +0 -1
  37. package/web/dist/assets/ModelsView-BW6eRUwf.js +0 -1
  38. package/web/dist/assets/PluginsView-CrHGk_JC.js +0 -1
  39. package/web/dist/assets/SessionGrid-DYYsm2dT.js +0 -52
  40. package/web/dist/assets/SettingsModal-DNxIKsKC.js +0 -10
  41. package/web/dist/assets/SkillsView-DS0nnKig.js +0 -1
  42. package/web/dist/assets/TemplatesTab-pXElHCnz.js +0 -1
  43. package/web/dist/assets/ThreeScene-DFL_qzB1.js +0 -2863
  44. package/web/dist/assets/ThreeScene-DvOrMIoG.css +0 -1
  45. package/web/dist/assets/ToolsView-Bk4hckku.js +0 -1
  46. package/web/dist/assets/index-CtPliI0f.css +0 -1
  47. package/web/dist/assets/index-D1N4vQ9I.js +0 -591
@@ -0,0 +1,47 @@
1
+ var ei=Object.defineProperty;var ti=(s,t,n)=>t in s?ei(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n;var Yt=(s,t,n)=>ti(s,typeof t!="symbol"?t+"":t,n);import{j as e}from"./markdown-B2L4Mq-x.js";import{a as o,s as Ur,u as nn,n as Fe,i as Re,b7 as si,t as ts,aE as ni,aF as rn,b8 as ri,b9 as ai,a8 as ii,a1 as ds,d as rs,ao as Wr,aC as Gr,E as an,aJ as Mt,f as Ue,X as De,ba as Gs,b as as,A as $e,w as is,ad as on,ac as Vs,b2 as ln,D as oi,aT as li,bb as ss,bc as ci,k as Ct,aK as di,a6 as Js,bd as cn,aw as ut,C as Vr,Y as tt,ay as ui,aP as Jr,be as hi,bf as mi,ar as xi,bg as fi,at as pi,bh as Vn,bi as gi,au as Jn,N as bi,aO as ki,bj as vi,bk as Yn,m as dn,ax as Yr,U as yi,av as ji,aB as wi,bl as Ni,bm as Xn,bn as Si,bo as Mi,bp as Ci,j as Ei,a7 as Ti,bq as ct,ah as Ai,aV as Ii,am as Ri,aR as Di,br as _i,bs as zi,y as $i,bt as Oi,a4 as Pi,a5 as Li,x as Fi,al as Bi,bu as Hi}from"./icons-BxNxyk-c.js";import{c as ge,u as se,r as Qn,b as qi,e as At,D as Ki,i as un,d as Et,g as Ui,U as hn,h as Wi,t as ce,j as us,k as mt,o as hs,l as dt,R as Gi,m as Tt,n as Xr,w as Ne,p as Ys,q as Te,s as Qr,a as ve,v as Zr,x as Vi,y as Ji,z as Yi,A as Xi,E as ea,F as Xs,G as pe,H as Qi,J as Zi,K as ta,L as eo,N as to,O as Zn,W as so,Q as Qs,S as Zs,T as Nt,V as mn,X as no,Y as ro,Z as ao,_ as io,$ as oo,a0 as lo,a1 as co,M as uo,a2 as ho,a3 as mo,a4 as xo,a5 as fo,a6 as po,a7 as go,a8 as bo,a9 as sa,aa as ko,ab as vo,ac as Xt,ad as yo,I as jo}from"./index-RB5ffy32.js";import{W as wo}from"./WorkspaceDirPicker-C5knnArH.js";import{r as No,p as So,s as Mo,S as Co,n as Eo,P as er}from"./profileChange-C7Jg9C61.js";import{c as To}from"./state-0T92JV0u.js";import"./react-vendor-B2V_5iSS.js";import"./panels-P_I7Q72_.js";const Ao=800,St=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g;let Io=0;const It=new Map;function na(s){const t=++Io;return It.set(t,s.replace(/\r\n?/g,`
2
+ `)),t}function Ro(s){return It.get(s)}function Do(s){It.delete(s)}function _o(s){return s.length>Ao||xn(s)>0}function xn(s){return(s.match(/\r\n|\r|\n/g)||[]).length}function zo(s){const t=na(s),n=xn(s);return n===0?{id:t,label:`[Pasted text #${t}]`}:{id:t,label:`[Pasted text #${t} +${n} lines]`}}function $o(s){return St.lastIndex=0,s.replace(St,(t,n)=>{const r=parseInt(n,10),a=It.get(r);return a!==void 0?a:t})}function Oo(s){St.lastIndex=0;const t=[];let n;for(;(n=St.exec(s))!==null;){const r=n[1];r!==void 0&&t.push(parseInt(r,10))}return St.lastIndex=0,t}function Po(s){for(const t of s)It.delete(t)}function Lo(s){const t=s.match(/\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]$/);return t?t[0]:null}function Fo(s){const t=s.match(/^\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]/);return t?t[0]:null}function tr(s){const t=s.match(/#(\d+)/);t&&Do(parseInt(t[1]??"",10))}function sr({value:s,max:t=100,size:n="md",variant:r="default",showLabel:a=!1,className:i}){const l=Math.min(Math.max(s/t*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:ge("w-full",i),children:[e.jsx("div",{className:ge("w-full bg-dark-border rounded-full overflow-hidden",c[n]),children:e.jsx("div",{className:ge("h-full rounded-full transition-all duration-300",d[r]),style:{width:`${l}%`}})}),a&&e.jsxs("span",{className:"text-xs text-dark-muted mt-1",children:[Math.round(l),"%"]})]})}function Bo(s){const t=o.useRef(null),n=o.useRef(0);return o.useEffect(()=>{if(!s){n.current=0;return}n.current=Date.now();const r=t.current;if(!r)return;const a=()=>{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};a();const i=setInterval(a,1e3);return()=>clearInterval(i)},[s]),t}function ra(s){if(typeof s=="string")try{const t=JSON.parse(s);return t&&typeof t=="object"&&!Array.isArray(t)?t:null}catch{return null}return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function we(s,t){const n=ra(s);if(!n)return"";for(const r of t){const a=n[r];if(typeof a=="string"&&a)return a}return""}function Ho(s,t){const n=ra(s);if(n)for(const r of t){const a=n[r],i=typeof a=="number"?a:typeof a=="string"&&a.trim()?Number(a):NaN;if(Number.isFinite(i)&&i>0)return i}}function Be(s){return typeof s=="string"?s:s&&typeof s=="object"?JSON.stringify(s,null,2):String(s??"")}function qo(s){for(const t of s.split(`
3
+ `)){const n=t.trim();if(n)return n}return""}function ze({label:s,tone:t="text-dark-muted",children:n}){return e.jsxs("div",{className:"px-2 py-1",children:[e.jsx("div",{className:`mb-0.5 text-[10px] ${t}`,children:s}),e.jsx("div",{className:"max-h-56 overflow-y-auto custom-scrollbar rounded border border-dark-border bg-dark-bg",children:n})]})}function Ko({toolCall:s}){const{t}=se(),n=we(s.args,["command","cmd","script"]),r=s.status==="error",a=s.status==="running",i=Be(s.result),l=a&&!i&&s.liveOutput||"";return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[n&&e.jsx(ze,{label:t("step.params"),children:e.jsxs("pre",{className:"tv-pre",children:[e.jsx("span",{className:"select-none text-accent-green",children:"$ "}),n]})}),l&&e.jsx(ze,{label:t("step.result"),tone:"text-accent-green",children:e.jsx("pre",{className:"tv-pre",children:l})}),s.result!==void 0&&s.result!==null&&e.jsx(ze,{label:t(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 Uo({toolCall:s}){const t=At(s.args),n=Be(s.result),r=s.diff||(n&&(n.includes("@@")||n.includes("+++")||n.includes("---"))?n:void 0);return!r&&!n?e.jsx(aa,{toolCall:s}):e.jsx("div",{className:"px-2 py-1",children:e.jsx(Ki,{filePath:t,content:r||n})})}function Wo({toolCall:s}){const{t}=se(),n=At(s.args),r=s.status==="error",a=Be(s.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})}),s.result!==void 0&&s.result!==null&&e.jsx(ze,{label:t(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:a})})]})}const nr=20,Go=/\b(grep|search_contents)\b/i;function Vo(s){return s===""?0:s.split(`
4
+ `).length}function Jo({toolCall:s}){const{t}=se(),n=we(s.args,["pattern","query","regex"]),r=s.status==="error",a=s.result!==void 0&&s.result!==null,i=a?Be(s.result):"",l=a?Vo(i):0,c=Go.test(s.name),d=s.noTruncate!==!0&&c&&a&&!r&&l>nr,[m,f]=o.useState(!1),h=d&&!m?i.split(`
5
+ `).slice(0,nr).join(`
6
+ `)+`
7
+ ${t("toolCall.linesTotal",{n:l})}`:i;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})}),a&&e.jsx(ze,{label:t(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:h})}),d&&e.jsx("div",{className:"px-2 pb-1",children:e.jsx("button",{type:"button","data-testid":"grep-result-toggle",onClick:()=>f(p=>!p),className:"text-[10px] text-accent-blue hover:underline",children:m?t("toolCall.collapse"):t("toolCall.expandAll",{n:l})})})]})}function Yo({toolCall:s}){const{t}=se(),n=we(s.args,["url","query"]),r=s.status==="error",a=Be(s.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}),s.result!==void 0&&s.result!==null&&e.jsx(ze,{label:t(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:a})})]})}function aa({toolCall:s}){const{t}=se(),n=s.status==="error",r=s.result!==void 0&&s.result!==null;return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[e.jsx(ze,{label:t("step.params"),children:e.jsx("pre",{className:"tv-pre",children:typeof s.args=="string"?s.args:JSON.stringify(s.args,null,2)})}),r&&e.jsx(ze,{label:t(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:Be(s.result)})})]})}function Xo({toolCall:s}){const{t}=se(),n=s.status==="error",r=Be(s.result),a=(s.attachments??[]).filter(i=>i.mime.startsWith("image/"));return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[a.length>0&&e.jsxs("div",{className:"px-2 pt-1",children:[e.jsx("div",{className:"mb-0.5 text-[10px] text-dark-muted",children:t("step.screenshot","Screenshot")}),e.jsx("div",{className:"max-h-72 overflow-y-auto custom-scrollbar rounded border border-dark-border bg-dark-bg",children:a.slice(0,4).map((i,l)=>e.jsx("img",{src:i.url,alt:i.filename??`computer screenshot ${l+1}`,className:"block w-full object-contain",loading:"lazy"},l))})]}),s.result!==void 0&&s.result!==null&&e.jsx(ze,{label:t(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})})]})}const rr=112;function Qo(s){const t=/^(\d+)\s*[x×]\s*(\d+)$/i.exec(s.trim()),n=t?Number(t[1]):0,r=t?Number(t[2]):0;return!n||!r?1:Math.min(Math.max(n/r,.5),2)}function Zo({toolCall:s}){const{t}=se(),n=we(s.args,["prompt"]),r=we(s.args,["size"]),a=Math.min(Math.max(Math.floor(Ho(s.args,["n"])??1),1),4),i=Qo(r),l=n.length>200?`${n.slice(0,199)}…`:n;return e.jsxs("div",{className:"px-2 py-1.5","data-testid":"image-generating",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-shimmer text-[13px] font-medium",children:t("step.imageGenerating")}),e.jsxs("span",{className:"chat-typing-dots","aria-hidden":"true",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})]}),e.jsx("div",{className:"mt-1.5 flex flex-wrap items-start gap-1.5",children:Array.from({length:a},(c,d)=>e.jsx("div",{"aria-hidden":"true",className:"skeleton-shimmer shrink-0 rounded-lg border border-dark-border",style:{height:rr,width:Math.round(rr*i)}},d))}),l&&e.jsx("p",{className:"mt-1.5 max-w-[26rem] text-[11px] leading-snug text-dark-muted",title:n,children:l}),r&&e.jsx("p",{className:"mt-0.5 font-mono text-[10px] text-dark-muted",children:r})]})}function el({toolCall:s}){const{t}=se(),n=s.status==="error",r=Be(s.result),a=(s.generatedImages??[]).filter(h=>h.length>0),i=we(s.args,["prompt"]),l=we(s.args,["size"]),c=s.generatedImageModel??"",d=i.length>300?`${i.slice(0,299)}…`:i,[m,f]=o.useState(null);return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[a.length>0&&e.jsxs("div",{className:"px-2 pt-1",children:[e.jsxs("div",{className:"mb-1 flex flex-wrap items-center gap-x-2 text-[10px] text-dark-muted",children:[e.jsx("span",{children:t("step.generatedImages",{count:a.length})}),l&&e.jsx("span",{className:"font-mono",children:l})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map((h,p)=>e.jsx("button",{onClick:()=>f(Qn(h)),title:t("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:Qn(h),alt:`generated image ${p+1}`,loading:"lazy",className:"h-28 w-auto max-w-[220px] object-cover"})},`${h}-${p}`))}),(d||c)&&e.jsxs("dl",{className:"mt-1.5 max-w-[26rem] space-y-0.5","data-testid":"image-gen-meta",children:[d&&e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("dt",{className:"shrink-0 text-[10px] text-dark-muted",children:t("step.imagePrompt")}),e.jsx("dd",{className:"min-w-0 break-words text-[11px] leading-snug text-dark-text/85",title:i,children:d})]}),c&&e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("dt",{className:"shrink-0 text-[10px] text-dark-muted",children:t("step.imageModel")}),e.jsx("dd",{className:"break-all font-mono text-[11px] text-dark-text/85",children:c})]})]})]}),s.result!==void 0&&s.result!==null&&e.jsx(ze,{label:t(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})}),m&&e.jsx(qi,{src:m,alt:t("fileJob.imagePreview"),onClose:()=>f(null)})]})}const tl=/(?:^|[_\W])(bash|powershell|pwsh|cmd|command|shell|exec|terminal)(?:[_\W]|$)/i,sl=/(?:^|[_\W])(read|cat|view|open)(?:[_\W]|$)/i,nl=/(?:^|[_\W])(grep|glob|search|find|list)(?:[_\W]|$)/i,rl=/(?:^|[_\W])(webfetch|websearch|fetch|web|http|curl|url)(?:[_\W]|$)/i,al=/(?:^|[_\W])(computer)(?:[_\W]|$)/i,il=/^agent$/i,ol=/generate[-_]?image|imagegen|create[-_]?image/i;function fn(s){return il.test(s)?"agent":ol.test(s)?"image":un(s)?"diff":tl.test(s)?"terminal":al.test(s)?"computer":rl.test(s)?"web":nl.test(s)?"search":sl.test(s)?"read":"generic"}function ll(s,t){const n=fn(s);let r="";switch(n){case"terminal":r=we(t,["command","cmd","script"]);break;case"computer":if(r=we(t,["action"])||we(t,["scope"]),r){const i=r,l=i==="type"||i==="key"?we(t,["text"]):i==="focus"?we(t,["keyword"]):i==="scroll"?we(t,["direction"]):"";r=l?`${i} ${l}`:i}break;case"diff":case"read":r=At(t)??"";break;case"search":r=we(t,["pattern","query","regex","glob"]);break;case"web":r=we(t,["url","query"]);break;case"image":r=we(t,["prompt"]);break;case"agent":r=we(t,["scope"])||we(t,["prompt"]);break;default:try{const i=typeof t=="string"?JSON.parse(t):t;r=i&&typeof i=="object"?JSON.stringify(i):String(t??"")}catch{r=typeof t=="string"?t:""}}const a=r.replace(/\s+/g," ").trim();return a.length>64?`${a.slice(0,63)}…`:a}function cl({toolCall:s}){switch(fn(s.name)){case"terminal":return e.jsx(Ko,{toolCall:s});case"diff":return e.jsx(Uo,{toolCall:s});case"read":return e.jsx(Wo,{toolCall:s});case"search":return e.jsx(Jo,{toolCall:s});case"web":return e.jsx(Yo,{toolCall:s});case"computer":return e.jsx(Xo,{toolCall:s});case"image":return s.status==="running"?e.jsx(Zo,{toolCall:s}):e.jsx(el,{toolCall:s});default:return e.jsx(aa,{toolCall:s})}}const dl=600;function ar(s){return{phase:"streaming",since:s,dryAt:null}}function ir(s,t,n,r={}){const a=r.settleDelayMs??dl;switch(t){case"erase":return s.phase==="erased"?s:{phase:"erased",since:n,dryAt:null};case"stream":return s.phase==="erased"||s.phase==="streaming"&&s.dryAt===null?s:{phase:"streaming",since:n,dryAt:null};case"settle":return s.phase!=="streaming"?s:r.reducedMotion?{phase:"settled",since:n,dryAt:null}:{...s,dryAt:(s.dryAt??n)+a}}}function ul(s,t){return s.phase!=="streaming"||s.dryAt===null||t<s.dryAt?s:{phase:"settled",since:s.dryAt,dryAt:null}}function hl(){return typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches}function pn(s,t){const[n,r]=o.useState(()=>s?ar(0):{phase:"settled",since:0,dryAt:null});return o.useEffect(()=>{r(a=>{const i=performance.now();return s?a.since===0?ar(i):ir(a,"stream",i):a.since===0?{phase:"settled",since:i,dryAt:null}:ir(a,"settle",i,{reducedMotion:hl()})})},[s,t]),o.useEffect(()=>{if(n.dryAt===null)return;const a=Math.max(0,n.dryAt-performance.now()),i=window.setTimeout(()=>r(l=>ul(l,performance.now())),a);return()=>window.clearTimeout(i)},[n.dryAt]),n.phase}function ml(s){const t=Math.max(0,Math.floor(s/1e3));return`${String(Math.floor(t/60)).padStart(2,"0")}:${String(t%60).padStart(2,"0")}`}const xl=s=>s==="completed"||s==="failed"||s==="paused";function or(s){return s==="paused"?"bg-amber-400":s==="completed"?"bg-accent-green":s==="failed"?"bg-accent-red":"bg-accent-blue"}function fl({status:s}){return s==="paused"?e.jsx(Ur,{size:10,className:"text-amber-400","aria-hidden":"true"}):s==="failed"?e.jsx(nn,{size:10,className:"text-accent-red","aria-hidden":"true"}):s==="completed"?e.jsx(Fe,{size:10,className:"text-accent-green","aria-hidden":"true"}):e.jsx(Re,{size:10,className:"animate-spin text-accent-blue","aria-hidden":"true"})}function lr(s){if(s==="paused")return"已暂停";if(s==="completed")return"已完成";if(s==="failed")return"已失败";if(s==="scheduled")return"排队中";if(s==="idle")return"待启动"}const cr="立即返回结果",dr="终止并返回结果";function pl({agent:s,labeled:t=!1}){const[n,r]=o.useState(!1);if(!(s.status==="running"||s.status==="scheduled"||s.status==="paused"))return null;const i=async l=>{r(!0);try{const c=await Wi(s.sessionId,s.id,l);c.ok?(c.alreadyFinished||c.stopInProgress)&&ce.info(c.message,4e3):ce.error(c.message,5e3)}finally{r(!1)}};return e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsxs("button",{type:"button",title:"在轮次边界停下来,把已经拿到的结果交回父代理","aria-label":cr,disabled:n,onClick:l=>{l.stopPropagation(),i("stop")},className:`flex items-center gap-1 rounded border border-dark-border/70 text-accent-blue hover:bg-dark-hover disabled:opacity-40 ${t?"px-1.5 py-0.5 text-[10px]":"p-0.5"}`,children:[e.jsx(si,{size:11}),t&&e.jsx("span",{children:cr})]}),e.jsxs("button",{type:"button",title:"立刻终止这个子代理,并把它已经拿到的结果交回父代理","aria-label":dr,disabled:n,onClick:l=>{l.stopPropagation(),i("kill")},className:`flex items-center gap-1 rounded border border-dark-border/70 text-accent-red hover:bg-dark-hover disabled:opacity-40 ${t?"px-1.5 py-0.5 text-[10px]":"p-0.5"}`,children:[e.jsx(ts,{size:11}),t&&e.jsx("span",{children:dr})]})]})}const gl=o.memo(function({agent:t}){Ui();const n=xl(t.status),r=t.status==="running"||t.status==="scheduled"||t.status==="idle"||t.status==="paused",i=pn(r,!1)==="streaming"?"draft":t.status==="failed"?"failed":t.status==="completed"?"committed":"draft",l=t.elapsedMs===void 0?void 0:!n&&t.elapsedAt?t.elapsedMs+Math.max(0,Date.now()-t.elapsedAt):t.elapsedMs,c=typeof t.round=="number"&&t.round>0&&typeof t.maxRounds=="number"&&t.maxRounds>0,d=c?Math.max(0,Math.min(100,Math.round(t.round/t.maxRounds*100))):0,m=[t.round!==void 0?t.maxRounds?`Turn ${t.round}/${t.maxRounds}`:`Turn ${t.round}`:"",t.currentTool&&t.status!=="completed"?`⚙ ${t.currentTool}`:"",l!==void 0?ml(l):""].filter(Boolean);return e.jsxs("div",{className:`ui-gram ${hn[i]} ml-[15px] mb-1 mr-1 rounded-md border border-dark-border/70 bg-dark-surface px-2 py-1.5`,"data-testid":"subagent-progress","data-agent-id":t.id,"data-agent-status":t.status,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"flex shrink-0 items-center",title:t.status,children:e.jsx(fl,{status:t.status})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-medium text-dark-text",title:t.name,children:t.name}),lr(t.status)&&e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted",children:lr(t.status)}),e.jsx(pl,{agent:t,labeled:!0})]}),e.jsx("div",{className:"mt-1 flex items-center gap-2",children:e.jsx("div",{className:"h-1 min-w-0 flex-1 overflow-hidden rounded-full bg-dark-hover",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":c?d:void 0,"aria-label":t.name,children:c?e.jsx("div",{className:`h-full rounded-full transition-[width] duration-500 ease-out ${or(t.status)}`,style:{width:`${d}%`}}):e.jsx("div",{className:`h-full w-1/4 animate-pulse rounded-full ${or(t.status)}`})})}),m.length>0&&e.jsx("div",{className:"mt-0.5",children:e.jsx("span",{className:"whitespace-nowrap font-mono text-[10px] tabular-nums text-dark-muted",children:m.join(" · ")})})]})}),bl=o.memo(function({sessionId:t,toolCallId:n,scope:r}){const a=Et(l=>t?l.agentsBySession[t]:void 0),i=o.useMemo(()=>t&&a?Et.getState().getAgentByToolCallId(t,n,r):void 0,[t,n,r,a]);return i?e.jsx(gl,{agent:i}):null}),kl=/^agent$/i;function vl(s){let t=s;if(typeof s=="string")try{t=JSON.parse(s)}catch{return}if(!t||typeof t!="object"||Array.isArray(t))return;const n=t.scope;return typeof n=="string"&&n.trim()?n:void 0}function yl(){const s=dt(t=>t.tokenRate);return e.jsx(Gi,{size:12,rate:s})}const jl={terminal:Gr,diff:Wr,read:rs,search:ds,web:ii,computer:ai,image:ri,agent:rn,generic:ni},wl=o.memo(function({toolCall:t,defaultCollapsed:n=!0,sessionId:r}){const a=t.status==="running",i=kl.test(t.name)&&!!r,l=i?vl(t.args):void 0,c=Bo(a),d=t.result!==void 0&&t.result!==null,m=t.status==="error",f=un(t.name),h=d?Be(t.result):"",p=At(t.args),{openFileMenu:b,menuNode:v}=us(),S=ll(t.name,t.args),k=m&&d?qo(h):"",[g,y]=o.useState(n),R=o.useRef(t.status);o.useEffect(()=>{R.current==="running"&&t.status!=="running"&&(t.diff||y(!0)),R.current=t.status},[t.status,t.diff,t.name]);const I=mt(t.duration),E=a?"bg-accent-blue":m?"bg-accent-red":"bg-accent-green",F=a?"running":m?"error":"success",N=pn(a,!1)==="streaming"?"draft":m?"failed":"committed",P=jl[fn(t.name)];return e.jsxs("div",{className:`tl-row ui-gram ui-gram--flat ui-gram--wash ${hn[N]} 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:()=>y(!g),"data-testid":"toolcall-row-header",children:[e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:a?e.jsx(yl,{}):e.jsx("span",{className:`tl-node ${E}`,"data-status":F})}),e.jsx("span",{className:`shrink-0 ${m?"text-accent-red":"text-dark-muted"}`,children:e.jsx(P,{size:12,"aria-hidden":"true"})}),e.jsx("span",{className:`font-medium text-[13px] shrink-0 truncate ${a?"text-shimmer":"text-dark-text"}`,children:t.name}),m&&k?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:h,children:k})]}):S?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:S,children:S})]}):e.jsx("span",{className:"min-w-0 flex-1"}),f&&p&&!m&&e.jsxs("button",{type:"button",onClick:B=>{B.stopPropagation(),hs(p)},onContextMenu:B=>b(B,p),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:p,children:[e.jsx(an,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:p})]}),a&&!i&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[11px] tabular-nums text-accent-blue",children:[e.jsx(Mt,{size:10}),e.jsx("span",{ref:c,children:"0s"})]}),!a&&I&&!i&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[10px] tabular-nums text-dark-muted",children:[e.jsx(Mt,{size:10}),e.jsx("span",{children:I})]}),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(Ue,{size:13})})]}),i&&e.jsx(bl,{sessionId:r,toolCallId:t.id,scope:l}),!g&&e.jsx("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25",children:e.jsx(cl,{toolCall:t})}),v]})});function ia(s){const t=s??"";let n=t,r=null,a=null;try{const i=JSON.parse(t);if(i&&typeof i=="object")if("payload"in i){a=typeof i.toolName=="string"?i.toolName:null;const l=i.payload;typeof l=="string"?n=l:l&&typeof l=="object"?(r=l,n=JSON.stringify(l,null,2)):n=""}else Array.isArray(i)||(r=i)}catch{n=t}if(!r&&n.length>0&&/^[\s]*[{[]/.test(n))try{const i=JSON.parse(n);i&&typeof i=="object"&&!Array.isArray(i)&&(r=i)}catch{}return{toolName:a,payloadText:n,args:r}}const gn=/\b(bash|shell|exec|cmd|powershell|terminal)\b/i,oa=/write_file|write|save|create|upload|deploy|publish/i,la=/edit_file|edit|patch|apply|update|replace/i,ca=/read_file|read|view|cat|open|list|dir\b/i,Nl=/file_delete|delete|remove|unlink|\brm\b|\bdel\b/i,Sl=/\b(glob|find|locate)\b/i,Ml=/\b(grep|rg|search_contents)\b/i,Cl=/web_search|search_web|browse/i,da=/web_fetch|fetch|http|curl|wget|download|request|api/i,El=/git|commit|merge|rebase|push|checkout/i,Tl=/install|uninstall|npm|pnpm|yarn|pip|cargo|gem|apt|brew|choco/i,bn=/send_message|send_file|message|notify|post/i;function ua(s){const t=s.toLowerCase();return gn.test(t)?"verbRunCommand":Cl.test(t)?"verbSearchWeb":oa.test(t)?"verbWriteFile":la.test(t)?"verbEditFile":Nl.test(t)?"verbDeleteFile":ca.test(t)?"verbReadFile":Ml.test(t)?"verbSearchContents":Sl.test(t)?"verbFindFiles":da.test(t)?"verbFetchUrl":El.test(t)?"verbGit":Tl.test(t)?"verbInstall":bn.test(t)?"verbSendMessage":"verbRunTool"}function Ts(s,t){const n=(s??"").replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function Al(s){if(!s)return null;for(const t of["file_path","filePath","path","file","target"]){const n=s[t];if(typeof n=="string"&&n.length>0)return n}return null}function ha(s,t){const{payloadText:n,args:r}=ia(t),a=s.toLowerCase();if(gn.test(a))return"";const i=Al(r);if(i)return i;const l=n.match(/(?:file_path|path|file)["\s:=]+([^\s",}]+)/i);if(l!=null&&l[1])return l[1];if(da.test(a)&&typeof(r==null?void 0:r.url)=="string"&&r.url)return Ts(r.url,48);if(bn.test(a)){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 ma(s,t){const{payloadText:n,args:r}=ia(t),a=s.toLowerCase();if(gn.test(a)){const i=typeof(r==null?void 0:r.command)=="string"?r.command:n;return i?{text:i,mono:!0}:null}if(oa.test(a)||la.test(a)){const i=typeof(r==null?void 0:r.content)=="string"?r.content:typeof(r==null?void 0:r.data)=="string"?r.data:"";if(i)return{text:i,mono:!0};if(r){const l=ur(r);if(l)return{text:l,mono:!0}}return n?{text:n,mono:!0}:null}if(bn.test(a)){const i=typeof(r==null?void 0:r.text)=="string"?r.text:typeof(r==null?void 0:r.message)=="string"?r.message:n;return i?{text:i,mono:!1}:null}if(ca.test(a))return null;if(r){const i=ur(r);if(i)return{text:i,mono:!0}}return n?{text:n,mono:!0}:null}function ur(s){return s?Object.entries(s).filter(([,t])=>t!=null).map(([t,n])=>{let r=typeof n=="string"?n:JSON.stringify(n);return r.length>96&&(r=`${r.slice(0,95)}…`),`${t}=${r.replace(/\n/g," ")}`}).join(" "):""}function xa(s,t){const n=Tt(t);return n?{path:n,external:!0}:{key:"scopeLocal",external:!1}}function fa({pre:s,obj:t}){return e.jsxs("span",{className:"min-w-0 text-sm text-dark-muted",children:[e.jsx("span",{children:s}),t&&e.jsx("b",{className:"font-semibold text-dark-text",children:t})]})}const As=5,Is=420;function en({text:s,mono:t=!0}){const{t:n}=se("hook"),[r,a]=o.useState(!1),i=s.split(`
9
+ `),l=i.length>As||s.length>Is;let c=s;!r&&l&&(c=i.slice(0,As).join(`
10
+ `),c.length>Is&&(c=`${c.slice(0,Is).trimEnd()}…`));const d=r?n("showLess"):i.length>As?n("showAllLines",{n:i.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 ${t?"font-mono":""} text-dark-text`,children:[c,l&&e.jsx("button",{type:"button",onClick:()=>a(m=>!m),className:"mt-1 block text-[11px] text-accent-blue hover:underline",children:d})]})}const Rs=15,Il=o.memo(function({approval:t,onResolved:n}){const{t:r}=se("hook"),[a,i]=o.useState(!1),[l,c]=o.useState(Rs),d=o.useRef(null),m=t.status==="pending",{level:f,reasonKey:h}=Xr(t.toolName,t.askPayload),p=Qr[f],b=ma(t.toolName,t.askPayload),v=xa(t.toolName,t.askPayload),S=Tt(t.askPayload)!==null;o.useEffect(()=>{if(m)return c(Rs),d.current=setInterval(()=>{c(N=>N<=1?(d.current&&clearInterval(d.current),0):N-1)},1e3),()=>{d.current&&clearInterval(d.current)}},[m,t.approvalId]),o.useEffect(()=>{const N=(t.timeoutMs??15e3)>0;l===0&&m&&!a&&N&&k()},[l]);const k=o.useCallback(()=>{!m||a||(i(!0),d.current&&clearInterval(d.current),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),n==null||n(t.approvalId,"approved"))},[m,a,t.approvalId,n]),g=o.useCallback(()=>{!m||a||(i(!0),d.current&&clearInterval(d.current),Ne.send({type:"hook_deny",data:JSON.stringify({approvalId:t.approvalId})}),n==null||n(t.approvalId,"denied"))},[m,a,t.approvalId,n]),y=o.useCallback(()=>{if(!m||a)return;i(!0),d.current&&clearInterval(d.current);const N=Ys.getState(),P=Tt(t.askPayload);P?(N.addToSessionAllowList(t.toolName,P),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId,sessionAllow:!0})})):(N.addToSessionAllowList(t.toolName),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})})),n==null||n(t.approvalId,"approved")},[m,a,t.approvalId,t.toolName,t.askPayload,n]),R=o.useCallback(()=>{!m||a||(i(!0),d.current&&clearInterval(d.current),Ys.getState().setAutoMode(!0),Te.getState().setAuto(!0),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),n==null||n(t.approvalId,"approved"))},[m,a,t.approvalId,n]);if(!m){const N=t.status==="approved";return e.jsx("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${N?"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:N?e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:14}),e.jsxs("span",{children:[r("alreadyAllowed"),t.toolName]})]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{size:14}),e.jsxs("span",{children:[r("alreadyDenied"),t.toolName]})]})})}const I=l/Rs*100,E=l<=5,F=[{id:"allow",index:1,label:r("optionAllow"),hint:r("optionAllowHint"),action:k,kind:"primary"},{id:"allow_session",index:3,label:r("optionAllowAlways"),hint:S?r("optionAllowPathHint"):r("optionAllowAlwaysHint",{tool:t.toolName}),action:y,kind:"secondary"},{id:"auto_mode",index:4,label:r("optionAutoMode"),hint:r("optionAutoModeHint"),action:R,kind:"secondary"},{id:"deny",index:2,label:r("optionDeny"),hint:r("optionDenyHint"),action:g,kind:"danger"}],G={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 ${v.external?"border-amber-500/40":p.border}`,children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 border-b ${p.bg} ${v.external?"border-amber-500/30":p.border}`,children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${rc.badge}",children:[p.icon," ",f]}),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(Gs,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(fa,{pre:r(ua(t.toolName)),obj:ha(t.toolName,t.askPayload)})}),v.external&&v.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:v.path,children:[e.jsx(as,{size:10}),v.path.length>32?`${v.path.slice(0,31)}…`:v.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(Mt,{size:11,className:E?"text-accent-red":"text-dark-muted"}),e.jsxs("span",{className:`text-[11px] font-mono ${E?"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 ${E?"bg-accent-red":l<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${I}%`}})})]})]}),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:t.toolName}),e.jsx("span",{className:"text-[10px] text-dark-muted/50",children:r(h)})]}),b&&e.jsx(en,{text:b.text,mono:b.mono}),(f==="CRITICAL"||f==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-[11px] px-2 py-1 rounded ${p.bg} ${p.text}`,children:[e.jsx($e,{size:12}),e.jsx("span",{children:r(f==="CRITICAL"?"highRiskWarning":"mediumRiskConfirm")})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:F.map(N=>e.jsxs("button",{onClick:N.action,disabled:a,className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs transition-colors disabled:opacity-50 ${G[N.kind]}`,children:[e.jsx("span",{className:`text-[9px] font-mono rounded px-0.5 ${N.kind==="primary"?"bg-white/20":"bg-dark-surface text-dark-muted"}`,children:N.index}),e.jsx("span",{children:N.label}),e.jsx("span",{className:`text-[10px] ${N.kind==="primary"?"text-white/70":"text-dark-muted/60"} hidden sm:inline`,children:N.hint})]},N.id))}),e.jsx("div",{className:"text-[10px] text-dark-muted/50 pt-0.5 border-t border-dark-border/50",children:r("clickToSelect")})]})]})}),Qt={xlsx:{icon:Vs},xls:{icon:Vs},csv:{icon:rs},docx:{icon:rs},text:{icon:on}};function hr(s){return!s&&s!==0?"—":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/1024/1024).toFixed(2)} MB`}const Rl=o.memo(function({job:t}){var v,S;const{t:n}=se(),{stage:r}=t,{openFileMenu:a,menuNode:i}=us(),l=o.useCallback(k=>{switch(k){case"xlsx":case"xls":return"Excel";case"csv":return"CSV";case"docx":return"Word";default:return n("fileJob.kindText")}},[n]),c=o.useCallback(k=>{ve.files.download(k).then(g=>{g.success||ce.error(g.error||n("fileJob.downloadFailed"))})},[n]),d=o.useMemo(()=>t.attachments||[],[t.attachments]),m=o.useMemo(()=>t.parsedFiles||[],[t.parsedFiles]),f=o.useMemo(()=>t.mapping||[],[t.mapping]),h=o.useMemo(()=>t.result||[],[t.result]),p=t.renderProgress??(r==="rendering"?0:100),b=t.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(is,{size:15,className:"text-accent-green shrink-0"}):r==="error"?e.jsx($e,{size:15,className:"text-accent-red shrink-0"}):e.jsx(Re,{size:15,className:"text-accent-blue animate-spin shrink-0"}),e.jsx("span",{className:"text-[13px] font-medium text-dark-text",children:Dl(r,n)}),e.jsx("div",{className:"flex-1"}),e.jsx("span",{className:"text-[10px] font-mono text-dark-muted/60",children:t.jobId})]}),e.jsxs("div",{className:"px-3.5 py-3 space-y-3",children:[d.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map((k,g)=>{const R=(Qt[k.kind]||Qt.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(R,{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:k.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[hr(k.size)," · ",l(k.kind),k.role&&k.role!=="unknown"&&e.jsxs("span",{className:ge("ml-1",k.role==="data"?"text-accent-green":"text-accent-purple"),children:["· ",k.role==="data"?n("fileJob.roleData"):n("fileJob.roleTemplate")]})]})]})]},`${k.fileName}-${g}`)})}),r==="parsing"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:n("fileJob.parsing",{file:((v=d[0])==null?void 0:v.fileName)||((S=m[0])==null?void 0:S.fileName)||""})}),e.jsx(sr,{value:b,size:"sm",showLabel:!0})]}),m.length>0&&r!=="error"&&e.jsxs("div",{className:"space-y-1.5",children:[m.map(k=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(is,{size:13,className:"text-accent-green shrink-0"}),e.jsx("span",{className:"truncate",children:k.fileName}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:n("fileJob.parsedSummary",{rows:k.rowCount,fields:k.fields.length})})]},k.fileName)),m[0]&&e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[m[0].fields.slice(0,12).map(k=>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:k},k)),m[0].fields.length>12&&e.jsxs("span",{className:"text-[10px] text-dark-muted/60",children:["+",m[0].fields.length-12]})]})]}),f.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:f.slice(0,8).map(k=>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:"{{"+k.placeholder+"}}"}),e.jsx("td",{className:"px-2 py-1.5 text-dark-muted",children:e.jsx(ln,{size:11})}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-blue",children:k.field})]},k.placeholder))})]})}),f.length>8&&e.jsx("div",{className:"text-[10px] text-dark-muted/60",children:n("fileJob.mappingMore",{n:f.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:t.currentRow||0,total:t.totalRows||0})}),e.jsx(sr,{value:p,size:"sm",variant:"warning",showLabel:!0})]}),h.length>0&&r==="complete"&&e.jsx("div",{className:"space-y-1.5",children:h.map(k=>{const y=(Qt[k.format]||Qt.text).icon,R=k.failedRows.length>0;return e.jsxs("div",{onContextMenu:I=>a(I,k.path),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:k.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[hr(k.size)," · ",n("fileJob.rowsDone",{done:k.successCount,total:k.rowCount}),R&&e.jsxs("span",{className:"text-accent-red",children:[" · ",n("fileJob.rowsFailed",{n:k.failedRows.length})]})]})]}),e.jsxs("button",{onClick:()=>hs(k.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(an,{size:12}),n("chat.previewInPanel")]}),e.jsxs("button",{onClick:()=>c(k.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(oi,{size:12}),n("fileJob.download")]})]}),R&&e.jsxs("div",{className:"mt-1.5 space-y-0.5 border-t border-dark-border/50 pt-1.5",children:[k.failedRows.slice(0,3).map(I=>e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-accent-red",children:[e.jsx(nn,{size:10,className:"shrink-0"}),e.jsxs("span",{children:["#",I.index+1]}),e.jsx("span",{className:"truncate",children:I.error})]},I.index)),k.failedRows.length>3&&e.jsx("div",{className:"text-[10px] text-dark-muted/70",children:n("fileJob.moreRows",{n:k.failedRows.length-3})})]})]},k.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($e,{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:t.error||n("fileJob.error")}),t.errorDetail&&e.jsx("div",{className:"mt-0.5 text-[11px] text-dark-muted break-words",children:t.errorDetail})]})]})]}),i]})});function Dl(s,t){switch(s){case"uploaded":return t("fileJob.stageUploaded");case"parsing":return t("fileJob.stageParsing");case"mapping":return t("fileJob.stageMapping");case"rendering":return t("fileJob.stageRendering");case"complete":return t("fileJob.stageComplete");case"error":return t("fileJob.stageError");default:return t("fileJob.stageUploaded")}}const mr={auth:{icon:ci,color:"text-accent-red"},rate_limit:{icon:ss,color:"text-accent-yellow"},busy:{icon:ss,color:"text-accent-yellow"},timeout:{icon:ss,color:"text-accent-yellow"},network:{icon:li,color:"text-accent-yellow"},model:{icon:rn,color:"text-accent-red"},tool:{icon:$e,color:"text-accent-yellow"},unknown:{icon:$e,color:"text-accent-red"}},_l=o.memo(function({error:t,onRetry:n}){const{t:r}=se(),[a,i]=o.useState(!1),l=mr[t.category]||mr.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:ge("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:t.summary}),t.detail&&t.detail!==t.summary&&e.jsx("div",{className:"mt-0.5 text-[11px] text-dark-muted/80 break-words",children:t.detail.slice(0,160)}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[t.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(Ct,{size:11}),r("errorCard.retry")]}),t.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(di,{size:11}),r("errorCard.modelSettings")]}),t.detail&&e.jsxs("button",{onClick:()=>i(m=>!m),className:"flex items-center gap-0.5 text-[11px] text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(Ue,{size:11,className:ge("transition-transform",a&&"rotate-180")}),r("errorCard.details")]})]})]})]}),a&&t.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:t.detail})]})});function zl({info:s}){const{t}=se(),n=s.stdout.length>0,r=s.stderr.length>0,a=n||r,i=!s.running&&(!!s.error||s.timedOut===!0||s.exitCode!==null&&s.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:s.command})]}),s.running?e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-dark-muted",children:[e.jsx(Re,{size:12,className:"animate-spin","aria-hidden":"true"}),t("chat.shellRunning")]}):e.jsxs(e.Fragment,{children:[a&&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:s.stdout}),r&&e.jsxs("span",{className:"text-accent-red",children:[n?s.stdout.endsWith(`
11
+ `)?"":`
12
+ `:"",s.stderr]})]}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-2.5 gap-y-1 text-[11px]",children:[s.error?e.jsxs("span",{className:"flex items-center gap-1 text-accent-red",children:[e.jsx($e,{size:11,"aria-hidden":"true"}),t("chat.shellRequestFailed",{message:s.error})]}):e.jsx("span",{className:i?"text-accent-red":"text-accent-green",children:s.exitCode===null?t("chat.shellNoExitCode"):t("chat.shellExitCode",{code:s.exitCode})}),s.durationMs>0&&e.jsx("span",{className:"tabular-nums text-dark-muted/70",children:mt(s.durationMs)}),s.timedOut&&e.jsx("span",{className:"text-accent-red",children:t("chat.shellTimedOut")}),s.truncated&&e.jsx("span",{className:"text-dark-muted/70",children:t("chat.shellTruncated")}),s.shellKind&&e.jsx("span",{className:"text-dark-muted/60",children:s.shellKind})]}),!a&&!s.error&&e.jsx("div",{className:"mt-1.5 text-[11px] text-dark-muted/70",children:t("chat.shellNoOutput")})]}),!s.running&&s.cwd&&e.jsx("div",{className:"mt-1 truncate font-mono text-[10.5px] text-dark-muted/50",title:s.cwd,children:s.cwd})]})}const Ds=360,_s=300,$l=180,Le=8;function kn({src:s,alt:t,children:n,className:r}){const a=o.useRef(null),i=o.useRef(null),[l,c]=o.useState(null),d=o.useCallback(()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]),m=o.useCallback(()=>{d(),i.current=window.setTimeout(()=>{var b;i.current=null;const p=(b=a.current)==null?void 0:b.getBoundingClientRect();p&&p.width>0&&c(p)},$l)},[d]),f=o.useCallback(()=>{d(),c(null)},[d]);o.useEffect(()=>()=>d(),[d]),o.useEffect(()=>{if(!l)return;const p=()=>c(null);return window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}},[l]);let h=null;if(l){const p=window.innerWidth,b=window.innerHeight,v=l.top>=_s+Le+Le,S=v?l.top-Le:l.bottom+Le,k=l.left+l.width/2-Ds/2,g=Math.max(Le,Math.min(k,Math.max(Le,p-Ds-Le))),y=v?S:Math.min(S,Math.max(Le,b-_s-Le));h={left:g,top:y,transform:v?"translateY(-100%)":void 0}}return e.jsxs("span",{ref:a,className:ge("inline-flex min-w-0",r),onMouseEnter:m,onMouseLeave:f,onFocus:m,onBlur:f,children:[n,l&&h&&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:h,children:e.jsx("img",{src:s,alt:t,draggable:!1,className:"block rounded object-contain",style:{maxWidth:Ds-8,maxHeight:_s}})})]})}function Ol({src:s,name:t,path:n,size:r=13,className:a,hoverPreview:i=!0}){const{t:l}=se(),c=o.useCallback(()=>{Zr({src:s,name:t,path:n})},[s,t,n]);if(!s)return e.jsx(Js,{size:r,className:"shrink-0 text-dark-muted","aria-hidden":"true"});const d=e.jsx("button",{type:"button",onClick:c,title:`${t} · ${l("fileJob.openInPanel")}`,"aria-label":`${t} — ${l("fileJob.openInPanel")}`,className:ge("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",a),children:e.jsx(Js,{size:r,"aria-hidden":"true"})});return i?e.jsx(kn,{src:s,alt:t,className:"shrink-0",children:d}):d}function Pl({src:s,name:t,path:n,className:r}){const{t:a}=se(),i=o.useCallback(()=>{Zr({src:s,name:t,path:n})},[s,t,n]);return e.jsx(kn,{src:s,alt:t,className:r,children:e.jsxs("button",{type:"button",onClick:i,title:`${t} · ${a("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(Js,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:t})]})})}const Ll=/<attachment\s+path="([^"]*)"\s*\/>/g,Fl=/<image\s+name="([^"]*)"\s*\/>/g,Bl=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g,Hl=new RegExp("(?<![\\w@.])@((?:[\\w@.()[\\]{}$%-]+[\\\\/])+[\\w@.()[\\]{}$%-]+|[\\w@.()[\\]{}$%-]*[\\w@()[\\]{}$%-]\\.[A-Za-z0-9]{1,12})","g");function ql(s){return!s||s.length>400?!1:s.includes("/")||s.includes("\\")?ea(s):/\.[A-Za-z0-9]{1,12}$/.test(s)}function tn(s){if(!s)return[];const t=[],n=a=>{a&&t.push({kind:"text",value:a})};return s.split(Hl).forEach((a,i)=>{if(i%2===1){ql(a)?t.push({kind:"mention",value:a}):n(`@${a??""}`);return}a.split(Yi).forEach((c,d)=>{if(d%2===1){const{path:m,tail:f}=Xi(c);if(m&&ea(m)){t.push({kind:"path",value:m}),n(f);return}}n(c)})}),t}function Kl(s,t){const n=[];let r=0;for(const a of s.matchAll(Bl)){const i=a.index??0,l=Number.parseInt(a[1]??"",10);i>r&&n.push(...tn(s.slice(r,i)));const c=t.get(l);c===void 0?n.push({kind:"text",value:a[0]}):n.push({kind:"paste",value:a[0],id:l,content:c}),r=i+a[0].length}return r<s.length&&n.push(...tn(s.slice(r))),n}function Ul(s,t){const n=[],r=[];let a=(s||"").replace(Ll,(l,c)=>(c&&n.push(c),"")).replace(Fl,(l,c)=>(c&&r.push(c),""));(n.length>0||r.length>0)&&(a=a.replace(/^(?:[ \t]*\n)+/,"")),a=a.replace(/\n{3,}/g,`
13
+
14
+ `);const i=new Map((t??[]).map(l=>[l.id,l.content]));return{attachments:n,imageNames:r,segments:i.size>0?Kl(a,i):tn(a)}}function Wl({path:s}){const{openFileMenu:t,menuNode:n}=us(),r=s.split(/[\\/]/).pop()||s;return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",title:s,onClick:()=>hs(s),onContextMenu:a=>t(a,s),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(cn,{size:11,className:"shrink-0 text-dark-muted"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:r}),e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-accent-blue",children:"<attachment>"})]}),n]})}function Gl({token:s,content:t}){const{t:n}=se(),[r,a]=o.useState(!1),[i,l]=o.useState(!1),c=async()=>{try{await navigator.clipboard.writeText(t),l(!0),setTimeout(()=>l(!1),2e3)}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>a(d=>!d),title:n(r?"chat.pasteCollapse":"chat.pasteExpand"),"aria-expanded":r,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(cn,{size:11,className:"shrink-0 text-dark-muted"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:s}),r?e.jsx(ut,{size:11,className:"shrink-0 text-dark-muted"}):e.jsx(Ue,{size:11,className:"shrink-0 text-dark-muted"})]}),r&&e.jsxs("div",{className:"my-1.5 rounded-lg border border-dark-border bg-dark-bg/70 p-2",children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-medium text-dark-muted",children:n("chat.pasteOriginal")}),e.jsxs("button",{type:"button",onClick:c,className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",children:[i?e.jsx(Fe,{size:10}):e.jsx(Vr,{size:10}),n(i?"common.copied":"common.copy")]})]}),e.jsx("pre",{className:"max-h-56 overflow-auto whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-dark-text",children:t})]})]})}function Vl({content:s,images:t,pastes:n}){const{t:r}=se(),{openFileMenu:a,menuNode:i}=us(),l=o.useMemo(()=>Ul(s,n),[s,n]),c=o.useMemo(()=>(t??[]).map((d,m)=>{const f=l.imageNames[m],h=d.startsWith("data:")||d.startsWith("blob:"),p=h?r("fileJob.imageN",{n:m+1}):(d.split(/[?#]/)[0]??"").split(/[\\/]/).pop()||r("fileJob.imageN",{n:m+1});return{key:`${m}-${d.slice(0,48)}`,src:Vi(d),name:f||p,path:h?void 0:d}}),[t,l.imageNames,r]);return e.jsxs("div",{className:"whitespace-pre-wrap break-words text-[14.5px] leading-relaxed",children:[l.attachments.map((d,m)=>e.jsx(Wl,{path:d},`${d}-${m}`)),c.map(d=>e.jsx(Pl,{src:d.src,name:d.name,path:d.path,className:"mr-1 align-middle"},d.key)),l.segments.map((d,m)=>d.kind==="text"?e.jsx("span",{children:d.value},m):d.kind==="paste"?e.jsx(Gl,{token:d.value,content:d.content},m):d.kind==="mention"?e.jsxs("button",{type:"button",onClick:()=>hs(d.value),onContextMenu:f=>a(f,d.value),title:d.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:d.value})]},m):e.jsx(Ji,{path:d.value},m)),i]})}const xr=12;function fr(s){const t=s.slice(0,xr).join(`
15
+ `),n=s.length-xr;return n>0?`${t}
16
+ … (${n})`:t}const Jl=o.memo(function({created:t,modified:n,onOpenArtifacts:r,onOpenChanges:a}){const{t:i}=se();if(t.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-xs","data-testid":"turn-result-footer",children:[t.length>0&&e.jsxs("button",{type:"button",onClick:r,className:l,"data-testid":"turn-result-artifacts",title:fr(t),children:[i("chat.viewAllArtifacts",{n:t.length}),e.jsx(tt,{size:11,className:"shrink-0 opacity-70"})]}),n.length>0&&e.jsxs("button",{type:"button",onClick:a,className:l,"data-testid":"turn-result-changes",title:fr(n),children:[i("chat.viewAllChanges",{n:n.length}),e.jsx(tt,{size:11,className:"shrink-0 opacity-70"})]})]})});function Yl(s){for(const t of s.split(`
17
+ `)){const n=t.trim();if(n)return n}return""}function Xl(s){var n;const t=s.split(`
18
+ `);for(let r=t.length-1;r>=0;r--){const a=(n=t[r])==null?void 0:n.trim();if(a)return a}return""}function Ql({index:s,text:t,isStreaming:n,collapsed:r,onToggle:a}){const{t:i}=se(),l=r?n?Xl(t):Yl(t):"",d=pn(n,!1)==="streaming"?"draft":"committed";return e.jsxs("div",{children:[e.jsxs("button",{className:`ui-gram ui-gram--flat ui-gram--wash ${hn[d]} flex w-full cursor-pointer select-none items-center gap-1.5 py-0.5 text-left text-xs`,onClick:()=>a(s),"data-testid":"thinking-toggle",children:[e.jsx(tt,{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?`${i("chat.thinking")}…`:i("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:t.replace(/\n{3,}/g,`
19
+
20
+ `)})]})}const pa=5,Zl=30,ec=["让我","我先","我现在","我发现","我注意到","我决定","我重新","我重试","我继续","我现在要","让我现在","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 tc(s){const t=s.charCodeAt(0);return t>=19968&&t<=40959}function sc(s){let t="",n=!1;for(const r of s)r===" "||r===" "||r===" "?(n||(t+=" "),n=!0):(t+=r,n=!1);return t}function nc(s){return s>=97&&s<=122||s>=48&&s<=57||s===95}function ga(s){const t=sc(s.trimStart().toLowerCase());return ec.some(n=>{if(!t.startsWith(n))return!1;const r=t[n.length];return r===void 0||tc(n)||n==="i re-"?!0:!nc(r.charCodeAt(0))})}function rc(s){if(!s)return!1;const t=s.split(/\r?\n/).slice(0,Zl);let n=0;for(const r of t)if(r.trim())if(ga(r)){if(n++,n>=pa)return!0}else return!1;return!1}function ac(s,t){if(!s)return{body:s||"",absorbed:""};if(!rc(s))return{body:s,absorbed:""};const n=s.split(/\r?\n/);let r=0,a=0;for(const l of n){if(!l.trim()){a++;continue}if(ga(l)){r++,a++;continue}break}if(r<pa)return{body:s,absorbed:""};let i=0;for(const l of n.slice(0,a)){if(i+=l.length,i>=s.length)break;s.startsWith(`\r
21
+ `,i)?i+=2:(s[i]===`
22
+ `||s[i]==="\r")&&(i+=1)}return{body:s.slice(i),absorbed:s.slice(0,i)}}const ic=new Set(["edit_file","edit_file_line","file_edit","file_append","notebook_edit","apply_patch","git_apply_patch","Edit","EditTool","NotebookEditTool"]);function pr(s){return s.replace(/\\/g,"/").replace(/^\.\//,"")}function oc(s){return typeof s.diff=="string"&&s.diff.trim().length>0}function lc(s){var i;const t=new Map,n=new Map,r=l=>{const c=pr(l);t.has(c)||(n.delete(c),t.set(c,l))},a=l=>{const c=pr(l);t.has(c)||n.has(c)||n.set(c,l)};for(const l of((i=s.fileJob)==null?void 0:i.result)??[])l!=null&&l.path&&r(l.path);for(const l of s.toolCalls??[]){if(!l||l.status==="error"||!un(l.name))continue;const c=At(l.args);c&&(ic.has(l.name)||oc(l)?a(c):r(c))}return{created:Array.from(t.values()),modified:Array.from(n.values())}}const gr={thinking:0,tool:1,text:2};function cc(s){return s.thinkingBlocks&&s.thinkingBlocks.length>0?s.thinkingBlocks:s.thinking?[{index:Number.MIN_SAFE_INTEGER,text:s.thinking}]:[]}function dc(s){return s.textBlocks&&s.textBlocks.length>0?s.textBlocks:s.content?[{index:Number.MAX_SAFE_INTEGER,text:s.content}]:[]}function uc(s,t,n){const r=[];for(const a of s)r.push({kind:"thinking",key:`thinking-${a.index}`,index:a.index,block:a});for(const a of t)r.push({kind:"text",key:`text-${a.index}`,index:a.index,block:a});for(const a of n??[])r.push({kind:"tool",key:`tool-${a.id}`,index:a.index??Number.MAX_SAFE_INTEGER,toolCall:a});return r.sort((a,i)=>a.index-i.index||gr[a.kind]-gr[i.kind]),r}function hc(s){let t=Number.MIN_SAFE_INTEGER;for(const n of s)t=Math.max(t,n.index);return t}function mc(s,t){return s.some(n=>n.index>t)}function xc(s){return!!(s.status==="running"||s.diff)}function zs({onClick:s,title:t,children:n,danger:r=!1}){return e.jsx("button",{onClick:s,title:t,"aria-label":t,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 $s({message:s,sessionId:t,onRegenerate:n,onDeleteMessage:r}){const{t:a}=se(),[i,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(s.content||s.thinking||""),l(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>l(!1),2e3)}catch(m){console.error("Failed to copy message:",m)}},[s.content,s.thinking]);return t?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(zs,{onClick:d,title:a("chat.copyMessage"),children:i?e.jsx(Fe,{size:13,className:"text-accent-green"}):e.jsx(Vr,{size:13})}),s.type==="assistant"&&n&&e.jsx(zs,{onClick:()=>n(s.id),title:a("chat.regenerate"),children:e.jsx(Ct,{size:13})}),r&&e.jsx(zs,{onClick:()=>r(s.id),title:a("chat.deleteMessage"),danger:!0,children:e.jsx(Jr,{size:13})})]}):null}function Os({ts:s,children:t}){const{i18n:n}=se(),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(s).toLocaleTimeString(r,{hour:"2-digit",minute:"2-digit"})}),t]})}const fc=o.memo(function({message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a,onOpenSidebarView:i}){var N,P,B;const{t:l}=se(),c=Xs(M=>M.developerView),d=pe(M=>{var V;if(!n||!M.generatingSessions.includes(n))return!1;const z=M.messagesBySession[n];return z?((V=z[z.length-1])==null?void 0:V.id)===t.id:!1}),m=pe(M=>{var V;if(!n)return!1;const z=M.messagesBySession[n];return z?((V=z[z.length-1])==null?void 0:V.id)===t.id:!1}),f=o.useMemo(()=>lc(t),[t.toolCalls,t.fileJob]),h=o.useMemo(()=>cc(t),[t.thinkingBlocks,t.thinking]),p=o.useMemo(()=>dc(t),[t.textBlocks,t.content]),b=o.useMemo(()=>uc(h,p,t.toolCalls),[h,p,t.toolCalls]),v=o.useMemo(()=>hc(b),[b]),[S,k]=o.useState({}),g=o.useCallback(M=>!c&&(!d||mc(b,M)),[c,d,b]),y=o.useCallback(M=>{k(z=>({...z,[M]:!(z[M]??g(M))}))},[g]),R=h.length>0,I=o.useCallback(M=>{if(!R)return M;const{body:z}=ac(M);return z||M},[R]),E=t.type==="user",F=t.type==="system",G=o.useCallback((M,z)=>{if(!n)return;const Q=pe.getState().getMessages(n),J=Q.findIndex(H=>H.id===t.id);if(J===-1)return;const re=Q[J];if(!re)return;const j={...re,hookApproval:re.hookApproval?{...re.hookApproval,status:z}:void 0},L=[...Q];L[J]=j,pe.setState({messagesBySession:{...pe.getState().messagesBySession,[n]:L}})},[n,t.id]);return t.deleted?null:t.shellRun?e.jsxs("div",{className:"chat-msg","data-role":"shell",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(Gr,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group relative",children:[e.jsx(Os,{ts:t.timestamp}),e.jsx($s,{message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a}),e.jsx(zl,{info:t.shellRun})]})]}):E?e.jsxs("div",{className:"chat-msg","data-role":"user",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(ui,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"max-w-[78%] flex flex-col",children:[t.channel&&(t.channel.senderName||t.channel.channelType)&&e.jsx("div",{className:"mb-0.5 self-end px-1 text-[10px] text-dark-muted","data-testid":"channel-source",children:[t.channel.channelType,t.channel.senderName].filter(Boolean).join(" · ")}),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(Os,{ts:t.timestamp}),e.jsx($s,{message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a}),e.jsx(Vl,{content:((P=((N=t.display)==null?void 0:N.content)??t.content)==null?void 0:P.replace(/\n{3,}/g,`
23
+
24
+ `))??"",images:t.images,pastes:(B=t.display)==null?void 0:B.pastes})]})]})]}):F?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:t.content})}):e.jsxs("div",{className:"chat-msg","data-role":"assistant",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(rn,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group relative",children:[e.jsx(Os,{ts:t.timestamp}),e.jsx($s,{message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a}),b.length>0&&!t.hookApproval&&e.jsx("div",{className:"mb-1 space-y-1","data-testid":"message-chronology",children:b.map(M=>M.kind==="thinking"?e.jsx(Ql,{index:M.block.index,text:M.block.text,isStreaming:d&&M.block.index===v,collapsed:S[M.block.index]??g(M.block.index),onToggle:y},M.key):M.kind==="text"?e.jsx("div",{className:"leading-relaxed",children:e.jsx(Qi,{content:I(M.block.text).replace(/\n{3,}/g,`
25
+
26
+ `),streaming:d&&M.block.index===v})},M.key):e.jsx(wl,{toolCall:M.toolCall,sessionId:n,defaultCollapsed:c?!1:!xc(M.toolCall)},M.key))}),b.length===0&&!t.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"),"…"]})]}),t.summary&&!d&&e.jsx("div",{className:"mt-1.5 text-[11px] text-dark-muted/70","data-testid":"turn-summary",children:Zi(t.summary)}),m&&!d&&!t.hookApproval&&e.jsx(Jl,{created:f.created,modified:f.modified,onOpenArtifacts:()=>i==null?void 0:i("artifacts"),onOpenChanges:()=>i==null?void 0:i("changes")}),t.fileJob&&e.jsx("div",{className:"mt-3",children:e.jsx(Rl,{job:t.fileJob})}),t.errorCard&&e.jsx("div",{className:"mt-3",children:e.jsx(_l,{error:t.errorCard,onRetry:n&&r?()=>r(t.id):void 0})}),t.hookApproval&&e.jsx("div",{className:"mt-3 border-l-2 border-accent-yellow/50 pl-3",children:e.jsx(Il,{approval:t.hookApproval,onResolved:G})})]})]})});function pc(s,t=28){const n=s.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}…`:n}const gc="cubic-bezier(0.34, 1.56, 0.64, 1)",bc=o.memo(function({items:t,activeId:n,onJump:r}){const{t:a}=se(),[i,l]=o.useState(!1),c=o.useRef(null),d=o.useCallback(()=>{c.current&&window.clearTimeout(c.current),l(!0)},[]),m=o.useCallback(()=>{c.current&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>l(!1),180)},[]);return t.length===0?null:e.jsx("div",{role:"list","aria-label":a("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:m,"data-testid":"rail-trigger",className:"pointer-events-auto relative flex items-center py-3",children:[e.jsxs("div",{"aria-hidden":!i,inert:!i,"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 ${i?"translate-x-0 scale-100 opacity-100":"pointer-events-none translate-x-4 scale-95 opacity-0"}`,style:{transitionTimingFunction:i?gc:"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(hi,{size:12,className:"text-accent-blue","aria-hidden":"true"}),a("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:t.length})]}),e.jsx("div",{className:"max-h-[55vh] overflow-y-auto p-1.5 custom-scrollbar",children:t.map((f,h)=>{const p=f.id===n;return e.jsxs("button",{type:"button",role:"listitem",onClick:()=>r(f.id),title:f.content,"aria-current":p?"true":void 0,tabIndex:i?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 ${i?"translate-x-0 opacity-100":"translate-x-2 opacity-0"} ${p?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{transitionDelay:i?`${Math.min(h*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 ${p?"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:h+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 ${p?"font-medium text-accent-blue":"text-dark-text/90"}`,children:f.content})}),e.jsx(tt,{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"})]},f.id)})})]}),e.jsx("div",{"data-testid":"rail-dots",className:"flex flex-col items-end gap-1",children:t.map((f,h)=>{const p=pc(f.content),b=f.id===n;return e.jsx("button",{type:"button",role:"listitem",onClick:()=>r(f.id),title:f.content,"aria-label":`${h+1}. ${p}`,"aria-current":b?"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:b?"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"})},f.id)})})]})})}),Ps=24;function kc({label:s}){const t=o.useRef(Date.now()),n=o.useRef(null),[r,a]=o.useState(!1);return o.useEffect(()=>{const i=window.setTimeout(()=>a(!0),15e3);return()=>window.clearTimeout(i)},[]),o.useEffect(()=>{if(!r)return;const i=()=>{const c=n.current;if(!c)return;const d=Math.floor((Date.now()-t.current)/1e3);c.textContent=d>=60?`${Math.floor(d/60)}m ${d%60}s`:`${d}s`};i();const l=window.setInterval(i,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:s}),r&&e.jsxs("span",{className:"flex items-center gap-1 tabular-nums text-dark-muted/70",children:[e.jsx(Mt,{size:10}),e.jsx("span",{ref:n,children:"15s"})]})]})}const vc=o.memo(function({messages:t,isGenerating:n,sessionId:r,onRegenerate:a,onDeleteMessage:i,onOpenSidebarView:l}){const{t:c}=se(),d=o.useRef(null),m=o.useRef(new Map),[f,h]=o.useState(!0),[p,b]=o.useState(null),v=o.useRef(f),S=o.useRef(p),k=o.useCallback(T=>{v.current!==T&&(v.current=T,h(T))},[]),g=o.useCallback(T=>{S.current!==T&&(S.current=T,b(T))},[]),[y,R]=o.useState(null),[I,E]=o.useState(0),F=o.useRef(null),G=o.useRef(!1),N=o.useRef(null),P=o.useRef(n);P.current=n;const B=o.useMemo(()=>t.filter(T=>!T.deleted),[t]),M=o.useMemo(()=>{if(!n)return!1;const T=B[B.length-1];return!T||T.type!=="assistant"?!1:!T.content},[n,B]),z=o.useMemo(()=>B.filter(T=>ta(T)).map(T=>({id:T.id,content:T.content})),[B]),V=o.useMemo(()=>z.map(T=>T.id),[z]),Q=o.useCallback(T=>{if(T){const ee=T.dataset.mid;ee&&m.current.set(ee,T)}},[]);o.useEffect(()=>{const T=new Set(V);for(const ee of m.current.keys())T.has(ee)||m.current.delete(ee)},[V]);const J=o.useCallback(()=>{const T=d.current;if(!T||V.length===0){g(null);return}const ee=T.getBoundingClientRect(),le=ee.top+ee.height*.35;let w=V[0]??null;for(const K of V){const $=m.current.get(K);if(!(!$||!$.isConnected))if($.getBoundingClientRect().top<=le)w=K;else break}T.scrollHeight-T.scrollTop-T.clientHeight<Ps&&(w=V[V.length-1]??w),g(w)},[V,g]),re=o.useCallback(()=>{const T=d.current;if(!T)return;const ee=T.scrollHeight-T.scrollTop-T.clientHeight;G.current?ee>=Ps&&(G.current=!1):k(ee<Ps),J()},[J,k]);o.useEffect(()=>{J()},[t,J]);const j=o.useCallback(T=>{const ee=d.current,le=m.current.get(T);if(!ee||!le||!le.isConnected)return;k(!1),R(T),E(he=>he+1),F.current&&window.clearTimeout(F.current),F.current=window.setTimeout(()=>R(null),1600);const w=ee.getBoundingClientRect(),K=le.getBoundingClientRect(),$=ee.scrollTop+(K.top-w.top)-ee.clientHeight/2+K.height/2;N.current&&window.clearTimeout(N.current),G.current=!0,ee.scrollTo({top:Math.max(0,$),behavior:"smooth"});const ne=()=>{G.current=!1};"onscrollend"in ee&&ee.addEventListener("scrollend",ne,{once:!0}),N.current=window.setTimeout(()=>{G.current=!1},1500)},[k]);o.useEffect(()=>()=>{F.current&&window.clearTimeout(F.current),N.current&&window.clearTimeout(N.current)},[]);const L=o.useCallback(()=>{N.current&&window.clearTimeout(N.current),G.current=!1;const T=d.current;T&&(T.scrollTop=T.scrollHeight)},[]),H=o.useCallback(()=>{N.current&&window.clearTimeout(N.current),G.current=!1,k(!0);const T=d.current;T&&T.scrollTo({top:T.scrollHeight,behavior:"smooth"})},[k]);o.useEffect(()=>{n&&(k(!0),L())},[n,L,k]);const W=o.useMemo(()=>{var ee,le,w,K,$;const T=B[B.length-1];return`${B.length}:${(T==null?void 0:T.id)??""}:${((ee=T==null?void 0:T.content)==null?void 0:ee.length)??0}:${((le=T==null?void 0:T.textBlocks)==null?void 0:le.length)??0}:${((w=T==null?void 0:T.toolCalls)==null?void 0:w.length)??0}:${((K=T==null?void 0:T.thinkingBlocks)==null?void 0:K.length)??0}:${(($=T==null?void 0:T.thinking)==null?void 0:$.length)??0}`},[B]),ie=o.useRef(W);return o.useEffect(()=>{if(!f){ie.current=W;return}W!==ie.current&&(ie.current=W,L())},[W,f,L]),e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsxs("div",{ref:d,onScroll:re,className:"h-full overflow-y-auto custom-scrollbar",children:[e.jsx("div",{className:"chat-stack flex flex-col pb-8 pt-5",children:B.map((T,ee)=>{const le=B[ee-1],w=le?le.type===T.type?"mt-2":"mt-5":"";return e.jsxs("div",{"data-mid":T.id,ref:Q,className:`relative w-full ${w}`,children:[y===T.id&&e.jsx("div",{className:"animate-rail-flash pointer-events-none absolute inset-0"},I),e.jsx(fc,{message:T,sessionId:r,onRegenerate:a,onDeleteMessage:i,onOpenSidebarView:l})]},T.id)})}),n&&!M&&e.jsx(kc,{label:c("chat.thinkingEllipsis")},r)]}),z.length>0&&e.jsx(bc,{items:z,activeId:p,onJump:j}),!f&&B.length>0&&e.jsx("button",{type:"button",onClick:H,title:c("chat.backToBottom"),"aria-label":c("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(Ue,{size:15})})]})});function ht(s){return s.recordId!==void 0?s.recordId:s.callId!==void 0?`${s.kind}\0call\0${s.callId}`:s.sourceSeq!==void 0?`${s.kind}\0seq\0${s.sourceSeq}`:`${s.kind}\0index\0${s.index}`}function vn(s){return mt(s===null?null:s*1e3)}const yc=2048,jc=512;function wc(s){return s.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 os(s){const t=s.slice(0,yc),n=wc(t).replace(/\s+/g," ").trim(),r=n.slice(0,jc).trimEnd();return t.length<s.length||r.length<n.length?`${r}…`:r}function br(s){if(Number.isFinite(s))return vn(s)}function kt(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function Nc(s){if(typeof s=="string")return s;try{return JSON.stringify(s,null,2)}catch{return""}}function sn(s){if(typeof s=="string")return s;if(s==null)return"";try{return JSON.stringify(s,null,2)}catch{return String(s)}}function Sc(s){if(s.status==="error")return{result:s.result===void 0?"error":sn(s.result)};const t=sn(s.result);return t===""?{result:"No output"}:{result:"",resultPreviewMarkdown:t}}function Mc(s,t){var i;const n=(t==null?void 0:t.get(s.id))??null,r=((i=s.summary)==null?void 0:i.durationMs)!==void 0?(n??s.timestamp)+s.summary.durationMs:null,a=n!==null||r!==null;if(a)return{timingRecorded:a,stepStartTime:s.timestamp,firstTokenTime:n,completedTime:r,usageProvided:!1,outputTokens:null}}function Cc(s,t,n){var l;const r=s.thinkingBlocks?s.thinkingBlocks.map(c=>c.text).join(`
27
+ `):s.thinking??"",a=Mc(s,n),i=(l=s.summary)==null?void 0:l.durationMs;return{index:t,kind:"message",text:"",...s.content===""?{}:{previewMarkdown:s.content},sourceSeq:t,inputDetail:s.content,...r===""?{}:{thinkingDetail:r},...a===void 0?{}:{assistantMetrics:a},timeSeconds:i===void 0?null:i/1e3,startedAt:s.timestamp}}function kr(s,t){const n=Nc(s.args),r=sn(s.result),a=Sc(s);return{index:t,kind:"tool",text:s.name,...n===""?{}:{previewMarkdown:n},sourceSeq:t,callId:s.id,...n===""?{}:{inputDetail:n},...r===""?{}:{outputDetail:r},...a,isError:s.status==="error",timeSeconds:s.duration===void 0?null:s.duration/1e3,startedAt:s.timestamp}}function vr(s,t){return{index:t,kind:"user",text:"",...s.content===""?{}:{previewMarkdown:s.content},sourceSeq:t,inputDetail:s.content,opensTurn:!0,timeSeconds:0,startedAt:s.timestamp}}function Ec(s,t){const n=[s.originalCount!==void 0?`original ${s.originalCount} msgs`:"",s.compressedCount!==void 0?`compressed ${s.compressedCount} msgs`:"",s.tokensSaved!==void 0?`freed ${s.tokensSaved} tokens`:""].filter(Boolean).join(", ");return{index:t,kind:"compacted",text:"Context compressed",sourceSeq:s.seq,...n===""?{}:{outputDetail:n},timeSeconds:0,startedAt:s.timestamp}}function Tc(s){var a;const t=[],n=[];for(const i of s)i.absTime===null||!Number.isFinite(i.absTime)||(n.push(i.absTime),i.cell.kind==="tool"&&i.cell.timeSeconds!==null&&Number.isFinite(i.cell.timeSeconds)&&n.push(i.absTime+i.cell.timeSeconds*1e3));if(n.length>=2){const i=br((Math.max(...n)-Math.min(...n))/1e3);i!==void 0&&t.push(i)}else if(n.length===1){const i=(a=s.find(c=>c.absTime===n[0]))==null?void 0:a.cell.timeSeconds,l=i!=null?br(i):void 0;l!==void 0&&t.push(l)}const r=new Map;for(const i of s)i.toolName===void 0||i.cell.kind!=="tool"||r.set(i.toolName,(r.get(i.toolName)??0)+1);for(const[i,l]of r)t.push(l>1?`${i}×${l}`:i);return t.length===0?void 0:t.join(" ")}function yr(s,t){const n=t.groups.map(({title:r,laid:a})=>{const i=Tc(a);return{title:r,...i!==void 0?{description:i}:{},cells:a.map(l=>l.cell)}});return{turn:s,groups:n}}function jr(s){return Math.min(...s.groups.flatMap(t=>t.cells.map(n=>n.index)),Number.POSITIVE_INFINITY)}function Ac(s){const{messages:t,compacted:n=[],ttft:r}=s,a=new Map,i=[];let l=0,c=0,d=null;const m=b=>{let v=a.get(b);return v===void 0&&(v={groups:[]},a.set(b,v)),v},f=(b,v)=>{const S=m(b).groups,k=S[S.length-1];if((k==null?void 0:k.title)==="Message"){k.laid.push(v);return}S.push({title:"Message",laid:[v]})},h=(b,v,S)=>{if(S.length===0)return;const k=m(b).groups,g=`Step ${v}`,y=k.find(R=>R.title===g);if(y!==void 0){y.laid.push(...S);return}k.push({title:g,laid:[...S]})},p=[...t.map(b=>({kind:"message",message:b})),...n.map(b=>({kind:"compacted",record:b}))].sort((b,v)=>{const S=b.kind==="message"?b.message.timestamp:b.record.timestamp,k=v.kind==="message"?v.message.timestamp:v.record.timestamp;return S-k});for(const b of p){if(b.kind==="compacted"){const g=Ec(b.record,++l);i.push({groups:[{title:`Compaction ${b.record.seq}`,laid:[{absTime:kt(b.record.timestamp),cell:g}]}]});continue}const v=b.message;if(ta(v)){c+=1;const g=vr(v,++l);f(c,{absTime:kt(v.timestamp),cell:g});continue}const S=c>0?c:d??1,k=eo(v)?vr(v,++l):Cc(v,++l,r);f(S,{absTime:kt(v.timestamp),cell:k}),d=S;for(const g of v.toolCalls??[]){const y=kr(g,++l);f(S,{absTime:kt(g.timestamp),toolName:g.name,callId:g.id,cell:y})}for(const[g,y]of(v.steps??[]).entries()){const R=(y.toolCalls??[]).map(I=>{const E=kr(I,++l);return{absTime:kt(I.timestamp),toolName:I.name,callId:I.id,cell:E}});h(S,g+1,R)}}return[...[...a.entries()].map(([b,v])=>yr(b,v)),...i.map(b=>yr(null,b))].sort((b,v)=>jr(b)-jr(v))}function ms(s){if(s.text!=="")return s.text;if(s.previewMarkdown!==void 0){const t=os(s.previewMarkdown);if(t!=="")return t}if(s.result!==void 0&&s.result!=="")return s.result;if(s.resultPreviewMarkdown!==void 0){const t=os(s.resultPreviewMarkdown);if(t!=="")return t}return s.kind}function Ls(s){return mt(s)}function ba(s){return s==="tool"||s==="subtool"?2:s==="message"||s==="compacted"?1:0}function wr(s){return s!=null&&Number.isFinite(s)}function Ic(s){if(!wr(s.startedAt))return null;const t=wr(s.timeSeconds)?Math.max(0,s.timeSeconds*1e3):0;return{start:s.startedAt,end:s.startedAt+t}}function ka(s,t="sequence"){if(t!=="sequence")return Rc(s,t==="duration");const n=[],r=[];for(const a of s){const i=a.groups.flatMap(l=>l.cells.filter(c=>c.requestOnly!==!0));i.length!==0&&(a.turn!==null&&r.push({turn:a.turn,time:n.length}),n.push(...i.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:ba(l.kind)}))))}return n.length===0?null:{start:0,end:n.length,spans:n,turnBoundaries:r}}function Rc(s,t){const n=s.flatMap(m=>{const f=m.groups.flatMap(h=>h.cells.flatMap(p=>{if(p.requestOnly===!0)return[];const b=Ic(p);return b===null?[]:[{...b,index:p.index,isError:p.isError===!0,kind:p.kind,label:p.text,lane:ba(p.kind)}]}));return f.length===0?[]:[{turn:m.turn,rawSpans:f}]}),r=n.flatMap(m=>m.rawSpans);if(r.length===0)return null;const a=new Map;let i=0,l=null;for(const m of[...r].sort((f,h)=>f.start-h.start||f.end-h.end))t&&l!==null&&m.start>l&&(i+=m.start-l),a.set(m,i),l=l===null?m.end:Math.max(l,m.end);const c=[],d=[];for(const m of n){const f=m.rawSpans.map(h=>{const p=a.get(h)??0;return{...h,start:h.start-p,end:h.end-p}});c.push(...f),m.turn!==null&&d.push({turn:m.turn,time:Math.min(...f.map(h=>h.start))})}return{start:Math.min(...c.map(m=>m.start)),end:Math.max(...c.map(m=>m.end)),spans:c,turnBoundaries:d}}function Dc(s,t,n="sequence"){const r=ka(s,n);return new Set(r==null?void 0:r.spans.filter(a=>a.start<=t.end&&a.end>=t.start).map(a=>a.index))}function _c(s,t){return s.length===t.length&&s.every((n,r)=>n===t[r])}function zc(s){if(s.previewMarkdown===void 0)return"";const t=os(s.previewMarkdown);return s.text===""?t:t===""?s.text:`${s.text} · ${t}`}function $c(s){return s.resultPreviewMarkdown===void 0?s.result??"":os(s.resultPreviewMarkdown)}function Oc(s,t,n){const r=[...n.sourceBlocks??[],...n.outputBlocks??[]];return[s===null?"between turns":`turn ${s}`,t,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(a=>[a.type,a.content,a.callId??"",a.toolName??"",a.imageAlt??""])]}class Pc{constructor(){Yt(this,"entries",new Map);Yt(this,"layouts")}update(t){if(this.layouts===t)return!1;this.layouts=t;const n=new Set;for(const r of t)for(const a of r)for(const i of a.groups)for(const l of i.cells){if(l.requestOnly===!0)continue;const c=ht(l),d=Oc(a.turn,i.title,l),m=this.entries.get(c),f=m!==void 0&&_c(m.sources,d)?m:{sources:d,text:[...d,zc(l),$c(l)].join(`
28
+ `).toLocaleLowerCase()};this.entries.set(c,f),n.add(c)}for(const r of this.entries.keys())n.has(r)||this.entries.delete(r);return!0}search(t){const n=t.trim().toLocaleLowerCase().split(/\s+/).filter(Boolean);if(n.length===0)return null;const r=new Set;for(const[a,i]of this.entries)n.every(l=>i.text.includes(l))&&r.add(a);return r}}const Lc=o.memo(function({actualDuration:t,onActualDurationChange:n,allTurnsCollapsed:r,onToggleAllTurns:a,allAssistantsCollapsed:i,onToggleAllAssistants:l,searchQuery:c,onSearchQueryChange:d}){const{t:m}=se();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":t,title:m(t?"trajectory.toolbar.equalWidth":"trajectory.toolbar.actualDuration"),onClick:()=>n(!t),children:[e.jsx(ss,{size:13}),m("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:m(r?"trajectory.toolbar.expandTurns":"trajectory.toolbar.collapseTurns"),onClick:a,children:[r?e.jsx(mi,{size:13}):e.jsx(xi,{size:13}),m("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":i,title:m(i?"trajectory.toolbar.expandCalls":"trajectory.toolbar.collapseCalls"),onClick:l,children:[e.jsx(fi,{size:13}),m("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(ds,{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":m("trajectory.toolbar.search"),placeholder:m("trajectory.toolbar.searchPlaceholder"),value:c,onChange:f=>d(f.currentTarget.value)})]})})]})}),Fc=3,Bc=500;function Hc(s){const t=s==null?void 0:s.stepStartTime,n=s==null?void 0:s.firstTokenTime,r=s==null?void 0:s.completedTime;return(s==null?void 0:s.timingRecorded)!==!0||typeof t!="number"||typeof n!="number"||typeof r!="number"||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||n<t||r<n?{}:{ttftMs:n-t,decodingMs:r-n}}function qc(s){const t=s.timeSeconds===null||!Number.isFinite(s.timeSeconds)?void 0:Math.max(0,s.timeSeconds*1e3),n=s.startedAt===null||!Number.isFinite(s.startedAt)?void 0:s.startedAt;return{...t===void 0?{}:{durationMs:t},...n===void 0?{}:{startedAt:n},...Hc(s.assistantMetrics)}}function Kc(s){switch(s){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 Fs(s){const t=new Date(s),n=a=>String(a).padStart(2,"0"),r=a=>String(a).padStart(3,"0");return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}.${r(t.getMilliseconds())}`}function Uc(s,t){const n=Kc(s);if(t===void 0)return n;const r=t.durationMs===void 0?null:`Total ${Ls(t.durationMs)}`,a=t.startedAt===void 0?null:t.durationMs===void 0?`Started ${Fs(t.startedAt)}`:`${Fs(t.startedAt)} → ${Fs(t.startedAt+t.durationMs)}`,i=t.ttftMs===void 0||t.decodingMs===void 0?null:`TTFT ${Ls(t.ttftMs)} · Decoding ${Ls(t.decodingMs)}`,l=[r,i].filter(c=>c!==null).join(" · ");return[n,a,l].filter(c=>c!==null&&c!=="").join(`
29
+ `)}function Wc(s,t){return s<=t?{start:s,end:t}:{start:t,end:s}}function Gc(s){return Math.min(1,Math.max(0,s))}const Vc=o.memo(function({turns:t,mode:n,range:r,selectedIndex:a=null,searchMatchIndexes:i=null,onRangeChange:l,onRecordSelect:c}){const d=o.useMemo(()=>ka(t,n),[n,t]),m=o.useMemo(()=>new Map(t.flatMap(j=>j.groups.flatMap(L=>L.cells.map(H=>[H.index,qc(H)])))),[t]),f=o.useMemo(()=>new Map(t.flatMap(j=>j.groups.flatMap(L=>L.cells.map(H=>[H.index,ms(H)])))),[t]),h=o.useRef(null),p=o.useRef(null),[b,v]=o.useState(null),[S,k]=o.useState(null),g=o.useRef(null),[y,R]=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&&R(j=>j!==null&&(j.end<d.start||j.start>d.end)?null:j)},[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 I=Math.max(1,d.end-d.start),E=(y==null?void 0:y.start)??d.start,F=y===null?I:Math.max(1,y.end-y.start),G=j=>{const L=h.current;if(!L)return 0;const H=L.getBoundingClientRect();return Gc((j-H.left)/Math.max(1,H.width))},N=j=>E+j*F,P=j=>{if(j.button===2){l(null);return}const H=j.target.closest("[data-timeline-record-index]"),W=H===null?null:Number(H.dataset.timelineRecordIndex);if(W!==null&&Number.isFinite(W)){c==null||c(W);return}p.current={pointerId:j.pointerId,anchorFraction:G(j.clientX),anchorClientX:j.clientX,recordIndex:null},j.currentTarget.setPointerCapture(j.pointerId)},B=j=>{const L=p.current;if(L!==null&&j.pointerId===L.pointerId){const T=G(j.clientX);if(Math.abs(j.clientX-L.anchorClientX)>=Fc){const ee=N(L.anchorFraction),le=N(T);v(Wc(ee,le))}return}const H=G(j.clientX),W=j.target.closest("[data-timeline-record-index]"),ie=W===null?null:Number(W.dataset.timelineRecordIndex);g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{k({fraction:H,recordIndex:Number.isFinite(ie)?ie:null})},Bc)},M=j=>{const L=p.current;L===null||j.pointerId!==L.pointerId||(p.current=null,b!==null&&(l(b),v(null)))},z=j=>{var L;((L=p.current)==null?void 0:L.pointerId)===j.pointerId&&(p.current=null,v(null))},V=j=>{if(d===null)return;const L=G(j.clientX),H=N(L),W=j.deltaY<0?.75:1.35,ie=Math.min(I,Math.max(1,F*W)),T=Math.min(Math.max(H-ie/2,d.start),d.end-ie);R({start:T,end:T+ie})},Q=o.useRef(()=>{});Q.current=V,o.useEffect(()=>{const j=h.current;if(!j)return;const L=H=>{H.preventDefault(),Q.current(H)};return j.addEventListener("wheel",L,{passive:!1}),()=>j.removeEventListener("wheel",L)},[d]);const J=b??r,re=S==null?void 0:S.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:h,className:"traj-track",role:"slider","aria-label":"Trajectory timeline",tabIndex:0,onKeyDown:j=>{j.key==="Escape"&&l(null)},onPointerDown:P,onPointerMove:B,onPointerUp:M,onPointerCancel:z,onPointerLeave:()=>{g.current&&clearTimeout(g.current),g.current=null,p.current===null&&k(null)},onDoubleClick:j=>{j.preventDefault(),l(null)},onContextMenu:j=>{j.preventDefault(),l(null)},children:[S!==null&&S.recordIndex===null&&b===null&&e.jsx("div",{className:"traj-hoverLine","aria-hidden":"true",style:{"--trajectory-hover-left":`${S.fraction*100}%`}}),J!==null&&e.jsx("div",{className:"traj-selection","data-dragging":b===null?void 0:"true","aria-hidden":"true",style:{"--trajectory-selection-left":`${(J.start-E)/F*100}%`,"--trajectory-selection-width":`${(J.end-J.start)/F*100}%`}}),e.jsx("div",{className:"traj-turnBoundaries","aria-hidden":"true",children:d.turnBoundaries.filter(j=>j.time>d.start&&j.time>=E&&j.time<=E+F).map(j=>e.jsx("span",{className:"traj-turnBoundary","data-turn":j.turn,style:{"--trajectory-turn-left":`${(j.time-d.start)/I*100}%`}},j.turn))}),e.jsx("div",{className:"traj-lanes","data-timeline-domain":"",children:d.spans.filter(j=>j.index===a||j.end>=E&&j.start<=E+F).map(j=>{const L=(j.start-d.start)/I,W=(j.end-j.start)/I*100,ie=m.get(j.index),T=ie==null?void 0:ie.ttftMs,ee=ie==null?void 0:ie.decodingMs,le=T===void 0||ee===void 0||T+ee<=0?null:T/(T+ee),w=f.get(j.index)??j.label;return e.jsx("span",{"aria-hidden":"true",className:"traj-span","data-timeline-span":j.kind,"data-timeline-record-index":j.index,"data-assistant-timing":le===null?void 0:"true","data-error":j.isError||void 0,"data-current":j.index===a||void 0,"data-hovered":re===j.index||void 0,"data-search-match":i===null?void 0:i.has(j.index)?"true":"false","data-selected":J===null?void 0:j.start<=J.end&&j.end>=J.start?"true":"false",title:Uc(j.kind,ie),style:{"--trajectory-span-left":`${L*100}%`,"--trajectory-span-width":`${W}%`,"--trajectory-span-lane":j.lane,...le===null?{}:{"--trajectory-assistant-ttft":`${le*100}%`}},children:w},j.index)})})]})]})});function Jc(s,t,n){const r=new Array(s);return new Proxy(r,{get(a,i,l){if(typeof i=="string"){const c=i.charCodeAt(0);if(c>=48&&c<=57){const d=+i;if(Number.isInteger(d)&&d>=0&&d<s){let m=a[d];if(!m){const f=t[d*2];m=a[d]={index:d,key:n(d),start:f,size:t[d*2+1],end:f+t[d*2+1],lane:0}}return m}}if(i==="length")return s}return Reflect.get(a,i,l)}})}function lt(s,t,n){let r=n.initialDeps??[],a,i=!0;function l(){const c=s();return(c.length!==r.length||c.some((m,f)=>r[f]!==m))&&(r=c,a=t(...c),n!=null&&n.onChange&&!(i&&n.skipInitialOnChange)&&n.onChange(a),i=!1),a}return l.updateDeps=c=>{r=c},l}function Nr(s,t){if(s===void 0)throw new Error("Unexpected undefined");return s}const Yc=(s,t)=>Math.abs(s-t)<1.01,Xc=(s,t,n)=>{let r;return Object.assign(function(...a){s.clearTimeout(r),r=s.setTimeout(()=>t.apply(this,a),n)},{cancel:()=>{s.clearTimeout(r)}})};let vt;const Bs=()=>{if(vt!==void 0)return vt;if(typeof navigator>"u")return vt=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return vt=!0;const s=navigator.maxTouchPoints;return vt=navigator.platform==="MacIntel"&&s!==void 0&&s>0},Sr=s=>{const{offsetWidth:t,offsetHeight:n}=s;return{width:t,height:n}},Qc=s=>s,Zc=s=>{const t=Math.max(s.startIndex-s.overscan,0),r=Math.min(s.endIndex+s.overscan,s.count-1)-t+1,a=new Array(r);for(let i=0;i<r;i++)a[i]=t+i;return a},ed=(s,t)=>{const n=s.scrollElement;if(!n)return;const r=s.targetWindow;if(!r)return;const a=l=>{const{width:c,height:d}=l;t({width:Math.round(c),height:Math.round(d)})};if(a(Sr(n)),!r.ResizeObserver)return()=>{};const i=new r.ResizeObserver(l=>{const c=()=>{const d=l[0];if(d!=null&&d.borderBoxSize){const m=d.borderBoxSize[0];if(m){a({width:m.inlineSize,height:m.blockSize});return}}a(Sr(n))};s.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return i.observe(n,{box:"border-box"}),()=>{i.unobserve(n)}},ls={passive:!0},td=typeof window>"u"?!0:"onscrollend"in window,sd=(s,t,n)=>{const r=s.scrollElement;if(!r)return;const a=s.targetWindow;if(!a)return;const i=s.options.useScrollendEvent&&td;let l=0;const c=i?null:Xc(a,()=>t(l,!1),s.options.isScrollingResetDelay),d=h=>()=>{l=n(r),c==null||c(),t(l,h)},m=d(!0),f=d(!1);return r.addEventListener("scroll",m,ls),i&&r.addEventListener("scrollend",f,ls),()=>{r.removeEventListener("scroll",m),i&&r.removeEventListener("scrollend",f),c==null||c.cancel()}},nd=(s,t)=>sd(s,t,n=>{const{horizontal:r,isRtl:a}=s.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),rd=(s,t,n)=>{if(n.options.useCachedMeasurements){const r=n.indexFromElement(s),a=n.options.getItemKey(r);return n.itemSizeCache.get(a)??n.options.estimateSize(r)}if(t!=null&&t.borderBoxSize){const r=t.borderBoxSize[0];if(r)return Math.round(r[n.options.horizontal?"inlineSize":"blockSize"])}if(!t){const r=n.indexFromElement(s),a=n.options.getItemKey(r),i=n.itemSizeCache.get(a);if(i!==void 0)return i}return s[n.options.horizontal?"offsetWidth":"offsetHeight"]},ad=(s,{adjustments:t=0,behavior:n},r)=>{var a,i;(i=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||i.call(a,{[r.options.horizontal?"left":"top"]:s+t,behavior:n})},id=ad;class od{constructor(t){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,a;return((a=(r=(n=this.targetWindow)==null?void 0:n.performance)==null?void 0:r.now)==null?void 0:a.call(r))??Date.now()},this.observer=(()=>{let n=null;const r=()=>n||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:n=new this.targetWindow.ResizeObserver(a=>{a.forEach(i=>{const l=()=>{const c=i.target,d=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[m,f]of this.elementsCache)if(f===c){this.elementsCache.delete(m);break}return}this.isIndexInRange(d)&&this.shouldMeasureDuringScroll(d)&&this.resizeItem(d,this.options.measureElement(c,i,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var i;return(i=r())==null?void 0:i.observe(a,{box:"border-box"})},unobserve:a=>{var i;return(i=r())==null?void 0:i.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r,a;const i={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Qc,rangeExtractor:Zc,onChange:()=>{},measureElement:rd,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 p in n){const b=n[p];b!==void 0&&(i[p]=b)}const l=this.options;let c=null,d=null,m=!1;if(l!==void 0&&l.enabled&&i.enabled&&i.anchorTo==="end"&&this.scrollElement!==null){const p=l.count,b=i.count,v=this.getMeasurements(),S=p>0?((r=v[0])==null?void 0:r.key)??l.getItemKey(0):null,k=p>0?((a=v[p-1])==null?void 0:a.key)??l.getItemKey(p-1):null;if(b!==p||p>0&&b>0&&(i.getItemKey(0)!==S||i.getItemKey(b-1)!==k)){m=!0;const R=p>0?this.getVirtualItemForOffset(this.getScrollOffset())??v[0]:null;R&&(c=[R.key,this.getScrollOffset()-R.start]);const I=i.followOnAppend===!0?"auto":i.followOnAppend||null;I&&b>p&&this.isAtEnd(l.scrollEndThreshold)&&(p===0||i.getItemKey(b-1)!==k)&&(d=I)}}this.options=i,m&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,h=0;if(c&&this.scrollOffset!==null){const[p,b]=c,v=this.getMeasurements(),{count:S,getItemKey:k}=this.options;let g=0;for(;g<S&&k(g)!==p;)g++;if(g<S){const y=v[g];if(y){const R=Math.max(0,y.start+b);R!==this.scrollOffset&&(h=R-this.scrollOffset,this.scrollOffset=R,f=!0)}}}(f||d)&&(this.pendingScrollAnchor=[f?c[0]:null,f?c[1]:0,d,h])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=lt(()=>(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(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,l)=>{if(l&&this._intendedScrollOffset===null&&i===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(i-this._intendedScrollOffset)<1.5&&(i=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const c=this.getScrollOffset();this.scrollDirection=l?c===i?this.scrollDirection:c<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=l,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const i=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,!(!Bs()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};i.addEventListener("touchstart",l,ls),i.addEventListener("touchend",c,ls),this.unsubs.push(()=>{i.removeEventListener("touchstart",l),i.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 a=this.pendingScrollAnchor;if(this.pendingScrollAnchor=null,a&&this.scrollElement&&this.options.enabled){const[i,l,c,d]=a;i!==null&&!c&&(Bs()&&(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 a=this._iosDeferredAdjustment;this._iosDeferredAdjustment=0,this._scrollToOffset(n,{adjustments:this.scrollAdjustments+=a,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=lt(()=>[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,a,i,l,c,d,m)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:i,enabled:l,lanes:c,laneAssignmentMode:d,gap:m}),{key:!1}),this.isIndexInRange=n=>n>=0&&n<this.options.count,this.getMeasurements=lt(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:i,enabled:l,lanes:c,laneAssignmentMode:d,gap:m},f)=>{const h=this.itemSizeCache;if(!l)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const g of this.laneAssignments.keys())g>=n&&this.laneAssignments.delete(g);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(g=>{this.itemSizeCache.set(g.key,g.size)}));const p=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===n&&(this.lanesSettling=!1),c===1){const g=n*2;let y=this._flatMeasurements;if(!y||y.length<g){const E=new Float64Array(g);y&&p>0&&E.set(y.subarray(0,p*2)),y=E,this._flatMeasurements=y}let R;if(p===0)R=r+a;else{const E=p-1;R=y[E*2]+y[E*2+1]+m}for(let E=p;E<n;E++){const F=i(E),G=h.get(F),N=typeof G=="number"?G:this.options.estimateSize(E);y[E*2]=R,y[E*2+1]=N,R+=N+m}const I=Jc(n,y,i);return this.measurementsCache=I,I}const b=this.measurementsCache.slice(0,p),v=new Array(c).fill(void 0),S=new Float64Array(c);let k=0;for(let g=0;g<p;g++){const y=b[g];y&&(v[y.lane]===void 0&&k++,v[y.lane]=g,S[y.lane]=y.end)}for(let g=p;g<n;g++){const y=i(g),R=this.laneAssignments.get(g);let I,E;const F=d==="estimate"||h.has(y);if(R!==void 0&&this.options.lanes>1){I=R;const B=v[I],M=B!==void 0?b[B]:void 0;E=M?M.end+m:r+a}else if(k===c){let B=0,M=S[0],z=v[0];for(let V=1;V<c;V++){const Q=S[V];(Q<M||Q===M&&v[V]<z)&&(B=V,M=Q,z=v[V])}I=B,E=M+m,F&&this.laneAssignments.set(g,I)}else I=g%this.options.lanes,E=r+a,F&&this.laneAssignments.set(g,I);const G=h.get(y),N=typeof G=="number"?G:this.options.estimateSize(g),P=E+N;b[g]={index:g,start:E,size:N,end:P,key:y,lane:I},v[I]===void 0&&k++,v[I]=g,S[I]=P}return this.measurementsCache=b,b},{key:!1,debug:()=>this.options.debug}),this.calculateRange=lt(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,i)=>n.length===0||r===0?(this.range=null,null):(this.range=cd(n,r,a,i,i===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=lt(()=>{let n=null,r=null;const a=this.calculateRange();return a&&(n=a.startIndex,r=a.endIndex),this.maybeNotify.updateDeps([this.isScrolling,n,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,n,r]},(n,r,a,i,l)=>i===null||l===null?[]:n({startIndex:i,endIndex:l,overscan:r,count:a}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=n=>{const r=this.options.indexAttribute,a=n.getAttribute(r);return a?parseInt(a,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 a=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(a!==void 0&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),l=Math.max(0,a-i),c=Math.min(this.options.count-1,a+i);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 a=this.options.getItemKey(r),i=this.elementsCache.get(a);i!==n&&(i&&this.observer.unobserve(i),this.observer.observe(n),this.elementsCache.set(a,n)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(n,void 0,this))},this.resizeItem=(n,r)=>{var a,i;if(!this.isIndexInRange(n))return;let l,c,d;const m=this._flatMeasurements;if(this.options.lanes===1&&m!==null)d=this.options.getItemKey(n),c=m[n*2],l=m[n*2+1];else{const p=this.measurementsCache[n];if(!p)return;d=p.key,c=p.start,l=p.size}const f=this.itemSizeCache.get(d)??l,h=r-f;if(h!==0){const p=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,b=p?this.getTotalSize():0,v=this.getScrollOffset()+this.scrollAdjustments,k=!this.itemSizeCache.has(d)?c<v:c+f<=v&&this.scrollDirection!=="backward",g=((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:d,start:c,size:l,end:c+l,lane:0},h,this):k);(this.pendingMin===null||n<this.pendingMin)&&(this.pendingMin=n),this.itemSizeCache.set(d,r),this.itemSizeCacheVersion++;let y=!1;p?y=this.applyScrollAdjustment(this.getTotalSize()-b):g&&(y=this.applyScrollAdjustment(h)),this.notify(y)}},this.getVirtualItems=lt(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const a=[];for(let i=0,l=n.length;i<l;i++){const c=n[i],d=r[c];a.push(d)}return a},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=n=>{const r=this.getMeasurements();if(r.length===0)return;const a=this._flatMeasurements,i=this.options.lanes===1&&a!=null,l=va(0,r.length-1,i?c=>a[c*2]:c=>Nr(r[c]).start,n);return Nr(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,a=0)=>{if(!this.scrollElement)return 0;const i=this.getSize(),l=this.getScrollOffset();r==="auto"&&(r=n>=l+i?"end":"start"),r==="center"?n+=(a-i)/2:r==="end"&&(n-=i);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 a=this.getSize(),i=this.getScrollOffset(),l=this.measurementsCache[n];if(!l)return;if(r==="auto")if(l.end>=i+a-this.options.scrollPaddingEnd)r="end";else if(l.start<=i+this.options.scrollPaddingStart)r="start";else return[i,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:a="auto"}={})=>{this._iosDeferredAdjustment=0;const i=this.getOffsetForAlignment(n,r),l=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:l,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollToIndex=(n,{align:r="auto",behavior:a="auto"}={})=>{this._iosDeferredAdjustment=0,n=Math.max(0,Math.min(n,this.options.count-1));const i=this.getOffsetForIndex(n,r);if(!i)return;const[l,c]=i,d=this.now();this.scrollState={index:n,align:c,behavior:a,startedAt:d,lastTargetOffset:l,stableFrames:0},this._scrollToOffset(l,{adjustments:void 0,behavior:a}),this.scheduleScrollReconcile()},this.scrollBy=(n,{behavior:r="auto"}={})=>{const a=this.getScrollOffset()+n,i=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:i,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{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 a;if(r.length===0)a=this.options.paddingStart;else if(this.options.lanes===1){const i=r.length-1,l=this._flatMeasurements;l!=null?a=l[i*2]+l[i*2+1]:a=((n=r[i])==null?void 0:n.end)??0}else{const i=Array(this.options.lanes).fill(null);let l=r.length-1;for(;l>=0&&i.some(c=>c===null);){const c=r[l];i[c.lane]===null&&(i[c.lane]=c.end),l--}a=Math.max(...i.filter(c=>c!==null))}return Math.max(a-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const n=[];if(this.itemSizeCache.size===0)return n;const r=this.getMeasurements();for(const a of r)a&&this.itemSizeCache.has(a.key)&&n.push({index:a.index,key:a.key,start:a.start,size:a.size,end:a.end,lane:a.lane});return n},this._scrollToOffset=(n,{adjustments:r,behavior:a})=>{this._intendedScrollOffset=n+(r??0),this.options.scrollToFn(n,{behavior:a,adjustments:r},this)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}applyScrollAdjustment(t,n){return t===0?!1:Bs()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?(this._iosDeferredAdjustment+=t,!1):(this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=t,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,a=r?r[0]:this.scrollState.lastTargetOffset,i=1,l=a!==this.scrollState.lastTargetOffset;if(!l&&Yc(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=i){this.getScrollOffset()!==a&&this._scrollToOffset(a,{adjustments:void 0,behavior:"auto"}),this.scrollState=null;return}}else if(this.scrollState.stableFrames=0,l){const c=this.getSize()||600,d=Math.abs(a-this.getScrollOffset()),m=this.scrollState.behavior==="smooth"&&d>c;this.scrollState.lastTargetOffset=a,m||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:m?"smooth":"auto"})}this.scheduleScrollReconcile()}}const va=(s,t,n,r)=>{for(;s<=t;){const a=(s+t)/2|0,i=n(a);if(i<r)s=a+1;else if(i>r)t=a-1;else return a}return s>0?s-1:0};function ld(s,t,n){let r=0;for(;r<=t;){const a=(r+t)/2|0,i=s[a*2];if(i<n)r=a+1;else if(i>n)t=a-1;else return a}return r>0?r-1:0}function cd(s,t,n,r,a){const i=s.length-1;if(s.length<=r)return{startIndex:0,endIndex:i};if(r===1&&a!==null){const m=ld(a,i,n);let f=m;const h=n+t;for(;f<i&&a[f*2]+a[f*2+1]<h;)f++;return{startIndex:m,endIndex:f}}let c=va(0,i,m=>s[m].start,n),d=c;if(r===1)for(;d<i&&s[d].end<n+t;)d++;else if(r>1){const m=Array(r).fill(0);for(;d<i&&m.some(h=>h<n+t);){const h=s[d];m[h.lane]=h.end,d++}const f=Array(r).fill(n+t);for(;c>=0&&f.some(h=>h>=n);){const h=s[c];f[h.lane]=h.start,c--}c=Math.max(0,c-c%r),d=Math.min(i,d+(r-1-d%r))}return{startIndex:c,endIndex:d}}const Hs=typeof document<"u"?o.useLayoutEffect:o.useEffect;function dd({useFlushSync:s=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const a=o.useReducer(f=>f+1,0)[1],i=o.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});i.current.enabled=t,i.current.mode=n;const l=f=>{const h=i.current;if(!h.enabled||!h.container)return;const p=f.getTotalSize();if(p!==h.lastSize){h.lastSize=p;const b=f.options.horizontal?"width":"height";h.container.style[b]=`${p}px`}},c=f=>{const h=i.current;if(!h.enabled||!h.container)return;l(f);const p=!!f.options.horizontal,b=h.mode==="transform",v=p?"left":"top",S=f.options.scrollMargin,k=f.getVirtualItems();for(const g of k){const y=g.start-S,R=f.elementsCache.get(g.key);R&&h.lastPositions.get(R)!==y&&(h.lastPositions.set(R,y),b?R.style.transform=p?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:R.style[v]=`${y}px`)}},d={...r,onChange:(f,h)=>{var p;const b=i.current;let v=!0;if(b.enabled){c(f);const S=f.range,k=b.prevRange;v=!k||k.isScrolling!==f.isScrolling||k.startIndex!==(S==null?void 0:S.startIndex)||k.endIndex!==(S==null?void 0:S.endIndex),v&&(b.prevRange=S?{startIndex:S.startIndex,endIndex:S.endIndex,isScrolling:f.isScrolling}:null)}v&&(s&&h?to.flushSync(a):a()),(p=r.onChange)==null||p.call(r,f,h)}},[m]=o.useState(()=>{const f=new od(d);return Object.assign(f,{containerRef:h=>{const p=i.current;if(p.container=h,p.lastSize=null,h&&p.enabled){const b=f.getTotalSize();p.lastSize=b;const v=f.options.horizontal?"width":"height";h.style[v]=`${b}px`}}})});return m.setOptions(d),Hs(()=>m._didMount(),[]),Hs(()=>(l(m),m._willUpdate())),Hs(()=>{c(m)}),m}function ud(s){return dd({observeElementRect:ed,observeElementOffset:nd,scrollToFn:id,...s})}const hd=30,md=20,xd=9;function cs(s){const t=encodeURIComponent(ht(s.cell));return s.collapsedSummaryKind===void 0?t:`${t}\0summary\0${s.collapsedSummaryKind}`}function fd(s){const t=[];let n=[];for(const[r,a]of s.entries()){const i={logicalIndex:r,record:a};if(a.cell.requestOnly===!0){n.push(i);continue}const l=[...n,i];n=[],t.push({entries:l,height:a.collapsedSummaryKind===void 0?hd:md,key:cs(a)})}return n.length>0&&t.push({entries:n,height:xd,key:n.map(r=>cs(r.record)).join("|")}),t}const pd=["Input","Output","Think","Time"],gd=o.memo(function({turn:t}){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 ",t]}),e.jsx("div",{className:"ml-auto flex items-center gap-3 pr-1 text-[10px] text-dark-muted/50","aria-hidden":"true",children:pd.map(n=>e.jsx("span",{className:"w-12 text-right",children:n},n))})]})}),bd=o.memo(function({title:t,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:t}),n!==void 0&&n!==""&&e.jsx("span",{className:"truncate text-dark-muted/50",children:n})]})}),kd={system:"System",user:"User",context:"Context",compacted:"Compacted",message:"Message",tool:"Tool",subtool:"Sub"},vd={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"},yd=o.memo(function({cell:t,selected:n=!1,onClick:r}){const{index:a,kind:i,timeSeconds:l,input:c,output:d,think:m}=t,f=ms(t),h=i==="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":i,"data-selected":n||void 0,onClick:()=>r==null?void 0:r(a),children:[e.jsxs("span",{className:"w-10 shrink-0 text-right tabular-nums text-dark-muted/50",children:["#",a]}),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",vd[i]].join(" "),children:kd[i]})}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-text",title:f,children:f}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2 tabular-nums text-dark-muted/60",children:[h&&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}),m!==void 0&&e.jsx("span",{title:"Reasoning tokens",children:m})]}),e.jsx("span",{className:"w-16 text-right",children:vn(l)})]})]})}),jd=100,wd=12,Nd=600,Sd=2;function Md(s){const t=o.useRef({rows:[],structure:[]});if(t.current.rows===s)return t.current.structure;const n=t.current.structure.length===s.length&&s.every((r,a)=>{const i=t.current.structure[a];return(i==null?void 0:i.key)===r.key&&i.height===r.height})?t.current.structure:s.map(r=>({key:r.key,height:r.height}));return t.current={rows:s,structure:n},n}function Cd(s){const t=[];for(const n of s){const r=[];for(const a of n.groups)a.cells.forEach((i,l)=>{r.push({turn:n.turn,group:a.title,groupDescription:a.description,groupStart:l===0,turnStart:r.length===0,cell:i,turnEnd:!1})});if(r.length>0){const a=r[r.length-1];a&&(a.turnEnd=!0)}t.push(...r)}return t}function Ed(s,t){const n=[];let r=[],a=null;const i=()=>{if(r.length!==0){if(a!==null&&t.has(a)){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 ${a} · ${l.length} records`,collapsedSummaryKind:"turn",cell:{...c.cell,index:c.cell.index}})}else n.push(...r);r=[],a=null}};for(const l of s)l.turnStart&&i(),a=l.turn,r.push(l);return i(),n}function Td(s,t){var a;const n=[];let r=0;for(;r<s.length;){const i=s[r],l=s[r+1];if(i.cell.kind==="message"&&l!==void 0&&(l.cell.kind==="tool"||l.cell.kind==="subtool")&&t.has(ht(i.cell))){let c=r+1;for(;c<s.length&&(s[c].cell.kind==="tool"||s[c].cell.kind==="subtool");)c+=1;const d=c-r-1;n.push({...i,groupStart:!0,turnEnd:((a=s[c-1])==null?void 0:a.turnEnd)??i.turnEnd,collapsedSummary:`${ms(i.cell)||"Message"} · ${d} tool call${d>1?"s":""}`,collapsedSummaryKind:"assistant"}),r=c;continue}n.push(i),r+=1}return n}function Ad(s,t){const n=[];let r=null,a=null;for(const i of s)i.turnStart&&(r=i),i.groupStart&&(a=i),t.has(i.cell.index)&&(r!==null&&n.length===0&&(n.push({...r,groupStart:!0,turnStart:!0}),r=null),a!==null&&n.length>0&&n[n.length-1].group!==i.group&&(n.push({...a,groupStart:!0,turnStart:!1}),a=null),n.push(i));return n}function qs(s){if(s===null||!Number.isFinite(s))return"Not available";const t=new Date(s),n=l=>String(l).padStart(2,"0"),r=l=>String(l).padStart(3,"0"),a=`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}.${r(t.getMilliseconds())}`;return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`} ${a}`}function Id(s){const t=[{id:"overview",label:"Summary"}];return s.inputDetail!==void 0&&s.inputDetail!==""&&t.push({id:"input",label:"Input"}),s.outputDetail!==void 0&&s.outputDetail!==""&&t.push({id:"output",label:"Output"}),s.thinkingDetail!==void 0&&s.thinkingDetail!==""&&t.push({id:"thinking",label:"Thinking"}),s.assistantMetrics!==void 0&&t.push({id:"timing",label:"Timing"}),(s.input!==void 0||s.output!==void 0||s.think!==void 0)&&t.push({id:"usage",label:"Usage"}),t}function Rd({cell:s,onClose:t}){var c;const n=Id(s),[r,a]=o.useState(((c=n[0])==null?void 0:c.id)??"overview"),i=ms(s),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:s.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:["#",s.index]})]}),s.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:s.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:vn(s.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:qs(s.startedAt??null)})]}),s.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"})]}),i!==""&&e.jsxs("div",{className:"pt-1",children:[e.jsx("dt",{className:"traj-detailKey mb-1",children:"Summary"}),e.jsx("dd",{className:"traj-detailBody",children:i})]})]});case"input":return e.jsx("div",{className:"traj-detailBody",children:s.inputDetail});case"output":return e.jsx("div",{className:"traj-detailBody",children:s.outputDetail});case"thinking":return e.jsx("div",{className:"traj-detailBody",children:s.thinkingDetail});case"timing":{const d=s.assistantMetrics;if(!d)return null;const m=d.firstTokenTime!==null&&d.stepStartTime!==null?d.firstTokenTime-d.stepStartTime:null,f=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:qs(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:qs(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:m===null?"—":`${m} 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:f===null?"—":`${f} ms`})]})]})}case"usage":return e.jsxs("dl",{className:"space-y-1.5",children:[s.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:s.input})]}),s.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:s.output})]}),s.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:s.think})]}),s.input===void 0&&s.output===void 0&&s.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 #",s.index]}),e.jsx("button",{type:"button",className:"rounded p-1 text-dark-muted hover:bg-dark-surface/60",onClick:t,"aria-label":"Close details",children:e.jsx(De,{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:()=>a(d.id),children:d.label},d.id))}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-3",children:l()})]})}function Dd({turns:s,searchMatchIndexes:t=null,selectedIndex:n,onSelectIndex:r,onDeselect:a,onClearSelection:i,collapsedTurns:l,onToggleTurn:c,collapsedAssistants:d,onToggleAssistant:m}){var B;const f=o.useRef(null),h=o.useMemo(()=>Cd(s),[s]),p=o.useMemo(()=>n===null?void 0:h.find(M=>M.cell.index===n),[h,n]),b=o.useMemo(()=>{if(t!==null)return Ad(h,t);const M=l.size===0?h:Ed(h,l);return d.size===0?M:Td(M,d)},[h,d,l,t]),v=o.useMemo(()=>fd(b),[b]),S=Md(v),k=b.length>jd,g=o.useCallback(M=>{var z;return((z=S[M])==null?void 0:z.height)??30},[S]),y=o.useCallback(M=>{var z;return((z=S[M])==null?void 0:z.key)??M},[S]),R=o.useCallback(()=>f.current,[]),I=ud({count:k?S.length:0,enabled:k,estimateSize:g,getItemKey:y,getScrollElement:R,initialRect:{width:0,height:Nd},anchorTo:"end",overscan:wd,scrollEndThreshold:Sd}),E=k?I.getVirtualItems():[],F=((B=E[0])==null?void 0:B.start)??0,G=k?I.getTotalSize():0,N=M=>{r(M)},P=M=>M.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:()=>{M.collapsedSummaryKind==="turn"&&M.turn!==null?c(M.turn):M.collapsedSummaryKind==="assistant"&&m(ht(M.cell))},children:[e.jsx("span",{className:"text-dark-muted/50",children:"▸"}),e.jsx("span",{className:"truncate",children:M.collapsedSummary})]}):e.jsxs(e.Fragment,{children:[M.turnStart&&M.turn!==null&&e.jsx(gd,{turn:M.turn}),M.groupStart&&e.jsx(bd,{title:M.group,description:M.groupDescription}),e.jsx(yd,{cell:M.cell,selected:n===M.cell.index,onClick:N})]});return e.jsxs("div",{className:"flex min-h-0 flex-1",children:[e.jsx("div",{ref:f,className:"min-w-0 flex-1 overflow-auto",onClick:M=>{M.target===M.currentTarget&&(i==null||i())},children:k?e.jsx("div",{style:{height:G,position:"relative"},children:E.map(M=>{const z=v[M.index];return z?e.jsx("div",{"data-virtual-row-key":z.key,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${M.start-F}px)`,height:z.height},children:z.entries.map(V=>e.jsx("div",{children:P(V.record)},cs(V.record)))},z.key):null})}):b.map(M=>e.jsx("div",{children:P(M)},cs(M)))}),p!==void 0&&e.jsx(Rd,{cell:p.cell,onClose:a},p.cell.index)]})}function Mr(s){const t=new Date(s),n=r=>String(r).padStart(2,"0");return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}const _d=o.memo(function({errors:t,onOpenLogs:n}){const{t:r}=se(),[a,i]=o.useState(!1),[l,c]=o.useState(null),d=o.useMemo(()=>t.filter(h=>h.level==="error"),[t]);if(o.useEffect(()=>{c(h=>h!==null&&d.length>h?null:h)},[d.length]),d.length===0||l!==null)return null;const m=d[d.length-1];if(m===void 0)return null;const f=d.slice(-20).reverse();return e.jsxs("div",{"data-trajectory-error-banner":"",className:"mx-2 mt-1 shrink-0 rounded-md border border-accent-red/50 bg-accent-red/10 text-xs",role:"alert",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-accent-red",children:[e.jsx($e,{size:14,className:"shrink-0","aria-hidden":"true"}),e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>i(h=>!h),title:r(a?"trajectory.errorBanner.collapse":"trajectory.errorBanner.expand"),children:[e.jsxs("span",{className:"shrink-0 font-semibold",children:[r("trajectory.errorBanner.title"),d.length>1&&e.jsxs("span",{className:"ml-1.5 rounded bg-accent-red px-1.5 py-0.5 text-[10px] font-semibold text-white",children:["×",d.length]})]}),e.jsxs("span",{className:"min-w-0 flex-1 truncate text-dark-text",children:[Mr(m.timestamp)," · ",m.message]}),a?e.jsx(ut,{size:14,className:"shrink-0","aria-hidden":"true"}):e.jsx(Ue,{size:14,className:"shrink-0","aria-hidden":"true"})]}),n&&e.jsxs("button",{type:"button",className:"flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-accent-red hover:bg-accent-red/15",onClick:n,title:r("trajectory.errorBanner.viewLogs"),children:[e.jsx(pi,{size:12,"aria-hidden":"true"}),r("trajectory.errorBanner.viewLogs")]}),e.jsx("button",{type:"button",className:"shrink-0 rounded p-0.5 text-dark-muted hover:bg-accent-red/15 hover:text-accent-red",onClick:()=>{c(d.length),i(!1)},title:r("trajectory.errorBanner.dismiss"),children:e.jsx(De,{size:14,"aria-hidden":"true"})})]}),a&&e.jsx("div",{className:"max-h-40 overflow-y-auto border-t border-accent-red/30 px-2 py-1.5 font-mono text-[11px] custom-scrollbar",children:f.map(h=>e.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[e.jsx("span",{className:"shrink-0 text-dark-muted",children:Mr(h.timestamp)}),e.jsx("span",{className:"shrink-0 rounded bg-accent-red px-1 py-0.5 text-[9px] font-semibold uppercase leading-none text-white",children:h.source}),e.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-all text-dark-text",children:h.message})]},h.id))})]})}),zd=new Set,$d=new Set,Od=[],Pd=3e3;function Ld({sessionId:s,messages:t,errorLogs:n,onOpenLogs:r}){const[a,i]=o.useState(zd),[l,c]=o.useState($d),[d,m]=o.useState(null),[f,h]=o.useState(!1),[p,b]=o.useState(""),[v]=o.useState(()=>new Pc),[S,k]=o.useState(0),g=o.useRef(null),y=o.useRef(!1),[R,I]=o.useState(null),E=Zn(w=>w.compactedBySession[s]??Fd),F=Zn(w=>w.ttftBySession[s]),G=o.useMemo(()=>{if(F!==void 0)return new Map(Object.entries(F))},[F]),N=o.useMemo(()=>Ac({messages:t,compacted:E,ttft:G}),[t,E,G]),P=f?"duration":"sequence";o.useEffect(()=>(g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{v.update([N]),k(w=>w+1),y.current=!0},y.current?Pd:0),()=>{g.current&&clearTimeout(g.current)}),[N,v]);const B=o.useMemo(()=>p.trim()===""?null:v.search(p),[p,S]),M=o.useMemo(()=>{if(B===null)return null;const w=new Set;for(const K of N)for(const $ of K.groups)for(const ne of $.cells)B.has(ht(ne))&&w.add(ne.index);return w},[N,B]),z=o.useMemo(()=>d===null?null:Dc(N,d,P),[N,P,d]),V=o.useMemo(()=>N.filter(w=>w.turn!==null&&w.groups.reduce((K,$)=>K+$.cells.filter(ne=>ne.requestOnly!==!0&&ne.kind!=="system").length,0)>1).flatMap(w=>w.turn===null?[]:[w.turn]),[N]),Q=V.length>0&&V.every(w=>a.has(w)),J=o.useMemo(()=>{const w=[];for(const K of N){const $=K.groups.flatMap(ne=>ne.cells);for(let ne=0;ne<$.length;ne++){const he=$[ne];if((he==null?void 0:he.kind)!=="message")continue;const te=$[ne+1];((te==null?void 0:te.kind)==="tool"||(te==null?void 0:te.kind)==="subtool")&&w.push(ht(he))}}return w},[N]),re=J.length>0&&J.every(w=>l.has(w)),j=o.useCallback(w=>{i(K=>{const $=new Set(K);return $.has(w)?$.delete(w):$.add(w),$})},[]),L=o.useCallback(()=>{i(w=>{const K=new Set(w);if(Q)for(const $ of V)K.delete($);else for(const $ of V)K.add($);return K})},[Q,V]),H=o.useCallback(w=>{c(K=>{const $=new Set(K);return $.has(w)?$.delete(w):$.add(w),$})},[]),W=o.useCallback(()=>{c(w=>{const K=new Set(w);if(re)for(const $ of J)K.delete($);else for(const $ of J)K.add($);return K})},[re,J]),ie=o.useCallback(w=>{m(w)},[]),T=o.useCallback(w=>{z!==null&&!z.has(w)&&m(null),I(K=>K===w?null:w)},[z]),ee=o.useCallback(()=>{I(null)},[]),le=o.useCallback(()=>{m(null),I(null)},[]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-conversation-composer-overlay":"",children:[e.jsx(Lc,{actualDuration:f,onActualDurationChange:w=>{h(w),m(null)},allTurnsCollapsed:Q,onToggleAllTurns:L,allAssistantsCollapsed:re,onToggleAllAssistants:W,searchQuery:p,onSearchQueryChange:b}),e.jsx(_d,{errors:n??Od,onOpenLogs:r}),e.jsx(Vc,{turns:N,mode:P,range:d,selectedIndex:R,searchMatchIndexes:M,onRangeChange:ie,onRecordSelect:T}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:e.jsx(Dd,{turns:N,searchMatchIndexes:M,selectedIndex:R,onSelectIndex:T,onDeselect:ee,onClearSelection:le,collapsedTurns:a,onToggleTurn:j,collapsedAssistants:l,onToggleAssistant:H})})]})}const Fd=[],Bd={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",chat:"border-accent-cyan/30 text-accent-cyan bg-accent-cyan/10",normal:"border-accent-green/30 text-accent-green"},Hd=o.memo(function(){const{t}=se(),n=Te(f=>f.mode),r=Te(f=>f.modeSource),a=Te(f=>f.setBaseMode),i=Te(f=>f.toggleAuto),l=n==="normal"?"act":n,c=Nt(l),d=Zs(l),m=r==="user_override";return e.jsxs("div",{className:"flex items-center gap-1",children:[so.map(f=>{const h=c===f,p=Qs[f],b=n!=="normal"&&h?Bd[n]??"border-dark-border text-dark-muted":"border-dark-border text-dark-muted hover:bg-dark-hover";return e.jsxs("button",{type:"button",onClick:()=>a(f),className:ge("px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",b),title:t("chat.clickToSwitchMode"),"aria-pressed":h,children:[p.label,h&&m&&e.jsx(Vn,{size:10,className:"ml-1 inline-block -mt-px","aria-hidden":!0})]},f)}),m&&e.jsx("span",{className:"flex items-center text-accent-yellow",title:t("plan.modeLocked"),"aria-label":t("plan.modeLocked"),children:e.jsx(Vn,{size:11,"aria-hidden":!0})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":d,disabled:c==="chat",onClick:()=>i(),className:ge("flex items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors",c==="chat"?"border-dark-border text-dark-muted opacity-50 cursor-not-allowed":ge("cursor-pointer",d?"border-accent-yellow/40 text-accent-yellow bg-accent-yellow/10":"border-dark-border text-dark-muted hover:bg-dark-hover")),title:t("plan.autoApprove"),children:[e.jsx(Ct,{size:11,className:ge(d?"text-accent-yellow":"text-dark-muted")}),e.jsx("span",{children:t("plan.autoApprove")})]})]})}),qd=o.memo(function(){var b,v;const{t}=se(),n=mn(S=>S.activeSessionId),r=Te(S=>n?S.pendingSuggestionsBySession[n]:void 0),a=Te(S=>S.clearPendingSuggestion),i=Te(S=>S.setBaseMode);if(!r)return null;const l=r.suggestedMode;if(l!=="act"&&l!=="goal")return null;const c=l,d=((b=Qs[c])==null?void 0:b.label)??c,m=((v=Qs[Nt(r.currentMode)])==null?void 0:v.label)??r.currentMode,f=typeof r.confidence=="number"?` · ${t("plan.modeSuggestionConfidence")} ${Math.round(r.confidence*100)}%`:"",h=()=>{i(c),a(r.sessionId)},p=()=>a(r.sessionId);return e.jsxs("div",{className:"flex items-center gap-2 border-b border-accent-cyan/20 bg-accent-cyan/10 px-4 py-1.5 text-xs",role:"status",children:[e.jsx("span",{className:"shrink-0 font-medium text-accent-cyan",children:t("plan.modeSuggestionTitle")}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1 text-dark-muted",children:[e.jsx("span",{className:"whitespace-nowrap",children:m}),e.jsx(ln,{size:11,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"whitespace-nowrap text-dark-text",children:d}),e.jsx("span",{className:"shrink-0",children:f}),r.reason&&e.jsxs("span",{className:"hidden min-w-0 truncate md:inline",title:r.reason,children:["· ",r.reason]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:h,className:ge("flex items-center gap-1 rounded-full border border-accent-cyan/40 px-2.5 py-0.5","text-accent-cyan transition-colors hover:bg-accent-cyan/20 cursor-pointer"),children:[e.jsx(Fe,{size:11,"aria-hidden":!0}),t("plan.modeSuggestionApply",{mode:d})]}),e.jsxs("button",{type:"button",onClick:p,className:ge("flex items-center gap-1 rounded-full border border-dark-border px-2.5 py-0.5","text-dark-muted transition-colors hover:bg-dark-hover cursor-pointer"),children:[e.jsx(De,{size:11,"aria-hidden":!0}),t("plan.modeSuggestionKeep",{mode:m})]})]})]})}),Cr={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"}},Kd=o.memo(function(){const{t}=se(),n=dt(A=>A.model),r=dt(A=>A.modelRef),a=dt(A=>A.setModel),i=dt(A=>A.setModelRef),l=Te(A=>A.mode),c=Xs(A=>A.effort),d=Xs(A=>A.setEffort),[m,f]=o.useState([]),[h,p]=o.useState(!1),b=o.useRef(null),[v,S]=o.useState("session"),k=mn(A=>A.activeSessionId),[g,y]=o.useState(!1),[R,I]=o.useState(""),[E,F]=o.useState(""),[G,N]=o.useState([]),[P,B]=o.useState(new Set),[M,z]=o.useState("none"),[V,Q]=o.useState(!1),[J,re]=o.useState(null),[j,L]=o.useState(null),H=o.useMemo(()=>Array.from(new Set(m.map(A=>A.provider))),[m]),W=o.useCallback(async()=>{try{const A=await ve.models.list();A.success&&A.data&&Array.isArray(A.data.models)&&f(A.data.models.filter(oe=>oe.enabled!==!1))}catch{}},[]),ie=o.useCallback(()=>{var oe,U;const A=no(r)||((oe=m.find(ye=>ye.isGlobalDefault))==null?void 0:oe.provider)||((U=m[0])==null?void 0:U.provider)||"";I(A),F(""),re(null),y(!0)},[r,m]),T=o.useCallback(()=>{y(!1),N([]),re(null)},[]),ee=o.useCallback(async(A,oe)=>{if(A){Q(!0),re(null);try{const U=await ve.models.byProvider(A,oe||void 0);U.success&&U.data?(N(U.data.models||[]),B(new Set(U.data.existing||[])),z(U.data.source)):(N([]),B(new Set),re(U.error||t("chat.loadModelsFailed")))}catch{N([]),B(new Set),re(t("chat.loadModelsFailed"))}finally{Q(!1)}}},[t]);o.useEffect(()=>{if(!g)return;const A=setTimeout(()=>{ee(R,E)},E?300:0);return()=>clearTimeout(A)},[g,R,E,ee]),o.useEffect(()=>{W()},[W]),o.useEffect(()=>{const A=()=>{W()};return window.addEventListener("models-updated",A),()=>window.removeEventListener("models-updated",A)},[W]);const le=o.useCallback(()=>p(!1),[]);o.useEffect(()=>{if(!h)return;const A=U=>{b.current&&!b.current.contains(U.target)&&le()},oe=U=>{U.key==="Escape"&&le()};return document.addEventListener("mousedown",A),document.addEventListener("keydown",oe),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",oe)}},[h,le]);const w=async A=>{if(le(),!k&&v==="session"){ce.error(t("chat.sessionModelNoSession"));return}const oe=n,U=r;if(a(A.id),i(`${A.provider}:${A.id}`),v==="session"){if(!k)return;try{const Ae=await ve.models.setSessionModel(k,A.provider,A.id);Ae.success||(a(oe),i(U),ce.error(Ae.error||t("chat.switchModelFailed")))}catch{a(oe),i(U),ce.error(t("chat.switchModelFailed"))}return}const ye=Nt(l==="normal"?"act":l),be=`${A.provider}:${A.id}`,We=ye==="goal"?{goal:be}:{global:be,act:be};try{const Ae=await ve.models.setDefaults(We);Ae.success?await W():(a(oe),i(U),ce.error(Ae.error||t("chat.switchModelFailed")))}catch{a(oe),i(U),ce.error(t("chat.switchModelFailed"))}},K=async A=>{const oe=P.has(A.id),U=`${R}:${A.id}`;L(A.id);const ye=n,be=r;a(A.id),i(U);try{if(!oe){const je=await ve.models.create({provider:R,model:{id:A.id,name:A.name||A.id}});if(!je.success){a(ye),i(be),re(je.error||t("chat.addModelFailed"));return}}if(v==="session"){if(!k){a(ye),i(be),ce.error(t("chat.sessionModelNoSession"));return}const je=await ve.models.setSessionModel(k,R,A.id);je.success?(T(),await W()):(a(ye),i(be),re(je.error||t("chat.switchModelFailed")));return}const Ae=Nt(l==="normal"?"act":l)==="goal"?{goal:U}:{global:U,act:U},Rt=await ve.models.setDefaults(Ae);Rt.success?(T(),await W()):(a(ye),i(be),re(Rt.error||t("chat.switchModelFailed")))}catch{a(ye),i(be),re(t("chat.addModelFailed"))}finally{L(null)}},$=Nt(l==="normal"?"act":l),ne=$==="goal"?"isGoalDefault":"isActDefault",he=A=>{const oe=`${A.provider}:${A.id}`;if(r)return r===oe;if(n===oe)return!0;if(n!==A.id)return!1;const U=m.filter(be=>be.id===A.id);return U.length<=1?!0:(U.find(be=>be[ne]===!0)??U.find(be=>be.isGlobalDefault)??U[0])===A},te=m.some(A=>A[ne]===!0),me=m.find(A=>A.isGlobalDefault),de=async()=>{le();const A=$==="goal"?{goal:null}:{act:null};try{(await ve.models.setDefaults(A)).success&&(me?(a(me.id),i(`${me.provider}:${me.id}`)):(a(""),i("")),await W())}catch{}},D=o.useMemo(()=>ro(m),[m]),ae=ao(n,r),Y=Cr[c];return e.jsxs("div",{className:"relative min-w-0",ref:b,children:[e.jsxs("button",{type:"button",onClick:()=>p(A=>!A),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:ae||t("chat.clickToSelectModel"),"aria-haspopup":"listbox","aria-expanded":h,children:[e.jsx(gi,{size:12,className:"shrink-0"}),e.jsx("span",{className:"font-medium max-w-[8rem] truncate",children:ae||t("chat.selectModel")}),e.jsx("span",{className:"h-3 w-px bg-dark-border shrink-0","aria-hidden":"true"}),e.jsx(Jn,{size:12,className:`shrink-0 ${Y.color}`}),e.jsx("span",{className:`text-xs font-medium ${Y.color}`,children:t(Y.labelKey)}),e.jsx(Ue,{size:12,className:ge("transition-transform",h&&"rotate-180")})]}),h&&e.jsxs("div",{role:"listbox","aria-label":t("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:t("chat.selectModel")}),e.jsx("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b border-dark-border",children:[{key:"session",label:t("chat.applyScopeSession"),hint:t("chat.sessionScopeHint")},{key:"global",label:t("chat.applyScopeGlobal"),hint:t("chat.globalScopeHint")}].map(({key:A,label:oe,hint:U})=>e.jsx("button",{type:"button",onClick:()=>S(A),title:U,className:ge("text-[11px] px-2 py-0.5 rounded-full border transition-colors cursor-pointer",v===A?"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:oe},A))}),g?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:T,title:t("chat.backToModels"),"aria-label":t("chat.backToModels"),className:"p-1 rounded hover:bg-dark-hover text-dark-muted hover:text-dark-text shrink-0",children:e.jsx(bi,{size:12})}),H.length>1?e.jsx("select",{value:R,onChange:A=>I(A.target.value),"aria-label":t("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:H.map(A=>e.jsx("option",{value:A,children:A},A))}):e.jsx("span",{className:"flex-1 min-w-0 text-xs font-medium text-dark-text truncate",children:R||t("chat.noConfiguredProviders")}),e.jsx("input",{value:E,onChange:A=>F(A.target.value),placeholder:t("chat.searchModels"),"aria-label":t("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:V?e.jsxs("div",{className:"px-3 py-2 text-xs text-dark-muted flex items-center gap-1.5",children:[e.jsx(ki,{size:11,className:"animate-spin"}),t("chat.loadingModels")]}):J?e.jsx("div",{className:"px-3 py-2 text-xs text-accent-red",children:J}):R?G.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t(E?"chat.noModelsFound":"chat.noProviderModels")}):e.jsxs(e.Fragment,{children:[M!=="none"&&e.jsx("div",{className:"px-3 pt-1.5 pb-0.5 text-[10px] text-dark-muted/70",children:t(M==="provider-api"?"chat.modelsSourceProviderApi":"chat.modelsSourceCatalog")}),G.map(A=>{const oe=P.has(A.id),U=r===`${R}:${A.id}`;return e.jsxs("button",{type:"button",role:"option","aria-selected":U,onClick:()=>K(A),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:A.name||A.id}),U&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-green/20 text-accent-green shrink-0",children:t("chat.currentModel")})]}),e.jsx("span",{className:"block text-[10px] text-dark-muted truncate mt-0.5",children:A.id})]}),oe?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-green/20 text-accent-green shrink-0",children:t("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:j===A.id?t("chat.addingModel"):t("chat.addAndSwitch")})]},A.id)})]}):e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("chat.noConfiguredProviders")})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"py-1 max-h-[32vh] overflow-y-auto custom-scrollbar",children:[te&&e.jsx("button",{type:"button",role:"option","aria-selected":!1,onClick:de,title:t("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(vi,{size:11}),t("chat.followGlobalDefault")]}),e.jsx("span",{className:"block text-[10px] text-dark-muted mt-0.5 truncate",children:me?me.name||me.id:t("chat.noGlobalDefault")})]})}),D.map(([A,oe])=>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:A}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:oe.length})]}),oe.map(U=>{const ye=he(U);return e.jsx("button",{type:"button",role:"option","aria-selected":ye,onClick:()=>w(U),className:ge("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors",ye?"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:ge("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",ye?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Fe,{size:11,strokeWidth:3})}),e.jsx("span",{className:"text-xs font-semibold text-dark-text truncate",children:U.name||U.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:U.id}),U.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-red/20 text-accent-red",children:t("chat.globalDefault")}),U.isActDefault&&!U.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-yellow/20 text-accent-yellow",children:t("chat.actDefault")}),U.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-purple/20 text-accent-purple",children:t("chat.goalDefault")})]})]})},`${U.provider}:${U.id}`)})]},A)),m.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t("chat.noEnabledModels")})]}),e.jsxs("button",{type:"button",onClick:ie,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(ds,{size:11}),t("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(Jn,{size:11}),t("chat.effort")]}),e.jsx("div",{className:"py-1",children:io.map(A=>{const oe=Cr[A],U=A===c;return e.jsxs("button",{type:"button",role:"option","aria-selected":U,onClick:()=>{d(A),le()},className:ge("w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors",U?"bg-dark-hover":"hover:bg-dark-hover"),children:[e.jsx("span",{className:ge("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",U?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Fe,{size:11,strokeWidth:3})}),e.jsx("span",{className:`text-xs font-medium ${U?oe.color:"text-dark-text"}`,children:t(oe.labelKey)})]},A)})})]})]})});function yt(s){const t=(s??"").toLowerCase();return t?t.includes("android")?"android":t.includes("iphone")||t.includes("ipad")||t.includes("ipod")?"ios":t.includes("mac")||t.includes("darwin")?"macos":t.includes("win")?"windows":t.includes("linux")||t.includes("x11")||t.includes("cros")?"linux":null:null}function Ud(){if(typeof navigator>"u")return"unknown";const s=typeof navigator.userAgent=="string"?navigator.userAgent:"",t=yt(s);if(t==="android"||t==="ios")return t;const n=navigator.userAgentData,r=yt(n==null?void 0:n.platform);if(r)return r;const a=typeof navigator.platform=="string"?navigator.platform:"";return yt(a)==="macos"&&(navigator.maxTouchPoints??0)>1?"ios":yt(a)??yt(s)??"unknown"}function Wd(){if(typeof navigator>"u")return"unknown";const s=navigator.userAgentData,t=`${(s==null?void 0:s.architecture)??""} ${navigator.userAgent??""} ${navigator.platform??""}`.toLowerCase();return/arm|aarch64|apple silicon/.test(t)?"arm64":/x86_64|amd64|x64|win64|wow64|intel/.test(t)?"x64":"unknown"}function Gd(){return typeof window<"u"&&window.__TAURI__!==void 0}const Er={windows:"chat.desktopDownloadOsWindows",macos:"chat.desktopDownloadOsMacos",linux:"chat.desktopDownloadOsLinux",android:"chat.desktopDownloadOsAndroid",ios:"chat.desktopDownloadOsIos",unknown:"chat.desktopDownloadOsUnknown"},Vd=["windows","macos","linux"];function Jd(s){if(typeof s!="number"||!Number.isFinite(s)||s<=0)return null;const t=s/(1024*1024);return t>=10?`${Math.round(t)} MB`:`${t.toFixed(1)} MB`}function Yd(s){try{return new URL(s).host}catch{return s}}function Tr(s){return s.url||s.mirrors[0]||""}function Ar(s,t){const n=document.createElement("a");n.href=s,n.download=t,n.target="_blank",n.rel="noopener",n.style.display="none",document.body.appendChild(n),n.click(),n.remove()}const Xd=o.memo(function({onHandoffToAi:t}){var re;const{t:n}=se(),[r,a]=o.useState("idle"),[i,l]=o.useState(null),[c,d]=o.useState(!1),m=o.useRef(null),f=o.useRef(!0),h=o.useRef(!1),p=o.useRef(!1);o.useEffect(()=>(f.current=!0,()=>{f.current=!1}),[]);const b=o.useMemo(()=>Ud(),[]),v=o.useMemo(()=>Wd(),[]),S=o.useMemo(()=>Gd(),[]),k=n(Er[b]),g=b==="android"||b==="ios",y=S?n("chat.desktopDownloadOtherPlatforms"):n("chat.desktopDownloadTitle",{os:k}),R=n(S?"chat.desktopDownloadOtherPlatforms":"chat.desktopDownloadRecommend"),I=(i==null?void 0:i.artifacts)??{},E=(re=I[b])==null?void 0:re[0],F=(i==null?void 0:i.page)||oo(),G=v==="arm64"&&(b==="windows"||b==="linux"),N=o.useCallback(()=>{h.current||(h.current=!0,a("loading"),ve.system.desktopDownload().then(j=>{f.current&&(j.success&&j.data?(l(j.data),a("ready")):a("failed"))}).catch(()=>{f.current&&a("failed")}))},[]);o.useEffect(()=>{if(!c)return;const j=H=>{var W;(W=m.current)!=null&&W.contains(H.target)||d(!1)},L=H=>{H.key==="Escape"&&d(!1)};return document.addEventListener("mousedown",j),document.addEventListener("keydown",L),()=>{document.removeEventListener("mousedown",j),document.removeEventListener("keydown",L)}},[c]);const P=o.useCallback(()=>{window.open(F,"_blank","noopener")},[F]),B=o.useCallback(j=>{const L=Tr(j);if(d(!1),!L){P(),ce.warning(n("chat.desktopDownloadUnavailable"));return}Ar(L,j.name),j.url&&j.source==="mirror"&&ce.info(n("chat.desktopDownloadViaMirrorToast"))},[P,n]),M=o.useCallback(()=>{if(g){P(),ce.info(n("chat.desktopDownloadMobileHint"));return}if(r==="failed"){P(),ce.warning(n("chat.desktopDownloadUnavailable"));return}if(r==="ready"){E?B(E):(P(),ce.warning(n("chat.desktopDownloadUnavailable")));return}p.current=!0,N(),ce.info(n("chat.desktopDownloadFetching"))},[B,g,P,E,N,r,n]);o.useEffect(()=>{r!=="ready"&&r!=="failed"||p.current&&(p.current=!1,M())},[r,M]);const z=o.useCallback(()=>{const j=E?Tr(E):F,L=((E==null?void 0:E.mirrors)??[]).slice(0,3).join(" ");t(n("chat.desktopDownloadPrompt",{os:k,url:j||F,mirrors:L||n("chat.desktopDownloadPromptNoMirror")})),d(!1),ce.success(n("chat.desktopDownloadHandToAiHint"))},[t,k,E,F,n]),V=(j,L,H)=>{const W=Jd(j.size),ie=lo(j.name);return e.jsxs("button",{type:"button",onClick:()=>B(j),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(Yn,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[e.jsxs("span",{className:"font-medium",children:[H?`${n(Er[L])} · `:"",ie]}),j.source==="mirror"&&e.jsx("span",{className:"ml-1.5 rounded bg-accent-yellow/15 px-1 py-0.5 text-[10px] text-accent-yellow",children:n("chat.desktopDownloadFromMirror")}),e.jsx("span",{className:"mt-0.5 block truncate text-[10px] text-dark-muted",children:j.name})]}),W&&e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted",children:n("chat.desktopDownloadSize",{size:W})})]},`${L}-${j.name}`)},Q=Vd.filter(j=>{var L;return j!==b&&(((L=I[j])==null?void 0:L.length)??0)>0}),J=(E==null?void 0:E.mirrors)??[];return e.jsxs("div",{className:"relative flex shrink-0 items-center",ref:m,onPointerEnter:N,onFocus:N,children:[e.jsxs("button",{type:"button",onClick:M,className:"flex h-8 items-center gap-1.5 rounded-l-full pl-2.5 pr-1.5 text-[11px] font-medium text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:y,"aria-label":y,children:[e.jsx(Yn,{size:14,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"hidden whitespace-nowrap sm:inline",children:R})]}),e.jsx("button",{type:"button",onClick:()=>{c||N(),d(!c)},className:"flex h-8 w-4 items-center justify-center rounded-r-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:n("chat.desktopDownloadMenu"),"aria-label":n("chat.desktopDownloadMenu"),"aria-haspopup":"menu","aria-expanded":c,children:e.jsx(ut,{size:11,className:ge("transition-transform",c&&"rotate-180"),"aria-hidden":"true"})}),c&&e.jsxs("div",{role:"menu","aria-label":n("chat.desktopDownloadMenu"),className:"absolute bottom-full left-0 mb-1 z-50 w-72 overflow-hidden rounded-lg border border-dark-border bg-dark-surface shadow-xl",children:[e.jsx("div",{className:"border-b border-dark-border px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-dark-muted",children:n("chat.desktopDownloadYourSystem",{os:k})}),e.jsx("div",{className:"py-1",children:(I[b]??[]).length>0?(I[b]??[]).map(j=>V(j,b,!1)):e.jsx("div",{className:"px-3 py-1.5 text-[11px] leading-relaxed text-dark-muted",children:n(g?"chat.desktopDownloadMobileMenuHint":r==="failed"?"chat.desktopDownloadUnavailable":"chat.desktopDownloadLoading")})}),G&&e.jsx("div",{className:"border-t border-dark-border px-3 py-1.5 text-[10px] leading-relaxed text-accent-yellow",children:n("chat.desktopDownloadArmHint")}),Q.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-y border-dark-border px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-dark-muted",children:n("chat.desktopDownloadOtherSystems")}),e.jsx("div",{className:"py-1",children:[...Q].flatMap(j=>(I[j]??[]).map(L=>V(L,j,!0)))})]}),e.jsx("div",{className:"border-y border-dark-border px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-dark-muted",children:n("chat.desktopDownloadTrouble")}),e.jsxs("div",{className:"py-1",children:[J.slice(0,2).map(j=>e.jsxs("button",{type:"button",onClick:()=>{d(!1),Ar(j,(E==null?void 0:E.name)??"")},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(as,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:n("chat.desktopDownloadViaMirror",{host:Yd(j)})})]},j)),e.jsxs("button",{type:"button",onClick:()=>{d(!1),P()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-dark-text transition-colors hover:bg-dark-hover",children:[e.jsx(as,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:n("chat.desktopDownloadOpenRelease")})]})]}),e.jsx("div",{className:"border-t border-dark-border",children:e.jsxs("button",{type:"button",onClick:z,className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-accent-blue transition-colors hover:bg-dark-hover",children:[e.jsx(dn,{size:12,className:"shrink-0","aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium",children:n("chat.desktopDownloadHandToAi")}),e.jsx("span",{className:"mt-0.5 block text-[10px] text-dark-muted",children:n("chat.desktopDownloadHandToAiDesc")})]})]})}),b==="macos"&&e.jsx("div",{className:"border-t border-dark-border px-3 py-1.5 text-[10px] leading-relaxed text-dark-muted/80",children:n("chat.desktopDownloadMacUnsignedHint")}),r!=="ready"&&r!=="failed"&&e.jsxs("div",{className:"flex items-center gap-1.5 border-t border-dark-border px-3 py-1.5 text-[10px] text-dark-muted",children:[e.jsx(Re,{size:10,className:"animate-spin","aria-hidden":"true"}),n("chat.desktopDownloadFetching")]})]})]})}),Ze="__files__",Qd="__sessions__";function Zd(s){return s==="enqueue"?"summarize":s==="summarize"?"next-step":s==="next-step"?"direct":"enqueue"}function eu(s){return s.replace(/[\\/]+$/,"").replace(/\\/g,"/").toLowerCase()}function tu(s){return[{key:Ze,label:s.files},{key:Qd,label:s.sessions}]}function Ir(s){return s?eu(s):"￿"}function su(s,t){return t===Ze?s.filter(r=>r.kind==="file"):[...s.filter(r=>r.kind==="session")].sort((r,a)=>Ir(r.kind==="session"?r.dir:"").localeCompare(Ir(a.kind==="session"?a.dir:"")))}function nu(s,t,n){if(s.length===0)return t;const r=s.indexOf(t),a=r<0?-1:r;if(n)return s[(a+1)%s.length];const i=a<0?s.length:a;return s[(i-1+s.length)%s.length]}const ru=new Set(["running"]);function au(s){return ru.has(String(s.status||""))?!0:s.live===!0}function iu(s,t){const n=[];for(const r of s){const a=String(r.id||r.sessionId||"");if(!a||a===t)continue;const i=String(r.title||a.slice(0,8));n.push({kind:"session",key:a,label:i,detail:a.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 Rr(s,t,n="active"){const r=iu(s,t);if(n==="all")return r;const a=new Map(s.map(i=>[String(i.id||i.sessionId||""),i]));return r.filter(i=>{const l=a.get(i.key);return l?au(l):!1})}const ou={enqueue:"chat.mentionDeliveryEnqueue",summarize:"chat.mentionDeliverySummarize","next-step":"chat.mentionDeliveryNextStep",direct:"chat.mentionDeliveryDirect"},lu={enqueue:"text-dark-muted hover:text-dark-text hover:bg-dark-hover",summarize:"text-dark-muted hover:text-dark-text hover:bg-dark-hover","next-step":"bg-accent-blue/20 text-accent-blue font-medium",direct:"bg-accent-green/20 text-accent-green font-medium"};function cu(s){return s==="running"?"bg-accent-green/15 text-accent-green":s==="paused"||s==="interrupted"||s==="error"?"bg-accent-yellow/15 text-accent-yellow":"bg-dark-hover text-dark-muted"}function du(s){return s==="running"?"chat.mentionStatusRunning":s==="paused"||s==="interrupted"?"chat.mentionStatusPaused":s==="error"?"chat.mentionStatusError":s==="stopped"?"chat.mentionStatusStopped":"chat.mentionStatusIdle"}function uu(s){return s?/^\d{12,}$/.test(s)?Number(s):s:0}function hu({isOpen:s,items:t,selectedIndex:n,query:r,isSearching:a,onSelect:i,onHover:l,selectedCount:c=0,onFinish:d,tabs:m,activeTab:f,onTabChange:h,scope:p="active",onToggleScope:b,deliveryMode:v="enqueue",onToggleDelivery:S}){const{t:k}=se();if(!s)return null;const g=!!(h&&m&&m.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}`:`@ ${k("chat.mentionFilesGroup")} / ${k("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:k("chat.selectedCountShort",{n:c})}),e.jsx("span",{children:k(g?"chat.mentionTabHint":"chat.fileMentionHelpMulti")})]})]}),g&&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:m.map(y=>{const R=y.key===f;return e.jsx("button",{type:"button",onMouseDown:I=>{I.preventDefault(),h(y.key)},className:`px-2 py-0.5 rounded text-[11px] whitespace-nowrap transition-colors ${R?"bg-accent-blue/20 text-accent-blue font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children:y.label},y.key)})}),t.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:a?e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:16,className:"animate-spin"}),e.jsx("span",{children:k("chat.searchingFiles")})]}):e.jsx("span",{children:k(g&&f!==Ze?"chat.mentionEmptySessions":"chat.noMatchingFiles")})}):t.map((y,R)=>{const I=t[R-1],E=I&&I.kind==="session"?I.dir||"":null,F=y.kind==="session"?y.dir||"":null,G=!I||I.kind!==y.kind||F!==null&&E!==F,N=F!==null?`📁 ${F||k("chat.mentionTabUnknownDir")}`:k("chat.mentionFilesGroup");return e.jsxs("div",{children:[G&&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:N,children:N}),e.jsxs("button",{onClick:()=>i(y),onMouseEnter:()=>l(R),className:`w-full px-3 py-1.5 flex items-center gap-2 text-left text-xs transition-colors border-l-2 ${R===n?"bg-accent-blue/20 text-accent-blue border-accent-blue":"hover:bg-dark-hover text-dark-text border-transparent"}`,children:[y.kind==="session"?e.jsx(Yr,{size:12,className:"text-accent-blue shrink-0"}):y.isDir?e.jsx(yi,{size:12,className:"text-accent-yellow shrink-0"}):e.jsx(on,{size:12,className:"text-dark-muted shrink-0"}),e.jsx("span",{className:"truncate",children:y.label}),y.kind==="session"?e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[y.detail&&e.jsx("span",{className:"text-[10px] text-dark-muted truncate",children:y.detail}),y.updatedAt&&e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:co(uu(y.updatedAt),Date.now(),k)}),y.messageCount!==void 0&&e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:k("chat.mentionMsgCount",{count:y.messageCount})}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] whitespace-nowrap ${cu(y.status)}`,children:k(du(y.status))})]}):y.detail&&e.jsx("span",{className:"text-[10px] text-dark-muted truncate ml-auto",children:y.detail})]})]},y.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:[g&&b&&e.jsxs("button",{type:"button",onMouseDown:y=>y.preventDefault(),onClick:b,className:`px-1.5 py-0.5 rounded text-[10px] transition-colors ${p==="all"?"bg-accent-blue/20 text-accent-blue font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,title:k("chat.mentionScopeHint"),children:[k("chat.mentionScopeLabel"),k(p==="all"?"chat.mentionScopeAll":"chat.mentionScopeActive")]}),g&&S&&e.jsxs("button",{type:"button",onMouseDown:y=>y.preventDefault(),onClick:S,className:`px-1.5 py-0.5 rounded text-[10px] transition-colors ${lu[v]}`,title:k("chat.mentionDeliveryHint"),children:[k("chat.mentionDeliveryLabel"),k(ou[v])]}),e.jsx("span",{children:c>0?k("chat.selectedFilesCount",{n:c}):k("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:k("chat.finishMention")})]})]})}function mu({open:s,onClose:t,onSelect:n}){const{t:r}=se(),[a,i]=o.useState([]),[l,c]=o.useState(!1),[d,m]=o.useState("");o.useEffect(()=>{s&&(m(""),c(!0),ve.skills.list().then(h=>{const p=Array.isArray(h.data)?h.data:[];i(p.filter(b=>b.enabled!==!1))}).catch(()=>i([])).finally(()=>c(!1)))},[s]);const f=o.useMemo(()=>{const h=d.trim().toLowerCase();return h?a.filter(p=>[p.id,p.name,p.description,p.category,...p.tags||[]].join(" ").toLowerCase().includes(h)):a},[a,d]);return e.jsx(uo,{isOpen:s,onClose:t,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(ds,{size:14,className:"text-dark-muted shrink-0"}),e.jsx("input",{value:d,onChange:h=>m(h.target.value),placeholder:r("skills.pickPlaceholder"),autoFocus:!0,className:"flex-1 bg-transparent outline-none text-sm placeholder-dark-muted/60"}),l&&e.jsx(Ct,{size:13,className:"animate-spin text-dark-muted"})]}),l?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Ct,{size:20,className:"animate-spin text-accent-blue"})}):f.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:f.map(h=>e.jsxs("button",{onClick:()=>n(h),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:[h.icon||"⭐"," ",h.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:h.injection||"lazy"})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate font-mono",children:["$",h.id]}),h.description&&e.jsx("div",{className:"text-xs text-dark-muted line-clamp-2",children:h.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:h.category||"—"}),e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-accent-blue shrink-0",children:[e.jsx(ji,{size:11}),r("skills.pickUse")]})]})]},h.id))})]})})}function xu({isOpen:s,items:t,selectedIndex:n,query:r,isLoading:a,onSelect:i,onHover:l}){const{t:c}=se();return s?e.jsx("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 truncate",children:r?`$${r}`:c("chat.skillMenuTitle")}),e.jsx("span",{className:"opacity-70 shrink-0",children:c("chat.skillMenuHint")})]}),t.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:a?e.jsxs(e.Fragment,{children:[e.jsx(Re,{size:16,className:"animate-spin"}),e.jsx("span",{children:c("chat.skillMenuLoading")})]}):e.jsx("span",{children:c("chat.skillMenuEmpty")})}):t.map((d,m)=>e.jsxs("button",{onClick:()=>i(d),onMouseEnter:()=>l(m),className:`w-full px-3 py-1.5 flex items-center gap-2 text-left text-xs transition-colors border-l-2 ${m===n?"bg-accent-blue/20 text-accent-blue border-accent-blue":"hover:bg-dark-hover text-dark-text border-transparent"}`,children:[e.jsx("span",{className:"shrink-0","aria-hidden":"true",children:d.icon||e.jsx(dn,{size:12,className:"text-accent-blue"})}),e.jsx("span",{className:"truncate",children:d.name||d.id}),e.jsxs("span",{className:"text-[10px] font-mono text-dark-muted shrink-0",children:["$",d.id]}),d.description&&e.jsx("span",{className:"text-[10px] text-dark-muted truncate ml-auto",children:d.description})]},d.id))]})}):null}function fu(s){for(let t=s.length-1;t>=0;t--)if(s[t]==="$"){if(t>0&&/\w/.test(s.charAt(t-1)))continue;return t}return-1}function pu(s,t){const n=t.filter(r=>r.enabled!==!1);if(!s)return"prefix";for(const r of n)if(r.id.toLowerCase()===s)return"exact";for(const r of n)if(r.id.toLowerCase().startsWith(s))return"prefix";return null}function Dr(s,t,n){const r=s.slice(0,t),a=fu(r);if(a===-1)return{active:!1,query:"",start:-1};const i=r.slice(a+1);if(i.length>=200||!/^[\w.\-\\/\s]*$/.test(i))return{active:!1,query:"",start:-1};const l=(i.split(/[\s/\\]/)[0]??"").toLowerCase();return(n.length===0?"prefix":pu(l,n))!=="prefix"?{active:!1,query:"",start:-1}:{active:!0,query:i,start:a}}function gu(s,t){const n=t.trim().toLowerCase();if(!n)return 1;const r=s.id.toLowerCase(),a=(s.name||"").toLowerCase(),i=(s.description||"").toLowerCase(),l=(s.tags||[]).join(" ").toLowerCase();return r===n||a===n?100:r.startsWith(n)?90:a.startsWith(n)?80:r.includes(n)?60:a.includes(n)?55:l.includes(n)?40:i.includes(n)?30:0}function bu(s,t){const n=t.replace(/^\$/,"").trim().split(/\s+/)[0]??"";return s.filter(r=>r.enabled!==!1).map(r=>({skill:r,score:gu(r,n)})).filter(r=>r.score>0).sort((r,a)=>a.score-r.score||r.skill.id.localeCompare(a.skill.id)).map(r=>r.skill)}class et extends Error{constructor(n,r){super(r??n);Yt(this,"code");this.code=n,this.name="ScreenshotError"}}function ku(s){const t=document.createElement("canvas");t.width=s.videoWidth,t.height=s.videoHeight;const n=t.getContext("2d");if(!n)throw new et("failed","Canvas 2D context unavailable");return n.drawImage(s,0,0,t.width,t.height),new Promise((r,a)=>{t.toBlob(i=>i?r(i):a(new et("failed","canvas.toBlob returned null")),"image/png")})}async function vu(){var n;if(!((n=navigator.mediaDevices)!=null&&n.getDisplayMedia))throw new et("unsupported","Screen capture is not supported in this browser");const s=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1}).catch(r=>{const a=r instanceof DOMException?r.name:"";throw a==="NotAllowedError"||a==="AbortError"?new et("cancelled","User dismissed the screen picker"):new et("failed",r instanceof Error?r.message:String(r))}),t=s.getTracks();try{const r=document.createElement("video");r.srcObject=s,r.muted=!0,r.playsInline=!0,await r.play().catch(()=>{}),r.readyState<2&&await new Promise(d=>{const m=()=>d();r.addEventListener("loadeddata",m,{once:!0}),setTimeout(m,1e3)}),await new Promise(d=>requestAnimationFrame(()=>d()));const a=r.videoWidth,i=r.videoHeight;if(!a||!i)throw new et("failed","Captured video frame has no pixels");const l=await ku(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 t)r.stop()}}const ns=16e3;function Ks(){const s=["audio/webm;codecs=opus","audio/webm","audio/mp4"];if(typeof MediaRecorder>"u")return"";for(const t of s)if(MediaRecorder.isTypeSupported(t))return t;return""}async function yu(s){if(s.sampleRate===ns&&s.numberOfChannels===1)return s.getChannelData(0);const t=Math.max(1,Math.ceil(s.length*ns/s.sampleRate)),n=new OfflineAudioContext(1,t,ns),r=n.createBufferSource();return r.buffer=s,r.connect(n.destination),r.start(0),(await n.startRendering()).getChannelData(0)}function ju(s,t){const n=new ArrayBuffer(44+s.length*2),r=new DataView(n),a=(l,c)=>{for(let d=0;d<c.length;d++)r.setUint8(l+d,c.charCodeAt(d))};a(0,"RIFF"),r.setUint32(4,36+s.length*2,!0),a(8,"WAVE"),a(12,"fmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,t,!0),r.setUint32(28,t*2,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),a(36,"data"),r.setUint32(40,s.length*2,!0);let i=44;for(let l=0;l<s.length;l++){const c=Math.max(-1,Math.min(1,s[l]??0));r.setInt16(i,c<0?c*32768:c*32767,!0),i+=2}return n}function wu(s){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const a=String(r.result||""),i=a.indexOf(",");t(i>=0?a.slice(i+1):a)},r.onerror=()=>n(r.error),r.readAsDataURL(s)})}function Nu(s){const[t,n]=o.useState("idle"),[r,a]=o.useState(0),i=o.useRef(null),l=o.useRef(null),c=o.useRef([]),d=o.useRef(null),m=o.useRef(0),f=o.useCallback(()=>{var S;(S=l.current)==null||S.getTracks().forEach(k=>k.stop()),l.current=null},[]),h=o.useCallback(()=>{d.current&&(clearInterval(d.current),d.current=null)},[]);o.useEffect(()=>()=>{h(),i.current&&i.current.state!=="inactive"&&i.current.stop(),f()},[h,f]);const p=o.useCallback(async()=>{if(t!=="idle")return;if(typeof MediaRecorder>"u")throw new Error("当前浏览器不支持语音输入(需要 MediaRecorder)。请使用 Chrome/Edge/Firefox 或桌面版。");let S;try{S=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}})}catch(g){throw g instanceof DOMException&&g.name==="NotAllowedError"?new Error("麦克风权限被拒绝。请在浏览器地址栏允许麦克风权限后重试。"):new Error("无法访问麦克风:"+(g instanceof Error?g.message:String(g)))}l.current=S,c.current=[];const k=new MediaRecorder(S,Ks()?{mimeType:Ks()}:void 0);k.ondataavailable=g=>{g.data&&g.data.size>0&&c.current.push(g.data)},i.current=k,k.start(),m.current=Date.now(),a(0),n("recording"),d.current=setInterval(()=>a(Date.now()-m.current),100)},[t]),b=o.useCallback(async()=>{var g;const S=i.current;if(!S||S.state==="inactive")throw new Error("当前没有进行中的录音。");const k=new Promise(y=>{S.onstop=()=>y()});S.stop(),await k,h(),f(),i.current=null,n("transcribing");try{const y=new Blob(c.current,{type:Ks()||"audio/webm"});c.current=[];const R=await y.arrayBuffer(),I=new AudioContext;let E;try{E=await I.decodeAudioData(R)}finally{I.close()}if(E.duration<.25)return n("idle"),"";const G=await yu(E),N=ju(G,ns),P=await wu(new Blob([N],{type:"audio/wav"})),B=await ve.stt.transcribe(s,P,"wav");if(!B.success)throw new Error(B.error||"语音转写失败");return((g=B.data)==null?void 0:g.text)??""}finally{n("idle")}},[s,h,f]),v=o.useCallback(()=>{const S=i.current;S&&S.state!=="inactive"&&S.stop(),i.current=null,c.current=[],h(),f(),n("idle")},[h,f]);return{state:t,elapsedMs:r,start:p,stop:b,cancel:v}}const Su=({isOpen:s,commands:t,selectedIndex:n,filter:r,onSelect:a,onHover:i,containerRef:l})=>{const{t:c}=se();return!s||t.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")})]}),t.map((d,m)=>e.jsxs("button",{"data-index":m,onClick:()=>a(d),onMouseEnter:()=>i(m),className:`w-full px-3 py-2 flex items-start gap-3 text-left transition-colors border-l-2 ${m===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})]}),m===n&&e.jsx(wi,{size:14,className:"text-dark-muted shrink-0 mt-0.5","aria-hidden":"true"})]},d.id))]})},ya=["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"],Mu=new RegExp(`(?:\\.(${ya.join("|")})|dockerfile|makefile)$`,"i"),ja=["png","jpg","jpeg","webp","gif","bmp","svg"],Cu=Object.freeze([]),Eu=new RegExp(`\\.(${ja.join("|")})$`,"i"),Tu=10*1024*1024,Au=ya.map(s=>`.${s}`).join(",")+",.Dockerfile,.Makefile,"+ja.map(s=>`.${s}`).join(","),Iu=".deepseekcode/attachments",Ru=50*1024*1024,Zt=10,es="chat-col",_r=72,zr=.7,Du=/["<>]/g;function _u(s){return`<image name="${(s||"image").replace(Du,"")}" />`}const zu=s=>/\.xlsx?$/i.test(s)?Vs:/\.(csv|docx|txt|md|mdx|rst|adoc|json|jsonc|yaml|yml|toml|xml|html|css|scss|less|env|gitignore|gitattributes|editorconfig)$/i.test(s)?rs:/\.(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(s)?Ti:on,Us=3e3,$r=5,jt=50,$u=5e3,Ou={enqueue:"chat.mentionDeliveryEnqueue",summarize:"chat.mentionDeliverySummarize","next-step":"chat.mentionDeliveryNextStep",direct:"chat.mentionDeliveryDirect"},Pu={enqueue:"text-dark-muted hover:bg-dark-hover hover:text-dark-text",summarize:"text-dark-muted hover:bg-dark-hover hover:text-dark-text","next-step":"bg-accent-blue/10 text-accent-blue",direct:"bg-accent-blue/10 text-accent-blue"};function Lu(s,t){const n=s.slice(0,t),r=n.lastIndexOf("@");if(r===-1)return{active:!1,query:"",start:-1};const a=n.slice(r+1);return/^[\p{L}\p{N}_\-./]*$/u.test(a)?{active:!0,query:a,start:r}:{active:!1,query:"",start:-1}}function Fu(s,t){const n=s.lastIndexOf(`
30
+ `,t-1)+1,r=s.slice(n,t);return r.startsWith("/")?/\s/.test(r)?{active:!1,query:""}:{active:!0,query:r.slice(1)}:{active:!1,query:""}}const Bu=o.memo(function({sessionId:t,onSend:n,onRunShell:r,onStop:a,onPause:i,onResume:l,slashOptions:c,workspaceDir:d,onWorkspaceSelect:m,focusRequest:f}){const{t:h}=se(),p=pe(u=>{var x;return((x=u.sessionInputs)==null?void 0:x[t])??""}),b=pe(u=>u.setSessionInput),v=pe(u=>{var x;return((x=u.generatingSessions)==null?void 0:x.includes(t))??!1}),S=pe(u=>{var x;return((x=u.pausedSessions)==null?void 0:x.includes(t))??!1}),k=pe(u=>{var x;return(x=u.pendingBySession)==null?void 0:x[t]})??Cu,g=k.length,y=o.useRef(null),[R,I]=o.useState(null),E=o.useRef(null),[F,G]=o.useState(!1),N=o.useRef(null),P=o.useRef(!1),B=o.useRef(0),[M,z]=o.useState([]),[V,Q]=o.useState(!1),[J,re]=o.useState(!1),[j,L]=o.useState(!1),[H,W]=o.useState(!1),[ie,T]=o.useState(""),[ee,le]=o.useState(0),[w,K]=o.useState([]),[$,ne]=o.useState(!1),he=o.useRef(-1),te=o.useRef([]);te.current=w;const me=o.useRef(null),de=o.useCallback(()=>{const u=pe.getState().clearPending(t);u>0&&ce.info(h("toast.queueRevoked",{count:u}))},[t,h]),D=o.useCallback(u=>{const x=pe.getState();if(x.promotePending(t,u),!x.isGenerating(t)&&!x.isPaused(t)){ho(t);return}ce.info(h("toast.queuePromoted"))},[t,h]),ae=o.useCallback(u=>{pe.getState().removePending(t,u)&&ce.info(h("toast.queueRemoved"))},[t,h]),Y=o.useCallback(u=>{b(t,u)},[t,b]),A=o.useCallback(u=>{var ue;const x=pe.getState().removePending(t,u);if(!x)return;const C=[],_=[];let O=(((ue=x.display)==null?void 0:ue.content)??x.content).replace(/<attachment path="([^"]*)"\s*\/>/g,(Z,xe)=>(C.push(xe),"")).replace(/<image name="([^"]*)"\s*\/>/g,(Z,xe)=>(_.push(xe),"")).trim();if(x.display)for(const Z of x.display.pastes){const xe=na(Z.content),ke=xn(Z.content),Se=ke>0?`[Pasted text #${xe} +${ke} lines]`:`[Pasted text #${xe}]`;O=O.replace(new RegExp(`\\[Pasted text #${Z.id}(?:\\s*\\+\\d+ lines?)?\\]`,"g"),Se)}for(const Z of x.files??[])Ie.current.add(Z);const q=C.map((Z,xe)=>({id:`queued-att-${Date.now()}-${xe}`,name:Z.split("/").pop()||Z,size:0,uploading:!1,path:Z}));(x.images??[]).forEach((Z,xe)=>{q.push({id:`queued-img-${Date.now()}-${xe}`,name:_[xe]||`image-${xe+1}.png`,size:Math.max(1,Math.round((Z.length-Z.indexOf(",")-1)*3/4)),uploading:!1,imageDataUri:Z})}),q.length>0&&z(Z=>[...Z,...q].slice(-Zt));const X=pe.getState().getSessionInput(t);Y(X.trim()?`${X.trimEnd()}
31
+
32
+ ${O}`:O),requestAnimationFrame(()=>{var Z;return(Z=y.current)==null?void 0:Z.focus()})},[t,Y]),oe=o.useCallback(u=>u.replace(/<attachment path="[^"]*"\s*\/>/g,"").replace(/<image name="[^"]*"\s*\/>/g,"").trim(),[]),[U,ye]=o.useState(No),[be,We]=o.useState(!1),Ae=o.useRef(null),Rt=o.useCallback(u=>{ye(u),So(u),We(!1)},[]);o.useEffect(()=>{if(!be)return;const u=C=>{Ae.current&&!Ae.current.contains(C.target)&&We(!1)},x=C=>{C.key==="Escape"&&We(!1)};return document.addEventListener("mousedown",u),document.addEventListener("keydown",x),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",x)}},[be]);const je=Nu(U),Dt=o.useRef(null),yn=o.useCallback(async()=>{var u;try{if(!Dt.current){const _=await ve.stt.status();_.success&&_.data&&(Dt.current=_.data)}const x=Dt.current;if(!x)return!0;if(x.service!=="ok"&&x.service!=="stopped")return ce.warning(h("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1;const C=(u=x.backends)==null?void 0:u[U];return C&&!C.installed?(ce.warning(h("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1):!0}catch{return!0}},[h,U]);o.useEffect(()=>{const u=()=>{Dt.current=null};return window.addEventListener("stt-backends-changed",u),()=>window.removeEventListener("stt-backends-changed",u)},[]),o.useEffect(()=>{const u=x=>{var _;const C=Eo((_=x.detail)==null?void 0:_.lang);ye(C)};return window.addEventListener("stt-lang-changed",u),()=>window.removeEventListener("stt-lang-changed",u)},[]);const jn=o.useCallback(u=>{const x=y.current,C=(x==null?void 0:x.selectionStart)??p.length,_=p.slice(0,C)+u+p.slice(C);Y(_),requestAnimationFrame(()=>{x==null||x.focus();const O=C+u.length;x&&(x.selectionStart=x.selectionEnd=O)})},[p,Y]);o.useEffect(()=>{if(!f)return;const u=y.current;if(!u)return;u.focus();const x=u.value.length;u.selectionStart=x,u.selectionEnd=x},[f]);const Ca=o.useCallback(async()=>{if(v){ce.info(h("stt.generatingTitle"));return}if(je.state==="recording"){try{const x=await je.stop();x?jn(x):ce.info(h("stt.noSpeech"))}catch(x){ce.error(x instanceof Error?x.message:String(x))}return}if(!(je.state!=="idle"||!await yn()))try{await je.start()}catch(x){ce.error(x instanceof Error?x.message:String(x))}},[je,jn,yn,h,v]),Ea=mo(c),{isOpen:Oe,filter:Ta,filteredCommands:_t,selectedIndex:xs,setSelectedIndex:fs,selectNext:wn,selectPrev:Nn,executeCommand:zt,openMenu:Sn,closeMenu:Me,setFilter:Mn,allCommands:Cn,containerRef:Aa}=Ea,[Ce,_e]=o.useState(!1),[$t,st]=o.useState(""),[ps,En]=o.useState([]),[gs,Ge]=o.useState(0),[Ia,Tn]=o.useState(!1),[Ra,Ve]=o.useState(0),nt=o.useRef(-1),[An,Da]=o.useState("active"),Ot=o.useRef("active"),[Pt,_a]=o.useState("summarize"),Lt=o.useRef("summarize");Lt.current=Pt;const[In,za]=o.useState([]),Ft=o.useCallback(()=>{za(Array.from(Pe.current.values()))},[]);Ot.current=An;const Ie=o.useRef(new Set),Pe=o.useRef(new Map),xt=o.useRef(null),Bt=o.useRef(null),Ht=o.useRef([]),He=o.useRef(!1);o.useEffect(()=>{const u=x=>{const C=pe.getState().getSessionInput(t),_=`@${x} `,O=C.trim()?`${C.trimEnd()} ${_}`:_;Ie.current.add(x),b(t,O),Ve(Ie.current.size+Pe.current.size),requestAnimationFrame(()=>{var q;return(q=y.current)==null?void 0:q.focus()})};return go(u),()=>xo(u)},[t,b]);const $a=o.useCallback(u=>{const x=pe.getState().getSessionInput(t),C=x.trim()?`${x.trimEnd()}
33
+
34
+ ${u}`:u;b(t,C),requestAnimationFrame(()=>{var _;return(_=y.current)==null?void 0:_.focus()})},[t,b]),Rn=o.useRef([]),[Dn,qt]=o.useState(Ze),ft=o.useRef([]),rt=o.useRef([]),bs=o.useRef(0),_n=o.useRef("");_n.current=$t;const Je=o.useCallback((u,x)=>{const C=u.map(X=>({kind:"file",key:X.path,label:X.name,detail:X.path,isDir:X.type==="directory"})),_=ft.current,O=x.toLowerCase(),q=(O?_.filter(X=>X.label.toLowerCase().includes(O)||X.key.toLowerCase().includes(O)):_).slice(0,jt);return[...C,...q]},[]),Kt=o.useCallback(async()=>{const u=Date.now();if(rt.current.length>0&&u-bs.current<$u)return rt.current;try{const x=await ve.sessions.list(),C=x.success&&x.data?x.data:[];(C.length>0||rt.current.length===0)&&(rt.current=C),bs.current=Date.now()}catch{}return rt.current},[]),ks=o.useCallback(async()=>{const u=await Kt();return ft.current=Rr(u,t,Ot.current),ft.current},[Kt,t]),Ye=o.useCallback(u=>{Rn.current=u,En(u)},[]),vs=o.useCallback(()=>{const u=Ot.current==="active"?"all":"active";Ot.current=u,Da(u),(async()=>{const x=await Kt();ft.current=Rr(x,t,u);const C=_n.current.toLowerCase(),_=Ht.current.filter(O=>!C||O.path.toLowerCase().includes(C)).slice(0,jt);Ye(Je(_,C))})()},[Kt,t,Ye,Je]),Ut=o.useCallback(()=>{let u=Zd(Lt.current);(u==="direct"||u==="summarize")&&Ie.current.size>0&&(u="enqueue"),Lt.current=u,_a(u)},[]),Xe=o.useMemo(()=>tu({files:h("chat.mentionTabFiles"),sessions:h("chat.mentionTabSessions")}),[h]),ys=Xe.some(u=>u.key===Dn)?Dn:Ze,at=o.useMemo(()=>su(ps,ys),[ps,ys]);o.useEffect(()=>{Ie.current=new Set,Pe.current=new Map,Ft(),He.current=!1,qt(Ze),ft.current=[],rt.current=[],bs.current=0,_e(!1),st(""),En([]),Rn.current=[],Ve(0),Me()},[t,Me,Ft]);const zn=o.useDeferredValue(p),$n=dt(u=>u.estimateTokens),js=o.useMemo(()=>$n(zn),[zn,$n]),On=o.useCallback(()=>{const u=y.current;if(u){if(R!=null){u.style.maxHeight=`${R}px`,u.style.height=`${R}px`;return}u.style.maxHeight="",u.style.height="auto",u.style.height=Math.min(u.scrollHeight,200)+"px"}},[R]);o.useEffect(()=>{On()},[p,M.length,On]),o.useEffect(()=>()=>{document.body.style.userSelect=""},[]);const Oa=o.useCallback(u=>{const x=y.current;!x||u.button!==0||(u.preventDefault(),E.current={startY:u.clientY,startHeight:x.getBoundingClientRect().height,current:0},u.currentTarget.setPointerCapture(u.pointerId),document.body.style.userSelect="none",G(!0))},[]),Pa=o.useCallback(u=>{const x=E.current,C=y.current;if(!x||!C)return;x.movedY=u.clientY-x.startY;const _=Math.max(_r,Math.min(Math.round(window.innerHeight*zr),x.startHeight-(u.clientY-x.startY)));x.current=_,C.style.maxHeight=`${_}px`,C.style.height=`${_}px`},[]),Pn=o.useCallback(u=>{const x=E.current;if(E.current=null,document.body.style.userSelect="",G(!1),!!x){try{u.currentTarget.releasePointerCapture(u.pointerId)}catch{}x.current>0&&Math.abs(x.movedY??0)>3&&I(x.current)}},[]),La=o.useCallback(()=>I(null),[]),Ln=o.useCallback(u=>{const x=y.current;if(!x)return;const C=R??x.getBoundingClientRect().height,_=Math.max(_r,Math.min(Math.round(window.innerHeight*zr),C+u));I(_)},[R]),ws=o.useCallback(()=>{if(xt.current)return Promise.resolve(xt.current);if(Bt.current)return Bt.current;Tn(!0);const u=(async()=>{try{const x=await ve.files.list(),C=x.success&&x.data?x.data[0]:void 0;if(!C)return xt.current=[],[];const _=[],O=new Set,q=async(X,ue)=>{if(ue>$r||_.length>=Us)return;const Z=[];for(const ke of X||[]){if(_.length>=Us)return;const Se=ke.path.replace(/\\/g,"/");O.has(Se)||(O.add(Se),ke.type==="file"?_.push({...ke,path:Se}):ke.children&&ke.children.length>0?await q(ke.children,ue+1):ue<$r&&Z.push(ke))}if(Z.length===0)return;const xe=await Promise.all(Z.map(async ke=>{var Se;try{const bt=await ve.files.list(ke.path.replace(/\\/g,"/"));return bt.success&&bt.data?((Se=bt.data[0])==null?void 0:Se.children)||[]:[]}catch{return[]}}));for(const ke of xe){if(_.length>=Us)return;await q(ke,ue+1)}};return await q(C.children,1),xt.current=_,_}catch{return xt.current=[],[]}finally{Bt.current=null,Tn(!1)}})();return Bt.current=u,u},[]),Fn=o.useCallback(async(u,x)=>{if(He.current){const X=nt.current;if(X<0||x<X){He.current=!1,_e(!1);return}const ue=u.slice(X,x);if(/\s/.test(ue)){He.current=!1,_e(!1);return}nt.current=X,st(ue),_e(!0),Ge(0);const[Z]=await Promise.all([ws(),ks()]);Ht.current=Z;const xe=ue.toLowerCase(),ke=Z.filter(Se=>!xe||Se.path.toLowerCase().includes(xe)).slice(0,jt);Ye(Je(ke,xe));return}const C=Lu(u,x);if(!C.active){Ce&&_e(!1);return}nt.current=C.start,st(C.query),_e(!0),Ge(0);const[_]=await Promise.all([ws(),ks()]);Ht.current=_;const O=C.query.toLowerCase(),q=_.filter(X=>!O||X.path.toLowerCase().includes(O)).slice(0,jt);Ye(Je(q,O))},[Ce,ws,ks,Je,Ye]),Bn=o.useCallback(async()=>{if(te.current.length>0)return te.current;if(me.current)return me.current;ne(!0);const u=ve.skills.list().then(x=>{const C=Array.isArray(x.data)?x.data:[];return K(C),C}).catch(()=>[]).finally(()=>{me.current=null,ne(!1)});return me.current=u,u},[]),Qe=o.useMemo(()=>bu(w,ie),[w,ie]),Hn=o.useCallback((u,x)=>{const C=Dr(u,x,te.current);if(!C.active){H&&(W(!1),T(""));return}he.current=C.start,T(C.query),le(0),W(!0),te.current.length===0&&Bn()},[H,Bn]);o.useEffect(()=>{if(!H||w.length===0)return;const u=y.current;if(!u)return;const x=Dr(u.value,u.selectionStart??u.value.length,w);if(!x.active){W(!1),T("");return}he.current=x.start,T(x.query)},[w,H]);const Fa=o.useCallback(u=>{const x=u.target.value,C=u.target.selectionStart??x.length;Y(x),Fn(x,C),Hn(x,C);const _=Fu(x,C);_.active?(Oe||Sn(),Mn(_.query),fs(0)):Oe&&Me()},[Y,Fn,Hn,Oe,Sn,Mn,fs,Me]),Ns=o.useCallback(u=>{const x=y.current,C=p,_=nt.current>=0?nt.current:(x==null?void 0:x.selectionStart)??C.length,O=Math.min(C.length,_+1+$t.length);let q,X;if(u.kind==="session"){const Z=u.label||u.key;q=/\s/.test(Z)?u.key:Z,Pe.current.set(u.key,Z),Ft(),X=`@${q} `}else q=u.key,Ie.current.add(q),X=`@${q} `;const ue=C.slice(0,_)+X+C.slice(O);Y(ue),_e(!0),st(""),Ye(Je(Ht.current.slice(0,jt),"")),Ge(0),Ve(Ie.current.size+Pe.current.size),nt.current=_+X.length,He.current=!0,requestAnimationFrame(()=>{x==null||x.focus(),x&&(x.selectionStart=x.selectionEnd=_+X.length)})},[p,$t,Y,Je,Ye]),pt=o.useCallback(()=>{He.current=!1,_e(!1),st(""),Ve(0),qt(Ze)},[]),Ss=o.useCallback(u=>{if(!u.args){const q=zt(u,"");q!=null&&q.message&&(q.success?ce.success(q.message):ce.error(q.message)),Y(""),I(null);return}const x=y.current,C=(x==null?void 0:x.selectionStart)??p.length,_=p.lastIndexOf(`
35
+ `,C-1)+1,O=p.slice(0,_)+`/${u.name} `+p.slice(C);Y(O),Me(),requestAnimationFrame(()=>{x==null||x.focus();const q=_+u.name.length+2;x&&(x.selectionStart=x.selectionEnd=q)})},[p,Y,zt,Me]),Ms=o.useCallback(u=>{const x=y.current,C=he.current>=0?he.current:(x==null?void 0:x.selectionStart)??p.length,_=Math.min(p.length,C+1+ie.length),O=`$${u.id} `,q=p.slice(0,C)+O+p.slice(_);Y(q),W(!1),T(""),he.current=-1,requestAnimationFrame(()=>{x==null||x.focus();const X=C+O.length;x&&(x.selectionStart=x.selectionEnd=X)})},[p,ie,Y]),Wt=o.useCallback(()=>{W(!1),T(""),he.current=-1},[]),Ba=o.useCallback(u=>{const x=y.current,C=(x==null?void 0:x.selectionStart)??p.length,_=`$${u.id} `,O=p.slice(0,C)+_+p.slice(C);Y(O),L(!1),He.current=!1,_e(!1),st(""),W(!1),T(""),requestAnimationFrame(()=>{x==null||x.focus();const q=C+_.length;x&&(x.selectionStart=x.selectionEnd=q)})},[p,Y]),qn=2048,Kn=o.useCallback(u=>new Promise((x,C)=>{const _=()=>{const O=new FileReader;O.onload=()=>x(String(O.result??"")),O.onerror=()=>C(new Error("Failed to read image")),O.readAsDataURL(u)};(async()=>{let O=null;try{O=await createImageBitmap(u)}catch{_();return}try{const q=Math.max(O.width,O.height);if(q<=qn){O.close(),_();return}const X=qn/q,ue=document.createElement("canvas");ue.width=Math.max(1,Math.round(O.width*X)),ue.height=Math.max(1,Math.round(O.height*X));const Z=ue.getContext("2d");if(!Z){O.close(),_();return}Z.drawImage(O,0,0,ue.width,ue.height),O.close();const xe=u.type==="image/jpeg"?"image/jpeg":"image/png";x(ue.toDataURL(xe,xe==="image/jpeg"?.9:void 0))}catch{O==null||O.close(),_()}})()}),[]),qe=o.useCallback(u=>{const x=Array.from(u);z(C=>{const _=Zt-C.length,O=C.slice();for(const q of x.slice(0,_)){const X=Eu.test(q.name);if(!X&&!Mu.test(q.name)){ce.warning(h("fileJob.unsupportedType",{name:q.name}));continue}if(q.size>(X?Tu:Ru)){ce.error(h("fileJob.fileTooLarge",{name:q.name}));continue}if(O.some(Z=>Z.name===q.name&&Z.size===q.size)){ce.warning(h("fileJob.duplicateFile",{name:q.name}));continue}const ue={id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,file:q,name:q.name,size:q.size,uploading:!1};X&&Kn(q).then(Z=>{z(xe=>xe.map(ke=>ke.id===ue.id?{...ke,imageDataUri:Z}:ke))}).catch(()=>{z(Z=>Z.filter(xe=>xe.id!==ue.id)),ce.error(h("fileJob.uploadFailed",{name:q.name}))}),O.push(ue)}return O.length>=Zt&&ce.warning(h("fileJob.maxAttachments",{n:Zt})),O})},[h,Kn]),Ha=o.useCallback(u=>{u.target.files&&u.target.files.length>0&&(qe(u.target.files),u.target.value="")},[qe]),qa=o.useCallback(()=>{var u;(u=N.current)==null||u.click()},[]),Gt=o.useCallback(async()=>{if(!(J||v)){re(!0);try{const u=await vu();qe([u])}catch(u){u instanceof et&&u.code==="cancelled"||ce.error(h("fileJob.screenshotFailed"))}finally{re(!1)}}},[qe,h,J,v]),Un=o.useRef(Gt);o.useEffect(()=>{Un.current=Gt},[Gt]),o.useEffect(()=>{const u=x=>{!(x.ctrlKey||x.metaKey)||!x.shiftKey||x.key!=="s"&&x.key!=="S"||(x.preventDefault(),Un.current())};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[]);const Ka=o.useCallback(u=>{z(x=>x.filter(C=>C.id!==u))},[]),Ua=o.useCallback(u=>{u.preventDefault(),Q(!0)},[]),Wa=o.useCallback(u=>{u.preventDefault(),Q(!1)},[]),Ga=o.useCallback(u=>{u.preventDefault(),Q(!1),u.dataTransfer.files&&u.dataTransfer.files.length>0&&qe(u.dataTransfer.files)},[qe]),Wn=o.useCallback(async()=>{var x;if(M.length===0)return"";const u=[];for(const C of M){if(C.imageDataUri)continue;if(C.path){u.push(`<attachment path="${C.path}" />`);continue}if(!C.file)continue;z(q=>q.map(X=>X.id===C.id?{...X,uploading:!0,error:void 0}:X));const _=`${Iu}/${C.name}`,O=await ve.files.upload(C.file,_);if(O.success&&((x=O.data)!=null&&x.path)){const q=O.data.path.replace(/\\/g,"/");z(X=>X.map(ue=>ue.id===C.id?{...ue,uploading:!1,path:q}:ue)),u.push(`<attachment path="${q}" />`)}else z(q=>q.map(X=>X.id===C.id?{...X,uploading:!1,error:O.error||h("fileJob.uploadFailed")}:X)),ce.error(`${C.name}: ${O.error||h("fileJob.uploadFailed")}`)}return u.length>0?`${u.join(`
36
+ `)}
37
+
38
+ `:""},[M,h]),Va=o.useCallback(u=>{const x=u.clipboardData.getData("text/plain");if(u.clipboardData.files&&u.clipboardData.files.length>0){u.preventDefault(),qe(u.clipboardData.files);return}if(!x||!_o(x))return;u.preventDefault();const{label:C}=zo(x),_=y.current;if(!_)return;const O=_.selectionStart,q=_.selectionEnd,X=_.value,ue=X.slice(0,O)+C+X.slice(q);Y(ue),requestAnimationFrame(()=>{_.selectionStart=_.selectionEnd=O+C.length})},[Y,qe]),gt=o.useCallback(async()=>{const u=Oo(p),x=u.map(fe=>({id:fe,content:Ro(fe)??""})).filter(fe=>fe.content!==""),C=$o(p);Po(u),He.current=!1,_e(!1),Me();const _=C.trim(),O=M.length>0;if(!_&&!O)return;const q=C.trim();if(q.startsWith("/")&&!O){const fe=fo(q);if(fe){const ot=Cn.find(Ke=>Ke.name===fe.command);if(ot){const Ke=zt(ot,fe.args);Ke!=null&&Ke.message&&(Ke.success?ce.success(Ke.message):ce.error(Ke.message)),Y(""),I(null),z([]),Ie.current=new Set,Pe.current=new Map,Ft(),Ve(0);return}ce.error(h("slashCommands.unknownCommand",{cmd:`/${fe.command}`}));return}}if(q.startsWith("!")&&!O){const fe=q.slice(1).trim();if(!fe)return;r==null||r(fe),Y(""),I(null),z([]),Ie.current=new Set,Pe.current=new Map,Ve(0);return}const X=Array.from(Ie.current).filter(fe=>C.includes(`@${fe}`)),ue=Array.from(Pe.current.entries()).map(([fe,ot])=>({id:fe,title:ot})).filter(fe=>C.includes(`@${fe.title}`)||C.includes(`@${fe.id}`));let Z="";if(O){if(M.some(fe=>fe.uploading)){ce.warning(h("fileJob.stillUploading"));return}Z=await Wn()}const xe=M.filter(fe=>fe.imageDataUri),ke=xe.map(fe=>fe.imageDataUri);if(xe.length>0){const fe=xe.map(ot=>_u(ot.name)).join(`
39
+ `);Z=Z?`${Z}${fe}
40
+
41
+ `:`${fe}
42
+
43
+ `}const Se=(Z+C).trim();if(!Se&&!O)return;const bt=x.length>0?{content:`${Z}${p}`,pastes:x}:void 0;n(Se||Z.trim(),X.length>0?X:void 0,ke.length>0?ke:void 0,ue.length>0?ue:void 0,ue.length>0?Lt.current:void 0,bt),Y(""),I(null),z([]),Ie.current=new Set,Pe.current=new Map,Ve(0),W(!1),T("")},[p,M,n,r,Y,Wn,h,Me,Cn,zt]),Ja=o.useCallback(u=>{if(!u.nativeEvent.isComposing){if((u.key==="Backspace"||u.key==="Delete")&&!u.ctrlKey&&!u.metaKey&&!u.altKey&&!u.shiftKey){const x=y.current;if(x&&x.selectionStart===x.selectionEnd){const C=x.selectionStart,_=x.value;if(u.key==="Backspace"&&C>0){const O=Lo(_.slice(0,C));if(O){u.preventDefault(),Y(_.slice(0,C-O.length)+_.slice(C)),tr(O),requestAnimationFrame(()=>{x.focus();const q=C-O.length;x.selectionStart=x.selectionEnd=q});return}}else if(u.key==="Delete"&&C<_.length){const O=Fo(_.slice(C));if(O){u.preventDefault(),Y(_.slice(0,C)+_.slice(C+O.length)),tr(O),requestAnimationFrame(()=>{x.focus(),x.selectionStart=x.selectionEnd=C});return}}}}if(Ce&&Xe.length>1&&u.key==="Tab"){u.preventDefault();const x=Xe.map(C=>C.key);qt(C=>nu(x,C,!u.shiftKey)),Ge(0);return}if(Ce&&Xe.length>1&&u.key==="S"&&!u.ctrlKey&&!u.metaKey&&!u.altKey){u.preventDefault(),vs();return}if(Ce&&Xe.length>1&&u.key==="M"&&!u.ctrlKey&&!u.metaKey&&!u.altKey){u.preventDefault(),Ut();return}if(Ce&&at.length>0){if(u.key==="ArrowDown"){u.preventDefault(),Ge(x=>(x+1)%at.length);return}if(u.key==="ArrowUp"){u.preventDefault(),Ge(x=>(x-1+at.length)%at.length);return}if(u.key==="Enter"&&!u.shiftKey&&!u.ctrlKey&&!u.metaKey){const x=at[gs];x&&(u.preventDefault(),Ns(x));return}if(u.key==="Escape"){u.preventDefault(),pt();return}}else if(Ce&&u.key==="Escape"){u.preventDefault(),pt();return}if(H&&Qe.length>0){if(u.key==="ArrowDown"){u.preventDefault(),le(x=>(x+1)%Qe.length);return}if(u.key==="ArrowUp"){u.preventDefault(),le(x=>(x-1+Qe.length)%Qe.length);return}if(u.key==="Enter"&&!u.shiftKey&&!u.ctrlKey&&!u.metaKey){const x=Qe[ee];x&&(u.preventDefault(),Ms(x));return}if(u.key==="Escape"){u.preventDefault(),Wt();return}}else if(H&&u.key==="Escape"){u.preventDefault(),Wt();return}if(Oe&&_t.length>0){if(u.key==="ArrowDown"){u.preventDefault(),wn();return}if(u.key==="ArrowUp"){u.preventDefault(),Nn();return}if(u.key==="Enter"&&!u.shiftKey&&!u.ctrlKey&&!u.metaKey){const x=_t[xs];x&&(u.preventDefault(),Ss(x));return}if(u.key==="Escape"){u.preventDefault(),Me();return}}else if(Oe&&u.key==="Escape"){u.preventDefault(),Me();return}if(u.key==="Escape"&&v){u.preventDefault();const x=Date.now(),C=po(g,S,B.current,x);B.current=x,C==="revokeQueue"?(de(),B.current=0):C==="stop"?a():i();return}if(u.key==="Enter"&&(u.ctrlKey||u.metaKey)){u.preventDefault(),gt();return}u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),gt())}},[v,S,g,de,gt,i,l,a,Ce,ps,gs,Ns,pt,Xe,vs,Ut,H,Qe,ee,Ms,Wt,Oe,_t,xs,wn,Nn,Ss,Me,Y]),Ya=o.useCallback(()=>{P.current=!0},[]),Xa=o.useCallback(()=>{P.current=!1},[]),[Vt,Qa]=o.useState(()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(max-width: 767px)").matches);o.useEffect(()=>{if(typeof window.matchMedia!="function")return;const u=window.matchMedia("(max-width: 767px)"),x=()=>{Qa(u.matches),u.matches||Jt(!1)};return u.addEventListener("change",x),()=>u.removeEventListener("change",x)},[]);const[Za,Jt]=o.useState(!1);o.useEffect(()=>{Vt&&v&&Jt(!0)},[Vt,v]);const it=Za&&Vt,Gn=js>8e3,Cs=p.trim().length>0||M.length>0,Es=/mac/i.test(navigator.platform||"")?"⌘":"Ctrl";return e.jsxs("div",{className:"chat-composer-shell shrink-0 pb-3 pt-2 max-md:order-4 max-md:mt-auto",onDragOver:Ua,onDragLeave:Wa,onDrop:Ga,children:[k.length>0&&e.jsxs("div",{className:`${es} mb-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5 text-xs text-dark-muted`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{"aria-hidden":"true",children:"⏳"}),e.jsx("span",{className:"font-medium text-dark-text",children:h("chat.queuedCount",{count:k.length})}),e.jsx("span",{className:"min-w-0 flex-1"}),e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted/60",children:h("chat.queuedEscHint")}),e.jsx("button",{onClick:de,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:h("chat.queuedRevoke"),"aria-label":h("chat.queuedRevoke"),children:e.jsx(De,{size:12,"aria-hidden":"true"})})]}),e.jsx("ul",{className:"mt-1 max-h-40 space-y-0.5 overflow-y-auto",children:k.map((u,x)=>e.jsxs("li",{className:"group flex items-center gap-2 rounded px-1 py-0.5 transition-colors hover:bg-dark-hover/60",children:[e.jsx("span",{className:"w-4 shrink-0 text-center text-[10px] tabular-nums text-dark-muted/60",children:x+1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:oe(u.content),children:oe(u.content)||h("chat.queuedEmptyPreview")}),e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100",children:[e.jsx("button",{onClick:()=>D(u.id),className:"flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:h("chat.queuedSendNow"),"aria-label":h("chat.queuedSendNow"),children:e.jsx(Ni,{size:12,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>A(u.id),className:"flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-blue",title:h("chat.queuedEdit"),"aria-label":h("chat.queuedEdit"),children:e.jsx(Wr,{size:12,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>ae(u.id),className:"flex h-5 w-5 items-center justify-center rounded text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:h("chat.queuedDelete"),"aria-label":h("chat.queuedDelete"),children:e.jsx(Jr,{size:12,"aria-hidden":"true"})})]})]},u.id))})]}),M.length>0&&e.jsx("div",{className:`${es} mb-2 flex flex-wrap gap-1.5`,children:M.map(u=>{const x=zu(u.name),C=u.imageDataUri,_=e.jsxs(e.Fragment,{children:[C?e.jsx(Ol,{src:C,name:u.name,size:13,hoverPreview:!1}):u.uploading?e.jsx(Re,{size:13,className:"animate-spin"}):e.jsx(x,{size:13}),e.jsx("span",{className:"max-w-[140px] truncate",children:u.name}),e.jsx("span",{className:"text-[10px] text-dark-muted",children:u.size>1024*1024?`${(u.size/1024/1024).toFixed(1)} MB`:`${Math.max(1,Math.round(u.size/1024))} KB`}),!u.uploading&&e.jsx("button",{onClick:()=>Ka(u.id),className:"rounded p-0.5 text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors","aria-label":h("a11y.close"),children:e.jsx(De,{size:11})})]}),O=ge("flex items-center gap-1.5 rounded-lg border px-2 py-1 text-xs transition-colors",u.error?"border-accent-red/40 bg-accent-red/5 text-accent-red":u.uploading?"border-accent-blue/40 bg-accent-blue/5 text-accent-blue":"border-dark-border bg-dark-surface text-dark-text",C&&"cursor-zoom-in hover:border-accent-blue/40");return C?e.jsx(kn,{src:C,alt:u.name,className:"min-w-0",children:e.jsx("div",{className:O,children:_})},u.id):e.jsx("div",{className:O,children:_},u.id)})}),V&&e.jsx("div",{className:`${es} 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:h("fileJob.dropHint")}),e.jsx(qd,{}),e.jsxs("div",{className:`chat-composer-card relative rounded-xl border ${F?"":"transition-all duration-150"} ${es} ${it?"flex items-end gap-1 px-2 py-1.5":""}`,children:[!it&&e.jsx("div",{role:"separator","aria-orientation":"horizontal","aria-label":h("chat.resizeHint"),title:h("chat.resizeHint"),tabIndex:0,onPointerDown:Oa,onPointerMove:Pa,onPointerUp:Pn,onPointerCancel:Pn,onDoubleClick:La,onKeyDown:u=>{u.key==="ArrowUp"?(u.preventDefault(),Ln(24)):u.key==="ArrowDown"&&(u.preventDefault(),Ln(-24))},className:"group absolute inset-x-0 top-0 z-10 flex h-2.5 cursor-row-resize touch-none items-center justify-center rounded-t-xl outline-none focus-visible:bg-accent-blue/10",children:e.jsx("span",{"aria-hidden":"true",className:"h-1 w-9 rounded-full bg-dark-border transition-colors group-hover:bg-accent-blue/70 group-focus-visible:bg-accent-blue/70"})}),Ce&&e.jsx("div",{onMouseDown:u=>u.preventDefault(),"aria-hidden":!Ce,children:e.jsx(hu,{isOpen:Ce,items:at,selectedIndex:gs,query:$t,isSearching:Ia,onSelect:Ns,onHover:Ge,selectedCount:Ra,onFinish:pt,tabs:Xe,activeTab:ys,onTabChange:qt,scope:An,onToggleScope:vs,deliveryMode:Pt,onToggleDelivery:Ut})}),H&&e.jsx("div",{onMouseDown:u=>u.preventDefault(),"aria-hidden":!H,children:e.jsx(xu,{isOpen:H,items:Qe,selectedIndex:ee,query:ie,isLoading:$,onSelect:Ms,onHover:le})}),Oe&&e.jsx("div",{onMouseDown:u=>u.preventDefault(),"aria-hidden":!Oe,children:e.jsx(Su,{isOpen:Oe,commands:_t,selectedIndex:xs,filter:Ta,onSelect:Ss,onHover:fs,containerRef:Aa})}),e.jsx("textarea",{ref:y,value:p,onChange:Fa,onKeyDown:Ja,onPaste:Va,onBlur:()=>{Ce&&pt(),Me(),H&&Wt()},onCompositionStart:Ya,onCompositionEnd:Xa,placeholder:h(it?"chat.inputPlaceholderCollapsed":v?"chat.generatingPlaceholder":"chat.inputPlaceholder"),rows:1,"aria-label":"Message input",className:it?"w-full flex-1 bg-transparent px-1.5 py-1.5 text-sm text-dark-text placeholder-dark-muted/60 resize-none focus:outline-none min-h-[36px] max-h-[28vh] leading-relaxed":`w-full bg-transparent px-4 pt-4 pb-3 text-sm text-dark-text placeholder-dark-muted/60
44
+ resize-none focus:outline-none min-h-[72px] max-h-[40vh] leading-relaxed`}),it&&e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 pb-0.5",children:[e.jsx("button",{type:"button",onClick:()=>Jt(!1),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:h("chat.composerExpand"),"aria-label":h("chat.composerExpand"),children:e.jsx(ut,{size:15,"aria-hidden":"true"})}),v&&e.jsx("button",{onClick:a,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:h("chat.stopGen"),"aria-label":h("chat.stopGen"),children:e.jsx(ts,{size:13,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>void gt(),disabled:!Cs,className:`flex h-8 w-8 items-center justify-center rounded-full bg-dark-text text-dark-bg transition-all
45
+ hover:opacity-80 active:scale-95 disabled:opacity-25 disabled:cursor-not-allowed`,title:h(v?"chat.sendQueuedBtn":"chat.sendBtn"),"aria-label":h(v?"chat.sendQueuedBtn":"chat.sendBtn"),children:e.jsx(Xn,{size:15,"aria-hidden":"true"})})]}),!it&&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:[Vt&&e.jsx("button",{type:"button",onClick:()=>Jt(!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:h("chat.composerCollapse"),"aria-label":h("chat.composerCollapse"),children:e.jsx(Ue,{size:15,"aria-hidden":"true"})}),m&&e.jsx(wo,{workspaceDir:d,onSelect:m}),e.jsx(Hd,{}),e.jsx("span",{className:"hidden min-w-0 sm:block",children:e.jsx(Kd,{})}),e.jsx(Xd,{onHandoffToAi:$a}),In.length>0&&e.jsx("button",{type:"button",onClick:Ut,className:ge("flex h-8 min-w-0 items-center rounded-full px-2.5 text-[11px] font-medium transition-colors",Pu[Pt]),title:h("chat.mentionDeliveryHint"),children:e.jsx("span",{className:"max-w-[180px] truncate",children:h("chat.mentionDeliveryChip",{titles:In.join("、"),mode:h(Ou[Pt])})})})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[js>0&&p.length>0&&e.jsxs("span",{className:`text-[10px] tabular-nums ${Gn?"text-accent-red font-medium":"text-dark-muted/60"}`,children:["~",js," tokens",Gn?` · ${h("chat.nearLimit")}`:""]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("div",{ref:Ae,className:"relative",children:[e.jsxs("button",{onClick:()=>We(u=>!u),disabled:je.state!=="idle"||v,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:h(v?"stt.generatingTitle":"stt.langToggle"),"aria-label":h(v?"stt.generatingTitle":"stt.langToggle"),"aria-haspopup":"listbox","aria-expanded":be,children:[Mo(U).short,e.jsx(ut,{size:11,"aria-hidden":"true"})]}),be&&e.jsxs("div",{role:"listbox","aria-label":h("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:[Co.map(u=>e.jsxs("button",{role:"option","aria-selected":u.code===U,onClick:()=>Rt(u.code),className:ge("flex w-full items-center justify-between gap-2 px-3 py-1.5 text-xs transition-colors",u.code===U?"text-accent-blue bg-accent-blue/10":"text-dark-text hover:bg-dark-hover"),children:[e.jsx("span",{className:"font-medium",children:u.label}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-dark-muted",children:[u.code==="zh"?"FunASR":"Whisper",u.code===U&&e.jsx(Fe,{size:12,"aria-hidden":"true"})]})]},u.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:h("stt.multiHint")})]})]}),e.jsx("button",{onClick:()=>void Ca(),disabled:je.state==="transcribing"||v,className:ge("flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors",je.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:v?h("stt.generatingTitle"):je.state==="recording"?h("stt.stopTitle"):h("stt.title"),"aria-label":v?h("stt.generatingTitle"):je.state==="recording"?h("stt.stopTitle"):h("stt.title"),children:je.state==="transcribing"?e.jsx(Re,{size:15,className:"animate-spin","aria-hidden":"true"}):je.state==="recording"?e.jsx(Si,{size:15,"aria-hidden":"true"}):e.jsx(Mi,{size:15,"aria-hidden":"true"})}),je.state==="recording"&&e.jsxs("span",{className:"text-[10px] tabular-nums text-accent-red","aria-hidden":"true",children:[(je.elapsedMs/1e3).toFixed(0),"s"]})]}),!v&&e.jsx("button",{onClick:()=>L(!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:h("skills.pickTitle"),"aria-label":h("skills.pickTitle"),children:e.jsx(dn,{size:15,"aria-hidden":"true"})}),!v&&e.jsx("button",{onClick:()=>void Gt(),disabled:J,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:`${h("fileJob.screenshot")} (${Es}+Shift+S)`,"aria-label":`${h("fileJob.screenshot")} (${Es}+Shift+S)`,children:J?e.jsx(Re,{size:15,className:"animate-spin","aria-hidden":"true"}):e.jsx(Ci,{size:15,"aria-hidden":"true"})}),!v&&e.jsx("button",{onClick:()=>void qa(),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:h("fileJob.attach"),"aria-label":h("fileJob.attach"),children:e.jsx(cn,{size:15,"aria-hidden":"true"})}),e.jsx("input",{ref:N,type:"file",multiple:!0,accept:Au,className:"hidden",onChange:Ha}),v&&!Cs?e.jsxs("div",{className:"flex items-center gap-1.5",children:[S?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:h("chat.resumeGen"),"aria-label":h("chat.resumeGen"),children:e.jsx(Ei,{size:14,"aria-hidden":"true"})}):e.jsx("button",{onClick:i,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:h("chat.pauseGen"),"aria-label":h("chat.pauseGen"),children:e.jsx(Ur,{size:14,"aria-hidden":"true"})}),e.jsx("button",{onClick:a,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:h("chat.stopGen"),"aria-label":h("chat.stopGen"),children:e.jsx(ts,{size:13,"aria-hidden":"true"})})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[v&&e.jsx("button",{onClick:a,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:h("chat.stopGen"),"aria-label":h("chat.stopGen"),children:e.jsx(ts,{size:13,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>void gt(),disabled:!Cs,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:h(v?"chat.sendQueuedBtn":"chat.sendBtn"),"aria-label":h(v?"chat.sendQueuedBtn":"chat.sendBtn"),children:e.jsx(Xn,{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:h("chat.shiftEnter")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:h("chat.escHint")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:`${Es}+Shift+S ${h("shortcuts.screenshot")}`}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:h("chat.bangHint")})]}),e.jsx(mu,{open:j,onClose:()=>L(!1),onSelect:Ba})]})}),Hu=o.memo(function({activeSessionId:t}){const{t:n}=se(),a=bo(i=>i.observed).filter(i=>i.id!==t);return a.length===0?null:e.jsxs("div",{className:"mb-2 flex flex-col gap-1.5",children:[a.map(i=>e.jsx(qu,{id:i.id,title:i.title},i.id)),e.jsx("span",{className:"sr-only",children:n("chat.observedTitle")})]})});function qu({id:s,title:t}){const{t:n}=se(),r=pe(c=>{var d;return((d=c.generatingSessions)==null?void 0:d.includes(s))??!1}),a=pe(c=>{const d=c.messagesBySession[s],m=d&&d.length>0?d[d.length-1]:void 0;return!!(m!=null&&m.errorCard)}),i=pe(c=>{const d=c.messagesBySession[s];if(!d||d.length===0)return"";for(let m=d.length-1;m>=0;m--){const f=d[m];if(f.type==="user")continue;const h=f.content||"";if(h.trim())return h.trim().slice(-160)}return""}),l=n(r?"chat.observedRunning":a?"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(Yr,{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:t,children:t}),e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted",children:s.slice(0,8)}),r?e.jsx(Re,{size:12,className:"shrink-0 animate-spin text-accent-yellow","aria-hidden":"true"}):a?e.jsx(nn,{size:12,className:"shrink-0 text-accent-red","aria-hidden":"true"}):e.jsx(is,{size:12,className:"shrink-0 text-accent-green","aria-hidden":"true"}),e.jsx("span",{className:`shrink-0 text-[10px] ${a?"text-accent-red":r?"text-accent-yellow":"text-accent-green"}`,children:l}),i&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:i,children:i})]})}function Or(s,t){if(!s||!t||t.length===0)return;const n=s.find(r=>r.switchMode&&t.includes(r.label));n!=null&&n.switchMode&&Te.getState().setBaseMode(n.switchMode)}const Ku=15e3,Uu=300;function wa(s){const{t}=se();return o.useMemo(()=>{const n=t("chat.askOtherLabel"),r=t("chat.askProceedLabel"),a=s.options||[],i=a.some(f=>f.label===n),l=a.some(f=>f.label===r),c=[...a];l||c.push({label:r,description:t("chat.askProceedDesc")}),i||c.push({label:n,description:t("chat.askCustomDesc")});const d=i?c.findIndex(f=>f.label===n):c.length-1,m=l?c.findIndex(f=>f.label===r):c.length-(i?1:2);return{allItems:c,otherIdx:d,proceedIdx:m,displayItems:c}},[s,t])}function Pr({item:s,answered:t,selectedIdx:n,multiSelected:r,customInput:a,showCustomInput:i,onSelect:l,onToggleMulti:c,onProceed:d,onEnterCustom:m,onCancelCustom:f,onSubmitCustom:h,onCustomChange:p,inputRef:b}){const{t:v}=se(),{otherIdx:S,proceedIdx:k,displayItems:g}=wa(s),y=!!s.multiSelect,R=I=>{if(I===k){d();return}if(I===S){m();return}if(y){c(I);return}l(I)};return e.jsxs("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:[g.map((I,E)=>{const F=n===E,G=r.has(E),N=E===S;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 ${F?"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:()=>R(E),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[y&&e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center text-[10px] ${G?"bg-blue-600 border-blue-600 text-white":"border-gray-400 dark:border-gray-500"}`,children:G&&e.jsx(Fe,{size:10})}),e.jsxs("span",{className:`font-medium ${F?"text-blue-700 dark:text-blue-300":"text-gray-800 dark:text-gray-200"}`,children:[y?"":`${E+1}. `,I.label]}),E===k&&e.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:v("chat.askDirectTag")}),N&&e.jsx("span",{className:"text-xs text-gray-400",children:v("chat.askCustomTag")})]}),I.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 ml-6",children:I.description})]}),N&&F&&i&&e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("textarea",{ref:b,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:a,onChange:P=>p(P.target.value),onKeyDown:P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),h()),P.key==="Escape"&&f()},placeholder:v("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:h,children:[e.jsx(ct,{size:12}),v("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:f,children:[e.jsx(De,{size:12}),v("common.cancel")]})]})]})]},`opt-${E}`)}),t&&e.jsx("div",{className:"text-xs text-emerald-600 dark:text-emerald-400 font-medium",children:v("chat.askAnswered")})]})}function Wu({isOpen:s,onClose:t}){const{t:n}=se(),[r,a]=o.useState(null),[i,l]=o.useState(-1),[c,d]=o.useState(new Set),[m,f]=o.useState(""),[h,p]=o.useState(!1),[b,v]=o.useState(!1),[S,k]=o.useState(!1),[g,y]=o.useState(!1),[R,I]=o.useState(0),[E,F]=o.useState([]),[G,N]=o.useState(!1),P=o.useRef(null),B=o.useRef(null),M=o.useMemo(()=>r?r.questions&&r.questions.length>0?r.questions:[{question:r.question,header:r.header,options:r.options,multiSelect:r.multiSelect}]:[],[r]),z=M.length>1,V=o.useCallback(D=>{a(D),l(D.multiSelect?-1:0),d(new Set),f(""),p(!1),v(!1),k(!1),y(!1),I(0),N(!1);const ae=D.questions&&D.questions.length>0?D.questions:[D];F(ae.map(()=>null))},[]);o.useEffect(()=>{B.current=r}),o.useEffect(()=>{if(s){const D=window.__pendingQuestion;D&&V(D)}},[s,V]),o.useEffect(()=>{const D=ae=>{var U;const Y=ae.detail,A=((U=B.current)==null?void 0:U.questionId)??null;if(Y&&A&&Y!==A)return;const oe=A;v(!0),setTimeout(()=>{var be;const ye=((be=B.current)==null?void 0:be.questionId)??null;oe&&ye&&ye!==oe||(t(),a(null),v(!1))},Uu)};return window.addEventListener("ask-question-dismiss",D),()=>window.removeEventListener("ask-question-dismiss",D)},[t]),o.useEffect(()=>{if(!b)return;const D=setTimeout(()=>{v(!1),k(!0)},Ku);return()=>clearTimeout(D)},[b]),o.useEffect(()=>{const D=()=>{k(!1),y(!1)};return window.addEventListener("ask-question-dismiss",D),()=>window.removeEventListener("ask-question-dismiss",D)},[]),o.useEffect(()=>{const D=ae=>{var oe;const Y=ae.detail,A=((oe=B.current)==null?void 0:oe.questionId)??null;Y&&A&&Y!==A||(v(!1),k(!0),y(!0))};return window.addEventListener("ask-question-ack-failed",D),()=>window.removeEventListener("ask-question-ack-failed",D)},[]),o.useEffect(()=>{const D=()=>{const ae=window.__pendingQuestion;ae&&V(ae)};return window.addEventListener("ask-question-required",D),()=>window.removeEventListener("ask-question-required",D)},[V]),o.useEffect(()=>{l(0),d(new Set),f(""),p(!1)},[R,G,r]);const Q=M[R]||null,{allItems:J,otherIdx:re}=wa(Q||{question:""}),j=o.useCallback((D,ae)=>{b||!r||(k(!1),v(!0),Or(r.options,ae),Ne.send({type:"question_answer",sessionId:r.sessionId||Ne.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answer:D,selectedOptions:ae})}))},[b,r]),L=o.useCallback(()=>{b||!r||(k(!1),v(!0),Ne.send({type:"question_answer",sessionId:r.sessionId||Ne.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:M.map((D,ae)=>E[ae]||{answer:n("chat.askUnansweredValue")})})}))},[b,r,M,E,n]),H=o.useCallback((D,ae,Y)=>{var A;Or((A=M[D])==null?void 0:A.options,Y),F(oe=>{const U=oe.slice();return U[D]={answer:ae,selectedOptions:Y},U}),D<M.length-1?I(D+1):N(!0)},[M]),W=o.useCallback(D=>{if(b||!r)return;const ae=J[D];ae&&(l(D),j(ae.label,[ae.label]))},[b,r,J,j]),ie=o.useCallback(()=>{if(b||!r||i<0)return;const D=J[i];D&&j(D.label,[D.label])},[b,r,i,J,j]),T=o.useCallback(()=>{if(b||i<0)return;const D=J[i];D&&H(R,D.label,[D.label])},[b,i,J,H,R]),ee=o.useCallback(D=>{if(b)return;const ae=J[D];ae&&H(R,ae.label,[ae.label])},[b,J,H,R]),le=o.useCallback(D=>{b||d(ae=>{const Y=new Set(ae);return Y.has(D)?Y.delete(D):Y.add(D),Y})},[b]),w=o.useCallback(()=>{if(b)return;const D=[...c].map(ae=>{var Y;return((Y=J[ae])==null?void 0:Y.label)||""});z?H(R,D.join(", "),D):j(D.join(", "),D)},[b,c,J,z,H,R,j]),K=o.useCallback(()=>{if(b)return;const D=n("chat.askProceedLabel");z?H(R,D,[D]):j(D,[D])},[b,z,H,R,j,n]),$=o.useCallback(()=>{b||(l(re),p(!0),setTimeout(()=>{var D;return(D=P.current)==null?void 0:D.focus()},100))},[b,re]),ne=o.useCallback(()=>{p(!1),f("")},[]),he=o.useCallback(()=>{if(b)return;const D=m||n("chat.askEmptyInputValue");z?H(R,D):j(D)},[b,m,z,H,R,j,n]),te=o.useCallback(()=>{b||!r||(k(!1),v(!0),Ne.send({type:"question_answer",sessionId:r.sessionId||Ne.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:M.map(()=>({answer:"(cancelled)"}))})}))},[b,r,M]),me=o.useCallback(()=>{if(!b){if(g){t();return}if(z){if(h){p(!1),f("");return}if(G){N(!1),I(M.length-1);return}te();return}if(h){p(!1),f("");return}j("(cancelled)")}},[b,z,h,G,M.length,te,j,g,t]);if(!s||!r)return null;const de=E.filter(D=>!D).length;return e.jsx(sa,{isOpen:s,onClose:me,title:r.header||n(z?"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"),z?` · ${E.filter(Boolean).length}/${M.length}`:""]}),collapsedSummary:e.jsx("span",{className:"truncate",children:(Q==null?void 0:Q.question)||r.question}),maxHeight:"50vh",children:z?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:[M.map((D,ae)=>{const Y=!!E[ae],A=!G&&R===ae;return e.jsxs("button",{type:"button",onClick:()=>{I(ae),N(!1)},className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${A?"bg-blue-600 text-white":Y?"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",ae+1," ",Y?"✓":""]},`nav-${ae}`)}),e.jsx("button",{type:"button",onClick:()=>N(!0),className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${G?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:n("chat.askSubmit")})]}),G?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")}),M.map((D,ae)=>{const Y=E[ae];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:[ae+1,". "]}),D.question]}),e.jsx("div",{className:`text-xs shrink-0 max-w-[45%] text-right break-words ${Y?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dark:text-amber-400"}`,children:Y?Y.answer:n("chat.askNotAnswered")})]},`rev-${ae}`)}),de>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($e,{size:14}),n("chat.askUnansweredWarning",{count:de})]}),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:L,disabled:b,children:[e.jsx(ct,{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:()=>{N(!1),I(M.length-1)},disabled:b,children:n("chat.askBackToEdit")})]})]}):Q?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:Q.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:()=>{I(D=>Math.max(0,D-1)),N(!1)},disabled:R===0,children:[e.jsx(Ai,{size:12}),n("chat.askPrevQuestion")]}),R<M.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:()=>{I(D=>Math.min(M.length-1,D+1)),N(!1)},children:[n("chat.askNextQuestion"),e.jsx(tt,{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:()=>N(!0),children:[n("chat.askViewSubmit"),e.jsx(tt,{size:12})]})]})]}),e.jsx(Pr,{item:Q,answered:!!E[R],selectedIdx:i,multiSelected:c,customInput:m,showCustomInput:h,onSelect:ee,onToggleMulti:le,onProceed:K,onEnterCustom:$,onCancelCustom:ne,onSubmitCustom:he,onCustomChange:f,inputRef:P}),!h&&e.jsx("div",{className:"flex items-center gap-2",children:Q.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:w,disabled:b||c.size===0,children:[e.jsx(ct,{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:T,disabled:b||i<0,children:[e.jsx(ct,{size:14}),n("chat.askConfirmQuestion")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:h?e.jsx("span",{children:n("chat.askEnterHint")}):Q.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(Pr,{item:M[0],answered:!1,selectedIdx:i,multiSelected:c,customInput:m,showCustomInput:h,onSelect:W,onToggleMulti:le,onProceed:K,onEnterCustom:$,onCancelCustom:ne,onSubmitCustom:he,onCustomChange:f,inputRef:P}),!h&&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:w,disabled:b||c.size===0,children:[e.jsx(ct,{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:ie,disabled:b||i<0,children:[e.jsx(ct,{size:14}),n("chat.askSubmit")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:b?e.jsx("span",{children:n("chat.askSubmitting")}):S?e.jsxs("span",{className:"flex items-center gap-1.5 text-amber-600 dark:text-amber-400",children:[e.jsx($e,{size:12}),n("chat.askSubmitRetry")]}):h?e.jsx("span",{children:n("chat.askEnterHint")}):r.multiSelect?e.jsx("span",{children:n("chat.askMultiHintSingle")}):e.jsx("span",{children:n("chat.askSingleHintSingle")})})]})})}const wt=15;function Gu({isOpen:s,onCloseModal:t}){const{t:n}=se("hook"),r=Ys(),a=r.pendingApprovals,i=r.autoMode,l=r.setAutoMode,[c,d]=o.useState(0),[m,f]=o.useState(!1),[h,p]=o.useState(wt),[b,v]=o.useState(!0),S=o.useRef(null),k=o.useRef(!1);o.useEffect(()=>{if(a.length!==0){if(i){a.forEach(te=>{Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:te.approvalId})})}),r.clearApprovals();return}d(te=>Math.min(te,a.length-1))}},[a.length,i]);const g=a[c]??null,y=a.length>0&&g!==null,R=a.length,I=y?R-c-1:0;o.useEffect(()=>{if(!(!y||m||!s||!g))return p(wt),S.current=setInterval(()=>{p(te=>te<=1?(S.current&&clearInterval(S.current),0):te-1)},1e3),()=>{S.current&&clearInterval(S.current)}},[y,m,s,g==null?void 0:g.approvalId]);const E=g?Xr(g.toolName,g.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},F=Qr[E.level],G=ko[E.level==="CRITICAL"?"critical":E.level==="HIGH"?"high":E.level==="LOW"?"low":"medium"],N=g?ma(g.toolName,g.askPayload):null,P=g?vo(g.toolName,g.askPayload):null,B=g?{verb:ua(g.toolName),target:ha(g.toolName,g.askPayload)}:null,M=g?Tt(g.askPayload)!==null:!1,z=g?xa(g.toolName,g.askPayload):null,V=h/wt*100,Q=h<=5,J=mt((wt-h)*1e3),re=o.useCallback((te,me)=>{const de=mn.getState().activeSessionId;de&&pe.getState().updateHookApprovalStatus(de,te,me)},[]),j=o.useCallback(te=>{g&&(te&&re(g.approvalId,te),f(!0),setTimeout(()=>{r.removeApproval(g.approvalId),d(0),f(!1),k.current=!1,p(wt)},200))},[g==null?void 0:g.approvalId,r,re]),L=o.useCallback(()=>{!g||m||k.current||(k.current=!0,S.current&&clearInterval(S.current),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:g.approvalId})}),j("approved"))},[g,j,m]),H=o.useCallback(()=>{!g||m||k.current||(k.current=!0,S.current&&clearInterval(S.current),Ne.send({type:"hook_deny",data:JSON.stringify({approvalId:g.approvalId})}),j("denied"))},[g,j,m]),W=o.useCallback(()=>{if(!g||m||k.current)return;k.current=!0,S.current&&clearInterval(S.current);const te=Tt(g.askPayload);te?(r.addToSessionAllowList(g.toolName,te),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:g.approvalId,sessionAllow:!0})})):(r.addToSessionAllowList(g.toolName),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:g.approvalId})})),j("approved")},[g,j,r,m]),ie=o.useCallback(()=>{!g||m||k.current||(k.current=!0,S.current&&clearInterval(S.current),l(!0),Te.getState().setAuto(!0),Ne.send({type:"hook_allow",data:JSON.stringify({approvalId:g.approvalId})}),j("approved"))},[g,j,m,l]),T=((g==null?void 0:g.timeoutMs)??15e3)>0,ee=(g==null?void 0:g.timeoutAction)==="deny"?H:L;if(o.useEffect(()=>{h===0&&s&&!m&&g&&T&&ee()},[h,s,m,g,ee,T]),o.useEffect(()=>{if(!s||!b)return;const te=me=>{const de=me.target;de&&typeof de.closest=="function"&&de.closest('input, textarea, select, [contenteditable="true"]')||(me.key==="Escape"?(me.preventDefault(),me.stopPropagation(),H()):me.key==="Enter"?(me.preventDefault(),L()):me.key==="1"?L():me.key==="2"?H():me.key==="3"?W():me.key==="4"&&ie())};return window.addEventListener("keydown",te),()=>window.removeEventListener("keydown",te)},[s,b,L,H,W,ie]),!y||!g)return null;const le=n("optionAllowHint"),w=n("optionDenyHint"),K=M?n("optionAllowPathHint"):n("optionAllowAlwaysHint",{tool:g.toolName}),$=n("optionAutoModeHint"),ne=(N==null?void 0:N.text)??P??null,he=ne?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:g.toolName}),e.jsx("span",{className:"truncate",children:ne})]}):null;return e.jsx(sa,{isOpen:s,onClose:()=>t==null?void 0:t(),title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gs,{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,"/",R,")"]})]}),badge:e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${F.badge}`,children:[F.icon," ",E.level]}),collapsedSummary:he,onExpandedChange:v,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 ${F.bg} border ${F.border}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${F.badge}`,children:[F.icon," ",E.level]}),e.jsx("span",{className:"text-xs text-dark-muted truncate",children:n(E.reasonKey)}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[e.jsx(Mt,{size:12,className:Q?"text-accent-red":"text-dark-muted"}),e.jsx("span",{className:`text-xs font-mono ${Q?"text-accent-red animate-pulse":"text-dark-muted"}`,children:T?`${h}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 ${Q?"bg-accent-red":h<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${V}%`}})})]})]}),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(Gs,{size:15})}),B&&e.jsx(fa,{pre:n(B.verb),obj:B.target})]}),z&&(z.external&&z.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:z.path,children:[e.jsx(as,{size:10}),n("scopeExternal"),": ",z.path.length>48?`${z.path.slice(0,47)}…`:z.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:g.toolName}),e.jsx("span",{className:"text-dark-muted/50",children:J}),e.jsx("span",{className:"text-dark-muted/50",children:G.label}),g.timeoutAction&&e.jsxs("span",{className:`text-xs ${g.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",T?`${g.timeoutAction==="allow"?"auto-allow":"auto-deny"}${g.timeoutMs?` (${(g.timeoutMs/1e3).toFixed(0)}s)`:""}`:n("timeoutWaitUser")]})]}),N?e.jsx(en,{text:N.text,mono:N.mono}):P?e.jsx(en,{text:P}):null,(E.level==="CRITICAL"||E.level==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${F.bg} ${F.text}`,children:[e.jsx($e,{size:13}),e.jsx("span",{children:E.level==="CRITICAL"?n("highRiskWarning"):n("mediumRiskConfirm")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:L,disabled:m,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:Xt.allow.label}),e.jsx("span",{className:"text-[11px] text-white/70 hidden sm:inline",children:le})]}),e.jsxs("button",{onClick:W,disabled:m,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:Xt.allow_session.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:K})]}),e.jsxs("button",{onClick:ie,disabled:m,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:Xt.auto.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:$})]}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:H,disabled:m,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:Xt.deny.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:w})]})]}),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:I>0?n("morePending",{n:I}):n("lastItem")})]})]})})}const Ws="dsc-auto-access-banner-dismissed",Vu=o.memo(function(){const{t}=se(),n=Te(c=>c.mode),[r,a]=o.useState(()=>localStorage.getItem(Ws)==="1");o.useEffect(()=>{Zs(n==="normal"?"act":n)||localStorage.getItem(Ws)==="1"&&a(!1)},[n]);const i=o.useCallback(c=>{c&&localStorage.setItem(Ws,"1"),a(!0)},[]);return!(n!=="normal"&&Zs(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:t("autoAccess.desc"),children:[e.jsx(Ii,{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:t("autoAccess.title")}),e.jsxs("span",{className:"text-accent-yellow/60",children:[" · ",t("autoAccess.desc")]})]}),e.jsx("button",{onClick:()=>i(!1),className:"shrink-0 rounded p-0.5 text-accent-yellow/50 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors",title:t("autoAccess.dismiss"),"aria-label":t("autoAccess.dismiss"),children:e.jsx(De,{size:11})}),e.jsx("button",{onClick:()=>i(!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:t("autoAccess.neverShow")})]})}),Ju=12,Yu=56;function Na(s,t){const n=s.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}…`:n}function Xu(s){return Na(s,Ju)}function Lr(){return`custom-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Qu(s,t){return s.some(n=>n.kind==="scenario"&&n.id===t)}function Zu(s){if(!s||typeof s!="object")return!1;const t=s;return typeof t.id!="string"||t.id===""||typeof t.label!="string"||t.label===""||typeof t.hint!="string"?!1:t.kind==="template"?typeof t.templateId=="string"&&t.templateId!=="":t.kind!==void 0&&t.kind!=="prompt"?!1:typeof t.prompt=="string"&&t.prompt!==""}function eh(s){if(!s||typeof s!="object")return!1;const t=s;return typeof t.id=="string"&&t.id!==""&&typeof t.label=="string"&&t.label!==""&&Array.isArray(t.scenarios)&&t.scenarios.length>0&&t.scenarios.every(Zu)}function th(s){const t=s("chat.start.categories",{returnObjects:!0,defaultValue:[]});return Array.isArray(t)?t.filter(eh):[]}const sh="tpl:",nh="tpl-";function Fr(s){return s.trim().toLowerCase()}function rh(s){const t=new Map;for(const n of s){const r=(n.category??"").trim();if(!r)continue;const a=(n.name??"").trim();if(!a)continue;const i={id:`${nh}${n.id}`,label:a,hint:n.description??"",prompt:"",kind:"template",templateId:n.id},l=t.get(r);l?l.push(i):t.set(r,[i])}return[...t].map(([n,r])=>({id:`${sh}${n}`,label:n,scenarios:r}))}function ah(s,t){if(t.length===0)return s;const n=s.map(i=>({...i})),r=new Set(n.map(i=>i.id)),a=new Map(n.map((i,l)=>[Fr(i.label),l]));for(const i of t){const l=Fr(i.label),c=a.get(l);if(c!==void 0){const d=n[c];n[c]={...d,scenarios:[...d.scenarios,...i.scenarios]};continue}r.has(i.id)||(r.add(i.id),a.set(l,n.length),n.push(i))}return n}const Sa=6;function ih(s,t,n){const r=new Map;for(const l of s)for(const c of l.scenarios)r.set(c.id,c);const a=new Set,i=[];for(const l of t){if(a.has(l.id))continue;if(a.add(l.id),l.kind==="custom"){i.push({id:l.id,label:l.label,hint:Na(l.prompt,Yu),prompt:l.prompt});continue}const c=r.get(l.id);c&&i.push(c)}return Ma(i,n).slice(0,Sa)}function oh(s){return s<5?"chat.start.greetingDawn":s<11?"chat.start.greetingMorning":s<13?"chat.start.greetingNoon":s<18?"chat.start.greetingAfternoon":"chat.start.greetingEvening"}function lh(s,t,n){const r=s(oh(t)),a=(n??"").trim();return a?s("chat.start.withName",{greeting:r,name:a}):r}function Ma(s,t){return s.map((n,r)=>({scenario:n,index:r,count:t[n.id]??0})).sort((n,r)=>r.count-n.count||n.index-r.index).map(n=>n.scenario)}function ch(s,t){return s.length===0||!t?null:s.find(n=>n.id===t)??null}const Ee=To()(yo((s,t)=>({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0,setCategoryId:n=>s({categoryId:n,suggestionsHidden:!1}),recordUse:n=>s(r=>({clickCounts:{...r.clickCounts,[n]:(r.clickCounts[n]??0)+1},favorites:r.favorites.some(a=>a.id===n)?r.favorites:[{kind:"scenario",id:n},...r.favorites]})),toggleFavorite:n=>s(r=>({favorites:r.favorites.some(a=>a.kind==="scenario"&&a.id===n)?r.favorites.filter(a=>!(a.kind==="scenario"&&a.id===n)):[{kind:"scenario",id:n},...r.favorites]})),removeFavorite:n=>s(r=>({favorites:r.favorites.filter(a=>a.id!==n)})),addCustomFavorite:(n,r)=>{const a=r.trim();if(!a)return null;let i=Lr();const l=new Set(t().favorites.map(d=>d.id));for(;l.has(i);)i=Lr();const c={kind:"custom",id:i,label:n.trim()||Xu(a),prompt:a};return s(d=>({favorites:[c,...d.favorites]})),c},toggleSuggestions:()=>s(n=>({suggestionsHidden:!n.suggestionsHidden})),requestFocus:()=>s(n=>({prefillNonce:n.prefillNonce+1})),reset:()=>s({categoryId:null,clickCounts:{},favorites:[],suggestionsHidden:!0,prefillNonce:0})}),{name:"deepseekcode-start-page-storage",partialize:s=>({categoryId:s.categoryId,clickCounts:s.clickCounts,favorites:s.favorites,suggestionsHidden:s.suggestionsHidden}),version:2,migrate:(s,t)=>{const n=t??0;if(n>=2||!s||typeof s!="object")return s;const r=s,a=n<1?!0:r.suggestionsHidden,i=n<1?Object.entries(r.clickCounts??{}).sort((l,c)=>c[1]-l[1]).slice(0,Sa).map(([l])=>l):r.favoriteIds??[];return{categoryId:r.categoryId??null,clickCounts:r.clickCounts??{},suggestionsHidden:a,favorites:i.map(l=>({kind:"scenario",id:l}))}}}));function dh(s){return typeof s!="string"||!s?null:s.split(/[\\/]+/).pop()||null}const uh={enabled:!0,exists:!1,name:null,file:null};function hh(){const[s,t]=o.useState(uh);return o.useEffect(()=>{let n=!1;const r=()=>{ve.profile.get().then(a=>{if(n||!a.success||!a.data)return;const i=a.data,l=i.enabled!==!1,c=i.exists===!0,d={enabled:l,exists:c,name:l&&i.name?i.name:null,file:l&&c?dh(i.path):null};t(m=>m.enabled===d.enabled&&m.exists===d.exists&&m.name===d.name&&m.file===d.file?m:d)}).catch(()=>{})};return r(),window.addEventListener(er,r),()=>{n=!0,window.removeEventListener(er,r)}},[]),s}const mh=o.memo(function(){return e.jsxs("div",{className:"relative flex min-h-[8.5rem] w-full flex-col justify-end pb-1",children:[e.jsx(xh,{}),e.jsx(gh,{})]})}),xh=o.memo(function(){const{t}=se(),{enabled:n,exists:r,name:a,file:i}=hh(),l=o.useMemo(()=>lh(t,new Date().getHours(),a),[t,a]);return e.jsxs("div",{className:"chat-col px-4 pt-2 sm:px-6",children:[e.jsxs("h1",{className:"text-[24px] font-semibold leading-snug tracking-tight text-dark-text sm:text-[26px]",children:[e.jsx("span",{className:"block",children:l}),e.jsx("span",{className:"block",children:t("chat.start.question")})]}),e.jsx(fh,{enabled:n,exists:r,name:a,file:i})]})});function fh({enabled:s,exists:t,name:n,file:r}){const{t:a}=se(),i=s?n?a("chat.start.profileOn",{name:n}):t?r?a("chat.start.profileFile",{file:r}):a("chat.start.profileSet"):a("chat.start.profileAnonymous"):a("chat.start.profileDisabled"),l=o.useCallback(()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"profile"}}))},[]);return e.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:e.jsxs("button",{type:"button",onClick:l,title:a("chat.start.profileHint"),className:"inline-flex min-w-0 items-center gap-1.5 rounded-full border border-dark-border/70 bg-dark-surface/50 px-2.5 py-1 text-[11px] text-dark-muted transition-colors hover:border-accent-blue/40 hover:text-dark-text",children:[e.jsx(zi,{size:11,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:i}),e.jsxs("span",{className:"shrink-0 text-dark-muted/70",children:["· ",a("chat.start.profileEdit")]})]})})}const ph=[{glyph:"/",labelKey:"shortcuts.slashCommand"},{glyph:"@",labelKey:"shortcuts.fileRef"},{glyph:"!",labelKey:"shortcuts.shellCommand"},{glyph:"$",labelKey:"shortcuts.skillRef"}],gh=o.memo(function(){const{t}=se();return e.jsx("ul",{"data-testid":"start-tips","aria-label":t("shortcuts.title"),className:"chat-col mt-3 flex flex-wrap items-center gap-x-4 gap-y-1.5 px-4 sm:px-6",children:ph.map(n=>e.jsxs("li",{className:"inline-flex items-center gap-1.5 text-[10px] text-dark-muted/60",children:[e.jsx("kbd",{className:"rounded border border-dark-border bg-dark-bg px-1.5 py-0.5 font-mono text-[10px] leading-none text-dark-muted",children:n.glyph}),e.jsx("span",{children:t(n.labelKey)})]},n.glyph))})}),bh=o.memo(function({sessionId:t,onStartTemplate:n}){const{t:r}=se(),[a,i]=o.useState([]);o.useEffect(()=>{if(!n)return;let w=!1;return ve.templates.list().then(K=>{!w&&K.success&&K.data&&i(K.data)}).catch(()=>{}),()=>{w=!0}},[n]);const l=o.useMemo(()=>ah(th(r),rh(a)),[r,a]),c=Ee(w=>w.categoryId),d=Ee(w=>w.setCategoryId),m=Ee(w=>w.clickCounts),f=Ee(w=>w.favorites),h=Ee(w=>w.recordUse),p=Ee(w=>w.toggleFavorite),b=Ee(w=>w.removeFavorite),v=Ee(w=>w.addCustomFavorite),S=Ee(w=>w.suggestionsHidden),k=Ee(w=>w.toggleSuggestions),g=Ee(w=>w.requestFocus),y=o.useMemo(()=>ch(l,c),[l,c]),R=o.useCallback(()=>d(null),[d]),I=o.useMemo(()=>y?Ma(y.scenarios,m):ih(l,f,m),[y,l,f,m]),[E,F]=o.useState(!1),[G,N]=o.useState(""),[P,B]=o.useState(""),M=o.useCallback(()=>{F(!1),N(""),B("")},[]),z=o.useCallback(()=>{F(!0),S&&k()},[S,k]),V=o.useCallback(w=>{w.preventDefault(),v(G,P)&&M()},[v,M,G,P]),Q=o.useCallback(w=>{t&&(pe.getState().setSessionInput(t,w.prompt),h(w.id),g())},[t,h,g]),[J,re]=o.useState(null),[j,L]=o.useState(""),H=o.useCallback(async w=>{L("");const K=await ve.templates.get(w);if(!K.success||!K.data){L(r("templates.loadFailed"));return}re(K.data),S&&k()},[r,S,k]),W=o.useCallback(w=>{if(w.kind==="template"&&w.templateId){n&&H(w.templateId);return}Q(w)},[n,H,Q]),ie=o.useRef([]),[T,ee]=o.useState(0),le=o.useCallback((w,K,$)=>{var ne;if(w.key==="ArrowDown"||w.key==="ArrowUp"){w.preventDefault();const he=w.key==="ArrowDown"?Math.min(K+1,I.length-1):Math.max(K-1,0);ee(he),(ne=ie.current[he])==null||ne.focus();return}if(w.key==="Tab"){w.preventDefault(),W($);return}},[W,I.length]);return l.length===0?null:e.jsxs("div",{className:"start-col max-md:order-3 px-4 pb-4 sm:px-6",children:[e.jsxs("div",{role:"tablist","aria-label":r("chat.start.categoriesLabel"),onKeyDown:w=>{w.key==="Escape"&&c&&(w.preventDefault(),R())},className:"mt-5 flex items-center gap-2 overflow-x-auto pb-1",children:[l.map(w=>{const K=w.id===c;return e.jsxs("span",{"data-testid":"start-chip","data-category-id":w.id,"data-selected":K?"true":void 0,className:`inline-flex shrink-0 items-center overflow-hidden rounded-full border transition-colors focus-within:ring-1 focus-within:ring-accent-blue/60 ${K?"border-transparent bg-gradient-to-r from-accent-blue to-accent-purple text-white shadow-sm":"border-dark-border/70 text-dark-muted hover:border-accent-blue/40 hover:text-dark-text"}`,children:[e.jsx("button",{type:"button",role:"tab","aria-selected":K,"data-testid":"start-chip-label",onClick:()=>d(K?null:w.id),className:`py-1 text-[11px] transition-colors focus-visible:outline-none ${K?"pl-3 pr-1.5":"px-3"}`,children:w.label}),K&&e.jsx("button",{type:"button","data-testid":"start-chip-clear","aria-label":r("chat.start.clearCategory",{label:w.label}),title:r("chat.start.clearCategory",{label:w.label}),onClick:R,className:"py-1 pl-0 pr-2 text-white/75 transition-colors hover:text-white focus-visible:outline-none",children:e.jsx(De,{size:12,"aria-hidden":"true"})})]},w.id)}),e.jsx(tt,{size:13,"aria-hidden":"true",className:"shrink-0 text-dark-muted/50"})]}),e.jsxs("div",{className:"mt-2.5",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[e.jsxs("span",{className:"min-w-0 truncate text-[11px] text-dark-muted/60",children:[y?r("chat.start.categoryTitle",{label:y.label}):r("chat.start.frequentTitle"),e.jsx("span",{className:"ml-2 text-dark-muted/40",children:r(y?"chat.start.selectedHint":"chat.start.frequentHint")})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-3",children:[!y&&!E&&e.jsxs("button",{type:"button","data-testid":"start-custom-add",onClick:z,className:"inline-flex items-center gap-1 text-[11px] text-dark-muted/60 transition-colors hover:text-dark-text",children:[e.jsx(Ri,{size:11,"aria-hidden":"true"}),r("chat.start.customAdd")]}),e.jsx("button",{type:"button",onClick:k,className:"inline-flex items-center gap-1 text-[11px] text-dark-muted/60 transition-colors hover:text-dark-text",children:S?e.jsxs(e.Fragment,{children:[e.jsx(an,{size:11,"aria-hidden":"true"}),r("chat.start.show")]}):e.jsxs(e.Fragment,{children:[e.jsx(Di,{size:11,"aria-hidden":"true"}),r("chat.start.hide")]})})]})]}),j&&e.jsx("div",{"data-testid":"start-template-error",className:"mb-2 text-[11px] text-accent-red",children:j}),J&&e.jsxs("div",{"data-testid":"start-template-form",className:"mb-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3",children:[e.jsx("div",{className:"mb-2 text-[12px] font-medium text-dark-text",children:J.name}),e.jsx(jo,{template:J,onCancel:()=>re(null),onSubmit:w=>{const K=J;re(null),n==null||n(K,w)},submitLabel:r("templates.launch")})]}),E&&!y&&e.jsxs("form",{"data-testid":"start-custom-form",onSubmit:V,className:"mb-2 flex flex-col gap-2 rounded-xl border border-dark-border/60 bg-dark-surface/40 p-3",children:[e.jsx("input",{"data-testid":"start-custom-label",value:G,onChange:w=>N(w.target.value),placeholder:r("chat.start.customLabelPlaceholder"),maxLength:40,className:"w-full rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-[12px] text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none"}),e.jsx("textarea",{"data-testid":"start-custom-prompt",value:P,onChange:w=>B(w.target.value),placeholder:r("chat.start.customPromptPlaceholder"),rows:2,autoFocus:!0,className:"w-full resize-none rounded-md border border-dark-border/60 bg-dark-bg/60 px-2.5 py-1.5 text-[12px] leading-snug text-dark-text placeholder:text-dark-muted/50 focus:border-accent-blue/50 focus-visible:outline-none"}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{type:"button","data-testid":"start-custom-cancel",onClick:M,className:"rounded-md px-2.5 py-1 text-[11px] text-dark-muted transition-colors hover:text-dark-text",children:r("chat.start.customCancel")}),e.jsx("button",{type:"submit","data-testid":"start-custom-save",disabled:!P.trim(),className:"rounded-md border border-accent-blue/40 bg-accent-blue/10 px-2.5 py-1 text-[11px] font-medium text-accent-blue transition-colors hover:bg-accent-blue/20 disabled:cursor-not-allowed disabled:border-dark-border/60 disabled:bg-transparent disabled:text-dark-muted/40",children:r("chat.start.customSave")})]})]}),!S&&!J&&(I.length===0?E?null:e.jsx("p",{"data-testid":"start-frequent-empty",className:"rounded-xl border border-dashed border-dark-border/60 px-4 py-3 text-[12px] leading-relaxed text-dark-muted/70",children:r("chat.start.frequentEmpty")}):e.jsx("div",{className:"overflow-hidden rounded-xl border border-dark-border/60 bg-dark-surface/40",children:I.map((w,K)=>{const $=Qu(f,w.id);return e.jsxs("div",{"data-testid":"start-row-shell",className:`group flex items-center transition-colors hover:bg-dark-hover/40 focus-within:bg-dark-hover/40 ${K>0?"border-t border-dark-border/40":""}`,children:[e.jsxs("button",{ref:ne=>{ie.current[K]=ne},type:"button","data-testid":"start-row","data-scenario-id":w.id,tabIndex:K===T?0:-1,onClick:()=>W(w),onKeyDown:ne=>le(ne,K,w),className:"flex min-w-0 flex-1 items-baseline gap-3 py-2.5 pl-4 pr-2 text-left transition-colors focus-visible:outline-none",children:[e.jsx("span",{className:"w-[84px] shrink-0 text-[13px] font-medium leading-snug text-dark-text",children:w.label}),e.jsx("span",{className:"min-w-0 flex-1 border-l border-dark-border/50 pl-3 text-[13px] leading-snug text-dark-muted",children:w.hint}),e.jsx(ln,{size:12,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-dark-muted/40"})]}),y?e.jsx("button",{type:"button","data-testid":"start-row-favorite","aria-pressed":$,"aria-label":r($?"chat.start.removeFavorite":"chat.start.addFavorite",{label:w.label}),title:r($?"chat.start.removeFavorite":"chat.start.addFavorite",{label:w.label}),onClick:()=>p(w.id),className:`mr-2 shrink-0 rounded-md p-1.5 transition-colors focus-visible:outline-none ${$?"text-accent-yellow":"text-dark-muted/40 hover:text-dark-text"}`,children:e.jsx(_i,{size:13,"aria-hidden":"true",className:$?"fill-current":""})}):e.jsx("button",{type:"button","data-testid":"start-row-remove","aria-label":r("chat.start.removeFavorite",{label:w.label}),title:r("chat.start.removeFavorite",{label:w.label}),onClick:()=>b(w.id),className:"mr-2 shrink-0 rounded-md p-1.5 text-dark-muted/40 transition-colors hover:text-dark-text focus-visible:outline-none",children:e.jsx(De,{size:13,"aria-hidden":"true"})})]},w.id)})}))]})]})}),Br=24,Hr=320,kh={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"}},vh=({status:s})=>s==="running"?e.jsx(Re,{size:12,className:"animate-spin text-accent-blue"}):s==="completed"?e.jsx(is,{size:12,className:"text-accent-green"}):s==="failed"?e.jsx(Pi,{size:12,className:"text-accent-red"}):s==="skipped"?e.jsx(Li,{size:12,className:"text-dark-muted"}):e.jsx(Fi,{size:12,className:"text-dark-muted"}),qr={workflow:"WF",goal:"Goal",plan:"Plan",task:"Task",todo:"Todo",agent:"Agent"};function yh(s){const t=new Map;for(const i of s)t.set(i.id,i);const n=new Map,r=[];for(const i of s){const c=i.source==="goal"&&i.dependencies&&i.dependencies[0]||void 0;if(c&&t.has(c)){const d=n.get(c)??[];d.push(i),n.set(c,d)}else r.push(i)}const a=(i,l)=>{const c=(n.get(i.id)??[]).filter(d=>!l.has(d.id)).map(d=>a(d,new Set(l).add(i.id)));return{task:i,children:c}};return r.map(i=>a(i,new Set))}const jh=o.memo(function s({node:t,depth:n}){const{task:r,children:a}=t,i=kh[r.status],l=o.useMemo(()=>r.startedAt?mt((r.completedAt||Date.now())-r.startedAt):"",[r.startedAt,r.completedAt]);return e.jsxs("li",{className:"min-w-0",children:[e.jsx("div",{className:`rounded border p-2 transition-colors ${i.bg} border-dark-border`,style:{marginLeft:n*14},children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vh,{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] ${i.color} shrink-0`,children:i.label}),r.source&&qr[r.source]&&e.jsx("span",{className:"rounded bg-dark-surface/80 px-1 py-px text-[9px] text-dark-muted",children:qr[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]})]})]})}),a.length>0&&e.jsx("ul",{className:"mt-1 space-y-1",children:a.map(c=>e.jsx(s,{node:c,depth:n+1},c.task.id))})]})}),wh=o.memo(function({sessionId:t,defaultExpanded:n,onClose:r}){const{t:a}=se(),[i,l]=o.useState(n??!0),c=Et(N=>N.tasksBySession[t]),d=o.useMemo(()=>Et.getState().getTasksForSession(t),[t,c]),[m,f]=o.useState(null),h=o.useRef(null),p=o.useRef(!1),b=o.useRef(null),v=o.useCallback(N=>{var P;N.button===0&&(N.target.closest("[data-taskboard-close]")||(p.current=!1,h.current={y:N.clientY,expanded:i,bodyHeight:((P=b.current)==null?void 0:P.offsetHeight)??0},N.currentTarget.setPointerCapture(N.pointerId)))},[i]),S=o.useCallback(N=>{const P=h.current;P&&(Math.abs(N.clientY-P.y)>4&&(p.current=!0),f(N.clientY-P.y))},[]),k=o.useCallback(N=>{const P=h.current;if(!P)return;const B=N.clientY-P.y;P.expanded&&B<-Br?l(!1):!P.expanded&&B>Br&&l(!0),h.current=null,f(null),setTimeout(()=>{p.current=!1},0)},[]),g=o.useCallback(()=>{if(p.current){p.current=!1;return}l(N=>!N)},[]),y=o.useCallback(N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),l(P=>!P))},[]),R=m!==null,I=o.useMemo(()=>{const N=h.current;return m===null||!N?null:N.expanded?Math.min(Hr,Math.max(0,N.bodyHeight+m)):Math.min(Hr,Math.max(0,m))},[m]),E=o.useMemo(()=>{const N=d.length,P=d.filter(V=>V.status==="completed").length,B=d.filter(V=>V.status==="running").length,M=d.filter(V=>V.status==="failed").length,z=N>0?Math.round(P/N*100):0;return{total:N,completed:P,running:B,failed:M,progress:z}},[d]),F=o.useMemo(()=>yh(d),[d]),G=i||R;return d.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":i,onClick:g,onKeyDown:y,onPointerDown:v,onPointerMove:S,onPointerUp:k,onPointerCancel:k,onLostPointerCapture:k,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:a("chat.taskBoardDragHint"),children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx($i,{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:[E.completed,"/",E.total]}),E.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 ${E.running>0?"bg-accent-blue":E.failed>0?"bg-accent-red":"bg-accent-green"}`,style:{width:`${E.progress}%`}})}),E.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:N=>{N.stopPropagation(),r()},onKeyDown:N=>{N.key==="Enter"&&(N.stopPropagation(),r())},className:"p-0.5 rounded hover:bg-dark-hover transition-colors cursor-pointer",title:"Hide task drawer",children:e.jsx(De,{size:12,className:"text-dark-muted"})}),e.jsx(Oi,{size:12,className:"text-dark-muted/40 shrink-0","aria-hidden":"true"}),i?e.jsx(ut,{size:14,className:"text-dark-muted"}):e.jsx(Ue,{size:14,className:"text-dark-muted"})]})]}),G&&e.jsx("div",{ref:b,className:"border-t border-dark-border",style:I!==null?{height:I,overflow:"hidden"}:void 0,children:e.jsx("div",{className:"px-2.5 py-2 max-h-[320px] overflow-y-auto custom-scrollbar",children:F.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:a("chat.noTasks")}):e.jsx("ul",{className:"space-y-1.5",children:F.map(N=>e.jsx(jh,{node:N,depth:0},N.task.id))})})})]})}),Nh=[{mode:"chat",Icon:Bi,labelKey:"trajectory.viewChat"},{mode:"trajectory",Icon:Hi,labelKey:"trajectory.viewTrajectory"}],Kr=[],_h=o.memo(function({tabs:t,activeSessionId:n,onSend:r,onStop:a,onPause:i,onResume:l,activeTab:c,setActiveTab:d,createNewSession:m,clearMessages:f,setTheme:h,setThemePreset:p,setLogs:b,setUnreadLogs:v,showTaskBoard:S=!0,onToggleTaskBoard:k,onRegenerate:g,onDeleteMessage:y,onOpenSidebarView:R,hookDrawerOpen:I,onCloseHookDrawer:E,questionDrawerOpen:F,onCloseQuestionDrawer:G,workspaceDir:N,onWorkspaceSelect:P,errorLogs:B,onOpenLogs:M,onStartTemplate:z}){const V=o.useMemo(()=>({setActiveTab:d,createNewSession:m,clearMessages:f,setTheme:h,setThemePreset:p,setLogs:b,setUnreadLogs:v}),[d,m,f,h,p,b,v]),[Q,J]=o.useState("chat"),{t:re}=se(),j=pe($=>n?$.messagesBySession[n]??Kr:Kr),L=pe($=>n?$.generatingSessions.includes(n):!1),H=pe($=>n?$.pausedSessions.includes(n):!1),W=t.find($=>$.id===n)||null,ie=o.useMemo(()=>j.filter($=>!$.deleted).length===0,[j]),T=Ee($=>$.prefillNonce);o.useEffect(()=>{if(!n)return;let $=!1;return ve.tasks.list(n).then(ne=>{if($||!ne.success||!Array.isArray(ne.data))return;const he={PENDING:"pending",RUNNING:"running",COMPLETED:"completed",FAILED:"failed",CANCELLED:"skipped"},te=Date.now(),me=ne.data.filter(de=>de.sessionId===n).map(de=>{const D=new Date(de.createdAt).getTime()||te,ae=new Date(de.updatedAt).getTime()||te;return{id:de.id,sessionId:n,title:de.title,status:he[de.status]||"pending",source:"task",description:de.description,progress:de.progress,createdAt:D,updatedAt:ae,raw:de}});Et.getState().setTasks(n,me,"task")}).catch(()=>{}),()=>{$=!0}},[n]);const ee=o.useCallback(($,ne,he,te,me,de)=>{if(!n)return;const D=te||de?{...te?{mentions:te,mentionDeliveryMode:me}:{},...de?{display:de}:{}}:void 0;r(n,$,ne,he,D)},[r,n]),le=o.useCallback(async $=>{const ne=n;if(!ne)return;const he=`shell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,te=Date.now();pe.getState().addMessage(ne,{id:he,type:"user",content:`!${$}`,timestamp:te,noTruncate:!0,shellRun:{command:$,stdout:"",stderr:"",exitCode:null,durationMs:0,running:!0}});const de=await ve.shell.exec($,N),D=de.success&&de.data?{...de.data,running:!1}:{command:$,stdout:"",stderr:"",exitCode:null,durationMs:Date.now()-te,running:!1,error:de.error||re("chat.shellRequestFailedGeneric")};pe.getState().updateMessage(ne,he,{shellRun:D})},[n,N,re]),w=o.useCallback($=>{n&&g&&g(n,$)},[g,n]),K=o.useCallback($=>{n&&y&&y(n,$)},[y,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(Vu,{}),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":re("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 ${Q==="trajectory"?"translate-x-full bg-accent-blue/20 ring-accent-blue/40":"translate-x-0 bg-dark-hover ring-dark-border"}`}),Nh.map(({mode:$,Icon:ne,labelKey:he})=>{const te=Q===$;return e.jsxs("button",{type:"button",role:"radio","aria-checked":te,title:re("trajectory.viewToggleTitle"),onClick:()=>J($),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 ${te?"text-dark-text":"text-dark-muted hover:text-dark-text"}`,children:[e.jsx(ne,{size:11}),re(he)]},$)})]})}),e.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col ${ie&&Q==="chat"?"justify-center overflow-y-auto custom-scrollbar py-2 max-md:justify-start":""}`,children:[Q==="chat"?e.jsx(e.Fragment,{children:ie?e.jsx(mh,{}):e.jsxs(e.Fragment,{children:[e.jsx(vc,{messages:j,isGenerating:L,isPaused:H,sessionId:W.id,onRegenerate:g?w:void 0,onDeleteMessage:y?K:void 0,onOpenSidebarView:R}),e.jsx(Gu,{isOpen:!!I,onCloseModal:E}),e.jsx(Wu,{isOpen:!!F,onClose:G??(()=>{})}),S&&e.jsx(wh,{sessionId:W.id,defaultExpanded:!1,onClose:k},W.id)]})}):e.jsx(Ld,{sessionId:W.id,messages:j,errorLogs:B,onOpenLogs:M}),e.jsx(e.Fragment,{children:e.jsx(Hu,{activeSessionId:W.id})}),e.jsx(Bu,{sessionId:W.id,onSend:ee,onRunShell:le,onStop:()=>a(W.id),onPause:()=>i(W.id),onResume:()=>l(W.id),slashOptions:V,workspaceDir:N,onWorkspaceSelect:P,focusRequest:T}),Q==="chat"&&ie&&e.jsx(bh,{sessionId:W.id,onStartTemplate:z})]})]})]})})});export{_h as SessionGrid};