filecat 7.18.3 → 7.18.4
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/build/dist/{6104.b8465719e94a508b1416.js → 6104.05cd833b0fa8c283023e.js} +1 -1
- package/build/dist/6805.c5a415cdd8bcf6b813fe.js +1 -0
- package/build/dist/{8358.f71f82878c562d287576.js → 8358.cab702ca92cb80296799.js} +1 -1
- package/build/dist/index.html +1 -1
- package/build/dist/main.ac18f0f730d3d5f082a5.js +2 -0
- package/build/main.js +1 -1
- package/package.json +1 -1
- package/build/dist/6805.4308dfd0c659c7f78b61.js +0 -1
- package/build/dist/main.6327c5b7bf19bc5d86ff.js +0 -2
- /package/build/dist/{main.6327c5b7bf19bc5d86ff.js.LICENSE.txt → main.ac18f0f730d3d5f082a5.js.LICENSE.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[6010,6104],{83277(e,s,t){t.d(s,{$j:()=>o,CP:()=>a,Lv:()=>n,cL:()=>i});class n{token;open=!1;note;index;url;model;request_type;json_params;sys_prompt;dotenv="";yaml_env="";tool_mode=!1;show_options;static get_label_by_v(e,s){if(!e||!s?.length)return e;for(const t of s)if(t.value===e)return t.label;return e}static have_label_by_v(e,s){if(!e||!s?.length)return!1;for(const t of s)if(t.value===e)return!0;return!1}}const a="\n# 聊天循环最大次数\ntool_call_max: 500\n\n# 是否允许AI直接执行命令而不需要用户确认。\n# 默认为 false,需要用户手动确认;使用 workflow 时等价于 true。\nallow_exec_cmd_directly: false\n\n# 可选的大模型请求代理地址\n# proxy_url: http://127.0.0.1:7890\n\n# 可选的多个 url\n# options_agent_url_list:\n# - value: http://...\n# label: openai\n\n# 可选的多个 key\n# options_agent_key_list:\n# - value: sk-aaa\n# label: option1\n\n# 可选的多个 model\n# options_agent_model_list:\n# - value: gpt-5.5\n# label: gpt\n\n# 本地 prompt 文件列表,每次聊天时自动读取并加载\n# options_local_file_path_prompt_list:\n# - /prompt/a.txt\n\n# 开启切换模型,AI 可以根据 prompt 自己决定下一步调用哪个模型\n# open_pick_model: false\n\n# 历史消息裁剪相关\nmax_recent_messages: 12\ncompress_message_count: 16\nmax_tool_content_chars: 200\n\n# ===== 模型类型(request_type)=====\n# 默认 completions,可选值:\n# completions 标准对话/聊天补全 (chat/completions)\n# images 图片生成 (images/generations)\n# audio_speech 文本转语音 (audio/speech)\n# audio_transcription 语音转文字 (audio/transcriptions)\n# audio_translation 语音翻译 (audio/translations)\n# embeddings 向量嵌入 (embeddings)\n# request_type: completions\n\n# ===== 成为 tool(tool_mode)=====\n# 开启后该模型会作为一个工具被加载,供 AI agent 动态调用。\n# 注意:不能与「是否开启」(open) 同时为 true。\n# tool_mode: false\n\n# ===== 图片理解(image_understanding)=====\n# 开启后注册 read_image 工具,工具读到的图片会以 image_url 多模态格式随消息发给模型。\nimage_understanding: true\n\n# ===== 命令环境变量(command_env)=====\n# AI 调用内置命令工具(exec_cmd / exec_cmd_background)执行命令时,\n# 这里配置的变量会覆盖到子进程的环境变量上。\n# command_env:\n# NODE_ENV: production\n# HTTP_PROXY: http://127.0.0.1:7890\n\n# 是否允许 AI 通过 set_command_env 工具修改上面的 command_env\ncommand_env_tool: false\n";const i=JSON.stringify({stream:!0,thinking:{type:"disabled"}});function o(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>"text"===e.type?e.text:"[图片]").join("\n"):""}},69857(e,s,t){t.r(s),t.d(s,{default:()=>le});var n=t(96540),a=t(34843),i=t(22022),o=t(52671),c=t(14284),r=t(7463),l=t(78247),d=t(53459),u=t(72693),m=t(82893),g=t(61443),h=t(83277);function _(e){return null==e||e<0?"0":e.toLocaleString()}var p=t(14944),f=t(92275),x=t(62042);function v(e){const s=[];if(e.attachments?.length&&s.push(e.attachments.map(e=>`[附件] ${e.name}`).join("\n")),e.content_list?.length)for(const t of e.content_list){const e=(0,h.$j)(t.content);if(e&&s.push(e),t.tool_call_ends?.length){const e=t.tool_call_ends.map(e=>{const s=e.tool_display_name||e.tool_name;return e.success?`[工具] ${s} 成功`:`[工具] ${s} 失败`});s.push(e.join("\n"))}}return e.text&&!s.length&&s.push(e.text),e.images?.length&&s.push(`[生成图片 ${e.images.length} 张]`),e.audio&&s.push("[音频]"),s.join("\n\n")}function j(e){const s=(0,h.$j)(e.content);if(s)return s;const t=e.content_list??[];return t.length?t.map(e=>(0,h.$j)(e.content)).filter(Boolean).join("\n\n"):""}let b=0;function w(){return-++b}function y(e=[]){let s=0;return e.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({id:++s,sender:"assistant"===e.role?"bot":"user",text:j(e),attachments:e.attachments??[],content_list:e.content_list??(e.tool_call_ends?.length?[{tool_call_ends:e.tool_call_ends,content:j(e),role:"assistant"}]:void 0),images:e.images,audio:e.audio,embeddings:e.embeddings,elapsed_ms:e.elapsed_ms}))}const S=/\.(md|txt|json|js|jsx|ts|tsx|css|html?|xml|ya?ml|py|java|go|rs|c|cpp|h|hpp|sh|bat|cmd|ini|toml|csv|log|sql|env|gitignore|dockerfile)$/i;function N(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||S.test(e.name)?"text":"binary"}function k(e){return e.text()}function C(e){return new Promise((s,t)=>{const n=new FileReader;n.onload=()=>s(n.result),n.onerror=t,n.readAsDataURL(e)})}async function A(e){const s=[];for(const t of e){const e=N(t);let n="";if("text"===e)try{const e=await k(t),s=12e4;n=e.length>s?`${e.slice(0,s)}\n\n[内容已截断,原始长度 ${e.length} 字符]`:e}catch{n="[文本读取失败]"}else if("image"===e)try{n=await C(t)}catch{n=`[图片文件: ${t.name}]`}else n=`[二进制文件: ${t.name}]`;s.push({name:t.name,mime_type:t.type,size:t.size,kind:e,content:n})}return s}function M(e){return"bot"!==e.sender||!!(e.text||e.content_list?.length||e.attachments?.length)}var I=t(21499),$=t(64694),R=t(45907),B=t(74848);var T=t(40505);function D(e){const{active_session_id_ref:s,local_owner_ref:t,subscribed_ref:a,set_messages:i,scroll_to_bottom:o,follow_ref:c,mark_session_running:r,refresh_sessions:l,reload_session:d,set_active_session_running:u}=e,m=(0,n.useRef)(new Map);return(0,n.useEffect)(()=>{const e=()=>s.current,n=(s,n)=>{if(r(s,!1),e()&&e()===s){if(m.current.clear(),u(!1),a.current===s&&(p.ws.sendData(f.HK.ai_chat_subscribe,{session_id:s,subscribe:!1}),a.current=null),t.current===s)return void(t.current=null);n?.length?i(e=>{let s=e.length;for(;s>0&&"bot"===e[s-1].sender;)s--;return[...e.slice(0,s),...y(n)].map((e,s)=>({...e,id:s+1}))}):d(s).catch(()=>{})}l()},g=s=>{const n=s?.context||{};n.session_id&&(((s,n,a,r,l=0)=>{e()&&e()===s&&t.current!==s&&i(e=>{const s=m.current,t=r?-(l+1):l;let i=e;if(!r){const e=-(l+1),t=s.get(e);void 0!==t&&(i=i.filter(e=>e.id!==t),s.delete(e))}const d=s.get(t),u=void 0===d?-1:i.findIndex(e=>e.id===d),g=-1===u?{id:w(),sender:"bot",text:""}:{...i[u]};if(-1===u&&s.set(t,g.id),r)g.text=n,g.is_loading=!0;else if(n){g.text=g.text+n;const e=g.content_list?.[0];e&&(e.content=g.text),g.is_loading=!1}if(a&&(g.content_list=[{tool_call_ends:a,content:g.text,role:"assistant"}],g.is_loading=!1),c.current&&requestAnimationFrame(()=>o()),-1===u)return[...i,g];const h=i.slice();return h[u]=g,h})})(n.session_id,n.text||"",n.tool_call_ends,n.notice,n.chunk_index),r(n.session_id,!0))},h=e=>{const s=e?.context||{};s.session_id&&n(s.session_id,s.once_messages_list)},_=e=>{const s=e?.context||{};s.session_id&&n(s.session_id,s.once_messages_list)};return p.ws.addMsg(f.HK.ai_chat_msg,g),p.ws.addMsg(f.HK.ai_chat_end,h),p.ws.addMsg(f.HK.ai_chat_error,_),()=>{p.ws.off_message(`message_${f.HK.ai_chat_msg}`,g),p.ws.off_message(`message_${f.HK.ai_chat_end}`,h),p.ws.off_message(`message_${f.HK.ai_chat_error}`,_),a.current&&(p.ws.sendData(f.HK.ai_chat_subscribe,{session_id:a.current,subscribe:!1}),a.current=null)}},[]),{chunkBubbleRef:m,bind_live_bubbles:(e,s)=>{m.current.clear();for(let t=0;t<s;t++){const n=e[e.length-s+t];n&&m.current.set(t,n.id)}},clear_bubbles:()=>m.current.clear()}}var H=t(85997),E=t(34299);function V(e){const s=e.attachments&&e.attachments.length>0?(0,B.jsx)("div",{className:"chat-message-attachments",children:e.attachments.map((e,s)=>(0,B.jsxs)("div",{className:"chat-message-attachment",children:[(0,B.jsx)(H.In,{icon:"attach_file"}),(0,B.jsx)("span",{children:e.name}),(0,B.jsxs)("small",{children:[e.size," B"]})]},`${e.name}_${s}`))}):null,t=[];e.images&&"bot"===e.sender&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(P,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(L,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(F,{embeddings:e.embeddings,text:e.text})},"embeddings"));const a=function(e){if("bot"!==e.sender||!e.content_list?.length)return e.text?(0,B.jsx)(E.default,{context:e.text}):null;return(0,B.jsxs)(B.Fragment,{children:[e.content_list.map((e,s)=>{const t=[],a=(0,h.$j)(e.content);return a&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(E.default,{context:a})},`content-${s}`)),e.tool_call_ends?.length&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(K,{callList:e.tool_call_ends})},`tool-${s}`)),(0,B.jsx)(n.Fragment,{children:t},`part-${s}`)}),!e.content_list.some(e=>e.content)&&e.text?(0,B.jsx)(E.default,{context:e.text}):null]})}(e);return 0===t.length?(0,B.jsxs)(B.Fragment,{children:[s,a]}):(0,B.jsxs)(B.Fragment,{children:[t,s,a]})}function K({callList:e}){const[s,t]=n.useState(!1);if(!e?.length)return null;e.filter(e=>e.success).length;const a=e.filter(e=>!e.success).length;return(0,B.jsxs)("div",{className:"chat-message-call-list",children:[(0,B.jsxs)("div",{className:"call-list-header",onClick:()=>t(!s),children:[(0,B.jsx)(H.In,{icon:s?"expand_less":"expand_more"}),(0,B.jsxs)("span",{className:"call-list-summary",children:["工具调用 (",e.length,")",a>0&&(0,B.jsx)("span",{className:"call-list-fail",children:" 失败 "})]})]}),s&&(0,B.jsx)("div",{className:"call-list-body",children:e.map((e,s)=>(0,B.jsxs)("div",{className:"call-list-item "+(e.success?"call-success":"call-fail"),children:[(0,B.jsxs)("div",{className:"call-list-item-header",children:[(0,B.jsx)(H.In,{icon:e.success?"check_circle":"error"}),(0,B.jsx)("span",{className:"call-list-tool-name",children:e.tool_display_name||e.tool_name}),(0,B.jsxs)("span",{className:"call-list-duration",children:[e.duration_ms,"ms"]})]}),e.tool_args&&(0,B.jsxs)("details",{className:"call-list-details",children:[(0,B.jsx)("summary",{children:"参数"}),(0,B.jsx)("pre",{className:"call-list-pre",children:JSON.stringify(e.tool_args,null,2)})]}),!e.success&&e.error&&(0,B.jsxs)("details",{className:"call-list-details",children:[(0,B.jsx)("summary",{children:"错误"}),(0,B.jsx)("pre",{className:"call-list-pre call-list-error-text",children:e.error})]}),e.success&&e.tool_result&&(0,B.jsxs)("details",{className:"call-list-details",children:[(0,B.jsx)("summary",{children:"结果"}),(0,B.jsx)("pre",{className:"call-list-pre",children:e.tool_result.length>500?e.tool_result.slice(0,500)+"...":e.tool_result})]})]},s))})]})}function P({images:e,text:s}){let t=e||[];if(!t.length&&s)try{t=JSON.parse(s).data||[]}catch{}return t.length?(0,B.jsxs)("div",{className:"image-generation-result",children:[t.map((e,s)=>(0,B.jsxs)("div",{className:"image-generation-item",children:[e.url&&(0,B.jsx)("div",{className:"image-generation-image-wrapper",children:(0,B.jsx)("img",{src:e.url,alt:e.revised_prompt||`生成的图片 ${s+1}`,loading:"lazy"})}),e.b64_json&&(0,B.jsx)("div",{className:"image-generation-image-wrapper",children:(0,B.jsx)("img",{src:`data:image/png;base64,${e.b64_json}`,alt:`生成的图片 ${s+1}`})}),e.revised_prompt&&(0,B.jsx)("p",{className:"image-generation-prompt",children:(0,B.jsx)("small",{children:e.revised_prompt})})]},s)),s&&!e&&(0,B.jsx)(E.default,{context:s})]}):(0,B.jsx)(E.default,{context:s||""})}function L({audio:e,text:s}){if(e){if(e.url)return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:e.url,children:"您的浏览器不支持音频播放"})});if(e.data){const s=e.mime_type||"audio/mpeg";return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:`data:${s};base64,${e.data}`,children:"您的浏览器不支持音频播放"})})}}const t=s||"";if(t.startsWith("http://")||t.startsWith("https://"))return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:t,children:"您的浏览器不支持音频播放"})});try{const e=JSON.parse(t);if(e?.data||e?.audio_data){const s=e.data||e.audio_data;return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:`data:audio/mpeg;base64,${s}`,children:"您的浏览器不支持音频播放"})})}}catch{}return(0,B.jsx)(E.default,{context:t})}function z({content:e,label:s}){const[t,a]=n.useState(!1);return(0,B.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,T.lW)(e),a(!0),setTimeout(()=>a(!1),1500)},children:[(0,B.jsx)(H.In,{icon:t?"check":"content_copy"}),t?"已复制":s||"复制"]})}function F({embeddings:e,text:s}){let t=e||null;if(!t&&s)try{t=JSON.parse(s)}catch{return(0,B.jsx)(E.default,{context:s})}if(!t)return(0,B.jsx)(E.default,{context:s||""});const n=t?.data||[],a=t?.usage,i=JSON.stringify(t,null,2);return(0,B.jsxs)("div",{className:"embeddings-result",children:[(0,B.jsxs)("div",{className:"embeddings-summary",children:[(0,B.jsx)("strong",{children:"向量嵌入结果"}),(0,B.jsxs)("span",{children:["维度: ",n[0]?.embedding?.length??"N/A"]}),(0,B.jsxs)("span",{children:["数量: ",n.length]}),a&&(0,B.jsxs)("span",{children:["使用 tokens: ",a.total_tokens??"N/A"]})]}),(0,B.jsxs)("div",{className:"embeddings-toolbar",children:[(0,B.jsx)(z,{content:i,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,B.jsx)(z,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,B.jsx)(z,{content:JSON.stringify(n.map(e=>e.embedding),null,2),label:"复制所有向量数据"})]}),n.length>0&&n[0]?.embedding&&(0,B.jsx)("div",{className:"embeddings-preview",children:(0,B.jsxs)("span",{children:["向量预览: [",n[0].embedding.slice(0,5).join(", "),n[0].embedding.length>5?", ...":"","]"]})}),n.length>0&&(0,B.jsxs)("details",{children:[(0,B.jsx)("summary",{children:"查看详细数据"}),(0,B.jsx)("pre",{className:"embeddings-raw",children:i})]})]})}async function O(e,s,t,n){try{switch(e){case"images":{const e=await async function(e,s){const t={prompt:e,session_id:s},n=await c.jV.post("images/generations",t);if(0!==n.code)throw new Error(n.message||"图片生成失败");const a=n.data||{},i=(a.data||[]).map(e=>({url:e.url,b64_json:e.b64_json,revised_prompt:e.revised_prompt})),o=i.map((e,s)=>`${e.revised_prompt?`\n> ${e.revised_prompt}`:""}`).join("\n\n");return{session_id:a.session_id||s,images:i,text:o||`生成了 ${i.length} 张图片`}}(s,t);return e&&n(e.text,{images:e.images}),!0}case"audio_speech":{const e=await async function(e,s){const t={input:e,session_id:s};try{const e=localStorage.getItem("ai_audio_extra_params");if(e){const s=JSON.parse(e);s.voice&&(t.voice=s.voice),s.speed&&(t.speed=parseFloat(s.speed))}}catch{}const n=localStorage.getItem("token")||"",a=await fetch("/api/ai_agent/audio/speech",{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(t)});if(!a.ok)throw new Error(`语音合成失败: ${a.statusText}`);const i=a.headers.get("X-Session-Id")||s,o=await a.arrayBuffer();return{session_id:i,audio:{data:btoa(String.fromCharCode(...Array.from(new Uint8Array(o)))),mime_type:a.headers.get("content-type")||"audio/mpeg"},text:`[音频文件: ${e.slice(0,50)}...]`}}(s,t);return e&&n(e.text,{audio:e.audio}),!0}case"embeddings":{const e=await async function(e,s){const t=await c.jV.post("embeddings",{input:e,session_id:s});if(0!==t.code)throw new Error(t.message||"Embeddings 请求失败");const n=t.data||{},a=n?.data??[],i=`向量维度: ${a[0]?.embedding?.length??0}, 数量: ${a.length}`;return{session_id:n.session_id||s,embeddings:n,text:`✅ Embeddings 结果 - ${i}\n\`\`\`json\n${JSON.stringify(n,null,2).slice(0,2e3)}\n\`\`\``}}(s,t);return e&&n(e.text,{embeddings:e.embeddings}),!0}default:return!1}}catch(e){return n(`请求失败: ${e?.message||JSON.stringify(e)}`),!0}}var q=t(4412),U=t(23430),G=t(87361),J=t(80389),W=t(7523),Q=t(23496);const X=({currentModelName:e,setCurrentModelName:s,modelGroups:t,onModelChanged:r,batchMode:u,selectedMsgCount:h,sessionVisible:_,onToggleSessionPanel:p,onCreateSession:f,onToggleBatchMode:v,onBatchDeleteMessages:j,bgProcessVisible:b,bgProcessCount:w,onToggleBgProcess:y,inline:S})=>{const{t:N}=(0,i.Bd)(),k=(0,o.Zp)(),{check_user_auth:C}=(0,l.MH)(),[,A]=(0,a.fp)(m.AG.ai_session_collapsed),{open:M}=function(){const{t:e}=(0,i.Bd)(),[,s]=(0,a.fp)(m.AG.prompt_card),[t,o]=(0,a.fp)(m.AG.ai_chat_zoom),{initUserInfo:r}=(0,n.useContext)(W.F);return{open:()=>{const n=t,a=()=>s({open:!1});s({open:!0,title:e("缩放调整"),context_div:(0,B.jsx)(J.p,{defaultValue:t,onChange:o,min:30,max:200}),cancel:()=>{o(n),a()},confirm:async()=>{let s=100;o(e=>(s=e<30||e>200?100:e,s)),await c.wm.post(Q.s.user_save_private_attr,{is_ai_chat_zoom:!0,ai_chat_zoom:s}),(0,x.SK)(e("缩放调整成功")),r(),a()}})}}}(),I=C(U.oV.ai_model_switch)||C(U.oV.ai_agent_setting),$=[];for(const e of t)for(const s of e.models)$.push({title:s.label||s.value,value:`${e.index}::${s.value}`,group:e.note});const R=t.find(e=>e.active),T=R?`${R.index}::${e}`:"",D=(0,B.jsxs)(n.Fragment,{children:[(0,B.jsx)(H.rA,{icon:"menu",title:N("会话"),onClick:p,selected:_}),(0,B.jsx)(H.rA,{icon:"add",title:N("新会话"),onClick:()=>f()}),I&&$.length>0&&(0,B.jsx)(g.l6,{value:T,options:[{title:N("选择模型"),value:""},...$],margin:"0 0 0 1em",onChange:e=>{const t=String(e??"");if(!t.includes("::"))return;const[n,...a]=t.split("::"),i=a.join("::");i&&(s(i),c.jV.post("set_active_model",{index:Number(n),model_name:i}).then(e=>{e?.code===d.m.Success?((0,x.SK)("success"),r()):(0,x.zN)(e?.message||"fail")}).catch(console.error))},no_border:!0,width:"auto"}),u&&(0,B.jsx)(H.rA,{icon:"done",title:N("完成"),onClick:v}),u&&h>0&&(0,B.jsx)(H.rA,{icon:"delete",title:N("删除选中消息"),onClick:j}),(0,B.jsx)(H.rA,{icon:"zoom_in",title:N("缩放调整"),onClick:M}),(0,B.jsx)(H.rA,{icon:"terminal",title:N("后台进程"),onClick:y,selected:b,tip:w||null}),C(U.oV.ai_agent_setting)&&(0,B.jsx)(H.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{k(G.o.ai_rebot_setting_page)}}),C(U.oV.ai_agent_setting)&&(0,B.jsx)(H.rA,{icon:"settings",title:"ai setting",onClick:()=>{k(G.o.ai_agent_setting_page)}})]});return S?(0,B.jsx)("div",{className:"chat-inline-header",children:D}):(0,B.jsx)(q.aZ,{position:"right",children:D})};var Y=t(75725);function Z({items:e}){const s=e.filter(e=>!!e.text);return 0===s.length?null:(0,B.jsx)("div",{className:"chat-session-meta",children:s.map((e,s)=>(0,B.jsx)("small",{className:e.className,title:e.title,children:e.text},s))})}function ee(e){return e||"新会话"}function se({sessions:e,activeSessionId:s,onSelectSession:t,onReorderSessions:a,onRenameSession:o,onDeleteSession:c,onToggleCmdAuto:r,onShowUsageStats:l,onShowSessionSetting:d,batchMode:u,selectedSessionIds:m,onToggleSessionSelect:g,onToggleBatchMode:h,onBatchDeleteSessions:_,onClearAllSessions:p,allUsersMode:f,onToggleAllUsersMode:x,showAllUsersEntry:v,sysPromptList:j,onChangeSysPrompt:b}){const{t:w}=(0,i.Bd)(),[y,S]=(0,n.useState)(""),N=(0,n.useRef)(null),[k,C]=(0,n.useState)(null),[A,M]=(0,n.useState)(null),[I,$]=(0,n.useState)(null),R=!!a&&!f,T=e=>{if(!e)return"";const s=j?.find(s=>String(s.index)===String(e));return s?s.note||s.prompt.slice(0,20):""},D=e=>[{text:String(e.message_count??""),className:"chat-session-meta__count",title:w("消息数")},{text:T(e.sys_prompt_id),className:"chat-session-meta__prompt",title:w("系统提示词")},{text:"web"!==e.source?e.source:"",className:"chat-session-meta__source",title:w("来源")},{text:f&&e.owner_name||"",className:"chat-session-meta__owner",title:e.owner_name}],E=y.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(y.toLowerCase())||(e.summary||"").toLowerCase().includes(y.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(y.toLowerCase())||f&&(e.owner_name||"").toLowerCase().includes(y.toLowerCase())):e,V=e.find(e=>e.id===s);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("aside",{className:"chat-session-list",children:[(0,B.jsxs)("div",{className:"chat-session-search",children:[(0,B.jsx)("input",{type:"text",className:"chat-session-search-input",placeholder:w("搜索会话"),value:y,onChange:e=>S(e.target.value)}),V&&(0,B.jsx)("button",{className:"chat-session-current",title:ee(V.title),onClick:()=>(e=>{const s=()=>{const s=N.current,t=s?.querySelector(`[data-session-id="${e}"]`);t&&t.scrollIntoView({block:"center",behavior:"smooth"})};if(!E.some(s=>s.id===e))return S(""),void requestAnimationFrame(()=>requestAnimationFrame(s));s()})(V.id),children:(0,B.jsx)("span",{children:ee(V.title)})})]}),(0,B.jsx)("div",{className:"chat-session-items-wrap",ref:N,children:E.map((e,n)=>(0,B.jsx)("div",{"data-session-id":e.id,children:(0,B.jsxs)("button",{className:`chat-session-item ${s===e.id?"active":""} ${u?"batch-mode":""} ${e.running?"is-running":""} ${k===n?"row-dragging":""} ${A===n&&null!==k&&k!==n?"row-drop-target":""}`,draggable:R,onDragStart:()=>C(n),onDragOver:e=>{null!==k&&(e.preventDefault(),A!==n&&M(n))},onDragEnd:()=>{C(null),M(null)},onDrop:e=>{e.preventDefault(),(e=>{const s=k;if(C(null),M(null),null===s||s===e||!a)return;const t=E[s]?.id,n=E[e]?.id;t&&n&&a(t,n)})(n)},onClick:()=>{u&&g?g(e.id):t(e.id)},title:e.summary||e.long_term_memory||e.title,children:[u&&(0,B.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:m?.has(e.id)??!1,onChange:()=>g?.(e.id),onClick:e=>e.stopPropagation()}),(0,B.jsx)("span",{children:ee(e.title)}),e.running&&(0,B.jsx)("span",{className:"chat-session-running",title:w("正在执行中")}),(0,B.jsx)(Z,{items:D(e)}),!u&&(0,B.jsx)("i",{className:"chat-session-more material-icons",title:w("更多操作"),onClick:s=>{s.stopPropagation();const t=s.currentTarget.getBoundingClientRect();$({x:t.right,y:t.bottom,session:e})},children:"more_horiz"})]})},e.id))}),(0,B.jsxs)("div",{className:"chat-session-actions",children:[(0,B.jsx)(H.rA,{icon:u?"check_circle":"checklist",title:w(u?"取消批量选择":"批量选择"),onClick:h}),v&&!u&&(0,B.jsx)(H.rA,{icon:f?"person":"groups",title:w(f?"仅看我的会话":"查看所有用户会话"),onClick:x}),u&&(m?.size??0)>0&&(0,B.jsx)(H.rA,{icon:"delete",title:w("删除选中会话"),onClick:_}),!u&&p&&(0,B.jsx)(H.rA,{icon:"delete_sweep",title:w("删除全部会话"),onClick:p})]})]}),I&&(0,B.jsx)(Y.rY,{click:()=>$(null),children:(0,B.jsx)(Y.sw,{x:I.x,y:I.y,items:(e=>{const s=[{r:w("重命名"),v:"rename",run:()=>o(e.id,e.title)},...f?[]:[{r:w("移动到最上"),v:"to_top",run:()=>{const s=E[0];s&&s.id!==e.id&&a?.(e.id,s.id)}},{r:w("移动到最下"),v:"to_bottom",run:()=>{const s=E[E.length-1];s&&s.id!==e.id&&a?.(e.id,s.id)}}],{r:e.cmd_auto_allow?w("命令检测关闭"):w("命令检测开启"),v:"cmd_auto",run:()=>r?.(e.id,!e.cmd_auto_allow)}];return j?.length&&s.push({r:w("系统提示词"),items:[{r:w("不使用"),v:"",run:()=>b?.(e.id,"")},...j.map(s=>({r:T(String(s.index)),v:String(s.index),run:()=>b?.(e.id,String(s.index))}))]}),s.push({r:w("字符消耗统计"),v:"usage",run:()=>l(e.id)},{r:w("设置"),v:"setting",run:()=>d?.(e.id)},{r:w("删除"),v:"delete",run:()=>c(e.id)}),s})(I.session),pre_value:I.session.sys_prompt_id?String(I.session.sys_prompt_id):"",click:(e,s)=>{$(null),s?.run?.()}})})]})}function te(e){const s=(e.text||"").split("\n").map(e=>e.trim()).find(Boolean)||"";return s.length>80?s.slice(0,80)+"…":s}const ne=({messages:e,batchMode:s,selectedMsgIds:t,sending:a,chatContainerRef:i,messagesEndRef:o,onToggleMsgSelect:c,onDelete:r,onCopy:l,onCopyAll:d,onToggleBatchMode:u,onBatchCopy:m,onBatchDelete:g,showBatchBar:h,t:_})=>{const[p,f]=(0,n.useState)(new Set),x=(0,n.useMemo)(()=>e.filter(e=>!e.is_loading).map(e=>e.id),[e]),v=e=>{f(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},j=()=>{f(e=>e.size>0&&x.every(s=>e.has(s))?new Set:new Set(x))};return(0,B.jsxs)("div",{className:"chat-messages",ref:i,"data-sending":a?"true":"false",children:[h&&(0,B.jsxs)("div",{className:"chat-message-batch-bar",children:[(0,B.jsxs)("span",{className:"batch-bar-count",children:[_("已选")," ",t.size]}),(0,B.jsx)("button",{onClick:m,children:_("复制所选")}),(0,B.jsx)("button",{onClick:g,className:"danger",children:_("删除所选")}),(0,B.jsx)("button",{onClick:u,children:_("取消")})]}),e.map(e=>{const n=p.has(e.id);return(0,B.jsxs)("div",{className:`chat-message ${e.sender} ${s?"batch-mode":""} ${e.is_loading?"is-loading":""} ${n?"collapsed":""}`,children:[s&&(0,B.jsx)("input",{type:"checkbox",className:"chat-message-checkbox",checked:t.has(e.id),onChange:()=>c(e.id)}),e.is_loading?(0,B.jsxs)("div",{className:"ai-loading-bubble",children:[(0,B.jsxs)("div",{className:"ai-loading-dots",children:[(0,B.jsx)("span",{className:"ai-loading-dot"}),(0,B.jsx)("span",{className:"ai-loading-dot"}),(0,B.jsx)("span",{className:"ai-loading-dot"})]}),(0,B.jsx)("span",{className:"ai-loading-text",children:e.text})]}):(0,B.jsxs)(B.Fragment,{children:[n?(0,B.jsxs)("div",{className:"chat-message-summary",title:e.text,onClick:()=>v(e.id),children:[(0,B.jsx)("span",{className:"chat-message-summary-icon",children:"▸"}),(0,B.jsx)("span",{className:"chat-message-summary-text",children:te(e)||_("(无内容)")})]}):(0,B.jsx)("div",{className:"chat-message-body",children:V(e)}),(0,B.jsxs)("div",{className:"message-actions",children:[(0,B.jsx)("button",{onClick:()=>r(e.id),children:_("删除")}),(0,B.jsx)("button",{onClick:()=>l(e),children:_("复制")}),(0,B.jsx)("button",{onClick:d,children:_("全部复制")}),(0,B.jsx)("button",{onClick:u,children:_("多选")})]}),(0,B.jsxs)("div",{className:"message-collapse-bar",children:[(0,B.jsx)("button",{onClick:()=>v(e.id),children:_(n?"展开":"折叠")}),(0,B.jsx)("button",{onClick:j,children:_("全部折叠")}),"bot"===e.sender&&null!=e.elapsed_ms&&(0,B.jsx)("span",{className:"message-elapsed",children:(0,I.kf)(e.elapsed_ms)})]})]})]},e.id)}),(0,B.jsx)("div",{ref:o})]})},ae=(0,n.forwardRef)(function({placeholder:e="",disabled:s=!1,className:t,style:a,onEnter:i,onPaste:o,onChange:c},r){const l=(0,n.useRef)(null),[d,u]=(0,n.useState)(!0),[m,g]=(0,n.useState)(!1),h=(0,n.useCallback)(()=>{const e=l.current;return e?(e.textContent??"").replace(/\u00A0/g," ").trimEnd():""},[]);(0,n.useImperativeHandle)(r,()=>({getValue:()=>h(),setValue:e=>{const s=l.current;if(!s)return;s.textContent=e,u(!e);const t=document.createRange();t.selectNodeContents(s),t.collapse(!1);const n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)},clear:()=>{const e=l.current;e&&(e.textContent="",u(!0))},focus:()=>l.current?.focus()})),(0,n.useEffect)(()=>{const e=l.current;if(!e)return;const s=()=>u(!e.textContent);return e.addEventListener("input",s),()=>e.removeEventListener("input",s)},[]);return(0,B.jsx)("div",{ref:l,contentEditable:!s,suppressContentEditableWarning:!0,className:"rich-textarea"+(t?" "+t:""),style:a,onKeyDown:e=>{m||"Enter"!==e.key||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),i?.())},onPaste:o,onInput:()=>c?.(h()),onCompositionStart:()=>g(!0),onCompositionEnd:()=>g(!1),"data-placeholder":d?e:void 0})});var ie=t(84369);function oe({pendingAttachments:e,onRemove:s}){return 0===e.length?null:(0,B.jsx)("div",{className:"chat-attachment-strip",children:e.map((e,t)=>(0,B.jsxs)("div",{className:"chat-attachment-chip",children:[(0,B.jsx)(H.In,{icon:"attach_file"}),(0,B.jsx)("span",{title:e.name,children:e.name}),(0,B.jsx)("button",{type:"button",onClick:()=>s(t),children:(0,B.jsx)(H.In,{icon:"close"})})]},`${e.name}_${t}`))})}const ce=(0,n.forwardRef)(({onSend:e,sending:s,onAbort:t,pendingAttachments:o,onRemoveAttachment:c,onOpenFilePicker:r,onAddFiles:l,onDrop:d,onDragOver:u,fileInputRef:g,readonly:h=!1},_)=>{const{t:p}=(0,i.Bd)(),f=(0,n.useRef)(null),x=(0,n.useRef)(null),[v,j]=(0,a.fp)(m.AG.ai_chat_input_height);(0,n.useImperativeHandle)(_,()=>({getValue:()=>f.current?.getValue()??"",setValue:e=>f.current?.setValue(e),clear:()=>f.current?.clear()}));const{dragging:b,on_pointer_down:w,on_pointer_up:y}=(0,ie.y)({direction:"vertical",get_start_size:()=>v,px_to_unit:e=>e/(()=>{const e=x.current;return e&&parseFloat(getComputedStyle(e).fontSize)||16})(),min:2,on_change:e=>j(e)}),S={minHeight:`${v}em`,maxHeight:`${v}em`};return(0,B.jsxs)("div",{ref:x,className:"chat-input-area"+(h?" readonly":""),onDrop:h?void 0:d,onDragOver:h?void 0:u,children:[!h&&(0,B.jsx)("div",{className:"chat-input-resize-handle"+(b?" dragging":""),onPointerDown:w}),(0,B.jsx)("input",{ref:g,type:"file",multiple:!0,style:{display:"none"},onChange:e=>{e.target.files?.length&&(l(e.target.files),e.currentTarget.value="")}}),(0,B.jsxs)("div",{className:"chat-input-shell",children:[(0,B.jsx)(oe,{pendingAttachments:o,onRemove:c}),(0,B.jsx)(ae,{ref:f,placeholder:p(h?"查看全部会话时不可发送消息":"输入消息"),disabled:h,onEnter:()=>e(),onPaste:e=>{const s=e.clipboardData?.files;s&&s.length>0&&(e.preventDefault(),l(s))},className:"chat-input",style:S})]}),!h&&(0,B.jsx)(H.rA,{title:p("添加文件"),icon:"attach_file",onClick:r}),h?(0,B.jsx)("button",{className:"little-button button",disabled:!0,children:p("发送")}):s?(0,B.jsx)(H.Vi,{color:"var( --icon-red)",text:p("暂停"),clickFun:t}):(0,B.jsx)(H.Vi,{text:p("发送"),clickFun:e}),b&&(0,B.jsx)("div",{className:"chat-input-overlay",onPointerUp:y})]})}),re=function(e){const{t:s}=(0,i.Bd)(),[t,o]=(0,n.useState)([]),[c,r]=(0,n.useState)(!1),[l,d]=(0,n.useState)(null),[u,g]=(0,n.useState)(null),[h,_]=(0,n.useState)(!1),[v,j]=(0,a.fp)(m.AG.ai_bg_expanded),[,b]=(0,a.fp)(m.AG.ai_session_collapsed),w=()=>{j(!1)},y=(0,n.useCallback)(async()=>{r(!0);try{const s=new f.hf(f.HK.ai_bg_process_list_req);s.context={};const t=await p.ws.send(s);t?.context?.processes&&(o(t.context.processes),e.panelRef?.current?.onCountChange?.(t.context.processes.length))}catch(e){console.error("获取后台进程列表失败",e)}finally{r(!1)}},[]);e.panelRef&&(e.panelRef.current.refresh=y);const S=(0,n.useCallback)(async e=>{_(!0),d(e);try{const s=new f.hf(f.HK.ai_bg_process_output_req);s.context={pid:e};const t=await p.ws.send(s);g(t.context)}catch(e){console.error("获取进程输出失败",e),(0,x.zN)("获取进程输出失败")}finally{_(!1)}},[]),N=(0,n.useCallback)(async e=>{try{const s=new f.hf(f.HK.ai_bg_process_kill_req);s.context={pid:e};const t=await p.ws.send(s);t?.context?.success?((0,x.SK)("进程已终止"),y(),l===e&&(d(null),g(null))):(0,x.zN)(t?.context?.message||"终止失败")}catch(e){console.error("终止进程失败",e),(0,x.zN)("终止进程失败")}},[y,l]);(0,n.useEffect)(()=>{y();const e=setInterval(y,5e3);return()=>clearInterval(e)},[y]);const k=t.filter(e=>e.running),C=t.filter(e=>!e.running);return(0,B.jsxs)(B.Fragment,{children:[v&&(0,B.jsx)("div",{className:"chat-session-overlay",onClick:w}),(0,B.jsxs)("aside",{className:"chat-bg-process-panel "+(v?"expanded":""),children:[(0,B.jsxs)("div",{className:"chat-bg-process-header",children:[(0,B.jsx)("span",{className:"chat-bg-process-title",children:s("后台进程")}),(0,B.jsx)(H.rA,{icon:"close",title:s("关闭"),onClick:w})]}),(0,B.jsxs)("div",{className:"chat-bg-process-toolbar",children:[(0,B.jsx)(H.rA,{icon:"refresh",title:s("刷新"),onClick:y}),(0,B.jsxs)("span",{className:"chat-bg-process-count",children:[k.length," ",s("个运行中"),C.length>0&&` / ${C.length} ${s("个已退出")}`]})]}),(0,B.jsxs)("div",{className:"chat-bg-process-list",children:[c&&0===t.length&&(0,B.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}),!c&&0===t.length&&(0,B.jsx)("div",{className:"chat-bg-process-empty",children:s("暂无后台进程")}),k.map(e=>(0,B.jsxs)("div",{className:`chat-bg-process-item ${l===e.pid?"active":""} running`,children:[(0,B.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>S(e.pid),children:[(0,B.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,B.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>40?e.cmd.slice(0,40)+"...":e.cmd}),(0,B.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,B.jsx)("span",{className:"chat-bg-process-status running-dot",title:s("运行中"),children:"●"})]}),(0,B.jsxs)("div",{className:"chat-bg-process-item-actions",children:[(0,B.jsx)(H.rA,{icon:"terminal",title:s("查看输出"),onClick:()=>S(e.pid)}),(0,B.jsx)(H.rA,{icon:"stop",title:s("终止进程"),onClick:()=>N(e.pid)})]})]},e.pid)),C.map(e=>(0,B.jsx)("div",{className:`chat-bg-process-item ${l===e.pid?"active":""} finished`,children:(0,B.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>S(e.pid),children:[(0,B.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,B.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>30?e.cmd.slice(0,30)+"...":e.cmd}),(0,B.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,B.jsxs)("span",{className:"chat-bg-process-exit-code",children:["exit: ",e.exit_code]})]})},e.pid))]}),null!==l&&(0,B.jsxs)("div",{className:"chat-bg-process-output",children:[(0,B.jsxs)("div",{className:"chat-bg-process-output-header",children:[(0,B.jsxs)("span",{children:["PID: ",l," ",s("输出")]}),(0,B.jsx)(H.rA,{icon:"close",title:s("关闭"),onClick:()=>{d(null),g(null)}})]}),(0,B.jsx)("div",{className:"chat-bg-process-output-content",children:h?(0,B.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}):u?(0,B.jsx)("pre",{className:"chat-bg-process-output-pre",children:u.output||s("(无输出)")}):null})]})]})]})};function le(e={}){const{inline_header:s=!1,session_id:t,file_cwd_path:h,sync_url:j=!0,on_session_change:b}=e,{t:S}=(0,i.Bd)(),[N,k]=(0,o.ok)(),C=j&&N.get("session")||"",{check_user_auth:H}=(0,l.MH)();(0,u.w)();const[E]=(0,a.fp)(m.AG.user_base_info),V=!!E?.user_data?.is_root,[K,P]=(0,a.fp)(m.AG.ai_session_collapsed),[L,z]=(0,a.fp)(m.AG.ai_bg_expanded),[F,q]=(0,a.fp)(m.AG.prompt_card),[U]=(0,a.fp)(m.AG.ai_chat_zoom),[G,J]=(0,n.useState)(null),[W,Q]=(0,n.useState)([]),[Y,Z]=(0,n.useState)(new Set),[ee,te]=(0,n.useState)([]),[ae,ie]=(0,n.useState)(""),[oe,le]=(0,n.useState)([]),[de,ue]=(0,n.useState)(0),me=(0,n.useRef)(null),ge=(0,n.useRef)(null),he=(0,n.useRef)(null),_e=(0,n.useRef)({}),pe=(0,n.useRef)({}),fe=(0,n.useRef)(null);(0,n.useEffect)(()=>{fe.current=G},[G]);const xe=(0,n.useRef)(null),ve=(0,n.useRef)([]),je=(0,n.useRef)(""),be=(0,n.useRef)(!1),we=(0,n.useRef)(null),ye=(0,n.useRef)(()=>{}),Se=(0,n.useRef)(null),Ne=function(e){const{admin_call:s,owner_of_session:t,get_sessions:a,activeSessionId:o,admin_mode_ref:r}=e,{t:l}=(0,i.Bd)(),u=(0,R.y)(),[m,g]=(0,n.useState)([]),[h,_]=(0,n.useState)(!1),[p,f]=(0,n.useState)(new Set),j=(0,n.useRef)(null),b=(0,n.useRef)(!0),w=(0,n.useRef)(!1),S=(e=!1)=>{const s=j.current;if(!s||!b.current)return;s.scrollTo({top:s.scrollHeight,behavior:e?"smooth":"auto"});let t=0;const n=()=>{const s=j.current;s&&b.current&&(s.scrollTo({top:s.scrollHeight,behavior:e&&0===t?"smooth":"auto"}),++t<6&&requestAnimationFrame(n))};requestAnimationFrame(n)},N=()=>{w.current=!0};return(0,n.useLayoutEffect)(()=>{w.current&&(w.current=!1,b.current=!0),b.current&&S(!1)},[m]),(0,n.useEffect)(()=>{const e=j.current;if(!e)return;const s=s=>{s.deltaY<0?b.current=!1:e.scrollHeight-(e.scrollTop+e.clientHeight)<4&&(b.current=!0)},t=()=>{e.scrollHeight-(e.scrollTop+e.clientHeight)<4&&(b.current=!0)},n=()=>{b.current&&(e.scrollTop=e.scrollHeight)};e.addEventListener("wheel",s,{passive:!0}),e.addEventListener("scroll",t);const a=new ResizeObserver(n),i=()=>[...e.children].forEach(e=>a.observe(e));i();const o=new MutationObserver(()=>{i(),n()});return o.observe(e,{childList:!0}),()=>{e.removeEventListener("wheel",s),e.removeEventListener("scroll",t),a.disconnect(),o.disconnect()}},[]),{messages:m,setMessages:g,batchMode:h,setBatchMode:_,selectedMsgIds:p,setSelectedMsgIds:f,chatContainerRef:j,followRef:b,isNearBottom:(e,s=120)=>{const{scrollTop:t,scrollHeight:n,clientHeight:a}=e;return n-(t+a)<s},scrollToBottom:S,request_scroll_bottom:N,apply_session:e=>{if(!e)return g([]),void N();let s=e.messages??[];e.live_messages?.length&&(s=[...s,...e.live_messages]),g(y(s)),N()},handleDelete:e=>{u({sub_title:l("cf_one"),confirm_fun:async()=>{const n=m.findIndex(s=>s.id===e);if(n<0)return;if(g(m.filter(s=>s.id!==e)),!o)return;const a=t(o);a?s("message_delete",{session_id:o,user_id:a,indices:[n]}).catch(console.error):c.jV.post("session/message/delete",{session_id:o,indices:[n]}).catch(console.error)}})},handleCopy:async e=>{(0,T.lW)(v(e)),(0,x.SK)("复制成功")},handleCopyAll:async()=>{const e=a();if(!e.length)return void(0,x.SK)("暂无聊天记录");const t=[];for(const n of e){const e=n.user_id?await s("get",{session_id:n.id,user_id:n.user_id}):await c.jV.post("session/get",{session_id:n.id});if(e.code!==d.m.Success||!e.data)continue;const a=e.data,i=y([...a.messages??[],...a.live_messages??[]]).map(v).filter(Boolean).join("\n\n\n");i&&t.push(i)}t.length?((0,T.lW)(t.join("\n\n\n")),(0,x.SK)("复制成功")):(0,x.SK)("暂无聊天记录")},handleBatchCopy:()=>{const e=m.filter(e=>p.has(e.id)).map(v).filter(Boolean).join("\n\n\n");e?((0,T.lW)(e),(0,x.SK)("复制成功")):(0,x.SK)("暂无内容")},toggleBatchMode:()=>{h&&f(new Set),_(e=>!e)},toggleMsgSelect:e=>{f(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},batchDeleteMessages:()=>{0!==p.size&&u({sub_title:l("cf_msgs"),confirm_fun:async()=>{const e=[];if(m.forEach((s,t)=>{p.has(s.id)&&e.push(t)}),g(m.filter(e=>!p.has(e.id))),f(new Set),_(!1),!o||0===e.length)return;const n=t(o);n?s("message_delete",{session_id:o,user_id:n,indices:e}).catch(console.error):c.jV.post("session/message/delete",{session_id:o,indices:e}).catch(console.error)}})}}}({admin_call:(e,s)=>c.jV.post("admin/session",{action:e,...s||{}}),owner_of_session:e=>be.current?ve.current.find(s=>s.id===e)?.user_id:void 0,get_sessions:()=>ve.current,activeSessionId:je.current,admin_mode_ref:be});ye.current=Ne.apply_session;const ke=function(e){const{on_session_loaded:s,set_session_panel_open:t,on_session_change:o,init_cwd:r,write_url_session:l,url_session_id:u,init_session_id:h}=e,{t:_}=(0,i.Bd)(),p=(0,R.y)(),[f,v]=(0,a.fp)(m.AG.ai_last_session_id),[j,b]=(0,n.useState)([]),[w,y]=(0,n.useState)(""),[S,N]=(0,n.useState)(""),[k,C]=(0,n.useState)(!1),[A,M]=(0,n.useState)(!1),[T,D]=(0,n.useState)(!1),H=(0,n.useRef)(!1),E=(0,n.useRef)([]);(0,n.useEffect)(()=>{H.current=k},[k]),(0,n.useEffect)(()=>{E.current=j},[j]);const V=(e,s={})=>c.jV.post("admin/session",{action:e,...s}),K=e=>{if(H.current)return E.current.find(s=>s.id===e)?.user_id},P=async(e,n=!1,a)=>{const i=a??E.current.find(s=>s.id===e)?.user_id,r=H.current&&i?await V("get",{session_id:e,user_id:i}):await c.jV.post("session/get",{session_id:e});if(r.code!==d.m.Success||!r.data)return!1;const m=r.data;return y(m.id),v(m.id),u!==m.id&&l(m.id),o?.(m.id),M(!!m.running),N(m.sys_prompt_id??""),n&&t(!0),s(m),!0},L=async e=>{const t=H.current?await V("list_all_sessions"):await c.jV.get("sessions");if(t.code!==d.m.Success)return!1;const n=t.data??[];b(n);const a=null===e?n[0]?.id??"":e||w||n[0]?.id||"";if(!a)return y(""),l(null),s(null),!1;if(e&&!n.some(s=>s.id===e))return!1;const i=n.find(e=>e.id===a)?.user_id;return await P(a,!1,i)},z=async e=>{if(!e)return null;const s=await c.jV.get("sessions");if(s.code!==d.m.Success)return null;const t=s.data??[],n=(0,I.ed)(e),a=t.find(e=>(0,I.ed)(e.file_cwd_path)===n);if(a)return a.id;const i=await c.jV.post("session",{file_cwd_path:n});return i.code!==d.m.Success?null:i.data.id};return{sessions:j,setSessions:b,sessions_ref:E,activeSessionId:w,setActiveSessionId:y,selectedSysPromptId:S,setSelectedSysPromptId:N,admin_all_mode:k,admin_mode_ref:H,readonly:T,activeSessionRunning:A,setActiveSessionRunning:M,admin_call:V,call:(e,s,t)=>H.current?V(e,s):t(),owner_of_session:K,refreshSessions:async()=>{const e=H.current?await V("list_all_sessions"):await c.jV.get("sessions");e.code===d.m.Success&&b(e.data??[])},markSessionRunning:(e,s)=>{b(t=>{const n=t.find(s=>s.id===e);return n&&!!n.running!==s?t.map(t=>t.id===e?{...t,running:s}:t):t})},loadSession:P,loadSessions:L,createSession:async e=>{const n=await c.jV.post("session",{sys_prompt_id:e||void 0,file_cwd_path:r||void 0});if(n.code!==d.m.Success)return;const a=n.data;y(a.id),N(a.sys_prompt_id??""),t(!0),s(null),await L(a.id),requestAnimationFrame(()=>{const e=document.querySelector(".chat-input");e&&(e.style.height="auto",e.style.height=Math.min(e.scrollHeight,200)+"px")})},locate_session_by_cwd:z,init_active_session:async()=>{if(r){const e=await z(r);e&&await L(e)||await L()}else h?await L(h)||await L():u?await L(u)||await L():f&&await L(f)||await L()},reorderSessions:(e,s)=>{if(H.current)return;const t=E.current.findIndex(s=>s.id===e),n=E.current.findIndex(e=>e.id===s);if(t<0||n<0||t===n)return;const a=(0,$.TI)(E.current,t,n);b(a),c.jV.post("sessions/update/sort",{session_ids:a.map(e=>e.id)}).catch(()=>{})},deleteSession:e=>{p({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{const s=K(e);s?await V("delete",{session_id:e,user_id:s}):await c.jV.post("session/delete",{session_id:e}),w===e?(y(""),await L(null)):await L(w)}})},renameSession:(e,s)=>{let t=s;p({confirm_fun:async()=>{const s=K(e);s?await V("rename",{session_id:e,user_id:s,title:t}):await c.jV.post("sessions/update/meta",{id:e,title:t}),await L(w)},context_div:(0,B.jsx)("div",{className:"card-content",children:(0,B.jsx)(g.Sm,{value:t,handleInputChange:e=>{t=e}})})})},toggleCmdAuto:async(e,s)=>{const t=K(e);t?await V("cmd_auto",{session_id:e,user_id:t,allow:s}):await c.jV.post("session/cmd_auto_allow",{session_id:e,allow:s}),(0,x.SK)(_(s?"命令检测已开启":"命令检测已关闭")),await L(w)},batchDeleteSessions:(e,s)=>{0!==e.size&&p({sub_title:_("cf_ses"),confirm_fun:async()=>{if(H.current)await V("batch_delete",{session_ids:Array.from(e)});else for(const s of e)await c.jV.post("session/delete",{session_id:s});s(),e.has(w)?(y(""),await L(null)):await L(w)}})},clearAllSessions:()=>{p({sub_title:_("cf_all"),confirm_fun:async()=>{await c.jV.post("sessions/clear",{}),y(""),s(null),await L(null)}})},toggleAllUsersMode:async()=>{const e=!k;C(e),H.current=e,D(e),y(""),s(null);const t=e?await V("list_all_sessions"):await c.jV.get("sessions"),n=t.code===d.m.Success?t.data??[]:[];b(n),n[0]?.id&&await P(n[0].id,!1,n[0].user_id)},changeSystemPrompt:(e,s)=>{const t=s||w;if(!t)return;b(s=>s.map(s=>s.id===t?{...s,sys_prompt_id:e||void 0}:s)),t===w&&N(e);const n=K(t);n?V("sys_prompt",{session_id:t,user_id:n,sys_prompt_id:e||void 0}).catch(console.error):c.jV.post("session/sys_prompt",{session_id:t,sys_prompt_id:e||void 0}).catch(console.error)}}}({on_session_loaded:e=>{if(e&&(e.running&&(p.ws.sendData(f.HK.ai_chat_subscribe,{session_id:e.id,subscribe:!0}),we.current=e.id),ye.current(e),e.live_messages?.length)){const s=y([...e.messages??[],...e.live_messages]);Se.current?.bind_live_bubbles(s,e.live_messages.length)}},set_session_panel_open:e=>P(!e),on_session_change:b,init_cwd:h,write_url_session:e=>{j&&k(s=>{const t=new URLSearchParams(s);return e?t.set("session",e):t.delete("session"),t},{replace:!0})},url_session_id:C,init_session_id:t});(0,n.useEffect)(()=>{je.current=ke.activeSessionId,be.current=ke.admin_all_mode,ve.current=ke.sessions},[ke.activeSessionId,ke.admin_all_mode,ke.sessions]);const Ce=D({active_session_id_ref:je,local_owner_ref:xe,subscribed_ref:we,set_messages:Ne.setMessages,scroll_to_bottom:()=>Ne.scrollToBottom(!1),follow_ref:Ne.followRef,mark_session_running:ke.markSessionRunning,refresh_sessions:ke.refreshSessions,reload_session:e=>ke.loadSession(e),set_active_session_running:ke.setActiveSessionRunning});Se.current=Ce;const Ae=(0,n.useRef)((0,r.nF)(e=>{Ne.setMessages(e),Ne.followRef.current&&Ne.scrollToBottom(!1)},50)).current,Me=function(e){const{getMessages:s,setMessages:t,setMessagesDebounced:a,setSending:i,getActiveSessionId:o,setActiveSessionId:c,refreshSessions:r,scrollToBottom:l,buildRequestMessages:d,getSelectedSysPromptId:u,setLocalOwner:m}=e,g=(0,n.useRef)([]),h=(0,n.useRef)(null),_=(e,n,c)=>{const g=s(),_=g.length+1,x={...n,id:_},v=[...g,x];t(v),i(e),m(e),h.current={abort:()=>{}};const j={id:-1,sender:"bot",text:"AI thinking ...",is_loading:!0};v.push(j),t([...v]);const b=new Map,w=()=>{o()===e&&a([...v])},S=()=>{const e=v.indexOf(j);-1!==e&&v.splice(e,1)},N=s=>{const t=s.context||{};if(t.session_id!==e)return;const n=t.text||"",a=t.tool_call_ends,i=t.chunk_index??0;if(t.notice)return j.id=-1,j.text=n,j.is_loading=!0,v.includes(j)||v.push(j),void w();if("[DONE]"===n)return;if(!n&&!a)return;S();let o=b.get(i);if(o||(o={id:_+1+i,sender:"bot",text:"",is_loading:!0},v.push(o),b.set(i,o)),n){o.text=o.text+n;const e=o.content_list?.[0];e&&(e.content=o.text),o.is_loading=!1}a&&(o.content_list=[{tool_call_ends:a,content:o.text,role:"assistant"}],o.is_loading=!1),w()},k=s=>{const n=s.context||{};n.session_id===e&&(A(),h.current=null,m(null),i(s=>s===e?null:s),o()===e&&t(e=>{const s=e.filter(M);let t=s;if(n.once_messages_list?.length){let e=-1;for(let t=s.length-1;t>=0;t--)if("user"===s[t].sender){e=t;break}const a=e>=0?e+1:s.length;t=[...s.slice(0,a),...y(n.once_messages_list)]}return t.map((e,s)=>({...e,id:s+1}))}),r(),l(!0),c())},C=s=>{const n=s.context||{};if(n.session_id!==e)return;A(),h.current=null,i(s=>s===e?null:s);const a="AI request error: "+(n.message||"未知错误");S();const r=[...v].reverse().find(e=>"bot"===e.sender);r?(r.text=r.text?`${r.text}\n\n${a}`:a,r.is_loading=!1):v.push({id:_+1,sender:"bot",text:a}),o()===e&&t([...v].map((e,s)=>({...e,id:s+1}))),c()},A=()=>{p.ws.off_message(`message_${f.HK.ai_chat_msg}`,N),p.ws.off_message(`message_${f.HK.ai_chat_end}`,k),p.ws.off_message(`message_${f.HK.ai_chat_error}`,C)};p.ws.addMsg(f.HK.ai_chat_msg,N),p.ws.addMsg(f.HK.ai_chat_end,k),p.ws.addMsg(f.HK.ai_chat_error,C),p.ws.sendData(f.HK.ai_chat_req,{messages:d(n),session_id:e,sys_prompt_id:u()})},x=()=>{const e=g.current;if(0===e.length)return;const s=e.shift();if(!s)return;t(e=>e.map(e=>"user"===e.sender&&e.text.includes("⏳(排队中...)")?{...e,text:e.text.replace(" ⏳(排队中...)","")}:e));const n={id:w(),sender:"user",text:s.text,attachments:s.attachments};_(o(),n,x)};return{startChatStream:_,processPendingQueue:x,enqueueMessage:(e,s)=>{g.current.push({text:e,attachments:s})},getQueueLength:()=>g.current.length,abort:()=>{const e=o();e&&(p.ws.sendData(f.HK.ai_chat_abort,{session_id:e}),h.current&&(h.current=null,i(s=>s===e?null:s)))}}}({getMessages:()=>Ne.messages,setMessages:Ne.setMessages,setMessagesDebounced:Ae,setSending:J,getActiveSessionId:()=>je.current,setActiveSessionId:ke.setActiveSessionId,refreshSessions:ke.refreshSessions,scrollToBottom:Ne.scrollToBottom,buildRequestMessages:e=>{const s=(e.attachments??[]).filter(e=>"image"===e.kind);if(s.length>0){const t=[];e.text&&t.push({type:"text",text:e.text});for(const e of s)t.push({type:"image_url",image_url:{url:e.content}});return[{content:t,role:"user",attachments:e.attachments??[]}]}return[{content:e.text,role:"bot"===e.sender?"assistant":"user",attachments:e.attachments??[]}]},getSelectedSysPromptId:()=>ke.selectedSysPromptId,setLocalOwner:e=>{xe.current=e}}),Ie=e=>{ie(e?.ai_config?.model??"")},$e=async()=>{try{const e=await c.jV.get("public_models");e.code===d.m.Success&&le(e.data?.groups??[])}catch{le([])}},Re=e=>{const s=Array.from(e??[]).filter(Boolean);s.length&&Q(e=>[...e,...s])},Be=e=>ke.owner_of_session(e),Te=()=>{Ne.batchMode&&(Ne.setSelectedMsgIds(new Set),Z(new Set)),Ne.setBatchMode(e=>!e)};(0,n.useEffect)(()=>{(async()=>{const e=await c.XO.get("ai_agent_setting/env");e.code===d.m.Success&&(pe.current=e.data,Ie(e.data)),await $e(),await ke.init_active_session();const s=await c.jV.get("system_prompts");s.code===d.m.Success&&te(s.data??[])})(),requestAnimationFrame(()=>Ne.scrollToBottom(!1)),_e.current.onCountChange=ue,_e.current.refresh?.();const e=e=>{const s=e?.context?.count;"number"==typeof s&&ue(s)};return p.ws.addMsg(f.HK.ai_bg_process_count_notify,e),()=>{p.ws.off_message(`message_${f.HK.ai_bg_process_count_notify}`,e)}},[]);const De=G===ke.activeSessionId||ke.activeSessionRunning;return(0,B.jsxs)(n.Fragment,{children:[(0,B.jsx)(X,{inline:s,currentModelName:ae,setCurrentModelName:ie,modelGroups:oe,onModelChanged:async()=>{await $e();const e=await c.XO.get("ai_agent_setting/env");e.code===d.m.Success&&(pe.current=e.data,Ie(e.data))},batchMode:Ne.batchMode,selectedMsgCount:Ne.selectedMsgIds.size,sessionVisible:!K,onToggleSessionPanel:()=>P(e=>!e),onCreateSession:ke.createSession,onBatchDeleteMessages:Ne.batchDeleteMessages,onToggleBatchMode:Te,bgProcessVisible:L,bgProcessCount:de,onToggleBgProcess:()=>z(e=>!e)}),(0,B.jsxs)("div",{className:"chat-page"+(s?" chat-page--embedded":" chat-page-with-sessions"),style:{"--ai-chat-zoom":U},children:[!K&&(0,B.jsx)("div",{className:"chat-session-overlay",onClick:()=>P(!0)}),!K&&(0,B.jsx)(se,{sessions:ke.sessions,activeSessionId:ke.activeSessionId,onSelectSession:e=>ke.loadSession(e,!1),onReorderSessions:ke.reorderSessions,onRenameSession:ke.renameSession,onDeleteSession:ke.deleteSession,onToggleCmdAuto:ke.toggleCmdAuto,onShowUsageStats:async e=>{q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsx)("div",{className:"usage-stats-loading",children:S("加载中...")}),cancel:()=>q({open:!1})});try{const s=Be(e),t=s?await ke.admin_call("usage_stats",{session_id:e,user_id:s}):await c.jV.post("session/usage_stats",{session_id:e});if(t.code===d.m.Success&&t.data){const e=t.data;q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsxs)("div",{className:"usage-stats-panel",children:[[{l:S("对话轮次"),v:(e.turns??0).toString()},{l:S("AI输入Token"),v:_(e.input_tokens)},{l:S("AI输出Token"),v:_(e.output_tokens)},{l:S("AI输入Token(最近一轮)"),v:_(e.recent_input_tokens)},{l:S("AI输出Token(最近一轮)"),v:_(e.recent_output_tokens)}].map((e,s)=>(0,B.jsxs)("div",{className:"usage-stats-row",children:[(0,B.jsx)("span",{className:"usage-stats-label",children:e.l}),(0,B.jsx)("span",{className:"usage-stats-value",children:e.v})]},s)),(0,B.jsxs)("div",{className:"usage-stats-row usage-stats-total",children:[(0,B.jsx)("span",{className:"usage-stats-label",children:S("AI Token总计消耗")}),(0,B.jsx)("span",{className:"usage-stats-value",children:_((e.input_tokens||0)+(e.output_tokens||0))})]})]}),cancel:()=>q({open:!1})})}else q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsx)("div",{className:"usage-stats-empty",children:S("暂无统计数据")}),cancel:()=>q({open:!1})})}catch{q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsx)("div",{className:"usage-stats-empty",children:S("暂无统计数据")}),cancel:()=>q({open:!1})})}},onShowSessionSetting:e=>{let s=ke.sessions.find(s=>s.id===e)?.file_cwd_path??"";q({open:!0,title:S("会话设置"),context_div:(0,B.jsxs)("div",{className:"session-setting",children:[(0,B.jsx)("div",{className:"session-setting__label",children:S("服务器工作目录")}),(0,B.jsx)(g.Sm,{value:s,placeholder:S("服务器工作目录提示"),handleInputChange:e=>{s=e}})]}),confirm:async()=>{try{const t=Be(e);(t?await ke.admin_call("setting",{session_id:e,user_id:t,file_cwd_path:s.trim()}):await c.jV.post("session/setting",{session_id:e,file_cwd_path:s.trim()})).code===d.m.Success&&(0,x.SK)(S("保存成功"))}catch{}q({open:!1}),await ke.loadSessions(ke.activeSessionId)},cancel:()=>q({open:!1})})},batchMode:Ne.batchMode,selectedSessionIds:Y,onToggleSessionSelect:e=>{Z(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onToggleBatchMode:Te,onBatchDeleteSessions:()=>ke.batchDeleteSessions(Y,()=>{Z(new Set),Ne.setBatchMode(!1)}),onClearAllSessions:ke.admin_all_mode?void 0:ke.clearAllSessions,allUsersMode:ke.admin_all_mode,onToggleAllUsersMode:ke.toggleAllUsersMode,showAllUsersEntry:V,sysPromptList:ee,onChangeSysPrompt:(e,s)=>ke.changeSystemPrompt(s,e)}),(0,B.jsx)(re,{panelRef:_e}),(0,B.jsxs)("section",{className:"chat-main",children:[0===Ne.messages?.length&&(0,B.jsx)("div",{className:"chat-header",children:(0,B.jsx)("div",{children:S("ai_ask")})}),(0,B.jsx)(ne,{messages:Ne.messages,batchMode:Ne.batchMode,selectedMsgIds:Ne.selectedMsgIds,sending:De,chatContainerRef:Ne.chatContainerRef,messagesEndRef:he,onToggleMsgSelect:Ne.toggleMsgSelect,onDelete:Ne.handleDelete,onCopy:Ne.handleCopy,onCopyAll:Ne.handleCopyAll,onToggleBatchMode:Te,onBatchCopy:Ne.handleBatchCopy,onBatchDelete:Ne.batchDeleteMessages,showBatchBar:Ne.batchMode&&Ne.selectedMsgIds.size>0&&0===Y.size,t:S}),(0,B.jsx)(ce,{ref:me,onSend:async()=>{if(ke.admin_all_mode)return;const e=(me.current?.getValue()??"").trim();if(!e&&0===W.length)return;if(G===ke.activeSessionId){const s=await A(W);Me.enqueueMessage(e,s),me.current?.clear(),Q([]);const t={id:w(),sender:"user",text:e+(Me.getQueueLength()>1?" ⏳(排队中...)":""),attachments:s};return void Ne.setMessages(e=>[...e,t])}let s=ke.activeSessionId;if(!s){const t=await c.jV.post("session",{title:(e||W[0]?.name).slice(0,28),sys_prompt_id:void 0,file_cwd_path:h||void 0});if(t.code!==d.m.Success)return;s=t.data.id,ke.setActiveSessionId(s),b?.(s),await ke.loadSessions(s)}const t=await A(W),n={id:w(),sender:"user",text:e,attachments:t};me.current?.clear(),Q([]);const a=pe.current?.ai_config?.request_type||"completions";if("completions"!==a){const t={id:Ne.messages.length+2,sender:"bot",text:"处理中...",is_loading:!0},i={...n,id:Ne.messages.length+1},o=[...Ne.messages,i,t];Ne.setMessages(o),J(s);return void(await O(a,e,s,async(e,s)=>{t.text=e,t.is_loading=!1,s?.images&&(t.images=s.images),s?.audio&&(t.audio=s.audio),s?.embeddings&&(t.embeddings=s.embeddings),Ne.setMessages([...o]),J(null),ke.refreshSessions(),Ne.scrollToBottom(!0),Me.processPendingQueue()})||(t.text=`请求类型 "${a}" 的专用处理器尚未实现,请使用 completions 类型。`,t.is_loading=!1,Ne.setMessages([...o]),J(null),Me.processPendingQueue()))}Me.startChatStream(s,n,()=>Me.processPendingQueue())},readonly:ke.admin_all_mode,sending:De,onAbort:Me.abort,pendingAttachments:W,onRemoveAttachment:e=>{Q(s=>s.filter((s,t)=>t!==e))},onOpenFilePicker:()=>{ge.current?.click()},onAddFiles:Re,onDrop:e=>{const s=e.dataTransfer?.files;s&&s.length>0&&(e.preventDefault(),Re(s))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:ge})]})]})]})}},72693(e,s,t){t.d(s,{w:()=>g});var n=t(96540),a=t(22022),i=t(14944),o=t(92275),c=t(34843),r=t(82893),l=t(85997),d=t(14284),u=t(74848);function m(e){const{t:s}=(0,a.Bd)(),[t,i]=(0,n.useState)(!1),o=!!e.sessionId;return(0,u.jsxs)("div",{children:[(0,u.jsx)("div",{style:{maxHeight:"60vh",overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--surfaceSecondary)",padding:"0.75em",borderRadius:"0.5em",marginBottom:"0.75em",fontFamily:"monospace",fontSize:"0.9em",lineHeight:"1.5"},children:e.cmd}),o&&(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5em",marginBottom:"0.75em",color:t?"var(--icon-blue)":"var(--textSecondary)"},children:[(0,u.jsx)(l.Ay,{checked:t,onChange:s=>{i(s),s&&e.onAutoAllow()},title:s("此会话不再询问")}),(0,u.jsx)("span",{children:s("此会话不再询问")})]}),(0,u.jsxs)("div",{style:{display:"flex",gap:"0.5em",justifyContent:"flex-end"},children:[(0,u.jsx)(l.$n,{text:s("拒绝"),color:"var(--red)",clickFun:e.onDeny}),(0,u.jsx)(l.$n,{text:s("允许"),clickFun:e.onAllow})]})]})}function g(){const[e,s]=(0,c.fp)(r.AG.prompt_card),{t}=(0,a.Bd)(),l=(0,n.useRef)([]),g=(0,n.useRef)(!1),h=(0,n.useRef)(null),_=(0,n.useRef)(void 0),p=(0,n.useRef)(()=>{}),f=(0,n.useCallback)(e=>{s({open:!1}),g.current=!1,h.current&&(i.ws.sendData(o.HK.ai_confirm_cmd,{askId:h.current,approved:e}),h.current=null),p.current()},[s]),x=(0,n.useCallback)(()=>{if(g.current)return;if(0===l.current.length)return g.current=!1,void s({open:!1});g.current=!0;const e=l.current.shift();e?(h.current=e.askId,_.current=e.session_id,s({open:!0,title:t("命令确认"),cancel:()=>f(!1),context_div:(0,u.jsx)(m,{cmd:e.cmd,sessionId:e.session_id,onDeny:()=>f(!1),onAllow:()=>f(!0),onAutoAllow:async()=>{if(_.current)try{await d.jV.post("session/cmd_auto_allow",{session_id:_.current,allow:!0})}catch(e){console.error("设置会话命令免确认失败",e)}f(!0)}})})):g.current=!1},[t,f,s]);p.current=x;const v=(0,n.useCallback)(e=>{l.current.push(e),x()},[x]);(0,n.useEffect)(()=>{const e=e=>{const t=e.context||{};if(t.dismiss&&t.askId)return l.current=l.current.filter(e=>e.askId!==t.askId),void(g.current&&h.current===t.askId&&(h.current=null,g.current=!1,s({open:!1}),x()));t.askId&&t.cmd&&v({askId:t.askId,cmd:t.cmd,session_id:t.session_id})};return i.ws.addMsg(o.HK.ai_confirm_cmd,e),()=>{i.ws.off_message(`message_${o.HK.ai_confirm_cmd}`,e)}},[v]),(0,n.useEffect)(()=>()=>{l.current=[],g.current=!1,h.current=null},[])}},34299(e,s,t){t.r(s),t.d(s,{default:()=>y});var n=t(96540),a=t(23802),i=t(53995),o=t(18569),c=t(77979),r=t(8263),l=t(69428),d=t.n(l),u=(t(3775),t(21499)),m=t(99214),g=t(89117),h=t(86063),_=t(89334),p=t(41105),f=t(52388),x=t(19878),v=(t(72411),t(74848));const j=new a.A({html:!0,highlight:function(e,s){if(s&&x.A.getLanguage(s))try{return`<pre class="hljs code-block-with-copy"><code class="hljs language-${s}">${x.A.highlight(e,{language:s}).value}</code></pre>`}catch(e){}try{return`<pre class="hljs code-block-with-copy"><code class="hljs">${x.A.highlightAuto(e).value}</code></pre>`}catch(e){}return`<pre class="hljs code-block-with-copy"><code>${j.utils.escapeHtml(e)}</code></pre>`}});async function b(e,s){e.className="md-graph md-graph--mind md-graph--loading",e.textContent=f.A.t("rendering");const t=await(0,h.Hn)(s);e.isConnected&&(e.className="md-graph md-graph--mind",e.textContent="",await t.mount(e))}function w(e){const s=e.className.match(/language-([\w-]+)/);return s?s[1]:""}function y(e){const s=(0,n.useRef)(null);return(0,m.VD)(),(0,n.useEffect)(()=>{s.current&&(s.current.innerHTML=j.render(e.context??""),async function(e){const s=e.querySelectorAll("pre > code[class*='language-']");for(const e of Array.from(s)){const s=w(e),t=(0,g.Hm)(s),n=(0,h.hj)(s);if(!t&&!n)continue;const a=e.closest(".code-block-with-copy")??e.parentElement;if(!a)continue;const i=e.textContent??"",o=document.createElement("div");if(a.replaceWith(o),n){try{await b(o,i)}catch(e){console.error("[mind] render failed",e),o.className="md-graph md-graph--mind",o.textContent=String(e)}continue}o.className="md-graph md-graph--loading",o.textContent=f.A.t("rendering");const c=await(0,g.U6)(s,i);o.isConnected&&(c.error?(o.className="md-graph md-graph--error",o.textContent=c.error):(o.className="md-graph",o.innerHTML=c.svg))}}(s.current),(0,_.rg)(s.current))},[e.context]),(0,v.jsx)("div",{ref:s})}j.use(i.A).use(o.A).use(c.A).use(r.A).use(d()).use(e=>{e.renderer.rules.fence;e.renderer.rules.fence=(s,t,n,a,i)=>{const o=s[t],c=o.content.trim(),r=o.info.trim();let l="";if(r&&x.A.getLanguage(r))try{l=x.A.highlight(c,{language:r}).value}catch(s){l=e.utils.escapeHtml(c)}else try{l=x.A.highlightAuto(c).value}catch(s){l=e.utils.escapeHtml(c)}return`\n <div class="code-block-with-copy">\n <div class="code-header">\n <span class="code-language">${r||"code"}</span>\n <button class="copy-btn" data-code="${e.utils.escapeHtml(c)}">复制</button>\n </div>\n <pre><code class="hljs ${r?`language-${r}`:""}">${l}</code></pre>\n </div>`}}).use(e=>{const s=e.renderer.rules.link_open||function(e,s,t,n,a){return a.renderToken(e,s,t)};e.renderer.rules.link_open=(e,t,n,a,i)=>{const o=e[t],c=o.attrIndex("href");if(c>=0){const e=o.attrs[c][1];o.attrs[c][1]=(0,u.bi)(window.location.href,e)}return s(e,t,n,a,i)}}),(0,_.Rh)(j,p.pC)},84369(e,s,t){t.d(s,{y:()=>o});var n=t(96540),a=t(2543);function i(e){if(void 0!==e)return"function"==typeof e?e():e}function o(e){const{direction:s="vertical",target_ref:t,get_start_size:o,px_to_unit:c,min:r,max:l,throttle:d,on_change:u,on_drag_end:m}=e,[g,h]=(0,n.useState)(!1),_=(0,n.useRef)(null),p=(0,n.useRef)(u);p.current=u;const f=e=>"vertical"===s?e.clientY:e.clientX,x=(0,n.useRef)({direction:s,get_start_size:o,px_to_unit:c,min:r,max:l,get_pos:f});x.current={direction:s,get_start_size:o,px_to_unit:c,min:r,max:l,get_pos:f};const v=(0,n.useCallback)(e=>{const s=_.current;if(!s)return;const{px_to_unit:t,min:n,max:a,get_pos:o}=x.current,c=s.pos-o(e);let r=s.size+t(c);const l=i(n),d=i(a);void 0!==l&&(r=Math.max(l,r)),void 0!==d&&(r=Math.min(d,r)),p.current(r)},[]),j=n.useMemo(()=>void 0===d?v:a.throttle(e=>v(e),d),[d,v]),b=(0,n.useCallback)(()=>{_.current=null,h(!1);const e=j;"function"==typeof e.cancel&&e.cancel(),m?.()},[j,m]),w=(0,n.useCallback)(e=>{const{get_start_size:s,get_pos:t}=x.current;_.current={pos:t(e),size:s()},h(!0)},[]);return(0,n.useEffect)(()=>{if(!g)return;const e=t?.current??window;return e.addEventListener("pointermove",j),e.addEventListener("pointerup",b),()=>{e.removeEventListener("pointermove",j),e.removeEventListener("pointerup",b)}},[g,j,b,t]),(0,n.useEffect)(()=>{const e=j;return()=>{"function"==typeof e.cancel&&e.cancel()}},[j]),{dragging:g,on_pointer_down:w,on_pointer_up:b}}},60840(e){e.exports="data:image/svg+xml,<svg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 version=%271.1%27 aria-hidden=%27true%27><path fill-rule=%27evenodd%27 d=%27M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z%27></path></svg>"}}]);
|
|
1
|
+
"use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[6010,6104],{83277(e,s,t){t.d(s,{$j:()=>o,CP:()=>a,Lv:()=>n,cL:()=>i});class n{token;open=!1;note;index;url;model;request_type;json_params;sys_prompt;dotenv="";yaml_env="";tool_mode=!1;show_options;static get_label_by_v(e,s){if(!e||!s?.length)return e;for(const t of s)if(t.value===e)return t.label;return e}static have_label_by_v(e,s){if(!e||!s?.length)return!1;for(const t of s)if(t.value===e)return!0;return!1}}const a="\n# 聊天循环最大次数\ntool_call_max: 500\n\n# 是否允许AI直接执行命令而不需要用户确认。\n# 默认为 false,需要用户手动确认;使用 workflow 时等价于 true。\nallow_exec_cmd_directly: false\n\n# 可选的大模型请求代理地址\n# proxy_url: http://127.0.0.1:7890\n\n# 可选的多个 url\n# options_agent_url_list:\n# - value: http://...\n# label: openai\n\n# 可选的多个 key\n# options_agent_key_list:\n# - value: sk-aaa\n# label: option1\n\n# 可选的多个 model\n# options_agent_model_list:\n# - value: gpt-5.5\n# label: gpt\n\n# 本地 prompt 文件列表,每次聊天时自动读取并加载\n# options_local_file_path_prompt_list:\n# - /prompt/a.txt\n\n# 开启切换模型,AI 可以根据 prompt 自己决定下一步调用哪个模型\n# open_pick_model: false\n\n# 历史消息裁剪相关\nmax_recent_messages: 12\ncompress_message_count: 16\nmax_tool_content_chars: 200\n\n# ===== 模型类型(request_type)=====\n# 默认 completions,可选值:\n# completions 标准对话/聊天补全 (chat/completions)\n# images 图片生成 (images/generations)\n# audio_speech 文本转语音 (audio/speech)\n# audio_transcription 语音转文字 (audio/transcriptions)\n# audio_translation 语音翻译 (audio/translations)\n# embeddings 向量嵌入 (embeddings)\n# request_type: completions\n\n# ===== 成为 tool(tool_mode)=====\n# 开启后该模型会作为一个工具被加载,供 AI agent 动态调用。\n# 注意:不能与「是否开启」(open) 同时为 true。\n# tool_mode: false\n\n# ===== 图片理解(image_understanding)=====\n# 开启后注册 read_image 工具,工具读到的图片会以 image_url 多模态格式随消息发给模型。\nimage_understanding: true\n\n# ===== 命令环境变量(command_env)=====\n# AI 调用内置命令工具(exec_cmd / exec_cmd_background)执行命令时,\n# 这里配置的变量会覆盖到子进程的环境变量上。\n# command_env:\n# NODE_ENV: production\n# HTTP_PROXY: http://127.0.0.1:7890\n\n# 是否允许 AI 通过 set_command_env 工具修改上面的 command_env\ncommand_env_tool: false\n";const i=JSON.stringify({stream:!0,thinking:{type:"disabled"}});function o(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>"text"===e.type?e.text:"[图片]").join("\n"):""}},69857(e,s,t){t.r(s),t.d(s,{default:()=>le});var n=t(96540),a=t(34843),i=t(22022),o=t(52671),c=t(14284),r=t(7463),l=t(78247),d=t(53459),u=t(72693),m=t(82893),g=t(61443),h=t(83277);function _(e){return null==e||e<0?"0":e.toLocaleString()}var p=t(14944),f=t(92275),x=t(62042);function v(e){const s=[];if(e.attachments?.length&&s.push(e.attachments.map(e=>`[附件] ${e.name}`).join("\n")),e.content_list?.length)for(const t of e.content_list){const e=(0,h.$j)(t.content);if(e&&s.push(e),t.tool_call_ends?.length){const e=t.tool_call_ends.map(e=>{const s=e.tool_display_name||e.tool_name;return e.success?`[工具] ${s} 成功`:`[工具] ${s} 失败`});s.push(e.join("\n"))}}return e.text&&!s.length&&s.push(e.text),e.images?.length&&s.push(`[生成图片 ${e.images.length} 张]`),e.audio&&s.push("[音频]"),s.join("\n\n")}function j(e){const s=(0,h.$j)(e.content);if(s)return s;const t=e.content_list??[];return t.length?t.map(e=>(0,h.$j)(e.content)).filter(Boolean).join("\n\n"):""}let b=0;function w(){return-++b}function y(e=[]){let s=0;return e.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({id:++s,sender:"assistant"===e.role?"bot":"user",text:j(e),attachments:e.attachments??[],content_list:e.content_list??(e.tool_call_ends?.length?[{tool_call_ends:e.tool_call_ends,content:j(e),role:"assistant"}]:void 0),images:e.images,audio:e.audio,embeddings:e.embeddings,elapsed_ms:e.elapsed_ms}))}const S=/\.(md|txt|json|js|jsx|ts|tsx|css|html?|xml|ya?ml|py|java|go|rs|c|cpp|h|hpp|sh|bat|cmd|ini|toml|csv|log|sql|env|gitignore|dockerfile)$/i;function N(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||S.test(e.name)?"text":"binary"}function k(e){return e.text()}function C(e){return new Promise((s,t)=>{const n=new FileReader;n.onload=()=>s(n.result),n.onerror=t,n.readAsDataURL(e)})}async function A(e){const s=[];for(const t of e){const e=N(t);let n="";if("text"===e)try{const e=await k(t),s=12e4;n=e.length>s?`${e.slice(0,s)}\n\n[内容已截断,原始长度 ${e.length} 字符]`:e}catch{n="[文本读取失败]"}else if("image"===e)try{n=await C(t)}catch{n=`[图片文件: ${t.name}]`}else n=`[二进制文件: ${t.name}]`;s.push({name:t.name,mime_type:t.type,size:t.size,kind:e,content:n})}return s}function M(e){return"bot"!==e.sender||!!(e.text||e.content_list?.length||e.attachments?.length)}var I=t(21499),$=t(64694),R=t(45907),B=t(74848);var T=t(40505);function D(e){const{active_session_id_ref:s,local_owner_ref:t,subscribed_ref:a,set_messages:i,scroll_to_bottom:o,follow_ref:c,mark_session_running:r,refresh_sessions:l,reload_session:d,set_active_session_running:u}=e,m=(0,n.useRef)(new Map);return(0,n.useEffect)(()=>{const e=()=>s.current,n=(s,n)=>{if(r(s,!1),e()&&e()===s){if(m.current.clear(),u(!1),a.current===s&&(p.ws.sendData(f.HK.ai_chat_subscribe,{session_id:s,subscribe:!1}),a.current=null),t.current===s)return void(t.current=null);n?.length?i(e=>{let s=e.length;for(;s>0&&"bot"===e[s-1].sender;)s--;return[...e.slice(0,s),...y(n)].map((e,s)=>({...e,id:s+1}))}):d(s).catch(()=>{})}l()},g=s=>{const n=s?.context||{};n.session_id&&(((s,n,a,r,l=0)=>{e()&&e()===s&&t.current!==s&&i(e=>{const s=m.current,t=r?-(l+1):l;let i=e;if(!r){const e=-(l+1),t=s.get(e);void 0!==t&&(i=i.filter(e=>e.id!==t),s.delete(e))}const d=s.get(t),u=void 0===d?-1:i.findIndex(e=>e.id===d),g=-1===u?{id:w(),sender:"bot",text:""}:{...i[u]};if(-1===u&&s.set(t,g.id),r)g.text=n,g.is_loading=!0;else if(n){g.text=g.text+n;const e=g.content_list?.[0];e&&(e.content=g.text),g.is_loading=!1}if(a&&(g.content_list=[{tool_call_ends:a,content:g.text,role:"assistant"}],g.is_loading=!1),c.current&&requestAnimationFrame(()=>o()),-1===u)return[...i,g];const h=i.slice();return h[u]=g,h})})(n.session_id,n.text||"",n.tool_call_ends,n.notice,n.chunk_index),r(n.session_id,!0))},h=e=>{const s=e?.context||{};s.session_id&&n(s.session_id,s.once_messages_list)},_=e=>{const s=e?.context||{};s.session_id&&n(s.session_id,s.once_messages_list)};return p.ws.addMsg(f.HK.ai_chat_msg,g),p.ws.addMsg(f.HK.ai_chat_end,h),p.ws.addMsg(f.HK.ai_chat_error,_),()=>{p.ws.off_message(`message_${f.HK.ai_chat_msg}`,g),p.ws.off_message(`message_${f.HK.ai_chat_end}`,h),p.ws.off_message(`message_${f.HK.ai_chat_error}`,_),a.current&&(p.ws.sendData(f.HK.ai_chat_subscribe,{session_id:a.current,subscribe:!1}),a.current=null)}},[]),{chunkBubbleRef:m,bind_live_bubbles:(e,s)=>{m.current.clear();for(let t=0;t<s;t++){const n=e[e.length-s+t];n&&m.current.set(t,n.id)}},clear_bubbles:()=>m.current.clear()}}var H=t(85997),E=t(34299);function V(e){const s=e.attachments&&e.attachments.length>0?(0,B.jsx)("div",{className:"chat-message-attachments",children:e.attachments.map((e,s)=>(0,B.jsxs)("div",{className:"chat-message-attachment",children:[(0,B.jsx)(H.In,{icon:"attach_file"}),(0,B.jsx)("span",{children:e.name}),(0,B.jsxs)("small",{children:[e.size," B"]})]},`${e.name}_${s}`))}):null,t=[];e.images&&"bot"===e.sender&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(P,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(L,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(F,{embeddings:e.embeddings,text:e.text})},"embeddings"));const a=function(e){if("bot"!==e.sender||!e.content_list?.length)return e.text?(0,B.jsx)(E.default,{context:e.text}):null;return(0,B.jsxs)(B.Fragment,{children:[e.content_list.map((e,s)=>{const t=[],a=(0,h.$j)(e.content);return a&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(E.default,{context:a})},`content-${s}`)),e.tool_call_ends?.length&&t.push((0,B.jsx)(n.Fragment,{children:(0,B.jsx)(K,{callList:e.tool_call_ends})},`tool-${s}`)),(0,B.jsx)(n.Fragment,{children:t},`part-${s}`)}),!e.content_list.some(e=>e.content)&&e.text?(0,B.jsx)(E.default,{context:e.text}):null]})}(e);return 0===t.length?(0,B.jsxs)(B.Fragment,{children:[s,a]}):(0,B.jsxs)(B.Fragment,{children:[t,s,a]})}function K({callList:e}){const[s,t]=n.useState(!1);if(!e?.length)return null;e.filter(e=>e.success).length;const a=e.filter(e=>!e.success).length;return(0,B.jsxs)("div",{className:"chat-message-call-list",children:[(0,B.jsxs)("div",{className:"call-list-header",onClick:()=>t(!s),children:[(0,B.jsx)(H.In,{icon:s?"expand_less":"expand_more"}),(0,B.jsxs)("span",{className:"call-list-summary",children:["工具调用 (",e.length,")",a>0&&(0,B.jsx)("span",{className:"call-list-fail",children:" 失败 "})]})]}),s&&(0,B.jsx)("div",{className:"call-list-body",children:e.map((e,s)=>(0,B.jsxs)("div",{className:"call-list-item "+(e.success?"call-success":"call-fail"),children:[(0,B.jsxs)("div",{className:"call-list-item-header",children:[(0,B.jsx)(H.In,{icon:e.success?"check_circle":"error"}),(0,B.jsx)("span",{className:"call-list-tool-name",children:e.tool_display_name||e.tool_name}),(0,B.jsxs)("span",{className:"call-list-duration",children:[e.duration_ms,"ms"]})]}),e.tool_args&&(0,B.jsxs)("details",{className:"call-list-details",children:[(0,B.jsx)("summary",{children:"参数"}),(0,B.jsx)("pre",{className:"call-list-pre",children:JSON.stringify(e.tool_args,null,2)})]}),!e.success&&e.error&&(0,B.jsxs)("details",{className:"call-list-details",children:[(0,B.jsx)("summary",{children:"错误"}),(0,B.jsx)("pre",{className:"call-list-pre call-list-error-text",children:e.error})]}),e.success&&e.tool_result&&(0,B.jsxs)("details",{className:"call-list-details",children:[(0,B.jsx)("summary",{children:"结果"}),(0,B.jsx)("pre",{className:"call-list-pre",children:e.tool_result.length>500?e.tool_result.slice(0,500)+"...":e.tool_result})]})]},s))})]})}function P({images:e,text:s}){let t=e||[];if(!t.length&&s)try{t=JSON.parse(s).data||[]}catch{}return t.length?(0,B.jsxs)("div",{className:"image-generation-result",children:[t.map((e,s)=>(0,B.jsxs)("div",{className:"image-generation-item",children:[e.url&&(0,B.jsx)("div",{className:"image-generation-image-wrapper",children:(0,B.jsx)("img",{src:e.url,alt:e.revised_prompt||`生成的图片 ${s+1}`,loading:"lazy"})}),e.b64_json&&(0,B.jsx)("div",{className:"image-generation-image-wrapper",children:(0,B.jsx)("img",{src:`data:image/png;base64,${e.b64_json}`,alt:`生成的图片 ${s+1}`})}),e.revised_prompt&&(0,B.jsx)("p",{className:"image-generation-prompt",children:(0,B.jsx)("small",{children:e.revised_prompt})})]},s)),s&&!e&&(0,B.jsx)(E.default,{context:s})]}):(0,B.jsx)(E.default,{context:s||""})}function L({audio:e,text:s}){if(e){if(e.url)return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:e.url,children:"您的浏览器不支持音频播放"})});if(e.data){const s=e.mime_type||"audio/mpeg";return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:`data:${s};base64,${e.data}`,children:"您的浏览器不支持音频播放"})})}}const t=s||"";if(t.startsWith("http://")||t.startsWith("https://"))return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:t,children:"您的浏览器不支持音频播放"})});try{const e=JSON.parse(t);if(e?.data||e?.audio_data){const s=e.data||e.audio_data;return(0,B.jsx)("div",{className:"audio-result",children:(0,B.jsx)("audio",{controls:!0,src:`data:audio/mpeg;base64,${s}`,children:"您的浏览器不支持音频播放"})})}}catch{}return(0,B.jsx)(E.default,{context:t})}function z({content:e,label:s}){const[t,a]=n.useState(!1);return(0,B.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,T.lW)(e),a(!0),setTimeout(()=>a(!1),1500)},children:[(0,B.jsx)(H.In,{icon:t?"check":"content_copy"}),t?"已复制":s||"复制"]})}function F({embeddings:e,text:s}){let t=e||null;if(!t&&s)try{t=JSON.parse(s)}catch{return(0,B.jsx)(E.default,{context:s})}if(!t)return(0,B.jsx)(E.default,{context:s||""});const n=t?.data||[],a=t?.usage,i=JSON.stringify(t,null,2);return(0,B.jsxs)("div",{className:"embeddings-result",children:[(0,B.jsxs)("div",{className:"embeddings-summary",children:[(0,B.jsx)("strong",{children:"向量嵌入结果"}),(0,B.jsxs)("span",{children:["维度: ",n[0]?.embedding?.length??"N/A"]}),(0,B.jsxs)("span",{children:["数量: ",n.length]}),a&&(0,B.jsxs)("span",{children:["使用 tokens: ",a.total_tokens??"N/A"]})]}),(0,B.jsxs)("div",{className:"embeddings-toolbar",children:[(0,B.jsx)(z,{content:i,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,B.jsx)(z,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,B.jsx)(z,{content:JSON.stringify(n.map(e=>e.embedding),null,2),label:"复制所有向量数据"})]}),n.length>0&&n[0]?.embedding&&(0,B.jsx)("div",{className:"embeddings-preview",children:(0,B.jsxs)("span",{children:["向量预览: [",n[0].embedding.slice(0,5).join(", "),n[0].embedding.length>5?", ...":"","]"]})}),n.length>0&&(0,B.jsxs)("details",{children:[(0,B.jsx)("summary",{children:"查看详细数据"}),(0,B.jsx)("pre",{className:"embeddings-raw",children:i})]})]})}async function O(e,s,t,n){try{switch(e){case"images":{const e=await async function(e,s){const t={prompt:e,session_id:s},n=await c.jV.post("images/generations",t);if(0!==n.code)throw new Error(n.message||"图片生成失败");const a=n.data||{},i=(a.data||[]).map(e=>({url:e.url,b64_json:e.b64_json,revised_prompt:e.revised_prompt})),o=i.map((e,s)=>`${e.revised_prompt?`\n> ${e.revised_prompt}`:""}`).join("\n\n");return{session_id:a.session_id||s,images:i,text:o||`生成了 ${i.length} 张图片`}}(s,t);return e&&n(e.text,{images:e.images}),!0}case"audio_speech":{const e=await async function(e,s){const t={input:e,session_id:s};try{const e=localStorage.getItem("ai_audio_extra_params");if(e){const s=JSON.parse(e);s.voice&&(t.voice=s.voice),s.speed&&(t.speed=parseFloat(s.speed))}}catch{}const n=localStorage.getItem("token")||"",a=await fetch("/api/ai_agent/audio/speech",{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(t)});if(!a.ok)throw new Error(`语音合成失败: ${a.statusText}`);const i=a.headers.get("X-Session-Id")||s,o=await a.arrayBuffer();return{session_id:i,audio:{data:btoa(String.fromCharCode(...Array.from(new Uint8Array(o)))),mime_type:a.headers.get("content-type")||"audio/mpeg"},text:`[音频文件: ${e.slice(0,50)}...]`}}(s,t);return e&&n(e.text,{audio:e.audio}),!0}case"embeddings":{const e=await async function(e,s){const t=await c.jV.post("embeddings",{input:e,session_id:s});if(0!==t.code)throw new Error(t.message||"Embeddings 请求失败");const n=t.data||{},a=n?.data??[],i=`向量维度: ${a[0]?.embedding?.length??0}, 数量: ${a.length}`;return{session_id:n.session_id||s,embeddings:n,text:`✅ Embeddings 结果 - ${i}\n\`\`\`json\n${JSON.stringify(n,null,2).slice(0,2e3)}\n\`\`\``}}(s,t);return e&&n(e.text,{embeddings:e.embeddings}),!0}default:return!1}}catch(e){return n(`请求失败: ${e?.message||JSON.stringify(e)}`),!0}}var q=t(4412),U=t(23430),G=t(87361),J=t(80389),W=t(7523),Q=t(23496);const X=({currentModelName:e,setCurrentModelName:s,modelGroups:t,onModelChanged:r,batchMode:u,selectedMsgCount:h,sessionVisible:_,onToggleSessionPanel:p,onCreateSession:f,onToggleBatchMode:v,onBatchDeleteMessages:j,bgProcessVisible:b,bgProcessCount:w,onToggleBgProcess:y,inline:S})=>{const{t:N}=(0,i.Bd)(),k=(0,o.Zp)(),{check_user_auth:C}=(0,l.MH)(),[,A]=(0,a.fp)(m.AG.ai_session_collapsed),{open:M}=function(){const{t:e}=(0,i.Bd)(),[,s]=(0,a.fp)(m.AG.prompt_card),[t,o]=(0,a.fp)(m.AG.ai_chat_zoom),{initUserInfo:r}=(0,n.useContext)(W.F);return{open:()=>{const n=t,a=()=>s({open:!1});s({open:!0,title:e("缩放调整"),context_div:(0,B.jsx)(J.p,{defaultValue:t,onChange:o,min:30,max:200}),cancel:()=>{o(n),a()},confirm:async()=>{let s=100;o(e=>(s=e<30||e>200?100:e,s)),await c.wm.post(Q.s.user_save_private_attr,{is_ai_chat_zoom:!0,ai_chat_zoom:s}),(0,x.SK)(e("缩放调整成功")),r(),a()}})}}}(),I=C(U.oV.ai_model_switch)||C(U.oV.ai_agent_setting),$=[];for(const e of t)for(const s of e.models)$.push({title:s.label||s.value,value:`${e.index}::${s.value}`,group:e.note});const R=t.find(e=>e.active),T=R?`${R.index}::${e}`:"",D=(0,B.jsxs)(n.Fragment,{children:[(0,B.jsx)(H.rA,{icon:"menu",title:N("会话"),onClick:p,selected:_}),(0,B.jsx)(H.rA,{icon:"add",title:N("新会话"),onClick:()=>f()}),I&&$.length>0&&(0,B.jsx)(g.l6,{value:T,options:[{title:N("选择模型"),value:""},...$],margin:"0 0 0 1em",onChange:e=>{const t=String(e??"");if(!t.includes("::"))return;const[n,...a]=t.split("::"),i=a.join("::");i&&(s(i),c.jV.post("set_active_model",{index:Number(n),model_name:i}).then(e=>{e?.code===d.m.Success?((0,x.SK)("success"),r()):(0,x.zN)(e?.message||"fail")}).catch(console.error))},no_border:!0,width:"auto"}),u&&(0,B.jsx)(H.rA,{icon:"done",title:N("完成"),onClick:v}),u&&h>0&&(0,B.jsx)(H.rA,{icon:"delete",title:N("删除选中消息"),onClick:j}),(0,B.jsx)(H.rA,{icon:"zoom_in",title:N("缩放调整"),onClick:M}),(0,B.jsx)(H.rA,{icon:"terminal",title:N("后台进程"),onClick:y,selected:b,tip:w||null}),C(U.oV.ai_agent_setting)&&(0,B.jsx)(H.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{k(G.o.ai_rebot_setting_page)}}),C(U.oV.ai_agent_setting)&&(0,B.jsx)(H.rA,{icon:"settings",title:"ai setting",onClick:()=>{k(G.o.ai_agent_setting_page)}})]});return S?(0,B.jsx)("div",{className:"chat-inline-header",children:D}):(0,B.jsx)(q.aZ,{position:"right",children:D})};var Y=t(75725);function Z({items:e}){const s=e.filter(e=>!!e.text);return 0===s.length?null:(0,B.jsx)("div",{className:"chat-session-meta",children:s.map((e,s)=>(0,B.jsx)("small",{className:e.className,title:e.title,children:e.text},s))})}function ee(e){return e||"新会话"}function se({sessions:e,activeSessionId:s,onSelectSession:t,onReorderSessions:a,onRenameSession:o,onDeleteSession:c,onToggleCmdAuto:r,onShowUsageStats:l,onShowSessionSetting:d,batchMode:u,selectedSessionIds:m,onToggleSessionSelect:g,onToggleBatchMode:h,onBatchDeleteSessions:_,onClearAllSessions:p,allUsersMode:f,onToggleAllUsersMode:x,showAllUsersEntry:v,sysPromptList:j,onChangeSysPrompt:b}){const{t:w}=(0,i.Bd)(),[y,S]=(0,n.useState)(""),N=(0,n.useRef)(null),[k,C]=(0,n.useState)(null),[A,M]=(0,n.useState)(null),[I,$]=(0,n.useState)(null),R=!!a&&!f,T=e=>{if(!e)return"";const s=j?.find(s=>String(s.index)===String(e));return s?s.note||s.prompt.slice(0,20):""},D=e=>[{text:String(e.message_count??""),className:"chat-session-meta__count",title:w("消息数")},{text:T(e.sys_prompt_id),className:"chat-session-meta__prompt",title:w("系统提示词")},{text:"web"!==e.source?e.source:"",className:"chat-session-meta__source",title:w("来源")},{text:f&&e.owner_name||"",className:"chat-session-meta__owner",title:e.owner_name}],E=y.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(y.toLowerCase())||(e.summary||"").toLowerCase().includes(y.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(y.toLowerCase())||f&&(e.owner_name||"").toLowerCase().includes(y.toLowerCase())):e,V=e.find(e=>e.id===s);return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("aside",{className:"chat-session-list",children:[(0,B.jsxs)("div",{className:"chat-session-search",children:[(0,B.jsx)("input",{type:"text",className:"chat-session-search-input",placeholder:w("搜索会话"),value:y,onChange:e=>S(e.target.value)}),V&&(0,B.jsx)("button",{className:"chat-session-current",title:ee(V.title),onClick:()=>(e=>{const s=()=>{const s=N.current,t=s?.querySelector(`[data-session-id="${e}"]`);t&&t.scrollIntoView({block:"center",behavior:"smooth"})};if(!E.some(s=>s.id===e))return S(""),void requestAnimationFrame(()=>requestAnimationFrame(s));s()})(V.id),children:(0,B.jsx)("span",{children:ee(V.title)})})]}),(0,B.jsx)("div",{className:"chat-session-items-wrap",ref:N,children:E.map((e,n)=>(0,B.jsx)("div",{"data-session-id":e.id,children:(0,B.jsxs)("button",{className:`chat-session-item ${s===e.id?"active":""} ${u?"batch-mode":""} ${e.running?"is-running":""} ${k===n?"row-dragging":""} ${A===n&&null!==k&&k!==n?"row-drop-target":""}`,draggable:R,onDragStart:()=>C(n),onDragOver:e=>{null!==k&&(e.preventDefault(),A!==n&&M(n))},onDragEnd:()=>{C(null),M(null)},onDrop:e=>{e.preventDefault(),(e=>{const s=k;if(C(null),M(null),null===s||s===e||!a)return;const t=E[s]?.id,n=E[e]?.id;t&&n&&a(t,n)})(n)},onClick:()=>{u&&g?g(e.id):t(e.id)},title:e.summary||e.long_term_memory||e.title,children:[u&&(0,B.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:m?.has(e.id)??!1,onChange:()=>g?.(e.id),onClick:e=>e.stopPropagation()}),(0,B.jsx)("span",{children:ee(e.title)}),e.running&&(0,B.jsx)("span",{className:"chat-session-running",title:w("正在执行中")}),(0,B.jsx)(Z,{items:D(e)}),!u&&(0,B.jsx)("i",{className:"chat-session-more material-icons",title:w("更多操作"),onClick:s=>{s.stopPropagation();const t=s.currentTarget.getBoundingClientRect();$({x:t.right,y:t.bottom,session:e})},children:"more_horiz"})]})},e.id))}),(0,B.jsxs)("div",{className:"chat-session-actions",children:[(0,B.jsx)(H.rA,{icon:u?"check_circle":"checklist",title:w(u?"取消批量选择":"批量选择"),onClick:h}),v&&!u&&(0,B.jsx)(H.rA,{icon:f?"person":"groups",title:w(f?"仅看我的会话":"查看所有用户会话"),onClick:x}),u&&(m?.size??0)>0&&(0,B.jsx)(H.rA,{icon:"delete",title:w("删除选中会话"),onClick:_}),!u&&p&&(0,B.jsx)(H.rA,{icon:"delete_sweep",title:w("删除全部会话"),onClick:p})]})]}),I&&(0,B.jsx)(Y.rY,{click:()=>$(null),children:(0,B.jsx)(Y.sw,{x:I.x,y:I.y,items:(e=>{const s=[{r:w("重命名"),v:"rename",run:()=>o(e.id,e.title)},...f?[]:[{r:w("移动到最上"),v:"to_top",run:()=>{const s=E[0];s&&s.id!==e.id&&a?.(e.id,s.id)}},{r:w("移动到最下"),v:"to_bottom",run:()=>{const s=E[E.length-1];s&&s.id!==e.id&&a?.(e.id,s.id)}}],{r:e.cmd_auto_allow?w("命令检测关闭"):w("命令检测开启"),v:"cmd_auto",run:()=>r?.(e.id,!e.cmd_auto_allow)}];return j?.length&&s.push({r:w("系统提示词"),items:[{r:w("不使用"),v:"",run:()=>b?.(e.id,"")},...j.map(s=>({r:T(String(s.index)),v:String(s.index),run:()=>b?.(e.id,String(s.index))}))]}),s.push({r:w("字符消耗统计"),v:"usage",run:()=>l(e.id)},{r:w("设置"),v:"setting",run:()=>d?.(e.id)},{r:w("删除"),v:"delete",run:()=>c(e.id)}),s})(I.session),pre_value:I.session.sys_prompt_id?String(I.session.sys_prompt_id):"",click:(e,s)=>{$(null),s?.run?.()}})})]})}function te(e){const s=(e.text||"").split("\n").map(e=>e.trim()).find(Boolean)||"";return s.length>80?s.slice(0,80)+"…":s}const ne=({messages:e,batchMode:s,selectedMsgIds:t,sending:a,chatContainerRef:i,messagesEndRef:o,onToggleMsgSelect:c,onDelete:r,onCopy:l,onCopyAll:d,onToggleBatchMode:u,onBatchCopy:m,onBatchDelete:g,showBatchBar:h,t:_})=>{const[p,f]=(0,n.useState)(new Set),x=(0,n.useMemo)(()=>e.filter(e=>!e.is_loading).map(e=>e.id),[e]),v=e=>{f(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},j=()=>{f(e=>e.size>0&&x.every(s=>e.has(s))?new Set:new Set(x))};return(0,B.jsxs)("div",{className:"chat-messages",ref:i,"data-sending":a?"true":"false",children:[h&&(0,B.jsxs)("div",{className:"chat-message-batch-bar",children:[(0,B.jsxs)("span",{className:"batch-bar-count",children:[_("已选")," ",t.size]}),(0,B.jsx)("button",{onClick:m,children:_("复制所选")}),(0,B.jsx)("button",{onClick:g,className:"danger",children:_("删除所选")}),(0,B.jsx)("button",{onClick:u,children:_("取消")})]}),e.map(e=>{const n=p.has(e.id);return(0,B.jsxs)("div",{className:`chat-message ${e.sender} ${s?"batch-mode":""} ${e.is_loading?"is-loading":""} ${n?"collapsed":""}`,children:[s&&(0,B.jsx)("input",{type:"checkbox",className:"chat-message-checkbox",checked:t.has(e.id),onChange:()=>c(e.id)}),e.is_loading?(0,B.jsxs)("div",{className:"ai-loading-bubble",children:[(0,B.jsxs)("div",{className:"ai-loading-dots",children:[(0,B.jsx)("span",{className:"ai-loading-dot"}),(0,B.jsx)("span",{className:"ai-loading-dot"}),(0,B.jsx)("span",{className:"ai-loading-dot"})]}),(0,B.jsx)("span",{className:"ai-loading-text",children:e.text})]}):(0,B.jsxs)(B.Fragment,{children:[n?(0,B.jsxs)("div",{className:"chat-message-summary",title:e.text,onClick:()=>v(e.id),children:[(0,B.jsx)("span",{className:"chat-message-summary-icon",children:"▸"}),(0,B.jsx)("span",{className:"chat-message-summary-text",children:te(e)||_("(无内容)")})]}):(0,B.jsx)("div",{className:"chat-message-body",children:V(e)}),(0,B.jsxs)("div",{className:"message-actions",children:[(0,B.jsx)("button",{onClick:()=>r(e.id),children:_("删除")}),(0,B.jsx)("button",{onClick:()=>l(e),children:_("复制")}),(0,B.jsx)("button",{onClick:d,children:_("全部复制")}),(0,B.jsx)("button",{onClick:u,children:_("多选")})]}),(0,B.jsxs)("div",{className:"message-collapse-bar",children:[(0,B.jsx)("button",{onClick:()=>v(e.id),children:_(n?"展开":"折叠")}),(0,B.jsx)("button",{onClick:j,children:_("全部折叠")}),"bot"===e.sender&&null!=e.elapsed_ms&&(0,B.jsx)("span",{className:"message-elapsed",children:(0,I.kf)(e.elapsed_ms)})]})]})]},e.id)}),(0,B.jsx)("div",{ref:o})]})},ae=(0,n.forwardRef)(function({placeholder:e="",disabled:s=!1,className:t,style:a,onEnter:i,onPaste:o,onChange:c},r){const l=(0,n.useRef)(null),[d,u]=(0,n.useState)(!0),[m,g]=(0,n.useState)(!1),h=(0,n.useCallback)(()=>{const e=l.current;return e?(e.textContent??"").replace(/\u00A0/g," ").trimEnd():""},[]);(0,n.useImperativeHandle)(r,()=>({getValue:()=>h(),setValue:e=>{const s=l.current;if(!s)return;s.textContent=e,u(!e);const t=document.createRange();t.selectNodeContents(s),t.collapse(!1);const n=window.getSelection();n?.removeAllRanges(),n?.addRange(t)},clear:()=>{const e=l.current;e&&(e.textContent="",u(!0))},focus:()=>l.current?.focus()})),(0,n.useEffect)(()=>{const e=l.current;if(!e)return;const s=()=>u(!e.textContent);return e.addEventListener("input",s),()=>e.removeEventListener("input",s)},[]);return(0,B.jsx)("div",{ref:l,contentEditable:!s,suppressContentEditableWarning:!0,className:"rich-textarea"+(t?" "+t:""),style:a,onKeyDown:e=>{m||"Enter"!==e.key||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),i?.())},onPaste:o,onInput:()=>c?.(h()),onCompositionStart:()=>g(!0),onCompositionEnd:()=>g(!1),"data-placeholder":d?e:void 0})});var ie=t(84369);function oe({pendingAttachments:e,onRemove:s}){return 0===e.length?null:(0,B.jsx)("div",{className:"chat-attachment-strip",children:e.map((e,t)=>(0,B.jsxs)("div",{className:"chat-attachment-chip",children:[(0,B.jsx)(H.In,{icon:"attach_file"}),(0,B.jsx)("span",{title:e.name,children:e.name}),(0,B.jsx)("button",{type:"button",onClick:()=>s(t),children:(0,B.jsx)(H.In,{icon:"close"})})]},`${e.name}_${t}`))})}const ce=(0,n.forwardRef)(({onSend:e,sending:s,onAbort:t,pendingAttachments:o,onRemoveAttachment:c,onOpenFilePicker:r,onAddFiles:l,onDrop:d,onDragOver:u,fileInputRef:g,readonly:h=!1},_)=>{const{t:p}=(0,i.Bd)(),f=(0,n.useRef)(null),x=(0,n.useRef)(null),[v,j]=(0,a.fp)(m.AG.ai_chat_input_height);(0,n.useImperativeHandle)(_,()=>({getValue:()=>f.current?.getValue()??"",setValue:e=>f.current?.setValue(e),clear:()=>f.current?.clear()}));const{dragging:b,on_pointer_down:w,on_pointer_up:y}=(0,ie.y)({direction:"vertical",get_start_size:()=>v,px_to_unit:e=>e/(()=>{const e=x.current;return e&&parseFloat(getComputedStyle(e).fontSize)||16})(),min:2,on_change:e=>j(e)}),S={minHeight:`${v}em`,maxHeight:`${v}em`};return(0,B.jsxs)("div",{ref:x,className:"chat-input-area"+(h?" readonly":""),onDrop:h?void 0:d,onDragOver:h?void 0:u,children:[!h&&(0,B.jsx)("div",{className:"chat-input-resize-handle"+(b?" dragging":""),onPointerDown:w}),(0,B.jsx)("input",{ref:g,type:"file",multiple:!0,style:{display:"none"},onChange:e=>{e.target.files?.length&&(l(e.target.files),e.currentTarget.value="")}}),(0,B.jsxs)("div",{className:"chat-input-shell",children:[(0,B.jsx)(oe,{pendingAttachments:o,onRemove:c}),(0,B.jsx)(ae,{ref:f,placeholder:p(h?"查看全部会话时不可发送消息":"输入消息"),disabled:h,onEnter:()=>e(),onPaste:e=>{const s=e.clipboardData?.files;s&&s.length>0&&(e.preventDefault(),l(s))},className:"chat-input",style:S})]}),!h&&(0,B.jsx)(H.rA,{title:p("添加文件"),icon:"attach_file",onClick:r}),h?(0,B.jsx)("button",{className:"little-button button",disabled:!0,children:p("发送")}):s?(0,B.jsx)(H.Vi,{color:"var( --icon-red)",text:p("暂停"),clickFun:t}):(0,B.jsx)(H.Vi,{text:p("发送"),clickFun:e}),b&&(0,B.jsx)("div",{className:"chat-input-overlay",onPointerUp:y})]})}),re=function(e){const{t:s}=(0,i.Bd)(),[t,o]=(0,n.useState)([]),[c,r]=(0,n.useState)(!1),[l,d]=(0,n.useState)(null),[u,g]=(0,n.useState)(null),[h,_]=(0,n.useState)(!1),[v,j]=(0,a.fp)(m.AG.ai_bg_expanded),[,b]=(0,a.fp)(m.AG.ai_session_collapsed),w=()=>{j(!1)},y=(0,n.useCallback)(async()=>{r(!0);try{const s=new f.hf(f.HK.ai_bg_process_list_req);s.context={};const t=await p.ws.send(s);t?.context?.processes&&(o(t.context.processes),e.panelRef?.current?.onCountChange?.(t.context.processes.length))}catch(e){console.error("获取后台进程列表失败",e)}finally{r(!1)}},[]);e.panelRef&&(e.panelRef.current.refresh=y);const S=(0,n.useCallback)(async e=>{_(!0),d(e);try{const s=new f.hf(f.HK.ai_bg_process_output_req);s.context={pid:e};const t=await p.ws.send(s);g(t.context)}catch(e){console.error("获取进程输出失败",e),(0,x.zN)("获取进程输出失败")}finally{_(!1)}},[]),N=(0,n.useCallback)(async e=>{try{const s=new f.hf(f.HK.ai_bg_process_kill_req);s.context={pid:e};const t=await p.ws.send(s);t?.context?.success?((0,x.SK)("进程已终止"),y(),l===e&&(d(null),g(null))):(0,x.zN)(t?.context?.message||"终止失败")}catch(e){console.error("终止进程失败",e),(0,x.zN)("终止进程失败")}},[y,l]);(0,n.useEffect)(()=>{y();const e=setInterval(y,5e3);return()=>clearInterval(e)},[y]);const k=t.filter(e=>e.running),C=t.filter(e=>!e.running);return(0,B.jsxs)(B.Fragment,{children:[v&&(0,B.jsx)("div",{className:"chat-session-overlay",onClick:w}),(0,B.jsxs)("aside",{className:"chat-bg-process-panel "+(v?"expanded":""),children:[(0,B.jsxs)("div",{className:"chat-bg-process-header",children:[(0,B.jsx)("span",{className:"chat-bg-process-title",children:s("后台进程")}),(0,B.jsx)(H.rA,{icon:"close",title:s("关闭"),onClick:w})]}),(0,B.jsxs)("div",{className:"chat-bg-process-toolbar",children:[(0,B.jsx)(H.rA,{icon:"refresh",title:s("刷新"),onClick:y}),(0,B.jsxs)("span",{className:"chat-bg-process-count",children:[k.length," ",s("个运行中"),C.length>0&&` / ${C.length} ${s("个已退出")}`]})]}),(0,B.jsxs)("div",{className:"chat-bg-process-list",children:[c&&0===t.length&&(0,B.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}),!c&&0===t.length&&(0,B.jsx)("div",{className:"chat-bg-process-empty",children:s("暂无后台进程")}),k.map(e=>(0,B.jsxs)("div",{className:`chat-bg-process-item ${l===e.pid?"active":""} running`,children:[(0,B.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>S(e.pid),children:[(0,B.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,B.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>40?e.cmd.slice(0,40)+"...":e.cmd}),(0,B.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,B.jsx)("span",{className:"chat-bg-process-status running-dot",title:s("运行中"),children:"●"})]}),(0,B.jsxs)("div",{className:"chat-bg-process-item-actions",children:[(0,B.jsx)(H.rA,{icon:"terminal",title:s("查看输出"),onClick:()=>S(e.pid)}),(0,B.jsx)(H.rA,{icon:"stop",title:s("终止进程"),onClick:()=>N(e.pid)})]})]},e.pid)),C.map(e=>(0,B.jsx)("div",{className:`chat-bg-process-item ${l===e.pid?"active":""} finished`,children:(0,B.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>S(e.pid),children:[(0,B.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,B.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>30?e.cmd.slice(0,30)+"...":e.cmd}),(0,B.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,B.jsxs)("span",{className:"chat-bg-process-exit-code",children:["exit: ",e.exit_code]})]})},e.pid))]}),null!==l&&(0,B.jsxs)("div",{className:"chat-bg-process-output",children:[(0,B.jsxs)("div",{className:"chat-bg-process-output-header",children:[(0,B.jsxs)("span",{children:["PID: ",l," ",s("输出")]}),(0,B.jsx)(H.rA,{icon:"close",title:s("关闭"),onClick:()=>{d(null),g(null)}})]}),(0,B.jsx)("div",{className:"chat-bg-process-output-content",children:h?(0,B.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}):u?(0,B.jsx)("pre",{className:"chat-bg-process-output-pre",children:u.output||s("(无输出)")}):null})]})]})]})};function le(e={}){const{inline_header:s=!1,session_id:t,file_cwd_path:h,sync_url:j=!0,on_session_change:b}=e,{t:S}=(0,i.Bd)(),[N,k]=(0,o.ok)(),C=j&&N.get("session")||"",{check_user_auth:H}=(0,l.MH)();(0,u.w)();const[E]=(0,a.fp)(m.AG.user_base_info),V=!!E?.user_data?.is_root,[K,P]=(0,a.fp)(m.AG.ai_session_collapsed),[L,z]=(0,a.fp)(m.AG.ai_bg_expanded),[F,q]=(0,a.fp)(m.AG.prompt_card),[U]=(0,a.fp)(m.AG.ai_chat_zoom),[G,J]=(0,n.useState)(null),[W,Q]=(0,n.useState)([]),[Y,Z]=(0,n.useState)(new Set),[ee,te]=(0,n.useState)([]),[ae,ie]=(0,n.useState)(""),[oe,le]=(0,n.useState)([]),[de,ue]=(0,n.useState)(0),me=(0,n.useRef)(null),ge=(0,n.useRef)(null),he=(0,n.useRef)(null),_e=(0,n.useRef)({}),pe=(0,n.useRef)({}),fe=(0,n.useRef)(null);(0,n.useEffect)(()=>{fe.current=G},[G]);const xe=(0,n.useRef)(null),ve=(0,n.useRef)([]),je=(0,n.useRef)(""),be=(0,n.useRef)(!1),we=(0,n.useRef)(null),ye=(0,n.useRef)(()=>{}),Se=(0,n.useRef)(null),Ne=function(e){const{admin_call:s,owner_of_session:t,get_sessions:a,activeSessionId:o,admin_mode_ref:r}=e,{t:l}=(0,i.Bd)(),u=(0,R.y)(),[m,g]=(0,n.useState)([]),[h,_]=(0,n.useState)(!1),[p,f]=(0,n.useState)(new Set),j=(0,n.useRef)(null),b=(0,n.useRef)(!0),w=(0,n.useRef)(!1),S=(e=!1)=>{const s=j.current;if(!s||!b.current)return;s.scrollTo({top:s.scrollHeight,behavior:e?"smooth":"auto"});let t=0;const n=()=>{const s=j.current;s&&b.current&&(s.scrollTo({top:s.scrollHeight,behavior:e&&0===t?"smooth":"auto"}),++t<6&&requestAnimationFrame(n))};requestAnimationFrame(n)},N=()=>{w.current=!0};return(0,n.useLayoutEffect)(()=>{w.current&&(w.current=!1,b.current=!0),b.current&&S(!1)},[m]),(0,n.useEffect)(()=>{const e=j.current;if(!e)return;const s=s=>{s.deltaY<0?b.current=!1:e.scrollHeight-(e.scrollTop+e.clientHeight)<4&&(b.current=!0)},t=()=>{e.scrollHeight-(e.scrollTop+e.clientHeight)<4&&(b.current=!0)},n=()=>{b.current&&(e.scrollTop=e.scrollHeight)};e.addEventListener("wheel",s,{passive:!0}),e.addEventListener("scroll",t);const a=new ResizeObserver(n),i=()=>[...e.children].forEach(e=>a.observe(e));i();const o=new MutationObserver(()=>{i(),n()});return o.observe(e,{childList:!0}),()=>{e.removeEventListener("wheel",s),e.removeEventListener("scroll",t),a.disconnect(),o.disconnect()}},[]),{messages:m,setMessages:g,batchMode:h,setBatchMode:_,selectedMsgIds:p,setSelectedMsgIds:f,chatContainerRef:j,followRef:b,isNearBottom:(e,s=120)=>{const{scrollTop:t,scrollHeight:n,clientHeight:a}=e;return n-(t+a)<s},scrollToBottom:S,request_scroll_bottom:N,apply_session:e=>{if(!e)return g([]),void N();let s=e.messages??[];e.live_messages?.length&&(s=[...s,...e.live_messages]),g(y(s)),N()},handleDelete:e=>{u({sub_title:l("cf_one"),confirm_fun:async()=>{const n=m.findIndex(s=>s.id===e);if(n<0)return;if(g(m.filter(s=>s.id!==e)),!o)return;const a=t(o);a?s("message_delete",{session_id:o,user_id:a,indices:[n]}).catch(console.error):c.jV.post("session/message/delete",{session_id:o,indices:[n]}).catch(console.error)}})},handleCopy:async e=>{(0,T.lW)(v(e)),(0,x.SK)("复制成功")},handleCopyAll:async()=>{const e=a();if(!e.length)return void(0,x.SK)("暂无聊天记录");const t=[];for(const n of e){const e=n.user_id?await s("get",{session_id:n.id,user_id:n.user_id}):await c.jV.post("session/get",{session_id:n.id});if(e.code!==d.m.Success||!e.data)continue;const a=e.data,i=y([...a.messages??[],...a.live_messages??[]]).map(v).filter(Boolean).join("\n\n\n");i&&t.push(i)}t.length?((0,T.lW)(t.join("\n\n\n")),(0,x.SK)("复制成功")):(0,x.SK)("暂无聊天记录")},handleBatchCopy:()=>{const e=m.filter(e=>p.has(e.id)).map(v).filter(Boolean).join("\n\n\n");e?((0,T.lW)(e),(0,x.SK)("复制成功")):(0,x.SK)("暂无内容")},toggleBatchMode:()=>{h&&f(new Set),_(e=>!e)},toggleMsgSelect:e=>{f(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},batchDeleteMessages:()=>{0!==p.size&&u({sub_title:l("cf_msgs"),confirm_fun:async()=>{const e=[];if(m.forEach((s,t)=>{p.has(s.id)&&e.push(t)}),g(m.filter(e=>!p.has(e.id))),f(new Set),_(!1),!o||0===e.length)return;const n=t(o);n?s("message_delete",{session_id:o,user_id:n,indices:e}).catch(console.error):c.jV.post("session/message/delete",{session_id:o,indices:e}).catch(console.error)}})}}}({admin_call:(e,s)=>c.jV.post("admin/session",{action:e,...s||{}}),owner_of_session:e=>be.current?ve.current.find(s=>s.id===e)?.user_id:void 0,get_sessions:()=>ve.current,activeSessionId:je.current,admin_mode_ref:be});ye.current=Ne.apply_session;const ke=function(e){const{on_session_loaded:s,set_session_panel_open:t,on_session_change:o,init_cwd:r,write_url_session:l,url_session_id:u,init_session_id:h}=e,{t:_}=(0,i.Bd)(),p=(0,R.y)(),[f,v]=(0,a.fp)(m.AG.ai_last_session_id),[j,b]=(0,n.useState)([]),[w,y]=(0,n.useState)(""),[S,N]=(0,n.useState)(""),[k,C]=(0,n.useState)(!1),[A,M]=(0,n.useState)(!1),[T,D]=(0,n.useState)(!1),H=(0,n.useRef)(!1),E=(0,n.useRef)([]);(0,n.useEffect)(()=>{H.current=k},[k]),(0,n.useEffect)(()=>{E.current=j},[j]);const V=(e,s={})=>c.jV.post("admin/session",{action:e,...s}),K=e=>{if(H.current)return E.current.find(s=>s.id===e)?.user_id},P=async(e,n=!1,a)=>{const i=a??E.current.find(s=>s.id===e)?.user_id,r=H.current&&i?await V("get",{session_id:e,user_id:i}):await c.jV.post("session/get",{session_id:e});if(r.code!==d.m.Success||!r.data)return!1;const m=r.data;return y(m.id),v(m.id),u!==m.id&&l(m.id),o?.(m.id),M(!!m.running),N(m.sys_prompt_id??""),n&&t(!0),s(m),!0},L=async e=>{const t=H.current?await V("list_all_sessions"):await c.jV.get("sessions");if(t.code!==d.m.Success)return!1;const n=t.data??[];b(n);const a=null===e?n[0]?.id??"":e||w||n[0]?.id||"";if(!a)return y(""),l(null),s(null),!1;if(e&&!n.some(s=>s.id===e))return!1;const i=n.find(e=>e.id===a)?.user_id;return await P(a,!1,i)},z=async e=>{if(!e)return null;const s=await c.jV.get("sessions");if(s.code!==d.m.Success)return null;const t=s.data??[],n=(0,I.ed)(e),a=t.find(e=>(0,I.ed)(e.file_cwd_path)===n);if(a)return a.id;const i=await c.jV.post("session",{file_cwd_path:e});return i.code!==d.m.Success?null:i.data.id};return{sessions:j,setSessions:b,sessions_ref:E,activeSessionId:w,setActiveSessionId:y,selectedSysPromptId:S,setSelectedSysPromptId:N,admin_all_mode:k,admin_mode_ref:H,readonly:T,activeSessionRunning:A,setActiveSessionRunning:M,admin_call:V,call:(e,s,t)=>H.current?V(e,s):t(),owner_of_session:K,refreshSessions:async()=>{const e=H.current?await V("list_all_sessions"):await c.jV.get("sessions");e.code===d.m.Success&&b(e.data??[])},markSessionRunning:(e,s)=>{b(t=>{const n=t.find(s=>s.id===e);return n&&!!n.running!==s?t.map(t=>t.id===e?{...t,running:s}:t):t})},loadSession:P,loadSessions:L,createSession:async e=>{const n=await c.jV.post("session",{sys_prompt_id:e||void 0,file_cwd_path:r||void 0});if(n.code!==d.m.Success)return;const a=n.data;y(a.id),N(a.sys_prompt_id??""),t(!0),s(null),await L(a.id),requestAnimationFrame(()=>{const e=document.querySelector(".chat-input");e&&(e.style.height="auto",e.style.height=Math.min(e.scrollHeight,200)+"px")})},locate_session_by_cwd:z,init_active_session:async()=>{if(r){const e=await z(r);e&&await L(e)||await L()}else h?await L(h)||await L():u?await L(u)||await L():f&&await L(f)||await L()},reorderSessions:(e,s)=>{if(H.current)return;const t=E.current.findIndex(s=>s.id===e),n=E.current.findIndex(e=>e.id===s);if(t<0||n<0||t===n)return;const a=(0,$.TI)(E.current,t,n);b(a),c.jV.post("sessions/update/sort",{session_ids:a.map(e=>e.id)}).catch(()=>{})},deleteSession:e=>{p({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{const s=K(e);s?await V("delete",{session_id:e,user_id:s}):await c.jV.post("session/delete",{session_id:e}),w===e?(y(""),await L(null)):await L(w)}})},renameSession:(e,s)=>{let t=s;p({confirm_fun:async()=>{const s=K(e);s?await V("rename",{session_id:e,user_id:s,title:t}):await c.jV.post("sessions/update/meta",{id:e,title:t}),await L(w)},context_div:(0,B.jsx)("div",{className:"card-content",children:(0,B.jsx)(g.Sm,{value:t,handleInputChange:e=>{t=e}})})})},toggleCmdAuto:async(e,s)=>{const t=K(e);t?await V("cmd_auto",{session_id:e,user_id:t,allow:s}):await c.jV.post("session/cmd_auto_allow",{session_id:e,allow:s}),(0,x.SK)(_(s?"命令检测已开启":"命令检测已关闭")),await L(w)},batchDeleteSessions:(e,s)=>{0!==e.size&&p({sub_title:_("cf_ses"),confirm_fun:async()=>{if(H.current)await V("batch_delete",{session_ids:Array.from(e)});else for(const s of e)await c.jV.post("session/delete",{session_id:s});s(),e.has(w)?(y(""),await L(null)):await L(w)}})},clearAllSessions:()=>{p({sub_title:_("cf_all"),confirm_fun:async()=>{await c.jV.post("sessions/clear",{}),y(""),s(null),await L(null)}})},toggleAllUsersMode:async()=>{const e=!k;C(e),H.current=e,D(e),y(""),s(null);const t=e?await V("list_all_sessions"):await c.jV.get("sessions"),n=t.code===d.m.Success?t.data??[]:[];b(n),n[0]?.id&&await P(n[0].id,!1,n[0].user_id)},changeSystemPrompt:(e,s)=>{const t=s||w;if(!t)return;b(s=>s.map(s=>s.id===t?{...s,sys_prompt_id:e||void 0}:s)),t===w&&N(e);const n=K(t);n?V("sys_prompt",{session_id:t,user_id:n,sys_prompt_id:e||void 0}).catch(console.error):c.jV.post("session/sys_prompt",{session_id:t,sys_prompt_id:e||void 0}).catch(console.error)}}}({on_session_loaded:e=>{if(e&&(e.running&&(p.ws.sendData(f.HK.ai_chat_subscribe,{session_id:e.id,subscribe:!0}),we.current=e.id),ye.current(e),e.live_messages?.length)){const s=y([...e.messages??[],...e.live_messages]);Se.current?.bind_live_bubbles(s,e.live_messages.length)}},set_session_panel_open:e=>P(!e),on_session_change:b,init_cwd:h,write_url_session:e=>{j&&k(s=>{const t=new URLSearchParams(s);return e?t.set("session",e):t.delete("session"),t},{replace:!0})},url_session_id:C,init_session_id:t});(0,n.useEffect)(()=>{je.current=ke.activeSessionId,be.current=ke.admin_all_mode,ve.current=ke.sessions},[ke.activeSessionId,ke.admin_all_mode,ke.sessions]);const Ce=D({active_session_id_ref:je,local_owner_ref:xe,subscribed_ref:we,set_messages:Ne.setMessages,scroll_to_bottom:()=>Ne.scrollToBottom(!1),follow_ref:Ne.followRef,mark_session_running:ke.markSessionRunning,refresh_sessions:ke.refreshSessions,reload_session:e=>ke.loadSession(e),set_active_session_running:ke.setActiveSessionRunning});Se.current=Ce;const Ae=(0,n.useRef)((0,r.n)(e=>{Ne.setMessages(e),Ne.followRef.current&&Ne.scrollToBottom(!1)},50)).current,Me=function(e){const{getMessages:s,setMessages:t,setMessagesDebounced:a,setSending:i,getActiveSessionId:o,setActiveSessionId:c,refreshSessions:r,scrollToBottom:l,buildRequestMessages:d,getSelectedSysPromptId:u,setLocalOwner:m}=e,g=(0,n.useRef)([]),h=(0,n.useRef)(null),_=(e,n,c)=>{const g=s(),_=g.length+1,x={...n,id:_},v=[...g,x];t(v),i(e),m(e),h.current={abort:()=>{}};const j={id:-1,sender:"bot",text:"AI thinking ...",is_loading:!0};v.push(j),t([...v]);const b=new Map,w=()=>{o()===e&&a([...v])},S=()=>{const e=v.indexOf(j);-1!==e&&v.splice(e,1)},N=s=>{const t=s.context||{};if(t.session_id!==e)return;const n=t.text||"",a=t.tool_call_ends,i=t.chunk_index??0;if(t.notice)return j.id=-1,j.text=n,j.is_loading=!0,v.includes(j)||v.push(j),void w();if("[DONE]"===n)return;if(!n&&!a)return;S();let o=b.get(i);if(o||(o={id:_+1+i,sender:"bot",text:"",is_loading:!0},v.push(o),b.set(i,o)),n){o.text=o.text+n;const e=o.content_list?.[0];e&&(e.content=o.text),o.is_loading=!1}a&&(o.content_list=[{tool_call_ends:a,content:o.text,role:"assistant"}],o.is_loading=!1),w()},k=s=>{const n=s.context||{};n.session_id===e&&(A(),h.current=null,m(null),i(s=>s===e?null:s),o()===e&&t(e=>{const s=e.filter(M);let t=s;if(n.once_messages_list?.length){let e=-1;for(let t=s.length-1;t>=0;t--)if("user"===s[t].sender){e=t;break}const a=e>=0?e+1:s.length;t=[...s.slice(0,a),...y(n.once_messages_list)]}return t.map((e,s)=>({...e,id:s+1}))}),r(),l(!0),c())},C=s=>{const n=s.context||{};if(n.session_id!==e)return;A(),h.current=null,i(s=>s===e?null:s);const a="AI request error: "+(n.message||"未知错误");S();const r=[...v].reverse().find(e=>"bot"===e.sender);r?(r.text=r.text?`${r.text}\n\n${a}`:a,r.is_loading=!1):v.push({id:_+1,sender:"bot",text:a}),o()===e&&t([...v].map((e,s)=>({...e,id:s+1}))),c()},A=()=>{p.ws.off_message(`message_${f.HK.ai_chat_msg}`,N),p.ws.off_message(`message_${f.HK.ai_chat_end}`,k),p.ws.off_message(`message_${f.HK.ai_chat_error}`,C)};p.ws.addMsg(f.HK.ai_chat_msg,N),p.ws.addMsg(f.HK.ai_chat_end,k),p.ws.addMsg(f.HK.ai_chat_error,C),p.ws.sendData(f.HK.ai_chat_req,{messages:d(n),session_id:e,sys_prompt_id:u()})},x=()=>{const e=g.current;if(0===e.length)return;const s=e.shift();if(!s)return;t(e=>e.map(e=>"user"===e.sender&&e.text.includes("⏳(排队中...)")?{...e,text:e.text.replace(" ⏳(排队中...)","")}:e));const n={id:w(),sender:"user",text:s.text,attachments:s.attachments};_(o(),n,x)};return{startChatStream:_,processPendingQueue:x,enqueueMessage:(e,s)=>{g.current.push({text:e,attachments:s})},getQueueLength:()=>g.current.length,abort:()=>{const e=o();e&&(p.ws.sendData(f.HK.ai_chat_abort,{session_id:e}),h.current&&(h.current=null,i(s=>s===e?null:s)))}}}({getMessages:()=>Ne.messages,setMessages:Ne.setMessages,setMessagesDebounced:Ae,setSending:J,getActiveSessionId:()=>je.current,setActiveSessionId:ke.setActiveSessionId,refreshSessions:ke.refreshSessions,scrollToBottom:Ne.scrollToBottom,buildRequestMessages:e=>{const s=(e.attachments??[]).filter(e=>"image"===e.kind);if(s.length>0){const t=[];e.text&&t.push({type:"text",text:e.text});for(const e of s)t.push({type:"image_url",image_url:{url:e.content}});return[{content:t,role:"user",attachments:e.attachments??[]}]}return[{content:e.text,role:"bot"===e.sender?"assistant":"user",attachments:e.attachments??[]}]},getSelectedSysPromptId:()=>ke.selectedSysPromptId,setLocalOwner:e=>{xe.current=e}}),Ie=e=>{ie(e?.ai_config?.model??"")},$e=async()=>{try{const e=await c.jV.get("public_models");e.code===d.m.Success&&le(e.data?.groups??[])}catch{le([])}},Re=e=>{const s=Array.from(e??[]).filter(Boolean);s.length&&Q(e=>[...e,...s])},Be=e=>ke.owner_of_session(e),Te=()=>{Ne.batchMode&&(Ne.setSelectedMsgIds(new Set),Z(new Set)),Ne.setBatchMode(e=>!e)};(0,n.useEffect)(()=>{(async()=>{const e=await c.XO.get("ai_agent_setting/env");e.code===d.m.Success&&(pe.current=e.data,Ie(e.data)),await $e(),await ke.init_active_session();const s=await c.jV.get("system_prompts");s.code===d.m.Success&&te(s.data??[])})(),requestAnimationFrame(()=>Ne.scrollToBottom(!1)),_e.current.onCountChange=ue,_e.current.refresh?.();const e=e=>{const s=e?.context?.count;"number"==typeof s&&ue(s)};return p.ws.addMsg(f.HK.ai_bg_process_count_notify,e),()=>{p.ws.off_message(`message_${f.HK.ai_bg_process_count_notify}`,e)}},[]);const De=G===ke.activeSessionId||ke.activeSessionRunning;return(0,B.jsxs)(n.Fragment,{children:[(0,B.jsx)(X,{inline:s,currentModelName:ae,setCurrentModelName:ie,modelGroups:oe,onModelChanged:async()=>{await $e();const e=await c.XO.get("ai_agent_setting/env");e.code===d.m.Success&&(pe.current=e.data,Ie(e.data))},batchMode:Ne.batchMode,selectedMsgCount:Ne.selectedMsgIds.size,sessionVisible:!K,onToggleSessionPanel:()=>P(e=>!e),onCreateSession:ke.createSession,onBatchDeleteMessages:Ne.batchDeleteMessages,onToggleBatchMode:Te,bgProcessVisible:L,bgProcessCount:de,onToggleBgProcess:()=>z(e=>!e)}),(0,B.jsxs)("div",{className:"chat-page"+(s?" chat-page--embedded":" chat-page-with-sessions"),style:{"--ai-chat-zoom":U},children:[!K&&(0,B.jsx)("div",{className:"chat-session-overlay",onClick:()=>P(!0)}),!K&&(0,B.jsx)(se,{sessions:ke.sessions,activeSessionId:ke.activeSessionId,onSelectSession:e=>ke.loadSession(e,!1),onReorderSessions:ke.reorderSessions,onRenameSession:ke.renameSession,onDeleteSession:ke.deleteSession,onToggleCmdAuto:ke.toggleCmdAuto,onShowUsageStats:async e=>{q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsx)("div",{className:"usage-stats-loading",children:S("加载中...")}),cancel:()=>q({open:!1})});try{const s=Be(e),t=s?await ke.admin_call("usage_stats",{session_id:e,user_id:s}):await c.jV.post("session/usage_stats",{session_id:e});if(t.code===d.m.Success&&t.data){const e=t.data;q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsxs)("div",{className:"usage-stats-panel",children:[[{l:S("对话轮次"),v:(e.turns??0).toString()},{l:S("AI输入Token"),v:_(e.input_tokens)},{l:S("AI输出Token"),v:_(e.output_tokens)},{l:S("AI输入Token(最近一轮)"),v:_(e.recent_input_tokens)},{l:S("AI输出Token(最近一轮)"),v:_(e.recent_output_tokens)}].map((e,s)=>(0,B.jsxs)("div",{className:"usage-stats-row",children:[(0,B.jsx)("span",{className:"usage-stats-label",children:e.l}),(0,B.jsx)("span",{className:"usage-stats-value",children:e.v})]},s)),(0,B.jsxs)("div",{className:"usage-stats-row usage-stats-total",children:[(0,B.jsx)("span",{className:"usage-stats-label",children:S("AI Token总计消耗")}),(0,B.jsx)("span",{className:"usage-stats-value",children:_((e.input_tokens||0)+(e.output_tokens||0))})]})]}),cancel:()=>q({open:!1})})}else q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsx)("div",{className:"usage-stats-empty",children:S("暂无统计数据")}),cancel:()=>q({open:!1})})}catch{q({open:!0,title:S("Token消耗统计"),context_div:(0,B.jsx)("div",{className:"usage-stats-empty",children:S("暂无统计数据")}),cancel:()=>q({open:!1})})}},onShowSessionSetting:e=>{let s=ke.sessions.find(s=>s.id===e)?.file_cwd_path??"";q({open:!0,title:S("会话设置"),context_div:(0,B.jsxs)("div",{className:"session-setting",children:[(0,B.jsx)("div",{className:"session-setting__label",children:S("服务器工作目录")}),(0,B.jsx)(g.Sm,{value:s,placeholder:S("服务器工作目录提示"),handleInputChange:e=>{s=e}})]}),confirm:async()=>{try{const t=Be(e);(t?await ke.admin_call("setting",{session_id:e,user_id:t,file_cwd_path:s.trim()}):await c.jV.post("session/setting",{session_id:e,file_cwd_path:s.trim()})).code===d.m.Success&&(0,x.SK)(S("保存成功"))}catch{}q({open:!1}),await ke.loadSessions(ke.activeSessionId)},cancel:()=>q({open:!1})})},batchMode:Ne.batchMode,selectedSessionIds:Y,onToggleSessionSelect:e=>{Z(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onToggleBatchMode:Te,onBatchDeleteSessions:()=>ke.batchDeleteSessions(Y,()=>{Z(new Set),Ne.setBatchMode(!1)}),onClearAllSessions:ke.admin_all_mode?void 0:ke.clearAllSessions,allUsersMode:ke.admin_all_mode,onToggleAllUsersMode:ke.toggleAllUsersMode,showAllUsersEntry:V,sysPromptList:ee,onChangeSysPrompt:(e,s)=>ke.changeSystemPrompt(s,e)}),(0,B.jsx)(re,{panelRef:_e}),(0,B.jsxs)("section",{className:"chat-main",children:[0===Ne.messages?.length&&(0,B.jsx)("div",{className:"chat-header",children:(0,B.jsx)("div",{children:S("ai_ask")})}),(0,B.jsx)(ne,{messages:Ne.messages,batchMode:Ne.batchMode,selectedMsgIds:Ne.selectedMsgIds,sending:De,chatContainerRef:Ne.chatContainerRef,messagesEndRef:he,onToggleMsgSelect:Ne.toggleMsgSelect,onDelete:Ne.handleDelete,onCopy:Ne.handleCopy,onCopyAll:Ne.handleCopyAll,onToggleBatchMode:Te,onBatchCopy:Ne.handleBatchCopy,onBatchDelete:Ne.batchDeleteMessages,showBatchBar:Ne.batchMode&&Ne.selectedMsgIds.size>0&&0===Y.size,t:S}),(0,B.jsx)(ce,{ref:me,onSend:async()=>{if(ke.admin_all_mode)return;const e=(me.current?.getValue()??"").trim();if(!e&&0===W.length)return;if(G===ke.activeSessionId){const s=await A(W);Me.enqueueMessage(e,s),me.current?.clear(),Q([]);const t={id:w(),sender:"user",text:e+(Me.getQueueLength()>1?" ⏳(排队中...)":""),attachments:s};return void Ne.setMessages(e=>[...e,t])}let s=ke.activeSessionId;if(!s){const t=await c.jV.post("session",{title:(e||W[0]?.name).slice(0,28),sys_prompt_id:void 0,file_cwd_path:h||void 0});if(t.code!==d.m.Success)return;s=t.data.id,ke.setActiveSessionId(s),b?.(s),await ke.loadSessions(s)}const t=await A(W),n={id:w(),sender:"user",text:e,attachments:t};me.current?.clear(),Q([]);const a=pe.current?.ai_config?.request_type||"completions";if("completions"!==a){const t={id:Ne.messages.length+2,sender:"bot",text:"处理中...",is_loading:!0},i={...n,id:Ne.messages.length+1},o=[...Ne.messages,i,t];Ne.setMessages(o),J(s);return void(await O(a,e,s,async(e,s)=>{t.text=e,t.is_loading=!1,s?.images&&(t.images=s.images),s?.audio&&(t.audio=s.audio),s?.embeddings&&(t.embeddings=s.embeddings),Ne.setMessages([...o]),J(null),ke.refreshSessions(),Ne.scrollToBottom(!0),Me.processPendingQueue()})||(t.text=`请求类型 "${a}" 的专用处理器尚未实现,请使用 completions 类型。`,t.is_loading=!1,Ne.setMessages([...o]),J(null),Me.processPendingQueue()))}Me.startChatStream(s,n,()=>Me.processPendingQueue())},readonly:ke.admin_all_mode,sending:De,onAbort:Me.abort,pendingAttachments:W,onRemoveAttachment:e=>{Q(s=>s.filter((s,t)=>t!==e))},onOpenFilePicker:()=>{ge.current?.click()},onAddFiles:Re,onDrop:e=>{const s=e.dataTransfer?.files;s&&s.length>0&&(e.preventDefault(),Re(s))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:ge})]})]})]})}},72693(e,s,t){t.d(s,{w:()=>g});var n=t(96540),a=t(22022),i=t(14944),o=t(92275),c=t(34843),r=t(82893),l=t(85997),d=t(14284),u=t(74848);function m(e){const{t:s}=(0,a.Bd)(),[t,i]=(0,n.useState)(!1),o=!!e.sessionId;return(0,u.jsxs)("div",{children:[(0,u.jsx)("div",{style:{maxHeight:"60vh",overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--surfaceSecondary)",padding:"0.75em",borderRadius:"0.5em",marginBottom:"0.75em",fontFamily:"monospace",fontSize:"0.9em",lineHeight:"1.5"},children:e.cmd}),o&&(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5em",marginBottom:"0.75em",color:t?"var(--icon-blue)":"var(--textSecondary)"},children:[(0,u.jsx)(l.Ay,{checked:t,onChange:s=>{i(s),s&&e.onAutoAllow()},title:s("此会话不再询问")}),(0,u.jsx)("span",{children:s("此会话不再询问")})]}),(0,u.jsxs)("div",{style:{display:"flex",gap:"0.5em",justifyContent:"flex-end"},children:[(0,u.jsx)(l.$n,{text:s("拒绝"),color:"var(--red)",clickFun:e.onDeny}),(0,u.jsx)(l.$n,{text:s("允许"),clickFun:e.onAllow})]})]})}function g(){const[e,s]=(0,c.fp)(r.AG.prompt_card),{t}=(0,a.Bd)(),l=(0,n.useRef)([]),g=(0,n.useRef)(!1),h=(0,n.useRef)(null),_=(0,n.useRef)(void 0),p=(0,n.useRef)(()=>{}),f=(0,n.useCallback)(e=>{s({open:!1}),g.current=!1,h.current&&(i.ws.sendData(o.HK.ai_confirm_cmd,{askId:h.current,approved:e}),h.current=null),p.current()},[s]),x=(0,n.useCallback)(()=>{if(g.current)return;if(0===l.current.length)return g.current=!1,void s({open:!1});g.current=!0;const e=l.current.shift();e?(h.current=e.askId,_.current=e.session_id,s({open:!0,title:t("命令确认"),cancel:()=>f(!1),context_div:(0,u.jsx)(m,{cmd:e.cmd,sessionId:e.session_id,onDeny:()=>f(!1),onAllow:()=>f(!0),onAutoAllow:async()=>{if(_.current)try{await d.jV.post("session/cmd_auto_allow",{session_id:_.current,allow:!0})}catch(e){console.error("设置会话命令免确认失败",e)}f(!0)}})})):g.current=!1},[t,f,s]);p.current=x;const v=(0,n.useCallback)(e=>{l.current.push(e),x()},[x]);(0,n.useEffect)(()=>{const e=e=>{const t=e.context||{};if(t.dismiss&&t.askId)return l.current=l.current.filter(e=>e.askId!==t.askId),void(g.current&&h.current===t.askId&&(h.current=null,g.current=!1,s({open:!1}),x()));t.askId&&t.cmd&&v({askId:t.askId,cmd:t.cmd,session_id:t.session_id})};return i.ws.addMsg(o.HK.ai_confirm_cmd,e),()=>{i.ws.off_message(`message_${o.HK.ai_confirm_cmd}`,e)}},[v]),(0,n.useEffect)(()=>()=>{l.current=[],g.current=!1,h.current=null},[])}},34299(e,s,t){t.r(s),t.d(s,{default:()=>y});var n=t(96540),a=t(23802),i=t(53995),o=t(18569),c=t(77979),r=t(8263),l=t(69428),d=t.n(l),u=(t(3775),t(21499)),m=t(99214),g=t(89117),h=t(86063),_=t(89334),p=t(41105),f=t(52388),x=t(19878),v=(t(72411),t(74848));const j=new a.A({html:!0,highlight:function(e,s){if(s&&x.A.getLanguage(s))try{return`<pre class="hljs code-block-with-copy"><code class="hljs language-${s}">${x.A.highlight(e,{language:s}).value}</code></pre>`}catch(e){}try{return`<pre class="hljs code-block-with-copy"><code class="hljs">${x.A.highlightAuto(e).value}</code></pre>`}catch(e){}return`<pre class="hljs code-block-with-copy"><code>${j.utils.escapeHtml(e)}</code></pre>`}});async function b(e,s){e.className="md-graph md-graph--mind md-graph--loading",e.textContent=f.A.t("rendering");const t=await(0,h.Hn)(s);e.isConnected&&(e.className="md-graph md-graph--mind",e.textContent="",await t.mount(e))}function w(e){const s=e.className.match(/language-([\w-]+)/);return s?s[1]:""}function y(e){const s=(0,n.useRef)(null);return(0,m.VD)(),(0,n.useEffect)(()=>{s.current&&(s.current.innerHTML=j.render(e.context??""),async function(e){const s=e.querySelectorAll("pre > code[class*='language-']");for(const e of Array.from(s)){const s=w(e),t=(0,g.Hm)(s),n=(0,h.hj)(s);if(!t&&!n)continue;const a=e.closest(".code-block-with-copy")??e.parentElement;if(!a)continue;const i=e.textContent??"",o=document.createElement("div");if(a.replaceWith(o),n){try{await b(o,i)}catch(e){console.error("[mind] render failed",e),o.className="md-graph md-graph--mind",o.textContent=String(e)}continue}o.className="md-graph md-graph--loading",o.textContent=f.A.t("rendering");const c=await(0,g.U6)(s,i);o.isConnected&&(c.error?(o.className="md-graph md-graph--error",o.textContent=c.error):(o.className="md-graph",o.innerHTML=c.svg))}}(s.current),(0,_.rg)(s.current))},[e.context]),(0,v.jsx)("div",{ref:s})}j.use(i.A).use(o.A).use(c.A).use(r.A).use(d()).use(e=>{e.renderer.rules.fence;e.renderer.rules.fence=(s,t,n,a,i)=>{const o=s[t],c=o.content.trim(),r=o.info.trim();let l="";if(r&&x.A.getLanguage(r))try{l=x.A.highlight(c,{language:r}).value}catch(s){l=e.utils.escapeHtml(c)}else try{l=x.A.highlightAuto(c).value}catch(s){l=e.utils.escapeHtml(c)}return`\n <div class="code-block-with-copy">\n <div class="code-header">\n <span class="code-language">${r||"code"}</span>\n <button class="copy-btn" data-code="${e.utils.escapeHtml(c)}">复制</button>\n </div>\n <pre><code class="hljs ${r?`language-${r}`:""}">${l}</code></pre>\n </div>`}}).use(e=>{const s=e.renderer.rules.link_open||function(e,s,t,n,a){return a.renderToken(e,s,t)};e.renderer.rules.link_open=(e,t,n,a,i)=>{const o=e[t],c=o.attrIndex("href");if(c>=0){const e=o.attrs[c][1];o.attrs[c][1]=(0,u.bi)(window.location.href,e)}return s(e,t,n,a,i)}}),(0,_.Rh)(j,p.pC)},84369(e,s,t){t.d(s,{y:()=>o});var n=t(96540),a=t(2543);function i(e){if(void 0!==e)return"function"==typeof e?e():e}function o(e){const{direction:s="vertical",target_ref:t,get_start_size:o,px_to_unit:c,min:r,max:l,throttle:d,on_change:u,on_drag_end:m}=e,[g,h]=(0,n.useState)(!1),_=(0,n.useRef)(null),p=(0,n.useRef)(u);p.current=u;const f=e=>"vertical"===s?e.clientY:e.clientX,x=(0,n.useRef)({direction:s,get_start_size:o,px_to_unit:c,min:r,max:l,get_pos:f});x.current={direction:s,get_start_size:o,px_to_unit:c,min:r,max:l,get_pos:f};const v=(0,n.useCallback)(e=>{const s=_.current;if(!s)return;const{px_to_unit:t,min:n,max:a,get_pos:o}=x.current,c=s.pos-o(e);let r=s.size+t(c);const l=i(n),d=i(a);void 0!==l&&(r=Math.max(l,r)),void 0!==d&&(r=Math.min(d,r)),p.current(r)},[]),j=n.useMemo(()=>void 0===d?v:a.throttle(e=>v(e),d),[d,v]),b=(0,n.useCallback)(()=>{_.current=null,h(!1);const e=j;"function"==typeof e.cancel&&e.cancel(),m?.()},[j,m]),w=(0,n.useCallback)(e=>{const{get_start_size:s,get_pos:t}=x.current;_.current={pos:t(e),size:s()},h(!0)},[]);return(0,n.useEffect)(()=>{if(!g)return;const e=t?.current??window;return e.addEventListener("pointermove",j),e.addEventListener("pointerup",b),()=>{e.removeEventListener("pointermove",j),e.removeEventListener("pointerup",b)}},[g,j,b,t]),(0,n.useEffect)(()=>{const e=j;return()=>{"function"==typeof e.cancel&&e.cancel()}},[j]),{dragging:g,on_pointer_down:w,on_pointer_up:b}}},60840(e){e.exports="data:image/svg+xml,<svg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 version=%271.1%27 aria-hidden=%27true%27><path fill-rule=%27evenodd%27 d=%27M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z%27></path></svg>"}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[6805],{47996(e,n,t){t.d(n,{d:()=>l});t(96540);var s=t(74848);function l(e){return(0,s.jsxs)("div",{className:"instance-item",children:[(0,s.jsxs)("div",{className:"instance-item__toolbar",children:[(0,s.jsx)("span",{className:"instance-item__label",children:e.title}),e.toolbar]}),e.children]})}},77481(e,n,t){t.d(n,{S:()=>a,X:()=>r});var s=t(96540),l=t(61443),i=t(74848);function r(e){const[n,t]=s.useState([]),r=(0,s.useRef)(-1),[a,c]=(0,s.useState)(-1),[o,d]=(0,s.useState)(-1);(0,s.useEffect)(()=>{e.children?t(Array.isArray(e.children)?e.children:[e.children]):t(e.rows)},[e.rows,e.children]);const _=()=>{r.current=-1,c(-1),d(-1)};return(0,i.jsxs)("table",{children:[(0,i.jsx)("thead",{children:(0,i.jsx)("tr",{children:e.headers?.map((n,t)=>{const s=!!e.filter&&(e.filter.column??0)===t;let r=n;if(s){const t=e.filter,s=t.options.find(e=>e.value===t.value);null!=t.value&&s&&(r=`${n} (${s.label})`)}return(0,i.jsx)("th",{className:s?"table-filter-col":"",children:s?(0,i.jsx)(l.l6,{value:e.filter.value,options:e.filter.options,onChange:e.filter.onChange,bare:!0,trigger_label:r}):n},t)})})}),(0,i.jsx)("tbody",{children:n.map((n,t)=>{const s=!!e.onRowDrag;return(0,i.jsx)("tr",{className:s?(a===t?"row-dragging":"")+(o===t?" row-drop-target":""):"",draggable:s,onContextMenu:()=>{e.handleContextMenu&&e.handleContextMenu(n)},onDragStart:e=>{s&&(r.current=t,c(t),e.dataTransfer.effectAllowed="move")},onDragOver:e=>{!s||r.current<0||(e.preventDefault(),e.dataTransfer.dropEffect="move",d(t))},onDrop:n=>{s&&(n.preventDefault(),(()=>{const n=r.current,t=o;_(),n<0||t<0||n===t||e.onRowDrag?.(n,t)})())},onDragEnd:_,children:n.map((t,s)=>{const l=s===n.length-1?"small":"";return(0,i.jsx)("td",{className:l,style:{width:e.width??"auto"},children:t},s)})},t)})})]})}function a(e){return(0,i.jsx)("div",{style:{display:e.isFlex?"flex":"block"},children:e.columns.map((e,n)=>(0,i.jsx)("div",{children:e},n))})}},36805(e,n,t){t.r(n),t.d(n,{default:()=>K});var s=t(96540),l=t(75725),i=t(22022),r=t(70447),a=t(85997),c=t(77481),o=t(61443),d=t(14284),_=t(53459),x=t(7523),h=t(34843),p=t(82893),u=t(62042),j=(t(23430),t(21499),t(14944)),m=t(92275),v=t(6960),f=t(40505),g=t(4412),w=t(24659),y=t(74848);let S={};function C(){const{t:e,i18n:n}=(0,i.Bd)(),{initUserInfo:t,reloadUserInfo:C}=(0,s.useContext)(x.F),[b,k]=(0,h.fp)(p.AG.user_base_info),[I,A]=(0,s.useState)([]),[P,$]=(0,h.fp)(p.AG.prompt_card),N=(0,w.K)(),[F,K]=(0,s.useState)(),[B,U]=(0,s.useState)(void 0),[D,E]=(0,s.useState)(null),[G,V]=(0,s.useState)([]),[q,M]=(0,s.useState)([]),X=[e("序号"),e("名称"),e("在线状态"),e("时间"),e("备注")],Z=[e("序号"),e("服务端口"),e("转发ip"),e("转发端口"),e("开启"),e("备注")],z=[e("序号"),e("服务端口"),e("fwd_nm"),e("转发ip"),e("转发端口"),e("开启"),e("备注")],T=e=>null==e?"":(0,v.s)(e),H=async e=>{const n=await d.s9.post("server_bridge_get_one_fig",{server_client_num_id:e});if(n.code===_.m.Success){const e=n.data;for(const n of e)n.client_name=S?.[n.client_num_id]?.client_name??"";M(e)}},O=async e=>{const n=void 0===e?D:e,t=await d.s9.get("server_client_get");if(t.code===_.m.Success){const e=t.data,s=[],l=[];S={};for(const t of e)null!==n&&!!t.status!==n||(B?`${t.index}${t.client_name}${t.note}`.includes(B)&&s.push(t):s.push(t),l.push({label:t.client_name,value:t.client_num_id}),S[t.client_num_id]=t);A(s),V(l)}};(0,s.useEffect)(()=>{j.ws.addMsg(m.HK.tcp_forward_server_load,e=>{O()}),O()},[]);return(0,y.jsxs)(s.Fragment,{children:[(0,y.jsx)(g.aZ,{position:"right",children:F&&(0,y.jsx)("span",{children:`${F.client_name}${F.note?`(${F.note})`:""}`})}),(0,y.jsxs)(l.fI,{children:[(0,y.jsx)(l.VP,{widthPer:50,children:(0,y.jsx)(l.xh,{children:(0,y.jsx)(r.uF,{self_title:(0,y.jsx)("span",{className:" div-row ",children:(0,y.jsx)("h2",{children:e("客户端列表")})}),rightTopCom:(0,y.jsx)(o.Sm,{placeholder:e("过滤"),value:B,handleInputChange:e=>{U(e)},handlerEnter:()=>{O()}}),children:(0,y.jsx)(c.X,{headers:X,filter:{title:e("在线状态"),column:2,value:D,options:[{label:e("全部"),value:null},{label:e("在线"),value:!0},{label:e("离线"),value:!1}],onChange:e=>{E(e),O(e)}},rows:I.map((n,t)=>[(0,y.jsx)("p",{children:t}),(0,y.jsx)(r.xP,{children:n.client_name}),(0,y.jsx)(r.fq,{ok:n.status}),(0,y.jsx)(r.xP,{children:T(n.status?n.online_start_time:n.offline_time)}),(0,y.jsx)(r.xP,{children:n.note}),(0,y.jsxs)("div",{children:[(0,y.jsx)(a.rA,{icon:"edit",title:e("编辑"),onClick:()=>{K({...n}),H(n.client_num_id)}}),(0,y.jsx)(a.rA,{icon:"delete",title:e("删除"),onClick:()=>{$({open:!0,title:"share file",confirm:async()=>{$({open:!1}),await(async e=>{(await d.s9.post("server_client_del",{client_num_id:e})).code===_.m.Success&&((0,u.SK)("成功"),O())})(n.client_num_id)},context_div:(0,y.jsx)("div",{className:"card-content",children:e("确定删除这个吗客户端吗?")})})}})]})]),width:"10rem"})})})}),(0,y.jsx)(l.VP,{widthPer:50,children:F?(0,y.jsxs)(l.xh,{children:[(0,y.jsxs)(r.Zp,{self_title:(0,y.jsxs)("span",{className:" div-row ",children:[(0,y.jsx)("h2",{children:`服务器 ${e("代理配置")}`})," "]}),rightBottomCom:(0,y.jsx)("div",{children:(0,y.jsx)(a.rA,{icon:"save",title:e("保存"),onClick:async()=>{(await d.s9.post("server_client_save",F)).code===_.m.Success&&(0,u.SK)("成功")}})}),children:[(0,y.jsx)(l.Yh,{left:e("远程地址"),center:F?.client_remote_address??""}),(0,y.jsx)(l.Yh,{left:e(F?.status?"在线时间":"离线时间"),center:T(F?.status?F?.online_start_time:F?.offline_time)}),(0,y.jsx)(o.Sm,{placeholder:"名称",value:F.client_name,handleInputChange:e=>{F.client_name=e,K({...F})}}),(0,y.jsxs)("form",{children:[e("fc_pxy"),":",(0,y.jsx)(c.S,{isFlex:!0,columns:[(0,y.jsx)(o.U6,{value:1,context:e("开启"),selected:F.open_filecat,onchange:()=>{F.open_filecat=!F.open_filecat,K({...F})}}),(0,y.jsx)(o.U6,{value:1,context:e("关闭"),selected:!F.open_filecat,onchange:()=>{F.open_filecat=!F.open_filecat,K({...F})}})]})]}),F.open_filecat&&(0,y.jsxs)(s.Fragment,{children:[(0,y.jsxs)("form",{children:[e("fc_pxyw"),":",(0,y.jsx)(c.S,{isFlex:!0,columns:[(0,y.jsx)(o.U6,{value:1,context:e("开启"),selected:F.filecat_use_local_page,onchange:()=>{F.filecat_use_local_page=!F.filecat_use_local_page,K({...F})}}),(0,y.jsx)(o.U6,{value:1,context:e("关闭"),selected:!F.filecat_use_local_page,onchange:()=>{F.filecat_use_local_page=!F.filecat_use_local_page,K({...F})}})]})]}),(0,y.jsx)(o.Sm,{placeholderOut:e("fc_pxyr"),placeholder:"127.0.0.1:5567",value:F.filecat_proxy_host_port,handleInputChange:e=>{F.filecat_proxy_host_port=e,K({...F})}}),(0,y.jsx)(a.rA,{icon:"content_copy",title:e("复制filecat代理url"),onClick:()=>{const e=`${window.location.origin}?tcp_client_num_id=${F.client_num_id}`;(0,f.lW)(e),(0,u.SK)(e)}})]}),(0,y.jsx)(o.Sm,{placeholder:"备注",value:F.note,handleInputChange:e=>{F.note=e,K({...F})}}),(0,y.jsx)(a.rA,{icon:"add",onClick:()=>{F.proxy_fig_list.push({open:!1}),K({...F})},title:e("添加")}),e("代理"),(0,y.jsx)(c.X,{headers:Z,rows:F.proxy_fig_list.map((n,t)=>[(0,y.jsx)("p",{children:t}),(0,y.jsx)(o.Sm,{value:n.server_port,handleInputChange:e=>{n.server_port=parseInt(e)},no_border:!0}),(0,y.jsx)(o.Sm,{value:n.proxy_host,handleInputChange:e=>{n.proxy_host=e},no_border:!0}),(0,y.jsx)(o.Sm,{value:n.proxy_port,handleInputChange:e=>{n.proxy_port=parseInt(e)},no_border:!0}),(0,y.jsx)(o.l6,{value:!!n.open,onChange:e=>{n.open=e,K({...F})},options:N,no_border:!0}),(0,y.jsx)(o.Sm,{value:n.note,handleInputChange:e=>{n.note=e},no_border:!0}),(0,y.jsx)("div",{children:(0,y.jsx)(a.rA,{icon:"delete",title:e("删除"),onClick:()=>{const e=[];for(let n=0;n<(F.proxy_fig_list.length??0);n++)n!==t&&e.push(F.proxy_fig_list[n]);F.proxy_fig_list=e,K({...F})}})})]),width:"10rem"})]}),(0,y.jsxs)(r.Zp,{self_title:(0,y.jsxs)("span",{className:" div-row ",children:[(0,y.jsx)("h2",{children:`${e("客户端")} ${e("桥接配置")}`}),(0,y.jsx)(a.rA,{title:"info",icon:"info",onClick:()=>{$({open:!0,title:"Info",confirm:async()=>{$({open:!1})},context_div:(0,y.jsx)("div",{className:"card-content",children:e("在客户端设置一个端口,访问这个端口把流量转发到另一个客户端所在网络环境内的第一个地址")})})}})]}),children:[(0,y.jsx)(a.rA,{icon:"add",onClick:()=>{q.push({open:!1,server_client_num_id:F.client_num_id}),M([...q])},title:e("添加")}),e("代理"),(0,y.jsx)(c.X,{headers:z,rows:q.map((n,t)=>[(0,y.jsx)("p",{children:t}),(0,y.jsx)(o.Sm,{value:n.server_port,handleInputChange:e=>{n.server_port=parseInt(e)},no_border:!0}),(0,y.jsx)(o.Sm,{value:n.client_name,options:G,handleInputChange:e=>{const t=(e=>G.find(n=>String(n.value)===String(e)))(e);n.client_num_id=parseInt(String(t.value)),n.client_name=t.label,M([...q])},no_border:!0}),(0,y.jsx)(o.Sm,{value:n.client_proxy_host,handleInputChange:e=>{n.client_proxy_host=e},no_border:!0}),(0,y.jsx)(o.Sm,{value:n.client_proxy_port,handleInputChange:e=>{n.client_proxy_port=parseInt(e)},no_border:!0}),(0,y.jsx)(o.l6,{value:!!n.open,onChange:e=>{n.open=e,M([...q])},options:N,no_border:!0}),(0,y.jsx)(o.Sm,{value:n.note,handleInputChange:e=>{n.note=e},no_border:!0}),(0,y.jsxs)("div",{children:[(0,y.jsx)(a.rA,{icon:"delete",title:e("删除"),onClick:async()=>{if(null==n.id){const e=[];for(let n=0;n<(q.length??0);n++)n!==t&&e.push(q[n]);M([...e])}else await(async(e,n)=>{(await d.s9.post("server_bridge_del_fig",{id:e})).code===_.m.Success&&((0,u.SK)("成功"),H(n))})(n.id,n.server_client_num_id)}}),null==n.id?(0,y.jsx)(a.rA,{icon:"add",title:e("添加"),onClick:async()=>{await(async e=>{if(null==e.client_num_id)return void(0,u.zN)("未选择转发送 client");(await d.s9.post("server_bridge_add_fig",e)).code===_.m.Success&&((0,u.SK)("成功"),H(e.server_client_num_id))})(n)}}):(0,y.jsx)(a.rA,{icon:"save",title:e("保存"),onClick:async()=>{await(async e=>{if(null==e.client_num_id)return void(0,u.zN)("未选择转发送 client");(await d.s9.post("server_bridge_edit_fig",e)).code===_.m.Success&&((0,u.SK)("成功"),H(e.server_client_num_id))})(n)}})]})]),width:"10rem"})]})]}):(0,y.jsx)(l.xh,{})})]})]})}var b=t(18840),k=t(7463);function I(e){const{t:n}=(0,i.Bd)(),[t,x]=(0,s.useState)([]),[h,p]=(0,s.useState)([]),[v,f]=(0,s.useState)([]),[g,S]=(0,s.useState)([]),C=[n("序号"),n("服务端口"),n("转发客户端名称")],I=[n("序号"),n("原客户端"),n("目标客户端"),n("待同步文件数量")],A=[n("序号"),n("port"),n("host"),n("名称"),n("key"),n("在线"),n("开启"),n("备注")],P=(0,w.K)(),$=async()=>{const e=await d.s9.get("client_get");if(e.code===_.m.Success){const n=e.data;x(n.list)}const n=await d.s9.get("client_bridge_get_all_fig");n.code===_.m.Success&&f(n.data);const t=await d.s9.get("client_sync_task_get");t.code===_.m.Success&&S(t.data)};(0,s.useEffect)(()=>($(),j.ws.sendData(m.HK.tcp_proxy_client_status,{}).then(()=>{const e=(0,k.s)(()=>$(),500);j.ws.addMsg(m.HK.tcp_proxy_client_status,e)}),()=>{j.ws.removeMsg(m.HK.tcp_proxy_client_status)}),[]);const N=async e=>{const n=new b.gE;n.index=e.index,n.key=e.key,n.serverIp=e.serverIp,n.serverPort=e.serverPort,n.open=e.open,n.client_name=e.client_name,n.client_num_id=e.client_num_id;(await d.s9.post("client_save",n)).code===_.m.Success?(0,u.SK)("保存成功"):(0,u.zN)("网络错误")};return(0,y.jsxs)("div",{children:[(0,y.jsxs)(l.fI,{children:[(0,y.jsx)(l.VP,{widthPer:33,children:(0,y.jsxs)(r.Zp,{title:"",rightBottomCom:(0,y.jsx)(a.C3,{text:n("保存"),clickFun:()=>{t[0].index=0,N(t[0])}}),rightTopCom:(0,y.jsxs)("div",{children:[n("连接状态"),(0,y.jsx)(r.fq,{ok:!!t[0]?.status})]}),children:[(0,y.jsx)(o.Sm,{placeholder:`${n("服务器")} ip`,value:t[0]?.serverIp,handleInputChange:e=>{t[0].serverIp=e}}),(0,y.jsx)(o.Sm,{type:"number",placeholder:`${n("服务器")} port`,value:t[0]?.serverPort,handleInputChange:e=>{const n=parseInt(e);!isNaN(n)&&n>=0&&n<=65535&&(t[0].serverPort=n)}}),(0,y.jsx)(o.Sm,{placeholder:n("名称"),value:t[0]?.client_name,handleInputChange:e=>{t[0].client_name=e}}),(0,y.jsx)(o.Sm,{type:"password",placeholder:"key ",value:t[0]?.key,handleInputChange:e=>{t[0].key=e}}),(0,y.jsxs)("form",{children:[n("状态"),(0,y.jsx)(c.S,{isFlex:!0,columns:[(0,y.jsx)(o.U6,{value:1,context:n("开启"),selected:t[0]?.open,onchange:()=>{t[0].open=!t[0].open,x([...t])}}),(0,y.jsx)(o.U6,{value:1,context:n("关闭"),selected:!t[0]?.open,onchange:()=>{t[0].open=!t[0].open,x([...t])}})]})]})]})}),(0,y.jsx)(l.VP,{widthPer:40,children:(0,y.jsxs)(r.Zp,{self_title:(0,y.jsxs)("span",{className:" div-row ",children:[(0,y.jsx)("h2",{children:n("更多服务器")})," "]}),children:[(0,y.jsx)(a.rA,{icon:"add",onClick:()=>{t.push({open:!1,is_new:!0}),x([...t])},title:n("添加")}),n("代理"),(0,y.jsx)(c.X,{headers:A,rows:t.slice(1).map((e,s)=>[(0,y.jsx)("p",{children:s}),(0,y.jsx)(o.Sm,{type:"number",value:e.serverPort,handleInputChange:n=>{const t=parseInt(n);!isNaN(t)&&t>=0&&t<=65535&&(e.serverPort=t)},no_border:!0}),(0,y.jsx)(o.Sm,{value:e.serverIp,handleInputChange:n=>{e.serverIp=n},no_border:!0}),(0,y.jsx)(o.Sm,{value:e.client_name,handleInputChange:n=>{e.client_name=n},no_border:!0}),(0,y.jsx)(o.Sm,{value:e.key,handleInputChange:n=>{e.key=n},no_border:!0}),(0,y.jsx)(r.fq,{ok:!!e.status}),(0,y.jsx)(o.l6,{value:!!e.open,onChange:n=>{e.open=n,x([...t])},options:P,no_border:!0}),(0,y.jsx)(o.Sm,{value:e.note,handleInputChange:n=>{e.note=n},no_border:!0}),(0,y.jsxs)("div",{children:[(0,y.jsx)(a.rA,{icon:"delete",title:n("删除"),onClick:async()=>{if(e.is_new){const e=[];for(let n=0;n<(t.length??0);n++)n!==s&&e.push(t[n]);x([...e])}else await(async e=>{(await d.s9.post("client_del",{index:e})).code===_.m.Success?((0,u.SK)("保存成功"),$()):(0,u.zN)("网络错误")})(s+1)}}),e.is_new?(0,y.jsx)(a.rA,{icon:"add",title:n("添加"),onClick:async()=>{e.index=s+1,await N(e)}}):(0,y.jsx)(a.rA,{icon:"save",title:n("保存"),onClick:async()=>{e.index=s+1,await N(e)}})]})]),width:"10rem"})]})})]}),(0,y.jsxs)(l.fI,{children:[!!v?.length&&(0,y.jsx)(l.VP,{widthPer:40,children:(0,y.jsx)(r.Zp,{title:n("br_port"),children:(0,y.jsx)(c.X,{headers:C,rows:v.map((e,n)=>[(0,y.jsx)("p",{children:n}),(0,y.jsx)(r.xP,{children:e.server_port}),(0,y.jsx)(r.xP,{children:e.client_name})]),width:"10rem"})})}),!!g?.length&&(0,y.jsx)(l.VP,{widthPer:40,children:(0,y.jsx)(r.Zp,{title:n("文件同步列表"),children:(0,y.jsx)(c.X,{headers:I,rows:g.map((e,n)=>[(0,y.jsx)("p",{children:n}),(0,y.jsx)(r.xP,{children:e.source_client_name}),(0,y.jsx)(r.xP,{children:e.target_client_name}),(0,y.jsx)(r.xP,{children:e.running_num})]),width:"10rem"})})})]})]})}function A(){const{t:e,i18n:n}=(0,i.Bd)(),{initUserInfo:t,reloadUserInfo:v}=(0,s.useContext)(x.F),[f,g]=(0,h.fp)(p.AG.user_base_info),[w,S]=(0,h.fp)(p.AG.prompt_card),[C,k]=(0,s.useState)(!1),[I,A]=(0,s.useState)([]),[P,$]=(0,s.useState)(null),[N,F]=(0,s.useState)([]),[K,B]=(0,s.useState)(void 0),[U,D]=(0,s.useState)(void 0),E=(0,s.useMemo)(()=>{const e=[...I];return null!=P?(e.sort((e,n)=>P?e.server_port-n.server_port:n.server_port-e.server_port),e):e},[I,P]),G=async()=>{const e=await d.s9.get("get_all_open_server_client_proxy_fig");if(e.code===_.m.Success){const n=[];for(const t of e.data)U?`${t.server_port}${t.client_name}${t.proxy_host}${t.server_port}${t.server_port_note}`.includes(U)&&n.push(t):n.push(t);A(n)}},V=async()=>{const e=await d.s9.get("server_get");e.code===_.m.Success&&(B(e.data.port),k(!!e.data.open),F(e.data.option_keys??[])),G()};(0,s.useEffect)(()=>{j.ws.addMsg(m.HK.tcp_forward_server_load,e=>{V()}),V()},[]);const q=async e=>{const n=new b.I;n.port=K,n.open=C,n.option_keys=N;(await d.s9.post("server_save",{fig:n,notice_client:e})).code===_.m.Success&&(0,u.SK)("成功")};return(0,y.jsxs)(l.fI,{children:[(0,y.jsx)(l.VP,{widthPer:33,children:(0,y.jsx)(l.xh,{children:(0,y.jsxs)(r.Zp,{title:e("服务器配置"),rightBottomCom:(0,y.jsxs)("div",{children:[(0,y.jsx)(a.C3,{text:e("sv_ntf"),clickFun:()=>{q(!0)}}),(0,y.jsx)(a.C3,{text:e("保存"),clickFun:()=>{q(!1)}})]}),children:[(0,y.jsx)(o.Sm,{placeholder:"port",value:K,handleInputChange:e=>{B(e)}}),(0,y.jsxs)("label",{children:[(0,y.jsx)(a.rA,{icon:"add",onClick:()=>{F([...N,""])},title:e("添加")}),e("key")]}),(N??[]).map((n,t)=>(0,y.jsxs)("div",{style:{display:"flex"},children:[(0,y.jsx)("div",{style:{width:"90%"},children:(0,y.jsx)(o.Sm,{type:"password",value:n,handleInputChange:e=>{N[t]=e,F([...N])}})}),(0,y.jsx)(a.rA,{icon:"delete",onClick:()=>{N.splice(t,1),F([...N])},title:e("删除")})]},t)),(0,y.jsxs)("form",{children:[e("状态"),":",(0,y.jsx)(c.S,{isFlex:!0,columns:[(0,y.jsx)(o.U6,{value:1,context:e("开启"),selected:C,onchange:()=>{k(!C)}}),(0,y.jsx)(o.U6,{value:1,context:e("关闭"),selected:!C,onchange:()=>{k(!C)}})]})]})]})})}),(0,y.jsx)(l.VP,{widthPer:50,children:(0,y.jsx)(l.xh,{children:(0,y.jsx)(r.uF,{self_title:(0,y.jsx)("span",{className:" div-row ",children:(0,y.jsx)("h2",{children:e("服务器")+e("端口映射")})}),rightTopCom:(0,y.jsx)(o.Sm,{placeholder:e("过滤"),value:U,handleInputChange:e=>{D(e)},handlerEnter:()=>{G()}}),children:(0,y.jsx)(c.X,{headers:[e("序号"),(0,y.jsx)(a.rA,{title:e("服务端口"),onClick:()=>{$(e=>!e)}}),e("转发ip"),e("转发端口"),"client "+e("名称"),e("开启"),e("备注")],rows:E.map((e,n)=>[(0,y.jsx)("p",{children:n}),(0,y.jsx)(r.xP,{children:e.server_port}),(0,y.jsx)(r.xP,{children:e.proxy_host}),(0,y.jsx)(r.xP,{children:e.proxy_port}),(0,y.jsx)(r.xP,{children:e.client_name}),(0,y.jsx)(r.fq,{ok:!!e.open_success}),(0,y.jsx)(r.xP,{children:e.server_port_note})]),width:"10rem"})})})})]})}var P=t(47996),$=t(78247);function N(){const{t:e,i18n:n}=(0,i.Bd)(),{initUserInfo:t,reloadUserInfo:j}=(0,s.useContext)(x.F),[m,v]=(0,h.fp)(p.AG.user_base_info),[f,g]=(0,h.fp)(p.AG.prompt_card),[,w]=(0,h.fp)(p.AG.confirm),[S,C]=(0,h.fp)(p.AG.editorSetting),[k,I]=(0,s.useState)([]),[A,N]=(0,s.useState)([]),F=[e("编号"),e("原客户端"),e("开启"),e("备注"),e("操作")],[K,B]=(0,s.useState)(null);(0,s.useEffect)(()=>{(async()=>{const e=await d.s9.get("server_client_get");if(e.code===_.m.Success){const n=e.data,t=[];for(const e of n)t.push({label:e.client_name,value:e.client_num_id});N(t),await U()}})()},[]);const U=async()=>{const e=await d.s9.get("sync_task_get");e.code===_.m.Success&&I(e.data)},D=e=>A.find(n=>String(n.value)===String(e))?.label??"",E=e=>A.find(n=>String(n.value)===String(e)),G=(e,n,t)=>{K?.targets&&(K.targets[e]={...K.targets[e],[n]:t},B({...K,targets:[...K.targets]}))},V=async e=>{(await d.s9.post("sync_task_save",e)).code===_.m.Success&&await U()};return(0,y.jsxs)(l.fI,{children:[(0,y.jsx)(l.VP,{widthPer:50,maxWidth:"40rem",children:(0,y.jsx)(l.xh,{children:(0,y.jsx)(r.uF,{self_title:(0,y.jsxs)("span",{className:" div-row ",children:[(0,y.jsx)("h2",{children:e("客户端文件同步")}),(0,y.jsx)(a.rA,{icon:"info",onClick:()=>{g({open:!0,title:"信息",context_div:(0,y.jsx)("div",{children:(0,y.jsxs)("ul",{children:[(0,y.jsx)("li",{children:e("sy_tp1")}),(0,y.jsx)("li",{children:e("sy_tp2")}),(0,y.jsx)("li",{children:e("sy_tp3")})]})})})},title:e("信息")})]}),rightTopCom:(0,y.jsx)("div",{children:(0,y.jsx)(a.rA,{icon:"add",title:e("添加"),onClick:()=>{B({open:!1,source_client_num_id:void 0,source_dir:"",targets:[],delete_missing:!0,is_new:!0})}})}),children:(0,y.jsx)(c.X,{headers:F,rows:k.map((n,t)=>[(0,y.jsx)("p",{children:t}),(0,y.jsx)(r.xP,{children:n.source_client_name}),(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(r.fq,{ok:!!n.open}),n.open?e("开启"):e("关闭")]}),(0,y.jsx)(r.xP,{children:n.note}),(0,y.jsxs)("div",{children:[(0,y.jsx)(a.rA,{icon:"edit",title:e("编辑"),onClick:()=>(e=>{B(JSON.parse(JSON.stringify(e)))})(n)}),(0,y.jsx)(a.rA,{icon:"sync",title:e("立即同步"),onClick:()=>(async n=>{if(!n.id||!n.open)return void(0,u.zN)(e("tsk_off"));const t=await d.s9.post("sync_task_rescan",{id:n.id});t.code===_.m.Success?(0,u.SK)(e("已触发同步")):(0,u.zN)(t.message??e("操作失败"))})(n)}),(0,y.jsx)(a.rA,{icon:"delete",title:e("删除"),onClick:()=>{w({open:!0,title:e("确定删除吗"),handle:async()=>{await(async n=>{(await d.s9.post("sync_task_del",{id:n})).code===_.m.Success&&((0,u.SK)(e("成功")),K?.id===n&&B(null),await U())})(n.id),w({open:!1,handle:null})}})}})]})]),width:"10rem"})})})}),(0,y.jsx)(l.VP,{widthPer:50,children:K&&(0,y.jsx)(l.xh,{children:(0,y.jsxs)(r.Zp,{self_title:(0,y.jsx)("span",{className:" div-row ",children:(0,y.jsx)("h2",{children:e(""+(K.is_new?"添加":"编辑"))})}),rightBottomCom:(0,y.jsxs)("div",{children:[(0,y.jsx)(a.rA,{icon:"cancel",title:e("取消"),onClick:()=>B(null)}),(0,y.jsx)(a.rA,{icon:"save",title:e("保存"),onClick:async()=>{if(!K)return;const n=K,t=await d.s9.post("sync_task_save",n);t.code===_.m.Success?((0,u.SK)(e("成功")),B(null),await U()):(0,u.zN)(t.message??e("操作失败"))}})]}),children:[(0,y.jsx)(o.BC,{label:e("开启"),label_width:"6rem",children:(0,y.jsx)(o.GL,{selected:!!K.open,onchange:()=>{B({...K,open:!K.open})}})}),(0,y.jsx)(o.BC,{label:e("备注"),label_width:"6rem",children:(0,y.jsx)(o.Sm,{value:K.note,handleInputChange:e=>{B({...K,note:e})}})}),(0,y.jsx)(o.BC,{label:e("原客户端"),label_width:"6rem",required:!0,children:(0,y.jsx)(o.Sm,{value:D(K.source_client_num_id),options:A,handleInputChange:e=>{const n=E(e);n&&B({...K,source_client_num_id:parseInt(String(n.value))})}})}),(0,y.jsx)(o.BC,{label:e("原目录"),label_width:"6rem",required:!0,children:(0,y.jsx)(o.Sm,{value:K.source_dir,placeholder:e("被同步的源目录"),handleInputChange:e=>{B({...K,source_dir:e})}})}),(0,y.jsx)("label",{children:e("目标列表")}),(K.targets??[]).map((n,t)=>(0,y.jsxs)(P.d,{title:`${e("目标")}${t+1}`,toolbar:(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(o.BC,{label:e("全量同步"),label_width:"6rem",children:(0,y.jsx)(o.GL,{selected:!!n.full_sync,onchange:()=>G(t,"full_sync",!n.full_sync)})}),(0,y.jsx)(a.rA,{icon:"delete",title:e("删除"),onClick:()=>(e=>{if(!K?.targets)return;const n=[...K.targets];n.splice(e,1),B({...K,targets:n})})(t)})]}),children:[(0,y.jsx)(o.BC,{label:e("客户端"),label_width:"6rem",required:!0,children:(0,y.jsx)(o.Sm,{value:D(n.client_num_id),options:A,handleInputChange:e=>{const n=E(e);n&&G(t,"client_num_id",parseInt(String(n.value)))}})}),(0,y.jsx)(o.BC,{label:e("目标目录"),label_width:"6rem",required:!0,children:(0,y.jsx)(o.Sm,{value:n.dir,handleInputChange:e=>G(t,"dir",e)})})]},t)),(0,y.jsxs)("div",{className:"div-row",children:[(0,y.jsx)(a.rA,{icon:"add",title:e("添加"),onClick:()=>{if(!K)return;const e=[...K.targets??[],{client_num_id:void 0,dir:"",full_sync:!1}];B({...K,targets:e})}}),(0,y.jsx)(a.rA,{icon:"edit",title:e("忽略目录"),onClick:()=>{var e;e=K,$.xK.set_value_temp(e.ignore_text??b.mo),C({model:"ace/mode/gitignore",open:!0,fileName:"",save:async n=>{e.ignore_text=n,B({...e}),$.xK.set_value_temp(""),await V(e)}})}})]})]})})})]})}var F=t(87361);function K(){const{t:e}=(0,i.Bd)(),n=[{index:1,name:e("客户端"),rto:"tcp_proxy_client/",component:(0,y.jsx)(I,{})},{index:2,name:e("服务端"),rto:"tcp_proxy_server_info/",component:(0,y.jsx)(A,{})},{index:3,name:`${e("客户端列表")}(${e("服务端")})`,rto:"tcp_proxy_server_client/",component:(0,y.jsx)(C,{})},{index:4,name:`${e("客户端功能")}(${e("服务端")})`,rto:"tcp_proxy_server_client_setting/",component:(0,y.jsx)(N,{})}];return(0,y.jsx)(l.W1,{optionList:n,father_route:F.o.net_proxy})}},6960(e,n,t){t.d(n,{s:()=>r});var s=t(72635);const l=1440,i=525600;function r(e){e=e>1e12?e:1e3*e;const n=Date.now(),t=Math.abs(n-e)/6e4;return t<1?s.Ay.t("小于一分钟"):t<60?`${t.toFixed(0)} ${s.Ay.t("分钟前")}`:t<l?`${(t/60).toFixed(0)} ${s.Ay.t("小时前")}`:t<43200?`${(t/l).toFixed(0)} ${s.Ay.t("天前")}`:t<i?`${(t/43200).toFixed(0)} ${s.Ay.t("月前")}`:`${(t/i).toFixed(0)} ${s.Ay.t("年前")}`}},24659(e,n,t){t.d(n,{K:()=>l});var s=t(22022);const l=()=>{const{t:e}=(0,s.Bd)();return[{title:e("是"),value:!0,color:"#28a745"},{title:e("否"),value:!1,color:"#666666"}]}}}]);
|