xiaozhi-client 1.9.2 → 1.9.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +4 -4
  2. package/apps/frontend/dist/assets/form-utils-h64o2Nyg.js +2 -0
  3. package/apps/frontend/dist/assets/form-utils-h64o2Nyg.js.map +1 -0
  4. package/apps/frontend/dist/assets/index-88NfCOo9.js +50 -0
  5. package/apps/frontend/dist/assets/index-88NfCOo9.js.map +1 -0
  6. package/apps/frontend/dist/assets/index-P6Zq3MZF.css +1 -0
  7. package/apps/frontend/dist/assets/radix-ui-BA32w1ww.js.map +1 -1
  8. package/apps/frontend/dist/assets/react-vendor-DrjkXih1.js +319 -0
  9. package/apps/frontend/dist/assets/react-vendor-DrjkXih1.js.map +1 -0
  10. package/apps/frontend/dist/assets/utils-CiPelQLP.js +2 -0
  11. package/apps/frontend/dist/assets/utils-CiPelQLP.js.map +1 -0
  12. package/apps/frontend/dist/assets/{vendor-DvFnRBMT.js → vendor-DK9yaMt3.js} +2 -2
  13. package/apps/frontend/dist/assets/vendor-DK9yaMt3.js.map +1 -0
  14. package/apps/frontend/dist/index.html +6 -6
  15. package/dist/WebServerStandalone.js +16 -21
  16. package/dist/WebServerStandalone.js.map +1 -1
  17. package/dist/cli.js +17 -25
  18. package/dist/cli.js.map +1 -1
  19. package/dist/mcpServerProxy.d.ts +1 -1
  20. package/dist/mcpServerProxy.js +13 -13
  21. package/dist/mcpServerProxy.js.map +1 -1
  22. package/dist/package.json +25 -18
  23. package/docs/arch/{cache.md → cache.mdx} +62 -95
  24. package/docs/changelog.mdx +617 -0
  25. package/docs/development/docker-build.mdx +256 -0
  26. package/docs/development/todo__release-guide.md +5 -5
  27. package/docs/docs.json +6 -1
  28. package/docs/python-dependencies.md +2 -2
  29. package/docs/usage/docker.mdx +4 -4
  30. package/package.json +25 -18
  31. package/apps/frontend/dist/assets/form-utils-wyhL6gg0.js +0 -24
  32. package/apps/frontend/dist/assets/form-utils-wyhL6gg0.js.map +0 -1
  33. package/apps/frontend/dist/assets/index-COfJftUA.css +0 -1
  34. package/apps/frontend/dist/assets/index-ukaaLbQN.js +0 -50
  35. package/apps/frontend/dist/assets/index-ukaaLbQN.js.map +0 -1
  36. package/apps/frontend/dist/assets/react-vendor-B6Uf_8Kw.js +0 -319
  37. package/apps/frontend/dist/assets/react-vendor-B6Uf_8Kw.js.map +0 -1
  38. package/apps/frontend/dist/assets/utils-D0kRQKVW.js +0 -2
  39. package/apps/frontend/dist/assets/utils-D0kRQKVW.js.map +0 -1
  40. package/apps/frontend/dist/assets/vendor-DvFnRBMT.js.map +0 -1
  41. package/dist/templates/docker/mcpServers/calculator.js +0 -106
  42. package/dist/templates/docker/mcpServers/datetime.js +0 -390
  43. package/dist/templates/docker/package.json +0 -13
  44. package/dist/templates/docker/requirements.txt +0 -16
  45. package/dist/templates/docker/xiaozhi.config.json +0 -21
  46. package/templates/docker/mcpServers/calculator.js +0 -106
  47. package/templates/docker/mcpServers/datetime.js +0 -390
  48. package/templates/docker/package.json +0 -13
  49. package/templates/docker/requirements.txt +0 -16
  50. package/templates/docker/xiaozhi.config.json +0 -21
