filecat 7.31.1 → 7.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +21 -18
  2. package/build/dist/1448.ec0a69fe6ffca6c8df19.js +1 -0
  3. package/build/dist/1922.87a099397741d80df6ad.js +2 -0
  4. package/build/dist/2091.8324e03dcf28985539eb.js +1 -0
  5. package/build/dist/2136.20ea58a65c7fb22d5e43.js +1 -0
  6. package/build/dist/3187.67ad7348b6b7231e657d.js +1 -0
  7. package/build/dist/{3355.fde87101c5a125b8b35f.js → 3355.80b3ed1fdc66b35bd95a.js} +1 -1
  8. package/build/dist/4350.799e1d3b7382a15d295b.js +1 -0
  9. package/build/dist/{4598.0a8c8a04d718951d6692.js → 4598.4d016ea700f650cd1023.js} +1 -1
  10. package/build/dist/{47.1990e4d7ad6e60650aa0.js → 47.8c46e919a7977a77bc14.js} +1 -1
  11. package/build/dist/{6097.9ec647296d88d8025198.js → 6097.da228e297f45f3ec882d.js} +1 -1
  12. package/build/dist/610.9b08d7248340d26dead2.js +1 -0
  13. package/build/dist/6439.f3ddea3c0ef57dcbf23c.js +1 -0
  14. package/build/dist/7212.a825bc171875985e1aab.js +1 -0
  15. package/build/dist/{7678.7ad7da19e968caed935a.js → 7678.926d8c2225731a655537.js} +1 -1
  16. package/build/dist/7759.14e1e0dbbcfc86f3e4f1.js +1 -0
  17. package/build/dist/914.bb6f2b6d8ca806f9366a.js +1 -0
  18. package/build/dist/{9260.da294480ffc3c674bde0.js → 9260.7fbe354ea4e6bee93817.js} +1 -1
  19. package/build/dist/9290.6fd29c7dd03124235217.js +1 -0
  20. package/build/dist/9345.9342b70ddc66397cafce.js +1 -0
  21. package/build/dist/9546.fde8cbe4ebe2dafb6c27.js +1 -0
  22. package/build/dist/{9765.7f8eaa343038f1f21810.js → 9765.7f02ad22213339511811.js} +1 -1
  23. package/build/dist/9861.f266cc5eabb83fc5fa4b.js +1 -0
  24. package/build/dist/index.html +1 -1
  25. package/build/dist/main.b0bcf1b153b849530789.js +2 -0
  26. package/build/main.js +1 -1
  27. package/package.json +6 -1
  28. package/build/dist/1448.2340fca4e068db687c5c.js +0 -1
  29. package/build/dist/1922.c114fe6ee22d708a2a57.js +0 -2
  30. package/build/dist/2136.60e61c9c37b92af2c0d5.js +0 -1
  31. package/build/dist/4350.c743128b55202fecc4d7.js +0 -1
  32. package/build/dist/621.965609c72555c936154d.js +0 -1
  33. package/build/dist/6439.3747e3eab0dfe59ae24b.js +0 -1
  34. package/build/dist/7759.0860534bbc24ba31f42c.js +0 -1
  35. package/build/dist/9345.1dbe1ec2d934dc5ca747.js +0 -1
  36. package/build/dist/9546.827d973d735209b0b43e.js +0 -1
  37. package/build/dist/main.4d786381d17f4a7df3dd.js +0 -2
  38. /package/build/dist/{1922.c114fe6ee22d708a2a57.js.LICENSE.txt → 1922.87a099397741d80df6ad.js.LICENSE.txt} +0 -0
  39. /package/build/dist/{main.4d786381d17f4a7df3dd.js.LICENSE.txt → main.b0bcf1b153b849530789.js.LICENSE.txt} +0 -0
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[9345],{49345(e,s,t){t.r(s),t.d(s,{default:()=>me});var n=t(96540),i=t(34843),a=t(22022),o=t(52671),c=t(14284),r=t(7463),l=t(78247),d=t(53459),u=t(82893),m=t(61443);function g(e){return null==e||e<0?"0":e.toLocaleString()}var h=t(14944),_=t(92275),p=t(62042),f=t(83277);let x=0;function j(){return-++x}function v(e=[]){let s=0;const t=[];if(!Array.isArray(e))return t;for(const n of e){if(!n||"user"!==n.role&&"assistant"!==n.role)continue;const e=!!n.content_list?.length?n.content_list:[{role:n.role,content:n.content,tool_call_ends:n.tool_call_ends,message_type:n.message_type,ask_user:n.ask_user}],i=e.filter(e=>"ask_user"!==e.message_type),a=e.filter(e=>"ask_user"===e.message_type&&e.ask_user&&!0!==e.ask_user.confirmed),o=i.map(e=>(0,f.$j)(e.content)).filter(Boolean).join("\n\n"),c=i.some(e=>e.tool_call_ends?.length);(o||c||n.images?.length||n.audio||n.attachments?.length)&&t.push({id:++s,sender:"assistant"===n.role?"bot":"user",text:o,attachments:n.attachments??[],content_list:c?i:void 0,images:n.images,audio:n.audio,embeddings:n.embeddings,elapsed_ms:n.elapsed_ms});for(const e of a)t.push({id:++s,sender:"bot",text:"",interactive:b(e.ask_user)})}return t}function b(e){return"confirm_cmd"===e.kind?{kind:"confirm_cmd",ask_id:e.ask_id,cmd:e.cmd}:{kind:"ask_user",ask_id:e.ask_id,title:e.title,description:e.description,fields:e.fields??[]}}const y=/\.(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 S(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||y.test(e.name)?"text":"binary"}const w={"image/png":"png","image/jpeg":"jpg","image/gif":"gif","image/webp":"webp","image/bmp":"bmp","image/svg+xml":"svg"};function N(e){return e.text()}function k(e){return new Promise((s,t)=>{const n=new FileReader;n.onload=()=>s(n.result),n.onerror=t,n.readAsDataURL(e)})}function C(e){return"bot"!==e.sender||!!(e.text||e.content_list?.length||e.attachments?.length)}var A=t(21499),M=t(64694),$=t(45907),I=t(74848);var R=t(40505);function D(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,f.$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 B(e){const{active_session_id_ref:s,local_owner_ref:t,subscribed_ref:i,set_messages:a,scroll_to_bottom:o,follow_ref:c,mark_session_running:r,refresh_sessions:l,reload_session:d,set_active_session_running:u,on_chat_end:m}=e,g=(0,n.useRef)(new Map);return(0,n.useEffect)(()=>{const e=()=>s.current,n=(s,n,o)=>{if(m?.(s),r(s,!1),e()&&e()===s){if(g.current.clear(),u(!1),i.current===s&&(h.ws.sendData(_.HK.ai_chat_subscribe,{session_id:s,subscribe:!1}),i.current=null),t.current===s)return void(t.current=null);n?.length&&!o?a(e=>{let s=e.length;for(;s>0&&"bot"===e[s-1].sender;)s--;return[...e.slice(0,s),...v(n)].map((e,s)=>({...e,id:s+1}))}):d(s).catch(()=>{})}l()},p=s=>{const n=s?.context||{};n.session_id&&(((s,n,i,r,l=0)=>{e()&&e()===s&&t.current!==s&&a(e=>{const s=g.current,t=r?-(l+1):l;let a=e;if(!r){const e=-(l+1),t=s.get(e);void 0!==t&&(a=a.filter(e=>e.id!==t),s.delete(e))}const d=s.get(t),u=void 0===d?-1:a.findIndex(e=>e.id===d),m=-1===u?{id:j(),sender:"bot",text:""}:{...a[u]};if(-1===u&&s.set(t,m.id),r)m.text=n,m.is_loading=!0;else if(n){m.text=m.text+n;const e=m.content_list?.[0];e&&(e.content=m.text),m.is_loading=!1}if(i&&(m.content_list=[{tool_call_ends:i,content:m.text,role:"assistant"}],m.is_loading=!1),c.current&&requestAnimationFrame(()=>o()),-1===u)return[...a,m];const h=a.slice();return h[u]=m,h})})(n.session_id,n.text||"",n.tool_call_ends,n.notice,n.chunk_index),r(n.session_id,!0))},f=e=>{const s=e?.context||{};s.session_id&&n(s.session_id,s.once_messages_list,s.is_continue)},x=e=>{const s=e?.context||{};s.session_id&&n(s.session_id,s.once_messages_list,!0)};return h.ws.addMsg(_.HK.ai_chat_msg,p),h.ws.addMsg(_.HK.ai_chat_end,f),h.ws.addMsg(_.HK.ai_chat_error,x),()=>{h.ws.off_message(`message_${_.HK.ai_chat_msg}`,p),h.ws.off_message(`message_${_.HK.ai_chat_end}`,f),h.ws.off_message(`message_${_.HK.ai_chat_error}`,x),i.current&&(h.ws.sendData(_.HK.ai_chat_subscribe,{session_id:i.current,subscribe:!1}),i.current=null)}},[]),{chunkBubbleRef:g,bind_live_bubbles:(e,s)=>{g.current.clear();for(let t=0;t<s;t++){const n=e[e.length-s+t];n&&g.current.set(t,n.id)}},clear_bubbles:()=>g.current.clear()}}var T=t(85997),V=t(37470);function E(e){const s=e.attachments&&e.attachments.length>0?(0,I.jsx)("div",{className:"chat-message-attachments",children:e.attachments.map((e,s)=>(0,I.jsxs)("div",{className:"chat-message-attachment",children:[(0,I.jsx)(T.In,{icon:"attach_file"}),(0,I.jsx)("span",{children:e.name}),(0,I.jsxs)("small",{children:[e.size," B"]})]},`${e.name}_${s}`))}):null,t=[];e.images&&"bot"===e.sender&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(H,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(K,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(z,{embeddings:e.embeddings,text:e.text})},"embeddings"));const i=function(e){if("bot"!==e.sender||!e.content_list?.length)return e.text?(0,I.jsx)(V.default,{context:e.text}):null;return(0,I.jsxs)(I.Fragment,{children:[e.content_list.map((e,s)=>{const t=[],i=(0,f.$j)(e.content);return i&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(V.default,{context:i})},`content-${s}`)),e.tool_call_ends?.length&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(F,{callList:e.tool_call_ends})},`tool-${s}`)),(0,I.jsx)(n.Fragment,{children:t},`part-${s}`)}),!e.content_list.some(e=>e.content)&&e.text?(0,I.jsx)(V.default,{context:e.text}):null]})}(e);return 0===t.length?(0,I.jsxs)(I.Fragment,{children:[s,i]}):(0,I.jsxs)(I.Fragment,{children:[t,s,i]})}function F({callList:e}){const[s,t]=n.useState(!1);if(!e?.length)return null;e.filter(e=>e.success).length;const i=e.filter(e=>!e.success).length;return(0,I.jsxs)("div",{className:"chat-message-call-list",children:[(0,I.jsxs)("div",{className:"call-list-header",onClick:()=>t(!s),children:[(0,I.jsx)(T.In,{icon:s?"expand_less":"expand_more"}),(0,I.jsxs)("span",{className:"call-list-summary",children:["工具调用 (",e.length,")",i>0&&(0,I.jsx)("span",{className:"call-list-fail",children:" 失败 "})]})]}),s&&(0,I.jsx)("div",{className:"call-list-body",children:e.map((e,s)=>(0,I.jsxs)("div",{className:"call-list-item "+(e.success?"call-success":"call-fail"),children:[(0,I.jsxs)("div",{className:"call-list-item-header",children:[(0,I.jsx)(T.In,{icon:e.success?"check_circle":"error"}),(0,I.jsx)("span",{className:"call-list-tool-name",children:e.tool_display_name||e.tool_name}),(0,I.jsxs)("span",{className:"call-list-duration",children:[e.duration_ms,"ms"]})]}),e.tool_args&&(0,I.jsxs)("details",{className:"call-list-details",children:[(0,I.jsx)("summary",{children:"参数"}),(0,I.jsx)("pre",{className:"call-list-pre",children:JSON.stringify(e.tool_args,null,2)})]}),!e.success&&e.error&&(0,I.jsxs)("details",{className:"call-list-details",children:[(0,I.jsx)("summary",{children:"错误"}),(0,I.jsx)("pre",{className:"call-list-pre call-list-error-text",children:e.error})]}),e.success&&e.tool_result&&(0,I.jsxs)("details",{className:"call-list-details",children:[(0,I.jsx)("summary",{children:"结果"}),(0,I.jsx)("pre",{className:"call-list-pre",children:e.tool_result.length>500?e.tool_result.slice(0,500)+"...":e.tool_result})]})]},s))})]})}function H({images:e,text:s}){let t=e||[];if(!t.length&&s)try{t=JSON.parse(s).data||[]}catch{}return t.length?(0,I.jsxs)("div",{className:"image-generation-result",children:[t.map((e,s)=>(0,I.jsxs)("div",{className:"image-generation-item",children:[e.url&&(0,I.jsx)("div",{className:"image-generation-image-wrapper",children:(0,I.jsx)("img",{src:e.url,alt:e.revised_prompt||`生成的图片 ${s+1}`,loading:"lazy"})}),e.b64_json&&(0,I.jsx)("div",{className:"image-generation-image-wrapper",children:(0,I.jsx)("img",{src:`data:image/png;base64,${e.b64_json}`,alt:`生成的图片 ${s+1}`})}),e.revised_prompt&&(0,I.jsx)("p",{className:"image-generation-prompt",children:(0,I.jsx)("small",{children:e.revised_prompt})})]},s)),s&&!e&&(0,I.jsx)(V.default,{context:s})]}):(0,I.jsx)(V.default,{context:s||""})}function K({audio:e,text:s}){if(e){if(e.url)return(0,I.jsx)("div",{className:"audio-result",children:(0,I.jsx)("audio",{controls:!0,src:e.url,children:"您的浏览器不支持音频播放"})});if(e.data){const s=e.mime_type||"audio/mpeg";return(0,I.jsx)("div",{className:"audio-result",children:(0,I.jsx)("audio",{controls:!0,src:`data:${s};base64,${e.data}`,children:"您的浏览器不支持音频播放"})})}}const t=s||"";if(t.startsWith("http://")||t.startsWith("https://"))return(0,I.jsx)("div",{className:"audio-result",children:(0,I.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,I.jsx)("div",{className:"audio-result",children:(0,I.jsx)("audio",{controls:!0,src:`data:audio/mpeg;base64,${s}`,children:"您的浏览器不支持音频播放"})})}}catch{}return(0,I.jsx)(V.default,{context:t})}function P({content:e,label:s}){const[t,i]=n.useState(!1);return(0,I.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,R.lW)(e),i(!0),setTimeout(()=>i(!1),1500)},children:[(0,I.jsx)(T.In,{icon:t?"check":"content_copy"}),t?"已复制":s||"复制"]})}function z({embeddings:e,text:s}){let t=e||null;if(!t&&s)try{t=JSON.parse(s)}catch{return(0,I.jsx)(V.default,{context:s})}if(!t)return(0,I.jsx)(V.default,{context:s||""});const n=t?.data||[],i=t?.usage,a=JSON.stringify(t,null,2);return(0,I.jsxs)("div",{className:"embeddings-result",children:[(0,I.jsxs)("div",{className:"embeddings-summary",children:[(0,I.jsx)("strong",{children:"向量嵌入结果"}),(0,I.jsxs)("span",{children:["维度: ",n[0]?.embedding?.length??"N/A"]}),(0,I.jsxs)("span",{children:["数量: ",n.length]}),i&&(0,I.jsxs)("span",{children:["使用 tokens: ",i.total_tokens??"N/A"]})]}),(0,I.jsxs)("div",{className:"embeddings-toolbar",children:[(0,I.jsx)(P,{content:a,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,I.jsx)(P,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,I.jsx)(P,{content:JSON.stringify(n.map(e=>e.embedding),null,2),label:"复制所有向量数据"})]}),n.length>0&&n[0]?.embedding&&(0,I.jsx)("div",{className:"embeddings-preview",children:(0,I.jsxs)("span",{children:["向量预览: [",n[0].embedding.slice(0,5).join(", "),n[0].embedding.length>5?", ...":"","]"]})}),n.length>0&&(0,I.jsxs)("details",{children:[(0,I.jsx)("summary",{children:"查看详细数据"}),(0,I.jsx)("pre",{className:"embeddings-raw",children:a})]})]})}async function L(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 i=n.data||{},a=(i.data||[]).map(e=>({url:e.url,b64_json:e.b64_json,revised_prompt:e.revised_prompt})),o=a.map((e,s)=>`![生成图片${s+1}](${e.url||`data:image/png;base64,${e.b64_json}`})${e.revised_prompt?`\n> ${e.revised_prompt}`:""}`).join("\n\n");return{session_id:i.session_id||s,images:a,text:o||`生成了 ${a.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{bytes:n,headers:i}=await c.jV.post_bytes("audio/speech",t);return{session_id:i.get("X-Session-Id")||s,audio:{data:btoa(String.fromCharCode(...Array.from(n))),mime_type:i.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||{},i=n?.data??[],a=`向量维度: ${i[0]?.embedding?.length??0}, 数量: ${i.length}`;return{session_id:n.session_id||s,embeddings:n,text:`✅ Embeddings 结果 - ${a}\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 O=t(4412),q=t(23430),G=t(87361),U=t(80389),J=t(7523),W=t(23496);const X=({currentModelName:e,setCurrentModelName:s,modelGroups:t,onModelChanged:r,batchMode:g,selectedMsgCount:h,sessionVisible:_,onToggleSessionPanel:f,onCreateSession:x,onToggleBatchMode:j,onBatchDeleteMessages:v,bgProcessVisible:b,bgProcessCount:y,onToggleBgProcess:S,inline:w})=>{const{t:N}=(0,a.Bd)(),k=(0,o.Zp)(),{check_user_auth:C}=(0,l.MH)(),[,A]=(0,i.fp)(u.AG.ai_session_collapsed),{open:M}=function(){const{t:e}=(0,a.Bd)(),[,s]=(0,i.fp)(u.AG.prompt_card),[t,o]=(0,i.fp)(u.AG.ai_chat_zoom),{initUserInfo:r}=(0,n.useContext)(J.F);return{open:()=>{const n=t,i=()=>s({open:!1});s({open:!0,title:e("缩放调整"),context_div:(0,I.jsx)(U.p,{defaultValue:t,onChange:o,min:30,max:200}),cancel:()=>{o(n),i()},confirm:async()=>{let s=100;o(e=>(s=e<30||e>200?100:e,s)),await c.wm.post(W.s.user_save_private_attr,{is_ai_chat_zoom:!0,ai_chat_zoom:s}),(0,p.SK)(e("缩放调整成功")),r(),i()}})}}}(),$=C(q.oV.ai_model_switch)||C(q.oV.ai_agent_setting),R=[];for(const e of t)for(const s of e.models)R.push({title:s.label||s.value,value:`${e.index}::${s.value}`,group:e.note});const D=t.find(e=>e.active),B=D?`${D.index}::${e}`:"",V=(0,I.jsxs)(n.Fragment,{children:[(0,I.jsx)(T.rA,{icon:"menu",title:N("会话"),onClick:f,selected:_}),(0,I.jsx)(T.rA,{icon:"add",title:N("新会话"),onClick:()=>x()}),$&&R.length>0&&(0,I.jsx)(m.l6,{value:B,options:[{title:N("选择模型"),value:""},...R],margin:"0 0 0 1em",onChange:e=>{const t=String(e??"");if(!t.includes("::"))return;const[n,...i]=t.split("::"),a=i.join("::");a&&(s(a),c.jV.post("set_active_model",{index:Number(n),model_name:a}).then(e=>{e?.code===d.m.Success?((0,p.SK)("success"),r()):(0,p.zN)(e?.message||"fail")}).catch(console.error))},no_border:!0,width:"auto"}),g&&(0,I.jsx)(T.rA,{icon:"done",title:N("完成"),onClick:j}),g&&h>0&&(0,I.jsx)(T.rA,{icon:"delete",title:N("删除选中消息"),onClick:v}),(0,I.jsx)(T.rA,{icon:"zoom_in",title:N("缩放调整"),onClick:M}),(0,I.jsx)(T.rA,{icon:"terminal",title:N("后台进程"),onClick:S,selected:b,tip:y||null}),C(q.oV.ai_agent_setting)&&(0,I.jsx)(T.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{k(G.o.ai_rebot_setting_page)}}),C(q.oV.ai_agent_setting)&&(0,I.jsx)(T.rA,{icon:"settings",title:"ai setting",onClick:()=>{k(G.o.ai_agent_setting_page)}})]});return w?(0,I.jsx)("div",{className:"chat-inline-header",children:V}):(0,I.jsx)(O.aZ,{position:"right",children:V})};var Y=t(75725);function Z({items:e}){const s=e.filter(e=>!!e.text);return 0===s.length?null:(0,I.jsx)("div",{className:"chat-session-meta",children:s.map((e,s)=>(0,I.jsx)("small",{className:e.className,title:e.title,children:e.text},s))})}var Q=t(29993);function ee(e){return e||"新会话"}function se({sessions:e,activeSessionId:s,onSelectSession:t,onReorderSessions:i,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:j,sysPromptList:v,onChangeSysPrompt:b}){const{t:y}=(0,a.Bd)(),[S,w]=(0,n.useState)(""),N=(0,n.useRef)(null),[k,C]=(0,n.useState)(null),[A,M]=(0,n.useState)(null),[$,R]=(0,n.useState)(null),D=!!i&&!f,B=e=>{if(!e)return"";const s=v?.find(s=>String(s.index)===String(e));return s?s.note||s.prompt.slice(0,20):""},V=e=>[{text:String(e.message_count??""),className:"chat-session-meta__count",title:y("消息数")},{text:B(e.sys_prompt_id),className:"chat-session-meta__prompt",title:y("系统提示词")},{text:"web"!==e.source?e.source:"",className:"chat-session-meta__source",title:y("来源")},{text:f&&e.owner_name||"",className:"chat-session-meta__owner",title:e.owner_name}],E=S.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(S.toLowerCase())||(e.summary||"").toLowerCase().includes(S.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(S.toLowerCase())||f&&(e.owner_name||"").toLowerCase().includes(S.toLowerCase())):e,F=e.find(e=>e.id===s);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("aside",{className:"chat-session-list",children:[(0,I.jsxs)("div",{className:"chat-session-search",children:[(0,I.jsx)(Q.D,{placeholder:y("搜索会话"),value:S,onChange:w}),F&&(0,I.jsx)("button",{className:"chat-session-current",title:ee(F.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 w(""),void requestAnimationFrame(()=>requestAnimationFrame(s));s()})(F.id),children:(0,I.jsx)("span",{children:ee(F.title)})})]}),(0,I.jsx)("div",{className:"chat-session-items-wrap",ref:N,children:E.map((e,n)=>(0,I.jsx)("div",{"data-session-id":e.id,children:(0,I.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:D,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||!i)return;const t=E[s]?.id,n=E[e]?.id;t&&n&&i(t,n)})(n)},onClick:()=>{u&&g?g(e.id):t(e.id)},title:e.summary||e.long_term_memory||e.title,children:[u&&(0,I.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:m?.has(e.id)??!1,onChange:()=>g?.(e.id),onClick:e=>e.stopPropagation()}),(0,I.jsx)("span",{children:ee(e.title)}),e.running&&(0,I.jsx)("span",{className:"chat-session-running",title:y("正在执行中")}),(0,I.jsx)(Z,{items:V(e)}),!u&&(0,I.jsx)("i",{className:"chat-session-more material-icons",title:y("更多操作"),onClick:s=>{s.stopPropagation();const t=s.currentTarget.getBoundingClientRect();R({x:t.right,y:t.bottom,session:e})},children:"more_horiz"})]})},e.id))}),(0,I.jsxs)("div",{className:"chat-session-actions",children:[(0,I.jsx)(T.rA,{icon:u?"check_circle":"checklist",title:y(u?"取消批量选择":"批量选择"),onClick:h}),j&&!u&&(0,I.jsx)(T.rA,{icon:f?"person":"groups",title:y(f?"仅看我的会话":"查看所有用户会话"),onClick:x}),u&&(m?.size??0)>0&&(0,I.jsx)(T.rA,{icon:"delete",title:y("删除选中会话"),onClick:_}),!u&&p&&(0,I.jsx)(T.rA,{icon:"delete_sweep",title:y("删除全部会话"),onClick:p})]})]}),$&&(0,I.jsx)(Y.rY,{click:()=>R(null),children:(0,I.jsx)(Y.sw,{x:$.x,y:$.y,items:(e=>{const s=[{r:y("重命名"),v:"rename",run:()=>o(e.id,e.title)},...f?[]:[{r:y("移动到最上"),v:"to_top",run:()=>{const s=E[0];s&&s.id!==e.id&&i?.(e.id,s.id)}},{r:y("移动到最下"),v:"to_bottom",run:()=>{const s=E[E.length-1];s&&s.id!==e.id&&i?.(e.id,s.id)}}],{r:e.cmd_auto_allow?y("命令检测关闭"):y("命令检测开启"),v:"cmd_auto",run:()=>r?.(e.id,!e.cmd_auto_allow)}];return v?.length&&s.push({r:y("系统提示词"),items:[{r:y("不使用"),v:"",run:()=>b?.(e.id,"")},...v.map(s=>({r:B(String(s.index)),v:String(s.index),run:()=>b?.(e.id,String(s.index))}))]}),s.push({r:y("字符消耗统计"),v:"usage",run:()=>l(e.id)},{r:y("设置"),v:"setting",run:()=>d?.(e.id)},{r:y("删除"),v:"delete",run:()=>c(e.id)}),s})($.session),pre_value:$.session.sys_prompt_id?String($.session.sys_prompt_id):"",click:(e,s)=>{R(null),s?.run?.()}})})]})}function te(e){return(0,I.jsx)("div",{className:"ai-ask-options",children:e.options.map(s=>(0,I.jsxs)("label",{className:"ai-ask-option"+(e.value===s?" ai-ask-option--on":""),children:[(0,I.jsx)("input",{type:"radio",name:e.options.join("|"),checked:e.value===s,onChange:()=>e.onChange(s)}),(0,I.jsx)("span",{children:s})]},s))})}function ne(e){return(0,I.jsx)("div",{className:"ai-ask-options",children:e.options.map(s=>(0,I.jsxs)("label",{className:"ai-ask-option"+(e.value.includes(s)?" ai-ask-option--on":""),children:[(0,I.jsx)("input",{type:"checkbox",checked:e.value.includes(s),onChange:()=>(s=>{const t=e.value.includes(s);e.onChange(t?e.value.filter(e=>e!==s):[...e.value,s])})(s)}),(0,I.jsx)("span",{children:s})]},s))})}function ie(e){const{t:s}=(0,a.Bd)(),t=e.interactive,[i,o]=(0,n.useState)({});(0,n.useEffect)(()=>{const e={};for(const s of t.fields??[])e[s.key]="checkbox"===s.type?[]:"";o(e)},[t.ask_id]);const c=s=>{e.on_resolved(t.ask_id),e.on_submit("",{ask_id:t.ask_id,answer:s})};if("confirm_cmd"===t.kind)return(0,I.jsxs)("div",{className:"ai-interactive",children:[(0,I.jsx)("p",{className:"ai-interactive-title",children:s("是否允许执行该命令")}),(0,I.jsx)("pre",{className:"ai-interactive-cmd",children:t.cmd}),(0,I.jsxs)("div",{className:"div-row",children:[(0,I.jsx)(T.C3,{text:s("允许"),clickFun:()=>c("allow")}),(0,I.jsx)(T.C3,{text:s("拒绝"),clickFun:()=>c("reject")})]})]});return(0,I.jsxs)("div",{className:"ai-interactive",children:[(0,I.jsx)("p",{className:"ai-interactive-title",children:t.title}),t.description&&(0,I.jsx)("p",{className:"ai-interactive-desc",children:t.description}),(t.fields??[]).map(e=>(0,I.jsxs)("div",{className:"ai-ask-field",children:[(0,I.jsxs)("p",{className:"ai-ask-label",children:[e.label,e.required?" *":""]}),"select"===e.type&&(0,I.jsx)(te,{options:e.options??[],value:i[e.key]??"",onChange:s=>o(t=>({...t,[e.key]:s}))}),"checkbox"===e.type&&(0,I.jsx)(ne,{options:e.options??[],value:i[e.key]??[],onChange:s=>o(t=>({...t,[e.key]:s}))}),"text"===e.type&&(e.multiline?(0,I.jsx)(m.Z2,{value:i[e.key]??"",placeholder:e.placeholder??"",handleInputChange:s=>o(t=>({...t,[e.key]:s}))}):(0,I.jsx)(m.Sm,{value:i[e.key]??"",placeholder:e.placeholder??"",handleInputChange:s=>o(t=>({...t,[e.key]:s}))}))]},e.key)),(0,I.jsxs)("div",{className:"div-row",children:[(0,I.jsx)(T.C3,{text:s("提交"),clickFun:()=>{if((t.fields??[]).filter(e=>{if(!e.required)return!1;const s=i[e.key];return""===s||void 0===s||Array.isArray(s)&&0===s.length}).length)return;(t.fields??[]).map(e=>{const s=i[e.key],t=Array.isArray(s)?s.join("、"):String(s??"");return`${e.label}:${t}`});c(JSON.stringify(i))}}),(0,I.jsx)(T.C3,{text:s("取消"),clickFun:()=>c("cancel")})]})]})}function ae(e){const s=(e.text||"").split("\n").map(e=>e.trim()).find(Boolean)||"";return s.length>80?s.slice(0,80)+"…":s}const oe=({messages:e,batchMode:s,selectedMsgIds:t,sending:i,chatContainerRef:a,messagesEndRef:o,onToggleMsgSelect:c,onDelete:r,onCopy:l,onCopyAll:d,onToggleBatchMode:u,onBatchCopy:m,onBatchDelete:g,showBatchBar:h,on_interactive_resolved:_,on_interactive_submit:p,t:f})=>{const[x,j]=(0,n.useState)(new Set),v=(0,n.useMemo)(()=>e.filter(e=>!e.is_loading).map(e=>e.id),[e]),b=e=>{j(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},y=()=>{j(e=>e.size>0&&v.every(s=>e.has(s))?new Set:new Set(v))};return(0,I.jsxs)("div",{className:"chat-messages",ref:a,"data-sending":i?"true":"false",children:[h&&(0,I.jsxs)("div",{className:"chat-message-batch-bar",children:[(0,I.jsxs)("span",{className:"batch-bar-count",children:[f("已选")," ",t.size]}),(0,I.jsx)("button",{onClick:m,children:f("复制所选")}),(0,I.jsx)("button",{onClick:g,className:"danger",children:f("删除所选")}),(0,I.jsx)("button",{onClick:u,children:f("取消")})]}),e.map(e=>{const n=x.has(e.id);return!e.interactive?.resolved||e.text||e.is_loading?(0,I.jsxs)("div",{className:`chat-message ${e.sender} ${s?"batch-mode":""} ${e.is_loading?"is-loading":""} ${n?"collapsed":""}`,children:[s&&(0,I.jsx)("input",{type:"checkbox",className:"chat-message-checkbox",checked:t.has(e.id),onChange:()=>c(e.id)}),e.interactive&&!e.interactive.resolved?(0,I.jsx)(ie,{interactive:e.interactive,on_resolved:_,on_submit:p}):e.is_loading?(0,I.jsxs)("div",{className:"ai-loading-bubble",children:[(0,I.jsxs)("div",{className:"ai-loading-dots",children:[(0,I.jsx)("span",{className:"ai-loading-dot"}),(0,I.jsx)("span",{className:"ai-loading-dot"}),(0,I.jsx)("span",{className:"ai-loading-dot"})]}),(0,I.jsx)("span",{className:"ai-loading-text",children:e.text})]}):(0,I.jsxs)(I.Fragment,{children:[n?(0,I.jsxs)("div",{className:"chat-message-summary",title:e.text,onClick:()=>b(e.id),children:[(0,I.jsx)("span",{className:"chat-message-summary-icon",children:"▸"}),(0,I.jsx)("span",{className:"chat-message-summary-text",children:ae(e)||f("(无内容)")})]}):(0,I.jsx)("div",{className:"chat-message-body",children:E(e)}),(0,I.jsxs)("div",{className:"message-actions",children:[(0,I.jsx)("button",{onClick:()=>r(e.id),children:f("删除")}),(0,I.jsx)("button",{onClick:()=>l(e),children:f("复制")}),(0,I.jsx)("button",{onClick:d,children:f("全部复制")}),(0,I.jsx)("button",{onClick:u,children:f("多选")})]}),(0,I.jsxs)("div",{className:"message-collapse-bar",children:[(0,I.jsx)("button",{onClick:()=>b(e.id),children:f(n?"展开":"折叠")}),(0,I.jsx)("button",{onClick:y,children:f("全部折叠")}),"bot"===e.sender&&null!=e.elapsed_ms&&(0,I.jsx)("span",{className:"message-elapsed",children:(0,A.kf)(e.elapsed_ms)})]})]})]},e.id):null}),(0,I.jsx)("div",{ref:o})]})},ce=(0,n.forwardRef)(function({placeholder:e="",disabled:s=!1,className:t,style:i,onEnter:a,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,I.jsx)("div",{ref:l,contentEditable:!s,suppressContentEditableWarning:!0,className:"rich-textarea"+(t?" "+t:""),style:i,onKeyDown:e=>{m||"Enter"!==e.key||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),a?.())},onPaste:o,onInput:()=>c?.(h()),onCompositionStart:()=>g(!0),onCompositionEnd:()=>g(!1),"data-placeholder":d?e:void 0})});var re=t(84369);function le({pendingAttachments:e,onRemove:s}){return 0===e.length?null:(0,I.jsx)("div",{className:"chat-attachment-strip",children:e.map((e,t)=>(0,I.jsxs)("div",{className:"chat-attachment-chip",children:[(0,I.jsx)(T.In,{icon:"attach_file"}),(0,I.jsx)("span",{title:e.name,children:e.name}),(0,I.jsx)("button",{type:"button",onClick:()=>s(t),children:(0,I.jsx)(T.In,{icon:"close"})})]},`${e.name}_${t}`))})}const de=(0,n.forwardRef)(({onSend:e,sending:s,pausing:t=!1,onAbort:o,pendingAttachments:c,onRemoveAttachment:r,onOpenFilePicker:l,onAddFiles:d,onDrop:m,onDragOver:g,fileInputRef:h,readonly:_=!1},p)=>{const{t:f}=(0,a.Bd)(),x=(0,n.useRef)(null),j=(0,n.useRef)(null),[v,b]=(0,i.fp)(u.AG.ai_chat_input_height);(0,n.useImperativeHandle)(p,()=>({getValue:()=>x.current?.getValue()??"",setValue:e=>x.current?.setValue(e),clear:()=>x.current?.clear()}));const{dragging:y,on_pointer_down:S,on_pointer_up:N}=(0,re.y)({direction:"vertical",get_start_size:()=>v,px_to_unit:e=>e/(()=>{const e=j.current;return e&&parseFloat(getComputedStyle(e).fontSize)||16})(),min:2,on_change:e=>b(e)}),k={minHeight:`${v}em`,maxHeight:`${v}em`};return(0,I.jsxs)("div",{ref:j,className:"chat-input-area"+(_?" readonly":""),onDrop:_?void 0:m,onDragOver:_?void 0:g,children:[!_&&(0,I.jsx)("div",{className:"chat-input-resize-handle"+(y?" dragging":""),onPointerDown:S}),(0,I.jsx)("input",{ref:h,type:"file",multiple:!0,style:{display:"none"},onChange:e=>{e.target.files?.length&&(d(e.target.files),e.currentTarget.value="")}}),(0,I.jsxs)("div",{className:"chat-input-shell",children:[(0,I.jsx)(le,{pendingAttachments:c,onRemove:r}),(0,I.jsx)(ce,{ref:x,placeholder:f(_?"查看全部会话时不可发送消息":"输入消息"),disabled:_,onEnter:()=>e(),onPaste:e=>{const s=Array.from(e.clipboardData?.files??[]),t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind).map(e=>e.getAsFile()).filter(e=>!!e),n=s.length>0?s:t;n.length>0&&(e.preventDefault(),d(function(e){const s=Date.now();return e.map((e,t)=>{if(e.name&&"image.png"!==e.name)return e;const n=w[e.type]??e.type?.split("/")[1]??"png";return new File([e],`screenshot_${s}_${t+1}.${n}`,{type:e.type||"image/png"})})}(n)))},className:"chat-input",style:k})]}),!_&&(0,I.jsx)(T.rA,{title:f("添加文件"),icon:"attach_file",onClick:l}),_?(0,I.jsx)("button",{className:"little-button button",disabled:!0,children:f("发送")}):t?(0,I.jsx)(T.Vi,{color:"var( --icon-yellow)",text:f("暂停中"),clickFun:()=>{}}):s?(0,I.jsx)(T.Vi,{color:"var( --icon-red)",text:f("暂停"),clickFun:o}):(0,I.jsx)(T.Vi,{text:f("发送"),clickFun:e}),y&&(0,I.jsx)("div",{className:"chat-input-overlay",onPointerUp:N})]})}),ue=function(e){const{t:s}=(0,a.Bd)(),[t,o]=(0,n.useState)([]),[c,r]=(0,n.useState)(!1),[l,d]=(0,n.useState)(null),[m,g]=(0,n.useState)(null),[f,x]=(0,n.useState)(!1),[j,v]=(0,i.fp)(u.AG.ai_bg_expanded),[,b]=(0,i.fp)(u.AG.ai_session_collapsed),y=()=>{v(!1)},S=(0,n.useCallback)(async()=>{r(!0);try{const s=new _.hf(_.HK.ai_bg_process_list_req);s.context={};const t=await h.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=S);const w=(0,n.useCallback)(async e=>{x(!0),d(e);try{const s=new _.hf(_.HK.ai_bg_process_output_req);s.context={pid:e};const t=await h.ws.send(s);g(t.context)}catch(e){console.error("获取进程输出失败",e),(0,p.zN)(s("获取进程输出失败"))}finally{x(!1)}},[]),N=(0,n.useCallback)(async e=>{try{const t=new _.hf(_.HK.ai_bg_process_kill_req);t.context={pid:e};const n=await h.ws.send(t);n?.context?.success?((0,p.SK)(s("进程已终止")),S(),l===e&&(d(null),g(null))):(0,p.zN)(n?.context?.message||"终止失败")}catch(e){console.error("终止进程失败",e),(0,p.zN)(s("终止进程失败"))}},[S,l]);(0,n.useEffect)(()=>{S();const e=setInterval(S,5e3);return()=>clearInterval(e)},[S]);const k=t.filter(e=>e.running),C=t.filter(e=>!e.running);return(0,I.jsxs)(I.Fragment,{children:[j&&(0,I.jsx)("div",{className:"chat-session-overlay",onClick:y}),(0,I.jsxs)("aside",{className:"chat-bg-process-panel "+(j?"expanded":""),children:[(0,I.jsxs)("div",{className:"chat-bg-process-header",children:[(0,I.jsx)("span",{className:"chat-bg-process-title",children:s("后台进程")}),(0,I.jsx)(T.rA,{icon:"close",title:s("关闭"),onClick:y})]}),(0,I.jsxs)("div",{className:"chat-bg-process-toolbar",children:[(0,I.jsx)(T.rA,{icon:"refresh",title:s("刷新"),onClick:S}),(0,I.jsxs)("span",{className:"chat-bg-process-count",children:[k.length," ",s("个运行中"),C.length>0&&` / ${C.length} ${s("个已退出")}`]})]}),(0,I.jsxs)("div",{className:"chat-bg-process-list",children:[c&&0===t.length&&(0,I.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}),!c&&0===t.length&&(0,I.jsx)("div",{className:"chat-bg-process-empty",children:s("暂无后台进程")}),k.map(e=>(0,I.jsxs)("div",{className:`chat-bg-process-item ${l===e.pid?"active":""} running`,children:[(0,I.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>w(e.pid),children:[(0,I.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,I.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>40?e.cmd.slice(0,40)+"...":e.cmd}),(0,I.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,I.jsx)("span",{className:"chat-bg-process-status running-dot",title:s("运行中"),children:"●"})]}),(0,I.jsxs)("div",{className:"chat-bg-process-item-actions",children:[(0,I.jsx)(T.rA,{icon:"terminal",title:s("查看输出"),onClick:()=>w(e.pid)}),(0,I.jsx)(T.rA,{icon:"stop",title:s("终止进程"),onClick:()=>N(e.pid)})]})]},e.pid)),C.map(e=>(0,I.jsx)("div",{className:`chat-bg-process-item ${l===e.pid?"active":""} finished`,children:(0,I.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>w(e.pid),children:[(0,I.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,I.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>30?e.cmd.slice(0,30)+"...":e.cmd}),(0,I.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,I.jsxs)("span",{className:"chat-bg-process-exit-code",children:["exit: ",e.exit_code]})]})},e.pid))]}),null!==l&&(0,I.jsxs)("div",{className:"chat-bg-process-output",children:[(0,I.jsxs)("div",{className:"chat-bg-process-output-header",children:[(0,I.jsxs)("span",{children:["PID: ",l," ",s("输出")]}),(0,I.jsx)(T.rA,{icon:"close",title:s("关闭"),onClick:()=>{d(null),g(null)}})]}),(0,I.jsx)("div",{className:"chat-bg-process-output-content",children:f?(0,I.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}):m?(0,I.jsx)("pre",{className:"chat-bg-process-output-pre",children:m.output||s("(无输出)")}):null})]})]})]})};function me(e={}){const{inline_header:s=!1,session_id:t,file_cwd_path:f,sync_url:x=!0,on_session_change:b}=e,{t:y}=(0,a.Bd)(),[w,T]=(0,o.ok)(),V=x&&w.get("session")||"",{check_user_auth:E}=(0,l.MH)(),[F]=(0,i.fp)(u.AG.user_base_info),H=!!F?.user_data?.is_root,[K,P]=(0,i.fp)(u.AG.ai_session_collapsed),[z,O]=(0,i.fp)(u.AG.ai_bg_expanded),[q,G]=(0,i.fp)(u.AG.prompt_card),[U]=(0,i.fp)(u.AG.ai_chat_zoom),[J,W]=(0,n.useState)(null),[Y,Z]=(0,n.useState)([]),[Q,ee]=(0,n.useState)(new Set),[te,ne]=(0,n.useState)([]),[ie,ae]=(0,n.useState)(""),[ce,re]=(0,n.useState)([]),[le,me]=(0,n.useState)(0),ge=(0,n.useRef)(null),he=(0,n.useRef)(null),_e=(0,n.useRef)(null),pe=(0,n.useRef)({}),fe=(0,n.useRef)({}),xe=(0,n.useRef)(null);(0,n.useEffect)(()=>{xe.current=J},[J]);const je=(0,n.useRef)(null),ve=(0,n.useRef)(()=>{}),be=(0,n.useRef)([]),ye=(0,n.useRef)(""),Se=(0,n.useRef)(!1),we=(0,n.useRef)(null),Ne=(0,n.useRef)(()=>{}),ke=(0,n.useRef)(null),Ce=function(e){const{admin_call:s,owner_of_session:t,get_sessions:i,activeSessionId:o,admin_mode_ref:r}=e,{t:l}=(0,a.Bd)(),u=(0,$.y)(),[m,g]=(0,n.useState)([]),[h,_]=(0,n.useState)(!1),[f,x]=(0,n.useState)(new Set),j=(0,n.useRef)(null),b=(0,n.useRef)(!0),y=(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)},w=()=>{y.current=!0};return(0,n.useLayoutEffect)(()=>{y.current&&(y.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 i=new ResizeObserver(n),a=()=>[...e.children].forEach(e=>i.observe(e));a();const o=new MutationObserver(()=>{a(),n()});return o.observe(e,{childList:!0}),()=>{e.removeEventListener("wheel",s),e.removeEventListener("scroll",t),i.disconnect(),o.disconnect()}},[]),{messages:m,setMessages:g,batchMode:h,setBatchMode:_,selectedMsgIds:f,setSelectedMsgIds:x,chatContainerRef:j,followRef:b,isNearBottom:(e,s=120)=>{const{scrollTop:t,scrollHeight:n,clientHeight:i}=e;return n-(t+i)<s},scrollToBottom:S,request_scroll_bottom:w,apply_session:e=>{if(!e)return g([]),void w();let s=e.messages??[];e.live_messages?.length&&(s=[...s,...e.live_messages]),g(v(s)),w()},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 i=t(o);i?s("message_delete",{session_id:o,user_id:i,indices:[n]}).catch(console.error):c.jV.post("session/message/delete",{session_id:o,indices:[n]}).catch(console.error)}})},handleCopy:async e=>{(0,R.lW)(D(e)),(0,p.SK)(l("复制成功"))},handleCopyAll:async()=>{const e=i();if(!e.length)return void(0,p.SK)(l("暂无聊天记录"));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 i=e.data,a=v([...i.messages??[],...i.live_messages??[]]).map(D).filter(Boolean).join("\n\n\n");a&&t.push(a)}t.length?((0,R.lW)(t.join("\n\n\n")),(0,p.SK)(l("复制成功"))):(0,p.SK)(l("暂无聊天记录"))},handleInteractiveResolved:e=>{g(s=>s.map(s=>s.interactive?.ask_id===e?{...s,interactive:{...s.interactive,resolved:!0}}:s))},handleBatchCopy:()=>{const e=m.filter(e=>f.has(e.id)).map(D).filter(Boolean).join("\n\n\n");e?((0,R.lW)(e),(0,p.SK)(l("复制成功"))):(0,p.SK)(l("暂无内容"))},toggleBatchMode:()=>{h&&x(new Set),_(e=>!e)},toggleMsgSelect:e=>{x(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},batchDeleteMessages:()=>{0!==f.size&&u({sub_title:l("cf_msgs"),confirm_fun:async()=>{const e=[];if(m.forEach((s,t)=>{f.has(s.id)&&e.push(t)}),g(m.filter(e=>!f.has(e.id))),x(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=>Se.current?be.current.find(s=>s.id===e)?.user_id:void 0,get_sessions:()=>be.current,activeSessionId:ye.current,admin_mode_ref:Se});Ne.current=Ce.apply_session;const Ae=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:g,init_session_id:h}=e,{t:_}=(0,a.Bd)(),f=(0,$.y)(),[x,j]=(0,i.fp)(u.AG.ai_last_session_id),[v,b]=(0,n.useState)([]),[y,S]=(0,n.useState)(""),[w,N]=(0,n.useState)(""),[k,C]=(0,n.useState)(!1),[R,D]=(0,n.useState)(!1),[B,T]=(0,n.useState)(!1),V=(0,n.useRef)(!1),E=(0,n.useRef)([]);(0,n.useEffect)(()=>{V.current=k},[k]),(0,n.useEffect)(()=>{E.current=v},[v]);const F=(e,s={})=>c.jV.post("admin/session",{action:e,...s}),H=e=>{if(V.current)return E.current.find(s=>s.id===e)?.user_id},K=async(e,n=!1,i)=>{const a=i??E.current.find(s=>s.id===e)?.user_id,r=V.current&&a?await F("get",{session_id:e,user_id:a}):await c.jV.post("session/get",{session_id:e});if(r.code!==d.m.Success||!r.data)return!1;const u=r.data;return S(u.id),j(u.id),g!==u.id&&l(u.id),o?.(u.id),D(!!u.running),N(u.sys_prompt_id??""),n&&t(!0),s(u),!0},P=async e=>{const t=V.current?await F("list_all_sessions"):await c.jV.get("sessions");if(t.code!==d.m.Success)return!1;const n=t.data??[];b(n);const i=null===e?n[0]?.id??"":e||y||n[0]?.id||"";if(!i)return S(""),l(null),s(null),!1;if(e&&!n.some(s=>s.id===e))return!1;const a=n.find(e=>e.id===i)?.user_id;return await K(i,!1,a)},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,A.ed)(e),i=t.find(e=>(0,A.ed)(e.file_cwd_path)===n);if(i)return i.id;const a=await c.jV.post("session",{file_cwd_path:e});return a.code!==d.m.Success?null:a.data.id};return{sessions:v,setSessions:b,sessions_ref:E,activeSessionId:y,setActiveSessionId:S,selectedSysPromptId:w,setSelectedSysPromptId:N,admin_all_mode:k,admin_mode_ref:V,readonly:B,activeSessionRunning:R,setActiveSessionRunning:D,admin_call:F,call:(e,s,t)=>V.current?F(e,s):t(),owner_of_session:H,refreshSessions:async()=>{const e=V.current?await F("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:K,loadSessions:P,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 i=n.data;S(i.id),N(i.sys_prompt_id??""),t(!0),s(null),await P(i.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 P(e)||await P()}else h?await P(h)||await P():g?await P(g)||await P():x&&await P(x)||await P()},reorderSessions:(e,s)=>{if(V.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 i=(0,M.TI)(E.current,t,n);b(i),c.jV.post("sessions/update/sort",{session_ids:i.map(e=>e.id)}).catch(()=>{})},deleteSession:e=>{f({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{const s=H(e);s?await F("delete",{session_id:e,user_id:s}):await c.jV.post("session/delete",{session_id:e}),y===e?(S(""),await P(null)):await P(y)}})},renameSession:(e,s)=>{let t=s;f({confirm_fun:async()=>{const s=H(e);s?await F("rename",{session_id:e,user_id:s,title:t}):await c.jV.post("sessions/update/meta",{id:e,title:t}),await P(y)},context_div:(0,I.jsx)("div",{className:"card-content",children:(0,I.jsx)(m.Sm,{value:t,handleInputChange:e=>{t=e}})})})},toggleCmdAuto:async(e,s)=>{const t=H(e);t?await F("cmd_auto",{session_id:e,user_id:t,allow:s}):await c.jV.post("session/cmd_auto_allow",{session_id:e,allow:s}),(0,p.SK)(_(s?"命令检测已开启":"命令检测已关闭")),await P(y)},batchDeleteSessions:(e,s)=>{0!==e.size&&f({sub_title:_("cf_ses"),confirm_fun:async()=>{if(V.current)await F("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(y)?(S(""),await P(null)):await P(y)}})},clearAllSessions:()=>{f({sub_title:_("cf_all"),confirm_fun:async()=>{await c.jV.post("sessions/clear",{}),S(""),s(null),await P(null)}})},toggleAllUsersMode:async()=>{const e=!k;C(e),V.current=e,T(e),S(""),s(null);const t=e?await F("list_all_sessions"):await c.jV.get("sessions"),n=t.code===d.m.Success?t.data??[]:[];b(n),n[0]?.id&&await K(n[0].id,!1,n[0].user_id)},changeSystemPrompt:(e,s)=>{const t=s||y;if(!t)return;b(s=>s.map(s=>s.id===t?{...s,sys_prompt_id:e||void 0}:s)),t===y&&N(e);const n=H(t);n?F("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&&(h.ws.sendData(_.HK.ai_chat_subscribe,{session_id:e.id,subscribe:!0}),we.current=e.id),Ne.current(e),e.live_messages?.length)){const s=v([...e.messages??[],...e.live_messages]);ke.current?.bind_live_bubbles(s,e.live_messages.length)}},set_session_panel_open:e=>P(!e),on_session_change:b,init_cwd:f,write_url_session:e=>{x&&T(s=>{const t=new URLSearchParams(s);return e?t.set("session",e):t.delete("session"),t},{replace:!0})},url_session_id:V,init_session_id:t});(0,n.useEffect)(()=>{ye.current=Ae.activeSessionId,Se.current=Ae.admin_all_mode,be.current=Ae.sessions},[Ae.activeSessionId,Ae.admin_all_mode,Ae.sessions]);const Me=B({active_session_id_ref:ye,local_owner_ref:je,subscribed_ref:we,set_messages:Ce.setMessages,scroll_to_bottom:()=>Ce.scrollToBottom(!1),follow_ref:Ce.followRef,mark_session_running:Ae.markSessionRunning,refresh_sessions:Ae.refreshSessions,reload_session:e=>Ae.loadSession(e),set_active_session_running:Ae.setActiveSessionRunning,on_chat_end:e=>{ve.current(),W(s=>s===e?null:s)}});ke.current=Me;const $e=(0,n.useRef)((0,r.n)(e=>{Ce.setMessages(e),Ce.followRef.current&&Ce.scrollToBottom(!1)},50)).current,Ie=function(e){const{getMessages:s,setMessages:t,setMessagesDebounced:i,setSending:a,getActiveSessionId:o,setActiveSessionId:c,refreshSessions:r,scrollToBottom:l,buildRequestMessages:d,getSelectedSysPromptId:u,setLocalOwner:m}=e,[g,p]=(0,n.useState)(!1),f=(0,n.useRef)(null);return{startChatStream:(e,n)=>{const c=s(),g=c.length+1,p={...n,id:g},x=[...c,p];t(x),a(e),m(e),f.current={abort:()=>{}};const j={id:-1,sender:"bot",text:"AI thinking ...",is_loading:!0};x.push(j),t([...x]);const b=new Map,y=()=>{o()===e&&i([...x])},S=()=>{const e=x.indexOf(j);-1!==e&&x.splice(e,1)},w=s=>{const t=s.context||{};if(t.session_id!==e)return;const n=t.text||"",i=t.tool_call_ends,a=t.chunk_index??0;if(t.notice)return j.id=-1,j.text=n,j.is_loading=!0,x.includes(j)||x.push(j),void y();if("[DONE]"===n)return;if(!n&&!i)return;S();let o=b.get(a);if(o||(o={id:g+1+a,sender:"bot",text:"",is_loading:!0},x.push(o),b.set(a,o)),n){o.text=o.text+n;const e=o.content_list?.[0];e&&(e.content=o.text),o.is_loading=!1}i&&(o.content_list=[{tool_call_ends:i,content:o.text,role:"assistant"}],o.is_loading=!1),y()},N=s=>{const n=s.context||{};n.session_id===e&&(A(),f.current=null,m(null),a(s=>s===e?null:s),o()===e&&t(e=>{const s=e.filter(C);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 i=e>=0?e+1:s.length;t=[...s.slice(0,i),...v(n.once_messages_list)]}return t.map((e,s)=>({...e,id:s+1}))}),r(),l(!0))},k=s=>{const n=s.context||{};if(n.session_id!==e)return;A(),f.current=null,a(s=>s===e?null:s);const i="AI request error: "+(n.message||"未知错误");S();const c=(n.once_messages_list??[]).map(e=>"string"==typeof e?.content?e.content:"").filter(Boolean).join("\n\n"),r=c?`${c}\n\n${i}`:i,l=x.findIndex(e=>e.id===g);if(-1!==l){const e=[...x.slice(l+1)].reverse().find(e=>"bot"===e.sender);e?(e.text=e.text?`${e.text}\n\n${i}`:i,e.is_loading=!1):x.push({id:g+1,sender:"bot",text:r})}else x.push({id:g+1,sender:"bot",text:r});o()===e&&t([...x].map((e,s)=>({...e,id:s+1})))},A=()=>{h.ws.off_message(`message_${_.HK.ai_chat_msg}`,w),h.ws.off_message(`message_${_.HK.ai_chat_end}`,N),h.ws.off_message(`message_${_.HK.ai_chat_error}`,k)};h.ws.addMsg(_.HK.ai_chat_msg,w),h.ws.addMsg(_.HK.ai_chat_end,N),h.ws.addMsg(_.HK.ai_chat_error,k),h.ws.sendData(_.HK.ai_chat_req,{messages:d(n),session_id:e,sys_prompt_id:u()})},abort:()=>{const e=o();e&&(h.ws.sendData(_.HK.ai_chat_abort,{session_id:e}),f.current=null,p(!0))},confirmAsk:(e,s)=>{const t=o();t&&(a(t),h.ws.sendData(_.HK.ai_chat_confirm,{session_id:t,ask_id:e,answer:s}))},pausing:g,setPausing:p}}({getMessages:()=>Ce.messages,setMessages:Ce.setMessages,setMessagesDebounced:$e,setSending:W,getActiveSessionId:()=>ye.current,setActiveSessionId:Ae.setActiveSessionId,refreshSessions:Ae.refreshSessions,scrollToBottom:Ce.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:()=>Ae.selectedSysPromptId,setLocalOwner:e=>{je.current=e}});ve.current=()=>Ie.setPausing(!1);const Re=e=>{ae(e?.ai_config?.model??"")},De=async()=>{try{const e=await c.jV.get("public_models");e.code===d.m.Success&&re(e.data?.groups??[])}catch{re([])}},Be=e=>{const s=Array.from(e??[]).filter(Boolean);s.length&&Z(e=>[...e,...s])},Te=e=>Ae.owner_of_session(e),Ve=()=>{Ce.batchMode&&(Ce.setSelectedMsgIds(new Set),ee(new Set)),Ce.setBatchMode(e=>!e)};(0,n.useEffect)(()=>{(async()=>{const e=await c.XO.get("ai_agent_setting/env");e.code===d.m.Success&&(fe.current=e.data,Re(e.data)),await De(),await Ae.init_active_session();const s=await c.jV.get("system_prompts");s.code===d.m.Success&&ne(s.data??[])})(),requestAnimationFrame(()=>Ce.scrollToBottom(!1)),pe.current.onCountChange=me,pe.current.refresh?.();const e=e=>{const s=e?.context?.count;"number"==typeof s&&me(s)};return h.ws.addMsg(_.HK.ai_bg_process_count_notify,e),()=>{h.ws.off_message(`message_${_.HK.ai_bg_process_count_notify}`,e)}},[]);const Ee=J===Ae.activeSessionId||Ae.activeSessionRunning;return(0,I.jsxs)(n.Fragment,{children:[(0,I.jsx)(X,{inline:s,currentModelName:ie,setCurrentModelName:ae,modelGroups:ce,onModelChanged:async()=>{await De();const e=await c.XO.get("ai_agent_setting/env");e.code===d.m.Success&&(fe.current=e.data,Re(e.data))},batchMode:Ce.batchMode,selectedMsgCount:Ce.selectedMsgIds.size,sessionVisible:!K,onToggleSessionPanel:()=>P(e=>!e),onCreateSession:Ae.createSession,onBatchDeleteMessages:Ce.batchDeleteMessages,onToggleBatchMode:Ve,bgProcessVisible:z,bgProcessCount:le,onToggleBgProcess:()=>O(e=>!e)}),(0,I.jsxs)("div",{className:"chat-page"+(s?" chat-page--embedded":" chat-page-with-sessions"),style:{"--ai-chat-zoom":U},children:[!K&&(0,I.jsx)("div",{className:"chat-session-overlay",onClick:()=>P(!0)}),!K&&(0,I.jsx)(se,{sessions:Ae.sessions,activeSessionId:Ae.activeSessionId,onSelectSession:e=>Ae.loadSession(e,!1),onReorderSessions:Ae.reorderSessions,onRenameSession:Ae.renameSession,onDeleteSession:Ae.deleteSession,onToggleCmdAuto:Ae.toggleCmdAuto,onShowUsageStats:async e=>{G({open:!0,title:y("Token消耗统计"),context_div:(0,I.jsx)("div",{className:"usage-stats-loading",children:y("加载中...")}),cancel:()=>G({open:!1})});try{const s=Te(e),t=s?await Ae.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;G({open:!0,title:y("Token消耗统计"),context_div:(0,I.jsxs)("div",{className:"usage-stats-panel",children:[[{l:y("对话轮次"),v:(e.turns??0).toString()},{l:y("AI输入Token"),v:g(e.input_tokens)},{l:y("AI输出Token"),v:g(e.output_tokens)},{l:y("AI输入Token(最近一轮)"),v:g(e.recent_input_tokens)},{l:y("AI输出Token(最近一轮)"),v:g(e.recent_output_tokens)}].map((e,s)=>(0,I.jsxs)("div",{className:"usage-stats-row",children:[(0,I.jsx)("span",{className:"usage-stats-label",children:e.l}),(0,I.jsx)("span",{className:"usage-stats-value",children:e.v})]},s)),(0,I.jsxs)("div",{className:"usage-stats-row usage-stats-total",children:[(0,I.jsx)("span",{className:"usage-stats-label",children:y("AI Token总计消耗")}),(0,I.jsx)("span",{className:"usage-stats-value",children:g((e.input_tokens||0)+(e.output_tokens||0))})]})]}),cancel:()=>G({open:!1})})}else G({open:!0,title:y("Token消耗统计"),context_div:(0,I.jsx)("div",{className:"usage-stats-empty",children:y("暂无统计数据")}),cancel:()=>G({open:!1})})}catch{G({open:!0,title:y("Token消耗统计"),context_div:(0,I.jsx)("div",{className:"usage-stats-empty",children:y("暂无统计数据")}),cancel:()=>G({open:!1})})}},onShowSessionSetting:e=>{let s=Ae.sessions.find(s=>s.id===e)?.file_cwd_path??"";G({open:!0,title:y("会话设置"),context_div:(0,I.jsxs)("div",{className:"session-setting",children:[(0,I.jsx)("div",{className:"session-setting__label",children:y("服务器工作目录")}),(0,I.jsx)(m.Sm,{value:s,placeholder:y("服务器工作目录提示"),handleInputChange:e=>{s=e}})]}),confirm:async()=>{try{const t=Te(e);(t?await Ae.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,p.SK)(y("保存成功"))}catch{}G({open:!1}),await Ae.loadSessions(Ae.activeSessionId)},cancel:()=>G({open:!1})})},batchMode:Ce.batchMode,selectedSessionIds:Q,onToggleSessionSelect:e=>{ee(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onToggleBatchMode:Ve,onBatchDeleteSessions:()=>Ae.batchDeleteSessions(Q,()=>{ee(new Set),Ce.setBatchMode(!1)}),onClearAllSessions:Ae.admin_all_mode?void 0:Ae.clearAllSessions,allUsersMode:Ae.admin_all_mode,onToggleAllUsersMode:Ae.toggleAllUsersMode,showAllUsersEntry:H,sysPromptList:te,onChangeSysPrompt:(e,s)=>Ae.changeSystemPrompt(s,e)}),(0,I.jsx)(ue,{panelRef:pe}),(0,I.jsxs)("section",{className:"chat-main",children:[0===Ce.messages?.length&&(0,I.jsx)("div",{className:"chat-header",children:(0,I.jsx)("div",{children:y("ai_ask")})}),(0,I.jsx)(oe,{messages:Ce.messages,batchMode:Ce.batchMode,selectedMsgIds:Ce.selectedMsgIds,sending:Ee,chatContainerRef:Ce.chatContainerRef,messagesEndRef:_e,onToggleMsgSelect:Ce.toggleMsgSelect,onDelete:Ce.handleDelete,onCopy:Ce.handleCopy,onCopyAll:Ce.handleCopyAll,onToggleBatchMode:Ve,onBatchCopy:Ce.handleBatchCopy,onBatchDelete:Ce.batchDeleteMessages,showBatchBar:Ce.batchMode&&Ce.selectedMsgIds.size>0&&0===Q.size,on_interactive_resolved:Ce.handleInteractiveResolved,on_interactive_submit:(e,s)=>{Ae.admin_all_mode||s&&Ie.confirmAsk(s.ask_id,s.answer)},t:y}),(0,I.jsx)(de,{ref:ge,onSend:async()=>{if(Ae.admin_all_mode)return;const e=(ge.current?.getValue()??"").trim();if(!e&&0===Y.length)return;if(J===Ae.activeSessionId)return;let s=Ae.activeSessionId;if(!s){const t=await c.jV.post("session",{title:(e||Y[0]?.name).slice(0,28),sys_prompt_id:void 0,file_cwd_path:f||void 0});if(t.code!==d.m.Success)return;s=t.data.id,Ae.setActiveSessionId(s),b?.(s),await Ae.loadSessions(s)}const t=await async function(e){const s=[];for(const t of e){const e=S(t);let n="";if("text"===e)try{const e=await N(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 k(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}(Y),n={id:j(),sender:"user",text:e,attachments:t};ge.current?.clear(),Z([]);const i=fe.current?.ai_config?.request_type||"completions";if("completions"!==i){const t={id:Ce.messages.length+2,sender:"bot",text:"处理中...",is_loading:!0},a={...n,id:Ce.messages.length+1},o=[...Ce.messages,a,t];Ce.setMessages(o),W(s);return void(await L(i,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),Ce.setMessages([...o]),W(null),Ae.refreshSessions(),Ce.scrollToBottom(!0)})||(t.text=`请求类型 "${i}" 的专用处理器尚未实现,请使用 completions 类型。`,t.is_loading=!1,Ce.setMessages([...o]),W(null)))}Ie.startChatStream(s,n)},readonly:Ae.admin_all_mode,sending:Ee,pausing:Ie.pausing,onAbort:Ie.abort,pendingAttachments:Y,onRemoveAttachment:e=>{Z(s=>s.filter((s,t)=>t!==e))},onOpenFilePicker:()=>{he.current?.click()},onAddFiles:Be,onDrop:e=>{const s=e.dataTransfer?.files;s&&s.length>0&&(e.preventDefault(),Be(s))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:he})]})]})]})}},84369(e,s,t){t.d(s,{y:()=>o});var n=t(96540),i=t(2543);function a(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 j=(0,n.useCallback)(e=>{const s=_.current;if(!s)return;const{px_to_unit:t,min:n,max:i,get_pos:o}=x.current,c=s.pos-o(e);let r=s.size+t(c);const l=a(n),d=a(i);void 0!==l&&(r=Math.max(l,r)),void 0!==d&&(r=Math.min(d,r)),p.current(r)},[]),v=n.useMemo(()=>void 0===d?j:i.throttle(e=>j(e),d),[d,j]),b=(0,n.useCallback)(()=>{_.current=null,h(!1);const e=v;"function"==typeof e.cancel&&e.cancel(),m?.()},[v,m]),y=(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",v),e.addEventListener("pointerup",b),()=>{e.removeEventListener("pointermove",v),e.removeEventListener("pointerup",b)}},[g,v,b,t]),(0,n.useEffect)(()=>{const e=v;return()=>{"function"==typeof e.cancel&&e.cancel()}},[v]),{dragging:g,on_pointer_down:y,on_pointer_up:b}}}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[9546],{74777(e,t,s){s.d(t,{Gd:()=>o,Hb:()=>i,Mu:()=>c,aM:()=>n,jk:()=>r});let n=function(e){return e[e.close=0]="close",e[e.length=1]="length",e[e.forver=2]="forver",e}({}),i=function(e){return e[e.independent=0]="independent",e[e.reuse=1]="reuse",e[e.single=2]="single",e}({});class o{mode;length;persist;session_mode}let r=function(e){return e.ffmpeg="ffmpeg",e.smartmontools="smartctl",e.ufw="ufw",e}({});let c=function(e){return e[e.auth=0]="auth",e[e.cmd=1]="cmd",e[e.cyc=2]="cyc",e[e.sys_env=3]="sys_env",e[e.private_sys_env=4]="private_sys_env",e[e.auto_upgrade=6]="auto_upgrade",e}({})},75007(e,t,s){s.d(t,{h:()=>o});s(96540);var n=s(85997),i=s(74848);function o(e){return(0,i.jsxs)("h2",{className:"message",children:[(0,i.jsx)(n.In,{icon:"sentiment_dissatisfied"}),(0,i.jsx)("span",{children:e.context})]})}},22081(e,t,s){s.d(t,{A:()=>r});var n=s(96540),i=s(16349),o=s(74848);const r=({percentage:e})=>{const t=(0,n.useRef)(null),[s,r]=(0,n.useState)(null);return(0,n.useEffect)(()=>{const s=t.current.getContext("2d"),n=new i.Ay(s,{type:"doughnut",data:{labels:["use","left"],datasets:[{data:[e,100-e],backgroundColor:["#007bff","#f0f0f0"],borderWidth:0}]},options:{plugins:{legend:{display:!1},tooltip:{enabled:!1}},elements:{arc:{borderWidth:0}}}});return r(n),()=>{n.destroy()}},[]),(0,n.useEffect)(()=>{s&&(s.data.datasets[0].data=[e,100-e],s.update())},[e]),(0,o.jsx)("div",{style:{width:"8rem",overflow:"hidden"},children:(0,o.jsx)("canvas",{ref:t})})}},77481(e,t,s){s.d(t,{S:()=>c,X:()=>r});var n=s(96540),i=s(61443),o=s(74848);function r(e){const[t,s]=n.useState([]),r=(0,n.useRef)(-1),[c,l]=(0,n.useState)(-1),[a,d]=(0,n.useState)(-1);(0,n.useEffect)(()=>{e.children?s(Array.isArray(e.children)?e.children:[e.children]):s(e.rows)},[e.rows,e.children]);const u=()=>{r.current=-1,l(-1),d(-1)};return(0,o.jsxs)("table",{children:[(0,o.jsx)("thead",{children:(0,o.jsx)("tr",{children:e.headers?.map((t,s)=>{const n=!!e.filter&&(e.filter.column??0)===s;let r=t;if(n){const s=e.filter,n=s.options.find(e=>e.value===s.value);null!=s.value&&n&&(r=`${t} (${n.label})`)}return(0,o.jsx)("th",{className:n?"table-filter-col":"",children:n?(0,o.jsx)(i.l6,{value:e.filter.value,options:e.filter.options,onChange:e.filter.onChange,bare:!0,trigger_label:r}):t},s)})})}),(0,o.jsx)("tbody",{children:t.map((t,s)=>{const n=!!e.onRowDrag;return(0,o.jsx)("tr",{className:n?(c===s?"row-dragging":"")+(a===s?" row-drop-target":""):"",draggable:n,onContextMenu:()=>{e.handleContextMenu&&e.handleContextMenu(t)},onDragStart:e=>{n&&(r.current=s,l(s),e.dataTransfer.effectAllowed="move")},onDragOver:e=>{!n||r.current<0||(e.preventDefault(),e.dataTransfer.dropEffect="move",d(s))},onDrop:t=>{n&&(t.preventDefault(),(()=>{const t=r.current,s=a;u(),t<0||s<0||t===s||e.onRowDrag?.(t,s)})())},onDragEnd:u,children:t.map((s,n)=>{const i=n===t.length-1?"small":"";return(0,o.jsx)("td",{className:i,style:{width:e.width??"auto"},children:s},n)})},s)})})]})}function c(e){return(0,o.jsx)("div",{style:{display:e.isFlex?"flex":"block"},children:e.columns.map((e,t)=>(0,o.jsx)("div",{children:e},t))})}},88062(e,t,s){s.d(t,{A:()=>r});s(96540),s(32768);var n=s(74848);function i(e){return(0,n.jsx)("div",{className:"black-tip",onClick:()=>{e.click&&e.click(e)},onContextMenu:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation(),e.onContextMenu&&e.onContextMenu(t,e)},children:e.name})}const o=e=>(0,n.jsxs)("li",{children:[e.click?(0,n.jsx)(i,{...e.node,name:e.render?e.render(e.node):e.node.name,click:e.click,onContextMenu:e.onContextMenu}):(0,n.jsx)("div",{children:e.render?e.render(e.node):e.node.name}),e.node.children&&e.node.children.length>0&&(0,n.jsx)("ul",{children:e.node.children.map((t,s)=>(0,n.jsx)(o,{node:t,click:e.click,onContextMenu:e.onContextMenu,render:e.render},s))})]}),r=e=>(0,n.jsx)("div",{className:"card-tree-view",children:(0,n.jsx)("ul",{children:e.list&&e.list.map((t,s)=>(0,n.jsx)(o,{node:t,click:e.click,onContextMenu:e.onContextMenu,render:e.render},s))})})},59546(e,t,s){s.r(t),s.d(t,{default:()=>le});var n=s(96540),i=s(75725),o=s(7572),r=s(22081),c=s(92275),l=s(14944),a=s(14284),d=s(4412),u=s(85997),h=s(77481),x=s(53459),p=s(22022),m=s(34843),f=s(82893),j=s(74777),g=s(62042),_=s(61443),y=s(74848);function w(e){const{t}=(0,p.Bd)(),[s,r]=(0,m.fp)(f.AG.disk),[c,l]=(0,n.useState)({}),[j,g]=(0,n.useState)([]),_=[t("名字"),t("当前值"),t("历史最低"),t("临界值")];return(0,n.useEffect)(()=>{(async()=>{const s=await a.Yu.post("sys/disk/info",{name:e.name});if(s.code===x.m.Success){const e=[];for(const n of s.data.ata_smart_attributes??[]){let s;n[1]>=n[2]?s="var(--icon-green)":n[1]<=n[3]&&(s="var(--icon-red)"),n[0]=(0,y.jsx)("span",{style:{color:s},children:t(n[0])}),e.push(n)}g(s.data.ata_smart_attributes),l(s.data)}})()},[]),(0,y.jsxs)("div",{children:[(0,y.jsx)(d.aZ,{position:"right",children:(0,y.jsx)(u.rA,{icon:"close",title:t("关闭"),onClick:()=>{r({})}})}),(0,y.jsx)(i.jW,{isFull:!0,more:!0,children:(0,y.jsx)(i.NN,{children:(0,y.jsxs)(i.fI,{children:[(0,y.jsxs)(i.VP,{widthPer:30,children:[(0,y.jsx)(i.xh,{children:(0,y.jsxs)(o.Zp,{title:t("基本信息"),children:[(0,y.jsx)(i.Yh,{left:t("名字"),right:e.name}),(0,y.jsx)(i.Yh,{left:t("厂商名称"),right:e.typeName}),(0,y.jsx)(i.Yh,{left:t("类型"),right:e.type}),(0,y.jsx)(i.Yh,{left:t("容量"),right:e.total})]})}),(0,y.jsx)(i.xh,{children:(0,y.jsxs)(o.Zp,{title:t("物理信息"),children:[(0,y.jsx)(i.Yh,{left:t("是否健康"),right:!0===c.smart_status?"是":"否"}),(0,y.jsx)(i.Yh,{left:t("设备型号"),right:c.model_name}),(0,y.jsx)(i.Yh,{left:t("序列号"),right:c.serial_number}),(0,y.jsx)(i.Yh,{left:t("固件版本"),right:c.firmware_version}),(0,y.jsx)(i.Yh,{left:t("转速(每分钟)"),right:c.rotation_rate}),(0,y.jsx)(i.Yh,{left:t("通电时长(小时)"),right:c.power_on_time_hours}),(0,y.jsx)(i.Yh,{left:t("通电次数"),right:c.power_cycle_count}),(0,y.jsx)(i.Yh,{left:t("温度(°C)"),right:c.temperature}),(0,y.jsx)(i.Yh,{left:t("通信协议"),right:c.device_protocol})]})})]}),(0,y.jsx)(i.VP,{widthPer:50,children:(0,y.jsxs)(i.xh,{children:[j?.length?(0,y.jsx)(o.uF,{title:t("ATA/SATA详细信息"),children:(0,y.jsx)(h.X,{headers:_,rows:j,width:"10rem"})}):(0,y.jsx)(y.Fragment,{}),c.nvme_smart?(0,y.jsxs)(o.Zp,{title:t("NVME详细信息"),children:[(0,y.jsx)(i.Yh,{left:t("NVMe 可用备用块(%)"),right:c.nvme_smart.available_spare}),(0,y.jsx)(i.Yh,{left:t("NVMe 已使用寿命(%)"),right:c.nvme_smart.percentage_used}),(0,y.jsx)(i.Yh,{left:t("NVMe 读取量"),right:c.nvme_smart.data_units_read}),(0,y.jsx)(i.Yh,{left:t("NVMe 写入量"),right:c.nvme_smart.data_units_written}),(0,y.jsx)(i.Yh,{left:t("NVMe 通电次数"),right:c.nvme_smart.power_cycles}),(0,y.jsx)(i.Yh,{left:t("NVMe 通电时长(小时)"),right:c.nvme_smart.power_on_hours}),(0,y.jsx)(i.Yh,{left:t("NVMe 非正常关机"),right:c.nvme_smart.unsafe_shutdowns}),(0,y.jsx)(i.Yh,{left:t("NVMe 媒体错误"),right:c.nvme_smart.media_errors}),(0,y.jsx)(i.Yh,{left:t("NVMe 错误日志数"),right:c.nvme_smart.num_err_log_entries})]}):(0,y.jsx)(y.Fragment,{})]})})]})})})]})}let v=function(e){return e[e.mount=0]="mount",e}({});var k=s(88062),S=s(78247),b=s(23430),C=s(99214);const A=e=>(0,y.jsxs)("div",{style:{border:"2px solid black",padding:"10px",width:"300px",height:"300px",position:"relative"},children:[e.name,e.lvms.map((e,t)=>(0,y.jsx)("div",{style:{margin:"5px",height:"40px",display:"flex",alignItems:"center",justifyContent:"center",border:"1px solid "},children:e.name},t))]});function V(){return(0,y.jsx)("div",{style:{position:"relative",height:"300px",margin:"10px",width:"30px",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,y.jsx)("div",{style:{width:0,height:0,borderTop:"10px solid transparent",borderBottom:"10px solid transparent",borderLeft:"10px solid black"}})})}function P(){const{t:e}=(0,p.Bd)(),[t,s]=(0,m.fp)(f.AG.disk),[r,c]=(0,n.useState)({}),[l,j]=(0,n.useState)([]),[_,w]=(0,n.useState)([]),[P,$]=(0,m.fp)(f.AG.showPrompt),{check_user_auth:Y}=(0,S.MH)(),[F,I]=(0,n.useState)([]),{click_file:N}=(0,C.kZ)(),[E,M]=(0,m.fp)(f.AG.prompt_card),K=[e("挂载点"),"uuid",e("类型"),e("文件系统类型"),e("文件系统容量"),e("卷容量"),e("设备路径"),e("分区表类型")],B=async()=>{const e=await a.Yu.get("disk/blk");return e.code===x.m.Success&&j(e.data),e.code};(0,n.useEffect)(()=>{(async()=>{B()})()},[]);const H=[(0,y.jsx)(u.rA,{icon:"info",title:e("提示"),onClick:async()=>{M({open:!0,title:"信息",context_div:(0,y.jsx)("div",{children:(0,y.jsxs)("ul",{children:[(0,y.jsxs)("li",{children:["通用格式:","<文件系统> <挂载点> <类型> <挂载选项> <dump> <fsck> "]}),(0,y.jsxs)("li",{children:["文件系统,有多种格式",(0,y.jsxs)("ul",{children:[(0,y.jsx)("li",{children:"1(usb口默认名称)./dev/sda1"}),(0,y.jsx)("li",{children:"2(唯一Id).UUID=123e4567-e89b-12d3-a456-426614174000"}),(0,y.jsx)("li",{children:"3.LABEL=DATA"})]})]}),(0,y.jsx)("li",{children:"挂载点,就是文件路径,例如 /mnt/data ,这个目录要提前创建,且为空"}),(0,y.jsx)("li",{children:"类型,就是文件系统类型,对于系统不支持的类型,例如ntfs需要额外前提安装ntfs-3g(linux 5.15内核以后自带 ntfs)"}),(0,y.jsxs)("li",{children:['挂载选项的值只能是以下这些,可以用 "," 同时使用多个选项',(0,y.jsxs)("ul",{children:[(0,y.jsx)("li",{children:"defaults:使用默认挂载选项"}),(0,y.jsx)("li",{children:"noatime:不更新访问时间,提高性能"}),(0,y.jsx)("li",{children:"auto:系统启动时自动挂载"}),(0,y.jsx)("li",{children:"rw:以读写方式挂载"}),(0,y.jsx)("li",{children:"nofail:防止启动阻塞,挂载失败系统继续执行"}),(0,y.jsx)("li",{children:"...等"})]})]}),(0,y.jsx)("li",{children:"dump 0是需要备份 1是不需要备份"}),(0,y.jsx)("li",{children:"Fsck 整数值0是不检查,文件系统检查顺序越小越先检查"}),(0,y.jsx)("li",{children:"提示:只有含有文件系统的逻辑卷,或者分区才可以进行挂载。"})]})})})}}),(0,y.jsx)(u.rA,{icon:"update",title:e("更新挂载"),onClick:async()=>{(await a.Yu.post("cmd/exe",{type:v.mount})).code===x.m.Success&&(0,g.SK)(e("挂载文件已生效"))}},1)],Z=async()=>(await a.Yu.get("get_fstab")).data,G=async e=>{await a.Yu.post("save_fstab",{content:e})};return(0,y.jsxs)("div",{children:[(0,y.jsx)(d.aZ,{position:"right",children:(0,y.jsx)(u.rA,{icon:"close",title:e("关闭"),onClick:()=>{s({})}})}),(0,y.jsx)(i.jW,{isFull:!0,more:!0,children:(0,y.jsx)(i.NN,{children:(0,y.jsxs)(i.fI,{children:[(0,y.jsx)(i.VP,{widthPer:40,children:(0,y.jsxs)(o.Zp,{title:e("物理块(硬盘)设备、逻辑卷、物理卷"),rightTopCom:(0,y.jsxs)("div",{children:[Y(b.oV.sys_disk_mount)&&(0,y.jsx)(u.rA,{icon:"file_open",title:e("打开挂载文件"),onClick:async()=>{N({name:"fstab(谨慎修改,内容错误会导致系统无法启动)",model:"text",get_file_fun:Z,save_file_fun:G,menu_list:H})}}),(0,y.jsx)(u.rA,{icon:"update",title:e("刷新"),onClick:async()=>{await B()===x.m.Success&&(0,g.SK)(e("刷新成功"))}})]}),children:[(0,y.jsx)(h.X,{headers:K,rows:_,width:"10rem"}),(0,y.jsx)(k.A,{list:l,render:e=>{let t=e.name;return e.label&&(t+=`(${e.label})`),e.mountpoint?(0,y.jsxs)("span",{children:[t,(0,y.jsx)("span",{style:{color:"green"},children:"(已挂载)"})]}):t},onContextMenu:(e,t)=>{e.preventDefault()},click:t=>{let s="";if(t.mountpoint)for(let e=0;e<t.mountpoints.length;e++)s+=t.mountpoints[e]+";";w([[(0,y.jsx)(o.xP,{children:s}),(0,y.jsx)(o.xP,{children:t.uuid}),e(t.type),e(t.fstype),t.fssize,t.size,(0,y.jsx)(o.xP,{children:t.path}),t.pttype]])}})]})}),(0,y.jsx)(i.VP,{widthPer:60,children:F.map((t,s)=>{const n=[];for(const e of t.pv_list)n.push({name:`${e.name}---(${e.size})---(${e.free_size})`});const r=[];for(const e of t.lv_list)r.push({name:`${e.name}---(${e.size})`});return(0,y.jsx)(o.Zp,{children:(0,y.jsxs)(i.n5,{children:[(0,y.jsx)(A,{name:e("物理卷"),lvms:n}),(0,y.jsx)(V,{}),(0,y.jsx)(A,{name:`${e("逻辑卷")}---(${t.name})---size(${t.size})`,lvms:[]}),(0,y.jsx)(V,{}),(0,y.jsx)(A,{name:e("逻辑卷"),lvms:r})]})},s)})})]})})})]})}var $=s(88815);let Y=!0;function F(e){const{t}=(0,p.Bd)(),s=[t("名字"),t("厂商名称"),t("类型"),t("容量")],_=[t("名字"),t("物理硬盘"),t("文件系统类型"),t("挂载位置"),t("总容量"),t("剩余容量")],[v,k]=(0,m.fp)(f.AG.user_base_info),[S,C]=(0,n.useState)(0),[A,V]=(0,n.useState)(0),[F,I]=(0,n.useState)(0),[N,E]=(0,n.useState)(0),[M,K]=(0,n.useState)(0),[B,H]=(0,n.useState)({}),[Z,G]=(0,n.useState)(!1),[D,z]=(0,n.useState)(!1),[T,W]=(0,n.useState)(!1),[X,q]=(0,n.useState)(Y),[U,L]=(0,n.useState)(null),[R,O]=(0,n.useState)([]),[J,Q]=(0,n.useState)([]),[ee,te]=(0,m.fp)(f.AG.user_base_info),[se,ne]=(0,m.fp)(f.AG.disk),ie=async()=>{Y&&(await l.ws.addMsg(c.HK.sys_getting,e=>{E(e.context?.cpu_currentLoad);const t=e.context?.memLeft,s=e.context?.memTotal;V(t),I(s),C((s-t)/s*100),L(e.context?.node_memory_usage),K(e.context?.node_cpu_usage)}),await l.ws.send(new c.hf(c.HK.sys_get)))};return(0,n.useEffect)(()=>((async()=>{await ie()})(),()=>{l.ws.sendData(c.HK.sys_cancel,{})}),[]),(0,y.jsxs)("div",{children:[(0,y.jsxs)(d.aZ,{position:"right",children:[v.sys===b.XM.linux&&(0,y.jsx)(u.rA,{icon:"sd_card",title:"硬盘挂载",onClick:()=>{ne({type:"mount"})}}),(0,y.jsx)(u.Z$,{defaultStatus:!1,text:t("基本信息"),clickFun:e=>{G(e),e&&(async()=>{const e=await a.Yu.get("base");if(e.code===x.m.Success){const t=e.data;H(t)}})()}}),(0,y.jsx)(u.Z$,{defaultStatus:!1,text:t("物理硬盘"),clickFun:e=>{z(e),e&&(async()=>{const e=await a.Yu.get("disk");if(e.code===x.m.Success){const s=e.data,n=[];let i=!0;ee.sysSoftWare&&ee.sysSoftWare[j.jk.smartmontools]&&ee.sysSoftWare[j.jk.smartmontools].installed||(i=!1);for(const e of s??[])n.push([(0,y.jsx)(o.xP,{context:e.name}),e.typeName,e.type,e.total,(0,y.jsx)(u.rA,{icon:"health_and_safety",title:t("查看健康信息"),onClick:()=>{i?ne({type:"check",data:e}):(0,g.zN)(t("没有安装smartmontools"))}})]);O(n)}})()}}),(0,y.jsx)(u.Z$,{defaultStatus:!1,text:t("文件硬盘"),clickFun:e=>{W(e),e&&(async()=>{const e=await a.Yu.get("filedisk");if(e.code===x.m.Success){const t=e.data,s=[];for(const e of t??[])s.push([(0,y.jsx)(o.xP,{context:e.name}),(0,y.jsx)(o.xP,{context:e.device_name}),e.fsType,(0,y.jsx)(o.xP,{context:e.mount}),e.total,e.available]);Q(s)}})()}}),(0,y.jsx)(u.Z$,{defaultStatus:X,text:t("实时信息"),clickFun:e=>{q(e),Y=e,ie()}})]}),(0,y.jsxs)(i.xh,{children:[X&&(0,y.jsxs)(i.fI,{children:[(0,y.jsx)(i.VP,{widthPer:33,maxWidth:"30rem",children:(0,y.jsx)(o.Zp,{title:"Sys "+t("内存"),children:(0,y.jsxs)(i.fI,{children:[(0,y.jsx)(i.VP,{children:(0,y.jsx)(r.A,{percentage:S})}),(0,y.jsx)(i.VP,{children:(0,y.jsxs)(i.fI,{children:[(0,y.jsx)(i.VP,{widthPer:100,children:(0,y.jsx)("div",{children:(0,y.jsx)(i.Yh,{left:t("总容量"),center:`${F}G`})})}),(0,y.jsx)(i.VP,{widthPer:100,children:(0,y.jsx)(i.Yh,{left:t("剩余"),center:`${A}G`})})]})})]})})}),(0,y.jsx)(i.VP,{widthPer:33,maxWidth:"30rem",children:(0,y.jsx)(o.Zp,{title:"Sys cpu",children:(0,y.jsxs)(i.fI,{children:[(0,y.jsx)(i.VP,{children:(0,y.jsx)(r.A,{percentage:N})}),(0,y.jsx)(i.VP,{children:(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.Yh,{left:t("使用率"),center:N})})})]})})}),(0,y.jsx)(i.VP,{widthPer:33,maxWidth:"30rem",children:(0,y.jsx)(o.Zp,{title:"FileCat",children:(0,y.jsxs)(i.fI,{children:[(0,y.jsxs)(i.VP,{children:[(0,y.jsx)(i.qV,{content:t("内存")}),(0,y.jsx)(i.qV,{content:"total: "+(0,$.v7)(U?.rss)}),(0,y.jsx)(i.qV,{content:"object: "+(0,$.v7)(U?.heapTotal)}),(0,y.jsx)(i.qV,{content:"obj-use: "+(0,$.v7)(U?.heapUsed)}),(0,y.jsx)(i.qV,{content:"external: "+(0,$.v7)(U?.external)}),(0,y.jsx)(i.qV,{content:"buffer: "+(0,$.v7)(U?.arrayBuffers)})]}),(0,y.jsx)(i.VP,{children:(0,y.jsx)(i.qV,{content:"cpu growth rate: "+M})})]})})})]}),(0,y.jsxs)(i.fI,{children:[Z&&(0,y.jsx)(i.VP,{children:(0,y.jsxs)(o.Zp,{title:t("基本信息"),children:[(0,y.jsx)(i.Yh,{left:t("总内存"),right:B.mem_total}),(0,y.jsx)(i.Yh,{left:`cpu ${t("制造商")}`,right:B.cpu_manufacturer}),(0,y.jsx)(i.Yh,{left:`cpu ${t("品牌")}`,right:B.cpu_brand}),(0,y.jsx)(i.Yh,{left:`cpu ${t("逻辑核心")}`,right:B.cpu_core_num}),(0,y.jsx)(i.Yh,{left:`cpu ${t("物理核心")}`,right:B.cpu_phy_core_num}),(0,y.jsx)(i.Yh,{left:`cpu ${t("最大")}hz`,right:B.cpu_speed_hz}),(0,y.jsx)(i.Yh,{left:`${t("当前系统")}:pid;ppid`,right:B.pid_ppid}),(0,y.jsx)(i.Yh,{left:t("运行用户"),right:B.user})]})}),D&&(0,y.jsx)(i.VP,{children:(0,y.jsx)(o.uF,{title:t("物理硬盘"),children:(0,y.jsx)(h.X,{headers:s,rows:R,width:"10rem"})})}),T&&(0,y.jsx)(i.VP,{children:(0,y.jsx)(o.uF,{title:t("文件硬盘"),children:(0,y.jsx)(h.X,{headers:_,rows:J,width:"10rem"})})})]})]}),se&&"check"===se.type&&(0,y.jsx)(w,{...se.data}),se&&"mount"===se.type&&(0,y.jsx)(P,{})]})}var I=s(75007),N=s(97856),E=s(64405);const M=n.lazy(()=>Promise.all([s.e(2543),s.e(5614)]).then(s.bind(s,85614)));function K(e){const[t,s]=(0,n.useState)(null),[i,o]=(0,m.fp)(f.AG.dockerShellShow),[r,a]=(0,m.fp)(f.AG.user_base_info),d=r.user_data.theme?.includes("dark")?"#FFFFFF":"#000000",u=()=>{(async()=>{t&&(t.writeln("close! "),t.dispose(),s(null))})()};(0,n.useEffect)(()=>{i.show?(async()=>{const e=new N.Terminal({fontFamily:"Monaco, Menlo, Consolas, 'Courier New', monospace",theme:{background:"#FFFFFF",foreground:d,cursor:d,selectionBackground:"#a6d2ff"},cursorBlink:!0,cursorStyle:"bar",scrollback:1e3,scrollSensitivity:1,tabStopWidth:4,convertEol:!0});let t;l.ws.subscribeUnconnect(u);const n=t=>{e.write(t)};t=s=>{e.clear(),e.write(s),t=n},l.ws.addMsg("logs"===i.type?c.HK.docker_shell_logs_getting:c.HK.docker_shell_exec_getting,e=>{"error"===e.context&&u(),t(e.context)}),"exec"===i.type&&e.onData(async e=>{const t=new c.hf(c.HK.docker_shell_exec);t.context=e,await l.ws.send(t)}),s(e)})():u()},[i]),(0,n.useEffect)(()=>()=>{u()},[]);return(0,y.jsx)(M,{show:i.show,terminal:t,init:(e,s)=>{t.writeln("connect... ");const n=new E.n;let o;n.rows=e,n.cols=s,n.dockerId=i.dockerId,o="logs"===i.type?new c.hf(c.HK.docker_shell_logs):new c.hf(c.HK.docker_shell_exec_open),o.context=n,l.ws.send(o)}})}var B=s(78150),H=s(52671),Z=s(87361);let G="",D=[],z=!1;function T(e){const{t}=(0,p.Bd)(),s=(0,H.Zp)(),[r]=(0,m.fp)(f.AG.user_base_info),[j,w]=(0,n.useState)({}),[v,k]=(0,n.useState)([]),[C,A]=(0,n.useState)([]),{check_user_auth:V}=(0,S.MH)(),[P,$]=(0,m.fp)(f.AG.dockerShellShow),[Y,F]=(0,m.fp)(f.AG.showPrompt),[N,E]=(0,m.fp)(f.AG.confirm),[M,T]=(0,n.useState)(G),[W,X]=(0,n.useState)(["id",t("名字"),t("镜像"),t("命令"),t("状态"),t("内存"),"cpu%",t("选择")]),[q,U]=(0,n.useState)([]),[L,R]=(0,n.useState)(void 0),[O,J]=(0,n.useState)(!1),Q=["id",t("name"),t("create时间"),t("大小"),(0,y.jsxs)("span",{children:["选中",(0,y.jsx)(u.rA,{icon:"check_box",title:"全选",onClick:()=>{z=!z;const e={};for(let t=0;t<C.length&&z;t++)e[C[t][0].props.context]=1;w(e)}})]})],ee=(0,n.useRef)(()=>{}),te=async()=>{k([]),U([]),l.ws.off_message(`message_${c.HK.docker_getting}`,ee.current);const e=e=>{k((e=>{const t=[];if(G){for(const s of e)for(const e of s)if(`${e}`.includes(G)){t.push(s);break}}else t.push(...e);return t.map(e=>{const t=e.map(e=>(0,y.jsx)(o.xP,{context:e}));return t.push((0,y.jsx)(u.rA,{icon:"place",title:"选中",onClick:()=>{U(t)}})),t})})(e.context??[]))};ee.current=e,l.ws.addMsg(c.HK.docker_getting,e);const t=new c.hf(c.HK.docker_get);await l.ws.send(t)};(0,n.useEffect)(()=>(T(G),te(),()=>{(async()=>{l.ws.off_message(`message_${c.HK.docker_getting}`,ee.current),$({show:!1,type:"",dockerId:""})})()}),[]),(0,n.useEffect)(()=>{G=M},[M]);const se=()=>{const e=new c.hf("logs"===P.type?c.HK.docker_shell_logs_cancel:c.HK.docker_shell_exec_cancel);e.context="",l.ws.send(e)},ne=e=>{const t=new c.hf(c.HK.docker_switch);t.context={type:e,dockerId:q[0].props.context},U([]),l.ws.send(t)},ie=async()=>{const e=await a.Yu.get("docker/images");if(e.code===x.m.Success){const t=e.data??[],s=[];for(let e=0;e<t.length;e++){const n=t[e],i=[(0,y.jsx)(o.xP,{context:n[0]}),(0,y.jsx)(o.xP,{context:n[1]}),n[2],n[3],""];s.push(i)}D=s,A(s)}};return(0,y.jsxs)("div",{children:[(0,y.jsx)(d.aZ,{children:(0,y.jsx)(u.Z$,{defaultStatus:!1,text:t("doc_img"),clickFun:e=>{J(e),e?(ie(),U([])):(te(),A([]),w({}))}})}),(0,y.jsxs)(d.aZ,{position:"right",children:[r.sys===b.XM.linux&&(0,y.jsx)(u.rA,{icon:"settings",title:t("doc_cfg"),onClick:()=>s(Z.o.docker_setting_page)}),Object.keys(j).length>0&&(0,y.jsx)(u.rA,{icon:"delete",title:t("删除镜像"),onClick:async()=>{E({open:!0,title:t("doc_icf"),handle:async()=>{const e=Object.keys(j),s=await a.Yu.post("docker/check/delete",{ids:e});if(s.code===x.m.Success)if(0===s.data.length){(await a.Yu.post("docker/delete",{ids:e})).code===x.m.Success&&((0,g.SK)(t("删除完成")),ie(),E({open:!1,handle:null}))}else(0,g.N9)(`有镜像正在运行${JSON.stringify(s.data)}`)}})}}),q.length>0&&(0,y.jsx)("div",{children:q[1].props.context}),q.length>0&&(0,y.jsxs)("div",{children:[V(b.oV.docker_container_update)&&(0,y.jsx)(u.rA,{icon:"delete",title:t("删除容器"),onClick:()=>{F({show:!0,overlay:!0,type:B.PromptEnum.DockerDel,data:{dockerId:q[0].props.context,name:q[1].props.context}})}}),(0,y.jsx)(u.rA,{icon:"print",title:t("打印日志"),onClick:()=>{P.show?($({show:!1,type:"",dockerId:""}),se()):$({show:!0,dockerId:q[0].props.context,type:"logs"})}}),V(b.oV.docker_container_update)&&(0,y.jsx)(u.rA,{icon:"personal_video",title:t("执行命令"),onClick:()=>{P.show?($({show:!1,type:"",dockerId:""}),se()):$({show:!0,dockerId:q[0].props.context,type:"exec"})}}),V(b.oV.docker_container_update)&&q[4].props.context.includes("Up")&&(0,y.jsx)(u.rA,{icon:"stop",title:t("停止"),onClick:()=>ne("stop")}),V(b.oV.docker_container_update)&&!q[4].props.context.includes("Up")&&(0,y.jsx)(u.rA,{icon:"play_arrow",title:t("开启"),onClick:()=>{ne("start")}})]}),(0!==v.length||M)&&!O&&(0,y.jsx)(u.rA,{icon:"refresh",title:t("列表更新"),onClick:async()=>{const e=new c.hf(c.HK.docker_get);await l.ws.send(e)}})]}),(0,y.jsxs)(i.xh,{children:[O&&(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:80,children:(0,y.jsx)(o.uF,{title:`${t("镜像")} (${C.length})`,rightTopCom:(0,y.jsx)(_.Sm,{placeholder:t("过滤镜像"),value:L,handleInputChange:e=>{R(e)},handlerEnter:()=>{const e=[];if(L){for(const t of C)(t[0].props.context.includes(L)||t[1].props.context.includes(L))&&e.push(t);A(e)}else A(D)}}),children:(0,y.jsx)(h.X,{headers:Q,rows:C.map((e,s)=>(e[4]=(0,y.jsx)(_.GL,{context:t(""),selected:j[e[0].props.context],onchange:()=>{(e=>{const t={};Object.assign(t,j),t[e]?delete t[e]:t[e]=1,w(t)})(e[0].props.context)}}),e)),width:"10rem"})})})}),0===v.length&&!M&&!O&&(0,y.jsx)(I.h,{context:t("dc_nne")}),(0!==v.length||M)&&!O&&(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:80,children:(0,y.jsx)(o.uF,{title:`${t("容器")} (${v.length})`,rightTopCom:(0,y.jsx)(_.Sm,{placeholder:t("过滤"),value:M,handleInputChange:e=>{T(e)}}),children:(0,y.jsx)(h.X,{headers:W,rows:v,width:"10rem"})})})})]}),(0,y.jsx)(K,{})]})}var W=s(64694);let X="",q=!1,U=!1;function L(e){const{t}=(0,p.Bd)(),[s,r]=(0,n.useState)([]),[a,x]=(0,n.useState)([]),[m,f]=(0,n.useState)(0),[j,g]=(0,n.useState)(""),[w,v]=(0,n.useState)(["pid",t("名字"),t("创建用户"),(0,y.jsxs)("span",{children:[t("内存"),(0,y.jsx)(u.rA,{icon:"sort",title:t("升序"),onClick:()=>{q=!q}})]}),(0,y.jsxs)("span",{children:["cpu%",(0,y.jsx)(u.rA,{icon:"sort",title:t("升序"),onClick:()=>{U=!U}})]}),t("选择")]),{check_user_auth:k}=(0,S.MH)();(0,n.useEffect)(()=>{g(X),(async()=>{r([]),f(0),x([]);const e=new c.hf(c.HK.process_get);await l.ws.send(e),l.ws.addMsg(c.HK.process_getting,e=>{const s=[];if(X){for(const t of e.context)for(const e of t)if(`${e}`.includes(X)){s.push(t);break}}else s.push(...e.context);q&&(0,W.di)(s,e=>e[3],!1),U&&(0,W.di)(s,e=>e[4],!1);const n=s.map(e=>{const s=e.map((e,t)=>(0,y.jsx)(o.xP,{context:3===t?(0,$.v7)(e):e}));return s.push((0,y.jsx)(u.rA,{icon:"place",title:t("选中"),onClick:()=>{x(s)}})),s});f(s.length),r(n)})})()},[]),(0,n.useEffect)(()=>{X=j},[j]);return(0,y.jsxs)("div",{children:[(0,y.jsxs)(d.aZ,{position:"right",children:[a.length>0&&(0,y.jsx)("div",{children:a[1].props.context}),a.length>0&&k(b.oV.sys_process_close)&&(0,y.jsx)("div",{children:(0,y.jsx)(u.rA,{icon:"stop",title:t("停止"),onClick:()=>{const e=new c.hf(c.HK.process_close);e.context={pid:a[0].props.context},x([]),l.ws.send(e)}})})]}),(0,y.jsx)(i.xh,{children:0!==s.length||X?(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:80,children:(0,y.jsx)(o.uF,{title:`${t("进程")} (${m})`,rightTopCom:(0,y.jsx)(_.Sm,{placeholder:t("过滤"),value:j,handleInputChange:e=>{g(e)}}),children:(0,y.jsx)(h.X,{headers:w,rows:s,width:"10rem"})})})}):(0,y.jsx)(I.h,{context:t("ld_wait")})})]})}const R=n.lazy(()=>Promise.all([s.e(2543),s.e(5614)]).then(s.bind(s,85614)));function O(e){const[t,s]=(0,n.useState)(null),[i,o]=(0,m.fp)(f.AG.systemd_shell_show),[r,a]=(0,m.fp)(f.AG.user_base_info),d=r.user_data.theme?.includes("dark")?"#FFFFFF":"#000000",u=()=>{(async()=>{t&&(t.writeln("close! "),t.dispose(),s(null))})()};(0,n.useEffect)(()=>{if(!i.show)return void u();(async()=>{const e=new N.Terminal({fontFamily:"Monaco, Menlo, Consolas, 'Courier New', monospace",theme:{background:"#FFFFFF",foreground:d,cursor:d,selectionBackground:"#a6d2ff"},cursorBlink:!0,cursorStyle:"bar",scrollback:1e3,scrollSensitivity:1,tabStopWidth:4,convertEol:!0});l.ws.subscribeUnconnect(u),l.ws.addMsg(c.HK.systemd_logs_getting,t=>{"error"===t.context&&u(),e.write(t.context)}),s(e)})();const e=e=>{};return document.addEventListener("cancel_systemd_logs",e),()=>{document.removeEventListener("cancel_systemd_logs",e)}},[i]),(0,n.useEffect)(()=>()=>{u()},[]);return(0,y.jsx)(R,{show:i.show,terminal:t,init:(e,s)=>{t.writeln("connect... ");const n={unit_name:i.unit_name},o=new c.hf(c.HK.systemd_logs_get);o.context=n,l.ws.send(o)}})}const J=[{title:"no(不自动重启)",value:"no"},{title:"always(总是重启)",value:"always"},{title:"on-failure(失败才重启)",value:"on-failure"},{title:"on-abnormal(异常才重启)",value:"on-abnormal"}],Q=[{title:"simple",value:"simple"},{title:"forking",value:"forking"},{title:"oneshot",value:"oneshot"},{title:"notify",value:"notify"}],ee=[{title:"multi-user.target",value:"multi-user.target"},{title:"network.target",value:"network.target"}];function te(e,t){const s=[];s.push("[Unit]"),t.description.trim()?s.push(`Description=${t.description.trim()}`):s.push(`Description=${e}`),s.push(""),s.push("[Service]"),s.push(`Type=${t.type.trim()||"simple"}`),t.exec_start.trim()&&s.push(`ExecStart=${t.exec_start.trim()}`),t.working_dir.trim()&&s.push(`WorkingDirectory=${t.working_dir.trim()}`),t.user_.trim()&&s.push(`User=${t.user_.trim()}`);for(const e of t.env){const t=e.key.trim();if(!t)continue;const n=e.value??"",i=`${t}=${n}`,o=/[\s"'\\]/.test(n);s.push(`Environment=${o?`"${i.replace(/"/g,'\\"')}"`:i}`)}return t.restart&&"no"!==t.restart&&s.push(`Restart=${t.restart.trim()}`),s.push(""),s.push("[Install]"),s.push(`WantedBy=${t.wanted.trim()||"multi-user.target"}`),s.push(""),s.join("\n")}function se(e){const t={description:"",type:"simple",exec_start:"",working_dir:"",user_:"root",restart:"no",wanted:"multi-user.target",env:[]},s=(t,s)=>{const n=e.split(/\r?\n/);let i=!1;for(const e of n){const n=e.trim(),o=n.match(/^\[(.*)\]$/);if(o){i=(o[1]||"").trim()===t;continue}if(!i)continue;const r=n.match(new RegExp(`^${s}\\s*=\\s*(.*)$`,"i"));if(r)return r[1].trim()}return""};t.description=s("Unit","Description"),t.type=s("Service","Type")||"simple",t.exec_start=s("Service","ExecStart"),t.working_dir=s("Service","WorkingDirectory"),t.user_=s("Service","User"),t.restart=s("Service","Restart")||"no",t.wanted=s("Install","WantedBy")||"multi-user.target";let n=!1;for(const s of e.split(/\r?\n/)){const e=s.trim(),i=e.match(/^\[(.*)\]$/);if(i){n="Service"===(i[1]||"").trim();continue}if(!n)continue;const o=e.match(/^Environment\s*=\s*(.*)$/i);if(!o)continue;const r=o[1].trim();if(!r)continue;const c=[];let l=0;for(;l<r.length;){const e=r[l];if(/\s/.test(e))l++;else if('"'===e||"'"===e){const t=e;l++;const s=l;for(;l<r.length&&r[l]!==t;)l++;c.push({text:r.slice(s,l),quoted:!0}),l++}else{const e=l;for(;l<r.length&&!/\s/.test(r[l]);)l++;c.push({text:r.slice(e,l),quoted:!1})}}for(const e of c){const s=e.text,n=s.indexOf("=");n>0?t.env.push({key:s.slice(0,n).trim(),value:s.slice(n+1)}):t.env.length&&(t.env[t.env.length-1].value+=" "+s)}}return t}function ne(e){const{t}=(0,p.Bd)(),[s,i]=(0,n.useState)("form"),[o,r]=(0,n.useState)(()=>(e.unit_name||"").replace(/\.service$/i,"")),[c,l]=(0,n.useState)({description:"",type:"simple",exec_start:"",working_dir:"",user_:"root",restart:"no",wanted:"multi-user.target",env:[]}),[d,u]=(0,n.useState)(""),[h,j]=(0,n.useState)(""),[w,v]=(0,n.useState)(!1),[k,S]=(0,m.fp)(f.AG.confirm);(0,n.useEffect)(()=>{"edit"===e.mode&&e.unit_name&&(async()=>{v(!0);try{const t=await a.Yu.post("systemd/get/context",{unit_name:e.unit_name});if(t.code!==x.m.Success)return;const s=t.data.context??"",n=t.data.path??"";j(n),u(s),l(se(s))}finally{v(!1)}})()},[e.mode,e.unit_name]);const b=e=>{e!==s&&("text"===e?u(te(o,c)):l(se(d)),i(e))},C=e=>t=>{l(s=>({...s,[e]:t}))},A=(e,t,s)=>{l(n=>{const i=[...n.env];return i[e]={...i[e],[t]:s},{...n,env:i}})};return(0,y.jsxs)("div",{children:[(0,y.jsxs)("div",{style:{display:"flex",gap:"0.4rem",marginBottom:"0.6rem"},children:[(0,y.jsx)("button",{className:"button button--flat "+("form"===s?"":"button--grey"),onClick:()=>b("form"),children:t("表单")}),(0,y.jsx)("button",{className:"button button--flat "+("text"===s?"":"button--grey"),onClick:()=>b("text"),children:t("文本")})]}),w?(0,y.jsx)("div",{children:t("加载中...")}):"form"===s?(0,y.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"0.6rem"},children:[(0,y.jsx)(_.BC,{label:t("服务名称"),children:(0,y.jsx)(_.Sm,{placeholder:t("服务名称"),value:o,disabled:"edit"===e.mode,handleInputChange:e=>r(e),width:"100%"})}),(0,y.jsx)(_.BC,{label:t("服务描述"),children:(0,y.jsx)(_.Sm,{placeholder:t("服务描述"),value:c.description,handleInputChange:C("description"),width:"100%"})}),(0,y.jsx)(_.BC,{label:t("启动命令"),required:!0,children:(0,y.jsx)(_.Sm,{placeholder:t("ExecStart 启动命令,必填"),value:c.exec_start,handleInputChange:C("exec_start"),width:"100%"})}),(0,y.jsx)(_.BC,{label:t("运行类型"),children:(0,y.jsx)(_.l6,{options:Q,value:c.type,onChange:C("type")})}),(0,y.jsx)(_.BC,{label:t("工作目录"),children:(0,y.jsx)(_.Sm,{placeholder:t("工作目录(可选)"),value:c.working_dir,handleInputChange:C("working_dir"),width:"100%"})}),(0,y.jsx)(_.BC,{label:t("运行用户"),children:(0,y.jsx)(_.Sm,{placeholder:t("运行用户(可选)"),value:c.user_,handleInputChange:C("user_"),width:"100%"})}),(0,y.jsx)(_.BC,{label:t("重启策略"),children:(0,y.jsx)(_.l6,{options:J,value:c.restart,onChange:C("restart")})}),(0,y.jsx)(_.BC,{label:t("安装目标"),children:(0,y.jsx)(_.l6,{options:ee,value:c.wanted,onChange:C("wanted")})}),(0,y.jsxs)("div",{className:"div-row",style:{justifyContent:"space-between"},children:[(0,y.jsx)("span",{children:t("环境变量")}),(0,y.jsx)("button",{className:"button button--flat button--grey",onClick:()=>l(e=>({...e,env:[...e.env,{key:"",value:""}]})),children:t("添加")})]}),0===c.env.length&&(0,y.jsx)("div",{className:"text-secondary",style:{fontSize:"0.85rem"},children:t("暂无环境变量")}),c.env.map((e,s)=>(0,y.jsxs)("div",{className:"div-row",style:{gap:"0.4rem"},children:[(0,y.jsx)(_.Sm,{placeholder:"KEY",value:e.key,width:"35%",handleInputChange:e=>A(s,"key",e)}),(0,y.jsx)(_.Sm,{placeholder:"value",value:e.value,width:"50%",handleInputChange:e=>A(s,"value",e)}),(0,y.jsx)("button",{className:"button button--flat button--grey",onClick:()=>(e=>{l(t=>({...t,env:t.env.filter((t,s)=>s!==e)}))})(s),children:t("删除")})]},s))]}):(0,y.jsx)(_.Z2,{style:{width:"100%",minHeight:"16rem",fontFamily:"monospace",fontSize:"0.85rem",boxSizing:"border-box"},value:d,onChange:e=>u(e.target.value),spellCheck:!1}),(0,y.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:"0.4rem",marginTop:"0.6rem"},children:[(0,y.jsx)("button",{className:"button button--flat button--grey",disabled:w,onClick:e.onClose,children:t("取消")}),(0,y.jsx)("button",{className:"button button--flat",disabled:w,onClick:async()=>{if(!o.trim())return void(0,g.zN)(t("请填写服务名称"));const n=(i=o).trim().endsWith(".service")?i.trim():`${i.trim()}.service`;var i;const r="text"===s?d:te(n,c);if(r.includes("ExecStart=")){if("form"===s){if(c.env.find(e=>!e.key.trim()&&""!==(e.value??"").trim()))return void(0,g.zN)(t("环境变量的 KEY 不能为空"))}v(!0);try{if("create"===e.mode){const s=`/etc/systemd/system/${n}`;await a.Yu.post("systemd/sys/save",{unit_name:n,path:s,context:r}),await a.Yu.post("systemd/sys/enable",{unit_name:n}),await a.Yu.post("systemd/add",{unit_name:n}),(0,g.SK)(t("添加成功")),e.onClose(),e.onDone?.()}else await a.Yu.post("systemd/sys/save",{unit_name:n,path:h,context:r}),(0,g.SK)(t("保存成功")),e.onClose(),e.onDone?.(),S({open:!0,title:t("配置已保存,是否立即重启该服务让新配置生效?"),handle:async()=>{(await a.Yu.post("systemd/sys/restart",{unit_name:n})).code===x.m.Success&&((0,g.SK)(t("重启成功")),S({open:!1,handle:null}))}})}catch(e){console.error("systemd 保存失败",e)}finally{v(!1)}}else(0,g.zN)(t("请至少填写 ExecStart 启动命令"))},children:t("保存")})]})]})}let ie,oe="";function re(e){const{t}=(0,p.Bd)(),{check_user_auth:s}=(0,S.MH)(),[r,j]=(0,m.fp)(f.AG.systemd_shell_show),[w,v]=(0,m.fp)(f.AG.confirm),[k,C]=(0,n.useState)(["pid","name","process",t("创建用户"),t("内存"),t("cpu%"),t("active状态"),t("选择")]),[A,V]=(0,n.useState)(["单元名字","加载状态",t("active(sub)状态"),t("描述"),t("选择")]),[P,Y]=(0,n.useState)([]),[F,N]=(0,n.useState)([]),[E,M]=(0,n.useState)([]),[K,B]=(0,n.useState)(!1),[H,Z]=(0,n.useState)([]),[G,D]=(0,n.useState)(""),[z,T]=(0,n.useState)(""),[W,X]=(0,n.useState)(new Set),[q,U]=(0,m.fp)(f.AG.editorSetting),[L,R]=(0,m.fp)(f.AG.prompt_card);(0,n.useEffect)(()=>{T(oe),(async()=>{Y([]),M([]);const e=new c.hf(c.HK.systemd_inside_get);await l.ws.send(e),l.ws.addMsg(c.HK.systemd_inside_getting,e=>{const t=[];if(oe){for(const s of e.context)for(const e of s)if(`${e}`.includes(oe)){t.push(s);break}}else t.push(...e.context);Y(t.map(e=>{const t=e.map((e,t)=>(0,y.jsx)(o.xP,{context:4===t?(0,$.v7)(e):e}));return t.push((0,y.jsx)(u.rA,{icon:"place",title:"选中",onClick:()=>{M(t)}})),t}))})})()},[]),(0,n.useEffect)(()=>{oe=z},[z]);const J=e=>{if(r.show){j({show:!1,unit_name:""});const e=new CustomEvent("cancel_systemd_logs",{detail:{}});document.dispatchEvent(e)}else j({show:!0,unit_name:e})},Q=async e=>{v({open:!0,handle:async()=>{(await a.Yu.post("systemd/sys/restart",{unit_name:e})).code===x.m.Success&&((0,g.SK)(t("重启成功")),v({open:!1,handle:null}))}})},ee=async()=>{N([]),Z([]);const e=await a.Yu.get("systemd/inside/all");if(e.code!==x.m.Success)return;X(new Set(e.data));const t=await a.Yu.get("systemd/allget");if(t.code===x.m.Success){const e=t.data,s=[];for(const t of e??[]){const e=[(0,y.jsx)(o.xP,{context:t.unit}),t.load,`${t.active}(${t.sub})`,(0,y.jsx)(o.xP,{context:t.description})];s.push([...e,(0,y.jsx)(u.rA,{icon:"place",title:"添加",onClick:()=>{Z([...e])}})])}ie=s,N(s)}},te=(e,s)=>{R({open:!0,title:t("create"===e?"新建 systemd 服务":"编辑 systemd 服务"),context_div:(0,y.jsx)(ne,{mode:e,unit_name:s,onClose:()=>R({open:!1}),onDone:()=>{R({open:!1}),l.ws.send(new c.hf(c.HK.systemd_inside_get)),K&&ee(),M([]),Z([])}})})};return(0,y.jsxs)("div",{children:[(0,y.jsx)(d.aZ,{children:(0,y.jsx)(u.Z$,{defaultStatus:!1,text:t("系统systemd单元"),clickFun:e=>{B(e),e?(ee(),M([])):Z([])}})}),(0,y.jsxs)(d.aZ,{position:"right",children:[s(b.oV.systemd)&&(0,y.jsx)("div",{children:(0,y.jsx)(u.rA,{icon:"add_circle",title:t("添加 systemd"),onClick:()=>{te("create")}})}),E.length>0&&(0,y.jsx)("div",{children:E[1].props.context}),H.length>0&&(0,y.jsx)("div",{children:H[0].props.context}),E.length>0&&(0,y.jsxs)("div",{children:[s(b.oV.systemd)&&(0,y.jsx)(u.rA,{icon:"remove",title:"从实时监控删除",onClick:()=>{(async e=>{v({open:!0,handle:async()=>{(await a.Yu.post("systemd/delete",{unit_name:e})).code===x.m.Success&&((0,g.SK)(t("删除成功")),v({open:!1,handle:null}))}})})(E[1].props.context)}}),s(b.oV.systemd)&&(0,y.jsx)(u.rA,{icon:"edit",title:"可视化编辑",onClick:()=>{te("edit",E[1].props.context)}}),s(b.oV.systemd)&&W.has(E[1].props.context)&&(0,y.jsx)(u.rA,{icon:"restart_alt",title:t("重启服务"),onClick:()=>{Q(E[1].props.context)}}),(0,y.jsx)(u.rA,{icon:"print",title:"打印日志",onClick:()=>{J(E[1].props.context)}})]}),H.length>0&&(0,y.jsxs)("div",{children:[s(b.oV.systemd)&&(0,y.jsx)(u.rA,{icon:"delete",title:"删除系统上的sytemd",onClick:()=>{(async e=>{v({open:!0,handle:async()=>{(await a.Yu.post("systemd/sys/delete",{unit_name:e})).code===x.m.Success&&((0,g.SK)(t("删除成功")),v({open:!1,handle:null}))}})})(H[0].props.context)}}),(0,y.jsx)(u.rA,{icon:"print",title:"打印日志",onClick:()=>{J(H[0].props.context)}}),s(b.oV.systemd)&&(0,y.jsx)(u.rA,{icon:"restart_alt",title:t("重启服务"),onClick:()=>{Q(H[0].props.context)}}),s(b.oV.systemd)&&(0,y.jsx)(u.rA,{icon:"text_fields",title:"sytemd文件内容",onClick:()=>{(async t=>{const s=await a.Yu.post("systemd/get/context",{unit_name:t});s.code===x.m.Success&&(U({model:"text",open:!0,fileName:e.name,save:async e=>{const n={unit_name:t,path:s.data.path,context:e};(await a.Yu.post("systemd/sys/save",n)).code===x.m.Success&&S.xK.set_value_temp("")}}),S.xK.set_value_temp(s.data.context))})(H[0].props.context)}}),s(b.oV.systemd)&&!W.has(H[0].props.context)&&(0,y.jsx)(u.rA,{icon:"plus_one",title:"添加到管理",onClick:()=>(async e=>{const s=await a.Yu.post("systemd/add",{unit_name:e});s.code===x.m.Success&&(X(new Set(s.data)),(0,g.SK)(t("添加成功")))})(H[0].props.context)})]})]}),(0,y.jsxs)(i.xh,{children:[K&&(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:80,children:(0,y.jsx)(o.uF,{title:`systemd系统单元(${F.length})`,rightTopCom:(0,y.jsx)(_.Sm,{placeholder:"过滤单元",value:G,handleInputChange:e=>{D(e)},handlerEnter:()=>{const e=[];if(G){for(const t of ie)(t[0].props.context.includes(G)||t[3].props.context.includes(G))&&e.push(t);N(e)}else N(ie)}}),children:(0,y.jsx)(h.X,{headers:A,rows:F,width:"10rem"})})})}),0===P.length&&!K&&(0,y.jsx)(I.h,{context:"没有管理的单元 or 加载中请等待..."}),0!==P.length&&!K&&(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:80,children:(0,y.jsx)(o.uF,{title:`filecat监控单元(${P.length})`,rightTopCom:(0,y.jsx)(_.Sm,{placeholder:"过滤单元",value:z,handleInputChange:e=>{T(e)}}),children:(0,y.jsx)(h.X,{headers:k,rows:P,width:"10rem"})})})})]}),(0,y.jsx)(O,{})]})}function ce(){const{t:e}=(0,p.Bd)(),t=[{title:e("放行"),value:"allow"},{title:e("拒绝"),value:"deny"},{title:e("限速"),value:"limit"},{title:e("拒绝响应"),value:"reject"}],s=[{title:e("入站"),value:"in"},{title:e("出站"),value:"out"}],[r,c]=(0,n.useState)(null),[l,j]=(0,n.useState)("allow"),[w,v]=(0,n.useState)("in"),[k,S]=(0,n.useState)("tcp"),[b,C]=(0,n.useState)(""),[A,V]=(0,n.useState)(""),[P,$]=(0,n.useState)("list"),[Y,F]=(0,n.useState)([]),[N,E]=(0,n.useState)(""),[M,K]=(0,n.useState)(!1),[B,H]=(0,m.fp)(f.AG.confirm),Z=async()=>{try{const e=await a.V_.get("status");e.code===x.m.Success&&c(e.data)}catch(e){}},G=async()=>{K(!0);try{const e=await a.V_.get("rules");if(e.code===x.m.Success){const t=e.data;F(t?.rules??[]),E(t?.raw??"")}}catch(e){F([]),E("")}finally{K(!1)}};(0,n.useEffect)(()=>{Z(),G()},[]);const D=!0===r?.installed,z=!0===r?.active;return(0,y.jsxs)("div",{children:[(0,y.jsxs)(d.aZ,{position:"right",children:[(0,y.jsxs)("div",{children:[e("已安装"),": ",D?(0,y.jsx)("span",{style:{color:"green"},children:"✓"}):(0,y.jsx)("span",{style:{color:"red"},children:"✗"})]}),(0,y.jsxs)("div",{children:[e("已启用"),": ",z?(0,y.jsx)("span",{style:{color:"green"},children:"✓"}):(0,y.jsx)("span",{style:{color:"gray"},children:"✗"})]}),D&&(0,y.jsx)(u.rA,{icon:"power_settings_new",title:e(z?"停用":"启用"),onClick:()=>(async t=>{try{const s=await a.V_.post("enable",{enabled:t});if(s.code!==x.m.Success)return void(0,g.zN)(s.message||e("操作失败"));(0,g.SK)(s.data||e(t?"已启用":"已停用")),Z(),G()}catch(e){}})(!z)}),(0,y.jsx)(u.rA,{icon:"refresh",title:e("刷新规则"),onClick:G})]}),(0,y.jsxs)(i.xh,{children:[(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:35,children:(0,y.jsxs)(o.uF,{title:e("添加ufw规则"),rightTopCom:(0,y.jsx)(u.rA,{icon:"add",title:e("添加"),onClick:async()=>{if(b.trim())try{const t=await a.V_.post("rule/add",{action:l,direction:w,proto:k,port:b.trim(),from:"in"===w&&A.trim()||void 0});if(t.code!==x.m.Success)return void(0,g.zN)(t.message||e("操作失败"));(0,g.SK)(t.data||e("已添加")),G()}catch(e){}else(0,g.zN)(e("请填写端口号"))}}),children:[(0,y.jsx)(_.BC,{label:e("动作"),label_width:"4rem",input_max_width:"8rem",children:(0,y.jsx)(_.l6,{options:t,value:l,onChange:e=>j(e),defaultValue:"allow"})}),(0,y.jsx)(_.BC,{label:e("方向"),label_width:"4rem",input_max_width:"8rem",children:(0,y.jsx)(_.l6,{options:s,value:w,onChange:e=>v(e),defaultValue:"in"})}),(0,y.jsx)(_.BC,{label:e("协议"),label_width:"4rem",input_max_width:"8rem",children:(0,y.jsx)(_.l6,{options:[{title:"tcp",value:"tcp"},{title:"udp",value:"udp"}],value:k,onChange:e=>S(e),defaultValue:"tcp"})}),(0,y.jsx)(_.BC,{label:e("端口"),label_width:"4rem",required:!0,children:(0,y.jsx)(_.Sm,{maxWidth:"20rem",placeholder:e("可填范围如 1000:2000"),value:b,handleInputChange:e=>C(e)})}),"in"===w&&(0,y.jsx)(_.BC,{label:e("来源"),label_width:"4rem",children:(0,y.jsx)(_.Sm,{maxWidth:"20rem",placeholder:e("IP/网段,可选"),value:A,handleInputChange:e=>V(e)})})]})})}),(0,y.jsx)(i.fI,{children:(0,y.jsx)(i.VP,{widthPer:80,children:(0,y.jsxs)(o.uF,{title:e("规则列表"),rightTopCom:(0,y.jsxs)("div",{style:{display:"flex",gap:"0.4rem"},children:[(0,y.jsx)(u.C3,{text:e("名单视图"),clickFun:()=>$("list")}),(0,y.jsx)(u.C3,{text:e("文本视图"),clickFun:()=>$("text")})]}),children:[M&&(0,y.jsx)(I.h,{context:e("加载中...")}),!M&&"list"===P&&(0===Y.length?(0,y.jsx)(I.h,{context:e("暂无规则")}):(0,y.jsx)(h.X,{headers:[e("编号"),e("目标(To)"),e("动作"),e("fw_from"),e("备注"),e("操作")],rows:Y.map(t=>[t.number,(0,y.jsx)(o.xP,{context:t.to,tip_context:t.to}),t.action,t.from?(0,y.jsx)(o.xP,{context:t.from,tip_context:t.from}):"",t.description||"",(0,y.jsx)(u.rA,{icon:"delete",title:e("删除规则"),onClick:()=>(async(t,s,n)=>{H({open:!0,title:e("确定删除吗?"),sub_title:e(`${s} ${n}`),handle:async()=>{try{const s=await a.V_.post("ufw/rule/del",{number:t});if(s.code!==x.m.Success)return void(0,g.zN)(s.message||e("操作失败"));(0,g.SK)(s.data||e("规则已删除")),H({open:!1,handle:null}),G()}catch(e){}}})})(t.number,t.to,t.from)})]),width:"8rem"})),!M&&"text"===P&&(N?(0,y.jsx)("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-all",fontSize:"0.85rem",margin:0},children:N}):(0,y.jsx)(I.h,{context:e("暂无规则")}))]})})})]})]})}function le(e){const{t}=(0,p.Bd)(),[s,n]=(0,m.fp)(f.AG.user_base_info),o=[{index:1,name:t("系统性能"),rto:"sys/",component:(0,y.jsx)(F,{})},{index:2,name:t("系统进程"),rto:"process/",component:(0,y.jsx)(L,{})},{index:3,name:t("doc_ct"),rto:"docker/",component:(0,y.jsx)(T,{})}];if(s.sys===b.XM.linux){(s.user_data?.is_root||(s.user_data?.auth_list??[]).includes(b.oV.systemd))&&o.push({index:4,name:t("systemd"),rto:"systemd/",component:(0,y.jsx)(re,{})});(s.user_data?.is_root||(s.user_data?.auth_list??[]).includes(b.oV.firewall))&&s.sysSoftWare?.[j.jk.ufw]?.installed&&o.push({index:5,name:t("防火墙"),rto:"firewall/",component:(0,y.jsx)(ce,{})})}return(0,y.jsx)(i.W1,{optionList:o,father_route:Z.o.info})}}}]);