filecat 7.3.3 → 7.3.5

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.
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[4472,6010],{83277(e,s,t){t.d(s,{$j:()=>i,Lv:()=>n});class n{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,s){if(!e||!s?.length)return e;for(const t of s)if(t.value===e)return t.label;return e}static have_label_by_v(e,s){if(!e||!s?.length)return!1;for(const t of s)if(t.value===e)return!0;return!1}}const a=JSON.stringify({stream:!0,thinking:{type:"disabled"}});function i(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>"text"===e.type?e.text:"[图片]").join("\n"):""}t.d(s,["CP",0,'\n\n\n\n# 聊天循环最大次数\ntool_call_max=500\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# 存放本地的 prompt 文件 用于每次聊天的时候自动读取并加载\n# options_local_file_path_prompt_list=["/prompt/a.txt"]\n\n# 开启切换模型 ,开启以后,你可以自己写 prompt 提供多个模型让 ai 自己根据每次聊天切换下一步调用其他模型的次数\n# open_pick_model=false\n\n# 压缩后仍然完整保留的最近消息数\nmax_recent_messages=12\n# 当单个会话累计消息条数超过该值时,触发历史消息裁剪\ncompress_message_count=16\n# 历史消息中 tool 输出的最大字符数,只保留调用形式让 AI 知道调用了就行\nmax_tool_content_chars=200\n\n# ===== 模型类型(request_type)=====\n# 必填项,不同类型的 model 接口格式不同,默认 completions。\n# 可选值:\n# completions 标准对话/聊天补全 (chat/completions)\n# images 图片生成 (images/generations)\n# audio_speech 文本转语音 (audio/speech)\n# audio_transcription 语音转文字 (audio/transcriptions)\n# audio_translation 语音翻译 (audio/translations)\n# embeddings 向量嵌入 (embeddings)\n#request_type=completions\n\n# ===== 成为 tool(tool_mode)=====\n# 开启后该模型会作为一个工具被加载,可实现不同模型担任不同角色/能力,供 AI agent 在对话中动态调用。\n# 注意:不能与「是否开启」(open) 同时为 true。\n#tool_mode=false\n',"cL",0,a])},47713(e,s,t){t.r(s),t.d(s,{default:()=>ee});var n=t(96540),a=t(34843),i=t(86149),c=t(86090),o=t(92275),r=t(14284),l=t(7463),d=t(78247),u=t(40505),m=t(62042),h=t(45907),g=t(53459),p=t(72693),_=t(82893),x=t(61443),f=t(83277);function j(e){return null==e||e<0?"0":e.toLocaleString()}function v(e){const s=(0,f.$j)(e.content);if(s)return s;const t=e.content_list??[];return t.length?t.map(e=>(0,f.$j)(e.content)).filter(Boolean).join("\n\n"):""}function b(e=[]){return e.filter(e=>"user"===e.role||"assistant"===e.role).map((e,s)=>({id:Date.now()+s,sender:"assistant"===e.role?"bot":"user",text:v(e),attachments:e.attachments??[],content_list:e.content_list,images:e.images,audio:e.audio,embeddings:e.embeddings}))}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 w(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||y.test(e.name)?"text":"binary"}function S(e){return e.text()}function N(e){return new Promise((s,t)=>{const n=new FileReader;n.onload=()=>s(n.result),n.onerror=t,n.readAsDataURL(e)})}async function k(e){const s=[];for(const t of e){const e=w(t);let n="";if("text"===e)try{const e=await S(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 N(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}var C=t(14944);var A=t(85997),$=t(34299),I=t(74848);function M(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)(A.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)(R,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(H,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(V,{embeddings:e.embeddings,text:e.text})},"embeddings"));const a=function(e){if("bot"!==e.sender||!e.content_list?.length)return e.text?(0,I.jsx)($.default,{context:e.text}):null;return(0,I.jsxs)(I.Fragment,{children:[e.content_list.map((e,s)=>{const t=[],a=(0,f.$j)(e.content);return a&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)($.default,{context:a})},`content-${s}`)),e.tool_call_ends?.length&&t.push((0,I.jsx)(n.Fragment,{children:(0,I.jsx)(D,{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)($.default,{context:e.text}):null]})}(e);return 0===t.length?(0,I.jsxs)(I.Fragment,{children:[s,a]}):(0,I.jsxs)(I.Fragment,{children:[t,s,a]})}function D({callList:e}){const[s,t]=n.useState(!1);if(!e?.length)return null;e.filter(e=>e.success).length;const a=e.filter(e=>!e.success).length;return(0,I.jsxs)("div",{className:"chat-message-call-list",children:[(0,I.jsxs)("div",{className:"call-list-header",onClick:()=>t(!s),children:[(0,I.jsx)(A.In,{icon:s?"expand_less":"expand_more"}),(0,I.jsxs)("span",{className:"call-list-summary",children:["工具调用 (",e.length,")",a>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)(A.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 R({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)($.default,{context:s})]}):(0,I.jsx)($.default,{context:s||""})}function H({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)($.default,{context:t})}function T({content:e,label:s}){const[t,a]=n.useState(!1);return(0,I.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,u.lW)(e),a(!0),setTimeout(()=>a(!1),1500)},children:[(0,I.jsx)(A.In,{icon:t?"check":"content_copy"}),t?"已复制":s||"复制"]})}function V({embeddings:e,text:s}){let t=e||null;if(!t&&s)try{t=JSON.parse(s)}catch{return(0,I.jsx)($.default,{context:s})}if(!t)return(0,I.jsx)($.default,{context:s||""});const n=t?.data||[],a=t?.usage,i=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]}),a&&(0,I.jsxs)("span",{children:["使用 tokens: ",a.total_tokens??"N/A"]})]}),(0,I.jsxs)("div",{className:"embeddings-toolbar",children:[(0,I.jsx)(T,{content:i,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,I.jsx)(T,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,I.jsx)(T,{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:i})]})]})}async function K(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 r.jV.post("images/generations",t);if(0!==n.code)throw new Error(n.message||"图片生成失败");const a=n.data||{},i=(a.data||[]).map(e=>({url:e.url,b64_json:e.b64_json,revised_prompt:e.revised_prompt})),c=i.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:a.session_id||s,images:i,text:c||`生成了 ${i.length} 张图片`}}(s,t);return e&&n(e.text,{images:e.images}),!0}case"audio_speech":{const e=await async function(e,s){const t={input:e,session_id:s};try{const e=localStorage.getItem("ai_audio_extra_params");if(e){const s=JSON.parse(e);s.voice&&(t.voice=s.voice),s.speed&&(t.speed=parseFloat(s.speed))}}catch{}const n=localStorage.getItem("token")||"",a=await fetch("/api/ai_agent/audio/speech",{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(t)});if(!a.ok)throw new Error(`语音合成失败: ${a.statusText}`);const i=a.headers.get("X-Session-Id")||s,c=await a.arrayBuffer();return{session_id:i,audio:{data:btoa(String.fromCharCode(...Array.from(new Uint8Array(c)))),mime_type:a.headers.get("content-type")||"audio/mpeg"},text:`[音频文件: ${e.slice(0,50)}...]`}}(s,t);return e&&n(e.text,{audio:e.audio}),!0}case"embeddings":{const e=await async function(e,s){const t=await r.jV.post("embeddings",{input:e,session_id:s});if(0!==t.code)throw new Error(t.message||"Embeddings 请求失败");const n=t.data||{},a=n?.data??[],i=`向量维度: ${a[0]?.embedding?.length??0}, 数量: ${a.length}`;return{session_id:n.session_id||s,embeddings:n,text:`✅ Embeddings 结果 - ${i}\n\`\`\`json\n${JSON.stringify(n,null,2).slice(0,2e3)}\n\`\`\``}}(s,t);return e&&n(e.text,{embeddings:e.embeddings}),!0}default:return!1}}catch(e){return n(`请求失败: ${e?.message||JSON.stringify(e)}`),!0}}var E=t(4412),P=t(23430),B=t(87361),F=t(80389),L=t(7523),z=t(23496);const O=({currentModelName:e,setCurrentModelName:s,modelGroups:t,onModelChanged:o,sysPromptList:l,batchMode:u,selectedMsgCount:h,onToggleSessionPanel:p,onCreateSession:f,onToggleBatchMode:j,onBatchDeleteMessages:v,bgProcessVisible:b,bgProcessCount:y,onToggleBgProcess:w,selectedSysPromptId:S,setSelectedSysPromptId:N})=>{const{t:k}=(0,i.B)(),C=(0,c.Zp)(),{check_user_auth:$}=(0,d.MH)(),[,M]=(0,a.fp)(_.AG.ai_session_collapsed),{open:D}=function(){const{t:e}=(0,i.B)(),[,s]=(0,a.fp)(_.AG.prompt_card),[t,c]=(0,a.fp)(_.AG.ai_chat_zoom),{initUserInfo:o}=(0,n.useContext)(L.F);return{open:()=>{const n=t,a=()=>s({open:!1});s({open:!0,title:e("缩放调整"),context_div:(0,I.jsx)(F.p,{defaultValue:t,onChange:c,min:30,max:200}),cancel:()=>{c(n),a()},confirm:async()=>{let s=100;c(e=>(s=e<30||e>200?100:e,s)),await r.wm.post(z.s.user_save_private_attr,{is_ai_chat_zoom:!0,ai_chat_zoom:s}),(0,m.SK)(e("缩放调整成功")),o(),a()}})}}}(),R=$(P.oV.ai_model_switch)||$(P.oV.ai_agent_setting),H=[];for(const e of t)for(const s of e.models)H.push({title:s.label||s.value,value:`${e.index}::${s.value}`,group:e.note});const T=t.find(e=>e.active),V=T?`${T.index}::${e}`:"";return(0,I.jsxs)(E.aZ,{position:"right",children:[(0,I.jsx)(A.rA,{icon:"menu",title:k("会话"),onClick:p}),(0,I.jsx)(A.rA,{icon:"add",title:k("新会话"),onClick:()=>f()}),l.length>0&&(0,I.jsx)(x.l6,{value:S,options:[{title:k("选择系统提示词"),value:""},...l.map(e=>({title:e.note||e.prompt.slice(0,30),value:String(e.index)}))],onChange:e=>{N(e)},no_border:!0,width:"auto"}),R&&H.length>0&&(0,I.jsx)(x.l6,{value:V,options:[{title:k("选择模型"),value:""},...H],margin:"0 0 0 1em",onChange:e=>{const t=String(e??"");if(!t.includes("::"))return;const[n,...a]=t.split("::"),i=a.join("::");i&&(s(i),r.jV.post("set_active_model",{index:Number(n),model_name:i}).then(e=>{e?.code===g.m.Success?((0,m.SK)("success"),o()):(0,m.zN)(e?.message||"fail")}).catch(console.error))},no_border:!0,width:"auto"}),u&&h>0&&(0,I.jsx)(A.rA,{icon:"delete",title:k("删除选中消息"),onClick:v}),(0,I.jsx)(A.rA,{icon:"zoom_in",title:k("缩放调整"),onClick:D}),(0,I.jsx)(A.rA,{icon:"terminal",title:k("后台进程"),onClick:w,selected:b,tip:y||null}),$(P.oV.ai_agent_setting)&&(0,I.jsx)(A.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{C(B.o.ai_rebot_setting_page)}}),$(P.oV.ai_agent_setting)&&(0,I.jsx)(A.rA,{icon:"settings",title:"ai setting",onClick:()=>{C(B.o.ai_agent_setting_page)}})]})};var q=t(83529);function G({sessions:e,activeSessionId:s,onSelectSession:t,onRenameSession:c,onDeleteSession:o,onToggleCmdAuto:r,onShowUsageStats:l,batchMode:d,selectedSessionIds:u,onToggleSessionSelect:m,onToggleBatchMode:h,onBatchDeleteSessions:g,onClearAllSessions:p}){const{t:x}=(0,i.B)(),[f,j]=(0,a.fp)(_.AG.ai_session_collapsed),[v,b]=(0,n.useState)(""),y=v.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(v.toLowerCase())||(e.summary||"").toLowerCase().includes(v.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(v.toLowerCase())):e;return(0,I.jsxs)("aside",{className:`chat-session-list ${f?"active":""} ${f?"collapsed":""}`,children:[(0,I.jsx)("div",{className:"chat-session-search",children:(0,I.jsx)("input",{type:"text",className:"chat-session-search-input",placeholder:x("搜索会话"),value:v,onChange:e=>b(e.target.value)})}),(0,I.jsx)("div",{className:"chat-session-items-wrap",children:y.map(e=>{return(0,I.jsx)("div",{children:(0,I.jsxs)("button",{className:`chat-session-item ${s===e.id?"active":""} ${d?"batch-mode":""} ${e.running?"is-running":""}`,onClick:()=>{d&&m?m(e.id):t(e.id)},title:e.summary||e.long_term_memory||e.title,children:[d&&(0,I.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:u?.has(e.id)??!1,onChange:()=>m?.(e.id),onClick:e=>e.stopPropagation()}),(0,I.jsx)("span",{children:(n=e.title,n||"新会话")}),e.running&&(0,I.jsx)("span",{className:"chat-session-running",title:x("正在执行中")}),(0,I.jsx)("small",{children:e.message_count}),"web"!==e.source&&(0,I.jsx)("em",{className:"chat-session-source",children:e.source}),!d&&(0,I.jsx)(q.MenuSelect,{list:[{name:x("重命名"),click:()=>c(e.id,e.title)},{name:e.cmd_auto_allow?x("命令检测关闭"):x("命令检测开启"),click:()=>r?.(e.id,!e.cmd_auto_allow)},{name:x("字符消耗统计"),click:()=>l(e.id)},{name:x("删除"),click:()=>o(e.id)}],children:(0,I.jsx)(A.In,{icon:"more_horiz"})})]})},e.id);var n})}),(0,I.jsxs)("div",{className:"chat-session-actions",children:[(0,I.jsx)(A.rA,{icon:d?"check_circle":"checklist",title:x(d?"取消批量选择":"批量选择"),onClick:h}),d&&(u?.size??0)>0&&(0,I.jsx)(A.rA,{icon:"delete",title:x("删除选中会话"),onClick:g}),!d&&(0,I.jsx)(A.rA,{icon:"delete_sweep",title:x("删除全部会话"),onClick:p})]})]})}function J(e){const s=(e.text||"").split("\n").map(e=>e.trim()).find(Boolean)||"";return s.length>80?s.slice(0,80)+"…":s}const W=({messages:e,batchMode:s,selectedMsgIds:t,sending:a,chatContainerRef:i,messagesEndRef:c,onToggleMsgSelect:o,onDelete:r,onCopy:l,onToggleBatchMode:d,t:u})=>{const[m,h]=(0,n.useState)(new Set),g=(0,n.useMemo)(()=>e.filter(e=>!e.is_loading).map(e=>e.id),[e]),p=e=>{h(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},_=()=>{h(e=>e.size>0&&g.every(s=>e.has(s))?new Set:new Set(g))};return(0,I.jsxs)("div",{className:"chat-messages",ref:i,"data-sending":a?"true":"false",children:[e.map(e=>{const n=m.has(e.id);return(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:()=>o(e.id)}),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:()=>p(e.id),children:[(0,I.jsx)("span",{className:"chat-message-summary-icon",children:"▸"}),(0,I.jsx)("span",{className:"chat-message-summary-text",children:J(e)||u("(无内容)")})]}):(0,I.jsx)("div",{className:"chat-message-body",children:M(e)}),(0,I.jsxs)("div",{className:"message-collapse-bar",children:[(0,I.jsx)("button",{onClick:()=>p(e.id),children:u(n?"展开":"折叠")}),(0,I.jsx)("button",{onClick:_,children:u("全部折叠")})]}),(0,I.jsx)("div",{className:"message-actions",children:s?(0,I.jsx)("button",{onClick:()=>o(e.id),children:t.has(e.id)?u("取消选择"):u("选择")}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)("button",{onClick:()=>r(e.id),children:u("删除")}),(0,I.jsx)("button",{onClick:()=>l(e.text),children:u("复制")}),(0,I.jsx)("button",{onClick:d,children:u("多选")})]})})]})]},e.id)}),(0,I.jsx)("div",{ref:c})]})},Q=(0,n.forwardRef)(function({placeholder:e="",disabled:s=!1,className:t,style:a,onEnter:i,onPaste:c,onChange:o},r){const l=(0,n.useRef)(null),[d,u]=(0,n.useState)(!0),[m,h]=(0,n.useState)(!1),g=(0,n.useCallback)(()=>{const e=l.current;return e?(e.textContent??"").replace(/\u00A0/g," ").trimEnd():""},[]);(0,n.useImperativeHandle)(r,()=>({getValue:()=>g(),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:a,onKeyDown:e=>{m||"Enter"!==e.key||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),i?.())},onPaste:c,onInput:()=>o?.(g()),onCompositionStart:()=>h(!0),onCompositionEnd:()=>h(!1),"data-placeholder":d?e:void 0})});function U({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)(A.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)(A.In,{icon:"close"})})]},`${e.name}_${t}`))})}const X=(0,n.forwardRef)(({onSend:e,sending:s,onAbort:t,pendingAttachments:c,onRemoveAttachment:o,onOpenFilePicker:r,onAddFiles:l,onDrop:d,onDragOver:u,fileInputRef:m},h)=>{const{t:g}=(0,i.B)(),p=(0,n.useRef)(null),[x,f]=(0,n.useState)(!1),j=(0,n.useRef)(null),[v,b]=(0,a.fp)(_.AG.ai_chat_input_height);(0,n.useImperativeHandle)(h,()=>({getValue:()=>p.current?.getValue()??"",setValue:e=>p.current?.setValue(e),clear:()=>p.current?.clear()}));const y=(0,n.useCallback)(e=>{const s=j.current;if(!s)return;const t=s.getBoundingClientRect().bottom-e.clientY;let n=Math.round(t/21.375);n=Math.max(2,Math.min(20,n)),b(n)},[b]),w=(0,n.useCallback)(()=>f(!0),[]),S=(0,n.useCallback)(()=>f(!1),[]);(0,n.useEffect)(()=>{if(!x)return;const e=y;return window.addEventListener("pointermove",e),window.addEventListener("pointerup",S),()=>{window.removeEventListener("pointermove",e),window.removeEventListener("pointerup",S)}},[x,y,S]);const N={minHeight:`${v}em`,maxHeight:`${v}em`};return(0,I.jsxs)("div",{ref:j,className:"chat-input-area",onDrop:d,onDragOver:u,children:[(0,I.jsx)("div",{className:"chat-input-resize-handle"+(x?" dragging":""),onPointerDown:w}),(0,I.jsx)("input",{ref:m,type:"file",multiple:!0,style:{display:"none"},onChange:e=>{e.target.files?.length&&(l(e.target.files),e.currentTarget.value="")}}),(0,I.jsxs)("div",{className:"chat-input-shell",style:N,children:[(0,I.jsx)(U,{pendingAttachments:c,onRemove:o}),(0,I.jsx)(Q,{ref:p,placeholder:g("输入消息"),onEnter:()=>e(),onPaste:e=>{const s=e.clipboardData?.files;s&&s.length>0&&(e.preventDefault(),l(s))},className:"chat-input",style:N})]}),(0,I.jsx)(A.rA,{title:g("添加文件"),icon:"attach_file",onClick:r}),s?(0,I.jsx)(A.Vi,{color:"var( --icon-red)",text:g("暂停"),clickFun:t}):(0,I.jsx)(A.Vi,{text:g("发送"),clickFun:e}),x&&(0,I.jsx)("div",{className:"chat-input-overlay",onPointerUp:S})]})}),Z={},Y=function(){const{t:e}=(0,i.B)(),[s,t]=(0,n.useState)([]),[c,r]=(0,n.useState)(!1),[l,d]=(0,n.useState)(null),[u,h]=(0,n.useState)(null),[g,p]=(0,n.useState)(!1),[x,f]=(0,a.fp)(_.AG.ai_bg_expanded),[,j]=(0,a.fp)(_.AG.ai_session_collapsed),v=()=>{f(!1)},b=(0,n.useCallback)(async()=>{r(!0);try{const e=new o.hf(o.HK.ai_bg_process_list_req);e.context={};const s=await C.ws.send(e);s?.context?.processes&&(t(s.context.processes),Z.onCountChange?.(s.context.processes.length))}catch(e){console.error("获取后台进程列表失败",e)}finally{r(!1)}},[]);Z.refresh=b;const y=(0,n.useCallback)(async e=>{p(!0),d(e);try{const s=new o.hf(o.HK.ai_bg_process_output_req);s.context={pid:e};const t=await C.ws.send(s);h(t.context)}catch(e){console.error("获取进程输出失败",e),(0,m.zN)("获取进程输出失败")}finally{p(!1)}},[]),w=(0,n.useCallback)(async e=>{try{const s=new o.hf(o.HK.ai_bg_process_kill_req);s.context={pid:e};const t=await C.ws.send(s);t?.context?.success?((0,m.SK)("进程已终止"),b(),l===e&&(d(null),h(null))):(0,m.zN)(t?.context?.message||"终止失败")}catch(e){console.error("终止进程失败",e),(0,m.zN)("终止进程失败")}},[b,l]);(0,n.useEffect)(()=>{b();const e=setInterval(b,5e3);return()=>clearInterval(e)},[b]);const S=s.filter(e=>e.running),N=s.filter(e=>!e.running);return(0,I.jsxs)(I.Fragment,{children:[x&&(0,I.jsx)("div",{className:"chat-session-overlay",onClick:v}),(0,I.jsxs)("aside",{className:"chat-bg-process-panel "+(x?"expanded":""),children:[(0,I.jsxs)("div",{className:"chat-bg-process-header",children:[(0,I.jsx)("span",{className:"chat-bg-process-title",children:e("后台进程")}),(0,I.jsx)(A.rA,{icon:"close",title:e("关闭"),onClick:v})]}),(0,I.jsxs)("div",{className:"chat-bg-process-toolbar",children:[(0,I.jsx)(A.rA,{icon:"refresh",title:e("刷新"),onClick:b}),(0,I.jsxs)("span",{className:"chat-bg-process-count",children:[S.length," ",e("个运行中"),N.length>0&&` / ${N.length} ${e("个已退出")}`]})]}),(0,I.jsxs)("div",{className:"chat-bg-process-list",children:[c&&0===s.length&&(0,I.jsx)("div",{className:"chat-bg-process-empty",children:e("加载中...")}),!c&&0===s.length&&(0,I.jsx)("div",{className:"chat-bg-process-empty",children:e("暂无后台进程")}),S.map(s=>(0,I.jsxs)("div",{className:`chat-bg-process-item ${l===s.pid?"active":""} running`,children:[(0,I.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>y(s.pid),children:[(0,I.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",s.pid]}),(0,I.jsx)("span",{className:"chat-bg-process-cmd",title:s.cmd,children:s.cmd.length>40?s.cmd.slice(0,40)+"...":s.cmd}),(0,I.jsx)("span",{className:"chat-bg-process-time",children:new Date(s.start_time).toLocaleTimeString()}),(0,I.jsx)("span",{className:"chat-bg-process-status running-dot",title:e("运行中"),children:"●"})]}),(0,I.jsxs)("div",{className:"chat-bg-process-item-actions",children:[(0,I.jsx)(A.rA,{icon:"terminal",title:e("查看输出"),onClick:()=>y(s.pid)}),(0,I.jsx)(A.rA,{icon:"stop",title:e("终止进程"),onClick:()=>w(s.pid)})]})]},s.pid)),N.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:()=>y(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," ",e("输出")]}),(0,I.jsx)(A.rA,{icon:"close",title:e("关闭"),onClick:()=>{d(null),h(null)}})]}),(0,I.jsx)("div",{className:"chat-bg-process-output-content",children:g?(0,I.jsx)("div",{className:"chat-bg-process-empty",children:e("加载中...")}):u?(0,I.jsx)("pre",{className:"chat-bg-process-output-pre",children:u.output||e("(无输出)")}):null})]})]})]})};function ee(){const{t:e}=(0,i.B)(),s=((0,c.Zp)(),(0,h.y)()),{check_user_auth:t}=(0,d.MH)();(0,p.w)();const[f,v]=(0,n.useState)([]),[y,w]=(0,n.useState)([]),[S,N]=(0,n.useState)(""),[A,$]=(0,n.useState)(null),[M,D]=(0,n.useState)(!1),R=(0,n.useRef)(null),[H,T]=(0,n.useState)([]),[V,E]=(0,a.fp)(_.AG.ai_session_collapsed),[P,B]=(0,a.fp)(_.AG.ai_bg_expanded),[F,L]=(0,a.fp)(_.AG.prompt_card),[z]=(0,a.fp)(_.AG.ai_chat_zoom),[q,J]=(0,n.useState)(!1),[Q,U]=(0,n.useState)(new Set),[ee,se]=(0,n.useState)(new Set),[te,ne]=(0,n.useState)(""),ae=(0,n.useRef)(null),ie=(0,n.useRef)(null),ce=(0,n.useRef)(null),oe=(0,n.useRef)(!0),re=(0,n.useRef)(null),le=(0,n.useRef)(0),de=(0,n.useRef)(null),ue=(0,n.useRef)(S),me=(0,n.useRef)(A);(0,n.useEffect)(()=>{ue.current=S},[S]),(0,n.useEffect)(()=>{me.current=A},[A]);const he=(0,n.useRef)({}),[ge,pe]=(0,n.useState)([]),[_e,xe]=(0,n.useState)(""),[fe,je]=(0,n.useState)([]),ve=async()=>{try{const e=await r.jV.get("public_models");e.code===g.m.Success&&je(e.data?.groups??[])}catch{je([])}},be=e=>{xe(e?.ai_config?.model??"")},[ye,we]=(0,n.useState)(0),Se=(0,n.useRef)((0,l.sg)(e=>{v(e),oe.current&&Ne(!1)},50)).current,Ne=(e=!1)=>{const s=ce.current;s&&s.scrollTo({top:s.scrollHeight,behavior:e?"smooth":"auto"})},ke=async()=>{const e=await r.jV.get("sessions");e.code===g.m.Success&&w(e.data??[])},Ce=function(e){const{getMessages:s,setMessages:t,setMessagesDebounced:a,setSending:i,getActiveSessionId:c,setActiveSessionId:r,refreshSessions:l,scrollToBottom:d,buildRequestMessages:u,getSelectedSysPromptId:m}=e,h=(0,n.useRef)([]),g=(0,n.useRef)(null),p=(e,n,r)=>{const h=[...s(),n];t(h),i(e),g.current={abort:()=>{}};const p={id:n.id+1,sender:"bot",text:"AI思考中...",is_loading:!0};h.push(p),t([...h]);const _=new Map;let x=!0,f=p;const j=s=>{const t=s.context||{},n=t.text||"",i=t.tool_call_ends,o=t.chunk_index??0;if("[DONE]"!==n)if(x)x=!1,f.text=n,i&&(f.content_list=[{tool_call_ends:i,content:f.text,role:"assistant"}]),f.is_loading=!1,f.chunk_index=o,_.set(o,f),c()===e&&a([...h]);else{const s=_.get(o);if(s)s.text+=n,i&&(s.content_list=[{tool_call_ends:i,content:s.text,role:"assistant"}]),c()===e&&a([...h]);else{const s={id:Date.now()+Math.random(),sender:"bot",text:n,chunk_index:o};i&&(s.content_list=[{tool_call_ends:i,content:s.text,role:"assistant"}]),h.push(s),_.set(o,s),c()===e&&a([...h])}}},v=s=>{y(),g.current=null,i(s=>s===e?null:s),f.is_loading=!1,l(),d(!0),r()},b=s=>{y(),g.current=null,i(s=>s===e?null:s);const n=s.context||{};f.text="AI请求出错: "+(n.message||"未知错误"),f.is_loading=!1,c()===e&&t([...h]),r()},y=()=>{C.ws.off_message(`message_${o.HK.ai_chat_msg}`,j),C.ws.off_message(`message_${o.HK.ai_chat_end}`,v),C.ws.off_message(`message_${o.HK.ai_chat_error}`,b)};C.ws.addMsg(o.HK.ai_chat_msg,j),C.ws.addMsg(o.HK.ai_chat_end,v),C.ws.addMsg(o.HK.ai_chat_error,b),C.ws.sendData(o.HK.ai_chat_req,{messages:u(n),session_id:e,sys_prompt_id:m()})},_=()=>{const e=h.current;if(0===e.length)return;const s=e.shift();if(!s)return;t(e=>e.map(e=>"user"===e.sender&&e.text.includes("⏳(排队中...)")?{...e,text:e.text.replace(" ⏳(排队中...)","")}:e));const n={id:Date.now(),sender:"user",text:s.text,attachments:s.attachments};p(c(),n,_)};return{startChatStream:p,processPendingQueue:_,enqueueMessage:(e,s)=>{h.current.push({text:e,attachments:s})},getQueueLength:()=>h.current.length,abort:()=>{const e=c();e&&(C.ws.sendData(o.HK.ai_chat_abort,{session_id:e}),g.current&&(g.current=null,i(s=>s===e?null:s)))}}}({getMessages:()=>f,setMessages:v,setMessagesDebounced:Se,setSending:$,getActiveSessionId:()=>ue.current,setActiveSessionId:N,refreshSessions:ke,scrollToBottom:Ne,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:()=>te}),Ae=async e=>{const s=await r.jV.get("sessions");if(s.code!==g.m.Success)return;const t=s.data??[];w(t);const n=null===e?t[0]?.id??"":e||S||t[0]?.id||"";n?await $e(n):(v([]),N(""))},$e=async(e,s=!1)=>{const t=await r.jV.post("session/get",{session_id:e});if(t.code!==g.m.Success||!t.data)return;const n=t.data;N(n.id),D(!!n.running),de.current&&de.current!==n.id&&C.ws.sendData(o.HK.ai_chat_subscribe,{session_id:de.current,subscribe:!1}),de.current=n.running?n.id:null,de.current&&C.ws.sendData(o.HK.ai_chat_subscribe,{session_id:de.current,subscribe:!0});const a=b(n.messages);n.running&&n.live_messages?.length?v([...a,...b(n.live_messages)]):v(a),ne(n.sys_prompt_id??""),s&&E(!1),Z.refresh?.(),requestAnimationFrame(()=>Ne(!1))},Ie=e=>{const s=Array.from(e??[]).filter(Boolean);s.length&&T(e=>[...e,...s])},Me=()=>{q&&(U(new Set),se(new Set)),J(e=>!e)};(0,n.useEffect)(()=>((async()=>{const e=await r.XO.get("ai_agent_setting/env");e.code===g.m.Success&&(he.current=e.data,be(e.data)),await ve(),await Ae();const s=await r.jV.get("system_prompts");s.code===g.m.Success&&pe(s.data??[])})(),requestAnimationFrame(()=>Ne(!1)),Z.onCountChange=we,Z.refresh?.(),C.ws.addMsg(o.HK.ai_bg_process_count_notify,e=>{const s=e?.context?.count;"number"==typeof s&&we(s)}),()=>{C.ws.removeMsg(o.HK.ai_bg_process_count_notify)}),[]),(0,n.useEffect)(()=>{const e=ce.current;if(!e)return;const s=()=>{oe.current=((e,s=120)=>{const{scrollTop:t,scrollHeight:n,clientHeight:a}=e;return n-(t+a)<s})(e)};return e.addEventListener("scroll",s),()=>e.removeEventListener("scroll",s)},[]),(0,n.useEffect)(()=>{const e=()=>ue.current,s=()=>me.current,t=(t,n)=>{if(e()&&e()===t){if(re.current=null,D(!1),de.current===t&&(C.ws.sendData(o.HK.ai_chat_subscribe,{session_id:t,subscribe:!1}),de.current=null),s()===t)return;n?.length?v(e=>{const s=b(n),t=e[e.length-1];return"bot"===t?.sender?[...e.slice(0,-1),...s]:[...e,...s]}):$e(t).catch(()=>{}),ke()}},n=t=>{const n=t?.context||{};if(!n.session_id)return;var a,i,c;a=n.session_id,i=n.text||"",c=n.tool_call_ends,e()&&e()===a&&s()!==a&&v(e=>{const s=e[e.length-1];if(s&&"bot"===s.sender){const t=[...e],n={...s};return n.text+=i,c&&(n.content_list=[{tool_call_ends:c,content:n.text,role:"assistant"}]),t[t.length-1]=n,re.current=n.id,oe.current&&requestAnimationFrame(()=>Ne(!1)),t}const t={id:Date.now()+Math.random(),sender:"bot",text:i};return c&&(t.content_list=[{tool_call_ends:c,content:i,role:"assistant"}]),re.current=t.id,oe.current&&requestAnimationFrame(()=>Ne(!1)),[...e,t]});const o=Date.now();o-le.current>1500&&(le.current=o,ke())},a=e=>{const s=e?.context||{};s.session_id&&t(s.session_id,s.once_messages_list)},i=e=>{const s=e?.context||{};s.session_id&&t(s.session_id)};return C.ws.addMsg(o.HK.ai_chat_msg,n),C.ws.addMsg(o.HK.ai_chat_end,a),C.ws.addMsg(o.HK.ai_chat_error,i),()=>{C.ws.off_message(`message_${o.HK.ai_chat_msg}`,n),C.ws.off_message(`message_${o.HK.ai_chat_end}`,a),C.ws.off_message(`message_${o.HK.ai_chat_error}`,i),de.current&&(C.ws.sendData(o.HK.ai_chat_subscribe,{session_id:de.current,subscribe:!1}),de.current=null)}},[]),(0,n.useLayoutEffect)(()=>{oe.current&&Ne(!1)},[f]);return(0,I.jsxs)(n.Fragment,{children:[(0,I.jsx)(O,{currentModelName:_e,setCurrentModelName:xe,modelGroups:fe,onModelChanged:async()=>{await ve();const e=await r.XO.get("ai_agent_setting/env");e.code===g.m.Success&&(he.current=e.data,be(e.data))},sysPromptList:ge,batchMode:q,selectedMsgCount:Q.size,onToggleSessionPanel:()=>{E(e=>!e)},onCreateSession:async e=>{const s=void 0!==e?e:te,t=await r.jV.post("session",{title:"新会话",sys_prompt_id:s||void 0});if(t.code!==g.m.Success)return;const n=t.data;N(n.id),v([]),ne(n.sys_prompt_id??""),E(!1),await Ae(n.id),requestAnimationFrame(()=>{const e=document.querySelector(".chat-input");e&&(e.style.height="auto",e.style.height=Math.min(e.scrollHeight,200)+"px")})},onBatchDeleteMessages:()=>{0!==Q.size&&s({sub_title:e("cf_msgs"),confirm_fun:async()=>{const e=[];f.forEach((s,t)=>{Q.has(s.id)&&e.push(t)}),v(f.filter(e=>!Q.has(e.id))),U(new Set),J(!1),S&&e.length>0&&r.jV.post("session/message/delete",{session_id:S,indices:e}).catch(console.error)}})},bgProcessVisible:P,bgProcessCount:ye,onToggleBgProcess:()=>B(e=>!e),selectedSysPromptId:te,setSelectedSysPromptId:e=>{ne(e),S&&r.jV.post("session/sys_prompt",{session_id:S,sys_prompt_id:e||void 0}).catch(console.error)}}),(0,I.jsxs)("div",{className:"chat-page chat-page-with-sessions",style:{"--ai-chat-zoom":z},children:[V&&(0,I.jsx)("div",{className:"chat-session-overlay",onClick:()=>E(!1)}),(0,I.jsx)(G,{sessions:y,activeSessionId:S,onSelectSession:e=>$e(e,!1),onRenameSession:(e,t)=>{let n=t;s({confirm_fun:async()=>{await r.jV.post("sessions/update/meta",{id:e,title:n}),await Ae(S)},context_div:(0,I.jsx)("div",{className:"card-content",children:(0,I.jsx)(x.Sm,{value:n,handleInputChange:e=>{n=e}})})})},onDeleteSession:e=>{s({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{await r.jV.post("session/delete",{session_id:e}),S===e?(N(""),await Ae(null)):await Ae(S)}})},onToggleCmdAuto:async(s,t)=>{await r.jV.post("session/cmd_auto_allow",{session_id:s,allow:t}),(0,m.SK)(e(t?"命令检测已开启":"命令检测已关闭")),await Ae(S)},onShowUsageStats:async s=>{L({open:!0,title:e("Token消耗统计"),context_div:(0,I.jsx)("div",{className:"usage-stats-loading",children:e("加载中...")}),cancel:()=>L({open:!1})});try{const t=await r.jV.post("session/usage_stats",{session_id:s});if(t.code===g.m.Success&&t.data){const s=t.data;L({open:!0,title:e("Token消耗统计"),context_div:(0,I.jsxs)("div",{className:"usage-stats-panel",children:[[{l:e("对话轮次"),v:(s.turns??0).toString()},{l:e("AI输入Token"),v:j(s.input_tokens)},{l:e("AI输出Token"),v:j(s.output_tokens)},{l:e("AI输入Token(最近一轮)"),v:j(s.recent_input_tokens)},{l:e("AI输出Token(最近一轮)"),v:j(s.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:e("AI Token总计消耗")}),(0,I.jsx)("span",{className:"usage-stats-value",children:j((s.input_tokens||0)+(s.output_tokens||0))})]})]}),cancel:()=>L({open:!1})})}else L({open:!0,title:e("Token消耗统计"),context_div:(0,I.jsx)("div",{className:"usage-stats-empty",children:e("暂无统计数据")}),cancel:()=>L({open:!1})})}catch{L({open:!0,title:e("Token消耗统计"),context_div:(0,I.jsx)("div",{className:"usage-stats-empty",children:e("暂无统计数据")}),cancel:()=>L({open:!1})})}},batchMode:q,selectedSessionIds:ee,onToggleSessionSelect:e=>{se(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onToggleBatchMode:Me,onBatchDeleteSessions:()=>{0!==ee.size&&s({sub_title:e("cf_ses"),confirm_fun:async()=>{for(const e of ee)await r.jV.post("session/delete",{session_id:e});se(new Set),J(!1),ee.has(S)?(N(""),await Ae(null)):await Ae(S)}})},onClearAllSessions:()=>{s({sub_title:e("cf_all"),confirm_fun:async()=>{await r.jV.post("sessions/clear",{}),N(""),v([]),await Ae(null)}})}}),(0,I.jsx)(Y,{}),(0,I.jsxs)("section",{className:"chat-main",children:[0===f?.length&&(0,I.jsx)("div",{className:"chat-header",children:(0,I.jsx)("div",{children:e("ai_ask")})}),(0,I.jsx)(W,{messages:f,batchMode:q,selectedMsgIds:Q,sending:A===S||M,chatContainerRef:ce,messagesEndRef:ie,onToggleMsgSelect:e=>{U(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onDelete:t=>{s({sub_title:e("cf_one"),confirm_fun:async()=>{const e=f.findIndex(e=>e.id===t);if(e<0)return;const s=f.filter(e=>e.id!==t);v(s),S&&r.jV.post("session/message/delete",{session_id:S,indices:[e]}).catch(console.error)}})},onCopy:async e=>{(0,u.lW)(e),(0,m.SK)("复制成功")},onToggleBatchMode:Me,t:e}),(0,I.jsx)(X,{ref:R,onSend:async()=>{const e=(R.current?.getValue()??"").trim();if(!e&&0===H.length)return;if(A===S){const s=await k(H);Ce.enqueueMessage(e,s),R.current?.clear(),T([]);const t={id:Date.now(),sender:"user",text:e+(Ce.getQueueLength()>1?" ⏳(排队中...)":""),attachments:s};return void v(e=>[...e,t])}let s=S;if(!s){const t=await r.jV.post("session",{title:(e||H[0]?.name||"新会话").slice(0,28),sys_prompt_id:te||void 0});if(t.code!==g.m.Success)return;s=t.data.id,N(s),await Ae(s)}const t=await k(H),n={id:Date.now(),sender:"user",text:e,attachments:t};R.current?.clear(),T([]);const a=he?.current?.ai_config?.request_type||"completions";if("completions"!==a){const t={id:n.id+1,sender:"bot",text:"处理中...",is_loading:!0},i=[...f,n,t];v(i),$(s);return void(await K(a,e,s,async(e,s)=>{t.text=e,t.is_loading=!1,s?.images&&(t.images=s.images),s?.audio&&(t.audio=s.audio),s?.embeddings&&(t.embeddings=s.embeddings),v([...i]),$(null),ke(),Ne(!0),Ce.processPendingQueue()})||(t.text=`请求类型 "${a}" 的专用处理器尚未实现,请使用 completions 类型。`,t.is_loading=!1,v([...i]),$(null),Ce.processPendingQueue()))}Ce.startChatStream(s,n,()=>Ce.processPendingQueue())},sending:A===S||M,onAbort:Ce.abort,pendingAttachments:H,onRemoveAttachment:e=>{T(s=>s.filter((s,t)=>t!==e))},onOpenFilePicker:()=>{ae.current?.click()},onAddFiles:Ie,onDrop:e=>{const s=e.dataTransfer?.files;s&&s.length>0&&(e.preventDefault(),Ie(s))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:ae})]})]})]})}},72693(e,s,t){t.d(s,{w:()=>h});var n=t(96540),a=t(86149),i=t(14944),c=t(92275),o=t(34843),r=t(82893),l=t(85997),d=t(14284),u=t(74848);function m(e){const{t:s}=(0,a.B)(),[t,i]=(0,n.useState)(!1),c=!!e.sessionId;return(0,u.jsxs)("div",{children:[(0,u.jsx)("div",{style:{maxHeight:"60vh",overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--surfaceSecondary)",padding:"0.75em",borderRadius:"0.5em",marginBottom:"0.75em",fontFamily:"monospace",fontSize:"0.9em",lineHeight:"1.5"},children:e.cmd}),c&&(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5em",marginBottom:"0.75em",color:t?"var(--icon-blue)":"var(--textSecondary)"},children:[(0,u.jsx)(l.Ay,{checked:t,onChange:s=>{i(s),s&&e.onAutoAllow()},title:s("此会话不再询问")}),(0,u.jsx)("span",{children:s("此会话不再询问")})]}),(0,u.jsxs)("div",{style:{display:"flex",gap:"0.5em",justifyContent:"flex-end"},children:[(0,u.jsx)(l.$n,{text:s("拒绝"),color:"var(--red)",clickFun:e.onDeny}),(0,u.jsx)(l.$n,{text:s("允许"),clickFun:e.onAllow})]})]})}function h(){const[e,s]=(0,o.fp)(r.AG.prompt_card),{t}=(0,a.B)(),l=(0,n.useRef)([]),h=(0,n.useRef)(!1),g=(0,n.useRef)(null),p=(0,n.useRef)(void 0),_=(0,n.useRef)(()=>{}),x=(0,n.useCallback)(e=>{s({open:!1}),h.current=!1,g.current&&(i.ws.sendData(c.HK.ai_confirm_cmd,{askId:g.current,approved:e}),g.current=null),_.current()},[s]),f=(0,n.useCallback)(()=>{if(h.current)return;if(0===l.current.length)return h.current=!1,void s({open:!1});h.current=!0;const e=l.current.shift();e?(g.current=e.askId,p.current=e.session_id,s({open:!0,title:t("命令确认"),cancel:()=>x(!1),context_div:(0,u.jsx)(m,{cmd:e.cmd,sessionId:e.session_id,onDeny:()=>x(!1),onAllow:()=>x(!0),onAutoAllow:async()=>{if(p.current)try{await d.jV.post("session/cmd_auto_allow",{session_id:p.current,allow:!0})}catch(e){console.error("设置会话命令免确认失败",e)}x(!0)}})})):h.current=!1},[t,x,s]);_.current=f;const j=(0,n.useCallback)(e=>{l.current.push(e),f()},[f]);(0,n.useEffect)(()=>(i.ws.addMsg(c.HK.ai_confirm_cmd,e=>{const t=e.context||{};if(t.dismiss&&t.askId)return l.current=l.current.filter(e=>e.askId!==t.askId),void(h.current&&g.current===t.askId&&(g.current=null,h.current=!1,s({open:!1}),f()));t.askId&&t.cmd&&j({askId:t.askId,cmd:t.cmd,session_id:t.session_id})}),()=>{i.ws.removeMsg(c.HK.ai_confirm_cmd)}),[j]),(0,n.useEffect)(()=>()=>{l.current=[],h.current=!1,g.current=null},[])}},34299(e,s,t){t.r(s),t.d(s,{default:()=>p});t(96540);var n=t(22091),a=t(53995),i=t(18569),c=t(77979),o=t(8263),r=t(69428),l=t.n(r),d=(t(3775),t(21499)),u=t(99214),m=t(19878),h=(t(72411),t(74848));const g=new n.A({html:!0,highlight:function(e,s){if(s&&m.A.getLanguage(s))try{return`<pre class="hljs code-block-with-copy"><code class="hljs language-${s}">${m.A.highlight(e,{language:s}).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(c.A).use(o.A).use(l()).use(e=>{e.renderer.rules.fence;e.renderer.rules.fence=(s,t,n,a,i)=>{const c=s[t],o=c.content.trim(),r=c.info.trim();let l="";if(r&&m.A.getLanguage(r))try{l=m.A.highlight(o,{language:r}).value}catch(s){l=e.utils.escapeHtml(o)}else try{l=m.A.highlightAuto(o).value}catch(s){l=e.utils.escapeHtml(o)}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(o)}">复制</button>\n </div>\n <pre><code class="hljs ${r?`language-${r}`:""}">${l}</code></pre>\n </div>`}}).use(e=>{const s=e.renderer.rules.link_open||function(e,s,t,n,a){return a.renderToken(e,s,t)};e.renderer.rules.link_open=(e,t,n,a,i)=>{const c=e[t],o=c.attrIndex("href");if(o>=0){const e=c.attrs[o][1];c.attrs[o][1]=(0,d.bi)(window.location.href,e)}return s(e,t,n,a,i)}})},45907(e,s,t){t.d(s,{y:()=>i});var n=t(34843),a=t(82893);function i(){const[e,s]=(0,n.fp)(a.AG.confirm);return({sub_title:e,confirm_fun:t,title:n,context_div:a})=>{s({open:!0,sub_title:e,handle:()=>{t(),s({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>"}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[8603],{58603(e,t,i){i.r(t),i.d(t,{default:()=>N});var n=i(96540),s=i(75725),r=i(70447),a=i(34843),o=i(82893),l=i(60096),c=i(85997),d=i(34251),m=i(34289),h=i(87361),_=i(14284),u=i(53459),x=i(61443),f=i(86149),p=i(62042),j=(i(47022),i(4412)),k=i(99214),g=i(6960),w=i(88815),v=i(40505),z=i(23430),F=i(64694),b=i(86090),C=i(74848);function N(){const[e,t]=(0,n.useState)(null),i=(0,n.useRef)(""),N=(0,n.useRef)(""),[y,$]=(0,a.fp)(o.AG.prompt_card),[S,M]=(0,a.fp)(o.AG.share_sort_type),{t:A}=(0,f.B)(),[G,I]=(0,a.fp)(o.AG.selectedFileList),[U,V]=(0,a.fp)(o.AG.clickFileList),{click_file:W}=(0,k.kZ)(),[D]=(0,b.ok)(),L=(0,k.oT)(),R=(0,k.xp)(),Z=(0,k.Vs)(!0),B=(0,n.useMemo)(()=>{const t=[...e?.items??[]],i=e=>Number(e.mtime??0);return S===z.t8.time_minx_max?t.sort((e,t)=>i(e)-i(t)):S===z.t8.time_max_min&&t.sort((e,t)=>i(t)-i(e)),t},[e?.items,S]),H=async()=>{const e=await _.$M.post("share",{id:i.current,token:N.current});if(e.code===u.m.Success){const n={is_dir:e.data.is_dir};n.items=e.data.files??[];for(const e of n.items)e.origin_size=e.size,e.show_mtime=e.mtime?(0,g.s)(e.mtime):"",e.size=(0,w.v7)(e.size);if(!n.is_dir){const t=e.data.files[0];n.name=t.name,n.size=t.size,n.show_mtime=t.show_mtime}localStorage.setItem(`file_share_token_${i.current}`,N.current);const s=D.get("share_preview_file_name");if(s)try{const t=e.data.files.find(e=>e.name===s);W({file_path:t.path,file_url:_.$M.getDownloadUrlV2(t.path,"share_download",{share_id:i.current,share_token:N.current}),name:t.name,size:t.origin_size,opt_shell:!0,mtime:t.mtime,not_type_tip:A("未知类型,请下载查看"),readonly:!0,close:()=>{L("share_preview_file_name",null)}})}catch(e){(0,p.zN)(e?.message||e)}else t(n)}else e.code===u.m.need_token_share&&(localStorage.removeItem(`file_share_token_${i.current}`),(0,p.zN)("需要正确的访问token"),$({open:!0,title:"share file",confirm:()=>{$({open:!1}),H()},context_div:(0,C.jsx)("div",{className:"card-content",children:(0,C.jsx)(x.Sm,{placeholderOut:A("请输入访问token"),value:"",handleInputChange:e=>{N.current=e}})})}))};if((0,n.useEffect)(()=>{const e=(0,m.oW)(`${(0,m.GG)(h.o.share,(0,m.vX)())}`);i.current=e,N.current=localStorage.getItem(`file_share_token_${e}`),H()},[D]),!e)return(0,C.jsx)(s.jW,{isFull:!0,children:(0,C.jsx)("div",{className:"common-box common-box-center",children:"Loading..."})});return(0,C.jsxs)(n.Fragment,{children:[(0,C.jsx)(j.aZ,{children:(0,C.jsx)(C.Fragment,{children:(0,C.jsxs)("h2",{children:["Share ",e.is_dir?"Folder":"File"]})})}),(0,C.jsxs)(j.aZ,{position:"right",children:[G.length>0&&(0,C.jsx)(c.rA,{icon:"download",title:A("下载"),onClick:function(){const e=[];for(let t=0;t<G.length;t++){const i=B[G[t]];e.push(encodeURIComponent(i.path))}const t=_.$M.getDownloadUrlV2(e,"share_download",{share_id:i.current,share_token:N.current});window.open(t)}}),e.is_dir&&(0,C.jsx)(c.rA,{icon:"grid_view",title:A("切换样式"),onClick:Z}),e.is_dir&&(0,C.jsx)(c.rA,{icon:"schedule",title:S===z.t8.time_minx_max?A("时间逆序"):A("时间顺序"),onClick:()=>{const e=(0,F.jH)([z.t8.time_max_min,z.t8.time_minx_max,z.t8.defualt],S);M(e),I([]),V([])}})]}),(0,C.jsx)(s.xh,{children:(0,C.jsx)(s.jW,{isFull:!0,children:(0,C.jsx)("div",{className:"common-box ",children:e.is_dir?(0,C.jsx)(l.QW,{share:{share_id:i.current,share_token:N.current},handleContextMenu:()=>{},file_list:B,clickBlank:e=>{e.target===e.currentTarget&&(I([]),V([]))}}):(0,C.jsx)(r.uF,{children:(0,C.jsxs)("div",{style:{height:"25rem"},className:"common-box common-box-center",children:[(0,C.jsx)("div",{className:"file-icons",children:(0,C.jsx)("div",{"data-type":(0,d.uL)(e.name),"data-dir":e.is_dir,"aria-label":e.name,children:(0,C.jsx)(c.In,{icon:"",style:{fontSize:"10rem",display:"inline-block",lineHeight:1},aria_label:e.name})})}),(0,C.jsx)("div",{className:"",children:e.name}),(0,C.jsx)("div",{className:"",children:e.size}),(0,C.jsx)("div",{className:"",children:e.show_mtime}),(0,C.jsx)(c.C3,{text:"download",clickFun:()=>{const e=B[0],t=_.$M.getDownloadUrlV2(e.path,"share_download",{share_id:i.current,share_token:N.current});window.open(t)}}),(0,C.jsx)(c.C3,{text:"copy url",clickFun:()=>{const e=B[0],t=_.$M.getDownloadUrlV2(e.path,"share_download",{share_id:i.current,share_token:N.current}),n=_.$M.get_full_url(t);(0,v.lW)(n),(0,p.SK)(n)}}),(0,C.jsx)(c.C3,{text:"preview",clickFun:()=>{const e=B[0];R(e.name)}})]})})})})})]})}}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[9877],{69918(t,e,n){n.d(e,{Ce:()=>l,FG:()=>r.FG,fy:()=>c,gC:()=>a});var r=n(18840),o=n(14284),s=n(53459);async function a(){try{const t=await o.XO.get("md_editor_setting/get");return{...r.FG,...t?.data??{}}}catch(t){return{...r.FG}}}async function c(t){const e=await o.XO.post("md_editor_setting/save",t);return e?.code!==s.m.Success?null:{...r.FG,...e.data??t}}function l(t,e){t&&(t.style.setProperty("--md-editor-max-width",e.content_max_width),t.style.setProperty("--md-editor-padding",e.content_padding),t.style.setProperty("--md-editor-font-size",e.font_size),t.style.setProperty("--md-editor-line-height",e.line_height))}},64877(t,e,n){n.d(e,{A:()=>a});var r=n(96540),o=n(86149),s=n(74848);function a(t){const{t:e}=(0,o.B)(),[n,a]=(0,r.useState)(new Set),c=(0,r.useMemo)(()=>function(t){const e=[],n=[];for(const r of t){const t={...r,children:[]};for(;n.length>0&&n[n.length-1].level>=t.level;)n.pop();0===n.length?e.push(t):n[n.length-1].children.push(t),n.push(t)}return e}(t.items),[t.items]),l=(r,o)=>r.map(r=>{const c=r.children.length>0,i=n.has(r.pos),d=r.pos===t.active_pos;return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:`md-outline-item md-outline-item--h${r.level}${d?" md-outline-item--active":""}`,style:{paddingLeft:.4+.75*o+"em"},title:r.text,onClick:()=>t.on_click(r),children:[(0,s.jsx)("i",{className:"material-icons md-outline-arrow"+(c?"":" md-outline-arrow--empty"),onClick:c?t=>{return e=r.pos,t.stopPropagation(),void a(t=>{const n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});var e}:void 0,children:c?i?"arrow_right":"arrow_drop_down":""}),(0,s.jsx)("span",{className:"md-outline-text",children:r.text||e("未命名标题")})]}),c&&!i&&l(r.children,o+1)]},r.pos)});return 0===t.items.length?(0,s.jsx)("div",{className:"md-outline md-outline--empty",children:(0,s.jsx)("div",{className:"md-outline-tip",children:e("no_head")})}):(0,s.jsx)("div",{className:"md-outline",children:(0,s.jsx)("div",{className:"md-outline-list",children:l(c,0)})})}},86504(t,e,n){n.d(e,{A:()=>T});var r=n(96540),o=n(42845),s=n(1575),a=n(89781),c=n(61396),l=n(46762),i=n(73337),d=n(89552),u=n(86059),h=n(5091),p=n(22091),m=n(58903);const f=new p.A({html:!0,linkify:!0,breaks:!1,typographer:!1});function g(t){const e=f.render(t??""),n=document.createElement("div");return n.innerHTML=e,m.S4.fromSchema(h.Y).parse(n)}function _(t){let e="";return t.forEach(t=>{if(t.isText){let n=t.marks.some(t=>"code"===t.type.name)?t.text??"":function(t){return t.replace(/([\\`*_[\]<>])/g,"\\$1")}(t.text??"");for(const e of t.marks)switch(e.type.name){case"code":n=`\`${t.text??""}\``;break;case"strong":n=`**${n}**`;break;case"em":n=`*${n}*`;break;case"strike":n=`~~${n}~~`;break;case"link":n=`[${n}](${e.attrs.href}${e.attrs.title?` "${e.attrs.title}"`:""})`}e+=n}else if("image"===t.type.name){const{src:n,alt:r,title:o}=t.attrs;e+=`![${r??""}](${n}${o?` "${o}"`:""})`}else"hard_break"===t.type.name&&(e+=" \n")}),e}function y(t){const e=[];if(t.forEach(t=>{const n=[],r=[];t.forEach(t=>{var e;n.push((e=t.textContent,e.replace(/\|/g,"\\|").replace(/\n/g," ")).trim()),r.push("table_header"===t.type.name)}),e.push({cells:n,header_flags:r})}),0===e.length)return"";const n=Math.max(...e.map(t=>t.cells.length)),r=e[0].header_flags.some(t=>t),o=Array.from({length:n},(t,n)=>Math.max(3,...e.map(t=>k(t.cells[n]??"")))),s=t=>`| ${Array.from({length:n},(e,n)=>{return r=t[n]??"",s=o[n],r+" ".repeat(Math.max(0,s-k(r)));var r,s}).join(" | ")} |`,a=[];if(r){a.push(s(e[0].cells)),a.push(`| ${o.map(t=>"-".repeat(t)).join(" | ")} |`);for(let t=1;t<e.length;t++)a.push(s(e[t].cells))}else{a.push(s(new Array(n).fill(""))),a.push(`| ${o.map(t=>"-".repeat(t)).join(" | ")} |`);for(const t of e)a.push(s(t.cells))}return a.join("\n")}function k(t){let e=0;for(const n of t){const t=n.codePointAt(0)??0;e+=t>=4352&&t<=4447||t>=11904&&t<=42191||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65072&&t<=65135||t>=65280&&t<=65376||t>=65504&&t<=65510?2:1}return e}function b(t,e=""){switch(t.type.name){case"paragraph":default:return e+_(t);case"heading":return`${e}${"#".repeat(t.attrs.level)} ${_(t)}`;case"blockquote":return w(t,"").split("\n").map(t=>`${e}> ${t}`).join("\n");case"code_block":{const n=t.attrs.language??"";return`${e}\`\`\`${n}\n${t.textContent}\n${e}\`\`\``}case"horizontal_rule":return`${e}---`;case"bullet_list":{const n=[];return t.forEach((t,r,o)=>{n.push(v(t,e,`${e}- `,`${e} `,o))}),n.join("\n")}case"ordered_list":{const n=[],r=t.attrs.order??1;return t.forEach((t,o,s)=>{n.push(v(t,e,`${e}${r+s}. `,`${e} `,s))}),n.join("\n")}case"table":return y(t).split("\n").map(t=>e+t).join("\n")}}function v(t,e,n,r,o){const s=t.attrs.checked,a=null===s?"":s?"[x] ":"[ ] ",c=[];t.forEach((t,e,n)=>{c.push(b(t,0===n?"":r))});const l=c.join("\n").split("\n");return n+a+l[0]+(l.length>1?"\n"+l.slice(1).join("\n"):"")}function w(t,e=""){const n=[];return t.forEach(t=>{n.push(b(t,e))}),n.join("\n\n")}function $(t){return w(t).trim()+"\n"}n(64877);var M=n(19878);const x=new o.hs("md_source_highlight");let O=!1;function S(t){O=t}function D(t,e,n){let r=e;for(const e of t){if("string"==typeof e){r+=e.length;continue}const t=r;Array.isArray(e.children)&&(r=D(e.children,r,n)),e.scope&&n.push({from:t,to:r,cls:`hljs-${e.scope}`})}return r}function A(t,e){const n=t.textContent;if(!n)return[];let r;try{r=M.A.highlight(n,{language:"markdown",ignoreIllegals:!0})}catch{return[]}const o=[],a=r._emitter?.rootNode;a?.children&&D(a.children,0,o);const c=e+1,l=[];for(const t of o){const e=Math.min(t.from,n.length),r=Math.min(t.to,n.length);e>=r||l.push(s.NZ.inline(c+e,c+r,{class:t.cls}))}return l}function C(t){const e=[];return t.descendants((t,n)=>"code_block"!==t.type.name||(e.push(...A(t,n)),!1)),s.zF.create(t,e)}var N=n(67951),j=(n(41631),n(50576),n(70432),n(74848));function z(t){return 0===t?(0,N.uf)("paragraph"):(0,N.uf)("heading",{level:t})}function E(t){return!(!t.ctrlKey&&!t.metaKey)}function F(t,e){return(0,u.D8)(1)(t,e)}const G=r.forwardRef(function(t,e){const n=(0,r.useRef)(null),p=(0,r.useRef)(null),m=(0,r.useRef)(t.on_change),f=(0,r.useRef)(t.on_save),_=(0,r.useRef)(t.on_selection_change),y=(0,r.useRef)(t.on_source_mode_change);return(0,r.useEffect)(()=>{m.current=t.on_change,f.current=t.on_save,_.current=t.on_selection_change,y.current=t.on_source_mode_change}),(0,r.useEffect)(()=>{if(!n.current)return;h.Y;const r=o.$t.create({doc:g(t.value??""),plugins:[(0,a.b6)(),new o.k_({key:x,state:{init:(t,e)=>s.zF.empty,apply:(t,e,n,r)=>O?t.docChanged?C(r.doc):x.getState(r)??s.zF.empty:s.zF.empty},props:{decorations(t){if(!O)return null;const e=x.getState(t);return e&&e.find().length?e:C(t.doc)}}}),(0,N.k5)(),(0,c.w)({"Mod-z":a.tN,"Mod-y":a.ZS,"Mod-Shift-z":a.ZS,"Mod-b":(0,N.NH)("strong"),"Mod-i":(0,N.NH)("em"),"Mod-Shift-x":(0,N.NH)("strike"),"Mod-`":(0,N.NH)("code"),"Mod-1":(t,e)=>z(1)(t,e),"Mod-2":(t,e)=>z(2)(t,e),"Mod-3":(t,e)=>z(3)(t,e),"Mod-0":(t,e)=>z(0)(t,e),"Mod-Shift-8":N.fK,"Mod-Shift-9":N.oB,"Mod-Shift-.":N.Vu,Tab:N.G8.sink,"Shift-Tab":N.G8.lift,"Mod-Enter":F,"Mod-s":()=>(f.current?.(),!0)}),(0,u.LF)({allowTableNodeSelection:!0}),(0,u.AL)(),(0,i.A)({color:"var(--primary, #1a73e8)",width:2}),(0,d.z)(),(0,c.w)({Enter:(0,l.st)(N.x0,l.pC,N.G8.split,l.Z1,l.iz,l.aw),"Shift-Enter":(t,e)=>{const{hard_break:n}=t.schema.nodes;return e&&e(t.tr.replaceSelectionWith(n.create()).scrollIntoView()),!0},"Mod-Enter":l.I$}),(0,c.w)(l.RV)]}),k=new s.Lz(n.current,{state:r,editable:()=>!1!==t.editable,handleClickOn(t,e,n,r,o){if(!E(o))return!1;const s=function(t){if(!(t instanceof Element))return null;const e=t.closest("a[href]"),n=e?.getAttribute("href");return n||null}(o.target)??function(t,e){const n=t.doc.content.size,r=Math.max(0,Math.min(e,n));let o;try{o=t.doc.resolve(r)}catch{return null}for(const e of[1,-1]){const o=1===e?r:r-1;if(!(o<0||o>=n))try{const e=t.doc.resolve(o).marks().find(t=>"link"===t.type.name);if(e?.attrs?.href)return e.attrs.href}catch{}}try{const t=o.parent.marks.find(t=>"link"===t.type.name);if(t?.attrs?.href)return t.attrs.href}catch{}return null}(t.state,e);return!!s&&(window.open(s,"_blank","noopener,noreferrer"),!0)},handleDOMEvents:{keydown:(t,e)=>{if(E(e)&&t.dom.classList.add("md-ctrl-down"),I(t.state.doc)&&"Enter"===e.key&&!e.ctrlKey&&!e.metaKey&&!e.altKey){e.preventDefault();const{from:n,to:r}=t.state.selection;return t.dispatch(t.state.tr.insertText("\n",n,r).scrollIntoView()),!0}return!1},keyup:(t,e)=>(E(e)||t.dom.classList.remove("md-ctrl-down"),!1),blur:t=>(t.dom.classList.remove("md-ctrl-down"),!1),beforeinput:(t,e)=>{if(!I(t.state.doc))return!1;const n=e;if("insertText"!==n.inputType)return!1;const r=n.data;if(null==r)return!1;n.preventDefault();const{from:o,to:s}=t.state.selection;return t.dispatch(t.state.tr.insertText(r.replace(/\r\n?/g,"\n"),o,s).scrollIntoView()),!0}},dispatchTransaction(t){const e=k.state.apply(t);k.updateState(e);const n=I(e.doc);S(n),n?k.dom.classList.add("md-source-mode"):k.dom.classList.remove("md-source-mode"),n!==I(t.before)&&y.current?.(n),t.docChanged&&m.current?.(n?e.doc.textContent:$(e.doc)),(t.selectionSet||t.docChanged)&&_.current?.()},attributes:{class:"md-filecat-content",spellcheck:"false"}});if(p.current=k,t.initial_source_mode&&!I(k.state.doc)){const t=$(k.state.doc),e=k.state.schema.nodes.code_block.create({language:"markdown"},t?k.state.schema.text(t):null),n=k.state.tr;n.replaceWith(0,k.state.doc.content.size,e),n.setMeta("addToHistory",!1),k.dispatch(n)}const b={get_markdown:()=>I(k.state.doc)?k.state.doc.textContent:$(k.state.doc),set_markdown:t=>{const e=g(t);k.dispatch(k.state.tr.replaceWith(0,k.state.doc.content.size,e.content))},focus:()=>k.focus(),get_view:()=>p.current,in_table:()=>function(t){const{$from:e}=t.selection;for(let t=e.depth;t>0;t--){if("table"===e.node(t).type.name)return!0}return!1}(k.state),active_marks:()=>(k.state.storedMarks??k.state.selection.$from.marks()).map(t=>t.type.name),active_block:()=>{const{$from:t}=k.state.selection;for(let e=t.depth;e>0;e--){const n=t.node(e);if("heading"===n.type.name)return{name:"heading",level:n.attrs.level};if("paragraph"===n.type.name)return{name:"paragraph"}}return{name:"paragraph"}},insert_table:(t=3,e=3)=>{const n=function(t,e,n){const r=(0,u.e)(t),o=r.table,s=r.row,a=r.cell,c=r.header_cell??r.cell;if(!o||!s||!a)return null;const l=t=>s.create(null,Array.from({length:e},()=>t.createAndFill())),i=l(c),d=Array.from({length:n},()=>l(a));return o.create(null,[i,...d])}(k.state.schema,t,e);if(!n)return;const{from:r}=k.state.selection,o=k.state.doc.resolve(r);let s=r;for(let t=o.depth;t>0;t--)if("table"===o.node(t).type.name){s=o.after(t);break}const a=k.state.tr;s===r?a.replaceSelectionWith(n):a.insert(s,n),k.dispatch(a.scrollIntoView());const c=k.state.doc.resolve(Math.min(s+3,k.state.doc.content.size));try{k.dispatch(k.state.tr.setSelection(k.state.selection.constructor.near(c)))}catch{}},get_headings:()=>function(t){const e=[];return t.doc.descendants((t,n)=>("heading"!==t.type.name||e.push({level:t.attrs.level,text:t.textContent,pos:n}),!0)),e}(k.state),scroll_to_pos:t=>{const e=k.state.doc.content.size,n=Math.max(0,Math.min(t,e)),r=k.state.doc.nodeAt(n);let s;try{s=r?o.U3.near(k.state.doc.resolve(n+1),1):o.U3.near(k.state.doc.resolve(n),1)}catch{s=o.U3.near(k.state.doc.resolve(0),1)}k.dispatch(k.state.tr.setSelection(s).scrollIntoView()),k.focus()},is_source_mode:()=>I(k.state.doc),enter_source_mode:()=>{if(I(k.state.doc))return;const t=$(k.state.doc),e=k.state.schema.nodes.code_block.create({language:"markdown"},t?k.state.schema.text(t):null),n=k.state.tr;n.replaceWith(0,k.state.doc.content.size,e),S(!0),k.dispatch(n),k.dom.classList.add("md-source-mode")},exit_source_mode:()=>{if(!I(k.state.doc))return;const t=g(k.state.doc.textContent),e=k.state.tr;e.replaceWith(0,k.state.doc.content.size,t.content),S(!1),k.dispatch(e),k.dom.classList.remove("md-source-mode")}};return"function"==typeof e?e(b):e&&(e.current=b),t.on_ready?.(b),()=>{k.destroy(),p.current=null}},[]),(0,j.jsx)("div",{className:"md-filecat",ref:n})});function I(t){if(1!==t.childCount)return!1;const e=t.firstChild;return!!e&&"code_block"===e.type.name&&"markdown"===e.attrs.language}const T=G},67951(t,e,n){n.d(e,{NH:()=>i,k5:()=>l,uf:()=>d});var r=n(38341),o=n(5091),s=n(46762),a=n(3772);function c(t,e){return new r.fV(t,(t,n,r,o)=>{const s=t.schema.marks[e],a=n[1];if(!s||!a)return null;const c=n[0].indexOf(a);if(c<0)return null;const l=r+c,i=l+a.length,d=t.tr;return d.delete(i,o),d.delete(r,l),d.addMark(r,r+a.length,s.create()),d.removeStoredMark(s),d})}function l(){const t=o.Y;return(0,r.sM)({rules:[(0,r.JJ)(/^(#{1,6})\s$/,t.nodes.heading,t=>({level:t[1].length})),(0,r.JJ)(/^#([1-6])\s$/,t.nodes.heading,t=>({level:Number(t[1])})),(0,r.JJ)(/^```([\w-]*)\s$/,t.nodes.code_block,t=>({language:t[1]??""})),(0,r.tG)(/^\s*>\s$/,t.nodes.blockquote),(0,r.tG)(/^\s*([-+*])\s$/,t.nodes.bullet_list),(0,r.tG)(/^(\d+)\.\s$/,t.nodes.ordered_list,t=>({order:Number(t[1])})),c(/(?:\*\*)([^*]+)(?:\*\*)$/,"strong"),c(/(?:__)([^_]+)(?:__)$/,"strong"),c(/(?<![*])\*([^*]+)\*$/,"em"),c(/(?<![_])_([^_]+)_$/,"em"),c(/(?:~~)([^~]+)(?:~~)$/,"strike"),c(/(?:`)([^`]+)(?:`)$/,"code"),...r.Fr,r.gO]})}function i(t){return(e,n)=>{const r=e.schema.marks[t];return!!r&&(0,s.wh)(r)(e,n)}}function d(t,e={}){return(n,r)=>{const o=n.schema.nodes[t];if(!o)return!1;const{$from:s,$to:a}=n.selection,c=s.blockRange(a);if(!c)return!1;const l=s.parent,i=l.type===o&&Object.entries(e).every(([t,e])=>l.attrs[t]===e),d=i?n.schema.nodes.paragraph:o,u=i?{}:e;return r&&r(n.tr.setBlockType(c.start,c.end,d,u)),!0}}const u=(t,e)=>(0,a.Sd)(t.schema.nodes.bullet_list)(t,e),h=(t,e)=>(0,a.Sd)(t.schema.nodes.ordered_list)(t,e),p={sink:(0,a.$B)(o.Y.nodes.list_item),lift:(0,a.T2)(o.Y.nodes.list_item),split:(0,a.wn)(o.Y.nodes.list_item),wrap_bullet:u,wrap_ordered:h};n.d(e,["G8",0,p,"Vu",0,(t,e)=>{const{blockquote:n}=t.schema.nodes,{$from:r,$to:o}=t.selection,s=r.blockRange(o);if(!s)return!1;if(s.parent.type===n&&s.depth>0){const n=r.before(s.depth),o=t.tr.doc.nodeAt(n);if(o&&1===o.childCount)return e&&e(t.tr.replaceWith(n,n+o.nodeSize,o.child(0)).scrollIntoView()),!0;if(e){const n=t.tr,o=r.parent,a=r.after(s.depth);n.delete(s.start,s.end),n.insert(a,o),e(n.scrollIntoView())}return!0}return e&&e(t.tr.wrap(s,[{type:n}]).scrollIntoView()),!0},"fK",0,u,"oB",0,h,"x0",0,(t,e)=>{const{$from:n,empty:r}=t.selection;if(!r||"paragraph"!==n.parent.type.name)return!1;const o=n.parent.textContent;if(!o.trim())return!1;const s=function(t){const e=t.trim(),n=/^#([1-6])$/.exec(e);if(n)return{type:"heading",attrs:{level:Number(n[1])}};const r=/^(#{1,6})$/.exec(e);if(r)return{type:"heading",attrs:{level:r[1].length}};const o=/^```([\w-]*)$/.exec(e);return o?{type:"code_block",attrs:{language:o[1]??""}}:/^(?:-{3,}|\*{3,}|_{3,})$/.test(e.replace(/\s+/g,""))?{type:"horizontal_rule"}:/^>\s*$/.test(e)?{type:"blockquote"}:/^[-+*]\s*$/.test(e)?{type:"bullet_list"}:/^\d+[.)]?$/.test(e)?{type:"ordered_list"}:null}(o);if(!s)return!1;if("blockquote"===s.type&&n.depth>1)return!1;const a=t.schema.nodes[s.type];if(!a)return!1;const c=n.before(n.depth),l=n.after(n.depth);if(e){const n=t.tr,r=a.createAndFill(s.attrs)??a.create(s.attrs);n.replaceWith(c,l,r),n.scrollIntoView(),e(n)}return!0}])},96763(t,e,n){n.d(e,{Kz:()=>a,P7:()=>i,_8:()=>h,_D:()=>u,bN:()=>s,sO:()=>d});var r=n(14284),o=n(53459);function s(t,e){const n="md-theme-style-"+t,r=document.getElementById(n);if(!e)return void r?.remove();let o=r;o||(o=document.createElement("style"),o.id=n,document.head.appendChild(o)),o.textContent=e}async function a(){try{const t=await r.XO.get("md_theme/list");return t?.code===o.m.Success?t.data??[]:[]}catch(t){return[]}}const c="md-theme-change";function l(){window.dispatchEvent(new Event(c))}async function i(t){try{const e=await r.XO.get(`md_theme/get?id=${encodeURIComponent(t)}`);return e?.code===o.m.Success?e.data??"":""}catch(t){return""}}async function d(){try{const t=await r.XO.get("md_theme/active");return t?.code===o.m.Success?t.data??"":""}catch(t){return""}}async function u(t){const e=await r.XO.post("md_theme/save",t);return e?.code!==o.m.Success?null:(l(),e.data)}async function h(t){const e=await r.XO.post("md_theme/del",{id:t});return e?.code===o.m.Success&&(l(),!0)}n.d(e,["o3",0,c])},5091(t,e,n){var r=n(58903);const o=(0,n(86059).of)({tableGroup:"block",cellContent:"block+",cellAttributes:{}}),s={align:{default:null}},a={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",attrs:s,parseDOM:[{tag:"p"}],toDOM:t=>["p",t.attrs.align?{style:`text-align:${t.attrs.align}`}:{},0]},heading:{content:"inline*",group:"block",attrs:{level:{default:1},...s},defining:!0,parseDOM:[1,2,3,4,5,6].map(t=>({tag:`h${t}`,attrs:{level:t}})),toDOM(t){const e=t.attrs.align?{style:`text-align:${t.attrs.align}`}:{};return[`h${t.attrs.level}`,e,0]}},bullet_list:{group:"block",content:"list_item+",parseDOM:[{tag:"ul"}],toDOM:()=>["ul",0]},ordered_list:{group:"block",content:"list_item+",attrs:{order:{default:1}},parseDOM:[{tag:"ol",getAttrs:t=>({order:Number(t.getAttribute("start")??1)})}],toDOM:t=>1===t.attrs.order?["ol",0]:["ol",{start:t.attrs.order},0]},list_item:{content:"paragraph block*",defining:!0,attrs:{checked:{default:null}},parseDOM:[{tag:"li",getAttrs:t=>{const e=t,n=e.querySelector("input[type=checkbox]");if(n)return{checked:n.checked};const r=e.getAttribute("data-checked");return{checked:null===r?null:"true"===r}}}],toDOM:t=>null!==t.attrs.checked?["li",{"data-checked":String(t.attrs.checked)},0]:["li",0]},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:()=>["blockquote",0]},code_block:{content:"text*",group:"block",marks:"",defining:!0,attrs:{language:{default:""}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:t=>{const e=t.querySelector("code"),n=/language-([\w-]+)/.exec(e?.className??"");return{language:n?n[1]:""}}}],toDOM:t=>["pre",{"data-language":t.attrs.language},["code",0]]},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM:()=>["hr"]},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM:()=>["br"]},image:{inline:!0,group:"inline",draggable:!0,attrs:{src:{},alt:{default:null},title:{default:null}},parseDOM:[{tag:"img[src]",getAttrs:t=>{const e=t;return{src:e.getAttribute("src"),alt:e.getAttribute("alt"),title:e.getAttribute("title")}}}],toDOM(t){const{src:e,alt:n,title:r}=t.attrs,o={src:e};return n&&(o.alt=n),r&&(o.title=r),["img",o]}},text:{group:"inline"},...o},c={strong:{parseDOM:[{tag:"strong"},{tag:"b"},{style:"font-weight=bold"}],toDOM:()=>["strong",0]},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"}],toDOM:()=>["em",0]},strike:{parseDOM:[{tag:"s"},{tag:"del"},{tag:"strike"}],toDOM:()=>["s",0]},code:{parseDOM:[{tag:"code",getAttrs:t=>"PRE"!==t.parentElement?.tagName&&null}],toDOM:()=>["code",0]},link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs:t=>{const e=t;return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM(t){const{href:e,title:n}=t.attrs;return["a",{href:e,title:n,rel:"noopener noreferrer",target:"_blank"},0]}}},l=new r.Sj({nodes:a,marks:c});n.d(e,["Y",0,l])}}]);
@@ -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" href="{{{logo_favicon}}}"/><script defer="defer" src="main.62150e46f9d1c96fa5bf.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" href="{{{logo_favicon}}}"/><script defer="defer" src="main.8cdfbbc725aa2f58f68e.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>