@@ -0,0 +1,50 @@
1
+ var _r=Object.defineProperty;var Ur=(r,t,s)=>t in r?_r(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s;var q=(r,t,s)=>Ur(r,typeof t!="symbol"?t+"":t,s);import{c as Bt,d as Ht,r as o,t as k,j as e,S as ke,R as gs,O as bt,P as bs,C as wt,a as Jt,X as ws,b as jt,D as vt,e as js,f as vs,h as Vr,i as qr,k as Fr,l as Br,u as Hr,L as Ns,m as Jr,n as Ge,o as ys,p as Kr,q as Ss,s as Cs,v as ks,A as Es,w as Ts,x as Gr,y as Zr,B as Qr,E as Ps,F as ge,W as os,G as is,H as Nt,I as Ms,J as Yr,K as Le,M as Rs,N as Is,Q as Os,U as Xr,V as it,Y as ea,Z as Kt,_ as ht,$ as Gt,a0 as pt,a1 as Ze,a2 as Ds,a3 as ta,a4 as sa,a5 as Me,a6 as Ae,a7 as _e,a8 as zs,a9 as ra,aa as $s,ab as aa,ac as Zt,ad as Ws,ae as Ls,af as As,ag as na,ah as _s,ai as oa,aj as Us,ak as Vs,al as ia,am as ca,an as qs,ao as la,ap as da,aq as Fs,ar as Bs,as as qe,at as ua,au as ma,av as He,aw as fa,ax as Qt,ay as Hs,az as ha,aA as pa,aB as cs,aC as ls,aD as xa,aE as ds,aF as Js,aG as ga,aH as ba,aI as wa,aJ as ja,aK as va,aL as Na,aM as Dt,aN as ya,aO as Sa,aP as Ca,aQ as ka}from"./react-vendor-DrjkXih1.js";import{t as Ea,c as Ks,a as Ue,T as Ta}from"./utils-CiPelQLP.js";import{z as G,o as yt,b as Gs,e as Zs,s as xt,c as Lt,d as ct,r as Pa,n as Ma}from"./form-utils-h64o2Nyg.js";import{m as Ra}from"./vendor-DK9yaMt3.js";import"./radix-ui-BA32w1ww.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))a(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&a(c)}).observe(document,{childList:!0,subtree:!0});function s(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function a(n){if(n.ep)return;n.ep=!0;const i=s(n);fetch(n.href,i)}})();class Ia{constructor(t){q(this,"baseUrl");if(t)this.baseUrl=t;else{const s=window.location.protocol,a=window.location.hostname,n=window.location.port;this.baseUrl=`${s}//${a}${n?`:${n}`:""}`}}async request(t,s={}){var c;const a=`${this.baseUrl}${t}`,n={headers:{"Content-Type":"application/json",...s.headers}},i=await fetch(a,{...n,...s});if(!i.ok){let m=`HTTP ${i.status}: ${i.statusText}`;try{m=((c=(await i.json()).error)==null?void 0:c.message)||m}catch{}throw new Error(m)}return i.json()}async getConfig(){const t=await this.request("/api/config");if(!t.success||!t.data)throw new Error("获取配置失败");return t.data}async updateConfig(t){const s=await this.request("/api/config",{method:"PUT",body:JSON.stringify(t)});if(!s.success)throw new Error(s.message||"配置更新失败")}async getMcpEndpoint(){const t=await this.request("/api/config/mcp-endpoint");if(!t.success||!t.data)throw new Error("获取 MCP 端点失败");return t.data.endpoint}async getMcpEndpoints(){const t=await this.request("/api/config/mcp-endpoints");if(!t.success||!t.data)throw new Error("获取 MCP 端点列表失败");return t.data.endpoints}async getMcpServers(){const t=await this.request("/api/config/mcp-servers");if(!t.success||!t.data)throw new Error("获取 MCP 服务配置失败");return t.data.servers}async getConnectionConfig(){const t=await this.request("/api/config/connection");if(!t.success||!t.data)throw new Error("获取连接配置失败");return t.data.connection}async reloadConfig(){const t=await this.request("/api/config/reload",{method:"POST"});if(!t.success||!t.data)throw new Error("重新加载配置失败");return t.data}async getConfigPath(){const t=await this.request("/api/config/path");if(!t.success||!t.data)throw new Error("获取配置文件路径失败");return t.data.path}async checkConfigExists(){var s;const t=await this.request("/api/config/exists");if(!t.success||((s=t.data)==null?void 0:s.exists)===void 0)throw new Error("检查配置是否存在失败");return t.data.exists}async getStatus(){const t=await this.request("/api/status");if(!t.success||!t.data)throw new Error("获取状态失败");return t.data}async getClientStatus(){const t=await this.request("/api/status/client");if(!t.success||!t.data)throw new Error("获取客户端状态失败");return t.data}async getRestartStatus(){const t=await this.request("/api/status/restart");if(!t.success)throw new Error("获取重启状态失败");return t.data||null}async checkClientConnected(){var s;const t=await this.request("/api/status/connected");if(!t.success||((s=t.data)==null?void 0:s.connected)===void 0)throw new Error("检查客户端连接失败");return t.data.connected}async getLastHeartbeat(){var s;const t=await this.request("/api/status/heartbeat");if(!t.success)throw new Error("获取最后心跳时间失败");return((s=t.data)==null?void 0:s.lastHeartbeat)||null}async getActiveMCPServers(){const t=await this.request("/api/status/mcp-servers");if(!t.success||!t.data)throw new Error("获取活跃 MCP 服务器失败");return t.data.servers}async updateClientStatus(t){const s=await this.request("/api/status/client",{method:"PUT",body:JSON.stringify(t)});if(!s.success)throw new Error(s.message||"更新客户端状态失败")}async setActiveMCPServers(t){const s=await this.request("/api/status/mcp-servers",{method:"PUT",body:JSON.stringify({servers:t})});if(!s.success)throw new Error(s.message||"设置活跃 MCP 服务器失败")}async resetStatus(){const t=await this.request("/api/status/reset",{method:"POST"});if(!t.success)throw new Error(t.message||"重置状态失败")}async addCustomTool(t,s,a,n){if(typeof t=="object"&&"type"in t&&"data"in t){const m=await this.request("/api/tools/custom",{method:"POST",body:JSON.stringify(t)});if(!m.success||!m.data)throw new Error(m.message||"添加自定义工具失败");return m.data.tool}const i=t,c=await this.request("/api/tools/custom",{method:"POST",body:JSON.stringify({workflow:i,customName:s,customDescription:a,parameterConfig:n})});if(!c.success||!c.data)throw new Error(c.message||"添加自定义工具失败");return c.data.tool}async updateCustomTool(t,s){const a=await this.request(`/api/tools/custom/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(s)});if(!a.success||!a.data)throw new Error(a.message||"更新自定义工具失败");return a.data.tool}async removeCustomTool(t){const s=await this.request(`/api/tools/custom/${encodeURIComponent(t)}`,{method:"DELETE"});if(!s.success)throw new Error(s.message||"删除自定义工具失败")}async getCustomTools(){const t=await this.request("/api/tools/custom");if(!t.success||!t.data)throw new Error("获取自定义工具列表失败");return t.data.tools}async getToolsList(t="all"){const s=new URLSearchParams;t!=="all"&&s.append("status",t);const a=`/api/tools/list${s.toString()?`?${s.toString()}`:""}`,n=await this.request(a);if(!n.success||!n.data)throw new Error("获取工具列表失败");return n.data.list}async restartService(){const t=await this.request("/api/services/restart",{method:"POST"});if(!t.success)throw new Error(t.message||"重启服务失败")}async stopService(){const t=await this.request("/api/services/stop",{method:"POST"});if(!t.success)throw new Error(t.message||"停止服务失败")}async startService(){const t=await this.request("/api/services/start",{method:"POST"});if(!t.success)throw new Error(t.message||"启动服务失败")}async getServiceStatus(){const t=await this.request("/api/services/status");if(!t.success||!t.data)throw new Error("获取服务状态失败");return t.data}async getServiceHealth(){const t=await this.request("/api/services/health");if(!t.success||!t.data)throw new Error("获取服务健康状态失败");return t.data}async getVersion(){const t=await this.request("/api/version");if(!t.success||!t.data)throw new Error("获取版本信息失败");return t.data}async getVersionSimple(){const t=await this.request("/api/version/simple");if(!t.success||!t.data)throw new Error("获取版本号失败");return t.data}async getAvailableVersions(t="stable"){const s=new URLSearchParams;t!=="stable"&&s.append("type",t);const a=`/api/version/available${s.toString()?`?${s.toString()}`:""}`,n=await this.request(a);if(!n.success||!n.data)throw new Error("获取可用版本列表失败");return n.data}async getLatestVersion(){const t=await this.request("/api/version/latest");if(!t.success||!t.data)throw new Error("检查最新版本失败");return t.data}async clearVersionCache(){const t=await this.request("/api/version/cache/clear",{method:"POST"});if(!t.success)throw new Error(t.message||"清除版本缓存失败")}async updateVersion(t){const s=await this.request("/api/update",{method:"POST",body:JSON.stringify({version:t})});if(!s.success)throw new Error(s.message||"版本更新失败");return s.data}async getEndpointStatus(t){const s=await this.request("/api/endpoint/status",{method:"POST",body:JSON.stringify({endpoint:t})});if(!s.success||!s.data)throw new Error("获取接入点状态失败");return s.data}async connectEndpoint(t){const s=await this.request("/api/endpoint/connect",{method:"POST",body:JSON.stringify({endpoint:t})});if(!s.success)throw new Error(s.message||"连接接入点失败")}async disconnectEndpoint(t){const s=await this.request("/api/endpoint/disconnect",{method:"POST",body:JSON.stringify({endpoint:t})});if(!s.success)throw new Error(s.message||"断开接入点失败")}async reconnectEndpoint(t){const s=await this.request("/api/endpoint/reconnect",{method:"POST",body:JSON.stringify({endpoint:t})});if(!s.success)throw new Error(s.message||"重连接入点失败")}async addEndpoint(t){const s=await this.request("/api/endpoint/add",{method:"POST",body:JSON.stringify({endpoint:t})});if(!s.success||!s.data)throw new Error(s.message||"添加接入点失败");return s.data}async removeEndpoint(t){const s=await this.request("/api/endpoint/remove",{method:"POST",body:JSON.stringify({endpoint:t})});if(!s.success)throw new Error(s.message||"移除接入点失败")}async addMCPServer(t,s){const a={name:t,config:s},n=await this.request("/api/mcp-servers",{method:"POST",body:JSON.stringify(a)});if(!n.success||!n.data)throw new Error(n.message||"添加 MCP 服务器失败");return n.data}async removeMCPServer(t){const s=await this.request(`/api/mcp-servers/${encodeURIComponent(t)}`,{method:"DELETE"});if(!s.success||!s.data)throw new Error(s.message||"删除 MCP 服务器失败");return s.data}async getMCPServerStatus(t){const s=await this.request(`/api/mcp-servers/${encodeURIComponent(t)}/status`);if(!s.success||!s.data)throw new Error(s.message||"获取 MCP 服务器状态失败");return s.data}async listMCPServers(){const t=await this.request("/api/mcp-servers");if(!t.success||!t.data)throw new Error(t.message||"获取 MCP 服务器列表失败");return t.data}async checkMCPServerExists(t){var s;try{const a=await this.request(`/api/mcp-servers/${encodeURIComponent(t)}/exists`);return a.success&&((s=a.data)==null?void 0:s.exists)||!1}catch(a){if(a instanceof Error&&a.message.includes("404"))return!1;throw a}}async updateMCPServer(t,s){const a=await this.request(`/api/mcp-servers/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify({config:s})});if(!a.success||!a.data)throw new Error(a.message||"更新 MCP 服务器配置失败");return a.data}async callTool(t,s,a={}){const n=await this.request("/api/tools/call",{method:"POST",body:JSON.stringify({serviceName:t,toolName:s,args:a})});if(!n.success)throw new Error(n.message||"调用工具失败");return n.data}async restartMCPServer(t){const s=await this.request(`/api/mcp-servers/${encodeURIComponent(t)}/restart`,{method:"POST"});if(!s.success||!s.data)throw new Error(s.message||"重启 MCP 服务器失败");return s.data}}const D=new Ia,At={addServer:async(r,t)=>await D.addMCPServer(r,t),removeServer:async r=>await D.removeMCPServer(r),listServers:async()=>await D.listMCPServers(),getServerStatus:async r=>await D.getMCPServerStatus(r),serverExists:async r=>await D.checkMCPServerExists(r),updateServer:async(r,t)=>await D.updateMCPServer(r,t),restartServer:async r=>await D.restartMCPServer(r)};var se=(r=>(r.DISCONNECTED="disconnected",r.CONNECTING="connecting",r.CONNECTED="connected",r.RECONNECTING="reconnecting",r))(se||{});class Oa{constructor(){q(this,"listeners",new Map)}on(t,s){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(s),()=>{this.off(t,s)}}off(t,s){const a=this.listeners.get(t);a&&(a.delete(s),a.size===0&&this.listeners.delete(t))}emit(t,s){const a=this.listeners.get(t);if(a)for(const n of a)try{n(s)}catch(i){console.error(`[EventBus] 事件监听器执行失败 (${t}):`,i)}}clear(){this.listeners.clear()}getListenerCount(t){var s;return t?((s=this.listeners.get(t))==null?void 0:s.size)||0:Array.from(this.listeners.values()).reduce((a,n)=>a+n.size,0)}}const K=class K{constructor(t={}){q(this,"ws",null);q(this,"url");q(this,"state","disconnected");q(this,"eventBus",new Oa);q(this,"reconnectAttempts",0);q(this,"maxReconnectAttempts");q(this,"reconnectInterval");q(this,"reconnectTimer");q(this,"heartbeatTimer");q(this,"heartbeatInterval");q(this,"heartbeatTimeout");q(this,"lastHeartbeat",0);this.url=t.url||this.getDefaultWebSocketUrl(),this.maxReconnectAttempts=t.maxReconnectAttempts||5,this.reconnectInterval=t.reconnectInterval||3e3,this.heartbeatInterval=t.heartbeatInterval||3e4,this.heartbeatTimeout=t.heartbeatTimeout||35e3}static getInstance(t){if(K.instance)return K.instance;if(K.isCreating)throw new Error("[WebSocketManager] 检测到循环创建,请检查代码逻辑");K.isCreating=!0;try{return K.instance=new K(t),console.log("[WebSocketManager] 单例实例已创建"),K.instance}finally{K.isCreating=!1}}static resetInstance(){K.instance&&(K.instance.disconnect(),K.instance.eventBus.clear(),K.instance=null,console.log("[WebSocketManager] 单例实例已重置"))}getDefaultWebSocketUrl(){const t=localStorage.getItem("xiaozhi-ws-url");if(t)return t;const s=window.location.protocol==="https:"?"wss:":"ws:",a=window.location.hostname,n=window.location.port==="5173"?9999:window.location.port;return`${s}//${a}${n?`:${n}`:""}`}connect(){if(!(this.state==="connected"||this.state==="connecting")){this.state="connecting",console.log(`[WebSocket] 连接到: ${this.url}`),this.eventBus.emit("connection:connecting",void 0);try{this.ws=new WebSocket(this.url),this.setupEventHandlers()}catch(t){console.error("[WebSocket] 连接失败:",t),this.handleConnectionError(t)}}}disconnect(){console.log("[WebSocket] 主动断开连接"),this.clearTimers(),this.state="disconnected",this.reconnectAttempts=0,this.ws&&(this.ws.close(),this.ws=null)}subscribe(t,s){return this.eventBus.on(t,s)}unsubscribe(t,s){this.eventBus.off(t,s)}getEventBus(){return this.eventBus}getState(){return this.state}isConnected(){var t;return this.state==="connected"&&((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN}setUrl(t){this.url!==t&&(this.url=t,localStorage.setItem("xiaozhi-ws-url",t),this.isConnected()&&(this.disconnect(),setTimeout(()=>this.connect(),1e3)))}send(t){if(!this.isConnected())return console.warn("[WebSocket] 连接未建立,无法发送消息"),!1;try{const s=typeof t=="string"?t:JSON.stringify(t);return this.ws.send(s),!0}catch(s){return console.error("[WebSocket] 发送消息失败:",s),this.eventBus.emit("connection:error",{error:s,context:"send_message"}),!1}}getUrl(){return this.url}getConnectionStats(){return{state:this.state,url:this.url,reconnectAttempts:this.reconnectAttempts,maxReconnectAttempts:this.maxReconnectAttempts,lastHeartbeat:this.lastHeartbeat,eventListenerCount:this.eventBus.getListenerCount()}}setupEventHandlers(){this.ws&&(this.ws.onopen=()=>{console.log("[WebSocket] 连接已建立"),this.state="connected",this.reconnectAttempts=0,this.startHeartbeat(),this.eventBus.emit("connection:connected",void 0)},this.ws.onmessage=t=>{try{const s=JSON.parse(t.data);this.handleMessage(s)}catch(s){console.error("[WebSocket] 消息解析失败:",s)}},this.ws.onclose=t=>{console.log(`[WebSocket] 连接已关闭 (code: ${t.code})`),this.handleConnectionClose()},this.ws.onerror=t=>{console.error("[WebSocket] 连接错误:",t),this.handleConnectionError(new Error("WebSocket 连接错误"))})}handleMessage(t){var s;console.log("[WebSocket] 收到消息:",t.type),this.eventBus.emit("system:message",t);try{switch(t.type){case"configUpdate":case"config":t.data&&this.eventBus.emit("data:configUpdate",t.data);break;case"statusUpdate":case"status":t.data&&this.eventBus.emit("data:statusUpdate",t.data);break;case"restartStatus":t.data&&this.eventBus.emit("data:restartStatus",t.data);break;case"endpoint_status_changed":t.data&&this.eventBus.emit("data:endpointStatusChanged",t.data);break;case"npm:install:started":t.data&&this.eventBus.emit("data:npmInstallStarted",t.data);break;case"npm:install:log":t.data&&this.eventBus.emit("data:npmInstallLog",t.data);break;case"npm:install:completed":t.data&&this.eventBus.emit("data:npmInstallCompleted",t.data);break;case"npm:install:failed":t.data&&this.eventBus.emit("data:npmInstallFailed",t.data);break;case"heartbeatResponse":this.lastHeartbeat=Date.now(),this.eventBus.emit("system:heartbeat",{timestamp:this.lastHeartbeat});break;case"error":{const a=new Error(((s=t.error)==null?void 0:s.message)||"服务器错误");console.error("[WebSocket] 服务器错误:",t.error),this.eventBus.emit("system:error",{error:a,message:t}),this.eventBus.emit("connection:error",{error:a,context:"server_error"});break}default:console.log("[WebSocket] 未处理的消息类型:",t.type)}}catch(a){console.error("[WebSocket] 消息处理失败:",a),this.eventBus.emit("system:error",{error:a,message:t})}}handleConnectionClose(){this.state="disconnected",this.clearTimers(),this.eventBus.emit("connection:disconnected",void 0),this.reconnectAttempts<this.maxReconnectAttempts?this.scheduleReconnect():(console.error("[WebSocket] 达到最大重连次数,停止重连"),this.eventBus.emit("connection:error",{error:new Error("达到最大重连次数"),context:"max_reconnect_attempts"}))}handleConnectionError(t){this.state="disconnected",this.clearTimers(),this.eventBus.emit("connection:error",{error:t,context:"connection_error"}),this.reconnectAttempts<this.maxReconnectAttempts?this.scheduleReconnect():console.error("[WebSocket] 达到最大重连次数,停止重连")}scheduleReconnect(){this.reconnectAttempts++,this.state="reconnecting",console.log(`[WebSocket] 安排重连 (${this.reconnectAttempts}/${this.maxReconnectAttempts}) 在 ${this.reconnectInterval}ms 后`),this.eventBus.emit("connection:reconnecting",{attempt:this.reconnectAttempts,maxAttempts:this.maxReconnectAttempts}),this.reconnectTimer=setTimeout(()=>{this.connect()},this.reconnectInterval)}startHeartbeat(){this.lastHeartbeat=Date.now(),this.heartbeatTimer=setInterval(()=>{this.isConnected()&&(this.sendHeartbeat(),Date.now()-this.lastHeartbeat>this.heartbeatTimeout&&(console.warn("[WebSocket] 心跳超时,重新连接"),this.disconnect(),this.connect()))},this.heartbeatInterval)}sendHeartbeat(){var t;if(this.isConnected()){const s={type:"clientStatus",data:{status:"connected",timestamp:Date.now()}};(t=this.ws)==null||t.send(JSON.stringify(s))}}clearTimers(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=void 0),this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=void 0)}};q(K,"instance",null),q(K,"isCreating",!1);let _t=K;const W=_t.getInstance(),us={clientStatus:null,restartStatus:null,serviceStatus:null,serviceHealth:null,fullStatus:null,loading:{isLoading:!1,isRefreshing:!1,isRestarting:!1,lastUpdated:null,lastError:null},polling:{enabled:!1,interval:3e4,maxRetries:3,currentRetries:0},restartPolling:{enabled:!1,interval:1e3,maxAttempts:60,currentAttempts:0,timeout:6e4,startTime:null},lastSource:null};let lt=null,dt=null;const pe=Bt()(Ht((r,t)=>({...us,setClientStatus:(s,a="http")=>{console.log(`[StatusStore] 设置客户端状态,来源: ${a}`),r(n=>({clientStatus:s,lastSource:a,loading:{...n.loading,lastUpdated:Date.now(),lastError:null}}),!1,"setClientStatus")},setRestartStatus:(s,a="http")=>{console.log(`[StatusStore] 设置重启状态,来源: ${a}`),r(n=>({restartStatus:s,lastSource:a,loading:{...n.loading,lastUpdated:Date.now(),lastError:null}}),!1,"setRestartStatus")},setServiceStatus:s=>{console.log("[StatusStore] 设置服务状态"),r({serviceStatus:s},!1,"setServiceStatus")},setServiceHealth:s=>{console.log("[StatusStore] 设置服务健康状态"),r({serviceHealth:s},!1,"setServiceHealth")},setFullStatus:(s,a="http")=>{console.log(`[StatusStore] 设置完整状态,来源: ${a}`),r(n=>({fullStatus:s,clientStatus:s.client,restartStatus:s.restart||null,lastSource:a,loading:{...n.loading,lastUpdated:Date.now(),lastError:null}}),!1,"setFullStatus")},setLoading:s=>{r(a=>({loading:{...a.loading,...s}}),!1,"setLoading")},setError:s=>{r(a=>({loading:{...a.loading,lastError:s}}),!1,"setError")},getStatus:async()=>{const{fullStatus:s,loading:a}=t();return s&&a.lastUpdated&&Date.now()-a.lastUpdated<30*1e3?s:t().refreshStatus()},refreshStatus:async()=>{const{setLoading:s,setFullStatus:a,setError:n,polling:i}=t();try{s({isRefreshing:!0,lastError:null}),console.log("[StatusStore] 开始刷新状态");const c=await D.getStatus();return a(c,"http"),i.enabled&&t().setPollingConfig({currentRetries:0}),console.log("[StatusStore] 状态刷新成功"),c}catch(c){const m=c instanceof Error?c:new Error("状态刷新失败");if(console.error("[StatusStore] 状态刷新失败:",m),n(m),i.enabled){const b=i.currentRetries+1;t().setPollingConfig({currentRetries:b}),b>=i.maxRetries&&(console.warn("[StatusStore] 达到最大重试次数,停止轮询"),t().stopPolling())}throw m}finally{s({isRefreshing:!1})}},restartService:async()=>{const{setLoading:s,setRestartStatus:a,setError:n,startRestartPolling:i}=t();try{s({isRestarting:!0,lastError:null}),console.log("[StatusStore] 开始重启服务"),a({status:"restarting",timestamp:Date.now()},"http"),await D.restartService(),console.log("[StatusStore] 服务重启请求已发送,开始重连检查"),i()}catch(c){const m=c instanceof Error?c:new Error("服务重启失败");throw console.error("[StatusStore] 服务重启失败:",m),a({status:"failed",error:m.message,timestamp:Date.now()},"http"),n(m),s({isRestarting:!1}),m}},getServiceStatus:async()=>{try{console.log("[StatusStore] 获取服务状态");const s=await D.getServiceStatus();return t().setServiceStatus(s),s}catch(s){const a=s instanceof Error?s:new Error("获取服务状态失败");throw console.error("[StatusStore] 获取服务状态失败:",a),t().setError(a),a}},getServiceHealth:async()=>{try{console.log("[StatusStore] 获取服务健康状态");const s=await D.getServiceHealth();return t().setServiceHealth(s),s}catch(s){const a=s instanceof Error?s:new Error("获取服务健康状态失败");throw console.error("[StatusStore] 获取服务健康状态失败:",a),t().setError(a),a}},startPolling:(s=3e4)=>{const{polling:a,refreshStatus:n}=t();if(a.enabled){console.log("[StatusStore] 轮询已启用,跳过启动");return}console.log(`[StatusStore] 启动状态轮询,间隔: ${s}ms`),r(i=>({polling:{...i.polling,enabled:!0,interval:s,currentRetries:0}}),!1,"startPolling"),n().catch(i=>{console.error("[StatusStore] 轮询初始刷新失败:",i)}),lt=setInterval(()=>{t().polling.enabled&&n().catch(c=>{console.error("[StatusStore] 轮询刷新失败:",c)})},s)},stopPolling:()=>{console.log("[StatusStore] 停止状态轮询"),r(s=>({polling:{...s.polling,enabled:!1,currentRetries:0}}),!1,"stopPolling"),lt&&(clearInterval(lt),lt=null)},setPollingConfig:s=>{r(a=>({polling:{...a.polling,...s}}),!1,"setPollingConfig")},startRestartPolling:()=>{const{restartPolling:s,refreshStatus:a,setRestartStatus:n,setLoading:i}=t();if(s.enabled){console.log("[StatusStore] 重启轮询已启用,跳过启动");return}console.log("[StatusStore] 启动重启后重连检查轮询");const c=Date.now();r(m=>({restartPolling:{...m.restartPolling,enabled:!0,currentAttempts:0,startTime:c}}),!1,"startRestartPolling"),dt=setInterval(async()=>{var p;const m=t(),{restartPolling:b}=m;if(!b.enabled)return;const g=Date.now()-(b.startTime||0),h=b.currentAttempts+1;console.log(`[StatusStore] 重启重连检查 (第 ${h} 次,已用时 ${Math.round(g/1e3)}s)`);try{if(((p=(await a()).client)==null?void 0:p.status)==="connected"){console.log("[StatusStore] 服务重连成功,停止重启轮询"),n({status:"completed",timestamp:Date.now()},"polling"),m.stopRestartPolling(),i({isRestarting:!1});return}m.setRestartPollingConfig({currentAttempts:h}),(g>=b.timeout||h>=b.maxAttempts)&&(console.warn("[StatusStore] 重启重连检查超时或达到最大尝试次数"),n({status:"failed",error:"重连超时,服务可能未成功重启",timestamp:Date.now()},"polling"),m.stopRestartPolling(),i({isRestarting:!1}))}catch(d){console.log(`[StatusStore] 重启重连检查失败 (第 ${h} 次):`,d),m.setRestartPollingConfig({currentAttempts:h}),(g>=b.timeout||h>=b.maxAttempts)&&(console.error("[StatusStore] 重启重连检查超时或达到最大尝试次数"),n({status:"failed",error:"重连超时,服务可能未成功重启",timestamp:Date.now()},"polling"),m.stopRestartPolling(),i({isRestarting:!1}))}},s.interval)},stopRestartPolling:()=>{console.log("[StatusStore] 停止重启轮询"),r(s=>({restartPolling:{...s.restartPolling,enabled:!1,currentAttempts:0,startTime:null}}),!1,"stopRestartPolling"),dt&&(clearInterval(dt),dt=null)},setRestartPollingConfig:s=>{r(a=>({restartPolling:{...a.restartPolling,...s}}),!1,"setRestartPollingConfig")},reset:()=>{console.log("[StatusStore] 重置状态"),t().stopPolling(),t().stopRestartPolling(),r(us,!1,"reset")},initialize:async()=>{const{setLoading:s,refreshStatus:a}=t();try{s({isLoading:!0}),console.log("[StatusStore] 初始化状态 Store"),W.subscribe("data:statusUpdate",n=>{console.log("[StatusStore] 收到 WebSocket 状态更新"),t().setClientStatus(n,"websocket")}),W.subscribe("data:restartStatus",n=>{console.log("[StatusStore] 收到 WebSocket 重启状态更新"),t().setRestartStatus(n,"websocket")}),await a(),console.log("[StatusStore] 状态 Store 初始化完成")}catch(n){throw console.error("[StatusStore] 状态 Store 初始化失败:",n),n}finally{s({isLoading:!1})}}}),{name:"status-store"})),Da=()=>pe(r=>r.restartStatus),Qs=()=>pe(r=>r.restartPolling);function za(){const r=Da(),t=Qs(),s=o.useRef(null),a=o.useRef(null);o.useEffect(()=>{if(!r)return;const{status:n,timestamp:i,error:c}=r;if(!(s.current===n&&a.current===i))switch(s.current=n,a.current=i,n){case"restarting":k.info("正在重启服务...",{id:"restart-status-progress",description:"请耐心等待",duration:0});break;case"completed":{const m=t.enabled?`服务重启成功!重连检查完成 (${t.currentAttempts}次检查)`:"服务重启成功!";k.dismiss("restart-status-progress"),k.success(m,{id:"restart-status-success",description:"服务已恢复正常运行"});break}case"failed":{const m=c||"服务重启失败",b=t.enabled?`重连检查超时 (${t.currentAttempts}/${t.maxAttempts}次)`:"请检查服务状态或稍后重试";k.dismiss("restart-status-progress"),k.error(m,{id:"restart-status-failed",description:b});break}}},[r,t]),o.useEffect(()=>()=>{s.current=null,a.current=null},[])}function $a(){return za(),null}function w(...r){return Ea(Ks(r))}const Yt=Ue("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),E=o.forwardRef(({className:r,variant:t,size:s,asChild:a=!1,...n},i)=>{const c=a?ke:"button";return e.jsx(c,{className:w(Yt({variant:t,size:s,className:r})),ref:i,...n})});E.displayName="Button";const re=o.forwardRef(({className:r,type:t,...s},a)=>e.jsx("input",{type:t,className:w("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),ref:a,"data-1p-ignore":!0,...s}));re.displayName="Input";const St=o.forwardRef(({className:r,orientation:t="horizontal",decorative:s=!0,...a},n)=>e.jsx(gs,{ref:n,decorative:s,orientation:t,className:w("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",r),...a}));St.displayName=gs.displayName;const Wa=js,La=bs,Ys=o.forwardRef(({className:r,...t},s)=>e.jsx(bt,{className:w("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),...t,ref:s}));Ys.displayName=bt.displayName;const Aa=Ue("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Xs=o.forwardRef(({side:r="right",className:t,children:s,...a},n)=>e.jsxs(La,{children:[e.jsx(Ys,{}),e.jsxs(wt,{ref:n,className:w(Aa({side:r}),t),...a,children:[s,e.jsxs(Jt,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[e.jsx(ws,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Xs.displayName=wt.displayName;const er=({className:r,...t})=>e.jsx("div",{className:w("flex flex-col space-y-2 text-center sm:text-left",r),...t});er.displayName="SheetHeader";const tr=o.forwardRef(({className:r,...t},s)=>e.jsx(jt,{ref:s,className:w("text-lg font-semibold text-foreground",r),...t}));tr.displayName=jt.displayName;const sr=o.forwardRef(({className:r,...t},s)=>e.jsx(vt,{ref:s,className:w("text-sm text-muted-foreground",r),...t}));sr.displayName=vt.displayName;function Oe({className:r,...t}){return e.jsx("div",{className:w("animate-pulse rounded-md bg-muted",r),...t})}const Xt=Vr,Ct=qr,kt=Fr,Qe=o.forwardRef(({className:r,sideOffset:t=4,...s},a)=>e.jsx(vs,{ref:a,sideOffset:t,className:w("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",r),...s}));Qe.displayName=vs.displayName;const zt=768;function _a(){const[r,t]=o.useState(void 0);return o.useEffect(()=>{const s=window.matchMedia(`(max-width: ${zt-1}px)`),a=()=>{t(window.innerWidth<zt)};return s.addEventListener("change",a),t(window.innerWidth<zt),()=>s.removeEventListener("change",a)},[]),!!r}const Ua="sidebar_state",Va=3600*24*7,qa="16rem",Fa="18rem",Ba="3rem",Ha="b",rr=o.createContext(null);function Et(){const r=o.useContext(rr);if(!r)throw new Error("useSidebar must be used within a SidebarProvider.");return r}const es=o.forwardRef(({defaultOpen:r=!0,open:t,onOpenChange:s,className:a,style:n,children:i,...c},m)=>{const b=_a(),[g,h]=o.useState(!1),[p,d]=o.useState(r),u=t??p,f=o.useCallback(O=>{const P=typeof O=="function"?O(u):O;s?s(P):d(P),document.cookie=`${Ua}=${P}; path=/; max-age=${Va}`},[s,u]),C=o.useCallback(()=>b?h(O=>!O):f(O=>!O),[b,f]);o.useEffect(()=>{const O=P=>{P.key===Ha&&(P.metaKey||P.ctrlKey)&&(P.preventDefault(),C())};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[C]);const y=u?"expanded":"collapsed",v=o.useMemo(()=>({state:y,open:u,setOpen:f,isMobile:b,openMobile:g,setOpenMobile:h,toggleSidebar:C}),[y,u,f,b,g,C]);return e.jsx(rr.Provider,{value:v,children:e.jsx(Xt,{delayDuration:0,children:e.jsx("div",{style:{"--sidebar-width":qa,"--sidebar-width-icon":Ba,...n},className:w("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",a),ref:m,...c,children:i})})})});es.displayName="SidebarProvider";const ar=o.forwardRef(({side:r="left",variant:t="sidebar",collapsible:s="offcanvas",className:a,children:n,...i},c)=>{const{isMobile:m,state:b,openMobile:g,setOpenMobile:h}=Et();return s==="none"?e.jsx("div",{className:w("flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",a),ref:c,...i,children:n}):m?e.jsx(Wa,{open:g,onOpenChange:h,...i,children:e.jsxs(Xs,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":Fa},side:r,children:[e.jsxs(er,{className:"sr-only",children:[e.jsx(tr,{children:"Sidebar"}),e.jsx(sr,{children:"Displays the mobile sidebar."})]}),e.jsx("div",{className:"flex h-full w-full flex-col",children:n})]})}):e.jsxs("div",{ref:c,className:"group peer hidden text-sidebar-foreground md:block","data-state":b,"data-collapsible":b==="collapsed"?s:"","data-variant":t,"data-side":r,children:[e.jsx("div",{className:w("relative w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),e.jsx("div",{className:w("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",r==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",a),...i,children:e.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:n})})]})});ar.displayName="Sidebar";const nr=o.forwardRef(({className:r,onClick:t,...s},a)=>{const{toggleSidebar:n}=Et();return e.jsxs(E,{ref:a,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:w("h-7 w-7",r),onClick:i=>{t==null||t(i),n()},...s,children:[e.jsx(Br,{}),e.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});nr.displayName="SidebarTrigger";const Ja=o.forwardRef(({className:r,...t},s)=>{const{toggleSidebar:a}=Et();return e.jsx("button",{ref:s,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:a,title:"Toggle Sidebar",className:w("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",r),...t})});Ja.displayName="SidebarRail";const ts=o.forwardRef(({className:r,...t},s)=>e.jsx("main",{ref:s,className:w("relative flex w-full flex-1 flex-col bg-background","md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",r),...t}));ts.displayName="SidebarInset";const Ka=o.forwardRef(({className:r,...t},s)=>e.jsx(re,{ref:s,"data-sidebar":"input",className:w("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",r),...t}));Ka.displayName="SidebarInput";const or=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,"data-sidebar":"header",className:w("flex flex-col gap-2 p-2",r),...t}));or.displayName="SidebarHeader";const Ga=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,"data-sidebar":"footer",className:w("flex flex-col gap-2 p-2",r),...t}));Ga.displayName="SidebarFooter";const Za=o.forwardRef(({className:r,...t},s)=>e.jsx(St,{ref:s,"data-sidebar":"separator",className:w("mx-2 w-auto bg-sidebar-border",r),...t}));Za.displayName="SidebarSeparator";const ir=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,"data-sidebar":"content",className:w("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",r),...t}));ir.displayName="SidebarContent";const cr=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,"data-sidebar":"group",className:w("relative flex w-full min-w-0 flex-col p-2",r),...t}));cr.displayName="SidebarGroup";const Qa=o.forwardRef(({className:r,asChild:t=!1,...s},a)=>{const n=t?ke:"div";return e.jsx(n,{ref:a,"data-sidebar":"group-label",className:w("flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",r),...s})});Qa.displayName="SidebarGroupLabel";const Ya=o.forwardRef(({className:r,asChild:t=!1,...s},a)=>{const n=t?ke:"button";return e.jsx(n,{ref:a,"data-sidebar":"group-action",className:w("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",r),...s})});Ya.displayName="SidebarGroupAction";const lr=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,"data-sidebar":"group-content",className:w("w-full text-sm",r),...t}));lr.displayName="SidebarGroupContent";const ss=o.forwardRef(({className:r,...t},s)=>e.jsx("ul",{ref:s,"data-sidebar":"menu",className:w("flex w-full min-w-0 flex-col gap-1",r),...t}));ss.displayName="SidebarMenu";const rs=o.forwardRef(({className:r,...t},s)=>e.jsx("li",{ref:s,"data-sidebar":"menu-item",className:w("group/menu-item relative",r),...t}));rs.displayName="SidebarMenuItem";const Xa=Ue("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),as=o.forwardRef(({asChild:r=!1,isActive:t=!1,variant:s="default",size:a="default",tooltip:n,className:i,...c},m)=>{const b=r?ke:"button",{isMobile:g,state:h}=Et(),p=e.jsx(b,{ref:m,"data-sidebar":"menu-button","data-size":a,"data-active":t,className:w(Xa({variant:s,size:a}),i),...c});return n?(typeof n=="string"&&(n={children:n}),e.jsxs(Ct,{children:[e.jsx(kt,{asChild:!0,children:p}),e.jsx(Qe,{side:"right",align:"center",hidden:h!=="collapsed"||g,...n})]})):p});as.displayName="SidebarMenuButton";const en=o.forwardRef(({className:r,asChild:t=!1,showOnHover:s=!1,...a},n)=>{const i=t?ke:"button";return e.jsx(i,{ref:n,"data-sidebar":"menu-action",className:w("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",s&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",r),...a})});en.displayName="SidebarMenuAction";const tn=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,"data-sidebar":"menu-badge",className:w("pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",r),...t}));tn.displayName="SidebarMenuBadge";const sn=o.forwardRef(({className:r,showIcon:t=!1,...s},a)=>{const n=o.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return e.jsxs("div",{ref:a,"data-sidebar":"menu-skeleton",className:w("flex h-8 items-center gap-2 rounded-md px-2",r),...s,children:[t&&e.jsx(Oe,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),e.jsx(Oe,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":n}})]})});sn.displayName="SidebarMenuSkeleton";const rn=o.forwardRef(({className:r,...t},s)=>e.jsx("ul",{ref:s,"data-sidebar":"menu-sub",className:w("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",r),...t}));rn.displayName="SidebarMenuSub";const an=o.forwardRef(({...r},t)=>e.jsx("li",{ref:t,...r}));an.displayName="SidebarMenuSubItem";const nn=o.forwardRef(({asChild:r=!1,size:t="md",isActive:s,className:a,...n},i)=>{const c=r?ke:"a";return e.jsx(c,{ref:i,"data-sidebar":"menu-sub-button","data-size":t,"data-active":s,className:w("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",a),...n})});nn.displayName="SidebarMenuSubButton";function on({items:r}){const t=Hr();return e.jsx(cr,{children:e.jsx(lr,{className:"flex flex-col gap-2",children:e.jsx(ss,{children:r.map(s=>{const n=t.pathname===s.url;return e.jsx(rs,{children:e.jsx(as,{className:w("min-w-8 duration-200 ease-linear hover:bg-primary/5",n?"bg-primary text-primary-foreground duration-200 ease-linear hover:bg-primary/90 hover:text-primary-foreground active:bg-primary/90 active:text-primary-foreground":"min-w-8 duration-200 ease-linear"),tooltip:s.title,asChild:!0,children:e.jsxs(Ns,{to:s.url,children:[s.icon&&e.jsx(s.icon,{}),e.jsx("span",{children:s.title})]})})},s.title)})})})})}const cn={navMain:[{title:"仪表板",url:"/dashboard",icon:Jr},{title:"全局配置",url:"/settings",icon:Ge}]};function dr({...r}){return e.jsxs(ar,{collapsible:"offcanvas",...r,children:[e.jsx(or,{children:e.jsx(ss,{children:e.jsx(rs,{children:e.jsx(as,{asChild:!0,className:"data-[slot=sidebar-menu-button]:!p-1.5",children:e.jsx(Ns,{to:"/",className:"flex items-center gap-2",children:e.jsx("span",{className:"text-base font-semibold",children:"Xiaozhi Client"})})})})})}),e.jsx(ir,{children:e.jsx(on,{items:cn.navMain})})]})}const ln=Ue("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function te({className:r,variant:t,...s}){return e.jsx("div",{className:w(ln({variant:t}),r),...s})}const Tt=Gr,dn=Zr,un=Kr,ur=o.forwardRef(({className:r,...t},s)=>e.jsx(ys,{className:w("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),...t,ref:s}));ur.displayName=ys.displayName;const Ye=o.forwardRef(({className:r,...t},s)=>e.jsxs(un,{children:[e.jsx(ur,{}),e.jsx(Ss,{ref:s,className:w("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",r),...t})]}));Ye.displayName=Ss.displayName;const Xe=({className:r,...t})=>e.jsx("div",{className:w("flex flex-col space-y-2 text-center sm:text-left",r),...t});Xe.displayName="AlertDialogHeader";const et=({className:r,...t})=>e.jsx("div",{className:w("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",r),...t});et.displayName="AlertDialogFooter";const tt=o.forwardRef(({className:r,...t},s)=>e.jsx(Cs,{ref:s,className:w("text-lg font-semibold",r),...t}));tt.displayName=Cs.displayName;const st=o.forwardRef(({className:r,...t},s)=>e.jsx(ks,{ref:s,className:w("text-sm text-muted-foreground",r),...t}));st.displayName=ks.displayName;const rt=o.forwardRef(({className:r,...t},s)=>e.jsx(Es,{ref:s,className:w(Yt(),r),...t}));rt.displayName=Es.displayName;const at=o.forwardRef(({className:r,...t},s)=>e.jsx(Ts,{ref:s,className:w(Yt({variant:"outline"}),"mt-2 sm:mt-0",r),...t}));at.displayName=Ts.displayName;const ue=js,Ee=Qr,mn=bs,Pt=Jt,mr=o.forwardRef(({className:r,...t},s)=>e.jsx(bt,{ref:s,className:w("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",r),...t}));mr.displayName=bt.displayName;const ie=o.forwardRef(({className:r,children:t,...s},a)=>e.jsxs(mn,{children:[e.jsx(mr,{}),e.jsxs(wt,{ref:a,className:w("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",r),...s,children:[t,e.jsxs(Jt,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(ws,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ie.displayName=wt.displayName;const ce=({className:r,...t})=>e.jsx("div",{className:w("flex flex-col space-y-1.5 text-center sm:text-left",r),...t});ce.displayName="DialogHeader";const Te=({className:r,...t})=>e.jsx("div",{className:w("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",r),...t});Te.displayName="DialogFooter";const le=o.forwardRef(({className:r,...t},s)=>e.jsx(jt,{ref:s,className:w("text-lg font-semibold leading-none tracking-tight",r),...t}));le.displayName=jt.displayName;const ve=o.forwardRef(({className:r,...t},s)=>e.jsx(vt,{ref:s,className:w("text-sm text-muted-foreground",r),...t}));ve.displayName=vt.displayName;const ms={config:null,loading:{isLoading:!1,isUpdating:!1,isRefreshing:!1,lastUpdated:null,lastError:null},lastSource:null},he=Bt()(Ht((r,t)=>({...ms,setConfig:(s,a="http")=>{console.log(`[ConfigStore] 设置配置数据,来源: ${a}`),r(n=>({config:s,lastSource:a,loading:{...n.loading,lastUpdated:Date.now(),lastError:null}}),!1,"setConfig")},setLoading:s=>{r(a=>({loading:{...a.loading,...s}}),!1,"setLoading")},setError:s=>{r(a=>({loading:{...a.loading,lastError:s}}),!1,"setError")},getConfig:async()=>{const{config:s,loading:a}=t();return s&&a.lastUpdated&&Date.now()-a.lastUpdated<300*1e3?s:t().refreshConfig()},updateConfig:async s=>{const{setLoading:a,setConfig:n,setError:i}=t();try{a({isUpdating:!0,lastError:null}),console.log("[ConfigStore] 开始更新配置"),await D.updateConfig(s),n(s,"http"),console.log("[ConfigStore] 配置更新成功")}catch(c){const m=c instanceof Error?c:new Error("配置更新失败");throw console.error("[ConfigStore] 配置更新失败:",m),i(m),m}finally{a({isUpdating:!1})}},refreshConfig:async()=>{const{setLoading:s,setConfig:a,setError:n}=t();try{s({isRefreshing:!0,lastError:null}),console.log("[ConfigStore] 开始刷新配置");const i=await D.getConfig();return a(i,"http"),console.log("[ConfigStore] 配置刷新成功"),i}catch(i){const c=i instanceof Error?i:new Error("配置刷新失败");throw console.error("[ConfigStore] 配置刷新失败:",c),n(c),c}finally{s({isRefreshing:!1})}},reloadConfig:async()=>{const{setLoading:s,setConfig:a,setError:n}=t();try{s({isRefreshing:!0,lastError:null}),console.log("[ConfigStore] 开始重新加载配置");const i=await D.reloadConfig();return a(i,"http"),console.log("[ConfigStore] 配置重新加载成功"),i}catch(i){const c=i instanceof Error?i:new Error("配置重新加载失败");throw console.error("[ConfigStore] 配置重新加载失败:",c),n(c),c}finally{s({isRefreshing:!1})}},updateMcpEndpoint:async s=>{const{config:a,updateConfig:n}=t();if(!a)throw new Error("配置未加载,无法更新 MCP 端点");const i={...a,mcpEndpoint:s};await n(i)},updateMcpServers:async s=>{const{config:a,updateConfig:n}=t();if(!a)throw new Error("配置未加载,无法更新 MCP 服务");const i={...a,mcpServers:s};await n(i)},updateConnectionConfig:async s=>{const{config:a,updateConfig:n}=t();if(!a)throw new Error("配置未加载,无法更新连接配置");const i={...a,connection:s};await n(i)},updateModelScopeConfig:async s=>{const{config:a,updateConfig:n}=t();if(!a)throw new Error("配置未加载,无法更新 ModelScope 配置");const i={...a,modelscope:s};await n(i)},updateWebUIConfig:async s=>{const{config:a,updateConfig:n}=t();if(!a)throw new Error("配置未加载,无法更新 Web UI 配置");const i={...a,webUI:s};await n(i)},reset:()=>{console.log("[ConfigStore] 重置状态"),r(ms,!1,"reset")},initialize:async()=>{const{setLoading:s,refreshConfig:a}=t();try{s({isLoading:!0}),console.log("[ConfigStore] 初始化配置 Store"),W.subscribe("data:configUpdate",n=>{console.log("[ConfigStore] 收到 WebSocket 配置更新"),t().setConfig(n,"websocket")}),await a(),console.log("[ConfigStore] 配置 Store 初始化完成")}catch(n){throw console.error("[ConfigStore] 配置 Store 初始化失败:",n),n}finally{s({isLoading:!1})}}}),{name:"config-store"})),nt=()=>he(r=>r.config),fr=()=>he(r=>{var t;return(t=r.config)==null?void 0:t.mcpEndpoint}),hr=()=>he(r=>{var t;return(t=r.config)==null?void 0:t.mcpServers}),fn=()=>he(r=>{var t;return(t=r.config)==null?void 0:t.mcpServerConfig}),pr=()=>he(Ps(r=>({getConfig:r.getConfig,updateConfig:r.updateConfig,refreshConfig:r.refreshConfig,reloadConfig:r.reloadConfig,updateMcpEndpoint:r.updateMcpEndpoint,updateMcpServers:r.updateMcpServers,updateConnectionConfig:r.updateConnectionConfig,updateModelScopeConfig:r.updateModelScopeConfig,updateWebUIConfig:r.updateWebUIConfig,reset:r.reset,initialize:r.initialize}))),fs=r=>`${r.slice(0,30)}...${r.slice(-10)}`,hn=r=>{if(!r.trim())return"请输入接入点地址";if(!r.startsWith("ws://")&&!r.startsWith("wss://"))return"接入点格式无效,请输入正确的WebSocket URL (ws:// 或 wss://)";try{new URL(r)}catch{return"接入点格式无效,请输入正确的URL格式"}return null};function pn(){const[r,t]=o.useState(!1),[s,a]=o.useState(!1),[n,i]=o.useState(""),[c,m]=o.useState(!1),[b,g]=o.useState(!1),[h,p]=o.useState(""),[d,u]=o.useState(!1),[f,C]=o.useState(""),[y,v]=o.useState({}),O=nt(),P=fr(),{refreshConfig:$}=pr(),S=o.useCallback(async x=>{try{return await D.getEndpointStatus(x)}catch(j){return console.error(`获取接入点状态失败: ${x}`,j),{endpoint:x,connected:!1,initialized:!1,isReconnecting:!1,reconnectAttempts:0,reconnectDelay:0}}},[]),R=o.useCallback((x,j)=>{v(N=>({...N,[x]:{...N[x],...j}}))},[]),A=o.useCallback(async x=>{const j={};for(const N of x)try{const T=await S(N);j[N]={connected:T.connected,isOperating:!1,lastOperation:{type:null,success:!1,message:"",timestamp:0}}}catch{j[N]={connected:!1,isOperating:!1,lastOperation:{type:null,success:!1,message:"",timestamp:0}}}v(j)},[S]),V=async x=>{R(x,{isOperating:!0});try{await D.connectEndpoint(x),R(x,{connected:!0,isOperating:!1,lastOperation:{type:"connect",success:!0,message:"连接成功",timestamp:Date.now()}}),k.success("接入点连接成功")}catch(j){R(x,{isOperating:!1,lastOperation:{type:"connect",success:!1,message:j instanceof Error?j.message:"连接失败",timestamp:Date.now()}}),k.error(j instanceof Error?j.message:"接入点连接失败")}},Q=async x=>{R(x,{isOperating:!0});try{await D.disconnectEndpoint(x),R(x,{connected:!1,isOperating:!1,lastOperation:{type:"disconnect",success:!0,message:"断开成功",timestamp:Date.now()}}),k.success("接入点断开成功")}catch(j){R(x,{isOperating:!1,lastOperation:{type:"disconnect",success:!1,message:j instanceof Error?j.message:"断开失败",timestamp:Date.now()}}),k.error(j instanceof Error?j.message:"接入点断开失败")}},me=async x=>{var j;try{if((j=navigator.clipboard)!=null&&j.writeText)await navigator.clipboard.writeText(x),k.success("接入点地址已复制到剪贴板");else{const N=document.createElement("textarea");N.value=x,N.style.position="fixed",N.style.opacity="0",document.body.appendChild(N),N.select();const T=document.execCommand("copy");if(document.body.removeChild(N),T)k.success("接入点地址已复制到剪贴板");else throw new Error("复制命令执行失败")}}catch(N){console.error("复制失败:",N),k.error("复制失败,请手动复制")}},fe=async()=>{m(!0);try{await D.removeEndpoint(n),await $(),v(x=>{const j={...x};return delete j[n],j}),k.success("接入点已删除"),a(!1),i("")}catch(x){console.error("删除接入点失败:",x),k.error(x instanceof Error?x.message:"删除接入点失败")}finally{m(!1)}},I=async()=>{const x=hn(h);if(x){C(x);return}if((Array.isArray(P)?P:[P]).includes(h)){C("该接入点已存在");return}if(!O){k.error("配置数据未加载,请稍后重试");return}u(!0);try{const N=await D.addEndpoint(h);await $(),v(T=>({...T,[h]:{connected:N.connected,isOperating:!1,lastOperation:{type:null,success:!1,message:"",timestamp:0}}})),k.success("接入点添加成功"),g(!1),p(""),C("")}catch(N){console.error("添加接入点失败:",N),k.error(N instanceof Error?N.message:"添加接入点失败")}finally{u(!1)}},L=()=>{p(""),C(""),g(!0)},_=x=>{p(x),f&&C("")},J=x=>{i(x),a(!0)},l=o.useMemo(()=>{let x=[];return Array.isArray(P)&&(x=P),typeof P=="string"&&P.length&&x.push(P),x},[P]);return o.useEffect(()=>{r&&l.length>0&&A(l)},[r,l,A]),o.useEffect(()=>{if(!r||l.length===0)return;const x=l.map(j=>W.subscribe("data:endpointStatusChanged",T=>{T.endpoint===j&&(console.log(`[McpEndpointSettingButton] 接收到端点 ${j} 状态变更:`,T),R(j,{connected:T.connected,isOperating:!1,lastOperation:{type:T.operation,success:T.success,message:T.message||(T.connected?"连接成功":"断开成功"),timestamp:T.timestamp}}),T.success?k.success(`端点 ${T.operation==="connect"?"连接":T.operation==="disconnect"?"断开":"重连"}成功`):k.error(`端点 ${T.operation==="connect"?"连接":T.operation==="disconnect"?"断开":"重连"}失败: ${T.message||"未知错误"}`))}));return()=>{for(const j of x)j()}},[r,l,R]),e.jsxs(ue,{open:r,onOpenChange:t,children:[e.jsx(Ee,{asChild:!0,children:e.jsx(E,{variant:"secondary",size:"icon",className:"size-8",children:e.jsx(Ge,{className:"size-4"})})}),e.jsxs(ie,{className:"min-w-[600px] max-w-[800px] max-h-[80vh] overflow-y-auto",children:[e.jsxs(ce,{className:"mb-4",children:[e.jsx(le,{children:"配置小智服务端接入点"}),e.jsx(ve,{children:"点击保存后,需要重启服务才会生效。"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[l.map(x=>{const j=y[x],N=(j==null?void 0:j.connected)||!1,T=(j==null?void 0:j.isOperating)||!1;return e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between p-4 bg-slate-50 rounded-md font-mono gap-3 transition-all duration-200 hover:bg-slate-100",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center gap-2 sm:gap-3 flex-1 min-w-0",children:[e.jsx("span",{className:"flex-1 text-ellipsis overflow-hidden whitespace-nowrap text-sm sm:text-base",children:fs(x)}),e.jsxs(te,{className:`flex items-center gap-1 transition-all duration-200 text-xs sm:text-sm ${N?"bg-green-100 text-green-800 border-green-200 hover:text-green-800 hover:border-green-200 hover:bg-green-100":"bg-gray-100 text-gray-600 border-gray-200 hover:bg-gray-100 hover:text-gray-600 hover:border-gray-200"}`,children:[T?e.jsx(ge,{className:"size-3 animate-spin"}):N?e.jsx(os,{className:"size-3"}):e.jsx(is,{className:"size-3"}),T?"操作中":N?"已连接":"未连接"]})]}),e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 flex-wrap justify-end",children:[e.jsx(E,{variant:"outline",size:"icon",onClick:()=>me(x),title:"复制完整地址",className:"transition-all duration-200 hover:scale-105",children:e.jsx(Nt,{className:"size-4"})}),N?e.jsx(E,{variant:"outline",size:"icon",onClick:()=>Q(x),title:"断开连接",disabled:T,className:"text-red-600 hover:text-red-700 hover:bg-red-50 transition-all duration-200 hover:scale-105 disabled:scale-100 disabled:opacity-50",children:T?e.jsx(ge,{className:"size-4 animate-spin"}):e.jsx(is,{className:"size-4"})}):e.jsx(E,{variant:"outline",size:"icon",onClick:()=>V(x),title:"连接",disabled:T,className:"text-green-600 hover:text-green-700 hover:bg-green-50 transition-all duration-200 hover:scale-105 disabled:scale-100 disabled:opacity-50",children:T?e.jsx(ge,{className:"size-4 animate-spin"}):e.jsx(os,{className:"size-4"})}),e.jsx(E,{variant:"outline",size:"icon",onClick:()=>J(x),title:"删除此接入点",className:"transition-all duration-200 hover:scale-105 hover:text-red-600",children:e.jsx(Ms,{className:"size-4 text-red-500"})})]})]},x)}),l.length===0&&e.jsxs("div",{className:"flex flex-col items-center flex-1 text-sm text-muted-foreground text-center justify-center gap-2",children:[e.jsx(Yr,{}),e.jsx("span",{children:"暂无接入点,请添加"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center gap-2 mt-4",children:[e.jsxs(E,{className:"flex-1 flex items-center gap-2",onClick:L,children:[e.jsx(Le,{className:"size-4"}),e.jsx("span",{className:"text-sm sm:text-base",children:"添加小智服务端接入点"})]}),e.jsx(E,{variant:"outline",className:"flex-1 flex items-center gap-2",onClick:()=>window.open("https://xiaozhi.me/console/agents","_blank"),children:e.jsx("span",{className:"text-sm sm:text-base",children:"打开小智服务端"})})]})]})]}),e.jsx(Tt,{open:s,onOpenChange:a,children:e.jsxs(Ye,{children:[e.jsxs(Xe,{children:[e.jsx(tt,{children:"确认删除接入点"}),e.jsxs(st,{children:['确定要删除接入点 "',fs(n),'" 吗?此操作无法撤销。']})]}),e.jsxs(et,{children:[e.jsx(at,{disabled:c,children:"取消"}),e.jsx(rt,{onClick:fe,disabled:c,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:c?"删除中...":"确定删除"})]})]})}),e.jsx(ue,{open:b,onOpenChange:g,children:e.jsxs(ie,{className:"sm:max-w-[500px]",children:[e.jsxs(ce,{children:[e.jsx(le,{children:"添加新的接入点"}),e.jsx(ve,{children:"请输入小智服务端接入点地址"})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(re,{placeholder:"请输入接入点地址,例如:wss://api.xiaozhi.me/mcp/?token=... 或 ws(s)://<hostname>:<port>",value:h,onChange:x=>_(x.target.value),disabled:d,className:"font-mono text-sm"}),f&&e.jsx("p",{className:"text-sm text-red-500",children:f})]})}),e.jsxs(Te,{children:[e.jsx(Pt,{asChild:!0,children:e.jsx(E,{variant:"outline",disabled:d,children:"取消"})}),e.jsx(E,{onClick:I,disabled:d||!h.trim(),children:d?"添加中...":"确定"})]})]})})]})}const de=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("rounded-lg border bg-card text-card-foreground shadow-sm",r),...t}));de.displayName="Card";const De=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("flex flex-col space-y-1.5 p-6",r),...t}));De.displayName="CardHeader";const ze=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("text-2xl font-semibold leading-none tracking-tight",r),...t}));ze.displayName="CardTitle";const Fe=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("text-sm text-muted-foreground",r),...t}));Fe.displayName="CardDescription";const ye=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("p-6 pt-0",r),...t}));ye.displayName="CardContent";const Be=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("flex items-center p-6 pt-0",r),...t}));Be.displayName="CardFooter";const be=o.forwardRef(({className:r,children:t,...s},a)=>e.jsx("div",{ref:a,className:w("relative overflow-auto",r),...s,children:t}));be.displayName="ScrollArea";const xn=o.forwardRef(({className:r,orientation:t="vertical",...s},a)=>e.jsx("div",{ref:a,className:w("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 w-full border-t border-t-transparent p-[1px]",r),...s,children:e.jsx("div",{className:"relative flex-1 rounded-full bg-border"})}));xn.displayName="ScrollBar";const xr=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:s,className:w("w-full caption-bottom text-sm",r),...t})}));xr.displayName="Table";const gr=o.forwardRef(({className:r,...t},s)=>e.jsx("thead",{ref:s,className:w("[&_tr]:border-b",r),...t}));gr.displayName="TableHeader";const br=o.forwardRef(({className:r,...t},s)=>e.jsx("tbody",{ref:s,className:w("[&_tr:last-child]:border-0",r),...t}));br.displayName="TableBody";const gn=o.forwardRef(({className:r,...t},s)=>e.jsx("tfoot",{ref:s,className:w("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",r),...t}));gn.displayName="TableFooter";const Ut=o.forwardRef(({className:r,...t},s)=>e.jsx("tr",{ref:s,className:w("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",r),...t}));Ut.displayName="TableRow";const Re=o.forwardRef(({className:r,...t},s)=>e.jsx("th",{ref:s,className:w("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",r),...t}));Re.displayName="TableHead";const Ie=o.forwardRef(({className:r,...t},s)=>e.jsx("td",{ref:s,className:w("p-4 align-middle [&:has([role=checkbox])]:pr-0",r),...t}));Ie.displayName="TableCell";const bn=o.forwardRef(({className:r,...t},s)=>e.jsx("caption",{ref:s,className:w("mt-4 text-sm text-muted-foreground",r),...t}));bn.displayName="TableCaption";const gt=Xr,Mt=o.forwardRef(({className:r,...t},s)=>e.jsx(Rs,{ref:s,className:w("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",r),...t}));Mt.displayName=Rs.displayName;const we=o.forwardRef(({className:r,...t},s)=>e.jsx(Is,{ref:s,className:w("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",r),...t}));we.displayName=Is.displayName;const je=o.forwardRef(({className:r,...t},s)=>e.jsx(Os,{ref:s,className:w("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",r),...t}));je.displayName=Os.displayName;const wr=r=>r?new Date(r).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}):"未知时间",jr=r=>r?r<1e3?`${r}ms`:`${(r/1e3).toFixed(1)}s`:"-",wn=(r,t)=>{const s=r.timestamp||Date.now();return`${r.toolName}-${s}-${t}`},ut=r=>{if(!r)return null;try{return JSON.stringify(r,null,2)}catch{return String(r)}};function jn(){const[r,t]=o.useState(!1),[s,a]=o.useState([]),[n,i]=o.useState(!1),[c,m]=o.useState(!1),[b,g]=o.useState(null),[h,p]=o.useState(null),[d,u]=o.useState(null),[f]=o.useState(50),[C,y]=o.useState(0),v=o.useCallback(async(S=!1)=>{var R;S?m(!0):i(!0),g(null);try{await new Promise(Q=>setTimeout(Q,1e3));const V=await(await fetch(`/api/tool-calls/logs?limit=${f}`)).json();V.success&&V.data?(a(V.data.records),y(V.data.total)):g(((R=V.error)==null?void 0:R.message)||"获取日志失败")}catch(A){g("网络请求失败"),console.error("Failed to fetch tool call logs:",A)}finally{S?m(!1):i(!1)}},[f]);o.useEffect(()=>{r?v():(p(null),u(null))},[r,v]);const O=(S,R)=>{d!==R&&(p(S),u(R))},P=()=>{},$=()=>{p(null),u(null)};return e.jsxs(ue,{open:r,onOpenChange:t,children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(E,{variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(it,{className:"h-4 w-4"}),"调用日志"]})}),e.jsxs(ie,{className:"max-w-6xl max-h-[80vh]",onMouseLeave:$,children:[e.jsx(ce,{children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs(le,{className:"flex items-center gap-2",children:[e.jsx(it,{className:"h-5 w-5"}),"MCP 工具调用日志",C>0&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground ml-2",children:["(共 ",C," 条记录)"]}),e.jsxs(E,{variant:"ghost",size:"sm",onClick:()=>v(!0),disabled:c,children:[e.jsx(ea,{className:`h-4 w-4 ${c?"animate-spin":""}`}),"刷新"]})]})})}),e.jsxs("div",{className:"flex-1 flex gap-4",children:[e.jsx("div",{className:"flex-1",children:n?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ge,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(it,{className:"h-4 w-4 text-muted-foreground/50"})})]}),e.jsxs("div",{className:"mt-4 text-center",children:[e.jsx("p",{className:"text-muted-foreground font-medium",children:"正在加载日志数据"}),e.jsx("p",{className:"text-muted-foreground/70 text-sm mt-1",children:"请稍候片刻..."})]})]}):b?e.jsx("div",{className:"text-center py-8",children:e.jsxs("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-6 max-w-md mx-auto",children:[e.jsx(Kt,{className:"h-12 w-12 text-destructive mx-auto mb-4"}),e.jsx("h3",{className:"text-destructive font-semibold text-lg mb-2",children:"加载失败"}),e.jsx("p",{className:"text-muted-foreground text-sm mb-4 leading-relaxed",children:b}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs(E,{onClick:()=>v(),variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ht,{className:"h-4 w-4"}),"重试加载"]}),e.jsx(E,{onClick:()=>v(!0),variant:"ghost",size:"sm",className:"text-xs",children:"强制刷新"})]})]})}):s.length===0?e.jsx("div",{className:"text-center py-8",children:e.jsxs("div",{className:"bg-muted/30 border border-muted rounded-lg p-6 max-w-md mx-auto",children:[e.jsx(it,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"font-medium text-lg mb-2",children:"暂无工具调用记录"}),e.jsx("p",{className:"text-muted-foreground text-sm leading-relaxed mb-4",children:"当前还没有任何工具调用记录。当您开始使用工具时,相关的调用信息会在这里显示。"}),e.jsxs(E,{onClick:()=>v(!0),variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(ht,{className:"h-4 w-4"}),"检查更新"]})]})}):e.jsx(be,{className:"h-[60vh]",children:e.jsxs(xr,{children:[e.jsx(gr,{children:e.jsxs(Ut,{children:[e.jsx(Re,{children:"工具名称"}),e.jsx(Re,{children:"服务器"}),e.jsx(Re,{children:"状态"}),e.jsx(Re,{children:"耗时"}),e.jsx(Re,{children:"时间"})]})}),e.jsx(br,{children:s.map((S,R)=>e.jsxs(Ut,{className:`cursor-pointer transition-colors ${d===R?"bg-muted/50":"hover:bg-muted/30"}`,onMouseEnter:()=>O(S,R),children:[e.jsx(Ie,{className:"font-medium",children:e.jsxs("div",{children:[e.jsx("div",{children:S.toolName}),S.originalToolName&&S.originalToolName!==S.toolName&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["原始: ",S.originalToolName]})]})}),e.jsx(Ie,{children:S.serverName||e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx(Ie,{children:e.jsx(te,{variant:S.success?void 0:"destructive",className:`gap-1 w-[50px] text-center ${S.success?"bg-green-600 hover:bg-green-600":"bg-red-600 hover:bg-red-600"}`,children:S.success?"成功":"失败"})}),e.jsx(Ie,{children:jr(S.duration)}),e.jsx(Ie,{className:"text-muted-foreground text-sm",children:wr(S.timestamp)})]},wn(S,R)))})]})})}),h&&e.jsx("div",{className:"w-96 border-l pl-4",onMouseEnter:P,children:e.jsx(vn,{log:h})})]})]})]})}function mt({size:r="sm",copyContent:t,className:s=""}){const[a,n]=o.useState(!1),i=async()=>{try{await navigator.clipboard.writeText(t),n(!0),setTimeout(()=>{n(!1)},3e3)}catch(c){console.error("复制失败:",c)}};return e.jsx(E,{variant:"ghost",size:r,className:`${s} ${a?"text-green-600 hover:text-green-700":""}`,onClick:i,children:a?e.jsx(Ze,{}):e.jsx(Nt,{})})}function vn({log:r}){const t=s=>{try{return JSON.stringify(s,null,2)}catch{return String(s)}};return e.jsx(de,{className:"h-[60vh]",children:e.jsxs("div",{className:"p-4 h-full flex flex-col",children:[e.jsxs(gt,{defaultValue:"arguments",className:"flex-1 flex flex-col min-h-0",children:[e.jsxs(Mt,{className:"grid w-full grid-cols-3 flex-shrink-0",children:[e.jsx(we,{value:"arguments",children:"入参"}),e.jsx(we,{value:"result",children:"出参"}),e.jsx(we,{value:"raw",children:"原始数据"})]}),e.jsxs("div",{className:"flex-1 min-h-0",children:[e.jsx(je,{value:"arguments",className:"h-full data-[state=active]:flex data-[state=active]:flex-col",children:e.jsx(be,{className:"h-full",children:r.arguments?e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"text-xs bg-muted p-3 rounded-md overflow-x-auto text-wrap break-words",children:ut(r.arguments)}),e.jsx(mt,{copyContent:ut(r.arguments)||"",className:"absolute top-2 right-2 hover:bg-slate-200 w-[30px] h-[30px]"})]}):e.jsxs("div",{className:"text-center text-muted-foreground py-8",children:[e.jsx(Gt,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"无入参"})]})})}),e.jsx(je,{value:"result",className:"h-full data-[state=active]:flex data-[state=active]:flex-col",children:e.jsx(be,{className:"h-full",children:r.success?r.result?e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"text-xs bg-muted p-3 rounded-md overflow-x-auto text-wrap break-words",children:ut(r.result)}),e.jsx(mt,{copyContent:ut(r.result)||"",className:"absolute top-2 right-2 hover:bg-slate-200 w-[30px] h-[30px]"})]}):e.jsxs("div",{className:"text-center text-muted-foreground py-8",children:[e.jsx(pt,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"无出参"})]}):e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"bg-destructive/10 border border-destructive/20 p-3 rounded-md",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(Kt,{className:"h-4 w-4 text-destructive"}),e.jsx("span",{className:"font-medium text-destructive",children:"调用失败"})]}),r.error&&e.jsx("pre",{className:"text-xs text-destructive/80 whitespace-pre-wrap",children:r.error})]}),r.error&&e.jsx(mt,{copyContent:r.error||"",className:"absolute top-2 right-2"})]})})}),e.jsx(je,{value:"raw",className:"h-full data-[state=active]:flex data-[state=active]:flex-col",children:e.jsx(be,{className:"h-full",children:e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"text-xs bg-muted p-3 rounded-md overflow-x-auto text-wrap break-words",children:t(r)}),e.jsx(mt,{copyContent:t(r),className:"absolute top-2 right-2 hover:bg-slate-200 w-[30px] h-[30px]"})]})})})]})]}),e.jsx(St,{className:"my-4 flex-shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground flex justify-between flex-shrink-0",children:[e.jsxs("span",{children:["耗时: ",jr(r.duration)]}),e.jsx("span",{children:wr(r.timestamp)})]})]})})}const Nn=Ue("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),vr=o.forwardRef(({className:r,...t},s)=>e.jsx(Ds,{ref:s,className:w(Nn(),r),...t}));vr.displayName=Ds.displayName;const Ve=sa,Nr=o.createContext({}),ee=({...r})=>e.jsx(Nr.Provider,{value:{name:r.name},children:e.jsx(Me,{...r})}),Rt=()=>{const r=o.useContext(Nr),t=o.useContext(yr),{getFieldState:s,formState:a}=ta(),n=s(r.name,a);if(!r)throw new Error("useFormField should be used within <FormField>");const{id:i}=t;return{id:i,name:r.name,formItemId:`${i}-form-item`,formDescriptionId:`${i}-form-item-description`,formMessageId:`${i}-form-item-message`,...n}},yr=o.createContext({}),Z=o.forwardRef(({className:r,...t},s)=>{const a=o.useId();return e.jsx(yr.Provider,{value:{id:a},children:e.jsx("div",{ref:s,className:w("space-y-2",r),...t})})});Z.displayName="FormItem";const ne=o.forwardRef(({className:r,...t},s)=>{const{error:a,formItemId:n}=Rt();return e.jsx(vr,{ref:s,className:w(a&&"text-destructive",r),htmlFor:n,...t})});ne.displayName="FormLabel";const H=o.forwardRef(({...r},t)=>{const{error:s,formItemId:a,formDescriptionId:n,formMessageId:i}=Rt();return e.jsx(ke,{ref:t,id:a,"aria-describedby":s?`${n} ${i}`:`${n}`,"aria-invalid":!!s,...r})});H.displayName="FormControl";const Sr=o.forwardRef(({className:r,...t},s)=>{const{formDescriptionId:a}=Rt();return e.jsx("p",{ref:s,id:a,className:w("text-sm text-muted-foreground",r),...t})});Sr.displayName="FormDescription";const ae=o.forwardRef(({className:r,children:t,...s},a)=>{const{error:n,formMessageId:i}=Rt(),c=n?String((n==null?void 0:n.message)??""):t;return c?e.jsx("p",{ref:a,id:i,className:w("text-sm font-medium text-destructive",r),...s,children:c}):null});ae.displayName="FormMessage";class yn{constructor(t){q(this,"baseUrl");if(t)this.baseUrl=t;else{const s=window.location.protocol,a=window.location.hostname,n=window.location.port;this.baseUrl=`${s}//${a}${n?`:${n}`:""}`}}async request(t,s={}){var c;const a=`${this.baseUrl}${t}`,n={headers:{"Content-Type":"application/json",...s.headers}},i=await fetch(a,{...n,...s});if(!i.ok){let m=`HTTP ${i.status}: ${i.statusText}`;try{m=((c=(await i.json()).error)==null?void 0:c.message)||m}catch{}throw new Error(m)}return i.json()}async fetchWorkspaces(){try{const t=await this.request("/api/coze/workspaces");if(!t.success||!t.data)throw new Error(t.message||"获取工作空间列表失败");return t.data}catch(t){throw console.error("获取工作空间列表失败:",t),t}}async fetchWorkflows(t){try{const s=new URLSearchParams;s.append("workspace_id",t.workspace_id),t.page_num!==void 0&&s.append("page_num",t.page_num.toString()),t.page_size!==void 0&&s.append("page_size",t.page_size.toString());const a=await this.request(`/api/coze/workflows?${s.toString()}`);if(!a.success||!a.data)throw new Error(a.message||"获取工作流列表失败");return a.data}catch(s){throw console.error("获取工作流列表失败:",s),s}}async clearCache(){try{const t=await this.request("/api/coze/cache/clear",{method:"POST"});if(!t.success)throw new Error(t.message||"清除缓存失败")}catch(t){throw console.error("清除缓存失败:",t),t}}async getCacheStats(){try{const t=await this.request("/api/coze/cache/stats");if(!t.success||!t.data)throw new Error(t.message||"获取缓存统计失败");return t.data}catch(t){throw console.error("获取缓存统计失败:",t),t}}}const ft=new yn;class Sn{constructor(){q(this,"apiClient");q(this,"webSocketManager");q(this,"initialized",!1);this.apiClient=D,this.webSocketManager=W}async initialize(){this.initialized||(console.log("[NetworkService] 初始化网络服务"),this.webSocketManager.connect(),this.initialized=!0,console.log("[NetworkService] 网络服务初始化完成"))}destroy(){console.log("[NetworkService] 销毁网络服务"),this.webSocketManager.disconnect(),this.initialized=!1}async getConfig(){return this.apiClient.getConfig()}async updateConfig(t){return this.apiClient.updateConfig(t)}async getStatus(){return this.apiClient.getStatus()}async getClientStatus(){return this.apiClient.getClientStatus()}async restartService(){return this.apiClient.restartService()}async stopService(){return this.apiClient.stopService()}async startService(){return this.apiClient.startService()}async getServiceStatus(){return this.apiClient.getServiceStatus()}async getServiceHealth(){return this.apiClient.getServiceHealth()}async getMcpEndpoint(){return this.apiClient.getMcpEndpoint()}async getMcpEndpoints(){return this.apiClient.getMcpEndpoints()}async getMcpServers(){return this.apiClient.getMcpServers()}async getConnectionConfig(){return this.apiClient.getConnectionConfig()}async reloadConfig(){return this.apiClient.reloadConfig()}async getConfigPath(){return this.apiClient.getConfigPath()}async checkConfigExists(){return this.apiClient.checkConfigExists()}async getRestartStatus(){return this.apiClient.getRestartStatus()}async checkClientConnected(){return this.apiClient.checkClientConnected()}async getLastHeartbeat(){return this.apiClient.getLastHeartbeat()}async getActiveMCPServers(){return this.apiClient.getActiveMCPServers()}async updateClientStatus(t){return this.apiClient.updateClientStatus(t)}async setActiveMCPServers(t){return this.apiClient.setActiveMCPServers(t)}async resetStatus(){return this.apiClient.resetStatus()}getWebSocketState(){return this.webSocketManager.getState()}isWebSocketConnected(){return this.webSocketManager.isConnected()}setWebSocketUrl(t){this.webSocketManager.setUrl(t)}onWebSocketEvent(t,s){return this.webSocketManager.subscribe(t,s)}reconnectWebSocket(){this.webSocketManager.disconnect(),setTimeout(()=>{this.webSocketManager.connect()},1e3)}send(t){return this.webSocketManager.send(t)}async getFullAppState(){const[t,s]=await Promise.all([this.getConfig(),this.getStatus()]);return{config:t,status:s,webSocketConnected:this.isWebSocketConnected()}}async updateConfigWithNotification(t,s=5e3){return new Promise((a,n)=>{const i=this.webSocketManager.subscribe("data:configUpdate",()=>{clearTimeout(c),i(),a()}),c=setTimeout(()=>{i(),n(new Error("等待配置更新通知超时"))},s);this.updateConfig(t).catch(m=>{clearTimeout(c),i==null||i(),n(m)})})}async restartServiceWithNotification(t=3e4){return new Promise((s,a)=>{const n=this.webSocketManager.subscribe("data:restartStatus",c=>{c.status==="completed"?(clearTimeout(i),n(),s()):c.status==="failed"&&(clearTimeout(i),n(),a(new Error(c.error||"服务重启失败")))}),i=setTimeout(()=>{n(),a(new Error("等待重启状态通知超时"))},t);this.restartService().catch(c=>{clearTimeout(i),n==null||n(),a(c)})})}}const F=new Sn,hs={connectionState:se.DISCONNECTED,wsUrl:"",connectionStats:{reconnectAttempts:0,maxReconnectAttempts:5,lastHeartbeat:0,eventListenerCount:0},portChangeStatus:void 0,lastError:null,connectedAt:null,disconnectedAt:null},ot=Bt()(Ht((r,t)=>({...hs,setConnectionState:s=>{console.log("[WebSocketStore] 更新连接状态:",s);const a=Date.now(),n={connectionState:s};s===se.CONNECTED?(n.connectedAt=a,n.lastError=null):s===se.DISCONNECTED&&(n.disconnectedAt=a),r(n,!1,"setConnectionState");const i=W.getConnectionStats();t().setConnectionStats(i)},setWsUrl:s=>{console.log("[WebSocketStore] 更新 WebSocket URL:",s),r({wsUrl:s},!1,"setWsUrl")},setConnectionStats:s=>{r({connectionStats:s},!1,"setConnectionStats")},setLastError:s=>{console.log("[WebSocketStore] 更新连接错误:",s==null?void 0:s.message),r({lastError:s},!1,"setLastError")},setPortChangeStatus:s=>{console.log("[WebSocketStore] 更新端口变更状态:",s==null?void 0:s.status),r({portChangeStatus:s},!1,"setPortChangeStatus")},connect:async()=>{try{console.log("[WebSocketStore] 开始连接 WebSocket"),W.connect()}catch(s){const a=s instanceof Error?s:new Error("连接失败");throw console.error("[WebSocketStore] 连接失败:",a),t().setLastError(a),a}},disconnect:()=>{console.log("[WebSocketStore] 断开 WebSocket 连接"),W.disconnect()},reconnect:async()=>{try{console.log("[WebSocketStore] 重新连接 WebSocket"),W.disconnect(),await new Promise(s=>setTimeout(s,1e3)),W.connect()}catch(s){const a=s instanceof Error?s:new Error("重连失败");throw console.error("[WebSocketStore] 重连失败:",a),t().setLastError(a),a}},send:s=>{try{return W.send(s)}catch(a){const n=a instanceof Error?a:new Error("发送消息失败");return console.error("[WebSocketStore] 发送消息失败:",n),t().setLastError(n),!1}},updateUrl:s=>{console.log("[WebSocketStore] 更新 WebSocket URL:",s),W.setUrl(s),t().setWsUrl(s)},getConnectionInfo:()=>{const s=t();return{state:s.connectionState,url:s.wsUrl,stats:s.connectionStats,isConnected:s.connectionState===se.CONNECTED}},reset:()=>{console.log("[WebSocketStore] 重置状态"),r(hs,!1,"reset")},initialize:()=>{console.log("[WebSocketStore] 初始化 WebSocket Store"),W.subscribe("connection:connecting",()=>{t().setConnectionState(se.CONNECTING)}),W.subscribe("connection:connected",()=>{t().setConnectionState(se.CONNECTED)}),W.subscribe("connection:disconnected",()=>{t().setConnectionState(se.DISCONNECTED)}),W.subscribe("connection:reconnecting",()=>{t().setConnectionState(se.RECONNECTING);const a=W.getConnectionStats();t().setConnectionStats(a)}),W.subscribe("connection:error",({error:a})=>{t().setLastError(a)}),W.subscribe("system:heartbeat",()=>{const a=W.getConnectionStats();t().setConnectionStats(a)});const s=W.getConnectionStats();t().setConnectionStats(s),t().setWsUrl(W.getUrl()),console.log("[WebSocketStore] WebSocket Store 初始化完成")},setConnected:s=>{console.warn("[WebSocketStore] setConnected 方法已废弃,请使用 setConnectionState");const a=s?se.CONNECTED:se.DISCONNECTED;t().setConnectionState(a)}}),{name:"websocket-store"})),Cr=()=>ot(r=>r.connectionState===se.CONNECTED),Cn=()=>ot(r=>r.wsUrl),kn=()=>ot(r=>r.portChangeStatus),En=()=>ot(Ps(r=>({setConnectionState:r.setConnectionState,setWsUrl:r.setWsUrl,setConnectionStats:r.setConnectionStats,setLastError:r.setLastError,setPortChangeStatus:r.setPortChangeStatus,connect:r.connect,disconnect:r.disconnect,reconnect:r.reconnect,send:r.send,updateUrl:r.updateUrl,reset:r.reset,initialize:r.initialize,getConnectionInfo:r.getConnectionInfo,setConnected:r.setConnected})));function Tn(){const r=En(),t=o.useRef(!1);o.useEffect(()=>{if(t.current)return;console.log("[NetworkService] 初始化网络服务"),t.current=!0,F.initialize().catch(f=>{console.error("[NetworkService] 初始化失败:",f)});const u=[F.onWebSocketEvent("connection:connected",()=>{console.log("[NetworkService] WebSocket 已连接"),r.setConnectionState(se.CONNECTED),s()}),F.onWebSocketEvent("connection:disconnected",()=>{console.log("[NetworkService] WebSocket 已断开"),r.setConnectionState(se.DISCONNECTED)}),F.onWebSocketEvent("data:configUpdate",f=>{console.log("[NetworkService] 收到配置更新通知"),he.getState().setConfig(f,"websocket")}),F.onWebSocketEvent("data:statusUpdate",f=>{console.log("[NetworkService] 收到状态更新通知"),pe.getState().setClientStatus(f,"websocket")}),F.onWebSocketEvent("data:restartStatus",f=>{console.log("[NetworkService] 收到重启状态通知:",f),pe.getState().setRestartStatus(f,"websocket")}),F.onWebSocketEvent("system:error",({error:f})=>{console.error("[NetworkService] WebSocket 错误:",f);const C=`WebSocket 连接错误: ${f.message}`;pe.getState().setError(new Error(C)),f.message.includes("ECONNREFUSED")||f.message.includes("连接被拒绝")?console.warn("[NetworkService] 连接被拒绝,可能是服务未启动"):f.message.includes("timeout")||f.message.includes("超时")?console.warn("[NetworkService] 连接超时,请检查网络连接"):console.warn("[NetworkService] 未知的 WebSocket 错误:",f)})];return()=>{console.log("[NetworkService] 清理网络服务");for(const f of u)try{f==null||f()}catch(C){console.error("[NetworkService] 清理事件监听器失败:",C)}F.destroy(),t.current=!1}},[r]);const s=o.useCallback(async()=>{try{console.log("[NetworkService] 加载初始数据");const[u,f]=await Promise.all([F.getConfig(),F.getClientStatus()]);console.log("[NetworkService] 初始数据加载成功"),he.getState().setConfig(u,"http"),pe.getState().setClientStatus(f,"http")}catch(u){console.error("[NetworkService] 加载初始数据失败:",u)}},[]),a=o.useCallback(async()=>{try{const u=await F.getConfig();return he.getState().setConfig(u,"http"),u}catch(u){throw console.error("[NetworkService] 获取配置失败:",u),u}},[]),n=o.useCallback(async u=>{try{console.log("[NetworkService] 更新配置"),await F.updateConfig(u),he.getState().setConfig(u,"http"),console.log("[NetworkService] 配置更新成功")}catch(f){throw console.error("[NetworkService] 配置更新失败:",f),f}},[]),i=o.useCallback(async()=>{try{const u=await F.getStatus();return pe.getState().setClientStatus(u.client,"http"),u}catch(u){throw console.error("[NetworkService] 获取状态失败:",u),u}},[]),c=o.useCallback(async()=>{try{await i()}catch(u){console.error("[NetworkService] 刷新状态失败:",u)}},[i]),m=o.useCallback(async()=>{try{console.log("[NetworkService] 重启服务"),await F.restartService(),console.log("[NetworkService] 重启请求已发送")}catch(u){throw console.error("[NetworkService] 重启服务失败:",u),u}},[]),b=o.useCallback(async(u=3e4)=>{try{console.log("[NetworkService] 重启服务并等待通知"),await F.restartServiceWithNotification(u),console.log("[NetworkService] 服务重启完成")}catch(f){throw console.error("[NetworkService] 重启服务失败:",f),f}},[]),g=o.useCallback(async(u,f=5e3)=>{try{console.log("[NetworkService] 更新配置并等待通知"),await F.updateConfigWithNotification(u,f),console.log("[NetworkService] 配置更新完成")}catch(C){throw console.error("[NetworkService] 配置更新失败:",C),C}},[]),h=o.useCallback(u=>{console.log("[NetworkService] 设置自定义 WebSocket URL:",u),F.setWebSocketUrl(u),r.setWsUrl(u)},[r]),p=o.useCallback(async u=>{try{console.log(`[NetworkService] 切换到端口 ${u}`),r.setPortChangeStatus({status:"checking",targetPort:u,timestamp:Date.now()});const f=window.location.protocol==="https:"?"wss:":"ws:",C=window.location.hostname,y=`${f}//${C}:${u}`;await m(),await new Promise(v=>setTimeout(v,5e3)),h(y),window.location.reload()}catch(f){throw console.error("[NetworkService] 端口切换失败:",f),r.setPortChangeStatus({status:"failed",targetPort:u,error:f instanceof Error?f.message:"端口切换失败",timestamp:Date.now()}),f}},[r,m,h]),d=o.useCallback(()=>{const u=localStorage.getItem("xiaozhi-ws-url");if(u)return u;const f=window.location.protocol==="https:"?"wss:":"ws:",C=window.location.hostname,y=window.location.port;return`${f}//${C}${y?`:${y}`:""}`},[]);return{getConfig:a,updateConfig:n,getStatus:i,refreshStatus:c,restartService:m,updateConfigWithNotification:g,restartServiceWithNotification:b,setCustomWsUrl:h,getWebSocketUrl:d,changePort:p,loadInitialData:s,isWebSocketConnected:()=>F.isWebSocketConnected(),getWebSocketState:()=>F.getWebSocketState()}}async function Pn(){console.log("[Stores] 开始初始化所有 stores");try{console.log("[Stores] 初始化 WebSocket store"),ot.getState().initialize(),console.log("[Stores] 初始化配置 store"),await he.getState().initialize(),console.log("[Stores] 初始化状态 store"),await pe.getState().initialize(),console.log("[Stores] 所有 stores 初始化完成")}catch(r){throw console.error("[Stores] Stores 初始化失败:",r),r}}const kr=o.createContext(null);function Mn({children:r}){const t=Tn(),[s,a]=o.useState(!1);return o.useEffect(()=>{let n=!0;return(async()=>{try{console.log("[WebSocketProvider] 开始初始化 stores"),await Pn(),n&&(a(!0),console.log("[WebSocketProvider] Stores 初始化完成"))}catch(c){console.error("[WebSocketProvider] Stores 初始化失败:",c),n&&a(!0)}})(),()=>{n=!1}},[]),s?e.jsx(kr.Provider,{value:t,children:r}):e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-600",children:"正在初始化应用..."})]})})}function ns(){const r=o.useContext(kr);if(!r)throw new Error("useNetworkServiceActions must be used within a NetworkServiceProvider");return r}const Rn=Mn,Er=ns,In=G.object({port:G.string().min(1,{message:"端口号不能为空"}).refine(r=>!Number.isNaN(Number(r)),{message:"请输入有效的数字"}).refine(r=>Number(r)>=1&&Number(r)<=65535,{message:"端口号必须在 1-65535 之间"}).refine(r=>Number.isInteger(Number(r)),{message:"端口号必须是整数"})});function On(){const[r,t]=o.useState(!1),[s,a]=o.useState(!1),n=nt(),i=Cr(),c=kn(),{changePort:m}=ns(),b=Ae({resolver:_e(In),defaultValues:{port:"9999"}});o.useEffect(()=>{var p;(p=n==null?void 0:n.webUI)!=null&&p.port&&b.reset({port:n.webUI.port.toString()})},[n,b]);const g=()=>{if(s)return"处理中...";if((c==null?void 0:c.status)==="checking")return"检测端口...";if((c==null?void 0:c.status)==="polling"){const{currentAttempt:p,maxAttempts:d}=c;return`等待服务重启 (${p||0}/${d||45})`}return(c==null?void 0:c.status)==="connecting"?"连接中...":i?"保存并重启":"保存并连接"};async function h(p){var f;const d=Number(p.port),u=(f=n==null?void 0:n.webUI)==null?void 0:f.port;if(d===u){t(!1);return}console.log(`[WebUrlSettingButton] 开始端口切换: ${u} -> ${d}`),a(!0);try{k.info(i?`正在将端口从 ${u} 切换到 ${d}...`:`正在连接到端口 ${d}...`),await m(d),k.success(i?`端口已成功切换到 ${d},页面即将刷新...`:`已成功连接到端口 ${d},页面即将刷新...`),t(!1)}catch(C){console.error("端口切换失败:",C);const y=C instanceof Error?C.message:"端口切换失败";k.error(`端口切换失败: ${y}`)}finally{a(!1)}}return e.jsxs(ue,{open:r,onOpenChange:t,children:[e.jsx(Ee,{asChild:!0,children:e.jsx(E,{variant:"secondary",size:"icon",className:"size-8",children:e.jsx(Ge,{className:"h-4 w-4"})})}),e.jsx(ie,{className:"sm:max-w-[250px]",children:e.jsx(Ve,{...b,children:e.jsxs("form",{onSubmit:b.handleSubmit(h),children:[e.jsxs(ce,{className:"mb-4",children:[e.jsx(le,{children:"配置服务端端口"}),e.jsx(ve,{children:i?"修改端口后将自动重启服务并重新连接。":"请输入服务端端口号,系统将尝试连接。"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{children:["ws://",window.location.hostname,":"]}),e.jsx("div",{className:"w-[100px]",children:e.jsx(ee,{control:b.control,name:"port",render:({field:p})=>e.jsxs(Z,{children:[e.jsx(H,{children:e.jsx(re,{placeholder:"服务端端口,默认9999",className:"font-mono text-sm",disabled:s,type:"number",...p})}),e.jsx(ae,{})]})})})]}),e.jsxs(Te,{className:"mt-4",children:[e.jsx(Pt,{asChild:!0,children:e.jsx(E,{variant:"outline",disabled:s,children:"取消"})}),e.jsx(E,{type:"submit",disabled:s||(c==null?void 0:c.status)==="polling",children:g()})]})]})})})]})}const $t=({showValue:r=!0,value:t=0,maxValue:s=100,size:a=60,activeColor:n="#3b82f6",inactiveColor:i="#e5e7eb",symbol:c="%"})=>{const m=(a-6)/2,b=m*2*Math.PI,g=b,h=s===0?b:b-t/s*b;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:a,height:a,className:"transform -rotate-90",children:[e.jsx("circle",{cx:a/2,cy:a/2,r:m,stroke:i,strokeWidth:6,fill:"none"}),e.jsx("circle",{cx:a/2,cy:a/2,r:m,stroke:n,strokeWidth:6,fill:"none",strokeDasharray:g,strokeDashoffset:h,strokeLinecap:"round",className:"transition-all duration-300 ease-in-out"})]}),r&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("span",{className:"text-xs font-medium",children:[t,c]})})]})};function Dn(){const r=hr(),t=Cr(),s=Object.keys(r||{}).length,a=Cn(),n=fr();return e.jsxs("div",{className:"*:data-[slot=card]:shadow-xs @xl/main:grid-cols-2 @5xl/main:grid-cols-4 grid grid-cols-1 gap-4 px-4 *:data-[slot=card]:bg-gradient-to-t *:data-[slot=card]:from-primary/5 *:data-[slot=card]:to-card dark:*:data-[slot=card]:bg-card lg:px-6",children:[e.jsxs(de,{className:"@container/card",children:[e.jsxs(De,{className:"relative",children:[e.jsx(Fe,{children:"小智接入点"}),e.jsx(ze,{className:"@[250px]/card:text-3xl text-2xl font-semibold tabular-nums",children:Array.isArray(n)?n.length:n?1:0}),e.jsx("div",{className:"absolute right-4 top-4 flex flex-col items-center",children:e.jsx($t,{showValue:!1,value:Array.isArray(n)?n.length:n?1:0,maxValue:Math.max(Array.isArray(n)?n.length:1,1),activeColor:"#16a34a",inactiveColor:"#f87171",size:30,symbol:""})})]}),e.jsx(Be,{className:"flex-col items-end gap-1 text-sm",children:e.jsx(pn,{})})]}),e.jsxs(de,{className:"@container/card",children:[e.jsxs(De,{className:"relative",children:[e.jsx(Fe,{children:"Xiaozhi Client"}),e.jsx(ze,{className:"@[250px]/card:text-3xl text-2xl font-semibold tabular-nums",children:t?"已连接":"未连接"}),e.jsx("div",{className:"absolute right-4 top-4",children:e.jsx($t,{showValue:!1,value:1,maxValue:1,activeColor:t?"#16a34a":"#f87171",inactiveColor:t?"#16a34a":"#f87171",size:30,symbol:""})})]}),e.jsxs(Be,{className:"flex items-center justify-between gap-1 text-sm",children:[e.jsx("div",{className:"text-muted-foreground",children:a}),e.jsx(On,{})]})]}),e.jsxs(de,{className:"@container/card",children:[e.jsxs(De,{className:"relative",children:[e.jsx(Fe,{children:"MCP服务"}),e.jsx(ze,{className:"@[250px]/card:text-3xl text-2xl font-semibold tabular-nums",children:s}),e.jsx("div",{className:"absolute right-4 top-4",children:e.jsx($t,{showValue:!1,value:s,maxValue:Math.max(s,1),activeColor:"#16a34a",inactiveColor:"#f87171",size:30,symbol:""})})]}),e.jsxs(Be,{className:"flex items-center justify-between gap-1 text-sm",children:[e.jsxs("div",{className:"text-muted-foreground",children:["共 ",s," 个服务"]}),e.jsx(jn,{})]})]})]})}const Tr=o.forwardRef(({className:r,...t},s)=>e.jsx(zs,{ref:s,className:w("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",r),...t,children:e.jsx(ra,{className:w("flex items-center justify-center text-current"),children:e.jsx(Ze,{className:"h-4 w-4"})})}));Tr.displayName=zs.displayName;const $e=la,We=da,Se=o.forwardRef(({className:r,children:t,...s},a)=>e.jsxs($s,{ref:a,className:w("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",r),...s,children:[t,e.jsx(aa,{asChild:!0,children:e.jsx(Zt,{className:"h-4 w-4 opacity-50"})})]}));Se.displayName=$s.displayName;const Pr=o.forwardRef(({className:r,...t},s)=>e.jsx(Ws,{ref:s,className:w("flex cursor-default items-center justify-center py-1",r),...t,children:e.jsx(Ls,{className:"h-4 w-4"})}));Pr.displayName=Ws.displayName;const Mr=o.forwardRef(({className:r,...t},s)=>e.jsx(As,{ref:s,className:w("flex cursor-default items-center justify-center py-1",r),...t,children:e.jsx(Zt,{className:"h-4 w-4"})}));Mr.displayName=As.displayName;const Ce=o.forwardRef(({className:r,children:t,position:s="popper",...a},n)=>e.jsx(na,{children:e.jsxs(_s,{ref:n,className:w("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",s==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",r),position:s,...a,children:[e.jsx(Pr,{}),e.jsx(oa,{className:w("p-1",s==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),e.jsx(Mr,{})]})}));Ce.displayName=_s.displayName;const zn=o.forwardRef(({className:r,...t},s)=>e.jsx(Us,{ref:s,className:w("py-1.5 pl-8 pr-2 text-sm font-semibold",r),...t}));zn.displayName=Us.displayName;const oe=o.forwardRef(({className:r,children:t,...s},a)=>e.jsxs(Vs,{ref:a,className:w("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",r),...s,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(ia,{children:e.jsx(Ze,{className:"h-4 w-4"})})}),e.jsx(ca,{children:t})]}));oe.displayName=Vs.displayName;const $n=o.forwardRef(({className:r,...t},s)=>e.jsx(qs,{ref:s,className:w("-mx-1 my-1 h-px bg-muted",r),...t}));$n.displayName=qs.displayName;const Wn=yt({fieldName:xt().min(1,"字段名不能为空").regex(/^[a-zA-Z][a-zA-Z0-9_]*$/,"字段名必须以字母开头,只能包含字母、数字和下划线"),description:xt().min(1,"描述不能为空").max(200,"描述不能超过200个字符"),type:Zs(["string","number","boolean"]),required:Gs()}),Ln=yt({parameters:Lt(Wn).refine(r=>{const t=r.map(s=>s.fieldName);return t.length===new Set(t).size},{message:"字段名不能重复"})});function An(r){if(!r||!r.properties)return[];const t=r.properties,s=r.required||[];return Object.entries(t).map(([a,n])=>{let i="string";return n.type==="integer"||n.type==="number"?i="number":n.type==="boolean"&&(i="boolean"),{fieldName:a,description:n.description||"",type:i,required:s.includes(a)}})}function Rr({open:r,onOpenChange:t,workflow:s,onConfirm:a,onCancel:n,title:i}){const c=Ae({resolver:_e(Ln),defaultValues:{parameters:[]}});o.useEffect(()=>{r&&c.reset({parameters:An(s.inputSchema)})},[r,s,c.reset]);const{fields:m,append:b,remove:g}=Fs({control:c.control,name:"parameters"}),h=()=>{b({fieldName:"",description:"",type:"string",required:!1})},p=f=>{g(f)},d=f=>{a(s,f.parameters),c.reset()},u=()=>{c.reset(),n()};return e.jsx(ue,{open:r,onOpenChange:t,children:e.jsxs(ie,{className:"max-w-4xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(ce,{children:[e.jsx(le,{children:i||`配置工作流参数 - ${s.workflow_name}`}),e.jsx(ve,{children:"为工作流配置输入参数,这些参数将用于生成工具的输入架构。 您可以跳过此步骤使用默认的空参数配置。"})]}),e.jsx(Ve,{...c,children:e.jsxs("form",{onSubmit:c.handleSubmit(d),className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4 mb-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:"参数列表"}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:h,className:"flex items-center gap-2",children:[e.jsx(Le,{className:"h-4 w-4"}),"添加参数"]})]}),m.length===0&&e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:'暂无参数,点击"添加参数"开始配置'}),m.map((f,C)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ee,{control:c.control,name:`parameters.${C}.fieldName`,render:({field:y})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"字段名"}),e.jsx(H,{children:e.jsx(re,{placeholder:"例如: userName",...y})}),e.jsx(ae,{})]})}),e.jsx(ee,{control:c.control,name:`parameters.${C}.description`,render:({field:y})=>e.jsxs(Z,{className:"flex-1",children:[e.jsx(ne,{children:"描述"}),e.jsx(H,{children:e.jsx(re,{placeholder:"例如: 用户名称",...y})}),e.jsx(ae,{})]})}),e.jsx(ee,{control:c.control,name:`parameters.${C}.type`,render:({field:y})=>e.jsxs(Z,{className:"w-[140px]",children:[e.jsx(ne,{children:"参数类型"}),e.jsxs($e,{onValueChange:y.onChange,defaultValue:y.value,children:[e.jsx(H,{children:e.jsx(Se,{children:e.jsx(We,{placeholder:"选择参数类型"})})}),e.jsxs(Ce,{children:[e.jsx(oe,{value:"string",children:"string"}),e.jsx(oe,{value:"number",children:"number"}),e.jsx(oe,{value:"boolean",children:"boolean"})]})]}),e.jsx(ae,{})]})}),e.jsx(ee,{control:c.control,name:`parameters.${C}.required`,render:({field:y})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"是否必填"}),e.jsx(H,{children:e.jsx("div",{className:"flex items-center justify-center h-[40px]",children:e.jsx(Tr,{checked:y.value,onCheckedChange:y.onChange})})})]})}),e.jsx("div",{className:"flex flex-col h-[72px] justify-end",children:e.jsx(E,{type:"button",variant:"link",size:"sm",onClick:()=>p(C),className:"text-destructive mb-[4px]",children:e.jsx(Bs,{className:"h-4 w-4"})})})]},f.id))]}),e.jsxs(Te,{children:[e.jsx(E,{type:"button",variant:"outline",onClick:u,children:"取消"}),e.jsx(E,{type:"submit",children:"确认配置"})]})]})})]})})}function Vt(r){if(!r||typeof r!="object")throw new Error("服务配置必须是一个有效的对象");if("command"in r&&typeof r.command=="string")return"stdio";if("type"in r&&r.type==="sse")return"sse";if("url"in r&&typeof r.url=="string")return"streamable-http";throw new Error("无法识别的 MCP 服务配置类型。配置必须包含 command 字段(stdio)、type: 'sse' 字段(sse)或 url 字段(streamable-http)")}const It=o.forwardRef(({className:r,...t},s)=>e.jsx("textarea",{className:w("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),ref:s,...t}));It.displayName="Textarea";const _n=G.object({config:G.string().min(2,{message:"配置不能为空"})});function ps(){const[r,t]=o.useState(!1),[s,a]=o.useState(!1),n=nt(),i=Ae({resolver:_e(_n),defaultValues:{config:""}}),c=(g,h)=>{if(!h||typeof h!="object")return{valid:!1,error:`服务 "${g}" 的配置必须是一个对象`};const p="command"in h,d="type"in h,u="url"in h;if(p){if(!h.command||typeof h.command!="string")return{valid:!1,error:`服务 "${g}" 缺少必需的 command 字段或字段类型不正确`};if(!Array.isArray(h.args))return{valid:!1,error:`服务 "${g}" 的 args 字段必须是数组`}}else if(d&&h.type==="sse"){if(!h.url||typeof h.url!="string")return{valid:!1,error:`服务 "${g}" 缺少必需的 url 字段或字段类型不正确`}}else if(u){if(!h.url||typeof h.url!="string")return{valid:!1,error:`服务 "${g}" 缺少必需的 url 字段或字段类型不正确`}}else return{valid:!1,error:`服务 "${g}" 的配置无效: 必须包含 command 字段(stdio)、type: 'sse' 字段(sse)或 url 字段(streamable-http)`};try{return Vt(h),{valid:!0}}catch(f){return{valid:!1,error:`服务 "${g}" 的配置无效: ${f instanceof Error?f.message:"未知错误"}`}}},m=g=>{try{const h=g.trim();if(!h)return{success:!1,error:"配置不能为空"};const p=JSON.parse(h);let d;if(p.mcpServers&&typeof p.mcpServers=="object")d=p.mcpServers;else if(typeof p=="object"&&!Array.isArray(p))try{Vt(p),d={[p.command?p.command.split("/").pop()||"mcp-server":p.type==="sse"?"sse-server":"http-server"]:p}}catch{d=p}else return{success:!1,error:"配置格式错误: 必须是对象格式"};for(const[u,f]of Object.entries(d)){const C=c(u,f);if(!C.valid)return{success:!1,error:C.error}}return{success:!0,data:d}}catch(h){return{success:!1,error:`JSON 格式错误: ${h instanceof Error?h.message:"无法解析 JSON"}`}}};async function b(g){if(!n){k.error("配置数据未加载,请稍后重试");return}a(!0);try{const h=m(g.config);if(!h.success){k.error(h.error||"配置验证失败");return}const p=h.data,d=await At.listServers(),u=Object.keys(p).filter(C=>d.servers.some(y=>y.name===C));if(u.length>0){k.error(`服务名称冲突: 以下服务已存在: ${u.join(", ")}`);return}for(const[C,y]of Object.entries(p))if(!await At.addServer(C,y))throw new Error("添加服务器失败");const f=Object.keys(p).length;k.success(f===1?`已添加 MCP 服务 "${Object.keys(p)[0]}"`:`已添加 ${f} 个 MCP 服务`),i.reset(),t(!1)}catch(h){console.error("更新配置失败:",h),k.error(h instanceof Error?h.message:"更新配置失败")}finally{a(!1)}}return e.jsxs(ue,{open:r,onOpenChange:t,children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(E,{size:"icon",className:"w-full",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{children:"添加MCP服务"})]})}),e.jsx(ie,{className:"sm:max-w-[500px]",children:e.jsx(Ve,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(b),children:[e.jsxs(ce,{className:"mb-4",children:[e.jsx(le,{children:"添加MCP服务"}),e.jsx(ve,{children:"添加后,需要重启服务才会生效。"})]}),e.jsx("div",{className:"grid gap-4",children:e.jsx(ee,{control:i.control,name:"config",render:({field:g})=>e.jsxs(Z,{children:[e.jsx(H,{children:e.jsx(It,{className:"resize-none h-[300px] font-mono text-sm",disabled:s,placeholder:`支持三种通信方式:
2
+
3
+ 1. 本地进程 (stdio):
4
+ {
5
+ "mcpServers": {
6
+ "local-server": {
7
+ "command": "npx",
8
+ "args": ["-y", "@example/mcp-server"]
9
+ }
10
+ }
11
+ }
12
+
13
+ 2. 服务器推送 (SSE):
14
+ {
15
+ "mcpServers": {
16
+ "sse-server": {
17
+ "type": "sse",
18
+ "url": "https://example.com/sse"
19
+ }
20
+ }
21
+ }
22
+
23
+ 3. 流式 HTTP:
24
+ {
25
+ "mcpServers": {
26
+ "http-server": {
27
+ "url": "https://example.com/mcp"
28
+ }
29
+ }
30
+ }`,...g})}),e.jsx(ae,{})]})})}),e.jsxs(Te,{className:"mt-4",children:[e.jsx(Pt,{asChild:!0,children:e.jsx(E,{variant:"outline",disabled:s,children:"取消"})}),e.jsx(E,{type:"submit",disabled:s,children:s?"保存中...":"保存"})]})]})})})]})}function Un(r={}){const{autoLoadWorkspaces:t=!0,autoLoadWorkflows:s=!0,defaultPageSize:a=20,initialWorkspaceId:n}=r,[i,c]=o.useState([]),[m,b]=o.useState([]),[g,h]=o.useState(n||null),[p,d]=o.useState({selectedWorkspaceId:n||null,workspacesLoading:!1,workflowsLoading:!1,workspacesError:null,workflowsError:null}),[u,f]=o.useState(1),[C,y]=o.useState(a),[v,O]=o.useState(!1),P=o.useMemo(()=>i&&Array.isArray(i)&&i.find(I=>I.id===g)||null,[i,g]),$=o.useCallback(async()=>{d(I=>({...I,workspacesLoading:!0,workspacesError:null}));try{const I=await ft.fetchWorkspaces();c(I.workspaces),d(L=>({...L,workspacesLoading:!1}))}catch(I){const L=I instanceof Error?I.message:"加载工作空间失败";d(_=>({..._,workspacesLoading:!1,workspacesError:L})),console.error("加载工作空间失败:",I)}},[]),S=o.useCallback(async(I={})=>{const L=I.workspace_id||g;if(!L){console.warn("无法加载工作流:未选择工作空间");return}d(_=>({..._,workflowsLoading:!0,workflowsError:null}));try{const _={workspace_id:L,page_num:I.page_num||u,page_size:I.page_size||C},J=await ft.fetchWorkflows(_);b(J.items),O(J.hasMore),d(l=>({...l,workflowsLoading:!1}))}catch(_){const J=_ instanceof Error?_.message:"加载工作流失败";d(l=>({...l,workflowsLoading:!1,workflowsError:J})),console.error("加载工作流失败:",_)}},[g,u,C]),R=o.useCallback(I=>{h(I),d(L=>({...L,selectedWorkspaceId:I})),b([]),f(1),O(!1),s&&I&&S({workspace_id:I,page_num:1})},[s,S]),A=o.useCallback(async()=>{await $()},[$]),V=o.useCallback(async()=>{g&&await S({workspace_id:g,page_num:u})},[S,g,u]),Q=o.useCallback(async()=>{try{await ft.clearCache(),t&&await $(),s&&g&&await S({workspace_id:g,page_num:1})}catch(I){throw console.error("清除缓存失败:",I),I}},[t,s,g,$,S]),me=o.useCallback(I=>{f(I),g&&S({workspace_id:g,page_num:I})},[g,S]),fe=o.useCallback(I=>{y(I),f(1),g&&S({workspace_id:g,page_num:1,page_size:I})},[g,S]);return o.useEffect(()=>{t&&$()},[t,$]),o.useEffect(()=>{s&&g&&(async()=>{d(L=>({...L,workflowsLoading:!0,workflowsError:null}));try{const L={workspace_id:g,page_num:1,page_size:C},_=await ft.fetchWorkflows(L);b(_.items),O(_.hasMore),d(J=>({...J,workflowsLoading:!1}))}catch(L){const _=L instanceof Error?L.message:"加载工作流失败";d(J=>({...J,workflowsLoading:!1,workflowsError:_})),console.error("加载工作流失败:",L)}})()},[s,g,C]),{workspaces:i,workflows:m,selectedWorkspace:P,workspacesLoading:p.workspacesLoading,workflowsLoading:p.workflowsLoading,workspacesError:p.workspacesError,workflowsError:p.workflowsError,hasMoreWorkflows:v,selectWorkspace:R,loadWorkflows:S,refreshWorkspaces:A,refreshWorkflows:V,clearCache:Q,setWorkflows:b,currentPage:u,pageSize:C,setPage:me,setPageSize:fe}}function Vn({onToolAdded:r}){var Ne;const[t,s]=o.useState(!1),[a,n]=o.useState(!1),[i,c]=o.useState({open:!1,action:"add"}),[m,b]=o.useState({open:!1}),[g,h]=o.useState(navigator.onLine),[p,d]=o.useState(new Set),[u,f]=o.useState(!1),{workspaces:C,workflows:y,selectedWorkspace:v,workspacesLoading:O,workflowsLoading:P,workspacesError:$,workflowsError:S,hasMoreWorkflows:R,currentPage:A,selectWorkspace:V,refreshWorkflows:Q,setPage:me,setWorkflows:fe}=Un({autoLoadWorkspaces:!0,autoLoadWorkflows:!0});o.useEffect(()=>{const M=()=>h(!0),B=()=>h(!1);return window.addEventListener("online",M),window.addEventListener("offline",B),()=>{window.removeEventListener("online",M),window.removeEventListener("offline",B)}},[]),o.useEffect(()=>{if(!O&&C.length>0&&!v&&!u){const M=C[0];console.log(`自动选择第一个工作空间: ${M.name}`),V(M.id),f(!0)}O&&u&&f(!1)},[C,O,v,u,V]);const I=M=>{f(!0),V(M)},L=M=>{if(!g){k.error("网络连接已断开,请检查网络后重试");return}const B=`add_${M.workflow_id}`;if(p.has(B)){k.warning("该工作流正在添加中,请勿重复操作");return}b({open:!0,workflow:M})},_=async(M,B)=>{const U=`add_${M.workflow_id}`;n(!0),d(z=>new Set(z).add(U));try{if(!M.workflow_id||!M.workflow_name||!M.app_id)throw new Error("工作流数据不完整,缺少必要字段");if(!g)throw new Error("网络连接已断开,请检查网络后重试");const z=B.length>0?{parameters:B}:void 0,X={type:"coze",data:{workflow:M,customName:void 0,customDescription:void 0,parameterConfig:z}},Pe=await D.addCustomTool(X);k.success(`已添加工作流 "${M.workflow_name}" 为 MCP 工具 "${Pe.name}"${B.length>0?`,配置了 ${B.length} 个参数`:""}`),fe(Ar=>Ar.map(Ot=>Ot.workflow_id===M.workflow_id?{...Ot,isAddedAsTool:!0,toolName:Pe.name}:Ot)),r==null||r(),await Q()}catch(z){console.error("添加工作流失败:",z);let X="添加工作流失败,请重试";z instanceof Error&&(z.message.includes("已存在")||z.message.includes("冲突")?X=`工作流 "${M.workflow_name}" 已存在,请勿重复添加`:z.message.includes("配置")||z.message.includes("token")?X="系统配置错误,请检查扣子API配置":z.message.includes("验证失败")||z.message.includes("格式")?X="工作流数据格式错误,请联系管理员":z.message.includes("网络")||z.message.includes("超时")||z.message.includes("连接")?X="网络连接失败,请检查网络后重试":z.message.includes("权限")?X="权限不足,请检查API权限配置":z.message.includes("频繁")?X="操作过于频繁,请稍后重试":X=z.message),k.error(X)}finally{n(!1),d(z=>{const X=new Set(z);return X.delete(U),X}),b({open:!1})}},J=()=>{b({open:!1})},l=async M=>{const B=`add_${M.workflow_id}`;n(!0),d(U=>new Set(U).add(B));try{if(!M.workflow_id||!M.workflow_name||!M.app_id)throw new Error("工作流数据不完整,缺少必要字段");if(!g)throw new Error("网络连接已断开,请检查网络后重试");const U={type:"coze",data:{workflow:M,customName:void 0,customDescription:void 0,parameterConfig:void 0}},z=await D.addCustomTool(U);k.success(`已添加工作流 "${M.workflow_name}" 为 MCP 工具 "${z.name}"`),fe(X=>X.map(Pe=>Pe.workflow_id===M.workflow_id?{...Pe,isAddedAsTool:!0,toolName:z.name}:Pe)),r==null||r(),await Q()}catch(U){console.error("添加工作流失败:",U);let z="添加工作流失败,请重试";U instanceof Error&&(U.message.includes("已存在")||U.message.includes("冲突")?z=`工作流 "${M.workflow_name}" 已存在,请勿重复添加`:U.message.includes("配置")||U.message.includes("token")?z="系统配置错误,请检查扣子API配置":U.message.includes("验证失败")||U.message.includes("格式")?z="工作流数据格式错误,请联系管理员":U.message.includes("网络")||U.message.includes("超时")||U.message.includes("连接")?z="网络连接失败,请检查网络后重试":U.message.includes("权限")?z="权限不足,请检查API权限配置":U.message.includes("频繁")?z="操作过于频繁,请稍后重试":z=U.message),k.error(z)}finally{n(!1),d(U=>{const z=new Set(U);return z.delete(B),z}),c({open:!1,action:"add"})}},x=()=>{A>1&&me(A-1)},j=()=>{R&&me(A+1)},N=()=>{v&&Q()},T=()=>e.jsx("div",{className:"space-y-2",children:$?e.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm text-red-600 bg-red-50 rounded-md",children:[e.jsx(He,{className:"h-4 w-4"}),e.jsxs("span",{children:["加载工作空间失败: ",$]})]}):e.jsxs($e,{value:(v==null?void 0:v.id)||"",onValueChange:I,disabled:O,children:[e.jsx(Se,{children:e.jsx(We,{placeholder:O?"加载中...":"请选择工作空间"})}),e.jsx(Ce,{children:C.map(M=>e.jsx(oe,{value:M.id,children:e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{children:M.name})})},M.id))})]})}),Y=()=>v?S?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(He,{className:"h-12 w-12 text-red-500 mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"加载工作流失败"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:S}),e.jsxs(E,{onClick:N,variant:"outline",children:[e.jsx(ht,{className:"h-4 w-4 mr-2"}),"重试"]})]}):P?e.jsx("div",{className:"space-y-3",children:Array.from({length:3},(M,B)=>B).map(M=>e.jsxs("div",{className:"flex items-center gap-4 p-4 border rounded-lg",children:[e.jsx(Oe,{className:"w-10 h-10 rounded-lg","data-testid":"skeleton"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(Oe,{className:"h-4 w-1/3","data-testid":"skeleton"}),e.jsx(Oe,{className:"h-3 w-2/3","data-testid":"skeleton"})]}),e.jsx(Oe,{className:"w-16 h-8","data-testid":"skeleton"})]},`skeleton-${M}`))}):y.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(qe,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"暂无工作流"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"当前工作空间下没有可用的工作流"})]}):e.jsx("div",{className:"space-y-3 max-h-[500px] overflow-auto",children:y.map(M=>e.jsxs("div",{className:"flex items-center gap-4 p-4 border rounded-lg hover:bg-slate-50 transition-colors",children:[e.jsx("div",{className:"flex-shrink-0 w-10 h-10 bg-green-100 rounded-lg flex items-center justify-center text-lg",children:e.jsx(qe,{className:"h-5 w-5 text-green-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"font-medium text-sm truncate",children:M.workflow_name}),e.jsx(te,{variant:"secondary",className:"text-xs",children:"工作流"})]}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:M.description||"暂无描述"})]}),e.jsx("div",{className:"flex-shrink-0",children:M.isAddedAsTool?e.jsx(te,{variant:"secondary",className:"text-xs bg-green-100 text-green-800",children:"已添加"}):e.jsxs(E,{size:"sm",onClick:()=>L(M),disabled:a,children:[a?e.jsx(ge,{className:"h-4 w-4 animate-spin","data-testid":"loader"}):e.jsx(Le,{className:"h-4 w-4"}),"添加"]})})]},M.workflow_id))}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(qe,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-2",children:"请先选择工作空间"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"选择一个工作空间后,将显示该空间下的工作流列表"})]}),xe=()=>!v||y.length===0?null:e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{variant:"link",size:"sm",onClick:x,disabled:A===1,className:"text-muted-foreground",children:e.jsx(ua,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("span",{className:"text-sm",children:A})}),e.jsx(E,{variant:"link",size:"sm",onClick:j,disabled:!R,className:"text-muted-foreground",children:e.jsx(ma,{className:"h-4 w-4"})})]})});return e.jsxs(e.Fragment,{children:[e.jsxs(ue,{open:t,onOpenChange:s,children:[e.jsx(Ee,{asChild:!0,children:e.jsxs(E,{variant:"outline",className:"w-full",children:[e.jsx(qe,{className:"h-4 w-4 mr-2"}),"工作流集成"]})}),e.jsxs(ie,{className:"flex flex-col max-w-full w-[1000px]",children:[e.jsx(ce,{className:"flex-shrink-0",children:e.jsxs(le,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-5 w-5"}),"工作流集成"]})}),e.jsx("div",{className:"w-[120px]",children:T()}),e.jsx("div",{className:"flex-1 pr-2 w-full",children:Y()}),xe()]})]}),m.workflow&&e.jsx(Rr,{open:m.open,onOpenChange:M=>b(B=>({...B,open:M})),workflow:m.workflow,onConfirm:_,onCancel:J,title:"配置工作流参数"}),e.jsx(Tt,{open:i.open,onOpenChange:M=>c(B=>({...B,open:M})),children:e.jsxs(Ye,{children:[e.jsxs(Xe,{children:[e.jsx(tt,{children:"确认添加工作流"}),e.jsxs(st,{children:['确定要将工作流 "',(Ne=i.workflow)==null?void 0:Ne.workflow_name,'" 添加为 MCP 工具吗?']})]}),e.jsxs(et,{children:[e.jsx(at,{children:"取消"}),e.jsx(rt,{onClick:()=>{i.workflow&&l(i.workflow)},children:"添加"})]})]})})]})}const qn=G.object({config:G.string().min(2,{message:"配置不能为空"})});function Fn({mcpServer:r,mcpServerName:t}){const[s,a]=o.useState(!1),[n,i]=o.useState(!1),c=nt(),{updateConfig:m}=ns(),b=Ae({resolver:_e(qn),defaultValues:{config:JSON.stringify(r,null,2)}});async function g(h){if(!c){k.error("配置数据未加载,请稍后重试");return}i(!0);try{let p;try{p=JSON.parse(h.config)}catch{k.error("JSON格式错误,请检查配置格式");return}if(!p||typeof p!="object"){k.error("配置格式无效");return}const d={...c,mcpServers:{...c.mcpServers,[t]:p}};await m(d),k.success("MCP服务器配置已更新"),a(!1)}catch(p){console.error("更新配置失败:",p),k.error(p instanceof Error?p.message:"更新配置失败")}finally{i(!1)}}return e.jsxs(ue,{open:s,onOpenChange:a,children:[e.jsx(Ee,{asChild:!0,children:e.jsx(E,{variant:"secondary",size:"icon",className:"size-8",children:e.jsx(Ge,{className:"h-4 w-4"})})}),e.jsx(ie,{className:"sm:max-w-[500px]",children:e.jsx(Ve,{...b,children:e.jsxs("form",{onSubmit:b.handleSubmit(g),children:[e.jsxs(ce,{className:"mb-4",children:[e.jsxs(le,{children:["配置 ",t," MCP"]}),e.jsx(ve,{children:"点击保存后,需要重启服务才会生效。"})]}),e.jsx("div",{className:"grid gap-4",children:e.jsx(ee,{control:b.control,name:"config",render:({field:h})=>e.jsxs(Z,{children:[e.jsx(H,{children:e.jsx(It,{placeholder:"MCP服务配置",className:"resize-none h-[300px] font-mono text-sm",disabled:n,...h})}),e.jsx(ae,{})]})})}),e.jsxs(Te,{className:"mt-4",children:[e.jsx(Pt,{asChild:!0,children:e.jsx(E,{variant:"outline",disabled:n,children:"取消"})}),e.jsx(E,{type:"submit",disabled:n,children:n?"保存中...":"保存"})]})]})})})]})}function Bn({mcpServerName:r,onRemoveSuccess:t,disabled:s=!1}){const[a,n]=o.useState(!1),i=async()=>{try{if(n(!0),!await At.removeServer(r))throw new Error("删除服务器失败");k.success(`MCP 服务 "${r}" 已删除`),t&&await t()}catch(c){console.error("删除 MCP 服务失败:",c),k.error(`删除 MCP 服务失败: ${c instanceof Error?c.message:"未知错误"}`)}finally{n(!1)}};return e.jsxs(Tt,{children:[e.jsx(dn,{asChild:!0,children:e.jsx(E,{variant:"destructive",size:"icon",className:"size-8",disabled:s||a,children:e.jsx(Ms,{className:"h-4 w-4"})})}),e.jsxs(Ye,{children:[e.jsxs(Xe,{children:[e.jsxs(tt,{children:["确定要删除这个(",r,")MCP服务吗?"]}),e.jsx(st,{children:"删除后,对应的工具列表也会移除。"})]}),e.jsxs(et,{children:[e.jsx(at,{children:"取消"}),e.jsx(rt,{onClick:i,disabled:s||a,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:a?"删除中...":"确定"})]})]})]})}function Ir({disabled:r=!1,variant:t="outline",className:s="",restartingText:a="重启中...",defaultText:n="重启服务"}){const{loading:{isRestarting:i},restartService:c}=pe(),m=Qs(),b=async()=>{try{await c()}catch(h){console.error("[RestartButton] 重启失败:",h)}},g=()=>i?m.enabled&&m.startTime?"重连中...":a:n;return e.jsxs(E,{type:"button",onClick:b,variant:t,disabled:i||r,className:Ks("flex items-center gap-2 w-[120px]",s),children:[i?e.jsx(ge,{className:"size-4 animate-spin"}):e.jsx(fa,{className:"size-4"}),g()]})}const Hn=Ue("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Je=o.forwardRef(({className:r,variant:t,...s},a)=>e.jsx("div",{ref:a,role:"alert",className:w(Hn({variant:t}),r),...s}));Je.displayName="Alert";const Or=o.forwardRef(({className:r,...t},s)=>e.jsx("h5",{ref:s,className:w("mb-1 font-medium leading-none tracking-tight",r),...t}));Or.displayName="AlertTitle";const Ke=o.forwardRef(({className:r,...t},s)=>e.jsx("div",{ref:s,className:w("text-sm [&_p]:leading-relaxed",r),...t}));Ke.displayName="AlertDescription";function qt(r){if(!r||typeof r!="object")return ct();switch(r.type){case"string":{if(r.enum)return Zs(r.enum);let t=xt();return r.minLength&&(t=t.min(r.minLength)),r.maxLength&&(t=t.max(r.maxLength)),r.pattern&&(t=t.regex(new RegExp(r.pattern))),t}case"number":case"integer":{let t=Ma();return r.type==="integer"&&(t=t.int()),typeof r.minimum=="number"&&(t=t.min(r.minimum)),typeof r.maximum=="number"&&(t=t.max(r.maximum)),typeof r.multipleOf=="number"&&(t=t.multipleOf(r.multipleOf)),t}case"boolean":return Gs();case"array":if(r.items){const t=qt(r.items);let s=Lt(t);return typeof r.minItems=="number"&&(s=s.min(r.minItems)),typeof r.maxItems=="number"&&(s=s.max(r.maxItems)),s}return Lt(ct());case"object":if(r.properties&&Object.keys(r.properties).length>0){const t={},s=r.required||[];for(const[a,n]of Object.entries(r.properties)){let i=qt(n);s.includes(a)||(i=i.optional()),t[a]=i}return yt(t)}return Pa(xt(),ct());default:return ct()}}function Ft(r){if(r)switch(r.type){case"string":return r.enum?r.enum[0]:"";case"number":case"integer":return 0;case"boolean":return!1;case"array":return[];case"object":if(r.properties){const t={};for(const[s,a]of Object.entries(r.properties))t[s]=Ft(a);return t}return{};default:return}}function Jn(r){if(!r||!r.properties)return{};const t={},s=r.required||[];for(const[a,n]of Object.entries(r.properties))if(s.includes(a))t[a]=Ft(n);else{const i=Ft(n);i!==void 0&&i!==""&&(t[a]=i)}return t}const Kn=o.memo(function({name:t,schema:s,form:a,renderFormField:n}){var g;const{fields:i,append:c,remove:m}=Fs({control:a.control,name:t}),b=()=>{const h=s.items;let p;switch(h.type){case"string":p=h.enum?h.enum[0]:"";break;case"number":case"integer":p=0;break;case"boolean":p=!1;break;case"array":p=[];break;case"object":p={};break;default:p=""}c(p)};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium",children:["数组项目 (",((g=s.items)==null?void 0:g.type)||"unknown",")"]}),e.jsxs(E,{type:"button",variant:"outline",size:"sm",onClick:b,className:"h-8 px-2",children:[e.jsx(Le,{className:"h-3 w-3 mr-1"}),"添加"]})]}),i.length===0?e.jsx("div",{className:"text-center py-4 border border-dashed rounded-md",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:"暂无数组项目"})}):e.jsx("div",{className:"space-y-3",children:i.map((h,p)=>e.jsxs("div",{className:"relative p-3 border rounded-md bg-muted/20",children:[e.jsx("div",{className:"absolute top-2 right-2",children:e.jsx(E,{type:"button",variant:"ghost",size:"sm",onClick:()=>m(p),className:"h-6 w-6 p-0 text-red-500 hover:text-red-700",children:e.jsx(Bs,{className:"h-3 w-3"})})}),e.jsxs("div",{className:"pr-8",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground mb-2 block",children:["项目 ",p+1]}),e.jsx(ee,{control:a.control,name:`${t}.${p}`,render:()=>e.jsx(Z,{children:(()=>{var d,u;return((d=s.items)==null?void 0:d.type)==="object"||((u=s.items)==null?void 0:u.type)==="array"?e.jsx("div",{className:"ml-6 border-l-2 border-muted pl-4",children:n(`${t}.${p}`,s.items)}):n(`${t}.${p}`,s.items)})()})})]})]},h.id))})]})}),Gn=o.memo(function({name:t,schema:s,form:a,renderFormField:n,getTypeBadge:i}){return!s.properties||Object.keys(s.properties).length===0?e.jsx("div",{className:"text-center py-4 border border-dashed rounded-md",children:e.jsx("span",{className:"text-sm text-muted-foreground",children:"对象无定义字段"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("span",{className:"text-sm font-medium",children:"对象字段"}),Object.entries(s.properties).map(([c,m])=>e.jsx("div",{className:"ml-6 border-l-2 border-muted pl-4",children:e.jsx(ee,{control:a.control,name:`${t}.${c}`,render:()=>{var b;return e.jsxs(Z,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ne,{children:[((b=s.required)==null?void 0:b.includes(c))&&e.jsx("span",{className:"text-red-500 mr-1",children:"*"}),c]}),e.jsx(te,{variant:"secondary",className:`text-xs ${i(m.type)}`,children:m.type}),m.description&&e.jsxs(Ct,{children:[e.jsx(kt,{children:e.jsx(Qt,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(Qe,{children:e.jsx("p",{className:"max-w-xs whitespace-pre-wrap",children:m.description})})]})]}),n(`${t}.${c}`,m),m.description&&e.jsx(Sr,{children:m.description}),e.jsx(ae,{})]})}})},`${t}-${c}`))]})}),Zn=o.memo(function(){return e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-4 max-w-sm mx-auto p-6",children:[e.jsx("div",{className:"mx-auto w-16 h-16 bg-green-100 rounded-full flex items-center justify-center",children:e.jsx(Ze,{className:"h-8 w-8 text-green-600"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"无需输入参数"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:'点击"调用工具"按钮执行,无需输入任何参数。'})]})]})})}),Qn=o.memo(function({tool:t,form:s,renderFormField:a}){var n;return(n=t==null?void 0:t.inputSchema)!=null&&n.properties?e.jsx(Ve,{...s,children:e.jsx(be,{className:"h-full",children:e.jsx("div",{className:"space-y-4 p-2",children:Object.entries(t.inputSchema.properties).map(([i,c])=>e.jsx(ee,{control:s.control,name:i,render:()=>{var m;return e.jsxs(Z,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ne,{children:[((m=t.inputSchema.required)==null?void 0:m.includes(i))&&e.jsx("span",{className:"text-red-500 mr-1",children:"*"}),i]}),e.jsx(te,{variant:"secondary",className:`text-xs ${c.type==="string"?"bg-blue-100 text-blue-800":c.type==="number"||c.type==="integer"?"bg-green-100 text-green-800":c.type==="boolean"?"bg-purple-100 text-purple-800":c.type==="array"?"bg-orange-100 text-orange-800":(c.type==="object","bg-gray-100 text-gray-800")}`,children:c.type}),c.description&&e.jsxs(Ct,{children:[e.jsx(kt,{children:e.jsx(Qt,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(Qe,{children:e.jsx("p",{className:"max-w-xs whitespace-pre-wrap",children:c.description})})]})]}),a(i,c),e.jsx(ae,{})]})}},`${t.name}-${i}`))})})}):e.jsxs("div",{className:"text-center py-8",children:[e.jsx(Gt,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-muted-foreground",children:"该工具无参数定义"})]})});function Yn({open:r,onOpenChange:t,tool:s}){var L,_,J;const[a,n]=o.useState("form"),[i,c]=o.useState(`{
31
+
32
+ }`),[m,b]=o.useState(null),[g,h]=o.useState(!1),[p,d]=o.useState(null),[u,f]=o.useState(!1),C=o.useMemo(()=>s!=null&&s.inputSchema?qt(s.inputSchema):yt({}),[s==null?void 0:s.inputSchema]),y=o.useMemo(()=>s!=null&&s.inputSchema?Jn(s.inputSchema):{},[s==null?void 0:s.inputSchema]),v=Ae({resolver:_e(C),defaultValues:y,mode:"onChange"});o.useEffect(()=>{if(s!=null&&s.inputSchema){v.reset(y);try{c(JSON.stringify(y,null,2))}catch{c(`{
33
+
34
+ }`)}}else v.reset({}),c(`{
35
+
36
+ }`)},[s==null?void 0:s.inputSchema,y,v]);const O=o.useCallback(()=>{n("form"),c(`{
37
+
38
+ }`),b(null),d(null),f(!1),s!=null&&s.inputSchema&&v.reset(y)},[s==null?void 0:s.inputSchema,y,v]),P=o.useCallback(l=>{if(l==="json"&&a==="form"){const x=v.getValues();try{c(JSON.stringify(x,null,2))}catch{c(`{
39
+
40
+ }`)}}else if(l==="form"&&a==="json")try{const x=JSON.parse(i);for(const j of Object.keys(x))v.setValue(j,x[j])}catch{}n(l)},[a,i,v]),$=o.useCallback(l=>{l||O(),t(l)},[t,O]),S=o.useCallback(l=>{try{return JSON.parse(l),!0}catch{return!1}},[]),R=o.useCallback(async()=>{var j;if(!s)return;let l;if(!((j=s==null?void 0:s.inputSchema)!=null&&j.properties)||Object.keys(s.inputSchema.properties).length===0)l={};else if(a==="form"){const N=v.getValues();if(!await v.trigger()){k.error("请检查表单中的错误");return}l=N}else{if(!S(i)){k.error("输入参数不是有效的JSON格式");return}l=JSON.parse(i)}h(!0),d(null),b(null);try{const N=await D.callTool(s.serverName,s.toolName,l);b(N),k.success("工具调用成功")}catch(N){const T=N instanceof Error?N.message:"调用工具失败";d(T),k.error(T)}finally{h(!1)}},[s,a,v,i,S]),A=o.useCallback(async()=>{const l=m?JSON.stringify(m,null,2):p||"";try{await navigator.clipboard.writeText(l),f(!0),k.success("已复制到剪贴板"),setTimeout(()=>f(!1),2e3)}catch{k.error("复制失败")}},[m,p]),V=o.useCallback(()=>{if(b(null),d(null),a==="form"&&(s!=null&&s.inputSchema)){v.reset(y);try{c(JSON.stringify(y,null,2))}catch{c(`{
41
+
42
+ }`)}}else c(`{
43
+
44
+ }`),s!=null&&s.inputSchema?v.reset(y):v.reset({})},[a,s==null?void 0:s.inputSchema,y,v]),Q=o.useMemo(()=>{const l=x=>({string:"bg-blue-100 text-blue-800",number:"bg-green-100 text-green-800",integer:"bg-green-100 text-green-800",boolean:"bg-purple-100 text-purple-800",array:"bg-orange-100 text-orange-800",object:"bg-gray-100 text-gray-800"})[x]||"bg-gray-100 text-gray-800";return(x,j)=>{switch(j.type){case"string":return j.enum?e.jsx(Me,{name:x,control:v.control,render:({field:N})=>e.jsxs($e,{value:N.value,onValueChange:N.onChange,children:[e.jsx(H,{children:e.jsx(Se,{children:e.jsx(We,{placeholder:`选择${x}`})})}),e.jsx(Ce,{children:j.enum.map(T=>e.jsx(oe,{value:T,children:T},T))})]})}):e.jsx(Me,{name:x,control:v.control,render:({field:N})=>e.jsx(H,{children:e.jsx(re,{...N,placeholder:`输入${x}`,type:j.format==="password"?"password":"text"})})});case"number":case"integer":return e.jsx(Me,{name:x,control:v.control,render:({field:N})=>e.jsx(H,{children:e.jsx(re,{...N,type:"number",placeholder:`输入${x}`,step:j.type==="integer"?"1":"0.1",onChange:T=>{const Y=T.target.value;N.onChange(Y===""?"":Number(Y))}})})});case"boolean":return e.jsx(Me,{name:x,control:v.control,render:({field:N})=>{var T;return e.jsxs($e,{value:(T=N.value)==null?void 0:T.toString(),onValueChange:Y=>N.onChange(Y==="true"),children:[e.jsx(H,{children:e.jsx(Se,{children:e.jsx(We,{placeholder:`选择${x}`})})}),e.jsxs(Ce,{children:[e.jsx(oe,{value:"true",children:"true"}),e.jsx(oe,{value:"false",children:"false"})]})]})}});case"array":return e.jsx(Kn,{name:x,schema:j,form:v,renderFormField:Q});case"object":return e.jsx(Gn,{name:x,schema:j,form:v,renderFormField:Q,getTypeBadge:l});default:return e.jsx(Me,{name:x,control:v.control,render:({field:N})=>e.jsx(H,{children:e.jsx(re,{...N,placeholder:`输入${x}`})})})}}},[v]),me=o.useCallback(l=>{try{return JSON.stringify(l,null,2)}catch{return String(l)}},[]),fe=o.useCallback(()=>typeof window>"u"||/Mac|iPhone|iPad|iPod/.test(navigator.platform)?"⌘+Enter":"Ctrl+Enter",[]),I=o.useCallback(async l=>{var N;if((/Mac|iPhone|iPad|iPod/.test(navigator.platform)?l.metaKey&&l.key==="Enter":l.ctrlKey&&l.key==="Enter")&&r&&!g){if(l.preventDefault(),!(!((N=s==null?void 0:s.inputSchema)!=null&&N.properties)||Object.keys(s.inputSchema.properties).length===0)&&a==="json"&&!S(i)){k.error("输入参数不是有效的JSON格式");return}await R()}},[r,g,a,i,S,R,(L=s==null?void 0:s.inputSchema)==null?void 0:L.properties]);return o.useEffect(()=>{if(r)return window.addEventListener("keydown",I),()=>{window.removeEventListener("keydown",I)}},[r,I]),e.jsx(ue,{open:r,onOpenChange:$,children:e.jsx(Xt,{children:e.jsxs(ie,{className:"max-w-4xl max-h-[90vh] flex flex-col",children:[e.jsx(ce,{children:e.jsxs(le,{className:"flex items-center gap-2",children:[e.jsx(Hs,{className:"h-5 w-5"}),"工具调试"]})}),s&&e.jsxs("div",{className:"flex flex-col gap-4 h-[80vh]",children:[e.jsxs(de,{children:[e.jsx(De,{className:"pb-0",children:e.jsxs(ze,{className:"text-base flex items-center gap-2",children:[e.jsx(te,{variant:"secondary",children:s.serverName}),s.toolName]})}),e.jsx(ye,{children:s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:s.description})})]}),e.jsxs("div",{className:"flex-1 flex min-h-0 w-full overflow-hidden",children:[e.jsxs("div",{className:"w-1/2 flex flex-col gap-2 flex-shrink-0 overflow-hidden pr-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between h-[40px]",children:[e.jsx("h3",{className:"text-sm font-medium",children:"输入参数"}),((_=s==null?void 0:s.inputSchema)==null?void 0:_.properties)&&Object.keys(s.inputSchema.properties).length>0&&e.jsx(gt,{value:a,onValueChange:l=>P(l),children:e.jsxs(Mt,{className:"grid w-full grid-cols-2",children:[e.jsx(we,{value:"form",className:"text-xs",children:"表单模式"}),e.jsx(we,{value:"json",className:"text-xs",children:"高级模式"})]})})]}),e.jsx("div",{className:"flex-1 min-h-0",children:(J=s==null?void 0:s.inputSchema)!=null&&J.properties&&Object.keys(s.inputSchema.properties).length>0?e.jsxs(gt,{value:a,onValueChange:l=>P(l),className:"h-full flex flex-col",children:[e.jsx(je,{value:"form",className:"flex-1 data-[state=active]:flex data-[state=active]:flex-col mt-0",children:e.jsx(Qn,{tool:s,form:v,renderFormField:Q})}),e.jsx(je,{value:"json",className:"flex-1 data-[state=active]:flex data-[state=active]:flex-col mt-0",children:e.jsxs("div",{className:"flex-1 flex flex-col",children:[e.jsx(It,{value:i,onChange:l=>c(l.target.value),placeholder:"请输入JSON格式的参数...",className:"flex-1 font-mono text-sm resize-none min-h-[200px]",disabled:g}),!S(i)&&i.trim()!==`{
45
+
46
+ }`&&e.jsxs(Je,{className:"mt-2",children:[e.jsx(He,{className:"h-4 w-4"}),e.jsx(Ke,{children:"JSON格式错误,请检查输入"})]})]})})]}):e.jsx(Zn,{})})]}),e.jsxs("div",{className:"w-1/2 flex flex-col gap-2 flex-shrink-0 overflow-hidden pl-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between h-[40px]",children:[e.jsx("h3",{className:"text-sm font-medium",children:"调用结果"}),(m||p)&&e.jsx(E,{variant:"outline",size:"sm",onClick:A,className:"gap-0",children:u?e.jsxs(e.Fragment,{children:[e.jsx(Ze,{className:"h-4 w-4 mr-1"}),"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"h-4 w-4 mr-1"}),"复制结果"]})})]}),e.jsx("div",{className:"flex-1 min-h-0",children:g?e.jsx("div",{className:"h-full flex items-center justify-center border rounded-md",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(ge,{className:"h-8 w-8 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"正在调用工具..."})]})}):p?e.jsx("div",{className:"h-full",children:e.jsx(Je,{variant:"destructive",className:"h-full",children:e.jsx(Ke,{className:"font-mono text-sm whitespace-pre-wrap break-words",children:p})})}):m?e.jsx(be,{className:"h-full border rounded-md",children:e.jsx("pre",{className:"p-3 text-sm font-mono whitespace-pre-wrap break-words min-w-0",children:me(m)})}):e.jsx("div",{className:"h-full flex items-center justify-center border rounded-md",children:e.jsxs("div",{className:"text-center text-muted-foreground",children:[e.jsx(Gt,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"等待调用工具..."})]})})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4 border-t",children:[e.jsxs(E,{variant:"outline",onClick:V,disabled:g,children:[e.jsx(ha,{className:"h-4 w-4"}),"清空"]}),e.jsx(E,{onClick:R,disabled:g||(()=>{var x;return!(!((x=s==null?void 0:s.inputSchema)!=null&&x.properties)||Object.keys(s.inputSchema.properties).length===0)&&a==="json"&&!S(i)})(),children:g?e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"h-4 w-4 mr-2 animate-spin"}),"调用中..."]}):e.jsxs(e.Fragment,{children:[e.jsx(pa,{className:"h-4 w-4"}),(()=>{var x;return!((x=s==null?void 0:s.inputSchema)!=null&&x.properties)||Object.keys(s.inputSchema.properties).length===0?"直接调用":"调用工具"})()," (",fe(),")"]})})]})]})]})})})}const Wt="未知服务",Xn="自定义服务";function eo({updateConfig:r}){const t=fn(),s=hr(),{refreshConfig:a}=pr(),[n,i]=o.useState([]),[c,m]=o.useState([]),[b,g]=o.useState(!1),[h,p]=o.useState(null),d=o.useCallback((l,x)=>{var T,Y;const{serviceName:j,toolName:N}=(()=>{var xe,Ne;return!l||!l.handler?{serviceName:Wt,toolName:(l==null?void 0:l.name)||Wt}:l.handler.type==="mcp"?{serviceName:((xe=l.handler.config)==null?void 0:xe.serviceName)||Wt,toolName:((Ne=l.handler.config)==null?void 0:Ne.toolName)||l.name}:l.handler.type==="proxy"&&l.handler.platform==="coze"?{serviceName:"customMCP",toolName:l.name}:{serviceName:Xn,toolName:l.name}})();return{serverName:j,toolName:N,enable:x,name:l.name,description:l.description,usageCount:(T=l.stats)==null?void 0:T.usageCount,lastUsedTime:(Y=l.stats)==null?void 0:Y.lastUsedTime,inputSchema:l.inputSchema}},[]),u=o.useCallback(async()=>{g(!0),p(null);try{const[l,x]=await Promise.all([D.getToolsList("enabled"),D.getToolsList("disabled")]),j=l.map(T=>d(T,!0)),N=x.map(T=>d(T,!1));i(j),m(N)}catch(l){console.error("获取工具列表失败:",l);const x=l instanceof Error?l.message:"获取工具列表失败";if(p(x),k.error(x),t){const j=Object.entries(t).flatMap(([Y,xe])=>Object.entries((xe==null?void 0:xe.tools)||{}).map(([Ne,M])=>({serverName:Y,toolName:Ne,...M}))),N=j.filter(Y=>Y.enable!==!1),T=j.filter(Y=>Y.enable===!1);i(N),m(T)}}finally{g(!1)}},[t,d]),[f,C]=o.useState(!1),y=o.useCallback(async()=>{if(!f)try{C(!0),await Promise.all([a(),u()])}catch(l){console.error("刷新数据失败:",l),k.error("刷新数据失败")}finally{C(!1)}},[a,u,f]),v=o.useCallback(async()=>{try{const[l,x]=await Promise.all([D.getToolsList("enabled"),D.getToolsList("disabled")]),j=l.map(T=>d(T,!0)),N=x.map(T=>d(T,!1));i(j),m(N)}catch(l){console.error("刷新工具列表失败:",l),k.error("刷新工具列表失败")}},[d]);o.useEffect(()=>{u()},[u]);const[O,P]=o.useState(null),[$,S]=o.useState({open:!1}),[R,A]=o.useState({open:!1}),V=async(l,x)=>{try{if(x){const j=[...n,...c].find(N=>N.name===l);if(!j){k.error("找不到对应的工具信息");return}if(j.serverName==="coze"){P(l);return}await D.removeCustomTool(l),k.success(`删除工具 ${l} 成功`)}else{const j=[...n,...c].find(N=>N.name===l);if(!j){k.error("找不到对应的工具信息");return}j.serverName==="coze"?await D.addCustomTool({workflow_id:"",workflow_name:l,description:j.description||"",icon_url:"",app_id:""},l,j.description||""):await D.addCustomTool({type:"mcp",data:{serviceName:j.serverName,toolName:j.toolName,customName:l,customDescription:j.description||""}}),k.success(`添加工具 ${l} 成功`)}await v()}catch(j){console.error("切换工具状态失败:",j),k.error(j instanceof Error?j.message:"切换工具状态失败")}},Q=async()=>{if(O)try{await D.removeCustomTool(O),k.success(`删除工具 ${O} 成功`),await v()}catch(l){console.error("删除 Coze 工具失败:",l),k.error(l instanceof Error?l.message:"删除 Coze 工具失败")}finally{P(null)}},me=()=>{P(null)},fe=l=>{l.serverName==="coze"&&S({open:!0,tool:l})},I=l=>{A({open:!0,tool:{name:l.name,serverName:l.serverName,toolName:l.toolName,description:l.description,inputSchema:l.inputSchema}})},L=l=>{var x,j,N;return l.serverName==="coze"&&((x=l.handler)==null?void 0:x.type)==="proxy"?{workflow_id:((j=l.handler.config)==null?void 0:j.workflow_id)||"",workflow_name:l.toolName,description:l.description||"",icon_url:"",app_id:((N=l.handler.config)==null?void 0:N.app_id)||"",creator:{id:"",name:""},created_at:0,updated_at:0,isAddedAsTool:!0,toolName:l.name,inputSchema:l.inputSchema}:{workflow_id:"",workflow_name:l.toolName,description:l.description||"",icon_url:"",app_id:"",creator:{id:"",name:""},created_at:0,updated_at:0,isAddedAsTool:!0,toolName:l.name,inputSchema:l.inputSchema}},_=async(l,x)=>{if($.tool)try{const j=x.length>0?{parameters:x}:void 0,N=L($.tool);l.workflow_id&&(N.workflow_id=l.workflow_id),l.app_id&&(N.app_id=l.app_id);const T={type:"coze",data:{workflow:N,customName:void 0,customDescription:void 0,parameterConfig:j}};await D.updateCustomTool($.tool.name,T),k.success(`工具 "${N.workflow_name}" 参数配置更新成功`),await v()}catch(j){console.error("更新工具参数配置失败:",j);let N="更新工具参数配置失败,请重试";j instanceof Error&&(N=j.message),k.error(N)}finally{S({open:!1})}},J=()=>{S({open:!1})};return!s||Object.keys(s).length===0?e.jsx("div",{className:"@container/main flex flex-1 flex-col gap-2",children:e.jsxs("div",{className:"flex flex-col gap-4 py-4 md:gap-6 md:py-6",children:[e.jsx("div",{className:"flex items-center justify-between px-4 lg:px-6",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"你的聚合 MCP 服务"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"在这里管理你的 MCP 服务器和工具。"})]})}),e.jsx("div",{className:"px-4 lg:px-6",children:e.jsx(de,{className:"border-dashed",children:e.jsxs(ye,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(cs,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"还没有 MCP 服务"}),e.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"添加你的第一个 MCP 服务器来开始使用强大的工具集成功能。"}),e.jsx(ps,{})]})})})]})}):e.jsxs("div",{className:"flex flex-col gap-4 px-4 lg:px-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"你的聚合 MCP 服务"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"你可以在这里管理你的 MCP 服务,包括启用/禁用工具,以及查看工具的详细信息。"})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"}),"刷新中..."]})]}),e.jsxs("div",{className:"*:data-[slot=card]:shadow-xs @xl/main:grid-cols-8 @5xl/main:grid-cols-8 grid grid-cols-1 gap-4 *:data-[slot=card]:bg-gradient-to-t *:data-[slot=card]:from-primary/5 *:data-[slot=card]:to-card dark:*:data-[slot=card]:bg-card",children:[e.jsx(de,{className:"transition-all duration-200 col-span-3",children:e.jsx(ye,{className:"p-4",children:e.jsxs("div",{className:"flex-col",children:[e.jsxs("h4",{className:"text-sm font-medium mb-3 flex items-center gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),"使用中的工具 (",n.length,")",b&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(加载中...)"})]}),e.jsx("div",{className:"flex-1 space-y-2",children:b?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"加载工具列表中..."})}):h?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 px-4",children:[e.jsx("div",{className:"text-sm text-red-500 mb-2",children:h}),e.jsx(E,{variant:"outline",size:"sm",onClick:u,children:"重试"})]}):n.map(l=>e.jsxs("div",{className:"flex items-start justify-between p-4 bg-slate-50 rounded-md font-mono",children:[e.jsxs("div",{className:"text-md flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 justify-start",children:[e.jsx(te,{variant:"secondary",className:"rounded-md",children:l.serverName}),e.jsx("span",{children:l.toolName})]}),e.jsx("p",{className:"text-sm text-muted-foreground my-2",children:l.description}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"text-muted-foreground",children:"使用次数:"})," ",e.jsx("span",{className:"text-primary font-bold",children:l.usageCount||0})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"text-muted-foreground",children:"最后使用:"})," ",e.jsx("span",{className:"text-primary font-bold",children:l.lastUsedTime||"-"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[l.serverName==="customMCP"&&e.jsx(E,{variant:"secondary",size:"icon",className:"size-8 hover:bg-blue-500 hover:text-white",onClick:()=>fe(l),title:"配置参数",children:e.jsx(Ge,{size:16})}),e.jsx(E,{variant:"secondary",size:"icon",className:"size-8 hover:bg-blue-500 hover:text-white",onClick:()=>I(l),title:"调试工具",children:e.jsx(Hs,{size:18})}),e.jsx(E,{variant:"secondary",size:"icon",className:"size-8 hover:bg-red-500 hover:text-white",onClick:()=>V(l.name,!0),children:e.jsx(xa,{size:18})})]})]},l.toolName))})]})})}),e.jsx(de,{className:"transition-all duration-200 col-span-3",children:e.jsx(ye,{className:"p-4",children:e.jsxs("div",{className:"flex-col",children:[e.jsxs("h4",{className:"text-sm font-medium mb-3 flex items-center gap-2",children:[e.jsx(ls,{className:"h-4 w-4"}),"未使用的工具 (",c.length,")",b&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(加载中...)"})]}),e.jsx("div",{className:"flex-1 space-y-2",children:b?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"加载工具列表中..."})}):h?e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 px-4",children:[e.jsx("div",{className:"text-sm text-red-500 mb-2",children:h}),e.jsx(E,{variant:"outline",size:"sm",onClick:u,children:"重试"})]}):c.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-4 py-20 px-4 bg-slate-50 rounded-md font-mono h-full",children:[e.jsx(cs,{strokeWidth:1.5,size:48,className:"text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"全部工具都已经启用"})]}):c.map(l=>e.jsxs("div",{className:"flex items-start justify-between p-4 bg-slate-50 rounded-md font-mono",children:[e.jsxs("div",{className:"text-md flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 justify-start",children:[e.jsx(te,{variant:"secondary",className:"rounded-md",children:l.serverName}),e.jsx("span",{children:l.toolName})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l.description}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"text-muted-foreground",children:"使用次数:"})," ",e.jsx("span",{className:"text-primary font-bold",children:l.usageCount||0})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"text-muted-foreground",children:"最后使用:"})," ",e.jsx("span",{className:"text-primary font-bold",children:l.lastUsedTime||"-"})]})]})]}),e.jsx("div",{className:"flex items-center gap-2 ml-4",children:e.jsx(E,{variant:"secondary",size:"icon",className:"size-8 hover:bg-green-500 hover:text-white",onClick:()=>V(l.name,!1),children:e.jsx(Le,{className:"h-4 w-4"})})})]},l.toolName))})]})})}),e.jsxs("div",{className:"transition-all duration-200 gap-4 flex flex-col col-span-2",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ps,{}),e.jsx(Ir,{})]}),e.jsx(Vn,{onToolAdded:v})]}),Object.entries(s||{}).map(([l,x])=>e.jsxs(de,{className:"transition-all duration-200",children:[e.jsx(ye,{className:"p-0",children:e.jsx("div",{className:"p-4 pb-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx("div",{className:"flex items-start gap-4 flex-1",children:e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("h3",{className:"text-lg font-semibold",children:l})})})}),e.jsxs("div",{className:"flex items-center gap-2 ml-4",children:[e.jsx(Fn,{mcpServerName:l,mcpServer:x}),e.jsx(Bn,{mcpServerName:l,onRemoveSuccess:y,disabled:f})]})]})})}),e.jsx(Be,{className:"p-4 pt-2",children:e.jsx(te,{variant:"outline",className:"text-xs",children:Vt(x)})})]},l))]})]}),e.jsx(Tt,{open:O!==null,onOpenChange:l=>!l&&P(null),children:e.jsxs(Ye,{children:[e.jsxs(Xe,{children:[e.jsx(tt,{children:"确认移除 Coze 工作流工具"}),e.jsxs(st,{children:['移除后需要通过【工作流集成】重新添加并配置入参,确定要移除工具 "',O,'" 吗?']})]}),e.jsxs(et,{children:[e.jsx(at,{onClick:me,children:"取消"}),e.jsx(rt,{onClick:Q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"确认移除"})]})]})}),$.tool&&e.jsx(Rr,{open:$.open,onOpenChange:l=>S(x=>({...x,open:l})),workflow:$.tool,onConfirm:_,onCancel:J,title:"配置工作流参数"}),e.jsx(Yn,{open:R.open,onOpenChange:l=>A(x=>({...x,open:l})),tool:R.tool||null})]})}const to=({size:r=24,color:t="currentColor",...s})=>e.jsx("svg",{width:r,height:r,viewBox:"0 0 1024 1024",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...s,children:e.jsx("path",{d:"M980.79827 694.105946c-21.144216-122.796973-109.844757-203.250162-109.844757-203.250162 12.647784-111.477622-33.792-131.26573-33.792-131.26573C827.392 14.668108 530.985514 20.67373 524.730811 20.839784 518.476108 20.67373 222.01427 14.668108 212.300108 359.590054c0 0-46.467459 19.788108-33.819676 131.26573 0 0-88.700541 80.453189-109.817081 203.250162 0 0-11.291676 207.484541 101.403676 25.40627 0 0 25.350919 69.161514 71.790703 131.26573 0 0-83.082378 28.256865-75.997405 101.625081 0 0-2.87827 81.836973 177.401081 76.218811 0 0 126.699243-9.852541 164.753297-63.515676l16.605405 0 0.276757 0 16.633081 0c38.026378 53.635459 164.725622 63.515676 164.725622 63.515676 180.224 5.618162 177.401081-76.218811 177.401081-76.218811 7.029622-73.368216-75.997405-101.625081-75.997405-101.625081 46.439784-62.104216 71.790703-131.26573 71.790703-131.26573C992.034595 901.590486 980.79827 694.105946 980.79827 694.105946z"})}),so=({size:r=24,color:t="currentColor",...s})=>e.jsx("svg",{width:r,height:r,viewBox:"0 0 1024 1024",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...s,children:e.jsx("path",{d:"M0 524.992q0 166.016 95.488 298.496t247.488 185.504q6.016 0.992 10.016 0.992t6.496-1.504 4-3.008 2.016-4.992 0.512-4.992v-100.512q-36.992 4-66.016-0.512t-45.504-14.016-28.992-23.488-16.992-25.504-8.992-24-5.504-14.496q-8.992-15.008-27.008-27.488t-27.008-20-2.016-14.496q50.016-26.016 112.992 66.016 34.016 51.008 119.008 30.016 10.016-40.992 40-70.016Q293.984 736 237.984 670.976t-56-158.016q0-87.008 55.008-151.008-22.016-64.992 6.016-136.992 28.992-2.016 64.992 11.488t50.496 23.008 25.504 17.504q56.992-16 128.512-16t129.504 16q12.992-8.992 28.992-19.008t48.992-21.504 60.992-9.504q27.008 71.008 7.008 135.008 56 64 56 151.008 0 92.992-56.992 158.496t-172 85.504q43.008 43.008 43.008 104v128.992q0 0.992 0.992 3.008 0 6.016 0.512 8.992t4.512 6.016 12 3.008q152.992-52 250.496-185.504t97.504-300.512q0-104-40.512-199.008t-108.992-163.488-163.488-108.992T512.032 12.96 313.024 53.472 149.536 162.464t-108.992 163.488-40.512 199.008z","p-id":"4674"})});function Dr(){const[r,t]=o.useState({status:"idle",logs:[]});o.useEffect(()=>{const b=W.subscribe("data:npmInstallStarted",d=>{console.log("[useNPMInstall] 安装开始:",d),t({status:"installing",version:d.version,installId:d.installId,logs:[]})}),g=W.subscribe("data:npmInstallLog",d=>{console.log("[useNPMInstall] 收到日志:",d),t(u=>u.installId===d.installId?{...u,logs:[...u.logs,{type:d.type,message:d.message,timestamp:d.timestamp}]}:u)}),h=W.subscribe("data:npmInstallCompleted",d=>{console.log("[useNPMInstall] 安装完成:",d),t(u=>u.installId===d.installId?{...u,status:"completed",duration:d.duration}:u)}),p=W.subscribe("data:npmInstallFailed",d=>{console.log("[useNPMInstall] 安装失败:",d),t(u=>u.installId===d.installId?{...u,status:"failed",error:d.error,duration:d.duration}:u)});return()=>{b(),g(),h(),p()}},[]);const s=o.useCallback(async b=>{var g;try{console.log("[useNPMInstall] 开始安装版本:",b);const p=await(await fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({version:b})})).json();if(!p.success)throw new Error(((g=p.error)==null?void 0:g.message)||"安装请求失败");return console.log("[useNPMInstall] 安装请求已接受:",p),p}catch(h){throw console.error("[useNPMInstall] 安装请求失败:",h),t(p=>({...p,status:"failed",error:h instanceof Error?h.message:"未知错误"})),h}},[]),a=o.useCallback(()=>{console.log("[useNPMInstall] 清除安装状态"),t({status:"idle",logs:[]})},[]),n=o.useCallback(()=>{switch(r.status){case"installing":return`正在安装 xiaozhi-client@${r.version}...`;case"completed":return"安装完成!";case"failed":return`安装失败: ${r.error}`;default:return""}},[r]),i=o.useCallback(()=>{switch(r.status){case"installing":return"text-blue-600";case"completed":return"text-green-600";case"failed":return"text-red-600";default:return"text-gray-600"}},[r]),c=o.useCallback(()=>r.status==="installing",[r.status]),m=o.useCallback(()=>r.status!=="installing",[r.status]);return{installStatus:r,startInstall:s,clearStatus:a,getStatusText:n,getStatusColor:i,isInstalling:c,canCloseDialog:m}}const zr=o.forwardRef(({className:r,value:t,status:s="idle",...a},n)=>{const i=()=>{switch(s){case"installing":return"bg-blue-500";case"completed":return"bg-green-500";case"failed":return"bg-red-500";default:return"bg-gray-300"}};return e.jsx("div",{ref:n,className:w("relative h-4 w-full overflow-hidden rounded-full bg-gray-200 dark:bg-gray-800",r),...a,children:e.jsx("div",{className:w("h-full transition-all duration-300 ease-in-out",i()),style:{width:`${t||0}%`}})})});zr.displayName="Progress";function $r({isOpen:r,onClose:t,version:s}){const{installStatus:a,startInstall:n,clearStatus:i,isInstalling:c,canCloseDialog:m}=Dr(),b=o.useRef(null),[g,h]=o.useState(!1);o.useEffect(()=>{r&&s&&(console.log("[InstallLogDialog] 对话框打开,开始安装版本:",s),i(),n(s).catch(P=>{console.error("[InstallLogDialog] 启动安装失败:",P)}))},[r,s,n,i]),o.useEffect(()=>{const P=setTimeout(()=>{b.current&&(b.current.scrollTop=b.current.scrollHeight)},100);return()=>clearTimeout(P)});const p=()=>{switch(a.status){case"idle":return 0;case"installing":return Math.min(90,a.logs.length*2);case"completed":return 100;case"failed":return 100;default:return 0}},d=()=>{switch(a.status){case"installing":return"正在安装...";case"completed":return"安装完成";case"failed":return"安装失败";default:return"准备安装"}},u=()=>{switch(a.status){case"installing":return e.jsx(ds,{className:"h-4 w-4 animate-pulse"});case"completed":return e.jsx(pt,{className:"h-4 w-4 text-green-600"});case"failed":return e.jsx(Kt,{className:"h-4 w-4 text-red-600"});default:return null}},f=()=>{switch(a.status){case"installing":return"default";case"completed":return"secondary";case"failed":return"destructive";default:return"outline"}},C=P=>{let $=P;const S=[/\[0m/g,/\[31m/g,/\[32m/g,/\[33m/g,/\[34m/g,/\[35m/g,/\[36m/g,/\[37m/g,/\[90m/g,/\[91m/g,/\[92m/g,/\[93m/g,/\[94m/g,/\[95m/g,/\[96m/g,/\[97m/g];for(const R of S)$=$.replace(R,"");return $.split(`
47
+ `).filter(R=>R.trim()).map((R,A)=>e.jsx("div",{className:"leading-relaxed",children:R},`${R.slice(0,20)}-${A}`))},y=()=>{m()?(i(),t()):k.error("安装过程中无法关闭对话框,请等待安装完成")},v=P=>{P.key==="Escape"&&m()&&y()},O=()=>{h(!g)};return e.jsx(ue,{open:r,onOpenChange:y,children:e.jsxs(ie,{className:"max-w-2xl max-h-[80vh] flex flex-col",onKeyDown:v,children:[e.jsx(ce,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(le,{className:"text-lg font-semibold",children:"正在安装"}),a.status!=="idle"&&e.jsxs(te,{variant:f(),className:"flex items-center gap-1",children:[u(),d()]})]})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium",children:"安装进度"}),a.version&&e.jsxs(te,{variant:"outline",className:"text-xs",children:["v",a.version]})]}),e.jsx(zr,{value:p(),status:a.status,className:"w-full h-2"}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:d()}),a.duration&&e.jsxs("span",{children:["耗时: ",(a.duration/1e3).toFixed(1),"s"]})]})]}),a.status==="failed"&&e.jsx(Je,{variant:"destructive",children:e.jsx(Ke,{children:"安装失败,请查看详细日志了解具体原因。"})}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:O,className:"flex w-full items-center justify-between h-auto p-0 gap-0 hover:bg-none bg-none text-sm mb-2",children:[e.jsx("h4",{className:"font-medium",children:"安装日志"}),e.jsx("div",{className:"flex items-center gap-1",children:g?e.jsxs(e.Fragment,{children:["收起 ",e.jsx(Ls,{className:"h-4 w-4"})]}):e.jsxs(e.Fragment,{children:["展开 ",e.jsx(Zt,{className:"h-4 w-4"})]})})]}),g&&e.jsx(be,{ref:b,className:"h-[300px] w-full rounded-md border bg-background",children:e.jsx("div",{className:"p-4 font-mono text-xs",children:a.logs.length===0?e.jsxs("div",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(ds,{className:"h-4 w-4 animate-pulse"}),"等待日志输出..."]}):e.jsx("div",{className:"space-y-1",children:a.logs.map(P=>e.jsx("div",{className:`${P.type==="stderr"?"text-orange-600":"text-foreground"} break-words`,children:C(P.message)},`${P.timestamp}-${P.message.slice(0,50)}`))})})})]})]}),e.jsx(Te,{className:"flex items-center justify-between pt-4 border-t",children:e.jsxs("div",{className:"flex gap-2",children:[a.status==="completed"&&e.jsxs(E,{variant:"outline",onClick:()=>window.location.reload(),className:"flex items-center gap-2",children:[e.jsx(pt,{className:"h-4 w-4"}),"重启应用"]}),e.jsx(E,{onClick:y,disabled:!m(),variant:a.status==="failed"?"destructive":"default",children:c()?"安装中...":a.status==="completed"?"完成":(a.status==="failed","关闭")})]})})]})})}const ro=[{value:"stable",label:"正式版"},{value:"rc",label:"预览版"},{value:"beta",label:"测试版"},{value:"all",label:"全部版本"}];function xs({children:r,defaultSelectedVersion:t}){const[s,a]=o.useState(!1),[n,i]=o.useState(""),[c,m]=o.useState("stable"),[b,g]=o.useState(!1),[h,p]=o.useState([]),[d,u]=o.useState(!1),{startInstall:f}=Dr(),C=o.useCallback(async S=>{try{u(!0);const R=await D.getAvailableVersions(S),A=R.versions.map(V=>({value:V,label:`v${V}`}));p(A),console.log(`[VersionUpgradeDialog] 获取到 ${R.total} 个${S}版本`),t&&R.versions.includes(t||"")&&i(t||"")}catch(R){console.error("[VersionUpgradeDialog] 获取版本列表失败:",R),p([])}finally{u(!1)}},[t]);o.useEffect(()=>{s&&C(c)},[s,c,C]);const y=S=>{m(S),i("")},v=S=>{i(S)},O=async()=>{if(n)try{console.log("[VersionUpgradeDialog] 开始安装版本:",n),a(!1),g(!0),await f(n)}catch(S){console.error("[VersionUpgradeDialog] 安装失败:",S),g(!1)}},P=()=>{g(!1),i("")},$=S=>{S||(i(""),m("stable")),a(S)};return e.jsxs(e.Fragment,{children:[e.jsxs(ue,{open:s,onOpenChange:$,children:[e.jsx(Ee,{asChild:!0,children:r||e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(Js,{className:"h-4 w-4"}),"升级版本"]})}),e.jsxs(ie,{className:"sm:max-w-md",children:[e.jsxs(ce,{children:[e.jsx(le,{children:"选择安装版本"}),e.jsx(ve,{children:"请选择要安装的 xiaozhi-client 版本"})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"version-select",className:"text-sm font-medium",children:"版本选择"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($e,{value:c,onValueChange:y,children:[e.jsx(Se,{id:"version-type-select",className:"w-[150px]",children:e.jsx(We,{placeholder:"请选择版本类型"})}),e.jsx(Ce,{children:ro.map(S=>e.jsx(oe,{value:S.value,children:S.label},S.value))})]}),e.jsxs($e,{value:n,onValueChange:v,disabled:d,children:[e.jsx(Se,{id:"version-select",children:e.jsx(We,{placeholder:d?"正在获取版本列表...":"请选择版本"})}),e.jsx(Ce,{children:d?e.jsx(oe,{value:"loading",disabled:!0,children:"正在获取版本列表..."}):h.length===0?e.jsx(oe,{value:"empty",disabled:!0,children:"暂无可用版本"}):h.map(S=>e.jsx(oe,{value:S.value,children:S.label},S.value))})]})]}),!d&&h.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"当前版本类型暂无可用版本"}),n&&Ra.lt(n,"1.8.0")&&e.jsxs(Je,{variant:"destructive",children:[e.jsx(ga,{size:18}),e.jsx(Or,{children:"重要提醒"}),e.jsx(Ke,{children:"指定版本低于1.8.0,安装后无法再使用Web界面重装,需手动通过命令操作,请谨慎操作!"})]})]})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(E,{variant:"outline",onClick:()=>a(!1),children:"取消"}),e.jsx(E,{onClick:O,disabled:!n||d,children:"确定安装"})]})]})]}),e.jsx($r,{isOpen:b,onClose:P,version:n})]})}function Wr({className:r}){const[t,s]=o.useState(null),[a,n]=o.useState(null),[i,c]=o.useState(!0),[m,b]=o.useState(!0),[g,h]=o.useState(null),[p,d]=o.useState(!1);o.useEffect(()=>{(async()=>{try{c(!0),h(null);const v=await D.getVersion();s(v)}catch(v){h(v instanceof Error?v.message:"获取版本信息失败"),console.error("获取版本信息失败:",v)}finally{c(!1)}})()},[]),o.useEffect(()=>{t&&(async()=>{try{b(!0);const v=await D.getLatestVersion();n(v)}catch(v){console.error("检查更新失败:",v),n({currentVersion:(t==null?void 0:t.version)||"unknown",latestVersion:null,hasUpdate:!1,error:v instanceof Error?v.message:"检查更新失败"})}finally{b(!1)}})()},[t]);const u=async()=>{if(t!=null&&t.version)try{await navigator.clipboard.writeText(t.version),d(!0),setTimeout(()=>d(!1),2e3)}catch(y){console.error("复制版本号失败:",y)}};if(i)return e.jsx(te,{variant:"outline",className:r,children:e.jsx("span",{className:"text-xs",children:"加载中..."})});if(g||!t)return e.jsx(te,{variant:"outline",className:r,children:e.jsx("span",{className:"text-xs text-muted-foreground",children:"版本未知"})});const f=e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{className:"h-3 w-3"}),e.jsx("span",{className:"font-semibold",children:"版本详情"})]}),e.jsxs("div",{className:"text-xs space-y-0.5",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"名称:"})," ",t.name]}),e.jsxs("div",{children:[e.jsx("strong",{children:"版本:"})," ",t.version]}),a&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("strong",{children:"最新版本:"})," ",a.latestVersion||"未知"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"状态:"}),m?"检查中...":a.hasUpdate?"有新版本":"已是最新"]})]}),e.jsxs("div",{children:[e.jsx("strong",{children:"描述:"})," ",t.description]}),e.jsxs("div",{children:[e.jsx("strong",{children:"作者:"})," ",t.author]})]}),e.jsx("div",{className:"pt-1 border-t",children:e.jsxs("button",{type:"button",onClick:u,className:"text-xs text-primary hover:underline flex items-center gap-1",children:[e.jsx(Nt,{className:"h-3 w-3"}),p?"已复制!":"复制版本号"]})})]}),C=()=>m?null:a!=null&&a.hasUpdate&&a.latestVersion?e.jsx(xs,{defaultSelectedVersion:a.latestVersion,children:e.jsxs(E,{variant:"link",className:"p-0 gap-1",children:[e.jsx(ba,{}),"升级版本"]})}):e.jsx(xs,{defaultSelectedVersion:t.version,children:e.jsx(E,{variant:"link",className:"p-0 gap-1",children:"切换版本"})});return e.jsx(Xt,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[C(),e.jsxs(Ct,{children:[e.jsx(kt,{asChild:!0,children:e.jsxs("span",{className:"text-sm cursor-help",children:["v",t.version]})}),e.jsx(Qe,{children:f})]})]})})}function Lr({title:r}){return e.jsxs("header",{className:"group-has-data-[collapsible=icon]/sidebar-wrapper:h-12 flex h-12 shrink-0 items-center gap-2 border-b transition-[width,height] ease-linear pr-4",children:[e.jsxs("div",{className:"flex w-full items-center gap-2 px-4 box-border",children:[e.jsx(nr,{className:"-ml-1"}),e.jsx(St,{orientation:"vertical",className:"mx-2 data-[orientation=vertical]:h-4"}),e.jsx("h1",{className:"text-base font-medium",children:r})]}),e.jsxs("div",{className:"flex w-full justify-end items-center gap-4 box-border",children:[e.jsx(Wr,{}),e.jsx("a",{href:"https://qun.qq.com/universal-share/share?ac=1&authKey=c08PvS2zvAF1NN%2F%2BuaOi0ze1AElTIsvFBLwbWUMFc2ixjaZYxqZTUQHzipwd8Kka&busi_data=eyJncm91cENvZGUiOiIxMDU0ODg4NDczIiwidG9rZW4iOiJuSmJUN2cyUEVkNEQ5WXovM3RQbFVNcDluMGVibUNZTUQvL1RuQnFJRjBkZmRZQnRBRTdwU0szL3V2Y0dLc1ZmIiwidWluIjoiMzkxMTcyMDYwMCJ9&data=9cH6_zEC-sN3xYlwzKEWiYF71RLY9CId5taN-gy6XZo7axSlSWDpd1Ojui5hYMQKIgEJYSPw59XYgF5vH2wLog&svctype=4&tempid=h5_group_info",target:"_blank",rel:"noopener noreferrer",children:e.jsx(to,{size:24,className:"text-slate-800",fill:"currentColor"})}),e.jsx("a",{href:"https://github.com/shenjingnan/xiaozhi-client",target:"_blank",rel:"noopener noreferrer",children:e.jsx(so,{size:24,className:"text-slate-800",fill:"currentColor"})})]})]})}function ao(){const{updateConfig:r}=Er();return e.jsxs(es,{children:[e.jsx(dr,{variant:"inset"}),e.jsxs(ts,{children:[e.jsx(Lr,{title:"看板"}),e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsx("div",{className:"@container/main flex flex-1 flex-col gap-2",children:e.jsxs("div",{className:"flex flex-col gap-4 py-4 md:gap-6 md:py-6",children:[e.jsx(Dn,{}),e.jsx(eo,{updateConfig:r})]})})})]})]})}function no(){const[r,t]=o.useState(null),[s,a]=o.useState(null),[n,i]=o.useState(!1),[c,m]=o.useState(null),[b,g]=o.useState(!1),[h,p]=o.useState(""),d=o.useCallback(async()=>{try{m(null);const y=await D.getVersion();t(y),console.log("[VersionManager] 当前版本信息:",y)}catch(y){const v=y instanceof Error?y.message:"获取版本信息失败";m(v),console.error("[VersionManager] 获取版本信息失败:",y)}},[]),u=async()=>{if(r)try{i(!0),m(null),console.log("[VersionManager] 检查更新..."),await new Promise(v=>setTimeout(v,1e3));const y={currentVersion:r.version,latestVersion:"1.8.0",updateAvailable:!0,releaseNotes:`• 修复了若干 bug
48
+ • 新增实时日志功能
49
+ • 性能优化`,publishDate:new Date().toISOString()};a(y),console.log("[VersionManager] 更新检查结果:",y)}catch(y){const v=y instanceof Error?y.message:"检查更新失败";m(v),console.error("[VersionManager] 检查更新失败:",y)}finally{i(!1)}},f=y=>{console.log("[VersionManager] 开始更新到版本:",y),p(y),g(!0)},C=()=>{g(!1),p(""),setTimeout(()=>{d()},1e3)};return o.useEffect(()=>{d()},[d]),e.jsxs(de,{className:"w-full max-w-2xl",children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(ze,{className:"flex items-center gap-2",children:[e.jsx(wa,{className:"h-5 w-5"}),"版本管理"]}),e.jsx(Fe,{children:"管理应用版本和更新"})]}),e.jsx(Wr,{})]})}),e.jsxs(ye,{className:"space-y-6",children:[c&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-destructive/10 border border-destructive/20 rounded-md",children:[e.jsx(He,{className:"h-4 w-4 text-destructive"}),e.jsx("span",{className:"text-sm text-destructive",children:c})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-lg font-medium",children:"当前版本"}),r?e.jsxs("div",{className:"p-4 bg-muted/50 rounded-md space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-medium",children:["版本 ",r.version]}),e.jsx(te,{variant:"secondary",children:r.name})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["作者: ",r.author]})]}):e.jsx("div",{className:"p-4 bg-muted/50 rounded-md",children:e.jsx("span",{className:"text-muted-foreground",children:"加载中..."})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-lg font-medium",children:"更新检查"}),e.jsxs(E,{variant:"outline",size:"sm",onClick:u,disabled:n||!r,className:"flex items-center gap-2",children:[e.jsx(ht,{className:`h-4 w-4 ${n?"animate-spin":""}`}),n?"检查中...":"检查更新"]})]}),s&&e.jsx("div",{className:"p-4 border rounded-md space-y-3",children:s.updateAvailable?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-4 w-4 text-blue-600"}),e.jsxs("span",{className:"font-medium text-blue-600",children:["发现新版本 ",s.latestVersion]})]}),s.publishDate&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ja,{className:"h-3 w-3"}),"发布日期:"," ",new Date(s.publishDate).toLocaleDateString()]}),s.releaseNotes&&e.jsxs("div",{className:"mt-3",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"更新内容:"}),e.jsx("div",{className:"text-sm text-muted-foreground whitespace-pre-line bg-muted/30 p-2 rounded",children:s.releaseNotes})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(E,{onClick:()=>f(s.latestVersion),className:"flex items-center gap-2",children:[e.jsx(Js,{className:"h-4 w-4"}),"更新到 ",s.latestVersion]}),e.jsx(E,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:"https://github.com/shenjingnan/xiaozhi-client/releases",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1",children:[e.jsx(va,{className:"h-3 w-3"}),"查看详情"]})})]})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pt,{className:"h-4 w-4 text-green-600"}),e.jsxs("span",{className:"text-green-600",children:["当前版本 ",s.currentVersion," 是最新版本"]})]})})]})]}),e.jsx($r,{isOpen:b,onClose:C,version:h})]})}const oo=G.object({modelscope:G.object({apiKey:G.string().optional()}),platforms:G.object({coze:G.object({token:G.string().optional()})}),connection:G.object({heartbeatInterval:G.number().min(1e3,{message:"心跳间隔不能小于1000毫秒"}),heartbeatTimeout:G.number().min(1e3,{message:"心跳超时不能小于1000毫秒"}),reconnectInterval:G.number().min(1e3,{message:"重连间隔不能小于1000毫秒"})})});function io(){var c,m,b,g,h,p;const r=nt(),{updateConfig:t}=Er(),[s,a]=o.useState(!1),n=Ae({resolver:_e(oo),defaultValues:{platforms:{coze:{token:((m=(c=r==null?void 0:r.platforms)==null?void 0:c.coze)==null?void 0:m.token)||""}},modelscope:{apiKey:((b=r==null?void 0:r.modelscope)==null?void 0:b.apiKey)||""},connection:{heartbeatInterval:((g=r==null?void 0:r.connection)==null?void 0:g.heartbeatInterval)||3e4,heartbeatTimeout:((h=r==null?void 0:r.connection)==null?void 0:h.heartbeatTimeout)||1e4,reconnectInterval:((p=r==null?void 0:r.connection)==null?void 0:p.reconnectInterval)||5e3}}});o.useEffect(()=>{var d,u,f,C;n.reset({modelscope:{apiKey:((d=r==null?void 0:r.modelscope)==null?void 0:d.apiKey)||""},connection:{heartbeatInterval:((u=r==null?void 0:r.connection)==null?void 0:u.heartbeatInterval)||3e4,heartbeatTimeout:((f=r==null?void 0:r.connection)==null?void 0:f.heartbeatTimeout)||1e4,reconnectInterval:((C=r==null?void 0:r.connection)==null?void 0:C.reconnectInterval)||5e3}})},[r,n.reset]);async function i(d){var u;if(!r){k.error("配置数据未加载,请稍后重试");return}a(!0);try{const f={...r,modelscope:{apiKey:d.modelscope.apiKey},connection:{heartbeatInterval:d.connection.heartbeatInterval,heartbeatTimeout:d.connection.heartbeatTimeout,reconnectInterval:d.connection.reconnectInterval},platforms:{...(r==null?void 0:r.platforms)??{},coze:{...((u=r==null?void 0:r.platforms)==null?void 0:u.coze)??{},token:d.platforms.coze.token}}};await t(f),k.success("配置已更新")}catch(f){console.error("更新配置失败:",f),k.error(f instanceof Error?f.message:"更新配置失败")}finally{a(!1)}}return e.jsxs(es,{children:[e.jsx(dr,{variant:"inset"}),e.jsxs(ts,{children:[e.jsx(Lr,{title:"设置"}),e.jsx("div",{className:"flex flex-1 flex-col p-4",children:e.jsx("div",{className:"@container/main flex flex-1 flex-col gap-2 items-center",children:e.jsx("div",{className:"flex flex-col gap-4 py-4 md:gap-6 md:py-6 w-full max-w-4xl",children:e.jsxs(gt,{defaultValue:"general",className:"w-full",children:[e.jsxs(Mt,{className:"grid w-full grid-cols-2",children:[e.jsx(we,{value:"general",children:"常规设置"}),e.jsx(we,{value:"version",children:"版本管理"})]}),e.jsx(je,{value:"general",className:"mt-6",children:e.jsx("div",{className:"w-[600px] mx-auto",children:e.jsx(Ve,{...n,children:e.jsx("form",{onSubmit:n.handleSubmit(i),children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(ee,{control:n.control,name:"modelscope.apiKey",render:({field:d})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"魔搭社区 API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{children:e.jsx(re,{placeholder:"魔搭社区 API Key",className:"font-mono text-sm",type:"password",disabled:s,autoComplete:"off","data-1p-ignore":!0,...d})}),e.jsx(E,{variant:"outline",onClick:()=>{window.open("https://www.modelscope.cn/my/myaccesstoken","_blank")},children:"打开魔搭社区"})]}),e.jsx(ae,{})]})}),e.jsx(ee,{control:n.control,name:"platforms.coze.token",render:({field:d})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"扣子身份凭证"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(H,{children:e.jsx(re,{placeholder:"扣子身份凭证",className:"font-mono text-sm",type:"password",autoComplete:"off","data-1p-ignore":!0,disabled:s,...d})}),e.jsx(E,{variant:"outline",onClick:()=>{window.open("https://www.coze.cn/open/oauth/sats","_blank")},children:"打开扣子平台"})]}),e.jsx(ae,{})]})}),e.jsx(ee,{control:n.control,name:"connection.heartbeatInterval",render:({field:d})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"心跳间隔(毫秒)"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(H,{children:e.jsx(re,{placeholder:"心跳间隔(毫秒)",className:"font-mono text-sm",type:"number",disabled:s,...d,value:d.value||"",onChange:u=>{const f=u.target.value;d.onChange(f===""?"":Number(f))}})}),e.jsx("span",{className:"text-sm text-muted-foreground w-[50px]",children:"毫秒"})]}),e.jsx(ae,{})]})}),e.jsx(ee,{control:n.control,name:"connection.heartbeatTimeout",render:({field:d})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"心跳超时(毫秒)"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(H,{children:e.jsx(re,{placeholder:"心跳超时(毫秒)",className:"font-mono text-sm",type:"number",disabled:s,...d,value:d.value||"",onChange:u=>{const f=u.target.value;d.onChange(f===""?"":Number(f))}})}),e.jsx("span",{className:"text-sm text-muted-foreground w-[50px]",children:"毫秒"})]}),e.jsx(ae,{})]})}),e.jsx(ee,{control:n.control,name:"connection.reconnectInterval",render:({field:d})=>e.jsxs(Z,{children:[e.jsx(ne,{children:"重连间隔(毫秒)"}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(H,{children:e.jsx(re,{placeholder:"重连间隔(毫秒)",className:"font-mono text-sm",type:"number",disabled:s,...d,value:d.value||"",onChange:u=>{const f=u.target.value;d.onChange(f===""?"":Number(f))}})}),e.jsx("span",{className:"text-sm text-muted-foreground w-[50px]",children:"毫秒"})]}),e.jsx(ae,{})]})}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(E,{type:"submit",disabled:s,className:"flex-1",children:s?"保存中...":"保存"}),e.jsx(Ir,{})]})]})})})})}),e.jsx(je,{value:"version",className:"mt-6",children:e.jsx("div",{className:"w-[600px] mx-auto",children:e.jsx(no,{})})})]})})})})]})]})}function co(){return e.jsxs(Rn,{children:[e.jsx($a,{}),e.jsxs(Na,{children:[e.jsx(Dt,{path:"/",element:e.jsx(ya,{to:"/dashboard"})}),e.jsx(Dt,{path:"/dashboard",element:e.jsx(ao,{})}),e.jsx(Dt,{path:"/settings",element:e.jsx(io,{})})]}),e.jsx(Ta,{richColors:!0,toastOptions:{classNames:{description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-white group-[.toast]:text-black",error:"group toast group-[.toaster]:bg-red group-[.toaster]:text-red-600 dark:group-[.toaster]:text-foreground group-[.toaster]:shadow-lg",success:"group toast group-[.toaster]:bg-green group-[.toaster]:text-green-600 dark:group-[.toaster]:text-foreground group-[.toaster]:shadow-lg",warning:"group toast group-[.toaster]:bg-yellow group-[.toaster]:text-yellow-600 dark:group-[.toaster]:text-foreground group-[.toaster]:shadow-lg",info:"group toast group-[.toaster]:bg-blue group-[.toaster]:text-blue-600 dark:group-[.toaster]:text-foreground group-[.toaster]:shadow-lg"}}})]})}Sa.createRoot(document.getElementById("root")).render(e.jsx(Ca.StrictMode,{children:e.jsx(ka,{children:e.jsx(co,{})})}));
50
+ //# sourceMappingURL=index-88NfCOo9.js.map