@deepseekcode/cli 1.0.26 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/cli.js +1057 -985
  2. package/package.json +31 -31
  3. package/web/dist/assets/{AutomationView-CPCd-Qhd.js → AutomationView-ClGqJM46.js} +1 -1
  4. package/web/dist/assets/{ChannelConfigView-D6JtjZyf.js → ChannelConfigView-BcGUdK94.js} +1 -1
  5. package/web/dist/assets/{ConnectorsView-BPPr7T9p.js → ConnectorsView-Dadj20jv.js} +1 -1
  6. package/web/dist/assets/{FileTreeView-CO8knuwu.js → FileTreeView-DLRQZmLP.js} +1 -1
  7. package/web/dist/assets/{HookConfigView-CYuzwf8u.js → HookConfigView-DE0NCrV9.js} +1 -1
  8. package/web/dist/assets/{ModelsView-Cji4mbXE.js → ModelsView-DVTuTql9.js} +1 -1
  9. package/web/dist/assets/{PluginsView-CKKnYKMP.js → PluginsView-DBF_BvKL.js} +1 -1
  10. package/web/dist/assets/SessionGrid-ByIAFTc2.js +38 -0
  11. package/web/dist/assets/SettingsPanel-CHRy0Xqj.js +4 -0
  12. package/web/dist/assets/{SkillsView-DmQGY9v0.js → SkillsView-BAorWQAI.js} +1 -1
  13. package/web/dist/assets/{TemplatesTab-_vSIuTZP.js → TemplatesTab-DEblm2pS.js} +1 -1
  14. package/web/dist/assets/{TerminalView-CTU0aA8o.js → TerminalView-Cnnipr8e.js} +1 -1
  15. package/web/dist/assets/ThreeScene-5Zi32o_j.js +2863 -0
  16. package/web/dist/assets/ThreeScene-DvOrMIoG.css +1 -0
  17. package/web/dist/assets/{ToolsView-DUEqePPo.js → ToolsView-lOHdaw4V.js} +1 -1
  18. package/web/dist/assets/{icons-qcawb7PZ.js → icons-DLsYqrD5.js} +144 -119
  19. package/web/dist/assets/index-Bht_ARrv.css +1 -0
  20. package/web/dist/assets/{index-DUpwXfa-.js → index-DEninW1j.js} +9 -9
  21. package/web/dist/assets/{markdown-yjmXQjrx.js → markdown-tZ6sw2sR.js} +1 -1
  22. package/web/dist/assets/{panels-CX_dYEv0.js → panels-wDJMsvra.js} +1 -1
  23. package/web/dist/assets/{react-vendor-CSlQceOk.js → react-vendor-BRkWBfPR.js} +1 -1
  24. package/web/dist/assets/{state-DOzZasIm.js → state-B80cA8v4.js} +1 -1
  25. package/web/dist/favicon.svg +38 -30
  26. package/web/dist/index.html +7 -7
  27. package/web/dist/logo.svg +38 -30
  28. package/web/dist/assets/SessionGrid-BOpVWUEK.js +0 -37
  29. package/web/dist/assets/SettingsPanel-R1fOoB25.js +0 -4
  30. package/web/dist/assets/index-DL2ULWxM.css +0 -1
