@aalis/plugin-webui-client 0.4.2 → 0.5.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 (66) hide show
  1. package/dist/assets/AuthorityPage-D8tM4Jkk.js +16 -0
  2. package/dist/assets/ConfirmDialog-DbV-E1Nd.js +1 -0
  3. package/dist/assets/{DynamicPage-CNJTcLnN.js → DynamicPage-C3r8FUPm.js} +1 -1
  4. package/dist/assets/{FilesPage-BDkXMn2Z.js → FilesPage-BsecL1P2.js} +1 -1
  5. package/dist/assets/MarketplacePage-BeKSN-rv.js +6 -0
  6. package/dist/assets/{PlatformPage-69hFZKZQ.js → PlatformPage-COs5JjPE.js} +1 -1
  7. package/dist/assets/PluginConfigPage-D2LUENTd.js +23 -0
  8. package/dist/assets/{SessionsPage-UesoGK-U.js → SessionsPage-BSXA8zsW.js} +1 -1
  9. package/dist/assets/{arc-C1C8ofUu.js → arc-BcIO9BfO.js} +1 -1
  10. package/dist/assets/{architectureDiagram-3BPJPVTR-8ItpcM0M.js → architectureDiagram-3BPJPVTR-Ckgcj3C6.js} +1 -1
  11. package/dist/assets/{blockDiagram-GPEHLZMM-e278UOZ1.js → blockDiagram-GPEHLZMM-DUJAGy-V.js} +1 -1
  12. package/dist/assets/{c4Diagram-AAUBKEIU-zEn3CuR9.js → c4Diagram-AAUBKEIU-2O4dZC2J.js} +1 -1
  13. package/dist/assets/channel-Rk2mElPG.js +1 -0
  14. package/dist/assets/{chunk-2J33WTMH-BRSV8jER.js → chunk-2J33WTMH-raYd61X4.js} +1 -1
  15. package/dist/assets/{chunk-4BX2VUAB-DQe5s5lD.js → chunk-4BX2VUAB-yyQO-yMR.js} +1 -1
  16. package/dist/assets/{chunk-55IACEB6-CC6IKjNG.js → chunk-55IACEB6-CFywrQV5.js} +1 -1
  17. package/dist/assets/{chunk-727SXJPM-DW7QtRdS.js → chunk-727SXJPM-BuMVJVk6.js} +1 -1
  18. package/dist/assets/{chunk-AQP2D5EJ-BmZhrldk.js → chunk-AQP2D5EJ-Cf22e-wI.js} +1 -1
  19. package/dist/assets/{chunk-FMBD7UC4-DdCUM4gd.js → chunk-FMBD7UC4-BQAwLV2v.js} +1 -1
  20. package/dist/assets/{chunk-ND2GUHAM-mCIgZWkP.js → chunk-ND2GUHAM-DoDWTieE.js} +1 -1
  21. package/dist/assets/{chunk-QZHKN3VN-CbOaIP_o.js → chunk-QZHKN3VN-CHYdElx3.js} +1 -1
  22. package/dist/assets/classDiagram-4FO5ZUOK-CuD8LqLR.js +1 -0
  23. package/dist/assets/classDiagram-v2-Q7XG4LA2-CuD8LqLR.js +1 -0
  24. package/dist/assets/{clock-C78cKfEH.js → clock-C13OxDcQ.js} +1 -1
  25. package/dist/assets/{cose-bilkent-S5V4N54A-JG-g7yO6.js → cose-bilkent-S5V4N54A-BDhJ5StZ.js} +1 -1
  26. package/dist/assets/{dagre-BM42HDAG-WsBIHgG6.js → dagre-BM42HDAG-CZHlqrZg.js} +1 -1
  27. package/dist/assets/{diagram-2AECGRRQ-BRWYjjQ4.js → diagram-2AECGRRQ-B18MLe8Z.js} +1 -1
  28. package/dist/assets/{diagram-5GNKFQAL-BytqVEJ-.js → diagram-5GNKFQAL-Bxuqyrbt.js} +1 -1
  29. package/dist/assets/{diagram-KO2AKTUF-hb8rpL1j.js → diagram-KO2AKTUF-DzYO6txa.js} +1 -1
  30. package/dist/assets/{diagram-LMA3HP47-xy7p2Dua.js → diagram-LMA3HP47-BTdo9KPv.js} +1 -1
  31. package/dist/assets/{diagram-OG6HWLK6-C8Xsbb2D.js → diagram-OG6HWLK6-DuRqHpgf.js} +1 -1
  32. package/dist/assets/{erDiagram-TEJ5UH35-CmPUjEAN.js → erDiagram-TEJ5UH35-BQTIyY-f.js} +1 -1
  33. package/dist/assets/{flowDiagram-I6XJVG4X-CyA6TsIo.js → flowDiagram-I6XJVG4X-CdVtB4GR.js} +1 -1
  34. package/dist/assets/{ganttDiagram-6RSMTGT7-DFyQ0_Fc.js → ganttDiagram-6RSMTGT7-C7HBiJ6w.js} +1 -1
  35. package/dist/assets/{gitGraphDiagram-PVQCEYII-B-Vn7-Dr.js → gitGraphDiagram-PVQCEYII-DOIMmzt3.js} +1 -1
  36. package/dist/assets/{globe-Kcd-3YqI.js → globe-CmrIFzvQ.js} +1 -1
  37. package/dist/assets/index-BmSmi5hw.js +207 -0
  38. package/dist/assets/{index-CaU2rCNv.css → index-EjEFcXcf.css} +1 -1
  39. package/dist/assets/{infoDiagram-5YYISTIA-DWqAc1XU.js → infoDiagram-5YYISTIA-Bt9ytkbK.js} +1 -1
  40. package/dist/assets/{ishikawaDiagram-YF4QCWOH-BMYuTloU.js → ishikawaDiagram-YF4QCWOH-Cv4Z-Yx7.js} +1 -1
  41. package/dist/assets/{journeyDiagram-JHISSGLW-nlNlTZ17.js → journeyDiagram-JHISSGLW-BP5fVFGk.js} +1 -1
  42. package/dist/assets/{kanban-definition-UN3LZRKU-faJtQP8n.js → kanban-definition-UN3LZRKU-D6NKAn15.js} +1 -1
  43. package/dist/assets/{linear-BEHw4aep.js → linear-sOj0r-nV.js} +1 -1
  44. package/dist/assets/{mermaid.core-CdhXQnZd.js → mermaid.core-DRBjcUv6.js} +4 -4
  45. package/dist/assets/{mindmap-definition-RKZ34NQL-CceAdb-a.js → mindmap-definition-RKZ34NQL-DY9ZVZYO.js} +1 -1
  46. package/dist/assets/{pieDiagram-4H26LBE5-BlgRYzJ4.js → pieDiagram-4H26LBE5-BFHJPE_0.js} +1 -1
  47. package/dist/assets/{quadrantDiagram-W4KKPZXB-Af7PyAAW.js → quadrantDiagram-W4KKPZXB-CB7WGOU4.js} +1 -1
  48. package/dist/assets/{requirementDiagram-4Y6WPE33-VO1Y3hfL.js → requirementDiagram-4Y6WPE33-1Vfe3_sr.js} +1 -1
  49. package/dist/assets/{sankeyDiagram-5OEKKPKP-DfiQjgmw.js → sankeyDiagram-5OEKKPKP-TmuLSXwo.js} +1 -1
  50. package/dist/assets/{sequenceDiagram-3UESZ5HK-CerqLOrN.js → sequenceDiagram-3UESZ5HK-YvTQKyOr.js} +1 -1
  51. package/dist/assets/{stateDiagram-AJRCARHV-BKoCD-3C.js → stateDiagram-AJRCARHV-CKfFj6XP.js} +1 -1
  52. package/dist/assets/{stateDiagram-v2-BHNVJYJU-D3J-8YEh.js → stateDiagram-v2-BHNVJYJU-zUKSxMr4.js} +1 -1
  53. package/dist/assets/{timeline-definition-PNZ67QCA-B2VNsLMh.js → timeline-definition-PNZ67QCA-CngO2jjJ.js} +1 -1
  54. package/dist/assets/{vennDiagram-CIIHVFJN-DjijEYHv.js → vennDiagram-CIIHVFJN-DURn8ESK.js} +1 -1
  55. package/dist/assets/{wardley-L42UT6IY-D5JprGQD.js → wardley-L42UT6IY-BKa-ecG2.js} +1 -1
  56. package/dist/assets/{wardleyDiagram-YWT4CUSO-D5-MQMdk.js → wardleyDiagram-YWT4CUSO-C6V3F7Mg.js} +1 -1
  57. package/dist/assets/{xychartDiagram-2RQKCTM6-D4As0A0v.js → xychartDiagram-2RQKCTM6-VniDsYL5.js} +1 -1
  58. package/dist/index.html +2 -2
  59. package/package.json +10 -10
  60. package/dist/assets/AuthorityPage-BM4HipXP.js +0 -12
  61. package/dist/assets/MarketplacePage-pv_YtVO7.js +0 -18
  62. package/dist/assets/PluginConfigPage-C40cz0di.js +0 -23
  63. package/dist/assets/channel-LERG0Vbd.js +0 -1
  64. package/dist/assets/classDiagram-4FO5ZUOK-CjC5-lNd.js +0 -1
  65. package/dist/assets/classDiagram-v2-Q7XG4LA2-CjC5-lNd.js +0 -1
  66. package/dist/assets/index-CAL5qre3.js +0 -207
