filecat 6.12.0 → 6.12.1

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.
@@ -1 +1 @@
1
- "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[6010,9782],{83277(e,t,s){s.d(t,{$j:()=>c,Lv:()=>a,qq:()=>i});class n{options_agent_url_list;options_agent_key_list;options_agent_model_list}class a{token;open=!1;note;index;url;model;request_type;json_params;sys_prompt;dotenv="";tool_mode=!1;show_options;static get_label_by_v(e,t){if(!e||!t?.length)return e;for(const s of t)if(s.value===e)return s.label;return e}static have_label_by_v(e,t){if(!e||!t?.length)return!1;for(const s of t)if(s.value===e)return!0;return!1}}class i extends n{tool_error_max=50;tool_call_max=300;allow_exec_cmd_directly=!1;proxy_url}const o=JSON.stringify({stream:!0,thinking:{type:"disabled"}});function c(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>"text"===e.type?e.text:"[图片]").join("\n"):""}s.d(t,["CP",0,'\n\n# 工具报错最大尝试次数\ntool_error_max=50\n# 聊天循环最大次数\ntool_call_max=300\n# 是否允许AI直接执行命令而不需要用户确认,默认为false,需要用户手动确认,如果使用 workflow 这里等价于为 true\nallow_exec_cmd_directly=false\n\n# 可选的代理 url,如果指定了所有访问大模型的请求将会走代理\n#proxy_url=\n\n# 可选的多个url 以数组分割\n# options_agent_url_list=[{"value":"http://..","label":"openai"}]\n\n# 可选的多个 key\n# options_agent_key_list=[{"value":"sh-aaa","label":"option1"}]\n\n# 可选的多个 model\n# options_agent_model_list=[{"value":"gpt-5.5","label":"gpt"}]\n\n',"cL",0,o])},86271(e,t,s){s.r(t),s.d(t,{default:()=>M});var n=s(96540),a=s(14284),i=s(7463),o=s(57952),c=s(85997),r=s(78247),l=s(23430),d=s(40505),u=s(62042),m=s(22022),h=s(45907),g=s(53459),p=s(87361),x=s(52671),_=s(34843),f=s(82893),j=s(27690),v=s(61443),y=s(72693),b=s(83277),w=s(74848);function S({sessions:e,activeSessionId:t,onSelectSession:s,onRenameSession:a,onDeleteSession:i,onShowUsageStats:o,batchMode:r,selectedSessionIds:l,onToggleSessionSelect:d}){const{t:u}=(0,m.Bd)(),[h,g]=(0,_.fp)(f.AG.ai_session_collapsed),[p,x]=(0,n.useState)(""),v=p.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(p.toLowerCase())||(e.summary||"").toLowerCase().includes(p.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(p.toLowerCase())):e;return(0,w.jsxs)("aside",{className:`chat-session-list ${h?"active":""} ${h?"collapsed":""}`,children:[!h&&(0,w.jsx)("div",{className:"chat-session-search",children:(0,w.jsx)("input",{type:"text",className:"chat-session-search-input",placeholder:u("搜索会话"),value:p,onChange:e=>x(e.target.value)})}),v.map(e=>{return(0,w.jsx)("div",{children:(0,w.jsxs)("button",{className:`chat-session-item ${t===e.id?"active":""} ${r?"batch-mode":""}`,onClick:()=>{r&&d?d(e.id):s(e.id)},title:e.summary||e.long_term_memory||e.title,children:[r&&(0,w.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:l?.has(e.id)??!1,onChange:()=>d?.(e.id),onClick:e=>e.stopPropagation()}),(0,w.jsx)("span",{children:(n=e.title,n||"新会话")}),(0,w.jsx)("small",{children:e.message_count}),"web"!==e.source&&(0,w.jsx)("em",{className:"chat-session-source",children:e.source}),!r&&(0,w.jsx)(j.MenuSelect,{list:[{name:u("重命名"),click:()=>a(e.id,e.title)},{name:u("字符消耗统计"),click:()=>o(e.id)},{name:u("删除"),click:()=>i(e.id)}],children:(0,w.jsx)(c.In,{icon:"more_horiz"})})]})},e.id);var n})]})}function k({pendingAttachments:e,onRemove:t}){return 0===e.length?null:(0,w.jsx)("div",{className:"chat-attachment-strip",children:e.map((e,s)=>(0,w.jsxs)("div",{className:"chat-attachment-chip",children:[(0,w.jsx)(c.In,{icon:"attach_file"}),(0,w.jsx)("span",{title:e.name,children:e.name}),(0,w.jsx)("button",{type:"button",onClick:()=>t(s),children:(0,w.jsx)(c.In,{icon:"close"})})]},`${e.name}_${s}`))})}function N({inputValue:e,onInputChange:t,onKeyDown:s,onPaste:n,onSend:a,sending:i,pendingAttachments:o,onRemoveAttachment:r,onOpenFilePicker:l,onAddFiles:d,onDrop:u,onDragOver:h,fileInputRef:g}){const{t:p}=(0,m.Bd)();return(0,w.jsxs)("div",{className:"chat-input-area",onDrop:u,onDragOver:h,children:[(0,w.jsx)("input",{ref:g,type:"file",multiple:!0,style:{display:"none"},onChange:e=>{e.target.files?.length&&(d(e.target.files),e.currentTarget.value="")}}),(0,w.jsxs)("div",{className:"chat-input-shell",children:[(0,w.jsx)(k,{pendingAttachments:o,onRemove:r}),(0,w.jsx)("textarea",{value:e,onChange:t,onPaste:n,onKeyDown:s,placeholder:p("输入消息"),className:"chat-input"})]}),(0,w.jsx)(c.rA,{title:p("添加文件"),icon:"attach_file",onClick:l}),!1===i?(0,w.jsx)(c.Vi,{text:p("发送"),clickFun:a}):(0,w.jsx)("div",{className:"ai-thinking-indicator",children:(0,w.jsxs)("div",{className:"ai-thinking-dots",children:[(0,w.jsx)("div",{className:"ai-thinking-dot"}),(0,w.jsx)("div",{className:"ai-thinking-dot"}),(0,w.jsx)("div",{className:"ai-thinking-dot"})]})})]})}var A=s(96494);function C(){try{const e=localStorage.getItem("ai_images_extra_params");if(e)return JSON.parse(e)}catch{}return{size:"1024x1024",n:1}}function $({onClose:e}){const{t}=(0,m.Bd)(),[s,a]=(0,n.useState)(C),[i,o]=(0,n.useState)(s.size||"1024x1024"),[r,l]=(0,n.useState)(String(s.n??1)),[d,u]=(0,n.useState)(s.quality||""),[h,g]=(0,n.useState)(s.style||""),[p,x]=(0,n.useState)(s.extra_json||"");return(0,w.jsxs)("div",{className:"card images-params-card",children:[(0,w.jsx)("h3",{children:t("图片生成参数设置")}),(0,w.jsx)("p",{className:"images-params-hint",children:"不同模型支持的参数不同,请参考模型文档。常见 size 值: 1024x1024, 1792x1024, 1024x1792 (DALL-E 3)"}),(0,w.jsxs)("div",{className:"images-params-fields",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:"size (图片尺寸)"}),(0,w.jsx)(v.Sm,{value:i,handleInputChange:o,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:"n (生成数量)"}),(0,w.jsx)(v.Sm,{value:r,handleInputChange:l,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:'quality (画质, 如 "standard" / "hd")'}),(0,w.jsx)(v.Sm,{value:d,handleInputChange:u,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:'style (风格, 如 "vivid" / "natural")'}),(0,w.jsx)(v.Sm,{value:h,handleInputChange:g,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:"额外参数 (JSON,会合并到请求体中)"}),(0,w.jsx)(v.Sm,{value:p,handleInputChange:x,no_border:!1})]})]}),(0,w.jsxs)("div",{className:"images-params-actions",children:[(0,w.jsx)(c.rA,{icon:"close",title:t("取消"),onClick:e}),(0,w.jsx)(c.rA,{icon:"save",title:t("保存"),onClick:()=>{const t={size:i,n:parseInt(r)||1};d&&(t.quality=d),h&&(t.style=h),p&&(t.extra_json=p),function(e){localStorage.setItem("ai_images_extra_params",JSON.stringify(e))}(t),e()}})]})]})}function I(){const{t:e}=(0,m.Bd)(),[t,s]=(0,_.fp)(f.AG.ai_request_type),[a,i]=(0,n.useState)(!1),o=(0,A.r)(),c=o.find(e=>e.value===t)??o[0];return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(j.MenuSelect,{list:[...o.map(e=>({name:e.label,click:()=>s(e.value)})),..."images"===t?[{name:e("图片参数设置"),click:()=>i(!0)}]:[],..."audio_speech"===t?[{name:e("语音参数设置"),click:()=>{const t=localStorage.getItem("ai_audio_extra_params"),s=t?JSON.parse(t):{},n=s.voice||"alloy",a=s.speed||"1.0",i=prompt(e("输入 voice (如 alloy, echo, fable, onyx, nova, shimmer)"),n);if(null!==i){const t=prompt(e("输入 speed (0.25 ~ 4.0)"),a);null!==t&&localStorage.setItem("ai_audio_extra_params",JSON.stringify({voice:i,speed:parseFloat(t)||1}))}}}]:[]],children:(0,w.jsxs)("div",{className:"menu-select-trigger",children:[(0,w.jsx)("span",{children:c.label}),(0,w.jsx)("span",{className:"menu-select-arrow",children:"▾"})]})}),a&&(0,w.jsx)("div",{className:"modal-overlay",onClick:()=>i(!1),children:(0,w.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,w.jsx)($,{onClose:()=>i(!1)})})})]})}var O=s(34299);function D(e){const t=e.attachments&&e.attachments.length>0?(0,w.jsx)("div",{className:"chat-message-attachments",children:e.attachments.map((e,t)=>(0,w.jsxs)("div",{className:"chat-message-attachment",children:[(0,w.jsx)(c.In,{icon:"attach_file"}),(0,w.jsx)("span",{children:e.name}),(0,w.jsxs)("small",{children:[e.size," B"]})]},`${e.name}_${t}`))}):null,s=[];return e.images&&"bot"===e.sender&&s.push((0,w.jsx)(n.Fragment,{children:(0,w.jsx)(F,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&s.push((0,w.jsx)(n.Fragment,{children:(0,w.jsx)(V,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&s.push((0,w.jsx)(n.Fragment,{children:(0,w.jsx)(z,{embeddings:e.embeddings,text:e.text})},"embeddings")),0===s.length?(0,w.jsxs)(w.Fragment,{children:[t,(0,w.jsx)(O.default,{context:e.text})]}):(0,w.jsxs)(w.Fragment,{children:[s,t,e.text&&(0,w.jsx)(O.default,{context:e.text})]})}function F({images:e,text:t}){let s=e||[];if(!s.length&&t)try{s=JSON.parse(t).data||[]}catch{}return s.length?(0,w.jsxs)("div",{className:"image-generation-result",children:[s.map((e,t)=>(0,w.jsxs)("div",{className:"image-generation-item",children:[e.url&&(0,w.jsx)("div",{className:"image-generation-image-wrapper",children:(0,w.jsx)("img",{src:e.url,alt:e.revised_prompt||`生成的图片 ${t+1}`,loading:"lazy"})}),e.b64_json&&(0,w.jsx)("div",{className:"image-generation-image-wrapper",children:(0,w.jsx)("img",{src:`data:image/png;base64,${e.b64_json}`,alt:`生成的图片 ${t+1}`})}),e.revised_prompt&&(0,w.jsx)("p",{className:"image-generation-prompt",children:(0,w.jsx)("small",{children:e.revised_prompt})})]},t)),t&&!e&&(0,w.jsx)(O.default,{context:t})]}):(0,w.jsx)(O.default,{context:t||""})}function V({audio:e,text:t}){if(e){if(e.url)return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:e.url,children:"您的浏览器不支持音频播放"})});if(e.data){const t=e.mime_type||"audio/mpeg";return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:`data:${t};base64,${e.data}`,children:"您的浏览器不支持音频播放"})})}}const s=t||"";if(s.startsWith("http://")||s.startsWith("https://"))return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:s,children:"您的浏览器不支持音频播放"})});try{const e=JSON.parse(s);if(e?.data||e?.audio_data){const t=e.data||e.audio_data;return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:`data:audio/mpeg;base64,${t}`,children:"您的浏览器不支持音频播放"})})}}catch{}return(0,w.jsx)(O.default,{context:s})}function J({content:e,label:t}){const[s,a]=n.useState(!1);return(0,w.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,d.lW)(e),a(!0),setTimeout(()=>a(!1),1500)},children:[(0,w.jsx)(c.In,{icon:s?"check":"content_copy"}),s?"已复制":t||"复制"]})}function z({embeddings:e,text:t}){let s=e||null;if(!s&&t)try{s=JSON.parse(t)}catch{return(0,w.jsx)(O.default,{context:t})}if(!s)return(0,w.jsx)(O.default,{context:t||""});const n=s?.data||[],a=s?.usage,i=JSON.stringify(s,null,2);return(0,w.jsxs)("div",{className:"embeddings-result",children:[(0,w.jsxs)("div",{className:"embeddings-summary",children:[(0,w.jsx)("strong",{children:"向量嵌入结果"}),(0,w.jsxs)("span",{children:["维度: ",n[0]?.embedding?.length??"N/A"]}),(0,w.jsxs)("span",{children:["数量: ",n.length]}),a&&(0,w.jsxs)("span",{children:["使用 tokens: ",a.total_tokens??"N/A"]})]}),(0,w.jsxs)("div",{className:"embeddings-toolbar",children:[(0,w.jsx)(J,{content:i,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,w.jsx)(J,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,w.jsx)(J,{content:JSON.stringify(n.map(e=>e.embedding),null,2),label:"复制所有向量数据"})]}),n.length>0&&n[0]?.embedding&&(0,w.jsx)("div",{className:"embeddings-preview",children:(0,w.jsxs)("span",{children:["向量预览: [",n[0].embedding.slice(0,5).join(", "),n[0].embedding.length>5?", ...":"","]"]})}),n.length>0&&(0,w.jsxs)("details",{children:[(0,w.jsx)("summary",{children:"查看详细数据"}),(0,w.jsx)("pre",{className:"embeddings-raw",children:i})]})]})}async function R(e,t){const s=function(){try{const e=localStorage.getItem("ai_images_extra_params");if(e)return JSON.parse(e)}catch{}return{}}(),n={prompt:e,n:s.n??1,size:s.size??"1024x1024",session_id:t};if(s.quality&&(n.quality=s.quality),s.style&&(n.style=s.style),s.extra_json)try{const e=JSON.parse(s.extra_json);Object.assign(n,e)}catch(e){console.warn("图片额外参数 JSON 解析失败:",e)}const i=await a.jV.post("images/generations",n);if(0!==i.code)throw new Error(i.message||"图片生成失败");const o=i.data||{},c=(o.data||[]).map(e=>({url:e.url,b64_json:e.b64_json,revised_prompt:e.revised_prompt})),r=c.map((e,t)=>`![生成图片${t+1}](${e.url||`data:image/png;base64,${e.b64_json}`})${e.revised_prompt?`\n> ${e.revised_prompt}`:""}`).join("\n\n");return{session_id:o.session_id||t,images:c,text:r||`生成了 ${c.length} 张图片`}}async function q(e,t,s,n){try{switch(e){case"images":{const e=await R(t,s);return e&&n(e.text,{images:e.images}),!0}case"audio_speech":{const e=await async function(e,t){const s={input:e,session_id:t};try{const e=localStorage.getItem("ai_audio_extra_params");if(e){const t=JSON.parse(e);t.voice&&(s.voice=t.voice),t.speed&&(s.speed=parseFloat(t.speed))}}catch{}const n=localStorage.getItem("token")||"",a=await fetch("/api/ai_agent/audio/speech",{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(s)});if(!a.ok)throw new Error(`语音合成失败: ${a.statusText}`);const i=a.headers.get("X-Session-Id")||t,o=await a.arrayBuffer();return{session_id:i,audio:{data:btoa(String.fromCharCode(...Array.from(new Uint8Array(o)))),mime_type:a.headers.get("content-type")||"audio/mpeg"},text:`[音频文件: ${e.slice(0,50)}...]`}}(t,s);return e&&n(e.text,{audio:e.audio}),!0}case"embeddings":{const e=await async function(e,t){const s=await a.jV.post("embeddings",{input:e,session_id:t});if(0!==s.code)throw new Error(s.message||"Embeddings 请求失败");const n=s.data||{},i=n?.data??[],o=`向量维度: ${i[0]?.embedding?.length??0}, 数量: ${i.length}`;return{session_id:n.session_id||t,embeddings:n,text:`✅ Embeddings 结果 - ${o}\n\`\`\`json\n${JSON.stringify(n,null,2).slice(0,2e3)}\n\`\`\``}}(t,s);return e&&n(e.text,{embeddings:e.embeddings}),!0}default:return!1}}catch(e){return n(`请求失败: ${e?.message||JSON.stringify(e)}`),!0}}function H(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||/\.(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.test(e.name)?"text":"binary"}function L(e){return e.text()}function E(e){return new Promise((t,s)=>{const n=new FileReader;n.onload=()=>t(n.result),n.onerror=s,n.readAsDataURL(e)})}function B(e){return e.map(e=>({role:"bot"===e.sender?"assistant":"user",content:e.text,attachments:e.attachments??[],images:e.images,audio:e.audio,embeddings:e.embeddings}))}function M(){const[e,t]=(0,n.useState)([]),[s,k]=(0,n.useState)([]),[C,$]=(0,n.useState)(""),[O,F]=(0,_.fp)(f.AG.ai_session_collapsed),[V,J]=(0,n.useState)([]),[z,R]=(0,_.fp)(f.AG.ai_request_type);(0,y.w)();const M=(0,A.r)(),{t:T}=(0,m.Bd)(),K=(0,n.useRef)(null),[P,W]=(0,_.fp)(f.AG.prompt_card),[G,U]=(0,n.useState)(!1),[X,Z]=(0,n.useState)(new Set),[Q,Y]=(0,n.useState)(new Set),ee=(0,n.useRef)((0,i.sg)(e=>{t(e),de.current&&xe(!1)},50)).current,[te,se]=(0,n.useState)(!1),{check_user_auth:ne}=(0,r.MH)(),[ae,ie]=(0,n.useState)(""),oe=(0,n.useRef)(null),ce=(0,n.useRef)(null),re=(0,h.y)(),le=(0,x.Zp)(),de=(0,n.useRef)(!0),ue=(0,n.useRef)(new b.qq),[me,he]=(0,n.useState)([]),[ge,pe]=(0,n.useState)(""),xe=(e=!1)=>{const t=ce.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?"smooth":"auto"})},_e=e=>{const t=Array.from(e??[]).filter(Boolean);t.length&&J(e=>[...e,...t])},fe=async e=>{const s=await a.jV.get("sessions");if(s.code!==g.m.Success)return;const n=s.data??[];k(n);const i=null===e?n[0]?.id??"":e||C||n[0]?.id||"";i?await ve(i):(t([]),$(""))},je=async()=>{const e=await a.jV.get("sessions");e.code===g.m.Success&&k(e.data??[])},ve=async(e,s=!1)=>{const n=await a.jV.post("session/get",{session_id:e});if(n.code!==g.m.Success||!n.data)return;const i=n.data;$(i.id),t(function(e=[]){return e.filter(e=>"user"===e.role||"assistant"===e.role).map((e,t)=>({id:Date.now()+t,sender:"assistant"===e.role?"bot":"user",text:(0,b.$j)(e.content),attachments:e.attachments??[],images:e.images,audio:e.audio,embeddings:e.embeddings}))}(i.messages)),s&&F(!1),requestAnimationFrame(()=>xe(!1))},ye=async e=>{const s=await a.jV.post("session",{title:"新会话"});if(s.code!==g.m.Success)return;const n=s.data;$(n.id),e?(ie(e),t([])):t([]),F(!1),await fe(n.id),requestAnimationFrame(()=>{const e=document.querySelector(".chat-input");e&&(e.style.height="auto",e.style.height=Math.min(e.scrollHeight,200)+"px")})};(0,n.useEffect)(()=>{(async()=>{const e=await a.XO.get("ai_agent_setting/env");if(e.code===g.m.Success){ue.current=e.data;const t=e.data.current_model_note||"",s=(e.data.options_agent_model_list??[]).find(e=>e.label===t);pe(s?s.value:t)}await fe();const t=await a.jV.get("system_prompts");t.code===g.m.Success&&he(t.data??[])})(),requestAnimationFrame(()=>{xe(!1)})},[]),(0,n.useEffect)(()=>{const e=ce.current;if(!e)return;const t=()=>{de.current=((e,t=120)=>{const{scrollTop:s,scrollHeight:n,clientHeight:a}=e;return n-(s+a)<t})(e)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.useLayoutEffect)(()=>{de.current&&xe(!1)},[e]);const be=e=>{const t=(e.attachments??[]).filter(e=>"image"===e.kind);if(t.length>0){const s=[];e.text&&s.push({type:"text",text:e.text});for(const e of t)s.push({type:"image_url",image_url:{url:e.content}});return[{content:s,role:"user",attachments:e.attachments??[]}]}return[{content:e.text,role:"bot"===e.sender?"assistant":"user",attachments:e.attachments??[]}]},we=async()=>{const s=ae.trim();if(te||!s&&0===V.length)return;let n=C;if(!n){const e=await a.jV.post("session",{title:(s||V[0]?.name||"新会话").slice(0,28)});if(e.code!==g.m.Success)return;n=e.data.id,$(n),await fe(n)}const o=await(async e=>{const t=[];for(const s of e){const e=H(s);let n="";if("text"===e)try{const e=await L(s),t=12e4;n=e.length>t?`${e.slice(0,t)}\n\n[内容已截断,原始长度 ${e.length} 字符]`:e}catch{n="[文本读取失败]"}else if("image"===e)try{n=await E(s)}catch{n=`[图片文件: ${s.name}]`}else n=`[二进制文件: ${s.name}]`;t.push({name:s.name,mime_type:s.type,size:s.size,kind:e,content:n})}return t})(V),c={id:Date.now(),sender:"user",text:s,attachments:o},r=[...e,c];if(t(r),ie(""),J([]),se(!0),"completions"!==z){const e={id:c.id+1,sender:"bot",text:"处理中..."};r.push(e),t([...r]);return void(await q(z,s,n,async(s,n)=>{e.text=s,n?.images&&(e.images=n.images),n?.audio&&(e.audio=n.audio),n?.embeddings&&(e.embeddings=n.embeddings),t([...r]),se(!1),je(),xe(!0)})||(e.text=`请求类型 "${z}" 的专用处理器尚未实现,请使用 completions 类型。`,t([...r]),se(!1)))}const l={id:c.id+1,sender:"bot",text:"AI思考中..."};r.push(l),t([...r]);let d=!0;a.jV.sse_post("chat",{messages:be(c),session_id:n},{onMessage:e=>{d&&(l.text="",d=!1);try{const t=JSON.parse(e),s="string"==typeof t?t:t?.choices?.[0]?.delta?.content??t?.choices?.[0]?.message?.content;s&&(l.text+=s)}catch(t){try{l.text+=JSON.parse(e)}catch(t){l.text+=e}}ee([...r])},onDone:(0,i.nF)(async()=>{se(!1),await je(),xe(!0)},100)})},Se=e=>null==e||e<0?"0":e.toLocaleString();return(0,w.jsxs)(n.Fragment,{children:[(0,w.jsxs)(o.A,{children:[(0,w.jsx)(c.rA,{icon:"menu",title:T("会话"),onClick:()=>{window.innerWidth<=736?F(!0):F(e=>!e)}}),(0,w.jsx)(c.rA,{icon:"add",title:T("新会话"),onClick:()=>ye()}),me.length>0&&(0,w.jsx)(j.MenuSelect,{list:me.map((e,t)=>({name:e.note||`${T("提示词")} ${t+1}`,click:()=>{e.prompt&&ye(e.prompt)}})),children:(0,w.jsx)(c.rA,{icon:"add_comment",title:T("提示词模板创建会话")})}),(0,w.jsx)(I,{}),(ue.current?.options_agent_model_list?.length??0)>0&&(0,w.jsx)(v.l6,{value:ge,options:ue.current.options_agent_model_list?.map(e=>({title:e.label,value:e.value}))??[],onChange:e=>{pe(e),a.jV.post("set_active_model",{model_name:e}).then(()=>{(0,u.SK)("success"),a.XO.get("ai_agent_setting/env").then(e=>{e.code===g.m.Success&&(ue.current=e.data)})}).catch(console.error)},no_border:!0,maxWidth:"10rem"}),(0,w.jsx)(c.rA,{icon:G?"check_circle":"checklist",title:T(G?"取消批量选择":"批量选择"),onClick:()=>{G&&(Z(new Set),Y(new Set)),U(e=>!e)}}),G&&X.size>0&&(0,w.jsx)(c.rA,{icon:"delete",title:T("删除选中消息"),onClick:()=>{0!==X.size&&re({sub_title:T("确认删除选中的聊天消息吗?"),confirm_fun:()=>{const s=e.filter(e=>!X.has(e.id));t(s),Z(new Set),U(!1),C&&s.length!==e.length&&a.jV.post("session/messages",{session_id:C,messages:B(s)}).catch(console.error)}})}}),G&&Q.size>0&&(0,w.jsx)(c.rA,{icon:"delete",title:T("删除选中会话"),onClick:()=>{0!==Q.size&&re({sub_title:T("确认删除选中的会话吗?"),confirm_fun:async()=>{for(const e of Q)await a.jV.post("session/delete",{session_id:e});Y(new Set),U(!1),Q.has(C)?($(""),await fe(null)):await fe(C)}})}}),(0,w.jsx)(c.rA,{icon:"delete_sweep",title:T("清空全部会话"),onClick:()=>{re({sub_title:T("确认删除全部聊天会话吗?"),confirm_fun:async()=>{await a.jV.post("sessions/clear",{}),$(""),t([]),await fe(null)}})}}),ne(l.oV.ai_agent_setting)&&(0,w.jsx)(c.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{le(`/${p.o.ai_rebot_setting_page}`)}}),ne(l.oV.ai_agent_setting)&&(0,w.jsx)(c.rA,{icon:"settings",title:"ai setting",onClick:()=>{le(`/${p.o.ai_agent_setting_page}`)}})]}),(0,w.jsxs)("div",{className:"chat-page chat-page-with-sessions",children:[O&&(0,w.jsx)("div",{className:"chat-session-overlay",onClick:()=>F(!1)}),(0,w.jsx)(S,{sessions:s,activeSessionId:C,onSelectSession:e=>ve(e,!1),onRenameSession:(e,t)=>{let s=t;re({confirm_fun:async()=>{await a.jV.post("sessions/update/meta",{id:e,title:s}),await fe(C)},context_div:(0,w.jsx)("div",{className:"card-content",children:(0,w.jsx)(v.Sm,{value:s,handleInputChange:e=>s=e})})})},onDeleteSession:e=>{re({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{await a.jV.post("session/delete",{session_id:e}),C===e?($(""),await fe(null)):await fe(C)}})},onShowUsageStats:async e=>{W({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsx)("div",{className:"usage-stats-loading",children:T("加载中...")}),cancel:()=>W({open:!1})});try{const t=await a.jV.post("session/usage_stats",{session_id:e});if(t.code===g.m.Success&&t.data){const e=t.data;W({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsxs)("div",{className:"usage-stats-panel",children:[[{l:T("对话轮次"),v:(e.turns??0).toString()},{l:T("AI输入字符"),v:Se(e.input_chars)},{l:T("AI输出字符"),v:Se(e.output_chars)},{l:T("AI输入字符(最近一轮)"),v:Se(e.recent_input_chars)},{l:T("AI输出字符(最近一轮)"),v:Se(e.recent_output_chars)}].map((e,t)=>(0,w.jsxs)("div",{className:"usage-stats-row",children:[(0,w.jsx)("span",{className:"usage-stats-label",children:e.l}),(0,w.jsx)("span",{className:"usage-stats-value",children:e.v})]},t)),(0,w.jsxs)("div",{className:"usage-stats-row usage-stats-total",children:[(0,w.jsx)("span",{className:"usage-stats-label",children:T("AI字符总计消耗")}),(0,w.jsx)("span",{className:"usage-stats-value",children:Se((e.input_chars||0)+(e.output_chars||0))})]})]}),cancel:()=>W({open:!1})})}else W({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsx)("div",{className:"usage-stats-empty",children:T("暂无统计数据")}),cancel:()=>W({open:!1})})}catch{W({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsx)("div",{className:"usage-stats-empty",children:T("暂无统计数据")}),cancel:()=>W({open:!1})})}},batchMode:G,selectedSessionIds:Q,onToggleSessionSelect:e=>{Y(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})}}),(0,w.jsxs)("section",{className:"chat-main",children:[0===e?.length&&(0,w.jsx)("div",{className:"chat-header",children:(0,w.jsx)("div",{children:"completions"===z?T("询问服务器的一切"):M.find(e=>e.value===z)?.label??z})}),(0,w.jsxs)("div",{className:"chat-messages",ref:ce,children:[e.map(s=>(0,w.jsxs)("div",{className:`chat-message ${s.sender} ${G?"batch-mode":""}`,children:[G&&(0,w.jsx)("input",{type:"checkbox",className:"chat-message-checkbox",checked:X.has(s.id),onChange:()=>{return e=s.id,void Z(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s});var e}}),D(s),!G&&(0,w.jsxs)("div",{className:"message-actions",children:[(0,w.jsx)("button",{onClick:()=>{return n=s.id,void re({sub_title:T("确认删除这条消息吗?"),confirm_fun:()=>{const s=e.filter(e=>e.id!==n);t(s),C&&a.jV.post("session/messages",{session_id:C,messages:B(s)}).catch(console.error)}});var n},children:T("删除")}),(0,w.jsx)("button",{onClick:()=>(async e=>{(0,d.lW)(e),(0,u.SK)("复制成功")})(s.text),children:T("复制")})]})]},s.id)),(0,w.jsx)("div",{ref:oe})]}),(0,w.jsx)(N,{inputValue:ae,onInputChange:e=>{const t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px",ie(t.value)},onKeyDown:e=>{"Process"===e.key||e.nativeEvent.isComposing||e.shiftKey||e.ctrlKey||"Enter"===e.key&&(e.preventDefault(),we())},onPaste:e=>{const t=e.clipboardData?.files;t&&t.length>0&&(e.preventDefault(),_e(t))},onSend:we,sending:te,pendingAttachments:V,onRemoveAttachment:e=>{J(t=>t.filter((t,s)=>s!==e))},onOpenFilePicker:()=>{K.current?.click()},onAddFiles:_e,onDrop:e=>{const t=e.dataTransfer?.files;t&&t.length>0&&(e.preventDefault(),_e(t))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:K})]})]})]})}},96494(e,t,s){s.d(t,{r:()=>a});var n=s(22022);function a(){const{t:e}=(0,n.Bd)();return[{value:"completions",label:e("文本对话")},{value:"images",label:e("图片生成")}]}},72693(e,t,s){s.d(t,{w:()=>u});var n=s(96540),a=s(22022),i=s(14944),o=s(92275),c=s(34843),r=s(82893),l=s(85997),d=s(74848);function u(){const[e,t]=(0,c.fp)(r.AG.prompt_card),{t:s}=(0,a.Bd)(),u=(0,n.useRef)([]),m=(0,n.useRef)(!1),h=(0,n.useCallback)(()=>{if(m.current)return;if(0===u.current.length)return m.current=!1,void t({open:!1});m.current=!0;const e=u.current.shift();e?t({open:!0,title:s("命令确认"),cancel:()=>{i.ws.sendData(o.HK.ai_confirm_cmd,{askId:e.askId,approved:!1}),t({open:!1}),m.current=!1,h()},context_div:(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{maxHeight:"60vh",overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--surfaceSecondary)",padding:"0.75em",borderRadius:"0.5em",marginBottom:"0.75em",fontFamily:"monospace",fontSize:"0.9em",lineHeight:"1.5"},children:e.cmd}),(0,d.jsxs)("div",{style:{display:"flex",gap:"0.5em",justifyContent:"flex-end"},children:[(0,d.jsx)(l.$n,{text:s("拒绝"),color:"var(--red)",clickFun:()=>{i.ws.sendData(o.HK.ai_confirm_cmd,{askId:e.askId,approved:!1}),t({open:!1}),m.current=!1,h()}}),(0,d.jsx)(l.$n,{text:s("允许"),clickFun:()=>{i.ws.sendData(o.HK.ai_confirm_cmd,{askId:e.askId,approved:!0}),t({open:!1}),m.current=!1,h()}})]})]})}):m.current=!1},[s]),g=(0,n.useCallback)(e=>{u.current.push(e),h()},[h]);(0,n.useEffect)(()=>(i.ws.addMsg(o.HK.ai_confirm_cmd,e=>{const t=e.context||{};t.askId&&t.cmd&&g({askId:t.askId,cmd:t.cmd})}),()=>{i.ws.removeMsg(o.HK.ai_confirm_cmd)}),[g]),(0,n.useEffect)(()=>()=>{u.current=[],m.current=!1},[])}},34299(e,t,s){s.r(t),s.d(t,{default:()=>p});s(96540);var n=s(73557),a=s(53995),i=s(18569),o=s(77979),c=s(8263),r=s(69428),l=s.n(r),d=(s(3775),s(21499)),u=s(99214),m=s(19878),h=(s(72411),s(74848));const g=new n.A({html:!0,highlight:function(e,t){if(t&&m.A.getLanguage(t))try{return`<pre class="hljs code-block-with-copy"><code class="hljs language-${t}">${m.A.highlight(e,{language:t}).value}</code></pre>`}catch(e){}try{return`<pre class="hljs code-block-with-copy"><code class="hljs">${m.A.highlightAuto(e).value}</code></pre>`}catch(e){}return`<pre class="hljs code-block-with-copy"><code>${g.utils.escapeHtml(e)}</code></pre>`}});function p(e){return(0,u.VD)(),(0,h.jsx)("div",{dangerouslySetInnerHTML:{__html:g.render(e.context)}})}g.use(a.A).use(i.A).use(o.A).use(c.A).use(l()).use(e=>{e.renderer.rules.fence;e.renderer.rules.fence=(t,s,n,a,i)=>{const o=t[s],c=o.content.trim(),r=o.info.trim();let l="";if(r&&m.A.getLanguage(r))try{l=m.A.highlight(c,{language:r}).value}catch(t){l=e.utils.escapeHtml(c)}else try{l=m.A.highlightAuto(c).value}catch(t){l=e.utils.escapeHtml(c)}return`\n <div class="code-block-with-copy">\n <div class="code-header">\n <span class="code-language">${r||"code"}</span>\n <button class="copy-btn" data-code="${e.utils.escapeHtml(c)}">复制</button>\n </div>\n <pre><code class="hljs ${r?`language-${r}`:""}">${l}</code></pre>\n </div>`}}).use(e=>{const t=e.renderer.rules.link_open||function(e,t,s,n,a){return a.renderToken(e,t,s)};e.renderer.rules.link_open=(e,s,n,a,i)=>{const o=e[s],c=o.attrIndex("href");if(c>=0){const e=o.attrs[c][1];o.attrs[c][1]=(0,d.bi)(window.location.href,e)}return t(e,s,n,a,i)}})},45907(e,t,s){s.d(t,{y:()=>i});var n=s(34843),a=s(82893);function i(){const[e,t]=(0,n.fp)(a.AG.confirm);return({sub_title:e,confirm_fun:s,title:n,context_div:a})=>{t({open:!0,sub_title:e,handle:()=>{s(),t({open:!1,handle:null})},title:n,context_div:a})}}},60840(e){e.exports="data:image/svg+xml,<svg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 version=%271.1%27 aria-hidden=%27true%27><path fill-rule=%27evenodd%27 d=%27M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z%27></path></svg>"}}]);
1
+ "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[6010,9782],{83277(e,t,s){s.d(t,{$j:()=>c,Lv:()=>a,qq:()=>i});class n{options_agent_url_list;options_agent_key_list;options_agent_model_list}class a{token;open=!1;note;index;url;model;request_type;json_params;sys_prompt;dotenv="";tool_mode=!1;show_options;static get_label_by_v(e,t){if(!e||!t?.length)return e;for(const s of t)if(s.value===e)return s.label;return e}static have_label_by_v(e,t){if(!e||!t?.length)return!1;for(const s of t)if(s.value===e)return!0;return!1}}class i extends n{tool_error_max=50;tool_call_max=300;allow_exec_cmd_directly=!1;proxy_url}const o=JSON.stringify({stream:!0,thinking:{type:"disabled"}});function c(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>"text"===e.type?e.text:"[图片]").join("\n"):""}s.d(t,["CP",0,'\n\n# 工具报错最大尝试次数\ntool_error_max=50\n# 聊天循环最大次数\ntool_call_max=300\n# 是否允许AI直接执行命令而不需要用户确认,默认为false,需要用户手动确认,如果使用 workflow 这里等价于为 true\nallow_exec_cmd_directly=false\n\n# 可选的代理 url,如果指定了所有访问大模型的请求将会走代理\n#proxy_url=\n\n# 可选的多个url 以数组分割\n# options_agent_url_list=[{"value":"http://..","label":"openai"}]\n\n# 可选的多个 key\n# options_agent_key_list=[{"value":"sh-aaa","label":"option1"}]\n\n# 可选的多个 model\n# options_agent_model_list=[{"value":"gpt-5.5","label":"gpt"}]\n\n',"cL",0,o])},86271(e,t,s){s.r(t),s.d(t,{default:()=>M});var n=s(96540),a=s(14284),i=s(7463),o=s(57952),c=s(85997),r=s(78247),l=s(23430),d=s(40505),u=s(62042),m=s(22022),h=s(45907),g=s(53459),p=s(87361),x=s(52671),_=s(34843),f=s(82893),j=s(27690),v=s(61443),y=s(72693),b=s(83277),w=s(74848);function S({sessions:e,activeSessionId:t,onSelectSession:s,onRenameSession:a,onDeleteSession:i,onShowUsageStats:o,batchMode:r,selectedSessionIds:l,onToggleSessionSelect:d}){const{t:u}=(0,m.Bd)(),[h,g]=(0,_.fp)(f.AG.ai_session_collapsed),[p,x]=(0,n.useState)(""),v=p.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(p.toLowerCase())||(e.summary||"").toLowerCase().includes(p.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(p.toLowerCase())):e;return(0,w.jsxs)("aside",{className:`chat-session-list ${h?"active":""} ${h?"collapsed":""}`,children:[!h&&(0,w.jsx)("div",{className:"chat-session-search",children:(0,w.jsx)("input",{type:"text",className:"chat-session-search-input",placeholder:u("搜索会话"),value:p,onChange:e=>x(e.target.value)})}),v.map(e=>{return(0,w.jsx)("div",{children:(0,w.jsxs)("button",{className:`chat-session-item ${t===e.id?"active":""} ${r?"batch-mode":""}`,onClick:()=>{r&&d?d(e.id):s(e.id)},title:e.summary||e.long_term_memory||e.title,children:[r&&(0,w.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:l?.has(e.id)??!1,onChange:()=>d?.(e.id),onClick:e=>e.stopPropagation()}),(0,w.jsx)("span",{children:(n=e.title,n||"新会话")}),(0,w.jsx)("small",{children:e.message_count}),"web"!==e.source&&(0,w.jsx)("em",{className:"chat-session-source",children:e.source}),!r&&(0,w.jsx)(j.MenuSelect,{list:[{name:u("重命名"),click:()=>a(e.id,e.title)},{name:u("字符消耗统计"),click:()=>o(e.id)},{name:u("删除"),click:()=>i(e.id)}],children:(0,w.jsx)(c.In,{icon:"more_horiz"})})]})},e.id);var n})]})}function k({pendingAttachments:e,onRemove:t}){return 0===e.length?null:(0,w.jsx)("div",{className:"chat-attachment-strip",children:e.map((e,s)=>(0,w.jsxs)("div",{className:"chat-attachment-chip",children:[(0,w.jsx)(c.In,{icon:"attach_file"}),(0,w.jsx)("span",{title:e.name,children:e.name}),(0,w.jsx)("button",{type:"button",onClick:()=>t(s),children:(0,w.jsx)(c.In,{icon:"close"})})]},`${e.name}_${s}`))})}function N({inputValue:e,onInputChange:t,onKeyDown:s,onPaste:n,onSend:a,sending:i,pendingAttachments:o,onRemoveAttachment:r,onOpenFilePicker:l,onAddFiles:d,onDrop:u,onDragOver:h,fileInputRef:g}){const{t:p}=(0,m.Bd)();return(0,w.jsxs)("div",{className:"chat-input-area",onDrop:u,onDragOver:h,children:[(0,w.jsx)("input",{ref:g,type:"file",multiple:!0,style:{display:"none"},onChange:e=>{e.target.files?.length&&(d(e.target.files),e.currentTarget.value="")}}),(0,w.jsxs)("div",{className:"chat-input-shell",children:[(0,w.jsx)(k,{pendingAttachments:o,onRemove:r}),(0,w.jsx)("textarea",{value:e,onChange:t,onPaste:n,onKeyDown:s,placeholder:p("输入消息"),className:"chat-input"})]}),(0,w.jsx)(c.rA,{title:p("添加文件"),icon:"attach_file",onClick:l}),!1===i?(0,w.jsx)(c.Vi,{text:p("发送"),clickFun:a}):(0,w.jsx)("div",{className:"ai-thinking-indicator",children:(0,w.jsxs)("div",{className:"ai-thinking-dots",children:[(0,w.jsx)("div",{className:"ai-thinking-dot"}),(0,w.jsx)("div",{className:"ai-thinking-dot"}),(0,w.jsx)("div",{className:"ai-thinking-dot"})]})})]})}var A=s(96494);function C(){try{const e=localStorage.getItem("ai_images_extra_params");if(e)return JSON.parse(e)}catch{}return{size:"1024x1024",n:1}}function $({onClose:e}){const{t}=(0,m.Bd)(),[s,a]=(0,n.useState)(C),[i,o]=(0,n.useState)(s.size||"1024x1024"),[r,l]=(0,n.useState)(String(s.n??1)),[d,u]=(0,n.useState)(s.quality||""),[h,g]=(0,n.useState)(s.style||""),[p,x]=(0,n.useState)(s.extra_json||"");return(0,w.jsxs)("div",{className:"card images-params-card",children:[(0,w.jsx)("h3",{children:t("图片生成参数设置")}),(0,w.jsx)("p",{className:"images-params-hint",children:"不同模型支持的参数不同,请参考模型文档。常见 size 值: 1024x1024, 1792x1024, 1024x1792 (DALL-E 3)"}),(0,w.jsxs)("div",{className:"images-params-fields",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:"size (图片尺寸)"}),(0,w.jsx)(v.Sm,{value:i,handleInputChange:o,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:"n (生成数量)"}),(0,w.jsx)(v.Sm,{value:r,handleInputChange:l,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:'quality (画质, 如 "standard" / "hd")'}),(0,w.jsx)(v.Sm,{value:d,handleInputChange:u,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:'style (风格, 如 "vivid" / "natural")'}),(0,w.jsx)(v.Sm,{value:h,handleInputChange:g,no_border:!1})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{children:"额外参数 (JSON,会合并到请求体中)"}),(0,w.jsx)(v.Sm,{value:p,handleInputChange:x,no_border:!1})]})]}),(0,w.jsxs)("div",{className:"images-params-actions",children:[(0,w.jsx)(c.rA,{icon:"close",title:t("取消"),onClick:e}),(0,w.jsx)(c.rA,{icon:"save",title:t("保存"),onClick:()=>{const t={size:i,n:parseInt(r)||1};d&&(t.quality=d),h&&(t.style=h),p&&(t.extra_json=p),function(e){localStorage.setItem("ai_images_extra_params",JSON.stringify(e))}(t),e()}})]})]})}function I(){const{t:e}=(0,m.Bd)(),[t,s]=(0,_.fp)(f.AG.ai_request_type),[a,i]=(0,n.useState)(!1),o=(0,A.r)(),c=o.find(e=>e.value===t)??o[0];return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(j.MenuSelect,{list:[...o.map(e=>({name:e.label,click:()=>s(e.value)})),..."images"===t?[{name:e("图片参数设置"),click:()=>i(!0)}]:[],..."audio_speech"===t?[{name:e("语音参数设置"),click:()=>{const t=localStorage.getItem("ai_audio_extra_params"),s=t?JSON.parse(t):{},n=s.voice||"alloy",a=s.speed||"1.0",i=prompt(e("输入 voice (如 alloy, echo, fable, onyx, nova, shimmer)"),n);if(null!==i){const t=prompt(e("输入 speed (0.25 ~ 4.0)"),a);null!==t&&localStorage.setItem("ai_audio_extra_params",JSON.stringify({voice:i,speed:parseFloat(t)||1}))}}}]:[]],children:(0,w.jsxs)("div",{className:"menu-select-trigger",children:[(0,w.jsx)("span",{children:c.label}),(0,w.jsx)("span",{className:"menu-select-arrow",children:"▾"})]})}),a&&(0,w.jsx)("div",{className:"modal-overlay",onClick:()=>i(!1),children:(0,w.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,w.jsx)($,{onClose:()=>i(!1)})})})]})}var O=s(34299);function D(e){const t=e.attachments&&e.attachments.length>0?(0,w.jsx)("div",{className:"chat-message-attachments",children:e.attachments.map((e,t)=>(0,w.jsxs)("div",{className:"chat-message-attachment",children:[(0,w.jsx)(c.In,{icon:"attach_file"}),(0,w.jsx)("span",{children:e.name}),(0,w.jsxs)("small",{children:[e.size," B"]})]},`${e.name}_${t}`))}):null,s=[];return e.images&&"bot"===e.sender&&s.push((0,w.jsx)(n.Fragment,{children:(0,w.jsx)(F,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&s.push((0,w.jsx)(n.Fragment,{children:(0,w.jsx)(V,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&s.push((0,w.jsx)(n.Fragment,{children:(0,w.jsx)(z,{embeddings:e.embeddings,text:e.text})},"embeddings")),0===s.length?(0,w.jsxs)(w.Fragment,{children:[t,(0,w.jsx)(O.default,{context:e.text})]}):(0,w.jsxs)(w.Fragment,{children:[s,t,e.text&&(0,w.jsx)(O.default,{context:e.text})]})}function F({images:e,text:t}){let s=e||[];if(!s.length&&t)try{s=JSON.parse(t).data||[]}catch{}return s.length?(0,w.jsxs)("div",{className:"image-generation-result",children:[s.map((e,t)=>(0,w.jsxs)("div",{className:"image-generation-item",children:[e.url&&(0,w.jsx)("div",{className:"image-generation-image-wrapper",children:(0,w.jsx)("img",{src:e.url,alt:e.revised_prompt||`生成的图片 ${t+1}`,loading:"lazy"})}),e.b64_json&&(0,w.jsx)("div",{className:"image-generation-image-wrapper",children:(0,w.jsx)("img",{src:`data:image/png;base64,${e.b64_json}`,alt:`生成的图片 ${t+1}`})}),e.revised_prompt&&(0,w.jsx)("p",{className:"image-generation-prompt",children:(0,w.jsx)("small",{children:e.revised_prompt})})]},t)),t&&!e&&(0,w.jsx)(O.default,{context:t})]}):(0,w.jsx)(O.default,{context:t||""})}function V({audio:e,text:t}){if(e){if(e.url)return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:e.url,children:"您的浏览器不支持音频播放"})});if(e.data){const t=e.mime_type||"audio/mpeg";return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:`data:${t};base64,${e.data}`,children:"您的浏览器不支持音频播放"})})}}const s=t||"";if(s.startsWith("http://")||s.startsWith("https://"))return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:s,children:"您的浏览器不支持音频播放"})});try{const e=JSON.parse(s);if(e?.data||e?.audio_data){const t=e.data||e.audio_data;return(0,w.jsx)("div",{className:"audio-result",children:(0,w.jsx)("audio",{controls:!0,src:`data:audio/mpeg;base64,${t}`,children:"您的浏览器不支持音频播放"})})}}catch{}return(0,w.jsx)(O.default,{context:s})}function J({content:e,label:t}){const[s,a]=n.useState(!1);return(0,w.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,d.lW)(e),a(!0),setTimeout(()=>a(!1),1500)},children:[(0,w.jsx)(c.In,{icon:s?"check":"content_copy"}),s?"已复制":t||"复制"]})}function z({embeddings:e,text:t}){let s=e||null;if(!s&&t)try{s=JSON.parse(t)}catch{return(0,w.jsx)(O.default,{context:t})}if(!s)return(0,w.jsx)(O.default,{context:t||""});const n=s?.data||[],a=s?.usage,i=JSON.stringify(s,null,2);return(0,w.jsxs)("div",{className:"embeddings-result",children:[(0,w.jsxs)("div",{className:"embeddings-summary",children:[(0,w.jsx)("strong",{children:"向量嵌入结果"}),(0,w.jsxs)("span",{children:["维度: ",n[0]?.embedding?.length??"N/A"]}),(0,w.jsxs)("span",{children:["数量: ",n.length]}),a&&(0,w.jsxs)("span",{children:["使用 tokens: ",a.total_tokens??"N/A"]})]}),(0,w.jsxs)("div",{className:"embeddings-toolbar",children:[(0,w.jsx)(J,{content:i,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,w.jsx)(J,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,w.jsx)(J,{content:JSON.stringify(n.map(e=>e.embedding),null,2),label:"复制所有向量数据"})]}),n.length>0&&n[0]?.embedding&&(0,w.jsx)("div",{className:"embeddings-preview",children:(0,w.jsxs)("span",{children:["向量预览: [",n[0].embedding.slice(0,5).join(", "),n[0].embedding.length>5?", ...":"","]"]})}),n.length>0&&(0,w.jsxs)("details",{children:[(0,w.jsx)("summary",{children:"查看详细数据"}),(0,w.jsx)("pre",{className:"embeddings-raw",children:i})]})]})}async function R(e,t){const s=function(){try{const e=localStorage.getItem("ai_images_extra_params");if(e)return JSON.parse(e)}catch{}return{}}(),n={prompt:e,n:s.n??1,size:s.size??"1024x1024",session_id:t};if(s.quality&&(n.quality=s.quality),s.style&&(n.style=s.style),s.extra_json)try{const e=JSON.parse(s.extra_json);Object.assign(n,e)}catch(e){console.warn("图片额外参数 JSON 解析失败:",e)}const i=await a.jV.post("images/generations",n);if(0!==i.code)throw new Error(i.message||"图片生成失败");const o=i.data||{},c=(o.data||[]).map(e=>({url:e.url,b64_json:e.b64_json,revised_prompt:e.revised_prompt})),r=c.map((e,t)=>`![生成图片${t+1}](${e.url||`data:image/png;base64,${e.b64_json}`})${e.revised_prompt?`\n> ${e.revised_prompt}`:""}`).join("\n\n");return{session_id:o.session_id||t,images:c,text:r||`生成了 ${c.length} 张图片`}}async function q(e,t,s,n){try{switch(e){case"images":{const e=await R(t,s);return e&&n(e.text,{images:e.images}),!0}case"audio_speech":{const e=await async function(e,t){const s={input:e,session_id:t};try{const e=localStorage.getItem("ai_audio_extra_params");if(e){const t=JSON.parse(e);t.voice&&(s.voice=t.voice),t.speed&&(s.speed=parseFloat(t.speed))}}catch{}const n=localStorage.getItem("token")||"",a=await fetch("/api/ai_agent/audio/speech",{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(s)});if(!a.ok)throw new Error(`语音合成失败: ${a.statusText}`);const i=a.headers.get("X-Session-Id")||t,o=await a.arrayBuffer();return{session_id:i,audio:{data:btoa(String.fromCharCode(...Array.from(new Uint8Array(o)))),mime_type:a.headers.get("content-type")||"audio/mpeg"},text:`[音频文件: ${e.slice(0,50)}...]`}}(t,s);return e&&n(e.text,{audio:e.audio}),!0}case"embeddings":{const e=await async function(e,t){const s=await a.jV.post("embeddings",{input:e,session_id:t});if(0!==s.code)throw new Error(s.message||"Embeddings 请求失败");const n=s.data||{},i=n?.data??[],o=`向量维度: ${i[0]?.embedding?.length??0}, 数量: ${i.length}`;return{session_id:n.session_id||t,embeddings:n,text:`✅ Embeddings 结果 - ${o}\n\`\`\`json\n${JSON.stringify(n,null,2).slice(0,2e3)}\n\`\`\``}}(t,s);return e&&n(e.text,{embeddings:e.embeddings}),!0}default:return!1}}catch(e){return n(`请求失败: ${e?.message||JSON.stringify(e)}`),!0}}function H(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||/\.(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.test(e.name)?"text":"binary"}function L(e){return e.text()}function E(e){return new Promise((t,s)=>{const n=new FileReader;n.onload=()=>t(n.result),n.onerror=s,n.readAsDataURL(e)})}function B(e){return e.map(e=>({role:"bot"===e.sender?"assistant":"user",content:e.text,attachments:e.attachments??[],images:e.images,audio:e.audio,embeddings:e.embeddings}))}function M(){const[e,t]=(0,n.useState)([]),[s,k]=(0,n.useState)([]),[C,$]=(0,n.useState)(""),[O,F]=(0,_.fp)(f.AG.ai_session_collapsed),[V,J]=(0,n.useState)([]),[z,R]=(0,_.fp)(f.AG.ai_request_type);(0,y.w)();const M=(0,A.r)(),{t:T}=(0,m.Bd)(),K=(0,n.useRef)(null),[P,G]=(0,_.fp)(f.AG.prompt_card),[W,U]=(0,n.useState)(!1),[X,Z]=(0,n.useState)(new Set),[Q,Y]=(0,n.useState)(new Set),ee=(0,n.useRef)((0,i.sg)(e=>{t(e),de.current&&xe(!1)},50)).current,[te,se]=(0,n.useState)(!1),{check_user_auth:ne}=(0,r.MH)(),[ae,ie]=(0,n.useState)(""),oe=(0,n.useRef)(null),ce=(0,n.useRef)(null),re=(0,h.y)(),le=(0,x.Zp)(),de=(0,n.useRef)(!0),ue=(0,n.useRef)(new b.qq),[me,he]=(0,n.useState)([]),[ge,pe]=(0,n.useState)(""),xe=(e=!1)=>{const t=ce.current;t&&t.scrollTo({top:t.scrollHeight,behavior:e?"smooth":"auto"})},_e=e=>{const t=Array.from(e??[]).filter(Boolean);t.length&&J(e=>[...e,...t])},fe=async e=>{const s=await a.jV.get("sessions");if(s.code!==g.m.Success)return;const n=s.data??[];k(n);const i=null===e?n[0]?.id??"":e||C||n[0]?.id||"";i?await ve(i):(t([]),$(""))},je=async()=>{const e=await a.jV.get("sessions");e.code===g.m.Success&&k(e.data??[])},ve=async(e,s=!1)=>{const n=await a.jV.post("session/get",{session_id:e});if(n.code!==g.m.Success||!n.data)return;const i=n.data;$(i.id),t(function(e=[]){return e.filter(e=>"user"===e.role||"assistant"===e.role).map((e,t)=>({id:Date.now()+t,sender:"assistant"===e.role?"bot":"user",text:(0,b.$j)(e.content),attachments:e.attachments??[],images:e.images,audio:e.audio,embeddings:e.embeddings}))}(i.messages)),s&&F(!1),requestAnimationFrame(()=>xe(!1))},ye=async e=>{const s=await a.jV.post("session",{title:"新会话"});if(s.code!==g.m.Success)return;const n=s.data;$(n.id),e?(ie(e),t([])):t([]),F(!1),await fe(n.id),requestAnimationFrame(()=>{const e=document.querySelector(".chat-input");e&&(e.style.height="auto",e.style.height=Math.min(e.scrollHeight,200)+"px")})};(0,n.useEffect)(()=>{(async()=>{const e=await a.XO.get("ai_agent_setting/env");if(e.code===g.m.Success){ue.current=e.data;const t=e.data.current_model_note||"",s=(e.data.options_agent_model_list??[]).find(e=>e.label===t);pe(s?s.value:t)}await fe();const t=await a.jV.get("system_prompts");t.code===g.m.Success&&he(t.data??[])})(),requestAnimationFrame(()=>{xe(!1)})},[]),(0,n.useEffect)(()=>{const e=ce.current;if(!e)return;const t=()=>{de.current=((e,t=120)=>{const{scrollTop:s,scrollHeight:n,clientHeight:a}=e;return n-(s+a)<t})(e)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.useLayoutEffect)(()=>{de.current&&xe(!1)},[e]);const be=e=>{const t=(e.attachments??[]).filter(e=>"image"===e.kind);if(t.length>0){const s=[];e.text&&s.push({type:"text",text:e.text});for(const e of t)s.push({type:"image_url",image_url:{url:e.content}});return[{content:s,role:"user",attachments:e.attachments??[]}]}return[{content:e.text,role:"bot"===e.sender?"assistant":"user",attachments:e.attachments??[]}]},we=async()=>{const s=ae.trim();if(te||!s&&0===V.length)return;let n=C;if(!n){const e=await a.jV.post("session",{title:(s||V[0]?.name||"新会话").slice(0,28)});if(e.code!==g.m.Success)return;n=e.data.id,$(n),await fe(n)}const o=await(async e=>{const t=[];for(const s of e){const e=H(s);let n="";if("text"===e)try{const e=await L(s),t=12e4;n=e.length>t?`${e.slice(0,t)}\n\n[内容已截断,原始长度 ${e.length} 字符]`:e}catch{n="[文本读取失败]"}else if("image"===e)try{n=await E(s)}catch{n=`[图片文件: ${s.name}]`}else n=`[二进制文件: ${s.name}]`;t.push({name:s.name,mime_type:s.type,size:s.size,kind:e,content:n})}return t})(V),c={id:Date.now(),sender:"user",text:s,attachments:o},r=[...e,c];if(t(r),ie(""),J([]),se(!0),"completions"!==z){const e={id:c.id+1,sender:"bot",text:"处理中..."};r.push(e),t([...r]);return void(await q(z,s,n,async(s,n)=>{e.text=s,n?.images&&(e.images=n.images),n?.audio&&(e.audio=n.audio),n?.embeddings&&(e.embeddings=n.embeddings),t([...r]),se(!1),je(),xe(!0)})||(e.text=`请求类型 "${z}" 的专用处理器尚未实现,请使用 completions 类型。`,t([...r]),se(!1)))}const l={id:c.id+1,sender:"bot",text:"AI思考中..."};r.push(l),t([...r]);let d=!0;a.jV.sse_post("chat",{messages:be(c),session_id:n},{onMessage:e=>{d&&(l.text="",d=!1);try{const t=JSON.parse(e),s="string"==typeof t?t:t?.choices?.[0]?.delta?.content??t?.choices?.[0]?.message?.content;s&&(l.text+=s)}catch(t){try{l.text+=JSON.parse(e)}catch(t){l.text+=e}}ee([...r])},onDone:(0,i.nF)(async()=>{se(!1),await je(),xe(!0)},100)})},Se=e=>null==e||e<0?"0":e.toLocaleString();return(0,w.jsxs)(n.Fragment,{children:[(0,w.jsxs)(o.A,{children:[(0,w.jsx)(c.rA,{icon:"menu",title:T("会话"),onClick:()=>{window.innerWidth<=736?F(!0):F(e=>!e)}}),(0,w.jsx)(c.rA,{icon:"add",title:T("新会话"),onClick:()=>ye()}),me.length>0&&(0,w.jsx)(j.MenuSelect,{list:me.map((e,t)=>({name:e.note||`${T("提示词")} ${t+1}`,click:()=>{e.prompt&&ye(e.prompt)}})),children:(0,w.jsx)(c.rA,{icon:"add_comment",title:T("提示词模板创建会话")})}),(0,w.jsx)(I,{}),(ue.current?.options_agent_model_list?.length??0)>0&&(0,w.jsx)(v.l6,{value:ge,options:ue.current.options_agent_model_list?.map(e=>({title:e.label,value:e.value}))??[],onChange:e=>{pe(e),a.jV.post("set_active_model",{model_name:e}).then(()=>{(0,u.SK)("success"),a.XO.get("ai_agent_setting/env").then(e=>{e.code===g.m.Success&&(ue.current=e.data)})}).catch(console.error)},no_border:!0,width:"auto"}),(0,w.jsx)(c.rA,{icon:W?"check_circle":"checklist",title:T(W?"取消批量选择":"批量选择"),onClick:()=>{W&&(Z(new Set),Y(new Set)),U(e=>!e)}}),W&&X.size>0&&(0,w.jsx)(c.rA,{icon:"delete",title:T("删除选中消息"),onClick:()=>{0!==X.size&&re({sub_title:T("确认删除选中的聊天消息吗?"),confirm_fun:()=>{const s=e.filter(e=>!X.has(e.id));t(s),Z(new Set),U(!1),C&&s.length!==e.length&&a.jV.post("session/messages",{session_id:C,messages:B(s)}).catch(console.error)}})}}),W&&Q.size>0&&(0,w.jsx)(c.rA,{icon:"delete",title:T("删除选中会话"),onClick:()=>{0!==Q.size&&re({sub_title:T("确认删除选中的会话吗?"),confirm_fun:async()=>{for(const e of Q)await a.jV.post("session/delete",{session_id:e});Y(new Set),U(!1),Q.has(C)?($(""),await fe(null)):await fe(C)}})}}),(0,w.jsx)(c.rA,{icon:"delete_sweep",title:T("清空全部会话"),onClick:()=>{re({sub_title:T("确认删除全部聊天会话吗?"),confirm_fun:async()=>{await a.jV.post("sessions/clear",{}),$(""),t([]),await fe(null)}})}}),ne(l.oV.ai_agent_setting)&&(0,w.jsx)(c.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{le(`/${p.o.ai_rebot_setting_page}`)}}),ne(l.oV.ai_agent_setting)&&(0,w.jsx)(c.rA,{icon:"settings",title:"ai setting",onClick:()=>{le(`/${p.o.ai_agent_setting_page}`)}})]}),(0,w.jsxs)("div",{className:"chat-page chat-page-with-sessions",children:[O&&(0,w.jsx)("div",{className:"chat-session-overlay",onClick:()=>F(!1)}),(0,w.jsx)(S,{sessions:s,activeSessionId:C,onSelectSession:e=>ve(e,!1),onRenameSession:(e,t)=>{let s=t;re({confirm_fun:async()=>{await a.jV.post("sessions/update/meta",{id:e,title:s}),await fe(C)},context_div:(0,w.jsx)("div",{className:"card-content",children:(0,w.jsx)(v.Sm,{value:s,handleInputChange:e=>s=e})})})},onDeleteSession:e=>{re({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{await a.jV.post("session/delete",{session_id:e}),C===e?($(""),await fe(null)):await fe(C)}})},onShowUsageStats:async e=>{G({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsx)("div",{className:"usage-stats-loading",children:T("加载中...")}),cancel:()=>G({open:!1})});try{const t=await a.jV.post("session/usage_stats",{session_id:e});if(t.code===g.m.Success&&t.data){const e=t.data;G({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsxs)("div",{className:"usage-stats-panel",children:[[{l:T("对话轮次"),v:(e.turns??0).toString()},{l:T("AI输入字符"),v:Se(e.input_chars)},{l:T("AI输出字符"),v:Se(e.output_chars)},{l:T("AI输入字符(最近一轮)"),v:Se(e.recent_input_chars)},{l:T("AI输出字符(最近一轮)"),v:Se(e.recent_output_chars)}].map((e,t)=>(0,w.jsxs)("div",{className:"usage-stats-row",children:[(0,w.jsx)("span",{className:"usage-stats-label",children:e.l}),(0,w.jsx)("span",{className:"usage-stats-value",children:e.v})]},t)),(0,w.jsxs)("div",{className:"usage-stats-row usage-stats-total",children:[(0,w.jsx)("span",{className:"usage-stats-label",children:T("AI字符总计消耗")}),(0,w.jsx)("span",{className:"usage-stats-value",children:Se((e.input_chars||0)+(e.output_chars||0))})]})]}),cancel:()=>G({open:!1})})}else G({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsx)("div",{className:"usage-stats-empty",children:T("暂无统计数据")}),cancel:()=>G({open:!1})})}catch{G({open:!0,title:T("字符消耗统计"),context_div:(0,w.jsx)("div",{className:"usage-stats-empty",children:T("暂无统计数据")}),cancel:()=>G({open:!1})})}},batchMode:W,selectedSessionIds:Q,onToggleSessionSelect:e=>{Y(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s})}}),(0,w.jsxs)("section",{className:"chat-main",children:[0===e?.length&&(0,w.jsx)("div",{className:"chat-header",children:(0,w.jsx)("div",{children:"completions"===z?T("询问服务器的一切"):M.find(e=>e.value===z)?.label??z})}),(0,w.jsxs)("div",{className:"chat-messages",ref:ce,children:[e.map(s=>(0,w.jsxs)("div",{className:`chat-message ${s.sender} ${W?"batch-mode":""}`,children:[W&&(0,w.jsx)("input",{type:"checkbox",className:"chat-message-checkbox",checked:X.has(s.id),onChange:()=>{return e=s.id,void Z(t=>{const s=new Set(t);return s.has(e)?s.delete(e):s.add(e),s});var e}}),D(s),!W&&(0,w.jsxs)("div",{className:"message-actions",children:[(0,w.jsx)("button",{onClick:()=>{return n=s.id,void re({sub_title:T("确认删除这条消息吗?"),confirm_fun:()=>{const s=e.filter(e=>e.id!==n);t(s),C&&a.jV.post("session/messages",{session_id:C,messages:B(s)}).catch(console.error)}});var n},children:T("删除")}),(0,w.jsx)("button",{onClick:()=>(async e=>{(0,d.lW)(e),(0,u.SK)("复制成功")})(s.text),children:T("复制")})]})]},s.id)),(0,w.jsx)("div",{ref:oe})]}),(0,w.jsx)(N,{inputValue:ae,onInputChange:e=>{const t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px",ie(t.value)},onKeyDown:e=>{"Process"===e.key||e.nativeEvent.isComposing||e.shiftKey||e.ctrlKey||"Enter"===e.key&&(e.preventDefault(),we())},onPaste:e=>{const t=e.clipboardData?.files;t&&t.length>0&&(e.preventDefault(),_e(t))},onSend:we,sending:te,pendingAttachments:V,onRemoveAttachment:e=>{J(t=>t.filter((t,s)=>s!==e))},onOpenFilePicker:()=>{K.current?.click()},onAddFiles:_e,onDrop:e=>{const t=e.dataTransfer?.files;t&&t.length>0&&(e.preventDefault(),_e(t))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:K})]})]})]})}},96494(e,t,s){s.d(t,{r:()=>a});var n=s(22022);function a(){const{t:e}=(0,n.Bd)();return[{value:"completions",label:e("文本对话")},{value:"images",label:e("图片生成")}]}},72693(e,t,s){s.d(t,{w:()=>u});var n=s(96540),a=s(22022),i=s(14944),o=s(92275),c=s(34843),r=s(82893),l=s(85997),d=s(74848);function u(){const[e,t]=(0,c.fp)(r.AG.prompt_card),{t:s}=(0,a.Bd)(),u=(0,n.useRef)([]),m=(0,n.useRef)(!1),h=(0,n.useCallback)(()=>{if(m.current)return;if(0===u.current.length)return m.current=!1,void t({open:!1});m.current=!0;const e=u.current.shift();e?t({open:!0,title:s("命令确认"),cancel:()=>{i.ws.sendData(o.HK.ai_confirm_cmd,{askId:e.askId,approved:!1}),t({open:!1}),m.current=!1,h()},context_div:(0,d.jsxs)("div",{children:[(0,d.jsx)("div",{style:{maxHeight:"60vh",overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--surfaceSecondary)",padding:"0.75em",borderRadius:"0.5em",marginBottom:"0.75em",fontFamily:"monospace",fontSize:"0.9em",lineHeight:"1.5"},children:e.cmd}),(0,d.jsxs)("div",{style:{display:"flex",gap:"0.5em",justifyContent:"flex-end"},children:[(0,d.jsx)(l.$n,{text:s("拒绝"),color:"var(--red)",clickFun:()=>{i.ws.sendData(o.HK.ai_confirm_cmd,{askId:e.askId,approved:!1}),t({open:!1}),m.current=!1,h()}}),(0,d.jsx)(l.$n,{text:s("允许"),clickFun:()=>{i.ws.sendData(o.HK.ai_confirm_cmd,{askId:e.askId,approved:!0}),t({open:!1}),m.current=!1,h()}})]})]})}):m.current=!1},[s]),g=(0,n.useCallback)(e=>{u.current.push(e),h()},[h]);(0,n.useEffect)(()=>(i.ws.addMsg(o.HK.ai_confirm_cmd,e=>{const t=e.context||{};t.askId&&t.cmd&&g({askId:t.askId,cmd:t.cmd})}),()=>{i.ws.removeMsg(o.HK.ai_confirm_cmd)}),[g]),(0,n.useEffect)(()=>()=>{u.current=[],m.current=!1},[])}},34299(e,t,s){s.r(t),s.d(t,{default:()=>p});s(96540);var n=s(73557),a=s(53995),i=s(18569),o=s(77979),c=s(8263),r=s(69428),l=s.n(r),d=(s(3775),s(21499)),u=s(99214),m=s(19878),h=(s(72411),s(74848));const g=new n.A({html:!0,highlight:function(e,t){if(t&&m.A.getLanguage(t))try{return`<pre class="hljs code-block-with-copy"><code class="hljs language-${t}">${m.A.highlight(e,{language:t}).value}</code></pre>`}catch(e){}try{return`<pre class="hljs code-block-with-copy"><code class="hljs">${m.A.highlightAuto(e).value}</code></pre>`}catch(e){}return`<pre class="hljs code-block-with-copy"><code>${g.utils.escapeHtml(e)}</code></pre>`}});function p(e){return(0,u.VD)(),(0,h.jsx)("div",{dangerouslySetInnerHTML:{__html:g.render(e.context)}})}g.use(a.A).use(i.A).use(o.A).use(c.A).use(l()).use(e=>{e.renderer.rules.fence;e.renderer.rules.fence=(t,s,n,a,i)=>{const o=t[s],c=o.content.trim(),r=o.info.trim();let l="";if(r&&m.A.getLanguage(r))try{l=m.A.highlight(c,{language:r}).value}catch(t){l=e.utils.escapeHtml(c)}else try{l=m.A.highlightAuto(c).value}catch(t){l=e.utils.escapeHtml(c)}return`\n <div class="code-block-with-copy">\n <div class="code-header">\n <span class="code-language">${r||"code"}</span>\n <button class="copy-btn" data-code="${e.utils.escapeHtml(c)}">复制</button>\n </div>\n <pre><code class="hljs ${r?`language-${r}`:""}">${l}</code></pre>\n </div>`}}).use(e=>{const t=e.renderer.rules.link_open||function(e,t,s,n,a){return a.renderToken(e,t,s)};e.renderer.rules.link_open=(e,s,n,a,i)=>{const o=e[s],c=o.attrIndex("href");if(c>=0){const e=o.attrs[c][1];o.attrs[c][1]=(0,d.bi)(window.location.href,e)}return t(e,s,n,a,i)}})},45907(e,t,s){s.d(t,{y:()=>i});var n=s(34843),a=s(82893);function i(){const[e,t]=(0,n.fp)(a.AG.confirm);return({sub_title:e,confirm_fun:s,title:n,context_div:a})=>{t({open:!0,sub_title:e,handle:()=>{s(),t({open:!1,handle:null})},title:n,context_div:a})}}},60840(e){e.exports="data:image/svg+xml,<svg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 version=%271.1%27 aria-hidden=%27true%27><path fill-rule=%27evenodd%27 d=%27M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z%27></path></svg>"}}]);
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{{web_site_title}}}</title><link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"/><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"/><script defer="defer" src="main.ae79754dd56d4abb105c.js"></script></head><body><div id="root"></div></body><script id="pre_code" type="text/template">return {{{Windows_FileCat}}};</script><script>window.EXCALIDRAW_ASSET_PATH = "/";window.FileCat;</script></html>
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>{{{web_site_title}}}</title><link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"/><link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"/><script defer="defer" src="main.0efa49d69dc300ccfda6.js"></script></head><body><div id="root"></div></body><script id="pre_code" type="text/template">return {{{Windows_FileCat}}};</script><script>window.EXCALIDRAW_ASSET_PATH = "/";window.FileCat;</script></html>