filecat 7.8.0 → 7.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/build/dist/1075.40103ec059c6b23b056e.js +1 -0
  2. package/build/dist/1417.7e511043474084a2a65b.js +1 -0
  3. package/build/dist/2479.dcc88b3370f0f1d66e02.js +1 -0
  4. package/build/dist/2674.7fd28dae86ccdb247851.js +1 -0
  5. package/build/dist/{3299.d01f5a742d80f4e6e25b.js → 3299.f37767d30b6999df4014.js} +1 -1
  6. package/build/dist/4004.5d68418ad5c2321cb11f.js +1 -0
  7. package/build/dist/{4903.407cafe944a297471f5a.js → 4903.b5451ed0802b3f7c07b2.js} +1 -1
  8. package/build/dist/6010.5400c344149450c83284.js +1 -0
  9. package/build/dist/7943.19d2de387eeb7f513d8e.js +1 -0
  10. package/build/dist/{7954.6ce241a8ed27cb26efc6.js → 8014.28b5cf8c3787dc829aa4.js} +1 -1
  11. package/build/dist/{8302.c1c381630b4ec76bf8ab.js → 8302.5ae5bfe8baa0084204bb.js} +1 -1
  12. package/build/dist/8781.58f0c51870d3dd2689d7.js +1 -0
  13. package/build/dist/9299.6c06dad1abe098b61766.js +1 -0
  14. package/build/dist/index.html +1 -1
  15. package/build/dist/main.3a12152528aff6ae213a.js +2 -0
  16. package/build/main.js +1 -1
  17. package/package.json +1 -1
  18. package/build/dist/1075.493acb74297c1e753de2.js +0 -1
  19. package/build/dist/2479.15722ac55b05c521f4f7.js +0 -1
  20. package/build/dist/2674.0c822a9c458f923a4eff.js +0 -1
  21. package/build/dist/4004.de90f1192487a24a0a9a.js +0 -1
  22. package/build/dist/4437.4d5a0965043471411a00.js +0 -1
  23. package/build/dist/6010.2da6f8c2fce5292557cb.js +0 -1
  24. package/build/dist/7943.54c702542d55f576a576.js +0 -1
  25. package/build/dist/9299.ed4de6cd4f4bfa0a966a.js +0 -1
  26. package/build/dist/main.98bb29605335d9b2219f.js +0 -2
  27. /package/build/dist/{main.98bb29605335d9b2219f.js.LICENSE.txt → main.3a12152528aff6ae213a.js.LICENSE.txt} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filecat",
3
- "version": "7.8.0",
3
+ "version": "7.9.0",
4
4
  "description": "File browser and server manager",
5
5
  "author": "xiaobaidadada",