@@ -1,23 +0,0 @@
1
- import{r as d,j as e}from"./react-vendor-BPQixOLZ.js";import{c as _,a as S,T as Ae}from"./index-CAL5qre3.js";import{b as K,S as ye,f as Ne,u as Re}from"./SchemaForm-YVQZ6Keg.js";import"./highlight-DJvvuuwd.js";import"./katex-Bq6vt64r.js";import"./markdown-BCywGHw2.js";/**
2
- * @license lucide-react v1.7.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const Ge=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],Je=_("link-2",Ge);/**
7
- * @license lucide-react v1.7.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const Ke=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],Ze=_("loader-circle",Ke);/**
12
- * @license lucide-react v1.7.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const He=[["path",{d:"M16.247 7.761a6 6 0 0 1 0 8.478",key:"1fwjs5"}],["path",{d:"M19.075 4.933a10 10 0 0 1 0 14.134",key:"ehdyv1"}],["path",{d:"M4.925 19.067a10 10 0 0 1 0-14.134",key:"1q22gi"}],["path",{d:"M7.753 16.239a6 6 0 0 1 0-8.478",key:"r2q7qm"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}]],We=_("radio",He);/**
17
- * @license lucide-react v1.7.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const Qe=[["rect",{width:"8",height:"8",x:"3",y:"3",rx:"2",key:"by2w9f"}],["path",{d:"M7 11v4a2 2 0 0 0 2 2h4",key:"xkn7yn"}],["rect",{width:"8",height:"8",x:"13",y:"13",rx:"2",key:"1cgmvn"}]],Xe=_("workflow",Qe);function Z({label:f,value:r,depth:u=0,secret:O,description:v,defaultValue:y}){const[p,I]=d.useState(u<1);if(Array.isArray(r))return r.length===0?e.jsxs("div",{className:"config-item",style:{paddingLeft:u*12},children:[e.jsxs("span",{className:"key",children:[e.jsx("code",{className:"field-key",children:f}),v&&e.jsxs("span",{className:"field-hint",children:[" / ",v]})]}),e.jsx("span",{className:"val",children:"(空)"})]}):e.jsxs("div",{className:"config-nested",style:{paddingLeft:u*12},children:[e.jsxs("div",{className:"config-nested-header",onClick:()=>I(h=>!h),children:[e.jsx("span",{className:`config-block-toggle ${p?"open":""}`,children:"▶"}),e.jsxs("span",{className:"key",children:[e.jsx("code",{className:"field-key",children:f}),v&&e.jsxs("span",{className:"field-hint",children:[" / ",v]})]}),e.jsxs("span",{className:"config-nested-count",children:[r.length," 项"]})]}),p&&e.jsx("div",{className:"config-nested-body",children:r.map((h,b)=>e.jsx(Z,{label:`#${b+1}`,value:h,depth:u+1,secret:O},b))})]});if(r==null||typeof r!="object"){const h=O||typeof r=="string"&&/(apiKey|password|secret|token)(?![a-zA-Z])/i.test(f),b=r==null,w=b&&y!==void 0&&y!==null,k=b?w?typeof y=="object"?JSON.stringify(y):String(y):"-":String(r),M=h&&k.length>4?k.slice(0,4)+"••••••":k;return e.jsxs("div",{className:"config-item",style:{paddingLeft:u*12},children:[e.jsxs("span",{className:"key",children:[e.jsx("code",{className:"field-key",children:f}),v&&e.jsxs("span",{className:"field-hint",children:[" / ",v]})]}),e.jsxs("span",{className:"val",title:h?"••••••":k,children:[M,w&&e.jsx("span",{className:"field-hint",children:" (默认)"})]})]})}const z=Object.entries(r);return e.jsxs("div",{className:"config-nested",style:{paddingLeft:u*12},children:[e.jsxs("div",{className:"config-nested-header",onClick:()=>I(h=>!h),children:[e.jsx("span",{className:`config-block-toggle ${p?"open":""}`,children:"▶"}),e.jsx("span",{className:"key",children:f}),e.jsxs("span",{className:"config-nested-count",children:[z.length," 项"]})]}),p&&e.jsx("div",{className:"config-nested-body",children:z.map(([h,b])=>e.jsx(Z,{label:h,value:b,depth:u+1,secret:O},h))})]})}function ts({plugins:f,config:r,onRefresh:u,onConfigSaved:O,onRestart:v}){const[y,p]=d.useState(new Set),I=d.useRef(f),[z,h]=d.useState(null),[b,w]=d.useState({}),[k,M]=d.useState({}),[D,H]=d.useState({}),[F,W]=d.useState(void 0),[Q,X]=d.useState(null),[Y,V]=d.useState(!1),[ve,Se]=d.useState(new Set),[q,ee]=d.useState(""),[ke,Ce]=d.useState(new Set),[se,B]=d.useState(null),[U,A]=d.useState("");d.useEffect(()=>{I.current!==f&&y.size>0&&p(new Set),I.current=f},[f,y]);const P=s=>p(t=>new Set(t).add(s)),C=s=>y.has(s),j=s=>{X(s),setTimeout(()=>X(null),2500)},we=async s=>{if(s.core)return;P(s.instanceId);const t=s.state==="disabled"?"enable":"disable",i=await S(`/api/plugins/${encodeURIComponent(s.instanceId)}/${t}`,{method:"POST"});i.ok?(j(`${s.instanceId} 已${t==="enable"?"启用":"禁用"}`),u()):(j(i.error??"未知错误"),p(l=>{const x=new Set(l);return x.delete(s.instanceId),x}))},$e=s=>{const t=s.config??{};s.configSchema?M(K(s.configSchema,t)):w(Ne(t)),h(s.instanceId)},ne=d.useCallback(async s=>{if(!D[s])try{const t=await S(`/api/models/${encodeURIComponent(s)}`),i=t.providers&&t.providers.length>0?t.providers.map(l=>({label:`${l.provider} / ${l.model}`,value:l.value})):(t.models??[]).map(l=>({label:l,value:l}));H(l=>({...l,[s]:i}))}catch{H(t=>({...t,[s]:[]}))}},[D]),ae=d.useCallback(async()=>{if(!F)try{const s=await S("/api/llm-providers");W(s.providers??[])}catch{W([])}},[F]),te=s=>{const t=s.defaultConfig??{};s.configSchema?M(K(s.configSchema,t)):w(Ne(t))},ie=async(s,t)=>{const i=t?k:Re(b);P(s),await S(`/api/plugins/${encodeURIComponent(s)}/config`,{method:"PUT",body:JSON.stringify({config:i})}),j(`${s} 配置已更新,正在重载…`),h(null),u()},ce=async s=>{const t=U.trim();if(!t)return;P(s);const i=await S(`/api/plugins/${encodeURIComponent(s)}/instances`,{method:"POST",body:JSON.stringify({suffix:t})});i.ok?(j(`已创建实例 ${i.instanceId}`),B(null),A(""),u()):(j(i.error??"创建失败"),p(l=>{const x=new Set(l);return x.delete(s),x}))},Le=async s=>{if(!confirm(`确定删除实例 "${s}"?配置将一并移除。`))return;P(s);const t=await S(`/api/plugins/${encodeURIComponent(s)}/instance`,{method:"DELETE"});t.ok?(j(`已删除实例 ${s}`),u()):(j(t.error??"删除失败"),p(i=>{const l=new Set(i);return l.delete(s),l}))},Oe=new Set(["@aalis/core","@aalis/plugin-package-manager","@aalis/plugin-webui-server","@aalis/plugin-webui-client"]),Ie=s=>Oe.has(s)||/-api$/.test(s.replace(/^@[^/]+\//,"")),Me=async s=>{if(!confirm(`确定卸载插件「${s.displayName??s.name}」(${s.name})?
22
-
23
- 将删除其代码目录并清除残留配置。不可恢复,但可从插件市场重新安装。`))return;P(s.instanceId);const t=await S("/api/marketplace/uninstall",{method:"POST",body:JSON.stringify({name:s.name})});t.ok?(j(t.message??`${s.name} 已卸载`),u()):(j(t.error??"卸载失败"),p(i=>{const l=new Set(i);return l.delete(s.instanceId),l}))},Pe=s=>s.instanceId!==s.name,Te={active:"运行中",disabled:"已禁用",pending:"等待中",disposed:"已释放",error:"运行错误"},Ee={active:"active",disabled:"disposed",pending:"pending",error:"error"},ze=s=>{Se(t=>{const i=new Set(t);return i.has(s)?i.delete(s):i.add(s),i})},[le,R]=d.useState(!1),[oe,re]=d.useState({}),$=r&&r._schema?r._schema:void 0;d.useEffect(()=>{r&&$&&re(K($,r))},[r,$]);const De=async()=>{V(!0);const s=await S("/api/config",{method:"PUT",body:JSON.stringify(oe)});V(!1),s.ok?(R(!1),O(),s.restart?v():j("全局配置已保存")):j(s.error??"未知错误")};return e.jsxs("div",{className:"page-content page-plugin-config",children:[Q&&e.jsx("div",{className:"toast",children:Q}),e.jsxs("div",{className:"config-header-row",children:[e.jsx("div",{className:"section-label",style:{marginBottom:0},children:"全局配置"}),e.jsx("div",{style:{display:"flex",gap:6},children:le?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-primary btn-sm",onClick:De,disabled:Y,children:Y?"保存中...":"保存"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>R(!1),children:"取消"})]}):e.jsx("button",{className:"btn btn-sm",onClick:()=>R(!0),children:"编辑"})})]}),r&&$&&e.jsx("div",{className:"config-block",style:{marginTop:8,marginBottom:20},children:e.jsx("div",{className:"config-block-body",style:{paddingTop:10},children:le?e.jsx(ye,{schema:$,draft:oe,onChange:re,modelCache:D,onFetchModels:ne,llmProviders:F,onFetchLLMProviders:ae}):e.jsx(e.Fragment,{children:Object.entries($).map(([s,t])=>{const i=r[s],l=t,x=l.description||l.label;return e.jsxs("div",{className:"config-item",children:[e.jsxs("span",{className:"key",children:[e.jsx("code",{className:"field-key",children:s}),x&&e.jsxs("span",{className:"field-hint",children:[" / ",x]})]}),e.jsx("span",{className:"val",children:l.type==="boolean"?i?"✓ 开启":"✗ 关闭":i===""||i==null?"(空)":String(i)})]},s)})})})}),e.jsx("div",{className:"section-label",style:{marginBottom:0},children:"插件管理"}),e.jsxs("div",{className:"plugin-search-row",children:[e.jsx("input",{className:"plugin-search-input",placeholder:"搜索插件 / 工具名 / 指令名...",value:q,onChange:s=>ee(s.target.value)}),q&&e.jsx("button",{className:"plugin-search-clear",onClick:()=>ee(""),children:"✕"})]}),f.length===0&&e.jsx("div",{className:"empty-hint",children:"无插件"}),(()=>{const s=q.toLowerCase(),t=s?f.filter(c=>c.name.toLowerCase().includes(s)||c.instanceId.toLowerCase().includes(s)||c.displayName&&c.displayName.toLowerCase().includes(s)||c.provides.some(o=>o.toLowerCase().includes(s))||(c.tools??[]).some(o=>o.toLowerCase().includes(s))||(c.commands??[]).some(o=>o.toLowerCase().includes(s))):f,i={},l=["系统","LLM 模型","智能体","存储","嵌入模型","向量存储","工具","界面","适配器","自动化","其他"];for(const c of t){const o=c.name,N=c.core?"系统":/^(@aalis\/)?plugin-(openai|deepseek|ollama)$/.test(o)?"LLM 模型":/^(@aalis\/)?plugin-agent/.test(o)||/^(@aalis\/)?plugin-persona$/.test(o)?"智能体":/^(@aalis\/)?plugin-memory-/.test(o)?"存储":/^(@aalis\/)?plugin-embedding-/.test(o)?"嵌入模型":/^(@aalis\/)?plugin-vectorstore-/.test(o)?"向量存储":/^(@aalis\/)?plugin-(tool-|tools-|websearch-)/.test(o)?"工具":/^(@aalis\/)?plugin-(webui-|cli)/.test(o)?"界面":/^(@aalis\/)?plugin-adapter-/.test(o)?"适配器":/^(@aalis\/)?plugin-(scheduler|skills)$/.test(o)?"自动化":/^(@aalis\/)?plugin-(commands|authority)$/.test(o)?"系统":"其他";i[c.instanceId]=N}const x=new Map;for(const c of l)x.set(c,[]);for(const c of t){const o=i[c.instanceId]||"其他";x.get(o).push(c)}const Fe=c=>{Ce(o=>{const N=new Set(o);return N.has(c)?N.delete(c):N.add(c),N})};return Array.from(x.entries()).filter(([,c])=>c.length>0).map(([c,o])=>{const N=ke.has(c);return e.jsxs("div",{className:"plugin-category",children:[e.jsxs("div",{className:"plugin-category-header",onClick:()=>Fe(c),children:[e.jsx("span",{className:`config-block-toggle ${N?"":"open"}`,children:"▶"}),e.jsx("span",{className:"plugin-category-name",children:c}),e.jsx("span",{className:"plugin-category-count",children:o.length})]}),!N&&o.map(n=>{var he,ge,fe,ue,xe,pe,be;const g=n.instanceId,_e=z===g,T=ve.has(g),L=Pe(n),de=L?g.slice(n.name.length+1):void 0,me=n.extends&&(((he=n.extends.events)==null?void 0:he.length)||((ge=n.extends.hooks)==null?void 0:ge.length)||n.extends.mixins&&Object.keys(n.extends.mixins).length),G=me||n.config&&Object.keys(n.config).length>0||!!n.configSchema,J=!!n.configSchema;return e.jsxs("div",{className:`plugin-card ${n.state==="disabled"?"disabled":""} ${n.state==="error"?"errored":""}`,style:{position:"relative"},children:[C(g)&&e.jsxs("div",{className:"plugin-reload-overlay",children:[e.jsx(Ze,{size:20,className:"plugin-reload-spinner"}),e.jsx("span",{children:"重载中…"})]}),e.jsxs("div",{className:"plugin-card-header",children:[e.jsxs("div",{className:"plugin-card-info",style:{cursor:G?"pointer":"default"},onClick:()=>G&&ze(g),children:[G&&e.jsx("span",{className:`config-block-toggle ${T?"open":""}`,children:"▶"}),e.jsxs("span",{className:"plugin-card-name",children:[n.displayName??n.name,n.displayName&&e.jsx("span",{className:"plugin-card-module-name",children:n.name}),de&&e.jsxs("span",{className:"plugin-instance-suffix",children:[":",de]})]}),e.jsx("span",{className:`badge ${Ee[n.state]??"pending"}`,children:Te[n.state]??n.state}),n.core&&e.jsx("span",{className:"badge core-badge",children:"核心"}),n.reusable&&!L&&e.jsx("span",{className:"badge",style:{background:"#7c5cfc",color:"#fff",fontSize:10},children:"多实例"}),n.provides.length>0&&e.jsx("span",{className:"plugin-provides-inline",children:n.provides.map(a=>e.jsx("span",{className:"provides-chip",children:a},a))})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[L&&e.jsx("button",{className:"btn btn-sm",style:{color:"#e55",fontSize:11},onClick:()=>Le(g),disabled:C(g),children:"删除"}),!L&&!n.core&&!Ie(n.name)&&e.jsx("button",{className:"btn btn-sm",style:{color:"#e55",fontSize:11},onClick:()=>Me(n),disabled:C(g),title:"卸载插件(删包 + 清配置)",children:"卸载"}),n.reusable&&!L&&e.jsx("button",{className:"btn btn-sm",style:{fontSize:11},onClick:()=>{B(se===n.name?null:n.name),A("")},children:"+ 实例"}),e.jsxs("label",{className:`toggle-switch ${n.core?"core-locked":""}`,children:[e.jsx("input",{type:"checkbox",checked:n.state!=="disabled",onChange:()=>we(n),disabled:n.core||C(g)}),e.jsx("span",{className:"toggle-slider"})]})]})]}),se===n.name&&!L&&e.jsxs("div",{className:"plugin-new-instance-row",style:{display:"flex",gap:6,padding:"6px 12px",alignItems:"center"},children:[e.jsxs("span",{style:{fontSize:12,opacity:.7},children:[n.name,":"]}),e.jsx("input",{style:{flex:1,fontSize:12},className:"plugin-search-input",placeholder:"输入实例后缀(如 vision)",value:U,onChange:a=>A(a.target.value),onKeyDown:a=>a.key==="Enter"&&ce(n.name)}),e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>ce(n.name),disabled:!U.trim()||C(n.name),children:"创建"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>B(null),children:"取消"})]}),n.state==="error"&&n.error&&e.jsxs("div",{className:"plugin-error-msg",children:[e.jsx(Ae,{size:14})," ",n.error]}),T&&n.provides.length>0&&e.jsx("div",{className:"plugin-card-provides",children:n.provides.map(a=>e.jsx("span",{className:"tool-chip",children:a},a))}),T&&((((fe=n.requiredServices)==null?void 0:fe.length)??0)>0||(((ue=n.optionalServices)==null?void 0:ue.length)??0)>0||(((xe=n.capabilities)==null?void 0:xe.length)??0)>0)&&e.jsxs("div",{className:"plugin-card-caps",children:[(n.requiredServices??[]).map(a=>e.jsxs("span",{className:"cap-chip dep-required",title:"必需依赖的服务",children:["需 ",a]},`req-${a}`)),(n.optionalServices??[]).map(a=>e.jsxs("span",{className:"cap-chip dep-optional",title:"可选依赖的服务",children:["可选 ",a]},`opt-${a}`)),(n.capabilities??[]).map(a=>e.jsx("span",{className:`cap-chip ${a==="safety:dangerous"?"cap-danger":"cap-sensitive"}`,title:"触达的敏感能力",children:a==="safety:dangerous"?"⚠ 高危操作":a},`cap-${a}`))]}),T&&me&&e.jsxs("div",{className:"plugin-card-extends",children:[e.jsx("span",{className:"extends-label",children:"扩展 Core:"}),(pe=n.extends.events)==null?void 0:pe.map(a=>e.jsxs("span",{className:"extends-chip event",children:[e.jsx(We,{size:12})," ",a]},`e-${a}`)),(be=n.extends.hooks)==null?void 0:be.map(a=>e.jsxs("span",{className:"extends-chip hook",children:[e.jsx(Xe,{size:12})," ",a]},`h-${a}`)),n.extends.mixins&&Object.entries(n.extends.mixins).map(([a,E])=>E.map(m=>e.jsxs("span",{className:"extends-chip mixin",children:[e.jsx(Je,{size:12})," ctx.",m,"()"]},`m-${a}-${m}`)))]}),T&&(n.config&&Object.keys(n.config).length>0||J)&&e.jsx("div",{className:"plugin-card-config",children:_e?J?e.jsxs(e.Fragment,{children:[e.jsx(ye,{schema:n.configSchema,draft:k,onChange:M,modelCache:D,onFetchModels:ne,llmProviders:F,onFetchLLMProviders:ae}),e.jsxs("div",{className:"config-edit-actions",children:[e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>ie(g,!0),disabled:C(g),children:"保存"}),n.defaultConfig&&Object.keys(n.defaultConfig).length>0&&e.jsx("button",{className:"btn btn-warn btn-sm",onClick:()=>te(n),children:"恢复默认"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>h(null),children:"取消"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"config-edit-form",children:Object.keys(b).map(a=>e.jsxs("div",{className:"config-edit-row",children:[e.jsx("label",{className:"config-edit-label",children:a}),e.jsx("input",{className:"config-edit-input",type:/(apiKey|password|secret|token)(?![a-zA-Z])/i.test(a)?"password":"text",value:b[a],onChange:E=>w(m=>({...m,[a]:E.target.value}))})]},a))}),e.jsxs("div",{className:"config-edit-actions",children:[e.jsx("button",{className:"btn btn-primary btn-sm",onClick:()=>ie(g,!1),disabled:C(g),children:"保存"}),n.defaultConfig&&Object.keys(n.defaultConfig).length>0&&e.jsx("button",{className:"btn btn-warn btn-sm",onClick:()=>te(n),children:"恢复默认"}),e.jsx("button",{className:"btn btn-sm",onClick:()=>h(null),children:"取消"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"config-block-body",style:{paddingTop:6},children:(J?Object.keys(n.configSchema).map(a=>[a,n.config[a]]):Object.entries(n.config)).map(([a,E])=>{var je;const m=(je=n.configSchema)==null?void 0:je[a],qe=m&&"secret"in m?m.secret:void 0,Be=m&&"description"in m?m.description:m&&"label"in m?m.label:void 0,Ue=m&&"default"in m?m.default:void 0;return e.jsx(Z,{label:a,value:E,secret:qe,description:Be,defaultValue:Ue},a)})}),e.jsx("button",{className:"btn btn-sm",onClick:()=>$e(n),children:"编辑配置"})]})})]},g)})]},c)})})()]})}export{ts as PluginConfigPage};
@@ -1 +0,0 @@
1
- import{ai as o,aj as n}from"./mermaid.core-CdhXQnZd.js";const t=(a,r)=>o.lang.round(n.parse(a)[r]);export{t as c};
@@ -1 +0,0 @@
1
- import{s as a,c as s,a as t,C as e}from"./chunk-727SXJPM-DW7QtRdS.js";import{_ as i}from"./mermaid.core-CdhXQnZd.js";import"./chunk-FMBD7UC4-DdCUM4gd.js";import"./chunk-ND2GUHAM-mCIgZWkP.js";import"./chunk-55IACEB6-CC6IKjNG.js";import"./chunk-2J33WTMH-BRSV8jER.js";import"./index-CAL5qre3.js";import"./react-vendor-BPQixOLZ.js";import"./highlight-DJvvuuwd.js";import"./katex-Bq6vt64r.js";import"./markdown-BCywGHw2.js";var g={parser:t,get db(){return new e},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{g as diagram};
@@ -1 +0,0 @@
1
- import{s as a,c as s,a as t,C as e}from"./chunk-727SXJPM-DW7QtRdS.js";import{_ as i}from"./mermaid.core-CdhXQnZd.js";import"./chunk-FMBD7UC4-DdCUM4gd.js";import"./chunk-ND2GUHAM-mCIgZWkP.js";import"./chunk-55IACEB6-CC6IKjNG.js";import"./chunk-2J33WTMH-BRSV8jER.js";import"./index-CAL5qre3.js";import"./react-vendor-BPQixOLZ.js";import"./highlight-DJvvuuwd.js";import"./katex-Bq6vt64r.js";import"./markdown-BCywGHw2.js";var g={parser:t,get db(){return new e},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{g as diagram};
@@ -1,207 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/mermaid.core-CdhXQnZd.js","assets/react-vendor-BPQixOLZ.js","assets/PluginConfigPage-C40cz0di.js","assets/SchemaForm-YVQZ6Keg.js","assets/highlight-DJvvuuwd.js","assets/highlight-BPWJwfct.css","assets/katex-Bq6vt64r.js","assets/katex-CIHdCL6t.css","assets/markdown-BCywGHw2.js","assets/MarketplacePage-pv_YtVO7.js","assets/clock-C78cKfEH.js","assets/PlatformPage-69hFZKZQ.js","assets/globe-Kcd-3YqI.js","assets/AuthorityPage-BM4HipXP.js","assets/LogPage-C_Z3RA5T.js","assets/SessionsPage-UesoGK-U.js","assets/FilesPage-BDkXMn2Z.js","assets/DynamicPage-CNJTcLnN.js","assets/cytoscape.esm-LDYqcvCF.js","assets/cytoscape-fcose-DXAQNCkb.js"])))=>i.map(i=>d[i]);
2
- import{j as e,r as a,c as qs}from"./react-vendor-BPQixOLZ.js";import"./highlight-DJvvuuwd.js";import"./katex-Bq6vt64r.js";import{r as Bs,b as Hs,a as Vs,c as Js,M as _e}from"./markdown-BCywGHw2.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const d of i)if(d.type==="childList")for(const u of d.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&r(u)}).observe(document,{childList:!0,subtree:!0});function n(i){const d={};return i.integrity&&(d.integrity=i.integrity),i.referrerPolicy&&(d.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?d.credentials="include":i.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function r(i){if(i.ep)return;i.ep=!0;const d=n(i);fetch(i.href,d)}})();const Gs="modulepreload",Ks=function(t){return"/"+t},as={},he=function(s,n,r){let i=Promise.resolve();if(n&&n.length>0){let u=function(l){return Promise.all(l.map(g=>Promise.resolve(g).then(j=>({status:"fulfilled",value:j}),j=>({status:"rejected",reason:j}))))};document.getElementsByTagName("link");const f=document.querySelector("meta[property=csp-nonce]"),x=(f==null?void 0:f.nonce)||(f==null?void 0:f.getAttribute("nonce"));i=u(n.map(l=>{if(l=Ks(l),l in as)return;as[l]=!0;const g=l.endsWith(".css"),j=g?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${l}"]${j}`))return;const v=document.createElement("link");if(v.rel=g?"stylesheet":Gs,g||(v.as="script"),v.crossOrigin="",v.href=l,x&&v.setAttribute("nonce",x),document.head.appendChild(v),g)return new Promise((w,c)=>{v.addEventListener("load",w),v.addEventListener("error",()=>c(new Error(`Unable to preload CSS for ${l}`)))})}))}function d(u){const f=new Event("vite:preloadError",{cancelable:!0});if(f.payload=u,window.dispatchEvent(f),!f.defaultPrevented)throw u}return i.then(u=>{for(const f of u||[])f.status==="rejected"&&d(f.reason);return s().catch(d)})},ms="aalis:activeSessionId";function Us(){try{return window.localStorage.getItem(ms)||"__new_chat__"}catch{return"__new_chat__"}}let Ye=Us();const Xe=new Set;function oe(){return Ye}function He(t){if(Ye!==t){Ye=t;try{window.localStorage.setItem(ms,t)}catch{}for(const s of Xe)s(t)}}function Ys(t){return Xe.add(t),()=>Xe.delete(t)}async function Q(t,s){return(await fetch(t,{headers:{"Content-Type":"application/json"},...s})).json()}async function de(t,s,n={}){const r=await fetch(`/api/page-action/${encodeURIComponent(t)}/${encodeURIComponent(s)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),i=await r.json();if(!r.ok)throw new Error(i.error||"请求失败");return i.data}function je(t){return t?t.startsWith("http://")||t.startsWith("https://")?`/api/proxy/image?url=${encodeURIComponent(t)}`:t:""}function Xs(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]})}function Zs(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"9",cy:"21",r:"1"}),e.jsx("circle",{cx:"20",cy:"21",r:"1"}),e.jsx("path",{d:"M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"})]})}function Qs(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function et(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14,2 14,8 20,8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"}),e.jsx("line",{x1:"10",y1:"9",x2:"8",y2:"9"})]})}function st(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function tt(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}function nt(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function at(t){const s=a.useRef(t);s.current=t;const n=a.useRef(null),[r,i]=a.useState(!1),d=a.useRef(oe());a.useEffect(()=>{let x,l,g=!1;function j(){if(g)return;const v=location.protocol==="https:"?"wss:":"ws:";x=new WebSocket(`${v}//${location.host}/ws`),n.current=x,x.onopen=()=>{g||(i(!0),x.send(JSON.stringify({type:"subscribe_logs"})),x.send(JSON.stringify({type:"subscribe_session",sessionId:oe()})),d.current=oe())},x.onclose=()=>{g||(i(!1),l=setTimeout(j,3e3))},x.onmessage=w=>{var c,L,I,C,S,G,P,Z,q,U,Y,k,m;try{const h=JSON.parse(w.data),p=s.current;h.type==="stream"?(p.onStream(h.contentDelta,h.reasoningDelta,h.done,h.toolLimitReached),h.toolCallProgress&&((c=p.onToolCallProgress)==null||c.call(p,h.toolCallProgress)),h.done&&((L=p.onToolCallProgressClear)==null||L.call(p))):h.type==="message"&&(h.content||(I=h.attachments)!=null&&I.length)?p.onMessage(h.content??"",h.reasoningContent,h.segments,h.attachments,h.modelInfo):h.type==="tool_call"&&h.toolName?p.onToolCall(h.toolName,h.toolArgs??{},h.toolPhase,h.toolResult):h.type==="log"&&h.log?p.onLog(h.log):h.type==="state_changed"?(C=p.onStateChanged)==null||C.call(p):h.type==="restarting"?(S=p.onRestarting)==null||S.call(p):h.type==="reload"?(G=p.onReload)==null||G.call(p):h.type==="sessions_changed"?(P=p.onSessionsChanged)==null||P.call(p):h.type==="todo_updated"&&h.todoItems?(Z=p.onTodoUpdated)==null||Z.call(p,h.todoItems):h.type==="stream_resume"?(q=p.onStreamResume)==null||q.call(p,h.content??"",h.reasoningContent??"",h.segments??[],!!h.done,h.toolCallsProgress):h.type==="confirm"&&h.content?(U=p.onConfirm)==null||U.call(p,h.content):h.type==="token_usage"&&h.tokenUsage?(Y=p.onTokenUsage)==null||Y.call(p,h.tokenUsage):h.type==="compressing"&&h.sessionId?(k=p.onCompressing)==null||k.call(p,h.sessionId,h.content??"start"):h.type==="history_changed"&&h.sessionId?(m=p.onHistoryChanged)==null||m.call(p,h.sessionId):h.type==="page_refresh"&&window.dispatchEvent(new CustomEvent("aalis:page-refresh",{detail:{pluginName:h.pluginName}}))}catch{}}}return j(),()=>{g=!0,clearTimeout(l),x==null||x.close()}},[]),a.useEffect(()=>Ys(l=>{const g=n.current;(g==null?void 0:g.readyState)===WebSocket.OPEN&&(g.send(JSON.stringify({type:"unsubscribe_session",sessionId:d.current})),g.send(JSON.stringify({type:"subscribe_session",sessionId:l})),d.current=l)}),[]);const u=a.useCallback((x,l)=>{var g;if(((g=n.current)==null?void 0:g.readyState)===WebSocket.OPEN){const j={type:"message",content:x,sessionId:oe()};l&&l.length>0&&(j.attachments=l),n.current.send(JSON.stringify(j))}},[]),f=a.useCallback(x=>{var l;((l=n.current)==null?void 0:l.readyState)===WebSocket.OPEN&&n.current.send(JSON.stringify(x))},[]);return{send:u,sendRaw:f,connected:r}}function rt(){const t=new Date,s=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),r=String(t.getHours()).padStart(2,"0"),i=String(t.getMinutes()).padStart(2,"0");return`会话 ${s}-${n} ${r}:${i}`}function ot(t){const s=[];let n=t.replace(/\n?\[文件: ([^\n(]+?)\s*\(ID:[^)]+\)\]\n--- 文件内容 ---[\s\S]*?--- 文件内容结束 ---/g,(r,i)=>(s.push(i.trim()),""));return n=n.replace(/\n?\[文件: ([^\n(]+?)\s*\(ID:[^,\n)]+[,\n][\s\S]*?\)\]/g,(r,i)=>(s.push(i.trim()),"")),n=n.replace(/\n?\[文件: ([^\]-]+?) - [^\]]+\]/g,(r,i)=>(s.push(i.trim()),"")),n=n.replace(/\n?\[文件: ([^\]]+?)\s*(?:\(ID:[^)]+\))?\]/g,(r,i)=>(s.push(i.trim()),"")),{displayContent:n.trim(),fileNames:s}}function it(t){var r,i,d,u;const s=[];let n=0;for(;n<t.length;){const f=t[n];if(f.role==="user"){const x=f.content??"",l=Array.isArray((r=f.metadata)==null?void 0:r.fileNames)?f.metadata.fileNames:null,{displayContent:g,fileNames:j}=ot(x),v=(l??j).filter(Boolean);s.push({role:"user",content:g,fileNames:v.length>0?v:void 0,timestamp:f.timestamp??0}),n++;continue}if(f.role==="system"){f.kind==="event-marker"&&s.push({role:"system",content:f.content??"",timestamp:f.timestamp??0}),n++;continue}if(f.role==="notice"){s.push({role:"system",content:f.content??"",timestamp:f.timestamp??0}),n++;continue}if(f.role==="assistant"){const x=[],l=[];let g=f.timestamp??0,j="",v=!1,w;for(;n<t.length&&(t[n].role==="assistant"||t[n].role==="tool");){const C=t[n];if(C.role==="assistant"){const S=(i=C.metadata)==null?void 0:i.modelInfo;S&&(w=S)}if(C.role==="assistant"&&C.segments&&C.segments.length>0){v=!0,x.length=0,l.length=0;for(const S of C.segments)x.push(S);g=C.timestamp??g,n++;continue}if(C.role==="assistant"&&C.toolCalls&&C.toolCalls.length>0){C.reasoningContent&&l.push({type:"reasoning_text",content:C.reasoningContent}),C.content&&x.push({type:"text",content:C.content});for(const S of C.toolCalls){let G={};try{G=JSON.parse(S.function.arguments)}catch{}x.push({type:"tool_call",name:S.function.name,args:G})}g=C.timestamp??g,n++}else if(C.role==="tool"&&C.toolCallId){for(let S=x.length-1;S>=0;S--){const G=x[S];if(G.type==="tool_call"&&G.result===void 0){G.result=C.content??"";break}}n++}else if(C.role==="assistant"){if(n===t.length-1||((d=t[n+1])==null?void 0:d.role)==="user"||((u=t[n+1])==null?void 0:u.role)==="system"){C.reasoningContent&&l.push({type:"reasoning_text",content:C.reasoningContent}),j=C.content??"",g=C.timestamp??g,n++;break}C.reasoningContent&&l.push({type:"reasoning_text",content:C.reasoningContent}),C.content&&x.push({type:"text",content:C.content}),g=C.timestamp??g,n++}else break}let c;v?c=x:(c=[...l,...x],j&&c.push({type:"text",content:j}));let L="",I="";for(const C of c)C.type==="reasoning_text"?L+=C.content:C.type==="text"&&(I+=C.content);s.push({role:"assistant",content:I||j||f.content||"",segments:c.length>0?c:void 0,reasoningContent:L||void 0,timestamp:g,modelInfo:w});continue}n++}return s}function lt(t){const[s,n]=a.useState([]),[r,i]=a.useState(oe()),[d,u]=a.useState([]),[f,x]=a.useState(!1),l=a.useRef(!1),g=a.useRef(new Map),j=a.useMemo(()=>{const k=t.find(m=>m.key==="sessions");return(k==null?void 0:k.plugin)??null},[t]),v=a.useRef(j);v.current=j;const w=a.useRef(r);w.current=r;const c=a.useRef(d);c.current=d;const L=a.useRef(s);L.current=s;const I=a.useMemo(()=>j?s.length===0||!s.some(k=>k.id===r):!1,[j,s,r]),C=a.useMemo(()=>{const k=s.find(m=>m.id===r);return(k==null?void 0:k.title)||(k==null?void 0:k.displayTitle)||(k==null?void 0:k.name)||""},[s,r]),S=a.useCallback(()=>{const k=v.current;k&&de(k,"listSessions").then(m=>{Array.isArray(m)&&n(m)}).catch(()=>{})},[]),G=a.useCallback(()=>{c.current.length>0&&g.current.set(w.current,c.current);const k="__new_chat__";i(k),He(k),u([]),x(!1),l.current=!1},[]),P=a.useCallback(async k=>{const m=v.current;if(!m)return null;const h=rt();try{const p=await de(m,"createSession",{name:h,...k?{parentId:k}:{}});if(!(p!=null&&p.id))return null;const W=p.id;return n(V=>{if(V.some(_=>_.id===W))return V;const ae={id:W,name:p.name||h,title:p.title,displayTitle:p.title||p.name||h,status:"active",children:[],childCount:0,parentId:k,createdAt:Date.now()};return[...V,ae]}),k&&n(V=>V.map(ae=>ae.id===k?{...ae,children:[...ae.children,W],childCount:ae.childCount+1}:ae)),c.current.length>0&&g.current.set(w.current,c.current),i(W),He(W),u([]),x(!1),l.current=!1,de(m,"listSessions").then(V=>{Array.isArray(V)&&n(V)}).catch(()=>{}),W}catch{return null}},[]),Z=a.useCallback(async()=>!v.current||L.current.some(h=>h.id===w.current)?w.current:await P()||w.current,[P]),q=a.useCallback((k,m)=>{de(m,"getSessionDetail",{id:k}).then(h=>{if(h!=null&&h.messages&&w.current===k){const p=it(h.messages);if(l.current){for(;p.length>0&&p[p.length-1].role==="assistant";)p.pop();const W=c.current,V=W[W.length-1];V&&V.role==="assistant"&&p.push(V)}u(p),g.current.set(k,p)}}).catch(()=>{})},[]),U=a.useCallback(k=>{const m=k===w.current;if(m&&c.current.length>0)return;!m&&c.current.length>0&&g.current.set(w.current,c.current),i(k),He(k),x(!1),l.current=!1;const h=v.current,p=g.current.get(k);u(p??[]),!p&&h&&q(k,h),S()},[q,S]),Y=a.useCallback(k=>{if(k!==w.current)return;const m=v.current;m&&(g.current.delete(k),q(k,m))},[q]);return a.useEffect(()=>{j&&de(j,"listSessions").then(k=>{if(!Array.isArray(k))return;n(k);const m=oe();m&&m!=="__new_chat__"&&k.some(h=>h.id===m)&&(i(m),q(m,j))}).catch(()=>{})},[j,q]),{pluginName:j,sessionList:s,activeSessionId:r,activeSessionTitle:C,isNewChat:I,messages:d,setMessages:u,refresh:S,startNewChat:G,createSession:P,ensureSession:Z,switchSession:U,handleHistoryChanged:Y,loading:f,setLoading:x,streamingRef:l}}/**
3
- * @license lucide-react v1.7.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const fs=(...t)=>t.filter((s,n,r)=>!!s&&s.trim()!==""&&r.indexOf(s)===n).join(" ").trim();/**
8
- * @license lucide-react v1.7.0 - ISC
9
- *
10
- * This source code is licensed under the ISC license.
11
- * See the LICENSE file in the root directory of this source tree.
12
- */const ct=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();/**
13
- * @license lucide-react v1.7.0 - ISC
14
- *
15
- * This source code is licensed under the ISC license.
16
- * See the LICENSE file in the root directory of this source tree.
17
- */const dt=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(s,n,r)=>r?r.toUpperCase():n.toLowerCase());/**
18
- * @license lucide-react v1.7.0 - ISC
19
- *
20
- * This source code is licensed under the ISC license.
21
- * See the LICENSE file in the root directory of this source tree.
22
- */const rs=t=>{const s=dt(t);return s.charAt(0).toUpperCase()+s.slice(1)};/**
23
- * @license lucide-react v1.7.0 - ISC
24
- *
25
- * This source code is licensed under the ISC license.
26
- * See the LICENSE file in the root directory of this source tree.
27
- */var Ve={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
28
- * @license lucide-react v1.7.0 - ISC
29
- *
30
- * This source code is licensed under the ISC license.
31
- * See the LICENSE file in the root directory of this source tree.
32
- */const ut=t=>{for(const s in t)if(s.startsWith("aria-")||s==="role"||s==="title")return!0;return!1},ht=a.createContext({}),mt=()=>a.useContext(ht),ft=a.forwardRef(({color:t,size:s,strokeWidth:n,absoluteStrokeWidth:r,className:i="",children:d,iconNode:u,...f},x)=>{const{size:l=24,strokeWidth:g=2,absoluteStrokeWidth:j=!1,color:v="currentColor",className:w=""}=mt()??{},c=r??j?Number(n??g)*24/Number(s??l):n??g;return a.createElement("svg",{ref:x,...Ve,width:s??l??Ve.width,height:s??l??Ve.height,stroke:t??v,strokeWidth:c,className:fs("lucide",w,i),...!d&&!ut(f)&&{"aria-hidden":"true"},...f},[...u.map(([L,I])=>a.createElement(L,I)),...Array.isArray(d)?d:[d]])});/**
33
- * @license lucide-react v1.7.0 - ISC
34
- *
35
- * This source code is licensed under the ISC license.
36
- * See the LICENSE file in the root directory of this source tree.
37
- */const H=(t,s)=>{const n=a.forwardRef(({className:r,...i},d)=>a.createElement(ft,{ref:d,iconNode:s,className:fs(`lucide-${ct(rs(t))}`,`lucide-${t}`,r),...i}));return n.displayName=rs(t),n};/**
38
- * @license lucide-react v1.7.0 - ISC
39
- *
40
- * This source code is licensed under the ISC license.
41
- * See the LICENSE file in the root directory of this source tree.
42
- */const pt=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],ps=H("archive",pt);/**
43
- * @license lucide-react v1.7.0 - ISC
44
- *
45
- * This source code is licensed under the ISC license.
46
- * See the LICENSE file in the root directory of this source tree.
47
- */const xt=[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]],gt=H("bot",xt);/**
48
- * @license lucide-react v1.7.0 - ISC
49
- *
50
- * This source code is licensed under the ISC license.
51
- * See the LICENSE file in the root directory of this source tree.
52
- */const jt=[["path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z",key:"l5xja"}],["path",{d:"M9 13a4.5 4.5 0 0 0 3-4",key:"10igwf"}],["path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5",key:"105sqy"}],["path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396",key:"ql3yin"}],["path",{d:"M6 18a4 4 0 0 1-1.967-.516",key:"2e4loj"}],["path",{d:"M12 13h4",key:"1ku699"}],["path",{d:"M12 18h6a2 2 0 0 1 2 2v1",key:"105ag5"}],["path",{d:"M12 8h8",key:"1lhi5i"}],["path",{d:"M16 8V5a2 2 0 0 1 2-2",key:"u6izg6"}],["circle",{cx:"16",cy:"13",r:".5",key:"ry7gng"}],["circle",{cx:"18",cy:"3",r:".5",key:"1aiba7"}],["circle",{cx:"20",cy:"21",r:".5",key:"yhc1fs"}],["circle",{cx:"20",cy:"8",r:".5",key:"1e43v0"}]],os=H("brain-circuit",jt);/**
53
- * @license lucide-react v1.7.0 - ISC
54
- *
55
- * This source code is licensed under the ISC license.
56
- * See the LICENSE file in the root directory of this source tree.
57
- */const vt=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],xs=H("chevron-down",vt);/**
58
- * @license lucide-react v1.7.0 - ISC
59
- *
60
- * This source code is licensed under the ISC license.
61
- * See the LICENSE file in the root directory of this source tree.
62
- */const yt=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],gs=H("chevron-right",yt);/**
63
- * @license lucide-react v1.7.0 - ISC
64
- *
65
- * This source code is licensed under the ISC license.
66
- * See the LICENSE file in the root directory of this source tree.
67
- */const Nt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],js=H("circle-check",Nt);/**
68
- * @license lucide-react v1.7.0 - ISC
69
- *
70
- * This source code is licensed under the ISC license.
71
- * See the LICENSE file in the root directory of this source tree.
72
- */const wt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],kt=H("circle",wt);/**
73
- * @license lucide-react v1.7.0 - ISC
74
- *
75
- * This source code is licensed under the ISC license.
76
- * See the LICENSE file in the root directory of this source tree.
77
- */const bt=[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]],Ct=H("command",bt);/**
78
- * @license lucide-react v1.7.0 - ISC
79
- *
80
- * This source code is licensed under the ISC license.
81
- * See the LICENSE file in the root directory of this source tree.
82
- */const St=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],_t=H("download",St);/**
83
- * @license lucide-react v1.7.0 - ISC
84
- *
85
- * This source code is licensed under the ISC license.
86
- * See the LICENSE file in the root directory of this source tree.
87
- */const $t=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Ze=H("file-text",$t);/**
88
- * @license lucide-react v1.7.0 - ISC
89
- *
90
- * This source code is licensed under the ISC license.
91
- * See the LICENSE file in the root directory of this source tree.
92
- */const Tt=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]],It=H("file",Tt);/**
93
- * @license lucide-react v1.7.0 - ISC
94
- *
95
- * This source code is licensed under the ISC license.
96
- * See the LICENSE file in the root directory of this source tree.
97
- */const Mt=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],Et=H("folder-open",Mt);/**
98
- * @license lucide-react v1.7.0 - ISC
99
- *
100
- * This source code is licensed under the ISC license.
101
- * See the LICENSE file in the root directory of this source tree.
102
- */const Lt=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]],Je=H("history",Lt);/**
103
- * @license lucide-react v1.7.0 - ISC
104
- *
105
- * This source code is licensed under the ISC license.
106
- * See the LICENSE file in the root directory of this source tree.
107
- */const Rt=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],Dt=H("list-todo",Rt);/**
108
- * @license lucide-react v1.7.0 - ISC
109
- *
110
- * This source code is licensed under the ISC license.
111
- * See the LICENSE file in the root directory of this source tree.
112
- */const Pt=[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]],Qe=H("loader",Pt);/**
113
- * @license lucide-react v1.7.0 - ISC
114
- *
115
- * This source code is licensed under the ISC license.
116
- * See the LICENSE file in the root directory of this source tree.
117
- */const At=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],is=H("message-square",At);/**
118
- * @license lucide-react v1.7.0 - ISC
119
- *
120
- * This source code is licensed under the ISC license.
121
- * See the LICENSE file in the root directory of this source tree.
122
- */const zt=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],vs=H("paperclip",zt);/**
123
- * @license lucide-react v1.7.0 - ISC
124
- *
125
- * This source code is licensed under the ISC license.
126
- * See the LICENSE file in the root directory of this source tree.
127
- */const Ot=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],Ft=H("refresh-cw",Ot);/**
128
- * @license lucide-react v1.7.0 - ISC
129
- *
130
- * This source code is licensed under the ISC license.
131
- * See the LICENSE file in the root directory of this source tree.
132
- */const Wt=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],qt=H("sparkles",Wt);/**
133
- * @license lucide-react v1.7.0 - ISC
134
- *
135
- * This source code is licensed under the ISC license.
136
- * See the LICENSE file in the root directory of this source tree.
137
- */const Bt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Ht=H("square",Bt);/**
138
- * @license lucide-react v1.7.0 - ISC
139
- *
140
- * This source code is licensed under the ISC license.
141
- * See the LICENSE file in the root directory of this source tree.
142
- */const Vt=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Jt=H("trash-2",Vt);/**
143
- * @license lucide-react v1.7.0 - ISC
144
- *
145
- * This source code is licensed under the ISC license.
146
- * See the LICENSE file in the root directory of this source tree.
147
- */const Gt=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],De=H("triangle-alert",Gt);/**
148
- * @license lucide-react v1.7.0 - ISC
149
- *
150
- * This source code is licensed under the ISC license.
151
- * See the LICENSE file in the root directory of this source tree.
152
- */const Kt=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],ss=H("wrench",Kt);/**
153
- * @license lucide-react v1.7.0 - ISC
154
- *
155
- * This source code is licensed under the ISC license.
156
- * See the LICENSE file in the root directory of this source tree.
157
- */const Ut=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],ys=H("x",Ut);/**
158
- * @license lucide-react v1.7.0 - ISC
159
- *
160
- * This source code is licensed under the ISC license.
161
- * See the LICENSE file in the root directory of this source tree.
162
- */const Yt=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],Ns=H("zap",Yt);function Ge({name:t,info:s,onPreferChanged:n}){var v;const[r,i]=a.useState(!1),d=s.providers,u=d.length>0,f=d.length>1,x=s.preferred??((v=d[0])==null?void 0:v.contextId)??"",l=d.find(w=>w.contextId===x),g=async w=>{if(!r){i(!0);try{await Q(`/api/services/${encodeURIComponent(t)}/prefer`,{method:"POST",body:JSON.stringify({contextId:w})}),n==null||n()}finally{i(!1)}}},j=async()=>{if(!r){i(!0);try{await Q(`/api/services/${encodeURIComponent(t)}/prefer`,{method:"DELETE"}),n==null||n()}finally{i(!1)}}};return e.jsxs("div",{className:"service-slot-card",children:[e.jsxs("div",{className:"service-slot-header",children:[e.jsx("span",{className:"service-slot-name",children:t}),e.jsxs("div",{className:"service-slot-header-badges",children:[s.preferred&&e.jsx("span",{className:"service-winner-badge preferred",children:"偏好"}),e.jsx("span",{className:`badge ${u?"active":"error"}`,children:u?f?`${d.length} 个提供者`:"就绪":"未就绪"})]})]}),u?f?e.jsxs("div",{className:"service-slot-select-row",children:[e.jsx("span",{className:"service-slot-label",children:"活跃提供者"}),e.jsx("select",{className:"service-select",value:x,disabled:r,onChange:w=>g(w.target.value),children:d.map(w=>{const c=w.displayName||w.label||w.contextId,L=c!==w.contextId?`${c} · p${w.priority} (${w.contextId})`:`${w.contextId} · p${w.priority}`;return e.jsx("option",{value:w.contextId,children:L},w.contextId)})}),s.preferred&&e.jsx("button",{type:"button",className:"service-clear-prefer",onClick:j,disabled:r,title:"清除偏好,恢复 priority 默认顺序",children:"恢复默认"})]}):e.jsxs("div",{className:"service-slot-single",children:[e.jsx("span",{className:"service-slot-label",children:"提供者"}),e.jsxs("span",{className:"service-slot-provider-name",children:[(l==null?void 0:l.displayName)||(l==null?void 0:l.label)||(l==null?void 0:l.contextId),((l==null?void 0:l.displayName)||(l==null?void 0:l.label))&&e.jsxs("span",{className:"service-slot-context-id",children:[" ",l==null?void 0:l.contextId]})]})]}):e.jsx("div",{className:"service-slot-single",children:e.jsx("span",{className:"empty-hint",children:"无提供者"})}),l&&l.capabilities.length>0&&e.jsx("div",{className:"service-slot-caps",children:l.capabilities.map(w=>e.jsx("span",{className:"tool-chip",children:w},w))})]})}function Xt({status:t,connected:s,plugins:n,servicesData:r,onRefreshServices:i}){var k;const d=n.filter(m=>m.state==="active").length,u=n.filter(m=>m.state==="error").length,f=n.length,[x,l]=a.useState(null),[g,j]=a.useState([]),[v,w]=a.useState([]),[c,L]=a.useState([]),[I,C]=a.useState([]);a.useEffect(()=>{Q("/api/tool-groups").then(m=>j(m.groups??[])).catch(()=>{})},[n]),a.useEffect(()=>{Q("/api/service-groups").then(m=>w(m.groups??[])).catch(()=>{})},[n]),a.useEffect(()=>{Q("/api/llm-models").then(m=>L(m.models??[])).catch(()=>{})},[n]),a.useEffect(()=>{Q("/api/clients").then(m=>C(m.clients??[])).catch(()=>{})},[]);const S=m=>{l(m),setTimeout(()=>l(null),2500)},G=async m=>{try{const h=await fetch("/api/clients/active",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:m})}),p=await h.json().catch(()=>({}));if(!h.ok)throw new Error(p.error||`切换失败(HTTP ${h.status})`);S("已切换前端,正在重新加载…"),setTimeout(()=>window.location.reload(),600)}catch(h){S(h instanceof Error?h.message:"切换失败(需 owner 权限)")}},P=r?Object.entries(r):[],Z=v.map(m=>({label:m.label,entries:P.filter(([h])=>m.services.includes(h))})),q=Z.some(m=>m.entries.length>0),U=new Set(v.flatMap(m=>m.services)),Y=P.filter(([m])=>!U.has(m));return e.jsxs("div",{className:"page-content page-dashboard",children:[x&&e.jsx("div",{className:"toast",children:x}),e.jsx("div",{className:"section-label",children:"概览"}),e.jsxs("div",{className:"overview-grid",children:[e.jsxs("div",{className:"overview-card",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx("span",{className:`status-dot-lg ${s?"online":"offline"}`})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"连接状态"}),e.jsx("div",{className:"overview-card-value",children:s?"已连接":"离线"})]})]}),e.jsxs("div",{className:"overview-card",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx(qt,{size:20})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"应用名称"}),e.jsx("div",{className:"overview-card-value",children:(t==null?void 0:t.name)??"-"})]})]}),e.jsxs("div",{className:"overview-card",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx(Ns,{size:20})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"活跃插件"}),e.jsxs("div",{className:"overview-card-value",children:[d," / ",f]})]})]}),u>0&&e.jsxs("div",{className:"overview-card overview-card-error",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx(De,{size:20})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"错误插件"}),e.jsx("div",{className:"overview-card-value",children:u})]})]}),e.jsxs("div",{className:"overview-card",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx(ss,{size:20})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"已注册工具"}),e.jsx("div",{className:"overview-card-value",children:(t==null?void 0:t.tools.length)??0})]})]}),e.jsxs("div",{className:"overview-card",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx(Ct,{size:20})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"已注册指令"}),e.jsx("div",{className:"overview-card-value",children:((k=t==null?void 0:t.commands)==null?void 0:k.length)??0})]})]}),e.jsxs("div",{className:"overview-card",children:[e.jsx("div",{className:"overview-card-icon",children:e.jsx(gt,{size:20})}),e.jsxs("div",{className:"overview-card-body",children:[e.jsx("div",{className:"overview-card-label",children:"可用模型"}),e.jsx("div",{className:"overview-card-value",children:c.length})]})]})]}),I.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"section-label",children:"前端(活跃切换)"}),e.jsx("div",{className:"services-grid",children:I.map(m=>e.jsxs("div",{className:"service-slot-card",style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontWeight:600},children:m.label}),m.active?e.jsx("span",{className:"badge active",children:"活跃"}):e.jsx("button",{type:"button",className:"btn-sm",onClick:()=>G(m.id),children:"设为活跃"})]}),e.jsx("div",{style:{fontSize:11,color:"var(--text-dim, #888)"},children:m.id})]},m.id))})]}),q?e.jsxs(e.Fragment,{children:[Z.map(m=>m.entries.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"section-label",children:m.label}),e.jsx("div",{className:"services-grid",children:m.entries.map(([h,p])=>e.jsx(Ge,{name:h,info:p,onPreferChanged:i},h))})]},m.label)),Y.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"section-label",children:"其他"}),e.jsx("div",{className:"services-grid",children:Y.map(([m,h])=>e.jsx(Ge,{name:m,info:h,onPreferChanged:i},m))})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"section-label",children:"服务"}),e.jsxs("div",{className:"services-grid",children:[P.length===0&&e.jsx("div",{className:"empty-hint",children:"加载中..."}),P.map(([m,h])=>e.jsx(Ge,{name:m,info:h,onPreferChanged:i},m))]})]}),e.jsx("div",{className:"section-label",children:"工具分组"}),g.length>0?e.jsx("div",{className:"tool-groups-grid",children:g.map(m=>{const h=m.contributingPlugins??[],p=[m.pluginName,...h.filter(W=>W!==m.pluginName)];return e.jsxs("div",{className:"tool-group-card",children:[e.jsxs("div",{className:"tool-group-header",children:[e.jsx("span",{className:"tool-group-name",children:m.label}),e.jsxs("span",{className:"tool-group-count",children:[m.toolCount," 工具"]})]}),m.description&&e.jsx("div",{className:"tool-group-desc",children:m.description}),e.jsxs("div",{className:"tool-group-meta",children:[e.jsx("span",{className:"tool-group-id",children:m.name}),e.jsx("span",{className:"tool-group-plugin",title:p.join(", "),children:p.join(" · ")})]})]},m.name)})}):e.jsx("div",{className:"tools-grid",children:!t||t.tools.length===0?e.jsx("div",{className:"empty-hint",children:"无工具"}):t.tools.map(m=>e.jsx("span",{className:"tool-chip",children:m},m))}),e.jsx("div",{className:"section-label",children:"已注册指令"}),e.jsx("div",{className:"tools-grid",children:!t||!t.commands||t.commands.length===0?e.jsx("div",{className:"empty-hint",children:"无指令"}):t.commands.map(m=>e.jsxs("span",{className:"tool-chip cmd-chip",title:m.description,children:["/",m.name]},m.name))})]})}function ls(t){const n=t.trim().split("|"),r=n[0].trim()===""?1:0,i=n[n.length-1].trim()===""?n.length-1:n.length;return Math.max(0,i-r)}function Zt(t,s){const n=t.trim(),r=n.startsWith("|")?"|":"",i=n.endsWith("|")?"|":"",u=n.slice(r.length,i?n.length-1:void 0).split("|").map(f=>f.trim()).filter(f=>/^:?-+:?$/.test(f));for(;u.length<s;)u.push("---");return u.length=s,r+u.join("|")+i}function Qt(t){return/^\|?[ \t]*:?-+:?[ \t]*(\|[ \t]*:?-+:?[ \t]*)*\|?\s*$/.test(t)}function en(t){return t&&t.split(/(```[\s\S]*?```|`[^`\n]*`)/g).map((n,r)=>{if(r%2===1)return n;const i=n.split(`
163
- `),d=[];for(let u=0;u<i.length;u++){const f=i[u];if(u>0&&Qt(f)){const x=i[u-1];if(x.includes("|")&&x.trim()){const l=ls(x),g=ls(f);if(l>0&&g>0&&l!==g){d.push(Zt(f,l));continue}}}d.push(f)}return d.join(`
164
- `)}).join("")}function $e(t){return t=en(t),t.split(/(```[\s\S]*?```|`[^`]*`)/g).map((n,r)=>(r%2===1||(n=n.replace(/\\\[([\s\S]*?)\\\]/g,(d,u)=>`$$${u.replace(/\|/g,"\\vert ")}$$`),n=n.replace(/\\\((.*?)\\\)/g,(d,u)=>`$${u.replace(/\|/g,"\\vert ")}$`),n=n.replace(/\$\$([\s\S]+?)\$\$/g,(d,u)=>u.includes(`
165
- `)?`
166
-
167
- $$
168
- ${u.replace(/^[ \t]*\n?/,"").replace(/\n?[ \t]*$/,"")}
169
- $$
170
-
171
- `:d),(n.match(/\$\$/g)??[]).length%2===1&&(n=n.replace(/\$\$((?:(?!\$\$)[\s\S])+)$/,(d,u)=>{const f=u.replace(/^[ \t]*\n?/,"").replace(/\n?[ \t]*$/,"");return!f||!u.includes(`
172
- `)?`$$${u}`:`
173
-
174
- $$
175
- ${f}
176
- $$
177
-
178
- `}))),n)).join("")}function sn(t){if(!t||!Number.isFinite(t))return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const n=new Date,r=x=>x.toString().padStart(2,"0"),i=`${r(s.getHours())}:${r(s.getMinutes())}`,d=s.getFullYear()===n.getFullYear();if(d&&s.getMonth()===n.getMonth()&&s.getDate()===n.getDate())return i;const f=`${s.getMonth()+1}-${s.getDate()} ${i}`;return d?f:`${s.getFullYear()}-${f}`}let Ke=null;function tn(){return Ke||(Ke=he(()=>import("./mermaid.core-CdhXQnZd.js").then(t=>t.bm),__vite__mapDeps([0,1])).then(t=>{var r;const s=t.default,n=typeof window<"u"&&((r=window.matchMedia)==null?void 0:r.call(window,"(prefers-color-scheme: dark)").matches);return s.initialize({startOnLoad:!1,theme:n?"dark":"default",securityLevel:"loose",fontFamily:"inherit"}),s})),Ke}function cs(t){if(!(typeof document>"u"))for(const s of[`#${t}`,`#d${t}`,`#${t}-temp`])document.querySelectorAll(s).forEach(n=>n.remove())}let nn=0;function an({chart:t}){const[s,n]=a.useState(null),[r,i]=a.useState(null),d=a.useRef(`mermaid-${++nn}`);return a.useEffect(()=>{let u=!1;const f=d.current,x=t.trim();if(!x){n(null),i(null);return}return tn().then(async l=>(await l.parse(x),l.render(f,x))).then(({svg:l})=>{u||(n(l),i(null))}).catch(l=>{if(cs(f),u)return;const g=l instanceof Error?l.message:String(l);i(g),n(null)}),()=>{u=!0,cs(f)}},[t]),r?e.jsxs("div",{className:"mermaid-block mermaid-block-error",children:[e.jsxs("div",{className:"mermaid-error-banner",children:["⚠ Mermaid 渲染失败:",r]}),e.jsx("pre",{children:e.jsx("code",{className:"language-mermaid",children:t})})]}):s?e.jsx("div",{className:"mermaid-block",dangerouslySetInnerHTML:{__html:s}}):e.jsx("pre",{className:"mermaid-block mermaid-block-loading",children:e.jsx("code",{className:"language-mermaid",children:t})})}const rn=a.memo(an),Te=[Vs,Js],on={strict:"ignore",throwOnError:!1,errorColor:"inherit",output:"htmlAndMathml"},Ie=[Bs,[Hs,on]];function ln({className:t,children:s,...n}){const r=/language-(\w+)/.exec(t??"");if((r==null?void 0:r[1])==="mermaid"){const d=Array.isArray(s)?s.join(""):String(s??"");return e.jsx(rn,{chart:d.replace(/\n$/,"")})}return e.jsx("code",{className:t,...n,children:s})}const Me={code:ln};function cn(t){if(t===0)return"—";const s=["B","KB","MB","GB"];let n=0,r=t;for(;r>=1024&&n<s.length-1;)r/=1024,n++;return`${r.toFixed(n===0?0:1)} ${s[n]}`}function dn(t){return new Date(t).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function un({open:t,onClose:s,sessionId:n}){const[r,i]=a.useState([]),[d,u]=a.useState(!1),[f,x]=a.useState(null),[l,g]=a.useState(null),j=a.useCallback(async()=>{if(!n||n==="__new_chat__"){i([]);return}u(!0),x(null);try{const c=await Q(`/api/uploaded-files?sessionId=${encodeURIComponent(n)}`);if(c.error)throw new Error(c.error);i(c.files||[])}catch(c){x(c instanceof Error?c.message:String(c)),i([])}finally{u(!1)}},[n]);a.useEffect(()=>{t&&j()},[t,j]);const v=a.useCallback(async c=>{if(window.confirm(`确定删除文件 "${c.name}"?删除后无法恢复。`)){g(c.id);try{const I=await fetch("/api/uploaded-files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:c.sessionId,fileId:c.id})}),C=await I.json();if(!I.ok||C.error)throw new Error(C.error||`HTTP ${I.status}`);await j()}catch(I){window.alert(`删除失败:${I instanceof Error?I.message:String(I)}`)}finally{g(null)}}},[j]),w=a.useCallback(c=>{const L=`/api/uploaded-files/download?sessionId=${encodeURIComponent(c.sessionId)}&fileId=${encodeURIComponent(c.id)}`;window.open(L,"_blank")},[]);return t?e.jsxs("div",{className:"uploaded-files-drawer",children:[e.jsxs("div",{className:"uploaded-files-drawer-header",children:[e.jsx("span",{className:"uploaded-files-drawer-title",children:"已上传的文件"}),e.jsxs("div",{className:"uploaded-files-drawer-actions",children:[e.jsx("button",{type:"button",className:"uploaded-files-drawer-btn",onClick:j,title:"刷新",disabled:d,children:e.jsx(Ft,{size:14,className:d?"spin":""})}),e.jsx("button",{type:"button",className:"uploaded-files-drawer-btn",onClick:s,title:"关闭",children:e.jsx(ys,{size:14})})]})]}),e.jsxs("div",{className:"uploaded-files-drawer-body",children:[f&&e.jsxs("div",{className:"uploaded-files-drawer-error",children:["加载失败:",f]}),!f&&r.length===0&&!d&&e.jsx("div",{className:"uploaded-files-drawer-empty",children:"当前会话没有已上传的文件"}),r.map(c=>e.jsxs("div",{className:"uploaded-files-drawer-item",children:[e.jsx(It,{size:16,className:"uploaded-files-drawer-icon"}),e.jsxs("div",{className:"uploaded-files-drawer-info",children:[e.jsx("div",{className:"uploaded-files-drawer-name",title:c.name,children:c.name}),e.jsxs("div",{className:"uploaded-files-drawer-meta",children:[cn(c.size)," · ",c.mimeType," · ",dn(c.uploadedAt)]}),e.jsxs("div",{className:"uploaded-files-drawer-id",title:c.id,children:["ID: ",c.id]})]}),e.jsx("button",{type:"button",className:"uploaded-files-drawer-btn",onClick:()=>w(c),title:"下载",children:e.jsx(_t,{size:14})}),e.jsx("button",{type:"button",className:"uploaded-files-drawer-btn danger",onClick:()=>v(c),disabled:l===c.id,title:"删除",children:e.jsx(Jt,{size:14})})]},c.id))]})]}):null}function ds(t){return new Promise((s,n)=>{const r=new FileReader;r.onload=()=>s(r.result),r.onerror=n,r.readAsDataURL(t)})}const hn=a.memo(a.forwardRef(function({loading:s,connected:n,canUpload:r,canUploadImage:i,canUploadFile:d,acceptAttr:u,onSend:f,onAbort:x},l){const[g,j]=a.useState(""),[v,w]=a.useState([]),[c,L]=a.useState([]),I=a.useRef([]),C=a.useRef(null),S=a.useRef(null),G=a.useCallback(()=>{const _=C.current;_&&(_.style.height="auto",_.style.height=`${_.scrollHeight}px`)},[]),P=a.useCallback(async _=>{const M=[],A=[],z=[];for(const K of Array.from(_))if(K.type.startsWith("image/")&&i){if(K.size>10*1024*1024)continue;const ee=await ds(K);M.push(ee),z.push("image")}else if(d){if(K.size>20*1024*1024)continue;const ee=await ds(K);A.push({name:K.name,data:ee,mimeType:K.type||void 0}),z.push("file")}M.length>0&&w(K=>[...K,...M]),A.length>0&&L(K=>[...K,...A]),z.length>0&&(I.current=[...I.current,...z])},[i,d]);a.useImperativeHandle(l,()=>({addFiles:P}),[P]);const Z=a.useCallback(async()=>{await f(g,c,v,I.current),j(""),w([]),L([]),I.current=[],C.current&&(C.current.style.height="auto")},[g,c,v,f]),q=_=>{_.key==="Enter"&&!_.shiftKey&&(_.preventDefault(),Z())},U=async _=>{_.target.files&&await P(_.target.files),_.target.value=""},Y=async _=>{var z;if(!i)return;const M=(z=_.clipboardData)==null?void 0:z.items;if(!M)return;const A=[];for(const K of Array.from(M)){if(!K.type.startsWith("image/"))continue;const ee=K.getAsFile();ee&&A.push(ee)}A.length>0&&await P(A)},k=_=>{w(z=>z.filter((K,ee)=>ee!==_));const M=[...I.current];let A=0;for(let z=0;z<M.length;z++)if(M[z]==="image"){if(A===_){M.splice(z,1);break}A++}I.current=M},m=_=>{L(z=>z.filter((K,ee)=>ee!==_));const M=[...I.current];let A=0;for(let z=0;z<M.length;z++)if(M[z]==="file"){if(A===_){M.splice(z,1);break}A++}I.current=M},h=I.current,p=new Array(v.length),W=new Array(c.length);{let _=0,M=0;for(let A=0;A<h.length;A++)h[A]==="image"?(_<p.length&&(p[_]=A+1),_++):h[A]==="file"&&(M<W.length&&(W[M]=A+1),M++)}const V=!!(g.trim()||v.length>0||c.length>0),ae=s&&!V;return e.jsxs(e.Fragment,{children:[v.length>0&&e.jsx("div",{className:"pending-images",children:v.map((_,M)=>e.jsxs("div",{className:"pending-image-item",children:[e.jsx("img",{src:_,alt:`pending-${M}`}),e.jsx("button",{className:"pending-image-remove",onClick:()=>k(M),children:"×"}),p[M]>0&&e.jsxs("span",{className:"pending-order-badge",children:["#",p[M]]})]},M))}),c.length>0&&e.jsx("div",{className:"pending-files",children:c.map((_,M)=>e.jsxs("div",{className:"pending-file-item",children:[W[M]>0&&e.jsxs("span",{className:"pending-file-order",children:["#",W[M]]}),e.jsx("span",{className:"pending-file-icon",children:e.jsx(Ze,{size:14})}),e.jsx("span",{className:"pending-file-name",children:_.name}),e.jsx("button",{className:"pending-file-remove",onClick:()=>m(M),children:"×"})]},M))}),e.jsxs("div",{className:"input-area",children:[e.jsx("input",{ref:S,type:"file",accept:u,multiple:!0,style:{display:"none"},onChange:U}),r&&e.jsx("button",{className:"upload-btn",onClick:()=>{var _;return(_=S.current)==null?void 0:_.click()},disabled:!n,title:i&&d?"上传图片或文件":i?"上传图片":"上传文件",children:e.jsx(vs,{size:18})}),e.jsx("textarea",{ref:C,value:g,onChange:_=>{j(_.target.value),G()},onKeyDown:q,onPaste:Y,placeholder:"输入消息... (Enter 发送, Shift+Enter 换行)",disabled:!n,rows:1}),ae?e.jsx("button",{className:"send-btn stop-mode",onClick:x,title:"停止生成",children:e.jsx(Ht,{size:16})}):e.jsx("button",{className:"send-btn",onClick:()=>{Z()},disabled:!n||!V,children:"↑"})]})]})}));function mn({startTime:t,endTime:s}){const[n,r]=a.useState(Date.now());if(a.useEffect(()=>{if(s||!t)return;const d=setInterval(()=>r(Date.now()),100);return()=>clearInterval(d)},[t,s]),!t)return null;const i=((s||n)-t)/1e3;return e.jsxs("span",{className:"tool-call-timer",children:[i.toFixed(1),"s"]})}function us({startTime:t,endTime:s}){const[n,r]=a.useState(Date.now());a.useEffect(()=>{if(s)return;let d;const u=()=>{r(Date.now()),d=requestAnimationFrame(u)};return d=requestAnimationFrame(u),()=>cancelAnimationFrame(d)},[s]);const i=((s||n)-t)/1e3;return e.jsxs("span",{className:"compress-timer",children:[i.toFixed(1),"s"]})}function fn({seg:t,index:s}){return e.jsxs("details",{className:"tool-call-block",children:[e.jsxs("summary",{className:"tool-call-summary",children:[e.jsx(ss,{size:14})," ",t.name,t.result==null?" …":"",e.jsx(mn,{startTime:t.startTime,endTime:t.endTime})]}),e.jsxs("div",{className:"tool-call-content",children:[e.jsxs("div",{className:"tool-call-args",children:[e.jsx("strong",{children:"参数"}),e.jsx("pre",{children:JSON.stringify(t.args,null,2)})]}),t.result!=null&&e.jsxs("div",{className:"tool-call-result",children:[e.jsx("strong",{children:"结果"}),e.jsx("pre",{children:t.result})]})]})]},s)}const pn=[".txt",".md",".csv",".json",".xml",".html",".htm",".css",".js",".ts",".yaml",".yml",".ini",".cfg",".conf",".log",".sh",".py",".java",".c",".cpp",".h",".rs",".go",".rb",".php",".sql",".pdf",".docx"],xn=pn.join(",")+",text/*,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document";function gn(t){const s=t.trim();if(!s.startsWith("{"))return null;try{const n=JSON.parse(s);return typeof n!="object"||n===null||Array.isArray(n)?null:n}catch{return null}}function jn(t){const s=t.trim();if(!s.startsWith("{"))return null;const n=[];let r=1;const i=()=>{for(;r<s.length&&/[\s,]/.test(s[r]);)r++};for(;r<s.length&&(i(),!(r>=s.length||s[r]==="}"||s[r]!=='"'));){r++;let d="",u=!1;for(;r<s.length;)if(s[r]==="\\"&&r+1<s.length)d+=s[r+1],r+=2;else if(s[r]==='"'){u=!0,r++;break}else d+=s[r],r++;if(!u){n.push({key:d,keyDone:!1,value:"",valueDone:!1,valueType:"unknown"});break}if(i(),r>=s.length||s[r]!==":"){n.push({key:d,keyDone:!0,value:"",valueDone:!1,valueType:"unknown"});break}if(r++,i(),r>=s.length){n.push({key:d,keyDone:!0,value:"",valueDone:!1,valueType:"unknown"});break}if(s[r]==='"'){r++;let f="",x=!1;for(;r<s.length;)if(s[r]==="\\"&&r+1<s.length){const l=s[r+1];f+=l==="n"?`
179
- `:l==="t"?" ":l==='"'?'"':l==="\\"?"\\":l,r+=2}else if(s[r]==='"'){x=!0,r++;break}else f+=s[r],r++;n.push({key:d,keyDone:!0,value:f,valueDone:x,valueType:"string"})}else if(s[r]==="{"||s[r]==="["){const f=s[r],x=f==="{"?"}":"]";let l=1;const g=r;r++;let j=!1;for(;r<s.length&&l>0;)j?s[r]==="\\"?r++:s[r]==='"'&&(j=!1):s[r]==='"'?j=!0:s[r]===f?l++:s[r]===x&&l--,r++;n.push({key:d,keyDone:!0,value:s.slice(g,r),valueDone:l===0,valueType:f==="{"?"object":"array"})}else{let f="";for(;r<s.length&&!/[,\s}]/.test(s[r]);)f+=s[r],r++;const x=r<s.length&&/[,}]/.test(s[r]),l=/^(true|false)$/.test(f)?"boolean":f==="null"?"null":"number";n.push({key:d,keyDone:!0,value:f,valueDone:x,valueType:l})}}return n.length>0?n:null}const ws={mood:"心情",state:"状态",desire:"发言欲望",current_action:"当前动作",think:"思考",message:"回复",response:"回复",reply:"回复",content:"内容",analysis:"分析",file_analysis:"文件分析",image_analysis:"图片分析"},ks=new Set(["message","response","reply","content","answer","text","msg"]);function vn({label:t,data:s}){const[n,r]=a.useState(!0);return e.jsxs("div",{className:"json-field json-field-group",children:[e.jsxs("div",{className:"json-field-header json-field-toggle",onClick:()=>r(!n),children:[n?e.jsx(xs,{size:14}):e.jsx(gs,{size:14}),e.jsx("span",{className:"json-field-label",children:t})]}),n&&e.jsx("div",{className:"json-field-children",children:Object.entries(s).map(([i,d])=>e.jsx(bs,{fieldKey:i,value:d},i))})]})}function bs({fieldKey:t,value:s}){const n=ws[t]||t;if(s==null||s==="")return null;if(typeof s=="object"&&!Array.isArray(s))return e.jsx(vn,{label:n,data:s});if(Array.isArray(s))return e.jsxs("div",{className:"json-field",children:[e.jsx("span",{className:"json-field-label",children:n}),e.jsx("span",{className:"json-field-value",children:s.map(String).join(", ")})]});const r=String(s),i=ks.has(t);return e.jsxs("div",{className:`json-field${i?" json-field-reply":""}`,children:[e.jsx("span",{className:"json-field-label",children:n}),i?e.jsx("div",{className:"json-field-value json-field-value-md",children:e.jsx(_e,{remarkPlugins:Te,rehypePlugins:Ie,components:Me,children:$e(r)})}):e.jsx("span",{className:"json-field-value",children:r})]})}function yn({data:t}){return e.jsx("div",{className:"json-message-view",children:Object.entries(t).map(([s,n])=>e.jsx(bs,{fieldKey:s,value:n},s))})}function Nn({fields:t}){return e.jsx("div",{className:"json-message-view",children:t.map((s,n)=>{const i=n===t.length-1&&(!s.valueDone||!s.keyDone),d=s.keyDone&&ws[s.key]||s.key,u=s.keyDone&&ks.has(s.key);return e.jsxs("div",{className:`json-field${u?" json-field-reply":""}`,children:[e.jsxs("span",{className:`json-field-label${s.keyDone?"":" json-field-partial"}`,children:[d,!s.keyDone&&i&&e.jsx("span",{className:"streaming-cursor"})]}),s.keyDone&&(u&&s.value?e.jsxs("div",{className:"json-field-value json-field-value-md",children:[e.jsx(_e,{remarkPlugins:Te,rehypePlugins:Ie,components:Me,children:$e(s.value)}),i&&e.jsx("span",{className:"streaming-cursor"})]}):e.jsxs("span",{className:"json-field-value",children:[s.value,i&&e.jsx("span",{className:"streaming-cursor"})]}))]},n)})})}const Ue=a.memo(function({content:s}){const n=gn(s);if(n)return e.jsx(yn,{data:n});if(s.trim().startsWith("{")){const i=jn(s);return i?e.jsx(Nn,{fields:i}):null}return e.jsx(_e,{remarkPlugins:Te,rehypePlugins:Ie,components:Me,children:$e(s)})});function wn(t){if(!t)return"";const s=[];return t.image&&s.push("image/*"),t.file&&s.push(xn),s.push("audio/*"),s.push("video/*"),s.join(",")}function kn({status:t}){switch(t){case"completed":return e.jsx(js,{size:14,className:"todo-icon todo-icon-done"});case"in-progress":return e.jsx(Qe,{size:14,className:"todo-icon todo-icon-active"});default:return e.jsx(kt,{size:14,className:"todo-icon todo-icon-pending"})}}function bn({items:t,onClear:s,loading:n}){const[r,i]=a.useState(!0),d=t.filter(l=>l.status==="completed").length,u=t.length,f=d===u,x=!f&&n;return e.jsxs("div",{className:`todo-bar ${f?"todo-bar-done":""}`,children:[e.jsxs("div",{className:"todo-bar-header",onClick:()=>i(!r),children:[e.jsx(Dt,{size:15,className:"todo-bar-icon"}),e.jsx("span",{className:"todo-bar-title",children:"任务计划"}),e.jsxs("span",{className:"todo-bar-count",children:[d,"/",u]}),e.jsx("div",{className:"todo-bar-progress",children:e.jsx("div",{className:"todo-bar-progress-fill",style:{width:`${u>0?d/u*100:0}%`}})}),e.jsx("button",{className:"todo-bar-toggle",title:r?"收起":"展开",children:r?e.jsx(xs,{size:14}):e.jsx(gs,{size:14})}),e.jsx("button",{className:"todo-bar-clear",onClick:l=>{l.stopPropagation(),x||s()},disabled:x,title:x?"任务执行中,无法清除":"清除计划",children:e.jsx(ys,{size:14})})]}),r&&e.jsx("div",{className:"todo-bar-list",children:t.map(l=>e.jsxs("div",{className:`todo-item todo-item-${l.status}`,children:[e.jsx(kn,{status:l.status}),e.jsx("span",{className:"todo-item-title",children:l.title})]},l.id))})]})}const es="aalis:open-lightbox";function hs(t){window.dispatchEvent(new CustomEvent(es,{detail:t}))}const Cn=a.memo(function({msg:s,senderName:n,isLast:r,isGenerating:i,onAbort:d,checkpoint:u,rolledBack:f,onRollback:x,onRollbackWithChat:l,toolCallsProgress:g}){return s.role==="system"?e.jsxs("div",{className:"system-event-separator",children:[e.jsx("span",{className:"system-event-line"}),e.jsxs("span",{className:"system-event-text",children:[e.jsx(ps,{size:12})," ",s.content]}),e.jsx("span",{className:"system-event-line"})]}):e.jsxs("div",{className:`message-group ${s.role}`,children:[e.jsxs("div",{className:"message-sender",children:[e.jsx("span",{className:"message-sender-name",children:s.role==="user"?"You":n}),s.timestamp?e.jsx("span",{className:"message-time",title:new Date(s.timestamp).toLocaleString(),children:sn(s.timestamp)}):null,s.role==="assistant"&&s.modelInfo&&(s.modelInfo.model||s.modelInfo.completionTokens!=null)?e.jsxs("span",{className:"message-model-badge",title:[s.modelInfo.provider&&s.modelInfo.model?`${s.modelInfo.provider} / ${s.modelInfo.model}`:s.modelInfo.model,s.modelInfo.completionTokens!=null?`本次生成 ${s.modelInfo.completionTokens} tok`:null,s.modelInfo.promptTokens!=null?`上下文 ${s.modelInfo.promptTokens} tok`:null,s.modelInfo.elapsedMs!=null?`耗时 ${(s.modelInfo.elapsedMs/1e3).toFixed(1)}s`:null].filter(Boolean).join(" · "),children:[s.modelInfo.model??"",s.modelInfo.completionTokens!=null?` · ${(s.modelInfo.completionTokens/1e3).toFixed(1)}k`:"",s.modelInfo.elapsedMs!=null?` · ${(s.modelInfo.elapsedMs/1e3).toFixed(1)}s`:""]}):null]}),s.role==="user"&&s.images&&s.images.length>0&&e.jsx("div",{className:"message-images",children:s.images.map((j,v)=>e.jsx("div",{className:"message-image-wrap",children:e.jsx("img",{src:je(j),alt:`attached-${v}`,className:"message-image",onClick:()=>hs(je(j))})},v))}),s.role==="user"&&s.fileNames&&s.fileNames.length>0&&e.jsx("div",{className:"message-files",children:s.fileNames.map((j,v)=>e.jsxs("div",{className:"message-file-item",children:[e.jsx(Ze,{size:14})," ",j]},v))}),s.role==="assistant"&&s.attachments&&s.attachments.length>0&&e.jsx("div",{className:"message-images",children:s.attachments.map((j,v)=>j.kind==="image"?e.jsx("div",{className:"message-image-wrap",children:e.jsx("img",{src:je(j.data),alt:j.name??`attachment-${v}`,className:"message-image",onClick:()=>hs(je(j.data))})},`a-${v}`):j.kind==="video"?e.jsx("video",{controls:!0,src:je(j.data),className:"message-image"},`a-${v}`):j.kind==="audio"?e.jsx("audio",{controls:!0,src:je(j.data)},`a-${v}`):e.jsxs("div",{className:"message-file-item",children:[e.jsx(Ze,{size:14})," ",j.name??"attachment"]},`a-${v}`))}),s.role==="assistant"&&s.segments&&s.segments.length>0?e.jsx("div",{className:"message-bubble",children:(()=>{const j=[];let v=0;for(;v<s.segments.length;){const w=s.segments[v];if(w.type==="reasoning_text"){const c=[];for(;v<s.segments.length&&s.segments[v].type==="reasoning_text";)c.push(s.segments[v]),v++;const L=c.filter(I=>I.type==="reasoning_text").map(I=>I.content).join("");L&&j.push(e.jsxs("details",{className:"thinking-block",children:[e.jsxs("summary",{className:"thinking-summary",children:[e.jsx(os,{size:14})," 思考过程"]}),e.jsx("div",{className:"thinking-content",children:e.jsx(_e,{remarkPlugins:Te,rehypePlugins:Ie,components:Me,children:$e(L)})})]},`r-${v}`));continue}if(w.type==="text"){w.content&&j.push(e.jsx(Ue,{content:w.content},`t-${v}`)),v++;continue}j.push(e.jsx(fn,{seg:w,index:v},`tc-${v}`)),v++}return j})()}):s.role==="assistant"&&s.reasoningContent?e.jsxs(e.Fragment,{children:[e.jsxs("details",{className:"thinking-block",children:[e.jsxs("summary",{className:"thinking-summary",children:[e.jsx(os,{size:14})," 思考过程"]}),e.jsx("div",{className:"thinking-content",children:e.jsx(_e,{remarkPlugins:Te,rehypePlugins:Ie,components:Me,children:$e(s.reasoningContent)})})]}),e.jsx("div",{className:"message-bubble",children:e.jsx(Ue,{content:s.content})})]}):e.jsx("div",{className:"message-bubble",children:s.role==="assistant"?e.jsx(Ue,{content:s.content}):s.content}),s.role==="assistant"&&g&&g.size>0&&e.jsx("div",{className:"tool-call-progress-bubble",children:[...g.entries()].sort((j,v)=>j[0]-v[0]).map(([j,v])=>e.jsx(Cs,{name:v.name,charsAccumulated:v.charsAccumulated,startedAt:v.startedAt},`pending-${j}`))}),r&&i&&s.role==="assistant"&&e.jsx("button",{className:"stop-generate-btn",onClick:d,title:"停止生成",children:"■ 停止生成"}),s.role==="assistant"&&u&&!i&&(f?e.jsxs("span",{className:"checkpoint-rolled-back",children:[e.jsx(Je,{size:12})," 此次修改已回滚"]}):e.jsxs("div",{className:"checkpoint-rollback-actions",children:[u.fileCount>0&&e.jsxs("button",{className:"checkpoint-rollback-btn",onClick:()=>x==null?void 0:x(u),title:`仅回滚本回合的 ${u.fileCount} 个文件改动(保留对话)${u.execUsed?`
180
- 注意:本回合调用过 exec/shell,命令副作用无法回滚`:""}`,children:[e.jsx(Je,{size:12})," 回滚文件改动",u.execUsed&&e.jsxs("span",{className:"checkpoint-warn",children:[e.jsx(De,{size:11})," exec"]})]}),e.jsxs("button",{className:"checkpoint-rollback-btn",onClick:()=>l==null?void 0:l(u),title:`回滚本轮对话(含 ${u.fileCount} 处文件改动):删除本轮的用户提问、回复和工具调用记录,并恢复文件${u.execUsed?`
181
- 注意:本回合调用过 exec/shell,命令副作用无法回滚`:""}`,children:[e.jsx(Je,{size:12})," 回滚本轮对话(含文件)",u.execUsed&&e.jsxs("span",{className:"checkpoint-warn",children:[e.jsx(De,{size:11})," exec"]})]})]}))]})});function Cs({name:t,charsAccumulated:s,startedAt:n}){const[r,i]=a.useState(Date.now()-n);a.useEffect(()=>{const u=window.setInterval(()=>i(Date.now()-n),100);return()=>window.clearInterval(u)},[n]);const d=(r/1e3).toFixed(1);return e.jsx("div",{className:"tool-call-block tool-call-block-pending","aria-live":"polite",children:e.jsxs("div",{className:"tool-call-summary",children:[e.jsx("span",{className:"tool-call-progress-icon",children:e.jsx(ss,{size:14})}),e.jsx("span",{children:t||"正在生成…"}),e.jsxs("span",{className:"tool-call-progress-meta",children:[s," 字符 · ",d,"s"]})]})})}function Sn({messages:t,loading:s,connected:n,status:r,onSend:i,onAbort:d,width:u,sessionTitle:f,onNewSession:x,todoItems:l,onClearTodos:g,toolLimitReached:j,onContinueTools:v,toolCallsProgress:w,tokenUsage:c,compressingStatus:L,onCompress:I}){const C=a.useRef(null),S=a.useRef(null),G=a.useRef(null),P=a.useRef(!1),[Z,q]=a.useState([]),[U,Y]=a.useState(new Set),k=a.useRef(s);a.useEffect(()=>{let y=!1;async function R(){try{const B=oe();if(!B||B==="__new_chat__"){y||q([]);return}const F=await de("@aalis/plugin-checkpoint","listTurns",{sessionId:B});!y&&Array.isArray(F)&&q(F)}catch{}}return k.current&&!s?R():t.length===0?q([]):R(),k.current=s,()=>{y=!0}},[s,f,t.length]);const m=a.useMemo(()=>y=>{for(const R of Z){const B=R.startedAt-1e3,F=(R.endedAt??R.startedAt+6e4)+5e3;if(y>=B&&y<=F)return R}},[Z]),h=a.useCallback(async y=>{const R=y.filesPreview.slice(0,3).join(`
182
- `),B=y.fileCount>y.filesPreview.length?`
183
- ... 共 ${y.fileCount} 个文件`:"",F=y.execUsed?`
184
-
185
- ⚠ 本回合调用过 exec/shell,命令的副作用无法回滚!`:"";if(window.confirm(`将回滚此回合的文件改动:
186
-
187
- ${R}${B}${F}
188
-
189
- 确定继续?`))try{const se=await de("@aalis/plugin-checkpoint","rollback",{sessionId:oe(),turnId:y.turnId}),X=`回滚完成:恢复 ${se.restored.length} 个,删除 ${se.deleted.length} 个`;se.errors.length>0?window.alert(`${X}
190
- 失败 ${se.errors.length} 个(如有新建文件在不可删除的根下,需手动删除):
191
- `+se.errors.map(le=>`${le.uri}: ${le.reason}`).join(`
192
- `)):window.alert(X),Y(le=>new Set([...le,y.turnId]))}catch(se){window.alert(`回滚失败:${se.message}`)}},[]),p=a.useCallback(async y=>{const R=y.filesPreview.slice(0,3).join(`
193
- `),B=y.fileCount>y.filesPreview.length?`
194
- ... 共 ${y.fileCount} 个文件`:"",F=y.execUsed?`
195
-
196
- ⚠ 本回合调用过 exec/shell,命令的副作用无法回滚!`:"",me=y.fileCount>0?`
197
-
198
- 同时恢复以下文件:
199
- ${R}${B}`:"";if(window.confirm(`将回滚本轮对话:
200
-
201
- · 删除本轮的用户提问、AI 回复和工具调用记录
202
- · 清除对应的向量记忆条目${me}${F}
203
-
204
- 此操作不可撤销。确定继续?`))try{const X=await de("@aalis/plugin-checkpoint","rollbackWithChat",{sessionId:oe(),turnId:y.turnId}),le=[];X.chatDeleted&&le.push(`删除 ${X.deletedMessages} 条消息`),y.fileCount>0&&le.push(`恢复 ${X.restored.length} 个文件,删除 ${X.deleted.length} 个新建文件`);const Oe=le.length>0?`回滚完成:${le.join(";")}`:"回滚完成";X.errors.length>0&&window.alert(`${Oe}
205
- 失败 ${X.errors.length} 项:
206
- `+X.errors.map(ge=>`${ge.uri||"(memory)"}: ${ge.reason}`).join(`
207
- `)),Y(ge=>new Set([...ge,y.turnId]))}catch(X){window.alert(`回滚失败:${X.message}`)}},[]),W=a.useRef(null),V=a.useRef(!1),[ae,_]=a.useState(!1),M=a.useRef(0),[A,z]=a.useState(!1),[K,ee]=a.useState(!1),[xe,ue]=a.useState(null),ve=a.useRef(0),ye=a.useRef(0);a.useEffect(()=>{const y=B=>{const F=B.detail;typeof F=="string"&&ue(F)},R=B=>{B.key==="Escape"&&ue(null)};return window.addEventListener(es,y),window.addEventListener("keydown",R),()=>{window.removeEventListener(es,y),window.removeEventListener("keydown",R)}},[]);const re=r==null?void 0:r.uploadCapabilities,Ne=(re==null?void 0:re.image)??!1,we=(re==null?void 0:re.file)??!1,ke=Ne||we,Pe=wn(re);a.useEffect(()=>{L==="start"?(ve.current=Date.now(),ye.current=0):(L==="done"||L==="error")&&(ye.current=Date.now())},[L]),a.useEffect(()=>{const y=G.current;if(!y)return;const R=()=>{const{scrollTop:B,scrollHeight:F,clientHeight:me}=y;P.current=F-B-me>200,V.current=!0,W.current&&clearTimeout(W.current),W.current=setTimeout(()=>{V.current=!1},300)};return y.addEventListener("scroll",R,{passive:!0}),()=>y.removeEventListener("scroll",R)},[]),a.useEffect(()=>{const y=G.current;if(!y)return;const R=new ResizeObserver(()=>{var B;!P.current&&!V.current&&((B=S.current)==null||B.scrollIntoView({behavior:s?"instant":"smooth"}))});return R.observe(y),()=>R.disconnect()},[t.length]),a.useEffect(()=>{var y;!P.current&&!V.current&&((y=S.current)==null||y.scrollIntoView({behavior:"smooth"}))},[t]);const Ae=a.useCallback((y,R,B,F)=>i(y,R,B,F),[i]),be=y=>{y.preventDefault(),y.stopPropagation(),M.current++,ke&&y.dataTransfer.types.includes("Files")&&_(!0)},Ce=y=>{y.preventDefault(),y.stopPropagation(),M.current--,M.current<=0&&(M.current=0,_(!1))},Ee=y=>{y.preventDefault(),y.stopPropagation()},ze=async y=>{var R;y.preventDefault(),y.stopPropagation(),M.current=0,_(!1),!(!ke||!y.dataTransfer.files.length)&&await((R=C.current)==null?void 0:R.addFiles(y.dataTransfer.files))},ie=t[t.length-1],Le=(ie==null?void 0:ie.role)==="assistant"&&s;return e.jsxs("div",{className:`chat-panel${ae?" drag-over":""}`,style:{width:u},onDragEnter:be,onDragLeave:Ce,onDragOver:Ee,onDrop:ze,children:[ae&&e.jsx("div",{className:"drag-overlay",children:e.jsxs("div",{className:"drag-overlay-content",children:[e.jsx(vs,{size:16})," 松开以上传文件"]})}),e.jsxs("div",{className:"chat-panel-header",children:[e.jsxs("span",{className:"chat-panel-title",children:[e.jsx(is,{size:16})," ",f||(r==null?void 0:r.name)||"Aalis"]}),e.jsxs("div",{className:"chat-panel-header-actions",children:[e.jsxs("div",{className:"token-usage-badge",onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),children:[e.jsx(Ns,{size:12}),e.jsx("span",{className:`token-usage-number${c&&c.usageRatio>.85?" warn":c&&c.usageRatio>.7?" caution":""}`,children:c?c.used.toLocaleString():"--"}),A&&e.jsxs("div",{className:"token-usage-panel",children:[e.jsx("div",{className:"token-panel-title",children:"Token 使用情况"}),c?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"token-panel-bar",children:e.jsx("div",{className:`token-panel-bar-fill${c.usageRatio>.85?" warn":c.usageRatio>.7?" caution":""}`,style:{width:`${Math.min(100,c.usageRatio*100)}%`}})}),e.jsxs("div",{className:"token-panel-ratio",children:[(c.usageRatio*100).toFixed(1),"% 已使用"]}),e.jsxs("div",{className:"token-panel-rows",children:[e.jsxs("div",{className:"token-panel-row",children:[e.jsx("span",{children:"上下文窗口"}),e.jsx("span",{children:c.contextWindow.toLocaleString()})]}),e.jsxs("div",{className:"token-panel-section-header",children:["系统提示词 ",e.jsx("span",{className:"token-panel-section-total",children:c.breakdown.system.toLocaleString()})]}),e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"人设 / Persona"}),e.jsx("span",{children:c.breakdown.persona.toLocaleString()})]}),c.breakdown.memorySummary>0&&e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"对话摘要"}),e.jsx("span",{children:c.breakdown.memorySummary.toLocaleString()})]}),c.breakdown.memoryVector>0&&e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"向量记忆"}),e.jsx("span",{children:c.breakdown.memoryVector.toLocaleString()})]}),c.breakdown.skills>0&&e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"技能描述"}),e.jsx("span",{children:c.breakdown.skills.toLocaleString()})]}),c.breakdown.platform>0&&e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"平台提示"}),e.jsx("span",{children:c.breakdown.platform.toLocaleString()})]}),c.breakdown.subtask>0&&e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"子任务上下文"}),e.jsx("span",{children:c.breakdown.subtask.toLocaleString()})]}),c.breakdown.systemOther>0&&e.jsxs("div",{className:"token-panel-row sub",children:[e.jsx("span",{children:"其他系统提示"}),e.jsx("span",{children:c.breakdown.systemOther.toLocaleString()})]}),e.jsxs("div",{className:"token-panel-row",children:[e.jsx("span",{children:"历史消息"}),e.jsx("span",{children:c.breakdown.history.toLocaleString()})]}),e.jsxs("div",{className:"token-panel-row",children:[e.jsx("span",{children:"工具结果"}),e.jsx("span",{children:c.breakdown.toolResults.toLocaleString()})]}),e.jsxs("div",{className:"token-panel-row",children:[e.jsx("span",{children:"工具定义"}),e.jsx("span",{children:c.breakdown.toolDefs.toLocaleString()})]}),e.jsxs("div",{className:"token-panel-row",children:[e.jsx("span",{children:"回复保留量"}),e.jsx("span",{children:c.breakdown.reservedForReply.toLocaleString()})]})]}),I&&e.jsx("button",{className:"token-panel-compress-btn",onClick:y=>{y.stopPropagation(),I()},disabled:L==="start",children:L==="start"?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{size:12,className:"compress-spinner"})," 压缩中…"]}):e.jsxs(e.Fragment,{children:[e.jsx(ps,{size:12})," 压缩对话"]})})]}):e.jsx("div",{className:"token-panel-empty",children:"发送消息后将显示 Token 用量统计"})]})]}),x&&e.jsx("button",{className:"chat-panel-new-btn",onClick:x,title:"新对话",children:"+"}),e.jsx("button",{className:"chat-panel-new-btn",onClick:()=>ee(y=>!y),title:"已上传的文件","aria-label":"已上传的文件",children:e.jsx(Et,{size:14})})]})]}),e.jsx(un,{open:K,onClose:()=>ee(!1),sessionId:oe()}),e.jsxs("div",{className:"messages",ref:G,children:[t.length===0&&e.jsxs("div",{className:"empty",children:[e.jsx("div",{className:"empty-icon",children:e.jsx(is,{size:40})}),"开始和 ",(r==null?void 0:r.name)??"Aalis"," 对话吧"]}),t.map((y,R)=>{const B=R===t.length-1;return e.jsx(Cn,{msg:y,senderName:(r==null?void 0:r.name)??"Aalis",isLast:B,isGenerating:Le,onAbort:d,checkpoint:y.role==="assistant"?m(y.timestamp):void 0,rolledBack:y.role==="assistant"?(()=>{const F=m(y.timestamp);return F?U.has(F.turnId):!1})():!1,onRollback:h,onRollbackWithChat:p,toolCallsProgress:B&&y.role==="assistant"&&Le?w:void 0},R)}),s&&(!ie||ie.role!=="assistant")&&e.jsxs("div",{className:"message-group assistant",children:[e.jsx("div",{className:"message-sender",children:(r==null?void 0:r.name)??"Aalis"}),e.jsx("div",{className:"message-bubble",children:w&&w.size>0?[...w.entries()].sort((y,R)=>y[0]-R[0]).map(([y,R])=>e.jsx(Cs,{name:R.name,charsAccumulated:R.charsAccumulated,startedAt:R.startedAt},`pending-${y}`)):e.jsxs("div",{className:"typing-indicator",children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}),e.jsx("button",{className:"stop-generate-btn",onClick:d,title:"停止生成",children:"■ 停止生成"})]}),j&&!s&&e.jsxs("div",{className:"tool-limit-bar",children:[e.jsx("span",{className:"tool-limit-text",children:"⚠ 工具调用次数已达上限"}),e.jsxs("div",{className:"tool-limit-actions",children:[v&&e.jsx("button",{className:"tool-limit-btn continue",onClick:v,children:"继续迭代"}),e.jsx("span",{className:"tool-limit-hint",children:"或输入新内容引导模型"})]})]}),L==="start"&&e.jsxs("div",{className:"system-event-separator compressing",children:[e.jsx("span",{className:"system-event-line"}),e.jsxs("span",{className:"system-event-text",children:[e.jsx(Qe,{size:12,className:"compress-spinner"})," 压缩对话中 ",e.jsx(us,{startTime:ve.current})]}),e.jsx("span",{className:"system-event-line"})]}),L==="done"&&e.jsxs("div",{className:"system-event-separator compress-done",children:[e.jsx("span",{className:"system-event-line"}),e.jsxs("span",{className:"system-event-text",children:[e.jsx(js,{size:12})," 已压缩对话 ",e.jsx(us,{startTime:ve.current,endTime:ye.current})]}),e.jsx("span",{className:"system-event-line"})]}),L==="error"&&e.jsxs("div",{className:"system-event-separator compress-error",children:[e.jsx("span",{className:"system-event-line"}),e.jsxs("span",{className:"system-event-text",children:[e.jsx(De,{size:12})," 压缩失败"]}),e.jsx("span",{className:"system-event-line"})]}),e.jsx("div",{ref:S})]}),l&&l.length>0&&g&&e.jsx(bn,{items:l,onClear:g,loading:s}),e.jsx(hn,{ref:C,loading:s,connected:n,canUpload:ke,canUploadImage:Ne,canUploadFile:we,acceptAttr:Pe,onSend:Ae,onAbort:d}),xe&&e.jsxs("div",{className:"image-lightbox",onClick:()=>ue(null),children:[e.jsx("img",{src:xe,alt:"预览",className:"image-lightbox-content",onClick:y=>y.stopPropagation()}),e.jsx("button",{type:"button",className:"image-lightbox-close",onClick:()=>ue(null),"aria-label":"关闭",children:"×"})]})]})}const _n=a.lazy(()=>he(()=>import("./PluginConfigPage-C40cz0di.js"),__vite__mapDeps([2,1,3,4,5,6,7,8])).then(t=>({default:t.PluginConfigPage}))),$n=a.lazy(()=>he(()=>import("./MarketplacePage-pv_YtVO7.js"),__vite__mapDeps([9,1,10,4,5,6,7,8])).then(t=>({default:t.MarketplacePage}))),Tn=a.lazy(()=>he(()=>import("./PlatformPage-69hFZKZQ.js"),__vite__mapDeps([11,1,12,4,5,6,7,8])).then(t=>({default:t.PlatformPage}))),In=a.lazy(()=>he(()=>import("./AuthorityPage-BM4HipXP.js"),__vite__mapDeps([13,1,10,4,5,6,7,8])).then(t=>({default:t.AuthorityPage}))),Mn=a.lazy(()=>he(()=>import("./LogPage-C_Z3RA5T.js"),__vite__mapDeps([14,1])).then(t=>({default:t.LogPage}))),En=a.lazy(()=>he(()=>import("./SessionsPage-UesoGK-U.js"),__vite__mapDeps([15,1,8,6,7,4,5])).then(t=>({default:t.SessionsPage}))),Ln=a.lazy(()=>he(()=>import("./FilesPage-BDkXMn2Z.js"),__vite__mapDeps([16,1,4,5,6,7,8])).then(t=>({default:t.FilesPage}))),Rn=a.lazy(()=>he(()=>import("./DynamicPage-CNJTcLnN.js"),__vite__mapDeps([17,1,3,18,19,12,10,8,6,7,4,5])).then(t=>({default:t.DynamicPage})));function Dn(){var ns;const[t,s]=a.useState(()=>location.hash.replace("#","")||"dashboard"),[n,r]=a.useState(null),[i,d]=a.useState([]);a.useEffect(()=>{location.hash=t},[t]),a.useEffect(()=>{n&&!n.has(t)&&s("dashboard")},[n,t]);const[u,f]=a.useState([]),[x,l]=a.useState(null),[g,j]=a.useState(null),[v,w]=a.useState(null),[c,L]=a.useState([]),[I,C]=a.useState(null),S=lt(i),{messages:G,setMessages:P,loading:Z,setLoading:q,streamingRef:U}=S,Y=a.useRef({pending:[],raf:0}),[k,m]=a.useState(0),[h,p]=a.useState([]),[W,V]=a.useState(()=>{if(typeof window>"u")return 420;const o=Number(window.localStorage.getItem("aalis:chatWidth"));return Number.isFinite(o)&&o>=280?o:420});a.useEffect(()=>{try{window.localStorage.setItem("aalis:chatWidth",String(W))}catch{}},[W]),a.useEffect(()=>{const o=document.querySelector(".app-layout");if(!o||typeof ResizeObserver>"u")return;const N=360,b=240,E=()=>{var te;const $=o.clientWidth,O=((te=document.querySelector(".nav-rail"))==null?void 0:te.getBoundingClientRect().width)??56,D=Math.max(b,$-O-N);V(J=>Math.min(Math.max(J,b),D))},T=new ResizeObserver(E);return T.observe(o),()=>T.disconnect()},[]);const[ae,_]=a.useState(!1),[M,A]=a.useState(new Map),[z,K]=a.useState(!1),[ee,xe]=a.useState(!1),[ue,ve]=a.useState(!1),[ye,re]=a.useState("正在重启…"),[Ne,we]=a.useState(!1),[ke,Pe]=a.useState(null),[Ae,be]=a.useState(null),Ce=(o,N)=>{const b=o?[...o]:[],E=b[b.length-1];return N.type==="text"&&E&&E.type==="text"?b[b.length-1]={type:"text",content:E.content+N.content}:N.type==="reasoning_text"&&E&&E.type==="reasoning_text"?b[b.length-1]={type:"reasoning_text",content:E.content+N.content}:b.push(N),b},Ee=o=>{let N="",b="";for(const E of o??[])E.type==="text"?N+=E.content:E.type==="reasoning_text"&&(b+=E.content);return{content:N,reasoning:b}},ze=a.useCallback((o,N,b,E,T)=>{Y.current.raf&&(cancelAnimationFrame(Y.current.raf),Y.current.raf=0),Y.current.pending=[],P($=>{const O=$[$.length-1],D=b&&b.length>0?b:N?[{type:"reasoning_text",content:N},{type:"text",content:o}]:[{type:"text",content:o}];return O&&O.role==="assistant"&&U.current?(U.current=!1,[...$.slice(0,-1),{...O,content:o,reasoningContent:N??O.reasoningContent,segments:D,attachments:E??O.attachments,modelInfo:T??O.modelInfo}]):(U.current=!1,[...$,{role:"assistant",content:o,reasoningContent:N,segments:D,attachments:E,modelInfo:T,timestamp:Date.now()}])}),q(!1)},[]),ie=a.useCallback(()=>{const o=Y.current;if(o.raf&&(cancelAnimationFrame(o.raf),o.raf=0),o.pending.length===0)return;const N=o.pending;o.pending=[],P(b=>{const E=b[b.length-1];if(E&&E.role==="assistant"&&U.current){let D=E.segments??[];for(const ne of N)D=Ce(D,{type:ne.kind==="content"?"text":"reasoning_text",content:ne.text});const{content:te,reasoning:J}=Ee(D);return[...b.slice(0,-1),{...E,content:te,reasoningContent:J||void 0,segments:D}]}U.current=!0;let T=[];for(const D of N)T=Ce(T,{type:D.kind==="content"?"text":"reasoning_text",content:D.text});const{content:$,reasoning:O}=Ee(T);return[...b,{role:"assistant",content:$,reasoningContent:O||void 0,segments:T,timestamp:Date.now()}]})},[P,U]),Le=a.useCallback((o,N,b,E)=>{if(b){ie(),q(!1),_(!!E),A(new Map);return}(o||N)&&A($=>$.size===0?$:new Map);const T=Y.current;N&&T.pending.push({kind:"reasoning",text:N}),o&&T.pending.push({kind:"content",text:o}),!T.raf&&(T.raf=requestAnimationFrame(ie))},[ie,q]),y=a.useCallback(o=>{f(N=>N.length>0&&N[N.length-1].seq>=o.seq&&N.some(b=>b.seq===o.seq)?N:[...N,o])},[]),R=a.useCallback(async()=>{const o=u[0];if(!o)return 0;try{const N=await Q(`/api/logs/range?before=${o.seq}&limit=200`);return!N||N.length===0?0:(f(b=>{const E=new Set(b.map($=>$.seq));return[...N.filter($=>!E.has($.seq)),...b]}),N.length)}catch{return 0}},[u]),B=a.useCallback((o,N,b,E)=>{ie(),b==="start"&&A(T=>T.size===0?T:new Map),P(T=>{const $=T[T.length-1];if(b==="start"){const O=Date.now();if($&&$.role==="assistant"){const D=Ce($.segments,{type:"tool_call",name:o,args:N,startTime:O});return[...T.slice(0,-1),{...$,segments:D}]}return U.current=!0,[...T,{role:"assistant",content:"",segments:[{type:"tool_call",name:o,args:N,startTime:O}],timestamp:Date.now()}]}if($&&$.role==="assistant"&&$.segments){const O=Date.now(),D=[...$.segments];for(let te=D.length-1;te>=0;te--){const J=D[te];if(J.type==="tool_call"&&J.name===o&&J.result==null)return D[te]={...J,result:E,endTime:O},[...T.slice(0,-1),{...$,segments:D}]}}return T})},[ie]),F=a.useCallback(()=>{Q("/api/plugins").then(o=>L(o.plugins??[])).catch(()=>{})},[]),me=a.useCallback(()=>{Q("/api/config").then(w).catch(()=>{})},[]),se=a.useCallback(()=>{Q("/api/services").then(o=>C(o.services??null)).catch(()=>{})},[]),X=a.useCallback(()=>{Q("/api/pages").then(o=>{d(o),r(new Set(o.map(N=>N.key)))}).catch(()=>{})},[]),le=a.useCallback(()=>{F(),se(),X(),S.refresh(),Q("/api/status").then(l).catch(()=>{})},[F,se,X,S.refresh]),Oe=a.useCallback(()=>{K(!0),xe(!1),re("正在重启…")},[]),ge=a.useCallback(()=>{ve(!0),re("正在切换前端,即将刷新…")},[]),Ss=a.useCallback(()=>{S.refresh(),m(o=>o+1)},[S.refresh]),_s=a.useCallback(o=>{p(o)},[]),$s=a.useCallback((o,N,b,E,T)=>{P($=>{let O=b&&b.length>0?b:[];O.length===0&&(N&&O.push({type:"reasoning_text",content:N}),o&&O.push({type:"text",content:o}));const D=$[$.length-1];return D&&D.role==="assistant"?[...$.slice(0,-1),{...D,content:o,reasoningContent:N||D.reasoningContent,segments:O}]:[...$,{role:"assistant",content:o,reasoningContent:N||void 0,segments:O,timestamp:Date.now()}]}),E||(U.current=!0,q(!0)),T&&T.length>0?A(new Map(T.map($=>[$.index,{name:$.name,charsAccumulated:$.charsAccumulated,startedAt:$.startedAt}]))):A($=>$.size===0?$:new Map)},[]),Ts=a.useCallback(o=>{A(N=>{const b=new Map(N),E=b.get(o.index);return b.set(o.index,{name:o.name,charsAccumulated:o.charsAccumulated,startedAt:(E==null?void 0:E.startedAt)??Date.now()}),b})},[]),Is=a.useCallback(()=>{A(o=>o.size===0?o:new Map)},[]),Ms=a.useCallback(o=>{we(!0),P(N=>[...N,{role:"assistant",content:o,segments:[{type:"text",content:o}],timestamp:Date.now()}])},[]),Es=a.useCallback(o=>{Pe(o)},[]),Ls=a.useCallback((o,N)=>{o===oe()&&(be(N),N==="done"?(P(b=>[...b,{role:"system",content:"对话已压缩",timestamp:Date.now()}]),setTimeout(()=>be(null),1500)):N==="error"&&setTimeout(()=>be(null),3e3))},[]),{send:Se,sendRaw:Re,connected:fe}=at({onMessage:ze,onStream:Le,onLog:y,onToolCall:B,onStateChanged:le,onRestarting:Oe,onReload:ge,onSessionsChanged:Ss,onTodoUpdated:_s,onStreamResume:$s,onConfirm:Ms,onTokenUsage:Es,onCompressing:Ls,onHistoryChanged:S.handleHistoryChanged,onToolCallProgress:Ts,onToolCallProgressClear:Is}),Rs=a.useCallback(()=>{Re({type:"compress",sessionId:oe()})},[Re]);a.useEffect(()=>{z&&!fe&&(xe(!0),re("等待服务器重启…"))},[z,fe]),a.useEffect(()=>{if(z&&ee&&fe){re("服务器已就绪,即将刷新…");const o=setTimeout(()=>window.location.reload(),800);return()=>clearTimeout(o)}},[z,ee,fe]),a.useEffect(()=>{if(ue){const o=setTimeout(()=>window.location.reload(),1500);return()=>clearTimeout(o)}},[ue]),a.useEffect(()=>{Q("/api/status").then(l).catch(()=>{}),Q("/api/auth/me").then(j).catch(()=>{}),me(),F(),se(),X(),S.refresh(),Q("/api/logs/tail?limit=200").then(f).catch(()=>{})},[F,me,se,X,S.refresh]),a.useEffect(()=>{const o=S.activeSessionId;if(!o||o==="__new_chat__"){p([]);return}de("@aalis/plugin-todo-list","getTodos",{sessionId:o}).then(N=>p(N??[])).catch(()=>p([]))},[S.activeSessionId]),a.useEffect(()=>{const o=setInterval(()=>{Q("/api/status").then(l).catch(()=>{}),F(),se(),X(),S.refresh()},3e4);return()=>clearInterval(o)},[F,se,X,S.refresh]);const Fe=a.useCallback(()=>{Re({type:"abort",sessionId:oe()}),q(!1),_(!1),U.current=!1},[Re]),Ds=a.useCallback(()=>{P(o=>[...o,{role:"user",content:"[请继续执行未完成的工具调用]",timestamp:Date.now()}]),Se("[请继续执行未完成的工具调用]"),_(!1),q(!0)},[Se]),Ps=a.useCallback(()=>{const o=S.activeSessionId;!o||o==="__new_chat__"||(de("@aalis/plugin-todo-list","clearTodos",{sessionId:o}).catch(()=>{}),p([]))},[S.activeSessionId]),As=a.useCallback(async(o,N,b,E)=>{const T=o.trim();if(Ne){if(!T)return;we(!1),P(J=>[...J,{role:"user",content:T,timestamp:Date.now()}]),Se(T);return}if(Z&&Fe(),!T&&b.length===0&&N.length===0)return;await S.ensureSession();const $=b.length>0?[...b]:void 0,O=[];let D=0,te=0;if(E.length>0){for(const J of E)if(J==="image"&&D<b.length)O.push({kind:"image",data:b[D++]});else if(J==="file"&&te<N.length){const ne=N[te++],pe=ne.mimeType??"",Be=pe.startsWith("audio/")?"audio":pe.startsWith("video/")?"video":"file";O.push({kind:Be,data:ne.data,mimeType:pe,name:ne.name})}}for(;D<b.length;)O.push({kind:"image",data:b[D++]});for(;te<N.length;){const J=N[te++],ne=J.mimeType??"",pe=ne.startsWith("audio/")?"audio":ne.startsWith("video/")?"video":"file";O.push({kind:pe,data:J.data,mimeType:ne,name:J.name})}P(J=>[...J,{role:"user",content:T,images:$,fileNames:N.map(ne=>ne.name),timestamp:Date.now()}]),_(!1),q(!0),Se(T,O.length>0?O:void 0)},[Ne,Z,Se,Fe,S]),We={dashboard:e.jsx(Xs,{}),marketplace:e.jsx(Zs,{}),"plugin-config":e.jsx(Qs,{}),platforms:e.jsx(st,{}),authority:e.jsx(tt,{}),files:e.jsx(nt,{}),logs:e.jsx(et,{})},zs=e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M9 3v18M3 9h18"})]}),Os=(o,N)=>We[o]?We[o]:N&&N.trimStart().startsWith("<svg")?e.jsx("span",{className:"nav-item-svg",dangerouslySetInnerHTML:{__html:N}}):zs,ts=a.useMemo(()=>n?i.filter(o=>n.has(o.key)).map(o=>({key:o.key,label:o.label,pluginDisplayName:o.pluginDisplayName,icon:Os(o.key,o.icon),order:o.order??99})).sort((o,N)=>o.order-N.order):Object.entries(We).map(([o,N],b)=>({key:o,label:o,icon:N,order:(b+1)*10})),[n,i]),Fs=(o,N)=>{switch(o){case"dashboard":return e.jsx(Xt,{status:x,connected:fe,plugins:c,servicesData:I,onRefreshServices:se});case"marketplace":return e.jsx($n,{plugins:c,onRefresh:F});case"plugin-config":return e.jsx(_n,{plugins:c,config:v,onRefresh:F,onConfigSaved:me,onRestart:()=>{K(!0),xe(!1),re("正在重启…")}});case"platforms":return e.jsx(Tn,{});case"authority":return e.jsx(In,{});case"logs":return e.jsx(Mn,{logs:u,onLoadOlder:R});case"files":return e.jsx(Ln,{});case"sessions":return e.jsx(En,{pluginName:N,activeSessionId:S.activeSessionId,onSwitchSession:b=>{S.switchSession(b)},onStartNewChat:()=>S.startNewChat(),refreshSignal:k});default:return null}},ce=i.find(o=>o.key===t),qe=ce!=null&&ce.content?ce:void 0;return e.jsxs("div",{className:"app-layout",children:[e.jsxs("nav",{className:"nav-rail",children:[e.jsxs("div",{className:"nav-rail-top",children:[e.jsx("div",{className:"nav-logo",children:"A"}),ts.map(o=>e.jsxs("button",{className:`nav-item ${t===o.key?"active":""}`,onClick:()=>s(o.key),children:[e.jsx("span",{className:"nav-item-icon",children:o.icon}),e.jsx("span",{className:"nav-item-label",children:o.label})]},o.key))]}),e.jsx("div",{className:"nav-rail-bottom",children:e.jsx("div",{className:`nav-status ${fe?"online":"offline"}`,title:fe?"已连接":"离线"})})]}),e.jsxs("main",{className:"content-area",children:[e.jsxs("div",{className:"content-header",children:[e.jsx("span",{className:"content-title",children:(ns=ts.find(o=>o.key===t))==null?void 0:ns.label}),g&&e.jsxs("span",{className:"content-user",title:`${g.identity.platform}:${g.identity.userId}`,children:[g.identity.userId,g.isOwner&&e.jsx("span",{className:"content-user-level",children:"owner"}),e.jsx("button",{className:"btn-sm",onClick:async()=>{await fetch("/api/auth/logout",{method:"POST"}),window.location.reload()},children:"登出"})]})]}),e.jsx("div",{className:"content-body",children:e.jsxs(a.Suspense,{fallback:e.jsx("div",{className:"empty-hint",style:{padding:24},children:"加载中…"}),children:[qe&&e.jsx(Rn,{page:qe}),!qe&&(ce==null?void 0:ce.renderer)&&(Fs(ce.renderer,ce.plugin)||e.jsxs("div",{className:"empty-hint",style:{padding:24},children:["此客户端不支持渲染器「",ce.renderer,"」"]}))]})})]}),e.jsx("div",{className:"resize-handle",onMouseDown:o=>{var pe;o.preventDefault();const N=o.clientX,b=W,E=((pe=document.querySelector(".app-layout"))==null?void 0:pe.clientWidth)??window.innerWidth,T=document.querySelector(".nav-rail"),$=(T==null?void 0:T.getBoundingClientRect().width)??56,O=360,D=280,te=Math.max(D,E-$-O);document.body.classList.add("is-dragging-chat");const J=Be=>{const Ws=b-(Be.clientX-N);V(Math.max(D,Math.min(te,Ws)))},ne=()=>{document.removeEventListener("mousemove",J),document.removeEventListener("mouseup",ne),document.body.style.cursor="",document.body.style.userSelect="",document.body.classList.remove("is-dragging-chat")};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",J),document.addEventListener("mouseup",ne)}}),e.jsx("div",{className:"chat-column",style:{width:W},children:e.jsx(Sn,{messages:G,loading:Z,connected:fe,status:x,onSend:As,onAbort:Fe,width:W,sessionTitle:S.isNewChat?"新对话":S.activeSessionTitle,onNewSession:S.pluginName?()=>S.startNewChat():void 0,todoItems:h,onClearTodos:Ps,toolLimitReached:ae,onContinueTools:Ds,toolCallsProgress:M,tokenUsage:ke,compressingStatus:Ae,onCompress:Rs})}),(z||ue)&&e.jsx("div",{className:"restart-overlay",children:e.jsxs("div",{className:"restart-dialog",children:[e.jsx("div",{className:"restart-spinner"}),e.jsx("h3",{children:ue?"切换前端":"正在重启…"}),e.jsx("p",{className:"restart-desc",children:ye})]})})]})}qs.createRoot(document.getElementById("root")).render(e.jsx(Dn,{}));export{os as B,Ct as C,_t as D,Et as F,Me as M,Ie as R,qt as S,De as T,ss as W,ys as X,he as _,Q as a,it as b,H as c,Te as d,$e as e,gs as f,Ft as g,It as h,Jt as i,de as p};