import{j as e,r as T}from"./react-vendor-jWT2yUdV.js";import{b as y,u as X,k as Y,c as D,S as ee,T as te,O as ae,Q as se,R as re,U as le,g as ne,P as oe}from"./index-DiaaLdUu.js";import{t as ie,a as ce}from"./chunk-ML27DD5T-ZFWrMOn-.js";import{z as j}from"./react-hot-toast-cGcFZPSt.js";import{a as de}from"./index-DvErMbt6.js";import{d as ue,a as me,b as pe,m as P}from"./chunk-KQ5CH2X7-DgF-_fDD.js";import{t as W}from"./chunk-6LIX6LVT-B246pOuK.js";import{s as I}from"./index-_HIxriDC.js";import{z as he,A as be}from"./index-FvTxWQTZ.js";import{P as xe,H as $,a as fe,W as we,b as ge}from"./icons-C0t6aNgu.js";import{c as C}from"./chunk-NAV3ZXLI-ChbUTMf0.js";import{s as ve}from"./chunk-J6JGI6RM-Djlxjgjl.js";import{G as ye}from"./iconBase-B7bT1FlI.js";import{f as Se}from"./index-CVa9XolR.js";import{t as ke}from"./index-DE7yoXMZ.js";import{a as je,c as Ce}from"./chunk-5PILOUBS-KHYNqMZE.js";import{c as Ne}from"./chunk-TE6SZS6W-DGowl7ka.js";import{c as Pe}from"./chunk-D5XJWRAV-DVN21qSw.js";import{E as Te}from"./empty_state-BmDJmEaB.js";import{u as U}from"./use-config-Cu0QvgCe.js";import{u as B}from"./use-dialog-CRIMuzeE.js";import{i as De}from"./chunk-2QAN2V2R-B2qCPZrG.js";import{s as Ee,l as He}from"./chunk-KVDW62ZT-CGYYmJoP.js";import{u as Re,C as _e}from"./react-hook-form-DTbqnRcd.js";import{S as Fe}from"./switch_card-5j4Yjx-K.js";import{P as We}from"./page_header-Dr2OAQrb.js";import{L as Z}from"./index-BBhZPeTB.js";import"./qface-BZLvZXJ8.js";import"./react-router-dom-C6k78GT4.js";import"./index-BV9-YCKp.js";import"./chunk-UX7UMZL5-CMHjUaC_.js";import"./SelectionManager-Dl9uHsLK.js";import"./usePress-BrNwsdVw.js";import"./layout-Buao20KT.js";import"./gestures-BHfQC-M8.js";import"./features-animation-BkV7kg8P.js";import"./Item-D8Sud-UP.js";import"./chunk-2QQAR2RD-YG5LNmAk.js";import"./chunk-WQVQ7P2I-BJd1EiqP.js";import"./chunk-FGM523TA-CgSvUh2a.js";import"./useHover-DC1o5-bm.js";import"./useFocusable-DA5Croun.js";import"./chunk-M3MASYO7-B4fjH-eW.js";import"./chunk-EN4B57RQ-Ief8qCCd.js";import"./useToggle-B3ZYBe5S.js";import"./qq_manager-BfRTEAby.js";import"./chunk-SLABUSGS-Cmz8sGrU.js";import"./DOMLayoutDelegate-DOgfSALU.js";import"./chunk-AXSF7SRE-Cr4elNVq.js";const Ie=a=>{const{onOpen:s}=a;return e.jsxs(ue,{classNames:{content:"bg-white/90 dark:bg-zinc-900/90 backdrop-blur-2xl border border-white/70 dark:border-white/10 shadow-2xl shadow-primary-900/10 rounded-2xl"},placement:"right",children:[e.jsx(me,{children:e.jsx(y,{className:"bg-gradient-to-r from-primary-400 to-primary-600 text-white font-semibold shadow-md shadow-primary-500/25 hover:shadow-lg hover:shadow-primary-500/30 transition-all",radius:"full",startContent:e.jsx(he,{className:"text-xl"}),children:"新建"})}),e.jsxs(pe,{"aria-label":"Create Network Config",color:"default",variant:"flat",onAction:i=>{s(i)},children:[e.jsx(P,{isReadOnly:!0,className:"cursor-default hover:!bg-transparent",textValue:"title",children:e.jsxs("div",{className:"flex items-center gap-2 justify-center",children:[e.jsx("div",{className:"w-5 h-5 -ml-3 flex items-center justify-center",children:e.jsx(xe,{})}),e.jsx("div",{className:"text-primary-400",children:"新建网络配置"})]})},"title"),e.jsx(P,{textValue:"httpServers",startContent:e.jsx("div",{className:"w-6 h-6",children:e.jsx($,{})}),children:e.jsxs("div",{className:"flex gap-1 items-center",children:["HTTP服务器",e.jsx(W,{content:"「由SnowCat建立」一个HTTP服务器,你可以「使用框架连接」此服务器或者「自己构造请求发送」至此服务器。SnowCat会根据你配置的IP和端口等建立一个地址,你或者你的框架应该连接到这个地址。",showArrow:!0,className:"max-w-64",children:e.jsx(y,{isIconOnly:!0,radius:"full",size:"sm",variant:"light",className:"w-4 h-4 min-w-0",children:e.jsx(I,{})})})]})},"httpServers"),e.jsx(P,{textValue:"httpSseServers",startContent:e.jsx("div",{className:"w-6 h-6",children:e.jsx($,{})}),children:e.jsxs("div",{className:"flex gap-1 items-center",children:["HTTP SSE服务器",e.jsx(W,{content:"「由SnowCat建立」一个HTTP SSE服务器,你可以「使用框架连接」此服务器或者「自己构造请求发送」至此服务器。SnowCat会根据你配置的IP和端口等建立一个地址,你或者你的框架应该连接到这个地址。",showArrow:!0,className:"max-w-64",children:e.jsx(y,{isIconOnly:!0,radius:"full",size:"sm",variant:"light",className:"w-4 h-4 min-w-0",children:e.jsx(I,{})})})]})},"httpSseServers"),e.jsx(P,{textValue:"httpClients",startContent:e.jsx("div",{className:"w-6 h-6",children:e.jsx(fe,{})}),children:e.jsxs("div",{className:"flex gap-1 items-center",children:["HTTP客户端",e.jsx(W,{content:"「由框架或者你自己建立」的一个用于「接收」SnowCat向你发送请求的客户端,通常框架会提供一个HTTP地址。这个地址是你使用的框架提供的,SnowCat会主动连接它。",showArrow:!0,className:"max-w-64",children:e.jsx(y,{isIconOnly:!0,radius:"full",size:"sm",variant:"light",className:"w-4 h-4 min-w-0",children:e.jsx(I,{})})})]})},"httpClients"),e.jsx(P,{textValue:"websocketServers",startContent:e.jsx("div",{className:"w-6 h-6",children:e.jsx(we,{})}),children:e.jsxs("div",{className:"flex gap-1 items-center",children:["Websocket服务器",e.jsx(W,{content:"「由SnowCat建立」一个WebSocket服务器,你的框架应该连接到此服务器。SnowCat会根据你配置的IP和端口等建立一个WebSocket地址,你或者你的框架应该连接到这个地址。",showArrow:!0,className:"max-w-64",children:e.jsx(y,{isIconOnly:!0,radius:"full",size:"sm",variant:"light",className:"w-4 h-4 min-w-0",children:e.jsx(I,{})})})]})},"websocketServers"),e.jsx(P,{textValue:"websocketClients",startContent:e.jsx("div",{className:"w-6 h-6",children:e.jsx(ge,{})}),children:e.jsxs("div",{className:"flex gap-1 items-center",children:["Websocket客户端",e.jsx(W,{content:"「由框架或者你自己建立」的WebSocket,通常框架会「提供」一个ws地址,SnowCat会主动连接它。",showArrow:!0,className:"max-w-64",children:e.jsx(y,{isIconOnly:!0,radius:"full",size:"sm",variant:"light",className:"w-4 h-4 min-w-0",children:e.jsx(I,{})})})]})},"websocketClients"),e.jsx(P,{textValue:"mcpServers",startContent:e.jsx("div",{className:"w-6 h-6",children:e.jsx(be,{className:"w-5 h-5 text-primary-400"})}),children:e.jsxs("div",{className:"flex gap-1 items-center",children:["MCP 服务器",e.jsx(W,{content:"「由SnowCat建立」一个 MCP(Model Context Protocol)服务器,把雪猫的全部动作以 MCP 工具形式暴露,AI 宿主(Claude / dsh 等)可直连调用。传输:Streamable HTTP。",showArrow:!0,className:"max-w-64",children:e.jsx(y,{isIconOnly:!0,radius:"full",size:"sm",variant:"light",className:"w-4 h-4 min-w-0",children:e.jsx(I,{})})})]})},"mcpServers")]})]})};function ze(a){return ye({attr:{viewBox:"0 0 24 24",fill:"none"},child:[{tag:"path",attr:{d:"M10 11C10 10.4477 10.4477 10 11 10H13C13.5523 10 14 10.4477 14 11C14 11.5523 13.5523 12 13 12H11C10.4477 12 10 11.5523 10 11Z",fill:"currentColor"},child:[]},{tag:"path",attr:{d:"M11 14C10.4477 14 10 14.4477 10 15C10 15.5523 10.4477 16 11 16H13C13.5523 16 14 15.5523 14 15C14 14.4477 13.5523 14 13 14H11Z",fill:"currentColor"},child:[]},{tag:"path",attr:{fillRule:"evenodd",clipRule:"evenodd",d:"M9.09447 4.74918C8.41606 4.03243 8 3.0648 8 2H10C10 3.10457 10.8954 4 12 4C13.1046 4 14 3.10457 14 2H16C16 3.0648 15.5839 4.03243 14.9055 4.74918C16.1782 5.45491 17.1673 6.6099 17.6586 8H19C19.5523 8 20 8.44772 20 9C20 9.55229 19.5523 10 19 10H18V12H19C19.5523 12 20 12.4477 20 13C20 13.5523 19.5523 14 19 14H18V16H19C19.5523 16 20 16.4477 20 17C20 17.5523 19.5523 18 19 18H17.6586C16.8349 20.3304 14.6124 22 12 22C9.38756 22 7.16508 20.3304 6.34141 18H5C4.44772 18 4 17.5523 4 17C4 16.4477 4.44772 16 5 16H6V14H5C4.44772 14 4 13.5523 4 13C4 12.4477 4.44772 12 5 12H6V10H5C4.44772 10 4 9.55229 4 9C4 8.44772 4.44772 8 5 8H6.34141C6.83274 6.6099 7.82181 5.45491 9.09447 4.74918ZM8 16V10C8 7.79086 9.79086 6 12 6C14.2091 6 16 7.79086 16 10V16C16 18.2091 14.2091 20 12 20C9.79086 20 8 18.2091 8 16Z",fill:"currentColor"},child:[]}]})(a)}const Me=({title:a,action:s,enableSwitch:i,children:c,className:o})=>{const[h]=X(Y.backgroundImage,""),m=!!h;return e.jsxs(je,{className:D("backdrop-blur-xl border rounded-2xl overflow-hidden transition-all duration-300 h-full",m?"bg-black/25 border-white/25":"bg-white/60 dark:bg-white/[0.04] border-white/60 dark:border-white/10","hover:shadow-lg hover:shadow-primary-500/10 hover:-translate-y-0.5",o),children:[e.jsxs(Pe,{className:"p-4 pb-2 flex items-center justify-between gap-3",children:[e.jsx("div",{className:"flex-1 min-w-0 mr-2",children:e.jsxs("div",{className:"inline-flex items-center gap-2 px-3 py-1 rounded-lg bg-default-100/60 dark:bg-white/[0.06] border border-white/40 dark:border-white/5",children:[e.jsx("span",{className:D("w-1.5 h-1.5 rounded-full flex-shrink-0",m?"bg-white/70":"bg-primary-500")}),e.jsx("span",{className:D("font-semibold text-sm truncate select-text",m?"text-white":"text-default-700 dark:text-white/90"),children:a})]})}),e.jsx("div",{className:"flex-shrink-0",children:i})]}),e.jsx(Ce,{className:"px-4 py-2 text-sm text-default-600",children:c}),e.jsx(Ne,{className:"px-4 pb-4 pt-2",children:s})]})},z=({data:a,typeLabel:s,fields:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m,showType:x})=>{const{name:b,enable:u,debug:f}=a,[d,n]=T.useState(!1),r=()=>{n(!0),o().finally(()=>n(!1))},p=()=>{n(!0),h().finally(()=>n(!1))},g=()=>{n(!0),m().finally(()=>n(!1))},N=v=>["URL","Token","AccessToken"].includes(v);return e.jsx(Me,{className:"w-full max-w-[420px]",tag:x?s:void 0,action:e.jsxs("div",{className:"flex gap-2 w-full",children:[e.jsx(y,{fullWidth:!0,radius:"full",size:"sm",variant:"flat",className:"flex-1 bg-white/60 dark:bg-white/[0.06] border border-white/50 dark:border-white/10 text-default-600 font-medium hover:bg-warning/20 hover:text-warning transition-colors",startContent:e.jsx(Se,{size:16}),onPress:c,isDisabled:d,children:"编辑"}),e.jsx(y,{fullWidth:!0,radius:"full",size:"sm",variant:"flat",className:D("flex-1 bg-white/60 dark:bg-white/[0.06] border border-white/50 dark:border-white/10 text-default-600 font-medium transition-colors",f?"hover:bg-secondary/20 hover:text-secondary data-[hover=true]:text-secondary":"hover:bg-success/20 hover:text-success data-[hover=true]:text-success"),startContent:e.jsx(ze,{size:16}),onPress:g,isDisabled:d,children:f?"默认":"调试"}),e.jsx(y,{fullWidth:!0,radius:"full",size:"sm",variant:"flat",className:"flex-1 bg-white/60 dark:bg-white/[0.06] border border-white/50 dark:border-white/10 text-default-600 font-medium hover:bg-danger/20 hover:text-danger transition-colors",startContent:e.jsx(ke,{size:16}),onPress:p,isDisabled:d,children:"删除"})]}),enableSwitch:e.jsx(ve,{isDisabled:d,isSelected:u,onChange:r,classNames:{wrapper:"group-data-[selected=true]:bg-primary-400"}}),title:b,children:e.jsx("div",{className:"grid grid-cols-2 gap-3",children:(()=>{const v=i.find(E=>N(E.label));if(v)return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1 p-3 bg-white/55 dark:bg-white/[0.04] rounded-xl border border-white/50 dark:border-white/[0.06] hover:border-primary/25 transition-colors col-span-2",children:[e.jsx("span",{className:"text-xs text-default-500 dark:text-white/50 font-medium tracking-wide",children:"类型"}),e.jsx("div",{className:"text-sm font-medium text-default-700 dark:text-white/90 truncate",children:s})]}),e.jsxs("div",{className:"flex flex-col gap-1 p-3 bg-white/55 dark:bg-white/[0.04] rounded-xl border border-white/50 dark:border-white/[0.06] hover:border-primary/25 transition-colors col-span-2",children:[e.jsx("span",{className:"text-xs text-default-500 dark:text-white/50 font-medium tracking-wide",children:v.label}),e.jsx("div",{className:"text-sm font-medium text-default-700 dark:text-white/90 truncate",children:v.render?v.render(v.value):e.jsx("span",{className:D(typeof v.value=="string"&&(v.value.startsWith("http")||v.value.includes(".")||v.value.includes(":"))?"font-mono":""),children:String(v.value)})})]})]});{const E=i.slice(0,3);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1 p-3 bg-white/55 dark:bg-white/[0.04] rounded-xl border border-white/50 dark:border-white/[0.06] hover:border-primary/25 transition-colors",children:[e.jsx("span",{className:"text-[11px] text-default-400 dark:text-white/45 font-medium tracking-wide",children:"类型"}),e.jsx("div",{className:"text-[13px] font-semibold text-default-700 dark:text-white/90 leading-snug break-words",children:s})]}),E.map((k,A)=>e.jsxs("div",{className:"flex flex-col gap-1 p-3 bg-white/55 dark:bg-white/[0.04] rounded-xl border border-white/50 dark:border-white/[0.06] hover:border-primary/25 transition-colors",children:[e.jsx("span",{className:"text-[11px] text-default-400 dark:text-white/45 font-medium tracking-wide",children:k.label}),e.jsx("div",{className:"text-[13px] font-semibold text-default-700 dark:text-white/90 leading-snug break-words",children:k.render?k.render(k.value):e.jsx("span",{className:D(typeof k.value=="string"&&(k.value.startsWith("http")||k.value.includes(".")||k.value.includes(":"))?"font-mono":""),children:String(k.value)})})]},A))]})}})()})})},qe=a=>{const{data:s,showType:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m}=a,{url:x,reportSelfMessage:b,messagePostFormat:u}=s,f=[{label:"URL",value:x},{label:"消息格式",value:u},{label:"上报自身消息",value:b,render:d=>e.jsx(C,{color:d?"success":"default",size:"sm",variant:"flat",children:d?"是":"否"})}];return e.jsx(z,{data:s,showType:i,typeLabel:"HTTP客户端",fields:f,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m})},Oe=a=>{const{data:s,showType:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m}=a,{host:x,port:b,enableCors:u,enableWebsocket:f,messagePostFormat:d}=s,n=[{label:"主机",value:x},{label:"端口",value:b},{label:"消息格式",value:d},{label:"CORS",value:u,render:r=>e.jsx(C,{color:r?"success":"default",size:"sm",variant:"flat",children:r?"已启用":"未启用"})},{label:"WS",value:f,render:r=>e.jsx(C,{color:r?"success":"default",size:"sm",variant:"flat",children:r?"已启用":"未启用"})}];return e.jsx(z,{data:s,showType:i,typeLabel:"HTTP服务器",fields:n,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m})},Ae=a=>{const{data:s,showType:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m}=a,{host:x,port:b,enableCors:u,enableWebsocket:f,messagePostFormat:d}=s,n=[{label:"主机",value:x},{label:"端口",value:b},{label:"消息格式",value:d},{label:"CORS",value:u,render:r=>e.jsx(C,{color:r?"success":"default",size:"sm",variant:"flat",children:r?"已启用":"未启用"})},{label:"WS",value:f,render:r=>e.jsx(C,{color:r?"success":"default",size:"sm",variant:"flat",children:r?"已启用":"未启用"})}];return e.jsx(z,{data:s,showType:i,typeLabel:"HTTP服务器",fields:n,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m})},Le=a=>{const{data:s,showType:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m}=a,{host:x,port:b,token:u}=s,f=[{label:"主机",value:x},{label:"端口",value:b},{label:"端点",value:"/mcp"},{label:"鉴权",value:!!u,render:d=>e.jsx(C,{color:d?"success":"warning",size:"sm",variant:"flat",children:d?"Bearer Token":"未鉴权"})}];return e.jsx(z,{data:s,showType:i,typeLabel:"MCP服务器",fields:f,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m})},Ve=a=>{const{data:s,showType:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m}=a,{url:x,heartInterval:b,reconnectInterval:u,messagePostFormat:f,reportSelfMessage:d}=s,n=[{label:"URL",value:x},{label:"重连间隔",value:`${u}ms`},{label:"心跳间隔",value:`${b}ms`},{label:"消息格式",value:f},{label:"上报自身消息",value:d,render:r=>e.jsx(C,{color:r?"success":"default",size:"sm",variant:"flat",children:r?"是":"否"})}];return e.jsx(z,{data:s,showType:i,typeLabel:"Websocket客户端",fields:n,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m})},$e=a=>{const{data:s,showType:i,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m}=a,{host:x,port:b,heartInterval:u,messagePostFormat:f,reportSelfMessage:d,enableForcePushEvent:n}=s,r=[{label:"主机",value:x},{label:"端口",value:b},{label:"心跳间隔",value:`${u}ms`},{label:"消息格式",value:f},{label:"上报自身消息",value:d,render:p=>e.jsx(C,{color:p?"success":"default",size:"sm",variant:"flat",children:p?"是":"否"})},{label:"强制推送事件",value:n,render:p=>e.jsx(C,{color:p?"success":"default",size:"sm",variant:"flat",children:p?"是":"否"})}];return e.jsx(z,{data:s,showType:i,typeLabel:"Websocket服务器",fields:r,onEdit:c,onEnable:o,onDelete:h,onEnableDebug:m})},M=({data:a,defaultValues:s,onClose:i,onSubmit:c,fields:o})=>{const{control:h,handleSubmit:m,formState:x,setValue:b,reset:u}=Re({defaultValues:s}),d=m(async n=>{await c(n),i()},n=>{var p;const r=Object.values(n);r.length>0&&j.error((p=r[0])==null?void 0:p.message)});return T.useEffect(()=>{if(a){const n=Object.keys(a);for(const r of n){const p=a[r];b(r,p)}}else u()},[a,u,b]),e.jsxs(e.Fragment,{children:[e.jsx(ee,{children:e.jsx("div",{className:"grid grid-cols-2 gap-y-4 gap-x-2 w-full",children:o.map(n=>e.jsx("div",{className:n.colSpan===1?"col-span-1":"col-span-2",children:e.jsx(_e,{control:h,name:n.name,rules:n.isRequired?{required:`请填写${n.label}`}:void 0,render:({field:r})=>{var p;switch(n.type){case"input":return e.jsx(De,{value:r.value,onValueChange:g=>r.onChange(g),ref:r.ref,isRequired:n.isRequired,isDisabled:n.isDisabled,label:n.label,placeholder:n.placeholder,classNames:{inputWrapper:"bg-white/80 dark:bg-white/[0.06] backdrop-blur-md border border-black/[0.08] dark:border-white/12 hover:bg-white/95 dark:hover:bg-white/[0.09] transition-all shadow-sm data-[hover=true]:border-primary/35 group-data-[focus=true]:border-primary/55",input:"bg-transparent text-default-700 dark:text-default-100 placeholder:text-default-400"}});case"select":return e.jsx(Ee,{...r,ref:r.ref,isRequired:n.isRequired,label:n.label,placeholder:n.placeholder,selectedKeys:[r.value],value:r.value.toString(),classNames:{trigger:"bg-white/80 dark:bg-white/[0.06] backdrop-blur-md border border-black/[0.08] dark:border-white/12 hover:bg-white/95 dark:hover:bg-white/[0.09] transition-all shadow-sm data-[hover=true]:border-primary/35",value:"text-default-700 dark:text-default-100"},children:((p=n.options)==null?void 0:p.map(g=>e.jsx(He,{value:g.value,children:g.value},g.key)))||e.jsx(e.Fragment,{})});case"switch":return e.jsx(Fe,{...r,value:r.value,description:n.description,label:n.label});default:return e.jsx(e.Fragment,{})}}})},n.name))})}),e.jsxs(te,{className:"border-t border-white/50 dark:border-white/[0.06] pt-3",children:[e.jsx(y,{color:"default",isDisabled:x.isSubmitting,variant:"flat",radius:"full",className:"bg-white/60 dark:bg-white/[0.06] text-default-600",onPress:i,children:"取消"}),e.jsx(y,{color:"primary",radius:"full",isLoading:x.isSubmitting,className:"font-semibold bg-gradient-to-r from-primary-400 to-primary-600 shadow-md shadow-primary-500/25 px-6",onPress:()=>d(),children:"保存"})]})]})};function q(a){const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~";let i="";for(let c=0;c{const c={enable:!1,name:"",url:"http://localhost:8080",reportSelfMessage:!1,messagePostFormat:"array",token:q(16),debug:!1},o=[{name:"enable",label:"启用",type:"switch",description:"保存后启用此配置",colSpan:1},{name:"debug",label:"开启Debug",type:"switch",description:"是否开启调试模式",colSpan:1},{name:"name",label:"名称",type:"input",placeholder:"请输入名称",isRequired:!0,isDisabled:!!a},{name:"url",label:"URL",type:"input",placeholder:"请输入URL",isRequired:!0},{name:"reportSelfMessage",label:"上报自身消息",type:"switch",description:"是否上报自身消息",colSpan:1},{name:"messagePostFormat",label:"消息格式",type:"select",placeholder:"请选择消息格式",isRequired:!0,options:[{key:"array",value:"Array"},{key:"string",value:"String"}],colSpan:1},{name:"token",label:"Token",type:"input",placeholder:"请输入Token"}];return e.jsx(M,{data:a,defaultValues:c,onClose:s,onSubmit:i,fields:o})},Be=({data:a,onClose:s,onSubmit:i})=>{const c={enable:!1,name:"",host:"127.0.0.1",port:3e3,enableCors:!0,enableWebsocket:!1,messagePostFormat:"array",token:q(16),debug:!1},o=[{name:"enable",label:"启用",type:"switch",description:"保存后启用此配置",colSpan:1},{name:"debug",label:"开启Debug",type:"switch",description:"是否开启调试模式",colSpan:1},{name:"name",label:"名称",type:"input",placeholder:"请输入名称",isRequired:!0,isDisabled:!!a},{name:"host",label:"Host",type:"input",placeholder:"请输入主机地址",isRequired:!0},{name:"port",label:"Port",type:"input",placeholder:"请输入端口",isRequired:!0},{name:"enableCors",label:"启用CORS",type:"switch",description:"是否启用CORS跨域",colSpan:1},{name:"enableWebsocket",label:"启用Websocket",type:"switch",description:"是否启用Websocket",colSpan:1},{name:"messagePostFormat",label:"消息格式",type:"select",placeholder:"请选择消息格式",isRequired:!0,options:[{key:"array",value:"Array"},{key:"string",value:"String"}]},{name:"token",label:"Token",type:"input",placeholder:"请输入Token"}];return e.jsx(M,{data:a,defaultValues:c,onClose:s,onSubmit:i,fields:o})},Ze=({data:a,onClose:s,onSubmit:i})=>{const c={enable:!1,name:"",host:"127.0.0.1",port:3e3,enableCors:!0,enableWebsocket:!1,messagePostFormat:"array",token:q(16),debug:!1,reportSelfMessage:!1},o=[{name:"enable",label:"启用",type:"switch",description:"保存后启用此配置",colSpan:1},{name:"debug",label:"开启Debug",type:"switch",description:"是否开启调试模式",colSpan:1},{name:"name",label:"名称",type:"input",placeholder:"请输入名称",isRequired:!0,isDisabled:!!a},{name:"host",label:"Host",type:"input",placeholder:"请输入主机地址",isRequired:!0},{name:"port",label:"Port",type:"input",placeholder:"请输入端口",isRequired:!0},{name:"enableCors",label:"启用CORS",type:"switch",description:"是否启用CORS跨域",colSpan:1},{name:"enableWebsocket",label:"启用Websocket",type:"switch",description:"是否启用Websocket",colSpan:1},{name:"messagePostFormat",label:"消息格式",type:"select",placeholder:"请选择消息格式",isRequired:!0,options:[{key:"array",value:"Array"},{key:"string",value:"String"}]},{name:"token",label:"Token",type:"input",placeholder:"请输入Token"},{name:"reportSelfMessage",label:"上报自身消息",type:"switch",description:"是否上报自身消息",colSpan:1}];return e.jsx(M,{data:a,defaultValues:c,onClose:s,onSubmit:i,fields:o})},Ge=({data:a,onClose:s,onSubmit:i})=>{const c={enable:!1,name:"",host:"127.0.0.1",port:3002,token:q(16),debug:!1},o=[{name:"enable",label:"启用",type:"switch",description:"保存后启用此配置",colSpan:1},{name:"debug",label:"开启Debug",type:"switch",description:"是否开启调试模式",colSpan:1},{name:"name",label:"名称",type:"input",placeholder:"请输入名称",isRequired:!0,isDisabled:!!a},{name:"host",label:"Host",type:"input",placeholder:"请输入主机地址",isRequired:!0},{name:"port",label:"Port",type:"input",placeholder:"请输入端口",isRequired:!0},{name:"token",label:"Token",type:"input",placeholder:"留空则不鉴权(仅限本机使用)",description:"AI 宿主以 Authorization: Bearer 连接"}];return e.jsx(M,{data:a,defaultValues:c,onClose:s,onSubmit:i,fields:o})},Qe=({data:a,onClose:s,onSubmit:i})=>{const c={enable:!1,name:"",url:"ws://localhost:8082",reportSelfMessage:!1,messagePostFormat:"array",token:q(16),debug:!1,heartInterval:3e4,reconnectInterval:3e4,verifyCertificate:!0},o=[{name:"enable",label:"启用",type:"switch",description:"保存后启用此配置",colSpan:1},{name:"debug",label:"开启Debug",type:"switch",description:"是否开启调试模式",colSpan:1},{name:"name",label:"名称",type:"input",placeholder:"请输入名称",isRequired:!0,isDisabled:!!a},{name:"url",label:"URL",type:"input",placeholder:"请输入URL",isRequired:!0},{name:"reportSelfMessage",label:"上报自身消息",type:"switch",description:"是否上报自身消息",colSpan:1},{name:"messagePostFormat",label:"消息格式",type:"select",placeholder:"请选择消息格式",isRequired:!0,options:[{key:"array",value:"Array"},{key:"string",value:"String"}],colSpan:1},{name:"token",label:"Token",type:"input",placeholder:"请输入Token"},{name:"heartInterval",label:"心跳间隔",type:"input",placeholder:"请输入心跳间隔",isRequired:!0,colSpan:1},{name:"reconnectInterval",label:"重连间隔",type:"input",placeholder:"请输入重连间隔",isRequired:!0,colSpan:1},{name:"verifyCertificate",label:"SSL证书验证",type:"switch",description:"是否验证SSL证书(wss连接)。关闭后可连接自签名证书的服务器,但会降低安全性",colSpan:2}];return e.jsx(M,{data:a,defaultValues:c,onClose:s,onSubmit:i,fields:o})},Ke=({data:a,onClose:s,onSubmit:i})=>{const c={enable:!1,name:"",host:"127.0.0.1",port:3001,reportSelfMessage:!1,enableForcePushEvent:!0,messagePostFormat:"array",token:q(16),debug:!1,heartInterval:3e4},o=[{name:"enable",label:"启用",type:"switch",description:"保存后启用此配置",colSpan:1},{name:"debug",label:"开启Debug",type:"switch",description:"是否开启调试模式",colSpan:1},{name:"name",label:"名称",type:"input",placeholder:"请输入名称",isRequired:!0,isDisabled:!!a},{name:"host",label:"Host",type:"input",placeholder:"请输入主机地址",isRequired:!0},{name:"port",label:"Port",type:"input",placeholder:"请输入端口",isRequired:!0,colSpan:1},{name:"messagePostFormat",label:"消息格式",type:"select",placeholder:"请选择消息格式",isRequired:!0,options:[{key:"array",value:"Array"},{key:"string",value:"String"}],colSpan:1},{name:"reportSelfMessage",label:"上报自身消息",type:"switch",description:"是否上报自身消息",colSpan:1},{name:"enableForcePushEvent",label:"强制推送事件",type:"switch",description:"是否强制推送事件",colSpan:1},{name:"token",label:"Token",type:"input",placeholder:"请输入Token"},{name:"heartInterval",label:"心跳间隔",type:"input",placeholder:"请输入心跳间隔",isRequired:!0}];return e.jsx(M,{data:a,defaultValues:c,onClose:s,onSubmit:i,fields:o})},Je={httpServers:"HTTP Server",httpClients:"HTTP Client",httpSseServers:"HTTP SSE Server",websocketServers:"Websocket Server",websocketClients:"Websocket Client",mcpServers:"MCP Server"},Xe=a=>{const{isOpen:s,onOpenChange:i,field:c,data:o}=a,{createNetworkConfig:h,updateNetworkConfig:m}=U(),x=B(),b=!o,u=async d=>{const n=async r=>{try{b?await h(c,r):await m(c,r),j.success("保存配置成功")}catch(p){const g=p.message;throw j.error(`保存配置失败: ${g}`),p}};if(["httpServers","httpSseServers","websocketServers"].includes(c)){const r=d;if(!r.token&&r.host!=="127.0.0.1"){await new Promise((p,g)=>{x.confirm({title:"安全警告",content:e.jsxs("div",{children:[e.jsx("p",{children:"检测到未配置Token,这可能导致安全风险。确认要继续吗?"}),e.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"(未配置Token时,Host将被强制限制为 127.0.0.1)"})]}),onConfirm:async()=>{r.host="127.0.0.1";try{await n(r),p()}catch(N){g(N)}},onCancel:()=>{g(new Error("Cancelled"))}})});return}}await n(d)},f=d=>{switch(c){case"httpServers":return e.jsx(Be,{data:o,onClose:d,onSubmit:u});case"httpClients":return e.jsx(Ue,{data:o,onClose:d,onSubmit:u});case"websocketServers":return e.jsx(Ke,{data:o,onClose:d,onSubmit:u});case"websocketClients":return e.jsx(Qe,{data:o,onClose:d,onSubmit:u});case"httpSseServers":return e.jsx(Ze,{data:o,onClose:d,onSubmit:u});case"mcpServers":return e.jsx(Ge,{data:o,onClose:d,onSubmit:u});default:return null}};return e.jsx(ae,{backdrop:"blur",isDismissable:!1,isOpen:s,size:"lg",scrollBehavior:"outside",onOpenChange:i,children:e.jsx(se,{className:"rounded-3xl border border-white/70 dark:border-white/10 bg-white/90 dark:bg-zinc-900/90 backdrop-blur-2xl shadow-2xl shadow-primary-900/10",children:d=>e.jsxs(e.Fragment,{children:[e.jsxs(re,{className:"flex flex-col gap-1 pb-2",children:[e.jsx("span",{className:"text-lg font-semibold tracking-tight",children:Je[c]}),e.jsx("span",{className:"text-tiny font-normal text-default-400",children:b?"新建一个接入点":`编辑「${(o==null?void 0:o.name)??""}」`})]}),f(d)]})})})},Ye=({isEmpty:a})=>e.jsx("div",{className:D(a?"block":"hidden"),children:e.jsx(Te,{compact:!0,icon:e.jsx(Z,{size:20}),title:"这一栏还是空的",description:"点击右上角「新增」添加第一个接入点"})});function Qt(){const{config:a,refreshConfig:s,deleteNetworkConfig:i,enableNetworkConfig:c,enableDebugNetworkConfig:o}=U(),[h,m]=T.useState("httpServers"),[x,b]=T.useState(""),{network:{httpServers:u=[],httpClients:f=[],httpSseServers:d=[],websocketServers:n=[],websocketClients:r=[],mcpServers:p=[]}={}}=a,[g,N]=T.useState(!1),{isOpen:v,onOpen:E,onOpenChange:k}=le(),A=B(),G=T.useMemo(()=>ne(a,h).find(t=>t.name===x),[h,x,a]),L=async()=>{N(!0);try{await s(),N(!1)}catch(l){const t=l.message;j.error(`获取配置失败: ${t}`)}finally{N(!1)}},Q=l=>{m(l),b(""),E()},H=async(l,t)=>new Promise((w,O)=>{A.confirm({title:"删除配置",content:`确定要删除配置「${t}」吗?`,onConfirm:async()=>{try{await i(l,t),j.success("删除配置成功"),w()}catch(V){const J=V.message;j.error(`删除配置失败: ${J}`),O(V)}},onCancel:()=>{w()}})}),R=async(l,t)=>{try{await c(l,t),j.success("更新配置成功")}catch(w){const O=w.message;throw j.error(`更新配置失败: ${O}`),w}},_=async(l,t)=>{try{await o(l,t),j.success("更新配置成功")}catch(w){const O=w.message;throw j.error(`更新配置失败: ${O}`),w}},F=(l,t)=>{m(l),b(t),E()},S=(l,t,w=!1)=>{switch(l){case"httpServers":return e.jsx(Oe,{showType:w,data:t,onDelete:async()=>{await H("httpServers",t.name)},onEdit:()=>{F("httpServers",t.name)},onEnable:async()=>{await R("httpServers",t.name)},onEnableDebug:async()=>{await _("httpServers",t.name)}},t.name);case"httpClients":return e.jsx(qe,{showType:w,data:t,onDelete:async()=>{await H("httpClients",t.name)},onEdit:()=>{F("httpClients",t.name)},onEnable:async()=>{await R("httpClients",t.name)},onEnableDebug:async()=>{await _("httpClients",t.name)}},t.name);case"httpSseServers":return e.jsx(Ae,{showType:w,data:t,onDelete:async()=>{await H("httpSseServers",t.name)},onEdit:()=>{F("httpSseServers",t.name)},onEnable:async()=>{await R("httpSseServers",t.name)},onEnableDebug:async()=>{await _("httpSseServers",t.name)}},t.name);case"websocketServers":return e.jsx($e,{showType:w,data:t,onDelete:async()=>{await H("websocketServers",t.name)},onEdit:()=>{F("websocketServers",t.name)},onEnable:async()=>{await R("websocketServers",t.name)},onEnableDebug:async()=>{await _("websocketServers",t.name)}},t.name);case"mcpServers":return e.jsx(Le,{showType:w,data:t,onDelete:async()=>{await H("mcpServers",t.name)},onEdit:()=>{F("mcpServers",t.name)},onEnable:async()=>{await R("mcpServers",t.name)},onEnableDebug:async()=>{await _("mcpServers",t.name)}},t.name);case"websocketClients":return e.jsx(Ve,{showType:w,data:t,onDelete:async()=>{await H("websocketClients",t.name)},onEdit:()=>{F("websocketClients",t.name)},onEnable:async()=>{await R("websocketClients",t.name)},onEnableDebug:async()=>{await _("websocketClients",t.name)}},t.name)}},K=[{key:"all",title:"全部",items:[...u,...f,...n,...r,...d,...p].sort((l,t)=>l.name.localeCompare(t.name)).map(l=>u.find(t=>t.name===l.name)?S("httpServers",l,!0):d.find(t=>t.name===l.name)?S("httpSseServers",l,!0):f.find(t=>t.name===l.name)?S("httpClients",l,!0):n.find(t=>t.name===l.name)?S("websocketServers",l,!0):r.find(t=>t.name===l.name)?S("websocketClients",l,!0):p.find(t=>t.name===l.name)?S("mcpServers",l,!0):null)},{key:"mcpServers",title:"MCP服务器",items:p.map(l=>S("mcpServers",l))},{key:"httpServers",title:"HTTP服务器",items:u.map(l=>S("httpServers",l))},{key:"httpClients",title:"HTTP客户端",items:f.map(l=>S("httpClients",l))},{key:"httpSseServers",title:"HTTP SSE服务器",items:d.map(l=>S("httpSseServers",l))},{key:"websocketServers",title:"Websocket服务器",items:n.map(l=>S("websocketServers",l))},{key:"websocketClients",title:"Websocket客户端",items:r.map(l=>S("websocketClients",l))}];return T.useEffect(()=>{L()},[]),e.jsxs(e.Fragment,{children:[e.jsx("title",{children:"网络配置 - SnowCat WebUI"}),e.jsxs("div",{className:"sc-page",children:[e.jsx(Xe,{data:G,field:h,isOpen:v,onOpenChange:k}),e.jsx(oe,{loading:g}),e.jsx(We,{icon:e.jsx(Z,{size:20}),title:"网络配置",description:"WS / HTTP / SSE / MCP 四类接入点,一处统一管理",actions:e.jsxs(e.Fragment,{children:[e.jsx(Ie,{onOpen:Q}),e.jsx(y,{isIconOnly:!0,className:"bg-white/60 dark:bg-white/10 text-default-600 dark:text-default-300 backdrop-blur-md hover:bg-white/80 dark:hover:bg-white/20",radius:"full",onPress:L,children:e.jsx(de,{size:22})})]})}),e.jsx(ie,{"aria-label":"Network Configs",className:"max-w-full",items:K,classNames:{tabList:"sc-tablist",cursor:"sc-tab-cursor"},children:l=>e.jsxs(ce,{title:l.title,children:[e.jsx(Ye,{isEmpty:!l.items.length}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 justify-start items-stretch gap-x-2 gap-y-4",children:l.items})]},l.key)})]})]})}export{Qt as default};