@deepseekcode/cli 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1095 -1074
- package/package.json +2 -2
- package/web/dist/assets/{AutomationView-BbLzZ7Db.js → AutomationView-MOGwMs0s.js} +1 -1
- package/web/dist/assets/{ChannelConfigView-CjcMwBSL.js → ChannelConfigView-CHWC4ETy.js} +1 -1
- package/web/dist/assets/{ConnectorsView-CTFoG0sF.js → ConnectorsView-DaP_wB0W.js} +1 -1
- package/web/dist/assets/{FileTreeView-_N5eobgO.js → FileTreeView-N64-Dser.js} +1 -1
- package/web/dist/assets/{HookConfigView-DM6IVFGm.js → HookConfigView-DsZDeVFi.js} +1 -1
- package/web/dist/assets/ModelsView-C1cE2wMN.js +2 -0
- package/web/dist/assets/PluginsView-CsSjjfrn.js +1 -0
- package/web/dist/assets/SessionGrid-Bg-UTI2P.js +37 -0
- package/web/dist/assets/{SettingsPanel-D9kr-sFj.js → SettingsPanel-pZbjabYJ.js} +3 -3
- package/web/dist/assets/{SkillsView-CS0XvZ4N.js → SkillsView-BrQY_vgT.js} +1 -1
- package/web/dist/assets/{TemplatesTab-Pwfjxer7.js → TemplatesTab-DSfCryw2.js} +1 -1
- package/web/dist/assets/{TerminalView-C__4-QSL.js → TerminalView-Drr72DaP.js} +1 -1
- package/web/dist/assets/{ToolsView-Y5MpTnXY.js → ToolsView-ByqbKwqW.js} +1 -1
- package/web/dist/assets/{icons-BXecaLRH.js → icons-B9mi2ie6.js} +114 -104
- package/web/dist/assets/index-DCj9TkXV.css +1 -0
- package/web/dist/assets/index-PcXINYWS.js +68 -0
- package/web/dist/assets/{markdown-BASfeONY.js → markdown-BrFQfawv.js} +1 -1
- package/web/dist/assets/{panels-Bod3sKnK.js → panels-BX-TtLOU.js} +1 -1
- package/web/dist/assets/{react-vendor-7At16BnY.js → react-vendor-CiRFOYk_.js} +1 -1
- package/web/dist/assets/{state-D4zgKwQs.js → state-BcoCffxz.js} +1 -1
- package/web/dist/index.html +7 -7
- package/web/dist/assets/ModelsView-CPm2WAbG.js +0 -2
- package/web/dist/assets/PluginsView-D9pzIe-R.js +0 -1
- package/web/dist/assets/SessionGrid-C-Z-kzmG.js +0 -35
- package/web/dist/assets/index-CFxV9r1K.css +0 -1
- package/web/dist/assets/index-CcPIw0Dj.js +0 -68
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import{j as e}from"./markdown-BrFQfawv.js";import{a as o,Z as ds,ak as ze,d as fe,K as ke,aA as Ie,X as Ce,aQ as pt,E as us,_ as Se,l as mt,L as Te,u as yt,F as ht,aR as ft,aH as rn,D as an,k as on,aS as xs,aw as ln,aT as $t,aU as cn,h as $e,al as dn,i as ps,aV as un,aW as xn,aX as pn,b as mn,aq as hn,aY as fn,aG as bn,aa as wt,a0 as ms,aZ as gn,$ as Dt,B as kn,ap as yn,a_ as wn,n as hs,aN as vt,aM as vn,a5 as fs,ab as jn,a$ as Nn,b0 as Sn,ag as Cn,b1 as En,f as _n,S as An,t as Mn,b2 as Re,y as Rn,b3 as zn,m as In,b4 as Tn,a1 as $n,p as Dn,q as Pn,j as Ln}from"./icons-B9mi2ie6.js";import{D as Bn,d as ae,h as Pt,c as V,i as On,j as bs,o as gs,k as qe,l as ks,w as se,m as bt,u as Ne,R as ys,a as ue,t as le,n as Fn,s as qn,r as Hn,f as Ve,p as he,q as Un,v as Jn,W as Wn,x as Gn,y as gt,b as Ke,z as Oe,E as Kn,M as Zn,A as Vn,F as Xn,G as ws,H as Qn,J as Yn,K as er,L as Je,N as tr,O as vs}from"./index-PcXINYWS.js";import"./react-vendor-CiRFOYk_.js";import"./state-BcoCffxz.js";import"./panels-BX-TtLOU.js";class sr extends Bn{tokenize(t){return t.slice()}join(t){return t}removeEmpty(t){return t}}const nr=new sr;function rr(r,t,s){return nr.diff(r,t,s)}function Lt({value:r,max:t=100,size:s="md",variant:n="default",showLabel:a=!1,className:i}){const c=Math.min(Math.max(r/t*100,0),100),d={sm:"h-1",md:"h-2",lg:"h-3"},u={default:"bg-accent-blue",success:"bg-accent-green",warning:"bg-accent-yellow",error:"bg-accent-red"};return e.jsxs("div",{className:ae("w-full",i),children:[e.jsx("div",{className:ae("w-full bg-dark-border rounded-full overflow-hidden",d[s]),children:e.jsx("div",{className:ae("h-full rounded-full transition-all duration-300",u[n]),style:{width:`${c}%`}})}),a&&e.jsxs("span",{className:"text-xs text-dark-muted mt-1",children:[Math.round(c),"%"]})]})}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(/&/,"&"))});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 a={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:n}};a["language-"+s]={pattern:/[\s\S]+/,inside:Prism.languages[s]};var i={};i[t]={pattern:RegExp(/(<__[^>]*>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g,function(){return t}),"i"),lookbehind:!0,greedy:!0,inside:a},Prism.languages.insertBefore("markup","cdata",i)}});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={},Ot;function ar(){return Ot||(Ot=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}ar();var Ft={},qt;function or(){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)),Ft}or();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={},Ut;function lr(){return Ut||(Ut=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}lr();(function(r){function t(s,n){return"___"+s.toUpperCase()+n+"___"}Object.defineProperties(r.languages["markup-templating"]={},{buildPlaceholders:{value:function(s,n,a,i){if(s.language===n){var c=s.tokenStack=[];s.code=s.code.replace(a,function(d){if(typeof i=="function"&&!i(d))return d;for(var u=c.length,l;s.code.indexOf(l=t(n,u))!==-1;)++u;return c[u]=d,l}),s.grammar=r.languages.markup}}},tokenizePlaceholders:{value:function(s,n){if(s.language!==n||!s.tokenStack)return;s.grammar=r.languages[n];var a=0,i=Object.keys(s.tokenStack);function c(d){for(var u=0;u<d.length&&!(a>=i.length);u++){var l=d[u];if(typeof l=="string"||l.content&&typeof l.content=="string"){var x=i[a],f=s.tokenStack[x],h=typeof l=="string"?l:l.content,g=t(n,x),N=h.indexOf(g);if(N>-1){++a;var w=h.substring(0,N),y=new r.Token(n,r.tokenize(f,s.grammar),"language-"+n,f),p=h.substring(N+g.length),S=[];w&&S.push.apply(S,c([w])),S.push(y),p&&S.push.apply(S,c([p])),typeof l=="string"?d.splice.apply(d,[u,1].concat(S)):l.content=S}}else l.content&&c(l.content)}return d}c(s.tokens)}}})})(Prism);var Jt={},Wt;function ir(){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,a=/<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/,i=/[{}\[\](),:;]/;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:a,punctuation:i};var c={pattern:/\{\$(?:\{(?:\{[^{}]+\}|[^{}]+)\}|[^{}])+\}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)?)/,lookbehind:!0,inside:r.languages.php},d=[{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:c}},{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:c}}];r.languages.insertBefore("php","variable",{string:d,attribute:{pattern:/#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,greedy:!0,inside:{"attribute-content":{pattern:/^(#\[)[\s\S]+(?=\]$)/,lookbehind:!0,inside:{comment:t,string:d,"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:a,punctuation:i}},delimiter:{pattern:/^#\[|\]$/,alias:"punctuation"}}}}),r.hooks.add("before-tokenize",function(u){if(/<\?/.test(u.code)){var l=/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/g;r.languages["markup-templating"].buildPlaceholders(u,"php",l)}}),r.hooks.add("after-tokenize",function(u){r.languages["markup-templating"].tokenizePlaceholders(u,"php")})})(Prism)),Jt}ir();var Gt={},Kt;function cr(){return Kt||(Kt=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)),Gt}cr();const dr=.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 a=s+1;for(;a<r.length&&/[\p{L}\p{N}_]/u.test(r[a]);)a++;t.push(r.slice(s,a)),s=a}else if(/\s/.test(n)){let a=s+1;for(;a<r.length&&/\s/.test(r[a]);)a++;t.push(r.slice(s,a)),s=a}else{const i=r.codePointAt(s)>65535?2:1;t.push(r.slice(s,s+i)),s+=i}}return t}function ur(r,t){const s=rr(Zt(r),Zt(t)),n=r.length+t.length;let a=0;const i=[],c=[];let d=0,u=0;for(const l of s){const x=l.value.reduce((f,h)=>f+h.length,0);l.removed?(a+=x,i.push({start:d,end:d+x}),d+=x):l.added?(a+=x,c.push({start:u,end:u+x}),u+=x):(d+=x,u+=x)}return n>0&&a/n>dr?[[],[]]:[i,c]}function js(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 a=n.match(/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);if(a){s&&t.push(s),s={oldStart:parseInt(a[1],10),oldLines:parseInt(a[2]??"1",10),newStart:parseInt(a[3],10),newLines:parseInt(a[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 Ns(r){let t=r.oldStart,s=r.newStart;const n=[];for(const a of r.lines){const i=a[0]==="+"||a[0]==="-"?a[0]:" ",c=a.slice(1);let d=null,u=null;i==="-"?d=t++:(i==="+"||(d=t++),u=s++),n.push({marker:i,code:c,oldLine:d,newLine:u})}return n}const xr=o.memo(function({filePath:t,content:s,language:n}){if(!s&&!t)return null;const[a,i]=o.useState("unified"),[c,d]=o.useState(!1),u=pr(t,n),l=(s==null?void 0:s.includes("@@"))||(s==null?void 0:s.includes("+++"))||(s==null?void 0:s.includes("---")),x=l?mr(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:u}),l&&e.jsxs("div",{className:"flex gap-0.5 ml-2",children:[e.jsx("button",{onClick:()=>i("unified"),className:`text-xs px-1.5 py-0.5 rounded ${a==="unified"?"bg-accent-blue/20 text-accent-blue":"text-dark-muted hover:text-dark-fg"}`,title:"Unified view",children:"Unified"}),e.jsx("button",{onClick:()=>i("side-by-side"),className:`text-xs px-1.5 py-0.5 rounded ${a==="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:()=>d(!c),className:"text-xs text-dark-muted hover:text-dark-fg ml-1",children:c?"▶":"▼"})]}),!c&&e.jsxs("div",{className:"bg-dark-bg overflow-x-auto max-h-96 overflow-y-auto custom-scrollbar",children:[l?a==="unified"?gr(s||"",u):kr(s||"",u):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 pr(r,t){var a;if(t)return t;if(!r)return"plaintext";const s=(a=r.split(".").pop())==null?void 0:a.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 mr(r){const t=r.split(`
|
|
3
|
+
`);let s=0,n=0,a=0;for(const i of t)i.startsWith("@@")?a++:i.startsWith("+")&&!i.startsWith("+++")?s++:i.startsWith("-")&&!i.startsWith("---")&&n++;return{additions:s,deletions:n,hunks:a,filesChanged:1}}function hr(r){const t=[],s=(a,i)=>{if(!i)return;const c=t[t.length-1];c&&c.type===a?c.text+=i:t.push({type:a,text:i})},n=(a,i)=>{if(typeof a=="string"){s(i,a);return}const c=a.type||i;if(typeof a.content=="string"){s(c,a.content);return}for(const d of a.content)n(d,c)};for(const a of r)n(a,"");return t}function Ss(r,t){const s=Pt.languages[t];if(!s)return[{type:"",text:r}];try{return hr(Pt.tokenize(r,s))}catch{return[{type:"",text:r}]}}function fr(r,t){if(t.length===0)return r.map(a=>({...a,word:!1}));const s=[];let n=0;for(const a of r){const i=n,c=n+a.text.length;let d=0;for(const u of t){const l=Math.max(0,u.start-i),x=Math.min(a.text.length,u.end-i);x<=0||l>=a.text.length||(l>d&&s.push({type:a.type,text:a.text.slice(d,l),word:!1}),s.push({type:a.type,text:a.text.slice(l,x),word:!0}),d=x)}d<a.text.length&&s.push({type:a.type,text:a.text.slice(d),word:!1}),n=c}return s}function br({code:r,marker:t,lang:s,ranges:n}){const a=t==="-"?[{type:"",text:r}]:Ss(r,s),i=fr(a,n),c=t==="+"?"bg-green-900/30":t==="-"?"bg-red-900/30":"",d=t==="+"?"bg-green-700/60":"bg-red-700/60";return e.jsx("span",{className:`flex-1 whitespace-pre-wrap px-2 ${c}`,children:i.length===0?" ":i.map((u,l)=>e.jsx("span",{className:[u.type?`token ${u.type}`:"",u.word&&t!==" "?d:""].join(" "),children:u.text},l))})}function gr(r,t){const s=js(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 a=0;for(const i of s){const c=Ns(i);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:["@@ -",i.oldStart,",",i.oldLines," +",i.newStart,",",i.newLines," @@"]})]},a++));const d=new Map;for(let u=0;u<c.length;){if(c[u].marker!=="-"){u++;continue}const l=u;for(;u<c.length&&c[u].marker==="-";)u++;const x=u;for(;u<c.length&&c[u].marker==="+";)u++;const f=Math.min(x-l,u-x);for(let h=0;h<f;h++){const[g,N]=ur(c[l+h].code,c[x+h].code);d.set(l+h,g),d.set(x+h,N)}}for(let u=0;u<c.length;u++){const l=c[u],x=l.marker==="+",f=l.marker==="-",h=x?"bg-green-900/30":f?"bg-red-900/30":"",g=l.marker==="-"?l.oldLine:l.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 ${h} ${x?"text-green-400":f?"text-red-400":"text-dark-muted"}`,children:[l.marker===" "?"":l.marker,g??""]}),e.jsx(br,{code:l.code,marker:l.marker,lang:t,ranges:d.get(u)??[]})]},a++))}}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}]:Ss(r,t),a=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 ${a}`,children:n.map((i,c)=>e.jsx("span",{className:i.type?`token ${i.type}`:"",children:i.text},c))})}function kr(r,t){const s=js(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 a of s){const i=Ns(a);n.push({left:`@@ -${a.oldStart},${a.oldLines} +${a.newStart},${a.newLines} @@`,right:"",type:"header"});let c=[],d=[];const u=()=>{(c.length>0||d.length>0)&&(yr(n,c,d),c=[],d=[])};for(const l of i)l.marker==="-"?c.push(l.code):l.marker==="+"?d.push(l.code):(u(),n.push({left:l.code,right:l.code,type:"context"}));u()}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((a,i)=>a.type==="header"?e.jsx("div",{className:"bg-accent-blue/5 text-accent-blue font-bold font-mono text-xs leading-snug px-2",children:a.left},i):e.jsxs("div",{className:"flex",style:{minHeight:"1.25rem"},children:[e.jsx(Vt,{code:a.type==="replace"||a.type==="delete"?"- "+a.left:a.left,lang:t,kind:a.type==="replace"||a.type==="delete"?"remove":"context"}),e.jsx(Vt,{code:a.type==="replace"||a.type==="add"?"+ "+a.right:a.right,lang:t,kind:a.type==="replace"||a.type==="add"?"add":"context"})]},i))]})}function yr(r,t,s){const n=Math.max(t.length,s.length);for(let a=0;a<n;a++){const i=a<t.length?t[a]??"":"",c=a<s.length?s[a]??"":"";r.push({left:i,right:c,type:a<t.length&&a<s.length?"replace":a<t.length?"delete":"add"})}}function Cs(r){const t=o.useRef(null),s=o.useRef(0);return o.useEffect(()=>{if(!r){s.current=0;return}s.current=Date.now();const n=t.current;if(!n)return;const a=()=>{const c=Math.floor((Date.now()-s.current)/1e3),d=c>=60?`${Math.floor(c/60)}m ${c%60}s`:`${c}s`;n.textContent=d};a();const i=setInterval(a,1e3);return()=>clearInterval(i)},[r]),t}function wr(r){return typeof r=="string"?r:r&&typeof r=="object"?JSON.stringify(r,null,2):String(r??"")}const Xt=20,vr=/\b(grep|search_contents)\b/i;function jr(r){return r===""?0:r.split(`
|
|
4
|
+
`).length}const Qt=o.memo(function({toolCall:t,defaultCollapsed:s=!0}){const{t:n}=V(),a=t.status==="running",i=Cs(a),c=t.result!==void 0&&t.result!==null,d=t.status==="error",u=On(t.name),l=c?wr(t.result):"",x=c?jr(l):0,f=vr.test(t.name),h=t.noTruncate!==!0&&f&&c&&!d&&x>Xt,[g,N]=o.useState(!1),w=h&&!g?l.split(`
|
|
5
|
+
`).slice(0,Xt).join(`
|
|
6
|
+
`)+`
|
|
7
|
+
${n("toolCall.linesTotal",{n:x})}`:l,y=t.diff||(u&&l&&(l.includes("@@")||l.includes("+++")||l.includes("---"))?l:void 0),p=bs(t.args),[S,$]=o.useState(s),_=t.duration??0,A=_>0?_>=60?`${Math.floor(_/60)}m ${_%60}s`:`${_}s`:"",R=a?"bg-accent-blue":d?"bg-accent-red":"bg-accent-green";return e.jsxs("div",{className:"rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"toolcall-row",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 cursor-pointer select-none",onClick:()=>$(!S),children:[a?e.jsx("span",{className:"inline-block w-3 h-3 shrink-0 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:`w-2 h-2 shrink-0 rounded-full ${R}`}),e.jsx("span",{className:"text-xs text-dark-muted shrink-0",children:"🔧"}),e.jsx("span",{className:"font-medium text-[13px] text-dark-text truncate",children:t.name}),u&&p&&!d&&e.jsxs("button",{type:"button",onClick:v=>{v.stopPropagation(),gs(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(ds,{size:10,className:"shrink-0"}),e.jsx("span",{className:"truncate",children:p})]}),a&&e.jsxs("span",{className:"text-[11px] text-accent-blue shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(ze,{size:10}),e.jsx("span",{ref:i,children:"0s"})]}),!a&&A&&e.jsxs("span",{className:"text-[10px] text-dark-muted shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(ze,{size:10}),e.jsx("span",{children:A})]}),e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${S?"":"rotate-180"}`,children:e.jsx(fe,{size:13})})]}),!S&&e.jsxs("div",{className:"ml-4 pb-1 pl-3 border-l-2 border-dark-border/30 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)})]}),c&&e.jsxs("div",{className:"py-0.5 px-2",children:[e.jsx("div",{className:`text-[10px] mb-0.5 ${d?"text-accent-red":"text-accent-green"}`,children:n(d?"step.error":"step.result")}),u&&(y||l)?e.jsx(xr,{filePath:p,content:y||l}):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 ${d?"text-accent-red":"text-accent-green"}`,children:w}),h&&e.jsx("button",{type:"button","data-testid":"grep-result-toggle",onClick:()=>N(v=>!v),className:"mt-1 text-[10px] text-accent-blue hover:underline",children:g?n("toolCall.collapse"):n("toolCall.expandAll",{n:x})})]})]})]})]})}),jt=o.memo(function({toolCalls:t,label:s,defaultCollapsed:n=!0}){const{t:a}=V(),[i,c]=o.useState(n),d=o.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]),u=o.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(Qt,{toolCall:w})}const x=d.slice(0,3),f=d.length-x.length,h=t.reduce((w,y)=>w+(y.duration??0),0),g=h>=60?`${Math.floor(h/60)}m ${h%60}s`:h>=1?`${h}s`:"",N=u==="running"?"bg-accent-blue":u==="error"?"bg-accent-red":"bg-accent-green";return e.jsxs("div",{className:"rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"toolcall-group",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 cursor-pointer select-none",onClick:()=>c(!i),"data-testid":"toolcall-group-toggle",children:[u==="running"?e.jsx("span",{className:"inline-block w-3 h-3 shrink-0 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:`w-2 h-2 shrink-0 rounded-full ${N}`}),e.jsx("span",{className:"text-xs text-dark-muted shrink-0",children:"🔧"}),e.jsx("span",{className:"font-medium text-[13px] text-dark-text shrink-0","data-testid":"toolcall-group-count",children:a("activity.toolCallCount",{count:t.length})}),x.map(([w,y])=>e.jsxs("span",{className:"shrink-0 rounded border border-dark-border/70 px-1.5 py-px text-[10.5px] font-mono text-dark-muted",children:[w," ×",y]},w)),f>0&&e.jsx("span",{className:"shrink-0 text-[10.5px] text-dark-muted",children:a("activity.toolNamesMore",{count:f})}),g&&e.jsx("span",{className:"shrink-0 text-[10px] text-dark-muted tabular-nums",children:g}),e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${i?"":"rotate-180"}`,children:e.jsx(fe,{size:13})})]}),!i&&e.jsxs("div",{className:"ml-4 pb-1 pl-3 border-l-2 border-dark-border/30 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??a("activity.evidence")}),t.map(w=>e.jsx(Qt,{toolCall:w},w.id))]})]})}),Nr=o.memo(function({text:t,maxLength:s=300,preformatted:n=!1}){const[a,i]=o.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:a?t:t.slice(0,s)+"..."}):e.jsx("div",{className:"text-dark-text leading-snug",children:a?t:t.slice(0,s)+"..."}),e.jsx("button",{onClick:d=>{d.stopPropagation(),i(!a)},className:"mt-1 text-[10px] px-2 py-0.5 rounded bg-dark-hover text-accent-blue hover:bg-dark-border transition-colors",children:a?"收起":"展开"})]}):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})}),Sr=o.memo(function({step:t,defaultCollapsed:s=!0}){const{t:n}=V(),[a,i]=o.useState(s),[c,d]=o.useState(!0),u=t.status==="running",l=Cs(u),x=t.description||t.thought||t.result||t.action||t.toolCalls&&t.toolCalls.length>0,f=t.duration??0,h=f>0?f>=60?`${Math.floor(f/60)}m ${f%60}s`:`${f}s`:"",g={pending:"bg-dark-muted/40",running:"bg-accent-blue",success:"bg-accent-green",error:"bg-accent-red",warning:"bg-accent-yellow"}[t.status]||"bg-dark-muted/40";return e.jsxs("div",{className:"rounded-lg transition-colors hover:bg-dark-surface/40","data-testid":"step-row",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 cursor-pointer select-none",onClick:()=>x&&i(!a),children:[u?e.jsx("span",{className:"inline-block w-3 h-3 shrink-0 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:`w-2 h-2 shrink-0 rounded-full ${g} ${t.status==="pending"?"opacity-60":""}`}),e.jsx("span",{className:"text-[13px] text-dark-text truncate",children:t.title}),u&&e.jsxs("span",{className:"text-[11px] text-accent-blue shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(ze,{size:10}),e.jsx("span",{ref:l,children:"0s"})]}),!u&&h&&e.jsxs("span",{className:"text-[10px] text-dark-muted shrink-0 flex items-center gap-1 tabular-nums",children:[e.jsx(ze,{size:10}),e.jsx("span",{children:h})]}),x&&e.jsx("span",{className:`ml-auto shrink-0 text-dark-muted/60 transition-transform ${a?"":"rotate-180"}`,children:e.jsx(fe,{size:13})})]}),!a&&x&&e.jsxs("div",{className:"ml-4 pb-1 pl-3 border-l-2 border-dark-border/30 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-blue/40 bg-accent-blue/5 rounded-r",children:[e.jsxs("div",{className:"flex items-center gap-1 text-accent-blue cursor-pointer hover:opacity-80 select-none",onClick:()=>d(!c),children:[c?e.jsx(ke,{size:12}):e.jsx(fe,{size:12}),e.jsxs("span",{children:["🧠 ",n("step.thinking")]}),c&&e.jsxs("span",{className:"text-[10px] text-dark-muted truncate max-w-[200px]",children:[t.thought.slice(0,80).replace(/\n/g," "),"..."]})]}),!c&&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:["⚡ ",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(jt,{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:["✓ ",n("step.result")]}),e.jsx(Nr,{text:t.result,maxLength:500})]})]})]})}),Cr=o.memo(function({steps:t,isGenerating:s}){const{t:n}=V(),[a,i]=o.useState(s),c=o.useRef(s);o.useEffect(()=>{c.current&&!s&&i(!1),c.current=s},[s]);const d=t.length,u=s||t.some(g=>g.status==="running"),l=[...t].reverse().find(g=>g.status==="running"),x=t[t.length-1],f=(l==null?void 0:l.title)||(x==null?void 0:x.title)||"",h=`${d} ${n(d===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:()=>i(!a),"data-testid":"turn-group-toggle",children:[e.jsx("span",{className:"shrink-0 text-dark-muted/60 transition-transform",children:a?e.jsx(fe,{size:13}):e.jsx(ke,{size:13})}),u?e.jsx("span",{className:"inline-block w-3 h-3 shrink-0 rounded-full border-2 border-accent-blue border-r-transparent animate-spin"}):e.jsx("span",{className:"w-2 h-2 shrink-0 rounded-full bg-accent-green"}),e.jsx("span",{className:"text-xs text-dark-muted",children:u?`${n("chat.runningSteps")} ${h}…`:h}),u&&f&&e.jsxs("span",{className:"min-w-0 flex-1 truncate pl-1 text-xs text-dark-muted/70",children:["· ",f]})]}),a&&e.jsx("div",{className:"ml-3 pb-1 pl-3 border-l-2 border-dark-border/30 space-y-0.5",children:t.map(g=>e.jsx(Sr,{step:g},g.id))})]})});function Es(r){const t=r??"";let s=t,n=null,a=null;try{const i=JSON.parse(t);if(i&&typeof i=="object")if("payload"in i){a=typeof i.toolName=="string"?i.toolName:null;const c=i.payload;typeof c=="string"?s=c:c&&typeof c=="object"?(n=c,s=JSON.stringify(c,null,2)):s=""}else Array.isArray(i)||(n=i)}catch{s=t}if(!n&&s.length>0&&/^[\s]*[{[]/.test(s))try{const i=JSON.parse(s);i&&typeof i=="object"&&!Array.isArray(i)&&(n=i)}catch{}return{toolName:a,payloadText:s,args:n}}const Nt=/\b(bash|shell|exec|cmd|powershell|terminal)\b/i,_s=/write_file|write|save|create|upload|deploy|publish/i,As=/edit_file|edit|patch|apply|update|replace/i,Ms=/read_file|read|view|cat|open|list|dir\b/i,Er=/file_delete|delete|remove|unlink|\brm\b|\bdel\b/i,_r=/\b(glob|find|locate)\b/i,Ar=/\b(grep|rg|search_contents)\b/i,Mr=/web_search|search_web|browse/i,Rs=/web_fetch|fetch|http|curl|wget|download|request|api/i,Rr=/git|commit|merge|rebase|push|checkout/i,zr=/install|uninstall|npm|pnpm|yarn|pip|cargo|gem|apt|brew|choco/i,St=/send_message|send_file|message|notify|post/i;function zs(r){const t=r.toLowerCase();return Nt.test(t)?"verbRunCommand":Mr.test(t)?"verbSearchWeb":_s.test(t)?"verbWriteFile":As.test(t)?"verbEditFile":Er.test(t)?"verbDeleteFile":Ms.test(t)?"verbReadFile":Ar.test(t)?"verbSearchContents":_r.test(t)?"verbFindFiles":Rs.test(t)?"verbFetchUrl":Rr.test(t)?"verbGit":zr.test(t)?"verbInstall":St.test(t)?"verbSendMessage":"verbRunTool"}function st(r,t){const s=(r??"").replace(/\s+/g," ").trim();return s.length>t?`${s.slice(0,t-1)}…`:s}function Ir(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 Is(r,t){const{payloadText:s,args:n}=Es(t),a=r.toLowerCase();if(Nt.test(a))return"";const i=Ir(n);if(i)return i;const c=s.match(/(?:file_path|path|file)["\s:=]+([^\s",}]+)/i);if(c!=null&&c[1])return c[1];if(Rs.test(a)&&typeof(n==null?void 0:n.url)=="string"&&n.url)return st(n.url,48);if(St.test(a)){const d=typeof(n==null?void 0:n.text)=="string"?n.text:typeof(n==null?void 0:n.message)=="string"?n.message:s;return st(d,48)}return st(s,48)}function Ts(r,t){const{payloadText:s,args:n}=Es(t),a=r.toLowerCase();if(Nt.test(a)){const i=typeof(n==null?void 0:n.command)=="string"?n.command:s;return i?{text:i,mono:!0}:null}if(_s.test(a)||As.test(a)){const i=typeof(n==null?void 0:n.content)=="string"?n.content:typeof(n==null?void 0:n.data)=="string"?n.data:"";if(i)return{text:i,mono:!0};if(n){const c=Yt(n);if(c)return{text:c,mono:!0}}return s?{text:s,mono:!0}:null}if(St.test(a)){const i=typeof(n==null?void 0:n.text)=="string"?n.text:typeof(n==null?void 0:n.message)=="string"?n.message:s;return i?{text:i,mono:!1}:null}if(Ms.test(a))return null;if(n){const i=Yt(n);if(i)return{text:i,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 $s(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 nt=5,rt=420;function kt({text:r,mono:t=!0}){const{t:s}=V("hook"),[n,a]=o.useState(!1),i=r.split(`
|
|
10
|
+
`),c=i.length>nt||r.length>rt;let d=r;!n&&c&&(d=i.slice(0,nt).join(`
|
|
11
|
+
`),d.length>rt&&(d=`${d.slice(0,rt).trimEnd()}…`));const u=n?s("showLess"):i.length>nt?s("showAllLines",{n:i.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:[d,c&&e.jsx("button",{type:"button",onClick:()=>a(l=>!l),className:"mt-1 block text-[11px] text-accent-blue hover:underline",children:u})]})}const at=15,Tr=o.memo(function({approval:t,onResolved:s}){const{t:n}=V("hook"),[a,i]=o.useState(!1),[c,d]=o.useState(at),u=o.useRef(null),l=t.status==="pending",{level:x,reasonKey:f}=ks(t.toolName,t.askPayload),h=ys[x],g=Ts(t.toolName,t.askPayload),N=$s(t.toolName,t.askPayload),w=qe(t.askPayload)!==null;o.useEffect(()=>{if(l)return d(at),u.current=setInterval(()=>{d(j=>j<=1?(u.current&&clearInterval(u.current),0):j-1)},1e3),()=>{u.current&&clearInterval(u.current)}},[l,t.approvalId]),o.useEffect(()=>{const j=(t.timeoutMs??15e3)>0;c===0&&l&&!a&&j&&y()},[c]);const y=o.useCallback(()=>{!l||a||(i(!0),u.current&&clearInterval(u.current),se.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),s==null||s(t.approvalId,"approved"))},[l,a,t.approvalId,s]),p=o.useCallback(()=>{!l||a||(i(!0),u.current&&clearInterval(u.current),se.send({type:"hook_deny",data:JSON.stringify({approvalId:t.approvalId})}),s==null||s(t.approvalId,"denied"))},[l,a,t.approvalId,s]),S=o.useCallback(()=>{if(!l||a)return;i(!0),u.current&&clearInterval(u.current);const j=bt.getState(),O=qe(t.askPayload);O?(j.addToSessionAllowList(t.toolName,O),se.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId,sessionAllow:!0})})):(j.addToSessionAllowList(t.toolName),se.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})})),s==null||s(t.approvalId,"approved")},[l,a,t.approvalId,t.toolName,t.askPayload,s]),$=o.useCallback(()=>{!l||a||(i(!0),u.current&&clearInterval(u.current),bt.getState().setAutoMode(!0),Ne.getState().setAuto(!0),se.send({type:"hook_allow",data:JSON.stringify({approvalId:t.approvalId})}),s==null||s(t.approvalId,"approved"))},[l,a,t.approvalId,s]);if(!l){const j=t.status==="approved";return e.jsx("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${j?"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:j?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{size:14}),e.jsxs("span",{children:[n("alreadyAllowed"),t.toolName]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ce,{size:14}),e.jsxs("span",{children:[n("alreadyDenied"),t.toolName]})]})})}const _=c/at*100,A=c<=5,R=[{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:S,kind:"secondary"},{id:"auto_mode",index:4,label:n("optionAutoMode"),hint:n("optionAutoModeHint"),action:$,kind:"secondary"},{id:"deny",index:2,label:n("optionDeny"),hint:n("optionDenyHint"),action:p,kind:"danger"}],v={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 ${N.external?"border-amber-500/40":h.border}`,children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 border-b ${h.bg} ${N.external?"border-amber-500/30":h.border}`,children:[e.jsxs("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${rc.badge}",children:[h.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(pt,{size:13})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Ds,{pre:n(zs(t.toolName)),obj:Is(t.toolName,t.askPayload)})}),N.external&&N.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:N.path,children:[e.jsx(us,{size:10}),N.path.length>32?`${N.path.slice(0,31)}…`:N.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(ze,{size:11,className:A?"text-accent-red":"text-dark-muted"}),e.jsxs("span",{className:`text-[11px] font-mono ${A?"text-accent-red animate-pulse":"text-dark-muted"}`,children:[c,"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 ${A?"bg-accent-red":c<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${_}%`}})})]})]}),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(f)})]}),g&&e.jsx(kt,{text:g.text,mono:g.mono}),(x==="CRITICAL"||x==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-[11px] px-2 py-1 rounded ${h.bg} ${h.text}`,children:[e.jsx(Se,{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:R.map(j=>e.jsxs("button",{onClick:j.action,disabled:a,className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs transition-colors disabled:opacity-50 ${v[j.kind]}`,children:[e.jsx("span",{className:`text-[9px] font-mono rounded px-0.5 ${j.kind==="primary"?"bg-white/20":"bg-dark-surface text-dark-muted"}`,children:j.index}),e.jsx("span",{children:j.label}),e.jsx("span",{className:`text-[10px] ${j.kind==="primary"?"text-white/70":"text-dark-muted/60"} hidden sm:inline`,children:j.hint})]},j.id))}),e.jsx("div",{className:"text-[10px] text-dark-muted/50 pt-0.5 border-t border-dark-border/50",children:n("clickToSelect")})]})]})}),We={xlsx:{icon:ft,label:"Excel"},xls:{icon:ft,label:"Excel"},csv:{icon:ht,label:"CSV"},docx:{icon:ht,label:"Word"},text:{icon:yt,label:"文本"}};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 $r=o.memo(function({job:t}){var f,h;const{t:s}=V(),{stage:n}=t,a=o.useCallback(g=>{ue.files.download(g).then(N=>{N.success||le.error(N.error||s("fileJob.downloadFailed"))})},[s]),i=o.useMemo(()=>t.attachments||[],[t.attachments]),c=o.useMemo(()=>t.parsedFiles||[],[t.parsedFiles]),d=o.useMemo(()=>t.mapping||[],[t.mapping]),u=o.useMemo(()=>t.result||[],[t.result]),l=t.renderProgress??(n==="rendering"?0:100),x=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(mt,{size:15,className:"text-accent-green shrink-0"}):n==="error"?e.jsx(Se,{size:15,className:"text-accent-red shrink-0"}):e.jsx(Te,{size:15,className:"text-accent-blue animate-spin shrink-0"}),e.jsx("span",{className:"text-[13px] font-medium text-dark-text",children:Dr(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:[i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:i.map((g,N)=>{const w=We[g.kind]||We.text,y=w.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(y,{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:g.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[es(g.size)," · ",w.label,g.role&&g.role!=="unknown"&&e.jsxs("span",{className:ae("ml-1",g.role==="data"?"text-accent-green":"text-accent-purple"),children:["· ",g.role==="data"?s("fileJob.roleData"):s("fileJob.roleTemplate")]})]})]})]},`${g.fileName}-${N}`)})}),n==="parsing"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-dark-muted",children:s("fileJob.parsing",{file:((f=i[0])==null?void 0:f.fileName)||((h=c[0])==null?void 0:h.fileName)||""})}),e.jsx(Lt,{value:x,size:"sm",showLabel:!0})]}),c.length>0&&n!=="error"&&e.jsxs("div",{className:"space-y-1.5",children:[c.map(g=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted",children:[e.jsx(mt,{size:13,className:"text-accent-green shrink-0"}),e.jsx("span",{className:"truncate",children:g.fileName}),e.jsx("span",{className:"text-[10px] text-dark-muted/70",children:s("fileJob.parsedSummary",{rows:g.rowCount,fields:g.fields.length})})]},g.fileName)),c[0]&&e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[c[0].fields.slice(0,12).map(g=>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:g},g)),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(g=>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:"{{"+g.placeholder+"}}"}),e.jsx("td",{className:"px-2 py-1.5 text-dark-muted",children:e.jsx(rn,{size:11})}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-accent-blue",children:g.field})]},g.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:l,size:"sm",variant:"warning",showLabel:!0})]}),u.length>0&&n==="complete"&&e.jsx("div",{className:"space-y-1.5",children:u.map(g=>{const w=(We[g.format]||We.text).icon,y=g.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(w,{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:g.fileName}),e.jsxs("div",{className:"text-[10px] text-dark-muted",children:[es(g.size)," · ",g.successCount,"/",g.rowCount," 行",y&&e.jsxs("span",{className:"text-accent-red",children:[" · ",g.failedRows.length," 行失败"]})]})]}),e.jsxs("button",{onClick:()=>gs(g.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(ds,{size:12}),s("chat.previewInPanel")]}),e.jsxs("button",{onClick:()=>a(g.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(an,{size:12}),s("fileJob.download")]})]}),y&&e.jsxs("div",{className:"mt-1.5 space-y-0.5 border-t border-dark-border/50 pt-1.5",children:[g.failedRows.slice(0,3).map(p=>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:["#",p.index+1]}),e.jsx("span",{className:"truncate",children:p.error})]},p.index)),g.failedRows.length>3&&e.jsxs("div",{className:"text-[10px] text-dark-muted/70",children:["+",g.failedRows.length-3," 行"]})]})]},g.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(Se,{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 Dr(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:cn,color:"text-accent-red"},rate_limit:{icon:$t,color:"text-accent-yellow"},timeout:{icon:$t,color:"text-accent-yellow"},network:{icon:ln,color:"text-accent-yellow"},model:{icon:xs,color:"text-accent-red"},tool:{icon:Se,color:"text-accent-yellow"},unknown:{icon:Se,color:"text-accent-red"}},Pr=o.memo(function({error:t,onRetry:s}){const{t:n}=V(),[a,i]=o.useState(!1),c=ts[t.category]||ts.unknown,d=c.icon,u=()=>{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(d,{size:18,className:ae("shrink-0 mt-0.5",c.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($e,{size:11}),n("errorCard.retry")]}),t.category==="auth"&&e.jsxs("button",{onClick:u,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(dn,{size:11}),n("errorCard.modelSettings")]}),t.detail&&e.jsxs("button",{onClick:()=>i(l=>!l),className:"flex items-center gap-0.5 text-[11px] text-dark-muted hover:text-dark-text transition-colors",children:[e.jsx(fe,{size:11,className:ae("transition-transform",a&&"rotate-180")}),n("errorCard.details")]})]})]})]}),a&&t.detail&&e.jsx("div",{className:"border-t border-dark-border/60 bg-dark-bg px-3.5 py-2.5 text-[11px] font-mono text-dark-muted break-words max-h-40 overflow-y-auto custom-scrollbar",children:t.detail})]})});function Lr(r){const t=r.replace(/\\/g,"/");return t.slice(t.lastIndexOf("/")+1)||r}function Br({status:r}){switch(r){case"completed":return e.jsx(Ie,{size:13,className:"shrink-0 text-accent-green","data-testid":"activity-status-completed"});case"failed":return e.jsx(Ce,{size:13,className:"shrink-0 text-accent-red","data-testid":"activity-status-failed"});case"running":return e.jsx("span",{className:"inline-block w-2.5 h-2.5 shrink-0 rounded-full border-2 border-accent-blue border-r-transparent animate-spin","data-testid":"activity-status-running"});case"waiting_user":return e.jsx(xn,{size:13,className:"shrink-0 text-accent-yellow","data-testid":"activity-status-waiting"});case"blocked":return e.jsx(un,{size:13,className:"shrink-0 text-accent-red","data-testid":"activity-status-blocked"});case"paused":return e.jsx(ps,{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 Or=o.memo(function({activity:t,toolCalls:s,onAnswer:n}){const{t:a}=V(),[i,c]=o.useState(t.status==="running"),d=o.useRef(t.status);o.useEffect(()=>{(d.current==="running"||d.current==="waiting_user"||d.current==="paused")&&(t.status==="completed"||t.status==="failed")&&c(!1),d.current=t.status},[t.status]);const u=o.useMemo(()=>{for(const N of s){const w=bs(N.args);if(w)return w}},[s]),l=t.endedAt?t.endedAt-t.startedAt:Date.now()-t.startedAt,x=l>=6e4?`${Math.round(l/6e4)}m`:l>=1500?`${Math.round(l/1e3)}s`:"",f=t.status==="waiting_user",h=t.status==="blocked",g=t.status==="paused";return e.jsxs("div",{className:`rounded-lg border transition-colors ${f?"border-accent-yellow/30 bg-accent-yellow/5":h?"border-accent-red/30 bg-accent-red/5":"border-dark-border/40 bg-dark-surface/30 hover:bg-dark-surface/50"}`,"data-testid":"activity-row",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 cursor-pointer select-none",onClick:()=>c(N=>!N),"data-testid":"activity-row-toggle",children:[e.jsx(Br,{status:t.status}),e.jsx("span",{className:"min-w-0 text-[13px] font-medium text-dark-text truncate",children:t.title}),t.phase!=="analysis"&&e.jsx("span",{className:"shrink-0 rounded border border-dark-border/60 px-1 py-px text-[9.5px] uppercase tracking-wide text-dark-muted","data-testid":"activity-phase",children:a(`activity.phase.${t.phase}`)}),u&&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:Lr(u)}),s.length>1&&e.jsx("span",{className:"shrink-0 text-[10.5px] text-dark-muted",children:a("activity.evidenceMore",{count:s.length-1})}),x&&e.jsx("span",{className:"shrink-0 text-[10.5px] text-dark-muted",children:x}),f&&e.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-accent-yellow",children:a("activity.waitingUser")}),h&&e.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-accent-red",title:t.blockedReason?a("activity.blocked",{reason:t.blockedReason}):void 0,children:a("activity.blocked",{reason:t.blockedReason??""})}),g&&e.jsx("span",{className:"ml-auto shrink-0 text-[11px] text-dark-300",children:a("activity.paused")}),f&&n&&e.jsx("button",{type:"button",onClick:N=>{N.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:a("activity.viewAndAnswer")}),!f&&s.length>0&&e.jsx(fe,{size:12,className:`ml-auto shrink-0 text-dark-muted transition-transform ${i?"rotate-180":""}`})]}),i&&s.length>0&&e.jsx("div",{className:"px-1 pb-1",children:e.jsx(jt,{toolCalls:s})})]})});function Fr({index:r,text:t,isStreaming:s,collapsed:n,onToggle:a}){const{t:i}=V();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:()=>a(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-accent-blue/90 animate-pulse":"text-dark-muted",children:s?`${i("chat.thinking")}…`:i("chat.thoughtProcess")})]}),!n&&e.jsx("div",{className:"mt-1 text-xs text-dark-muted whitespace-pre-wrap break-words border-l-2 border-dark-border/40 pl-3 max-h-64 overflow-y-auto custom-scrollbar",children:t.replace(/\n{3,}/g,`
|
|
12
|
+
|
|
13
|
+
`)})]})}const qr=o.memo(function({message:t,sessionId:s,isGenerating:n,onAnswer:a}){const i=Fn(y=>qn(y,s,t.id)),c=o.useMemo(()=>i.length>0?i:!t.toolCalls||t.toolCalls.length===0?[]:Hn(s??"",t),[i,t,s]),d=o.useMemo(()=>t.thinkingBlocks&&t.thinkingBlocks.length>0?t.thinkingBlocks:t.thinking?[{index:Number.MIN_SAFE_INTEGER,text:t.thinking}]:[],[t.thinkingBlocks,t.thinking]),[u,l]=o.useState({}),x=!n||!!t.content;o.useEffect(()=>{x&&l(y=>{const p={...y};for(const S of d)p[S.index]=!0;return p})},[x,d]);const f=o.useMemo(()=>{let y=Number.MIN_SAFE_INTEGER;for(const p of d)y=Math.max(y,p.index);for(const p of t.toolCalls??[])y=Math.max(y,p.index??Number.MIN_SAFE_INTEGER);return y},[d,t.toolCalls]),h=y=>n&&!t.content&&y===f,g=y=>{const p=u[y]??(!!t.content||!n);l(S=>({...S,[y]:!p}))},N=o.useMemo(()=>{const y=[];for(const p of d)y.push({key:`thinking-${p.index}`,index:p.index,kind:"thinking",block:p});for(const p of c)y.push({key:`activity-${p.id}`,index:p.blockRange[0],kind:"activity",activity:p});return y.sort((p,S)=>p.index-S.index),y},[d,c]),w=o.useMemo(()=>{const y={},p=t.toolCalls??[];for(const S of c)y[S.id]=S.toolCallIds.map($=>p.find(_=>_.id===$)).filter($=>!!$);return y},[c,t.toolCalls]);return N.length===0?null:e.jsx("div",{className:"mb-1 space-y-0.5","data-testid":"agent-activity-feed",children:N.map(y=>y.kind==="thinking"&&y.block?e.jsx(Fr,{index:y.block.index,text:y.block.text,isStreaming:h(y.block.index),collapsed:u[y.block.index]??(!!t.content||!n),onToggle:g},y.key):y.activity?e.jsx(Or,{activity:y.activity,toolCalls:w[y.activity.id]??[],onAnswer:a},y.key):null)})}),Ps=5,Hr=30,Ur=["让我","我先","我现在","我发现","我注意到","我决定","我重新","我重试","我继续","我现在要","让我现在","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 Jr(r){const t=r.charCodeAt(0);return t>=19968&&t<=40959}function Wr(r){let t="",s=!1;for(const n of r)n===" "||n===" "||n===" "?(s||(t+=" "),s=!0):(t+=n,s=!1);return t}function Gr(r){return r>=97&&r<=122||r>=48&&r<=57||r===95}function Ls(r){const t=Wr(r.trimStart().toLowerCase());return Ur.some(s=>{if(!t.startsWith(s))return!1;const n=t[s.length];return n===void 0||Jr(s)||s==="i re-"?!0:!Gr(n.charCodeAt(0))})}function Kr(r){if(!r)return!1;const t=r.split(/\r?\n/).slice(0,Hr);let s=0;for(const n of t)if(n.trim())if(Ls(n)){if(s++,s>=Ps)return!0}else return!1;return!1}function Zr(r,t){if(!r)return{body:r||"",absorbed:""};if(!Kr(r))return{body:r,absorbed:""};const s=r.split(/\r?\n/);let n=0,a=0;for(const c of s){if(!c.trim()){a++;continue}if(Ls(c)){n++,a++;continue}break}if(n<Ps)return{body:r,absorbed:""};let i=0;for(const c of s.slice(0,a)){if(i+=c.length,i>=r.length)break;r.startsWith(`\r
|
|
14
|
+
`,i)?i+=2:(r[i]===`
|
|
15
|
+
`||r[i]==="\r")&&(i+=1)}return{body:r.slice(i),absorbed:r.slice(0,i)}}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:a}=V(),[i,c]=o.useState(!1),d=o.useRef(null);o.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]);const u=o.useCallback(async()=>{try{await navigator.clipboard.writeText(r.content||r.thinking||""),c(!0),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>c(!1),2e3)}catch(l){console.error("Failed to copy message:",l)}},[r.content,r.thinking]);return t?e.jsxs(e.Fragment,{children:[e.jsx(ot,{onClick:u,title:a("chat.copyMessage"),children:i?e.jsx(Ie,{size:12,className:"text-accent-green"}):e.jsx(mn,{size:12})}),r.type==="assistant"&&s&&e.jsx(ot,{onClick:()=>s(r.id),title:a("chat.regenerate"),children:e.jsx($e,{size:12})}),n&&e.jsx(ot,{onClick:()=>n(r.id),title:a("chat.deleteMessage"),danger:!0,children:e.jsx(hn,{size:12})})]}):null}function ns({ts:r,children:t}){const{i18n:s}=V(),n=s.language==="en"?"en-US":"zh-CN";return e.jsxs("div",{className:"absolute top-2 right-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:[t,e.jsx("span",{className:"pl-1 text-[10px] text-dark-muted/50",children:new Date(r).toLocaleTimeString(n,{hour:"2-digit",minute:"2-digit"})})]})}function Vr(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,a)=>n.index-a.index),s}function Xr({index:r,text:t,isStreaming:s,collapsed:n,onToggle:a}){const{t:i}=V();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:()=>a(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-accent-blue/90 animate-pulse":"text-dark-muted",children:s?`${i("chat.thinking")}…`:i("chat.thoughtProcess")})]}),!n&&e.jsx("div",{className:"mt-1 text-xs text-dark-muted whitespace-pre-wrap break-words border-l-2 border-dark-border/40 pl-3 max-h-64 overflow-y-auto custom-scrollbar",children:t.replace(/\n{3,}/g,`
|
|
16
|
+
|
|
17
|
+
`)})]})}const Qr=o.memo(function({message:t,sessionId:s,onRegenerate:n,onDeleteMessage:a}){var _,A,R;const{t:i}=V(),c=Ve(v=>v.developerView),d=he(v=>{var O;if(!s||!v.generatingSessions.includes(s))return!1;const j=v.messagesBySession[s];return j?((O=j[j.length-1])==null?void 0:O.id)===t.id:!1}),u=o.useMemo(()=>t.thinkingBlocks&&t.thinkingBlocks.length>0?t.thinkingBlocks:t.thinking?[{index:Number.MIN_SAFE_INTEGER,text:t.thinking}]:[],[t.thinkingBlocks,t.thinking]),[l,x]=o.useState({}),f=!d||!!t.content;o.useEffect(()=>{f&&x(v=>{const j={...v};for(const O of u)j[O.index]=!0;return j})},[f,u]);const h=o.useMemo(()=>Vr(u,t.toolCalls),[u,t.toolCalls]),g=o.useMemo(()=>{var O;if(!t.content)return"";if(!(!!t.thinking||(((O=t.thinkingBlocks)==null?void 0:O.length)??0)>0))return t.content;const{body:j}=Zr(t.content);return j||t.content},[t.content,t.thinking,t.thinkingBlocks]),N=o.useMemo(()=>{const v=[];for(const j of h)if(j.kind==="thinking"&&j.block)v.push({key:j.key,kind:"thinking",block:j.block});else if(j.kind==="tool"&&j.toolCall){const O=v[v.length-1];O&&O.kind==="tools"?O.toolCalls.push(j.toolCall):v.push({key:`tools-${j.key}`,kind:"tools",toolCalls:[j.toolCall]})}return v},[h]),w=o.useMemo(()=>{let v=Number.MIN_SAFE_INTEGER;for(const j of u)v=Math.max(v,j.index);for(const j of t.toolCalls??[])v=Math.max(v,j.index??Number.MIN_SAFE_INTEGER);return v},[u,t.toolCalls]),y=o.useCallback(v=>{const j=l[v]??(!!t.content||!d);x(O=>({...O,[v]:!j}))},[d,t.content,l]),p=t.type==="user",S=t.type==="system",$=o.useCallback((v,j)=>{if(!s)return;const E=he.getState().getMessages(s),D=E.findIndex(ne=>ne.id===t.id);if(D===-1)return;const F=E[D];if(!F)return;const X={...F,hookApproval:F.hookApproval?{...F.hookApproval,status:j}:void 0},W=[...E];W[D]=X,he.setState({messagesBySession:{...he.getState().messagesBySession,[s]:W}})},[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(pn,{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:a})}),e.jsx("div",{className:"whitespace-pre-wrap break-words leading-relaxed text-[14.5px]",children:(_=t.content)==null?void 0:_.replace(/\n{3,}/g,`
|
|
18
|
+
|
|
19
|
+
`)})]})})]}):S?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(xs,{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:a})}),t.steps&&t.steps.length>0&&!t.hookApproval?e.jsx(Cr,{steps:t.steps,isGenerating:d}):c?e.jsx(e.Fragment,{children:N.length>0&&!t.hookApproval&&e.jsx("div",{className:"mb-2 space-y-1",children:N.map(v=>v.kind==="thinking"?e.jsx(Xr,{index:v.block.index,text:v.block.text,isStreaming:d&&!t.content&&v.block.index===w,collapsed:l[v.block.index]??(!!t.content||!d),onToggle:y},v.key):e.jsx(jt,{toolCalls:v.toolCalls},v.key))})}):e.jsx(qr,{message:t,sessionId:s,isGenerating:d}),t.content?e.jsx("div",{className:"leading-relaxed",children:e.jsx(Un,{content:g.replace(/\n{3,}/g,`
|
|
20
|
+
|
|
21
|
+
`)})}):u.length===0&&!t.hookApproval&&((A=t.steps)!=null&&A.length)?null:u.length===0&&!t.hookApproval&&!((R=t.steps)!=null&&R.length)&&d?e.jsxs("div",{className:"flex items-center gap-2 py-1 text-xs text-dark-muted","data-testid":"thinking-typing",children:[e.jsxs("span",{className:"chat-typing-dots",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsxs("span",{children:[i("chat.thinking"),"…"]})]}):null,t.summary&&!d&&e.jsx("div",{className:"mt-1.5 text-[11px] text-dark-muted/70","data-testid":"turn-summary",children:Jn(t.summary)}),t.fileJob&&e.jsx("div",{className:"mt-3",children:e.jsx($r,{job:t.fileJob})}),t.errorCard&&e.jsx("div",{className:"mt-3",children:e.jsx(Pr,{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(Tr,{approval:t.hookApproval,onResolved:$})})]})]})});function Yr(r,t=28){const s=r.replace(/\s+/g," ").trim();return s.length>t?`${s.slice(0,t)}…`:s}const ea="cubic-bezier(0.34, 1.56, 0.64, 1)",ta=o.memo(function({items:t,activeId:s,onJump:n}){const{t:a}=V(),[i,c]=o.useState(!1),d=o.useRef(null),u=o.useCallback(()=>{d.current&&window.clearTimeout(d.current),c(!0)},[]),l=o.useCallback(()=>{d.current&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>c(!1),180)},[]);return t.length===0?null:e.jsx("div",{role:"list","aria-label":a("chat.messageRail"),className:"pointer-events-none absolute right-4 top-1/2 z-30 hidden -translate-y-1/2 md:block",children:e.jsxs("div",{onMouseEnter:u,onMouseLeave:l,"data-testid":"rail-trigger",className:"pointer-events-auto relative flex items-center py-3",children:[e.jsxs("div",{"aria-hidden":!i,inert:!i,"data-testid":"rail-panel",className:`absolute right-full top-1/2 flex w-72 -translate-y-1/2 origin-right flex-col overflow-hidden rounded-xl border border-dark-border/70 bg-dark-bg/90 shadow-xl shadow-black/10 backdrop-blur-xl transition-all duration-300 ${i?"translate-x-0 scale-100 opacity-100":"pointer-events-none translate-x-4 scale-95 opacity-0"}`,style:{transitionTimingFunction:i?ea:"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(fn,{size:12,className:"text-accent-blue","aria-hidden":"true"}),a("chat.messageIndex")]}),e.jsx("span",{className:"rounded-full bg-dark-hover px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-dark-muted",children:t.length})]}),e.jsx("div",{className:"max-h-[55vh] overflow-y-auto p-1.5 custom-scrollbar",children:t.map((x,f)=>{const h=x.id===s;return e.jsxs("button",{type:"button",role:"listitem",onClick:()=>n(x.id),title:x.content,"aria-current":h?"true":void 0,tabIndex:i?0:-1,className:`group/item flex w-full items-start gap-2 rounded-lg px-2 py-1.5 text-left transition-all duration-200 ${i?"translate-x-0 opacity-100":"translate-x-2 opacity-0"} ${h?"bg-accent-blue/10":"hover:bg-dark-hover"}`,style:{transitionDelay:i?`${Math.min(f*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 ${h?"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:f+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 ${h?"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,f)=>{const h=Yr(x.content),g=x.id===s;return e.jsx("button",{type:"button",role:"listitem",onClick:()=>n(x.id),title:x.content,"aria-label":`${f+1}. ${h}`,"aria-current":g?"true":void 0,className:"group/dot pointer-events-auto flex h-6 w-5 items-center justify-center rounded-full transition-colors duration-200 hover:bg-dark-surface/80",children:e.jsx("span",{className:g?"h-2 w-2 rounded-full bg-accent-blue ring-2 ring-accent-blue/25 transition-all duration-300 ease-out group-hover/dot:scale-125":"h-1.5 w-1.5 rounded-full bg-dark-muted/35 transition-all duration-300 ease-out group-hover/dot:scale-150 group-hover/dot:bg-dark-muted"})},x.id)})})]})})}),sa=o.memo(function({messages:t,isGenerating:s,sessionId:n,onSendSuggestion:a,onRegenerate:i,onDeleteMessage:c}){const{t:d}=V(),u=o.useRef(null),l=o.useRef(new Map),[x,f]=o.useState(!0),[h,g]=o.useState(null),[N,w]=o.useState(null),[y,p]=o.useState(0),S=o.useRef(null),$=o.useRef(!1),_=o.useRef(null),A=o.useRef(s);A.current=s;const R=o.useMemo(()=>t.filter(z=>!z.deleted),[t]),v=o.useMemo(()=>R.filter(z=>z.type==="user").map(z=>({id:z.id,content:z.content})),[R]),j=o.useMemo(()=>v.map(z=>z.id),[v]),O=o.useCallback(z=>{if(z){const L=z.dataset.mid;L&&l.current.set(L,z)}},[]);o.useEffect(()=>{const z=new Set(j);for(const L of l.current.keys())z.has(L)||l.current.delete(L)},[j]);const E=o.useCallback(()=>{const z=u.current;if(!z||j.length===0){g(null);return}const L=z.getBoundingClientRect(),oe=L.top+L.height*.35;let H=j[0]??null;for(const Q of j){const Y=l.current.get(Q);if(!(!Y||!Y.isConnected))if(Y.getBoundingClientRect().top<=oe)H=Q;else break}z.scrollHeight-z.scrollTop-z.clientHeight<50&&(H=j[j.length-1]??H),g(H)},[j]),D=o.useCallback(()=>{const z=u.current;if(!z)return;const L=z.scrollHeight-z.scrollTop-z.clientHeight;$.current?L>=50&&($.current=!1):f(L<50),E()},[E]);o.useEffect(()=>{E()},[t,E]);const F=o.useCallback(z=>{const L=u.current,oe=l.current.get(z);if(!L||!oe||!oe.isConnected)return;f(!1),w(z),p(pe=>pe+1),S.current&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>w(null),1600);const H=L.getBoundingClientRect(),Q=oe.getBoundingClientRect(),Y=L.scrollTop+(Q.top-H.top)-L.clientHeight/2+Q.height/2;_.current&&window.clearTimeout(_.current),$.current=!0,L.scrollTo({top:Math.max(0,Y),behavior:"smooth"});const ce=()=>{$.current=!1};"onscrollend"in L&&L.addEventListener("scrollend",ce,{once:!0}),_.current=window.setTimeout(()=>{$.current=!1},1500)},[]);o.useEffect(()=>()=>{S.current&&window.clearTimeout(S.current),_.current&&window.clearTimeout(_.current)},[]);const X=o.useCallback(()=>{_.current&&window.clearTimeout(_.current),$.current=!1;const z=u.current;z&&(z.scrollTop=z.scrollHeight)},[]),W=o.useCallback(()=>{_.current&&window.clearTimeout(_.current),$.current=!1,f(!0);const z=u.current;z&&z.scrollTo({top:z.scrollHeight,behavior:"smooth"})},[]);o.useEffect(()=>{s&&(f(!0),X())},[s,X]),o.useEffect(()=>{x&&X()},[t,x,X]);const ne=o.useMemo(()=>[{icon:bn,label:d("chat.suggestionCode"),prompt:d("chat.suggestionCodePrompt")},{icon:wt,label:d("chat.suggestionAnalyze"),prompt:d("chat.suggestionAnalyzePrompt")},{icon:ms,label:d("chat.suggestionAutomate"),prompt:d("chat.suggestionAutomatePrompt")}],[d]);return e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsxs("div",{ref:u,onScroll:D,className:"h-full overflow-y-auto custom-scrollbar",children:[R.length===0?e.jsx("div",{className:"flex min-h-[55vh] items-center justify-center p-6",children:e.jsxs("div",{className:"w-full max-w-xl px-4 text-center",children:[e.jsx("img",{src:"/logo.svg",alt:"deepseekcode",className:"w-14 h-14 mx-auto mb-5 rounded-2xl shadow-md"}),e.jsx("h2",{className:"text-xl font-semibold tracking-tight mb-2",children:d("chat.welcome")}),e.jsx("p",{className:"text-dark-muted text-sm mb-8",children:d("chat.welcomeDesc")}),a&&e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2.5 text-left",children:ne.map(z=>e.jsxs("button",{onClick:()=>a(z.prompt),className:"group w-full rounded-xl border border-dark-border bg-dark-surface px-3.5 py-3 text-left transition-all duration-150 hover:border-accent-blue/40 hover:shadow-md hover:-translate-y-px",children:[e.jsx(z.icon,{size:16,"aria-hidden":"true",className:"text-accent-blue mb-2"}),e.jsx("div",{className:"text-[13px] font-medium text-dark-text",children:z.label}),e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-dark-muted line-clamp-2",children:z.prompt})]},z.label))})]})}):e.jsx("div",{className:"chat-stack flex flex-col",children:R.map(z=>e.jsxs("div",{"data-mid":z.id,ref:O,className:"relative w-full",children:[N===z.id&&e.jsx("div",{className:"animate-rail-flash pointer-events-none absolute inset-0"},y),e.jsx(Qr,{message:z,sessionId:n,onRegenerate:i,onDeleteMessage:c})]},z.id))}),s&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-dark-muted py-3 px-5",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:d("chat.thinkingEllipsis")})]})]}),v.length>0&&e.jsx(ta,{items:v,activeId:h,onJump:F}),!x&&R.length>0&&e.jsx("button",{type:"button",onClick:W,title:d("chat.backToBottom"),"aria-label":d("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(fe,{size:15})})]})}),na={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"},ra=o.memo(function(){const{t}=V(),s=Ne(u=>u.mode),n=Ne(u=>u.setBaseMode),a=Ne(u=>u.toggleAuto),i=s==="normal"?"act":s,c=Ke(i),d=gt(i);return e.jsxs("div",{className:"flex items-center gap-1",children:[Wn.map(u=>{const l=c===u,x=Gn[u],f=s!=="normal"&&l?na[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(u),className:ae("px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",f),title:t("chat.clickToSwitchMode"),"aria-pressed":l,children:x.label},u)}),e.jsxs("button",{type:"button",role:"switch","aria-checked":d,onClick:()=>a(),className:ae("flex items-center gap-1 px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",d?"border-accent-yellow/40 text-accent-yellow bg-accent-yellow/10":"border-dark-border text-dark-muted hover:bg-dark-hover"),title:t("plan.autoApprove"),children:[e.jsx($e,{size:11,className:ae(d?"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"}},aa=o.memo(function(){const{t}=V(),s=Oe(b=>b.model),n=Oe(b=>b.modelRef),a=Oe(b=>b.setModel),i=Oe(b=>b.setModelRef),c=Ne(b=>b.mode),d=Ve(b=>b.effort),u=Ve(b=>b.setEffort),[l,x]=o.useState([]),[f,h]=o.useState(!1),g=o.useRef(null),[N,w]=o.useState(!1),[y,p]=o.useState(""),[S,$]=o.useState(""),[_,A]=o.useState([]),[R,v]=o.useState(new Set),[j,O]=o.useState("none"),[E,D]=o.useState(!1),[F,X]=o.useState(null),[W,ne]=o.useState(null),z=o.useMemo(()=>Array.from(new Set(l.map(b=>b.provider))),[l]),L=o.useCallback(async()=>{try{const b=await ue.models.list();b.success&&b.data&&Array.isArray(b.data.models)&&x(b.data.models.filter(q=>q.enabled!==!1))}catch{}},[]),oe=o.useCallback(()=>{var q,B;const b=(n==null?void 0:n.split(":")[0])||((q=l.find(ie=>ie.isGlobalDefault))==null?void 0:q.provider)||((B=l[0])==null?void 0:B.provider)||"";p(b),$(""),X(null),w(!0)},[n,l]),H=o.useCallback(()=>{w(!1),A([]),X(null)},[]),Q=o.useCallback(async(b,q)=>{if(b){D(!0),X(null);try{const B=await ue.models.byProvider(b,q||void 0);B.success&&B.data?(A(B.data.models||[]),v(new Set(B.data.existing||[])),O(B.data.source)):(A([]),v(new Set),X(B.error||t("chat.loadModelsFailed")))}catch{A([]),v(new Set),X(t("chat.loadModelsFailed"))}finally{D(!1)}}},[t]);o.useEffect(()=>{if(!N)return;const b=setTimeout(()=>{Q(y,S)},S?300:0);return()=>clearTimeout(b)},[N,y,S,Q]),o.useEffect(()=>{L()},[L]),o.useEffect(()=>{const b=()=>{L()};return window.addEventListener("models-updated",b),()=>window.removeEventListener("models-updated",b)},[L]);const Y=o.useCallback(()=>h(!1),[]);o.useEffect(()=>{if(!f)return;const b=B=>{g.current&&!g.current.contains(B.target)&&Y()},q=B=>{B.key==="Escape"&&Y()};return document.addEventListener("mousedown",b),document.addEventListener("keydown",q),()=>{document.removeEventListener("mousedown",b),document.removeEventListener("keydown",q)}},[f,Y]);const ce=async b=>{Y();const q=Ke(c==="normal"?"act":c),B=`${b.provider}:${b.id}`,ie=q==="plan"?{plan:B}:q==="goal"?{goal:B}:{global:B,act:B};try{(await ue.models.setDefaults(ie)).success&&(a(b.id),i(`${b.provider}:${b.id}`),await L())}catch{}},pe=async b=>{const q=R.has(b.id),B=`${y}:${b.id}`;ne(b.id);try{if(!q){const ge=await ue.models.create({provider:y,model:{id:b.id,name:b.name||b.id}});if(!ge.success){X(ge.error||t("chat.addModelFailed"));return}}const ie=Ke(c==="normal"?"act":c),de=ie==="plan"?{plan:B}:ie==="goal"?{goal:B}:{global:B,act:B},Ee=await ue.models.setDefaults(de);Ee.success?(a(b.id),i(B),H(),await L()):X(Ee.error||t("chat.switchModelFailed"))}catch{X(t("chat.addModelFailed"))}finally{ne(null)}},ee=Ke(c==="normal"?"act":c),me=ee==="plan"?"isPlanDefault":ee==="goal"?"isGoalDefault":"isActDefault",re=b=>{const q=`${b.provider}:${b.id}`;if(n)return n===q;if(s===q)return!0;if(s!==b.id)return!1;const B=l.filter(de=>de.id===b.id);return B.length<=1?!0:(B.find(de=>de[me]===!0)??B.find(de=>de.isGlobalDefault)??B[0])===b},be=l.some(b=>b[me]===!0),C=l.find(b=>b.isGlobalDefault),U=async()=>{Y();const b=ee==="plan"?{plan:null}:ee==="goal"?{goal:null}:{act:null};try{(await ue.models.setDefaults(b)).success&&(C?(a(C.id),i(`${C.provider}:${C.id}`)):(a(""),i("")),await L())}catch{}},P=rs[d];return e.jsxs("div",{className:"relative",ref:g,children:[e.jsxs("button",{type:"button",onClick:()=>h(b=>!b),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:t("chat.clickToSelectModel"),"aria-haspopup":"listbox","aria-expanded":f,children:[e.jsx(gn,{size:12,className:"shrink-0"}),e.jsx("span",{className:"font-medium max-w-[8rem] truncate",children:s||t("chat.selectModel")}),e.jsx("span",{className:"h-3 w-px bg-dark-border shrink-0","aria-hidden":"true"}),e.jsx(Dt,{size:12,className:`shrink-0 ${P.color}`}),e.jsx("span",{className:`text-xs font-medium ${P.color}`,children:t(P.labelKey)}),e.jsx(fe,{size:12,className:ae("transition-transform",f&&"rotate-180")})]}),f&&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")}),N?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:H,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(kn,{size:12})}),z.length>1?e.jsx("select",{value:y,onChange:b=>p(b.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:z.map(b=>e.jsx("option",{value:b,children:b},b))}):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:S,onChange:b=>$(b.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:E?e.jsxs("div",{className:"px-3 py-2 text-xs text-dark-muted flex items-center gap-1.5",children:[e.jsx(yn,{size:11,className:"animate-spin"}),t("chat.loadingModels")]}):F?e.jsx("div",{className:"px-3 py-2 text-xs text-accent-red",children:F}):y?_.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-dark-muted",children:t(S?"chat.noModelsFound":"chat.noProviderModels")}):e.jsxs(e.Fragment,{children:[j!=="none"&&e.jsx("div",{className:"px-3 pt-1.5 pb-0.5 text-[10px] text-dark-muted/70",children:t(j==="provider-api"?"chat.modelsSourceProviderApi":"chat.modelsSourceCatalog")}),_.map(b=>{const q=R.has(b.id),B=n===`${y}:${b.id}`;return e.jsxs("button",{type:"button",role:"option","aria-selected":B,onClick:()=>pe(b),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:b.name||b.id}),B&&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:b.id})]}),q?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:W===b.id?t("chat.addingModel"):t("chat.addAndSwitch")})]},b.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:[be&&e.jsx("button",{type:"button",role:"option","aria-selected":!1,onClick:U,title:t("chat.followGlobalDefaultHint"),className:"w-full flex items-center gap-2 px-3 py-2 text-left transition-colors hover:bg-dark-hover border-b border-dark-border/60",children:e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsxs("span",{className:"text-xs font-semibold text-accent-green flex items-center gap-1.5",children:[e.jsx(wn,{size:11}),t("chat.followGlobalDefault")]}),e.jsx("span",{className:"block text-[10px] text-dark-muted mt-0.5 truncate",children:C?C.name||C.id:t("chat.noGlobalDefault")})]})}),l.map(b=>{const q=re(b);return e.jsx("button",{type:"button",role:"option","aria-selected":q,onClick:()=>ce(b),className:ae("w-full flex items-center gap-2 px-3 py-2 text-left transition-colors",q?"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:ae("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",q?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Ie,{size:11,strokeWidth:3})}),e.jsx("span",{className:"text-xs font-semibold text-dark-text truncate",children:b.name||b.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",children:b.provider}),b.isGlobalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-green/20 text-accent-green",children:t("chat.globalDefault")}),b.isPlanDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-blue/20 text-accent-blue",children:t("chat.planDefault")}),b.isActDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-yellow/20 text-accent-yellow",children:t("chat.actDefault")}),b.isGoalDefault&&e.jsx("span",{className:"text-[10px] px-1 rounded bg-accent-purple/20 text-accent-purple",children:t("chat.goalDefault")})]})]})},`${b.provider}:${b.id}`)}),l.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:oe,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(wt,{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(Dt,{size:11}),t("chat.effort")]}),e.jsx("div",{className:"py-1",children:Kn.map(b=>{const q=rs[b],B=b===d;return e.jsxs("button",{type:"button",role:"option","aria-selected":B,onClick:()=>{u(b),Y()},className:ae("w-full flex items-center gap-2 px-3 py-1.5 text-left transition-colors",B?"bg-dark-hover":"hover:bg-dark-hover"),children:[e.jsx("span",{className:ae("flex h-4 w-4 items-center justify-center rounded border transition-colors shrink-0",B?"border-accent-green bg-accent-green/20 text-accent-green":"border-dark-border text-transparent"),children:e.jsx(Ie,{size:11,strokeWidth:3})}),e.jsx("span",{className:`text-xs font-medium ${B?q.color:"text-dark-text"}`,children:t(q.labelKey)})]},b)})})]})]})});function oa(r,t){if(!r)return t;const s=r.includes("\\")?"\\":"/";return r.endsWith(s)?r+t:r+s+t}function la(r){const t=r.replace(/[\\/]+$/,""),s=Math.max(t.lastIndexOf("\\"),t.lastIndexOf("/"));return s===-1?t:t.slice(s+1)}function ia({initial:r,onClose:t,onConfirm:s}){const{t:n}=V(),[a,i]=o.useState(r),[c,d]=o.useState(null),[u,l]=o.useState([]),[x,f]=o.useState(!1),[h,g]=o.useState(""),[N,w]=o.useState(r),y=o.useRef(null),p=o.useCallback(async _=>{f(!0),g("");try{const A=await ue.dirs.list(_);if(!A.success||!A.data){g(A.error||n("chat.dirPickerLoadError"));return}i(A.data.path),d(A.data.parent),l(A.data.dirs||[]),w(A.data.path)}catch(A){g(A instanceof Error?A.message:n("chat.dirPickerLoadError"))}finally{f(!1)}},[n]);o.useEffect(()=>{p(r)},[r,p]),o.useEffect(()=>{var _;(_=y.current)==null||_.focus()},[]),o.useEffect(()=>{const _=A=>{A.key==="Escape"&&(A.preventDefault(),A.stopPropagation(),t())};return document.addEventListener("keydown",_),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",_),document.body.style.overflow=""}},[t]);const S=o.useCallback(()=>{const _=N.trim();_&&p(_)},[N,p]),$=o.useCallback(()=>{c&&p(c)},[c,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(hs,{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(Ce,{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(vn,{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:N,onChange:_=>w(_.target.value),onKeyDown:_=>{_.key==="Enter"&&S()},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:S,disabled:x||!N.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:a,children:a||n("chat.noWorkspaceDir")}),e.jsxs("button",{type:"button",onClick:()=>void $(),disabled:x||!a,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(fs,{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(Te,{size:14,className:"animate-spin","aria-hidden":"true"}),n("chat.loading")]}):h?e.jsx("div",{className:"px-3 py-4 text-xs text-accent-red",children:h}):u.length===0?e.jsx("div",{className:"px-3 py-4 text-xs text-dark-muted/60 text-center",children:n("chat.dirPickerNoDirs")}):u.map(_=>{const A=oa(a,_);return e.jsxs("button",{type:"button",onClick:()=>void p(A),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(vt,{size:13,className:"shrink-0 text-accent-yellow/80 group-hover:text-accent-yellow","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:_}),e.jsx(ke,{size:12,className:"shrink-0 ml-auto text-dark-muted/40","aria-hidden":"true"})]},_)})}),e.jsx("button",{type:"button",onClick:()=>s(a),disabled:!a||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 ca=o.memo(function({workspaceDir:t,onSelect:s}){const{t:n}=V(),a=Ve(f=>f.recentDirs),[i,c]=o.useState(!1),[d,u]=o.useState(!1),l=o.useRef(null);o.useEffect(()=>{if(!i)return;const f=g=>{l.current&&!l.current.contains(g.target)&&c(!1)},h=g=>{g.key==="Escape"&&c(!1)};return document.addEventListener("mousedown",f),document.addEventListener("keydown",h),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",h)}},[i]);const x=o.useCallback(f=>{var g;const h=((g=f==null?void 0:f.trim)==null?void 0:g.call(f))||"";h&&(c(!1),u(!1),s(h))},[s]);return e.jsxs("div",{className:"relative shrink-0",ref:l,children:[e.jsxs("button",{type:"button",onClick:()=>c(f=>!f),className:ae("flex items-center gap-1 max-w-[180px] px-2 py-0.5 rounded-full border text-xs whitespace-nowrap transition-colors cursor-pointer",i?"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":i,"aria-haspopup":"menu",children:[e.jsx(hs,{size:12,className:"shrink-0 text-accent-blue/80","aria-hidden":"true"}),e.jsx("span",{className:"truncate font-mono text-[11px]",children:t?la(t):n("chat.noWorkspaceDir")}),e.jsx(fe,{size:11,className:ae("shrink-0 transition-transform",i&&"rotate-180"),"aria-hidden":"true"})]}),i&&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")}),a.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:a.map(f=>{const h=f===t;return e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>x(f),className:ae("w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors group",h?"text-accent-blue bg-accent-blue/5":"text-dark-text hover:bg-dark-hover"),title:f,children:[e.jsx(vt,{size:12,className:ae("shrink-0",h?"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:f}),h&&e.jsx("span",{className:"ml-auto shrink-0 text-[10px] text-accent-blue",children:"✓"})]},f)})}),e.jsx("div",{className:"border-t border-dark-border"}),e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{c(!1),u(!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")]})]}),d&&e.jsx(ia,{initial:t||"",onClose:()=>u(!1),onConfirm:x})]})});function da({isOpen:r,files:t,selectedIndex:s,query:n,isSearching:a,onSelect:i,onHover:c,selectedCount:d=0,onFinish:u}){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:[d>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded-full bg-accent-blue/20 text-accent-blue font-medium",children:["已选 ",d]}),e.jsx("span",{children:"↑↓ 选择 · Enter 插入(可连续多选)· Esc 关闭"})]})]}),t.length===0?e.jsx("div",{className:"px-3 py-6 text-center text-dark-muted text-xs flex flex-col items-center gap-1",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Te,{size:16,className:"animate-spin"}),e.jsx("span",{children:"搜索文件中..."})]}):e.jsx("span",{children:"未找到匹配的文件"})}):t.map((l,x)=>e.jsxs("button",{onClick:()=>i(l),onMouseEnter:()=>c(x),className:`w-full px-3 py-1.5 flex items-center gap-2 text-left text-xs transition-colors border-l-2 ${x===s?"bg-accent-blue/20 text-accent-blue border-accent-blue":"hover:bg-dark-hover text-dark-text border-transparent"}`,children:[l.type==="directory"?e.jsx(vt,{size:12,className:"text-accent-yellow shrink-0"}):e.jsx(yt,{size:12,className:"text-dark-muted shrink-0"}),e.jsx("span",{className:"truncate",children:l.name}),e.jsx("span",{className:"text-[10px] text-dark-muted truncate ml-auto",children:l.path})]},l.id||l.path))]}),u&&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:d>0?`已选 ${d} 个文件`:"Enter 插入 · 可连续多选"}),e.jsx("button",{onClick:u,className:"px-3 py-1 text-[11px] rounded bg-accent-blue text-white hover:opacity-90 transition-opacity",children:"完成引用"})]})]}):null}function ua({open:r,onClose:t,onSelect:s}){const{t:n}=V(),[a,i]=o.useState([]),[c,d]=o.useState(!1),[u,l]=o.useState("");o.useEffect(()=>{r&&(l(""),d(!0),ue.skills.list().then(f=>{const h=Array.isArray(f.data)?f.data:[];i(h.filter(g=>g.enabled!==!1))}).catch(()=>i([])).finally(()=>d(!1)))},[r]);const x=o.useMemo(()=>{const f=u.trim().toLowerCase();return f?a.filter(h=>[h.id,h.name,h.description,h.category,...h.tags||[]].join(" ").toLowerCase().includes(f)):a},[a,u]);return e.jsx(Zn,{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(wt,{size:14,className:"text-dark-muted shrink-0"}),e.jsx("input",{value:u,onChange:f=>l(f.target.value),placeholder:n("skills.pickPlaceholder"),autoFocus:!0,className:"flex-1 bg-transparent outline-none text-sm placeholder-dark-muted/60"}),c&&e.jsx($e,{size:13,className:"animate-spin text-dark-muted"})]}),c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx($e,{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(f=>e.jsxs("button",{onClick:()=>s(f),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:[f.icon||"⭐"," ",f.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:f.injection||"lazy"})]}),e.jsxs("div",{className:"text-xs text-dark-muted truncate font-mono",children:["$",f.id]}),f.description&&e.jsx("div",{className:"text-xs text-dark-muted line-clamp-2",children:f.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:f.category||"—"}),e.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-accent-blue shrink-0",children:[e.jsx(ms,{size:11}),n("skills.pickUse")]})]})]},f.id))})]})})}const xa=800,Fe=/\[Pasted text #(\d+)(?:\s*\+\d+ lines?)?\]/g;let pa=0;const Ct=new Map;function ma(r){const t=++pa;return Ct.set(t,r),t}function ha(r){return r.length>xa||Bs(r)>0}function Bs(r){return(r.match(/\r\n|\r|\n/g)||[]).length}function fa(r){const t=ma(r),s=Bs(r);return s===0?{id:t,label:`[Pasted text #${t}]`}:{id:t,label:`[Pasted text #${t} +${s} lines]`}}function ba(r){return Fe.lastIndex=0,r.replace(Fe,(t,s)=>{const n=parseInt(s,10),a=Ct.get(n);return a!==void 0?a:t})}function ga(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 ka(r){for(const t of r)Ct.delete(t)}const Ze=16e3;function lt(){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 ya(r){if(r.sampleRate===Ze&&r.numberOfChannels===1)return r.getChannelData(0);const t=Math.max(1,Math.ceil(r.length*Ze/r.sampleRate)),s=new OfflineAudioContext(1,t,Ze),n=s.createBufferSource();return n.buffer=r,n.connect(s.destination),n.start(0),(await s.startRendering()).getChannelData(0)}function wa(r,t){const s=new ArrayBuffer(44+r.length*2),n=new DataView(s),a=(c,d)=>{for(let u=0;u<d.length;u++)n.setUint8(c+u,d.charCodeAt(u))};a(0,"RIFF"),n.setUint32(4,36+r.length*2,!0),a(8,"WAVE"),a(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),a(36,"data"),n.setUint32(40,r.length*2,!0);let i=44;for(let c=0;c<r.length;c++){const d=Math.max(-1,Math.min(1,r[c]??0));n.setInt16(i,d<0?d*32768:d*32767,!0),i+=2}return s}function va(r){return new Promise((t,s)=>{const n=new FileReader;n.onload=()=>{const a=String(n.result||""),i=a.indexOf(",");t(i>=0?a.slice(i+1):a)},n.onerror=()=>s(n.error),n.readAsDataURL(r)})}function ja(r){const[t,s]=o.useState("idle"),[n,a]=o.useState(0),i=o.useRef(null),c=o.useRef(null),d=o.useRef([]),u=o.useRef(null),l=o.useRef(0),x=o.useCallback(()=>{var w;(w=c.current)==null||w.getTracks().forEach(y=>y.stop()),c.current=null},[]),f=o.useCallback(()=>{u.current&&(clearInterval(u.current),u.current=null)},[]);o.useEffect(()=>()=>{f(),i.current&&i.current.state!=="inactive"&&i.current.stop(),x()},[f,x]);const h=o.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)))}c.current=w,d.current=[];const y=new MediaRecorder(w,lt()?{mimeType:lt()}:void 0);y.ondataavailable=p=>{p.data&&p.data.size>0&&d.current.push(p.data)},i.current=y,y.start(),l.current=Date.now(),a(0),s("recording"),u.current=setInterval(()=>a(Date.now()-l.current),100)},[t]),g=o.useCallback(async()=>{var p;const w=i.current;if(!w||w.state==="inactive")throw new Error("当前没有进行中的录音。");const y=new Promise(S=>{w.onstop=()=>S()});w.stop(),await y,f(),x(),i.current=null,s("transcribing");try{const S=new Blob(d.current,{type:lt()||"audio/webm"});d.current=[];const $=await S.arrayBuffer(),_=new AudioContext;let A;try{A=await _.decodeAudioData($)}finally{_.close()}if(A.duration<.25)return s("idle"),"";const v=await ya(A),j=wa(v,Ze),O=await va(new Blob([j],{type:"audio/wav"})),E=await ue.stt.transcribe(r,O,"wav");if(!E.success)throw new Error(E.error||"语音转写失败");return((p=E.data)==null?void 0:p.text)??""}finally{s("idle")}},[r,f,x]),N=o.useCallback(()=>{const w=i.current;w&&w.state!=="inactive"&&w.stop(),i.current=null,d.current=[],f(),x(),s("idle")},[f,x]);return{state:t,elapsedMs:n,start:h,stop:g,cancel:N}}function Na(){return typeof window<"u"&&!!window.__TAURI__}async function Sa(){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 Ca=({isOpen:r,commands:t,selectedIndex:s,filter:n,onSelect:a,onHover:i,containerRef:c})=>{const{t:d}=V();return!r||t.length===0?null:e.jsxs("div",{ref:c,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}`:d("slashCommands.quickCommands")}),e.jsx("span",{className:"opacity-70",children:d("slashCommands.help")})]}),t.map((u,l)=>e.jsxs("button",{"data-index":l,onClick:()=>a(u),onMouseEnter:()=>i(l),className:`w-full px-3 py-2 flex items-start gap-3 text-left transition-colors border-l-2 ${l===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:u.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:["/",u.name]}),u.args&&e.jsx("span",{className:"text-xs text-dark-muted",children:u.args}),!u.local&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-accent-blue/20 text-accent-blue shrink-0",children:d("slashCommands.backend")})]}),e.jsx("div",{className:"text-xs text-dark-muted truncate",children:u.description})]}),l===s&&e.jsx(jn,{size:14,className:"text-dark-muted shrink-0 mt-0.5","aria-hidden":"true"})]},u.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"],as=new RegExp(`(?:\\.(${Os.join("|")})|dockerfile|makefile)$`,"i"),Fs=["png","jpg","jpeg","webp","gif","bmp","svg"],it=new RegExp(`\\.(${Fs.join("|")})$`,"i"),Ea=10*1024*1024,_a=Os.map(r=>`.${r}`).join(",")+",.Dockerfile,.Makefile,"+Fs.map(r=>`.${r}`).join(","),Aa=".deepseekcode/attachments",Ma=50*1024*1024,Ge=10,Ra=r=>/\.xlsx?$/i.test(r)?ft:/\.(csv|docx|txt|md|mdx|rst|adoc|json|jsonc|yaml|yml|toml|xml|html|css|scss|less|env|gitignore|gitattributes|editorconfig)$/i.test(r)?ht:/\.(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)?Mn:yt,ct=3e3,os=5,dt=50;function za(r,t){const s=r.slice(0,t),n=s.lastIndexOf("@");if(n===-1)return{active:!1,query:"",start:-1};const a=s.slice(n+1);return/^[\p{L}\p{N}_\-./]*$/u.test(a)?{active:!0,query:a,start:n}:{active:!1,query:"",start:-1}}function Ia(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 Ta=o.memo(function({sessionId:t,onSend:s,onStop:n,onPause:a,onResume:i,slashOptions:c,workspaceDir:d,onWorkspaceSelect:u}){const{t:l}=V(),x=he(m=>{var k;return((k=m.sessionInputs)==null?void 0:k[t])??""}),f=he(m=>m.setSessionInput),h=he(m=>{var k;return((k=m.generatingSessions)==null?void 0:k.includes(t))??!1}),g=he(m=>{var k;return((k=m.pausedSessions)==null?void 0:k.includes(t))??!1}),N=o.useRef(null),w=o.useRef(null),y=o.useRef(!1),[p,S]=o.useState([]),[$,_]=o.useState(!1),[A,R]=o.useState(!1),v=o.useCallback(m=>{f(t,m)},[t,f]),[j,O]=o.useState(()=>{try{return localStorage.getItem("dsc.stt.lang")==="zh"?"zh":"en"}catch{return"en"}}),E=o.useCallback(()=>{O(m=>{const k=m==="en"?"zh":"en";try{localStorage.setItem("dsc.stt.lang",k)}catch{}return k})},[]),D=ja(j),F=o.useRef(null),X=o.useCallback(async()=>{var m;try{if(!F.current){const T=await ue.stt.status();T.success&&T.data&&(F.current=T.data)}const k=F.current;if(!k)return!0;if(k.service!=="ok"&&k.service!=="stopped")return le.warning(l("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1;const M=(m=k.backends)==null?void 0:m[j];return M&&!M.installed?(le.warning(l("stt.backendMissing")),window.dispatchEvent(new CustomEvent("switch-tab",{detail:{tab:"settings",section:"stt"}})),!1):!0}catch{return!0}},[l,j]);o.useEffect(()=>{const m=()=>{F.current=null};return window.addEventListener("stt-backends-changed",m),()=>window.removeEventListener("stt-backends-changed",m)},[]),o.useEffect(()=>{const m=k=>{var T;const M=(T=k.detail)==null?void 0:T.lang;(M==="en"||M==="zh")&&O(M)};return window.addEventListener("stt-lang-changed",m),()=>window.removeEventListener("stt-lang-changed",m)},[]);const W=o.useCallback(m=>{const k=N.current,M=(k==null?void 0:k.selectionStart)??x.length,T=x.slice(0,M)+m+x.slice(M);v(T),requestAnimationFrame(()=>{k==null||k.focus();const G=M+m.length;k&&(k.selectionStart=k.selectionEnd=G)})},[x,v]),ne=o.useCallback(async()=>{if(D.state==="recording"){try{const k=await D.stop();k?W(k):le.info(l("stt.noSpeech"))}catch(k){le.error(k instanceof Error?k.message:String(k))}return}if(!(D.state!=="idle"||!await X()))try{await D.start()}catch(k){le.error(k instanceof Error?k.message:String(k))}},[D,W,X,l]),z=Vn(c),{isOpen:L,filter:oe,filteredCommands:H,selectedIndex:Q,setSelectedIndex:Y,selectNext:ce,selectPrev:pe,executeCommand:ee,openMenu:me,closeMenu:re,setFilter:be,allCommands:C,containerRef:U}=z,[P,b]=o.useState(!1),[q,B]=o.useState(""),[ie,de]=o.useState([]),[Ee,ge]=o.useState(0),[Hs,Et]=o.useState(!1),[Us,De]=o.useState(0),_e=o.useRef(-1),Ae=o.useRef(new Set),Pe=o.useRef(null),He=o.useRef(null),Xe=o.useRef([]),ye=o.useRef(!1);o.useEffect(()=>{Ae.current=new Set,ye.current=!1,b(!1),B(""),de([]),De(0),re()},[t,re]);const _t=o.useDeferredValue(x),At=Oe(m=>m.estimateTokens),Qe=o.useMemo(()=>At(_t),[_t,At]),Mt=o.useCallback(()=>{const m=N.current;m&&(m.style.height="auto",m.style.height=Math.min(m.scrollHeight,200)+"px")},[]);o.useEffect(()=>{Mt()},[x,p.length,Mt]);const Ye=o.useCallback(()=>{if(Pe.current)return Promise.resolve(Pe.current);if(He.current)return He.current;Et(!0);const m=(async()=>{try{const k=await ue.files.list(),M=k.success&&k.data?k.data[0]:void 0;if(!M)return Pe.current=[],[];const T=[],G=new Set,I=async(J,te)=>{if(te>os||T.length>=ct)return;const K=[];for(const Z of J||[]){if(T.length>=ct)return;const we=Z.path.replace(/\\/g,"/");G.has(we)||(G.add(we),Z.type==="file"?T.push({...Z,path:we}):Z.children&&Z.children.length>0?await I(Z.children,te+1):te<os&&K.push(Z))}if(K.length===0)return;const xe=await Promise.all(K.map(async Z=>{var we;try{const ve=await ue.files.list(Z.path.replace(/\\/g,"/"));return ve.success&&ve.data?((we=ve.data[0])==null?void 0:we.children)||[]:[]}catch{return[]}}));for(const Z of xe){if(T.length>=ct)return;await I(Z,te+1)}};return await I(M.children,1),Pe.current=T,T}catch{return Pe.current=[],[]}finally{He.current=null,Et(!1)}})();return He.current=m,m},[]),Rt=o.useCallback(async(m,k)=>{if(ye.current){const J=_e.current;if(J<0||k<J){ye.current=!1,b(!1);return}const te=m.slice(J,k);if(/\s/.test(te)){ye.current=!1,b(!1);return}_e.current=J,B(te),b(!0),ge(0);const K=await Ye();Xe.current=K;const xe=te.toLowerCase();de(K.filter(Z=>!xe||Z.path.toLowerCase().includes(xe)).slice(0,dt));return}const M=za(m,k);if(!M.active){P&&b(!1);return}_e.current=M.start,B(M.query),b(!0),ge(0);const T=await Ye();Xe.current=T;const G=M.query.toLowerCase(),I=T.filter(J=>!G||J.path.toLowerCase().includes(G)).slice(0,dt);de(I)},[P,Ye]),Js=o.useCallback(m=>{const k=m.target.value,M=m.target.selectionStart??k.length;v(k),Rt(k,M);const T=Ia(k,M);T.active?(L||me(),be(T.query),Y(0)):L&&re()},[v,Rt,L,me,be,Y,re]),et=o.useCallback(m=>{const k=N.current,M=x,T=_e.current>=0?_e.current:(k==null?void 0:k.selectionStart)??M.length,G=Math.min(M.length,T+1+q.length),I=`@${m.path} `,J=M.slice(0,T)+I+M.slice(G);Ae.current.add(m.path),v(J),b(!0),B(""),de(Xe.current.slice(0,dt)),ge(0),De(Ae.current.size),_e.current=T+I.length,ye.current=!0,requestAnimationFrame(()=>{k==null||k.focus(),k&&(k.selectionStart=k.selectionEnd=T+I.length)})},[x,q,v]),Le=o.useCallback(()=>{ye.current=!1,b(!1),B(""),De(0)},[]),tt=o.useCallback(m=>{if(!m.args){const I=ee(m,"");I!=null&&I.message&&(I.success?le.success(I.message):le.error(I.message)),v("");return}const k=N.current,M=(k==null?void 0:k.selectionStart)??x.length,T=x.lastIndexOf(`
|
|
28
|
+
`,M-1)+1,G=x.slice(0,T)+`/${m.name} `+x.slice(M);v(G),re(),requestAnimationFrame(()=>{k==null||k.focus();const I=T+m.name.length+2;k&&(k.selectionStart=k.selectionEnd=I)})},[x,v,ee,re]),Ws=o.useCallback(m=>{const k=N.current,M=(k==null?void 0:k.selectionStart)??x.length,T=`$${m.id} `,G=x.slice(0,M)+T+x.slice(M);v(G),R(!1),ye.current=!1,b(!1),B(""),requestAnimationFrame(()=>{k==null||k.focus();const I=M+T.length;k&&(k.selectionStart=k.selectionEnd=I)})},[x,v]),zt=o.useCallback(m=>new Promise((k,M)=>{const T=new FileReader;T.onload=()=>k(String(T.result??"")),T.onerror=()=>M(new Error("Failed to read image")),T.readAsDataURL(m)}),[]),Me=o.useCallback(m=>{const k=Array.from(m);S(M=>{const T=Ge-M.length,G=M.slice();for(const I of k.slice(0,T)){const J=it.test(I.name);if(!J&&!as.test(I.name)){le.warning(l("fileJob.unsupportedType",{name:I.name}));continue}if(I.size>(J?Ea:Ma)){le.error(l("fileJob.fileTooLarge",{name:I.name}));continue}if(G.some(K=>K.name===I.name)){le.warning(l("fileJob.duplicateFile",{name:I.name}));continue}const te={id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,file:I,name:I.name,size:I.size,uploading:!1};J&&zt(I).then(K=>{S(xe=>xe.map(Z=>Z.id===te.id?{...Z,imageDataUri:K}:Z))}).catch(()=>{S(K=>K.filter(xe=>xe.id!==te.id)),le.error(l("fileJob.uploadFailed",{name:I.name}))}),G.push(te)}return G.length>=Ge&&le.warning(l("fileJob.maxAttachments",{n:Ge})),G})},[l,zt]),Gs=o.useCallback(m=>{m.target.files&&m.target.files.length>0&&(Me(m.target.files),m.target.value="")},[Me]),Ks=o.useCallback(async()=>{var m,k;if(Na()){const M=await Sa();if(!M||M.length===0)return;const T=await ue.fileJob.importPaths(M);if(T.success&&Array.isArray(T.data)){const G=T.data.filter(I=>as.test(I.name)||it.test(I.name)).map(I=>({id:`att-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,name:I.name,size:I.size,uploading:!1,path:I.path.replace(/\\/g,"/")}));S(I=>{const J=Ge-I.length;return[...I,...G.slice(0,J)]});for(const I of G.filter(J=>it.test(J.name)))try{const J=sessionStorage.getItem("auth_token")??localStorage.getItem("auth_token"),te={};J&&(te.Authorization=`Bearer ${J}`);const K=await fetch(`/api/files/read?path=${encodeURIComponent(I.path)}&base64=1`,{headers:te});if(K.ok){const xe=await K.json();if((m=xe.data)!=null&&m.base64){const Z=`data:${xe.data.mime??"image/png"};base64,${xe.data.base64}`;S(we=>we.map(ve=>ve.path===I.path?{...ve,imageDataUri:Z}:ve))}}}catch{}}else le.error(T.error||l("fileJob.importFailed"))}else(k=w.current)==null||k.click()},[l]),Zs=o.useCallback(m=>{S(k=>k.filter(M=>M.id!==m))},[]),Vs=o.useCallback(m=>{m.preventDefault(),_(!0)},[]),Xs=o.useCallback(m=>{m.preventDefault(),_(!1)},[]),Qs=o.useCallback(m=>{m.preventDefault(),_(!1),m.dataTransfer.files&&m.dataTransfer.files.length>0&&Me(m.dataTransfer.files)},[Me]),It=o.useCallback(async()=>{var k;if(p.length===0)return"";const m=[];for(const M of p){if(M.imageDataUri)continue;if(M.path){m.push(`<attachment path="${M.path}" />`);continue}if(!M.file)continue;S(I=>I.map(J=>J.id===M.id?{...J,uploading:!0,error:void 0}:J));const T=`${Aa}/${M.name}`,G=await ue.files.upload(M.file,T);if(G.success&&((k=G.data)!=null&&k.path)){const I=G.data.path.replace(/\\/g,"/");S(J=>J.map(te=>te.id===M.id?{...te,uploading:!1,path:I}:te)),m.push(`<attachment path="${I}" />`)}else S(I=>I.map(J=>J.id===M.id?{...J,uploading:!1,error:G.error||l("fileJob.uploadFailed")}:J)),le.error(`${M.name}: ${G.error||l("fileJob.uploadFailed")}`)}return m.length>0?`${m.join(`
|
|
29
|
+
`)}
|
|
30
|
+
|
|
31
|
+
`:""},[p,l]),Ys=o.useCallback(m=>{const k=m.clipboardData.getData("text/plain");if(m.clipboardData.files&&m.clipboardData.files.length>0){m.preventDefault(),Me(m.clipboardData.files);return}if(!k||!ha(k))return;m.preventDefault();const{label:M}=fa(k),T=N.current;if(!T)return;const G=T.selectionStart,I=T.selectionEnd,J=T.value,te=J.slice(0,G)+M+J.slice(I);v(te),requestAnimationFrame(()=>{T.selectionStart=T.selectionEnd=G+M.length})},[v,Me]),Ue=o.useCallback(async()=>{const m=ba(x);ka(ga(m)),ye.current=!1,b(!1),re();const k=m.trim(),M=p.length>0;if(!k&&!M)return;const T=m.trim();if(T.startsWith("/")&&!M){const K=Xn(T);if(K){const xe=C.find(Z=>Z.name===K.command);if(xe){const Z=ee(xe,K.args);Z!=null&&Z.message&&(Z.success?le.success(Z.message):le.error(Z.message)),v(""),S([]),Ae.current=new Set,De(0);return}le.error(l("slashCommands.unknownCommand",{cmd:`/${K.command}`}));return}}const G=Array.from(Ae.current).filter(K=>m.includes(`@${K}`));let I="";if(M){if(p.some(K=>K.uploading)){le.warning(l("fileJob.stillUploading"));return}I=await It()}const J=(I+m).trim();if(!J&&!M)return;const te=p.filter(K=>K.imageDataUri).map(K=>K.imageDataUri);s(J||I.trim(),G.length>0?G:void 0,te.length>0?te:void 0),v(""),S([]),Ae.current=new Set,De(0)},[x,p,s,v,It,l,re,C,ee]),en=o.useCallback(m=>{if(!m.nativeEvent.isComposing){if(P&&ie.length>0){if(m.key==="ArrowDown"){m.preventDefault(),ge(k=>(k+1)%ie.length);return}if(m.key==="ArrowUp"){m.preventDefault(),ge(k=>(k-1+ie.length)%ie.length);return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const k=ie[Ee];k&&(m.preventDefault(),et(k));return}if(m.key==="Escape"){m.preventDefault(),Le();return}}else if(P&&m.key==="Escape"){m.preventDefault(),Le();return}if(L&&H.length>0){if(m.key==="ArrowDown"){m.preventDefault(),ce();return}if(m.key==="ArrowUp"){m.preventDefault(),pe();return}if(m.key==="Enter"&&!m.shiftKey&&!m.ctrlKey&&!m.metaKey){const k=H[Q];k&&(m.preventDefault(),tt(k));return}if(m.key==="Escape"){m.preventDefault(),re();return}}else if(L&&m.key==="Escape"){m.preventDefault(),re();return}if(m.key==="Escape"&&h){m.preventDefault(),g?i():a();return}if(m.key==="Enter"&&(m.ctrlKey||m.metaKey)){m.preventDefault(),Ue();return}m.key==="Enter"&&!m.shiftKey&&(m.preventDefault(),Ue())}},[h,g,Ue,a,i,P,ie,Ee,et,Le,L,H,Q,ce,pe,tt,re]),tn=o.useCallback(()=>{y.current=!0},[]),sn=o.useCallback(()=>{y.current=!1},[]),Tt=Qe>8e3,nn=x.trim().length>0||p.length>0;return e.jsxs("div",{className:"shrink-0 px-3 sm:px-4 pb-3 pt-2 bg-dark-bg",onDragOver:Vs,onDragLeave:Xs,onDrop:Qs,children:[p.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:p.map(m=>{const k=Ra(m.name);return e.jsxs("div",{className:ae("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:l("fileJob.imagePreview")}):m.uploading?e.jsx(Te,{size:13,className:"animate-spin"}):e.jsx(k,{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":l("a11y.close"),children:e.jsx(Ce,{size:11})})]},m.id)})}),$&&e.jsx("div",{className:"mb-2 rounded-2xl border-2 border-dashed border-accent-blue/50 bg-accent-blue/5 py-3 text-center text-xs text-accent-blue",children:l("fileJob.dropHint")}),e.jsxs("div",{className:"relative rounded-2xl border border-dark-border bg-dark-surface shadow-sm transition-all duration-150 focus-within:border-accent-blue/50 focus-within:ring-4 focus-within:ring-accent-blue/10",children:[P&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!P,children:e.jsx(da,{isOpen:P,files:ie,selectedIndex:Ee,query:q,isSearching:Hs,onSelect:et,onHover:ge,selectedCount:Us,onFinish:Le})}),L&&e.jsx("div",{onMouseDown:m=>m.preventDefault(),"aria-hidden":!L,children:e.jsx(Ca,{isOpen:L,commands:H,selectedIndex:Q,filter:oe,onSelect:tt,onHover:Y,containerRef:U})}),e.jsx("textarea",{ref:N,value:x,onChange:Js,onKeyDown:en,onPaste:Ys,onBlur:()=>{P&&Le(),re()},onCompositionStart:tn,onCompositionEnd:sn,placeholder:l(h?"chat.generatingPlaceholder":"chat.inputPlaceholder"),rows:1,disabled:h&&!g,"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:[u&&e.jsx(ca,{workspaceDir:d,onSelect:u}),e.jsx(ra,{}),e.jsx("span",{className:"hidden sm:block",children:e.jsx(aa,{})}),e.jsx("div",{className:"flex-1"}),Qe>0&&x.length>0&&e.jsxs("span",{className:`text-[10px] tabular-nums ${Tt?"text-accent-red font-medium":"text-dark-muted/60"}`,children:["~",Qe," tokens",Tt?` · ${l("chat.nearLimit")}`:""]}),!h&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:E,disabled:D.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:l("stt.langToggle"),"aria-label":l("stt.langToggle"),children:j==="en"?"EN":"中"}),e.jsx("button",{onClick:()=>void ne(),disabled:D.state==="transcribing",className:ae("flex h-8 w-8 items-center justify-center rounded-full text-dark-muted transition-colors",D.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:D.state==="recording"?l("stt.stopTitle"):l("stt.title"),"aria-label":D.state==="recording"?l("stt.stopTitle"):l("stt.title"),children:D.state==="transcribing"?e.jsx(Te,{size:15,className:"animate-spin","aria-hidden":"true"}):D.state==="recording"?e.jsx(Nn,{size:15,"aria-hidden":"true"}):e.jsx(Sn,{size:15,"aria-hidden":"true"})}),D.state==="recording"&&e.jsxs("span",{className:"text-[10px] tabular-nums text-accent-red","aria-hidden":"true",children:[(D.elapsedMs/1e3).toFixed(0),"s"]})]}),!h&&e.jsx("button",{onClick:()=>R(!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:l("skills.pickTitle"),"aria-label":l("skills.pickTitle"),children:e.jsx(Cn,{size:15,"aria-hidden":"true"})}),!h&&e.jsx("button",{onClick:()=>void Ks(),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:l("fileJob.attach"),"aria-label":l("fileJob.attach"),children:e.jsx(En,{size:15,"aria-hidden":"true"})}),e.jsx("input",{ref:w,type:"file",multiple:!0,accept:_a,className:"hidden",onChange:Gs}),h?e.jsxs("div",{className:"flex items-center gap-1.5",children:[g?e.jsx("button",{onClick:i,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:l("chat.resumeGen"),"aria-label":l("chat.resumeGen"),children:e.jsx(_n,{size:14,"aria-hidden":"true"})}):e.jsx("button",{onClick:a,className:"flex h-8 w-8 items-center justify-center rounded-full bg-accent-yellow text-white transition-all hover:opacity-85 active:scale-95",title:l("chat.pauseGen"),"aria-label":l("chat.pauseGen"),children:e.jsx(ps,{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:l("chat.stopGen"),"aria-label":l("chat.stopGen"),children:e.jsx(An,{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:l("chat.sendBtn"),"aria-label":l("chat.sendBtn"),children:e.jsx(fs,{size:15,"aria-hidden":"true"})})]})]}),e.jsxs("div",{className:"mt-1.5 hidden sm:flex items-center justify-center gap-3 text-[10px] text-dark-muted/50 select-none",children:[e.jsx("span",{children:l("chat.shiftEnter")}),e.jsx("span",{"aria-hidden":"true",children:"·"}),e.jsx("span",{children:l("chat.escHint")})]}),e.jsx(ua,{open:A,onClose:()=>R(!1),onSelect:Ws})]})}),ut="其他(我来说明)",je="推进",$a="不选具体项,按你的最佳判断继续",Da=15e3,Pa=300;function qs(r){return o.useMemo(()=>{const t=r.options||[],s=t.some(d=>d.label===ut),n=t.some(d=>d.label===je),a=[...t];n||a.push({label:je,description:$a}),s||a.push({label:ut,description:"输入自定义答案"});const i=s?a.findIndex(d=>d.label===ut):a.length-1,c=n?a.findIndex(d=>d.label===je):a.length-(s?1:2);return{allItems:a,otherIdx:i,proceedIdx:c,displayItems:a}},[r])}function ls({item:r,answered:t,selectedIdx:s,multiSelected:n,customInput:a,showCustomInput:i,onSelect:c,onToggleMulti:d,onProceed:u,onEnterCustom:l,onCancelCustom:x,onSubmitCustom:f,onCustomChange:h,inputRef:g}){const{otherIdx:N,proceedIdx:w,displayItems:y}=qs(r),p=!!r.multiSelect,S=$=>{if($===w){u();return}if($===N){l();return}if(p){d($);return}c($)};return e.jsxs("div",{className:"flex flex-col gap-2 max-h-64 overflow-y-auto",children:[y.map(($,_)=>{const A=s===_,R=n.has(_),v=_===N;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 ${A?"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:()=>S(_),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsx("span",{className:`w-4 h-4 rounded border flex items-center justify-center text-[10px] ${R?"bg-blue-600 border-blue-600 text-white":"border-gray-400 dark:border-gray-500"}`,children:R&&e.jsx(Ie,{size:10})}),e.jsxs("span",{className:`font-medium ${A?"text-blue-700 dark:text-blue-300":"text-gray-800 dark:text-gray-200"}`,children:[p?"":`${_+1}. `,$.label]}),_===w&&e.jsx("span",{className:"text-xs text-emerald-600 dark:text-emerald-400",children:"(直接继续)"}),v&&e.jsx("span",{className:"text-xs text-gray-400",children:"(自定义)"})]}),$.description&&e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5 ml-6",children:$.description})]}),v&&A&&i&&e.jsxs("div",{className:"mt-2 ml-4",children:[e.jsx("textarea",{ref:g,className:"w-full px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none",rows:3,value:a,onChange:j=>h(j.target.value),onKeyDown:j=>{j.key==="Enter"&&!j.shiftKey&&(j.preventDefault(),f()),j.key==="Escape"&&x()},placeholder:"输入您的回答...",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:f,children:[e.jsx(Re,{size:12}),"提交"]}),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(Ce,{size:12}),"取消"]})]})]})]},`opt-${_}`)}),t&&e.jsx("div",{className:"text-xs text-emerald-600 dark:text-emerald-400 font-medium",children:"✓ 已回答"})]})}function La({isOpen:r,onClose:t}){const[s,n]=o.useState(null),[a,i]=o.useState(-1),[c,d]=o.useState(new Set),[u,l]=o.useState(""),[x,f]=o.useState(!1),[h,g]=o.useState(!1),[N,w]=o.useState(0),[y,p]=o.useState([]),[S,$]=o.useState(!1),_=o.useRef(null),A=o.useRef(null),R=o.useMemo(()=>s?s.questions&&s.questions.length>0?s.questions:[{question:s.question,header:s.header,options:s.options,multiSelect:s.multiSelect}]:[],[s]),v=R.length>1,j=o.useCallback(C=>{n(C),i(C.multiSelect?-1:0),d(new Set),l(""),f(!1),g(!1),w(0),$(!1);const U=C.questions&&C.questions.length>0?C.questions:[C];p(U.map(()=>null))},[]);o.useEffect(()=>{A.current=s}),o.useEffect(()=>{if(r){const C=window.__pendingQuestion;C&&j(C)}},[r,j]),o.useEffect(()=>{const C=U=>{var B;const P=U.detail,b=((B=A.current)==null?void 0:B.questionId)??null;if(P&&b&&P!==b)return;const q=b;g(!0),setTimeout(()=>{var de;const ie=((de=A.current)==null?void 0:de.questionId)??null;q&&ie&&ie!==q||(t(),n(null),g(!1))},Pa)};return window.addEventListener("ask-question-dismiss",C),()=>window.removeEventListener("ask-question-dismiss",C)},[t]),o.useEffect(()=>{if(!h)return;const C=setTimeout(()=>g(!1),Da);return()=>clearTimeout(C)},[h]),o.useEffect(()=>{const C=()=>{const U=window.__pendingQuestion;U&&j(U)};return window.addEventListener("ask-question-required",C),()=>window.removeEventListener("ask-question-required",C)},[j]),o.useEffect(()=>{i(0),d(new Set),l(""),f(!1)},[N,S,s]);const O=R[N]||null,{allItems:E,otherIdx:D}=qs(O||{question:""}),F=o.useCallback((C,U)=>{h||!s||(g(!0),se.send({type:"question_answer",sessionId:se.getSessionId()??void 0,data:JSON.stringify({questionId:s.questionId,answer:C,selectedOptions:U})}))},[h,s]),X=o.useCallback(()=>{h||!s||(g(!0),se.send({type:"question_answer",sessionId:se.getSessionId()??void 0,data:JSON.stringify({questionId:s.questionId,answers:R.map((C,U)=>y[U]||{answer:"(用户未回答)"})})}))},[h,s,R,y]),W=o.useCallback((C,U,P)=>{p(b=>{const q=b.slice();return q[C]={answer:U,selectedOptions:P},q}),C<R.length-1?w(C+1):$(!0)},[R.length]),ne=o.useCallback(C=>{if(h||!s)return;const U=E[C];U&&(i(C),F(U.label,[U.label]))},[h,s,E,F]),z=o.useCallback(()=>{if(h||!s||a<0)return;const C=E[a];C&&F(C.label,[C.label])},[h,s,a,E,F]),L=o.useCallback(()=>{if(h||a<0)return;const C=E[a];C&&W(N,C.label,[C.label])},[h,a,E,W,N]),oe=o.useCallback(C=>{if(h)return;const U=E[C];U&&W(N,U.label,[U.label])},[h,E,W,N]),H=o.useCallback(C=>{h||d(U=>{const P=new Set(U);return P.has(C)?P.delete(C):P.add(C),P})},[h]),Q=o.useCallback(()=>{if(h)return;const C=[...c].map(U=>{var P;return((P=E[U])==null?void 0:P.label)||""});v?W(N,C.join(", "),C):F(C.join(", "),C)},[h,c,E,v,W,N,F]),Y=o.useCallback(()=>{h||(v?W(N,je,[je]):F(je,[je]))},[h,v,W,N,F]),ce=o.useCallback(()=>{h||(i(D),f(!0),setTimeout(()=>{var C;return(C=_.current)==null?void 0:C.focus()},100))},[h,D]),pe=o.useCallback(()=>{f(!1),l("")},[]),ee=o.useCallback(()=>{if(h)return;const C=u||"(用户未输入)";v?W(N,C):F(C)},[h,u,v,W,N,F]),me=o.useCallback(()=>{h||!s||(g(!0),se.send({type:"question_answer",sessionId:se.getSessionId()??void 0,data:JSON.stringify({questionId:s.questionId,answers:R.map(()=>({answer:"(cancelled)"}))})}))},[h,s,R]),re=o.useCallback(()=>{if(!h){if(v){if(x){f(!1),l("");return}if(S){$(!1),w(R.length-1);return}me();return}if(x){f(!1),l("");return}F("(cancelled)")}},[h,v,x,S,R.length,me,F]);if(!r||!s)return null;const be=y.filter(C=>!C).length;return e.jsx(ws,{isOpen:r,onClose:re,title:s.header||(v?"批量确认":"请回答"),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"}),"待回答",v?` · ${y.filter(Boolean).length}/${R.length}`:""]}),collapsedSummary:e.jsx("span",{className:"truncate",children:(O==null?void 0:O.question)||s.question}),maxHeight:"50vh",children:v?e.jsxs("div",{className:"flex flex-col gap-4",children:[s.autoResolutionMs&&s.autoResolutionMs>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-1.5",children:["⏱ ",Math.max(1,Math.round(s.autoResolutionMs/1e3)),"s 后未回答将自动按推荐项继续"]}),e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[R.map((C,U)=>{const P=!!y[U],b=!S&&N===U;return e.jsxs("button",{type:"button",onClick:()=>{w(U),$(!1)},className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${b?"bg-blue-600 text-white":P?"bg-emerald-50 dark:bg-emerald-900/20 text-emerald-700 dark:text-emerald-300":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:["Q",U+1," ",P?"✓":""]},`nav-${U}`)}),e.jsx("button",{type:"button",onClick:()=>$(!0),className:`px-2 py-1 rounded-md text-xs font-medium transition-colors ${S?"bg-blue-600 text-white":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:"提交"})]}),S?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:"确认答案"}),R.map((C,U)=>{const P=y[U];return e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed min-w-0",children:[e.jsxs("span",{className:"font-medium",children:[U+1,". "]}),C.question]}),e.jsx("div",{className:`text-xs shrink-0 max-w-[45%] text-right break-words ${P?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dark:text-amber-400"}`,children:P?P.answer:"未回答"})]},`rev-${U}`)}),be>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(Se,{size:14}),"有 ",be," 题未回答,将记为「未回答」。点击上方题号可回到对应题目修改。"]}),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:X,disabled:h,children:[e.jsx(Re,{size:14}),"提交全部答案"]}),e.jsx("button",{type:"button",className:"inline-flex items-center gap-1 px-4 py-2 text-sm font-medium text-gray-600 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 rounded-md hover:bg-gray-200 dark:hover:bg-gray-600",onClick:()=>{$(!1),w(R.length-1)},disabled:h,children:"返回修改"})]})]}):O?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:O.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:()=>{w(C=>Math.max(0,C-1)),$(!1)},disabled:N===0,children:[e.jsx(Rn,{size:12}),"上一题"]}),N<R.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:()=>{w(C=>Math.min(R.length-1,C+1)),$(!1)},children:["下一题",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:()=>$(!0),children:["查看提交",e.jsx(ke,{size:12})]})]})]}),e.jsx(ls,{item:O,answered:!!y[N],selectedIdx:a,multiSelected:c,customInput:u,showCustomInput:x,onSelect:oe,onToggleMulti:H,onProceed:Y,onEnterCustom:ce,onCancelCustom:pe,onSubmitCustom:ee,onCustomChange:l,inputRef:_}),!x&&e.jsx("div",{className:"flex items-center gap-2",children:O.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:Q,disabled:h||c.size===0,children:[e.jsx(Re,{size:14}),"完成本题 (",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:L,disabled:h||a<0,children:[e.jsx(Re,{size:14}),"确认本题"]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:x?e.jsx("span",{children:"Enter 提交,Shift+Enter 换行"}):O.multiSelect?e.jsx("span",{children:"点击选项勾选,再点击「完成本题」提交本题;「推进」表示按 AI 判断继续"}):e.jsx("span",{children:"点击选项完成本题自动进入下一题,或点击「确认本题」提交当前高亮项"})})]}):null]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[s.autoResolutionMs&&s.autoResolutionMs>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-1.5",children:["⏱ ",Math.max(1,Math.round(s.autoResolutionMs/1e3)),"s 后未回答将自动按推荐项继续"]}),e.jsx("div",{className:"text-sm text-gray-700 dark:text-gray-300 leading-relaxed",children:s.question}),e.jsx(ls,{item:R[0],answered:!1,selectedIdx:a,multiSelected:c,customInput:u,showCustomInput:x,onSelect:ne,onToggleMulti:H,onProceed:Y,onEnterCustom:ce,onCancelCustom:pe,onSubmitCustom:ee,onCustomChange:l,inputRef:_}),!x&&e.jsx("div",{className:"flex items-center gap-2",children:s.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:Q,disabled:h||c.size===0,children:[e.jsx(Re,{size:14}),"提交所选 (",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:z,disabled:h||a<0,children:[e.jsx(Re,{size:14}),"提交"]})}),e.jsx("div",{className:"text-xs text-gray-400 dark:text-gray-500",children:h?e.jsx("span",{children:"提交中..."}):x?e.jsx("span",{children:"Enter 提交,Shift+Enter 换行"}):s.multiSelect?e.jsx("span",{children:"点击选项勾选,再点击「提交所选」提交;「推进」表示按 AI 判断继续"}):e.jsx("span",{children:"点击选项立即提交,或点击下方「提交」确认当前选项"})})]})})}const Be=15;function Ba({isOpen:r,onCloseModal:t}){const{t:s}=V("hook"),n=bt(),a=n.pendingApprovals,i=n.autoMode,c=n.setAutoMode,[d,u]=o.useState(0),[l,x]=o.useState(!1),[f,h]=o.useState(Be),[g,N]=o.useState(!0),w=o.useRef(null),y=o.useRef(!1);o.useEffect(()=>{if(a.length!==0){if(i){a.forEach(P=>{se.send({type:"hook_allow",data:JSON.stringify({approvalId:P.approvalId})})}),n.clearApprovals();return}u(P=>Math.min(P,a.length-1))}},[a.length,i]);const p=a[d]??null,S=a.length>0&&p!==null,$=a.length,_=S?$-d-1:0;o.useEffect(()=>{if(!(!S||l||!r||!p))return h(Be),w.current=setInterval(()=>{h(P=>P<=1?(w.current&&clearInterval(w.current),0):P-1)},1e3),()=>{w.current&&clearInterval(w.current)}},[S,l,r,p==null?void 0:p.approvalId]);const A=p?ks(p.toolName,p.askPayload):{level:"MEDIUM",reasonKey:"risk_default"},R=ys[A.level],v=Qn[A.level==="CRITICAL"?"critical":A.level==="HIGH"?"high":A.level==="LOW"?"low":"medium"],j=p?Ts(p.toolName,p.askPayload):null,O=p?Yn(p.toolName,p.askPayload):null,E=p?{verb:zs(p.toolName),target:Is(p.toolName,p.askPayload)}:null,D=p?qe(p.askPayload)!==null:!1,F=p?$s(p.toolName,p.askPayload):null,X=f/Be*100,W=f<=5,ne=tr(Be-f),z=o.useCallback((P,b)=>{const q=er.getState().activeSessionId;q&&he.getState().updateHookApprovalStatus(q,P,b)},[]),L=o.useCallback(P=>{p&&(P&&z(p.approvalId,P),x(!0),setTimeout(()=>{n.removeApproval(p.approvalId),u(0),x(!1),y.current=!1,h(Be)},200))},[p==null?void 0:p.approvalId,n,z]),oe=o.useCallback(()=>{!p||l||y.current||(y.current=!0,w.current&&clearInterval(w.current),se.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId})}),L("approved"))},[p,L,l]),H=o.useCallback(()=>{!p||l||y.current||(y.current=!0,w.current&&clearInterval(w.current),se.send({type:"hook_deny",data:JSON.stringify({approvalId:p.approvalId})}),L("denied"))},[p,L,l]),Q=o.useCallback(()=>{if(!p||l||y.current)return;y.current=!0,w.current&&clearInterval(w.current);const P=qe(p.askPayload);P?(n.addToSessionAllowList(p.toolName,P),se.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId,sessionAllow:!0})})):(n.addToSessionAllowList(p.toolName),se.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId})})),L("approved")},[p,L,n,l]),Y=o.useCallback(()=>{!p||l||y.current||(y.current=!0,w.current&&clearInterval(w.current),c(!0),Ne.getState().setAuto(!0),se.send({type:"hook_allow",data:JSON.stringify({approvalId:p.approvalId})}),L("approved"))},[p,L,l,c]),ce=((p==null?void 0:p.timeoutMs)??15e3)>0,pe=(p==null?void 0:p.timeoutAction)==="deny"?H:oe;if(o.useEffect(()=>{f===0&&r&&!l&&p&&ce&&pe()},[f,r,l,p,pe,ce]),o.useEffect(()=>{if(!r||!g)return;const P=b=>{const q=b.target;q&&typeof q.closest=="function"&&q.closest('input, textarea, select, [contenteditable="true"]')||(b.key==="Escape"?(b.preventDefault(),b.stopPropagation(),H()):b.key==="Enter"?(b.preventDefault(),oe()):b.key==="1"?oe():b.key==="2"?H():b.key==="3"?Q():b.key==="4"&&Y())};return window.addEventListener("keydown",P),()=>window.removeEventListener("keydown",P)},[r,g,oe,H,Q,Y]),!S||!p)return null;const ee=s("optionAllowHint"),me=s("optionDenyHint"),re=D?s("optionAllowPathHint"):s("optionAllowAlwaysHint",{tool:p.toolName}),be=s("optionAutoModeHint"),C=(j==null?void 0:j.text)??O??null,U=C?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:C})]}):null;return e.jsx(ws,{isOpen:r,onClose:()=>t==null?void 0:t(),title:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pt,{className:"w-4 h-4 text-yellow-400"}),e.jsx("span",{children:s("hookApproval")}),e.jsxs("span",{className:"text-xs text-dark-muted",children:["(",d+1,"/",$,")"]})]}),badge:e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold border shrink-0 ${R.badge}`,children:[R.icon," ",A.level]}),collapsedSummary:U,onExpandedChange:N,maxHeight:"50vh",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg ${R.bg} border ${R.border}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-xs font-bold border ${R.badge}`,children:[R.icon," ",A.level]}),e.jsx("span",{className:"text-xs text-dark-muted truncate",children:s(A.reasonKey)}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-auto shrink-0",children:[e.jsx(ze,{size:12,className:W?"text-accent-red":"text-dark-muted"}),e.jsx("span",{className:`text-xs font-mono ${W?"text-accent-red animate-pulse":"text-dark-muted"}`,children:ce?`${f}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 ${W?"bg-accent-red":f<=8?"bg-accent-yellow":"bg-accent-green"}`,style:{width:`${X}%`}})})]})]}),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(pt,{size:15})}),E&&e.jsx(Ds,{pre:s(E.verb),obj:E.target})]}),F&&(F.external&&F.path?e.jsxs("span",{className:"flex items-center gap-1 text-[11px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/30 shrink-0",title:F.path,children:[e.jsx(us,{size:10}),s("scopeExternal"),": ",F.path.length>48?`${F.path.slice(0,47)}…`:F.path]}):e.jsx("span",{className:"text-[11px] text-dark-muted/60 shrink-0",children: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:ne}),e.jsx("span",{className:"text-dark-muted/50",children:v.label}),p.timeoutAction&&e.jsxs("span",{className:`text-xs ${p.timeoutAction==="deny"?"text-accent-red":"text-accent-green"}`,children:["timeout: ",ce?`${p.timeoutAction==="allow"?"auto-allow":"auto-deny"}${p.timeoutMs?` (${(p.timeoutMs/1e3).toFixed(0)}s)`:""}`:s("timeoutWaitUser")]})]}),j?e.jsx(kt,{text:j.text,mono:j.mono}):O?e.jsx(kt,{text:O}):null,(A.level==="CRITICAL"||A.level==="HIGH")&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs px-2 py-1.5 rounded ${R.bg} ${R.text}`,children:[e.jsx(Se,{size:13}),e.jsx("span",{children:A.level==="CRITICAL"?s("highRiskWarning"):s("mediumRiskConfirm")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:oe,disabled:l,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:Je.allow.label}),e.jsx("span",{className:"text-[11px] text-white/70 hidden sm:inline",children:ee})]}),e.jsxs("button",{onClick:Q,disabled:l,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:Je.allow_session.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:re})]}),e.jsxs("button",{onClick:Y,disabled:l,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:Je.auto.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:be})]}),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{onClick:H,disabled:l,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:Je.deny.label}),e.jsx("span",{className:"text-[11px] text-dark-muted/60 hidden sm:inline",children:me})]})]}),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:_>0?s("morePending",{n:_}):s("lastItem")})]})]})})}const Oa=o.memo(function(){const{t}=V(),[s,n]=o.useState(0),[a,i]=o.useState(0),c=o.useCallback(()=>{const d=se.getReconnectState();n(d.reconnecting?d.attempts:0),i(d.maxAttempts)},[]);return o.useEffect(()=>{const d=se.onReconnectAttempt((h,g)=>{n(h),i(g)}),u=se.onReconnectSuccess(()=>{n(0),i(0)}),l=se.onReconnectGiveUp(()=>n(0)),x=se.onClose(c),f=se.onOpen(c);return c(),()=>{d(),u(),l(),x(),f()}},[c]),s<=0?null:e.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-2 text-xs text-accent-yellow bg-accent-yellow/10 border-b border-accent-yellow/20 select-none",role:"status","aria-live":"polite",children:[e.jsx($e,{size:13,className:"animate-spin shrink-0"}),e.jsx("span",{children:t("reconnect.reconnecting",{attempt:s,max:a})}),e.jsx("span",{className:"hidden sm:inline text-[10px] text-accent-yellow/70",children:t("reconnect.hint")})]})}),xt="dsc-auto-access-banner-dismissed",Fa=o.memo(function(){const{t}=V(),s=Ne(d=>d.mode),[n,a]=o.useState(()=>localStorage.getItem(xt)==="1");o.useEffect(()=>{gt(s==="normal"?"act":s)||localStorage.getItem(xt)==="1"&&a(!1)},[s]);const i=o.useCallback(d=>{d&&localStorage.setItem(xt,"1"),a(!0)},[]);return!(s!=="normal"&>(s))||n?null:e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2 text-[11px] leading-snug text-accent-yellow bg-accent-yellow/10 border-b border-accent-yellow/20 select-none",role:"note",children:[e.jsx(zn,{size:14,className:"shrink-0 mt-0.5 text-accent-yellow"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"font-medium",children:t("autoAccess.title")}),e.jsxs("span",{className:"text-accent-yellow/80",children:[" ",t("autoAccess.desc")]})]}),e.jsx("button",{onClick:()=>i(!1),className:"shrink-0 rounded p-0.5 text-accent-yellow/70 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors",title:t("autoAccess.dismiss"),"aria-label":t("autoAccess.dismiss"),children:e.jsx(Ce,{size:12})}),e.jsx("button",{onClick:()=>i(!0),className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] text-accent-yellow/70 hover:text-accent-yellow hover:bg-accent-yellow/10 transition-colors whitespace-nowrap",children:t("autoAccess.neverShow")})]})}),is=24,cs=240,qa={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"}},Ha=({status:r})=>r==="running"?e.jsx(Te,{size:12,className:"animate-spin text-accent-blue"}):r==="completed"?e.jsx(mt,{size:12,className:"text-accent-green"}):r==="failed"?e.jsx(Dn,{size:12,className:"text-accent-red"}):r==="skipped"?e.jsx(Pn,{size:12,className:"text-dark-muted"}):e.jsx(Ln,{size:12,className:"text-dark-muted"}),Ua=o.memo(function({sessionId:t,defaultExpanded:s,onClose:n}){const{t:a}=V(),[i,c]=o.useState(s??!1),[d,u]=o.useState(null),l=vs(E=>E.getTasksForSession(t)),[x,f]=o.useState(null),h=o.useRef(null),g=o.useRef(!1),N=o.useRef(null),w=o.useCallback(E=>{var D;E.button===0&&(E.target.closest("[data-taskboard-close]")||(g.current=!1,h.current={y:E.clientY,expanded:i,bodyHeight:((D=N.current)==null?void 0:D.offsetHeight)??0},E.currentTarget.setPointerCapture(E.pointerId)))},[i]),y=o.useCallback(E=>{const D=h.current;D&&(Math.abs(E.clientY-D.y)>4&&(g.current=!0),f(E.clientY-D.y))},[]),p=o.useCallback(E=>{const D=h.current;if(!D)return;const F=E.clientY-D.y;D.expanded&&F<-is?c(!1):!D.expanded&&F>is&&c(!0),h.current=null,f(null),setTimeout(()=>{g.current=!1},0)},[]),S=o.useCallback(()=>{if(g.current){g.current=!1;return}c(E=>!E)},[]),$=o.useCallback(E=>{(E.key==="Enter"||E.key===" ")&&(E.preventDefault(),c(D=>!D))},[]),_=x!==null,A=o.useMemo(()=>{const E=h.current;return x===null||!E?null:E.expanded?Math.min(cs,Math.max(0,E.bodyHeight+x)):Math.min(cs,Math.max(0,x))},[x]),R=o.useMemo(()=>{const E=l.length,D=l.filter(ne=>ne.status==="completed").length,F=l.filter(ne=>ne.status==="running").length,X=l.filter(ne=>ne.status==="failed").length,W=E>0?Math.round(D/E*100):0;return{total:E,completed:D,running:F,failed:X,progress:W}},[l]),v=o.useMemo(()=>{const E={pending:[],running:[],completed:[],failed:[]};return l.forEach(D=>{const F=D.status==="skipped"?"pending":D.status;E[F].push(D)}),E},[l]),j=[...v.running,...v.failed,...v.pending.slice(0,5),...v.completed.slice(-3)],O=i||_;return l.length===0?null:e.jsxs("div",{className:"w-full shrink-0 mb-2 border border-dark-border rounded-lg bg-dark-bg/70 overflow-hidden",children:[e.jsxs("div",{role:"button",tabIndex:0,"aria-expanded":i,onClick:S,onKeyDown:$,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:a("chat.taskBoardDragHint"),children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(In,{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:[R.completed,"/",R.total]}),R.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 ${R.running>0?"bg-accent-blue":R.failed>0?"bg-accent-red":"bg-accent-green"}`,style:{width:`${R.progress}%`}})}),R.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:E=>{E.stopPropagation(),n()},onKeyDown:E=>{E.key==="Enter"&&(E.stopPropagation(),n())},className:"p-0.5 rounded hover:bg-dark-hover transition-colors cursor-pointer",title:"Hide task drawer",children:e.jsx(Ce,{size:12,className:"text-dark-muted"})}),e.jsx(Tn,{size:12,className:"text-dark-muted/40 shrink-0","aria-hidden":"true"}),i?e.jsx($n,{size:14,className:"text-dark-muted"}):e.jsx(fe,{size:14,className:"text-dark-muted"})]})]}),O&&e.jsx("div",{ref:N,className:"border-t border-dark-border",style:A!==null?{height:A,overflow:"hidden"}:void 0,children:l.length===0?e.jsx("div",{className:"text-xs text-dark-muted py-4 text-center",children:a("chat.noTasks")}):e.jsxs("div",{className:"px-2.5 py-2 max-h-[240px] overflow-y-auto custom-scrollbar space-y-1.5",children:[j.map(E=>e.jsx(Wa,{task:E,isSelected:E.id===d,onClick:()=>u(d===E.id?null:E.id)},E.id)),v.pending.length>5&&e.jsxs("div",{className:"text-[10px] text-dark-muted text-center",children:[v.pending.length-5," more pending tasks"]}),v.completed.length>3&&e.jsxs("div",{className:"text-[10px] text-dark-muted text-center",children:[v.completed.length-3," more completed tasks"]})]})})]})}),Ja=(r,t)=>{if(!r)return"";const s=(t||Date.now())-r;return s<1e3?`${s}ms`:`${(s/1e3).toFixed(1)}s`},Wa=o.memo(function({task:t,isSelected:s,onClick:n}){const a=qa[t.status];return e.jsxs("div",{onClick:n,className:`rounded border p-2 cursor-pointer transition-all ${a.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(Ha,{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] ${a.color} shrink-0`,children:a.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:Ja(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"]})]})]})}),Ya=o.memo(function({tabs:t,activeSessionId:s,onSend:n,onStop:a,onPause:i,onResume:c,activeTab:d,setActiveTab:u,createNewSession:l,clearMessages:x,setTheme:f,setThemePreset:h,toggleTerminal:g,setLogs:N,setUnreadLogs:w,showTaskBoard:y=!0,onToggleTaskBoard:p,onRegenerate:S,onDeleteMessage:$,hookDrawerOpen:_,onCloseHookDrawer:A,questionDrawerOpen:R,onCloseQuestionDrawer:v,workspaceDir:j,onWorkspaceSelect:O}){const E=o.useMemo(()=>({setActiveTab:u,createNewSession:l,clearMessages:x,setTheme:f,setThemePreset:h,toggleTerminal:g,setLogs:N,setUnreadLogs:w}),[u,l,x,f,h,g,N,w]),D=he(H=>s?H.messagesBySession[s]||[]:[]),F=he(H=>s?H.generatingSessions.includes(s):!1),X=he(H=>s?H.pausedSessions.includes(s):!1),W=t.find(H=>H.id===s)||null;o.useEffect(()=>{if(!s)return;let H=!1;return ue.tasks.list(s).then(Q=>{if(H||!Q.success||!Array.isArray(Q.data))return;const Y={PENDING:"pending",RUNNING:"running",COMPLETED:"completed",FAILED:"failed",CANCELLED:"skipped"},ce=Date.now(),pe=Q.data.filter(ee=>ee.sessionId===s).map(ee=>{const me=new Date(ee.createdAt).getTime()||ce,re=new Date(ee.updatedAt).getTime()||ce;return{id:ee.id,sessionId:s,title:ee.title,status:Y[ee.status]||"pending",source:"task",description:ee.description,progress:ee.progress,createdAt:me,updatedAt:re,raw:ee}});vs.getState().setTasks(s,pe,"task")}).catch(()=>{}),()=>{H=!0}},[s]);const ne=o.useCallback((H,Q)=>{s&&n(s,H,Q)},[n,s]),z=o.useCallback(H=>{s&&n(s,H)},[n,s]),L=o.useCallback(H=>{s&&S&&S(s,H)},[S,s]),oe=o.useCallback(H=>{s&&$&&$(s,H)},[$,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(Oa,{}),e.jsx(Fa,{}),W&&e.jsxs(e.Fragment,{children:[e.jsx(sa,{messages:D,isGenerating:F,isPaused:X,sessionId:W.id,onSendSuggestion:z,onRegenerate:S?L:void 0,onDeleteMessage:$?oe:void 0}),e.jsx(Ba,{isOpen:!!_,onCloseModal:A}),e.jsx(La,{isOpen:!!R,onClose:v??(()=>{})}),y&&e.jsx(Ua,{sessionId:W.id,defaultExpanded:!1,onClose:p},W.id),e.jsx(Ta,{sessionId:W.id,onSend:ne,onStop:()=>a(W.id),onPause:()=>i(W.id),onResume:()=>c(W.id),slashOptions:E,workspaceDir:j,onWorkspaceSelect:O})]})]})})});export{Ya as SessionGrid};
|