@@ -1,37 +0,0 @@
1
- import{j as e}from"./markdown-yjmXQjrx.js";import{a,af as us,_ as xs,ak as Te,d as ge,K as ke,ae as rn,a1 as wt,aA as Se,X as Ee,aQ as mt,E as ps,$ as Ce,l as ht,L as Ie,u as vt,F as ft,aR as bt,aH as an,D as ln,k as on,aS as ms,aw as cn,aT as $t,aU as dn,h as Oe,al as un,i as hs,aV as xn,aW as pn,aX as mn,b as hn,aq as fn,aY as bn,aG as gn,O as jt,aZ as kn,a0 as Pt,B as yn,ap as wn,a_ as vn,n as fs,aN as Nt,aM as jn,a6 as bs,ab as Nn,a$ as Sn,b0 as Cn,ag as En,b1 as _n,f as An,S as Mn,t as zn,b2 as ze,y as Tn,b3 as In,m as Rn,b4 as $n,a2 as Pn,p as Dn,q as Ln,j as Bn}from"./icons-qcawb7PZ.js";import{D as Fn,d as le,h as Dt,u as G,i as On,j as gs,o as ks,k as qe,l as ys,w as ce,m as gt,b as Ne,R as ws,a as ue,t as ie,n as qn,s as Hn,r as Jn,f as Qe,p as be,q as Un,v as Wn,W as Kn,x as Gn,y as kt,c as Ze,z as Be,A as Zn,E as Vn,F as Qn,G as Xn,M as Yn,H as er,J as tr,K as vs,L as sr,N as nr,O as rr,Q as We,S as ar,T as js}from"./index-DUpwXfa-.js";import{r as lr}from"./react-vendor-CSlQceOk.js";import"./state-DOzZasIm.js";import"./panels-CX_dYEv0.js";class ir extends Fn{tokenize(t){return t.slice()}join(t){return t}removeEmpty(t){return t}}const or=new ir;function cr(r,t,s){return or.diff(r,t,s)}function Lt({value:r,max:t=100,size:s="md",variant:n="default",showLabel:l=!1,className:o}){const u=Math.min(Math.max(r/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:le("w-full",o),children:[e.jsx("div",{className:le("w-full bg-dark-border rounded-full overflow-hidden",c[s]),children:e.jsx("div",{className:le("h-full rounded-full transition-all duration-300",d[n]),style:{width:`${u}%`}})}),l&&e.jsxs("span",{className:"text-xs text-dark-muted mt-1",children:[Math.round(u),"%"]})]})}Prism.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]};Prism.languages.markup.tag.inside["attr-value"].inside.entity=Prism.languages.markup.entity;Prism.languages.markup.doctype.inside["internal-subset"].inside=Prism.languages.markup;Prism.hooks.add("wrap",function(r){r.type==="entity"&&(r.attributes.title=r.content.replace(/&amp;/,"&"))});Object.defineProperty(Prism.languages.markup.tag,"addInlined",{value:function(t,s){var n={};n["language-"+s]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:Prism.languages[s]},n.cdata=/^<!\[CDATA\[|\]\]>$/i;var l={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:n}};l["language-"+s]={pattern:/[\s\S]+/,inside:Prism.languages[s]};var o={};o[t]={pattern:RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g,function(){return t}),"i"),lookbehind:!0,greedy:!0,inside:l},Prism.languages.insertBefore("markup","cdata",o)}});Object.defineProperty(Prism.languages.markup.tag,"addAttribute",{value:function(r,t){Prism.languages.markup.tag.inside["special-attr"].push({pattern:RegExp(/(^|["'\s])/.source+"(?:"+r+")"+/\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))/.source,"i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,"language-"+t],inside:Prism.languages[t]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}});Prism.languages.html=Prism.languages.markup;Prism.languages.mathml=Prism.languages.markup;Prism.languages.svg=Prism.languages.markup;Prism.languages.xml=Prism.languages.extend("markup",{});Prism.languages.ssml=Prism.languages.xml;Prism.languages.atom=Prism.languages.xml;Prism.languages.rss=Prism.languages.xml;Prism.languages.go=Prism.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/,lookbehind:!0,greedy:!0},keyword:/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b/,boolean:/\b(?:_|false|iota|nil|true)\b/,number:[/\b0(?:b[01_]+|o[0-7_]+)i?\b/i,/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i,/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i],operator:/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./,builtin:/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/});Prism.languages.insertBefore("go","string",{char:{pattern:/'(?:\\.|[^'\\\r\n]){0,10}'/,greedy:!0}});delete Prism.languages.go["class-name"];var Bt={},Ft;function dr(){return Ft||(Ft=1,(function(r){for(var t=/\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source,s=0;s<2;s++)t=t.replace(/<self>/g,function(){return t});t=t.replace(/<self>/g,function(){return/[^\s\S]/.source}),r.languages.rust={comment:[{pattern:RegExp(/(^|[^\\])/.source+t),lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/b?"(?:\\[\s\S]|[^\\"])*"|b?r(#*)"(?:[^"]|"(?!\1))*"\1/,greedy:!0},char:{pattern:/b?'(?:\\(?:x[0-7][\da-fA-F]|u\{(?:[\da-fA-F]_*){1,6}\}|.)|[^\\\r\n\t'])'/,greedy:!0},attribute:{pattern:/#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/,greedy:!0,alias:"attr-name",inside:{string:null}},"closure-params":{pattern:/([=(,:]\s*|\bmove\s*)\|[^|]*\||\|[^|]*\|(?=\s*(?:\{|->))/,lookbehind:!0,greedy:!0,inside:{"closure-punctuation":{pattern:/^\||\|$/,alias:"punctuation"},rest:null}},"lifetime-annotation":{pattern:/'\w+/,alias:"symbol"},"fragment-specifier":{pattern:/(\$\w+:)[a-z]+/,lookbehind:!0,alias:"punctuation"},variable:/\$\w+/,"function-definition":{pattern:/(\bfn\s+)\w+/,lookbehind:!0,alias:"function"},"type-definition":{pattern:/(\b(?:enum|struct|trait|type|union)\s+)\w+/,lookbehind:!0,alias:"class-name"},"module-declaration":[{pattern:/(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/,lookbehind:!0,alias:"namespace"},{pattern:/(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/,lookbehind:!0,alias:"namespace",inside:{punctuation:/::/}}],keyword:[/\b(?:Self|abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,/\b(?:bool|char|f(?:32|64)|[ui](?:8|16|32|64|128|size)|str)\b/],function:/\b[a-z_]\w*(?=\s*(?:::\s*<|\())/,macro:{pattern:/\b\w+!/,alias:"property"},constant:/\b[A-Z_][A-Z_\d]+\b/,"class-name":/\b[A-Z]\w*\b/,namespace:{pattern:/(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/,inside:{punctuation:/::/}},number:/\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:(?:\d(?:_?\d)*)?\.)?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:f32|f64|[iu](?:8|16|32|64|size)?))?\b/,boolean:/\b(?:false|true)\b/,punctuation:/->|\.\.=|\.{1,3}|::|[{}[\];(),:]/,operator:/[-+*\/%!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?=?|[@?]/},r.languages.rust["closure-params"].inside.rest=r.languages.rust,r.languages.rust.attribute.inside.string=r.languages.rust.string})(Prism)),Bt}dr();var Ot={},qt;function ur(){return qt||(qt=1,(function(r){var t=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,s=/(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source,n={pattern:RegExp(/(^|[^\w.])/.source+s+/[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),lookbehind:!0,inside:{namespace:{pattern:/^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,inside:{punctuation:/\./}},punctuation:/\./}};r.languages.java=r.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,lookbehind:!0,greedy:!0},"class-name":[n,{pattern:RegExp(/(^|[^\w.])/.source+s+/[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),lookbehind:!0,inside:n.inside},{pattern:RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source+s+/[A-Z]\w*\b/.source),lookbehind:!0,inside:n.inside}],keyword:t,function:[r.languages.clike.function,{pattern:/(::\s*)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0},constant:/\b[A-Z][A-Z_\d]+\b/}),r.languages.insertBefore("java","string",{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:"string"},char:{pattern:/'(?:\\.|[^'\\\r\n]){1,6}'/,greedy:!0}}),r.languages.insertBefore("java","class-name",{annotation:{pattern:/(^|[^.])@\w+(?:\s*\.\s*\w+)*/,lookbehind:!0,alias:"punctuation"},generics:{pattern:/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,inside:{"class-name":n,keyword:t,punctuation:/[<>(),.:]/,operator:/[?&|]/}},import:[{pattern:RegExp(/(\bimport\s+)/.source+s+/(?:[A-Z]\w*|\*)(?=\s*;)/.source),lookbehind:!0,inside:{namespace:n.inside.namespace,punctuation:/\./,operator:/\*/,"class-name":/\w+/}},{pattern:RegExp(/(\bimport\s+static\s+)/.source+s+/(?:\w+|\*)(?=\s*;)/.source),lookbehind:!0,alias:"static",inside:{namespace:n.inside.namespace,static:/\b\w+$/,punctuation:/\./,operator:/\*/,"class-name":/\w+/}}],namespace:{pattern:RegExp(/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/.source.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0,inside:{punctuation:/\./}}})})(Prism)),Ot}ur();Prism.languages.c=Prism.languages.extend("clike",{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,lookbehind:!0},keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,function:/\b[a-z_]\w*(?=\s*\()/i,number:/(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/});Prism.languages.insertBefore("c","string",{char:{pattern:/'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,greedy:!0}});Prism.languages.insertBefore("c","string",{macro:{pattern:/(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:"property",inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},Prism.languages.c.string],char:Prism.languages.c.char,comment:Prism.languages.c.comment,"macro-name":[{pattern:/(^#\s*define\s+)\w+\b(?!\()/i,lookbehind:!0},{pattern:/(^#\s*define\s+)\w+\b(?=\()/i,lookbehind:!0,alias:"function"}],directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:"keyword"},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:Prism.languages.c}}}});Prism.languages.insertBefore("c","function",{constant:/\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/});delete Prism.languages.c.boolean;var Ht={},Jt;function xr(){return Jt||(Jt=1,(function(r){var t=/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,s=/\b(?!<keyword>)\w+(?:\s*\.\s*\w+)*\b/.source.replace(/<keyword>/g,function(){return t.source});r.languages.cpp=r.languages.extend("c",{"class-name":[{pattern:RegExp(/(\b(?:class|concept|enum|struct|typename)\s+)(?!<keyword>)\w+/.source.replace(/<keyword>/g,function(){return t.source})),lookbehind:!0},/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/],keyword:t,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,greedy:!0},operator:/>>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:false|true)\b/}),r.languages.insertBefore("cpp","string",{module:{pattern:RegExp(/(\b(?:import|module)\s+)/.source+"(?:"+/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|<[^<>\r\n]*>/.source+"|"+/<mod-name>(?:\s*:\s*<mod-name>)?|:\s*<mod-name>/.source.replace(/<mod-name>/g,function(){return s})+")"),lookbehind:!0,greedy:!0,inside:{string:/^[<"][\s\S]+/,operator:/:/,punctuation:/\./}},"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:"string",greedy:!0}}),r.languages.insertBefore("cpp","keyword",{"generic-function":{pattern:/\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,inside:{function:/^\w+/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:r.languages.cpp}}}}),r.languages.insertBefore("cpp","operator",{"double-colon":{pattern:/::/,alias:"punctuation"}}),r.languages.insertBefore("cpp","class-name",{"base-clause":{pattern:/(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,lookbehind:!0,greedy:!0,inside:r.languages.extend("cpp",{})}}),r.languages.insertBefore("inside","double-colon",{"class-name":/\b[a-z_]\w*\b(?!\s*::)/i},r.languages.cpp["base-clause"])})(Prism)),Ht}xr();(function(r){function t(s,n){return"___"+s.toUpperCase()+n+"___"}Object.defineProperties(r.languages["markup-templating"]={},{buildPlaceholders:{value:function(s,n,l,o){if(s.language===n){var u=s.tokenStack=[];s.code=s.code.replace(l,function(c){if(typeof o=="function"&&!o(c))return c;for(var d=u.length,i;s.code.indexOf(i=t(n,d))!==-1;)++d;return u[d]=c,i}),s.grammar=r.languages.markup}}},tokenizePlaceholders:{value:function(s,n){if(s.language!==n||!s.tokenStack)return;s.grammar=r.languages[n];var l=0,o=Object.keys(s.tokenStack);function u(c){for(var d=0;d<c.length&&!(l>=o.length);d++){var i=c[d];if(typeof i=="string"||i.content&&typeof i.content=="string"){var x=o[l],h=s.tokenStack[x],g=typeof i=="string"?i:i.content,k=t(n,x),b=g.indexOf(k);if(b>-1){++l;var w=g.substring(0,b),y=new r.Token(n,r.tokenize(h,s.grammar),"language-"+n,h),p=g.substring(b+k.length),C=[];w&&C.push.apply(C,u([w])),C.push(y),p&&C.push.apply(C,u([p])),typeof i=="string"?c.splice.apply(c,[d,1].concat(C)):i.content=C}}else i.content&&u(i.content)}return c}u(s.tokens)}}})})(Prism);var Ut={},Wt;function pr(){return Wt||(Wt=1,(function(r){var t=/\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/,s=[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},{pattern:/(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,greedy:!0,lookbehind:!0},/\b(?:null)\b/i,/\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/],n=/\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i,l=/<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/,o=/[{}\[\](),:;]/;r.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:t,variable:/\$+(?:\w+\b|(?=\{))/,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"class-name-definition":{pattern:/(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,lookbehind:!0,alias:"class-name"},"function-definition":{pattern:/(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,lookbehind:!0,alias:"function"},keyword:[{pattern:/(\(\s*)\b(?:array|bool|boolean|float|int|integer|object|string)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|object|self|static|string)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*(?:\?\s*)?)\b(?:array(?!\s*\()|bool|callable|(?:false|null)(?=\s*\|)|float|int|iterable|mixed|never|object|self|static|string|void)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:array(?!\s*\()|bool|float|int|iterable|mixed|object|string|void)\b/i,alias:"type-declaration",greedy:!0},{pattern:/(\|\s*)(?:false|null)\b|\b(?:false|null)(?=\s*\|)/i,alias:"type-declaration",greedy:!0,lookbehind:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(\byield\s+)from\b/i,lookbehind:!0},/\bclass\b/i,{pattern:/((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|match|namespace|never|new|or|parent|print|private|protected|public|readonly|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield|__halt_compiler)\b/i,lookbehind:!0}],"argument-name":{pattern:/([(,]\s*)\b[a-z_]\w*(?=\s*:(?!:))/i,lookbehind:!0},"class-name":[{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\|\s*)\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,greedy:!0},{pattern:/(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,alias:"class-name-fully-qualified",greedy:!0,inside:{punctuation:/\\/}},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*\$)/i,alias:"type-declaration",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-declaration"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:s,function:{pattern:/(^|[^\\\w])\\?[a-z_](?:[\w\\]*\w)?(?=\s*\()/i,lookbehind:!0,inside:{punctuation:/\\/}},property:{pattern:/(->\s*)\w+/,lookbehind:!0},number:n,operator:l,punctuation:o};var u={pattern:/\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,lookbehind:!0,inside:r.languages.php},c=[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:u}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:u}}];r.languages.insertBefore("php","variable",{string:c,attribute:{pattern:/#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,greedy:!0,inside:{"attribute-content":{pattern:/^(#\[)[\s\S]+(?=\]$)/,lookbehind:!0,inside:{comment:t,string:c,"attribute-class-name":[{pattern:/([^:]|^)\b[a-z_]\w*(?!\\)\b/i,alias:"class-name",greedy:!0,lookbehind:!0},{pattern:/([^:]|^)(?:\\?\b[a-z_]\w*)+/i,alias:["class-name","class-name-fully-qualified"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:s,number:n,operator:l,punctuation:o}},delimiter:{pattern:/^#\[|\]$/,alias:"punctuation"}}}}),r.hooks.add("before-tokenize",function(d){if(/<\?/.test(d.code)){var i=/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;r.languages["markup-templating"].buildPlaceholders(d,"php",i)}}),r.hooks.add("after-tokenize",function(d){r.languages["markup-templating"].tokenizePlaceholders(d,"php")})})(Prism)),Ut}pr();var Kt={},Gt;function mr(){return Gt||(Gt=1,(function(r){r.languages.ruby=r.languages.extend("clike",{comment:{pattern:/#.*|^=begin\s[\s\S]*?^=end/m,greedy:!0},"class-name":{pattern:/(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/,operator:/\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,punctuation:/[(){}[\].,;]/}),r.languages.insertBefore("ruby","operator",{"double-colon":{pattern:/::/,alias:"punctuation"}});var t={pattern:/((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,lookbehind:!0,inside:{content:{pattern:/^(#\{)[\s\S]+(?=\}$)/,lookbehind:!0,inside:r.languages.ruby},delimiter:{pattern:/^#\{|\}$/,alias:"punctuation"}}};delete r.languages.ruby.function;var s="(?:"+[/([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,/\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source,/\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source,/\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source,/<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source].join("|")+")",n=/(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source;r.languages.insertBefore("ruby","keyword",{"regex-literal":[{pattern:RegExp(/%r/.source+s+/[egimnosux]{0,6}/.source),greedy:!0,inside:{interpolation:t,regex:/[\s\S]+/}},{pattern:/(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,lookbehind:!0,greedy:!0,inside:{interpolation:t,regex:/[\s\S]+/}}],variable:/[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,symbol:[{pattern:RegExp(/(^|[^:]):/.source+n),lookbehind:!0,greedy:!0},{pattern:RegExp(/([\r\n{(,][ \t]*)/.source+n+/(?=:(?!:))/.source),lookbehind:!0,greedy:!0}],"method-definition":{pattern:/(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,lookbehind:!0,inside:{function:/\b\w+$/,keyword:/^self\b/,"class-name":/^\w+/,punctuation:/\./}}}),r.languages.insertBefore("ruby","string",{"string-literal":[{pattern:RegExp(/%[qQiIwWs]?/.source+s),greedy:!0,inside:{interpolation:t,string:/[\s\S]+/}},{pattern:/("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,greedy:!0,inside:{interpolation:t,string:/[\s\S]+/}},{pattern:/<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i,inside:{symbol:/\b\w+/,punctuation:/^<<[-~]?/}},interpolation:t,string:/[\s\S]+/}},{pattern:/<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,inside:{symbol:/\b\w+/,punctuation:/^<<[-~]?'|'$/}},string:/[\s\S]+/}}],"command-literal":[{pattern:RegExp(/%x/.source+s),greedy:!0,inside:{interpolation:t,command:{pattern:/[\s\S]+/,alias:"string"}}},{pattern:/`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,greedy:!0,inside:{interpolation:t,command:{pattern:/[\s\S]+/,alias:"string"}}}]}),delete r.languages.ruby.string,r.languages.insertBefore("ruby","number",{builtin:/\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/,constant:/\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/}),r.languages.rb=r.languages.ruby})(Prism)),Kt}mr();const hr=.4;function Zt(r){const t=[];let s=0;for(;s<r.length;){const n=r[s];if(/[\p{L}\p{N}_]/u.test(n)){let l=s+1;for(;l<r.length&&/[\p{L}\p{N}_]/u.test(r[l]);)l++;t.push(r.slice(s,l)),s=l}else if(/\s/.test(n)){let l=s+1;for(;l<r.length&&/\s/.test(r[l]);)l++;t.push(r.slice(s,l)),s=l}else{const o=r.codePointAt(s)>65535?2:1;t.push(r.slice(s,s+o)),s+=o}}return t}function fr(r,t){const s=cr(Zt(r),Zt(t)),n=r.length+t.length;let l=0;const o=[],u=[];let c=0,d=0;for(const i of s){const x=i.value.reduce((h,g)=>h+g.length,0);i.removed?(l+=x,o.push({start:c,end:c+x}),c+=x):i.added?(l+=x,u.push({start:d,end:d+x}),d+=x):(c+=x,d+=x)}return n>0&&l/n>hr?[[],[]]:[o,u]}function Ns(r){const t=[];let s=null;for(const n of r.split(`
2
- `)){if(n.startsWith("---")||n.startsWith("+++")||n.startsWith("index ")||n.startsWith("diff --git")||n.startsWith("==="))continue;const l=n.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(l){s&&t.push(s),s={oldStart:parseInt(l[1],10),oldLines:parseInt(l[2]??"1",10),newStart:parseInt(l[3],10),newLines:parseInt(l[4]??"1",10),lines:[]};continue}if(!n.startsWith("\\")){if(s&&(n.startsWith("+")||n.startsWith("-")||n.startsWith(" ")||n==="")){s.lines.push(n);continue}s&&n&&(t.push(s),s=null)}}return s&&t.push(s),t}function Ss(r){let t=r.oldStart,s=r.newStart;const n=[];for(const l of r.lines){const o=l[0]==="+"||l[0]==="-"?l[0]:" ",u=l.slice(1);let c=null,d=null;o==="-"?c=t++:(o==="+"||(c=t++),d=s++),n.push({marker:o,code:u,oldLine:c,newLine:d})}return n}const br=a.memo(function({filePath:t,content:s,language:n}){if(!s&&!t)return null;const[l,o]=a.useState("unified"),[u,c]=a.useState(!1),d=gr(t,n),i=(s==null?void 0:s.includes("@@"))||(s==null?void 0:s.includes("+++"))||(s==null?void 0:s.includes("---")),x=i?kr(s||""):null;return e.jsxs("div",{className:"mt-2 border border-dark-border rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-dark-surface border-b border-dark-border",children:[e.jsx("span",{className:"text-accent-purple text-xs",children:"📝"}),e.jsx("span",{className:"text-xs font-mono text-dark-fg truncate",children:t||"file"}),x&&e.jsxs("span",{className:"text-xs ml-2 flex gap-2",children:[e.jsxs("span",{className:"text-green-400",children:["+",x.additions]}),e.jsxs("span",{className:"text-red-400",children:["-",x.deletions]})]}),e.jsx("span",{className:"text-xs text-dark-muted ml-auto",children:d}),i&&e.jsxs("div",{className:"flex gap-0.5 ml-2",children:[e.jsx("button",{onClick:()=>o("unified"),className:`text-xs px-1.5 py-0.5 rounded ${l==="unified"?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-fg"}`,title:"Unified view",children:"Unified"}),e.jsx("button",{onClick:()=>o("side-by-side"),className:`text-xs px-1.5 py-0.5 rounded ${l==="side-by-side"?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-fg"}`,title:"Side-by-side view",children:"Side"})]}),e.jsx("button",{onClick:()=>c(!u),className:"text-xs text-dark-muted hover:text-dark-fg ml-1",children:u?"▶":"▼"})]}),!u&&e.jsxs("div",{className:"bg-dark-bg overflow-x-auto max-h-96 overflow-y-auto custom-scrollbar",children:[i?l==="unified"?jr(s||"",d):Nr(s||"",d):e.jsx("pre",{className:"text-xs font-mono p-2 text-dark-fg whitespace-pre-wrap",children:s||"(no content)"}),x&&e.jsxs("div",{className:"sticky bottom-0 bg-dark-surface border-t border-dark-border px-3 py-1 flex gap-4 text-xs text-dark-muted",children:[e.jsxs("span",{className:"text-green-400",children:["+",x.additions," additions"]}),e.jsxs("span",{className:"text-red-400",children:["-",x.deletions," deletions"]}),e.jsxs("span",{children:[x.hunks," hunks"]})]})]})]})});function gr(r,t){var l;if(t)return t;if(!r)return"plaintext";const s=(l=r.split(".").pop())==null?void 0:l.toLowerCase();return{ts:"typescript",tsx:"typescript",mts:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",py:"python",go:"go",rs:"rust",cpp:"cpp",cxx:"cpp",hpp:"cpp",cc:"cpp",c:"cpp",h:"cpp",css:"css",scss:"css",html:"markup",htm:"markup",svg:"markup",xml:"xml",json:"json",yml:"yaml",yaml:"yaml",md:"markdown",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",php:"php",rb:"ruby"}[s||""]||"plaintext"}function kr(r){const t=r.split(`
3
- `);let s=0,n=0,l=0;for(const o of t)o.startsWith("@@")?l++:o.startsWith("+")&&!o.startsWith("+++")?s++:o.startsWith("-")&&!o.startsWith("---")&&n++;return{additions:s,deletions:n,hunks:l,filesChanged:1}}function yr(r){const t=[],s=(l,o)=>{if(!o)return;const u=t[t.length-1];u&&u.type===l?u.text+=o:t.push({type:l,text:o})},n=(l,o)=>{if(typeof l=="string"){s(o,l);return}const u=l.type||o;if(typeof l.content=="string"){s(u,l.content);return}for(const c of l.content)n(c,u)};for(const l of r)n(l,"");return t}function Cs(r,t){const s=Dt.languages[t];if(!s)return[{type:"",text:r}];try{return yr(Dt.tokenize(r,s))}catch{return[{type:"",text:r}]}}function wr(r,t){if(t.length===0)return r.map(l=>({...l,word:!1}));const s=[];let n=0;for(const l of r){const o=n,u=n+l.text.length;let c=0;for(const d of t){const i=Math.max(0,d.start-o),x=Math.min(l.text.length,d.end-o);x<=0||i>=l.text.length||(i>c&&s.push({type:l.type,text:l.text.slice(c,i),word:!1}),s.push({type:l.type,text:l.text.slice(i,x),word:!0}),c=x)}c<l.text.length&&s.push({type:l.type,text:l.text.slice(c),word:!1}),n=u}return s}function vr({code:r,marker:t,lang:s,ranges:n}){const l=t==="-"?[{type:"",text:r}]:Cs(r,s),o=wr(l,n),u=t==="+"?"bg-green-900/30":t==="-"?"bg-red-900/30":"",c=t==="+"?"bg-green-700/60":"bg-red-700/60";return e.jsx("span",{className:`flex-1 whitespace-pre-wrap px-2 ${u}`,children:o.length===0?" ":o.map((d,i)=>e.jsx("span",{className:[d.type?`token ${d.type}`:"",d.word&&t!==" "?c:""].join(" "),children:d.text},i))})}function jr(r,t){const s=Ns(r);if(s.length===0)return e.jsx("pre",{className:"text-xs font-mono p-2 text-dark-fg whitespace-pre-wrap",children:r});const n=[];let l=0;for(const o of s){const u=Ss(o);n.push(e.jsxs("div",{className:"flex text-xs font-mono leading-snug bg-accent-blue/5 text-accent-blue font-bold px-2",style:{minHeight:"1.25rem"},children:[e.jsx("span",{className:"select-none shrink-0 text-right pr-1",children:"@"}),e.jsxs("span",{className:"flex-1 whitespace-pre-wrap",children:["@@ -",o.oldStart,",",o.oldLines," +",o.newStart,",",o.newLines," @@"]})]},l++));const c=new Map;for(let d=0;d<u.length;){if(u[d].marker!=="-"){d++;continue}const i=d;for(;d<u.length&&u[d].marker==="-";)d++;const x=d;for(;d<u.length&&u[d].marker==="+";)d++;const h=Math.min(x-i,d-x);for(let g=0;g<h;g++){const[k,b]=fr(u[i+g].code,u[x+g].code);c.set(i+g,k),c.set(x+g,b)}}for(let d=0;d<u.length;d++){const i=u[d],x=i.marker==="+",h=i.marker==="-",g=x?"bg-green-900/30":h?"bg-red-900/30":"",k=i.marker==="-"?i.oldLine:i.newLine;n.push(e.jsxs("div",{className:"flex text-xs font-mono leading-snug",style:{minHeight:"1.25rem"},children:[e.jsxs("span",{className:`select-none shrink-0 w-9 text-right pr-1 ${g} ${x?"text-green-400":h?"text-red-400":"text-dark-muted"}`,children:[i.marker===" "?"":i.marker,k??""]}),e.jsx(vr,{code:i.code,marker:i.marker,lang:t,ranges:c.get(d)??[]})]},l++))}}return e.jsx("div",{children:n})}function Vt({code:r,lang:t,kind:s}){if(r==="")return e.jsx("span",{className:"flex-1 px-2 border-r border-dark-border/30 font-mono text-xs leading-snug",style:{minHeight:"1.25rem"},children:" "});const n=s==="remove"?[{type:"",text:r}]:Cs(r,t),l=s==="add"?"bg-green-900/30":s==="remove"?"bg-red-900/30":"";return e.jsx("span",{className:`flex-1 px-2 border-r border-dark-border/30 font-mono text-xs leading-snug ${l}`,children:n.map((o,u)=>e.jsx("span",{className:o.type?`token ${o.type}`:"",children:o.text},u))})}function Nr(r,t){const s=Ns(r);if(s.length===0)return e.jsx("pre",{className:"text-xs font-mono p-2 text-dark-fg whitespace-pre-wrap",children:r});const n=[];for(const l of s){const o=Ss(l);n.push({left:`@@ -${l.oldStart},${l.oldLines} +${l.newStart},${l.newLines} @@`,right:"",type:"header"});let u=[],c=[];const d=()=>{(u.length>0||c.length>0)&&(Sr(n,u,c),u=[],c=[])};for(const i of o)i.marker==="-"?u.push(i.code):i.marker==="+"?c.push(i.code):(d(),n.push({left:i.code,right:i.code,type:"context"}));d()}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex border-b border-dark-border text-xs font-bold text-dark-muted",children:[e.jsx("div",{className:"flex-1 px-2 py-0.5 border-r border-dark-border",children:"Old"}),e.jsx("div",{className:"flex-1 px-2 py-0.5",children:"New"})]}),n.map((l,o)=>l.type==="header"?e.jsx("div",{className:"bg-accent-blue/5 text-accent-blue font-bold font-mono text-xs leading-snug px-2",children:l.left},o):e.jsxs("div",{className:"flex",style:{minHeight:"1.25rem"},children:[e.jsx(Vt,{code:l.type==="replace"||l.type==="delete"?"- "+l.left:l.left,lang:t,kind:l.type==="replace"||l.type==="delete"?"remove":"context"}),e.jsx(Vt,{code:l.type==="replace"||l.type==="add"?"+ "+l.right:l.right,lang:t,kind:l.type==="replace"||l.type==="add"?"add":"context"})]},o))]})}function Sr(r,t,s){const n=Math.max(t.length,s.length);for(let l=0;l<n;l++){const o=l<t.length?t[l]??"":"",u=l<s.length?s[l]??"":"";r.push({left:o,right:u,type:l<t.length&&l<s.length?"replace":l<t.length?"delete":"add"})}}function Es(r){const t=a.useRef(null),s=a.useRef(0);return a.useEffect(()=>{if(!r){s.current=0;return}s.current=Date.now();const n=t.current;if(!n)return;const l=()=>{const u=Math.floor((Date.now()-s.current)/1e3),c=u>=60?`${Math.floor(u/60)}m ${u%60}s`:`${u}s`;n.textContent=c};l();const o=setInterval(l,1e3);return()=>clearInterval(o)},[r]),t}function Cr(r){return typeof r=="string"?r:r&&typeof r=="object"?JSON.stringify(r,null,2):String(r??"")}const Qt=20,Er=/\b(grep|search_contents)\b/i;function _r(r){return r===""?0:r.split(`
4
- `).length}const Xt=a.memo(function({toolCall:t,defaultCollapsed:s=!0}){const{t:n}=G(),l=t.status==="running",o=Es(l),u=t.result!==void 0&&t.result!==null,c=t.status==="error",d=On(t.name),i=u?Cr(t.result):"",x=u?_r(i):0,h=Er.test(t.name),g=t.noTruncate!==!0&&h&&u&&!c&&x>Qt,[k,b]=a.useState(!1),w=g&&!k?i.split(`
5
- `).slice(0,Qt).join(`
6
- `)+`
7
- ${n("toolCall.linesTotal",{n:x})}`:i,y=t.diff||(d&&i&&(i.includes("@@")||i.includes("+++")||i.includes("---"))?i:void 0),p=gs(t.args),[C,F]=a.useState(s),E=t.duration??0,z=E>0?E>=60?`${Math.floor(E/60)}m ${E%60}s`:`${E}s`:"",L=l?"bg-accent-blue":c?"bg-accent-red":"bg-accent-green",j=l?"running":c?"error":"success";return e.jsxs("div",{className:"tl-row 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:()=>F(!C),children:[e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:l?e.jsx("span",{className:"inline-block h-3 w-3 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:`tl-node ${L}`,"data-status":j})}),e.jsx("span",{className:"text-dark-muted shrink-0",children:e.jsx(us,{size:12,"aria-hidden":"true"})}),e.jsx("span",{className:`font-medium text-[13px] truncate ${l?"text-shimmer":"text-dark-text"}`,children:t.name}),d&&p&&!c&&e.jsxs("button",{type:"button",onClick:N=>{N.stopPropagation(),ks(p)},className:`flex items-center gap-1 max-w-[16rem] shrink truncate rounded-full border border-dark-border/70 px-2 py-0.5 text-[11px] font-mono text-accent-blue
8
- hover:bg-dark-hover hover:border-accent-blue/40 transition-colors`,title:p,children:[e.jsx(xs,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:p})]}),l&&e.jsxs("span",{className:"text-[11px] text-accent-blue shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(Te,{size:10}),e.jsx("span",{ref:o,children:"0s"})]}),!l&&z&&e.jsxs("span",{className:"text-[10px] text-dark-muted shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(Te,{size:10}),e.jsx("span",{children:z})]}),e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${C?"":"rotate-180"}`,children:e.jsx(ge,{size:13})})]}),!C&&e.jsxs("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25 space-y-1",children:[e.jsxs("div",{className:"py-0.5 px-2",children:[e.jsx("div",{className:"text-[10px] text-dark-muted mb-0.5",children:n("step.params")}),e.jsx("pre",{className:"text-[11px] font-mono bg-dark-bg border border-dark-border p-2 rounded overflow-x-auto max-h-24 overflow-y-auto custom-scrollbar",children:typeof t.args=="string"?t.args:JSON.stringify(t.args,null,2)})]}),u&&e.jsxs("div",{className:"py-0.5 px-2",children:[e.jsx("div",{className:`text-[10px] mb-0.5 ${c?"text-accent-red":"text-accent-green"}`,children:n(c?"step.error":"step.result")}),d&&(y||i)?e.jsx(br,{filePath:p,content:y||i}):e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:`text-[11px] font-mono bg-dark-bg border border-dark-border p-2 rounded overflow-x-auto max-h-48 overflow-y-auto custom-scrollbar whitespace-pre-wrap break-all ${c?"text-accent-red":"text-accent-green"}`,children:w}),g&&e.jsx("button",{type:"button","data-testid":"grep-result-toggle",onClick:()=>b(N=>!N),className:"mt-1 text-[10px] text-accent-blue hover:underline",children:k?n("toolCall.collapse"):n("toolCall.expandAll",{n:x})})]})]})]})]})}),St=a.memo(function({toolCalls:t,label:s,defaultCollapsed:n=!0}){const{t:l}=G(),[o,u]=a.useState(n),c=a.useMemo(()=>{const w=new Map;for(const y of t)w.set(y.name,(w.get(y.name)??0)+1);return[...w.entries()].sort((y,p)=>p[1]-y[1])},[t]),d=a.useMemo(()=>t.some(w=>w.status==="running")?"running":t.some(w=>w.status==="error")?"error":"completed",[t]);if(t.length===0)return null;if(t.length===1){const w=t[0];return e.jsx(Xt,{toolCall:w})}const x=c.slice(0,3),h=c.length-x.length,g=t.reduce((w,y)=>w+(y.duration??0),0),k=g>=60?`${Math.floor(g/60)}m ${g%60}s`:g>=1?`${g}s`:"",b=d==="running"?"bg-accent-blue":d==="error"?"bg-accent-red":"bg-accent-green";return e.jsxs("div",{className:"tl-row rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"toolcall-group",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:()=>u(!o),"data-testid":"toolcall-group-toggle",children:[e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:d==="running"?e.jsx("span",{className:"inline-block w-3 h-3 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:`w-2 h-2 rounded-full ${b}`})}),e.jsx("span",{className:"text-dark-muted shrink-0",children:e.jsx(us,{size:12,"aria-hidden":"true"})}),e.jsx("span",{className:"font-medium text-[13px] text-dark-text shrink-0","data-testid":"toolcall-group-count",children:l("activity.toolCallCount",{count:t.length})}),x.map(([w,y])=>e.jsxs("span",{className:"shrink-0 rounded-full bg-dark-muted/10 px-1.5 py-px text-[10.5px] font-mono text-dark-muted",children:[w," ×",y]},w)),h>0&&e.jsx("span",{className:"shrink-0 text-[10.5px] text-dark-muted",children:l("activity.toolNamesMore",{count:h})}),k&&e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted tabular-nums",children:k}),e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${o?"":"rotate-180"}`,children:e.jsx(ge,{size:13})})]}),!o&&e.jsxs("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25 space-y-0.5",children:[e.jsx("div",{className:"px-2 pt-0.5 text-[10px] uppercase tracking-wide text-dark-muted/60",children:s??l("activity.evidence")}),t.map(w=>e.jsx(Xt,{toolCall:w},w.id))]})]})}),Ar=a.memo(function({text:t,maxLength:s=300,preformatted:n=!1}){const{t:l}=G(),[o,u]=a.useState(!1);return t.length>s?e.jsxs("div",{children:[n?e.jsx("pre",{className:"text-xs font-mono bg-dark-bg p-1.5 rounded overflow-x-auto custom-scrollbar mt-1 text-accent-green",children:o?t:t.slice(0,s)+"..."}):e.jsx("div",{className:"text-dark-text leading-snug",children:o?t:t.slice(0,s)+"..."}),e.jsx("button",{onClick:d=>{d.stopPropagation(),u(!o)},className:"mt-1 text-[10px] px-2 py-0.5 rounded bg-dark-hover text-accent-blue hover:bg-dark-border transition-colors",children:l(o?"common.collapse_short":"common.expand")})]}):n?e.jsx("pre",{className:"text-xs font-mono bg-dark-bg p-1.5 rounded overflow-x-auto custom-scrollbar mt-1 text-accent-green",children:t}):e.jsx("div",{className:"text-dark-text leading-snug",children:t})}),Mr=a.memo(function({step:t,defaultCollapsed:s=!0}){const{t:n}=G(),[l,o]=a.useState(s),[u,c]=a.useState(!0),d=t.status==="running",i=Es(d),x=t.description||t.thought||t.result||t.action||t.toolCalls&&t.toolCalls.length>0,h=t.duration??0,g=h>0?h>=60?`${Math.floor(h/60)}m ${h%60}s`:`${h}s`:"";return e.jsxs("div",{className:"tl-row rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"step-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:()=>x&&o(!l),children:[e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:e.jsx("span",{className:"tl-node","data-status":t.status})}),e.jsx("span",{className:`text-[13px] truncate ${d?"text-shimmer":"text-dark-text"}`,children:t.title}),d&&e.jsxs("span",{className:"text-[11px] text-accent-blue shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(Te,{size:10}),e.jsx("span",{ref:i,children:"0s"})]}),!d&&g&&e.jsxs("span",{className:"text-[10px] text-dark-muted shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(Te,{size:10}),e.jsx("span",{children:g})]}),x&&e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${l?"":"rotate-180"}`,children:e.jsx(ge,{size:13})})]}),!l&&x&&e.jsxs("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25 space-y-1",children:[t.description&&e.jsx("div",{className:"text-dark-muted py-0.5 px-2 text-xs",children:t.description}),t.thought&&e.jsxs("div",{className:"py-0.5 px-2 text-xs border-l-2 border-accent-purple/40 bg-accent-purple/5 rounded-r",children:[e.jsxs("div",{className:"flex items-center gap-1 text-accent-purple cursor-pointer hover:opacity-80 select-none",onClick:()=>c(!u),children:[u?e.jsx(ke,{size:12}):e.jsx(ge,{size:12}),e.jsx(rn,{size:12,"aria-hidden":"true"}),e.jsx("span",{children:n("step.thinking")}),u&&e.jsxs("span",{className:"text-[10px] text-dark-muted truncate max-w-[200px]",children:[t.thought.slice(0,80).replace(/\n/g," "),"..."]})]}),!u&&e.jsx("div",{className:"text-dark-muted italic whitespace-pre-wrap leading-snug mt-1",children:t.thought.replace(/\n\s*\n+/g,`
9
- `)})]}),t.action&&e.jsxs("div",{className:"py-0.5 px-2 text-xs border-l-2 border-accent-yellow/40 bg-accent-yellow/5 rounded-r",children:[e.jsxs("div",{className:"flex items-center gap-1 text-accent-yellow mb-0.5",children:[e.jsx(wt,{size:12,"aria-hidden":"true"}),e.jsx("span",{children:n("step.action")})]}),e.jsx("div",{className:"text-dark-text leading-snug font-mono text-[11px]",children:t.action})]}),t.toolCalls&&t.toolCalls.length>0&&e.jsx("div",{className:"px-1 py-0.5",children:e.jsx(St,{toolCalls:t.toolCalls})}),t.result&&e.jsxs("div",{className:"py-0.5 px-2 text-xs border-l-2 border-accent-green/40 bg-accent-green/5 rounded-r",children:[e.jsxs("div",{className:"flex items-center gap-1 text-accent-green mb-0.5",children:[e.jsx(Se,{size:12,"aria-hidden":"true"}),e.jsx("span",{children:n("step.result")})]}),e.jsx(Ar,{text:t.result,maxLength:500})]})]})]})}),zr=a.memo(function({steps:t,isGenerating:s}){const{t:n}=G(),[l,o]=a.useState(s),u=a.useRef(s);a.useEffect(()=>{u.current&&!s&&o(!1),u.current=s},[s]);const c=t.length,d=s||t.some(k=>k.status==="running"),i=[...t].reverse().find(k=>k.status==="running"),x=t[t.length-1],h=(i==null?void 0:i.title)||(x==null?void 0:x.title)||"",g=`${c} ${n(c===1?"chat.stepCount":"chat.stepCountPlural")}`;return e.jsxs("div",{className:"mb-1 rounded-lg border border-dark-border/50 transition-colors","data-testid":"turn-group",children:[e.jsxs("button",{className:"flex w-full items-center gap-2 px-2 py-1 text-left cursor-pointer select-none hover:bg-dark-surface/40",onClick:()=>o(!l),"data-testid":"turn-group-toggle",children:[e.jsx("span",{className:"shrink-0 text-dark-muted/60 transition-transform",children:l?e.jsx(ge,{size:13}):e.jsx(ke,{size:13})}),d?e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:e.jsx("span",{className:"tl-node bg-accent-blue","data-status":"running"})}):e.jsx("span",{className:"w-2 h-2 shrink-0 rounded-full bg-accent-green"}),e.jsx("span",{className:`text-xs ${d?"text-shimmer":"text-dark-muted"}`,children:d?`${n("chat.runningSteps")} ${g}…`:g}),d&&h&&e.jsxs("span",{className:"min-w-0 flex-1 truncate pl-1 text-xs text-dark-muted/70",children:["· ",h]})]}),l&&e.jsx("div",{className:"ml-[15px] pb-1 pl-3 border-l border-dark-border/25 space-y-0.5",children:t.map(k=>e.jsx(Mr,{step:k},k.id))})]})});function _s(r){const t=r??"";let s=t,n=null,l=null;try{const o=JSON.parse(t);if(o&&typeof o=="object")if("payload"in o){l=typeof o.toolName=="string"?o.toolName:null;const u=o.payload;typeof u=="string"?s=u:u&&typeof u=="object"?(n=u,s=JSON.stringify(u,null,2)):s=""}else Array.isArray(o)||(n=o)}catch{s=t}if(!n&&s.length>0&&/^[\s]*[{[]/.test(s))try{const o=JSON.parse(s);o&&typeof o=="object"&&!Array.isArray(o)&&(n=o)}catch{}return{toolName:l,payloadText:s,args:n}}const Ct=/\b(bash|shell|exec|cmd|powershell|terminal)\b/i,As=/write_file|write|save|create|upload|deploy|publish/i,Ms=/edit_file|edit|patch|apply|update|replace/i,zs=/read_file|read|view|cat|open|list|dir\b/i,Tr=/file_delete|delete|remove|unlink|\brm\b|\bdel\b/i,Ir=/\b(glob|find|locate)\b/i,Rr=/\b(grep|rg|search_contents)\b/i,$r=/web_search|search_web|browse/i,Ts=/web_fetch|fetch|http|curl|wget|download|request|api/i,Pr=/git|commit|merge|rebase|push|checkout/i,Dr=/install|uninstall|npm|pnpm|yarn|pip|cargo|gem|apt|brew|choco/i,Et=/send_message|send_file|message|notify|post/i;function Is(r){const t=r.toLowerCase();return Ct.test(t)?"verbRunCommand":$r.test(t)?"verbSearchWeb":As.test(t)?"verbWriteFile":Ms.test(t)?"verbEditFile":Tr.test(t)?"verbDeleteFile":zs.test(t)?"verbReadFile":Rr.test(t)?"verbSearchContents":Ir.test(t)?"verbFindFiles":Ts.test(t)?"verbFetchUrl":Pr.test(t)?"verbGit":Dr.test(t)?"verbInstall":Et.test(t)?"verbSendMessage":"verbRunTool"}function rt(r,t){const s=(r??"").replace(/\s+/g," ").trim();return s.length>t?`${s.slice(0,t-1)}…`:s}function Lr(r){if(!r)return null;for(const t of["file_path","filePath","path","file","target"]){const s=r[t];if(typeof s=="string"&&s.length>0)return s}return null}function Rs(r,t){const{payloadText:s,args:n}=_s(t),l=r.toLowerCase();if(Ct.test(l))return"";const o=Lr(n);if(o)return o;const u=s.match(/(?:file_path|path|file)["\s:=]+([^\s",}]+)/i);if(u!=null&&u[1])return u[1];if(Ts.test(l)&&typeof(n==null?void 0:n.url)=="string"&&n.url)return rt(n.url,48);if(Et.test(l)){const c=typeof(n==null?void 0:n.text)=="string"?n.text:typeof(n==null?void 0:n.message)=="string"?n.message:s;return rt(c,48)}return rt(s,48)}function $s(r,t){const{payloadText:s,args:n}=_s(t),l=r.toLowerCase();if(Ct.test(l)){const o=typeof(n==null?void 0:n.command)=="string"?n.command:s;return o?{text:o,mono:!0}:null}if(As.test(l)||Ms.test(l)){const o=typeof(n==null?void 0:n.content)=="string"?n.content:typeof(n==null?void 0:n.data)=="string"?n.data:"";if(o)return{text:o,mono:!0};if(n){const u=Yt(n);if(u)return{text:u,mono:!0}}return s?{text:s,mono:!0}:null}if(Et.test(l)){const o=typeof(n==null?void 0:n.text)=="string"?n.text:typeof(n==null?void 0:n.message)=="string"?n.message:s;return o?{text:o,mono:!1}:null}if(zs.test(l))return null;if(n){const o=Yt(n);if(o)return{text:o,mono:!0}}return s?{text:s,mono:!0}:null}function Yt(r){return r?Object.entries(r).filter(([,t])=>t!=null).map(([t,s])=>{let n=typeof s=="string"?s:JSON.stringify(s);return n.length>96&&(n=`${n.slice(0,95)}…`),`${t}=${n.replace(/\n/g," ")}`}).join(" "):""}function Ps(r,t){const s=qe(t);return s?{path:s,external:!0}:{key:"scopeLocal",external:!1}}function Ds({pre:r,obj:t}){return e.jsxs("span",{className:"min-w-0 text-sm text-dark-muted",children:[e.jsx("span",{children:r}),t&&e.jsx("b",{className:"font-semibold text-dark-text",children:t})]})}const at=5,lt=420;function yt({text:r,mono:t=!0}){const{t:s}=G("hook"),[n,l]=a.useState(!1),o=r.split(`
10
- `),u=o.length>at||r.length>lt;let c=r;!n&&u&&(c=o.slice(0,at).join(`
11
- `),c.length>lt&&(c=`${c.slice(0,lt).trimEnd()}…`));const d=n?s("showLess"):o.length>at?s("showAllLines",{n:o.length}):s("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,u&&e.jsx("button",{type:"button",onClick:()=>l(i=>!i),className:"mt-1 block text-[11px] text-accent-blue hover:underline",children:d})]})}const it=15,Br=a.memo(function({approval:t,onResolved:s}){const{t:n}=G("hook"),[l,o]=a.useState(!1),[u,c]=a.useState(it),d=a.useRef(null),i=t.status==="pending",{level:x,reasonKey:h}=ys(t.toolName,t.askPayload),g=ws[x],k=$s(t.toolName,t.askPayload),b=Ps(t.toolName,t.askPayload),w=qe(t.askPayload)!==null;a.useEffect(()=>{if(i)return c(it),d.current=setInterval(()=>{c(N=>N<=1?(d.current&&clearInterval(d.current),0):N-1)},1e3),()=>{d.current&&clearInterval(d.current)}},[i,t.approvalId]),a.useEffect(()=>{const N=(t.timeoutMs??15e3)>0;u===0&&i&&!l&&N&&y()},[u]);const y=a.useCallback(()=>{!i||l||(o(!0),d.current&&clearInterval(d.current),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),s==null||s(t.approvalId,"approved"))},[i,l,t.approvalId,s]),p=a.useCallback(()=>{!i||l||(o(!0),d.current&&clearInterval(d.current),ce.send({type:"hook_deny",data:JSON.stringify({approvalId:t.approvalId})}),s==null||s(t.approvalId,"denied"))},[i,l,t.approvalId,s]),C=a.useCallback(()=>{if(!i||l)return;o(!0),d.current&&clearInterval(d.current);const N=gt.getState(),D=qe(t.askPayload);D?(N.addToSessionAllowList(t.toolName,D),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId,sessionAllow:!0})})):(N.addToSessionAllowList(t.toolName),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})})),s==null||s(t.approvalId,"approved")},[i,l,t.approvalId,t.toolName,t.askPayload,s]),F=a.useCallback(()=>{!i||l||(o(!0),d.current&&clearInterval(d.current),gt.getState().setAutoMode(!0),Ne.getState().setAuto(!0),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),s==null||s(t.approvalId,"approved"))},[i,l,t.approvalId,s]);if(!i){const N=t.status==="approved";return e.jsx("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${N?"bg-accent-green/10 border border-accent-green/30 text-accent-green":"bg-accent-red/10 border border-accent-red/30 text-accent-red"}`,children:N?e.jsxs(e.Fragment,{children:[e.jsx(Se,{size:14}),e.jsxs("span",{children:[n("alreadyAllowed"),t.toolName]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ee,{size:14}),e.jsxs("span",{children:[n("alreadyDenied"),t.toolName]})]})})}const E=u/it*100,z=u<=5,L=[{id:"allow",index:1,label:n("optionAllow"),hint:n("optionAllowHint"),action:y,kind:"primary"},{id:"allow_session",index:3,label:n("optionAllowAlways"),hint:w?n("optionAllowPathHint"):n("optionAllowAlwaysHint",{tool:t.toolName}),action:C,kind:"secondary"},{id:"auto_mode",index:4,label:n("optionAutoMode"),hint:n("optionAutoModeHint"),action:F,kind:"secondary"},{id:"deny",index:2,label:n("optionDeny"),hint:n("optionDenyHint"),action:p,kind:"danger"}],j={primary:"bg-accent-blue text-white hover:opacity-90 shadow-sm",secondary:"border border-dark-border bg-dark-bg text-dark-text hover:bg-dark-hover",danger:"text-dark-muted hover:bg-red-500/10 hover:text-red-400"};return e.jsxs("div",{className:`bg-dark-bg border rounded-xl overflow-hidden ${b.external?"border-amber-500/40":g.border}`,children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 border-b ${g.bg} ${b.external?"border-amber-500/30":g.border}`,children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${rc.badge}",children:[g.icon," ",x]}),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(mt,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Ds,{pre:n(Is(t.toolName)),obj:Rs(t.toolName,t.askPayload)})}),b.external&&b.path?e.jsxs("span",{className:"flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/30 shrink-0",title:b.path,children:[e.jsx(ps,{size:10}),b.path.length>32?`${b.path.slice(0,31)}…`:b.path]}):e.jsx("span",{className:"text-[10px] text-dark-muted/60 shrink-0",children:n("scopeLocal")}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-1 shrink-0",children:[e.jsx(Te,{size:11,className:z?"text-accent-red":"text-dark-muted"}),e.jsxs("span",{className:`text-[11px] font-mono ${z?"text-accent-red animate-pulse":"text-dark-muted"}`,children:[u,"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 ${z?"bg-accent-red":u<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${E}%`}})})]})]}),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:n("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:n(h)})]}),k&&e.jsx(yt,{text:k.text,mono:k.mono}),(x==="CRITICAL"||x==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-[11px] px-2 py-1 rounded ${g.bg} ${g.text}`,children:[e.jsx(Ce,{size:12}),e.jsx("span",{children:n(x==="CRITICAL"?"highRiskWarning":"mediumRiskConfirm")})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:L.map(N=>e.jsxs("button",{onClick:N.action,disabled:l,className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs transition-colors disabled:opacity-50 ${j[N.kind]}`,children:[e.jsx("span",{className:`text-[9px] font-mono rounded px-0.5 ${N.kind==="primary"?"bg-white/20":"bg-dark-surface text-dark-muted"}`,children:N.index}),e.jsx("span",{children:N.label}),e.jsx("span",{className:`text-[10px] ${N.kind==="primary"?"text-white/70":"text-dark-muted/60"} hidden sm:inline`,children:N.hint})]},N.id))}),e.jsx("div",{className:"text-[10px] text-dark-muted/50 pt-0.5 border-t border-dark-border/50",children:n("clickToSelect")})]})]})}),Ke={xlsx:{icon:bt},xls:{icon:bt},csv:{icon:ft},docx:{icon:ft},text:{icon:vt}};function es(r){return!r&&r!==0?"—":r<1024?`${r} B`:r<1024*1024?`${(r/1024).toFixed(1)} KB`:`${(r/1024/1024).toFixed(2)} MB`}const Fr=a.memo(function({job:t}){var g,k;const{t:s}=G(),{stage:n}=t,l=a.useCallback(b=>{switch(b){case"xlsx":case"xls":return"Excel";case"csv":return"CSV";case"docx":return"Word";default:return s("fileJob.kindText")}},[s]),o=a.useCallback(b=>{ue.files.download(b).then(w=>{w.success||ie.error(w.error||s("fileJob.downloadFailed"))})},[s]),u=a.useMemo(()=>t.attachments||[],[t.attachments]),c=a.useMemo(()=>t.parsedFiles||[],[t.parsedFiles]),d=a.useMemo(()=>t.mapping||[],[t.mapping]),i=a.useMemo(()=>t.result||[],[t.result]),x=t.renderProgress??(n==="rendering"?0:100),h=t.parseProgress??(n==="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:[n==="complete"?e.jsx(ht,{size:15,className:"text-accent-green shrink-0"}):n==="error"?e.jsx(Ce,{size:15,className:"text-accent-red shrink-0"}):e.jsx(Ie,{size:15,className:"text-accent-blue animate-spin shrink-0"}),e.jsx("span",{className:"text-[13px] font-medium text-dark-text",children:Or(n,s)}),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:[u.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:u.map((b,w)=>{const p=(Ke[b.kind]||Ke.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(p,{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:[es(b.size)," · ",l(b.kind),b.role&&b.role!=="unknown"&&e.jsxs("span",{className:le("ml-1",b.role==="data"?"text-accent-green":"text-accent-purple"),children:["· ",b.role==="data"?s("fileJob.roleData"):s("fileJob.roleTemplate")]})]})]})]},`${b.fileName}-${w}`)})}),n==="parsing"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:s("fileJob.parsing",{file:((g=u[0])==null?void 0:g.fileName)||((k=c[0])==null?void 0:k.fileName)||""})}),e.jsx(Lt,{value:h,size:"sm",showLabel:!0})]}),c.length>0&&n!=="error"&&e.jsxs("div",{className:"space-y-1.5",children:[c.map(b=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(ht,{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:s("fileJob.parsedSummary",{rows:b.rowCount,fields:b.fields.length})})]},b.fileName)),c[0]&&e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[c[0].fields.slice(0,12).map(b=>e.jsx("span",{className:"rounded bg-dark-bg border border-dark-border/60 px-1.5 py-0.5 text-[10px] font-mono text-dark-muted",children:b},b)),c[0].fields.length>12&&e.jsxs("span",{className:"text-[10px] text-dark-muted/60",children:["+",c[0].fields.length-12]})]})]}),d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-[11px] text-dark-muted",children:s("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:s("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:s("fileJob.dataField")})]})}),e.jsx("tbody",{children:d.slice(0,8).map(b=>e.jsxs("tr",{className:"border-t border-dark-border/50",children:[e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-purple",children:"{{"+b.placeholder+"}}"}),e.jsx("td",{className:"px-2 py-1.5 text-dark-muted",children:e.jsx(an,{size:11})}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-blue",children:b.field})]},b.placeholder))})]})}),d.length>8&&e.jsx("div",{className:"text-[10px] text-dark-muted/60",children:s("fileJob.mappingMore",{n:d.length-8})})]}),n==="rendering"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:s("fileJob.rendering",{current:t.currentRow||0,total:t.totalRows||0})}),e.jsx(Lt,{value:x,size:"sm",variant:"warning",showLabel:!0})]}),i.length>0&&n==="complete"&&e.jsx("div",{className:"space-y-1.5",children:i.map(b=>{const y=(Ke[b.format]||Ke.text).icon,p=b.failedRows.length>0;return e.jsxs("div",{className:"rounded-lg border border-dark-border bg-dark-bg px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{size:15,className:"text-accent-green shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs text-dark-text truncate",children:b.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[es(b.size)," · ",s("fileJob.rowsDone",{done:b.successCount,total:b.rowCount}),p&&e.jsxs("span",{className:"text-accent-red",children:[" · ",s("fileJob.rowsFailed",{n:b.failedRows.length})]})]})]}),e.jsxs("button",{onClick:()=>ks(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:s("chat.previewInPanel"),children:[e.jsx(xs,{size:12}),s("chat.previewInPanel")]}),e.jsxs("button",{onClick:()=>o(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:s("fileJob.download"),children:[e.jsx(ln,{size:12}),s("fileJob.download")]})]}),p&&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(on,{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:s("fileJob.moreRows",{n:b.failedRows.length-3})})]})]},b.path)})}),n==="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(Ce,{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||s("fileJob.error")}),t.errorDetail&&e.jsx("div",{className:"mt-0.5 text-[11px] text-dark-muted break-words",children:t.errorDetail})]})]})]})]})});function Or(r,t){switch(r){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 ts={auth:{icon:dn,color:"text-accent-red"},rate_limit:{icon:$t,color:"text-accent-yellow"},timeout:{icon:$t,color:"text-accent-yellow"},network:{icon:cn,color:"text-accent-yellow"},model:{icon:ms,color:"text-accent-red"},tool:{icon:Ce,color:"text-accent-yellow"},unknown:{icon:Ce,color:"text-accent-red"}},qr=a.memo(function({error:t,onRetry:s}){const{t:n}=G(),[l,o]=a.useState(!1),u=ts[t.category]||ts.unknown,c=u.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:le("shrink-0 mt-0.5",u.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&&s&&e.jsxs("button",{onClick:s,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(Oe,{size:11}),n("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(un,{size:11}),n("errorCard.modelSettings")]}),t.detail&&e.jsxs("button",{onClick:()=>o(i=>!i),className:"flex items-center gap-0.5 text-[11px] text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(ge,{size:11,className:le("transition-transform",l&&"rotate-180")}),n("errorCard.details")]})]})]})]}),l&&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 Hr(r){const t=r.replace(/\\/g,"/");return t.slice(t.lastIndexOf("/")+1)||r}function Jr({status:r}){switch(r){case"completed":return e.jsx(Se,{size:13,className:"shrink-0 text-accent-green","data-testid":"activity-status-completed"});case"failed":return e.jsx(Ee,{size:13,className:"shrink-0 text-accent-red","data-testid":"activity-status-failed"});case"running":return e.jsx("span",{className:"tl-node bg-accent-blue","data-status":"running","data-testid":"activity-status-running"});case"waiting_user":return e.jsx(pn,{size:13,className:"shrink-0 text-accent-yellow","data-testid":"activity-status-waiting"});case"blocked":return e.jsx(xn,{size:13,className:"shrink-0 text-accent-red","data-testid":"activity-status-blocked"});case"paused":return e.jsx(hs,{size:13,className:"shrink-0 text-dark-300","data-testid":"activity-status-paused"});default:return e.jsx("span",{className:"inline-block w-2 h-2 shrink-0 rounded-full bg-dark-border"})}}const Ur=a.memo(function({activity:t,toolCalls:s,onAnswer:n}){const{t:l}=G(),[o,u]=a.useState(t.status==="running"),c=a.useRef(t.status);a.useEffect(()=>{(c.current==="running"||c.current==="waiting_user"||c.current==="paused")&&(t.status==="completed"||t.status==="failed")&&u(!1),c.current=t.status},[t.status]);const d=a.useMemo(()=>{for(const b of s){const w=gs(b.args);if(w)return w}},[s]),i=t.endedAt?t.endedAt-t.startedAt:Date.now()-t.startedAt,x=i>=6e4?`${Math.round(i/6e4)}m`:i>=1500?`${Math.round(i/1e3)}s`:"",h=t.status==="waiting_user",g=t.status==="blocked",k=t.status==="paused";return e.jsxs("div",{className:`tl-row rounded-lg transition-colors ${h?"border border-accent-yellow/25 bg-accent-yellow/5":g?"border border-accent-red/25 bg-accent-red/5":"hover:bg-dark-surface/40"}`,"data-testid":"activity-row",children:[!h&&!g&&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:()=>u(b=>!b),"data-testid":"activity-row-toggle",children:[e.jsx("span",{className:"flex h-3 w-3 shrink-0 items-center justify-center",children:e.jsx(Jr,{status:t.status})}),e.jsx("span",{className:`min-w-0 text-[13px] font-medium truncate ${t.status==="running"?"text-shimmer":"text-dark-text"}`,children:t.title}),t.phase!=="analysis"&&e.jsx("span",{className:"status-pill","data-tone":"neutral","data-testid":"activity-phase",children:l(`activity.phase.${t.phase}`)}),d&&e.jsx("span",{className:"shrink-0 max-w-[14rem] truncate rounded-full border border-dark-border/70 px-2 py-0.5 font-mono text-[10.5px] text-accent-blue",children:Hr(d)}),s.length>1&&e.jsx("span",{className:"shrink-0 text-[10.5px] text-dark-muted",children:l("activity.evidenceMore",{count:s.length-1})}),x&&e.jsx("span",{className:"shrink-0 text-[10.5px] text-dark-muted",children:x}),h&&e.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-accent-yellow",children:l("activity.waitingUser")}),g&&e.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-accent-red",title:t.blockedReason?l("activity.blocked",{reason:t.blockedReason}):void 0,children:l("activity.blocked",{reason:t.blockedReason??""})}),k&&e.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-dark-300",children:l("activity.paused")}),h&&n&&e.jsx("button",{type:"button",onClick:b=>{b.stopPropagation(),n(t.id)},className:"shrink-0 rounded border border-accent-yellow/40 px-1.5 py-0.5 text-[10.5px] text-accent-yellow hover:bg-accent-yellow/10",children:l("activity.viewAndAnswer")}),!h&&s.length>0&&e.jsx(ge,{size:12,className:`ml-auto shrink-0 text-dark-muted transition-transform ${o?"rotate-180":""}`})]}),o&&s.length>0&&e.jsx("div",{className:"relative ml-[15px] pb-1 pl-3 border-l border-dark-border/25",children:e.jsx(St,{toolCalls:s})})]})});function Wr({index:r,text:t,isStreaming:s,collapsed:n,onToggle:l}){const{t:o}=G();return e.jsxs("div",{children:[e.jsxs("button",{className:"flex items-center gap-1.5 cursor-pointer select-none py-0.5 text-xs",onClick:()=>l(r),"data-testid":"thinking-toggle",children:[e.jsx(ke,{size:12,className:`text-dark-muted transition-transform ${n?"":"rotate-90"}`}),e.jsx("span",{className:s?"text-shimmer":"text-dark-muted",children:s?`${o("chat.thinking")}…`:o("chat.thoughtProcess")})]}),!n&&e.jsx("div",{className:"mt-1 text-xs text-dark-muted whitespace-pre-wrap break-words border-l border-dark-border/25 pl-3 max-h-64 overflow-y-auto custom-scrollbar",children:t.replace(/\n{3,}/g,`
12
-
13
- `)})]})}const Kr=a.memo(function({message:t,sessionId:s,isGenerating:n,onAnswer:l}){const o=qn(y=>Hn(y,s,t.id)),u=a.useMemo(()=>o.length>0?o:!t.toolCalls||t.toolCalls.length===0?[]:Jn(s??"",t),[o,t,s]),c=a.useMemo(()=>t.thinkingBlocks&&t.thinkingBlocks.length>0?t.thinkingBlocks:t.thinking?[{index:Number.MIN_SAFE_INTEGER,text:t.thinking}]:[],[t.thinkingBlocks,t.thinking]),[d,i]=a.useState({}),x=!n||!!t.content;a.useEffect(()=>{x&&i(y=>{const p={...y};for(const C of c)p[C.index]=!0;return p})},[x,c]);const h=a.useMemo(()=>{let y=Number.MIN_SAFE_INTEGER;for(const p of c)y=Math.max(y,p.index);for(const p of t.toolCalls??[])y=Math.max(y,p.index??Number.MIN_SAFE_INTEGER);return y},[c,t.toolCalls]),g=y=>n&&!t.content&&y===h,k=y=>{const p=d[y]??(!!t.content||!n);i(C=>({...C,[y]:!p}))},b=a.useMemo(()=>{const y=[];for(const p of c)y.push({key:`thinking-${p.index}`,index:p.index,kind:"thinking",block:p});for(const p of u)y.push({key:`activity-${p.id}`,index:p.blockRange[0],kind:"activity",activity:p});return y.sort((p,C)=>p.index-C.index),y},[c,u]),w=a.useMemo(()=>{const y={},p=t.toolCalls??[];for(const C of u)y[C.id]=C.toolCallIds.map(F=>p.find(E=>E.id===F)).filter(F=>!!F);return y},[u,t.toolCalls]);return b.length===0?null:e.jsx("div",{className:"mb-1 space-y-0.5","data-testid":"agent-activity-feed",children:b.map(y=>y.kind==="thinking"&&y.block?e.jsx(Wr,{index:y.block.index,text:y.block.text,isStreaming:g(y.block.index),collapsed:d[y.block.index]??(!!t.content||!n),onToggle:k},y.key):y.activity?e.jsx(Ur,{activity:y.activity,toolCalls:w[y.activity.id]??[],onAnswer:l},y.key):null)})}),Ls=5,Gr=30,Zr=["让我","我先","我现在","我发现","我注意到","我决定","我重新","我重试","我继续","我现在要","让我现在","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 Vr(r){const t=r.charCodeAt(0);return t>=19968&&t<=40959}function Qr(r){let t="",s=!1;for(const n of r)n===" "||n===" "||n===" "?(s||(t+=" "),s=!0):(t+=n,s=!1);return t}function Xr(r){return r>=97&&r<=122||r>=48&&r<=57||r===95}function Bs(r){const t=Qr(r.trimStart().toLowerCase());return Zr.some(s=>{if(!t.startsWith(s))return!1;const n=t[s.length];return n===void 0||Vr(s)||s==="i re-"?!0:!Xr(n.charCodeAt(0))})}function Yr(r){if(!r)return!1;const t=r.split(/\r?\n/).slice(0,Gr);let s=0;for(const n of t)if(n.trim())if(Bs(n)){if(s++,s>=Ls)return!0}else return!1;return!1}function ea(r,t){if(!r)return{body:r||"",absorbed:""};if(!Yr(r))return{body:r,absorbed:""};const s=r.split(/\r?\n/);let n=0,l=0;for(const u of s){if(!u.trim()){l++;continue}if(Bs(u)){n++,l++;continue}break}if(n<Ls)return{body:r,absorbed:""};let o=0;for(const u of s.slice(0,l)){if(o+=u.length,o>=r.length)break;r.startsWith(`\r
14
- `,o)?o+=2:(r[o]===`
15
- `||r[o]==="\r")&&(o+=1)}return{body:r.slice(o),absorbed:r.slice(0,o)}}function ot({onClick:r,title:t,children:s,danger:n=!1}){return e.jsx("button",{onClick:r,title:t,"aria-label":t,className:`inline-flex items-center justify-center rounded p-1 transition-colors ${n?"text-dark-muted hover:text-accent-red hover:bg-accent-red/10":"text-dark-muted hover:text-dark-text hover:bg-dark-hover"}`,children:s})}function ss({message:r,sessionId:t,onRegenerate:s,onDeleteMessage:n}){const{t:l}=G(),[o,u]=a.useState(!1),c=a.useRef(null);a.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const d=a.useCallback(async()=>{try{await navigator.clipboard.writeText(r.content||r.thinking||""),u(!0),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>u(!1),2e3)}catch(i){console.error("Failed to copy message:",i)}},[r.content,r.thinking]);return t?e.jsxs(e.Fragment,{children:[e.jsx(ot,{onClick:d,title:l("chat.copyMessage"),children:o?e.jsx(Se,{size:12,className:"text-accent-green"}):e.jsx(hn,{size:12})}),r.type==="assistant"&&s&&e.jsx(ot,{onClick:()=>s(r.id),title:l("chat.regenerate"),children:e.jsx(Oe,{size:12})}),n&&e.jsx(ot,{onClick:()=>n(r.id),title:l("chat.deleteMessage"),danger:!0,children:e.jsx(fn,{size:12})})]}):null}function ns({ts:r,children:t}){const{i18n:s}=G(),n=s.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(r).toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"})}),t]})}function ta(r,t){const s=[];for(const n of r)s.push({key:`thinking-${n.index}`,index:n.index,kind:"thinking",block:n});for(const n of t??[])s.push({key:`tool-${n.id}`,index:n.index??Number.MAX_SAFE_INTEGER,kind:"tool",toolCall:n});return s.sort((n,l)=>n.index-l.index),s}function sa({index:r,text:t,isStreaming:s,collapsed:n,onToggle:l}){const{t:o}=G();return e.jsxs("div",{children:[e.jsxs("button",{className:"flex items-center gap-1.5 cursor-pointer select-none py-0.5 text-xs",onClick:()=>l(r),"data-testid":"thinking-toggle",children:[e.jsx(ke,{size:12,className:`text-dark-muted transition-transform ${n?"":"rotate-90"}`}),e.jsx("span",{className:s?"text-shimmer":"text-dark-muted",children:s?`${o("chat.thinking")}…`:o("chat.thoughtProcess")})]}),!n&&e.jsx("div",{className:"mt-1 text-xs text-dark-muted whitespace-pre-wrap break-words border-l border-dark-border/25 pl-3 max-h-64 overflow-y-auto custom-scrollbar",children:t.replace(/\n{3,}/g,`
16
-
17
- `)})]})}const na=a.memo(function({message:t,sessionId:s,onRegenerate:n,onDeleteMessage:l}){var E,z,L;const{t:o}=G(),u=Qe(j=>j.developerView),c=be(j=>{var D;if(!s||!j.generatingSessions.includes(s))return!1;const N=j.messagesBySession[s];return N?((D=N[N.length-1])==null?void 0:D.id)===t.id:!1}),d=a.useMemo(()=>t.thinkingBlocks&&t.thinkingBlocks.length>0?t.thinkingBlocks:t.thinking?[{index:Number.MIN_SAFE_INTEGER,text:t.thinking}]:[],[t.thinkingBlocks,t.thinking]),[i,x]=a.useState({}),h=!c||!!t.content;a.useEffect(()=>{h&&x(j=>{const N={...j};for(const D of d)N[D.index]=!0;return N})},[h,d]);const g=a.useMemo(()=>ta(d,t.toolCalls),[d,t.toolCalls]),k=a.useMemo(()=>{var D;if(!t.content)return"";if(!(!!t.thinking||(((D=t.thinkingBlocks)==null?void 0:D.length)??0)>0))return t.content;const{body:N}=ea(t.content);return N||t.content},[t.content,t.thinking,t.thinkingBlocks]),b=a.useMemo(()=>{const j=[];for(const N of g)if(N.kind==="thinking"&&N.block)j.push({key:N.key,kind:"thinking",block:N.block});else if(N.kind==="tool"&&N.toolCall){const D=j[j.length-1];D&&D.kind==="tools"?D.toolCalls.push(N.toolCall):j.push({key:`tools-${N.key}`,kind:"tools",toolCalls:[N.toolCall]})}return j},[g]),w=a.useMemo(()=>{let j=Number.MIN_SAFE_INTEGER;for(const N of d)j=Math.max(j,N.index);for(const N of t.toolCalls??[])j=Math.max(j,N.index??Number.MIN_SAFE_INTEGER);return j},[d,t.toolCalls]),y=a.useCallback(j=>{const N=i[j]??(!!t.content||!c);x(D=>({...D,[j]:!N}))},[c,t.content,i]),p=t.type==="user",C=t.type==="system",F=a.useCallback((j,N)=>{if(!s)return;const M=be.getState().getMessages(s),R=M.findIndex(V=>V.id===t.id);if(R===-1)return;const W=M[R];if(!W)return;const K={...W,hookApproval:W.hookApproval?{...W.hookApproval,status:N}:void 0},Z=[...M];Z[R]=K,be.setState({messagesBySession:{...be.getState().messagesBySession,[s]:Z}})},[s,t.id]);return t.deleted?null:p?e.jsxs("div",{className:"chat-msg","data-role":"user",children:[e.jsx("div",{className:"chat-avatar","aria-hidden":!0,children:e.jsx(mn,{size:14,strokeWidth:2.4})}),e.jsx("div",{className:"max-w-[78%] flex flex-col",children:e.jsxs("div",{className:"group relative inline-block self-end rounded-2xl border border-dark-border/40 bg-dark-surface px-4 py-2.5 text-dark-text shadow-sm",style:{borderBottomRightRadius:"0.375rem"},children:[e.jsx(ns,{ts:t.timestamp,children:e.jsx(ss,{message:t,sessionId:s,onRegenerate:n,onDeleteMessage:l})}),e.jsx("div",{className:"whitespace-pre-wrap break-words leading-relaxed text-[14.5px]",children:(E=t.content)==null?void 0:E.replace(/\n{3,}/g,`
18
-
19
- `)})]})})]}):C?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(ms,{size:14,strokeWidth:2.4})}),e.jsxs("div",{className:"chat-card group",children:[e.jsx(ns,{ts:t.timestamp,children:e.jsx(ss,{message:t,sessionId:s,onRegenerate:n,onDeleteMessage:l})}),t.steps&&t.steps.length>0&&!t.hookApproval?e.jsx(zr,{steps:t.steps,isGenerating:c}):u?e.jsx(e.Fragment,{children:b.length>0&&!t.hookApproval&&e.jsx("div",{className:"mb-2 space-y-1",children:b.map(j=>j.kind==="thinking"?e.jsx(sa,{index:j.block.index,text:j.block.text,isStreaming:c&&!t.content&&j.block.index===w,collapsed:i[j.block.index]??(!!t.content||!c),onToggle:y},j.key):e.jsx(St,{toolCalls:j.toolCalls},j.key))})}):e.jsx(Kr,{message:t,sessionId:s,isGenerating:c}),t.content?e.jsx("div",{className:"leading-relaxed",children:e.jsx(Un,{content:k.replace(/\n{3,}/g,`
20
-
21
- `)})}):d.length===0&&!t.hookApproval&&((z=t.steps)!=null&&z.length)?null:d.length===0&&!t.hookApproval&&!((L=t.steps)!=null&&L.length)&&c?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:[o("chat.thinking"),"…"]})]}):null,t.summary&&!c&&e.jsx("div",{className:"mt-1.5 text-[11px] text-dark-muted/70","data-testid":"turn-summary",children:Wn(t.summary)}),t.fileJob&&e.jsx("div",{className:"mt-3",children:e.jsx(Fr,{job:t.fileJob})}),t.errorCard&&e.jsx("div",{className:"mt-3",children:e.jsx(qr,{error:t.errorCard,onRetry:s&&n?()=>n(t.id):void 0})}),t.hookApproval&&e.jsx("div",{className:"mt-3 border-l-2 border-accent-yellow/50 pl-3",children:e.jsx(Br,{approval:t.hookApproval,onResolved:F})})]})]})});function ra(r,t=28){const s=r.replace(/\s+/g," ").trim();return s.length>t?`${s.slice(0,t)}…`:s}const aa="cubic-bezier(0.34, 1.56, 0.64, 1)",la=a.memo(function({items:t,activeId:s,onJump:n}){const{t:l}=G(),[o,u]=a.useState(!1),c=a.useRef(null),d=a.useCallback(()=>{c.current&&window.clearTimeout(c.current),u(!0)},[]),i=a.useCallback(()=>{c.current&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>u(!1),180)},[]);return t.length===0?null:e.jsx("div",{role:"list","aria-label":l("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:i,"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?aa:"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(bn,{size:12,className:"text-accent-blue","aria-hidden":"true"}),l("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((x,h)=>{const g=x.id===s;return e.jsxs("button",{type:"button",role:"listitem",onClick:()=>n(x.id),title:x.content,"aria-current":g?"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"} ${g?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{transitionDelay:o?`${Math.min(h*24,264)}ms`:"0ms"},children:[e.jsx("span",{className:`mt-px flex h-4 w-4 shrink-0 items-center justify-center rounded text-[10px] font-semibold tabular-nums transition-colors duration-200 ${g?"bg-accent-blue text-white":"bg-dark-hover text-dark-muted group-hover/item:bg-dark-border/80 group-hover/item:text-dark-text"}`,children:h+1}),e.jsx("span",{className:"min-w-0 flex-1",children:e.jsx("span",{"data-testid":"rail-entry-content",className:`block break-words text-xs leading-snug line-clamp-2 group-hover/item:line-clamp-none transition-colors duration-200 ${g?"font-medium text-accent-blue":"text-dark-text/90"}`,children:x.content})}),e.jsx(ke,{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"})]},x.id)})})]}),e.jsx("div",{"data-testid":"rail-dots",className:"flex flex-col items-end gap-1",children:t.map((x,h)=>{const g=ra(x.content),k=x.id===s;return e.jsx("button",{type:"button",role:"listitem",onClick:()=>n(x.id),title:x.content,"aria-label":`${h+1}. ${g}`,"aria-current":k?"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:k?"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"})},x.id)})})]})})}),ia=a.memo(function({messages:t,isGenerating:s,sessionId:n,onSendSuggestion:l,onRegenerate:o,onDeleteMessage:u}){const{t:c}=G(),d=a.useRef(null),i=a.useRef(new Map),[x,h]=a.useState(!0),[g,k]=a.useState(null),[b,w]=a.useState(null),[y,p]=a.useState(0),C=a.useRef(null),F=a.useRef(!1),E=a.useRef(null),z=a.useRef(s);z.current=s;const L=a.useMemo(()=>t.filter(S=>!S.deleted),[t]),j=a.useMemo(()=>{if(!s)return!1;const S=L[L.length-1];return!(!S||S.type!=="assistant"||S.content||S.steps&&S.steps.length>0)},[s,L]),N=a.useMemo(()=>L.filter(S=>S.type==="user").map(S=>({id:S.id,content:S.content})),[L]),D=a.useMemo(()=>N.map(S=>S.id),[N]),M=a.useCallback(S=>{if(S){const U=S.dataset.mid;U&&i.current.set(U,S)}},[]);a.useEffect(()=>{const S=new Set(D);for(const U of i.current.keys())S.has(U)||i.current.delete(U)},[D]);const R=a.useCallback(()=>{const S=d.current;if(!S||D.length===0){k(null);return}const U=S.getBoundingClientRect(),O=U.top+U.height*.35;let Q=D[0]??null;for(const te of D){const re=i.current.get(te);if(!(!re||!re.isConnected))if(re.getBoundingClientRect().top<=O)Q=te;else break}S.scrollHeight-S.scrollTop-S.clientHeight<50&&(Q=D[D.length-1]??Q),k(Q)},[D]),W=a.useCallback(()=>{const S=d.current;if(!S)return;const U=S.scrollHeight-S.scrollTop-S.clientHeight;F.current?U>=50&&(F.current=!1):h(U<50),R()},[R]);a.useEffect(()=>{R()},[t,R]);const K=a.useCallback(S=>{const U=d.current,O=i.current.get(S);if(!U||!O||!O.isConnected)return;h(!1),w(S),p(ee=>ee+1),C.current&&window.clearTimeout(C.current),C.current=window.setTimeout(()=>w(null),1600);const Q=U.getBoundingClientRect(),te=O.getBoundingClientRect(),re=U.scrollTop+(te.top-Q.top)-U.clientHeight/2+te.height/2;E.current&&window.clearTimeout(E.current),F.current=!0,U.scrollTo({top:Math.max(0,re),behavior:"smooth"});const me=()=>{F.current=!1};"onscrollend"in U&&U.addEventListener("scrollend",me,{once:!0}),E.current=window.setTimeout(()=>{F.current=!1},1500)},[]);a.useEffect(()=>()=>{C.current&&window.clearTimeout(C.current),E.current&&window.clearTimeout(E.current)},[]);const Z=a.useCallback(()=>{E.current&&window.clearTimeout(E.current),F.current=!1;const S=d.current;S&&(S.scrollTop=S.scrollHeight)},[]),V=a.useCallback(()=>{E.current&&window.clearTimeout(E.current),F.current=!1,h(!0);const S=d.current;S&&S.scrollTo({top:S.scrollHeight,behavior:"smooth"})},[]);a.useEffect(()=>{s&&(h(!0),Z())},[s,Z]),a.useEffect(()=>{x&&Z()},[t,x,Z]);const he=a.useMemo(()=>[{icon:gn,label:c("chat.suggestionCode"),prompt:c("chat.suggestionCodePrompt")},{icon:jt,label:c("chat.suggestionAnalyze"),prompt:c("chat.suggestionAnalyzePrompt")},{icon:wt,label:c("chat.suggestionAutomate"),prompt:c("chat.suggestionAutomatePrompt")}],[c]);return e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsxs("div",{ref:d,onScroll:W,className:"h-full overflow-y-auto custom-scrollbar",children:[L.length===0?e.jsx("div",{className:"flex min-h-[55vh] items-center justify-center px-4 py-10 sm:px-6",children:e.jsxs("div",{className:"w-full max-w-2xl px-1 text-center",children:[e.jsx("div",{className:"chat-empty-orb",children:e.jsx("img",{src:"/logo.svg",alt:"deepseekcode",className:"relative h-10 w-10 rounded-xl"})}),e.jsx("h2",{className:"text-xl font-semibold tracking-tight mb-2",children:c("chat.welcome")}),e.jsx("p",{className:"text-dark-muted text-sm mb-8",children:c("chat.welcomeDesc")}),l&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2.5 text-left",children:he.map(S=>e.jsxs("button",{onClick:()=>l(S.prompt),className:"ui-card-interactive group w-full px-4 py-3.5 text-left",children:[e.jsx(S.icon,{size:16,"aria-hidden":"true",className:"text-accent-blue mb-2"}),e.jsx("div",{className:"text-[13px] font-medium text-dark-text",children:S.label}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-dark-muted line-clamp-2",children:S.prompt})]},S.label))})]})}):e.jsx("div",{className:"chat-stack flex flex-col pb-8 pt-5",children:L.map((S,U)=>{const O=L[U-1],Q=O?O.type===S.type?"mt-2":"mt-5":"";return e.jsxs("div",{"data-mid":S.id,ref:M,className:`relative w-full ${Q}`,children:[b===S.id&&e.jsx("div",{className:"animate-rail-flash pointer-events-none absolute inset-0"},y),e.jsx(na,{message:S,sessionId:n,onRegenerate:o,onDeleteMessage:u})]},S.id)})}),s&&!j&&e.jsxs("div",{className:"mx-auto flex max-w-[46rem] 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:"w-1.5 h-1.5 rounded-full bg-accent-blue animate-blink"}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-blue animate-blink",style:{animationDelay:"0.2s"}}),e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-accent-blue animate-blink",style:{animationDelay:"0.4s"}})]}),e.jsx("span",{children:c("chat.thinkingEllipsis")})]})]}),N.length>0&&e.jsx(la,{items:N,activeId:g,onJump:K}),!x&&L.length>0&&e.jsx("button",{type:"button",onClick:V,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(ge,{size:15})})]})}),oa={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"},ca=a.memo(function(){const{t}=G(),s=Ne(d=>d.mode),n=Ne(d=>d.setBaseMode),l=Ne(d=>d.toggleAuto),o=s==="normal"?"act":s,u=Ze(o),c=kt(o);return e.jsxs("div",{className:"flex items-center gap-1",children:[Kn.map(d=>{const i=u===d,x=Gn[d],h=s!=="normal"&&i?oa[s]??"border-dark-border text-dark-muted":"border-dark-border text-dark-muted hover:bg-dark-hover";return e.jsx("button",{type:"button",onClick:()=>n(d),className:le("px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",h),title:t("chat.clickToSwitchMode"),"aria-pressed":i,children:x.label},d)}),e.jsxs("button",{type:"button",role:"switch","aria-checked":c,onClick:()=>l(),className:le("flex items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",c?"border-accent-yellow/40 text-accent-yellow bg-accent-yellow/10":"border-dark-border text-dark-muted hover:bg-dark-hover"),title:t("plan.autoApprove"),children:[e.jsx(Oe,{size:11,className:le(c?"text-accent-yellow":"text-dark-muted")}),e.jsx("span",{children:t("plan.autoApprove")})]})]})}),rs={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"}},da=a.memo(function(){const{t}=G(),s=Be(v=>v.model),n=Be(v=>v.modelRef),l=Be(v=>v.setModel),o=Be(v=>v.setModelRef),u=Ne(v=>v.mode),c=Qe(v=>v.effort),d=Qe(v=>v.setEffort),[i,x]=a.useState([]),[h,g]=a.useState(!1),k=a.useRef(null),[b,w]=a.useState(!1),[y,p]=a.useState(""),[C,F]=a.useState(""),[E,z]=a.useState([]),[L,j]=a.useState(new Set),[N,D]=a.useState("none"),[M,R]=a.useState(!1),[W,K]=a.useState(null),[Z,V]=a.useState(null),he=a.useMemo(()=>Array.from(new Set(i.map(v=>v.provider))),[i]),S=a.useCallback(async()=>{try{const v=await ue.models.list();v.success&&v.data&&Array.isArray(v.data.models)&&x(v.data.models.filter(H=>H.enabled!==!1))}catch{}},[]),U=a.useCallback(()=>{var H,P;const v=Zn(n)||((H=i.find(oe=>oe.isGlobalDefault))==null?void 0:H.provider)||((P=i[0])==null?void 0:P.provider)||"";p(v),F(""),K(null),w(!0)},[n,i]),O=a.useCallback(()=>{w(!1),z([]),K(null)},[]),Q=a.useCallback(async(v,H)=>{if(v){R(!0),K(null);try{const P=await ue.models.byProvider(v,H||void 0);P.success&&P.data?(z(P.data.models||[]),j(new Set(P.data.existing||[])),D(P.data.source)):(z([]),j(new Set),K(P.error||t("chat.loadModelsFailed")))}catch{z([]),j(new Set),K(t("chat.loadModelsFailed"))}finally{R(!1)}}},[t]);a.useEffect(()=>{if(!b)return;const v=setTimeout(()=>{Q(y,C)},C?300:0);return()=>clearTimeout(v)},[b,y,C,Q]),a.useEffect(()=>{S()},[S]),a.useEffect(()=>{const v=()=>{S()};return window.addEventListener("models-updated",v),()=>window.removeEventListener("models-updated",v)},[S]);const te=a.useCallback(()=>g(!1),[]);a.useEffect(()=>{if(!h)return;const v=P=>{k.current&&!k.current.contains(P.target)&&te()},H=P=>{P.key==="Escape"&&te()};return document.addEventListener("mousedown",v),document.addEventListener("keydown",H),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("keydown",H)}},[h,te]);const re=async v=>{te();const H=Ze(u==="normal"?"act":u),P=`${v.provider}:${v.id}`,oe=H==="plan"?{plan:P}:H==="goal"?{goal:P}:{global:P,act:P};try{(await ue.models.setDefaults(oe)).success&&(l(v.id),o(`${v.provider}:${v.id}`),await S())}catch{}},me=async v=>{const H=L.has(v.id),P=`${y}:${v.id}`;V(v.id);try{if(!H){const Re=await ue.models.create({provider:y,model:{id:v.id,name:v.name||v.id}});if(!Re.success){K(Re.error||t("chat.addModelFailed"));return}}const oe=Ze(u==="normal"?"act":u),xe=oe==="plan"?{plan:P}:oe==="goal"?{goal:P}:{global:P,act:P},He=await ue.models.setDefaults(xe);He.success?(l(v.id),o(P),O(),await S()):K(He.error||t("chat.switchModelFailed"))}catch{K(t("chat.addModelFailed"))}finally{V(null)}},ee=Ze(u==="normal"?"act":u),fe=ee==="plan"?"isPlanDefault":ee==="goal"?"isGoalDefault":"isActDefault",ae=v=>{const H=`${v.provider}:${v.id}`;if(n)return n===H;if(s===H)return!0;if(s!==v.id)return!1;const P=i.filter(xe=>xe.id===v.id);return P.length<=1?!0:(P.find(xe=>xe[fe]===!0)??P.find(xe=>xe.isGlobalDefault)??P[0])===v},ye=i.some(v=>v[fe]===!0),de=i.find(v=>v.isGlobalDefault),A=async()=>{te();const v=ee==="plan"?{plan:null}:ee==="goal"?{goal:null}:{act:null};try{(await ue.models.setDefaults(v)).success&&(de?(l(de.id),o(`${de.provider}:${de.id}`)):(l(""),o("")),await S())}catch{}},T=a.useMemo(()=>Vn(i),[i]),B=Qn(s,n),ne=rs[c];return e.jsxs("div",{className:"relative",ref:k,children:[e.jsxs("button",{type:"button",onClick:()=>g(v=>!v),className:"flex 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:B||t("chat.clickToSelectModel"),"aria-haspopup":"listbox","aria-expanded":h,children:[e.jsx(kn,{size:12,className:"shrink-0"}),e.jsx("span",{className:"font-medium max-w-[8rem] truncate",children:B||t("chat.selectModel")}),e.jsx("span",{className:"h-3 w-px bg-dark-border shrink-0","aria-hidden":"true"}),e.jsx(Pt,{size:12,className:`shrink-0 ${ne.color}`}),e.jsx("span",{className:`text-xs font-medium ${ne.color}`,children:t(ne.labelKey)}),e.jsx(ge,{size:12,className:le("transition-transform",h&&"rotate-180")})]}),h&&e.jsxs("div",{role:"listbox","aria-label":t("chat.selectModel"),className:"absolute bottom-full left-0 mb-1 z-50 min-w-[260px] bg-dark-surface border border-dark-border rounded-lg shadow-xl overflow-hidden",children:[e.jsx("div",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wide text-dark-muted border-b border-dark-border",children:t("chat.selectModel")}),b?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:O,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(yn,{size:12})}),he.length>1?e.jsx("select",{value:y,onChange:v=>p(v.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:he.map(v=>e.jsx("option",{value:v,children:v},v))}):e.jsx("span",{className:"flex-1 min-w-0 text-xs font-medium text-dark-text truncate",children:y||t("chat.noConfiguredProviders")}),e.jsx("input",{value:C,onChange:v=>F(v.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:M?e.jsxs("div",{className:"px-3 py-2 text-xs text-dark-muted flex items-center gap-1.5",children:[e.jsx(wn,{size:11,className:"animate-spin"}),t("chat.loadingModels")]}):W?e.jsx("div",{className:"px-3 py-2 text-xs text-accent-red",children:W}):y?E.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t(C?"chat.noModelsFound":"chat.noProviderModels")}):e.jsxs(e.Fragment,{children:[N!=="none"&&e.jsx("div",{className:"px-3 pt-1.5 pb-0.5 text-[10px] text-dark-muted/70",children:t(N==="provider-api"?"chat.modelsSourceProviderApi":"chat.modelsSourceCatalog")}),E.map(v=>{const H=L.has(v.id),P=n===`${y}:${v.id}`;return e.jsxs("button",{type:"button",role:"option","aria-selected":P,onClick:()=>me(v),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:v.name||v.id}),P&&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:v.id})]}),H?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:Z===v.id?t("chat.addingModel"):t("chat.addAndSwitch")})]},v.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:[ye&&e.jsx("button",{type:"button",role:"option","aria-selected":!1,onClick:A,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(vn,{size:11}),t("chat.followGlobalDefault")]}),e.jsx("span",{className:"block text-[10px] text-dark-muted mt-0.5 truncate",children:de?de.name||de.id:t("chat.noGlobalDefault")})]})}),T.map(([v,H])=>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:v}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:H.length})]}),H.map(P=>{const oe=ae(P);return e.jsx("button",{type:"button",role:"option","aria-selected":oe,onClick:()=>re(P),className:le("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors",oe?"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:le("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",oe?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Se,{size:11,strokeWidth:3})}),e.jsx("span",{className:"text-xs font-semibold text-dark-text truncate",children:P.name||P.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:P.id}),P.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-green/20 text-accent-green",children:t("chat.globalDefault")}),P.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-blue/20 text-accent-blue",children:t("chat.planDefault")}),P.isActDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-yellow/20 text-accent-yellow",children:t("chat.actDefault")}),P.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-purple/20 text-accent-purple",children:t("chat.goalDefault")})]})]})},`${P.provider}:${P.id}`)})]},v)),i.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:U,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(jt,{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(Pt,{size:11}),t("chat.effort")]}),e.jsx("div",{className:"py-1",children:Xn.map(v=>{const H=rs[v],P=v===c;return e.jsxs("button",{type:"button",role:"option","aria-selected":P,onClick:()=>{d(v),te()},className:le("w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors",P?"bg-dark-hover":"hover:bg-dark-hover"),children:[e.jsx("span",{className:le("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",P?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Se,{size:11,strokeWidth:3})}),e.jsx("span",{className:`text-xs font-medium ${P?H.color:"text-dark-text"}`,children:t(H.labelKey)})]},v)})})]})]})});var ua=lr();function xa(r,t){if(!r)return t;const s=r.includes("\\")?"\\":"/";return r.endsWith(s)?r+t:r+s+t}function pa(r){const t=r.replace(/[\\/]+$/,""),s=Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/"));return s===-1?t:t.slice(s+1)}function ma({initial:r,onClose:t,onConfirm:s}){const{t:n}=G(),[l,o]=a.useState(r),[u,c]=a.useState(null),[d,i]=a.useState([]),[x,h]=a.useState(!1),[g,k]=a.useState(""),[b,w]=a.useState(r),y=a.useRef(null),p=a.useCallback(async E=>{h(!0),k("");try{const z=await ue.dirs.list(E);if(!z.success||!z.data){k(z.error||n("chat.dirPickerLoadError"));return}o(z.data.path),c(z.data.parent),i(z.data.dirs||[]),w(z.data.path)}catch(z){k(z instanceof Error?z.message:n("chat.dirPickerLoadError"))}finally{h(!1)}},[n]);a.useEffect(()=>{p(r)},[r,p]),a.useEffect(()=>{var E;(E=y.current)==null||E.focus()},[]),a.useEffect(()=>{const E=z=>{z.key==="Escape"&&(z.preventDefault(),z.stopPropagation(),t())};return document.addEventListener("keydown",E),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",E),document.body.style.overflow=""}},[t]);const C=a.useCallback(()=>{const E=b.trim();E&&p(E)},[b,p]),F=a.useCallback(()=>{u&&p(u)},[u,p]);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(fs,{size:15,className:"text-accent-blue","aria-hidden":"true"}),n("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":n("a11y.close"),children:e.jsx(Ee,{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(jn,{size:13,className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-dark-muted/60","aria-hidden":"true"}),e.jsx("input",{ref:y,value:b,onChange:E=>w(E.target.value),onKeyDown:E=>{E.key==="Enter"&&C()},placeholder:n("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
22
- 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:C,disabled:x||!b.trim(),className:`shrink-0 rounded-lg border border-dark-border px-2.5 py-1.5 text-xs text-dark-muted
23
- hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:n("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:l,children:l||n("chat.noWorkspaceDir")}),e.jsxs("button",{type:"button",onClick:()=>void F(),disabled:x||!l,className:`shrink-0 flex items-center gap-1 rounded-md border border-dark-border px-2 py-1 text-[11px] text-dark-muted
24
- hover:bg-dark-hover hover:text-dark-text disabled:opacity-40 transition-colors`,children:[e.jsx(bs,{size:12,"aria-hidden":"true"}),n("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:x?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-xs text-dark-muted",children:[e.jsx(Ie,{size:14,className:"animate-spin","aria-hidden":"true"}),n("chat.loading")]}):g?e.jsx("div",{className:"px-3 py-4 text-xs text-accent-red",children:g}):d.length===0?e.jsx("div",{className:"px-3 py-4 text-xs text-dark-muted/60 text-center",children:n("chat.dirPickerNoDirs")}):d.map(E=>{const z=xa(l,E);return e.jsxs("button",{type:"button",onClick:()=>void p(z),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs text-dark-text
25
- hover:bg-dark-hover transition-colors group`,children:[e.jsx(Nt,{size:13,className:"shrink-0 text-accent-yellow/80 group-hover:text-accent-yellow","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:E}),e.jsx(ke,{size:12,className:"shrink-0 ml-auto text-dark-muted/40","aria-hidden":"true"})]},E)})}),e.jsx("button",{type:"button",onClick:()=>s(l),disabled:!l||x,className:`w-full rounded-lg bg-accent-blue/90 text-white text-xs font-medium py-2
26
- hover:bg-accent-blue disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:n("chat.dirPickerConfirm")})]})]})]})}const ha=a.memo(function({workspaceDir:t,onSelect:s}){const{t:n}=G(),l=Qe(h=>h.recentDirs),[o,u]=a.useState(!1),[c,d]=a.useState(!1),i=a.useRef(null);a.useEffect(()=>{if(!o)return;const h=k=>{i.current&&!i.current.contains(k.target)&&u(!1)},g=k=>{k.key==="Escape"&&u(!1)};return document.addEventListener("mousedown",h),document.addEventListener("keydown",g),()=>{document.removeEventListener("mousedown",h),document.removeEventListener("keydown",g)}},[o]);const x=a.useCallback(h=>{var k;const g=((k=h==null?void 0:h.trim)==null?void 0:k.call(h))||"";g&&(u(!1),d(!1),s(g))},[s]);return e.jsxs("div",{className:"relative shrink-0",ref:i,children:[e.jsxs("button",{type:"button",onClick:()=>u(h=>!h),className:le("flex items-center gap-1 max-w-[180px] 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:n("chat.clickToSwitchDir"),"aria-label":n("chat.clickToSwitchDir"),"aria-expanded":o,"aria-haspopup":"menu",children:[e.jsx(fs,{size:12,className:"shrink-0 text-accent-blue/80","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:t?pa(t):n("chat.noWorkspaceDir")}),e.jsx(ge,{size:11,className:le("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:n("chat.recentDirs")}),l.length===0?e.jsx("div",{className:"px-3 pb-2 text-[11px] text-dark-muted/50 select-none",children:n("chat.noRecentDirs")}):e.jsx("div",{className:"max-h-56 overflow-y-auto custom-scrollbar",children:l.map(h=>{const g=h===t;return e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>x(h),className:le("w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors group",g?"text-accent-blue bg-accent-blue/5":"text-dark-text hover:bg-dark-hover"),title:h,children:[e.jsx(Nt,{size:12,className:le("shrink-0",g?"text-accent-blue":"text-accent-yellow/80 group-hover:text-accent-yellow"),"aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:h}),g&&e.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-accent-blue",children:"✓"})]},h)})}),e.jsx("div",{className:"border-t border-dark-border"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{u(!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(ke,{size:13,"aria-hidden":"true"}),n("chat.chooseOtherDir")]})]}),c&&ua.createPortal(e.jsx(ma,{initial:t||"",onClose:()=>d(!1),onConfirm:x}),document.body)]})});function fa({isOpen:r,files:t,selectedIndex:s,query:n,isSearching:l,onSelect:o,onHover:u,selectedCount:c=0,onFinish:d}){const{t:i}=G();return r?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:n?`@${n}`:"@ file"}),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:i("chat.selectedCountShort",{n:c})}),e.jsx("span",{children:i("chat.fileMentionHelpMulti")})]})]}),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:l?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:16,className:"animate-spin"}),e.jsx("span",{children:i("chat.searchingFiles")})]}):e.jsx("span",{children:i("chat.noMatchingFiles")})}):t.map((x,h)=>e.jsxs("button",{onClick:()=>o(x),onMouseEnter:()=>u(h),className:`w-full px-3 py-1.5 flex items-center gap-2 text-left text-xs transition-colors border-l-2 ${h===s?"bg-accent-blue/20 text-accent-blue border-accent-blue":"hover:bg-dark-hover text-dark-text border-transparent"}`,children:[x.type==="directory"?e.jsx(Nt,{size:12,className:"text-accent-yellow shrink-0"}):e.jsx(vt,{size:12,className:"text-dark-muted shrink-0"}),e.jsx("span",{className:"truncate",children:x.name}),e.jsx("span",{className:"text-[10px] text-dark-muted truncate ml-auto",children:x.path})]},x.id||x.path))]}),d&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-dark-border bg-dark-bg",children:[e.jsx("span",{className:"text-[10px] text-dark-muted",children:c>0?i("chat.selectedFilesCount",{n:c}):i("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:i("chat.finishMention")})]})]}):null}function ba({open:r,onClose:t,onSelect:s}){const{t:n}=G(),[l,o]=a.useState([]),[u,c]=a.useState(!1),[d,i]=a.useState("");a.useEffect(()=>{r&&(i(""),c(!0),ue.skills.list().then(h=>{const g=Array.isArray(h.data)?h.data:[];o(g.filter(k=>k.enabled!==!1))}).catch(()=>o([])).finally(()=>c(!1)))},[r]);const x=a.useMemo(()=>{const h=d.trim().toLowerCase();return h?l.filter(g=>[g.id,g.name,g.description,g.category,...g.tags||[]].join(" ").toLowerCase().includes(h)):l},[l,d]);return e.jsx(Yn,{isOpen:r,onClose:t,title:n("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(jt,{size:14,className:"text-dark-muted shrink-0"}),e.jsx("input",{value:d,onChange:h=>i(h.target.value),placeholder:n("skills.pickPlaceholder"),autoFocus:!0,className:"flex-1 bg-transparent outline-none text-sm placeholder-dark-muted/60"}),u&&e.jsx(Oe,{size:13,className:"animate-spin text-dark-muted"})]}),u?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Oe,{size:20,className:"animate-spin text-accent-blue"})}):x.length===0?e.jsx("div",{className:"text-center py-12 text-sm text-dark-muted",children:n("skills.pickEmpty")}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:x.map(h=>e.jsxs("button",{onClick:()=>s(h),className:"text-left rounded-lg border border-dark-border p-3 flex flex-col gap-1 transition-colors hover:border-accent-blue/50 hover:bg-dark-hover",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0",children:[e.jsxs("span",{className:"font-medium text-sm truncate",children:[h.icon||"⭐"," ",h.name]}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted shrink-0",children:h.injection||"lazy"})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate font-mono",children:["$",h.id]}),h.description&&e.jsx("div",{className:"text-xs text-dark-muted line-clamp-2",children:h.description}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-1",children:[e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dark-bg border border-dark-border text-dark-muted truncate",children:h.category||"—"}),e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-accent-blue shrink-0",children:[e.jsx(wt,{size:11}),n("skills.pickUse")]})]})]},h.id))})]})})}const ga=800,Fe=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g;let ka=0;const Xe=new Map;function ya(r){const t=++ka;return Xe.set(t,r),t}function wa(r){Xe.delete(r)}function va(r){return r.length>ga||Fs(r)>0}function Fs(r){return(r.match(/\r\n|\r|\n/g)||[]).length}function ja(r){const t=ya(r),s=Fs(r);return s===0?{id:t,label:`[Pasted text #${t}]`}:{id:t,label:`[Pasted text #${t} +${s} lines]`}}function Na(r){return Fe.lastIndex=0,r.replace(Fe,(t,s)=>{const n=parseInt(s,10),l=Xe.get(n);return l!==void 0?l:t})}function Sa(r){Fe.lastIndex=0;const t=[];let s;for(;(s=Fe.exec(r))!==null;){const n=s[1];n!==void 0&&t.push(parseInt(n,10))}return Fe.lastIndex=0,t}function Ca(r){for(const t of r)Xe.delete(t)}function Ea(r){const t=r.match(/\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]$/);return t?t[0]??null:null}function _a(r){const t=r.match(/^\[Pasted text #\d+(?:\s*\+\d+ lines?)?\]/);return t?t[0]??null:null}function as(r){const t=r.match(/#(\d+)/);t&&wa(parseInt(t[1]??"",10))}const Ve=16e3;function ct(){const r=["audio/webm;codecs=opus","audio/webm","audio/mp4"];if(typeof MediaRecorder>"u")return"";for(const t of r)if(MediaRecorder.isTypeSupported(t))return t;return""}async function Aa(r){if(r.sampleRate===Ve&&r.numberOfChannels===1)return r.getChannelData(0);const t=Math.max(1,Math.ceil(r.length*Ve/r.sampleRate)),s=new OfflineAudioContext(1,t,Ve),n=s.createBufferSource();return n.buffer=r,n.connect(s.destination),n.start(0),(await s.startRendering()).getChannelData(0)}function Ma(r,t){const s=new ArrayBuffer(44+r.length*2),n=new DataView(s),l=(u,c)=>{for(let d=0;d<c.length;d++)n.setUint8(u+d,c.charCodeAt(d))};l(0,"RIFF"),n.setUint32(4,36+r.length*2,!0),l(8,"WAVE"),l(12,"fmt "),n.setUint32(16,16,!0),n.setUint16(20,1,!0),n.setUint16(22,1,!0),n.setUint32(24,t,!0),n.setUint32(28,t*2,!0),n.setUint16(32,2,!0),n.setUint16(34,16,!0),l(36,"data"),n.setUint32(40,r.length*2,!0);let o=44;for(let u=0;u<r.length;u++){const c=Math.max(-1,Math.min(1,r[u]??0));n.setInt16(o,c<0?c*32768:c*32767,!0),o+=2}return s}function za(r){return new Promise((t,s)=>{const n=new FileReader;n.onload=()=>{const l=String(n.result||""),o=l.indexOf(",");t(o>=0?l.slice(o+1):l)},n.onerror=()=>s(n.error),n.readAsDataURL(r)})}function Ta(r){const[t,s]=a.useState("idle"),[n,l]=a.useState(0),o=a.useRef(null),u=a.useRef(null),c=a.useRef([]),d=a.useRef(null),i=a.useRef(0),x=a.useCallback(()=>{var w;(w=u.current)==null||w.getTracks().forEach(y=>y.stop()),u.current=null},[]),h=a.useCallback(()=>{d.current&&(clearInterval(d.current),d.current=null)},[]);a.useEffect(()=>()=>{h(),o.current&&o.current.state!=="inactive"&&o.current.stop(),x()},[h,x]);const g=a.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(p){throw p instanceof DOMException&&p.name==="NotAllowedError"?new Error("麦克风权限被拒绝。请在浏览器地址栏允许麦克风权限后重试。"):new Error("无法访问麦克风:"+(p instanceof Error?p.message:String(p)))}u.current=w,c.current=[];const y=new MediaRecorder(w,ct()?{mimeType:ct()}:void 0);y.ondataavailable=p=>{p.data&&p.data.size>0&&c.current.push(p.data)},o.current=y,y.start(),i.current=Date.now(),l(0),s("recording"),d.current=setInterval(()=>l(Date.now()-i.current),100)},[t]),k=a.useCallback(async()=>{var p;const w=o.current;if(!w||w.state==="inactive")throw new Error("当前没有进行中的录音。");const y=new Promise(C=>{w.onstop=()=>C()});w.stop(),await y,h(),x(),o.current=null,s("transcribing");try{const C=new Blob(c.current,{type:ct()||"audio/webm"});c.current=[];const F=await C.arrayBuffer(),E=new AudioContext;let z;try{z=await E.decodeAudioData(F)}finally{E.close()}if(z.duration<.25)return s("idle"),"";const j=await Aa(z),N=Ma(j,Ve),D=await za(new Blob([N],{type:"audio/wav"})),M=await ue.stt.transcribe(r,D,"wav");if(!M.success)throw new Error(M.error||"语音转写失败");return((p=M.data)==null?void 0:p.text)??""}finally{s("idle")}},[r,h,x]),b=a.useCallback(()=>{const w=o.current;w&&w.state!=="inactive"&&w.stop(),o.current=null,c.current=[],h(),x(),s("idle")},[h,x]);return{state:t,elapsedMs:n,start:g,stop:k,cancel:b}}function Ia(){return typeof window<"u"&&!!window.__TAURI__}async function Ra(){const r=window.__TAURI__;if(!r)return null;try{const t=await r.core.invoke("pick_files");return Array.isArray(t)?t.map(s=>String(s)).filter(Boolean):null}catch(t){return console.warn("[native] pick_files failed, falling back to browser picker:",t),null}}const $a=({isOpen:r,commands:t,selectedIndex:s,filter:n,onSelect:l,onHover:o,containerRef:u})=>{const{t:c}=G();return!r||t.length===0?null:e.jsxs("div",{ref:u,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:n?`/${n}`:c("slashCommands.quickCommands")}),e.jsx("span",{className:"opacity-70",children:c("slashCommands.help")})]}),t.map((d,i)=>e.jsxs("button",{"data-index":i,onClick:()=>l(d),onMouseEnter:()=>o(i),className:`w-full px-3 py-2 flex items-start gap-3 text-left transition-colors border-l-2 ${i===s?"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})]}),i===s&&e.jsx(Nn,{size:14,className:"text-dark-muted shrink-0 mt-0.5","aria-hidden":"true"})]},d.id))]})},Os=["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"],ls=new RegExp(`(?:\\.(${Os.join("|")})|dockerfile|makefile)$`,"i"),qs=["png","jpg","jpeg","webp","gif","bmp","svg"],dt=new RegExp(`\\.(${qs.join("|")})$`,"i"),Pa=10*1024*1024,Da=Os.map(r=>`.${r}`).join(",")+",.Dockerfile,.Makefile,"+qs.map(r=>`.${r}`).join(","),La=".deepseekcode/attachments",Ba=50*1024*1024,Ge=10,Fa=r=>/\.xlsx?$/i.test(r)?bt:/\.(csv|docx|txt|md|mdx|rst|adoc|json|jsonc|yaml|yml|toml|xml|html|css|scss|less|env|gitignore|gitattributes|editorconfig)$/i.test(r)?ft:/\.(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(r)?zn:vt,ut=3e3,is=5,xt=50;function Oa(r,t){const s=r.slice(0,t),n=s.lastIndexOf("@");if(n===-1)return{active:!1,query:"",start:-1};const l=s.slice(n+1);return/^[\p{L}\p{N}_\-./]*$/u.test(l)?{active:!0,query:l,start:n}:{active:!1,query:"",start:-1}}function qa(r,t){const s=r.lastIndexOf(`
27
- `,t-1)+1,n=r.slice(s,t);return n.startsWith("/")?/\s/.test(n)?{active:!1,query:""}:{active:!0,query:n.slice(1)}:{active:!1,query:""}}const Ha=a.memo(function({sessionId:t,onSend:s,onStop:n,onPause:l,onResume:o,slashOptions:u,workspaceDir:c,onWorkspaceSelect:d}){const{t:i}=G(),x=be(m=>{var f;return((f=m.sessionInputs)==null?void 0:f[t])??""}),h=be(m=>m.setSessionInput),g=be(m=>{var f;return((f=m.generatingSessions)==null?void 0:f.includes(t))??!1}),k=be(m=>{var f;return((f=m.pausedSessions)==null?void 0:f.includes(t))??!1}),b=a.useRef(null),w=a.useRef(null),y=a.useRef(!1),[p,C]=a.useState([]),[F,E]=a.useState(!1),[z,L]=a.useState(!1),j=a.useCallback(m=>{h(t,m)},[t,h]),[N,D]=a.useState(()=>{try{return localStorage.getItem("dsc.stt.lang")==="zh"?"zh":"en"}catch{return"en"}}),M=a.useCallback(()=>{D(m=>{const f=m==="en"?"zh":"en";try{localStorage.setItem("dsc.stt.lang",f)}catch{}return f})},[]),R=Ta(N),W=a.useRef(null),K=a.useCallback(async()=>{var m;try{if(!W.current){const I=await ue.stt.status();I.success&&I.data&&(W.current=I.data)}const f=W.current;if(!f)return!0;if(f.service!=="ok"&&f.service!=="stopped")return ie.warning(i("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1;const _=(m=f.backends)==null?void 0:m[N];return _&&!_.installed?(ie.warning(i("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1):!0}catch{return!0}},[i,N]);a.useEffect(()=>{const m=()=>{W.current=null};return window.addEventListener("stt-backends-changed",m),()=>window.removeEventListener("stt-backends-changed",m)},[]),a.useEffect(()=>{const m=f=>{var I;const _=(I=f.detail)==null?void 0:I.lang;(_==="en"||_==="zh")&&D(_)};return window.addEventListener("stt-lang-changed",m),()=>window.removeEventListener("stt-lang-changed",m)},[]);const Z=a.useCallback(m=>{const f=b.current,_=(f==null?void 0:f.selectionStart)??x.length,I=x.slice(0,_)+m+x.slice(_);j(I),requestAnimationFrame(()=>{f==null||f.focus();const q=_+m.length;f&&(f.selectionStart=f.selectionEnd=q)})},[x,j]),V=a.useCallback(async()=>{if(R.state==="recording"){try{const f=await R.stop();f?Z(f):ie.info(i("stt.noSpeech"))}catch(f){ie.error(f instanceof Error?f.message:String(f))}return}if(!(R.state!=="idle"||!await K()))try{await R.start()}catch(f){ie.error(f instanceof Error?f.message:String(f))}},[R,Z,K,i]),he=er(u),{isOpen:S,filter:U,filteredCommands:O,selectedIndex:Q,setSelectedIndex:te,selectNext:re,selectPrev:me,executeCommand:ee,openMenu:fe,closeMenu:ae,setFilter:ye,allCommands:de,containerRef:A}=he,[T,B]=a.useState(!1),[ne,v]=a.useState(""),[H,P]=a.useState([]),[oe,xe]=a.useState(0),[He,Re]=a.useState(!1),[Js,$e]=a.useState(0),_e=a.useRef(-1),Ae=a.useRef(new Set),Pe=a.useRef(null),Je=a.useRef(null),Ye=a.useRef([]),we=a.useRef(!1);a.useEffect(()=>{Ae.current=new Set,we.current=!1,B(!1),v(""),P([]),$e(0),ae()},[t,ae]);const _t=a.useDeferredValue(x),At=Be(m=>m.estimateTokens),et=a.useMemo(()=>At(_t),[_t,At]),Mt=a.useCallback(()=>{const m=b.current;m&&(m.style.height="auto",m.style.height=Math.min(m.scrollHeight,200)+"px")},[]);a.useEffect(()=>{Mt()},[x,p.length,Mt]);const tt=a.useCallback(()=>{if(Pe.current)return Promise.resolve(Pe.current);if(Je.current)return Je.current;Re(!0);const m=(async()=>{try{const f=await ue.files.list(),_=f.success&&f.data?f.data[0]:void 0;if(!_)return Pe.current=[],[];const I=[],q=new Set,$=async(J,se)=>{if(se>is||I.length>=ut)return;const X=[];for(const Y of J||[]){if(I.length>=ut)return;const ve=Y.path.replace(/\\/g,"/");q.has(ve)||(q.add(ve),Y.type==="file"?I.push({...Y,path:ve}):Y.children&&Y.children.length>0?await $(Y.children,se+1):se<is&&X.push(Y))}if(X.length===0)return;const pe=await Promise.all(X.map(async Y=>{var ve;try{const je=await ue.files.list(Y.path.replace(/\\/g,"/"));return je.success&&je.data?((ve=je.data[0])==null?void 0:ve.children)||[]:[]}catch{return[]}}));for(const Y of pe){if(I.length>=ut)return;await $(Y,se+1)}};return await $(_.children,1),Pe.current=I,I}catch{return Pe.current=[],[]}finally{Je.current=null,Re(!1)}})();return Je.current=m,m},[]),zt=a.useCallback(async(m,f)=>{if(we.current){const J=_e.current;if(J<0||f<J){we.current=!1,B(!1);return}const se=m.slice(J,f);if(/\s/.test(se)){we.current=!1,B(!1);return}_e.current=J,v(se),B(!0),xe(0);const X=await tt();Ye.current=X;const pe=se.toLowerCase();P(X.filter(Y=>!pe||Y.path.toLowerCase().includes(pe)).slice(0,xt));return}const _=Oa(m,f);if(!_.active){T&&B(!1);return}_e.current=_.start,v(_.query),B(!0),xe(0);const I=await tt();Ye.current=I;const q=_.query.toLowerCase(),$=I.filter(J=>!q||J.path.toLowerCase().includes(q)).slice(0,xt);P($)},[T,tt]),Us=a.useCallback(m=>{const f=m.target.value,_=m.target.selectionStart??f.length;j(f),zt(f,_);const I=qa(f,_);I.active?(S||fe(),ye(I.query),te(0)):S&&ae()},[j,zt,S,fe,ye,te,ae]),st=a.useCallback(m=>{const f=b.current,_=x,I=_e.current>=0?_e.current:(f==null?void 0:f.selectionStart)??_.length,q=Math.min(_.length,I+1+ne.length),$=`@${m.path} `,J=_.slice(0,I)+$+_.slice(q);Ae.current.add(m.path),j(J),B(!0),v(""),P(Ye.current.slice(0,xt)),xe(0),$e(Ae.current.size),_e.current=I+$.length,we.current=!0,requestAnimationFrame(()=>{f==null||f.focus(),f&&(f.selectionStart=f.selectionEnd=I+$.length)})},[x,ne,j]),De=a.useCallback(()=>{we.current=!1,B(!1),v(""),$e(0)},[]),nt=a.useCallback(m=>{if(!m.args){const $=ee(m,"");$!=null&&$.message&&($.success?ie.success($.message):ie.error($.message)),j("");return}const f=b.current,_=(f==null?void 0:f.selectionStart)??x.length,I=x.lastIndexOf(`
28
- `,_-1)+1,q=x.slice(0,I)+`/${m.name} `+x.slice(_);j(q),ae(),requestAnimationFrame(()=>{f==null||f.focus();const $=I+m.name.length+2;f&&(f.selectionStart=f.selectionEnd=$)})},[x,j,ee,ae]),Ws=a.useCallback(m=>{const f=b.current,_=(f==null?void 0:f.selectionStart)??x.length,I=`$${m.id} `,q=x.slice(0,_)+I+x.slice(_);j(q),L(!1),we.current=!1,B(!1),v(""),requestAnimationFrame(()=>{f==null||f.focus();const $=_+I.length;f&&(f.selectionStart=f.selectionEnd=$)})},[x,j]),Tt=a.useCallback(m=>new Promise((f,_)=>{const I=new FileReader;I.onload=()=>f(String(I.result??"")),I.onerror=()=>_(new Error("Failed to read image")),I.readAsDataURL(m)}),[]),Me=a.useCallback(m=>{const f=Array.from(m);C(_=>{const I=Ge-_.length,q=_.slice();for(const $ of f.slice(0,I)){const J=dt.test($.name);if(!J&&!ls.test($.name)){ie.warning(i("fileJob.unsupportedType",{name:$.name}));continue}if($.size>(J?Pa:Ba)){ie.error(i("fileJob.fileTooLarge",{name:$.name}));continue}if(q.some(X=>X.name===$.name)){ie.warning(i("fileJob.duplicateFile",{name:$.name}));continue}const se={id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,file:$,name:$.name,size:$.size,uploading:!1};J&&Tt($).then(X=>{C(pe=>pe.map(Y=>Y.id===se.id?{...Y,imageDataUri:X}:Y))}).catch(()=>{C(X=>X.filter(pe=>pe.id!==se.id)),ie.error(i("fileJob.uploadFailed",{name:$.name}))}),q.push(se)}return q.length>=Ge&&ie.warning(i("fileJob.maxAttachments",{n:Ge})),q})},[i,Tt]),Ks=a.useCallback(m=>{m.target.files&&m.target.files.length>0&&(Me(m.target.files),m.target.value="")},[Me]),Gs=a.useCallback(async()=>{var m,f;if(Ia()){const _=await Ra();if(!_||_.length===0)return;const I=await ue.fileJob.importPaths(_);if(I.success&&Array.isArray(I.data)){const q=I.data.filter($=>ls.test($.name)||dt.test($.name)).map($=>({id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:$.name,size:$.size,uploading:!1,path:$.path.replace(/\\/g,"/")}));C($=>{const J=Ge-$.length;return[...$,...q.slice(0,J)]});for(const $ of q.filter(J=>dt.test(J.name)))try{const J=sessionStorage.getItem("auth_token")??localStorage.getItem("auth_token"),se={};J&&(se.Authorization=`Bearer ${J}`);const X=await fetch(`/api/files/read?path=${encodeURIComponent($.path)}&base64=1`,{headers:se});if(X.ok){const pe=await X.json();if((m=pe.data)!=null&&m.base64){const Y=`data:${pe.data.mime??"image/png"};base64,${pe.data.base64}`;C(ve=>ve.map(je=>je.path===$.path?{...je,imageDataUri:Y}:je))}}}catch{}}else ie.error(I.error||i("fileJob.importFailed"))}else(f=w.current)==null||f.click()},[i]),Zs=a.useCallback(m=>{C(f=>f.filter(_=>_.id!==m))},[]),Vs=a.useCallback(m=>{m.preventDefault(),E(!0)},[]),Qs=a.useCallback(m=>{m.preventDefault(),E(!1)},[]),Xs=a.useCallback(m=>{m.preventDefault(),E(!1),m.dataTransfer.files&&m.dataTransfer.files.length>0&&Me(m.dataTransfer.files)},[Me]),It=a.useCallback(async()=>{var f;if(p.length===0)return"";const m=[];for(const _ of p){if(_.imageDataUri)continue;if(_.path){m.push(`<attachment path="${_.path}" />`);continue}if(!_.file)continue;C($=>$.map(J=>J.id===_.id?{...J,uploading:!0,error:void 0}:J));const I=`${La}/${_.name}`,q=await ue.files.upload(_.file,I);if(q.success&&((f=q.data)!=null&&f.path)){const $=q.data.path.replace(/\\/g,"/");C(J=>J.map(se=>se.id===_.id?{...se,uploading:!1,path:$}:se)),m.push(`<attachment path="${$}" />`)}else C($=>$.map(J=>J.id===_.id?{...J,uploading:!1,error:q.error||i("fileJob.uploadFailed")}:J)),ie.error(`${_.name}: ${q.error||i("fileJob.uploadFailed")}`)}return m.length>0?`${m.join(`
29
- `)}
30
-
31
- `:""},[p,i]),Ys=a.useCallback(m=>{const f=m.clipboardData.getData("text/plain");if(m.clipboardData.files&&m.clipboardData.files.length>0){m.preventDefault(),Me(m.clipboardData.files);return}if(!f||!va(f))return;m.preventDefault();const{label:_}=ja(f),I=b.current;if(!I)return;const q=I.selectionStart,$=I.selectionEnd,J=I.value,se=J.slice(0,q)+_+J.slice($);j(se),requestAnimationFrame(()=>{I.selectionStart=I.selectionEnd=q+_.length})},[j,Me]),Ue=a.useCallback(async()=>{const m=Na(x);Ca(Sa(m)),we.current=!1,B(!1),ae();const f=m.trim(),_=p.length>0;if(!f&&!_)return;const I=m.trim();if(I.startsWith("/")&&!_){const X=tr(I);if(X){const pe=de.find(Y=>Y.name===X.command);if(pe){const Y=ee(pe,X.args);Y!=null&&Y.message&&(Y.success?ie.success(Y.message):ie.error(Y.message)),j(""),C([]),Ae.current=new Set,$e(0);return}ie.error(i("slashCommands.unknownCommand",{cmd:`/${X.command}`}));return}}const q=Array.from(Ae.current).filter(X=>m.includes(`@${X}`));let $="";if(_){if(p.some(X=>X.uploading)){ie.warning(i("fileJob.stillUploading"));return}$=await It()}const J=($+m).trim();if(!J&&!_)return;const se=p.filter(X=>X.imageDataUri).map(X=>X.imageDataUri);s(J||$.trim(),q.length>0?q:void 0,se.length>0?se:void 0),j(""),C([]),Ae.current=new Set,$e(0)},[x,p,s,j,It,i,ae,de,ee]),en=a.useCallback(m=>{if(!m.nativeEvent.isComposing){if((m.key==="Backspace"||m.key==="Delete")&&!m.ctrlKey&&!m.metaKey&&!m.altKey&&!m.shiftKey){const f=b.current;if(f&&f.selectionStart===f.selectionEnd){const _=f.selectionStart,I=f.value;if(m.key==="Backspace"&&_>0){const q=Ea(I.slice(0,_));if(q){m.preventDefault(),j(I.slice(0,_-q.length)+I.slice(_)),as(q),requestAnimationFrame(()=>{f.focus();const $=_-q.length;f.selectionStart=f.selectionEnd=$});return}}else if(m.key==="Delete"&&_<I.length){const q=_a(I.slice(_));if(q){m.preventDefault(),j(I.slice(0,_)+I.slice(_+q.length)),as(q),requestAnimationFrame(()=>{f.focus(),f.selectionStart=f.selectionEnd=_});return}}}}if(T&&H.length>0){if(m.key==="ArrowDown"){m.preventDefault(),xe(f=>(f+1)%H.length);return}if(m.key==="ArrowUp"){m.preventDefault(),xe(f=>(f-1+H.length)%H.length);return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const f=H[oe];f&&(m.preventDefault(),st(f));return}if(m.key==="Escape"){m.preventDefault(),De();return}}else if(T&&m.key==="Escape"){m.preventDefault(),De();return}if(S&&O.length>0){if(m.key==="ArrowDown"){m.preventDefault(),re();return}if(m.key==="ArrowUp"){m.preventDefault(),me();return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const f=O[Q];f&&(m.preventDefault(),nt(f));return}if(m.key==="Escape"){m.preventDefault(),ae();return}}else if(S&&m.key==="Escape"){m.preventDefault(),ae();return}if(m.key==="Escape"&&g){m.preventDefault(),k?o():l();return}if(m.key==="Enter"&&(m.ctrlKey||m.metaKey)){m.preventDefault(),Ue();return}m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Ue())}},[g,k,Ue,l,o,T,H,oe,st,De,S,O,Q,re,me,nt,ae,j]),tn=a.useCallback(()=>{y.current=!0},[]),sn=a.useCallback(()=>{y.current=!1},[]),Rt=et>8e3,nn=x.trim().length>0||p.length>0;return e.jsxs("div",{className:"chat-composer-shell shrink-0 px-3 pb-3 pt-2 sm:px-4",onDragOver:Vs,onDragLeave:Qs,onDrop:Xs,children:[p.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:p.map(m=>{const f=Fa(m.name);return e.jsxs("div",{className:le("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"),children:[m.imageDataUri?e.jsx("img",{src:m.imageDataUri,alt:m.name,className:"h-6 w-6 rounded object-cover",title:i("fileJob.imagePreview")}):m.uploading?e.jsx(Ie,{size:13,className:"animate-spin"}):e.jsx(f,{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:()=>Zs(m.id),className:"rounded p-0.5 text-dark-muted hover:text-accent-red hover:bg-accent-red/10 transition-colors","aria-label":i("a11y.close"),children:e.jsx(Ee,{size:11})})]},m.id)})}),F&&e.jsx("div",{className:"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:i("fileJob.dropHint")}),e.jsxs("div",{className:"chat-composer-card relative rounded-xl border transition-all duration-150",children:[T&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!T,children:e.jsx(fa,{isOpen:T,files:H,selectedIndex:oe,query:ne,isSearching:He,onSelect:st,onHover:xe,selectedCount:Js,onFinish:De})}),S&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!S,children:e.jsx($a,{isOpen:S,commands:O,selectedIndex:Q,filter:U,onSelect:nt,onHover:te,containerRef:A})}),e.jsx("textarea",{ref:b,value:x,onChange:Us,onKeyDown:en,onPaste:Ys,onBlur:()=>{T&&De(),ae()},onCompositionStart:tn,onCompositionEnd:sn,placeholder:i(g?"chat.generatingPlaceholder":"chat.inputPlaceholder"),rows:1,disabled:g&&!k,"aria-label":"Message input",className:`w-full bg-transparent px-4 pt-3.5 pb-2 text-sm text-dark-text placeholder-dark-muted/60
32
- resize-none focus:outline-none min-h-[44px] max-h-[40vh] leading-relaxed
33
- disabled:opacity-50 disabled:cursor-not-allowed`}),e.jsxs("div",{className:"flex items-center gap-2 px-2.5 pb-2.5",children:[d&&e.jsx(ha,{workspaceDir:c,onSelect:d}),e.jsx(ca,{}),e.jsx("span",{className:"hidden sm:block",children:e.jsx(da,{})}),e.jsx("div",{className:"flex-1"}),et>0&&x.length>0&&e.jsxs("span",{className:`text-[10px] tabular-nums ${Rt?"text-accent-red font-medium":"text-dark-muted/60"}`,children:["~",et," tokens",Rt?` · ${i("chat.nearLimit")}`:""]}),!g&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:M,disabled:R.state!=="idle",className:`flex h-8 items-center justify-center rounded-full px-2 text-[11px] font-semibold text-dark-muted transition-colors
34
- hover:bg-dark-hover hover:text-dark-text disabled:opacity-40`,title:i("stt.langToggle"),"aria-label":i("stt.langToggle"),children:N==="en"?"EN":i("stt.langZh")}),e.jsx("button",{onClick:()=>void V(),disabled:R.state==="transcribing",className:le("flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors",R.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"),title:R.state==="recording"?i("stt.stopTitle"):i("stt.title"),"aria-label":R.state==="recording"?i("stt.stopTitle"):i("stt.title"),children:R.state==="transcribing"?e.jsx(Ie,{size:15,className:"animate-spin","aria-hidden":"true"}):R.state==="recording"?e.jsx(Sn,{size:15,"aria-hidden":"true"}):e.jsx(Cn,{size:15,"aria-hidden":"true"})}),R.state==="recording"&&e.jsxs("span",{className:"text-[10px] tabular-nums text-accent-red","aria-hidden":"true",children:[(R.elapsedMs/1e3).toFixed(0),"s"]})]}),!g&&e.jsx("button",{onClick:()=>L(!0),className:"flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors hover:bg-dark-hover hover:text-dark-text",title:i("skills.pickTitle"),"aria-label":i("skills.pickTitle"),children:e.jsx(En,{size:15,"aria-hidden":"true"})}),!g&&e.jsx("button",{onClick:()=>void Gs(),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:i("fileJob.attach"),"aria-label":i("fileJob.attach"),children:e.jsx(_n,{size:15,"aria-hidden":"true"})}),e.jsx("input",{ref:w,type:"file",multiple:!0,accept:Da,className:"hidden",onChange:Ks}),g?e.jsxs("div",{className:"flex items-center gap-1.5",children:[k?e.jsx("button",{onClick:o,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:i("chat.resumeGen"),"aria-label":i("chat.resumeGen"),children:e.jsx(An,{size:14,"aria-hidden":"true"})}):e.jsx("button",{onClick:l,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:i("chat.pauseGen"),"aria-label":i("chat.pauseGen"),children:e.jsx(hs,{size:14,"aria-hidden":"true"})}),e.jsx("button",{onClick:n,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:i("chat.stopGen"),"aria-label":i("chat.stopGen"),children:e.jsx(Mn,{size:13,"aria-hidden":"true"})})]}):e.jsx("button",{onClick:()=>void Ue(),disabled:!nn,className:`flex h-8 w-8 items-center justify-center rounded-full bg-dark-text text-dark-bg transition-all
35
- hover:opacity-80 active:scale-95 disabled:opacity-25 disabled:cursor-not-allowed`,title:i("chat.sendBtn"),"aria-label":i("chat.sendBtn"),children:e.jsx(bs,{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:i("chat.shiftEnter")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:i("chat.escHint")})]}),e.jsx(ba,{open:z,onClose:()=>L(!1),onSelect:Ws})]})}),Ja=15e3,Ua=300;function Hs(r){const{t}=G();return a.useMemo(()=>{const s=t("chat.askOtherLabel"),n=t("chat.askProceedLabel"),l=r.options||[],o=l.some(x=>x.label===s),u=l.some(x=>x.label===n),c=[...l];u||c.push({label:n,description:t("chat.askProceedDesc")}),o||c.push({label:s,description:t("chat.askCustomDesc")});const d=o?c.findIndex(x=>x.label===s):c.length-1,i=u?c.findIndex(x=>x.label===n):c.length-(o?1:2);return{allItems:c,otherIdx:d,proceedIdx:i,displayItems:c}},[r,t])}function os({item:r,answered:t,selectedIdx:s,multiSelected:n,customInput:l,showCustomInput:o,onSelect:u,onToggleMulti:c,onProceed:d,onEnterCustom:i,onCancelCustom:x,onSubmitCustom:h,onCustomChange:g,inputRef:k}){const{t:b}=G(),{otherIdx:w,proceedIdx:y,displayItems:p}=Hs(r),C=!!r.multiSelect,F=E=>{if(E===y){d();return}if(E===w){i();return}if(C){c(E);return}u(E)};return e.jsxs("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:[p.map((E,z)=>{const L=s===z,j=n.has(z),N=z===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 ${L?"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:()=>F(z),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[C&&e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center text-[10px] ${j?"bg-blue-600 border-blue-600 text-white":"border-gray-400 dark:border-gray-500"}`,children:j&&e.jsx(Se,{size:10})}),e.jsxs("span",{className:`font-medium ${L?"text-blue-700 dark:text-blue-300":"text-gray-800 dark:text-gray-200"}`,children:[C?"":`${z+1}. `,E.label]}),z===y&&e.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:b("chat.askDirectTag")}),N&&e.jsx("span",{className:"text-xs text-gray-400",children:b("chat.askCustomTag")})]}),E.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 ml-6",children:E.description})]}),N&&L&&o&&e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("textarea",{ref:k,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:l,onChange:D=>g(D.target.value),onKeyDown:D=>{D.key==="Enter"&&!D.shiftKey&&(D.preventDefault(),h()),D.key==="Escape"&&x()},placeholder:b("chat.askAnswerPlaceholder"),autoFocus:!0}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700",onClick:h,children:[e.jsx(ze,{size:12}),b("chat.askSubmit")]}),e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium text-gray-600 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 rounded-md hover:bg-gray-200 dark:hover:bg-gray-600",onClick:x,children:[e.jsx(Ee,{size:12}),b("common.cancel")]})]})]})]},`opt-${z}`)}),t&&e.jsx("div",{className:"text-xs text-emerald-600 dark:text-emerald-400 font-medium",children:b("chat.askAnswered")})]})}function Wa({isOpen:r,onClose:t}){const{t:s}=G(),[n,l]=a.useState(null),[o,u]=a.useState(-1),[c,d]=a.useState(new Set),[i,x]=a.useState(""),[h,g]=a.useState(!1),[k,b]=a.useState(!1),[w,y]=a.useState(0),[p,C]=a.useState([]),[F,E]=a.useState(!1),z=a.useRef(null),L=a.useRef(null),j=a.useMemo(()=>n?n.questions&&n.questions.length>0?n.questions:[{question:n.question,header:n.header,options:n.options,multiSelect:n.multiSelect}]:[],[n]),N=j.length>1,D=a.useCallback(A=>{l(A),u(A.multiSelect?-1:0),d(new Set),x(""),g(!1),b(!1),y(0),E(!1);const T=A.questions&&A.questions.length>0?A.questions:[A];C(T.map(()=>null))},[]);a.useEffect(()=>{L.current=n}),a.useEffect(()=>{if(r){const A=window.__pendingQuestion;A&&D(A)}},[r,D]),a.useEffect(()=>{const A=T=>{var H;const B=T.detail,ne=((H=L.current)==null?void 0:H.questionId)??null;if(B&&ne&&B!==ne)return;const v=ne;b(!0),setTimeout(()=>{var oe;const P=((oe=L.current)==null?void 0:oe.questionId)??null;v&&P&&P!==v||(t(),l(null),b(!1))},Ua)};return window.addEventListener("ask-question-dismiss",A),()=>window.removeEventListener("ask-question-dismiss",A)},[t]),a.useEffect(()=>{if(!k)return;const A=setTimeout(()=>b(!1),Ja);return()=>clearTimeout(A)},[k]),a.useEffect(()=>{const A=()=>{const T=window.__pendingQuestion;T&&D(T)};return window.addEventListener("ask-question-required",A),()=>window.removeEventListener("ask-question-required",A)},[D]),a.useEffect(()=>{u(0),d(new Set),x(""),g(!1)},[w,F,n]);const M=j[w]||null,{allItems:R,otherIdx:W}=Hs(M||{question:""}),K=a.useCallback((A,T)=>{k||!n||(b(!0),ce.send({type:"question_answer",sessionId:ce.getSessionId()??void 0,data:JSON.stringify({questionId:n.questionId,answer:A,selectedOptions:T})}))},[k,n]),Z=a.useCallback(()=>{k||!n||(b(!0),ce.send({type:"question_answer",sessionId:ce.getSessionId()??void 0,data:JSON.stringify({questionId:n.questionId,answers:j.map((A,T)=>p[T]||{answer:s("chat.askUnansweredValue")})})}))},[k,n,j,p,s]),V=a.useCallback((A,T,B)=>{C(ne=>{const v=ne.slice();return v[A]={answer:T,selectedOptions:B},v}),A<j.length-1?y(A+1):E(!0)},[j.length]),he=a.useCallback(A=>{if(k||!n)return;const T=R[A];T&&(u(A),K(T.label,[T.label]))},[k,n,R,K]),S=a.useCallback(()=>{if(k||!n||o<0)return;const A=R[o];A&&K(A.label,[A.label])},[k,n,o,R,K]),U=a.useCallback(()=>{if(k||o<0)return;const A=R[o];A&&V(w,A.label,[A.label])},[k,o,R,V,w]),O=a.useCallback(A=>{if(k)return;const T=R[A];T&&V(w,T.label,[T.label])},[k,R,V,w]),Q=a.useCallback(A=>{k||d(T=>{const B=new Set(T);return B.has(A)?B.delete(A):B.add(A),B})},[k]),te=a.useCallback(()=>{if(k)return;const A=[...c].map(T=>{var B;return((B=R[T])==null?void 0:B.label)||""});N?V(w,A.join(", "),A):K(A.join(", "),A)},[k,c,R,N,V,w,K]),re=a.useCallback(()=>{if(k)return;const A=s("chat.askProceedLabel");N?V(w,A,[A]):K(A,[A])},[k,N,V,w,K,s]),me=a.useCallback(()=>{k||(u(W),g(!0),setTimeout(()=>{var A;return(A=z.current)==null?void 0:A.focus()},100))},[k,W]),ee=a.useCallback(()=>{g(!1),x("")},[]),fe=a.useCallback(()=>{if(k)return;const A=i||s("chat.askEmptyInputValue");N?V(w,A):K(A)},[k,i,N,V,w,K,s]),ae=a.useCallback(()=>{k||!n||(b(!0),ce.send({type:"question_answer",sessionId:ce.getSessionId()??void 0,data:JSON.stringify({questionId:n.questionId,answers:j.map(()=>({answer:"(cancelled)"}))})}))},[k,n,j]),ye=a.useCallback(()=>{if(!k){if(N){if(h){g(!1),x("");return}if(F){E(!1),y(j.length-1);return}ae();return}if(h){g(!1),x("");return}K("(cancelled)")}},[k,N,h,F,j.length,ae,K]);if(!r||!n)return null;const de=p.filter(A=>!A).length;return e.jsx(vs,{isOpen:r,onClose:ye,title:n.header||s(N?"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"}),s("chat.askPendingBadge"),N?` · ${p.filter(Boolean).length}/${j.length}`:""]}),collapsedSummary:e.jsx("span",{className:"truncate",children:(M==null?void 0:M.question)||n.question}),maxHeight:"50vh",children:N?e.jsxs("div",{className:"flex flex-col gap-4",children:[n.autoResolutionMs&&n.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:s("chat.askAutoContinue",{seconds:Math.max(1,Math.round(n.autoResolutionMs/1e3))})}),e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[j.map((A,T)=>{const B=!!p[T],ne=!F&&w===T;return e.jsxs("button",{type:"button",onClick:()=>{y(T),E(!1)},className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${ne?"bg-blue-600 text-white":B?"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",T+1," ",B?"✓":""]},`nav-${T}`)}),e.jsx("button",{type:"button",onClick:()=>E(!0),className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${F?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:s("chat.askSubmit")})]}),F?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:s("chat.askReviewTitle")}),j.map((A,T)=>{const B=p[T];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:[T+1,". "]}),A.question]}),e.jsx("div",{className:`text-xs shrink-0 max-w-[45%] text-right break-words ${B?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dark:text-amber-400"}`,children:B?B.answer:s("chat.askNotAnswered")})]},`rev-${T}`)}),de>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-md px-3 py-2",children:[e.jsx(Ce,{size:14}),s("chat.askUnansweredWarning",{count:de})]}),e.jsxs("div",{className:"flex gap-2 mt-1",children:[e.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50",onClick:Z,disabled:k,children:[e.jsx(ze,{size:14}),s("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:()=>{E(!1),y(j.length-1)},disabled:k,children:s("chat.askBackToEdit")})]})]}):M?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:M.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(A=>Math.max(0,A-1)),E(!1)},disabled:w===0,children:[e.jsx(Tn,{size:12}),s("chat.askPrevQuestion")]}),w<j.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(A=>Math.min(j.length-1,A+1)),E(!1)},children:[s("chat.askNextQuestion"),e.jsx(ke,{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:()=>E(!0),children:[s("chat.askViewSubmit"),e.jsx(ke,{size:12})]})]})]}),e.jsx(os,{item:M,answered:!!p[w],selectedIdx:o,multiSelected:c,customInput:i,showCustomInput:h,onSelect:O,onToggleMulti:Q,onProceed:re,onEnterCustom:me,onCancelCustom:ee,onSubmitCustom:fe,onCustomChange:x,inputRef:z}),!h&&e.jsx("div",{className:"flex items-center gap-2",children:M.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:te,disabled:k||c.size===0,children:[e.jsx(ze,{size:14}),s("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:U,disabled:k||o<0,children:[e.jsx(ze,{size:14}),s("chat.askConfirmQuestion")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:h?e.jsx("span",{children:s("chat.askEnterHint")}):M.multiSelect?e.jsx("span",{children:s("chat.askMultiHintBatch")}):e.jsx("span",{children:s("chat.askSingleHintBatch")})})]}):null]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[n.autoResolutionMs&&n.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:s("chat.askAutoContinue",{seconds:Math.max(1,Math.round(n.autoResolutionMs/1e3))})}),e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed",children:n.question}),e.jsx(os,{item:j[0],answered:!1,selectedIdx:o,multiSelected:c,customInput:i,showCustomInput:h,onSelect:he,onToggleMulti:Q,onProceed:re,onEnterCustom:me,onCancelCustom:ee,onSubmitCustom:fe,onCustomChange:x,inputRef:z}),!h&&e.jsx("div",{className:"flex items-center gap-2",children:n.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:te,disabled:k||c.size===0,children:[e.jsx(ze,{size:14}),s("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:S,disabled:k||o<0,children:[e.jsx(ze,{size:14}),s("chat.askSubmit")]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:k?e.jsx("span",{children:s("chat.askSubmitting")}):h?e.jsx("span",{children:s("chat.askEnterHint")}):n.multiSelect?e.jsx("span",{children:s("chat.askMultiHintSingle")}):e.jsx("span",{children:s("chat.askSingleHintSingle")})})]})})}const Le=15;function Ka({isOpen:r,onCloseModal:t}){const{t:s}=G("hook"),n=gt(),l=n.pendingApprovals,o=n.autoMode,u=n.setAutoMode,[c,d]=a.useState(0),[i,x]=a.useState(!1),[h,g]=a.useState(Le),[k,b]=a.useState(!0),w=a.useRef(null),y=a.useRef(!1);a.useEffect(()=>{if(l.length!==0){if(o){l.forEach(T=>{ce.send({type:"hook_allow",data:JSON.stringify({approvalId:T.approvalId})})}),n.clearApprovals();return}d(T=>Math.min(T,l.length-1))}},[l.length,o]);const p=l[c]??null,C=l.length>0&&p!==null,F=l.length,E=C?F-c-1:0;a.useEffect(()=>{if(!(!C||i||!r||!p))return g(Le),w.current=setInterval(()=>{g(T=>T<=1?(w.current&&clearInterval(w.current),0):T-1)},1e3),()=>{w.current&&clearInterval(w.current)}},[C,i,r,p==null?void 0:p.approvalId]);const z=p?ys(p.toolName,p.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},L=ws[z.level],j=sr[z.level==="CRITICAL"?"critical":z.level==="HIGH"?"high":z.level==="LOW"?"low":"medium"],N=p?$s(p.toolName,p.askPayload):null,D=p?nr(p.toolName,p.askPayload):null,M=p?{verb:Is(p.toolName),target:Rs(p.toolName,p.askPayload)}:null,R=p?qe(p.askPayload)!==null:!1,W=p?Ps(p.toolName,p.askPayload):null,K=h/Le*100,Z=h<=5,V=ar(Le-h),he=a.useCallback((T,B)=>{const ne=rr.getState().activeSessionId;ne&&be.getState().updateHookApprovalStatus(ne,T,B)},[]),S=a.useCallback(T=>{p&&(T&&he(p.approvalId,T),x(!0),setTimeout(()=>{n.removeApproval(p.approvalId),d(0),x(!1),y.current=!1,g(Le)},200))},[p==null?void 0:p.approvalId,n,he]),U=a.useCallback(()=>{!p||i||y.current||(y.current=!0,w.current&&clearInterval(w.current),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId})}),S("approved"))},[p,S,i]),O=a.useCallback(()=>{!p||i||y.current||(y.current=!0,w.current&&clearInterval(w.current),ce.send({type:"hook_deny",data:JSON.stringify({approvalId:p.approvalId})}),S("denied"))},[p,S,i]),Q=a.useCallback(()=>{if(!p||i||y.current)return;y.current=!0,w.current&&clearInterval(w.current);const T=qe(p.askPayload);T?(n.addToSessionAllowList(p.toolName,T),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId,sessionAllow:!0})})):(n.addToSessionAllowList(p.toolName),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId})})),S("approved")},[p,S,n,i]),te=a.useCallback(()=>{!p||i||y.current||(y.current=!0,w.current&&clearInterval(w.current),u(!0),Ne.getState().setAuto(!0),ce.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId})}),S("approved"))},[p,S,i,u]),re=((p==null?void 0:p.timeoutMs)??15e3)>0,me=(p==null?void 0:p.timeoutAction)==="deny"?O:U;if(a.useEffect(()=>{h===0&&r&&!i&&p&&re&&me()},[h,r,i,p,me,re]),a.useEffect(()=>{if(!r||!k)return;const T=B=>{const ne=B.target;ne&&typeof ne.closest=="function"&&ne.closest('input, textarea, select, [contenteditable="true"]')||(B.key==="Escape"?(B.preventDefault(),B.stopPropagation(),O()):B.key==="Enter"?(B.preventDefault(),U()):B.key==="1"?U():B.key==="2"?O():B.key==="3"?Q():B.key==="4"&&te())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[r,k,U,O,Q,te]),!C||!p)return null;const ee=s("optionAllowHint"),fe=s("optionDenyHint"),ae=R?s("optionAllowPathHint"):s("optionAllowAlwaysHint",{tool:p.toolName}),ye=s("optionAutoModeHint"),de=(N==null?void 0:N.text)??D??null,A=de?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:p.toolName}),e.jsx("span",{className:"truncate",children:de})]}):null;return e.jsx(vs,{isOpen:r,onClose:()=>t==null?void 0:t(),title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{className:"w-4 h-4 text-yellow-400"}),e.jsx("span",{children:s("hookApproval")}),e.jsxs("span",{className:"text-xs text-dark-muted",children:["(",c+1,"/",F,")"]})]}),badge:e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${L.badge}`,children:[L.icon," ",z.level]}),collapsedSummary:A,onExpandedChange:b,maxHeight:"50vh",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${L.bg} border ${L.border}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${L.badge}`,children:[L.icon," ",z.level]}),e.jsx("span",{className:"text-xs text-dark-muted truncate",children:s(z.reasonKey)}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[e.jsx(Te,{size:12,className:Z?"text-accent-red":"text-dark-muted"}),e.jsx("span",{className:`text-xs font-mono ${Z?"text-accent-red animate-pulse":"text-dark-muted"}`,children:re?`${h}s`:"∞"}),e.jsx("div",{className:"w-12 h-1.5 bg-dark-border rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${Z?"bg-accent-red":h<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${K}%`}})})]})]}),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(mt,{size:15})}),M&&e.jsx(Ds,{pre:s(M.verb),obj:M.target})]}),W&&(W.external&&W.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:W.path,children:[e.jsx(ps,{size:10}),s("scopeExternal"),": ",W.path.length>48?`${W.path.slice(0,47)}…`:W.path]}):e.jsx("span",{className:"text-[11px] text-dark-muted/60 shrink-0",children:s("scopeLocal")}))]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-dark-muted shrink-0",children:s("tool")}),e.jsx("code",{className:"text-accent-blue font-mono text-xs bg-dark-surface px-1.5 py-0.5 rounded truncate",children:p.toolName}),e.jsx("span",{className:"text-dark-muted/50",children:V}),e.jsx("span",{className:"text-dark-muted/50",children:j.label}),p.timeoutAction&&e.jsxs("span",{className:`text-xs ${p.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",re?`${p.timeoutAction==="allow"?"auto-allow":"auto-deny"}${p.timeoutMs?` (${(p.timeoutMs/1e3).toFixed(0)}s)`:""}`:s("timeoutWaitUser")]})]}),N?e.jsx(yt,{text:N.text,mono:N.mono}):D?e.jsx(yt,{text:D}):null,(z.level==="CRITICAL"||z.level==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${L.bg} ${L.text}`,children:[e.jsx(Ce,{size:13}),e.jsx("span",{children:z.level==="CRITICAL"?s("highRiskWarning"):s("mediumRiskConfirm")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:U,disabled:i,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:We.allow.label}),e.jsx("span",{className:"text-[11px] text-white/70 hidden sm:inline",children:ee})]}),e.jsxs("button",{onClick:Q,disabled:i,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:We.allow_session.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:ae})]}),e.jsxs("button",{onClick:te,disabled:i,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:We.auto.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:ye})]}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:O,disabled:i,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:We.deny.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:fe})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-dark-muted/60",children:[e.jsx("span",{children:s("shortcutHint")}),e.jsx("span",{children:E>0?s("morePending",{n:E}):s("lastItem")})]})]})})}const pt="dsc-auto-access-banner-dismissed",Ga=a.memo(function(){const{t}=G(),s=Ne(c=>c.mode),[n,l]=a.useState(()=>localStorage.getItem(pt)==="1");a.useEffect(()=>{kt(s==="normal"?"act":s)||localStorage.getItem(pt)==="1"&&l(!1)},[s]);const o=a.useCallback(c=>{c&&localStorage.setItem(pt,"1"),l(!0)},[]);return!(s!=="normal"&&kt(s))||n?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(In,{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(Ee,{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")})]})}),cs=24,ds=240,Za={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"}},Va=({status:r})=>r==="running"?e.jsx(Ie,{size:12,className:"animate-spin text-accent-blue"}):r==="completed"?e.jsx(ht,{size:12,className:"text-accent-green"}):r==="failed"?e.jsx(Dn,{size:12,className:"text-accent-red"}):r==="skipped"?e.jsx(Ln,{size:12,className:"text-dark-muted"}):e.jsx(Bn,{size:12,className:"text-dark-muted"}),Qa=a.memo(function({sessionId:t,defaultExpanded:s,onClose:n}){const{t:l}=G(),[o,u]=a.useState(s??!1),[c,d]=a.useState(null),i=js(M=>M.getTasksForSession(t)),[x,h]=a.useState(null),g=a.useRef(null),k=a.useRef(!1),b=a.useRef(null),w=a.useCallback(M=>{var R;M.button===0&&(M.target.closest("[data-taskboard-close]")||(k.current=!1,g.current={y:M.clientY,expanded:o,bodyHeight:((R=b.current)==null?void 0:R.offsetHeight)??0},M.currentTarget.setPointerCapture(M.pointerId)))},[o]),y=a.useCallback(M=>{const R=g.current;R&&(Math.abs(M.clientY-R.y)>4&&(k.current=!0),h(M.clientY-R.y))},[]),p=a.useCallback(M=>{const R=g.current;if(!R)return;const W=M.clientY-R.y;R.expanded&&W<-cs?u(!1):!R.expanded&&W>cs&&u(!0),g.current=null,h(null),setTimeout(()=>{k.current=!1},0)},[]),C=a.useCallback(()=>{if(k.current){k.current=!1;return}u(M=>!M)},[]),F=a.useCallback(M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),u(R=>!R))},[]),E=x!==null,z=a.useMemo(()=>{const M=g.current;return x===null||!M?null:M.expanded?Math.min(ds,Math.max(0,M.bodyHeight+x)):Math.min(ds,Math.max(0,x))},[x]),L=a.useMemo(()=>{const M=i.length,R=i.filter(V=>V.status==="completed").length,W=i.filter(V=>V.status==="running").length,K=i.filter(V=>V.status==="failed").length,Z=M>0?Math.round(R/M*100):0;return{total:M,completed:R,running:W,failed:K,progress:Z}},[i]),j=a.useMemo(()=>{const M={pending:[],running:[],completed:[],failed:[]};return i.forEach(R=>{const W=R.status==="skipped"?"pending":R.status;M[W].push(R)}),M},[i]),N=[...j.running,...j.failed,...j.pending.slice(0,5),...j.completed.slice(-3)],D=o||E;return i.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:C,onKeyDown:F,onPointerDown:w,onPointerMove:y,onPointerUp:p,onPointerCancel:p,onLostPointerCapture:p,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:l("chat.taskBoardDragHint"),children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Rn,{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:[L.completed,"/",L.total]}),L.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 ${L.running>0?"bg-accent-blue":L.failed>0?"bg-accent-red":"bg-accent-green"}`,style:{width:`${L.progress}%`}})}),L.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:[n&&e.jsx("span",{role:"button",tabIndex:0,"data-taskboard-close":!0,onClick:M=>{M.stopPropagation(),n()},onKeyDown:M=>{M.key==="Enter"&&(M.stopPropagation(),n())},className:"p-0.5 rounded hover:bg-dark-hover transition-colors cursor-pointer",title:"Hide task drawer",children:e.jsx(Ee,{size:12,className:"text-dark-muted"})}),e.jsx($n,{size:12,className:"text-dark-muted/40 shrink-0","aria-hidden":"true"}),o?e.jsx(Pn,{size:14,className:"text-dark-muted"}):e.jsx(ge,{size:14,className:"text-dark-muted"})]})]}),D&&e.jsx("div",{ref:b,className:"border-t border-dark-border",style:z!==null?{height:z,overflow:"hidden"}:void 0,children:i.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:l("chat.noTasks")}):e.jsxs("div",{className:"px-2.5 py-2 max-h-[240px] overflow-y-auto custom-scrollbar space-y-1.5",children:[N.map(M=>e.jsx(Ya,{task:M,isSelected:M.id===c,onClick:()=>d(c===M.id?null:M.id)},M.id)),j.pending.length>5&&e.jsxs("div",{className:"text-[10px] text-dark-muted text-center",children:[j.pending.length-5," more pending tasks"]}),j.completed.length>3&&e.jsxs("div",{className:"text-[10px] text-dark-muted text-center",children:[j.completed.length-3," more completed tasks"]})]})})]})}),Xa=(r,t)=>{if(!r)return"";const s=(t||Date.now())-r;return s<1e3?`${s}ms`:`${(s/1e3).toFixed(1)}s`},Ya=a.memo(function({task:t,isSelected:s,onClick:n}){const l=Za[t.status];return e.jsxs("div",{onClick:n,className:`rounded border p-2 cursor-pointer transition-all ${l.bg} border-dark-border
36
- ${s?"ring-1 ring-accent-blue":"hover:border-dark-muted/40"}
37
- ${t.status==="running"?"border-l-2 border-l-accent-blue":"border-l-2 border-l-transparent"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Va,{status:t.status}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-dark-text truncate",children:t.title}),e.jsx("span",{className:`text-[10px] ${l.color} shrink-0`,children:l.label})]}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-dark-muted",children:[e.jsx("span",{children:t.agentType||t.source}),t.startedAt&&e.jsx("span",{children:Xa(t.startedAt,t.completedAt)})]})]})]}),t.status==="running"&&t.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:`${t.progress}%`}})})}),s&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-dark-border space-y-1",children:[t.description&&e.jsx("p",{className:"text-[10px] text-dark-muted",children:t.description}),t.error&&e.jsx("p",{className:"text-[10px] text-red-400",children:t.error}),t.result&&e.jsx("p",{className:"text-[10px] text-green-400",children:t.result}),t.dependencies&&t.dependencies.length>0&&e.jsxs("p",{className:"text-[10px] text-dark-muted",children:[t.dependencies.length," dependencies"]})]})]})}),ll=a.memo(function({tabs:t,activeSessionId:s,onSend:n,onStop:l,onPause:o,onResume:u,activeTab:c,setActiveTab:d,createNewSession:i,clearMessages:x,setTheme:h,setThemePreset:g,toggleTerminal:k,setLogs:b,setUnreadLogs:w,showTaskBoard:y=!0,onToggleTaskBoard:p,onRegenerate:C,onDeleteMessage:F,hookDrawerOpen:E,onCloseHookDrawer:z,questionDrawerOpen:L,onCloseQuestionDrawer:j,workspaceDir:N,onWorkspaceSelect:D}){const M=a.useMemo(()=>({setActiveTab:d,createNewSession:i,clearMessages:x,setTheme:h,setThemePreset:g,toggleTerminal:k,setLogs:b,setUnreadLogs:w}),[d,i,x,h,g,k,b,w]),R=be(O=>s?O.messagesBySession[s]||[]:[]),W=be(O=>s?O.generatingSessions.includes(s):!1),K=be(O=>s?O.pausedSessions.includes(s):!1),Z=t.find(O=>O.id===s)||null;a.useEffect(()=>{if(!s)return;let O=!1;return ue.tasks.list(s).then(Q=>{if(O||!Q.success||!Array.isArray(Q.data))return;const te={PENDING:"pending",RUNNING:"running",COMPLETED:"completed",FAILED:"failed",CANCELLED:"skipped"},re=Date.now(),me=Q.data.filter(ee=>ee.sessionId===s).map(ee=>{const fe=new Date(ee.createdAt).getTime()||re,ae=new Date(ee.updatedAt).getTime()||re;return{id:ee.id,sessionId:s,title:ee.title,status:te[ee.status]||"pending",source:"task",description:ee.description,progress:ee.progress,createdAt:fe,updatedAt:ae,raw:ee}});js.getState().setTasks(s,me,"task")}).catch(()=>{}),()=>{O=!0}},[s]);const V=a.useCallback((O,Q)=>{s&&n(s,O,Q)},[n,s]),he=a.useCallback(O=>{s&&n(s,O)},[n,s]),S=a.useCallback(O=>{s&&C&&C(s,O)},[C,s]),U=a.useCallback(O=>{s&&F&&F(s,O)},[F,s]);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(Ga,{}),Z&&e.jsxs(e.Fragment,{children:[e.jsx(ia,{messages:R,isGenerating:W,isPaused:K,sessionId:Z.id,onSendSuggestion:he,onRegenerate:C?S:void 0,onDeleteMessage:F?U:void 0}),e.jsx(Ka,{isOpen:!!E,onCloseModal:z}),e.jsx(Wa,{isOpen:!!L,onClose:j??(()=>{})}),y&&e.jsx(Qa,{sessionId:Z.id,defaultExpanded:!1,onClose:p},Z.id),e.jsx(Ha,{sessionId:Z.id,onSend:V,onStop:()=>l(Z.id),onPause:()=>o(Z.id),onResume:()=>u(Z.id),slashOptions:M,workspaceDir:N,onWorkspaceSelect:D})]})]})})});export{ll as SessionGrid};