@deepseekcode/cli 1.0.37 → 1.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/package.json +9 -9
- package/web/dist/assets/AssistantsView-Bh6ajWIo.js +1 -0
- package/web/dist/assets/AutomationView-D2Z-_4qe.js +1 -0
- package/web/dist/assets/{ChannelConfigView-JDljUn42.js → ChannelConfigView-DlakOI5z.js} +5 -5
- package/web/dist/assets/ConnectorsView-ELXDmM9m.js +1 -0
- package/web/dist/assets/FileTreeView-Ciq1vhTf.js +11 -0
- package/web/dist/assets/HookConfigView-DR8TP3QG.js +1 -0
- package/web/dist/assets/ModelsView-BW6eRUwf.js +1 -0
- package/web/dist/assets/PluginsView-CrHGk_JC.js +1 -0
- package/web/dist/assets/SessionGrid-DYYsm2dT.js +52 -0
- package/web/dist/assets/SettingsModal-DNxIKsKC.js +10 -0
- package/web/dist/assets/SkillsView-DS0nnKig.js +1 -0
- package/web/dist/assets/TemplatesTab-pXElHCnz.js +1 -0
- package/web/dist/assets/{ThreeScene-CMqkpyKO.js → ThreeScene-DFL_qzB1.js} +1 -1
- package/web/dist/assets/ToolsView-Bk4hckku.js +1 -0
- package/web/dist/assets/{icons-f1hlMKvD.js → icons-YJcunJnw.js} +195 -140
- package/web/dist/assets/index-CtPliI0f.css +1 -0
- package/web/dist/assets/index-D1N4vQ9I.js +591 -0
- package/web/dist/assets/{markdown-DEtuzEyz.js → markdown-CrVimah5.js} +1 -1
- package/web/dist/assets/{panels-Bn-2wCur.js → panels-BykQW6E1.js} +1 -1
- package/web/dist/assets/{react-vendor-ClBKp0t-.js → react-vendor-DM-M1fu_.js} +1 -1
- package/web/dist/assets/{state-xD58vmym.js → state-D8omNTWe.js} +1 -1
- package/web/dist/assets/sttLanguages-D4JbRJc6.js +1 -0
- package/web/dist/index.html +7 -7
- package/web/dist/assets/AssistantsView-OMdgsTIj.js +0 -1
- package/web/dist/assets/AutomationView-BPwjLbkL.js +0 -1
- package/web/dist/assets/ConnectorsView-AemNT1Ae.js +0 -1
- package/web/dist/assets/FileTreeView-DYx-0jFV.js +0 -11
- package/web/dist/assets/HookConfigView-CS1QqgPx.js +0 -1
- package/web/dist/assets/ModelsView-B3nHezvJ.js +0 -1
- package/web/dist/assets/PluginsView-C4Xc70ec.js +0 -1
- package/web/dist/assets/SessionGrid-C9-LeJH0.js +0 -47
- package/web/dist/assets/SettingsModal-CjWT1C66.js +0 -4
- package/web/dist/assets/SkillsView-DTZyXald.js +0 -1
- package/web/dist/assets/TemplatesTab-CE-CfCf2.js +0 -1
- package/web/dist/assets/ToolsView-CrEHDTEO.js +0 -1
- package/web/dist/assets/index-BCHbHIbw.css +0 -1
- package/web/dist/assets/index-u1vYyqna.js +0 -592
- package/web/dist/assets/sttLanguages-BNRptAQA.js +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ThreeScene-DFL_qzB1.js","assets/markdown-CrVimah5.js","assets/icons-YJcunJnw.js","assets/ThreeScene-DvOrMIoG.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
var ga=Object.defineProperty;var ba=(s,t,n)=>t in s?ga(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n;var Ft=(s,t,n)=>ba(s,typeof t!="symbol"?t+"":t,n);import{j as e}from"./markdown-CrVimah5.js";import{a as i,b2 as ka,s as Rs,q as qs,t as Ks,m as Pe,L as Te,aw as va,ax as Ws,b3 as ja,b4 as ya,_ as wa,ae as Zt,d as Ut,ah as hr,b5 as mr,E as Us,aB as wt,f as Ke,X as Ae,b6 as Ds,b as Gt,A as ze,v as Jt,a3 as Gs,a2 as _s,aZ as Js,D as Na,aM as Sa,b7 as zs,b8 as Ma,j as Nt,aC as Ca,Y as $s,b9 as Vs,ap as Mt,C as xr,ag as Le,ar as Ea,aH as fr,ba as Ta,bb as Aa,ak as Ia,bc as Ra,am as Da,aP as wn,bd as _a,an as Nn,K as za,aG as $a,be as Oa,bf as Sn,l as pr,F as gr,T as Xs,bg as Pa,bh as br,aq as Qs,ao as La,au as Fa,bi as Ba,bj as Ha,bk as qa,bl as Ka,i as Wa,Z as Ua,z as Ga,bm as Ja,bn as ot,a7 as Va,aO as Xa,ac as Qa,aJ as Ya,bo as Za,bp as eo,x as to,bq as so,U as no,V as ro,w as ao,ab as oo,br as io}from"./icons-YJcunJnw.js";import{d as ue,u as Y,r as Mn,e as lo,g as Ct,D as co,i as Ys,h as Ze,t as ne,j as kr,a as ge,k as es,l as ct,o as ts,m as it,R as uo,n as St,p as vr,w as je,q as Os,b as Ee,s as jr,v as yr,x as ho,y as mo,z as xo,A as fo,E as wr,F as Vt,G as me,H as po,J as go,K as Nr,L as bo,N as Sr,O as Cn,W as ko,Q as Ps,S as Ls,c as jt,T as Mr,U as vo,V as jo,X as yo,Y as wo,Z as No,_ as So,$ as Mo,M as Co,a0 as Eo,a1 as To,a2 as Ao,a3 as Io,a4 as Ro,a5 as Do,a6 as _o,a7 as Cr,a8 as zo,a9 as $o,aa as Bt,ab as Oo,ac as Po}from"./index-D1N4vQ9I.js";import{r as Lo,p as Fo,s as Bo,S as Ho,n as qo}from"./sttLanguages-D4JbRJc6.js";import{c as Ko}from"./state-D8omNTWe.js";import"./react-vendor-DM-M1fu_.js";import"./panels-BykQW6E1.js";const Wo=800,yt=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g;let Uo=0;const Et=new Map;function Er(s){const t=++Uo;return Et.set(t,s.replace(/\r\n?/g,`
|
|
3
|
+
`)),t}function Go(s){return Et.get(s)}function Jo(s){Et.delete(s)}function Vo(s){return s.length>Wo||Zs(s)>0}function Zs(s){return(s.match(/\r\n|\r|\n/g)||[]).length}function Xo(s){const t=Er(s),n=Zs(s);return n===0?{id:t,label:`[Pasted text #${t}]`}:{id:t,label:`[Pasted text #${t} +${n} lines]`}}function Qo(s){return yt.lastIndex=0,s.replace(yt,(t,n)=>{const r=parseInt(n,10),a=Et.get(r);return a!==void 0?a:t})}function Yo(s){yt.lastIndex=0;const t=[];let n;for(;(n=yt.exec(s))!==null;){const r=n[1];r!==void 0&&t.push(parseInt(r,10))}return yt.lastIndex=0,t}function Zo(s){for(const t of s)Et.delete(t)}function ei(s){const t=s.match(/\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]$/);return t?t[0]:null}function ti(s){const t=s.match(/^\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]/);return t?t[0]:null}function En(s){const t=s.match(/#(\d+)/);t&&Jo(parseInt(t[1]??"",10))}function Tn({value:s,max:t=100,size:n="md",variant:r="default",showLabel:a=!1,className:o}){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:ue("w-full",o),children:[e.jsx("div",{className:ue("w-full bg-dark-border rounded-full overflow-hidden",c[n]),children:e.jsx("div",{className:ue("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 si(s){const t=i.useRef(null),n=i.useRef(0);return i.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 o=setInterval(a,1e3);return()=>clearInterval(o)},[s]),t}function we(s,t){let n=null;if(typeof s=="string")try{const r=JSON.parse(s);r&&typeof r=="object"&&!Array.isArray(r)&&(n=r)}catch{return""}else s&&typeof s=="object"&&!Array.isArray(s)&&(n=s);if(!n)return"";for(const r of t){const a=n[r];if(typeof a=="string"&&a)return a}return""}function Fe(s){return typeof s=="string"?s:s&&typeof s=="object"?JSON.stringify(s,null,2):String(s??"")}function ni(s){for(const t of s.split(`
|
|
4
|
+
`)){const n=t.trim();if(n)return n}return""}function _e({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 ri({toolCall:s}){const{t}=Y(),n=we(s.args,["command","cmd","script"]),r=s.status==="error",a=s.status==="running",o=Fe(s.result),l=a&&!o&&s.liveOutput||"";return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[n&&e.jsx(_e,{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(_e,{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(_e,{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:o})})]})}function ai({toolCall:s}){const t=Ct(s.args),n=Fe(s.result),r=s.diff||(n&&(n.includes("@@")||n.includes("+++")||n.includes("---"))?n:void 0);return!r&&!n?e.jsx(Tr,{toolCall:s}):e.jsx("div",{className:"px-2 py-1",children:e.jsx(co,{filePath:t,content:r||n})})}function oi({toolCall:s}){const{t}=Y(),n=Ct(s.args),r=s.status==="error",a=Fe(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(_e,{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 An=20,ii=/\b(grep|search_contents)\b/i;function li(s){return s===""?0:s.split(`
|
|
5
|
+
`).length}function ci({toolCall:s}){const{t}=Y(),n=we(s.args,["pattern","query","regex"]),r=s.status==="error",a=s.result!==void 0&&s.result!==null,o=a?Fe(s.result):"",l=a?li(o):0,c=ii.test(s.name),d=s.noTruncate!==!0&&c&&a&&!r&&l>An,[h,f]=i.useState(!1),u=d&&!h?o.split(`
|
|
6
|
+
`).slice(0,An).join(`
|
|
7
|
+
`)+`
|
|
8
|
+
${t("toolCall.linesTotal",{n:l})}`:o;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(_e,{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:u})}),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:h?t("toolCall.collapse"):t("toolCall.expandAll",{n:l})})})]})}function di({toolCall:s}){const{t}=Y(),n=we(s.args,["url","query"]),r=s.status==="error",a=Fe(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(_e,{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 Tr({toolCall:s}){const{t}=Y(),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(_e,{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(_e,{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:Fe(s.result)})})]})}function ui({toolCall:s}){const{t}=Y(),n=s.status==="error",r=Fe(s.result),a=(s.attachments??[]).filter(o=>o.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((o,l)=>e.jsx("img",{src:o.url,alt:o.filename??`computer screenshot ${l+1}`,className:"block w-full object-contain",loading:"lazy"},l))})]}),s.result!==void 0&&s.result!==null&&e.jsx(_e,{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})})]})}function hi({toolCall:s}){const{t}=Y(),n=s.status==="error",r=Fe(s.result),a=(s.generatedImages??[]).filter(c=>c.length>0),[o,l]=i.useState(null);return e.jsxs("div",{className:"space-y-0.5 py-0.5",children:[a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 px-2 pt-1",children:a.map((c,d)=>e.jsx("button",{onClick:()=>l(Mn(c)),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:Mn(c),alt:`generated image ${d+1}`,loading:"lazy",className:"h-28 w-auto max-w-[220px] object-cover"})},`${c}-${d}`))}),s.result!==void 0&&s.result!==null&&e.jsx(_e,{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})}),o&&e.jsx(lo,{src:o,alt:t("fileJob.imagePreview"),onClose:()=>l(null)})]})}const mi=/(?:^|[_\W])(bash|powershell|pwsh|cmd|command|shell|exec|terminal)(?:[_\W]|$)/i,xi=/(?:^|[_\W])(read|cat|view|open)(?:[_\W]|$)/i,fi=/(?:^|[_\W])(grep|glob|search|find|list)(?:[_\W]|$)/i,pi=/(?:^|[_\W])(webfetch|websearch|fetch|web|http|curl|url)(?:[_\W]|$)/i,gi=/(?:^|[_\W])(computer)(?:[_\W]|$)/i,bi=/^agent$/i,ki=/generate[-_]?image|imagegen|create[-_]?image/i;function en(s){return bi.test(s)?"agent":ki.test(s)?"image":Ys(s)?"diff":mi.test(s)?"terminal":gi.test(s)?"computer":pi.test(s)?"web":fi.test(s)?"search":xi.test(s)?"read":"generic"}function vi(s,t){const n=en(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 o=r,l=o==="type"||o==="key"?we(t,["text"]):o==="focus"?we(t,["keyword"]):o==="scroll"?we(t,["direction"]):"";r=l?`${o} ${l}`:o}break;case"diff":case"read":r=Ct(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 o=typeof t=="string"?JSON.parse(t):t;r=o&&typeof o=="object"?JSON.stringify(o):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 ji({toolCall:s}){switch(en(s.name)){case"terminal":return e.jsx(ri,{toolCall:s});case"diff":return e.jsx(ai,{toolCall:s});case"read":return e.jsx(oi,{toolCall:s});case"search":return e.jsx(ci,{toolCall:s});case"web":return e.jsx(di,{toolCall:s});case"computer":return e.jsx(ui,{toolCall:s});case"image":return e.jsx(hi,{toolCall:s});default:return e.jsx(Tr,{toolCall:s})}}function yi(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 wi=s=>s==="completed"||s==="failed"||s==="paused";function In(s){return s==="paused"?"bg-amber-400":s==="completed"?"bg-accent-green":s==="failed"?"bg-accent-red":"bg-accent-blue"}function Ni({status:s}){return s==="paused"?e.jsx(qs,{size:10,className:"text-amber-400","aria-hidden":"true"}):s==="failed"?e.jsx(Ks,{size:10,className:"text-accent-red","aria-hidden":"true"}):s==="completed"?e.jsx(Pe,{size:10,className:"text-accent-green","aria-hidden":"true"}):e.jsx(Te,{size:10,className:"animate-spin text-accent-blue","aria-hidden":"true"})}function Rn(s){if(s==="paused")return"已暂停";if(s==="completed")return"已完成";if(s==="failed")return"已失败";if(s==="scheduled")return"排队中";if(s==="idle")return"待启动"}const Dn="立即返回结果",_n="终止并返回结果";function Ar(s){return`subagent-card-${s}`}const zn=["ring-2","ring-accent-blue"];function Si(s){if(typeof document>"u")return!1;const t=document.getElementById(Ar(s));return t?(t.scrollIntoView({behavior:"smooth",block:"center"}),t.classList.add(...zn),window.setTimeout(()=>t.classList.remove(...zn),1600),!0):!1}function Ir({agent:s,labeled:t=!1}){const[n,r]=i.useState(!1);if(!(s.status==="running"||s.status==="scheduled"||s.status==="paused"))return null;const o=async(l,c)=>{r(!0);try{await l()}catch(d){const h=d instanceof Error?d.message:String(d);ne.error(`${c}失败: ${h.slice(0,120)}`,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":Dn,disabled:n,onClick:l=>{l.stopPropagation(),o(()=>ge.agentRuns.stop(s.id),"立即返回")},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(ka,{size:11}),t&&e.jsx("span",{children:Dn})]}),e.jsxs("button",{type:"button",title:"立刻终止这个子代理,并把它已经拿到的结果交回父代理","aria-label":_n,disabled:n,onClick:l=>{l.stopPropagation(),o(()=>ge.agentRuns.kill(s.id),"终止")},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(Rs,{size:11}),t&&e.jsx("span",{children:_n})]})]})}const Mi=i.memo(function({agent:t}){kr();const n=wi(t.status),r=t.elapsedMs===void 0?void 0:!n&&t.elapsedAt?t.elapsedMs+Math.max(0,Date.now()-t.elapsedAt):t.elapsedMs,a=typeof t.round=="number"&&t.round>0&&typeof t.maxRounds=="number"&&t.maxRounds>0,o=a?Math.max(0,Math.min(100,Math.round(t.round/t.maxRounds*100))):0,l=[t.round!==void 0?t.maxRounds?`Turn ${t.round}/${t.maxRounds}`:`Turn ${t.round}`:"",t.currentTool&&t.status!=="completed"?`⚙ ${t.currentTool}`:"",r!==void 0?yi(r):""].filter(Boolean);return e.jsxs("div",{id:t.toolCallId?Ar(t.toolCallId):void 0,className:"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(Ni,{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}),Rn(t.status)&&e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted",children:Rn(t.status)}),e.jsx(Ir,{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":a?o:void 0,"aria-label":t.name,children:a?e.jsx("div",{className:`h-full rounded-full transition-[width] duration-500 ease-out ${In(t.status)}`,style:{width:`${o}%`}}):e.jsx("div",{className:`h-full w-1/4 animate-pulse rounded-full ${In(t.status)}`})})}),l.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:l.join(" · ")})})]})}),Ci=i.memo(function({sessionId:t,toolCallId:n,scope:r}){const a=Ze(l=>t?l.agentsBySession[t]:void 0),o=i.useMemo(()=>t&&a?Ze.getState().getAgentByToolCallId(t,n,r):void 0,[t,n,r,a]);return o?e.jsx(Mi,{agent:o}):null}),Ei=/^agent$/i;function Ti(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 Ai(){const s=it(t=>t.tokenRate);return e.jsx(uo,{size:12,rate:s})}const Ii={terminal:mr,diff:hr,read:Ut,search:Zt,web:wa,computer:ya,image:ja,agent:Ws,generic:va},Ri=i.memo(function({toolCall:t,defaultCollapsed:n=!0,sessionId:r}){const a=t.status==="running",o=Ei.test(t.name)&&!!r,l=o?Ti(t.args):void 0,c=si(a),d=t.result!==void 0&&t.result!==null,h=t.status==="error",f=Ys(t.name),u=d?Fe(t.result):"",p=Ct(t.args),{openFileMenu:g,menuNode:j}=es(),w=vi(t.name,t.args),b=h&&d?ni(u):"",[x,y]=i.useState(n),D=i.useRef(t.status);i.useEffect(()=>{D.current==="running"&&t.status!=="running"&&(t.diff||t.name==="exit_plan_mode"||y(!0)),D.current=t.status},[t.status,t.diff,t.name]);const C=ct(t.duration),M=a?"bg-accent-blue":h?"bg-accent-red":"bg-accent-green",_=a?"running":h?"error":"success",K=Ii[en(t.name)];return e.jsxs("div",{className:"tl-row group rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"toolcall-row",children:[e.jsx("span",{className:"tl-line","aria-hidden":"true"}),e.jsxs("div",{className:"relative flex items-center gap-2 px-2 py-1 cursor-pointer select-none",onClick:()=>y(!x),"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(Ai,{}):e.jsx("span",{className:`tl-node ${M}`,"data-status":_})}),e.jsx("span",{className:`shrink-0 ${h?"text-accent-red":"text-dark-muted"}`,children:e.jsx(K,{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}),h&&b?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:u,children:b})]}):w?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:w,children:w})]}):e.jsx("span",{className:"min-w-0 flex-1"}),f&&p&&!h&&e.jsxs("button",{type:"button",onClick:S=>{S.stopPropagation(),ts(p)},onContextMenu:S=>g(S,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
|
|
9
|
+
transition-colors hover:border-accent-blue/40 hover:bg-dark-hover`,title:p,children:[e.jsx(Us,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:p})]}),a&&!o&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[11px] tabular-nums text-accent-blue",children:[e.jsx(wt,{size:10}),e.jsx("span",{ref:c,children:"0s"})]}),!a&&C&&!o&&e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-[10px] tabular-nums text-dark-muted",children:[e.jsx(wt,{size:10}),e.jsx("span",{children:C})]}),e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${x?"opacity-0 group-hover:opacity-100":"rotate-180"}`,children:e.jsx(Ke,{size:13})})]}),o&&e.jsx(Ci,{sessionId:r,toolCallId:t.id,scope:l}),!x&&e.jsx("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25",children:e.jsx(ji,{toolCall:t})}),j]})});function Rr(s){const t=s??"";let n=t,r=null,a=null;try{const o=JSON.parse(t);if(o&&typeof o=="object")if("payload"in o){a=typeof o.toolName=="string"?o.toolName:null;const l=o.payload;typeof l=="string"?n=l:l&&typeof l=="object"?(r=l,n=JSON.stringify(l,null,2)):n=""}else Array.isArray(o)||(r=o)}catch{n=t}if(!r&&n.length>0&&/^[\s]*[{[]/.test(n))try{const o=JSON.parse(n);o&&typeof o=="object"&&!Array.isArray(o)&&(r=o)}catch{}return{toolName:a,payloadText:n,args:r}}const tn=/\b(bash|shell|exec|cmd|powershell|terminal)\b/i,Dr=/write_file|write|save|create|upload|deploy|publish/i,_r=/edit_file|edit|patch|apply|update|replace/i,zr=/read_file|read|view|cat|open|list|dir\b/i,Di=/file_delete|delete|remove|unlink|\brm\b|\bdel\b/i,_i=/\b(glob|find|locate)\b/i,zi=/\b(grep|rg|search_contents)\b/i,$i=/web_search|search_web|browse/i,$r=/web_fetch|fetch|http|curl|wget|download|request|api/i,Oi=/git|commit|merge|rebase|push|checkout/i,Pi=/install|uninstall|npm|pnpm|yarn|pip|cargo|gem|apt|brew|choco/i,sn=/send_message|send_file|message|notify|post/i;function Or(s){const t=s.toLowerCase();return tn.test(t)?"verbRunCommand":$i.test(t)?"verbSearchWeb":Dr.test(t)?"verbWriteFile":_r.test(t)?"verbEditFile":Di.test(t)?"verbDeleteFile":zr.test(t)?"verbReadFile":zi.test(t)?"verbSearchContents":_i.test(t)?"verbFindFiles":$r.test(t)?"verbFetchUrl":Oi.test(t)?"verbGit":Pi.test(t)?"verbInstall":sn.test(t)?"verbSendMessage":"verbRunTool"}function xs(s,t){const n=(s??"").replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t-1)}…`:n}function Li(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 Pr(s,t){const{payloadText:n,args:r}=Rr(t),a=s.toLowerCase();if(tn.test(a))return"";const o=Li(r);if(o)return o;const l=n.match(/(?:file_path|path|file)["\s:=]+([^\s",}]+)/i);if(l!=null&&l[1])return l[1];if($r.test(a)&&typeof(r==null?void 0:r.url)=="string"&&r.url)return xs(r.url,48);if(sn.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 xs(c,48)}return xs(n,48)}function Lr(s,t){const{payloadText:n,args:r}=Rr(t),a=s.toLowerCase();if(tn.test(a)){const o=typeof(r==null?void 0:r.command)=="string"?r.command:n;return o?{text:o,mono:!0}:null}if(Dr.test(a)||_r.test(a)){const o=typeof(r==null?void 0:r.content)=="string"?r.content:typeof(r==null?void 0:r.data)=="string"?r.data:"";if(o)return{text:o,mono:!0};if(r){const l=$n(r);if(l)return{text:l,mono:!0}}return n?{text:n,mono:!0}:null}if(sn.test(a)){const o=typeof(r==null?void 0:r.text)=="string"?r.text:typeof(r==null?void 0:r.message)=="string"?r.message:n;return o?{text:o,mono:!1}:null}if(zr.test(a))return null;if(r){const o=$n(r);if(o)return{text:o,mono:!0}}return n?{text:n,mono:!0}:null}function $n(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 Fr(s,t){const n=St(t);return n?{path:n,external:!0}:{key:"scopeLocal",external:!1}}function Br({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 fs=5,ps=420;function Fs({text:s,mono:t=!0}){const{t:n}=Y("hook"),[r,a]=i.useState(!1),o=s.split(`
|
|
10
|
+
`),l=o.length>fs||s.length>ps;let c=s;!r&&l&&(c=o.slice(0,fs).join(`
|
|
11
|
+
`),c.length>ps&&(c=`${c.slice(0,ps).trimEnd()}…`));const d=r?n("showLess"):o.length>fs?n("showAllLines",{n:o.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(h=>!h),className:"mt-1 block text-[11px] text-accent-blue hover:underline",children:d})]})}const gs=15,Fi=i.memo(function({approval:t,onResolved:n}){const{t:r}=Y("hook"),[a,o]=i.useState(!1),[l,c]=i.useState(gs),d=i.useRef(null),h=t.status==="pending",{level:f,reasonKey:u}=vr(t.toolName,t.askPayload),p=jr[f],g=Lr(t.toolName,t.askPayload),j=Fr(t.toolName,t.askPayload),w=St(t.askPayload)!==null;i.useEffect(()=>{if(h)return c(gs),d.current=setInterval(()=>{c(S=>S<=1?(d.current&&clearInterval(d.current),0):S-1)},1e3),()=>{d.current&&clearInterval(d.current)}},[h,t.approvalId]),i.useEffect(()=>{const S=(t.timeoutMs??15e3)>0;l===0&&h&&!a&&S&&b()},[l]);const b=i.useCallback(()=>{!h||a||(o(!0),d.current&&clearInterval(d.current),je.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),n==null||n(t.approvalId,"approved"))},[h,a,t.approvalId,n]),x=i.useCallback(()=>{!h||a||(o(!0),d.current&&clearInterval(d.current),je.send({type:"hook_deny",data:JSON.stringify({approvalId:t.approvalId})}),n==null||n(t.approvalId,"denied"))},[h,a,t.approvalId,n]),y=i.useCallback(()=>{if(!h||a)return;o(!0),d.current&&clearInterval(d.current);const S=Os.getState(),z=St(t.askPayload);z?(S.addToSessionAllowList(t.toolName,z),je.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId,sessionAllow:!0})})):(S.addToSessionAllowList(t.toolName),je.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})})),n==null||n(t.approvalId,"approved")},[h,a,t.approvalId,t.toolName,t.askPayload,n]),D=i.useCallback(()=>{!h||a||(o(!0),d.current&&clearInterval(d.current),Os.getState().setAutoMode(!0),Ee.getState().setAuto(!0),je.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),n==null||n(t.approvalId,"approved"))},[h,a,t.approvalId,n]);if(!h){const S=t.status==="approved";return e.jsx("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${S?"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:S?e.jsxs(e.Fragment,{children:[e.jsx(Pe,{size:14}),e.jsxs("span",{children:[r("alreadyAllowed"),t.toolName]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ae,{size:14}),e.jsxs("span",{children:[r("alreadyDenied"),t.toolName]})]})})}const C=l/gs*100,M=l<=5,_=[{id:"allow",index:1,label:r("optionAllow"),hint:r("optionAllowHint"),action:b,kind:"primary"},{id:"allow_session",index:3,label:r("optionAllowAlways"),hint:w?r("optionAllowPathHint"):r("optionAllowAlwaysHint",{tool:t.toolName}),action:y,kind:"secondary"},{id:"auto_mode",index:4,label:r("optionAutoMode"),hint:r("optionAutoModeHint"),action:D,kind:"secondary"},{id:"deny",index:2,label:r("optionDeny"),hint:r("optionDenyHint"),action:x,kind:"danger"}],K={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 ${j.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} ${j.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(Ds,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Br,{pre:r(Or(t.toolName)),obj:Pr(t.toolName,t.askPayload)})}),j.external&&j.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:j.path,children:[e.jsx(Gt,{size:10}),j.path.length>32?`${j.path.slice(0,31)}…`:j.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(wt,{size:11,className:M?"text-accent-red":"text-dark-muted"}),e.jsxs("span",{className:`text-[11px] font-mono ${M?"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 ${M?"bg-accent-red":l<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${C}%`}})})]})]}),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(u)})]}),g&&e.jsx(Fs,{text:g.text,mono:g.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(ze,{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:_.map(S=>e.jsxs("button",{onClick:S.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 ${K[S.kind]}`,children:[e.jsx("span",{className:`text-[9px] font-mono rounded px-0.5 ${S.kind==="primary"?"bg-white/20":"bg-dark-surface text-dark-muted"}`,children:S.index}),e.jsx("span",{children:S.label}),e.jsx("span",{className:`text-[10px] ${S.kind==="primary"?"text-white/70":"text-dark-muted/60"} hidden sm:inline`,children:S.hint})]},S.id))}),e.jsx("div",{className:"text-[10px] text-dark-muted/50 pt-0.5 border-t border-dark-border/50",children:r("clickToSelect")})]})]})}),Ht={xlsx:{icon:_s},xls:{icon:_s},csv:{icon:Ut},docx:{icon:Ut},text:{icon:Gs}};function On(s){return!s&&s!==0?"—":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/1024/1024).toFixed(2)} MB`}const Bi=i.memo(function({job:t}){var j,w;const{t:n}=Y(),{stage:r}=t,{openFileMenu:a,menuNode:o}=es(),l=i.useCallback(b=>{switch(b){case"xlsx":case"xls":return"Excel";case"csv":return"CSV";case"docx":return"Word";default:return n("fileJob.kindText")}},[n]),c=i.useCallback(b=>{ge.files.download(b).then(x=>{x.success||ne.error(x.error||n("fileJob.downloadFailed"))})},[n]),d=i.useMemo(()=>t.attachments||[],[t.attachments]),h=i.useMemo(()=>t.parsedFiles||[],[t.parsedFiles]),f=i.useMemo(()=>t.mapping||[],[t.mapping]),u=i.useMemo(()=>t.result||[],[t.result]),p=t.renderProgress??(r==="rendering"?0:100),g=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(Jt,{size:15,className:"text-accent-green shrink-0"}):r==="error"?e.jsx(ze,{size:15,className:"text-accent-red shrink-0"}):e.jsx(Te,{size:15,className:"text-accent-blue animate-spin shrink-0"}),e.jsx("span",{className:"text-[13px] font-medium text-dark-text",children:Hi(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((b,x)=>{const D=(Ht[b.kind]||Ht.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(D,{size:14,className:"text-accent-blue shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs text-dark-text truncate max-w-[160px]",children:b.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[On(b.size)," · ",l(b.kind),b.role&&b.role!=="unknown"&&e.jsxs("span",{className:ue("ml-1",b.role==="data"?"text-accent-green":"text-accent-purple"),children:["· ",b.role==="data"?n("fileJob.roleData"):n("fileJob.roleTemplate")]})]})]})]},`${b.fileName}-${x}`)})}),r==="parsing"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:n("fileJob.parsing",{file:((j=d[0])==null?void 0:j.fileName)||((w=h[0])==null?void 0:w.fileName)||""})}),e.jsx(Tn,{value:g,size:"sm",showLabel:!0})]}),h.length>0&&r!=="error"&&e.jsxs("div",{className:"space-y-1.5",children:[h.map(b=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(Jt,{size:13,className:"text-accent-green shrink-0"}),e.jsx("span",{className:"truncate",children:b.fileName}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:n("fileJob.parsedSummary",{rows:b.rowCount,fields:b.fields.length})})]},b.fileName)),h[0]&&e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[h[0].fields.slice(0,12).map(b=>e.jsx("span",{className:"rounded bg-dark-bg border border-dark-border/60 px-1.5 py-0.5 text-[10px] font-mono text-dark-muted",children:b},b)),h[0].fields.length>12&&e.jsxs("span",{className:"text-[10px] text-dark-muted/60",children:["+",h[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(b=>e.jsxs("tr",{className:"border-t border-dark-border/50",children:[e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-purple",children:"{{"+b.placeholder+"}}"}),e.jsx("td",{className:"px-2 py-1.5 text-dark-muted",children:e.jsx(Js,{size:11})}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-blue",children:b.field})]},b.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(Tn,{value:p,size:"sm",variant:"warning",showLabel:!0})]}),u.length>0&&r==="complete"&&e.jsx("div",{className:"space-y-1.5",children:u.map(b=>{const y=(Ht[b.format]||Ht.text).icon,D=b.failedRows.length>0;return e.jsxs("div",{onContextMenu:C=>a(C,b.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:b.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[On(b.size)," · ",n("fileJob.rowsDone",{done:b.successCount,total:b.rowCount}),D&&e.jsxs("span",{className:"text-accent-red",children:[" · ",n("fileJob.rowsFailed",{n:b.failedRows.length})]})]})]}),e.jsxs("button",{onClick:()=>ts(b.path),className:"flex items-center gap-1 rounded-md bg-dark-surface border border-dark-border text-dark-muted px-2 py-1 text-[11px] hover:bg-dark-hover hover:text-dark-text transition-colors",title:n("chat.previewInPanel"),children:[e.jsx(Us,{size:12}),n("chat.previewInPanel")]}),e.jsxs("button",{onClick:()=>c(b.path),className:"flex items-center gap-1 rounded-md bg-accent-blue/10 text-accent-blue px-2 py-1 text-[11px] hover:bg-accent-blue/20 transition-colors",title:n("fileJob.download"),children:[e.jsx(Na,{size:12}),n("fileJob.download")]})]}),D&&e.jsxs("div",{className:"mt-1.5 space-y-0.5 border-t border-dark-border/50 pt-1.5",children:[b.failedRows.slice(0,3).map(C=>e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-accent-red",children:[e.jsx(Ks,{size:10,className:"shrink-0"}),e.jsxs("span",{children:["#",C.index+1]}),e.jsx("span",{className:"truncate",children:C.error})]},C.index)),b.failedRows.length>3&&e.jsx("div",{className:"text-[10px] text-dark-muted/70",children:n("fileJob.moreRows",{n:b.failedRows.length-3})})]})]},b.path)})}),r==="error"&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-accent-red/30 bg-accent-red/5 px-3 py-2.5",children:[e.jsx(ze,{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})]})]})]}),o]})});function Hi(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 Pn={auth:{icon:Ma,color:"text-accent-red"},rate_limit:{icon:zs,color:"text-accent-yellow"},timeout:{icon:zs,color:"text-accent-yellow"},network:{icon:Sa,color:"text-accent-yellow"},model:{icon:Ws,color:"text-accent-red"},tool:{icon:ze,color:"text-accent-yellow"},unknown:{icon:ze,color:"text-accent-red"}},qi=i.memo(function({error:t,onRetry:n}){const{t:r}=Y(),[a,o]=i.useState(!1),l=Pn[t.category]||Pn.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:ue("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(Nt,{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(Ca,{size:11}),r("errorCard.modelSettings")]}),t.detail&&e.jsxs("button",{onClick:()=>o(h=>!h),className:"flex items-center gap-0.5 text-[11px] text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(Ke,{size:11,className:ue("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 Ki({info:s}){const{t}=Y(),n=s.stdout.length>0,r=s.stderr.length>0,a=n||r,o=!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(Te,{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(`
|
|
12
|
+
`)?"":`
|
|
13
|
+
`:"",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(ze,{size:11,"aria-hidden":"true"}),t("chat.shellRequestFailed",{message:s.error})]}):e.jsx("span",{className:o?"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:ct(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 bs=360,ks=300,Wi=180,Oe=8;function nn({src:s,alt:t,children:n,className:r}){const a=i.useRef(null),o=i.useRef(null),[l,c]=i.useState(null),d=i.useCallback(()=>{o.current!==null&&(window.clearTimeout(o.current),o.current=null)},[]),h=i.useCallback(()=>{d(),o.current=window.setTimeout(()=>{var g;o.current=null;const p=(g=a.current)==null?void 0:g.getBoundingClientRect();p&&p.width>0&&c(p)},Wi)},[d]),f=i.useCallback(()=>{d(),c(null)},[d]);i.useEffect(()=>()=>d(),[d]),i.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 u=null;if(l){const p=window.innerWidth,g=window.innerHeight,j=l.top>=ks+Oe+Oe,w=j?l.top-Oe:l.bottom+Oe,b=l.left+l.width/2-bs/2,x=Math.max(Oe,Math.min(b,Math.max(Oe,p-bs-Oe))),y=j?w:Math.min(w,Math.max(Oe,g-ks-Oe));u={left:x,top:y,transform:j?"translateY(-100%)":void 0}}return e.jsxs("span",{ref:a,className:ue("inline-flex min-w-0",r),onMouseEnter:h,onMouseLeave:f,onFocus:h,onBlur:f,children:[n,l&&u&&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:u,children:e.jsx("img",{src:s,alt:t,draggable:!1,className:"block rounded object-contain",style:{maxWidth:bs-8,maxHeight:ks}})})]})}function Ui({src:s,name:t,path:n,size:r=13,className:a,hoverPreview:o=!0}){const{t:l}=Y(),c=i.useCallback(()=>{yr({src:s,name:t,path:n})},[s,t,n]);if(!s)return e.jsx($s,{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:ue("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($s,{size:r,"aria-hidden":"true"})});return o?e.jsx(nn,{src:s,alt:t,className:"shrink-0",children:d}):d}function Gi({src:s,name:t,path:n,className:r}){const{t:a}=Y(),o=i.useCallback(()=>{yr({src:s,name:t,path:n})},[s,t,n]);return e.jsx(nn,{src:s,alt:t,className:r,children:e.jsxs("button",{type:"button",onClick:o,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($s,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:t})]})})}const Ji=/<attachment\s+path="([^"]*)"\s*\/>/g,Vi=/<image\s+name="([^"]*)"\s*\/>/g,Xi=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g,Qi=new RegExp("(?<![\\w@.])@((?:[\\w@.()[\\]{}$%-]+[\\\\/])+[\\w@.()[\\]{}$%-]+|[\\w@.()[\\]{}$%-]*[\\w@()[\\]{}$%-]\\.[A-Za-z0-9]{1,12})","g");function Yi(s){return!s||s.length>400?!1:s.includes("/")||s.includes("\\")?wr(s):/\.[A-Za-z0-9]{1,12}$/.test(s)}function Bs(s){if(!s)return[];const t=[],n=a=>{a&&t.push({kind:"text",value:a})};return s.split(Qi).forEach((a,o)=>{if(o%2===1){Yi(a)?t.push({kind:"mention",value:a}):n(`@${a??""}`);return}a.split(xo).forEach((c,d)=>{if(d%2===1){const{path:h,tail:f}=fo(c);if(h&&wr(h)){t.push({kind:"path",value:h}),n(f);return}}n(c)})}),t}function Zi(s,t){const n=[];let r=0;for(const a of s.matchAll(Xi)){const o=a.index??0,l=Number.parseInt(a[1]??"",10);o>r&&n.push(...Bs(s.slice(r,o)));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=o+a[0].length}return r<s.length&&n.push(...Bs(s.slice(r))),n}function el(s,t){const n=[],r=[];let a=(s||"").replace(Ji,(l,c)=>(c&&n.push(c),"")).replace(Vi,(l,c)=>(c&&r.push(c),""));(n.length>0||r.length>0)&&(a=a.replace(/^(?:[ \t]*\n)+/,"")),a=a.replace(/\n{3,}/g,`
|
|
14
|
+
|
|
15
|
+
`);const o=new Map((t??[]).map(l=>[l.id,l.content]));return{attachments:n,imageNames:r,segments:o.size>0?Zi(a,o):Bs(a)}}function tl({path:s}){const{openFileMenu:t,menuNode:n}=es(),r=s.split(/[\\/]/).pop()||s;return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",title:s,onClick:()=>ts(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(Vs,{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 sl({token:s,content:t}){const{t:n}=Y(),[r,a]=i.useState(!1),[o,l]=i.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(Vs,{size:11,className:"shrink-0 text-dark-muted"}),e.jsx("span",{className:"truncate font-mono text-dark-text",children:s}),r?e.jsx(Mt,{size:11,className:"shrink-0 text-dark-muted"}):e.jsx(Ke,{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:[o?e.jsx(Pe,{size:10}):e.jsx(xr,{size:10}),n(o?"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 nl({content:s,images:t,pastes:n}){const{t:r}=Y(),{openFileMenu:a,menuNode:o}=es(),l=i.useMemo(()=>el(s,n),[s,n]),c=i.useMemo(()=>(t??[]).map((d,h)=>{const f=l.imageNames[h],u=d.startsWith("data:")||d.startsWith("blob:"),p=u?r("fileJob.imageN",{n:h+1}):(d.split(/[?#]/)[0]??"").split(/[\\/]/).pop()||r("fileJob.imageN",{n:h+1});return{key:`${h}-${d.slice(0,48)}`,src:ho(d),name:f||p,path:u?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,h)=>e.jsx(tl,{path:d},`${d}-${h}`)),c.map(d=>e.jsx(Gi,{src:d.src,name:d.name,path:d.path,className:"mr-1 align-middle"},d.key)),l.segments.map((d,h)=>d.kind==="text"?e.jsx("span",{children:d.value},h):d.kind==="paste"?e.jsx(sl,{token:d.value,content:d.content},h):d.kind==="mention"?e.jsxs("button",{type:"button",onClick:()=>ts(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})]},h):e.jsx(mo,{path:d.value},h)),o]})}const Ln=12;function Fn(s){const t=s.slice(0,Ln).join(`
|
|
16
|
+
`),n=s.length-Ln;return n>0?`${t}
|
|
17
|
+
… (${n})`:t}const rl=i.memo(function({created:t,modified:n,onOpenArtifacts:r,onOpenChanges:a}){const{t:o}=Y();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-[11px]","data-testid":"turn-result-footer",children:[t.length>0&&e.jsxs("button",{type:"button",onClick:r,className:l,"data-testid":"turn-result-artifacts",title:Fn(t),children:[o("chat.viewAllArtifacts",{n:t.length}),e.jsx(Le,{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:Fn(n),children:[o("chat.viewAllChanges",{n:n.length}),e.jsx(Le,{size:11,className:"shrink-0 opacity-70"})]})]})});function al(s){for(const t of s.split(`
|
|
18
|
+
`)){const n=t.trim();if(n)return n}return""}function ol(s){var n;const t=s.split(`
|
|
19
|
+
`);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 il({index:s,text:t,isStreaming:n,collapsed:r,onToggle:a}){const{t:o}=Y(),l=r?n?ol(t):al(t):"";return e.jsxs("div",{children:[e.jsxs("button",{className:"flex w-full cursor-pointer select-none items-center gap-1.5 py-0.5 text-left text-xs",onClick:()=>a(s),"data-testid":"thinking-toggle",children:[e.jsx(Le,{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?`${o("chat.thinking")}…`:o("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,`
|
|
20
|
+
|
|
21
|
+
`)})]})}const Hr=5,ll=30,cl=["让我","我先","我现在","我发现","我注意到","我决定","我重新","我重试","我继续","我现在要","让我现在","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 dl(s){const t=s.charCodeAt(0);return t>=19968&&t<=40959}function ul(s){let t="",n=!1;for(const r of s)r===" "||r===" "||r===" "?(n||(t+=" "),n=!0):(t+=r,n=!1);return t}function hl(s){return s>=97&&s<=122||s>=48&&s<=57||s===95}function qr(s){const t=ul(s.trimStart().toLowerCase());return cl.some(n=>{if(!t.startsWith(n))return!1;const r=t[n.length];return r===void 0||dl(n)||n==="i re-"?!0:!hl(r.charCodeAt(0))})}function ml(s){if(!s)return!1;const t=s.split(/\r?\n/).slice(0,ll);let n=0;for(const r of t)if(r.trim())if(qr(r)){if(n++,n>=Hr)return!0}else return!1;return!1}function xl(s,t){if(!s)return{body:s||"",absorbed:""};if(!ml(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(qr(l)){r++,a++;continue}break}if(r<Hr)return{body:s,absorbed:""};let o=0;for(const l of n.slice(0,a)){if(o+=l.length,o>=s.length)break;s.startsWith(`\r
|
|
22
|
+
`,o)?o+=2:(s[o]===`
|
|
23
|
+
`||s[o]==="\r")&&(o+=1)}return{body:s.slice(o),absorbed:s.slice(0,o)}}const fl=new Set(["edit_file","edit_file_line","file_edit","file_append","notebook_edit","apply_patch","git_apply_patch","Edit","EditTool","NotebookEditTool"]);function Bn(s){return s.replace(/\\/g,"/").replace(/^\.\//,"")}function pl(s){return typeof s.diff=="string"&&s.diff.trim().length>0}function gl(s){var o;const t=new Map,n=new Map,r=l=>{const c=Bn(l);t.has(c)||(n.delete(c),t.set(c,l))},a=l=>{const c=Bn(l);t.has(c)||n.has(c)||n.set(c,l)};for(const l of((o=s.fileJob)==null?void 0:o.result)??[])l!=null&&l.path&&r(l.path);for(const l of s.toolCalls??[]){if(!l||l.status==="error"||!Ys(l.name))continue;const c=Ct(l.args);c&&(fl.has(l.name)||pl(l)?a(c):r(c))}return{created:Array.from(t.values()),modified:Array.from(n.values())}}const Hn={thinking:0,tool:1,text:2};function bl(s){return s.thinkingBlocks&&s.thinkingBlocks.length>0?s.thinkingBlocks:s.thinking?[{index:Number.MIN_SAFE_INTEGER,text:s.thinking}]:[]}function kl(s){return s.textBlocks&&s.textBlocks.length>0?s.textBlocks:s.content?[{index:Number.MAX_SAFE_INTEGER,text:s.content}]:[]}function vl(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,o)=>a.index-o.index||Hn[a.kind]-Hn[o.kind]),r}function jl(s){let t=Number.MIN_SAFE_INTEGER;for(const n of s)t=Math.max(t,n.index);return t}function yl(s,t){return s.some(n=>n.index>t)}function wl(s){return!!(s.status==="running"||s.diff||s.name==="exit_plan_mode")}function vs({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 js({message:s,sessionId:t,onRegenerate:n,onDeleteMessage:r}){const{t:a}=Y(),[o,l]=i.useState(!1),c=i.useRef(null);i.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const d=i.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(h){console.error("Failed to copy message:",h)}},[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(vs,{onClick:d,title:a("chat.copyMessage"),children:o?e.jsx(Pe,{size:13,className:"text-accent-green"}):e.jsx(xr,{size:13})}),s.type==="assistant"&&n&&e.jsx(vs,{onClick:()=>n(s.id),title:a("chat.regenerate"),children:e.jsx(Nt,{size:13})}),r&&e.jsx(vs,{onClick:()=>r(s.id),title:a("chat.deleteMessage"),danger:!0,children:e.jsx(fr,{size:13})})]}):null}function ys({ts:s,children:t}){const{i18n:n}=Y(),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 Nl=i.memo(function({message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a,onOpenSidebarView:o}){var S,z,q;const{t:l}=Y(),c=Vt(T=>T.developerView),d=me(T=>{var H;if(!n||!T.generatingSessions.includes(n))return!1;const F=T.messagesBySession[n];return F?((H=F[F.length-1])==null?void 0:H.id)===t.id:!1}),h=me(T=>{var H;if(!n)return!1;const F=T.messagesBySession[n];return F?((H=F[F.length-1])==null?void 0:H.id)===t.id:!1}),f=i.useMemo(()=>gl(t),[t.toolCalls,t.fileJob]),u=i.useMemo(()=>bl(t),[t.thinkingBlocks,t.thinking]),p=i.useMemo(()=>kl(t),[t.textBlocks,t.content]),g=i.useMemo(()=>vl(u,p,t.toolCalls),[u,p,t.toolCalls]),j=i.useMemo(()=>jl(g),[g]),[w,b]=i.useState({}),x=i.useCallback(T=>!c&&(!d||yl(g,T)),[c,d,g]),y=i.useCallback(T=>{b(F=>({...F,[T]:!(F[T]??x(T))}))},[x]),D=u.length>0,C=i.useCallback(T=>{if(!D)return T;const{body:F}=xl(T);return F||T},[D]),M=t.type==="user",_=t.type==="system",K=i.useCallback((T,F)=>{if(!n)return;const te=me.getState().getMessages(n),X=te.findIndex($=>$.id===t.id);if(X===-1)return;const I=te[X];if(!I)return;const k={...I,hookApproval:I.hookApproval?{...I.hookApproval,status:F}:void 0},N=[...te];N[X]=k,me.setState({messagesBySession:{...me.getState().messagesBySession,[n]:N}})},[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(mr,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group relative",children:[e.jsx(ys,{ts:t.timestamp}),e.jsx(js,{message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a}),e.jsx(Ki,{info:t.shellRun})]})]}):M?e.jsxs("div",{className:"chat-msg","data-role":"user",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(Ea,{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(ys,{ts:t.timestamp}),e.jsx(js,{message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a}),e.jsx(nl,{content:((z=((S=t.display)==null?void 0:S.content)??t.content)==null?void 0:z.replace(/\n{3,}/g,`
|
|
24
|
+
|
|
25
|
+
`))??"",images:t.images,pastes:(q=t.display)==null?void 0:q.pastes})]})]})]}):_?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(Ws,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group relative",children:[e.jsx(ys,{ts:t.timestamp}),e.jsx(js,{message:t,sessionId:n,onRegenerate:r,onDeleteMessage:a}),g.length>0&&!t.hookApproval&&e.jsx("div",{className:"mb-1 space-y-1","data-testid":"message-chronology",children:g.map(T=>T.kind==="thinking"?e.jsx(il,{index:T.block.index,text:T.block.text,isStreaming:d&&T.block.index===j,collapsed:w[T.block.index]??x(T.block.index),onToggle:y},T.key):T.kind==="text"?e.jsx("div",{className:"leading-relaxed",children:e.jsx(po,{content:C(T.block.text).replace(/\n{3,}/g,`
|
|
26
|
+
|
|
27
|
+
`)})},T.key):e.jsx(Ri,{toolCall:T.toolCall,sessionId:n,defaultCollapsed:c?!1:!wl(T.toolCall)},T.key))}),g.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:go(t.summary)}),h&&!d&&!t.hookApproval&&e.jsx(rl,{created:f.created,modified:f.modified,onOpenArtifacts:()=>o==null?void 0:o("artifacts"),onOpenChanges:()=>o==null?void 0:o("changes")}),t.fileJob&&e.jsx("div",{className:"mt-3",children:e.jsx(Bi,{job:t.fileJob})}),t.errorCard&&e.jsx("div",{className:"mt-3",children:e.jsx(qi,{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(Fi,{approval:t.hookApproval,onResolved:K})})]})]})});function Sl(s,t=28){const n=s.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}…`:n}const Ml="cubic-bezier(0.34, 1.56, 0.64, 1)",Cl=i.memo(function({items:t,activeId:n,onJump:r}){const{t:a}=Y(),[o,l]=i.useState(!1),c=i.useRef(null),d=i.useCallback(()=>{c.current&&window.clearTimeout(c.current),l(!0)},[]),h=i.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:h,"data-testid":"rail-trigger",className:"pointer-events-auto relative flex items-center py-3",children:[e.jsxs("div",{"aria-hidden":!o,inert:!o,"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 ${o?"translate-x-0 scale-100 opacity-100":"pointer-events-none translate-x-4 scale-95 opacity-0"}`,style:{transitionTimingFunction:o?Ml:"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(Ta,{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,u)=>{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:o?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 ${o?"translate-x-0 opacity-100":"translate-x-2 opacity-0"} ${p?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{transitionDelay:o?`${Math.min(u*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:u+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(Le,{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,u)=>{const p=Sl(f.content),g=f.id===n;return e.jsx("button",{type:"button",role:"listitem",onClick:()=>r(f.id),title:f.content,"aria-label":`${u+1}. ${p}`,"aria-current":g?"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:g?"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)})})]})})}),ws=24;function El({label:s}){const t=i.useRef(Date.now()),n=i.useRef(null),[r,a]=i.useState(!1);return i.useEffect(()=>{const o=window.setTimeout(()=>a(!0),15e3);return()=>window.clearTimeout(o)},[]),i.useEffect(()=>{if(!r)return;const o=()=>{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`};o();const l=window.setInterval(o,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(wt,{size:10}),e.jsx("span",{ref:n,children:"15s"})]})]})}const Tl=i.memo(function({messages:t,isGenerating:n,sessionId:r,onRegenerate:a,onDeleteMessage:o,onOpenSidebarView:l}){const{t:c}=Y(),d=i.useRef(null),h=i.useRef(new Map),[f,u]=i.useState(!0),[p,g]=i.useState(null),[j,w]=i.useState(null),[b,x]=i.useState(0),y=i.useRef(null),D=i.useRef(!1),C=i.useRef(null),M=i.useRef(n);M.current=n;const _=i.useMemo(()=>t.filter(N=>!N.deleted),[t]),K=i.useMemo(()=>{if(!n)return!1;const N=_[_.length-1];return!N||N.type!=="assistant"?!1:!N.content},[n,_]),S=i.useMemo(()=>_.filter(N=>Nr(N)).map(N=>({id:N.id,content:N.content})),[_]),z=i.useMemo(()=>S.map(N=>N.id),[S]),q=i.useCallback(N=>{if(N){const $=N.dataset.mid;$&&h.current.set($,N)}},[]);i.useEffect(()=>{const N=new Set(z);for(const $ of h.current.keys())N.has($)||h.current.delete($)},[z]);const T=i.useCallback(()=>{const N=d.current;if(!N||z.length===0){g(null);return}const $=N.getBoundingClientRect(),W=$.top+$.height*.35;let ee=z[0]??null;for(const se of z){const le=h.current.get(se);if(!(!le||!le.isConnected))if(le.getBoundingClientRect().top<=W)ee=se;else break}N.scrollHeight-N.scrollTop-N.clientHeight<ws&&(ee=z[z.length-1]??ee),g(ee)},[z]),F=i.useCallback(()=>{const N=d.current;if(!N)return;const $=N.scrollHeight-N.scrollTop-N.clientHeight;D.current?$>=ws&&(D.current=!1):u($<ws),T()},[T]);i.useEffect(()=>{T()},[t,T]);const H=i.useCallback(N=>{const $=d.current,W=h.current.get(N);if(!$||!W||!W.isConnected)return;u(!1),w(N),x(J=>J+1),y.current&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>w(null),1600);const ee=$.getBoundingClientRect(),se=W.getBoundingClientRect(),le=$.scrollTop+(se.top-ee.top)-$.clientHeight/2+se.height/2;C.current&&window.clearTimeout(C.current),D.current=!0,$.scrollTo({top:Math.max(0,le),behavior:"smooth"});const he=()=>{D.current=!1};"onscrollend"in $&&$.addEventListener("scrollend",he,{once:!0}),C.current=window.setTimeout(()=>{D.current=!1},1500)},[]);i.useEffect(()=>()=>{y.current&&window.clearTimeout(y.current),C.current&&window.clearTimeout(C.current)},[]);const te=i.useCallback(()=>{C.current&&window.clearTimeout(C.current),D.current=!1;const N=d.current;N&&(N.scrollTop=N.scrollHeight)},[]),X=i.useCallback(()=>{C.current&&window.clearTimeout(C.current),D.current=!1,u(!0);const N=d.current;N&&N.scrollTo({top:N.scrollHeight,behavior:"smooth"})},[]);i.useEffect(()=>{n&&(u(!0),te())},[n,te]);const I=i.useMemo(()=>{var $,W,ee,se,le;const N=_[_.length-1];return`${_.length}:${(N==null?void 0:N.id)??""}:${(($=N==null?void 0:N.content)==null?void 0:$.length)??0}:${((W=N==null?void 0:N.textBlocks)==null?void 0:W.length)??0}:${((ee=N==null?void 0:N.toolCalls)==null?void 0:ee.length)??0}:${((se=N==null?void 0:N.thinkingBlocks)==null?void 0:se.length)??0}:${((le=N==null?void 0:N.thinking)==null?void 0:le.length)??0}`},[_]),k=i.useRef(I);return i.useEffect(()=>{if(!f){k.current=I;return}I!==k.current&&(k.current=I,te())},[I,f,te]),e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsxs("div",{ref:d,onScroll:F,className:"h-full overflow-y-auto custom-scrollbar",children:[e.jsx("div",{className:"chat-stack flex flex-col pb-8 pt-5",children:_.map((N,$)=>{const W=_[$-1],ee=W?W.type===N.type?"mt-2":"mt-5":"";return e.jsxs("div",{"data-mid":N.id,ref:q,className:`relative w-full ${ee}`,children:[j===N.id&&e.jsx("div",{className:"animate-rail-flash pointer-events-none absolute inset-0"},b),e.jsx(Nl,{message:N,sessionId:r,onRegenerate:a,onDeleteMessage:o,onOpenSidebarView:l})]},N.id)})}),n&&!K&&e.jsx(El,{label:c("chat.thinkingEllipsis")},r)]}),S.length>0&&e.jsx(Cl,{items:S,activeId:p,onJump:H}),!f&&_.length>0&&e.jsx("button",{type:"button",onClick:X,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(Ke,{size:15})})]})});function lt(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 rn(s){return ct(s===null?null:s*1e3)}const Al=2048,Il=512;function Rl(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 Xt(s){const t=s.slice(0,Al),n=Rl(t).replace(/\s+/g," ").trim(),r=n.slice(0,Il).trimEnd();return t.length<s.length||r.length<n.length?`${r}…`:r}function qn(s){if(Number.isFinite(s))return rn(s)}function pt(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function Dl(s){if(typeof s=="string")return s;try{return JSON.stringify(s,null,2)}catch{return""}}function Hs(s){if(typeof s=="string")return s;if(s==null)return"";try{return JSON.stringify(s,null,2)}catch{return String(s)}}function _l(s){if(s.status==="error")return{result:s.result===void 0?"error":Hs(s.result)};const t=Hs(s.result);return t===""?{result:"No output"}:{result:"",resultPreviewMarkdown:t}}function zl(s,t){var o;const n=(t==null?void 0:t.get(s.id))??null,r=((o=s.summary)==null?void 0:o.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 $l(s,t,n){var l;const r=s.thinkingBlocks?s.thinkingBlocks.map(c=>c.text).join(`
|
|
28
|
+
`):s.thinking??"",a=zl(s,n),o=(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:o===void 0?null:o/1e3,startedAt:s.timestamp}}function Kn(s,t){const n=Dl(s.args),r=Hs(s.result),a=_l(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 Wn(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 Ol(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 Pl(s){var a;const t=[],n=[];for(const o of s)o.absTime===null||!Number.isFinite(o.absTime)||(n.push(o.absTime),o.cell.kind==="tool"&&o.cell.timeSeconds!==null&&Number.isFinite(o.cell.timeSeconds)&&n.push(o.absTime+o.cell.timeSeconds*1e3));if(n.length>=2){const o=qn((Math.max(...n)-Math.min(...n))/1e3);o!==void 0&&t.push(o)}else if(n.length===1){const o=(a=s.find(c=>c.absTime===n[0]))==null?void 0:a.cell.timeSeconds,l=o!=null?qn(o):void 0;l!==void 0&&t.push(l)}const r=new Map;for(const o of s)o.toolName===void 0||o.cell.kind!=="tool"||r.set(o.toolName,(r.get(o.toolName)??0)+1);for(const[o,l]of r)t.push(l>1?`${o}×${l}`:o);return t.length===0?void 0:t.join(" ")}function Un(s,t){const n=t.groups.map(({title:r,laid:a})=>{const o=Pl(a);return{title:r,...o!==void 0?{description:o}:{},cells:a.map(l=>l.cell)}});return{turn:s,groups:n}}function Gn(s){return Math.min(...s.groups.flatMap(t=>t.cells.map(n=>n.index)),Number.POSITIVE_INFINITY)}function Ll(s){const{messages:t,compacted:n=[],ttft:r}=s,a=new Map,o=[];let l=0,c=0,d=null;const h=g=>{let j=a.get(g);return j===void 0&&(j={groups:[]},a.set(g,j)),j},f=(g,j)=>{const w=h(g).groups,b=w[w.length-1];if((b==null?void 0:b.title)==="Message"){b.laid.push(j);return}w.push({title:"Message",laid:[j]})},u=(g,j,w)=>{if(w.length===0)return;const b=h(g).groups,x=`Step ${j}`,y=b.find(D=>D.title===x);if(y!==void 0){y.laid.push(...w);return}b.push({title:x,laid:[...w]})},p=[...t.map(g=>({kind:"message",message:g})),...n.map(g=>({kind:"compacted",record:g}))].sort((g,j)=>{const w=g.kind==="message"?g.message.timestamp:g.record.timestamp,b=j.kind==="message"?j.message.timestamp:j.record.timestamp;return w-b});for(const g of p){if(g.kind==="compacted"){const x=Ol(g.record,++l);o.push({groups:[{title:`Compaction ${g.record.seq}`,laid:[{absTime:pt(g.record.timestamp),cell:x}]}]});continue}const j=g.message;if(Nr(j)){c+=1;const x=Wn(j,++l);f(c,{absTime:pt(j.timestamp),cell:x});continue}const w=c>0?c:d??1,b=bo(j)?Wn(j,++l):$l(j,++l,r);f(w,{absTime:pt(j.timestamp),cell:b}),d=w;for(const x of j.toolCalls??[]){const y=Kn(x,++l);f(w,{absTime:pt(x.timestamp),toolName:x.name,callId:x.id,cell:y})}for(const[x,y]of(j.steps??[]).entries()){const D=(y.toolCalls??[]).map(C=>{const M=Kn(C,++l);return{absTime:pt(C.timestamp),toolName:C.name,callId:C.id,cell:M}});u(w,x+1,D)}}return[...[...a.entries()].map(([g,j])=>Un(g,j)),...o.map(g=>Un(null,g))].sort((g,j)=>Gn(g)-Gn(j))}function ss(s){if(s.text!=="")return s.text;if(s.previewMarkdown!==void 0){const t=Xt(s.previewMarkdown);if(t!=="")return t}if(s.result!==void 0&&s.result!=="")return s.result;if(s.resultPreviewMarkdown!==void 0){const t=Xt(s.resultPreviewMarkdown);if(t!=="")return t}return s.kind}function Ns(s){return ct(s)}function Kr(s){return s==="tool"||s==="subtool"?2:s==="message"||s==="compacted"?1:0}function Jn(s){return s!=null&&Number.isFinite(s)}function Fl(s){if(!Jn(s.startedAt))return null;const t=Jn(s.timeSeconds)?Math.max(0,s.timeSeconds*1e3):0;return{start:s.startedAt,end:s.startedAt+t}}function Wr(s,t="sequence"){if(t!=="sequence")return Bl(s,t==="duration");const n=[],r=[];for(const a of s){const o=a.groups.flatMap(l=>l.cells.filter(c=>c.requestOnly!==!0));o.length!==0&&(a.turn!==null&&r.push({turn:a.turn,time:n.length}),n.push(...o.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:Kr(l.kind)}))))}return n.length===0?null:{start:0,end:n.length,spans:n,turnBoundaries:r}}function Bl(s,t){const n=s.flatMap(h=>{const f=h.groups.flatMap(u=>u.cells.flatMap(p=>{if(p.requestOnly===!0)return[];const g=Fl(p);return g===null?[]:[{...g,index:p.index,isError:p.isError===!0,kind:p.kind,label:p.text,lane:Kr(p.kind)}]}));return f.length===0?[]:[{turn:h.turn,rawSpans:f}]}),r=n.flatMap(h=>h.rawSpans);if(r.length===0)return null;const a=new Map;let o=0,l=null;for(const h of[...r].sort((f,u)=>f.start-u.start||f.end-u.end))t&&l!==null&&h.start>l&&(o+=h.start-l),a.set(h,o),l=l===null?h.end:Math.max(l,h.end);const c=[],d=[];for(const h of n){const f=h.rawSpans.map(u=>{const p=a.get(u)??0;return{...u,start:u.start-p,end:u.end-p}});c.push(...f),h.turn!==null&&d.push({turn:h.turn,time:Math.min(...f.map(u=>u.start))})}return{start:Math.min(...c.map(h=>h.start)),end:Math.max(...c.map(h=>h.end)),spans:c,turnBoundaries:d}}function Hl(s,t,n="sequence"){const r=Wr(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 ql(s,t){return s.length===t.length&&s.every((n,r)=>n===t[r])}function Kl(s){if(s.previewMarkdown===void 0)return"";const t=Xt(s.previewMarkdown);return s.text===""?t:t===""?s.text:`${s.text} · ${t}`}function Wl(s){return s.resultPreviewMarkdown===void 0?s.result??"":Xt(s.resultPreviewMarkdown)}function Ul(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 Gl{constructor(){Ft(this,"entries",new Map);Ft(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 o of a.groups)for(const l of o.cells){if(l.requestOnly===!0)continue;const c=lt(l),d=Ul(a.turn,o.title,l),h=this.entries.get(c),f=h!==void 0&&ql(h.sources,d)?h:{sources:d,text:[...d,Kl(l),Wl(l)].join(`
|
|
29
|
+
`).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,o]of this.entries)n.every(l=>o.text.includes(l))&&r.add(a);return r}}const Jl=i.memo(function({actualDuration:t,onActualDurationChange:n,allTurnsCollapsed:r,onToggleAllTurns:a,allAssistantsCollapsed:o,onToggleAllAssistants:l,searchQuery:c,onSearchQueryChange:d}){const{t:h}=Y();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:h(t?"trajectory.toolbar.equalWidth":"trajectory.toolbar.actualDuration"),onClick:()=>n(!t),children:[e.jsx(zs,{size:13}),h("trajectory.toolbar.duration")]}),e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":r,title:h(r?"trajectory.toolbar.expandTurns":"trajectory.toolbar.collapseTurns"),onClick:a,children:[r?e.jsx(Aa,{size:13}):e.jsx(Ia,{size:13}),h("trajectory.toolbar.turns")]}),e.jsxs("button",{type:"button",className:"flex items-center gap-1.5 rounded px-2 py-1 text-xs text-dark-muted hover:bg-dark-surface/60","aria-pressed":o,title:h(o?"trajectory.toolbar.expandCalls":"trajectory.toolbar.collapseCalls"),onClick:l,children:[e.jsx(Ra,{size:13}),h("trajectory.toolbar.calls")]}),e.jsx("div",{className:"ml-auto flex min-w-0 flex-1 items-center justify-end",children:e.jsxs("div",{className:"relative flex w-56 items-center",children:[e.jsx(Zt,{size:12,className:"pointer-events-none absolute left-2 text-dark-muted/50"}),e.jsx("input",{type:"search",className:"h-7 w-full rounded border border-dark-border/40 bg-dark-surface/60 pl-7 pr-2 text-xs text-dark-text outline-none placeholder:text-dark-muted/40 focus:border-accent-blue/50","aria-label":h("trajectory.toolbar.search"),placeholder:h("trajectory.toolbar.searchPlaceholder"),value:c,onChange:f=>d(f.currentTarget.value)})]})})]})}),Vl=3,Xl=500;function Ql(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 Yl(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},...Ql(s.assistantMetrics)}}function Zl(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 Ss(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 ec(s,t){const n=Zl(s);if(t===void 0)return n;const r=t.durationMs===void 0?null:`Total ${Ns(t.durationMs)}`,a=t.startedAt===void 0?null:t.durationMs===void 0?`Started ${Ss(t.startedAt)}`:`${Ss(t.startedAt)} → ${Ss(t.startedAt+t.durationMs)}`,o=t.ttftMs===void 0||t.decodingMs===void 0?null:`TTFT ${Ns(t.ttftMs)} · Decoding ${Ns(t.decodingMs)}`,l=[r,o].filter(c=>c!==null).join(" · ");return[n,a,l].filter(c=>c!==null&&c!=="").join(`
|
|
30
|
+
`)}function tc(s,t){return s<=t?{start:s,end:t}:{start:t,end:s}}function sc(s){return Math.min(1,Math.max(0,s))}const nc=i.memo(function({turns:t,mode:n,range:r,selectedIndex:a=null,searchMatchIndexes:o=null,onRangeChange:l,onRecordSelect:c}){const d=i.useMemo(()=>Wr(t,n),[n,t]),h=i.useMemo(()=>new Map(t.flatMap(k=>k.groups.flatMap(N=>N.cells.map($=>[$.index,Yl($)])))),[t]),f=i.useMemo(()=>new Map(t.flatMap(k=>k.groups.flatMap(N=>N.cells.map($=>[$.index,ss($)])))),[t]),u=i.useRef(null),p=i.useRef(null),[g,j]=i.useState(null),[w,b]=i.useState(null),x=i.useRef(null),[y,D]=i.useState(null);if(i.useEffect(()=>{d!==null&&r!==null&&(r.end<d.start||r.start>d.end)&&l(null)},[d,l,r]),i.useEffect(()=>{d!==null&&D(k=>k!==null&&(k.end<d.start||k.start>d.end)?null:k)},[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 C=Math.max(1,d.end-d.start),M=(y==null?void 0:y.start)??d.start,_=y===null?C:Math.max(1,y.end-y.start),K=k=>{const N=u.current;if(!N)return 0;const $=N.getBoundingClientRect();return sc((k-$.left)/Math.max(1,$.width))},S=k=>M+k*_,z=k=>{if(k.button===2){l(null);return}const $=k.target.closest("[data-timeline-record-index]"),W=$===null?null:Number($.dataset.timelineRecordIndex);if(W!==null&&Number.isFinite(W)){c==null||c(W);return}p.current={pointerId:k.pointerId,anchorFraction:K(k.clientX),anchorClientX:k.clientX,recordIndex:null},k.currentTarget.setPointerCapture(k.pointerId)},q=k=>{const N=p.current;if(N!==null&&k.pointerId===N.pointerId){const se=K(k.clientX);if(Math.abs(k.clientX-N.anchorClientX)>=Vl){const le=S(N.anchorFraction),he=S(se);j(tc(le,he))}return}const $=K(k.clientX),W=k.target.closest("[data-timeline-record-index]"),ee=W===null?null:Number(W.dataset.timelineRecordIndex);x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{b({fraction:$,recordIndex:Number.isFinite(ee)?ee:null})},Xl)},T=k=>{const N=p.current;N===null||k.pointerId!==N.pointerId||(p.current=null,g!==null&&(l(g),j(null)))},F=k=>{var N;((N=p.current)==null?void 0:N.pointerId)===k.pointerId&&(p.current=null,j(null))},H=k=>{if(d===null)return;const N=K(k.clientX),$=S(N),W=k.deltaY<0?.75:1.35,ee=Math.min(C,Math.max(1,_*W)),se=Math.min(Math.max($-ee/2,d.start),d.end-ee);D({start:se,end:se+ee})},te=i.useRef(()=>{});te.current=H,i.useEffect(()=>{const k=u.current;if(!k)return;const N=$=>{$.preventDefault(),te.current($)};return k.addEventListener("wheel",N,{passive:!1}),()=>k.removeEventListener("wheel",N)},[d]);const X=g??r,I=w==null?void 0:w.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:u,className:"traj-track",role:"slider","aria-label":"Trajectory timeline",tabIndex:0,onKeyDown:k=>{k.key==="Escape"&&l(null)},onPointerDown:z,onPointerMove:q,onPointerUp:T,onPointerCancel:F,onPointerLeave:()=>{x.current&&clearTimeout(x.current),x.current=null,p.current===null&&b(null)},onDoubleClick:k=>{k.preventDefault(),l(null)},onContextMenu:k=>{k.preventDefault(),l(null)},children:[w!==null&&w.recordIndex===null&&g===null&&e.jsx("div",{className:"traj-hoverLine","aria-hidden":"true",style:{"--trajectory-hover-left":`${w.fraction*100}%`}}),X!==null&&e.jsx("div",{className:"traj-selection","data-dragging":g===null?void 0:"true","aria-hidden":"true",style:{"--trajectory-selection-left":`${(X.start-M)/_*100}%`,"--trajectory-selection-width":`${(X.end-X.start)/_*100}%`}}),e.jsx("div",{className:"traj-turnBoundaries","aria-hidden":"true",children:d.turnBoundaries.filter(k=>k.time>d.start&&k.time>=M&&k.time<=M+_).map(k=>e.jsx("span",{className:"traj-turnBoundary","data-turn":k.turn,style:{"--trajectory-turn-left":`${(k.time-d.start)/C*100}%`}},k.turn))}),e.jsx("div",{className:"traj-lanes","data-timeline-domain":"",children:d.spans.filter(k=>k.index===a||k.end>=M&&k.start<=M+_).map(k=>{const N=(k.start-d.start)/C,W=(k.end-k.start)/C*100,ee=h.get(k.index),se=ee==null?void 0:ee.ttftMs,le=ee==null?void 0:ee.decodingMs,he=se===void 0||le===void 0||se+le<=0?null:se/(se+le),J=f.get(k.index)??k.label;return e.jsx("span",{"aria-hidden":"true",className:"traj-span","data-timeline-span":k.kind,"data-timeline-record-index":k.index,"data-assistant-timing":he===null?void 0:"true","data-error":k.isError||void 0,"data-current":k.index===a||void 0,"data-hovered":I===k.index||void 0,"data-search-match":o===null?void 0:o.has(k.index)?"true":"false","data-selected":X===null?void 0:k.start<=X.end&&k.end>=X.start?"true":"false",title:ec(k.kind,ee),style:{"--trajectory-span-left":`${N*100}%`,"--trajectory-span-width":`${W}%`,"--trajectory-span-lane":k.lane,...he===null?{}:{"--trajectory-assistant-ttft":`${he*100}%`}},children:J},k.index)})})]})]})});function rc(s,t,n){const r=new Array(s);return new Proxy(r,{get(a,o,l){if(typeof o=="string"){const c=o.charCodeAt(0);if(c>=48&&c<=57){const d=+o;if(Number.isInteger(d)&&d>=0&&d<s){let h=a[d];if(!h){const f=t[d*2];h=a[d]={index:d,key:n(d),start:f,size:t[d*2+1],end:f+t[d*2+1],lane:0}}return h}}if(o==="length")return s}return Reflect.get(a,o,l)}})}function at(s,t,n){let r=n.initialDeps??[],a,o=!0;function l(){const c=s();return(c.length!==r.length||c.some((h,f)=>r[f]!==h))&&(r=c,a=t(...c),n!=null&&n.onChange&&!(o&&n.skipInitialOnChange)&&n.onChange(a),o=!1),a}return l.updateDeps=c=>{r=c},l}function Vn(s,t){if(s===void 0)throw new Error("Unexpected undefined");return s}const ac=(s,t)=>Math.abs(s-t)<1.01,oc=(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 gt;const Ms=()=>{if(gt!==void 0)return gt;if(typeof navigator>"u")return gt=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return gt=!0;const s=navigator.maxTouchPoints;return gt=navigator.platform==="MacIntel"&&s!==void 0&&s>0},Xn=s=>{const{offsetWidth:t,offsetHeight:n}=s;return{width:t,height:n}},ic=s=>s,lc=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 o=0;o<r;o++)a[o]=t+o;return a},cc=(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(Xn(n)),!r.ResizeObserver)return()=>{};const o=new r.ResizeObserver(l=>{const c=()=>{const d=l[0];if(d!=null&&d.borderBoxSize){const h=d.borderBoxSize[0];if(h){a({width:h.inlineSize,height:h.blockSize});return}}a(Xn(n))};s.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(c):c()});return o.observe(n,{box:"border-box"}),()=>{o.unobserve(n)}},Qt={passive:!0},dc=typeof window>"u"?!0:"onscrollend"in window,uc=(s,t,n)=>{const r=s.scrollElement;if(!r)return;const a=s.targetWindow;if(!a)return;const o=s.options.useScrollendEvent&&dc;let l=0;const c=o?null:oc(a,()=>t(l,!1),s.options.isScrollingResetDelay),d=u=>()=>{l=n(r),c==null||c(),t(l,u)},h=d(!0),f=d(!1);return r.addEventListener("scroll",h,Qt),o&&r.addEventListener("scrollend",f,Qt),()=>{r.removeEventListener("scroll",h),o&&r.removeEventListener("scrollend",f),c==null||c.cancel()}},hc=(s,t)=>uc(s,t,n=>{const{horizontal:r,isRtl:a}=s.options;return r?n.scrollLeft*(a&&-1||1):n.scrollTop}),mc=(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),o=n.itemSizeCache.get(a);if(o!==void 0)return o}return s[n.options.horizontal?"offsetWidth":"offsetHeight"]},xc=(s,{adjustments:t=0,behavior:n},r)=>{var a,o;(o=(a=r.scrollElement)==null?void 0:a.scrollTo)==null||o.call(a,{[r.options.horizontal?"left":"top"]:s+t,behavior:n})},fc=xc;class pc{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(o=>{const l=()=>{const c=o.target,d=this.indexFromElement(c);if(!c.isConnected){this.observer.unobserve(c);for(const[h,f]of this.elementsCache)if(f===c){this.elementsCache.delete(h);break}return}this.isIndexInRange(d)&&this.shouldMeasureDuringScroll(d)&&this.resizeItem(d,this.options.measureElement(c,o,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(l):l()})}));return{disconnect:()=>{var a;(a=r())==null||a.disconnect(),n=null},observe:a=>{var o;return(o=r())==null?void 0:o.observe(a,{box:"border-box"})},unobserve:a=>{var o;return(o=r())==null?void 0:o.unobserve(a)}}})(),this.range=null,this.setOptions=n=>{var r,a;const o={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:ic,rangeExtractor:lc,onChange:()=>{},measureElement:mc,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 g=n[p];g!==void 0&&(o[p]=g)}const l=this.options;let c=null,d=null,h=!1;if(l!==void 0&&l.enabled&&o.enabled&&o.anchorTo==="end"&&this.scrollElement!==null){const p=l.count,g=o.count,j=this.getMeasurements(),w=p>0?((r=j[0])==null?void 0:r.key)??l.getItemKey(0):null,b=p>0?((a=j[p-1])==null?void 0:a.key)??l.getItemKey(p-1):null;if(g!==p||p>0&&g>0&&(o.getItemKey(0)!==w||o.getItemKey(g-1)!==b)){h=!0;const D=p>0?this.getVirtualItemForOffset(this.getScrollOffset())??j[0]:null;D&&(c=[D.key,this.getScrollOffset()-D.start]);const C=o.followOnAppend===!0?"auto":o.followOnAppend||null;C&&g>p&&this.isAtEnd(l.scrollEndThreshold)&&(p===0||o.getItemKey(g-1)!==b)&&(d=C)}}this.options=o,h&&(this.pendingMin=0,this.itemSizeCacheVersion++);let f=!1,u=0;if(c&&this.scrollOffset!==null){const[p,g]=c,j=this.getMeasurements(),{count:w,getItemKey:b}=this.options;let x=0;for(;x<w&&b(x)!==p;)x++;if(x<w){const y=j[x];if(y){const D=Math.max(0,y.start+g);D!==this.scrollOffset&&(u=D-this.scrollOffset,this.scrollOffset=D,f=!0)}}}(f||d)&&(this.pendingScrollAnchor=[f?c[0]:null,f?c[1]:0,d,u])},this.notify=n=>{var r,a;(a=(r=this.options).onChange)==null||a.call(r,this,n)},this.maybeNotify=at(()=>(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(o=>{this.observer.observe(o)}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,l)=>{if(l&&this._intendedScrollOffset===null&&o===this.scrollOffset)return;this._intendedScrollOffset!==null&&Math.abs(o-this._intendedScrollOffset)<1.5&&(o=this._intendedScrollOffset),this._intendedScrollOffset=null,this.scrollAdjustments=0;const c=this.getScrollOffset();this.scrollDirection=l?c===o?this.scrollDirection:c<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=l,this._flushIosDeferredIfReady(),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),"addEventListener"in this.scrollElement){const o=this.scrollElement,l=()=>{this._iosTouching=!0,this._iosJustTouchEnded=!1,this._iosTouchEndTimerId!==null&&this.targetWindow!=null&&(this.targetWindow.clearTimeout(this._iosTouchEndTimerId),this._iosTouchEndTimerId=null)},c=()=>{this._iosTouching=!1,!(!Ms()||this.targetWindow==null)&&(this._iosJustTouchEnded=!0,this._iosTouchEndTimerId=this.targetWindow.setTimeout(()=>{this._iosJustTouchEnded=!1,this._iosTouchEndTimerId=null,this._flushIosDeferredIfReady()},150))};o.addEventListener("touchstart",l,Qt),o.addEventListener("touchend",c,Qt),this.unsubs.push(()=>{o.removeEventListener("touchstart",l),o.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[o,l,c,d]=a;o!==null&&!c&&(Ms()&&(this.isScrolling||this._iosTouching||this._iosJustTouchEnded)?d!==0&&(this._iosDeferredAdjustment+=d):this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})),c&&this.scrollToEnd({behavior:c})}},this._flushIosDeferredIfReady=()=>{if(this._iosDeferredAdjustment===0||this.isScrolling||this._iosTouching||this._iosJustTouchEnded)return;const n=this.getScrollOffset(),r=this.getMaxScrollOffset();if(n<0||n>r)return;if(this._iosDeferredAdjustment<0&&n>=r-1){this._iosDeferredAdjustment=0;return}const 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=at(()=>[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,o,l,c,d,h)=>(this.prevLanes!==void 0&&this.prevLanes!==c&&(this.lanesChangedFlag=!0),this.prevLanes=c,this.pendingMin=null,{count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:l,lanes:c,laneAssignmentMode:d,gap:h}),{key:!1}),this.isIndexInRange=n=>n>=0&&n<this.options.count,this.getMeasurements=at(()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion],({count:n,paddingStart:r,scrollMargin:a,getItemKey:o,enabled:l,lanes:c,laneAssignmentMode:d,gap:h},f)=>{const u=this.itemSizeCache;if(!l)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>n)for(const x of this.laneAssignments.keys())x>=n&&this.laneAssignments.delete(x);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(x=>{this.itemSizeCache.set(x.key,x.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 x=n*2;let y=this._flatMeasurements;if(!y||y.length<x){const M=new Float64Array(x);y&&p>0&&M.set(y.subarray(0,p*2)),y=M,this._flatMeasurements=y}let D;if(p===0)D=r+a;else{const M=p-1;D=y[M*2]+y[M*2+1]+h}for(let M=p;M<n;M++){const _=o(M),K=u.get(_),S=typeof K=="number"?K:this.options.estimateSize(M);y[M*2]=D,y[M*2+1]=S,D+=S+h}const C=rc(n,y,o);return this.measurementsCache=C,C}const g=this.measurementsCache.slice(0,p),j=new Array(c).fill(void 0),w=new Float64Array(c);let b=0;for(let x=0;x<p;x++){const y=g[x];y&&(j[y.lane]===void 0&&b++,j[y.lane]=x,w[y.lane]=y.end)}for(let x=p;x<n;x++){const y=o(x),D=this.laneAssignments.get(x);let C,M;const _=d==="estimate"||u.has(y);if(D!==void 0&&this.options.lanes>1){C=D;const q=j[C],T=q!==void 0?g[q]:void 0;M=T?T.end+h:r+a}else if(b===c){let q=0,T=w[0],F=j[0];for(let H=1;H<c;H++){const te=w[H];(te<T||te===T&&j[H]<F)&&(q=H,T=te,F=j[H])}C=q,M=T+h,_&&this.laneAssignments.set(x,C)}else C=x%this.options.lanes,M=r+a,_&&this.laneAssignments.set(x,C);const K=u.get(y),S=typeof K=="number"?K:this.options.estimateSize(x),z=M+S;g[x]={index:x,start:M,size:S,end:z,key:y,lane:C},j[C]===void 0&&b++,j[C]=x,w[C]=z}return this.measurementsCache=g,g},{key:!1,debug:()=>this.options.debug}),this.calculateRange=at(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(n,r,a,o)=>n.length===0||r===0?(this.range=null,null):(this.range=bc(n,r,a,o,o===1&&this._flatMeasurements!=null?this._flatMeasurements:null),this.range),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=at(()=>{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,o,l)=>o===null||l===null?[]:n({startIndex:o,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 o=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),l=Math.max(0,a-o),c=Math.min(this.options.count-1,a+o);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),o=this.elementsCache.get(a);o!==n&&(o&&this.observer.unobserve(o),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,o;if(!this.isIndexInRange(n))return;let l,c,d;const h=this._flatMeasurements;if(this.options.lanes===1&&h!==null)d=this.options.getItemKey(n),c=h[n*2],l=h[n*2+1];else{const p=this.measurementsCache[n];if(!p)return;d=p.key,c=p.start,l=p.size}const f=this.itemSizeCache.get(d)??l,u=r-f;if(u!==0){const p=this.options.anchorTo==="end"&&((a=this.scrollState)==null?void 0:a.behavior)!=="smooth"&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,g=p?this.getTotalSize():0,j=this.getScrollOffset()+this.scrollAdjustments,b=!this.itemSizeCache.has(d)?c<j:c+f<=j&&this.scrollDirection!=="backward",x=((o=this.scrollState)==null?void 0:o.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[n]??{index:n,key:d,start:c,size:l,end:c+l,lane:0},u,this):b);(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()-g):x&&(y=this.applyScrollAdjustment(u)),this.notify(y)}},this.getVirtualItems=at(()=>[this.getVirtualIndexes(),this.getMeasurements()],(n,r)=>{const a=[];for(let o=0,l=n.length;o<l;o++){const c=n[o],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,o=this.options.lanes===1&&a!=null,l=Ur(0,r.length-1,o?c=>a[c*2]:c=>Vn(r[c]).start,n);return Vn(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 o=this.getSize(),l=this.getScrollOffset();r==="auto"&&(r=n>=l+o?"end":"start"),r==="center"?n+=(a-o)/2:r==="end"&&(n-=o);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(),o=this.getScrollOffset(),l=this.measurementsCache[n];if(!l)return;if(r==="auto")if(l.end>=o+a-this.options.scrollPaddingEnd)r="end";else if(l.start<=o+this.options.scrollPaddingStart)r="start";else return[o,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 o=this.getOffsetForAlignment(n,r),l=this.now();this.scrollState={index:null,align:r,behavior:a,startedAt:l,lastTargetOffset:o,stableFrames:0},this._scrollToOffset(o,{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 o=this.getOffsetForIndex(n,r);if(!o)return;const[l,c]=o,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,o=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:o,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 o=r.length-1,l=this._flatMeasurements;l!=null?a=l[o*2]+l[o*2+1]:a=((n=r[o])==null?void 0:n.end)??0}else{const o=Array(this.options.lanes).fill(null);let l=r.length-1;for(;l>=0&&o.some(c=>c===null);){const c=r[l];o[c.lane]===null&&(o[c.lane]=c.end),l--}a=Math.max(...o.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:Ms()&&(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,o=1,l=a!==this.scrollState.lastTargetOffset;if(!l&&ac(a,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=o){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()),h=this.scrollState.behavior==="smooth"&&d>c;this.scrollState.lastTargetOffset=a,h||(this.scrollState.behavior="auto"),this._scrollToOffset(a,{adjustments:void 0,behavior:h?"smooth":"auto"})}this.scheduleScrollReconcile()}}const Ur=(s,t,n,r)=>{for(;s<=t;){const a=(s+t)/2|0,o=n(a);if(o<r)s=a+1;else if(o>r)t=a-1;else return a}return s>0?s-1:0};function gc(s,t,n){let r=0;for(;r<=t;){const a=(r+t)/2|0,o=s[a*2];if(o<n)r=a+1;else if(o>n)t=a-1;else return a}return r>0?r-1:0}function bc(s,t,n,r,a){const o=s.length-1;if(s.length<=r)return{startIndex:0,endIndex:o};if(r===1&&a!==null){const h=gc(a,o,n);let f=h;const u=n+t;for(;f<o&&a[f*2]+a[f*2+1]<u;)f++;return{startIndex:h,endIndex:f}}let c=Ur(0,o,h=>s[h].start,n),d=c;if(r===1)for(;d<o&&s[d].end<n+t;)d++;else if(r>1){const h=Array(r).fill(0);for(;d<o&&h.some(u=>u<n+t);){const u=s[d];h[u.lane]=u.end,d++}const f=Array(r).fill(n+t);for(;c>=0&&f.some(u=>u>=n);){const u=s[c];f[u.lane]=u.start,c--}c=Math.max(0,c-c%r),d=Math.min(o,d+(r-1-d%r))}return{startIndex:c,endIndex:d}}const Cs=typeof document<"u"?i.useLayoutEffect:i.useEffect;function kc({useFlushSync:s=!0,directDomUpdates:t=!1,directDomUpdatesMode:n="transform",...r}){const a=i.useReducer(f=>f+1,0)[1],o=i.useRef({enabled:t,mode:n,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});o.current.enabled=t,o.current.mode=n;const l=f=>{const u=o.current;if(!u.enabled||!u.container)return;const p=f.getTotalSize();if(p!==u.lastSize){u.lastSize=p;const g=f.options.horizontal?"width":"height";u.container.style[g]=`${p}px`}},c=f=>{const u=o.current;if(!u.enabled||!u.container)return;l(f);const p=!!f.options.horizontal,g=u.mode==="transform",j=p?"left":"top",w=f.options.scrollMargin,b=f.getVirtualItems();for(const x of b){const y=x.start-w,D=f.elementsCache.get(x.key);D&&u.lastPositions.get(D)!==y&&(u.lastPositions.set(D,y),g?D.style.transform=p?`translate3d(${y}px, 0, 0)`:`translate3d(0, ${y}px, 0)`:D.style[j]=`${y}px`)}},d={...r,onChange:(f,u)=>{var p;const g=o.current;let j=!0;if(g.enabled){c(f);const w=f.range,b=g.prevRange;j=!b||b.isScrolling!==f.isScrolling||b.startIndex!==(w==null?void 0:w.startIndex)||b.endIndex!==(w==null?void 0:w.endIndex),j&&(g.prevRange=w?{startIndex:w.startIndex,endIndex:w.endIndex,isScrolling:f.isScrolling}:null)}j&&(s&&u?Sr.flushSync(a):a()),(p=r.onChange)==null||p.call(r,f,u)}},[h]=i.useState(()=>{const f=new pc(d);return Object.assign(f,{containerRef:u=>{const p=o.current;if(p.container=u,p.lastSize=null,u&&p.enabled){const g=f.getTotalSize();p.lastSize=g;const j=f.options.horizontal?"width":"height";u.style[j]=`${g}px`}}})});return h.setOptions(d),Cs(()=>h._didMount(),[]),Cs(()=>(l(h),h._willUpdate())),Cs(()=>{c(h)}),h}function vc(s){return kc({observeElementRect:cc,observeElementOffset:hc,scrollToFn:fc,...s})}const jc=30,yc=20,wc=9;function Yt(s){const t=encodeURIComponent(lt(s.cell));return s.collapsedSummaryKind===void 0?t:`${t}\0summary\0${s.collapsedSummaryKind}`}function Nc(s){const t=[];let n=[];for(const[r,a]of s.entries()){const o={logicalIndex:r,record:a};if(a.cell.requestOnly===!0){n.push(o);continue}const l=[...n,o];n=[],t.push({entries:l,height:a.collapsedSummaryKind===void 0?jc:yc,key:Yt(a)})}return n.length>0&&t.push({entries:n,height:wc,key:n.map(r=>Yt(r.record)).join("|")}),t}const Sc=["Input","Output","Think","Time"],Mc=i.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:Sc.map(n=>e.jsx("span",{className:"w-12 text-right",children:n},n))})]})}),Cc=i.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})]})}),Ec={system:"System",user:"User",context:"Context",compacted:"Compacted",message:"Message",tool:"Tool",subtool:"Sub"},Tc={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"},Ac=i.memo(function({cell:t,selected:n=!1,onClick:r}){const{index:a,kind:o,timeSeconds:l,input:c,output:d,think:h}=t,f=ss(t),u=o==="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":o,"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",Tc[o]].join(" "),children:Ec[o]})}),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:[u&&e.jsxs(e.Fragment,{children:[c!==void 0&&e.jsx("span",{title:"Input tokens",children:c}),d!==void 0&&e.jsx("span",{title:"Output tokens",children:d}),h!==void 0&&e.jsx("span",{title:"Reasoning tokens",children:h})]}),e.jsx("span",{className:"w-16 text-right",children:rn(l)})]})]})}),Ic=100,Rc=12,Dc=600,_c=2;function zc(s){const t=i.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 o=t.current.structure[a];return(o==null?void 0:o.key)===r.key&&o.height===r.height})?t.current.structure:s.map(r=>({key:r.key,height:r.height}));return t.current={rows:s,structure:n},n}function $c(s){const t=[];for(const n of s){const r=[];for(const a of n.groups)a.cells.forEach((o,l)=>{r.push({turn:n.turn,group:a.title,groupDescription:a.description,groupStart:l===0,turnStart:r.length===0,cell:o,turnEnd:!1})});if(r.length>0){const a=r[r.length-1];a&&(a.turnEnd=!0)}t.push(...r)}return t}function Oc(s,t){const n=[];let r=[],a=null;const o=()=>{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&&o(),a=l.turn,r.push(l);return o(),n}function Pc(s,t){var a;const n=[];let r=0;for(;r<s.length;){const o=s[r],l=s[r+1];if(o.cell.kind==="message"&&l!==void 0&&(l.cell.kind==="tool"||l.cell.kind==="subtool")&&t.has(lt(o.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({...o,groupStart:!0,turnEnd:((a=s[c-1])==null?void 0:a.turnEnd)??o.turnEnd,collapsedSummary:`${ss(o.cell)||"Message"} · ${d} tool call${d>1?"s":""}`,collapsedSummaryKind:"assistant"}),r=c;continue}n.push(o),r+=1}return n}function Lc(s,t){const n=[];let r=null,a=null;for(const o of s)o.turnStart&&(r=o),o.groupStart&&(a=o),t.has(o.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!==o.group&&(n.push({...a,groupStart:!0,turnStart:!1}),a=null),n.push(o));return n}function Es(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 Fc(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 Bc({cell:s,onClose:t}){var c;const n=Fc(s),[r,a]=i.useState(((c=n[0])==null?void 0:c.id)??"overview"),o=ss(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:rn(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:Es(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"})]}),o!==""&&e.jsxs("div",{className:"pt-1",children:[e.jsx("dt",{className:"traj-detailKey mb-1",children:"Summary"}),e.jsx("dd",{className:"traj-detailBody",children:o})]})]});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 h=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:Es(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:Es(d.firstTokenTime)})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"TTFT"}),e.jsx("dd",{className:"traj-detailValue",children:h===null?"—":`${h} ms`})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"traj-detailKey w-24 shrink-0",children:"Decoding"}),e.jsx("dd",{className:"traj-detailValue",children: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(Ae,{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 Hc({turns:s,searchMatchIndexes:t=null,selectedIndex:n,onSelectIndex:r,onDeselect:a,onClearSelection:o,collapsedTurns:l,onToggleTurn:c,collapsedAssistants:d,onToggleAssistant:h}){var q;const f=i.useRef(null),u=i.useMemo(()=>$c(s),[s]),p=i.useMemo(()=>n===null?void 0:u.find(T=>T.cell.index===n),[u,n]),g=i.useMemo(()=>{if(t!==null)return Lc(u,t);const T=l.size===0?u:Oc(u,l);return d.size===0?T:Pc(T,d)},[u,d,l,t]),j=i.useMemo(()=>Nc(g),[g]),w=zc(j),b=g.length>Ic,x=i.useCallback(T=>{var F;return((F=w[T])==null?void 0:F.height)??30},[w]),y=i.useCallback(T=>{var F;return((F=w[T])==null?void 0:F.key)??T},[w]),D=i.useCallback(()=>f.current,[]),C=vc({count:b?w.length:0,enabled:b,estimateSize:x,getItemKey:y,getScrollElement:D,initialRect:{width:0,height:Dc},anchorTo:"end",overscan:Rc,scrollEndThreshold:_c}),M=b?C.getVirtualItems():[],_=((q=M[0])==null?void 0:q.start)??0,K=b?C.getTotalSize():0,S=T=>{r(T)},z=T=>T.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:()=>{T.collapsedSummaryKind==="turn"&&T.turn!==null?c(T.turn):T.collapsedSummaryKind==="assistant"&&h(lt(T.cell))},children:[e.jsx("span",{className:"text-dark-muted/50",children:"▸"}),e.jsx("span",{className:"truncate",children:T.collapsedSummary})]}):e.jsxs(e.Fragment,{children:[T.turnStart&&T.turn!==null&&e.jsx(Mc,{turn:T.turn}),T.groupStart&&e.jsx(Cc,{title:T.group,description:T.groupDescription}),e.jsx(Ac,{cell:T.cell,selected:n===T.cell.index,onClick:S})]});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:T=>{T.target===T.currentTarget&&(o==null||o())},children:b?e.jsx("div",{style:{height:K,position:"relative"},children:M.map(T=>{const F=j[T.index];return F?e.jsx("div",{"data-virtual-row-key":F.key,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${T.start-_}px)`,height:F.height},children:F.entries.map(H=>e.jsx("div",{children:z(H.record)},Yt(H.record)))},F.key):null})}):g.map(T=>e.jsx("div",{children:z(T)},Yt(T)))}),p!==void 0&&e.jsx(Bc,{cell:p.cell,onClose:a},p.cell.index)]})}function Qn(s){const t=new Date(s),n=r=>String(r).padStart(2,"0");return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}const qc=i.memo(function({errors:t,onOpenLogs:n}){const{t:r}=Y(),[a,o]=i.useState(!1),[l,c]=i.useState(null),d=i.useMemo(()=>t.filter(u=>u.level==="error"),[t]);if(i.useEffect(()=>{c(u=>u!==null&&d.length>u?null:u)},[d.length]),d.length===0||l!==null)return null;const h=d[d.length-1];if(h===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(ze,{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:()=>o(u=>!u),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:[Qn(h.timestamp)," · ",h.message]}),a?e.jsx(Mt,{size:14,className:"shrink-0","aria-hidden":"true"}):e.jsx(Ke,{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(Da,{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),o(!1)},title:r("trajectory.errorBanner.dismiss"),children:e.jsx(Ae,{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(u=>e.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[e.jsx("span",{className:"shrink-0 text-dark-muted",children:Qn(u.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:u.source}),e.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-all text-dark-text",children:u.message})]},u.id))})]})}),Kc=new Set,Wc=new Set,Uc=[],Gc=3e3;function Jc({sessionId:s,messages:t,errorLogs:n,onOpenLogs:r}){const[a,o]=i.useState(Kc),[l,c]=i.useState(Wc),[d,h]=i.useState(null),[f,u]=i.useState(!1),[p,g]=i.useState(""),[j]=i.useState(()=>new Gl),[w,b]=i.useState(0),x=i.useRef(null),y=i.useRef(!1),[D,C]=i.useState(null),M=Cn(J=>J.compactedBySession[s]??Vc),_=Cn(J=>J.ttftBySession[s]),K=i.useMemo(()=>{if(_!==void 0)return new Map(Object.entries(_))},[_]),S=i.useMemo(()=>Ll({messages:t,compacted:M,ttft:K}),[t,M,K]),z=f?"duration":"sequence";i.useEffect(()=>(x.current&&clearTimeout(x.current),x.current=setTimeout(()=>{j.update([S]),b(J=>J+1),y.current=!0},y.current?Gc:0),()=>{x.current&&clearTimeout(x.current)}),[S,j]);const q=i.useMemo(()=>p.trim()===""?null:j.search(p),[p,w]),T=i.useMemo(()=>{if(q===null)return null;const J=new Set;for(const L of S)for(const V of L.groups)for(const ie of V.cells)q.has(lt(ie))&&J.add(ie.index);return J},[S,q]),F=i.useMemo(()=>d===null?null:Hl(S,d,z),[S,z,d]),H=i.useMemo(()=>S.filter(J=>J.turn!==null&&J.groups.reduce((L,V)=>L+V.cells.filter(ie=>ie.requestOnly!==!0&&ie.kind!=="system").length,0)>1).flatMap(J=>J.turn===null?[]:[J.turn]),[S]),te=H.length>0&&H.every(J=>a.has(J)),X=i.useMemo(()=>{const J=[];for(const L of S){const V=L.groups.flatMap(ie=>ie.cells);for(let ie=0;ie<V.length;ie++){const xe=V[ie];if((xe==null?void 0:xe.kind)!=="message")continue;const re=V[ie+1];((re==null?void 0:re.kind)==="tool"||(re==null?void 0:re.kind)==="subtool")&&J.push(lt(xe))}}return J},[S]),I=X.length>0&&X.every(J=>l.has(J)),k=i.useCallback(J=>{o(L=>{const V=new Set(L);return V.has(J)?V.delete(J):V.add(J),V})},[]),N=i.useCallback(()=>{o(J=>{const L=new Set(J);if(te)for(const V of H)L.delete(V);else for(const V of H)L.add(V);return L})},[te,H]),$=i.useCallback(J=>{c(L=>{const V=new Set(L);return V.has(J)?V.delete(J):V.add(J),V})},[]),W=i.useCallback(()=>{c(J=>{const L=new Set(J);if(I)for(const V of X)L.delete(V);else for(const V of X)L.add(V);return L})},[I,X]),ee=i.useCallback(J=>{h(J)},[]),se=i.useCallback(J=>{F!==null&&!F.has(J)&&h(null),C(L=>L===J?null:J)},[F]),le=i.useCallback(()=>{C(null)},[]),he=i.useCallback(()=>{h(null),C(null)},[]);return e.jsxs("div",{className:"flex h-full min-h-0 flex-col","data-conversation-composer-overlay":"",children:[e.jsx(Jl,{actualDuration:f,onActualDurationChange:J=>{u(J),h(null)},allTurnsCollapsed:te,onToggleAllTurns:N,allAssistantsCollapsed:I,onToggleAllAssistants:W,searchQuery:p,onSearchQueryChange:g}),e.jsx(qc,{errors:n??Uc,onOpenLogs:r}),e.jsx(nc,{turns:S,mode:z,range:d,selectedIndex:D,searchMatchIndexes:T,onRangeChange:ee,onRecordSelect:se}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Hc,{turns:S,searchMatchIndexes:T,selectedIndex:D,onSelectIndex:se,onDeselect:le,onClearSelection:he,collapsedTurns:a,onToggleTurn:k,collapsedAssistants:l,onToggleAssistant:$})})]})}const Vc=[],Xc={plan:"border-accent-blue/30 text-accent-blue bg-accent-blue/10","auto-plan":"border-accent-cyan/30 text-accent-cyan bg-accent-cyan/10",act:"border-accent-green/30 text-accent-green bg-accent-green/10","auto-act":"border-accent-yellow/30 text-accent-yellow bg-accent-yellow/10",goal:"border-accent-purple/30 text-accent-purple bg-accent-purple/10","auto-goal":"border-accent-red/30 text-accent-red bg-accent-red/10",normal:"border-accent-green/30 text-accent-green"},Qc=i.memo(function(){const{t}=Y(),n=Ee(f=>f.mode),r=Ee(f=>f.modeSource),a=Ee(f=>f.setBaseMode),o=Ee(f=>f.toggleAuto),l=n==="normal"?"act":n,c=jt(l),d=Ls(l),h=r==="user_override";return e.jsxs("div",{className:"flex items-center gap-1",children:[ko.map(f=>{const u=c===f,p=Ps[f],g=n!=="normal"&&u?Xc[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:ue("px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",g),title:t("chat.clickToSwitchMode"),"aria-pressed":u,children:[p.label,u&&h&&e.jsx(wn,{size:10,className:"ml-1 inline-block -mt-px","aria-hidden":!0})]},f)}),h&&e.jsx("span",{className:"flex items-center text-accent-yellow",title:t("plan.modeLocked"),"aria-label":t("plan.modeLocked"),children:e.jsx(wn,{size:11,"aria-hidden":!0})}),e.jsxs("button",{type:"button",role:"switch","aria-checked":d,onClick:()=>o(),className:ue("flex items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors 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(Nt,{size:11,className:ue(d?"text-accent-yellow":"text-dark-muted")}),e.jsx("span",{children:t("plan.autoApprove")})]})]})}),Yc=i.memo(function(){var p,g;const{t}=Y(),n=Ee(j=>j.pendingSuggestion),r=Ee(j=>j.setPendingSuggestion),a=Ee(j=>j.setBaseMode);if(!n)return null;const o=n.suggestedMode,l=o==="plan"||o==="act"||o==="goal"?o:"act",c=((p=Ps[l])==null?void 0:p.label)??l,d=((g=Ps[jt(n.currentMode)])==null?void 0:g.label)??n.currentMode,h=typeof n.confidence=="number"?` · ${t("plan.modeSuggestionConfidence")} ${Math.round(n.confidence*100)}%`:"",f=()=>{a(l),r(null)},u=()=>r(null);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:d}),e.jsx(Js,{size:11,className:"shrink-0","aria-hidden":!0}),e.jsx("span",{className:"whitespace-nowrap text-dark-text",children:c}),e.jsx("span",{className:"shrink-0",children:h}),n.reason&&e.jsxs("span",{className:"hidden min-w-0 truncate md:inline",title:n.reason,children:["· ",n.reason]})]}),e.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{type:"button",onClick:f,className:ue("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(Pe,{size:11,"aria-hidden":!0}),t("plan.modeSuggestionApply",{mode:c})]}),e.jsxs("button",{type:"button",onClick:u,className:ue("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(Ae,{size:11,"aria-hidden":!0}),t("plan.modeSuggestionKeep",{mode:d})]})]})]})}),Yn={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"}},Zc=i.memo(function(){const{t}=Y(),n=it(A=>A.model),r=it(A=>A.modelRef),a=it(A=>A.setModel),o=it(A=>A.setModelRef),l=Ee(A=>A.mode),c=Vt(A=>A.effort),d=Vt(A=>A.setEffort),[h,f]=i.useState([]),[u,p]=i.useState(!1),g=i.useRef(null),[j,w]=i.useState("session"),b=Mr(A=>A.activeSessionId),[x,y]=i.useState(!1),[D,C]=i.useState(""),[M,_]=i.useState(""),[K,S]=i.useState([]),[z,q]=i.useState(new Set),[T,F]=i.useState("none"),[H,te]=i.useState(!1),[X,I]=i.useState(null),[k,N]=i.useState(null),$=i.useMemo(()=>Array.from(new Set(h.map(A=>A.provider))),[h]),W=i.useCallback(async()=>{try{const A=await ge.models.list();A.success&&A.data&&Array.isArray(A.data.models)&&f(A.data.models.filter(ae=>ae.enabled!==!1))}catch{}},[]),ee=i.useCallback(()=>{var ae,G;const A=vo(r)||((ae=h.find(be=>be.isGlobalDefault))==null?void 0:ae.provider)||((G=h[0])==null?void 0:G.provider)||"";C(A),_(""),I(null),y(!0)},[r,h]),se=i.useCallback(()=>{y(!1),S([]),I(null)},[]),le=i.useCallback(async(A,ae)=>{if(A){te(!0),I(null);try{const G=await ge.models.byProvider(A,ae||void 0);G.success&&G.data?(S(G.data.models||[]),q(new Set(G.data.existing||[])),F(G.data.source)):(S([]),q(new Set),I(G.error||t("chat.loadModelsFailed")))}catch{S([]),q(new Set),I(t("chat.loadModelsFailed"))}finally{te(!1)}}},[t]);i.useEffect(()=>{if(!x)return;const A=setTimeout(()=>{le(D,M)},M?300:0);return()=>clearTimeout(A)},[x,D,M,le]),i.useEffect(()=>{W()},[W]),i.useEffect(()=>{const A=()=>{W()};return window.addEventListener("models-updated",A),()=>window.removeEventListener("models-updated",A)},[W]);const he=i.useCallback(()=>p(!1),[]);i.useEffect(()=>{if(!u)return;const A=G=>{g.current&&!g.current.contains(G.target)&&he()},ae=G=>{G.key==="Escape"&&he()};return document.addEventListener("mousedown",A),document.addEventListener("keydown",ae),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",ae)}},[u,he]);const J=async A=>{if(he(),!b&&j==="session"){ne.error(t("chat.sessionModelNoSession"));return}const ae=n,G=r;if(a(A.id),o(`${A.provider}:${A.id}`),j==="session"){if(!b)return;try{const Re=await ge.models.setSessionModel(b,A.provider,A.id);Re.success||(a(ae),o(G),ne.error(Re.error||t("chat.switchModelFailed")))}catch{a(ae),o(G),ne.error(t("chat.switchModelFailed"))}return}const be=jt(l==="normal"?"act":l),ke=`${A.provider}:${A.id}`,ve=be==="plan"?{plan:ke}:be==="goal"?{goal:ke}:{global:ke,act:ke};try{const Re=await ge.models.setDefaults(ve);Re.success?await W():(a(ae),o(G),ne.error(Re.error||t("chat.switchModelFailed")))}catch{a(ae),o(G),ne.error(t("chat.switchModelFailed"))}},L=async A=>{const ae=z.has(A.id),G=`${D}:${A.id}`;N(A.id);const be=n,ke=r;a(A.id),o(G);try{if(!ae){const We=await ge.models.create({provider:D,model:{id:A.id,name:A.name||A.id}});if(!We.success){a(be),o(ke),I(We.error||t("chat.addModelFailed"));return}}if(j==="session"){if(!b){a(be),o(ke),ne.error(t("chat.sessionModelNoSession"));return}const We=await ge.models.setSessionModel(b,D,A.id);We.success?(se(),await W()):(a(be),o(ke),I(We.error||t("chat.switchModelFailed")));return}const ve=jt(l==="normal"?"act":l),Re=ve==="plan"?{plan:G}:ve==="goal"?{goal:G}:{global:G,act:G},dt=await ge.models.setDefaults(Re);dt.success?(se(),await W()):(a(be),o(ke),I(dt.error||t("chat.switchModelFailed")))}catch{a(be),o(ke),I(t("chat.addModelFailed"))}finally{N(null)}},V=jt(l==="normal"?"act":l),ie=V==="plan"?"isPlanDefault":V==="goal"?"isGoalDefault":"isActDefault",xe=A=>{const ae=`${A.provider}:${A.id}`;if(r)return r===ae;if(n===ae)return!0;if(n!==A.id)return!1;const G=h.filter(ke=>ke.id===A.id);return G.length<=1?!0:(G.find(ke=>ke[ie]===!0)??G.find(ke=>ke.isGlobalDefault)??G[0])===A},re=h.some(A=>A[ie]===!0),E=h.find(A=>A.isGlobalDefault),U=async()=>{he();const A=V==="plan"?{plan:null}:V==="goal"?{goal:null}:{act:null};try{(await ge.models.setDefaults(A)).success&&(E?(a(E.id),o(`${E.provider}:${E.id}`)):(a(""),o("")),await W())}catch{}},fe=i.useMemo(()=>jo(h),[h]),ye=yo(n,r),Se=Yn[c];return e.jsxs("div",{className:"relative min-w-0",ref:g,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:ye||t("chat.clickToSelectModel"),"aria-haspopup":"listbox","aria-expanded":u,children:[e.jsx(_a,{size:12,className:"shrink-0"}),e.jsx("span",{className:"font-medium max-w-[8rem] truncate",children:ye||t("chat.selectModel")}),e.jsx("span",{className:"h-3 w-px bg-dark-border shrink-0","aria-hidden":"true"}),e.jsx(Nn,{size:12,className:`shrink-0 ${Se.color}`}),e.jsx("span",{className:`text-xs font-medium ${Se.color}`,children:t(Se.labelKey)}),e.jsx(Ke,{size:12,className:ue("transition-transform",u&&"rotate-180")})]}),u&&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:ae,hint:G})=>e.jsx("button",{type:"button",onClick:()=>w(A),title:G,className:ue("text-[11px] px-2 py-0.5 rounded-full border transition-colors cursor-pointer",j===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:ae},A))}),x?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:se,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(za,{size:12})}),$.length>1?e.jsx("select",{value:D,onChange:A=>C(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:$.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:D||t("chat.noConfiguredProviders")}),e.jsx("input",{value:M,onChange:A=>_(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:H?e.jsxs("div",{className:"px-3 py-2 text-xs text-dark-muted flex items-center gap-1.5",children:[e.jsx($a,{size:11,className:"animate-spin"}),t("chat.loadingModels")]}):X?e.jsx("div",{className:"px-3 py-2 text-xs text-accent-red",children:X}):D?K.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t(M?"chat.noModelsFound":"chat.noProviderModels")}):e.jsxs(e.Fragment,{children:[T!=="none"&&e.jsx("div",{className:"px-3 pt-1.5 pb-0.5 text-[10px] text-dark-muted/70",children:t(T==="provider-api"?"chat.modelsSourceProviderApi":"chat.modelsSourceCatalog")}),K.map(A=>{const ae=z.has(A.id),G=r===`${D}:${A.id}`;return e.jsxs("button",{type:"button",role:"option","aria-selected":G,onClick:()=>L(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}),G&&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})]}),ae?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:k===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:[re&&e.jsx("button",{type:"button",role:"option","aria-selected":!1,onClick:U,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(Oa,{size:11}),t("chat.followGlobalDefault")]}),e.jsx("span",{className:"block text-[10px] text-dark-muted mt-0.5 truncate",children:E?E.name||E.id:t("chat.noGlobalDefault")})]})}),fe.map(([A,ae])=>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:ae.length})]}),ae.map(G=>{const be=xe(G);return e.jsx("button",{type:"button",role:"option","aria-selected":be,onClick:()=>J(G),className:ue("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors",be?"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:ue("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",be?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Pe,{size:11,strokeWidth:3})}),e.jsx("span",{className:"text-xs font-semibold text-dark-text truncate",children:G.name||G.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:G.id}),G.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-red/20 text-accent-red",children:t("chat.globalDefault")}),G.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-blue/20 text-accent-blue",children:t("chat.planDefault")}),G.isActDefault&&!G.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-yellow/20 text-accent-yellow",children:t("chat.actDefault")}),G.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-purple/20 text-accent-purple",children:t("chat.goalDefault")})]})]})},`${G.provider}:${G.id}`)})]},A)),h.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:ee,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(Zt,{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(Nn,{size:11}),t("chat.effort")]}),e.jsx("div",{className:"py-1",children:wo.map(A=>{const ae=Yn[A],G=A===c;return e.jsxs("button",{type:"button",role:"option","aria-selected":G,onClick:()=>{d(A),he()},className:ue("w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors",G?"bg-dark-hover":"hover:bg-dark-hover"),children:[e.jsx("span",{className:ue("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",G?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Pe,{size:11,strokeWidth:3})}),e.jsx("span",{className:`text-xs font-medium ${G?ae.color:"text-dark-text"}`,children:t(ae.labelKey)})]},A)})})]})]})});function bt(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 ed(){if(typeof navigator>"u")return"unknown";const s=typeof navigator.userAgent=="string"?navigator.userAgent:"",t=bt(s);if(t==="android"||t==="ios")return t;const n=navigator.userAgentData,r=bt(n==null?void 0:n.platform);if(r)return r;const a=typeof navigator.platform=="string"?navigator.platform:"";return bt(a)==="macos"&&(navigator.maxTouchPoints??0)>1?"ios":bt(a)??bt(s)??"unknown"}function td(){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 sd(){return typeof window<"u"&&window.__TAURI__!==void 0}const Zn={windows:"chat.desktopDownloadOsWindows",macos:"chat.desktopDownloadOsMacos",linux:"chat.desktopDownloadOsLinux",android:"chat.desktopDownloadOsAndroid",ios:"chat.desktopDownloadOsIos",unknown:"chat.desktopDownloadOsUnknown"},nd=["windows","macos","linux"];function rd(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 ad(s){try{return new URL(s).host}catch{return s}}function er(s){return s.url||s.mirrors[0]||""}function tr(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 od=i.memo(function({onHandoffToAi:t}){var I;const{t:n}=Y(),[r,a]=i.useState("idle"),[o,l]=i.useState(null),[c,d]=i.useState(!1),h=i.useRef(null),f=i.useRef(!0),u=i.useRef(!1),p=i.useRef(!1);i.useEffect(()=>(f.current=!0,()=>{f.current=!1}),[]);const g=i.useMemo(()=>ed(),[]),j=i.useMemo(()=>td(),[]),w=i.useMemo(()=>sd(),[]),b=n(Zn[g]),x=g==="android"||g==="ios",y=w?n("chat.desktopDownloadOtherPlatforms"):n("chat.desktopDownloadTitle",{os:b}),D=n(w?"chat.desktopDownloadOtherPlatforms":"chat.desktopDownloadRecommend"),C=(o==null?void 0:o.artifacts)??{},M=(I=C[g])==null?void 0:I[0],_=(o==null?void 0:o.page)||No(),K=j==="arm64"&&(g==="windows"||g==="linux"),S=i.useCallback(()=>{u.current||(u.current=!0,a("loading"),ge.system.desktopDownload().then(k=>{f.current&&(k.success&&k.data?(l(k.data),a("ready")):a("failed"))}).catch(()=>{f.current&&a("failed")}))},[]);i.useEffect(()=>{if(!c)return;const k=$=>{var W;(W=h.current)!=null&&W.contains($.target)||d(!1)},N=$=>{$.key==="Escape"&&d(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",N),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",N)}},[c]);const z=i.useCallback(()=>{window.open(_,"_blank","noopener")},[_]),q=i.useCallback(k=>{const N=er(k);if(d(!1),!N){z(),ne.warning(n("chat.desktopDownloadUnavailable"));return}tr(N,k.name),k.url&&k.source==="mirror"&&ne.info(n("chat.desktopDownloadViaMirrorToast"))},[z,n]),T=i.useCallback(()=>{if(x){z(),ne.info(n("chat.desktopDownloadMobileHint"));return}if(r==="failed"){z(),ne.warning(n("chat.desktopDownloadUnavailable"));return}if(r==="ready"){M?q(M):(z(),ne.warning(n("chat.desktopDownloadUnavailable")));return}p.current=!0,S(),ne.info(n("chat.desktopDownloadFetching"))},[q,x,z,M,S,r,n]);i.useEffect(()=>{r!=="ready"&&r!=="failed"||p.current&&(p.current=!1,T())},[r,T]);const F=i.useCallback(()=>{const k=M?er(M):_,N=((M==null?void 0:M.mirrors)??[]).slice(0,3).join(" ");t(n("chat.desktopDownloadPrompt",{os:b,url:k||_,mirrors:N||n("chat.desktopDownloadPromptNoMirror")})),d(!1),ne.success(n("chat.desktopDownloadHandToAiHint"))},[t,b,M,_,n]),H=(k,N,$)=>{const W=rd(k.size),ee=So(k.name);return e.jsxs("button",{type:"button",onClick:()=>q(k),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(Sn,{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:[$?`${n(Zn[N])} · `:"",ee]}),k.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:k.name})]}),W&&e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted",children:n("chat.desktopDownloadSize",{size:W})})]},`${N}-${k.name}`)},te=nd.filter(k=>{var N;return k!==g&&(((N=C[k])==null?void 0:N.length)??0)>0}),X=(M==null?void 0:M.mirrors)??[];return e.jsxs("div",{className:"relative flex shrink-0 items-center",ref:h,onPointerEnter:S,onFocus:S,children:[e.jsxs("button",{type:"button",onClick:T,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(Sn,{size:14,className:"shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"hidden whitespace-nowrap sm:inline",children:D})]}),e.jsx("button",{type:"button",onClick:()=>{c||S(),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(Mt,{size:11,className:ue("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:b})}),e.jsx("div",{className:"py-1",children:(C[g]??[]).length>0?(C[g]??[]).map(k=>H(k,g,!1)):e.jsx("div",{className:"px-3 py-1.5 text-[11px] leading-relaxed text-dark-muted",children:n(x?"chat.desktopDownloadMobileMenuHint":r==="failed"?"chat.desktopDownloadUnavailable":"chat.desktopDownloadLoading")})}),K&&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")}),te.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:[...te].flatMap(k=>(C[k]??[]).map(N=>H(N,k,!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:[X.slice(0,2).map(k=>e.jsxs("button",{type:"button",onClick:()=>{d(!1),tr(k,(M==null?void 0:M.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(Gt,{size:12,className:"shrink-0 text-dark-muted","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:n("chat.desktopDownloadViaMirror",{host:ad(k)})})]},k)),e.jsxs("button",{type:"button",onClick:()=>{d(!1),z()},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(Gt,{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:F,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(pr,{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")})]})]})}),g==="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(Te,{size:10,className:"animate-spin","aria-hidden":"true"}),n("chat.desktopDownloadFetching")]})]})]})});function id(s,t){if(!s)return t;const n=s.includes("\\")?"\\":"/";return s.endsWith(n)?s+t:s+n+t}function ld(s){const t=s.replace(/[\\/]+$/,""),n=Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/"));return n===-1?t:t.slice(n+1)}function cd({initial:s,onClose:t,onConfirm:n}){const{t:r}=Y(),[a,o]=i.useState(s),[l,c]=i.useState(null),[d,h]=i.useState([]),[f,u]=i.useState(!1),[p,g]=i.useState(""),[j,w]=i.useState(s),b=i.useRef(null),x=i.useCallback(async C=>{u(!0),g("");try{const M=await ge.dirs.list(C);if(!M.success||!M.data){g(M.error||r("chat.dirPickerLoadError"));return}o(M.data.path),c(M.data.parent),h(M.data.dirs||[]),w(M.data.path)}catch(M){g(M instanceof Error?M.message:r("chat.dirPickerLoadError"))}finally{u(!1)}},[r]);i.useEffect(()=>{x(s)},[s,x]),i.useEffect(()=>{var C;(C=b.current)==null||C.focus()},[]),i.useEffect(()=>{const C=M=>{M.key==="Escape"&&(M.preventDefault(),M.stopPropagation(),t())};return document.addEventListener("keydown",C),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",C),document.body.style.overflow=""}},[t]);const y=i.useCallback(()=>{const C=j.trim();C&&x(C)},[j,x]),D=i.useCallback(()=>{l&&x(l)},[l,x]);return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center overflow-hidden p-4",role:"dialog","aria-modal":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:t}),e.jsxs("div",{className:"relative w-full max-w-lg mx-4 bg-dark-surface border border-dark-border rounded-xl shadow-2xl animate-fade-in flex flex-col max-h-[70vh]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-dark-border shrink-0",children:[e.jsxs("span",{className:"flex items-center gap-2 text-[13px] font-semibold text-dark-text",children:[e.jsx(gr,{size:15,className:"text-accent-blue","aria-hidden":"true"}),r("chat.dirPickerTitle")]}),e.jsx("button",{type:"button",onClick:t,className:"rounded p-1 text-dark-muted hover:bg-dark-hover hover:text-dark-text transition-colors","aria-label":r("a11y.close"),children:e.jsx(Ae,{size:15,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"p-4 flex flex-col gap-3 min-h-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Pa,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60","aria-hidden":"true"}),e.jsx("input",{ref:b,value:j,onChange:C=>w(C.target.value),onKeyDown:C=>{C.key==="Enter"&&y()},placeholder:r("chat.dirPickerEnterPath"),spellCheck:!1,className:`w-full rounded-lg border border-dark-border bg-dark-bg pl-8 pr-2.5 py-1.5 text-xs font-mono text-dark-text
|
|
31
|
+
placeholder-dark-muted/50 focus:outline-none focus:border-accent-blue/50 focus:ring-2 focus:ring-accent-blue/10`})]}),e.jsx("button",{type:"button",onClick:y,disabled:f||!j.trim(),className:`shrink-0 rounded-lg border border-dark-border px-2.5 py-1.5 text-xs text-dark-muted
|
|
32
|
+
hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:r("chat.dirPickerGo")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"flex-1 truncate font-mono text-[11px] text-dark-muted bg-dark-bg rounded-md px-2 py-1 border border-dark-border",title:a,children:a||r("chat.noWorkspaceDir")}),e.jsxs("button",{type:"button",onClick:()=>void D(),disabled:f||!a,className:`shrink-0 flex items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-[11px] text-dark-muted
|
|
33
|
+
hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:[e.jsx(br,{size:12,"aria-hidden":"true"}),r("chat.dirPickerUp")]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto custom-scrollbar rounded-lg border border-dark-border bg-dark-bg divide-y divide-dark-border/60",children:f?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-xs text-dark-muted",children:[e.jsx(Te,{size:14,className:"animate-spin","aria-hidden":"true"}),r("chat.loading")]}):p?e.jsx("div",{className:"px-3 py-4 text-xs text-accent-red",children:p}):d.length===0?e.jsx("div",{className:"px-3 py-4 text-xs text-dark-muted/60 text-center",children:r("chat.dirPickerNoDirs")}):d.map(C=>{const M=id(a,C);return e.jsxs("button",{type:"button",onClick:()=>void x(M),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs text-dark-text
|
|
34
|
+
hover:bg-dark-hover transition-colors group`,children:[e.jsx(Xs,{size:13,className:"shrink-0 text-accent-yellow/80 group-hover:text-accent-yellow","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:C}),e.jsx(Le,{size:12,className:"shrink-0 ml-auto text-dark-muted/40","aria-hidden":"true"})]},C)})}),e.jsx("button",{type:"button",onClick:()=>n(a),disabled:!a||f,className:`w-full rounded-lg bg-accent-blue/90 text-white text-xs font-medium py-2
|
|
35
|
+
hover:bg-accent-blue disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:r("chat.dirPickerConfirm")})]})]})]})}const dd=i.memo(function({workspaceDir:t,onSelect:n}){const{t:r}=Y(),a=Vt(u=>u.recentDirs),[o,l]=i.useState(!1),[c,d]=i.useState(!1),h=i.useRef(null);i.useEffect(()=>{if(!o)return;const u=g=>{h.current&&!h.current.contains(g.target)&&l(!1)},p=g=>{g.key==="Escape"&&l(!1)};return document.addEventListener("mousedown",u),document.addEventListener("keydown",p),()=>{document.removeEventListener("mousedown",u),document.removeEventListener("keydown",p)}},[o]);const f=i.useCallback(u=>{var g;const p=((g=u==null?void 0:u.trim)==null?void 0:g.call(u))||"";p&&(l(!1),d(!1),n(p))},[n]);return e.jsxs("div",{className:"relative max-w-[180px] min-w-0",ref:h,children:[e.jsxs("button",{type:"button",onClick:()=>l(u=>!u),className:ue("flex w-full items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",o?"border-accent-blue/40 text-accent-blue bg-accent-blue/10":"border-dark-border text-dark-muted hover:bg-dark-hover hover:text-dark-text"),title:r("chat.clickToSwitchDir"),"aria-label":r("chat.clickToSwitchDir"),"aria-expanded":o,"aria-haspopup":"menu",children:[e.jsx(gr,{size:12,className:"shrink-0 text-accent-blue/80","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:t?ld(t):r("chat.noWorkspaceDir")}),e.jsx(Ke,{size:11,className:ue("shrink-0 transition-transform",o&&"rotate-180"),"aria-hidden":"true"})]}),o&&e.jsxs("div",{role:"menu",className:"absolute bottom-full left-0 mb-2 w-72 max-w-[calc(100vw-1.5rem)] rounded-xl border border-dark-border bg-dark-surface shadow-2xl z-40 overflow-hidden animate-fade-in",children:[e.jsx("div",{className:"px-3 pt-2.5 pb-1 text-[10px] font-semibold uppercase tracking-wide text-dark-muted/50 select-none",children:r("chat.recentDirs")}),a.length===0?e.jsx("div",{className:"px-3 pb-2 text-[11px] text-dark-muted/50 select-none",children:r("chat.noRecentDirs")}):e.jsx("div",{className:"max-h-56 overflow-y-auto custom-scrollbar",children:a.map(u=>{const p=u===t;return e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>f(u),className:ue("w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors group",p?"text-accent-blue bg-accent-blue/5":"text-dark-text hover:bg-dark-hover"),title:u,children:[e.jsx(Xs,{size:12,className:ue("shrink-0",p?"text-accent-blue":"text-accent-yellow/80 group-hover:text-accent-yellow"),"aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:u}),p&&e.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-accent-blue",children:"✓"})]},u)})}),e.jsx("div",{className:"border-t border-dark-border"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{l(!1),d(!0)},className:"w-full flex items-center gap-2 px-3 py-2 text-left text-xs text-accent-blue hover:bg-dark-hover transition-colors",children:[e.jsx(Le,{size:13,"aria-hidden":"true"}),r("chat.chooseOtherDir")]})]}),c&&Sr.createPortal(e.jsx(cd,{initial:t||"",onClose:()=>d(!1),onConfirm:f}),document.body)]})}),Qe="__files__",ud="__sessions__";function hd(s){return s==="enqueue"?"next-step":s==="next-step"?"direct":"enqueue"}function md(s){return s.replace(/[\\/]+$/,"").replace(/\\/g,"/").toLowerCase()}function xd(s){return[{key:Qe,label:s.files},{key:ud,label:s.sessions}]}function sr(s){return s?md(s):""}function fd(s,t){return t===Qe?s.filter(r=>r.kind==="file"):[...s.filter(r=>r.kind==="session")].sort((r,a)=>sr(r.kind==="session"?r.dir:"").localeCompare(sr(a.kind==="session"?a.dir:"")))}function pd(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 o=a<0?s.length:a;return s[(o-1+s.length)%s.length]}const gd=new Set(["running"]);function bd(s){return gd.has(String(s.status||""))?!0:s.live===!0}function kd(s,t){const n=[];for(const r of s){const a=String(r.id||r.sessionId||"");if(!a||a===t)continue;const o=String(r.title||a.slice(0,8));n.push({kind:"session",key:a,label:o,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 nr(s,t,n="active"){const r=kd(s,t);if(n==="all")return r;const a=new Map(s.map(o=>[String(o.id||o.sessionId||""),o]));return r.filter(o=>{const l=a.get(o.key);return l?bd(l):!1})}function vd(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 jd(s){return s==="running"?"chat.mentionStatusRunning":s==="paused"||s==="interrupted"?"chat.mentionStatusPaused":s==="error"?"chat.mentionStatusError":s==="stopped"?"chat.mentionStatusStopped":"chat.mentionStatusIdle"}function yd(s){return s?/^\d{12,}$/.test(s)?Number(s):s:0}function wd({isOpen:s,items:t,selectedIndex:n,query:r,isSearching:a,onSelect:o,onHover:l,selectedCount:c=0,onFinish:d,tabs:h,activeTab:f,onTabChange:u,scope:p="active",onToggleScope:g,deliveryMode:j="enqueue",onToggleDelivery:w}){const{t:b}=Y();if(!s)return null;const x=!!(u&&h&&h.length>1);return e.jsxs("div",{className:"absolute bottom-full left-0 right-0 mb-2 bg-dark-surface border border-dark-border rounded-lg shadow-xl overflow-hidden z-50",children:[e.jsxs("div",{className:"max-h-60 overflow-y-auto custom-scrollbar",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 text-[11px] text-dark-muted border-b border-dark-border bg-dark-bg",children:[e.jsx("span",{className:"font-medium text-dark-text",children:r?`@${r}`:`@ ${b("chat.mentionFilesGroup")} / ${b("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:b("chat.selectedCountShort",{n:c})}),e.jsx("span",{children:b(x?"chat.mentionTabHint":"chat.fileMentionHelpMulti")})]})]}),x&&e.jsx("div",{className:"flex items-center gap-1 px-3 py-1.5 border-b border-dark-border bg-dark-bg overflow-x-auto custom-scrollbar",children:h.map(y=>{const D=y.key===f;return e.jsx("button",{type:"button",onMouseDown:C=>{C.preventDefault(),u(y.key)},className:`px-2 py-0.5 rounded text-[11px] whitespace-nowrap transition-colors ${D?"bg-accent-blue/20 text-accent-blue font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children: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(Te,{size:16,className:"animate-spin"}),e.jsx("span",{children:b("chat.searchingFiles")})]}):e.jsx("span",{children:b(x&&f!==Qe?"chat.mentionEmptySessions":"chat.noMatchingFiles")})}):t.map((y,D)=>{const C=t[D-1],M=C&&C.kind==="session"?C.dir||"":null,_=y.kind==="session"?y.dir||"":null,K=!C||C.kind!==y.kind||_!==null&&M!==_,S=_!==null?`📁 ${_||b("chat.mentionTabUnknownDir")}`:b("chat.mentionFilesGroup");return e.jsxs("div",{children:[K&&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:S,children:S}),e.jsxs("button",{onClick:()=>o(y),onMouseEnter:()=>l(D),className:`w-full px-3 py-1.5 flex items-center gap-2 text-left text-xs transition-colors border-l-2 ${D===n?"bg-accent-blue/20 text-accent-blue border-accent-blue":"hover:bg-dark-hover text-dark-text border-transparent"}`,children:[y.kind==="session"?e.jsx(Qs,{size:12,className:"text-accent-blue shrink-0"}):y.isDir?e.jsx(Xs,{size:12,className:"text-accent-yellow shrink-0"}):e.jsx(Gs,{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:Mo(yd(y.updatedAt),Date.now(),b)}),y.messageCount!==void 0&&e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:b("chat.mentionMsgCount",{count:y.messageCount})}),e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] whitespace-nowrap ${vd(y.status)}`,children:b(jd(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:[x&&g&&e.jsxs("button",{type:"button",onMouseDown:y=>y.preventDefault(),onClick:g,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:b("chat.mentionScopeHint"),children:[b("chat.mentionScopeLabel"),b(p==="all"?"chat.mentionScopeAll":"chat.mentionScopeActive")]}),x&&w&&e.jsxs("button",{type:"button",onMouseDown:y=>y.preventDefault(),onClick:w,className:`px-1.5 py-0.5 rounded text-[10px] transition-colors ${j==="next-step"?"bg-accent-blue/20 text-accent-blue font-medium":j==="direct"?"bg-accent-green/20 text-accent-green font-medium":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,title:b("chat.mentionDeliveryHint"),children:[b("chat.mentionDeliveryLabel"),b(j==="direct"?"chat.mentionDeliveryDirect":j==="next-step"?"chat.mentionDeliveryNextStep":"chat.mentionDeliveryEnqueue")]}),e.jsx("span",{children:c>0?b("chat.selectedFilesCount",{n:c}):b("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:b("chat.finishMention")})]})]})}function Nd({open:s,onClose:t,onSelect:n}){const{t:r}=Y(),[a,o]=i.useState([]),[l,c]=i.useState(!1),[d,h]=i.useState("");i.useEffect(()=>{s&&(h(""),c(!0),ge.skills.list().then(u=>{const p=Array.isArray(u.data)?u.data:[];o(p.filter(g=>g.enabled!==!1))}).catch(()=>o([])).finally(()=>c(!1)))},[s]);const f=i.useMemo(()=>{const u=d.trim().toLowerCase();return u?a.filter(p=>[p.id,p.name,p.description,p.category,...p.tags||[]].join(" ").toLowerCase().includes(u)):a},[a,d]);return e.jsx(Co,{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(Zt,{size:14,className:"text-dark-muted shrink-0"}),e.jsx("input",{value:d,onChange:u=>h(u.target.value),placeholder:r("skills.pickPlaceholder"),autoFocus:!0,className:"flex-1 bg-transparent outline-none text-sm placeholder-dark-muted/60"}),l&&e.jsx(Nt,{size:13,className:"animate-spin text-dark-muted"})]}),l?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Nt,{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(u=>e.jsxs("button",{onClick:()=>n(u),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:[u.icon||"⭐"," ",u.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:u.injection||"lazy"})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate font-mono",children:["$",u.id]}),u.description&&e.jsx("div",{className:"text-xs text-dark-muted line-clamp-2",children:u.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:u.category||"—"}),e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-accent-blue shrink-0",children:[e.jsx(La,{size:11}),r("skills.pickUse")]})]})]},u.id))})]})})}class Ye extends Error{constructor(n,r){super(r??n);Ft(this,"code");this.code=n,this.name="ScreenshotError"}}function Sd(s){const t=document.createElement("canvas");t.width=s.videoWidth,t.height=s.videoHeight;const n=t.getContext("2d");if(!n)throw new Ye("failed","Canvas 2D context unavailable");return n.drawImage(s,0,0,t.width,t.height),new Promise((r,a)=>{t.toBlob(o=>o?r(o):a(new Ye("failed","canvas.toBlob returned null")),"image/png")})}async function Md(){var n;if(!((n=navigator.mediaDevices)!=null&&n.getDisplayMedia))throw new Ye("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 Ye("cancelled","User dismissed the screen picker"):new Ye("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 h=()=>d();r.addEventListener("loadeddata",h,{once:!0}),setTimeout(h,1e3)}),await new Promise(d=>requestAnimationFrame(()=>d()));const a=r.videoWidth,o=r.videoHeight;if(!a||!o)throw new Ye("failed","Captured video frame has no pixels");const l=await Sd(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 Wt=16e3;function Ts(){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 Cd(s){if(s.sampleRate===Wt&&s.numberOfChannels===1)return s.getChannelData(0);const t=Math.max(1,Math.ceil(s.length*Wt/s.sampleRate)),n=new OfflineAudioContext(1,t,Wt),r=n.createBufferSource();return r.buffer=s,r.connect(n.destination),r.start(0),(await n.startRendering()).getChannelData(0)}function Ed(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 o=44;for(let l=0;l<s.length;l++){const c=Math.max(-1,Math.min(1,s[l]??0));r.setInt16(o,c<0?c*32768:c*32767,!0),o+=2}return n}function Td(s){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const a=String(r.result||""),o=a.indexOf(",");t(o>=0?a.slice(o+1):a)},r.onerror=()=>n(r.error),r.readAsDataURL(s)})}function Ad(s){const[t,n]=i.useState("idle"),[r,a]=i.useState(0),o=i.useRef(null),l=i.useRef(null),c=i.useRef([]),d=i.useRef(null),h=i.useRef(0),f=i.useCallback(()=>{var w;(w=l.current)==null||w.getTracks().forEach(b=>b.stop()),l.current=null},[]),u=i.useCallback(()=>{d.current&&(clearInterval(d.current),d.current=null)},[]);i.useEffect(()=>()=>{u(),o.current&&o.current.state!=="inactive"&&o.current.stop(),f()},[u,f]);const p=i.useCallback(async()=>{if(t!=="idle")return;if(typeof MediaRecorder>"u")throw new Error("当前浏览器不支持语音输入(需要 MediaRecorder)。请使用 Chrome/Edge/Firefox 或桌面版。");let w;try{w=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0}})}catch(x){throw x instanceof DOMException&&x.name==="NotAllowedError"?new Error("麦克风权限被拒绝。请在浏览器地址栏允许麦克风权限后重试。"):new Error("无法访问麦克风:"+(x instanceof Error?x.message:String(x)))}l.current=w,c.current=[];const b=new MediaRecorder(w,Ts()?{mimeType:Ts()}:void 0);b.ondataavailable=x=>{x.data&&x.data.size>0&&c.current.push(x.data)},o.current=b,b.start(),h.current=Date.now(),a(0),n("recording"),d.current=setInterval(()=>a(Date.now()-h.current),100)},[t]),g=i.useCallback(async()=>{var x;const w=o.current;if(!w||w.state==="inactive")throw new Error("当前没有进行中的录音。");const b=new Promise(y=>{w.onstop=()=>y()});w.stop(),await b,u(),f(),o.current=null,n("transcribing");try{const y=new Blob(c.current,{type:Ts()||"audio/webm"});c.current=[];const D=await y.arrayBuffer(),C=new AudioContext;let M;try{M=await C.decodeAudioData(D)}finally{C.close()}if(M.duration<.25)return n("idle"),"";const K=await Cd(M),S=Ed(K,Wt),z=await Td(new Blob([S],{type:"audio/wav"})),q=await ge.stt.transcribe(s,z,"wav");if(!q.success)throw new Error(q.error||"语音转写失败");return((x=q.data)==null?void 0:x.text)??""}finally{n("idle")}},[s,u,f]),j=i.useCallback(()=>{const w=o.current;w&&w.state!=="inactive"&&w.stop(),o.current=null,c.current=[],u(),f(),n("idle")},[u,f]);return{state:t,elapsedMs:r,start:p,stop:g,cancel:j}}const Id=({isOpen:s,commands:t,selectedIndex:n,filter:r,onSelect:a,onHover:o,containerRef:l})=>{const{t:c}=Y();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,h)=>e.jsxs("button",{"data-index":h,onClick:()=>a(d),onMouseEnter:()=>o(h),className:`w-full px-3 py-2 flex items-start gap-3 text-left transition-colors border-l-2 ${h===n?"bg-accent-blue/10 border-accent-blue":"border-transparent hover:bg-dark-hover"}`,children:[e.jsx("span",{className:"text-lg leading-none shrink-0","aria-hidden":"true",children:d.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm font-medium text-dark-text",children:["/",d.name]}),d.args&&e.jsx("span",{className:"text-xs text-dark-muted",children:d.args}),!d.local&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue shrink-0",children:c("slashCommands.backend")})]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:d.description})]}),h===n&&e.jsx(Fa,{size:14,className:"text-dark-muted shrink-0 mt-0.5","aria-hidden":"true"})]},d.id))]})},Gr=["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"],Rd=new RegExp(`(?:\\.(${Gr.join("|")})|dockerfile|makefile)$`,"i"),Jr=["png","jpg","jpeg","webp","gif","bmp","svg"],Dd=Object.freeze([]),_d=new RegExp(`\\.(${Jr.join("|")})$`,"i"),zd=10*1024*1024,$d=Gr.map(s=>`.${s}`).join(",")+",.Dockerfile,.Makefile,"+Jr.map(s=>`.${s}`).join(","),Od=".deepseekcode/attachments",Pd=50*1024*1024,qt=10,Kt="chat-col",Ld=/["<>]/g;function Fd(s){return`<image name="${(s||"image").replace(Ld,"")}" />`}const Bd=s=>/\.xlsx?$/i.test(s)?_s:/\.(csv|docx|txt|md|mdx|rst|adoc|json|jsonc|yaml|yml|toml|xml|html|css|scss|less|env|gitignore|gitattributes|editorconfig)$/i.test(s)?Ut:/\.(ts|tsx|js|jsx|mjs|cjs|mts|cts|py|rb|go|rs|java|kt|swift|c|h|cpp|hpp|cc|cs|sh|bash|zsh|ps1|bat|cmd|sql|graphql|proto|vue|svelte|astro|dockerfile|makefile)$/i.test(s)?Ua:Gs,As=3e3,rr=5,kt=50,Hd=5e3;function qd(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 Kd(s,t){const n=s.lastIndexOf(`
|
|
36
|
+
`,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 Wd=i.memo(function({sessionId:t,onSend:n,onRunShell:r,onStop:a,onPause:o,onResume:l,slashOptions:c,workspaceDir:d,onWorkspaceSelect:h,focusRequest:f}){const{t:u}=Y(),p=me(m=>{var v;return((v=m.sessionInputs)==null?void 0:v[t])??""}),g=me(m=>m.setSessionInput),j=me(m=>{var v;return((v=m.generatingSessions)==null?void 0:v.includes(t))??!1}),w=me(m=>{var v;return((v=m.pausedSessions)==null?void 0:v.includes(t))??!1}),b=me(m=>{var v;return(v=m.pendingBySession)==null?void 0:v[t]})??Dd,x=b.length,y=i.useRef(null),D=i.useRef(null),C=i.useRef(!1),M=i.useRef(0),[_,K]=i.useState([]),[S,z]=i.useState(!1),[q,T]=i.useState(!1),[F,H]=i.useState(!1),te=i.useCallback(()=>{const m=me.getState().clearPending(t);m>0&&ne.info(u("toast.queueRevoked",{count:m}))},[t,u]),X=i.useCallback(m=>{const v=me.getState();if(v.promotePending(t,m),!v.isGenerating(t)&&!v.isPaused(t)){Eo(t);return}ne.info(u("toast.queuePromoted"))},[t,u]),I=i.useCallback(m=>{me.getState().removePending(t,m)&&ne.info(u("toast.queueRemoved"))},[t,u]),k=i.useCallback(m=>{g(t,m)},[t,g]),N=i.useCallback(m=>{var oe;const v=me.getState().removePending(t,m);if(!v)return;const R=[],P=[];let O=(((oe=v.display)==null?void 0:oe.content)??v.content).replace(/<attachment path="([^"]*)"\s*\/>/g,(Q,ce)=>(R.push(ce),"")).replace(/<image name="([^"]*)"\s*\/>/g,(Q,ce)=>(P.push(ce),"")).trim();if(v.display)for(const Q of v.display.pastes){const ce=Er(Q.content),pe=Zs(Q.content),Ne=pe>0?`[Pasted text #${ce} +${pe} lines]`:`[Pasted text #${ce}]`;O=O.replace(new RegExp(`\\[Pasted text #${Q.id}(?:\\s*\\+\\d+ lines?)?\\]`,"g"),Ne)}for(const Q of v.files??[])Ie.current.add(Q);const B=R.map((Q,ce)=>({id:`queued-att-${Date.now()}-${ce}`,name:Q.split("/").pop()||Q,size:0,uploading:!1,path:Q}));(v.images??[]).forEach((Q,ce)=>{B.push({id:`queued-img-${Date.now()}-${ce}`,name:P[ce]||`image-${ce+1}.png`,size:Math.max(1,Math.round((Q.length-Q.indexOf(",")-1)*3/4)),uploading:!1,imageDataUri:Q})}),B.length>0&&K(Q=>[...Q,...B].slice(-qt));const Z=me.getState().getSessionInput(t);k(Z.trim()?`${Z.trimEnd()}
|
|
37
|
+
|
|
38
|
+
${O}`:O),requestAnimationFrame(()=>{var Q;return(Q=y.current)==null?void 0:Q.focus()})},[t,k]),$=i.useCallback(m=>m.replace(/<attachment path="[^"]*"\s*\/>/g,"").replace(/<image name="[^"]*"\s*\/>/g,"").trim(),[]),[W,ee]=i.useState(Lo),[se,le]=i.useState(!1),he=i.useRef(null),J=i.useCallback(m=>{ee(m),Fo(m),le(!1)},[]);i.useEffect(()=>{if(!se)return;const m=R=>{he.current&&!he.current.contains(R.target)&&le(!1)},v=R=>{R.key==="Escape"&&le(!1)};return document.addEventListener("mousedown",m),document.addEventListener("keydown",v),()=>{document.removeEventListener("mousedown",m),document.removeEventListener("keydown",v)}},[se]);const L=Ad(W),V=i.useRef(null),ie=i.useCallback(async()=>{var m;try{if(!V.current){const P=await ge.stt.status();P.success&&P.data&&(V.current=P.data)}const v=V.current;if(!v)return!0;if(v.service!=="ok"&&v.service!=="stopped")return ne.warning(u("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1;const R=(m=v.backends)==null?void 0:m[W];return R&&!R.installed?(ne.warning(u("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1):!0}catch{return!0}},[u,W]);i.useEffect(()=>{const m=()=>{V.current=null};return window.addEventListener("stt-backends-changed",m),()=>window.removeEventListener("stt-backends-changed",m)},[]),i.useEffect(()=>{const m=v=>{var P;const R=qo((P=v.detail)==null?void 0:P.lang);ee(R)};return window.addEventListener("stt-lang-changed",m),()=>window.removeEventListener("stt-lang-changed",m)},[]);const xe=i.useCallback(m=>{const v=y.current,R=(v==null?void 0:v.selectionStart)??p.length,P=p.slice(0,R)+m+p.slice(R);k(P),requestAnimationFrame(()=>{v==null||v.focus();const O=R+m.length;v&&(v.selectionStart=v.selectionEnd=O)})},[p,k]);i.useEffect(()=>{if(!f)return;const m=y.current;if(!m)return;m.focus();const v=m.value.length;m.selectionStart=v,m.selectionEnd=v},[f]);const re=i.useCallback(async()=>{if(j){ne.info(u("stt.generatingTitle"));return}if(L.state==="recording"){try{const v=await L.stop();v?xe(v):ne.info(u("stt.noSpeech"))}catch(v){ne.error(v instanceof Error?v.message:String(v))}return}if(!(L.state!=="idle"||!await ie()))try{await L.start()}catch(v){ne.error(v instanceof Error?v.message:String(v))}},[L,xe,ie,u,j]),E=To(c),{isOpen:U,filter:fe,filteredCommands:ye,selectedIndex:Se,setSelectedIndex:A,selectNext:ae,selectPrev:G,executeCommand:be,openMenu:ke,closeMenu:ve,setFilter:Re,allCommands:dt,containerRef:We}=E,[Me,De]=i.useState(!1),[Tt,et]=i.useState(""),[ns,an]=i.useState([]),[rs,Ue]=i.useState(0),[Zr,on]=i.useState(!1),[ea,Ge]=i.useState(0),tt=i.useRef(-1),[ln,ta]=i.useState("active"),At=i.useRef("active"),[ut,sa]=i.useState("enqueue"),It=i.useRef("enqueue");It.current=ut;const[cn,na]=i.useState([]),Rt=i.useCallback(()=>{na(Array.from($e.current.values()))},[]);At.current=ln;const Ie=i.useRef(new Set),$e=i.useRef(new Map),ht=i.useRef(null),Dt=i.useRef(null),_t=i.useRef([]),Be=i.useRef(!1);i.useEffect(()=>{const m=v=>{const R=me.getState().getSessionInput(t),P=`@${v} `,O=R.trim()?`${R.trimEnd()} ${P}`:P;Ie.current.add(v),g(t,O),Ge(Ie.current.size+$e.current.size),requestAnimationFrame(()=>{var B;return(B=y.current)==null?void 0:B.focus()})};return Do(m),()=>Ao(m)},[t,g]);const ra=i.useCallback(m=>{const v=me.getState().getSessionInput(t),R=v.trim()?`${v.trimEnd()}
|
|
39
|
+
|
|
40
|
+
${m}`:m;g(t,R),requestAnimationFrame(()=>{var P;return(P=y.current)==null?void 0:P.focus()})},[t,g]),dn=i.useRef([]),[un,zt]=i.useState(Qe),mt=i.useRef([]),st=i.useRef([]),as=i.useRef(0),hn=i.useRef("");hn.current=Tt;const Je=i.useCallback((m,v)=>{const R=m.map(Z=>({kind:"file",key:Z.path,label:Z.name,detail:Z.path,isDir:Z.type==="directory"})),P=mt.current,O=v.toLowerCase(),B=(O?P.filter(Z=>Z.label.toLowerCase().includes(O)||Z.key.toLowerCase().includes(O)):P).slice(0,kt);return[...R,...B]},[]),$t=i.useCallback(async()=>{const m=Date.now();if(st.current.length>0&&m-as.current<Hd)return st.current;try{const v=await ge.sessions.list(),R=v.success&&v.data?v.data:[];(R.length>0||st.current.length===0)&&(st.current=R),as.current=Date.now()}catch{}return st.current},[]),os=i.useCallback(async()=>{const m=await $t();return mt.current=nr(m,t,At.current),mt.current},[$t,t]),Ve=i.useCallback(m=>{dn.current=m,an(m)},[]),is=i.useCallback(()=>{const m=At.current==="active"?"all":"active";At.current=m,ta(m),(async()=>{const v=await $t();mt.current=nr(v,t,m);const R=hn.current.toLowerCase(),P=_t.current.filter(O=>!R||O.path.toLowerCase().includes(R)).slice(0,kt);Ve(Je(P,R))})()},[$t,t,Ve,Je]),Ot=i.useCallback(()=>{let m=hd(It.current);m==="direct"&&Ie.current.size>0&&(m="enqueue"),It.current=m,sa(m)},[]),Xe=i.useMemo(()=>xd({files:u("chat.mentionTabFiles"),sessions:u("chat.mentionTabSessions")}),[u]),ls=Xe.some(m=>m.key===un)?un:Qe,nt=i.useMemo(()=>fd(ns,ls),[ns,ls]);i.useEffect(()=>{Ie.current=new Set,$e.current=new Map,Rt(),Be.current=!1,zt(Qe),mt.current=[],st.current=[],as.current=0,De(!1),et(""),an([]),dn.current=[],Ge(0),ve()},[t,ve,Rt]);const mn=i.useDeferredValue(p),xn=it(m=>m.estimateTokens),cs=i.useMemo(()=>xn(mn),[mn,xn]),fn=i.useCallback(()=>{const m=y.current;m&&(m.style.height="auto",m.style.height=Math.min(m.scrollHeight,200)+"px")},[]);i.useEffect(()=>{fn()},[p,_.length,fn]);const ds=i.useCallback(()=>{if(ht.current)return Promise.resolve(ht.current);if(Dt.current)return Dt.current;on(!0);const m=(async()=>{try{const v=await ge.files.list(),R=v.success&&v.data?v.data[0]:void 0;if(!R)return ht.current=[],[];const P=[],O=new Set,B=async(Z,oe)=>{if(oe>rr||P.length>=As)return;const Q=[];for(const pe of Z||[]){if(P.length>=As)return;const Ne=pe.path.replace(/\\/g,"/");O.has(Ne)||(O.add(Ne),pe.type==="file"?P.push({...pe,path:Ne}):pe.children&&pe.children.length>0?await B(pe.children,oe+1):oe<rr&&Q.push(pe))}if(Q.length===0)return;const ce=await Promise.all(Q.map(async pe=>{var Ne;try{const ft=await ge.files.list(pe.path.replace(/\\/g,"/"));return ft.success&&ft.data?((Ne=ft.data[0])==null?void 0:Ne.children)||[]:[]}catch{return[]}}));for(const pe of ce){if(P.length>=As)return;await B(pe,oe+1)}};return await B(R.children,1),ht.current=P,P}catch{return ht.current=[],[]}finally{Dt.current=null,on(!1)}})();return Dt.current=m,m},[]),pn=i.useCallback(async(m,v)=>{if(Be.current){const Z=tt.current;if(Z<0||v<Z){Be.current=!1,De(!1);return}const oe=m.slice(Z,v);if(/\s/.test(oe)){Be.current=!1,De(!1);return}tt.current=Z,et(oe),De(!0),Ue(0);const[Q]=await Promise.all([ds(),os()]);_t.current=Q;const ce=oe.toLowerCase(),pe=Q.filter(Ne=>!ce||Ne.path.toLowerCase().includes(ce)).slice(0,kt);Ve(Je(pe,ce));return}const R=qd(m,v);if(!R.active){Me&&De(!1);return}tt.current=R.start,et(R.query),De(!0),Ue(0);const[P]=await Promise.all([ds(),os()]);_t.current=P;const O=R.query.toLowerCase(),B=P.filter(Z=>!O||Z.path.toLowerCase().includes(O)).slice(0,kt);Ve(Je(B,O))},[Me,ds,os,Je,Ve]),aa=i.useCallback(m=>{const v=m.target.value,R=m.target.selectionStart??v.length;k(v),pn(v,R);const P=Kd(v,R);P.active?(U||ke(),Re(P.query),A(0)):U&&ve()},[k,pn,U,ke,Re,A,ve]),us=i.useCallback(m=>{const v=y.current,R=p,P=tt.current>=0?tt.current:(v==null?void 0:v.selectionStart)??R.length,O=Math.min(R.length,P+1+Tt.length);let B,Z;if(m.kind==="session"){const Q=m.label||m.key;B=/\s/.test(Q)?m.key:Q,$e.current.set(m.key,Q),Rt(),Z=`@${B} `}else B=m.key,Ie.current.add(B),Z=`@${B} `;const oe=R.slice(0,P)+Z+R.slice(O);k(oe),De(!0),et(""),Ve(Je(_t.current.slice(0,kt),"")),Ue(0),Ge(Ie.current.size+$e.current.size),tt.current=P+Z.length,Be.current=!0,requestAnimationFrame(()=>{v==null||v.focus(),v&&(v.selectionStart=v.selectionEnd=P+Z.length)})},[p,Tt,k,Je,Ve]),xt=i.useCallback(()=>{Be.current=!1,De(!1),et(""),Ge(0),zt(Qe)},[]),hs=i.useCallback(m=>{if(!m.args){const B=be(m,"");B!=null&&B.message&&(B.success?ne.success(B.message):ne.error(B.message)),k("");return}const v=y.current,R=(v==null?void 0:v.selectionStart)??p.length,P=p.lastIndexOf(`
|
|
41
|
+
`,R-1)+1,O=p.slice(0,P)+`/${m.name} `+p.slice(R);k(O),ve(),requestAnimationFrame(()=>{v==null||v.focus();const B=P+m.name.length+2;v&&(v.selectionStart=v.selectionEnd=B)})},[p,k,be,ve]),oa=i.useCallback(m=>{const v=y.current,R=(v==null?void 0:v.selectionStart)??p.length,P=`$${m.id} `,O=p.slice(0,R)+P+p.slice(R);k(O),H(!1),Be.current=!1,De(!1),et(""),requestAnimationFrame(()=>{v==null||v.focus();const B=R+P.length;v&&(v.selectionStart=v.selectionEnd=B)})},[p,k]),gn=2048,bn=i.useCallback(m=>new Promise((v,R)=>{const P=()=>{const O=new FileReader;O.onload=()=>v(String(O.result??"")),O.onerror=()=>R(new Error("Failed to read image")),O.readAsDataURL(m)};(async()=>{let O=null;try{O=await createImageBitmap(m)}catch{P();return}try{const B=Math.max(O.width,O.height);if(B<=gn){O.close(),P();return}const Z=gn/B,oe=document.createElement("canvas");oe.width=Math.max(1,Math.round(O.width*Z)),oe.height=Math.max(1,Math.round(O.height*Z));const Q=oe.getContext("2d");if(!Q){O.close(),P();return}Q.drawImage(O,0,0,oe.width,oe.height),O.close();const ce=m.type==="image/jpeg"?"image/jpeg":"image/png";v(oe.toDataURL(ce,ce==="image/jpeg"?.9:void 0))}catch{O==null||O.close(),P()}})()}),[]),He=i.useCallback(m=>{const v=Array.from(m);K(R=>{const P=qt-R.length,O=R.slice();for(const B of v.slice(0,P)){const Z=_d.test(B.name);if(!Z&&!Rd.test(B.name)){ne.warning(u("fileJob.unsupportedType",{name:B.name}));continue}if(B.size>(Z?zd:Pd)){ne.error(u("fileJob.fileTooLarge",{name:B.name}));continue}if(O.some(Q=>Q.name===B.name&&Q.size===B.size)){ne.warning(u("fileJob.duplicateFile",{name:B.name}));continue}const oe={id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,file:B,name:B.name,size:B.size,uploading:!1};Z&&bn(B).then(Q=>{K(ce=>ce.map(pe=>pe.id===oe.id?{...pe,imageDataUri:Q}:pe))}).catch(()=>{K(Q=>Q.filter(ce=>ce.id!==oe.id)),ne.error(u("fileJob.uploadFailed",{name:B.name}))}),O.push(oe)}return O.length>=qt&&ne.warning(u("fileJob.maxAttachments",{n:qt})),O})},[u,bn]),ia=i.useCallback(m=>{m.target.files&&m.target.files.length>0&&(He(m.target.files),m.target.value="")},[He]),la=i.useCallback(()=>{var m;(m=D.current)==null||m.click()},[]),Pt=i.useCallback(async()=>{if(!(q||j)){T(!0);try{const m=await Md();He([m])}catch(m){m instanceof Ye&&m.code==="cancelled"||ne.error(u("fileJob.screenshotFailed"))}finally{T(!1)}}},[He,u,q,j]),kn=i.useRef(Pt);i.useEffect(()=>{kn.current=Pt},[Pt]),i.useEffect(()=>{const m=v=>{!(v.ctrlKey||v.metaKey)||!v.shiftKey||v.key!=="s"&&v.key!=="S"||(v.preventDefault(),kn.current())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[]);const ca=i.useCallback(m=>{K(v=>v.filter(R=>R.id!==m))},[]),da=i.useCallback(m=>{m.preventDefault(),z(!0)},[]),ua=i.useCallback(m=>{m.preventDefault(),z(!1)},[]),ha=i.useCallback(m=>{m.preventDefault(),z(!1),m.dataTransfer.files&&m.dataTransfer.files.length>0&&He(m.dataTransfer.files)},[He]),vn=i.useCallback(async()=>{var v;if(_.length===0)return"";const m=[];for(const R of _){if(R.imageDataUri)continue;if(R.path){m.push(`<attachment path="${R.path}" />`);continue}if(!R.file)continue;K(B=>B.map(Z=>Z.id===R.id?{...Z,uploading:!0,error:void 0}:Z));const P=`${Od}/${R.name}`,O=await ge.files.upload(R.file,P);if(O.success&&((v=O.data)!=null&&v.path)){const B=O.data.path.replace(/\\/g,"/");K(Z=>Z.map(oe=>oe.id===R.id?{...oe,uploading:!1,path:B}:oe)),m.push(`<attachment path="${B}" />`)}else K(B=>B.map(Z=>Z.id===R.id?{...Z,uploading:!1,error:O.error||u("fileJob.uploadFailed")}:Z)),ne.error(`${R.name}: ${O.error||u("fileJob.uploadFailed")}`)}return m.length>0?`${m.join(`
|
|
42
|
+
`)}
|
|
43
|
+
|
|
44
|
+
`:""},[_,u]),ma=i.useCallback(m=>{const v=m.clipboardData.getData("text/plain");if(m.clipboardData.files&&m.clipboardData.files.length>0){m.preventDefault(),He(m.clipboardData.files);return}if(!v||!Vo(v))return;m.preventDefault();const{label:R}=Xo(v),P=y.current;if(!P)return;const O=P.selectionStart,B=P.selectionEnd,Z=P.value,oe=Z.slice(0,O)+R+Z.slice(B);k(oe),requestAnimationFrame(()=>{P.selectionStart=P.selectionEnd=O+R.length})},[k,He]),Lt=i.useCallback(async()=>{const m=Yo(p),v=m.map(de=>({id:de,content:Go(de)??""})).filter(de=>de.content!==""),R=Qo(p);Zo(m),Be.current=!1,De(!1),ve();const P=R.trim(),O=_.length>0;if(!P&&!O)return;const B=R.trim();if(B.startsWith("/")&&!O){const de=Io(B);if(de){const rt=dt.find(qe=>qe.name===de.command);if(rt){const qe=be(rt,de.args);qe!=null&&qe.message&&(qe.success?ne.success(qe.message):ne.error(qe.message)),k(""),K([]),Ie.current=new Set,$e.current=new Map,Rt(),Ge(0);return}ne.error(u("slashCommands.unknownCommand",{cmd:`/${de.command}`}));return}}if(B.startsWith("!")&&!O){const de=B.slice(1).trim();if(!de)return;r==null||r(de),k(""),K([]),Ie.current=new Set,$e.current=new Map,Ge(0);return}const Z=Array.from(Ie.current).filter(de=>R.includes(`@${de}`)),oe=Array.from($e.current.entries()).map(([de,rt])=>({id:de,title:rt})).filter(de=>R.includes(`@${de.title}`)||R.includes(`@${de.id}`));let Q="";if(O){if(_.some(de=>de.uploading)){ne.warning(u("fileJob.stillUploading"));return}Q=await vn()}const ce=_.filter(de=>de.imageDataUri),pe=ce.map(de=>de.imageDataUri);if(ce.length>0){const de=ce.map(rt=>Fd(rt.name)).join(`
|
|
45
|
+
`);Q=Q?`${Q}${de}
|
|
46
|
+
|
|
47
|
+
`:`${de}
|
|
48
|
+
|
|
49
|
+
`}const Ne=(Q+R).trim();if(!Ne&&!O)return;const ft=v.length>0?{content:`${Q}${p}`,pastes:v}:void 0;n(Ne||Q.trim(),Z.length>0?Z:void 0,pe.length>0?pe:void 0,oe.length>0?oe:void 0,oe.length>0?It.current:void 0,ft),k(""),K([]),Ie.current=new Set,$e.current=new Map,Ge(0)},[p,_,n,r,k,vn,u,ve,dt,be]),xa=i.useCallback(m=>{if(!m.nativeEvent.isComposing){if((m.key==="Backspace"||m.key==="Delete")&&!m.ctrlKey&&!m.metaKey&&!m.altKey&&!m.shiftKey){const v=y.current;if(v&&v.selectionStart===v.selectionEnd){const R=v.selectionStart,P=v.value;if(m.key==="Backspace"&&R>0){const O=ei(P.slice(0,R));if(O){m.preventDefault(),k(P.slice(0,R-O.length)+P.slice(R)),En(O),requestAnimationFrame(()=>{v.focus();const B=R-O.length;v.selectionStart=v.selectionEnd=B});return}}else if(m.key==="Delete"&&R<P.length){const O=ti(P.slice(R));if(O){m.preventDefault(),k(P.slice(0,R)+P.slice(R+O.length)),En(O),requestAnimationFrame(()=>{v.focus(),v.selectionStart=v.selectionEnd=R});return}}}}if(Me&&Xe.length>1&&m.key==="Tab"){m.preventDefault();const v=Xe.map(R=>R.key);zt(R=>pd(v,R,!m.shiftKey)),Ue(0);return}if(Me&&Xe.length>1&&m.key==="S"&&!m.ctrlKey&&!m.metaKey&&!m.altKey){m.preventDefault(),is();return}if(Me&&Xe.length>1&&m.key==="M"&&!m.ctrlKey&&!m.metaKey&&!m.altKey){m.preventDefault(),Ot();return}if(Me&&nt.length>0){if(m.key==="ArrowDown"){m.preventDefault(),Ue(v=>(v+1)%nt.length);return}if(m.key==="ArrowUp"){m.preventDefault(),Ue(v=>(v-1+nt.length)%nt.length);return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const v=nt[rs];v&&(m.preventDefault(),us(v));return}if(m.key==="Escape"){m.preventDefault(),xt();return}}else if(Me&&m.key==="Escape"){m.preventDefault(),xt();return}if(U&&ye.length>0){if(m.key==="ArrowDown"){m.preventDefault(),ae();return}if(m.key==="ArrowUp"){m.preventDefault(),G();return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const v=ye[Se];v&&(m.preventDefault(),hs(v));return}if(m.key==="Escape"){m.preventDefault(),ve();return}}else if(U&&m.key==="Escape"){m.preventDefault(),ve();return}if(m.key==="Escape"&&j){m.preventDefault();const v=Date.now(),R=Ro(x,w,M.current,v);M.current=v,R==="revokeQueue"?(te(),M.current=0):R==="stop"?a():o();return}if(m.key==="Enter"&&(m.ctrlKey||m.metaKey)){m.preventDefault(),Lt();return}m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Lt())}},[j,w,x,te,Lt,o,l,a,Me,ns,rs,us,xt,Xe,is,Ot,U,ye,Se,ae,G,hs,ve,k]),fa=i.useCallback(()=>{C.current=!0},[]),pa=i.useCallback(()=>{C.current=!1},[]),jn=cs>8e3,yn=p.trim().length>0||_.length>0,ms=/mac/i.test(navigator.platform||"")?"⌘":"Ctrl";return e.jsxs("div",{className:"chat-composer-shell shrink-0 pb-3 pt-2",onDragOver:da,onDragLeave:ua,onDrop:ha,children:[b.length>0&&e.jsxs("div",{className:`${Kt} 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:u("chat.queuedCount",{count:b.length})}),e.jsx("span",{className:"min-w-0 flex-1"}),e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted/60",children:u("chat.queuedEscHint")}),e.jsx("button",{onClick:te,className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-accent-red",title:u("chat.queuedRevoke"),"aria-label":u("chat.queuedRevoke"),children:e.jsx(Ae,{size:12,"aria-hidden":"true"})})]}),e.jsx("ul",{className:"mt-1 max-h-40 space-y-0.5 overflow-y-auto",children:b.map((m,v)=>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:v+1}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:$(m.content),children:$(m.content)||u("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:()=>X(m.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:u("chat.queuedSendNow"),"aria-label":u("chat.queuedSendNow"),children:e.jsx(Ba,{size:12,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>N(m.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:u("chat.queuedEdit"),"aria-label":u("chat.queuedEdit"),children:e.jsx(hr,{size:12,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>I(m.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:u("chat.queuedDelete"),"aria-label":u("chat.queuedDelete"),children:e.jsx(fr,{size:12,"aria-hidden":"true"})})]})]},m.id))})]}),_.length>0&&e.jsx("div",{className:`${Kt} mb-2 flex flex-wrap gap-1.5`,children:_.map(m=>{const v=Bd(m.name),R=m.imageDataUri,P=e.jsxs(e.Fragment,{children:[R?e.jsx(Ui,{src:R,name:m.name,size:13,hoverPreview:!1}):m.uploading?e.jsx(Te,{size:13,className:"animate-spin"}):e.jsx(v,{size:13}),e.jsx("span",{className:"max-w-[140px] truncate",children:m.name}),e.jsx("span",{className:"text-[10px] text-dark-muted",children:m.size>1024*1024?`${(m.size/1024/1024).toFixed(1)} MB`:`${Math.max(1,Math.round(m.size/1024))} KB`}),!m.uploading&&e.jsx("button",{onClick:()=>ca(m.id),className:"rounded p-0.5 text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors","aria-label":u("a11y.close"),children:e.jsx(Ae,{size:11})})]}),O=ue("flex items-center gap-1.5 rounded-lg border px-2 py-1 text-xs transition-colors",m.error?"border-accent-red/40 bg-accent-red/5 text-accent-red":m.uploading?"border-accent-blue/40 bg-accent-blue/5 text-accent-blue":"border-dark-border bg-dark-surface text-dark-text",R&&"cursor-zoom-in hover:border-accent-blue/40");return R?e.jsx(nn,{src:R,alt:m.name,className:"min-w-0",children:e.jsx("div",{className:O,children:P})},m.id):e.jsx("div",{className:O,children:P},m.id)})}),S&&e.jsx("div",{className:`${Kt} mb-2 rounded-xl border-2 border-dashed border-accent-blue/50 bg-accent-blue/5 py-3 text-center text-xs text-accent-blue`,children:u("fileJob.dropHint")}),e.jsxs("div",{className:`chat-composer-card relative rounded-xl border transition-all duration-150 ${Kt}`,children:[Me&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!Me,children:e.jsx(wd,{isOpen:Me,items:nt,selectedIndex:rs,query:Tt,isSearching:Zr,onSelect:us,onHover:Ue,selectedCount:ea,onFinish:xt,tabs:Xe,activeTab:ls,onTabChange:zt,scope:ln,onToggleScope:is,deliveryMode:ut,onToggleDelivery:Ot})}),U&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!U,children:e.jsx(Id,{isOpen:U,commands:ye,selectedIndex:Se,filter:fe,onSelect:hs,onHover:A,containerRef:We})}),e.jsx("textarea",{ref:y,value:p,onChange:aa,onKeyDown:xa,onPaste:ma,onBlur:()=>{Me&&xt(),ve()},onCompositionStart:fa,onCompositionEnd:pa,placeholder:u(j?"chat.generatingPlaceholder":"chat.inputPlaceholder"),rows:1,"aria-label":"Message input",className:`w-full bg-transparent px-4 pt-4 pb-3 text-sm text-dark-text placeholder-dark-muted/60
|
|
50
|
+
resize-none focus:outline-none min-h-[72px] max-h-[40vh] leading-relaxed`}),e.jsx(Yc,{}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1.5 px-3 pb-3 lg:flex-nowrap",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-x-2",children:[h&&e.jsx(dd,{workspaceDir:d,onSelect:h}),e.jsx(Qc,{}),e.jsx("span",{className:"hidden min-w-0 sm:block",children:e.jsx(Zc,{})}),e.jsx(od,{onHandoffToAi:ra}),cn.length>0&&e.jsx("button",{type:"button",onClick:Ot,className:ue("flex h-8 min-w-0 items-center rounded-full px-2.5 text-[11px] font-medium transition-colors",ut==="enqueue"?"text-dark-muted hover:bg-dark-hover hover:text-dark-text":"bg-accent-blue/10 text-accent-blue"),title:u("chat.mentionDeliveryHint"),children:e.jsx("span",{className:"max-w-[180px] truncate",children:u("chat.mentionDeliveryChip",{titles:cn.join("、"),mode:u(ut==="direct"?"chat.mentionDeliveryDirect":ut==="next-step"?"chat.mentionDeliveryNextStep":"chat.mentionDeliveryEnqueue")})})})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[cs>0&&p.length>0&&e.jsxs("span",{className:`text-[10px] tabular-nums ${jn?"text-accent-red font-medium":"text-dark-muted/60"}`,children:["~",cs," tokens",jn?` · ${u("chat.nearLimit")}`:""]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs("div",{ref:he,className:"relative",children:[e.jsxs("button",{onClick:()=>le(m=>!m),disabled:L.state!=="idle"||j,className:`flex h-8 items-center justify-center gap-0.5 rounded-full px-2 text-[11px] font-semibold text-dark-muted transition-colors
|
|
51
|
+
hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 disabled:hover:bg-transparent disabled:cursor-not-allowed`,title:u(j?"stt.generatingTitle":"stt.langToggle"),"aria-label":u(j?"stt.generatingTitle":"stt.langToggle"),"aria-haspopup":"listbox","aria-expanded":se,children:[Bo(W).short,e.jsx(Mt,{size:11,"aria-hidden":"true"})]}),se&&e.jsxs("div",{role:"listbox","aria-label":u("stt.langToggle"),className:"absolute bottom-full right-0 mb-2 z-50 w-44 rounded-lg border border-dark-border bg-dark-surface shadow-lg py-1 max-h-72 overflow-auto custom-scrollbar",children:[Ho.map(m=>e.jsxs("button",{role:"option","aria-selected":m.code===W,onClick:()=>J(m.code),className:ue("flex w-full items-center justify-between gap-2 px-3 py-1.5 text-xs transition-colors",m.code===W?"text-accent-blue bg-accent-blue/10":"text-dark-text hover:bg-dark-hover"),children:[e.jsx("span",{className:"font-medium",children:m.label}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-dark-muted",children:[m.code==="zh"?"FunASR":"Whisper",m.code===W&&e.jsx(Pe,{size:12,"aria-hidden":"true"})]})]},m.code)),e.jsx("div",{className:"mt-1 border-t border-dark-border px-3 pt-1.5 pb-0.5 text-[10px] leading-relaxed text-dark-muted/70",children:u("stt.multiHint")})]})]}),e.jsx("button",{onClick:()=>void re(),disabled:L.state==="transcribing"||j,className:ue("flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors",L.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:j?u("stt.generatingTitle"):L.state==="recording"?u("stt.stopTitle"):u("stt.title"),"aria-label":j?u("stt.generatingTitle"):L.state==="recording"?u("stt.stopTitle"):u("stt.title"),children:L.state==="transcribing"?e.jsx(Te,{size:15,className:"animate-spin","aria-hidden":"true"}):L.state==="recording"?e.jsx(Ha,{size:15,"aria-hidden":"true"}):e.jsx(qa,{size:15,"aria-hidden":"true"})}),L.state==="recording"&&e.jsxs("span",{className:"text-[10px] tabular-nums text-accent-red","aria-hidden":"true",children:[(L.elapsedMs/1e3).toFixed(0),"s"]})]}),!j&&e.jsx("button",{onClick:()=>H(!0),className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:u("skills.pickTitle"),"aria-label":u("skills.pickTitle"),children:e.jsx(pr,{size:15,"aria-hidden":"true"})}),!j&&e.jsx("button",{onClick:()=>void Pt(),disabled:q,className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 disabled:cursor-not-allowed",title:`${u("fileJob.screenshot")} (${ms}+Shift+S)`,"aria-label":`${u("fileJob.screenshot")} (${ms}+Shift+S)`,children:q?e.jsx(Te,{size:15,className:"animate-spin","aria-hidden":"true"}):e.jsx(Ka,{size:15,"aria-hidden":"true"})}),!j&&e.jsx("button",{onClick:()=>void la(),className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:u("fileJob.attach"),"aria-label":u("fileJob.attach"),children:e.jsx(Vs,{size:15,"aria-hidden":"true"})}),e.jsx("input",{ref:D,type:"file",multiple:!0,accept:$d,className:"hidden",onChange:ia}),j&&!yn?e.jsxs("div",{className:"flex items-center gap-1.5",children:[w?e.jsx("button",{onClick:l,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-green text-white transition-all hover:opacity-85 active:scale-95",title:u("chat.resumeGen"),"aria-label":u("chat.resumeGen"),children:e.jsx(Wa,{size:14,"aria-hidden":"true"})}):e.jsx("button",{onClick:o,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-yellow text-white transition-all hover:opacity-85 active:scale-95",title:u("chat.pauseGen"),"aria-label":u("chat.pauseGen"),children:e.jsx(qs,{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:u("chat.stopGen"),"aria-label":u("chat.stopGen"),children:e.jsx(Rs,{size:13,"aria-hidden":"true"})})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[j&&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:u("chat.stopGen"),"aria-label":u("chat.stopGen"),children:e.jsx(Rs,{size:13,"aria-hidden":"true"})}),e.jsx("button",{onClick:()=>void Lt(),disabled:!yn,className:`flex h-8 w-8 items-center justify-center rounded-full bg-dark-text text-dark-bg transition-all
|
|
52
|
+
hover:opacity-80 active:scale-95 disabled:opacity-25 disabled:cursor-not-allowed`,title:u(j?"chat.sendQueuedBtn":"chat.sendBtn"),"aria-label":u(j?"chat.sendQueuedBtn":"chat.sendBtn"),children:e.jsx(br,{size:15,"aria-hidden":"true"})})]})]})]})]}),e.jsxs("div",{className:"mt-1.5 hidden select-none items-center justify-center gap-3 text-[10px] text-dark-muted/55 sm:flex",children:[e.jsx("span",{children:u("chat.shiftEnter")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:u("chat.escHint")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:`${ms}+Shift+S ${u("shortcuts.screenshot")}`}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:u("chat.bangHint")})]}),e.jsx(Nd,{open:F,onClose:()=>H(!1),onSelect:oa})]})}),Ud=i.memo(function({activeSessionId:t}){const{t:n}=Y(),a=_o(o=>o.observed).filter(o=>o.id!==t);return a.length===0?null:e.jsxs("div",{className:"mb-2 flex flex-col gap-1.5",children:[a.map(o=>e.jsx(Gd,{id:o.id,title:o.title},o.id)),e.jsx("span",{className:"sr-only",children:n("chat.observedTitle")})]})});function Gd({id:s,title:t}){const{t:n}=Y(),r=me(c=>{var d;return((d=c.generatingSessions)==null?void 0:d.includes(s))??!1}),a=me(c=>{const d=c.messagesBySession[s],h=d&&d.length>0?d[d.length-1]:void 0;return!!(h!=null&&h.errorCard)}),o=me(c=>{const d=c.messagesBySession[s];if(!d||d.length===0)return"";for(let h=d.length-1;h>=0;h--){const f=d[h];if(f.type==="user")continue;const u=f.content||"";if(u.trim())return u.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(Qs,{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(Te,{size:12,className:"shrink-0 animate-spin text-accent-yellow","aria-hidden":"true"}):a?e.jsx(Ks,{size:12,className:"shrink-0 text-accent-red","aria-hidden":"true"}):e.jsx(Jt,{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}),o&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-muted/80",title:o,children:o})]})}const Jd=4,Vd=3,Xd=12,Qd=s=>s==="running"||s==="scheduled"||s==="paused";function Yd(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 Zd=i.memo(function({agent:t,depth:n}){kr();const r=t.status==="paused",a=t.elapsedMs===void 0?void 0:!r&&t.elapsedAt?t.elapsedMs+Math.max(0,Date.now()-t.elapsedAt):t.elapsedMs,o=[t.round!==void 0?t.maxRounds?`Turn ${t.round}/${t.maxRounds}`:`Turn ${t.round}`:"",t.currentTool?`⚙ ${t.currentTool}`:"",a!==void 0?Yd(a):""].filter(Boolean);return e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",style:{paddingLeft:Math.min(n,Vd)*Xd},"data-testid":"agent-progress-row","data-agent-id":t.id,children:[n>0&&e.jsx(Ga,{size:10,className:"shrink-0 text-dark-muted/50","aria-hidden":"true"}),r?e.jsx(qs,{size:11,className:"shrink-0 text-amber-400","aria-hidden":"true"}):e.jsx(Te,{size:11,className:"shrink-0 animate-spin text-accent-blue","aria-hidden":"true"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-dark-text",title:t.name,children:t.name}),o.length>0&&e.jsx("span",{className:"shrink-0 whitespace-nowrap font-mono text-[10px] text-accent-blue/80",children:o.join(" · ")}),e.jsx(Ir,{agent:t}),t.toolCallId&&e.jsx("button",{type:"button",title:"定位到触发它的 agent 卡片","aria-label":"定位到子代理卡片",onClick:()=>{Si(t.toolCallId)||ne.info("未找到对应的子代理卡片(可能已被清理)")},className:"shrink-0 rounded p-0.5 text-dark-muted hover:bg-dark-hover hover:text-dark-text",children:e.jsx(Ja,{size:11})})]})}),eu=i.memo(function({sessionId:t}){const{t:n}=Y(),r=Ze(f=>t?f.agentsBySession[t]:void 0),a=i.useMemo(()=>{if(!t||!r)return[];const f=Ze.getState().getAgentTree(t),u=[],p=(g,j)=>{for(const w of g)Qd(w.agent.status)&&u.push({agent:w.agent,depth:j}),p(w.children,j+1)};return p(f,0),u.sort((g,j)=>{const w=b=>b.agent.status==="paused"?2:1;return w(g)-w(j)})},[t,r]);if(a.length===0)return null;const o=a.slice(0,Jd),l=a.length-o.length,c=a.filter(f=>f.agent.status==="paused").length,d=a.length-c,h=[d>0?n("chat.agentProgress.running",{count:d}):"",c>0?n("chat.agentProgress.paused",{count:c}):"",l>0?n("chat.agentProgress.more",{count:l}):""].filter(Boolean).join(" · ");return e.jsxs("div",{className:"mb-2 rounded-lg border border-dark-border bg-dark-surface px-2.5 py-1.5","data-testid":"agent-progress-bar",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px]",children:[e.jsx(Qs,{size:11,className:"shrink-0 text-accent-purple","aria-hidden":"true"}),e.jsx("span",{className:"font-semibold text-dark-text",children:n("chat.agentProgress.title")}),e.jsx("span",{className:"text-dark-muted",children:h})]}),e.jsx("div",{className:"mt-1 space-y-0.5",children:o.map(({agent:f,depth:u})=>e.jsx(Zd,{agent:f,depth:u},f.id))})]})});function ar(s,t){if(!s||!t||t.length===0)return;const n=s.find(r=>r.switchMode&&t.includes(r.label));n!=null&&n.switchMode&&Ee.getState().setBaseMode(n.switchMode)}const tu=15e3,su=300;function Vr(s){const{t}=Y();return i.useMemo(()=>{const n=t("chat.askOtherLabel"),r=t("chat.askProceedLabel"),a=s.options||[],o=a.some(f=>f.label===n),l=a.some(f=>f.label===r),c=[...a];l||c.push({label:r,description:t("chat.askProceedDesc")}),o||c.push({label:n,description:t("chat.askCustomDesc")});const d=o?c.findIndex(f=>f.label===n):c.length-1,h=l?c.findIndex(f=>f.label===r):c.length-(o?1:2);return{allItems:c,otherIdx:d,proceedIdx:h,displayItems:c}},[s,t])}function or({item:s,answered:t,selectedIdx:n,multiSelected:r,customInput:a,showCustomInput:o,onSelect:l,onToggleMulti:c,onProceed:d,onEnterCustom:h,onCancelCustom:f,onSubmitCustom:u,onCustomChange:p,inputRef:g}){const{t:j}=Y(),{otherIdx:w,proceedIdx:b,displayItems:x}=Vr(s),y=!!s.multiSelect,D=C=>{if(C===b){d();return}if(C===w){h();return}if(y){c(C);return}l(C)};return e.jsxs("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:[x.map((C,M)=>{const _=n===M,K=r.has(M),S=M===w;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 ${_?"bg-blue-50 dark:bg-blue-900/20 border border-blue-300 dark:border-blue-700":"bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-750"}`,onClick:()=>D(M),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] ${K?"bg-blue-600 border-blue-600 text-white":"border-gray-400 dark:border-gray-500"}`,children:K&&e.jsx(Pe,{size:10})}),e.jsxs("span",{className:`font-medium ${_?"text-blue-700 dark:text-blue-300":"text-gray-800 dark:text-gray-200"}`,children:[y?"":`${M+1}. `,C.label]}),M===b&&e.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:j("chat.askDirectTag")}),S&&e.jsx("span",{className:"text-xs text-gray-400",children:j("chat.askCustomTag")})]}),C.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 ml-6",children:C.description})]}),S&&_&&o&&e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("textarea",{ref:g,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:z=>p(z.target.value),onKeyDown:z=>{z.key==="Enter"&&!z.shiftKey&&(z.preventDefault(),u()),z.key==="Escape"&&f()},placeholder:j("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:u,children:[e.jsx(ot,{size:12}),j("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(Ae,{size:12}),j("common.cancel")]})]})]})]},`opt-${M}`)}),t&&e.jsx("div",{className:"text-xs text-emerald-600 dark:text-emerald-400 font-medium",children:j("chat.askAnswered")})]})}function nu({isOpen:s,onClose:t}){const{t:n}=Y(),[r,a]=i.useState(null),[o,l]=i.useState(-1),[c,d]=i.useState(new Set),[h,f]=i.useState(""),[u,p]=i.useState(!1),[g,j]=i.useState(!1),[w,b]=i.useState(!1),[x,y]=i.useState(0),[D,C]=i.useState([]),[M,_]=i.useState(!1),K=i.useRef(null),S=i.useRef(null),z=i.useMemo(()=>r?r.questions&&r.questions.length>0?r.questions:[{question:r.question,header:r.header,options:r.options,multiSelect:r.multiSelect}]:[],[r]),q=z.length>1,T=i.useCallback(E=>{a(E),l(E.multiSelect?-1:0),d(new Set),f(""),p(!1),j(!1),b(!1),y(0),_(!1);const U=E.questions&&E.questions.length>0?E.questions:[E];C(U.map(()=>null))},[]);i.useEffect(()=>{S.current=r}),i.useEffect(()=>{if(s){const E=window.__pendingQuestion;E&&T(E)}},[s,T]),i.useEffect(()=>{const E=U=>{var A;const fe=U.detail,ye=((A=S.current)==null?void 0:A.questionId)??null;if(fe&&ye&&fe!==ye)return;const Se=ye;j(!0),setTimeout(()=>{var G;const ae=((G=S.current)==null?void 0:G.questionId)??null;Se&&ae&&ae!==Se||(t(),a(null),j(!1))},su)};return window.addEventListener("ask-question-dismiss",E),()=>window.removeEventListener("ask-question-dismiss",E)},[t]),i.useEffect(()=>{if(!g)return;const E=setTimeout(()=>{j(!1),b(!0)},tu);return()=>clearTimeout(E)},[g]),i.useEffect(()=>{const E=()=>b(!1);return window.addEventListener("ask-question-dismiss",E),()=>window.removeEventListener("ask-question-dismiss",E)},[]),i.useEffect(()=>{const E=()=>{const U=window.__pendingQuestion;U&&T(U)};return window.addEventListener("ask-question-required",E),()=>window.removeEventListener("ask-question-required",E)},[T]),i.useEffect(()=>{l(0),d(new Set),f(""),p(!1)},[x,M,r]);const F=z[x]||null,{allItems:H,otherIdx:te}=Vr(F||{question:""}),X=i.useCallback((E,U)=>{g||!r||(b(!1),j(!0),ar(r.options,U),je.send({type:"question_answer",sessionId:r.sessionId||je.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answer:E,selectedOptions:U})}))},[g,r]),I=i.useCallback(()=>{g||!r||(b(!1),j(!0),je.send({type:"question_answer",sessionId:r.sessionId||je.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:z.map((E,U)=>D[U]||{answer:n("chat.askUnansweredValue")})})}))},[g,r,z,D,n]),k=i.useCallback((E,U,fe)=>{var ye;ar((ye=z[E])==null?void 0:ye.options,fe),C(Se=>{const A=Se.slice();return A[E]={answer:U,selectedOptions:fe},A}),E<z.length-1?y(E+1):_(!0)},[z]),N=i.useCallback(E=>{if(g||!r)return;const U=H[E];U&&(l(E),X(U.label,[U.label]))},[g,r,H,X]),$=i.useCallback(()=>{if(g||!r||o<0)return;const E=H[o];E&&X(E.label,[E.label])},[g,r,o,H,X]),W=i.useCallback(()=>{if(g||o<0)return;const E=H[o];E&&k(x,E.label,[E.label])},[g,o,H,k,x]),ee=i.useCallback(E=>{if(g)return;const U=H[E];U&&k(x,U.label,[U.label])},[g,H,k,x]),se=i.useCallback(E=>{g||d(U=>{const fe=new Set(U);return fe.has(E)?fe.delete(E):fe.add(E),fe})},[g]),le=i.useCallback(()=>{if(g)return;const E=[...c].map(U=>{var fe;return((fe=H[U])==null?void 0:fe.label)||""});q?k(x,E.join(", "),E):X(E.join(", "),E)},[g,c,H,q,k,x,X]),he=i.useCallback(()=>{if(g)return;const E=n("chat.askProceedLabel");q?k(x,E,[E]):X(E,[E])},[g,q,k,x,X,n]),J=i.useCallback(()=>{g||(l(te),p(!0),setTimeout(()=>{var E;return(E=K.current)==null?void 0:E.focus()},100))},[g,te]),L=i.useCallback(()=>{p(!1),f("")},[]),V=i.useCallback(()=>{if(g)return;const E=h||n("chat.askEmptyInputValue");q?k(x,E):X(E)},[g,h,q,k,x,X,n]),ie=i.useCallback(()=>{g||!r||(b(!1),j(!0),je.send({type:"question_answer",sessionId:r.sessionId||je.getSessionId()||void 0,data:JSON.stringify({questionId:r.questionId,answers:z.map(()=>({answer:"(cancelled)"}))})}))},[g,r,z]),xe=i.useCallback(()=>{if(!g){if(q){if(u){p(!1),f("");return}if(M){_(!1),y(z.length-1);return}ie();return}if(u){p(!1),f("");return}X("(cancelled)")}},[g,q,u,M,z.length,ie,X]);if(!s||!r)return null;const re=D.filter(E=>!E).length;return e.jsx(Cr,{isOpen:s,onClose:xe,title:r.header||n(q?"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"),q?` · ${D.filter(Boolean).length}/${z.length}`:""]}),collapsedSummary:e.jsx("span",{className:"truncate",children:(F==null?void 0:F.question)||r.question}),maxHeight:"50vh",children:q?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:[z.map((E,U)=>{const fe=!!D[U],ye=!M&&x===U;return e.jsxs("button",{type:"button",onClick:()=>{y(U),_(!1)},className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${ye?"bg-blue-600 text-white":fe?"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",U+1," ",fe?"✓":""]},`nav-${U}`)}),e.jsx("button",{type:"button",onClick:()=>_(!0),className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${M?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:n("chat.askSubmit")})]}),M?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")}),z.map((E,U)=>{const fe=D[U];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:[U+1,". "]}),E.question]}),e.jsx("div",{className:`text-xs shrink-0 max-w-[45%] text-right break-words ${fe?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dark:text-amber-400"}`,children:fe?fe.answer:n("chat.askNotAnswered")})]},`rev-${U}`)}),re>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(ze,{size:14}),n("chat.askUnansweredWarning",{count:re})]}),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:I,disabled:g,children:[e.jsx(ot,{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:()=>{_(!1),y(z.length-1)},disabled:g,children:n("chat.askBackToEdit")})]})]}):F?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:F.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:()=>{y(E=>Math.max(0,E-1)),_(!1)},disabled:x===0,children:[e.jsx(Va,{size:12}),n("chat.askPrevQuestion")]}),x<z.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:()=>{y(E=>Math.min(z.length-1,E+1)),_(!1)},children:[n("chat.askNextQuestion"),e.jsx(Le,{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:()=>_(!0),children:[n("chat.askViewSubmit"),e.jsx(Le,{size:12})]})]})]}),e.jsx(or,{item:F,answered:!!D[x],selectedIdx:o,multiSelected:c,customInput:h,showCustomInput:u,onSelect:ee,onToggleMulti:se,onProceed:he,onEnterCustom:J,onCancelCustom:L,onSubmitCustom:V,onCustomChange:f,inputRef:K}),!u&&e.jsx("div",{className:"flex items-center gap-2",children:F.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:le,disabled:g||c.size===0,children:[e.jsx(ot,{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:W,disabled:g||o<0,children:[e.jsx(ot,{size:14}),n("chat.askConfirmQuestion")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:u?e.jsx("span",{children:n("chat.askEnterHint")}):F.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(or,{item:z[0],answered:!1,selectedIdx:o,multiSelected:c,customInput:h,showCustomInput:u,onSelect:N,onToggleMulti:se,onProceed:he,onEnterCustom:J,onCancelCustom:L,onSubmitCustom:V,onCustomChange:f,inputRef:K}),!u&&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:le,disabled:g||c.size===0,children:[e.jsx(ot,{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:$,disabled:g||o<0,children:[e.jsx(ot,{size:14}),n("chat.askSubmit")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:g?e.jsx("span",{children:n("chat.askSubmitting")}):w?e.jsxs("span",{className:"flex items-center gap-1.5 text-amber-600 dark:text-amber-400",children:[e.jsx(ze,{size:12}),n("chat.askSubmitRetry")]}):u?e.jsx("span",{children:n("chat.askEnterHint")}):r.multiSelect?e.jsx("span",{children:n("chat.askMultiHintSingle")}):e.jsx("span",{children:n("chat.askSingleHintSingle")})})]})})}const vt=15;function ru({isOpen:s,onCloseModal:t}){const{t:n}=Y("hook"),r=Os(),a=r.pendingApprovals,o=r.autoMode,l=r.setAutoMode,[c,d]=i.useState(0),[h,f]=i.useState(!1),[u,p]=i.useState(vt),[g,j]=i.useState(!0),w=i.useRef(null),b=i.useRef(!1);i.useEffect(()=>{if(a.length!==0){if(o){a.forEach(re=>{je.send({type:"hook_allow",data:JSON.stringify({approvalId:re.approvalId})})}),r.clearApprovals();return}d(re=>Math.min(re,a.length-1))}},[a.length,o]);const x=a[c]??null,y=a.length>0&&x!==null,D=a.length,C=y?D-c-1:0;i.useEffect(()=>{if(!(!y||h||!s||!x))return p(vt),w.current=setInterval(()=>{p(re=>re<=1?(w.current&&clearInterval(w.current),0):re-1)},1e3),()=>{w.current&&clearInterval(w.current)}},[y,h,s,x==null?void 0:x.approvalId]);const M=x?vr(x.toolName,x.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},_=jr[M.level],K=zo[M.level==="CRITICAL"?"critical":M.level==="HIGH"?"high":M.level==="LOW"?"low":"medium"],S=x?Lr(x.toolName,x.askPayload):null,z=x?$o(x.toolName,x.askPayload):null,q=x?{verb:Or(x.toolName),target:Pr(x.toolName,x.askPayload)}:null,T=x?St(x.askPayload)!==null:!1,F=x?Fr(x.toolName,x.askPayload):null,H=u/vt*100,te=u<=5,X=ct((vt-u)*1e3),I=i.useCallback((re,E)=>{const U=Mr.getState().activeSessionId;U&&me.getState().updateHookApprovalStatus(U,re,E)},[]),k=i.useCallback(re=>{x&&(re&&I(x.approvalId,re),f(!0),setTimeout(()=>{r.removeApproval(x.approvalId),d(0),f(!1),b.current=!1,p(vt)},200))},[x==null?void 0:x.approvalId,r,I]),N=i.useCallback(()=>{!x||h||b.current||(b.current=!0,w.current&&clearInterval(w.current),je.send({type:"hook_allow",data:JSON.stringify({approvalId:x.approvalId})}),k("approved"))},[x,k,h]),$=i.useCallback(()=>{!x||h||b.current||(b.current=!0,w.current&&clearInterval(w.current),je.send({type:"hook_deny",data:JSON.stringify({approvalId:x.approvalId})}),k("denied"))},[x,k,h]),W=i.useCallback(()=>{if(!x||h||b.current)return;b.current=!0,w.current&&clearInterval(w.current);const re=St(x.askPayload);re?(r.addToSessionAllowList(x.toolName,re),je.send({type:"hook_allow",data:JSON.stringify({approvalId:x.approvalId,sessionAllow:!0})})):(r.addToSessionAllowList(x.toolName),je.send({type:"hook_allow",data:JSON.stringify({approvalId:x.approvalId})})),k("approved")},[x,k,r,h]),ee=i.useCallback(()=>{!x||h||b.current||(b.current=!0,w.current&&clearInterval(w.current),l(!0),Ee.getState().setAuto(!0),je.send({type:"hook_allow",data:JSON.stringify({approvalId:x.approvalId})}),k("approved"))},[x,k,h,l]),se=((x==null?void 0:x.timeoutMs)??15e3)>0,le=(x==null?void 0:x.timeoutAction)==="deny"?$:N;if(i.useEffect(()=>{u===0&&s&&!h&&x&&se&&le()},[u,s,h,x,le,se]),i.useEffect(()=>{if(!s||!g)return;const re=E=>{const U=E.target;U&&typeof U.closest=="function"&&U.closest('input, textarea, select, [contenteditable="true"]')||(E.key==="Escape"?(E.preventDefault(),E.stopPropagation(),$()):E.key==="Enter"?(E.preventDefault(),N()):E.key==="1"?N():E.key==="2"?$():E.key==="3"?W():E.key==="4"&&ee())};return window.addEventListener("keydown",re),()=>window.removeEventListener("keydown",re)},[s,g,N,$,W,ee]),!y||!x)return null;const he=n("optionAllowHint"),J=n("optionDenyHint"),L=T?n("optionAllowPathHint"):n("optionAllowAlwaysHint",{tool:x.toolName}),V=n("optionAutoModeHint"),ie=(S==null?void 0:S.text)??z??null,xe=ie?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:x.toolName}),e.jsx("span",{className:"truncate",children:ie})]}):null;return e.jsx(Cr,{isOpen:s,onClose:()=>t==null?void 0:t(),title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ds,{className:"w-4 h-4 text-yellow-400"}),e.jsx("span",{children:n("hookApproval")}),e.jsxs("span",{className:"text-xs text-dark-muted",children:["(",c+1,"/",D,")"]})]}),badge:e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${_.badge}`,children:[_.icon," ",M.level]}),collapsedSummary:xe,onExpandedChange:j,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 ${_.bg} border ${_.border}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${_.badge}`,children:[_.icon," ",M.level]}),e.jsx("span",{className:"text-xs text-dark-muted truncate",children:n(M.reasonKey)}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[e.jsx(wt,{size:12,className:te?"text-accent-red":"text-dark-muted"}),e.jsx("span",{className:`text-xs font-mono ${te?"text-accent-red animate-pulse":"text-dark-muted"}`,children:se?`${u}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 ${te?"bg-accent-red":u<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${H}%`}})})]})]}),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(Ds,{size:15})}),q&&e.jsx(Br,{pre:n(q.verb),obj:q.target})]}),F&&(F.external&&F.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:F.path,children:[e.jsx(Gt,{size:10}),n("scopeExternal"),": ",F.path.length>48?`${F.path.slice(0,47)}…`:F.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:x.toolName}),e.jsx("span",{className:"text-dark-muted/50",children:X}),e.jsx("span",{className:"text-dark-muted/50",children:K.label}),x.timeoutAction&&e.jsxs("span",{className:`text-xs ${x.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",se?`${x.timeoutAction==="allow"?"auto-allow":"auto-deny"}${x.timeoutMs?` (${(x.timeoutMs/1e3).toFixed(0)}s)`:""}`:n("timeoutWaitUser")]})]}),S?e.jsx(Fs,{text:S.text,mono:S.mono}):z?e.jsx(Fs,{text:z}):null,(M.level==="CRITICAL"||M.level==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${_.bg} ${_.text}`,children:[e.jsx(ze,{size:13}),e.jsx("span",{children:M.level==="CRITICAL"?n("highRiskWarning"):n("mediumRiskConfirm")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:N,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-accent-blue text-white text-sm font-medium hover:opacity-90 shadow-sm transition-all disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono bg-white/20 rounded px-1",children:"1"}),e.jsx("span",{children:Bt.allow.label}),e.jsx("span",{className:"text-[11px] text-white/70 hidden sm:inline",children:he})]}),e.jsxs("button",{onClick:W,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono text-dark-muted bg-dark-surface rounded px-1",children:"3"}),e.jsx("span",{children:Bt.allow_session.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:L})]}),e.jsxs("button",{onClick:ee,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono text-dark-muted bg-dark-surface rounded px-1",children:"4"}),e.jsx("span",{children:Bt.auto.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:V})]}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:$,disabled:h,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-dark-muted hover:bg-red-500/10 hover:text-red-400 text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"text-[10px] font-mono text-dark-muted/60 rounded px-1",children:"2"}),e.jsx("span",{children:Bt.deny.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:J})]})]}),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:C>0?n("morePending",{n:C}):n("lastItem")})]})]})})}const Is="dsc-auto-access-banner-dismissed",au=i.memo(function(){const{t}=Y(),n=Ee(c=>c.mode),[r,a]=i.useState(()=>localStorage.getItem(Is)==="1");i.useEffect(()=>{Ls(n==="normal"?"act":n)||localStorage.getItem(Is)==="1"&&a(!1)},[n]);const o=i.useCallback(c=>{c&&localStorage.setItem(Is,"1"),a(!0)},[]);return!(n!=="normal"&&Ls(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(Xa,{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:()=>o(!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(Ae,{size:11})}),e.jsx("button",{onClick:()=>o(!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")})]})}),ou=12,iu=56;function Xr(s,t){const n=s.replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}…`:n}function lu(s){return Xr(s,ou)}function ir(){return`custom-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function cu(s,t){return s.some(n=>n.kind==="scenario"&&n.id===t)}function du(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"&&typeof t.prompt=="string"&&t.prompt!==""}function uu(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(du)}function hu(s){const t=s("chat.start.categories",{returnObjects:!0,defaultValue:[]});return Array.isArray(t)?t.filter(uu):[]}const Qr=6;function mu(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,o=[];for(const l of t){if(a.has(l.id))continue;if(a.add(l.id),l.kind==="custom"){o.push({id:l.id,label:l.label,hint:Xr(l.prompt,iu),prompt:l.prompt});continue}const c=r.get(l.id);c&&o.push(c)}return Yr(o,n).slice(0,Qr)}function xu(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 fu(s,t,n){const r=s(xu(t)),a=(n??"").trim();return a?s("chat.start.withName",{greeting:r,name:a}):r}function Yr(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 pu(s,t){return s.length===0||!t?null:s.find(n=>n.id===t)??null}const Ce=Ko()(Oo((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 o=ir();const l=new Set(t().favorites.map(d=>d.id));for(;l.has(o);)o=ir();const c={kind:"custom",id:o,label:n.trim()||lu(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,o=n<1?Object.entries(r.clickCounts??{}).sort((l,c)=>c[1]-l[1]).slice(0,Qr).map(([l])=>l):r.favoriteIds??[];return{categoryId:r.categoryId??null,clickCounts:r.clickCounts??{},suggestionsHidden:a,favorites:o.map(l=>({kind:"scenario",id:l}))}}})),gu=i.lazy(()=>Po(()=>import("./ThreeScene-DFL_qzB1.js"),__vite__mapDeps([0,1,2,3])));function bu(){try{const s=document.createElement("canvas");return!!(s.getContext("webgl2")??s.getContext("webgl"))}catch{return!1}}function ku(){return i.useMemo(bu,[])?e.jsxs("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-0 hidden overflow-hidden dark:block [&_.threeui-background]:bg-transparent",children:[e.jsx(i.Suspense,{fallback:null,children:e.jsx(gu,{})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-b from-black/30 via-transparent to-black/40"})]}):null}function vu(){const[s,t]=i.useState(null);return i.useEffect(()=>{let n=!1;return ge.profile.get().then(r=>{if(n||!r.success||!r.data)return;const a=r.data;t(a.enabled!==!1&&a.name?a.name:null)}).catch(()=>{}),()=>{n=!0}},[]),s}const ju=i.memo(function(){return e.jsxs("div",{className:"relative flex min-h-[8.5rem] w-full flex-col justify-end pb-1",children:[e.jsx(ku,{}),e.jsx(yu,{}),e.jsx(Su,{})]})}),yu=i.memo(function(){const{t}=Y(),n=vu(),r=i.useMemo(()=>fu(t,new Date().getHours(),n),[t,n]);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:r}),e.jsx("span",{className:"block",children:t("chat.start.question")})]}),e.jsx(wu,{name:n})]})});function wu({name:s}){const{t}=Y(),n=s?t("chat.start.profileOn",{name:s}):t("chat.start.profileAnonymous"),r=i.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:r,title:t("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(eo,{size:11,"aria-hidden":"true",className:"shrink-0"}),e.jsx("span",{className:"truncate",children:n}),e.jsxs("span",{className:"shrink-0 text-dark-muted/70",children:["· ",t("chat.start.profileEdit")]})]})})}const Nu=[{glyph:"/",labelKey:"shortcuts.slashCommand"},{glyph:"@",labelKey:"shortcuts.fileRef"},{glyph:"!",labelKey:"shortcuts.shellCommand"},{glyph:"$",labelKey:"shortcuts.skillRef"}],Su=i.memo(function(){const{t}=Y();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:Nu.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))})}),Mu=i.memo(function({sessionId:t}){const{t:n}=Y(),r=i.useMemo(()=>hu(n),[n]),a=Ce(I=>I.categoryId),o=Ce(I=>I.setCategoryId),l=Ce(I=>I.clickCounts),c=Ce(I=>I.favorites),d=Ce(I=>I.recordUse),h=Ce(I=>I.toggleFavorite),f=Ce(I=>I.removeFavorite),u=Ce(I=>I.addCustomFavorite),p=Ce(I=>I.suggestionsHidden),g=Ce(I=>I.toggleSuggestions),j=Ce(I=>I.requestFocus),w=i.useMemo(()=>pu(r,a),[r,a]),b=i.useCallback(()=>o(null),[o]),x=i.useMemo(()=>w?Yr(w.scenarios,l):mu(r,c,l),[w,r,c,l]),[y,D]=i.useState(!1),[C,M]=i.useState(""),[_,K]=i.useState(""),S=i.useCallback(()=>{D(!1),M(""),K("")},[]),z=i.useCallback(()=>{D(!0),p&&g()},[p,g]),q=i.useCallback(I=>{I.preventDefault(),u(C,_)&&S()},[u,S,C,_]),T=i.useCallback(I=>{t&&(me.getState().setSessionInput(t,I.prompt),d(I.id),j())},[t,d,j]),F=i.useRef([]),[H,te]=i.useState(0),X=i.useCallback((I,k,N)=>{var $;if(I.key==="ArrowDown"||I.key==="ArrowUp"){I.preventDefault();const W=I.key==="ArrowDown"?Math.min(k+1,x.length-1):Math.max(k-1,0);te(W),($=F.current[W])==null||$.focus();return}if(I.key==="Tab"){I.preventDefault(),T(N);return}},[T,x.length]);return r.length===0?null:e.jsxs("div",{className:"start-col px-4 pb-4 sm:px-6",children:[e.jsxs("div",{role:"tablist","aria-label":n("chat.start.categoriesLabel"),onKeyDown:I=>{I.key==="Escape"&&a&&(I.preventDefault(),b())},className:"mt-5 flex items-center gap-2 overflow-x-auto pb-1",children:[r.map(I=>{const k=I.id===a;return e.jsxs("span",{"data-testid":"start-chip","data-category-id":I.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:()=>o(k?null:I.id),className:`py-1 text-[11px] transition-colors focus-visible:outline-none ${k?"pl-3 pr-1.5":"px-3"}`,children:I.label}),k&&e.jsx("button",{type:"button","data-testid":"start-chip-clear","aria-label":n("chat.start.clearCategory",{label:I.label}),title:n("chat.start.clearCategory",{label:I.label}),onClick:b,className:"py-1 pl-0 pr-2 text-white/75 transition-colors hover:text-white focus-visible:outline-none",children:e.jsx(Ae,{size:12,"aria-hidden":"true"})})]},I.id)}),e.jsx(Le,{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:[w?n("chat.start.categoryTitle",{label:w.label}):n("chat.start.frequentTitle"),e.jsx("span",{className:"ml-2 text-dark-muted/40",children:n(w?"chat.start.selectedHint":"chat.start.frequentHint")})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-3",children:[!w&&!y&&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(Qa,{size:11,"aria-hidden":"true"}),n("chat.start.customAdd")]}),e.jsx("button",{type:"button",onClick:g,className:"inline-flex items-center gap-1 text-[11px] text-dark-muted/60 transition-colors hover:text-dark-text",children:p?e.jsxs(e.Fragment,{children:[e.jsx(Us,{size:11,"aria-hidden":"true"}),n("chat.start.show")]}):e.jsxs(e.Fragment,{children:[e.jsx(Ya,{size:11,"aria-hidden":"true"}),n("chat.start.hide")]})})]})]}),y&&!w&&e.jsxs("form",{"data-testid":"start-custom-form",onSubmit:q,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:C,onChange:I=>M(I.target.value),placeholder:n("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:_,onChange:I=>K(I.target.value),placeholder:n("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:S,className:"rounded-md px-2.5 py-1 text-[11px] text-dark-muted transition-colors hover:text-dark-text",children:n("chat.start.customCancel")}),e.jsx("button",{type:"submit","data-testid":"start-custom-save",disabled:!_.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:n("chat.start.customSave")})]})]}),!p&&(x.length===0?y?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:n("chat.start.frequentEmpty")}):e.jsx("div",{className:"overflow-hidden rounded-xl border border-dark-border/60 bg-dark-surface/40",children:x.map((I,k)=>{const N=cu(c,I.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:$=>{F.current[k]=$},type:"button","data-testid":"start-row","data-scenario-id":I.id,tabIndex:k===H?0:-1,onClick:()=>T(I),onKeyDown:$=>X($,k,I),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:I.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:I.hint}),e.jsx(Js,{size:12,"aria-hidden":"true",className:"mt-0.5 shrink-0 text-dark-muted/40"})]}),w?e.jsx("button",{type:"button","data-testid":"start-row-favorite","aria-pressed":N,"aria-label":n(N?"chat.start.removeFavorite":"chat.start.addFavorite",{label:I.label}),title:n(N?"chat.start.removeFavorite":"chat.start.addFavorite",{label:I.label}),onClick:()=>h(I.id),className:`mr-2 shrink-0 rounded-md p-1.5 transition-colors focus-visible:outline-none ${N?"text-accent-yellow":"text-dark-muted/40 hover:text-dark-text"}`,children:e.jsx(Za,{size:13,"aria-hidden":"true",className:N?"fill-current":""})}):e.jsx("button",{type:"button","data-testid":"start-row-remove","aria-label":n("chat.start.removeFavorite",{label:I.label}),title:n("chat.start.removeFavorite",{label:I.label}),onClick:()=>f(I.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(Ae,{size:13,"aria-hidden":"true"})})]},I.id)})}))]})]})}),lr=24,cr=320,Cu={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"}},Eu=({status:s})=>s==="running"?e.jsx(Te,{size:12,className:"animate-spin text-accent-blue"}):s==="completed"?e.jsx(Jt,{size:12,className:"text-accent-green"}):s==="failed"?e.jsx(no,{size:12,className:"text-accent-red"}):s==="skipped"?e.jsx(ro,{size:12,className:"text-dark-muted"}):e.jsx(ao,{size:12,className:"text-dark-muted"}),dr={workflow:"WF",goal:"Goal",plan:"Plan",task:"Task",todo:"Todo",agent:"Agent"};function Tu(s){const t=new Map;for(const o of s)t.set(o.id,o);const n=new Map,r=[];for(const o of s){const c=o.source==="goal"&&o.dependencies&&o.dependencies[0]||void 0;if(c&&t.has(c)){const d=n.get(c)??[];d.push(o),n.set(c,d)}else r.push(o)}const a=(o,l)=>{const c=(n.get(o.id)??[]).filter(d=>!l.has(d.id)).map(d=>a(d,new Set(l).add(o.id)));return{task:o,children:c}};return r.map(o=>a(o,new Set))}const Au=i.memo(function s({node:t,depth:n}){const{task:r,children:a}=t,o=Cu[r.status],l=i.useMemo(()=>r.startedAt?ct((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 ${o.bg} border-dark-border`,style:{marginLeft:n*14},children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Eu,{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] ${o.color} shrink-0`,children:o.label}),r.source&&dr[r.source]&&e.jsx("span",{className:"rounded bg-dark-surface/80 px-1 py-px text-[9px] text-dark-muted",children:dr[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))})]})}),Iu=i.memo(function({sessionId:t,defaultExpanded:n,onClose:r}){const{t:a}=Y(),[o,l]=i.useState(n??!0),c=Ze(S=>S.tasksBySession[t]),d=i.useMemo(()=>Ze.getState().getTasksForSession(t),[t,c]),[h,f]=i.useState(null),u=i.useRef(null),p=i.useRef(!1),g=i.useRef(null),j=i.useCallback(S=>{var z;S.button===0&&(S.target.closest("[data-taskboard-close]")||(p.current=!1,u.current={y:S.clientY,expanded:o,bodyHeight:((z=g.current)==null?void 0:z.offsetHeight)??0},S.currentTarget.setPointerCapture(S.pointerId)))},[o]),w=i.useCallback(S=>{const z=u.current;z&&(Math.abs(S.clientY-z.y)>4&&(p.current=!0),f(S.clientY-z.y))},[]),b=i.useCallback(S=>{const z=u.current;if(!z)return;const q=S.clientY-z.y;z.expanded&&q<-lr?l(!1):!z.expanded&&q>lr&&l(!0),u.current=null,f(null),setTimeout(()=>{p.current=!1},0)},[]),x=i.useCallback(()=>{if(p.current){p.current=!1;return}l(S=>!S)},[]),y=i.useCallback(S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),l(z=>!z))},[]),D=h!==null,C=i.useMemo(()=>{const S=u.current;return h===null||!S?null:S.expanded?Math.min(cr,Math.max(0,S.bodyHeight+h)):Math.min(cr,Math.max(0,h))},[h]),M=i.useMemo(()=>{const S=d.length,z=d.filter(H=>H.status==="completed").length,q=d.filter(H=>H.status==="running").length,T=d.filter(H=>H.status==="failed").length,F=S>0?Math.round(z/S*100):0;return{total:S,completed:z,running:q,failed:T,progress:F}},[d]),_=i.useMemo(()=>Tu(d),[d]),K=o||D;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":o,onClick:x,onKeyDown:y,onPointerDown:j,onPointerMove:w,onPointerUp:b,onPointerCancel:b,onLostPointerCapture:b,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(to,{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:[M.completed,"/",M.total]}),M.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 ${M.running>0?"bg-accent-blue":M.failed>0?"bg-accent-red":"bg-accent-green"}`,style:{width:`${M.progress}%`}})}),M.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:S=>{S.stopPropagation(),r()},onKeyDown:S=>{S.key==="Enter"&&(S.stopPropagation(),r())},className:"p-0.5 rounded hover:bg-dark-hover transition-colors cursor-pointer",title:"Hide task drawer",children:e.jsx(Ae,{size:12,className:"text-dark-muted"})}),e.jsx(so,{size:12,className:"text-dark-muted/40 shrink-0","aria-hidden":"true"}),o?e.jsx(Mt,{size:14,className:"text-dark-muted"}):e.jsx(Ke,{size:14,className:"text-dark-muted"})]})]}),K&&e.jsx("div",{ref:g,className:"border-t border-dark-border",style:C!==null?{height:C,overflow:"hidden"}:void 0,children:e.jsx("div",{className:"px-2.5 py-2 max-h-[320px] overflow-y-auto custom-scrollbar",children:_.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:_.map(S=>e.jsx(Au,{node:S,depth:0},S.task.id))})})})]})}),Ru=[{mode:"chat",Icon:oo,labelKey:"trajectory.viewChat"},{mode:"trajectory",Icon:io,labelKey:"trajectory.viewTrajectory"}],ur=[],Bu=i.memo(function({tabs:t,activeSessionId:n,onSend:r,onStop:a,onPause:o,onResume:l,activeTab:c,setActiveTab:d,createNewSession:h,clearMessages:f,setTheme:u,setThemePreset:p,setLogs:g,setUnreadLogs:j,showTaskBoard:w=!0,onToggleTaskBoard:b,onRegenerate:x,onDeleteMessage:y,onOpenSidebarView:D,hookDrawerOpen:C,onCloseHookDrawer:M,questionDrawerOpen:_,onCloseQuestionDrawer:K,workspaceDir:S,onWorkspaceSelect:z,errorLogs:q,onOpenLogs:T}){const F=i.useMemo(()=>({setActiveTab:d,createNewSession:h,clearMessages:f,setTheme:u,setThemePreset:p,setLogs:g,setUnreadLogs:j}),[d,h,f,u,p,g,j]),[H,te]=i.useState("chat"),{t:X}=Y(),I=me(L=>n?L.messagesBySession[n]??ur:ur),k=me(L=>n?L.generatingSessions.includes(n):!1),N=me(L=>n?L.pausedSessions.includes(n):!1),$=t.find(L=>L.id===n)||null,W=i.useMemo(()=>I.filter(L=>!L.deleted).length===0,[I]),ee=Ce(L=>L.prefillNonce);i.useEffect(()=>{if(!n)return;let L=!1;return ge.tasks.list(n).then(V=>{if(L||!V.success||!Array.isArray(V.data))return;const ie={PENDING:"pending",RUNNING:"running",COMPLETED:"completed",FAILED:"failed",CANCELLED:"skipped"},xe=Date.now(),re=V.data.filter(E=>E.sessionId===n).map(E=>{const U=new Date(E.createdAt).getTime()||xe,fe=new Date(E.updatedAt).getTime()||xe;return{id:E.id,sessionId:n,title:E.title,status:ie[E.status]||"pending",source:"task",description:E.description,progress:E.progress,createdAt:U,updatedAt:fe,raw:E}});Ze.getState().setTasks(n,re,"task")}).catch(()=>{}),()=>{L=!0}},[n]);const se=i.useCallback((L,V,ie,xe,re,E)=>{if(!n)return;const U=xe||E?{...xe?{mentions:xe,mentionDeliveryMode:re}:{},...E?{display:E}:{}}:void 0;r(n,L,V,ie,U)},[r,n]),le=i.useCallback(async L=>{const V=n;if(!V)return;const ie=`shell_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,xe=Date.now();me.getState().addMessage(V,{id:ie,type:"user",content:`!${L}`,timestamp:xe,noTruncate:!0,shellRun:{command:L,stdout:"",stderr:"",exitCode:null,durationMs:0,running:!0}});const E=await ge.shell.exec(L,S),U=E.success&&E.data?{...E.data,running:!1}:{command:L,stdout:"",stderr:"",exitCode:null,durationMs:Date.now()-xe,running:!1,error:E.error||X("chat.shellRequestFailedGeneric")};me.getState().updateMessage(V,ie,{shellRun:U})},[n,S,X]),he=i.useCallback(L=>{n&&x&&x(n,L)},[x,n]),J=i.useCallback(L=>{n&&y&&y(n,L)},[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(au,{}),$&&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":X("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 ${H==="trajectory"?"translate-x-full bg-accent-blue/20 ring-accent-blue/40":"translate-x-0 bg-dark-hover ring-dark-border"}`}),Ru.map(({mode:L,Icon:V,labelKey:ie})=>{const xe=H===L;return e.jsxs("button",{type:"button",role:"radio","aria-checked":xe,title:X("trajectory.viewToggleTitle"),onClick:()=>te(L),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 ${xe?"text-dark-text":"text-dark-muted hover:text-dark-text"}`,children:[e.jsx(V,{size:11}),X(ie)]},L)})]})}),e.jsxs("div",{className:`relative flex min-h-0 flex-1 flex-col ${W&&H==="chat"?"justify-center overflow-y-auto custom-scrollbar py-2":""}`,children:[H==="chat"?e.jsx(e.Fragment,{children:W?e.jsx(ju,{}):e.jsxs(e.Fragment,{children:[e.jsx(Tl,{messages:I,isGenerating:k,isPaused:N,sessionId:$.id,onRegenerate:x?he:void 0,onDeleteMessage:y?J:void 0,onOpenSidebarView:D}),e.jsx(ru,{isOpen:!!C,onCloseModal:M}),e.jsx(nu,{isOpen:!!_,onClose:K??(()=>{})}),w&&e.jsx(Iu,{sessionId:$.id,defaultExpanded:!1,onClose:b},$.id)]})}):e.jsx(Jc,{sessionId:$.id,messages:I,errorLogs:q,onOpenLogs:T}),e.jsxs(e.Fragment,{children:[e.jsx(Ud,{activeSessionId:$.id}),e.jsx(eu,{sessionId:$.id})]}),e.jsx(Wd,{sessionId:$.id,onSend:se,onRunShell:le,onStop:()=>a($.id),onPause:()=>o($.id),onResume:()=>l($.id),slashOptions:F,workspaceDir:S,onWorkspaceSelect:z,focusRequest:ee}),H==="chat"&&W&&e.jsx(Mu,{sessionId:$.id})]})]})]})})});export{Bu as SessionGrid};
|