6
6
  "repository": {
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[1075,4877],{69918(t,e,n){n.d(e,{Ce:()=>i,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 i(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.r(e),n.d(e,{default:()=>a});var r=n(96540),o=n(22022),s=n(74848);function a(t){const{t:e}=(0,o.Bd)(),[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]),i=(r,o)=>r.map(r=>{const c=r.children.length>0,l=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?l?"arrow_right":"arrow_drop_down":""}),(0,s.jsx)("span",{className:"md-outline-text",children:r.text||e("未命名标题")})]}),c&&!l&&i(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:i(c,0)})})}},76118(t,e,n){n.d(e,{A:()=>Q});var r=n(96540),o=n(42845),s=n(1575),a=n(89781),c=n(61396),i=n(46762),l=n(73337),d=n(89552),u=n(86059),h=n(5091),m=n(23802),p=n(58903),f=n(41105),g=n(89334);const _=new m.A({html:!0,linkify:!0,breaks:!1,typographer:!1});_.renderer.rules.html_block=(t,e)=>`<div data-html-block="${(0,f.pC)(t[e].content)}"></div>`,_.renderer.rules.html_inline=(t,e)=>`<span data-html-inline="${(0,f.pC)(t[e].content)}"></span>`,_.inline.ruler.before("escape","math_inline",function(t,e){const n=t.pos,r=t.src,o=[{open:"\\(",close:"\\)"},{open:"$",close:"$"}];if(r.startsWith("$$",n))return!1;for(const s of o){if(!r.startsWith(s.open,n))continue;const o=n+s.open.length,a=r.indexOf(s.close,o);if(a<0)continue;const c=r.slice(o,a);if(c.trim()){if("$"===s.open){const t=r[a+1];if(void 0!==t&&/\d/.test(t))continue}if(!e){const e=t.push("math_inline","span",0);e.content=c,e.markup=s.open,e.meta={raw:r.slice(n,a+s.close.length)}}return t.pos=a+s.close.length,!0}}return!1}),_.block.ruler.before("fence","math_block",function(t,e,n,r){const o=t.bMarks[e]+t.tShift[e],s=t.eMarks[e],a=t.src.slice(o,s).trim(),c=[{open:"\\[",close:"\\]"},{open:"$$",close:"$$"}];for(const s of c){if(!a.startsWith(s.open))continue;if(a.endsWith(s.close)&&a.length>s.open.length+s.close.length){if(r)return!0;const n=a.slice(s.open.length,a.length-s.close.length),o=t.push("math_block","div",0);return o.content=n,o.markup=s.open,o.meta={raw:a},o.map=[e,e+1],t.line=e+1,!0}const c=a.slice(s.open.length);for(let a=e+1;a<n;a++){const n=t.bMarks[a]+t.tShift[a],i=t.eMarks[a],l=t.src.slice(n,i);if(!l.trimEnd().endsWith(s.close))continue;if(r)return!0;const d=[c,...t.getLines(e+1,a,t.tShift[e],!1).split("\n")].filter((t,e)=>!(0===e&&!t.trim())),u=l.trimEnd().slice(0,-s.close.length);d.push(u);const h=t.push("math_block","div",0);return h.content=d.join("\n").trim(),h.markup=s.open,h.map=[e,a+1],h.meta={raw:t.src.slice(o,t.eMarks[a]).trimEnd()},t.line=a+1,!0}}return!1},{alt:["paragraph","reference","blockquote","list"]}),_.renderer.rules.math_inline=(t,e)=>`<span data-math-inline="${(0,f.pC)(t[e].meta.raw)}"></span>`,_.renderer.rules.math_block=(t,e)=>`<div data-math-block="${(0,f.pC)(t[e].meta.raw)}"></div>`;const b=_.renderer.rules.fence;function k(t){const e=_.render(t??""),n=document.createElement("div");return n.innerHTML=e,p.S4.fromSchema(h.Y).parse(n)}function v(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":"html_inline"===t.type.name?e+=t.attrs.value:"math_inline"===t.type.name&&(e+=t.attrs.raw)}),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=>w(t.cells[n]??"")))),s=t=>`| ${Array.from({length:n},(e,n)=>{return r=t[n]??"",s=o[n],r+" ".repeat(Math.max(0,s-w(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 w(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 $(t,e=""){switch(t.type.name){case"paragraph":default:return e+v(t);case"heading":return`${e}${"#".repeat(t.attrs.level)} ${v(t)}`;case"blockquote":return x(t,"").split("\n").map(t=>`${e}> ${t}`).join("\n");case"code_block":{const n=t.attrs.language??"",r=t.textContent;let o=3;for(const t of r.match(/`+/g)??[])o=Math.max(o,t.length+1);const s="`".repeat(o),a=r.split("\n").map(t=>e+t).join("\n");return`${e}${s}${n}\n${a}\n${e}${s}`}case"horizontal_rule":return`${e}---`;case"html_block":return t.attrs.value.replace(/\n+$/,"").split("\n").map(t=>e+t).join("\n");case"math_block":return t.attrs.raw.replace(/\n+$/,"").split("\n").map(t=>e+t).join("\n");case"bullet_list":{const n=[];return t.forEach((t,r,o)=>{n.push(M(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(M(t,e,`${e}${r+s}. `,`${e} `,s))}),n.join("\n")}case"table":return y(t).split("\n").map(t=>e+t).join("\n")}}function M(t,e,n,r,o){const s=t.attrs.checked,a=null===s?"":s?"[x] ":"[ ] ",c=[];t.forEach((t,e,n)=>{c.push($(t,0===n?"":r))});const i=c.join("\n").split("\n");return n+a+i[0]+(i.length>1?"\n"+i.slice(1).join("\n"):"")}function x(t,e=""){const n=[];return t.forEach(t=>{n.push($(t,e))}),n.join("\n\n")}function A(t){return x(t).trim()+"\n"}_.renderer.rules.fence=(t,e,n,r,o)=>{const s=t[e],a=s.info.trim().toLowerCase();return(0,g.lG)(a)?`<div data-math-block="${(0,f.pC)(`$$\n${s.content.trim()}\n$$`)}"></div>`:b(t,e,n,r,o)};n(64877);var E=n(19878);const O=new o.hs("md_source_highlight");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 S(t,e){const n=t.textContent;if(!n)return[];const r=t.attrs.language??"";if(!r||!E.A.getLanguage(r))return[];let o;try{o=E.A.highlight(n,{language:r,ignoreIllegals:!0})}catch{return[]}const a=[],c=o._emitter?.rootNode;c?.children&&D(c.children,0,a);const i=e+1,l=[];for(const t of a){const e=Math.min(t.from,n.length),r=Math.min(t.to,n.length);e>=r||l.push(s.NZ.inline(i+e,i+r,{class:t.cls}))}return l}function N(){return new o.k_({key:O,props:{decorations(t){const e=function(t){const e=[];return t.descendants((t,n)=>"code_block"!==t.type.name||(e.push(...S(t,n)),!1)),s.zF.create(t,e)}(t.doc);return e.find().length?e:null}}})}var C=n(89117),L=n(52388);const z=new o.hs("md-graph"),j=new Map,T=new Map;function R(t,e){return`${t}\0${e}`}function V(t,e){if(e.error)return t.className="md-graph__body",void(t.textContent=e.error);t.className="md-graph__body",t.innerHTML=e.svg}function G(t,e,n,r){const s=document.createElement("div");s.className="md-graph",s.setAttribute("contenteditable","false");const a=document.createElement("div");a.className="md-graph__body",a.addEventListener("click",()=>{const n=j.get(R(e,t));n&&!n.error&&n.svg&&function(t){const e=document.createElement("div");e.className="md-graph-zoom";const n=document.createElement("div");n.className="md-graph-zoom__body",n.innerHTML=t;const r=document.createElement("button");r.className="md-graph-zoom__close",r.type="button",r.title=L.A.t("取消"),r.innerHTML='<i class="material-icons">close</i>';const o=t=>{"Escape"===t.key&&s()};function s(){document.removeEventListener("keydown",o),e.remove()}e.addEventListener("click",t=>{t.target===e&&s()}),r.addEventListener("click",s),document.addEventListener("keydown",o),e.append(n,r),document.body.appendChild(e)}(n.svg)});const c=document.createElement("button");c.className="md-graph__edit",c.type="button",c.textContent=L.A.t("clk_edt"),c.addEventListener("click",t=>{t.stopPropagation(),function(t,e){if(!t)return;const n=Math.min(e+1,t.state.doc.content.size);t.dispatch(t.state.tr.setSelection(o.U3.near(t.state.doc.resolve(n),1))),t.focus()}(r(),n)}),s.append(a,c);const i=j.get(R(e,t));return i?(i.error&&s.classList.add("md-graph--error"),V(a,i),s):(s.classList.add("md-graph--loading"),a.textContent=L.A.t("rendering"),function(t,e){const n=R(t,e),r=j.get(n);if(r)return Promise.resolve(r);let o=T.get(n);return o||(o=(0,C.U6)(t,e).then(t=>(j.set(n,t),T.delete(n),t)),T.set(n,o)),o}(e,t).then(t=>{s.isConnected&&(s.classList.remove("md-graph--loading"),t.error&&s.classList.add("md-graph--error"),V(a,t))}),s)}function I(){let t=null;return new o.k_({key:z,props:{decorations(e){const n=function(t,e){const n=[],{from:r,to:o}=t.selection;return t.doc.descendants((t,a)=>{if("code_block"!==t.type.name)return;const c=t.attrs.language;if(!(0,C.Hm)(c))return;const i=a,l=a+t.nodeSize;if(function(t,e,n,r){return t<=r&&e>=n}(r,o,i,l))return;const d=t.textContent;d.trim()&&(n.push(s.NZ.node(i,l,{class:"md-graph-hidden"})),n.push(s.NZ.widget(l,()=>G(d,c,i,e),{side:-1,ignoreSelection:!0,key:`graph-${c}-${i}-${d}`})))}),s.zF.create(t.doc,n)}(e,()=>t);return n.find().length?n:null}},view:e=>(t=e,{destroy(){t=null}})})}const P=new Map;class q{dom;node;view;get_pos;render_box;source_input;editing=!1;draft=null;painted_raw="";constructor(t,e,n){this.node=t,this.view=e,this.get_pos=n;const r="math_block"===t.type.name;this.dom=document.createElement(r?"div":"span"),this.dom.className=r?"md-math md-math--block":"md-math md-math--inline",this.dom.setAttribute("contenteditable","false"),this.render_box=document.createElement("span"),this.render_box.className="md-math__render",this.source_input=document.createElement("textarea"),this.source_input.className="md-math__source",this.source_input.setAttribute("spellcheck","false"),this.source_input.setAttribute("wrap","off"),this.source_input.setAttribute("rows","1"),this.dom.append(this.render_box,this.source_input),function(t,e){P.set(t,e)}(n(),this),this.source_input.addEventListener("input",()=>{this.draft=this.source_input.value,this.auto_size()}),this.source_input.addEventListener("blur",()=>this.commit()),this.source_input.addEventListener("keydown",t=>{t.stopPropagation(),"Escape"===t.key&&(t.preventDefault(),this.draft=null,this.set_editing(!1))});for(const t of["beforeinput","paste","input","keyup","keypress"])this.source_input.addEventListener(t,t=>t.stopPropagation());this.render_box.addEventListener("mousedown",t=>{t.preventDefault(),t.stopPropagation(),this.focus_source()}),this.paint(t)}paint(t){const e=t.attrs.raw;if(this.editing)return this.dom.setAttribute("data-mode","source"),null===this.draft&&(this.source_input.value=e),void this.auto_size();if(this.dom.setAttribute("data-mode","preview"),this.painted_raw===e)return;this.painted_raw=e;const n=this.render_box;n.classList.add("md-math--loading"),n.textContent="",n.textContent=e,(0,g.z$)(n,t.attrs.tex,"math_block"===t.type.name?"block":"inline",e)}auto_size(){const t=this.source_input;t.style.height="0px",t.style.height=`${t.scrollHeight}px`}focus_source(){this.editing||(this.set_editing(!0),this.source_input.focus(),this.source_input.setSelectionRange(this.source_input.value.length,this.source_input.value.length))}set_editing(t){this.editing!==t&&(this.editing=t,this.paint(this.node))}set_selected(t){t?this.focus_source():this.editing&&(this.commit(),this.set_editing(!1))}commit(){if(null===this.draft)return;const t=this.draft;if(this.draft=null,t===this.node.attrs.raw)return;const e=this.get_pos(),n=this.view.state.doc.nodeAt(e);if(!n)return;const r=(0,g.V)(t),o=r?.tex??t;this.view.dispatch(this.view.state.tr.setNodeMarkup(e,void 0,{...n.attrs,raw:t,tex:o})),this.painted_raw=""}update(t){if(t.type!==this.node.type)return!1;const e=t.attrs.raw!==this.node.attrs.raw;return this.node=t,e&&(this.draft=null,this.painted_raw=""),this.paint(t),!0}stopEvent(t){return this.dom.contains(t.target)}ignoreMutation(){return!0}destroy(){this.draft=null,function(t){for(const[e,n]of P)if(n===t)return void P.delete(e)}(this)}}function F(t){const e=t.state.selection,n=e.from,r=e.to;for(const[t,e]of P){const o=r>t&&n<=t+1;e.set_selected(o)}}var W=n(67951),H=(n(41631),n(50576),n(70432),n(74848));function K(t){return 0===t?(0,W.uf)("paragraph"):(0,W.uf)("heading",{level:t})}function B(t){return!(!t.ctrlKey&&!t.metaKey)}function U(t,e){let n=null;try{const r=t.domAtPos(e).node,o=1===r.nodeType?r:r.parentElement;n=o?o.closest(".md-filecat-content > *")??o:null}catch{}if(!n)return;const r=n.closest(".md-editor-scroll");if(!r)return;const o=parseFloat(getComputedStyle(n).scrollMarginTop)||0,s=r.scrollTop+n.getBoundingClientRect().top-r.getBoundingClientRect().top-o,a=r.scrollHeight-r.clientHeight;!function(t,e){const n=t.scrollTop,r=e-n;if(Math.abs(r)<1)return;const o=performance.now(),s=e=>{const a=Math.min(1,(e-o)/500);t.scrollTop=n+r*(1-Math.pow(1-a,3)),a<1&&requestAnimationFrame(s)};requestAnimationFrame(s)}(r,Math.max(0,Math.min(s,a)))}function X(t,e){return(0,u.D8)(1)(t,e)}const Y=r.forwardRef(function(t,e){const n=(0,r.useRef)(null),m=(0,r.useRef)(null),p=(0,r.useRef)(t.on_change),g=(0,r.useRef)(t.on_save),_=(0,r.useRef)(t.on_selection_change),b=(0,r.useRef)(t.on_source_mode_change);return(0,r.useEffect)(()=>{p.current=t.on_change,g.current=t.on_save,_.current=t.on_selection_change,b.current=t.on_source_mode_change}),(0,r.useEffect)(()=>{if(!n.current)return;h.Y;const r=o.$t.create({doc:k(t.value??""),plugins:[(0,a.b6)(),N(),I(),new o.k_({view:t=>(F(t),{update:(t,e)=>{t.state.selection===e.selection&&t.state.doc===e.doc||F(t)}})}),(0,W.k5)(),(0,c.w)({"Mod-a":W.Rx,"Mod-z":a.tN,"Mod-y":a.ZS,"Mod-Shift-z":a.ZS,"Mod-b":(0,W.NH)("strong"),"Mod-i":(0,W.NH)("em"),"Mod-Shift-x":(0,W.NH)("strike"),"Mod-`":(0,W.NH)("code"),"Mod-1":(t,e)=>K(1)(t,e),"Mod-2":(t,e)=>K(2)(t,e),"Mod-3":(t,e)=>K(3)(t,e),"Mod-0":(t,e)=>K(0)(t,e),"Mod-Shift-8":W.fK,"Mod-Shift-9":W.oB,"Mod-Shift-.":W.Vu,Tab:W.G8.sink,"Shift-Tab":W.G8.lift,"Mod-Enter":X,"Mod-s":()=>(g.current?.(),!0)}),(0,u.LF)({allowTableNodeSelection:!0}),(0,u.AL)(),(0,l.A)({color:"var(--primary, #1a73e8)",width:2}),(0,d.z)(),(0,c.w)({Enter:(0,i.st)(W.x0,i.pC,W.G8.split,i.Z1,i.iz,i.aw),"Shift-Enter":(t,e)=>{const{hard_break:n}=t.schema.nodes;return e&&e(t.tr.replaceSelectionWith(n.create()).scrollIntoView()),!0},"Mod-Enter":i.I$}),(0,c.w)(i.RV)]});(0,f.sL)(t.doc_path?t.doc_path.replace(/[^/]*$/,""):"");const v=t=>t.setAttribute("data-img-error",""),y=t=>"IMG"===t.tagName&&!t.classList.contains("ProseMirror-separator"),w=t=>{const e=t.target;"IMG"===e?.tagName&&y(e)&&v(e)},$=t=>{const e=t.target;"IMG"===e?.tagName&&y(e)&&(t=>{t.removeAttribute("data-img-error")})(e)},M=n.current;M.addEventListener("error",w,!0),M.addEventListener("load",$,!0);const x=()=>{M.querySelectorAll("img").forEach(t=>{if(!y(t))return;const e=t;e.dataset.imgSeen||(e.dataset.imgSeen="1",e.complete?0===e.naturalWidth&&v(e):v(e))})},E=new MutationObserver(()=>{requestAnimationFrame(x)});E.observe(M,{childList:!0,subtree:!0}),x();let O=null;if(O=new s.Lz(n.current,{state:r,editable:()=>!1!==t.editable,nodeViews:{...(0,f.op)(),math_block:(t,e,n)=>new q(t,e,n),math_inline:(t,e,n)=>new q(t,e,n)},handleClickOn(t,e,n,r,o){if(!B(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)},handlePaste(t,e){const n=e.clipboardData?.getData("text/plain");if(!n)return!1;const{from:r,to:o}=t.state.selection;return!(!Z(t.state.doc,r)||!Z(t.state.doc,o))&&(t.dispatch(t.state.tr.insertText(n.replace(/\r\n?/g,"\n"),r,o).scrollIntoView()),!0)},handleDOMEvents:{keydown:(t,e)=>{if(B(e)&&t.dom.classList.add("md-ctrl-down"),J(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)=>(B(e)||t.dom.classList.remove("md-ctrl-down"),!1),blur:t=>(t.dom.classList.remove("md-ctrl-down"),!1),beforeinput:(t,e)=>{if(!J(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=O.state.apply(t);O.updateState(e);const n=J(e.doc);n?O.dom.classList.add("md-source-mode"):O.dom.classList.remove("md-source-mode"),n!==J(t.before)&&b.current?.(n),t.docChanged&&p.current?.(n?e.doc.textContent:A(e.doc)),(t.selectionSet||t.docChanged)&&_.current?.()},attributes:{class:"md-filecat-content",spellcheck:"false"}}),m.current=O,t.initial_source_mode&&!J(O.state.doc)){const t=A(O.state.doc),e=O.state.schema.nodes.code_block.create({language:"markdown"},t?O.state.schema.text(t):null),n=O.state.tr;n.replaceWith(0,O.state.doc.content.size,e),n.setMeta("addToHistory",!1),O.dispatch(n)}const D={get_markdown:()=>J(O.state.doc)?O.state.doc.textContent:A(O.state.doc),set_markdown:t=>{const e=k(t);O.dispatch(O.state.tr.replaceWith(0,O.state.doc.content.size,e.content))},focus:()=>O.focus(),get_view:()=>m.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}(O.state),active_marks:()=>(O.state.storedMarks??O.state.selection.$from.marks()).map(t=>t.type.name),active_block:()=>{const{$from:t}=O.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 i=t=>s.create(null,Array.from({length:e},()=>t.createAndFill())),l=i(c),d=Array.from({length:n},()=>i(a));return o.create(null,[l,...d])}(O.state.schema,t,e);if(!n)return;const{from:r}=O.state.selection,o=O.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=O.state.tr;s===r?a.replaceSelectionWith(n):a.insert(s,n),O.dispatch(a.scrollIntoView());const c=O.state.doc.resolve(Math.min(s+3,O.state.doc.content.size));try{O.dispatch(O.state.tr.setSelection(O.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}(O.state),scroll_to_pos:t=>{const e=O.state.doc.content.size,n=Math.max(0,Math.min(t,e)),r=O.state.doc.nodeAt(n);let s;try{s=r?o.U3.near(O.state.doc.resolve(n+1),1):o.U3.near(O.state.doc.resolve(n),1)}catch{s=o.U3.near(O.state.doc.resolve(0),1)}O.dispatch(O.state.tr.setSelection(s)),U(O,s.from),O.focus()},is_source_mode:()=>J(O.state.doc),enter_source_mode:()=>{if(J(O.state.doc))return;const t=A(O.state.doc),e=O.state.schema.nodes.code_block.create({language:"markdown"},t?O.state.schema.text(t):null),n=O.state.tr;n.replaceWith(0,O.state.doc.content.size,e),O.dispatch(n),O.dom.classList.add("md-source-mode")},exit_source_mode:()=>{if(!J(O.state.doc))return;const t=k(O.state.doc.textContent),e=O.state.tr;e.replaceWith(0,O.state.doc.content.size,t.content),O.dispatch(e),O.dom.classList.remove("md-source-mode")}};return"function"==typeof e?e(D):e&&(e.current=D),t.on_ready?.(D),()=>{E.disconnect(),M.removeEventListener("error",w,!0),M.removeEventListener("load",$,!0),O.destroy(),m.current=null}},[]),(0,H.jsx)("div",{className:"md-filecat",ref:n})});function J(t){if(1!==t.childCount)return!1;const e=t.firstChild;return!!e&&"code_block"===e.type.name&&"markdown"===e.attrs.language}function Z(t,e){const n=t.resolve(e);for(let t=n.depth;t>0;t--)if("code_block"===n.node(t).type.name)return!0;return!1}const Q=Y},67951(t,e,n){n.d(e,{G8:()=>g,NH:()=>u,Rx:()=>_,Vu:()=>f,fK:()=>m,k5:()=>l,oB:()=>p,uf:()=>h,x0:()=>d});var r=n(38341),o=n(5091),s=n(42845),a=n(46762),c=n(3772);function i(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 i=r+c,l=i+a.length,d=t.tr;return d.delete(l,o),d.delete(r,i),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])})),i(/(?:\*\*)([^*]+)(?:\*\*)$/,"strong"),i(/(?:__)([^_]+)(?:__)$/,"strong"),i(/(?<![*])\*([^*]+)\*$/,"em"),i(/(?<![_])_([^_]+)_$/,"em"),i(/(?:~~)([^~]+)(?:~~)$/,"strike"),i(/(?:`)([^`]+)(?:`)$/,"code"),...r.Fr,r.gO]})}const d=(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),i=n.after(n.depth);if(e){const n=t.tr,r=a.createAndFill(s.attrs)??a.create(s.attrs);n.replaceWith(c,i,r),n.scrollIntoView(),e(n)}return!0};function u(t){return(e,n)=>{const r=e.schema.marks[t];return!!r&&(0,a.wh)(r)(e,n)}}function h(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 i=s.parent,l=i.type===o&&Object.entries(e).every(([t,e])=>i.attrs[t]===e),d=l?n.schema.nodes.paragraph:o,u=l?{}:e;return r&&r(n.tr.setBlockType(c.start,c.end,d,u)),!0}}const m=(t,e)=>(0,c.Sd)(t.schema.nodes.bullet_list)(t,e),p=(t,e)=>(0,c.Sd)(t.schema.nodes.ordered_list)(t,e),f=(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},g={sink:(0,c.$B)(o.Y.nodes.list_item),lift:(0,c.T2)(o.Y.nodes.list_item),split:(0,c.wn)(o.Y.nodes.list_item),wrap_bullet:m,wrap_ordered:p},_=(t,e)=>{const{$from:n}=t.selection;return"code_block"===n.parent.type.name&&(e&&e(t.tr.setSelection(s.U3.create(t.doc,n.start(),n.end())).scrollIntoView()),!0)}},96763(t,e,n){n.d(e,{Kz:()=>a,P7:()=>l,_8:()=>h,_D:()=>u,bN:()=>s,o3:()=>c,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 i(){window.dispatchEvent(new Event(c))}async function l(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:(i(),e.data)}async function h(t){const e=await r.XO.post("md_theme/del",{id:t});return e?.code===o.m.Success&&(i(),!0)}},5091(t,e,n){n.d(e,{Y:()=>u});var r=n(58903),o=n(86059),s=n(41105),a=n(89334);const c=(0,o.of)({tableGroup:"block",cellContent:"block+",cellAttributes:{}}),i={align:{default:null}},l={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",attrs:i,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},...i},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,code:!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"]},html_block:{group:"block",atom:!0,code:!0,attrs:{value:{default:""}},parseDOM:[{tag:"div[data-html-block]",getAttrs:t=>({value:(0,s.Ne)(t.getAttribute("data-html-block")??"")})}],toDOM:t=>["div",{"data-html-block":t.attrs.value}]},html_inline:{inline:!0,group:"inline",atom:!0,code:!0,attrs:{value:{default:""}},parseDOM:[{tag:"span[data-html-inline]",getAttrs:t=>({value:(0,s.Ne)(t.getAttribute("data-html-inline")??"")})}],toDOM:t=>["span",{"data-html-inline":t.attrs.value}]},math_inline:{inline:!0,group:"inline",atom:!0,attrs:{raw:{default:""},tex:{default:""}},parseDOM:[{tag:"span[data-math-inline]",getAttrs:t=>{const e=t,n=(0,s.Ne)(e.getAttribute("data-math-inline")??"");return{raw:n,tex:(0,a.V)(n)?.tex??""}}}],toDOM:t=>["span",{"data-math-inline":t.attrs.raw}]},math_block:{group:"block",atom:!0,code:!0,attrs:{raw:{default:""},tex:{default:""}},parseDOM:[{tag:"div[data-math-block]",getAttrs:t=>{const e=t,n=(0,s.Ne)(e.getAttribute("data-math-block")??"");return{raw:n,tex:(0,a.V)(n)?.tex??""}}}],toDOM:t=>["div",{"data-math-block":t.attrs.raw}]},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:(0,s.KR)(e)};return n&&(o.alt=n),r&&(o.title=r),["img",o]}},text:{group:"inline"},...c},d={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]}}},u=new r.Sj({nodes:l,marks:d})}}]);
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[2479],{12479(e,t,n){n.r(t),n.d(t,{default:()=>l});var r=n(96540),a=n(57889),s=(n(14284),n(62042)),c=n(22022),o=n(21417),i=(n(88781),n(74848));function l(e){const{t}=(0,c.Bd)(),[n,l]=(0,r.useState)(!0),[m,p]=(0,r.useState)(""),[f,h]=(0,r.useState)(100),y=(0,r.useRef)(null),b=(0,r.useRef)(null),N=(0,r.useRef)(!1),x=(0,r.useRef)({props:e});x.current={props:e};const w=async()=>{if(!b.current)return(0,s.zN)(t("编辑器尚未就绪")),!1;const e=await x.current.props.on_save((()=>{const e=b.current;return e?JSON.stringify(e.getData(!0)):""})());return e&&(N.current=!1,x.current.props.on_dirty?.(!1),x.current.props.on_saved?.()),e};(0,r.useEffect)(()=>{e.register?.({save:w,is_dirty:()=>N.current})},[e.register]),(0,r.useEffect)(()=>{if(!y.current||!e.url)return;let n=!1;const r=[];b.current?.destroy?.(),b.current=null,N.current=!1,l(!0),p("");const c=async e=>{if(n||!y.current)return;const a=new o.A({el:y.current,data:e??{data:{text:t("中心主题")}},fit:!0,enableFreeDrag:!1});b.current=a,l(!1);const s=()=>{let e=!1;const t=window.setTimeout(()=>{n||(e=!0)},400);r.push(t),a.on("data_change",()=>{e&&(N.current||(N.current=!0,x.current.props.on_dirty?.(!0)),h(u(a)))}),a.on("view_data_change",()=>{h(u(a))}),a.on("error",(e,t)=>{console.error("[mind]",e,t)}),h(u(a))};window.requestAnimationFrame(()=>{n||s()})};return(async()=>{try{const t=await a.l.get(e.url);if(n)return;let r=null;if("string"==typeof t&&t.trim())try{r=JSON.parse(t)}catch{r=null}r=function(e){if(!e||"object"!=typeof e)return null;if(e.root&&"object"==typeof e.root)return e.root.data?e.root:d(e.root);if(e.data&&"object"==typeof e.data)return e;return d(e)}(r),await c(r)}catch(e){n||(l(!1),p(t("加载思维导图失败")),(0,s.zN)(t("加载思维导图失败")))}})(),()=>{n=!0,r.forEach(e=>window.clearTimeout(e)),b.current?.destroy?.(),b.current=null}},[e.url]),(0,r.useEffect)(()=>{const e=e=>{(e.ctrlKey||e.metaKey)&&("s"===e.key||"S"===e.key||83===e.keyCode)&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),w())};return window.addEventListener("keydown",e,!0),document.addEventListener("keydown",e,!0),()=>{window.removeEventListener("keydown",e,!0),document.removeEventListener("keydown",e,!0)}},[]);const j=e=>{const t=b.current;if(!t)return;const n=Math.min(4,Math.max(.25,e));t.view.setScale(n),h(Math.round(100*n))};return(0,i.jsxs)("div",{className:"mind-wrap"+(e.fullscreen?" mind-wrap--full":""),children:[e.header,(0,i.jsxs)("div",{className:"mind-toolbar",children:[(0,i.jsx)("button",{type:"button",className:"mind-btn",title:t("添加子节点")+" (Tab)",onClick:()=>b.current?.execCommand?.("INSERT_CHILD_NODE"),children:(0,i.jsx)("span",{className:"material-icons",children:"account_tree"})}),(0,i.jsx)("button",{type:"button",className:"mind-btn",title:t("添加同级节点")+" (Enter)",onClick:()=>b.current?.execCommand?.("INSERT_NODE"),children:(0,i.jsx)("span",{className:"material-icons",children:"subdirectory_arrow_right"})}),(0,i.jsx)("button",{type:"button",className:"mind-btn",title:t("删除节点")+" (Delete)",onClick:()=>b.current?.execCommand?.("REMOVE_NODE"),children:(0,i.jsx)("span",{className:"material-icons",children:"delete"})}),(0,i.jsx)("span",{className:"mind-toolbar__gap"}),(0,i.jsxs)("span",{className:"mind-toolbar__zoom",children:[f,"%"]}),(0,i.jsx)("button",{type:"button",className:"mind-btn",title:t("缩小"),onClick:()=>j(u(b.current)/100-.2),children:(0,i.jsx)("span",{className:"material-icons",children:"remove"})}),(0,i.jsx)("button",{type:"button",className:"mind-btn",title:t("放大"),onClick:()=>j(u(b.current)/100+.2),children:(0,i.jsx)("span",{className:"material-icons",children:"add"})}),(0,i.jsx)("button",{type:"button",className:"mind-btn",title:t("适应窗口"),onClick:()=>b.current?.view?.fit?.(),children:(0,i.jsx)("span",{className:"material-icons",children:"fit_screen"})})]}),(0,i.jsxs)("div",{className:"mind-canvas",children:[(0,i.jsx)("div",{className:"mind-mount",ref:y}),n&&(0,i.jsx)("div",{className:"mind-mask",children:"Loading..."}),m&&(0,i.jsx)("div",{className:"mind-mask",children:m})]})]})}function u(e){const t=e?.view?.getTransformData?.()?.state?.scale;return"number"==typeof t&&t>0?Math.round(100*t):100}function d(e){return{data:{text:"string"==typeof e?.text?e.text:"",...e?.note?{note:e.note}:{}},children:Array.isArray(e?.children)?e.children.map(d):[]}}}}]);
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[2674],{92674(e,t,n){n.r(t),n.d(t,{default:()=>M});var a=n(96540),s=n(82893),i=n(34843),o=n(85997),l=n(57952),r=n(47022),c=n(34251),d=n(74848);function u(e){{const[t,n]=(0,a.useState)(!1),[s,i]=(0,a.useState)([]),l=e=>{i(e)},p=async()=>{"folder"===e.type?(t||!e.click||s||await e.click(e,l,e.pre_path),n(!t)):e.click&&await e.click(e,l,e.pre_path)},h=async(t=!1)=>{"folder"!==e.type||t?e.fatherNowToggleExpansion&&e.fatherNowToggleExpansion():await e.click(e,l,e.pre_path)};return(0,a.useEffect)(()=>{i(e.children)},[e.children]),(0,d.jsxs)("div",{className:"studio-item",children:[(0,d.jsxs)("div",{onClick:p,onContextMenu:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation(),e.handleContextMenu&&e.handleContextMenu(t,e.name,e.pre_path,e.type===r.Iw.folder,h)},className:"studio-item-title"+(e.active_path===e.pre_path?" studio-item-title--active":""),children:[(0,d.jsx)("i",{className:"material-icons studio-item-title-tag","data-icon":t?"arrow_drop_down":"arrow_right",children:"file"==e.type?"":t?"arrow_drop_down":"arrow_right"}),(0,d.jsx)("span",{className:"file-icons",children:(0,d.jsx)("span",{"data-type":(0,c.uL)(e.name),"data-dir":"folder"===e.type,"aria-label":e.name,children:(0,d.jsx)(o.In,{icon:"",aria_label:e.name})})}),(0,d.jsx)("span",{className:"studio-item-name",children:e.name})]}),t&&s&&(0,d.jsx)("div",{style:{marginLeft:20},children:s.map((t,n)=>(0,d.jsx)(a.Fragment,{children:(0,d.jsx)(u,{type:t.type,size:t.size,click:e.click,name:t.name,children:t.children,pre_path:`${e.pre_path}${t.name}${t.type===r.Iw.folder?"/":""}`,handleContextMenu:e.handleContextMenu,active_path:e.active_path,fatherNowToggleExpansion:h},n)},n))})]})}}n(61443);function p(e){return(0,d.jsx)("div",{children:e.list.map((t,n)=>(0,d.jsx)(u,{pre_path:`${e.pre_path}${t.name}${t.type===r.Iw.folder?"/":""}`,name:t.name,type:t.type,handleContextMenu:e.handleContextMenu,fatherNowToggleExpansion:e.fatherNowToggleExpansion,active_path:e.active_path,children:t.children,click:e.click,size:t.size},n))})}var h=n(14284),m=n(34289),f=n(53459),v=n(78247),x=(n(62042),n(2543)),_=n(83529),y=n(22022),w=n(88815),j=n(52671),g=n(23430);const k=a.lazy(()=>Promise.all([n.e(2543),n.e(4091)]).then(n.bind(n,84091))),C=a.lazy(()=>Promise.all([n.e(4946),n.e(1384),n.e(7954),n.e(1075),n.e(1142)]).then(n.bind(n,71142))),S=a.lazy(()=>n.e(4877).then(n.bind(n,64877))),N=a.lazy(()=>Promise.all([n.e(4946),n.e(2626),n.e(7954),n.e(4004)]).then(n.bind(n,95733))),E=a.lazy(()=>Promise.all([n.e(3140),n.e(5744)]).then(n.bind(n,16575))),b=a.lazy(()=>Promise.all([n.e(4437),n.e(2479)]).then(n.bind(n,12479)));function M(e){const[t,n]=(0,a.useState)([]),[u,M]=(0,a.useState)(""),[I,A]=(0,a.useState)(""),[P,$]=(0,a.useState)(!1),[R,z]=(0,a.useState)({path:"",name:""}),[F,D]=(0,a.useState)(""),[L,U]=(0,i.fp)(s.AG.confirm),[G,T]=(0,a.useState)(!1),[B,K]=(0,i.fp)(s.AG.fileShellShow),[J,O]=(0,i.fp)(s.AG.file_shell_hidden),X=(0,a.useRef)(null),H=(0,a.useRef)(null),[W,Y]=(0,a.useState)(!1),[V,Z]=(0,a.useState)(16),[q,Q]=(0,i.fp)(s.AG.showPrompt),{t:ee}=(0,y.Bd)(),te=(0,j.Zp)(),ne=(ae=R.name,(0,c.uL)(ae)===r.Iw.md);var ae;const se=function(e){return(0,c.uL)(e)===r.Iw.excalidraw}(R.name),ie=function(e){return(0,c.uL)(e)===r.Iw.mind}(R.name),oe=(0,a.useRef)(null),le=(0,a.useRef)(null),re=(0,a.useRef)(null),[ce,de]=(0,a.useState)([]),[ue,pe]=(0,a.useState)(-1),[he,me]=(0,a.useState)("folder"),[fe,ve]=(0,a.useState)(!0),[xe,_e]=(0,a.useState)(!1),[ye,we]=(0,a.useState)(!1),[je,ge]=(0,a.useState)(33),ke=(0,a.useRef)(null),[Ce,Se]=(0,a.useState)(!1),[Ne,Ee]=(0,a.useState)(void 0),be="studio_chat_session";let Me=(0,j.zy)().pathname.split("/").filter(Boolean).pop();Me=decodeURIComponent(Me);const{check_user_auth:Ie}=(0,v.MH)(),Ae=Me||"";const Pe=async()=>{const e=(0,m.GG)("file",Me);M(e),z({path:e,name:(0,m.mH)(e)});const t=await h.$M.post("studio/get/item",{path:e});if(t.code===f.m.Success){const e=[],a=[];for(const n of t.data.list)"folder"===n.type?e.push(n):"file"===n.type&&a.push(n);n([...e,...a])}};(0,a.useEffect)(()=>{A(""),T(!1),Pe()},[]);const $e=async(e,t)=>{const n=await h.$M.get(`${encodeURIComponent(t)}`);A(n.data),v.xK.set_value_temp(n.data),z({path:t,name:e}),D(t),me("folder"),_e(!1)},Re=(e,t)=>{e.size>w.o5?U({open:!0,handle:()=>{$e(e.name,t),U({open:!1,handle:null}),T(!1)},title:"超过20MB了还要打开吗?"}):$e(e.name,t)};async function ze(){if(!G)return;const e={context:v.xK.get_editor_value()};0===(await h.$M.post(`save/${encodeURIComponent(F)}`,e)).code&&T(!1)}const Fe=e=>{e.ctrlKey&&"s"===e.key&&(e.preventDefault(),G&&ze())};(0,a.useEffect)(()=>(document.addEventListener("keydown",Fe),()=>{document.removeEventListener("keydown",Fe)}),[G]);const De=(0,a.useCallback)(x.throttle(e=>{const t=parseFloat(getComputedStyle(H.current).fontSize),n=window.innerWidth/t-4,a=e.clientX/t,s=2.25+X.current.offsetWidth/t;a<=n&&a>=s&&Z(parseFloat(a.toFixed(2)))},32),[]),Le=()=>{Y(!1),H.current.removeEventListener("pointermove",De)},Ue=(0,a.useCallback)(x.throttle(e=>{const t=ke.current;if(!t)return;const n=parseFloat(getComputedStyle(t).fontSize),a=t.parentElement.getBoundingClientRect().right-e.clientX,s=.7*t.parentElement.getBoundingClientRect().width,i=Math.min(Math.max(a,320),s);ge(parseFloat((i/n).toFixed(2)))},32),[]),Ge=()=>{Se(!1),document.removeEventListener("pointermove",Ue)},Te=[{r:ee("创建文件"),v:"创建文件"},{r:ee("创建目录"),v:"创建目录"},{r:ee("重命名"),v:"重命名"},{r:ee("删除"),v:"删除"}],Be=[{r:ee("重命名"),v:"重命名"},{r:ee("删除"),v:"删除"}],Ke=(e,t,n,a,s)=>{e.preventDefault();const i=new c.ik;i.path=n,i.filename=t,i.x=e.clientX,i.y=e.clientY,i.items=a?Te:Be,s===Pe&&(i.items=i.items.slice(0,2)),i.type=a?r.Iw.studio_folder:r.Iw.studio_file;const o=e=>{s(e)};i.textClick=e=>{switch(e){case"创建文件":Q({show:!0,type:_.PromptEnum.FileNew,overlay:!0,data:{dir:n,call:o}});break;case"创建目录":Q({show:!0,type:_.PromptEnum.DirNew,overlay:!0,data:{dir:n,call:o}});break;case"删除":if(G&&(R.path===n||R.path.includes(n))){const e=()=>{o(a),T(!1),z({}),A(""),v.xK.set_value_temp("")};Q({show:!0,type:_.PromptEnum.FilesDelete,overlay:!0,data:{path:n,call:e,filename:t}});break}Q({show:!0,type:_.PromptEnum.FilesDelete,overlay:!0,data:{path:n,filename:t,call:a?()=>{o(!0)}:o}});break;case"重命名":Q({show:!0,type:_.PromptEnum.FileRename,overlay:!0,data:{path:n,dir:(0,m.Yp)(n),call:()=>{o(!0)},filename:t}})}},Q({show:!0,type:_.PromptEnum.FileMenu,overlay:!1,data:i})};const Je=ne&&"outline"===he;return(0,d.jsxs)("div",{className:"studio studio--file",children:[(0,d.jsxs)(l.A,{ignore_tags:!0,left_children:[(0,d.jsx)(o.rA,{title:"取消",icon:"close",onClick:()=>{K({show:!1,path:""}),O(void 0),te(-1)}},1),(0,d.jsx)("div",{children:R.name},2)],children:[(0,d.jsx)("title",{children:R.name}),(0,d.jsx)(o.rA,{title:"侧边栏",icon:"list",onClick:()=>ve(e=>!e),selected:fe}),ne&&[xe?(0,d.jsx)(o.rA,{title:ee("保存"),icon:"save",onClick:()=>oe.current?.save()},"save"):null,(0,d.jsx)(o.rA,{icon:"source"===oe.current?.mode()?"edit":"code",title:"source"===oe.current?.mode()?ee("实时编辑模式"):ee("源码模式"),onClick:()=>oe.current?.toggle_mode()},"mode"),(0,d.jsx)(o.rA,{title:ee("导出PDF"),icon:"print",onClick:()=>oe.current?.export_pdf()},"pdf")],!ne&&(0,c.zr)(R.name)&&(0,d.jsx)(o.rA,{title:"格式化",icon:"data_object",onClick:function(){v.xK.get_editor()?.formatCode()}}),(0,d.jsx)(o.rA,{icon:"terminal",title:"shell",onClick:function(){!0!==J&&!1!==J?B.show?K({show:!1,path:""}):(K({show:!0,path:(0,m.GG)("file",Me)}),O(!1)):O(!J)}}),Ie(g.oV.ai_agent_page)&&(0,d.jsx)(o.rA,{title:ee("AI 聊天"),icon:"smart_toy",selected:ye,onClick:()=>we(e=>!e)}),ne?xe?(0,d.jsx)(o.rA,{title:ee("保存"),icon:"save",onClick:()=>oe.current?.save()}):null:se?(0,d.jsx)(o.rA,{title:ee("保存"),icon:"save",onClick:()=>le.current?.save()}):ie?(0,d.jsx)(o.rA,{title:ee("保存"),icon:"save",onClick:()=>re.current?.save()}):G?(0,d.jsx)(o.rA,{title:"保存",icon:"save",onClick:ze}):null]}),(0,d.jsxs)("div",{className:"studio-body",ref:H,children:[(0,d.jsxs)("div",{className:"studio-nav",style:{display:fe?void 0:"none",width:V-1+"em"},onContextMenu:e=>{Ke(e,R.name,(0,m.GG)("file",Me),!0,Pe)},children:[(0,d.jsx)("div",{className:"studio-nav-outline",style:{display:Je?void 0:"none"},children:(0,d.jsx)(S,{items:ce,active_pos:ue,on_click:e=>oe.current?.goto_heading(e)})}),(0,d.jsx)("div",{className:"studio-nav-folder",style:{display:Je?"none":void 0},children:(0,d.jsx)(p,{pre_path:u,list:t,click:async(e,t,n)=>{if("folder"===e.type){const e=await h.$M.post("studio/get/item",{path:`${n}`});if(e.code===f.m.Success){const n=[],a=[];for(const t of e.data.list)"folder"===t.type?n.push(t):"file"===t.type&&a.push(t);t([...n,...a])}}else{if(G)return void U({open:!0,handle:()=>{U({open:!1,handle:null}),T(!1),Re(e,n)},title:"确定不保存就切换吗?"});Re(e,n)}},active_path:F,handleContextMenu:Ke,fatherNowToggleExpansion:Pe})}),ne&&(0,d.jsx)("div",{className:"studio-nav-switch",children:(0,d.jsx)(o.rA,{icon:Je?"folder":"list",title:ee(Je?"文件目录":"大纲"),onClick:()=>me(Je?"folder":"outline")})})]}),fe&&(0,d.jsx)("div",{className:"studio__divider",ref:X,onPointerDown:()=>{Y(!0),H.current.addEventListener("pointermove",De)},onPointerUp:Le}),W&&(0,d.jsx)("div",{className:"shell__overlay",onPointerUp:Le}),ne?(0,d.jsx)("div",{className:"studio-editor studio-editor--md",children:(0,d.jsx)(a.Suspense,{fallback:null,children:(0,d.jsx)(C,{pane:{path:F,url:h.$M.getDownloadUrl(encodeURIComponent(F)),name:R.name,on_dirty:_e,on_outline:(e,t)=>{de(e),pe(t)},register:e=>{oe.current=e}}})})},F):se?(0,d.jsx)("div",{className:"studio-editor studio-editor--draw",children:(0,d.jsx)(a.Suspense,{fallback:null,children:(0,d.jsx)(E,{reset_key:F,url:h.$M.getDownloadUrl(encodeURIComponent(F)),save_path:F,on_dirty:T,on_saved:()=>T(!1),register:e=>{le.current=e}})})},F):ie?(0,d.jsx)("div",{className:"studio-editor studio-editor--mind",children:(0,d.jsx)(a.Suspense,{fallback:null,children:(0,d.jsx)(b,{reset_key:F,url:h.$M.getDownloadUrl(encodeURIComponent(F)),on_dirty:T,on_saved:()=>T(!1),register:e=>{re.current=e},on_save:async e=>(await h.$M.post(`save/${encodeURIComponent(F)}`,{context:e})).code===f.m.Success})})},F):(0,d.jsx)("div",{className:"studio-editor",children:R.name&&(0,d.jsx)(a.Suspense,{fallback:null,children:(0,d.jsx)(k,{name:R.name,on_change:()=>{G||T(!0)}})})},F),ye&&(0,d.jsxs)(a.Fragment,{children:[(0,d.jsx)("div",{className:"studio__divider studio__divider--chat",ref:ke,onPointerDown:e=>{e.preventDefault(),Se(!0),document.addEventListener("pointermove",Ue),document.addEventListener("pointerup",Ge,{once:!0})}}),(0,d.jsx)("div",{className:"studio-chat-panel",style:{width:`${je}em`},children:(0,d.jsx)(a.Suspense,{fallback:null,children:(0,d.jsx)(N,{inline_header:!0,sync_url:!1,file_cwd_path:Ae,session_id:Ne??(e=>{try{const t=sessionStorage.getItem(be);if(!t)return;const n=JSON.parse(t);return n?.[e]||void 0}catch{return}})(Ae),on_session_change:e=>{Ee(e),((e,t)=>{try{const n=sessionStorage.getItem(be),a=n?JSON.parse(n):{};a[e]=t,sessionStorage.setItem(be,JSON.stringify(a))}catch{}})(Ae,e)}})})})]})]})]})}}}]);
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkfilecat=self.webpackChunkfilecat||[]).push([[4004,6010],{83277(e,s,t){t.d(s,{$j:()=>o,CP:()=>a,Lv:()=>n,cL:()=>i});class n{token;open=!1;note;index;url;model;request_type;json_params;sys_prompt;dotenv="";tool_mode=!1;show_options;static get_label_by_v(e,s){if(!e||!s?.length)return e;for(const t of s)if(t.value===e)return t.label;return e}static have_label_by_v(e,s){if(!e||!s?.length)return!1;for(const t of s)if(t.value===e)return!0;return!1}}const a='\n\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\n# ===== 是否支持图片(support_image)=====\n# 开启后:1) 注册 read_image 工具,让 AI 能读取本地图片;\n# 2) 工具读到的图片会以 OpenAI 多模态格式 image_url 随消息发给模型,模型就能真正"看图"。\n# 关闭后:AI 看不到图片,read_image 只会返回一句文字说明。\n# 主流模型(gpt-4o、豆包、qwen-vl、deepseek-vl 等)都支持,默认开启。\nsupport_image=true\n';const i=JSON.stringify({stream:!0,thinking:{type:"disabled"}});function o(e){return"string"==typeof e?e:Array.isArray(e)?e.map(e=>"text"===e.type?e.text:"[图片]").join("\n"):""}},95733(e,s,t){t.r(s),t.d(s,{default:()=>ne});var n=t(96540),a=t(34843),i=t(22022),o=t(52671),c=t(92275),r=t(14284),l=t(7463),d=t(64694),u=t(78247),m=t(40505),h=t(62042),g=t(45907),p=t(53459),_=t(72693),x=t(82893),f=t(61443),j=t(83277);function v(e){return null==e||e<0?"0":e.toLocaleString()}function b(e){const s=[];if(e.attachments?.length&&s.push(e.attachments.map(e=>`[附件] ${e.name}`).join("\n")),e.content_list?.length)for(const t of e.content_list){const e=(0,j.$j)(t.content);if(e&&s.push(e),t.tool_call_ends?.length){const e=t.tool_call_ends.map(e=>{const s=e.tool_display_name||e.tool_name;return e.success?`[工具] ${s} 成功`:`[工具] ${s} 失败`});s.push(e.join("\n"))}}return e.text&&!s.length&&s.push(e.text),e.images?.length&&s.push(`[生成图片 ${e.images.length} 张]`),e.audio&&s.push("[音频]"),s.join("\n\n")}function w(e){const s=(0,j.$j)(e.content);if(s)return s;const t=e.content_list??[];return t.length?t.map(e=>(0,j.$j)(e.content)).filter(Boolean).join("\n\n"):""}function y(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:w(e),attachments:e.attachments??[],content_list:e.content_list,images:e.images,audio:e.audio,embeddings:e.embeddings,elapsed_ms:e.elapsed_ms}))}const S=/\.(md|txt|json|js|jsx|ts|tsx|css|html?|xml|ya?ml|py|java|go|rs|c|cpp|h|hpp|sh|bat|cmd|ini|toml|csv|log|sql|env|gitignore|dockerfile)$/i;function N(e){return e.type?.startsWith("image/")?"image":e.type?.startsWith("text/")||S.test(e.name)?"text":"binary"}function k(e){return e.text()}function C(e){return new Promise((s,t)=>{const n=new FileReader;n.onload=()=>s(n.result),n.onerror=t,n.readAsDataURL(e)})}async function A(e){const s=[];for(const t of e){const e=N(t);let n="";if("text"===e)try{const e=await k(t),s=12e4;n=e.length>s?`${e.slice(0,s)}\n\n[内容已截断,原始长度 ${e.length} 字符]`:e}catch{n="[文本读取失败]"}else if("image"===e)try{n=await C(t)}catch{n=`[图片文件: ${t.name}]`}else n=`[二进制文件: ${t.name}]`;s.push({name:t.name,mime_type:t.type,size:t.size,kind:e,content:n})}return s}var $=t(14944);var I=t(85997),M=t(34299),R=t(74848);function D(e){const s=e.attachments&&e.attachments.length>0?(0,R.jsx)("div",{className:"chat-message-attachments",children:e.attachments.map((e,s)=>(0,R.jsxs)("div",{className:"chat-message-attachment",children:[(0,R.jsx)(I.In,{icon:"attach_file"}),(0,R.jsx)("span",{children:e.name}),(0,R.jsxs)("small",{children:[e.size," B"]})]},`${e.name}_${s}`))}):null,t=[];e.images&&"bot"===e.sender&&t.push((0,R.jsx)(n.Fragment,{children:(0,R.jsx)(V,{images:e.images,text:e.text})},"images")),e.audio&&"bot"===e.sender&&t.push((0,R.jsx)(n.Fragment,{children:(0,R.jsx)(K,{audio:e.audio,text:e.text})},"audio")),e.embeddings&&"bot"===e.sender&&t.push((0,R.jsx)(n.Fragment,{children:(0,R.jsx)(B,{embeddings:e.embeddings,text:e.text})},"embeddings"));const a=function(e){if("bot"!==e.sender||!e.content_list?.length)return e.text?(0,R.jsx)(M.default,{context:e.text}):null;return(0,R.jsxs)(R.Fragment,{children:[e.content_list.map((e,s)=>{const t=[],a=(0,j.$j)(e.content);return a&&t.push((0,R.jsx)(n.Fragment,{children:(0,R.jsx)(M.default,{context:a})},`content-${s}`)),e.tool_call_ends?.length&&t.push((0,R.jsx)(n.Fragment,{children:(0,R.jsx)(H,{callList:e.tool_call_ends})},`tool-${s}`)),(0,R.jsx)(n.Fragment,{children:t},`part-${s}`)}),!e.content_list.some(e=>e.content)&&e.text?(0,R.jsx)(M.default,{context:e.text}):null]})}(e);return 0===t.length?(0,R.jsxs)(R.Fragment,{children:[s,a]}):(0,R.jsxs)(R.Fragment,{children:[t,s,a]})}function H({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,R.jsxs)("div",{className:"chat-message-call-list",children:[(0,R.jsxs)("div",{className:"call-list-header",onClick:()=>t(!s),children:[(0,R.jsx)(I.In,{icon:s?"expand_less":"expand_more"}),(0,R.jsxs)("span",{className:"call-list-summary",children:["工具调用 (",e.length,")",a>0&&(0,R.jsx)("span",{className:"call-list-fail",children:" 失败 "})]})]}),s&&(0,R.jsx)("div",{className:"call-list-body",children:e.map((e,s)=>(0,R.jsxs)("div",{className:"call-list-item "+(e.success?"call-success":"call-fail"),children:[(0,R.jsxs)("div",{className:"call-list-item-header",children:[(0,R.jsx)(I.In,{icon:e.success?"check_circle":"error"}),(0,R.jsx)("span",{className:"call-list-tool-name",children:e.tool_display_name||e.tool_name}),(0,R.jsxs)("span",{className:"call-list-duration",children:[e.duration_ms,"ms"]})]}),e.tool_args&&(0,R.jsxs)("details",{className:"call-list-details",children:[(0,R.jsx)("summary",{children:"参数"}),(0,R.jsx)("pre",{className:"call-list-pre",children:JSON.stringify(e.tool_args,null,2)})]}),!e.success&&e.error&&(0,R.jsxs)("details",{className:"call-list-details",children:[(0,R.jsx)("summary",{children:"错误"}),(0,R.jsx)("pre",{className:"call-list-pre call-list-error-text",children:e.error})]}),e.success&&e.tool_result&&(0,R.jsxs)("details",{className:"call-list-details",children:[(0,R.jsx)("summary",{children:"结果"}),(0,R.jsx)("pre",{className:"call-list-pre",children:e.tool_result.length>500?e.tool_result.slice(0,500)+"...":e.tool_result})]})]},s))})]})}function V({images:e,text:s}){let t=e||[];if(!t.length&&s)try{t=JSON.parse(s).data||[]}catch{}return t.length?(0,R.jsxs)("div",{className:"image-generation-result",children:[t.map((e,s)=>(0,R.jsxs)("div",{className:"image-generation-item",children:[e.url&&(0,R.jsx)("div",{className:"image-generation-image-wrapper",children:(0,R.jsx)("img",{src:e.url,alt:e.revised_prompt||`生成的图片 ${s+1}`,loading:"lazy"})}),e.b64_json&&(0,R.jsx)("div",{className:"image-generation-image-wrapper",children:(0,R.jsx)("img",{src:`data:image/png;base64,${e.b64_json}`,alt:`生成的图片 ${s+1}`})}),e.revised_prompt&&(0,R.jsx)("p",{className:"image-generation-prompt",children:(0,R.jsx)("small",{children:e.revised_prompt})})]},s)),s&&!e&&(0,R.jsx)(M.default,{context:s})]}):(0,R.jsx)(M.default,{context:s||""})}function K({audio:e,text:s}){if(e){if(e.url)return(0,R.jsx)("div",{className:"audio-result",children:(0,R.jsx)("audio",{controls:!0,src:e.url,children:"您的浏览器不支持音频播放"})});if(e.data){const s=e.mime_type||"audio/mpeg";return(0,R.jsx)("div",{className:"audio-result",children:(0,R.jsx)("audio",{controls:!0,src:`data:${s};base64,${e.data}`,children:"您的浏览器不支持音频播放"})})}}const t=s||"";if(t.startsWith("http://")||t.startsWith("https://"))return(0,R.jsx)("div",{className:"audio-result",children:(0,R.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,R.jsx)("div",{className:"audio-result",children:(0,R.jsx)("audio",{controls:!0,src:`data:audio/mpeg;base64,${s}`,children:"您的浏览器不支持音频播放"})})}}catch{}return(0,R.jsx)(M.default,{context:t})}function T({content:e,label:s}){const[t,a]=n.useState(!1);return(0,R.jsxs)("button",{className:"embeddings-copy-btn",onClick:()=>{(0,m.lW)(e),a(!0),setTimeout(()=>a(!1),1500)},children:[(0,R.jsx)(I.In,{icon:t?"check":"content_copy"}),t?"已复制":s||"复制"]})}function B({embeddings:e,text:s}){let t=e||null;if(!t&&s)try{t=JSON.parse(s)}catch{return(0,R.jsx)(M.default,{context:s})}if(!t)return(0,R.jsx)(M.default,{context:s||""});const n=t?.data||[],a=t?.usage,i=JSON.stringify(t,null,2);return(0,R.jsxs)("div",{className:"embeddings-result",children:[(0,R.jsxs)("div",{className:"embeddings-summary",children:[(0,R.jsx)("strong",{children:"向量嵌入结果"}),(0,R.jsxs)("span",{children:["维度: ",n[0]?.embedding?.length??"N/A"]}),(0,R.jsxs)("span",{children:["数量: ",n.length]}),a&&(0,R.jsxs)("span",{children:["使用 tokens: ",a.total_tokens??"N/A"]})]}),(0,R.jsxs)("div",{className:"embeddings-toolbar",children:[(0,R.jsx)(T,{content:i,label:"复制全部结果"}),n.length>0&&n[0]?.embedding&&(0,R.jsx)(T,{content:JSON.stringify(n[0].embedding,null,2),label:"复制第一条向量"}),n.length>0&&(0,R.jsx)(T,{content:JSON.stringify(n.map(e=>e.embedding),null,2),label:"复制所有向量数据"})]}),n.length>0&&n[0]?.embedding&&(0,R.jsx)("div",{className:"embeddings-preview",children:(0,R.jsxs)("span",{children:["向量预览: [",n[0].embedding.slice(0,5).join(", "),n[0].embedding.length>5?", ...":"","]"]})}),n.length>0&&(0,R.jsxs)("details",{children:[(0,R.jsx)("summary",{children:"查看详细数据"}),(0,R.jsx)("pre",{className:"embeddings-raw",children:i})]})]})}async function E(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})),o=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:o||`生成了 ${i.length} 张图片`}}(s,t);return e&&n(e.text,{images:e.images}),!0}case"audio_speech":{const e=await async function(e,s){const t={input:e,session_id:s};try{const e=localStorage.getItem("ai_audio_extra_params");if(e){const s=JSON.parse(e);s.voice&&(t.voice=s.voice),s.speed&&(t.speed=parseFloat(s.speed))}}catch{}const n=localStorage.getItem("token")||"",a=await fetch("/api/ai_agent/audio/speech",{method:"POST",headers:{"Content-Type":"application/json",Authorization:n},body:JSON.stringify(t)});if(!a.ok)throw new Error(`语音合成失败: ${a.statusText}`);const i=a.headers.get("X-Session-Id")||s,o=await a.arrayBuffer();return{session_id:i,audio:{data:btoa(String.fromCharCode(...Array.from(new Uint8Array(o)))),mime_type:a.headers.get("content-type")||"audio/mpeg"},text:`[音频文件: ${e.slice(0,50)}...]`}}(s,t);return e&&n(e.text,{audio:e.audio}),!0}case"embeddings":{const e=await async function(e,s){const t=await 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 z=t(4412),P=t(23430),F=t(87361),L=t(80389),O=t(7523),q=t(23496);const G=({currentModelName:e,setCurrentModelName:s,modelGroups:t,onModelChanged:c,sysPromptList:l,batchMode:d,selectedMsgCount:m,sessionVisible:g,onToggleSessionPanel:_,onCreateSession:j,onToggleBatchMode:v,onBatchDeleteMessages:b,bgProcessVisible:w,bgProcessCount:y,onToggleBgProcess:S,selectedSysPromptId:N,setSelectedSysPromptId:k,inline:C})=>{const{t:A}=(0,i.Bd)(),$=(0,o.Zp)(),{check_user_auth:M}=(0,u.MH)(),[,D]=(0,a.fp)(x.AG.ai_session_collapsed),{open:H}=function(){const{t:e}=(0,i.Bd)(),[,s]=(0,a.fp)(x.AG.prompt_card),[t,o]=(0,a.fp)(x.AG.ai_chat_zoom),{initUserInfo:c}=(0,n.useContext)(O.F);return{open:()=>{const n=t,a=()=>s({open:!1});s({open:!0,title:e("缩放调整"),context_div:(0,R.jsx)(L.p,{defaultValue:t,onChange:o,min:30,max:200}),cancel:()=>{o(n),a()},confirm:async()=>{let s=100;o(e=>(s=e<30||e>200?100:e,s)),await r.wm.post(q.s.user_save_private_attr,{is_ai_chat_zoom:!0,ai_chat_zoom:s}),(0,h.SK)(e("缩放调整成功")),c(),a()}})}}}(),V=M(P.oV.ai_model_switch)||M(P.oV.ai_agent_setting),K=[];for(const e of t)for(const s of e.models)K.push({title:s.label||s.value,value:`${e.index}::${s.value}`,group:e.note});const T=t.find(e=>e.active),B=T?`${T.index}::${e}`:"",E=(0,R.jsxs)(n.Fragment,{children:[(0,R.jsx)(I.rA,{icon:"menu",title:A("会话"),onClick:_,selected:g}),(0,R.jsx)(I.rA,{icon:"add",title:A("新会话"),onClick:()=>j()}),l.length>0&&(0,R.jsx)(f.l6,{value:N,options:[{title:A("选择系统提示词"),value:""},...l.map(e=>({title:e.note||e.prompt.slice(0,30),value:String(e.index)}))],onChange:e=>{k(e)},no_border:!0,width:"auto"}),V&&K.length>0&&(0,R.jsx)(f.l6,{value:B,options:[{title:A("选择模型"),value:""},...K],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===p.m.Success?((0,h.SK)("success"),c()):(0,h.zN)(e?.message||"fail")}).catch(console.error))},no_border:!0,width:"auto"}),d&&m>0&&(0,R.jsx)(I.rA,{icon:"delete",title:A("删除选中消息"),onClick:b}),(0,R.jsx)(I.rA,{icon:"zoom_in",title:A("缩放调整"),onClick:H}),(0,R.jsx)(I.rA,{icon:"terminal",title:A("后台进程"),onClick:S,selected:w,tip:y||null}),M(P.oV.ai_agent_setting)&&(0,R.jsx)(I.rA,{icon:"smart_toy",title:"机器人配置",onClick:()=>{$(F.o.ai_rebot_setting_page)}}),M(P.oV.ai_agent_setting)&&(0,R.jsx)(I.rA,{icon:"settings",title:"ai setting",onClick:()=>{$(F.o.ai_agent_setting_page)}})]});return C?(0,R.jsx)("div",{className:"chat-inline-header",children:E}):(0,R.jsx)(z.aZ,{position:"right",children:E})};var J=t(83529);function W({sessions:e,activeSessionId:s,onSelectSession:t,onReorderSessions:a,onRenameSession:o,onDeleteSession:c,onToggleCmdAuto:r,onShowUsageStats:l,onShowSessionSetting:d,batchMode:u,selectedSessionIds:m,onToggleSessionSelect:h,onToggleBatchMode:g,onBatchDeleteSessions:p,onClearAllSessions:_}){const{t:x}=(0,i.Bd)(),[f,j]=(0,n.useState)(""),[v,b]=(0,n.useState)(null),[w,y]=(0,n.useState)(null),S=f.trim()?e.filter(e=>(e.title||"").toLowerCase().includes(f.toLowerCase())||(e.summary||"").toLowerCase().includes(f.toLowerCase())||(e.long_term_memory||"").toLowerCase().includes(f.toLowerCase())):e;return(0,R.jsxs)("aside",{className:"chat-session-list",children:[(0,R.jsx)("div",{className:"chat-session-search",children:(0,R.jsx)("input",{type:"text",className:"chat-session-search-input",placeholder:x("搜索会话"),value:f,onChange:e=>j(e.target.value)})}),(0,R.jsx)("div",{className:"chat-session-items-wrap",children:S.map((e,n)=>{return(0,R.jsx)("div",{children:(0,R.jsxs)("button",{className:`chat-session-item ${s===e.id?"active":""} ${u?"batch-mode":""} ${e.running?"is-running":""} ${v===n?"row-dragging":""} ${w===n&&null!==v&&v!==n?"row-drop-target":""}`,draggable:!!a,onDragStart:()=>b(n),onDragOver:e=>{null!==v&&(e.preventDefault(),w!==n&&y(n))},onDragEnd:()=>{b(null),y(null)},onDrop:e=>{e.preventDefault(),(e=>{const s=v;if(b(null),y(null),null===s||s===e||!a)return;const t=S[s]?.id,n=S[e]?.id;t&&n&&a(t,n)})(n)},onClick:()=>{u&&h?h(e.id):t(e.id)},title:e.summary||e.long_term_memory||e.title,children:[u&&(0,R.jsx)("input",{type:"checkbox",className:"chat-session-checkbox",checked:m?.has(e.id)??!1,onChange:()=>h?.(e.id),onClick:e=>e.stopPropagation()}),(0,R.jsx)("span",{children:(i=e.title,i||"新会话")}),e.running&&(0,R.jsx)("span",{className:"chat-session-running",title:x("正在执行中")}),(0,R.jsx)("small",{children:e.message_count}),"web"!==e.source&&(0,R.jsx)("em",{className:"chat-session-source",children:e.source}),!u&&(0,R.jsx)(J.MenuSelect,{list:[{name:x("重命名"),click:()=>o(e.id,e.title)},{name:x("移动到最上"),click:()=>{const s=S[0];s&&s.id!==e.id&&a?.(e.id,s.id)}},{name:x("移动到最下"),click:()=>{const s=S[S.length-1];s&&s.id!==e.id&&a?.(e.id,s.id)}},{name:e.cmd_auto_allow?x("命令检测关闭"):x("命令检测开启"),click:()=>r?.(e.id,!e.cmd_auto_allow)},{name:x("字符消耗统计"),click:()=>l(e.id)},{name:x("设置"),click:()=>d?.(e.id)},{name:x("删除"),click:()=>c(e.id)}],children:(0,R.jsx)(I.In,{icon:"more_horiz"})})]})},e.id);var i})}),(0,R.jsxs)("div",{className:"chat-session-actions",children:[(0,R.jsx)(I.rA,{icon:u?"check_circle":"checklist",title:x(u?"取消批量选择":"批量选择"),onClick:g}),u&&(m?.size??0)>0&&(0,R.jsx)(I.rA,{icon:"delete",title:x("删除选中会话"),onClick:p}),!u&&(0,R.jsx)(I.rA,{icon:"delete_sweep",title:x("删除全部会话"),onClick:_})]})]})}var U=t(21499);function Q(e){const s=(e.text||"").split("\n").map(e=>e.trim()).find(Boolean)||"";return s.length>80?s.slice(0,80)+"…":s}const X=({messages:e,batchMode:s,selectedMsgIds:t,sending:a,chatContainerRef:i,messagesEndRef:o,onToggleMsgSelect:c,onDelete:r,onCopy:l,onCopyAll:d,onToggleBatchMode:u,onBatchCopy:m,onBatchDelete:h,showBatchBar:g,t:p})=>{const[_,x]=(0,n.useState)(new Set),f=(0,n.useMemo)(()=>e.filter(e=>!e.is_loading).map(e=>e.id),[e]),j=e=>{x(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},v=()=>{x(e=>e.size>0&&f.every(s=>e.has(s))?new Set:new Set(f))};return(0,R.jsxs)("div",{className:"chat-messages",ref:i,"data-sending":a?"true":"false",children:[g&&(0,R.jsxs)("div",{className:"chat-message-batch-bar",children:[(0,R.jsxs)("span",{className:"batch-bar-count",children:[p("已选")," ",t.size]}),(0,R.jsx)("button",{onClick:m,children:p("复制所选")}),(0,R.jsx)("button",{onClick:h,className:"danger",children:p("删除所选")}),(0,R.jsx)("button",{onClick:u,children:p("取消")})]}),e.map(e=>{const n=_.has(e.id);return(0,R.jsxs)("div",{className:`chat-message ${e.sender} ${s?"batch-mode":""} ${e.is_loading?"is-loading":""} ${n?"collapsed":""}`,children:[s&&(0,R.jsx)("input",{type:"checkbox",className:"chat-message-checkbox",checked:t.has(e.id),onChange:()=>c(e.id)}),e.is_loading?(0,R.jsxs)("div",{className:"ai-loading-bubble",children:[(0,R.jsxs)("div",{className:"ai-loading-dots",children:[(0,R.jsx)("span",{className:"ai-loading-dot"}),(0,R.jsx)("span",{className:"ai-loading-dot"}),(0,R.jsx)("span",{className:"ai-loading-dot"})]}),(0,R.jsx)("span",{className:"ai-loading-text",children:e.text})]}):(0,R.jsxs)(R.Fragment,{children:[n?(0,R.jsxs)("div",{className:"chat-message-summary",title:e.text,onClick:()=>j(e.id),children:[(0,R.jsx)("span",{className:"chat-message-summary-icon",children:"▸"}),(0,R.jsx)("span",{className:"chat-message-summary-text",children:Q(e)||p("(无内容)")})]}):(0,R.jsx)("div",{className:"chat-message-body",children:D(e)}),(0,R.jsxs)("div",{className:"message-collapse-bar",children:[(0,R.jsx)("button",{onClick:()=>j(e.id),children:p(n?"展开":"折叠")}),(0,R.jsx)("button",{onClick:v,children:p("全部折叠")}),"bot"===e.sender&&null!=e.elapsed_ms&&(0,R.jsx)("span",{className:"message-elapsed",children:(0,U.kf)(e.elapsed_ms)})]}),(0,R.jsx)("div",{className:"message-actions",children:s?(0,R.jsx)("button",{onClick:()=>c(e.id),children:t.has(e.id)?p("取消选择"):p("选择")}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)("button",{onClick:()=>r(e.id),children:p("删除")}),(0,R.jsx)("button",{onClick:()=>l(e),children:p("复制")}),(0,R.jsx)("button",{onClick:d,children:p("全部复制")}),(0,R.jsx)("button",{onClick:u,children:p("多选")})]})})]})]},e.id)}),(0,R.jsx)("div",{ref:o})]})},Z=(0,n.forwardRef)(function({placeholder:e="",disabled:s=!1,className:t,style:a,onEnter:i,onPaste:o,onChange:c},r){const l=(0,n.useRef)(null),[d,u]=(0,n.useState)(!0),[m,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,R.jsx)("div",{ref:l,contentEditable:!s,suppressContentEditableWarning:!0,className:"rich-textarea"+(t?" "+t:""),style:a,onKeyDown:e=>{m||"Enter"!==e.key||e.shiftKey||e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),i?.())},onPaste:o,onInput:()=>c?.(g()),onCompositionStart:()=>h(!0),onCompositionEnd:()=>h(!1),"data-placeholder":d?e:void 0})});var Y=t(84369);function ee({pendingAttachments:e,onRemove:s}){return 0===e.length?null:(0,R.jsx)("div",{className:"chat-attachment-strip",children:e.map((e,t)=>(0,R.jsxs)("div",{className:"chat-attachment-chip",children:[(0,R.jsx)(I.In,{icon:"attach_file"}),(0,R.jsx)("span",{title:e.name,children:e.name}),(0,R.jsx)("button",{type:"button",onClick:()=>s(t),children:(0,R.jsx)(I.In,{icon:"close"})})]},`${e.name}_${t}`))})}const se=(0,n.forwardRef)(({onSend:e,sending:s,onAbort:t,pendingAttachments:o,onRemoveAttachment:c,onOpenFilePicker:r,onAddFiles:l,onDrop:d,onDragOver:u,fileInputRef:m},h)=>{const{t:g}=(0,i.Bd)(),p=(0,n.useRef)(null),_=(0,n.useRef)(null),[f,j]=(0,a.fp)(x.AG.ai_chat_input_height);(0,n.useImperativeHandle)(h,()=>({getValue:()=>p.current?.getValue()??"",setValue:e=>p.current?.setValue(e),clear:()=>p.current?.clear()}));const{dragging:v,on_pointer_down:b,on_pointer_up:w}=(0,Y.y)({direction:"vertical",get_start_size:()=>f,px_to_unit:e=>e/(()=>{const e=_.current;return e&&parseFloat(getComputedStyle(e).fontSize)||16})(),min:2,on_change:e=>j(e)}),y={minHeight:`${f}em`,maxHeight:`${f}em`};return(0,R.jsxs)("div",{ref:_,className:"chat-input-area",onDrop:d,onDragOver:u,children:[(0,R.jsx)("div",{className:"chat-input-resize-handle"+(v?" dragging":""),onPointerDown:b}),(0,R.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,R.jsxs)("div",{className:"chat-input-shell",children:[(0,R.jsx)(ee,{pendingAttachments:o,onRemove:c}),(0,R.jsx)(Z,{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:y})]}),(0,R.jsx)(I.rA,{title:g("添加文件"),icon:"attach_file",onClick:r}),s?(0,R.jsx)(I.Vi,{color:"var( --icon-red)",text:g("暂停"),clickFun:t}):(0,R.jsx)(I.Vi,{text:g("发送"),clickFun:e}),v&&(0,R.jsx)("div",{className:"chat-input-overlay",onPointerUp:w})]})}),te=function(e){const{t:s}=(0,i.Bd)(),[t,o]=(0,n.useState)([]),[r,l]=(0,n.useState)(!1),[d,u]=(0,n.useState)(null),[m,g]=(0,n.useState)(null),[p,_]=(0,n.useState)(!1),[f,j]=(0,a.fp)(x.AG.ai_bg_expanded),[,v]=(0,a.fp)(x.AG.ai_session_collapsed),b=()=>{j(!1)},w=(0,n.useCallback)(async()=>{l(!0);try{const s=new c.hf(c.HK.ai_bg_process_list_req);s.context={};const t=await $.ws.send(s);t?.context?.processes&&(o(t.context.processes),e.panelRef?.current?.onCountChange?.(t.context.processes.length))}catch(e){console.error("获取后台进程列表失败",e)}finally{l(!1)}},[]);e.panelRef&&(e.panelRef.current.refresh=w);const y=(0,n.useCallback)(async e=>{_(!0),u(e);try{const s=new c.hf(c.HK.ai_bg_process_output_req);s.context={pid:e};const t=await $.ws.send(s);g(t.context)}catch(e){console.error("获取进程输出失败",e),(0,h.zN)("获取进程输出失败")}finally{_(!1)}},[]),S=(0,n.useCallback)(async e=>{try{const s=new c.hf(c.HK.ai_bg_process_kill_req);s.context={pid:e};const t=await $.ws.send(s);t?.context?.success?((0,h.SK)("进程已终止"),w(),d===e&&(u(null),g(null))):(0,h.zN)(t?.context?.message||"终止失败")}catch(e){console.error("终止进程失败",e),(0,h.zN)("终止进程失败")}},[w,d]);(0,n.useEffect)(()=>{w();const e=setInterval(w,5e3);return()=>clearInterval(e)},[w]);const N=t.filter(e=>e.running),k=t.filter(e=>!e.running);return(0,R.jsxs)(R.Fragment,{children:[f&&(0,R.jsx)("div",{className:"chat-session-overlay",onClick:b}),(0,R.jsxs)("aside",{className:"chat-bg-process-panel "+(f?"expanded":""),children:[(0,R.jsxs)("div",{className:"chat-bg-process-header",children:[(0,R.jsx)("span",{className:"chat-bg-process-title",children:s("后台进程")}),(0,R.jsx)(I.rA,{icon:"close",title:s("关闭"),onClick:b})]}),(0,R.jsxs)("div",{className:"chat-bg-process-toolbar",children:[(0,R.jsx)(I.rA,{icon:"refresh",title:s("刷新"),onClick:w}),(0,R.jsxs)("span",{className:"chat-bg-process-count",children:[N.length," ",s("个运行中"),k.length>0&&` / ${k.length} ${s("个已退出")}`]})]}),(0,R.jsxs)("div",{className:"chat-bg-process-list",children:[r&&0===t.length&&(0,R.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}),!r&&0===t.length&&(0,R.jsx)("div",{className:"chat-bg-process-empty",children:s("暂无后台进程")}),N.map(e=>(0,R.jsxs)("div",{className:`chat-bg-process-item ${d===e.pid?"active":""} running`,children:[(0,R.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>y(e.pid),children:[(0,R.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,R.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>40?e.cmd.slice(0,40)+"...":e.cmd}),(0,R.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,R.jsx)("span",{className:"chat-bg-process-status running-dot",title:s("运行中"),children:"●"})]}),(0,R.jsxs)("div",{className:"chat-bg-process-item-actions",children:[(0,R.jsx)(I.rA,{icon:"terminal",title:s("查看输出"),onClick:()=>y(e.pid)}),(0,R.jsx)(I.rA,{icon:"stop",title:s("终止进程"),onClick:()=>S(e.pid)})]})]},e.pid)),k.map(e=>(0,R.jsx)("div",{className:`chat-bg-process-item ${d===e.pid?"active":""} finished`,children:(0,R.jsxs)("div",{className:"chat-bg-process-item-main",onClick:()=>y(e.pid),children:[(0,R.jsxs)("span",{className:"chat-bg-process-pid",children:["PID: ",e.pid]}),(0,R.jsx)("span",{className:"chat-bg-process-cmd",title:e.cmd,children:e.cmd.length>30?e.cmd.slice(0,30)+"...":e.cmd}),(0,R.jsx)("span",{className:"chat-bg-process-time",children:new Date(e.start_time).toLocaleTimeString()}),(0,R.jsxs)("span",{className:"chat-bg-process-exit-code",children:["exit: ",e.exit_code]})]})},e.pid))]}),null!==d&&(0,R.jsxs)("div",{className:"chat-bg-process-output",children:[(0,R.jsxs)("div",{className:"chat-bg-process-output-header",children:[(0,R.jsxs)("span",{children:["PID: ",d," ",s("输出")]}),(0,R.jsx)(I.rA,{icon:"close",title:s("关闭"),onClick:()=>{u(null),g(null)}})]}),(0,R.jsx)("div",{className:"chat-bg-process-output-content",children:p?(0,R.jsx)("div",{className:"chat-bg-process-empty",children:s("加载中...")}):m?(0,R.jsx)("pre",{className:"chat-bg-process-output-pre",children:m.output||s("(无输出)")}):null})]})]})]})};function ne(e={}){const{inline_header:s=!1,session_id:t,file_cwd_path:j,sync_url:w=!0,on_session_change:S}=e,{t:N}=(0,i.Bd)(),[k,C]=(0,o.ok)(),I=w&&k.get("session")||"",M=e=>{w&&C(s=>{const t=new URLSearchParams(s);return e?t.set("session",e):t.delete("session"),t},{replace:!0})},D=(0,g.y)(),{check_user_auth:H}=(0,u.MH)();(0,_.w)();const[V,K]=(0,n.useState)([]),[T,B]=(0,n.useState)([]),[z,P]=(0,n.useState)(""),[F,L]=(0,n.useState)(null),[O,q]=(0,n.useState)(!1),J=(0,n.useRef)(null),[U,Q]=(0,n.useState)([]),[Z,Y]=(0,a.fp)(x.AG.ai_session_collapsed),[ee,ne]=(0,a.fp)(x.AG.ai_bg_expanded),[ae,ie]=(0,a.fp)(x.AG.prompt_card),[oe]=(0,a.fp)(x.AG.ai_chat_zoom),[ce,re]=(0,n.useState)(!1),[le,de]=(0,n.useState)(new Set),[ue,me]=(0,n.useState)(new Set),[he,ge]=(0,n.useState)(""),pe=(0,n.useRef)(null),_e=(0,n.useRef)(null),xe=(0,n.useRef)(null),fe=(0,n.useRef)(!0),je=(0,n.useRef)(null),ve=(0,n.useRef)(0),be=(0,n.useRef)(null),we=(0,n.useRef)({}),ye=(0,n.useRef)(z),Se=(0,n.useRef)(F);(0,n.useEffect)(()=>{ye.current=z},[z]),(0,n.useEffect)(()=>{Se.current=F},[F]);const Ne=(0,n.useRef)({}),[ke,Ce]=(0,n.useState)([]),[Ae,$e]=(0,n.useState)(""),[Ie,Me]=(0,n.useState)([]),Re=async()=>{try{const e=await r.jV.get("public_models");e.code===p.m.Success&&Me(e.data?.groups??[])}catch{Me([])}},De=e=>{$e(e?.ai_config?.model??"")},[He,Ve]=(0,n.useState)(0),Ke=(0,n.useRef)((0,l.sg)(e=>{K(e),fe.current&&Te(!1)},50)).current,Te=(e=!1)=>{const s=xe.current;s&&s.scrollTo({top:s.scrollHeight,behavior:e?"smooth":"auto"})},Be=async()=>{const e=await r.jV.get("sessions");e.code===p.m.Success&&B(e.data??[])},Ee=function(e){const{getMessages:s,setMessages:t,setMessagesDebounced:a,setSending:i,getActiveSessionId:o,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||{};if(t.session_id!==e)return;const n=t.text||"",i=t.tool_call_ends,c=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=c,_.set(c,f),o()===e&&a([...h]);else{const s=_.get(c);if(s)s.text+=n,i&&(s.content_list=[{tool_call_ends:i,content:s.text,role:"assistant"}]),o()===e&&a([...h]);else{const s={id:Date.now()+Math.random(),sender:"bot",text:n,chunk_index:c};i&&(s.content_list=[{tool_call_ends:i,content:s.text,role:"assistant"}]),h.push(s),_.set(c,s),o()===e&&a([...h])}}},v=s=>{const n=s.context||{};if(n.session_id===e){if(w(),g.current=null,i(s=>s===e?null:s),f.is_loading=!1,o()===e)if(n.once_messages_list?.length){const e=y(n.once_messages_list);t(s=>{const t=s[s.length-1];return"bot"===t?.sender?[...s.slice(0,-1),...e]:[...s,...e]})}else t([...h]);l(),d(!0),r()}},b=s=>{const n=s.context||{};n.session_id===e&&(w(),g.current=null,i(s=>s===e?null:s),f.text="AI请求出错: "+(n.message||"未知错误"),f.is_loading=!1,o()===e&&t([...h]),r())},w=()=>{$.ws.off_message(`message_${c.HK.ai_chat_msg}`,j),$.ws.off_message(`message_${c.HK.ai_chat_end}`,v),$.ws.off_message(`message_${c.HK.ai_chat_error}`,b)};$.ws.addMsg(c.HK.ai_chat_msg,j),$.ws.addMsg(c.HK.ai_chat_end,v),$.ws.addMsg(c.HK.ai_chat_error,b),$.ws.sendData(c.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(o(),n,_)};return{startChatStream:p,processPendingQueue:_,enqueueMessage:(e,s)=>{h.current.push({text:e,attachments:s})},getQueueLength:()=>h.current.length,abort:()=>{const e=o();e&&($.ws.sendData(c.HK.ai_chat_abort,{session_id:e}),g.current&&(g.current=null,i(s=>s===e?null:s)))}}}({getMessages:()=>V,setMessages:K,setMessagesDebounced:Ke,setSending:L,getActiveSessionId:()=>ye.current,setActiveSessionId:P,refreshSessions:Be,scrollToBottom:Te,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:()=>he}),ze=async e=>{const s=await r.jV.get("sessions");if(s.code!==p.m.Success)return!1;const t=s.data??[];B(t);const n=null===e?t[0]?.id??"":e||z||t[0]?.id||"";return n?await Pe(n):(K([]),P(""),M(null),!1)},Pe=async(e,s=!1)=>{const t=await r.jV.post("session/get",{session_id:e});if(t.code!==p.m.Success||!t.data)return!1;const n=t.data;P(n.id),w&&I!==n.id&&M(n.id),S?.(n.id),q(!!n.running),be.current&&be.current!==n.id&&$.ws.sendData(c.HK.ai_chat_subscribe,{session_id:be.current,subscribe:!1}),be.current=n.running?n.id:null,be.current&&$.ws.sendData(c.HK.ai_chat_subscribe,{session_id:be.current,subscribe:!0});const a=y(n.messages);return n.running&&n.live_messages?.length?K([...a,...y(n.live_messages)]):K(a),ge(n.sys_prompt_id??""),s&&Y(!1),we.current.refresh?.(),requestAnimationFrame(()=>Te(!1)),!0},Fe=e=>{const s=Array.from(e??[]).filter(Boolean);s.length&&Q(e=>[...e,...s])},Le=()=>{ce&&(de(new Set),me(new Set)),re(e=>!e)},Oe=()=>{0!==le.size&&D({sub_title:N("cf_msgs"),confirm_fun:async()=>{const e=[];V.forEach((s,t)=>{le.has(s.id)&&e.push(t)}),K(V.filter(e=>!le.has(e.id))),de(new Set),re(!1),z&&e.length>0&&r.jV.post("session/message/delete",{session_id:z,indices:e}).catch(console.error)}})},qe=async()=>{const e=await r.XO.get("ai_agent_setting/env");if(e.code===p.m.Success&&(Ne.current=e.data,De(e.data)),await Re(),j){const e=await(async e=>{if(!e)return null;const s=await r.jV.get("sessions");if(s.code!==p.m.Success)return null;const t=(s.data??[]).find(s=>s.file_cwd_path===e);if(t)return t.id;const n=await r.jV.post("session",{title:"新会话",file_cwd_path:e});return n.code!==p.m.Success?null:n.data.id})(j);!!e&&await ze(e)||await ze()}else if(t){await ze(t)||await ze()}else if(I){await ze(I)||await ze()}else await ze();const s=await r.jV.get("system_prompts");s.code===p.m.Success&&Ce(s.data??[])};(0,n.useEffect)(()=>{qe(),requestAnimationFrame(()=>Te(!1)),we.current.onCountChange=Ve,we.current.refresh?.();const e=e=>{const s=e?.context?.count;"number"==typeof s&&Ve(s)};return $.ws.addMsg(c.HK.ai_bg_process_count_notify,e),()=>{$.ws.off_message(`message_${c.HK.ai_bg_process_count_notify}`,e)}},[]),(0,n.useEffect)(()=>{const e=xe.current;if(!e)return;const s=()=>{fe.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=()=>ye.current,s=()=>Se.current,t=(t,n)=>{if(e()&&e()===t){if(je.current=null,q(!1),be.current===t&&($.ws.sendData(c.HK.ai_chat_subscribe,{session_id:t,subscribe:!1}),be.current=null),s()===t)return;n?.length?K(e=>{const s=y(n),t=e[e.length-1];return"bot"===t?.sender?[...e.slice(0,-1),...s]:[...e,...s]}):Pe(t).catch(()=>{}),Be()}},n=t=>{const n=t?.context||{};if(!n.session_id)return;var a,i,o;a=n.session_id,i=n.text||"",o=n.tool_call_ends,e()&&e()===a&&s()!==a&&K(e=>{const s=e[e.length-1];if(s&&"bot"===s.sender){const t=[...e],n={...s};return n.text+=i,o&&(n.content_list=[{tool_call_ends:o,content:n.text,role:"assistant"}]),t[t.length-1]=n,je.current=n.id,fe.current&&requestAnimationFrame(()=>Te(!1)),t}const t={id:Date.now()+Math.random(),sender:"bot",text:i};return o&&(t.content_list=[{tool_call_ends:o,content:i,role:"assistant"}]),je.current=t.id,fe.current&&requestAnimationFrame(()=>Te(!1)),[...e,t]});const c=Date.now();c-ve.current>1500&&(ve.current=c,Be())},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 $.ws.addMsg(c.HK.ai_chat_msg,n),$.ws.addMsg(c.HK.ai_chat_end,a),$.ws.addMsg(c.HK.ai_chat_error,i),()=>{$.ws.off_message(`message_${c.HK.ai_chat_msg}`,n),$.ws.off_message(`message_${c.HK.ai_chat_end}`,a),$.ws.off_message(`message_${c.HK.ai_chat_error}`,i),be.current&&($.ws.sendData(c.HK.ai_chat_subscribe,{session_id:be.current,subscribe:!1}),be.current=null)}},[]),(0,n.useLayoutEffect)(()=>{fe.current&&Te(!1)},[V]);return(0,R.jsxs)(n.Fragment,{children:[(0,R.jsx)(G,{inline:s,currentModelName:Ae,setCurrentModelName:$e,modelGroups:Ie,onModelChanged:async()=>{await Re();const e=await r.XO.get("ai_agent_setting/env");e.code===p.m.Success&&(Ne.current=e.data,De(e.data))},sysPromptList:ke,batchMode:ce,selectedMsgCount:le.size,sessionVisible:!Z,onToggleSessionPanel:()=>{Y(e=>!e)},onCreateSession:async e=>{const s=e??"",t=await r.jV.post("session",{title:"新会话",sys_prompt_id:s||void 0,file_cwd_path:j||void 0});if(t.code!==p.m.Success)return;const n=t.data;P(n.id),K([]),ge(n.sys_prompt_id??""),Y(!1),await ze(n.id),requestAnimationFrame(()=>{const e=document.querySelector(".chat-input");e&&(e.style.height="auto",e.style.height=Math.min(e.scrollHeight,200)+"px")})},onBatchDeleteMessages:Oe,bgProcessVisible:ee,bgProcessCount:He,onToggleBgProcess:()=>ne(e=>!e),selectedSysPromptId:he,setSelectedSysPromptId:e=>{ge(e),z&&r.jV.post("session/sys_prompt",{session_id:z,sys_prompt_id:e||void 0}).catch(console.error)}}),(0,R.jsxs)("div",{className:"chat-page"+(s?" chat-page--embedded":" chat-page-with-sessions"),style:{"--ai-chat-zoom":oe},children:[!Z&&(0,R.jsx)(W,{sessions:T,activeSessionId:z,onSelectSession:e=>Pe(e,!1),onReorderSessions:(e,s)=>{const t=T.findIndex(s=>s.id===e),n=T.findIndex(e=>e.id===s);if(t<0||n<0||t===n)return;const a=(0,d.TI)(T,t,n);B(a),r.jV.post("sessions/update/sort",{session_ids:a.map(e=>e.id)}).catch(()=>{})},onRenameSession:(e,s)=>{let t=s;D({confirm_fun:async()=>{await r.jV.post("sessions/update/meta",{id:e,title:t}),await ze(z)},context_div:(0,R.jsx)("div",{className:"card-content",children:(0,R.jsx)(f.Sm,{value:t,handleInputChange:e=>{t=e}})})})},onDeleteSession:e=>{D({sub_title:"确认删除这个会话吗?",confirm_fun:async()=>{await r.jV.post("session/delete",{session_id:e}),z===e?(P(""),await ze(null)):await ze(z)}})},onToggleCmdAuto:async(e,s)=>{await r.jV.post("session/cmd_auto_allow",{session_id:e,allow:s}),(0,h.SK)(N(s?"命令检测已开启":"命令检测已关闭")),await ze(z)},onShowUsageStats:async e=>{ie({open:!0,title:N("Token消耗统计"),context_div:(0,R.jsx)("div",{className:"usage-stats-loading",children:N("加载中...")}),cancel:()=>ie({open:!1})});try{const s=await r.jV.post("session/usage_stats",{session_id:e});if(s.code===p.m.Success&&s.data){const e=s.data;ie({open:!0,title:N("Token消耗统计"),context_div:(0,R.jsxs)("div",{className:"usage-stats-panel",children:[[{l:N("对话轮次"),v:(e.turns??0).toString()},{l:N("AI输入Token"),v:v(e.input_tokens)},{l:N("AI输出Token"),v:v(e.output_tokens)},{l:N("AI输入Token(最近一轮)"),v:v(e.recent_input_tokens)},{l:N("AI输出Token(最近一轮)"),v:v(e.recent_output_tokens)}].map((e,s)=>(0,R.jsxs)("div",{className:"usage-stats-row",children:[(0,R.jsx)("span",{className:"usage-stats-label",children:e.l}),(0,R.jsx)("span",{className:"usage-stats-value",children:e.v})]},s)),(0,R.jsxs)("div",{className:"usage-stats-row usage-stats-total",children:[(0,R.jsx)("span",{className:"usage-stats-label",children:N("AI Token总计消耗")}),(0,R.jsx)("span",{className:"usage-stats-value",children:v((e.input_tokens||0)+(e.output_tokens||0))})]})]}),cancel:()=>ie({open:!1})})}else ie({open:!0,title:N("Token消耗统计"),context_div:(0,R.jsx)("div",{className:"usage-stats-empty",children:N("暂无统计数据")}),cancel:()=>ie({open:!1})})}catch{ie({open:!0,title:N("Token消耗统计"),context_div:(0,R.jsx)("div",{className:"usage-stats-empty",children:N("暂无统计数据")}),cancel:()=>ie({open:!1})})}},onShowSessionSetting:e=>{let s=T.find(s=>s.id===e)?.file_cwd_path??"";ie({open:!0,title:N("会话设置"),context_div:(0,R.jsxs)("div",{className:"session-setting",children:[(0,R.jsx)("div",{className:"session-setting__label",children:N("服务器工作目录")}),(0,R.jsx)(f.Sm,{value:s,placeholder:N("服务器工作目录提示"),handleInputChange:e=>{s=e}})]}),confirm:async()=>{try{(await r.jV.post("session/setting",{session_id:e,file_cwd_path:s.trim()})).code===p.m.Success&&(0,h.SK)(N("保存成功"))}catch{}ie({open:!1}),await ze(z)},cancel:()=>ie({open:!1})})},batchMode:ce,selectedSessionIds:ue,onToggleSessionSelect:e=>{me(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onToggleBatchMode:Le,onBatchDeleteSessions:()=>{0!==ue.size&&D({sub_title:N("cf_ses"),confirm_fun:async()=>{for(const e of ue)await r.jV.post("session/delete",{session_id:e});me(new Set),re(!1),ue.has(z)?(P(""),await ze(null)):await ze(z)}})},onClearAllSessions:()=>{D({sub_title:N("cf_all"),confirm_fun:async()=>{await r.jV.post("sessions/clear",{}),P(""),K([]),await ze(null)}})}}),(0,R.jsx)(te,{panelRef:we}),(0,R.jsxs)("section",{className:"chat-main",children:[0===V?.length&&(0,R.jsx)("div",{className:"chat-header",children:(0,R.jsx)("div",{children:N("ai_ask")})}),(0,R.jsx)(X,{messages:V,batchMode:ce,selectedMsgIds:le,sending:F===z||O,chatContainerRef:xe,messagesEndRef:_e,onToggleMsgSelect:e=>{de(s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t})},onDelete:e=>{D({sub_title:N("cf_one"),confirm_fun:async()=>{const s=V.findIndex(s=>s.id===e);if(s<0)return;const t=V.filter(s=>s.id!==e);K(t),z&&r.jV.post("session/message/delete",{session_id:z,indices:[s]}).catch(console.error)}})},onCopy:async e=>{(0,m.lW)(b(e)),(0,h.SK)("复制成功")},onCopyAll:async()=>{if(!T.length)return void(0,h.SK)("暂无聊天记录");const e=[];for(const s of T){const t=await r.jV.post("session/get",{session_id:s.id});if(t.code!==p.m.Success||!t.data)continue;const n=t.data,a=y([...n.messages??[],...n.live_messages??[]]).map(b).filter(Boolean).join("\n\n\n");a&&e.push(a)}e.length?((0,m.lW)(e.join("\n\n\n")),(0,h.SK)("复制成功")):(0,h.SK)("暂无聊天记录")},onToggleBatchMode:Le,onBatchCopy:()=>{const e=V.filter(e=>le.has(e.id)).map(b).filter(Boolean).join("\n\n\n");e?((0,m.lW)(e),(0,h.SK)("复制成功")):(0,h.SK)("暂无内容")},onBatchDelete:Oe,showBatchBar:ce&&le.size>0&&0===ue.size,t:N}),(0,R.jsx)(se,{ref:J,onSend:async()=>{const e=(J.current?.getValue()??"").trim();if(!e&&0===U.length)return;if(F===z){const s=await A(U);Ee.enqueueMessage(e,s),J.current?.clear(),Q([]);const t={id:Date.now(),sender:"user",text:e+(Ee.getQueueLength()>1?" ⏳(排队中...)":""),attachments:s};return void K(e=>[...e,t])}let s=z;if(!s){const t=await r.jV.post("session",{title:(e||U[0]?.name||"新会话").slice(0,28),sys_prompt_id:void 0,file_cwd_path:j||void 0});if(t.code!==p.m.Success)return;s=t.data.id,P(s),S?.(s),await ze(s)}const t=await A(U),n={id:Date.now(),sender:"user",text:e,attachments:t};J.current?.clear(),Q([]);const a=Ne?.current?.ai_config?.request_type||"completions";if("completions"!==a){const t={id:n.id+1,sender:"bot",text:"处理中...",is_loading:!0},i=[...V,n,t];K(i),L(s);return void(await E(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),K([...i]),L(null),Be(),Te(!0),Ee.processPendingQueue()})||(t.text=`请求类型 "${a}" 的专用处理器尚未实现,请使用 completions 类型。`,t.is_loading=!1,K([...i]),L(null),Ee.processPendingQueue()))}Ee.startChatStream(s,n,()=>Ee.processPendingQueue())},sending:F===z||O,onAbort:Ee.abort,pendingAttachments:U,onRemoveAttachment:e=>{Q(s=>s.filter((s,t)=>t!==e))},onOpenFilePicker:()=>{pe.current?.click()},onAddFiles:Fe,onDrop:e=>{const s=e.dataTransfer?.files;s&&s.length>0&&(e.preventDefault(),Fe(s))},onDragOver:e=>{e.dataTransfer?.types?.includes("Files")&&e.preventDefault()},fileInputRef:pe})]})]})]})}},72693(e,s,t){t.d(s,{w:()=>h});var n=t(96540),a=t(22022),i=t(14944),o=t(92275),c=t(34843),r=t(82893),l=t(85997),d=t(14284),u=t(74848);function m(e){const{t:s}=(0,a.Bd)(),[t,i]=(0,n.useState)(!1),o=!!e.sessionId;return(0,u.jsxs)("div",{children:[(0,u.jsx)("div",{style:{maxHeight:"60vh",overflow:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--surfaceSecondary)",padding:"0.75em",borderRadius:"0.5em",marginBottom:"0.75em",fontFamily:"monospace",fontSize:"0.9em",lineHeight:"1.5"},children:e.cmd}),o&&(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5em",marginBottom:"0.75em",color:t?"var(--icon-blue)":"var(--textSecondary)"},children:[(0,u.jsx)(l.Ay,{checked:t,onChange:s=>{i(s),s&&e.onAutoAllow()},title:s("此会话不再询问")}),(0,u.jsx)("span",{children:s("此会话不再询问")})]}),(0,u.jsxs)("div",{style:{display:"flex",gap:"0.5em",justifyContent:"flex-end"},children:[(0,u.jsx)(l.$n,{text:s("拒绝"),color:"var(--red)",clickFun:e.onDeny}),(0,u.jsx)(l.$n,{text:s("允许"),clickFun:e.onAllow})]})]})}function h(){const[e,s]=(0,c.fp)(r.AG.prompt_card),{t}=(0,a.Bd)(),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(o.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)(()=>{const e=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})};return i.ws.addMsg(o.HK.ai_confirm_cmd,e),()=>{i.ws.off_message(`message_${o.HK.ai_confirm_cmd}`,e)}},[j]),(0,n.useEffect)(()=>()=>{l.current=[],h.current=!1,g.current=null},[])}},34299(e,s,t){t.r(s),t.d(s,{default:()=>b});var n=t(96540),a=t(23802),i=t(53995),o=t(18569),c=t(77979),r=t(8263),l=t(69428),d=t.n(l),u=(t(3775),t(21499)),m=t(99214),h=t(89117),g=t(89334),p=t(41105),_=t(52388),x=t(19878),f=(t(72411),t(74848));const j=new a.A({html:!0,highlight:function(e,s){if(s&&x.A.getLanguage(s))try{return`<pre class="hljs code-block-with-copy"><code class="hljs language-${s}">${x.A.highlight(e,{language:s}).value}</code></pre>`}catch(e){}try{return`<pre class="hljs code-block-with-copy"><code class="hljs">${x.A.highlightAuto(e).value}</code></pre>`}catch(e){}return`<pre class="hljs code-block-with-copy"><code>${j.utils.escapeHtml(e)}</code></pre>`}});function v(e){const s=e.className.match(/language-([\w-]+)/);return s?s[1]:""}function b(e){const s=(0,n.useRef)(null);return(0,m.VD)(),(0,n.useEffect)(()=>{s.current&&(!async function(e){const s=e.querySelectorAll("pre > code[class*='language-']");for(const e of Array.from(s)){const s=v(e);if(!(0,h.Hm)(s))continue;const t=e.closest(".code-block-with-copy")??e.parentElement;if(!t)continue;const n=e.textContent??"",a=document.createElement("div");a.className="md-graph md-graph--loading",a.textContent=_.A.t("rendering"),t.replaceWith(a);const i=await(0,h.U6)(s,n);a.isConnected&&(i.error?(a.className="md-graph md-graph--error",a.textContent=i.error):(a.className="md-graph",a.innerHTML=i.svg))}}(s.current),(0,g.rg)(s.current))},[e.context]),(0,f.jsx)("div",{ref:s,dangerouslySetInnerHTML:{__html:j.render(e.context)}})}j.use(i.A).use(o.A).use(c.A).use(r.A).use(d()).use(e=>{e.renderer.rules.fence;e.renderer.rules.fence=(s,t,n,a,i)=>{const o=s[t],c=o.content.trim(),r=o.info.trim();let l="";if(r&&x.A.getLanguage(r))try{l=x.A.highlight(c,{language:r}).value}catch(s){l=e.utils.escapeHtml(c)}else try{l=x.A.highlightAuto(c).value}catch(s){l=e.utils.escapeHtml(c)}return`\n <div class="code-block-with-copy">\n <div class="code-header">\n <span class="code-language">${r||"code"}</span>\n <button class="copy-btn" data-code="${e.utils.escapeHtml(c)}">复制</button>\n </div>\n <pre><code class="hljs ${r?`language-${r}`:""}">${l}</code></pre>\n </div>`}}).use(e=>{const s=e.renderer.rules.link_open||function(e,s,t,n,a){return a.renderToken(e,s,t)};e.renderer.rules.link_open=(e,t,n,a,i)=>{const o=e[t],c=o.attrIndex("href");if(c>=0){const e=o.attrs[c][1];o.attrs[c][1]=(0,u.bi)(window.location.href,e)}return s(e,t,n,a,i)}}),(0,g.Rh)(j,p.pC)},84369(e,s,t){t.d(s,{y:()=>o});var n=t(96540),a=t(2543);function i(e){if(void 0!==e)return"function"==typeof e?e():e}function o(e){const{direction:s="vertical",target_ref:t,get_start_size:o,px_to_unit:c,min:r,max:l,throttle:d,on_change:u,on_drag_end:m}=e,[h,g]=(0,n.useState)(!1),p=(0,n.useRef)(null),_=(0,n.useRef)(u);_.current=u;const x=e=>"vertical"===s?e.clientY:e.clientX,f=(0,n.useRef)({direction:s,get_start_size:o,px_to_unit:c,min:r,max:l,get_pos:x});f.current={direction:s,get_start_size:o,px_to_unit:c,min:r,max:l,get_pos:x};const j=(0,n.useCallback)(e=>{const s=p.current;if(!s)return;const{px_to_unit:t,min:n,max:a,get_pos:o}=f.current,c=s.pos-o(e);let r=s.size+t(c);const l=i(n),d=i(a);void 0!==l&&(r=Math.max(l,r)),void 0!==d&&(r=Math.min(d,r)),_.current(r)},[]),v=n.useMemo(()=>void 0===d?j:a.throttle(e=>j(e),d),[d,j]),b=(0,n.useCallback)(()=>{p.current=null,g(!1);const e=v;"function"==typeof e.cancel&&e.cancel(),m?.()},[v,m]),w=(0,n.useCallback)(e=>{const{get_start_size:s,get_pos:t}=f.current;p.current={pos:t(e),size:s()},g(!0)},[]);return(0,n.useEffect)(()=>{if(!h)return;const e=t?.current??window;return e.addEventListener("pointermove",v),e.addEventListener("pointerup",b),()=>{e.removeEventListener("pointermove",v),e.removeEventListener("pointerup",b)}},[h,v,b,t]),(0,n.useEffect)(()=>{const e=v;return()=>{"function"==typeof e.cancel&&e.cancel()}},[v]),{dragging:h,on_pointer_down:w,on_pointer_up:b}}},60840(e){e.exports="data:image/svg+xml,<svg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27 version=%271.1%27 aria-hidden=%27true%27><path fill-rule=%27evenodd%27 d=%27M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z%27></path></svg>"}}]);