@yuku123/z-agent-frontend-component 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(Z,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react"),require("antd"),require("@ant-design/icons"),require("@yuku123/z-frontend-common"),require("@logicflow/core"),require("@logicflow/extension"),require("react-router-dom"),require("react-markdown"),require("remark-gfm"),require("echarts-for-react")):typeof define=="function"&&define.amd?define(["exports","react","antd","@ant-design/icons","@yuku123/z-frontend-common","@logicflow/core","@logicflow/extension","react-router-dom","react-markdown","remark-gfm","echarts-for-react"],s):(Z=typeof globalThis<"u"?globalThis:Z||self,s(Z.ZAgentFrontendComponent={},Z.React,Z.antd,Z.icons,Z.ZFrontendCommon,Z.LogicFlow,Z.LogicFlowExtension,Z.ReactRouterDOM,Z.ReactMarkdown,Z.RemarkGfm,Z.EChartsReact))})(this,(function(Z,s,t,l,We,re,Be,Ve,At,hs,Pt){"use strict";var Ke={exports:{}},Fe={};/**
1
+ (function(Z,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react"),require("antd"),require("@ant-design/icons"),require("@yuku123/z-frontend-common"),require("@logicflow/core"),require("@logicflow/extension"),require("react-router-dom"),require("react-markdown"),require("remark-gfm"),require("echarts-for-react")):typeof define=="function"&&define.amd?define(["exports","react","antd","@ant-design/icons","@yuku123/z-frontend-common","@logicflow/core","@logicflow/extension","react-router-dom","react-markdown","remark-gfm","echarts-for-react"],s):(Z=typeof globalThis<"u"?globalThis:Z||self,s(Z.ZAgentFrontendComponent={},Z.React,Z.antd,Z.icons,Z.ZFrontendCommon,Z.LogicFlow,Z.LogicFlowExtension,Z.ReactRouterDOM,Z.ReactMarkdown,Z.RemarkGfm,Z.EChartsReact))})(this,(function(Z,s,t,l,We,ne,Ne,Be,Et,gs,Pt){"use strict";var Ve={exports:{}},Fe={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Et;function ms(){if(Et)return Fe;Et=1;var o=Symbol.for("react.transitional.element"),i=Symbol.for("react.fragment");function a(n,T,d){var b=null;if(d!==void 0&&(b=""+d),T.key!==void 0&&(b=""+T.key),"key"in T){d={};for(var f in T)f!=="key"&&(d[f]=T[f])}else d=T;return T=d.ref,{$$typeof:o,type:n,key:b,ref:T!==void 0?T:null,props:d}}return Fe.Fragment=i,Fe.jsx=a,Fe.jsxs=a,Fe}var Ne={};/**
9
+ */var zt;function fs(){if(zt)return Fe;zt=1;var i=Symbol.for("react.transitional.element"),o=Symbol.for("react.fragment");function a(r,j,c){var m=null;if(c!==void 0&&(m=""+c),j.key!==void 0&&(m=""+j.key),"key"in j){c={};for(var b in j)b!=="key"&&(c[b]=j[b])}else c=j;return j=c.ref,{$$typeof:i,type:r,key:m,ref:j!==void 0?j:null,props:c}}return Fe.Fragment=o,Fe.jsx=a,Fe.jsxs=a,Fe}var Le={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,17 +14,17 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var zt;function gs(){return zt||(zt=1,process.env.NODE_ENV!=="production"&&(function(){function o(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===U?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case v:return"Fragment";case x:return"Profiler";case S:return"StrictMode";case C:return"Suspense";case P:return"SuspenseList";case V:return"Activity"}if(typeof r=="object")switch(typeof r.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case u:return"Portal";case G:return r.displayName||"Context";case D:return(r._context.displayName||"Context")+".Consumer";case g:var L=r.render;return r=r.displayName,r||(r=L.displayName||L.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case K:return L=r.displayName||null,L!==null?L:o(r.type)||"Memo";case O:L=r._payload,r=r._init;try{return o(r(L))}catch{}}return null}function i(r){return""+r}function a(r){try{i(r);var L=!1}catch{L=!0}if(L){L=console;var $=L.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&r[Symbol.toStringTag]||r.constructor.name||"Object";return $.call(L,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),i(r)}}function n(r){if(r===v)return"<>";if(typeof r=="object"&&r!==null&&r.$$typeof===O)return"<...>";try{var L=o(r);return L?"<"+L+">":"<...>"}catch{return"<...>"}}function T(){var r=A.A;return r===null?null:r.getOwner()}function d(){return Error("react-stack-top-frame")}function b(r){if(k.call(r,"key")){var L=Object.getOwnPropertyDescriptor(r,"key").get;if(L&&L.isReactWarning)return!1}return r.key!==void 0}function f(r,L){function $(){y||(y=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",L))}$.isReactWarning=!0,Object.defineProperty(r,"key",{get:$,configurable:!0})}function j(){var r=o(this.type);return M[r]||(M[r]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),r=this.props.ref,r!==void 0?r:null}function w(r,L,$,R,se,je){var le=$.ref;return r={$$typeof:N,type:r,key:L,props:$,_owner:R},(le!==void 0?le:null)!==null?Object.defineProperty(r,"ref",{enumerable:!1,get:j}):Object.defineProperty(r,"ref",{enumerable:!1,value:null}),r._store={},Object.defineProperty(r._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(r,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(r,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:se}),Object.defineProperty(r,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:je}),Object.freeze&&(Object.freeze(r.props),Object.freeze(r)),r}function h(r,L,$,R,se,je){var le=L.children;if(le!==void 0)if(R)if(_(le)){for(R=0;R<le.length;R++)m(le[R]);Object.freeze&&Object.freeze(le)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else m(le);if(k.call(L,"key")){le=o(r);var fe=Object.keys(L).filter(function(ee){return ee!=="key"});R=0<fe.length?"{key: someKey, "+fe.join(": ..., ")+": ...}":"{key: someKey}",c[le+R]||(fe=0<fe.length?"{"+fe.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var Rt;function ys(){return Rt||(Rt=1,process.env.NODE_ENV!=="production"&&(function(){function i(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===F?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case v:return"Fragment";case f:return"Profiler";case T:return"StrictMode";case k:return"Suspense";case E:return"SuspenseList";case B:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case x:return"Portal";case K:return n.displayName||"Context";case M:return(n._context.displayName||"Context")+".Consumer";case C:var _=n.render;return n=n.displayName,n||(n=_.displayName||_.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case W:return _=n.displayName||null,_!==null?_:i(n.type)||"Memo";case h:_=n._payload,n=n._init;try{return i(n(_))}catch{}}return null}function o(n){return""+n}function a(n){try{o(n);var _=!1}catch{_=!0}if(_){_=console;var $=_.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return $.call(_,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),o(n)}}function r(n){if(n===v)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===h)return"<...>";try{var _=i(n);return _?"<"+_+">":"<...>"}catch{return"<...>"}}function j(){var n=A.A;return n===null?null:n.getOwner()}function c(){return Error("react-stack-top-frame")}function m(n){if(I.call(n,"key")){var _=Object.getOwnPropertyDescriptor(n,"key").get;if(_&&_.isReactWarning)return!1}return n.key!==void 0}function b(n,_){function $(){w||(w=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",_))}$.isReactWarning=!0,Object.defineProperty(n,"key",{get:$,configurable:!0})}function S(){var n=i(this.type);return U[n]||(U[n]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),n=this.props.ref,n!==void 0?n:null}function y(n,_,$,R,se,je){var le=$.ref;return n={$$typeof:D,type:n,key:_,props:$,_owner:R},(le!==void 0?le:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:S}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:se}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:je}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function p(n,_,$,R,se,je){var le=_.children;if(le!==void 0)if(R)if(G(le)){for(R=0;R<le.length;R++)g(le[R]);Object.freeze&&Object.freeze(le)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else g(le);if(I.call(_,"key")){le=i(n);var fe=Object.keys(_).filter(function(ee){return ee!=="key"});R=0<fe.length?"{key: someKey, "+fe.join(": ..., ")+": ...}":"{key: someKey}",d[le+R]||(fe=0<fe.length?"{"+fe.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,R,le,fe,le),c[le+R]=!0)}if(le=null,$!==void 0&&(a($),le=""+$),b(L)&&(a(L.key),le=""+L.key),"key"in L){$={};for(var W in L)W!=="key"&&($[W]=L[W])}else $=L;return le&&f($,typeof r=="function"?r.displayName||r.name||"Unknown":r),w(r,le,$,T(),se,je)}function m(r){z(r)?r._store&&(r._store.validated=1):typeof r=="object"&&r!==null&&r.$$typeof===O&&(r._payload.status==="fulfilled"?z(r._payload.value)&&r._payload.value._store&&(r._payload.value._store.validated=1):r._store&&(r._store.validated=1))}function z(r){return typeof r=="object"&&r!==null&&r.$$typeof===N}var F=s,N=Symbol.for("react.transitional.element"),u=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),S=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),D=Symbol.for("react.consumer"),G=Symbol.for("react.context"),g=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),P=Symbol.for("react.suspense_list"),K=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),V=Symbol.for("react.activity"),U=Symbol.for("react.client.reference"),A=F.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,k=Object.prototype.hasOwnProperty,_=Array.isArray,p=console.createTask?console.createTask:function(){return null};F={react_stack_bottom_frame:function(r){return r()}};var y,M={},E=F.react_stack_bottom_frame.bind(F,d)(),Q=p(n(d)),c={};Ne.Fragment=v,Ne.jsx=function(r,L,$){var R=1e4>A.recentlyCreatedOwnerStacks++;return h(r,L,$,!1,R?Error("react-stack-top-frame"):E,R?p(n(r)):Q)},Ne.jsxs=function(r,L,$){var R=1e4>A.recentlyCreatedOwnerStacks++;return h(r,L,$,!0,R?Error("react-stack-top-frame"):E,R?p(n(r)):Q)}})()),Ne}var Rt;function fs(){return Rt||(Rt=1,process.env.NODE_ENV==="production"?Ke.exports=ms():Ke.exports=gs()),Ke.exports}var e=fs();const ys=We.createRequest({baseURL:"/api",timeout:15e3}),qe=We.createRequest({baseURL:"/api",timeout:15e3}),$e=We.createRequest({baseURL:"/api",timeout:15e3});function et(o){const i=function(n,T={}){const d={...T};return d.body!==void 0&&(d.data=d.body,delete d.body),typeof d.method=="string"&&(d.method=d.method.toUpperCase()),d.url=n,o.request(d)};return["get","post","put","delete","patch","head","request","create","interceptors"].forEach(n=>{typeof o[n]=="function"?i[n]=o[n].bind(o):i[n]=o[n]}),i}const te=et(ys);et(qe),et($e);const Bt={GET:"GET",POST:"POST",PUT:"PUT",DELETE:"DELETE"},Ge={};function B(o,i,a,n,T){Ge[o]||(Ge[o]={}),Ge[o][i]={verb:a,path:n,transform:T}}function js(o,i){let a=0;return o.replace(/\{(\w+)\}/g,()=>String(i[a++]??""))}function bs(o,i){return i.startsWith("/ctc/ac")||i.startsWith("/ctc/authorization")||i.startsWith("/ctc/surl")?$e:i.startsWith("/auth/")?qe:te}function ve(o){return new Proxy({},{get:(i,a)=>{if(!(a==="then"||typeof a=="symbol"))return a==="toJSON"||a==="constructor"||a==="toString"?()=>`[apiRouter:${o}]`:async(...n)=>{var d;const T=(d=Ge[o])==null?void 0:d[a];if(!T)return{code:200,message:"ok",data:[],total:0};try{const b=js(T.path,n),f=bs(T.verb,b),j={};T.verb===Bt.GET||T.verb===Bt.DELETE?n.length>0&&typeof n[0]=="object"&&n[0]!==null&&(j.params=n[0]):n.length===1?j.data=n[0]:n.length>1&&(typeof n[0]=="object"&&n[0]!==null&&(j.data=n[0]),typeof n[1]=="object"&&n[1]!==null&&(j.params=n[1]));const w=await f.request({method:T.verb,url:b,...j});return T.transform?T.transform(w,n):w}catch(b){return console.warn(`[apiRouter] ${o}.${a} failed:`,(b==null?void 0:b.message)||b),{code:200,message:"ok",data:[],total:0}}}}})}B("llmApi","knowledgeList","GET","/llm-gateway/knowledge/list"),B("llmApi","skillTemplateList","GET","/llm-gateway/skill/template-list"),B("llmApi","toolTemplateList","GET","/llm-gateway/tool/template-list"),B("llmApi","appConfig","GET","/llm-gateway/app/config"),B("llmApi","appSkillAdd","POST","/llm-gateway/app/skill-add"),B("llmApi","appToolAdd","POST","/llm-gateway/app/tool-add"),B("mcpApi","list","GET","/mcp/server/list"),B("mcpApi","listTools","POST","/mcp/server/tools/list"),B("mcpApi","callTool","POST","/mcp/server/tools/call"),B("mcpApi","test","POST","/mcp/server/test"),B("mcpApi","create","POST","/mcp/server"),B("mcpApi","update","POST","/mcp/server/update"),B("mcpApi","delete","POST","/mcp/server/delete"),B("ossApi","listBuckets","GET","/v1/bucket"),B("ossApi","getBucketStats","GET","/v1/bucket/{bucketName}/stats"),B("ossApi","createBucket","POST","/v1/bucket"),B("ossApi","deleteBucket","DELETE","/v1/bucket/{bucketName}"),B("ossApi","setBucketAcl","PUT","/v1/bucket/{bucketName}/acl"),B("ossApi","listObjects","GET","/v1/object/{bucketName}"),B("ossApi","presignedUrl","GET","/v1/object/{bucketName}/{objectKey}/url"),B("ossApi","uploadObject","POST","/v1/object/{bucketName}/{objectKey}"),B("ossApi","downloadUrl","GET","/v1/object/{bucketName}/{objectKey}/url"),B("ossApi","deleteObject","DELETE","/v1/object/{bucketName}/{objectKey}"),B("ossApi","copyObject","POST","/v1/object/{bucketName}/{objectKey}/copy"),B("ossApi","batchDelete","POST","/v1/object/{bucketName}/batch-delete"),B("ossApi","createFolder","POST","/v1/folder/{bucketName}/{folderKey}"),B("scriptApi","list","GET","/script/list"),B("scriptApi","create","POST","/script"),B("scriptApi","update","POST","/script/update"),B("scriptApi","delete","POST","/script/delete"),B("scriptApi","publish","POST","/script/publish"),B("scriptApi","unpublish","POST","/script/unpublish"),B("scriptApi","run","POST","/script/run"),B("scriptApi","importCurl","POST","/script/import-curl"),B("scriptApi","importOpenApi","POST","/script/import-openapi"),B("scriptApi","previewMapping","POST","/script/preview-mapping"),B("skillApi","page","GET","/skill/page"),B("skillApi","categoryTree","GET","/skill/category-tree"),B("skillApi","create","POST","/skill"),B("skillApi","createCategory","POST","/skill/category"),B("skillApi","deleteCategory","POST","/skill/category/delete"),B("skillApi","getBySkillCode","GET","/skill/by-code"),B("skillApi","install","POST","/skill/install"),B("skillApi","stats","GET","/skill/stats"),B("skillApi","versions","GET","/skill/versions"),B("skillApi","downloadPackage","GET","/skill/download"),B("skillApi","uploadPackage","POST","/skill/upload"),B("agentApi","appPage","POST","/agent/app/page"),B("agentApi","appGet","GET","/agent/app/get"),B("agentApi","appCreate","POST","/agent/app"),B("agentApi","appUpdate","POST","/agent/app/update"),B("agentApi","appDelete","POST","/agent/app/delete"),B("agentApi","appPublish","POST","/agent/app/publish"),B("agentApi","appUpgrade","POST","/agent/app/upgrade"),B("agentApi","appToggleShare","POST","/agent/app/toggleShare"),B("agentApi","versions","GET","/agent/app/versions"),B("agentApi","groupTree","GET","/agent/group/tree"),B("agentApi","groupCreate","POST","/agent/group"),B("agentApi","groupUpdate","POST","/agent/group/update"),B("agentApi","groupDelete","POST","/agent/group/delete"),B("agentApi","chatHistory","GET","/agent/chat/history"),B("agentApi","chatStream","POST","/agent/chat/send"),B("agentApi","chatClear","POST","/agent/chat/clear"),B("agentApi","shareVerify","GET","/agent/share/verify"),B("flowApi","list","GET","/agent/flow/list"),B("flowApi","get","GET","/agent/flow/{id}"),B("flowApi","byFlowId","GET","/agent/flow/byFlowId"),B("flowApi","versions","GET","/agent/flow/versions"),B("flowApi","create","POST","/agent/flow/create"),B("flowApi","update","POST","/agent/flow/update"),B("flowApi","publish","POST","/agent/flow/publish/{id}"),B("flowApi","archive","POST","/agent/flow/archive/{id}"),B("flowApi","newVersion","POST","/agent/flow/newVersion/{parentId}"),B("flowApi","delete","POST","/agent/flow/delete/{id}"),B("flowApi","execute","POST","/agent/flow/execute/{id}"),B("flowApi","health","GET","/agent/flow/health"),B("productApi","page","GET","/v1/products"),B("productApi","create","POST","/v1/products"),B("productApi","update","PUT","/v1/products/{id}"),B("productApi","delete","DELETE","/v1/products/{id}"),B("productApi","publish","POST","/v1/products/{id}/publish"),B("productApi","offline","POST","/v1/products/{id}/offline"),B("productApi","configGet","GET","/v1/products/{id}/config"),B("productApi","configSave","PUT","/v1/products/{id}/config"),B("sceneApi","page","GET","/v1/scenes"),B("sceneApi","create","POST","/v1/scenes"),B("sceneApi","update","PUT","/v1/scenes/{id}"),B("sceneApi","delete","DELETE","/v1/scenes/{id}"),B("sceneApi","duplicate","POST","/v1/scenes/{id}/duplicate"),B("sceneApi","publish","POST","/v1/scenes/{id}/publish"),B("sceneApi","offline","POST","/v1/scenes/{id}/offline"),B("sceneApi","execute","POST","/v1/scenes/{id}/execute"),B("sceneApi","canvasGet","GET","/v1/scenes/{id}/canvas"),B("sceneApi","configGet","GET","/v1/scenes/{id}/config"),B("sceneApi","nodes","GET","/v1/scenes/{id}/nodes"),B("sceneApi","chatHistory","GET","/v1/scenes/{id}/chat-history");const ae=ve("agentApi"),De=ve("flowApi"),Ae=ve("llmApi"),Ie=ve("mcpApi"),be=ve("scriptApi"),ge=ve("skillApi"),Se=ve("productApi"),ue=ve("sceneApi"),me=ve("ossApi"),bt=class bt extends re.CircleNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#52c41a",i.stroke="#52c41a",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#fff",i.fontSize=14,i}};bt.extendKey="start";let tt=bt;const St=class St extends re.RectNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#e6f4ff",i.stroke="#1677ff",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#1677ff",i.fontSize=13,i}};St.extendKey="llm";let st=St;const Ct=class Ct extends re.RectNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#f0f5ff",i.stroke="#2f54eb",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#2f54eb",i.fontSize=13,i}};Ct.extendKey="agent";let lt=Ct;const vt=class vt extends re.PolygonNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#fff7e6",i.stroke="#fa8c16",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#d46b08",i.fontSize=12,i}getAttributes(){const i=super.getAttributes(),a=120,n=80,T=[[i.x,i.y-n/2],[i.x+a/2,i.y],[i.x,i.y+n/2],[i.x-a/2,i.y]];return{...i,points:T,width:a,height:n}}};vt.extendKey="condition";let ot=vt;const Tt=class Tt extends re.RectNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#fff7e6",i.stroke="#fa8c16",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#d46b08",i.fontSize=13,i}};Tt.extendKey="http";let it=Tt;const wt=class wt extends re.RectNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#f6ffed",i.stroke="#13c2c2",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#08979c",i.fontSize=13,i}};wt.extendKey="template";let nt=wt;const kt=class kt extends re.RectNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#f9f0ff",i.stroke="#722ed1",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#722ed1",i.fontSize=13,i}getShape(){const{x:i,y:a,width:n,height:T}=this.getAttributes(),d=n/2,b=T/2,f=12;return re.h("polygon",{points:[[i-d+f,a-b],[i+d-f,a-b],[i+d,a],[i+d-f,a+b],[i-d+f,a+b],[i-d,a]]})}};kt.extendKey="parallel";let rt=kt;const It=class It extends re.CircleNode{getNodeStyle(){const i=super.getNodeStyle();return i.fill="#ff4d4f",i.stroke="#ff4d4f",i.strokeWidth=2,i}getTextStyle(){const i=super.getTextStyle();return i.color="#fff",i.fontSize=14,i}};It.extendKey="end";let at=It;function Ss(o){o.register({type:"start",view:tt,model:re.CircleNodeModel}),o.register({type:"llm",view:st,model:re.RectNodeModel}),o.register({type:"agent",view:lt,model:re.RectNodeModel}),o.register({type:"condition",view:ot,model:re.PolygonNodeModel}),o.register({type:"http",view:it,model:re.RectNodeModel}),o.register({type:"template",view:nt,model:re.RectNodeModel}),o.register({type:"parallel",view:rt,model:re.RectNodeModel}),o.register({type:"end",view:at,model:re.CircleNodeModel})}const ct=[{type:"start",label:"开始",icon:"https://cdn.jsdelivr.net/gh/LogicFlow/static@latest/docs/static/start.png"},{type:"llm",label:"LLM 调用",icon:"🤖"},{type:"agent",label:"Agent 节点",icon:"🤖"},{type:"condition",label:"条件分支",icon:"https://cdn.jsdelivr.net/gh/LogicFlow/static@latest/docs/static/condition.png"},{type:"http",label:"HTTP 请求",icon:"🔗"},{type:"template",label:"模板转换",icon:"📝"},{type:"parallel",label:"并行执行",icon:"⚡"},{type:"end",label:"结束",icon:"https://cdn.jsdelivr.net/gh/LogicFlow/static@latest/docs/static/end.png"}];re.use(Be.Control),re.use(Be.MiniMap),re.use(Be.Menu),re.use(Be.DndPanel),re.use(Be.SelectionSelect);const Ft={nodes:[{id:"start_1",type:"start",x:150,y:280,text:"开始"},{id:"llm_1",type:"llm",x:380,y:280,text:"LLM 调用"},{id:"end_1",type:"end",x:610,y:280,text:"结束"}],edges:[{id:"e1",type:"polyline",sourceNodeId:"start_1",targetNodeId:"llm_1",text:""},{id:"e2",type:"polyline",sourceNodeId:"llm_1",targetNodeId:"end_1",text:""}]},Cs=({node:o,onChange:i,onClose:a})=>{var T,d,b,f,j;if(!o)return null;const n=((T=ct.find(w=>w.type===o.type))==null?void 0:T.label)||o.type;return e.jsxs("div",{style:{position:"absolute",right:16,top:16,width:260,background:"#fff",borderRadius:8,boxShadow:"0 2px 12px rgba(0,0,0,0.12)",padding:16,zIndex:10},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsx("div",{children:e.jsx(t.Tag,{color:"blue",children:n})}),e.jsx(t.Button,{type:"text",size:"small",onClick:a,children:"✕"})]}),e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"节点 ID"}),e.jsx("div",{style:{fontSize:13,color:"#333"},children:o.id})]}),e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"显示文本"}),e.jsx("input",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:o.text,onBlur:w=>i(o.id,{text:w.target.value}),placeholder:"输入显示文本"})]}),o.type==="llm"&&e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"模型"}),e.jsxs("select",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:((d=o.properties)==null?void 0:d.model)||"qwen2.5:7b",onChange:w=>i(o.id,{properties:{...o.properties,model:w.target.value}}),children:[e.jsx("option",{value:"qwen2.5:7b",children:"Qwen 2.5 7B"}),e.jsx("option",{value:"qwen2.5:72b",children:"Qwen 2.5 72B"}),e.jsx("option",{value:"gpt-4o",children:"GPT-4o"})]})]}),o.type==="http"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"HTTP Method"}),e.jsxs("select",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:((b=o.properties)==null?void 0:b.method)||"GET",onChange:w=>i(o.id,{properties:{...o.properties,method:w.target.value}}),children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"}),e.jsx("option",{value:"PUT",children:"PUT"}),e.jsx("option",{value:"DELETE",children:"DELETE"})]})]}),e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"URL"}),e.jsx("input",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:((f=o.properties)==null?void 0:f.url)||"",onBlur:w=>i(o.id,{properties:{...o.properties,url:w.target.value}}),placeholder:"https://api.example.com/..."})]})]}),o.type==="condition"&&e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"条件表达式"}),e.jsx("textarea",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:12,resize:"vertical"},rows:3,defaultValue:((j=o.properties)==null?void 0:j.expression)||"",onBlur:w=>i(o.id,{properties:{...o.properties,expression:w.target.value}}),placeholder:"e.g. status == 'success'"})]})]})},Nt=({readOnly:o=!1,value:i,onChange:a,appCode:n,flowName:T})=>{const d=s.useRef(null),b=s.useRef(null),[f,j]=s.useState(null),[w,h]=s.useState(i||Ft),[m,z]=s.useState(null),[F,N]=s.useState(!1),[u,v]=s.useState(!1);s.useEffect(()=>{if(!d.current)return;const O=new re({container:d.current,grid:{size:20,visible:!0,type:"dot",config:{color:"#e5e5e5"}},keyboard:{enabled:!0},snapline:!0,outline:!0,textEdit:!o,isSilentMode:o,style:{rect:{rx:6,ry:6},polyline:{stroke:"#bfbfbf",strokeWidth:2}},edgeType:"polyline"});Ss(O),O.extension.dndPanel.setPatternItems(ct.map(U=>({type:U.type,label:U.label,icon:U.icon}))),O.extension.miniMap&&O.extension.miniMap.show({width:160,height:100,showEdge:!0,isShowHeader:!1});const V=i||Ft;return O.render(V),h(V),O.on("node:click",({data:U})=>{o||j(U)}),O.on("blank:click",()=>{j(null)}),O.on("graph:change",()=>{const U=O.getGraphData();h(U),a==null||a(U)}),b.current=O,()=>{O.destroy()}},[]);const S=s.useCallback((O,V)=>{if(!b.current)return;b.current.updateText(O,V.text||""),V.properties&&b.current.updateProperties(O,V.properties);const U=b.current.getGraphData().nodes.find(A=>A.id===O);U&&j(U)},[]);s.useCallback(O=>{var k;if(!b.current||o)return;const V=b.current.getGraphData(),U=V.nodes.reduce((_,p)=>_+p.x,0)/(V.nodes.length||1),A=V.nodes.reduce((_,p)=>_+p.y,0)/(V.nodes.length||1);b.current.addNode({type:O,x:U+80,y:A,text:((k=ct.find(_=>_.type===O))==null?void 0:k.label)||O})},[o]);const x=s.useCallback(()=>{var V,U;if(!b.current||o)return;const O=b.current.getSelectedModels();(V=O.nodes)!=null&&V.length&&O.nodes.forEach(A=>b.current.deleteNode(A.id)),(U=O.edges)!=null&&U.length&&O.edges.forEach(A=>b.current.deleteEdge(A.id)),j(null)},[o]),D=s.useCallback(()=>{!b.current||o||b.current.undo()},[o]),G=s.useCallback(()=>{!b.current||o||b.current.redo()},[o]),g=s.useCallback(()=>{if(!b.current)return;const O=b.current.getGraphData();h(O),a==null||a(O),t.message.success("流程已保存到前端")},[a]),C=s.useCallback(async()=>{if(!b.current||!n){t.message.warning("缺少 appCode, 无法保存到后端");return}N(!0);try{const O=b.current.getGraphData(),V={flowId:n,name:T||n,description:`App ${n} 的工作流`,nodes:JSON.stringify(O.nodes||[]),edges:JSON.stringify(O.edges||[]),variables:JSON.stringify(O.variables||{}),flowType:"AGENT",appCode:n,status:"DRAFT",version:1,creator:localStorage.getItem("userInfo")&&JSON.parse(localStorage.getItem("userInfo")||"{}").userCode||"anonymous"};let U;if(m)U=await De.update({...V,id:m});else{U=await De.create(V);const A=(U==null?void 0:U.data)??U;A&&typeof A=="number"?z(A):A&&A.id&&z(A.id)}t.message.success("流程已保存到后端 z_agent_flow_definition"),a==null||a(O)}catch(O){t.message.error("保存到后端失败: "+((O==null?void 0:O.message)||"未知错误"))}finally{N(!1)}},[n,T,m,a]),P=s.useCallback(async()=>{if(!m){t.message.warning('请先点击"保存到后端"');return}try{await De.publish(m),v(!1),t.message.success("流程已发布, 现在可以被 Agent Runtime 执行")}catch(O){t.message.error("发布失败: "+((O==null?void 0:O.message)||"未知错误"))}},[m]);s.useEffect(()=>{!n||o||(async()=>{try{const O=await De.byFlowId({flowId:n,version:1}),V=(O==null?void 0:O.data)??O;V&&V.id&&V.nodes&&(z(V.id),b.current&&b.current.render({nodes:JSON.parse(V.nodes),edges:JSON.parse(V.edges)}),t.message.info("已加载上次保存的工作流 v"+(V.version||1)))}catch{}})()},[n]);const K=s.useCallback(()=>{j(null)},[]);return e.jsxs("div",{style:{position:"relative",height:520,borderRadius:8,overflow:"hidden",background:"#fafafa",border:"1px solid #e8e8e8"},children:[!o&&e.jsxs("div",{style:{position:"absolute",top:8,left:8,zIndex:5,display:"flex",gap:6,alignItems:"center",background:"#fff",borderRadius:6,padding:"4px 8px",boxShadow:"0 1px 6px rgba(0,0,0,0.08)"},children:[e.jsxs(t.Space,{size:4,children:[e.jsx(t.Tooltip,{title:"撤销",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.UndoOutlined,{}),onClick:D})}),e.jsx(t.Tooltip,{title:"重做",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.RedoOutlined,{}),onClick:G})}),e.jsx("div",{style:{width:1,height:16,background:"#e8e8e8",margin:"0 2px"}}),e.jsx(t.Tooltip,{title:"删除选中",children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:x})}),e.jsx(t.Tooltip,{title:"保存到前端 (AgentApp)",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.SaveOutlined,{}),onClick:g})}),e.jsx("div",{style:{width:1,height:16,background:"#e8e8e8",margin:"0 2px"}}),e.jsx(t.Tooltip,{title:"保存到后端 z_agent_flow_definition (FEATURE013 A5)",children:e.jsx(t.Button,{size:"small",type:"primary",ghost:!0,icon:e.jsx(l.CloudUploadOutlined,{}),loading:F,disabled:!n,onClick:C,children:"保存流程"})}),e.jsx(t.Tooltip,{title:"发布 (DRAFT → PUBLISHED, FlowEngine 可加载执行)",children:e.jsx(t.Button,{size:"small",type:"primary",disabled:!m,onClick:()=>v(!0),children:"发布"})})]}),m&&e.jsxs(t.Tag,{color:"blue",style:{marginLeft:8},children:["flowId=",m]}),e.jsx("div",{style:{fontSize:12,color:"#999",marginLeft:8},children:"从左侧拖入节点到画布,双击节点编辑文本"})]}),e.jsxs(t.Modal,{title:"发布工作流",open:u,onOk:P,onCancel:()=>v(!1),okText:"确认发布",cancelText:"取消",children:[e.jsxs("p",{children:["发布后, ",e.jsx("b",{children:"FlowOrchestrationService"})," 会在下次请求时加载这个 flow, Agent Runtime 可以通过 ",e.jsxs("code",{children:["/api/agent/flow/execute/",m]})," 触发执行。"]}),e.jsx("p",{style:{color:"#999",fontSize:12},children:"提示: 如需修改, 需点击「升级到新版本」创建草稿。"})]}),e.jsx("div",{ref:d,style:{width:"100%",height:"100%"}}),f&&!o&&e.jsx(Cs,{node:f,onChange:S,onClose:K}),o&&e.jsx("div",{style:{position:"absolute",top:8,right:8,zIndex:5,background:"rgba(0,0,0,0.5)",color:"#fff",borderRadius:4,padding:"2px 8px",fontSize:12},children:"只读模式"})]})},{TextArea:Pe}=t.Input,{Text:Te,Title:vs}=t.Typography,Dt={ollama:[{code:"qwen2.5:7b-instruct-q4_K_M",name:"Qwen 2.5 7B"},{code:"qwen3:8b",name:"Qwen3 8B"},{code:"llama3:latest",name:"Llama 3"},{code:"qwen2.5:14b-instruct-q4_K_M",name:"Qwen 2.5 14B"}],openai:[{code:"gpt-4o",name:"GPT-4o"},{code:"gpt-4o-mini",name:"GPT-4o Mini"},{code:"gpt-4-turbo",name:"GPT-4 Turbo"}],dashscope:[{code:"qwen-max",name:"Qwen Max"},{code:"qwen-plus",name:"Qwen Plus"},{code:"qwen-turbo",name:"Qwen Turbo"}]},Lt={chat:{label:"对话",icon:e.jsx(l.MessageOutlined,{}),color:"#1677ff",desc:"纯文本对话,配置 Prompt + 模型即可",tabs:["basic","prompt","modelParams","memory"],tabLabels:{basic:"基本信息",prompt:"系统提示词",modelParams:"模型参数",memory:"记忆配置"}},agent:{label:"智能体",icon:e.jsx(l.RobotOutlined,{}),color:"#722ed1",desc:"工具调用 + 技能 + 知识库,具备自主决策能力",tabs:["basic","prompt","modelParams","memory","tools","skills","variables","knowledge"],tabLabels:{basic:"基本信息",prompt:"系统提示词",modelParams:"模型参数",memory:"记忆配置",tools:"工具配置",skills:"技能配置",variables:"变量配置",knowledge:"知识库"}},workflow:{label:"工作流",icon:e.jsx(l.ApartmentOutlined,{}),color:"#13c2c2",desc:"可视化多步骤流程编排",tabs:["basic","modelParams","workflow"],tabLabels:{basic:"基本信息",modelParams:"模型参数",workflow:"流程编排"}}},Mt=({app:o,onBack:i,onSaved:a})=>{const[n,T]=s.useState(o),d=n.status==="PUBLISHED",b=n.agentMode||"chat",f=Lt[b]||Lt.chat,[j,w]=s.useState(!1),[h,m]=s.useState(!1),[z,F]=s.useState(f.tabs[0]),[N]=t.Form.useForm(),[u,v]=s.useState(null);s.useEffect(()=>{z&&!f.tabs.includes(z)&&F(f.tabs[0])},[b]);const S=g=>{T(C=>({...C,agentMode:g})),N.setFieldsValue({agentMode:g})},x=async()=>{try{const g=await N.validateFields();w(!0),await ae.appUpdate({id:n.id,agentMode:b,...g,workflowData:u}),t.message.success("保存成功"),a==null||a()}catch(g){g.errorFields||t.message.error("保存失败")}finally{w(!1)}},D=async()=>{try{await ae.appPublish(n.appCode),t.message.success("发布成功"),a==null||a()}catch{t.message.error("发布失败")}},G=async()=>{try{m(!0);const g=await ae.appUpgrade(n.appCode),C=(g==null?void 0:g.data)||g;C&&(T(C),t.message.success(`已升级到 ${C.version||"新"} 版本,可编辑后发布`))}catch(g){t.message.error("升级失败:"+((g==null?void 0:g.message)||"未知错误"))}finally{m(!1)}};return e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",borderBottom:"1px solid #f0f0f0",background:"#fff",flexShrink:0},children:[e.jsx(t.Button,{type:"text",icon:e.jsx(l.ArrowLeftOutlined,{}),onClick:i}),e.jsxs(vs,{level:5,style:{margin:0,flex:1,minWidth:0},children:[e.jsx("span",{style:{marginRight:8},children:n.appName}),e.jsxs(t.Tag,{color:f.color,style:{borderRadius:20,marginRight:4},children:[f.icon," ",f.label]}),e.jsx(t.Tag,{color:d?"green":"default",style:{borderRadius:20},children:d?"已发布":"草稿"})]}),e.jsx("div",{style:{flex:1}}),d?e.jsx(t.Button,{icon:e.jsx(l.DiffOutlined,{}),loading:h,onClick:G,children:"升级到新草稿"}):e.jsxs(t.Space,{children:[e.jsx(t.Button,{icon:e.jsx(l.SaveOutlined,{}),type:"primary",ghost:!0,onClick:x,loading:j,children:"保存"}),e.jsx(t.Button,{icon:e.jsx(l.RocketOutlined,{}),type:"primary",onClick:D,children:"发布"})]})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:16,background:"#f5f5f5"},children:[d&&e.jsx(t.Alert,{type:"warning",showIcon:!0,icon:e.jsx(l.EyeOutlined,{}),message:"查看模式:当前为已发布版本,所有字段仅可浏览不可修改",description:"如需调整配置,请点击右上角「升级到新草稿」按钮,系统会基于当前版本创建一份可编辑的草稿。",style:{marginBottom:16,borderRadius:8}}),e.jsx(t.Card,{size:"small",style:{marginBottom:16,borderLeft:`3px solid ${f.color}`},bodyStyle:{padding:"12px 16px"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,flexWrap:"wrap"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:120},children:[e.jsx("span",{style:{fontSize:18,color:f.color},children:f.icon}),e.jsxs("div",{children:[e.jsx(Te,{strong:!0,style:{fontSize:13},children:"应用类型"}),e.jsx("div",{children:e.jsxs(Te,{type:"secondary",style:{fontSize:12},children:[f.label,"模式"]})})]})]}),e.jsx(t.Select,{value:b,disabled:d,onChange:S,style:{flex:1,maxWidth:400},options:[{value:"chat",label:e.jsxs("span",{children:[e.jsx(l.MessageOutlined,{style:{color:"#1677ff"}})," 对话 - 纯文本对话"]})},{value:"agent",label:e.jsxs("span",{children:[e.jsx(l.RobotOutlined,{style:{color:"#722ed1"}})," 智能体 - 工具调用 + 知识库"]})},{value:"workflow",label:e.jsxs("span",{children:[e.jsx(l.ApartmentOutlined,{style:{color:"#13c2c2"}})," 工作流 - 多步骤流程编排"]})}]}),e.jsx(Te,{type:"secondary",style:{fontSize:12},children:f.desc})]})}),e.jsx(t.Card,{size:"small",children:e.jsx(t.Tabs,{activeKey:z,onChange:F,style:{minHeight:300},children:f.tabs.map(g=>{var C;return e.jsx(t.Tabs.TabPane,{tab:f.tabLabels[g]||g,children:e.jsxs(t.Form,{form:N,layout:"vertical",initialValues:{appName:n.appName,description:n.description,prompt:n.prompt,modelProvider:n.modelProvider||"ollama",modelName:n.modelName||"qwen2.5:7b-instruct-q4_K_M",iconUrl:n.iconUrl,tools:n.tools,skillCodes:n.skillCodes,variables:n.variables,knowledgeIds:n.knowledgeIds,temperature:n.temperature??.7,topP:n.topP??.9,maxTokens:n.maxTokens??4096,historyWindowSize:n.historyWindowSize??50,enableLongMemory:n.enableLongMemory??!1,memoryPrompt:n.memoryPrompt||""},children:[g==="basic"&&e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:16,children:e.jsx(t.Form.Item,{name:"appName",label:"应用名称",rules:[{required:!0}],children:e.jsx(t.Input,{disabled:d})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"iconUrl",label:"图标 URL",children:e.jsx(t.Input,{disabled:d,placeholder:"图片URL"})})}),e.jsx(t.Col,{span:24,children:e.jsx(t.Form.Item,{name:"description",label:"应用描述",children:e.jsx(Pe,{rows:2,disabled:d})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"modelProvider",label:"供应商",rules:[{required:!0}],children:e.jsxs(t.Select,{disabled:d,onChange:P=>{const K=Dt[P]||[];K[0]&&N.setFieldsValue({modelName:K[0].code})},children:[e.jsx(t.Select.Option,{value:"ollama",children:"Ollama"}),e.jsx(t.Select.Option,{value:"openai",children:"OpenAI"}),e.jsx(t.Select.Option,{value:"dashscope",children:"阿里通义"})]})})}),e.jsx(t.Col,{span:16,children:e.jsx(t.Form.Item,{name:"modelName",label:"模型",rules:[{required:!0}],children:e.jsx(t.Select,{disabled:d,children:(Dt[((C=N.getFieldValue)==null?void 0:C.call(N,"modelProvider"))||n.modelProvider||"ollama"]||[]).map(P=>e.jsx(t.Select.Option,{value:P.code,children:P.name},P.code))})})})]}),g==="prompt"&&e.jsx(t.Form.Item,{name:"prompt",label:"系统提示词",extra:"定义 Agent 的身份、能力、行为规范和约束条件",children:e.jsx(Pe,{rows:12,disabled:d,placeholder:"你是智能助手,负责回答用户问题..."})}),g==="modelParams"&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"模型参数控制生成行为。不同模型支持的参数范围略有差异。",style:{marginBottom:16,border:"none",background:"#e6f4ff"}}),e.jsxs(t.Card,{size:"small",style:{background:"#fafafa",marginBottom:16},children:[e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(Te,{strong:!0,children:[e.jsx(l.ThunderboltOutlined,{})," 采样参数"]}),e.jsx(Te,{type:"secondary",style:{marginLeft:8,fontSize:12},children:"控制生成多样性和确定性"})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"temperature",label:"Temperature 温度",extra:"0=确定性,2=高随机",children:e.jsx(t.InputNumber,{min:0,max:2,step:.1,disabled:d,style:{width:"100%"}})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"topP",label:"Top P 核采样",extra:"0-1,建议 0.9",children:e.jsx(t.InputNumber,{min:0,max:1,step:.05,disabled:d,style:{width:"100%"}})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"maxTokens",label:"Max Tokens 最大输出",extra:"单次响应最大 token 数",children:e.jsx(t.InputNumber,{min:100,max:128e3,step:100,disabled:d,style:{width:"100%"}})})})]})]})]}),g==="memory"&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"记忆配置控制对话上下文管理",style:{marginBottom:16,border:"none",background:"#e6f4ff"}}),e.jsxs(t.Card,{size:"small",style:{background:"#fafafa",marginBottom:16},children:[e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(Te,{strong:!0,children:[e.jsx(l.DatabaseOutlined,{})," 历史窗口"]}),e.jsx(Te,{type:"secondary",style:{marginLeft:8,fontSize:12},children:"保留最近 N 条对话消息作为上下文"})]}),e.jsx(t.Form.Item,{name:"historyWindowSize",label:"历史窗口大小",children:e.jsx(t.InputNumber,{min:0,max:100,disabled:d,style:{width:200}})})]}),e.jsxs(t.Card,{size:"small",style:{background:"#fafafa",marginBottom:16},children:[e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(Te,{strong:!0,children:[e.jsx(l.BookOutlined,{})," 长期记忆"]}),e.jsx(Te,{type:"secondary",style:{marginLeft:8,fontSize:12},children:"跨会话持久化关键信息"})]}),e.jsx(t.Form.Item,{name:"enableLongMemory",label:"启用长期记忆",valuePropName:"checked",children:e.jsx(t.Switch,{disabled:d})}),e.jsx(t.Form.Item,{name:"memoryPrompt",label:"记忆提示词",extra:"定义如何总结和存储对话内容",children:e.jsx(Pe,{rows:3,disabled:d,placeholder:"例:提取用户的偏好和关键事实,以 JSON 结构存储..."})})]})]}),g==="tools"&&e.jsx(t.Form.Item,{name:"tools",label:"工具配置",extra:"JSON 数组格式",children:e.jsx(Pe,{rows:8,disabled:d,placeholder:'[{"toolCode":"web-search","toolName":"网页搜索"}]'})}),g==="skills"&&e.jsx(t.Form.Item,{name:"skillCodes",label:"技能编码",extra:"JSON 数组格式",children:e.jsx(Pe,{rows:8,disabled:d,placeholder:'["code-review", "data-analyzer"]'})}),g==="variables"&&e.jsx(t.Form.Item,{name:"variables",label:"变量配置",extra:"JSON 数组格式",children:e.jsx(Pe,{rows:8,disabled:d,placeholder:'[{"name":"userName","label":"用户名","type":"string"}]'})}),g==="knowledge"&&e.jsx(t.Form.Item,{name:"knowledgeIds",label:"知识库",extra:"JSON 数组格式",children:e.jsx(Pe,{rows:8,disabled:d,placeholder:"[1, 2, 3]"})}),g==="workflow"&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"工作流模式使用轻量引擎,支持中断恢复。节点定义存储在应用配置中。",style:{marginBottom:16,border:"none",background:"#e6f4ff"}}),e.jsx(We.ErrorBoundary,{fallbackTitle:"流程编辑器加载失败",fallbackDescription:"LogicFlow 初始化异常。请重试,或切换到「对话」/「智能体」模式后重新切回工作流。",onReset:()=>v(null),children:e.jsx(Nt,{readOnly:d,value:u,onChange:v,appCode:n.appCode,flowName:n.appName})})]})]})},g)})})})]})]})},{TextArea:Ts}=t.Input,{Option:we}=t.Select,{TabPane:dt}=t.Tabs,{Text:xe,Title:ze}=t.Typography,_t=()=>{const[o,i]=s.useState(""),[a,n]=s.useState(""),[T,d]=s.useState(0),[b,f]=s.useState(null),j=()=>d(w=>w+1);return b?e.jsx("div",{style:{flex:1,overflow:"hidden",borderRadius:8,background:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(Mt,{app:b,onBack:()=>{f(null),j()},onSaved:()=>{f(null),j()}})}):e.jsxs("div",{style:{display:"flex",gap:16,height:"calc(100vh - 180px)",padding:16},children:[e.jsx(t.Card,{size:"small",style:{width:300,overflow:"auto",flexShrink:0},title:"分组",extra:e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:j}),children:e.jsx(ks,{selectedGroupCode:o,onGroupSelect:(w,h)=>{i(w||""),n(w&&h||"")},onGroupRefresh:j},T)}),e.jsx(t.Card,{size:"small",style:{flex:1,overflow:"auto"},title:a||void 0,children:e.jsx(Ps,{selectedGroupCode:o,onEditApp:f})})]})},pt={ollama:[{code:"qwen2.5:7b-instruct-q4_K_M",name:"Qwen 2.5 7B"},{code:"qwen3:8b",name:"Qwen3 8B"},{code:"llama3:latest",name:"Llama 3"},{code:"qwen2.5:14b-instruct-q4_K_M",name:"Qwen 2.5 14B"}],openai:[{code:"gpt-4o",name:"GPT-4o"},{code:"gpt-4o-mini",name:"GPT-4o Mini"},{code:"gpt-4-turbo",name:"GPT-4 Turbo"}],dashscope:[{code:"qwen-max",name:"Qwen Max"},{code:"qwen-plus",name:"Qwen Plus"},{code:"qwen-turbo",name:"Qwen Turbo"}]},ws=o=>{const i={};o.forEach(n=>{i[n.groupCode]={key:n.groupCode,title:n.groupName,children:[]}});const a=[];return o.forEach(n=>{const T=i[n.groupCode];n.parentCode&&i[n.parentCode]?i[n.parentCode].children.push(T):n.parentCode||a.push(T)}),a},ks=({selectedGroupCode:o,onGroupSelect:i,onGroupRefresh:a})=>{const[n,T]=s.useState([]),[d,b]=s.useState(!1),[f,j]=s.useState(!1),[w,h]=s.useState(null),[m,z]=s.useState(null),[F]=t.Form.useForm(),N=s.useRef(null),u=g=>{i(g===o?"":g,"")},v=()=>{b(!0),ae.groupTree().then(g=>{T((g==null?void 0:g.data)||g||[])}).finally(()=>b(!1))};s.useEffect(()=>{v()},[]);const S=()=>{const g={};n.forEach(P=>{g[P.groupCode]={key:P.groupCode,title:P.groupName,groupCode:P.groupCode,parentCode:P.parentCode||"",icon:o===P.groupCode?e.jsx(l.FolderOpenOutlined,{}):e.jsx(l.FolderOutlined,{}),data:P,children:[]}});const C=[];return n.forEach(P=>{const K=g[P.groupCode];P.parentCode&&g[P.parentCode]?g[P.parentCode].children.push(K):P.parentCode||C.push(K)}),C},x=g=>{const C=n.find(P=>P.groupCode===g.groupCode);return e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,padding:"2px 0",cursor:"pointer"},onClick:()=>u(g.groupCode),children:[e.jsx("span",{style:{flex:1,fontSize:13},children:g.title}),e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.PlusOutlined,{style:{fontSize:11,color:"#1890ff"}}),onClick:P=>{P.stopPropagation(),z(C),h(null),F.resetFields(),F.setFieldsValue({parentCode:g.groupCode}),j(!0)},title:"新增子分组"}),e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.EditOutlined,{style:{fontSize:11}}),onClick:P=>{P.stopPropagation(),h(C),F.setFieldsValue({groupName:C.groupName,parentCode:C.parentCode||""}),z(null),j(!0)}}),e.jsx(t.Popconfirm,{title:`删除分组"${C.groupName}"?`,description:"子分组也会被删除",onConfirm:()=>D(g.groupCode),onCancel:P=>P==null?void 0:P.stopPropagation(),children:e.jsx(t.Button,{type:"text",size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{style:{fontSize:11}}),onClick:P=>P.stopPropagation()})})]})]})},D=async g=>{try{await ae.groupDelete(g),t.message.success("删除成功"),a()}catch{t.message.error("删除失败")}},G=async()=>{try{const g=await F.validateFields();b(!0),w?(await ae.groupUpdate({groupCode:w.groupCode,groupName:g.groupName,parentCode:g.parentCode||""}),t.message.success("更新成功")):(await ae.groupCreate({groupName:g.groupName,parentCode:g.parentCode||"",groupCode:"grp_"+Date.now()}),t.message.success("创建成功")),j(!1),a()}catch{t.message.error("操作失败")}finally{b(!1)}};return e.jsxs("div",{style:{padding:"4px 0"},children:[e.jsx("div",{style:{maxHeight:"calc(100vh - 320px)",overflow:"auto"},children:e.jsx(t.Tree,{treeData:S(),defaultExpandAll:!0,showLine:!0,blockNode:!0,titleRender:x,selectedKeys:o?[o]:[],onSelect:()=>{}})}),e.jsx(t.Modal,{title:w?"编辑分组":m?`新建子分组 - ${m.groupName}`:"新建分组",open:f,onCancel:()=>j(!1),onOk:()=>F.submit(),destroyOnClose:!0,children:e.jsxs(t.Form,{form:F,layout:"vertical",onFinish:G,children:[e.jsx(t.Form.Item,{name:"groupName",label:"分组名称",rules:[{required:!0,message:"请输入分组名称"}],children:e.jsx(t.Input,{ref:N,placeholder:"如:客服机器人"})}),e.jsx(t.Form.Item,{name:"parentCode",label:"父分组",children:e.jsx(t.Select,{allowClear:!0,placeholder:"留空为顶级分组",children:n.filter(g=>w?g.groupCode!==w.groupCode:!0).map(g=>e.jsx(t.Select.Option,{value:g.groupCode,children:g.groupName},g.groupCode))})})]})})]})},Is=({record:o,onEdit:i,onView:a,onPublish:n,onUpgrade:T,onShare:d,onDelete:b,onToolConfig:f,onToggleShare:j,loading:w})=>{var F,N;const h=o.status==="PUBLISHED",m=o.version||1,z=!!o.shareEnabled;return e.jsx(t.Card,{hoverable:!0,style:{borderRadius:12,border:"1px solid #f0f0f0",transition:"all 0.3s"},bodyStyle:{padding:16},actions:[h?e.jsx(t.Tooltip,{title:"查看发布版本(只读)",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>a==null?void 0:a(o),children:"查看"})},"view"):e.jsx(t.Tooltip,{title:"编辑草稿",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.EditOutlined,{}),onClick:()=>i(o),children:"编辑"})},"edit"),h?e.jsx(t.Tooltip,{title:"基于当前版本创建新草稿",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.DiffOutlined,{}),onClick:()=>T==null?void 0:T(o),children:"升级"})},"upgrade"):e.jsx(t.Tooltip,{title:"发布后即可分享",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.RocketOutlined,{}),onClick:()=>n(o.appCode),children:"发布"})},"publish"),e.jsx(t.Tooltip,{title:z?"查看/复制分享链接":"开启后生成分享链接",children:e.jsx(t.Button,{type:"text",icon:z?e.jsx(l.GlobalOutlined,{style:{color:"#52c41a"}}):e.jsx(l.LockOutlined,{}),onClick:()=>d==null?void 0:d(o),children:"分享"})},"share"),e.jsx(t.Tooltip,{title:"工具配置",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.SettingOutlined,{}),onClick:()=>f==null?void 0:f(o),children:"工具"})},"tools"),e.jsx(t.Popconfirm,{title:"确定删除此应用?",onConfirm:()=>b(o.id),okText:"删除",okButtonProps:{danger:!0},children:e.jsx(t.Button,{type:"text",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),children:"删除"})},"delete")],children:e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsx(t.Avatar,{shape:"square",size:64,src:o.iconUrl,icon:e.jsx(l.RobotOutlined,{}),style:{background:h?"linear-gradient(135deg, #52c41a 0%, #389e0d 100%)":"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:8},children:[e.jsxs("div",{children:[e.jsx(ze,{level:5,style:{margin:0,color:"#262626"},children:o.appName}),e.jsx(xe,{type:"secondary",style:{fontSize:12,fontFamily:"monospace"},children:o.appCode})]}),e.jsxs(t.Space,{size:4,children:[e.jsxs(t.Tag,{style:{borderRadius:20,fontSize:11},children:["v",m]}),e.jsx(t.Tag,{color:h?"success":"default",style:{borderRadius:20},children:h?"已发布":"草稿"}),z&&e.jsx(t.Tooltip,{title:"已开启分享,点击「分享」按钮获取链接",children:e.jsx(t.Tag,{color:"green",icon:e.jsx(l.GlobalOutlined,{}),style:{borderRadius:20,fontSize:11,margin:0},children:"已分享"})})]})]}),o.description&&e.jsx("div",{style:{color:"#595959",fontSize:13,marginBottom:12,lineHeight:1.6},children:o.description}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx(t.Tag,{color:"blue",style:{margin:0},children:o.modelProvider||"ollama"}),e.jsx(xe,{style:{fontSize:13,color:"#8c8c8c"},children:o.modelName||"qwen2.5:7b"})]}),e.jsxs("div",{style:{display:"flex",gap:16,fontSize:12,color:"#8c8c8c",marginTop:8},children:[e.jsxs("span",{children:["创建于 ",((F=o.gmtCreate)==null?void 0:F.split(" ")[0])||"-"]}),o.gmtModified!==o.gmtCreate&&e.jsxs("span",{children:["更新于 ",((N=o.gmtModified)==null?void 0:N.split(" ")[0])||"-"]})]})]})]})})},Os=({app:o,onEnable:i})=>{const[a,n]=s.useState(!1);return e.jsxs("div",{style:{padding:"24px 0",textAlign:"center"},children:[e.jsx("div",{style:{width:96,height:96,borderRadius:"50%",margin:"24px auto",background:"linear-gradient(135deg, #f6ffed 0%, #d9f7be 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.LockOutlined,{style:{fontSize:40,color:"#52c41a"}})}),e.jsx(ze,{level:5,style:{marginTop:8},children:"该应用尚未开启分享"}),e.jsxs(xe,{type:"secondary",style:{display:"block",marginBottom:24,fontSize:13},children:["开启后,任何人都可通过专属链接访问该 Agent",e.jsx("br",{}),"无需登录、可嵌入网页 / 群聊 / 二维码"]}),e.jsx(t.Button,{type:"primary",size:"large",icon:e.jsx(l.GlobalOutlined,{}),loading:a,onClick:async()=>{n(!0);try{await i()}finally{n(!1)}},style:{borderRadius:8,minWidth:160},children:"开启分享"}),e.jsx(t.Divider,{style:{margin:"32px 0 16px"},plain:!0,children:e.jsx(xe,{type:"secondary",style:{fontSize:12},children:"分享后你可以获得"})}),e.jsx(t.Space,{orientation:"vertical",size:"small",style:{width:"100%",textAlign:"left",padding:"0 16px"},children:[{icon:e.jsx(l.LinkOutlined,{}),text:"独立的访问链接与二维码"},{icon:e.jsx(l.CopyOutlined,{}),text:"一键复制到微信 / 飞书 / 邮件"},{icon:e.jsx(l.EyeOutlined,{}),text:"实时统计访问人数与对话轮次"}].map((T,d)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#595959",fontSize:13},children:[e.jsx("span",{style:{color:"#52c41a"},children:T.icon}),T.text]},d))})]})},As=({app:o,onDisable:i,onRefresh:a})=>{var h,m;const n=o.shareCode?`${window.location.origin}/share/${o.shareCode}`:"",[T,d]=s.useState(!1),[b,f]=s.useState(!1),j=async()=>{if(n)try{await navigator.clipboard.writeText(n),d(!0),t.message.success("链接已复制"),setTimeout(()=>d(!1),2e3)}catch{const z=document.createElement("textarea");z.value=n,document.body.appendChild(z),z.select(),document.execCommand("copy"),document.body.removeChild(z),d(!0),t.message.success("链接已复制"),setTimeout(()=>d(!1),2e3)}},w=async()=>{f(!0);try{await a()}finally{f(!1)}};return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"success",showIcon:!0,message:"已开启分享",description:"链接现在可被任何人访问,关闭分享后旧链接立即失效。",style:{borderRadius:8,marginBottom:20}}),e.jsxs("div",{style:{display:"flex",gap:20,padding:20,background:"#fafafa",borderRadius:12,alignItems:"center",marginBottom:20},children:[e.jsx("div",{style:{background:"#fff",padding:12,borderRadius:8,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flexShrink:0},children:n?e.jsx(t.QRCode,{value:n,size:140,bordered:!1}):e.jsx("div",{style:{width:140,height:140,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(xe,{type:"secondary",children:"无链接"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx(xe,{type:"secondary",style:{fontSize:12},children:"分享链接"}),e.jsx(t.Input.TextArea,{value:n,readOnly:!0,autoSize:{minRows:2,maxRows:3},style:{marginTop:4,fontSize:12,fontFamily:"monospace",resize:"none"},onClick:z=>z.target.select()}),e.jsxs(t.Space,{style:{marginTop:8},size:"small",children:[e.jsx(t.Button,{type:"primary",size:"small",icon:T?e.jsx(l.CheckCircleFilled,{}):e.jsx(l.CopyOutlined,{}),onClick:j,disabled:!n,children:T?"已复制":"复制链接"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.LinkOutlined,{}),onClick:()=>n&&window.open(n,"_blank"),disabled:!n,children:"打开"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),loading:b,onClick:w,children:"刷新链接"})]})]})]}),e.jsxs("div",{style:{marginBottom:20},children:[e.jsx(ze,{level:5,style:{fontSize:13,marginBottom:12},children:"分享设置"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"访问方式"}),e.jsx("div",{style:{marginTop:4},children:e.jsx(t.Tag,{color:"blue",style:{margin:0},children:"公开链接"})})]}),e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"是否需要登录"}),e.jsx("div",{style:{marginTop:4},children:e.jsx(t.Tag,{style:{margin:0},children:"不需要"})})]}),e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"创建时间"}),e.jsx("div",{style:{marginTop:4,fontSize:13},children:((h=o.shareGmtCreate)==null?void 0:h.split(" ")[0])||((m=o.gmtModified)==null?void 0:m.split(" ")[0])||"-"})]}),e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"累计访问"}),e.jsxs("div",{style:{marginTop:4,fontSize:13},children:[o.shareVisitCount??0," 次"]})]})]})]}),e.jsx(t.Divider,{style:{margin:"12px 0"}}),e.jsx(t.Popconfirm,{title:"确定要关闭分享吗?",description:"关闭后,链接将立即失效。",okText:"关闭分享",okButtonProps:{danger:!0},cancelText:"取消",onConfirm:i,children:e.jsx(t.Button,{block:!0,danger:!0,icon:e.jsx(l.LockOutlined,{}),children:"关闭分享"})})]})},Ps=({selectedGroupCode:o,onEditApp:i})=>{const[a,n]=s.useState([]),[T,d]=s.useState(!1),[b,f]=s.useState(""),[j,w]=s.useState(""),[h,m]=s.useState(1),[z]=s.useState(12),[F,N]=s.useState(0),[u,v]=s.useState(!1),[S,x]=s.useState([]),[D,G]=s.useState(!1),[g,C]=s.useState(null),[P,K]=s.useState(!1),[O,V]=s.useState(null),[U,A]=s.useState("card"),[k,_]=s.useState(pt.ollama),[p,y]=s.useState(!1),[M]=t.Form.useForm(),[E,Q]=s.useState([]);s.useEffect(()=>{c(),r()},[h,b,j,o]);const c=()=>{d(!0),ae.appPage({appName:b,status:j,groupCode:o,id:h}).then(H=>{H&&(n(H.records||[]),N(H.total||0))}).catch(H=>t.message.error("加载失败")).finally(()=>d(!1))},r=()=>{ae.groupTree().then(H=>{const X=(H==null?void 0:H.data)||H||[];x(X),Q(X.filter(ie=>ie.groupCode)),c()})},L=()=>{var ie;M.resetFields();const H="ollama",X=pt[H]||[];_(X),M.setFieldsValue({modelProvider:H,modelName:((ie=X[0])==null?void 0:ie.code)||"",groupCode:o}),y(!0)},$=async()=>{try{const H=await M.validateFields();v(!0),await ae.appCreate(H),t.message.success("创建成功"),y(!1),c()}catch(H){H.errorFields||t.message.error("操作失败")}finally{v(!1)}},R=H=>{i(H)},se=H=>{i(H)},je=async H=>{try{await ae.appDelete(H),t.message.success("删除成功"),c()}catch{t.message.error("删除失败")}},le=async H=>{try{await ae.appPublish(H),t.message.success("发布成功"),c()}catch{t.message.error("发布失败")}},fe=async H=>{try{await ae.appUpgrade(H.appCode),t.message.success("已升级到新草稿版本,可编辑后发布"),c();const X=await ae.appGet(H.appCode),ie=(X==null?void 0:X.data)||X;ie&&i(ie)}catch(X){t.message.error("升级失败:"+((X==null?void 0:X.message)||"未知错误"))}},W=H=>{V(H),K(!0)},ee=async(H,X)=>{try{const ie=await ae.appToggleShare(H.appCode,X),he=(ie==null?void 0:ie.data)||ie;t.message.success(X?"已开启分享":"已关闭分享"),n(ne=>ne.map(ye=>ye.id===H.id?{...ye,shareEnabled:X,shareCode:he||ye.shareCode}:ye)),V(ne=>ne&&ne.id===H.id?{...ne,shareEnabled:X,shareCode:he||ne.shareCode}:ne)}catch(ie){t.message.error("操作失败:"+((ie==null?void 0:ie.message)||"未知错误"))}},ce=a.filter(H=>H.status==="PUBLISHED").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16,padding:"16px 20px",background:"#fafafa",borderRadius:8},children:[e.jsxs(t.Space,{wrap:!0,children:[e.jsx(t.Input.Search,{placeholder:"搜索应用名称/编码",onSearch:H=>{f(H),m(1)},style:{width:280},allowClear:!0,enterButton:!0}),e.jsxs(t.Select,{placeholder:"状态筛选",allowClear:!0,style:{width:140},onChange:H=>{w(H),m(1)},children:[e.jsx(we,{value:"DRAFT",children:"草稿"}),e.jsx(we,{value:"PUBLISHED",children:"已发布"})]})]}),e.jsxs(t.Space,{children:[F>0&&e.jsxs(xe,{type:"secondary",children:["共 ",e.jsx(xe,{strong:!0,children:F})," 个应用,已发布 ",e.jsx(xe,{strong:!0,style:{color:"#52c41a"},children:ce})," 个"]}),e.jsx(t.Button,{size:"small",type:U==="card"?"primary":"default",icon:e.jsx(l.AppstoreFilled,{}),onClick:()=>A("card"),style:{borderRadius:6}}),e.jsx(t.Button,{size:"small",type:U==="list"?"primary":"default",icon:e.jsx(l.UnorderedListOutlined,{}),onClick:()=>A("list"),style:{borderRadius:6}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:L,style:{borderRadius:8},children:"新建应用"})]})]}),T&&e.jsxs("div",{style:{textAlign:"center",padding:48},children:[e.jsx(l.LoadingOutlined,{style:{fontSize:32,color:"#667eea"}}),e.jsx("div",{style:{marginTop:16,color:"#8c8c8c"},children:"加载中..."})]}),!T&&a.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"64px 24px",background:"#fafafa",borderRadius:12},children:[e.jsx("div",{style:{width:80,height:80,borderRadius:"50%",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 24px"},children:e.jsx(l.RobotOutlined,{style:{fontSize:36,color:"#fff"}})}),e.jsx(ze,{level:4,style:{marginBottom:8},children:"还没有应用"}),e.jsx(xe,{type:"secondary",style:{display:"block",marginBottom:24},children:"点击「新建应用」开始创建您的第一个 Agent"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:L,style:{borderRadius:8},children:"新建应用"})]}),!T&&a.length>0&&U==="card"&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(400px, 1fr))",gap:16,marginBottom:16},children:a.map(H=>e.jsx(Is,{record:H,onEdit:R,onView:se,onPublish:le,onUpgrade:fe,onShare:W,onDelete:je,onToolConfig:X=>{C(X),G(!0)},onShareManage:X=>{V(X),K(!0)}},H.id))}),!T&&a.length>0&&U==="list"&&e.jsx(t.Table,{dataSource:a,rowKey:"id",size:"small",pagination:!1,columns:[{title:"名称",dataIndex:"appName",width:180,render:(H,X)=>e.jsx("a",{onClick:()=>R(X),style:{fontWeight:500},children:H||X.appCode})},{title:"版本",dataIndex:"version",width:60,render:H=>e.jsxs(t.Tag,{style:{fontSize:11},children:["v",H||1]})},{title:"编码",dataIndex:"appCode",width:180,render:H=>e.jsx("code",{style:{fontSize:12,color:"#8c8c8c"},children:H})},{title:"状态",dataIndex:"status",width:80,render:H=>e.jsx(t.Tag,{color:H==="PUBLISHED"?"green":"default",children:H==="PUBLISHED"?"已发布":"草稿"})},{title:"供应商",dataIndex:"modelProvider",width:100},{title:"模型",dataIndex:"modelName",width:140,ellipsis:!0},{title:"创建时间",dataIndex:"gmtCreate",width:170},{title:"操作",width:220,render:(H,X)=>e.jsxs(t.Space,{size:"small",children:[X.status==="PUBLISHED"?e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>se(X),children:"查看"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.DiffOutlined,{}),onClick:()=>fe(X),children:"升级"})]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.EditOutlined,{}),onClick:()=>R(X),children:"编辑"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.RocketOutlined,{}),onClick:()=>le(X.appCode),children:"发布"})]}),e.jsx(t.Popconfirm,{title:"确定删除?",onConfirm:()=>je(X.id),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),children:"删除"})})]})}]}),!T&&F>z&&e.jsxs("div",{style:{textAlign:"center",marginTop:16},children:[e.jsx(t.Button,{onClick:()=>m(H=>Math.max(1,H-1)),disabled:h===1,children:"上一页"}),e.jsxs("span",{style:{margin:"0 16px"},children:["第 ",e.jsx(xe,{strong:!0,children:h})," / ",Math.ceil(F/z)," 页"]}),e.jsx(t.Button,{onClick:()=>m(H=>H+1),disabled:h>=Math.ceil(F/z),children:"下一页"})]}),e.jsx(t.Modal,{title:"新建应用",open:p,onOk:$,onCancel:()=>y(!1),confirmLoading:u,width:520,okText:"创建",cancelText:"取消",children:e.jsxs(t.Form,{form:M,layout:"vertical",size:"middle",children:[e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(t.Form.Item,{name:"appName",label:"应用名称",rules:[{required:!0,message:"请输入应用名称"}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"如:智能客服助手"})}),e.jsx(t.Form.Item,{name:"groupCode",label:"分组",style:{width:160},children:e.jsx(t.TreeSelect,{allowClear:!0,placeholder:"默认",treeData:ws(E),treeDefaultExpandAll:!0,onChange:H=>M.setFieldsValue({groupCode:H||""}),style:{width:"100%"}})})]}),e.jsx(t.Form.Item,{name:"description",label:"应用描述",children:e.jsx(Ts,{rows:2,placeholder:"简短描述这个应用的能力和使用场景"})}),e.jsx(t.Divider,{style:{margin:"12px 0",fontSize:12,color:"#8c8c8c"},children:"应用类型"}),e.jsx(t.Form.Item,{name:"agentMode",label:"类型",rules:[{required:!0,message:"请选择应用类型"}],initialValue:"chat",children:e.jsxs(t.Select,{children:[e.jsx(we,{value:"chat",children:"对话 - 纯文本对话"}),e.jsx(we,{value:"agent",children:"智能体 - 工具调用 + 知识库"}),e.jsx(we,{value:"workflow",children:"工作流 - 多步骤流程编排"})]})}),e.jsx(t.Divider,{style:{margin:"12px 0",fontSize:12,color:"#8c8c8c"},children:"模型配置"}),e.jsx(t.Form.Item,{name:"modelProvider",label:"提供商",rules:[{required:!0}],initialValue:"ollama",children:e.jsxs(t.Select,{onChange:H=>{var ie;const X=pt[H]||[];_(X),M.setFieldsValue({modelName:((ie=X[0])==null?void 0:ie.code)||""})},children:[e.jsx(we,{value:"ollama",children:"Ollama (本地)"}),e.jsx(we,{value:"openai",children:"OpenAI"}),e.jsx(we,{value:"dashscope",children:"阿里通义"})]})}),e.jsx(t.Form.Item,{name:"modelName",label:"模型",rules:[{required:!0}],children:e.jsx(t.Select,{children:k.map(H=>e.jsx(we,{value:H.code,children:H.name},H.code))})})]})}),e.jsx(t.Drawer,{title:g?`${g.appName} - 工具配置`:"工具配置",width:560,open:D,onClose:()=>G(!1),children:g&&e.jsx(Es,{appCode:g.appCode})}),e.jsx(t.Drawer,{title:O?`${O.appName} · 分享`:"分享",width:520,open:P,onClose:()=>K(!1),destroyOnClose:!0,extra:O&&e.jsxs(t.Space,{children:[e.jsx(xe,{type:"secondary",style:{fontSize:12},children:"分享"}),e.jsx(t.Switch,{size:"small",checked:!!O.shareEnabled,onChange:H=>ee(O,H)})]}),children:O&&(O.shareEnabled?e.jsx(As,{app:O,onDisable:()=>ee(O,!1),onRefresh:()=>ee(O,!0)}):e.jsx(Os,{app:O,onEnable:()=>ee(O,!0)}))})]})},Es=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(null),[T,d]=s.useState([]),[b,f]=s.useState([]),[j,w]=s.useState([]),[h,m]=s.useState([]),[z,F]=s.useState([]),[N,u]=s.useState([]),[v,S]=s.useState(!1),[x,D]=s.useState(!1),[G,g]=s.useState("tools"),[C,P]=s.useState(!1);s.useEffect(()=>{P(!0),ae.appPage({id:1,pageSize:100}).then(k=>{i((k==null?void 0:k.records)||[])}).finally(()=>P(!1))},[]),s.useEffect(()=>{a&&(S(!0),Promise.all([Ae.toolTemplateList(),Ae.skillTemplateList(),Ae.knowledgeList()]).then(([k,_,p])=>{d((k==null?void 0:k.data)||k||[]),f((_==null?void 0:_.data)||_||[]),w((p==null?void 0:p.data)||p||[]),K(a.appCode)}).finally(()=>S(!1)))},[a]);const K=k=>{Ae.appConfig(k).then(_=>{const p=(_==null?void 0:_.data)||_||{};m(p.tools||[]),F(p.skills||[]),u(p.knowledgeBases||[])}).catch(()=>{})},O=(k,_)=>k.includes(_),V=(k,_)=>{k==="tool"?m(p=>p.includes(_)?p.filter(y=>y!==_):[...p,_]):k==="skill"?F(p=>p.includes(_)?p.filter(y=>y!==_):[...p,_]):u(p=>p.includes(_)?p.filter(y=>y!==_):[...p,_])},U=async()=>{if(a){D(!0);try{for(const k of h)await Ae.appToolAdd({appCode:a.appCode,toolCode:k}).catch(()=>{});for(const k of z)await Ae.appSkillAdd({appCode:a.appCode,skillId:Number(k)}).catch(()=>{});t.message.success("工具配置已保存")}catch{t.message.error("保存失败")}finally{D(!1)}}},A=(k,_,p,y,M,E)=>e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:16},children:[_,e.jsx("span",{style:{fontWeight:500},children:k}),e.jsx(t.Tag,{children:p.length})]}),p.length===0?e.jsx(t.Empty,{description:"暂无可用项",image:t.Empty.PRESENTED_IMAGE_SIMPLE}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:p.map(E)})]});return o.length===0?e.jsx("div",{style:{padding:48,textAlign:"center"},children:e.jsx(t.Empty,{description:"请先创建应用后再配置工具"})}):e.jsx("div",{style:{padding:24},children:e.jsxs(t.Row,{gutter:24,children:[e.jsxs(t.Col,{span:8,children:[e.jsx(ze,{level:5,style:{marginBottom:16},children:"选择应用"}),e.jsx("div",{style:{background:"#fafafa",borderRadius:8,padding:16,maxHeight:500,overflow:"auto"},children:o.map(k=>e.jsx("div",{onClick:()=>n(k),style:{padding:"12px 16px",marginBottom:8,borderRadius:8,cursor:"pointer",background:(a==null?void 0:a.id)===k.id?"#fff":"transparent",border:(a==null?void 0:a.id)===k.id?"2px solid #667eea":"2px solid transparent",transition:"all 0.2s"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(t.Avatar,{size:"small",icon:e.jsx(l.RobotOutlined,{}),style:{background:k.status==="PUBLISHED"?"linear-gradient(135deg, #52c41a, #389e0d)":"linear-gradient(135deg, #667eea, #764ba2)"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:14},children:k.appName}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:k.appCode})]})]})},k.id))})]}),e.jsx(t.Col,{span:16,children:a?e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:20},children:[e.jsxs(ze,{level:5,style:{margin:0},children:["配置 ",a.appName]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CheckCircleFilled,{}),onClick:U,loading:x,children:"保存配置"})]}),e.jsxs(t.Tabs,{activeKey:G,onChange:g,children:[e.jsx(dt,{tab:"工具",children:e.jsx("div",{style:{padding:16,background:"#fafafa",borderRadius:8},children:A("可用工具",e.jsx(ToolOutlined,{}),T,h,"tool",k=>e.jsxs("div",{onClick:()=>V("tool",k.toolCode),style:{padding:"10px 14px",background:O(h,k.toolCode)?"#e6f7ff":"#fff",border:`1px solid ${O(h,k.toolCode)?"#91d5ff":"#f0f0f0"}`,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:20,height:20,borderRadius:4,background:O(h,k.toolCode)?"#1890ff":"#d9d9d9",display:"flex",alignItems:"center",justifyContent:"center"},children:O(h,k.toolCode)&&e.jsx(l.CheckCircleFilled,{style:{color:"#fff",fontSize:12}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:k.toolName||k.toolCode}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:k.description||k.toolCode})]})]},k.toolCode))})},"tools"),e.jsx(dt,{tab:"技能",children:e.jsx("div",{style:{padding:16,background:"#fafafa",borderRadius:8},children:A("可用技能",e.jsx(l.StarOutlined,{}),b,z,"skill",k=>e.jsxs("div",{onClick:()=>V("skill",String(k.id)),style:{padding:"10px 14px",background:O(z,String(k.id))?"#fff7e6":"#fff",border:`1px solid ${O(z,String(k.id))?"#ffd591":"#f0f0f0"}`,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:20,height:20,borderRadius:4,background:O(z,String(k.id))?"#fa8c16":"#d9d9d9",display:"flex",alignItems:"center",justifyContent:"center"},children:O(z,String(k.id))&&e.jsx(l.CheckCircleFilled,{style:{color:"#fff",fontSize:12}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:k.name}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:k.description||k.code})]})]},k.id))})},"skills"),e.jsx(dt,{tab:"知识库",children:e.jsx("div",{style:{padding:16,background:"#fafafa",borderRadius:8},children:A("可用知识库",e.jsx(l.BookOutlined,{}),j,N,"kb",k=>e.jsxs("div",{onClick:()=>V("kb",String(k.id)),style:{padding:"10px 14px",background:O(N,String(k.id))?"#f6ffed":"#fff",border:`1px solid ${O(N,String(k.id))?"#b7eb8f":"#f0f0f0"}`,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:20,height:20,borderRadius:4,background:O(N,String(k.id))?"#52c41a":"#d9d9d9",display:"flex",alignItems:"center",justifyContent:"center"},children:O(N,String(k.id))&&e.jsx(l.CheckCircleFilled,{style:{color:"#fff",fontSize:12}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:k.name}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:k.description||`ID: ${k.id}`})]})]},k.id))})},"knowledge")]})]}):e.jsxs("div",{style:{padding:48,textAlign:"center",background:"#fafafa",borderRadius:12},children:[e.jsx(l.RobotOutlined,{style:{fontSize:48,color:"#d9d9d9"}}),e.jsx("div",{style:{marginTop:16,color:"#8c8c8c"},children:"请从左侧选择一个应用"})]})})]})})},{TextArea:zs}=t.Input,Rs=({children:o,className:i})=>{const a=String(o).replace(/\n$/,""),[n,T]=s.useState(!1),d=()=>{navigator.clipboard.writeText(a).then(()=>{T(!0),setTimeout(()=>T(!1),2e3)})};return e.jsxs("div",{style:{position:"relative",margin:"8px 0"},children:[e.jsx(t.Button,{size:"small",icon:n?e.jsx(l.CheckCircleFilled,{}):e.jsx(l.CopyOutlined,{}),onClick:d,style:{position:"absolute",right:8,top:8,opacity:.7},children:n?"已复制":"复制"}),e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",borderRadius:6,padding:"12px 16px",overflow:"auto",fontSize:13,lineHeight:1.5,fontFamily:'Consolas, Monaco, "Courier New", monospace'},children:e.jsx("code",{className:i,children:a})})]})},Bs=({msg:o})=>{const i=o.role==="user",a=o.status==="FAILED";return e.jsxs("div",{style:{display:"flex",justifyContent:i?"flex-end":"flex-start",marginBottom:16,animation:"fadeIn 0.3s ease"},children:[!i&&e.jsx(t.Avatar,{icon:e.jsx(l.RobotOutlined,{}),size:36,style:{marginRight:10,background:"#1890ff",flexShrink:0}}),e.jsxs("div",{style:{maxWidth:"72%",display:"flex",flexDirection:"column",alignItems:i?"flex-end":"flex-start"},children:[a&&e.jsx(t.Tag,{color:"red",icon:e.jsx(l.ExclamationCircleFilled,{}),style:{marginBottom:4},children:"出错了"}),i?e.jsx("div",{style:{padding:"10px 14px",borderRadius:"16px 16px 4px 16px",background:"linear-gradient(135deg, #1890ff, #096dd9)",color:"#fff",lineHeight:1.6,fontSize:15,boxShadow:"0 2px 8px rgba(24,144,255,0.3)"},children:o.content}):e.jsx("div",{style:{padding:"12px 16px",borderRadius:"16px 16px 16px 4px",background:"#fff",color:"#333",lineHeight:1.7,fontSize:15,boxShadow:"0 1px 4px rgba(0,0,0,0.1)",border:"1px solid #f0f0f0"},children:e.jsx(At,{remarkPlugins:[hs],components:{code({node:n,inline:T,className:d,children:b,...f}){return T?e.jsx("code",{style:{background:"#f5f5f5",padding:"2px 6px",borderRadius:4,fontFamily:"monospace",fontSize:"0.9em",color:"#c7254e"},...f,children:b}):e.jsx(Rs,{className:d,children:b})},p({children:n}){return e.jsx("p",{style:{margin:"0 0 8px 0"},children:n})},ul({children:n}){return e.jsx("ul",{style:{margin:"4px 0",paddingLeft:20},children:n})},ol({children:n}){return e.jsx("ol",{style:{margin:"4px 0",paddingLeft:20},children:n})},li({children:n}){return e.jsx("li",{style:{marginBottom:2},children:n})},strong({children:n}){return e.jsx("strong",{style:{color:"#1890ff"},children:n})},h1({children:n}){return e.jsx("h1",{style:{fontSize:18,margin:"8px 0"},children:n})},h2({children:n}){return e.jsx("h2",{style:{fontSize:16,margin:"8px 0"},children:n})},h3({children:n}){return e.jsx("h3",{style:{fontSize:14,margin:"6px 0"},children:n})},blockquote({children:n}){return e.jsx("blockquote",{style:{borderLeft:"3px solid #1890ff",margin:"8px 0",paddingLeft:12,color:"#666"},children:n})}},children:o.content})}),o.latencyMs&&!i&&!a&&e.jsxs("span",{style:{fontSize:11,color:"#bbb",marginTop:4},children:[e.jsx(l.ClockCircleOutlined,{style:{marginRight:3}}),o.latencyMs,"ms"]})]}),i&&e.jsx(t.Avatar,{icon:e.jsx(l.UserOutlined,{}),size:36,style:{marginLeft:10,background:"#52c41a",flexShrink:0}})]})},Fs=({appName:o,appDesc:i})=>e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"60vh",color:"#666"},children:[e.jsx("div",{style:{fontSize:48,marginBottom:16,background:"linear-gradient(135deg, #1890ff, #52c41a)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",fontWeight:"bold"},children:o||"Agent"}),i&&e.jsx("p",{style:{color:"#999",marginBottom:24},children:i}),e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap",justifyContent:"center",maxWidth:500},children:["有什么可以帮助你的?","告诉我你的问题","试试问我任何事情"].map((a,n)=>e.jsx(t.Tag,{style:{padding:"6px 12px",fontSize:13,cursor:"pointer",borderRadius:16},onClick:()=>{const T=new CustomEvent("insertTip",{detail:a});window.dispatchEvent(T)},children:a},n))})]}),Ns=()=>{const{shareCode:o}=Ve.useParams(),[i,a]=s.useState(!0),[n,T]=s.useState(""),[d,b]=s.useState(""),[f,j]=s.useState(""),[w,h]=s.useState([]),[m,z]=s.useState(""),[F,N]=s.useState(!1),[u,v]=s.useState(!1),[S,x]=s.useState(""),[D,G]=s.useState(!1),g=s.useRef(null),C=s.useRef(null);s.useRef(null),s.useEffect(()=>{P();const U=A=>z(k=>k||A.detail);return window.addEventListener("insertTip",U),()=>window.removeEventListener("insertTip",U)},[o]),s.useEffect(()=>{var U;(U=g.current)==null||U.scrollIntoView({behavior:"smooth"})},[w]);const P=async()=>{a(!0),x("");try{const U=await ae.shareVerify(o);if(U){T(U.instanceCode),b(U.appName||"Agent"),j(U.appDesc||""),v(!0);try{const A=await ae.chatHistory(U.instanceCode,50);if(A.data&&A.data.length>0){const k=[];A.data.forEach(_=>{k.push({id:`u_${_.id}`,role:"user",content:_.userMessage,time:_.gmtCreate,status:"SUCCESS"}),k.push({id:`a_${_.id}`,role:"assistant",content:_.assistantMessage,time:_.gmtCreate,status:_.status,latencyMs:_.latencyMs})}),h(k)}}catch(A){console.warn("加载历史失败",A)}}}catch{x("分享链接无效或已过期"),G(!0)}a(!1)},K=s.useCallback(async()=>{var y;const U=m.trim();if(!U||F)return;const k={id:`u_${Date.now()}`,role:"user",content:U,status:"SUCCESS"};h(M=>[...M,k]),z(""),N(!0);const _=`a_${Date.now()}`;let p="";h(M=>[...M,{id:_,role:"assistant",content:"",status:"LOADING"}]);try{const M=localStorage.getItem("token"),E=ae.chatStream(n,U,"visitor","游客",M);E.onmessage=Q=>{Q.data==="[DONE]"?(E.close(),h(c=>c.map(r=>r.id===_?{...r,content:p||"好的,我明白了。",status:"SUCCESS"}:r)),N(!1)):(p+=Q.data,h(c=>c.map(r=>r.id===_?{...r,content:p,status:"LOADING"}:r)))},E.onerror=Q=>{E.close(),h(c=>c.map(r=>r.id===_?{...r,content:"抱歉,AI 服务暂时不可用,请稍后重试。",status:"FAILED"}:r)),N(!1)}}catch{h(E=>E.map(Q=>Q.id===_?{...Q,content:"抱歉,AI 服务暂时不可用,请稍后重试。",status:"FAILED"}:Q)),N(!1)}(y=C.current)==null||y.focus()},[m,F,n]),O=()=>{t.Modal.confirm({title:"清空对话",content:"确定清空当前对话记录?此操作不可恢复。",okText:"清空",okButtonProps:{danger:!0},onOk:()=>{h([]),ae.chatClear(n).catch(()=>{})}})},V=U=>{U.key==="Enter"&&!U.shiftKey&&(U.preventDefault(),K())};return i?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",background:"#f0f2f5"},children:e.jsx(t.Spin,{indicator:e.jsx(l.LoadingOutlined,{style:{fontSize:32},spin:!0}),tip:"正在连接..."})}):D||S?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",background:"#f0f2f5"},children:e.jsxs(t.Card,{style:{textAlign:"center",maxWidth:400},children:[e.jsx(l.ExclamationCircleFilled,{style:{fontSize:48,color:"#ff4d4f",marginBottom:16}}),e.jsx("h3",{children:S||"无法访问此应用"}),e.jsx("p",{style:{color:"#999"},children:"可能的原因:链接已失效、应用已被删除或访问权限不足。"}),e.jsx(t.Button,{type:"primary",href:"/",icon:e.jsx(l.RobotOutlined,{}),children:"返回首页"})]})}):e.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",background:"linear-gradient(180deg, #f0f2f5 0%, #fff 100%)"},children:[e.jsxs("div",{style:{borderBottom:"1px solid #e8e8e8",background:"#fff",padding:"12px 24px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(t.Avatar,{shape:"square",size:36,icon:e.jsx(l.RobotOutlined,{}),style:{background:"#1890ff"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:16},children:d}),f&&e.jsx("div",{style:{fontSize:12,color:"#999"},children:f})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("span",{style:{fontSize:12,color:u?"#52c41a":"#ff4d4f"},children:[e.jsx(l.CheckCircleFilled,{style:{marginRight:4}}),u?"已连接":"未连接"]}),e.jsx(t.Tooltip,{title:"清空对话",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.ClearOutlined,{}),onClick:O,disabled:w.length===0,children:"清空"})})]})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px 24px"},children:[w.length===0?e.jsx(Fs,{appName:d,appDesc:f}):e.jsx(e.Fragment,{children:e.jsx(t.List,{dataSource:w,renderItem:U=>e.jsx(Bs,{msg:U}),locale:{emptyText:""}})}),e.jsx("div",{ref:g})]}),w.length===0&&e.jsx("div",{style:{padding:"0 24px 8px",display:"flex",gap:8,flexWrap:"wrap"},children:["你好","你能做什么?","介绍下自己"].map((U,A)=>e.jsx(t.Button,{size:"small",type:"default",onClick:()=>z(U),children:U},A))}),e.jsxs("div",{style:{borderTop:"1px solid #e8e8e8",background:"#fff",padding:"12px 24px 20px",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-end"},children:[e.jsx(zs,{ref:C,value:m,onChange:U=>z(U.target.value),onKeyDown:V,placeholder:"输入消息,Enter 发送,Shift+Enter 换行",autoSize:{minRows:1,maxRows:4},style:{flex:1,borderRadius:20},disabled:F||!u}),e.jsx(t.Button,{type:"primary",icon:F?e.jsx(l.LoadingOutlined,{}):e.jsx(l.SendOutlined,{}),onClick:K,loading:F,disabled:!m.trim()||!u,style:{borderRadius:20,width:56,height:36}})]}),e.jsx("div",{style:{fontSize:11,color:"#ccc",marginTop:6,textAlign:"center"},children:"AI 助手可能会产生不准确的信息,请仔细甄别"})]}),e.jsx("style",{children:`
22
+ <%s key={someKey} {...props} />`,R,le,fe,le),d[le+R]=!0)}if(le=null,$!==void 0&&(a($),le=""+$),m(_)&&(a(_.key),le=""+_.key),"key"in _){$={};for(var V in _)V!=="key"&&($[V]=_[V])}else $=_;return le&&b($,typeof n=="function"?n.displayName||n.name||"Unknown":n),y(n,le,$,j(),se,je)}function g(n){P(n)?n._store&&(n._store.validated=1):typeof n=="object"&&n!==null&&n.$$typeof===h&&(n._payload.status==="fulfilled"?P(n._payload.value)&&n._payload.value._store&&(n._payload.value._store.validated=1):n._store&&(n._store.validated=1))}function P(n){return typeof n=="object"&&n!==null&&n.$$typeof===D}var N=s,D=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),v=Symbol.for("react.fragment"),T=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),K=Symbol.for("react.context"),C=Symbol.for("react.forward_ref"),k=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),B=Symbol.for("react.activity"),F=Symbol.for("react.client.reference"),A=N.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,I=Object.prototype.hasOwnProperty,G=Array.isArray,u=console.createTask?console.createTask:function(){return null};N={react_stack_bottom_frame:function(n){return n()}};var w,U={},z=N.react_stack_bottom_frame.bind(N,c)(),Q=u(r(c)),d={};Le.Fragment=v,Le.jsx=function(n,_,$){var R=1e4>A.recentlyCreatedOwnerStacks++;return p(n,_,$,!1,R?Error("react-stack-top-frame"):z,R?u(r(n)):Q)},Le.jsxs=function(n,_,$){var R=1e4>A.recentlyCreatedOwnerStacks++;return p(n,_,$,!0,R?Error("react-stack-top-frame"):z,R?u(r(n)):Q)}})()),Le}var Nt;function js(){return Nt||(Nt=1,process.env.NODE_ENV==="production"?Ve.exports=fs():Ve.exports=ys()),Ve.exports}var e=js();const bs=We.createRequest({baseURL:"/api",timeout:15e3}),qe=We.createRequest({baseURL:"/api",timeout:15e3}),$e=We.createRequest({baseURL:"/api",timeout:15e3});function et(i){const o=function(r,j={}){const c={...j};return c.body!==void 0&&(c.data=c.body,delete c.body),typeof c.method=="string"&&(c.method=c.method.toUpperCase()),c.url=r,i.request(c)};return["get","post","put","delete","patch","head","request","create","interceptors"].forEach(r=>{typeof i[r]=="function"?o[r]=i[r].bind(i):o[r]=i[r]}),o}const te=et(bs);et(qe),et($e);const Bt={GET:"GET",POST:"POST",PUT:"PUT",DELETE:"DELETE"},Ke={};function L(i,o,a,r,j){Ke[i]||(Ke[i]={}),Ke[i][o]={verb:a,path:r,transform:j}}function Ss(i,o){let a=0;return i.replace(/\{(\w+)\}/g,()=>String(o[a++]??""))}function Cs(i,o){return o.startsWith("/ctc/ac")||o.startsWith("/ctc/authorization")||o.startsWith("/ctc/surl")?$e:o.startsWith("/auth/")?qe:te}function Ce(i){return new Proxy({},{get:(o,a)=>{if(!(a==="then"||typeof a=="symbol"))return a==="toJSON"||a==="constructor"||a==="toString"?()=>`[apiRouter:${i}]`:async(...r)=>{var c;const j=(c=Ke[i])==null?void 0:c[a];if(!j)return{code:200,message:"ok",data:[],total:0};try{const m=Ss(j.path,r),b=Cs(j.verb,m),S={};j.verb===Bt.GET||j.verb===Bt.DELETE?r.length>0&&typeof r[0]=="object"&&r[0]!==null&&(S.params=r[0]):r.length===1?S.data=r[0]:r.length>1&&(typeof r[0]=="object"&&r[0]!==null&&(S.data=r[0]),typeof r[1]=="object"&&r[1]!==null&&(S.params=r[1]));const y=await b.request({method:j.verb,url:m,...S});return j.transform?j.transform(y,r):y}catch(m){return console.warn(`[apiRouter] ${i}.${a} failed:`,(m==null?void 0:m.message)||m),{code:200,message:"ok",data:[],total:0}}}}})}L("llmApi","knowledgeList","GET","/llm-gateway/knowledge/list"),L("llmApi","skillTemplateList","GET","/llm-gateway/skill/template-list"),L("llmApi","toolTemplateList","GET","/llm-gateway/tool/template-list"),L("llmApi","appConfig","GET","/llm-gateway/app/config"),L("llmApi","appSkillAdd","POST","/llm-gateway/app/skill-add"),L("llmApi","appToolAdd","POST","/llm-gateway/app/tool-add"),L("mcpApi","list","GET","/mcp/server/list"),L("mcpApi","listTools","POST","/mcp/server/tools/list"),L("mcpApi","callTool","POST","/mcp/server/tools/call"),L("mcpApi","test","POST","/mcp/server/test"),L("mcpApi","create","POST","/mcp/server"),L("mcpApi","update","POST","/mcp/server/update"),L("mcpApi","delete","POST","/mcp/server/delete"),L("ossApi","listBuckets","GET","/v1/bucket"),L("ossApi","getBucketStats","GET","/v1/bucket/{bucketName}/stats"),L("ossApi","createBucket","POST","/v1/bucket"),L("ossApi","deleteBucket","DELETE","/v1/bucket/{bucketName}"),L("ossApi","setBucketAcl","PUT","/v1/bucket/{bucketName}/acl"),L("ossApi","listObjects","GET","/v1/object/{bucketName}"),L("ossApi","presignedUrl","GET","/v1/object/{bucketName}/{objectKey}/url"),L("ossApi","uploadObject","POST","/v1/object/{bucketName}/{objectKey}"),L("ossApi","downloadUrl","GET","/v1/object/{bucketName}/{objectKey}/url"),L("ossApi","deleteObject","DELETE","/v1/object/{bucketName}/{objectKey}"),L("ossApi","copyObject","POST","/v1/object/{bucketName}/{objectKey}/copy"),L("ossApi","batchDelete","POST","/v1/object/{bucketName}/batch-delete"),L("ossApi","createFolder","POST","/v1/folder/{bucketName}/{folderKey}"),L("scriptApi","list","GET","/script/list"),L("scriptApi","create","POST","/script"),L("scriptApi","update","POST","/script/update"),L("scriptApi","delete","POST","/script/delete"),L("scriptApi","publish","POST","/script/publish"),L("scriptApi","unpublish","POST","/script/unpublish"),L("scriptApi","run","POST","/script/run"),L("scriptApi","importCurl","POST","/script/import-curl"),L("scriptApi","importOpenApi","POST","/script/import-openapi"),L("scriptApi","previewMapping","POST","/script/preview-mapping"),L("skillApi","page","GET","/skill/page"),L("skillApi","categoryTree","GET","/skill/category-tree"),L("skillApi","create","POST","/skill"),L("skillApi","createCategory","POST","/skill/category"),L("skillApi","deleteCategory","POST","/skill/category/delete"),L("skillApi","getBySkillCode","GET","/skill/by-code"),L("skillApi","install","POST","/skill/install"),L("skillApi","stats","GET","/skill/stats"),L("skillApi","versions","GET","/skill/versions"),L("skillApi","downloadPackage","GET","/skill/download"),L("skillApi","uploadPackage","POST","/skill/upload"),L("agentApi","appPage","POST","/agent/app/page"),L("agentApi","appGet","GET","/agent/app/get"),L("agentApi","appCreate","POST","/agent/app"),L("agentApi","appUpdate","POST","/agent/app/update"),L("agentApi","appDelete","POST","/agent/app/delete"),L("agentApi","appPublish","POST","/agent/app/publish"),L("agentApi","appUpgrade","POST","/agent/app/upgrade"),L("agentApi","appToggleShare","POST","/agent/app/toggleShare"),L("agentApi","versions","GET","/agent/app/versions"),L("agentApi","groupTree","GET","/agent/group/tree"),L("agentApi","groupCreate","POST","/agent/group"),L("agentApi","groupUpdate","POST","/agent/group/update"),L("agentApi","groupDelete","POST","/agent/group/delete"),L("agentApi","chatHistory","GET","/agent/chat/history"),L("agentApi","chatStream","POST","/agent/chat/send"),L("agentApi","chatClear","POST","/agent/chat/clear"),L("agentApi","shareVerify","GET","/agent/share/verify"),L("flowApi","list","GET","/agent/flow/list"),L("flowApi","get","GET","/agent/flow/{id}"),L("flowApi","byFlowId","GET","/agent/flow/byFlowId"),L("flowApi","versions","GET","/agent/flow/versions"),L("flowApi","create","POST","/agent/flow/create"),L("flowApi","update","POST","/agent/flow/update"),L("flowApi","publish","POST","/agent/flow/publish/{id}"),L("flowApi","archive","POST","/agent/flow/archive/{id}"),L("flowApi","newVersion","POST","/agent/flow/newVersion/{parentId}"),L("flowApi","delete","POST","/agent/flow/delete/{id}"),L("flowApi","execute","POST","/agent/flow/execute/{id}"),L("flowApi","health","GET","/agent/flow/health"),L("productApi","page","GET","/v1/products"),L("productApi","create","POST","/v1/products"),L("productApi","update","PUT","/v1/products/{id}"),L("productApi","delete","DELETE","/v1/products/{id}"),L("productApi","publish","POST","/v1/products/{id}/publish"),L("productApi","offline","POST","/v1/products/{id}/offline"),L("productApi","configGet","GET","/v1/products/{id}/config"),L("productApi","configSave","PUT","/v1/products/{id}/config"),L("sceneApi","page","GET","/v1/scenes"),L("sceneApi","create","POST","/v1/scenes"),L("sceneApi","update","PUT","/v1/scenes/{id}"),L("sceneApi","delete","DELETE","/v1/scenes/{id}"),L("sceneApi","duplicate","POST","/v1/scenes/{id}/duplicate"),L("sceneApi","publish","POST","/v1/scenes/{id}/publish"),L("sceneApi","offline","POST","/v1/scenes/{id}/offline"),L("sceneApi","execute","POST","/v1/scenes/{id}/execute"),L("sceneApi","canvasGet","GET","/v1/scenes/{id}/canvas"),L("sceneApi","configGet","GET","/v1/scenes/{id}/config"),L("sceneApi","nodes","GET","/v1/scenes/{id}/nodes"),L("sceneApi","chatHistory","GET","/v1/scenes/{id}/chat-history");const ae=Ce("agentApi"),De=Ce("flowApi"),Ae=Ce("llmApi"),Ie=Ce("mcpApi"),be=Ce("scriptApi"),ge=Ce("skillApi"),Se=Ce("productApi"),ue=Ce("sceneApi"),me=Ce("ossApi"),tt=Ce("traceApi"),St=class St extends ne.CircleNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#52c41a",o.stroke="#52c41a",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#fff",o.fontSize=14,o}};St.extendKey="start";let st=St;const Ct=class Ct extends ne.RectNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#e6f4ff",o.stroke="#1677ff",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#1677ff",o.fontSize=13,o}};Ct.extendKey="llm";let lt=Ct;const vt=class vt extends ne.RectNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#f0f5ff",o.stroke="#2f54eb",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#2f54eb",o.fontSize=13,o}};vt.extendKey="agent";let ot=vt;const Tt=class Tt extends ne.PolygonNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#fff7e6",o.stroke="#fa8c16",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#d46b08",o.fontSize=12,o}getAttributes(){const o=super.getAttributes(),a=120,r=80,j=[[o.x,o.y-r/2],[o.x+a/2,o.y],[o.x,o.y+r/2],[o.x-a/2,o.y]];return{...o,points:j,width:a,height:r}}};Tt.extendKey="condition";let it=Tt;const wt=class wt extends ne.RectNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#fff7e6",o.stroke="#fa8c16",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#d46b08",o.fontSize=13,o}};wt.extendKey="http";let rt=wt;const kt=class kt extends ne.RectNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#f6ffed",o.stroke="#13c2c2",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#08979c",o.fontSize=13,o}};kt.extendKey="template";let nt=kt;const It=class It extends ne.RectNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#f9f0ff",o.stroke="#722ed1",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#722ed1",o.fontSize=13,o}getShape(){const{x:o,y:a,width:r,height:j}=this.getAttributes(),c=r/2,m=j/2,b=12;return ne.h("polygon",{points:[[o-c+b,a-m],[o+c-b,a-m],[o+c,a],[o+c-b,a+m],[o-c+b,a+m],[o-c,a]]})}};It.extendKey="parallel";let at=It;const Ot=class Ot extends ne.CircleNode{getNodeStyle(){const o=super.getNodeStyle();return o.fill="#ff4d4f",o.stroke="#ff4d4f",o.strokeWidth=2,o}getTextStyle(){const o=super.getTextStyle();return o.color="#fff",o.fontSize=14,o}};Ot.extendKey="end";let ct=Ot;function vs(i){i.register({type:"start",view:st,model:ne.CircleNodeModel}),i.register({type:"llm",view:lt,model:ne.RectNodeModel}),i.register({type:"agent",view:ot,model:ne.RectNodeModel}),i.register({type:"condition",view:it,model:ne.PolygonNodeModel}),i.register({type:"http",view:rt,model:ne.RectNodeModel}),i.register({type:"template",view:nt,model:ne.RectNodeModel}),i.register({type:"parallel",view:at,model:ne.RectNodeModel}),i.register({type:"end",view:ct,model:ne.CircleNodeModel})}const dt=[{type:"start",label:"开始",icon:"https://cdn.jsdelivr.net/gh/LogicFlow/static@latest/docs/static/start.png"},{type:"llm",label:"LLM 调用",icon:"🤖"},{type:"agent",label:"Agent 节点",icon:"🤖"},{type:"condition",label:"条件分支",icon:"https://cdn.jsdelivr.net/gh/LogicFlow/static@latest/docs/static/condition.png"},{type:"http",label:"HTTP 请求",icon:"🔗"},{type:"template",label:"模板转换",icon:"📝"},{type:"parallel",label:"并行执行",icon:"⚡"},{type:"end",label:"结束",icon:"https://cdn.jsdelivr.net/gh/LogicFlow/static@latest/docs/static/end.png"}];ne.use(Ne.Control),ne.use(Ne.MiniMap),ne.use(Ne.Menu),ne.use(Ne.DndPanel),ne.use(Ne.SelectionSelect);const Ft={nodes:[{id:"start_1",type:"start",x:150,y:280,text:"开始"},{id:"llm_1",type:"llm",x:380,y:280,text:"LLM 调用"},{id:"end_1",type:"end",x:610,y:280,text:"结束"}],edges:[{id:"e1",type:"polyline",sourceNodeId:"start_1",targetNodeId:"llm_1",text:""},{id:"e2",type:"polyline",sourceNodeId:"llm_1",targetNodeId:"end_1",text:""}]},Ts=({node:i,onChange:o,onClose:a})=>{var j,c,m,b,S;if(!i)return null;const r=((j=dt.find(y=>y.type===i.type))==null?void 0:j.label)||i.type;return e.jsxs("div",{style:{position:"absolute",right:16,top:16,width:260,background:"#fff",borderRadius:8,boxShadow:"0 2px 12px rgba(0,0,0,0.12)",padding:16,zIndex:10},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsx("div",{children:e.jsx(t.Tag,{color:"blue",children:r})}),e.jsx(t.Button,{type:"text",size:"small",onClick:a,children:"✕"})]}),e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"节点 ID"}),e.jsx("div",{style:{fontSize:13,color:"#333"},children:i.id})]}),e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"显示文本"}),e.jsx("input",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:i.text,onBlur:y=>o(i.id,{text:y.target.value}),placeholder:"输入显示文本"})]}),i.type==="llm"&&e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"模型"}),e.jsxs("select",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:((c=i.properties)==null?void 0:c.model)||"qwen2.5:7b",onChange:y=>o(i.id,{properties:{...i.properties,model:y.target.value}}),children:[e.jsx("option",{value:"qwen2.5:7b",children:"Qwen 2.5 7B"}),e.jsx("option",{value:"qwen2.5:72b",children:"Qwen 2.5 72B"}),e.jsx("option",{value:"gpt-4o",children:"GPT-4o"})]})]}),i.type==="http"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"HTTP Method"}),e.jsxs("select",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:((m=i.properties)==null?void 0:m.method)||"GET",onChange:y=>o(i.id,{properties:{...i.properties,method:y.target.value}}),children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"}),e.jsx("option",{value:"PUT",children:"PUT"}),e.jsx("option",{value:"DELETE",children:"DELETE"})]})]}),e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"URL"}),e.jsx("input",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:13},defaultValue:((b=i.properties)==null?void 0:b.url)||"",onBlur:y=>o(i.id,{properties:{...i.properties,url:y.target.value}}),placeholder:"https://api.example.com/..."})]})]}),i.type==="condition"&&e.jsxs("div",{style:{marginBottom:8},children:[e.jsx("div",{style:{fontSize:12,color:"#666",marginBottom:4},children:"条件表达式"}),e.jsx("textarea",{style:{width:"100%",border:"1px solid #d9d9d9",borderRadius:4,padding:"4px 8px",fontSize:12,resize:"vertical"},rows:3,defaultValue:((S=i.properties)==null?void 0:S.expression)||"",onBlur:y=>o(i.id,{properties:{...i.properties,expression:y.target.value}}),placeholder:"e.g. status == 'success'"})]})]})},Lt=({readOnly:i=!1,value:o,onChange:a,appCode:r,flowName:j})=>{const c=s.useRef(null),m=s.useRef(null),[b,S]=s.useState(null),[y,p]=s.useState(o||Ft),[g,P]=s.useState(null),[N,D]=s.useState(!1),[x,v]=s.useState(!1);s.useEffect(()=>{if(!c.current)return;const h=new ne({container:c.current,grid:{size:20,visible:!0,type:"dot",config:{color:"#e5e5e5"}},keyboard:{enabled:!0},snapline:!0,outline:!0,textEdit:!i,isSilentMode:i,style:{rect:{rx:6,ry:6},polyline:{stroke:"#bfbfbf",strokeWidth:2}},edgeType:"polyline"});vs(h),h.extension.dndPanel.setPatternItems(dt.map(F=>({type:F.type,label:F.label,icon:F.icon}))),h.extension.miniMap&&h.extension.miniMap.show({width:160,height:100,showEdge:!0,isShowHeader:!1});const B=o||Ft;return h.render(B),p(B),h.on("node:click",({data:F})=>{i||S(F)}),h.on("blank:click",()=>{S(null)}),h.on("graph:change",()=>{const F=h.getGraphData();p(F),a==null||a(F)}),m.current=h,()=>{h.destroy()}},[]);const T=s.useCallback((h,B)=>{if(!m.current)return;m.current.updateText(h,B.text||""),B.properties&&m.current.updateProperties(h,B.properties);const F=m.current.getGraphData().nodes.find(A=>A.id===h);F&&S(F)},[]);s.useCallback(h=>{var I;if(!m.current||i)return;const B=m.current.getGraphData(),F=B.nodes.reduce((G,u)=>G+u.x,0)/(B.nodes.length||1),A=B.nodes.reduce((G,u)=>G+u.y,0)/(B.nodes.length||1);m.current.addNode({type:h,x:F+80,y:A,text:((I=dt.find(G=>G.type===h))==null?void 0:I.label)||h})},[i]);const f=s.useCallback(()=>{var B,F;if(!m.current||i)return;const h=m.current.getSelectedModels();(B=h.nodes)!=null&&B.length&&h.nodes.forEach(A=>m.current.deleteNode(A.id)),(F=h.edges)!=null&&F.length&&h.edges.forEach(A=>m.current.deleteEdge(A.id)),S(null)},[i]),M=s.useCallback(()=>{!m.current||i||m.current.undo()},[i]),K=s.useCallback(()=>{!m.current||i||m.current.redo()},[i]),C=s.useCallback(()=>{if(!m.current)return;const h=m.current.getGraphData();p(h),a==null||a(h),t.message.success("流程已保存到前端")},[a]),k=s.useCallback(async()=>{if(!m.current||!r){t.message.warning("缺少 appCode, 无法保存到后端");return}D(!0);try{const h=m.current.getGraphData(),B={flowId:r,name:j||r,description:`App ${r} 的工作流`,nodes:JSON.stringify(h.nodes||[]),edges:JSON.stringify(h.edges||[]),variables:JSON.stringify(h.variables||{}),flowType:"AGENT",appCode:r,status:"DRAFT",version:1,creator:localStorage.getItem("userInfo")&&JSON.parse(localStorage.getItem("userInfo")||"{}").userCode||"anonymous"};let F;if(g)F=await De.update({...B,id:g});else{F=await De.create(B);const A=(F==null?void 0:F.data)??F;A&&typeof A=="number"?P(A):A&&A.id&&P(A.id)}t.message.success("流程已保存到后端 z_agent_flow_definition"),a==null||a(h)}catch(h){t.message.error("保存到后端失败: "+((h==null?void 0:h.message)||"未知错误"))}finally{D(!1)}},[r,j,g,a]),E=s.useCallback(async()=>{if(!g){t.message.warning('请先点击"保存到后端"');return}try{await De.publish(g),v(!1),t.message.success("流程已发布, 现在可以被 Agent Runtime 执行")}catch(h){t.message.error("发布失败: "+((h==null?void 0:h.message)||"未知错误"))}},[g]);s.useEffect(()=>{!r||i||(async()=>{try{const h=await De.byFlowId({flowId:r,version:1}),B=(h==null?void 0:h.data)??h;B&&B.id&&B.nodes&&(P(B.id),m.current&&m.current.render({nodes:JSON.parse(B.nodes),edges:JSON.parse(B.edges)}),t.message.info("已加载上次保存的工作流 v"+(B.version||1)))}catch{}})()},[r]);const W=s.useCallback(()=>{S(null)},[]);return e.jsxs("div",{style:{position:"relative",height:520,borderRadius:8,overflow:"hidden",background:"#fafafa",border:"1px solid #e8e8e8"},children:[!i&&e.jsxs("div",{style:{position:"absolute",top:8,left:8,zIndex:5,display:"flex",gap:6,alignItems:"center",background:"#fff",borderRadius:6,padding:"4px 8px",boxShadow:"0 1px 6px rgba(0,0,0,0.08)"},children:[e.jsxs(t.Space,{size:4,children:[e.jsx(t.Tooltip,{title:"撤销",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.UndoOutlined,{}),onClick:M})}),e.jsx(t.Tooltip,{title:"重做",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.RedoOutlined,{}),onClick:K})}),e.jsx("div",{style:{width:1,height:16,background:"#e8e8e8",margin:"0 2px"}}),e.jsx(t.Tooltip,{title:"删除选中",children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:f})}),e.jsx(t.Tooltip,{title:"保存到前端 (AgentApp)",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.SaveOutlined,{}),onClick:C})}),e.jsx("div",{style:{width:1,height:16,background:"#e8e8e8",margin:"0 2px"}}),e.jsx(t.Tooltip,{title:"保存到后端 z_agent_flow_definition (FEATURE013 A5)",children:e.jsx(t.Button,{size:"small",type:"primary",ghost:!0,icon:e.jsx(l.CloudUploadOutlined,{}),loading:N,disabled:!r,onClick:k,children:"保存流程"})}),e.jsx(t.Tooltip,{title:"发布 (DRAFT → PUBLISHED, FlowEngine 可加载执行)",children:e.jsx(t.Button,{size:"small",type:"primary",disabled:!g,onClick:()=>v(!0),children:"发布"})})]}),g&&e.jsxs(t.Tag,{color:"blue",style:{marginLeft:8},children:["flowId=",g]}),e.jsx("div",{style:{fontSize:12,color:"#999",marginLeft:8},children:"从左侧拖入节点到画布,双击节点编辑文本"})]}),e.jsxs(t.Modal,{title:"发布工作流",open:x,onOk:E,onCancel:()=>v(!1),okText:"确认发布",cancelText:"取消",children:[e.jsxs("p",{children:["发布后, ",e.jsx("b",{children:"FlowOrchestrationService"})," 会在下次请求时加载这个 flow, Agent Runtime 可以通过 ",e.jsxs("code",{children:["/api/agent/flow/execute/",g]})," 触发执行。"]}),e.jsx("p",{style:{color:"#999",fontSize:12},children:"提示: 如需修改, 需点击「升级到新版本」创建草稿。"})]}),e.jsx("div",{ref:c,style:{width:"100%",height:"100%"}}),b&&!i&&e.jsx(Ts,{node:b,onChange:T,onClose:W}),i&&e.jsx("div",{style:{position:"absolute",top:8,right:8,zIndex:5,background:"rgba(0,0,0,0.5)",color:"#fff",borderRadius:4,padding:"2px 8px",fontSize:12},children:"只读模式"})]})},{TextArea:Ee}=t.Input,{Text:Te,Title:ws}=t.Typography,Dt={ollama:[{code:"qwen2.5:7b-instruct-q4_K_M",name:"Qwen 2.5 7B"},{code:"qwen3:8b",name:"Qwen3 8B"},{code:"llama3:latest",name:"Llama 3"},{code:"qwen2.5:14b-instruct-q4_K_M",name:"Qwen 2.5 14B"}],openai:[{code:"gpt-4o",name:"GPT-4o"},{code:"gpt-4o-mini",name:"GPT-4o Mini"},{code:"gpt-4-turbo",name:"GPT-4 Turbo"}],dashscope:[{code:"qwen-max",name:"Qwen Max"},{code:"qwen-plus",name:"Qwen Plus"},{code:"qwen-turbo",name:"Qwen Turbo"}]},Mt={chat:{label:"对话",icon:e.jsx(l.MessageOutlined,{}),color:"#1677ff",desc:"纯文本对话,配置 Prompt + 模型即可",tabs:["basic","prompt","modelParams","memory"],tabLabels:{basic:"基本信息",prompt:"系统提示词",modelParams:"模型参数",memory:"记忆配置"}},agent:{label:"智能体",icon:e.jsx(l.RobotOutlined,{}),color:"#722ed1",desc:"工具调用 + 技能 + 知识库,具备自主决策能力",tabs:["basic","prompt","modelParams","memory","tools","skills","variables","knowledge"],tabLabels:{basic:"基本信息",prompt:"系统提示词",modelParams:"模型参数",memory:"记忆配置",tools:"工具配置",skills:"技能配置",variables:"变量配置",knowledge:"知识库"}},workflow:{label:"工作流",icon:e.jsx(l.ApartmentOutlined,{}),color:"#13c2c2",desc:"可视化多步骤流程编排",tabs:["basic","modelParams","workflow"],tabLabels:{basic:"基本信息",modelParams:"模型参数",workflow:"流程编排"}}},_t=({app:i,onBack:o,onSaved:a})=>{const[r,j]=s.useState(i),c=r.status==="PUBLISHED",m=r.agentMode||"chat",b=Mt[m]||Mt.chat,[S,y]=s.useState(!1),[p,g]=s.useState(!1),[P,N]=s.useState(b.tabs[0]),[D]=t.Form.useForm(),[x,v]=s.useState(null);s.useEffect(()=>{P&&!b.tabs.includes(P)&&N(b.tabs[0])},[m]);const T=C=>{j(k=>({...k,agentMode:C})),D.setFieldsValue({agentMode:C})},f=async()=>{try{const C=await D.validateFields();y(!0),await ae.appUpdate({id:r.id,agentMode:m,...C,workflowData:x}),t.message.success("保存成功"),a==null||a()}catch(C){C.errorFields||t.message.error("保存失败")}finally{y(!1)}},M=async()=>{try{await ae.appPublish(r.appCode),t.message.success("发布成功"),a==null||a()}catch{t.message.error("发布失败")}},K=async()=>{try{g(!0);const C=await ae.appUpgrade(r.appCode),k=(C==null?void 0:C.data)||C;k&&(j(k),t.message.success(`已升级到 ${k.version||"新"} 版本,可编辑后发布`))}catch(C){t.message.error("升级失败:"+((C==null?void 0:C.message)||"未知错误"))}finally{g(!1)}};return e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",borderBottom:"1px solid #f0f0f0",background:"#fff",flexShrink:0},children:[e.jsx(t.Button,{type:"text",icon:e.jsx(l.ArrowLeftOutlined,{}),onClick:o}),e.jsxs(ws,{level:5,style:{margin:0,flex:1,minWidth:0},children:[e.jsx("span",{style:{marginRight:8},children:r.appName}),e.jsxs(t.Tag,{color:b.color,style:{borderRadius:20,marginRight:4},children:[b.icon," ",b.label]}),e.jsx(t.Tag,{color:c?"green":"default",style:{borderRadius:20},children:c?"已发布":"草稿"})]}),e.jsx("div",{style:{flex:1}}),c?e.jsx(t.Button,{icon:e.jsx(l.DiffOutlined,{}),loading:p,onClick:K,children:"升级到新草稿"}):e.jsxs(t.Space,{children:[e.jsx(t.Button,{icon:e.jsx(l.SaveOutlined,{}),type:"primary",ghost:!0,onClick:f,loading:S,children:"保存"}),e.jsx(t.Button,{icon:e.jsx(l.RocketOutlined,{}),type:"primary",onClick:M,children:"发布"})]})]}),e.jsxs("div",{style:{flex:1,overflow:"auto",padding:16,background:"#f5f5f5"},children:[c&&e.jsx(t.Alert,{type:"warning",showIcon:!0,icon:e.jsx(l.EyeOutlined,{}),message:"查看模式:当前为已发布版本,所有字段仅可浏览不可修改",description:"如需调整配置,请点击右上角「升级到新草稿」按钮,系统会基于当前版本创建一份可编辑的草稿。",style:{marginBottom:16,borderRadius:8}}),e.jsx(t.Card,{size:"small",style:{marginBottom:16,borderLeft:`3px solid ${b.color}`},bodyStyle:{padding:"12px 16px"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,flexWrap:"wrap"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:120},children:[e.jsx("span",{style:{fontSize:18,color:b.color},children:b.icon}),e.jsxs("div",{children:[e.jsx(Te,{strong:!0,style:{fontSize:13},children:"应用类型"}),e.jsx("div",{children:e.jsxs(Te,{type:"secondary",style:{fontSize:12},children:[b.label,"模式"]})})]})]}),e.jsx(t.Select,{value:m,disabled:c,onChange:T,style:{flex:1,maxWidth:400},options:[{value:"chat",label:e.jsxs("span",{children:[e.jsx(l.MessageOutlined,{style:{color:"#1677ff"}})," 对话 - 纯文本对话"]})},{value:"agent",label:e.jsxs("span",{children:[e.jsx(l.RobotOutlined,{style:{color:"#722ed1"}})," 智能体 - 工具调用 + 知识库"]})},{value:"workflow",label:e.jsxs("span",{children:[e.jsx(l.ApartmentOutlined,{style:{color:"#13c2c2"}})," 工作流 - 多步骤流程编排"]})}]}),e.jsx(Te,{type:"secondary",style:{fontSize:12},children:b.desc})]})}),e.jsx(t.Card,{size:"small",children:e.jsx(t.Tabs,{activeKey:P,onChange:N,style:{minHeight:300},children:b.tabs.map(C=>{var k;return e.jsx(t.Tabs.TabPane,{tab:b.tabLabels[C]||C,children:e.jsxs(t.Form,{form:D,layout:"vertical",initialValues:{appName:r.appName,description:r.description,prompt:r.prompt,modelProvider:r.modelProvider||"ollama",modelName:r.modelName||"qwen2.5:7b-instruct-q4_K_M",iconUrl:r.iconUrl,tools:r.tools,skillCodes:r.skillCodes,variables:r.variables,knowledgeIds:r.knowledgeIds,temperature:r.temperature??.7,topP:r.topP??.9,maxTokens:r.maxTokens??4096,historyWindowSize:r.historyWindowSize??50,enableLongMemory:r.enableLongMemory??!1,memoryPrompt:r.memoryPrompt||""},children:[C==="basic"&&e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:16,children:e.jsx(t.Form.Item,{name:"appName",label:"应用名称",rules:[{required:!0}],children:e.jsx(t.Input,{disabled:c})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"iconUrl",label:"图标 URL",children:e.jsx(t.Input,{disabled:c,placeholder:"图片URL"})})}),e.jsx(t.Col,{span:24,children:e.jsx(t.Form.Item,{name:"description",label:"应用描述",children:e.jsx(Ee,{rows:2,disabled:c})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"modelProvider",label:"供应商",rules:[{required:!0}],children:e.jsxs(t.Select,{disabled:c,onChange:E=>{const W=Dt[E]||[];W[0]&&D.setFieldsValue({modelName:W[0].code})},children:[e.jsx(t.Select.Option,{value:"ollama",children:"Ollama"}),e.jsx(t.Select.Option,{value:"openai",children:"OpenAI"}),e.jsx(t.Select.Option,{value:"dashscope",children:"阿里通义"})]})})}),e.jsx(t.Col,{span:16,children:e.jsx(t.Form.Item,{name:"modelName",label:"模型",rules:[{required:!0}],children:e.jsx(t.Select,{disabled:c,children:(Dt[((k=D.getFieldValue)==null?void 0:k.call(D,"modelProvider"))||r.modelProvider||"ollama"]||[]).map(E=>e.jsx(t.Select.Option,{value:E.code,children:E.name},E.code))})})})]}),C==="prompt"&&e.jsx(t.Form.Item,{name:"prompt",label:"系统提示词",extra:"定义 Agent 的身份、能力、行为规范和约束条件",children:e.jsx(Ee,{rows:12,disabled:c,placeholder:"你是智能助手,负责回答用户问题..."})}),C==="modelParams"&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"模型参数控制生成行为。不同模型支持的参数范围略有差异。",style:{marginBottom:16,border:"none",background:"#e6f4ff"}}),e.jsxs(t.Card,{size:"small",style:{background:"#fafafa",marginBottom:16},children:[e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(Te,{strong:!0,children:[e.jsx(l.ThunderboltOutlined,{})," 采样参数"]}),e.jsx(Te,{type:"secondary",style:{marginLeft:8,fontSize:12},children:"控制生成多样性和确定性"})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"temperature",label:"Temperature 温度",extra:"0=确定性,2=高随机",children:e.jsx(t.InputNumber,{min:0,max:2,step:.1,disabled:c,style:{width:"100%"}})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"topP",label:"Top P 核采样",extra:"0-1,建议 0.9",children:e.jsx(t.InputNumber,{min:0,max:1,step:.05,disabled:c,style:{width:"100%"}})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"maxTokens",label:"Max Tokens 最大输出",extra:"单次响应最大 token 数",children:e.jsx(t.InputNumber,{min:100,max:128e3,step:100,disabled:c,style:{width:"100%"}})})})]})]})]}),C==="memory"&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"记忆配置控制对话上下文管理",style:{marginBottom:16,border:"none",background:"#e6f4ff"}}),e.jsxs(t.Card,{size:"small",style:{background:"#fafafa",marginBottom:16},children:[e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(Te,{strong:!0,children:[e.jsx(l.DatabaseOutlined,{})," 历史窗口"]}),e.jsx(Te,{type:"secondary",style:{marginLeft:8,fontSize:12},children:"保留最近 N 条对话消息作为上下文"})]}),e.jsx(t.Form.Item,{name:"historyWindowSize",label:"历史窗口大小",children:e.jsx(t.InputNumber,{min:0,max:100,disabled:c,style:{width:200}})})]}),e.jsxs(t.Card,{size:"small",style:{background:"#fafafa",marginBottom:16},children:[e.jsxs("div",{style:{marginBottom:12},children:[e.jsxs(Te,{strong:!0,children:[e.jsx(l.BookOutlined,{})," 长期记忆"]}),e.jsx(Te,{type:"secondary",style:{marginLeft:8,fontSize:12},children:"跨会话持久化关键信息"})]}),e.jsx(t.Form.Item,{name:"enableLongMemory",label:"启用长期记忆",valuePropName:"checked",children:e.jsx(t.Switch,{disabled:c})}),e.jsx(t.Form.Item,{name:"memoryPrompt",label:"记忆提示词",extra:"定义如何总结和存储对话内容",children:e.jsx(Ee,{rows:3,disabled:c,placeholder:"例:提取用户的偏好和关键事实,以 JSON 结构存储..."})})]})]}),C==="tools"&&e.jsx(t.Form.Item,{name:"tools",label:"工具配置",extra:"JSON 数组格式",children:e.jsx(Ee,{rows:8,disabled:c,placeholder:'[{"toolCode":"web-search","toolName":"网页搜索"}]'})}),C==="skills"&&e.jsx(t.Form.Item,{name:"skillCodes",label:"技能编码",extra:"JSON 数组格式",children:e.jsx(Ee,{rows:8,disabled:c,placeholder:'["code-review", "data-analyzer"]'})}),C==="variables"&&e.jsx(t.Form.Item,{name:"variables",label:"变量配置",extra:"JSON 数组格式",children:e.jsx(Ee,{rows:8,disabled:c,placeholder:'[{"name":"userName","label":"用户名","type":"string"}]'})}),C==="knowledge"&&e.jsx(t.Form.Item,{name:"knowledgeIds",label:"知识库",extra:"JSON 数组格式",children:e.jsx(Ee,{rows:8,disabled:c,placeholder:"[1, 2, 3]"})}),C==="workflow"&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",showIcon:!0,message:"工作流模式使用轻量引擎,支持中断恢复。节点定义存储在应用配置中。",style:{marginBottom:16,border:"none",background:"#e6f4ff"}}),e.jsx(We.ErrorBoundary,{fallbackTitle:"流程编辑器加载失败",fallbackDescription:"LogicFlow 初始化异常。请重试,或切换到「对话」/「智能体」模式后重新切回工作流。",onReset:()=>v(null),children:e.jsx(Lt,{readOnly:c,value:x,onChange:v,appCode:r.appCode,flowName:r.appName})})]})]})},C)})})})]})]})},{TextArea:ks}=t.Input,{Option:we}=t.Select,{TabPane:pt}=t.Tabs,{Text:xe,Title:ze}=t.Typography,Ut=()=>{const[i,o]=s.useState(""),[a,r]=s.useState(""),[j,c]=s.useState(0),[m,b]=s.useState(null),S=()=>c(y=>y+1);return m?e.jsx("div",{style:{flex:1,overflow:"hidden",borderRadius:8,background:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(_t,{app:m,onBack:()=>{b(null),S()},onSaved:()=>{b(null),S()}})}):e.jsxs("div",{style:{display:"flex",gap:16,height:"calc(100vh - 180px)",padding:16},children:[e.jsx(t.Card,{size:"small",style:{width:300,overflow:"auto",flexShrink:0},title:"分组",extra:e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:S}),children:e.jsx(Os,{selectedGroupCode:i,onGroupSelect:(y,p)=>{o(y||""),r(y&&p||"")},onGroupRefresh:S},j)}),e.jsx(t.Card,{size:"small",style:{flex:1,overflow:"auto"},title:a||void 0,children:e.jsx(zs,{selectedGroupCode:i,onEditApp:b})})]})},ut={ollama:[{code:"qwen2.5:7b-instruct-q4_K_M",name:"Qwen 2.5 7B"},{code:"qwen3:8b",name:"Qwen3 8B"},{code:"llama3:latest",name:"Llama 3"},{code:"qwen2.5:14b-instruct-q4_K_M",name:"Qwen 2.5 14B"}],openai:[{code:"gpt-4o",name:"GPT-4o"},{code:"gpt-4o-mini",name:"GPT-4o Mini"},{code:"gpt-4-turbo",name:"GPT-4 Turbo"}],dashscope:[{code:"qwen-max",name:"Qwen Max"},{code:"qwen-plus",name:"Qwen Plus"},{code:"qwen-turbo",name:"Qwen Turbo"}]},Is=i=>{const o={};i.forEach(r=>{o[r.groupCode]={key:r.groupCode,title:r.groupName,children:[]}});const a=[];return i.forEach(r=>{const j=o[r.groupCode];r.parentCode&&o[r.parentCode]?o[r.parentCode].children.push(j):r.parentCode||a.push(j)}),a},Os=({selectedGroupCode:i,onGroupSelect:o,onGroupRefresh:a})=>{const[r,j]=s.useState([]),[c,m]=s.useState(!1),[b,S]=s.useState(!1),[y,p]=s.useState(null),[g,P]=s.useState(null),[N]=t.Form.useForm(),D=s.useRef(null),x=C=>{o(C===i?"":C,"")},v=()=>{m(!0),ae.groupTree().then(C=>{j((C==null?void 0:C.data)||C||[])}).finally(()=>m(!1))};s.useEffect(()=>{v()},[]);const T=()=>{const C={};r.forEach(E=>{C[E.groupCode]={key:E.groupCode,title:E.groupName,groupCode:E.groupCode,parentCode:E.parentCode||"",icon:i===E.groupCode?e.jsx(l.FolderOpenOutlined,{}):e.jsx(l.FolderOutlined,{}),data:E,children:[]}});const k=[];return r.forEach(E=>{const W=C[E.groupCode];E.parentCode&&C[E.parentCode]?C[E.parentCode].children.push(W):E.parentCode||k.push(W)}),k},f=C=>{const k=r.find(E=>E.groupCode===C.groupCode);return e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,padding:"2px 0",cursor:"pointer"},onClick:()=>x(C.groupCode),children:[e.jsx("span",{style:{flex:1,fontSize:13},children:C.title}),e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.PlusOutlined,{style:{fontSize:11,color:"#1890ff"}}),onClick:E=>{E.stopPropagation(),P(k),p(null),N.resetFields(),N.setFieldsValue({parentCode:C.groupCode}),S(!0)},title:"新增子分组"}),e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.EditOutlined,{style:{fontSize:11}}),onClick:E=>{E.stopPropagation(),p(k),N.setFieldsValue({groupName:k.groupName,parentCode:k.parentCode||""}),P(null),S(!0)}}),e.jsx(t.Popconfirm,{title:`删除分组"${k.groupName}"?`,description:"子分组也会被删除",onConfirm:()=>M(C.groupCode),onCancel:E=>E==null?void 0:E.stopPropagation(),children:e.jsx(t.Button,{type:"text",size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{style:{fontSize:11}}),onClick:E=>E.stopPropagation()})})]})]})},M=async C=>{try{await ae.groupDelete(C),t.message.success("删除成功"),a()}catch{t.message.error("删除失败")}},K=async()=>{try{const C=await N.validateFields();m(!0),y?(await ae.groupUpdate({groupCode:y.groupCode,groupName:C.groupName,parentCode:C.parentCode||""}),t.message.success("更新成功")):(await ae.groupCreate({groupName:C.groupName,parentCode:C.parentCode||"",groupCode:"grp_"+Date.now()}),t.message.success("创建成功")),S(!1),a()}catch{t.message.error("操作失败")}finally{m(!1)}};return e.jsxs("div",{style:{padding:"4px 0"},children:[e.jsx("div",{style:{maxHeight:"calc(100vh - 320px)",overflow:"auto"},children:e.jsx(t.Tree,{treeData:T(),defaultExpandAll:!0,showLine:!0,blockNode:!0,titleRender:f,selectedKeys:i?[i]:[],onSelect:()=>{}})}),e.jsx(t.Modal,{title:y?"编辑分组":g?`新建子分组 - ${g.groupName}`:"新建分组",open:b,onCancel:()=>S(!1),onOk:()=>N.submit(),destroyOnClose:!0,children:e.jsxs(t.Form,{form:N,layout:"vertical",onFinish:K,children:[e.jsx(t.Form.Item,{name:"groupName",label:"分组名称",rules:[{required:!0,message:"请输入分组名称"}],children:e.jsx(t.Input,{ref:D,placeholder:"如:客服机器人"})}),e.jsx(t.Form.Item,{name:"parentCode",label:"父分组",children:e.jsx(t.Select,{allowClear:!0,placeholder:"留空为顶级分组",children:r.filter(C=>y?C.groupCode!==y.groupCode:!0).map(C=>e.jsx(t.Select.Option,{value:C.groupCode,children:C.groupName},C.groupCode))})})]})})]})},As=({record:i,onEdit:o,onView:a,onPublish:r,onUpgrade:j,onShare:c,onDelete:m,onToolConfig:b,onToggleShare:S,loading:y})=>{var N,D;const p=i.status==="PUBLISHED",g=i.version||1,P=!!i.shareEnabled;return e.jsx(t.Card,{hoverable:!0,style:{borderRadius:12,border:"1px solid #f0f0f0",transition:"all 0.3s"},bodyStyle:{padding:16},actions:[p?e.jsx(t.Tooltip,{title:"查看发布版本(只读)",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>a==null?void 0:a(i),children:"查看"})},"view"):e.jsx(t.Tooltip,{title:"编辑草稿",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.EditOutlined,{}),onClick:()=>o(i),children:"编辑"})},"edit"),p?e.jsx(t.Tooltip,{title:"基于当前版本创建新草稿",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.DiffOutlined,{}),onClick:()=>j==null?void 0:j(i),children:"升级"})},"upgrade"):e.jsx(t.Tooltip,{title:"发布后即可分享",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.RocketOutlined,{}),onClick:()=>r(i.appCode),children:"发布"})},"publish"),e.jsx(t.Tooltip,{title:P?"查看/复制分享链接":"开启后生成分享链接",children:e.jsx(t.Button,{type:"text",icon:P?e.jsx(l.GlobalOutlined,{style:{color:"#52c41a"}}):e.jsx(l.LockOutlined,{}),onClick:()=>c==null?void 0:c(i),children:"分享"})},"share"),e.jsx(t.Tooltip,{title:"工具配置",children:e.jsx(t.Button,{type:"text",icon:e.jsx(l.SettingOutlined,{}),onClick:()=>b==null?void 0:b(i),children:"工具"})},"tools"),e.jsx(t.Popconfirm,{title:"确定删除此应用?",onConfirm:()=>m(i.id),okText:"删除",okButtonProps:{danger:!0},children:e.jsx(t.Button,{type:"text",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),children:"删除"})},"delete")],children:e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsx(t.Avatar,{shape:"square",size:64,src:i.iconUrl,icon:e.jsx(l.RobotOutlined,{}),style:{background:p?"linear-gradient(135deg, #52c41a 0%, #389e0d 100%)":"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:8},children:[e.jsxs("div",{children:[e.jsx(ze,{level:5,style:{margin:0,color:"#262626"},children:i.appName}),e.jsx(xe,{type:"secondary",style:{fontSize:12,fontFamily:"monospace"},children:i.appCode})]}),e.jsxs(t.Space,{size:4,children:[e.jsxs(t.Tag,{style:{borderRadius:20,fontSize:11},children:["v",g]}),e.jsx(t.Tag,{color:p?"success":"default",style:{borderRadius:20},children:p?"已发布":"草稿"}),P&&e.jsx(t.Tooltip,{title:"已开启分享,点击「分享」按钮获取链接",children:e.jsx(t.Tag,{color:"green",icon:e.jsx(l.GlobalOutlined,{}),style:{borderRadius:20,fontSize:11,margin:0},children:"已分享"})})]})]}),i.description&&e.jsx("div",{style:{color:"#595959",fontSize:13,marginBottom:12,lineHeight:1.6},children:i.description}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[e.jsx(t.Tag,{color:"blue",style:{margin:0},children:i.modelProvider||"ollama"}),e.jsx(xe,{style:{fontSize:13,color:"#8c8c8c"},children:i.modelName||"qwen2.5:7b"})]}),e.jsxs("div",{style:{display:"flex",gap:16,fontSize:12,color:"#8c8c8c",marginTop:8},children:[e.jsxs("span",{children:["创建于 ",((N=i.gmtCreate)==null?void 0:N.split(" ")[0])||"-"]}),i.gmtModified!==i.gmtCreate&&e.jsxs("span",{children:["更新于 ",((D=i.gmtModified)==null?void 0:D.split(" ")[0])||"-"]})]})]})]})})},Es=({app:i,onEnable:o})=>{const[a,r]=s.useState(!1);return e.jsxs("div",{style:{padding:"24px 0",textAlign:"center"},children:[e.jsx("div",{style:{width:96,height:96,borderRadius:"50%",margin:"24px auto",background:"linear-gradient(135deg, #f6ffed 0%, #d9f7be 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.LockOutlined,{style:{fontSize:40,color:"#52c41a"}})}),e.jsx(ze,{level:5,style:{marginTop:8},children:"该应用尚未开启分享"}),e.jsxs(xe,{type:"secondary",style:{display:"block",marginBottom:24,fontSize:13},children:["开启后,任何人都可通过专属链接访问该 Agent",e.jsx("br",{}),"无需登录、可嵌入网页 / 群聊 / 二维码"]}),e.jsx(t.Button,{type:"primary",size:"large",icon:e.jsx(l.GlobalOutlined,{}),loading:a,onClick:async()=>{r(!0);try{await o()}finally{r(!1)}},style:{borderRadius:8,minWidth:160},children:"开启分享"}),e.jsx(t.Divider,{style:{margin:"32px 0 16px"},plain:!0,children:e.jsx(xe,{type:"secondary",style:{fontSize:12},children:"分享后你可以获得"})}),e.jsx(t.Space,{orientation:"vertical",size:"small",style:{width:"100%",textAlign:"left",padding:"0 16px"},children:[{icon:e.jsx(l.LinkOutlined,{}),text:"独立的访问链接与二维码"},{icon:e.jsx(l.CopyOutlined,{}),text:"一键复制到微信 / 飞书 / 邮件"},{icon:e.jsx(l.EyeOutlined,{}),text:"实时统计访问人数与对话轮次"}].map((j,c)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"#595959",fontSize:13},children:[e.jsx("span",{style:{color:"#52c41a"},children:j.icon}),j.text]},c))})]})},Ps=({app:i,onDisable:o,onRefresh:a})=>{var p,g;const r=i.shareCode?`${window.location.origin}/share/${i.shareCode}`:"",[j,c]=s.useState(!1),[m,b]=s.useState(!1),S=async()=>{if(r)try{await navigator.clipboard.writeText(r),c(!0),t.message.success("链接已复制"),setTimeout(()=>c(!1),2e3)}catch{const P=document.createElement("textarea");P.value=r,document.body.appendChild(P),P.select(),document.execCommand("copy"),document.body.removeChild(P),c(!0),t.message.success("链接已复制"),setTimeout(()=>c(!1),2e3)}},y=async()=>{b(!0);try{await a()}finally{b(!1)}};return e.jsxs("div",{children:[e.jsx(t.Alert,{type:"success",showIcon:!0,message:"已开启分享",description:"链接现在可被任何人访问,关闭分享后旧链接立即失效。",style:{borderRadius:8,marginBottom:20}}),e.jsxs("div",{style:{display:"flex",gap:20,padding:20,background:"#fafafa",borderRadius:12,alignItems:"center",marginBottom:20},children:[e.jsx("div",{style:{background:"#fff",padding:12,borderRadius:8,boxShadow:"0 1px 3px rgba(0,0,0,0.06)",flexShrink:0},children:r?e.jsx(t.QRCode,{value:r,size:140,bordered:!1}):e.jsx("div",{style:{width:140,height:140,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(xe,{type:"secondary",children:"无链接"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx(xe,{type:"secondary",style:{fontSize:12},children:"分享链接"}),e.jsx(t.Input.TextArea,{value:r,readOnly:!0,autoSize:{minRows:2,maxRows:3},style:{marginTop:4,fontSize:12,fontFamily:"monospace",resize:"none"},onClick:P=>P.target.select()}),e.jsxs(t.Space,{style:{marginTop:8},size:"small",children:[e.jsx(t.Button,{type:"primary",size:"small",icon:j?e.jsx(l.CheckCircleFilled,{}):e.jsx(l.CopyOutlined,{}),onClick:S,disabled:!r,children:j?"已复制":"复制链接"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.LinkOutlined,{}),onClick:()=>r&&window.open(r,"_blank"),disabled:!r,children:"打开"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),loading:m,onClick:y,children:"刷新链接"})]})]})]}),e.jsxs("div",{style:{marginBottom:20},children:[e.jsx(ze,{level:5,style:{fontSize:13,marginBottom:12},children:"分享设置"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"访问方式"}),e.jsx("div",{style:{marginTop:4},children:e.jsx(t.Tag,{color:"blue",style:{margin:0},children:"公开链接"})})]}),e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"是否需要登录"}),e.jsx("div",{style:{marginTop:4},children:e.jsx(t.Tag,{style:{margin:0},children:"不需要"})})]}),e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"创建时间"}),e.jsx("div",{style:{marginTop:4,fontSize:13},children:((p=i.shareGmtCreate)==null?void 0:p.split(" ")[0])||((g=i.gmtModified)==null?void 0:g.split(" ")[0])||"-"})]}),e.jsxs("div",{style:{padding:12,background:"#fafafa",borderRadius:8},children:[e.jsx(xe,{type:"secondary",style:{fontSize:11},children:"累计访问"}),e.jsxs("div",{style:{marginTop:4,fontSize:13},children:[i.shareVisitCount??0," 次"]})]})]})]}),e.jsx(t.Divider,{style:{margin:"12px 0"}}),e.jsx(t.Popconfirm,{title:"确定要关闭分享吗?",description:"关闭后,链接将立即失效。",okText:"关闭分享",okButtonProps:{danger:!0},cancelText:"取消",onConfirm:o,children:e.jsx(t.Button,{block:!0,danger:!0,icon:e.jsx(l.LockOutlined,{}),children:"关闭分享"})})]})},zs=({selectedGroupCode:i,onEditApp:o})=>{const[a,r]=s.useState([]),[j,c]=s.useState(!1),[m,b]=s.useState(""),[S,y]=s.useState(""),[p,g]=s.useState(1),[P]=s.useState(12),[N,D]=s.useState(0),[x,v]=s.useState(!1),[T,f]=s.useState([]),[M,K]=s.useState(!1),[C,k]=s.useState(null),[E,W]=s.useState(!1),[h,B]=s.useState(null),[F,A]=s.useState("card"),[I,G]=s.useState(ut.ollama),[u,w]=s.useState(!1),[U]=t.Form.useForm(),[z,Q]=s.useState([]);s.useEffect(()=>{d(),n()},[p,m,S,i]);const d=()=>{c(!0),ae.appPage({appName:m,status:S,groupCode:i,id:p}).then(H=>{H&&(r(H.records||[]),D(H.total||0))}).catch(H=>t.message.error("加载失败")).finally(()=>c(!1))},n=()=>{ae.groupTree().then(H=>{const X=(H==null?void 0:H.data)||H||[];f(X),Q(X.filter(ie=>ie.groupCode)),d()})},_=()=>{var ie;U.resetFields();const H="ollama",X=ut[H]||[];G(X),U.setFieldsValue({modelProvider:H,modelName:((ie=X[0])==null?void 0:ie.code)||"",groupCode:i}),w(!0)},$=async()=>{try{const H=await U.validateFields();v(!0),await ae.appCreate(H),t.message.success("创建成功"),w(!1),d()}catch(H){H.errorFields||t.message.error("操作失败")}finally{v(!1)}},R=H=>{o(H)},se=H=>{o(H)},je=async H=>{try{await ae.appDelete(H),t.message.success("删除成功"),d()}catch{t.message.error("删除失败")}},le=async H=>{try{await ae.appPublish(H),t.message.success("发布成功"),d()}catch{t.message.error("发布失败")}},fe=async H=>{try{await ae.appUpgrade(H.appCode),t.message.success("已升级到新草稿版本,可编辑后发布"),d();const X=await ae.appGet(H.appCode),ie=(X==null?void 0:X.data)||X;ie&&o(ie)}catch(X){t.message.error("升级失败:"+((X==null?void 0:X.message)||"未知错误"))}},V=H=>{B(H),W(!0)},ee=async(H,X)=>{try{const ie=await ae.appToggleShare(H.appCode,X),he=(ie==null?void 0:ie.data)||ie;t.message.success(X?"已开启分享":"已关闭分享"),r(re=>re.map(ye=>ye.id===H.id?{...ye,shareEnabled:X,shareCode:he||ye.shareCode}:ye)),B(re=>re&&re.id===H.id?{...re,shareEnabled:X,shareCode:he||re.shareCode}:re)}catch(ie){t.message.error("操作失败:"+((ie==null?void 0:ie.message)||"未知错误"))}},ce=a.filter(H=>H.status==="PUBLISHED").length;return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:16,padding:"16px 20px",background:"#fafafa",borderRadius:8},children:[e.jsxs(t.Space,{wrap:!0,children:[e.jsx(t.Input.Search,{placeholder:"搜索应用名称/编码",onSearch:H=>{b(H),g(1)},style:{width:280},allowClear:!0,enterButton:!0}),e.jsxs(t.Select,{placeholder:"状态筛选",allowClear:!0,style:{width:140},onChange:H=>{y(H),g(1)},children:[e.jsx(we,{value:"DRAFT",children:"草稿"}),e.jsx(we,{value:"PUBLISHED",children:"已发布"})]})]}),e.jsxs(t.Space,{children:[N>0&&e.jsxs(xe,{type:"secondary",children:["共 ",e.jsx(xe,{strong:!0,children:N})," 个应用,已发布 ",e.jsx(xe,{strong:!0,style:{color:"#52c41a"},children:ce})," 个"]}),e.jsx(t.Button,{size:"small",type:F==="card"?"primary":"default",icon:e.jsx(l.AppstoreFilled,{}),onClick:()=>A("card"),style:{borderRadius:6}}),e.jsx(t.Button,{size:"small",type:F==="list"?"primary":"default",icon:e.jsx(l.UnorderedListOutlined,{}),onClick:()=>A("list"),style:{borderRadius:6}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:_,style:{borderRadius:8},children:"新建应用"})]})]}),j&&e.jsxs("div",{style:{textAlign:"center",padding:48},children:[e.jsx(l.LoadingOutlined,{style:{fontSize:32,color:"#667eea"}}),e.jsx("div",{style:{marginTop:16,color:"#8c8c8c"},children:"加载中..."})]}),!j&&a.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"64px 24px",background:"#fafafa",borderRadius:12},children:[e.jsx("div",{style:{width:80,height:80,borderRadius:"50%",background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 24px"},children:e.jsx(l.RobotOutlined,{style:{fontSize:36,color:"#fff"}})}),e.jsx(ze,{level:4,style:{marginBottom:8},children:"还没有应用"}),e.jsx(xe,{type:"secondary",style:{display:"block",marginBottom:24},children:"点击「新建应用」开始创建您的第一个 Agent"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:_,style:{borderRadius:8},children:"新建应用"})]}),!j&&a.length>0&&F==="card"&&e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(400px, 1fr))",gap:16,marginBottom:16},children:a.map(H=>e.jsx(As,{record:H,onEdit:R,onView:se,onPublish:le,onUpgrade:fe,onShare:V,onDelete:je,onToolConfig:X=>{k(X),K(!0)},onShareManage:X=>{B(X),W(!0)}},H.id))}),!j&&a.length>0&&F==="list"&&e.jsx(t.Table,{dataSource:a,rowKey:"id",size:"small",pagination:!1,columns:[{title:"名称",dataIndex:"appName",width:180,render:(H,X)=>e.jsx("a",{onClick:()=>R(X),style:{fontWeight:500},children:H||X.appCode})},{title:"版本",dataIndex:"version",width:60,render:H=>e.jsxs(t.Tag,{style:{fontSize:11},children:["v",H||1]})},{title:"编码",dataIndex:"appCode",width:180,render:H=>e.jsx("code",{style:{fontSize:12,color:"#8c8c8c"},children:H})},{title:"状态",dataIndex:"status",width:80,render:H=>e.jsx(t.Tag,{color:H==="PUBLISHED"?"green":"default",children:H==="PUBLISHED"?"已发布":"草稿"})},{title:"供应商",dataIndex:"modelProvider",width:100},{title:"模型",dataIndex:"modelName",width:140,ellipsis:!0},{title:"创建时间",dataIndex:"gmtCreate",width:170},{title:"操作",width:220,render:(H,X)=>e.jsxs(t.Space,{size:"small",children:[X.status==="PUBLISHED"?e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>se(X),children:"查看"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.DiffOutlined,{}),onClick:()=>fe(X),children:"升级"})]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.EditOutlined,{}),onClick:()=>R(X),children:"编辑"}),e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.RocketOutlined,{}),onClick:()=>le(X.appCode),children:"发布"})]}),e.jsx(t.Popconfirm,{title:"确定删除?",onConfirm:()=>je(X.id),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),children:"删除"})})]})}]}),!j&&N>P&&e.jsxs("div",{style:{textAlign:"center",marginTop:16},children:[e.jsx(t.Button,{onClick:()=>g(H=>Math.max(1,H-1)),disabled:p===1,children:"上一页"}),e.jsxs("span",{style:{margin:"0 16px"},children:["第 ",e.jsx(xe,{strong:!0,children:p})," / ",Math.ceil(N/P)," 页"]}),e.jsx(t.Button,{onClick:()=>g(H=>H+1),disabled:p>=Math.ceil(N/P),children:"下一页"})]}),e.jsx(t.Modal,{title:"新建应用",open:u,onOk:$,onCancel:()=>w(!1),confirmLoading:x,width:520,okText:"创建",cancelText:"取消",children:e.jsxs(t.Form,{form:U,layout:"vertical",size:"middle",children:[e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(t.Form.Item,{name:"appName",label:"应用名称",rules:[{required:!0,message:"请输入应用名称"}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"如:智能客服助手"})}),e.jsx(t.Form.Item,{name:"groupCode",label:"分组",style:{width:160},children:e.jsx(t.TreeSelect,{allowClear:!0,placeholder:"默认",treeData:Is(z),treeDefaultExpandAll:!0,onChange:H=>U.setFieldsValue({groupCode:H||""}),style:{width:"100%"}})})]}),e.jsx(t.Form.Item,{name:"description",label:"应用描述",children:e.jsx(ks,{rows:2,placeholder:"简短描述这个应用的能力和使用场景"})}),e.jsx(t.Divider,{style:{margin:"12px 0",fontSize:12,color:"#8c8c8c"},children:"应用类型"}),e.jsx(t.Form.Item,{name:"agentMode",label:"类型",rules:[{required:!0,message:"请选择应用类型"}],initialValue:"chat",children:e.jsxs(t.Select,{children:[e.jsx(we,{value:"chat",children:"对话 - 纯文本对话"}),e.jsx(we,{value:"agent",children:"智能体 - 工具调用 + 知识库"}),e.jsx(we,{value:"workflow",children:"工作流 - 多步骤流程编排"})]})}),e.jsx(t.Divider,{style:{margin:"12px 0",fontSize:12,color:"#8c8c8c"},children:"模型配置"}),e.jsx(t.Form.Item,{name:"modelProvider",label:"提供商",rules:[{required:!0}],initialValue:"ollama",children:e.jsxs(t.Select,{onChange:H=>{var ie;const X=ut[H]||[];G(X),U.setFieldsValue({modelName:((ie=X[0])==null?void 0:ie.code)||""})},children:[e.jsx(we,{value:"ollama",children:"Ollama (本地)"}),e.jsx(we,{value:"openai",children:"OpenAI"}),e.jsx(we,{value:"dashscope",children:"阿里通义"})]})}),e.jsx(t.Form.Item,{name:"modelName",label:"模型",rules:[{required:!0}],children:e.jsx(t.Select,{children:I.map(H=>e.jsx(we,{value:H.code,children:H.name},H.code))})})]})}),e.jsx(t.Drawer,{title:C?`${C.appName} - 工具配置`:"工具配置",width:560,open:M,onClose:()=>K(!1),children:C&&e.jsx(Rs,{appCode:C.appCode})}),e.jsx(t.Drawer,{title:h?`${h.appName} · 分享`:"分享",width:520,open:E,onClose:()=>W(!1),destroyOnClose:!0,extra:h&&e.jsxs(t.Space,{children:[e.jsx(xe,{type:"secondary",style:{fontSize:12},children:"分享"}),e.jsx(t.Switch,{size:"small",checked:!!h.shareEnabled,onChange:H=>ee(h,H)})]}),children:h&&(h.shareEnabled?e.jsx(Ps,{app:h,onDisable:()=>ee(h,!1),onRefresh:()=>ee(h,!0)}):e.jsx(Es,{app:h,onEnable:()=>ee(h,!0)}))})]})},Rs=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(null),[j,c]=s.useState([]),[m,b]=s.useState([]),[S,y]=s.useState([]),[p,g]=s.useState([]),[P,N]=s.useState([]),[D,x]=s.useState([]),[v,T]=s.useState(!1),[f,M]=s.useState(!1),[K,C]=s.useState("tools"),[k,E]=s.useState(!1);s.useEffect(()=>{E(!0),ae.appPage({id:1,pageSize:100}).then(I=>{o((I==null?void 0:I.records)||[])}).finally(()=>E(!1))},[]),s.useEffect(()=>{a&&(T(!0),Promise.all([Ae.toolTemplateList(),Ae.skillTemplateList(),Ae.knowledgeList()]).then(([I,G,u])=>{c((I==null?void 0:I.data)||I||[]),b((G==null?void 0:G.data)||G||[]),y((u==null?void 0:u.data)||u||[]),W(a.appCode)}).finally(()=>T(!1)))},[a]);const W=I=>{Ae.appConfig(I).then(G=>{const u=(G==null?void 0:G.data)||G||{};g(u.tools||[]),N(u.skills||[]),x(u.knowledgeBases||[])}).catch(()=>{})},h=(I,G)=>I.includes(G),B=(I,G)=>{I==="tool"?g(u=>u.includes(G)?u.filter(w=>w!==G):[...u,G]):I==="skill"?N(u=>u.includes(G)?u.filter(w=>w!==G):[...u,G]):x(u=>u.includes(G)?u.filter(w=>w!==G):[...u,G])},F=async()=>{if(a){M(!0);try{for(const I of p)await Ae.appToolAdd({appCode:a.appCode,toolCode:I}).catch(()=>{});for(const I of P)await Ae.appSkillAdd({appCode:a.appCode,skillId:Number(I)}).catch(()=>{});t.message.success("工具配置已保存")}catch{t.message.error("保存失败")}finally{M(!1)}}},A=(I,G,u,w,U,z)=>e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:16},children:[G,e.jsx("span",{style:{fontWeight:500},children:I}),e.jsx(t.Tag,{children:u.length})]}),u.length===0?e.jsx(t.Empty,{description:"暂无可用项",image:t.Empty.PRESENTED_IMAGE_SIMPLE}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:u.map(z)})]});return i.length===0?e.jsx("div",{style:{padding:48,textAlign:"center"},children:e.jsx(t.Empty,{description:"请先创建应用后再配置工具"})}):e.jsx("div",{style:{padding:24},children:e.jsxs(t.Row,{gutter:24,children:[e.jsxs(t.Col,{span:8,children:[e.jsx(ze,{level:5,style:{marginBottom:16},children:"选择应用"}),e.jsx("div",{style:{background:"#fafafa",borderRadius:8,padding:16,maxHeight:500,overflow:"auto"},children:i.map(I=>e.jsx("div",{onClick:()=>r(I),style:{padding:"12px 16px",marginBottom:8,borderRadius:8,cursor:"pointer",background:(a==null?void 0:a.id)===I.id?"#fff":"transparent",border:(a==null?void 0:a.id)===I.id?"2px solid #667eea":"2px solid transparent",transition:"all 0.2s"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(t.Avatar,{size:"small",icon:e.jsx(l.RobotOutlined,{}),style:{background:I.status==="PUBLISHED"?"linear-gradient(135deg, #52c41a, #389e0d)":"linear-gradient(135deg, #667eea, #764ba2)"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:14},children:I.appName}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:I.appCode})]})]})},I.id))})]}),e.jsx(t.Col,{span:16,children:a?e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:20},children:[e.jsxs(ze,{level:5,style:{margin:0},children:["配置 ",a.appName]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CheckCircleFilled,{}),onClick:F,loading:f,children:"保存配置"})]}),e.jsxs(t.Tabs,{activeKey:K,onChange:C,children:[e.jsx(pt,{tab:"工具",children:e.jsx("div",{style:{padding:16,background:"#fafafa",borderRadius:8},children:A("可用工具",e.jsx(ToolOutlined,{}),j,p,"tool",I=>e.jsxs("div",{onClick:()=>B("tool",I.toolCode),style:{padding:"10px 14px",background:h(p,I.toolCode)?"#e6f7ff":"#fff",border:`1px solid ${h(p,I.toolCode)?"#91d5ff":"#f0f0f0"}`,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:20,height:20,borderRadius:4,background:h(p,I.toolCode)?"#1890ff":"#d9d9d9",display:"flex",alignItems:"center",justifyContent:"center"},children:h(p,I.toolCode)&&e.jsx(l.CheckCircleFilled,{style:{color:"#fff",fontSize:12}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:I.toolName||I.toolCode}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:I.description||I.toolCode})]})]},I.toolCode))})},"tools"),e.jsx(pt,{tab:"技能",children:e.jsx("div",{style:{padding:16,background:"#fafafa",borderRadius:8},children:A("可用技能",e.jsx(l.StarOutlined,{}),m,P,"skill",I=>e.jsxs("div",{onClick:()=>B("skill",String(I.id)),style:{padding:"10px 14px",background:h(P,String(I.id))?"#fff7e6":"#fff",border:`1px solid ${h(P,String(I.id))?"#ffd591":"#f0f0f0"}`,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:20,height:20,borderRadius:4,background:h(P,String(I.id))?"#fa8c16":"#d9d9d9",display:"flex",alignItems:"center",justifyContent:"center"},children:h(P,String(I.id))&&e.jsx(l.CheckCircleFilled,{style:{color:"#fff",fontSize:12}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:I.name}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:I.description||I.code})]})]},I.id))})},"skills"),e.jsx(pt,{tab:"知识库",children:e.jsx("div",{style:{padding:16,background:"#fafafa",borderRadius:8},children:A("可用知识库",e.jsx(l.BookOutlined,{}),S,D,"kb",I=>e.jsxs("div",{onClick:()=>B("kb",String(I.id)),style:{padding:"10px 14px",background:h(D,String(I.id))?"#f6ffed":"#fff",border:`1px solid ${h(D,String(I.id))?"#b7eb8f":"#f0f0f0"}`,borderRadius:6,cursor:"pointer",display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:20,height:20,borderRadius:4,background:h(D,String(I.id))?"#52c41a":"#d9d9d9",display:"flex",alignItems:"center",justifyContent:"center"},children:h(D,String(I.id))&&e.jsx(l.CheckCircleFilled,{style:{color:"#fff",fontSize:12}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:I.name}),e.jsx("div",{style:{fontSize:11,color:"#8c8c8c"},children:I.description||`ID: ${I.id}`})]})]},I.id))})},"knowledge")]})]}):e.jsxs("div",{style:{padding:48,textAlign:"center",background:"#fafafa",borderRadius:12},children:[e.jsx(l.RobotOutlined,{style:{fontSize:48,color:"#d9d9d9"}}),e.jsx("div",{style:{marginTop:16,color:"#8c8c8c"},children:"请从左侧选择一个应用"})]})})]})})},{TextArea:Ns}=t.Input,Bs=({children:i,className:o})=>{const a=String(i).replace(/\n$/,""),[r,j]=s.useState(!1),c=()=>{navigator.clipboard.writeText(a).then(()=>{j(!0),setTimeout(()=>j(!1),2e3)})};return e.jsxs("div",{style:{position:"relative",margin:"8px 0"},children:[e.jsx(t.Button,{size:"small",icon:r?e.jsx(l.CheckCircleFilled,{}):e.jsx(l.CopyOutlined,{}),onClick:c,style:{position:"absolute",right:8,top:8,opacity:.7},children:r?"已复制":"复制"}),e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",borderRadius:6,padding:"12px 16px",overflow:"auto",fontSize:13,lineHeight:1.5,fontFamily:'Consolas, Monaco, "Courier New", monospace'},children:e.jsx("code",{className:o,children:a})})]})},Fs=({msg:i})=>{const o=i.role==="user",a=i.status==="FAILED";return e.jsxs("div",{style:{display:"flex",justifyContent:o?"flex-end":"flex-start",marginBottom:16,animation:"fadeIn 0.3s ease"},children:[!o&&e.jsx(t.Avatar,{icon:e.jsx(l.RobotOutlined,{}),size:36,style:{marginRight:10,background:"#1890ff",flexShrink:0}}),e.jsxs("div",{style:{maxWidth:"72%",display:"flex",flexDirection:"column",alignItems:o?"flex-end":"flex-start"},children:[a&&e.jsx(t.Tag,{color:"red",icon:e.jsx(l.ExclamationCircleFilled,{}),style:{marginBottom:4},children:"出错了"}),o?e.jsx("div",{style:{padding:"10px 14px",borderRadius:"16px 16px 4px 16px",background:"linear-gradient(135deg, #1890ff, #096dd9)",color:"#fff",lineHeight:1.6,fontSize:15,boxShadow:"0 2px 8px rgba(24,144,255,0.3)"},children:i.content}):e.jsx("div",{style:{padding:"12px 16px",borderRadius:"16px 16px 16px 4px",background:"#fff",color:"#333",lineHeight:1.7,fontSize:15,boxShadow:"0 1px 4px rgba(0,0,0,0.1)",border:"1px solid #f0f0f0"},children:e.jsx(Et,{remarkPlugins:[gs],components:{code({node:r,inline:j,className:c,children:m,...b}){return j?e.jsx("code",{style:{background:"#f5f5f5",padding:"2px 6px",borderRadius:4,fontFamily:"monospace",fontSize:"0.9em",color:"#c7254e"},...b,children:m}):e.jsx(Bs,{className:c,children:m})},p({children:r}){return e.jsx("p",{style:{margin:"0 0 8px 0"},children:r})},ul({children:r}){return e.jsx("ul",{style:{margin:"4px 0",paddingLeft:20},children:r})},ol({children:r}){return e.jsx("ol",{style:{margin:"4px 0",paddingLeft:20},children:r})},li({children:r}){return e.jsx("li",{style:{marginBottom:2},children:r})},strong({children:r}){return e.jsx("strong",{style:{color:"#1890ff"},children:r})},h1({children:r}){return e.jsx("h1",{style:{fontSize:18,margin:"8px 0"},children:r})},h2({children:r}){return e.jsx("h2",{style:{fontSize:16,margin:"8px 0"},children:r})},h3({children:r}){return e.jsx("h3",{style:{fontSize:14,margin:"6px 0"},children:r})},blockquote({children:r}){return e.jsx("blockquote",{style:{borderLeft:"3px solid #1890ff",margin:"8px 0",paddingLeft:12,color:"#666"},children:r})}},children:i.content})}),i.latencyMs&&!o&&!a&&e.jsxs("span",{style:{fontSize:11,color:"#bbb",marginTop:4},children:[e.jsx(l.ClockCircleOutlined,{style:{marginRight:3}}),i.latencyMs,"ms"]})]}),o&&e.jsx(t.Avatar,{icon:e.jsx(l.UserOutlined,{}),size:36,style:{marginLeft:10,background:"#52c41a",flexShrink:0}})]})},Ls=({appName:i,appDesc:o})=>e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"60vh",color:"#666"},children:[e.jsx("div",{style:{fontSize:48,marginBottom:16,background:"linear-gradient(135deg, #1890ff, #52c41a)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",fontWeight:"bold"},children:i||"Agent"}),o&&e.jsx("p",{style:{color:"#999",marginBottom:24},children:o}),e.jsx("div",{style:{display:"flex",gap:12,flexWrap:"wrap",justifyContent:"center",maxWidth:500},children:["有什么可以帮助你的?","告诉我你的问题","试试问我任何事情"].map((a,r)=>e.jsx(t.Tag,{style:{padding:"6px 12px",fontSize:13,cursor:"pointer",borderRadius:16},onClick:()=>{const j=new CustomEvent("insertTip",{detail:a});window.dispatchEvent(j)},children:a},r))})]}),Ds=()=>{const{shareCode:i}=Be.useParams(),[o,a]=s.useState(!0),[r,j]=s.useState(""),[c,m]=s.useState(""),[b,S]=s.useState(""),[y,p]=s.useState([]),[g,P]=s.useState(""),[N,D]=s.useState(!1),[x,v]=s.useState(!1),[T,f]=s.useState(""),[M,K]=s.useState(!1),C=s.useRef(null),k=s.useRef(null);s.useRef(null),s.useEffect(()=>{E();const F=A=>P(I=>I||A.detail);return window.addEventListener("insertTip",F),()=>window.removeEventListener("insertTip",F)},[i]),s.useEffect(()=>{var F;(F=C.current)==null||F.scrollIntoView({behavior:"smooth"})},[y]);const E=async()=>{a(!0),f("");try{const F=await ae.shareVerify(i);if(F){j(F.instanceCode),m(F.appName||"Agent"),S(F.appDesc||""),v(!0);try{const A=await ae.chatHistory(F.instanceCode,50);if(A.data&&A.data.length>0){const I=[];A.data.forEach(G=>{I.push({id:`u_${G.id}`,role:"user",content:G.userMessage,time:G.gmtCreate,status:"SUCCESS"}),I.push({id:`a_${G.id}`,role:"assistant",content:G.assistantMessage,time:G.gmtCreate,status:G.status,latencyMs:G.latencyMs})}),p(I)}}catch(A){console.warn("加载历史失败",A)}}}catch{f("分享链接无效或已过期"),K(!0)}a(!1)},W=s.useCallback(async()=>{var w;const F=g.trim();if(!F||N)return;const I={id:`u_${Date.now()}`,role:"user",content:F,status:"SUCCESS"};p(U=>[...U,I]),P(""),D(!0);const G=`a_${Date.now()}`;let u="";p(U=>[...U,{id:G,role:"assistant",content:"",status:"LOADING"}]);try{const U=localStorage.getItem("token"),z=ae.chatStream(r,F,"visitor","游客",U);z.onmessage=Q=>{Q.data==="[DONE]"?(z.close(),p(d=>d.map(n=>n.id===G?{...n,content:u||"好的,我明白了。",status:"SUCCESS"}:n)),D(!1)):(u+=Q.data,p(d=>d.map(n=>n.id===G?{...n,content:u,status:"LOADING"}:n)))},z.onerror=Q=>{z.close(),p(d=>d.map(n=>n.id===G?{...n,content:"抱歉,AI 服务暂时不可用,请稍后重试。",status:"FAILED"}:n)),D(!1)}}catch{p(z=>z.map(Q=>Q.id===G?{...Q,content:"抱歉,AI 服务暂时不可用,请稍后重试。",status:"FAILED"}:Q)),D(!1)}(w=k.current)==null||w.focus()},[g,N,r]),h=()=>{t.Modal.confirm({title:"清空对话",content:"确定清空当前对话记录?此操作不可恢复。",okText:"清空",okButtonProps:{danger:!0},onOk:()=>{p([]),ae.chatClear(r).catch(()=>{})}})},B=F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),W())};return o?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",background:"#f0f2f5"},children:e.jsx(t.Spin,{indicator:e.jsx(l.LoadingOutlined,{style:{fontSize:32},spin:!0}),tip:"正在连接..."})}):M||T?e.jsx("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",background:"#f0f2f5"},children:e.jsxs(t.Card,{style:{textAlign:"center",maxWidth:400},children:[e.jsx(l.ExclamationCircleFilled,{style:{fontSize:48,color:"#ff4d4f",marginBottom:16}}),e.jsx("h3",{children:T||"无法访问此应用"}),e.jsx("p",{style:{color:"#999"},children:"可能的原因:链接已失效、应用已被删除或访问权限不足。"}),e.jsx(t.Button,{type:"primary",href:"/",icon:e.jsx(l.RobotOutlined,{}),children:"返回首页"})]})}):e.jsxs("div",{style:{height:"100vh",display:"flex",flexDirection:"column",background:"linear-gradient(180deg, #f0f2f5 0%, #fff 100%)"},children:[e.jsxs("div",{style:{borderBottom:"1px solid #e8e8e8",background:"#fff",padding:"12px 24px",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(t.Avatar,{shape:"square",size:36,icon:e.jsx(l.RobotOutlined,{}),style:{background:"#1890ff"}}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:16},children:c}),b&&e.jsx("div",{style:{fontSize:12,color:"#999"},children:b})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsxs("span",{style:{fontSize:12,color:x?"#52c41a":"#ff4d4f"},children:[e.jsx(l.CheckCircleFilled,{style:{marginRight:4}}),x?"已连接":"未连接"]}),e.jsx(t.Tooltip,{title:"清空对话",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.ClearOutlined,{}),onClick:h,disabled:y.length===0,children:"清空"})})]})]}),e.jsxs("div",{style:{flex:1,overflowY:"auto",padding:"16px 24px"},children:[y.length===0?e.jsx(Ls,{appName:c,appDesc:b}):e.jsx(e.Fragment,{children:e.jsx(t.List,{dataSource:y,renderItem:F=>e.jsx(Fs,{msg:F}),locale:{emptyText:""}})}),e.jsx("div",{ref:C})]}),y.length===0&&e.jsx("div",{style:{padding:"0 24px 8px",display:"flex",gap:8,flexWrap:"wrap"},children:["你好","你能做什么?","介绍下自己"].map((F,A)=>e.jsx(t.Button,{size:"small",type:"default",onClick:()=>P(F),children:F},A))}),e.jsxs("div",{style:{borderTop:"1px solid #e8e8e8",background:"#fff",padding:"12px 24px 20px",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-end"},children:[e.jsx(Ns,{ref:k,value:g,onChange:F=>P(F.target.value),onKeyDown:B,placeholder:"输入消息,Enter 发送,Shift+Enter 换行",autoSize:{minRows:1,maxRows:4},style:{flex:1,borderRadius:20},disabled:N||!x}),e.jsx(t.Button,{type:"primary",icon:N?e.jsx(l.LoadingOutlined,{}):e.jsx(l.SendOutlined,{}),onClick:W,loading:N,disabled:!g.trim()||!x,style:{borderRadius:20,width:56,height:36}})]}),e.jsx("div",{style:{fontSize:11,color:"#ccc",marginTop:6,textAlign:"center"},children:"AI 助手可能会产生不准确的信息,请仔细甄别"})]}),e.jsx("style",{children:`
23
23
  @keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
24
- `})]})},{confirm:Ds}=t.Modal,ut=[{providerCode:"ollama",providerName:"Ollama",providerType:"ollama",baseUrl:"http://localhost:11434",enabled:1,priority:100},{providerCode:"openai",providerName:"OpenAI",providerType:"openai",baseUrl:"https://api.openai.com",enabled:1,priority:90},{providerCode:"dashscope",providerName:"阿里通义",providerType:"dashscope",baseUrl:"https://dashscope.aliyuncs.com",enabled:1,priority:80}],He=[{id:1,modelCode:"qwen2.5:7b-instruct-q4_K_M",modelName:"Qwen 2.5 7B",providerCode:"ollama",modelType:"chat",contextWindow:32768,status:"ACTIVE",description:"通义千问 2.5 轻量级文本生成模型",inputPrice:0,outputPrice:0},{id:2,modelCode:"qwen3:8b",modelName:"Qwen3 8B",providerCode:"ollama",modelType:"chat",contextWindow:40960,status:"ACTIVE",description:"通义千问 3 最新一代模型",inputPrice:0,outputPrice:0},{id:3,modelCode:"gpt-4o",modelName:"GPT-4o",providerCode:"openai",modelType:"chat",contextWindow:128e3,status:"ACTIVE",description:"OpenAI 旗舰多模态模型",inputPrice:.0025,outputPrice:.01},{id:4,modelCode:"gpt-4o-mini",modelName:"GPT-4o Mini",providerCode:"openai",modelType:"chat",contextWindow:128e3,status:"ACTIVE",description:"轻量快速,性价比高",inputPrice:15e-5,outputPrice:6e-4},{id:5,modelCode:"qwen-vl-max",modelName:"Qwen VL Max",providerCode:"dashscope",modelType:"vision",contextWindow:8192,status:"ACTIVE",description:"通义千问视觉模型,支持图像理解",inputPrice:.002,outputPrice:.008},{id:6,modelCode:"qwen2-audio",modelName:"Qwen2 Audio",providerCode:"dashscope",modelType:"audio",contextWindow:8192,status:"ACTIVE",description:"通义千问语音模型",inputPrice:.001,outputPrice:.004},{id:7,modelCode:"text-embedding-v3",modelName:"Text Embedding V3",providerCode:"openai",modelType:"embedding",contextWindow:8191,status:"ACTIVE",description:"OpenAI 文本嵌入模型",inputPrice:2e-5,outputPrice:0},{id:8,modelCode:"codestral",modelName:"Codestral",providerCode:"ollama",modelType:"code",contextWindow:32768,status:"ACTIVE",description:"代码生成专用模型,支持多种编程语言",inputPrice:0,outputPrice:0},{id:9,modelCode:"dall-e-3",modelName:"DALL·E 3",providerCode:"openai",modelType:"image",contextWindow:0,status:"ACTIVE",description:"OpenAI 图像生成模型",inputPrice:.04,outputPrice:0}],Ee=[{key:"chat",title:"文本生成",icon:e.jsx(l.BranchesOutlined,{}),color:"#1677ff",bg:"#e6f4ff",border:"#1677ff"},{key:"code",title:"代码生成",icon:e.jsx(l.ThunderboltOutlined,{}),color:"#722ed1",bg:"#f9f0ff",border:"#722ed1"},{key:"image",title:"图像生成",icon:e.jsx(l.PictureOutlined,{}),color:"#13c2c2",bg:"#e6fffb",border:"#13c2c2"},{key:"vision",title:"视觉理解",icon:e.jsx(l.EyeOutlined,{}),color:"#fa8c16",bg:"#fff7e6",border:"#fa8c16"},{key:"audio",title:"语音",icon:e.jsx(l.AudioOutlined,{}),color:"#eb2f96",bg:"#fff0f6",border:"#eb2f96"},{key:"embedding",title:"嵌入/向量",icon:e.jsx(l.NodeIndexOutlined,{}),color:"#52c41a",bg:"#f6ffed",border:"#52c41a"}],Ls=[{value:"ollama",label:"Ollama"},{value:"openai",label:"OpenAI"},{value:"dashscope",label:"阿里通义"},{value:"azure",label:"Azure OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"自定义"}],Ms=()=>{const[o,i]=s.useState([]),[a,n]=s.useState([]),[T,d]=s.useState(!1),[b,f]=s.useState("chat"),[j,w]=s.useState(null),[h,m]=s.useState(!1),[z,F]=s.useState(null),[N]=t.Form.useForm(),[u,v]=s.useState(!1),[S,x]=s.useState(null),[D]=t.Form.useForm(),G=async()=>{d(!0);try{const[p,y]=await Promise.all([te("/llm-center/model/list",{method:"GET"}).catch(()=>null),te("/llm-center/provider/list",{method:"GET"}).catch(()=>null)]),M=Array.isArray(p)?p:(p==null?void 0:p.data)||[],E=Array.isArray(y)?y:(y==null?void 0:y.data)||[];M.length===0&&E.length===0?(n(ut),i(He)):(i(M),n(E))}catch{n(ut),i(He)}finally{d(!1)}};s.useEffect(()=>{G()},[]);const g={};Ee.forEach(p=>{g[p.key]=o.filter(y=>y.modelType===p.key).length});const C=o.filter(p=>{const y=!b||p.modelType===b,M=!j||p.providerCode===j;return y&&M}),P={ollama:"blue",openai:"green",dashscope:"cyan",azure:"purple",anthropic:"orange",custom:"default"},K=()=>{F(null),N.resetFields(),N.setFieldsValue({status:"ACTIVE",contextWindow:4096}),m(!0)},O=p=>{F(p),N.setFieldsValue(p),m(!0)},V=p=>{Ds({title:"确认删除",content:`删除模型 ${p.modelName} ?`,onOk:async()=>{if(o===He){i(o.filter(y=>y.id!==p.id)),t.message.success("删除成功");return}await te("/llm-center/model/delete",{method:"POST",data:{id:p.id}}),t.message.success("删除成功"),G()}})},U=async()=>{try{const p=await N.validateFields();if(o===He){i(z?o.map(y=>y.id===z.id?{...y,...p}:y):[...o,{...p,id:Date.now()}]),t.message.success(z?"更新成功":"创建成功"),m(!1);return}await te(z?"/llm-center/model/update":"/llm-center/model/create",{method:"POST",data:p}),t.message.success(z?"更新成功":"创建成功"),m(!1),G()}catch{}},A=()=>{x(null),D.resetFields(),D.setFieldsValue({status:"ACTIVE"}),v(!0)},k=async()=>{try{const p=await D.validateFields();if(a===ut){n(S?a.map(y=>y.providerCode===S.providerCode?{...y,...p}:y):[...a,{...p}]),t.message.success(S?"更新成功":"创建成功"),v(!1);return}await te(S?"/llm-center/provider/update":"/llm-center/provider/create",{method:"POST",data:p}),t.message.success(S?"更新成功":"创建成功"),v(!1),G()}catch{}},_=p=>{const y=b===p.key,M=g[p.key]||0;return e.jsxs("div",{onClick:()=>f(p.key),style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",marginBottom:2,cursor:"pointer",borderRadius:8,borderLeft:y?`3px solid ${p.color}`:"3px solid transparent",background:y?p.bg:"transparent",transition:"all 0.2s"},onMouseEnter:E=>{y||(E.currentTarget.style.background="#f5f5f5")},onMouseLeave:E=>{y||(E.currentTarget.style.background="transparent")},children:[e.jsx("div",{style:{width:32,height:32,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:y?p.color:"#f0f0f0",color:y?"#fff":"#8c8c8c",fontSize:16,flexShrink:0,transition:"all 0.2s"},children:p.icon}),e.jsx("div",{style:{flex:1,minWidth:0},children:e.jsx("div",{style:{fontSize:13,fontWeight:y?600:400,color:y?"#262626":"#595959",lineHeight:1.4},children:p.title})}),e.jsx("span",{style:{fontSize:11,color:y?p.color:"#bababa",fontWeight:y?600:400,background:y?"#fff":"transparent",padding:"1px 7px",borderRadius:10},children:M})]},p.key)};return Ee.find(p=>p.key===b)||Ee[0],e.jsxs("div",{style:{display:"flex",gap:16,height:"calc(100vh - 180px)",padding:16},children:[e.jsxs(t.Card,{size:"small",style:{width:210,overflow:"auto",flexShrink:0,border:"none",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"},bodyStyle:{padding:"8px 0"},children:[e.jsx("div",{style:{padding:"8px 14px 4px",fontSize:12,color:"#8c8c8c",fontWeight:500},children:"能力分类"}),Ee.map(_)]}),e.jsxs("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column",gap:12},children:[e.jsx(t.Card,{size:"small",style:{flexShrink:0},bodyStyle:{padding:"10px 16px"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"#8c8c8c",marginRight:4,whiteSpace:"nowrap"},children:"供应商"}),e.jsx(t.Tag,{style:{cursor:"pointer",padding:"2px 10px",fontSize:12,borderRadius:16,margin:0},color:j?"default":"blue",onClick:()=>w(null),children:"全部"}),a.map(p=>e.jsx(t.Tag,{style:{cursor:"pointer",padding:"2px 10px",fontSize:12,borderRadius:16,margin:0},color:j===p.providerCode?P[p.providerType]||"blue":"default",onClick:()=>w(p.providerCode),children:p.providerName},p.providerCode)),e.jsx("div",{style:{flex:1}}),e.jsx(t.Button,{size:"small",type:"primary",ghost:!0,icon:e.jsx(l.PlusOutlined,{}),onClick:K,children:"新增模型"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ApiOutlined,{}),onClick:A,children:"新增供应商"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:G})]})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:T?e.jsx("div",{style:{textAlign:"center",padding:80},children:e.jsx(t.Spin,{size:"large"})}):C.length===0?e.jsx("div",{style:{textAlign:"center",padding:80},children:e.jsx(t.Empty,{description:"暂无匹配的模型"})}):e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(340px, 1fr))",gap:12},children:C.map(p=>{var E;const y=a.find(Q=>Q.providerCode===p.providerCode),M=Ee.find(Q=>Q.key===p.modelType);return e.jsx(t.Card,{size:"small",hoverable:!0,style:{borderRadius:8,borderTop:`3px solid ${(M==null?void 0:M.color)||"#d9d9d9"}`},bodyStyle:{padding:14},actions:[e.jsx(t.Tooltip,{title:"编辑模型",children:e.jsx(l.EditOutlined,{onClick:()=>O(p)})},"edit"),e.jsx(t.Tooltip,{title:"删除模型",children:e.jsx(l.DeleteOutlined,{style:{color:"#ff4d4f"},onClick:()=>V(p)})},"delete")],children:e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx("div",{style:{width:44,height:44,borderRadius:10,background:M?`linear-gradient(135deg, ${M.color}, ${M.color}dd)`:"#f0f0f0",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:M?e.jsx("span",{style:{color:"#fff",fontSize:20},children:M.icon}):e.jsx(l.GlobalOutlined,{style:{fontSize:20,color:"#fff"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:14,color:"#262626"},children:p.modelName||p.modelCode}),e.jsx("div",{style:{fontSize:12,color:"#8c8c8c",fontFamily:"monospace"},children:p.modelCode})]}),e.jsx(t.Tag,{color:p.status==="ACTIVE"?"green":"red",style:{borderRadius:20,fontSize:11,lineHeight:"20px",margin:0},children:p.status==="ACTIVE"?"正常":"禁用"})]}),e.jsxs("div",{style:{marginTop:8,display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsxs(t.Tag,{color:P[y==null?void 0:y.providerType]||"default",style:{fontSize:11,borderRadius:4},children:[e.jsx(l.GlobalOutlined,{style:{marginRight:4}}),(y==null?void 0:y.providerName)||p.providerCode]}),e.jsx(t.Tag,{style:{fontSize:11,borderRadius:4},children:((E=Ee.find(Q=>Q.key===p.modelType))==null?void 0:E.title)||p.modelType}),p.contextWindow>0&&e.jsxs(t.Tag,{style:{fontSize:11,borderRadius:4},children:[(p.contextWindow/1e3).toFixed(0),"K CTX"]})]}),p.description&&e.jsx("div",{style:{marginTop:6,fontSize:12,color:"#8c8c8c",lineHeight:1.5},children:p.description})]})]})},p.id||p.modelCode)})})})]}),e.jsx(t.Modal,{title:z?"编辑模型":"新增模型",open:h,onOk:U,onCancel:()=>m(!1),width:640,children:e.jsxs(t.Form,{form:N,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelCode",label:"模型编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: qwen2.5:72b, gpt-4o",disabled:!!z})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelName",label:"模型名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Qwen 2.5 72B"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerCode",label:"所属供应商",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择供应商",children:a.map(p=>e.jsx(t.Select.Option,{value:p.providerCode,children:p.providerName},p.providerCode))})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelType",label:"能力类型",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择能力分类",children:Ee.map(p=>e.jsx(t.Select.Option,{value:p.key,children:e.jsxs(t.Space,{children:[e.jsx("span",{style:{color:p.color},children:p.icon}),p.title]})},p.key))})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"contextWindow",label:"上下文窗口 (tokens)",children:e.jsx(t.InputNumber,{style:{width:"100%"},placeholder:"如: 4096",min:0})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"禁用"})]})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"inputPrice",label:"输入价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"outputPrice",label:"输出价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"模型描述..."})})]})}),e.jsx(t.Modal,{title:S?"编辑供应商":"新增供应商",open:u,onOk:k,onCancel:()=>v(!1),width:560,children:e.jsxs(t.Form,{form:D,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerCode",label:"供应商编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: ollama, openai",disabled:!!S})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerName",label:"供应商名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Ollama, OpenAI"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerType",label:"类型",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择类型",children:Ls.map(p=>e.jsx(t.Select.Option,{value:p.value,children:p.label},p.value))})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"禁用"})]})})})]}),e.jsx(t.Divider,{style:{margin:"8px 0",fontSize:12,color:"#8c8c8c"},children:"连接配置"}),e.jsx(t.Form.Item,{name:"baseUrl",label:"Base URL",rules:[{required:!0}],tooltip:"标准供应商自动填充地址;自定义/Ollama 需手动填写",children:e.jsx(t.Input,{placeholder:"如: http://localhost:11434"})}),e.jsx(t.Form.Item,{name:"apiKey",label:"API Key",tooltip:"系统级凭据,可在系统配置中统一管理。此字段仅用于展示,实际运行时从环境变量读取",children:e.jsx(t.Input.Password,{placeholder:"可选,建议通过系统配置管理"})})]})})]})},{confirm:_s}=t.Modal,Us=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(!1),[T,d]=s.useState(!1),[b,f]=s.useState(null),[j]=t.Form.useForm(),w=async()=>{n(!0);try{const v=await te("/llm-center/provider/list",{method:"GET"}),S=Array.isArray(v)?v:(v==null?void 0:v.data)||[];i(S)}catch{t.message.error("加载失败")}finally{n(!1)}};s.useEffect(()=>{w()},[]);const h=()=>{f(null),j.resetFields(),d(!0)},m=v=>{f(v),j.setFieldsValue(v),d(!0)},z=async v=>{_s({title:"确认删除",content:`删除供应商 ${v.providerName} ?`,onOk:async()=>{await te("/llm-center/provider/delete",{method:"POST",data:{id:v.id}}),t.message.success("删除成功"),w()}})},F=async()=>{try{const v=await j.validateFields();await te(b?"/llm-center/provider/update":"/llm-center/provider/create",{method:"POST",data:v}),t.message.success(b?"更新成功":"创建成功"),d(!1),w()}catch{}},N={ollama:"blue",openai:"green",azure:"purple",anthropic:"orange"},u=[{title:"供应商",render:(v,S)=>e.jsxs(t.Space,{children:[e.jsx(l.GlobalOutlined,{style:{fontSize:20,color:N[S.providerCode]||"blue"}}),e.jsxs("div",{children:[e.jsx("div",{children:e.jsx("strong",{children:S.providerName})}),e.jsx("div",{style:{fontSize:12,color:"#999"},children:S.providerCode})]})]})},{title:"类型",dataIndex:"providerType",render:v=>e.jsx(t.Tag,{color:N[v]||"default",children:v==null?void 0:v.toUpperCase()})},{title:"Base URL",dataIndex:"baseUrl",ellipsis:!0},{title:"模型数量",dataIndex:"modelCount",render:v=>e.jsx(t.Tag,{children:v||0})},{title:"状态",dataIndex:"status",render:v=>e.jsx(t.Tag,{color:v==="ACTIVE"?"green":"red",children:v==="ACTIVE"?"正常":"异常"})},{title:"操作",width:150,render:(v,S)=>e.jsxs(t.Space,{children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>m(S),children:"编辑"}),e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>z(S),children:"删除"})]})}];return e.jsxs("div",{children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"供应商数",value:o.length})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"活跃模型",value:o.reduce((v,S)=>v+(S.modelCount||0),0)})})})]}),e.jsx("div",{style:{marginBottom:16},children:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:h,children:"添加供应商"})}),e.jsx(t.Table,{columns:u,dataSource:o,loading:a,rowKey:"id"}),e.jsx(t.Modal,{title:b?"编辑供应商":"添加供应商",open:T,onOk:F,onCancel:()=>d(!1),width:500,children:e.jsxs(t.Form,{form:j,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"providerCode",label:"供应商编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: ollama, openai, azure",disabled:!!b})}),e.jsx(t.Form.Item,{name:"providerName",label:"供应商名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Ollama, OpenAI"})}),e.jsx(t.Form.Item,{name:"providerType",label:"类型",rules:[{required:!0}],children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ollama",children:"Ollama"}),e.jsx(t.Select.Option,{value:"openai",children:"OpenAI"}),e.jsx(t.Select.Option,{value:"azure",children:"Azure OpenAI"}),e.jsx(t.Select.Option,{value:"anthropic",children:"Anthropic"})]})}),e.jsx(t.Form.Item,{name:"baseUrl",label:"Base URL",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: http://localhost:11434"})}),e.jsx(t.Form.Item,{name:"apiKey",label:"API Key",children:e.jsx(t.Input.Password,{placeholder:"可选,部分供应商需要"})}),e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"异常"})]})})]})})]})},{confirm:Ws}=t.Modal,Vs=()=>{const[o,i]=s.useState([]),[a,n]=s.useState([]),[T,d]=s.useState(!1),[b,f]=s.useState(!1),[j,w]=s.useState(null),[h]=t.Form.useForm(),m=async()=>{d(!0);try{const x=await te("/llm-center/model/list",{method:"GET"}),D=Array.isArray(x)?x:(x==null?void 0:x.data)||[];i(D)}catch{t.message.error("加载失败")}finally{d(!1)}},z=async()=>{try{const x=await te("/llm-center/provider/list",{method:"GET"}),D=Array.isArray(x)?x:(x==null?void 0:x.data)||[];n(D)}catch{}};s.useEffect(()=>{m(),z()},[]);const F=()=>{w(null),h.resetFields(),h.setFieldsValue({status:"ACTIVE",contextWindow:4096}),f(!0)},N=x=>{w(x),h.setFieldsValue(x),f(!0)},u=async x=>{Ws({title:"确认删除",content:`删除模型 ${x.modelName} ?`,onOk:async()=>{await te("/llm-center/model/delete",{method:"POST",data:{id:x.id}}),t.message.success("删除成功"),m()}})},v=async()=>{try{const x=await h.validateFields();await te(j?"/llm-center/model/update":"/llm-center/model/create",{method:"POST",data:x}),t.message.success(j?"更新成功":"创建成功"),f(!1),m()}catch{}},S=[{title:"模型编码",dataIndex:"modelCode",width:120},{title:"模型名称",dataIndex:"modelName",width:150},{title:"供应商",dataIndex:"providerCode",render:x=>e.jsx(t.Tag,{children:x})},{title:"上下文窗口",dataIndex:"contextWindow",render:x=>x?`${x.toLocaleString()} tokens`:"-"},{title:"输入价格",dataIndex:"inputPrice",render:x=>x?`¥${x}/千token`:"-"},{title:"输出价格",dataIndex:"outputPrice",render:x=>x?`¥${x}/千token`:"-"},{title:"状态",dataIndex:"status",render:x=>e.jsx(t.Tag,{color:x==="ACTIVE"?"green":"red",children:x==="ACTIVE"?"正常":"禁用"})},{title:"操作",width:150,render:(x,D)=>e.jsxs(t.Space,{children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>N(D),children:"编辑"}),e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>u(D),children:"删除"})]})}];return e.jsxs("div",{children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"模型总数",value:o.length})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"活跃模型",value:o.filter(x=>x.status==="ACTIVE").length})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"总上下文",value:o.reduce((x,D)=>x+(D.contextWindow||0),0).toLocaleString(),suffix:"tokens"})})})]}),e.jsx("div",{style:{marginBottom:16},children:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:F,children:"添加模型"})}),e.jsx(t.Table,{columns:S,dataSource:o,loading:T,rowKey:"id"}),e.jsx(t.Modal,{title:j?"编辑模型":"添加模型",open:b,onOk:v,onCancel:()=>f(!1),width:600,children:e.jsxs(t.Form,{form:h,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelCode",label:"模型编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: qwen2.5, gpt-4o",disabled:!!j})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelName",label:"模型名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Qwen 2.5 72B"})})})]}),e.jsx(t.Form.Item,{name:"providerCode",label:"供应商",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择供应商",children:a.map(x=>e.jsx(t.Select.Option,{value:x.providerCode,children:x.providerName},x.providerCode))})}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"contextWindow",label:"上下文窗口 (tokens)",children:e.jsx(t.InputNumber,{style:{width:"100%"},placeholder:"如: 4096"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"禁用"})]})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"inputPrice",label:"输入价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6,placeholder:"如: 0.001"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"outputPrice",label:"输出价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6,placeholder:"如: 0.002"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"模型描述..."})})]})})]})},{Text:Ut}=t.Typography,Wt=o=>o?Number(o).toFixed(4):"0.0000",Vt=({open:o,ak:i,onClose:a})=>{const[n,T]=s.useState(null),[d,b]=s.useState([]),[f,j]=s.useState([]),[w,h]=s.useState(!1);s.useEffect(()=>{!o||!i||m()},[o,i]);const m=async()=>{var u,v;h(!0);try{const[S,x,D]=await Promise.allSettled([te("/llm-gateway/usage/overview",{method:"GET",params:{accessKey:i.accessKey}}),te("/llm-gateway/usage/trend",{method:"GET",params:{accessKey:i.accessKey,days:7}}),te("/llm-gateway/usage/records",{method:"GET",params:{accessKey:i.accessKey,page:1,size:20}})]);T(S.status==="fulfilled"&&(((u=S.value)==null?void 0:u.data)||S.value)||null),b(x.status==="fulfilled"?Array.isArray(x.value)?x.value:((v=x.value)==null?void 0:v.data)||[]:[]);const G=D.status==="fulfilled"?D.value:null;j(G?Array.isArray(G)?G:G.records||G.data||[]:[])}catch{}finally{h(!1)}},z=(u,v)=>{navigator.clipboard.writeText(u),message.success(`${v} 已复制`)},F={tooltip:{trigger:"axis"},legend:{data:["Token消耗","调用次数"]},grid:{top:40,right:40,bottom:30,left:50},xAxis:{type:"category",data:d.map(u=>u.date||u.statDate||"")},yAxis:[{type:"value",name:"Tokens",position:"left"},{type:"value",name:"调用次数",position:"right"}],series:[{name:"Token消耗",type:"bar",data:d.map(u=>u.dailyTokens||u.totalTokens||0)},{name:"调用次数",type:"line",yAxisIndex:1,data:d.map(u=>u.dailyCalls||u.totalCalls||0)}]},N=[{title:"时间",dataIndex:"gmtCreate",width:160},{title:"应用",dataIndex:"appCode",render:u=>u?e.jsx(t.Tag,{color:"blue",children:u}):"-"},{title:"用户",dataIndex:"userName",render:u=>u||"-"},{title:"供应商",dataIndex:"providerCode",render:u=>u?e.jsx(t.Tag,{color:"purple",children:u}):"-"},{title:"模型",dataIndex:"modelCode",render:u=>u?e.jsx(t.Tag,{children:u}):"-"},{title:"输入Token",dataIndex:"inputTokens",render:u=>(u==null?void 0:u.toLocaleString())||"-"},{title:"输出Token",dataIndex:"outputTokens",render:u=>(u==null?void 0:u.toLocaleString())||"-"},{title:"状态",dataIndex:"status",render:u=>e.jsx(t.Tag,{color:u==="SUCCESS"?"green":"red",children:u||"-"})},{title:"费用",dataIndex:"totalCost",render:u=>e.jsxs(Ut,{style:{color:"#faad14"},children:["¥",u||"0.0000"]})}];return e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx("span",{children:"用量详情 ·"}),e.jsx(Ut,{strong:!0,children:i==null?void 0:i.akName}),(i==null?void 0:i.accessKey)&&e.jsxs(t.Space,{size:4,children:[e.jsx("code",{style:{fontSize:12,color:"#595959",background:"#f5f5f5",padding:"2px 6px",borderRadius:4},children:i.accessKey}),e.jsx(l.CopyOutlined,{style:{cursor:"pointer",color:"#1677ff"},onClick:()=>z(i.accessKey,"AccessKey")})]})]}),open:o,onClose:a,width:820,destroyOnClose:!0,children:e.jsxs(t.Spin,{spinning:w,children:[e.jsxs(t.Row,{gutter:12,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"累计 Token",value:(n==null?void 0:n.totalTokens)||0,prefix:e.jsx(l.ThunderboltOutlined,{style:{color:"#667eea"}}),formatter:u=>Number(u).toLocaleString(),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"累计费用",value:Wt(n==null?void 0:n.totalCost),prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"今日 Token",value:(n==null?void 0:n.todayTokens)||0,prefix:e.jsx(l.ClockCircleOutlined,{style:{color:"#52c41a"}}),formatter:u=>Number(u).toLocaleString(),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"今日费用",value:Wt(n==null?void 0:n.todayCost),prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),valueStyle:{fontSize:18}})})})]}),e.jsx(t.Divider,{style:{margin:"12px 0"}}),e.jsxs(t.Tabs,{defaultActiveKey:"trend",size:"small",children:[e.jsx(t.Tabs.TabPane,{tab:"用量趋势",icon:e.jsx(l.BarChartOutlined,{}),children:e.jsx(t.Card,{size:"small",bodyStyle:{padding:12},children:d.length>0?e.jsx(Pt,{option:F,style:{height:300}}):e.jsx(t.Empty,{description:"该 AK 暂无用量数据",style:{padding:"40px 0"}})})},"trend"),e.jsx(t.Tabs.TabPane,{tab:"调用明细",icon:e.jsx(l.ApiOutlined,{}),children:e.jsx(t.Table,{columns:N,dataSource:f,rowKey:"id",size:"small",pagination:{pageSize:20,showSizeChanger:!1},locale:{emptyText:e.jsx(t.Empty,{description:"暂无调用记录"})}})},"records")]})]})})},{confirm:Ks}=t.Modal,Kt="http://localhost:8888",Gt=o=>o?o>=1e6?(o/1e6).toFixed(1)+"M":o>=1e3?(o/1e3).toFixed(1)+"K":Number(o).toLocaleString():"0",Gs=()=>{const[o,i]=s.useState("PERSONAL"),[a,n]=s.useState([]),[T,d]=s.useState(!1),[b,f]=s.useState(!1),[j,w]=s.useState(null),[h]=t.Form.useForm(),[m,z]=s.useState(null),[F,N]=s.useState(null),[u,v]=s.useState([]),S=async()=>{d(!0);try{const A=await te("/ak/list",{method:"GET",params:{akType:o}});n(Array.isArray(A)?A:(A==null?void 0:A.data)||[])}catch{t.message.error("加载失败")}finally{d(!1)}},x=async()=>{try{const A=await te("/agent/app/page",{method:"POST",body:JSON.stringify({current:1,size:100})}),k=Array.isArray(A)?A:(A==null?void 0:A.records)||(A==null?void 0:A.data)||[];v(k.map(_=>({value:_.appCode,label:_.appName||_.appCode})))}catch{}};s.useEffect(()=>{S()},[o]),s.useEffect(()=>{x()},[]);const D=()=>{w(null),h.resetFields(),h.setFieldsValue({akType:o}),f(!0)},G=A=>{w(A),h.setFieldsValue({akName:A.akName,description:A.description,akType:A.akType||"PERSONAL",appCode:A.appCode,appName:A.appName}),f(!0)},g=A=>{Ks({title:"确认删除",content:`删除 AK「${A.akName}」?此操作不可恢复。`,okText:"删除",okType:"danger",onOk:async()=>{await te("/ak/delete",{method:"POST",params:{id:A.id}}),t.message.success("删除成功"),S()}})},C=async A=>{const k=A.status===1?0:1;await te("/ak/toggle",{method:"POST",params:{id:A.id,status:k}}),t.message.success(k===1?"已启用":"已禁用"),S()},P=async()=>{try{const A=await h.validateFields();if(j)await te("/ak/update",{method:"POST",data:{...A,id:j.id}}),t.message.success("更新成功"),f(!1),S();else{const k=await te("/ak/create",{method:"POST",data:A}),_=k!=null&&k.accessKey?k:(k==null?void 0:k.data)||{};f(!1),S(),z({akName:A.akName,accessKey:_.accessKey,secretKey:_.secretKey})}}catch{}},K=(A,k)=>{navigator.clipboard.writeText(A),t.message.success(`${k} 已复制`)},O=[{title:"名称",dataIndex:"akName",key:"akName",width:160,render:(A,k)=>e.jsxs(t.Space,{children:[e.jsx(l.KeyOutlined,{style:{color:"#1677ff"}}),e.jsx("span",{style:{fontWeight:500},children:A}),k.akType==="APP"&&k.appName&&e.jsx(t.Tag,{color:"purple",style:{borderRadius:10,fontSize:11},children:k.appName})]})},{title:"AccessKey",dataIndex:"accessKey",key:"accessKey",width:200,render:A=>e.jsxs(t.Space,{children:[e.jsx("code",{style:{fontFamily:"monospace",fontSize:12,color:"#595959",background:"#f5f5f5",padding:"3px 8px",borderRadius:4},children:A}),e.jsx(t.Tooltip,{title:"复制 AccessKey",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:k=>{k.stopPropagation(),K(A,"AccessKey")}})})]})},{title:"Token 消耗",dataIndex:"totalTokens",key:"totalTokens",width:110,sorter:(A,k)=>(A.totalTokens||0)-(k.totalTokens||0),render:A=>e.jsxs(t.Space,{children:[e.jsx(l.ThunderboltOutlined,{style:{color:"#faad14",fontSize:12}}),e.jsx("span",{style:{fontWeight:500},children:Gt(A)})]})},{title:"最后使用",dataIndex:"lastUsedTime",key:"lastUsedTime",width:160,render:A=>e.jsx(t.Space,{size:4,children:e.jsx("span",{style:{color:A?"#595959":"#bfbfbf",fontSize:13},children:A||"从未使用"})})},{title:"状态",dataIndex:"status",key:"status",width:70,render:A=>e.jsx(t.Tag,{color:A===1?"green":"red",style:{borderRadius:20},children:A===1?"正常":"禁用"})},{title:"描述",dataIndex:"description",key:"description",ellipsis:!0},{title:"创建时间",dataIndex:"createdTime",key:"createdTime",width:160},{title:"操作",key:"action",width:130,render:(A,k)=>e.jsxs(t.Space,{size:"small",onClick:_=>_.stopPropagation(),children:[e.jsx(t.Tooltip,{title:k.status===1?"禁用":"启用",children:e.jsx(t.Button,{size:"small",type:"text",icon:k.status===1?e.jsx(l.StopOutlined,{style:{color:"#faad14"}}):e.jsx(l.CheckCircleOutlined,{style:{color:"#52c41a"}}),onClick:()=>C(k)})}),e.jsx(t.Tooltip,{title:"编辑",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.KeyOutlined,{}),onClick:()=>G(k)})}),e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.DeleteOutlined,{style:{color:"#ff4d4f"}}),onClick:()=>g(k)})})]})}],V=a.reduce((A,k)=>A+(k.totalTokens||0),0),U=a.filter(A=>A.status===1).length;return e.jsxs("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:12},children:[e.jsx(t.Alert,{type:"info",showIcon:!0,icon:e.jsx(l.ApiOutlined,{}),message:e.jsxs(t.Space,{children:[e.jsx("span",{style:{fontWeight:500},children:"API 接入地址:"}),e.jsx("code",{style:{fontFamily:"monospace",fontSize:13,background:"#e6f4ff",padding:"2px 8px",borderRadius:4},children:Kt}),e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>K(Kt,"API 地址")}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:12},children:"使用此地址 + AccessKey 调用平台所有模型"})]}),style:{border:"none",background:"#e6f4ff"}}),e.jsxs(t.Row,{gutter:12,children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"AK 总数",value:a.length,prefix:e.jsx(l.KeyOutlined,{}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"累计 Token",value:Gt(V),prefix:e.jsx(l.ThunderboltOutlined,{}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"有效 AK",value:U,prefix:e.jsx(l.CheckCircleOutlined,{style:{color:"#52c41a"}}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"所属应用",value:new Set(a.map(A=>A.appCode).filter(Boolean)).size,prefix:e.jsx(l.AppstoreOutlined,{}),valueStyle:{fontSize:18}})})})]}),e.jsx(t.Card,{size:"small",styles:{body:{padding:0}},children:e.jsx(t.Tabs,{activeKey:o,onChange:i,size:"small",tabBarStyle:{margin:0,padding:"0 16px"},tabBarExtraContent:e.jsxs(t.Space,{style:{padding:"8px 0"},children:[e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:D,size:"small",children:o==="PERSONAL"?"申请个人 AK":"申请应用 AK"}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:S,size:"small"})]}),items:[{key:"PERSONAL",label:e.jsxs(t.Space,{children:[e.jsx(l.UserOutlined,{}),"个人 AK"]}),children:e.jsx(t.Spin,{spinning:T,children:e.jsx(t.Table,{dataSource:a,columns:O,rowKey:"id",pagination:!1,size:"small",onRow:A=>({onClick:()=>N(A),style:{cursor:"pointer"}}),locale:{emptyText:'暂无个人 AK,点右上角"申请个人 AK"创建'}})})},{key:"APP",label:e.jsxs(t.Space,{children:[e.jsx(l.AppstoreOutlined,{}),"应用 AK"]}),children:e.jsx(t.Spin,{spinning:T,children:e.jsx(t.Table,{dataSource:a,columns:O,rowKey:"id",pagination:!1,size:"small",onRow:A=>({onClick:()=>N(A),style:{cursor:"pointer"}}),locale:{emptyText:'暂无应用 AK,点右上角"申请应用 AK"并绑定一个应用'}})})}]})}),e.jsx(t.Modal,{title:j?"编辑 AK":o==="APP"?"申请应用 AK":"申请个人 AK",open:b,onOk:P,onCancel:()=>f(!1),width:520,okText:j?"保存":"申请",destroyOnClose:!0,children:e.jsxs(t.Form,{form:h,layout:"vertical",preserve:!1,children:[e.jsx(t.Form.Item,{name:"akType",label:"AK 类型",rules:[{required:!0}],children:e.jsxs(t.Radio.Group,{disabled:!!j,children:[e.jsx(t.Radio.Button,{value:"PERSONAL",children:"个人 AK"}),e.jsx(t.Radio.Button,{value:"APP",children:"应用 AK"})]})}),e.jsx(t.Form.Item,{shouldUpdate:(A,k)=>A.akType!==k.akType,noStyle:!0,children:()=>h.getFieldValue("akType")==="APP"&&e.jsx(t.Form.Item,{name:"appCode",label:"所属应用",rules:[{required:!0,message:"应用 AK 必须绑定一个应用"}],children:e.jsx(t.Select,{showSearch:!0,optionFilterProp:"label",placeholder:"选择应用",options:u})})}),e.jsx(t.Form.Item,{name:"akName",label:"名称",rules:[{required:!0,message:"请输入 AK 名称"}],children:e.jsx(t.Input,{placeholder:o==="APP"?"如:生产环境-订单服务":"如:本地调试"})}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"密钥用途..."})}),!j&&e.jsx(t.Alert,{type:"info",showIcon:!0,message:"AccessKey 和 SecretKey 将由系统自动生成。SecretKey 仅在创建时展示一次,请妥善保管。",style:{background:"#e6f4ff",border:"none"}})]})}),e.jsx(t.Modal,{title:"AK 创建成功",open:!!m,onCancel:()=>z(null),footer:e.jsx(t.Button,{type:"primary",onClick:()=>z(null),children:"我已保存,关闭"}),width:520,children:m&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"warning",showIcon:!0,message:"SecretKey 仅在此展示一次,关闭后将无法再次查看。请立即复制并妥善保管。",style:{marginBottom:16}}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,color:"#8c8c8c",marginBottom:4},children:"AccessKey"}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1,fontFamily:"monospace",fontSize:14,padding:"8px 12px",background:"#f5f5f5",borderRadius:6,border:"1px solid #d9d9d9"},children:m.accessKey}),e.jsx(t.Button,{icon:e.jsx(l.CopyOutlined,{}),onClick:()=>K(m.accessKey,"AccessKey"),children:"复制"})]})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,color:"#8c8c8c",marginBottom:4},children:"SecretKey"}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1,fontFamily:"monospace",fontSize:14,padding:"8px 12px",background:"#fff7e6",borderRadius:6,border:"1px solid #ffd591",color:"#d46b08"},children:m.secretKey}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>K(m.secretKey,"SecretKey"),children:"复制"})]})]}),e.jsx("div",{style:{fontSize:12,color:"#ff4d4f",marginTop:8},children:"⚠ 请立即复制 SecretKey,此弹窗关闭后将无法再次获取。如遗失,请删除后重新申请。"})]})}),e.jsx(Vt,{open:!!F,ak:F,onClose:()=>N(null)})]})},{TextArea:Ht}=t.Input,{Text:Oe}=t.Typography;function Hs(){var E,Q;const[o,i]=s.useState("servers"),[a,n]=s.useState([]),[T,d]=s.useState(!1),[b,f]=s.useState(!1),[j,w]=s.useState(null),[h]=t.Form.useForm(),[m,z]=s.useState(null),[F,N]=s.useState([]),[u,v]=s.useState(null),[S,x]=s.useState("{}"),[D,G]=s.useState(""),[g,C]=s.useState(!1),[P,K]=s.useState(null);s.useEffect(()=>{O()},[]);const O=async()=>{d(!0);try{const c=localStorage.getItem("z_tenant")||"default",r=await Ie.list(c);n(Array.isArray(r)?r:(r==null?void 0:r.data)||r||[])}catch(c){console.warn("MCP API 不可用:",c==null?void 0:c.message),n([])}finally{d(!1)}},V=async()=>{try{const r={...await h.validateFields()};j?(r.id=j.id,await Ie.update(r),t.message.success("更新成功")):(await Ie.create(r),t.message.success("创建成功")),f(!1),w(null),h.resetFields(),O()}catch{}},U=c=>{w(c),h.setFieldsValue(c),f(!0)},A=async c=>{await Ie.delete(c),t.message.success("已删除"),O()},k=async c=>{K({loading:!0});try{const r=await Ie.test(c.id);K((r==null?void 0:r.data)||r)}catch(r){K({connected:!1,error:r.message})}},_=async c=>{z(c),v(null),G("");try{const r=await Ie.listTools(c.id),L=(r==null?void 0:r.data)||r;N((L==null?void 0:L.tools)||[])}catch{N([]),t.message.error("获取工具列表失败")}},p=c=>{v(c);const r=c.inputSchema;if(r!=null&&r.properties){const L={};Object.keys(r.properties).forEach($=>{L[$]=""}),x(JSON.stringify(L,null,2))}else x("{}");G("")},y=async()=>{if(!(!m||!u)){C(!0),G("Running...");try{let c={};try{c=JSON.parse(S)}catch{}const r=await Ie.callTool(m.id,u.name,c),L=(r==null?void 0:r.data)||r;L!=null&&L.content&&L.content.length>0?G(L.content[0].text||JSON.stringify(L.content,null,2)):G(JSON.stringify(L,null,2))}catch(c){G("Error: "+c.message)}finally{C(!1)}}},M=[{title:"名称",dataIndex:"serverName",key:"serverName",width:140},{title:"类型",dataIndex:"transportType",key:"transportType",width:80,render:c=>e.jsx(t.Tag,{color:c==="STDIO"?"purple":"blue",children:c||"HTTP"})},{title:"URL",dataIndex:"url",key:"url",ellipsis:!0},{title:"状态",dataIndex:"status",key:"status",width:80,render:c=>e.jsx(t.Tag,{color:c==="active"?"green":"default",children:c||"active"})},{title:"操作",key:"actions",width:260,render:(c,r)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.ApiOutlined,{}),onClick:()=>_(r),children:"工具"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.LinkOutlined,{}),onClick:()=>k(r),children:"测试"}),e.jsx(t.Button,{size:"small",onClick:()=>U(r),children:"编辑"}),e.jsx(t.Popconfirm,{title:"确认删除?",onConfirm:()=>A(r.id),children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{style:{height:"calc(100vh - 180px)",display:"flex",flexDirection:"column"},children:[e.jsxs(t.Tabs,{activeKey:o,onChange:i,tabBarExtraContent:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>{w(null),h.resetFields(),f(!0)},children:"添加服务"}),children:[e.jsx(t.Tabs.TabPane,{tab:"服务管理"},"servers"),e.jsx(t.Tabs.TabPane,{tab:"工具测试",disabled:!m},"test")]}),o==="servers"&&e.jsxs("div",{style:{flex:1,display:"flex",gap:16,overflow:"hidden"},children:[e.jsx("div",{style:{flex:m?"0 0 50%":1,overflow:"auto"},children:e.jsx(t.Table,{columns:M,dataSource:a,rowKey:"id",loading:T,size:"small",pagination:!1,onRow:c=>({onClick:()=>_(c),style:{background:(m==null?void 0:m.id)===c.id?"#e6f7ff":void 0,cursor:"pointer"}})})}),m&&e.jsxs("div",{style:{flex:"0 0 50%",borderLeft:"1px solid #f0f0f0",paddingLeft:16,overflow:"auto"},children:[e.jsxs("div",{style:{marginBottom:12,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(Oe,{strong:!0,style:{fontSize:15},children:[m.serverName," — 工具列表"]}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>_(m),children:"刷新"})]}),F.length===0?e.jsx("div",{style:{textAlign:"center",padding:40,color:"#999"},children:"暂无工具"}):F.map(c=>e.jsx(t.Card,{size:"small",hoverable:!0,style:{marginBottom:8,borderColor:(u==null?void 0:u.name)===c.name?"#1890ff":void 0},onClick:()=>{p(c),i("test")},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx(Oe,{strong:!0,children:c.name}),e.jsx("br",{}),e.jsx(Oe,{type:"secondary",style:{fontSize:12},children:c.description})]}),e.jsx(t.Tag,{color:"blue",style:{cursor:"pointer"},onClick:r=>{r.stopPropagation(),p(c),i("test")},children:"测试 →"})]})},c.name))]})]}),o==="test"&&u&&e.jsxs("div",{style:{flex:1,display:"flex",gap:16,overflow:"hidden"},children:[e.jsxs("div",{style:{flex:"0 0 40%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{marginBottom:8},children:[e.jsx(Oe,{strong:!0,children:u.name}),e.jsx(Oe,{type:"secondary",style:{marginLeft:8},children:u.description})]}),e.jsx(Oe,{type:"secondary",style:{marginBottom:4},children:"参数 (JSON):"}),e.jsx(Ht,{rows:8,value:S,onChange:c=>x(c.target.value),style:{fontFamily:"monospace",fontSize:13}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:y,loading:g,style:{marginTop:12},children:"执行"})]}),e.jsxs("div",{style:{flex:"0 0 60%",display:"flex",flexDirection:"column"},children:[e.jsx(Oe,{type:"secondary",style:{marginBottom:4},children:"结果:"}),e.jsx("pre",{style:{flex:1,overflow:"auto",background:"#f5f5f5",padding:12,borderRadius:4,fontFamily:"monospace",fontSize:13,margin:0,whiteSpace:"pre-wrap"},children:D||'点击"执行"查看结果'})]})]}),e.jsx(t.Modal,{title:"测试连接 - ",open:!!P,onCancel:()=>K(null),footer:e.jsx(t.Button,{onClick:()=>K(null),children:"关闭"}),children:P!=null&&P.loading?e.jsx(Oe,{children:"测试中..."}):P?e.jsxs(t.Descriptions,{column:1,size:"small",children:[e.jsx(t.Descriptions.Item,{label:"连接状态",children:e.jsx(t.Tag,{color:P.connected?"green":"red",children:P.connected?"成功":"失败"})}),P.serverInfo&&e.jsxs(t.Descriptions.Item,{label:"服务信息",children:[(E=P.serverInfo)==null?void 0:E.name," v",(Q=P.serverInfo)==null?void 0:Q.version]}),P.toolCount!==void 0&&e.jsx(t.Descriptions.Item,{label:"工具数量",children:P.toolCount}),P.error&&e.jsx(t.Descriptions.Item,{label:"错误",children:P.error})]}):null}),e.jsx(t.Modal,{title:j?"编辑 MCP 服务":"添加 MCP 服务",open:b,onOk:V,onCancel:()=>{f(!1),w(null),h.resetFields()},children:e.jsxs(t.Form,{form:h,layout:"vertical",initialValues:{transportType:"HTTP",timeout:60,status:"active"},children:[e.jsx(t.Form.Item,{name:"serverName",label:"服务名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: z-agent-mcp-impl-db"})}),e.jsx(t.Form.Item,{name:"transportType",label:"传输类型",children:e.jsx(t.Select,{options:[{label:"HTTP",value:"HTTP"},{label:"STDIO",value:"STDIO"}]})}),e.jsx(t.Form.Item,{name:"url",label:"URL",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"http://localhost:8095/mcp"})}),e.jsx(t.Form.Item,{name:"authToken",label:"Auth Token",children:e.jsx(t.Input.Password,{placeholder:"Bearer token (可选)"})}),e.jsx(t.Form.Item,{name:"timeout",label:"超时(秒)",children:e.jsx(t.InputNumber,{min:5,max:300,style:{width:"100%"}})}),e.jsx(t.Form.Item,{name:"status",label:"状态",children:e.jsx(t.Select,{options:[{label:"启用",value:"active"},{label:"停用",value:"inactive"}]})}),e.jsx(t.Form.Item,{name:"remark",label:"备注",children:e.jsx(Ht,{rows:2})})]})})]})}const Re={private:{label:"私有",color:"default",icon:e.jsx(l.LockOutlined,{})},"public-read":{label:"公共读",color:"blue",icon:e.jsx(l.EyeOutlined,{})},"public-read-write":{label:"公共读写",color:"orange",icon:e.jsx(l.GlobalOutlined,{})},"authenticated-read":{label:"认证读",color:"purple",icon:e.jsx(l.TeamOutlined,{})}};function Js(){const[o,i]=s.useState([]),[a,n]=s.useState(!1),[T,d]=s.useState(!1),[b]=t.Form.useForm(),[f,j]=s.useState(!1),w=Ve.useNavigate(),h=s.useCallback(async()=>{n(!0);try{const u=await me.listBuckets(),v=Array.isArray(u)?u:(u==null?void 0:u.data)||[];i(v)}catch(u){console.error("loadBuckets error:",u),t.message.error("加载桶列表失败:"+((u==null?void 0:u.message)||"未知错误"))}finally{n(!1)}},[]);s.useEffect(()=>{h()},[h]);const m=async()=>{try{const u=await b.validateFields();j(!0),await me.createBucket(u),t.message.success("桶创建成功"),d(!1),b.resetFields(),h()}catch(u){if(u!=null&&u.errorFields)return;t.message.error("创建失败:"+((u==null?void 0:u.message)||"未知错误"))}finally{j(!1)}},z=async u=>{try{await me.deleteBucket(u),t.message.success("已删除"),h()}catch(v){t.message.error("删除失败:"+((v==null?void 0:v.message)||"未知错误"))}},F=async(u,v)=>{try{await me.setBucketAcl(u,v),t.message.success("ACL 已更新"),h()}catch(S){t.message.error("设置 ACL 失败:"+((S==null?void 0:S.message)||"未知错误"))}},N=u=>({items:Object.keys(Re).map(v=>({key:v,label:Re[v].label,icon:Re[v].icon})),onClick:({key:v})=>F(u,v)});return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,background:"#fff",padding:"14px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)",marginBottom:16},children:[e.jsx(l.DatabaseOutlined,{style:{fontSize:18,color:"#1890ff"}}),e.jsx("span",{style:{fontSize:16,fontWeight:600},children:"对象存储"}),e.jsx(t.Tag,{color:"blue",children:"OSS Buckets"}),e.jsx("div",{style:{flex:1}}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:h,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>d(!0),children:"创建桶"})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"桶总数",value:o.length,prefix:e.jsx(l.ApartmentOutlined,{style:{color:"#1890ff"}})})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"公共读",value:o.filter(u=>u.acl==="public-read").length,valueStyle:{color:"#1890ff"},prefix:e.jsx(l.EyeOutlined,{})})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"私有",value:o.filter(u=>!u.acl||u.acl==="private").length,valueStyle:{color:"#999"},prefix:e.jsx(l.LockOutlined,{})})})})]}),a?e.jsx("div",{style:{textAlign:"center",padding:80},children:e.jsx(t.Spin,{size:"large"})}):o.length===0?e.jsx(t.Empty,{image:e.jsx(l.CloudOutlined,{style:{fontSize:64,color:"#bfbfbf"}}),description:e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,marginBottom:8},children:"还没有桶"}),e.jsx("div",{style:{color:"#999",fontSize:13,marginBottom:16},children:"创建一个桶来开始使用对象存储"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>d(!0),children:"创建第一个桶"})]}),style:{padding:80,background:"#fff",borderRadius:10}}):e.jsx(t.Row,{gutter:[16,16],children:o.map(u=>{var S;const v=Re[u.acl]||Re.private;return e.jsx(t.Col,{xs:24,sm:12,md:8,lg:6,children:e.jsxs(t.Card,{hoverable:!0,onClick:()=>w(`/ai/oss/bucket/${encodeURIComponent(u.name)}`),style:{borderRadius:12,border:"none",boxShadow:"0 2px 12px rgba(0,0,0,0.07)"},styles:{body:{padding:18}},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:10,background:"linear-gradient(135deg, #1890ff 0%, #36cfc9 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.FolderOutlined,{style:{fontSize:22,color:"#fff"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:15,fontWeight:600,color:"#262626",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.name}),e.jsxs("div",{style:{fontSize:12,color:"#999",marginTop:4},children:[u.region||"default"," · ",((S=u.createTime)==null?void 0:S.slice(0,10))||"-"]})]}),e.jsx(t.Dropdown,{trigger:["click"],menu:N(u.name),onClick:x=>x.stopPropagation(),children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.MoreOutlined,{}),onClick:x=>x.stopPropagation()})})]}),e.jsx("div",{style:{marginTop:14,display:"flex",gap:6,flexWrap:"wrap"},children:e.jsx(t.Tag,{color:v.color,icon:v.icon,children:v.label})}),e.jsxs("div",{style:{marginTop:14,paddingTop:12,borderTop:"1px solid #f5f5f5",display:"flex",gap:8,justifyContent:"space-between"},children:[e.jsx(t.Tooltip,{title:"进入桶",children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.AppstoreOutlined,{}),onClick:x=>{x.stopPropagation(),w(`/ai/oss/bucket/${encodeURIComponent(u.name)}`)},children:"浏览对象"})}),e.jsx(t.Popconfirm,{title:`确定删除桶 "${u.name}"?`,description:"桶必须为空才能删除",onConfirm:x=>{x==null||x.stopPropagation(),z(u.name)},onCancel:x=>x==null?void 0:x.stopPropagation(),okText:"确认",cancelText:"取消",okType:"danger",children:e.jsx(t.Button,{type:"text",size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:x=>x.stopPropagation(),children:"删除"})})]})]})},u.id||u.name)})}),e.jsx(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(l.CloudOutlined,{style:{color:"#1890ff"}}),e.jsx("span",{children:"创建存储桶"})]}),open:T,onCancel:()=>{d(!1),b.resetFields()},onOk:m,confirmLoading:f,okText:"创建",cancelText:"取消",destroyOnClose:!0,children:e.jsxs(t.Form,{form:b,layout:"vertical",initialValues:{acl:"private"},style:{marginTop:16},children:[e.jsx(t.Form.Item,{name:"name",label:"桶名称",rules:[{required:!0,message:"请输入桶名称"},{pattern:/^[a-z0-9][a-z0-9-]{2,62}[a-z0-9]$/,message:"只能包含小写字母、数字、连字符,长度 3-63"}],extra:"仅支持小写字母、数字、连字符,长度 3-63 字符",children:e.jsx(t.Input,{placeholder:"my-bucket",prefix:e.jsx(l.FolderOutlined,{})})}),e.jsx(t.Form.Item,{name:"region",label:"区域",initialValue:"default",children:e.jsx(t.Input,{placeholder:"default"})}),e.jsx(t.Form.Item,{name:"acl",label:"访问权限",initialValue:"private",children:e.jsx(t.Select,{options:Object.entries(Re).map(([u,v])=>({value:u,label:e.jsxs(t.Space,{children:[v.icon,v.label]})}))})})]})})]})}const Jt=o=>{if(!o||o===0)return"-";const i=["B","KB","MB","GB","TB"];let a=0,n=o;for(;n>=1024&&a<i.length-1;)n/=1024,a++;return n.toFixed(a===0?0:1)+" "+i[a]},Ys=o=>{var a;if(o.endsWith("/"))return e.jsx(l.FolderOutlined,{style:{color:"#faad14"}});const i=(a=o.split(".").pop())==null?void 0:a.toLowerCase();return["zip","tar","gz","rar","7z"].includes(i)?e.jsx(l.FileZipOutlined,{style:{color:"#722ed1"}}):["png","jpg","jpeg","gif","svg","webp"].includes(i)?e.jsx(l.FileImageOutlined,{style:{color:"#13c2c2"}}):["md","txt","log","json","xml","yaml","yml"].includes(i)?e.jsx(l.FileTextOutlined,{style:{color:"#52c41a"}}):e.jsx(l.FileOutlined,{style:{color:"#8c8c8c"}})};function Qs(){const{bucketName:o}=Ve.useParams(),i=decodeURIComponent(o||""),a=Ve.useNavigate(),[n,T]=s.useState([]),[d,b]=s.useState(!1),[f,j]=s.useState(""),[w,h]=s.useState({objectCount:0,totalSize:0}),[m,z]=s.useState(""),[F,N]=s.useState([]),[u,v]=s.useState(!1),[S,x]=s.useState(!1),[D]=t.Form.useForm();s.useRef(null);const G=s.useCallback(async(y=f)=>{if(i){b(!0);try{const M=await me.listObjects(i,y||void 0),E=Array.isArray(M)?M:(M==null?void 0:M.data)||[];T(E)}catch(M){t.message.error("加载对象失败:"+((M==null?void 0:M.message)||"未知错误")),T([])}finally{b(!1)}}},[i,f]),g=s.useCallback(async()=>{try{const y=await me.getBucketStats(i);h(y||{objectCount:0,totalSize:0})}catch{}},[i]);s.useEffect(()=>{j(""),N([])},[i]),s.useEffect(()=>{G(f),g()},[f,G,g]);const C=y=>{y.endsWith("/")&&(j(y),N([]))},P=y=>{j(y),N([])},K=async y=>{if(!y)return!1;v(!0);const M=(f||"")+y.name;try{await me.uploadObject(i,M,y),t.message.success(`已上传: ${y.name}`),G(f),g()}catch(E){t.message.error("上传失败:"+((E==null?void 0:E.message)||"未知错误"))}finally{v(!1)}return!1},O=async y=>{if(!(!y||y.length===0))try{y.length===1?await me.deleteObject(i,y[0]):await me.batchDelete(i,y),t.message.success(`已删除 ${y.length} 个`),N([]),G(f),g()}catch(M){t.message.error("删除失败:"+((M==null?void 0:M.message)||"未知错误"))}},V=async()=>{try{const y=await D.validateFields(),M=(f||"")+y.name+"/";await me.createFolder(i,M),t.message.success("文件夹已创建"),x(!1),D.resetFields(),G(f)}catch(y){if(y!=null&&y.errorFields)return;t.message.error("创建失败:"+((y==null?void 0:y.message)||"未知错误"))}},U=async y=>{try{const M=await me.presignedUrl(i,y,3600),E=(M==null?void 0:M.url)||me.downloadUrl(i,y);window.open(E,"_blank")}catch{window.open(me.downloadUrl(i,y),"_blank")}},A=async y=>{const M=(f||"")+"_copy_"+y.split("/").pop();try{await me.copyObject(i,y,i,M),t.message.success("已复制"),G(f)}catch(E){t.message.error("复制失败:"+((E==null?void 0:E.message)||"未知错误"))}},k=m?n.filter(y=>{var M;return(M=y.key)==null?void 0:M.toLowerCase().includes(m.toLowerCase())}):n,_=[{title:"名称",dataIndex:"key",render:(y,M)=>{const E=(y==null?void 0:y.endsWith("/"))||M.folder,Q=(y==null?void 0:y.split("/").filter(Boolean).pop())||y;return e.jsx("span",{style:{cursor:E?"pointer":"default",color:E?"#faad14":"#262626"},onClick:()=>E&&C(y),children:e.jsxs(t.Space,{children:[Ys(y),e.jsx("span",{style:{fontWeight:E?500:400},children:Q})]})})}},{title:"大小",dataIndex:"size",width:110,render:y=>Jt(y)},{title:"类型",dataIndex:"contentType",width:200,ellipsis:!0,render:y=>y?e.jsx(t.Tag,{children:y}):"-"},{title:"修改时间",dataIndex:"lastModified",width:180,render:y=>y?new Date(y).toLocaleString():"-"},{title:"操作",width:160,fixed:"right",render:(y,M)=>{var c;const Q=((c=M.key)==null?void 0:c.endsWith("/"))||M.folder?[{key:"enter",icon:e.jsx(l.FolderOutlined,{}),label:"进入"},{key:"delete",icon:e.jsx(l.DeleteOutlined,{}),label:"删除",danger:!0}]:[{key:"download",icon:e.jsx(l.DownloadOutlined,{}),label:"下载"},{key:"copy",icon:e.jsx(l.CopyOutlined,{}),label:"复制"},{key:"delete",icon:e.jsx(l.DeleteOutlined,{}),label:"删除",danger:!0}];return e.jsx(t.Dropdown,{trigger:["click"],menu:{items:Q,onClick:({key:r,domEvent:L})=>{L.stopPropagation(),r==="enter"?C(M.key):r==="download"?U(M.key):r==="copy"?A(M.key):r==="delete"&&O([M.key])}},children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.MoreOutlined,{})})})}}],p=[{title:"所有桶",onClick:()=>a("/ai/oss/bucket")},{title:i}];if(f){const y=f.split("/").filter(Boolean);let M="";y.forEach(E=>{M+=E+"/",p.push({title:E,onClick:()=>P(M)})})}return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,background:"#fff",padding:"14px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)",marginBottom:16},children:[e.jsx(t.Button,{type:"text",icon:e.jsx(l.ArrowLeftOutlined,{}),onClick:()=>a("/ai/oss/bucket"),children:"返回"}),e.jsx(l.FolderOutlined,{style:{fontSize:18,color:"#faad14"}}),e.jsx("span",{style:{fontSize:16,fontWeight:600},children:i}),e.jsx("div",{style:{flex:1}}),e.jsx(t.Input.Search,{placeholder:"搜索对象名...",value:m,onChange:y=>z(y.target.value),style:{width:220},allowClear:!0}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>{G(f),g()}})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"对象数",value:w.objectCount||0})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"总大小",value:Jt(w.totalSize)})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"Provider",value:w.activeProvider||"-",valueStyle:{fontSize:18,color:"#1890ff"},prefix:e.jsx(l.CloudOutlined,{})})})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,background:"#fff",padding:"10px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)",marginBottom:12},children:[e.jsx(t.Breadcrumb,{items:p,style:{flex:1}}),F.length>0&&e.jsx(t.Popconfirm,{title:`确定删除 ${F.length} 个对象?`,onConfirm:()=>O(F),okText:"确认",cancelText:"取消",okType:"danger",children:e.jsxs(t.Button,{danger:!0,size:"small",icon:e.jsx(l.DeleteOutlined,{}),children:["批量删除 (",F.length,")"]})}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.FolderAddOutlined,{}),onClick:()=>x(!0),children:"新建文件夹"}),e.jsx(t.Upload,{beforeUpload:K,showUploadList:!1,disabled:u,children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.UploadOutlined,{}),loading:u,children:"上传文件"})})]}),e.jsx(t.Card,{styles:{body:{padding:0}},children:d?e.jsx("div",{style:{textAlign:"center",padding:60},children:e.jsx(t.Spin,{size:"large"})}):k.length===0?e.jsx(t.Empty,{image:e.jsx(l.CloudOutlined,{style:{fontSize:48,color:"#bfbfbf"}}),description:m?"没有匹配的对象":"桶是空的,上传第一个文件吧",style:{padding:60}}):e.jsx(t.Table,{rowKey:"key",columns:_,dataSource:k,pagination:!1,size:"middle",rowSelection:{selectedRowKeys:F,onChange:N},onRow:y=>({onDoubleClick:()=>{var M;((M=y.key)!=null&&M.endsWith("/")||y.folder)&&C(y.key)}})})}),e.jsx(t.Modal,{title:"新建文件夹",open:S,onCancel:()=>{x(!1),D.resetFields()},onOk:V,okText:"创建",cancelText:"取消",destroyOnClose:!0,children:e.jsxs(t.Form,{form:D,layout:"vertical",style:{marginTop:16},children:[e.jsx(t.Form.Item,{name:"name",label:"文件夹名",rules:[{required:!0,message:"请输入文件夹名"}],children:e.jsx(t.Input,{prefix:e.jsx(l.FolderOutlined,{}),placeholder:"my-folder"})}),e.jsxs("div",{style:{fontSize:12,color:"#999"},children:["将创建在:",e.jsxs("code",{children:[i,"/",f||""]})]})]})})]})}const Zs=[{value:"string",label:"string"},{value:"number",label:"number"},{value:"boolean",label:"boolean"},{value:"object",label:"object"},{value:"array",label:"array"}];function xt({value:o=[],onChange:i,readonly:a=!1}){const n=(j,w,h)=>{const m=[...o];m[j]={...m[j],[w]:h},i(m)},T=j=>{const w=o.filter((h,m)=>m!==j);i(w)},d=(j,w)=>{const h=j+w;if(h<0||h>=o.length)return;const m=[...o],z=m[j];m[j]=m[h],m[h]=z,i(m)},b=()=>{i([...o,{name:"",type:"string",jsonPath:"",required:!1,description:""}])},f=[{title:"输出字段名",dataIndex:"name",width:150,render:(j,w,h)=>a?e.jsx("span",{style:{fontFamily:"monospace"},children:j}):e.jsx(t.Input,{size:"small",value:j,onChange:m=>n(h,"name",m.target.value),placeholder:"e.g. user_name"})},{title:"类型",dataIndex:"type",width:100,render:(j,w,h)=>a?e.jsx("span",{children:j}):e.jsx(t.Select,{size:"small",value:j,onChange:m=>n(h,"type",m),options:Zs,style:{width:"100%"}})},{title:"JSONPath",dataIndex:"jsonPath",width:220,render:(j,w,h)=>a?e.jsx("span",{style:{fontFamily:"monospace",color:"#0958d9"},children:j}):e.jsx(t.Input,{size:"small",value:j,onChange:m=>n(h,"jsonPath",m.target.value),placeholder:"$.data.user.name",style:{fontFamily:"monospace"}})},{title:"必填",dataIndex:"required",width:60,render:(j,w,h)=>a?e.jsx("span",{style:{color:j?"#ff4d4f":"#999"},children:j?"是":"否"}):e.jsx(t.Switch,{size:"small",checked:j,onChange:m=>n(h,"required",m)})},{title:"描述",dataIndex:"description",width:160,render:(j,w,h)=>a?e.jsx("span",{style:{color:"#666"},children:j}):e.jsx(t.Input,{size:"small",value:j,onChange:m=>n(h,"description",m.target.value),placeholder:"字段说明"})},...a?[]:[{title:"操作",key:"action",width:100,render:(j,w,h)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Tooltip,{title:"上移",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.ArrowUpOutlined,{}),disabled:h===0,onClick:()=>d(h,-1)})}),e.jsx(t.Tooltip,{title:"下移",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.ArrowDownOutlined,{}),disabled:h===o.length-1,onClick:()=>d(h,1)})}),e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>T(h)})})]})}]];return e.jsxs("div",{children:[e.jsx(t.Table,{dataSource:o,columns:f,rowKey:(j,w)=>w,pagination:!1,size:"small",bordered:!0,style:{marginBottom:8}}),!a&&e.jsx(t.Button,{size:"small",type:"dashed",icon:e.jsx(l.PlusOutlined,{}),onClick:b,block:!0,children:"添加字段映射"}),o.length===0&&!a&&e.jsx("div",{style:{textAlign:"center",color:"#999",padding:12},children:"暂未配置输出字段映射。发布后 MCP 工具将返回原始响应体。"})]})}const{TextArea:Xs}=t.Input,{Step:ht}=t.Steps;function Yt({open:o,onClose:i,onSuccess:a}){var V,U,A,k,_;const[n,T]=s.useState(0),[d,b]=s.useState(!1),[f,j]=s.useState(!1),[w,h]=s.useState(""),[m,z]=s.useState(null),[F,N]=s.useState([]),[u,v]=s.useState(null),[S,x]=s.useState("mapping"),D=()=>{T(0),h(""),z(null),N([]),v(null),x("mapping")},G=()=>{D(),i()},g=async()=>{if(!w.trim()){t.message.warning("请粘贴 curl 命令");return}b(!0);try{const p=await be.importCurl({curl:w});p!=null&&p.success?(z(p),N(p.outputMapping||[]),T(1)):t.message.error((p==null?void 0:p.message)||"解析失败")}catch(p){t.message.error("解析失败: "+((p==null?void 0:p.message)||"网络错误"))}finally{b(!1)}},C=async()=>{j(!0);try{const p=await be.previewMapping({curl:w,outputMapping:F.filter(y=>y.name&&y.jsonPath)});v(p),x("result")}catch(p){t.message.error("预览失败: "+((p==null?void 0:p.message)||"网络错误"))}finally{j(!1)}},P=async()=>{b(!0);try{const p=await be.importCurl({curl:w,outputMapping:F.filter(y=>y.name&&y.jsonPath)});p!=null&&p.success?(t.message.success(`脚本 [${p.scriptCode}] 创建成功`),D(),a==null||a(),i()):t.message.error((p==null?void 0:p.message)||"创建失败")}catch(p){t.message.error("创建失败: "+((p==null?void 0:p.message)||"网络错误"))}finally{b(!1)}},K=(V=m==null?void 0:m.request)==null?void 0:V.httpRequestLine,O=(A=(U=m==null?void 0:m.request)==null?void 0:U.httpRequestHeader)==null?void 0:A.headers;return e.jsxs(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(l.ApiOutlined,{}),"从 Curl 导入 API Bridge 脚本"]}),open:o,onCancel:G,width:900,footer:null,destroyOnClose:!0,children:[e.jsxs(t.Steps,{current:n,size:"small",style:{marginBottom:24},children:[e.jsx(ht,{title:"粘贴 curl",description:"输入 curl 命令"}),e.jsx(ht,{title:"配置映射",description:"设置字段映射"}),e.jsx(ht,{title:"确认创建",description:"保存脚本"})]}),n===0&&e.jsxs("div",{children:[e.jsx("p",{style:{color:"#666",marginBottom:8},children:"粘贴任意 HTTP curl 命令,系统将自动解析并生成 API_BRIDGE 脚本"}),e.jsx(Xs,{rows:8,value:w,onChange:p=>h(p.target.value),placeholder:`curl -X POST https://api.example.com/users \\
24
+ `})]})},{confirm:Ms}=t.Modal,xt=[{providerCode:"ollama",providerName:"Ollama",providerType:"ollama",baseUrl:"http://localhost:11434",enabled:1,priority:100},{providerCode:"openai",providerName:"OpenAI",providerType:"openai",baseUrl:"https://api.openai.com",enabled:1,priority:90},{providerCode:"dashscope",providerName:"阿里通义",providerType:"dashscope",baseUrl:"https://dashscope.aliyuncs.com",enabled:1,priority:80}],He=[{id:1,modelCode:"qwen2.5:7b-instruct-q4_K_M",modelName:"Qwen 2.5 7B",providerCode:"ollama",modelType:"chat",contextWindow:32768,status:"ACTIVE",description:"通义千问 2.5 轻量级文本生成模型",inputPrice:0,outputPrice:0},{id:2,modelCode:"qwen3:8b",modelName:"Qwen3 8B",providerCode:"ollama",modelType:"chat",contextWindow:40960,status:"ACTIVE",description:"通义千问 3 最新一代模型",inputPrice:0,outputPrice:0},{id:3,modelCode:"gpt-4o",modelName:"GPT-4o",providerCode:"openai",modelType:"chat",contextWindow:128e3,status:"ACTIVE",description:"OpenAI 旗舰多模态模型",inputPrice:.0025,outputPrice:.01},{id:4,modelCode:"gpt-4o-mini",modelName:"GPT-4o Mini",providerCode:"openai",modelType:"chat",contextWindow:128e3,status:"ACTIVE",description:"轻量快速,性价比高",inputPrice:15e-5,outputPrice:6e-4},{id:5,modelCode:"qwen-vl-max",modelName:"Qwen VL Max",providerCode:"dashscope",modelType:"vision",contextWindow:8192,status:"ACTIVE",description:"通义千问视觉模型,支持图像理解",inputPrice:.002,outputPrice:.008},{id:6,modelCode:"qwen2-audio",modelName:"Qwen2 Audio",providerCode:"dashscope",modelType:"audio",contextWindow:8192,status:"ACTIVE",description:"通义千问语音模型",inputPrice:.001,outputPrice:.004},{id:7,modelCode:"text-embedding-v3",modelName:"Text Embedding V3",providerCode:"openai",modelType:"embedding",contextWindow:8191,status:"ACTIVE",description:"OpenAI 文本嵌入模型",inputPrice:2e-5,outputPrice:0},{id:8,modelCode:"codestral",modelName:"Codestral",providerCode:"ollama",modelType:"code",contextWindow:32768,status:"ACTIVE",description:"代码生成专用模型,支持多种编程语言",inputPrice:0,outputPrice:0},{id:9,modelCode:"dall-e-3",modelName:"DALL·E 3",providerCode:"openai",modelType:"image",contextWindow:0,status:"ACTIVE",description:"OpenAI 图像生成模型",inputPrice:.04,outputPrice:0}],Pe=[{key:"chat",title:"文本生成",icon:e.jsx(l.BranchesOutlined,{}),color:"#1677ff",bg:"#e6f4ff",border:"#1677ff"},{key:"code",title:"代码生成",icon:e.jsx(l.ThunderboltOutlined,{}),color:"#722ed1",bg:"#f9f0ff",border:"#722ed1"},{key:"image",title:"图像生成",icon:e.jsx(l.PictureOutlined,{}),color:"#13c2c2",bg:"#e6fffb",border:"#13c2c2"},{key:"vision",title:"视觉理解",icon:e.jsx(l.EyeOutlined,{}),color:"#fa8c16",bg:"#fff7e6",border:"#fa8c16"},{key:"audio",title:"语音",icon:e.jsx(l.AudioOutlined,{}),color:"#eb2f96",bg:"#fff0f6",border:"#eb2f96"},{key:"embedding",title:"嵌入/向量",icon:e.jsx(l.NodeIndexOutlined,{}),color:"#52c41a",bg:"#f6ffed",border:"#52c41a"}],_s=[{value:"ollama",label:"Ollama"},{value:"openai",label:"OpenAI"},{value:"dashscope",label:"阿里通义"},{value:"azure",label:"Azure OpenAI"},{value:"anthropic",label:"Anthropic"},{value:"custom",label:"自定义"}],Us=()=>{const[i,o]=s.useState([]),[a,r]=s.useState([]),[j,c]=s.useState(!1),[m,b]=s.useState("chat"),[S,y]=s.useState(null),[p,g]=s.useState(!1),[P,N]=s.useState(null),[D]=t.Form.useForm(),[x,v]=s.useState(!1),[T,f]=s.useState(null),[M]=t.Form.useForm(),K=async()=>{c(!0);try{const[u,w]=await Promise.all([te("/llm-center/model/list",{method:"GET"}).catch(()=>null),te("/llm-center/provider/list",{method:"GET"}).catch(()=>null)]),U=Array.isArray(u)?u:(u==null?void 0:u.data)||[],z=Array.isArray(w)?w:(w==null?void 0:w.data)||[];U.length===0&&z.length===0?(r(xt),o(He)):(o(U),r(z))}catch{r(xt),o(He)}finally{c(!1)}};s.useEffect(()=>{K()},[]);const C={};Pe.forEach(u=>{C[u.key]=i.filter(w=>w.modelType===u.key).length});const k=i.filter(u=>{const w=!m||u.modelType===m,U=!S||u.providerCode===S;return w&&U}),E={ollama:"blue",openai:"green",dashscope:"cyan",azure:"purple",anthropic:"orange",custom:"default"},W=()=>{N(null),D.resetFields(),D.setFieldsValue({status:"ACTIVE",contextWindow:4096}),g(!0)},h=u=>{N(u),D.setFieldsValue(u),g(!0)},B=u=>{Ms({title:"确认删除",content:`删除模型 ${u.modelName} ?`,onOk:async()=>{if(i===He){o(i.filter(w=>w.id!==u.id)),t.message.success("删除成功");return}await te("/llm-center/model/delete",{method:"POST",data:{id:u.id}}),t.message.success("删除成功"),K()}})},F=async()=>{try{const u=await D.validateFields();if(i===He){o(P?i.map(w=>w.id===P.id?{...w,...u}:w):[...i,{...u,id:Date.now()}]),t.message.success(P?"更新成功":"创建成功"),g(!1);return}await te(P?"/llm-center/model/update":"/llm-center/model/create",{method:"POST",data:u}),t.message.success(P?"更新成功":"创建成功"),g(!1),K()}catch{}},A=()=>{f(null),M.resetFields(),M.setFieldsValue({status:"ACTIVE"}),v(!0)},I=async()=>{try{const u=await M.validateFields();if(a===xt){r(T?a.map(w=>w.providerCode===T.providerCode?{...w,...u}:w):[...a,{...u}]),t.message.success(T?"更新成功":"创建成功"),v(!1);return}await te(T?"/llm-center/provider/update":"/llm-center/provider/create",{method:"POST",data:u}),t.message.success(T?"更新成功":"创建成功"),v(!1),K()}catch{}},G=u=>{const w=m===u.key,U=C[u.key]||0;return e.jsxs("div",{onClick:()=>b(u.key),style:{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",marginBottom:2,cursor:"pointer",borderRadius:8,borderLeft:w?`3px solid ${u.color}`:"3px solid transparent",background:w?u.bg:"transparent",transition:"all 0.2s"},onMouseEnter:z=>{w||(z.currentTarget.style.background="#f5f5f5")},onMouseLeave:z=>{w||(z.currentTarget.style.background="transparent")},children:[e.jsx("div",{style:{width:32,height:32,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:w?u.color:"#f0f0f0",color:w?"#fff":"#8c8c8c",fontSize:16,flexShrink:0,transition:"all 0.2s"},children:u.icon}),e.jsx("div",{style:{flex:1,minWidth:0},children:e.jsx("div",{style:{fontSize:13,fontWeight:w?600:400,color:w?"#262626":"#595959",lineHeight:1.4},children:u.title})}),e.jsx("span",{style:{fontSize:11,color:w?u.color:"#bababa",fontWeight:w?600:400,background:w?"#fff":"transparent",padding:"1px 7px",borderRadius:10},children:U})]},u.key)};return Pe.find(u=>u.key===m)||Pe[0],e.jsxs("div",{style:{display:"flex",gap:16,height:"calc(100vh - 180px)",padding:16},children:[e.jsxs(t.Card,{size:"small",style:{width:210,overflow:"auto",flexShrink:0,border:"none",boxShadow:"0 1px 3px rgba(0,0,0,0.06)"},bodyStyle:{padding:"8px 0"},children:[e.jsx("div",{style:{padding:"8px 14px 4px",fontSize:12,color:"#8c8c8c",fontWeight:500},children:"能力分类"}),Pe.map(G)]}),e.jsxs("div",{style:{flex:1,overflow:"auto",display:"flex",flexDirection:"column",gap:12},children:[e.jsx(t.Card,{size:"small",style:{flexShrink:0},bodyStyle:{padding:"10px 16px"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:12,color:"#8c8c8c",marginRight:4,whiteSpace:"nowrap"},children:"供应商"}),e.jsx(t.Tag,{style:{cursor:"pointer",padding:"2px 10px",fontSize:12,borderRadius:16,margin:0},color:S?"default":"blue",onClick:()=>y(null),children:"全部"}),a.map(u=>e.jsx(t.Tag,{style:{cursor:"pointer",padding:"2px 10px",fontSize:12,borderRadius:16,margin:0},color:S===u.providerCode?E[u.providerType]||"blue":"default",onClick:()=>y(u.providerCode),children:u.providerName},u.providerCode)),e.jsx("div",{style:{flex:1}}),e.jsx(t.Button,{size:"small",type:"primary",ghost:!0,icon:e.jsx(l.PlusOutlined,{}),onClick:W,children:"新增模型"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ApiOutlined,{}),onClick:A,children:"新增供应商"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:K})]})}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:j?e.jsx("div",{style:{textAlign:"center",padding:80},children:e.jsx(t.Spin,{size:"large"})}):k.length===0?e.jsx("div",{style:{textAlign:"center",padding:80},children:e.jsx(t.Empty,{description:"暂无匹配的模型"})}):e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(340px, 1fr))",gap:12},children:k.map(u=>{var z;const w=a.find(Q=>Q.providerCode===u.providerCode),U=Pe.find(Q=>Q.key===u.modelType);return e.jsx(t.Card,{size:"small",hoverable:!0,style:{borderRadius:8,borderTop:`3px solid ${(U==null?void 0:U.color)||"#d9d9d9"}`},bodyStyle:{padding:14},actions:[e.jsx(t.Tooltip,{title:"编辑模型",children:e.jsx(l.EditOutlined,{onClick:()=>h(u)})},"edit"),e.jsx(t.Tooltip,{title:"删除模型",children:e.jsx(l.DeleteOutlined,{style:{color:"#ff4d4f"},onClick:()=>B(u)})},"delete")],children:e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx("div",{style:{width:44,height:44,borderRadius:10,background:U?`linear-gradient(135deg, ${U.color}, ${U.color}dd)`:"#f0f0f0",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:U?e.jsx("span",{style:{color:"#fff",fontSize:20},children:U.icon}):e.jsx(l.GlobalOutlined,{style:{fontSize:20,color:"#fff"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:14,color:"#262626"},children:u.modelName||u.modelCode}),e.jsx("div",{style:{fontSize:12,color:"#8c8c8c",fontFamily:"monospace"},children:u.modelCode})]}),e.jsx(t.Tag,{color:u.status==="ACTIVE"?"green":"red",style:{borderRadius:20,fontSize:11,lineHeight:"20px",margin:0},children:u.status==="ACTIVE"?"正常":"禁用"})]}),e.jsxs("div",{style:{marginTop:8,display:"flex",gap:6,flexWrap:"wrap"},children:[e.jsxs(t.Tag,{color:E[w==null?void 0:w.providerType]||"default",style:{fontSize:11,borderRadius:4},children:[e.jsx(l.GlobalOutlined,{style:{marginRight:4}}),(w==null?void 0:w.providerName)||u.providerCode]}),e.jsx(t.Tag,{style:{fontSize:11,borderRadius:4},children:((z=Pe.find(Q=>Q.key===u.modelType))==null?void 0:z.title)||u.modelType}),u.contextWindow>0&&e.jsxs(t.Tag,{style:{fontSize:11,borderRadius:4},children:[(u.contextWindow/1e3).toFixed(0),"K CTX"]})]}),u.description&&e.jsx("div",{style:{marginTop:6,fontSize:12,color:"#8c8c8c",lineHeight:1.5},children:u.description})]})]})},u.id||u.modelCode)})})})]}),e.jsx(t.Modal,{title:P?"编辑模型":"新增模型",open:p,onOk:F,onCancel:()=>g(!1),width:640,children:e.jsxs(t.Form,{form:D,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelCode",label:"模型编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: qwen2.5:72b, gpt-4o",disabled:!!P})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelName",label:"模型名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Qwen 2.5 72B"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerCode",label:"所属供应商",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择供应商",children:a.map(u=>e.jsx(t.Select.Option,{value:u.providerCode,children:u.providerName},u.providerCode))})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelType",label:"能力类型",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择能力分类",children:Pe.map(u=>e.jsx(t.Select.Option,{value:u.key,children:e.jsxs(t.Space,{children:[e.jsx("span",{style:{color:u.color},children:u.icon}),u.title]})},u.key))})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"contextWindow",label:"上下文窗口 (tokens)",children:e.jsx(t.InputNumber,{style:{width:"100%"},placeholder:"如: 4096",min:0})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"禁用"})]})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"inputPrice",label:"输入价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"outputPrice",label:"输出价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"模型描述..."})})]})}),e.jsx(t.Modal,{title:T?"编辑供应商":"新增供应商",open:x,onOk:I,onCancel:()=>v(!1),width:560,children:e.jsxs(t.Form,{form:M,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerCode",label:"供应商编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: ollama, openai",disabled:!!T})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerName",label:"供应商名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Ollama, OpenAI"})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"providerType",label:"类型",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择类型",children:_s.map(u=>e.jsx(t.Select.Option,{value:u.value,children:u.label},u.value))})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"禁用"})]})})})]}),e.jsx(t.Divider,{style:{margin:"8px 0",fontSize:12,color:"#8c8c8c"},children:"连接配置"}),e.jsx(t.Form.Item,{name:"baseUrl",label:"Base URL",rules:[{required:!0}],tooltip:"标准供应商自动填充地址;自定义/Ollama 需手动填写",children:e.jsx(t.Input,{placeholder:"如: http://localhost:11434"})}),e.jsx(t.Form.Item,{name:"apiKey",label:"API Key",tooltip:"系统级凭据,可在系统配置中统一管理。此字段仅用于展示,实际运行时从环境变量读取",children:e.jsx(t.Input.Password,{placeholder:"可选,建议通过系统配置管理"})})]})})]})},{confirm:Gs}=t.Modal,Ws=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState(!1),[m,b]=s.useState(null),[S]=t.Form.useForm(),y=async()=>{r(!0);try{const v=await te("/llm-center/provider/list",{method:"GET"}),T=Array.isArray(v)?v:(v==null?void 0:v.data)||[];o(T)}catch{t.message.error("加载失败")}finally{r(!1)}};s.useEffect(()=>{y()},[]);const p=()=>{b(null),S.resetFields(),c(!0)},g=v=>{b(v),S.setFieldsValue(v),c(!0)},P=async v=>{Gs({title:"确认删除",content:`删除供应商 ${v.providerName} ?`,onOk:async()=>{await te("/llm-center/provider/delete",{method:"POST",data:{id:v.id}}),t.message.success("删除成功"),y()}})},N=async()=>{try{const v=await S.validateFields();await te(m?"/llm-center/provider/update":"/llm-center/provider/create",{method:"POST",data:v}),t.message.success(m?"更新成功":"创建成功"),c(!1),y()}catch{}},D={ollama:"blue",openai:"green",azure:"purple",anthropic:"orange"},x=[{title:"供应商",render:(v,T)=>e.jsxs(t.Space,{children:[e.jsx(l.GlobalOutlined,{style:{fontSize:20,color:D[T.providerCode]||"blue"}}),e.jsxs("div",{children:[e.jsx("div",{children:e.jsx("strong",{children:T.providerName})}),e.jsx("div",{style:{fontSize:12,color:"#999"},children:T.providerCode})]})]})},{title:"类型",dataIndex:"providerType",render:v=>e.jsx(t.Tag,{color:D[v]||"default",children:v==null?void 0:v.toUpperCase()})},{title:"Base URL",dataIndex:"baseUrl",ellipsis:!0},{title:"模型数量",dataIndex:"modelCount",render:v=>e.jsx(t.Tag,{children:v||0})},{title:"状态",dataIndex:"status",render:v=>e.jsx(t.Tag,{color:v==="ACTIVE"?"green":"red",children:v==="ACTIVE"?"正常":"异常"})},{title:"操作",width:150,render:(v,T)=>e.jsxs(t.Space,{children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>g(T),children:"编辑"}),e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>P(T),children:"删除"})]})}];return e.jsxs("div",{children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"供应商数",value:i.length})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"活跃模型",value:i.reduce((v,T)=>v+(T.modelCount||0),0)})})})]}),e.jsx("div",{style:{marginBottom:16},children:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:p,children:"添加供应商"})}),e.jsx(t.Table,{columns:x,dataSource:i,loading:a,rowKey:"id"}),e.jsx(t.Modal,{title:m?"编辑供应商":"添加供应商",open:j,onOk:N,onCancel:()=>c(!1),width:500,children:e.jsxs(t.Form,{form:S,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"providerCode",label:"供应商编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: ollama, openai, azure",disabled:!!m})}),e.jsx(t.Form.Item,{name:"providerName",label:"供应商名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Ollama, OpenAI"})}),e.jsx(t.Form.Item,{name:"providerType",label:"类型",rules:[{required:!0}],children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ollama",children:"Ollama"}),e.jsx(t.Select.Option,{value:"openai",children:"OpenAI"}),e.jsx(t.Select.Option,{value:"azure",children:"Azure OpenAI"}),e.jsx(t.Select.Option,{value:"anthropic",children:"Anthropic"})]})}),e.jsx(t.Form.Item,{name:"baseUrl",label:"Base URL",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: http://localhost:11434"})}),e.jsx(t.Form.Item,{name:"apiKey",label:"API Key",children:e.jsx(t.Input.Password,{placeholder:"可选,部分供应商需要"})}),e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"异常"})]})})]})})]})},{confirm:Vs}=t.Modal,Ks=()=>{const[i,o]=s.useState([]),[a,r]=s.useState([]),[j,c]=s.useState(!1),[m,b]=s.useState(!1),[S,y]=s.useState(null),[p]=t.Form.useForm(),g=async()=>{c(!0);try{const f=await te("/llm-center/model/list",{method:"GET"}),M=Array.isArray(f)?f:(f==null?void 0:f.data)||[];o(M)}catch{t.message.error("加载失败")}finally{c(!1)}},P=async()=>{try{const f=await te("/llm-center/provider/list",{method:"GET"}),M=Array.isArray(f)?f:(f==null?void 0:f.data)||[];r(M)}catch{}};s.useEffect(()=>{g(),P()},[]);const N=()=>{y(null),p.resetFields(),p.setFieldsValue({status:"ACTIVE",contextWindow:4096}),b(!0)},D=f=>{y(f),p.setFieldsValue(f),b(!0)},x=async f=>{Vs({title:"确认删除",content:`删除模型 ${f.modelName} ?`,onOk:async()=>{await te("/llm-center/model/delete",{method:"POST",data:{id:f.id}}),t.message.success("删除成功"),g()}})},v=async()=>{try{const f=await p.validateFields();await te(S?"/llm-center/model/update":"/llm-center/model/create",{method:"POST",data:f}),t.message.success(S?"更新成功":"创建成功"),b(!1),g()}catch{}},T=[{title:"模型编码",dataIndex:"modelCode",width:120},{title:"模型名称",dataIndex:"modelName",width:150},{title:"供应商",dataIndex:"providerCode",render:f=>e.jsx(t.Tag,{children:f})},{title:"上下文窗口",dataIndex:"contextWindow",render:f=>f?`${f.toLocaleString()} tokens`:"-"},{title:"输入价格",dataIndex:"inputPrice",render:f=>f?`¥${f}/千token`:"-"},{title:"输出价格",dataIndex:"outputPrice",render:f=>f?`¥${f}/千token`:"-"},{title:"状态",dataIndex:"status",render:f=>e.jsx(t.Tag,{color:f==="ACTIVE"?"green":"red",children:f==="ACTIVE"?"正常":"禁用"})},{title:"操作",width:150,render:(f,M)=>e.jsxs(t.Space,{children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>D(M),children:"编辑"}),e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>x(M),children:"删除"})]})}];return e.jsxs("div",{children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"模型总数",value:i.length})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"活跃模型",value:i.filter(f=>f.status==="ACTIVE").length})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"总上下文",value:i.reduce((f,M)=>f+(M.contextWindow||0),0).toLocaleString(),suffix:"tokens"})})})]}),e.jsx("div",{style:{marginBottom:16},children:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:N,children:"添加模型"})}),e.jsx(t.Table,{columns:T,dataSource:i,loading:j,rowKey:"id"}),e.jsx(t.Modal,{title:S?"编辑模型":"添加模型",open:m,onOk:v,onCancel:()=>b(!1),width:600,children:e.jsxs(t.Form,{form:p,layout:"vertical",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelCode",label:"模型编码",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: qwen2.5, gpt-4o",disabled:!!S})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"modelName",label:"模型名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: Qwen 2.5 72B"})})})]}),e.jsx(t.Form.Item,{name:"providerCode",label:"供应商",rules:[{required:!0}],children:e.jsx(t.Select,{placeholder:"选择供应商",children:a.map(f=>e.jsx(t.Select.Option,{value:f.providerCode,children:f.providerName},f.providerCode))})}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"contextWindow",label:"上下文窗口 (tokens)",children:e.jsx(t.InputNumber,{style:{width:"100%"},placeholder:"如: 4096"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"status",label:"状态",initialValue:"ACTIVE",children:e.jsxs(t.Select,{children:[e.jsx(t.Select.Option,{value:"ACTIVE",children:"正常"}),e.jsx(t.Select.Option,{value:"INACTIVE",children:"禁用"})]})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"inputPrice",label:"输入价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6,placeholder:"如: 0.001"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"outputPrice",label:"输出价格 (元/千token)",children:e.jsx(t.InputNumber,{style:{width:"100%"},min:0,precision:6,placeholder:"如: 0.002"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"模型描述..."})})]})})]})},{Text:Gt}=t.Typography,Wt=i=>i?Number(i).toFixed(4):"0.0000",Vt=({open:i,ak:o,onClose:a})=>{const[r,j]=s.useState(null),[c,m]=s.useState([]),[b,S]=s.useState([]),[y,p]=s.useState(!1);s.useEffect(()=>{!i||!o||g()},[i,o]);const g=async()=>{var x,v;p(!0);try{const[T,f,M]=await Promise.allSettled([te("/llm-gateway/usage/overview",{method:"GET",params:{accessKey:o.accessKey}}),te("/llm-gateway/usage/trend",{method:"GET",params:{accessKey:o.accessKey,days:7}}),te("/llm-gateway/usage/records",{method:"GET",params:{accessKey:o.accessKey,page:1,size:20}})]);j(T.status==="fulfilled"&&(((x=T.value)==null?void 0:x.data)||T.value)||null),m(f.status==="fulfilled"?Array.isArray(f.value)?f.value:((v=f.value)==null?void 0:v.data)||[]:[]);const K=M.status==="fulfilled"?M.value:null;S(K?Array.isArray(K)?K:K.records||K.data||[]:[])}catch{}finally{p(!1)}},P=(x,v)=>{navigator.clipboard.writeText(x),message.success(`${v} 已复制`)},N={tooltip:{trigger:"axis"},legend:{data:["Token消耗","调用次数"]},grid:{top:40,right:40,bottom:30,left:50},xAxis:{type:"category",data:c.map(x=>x.date||x.statDate||"")},yAxis:[{type:"value",name:"Tokens",position:"left"},{type:"value",name:"调用次数",position:"right"}],series:[{name:"Token消耗",type:"bar",data:c.map(x=>x.dailyTokens||x.totalTokens||0)},{name:"调用次数",type:"line",yAxisIndex:1,data:c.map(x=>x.dailyCalls||x.totalCalls||0)}]},D=[{title:"时间",dataIndex:"gmtCreate",width:160},{title:"应用",dataIndex:"appCode",render:x=>x?e.jsx(t.Tag,{color:"blue",children:x}):"-"},{title:"用户",dataIndex:"userName",render:x=>x||"-"},{title:"供应商",dataIndex:"providerCode",render:x=>x?e.jsx(t.Tag,{color:"purple",children:x}):"-"},{title:"模型",dataIndex:"modelCode",render:x=>x?e.jsx(t.Tag,{children:x}):"-"},{title:"输入Token",dataIndex:"inputTokens",render:x=>(x==null?void 0:x.toLocaleString())||"-"},{title:"输出Token",dataIndex:"outputTokens",render:x=>(x==null?void 0:x.toLocaleString())||"-"},{title:"状态",dataIndex:"status",render:x=>e.jsx(t.Tag,{color:x==="SUCCESS"?"green":"red",children:x||"-"})},{title:"费用",dataIndex:"totalCost",render:x=>e.jsxs(Gt,{style:{color:"#faad14"},children:["¥",x||"0.0000"]})}];return e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx("span",{children:"用量详情 ·"}),e.jsx(Gt,{strong:!0,children:o==null?void 0:o.akName}),(o==null?void 0:o.accessKey)&&e.jsxs(t.Space,{size:4,children:[e.jsx("code",{style:{fontSize:12,color:"#595959",background:"#f5f5f5",padding:"2px 6px",borderRadius:4},children:o.accessKey}),e.jsx(l.CopyOutlined,{style:{cursor:"pointer",color:"#1677ff"},onClick:()=>P(o.accessKey,"AccessKey")})]})]}),open:i,onClose:a,width:820,destroyOnClose:!0,children:e.jsxs(t.Spin,{spinning:y,children:[e.jsxs(t.Row,{gutter:12,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"累计 Token",value:(r==null?void 0:r.totalTokens)||0,prefix:e.jsx(l.ThunderboltOutlined,{style:{color:"#667eea"}}),formatter:x=>Number(x).toLocaleString(),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"累计费用",value:Wt(r==null?void 0:r.totalCost),prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"今日 Token",value:(r==null?void 0:r.todayTokens)||0,prefix:e.jsx(l.ClockCircleOutlined,{style:{color:"#52c41a"}}),formatter:x=>Number(x).toLocaleString(),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"今日费用",value:Wt(r==null?void 0:r.todayCost),prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),valueStyle:{fontSize:18}})})})]}),e.jsx(t.Divider,{style:{margin:"12px 0"}}),e.jsxs(t.Tabs,{defaultActiveKey:"trend",size:"small",children:[e.jsx(t.Tabs.TabPane,{tab:"用量趋势",icon:e.jsx(l.BarChartOutlined,{}),children:e.jsx(t.Card,{size:"small",bodyStyle:{padding:12},children:c.length>0?e.jsx(Pt,{option:N,style:{height:300}}):e.jsx(t.Empty,{description:"该 AK 暂无用量数据",style:{padding:"40px 0"}})})},"trend"),e.jsx(t.Tabs.TabPane,{tab:"调用明细",icon:e.jsx(l.ApiOutlined,{}),children:e.jsx(t.Table,{columns:D,dataSource:b,rowKey:"id",size:"small",pagination:{pageSize:20,showSizeChanger:!1},locale:{emptyText:e.jsx(t.Empty,{description:"暂无调用记录"})}})},"records")]})]})})},{confirm:Hs}=t.Modal,Kt="http://localhost:8888",Ht=i=>i?i>=1e6?(i/1e6).toFixed(1)+"M":i>=1e3?(i/1e3).toFixed(1)+"K":Number(i).toLocaleString():"0",Js=()=>{const[i,o]=s.useState("PERSONAL"),[a,r]=s.useState([]),[j,c]=s.useState(!1),[m,b]=s.useState(!1),[S,y]=s.useState(null),[p]=t.Form.useForm(),[g,P]=s.useState(null),[N,D]=s.useState(null),[x,v]=s.useState([]),T=async()=>{c(!0);try{const A=await te("/ak/list",{method:"GET",params:{akType:i}});r(Array.isArray(A)?A:(A==null?void 0:A.data)||[])}catch{t.message.error("加载失败")}finally{c(!1)}},f=async()=>{try{const A=await te("/agent/app/page",{method:"POST",body:JSON.stringify({current:1,size:100})}),I=Array.isArray(A)?A:(A==null?void 0:A.records)||(A==null?void 0:A.data)||[];v(I.map(G=>({value:G.appCode,label:G.appName||G.appCode})))}catch{}};s.useEffect(()=>{T()},[i]),s.useEffect(()=>{f()},[]);const M=()=>{y(null),p.resetFields(),p.setFieldsValue({akType:i}),b(!0)},K=A=>{y(A),p.setFieldsValue({akName:A.akName,description:A.description,akType:A.akType||"PERSONAL",appCode:A.appCode,appName:A.appName}),b(!0)},C=A=>{Hs({title:"确认删除",content:`删除 AK「${A.akName}」?此操作不可恢复。`,okText:"删除",okType:"danger",onOk:async()=>{await te("/ak/delete",{method:"POST",params:{id:A.id}}),t.message.success("删除成功"),T()}})},k=async A=>{const I=A.status===1?0:1;await te("/ak/toggle",{method:"POST",params:{id:A.id,status:I}}),t.message.success(I===1?"已启用":"已禁用"),T()},E=async()=>{try{const A=await p.validateFields();if(S)await te("/ak/update",{method:"POST",data:{...A,id:S.id}}),t.message.success("更新成功"),b(!1),T();else{const I=await te("/ak/create",{method:"POST",data:A}),G=I!=null&&I.accessKey?I:(I==null?void 0:I.data)||{};b(!1),T(),P({akName:A.akName,accessKey:G.accessKey,secretKey:G.secretKey})}}catch{}},W=(A,I)=>{navigator.clipboard.writeText(A),t.message.success(`${I} 已复制`)},h=[{title:"名称",dataIndex:"akName",key:"akName",width:160,render:(A,I)=>e.jsxs(t.Space,{children:[e.jsx(l.KeyOutlined,{style:{color:"#1677ff"}}),e.jsx("span",{style:{fontWeight:500},children:A}),I.akType==="APP"&&I.appName&&e.jsx(t.Tag,{color:"purple",style:{borderRadius:10,fontSize:11},children:I.appName})]})},{title:"AccessKey",dataIndex:"accessKey",key:"accessKey",width:200,render:A=>e.jsxs(t.Space,{children:[e.jsx("code",{style:{fontFamily:"monospace",fontSize:12,color:"#595959",background:"#f5f5f5",padding:"3px 8px",borderRadius:4},children:A}),e.jsx(t.Tooltip,{title:"复制 AccessKey",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:I=>{I.stopPropagation(),W(A,"AccessKey")}})})]})},{title:"Token 消耗",dataIndex:"totalTokens",key:"totalTokens",width:110,sorter:(A,I)=>(A.totalTokens||0)-(I.totalTokens||0),render:A=>e.jsxs(t.Space,{children:[e.jsx(l.ThunderboltOutlined,{style:{color:"#faad14",fontSize:12}}),e.jsx("span",{style:{fontWeight:500},children:Ht(A)})]})},{title:"最后使用",dataIndex:"lastUsedTime",key:"lastUsedTime",width:160,render:A=>e.jsx(t.Space,{size:4,children:e.jsx("span",{style:{color:A?"#595959":"#bfbfbf",fontSize:13},children:A||"从未使用"})})},{title:"状态",dataIndex:"status",key:"status",width:70,render:A=>e.jsx(t.Tag,{color:A===1?"green":"red",style:{borderRadius:20},children:A===1?"正常":"禁用"})},{title:"描述",dataIndex:"description",key:"description",ellipsis:!0},{title:"创建时间",dataIndex:"createdTime",key:"createdTime",width:160},{title:"操作",key:"action",width:130,render:(A,I)=>e.jsxs(t.Space,{size:"small",onClick:G=>G.stopPropagation(),children:[e.jsx(t.Tooltip,{title:I.status===1?"禁用":"启用",children:e.jsx(t.Button,{size:"small",type:"text",icon:I.status===1?e.jsx(l.StopOutlined,{style:{color:"#faad14"}}):e.jsx(l.CheckCircleOutlined,{style:{color:"#52c41a"}}),onClick:()=>k(I)})}),e.jsx(t.Tooltip,{title:"编辑",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.KeyOutlined,{}),onClick:()=>K(I)})}),e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.DeleteOutlined,{style:{color:"#ff4d4f"}}),onClick:()=>C(I)})})]})}],B=a.reduce((A,I)=>A+(I.totalTokens||0),0),F=a.filter(A=>A.status===1).length;return e.jsxs("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:12},children:[e.jsx(t.Alert,{type:"info",showIcon:!0,icon:e.jsx(l.ApiOutlined,{}),message:e.jsxs(t.Space,{children:[e.jsx("span",{style:{fontWeight:500},children:"API 接入地址:"}),e.jsx("code",{style:{fontFamily:"monospace",fontSize:13,background:"#e6f4ff",padding:"2px 8px",borderRadius:4},children:Kt}),e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>W(Kt,"API 地址")}),e.jsx("span",{style:{color:"#8c8c8c",fontSize:12},children:"使用此地址 + AccessKey 调用平台所有模型"})]}),style:{border:"none",background:"#e6f4ff"}}),e.jsxs(t.Row,{gutter:12,children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"AK 总数",value:a.length,prefix:e.jsx(l.KeyOutlined,{}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"累计 Token",value:Ht(B),prefix:e.jsx(l.ThunderboltOutlined,{}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"有效 AK",value:F,prefix:e.jsx(l.CheckCircleOutlined,{style:{color:"#52c41a"}}),valueStyle:{fontSize:18}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{background:"#f5f5f5"},bodyStyle:{padding:"10px 14px"},children:e.jsx(t.Statistic,{title:"所属应用",value:new Set(a.map(A=>A.appCode).filter(Boolean)).size,prefix:e.jsx(l.AppstoreOutlined,{}),valueStyle:{fontSize:18}})})})]}),e.jsx(t.Card,{size:"small",styles:{body:{padding:0}},children:e.jsx(t.Tabs,{activeKey:i,onChange:o,size:"small",tabBarStyle:{margin:0,padding:"0 16px"},tabBarExtraContent:e.jsxs(t.Space,{style:{padding:"8px 0"},children:[e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:M,size:"small",children:i==="PERSONAL"?"申请个人 AK":"申请应用 AK"}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:T,size:"small"})]}),items:[{key:"PERSONAL",label:e.jsxs(t.Space,{children:[e.jsx(l.UserOutlined,{}),"个人 AK"]}),children:e.jsx(t.Spin,{spinning:j,children:e.jsx(t.Table,{dataSource:a,columns:h,rowKey:"id",pagination:!1,size:"small",onRow:A=>({onClick:()=>D(A),style:{cursor:"pointer"}}),locale:{emptyText:'暂无个人 AK,点右上角"申请个人 AK"创建'}})})},{key:"APP",label:e.jsxs(t.Space,{children:[e.jsx(l.AppstoreOutlined,{}),"应用 AK"]}),children:e.jsx(t.Spin,{spinning:j,children:e.jsx(t.Table,{dataSource:a,columns:h,rowKey:"id",pagination:!1,size:"small",onRow:A=>({onClick:()=>D(A),style:{cursor:"pointer"}}),locale:{emptyText:'暂无应用 AK,点右上角"申请应用 AK"并绑定一个应用'}})})}]})}),e.jsx(t.Modal,{title:S?"编辑 AK":i==="APP"?"申请应用 AK":"申请个人 AK",open:m,onOk:E,onCancel:()=>b(!1),width:520,okText:S?"保存":"申请",destroyOnClose:!0,children:e.jsxs(t.Form,{form:p,layout:"vertical",preserve:!1,children:[e.jsx(t.Form.Item,{name:"akType",label:"AK 类型",rules:[{required:!0}],children:e.jsxs(t.Radio.Group,{disabled:!!S,children:[e.jsx(t.Radio.Button,{value:"PERSONAL",children:"个人 AK"}),e.jsx(t.Radio.Button,{value:"APP",children:"应用 AK"})]})}),e.jsx(t.Form.Item,{shouldUpdate:(A,I)=>A.akType!==I.akType,noStyle:!0,children:()=>p.getFieldValue("akType")==="APP"&&e.jsx(t.Form.Item,{name:"appCode",label:"所属应用",rules:[{required:!0,message:"应用 AK 必须绑定一个应用"}],children:e.jsx(t.Select,{showSearch:!0,optionFilterProp:"label",placeholder:"选择应用",options:x})})}),e.jsx(t.Form.Item,{name:"akName",label:"名称",rules:[{required:!0,message:"请输入 AK 名称"}],children:e.jsx(t.Input,{placeholder:i==="APP"?"如:生产环境-订单服务":"如:本地调试"})}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input.TextArea,{rows:2,placeholder:"密钥用途..."})}),!S&&e.jsx(t.Alert,{type:"info",showIcon:!0,message:"AccessKey 和 SecretKey 将由系统自动生成。SecretKey 仅在创建时展示一次,请妥善保管。",style:{background:"#e6f4ff",border:"none"}})]})}),e.jsx(t.Modal,{title:"AK 创建成功",open:!!g,onCancel:()=>P(null),footer:e.jsx(t.Button,{type:"primary",onClick:()=>P(null),children:"我已保存,关闭"}),width:520,children:g&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"warning",showIcon:!0,message:"SecretKey 仅在此展示一次,关闭后将无法再次查看。请立即复制并妥善保管。",style:{marginBottom:16}}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,color:"#8c8c8c",marginBottom:4},children:"AccessKey"}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1,fontFamily:"monospace",fontSize:14,padding:"8px 12px",background:"#f5f5f5",borderRadius:6,border:"1px solid #d9d9d9"},children:g.accessKey}),e.jsx(t.Button,{icon:e.jsx(l.CopyOutlined,{}),onClick:()=>W(g.accessKey,"AccessKey"),children:"复制"})]})]}),e.jsxs("div",{style:{marginBottom:12},children:[e.jsx("div",{style:{fontSize:12,color:"#8c8c8c",marginBottom:4},children:"SecretKey"}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx("code",{style:{flex:1,fontFamily:"monospace",fontSize:14,padding:"8px 12px",background:"#fff7e6",borderRadius:6,border:"1px solid #ffd591",color:"#d46b08"},children:g.secretKey}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>W(g.secretKey,"SecretKey"),children:"复制"})]})]}),e.jsx("div",{style:{fontSize:12,color:"#ff4d4f",marginTop:8},children:"⚠ 请立即复制 SecretKey,此弹窗关闭后将无法再次获取。如遗失,请删除后重新申请。"})]})}),e.jsx(Vt,{open:!!N,ak:N,onClose:()=>D(null)})]})},{TextArea:Jt}=t.Input,{Text:Oe}=t.Typography;function Ys(){var z,Q;const[i,o]=s.useState("servers"),[a,r]=s.useState([]),[j,c]=s.useState(!1),[m,b]=s.useState(!1),[S,y]=s.useState(null),[p]=t.Form.useForm(),[g,P]=s.useState(null),[N,D]=s.useState([]),[x,v]=s.useState(null),[T,f]=s.useState("{}"),[M,K]=s.useState(""),[C,k]=s.useState(!1),[E,W]=s.useState(null);s.useEffect(()=>{h()},[]);const h=async()=>{c(!0);try{const d=localStorage.getItem("z_tenant")||"default",n=await Ie.list(d);r(Array.isArray(n)?n:(n==null?void 0:n.data)||n||[])}catch(d){console.warn("MCP API 不可用:",d==null?void 0:d.message),r([])}finally{c(!1)}},B=async()=>{try{const n={...await p.validateFields()};S?(n.id=S.id,await Ie.update(n),t.message.success("更新成功")):(await Ie.create(n),t.message.success("创建成功")),b(!1),y(null),p.resetFields(),h()}catch{}},F=d=>{y(d),p.setFieldsValue(d),b(!0)},A=async d=>{await Ie.delete(d),t.message.success("已删除"),h()},I=async d=>{W({loading:!0});try{const n=await Ie.test(d.id);W((n==null?void 0:n.data)||n)}catch(n){W({connected:!1,error:n.message})}},G=async d=>{P(d),v(null),K("");try{const n=await Ie.listTools(d.id),_=(n==null?void 0:n.data)||n;D((_==null?void 0:_.tools)||[])}catch{D([]),t.message.error("获取工具列表失败")}},u=d=>{v(d);const n=d.inputSchema;if(n!=null&&n.properties){const _={};Object.keys(n.properties).forEach($=>{_[$]=""}),f(JSON.stringify(_,null,2))}else f("{}");K("")},w=async()=>{if(!(!g||!x)){k(!0),K("Running...");try{let d={};try{d=JSON.parse(T)}catch{}const n=await Ie.callTool(g.id,x.name,d),_=(n==null?void 0:n.data)||n;_!=null&&_.content&&_.content.length>0?K(_.content[0].text||JSON.stringify(_.content,null,2)):K(JSON.stringify(_,null,2))}catch(d){K("Error: "+d.message)}finally{k(!1)}}},U=[{title:"名称",dataIndex:"serverName",key:"serverName",width:140},{title:"类型",dataIndex:"transportType",key:"transportType",width:80,render:d=>e.jsx(t.Tag,{color:d==="STDIO"?"purple":"blue",children:d||"HTTP"})},{title:"URL",dataIndex:"url",key:"url",ellipsis:!0},{title:"状态",dataIndex:"status",key:"status",width:80,render:d=>e.jsx(t.Tag,{color:d==="active"?"green":"default",children:d||"active"})},{title:"操作",key:"actions",width:260,render:(d,n)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.ApiOutlined,{}),onClick:()=>G(n),children:"工具"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.LinkOutlined,{}),onClick:()=>I(n),children:"测试"}),e.jsx(t.Button,{size:"small",onClick:()=>F(n),children:"编辑"}),e.jsx(t.Popconfirm,{title:"确认删除?",onConfirm:()=>A(n.id),children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{style:{height:"calc(100vh - 180px)",display:"flex",flexDirection:"column"},children:[e.jsxs(t.Tabs,{activeKey:i,onChange:o,tabBarExtraContent:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>{y(null),p.resetFields(),b(!0)},children:"添加服务"}),children:[e.jsx(t.Tabs.TabPane,{tab:"服务管理"},"servers"),e.jsx(t.Tabs.TabPane,{tab:"工具测试",disabled:!g},"test")]}),i==="servers"&&e.jsxs("div",{style:{flex:1,display:"flex",gap:16,overflow:"hidden"},children:[e.jsx("div",{style:{flex:g?"0 0 50%":1,overflow:"auto"},children:e.jsx(t.Table,{columns:U,dataSource:a,rowKey:"id",loading:j,size:"small",pagination:!1,onRow:d=>({onClick:()=>G(d),style:{background:(g==null?void 0:g.id)===d.id?"#e6f7ff":void 0,cursor:"pointer"}})})}),g&&e.jsxs("div",{style:{flex:"0 0 50%",borderLeft:"1px solid #f0f0f0",paddingLeft:16,overflow:"auto"},children:[e.jsxs("div",{style:{marginBottom:12,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(Oe,{strong:!0,style:{fontSize:15},children:[g.serverName," — 工具列表"]}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>G(g),children:"刷新"})]}),N.length===0?e.jsx("div",{style:{textAlign:"center",padding:40,color:"#999"},children:"暂无工具"}):N.map(d=>e.jsx(t.Card,{size:"small",hoverable:!0,style:{marginBottom:8,borderColor:(x==null?void 0:x.name)===d.name?"#1890ff":void 0},onClick:()=>{u(d),o("test")},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx(Oe,{strong:!0,children:d.name}),e.jsx("br",{}),e.jsx(Oe,{type:"secondary",style:{fontSize:12},children:d.description})]}),e.jsx(t.Tag,{color:"blue",style:{cursor:"pointer"},onClick:n=>{n.stopPropagation(),u(d),o("test")},children:"测试 →"})]})},d.name))]})]}),i==="test"&&x&&e.jsxs("div",{style:{flex:1,display:"flex",gap:16,overflow:"hidden"},children:[e.jsxs("div",{style:{flex:"0 0 40%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{marginBottom:8},children:[e.jsx(Oe,{strong:!0,children:x.name}),e.jsx(Oe,{type:"secondary",style:{marginLeft:8},children:x.description})]}),e.jsx(Oe,{type:"secondary",style:{marginBottom:4},children:"参数 (JSON):"}),e.jsx(Jt,{rows:8,value:T,onChange:d=>f(d.target.value),style:{fontFamily:"monospace",fontSize:13}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:w,loading:C,style:{marginTop:12},children:"执行"})]}),e.jsxs("div",{style:{flex:"0 0 60%",display:"flex",flexDirection:"column"},children:[e.jsx(Oe,{type:"secondary",style:{marginBottom:4},children:"结果:"}),e.jsx("pre",{style:{flex:1,overflow:"auto",background:"#f5f5f5",padding:12,borderRadius:4,fontFamily:"monospace",fontSize:13,margin:0,whiteSpace:"pre-wrap"},children:M||'点击"执行"查看结果'})]})]}),e.jsx(t.Modal,{title:"测试连接 - ",open:!!E,onCancel:()=>W(null),footer:e.jsx(t.Button,{onClick:()=>W(null),children:"关闭"}),children:E!=null&&E.loading?e.jsx(Oe,{children:"测试中..."}):E?e.jsxs(t.Descriptions,{column:1,size:"small",children:[e.jsx(t.Descriptions.Item,{label:"连接状态",children:e.jsx(t.Tag,{color:E.connected?"green":"red",children:E.connected?"成功":"失败"})}),E.serverInfo&&e.jsxs(t.Descriptions.Item,{label:"服务信息",children:[(z=E.serverInfo)==null?void 0:z.name," v",(Q=E.serverInfo)==null?void 0:Q.version]}),E.toolCount!==void 0&&e.jsx(t.Descriptions.Item,{label:"工具数量",children:E.toolCount}),E.error&&e.jsx(t.Descriptions.Item,{label:"错误",children:E.error})]}):null}),e.jsx(t.Modal,{title:S?"编辑 MCP 服务":"添加 MCP 服务",open:m,onOk:B,onCancel:()=>{b(!1),y(null),p.resetFields()},children:e.jsxs(t.Form,{form:p,layout:"vertical",initialValues:{transportType:"HTTP",timeout:60,status:"active"},children:[e.jsx(t.Form.Item,{name:"serverName",label:"服务名称",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"如: z-agent-mcp-impl-db"})}),e.jsx(t.Form.Item,{name:"transportType",label:"传输类型",children:e.jsx(t.Select,{options:[{label:"HTTP",value:"HTTP"},{label:"STDIO",value:"STDIO"}]})}),e.jsx(t.Form.Item,{name:"url",label:"URL",rules:[{required:!0}],children:e.jsx(t.Input,{placeholder:"http://localhost:8095/mcp"})}),e.jsx(t.Form.Item,{name:"authToken",label:"Auth Token",children:e.jsx(t.Input.Password,{placeholder:"Bearer token (可选)"})}),e.jsx(t.Form.Item,{name:"timeout",label:"超时(秒)",children:e.jsx(t.InputNumber,{min:5,max:300,style:{width:"100%"}})}),e.jsx(t.Form.Item,{name:"status",label:"状态",children:e.jsx(t.Select,{options:[{label:"启用",value:"active"},{label:"停用",value:"inactive"}]})}),e.jsx(t.Form.Item,{name:"remark",label:"备注",children:e.jsx(Jt,{rows:2})})]})})]})}const Re={private:{label:"私有",color:"default",icon:e.jsx(l.LockOutlined,{})},"public-read":{label:"公共读",color:"blue",icon:e.jsx(l.EyeOutlined,{})},"public-read-write":{label:"公共读写",color:"orange",icon:e.jsx(l.GlobalOutlined,{})},"authenticated-read":{label:"认证读",color:"purple",icon:e.jsx(l.TeamOutlined,{})}};function Qs(){const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState(!1),[m]=t.Form.useForm(),[b,S]=s.useState(!1),y=Be.useNavigate(),p=s.useCallback(async()=>{r(!0);try{const x=await me.listBuckets(),v=Array.isArray(x)?x:(x==null?void 0:x.data)||[];o(v)}catch(x){console.error("loadBuckets error:",x),t.message.error("加载桶列表失败:"+((x==null?void 0:x.message)||"未知错误"))}finally{r(!1)}},[]);s.useEffect(()=>{p()},[p]);const g=async()=>{try{const x=await m.validateFields();S(!0),await me.createBucket(x),t.message.success("桶创建成功"),c(!1),m.resetFields(),p()}catch(x){if(x!=null&&x.errorFields)return;t.message.error("创建失败:"+((x==null?void 0:x.message)||"未知错误"))}finally{S(!1)}},P=async x=>{try{await me.deleteBucket(x),t.message.success("已删除"),p()}catch(v){t.message.error("删除失败:"+((v==null?void 0:v.message)||"未知错误"))}},N=async(x,v)=>{try{await me.setBucketAcl(x,v),t.message.success("ACL 已更新"),p()}catch(T){t.message.error("设置 ACL 失败:"+((T==null?void 0:T.message)||"未知错误"))}},D=x=>({items:Object.keys(Re).map(v=>({key:v,label:Re[v].label,icon:Re[v].icon})),onClick:({key:v})=>N(x,v)});return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,background:"#fff",padding:"14px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)",marginBottom:16},children:[e.jsx(l.DatabaseOutlined,{style:{fontSize:18,color:"#1890ff"}}),e.jsx("span",{style:{fontSize:16,fontWeight:600},children:"对象存储"}),e.jsx(t.Tag,{color:"blue",children:"OSS Buckets"}),e.jsx("div",{style:{flex:1}}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:p,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>c(!0),children:"创建桶"})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"桶总数",value:i.length,prefix:e.jsx(l.ApartmentOutlined,{style:{color:"#1890ff"}})})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"公共读",value:i.filter(x=>x.acl==="public-read").length,valueStyle:{color:"#1890ff"},prefix:e.jsx(l.EyeOutlined,{})})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"私有",value:i.filter(x=>!x.acl||x.acl==="private").length,valueStyle:{color:"#999"},prefix:e.jsx(l.LockOutlined,{})})})})]}),a?e.jsx("div",{style:{textAlign:"center",padding:80},children:e.jsx(t.Spin,{size:"large"})}):i.length===0?e.jsx(t.Empty,{image:e.jsx(l.CloudOutlined,{style:{fontSize:64,color:"#bfbfbf"}}),description:e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,marginBottom:8},children:"还没有桶"}),e.jsx("div",{style:{color:"#999",fontSize:13,marginBottom:16},children:"创建一个桶来开始使用对象存储"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>c(!0),children:"创建第一个桶"})]}),style:{padding:80,background:"#fff",borderRadius:10}}):e.jsx(t.Row,{gutter:[16,16],children:i.map(x=>{var T;const v=Re[x.acl]||Re.private;return e.jsx(t.Col,{xs:24,sm:12,md:8,lg:6,children:e.jsxs(t.Card,{hoverable:!0,onClick:()=>y(`/ai/oss/bucket/${encodeURIComponent(x.name)}`),style:{borderRadius:12,border:"none",boxShadow:"0 2px 12px rgba(0,0,0,0.07)"},styles:{body:{padding:18}},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:10,background:"linear-gradient(135deg, #1890ff 0%, #36cfc9 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.FolderOutlined,{style:{fontSize:22,color:"#fff"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:15,fontWeight:600,color:"#262626",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:x.name}),e.jsxs("div",{style:{fontSize:12,color:"#999",marginTop:4},children:[x.region||"default"," · ",((T=x.createTime)==null?void 0:T.slice(0,10))||"-"]})]}),e.jsx(t.Dropdown,{trigger:["click"],menu:D(x.name),onClick:f=>f.stopPropagation(),children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.MoreOutlined,{}),onClick:f=>f.stopPropagation()})})]}),e.jsx("div",{style:{marginTop:14,display:"flex",gap:6,flexWrap:"wrap"},children:e.jsx(t.Tag,{color:v.color,icon:v.icon,children:v.label})}),e.jsxs("div",{style:{marginTop:14,paddingTop:12,borderTop:"1px solid #f5f5f5",display:"flex",gap:8,justifyContent:"space-between"},children:[e.jsx(t.Tooltip,{title:"进入桶",children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.AppstoreOutlined,{}),onClick:f=>{f.stopPropagation(),y(`/ai/oss/bucket/${encodeURIComponent(x.name)}`)},children:"浏览对象"})}),e.jsx(t.Popconfirm,{title:`确定删除桶 "${x.name}"?`,description:"桶必须为空才能删除",onConfirm:f=>{f==null||f.stopPropagation(),P(x.name)},onCancel:f=>f==null?void 0:f.stopPropagation(),okText:"确认",cancelText:"取消",okType:"danger",children:e.jsx(t.Button,{type:"text",size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:f=>f.stopPropagation(),children:"删除"})})]})]})},x.id||x.name)})}),e.jsx(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(l.CloudOutlined,{style:{color:"#1890ff"}}),e.jsx("span",{children:"创建存储桶"})]}),open:j,onCancel:()=>{c(!1),m.resetFields()},onOk:g,confirmLoading:b,okText:"创建",cancelText:"取消",destroyOnClose:!0,children:e.jsxs(t.Form,{form:m,layout:"vertical",initialValues:{acl:"private"},style:{marginTop:16},children:[e.jsx(t.Form.Item,{name:"name",label:"桶名称",rules:[{required:!0,message:"请输入桶名称"},{pattern:/^[a-z0-9][a-z0-9-]{2,62}[a-z0-9]$/,message:"只能包含小写字母、数字、连字符,长度 3-63"}],extra:"仅支持小写字母、数字、连字符,长度 3-63 字符",children:e.jsx(t.Input,{placeholder:"my-bucket",prefix:e.jsx(l.FolderOutlined,{})})}),e.jsx(t.Form.Item,{name:"region",label:"区域",initialValue:"default",children:e.jsx(t.Input,{placeholder:"default"})}),e.jsx(t.Form.Item,{name:"acl",label:"访问权限",initialValue:"private",children:e.jsx(t.Select,{options:Object.entries(Re).map(([x,v])=>({value:x,label:e.jsxs(t.Space,{children:[v.icon,v.label]})}))})})]})})]})}const Yt=i=>{if(!i||i===0)return"-";const o=["B","KB","MB","GB","TB"];let a=0,r=i;for(;r>=1024&&a<o.length-1;)r/=1024,a++;return r.toFixed(a===0?0:1)+" "+o[a]},Zs=i=>{var a;if(i.endsWith("/"))return e.jsx(l.FolderOutlined,{style:{color:"#faad14"}});const o=(a=i.split(".").pop())==null?void 0:a.toLowerCase();return["zip","tar","gz","rar","7z"].includes(o)?e.jsx(l.FileZipOutlined,{style:{color:"#722ed1"}}):["png","jpg","jpeg","gif","svg","webp"].includes(o)?e.jsx(l.FileImageOutlined,{style:{color:"#13c2c2"}}):["md","txt","log","json","xml","yaml","yml"].includes(o)?e.jsx(l.FileTextOutlined,{style:{color:"#52c41a"}}):e.jsx(l.FileOutlined,{style:{color:"#8c8c8c"}})};function Xs(){const{bucketName:i}=Be.useParams(),o=decodeURIComponent(i||""),a=Be.useNavigate(),[r,j]=s.useState([]),[c,m]=s.useState(!1),[b,S]=s.useState(""),[y,p]=s.useState({objectCount:0,totalSize:0}),[g,P]=s.useState(""),[N,D]=s.useState([]),[x,v]=s.useState(!1),[T,f]=s.useState(!1),[M]=t.Form.useForm();s.useRef(null);const K=s.useCallback(async(w=b)=>{if(o){m(!0);try{const U=await me.listObjects(o,w||void 0),z=Array.isArray(U)?U:(U==null?void 0:U.data)||[];j(z)}catch(U){t.message.error("加载对象失败:"+((U==null?void 0:U.message)||"未知错误")),j([])}finally{m(!1)}}},[o,b]),C=s.useCallback(async()=>{try{const w=await me.getBucketStats(o);p(w||{objectCount:0,totalSize:0})}catch{}},[o]);s.useEffect(()=>{S(""),D([])},[o]),s.useEffect(()=>{K(b),C()},[b,K,C]);const k=w=>{w.endsWith("/")&&(S(w),D([]))},E=w=>{S(w),D([])},W=async w=>{if(!w)return!1;v(!0);const U=(b||"")+w.name;try{await me.uploadObject(o,U,w),t.message.success(`已上传: ${w.name}`),K(b),C()}catch(z){t.message.error("上传失败:"+((z==null?void 0:z.message)||"未知错误"))}finally{v(!1)}return!1},h=async w=>{if(!(!w||w.length===0))try{w.length===1?await me.deleteObject(o,w[0]):await me.batchDelete(o,w),t.message.success(`已删除 ${w.length} 个`),D([]),K(b),C()}catch(U){t.message.error("删除失败:"+((U==null?void 0:U.message)||"未知错误"))}},B=async()=>{try{const w=await M.validateFields(),U=(b||"")+w.name+"/";await me.createFolder(o,U),t.message.success("文件夹已创建"),f(!1),M.resetFields(),K(b)}catch(w){if(w!=null&&w.errorFields)return;t.message.error("创建失败:"+((w==null?void 0:w.message)||"未知错误"))}},F=async w=>{try{const U=await me.presignedUrl(o,w,3600),z=(U==null?void 0:U.url)||me.downloadUrl(o,w);window.open(z,"_blank")}catch{window.open(me.downloadUrl(o,w),"_blank")}},A=async w=>{const U=(b||"")+"_copy_"+w.split("/").pop();try{await me.copyObject(o,w,o,U),t.message.success("已复制"),K(b)}catch(z){t.message.error("复制失败:"+((z==null?void 0:z.message)||"未知错误"))}},I=g?r.filter(w=>{var U;return(U=w.key)==null?void 0:U.toLowerCase().includes(g.toLowerCase())}):r,G=[{title:"名称",dataIndex:"key",render:(w,U)=>{const z=(w==null?void 0:w.endsWith("/"))||U.folder,Q=(w==null?void 0:w.split("/").filter(Boolean).pop())||w;return e.jsx("span",{style:{cursor:z?"pointer":"default",color:z?"#faad14":"#262626"},onClick:()=>z&&k(w),children:e.jsxs(t.Space,{children:[Zs(w),e.jsx("span",{style:{fontWeight:z?500:400},children:Q})]})})}},{title:"大小",dataIndex:"size",width:110,render:w=>Yt(w)},{title:"类型",dataIndex:"contentType",width:200,ellipsis:!0,render:w=>w?e.jsx(t.Tag,{children:w}):"-"},{title:"修改时间",dataIndex:"lastModified",width:180,render:w=>w?new Date(w).toLocaleString():"-"},{title:"操作",width:160,fixed:"right",render:(w,U)=>{var d;const Q=((d=U.key)==null?void 0:d.endsWith("/"))||U.folder?[{key:"enter",icon:e.jsx(l.FolderOutlined,{}),label:"进入"},{key:"delete",icon:e.jsx(l.DeleteOutlined,{}),label:"删除",danger:!0}]:[{key:"download",icon:e.jsx(l.DownloadOutlined,{}),label:"下载"},{key:"copy",icon:e.jsx(l.CopyOutlined,{}),label:"复制"},{key:"delete",icon:e.jsx(l.DeleteOutlined,{}),label:"删除",danger:!0}];return e.jsx(t.Dropdown,{trigger:["click"],menu:{items:Q,onClick:({key:n,domEvent:_})=>{_.stopPropagation(),n==="enter"?k(U.key):n==="download"?F(U.key):n==="copy"?A(U.key):n==="delete"&&h([U.key])}},children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.MoreOutlined,{})})})}}],u=[{title:"所有桶",onClick:()=>a("/ai/oss/bucket")},{title:o}];if(b){const w=b.split("/").filter(Boolean);let U="";w.forEach(z=>{U+=z+"/",u.push({title:z,onClick:()=>E(U)})})}return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,background:"#fff",padding:"14px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)",marginBottom:16},children:[e.jsx(t.Button,{type:"text",icon:e.jsx(l.ArrowLeftOutlined,{}),onClick:()=>a("/ai/oss/bucket"),children:"返回"}),e.jsx(l.FolderOutlined,{style:{fontSize:18,color:"#faad14"}}),e.jsx("span",{style:{fontSize:16,fontWeight:600},children:o}),e.jsx("div",{style:{flex:1}}),e.jsx(t.Input.Search,{placeholder:"搜索对象名...",value:g,onChange:w=>P(w.target.value),style:{width:220},allowClear:!0}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>{K(b),C()}})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"对象数",value:y.objectCount||0})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"总大小",value:Yt(y.totalSize)})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Card,{children:e.jsx(t.Statistic,{title:"Provider",value:y.activeProvider||"-",valueStyle:{fontSize:18,color:"#1890ff"},prefix:e.jsx(l.CloudOutlined,{})})})})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,background:"#fff",padding:"10px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)",marginBottom:12},children:[e.jsx(t.Breadcrumb,{items:u,style:{flex:1}}),N.length>0&&e.jsx(t.Popconfirm,{title:`确定删除 ${N.length} 个对象?`,onConfirm:()=>h(N),okText:"确认",cancelText:"取消",okType:"danger",children:e.jsxs(t.Button,{danger:!0,size:"small",icon:e.jsx(l.DeleteOutlined,{}),children:["批量删除 (",N.length,")"]})}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.FolderAddOutlined,{}),onClick:()=>f(!0),children:"新建文件夹"}),e.jsx(t.Upload,{beforeUpload:W,showUploadList:!1,disabled:x,children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.UploadOutlined,{}),loading:x,children:"上传文件"})})]}),e.jsx(t.Card,{styles:{body:{padding:0}},children:c?e.jsx("div",{style:{textAlign:"center",padding:60},children:e.jsx(t.Spin,{size:"large"})}):I.length===0?e.jsx(t.Empty,{image:e.jsx(l.CloudOutlined,{style:{fontSize:48,color:"#bfbfbf"}}),description:g?"没有匹配的对象":"桶是空的,上传第一个文件吧",style:{padding:60}}):e.jsx(t.Table,{rowKey:"key",columns:G,dataSource:I,pagination:!1,size:"middle",rowSelection:{selectedRowKeys:N,onChange:D},onRow:w=>({onDoubleClick:()=>{var U;((U=w.key)!=null&&U.endsWith("/")||w.folder)&&k(w.key)}})})}),e.jsx(t.Modal,{title:"新建文件夹",open:T,onCancel:()=>{f(!1),M.resetFields()},onOk:B,okText:"创建",cancelText:"取消",destroyOnClose:!0,children:e.jsxs(t.Form,{form:M,layout:"vertical",style:{marginTop:16},children:[e.jsx(t.Form.Item,{name:"name",label:"文件夹名",rules:[{required:!0,message:"请输入文件夹名"}],children:e.jsx(t.Input,{prefix:e.jsx(l.FolderOutlined,{}),placeholder:"my-folder"})}),e.jsxs("div",{style:{fontSize:12,color:"#999"},children:["将创建在:",e.jsxs("code",{children:[o,"/",b||""]})]})]})})]})}const qs=[{value:"string",label:"string"},{value:"number",label:"number"},{value:"boolean",label:"boolean"},{value:"object",label:"object"},{value:"array",label:"array"}];function ht({value:i=[],onChange:o,readonly:a=!1}){const r=(S,y,p)=>{const g=[...i];g[S]={...g[S],[y]:p},o(g)},j=S=>{const y=i.filter((p,g)=>g!==S);o(y)},c=(S,y)=>{const p=S+y;if(p<0||p>=i.length)return;const g=[...i],P=g[S];g[S]=g[p],g[p]=P,o(g)},m=()=>{o([...i,{name:"",type:"string",jsonPath:"",required:!1,description:""}])},b=[{title:"输出字段名",dataIndex:"name",width:150,render:(S,y,p)=>a?e.jsx("span",{style:{fontFamily:"monospace"},children:S}):e.jsx(t.Input,{size:"small",value:S,onChange:g=>r(p,"name",g.target.value),placeholder:"e.g. user_name"})},{title:"类型",dataIndex:"type",width:100,render:(S,y,p)=>a?e.jsx("span",{children:S}):e.jsx(t.Select,{size:"small",value:S,onChange:g=>r(p,"type",g),options:qs,style:{width:"100%"}})},{title:"JSONPath",dataIndex:"jsonPath",width:220,render:(S,y,p)=>a?e.jsx("span",{style:{fontFamily:"monospace",color:"#0958d9"},children:S}):e.jsx(t.Input,{size:"small",value:S,onChange:g=>r(p,"jsonPath",g.target.value),placeholder:"$.data.user.name",style:{fontFamily:"monospace"}})},{title:"必填",dataIndex:"required",width:60,render:(S,y,p)=>a?e.jsx("span",{style:{color:S?"#ff4d4f":"#999"},children:S?"是":"否"}):e.jsx(t.Switch,{size:"small",checked:S,onChange:g=>r(p,"required",g)})},{title:"描述",dataIndex:"description",width:160,render:(S,y,p)=>a?e.jsx("span",{style:{color:"#666"},children:S}):e.jsx(t.Input,{size:"small",value:S,onChange:g=>r(p,"description",g.target.value),placeholder:"字段说明"})},...a?[]:[{title:"操作",key:"action",width:100,render:(S,y,p)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Tooltip,{title:"上移",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.ArrowUpOutlined,{}),disabled:p===0,onClick:()=>c(p,-1)})}),e.jsx(t.Tooltip,{title:"下移",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.ArrowDownOutlined,{}),disabled:p===i.length-1,onClick:()=>c(p,1)})}),e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>j(p)})})]})}]];return e.jsxs("div",{children:[e.jsx(t.Table,{dataSource:i,columns:b,rowKey:(S,y)=>y,pagination:!1,size:"small",bordered:!0,style:{marginBottom:8}}),!a&&e.jsx(t.Button,{size:"small",type:"dashed",icon:e.jsx(l.PlusOutlined,{}),onClick:m,block:!0,children:"添加字段映射"}),i.length===0&&!a&&e.jsx("div",{style:{textAlign:"center",color:"#999",padding:12},children:"暂未配置输出字段映射。发布后 MCP 工具将返回原始响应体。"})]})}const{TextArea:$s}=t.Input,{Step:mt}=t.Steps;function Qt({open:i,onClose:o,onSuccess:a}){var B,F,A,I,G;const[r,j]=s.useState(0),[c,m]=s.useState(!1),[b,S]=s.useState(!1),[y,p]=s.useState(""),[g,P]=s.useState(null),[N,D]=s.useState([]),[x,v]=s.useState(null),[T,f]=s.useState("mapping"),M=()=>{j(0),p(""),P(null),D([]),v(null),f("mapping")},K=()=>{M(),o()},C=async()=>{if(!y.trim()){t.message.warning("请粘贴 curl 命令");return}m(!0);try{const u=await be.importCurl({curl:y});u!=null&&u.success?(P(u),D(u.outputMapping||[]),j(1)):t.message.error((u==null?void 0:u.message)||"解析失败")}catch(u){t.message.error("解析失败: "+((u==null?void 0:u.message)||"网络错误"))}finally{m(!1)}},k=async()=>{S(!0);try{const u=await be.previewMapping({curl:y,outputMapping:N.filter(w=>w.name&&w.jsonPath)});v(u),f("result")}catch(u){t.message.error("预览失败: "+((u==null?void 0:u.message)||"网络错误"))}finally{S(!1)}},E=async()=>{m(!0);try{const u=await be.importCurl({curl:y,outputMapping:N.filter(w=>w.name&&w.jsonPath)});u!=null&&u.success?(t.message.success(`脚本 [${u.scriptCode}] 创建成功`),M(),a==null||a(),o()):t.message.error((u==null?void 0:u.message)||"创建失败")}catch(u){t.message.error("创建失败: "+((u==null?void 0:u.message)||"网络错误"))}finally{m(!1)}},W=(B=g==null?void 0:g.request)==null?void 0:B.httpRequestLine,h=(A=(F=g==null?void 0:g.request)==null?void 0:F.httpRequestHeader)==null?void 0:A.headers;return e.jsxs(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(l.ApiOutlined,{}),"从 Curl 导入 API Bridge 脚本"]}),open:i,onCancel:K,width:900,footer:null,destroyOnClose:!0,children:[e.jsxs(t.Steps,{current:r,size:"small",style:{marginBottom:24},children:[e.jsx(mt,{title:"粘贴 curl",description:"输入 curl 命令"}),e.jsx(mt,{title:"配置映射",description:"设置字段映射"}),e.jsx(mt,{title:"确认创建",description:"保存脚本"})]}),r===0&&e.jsxs("div",{children:[e.jsx("p",{style:{color:"#666",marginBottom:8},children:"粘贴任意 HTTP curl 命令,系统将自动解析并生成 API_BRIDGE 脚本"}),e.jsx($s,{rows:8,value:y,onChange:u=>p(u.target.value),placeholder:`curl -X POST https://api.example.com/users \\
25
25
  -H "Authorization: Bearer \${token}" \\
26
26
  -H "Content-Type: application/json" \\
27
- -d '{"name": "\${name}", "email": "\${email}"}'`,style:{fontFamily:"monospace",fontSize:13,marginBottom:12}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CodeOutlined,{}),onClick:g,loading:d,block:!0,children:"解析 curl"})]}),n===1&&m&&e.jsxs("div",{children:[e.jsxs(t.Card,{size:"small",title:"请求信息",style:{marginBottom:16},children:[e.jsxs(t.Descriptions,{column:3,size:"small",children:[e.jsx(t.Descriptions.Item,{label:"方法",children:e.jsx(t.Tag,{color:"blue",children:(K==null?void 0:K.method)||"GET"})}),e.jsx(t.Descriptions.Item,{label:"URL",span:2,children:e.jsx(Text,{copyable:!0,style:{fontFamily:"monospace",fontSize:12},children:K==null?void 0:K.url})})]}),O&&Object.keys(O).length>0&&e.jsxs("div",{style:{marginTop:8},children:[e.jsx("span",{style:{fontSize:12,color:"#666",fontWeight:500},children:"请求头: "}),Object.entries(O).map(([p,y])=>e.jsxs(t.Tag,{style:{fontFamily:"monospace",fontSize:11},children:[p,": ",String(y).substring(0,40)]},p))]}),((k=m.inputParams)==null?void 0:k.length)>0&&e.jsxs("div",{style:{marginTop:8},children:[e.jsx("span",{style:{fontSize:12,color:"#666",fontWeight:500},children:"输入参数: "}),m.inputParams.map(p=>e.jsxs(t.Tag,{color:p.required?"orange":"default",style:{fontFamily:"monospace"},children:[p.name," ",e.jsxs("span",{style:{fontSize:10},children:["(",p.in,")"]})]},p.name))]})]}),e.jsx(t.Tabs,{activeKey:S,onChange:x,items:[{key:"mapping",label:"输出字段映射",children:e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:12,color:"#666",marginBottom:8},children:"配置 JSONPath 从响应中抽取字段。MCP 工具只返回映射后的字段。"}),e.jsx(xt,{value:F,onChange:N})]})},{key:"result",label:"试运行结果",children:e.jsxs("div",{children:[e.jsx(t.Button,{icon:e.jsx(l.ExperimentOutlined,{}),onClick:C,loading:f,style:{marginBottom:12},children:"试运行并查看映射结果"}),u&&e.jsxs("div",{children:[u.error?e.jsx(t.Alert,{type:"error",message:u.error,style:{marginBottom:12}}):e.jsxs(t.Descriptions,{column:3,size:"small",bordered:!0,style:{marginBottom:12},children:[e.jsx(t.Descriptions.Item,{label:"状态码",children:u.status}),e.jsxs(t.Descriptions.Item,{label:"耗时",children:[u.durationMs,"ms"]}),e.jsxs(t.Descriptions.Item,{label:"响应体大小",children:[(((_=u.bodyRaw)==null?void 0:_.length)||0).toLocaleString()," chars"]})]}),u.mapped&&Object.keys(u.mapped).length>0&&e.jsx(t.Card,{size:"small",title:"映射结果",style:{marginBottom:12},children:e.jsx("pre",{style:{fontFamily:"monospace",fontSize:12,margin:0,whiteSpace:"pre-wrap"},children:JSON.stringify(u.mapped,null,2)})}),u.bodyObject&&e.jsx(t.Card,{size:"small",title:"原始响应 (JSON)",style:{marginBottom:12},children:e.jsx("pre",{style:{fontFamily:"monospace",fontSize:12,margin:0,maxHeight:300,overflow:"auto",whiteSpace:"pre-wrap"},children:JSON.stringify(u.bodyObject,null,2)})})]})]})}]})]}),n===1&&m&&e.jsx("div",{style:{marginTop:16,textAlign:"right"},children:e.jsxs(t.Space,{children:[e.jsx(t.Button,{onClick:()=>{T(0),z(null)},children:"返回"}),e.jsx(t.Button,{onClick:C,loading:f,children:"试运行"}),e.jsx(t.Button,{type:"primary",onClick:P,loading:d,children:"创建脚本"})]})})]})}const{TextArea:qs}=t.Input;function Qt({open:o,onClose:i,onSuccess:a}){const[n,T]=s.useState(""),[d,b]=s.useState(null),[f,j]=s.useState(null),[w,h]=s.useState(!1),m=()=>{T(""),b(null),j(null)},z=()=>{m(),i()},F=()=>{if(!n.trim()){t.message.warning("请粘贴 OpenAPI JSON");return}try{const x=JSON.parse(n).paths;if(!x){t.message.warning("OpenAPI 中没有 paths 段");return}const D=[];for(const G of Object.keys(x)){const g=x[G];for(const C of["get","post","put","delete","patch"]){const P=g[C];P&&D.push({key:`${C}_${G}`,method:C.toUpperCase(),path:G,summary:P.summary||P.operationId||"",operationId:P.operationId||"-"})}}b(D),D.length===0?t.message.info("未找到可解析的接口"):t.message.success(`解析到 ${D.length} 个接口`)}catch(S){t.message.error("JSON 解析失败: "+S.message)}},N=async()=>{if(n.trim()){h(!0);try{const S=await be.importOpenApi({openApiJson:n});S!=null&&S.success?(j(S),t.message.success(`成功导入 ${S.count} 个脚本`)):t.message.error((S==null?void 0:S.message)||"导入失败")}catch(S){t.message.error("导入失败: "+((S==null?void 0:S.message)||"网络错误"))}finally{h(!1)}}},u=[{title:"方法",dataIndex:"method",key:"method",width:80,render:S=>{const x={GET:"green",POST:"blue",PUT:"orange",DELETE:"red",PATCH:"purple"};return e.jsx(t.Tag,{color:x[S]||"default",children:S})}},{title:"路径",dataIndex:"path",key:"path",width:280,render:S=>e.jsx("code",{style:{fontSize:12},children:S})},{title:"描述",dataIndex:"summary",key:"summary",ellipsis:!0},{title:"OperationId",dataIndex:"operationId",key:"operationId",width:160,render:S=>e.jsx(t.Tag,{style:{fontFamily:"monospace"},children:S})}],v=[{title:"方法",dataIndex:"method",key:"method",width:80,render:S=>{const x={GET:"green",POST:"blue",PUT:"orange",DELETE:"red",PATCH:"purple"};return e.jsx(t.Tag,{color:x[S]||"default",children:S})}},{title:"路径",dataIndex:"path",key:"path",width:280,render:S=>e.jsx("code",{style:{fontSize:12},children:S})},{title:"脚本编码",dataIndex:"scriptCode",key:"scriptCode",width:200,render:S=>e.jsx(t.Tag,{color:"blue",style:{fontFamily:"monospace"},children:S})},{title:"脚本名称",dataIndex:"scriptName",key:"scriptName",ellipsis:!0},{title:"结果",dataIndex:"created",key:"created",width:80,render:S=>S?e.jsx(t.Tag,{color:"green",children:"成功"}):e.jsx(t.Tag,{color:"red",children:"跳过"})}];return e.jsxs(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(l.ApiOutlined,{}),"从 OpenAPI 批量导入脚本"]}),open:o,onCancel:z,width:960,footer:null,destroyOnClose:!0,children:[!d&&!f&&e.jsxs("div",{children:[e.jsx("p",{style:{color:"#666",marginBottom:8},children:"粘贴 OpenAPI 3.0 / Swagger 2.0 规范的 JSON 内容,系统将自动为每个端点生成 API_BRIDGE 脚本。"}),e.jsx(qs,{rows:12,value:n,onChange:S=>T(S.target.value),placeholder:`{
27
+ -d '{"name": "\${name}", "email": "\${email}"}'`,style:{fontFamily:"monospace",fontSize:13,marginBottom:12}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CodeOutlined,{}),onClick:C,loading:c,block:!0,children:"解析 curl"})]}),r===1&&g&&e.jsxs("div",{children:[e.jsxs(t.Card,{size:"small",title:"请求信息",style:{marginBottom:16},children:[e.jsxs(t.Descriptions,{column:3,size:"small",children:[e.jsx(t.Descriptions.Item,{label:"方法",children:e.jsx(t.Tag,{color:"blue",children:(W==null?void 0:W.method)||"GET"})}),e.jsx(t.Descriptions.Item,{label:"URL",span:2,children:e.jsx(Text,{copyable:!0,style:{fontFamily:"monospace",fontSize:12},children:W==null?void 0:W.url})})]}),h&&Object.keys(h).length>0&&e.jsxs("div",{style:{marginTop:8},children:[e.jsx("span",{style:{fontSize:12,color:"#666",fontWeight:500},children:"请求头: "}),Object.entries(h).map(([u,w])=>e.jsxs(t.Tag,{style:{fontFamily:"monospace",fontSize:11},children:[u,": ",String(w).substring(0,40)]},u))]}),((I=g.inputParams)==null?void 0:I.length)>0&&e.jsxs("div",{style:{marginTop:8},children:[e.jsx("span",{style:{fontSize:12,color:"#666",fontWeight:500},children:"输入参数: "}),g.inputParams.map(u=>e.jsxs(t.Tag,{color:u.required?"orange":"default",style:{fontFamily:"monospace"},children:[u.name," ",e.jsxs("span",{style:{fontSize:10},children:["(",u.in,")"]})]},u.name))]})]}),e.jsx(t.Tabs,{activeKey:T,onChange:f,items:[{key:"mapping",label:"输出字段映射",children:e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:12,color:"#666",marginBottom:8},children:"配置 JSONPath 从响应中抽取字段。MCP 工具只返回映射后的字段。"}),e.jsx(ht,{value:N,onChange:D})]})},{key:"result",label:"试运行结果",children:e.jsxs("div",{children:[e.jsx(t.Button,{icon:e.jsx(l.ExperimentOutlined,{}),onClick:k,loading:b,style:{marginBottom:12},children:"试运行并查看映射结果"}),x&&e.jsxs("div",{children:[x.error?e.jsx(t.Alert,{type:"error",message:x.error,style:{marginBottom:12}}):e.jsxs(t.Descriptions,{column:3,size:"small",bordered:!0,style:{marginBottom:12},children:[e.jsx(t.Descriptions.Item,{label:"状态码",children:x.status}),e.jsxs(t.Descriptions.Item,{label:"耗时",children:[x.durationMs,"ms"]}),e.jsxs(t.Descriptions.Item,{label:"响应体大小",children:[(((G=x.bodyRaw)==null?void 0:G.length)||0).toLocaleString()," chars"]})]}),x.mapped&&Object.keys(x.mapped).length>0&&e.jsx(t.Card,{size:"small",title:"映射结果",style:{marginBottom:12},children:e.jsx("pre",{style:{fontFamily:"monospace",fontSize:12,margin:0,whiteSpace:"pre-wrap"},children:JSON.stringify(x.mapped,null,2)})}),x.bodyObject&&e.jsx(t.Card,{size:"small",title:"原始响应 (JSON)",style:{marginBottom:12},children:e.jsx("pre",{style:{fontFamily:"monospace",fontSize:12,margin:0,maxHeight:300,overflow:"auto",whiteSpace:"pre-wrap"},children:JSON.stringify(x.bodyObject,null,2)})})]})]})}]})]}),r===1&&g&&e.jsx("div",{style:{marginTop:16,textAlign:"right"},children:e.jsxs(t.Space,{children:[e.jsx(t.Button,{onClick:()=>{j(0),P(null)},children:"返回"}),e.jsx(t.Button,{onClick:k,loading:b,children:"试运行"}),e.jsx(t.Button,{type:"primary",onClick:E,loading:c,children:"创建脚本"})]})})]})}const{TextArea:el}=t.Input;function Zt({open:i,onClose:o,onSuccess:a}){const[r,j]=s.useState(""),[c,m]=s.useState(null),[b,S]=s.useState(null),[y,p]=s.useState(!1),g=()=>{j(""),m(null),S(null)},P=()=>{g(),o()},N=()=>{if(!r.trim()){t.message.warning("请粘贴 OpenAPI JSON");return}try{const f=JSON.parse(r).paths;if(!f){t.message.warning("OpenAPI 中没有 paths 段");return}const M=[];for(const K of Object.keys(f)){const C=f[K];for(const k of["get","post","put","delete","patch"]){const E=C[k];E&&M.push({key:`${k}_${K}`,method:k.toUpperCase(),path:K,summary:E.summary||E.operationId||"",operationId:E.operationId||"-"})}}m(M),M.length===0?t.message.info("未找到可解析的接口"):t.message.success(`解析到 ${M.length} 个接口`)}catch(T){t.message.error("JSON 解析失败: "+T.message)}},D=async()=>{if(r.trim()){p(!0);try{const T=await be.importOpenApi({openApiJson:r});T!=null&&T.success?(S(T),t.message.success(`成功导入 ${T.count} 个脚本`)):t.message.error((T==null?void 0:T.message)||"导入失败")}catch(T){t.message.error("导入失败: "+((T==null?void 0:T.message)||"网络错误"))}finally{p(!1)}}},x=[{title:"方法",dataIndex:"method",key:"method",width:80,render:T=>{const f={GET:"green",POST:"blue",PUT:"orange",DELETE:"red",PATCH:"purple"};return e.jsx(t.Tag,{color:f[T]||"default",children:T})}},{title:"路径",dataIndex:"path",key:"path",width:280,render:T=>e.jsx("code",{style:{fontSize:12},children:T})},{title:"描述",dataIndex:"summary",key:"summary",ellipsis:!0},{title:"OperationId",dataIndex:"operationId",key:"operationId",width:160,render:T=>e.jsx(t.Tag,{style:{fontFamily:"monospace"},children:T})}],v=[{title:"方法",dataIndex:"method",key:"method",width:80,render:T=>{const f={GET:"green",POST:"blue",PUT:"orange",DELETE:"red",PATCH:"purple"};return e.jsx(t.Tag,{color:f[T]||"default",children:T})}},{title:"路径",dataIndex:"path",key:"path",width:280,render:T=>e.jsx("code",{style:{fontSize:12},children:T})},{title:"脚本编码",dataIndex:"scriptCode",key:"scriptCode",width:200,render:T=>e.jsx(t.Tag,{color:"blue",style:{fontFamily:"monospace"},children:T})},{title:"脚本名称",dataIndex:"scriptName",key:"scriptName",ellipsis:!0},{title:"结果",dataIndex:"created",key:"created",width:80,render:T=>T?e.jsx(t.Tag,{color:"green",children:"成功"}):e.jsx(t.Tag,{color:"red",children:"跳过"})}];return e.jsxs(t.Modal,{title:e.jsxs(t.Space,{children:[e.jsx(l.ApiOutlined,{}),"从 OpenAPI 批量导入脚本"]}),open:i,onCancel:P,width:960,footer:null,destroyOnClose:!0,children:[!c&&!b&&e.jsxs("div",{children:[e.jsx("p",{style:{color:"#666",marginBottom:8},children:"粘贴 OpenAPI 3.0 / Swagger 2.0 规范的 JSON 内容,系统将自动为每个端点生成 API_BRIDGE 脚本。"}),e.jsx(el,{rows:12,value:r,onChange:T=>j(T.target.value),placeholder:`{
28
28
  "openapi": "3.0.0",
29
29
  "info": {...},
30
30
  "paths": {
@@ -36,9 +36,9 @@ React keys must be passed directly to JSX without using spread:
36
36
  }
37
37
  }
38
38
  }
39
- }`,style:{fontFamily:"monospace",fontSize:13,marginBottom:12}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.FileTextOutlined,{}),onClick:F,block:!0,children:"解析预览"})]}),d&&!f&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",message:`共解析到 ${d.length} 个接口,确认后将批量导入为 API_BRIDGE 脚本`,style:{marginBottom:12},showIcon:!0}),e.jsx(t.Table,{dataSource:d,columns:u,pagination:{pageSize:10},size:"small",bordered:!0,rowKey:"key"}),e.jsx("div",{style:{marginTop:16,textAlign:"right"},children:e.jsxs(t.Space,{children:[e.jsx(t.Button,{onClick:()=>{b(null),T("")},children:"返回修改"}),e.jsxs(t.Button,{type:"primary",icon:e.jsx(l.UploadOutlined,{}),onClick:N,loading:w,children:["导入 ",d.length," 个脚本"]})]})})]}),f&&e.jsxs("div",{children:[e.jsxs(t.Card,{style:{marginBottom:12,textAlign:"center"},children:[e.jsx(t.Progress,{type:"circle",percent:100,format:()=>`${f.count}`,width:80}),e.jsxs("div",{style:{marginTop:8,fontWeight:500},children:["成功导入 ",f.count," 个脚本"]})]}),e.jsx(t.Table,{dataSource:f.items||[],columns:v,pagination:{pageSize:10},size:"small",bordered:!0,rowKey:"scriptCode"}),e.jsx("div",{style:{marginTop:16,textAlign:"right"},children:e.jsx(t.Space,{children:e.jsx(t.Button,{onClick:()=>{m(),a==null||a(),i()},children:"完成"})})})]})]})}const{Text:Je,Paragraph:Ll}=t.Typography,$s=[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"},{value:"PATCH",label:"PATCH"},{value:"HEAD",label:"HEAD"},{value:"OPTIONS",label:"OPTIONS"}],el=[{value:"path",label:"path"},{value:"query",label:"query"},{value:"header",label:"header"},{value:"body",label:"body"}];function Zt({value:o,onChange:i,readonly:a=!1}){var S,x,D,G,g;const[n,T]=s.useState(null),[d,b]=s.useState(null);s.useEffect(()=>{if(!o){T({request:{httpRequestLine:{url:"",requestMethod:"GET"},httpRequestHeader:{headers:{}},httpRequestBody:{body:null}},inputParams:[],outputMapping:[]}),b(null);return}try{const C=typeof o=="string"?JSON.parse(o):o;C.request||(C.request={}),C.request.httpRequestLine||(C.request.httpRequestLine={}),C.request.httpRequestHeader||(C.request.httpRequestHeader={}),C.request.httpRequestBody||(C.request.httpRequestBody={}),C.inputParams||(C.inputParams=[]),C.outputMapping||(C.outputMapping=[]),T(C),b(null)}catch(C){b("JSON 解析失败: "+C.message)}},[o]);const f=s.useCallback(C=>{T(C),i==null||i(JSON.stringify(C,null,2))},[i]);if(d)return e.jsxs(t.Card,{size:"small",style:{borderColor:"#ff4d4f"},children:[e.jsx(Je,{type:"danger",children:d}),e.jsx("pre",{style:{fontFamily:"monospace",fontSize:12,marginTop:8,maxHeight:200,overflow:"auto"},children:typeof o=="string"?o.substring(0,500):String(o)})]});if(!n)return null;const j=((S=n.request)==null?void 0:S.httpRequestLine)||{},w=((D=(x=n.request)==null?void 0:x.httpRequestHeader)==null?void 0:D.headers)||{},h=C=>{const P=JSON.parse(JSON.stringify(n));P.request.httpRequestLine.requestMethod=C,f(P)},m=C=>{const P=JSON.parse(JSON.stringify(n));P.request.httpRequestLine.url=C,f(P)},z=(C,P,K)=>{const O=JSON.parse(JSON.stringify(n));O.inputParams[C][P]=K,f(O)},F=C=>{const P=JSON.parse(JSON.stringify(n));P.inputParams=P.inputParams.filter((K,O)=>O!==C),f(P)},N=()=>{const C=JSON.parse(JSON.stringify(n));C.inputParams.push({name:"",in:"query",required:!1,description:"",defaultValue:""}),f(C)},u=C=>{const P=JSON.parse(JSON.stringify(n));P.outputMapping=C,f(P)},v=[{title:"参数名",dataIndex:"name",width:140,render:(C,P,K)=>a?e.jsx(Je,{code:!0,children:C}):e.jsx(t.Input,{size:"small",value:C,onChange:O=>z(K,"name",O.target.value),placeholder:"param name"})},{title:"位置",dataIndex:"in",width:100,render:(C,P,K)=>a?e.jsx(t.Tag,{children:C}):e.jsx(t.Select,{size:"small",value:C,onChange:O=>z(K,"in",O),options:el,style:{width:"100%"}})},{title:"必填",dataIndex:"required",width:70,render:(C,P,K)=>a?e.jsx("span",{style:{color:C?"#ff4d4f":"#999"},children:C?"是":"否"}):e.jsx(t.Switch,{size:"small",checked:C,onChange:O=>z(K,"required",O)})},{title:"默认值",dataIndex:"defaultValue",width:120,render:(C,P,K)=>a?e.jsx("span",{children:C||"-"}):e.jsx(t.Input,{size:"small",value:C||"",onChange:O=>z(K,"defaultValue",O.target.value),placeholder:"default"})},{title:"描述",dataIndex:"description",render:(C,P,K)=>a?e.jsx("span",{style:{color:"#666"},children:C}):e.jsx(t.Input,{size:"small",value:C,onChange:O=>z(K,"description",O.target.value),placeholder:"描述"})},...a?[]:[{title:"",key:"action",width:50,render:(C,P,K)=>e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>F(K)})})}]];return e.jsxs("div",{children:[e.jsx(t.Card,{size:"small",title:"请求配置",style:{marginBottom:16},children:e.jsxs(t.Space,{style:{width:"100%"},direction:"vertical",size:"small",children:[e.jsxs(t.Space,{align:"center",style:{width:"100%"},children:[a?e.jsx(t.Tag,{color:"blue",style:{fontSize:14,padding:"2px 12px"},children:j.requestMethod||"GET"}):e.jsx(t.Select,{value:j.requestMethod||"GET",onChange:h,options:$s,style:{width:120}}),a?e.jsx(Je,{code:!0,style:{fontSize:13,wordBreak:"break-all"},children:j.url}):e.jsx(t.Input,{value:j.url||"",onChange:C=>m(C.target.value),placeholder:"https://api.example.com/resource/{id}?key=${key}",style:{fontFamily:"monospace",flex:1}})]}),Object.keys(w).length>0&&e.jsxs("div",{children:[e.jsx(Je,{type:"secondary",style:{fontSize:12},children:"请求头: "}),Object.entries(w).map(([C,P])=>e.jsxs(t.Tag,{style:{fontFamily:"monospace",fontSize:11},children:[C,": ",String(P).substring(0,50)]},C))]})]})}),e.jsx(t.Card,{size:"small",title:`输入参数 (${((G=n.inputParams)==null?void 0:G.length)||0})`,style:{marginBottom:16},extra:!a&&e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.PlusOutlined,{}),onClick:N,children:"添加"}),children:e.jsx(t.Table,{dataSource:n.inputParams||[],columns:v,rowKey:(C,P)=>P,pagination:!1,size:"small",locale:{emptyText:"暂无输入参数"}})}),e.jsx(t.Card,{size:"small",title:`输出字段映射 (${((g=n.outputMapping)==null?void 0:g.length)||0})`,children:e.jsx(xt,{value:n.outputMapping||[],onChange:u,readonly:a})})]})}const{TextArea:mt}=t.Input,{Text:gt,Paragraph:Xt}=t.Typography,tl=[{value:"EL",label:"EL (SpEL)"},{value:"GROOVY",label:"Groovy"},{value:"LUA",label:"Lua"},{value:"SQL",label:"SQL"},{value:"MOCK",label:"Mock Template"},{value:"API_BRIDGE",label:"API Bridge"}],sl=[{value:"NONE",label:"None"},{value:"HTTP",label:"HTTP"},{value:"MCP",label:"MCP"},{value:"BOTH",label:"HTTP + MCP"}],qt={0:{text:"Draft",color:"default"},1:{text:"Active",color:"green"},2:{text:"Disabled",color:"red"}},ll={NONE:"default",HTTP:"blue",MCP:"purple",BOTH:"cyan"},ol=[{id:1,scriptCode:"hello-el",scriptName:"Hello EL表达式",dslType:"EL",exposeAs:"HTTP",status:1,version:"1.0.0",httpPath:"/run/hello-el",sourceCode:"'Hello from ' + #name + '!'"},{id:2,scriptCode:"hello-groovy",scriptName:"Hello Groovy",dslType:"GROOVY",exposeAs:"NONE",status:1,version:"1.0.0",sourceCode:`def result = "Hello from Groovy!"
39
+ }`,style:{fontFamily:"monospace",fontSize:13,marginBottom:12}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.FileTextOutlined,{}),onClick:N,block:!0,children:"解析预览"})]}),c&&!b&&e.jsxs("div",{children:[e.jsx(t.Alert,{type:"info",message:`共解析到 ${c.length} 个接口,确认后将批量导入为 API_BRIDGE 脚本`,style:{marginBottom:12},showIcon:!0}),e.jsx(t.Table,{dataSource:c,columns:x,pagination:{pageSize:10},size:"small",bordered:!0,rowKey:"key"}),e.jsx("div",{style:{marginTop:16,textAlign:"right"},children:e.jsxs(t.Space,{children:[e.jsx(t.Button,{onClick:()=>{m(null),j("")},children:"返回修改"}),e.jsxs(t.Button,{type:"primary",icon:e.jsx(l.UploadOutlined,{}),onClick:D,loading:y,children:["导入 ",c.length," 个脚本"]})]})})]}),b&&e.jsxs("div",{children:[e.jsxs(t.Card,{style:{marginBottom:12,textAlign:"center"},children:[e.jsx(t.Progress,{type:"circle",percent:100,format:()=>`${b.count}`,width:80}),e.jsxs("div",{style:{marginTop:8,fontWeight:500},children:["成功导入 ",b.count," 个脚本"]})]}),e.jsx(t.Table,{dataSource:b.items||[],columns:v,pagination:{pageSize:10},size:"small",bordered:!0,rowKey:"scriptCode"}),e.jsx("div",{style:{marginTop:16,textAlign:"right"},children:e.jsx(t.Space,{children:e.jsx(t.Button,{onClick:()=>{g(),a==null||a(),o()},children:"完成"})})})]})]})}const{Text:Je,Paragraph:$l}=t.Typography,tl=[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"},{value:"DELETE",label:"DELETE"},{value:"PATCH",label:"PATCH"},{value:"HEAD",label:"HEAD"},{value:"OPTIONS",label:"OPTIONS"}],sl=[{value:"path",label:"path"},{value:"query",label:"query"},{value:"header",label:"header"},{value:"body",label:"body"}];function Xt({value:i,onChange:o,readonly:a=!1}){var T,f,M,K,C;const[r,j]=s.useState(null),[c,m]=s.useState(null);s.useEffect(()=>{if(!i){j({request:{httpRequestLine:{url:"",requestMethod:"GET"},httpRequestHeader:{headers:{}},httpRequestBody:{body:null}},inputParams:[],outputMapping:[]}),m(null);return}try{const k=typeof i=="string"?JSON.parse(i):i;k.request||(k.request={}),k.request.httpRequestLine||(k.request.httpRequestLine={}),k.request.httpRequestHeader||(k.request.httpRequestHeader={}),k.request.httpRequestBody||(k.request.httpRequestBody={}),k.inputParams||(k.inputParams=[]),k.outputMapping||(k.outputMapping=[]),j(k),m(null)}catch(k){m("JSON 解析失败: "+k.message)}},[i]);const b=s.useCallback(k=>{j(k),o==null||o(JSON.stringify(k,null,2))},[o]);if(c)return e.jsxs(t.Card,{size:"small",style:{borderColor:"#ff4d4f"},children:[e.jsx(Je,{type:"danger",children:c}),e.jsx("pre",{style:{fontFamily:"monospace",fontSize:12,marginTop:8,maxHeight:200,overflow:"auto"},children:typeof i=="string"?i.substring(0,500):String(i)})]});if(!r)return null;const S=((T=r.request)==null?void 0:T.httpRequestLine)||{},y=((M=(f=r.request)==null?void 0:f.httpRequestHeader)==null?void 0:M.headers)||{},p=k=>{const E=JSON.parse(JSON.stringify(r));E.request.httpRequestLine.requestMethod=k,b(E)},g=k=>{const E=JSON.parse(JSON.stringify(r));E.request.httpRequestLine.url=k,b(E)},P=(k,E,W)=>{const h=JSON.parse(JSON.stringify(r));h.inputParams[k][E]=W,b(h)},N=k=>{const E=JSON.parse(JSON.stringify(r));E.inputParams=E.inputParams.filter((W,h)=>h!==k),b(E)},D=()=>{const k=JSON.parse(JSON.stringify(r));k.inputParams.push({name:"",in:"query",required:!1,description:"",defaultValue:""}),b(k)},x=k=>{const E=JSON.parse(JSON.stringify(r));E.outputMapping=k,b(E)},v=[{title:"参数名",dataIndex:"name",width:140,render:(k,E,W)=>a?e.jsx(Je,{code:!0,children:k}):e.jsx(t.Input,{size:"small",value:k,onChange:h=>P(W,"name",h.target.value),placeholder:"param name"})},{title:"位置",dataIndex:"in",width:100,render:(k,E,W)=>a?e.jsx(t.Tag,{children:k}):e.jsx(t.Select,{size:"small",value:k,onChange:h=>P(W,"in",h),options:sl,style:{width:"100%"}})},{title:"必填",dataIndex:"required",width:70,render:(k,E,W)=>a?e.jsx("span",{style:{color:k?"#ff4d4f":"#999"},children:k?"是":"否"}):e.jsx(t.Switch,{size:"small",checked:k,onChange:h=>P(W,"required",h)})},{title:"默认值",dataIndex:"defaultValue",width:120,render:(k,E,W)=>a?e.jsx("span",{children:k||"-"}):e.jsx(t.Input,{size:"small",value:k||"",onChange:h=>P(W,"defaultValue",h.target.value),placeholder:"default"})},{title:"描述",dataIndex:"description",render:(k,E,W)=>a?e.jsx("span",{style:{color:"#666"},children:k}):e.jsx(t.Input,{size:"small",value:k,onChange:h=>P(W,"description",h.target.value),placeholder:"描述"})},...a?[]:[{title:"",key:"action",width:50,render:(k,E,W)=>e.jsx(t.Tooltip,{title:"删除",children:e.jsx(t.Button,{size:"small",type:"text",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>N(W)})})}]];return e.jsxs("div",{children:[e.jsx(t.Card,{size:"small",title:"请求配置",style:{marginBottom:16},children:e.jsxs(t.Space,{style:{width:"100%"},direction:"vertical",size:"small",children:[e.jsxs(t.Space,{align:"center",style:{width:"100%"},children:[a?e.jsx(t.Tag,{color:"blue",style:{fontSize:14,padding:"2px 12px"},children:S.requestMethod||"GET"}):e.jsx(t.Select,{value:S.requestMethod||"GET",onChange:p,options:tl,style:{width:120}}),a?e.jsx(Je,{code:!0,style:{fontSize:13,wordBreak:"break-all"},children:S.url}):e.jsx(t.Input,{value:S.url||"",onChange:k=>g(k.target.value),placeholder:"https://api.example.com/resource/{id}?key=${key}",style:{fontFamily:"monospace",flex:1}})]}),Object.keys(y).length>0&&e.jsxs("div",{children:[e.jsx(Je,{type:"secondary",style:{fontSize:12},children:"请求头: "}),Object.entries(y).map(([k,E])=>e.jsxs(t.Tag,{style:{fontFamily:"monospace",fontSize:11},children:[k,": ",String(E).substring(0,50)]},k))]})]})}),e.jsx(t.Card,{size:"small",title:`输入参数 (${((K=r.inputParams)==null?void 0:K.length)||0})`,style:{marginBottom:16},extra:!a&&e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.PlusOutlined,{}),onClick:D,children:"添加"}),children:e.jsx(t.Table,{dataSource:r.inputParams||[],columns:v,rowKey:(k,E)=>E,pagination:!1,size:"small",locale:{emptyText:"暂无输入参数"}})}),e.jsx(t.Card,{size:"small",title:`输出字段映射 (${((C=r.outputMapping)==null?void 0:C.length)||0})`,children:e.jsx(ht,{value:r.outputMapping||[],onChange:x,readonly:a})})]})}const{TextArea:gt}=t.Input,{Text:ft,Paragraph:qt}=t.Typography,ll=[{value:"EL",label:"EL (SpEL)"},{value:"GROOVY",label:"Groovy"},{value:"LUA",label:"Lua"},{value:"SQL",label:"SQL"},{value:"MOCK",label:"Mock Template"},{value:"API_BRIDGE",label:"API Bridge"}],ol=[{value:"NONE",label:"None"},{value:"HTTP",label:"HTTP"},{value:"MCP",label:"MCP"},{value:"BOTH",label:"HTTP + MCP"}],$t={0:{text:"Draft",color:"default"},1:{text:"Active",color:"green"},2:{text:"Disabled",color:"red"}},il={NONE:"default",HTTP:"blue",MCP:"purple",BOTH:"cyan"},rl=[{id:1,scriptCode:"hello-el",scriptName:"Hello EL表达式",dslType:"EL",exposeAs:"HTTP",status:1,version:"1.0.0",httpPath:"/run/hello-el",sourceCode:"'Hello from ' + #name + '!'"},{id:2,scriptCode:"hello-groovy",scriptName:"Hello Groovy",dslType:"GROOVY",exposeAs:"NONE",status:1,version:"1.0.0",sourceCode:`def result = "Hello from Groovy!"
40
40
  return result`},{id:3,scriptCode:"mock-users",scriptName:"Mock Users API",dslType:"MOCK",exposeAs:"HTTP",status:1,version:"1.0.0",httpPath:"/run/mock-users",sourceCode:'{"users": [{"name": "@name", "email": "@email"}]}'},{id:4,scriptCode:"parse-sql",scriptName:"SQL解析器",dslType:"SQL",exposeAs:"NONE",status:1,version:"1.0.0",sourceCode:"SELECT id, name FROM users WHERE status = 1"},{id:5,scriptCode:"lua-greet",scriptName:"Lua问候",dslType:"LUA",exposeAs:"NONE",status:0,version:"0.1.0",sourceCode:'return "Hello from Lua!"'},{id:6,scriptCode:"fetch-weather",scriptName:"Fetch Weather",dslType:"API_BRIDGE",exposeAs:"MCP",status:1,version:"1.0.0",mcpToolName:"fetch_weather",sourceCode:`source: https://api.weather.com
41
- method: GET`}];function il(){const[o,i]=s.useState([]),[a,n]=s.useState(!1),[T,d]=s.useState(!1),[b,f]=s.useState(!1),[j,w]=s.useState(null),[h]=t.Form.useForm(),[m,z]=s.useState(!1),[F,N]=s.useState(null),[u,v]=s.useState("{}"),[S,x]=s.useState(""),[D,G]=s.useState(!1),[g,C]=s.useState(!1),[P,K]=s.useState(!1),[O,V]=s.useState(null),A=t.Form.useWatch("dslType",h)==="API_BRIDGE";s.useEffect(()=>{k()},[]);const k=async()=>{n(!0);try{const R=await be.list();i(Array.isArray(R)?R:(R==null?void 0:R.data)||R||[]),d(!1)}catch(R){console.warn("Script API unavailable:",R==null?void 0:R.message),i(ol),d(!0),t.message.warning("后端未连接,显示模拟数据")}finally{n(!1)}},_=()=>{w(null),h.resetFields(),h.setFieldsValue({dslType:"EL",exposeAs:"NONE",status:0}),V(null),f(!0)},p=R=>{V(R==="API_BRIDGE"?JSON.stringify({request:{httpRequestLine:{url:"",requestMethod:"GET"},httpRequestHeader:{headers:{}},httpRequestBody:{body:null}},inputParams:[],outputMapping:[]}):null)},y=R=>{w(R),h.setFieldsValue(R),R.dslType==="API_BRIDGE"?V(R.sourceCode):V(null),f(!0)},M=async()=>{try{const R=await h.validateFields();R.dslType==="API_BRIDGE"&&O!=null&&(R.sourceCode=O),j?(await be.update(j.scriptCode,R),t.message.success("更新成功")):(await be.create(R),t.message.success("创建成功")),f(!1),V(null),k()}catch(R){if(R!=null&&R.errorFields)return;t.message.error("保存失败: "+((R==null?void 0:R.message)||"未知错误"))}},E=async R=>{try{await be.delete(R),t.message.success("删除成功"),k()}catch{t.message.error("删除失败")}},Q=R=>{N(R),v("{}"),x(""),z(!0)},c=async()=>{if(F){G(!0);try{const R=JSON.parse(u),se=await be.run(F.scriptCode,R);x(JSON.stringify(se,null,2))}catch(R){x("Error: "+((R==null?void 0:R.message)||"执行失败"))}finally{G(!1)}}},r=async(R,se)=>{try{await be.publish(R.scriptCode,se||"HTTP"),t.message.success("发布成功"),k()}catch{t.message.error("发布失败")}},L=async R=>{try{await be.unpublish(R.scriptCode),t.message.success("已取消发布"),k()}catch{t.message.error("操作失败")}},$=[{title:"名称",dataIndex:"scriptName",key:"scriptName",width:180,render:(R,se)=>e.jsxs(t.Space,{children:[e.jsx(l.CodeOutlined,{}),e.jsx(gt,{strong:!0,children:R})]})},{title:"编码",dataIndex:"scriptCode",key:"scriptCode",width:150,render:R=>e.jsx(gt,{code:!0,copyable:{text:R},children:R})},{title:"DSL类型",dataIndex:"dslType",key:"dslType",width:120,render:R=>e.jsx(t.Tag,{children:R})},{title:"暴露方式",dataIndex:"exposeAs",key:"exposeAs",width:120,render:R=>e.jsx(t.Tag,{color:ll[R]||"default",children:R})},{title:"状态",dataIndex:"status",key:"status",width:100,render:R=>{const se=qt[R]||qt[0];return e.jsx(t.Tag,{color:se.color,children:se.text})}},{title:"版本",dataIndex:"version",key:"version",width:80},{title:"HTTP路径",dataIndex:"httpPath",key:"httpPath",width:180,render:R=>R?e.jsx(gt,{type:"secondary",copyable:{text:R},children:R}):"-"},{title:"MCP工具名",dataIndex:"mcpToolName",key:"mcpToolName",width:160,render:R=>R?e.jsx(t.Tag,{color:"purple",children:R}):"-"},{title:"操作",key:"action",width:260,fixed:"right",render:(R,se)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Tooltip,{title:"运行测试",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:()=>Q(se),children:"运行"})}),e.jsx(t.Tooltip,{title:"编辑",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.EditOutlined,{}),onClick:()=>y(se)})}),se.exposeAs==="NONE"?e.jsx(t.Tooltip,{title:"发布为HTTP",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.CloudUploadOutlined,{}),onClick:()=>r(se,"HTTP"),children:"发布"})}):e.jsx(t.Tooltip,{title:"取消发布",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.CloudDownloadOutlined,{}),onClick:()=>L(se),children:"取消"})}),e.jsx(t.Popconfirm,{title:"确认删除?",onConfirm:()=>E(se.scriptCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[T&&e.jsxs("div",{style:{padding:"8px 16px",marginBottom:16,background:"#fffbe6",border:"1px solid #ffe58f",borderRadius:4},children:[e.jsx(t.Tag,{color:"orange",children:"Mock"})," 后端未连接,当前显示模拟数据"]}),e.jsxs(t.Card,{title:"脚本中心",extra:e.jsxs(t.Space,{children:[e.jsx(t.Button,{icon:e.jsx(l.ImportOutlined,{}),onClick:()=>C(!0),children:"导入 Curl"}),e.jsx(t.Button,{icon:e.jsx(l.CloudServerOutlined,{}),onClick:()=>K(!0),children:"导入 OpenAPI"}),e.jsx(t.Button,{icon:e.jsx(l.PlayCircleOutlined,{}),onClick:k,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:_,children:"新建脚本"})]}),children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"总脚本数",value:o.length})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"已发布",value:o.filter(R=>R.exposeAs!=="NONE").length})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"HTTP",value:o.filter(R=>R.exposeAs==="HTTP"||R.exposeAs==="BOTH").length})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"MCP",value:o.filter(R=>R.exposeAs==="MCP"||R.exposeAs==="BOTH").length})})]}),e.jsx(t.Table,{dataSource:o,columns:$,rowKey:"id",loading:a,pagination:{pageSize:10},scroll:{x:1300},size:"small"})]}),e.jsx(t.Modal,{title:j?"编辑脚本":"新建脚本",open:b,onCancel:()=>f(!1),onOk:M,width:800,okText:"保存",cancelText:"取消",children:e.jsxs(t.Form,{form:h,layout:"vertical",style:{marginTop:16},children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"scriptName",label:"脚本名称",rules:[{required:!0,message:"请输入名称"}],children:e.jsx(t.Input,{placeholder:"e.g. Hello World"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"scriptCode",label:"脚本编码",rules:[{required:!0,message:"请输入编码"}],children:e.jsx(t.Input,{placeholder:"e.g. hello-world",disabled:!!j})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"dslType",label:"DSL类型",children:e.jsx(t.Select,{options:tl,onChange:p})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"exposeAs",label:"暴露方式",children:e.jsx(t.Select,{options:sl})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"version",label:"版本",children:e.jsx(t.Input,{placeholder:"1.0.0"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input,{placeholder:"脚本描述"})}),A?e.jsx(t.Form.Item,{label:"API Bridge 配置",children:e.jsx(Zt,{value:O,onChange:V})}):e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"inputSchema",label:"输入 Schema (JSON)",children:e.jsx(mt,{rows:3,placeholder:'{"type": "object", "properties": {"name": {"type": "string"}}}'})}),e.jsx(t.Form.Item,{name:"sourceCode",label:"源代码",rules:[{required:!0,message:"请输入源代码"}],children:e.jsx(mt,{rows:12,placeholder:"输入DSL脚本代码...",style:{fontFamily:"monospace",fontSize:13}})})]})]})}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(l.PlayCircleOutlined,{}),"运行测试: ",F==null?void 0:F.scriptName]}),open:m,onClose:()=>z(!1),width:600,children:F&&e.jsxs("div",{children:[e.jsxs(t.Descriptions,{column:1,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(t.Descriptions.Item,{label:"编码",children:F.scriptCode}),e.jsx(t.Descriptions.Item,{label:"DSL类型",children:F.dslType}),e.jsx(t.Descriptions.Item,{label:"暴露方式",children:F.exposeAs})]}),e.jsx(Xt,{strong:!0,children:"输入参数 (JSON):"}),e.jsx(mt,{rows:5,value:u,onChange:R=>v(R.target.value),style:{fontFamily:"monospace",fontSize:13,marginBottom:12}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),loading:D,onClick:c,block:!0,children:"执行"}),S&&e.jsxs("div",{style:{marginTop:16},children:[e.jsx(Xt,{strong:!0,children:"执行结果:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:400,overflow:"auto",fontSize:13,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:S})]})]})}),e.jsx(Yt,{open:g,onClose:()=>C(!1),onSuccess:k}),e.jsx(Qt,{open:P,onClose:()=>K(!1),onSuccess:k})]})}const $t=[{id:1,skillCode:"code-review",skillName:"代码审查",categoryCode:"backend",version:"1.2.0",author:"zifang",status:"PUBLISHED",description:"自动审查代码质量,检测潜在 Bug 和安全漏洞,支持 Java/Python/Go 等多种语言。",tags:"java,python,code-quality,lint",downloadCount:128,content:`# 代码审查技能
41
+ method: GET`}];function nl(){const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState(!1),[m,b]=s.useState(!1),[S,y]=s.useState(null),[p]=t.Form.useForm(),[g,P]=s.useState(!1),[N,D]=s.useState(null),[x,v]=s.useState("{}"),[T,f]=s.useState(""),[M,K]=s.useState(!1),[C,k]=s.useState(!1),[E,W]=s.useState(!1),[h,B]=s.useState(null),A=t.Form.useWatch("dslType",p)==="API_BRIDGE";s.useEffect(()=>{I()},[]);const I=async()=>{r(!0);try{const R=await be.list();o(Array.isArray(R)?R:(R==null?void 0:R.data)||R||[]),c(!1)}catch(R){console.warn("Script API unavailable:",R==null?void 0:R.message),o(rl),c(!0),t.message.warning("后端未连接,显示模拟数据")}finally{r(!1)}},G=()=>{y(null),p.resetFields(),p.setFieldsValue({dslType:"EL",exposeAs:"NONE",status:0}),B(null),b(!0)},u=R=>{B(R==="API_BRIDGE"?JSON.stringify({request:{httpRequestLine:{url:"",requestMethod:"GET"},httpRequestHeader:{headers:{}},httpRequestBody:{body:null}},inputParams:[],outputMapping:[]}):null)},w=R=>{y(R),p.setFieldsValue(R),R.dslType==="API_BRIDGE"?B(R.sourceCode):B(null),b(!0)},U=async()=>{try{const R=await p.validateFields();R.dslType==="API_BRIDGE"&&h!=null&&(R.sourceCode=h),S?(await be.update(S.scriptCode,R),t.message.success("更新成功")):(await be.create(R),t.message.success("创建成功")),b(!1),B(null),I()}catch(R){if(R!=null&&R.errorFields)return;t.message.error("保存失败: "+((R==null?void 0:R.message)||"未知错误"))}},z=async R=>{try{await be.delete(R),t.message.success("删除成功"),I()}catch{t.message.error("删除失败")}},Q=R=>{D(R),v("{}"),f(""),P(!0)},d=async()=>{if(N){K(!0);try{const R=JSON.parse(x),se=await be.run(N.scriptCode,R);f(JSON.stringify(se,null,2))}catch(R){f("Error: "+((R==null?void 0:R.message)||"执行失败"))}finally{K(!1)}}},n=async(R,se)=>{try{await be.publish(R.scriptCode,se||"HTTP"),t.message.success("发布成功"),I()}catch{t.message.error("发布失败")}},_=async R=>{try{await be.unpublish(R.scriptCode),t.message.success("已取消发布"),I()}catch{t.message.error("操作失败")}},$=[{title:"名称",dataIndex:"scriptName",key:"scriptName",width:180,render:(R,se)=>e.jsxs(t.Space,{children:[e.jsx(l.CodeOutlined,{}),e.jsx(ft,{strong:!0,children:R})]})},{title:"编码",dataIndex:"scriptCode",key:"scriptCode",width:150,render:R=>e.jsx(ft,{code:!0,copyable:{text:R},children:R})},{title:"DSL类型",dataIndex:"dslType",key:"dslType",width:120,render:R=>e.jsx(t.Tag,{children:R})},{title:"暴露方式",dataIndex:"exposeAs",key:"exposeAs",width:120,render:R=>e.jsx(t.Tag,{color:il[R]||"default",children:R})},{title:"状态",dataIndex:"status",key:"status",width:100,render:R=>{const se=$t[R]||$t[0];return e.jsx(t.Tag,{color:se.color,children:se.text})}},{title:"版本",dataIndex:"version",key:"version",width:80},{title:"HTTP路径",dataIndex:"httpPath",key:"httpPath",width:180,render:R=>R?e.jsx(ft,{type:"secondary",copyable:{text:R},children:R}):"-"},{title:"MCP工具名",dataIndex:"mcpToolName",key:"mcpToolName",width:160,render:R=>R?e.jsx(t.Tag,{color:"purple",children:R}):"-"},{title:"操作",key:"action",width:260,fixed:"right",render:(R,se)=>e.jsxs(t.Space,{size:"small",children:[e.jsx(t.Tooltip,{title:"运行测试",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:()=>Q(se),children:"运行"})}),e.jsx(t.Tooltip,{title:"编辑",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.EditOutlined,{}),onClick:()=>w(se)})}),se.exposeAs==="NONE"?e.jsx(t.Tooltip,{title:"发布为HTTP",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.CloudUploadOutlined,{}),onClick:()=>n(se,"HTTP"),children:"发布"})}):e.jsx(t.Tooltip,{title:"取消发布",children:e.jsx(t.Button,{size:"small",type:"link",icon:e.jsx(l.CloudDownloadOutlined,{}),onClick:()=>_(se),children:"取消"})}),e.jsx(t.Popconfirm,{title:"确认删除?",onConfirm:()=>z(se.scriptCode),children:e.jsx(t.Button,{size:"small",type:"link",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[j&&e.jsxs("div",{style:{padding:"8px 16px",marginBottom:16,background:"#fffbe6",border:"1px solid #ffe58f",borderRadius:4},children:[e.jsx(t.Tag,{color:"orange",children:"Mock"})," 后端未连接,当前显示模拟数据"]}),e.jsxs(t.Card,{title:"脚本中心",extra:e.jsxs(t.Space,{children:[e.jsx(t.Button,{icon:e.jsx(l.ImportOutlined,{}),onClick:()=>k(!0),children:"导入 Curl"}),e.jsx(t.Button,{icon:e.jsx(l.CloudServerOutlined,{}),onClick:()=>W(!0),children:"导入 OpenAPI"}),e.jsx(t.Button,{icon:e.jsx(l.PlayCircleOutlined,{}),onClick:I,children:"刷新"}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:G,children:"新建脚本"})]}),children:[e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"总脚本数",value:i.length})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"已发布",value:i.filter(R=>R.exposeAs!=="NONE").length})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"HTTP",value:i.filter(R=>R.exposeAs==="HTTP"||R.exposeAs==="BOTH").length})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Statistic,{title:"MCP",value:i.filter(R=>R.exposeAs==="MCP"||R.exposeAs==="BOTH").length})})]}),e.jsx(t.Table,{dataSource:i,columns:$,rowKey:"id",loading:a,pagination:{pageSize:10},scroll:{x:1300},size:"small"})]}),e.jsx(t.Modal,{title:S?"编辑脚本":"新建脚本",open:m,onCancel:()=>b(!1),onOk:U,width:800,okText:"保存",cancelText:"取消",children:e.jsxs(t.Form,{form:p,layout:"vertical",style:{marginTop:16},children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"scriptName",label:"脚本名称",rules:[{required:!0,message:"请输入名称"}],children:e.jsx(t.Input,{placeholder:"e.g. Hello World"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"scriptCode",label:"脚本编码",rules:[{required:!0,message:"请输入编码"}],children:e.jsx(t.Input,{placeholder:"e.g. hello-world",disabled:!!S})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"dslType",label:"DSL类型",children:e.jsx(t.Select,{options:ll,onChange:u})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"exposeAs",label:"暴露方式",children:e.jsx(t.Select,{options:ol})})}),e.jsx(t.Col,{span:8,children:e.jsx(t.Form.Item,{name:"version",label:"版本",children:e.jsx(t.Input,{placeholder:"1.0.0"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(t.Input,{placeholder:"脚本描述"})}),A?e.jsx(t.Form.Item,{label:"API Bridge 配置",children:e.jsx(Xt,{value:h,onChange:B})}):e.jsxs(e.Fragment,{children:[e.jsx(t.Form.Item,{name:"inputSchema",label:"输入 Schema (JSON)",children:e.jsx(gt,{rows:3,placeholder:'{"type": "object", "properties": {"name": {"type": "string"}}}'})}),e.jsx(t.Form.Item,{name:"sourceCode",label:"源代码",rules:[{required:!0,message:"请输入源代码"}],children:e.jsx(gt,{rows:12,placeholder:"输入DSL脚本代码...",style:{fontFamily:"monospace",fontSize:13}})})]})]})}),e.jsx(t.Drawer,{title:e.jsxs(t.Space,{children:[e.jsx(l.PlayCircleOutlined,{}),"运行测试: ",N==null?void 0:N.scriptName]}),open:g,onClose:()=>P(!1),width:600,children:N&&e.jsxs("div",{children:[e.jsxs(t.Descriptions,{column:1,size:"small",bordered:!0,style:{marginBottom:16},children:[e.jsx(t.Descriptions.Item,{label:"编码",children:N.scriptCode}),e.jsx(t.Descriptions.Item,{label:"DSL类型",children:N.dslType}),e.jsx(t.Descriptions.Item,{label:"暴露方式",children:N.exposeAs})]}),e.jsx(qt,{strong:!0,children:"输入参数 (JSON):"}),e.jsx(gt,{rows:5,value:x,onChange:R=>v(R.target.value),style:{fontFamily:"monospace",fontSize:13,marginBottom:12}}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),loading:M,onClick:d,block:!0,children:"执行"}),T&&e.jsxs("div",{style:{marginTop:16},children:[e.jsx(qt,{strong:!0,children:"执行结果:"}),e.jsx("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:4,maxHeight:400,overflow:"auto",fontSize:13,fontFamily:"monospace",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:T})]})]})}),e.jsx(Qt,{open:C,onClose:()=>k(!1),onSuccess:I}),e.jsx(Zt,{open:E,onClose:()=>W(!1),onSuccess:I})]})}const es=[{id:1,skillCode:"code-review",skillName:"代码审查",categoryCode:"backend",version:"1.2.0",author:"zifang",status:"PUBLISHED",description:"自动审查代码质量,检测潜在 Bug 和安全漏洞,支持 Java/Python/Go 等多种语言。",tags:"java,python,code-quality,lint",downloadCount:128,content:`# 代码审查技能
42
42
 
43
43
  自动分析代码变更并给出审查意见。`,files:[{path:"SKILL.md",content:`# Code Review Skill
44
44
 
@@ -210,10 +210,10 @@ components:
210
210
  id: { type: integer }
211
211
  name: { type: string }
212
212
  email: { type: string }
213
- `}]}],ft=[{categoryCode:"backend",categoryName:"后端开发",parentCode:"",skillCount:2},{categoryCode:"frontend",categoryName:"前端开发",parentCode:"",skillCount:2},{categoryCode:"devops",categoryName:"DevOps",parentCode:"",skillCount:1},{categoryCode:"testing",categoryName:"测试",parentCode:"",skillCount:1},{categoryCode:"ai-agent",categoryName:"AI Agent",parentCode:"",skillCount:1},{categoryCode:"doc",categoryName:"文档",parentCode:"",skillCount:1}],es={total:8,published:7},{TextArea:nl}=t.Input,{Title:Ml,Paragraph:rl,Text:al}=t.Typography,ts={backend:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",frontend:"linear-gradient(135deg, #f093fb 0%, #f5576c 100%)",devops:"linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",testing:"linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)","ai-agent":"linear-gradient(135deg, #fa709a 0%, #fee140 100%)",doc:"linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)",default:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)"},Le=o=>ts[o]||ts.default,ss={PUBLISHED:"已发布",DRAFT:"草稿",ARCHIVED:"已归档"},Ye=["blue","green","cyan","purple","orange","red"],cl=o=>{const i={};o.forEach(n=>{i[n.categoryCode]={key:n.categoryCode,title:n.categoryName,categoryCode:n.categoryCode,categoryName:n.categoryName,parentCode:n.parentCode||"",skillCount:n.skillCount||0,data:n,children:[]}});const a=[];return o.forEach(n=>{const T=i[n.categoryCode];n.parentCode&&i[n.parentCode]?i[n.parentCode].children.push(T):n.parentCode||a.push(T)}),a},ls=o=>{const i=[],a=(n,T)=>{n.forEach(d=>{var f;const b=d.categoryCode||d.key;i.push({categoryCode:b,categoryName:d.categoryName||d.title,parentCode:T||d.parentCode||"",skillCount:d.skillCount||0}),(f=d.children)!=null&&f.length&&a(d.children,b)})};return o!=null&&o.length&&a(o,""),i};function dl(o){const i={key:"__root__",children:[]},a={"":i};return o.forEach(n=>{const T=n.path.split("/");T.pop();let d="";T.forEach((b,f)=>{const j=T.slice(0,f+1).join("/");a[j]||(a[j]={key:j,title:b,isLeaf:!1,children:[]}),a[d].children.some(w=>w.key===j)||a[d].children.push(a[j]),d=j})}),o.forEach(n=>{const T=n.path.includes("/")?n.path.split("/").slice(0,-1).join("/"):"",d=n.path.includes("/")?n.path.split("/").pop():n.path;a[T].children.push({key:n.path,title:d,isLeaf:!0,file:n})}),i.children}function pl(){const[o,i]=s.useState([]),[a,n]=s.useState(!1),[T,d]=s.useState(0),[b,f]=s.useState(1),j=s.useRef(12),[w,h]=s.useState(""),[m,z]=s.useState(void 0),[F,N]=s.useState("download_count"),[u,v]=s.useState([]),[S,x]=s.useState([]),[D,G]=s.useState(!1),[g,C]=s.useState(null),[P,K]=s.useState(""),[O,V]=s.useState([]),[U,A]=s.useState(!1),[k,_]=s.useState("overview"),[p,y]=s.useState(null),[M,E]=s.useState([]),[Q,c]=s.useState(!1),[r]=t.Form.useForm(),[L,$]=s.useState(!1),[R,se]=s.useState(!1),[je,le]=s.useState({total:0,published:0}),[fe,W]=s.useState(!1),[ee,ce]=s.useState(null),[H,X]=s.useState(null),[ie,he]=s.useState(!1),[ne]=t.Form.useForm(),[ye,_e]=s.useState(220),Tl=s.useRef(null),Ze=s.useRef(!1),as=s.useRef(0),cs=s.useRef(0),Ot=async()=>{try{const I=await ge.stats();I&&(I.total!==void 0||I.published!==void 0)?le(I):I!=null&&I.data?le(I.data):le(es)}catch{le(es)}},Ue=s.useCallback(async(I=1)=>{var J;n(!0);try{const Y={current:I,size:j.current,sortBy:F};w&&(Y.keyword=w),m&&(Y.categoryCode=m),(w||m)&&(Y.status="PUBLISHED");const q=await ge.page(Y);if(q&&q.records)i(q.records),d(Number(q.total)||q.records.length);else if(Array.isArray(q))i(q),d(q.length);else if((J=q==null?void 0:q.data)!=null&&J.records)i(q.data.records),d(Number(q.data.total)||q.data.records.length);else{const oe=$t.filter(pe=>!(w&&!pe.skillName.includes(w)&&!pe.description.includes(w)||m&&pe.categoryCode!==m));i(oe),d(oe.length)}}catch(Y){console.error("loadSkills error:",Y);const q=$t.filter(oe=>!(w&&!oe.skillName.includes(w)&&!oe.description.includes(w)||m&&oe.categoryCode!==m));i(q),d(q.length)}finally{n(!1)}},[w,m,F]),Xe=async()=>{var I,J;try{const Y=await ge.categoryTree(),q=oe=>(oe||[]).map(pe=>({categoryCode:pe.catCode||pe.categoryCode,categoryName:pe.catName||pe.categoryName,parentCode:pe.parentCode||"",skillCount:pe.skillCount||0,children:pe.children?q(pe.children):void 0}));if(Array.isArray(Y)&&Y.length>0){const oe=q(Y);(I=oe[0])!=null&&I.children?v(ls(oe)):v(oe)}else if(Y!=null&&Y.data&&Y.data.length>0){const oe=q(Y.data);(J=oe[0])!=null&&J.children?v(ls(oe)):v(oe)}else v(ft)}catch{const q=localStorage.getItem("z_skill_categories");if(q)try{v(JSON.parse(q))}catch{v(ft)}else v(ft)}};s.useEffect(()=>{Ot(),Xe()},[]),s.useEffect(()=>{Ue(b)},[Ue,b]);const wl=()=>{f(1),Ue(1)},kl=I=>{z(J=>J===I?void 0:I),f(1)},Il=I=>{N(I),f(1)},Ol=async I=>{var J,Y,q;C(I),G(!0),K(I.content||""),V([]),y(null),E([]),_("overview"),A(!0);try{const[oe,pe]=await Promise.allSettled([ge.getBySkillCode(I.skillCode),ge.versions(I.skillCode)]);if(oe.status==="fulfilled"&&oe.value){const Ce=((J=oe.value)==null?void 0:J.data)||oe.value;if(Ce&&typeof Ce=="object"){const Dl={...I,...Ce};C(Dl),K(Ce.content||Ce.readme||I.content||""),(Y=Ce.files)!=null&&Y.length&&y(Ce.files[0])}}if(pe.status==="fulfilled"&&pe.value){const Ce=((q=pe.value)==null?void 0:q.data)||pe.value;Array.isArray(Ce)&&V(Ce)}}catch(oe){console.warn("openDetail error:",oe)}finally{A(!1)}},ds=async I=>{try{await navigator.clipboard.writeText(I),t.message.success("已复制到剪贴板")}catch{t.message.error("复制失败")}},ps=I=>{if(I)if(I.packageType==="ZIP"&&(I.packagePath||I.version)){const J=ge.downloadPackage(I.skillCode,I.version);window.open(J,"_blank")}else I.content&&ds(I.content)},us=async I=>{try{const J=await ge.install({skillCode:I});J!=null?(t.message.success("安装成功"),Ot()):t.message.error("安装失败")}catch{t.message.error("安装异常")}},Al=async I=>{if(!g)return!1;if(!I.name.toLowerCase().endsWith(".zip"))return t.message.error("仅支持 .zip 格式"),t.Upload.LIST_IGNORE;se(!0);try{await ge.uploadPackage(g.skillCode,g.version||"1.0.0",I),t.message.success("上传成功"),C(J=>J&&{...J,packageType:"ZIP"});try{const J=await ge.getBySkillCode(g.skillCode),Y=J&&typeof J=="object"&&"data"in J?J.data:J;Y&&C(q=>q&&{...q,...Y})}catch{}Ue(b)}catch(J){console.error("uploadPackage error:",J),t.message.error("上传失败:"+((J==null?void 0:J.message)||"未知错误"))}finally{se(!1)}return!1},Pl=async()=>{try{const I=await r.validateFields();$(!0);const J=await ge.create({...I,status:"PUBLISHED"});J!=null?(t.message.success("发布成功"),c(!1),r.resetFields(),Ue(1),Ot()):t.message.error("发布失败")}catch(I){if(I!=null&&I.errorFields)return;t.message.error("发布异常")}finally{$(!1)}},xs=I=>{ce(null),X(I),ne.resetFields(),I&&ne.setFieldsValue({parentCode:I.categoryCode}),W(!0)},El=I=>{ce(I),X(null),ne.setFieldsValue({categoryCode:I.categoryCode,categoryName:I.categoryName,parentCode:I.parentCode||""}),W(!0)},zl=async()=>{try{const I=await ne.validateFields();he(!0),ee?(await ge.createCategory({catCode:I.categoryCode,catName:I.categoryName,parentCode:I.parentCode||""}),t.message.success("更新成功")):(await ge.createCategory({catCode:I.categoryCode,catName:I.categoryName,parentCode:I.parentCode||""}),t.message.success("创建成功")),W(!1),Xe()}catch(I){if(I!=null&&I.errorFields)return;const J=ne.getFieldsValue();let Y=[...u];if(ee){const q=Y.findIndex(oe=>oe.categoryCode===ee.categoryCode);q>=0&&(Y[q]={...Y[q],...J})}else Y.push({categoryCode:J.categoryCode,categoryName:J.categoryName,parentCode:J.parentCode||"",skillCount:0});v(Y),localStorage.setItem("z_skill_categories",JSON.stringify(Y)),W(!1),t.message.success(ee?"更新成功":"创建成功")}finally{he(!1)}},Rl=async I=>{try{const J=u.find(q=>q.categoryCode===I),Y=J==null?void 0:J.id;if(Y)await ge.deleteCategory(Y);else throw new Error("no api id");t.message.success("删除成功"),Xe()}catch{const Y=u.filter(q=>q.categoryCode!==I);v(Y),localStorage.setItem("z_skill_categories",JSON.stringify(Y)),t.message.success("删除成功")}},Bl=I=>{const J=u.find(Y=>Y.categoryCode===I.categoryCode);return J?e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,padding:"2px 0",cursor:"pointer"},onClick:()=>kl(I.categoryCode),children:[m===I.categoryCode?e.jsx(l.FolderOpenOutlined,{style:{fontSize:13,color:"#667eea"}}):e.jsx(l.FolderOutlined,{style:{fontSize:13,color:"#8c8c8c"}}),e.jsx("span",{style:{flex:1,fontSize:13,color:m===I.categoryCode?"#667eea":void 0,fontWeight:m===I.categoryCode?600:400},children:J.categoryName}),e.jsx(t.Tag,{style:{fontSize:10,padding:"0 4px",lineHeight:"16px",marginRight:0},children:J.skillCount||0}),e.jsx(t.Dropdown,{trigger:["click"],menu:{items:[{key:"add",icon:e.jsx(l.PlusOutlined,{}),label:"新增子分类"},{key:"edit",icon:e.jsx(l.EditOutlined,{}),label:"编辑分类"},{type:"divider"},{key:"delete",icon:e.jsx(l.DeleteOutlined,{}),label:"删除分类",danger:!0}],onClick:({key:Y,domEvent:q})=>{q.stopPropagation(),Y==="add"?xs(J):Y==="edit"?El(J):Y==="delete"&&t.Modal.confirm({title:`删除分类"${J.categoryName}"?`,content:"子分类也会被删除",okText:"确认删除",okType:"danger",cancelText:"取消",onOk:()=>Rl(I.categoryCode)})}},children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.MoreOutlined,{style:{fontSize:13}}),onClick:Y=>Y.stopPropagation()})})]}):e.jsx("span",{children:I.title})},Fl=[{value:"download_count",label:"最热门"},{value:"gmt_create",label:"最新发布"},{value:"skill_name",label:"名称排序"}],Nl=s.useCallback(I=>{I.preventDefault(),Ze.current=!0,as.current=I.clientX,cs.current=ye,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[ye]);return s.useEffect(()=>{const I=Y=>{if(!Ze.current)return;const q=Math.max(180,Math.min(cs.current+Y.clientX-as.current,340));_e(q)},J=()=>{Ze.current&&(Ze.current=!1,document.body.style.cursor="",document.body.style.userSelect="")};return window.addEventListener("mousemove",I),window.addEventListener("mouseup",J),()=>{window.removeEventListener("mousemove",I),window.removeEventListener("mouseup",J)}},[]),e.jsxs("div",{style:{display:"flex",gap:16,minHeight:600},children:[e.jsx("div",{ref:Tl,style:{width:ye,flexShrink:0},children:e.jsx(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.AppstoreOutlined,{style:{color:"#667eea",marginRight:6}}),"分类"]}),extra:e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:Xe}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>xs(null)})]}),styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"10px 14px"},body:{padding:"6px 8px"}},children:e.jsx(t.Tree,{showIcon:!1,treeData:cl(u),defaultExpandAll:!0,showLine:!0,titleRender:Bl,selectedKeys:m?[m]:[],onSelect:()=>{},style:{fontSize:13}})})}),e.jsx("div",{onMouseDown:Nl,style:{width:6,cursor:"col-resize",flexShrink:0,background:"#f0f0f0",borderRadius:3,alignSelf:"stretch"}}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:12,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"center",flexWrap:"wrap",background:"#fff",padding:"14px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)"},children:[e.jsx(t.Input,{prefix:e.jsx(l.SearchOutlined,{style:{color:"#bfbfbf"}}),placeholder:"搜索技能名称、描述、标签...",value:w,onChange:I=>h(I.target.value),onPressEnter:wl,allowClear:!0,style:{width:260,borderRadius:8}}),e.jsx(t.Select,{value:F,onChange:Il,options:Fl,style:{width:130,borderRadius:8}}),e.jsx("div",{style:{flex:1}}),e.jsxs("div",{style:{display:"flex",gap:20,alignItems:"center"},children:[e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,color:"#667eea",lineHeight:1.2},children:je.total||0}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:"全部技能"})]}),e.jsx("div",{style:{width:1,height:32,background:"#f0f0f0"}}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,color:"#52c41a",lineHeight:1.2},children:je.published||0}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:"已发布"})]})]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CloudUploadOutlined,{}),onClick:()=>c(!0),style:{borderRadius:8,height:36,paddingInline:18,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",border:"none",fontWeight:600,boxShadow:"0 4px 12px rgba(102,126,234,0.3)"},children:"发布技能"})]}),a?e.jsx("div",{style:{textAlign:"center",padding:60},children:e.jsx(t.Spin,{size:"large"})}):o.length===0?e.jsx(t.Empty,{description:"暂无技能",style:{padding:60}}):e.jsx(t.Row,{gutter:[16,16],children:o.map(I=>{const J=(I.tags||"").split(",").filter(Boolean);return e.jsx(t.Col,{xs:24,sm:12,md:8,lg:6,children:e.jsxs(t.Card,{hoverable:!0,size:"small",onClick:()=>Ol(I),style:{borderRadius:12,border:"none",boxShadow:"0 2px 12px rgba(0,0,0,0.07)",overflow:"hidden",cursor:"pointer"},styles:{body:{padding:0}},onMouseEnter:Y=>{Y.currentTarget.style.boxShadow="0 8px 24px rgba(102,126,234,0.18)",Y.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:Y=>{Y.currentTarget.style.boxShadow="0 2px 12px rgba(0,0,0,0.07)",Y.currentTarget.style.transform="translateY(0)"},children:[e.jsx("div",{style:{background:Le(I.categoryCode),padding:"14px 16px",borderRadius:"12px 12px 0 0"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:10,background:"rgba(255,255,255,0.2)",display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(8px)"},children:e.jsx(l.CodeOutlined,{style:{fontSize:20,color:"#fff"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#fff",lineHeight:1.3},children:I.skillName}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.8)",marginTop:2},children:["v",I.version," · ",I.author]})]}),I.status!=="PUBLISHED"&&e.jsx(t.Tag,{style:{background:"rgba(255,255,255,0.25)",color:"#fff",border:"none",borderRadius:10,fontSize:11},children:ss[I.status]})]})}),e.jsxs("div",{style:{padding:"12px 14px 14px"},children:[e.jsx(rl,{ellipsis:{rows:2},style:{fontSize:12,color:"#666",marginBottom:10,minHeight:36},children:I.description||"暂无描述"}),e.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap",marginBottom:10},children:[J.slice(0,3).map((Y,q)=>e.jsx(t.Tag,{color:Ye[q%Ye.length],style:{fontSize:11,borderRadius:4,marginBottom:2},children:Y},Y)),J.length>3&&e.jsxs(t.Tag,{style:{fontSize:11},children:["+",J.length-3]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingTop:10,borderTop:"1px solid #f5f5f5"},children:[e.jsx(t.Tooltip,{title:"安装次数",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[e.jsx(l.FireOutlined,{style:{color:"#ff4d4f",fontSize:12}}),e.jsx(al,{type:"secondary",style:{fontSize:12},children:I.downloadCount||0})]})}),e.jsx(t.Button,{type:"primary",size:"small",icon:e.jsx(l.DownloadOutlined,{}),onClick:Y=>{Y.stopPropagation(),us(I.skillCode)},style:{borderRadius:6,background:Le(I.categoryCode),border:"none",fontWeight:500},children:"安装"})]})]})]})},I.id)})}),T>j.current&&e.jsx("div",{style:{textAlign:"right",padding:"8px 0"},children:e.jsx(t.Pagination,{current:b,pageSize:j.current,total:T,onChange:I=>{f(I),window.scrollTo({top:0,behavior:"smooth"})},showSizeChanger:!1})})]}),e.jsx(t.Drawer,{title:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:8,background:Le(g==null?void 0:g.categoryCode),display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.CodeOutlined,{style:{fontSize:18,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:600},children:g==null?void 0:g.skillName}),e.jsxs("div",{style:{fontSize:11,color:"#999",fontWeight:400},children:["v",g==null?void 0:g.version," · ",g==null?void 0:g.author," · ",ss[g==null?void 0:g.status]||(g==null?void 0:g.status)]})]})]}),open:D,onClose:()=>G(!1),width:"75%",styles:{header:{padding:"14px 24px",borderBottom:"1px solid #f0f0f0"},body:{padding:0}},children:g&&e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"16px 24px",borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",gap:16,flexWrap:"wrap",background:"#fafafa"},children:[g.packageType==="ZIP"&&g.packagePath?e.jsx(t.Button,{type:"primary",size:"large",icon:e.jsx(l.DownloadOutlined,{}),onClick:()=>ps(g),style:{borderRadius:8,background:Le(g.categoryCode),border:"none",fontWeight:600,height:40,paddingInline:24},children:"下载技能包 (ZIP)"}):g.content?e.jsx(t.Button,{type:"primary",size:"large",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>ds(g.content),style:{borderRadius:8,background:Le(g.categoryCode),border:"none",fontWeight:600,height:40,paddingInline:24},children:"复制技能内容"}):e.jsx(t.Button,{size:"large",disabled:!0,icon:e.jsx(l.DownloadOutlined,{}),style:{height:40},children:"暂无下载包"}),e.jsx(t.Button,{icon:e.jsx(l.DownloadOutlined,{}),onClick:()=>us(g.skillCode),style:{borderRadius:8,height:40},children:"安装此技能"}),e.jsxs("div",{style:{flex:1,display:"flex",gap:8,flexWrap:"wrap",justifyContent:"flex-end"},children:[e.jsxs(t.Tag,{icon:e.jsx(l.CheckCircleOutlined,{}),color:"blue",children:["v",g.version]}),e.jsxs(t.Tag,{icon:e.jsx(l.FireOutlined,{}),color:"red",children:[g.downloadCount||0," 次安装"]}),e.jsx(t.Tag,{icon:e.jsx(l.StarOutlined,{}),color:"orange",children:g.author}),g.gmtModified&&e.jsx(t.Tag,{icon:e.jsx(l.ClockCircleOutlined,{}),color:"default",children:new Date(g.gmtModified).toLocaleDateString()})]})]}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(t.Tabs,{activeKey:k,onChange:_,style:{height:"100%"},tabBarStyle:{padding:"0 24px",marginBottom:0},items:[{key:"overview",label:e.jsxs("span",{children:[e.jsx(l.InfoCircleOutlined,{})," 概述"]}),children:e.jsx("div",{style:{padding:"20px 24px"},children:U?e.jsx("div",{style:{textAlign:"center",padding:40},children:e.jsx(t.Spin,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#333",marginBottom:8},children:"简介"}),e.jsx("div",{style:{fontSize:14,color:"#555",lineHeight:1.8},children:g.description||"暂无描述"})]}),g.tags&&e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#333",marginBottom:8},children:"标签"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:(g.tags||"").split(",").filter(Boolean).map((I,J)=>e.jsx(t.Tag,{color:Ye[J%Ye.length],style:{fontSize:12,borderRadius:4,padding:"2px 8px"},children:I},I))})]}),P&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#333",marginBottom:8},children:"技能说明"}),e.jsx("div",{style:{background:"#fafafa",border:"1px solid #f0f0f0",padding:16,borderRadius:8,lineHeight:1.8,fontSize:14,color:"#333"},children:e.jsx(At,{components:{code:({node:I,inline:J,className:Y,children:q,...oe})=>J?e.jsx("code",{style:{background:"#f0f0f0",padding:"2px 6px",borderRadius:4,fontSize:13},...oe,children:q}):e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:14,borderRadius:8,overflow:"auto",fontSize:13},children:e.jsx("code",{...oe,children:q})}),h1:({children:I})=>e.jsx("h1",{style:{fontSize:20,fontWeight:700,borderBottom:"1px solid #eee",paddingBottom:8,marginBottom:12},children:I}),h2:({children:I})=>e.jsx("h2",{style:{fontSize:17,fontWeight:600,marginTop:20,marginBottom:8},children:I}),h3:({children:I})=>e.jsx("h3",{style:{fontSize:15,fontWeight:600,marginTop:16,marginBottom:6},children:I}),ul:({children:I})=>e.jsx("ul",{style:{paddingLeft:20,marginBottom:12},children:I}),li:({children:I})=>e.jsx("li",{style:{marginBottom:4},children:I}),p:({children:I})=>e.jsx("p",{style:{marginBottom:10},children:I})},children:P})})]})]})})},{key:"files",label:e.jsxs("span",{children:[e.jsx(l.FileTextOutlined,{})," 文件"]}),children:e.jsxs("div",{style:{padding:"20px 24px"},children:[g.files&&g.files.length>0?e.jsxs("div",{style:{display:"flex",gap:16,height:400},children:[e.jsx("div",{style:{width:220,flexShrink:0,border:"1px solid #f0f0f0",borderRadius:8,overflow:"auto",padding:"4px 0"},children:e.jsx(t.Tree,{treeData:dl(g.files),defaultExpandAll:!0,showIcon:!0,selectedKeys:p?[p.path]:[],onSelect:(I,J)=>{J.node.isLeaf&&J.node.file&&y(J.node.file)},titleRender:I=>e.jsx("span",{style:{fontSize:13},children:I.title}),icon:I=>I.isLeaf?e.jsx(l.FileTextOutlined,{style:{fontSize:13,color:"#8c8c8c"}}):e.jsx(l.FolderOutlined,{style:{fontSize:13,color:"#faad14"}})})}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:p?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:6},children:p.path}),e.jsx("pre",{style:{flex:1,background:"#1e1e1e",color:"#d4d4d4",padding:14,borderRadius:8,fontSize:12,lineHeight:1.6,overflow:"auto",whiteSpace:"pre-wrap",fontFamily:'"SF Mono","Fira Code","Consolas",monospace',margin:0},children:p.content||"(empty)"})]}):e.jsx("div",{style:{color:"#999",textAlign:"center",paddingTop:80},children:"选择一个文件查看内容"})})]}):g.packageType==="ZIP"&&g.packagePath?e.jsxs("div",{style:{background:"#f6ffed",border:"1px solid #b7eb8f",borderRadius:8,padding:20,textAlign:"center"},children:[e.jsx(l.FileZipOutlined,{style:{fontSize:36,color:"#52c41a",marginBottom:12}}),e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#389e0d",marginBottom:8},children:"ZIP 包已上传"}),e.jsx("div",{style:{fontSize:12,color:"#999",wordBreak:"break-all"},children:g.packagePath}),e.jsx(t.Button,{type:"link",icon:e.jsx(l.DownloadOutlined,{}),onClick:()=>ps(g),style:{marginTop:12},children:"下载并解压查看文件"})]}):e.jsxs("div",{style:{textAlign:"center",padding:40,color:"#999"},children:[e.jsx(l.FileTextOutlined,{style:{fontSize:36,color:"#d9d9d9",marginBottom:12}}),e.jsx("div",{children:"暂无文件,上传 ZIP 包后可查看文件目录"})]}),e.jsxs("div",{style:{marginTop:20,borderTop:"1px solid #f0f0f0",paddingTop:16},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#333",marginBottom:8},children:"上传技能包"}),e.jsx(t.Upload,{accept:".zip",showUploadList:!1,beforeUpload:Al,disabled:R,children:e.jsxs("div",{style:{border:"2px dashed #d9d9d9",borderRadius:8,padding:16,textAlign:"center",cursor:R?"not-allowed":"pointer",opacity:R?.6:1},children:[R?e.jsx(t.Spin,{size:"small"}):e.jsx(l.CloudUploadOutlined,{style:{fontSize:20,color:"#bfbfbf"}}),e.jsx("div",{style:{fontSize:12,color:"#999",marginTop:6},children:R?"上传中...":g.packageType==="ZIP"?"重新上传 ZIP":"上传 ZIP 包"})]})})]})]})},{key:"versions",label:e.jsxs("span",{children:[e.jsx(l.HistoryOutlined,{})," 版本历史 ",O.length>0&&`(${O.length})`]}),children:e.jsx("div",{style:{padding:"20px 24px"},children:O.length>0?e.jsx(t.Timeline,{items:O.map((I,J)=>({color:J===0?"green":"gray",children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(t.Tag,{color:J===0?"green":"default",style:{fontWeight:600},children:I.version||I.versionNumber||`v${J+1}`}),J===0&&e.jsx(t.Tag,{color:"blue",children:"当前版本"})]}),I.changeLog&&e.jsx("div",{style:{fontSize:13,color:"#666",marginTop:4},children:I.changeLog}),e.jsx("div",{style:{fontSize:11,color:"#bbb",marginTop:2},children:I.gmtCreate?new Date(I.gmtCreate).toLocaleString():""})]})}))}):e.jsxs("div",{style:{textAlign:"center",padding:40,color:"#999"},children:[e.jsx(l.HistoryOutlined,{style:{fontSize:36,color:"#d9d9d9",marginBottom:12}}),e.jsx("div",{children:"暂无版本记录"}),e.jsxs("div",{style:{fontSize:12,color:"#bbb",marginTop:4},children:["当前版本: v",g.version]})]})})}]})})]})}),e.jsx(t.Modal,{title:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.CloudUploadOutlined,{style:{fontSize:16,color:"#fff"}})}),e.jsx("span",{style:{fontSize:16},children:"发布新技能"})]}),open:Q,onCancel:()=>{c(!1),r.resetFields()},onOk:Pl,confirmLoading:L,okText:"确认发布",cancelText:"取消",width:580,style:{top:80},children:e.jsxs(t.Form,{form:r,layout:"vertical",style:{marginTop:12},children:[e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(t.Form.Item,{name:"skillCode",label:"技能编码",rules:[{required:!0,message:"请输入技能编码"}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"如 java-entity-gen",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"skillName",label:"技能名称",rules:[{required:!0,message:"请输入技能名称"}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"如 Java Entity 生成器",style:{borderRadius:8}})})]}),e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(t.Form.Item,{name:"categoryCode",label:"分类",style:{flex:1},children:e.jsx(t.Input,{placeholder:"如 backend",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"version",label:"版本号",initialValue:"1.0.0",rules:[{required:!0}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"1.0.0",style:{borderRadius:8}})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(nl,{rows:3,placeholder:"简要描述技能功能...",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"tags",label:"标签",children:e.jsx(t.Input,{placeholder:"用逗号分隔,如 java,entity,generator",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"author",label:"作者",children:e.jsx(t.Input,{placeholder:"技能作者",style:{borderRadius:8}})})]})}),e.jsx(t.Modal,{title:ee?"编辑分类":H?`新建子分类 - ${H.categoryName}`:"新建分类",open:fe,onCancel:()=>W(!1),onOk:()=>ne.submit(),confirmLoading:ie,destroyOnClose:!0,okText:"确认",cancelText:"取消",children:e.jsxs(t.Form,{form:ne,layout:"vertical",onFinish:zl,style:{marginTop:8},children:[e.jsx(t.Form.Item,{name:"categoryCode",label:"分类编码",rules:[{required:!0,message:"请输入分类编码"}],children:e.jsx(t.Input,{placeholder:"如 backend",disabled:!!ee,style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"categoryName",label:"分类名称",rules:[{required:!0,message:"请输入分类名称"}],children:e.jsx(t.Input,{placeholder:"如 后端开发",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"parentCode",label:"父分类",children:e.jsx(t.Select,{allowClear:!0,placeholder:"留空为顶级分类",popupMatchSelectWidth:!1,children:u.filter(I=>ee?I.categoryCode!==ee.categoryCode:!0).map(I=>e.jsx(t.Select.Option,{value:I.categoryCode,children:I.categoryName},I.categoryCode))})})]})})]})}const{TextArea:os}=t.Input,{Option:ke}=t.Select,{TabPane:is}=t.Tabs,ul=()=>{const[o,i]=s.useState("list");return e.jsx(t.Card,{style:{minHeight:"calc(100vh - 140px)"},children:e.jsxs(t.Tabs,{activeKey:o,onChange:i,children:[e.jsx(is,{tab:e.jsxs("span",{children:[e.jsx(l.ShopOutlined,{})," 产品管理"]}),children:e.jsx(xl,{})},"list"),e.jsx(is,{tab:e.jsxs("span",{children:[e.jsx(l.FileTextOutlined,{})," 产品配置"]}),children:e.jsx(hl,{})},"config")]})})},xl=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(!1),[T,d]=s.useState(""),[b,f]=s.useState(""),[j,w]=s.useState(1),[h]=s.useState(12),[m,z]=s.useState(0),[F,N]=s.useState(!1),[u]=t.Form.useForm(),[v,S]=s.useState(null),[x,D]=s.useState(!1),[G,g]=s.useState(!1),[C,P]=s.useState(null);s.useEffect(()=>{K()},[j,T,b]);const K=async()=>{n(!0);try{const E=await Se.page({productName:T,status:b,id:j});E.data&&(i(E.data.records||[]),z(E.data.total||0))}catch(E){t.message.error("加载失败: "+(E.message||""))}n(!1)},O=()=>{S(null),u.resetFields(),u.setFieldsValue({status:"DRAFT"}),N(!0)},V=E=>{S(E),u.setFieldsValue({productCode:E.productCode,productName:E.productName,description:E.description,category:E.category,version:E.version||"1.0.0",iconUrl:E.iconUrl,status:E.status,tags:E.tags}),N(!0)},U=async()=>{try{const E=await u.validateFields();D(!0),v?(await Se.update({id:v.id,...E}),t.message.success("更新成功")):(await Se.create(E),t.message.success("创建成功")),N(!1),K()}catch(E){E.errorFields||t.message.error("操作失败")}finally{D(!1)}},A=async E=>{try{await Se.delete(E),t.message.success("删除成功"),K()}catch{t.message.error("删除失败")}},k=async E=>{try{await Se.publish(E),t.message.success("发布成功"),K()}catch{t.message.error("发布失败")}},_=async E=>{try{await Se.offline(E),t.message.success("下架成功"),K()}catch{t.message.error("下架失败")}},p=async E=>{P(E),g(!0)},y=E=>{navigator.clipboard.writeText(E).then(()=>t.message.success("产品编码已复制")).catch(()=>{})},M=[{title:"产品",key:"product",width:280,render:(E,Q)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:8,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.ShopOutlined,{style:{fontSize:18,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:Q.productName}),e.jsxs("div",{style:{fontSize:12,color:"#999"},children:[e.jsx("span",{style:{fontFamily:"monospace"},children:Q.productCode}),e.jsx(t.Tooltip,{title:"复制编码",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>y(Q.productCode),style:{marginLeft:4,padding:0}})})]})]})]})},{title:"分类",dataIndex:"category",width:120,render:E=>E?e.jsx(t.Tag,{icon:e.jsx(l.TagOutlined,{}),children:E}):e.jsx("span",{style:{color:"#ccc"},children:"未分类"})},{title:"状态",dataIndex:"status",width:100,render:E=>{const Q={PUBLISHED:"success",DRAFT:"warning",OFFLINE:"error",ARCHIVED:"default"},c={PUBLISHED:"已发布",DRAFT:"草稿",OFFLINE:"已下架",ARCHIVED:"已归档"};return e.jsx(t.Badge,{status:Q[E]||"default",text:c[E]||E})}},{title:"版本",dataIndex:"version",width:90,render:E=>e.jsxs("span",{style:{fontFamily:"monospace"},children:["v",E||"1.0.0"]})},{title:"描述",dataIndex:"description",ellipsis:!0},{title:"操作",width:320,render:(E,Q)=>e.jsxs(t.Space,{size:"small",wrap:!0,children:[e.jsx(t.Tooltip,{title:"查看详情",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>p(Q),children:"详情"})}),e.jsx(t.Tooltip,{title:"编辑配置",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>V(Q),children:"编辑"})}),Q.status==="DRAFT"&&e.jsx(t.Tooltip,{title:"发布产品",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.CheckCircleOutlined,{}),onClick:()=>k(Q.productCode),children:"发布"})}),Q.status==="PUBLISHED"&&e.jsx(t.Tooltip,{title:"下架产品",children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.StopOutlined,{}),onClick:()=>_(Q.productCode),children:"下架"})}),e.jsx(t.Tooltip,{title:"执行场景",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:()=>window.open(`/ai/product/execute?productCode=${Q.productCode}`,"_blank"),children:"执行"})}),e.jsx(t.Popconfirm,{title:"确定删除此产品?",onConfirm:()=>A(Q.id),okText:"删除",okButtonProps:{danger:!0},children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:16,gap:12,flexWrap:"wrap"},children:[e.jsxs(t.Space,{children:[e.jsx(t.Input.Search,{placeholder:"搜索产品名称/编码",onSearch:E=>{d(E),w(1)},style:{width:220},allowClear:!0}),e.jsxs(t.Select,{placeholder:"状态筛选",allowClear:!0,style:{width:120},onChange:E=>{f(E),w(1)},children:[e.jsx(ke,{value:"DRAFT",children:"草稿"}),e.jsx(ke,{value:"PUBLISHED",children:"已发布"}),e.jsx(ke,{value:"OFFLINE",children:"已下架"}),e.jsx(ke,{value:"ARCHIVED",children:"已归档"})]})]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:O,children:"新建产品"})]}),e.jsx(t.Table,{dataSource:o,columns:M,loading:a,rowKey:"id",pagination:{current:j,pageSize:h,total:m,showSizeChanger:!1,showTotal:E=>`共 ${E} 个产品`,onChange:E=>w(E)},locale:{emptyText:e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"还没有产品,点击新建开始创建"})}}),e.jsx(t.Modal,{title:v?`编辑产品: ${v.productName}`:"新建产品",open:F,onOk:U,onCancel:()=>N(!1),width:640,confirmLoading:x,okText:v?"保存":"创建",children:e.jsxs(t.Form,{form:u,layout:"vertical",size:"middle",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"productName",label:"产品名称",rules:[{required:!0,message:"请输入产品名称"}],children:e.jsx(t.Input,{placeholder:"如:智能客服助手"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"productCode",label:"产品编码",rules:[{required:!0,message:"请输入产品编码"}],children:e.jsx(t.Input,{placeholder:"如 product-ai-assistant",disabled:!!v})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"category",label:"产品分类",children:e.jsx(t.Input,{placeholder:"如 AI助手, 图像生成"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"version",label:"版本号",initialValue:"1.0.0",children:e.jsx(t.Input,{placeholder:"1.0.0"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"产品描述",children:e.jsx(os,{rows:2,placeholder:"简短描述这个产品的能力和使用场景"})}),e.jsx(t.Form.Item,{name:"tags",label:"产品标签",children:e.jsx(t.Input,{placeholder:"用逗号分隔,如 AI,客服,对话"})}),e.jsx(t.Form.Item,{name:"iconUrl",label:"图标URL",children:e.jsx(t.Input,{placeholder:"可选,图标图片URL"})}),!v&&e.jsx(t.Form.Item,{name:"status",label:"创建后状态",initialValue:"DRAFT",children:e.jsxs(t.Select,{children:[e.jsx(ke,{value:"DRAFT",children:"草稿(仅自己可见)"}),e.jsx(ke,{value:"PUBLISHED",children:"直接发布"})]})})]})}),e.jsx(t.Drawer,{title:"产品详情",open:G,onClose:()=>g(!1),width:560,children:C&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:10,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.ShopOutlined,{style:{fontSize:22,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600},children:C.productName}),e.jsx("div",{style:{fontSize:12,color:"#999"},children:C.productCode})]})]}),e.jsx(t.Divider,{style:{margin:"8px 0"}}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Statistic,{title:"分类",value:C.category||"未分类",valueStyle:{fontSize:14}})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Statistic,{title:"版本",value:C.version||"1.0.0",valueStyle:{fontSize:14}})})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"状态"}),e.jsx(t.Badge,{status:C.status==="PUBLISHED"?"success":C.status==="DRAFT"?"warning":"error",text:C.status==="PUBLISHED"?"已发布":C.status==="DRAFT"?"草稿":C.status==="OFFLINE"?"已下架":"已归档"})]}),C.tags&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:6},children:"标签"}),e.jsx(t.Space,{wrap:!0,children:(C.tags||"").split(",").filter(Boolean).map((E,Q)=>e.jsx(t.Tag,{color:"blue",children:E},Q))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"描述"}),e.jsx("div",{style:{color:"#333",lineHeight:1.6},children:C.description||"暂无描述"})]})]})})]})},hl=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(null),[T,d]=s.useState({scenes:[],params:[]}),[b,f]=s.useState(!1),[j,w]=s.useState(!1),[h,m]=s.useState(!1),[z]=t.Form.useForm();s.useEffect(()=>{Se.page({id:1,pageSize:100}).then(x=>{var D;i(((D=x.data)==null?void 0:D.records)||[])})},[]),s.useEffect(()=>{a&&F(a.productCode)},[a]);const F=async x=>{f(!0);try{const D=await Se.configGet(x);d(D.data||{scenes:[],params:[]})}catch{d({scenes:[],params:[]})}f(!1)},N=async()=>{if(a){w(!0);try{await Se.configSave({productCode:a.productCode,...T}),t.message.success("配置已保存")}catch{t.message.error("保存失败")}finally{w(!1)}}},u=()=>{z.resetFields(),m(!0)},v=async()=>{try{const x=await z.validateFields();d(D=>({...D,scenes:[...D.scenes||[],{...x,id:Date.now()}]})),m(!1),t.message.success("场景已添加")}catch{}},S=x=>{d(D=>({...D,scenes:(D.scenes||[]).filter(G=>G.id!==x)}))};return e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.ShopOutlined,{style:{color:"#667eea",marginRight:6}}),"选择产品"]}),style:{width:260,flexShrink:0,borderRadius:10},styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"12px 16px"},body:{padding:8}},children:[(o||[]).map(x=>e.jsxs("div",{onClick:()=>n(x),style:{padding:"10px 12px",borderRadius:8,cursor:"pointer",marginBottom:4,background:(a==null?void 0:a.id)===x.id?"linear-gradient(135deg, #667eea22, #764ba222)":"transparent",border:(a==null?void 0:a.id)===x.id?"1px solid #667eea44":"1px solid transparent",transition:"all 0.2s"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:x.productName}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:x.productCode})]},x.id)),o.length===0&&e.jsx(t.Empty,{description:"暂无产品",style:{padding:20}})]}),e.jsx(t.Card,{title:e.jsxs("span",{style:{fontWeight:600},children:["产品配置 ",a?`- ${a.productName}`:""]}),extra:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CloudUploadOutlined,{}),onClick:N,disabled:!a,loading:j,children:"保存配置"}),style:{flex:1,borderRadius:10},children:a?b?e.jsx("div",{style:{textAlign:"center",padding:40},children:"加载中..."}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:20},children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsx("span",{style:{fontWeight:500},children:"关联场景"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.PlusOutlined,{}),onClick:u,children:"添加场景"})]}),(T.scenes||[]).length===0?e.jsxs("div",{style:{textAlign:"center",padding:"20px 0",color:"#999",background:"#fafafa",borderRadius:8},children:[e.jsx(l.ExclamationCircleOutlined,{style:{marginRight:6}}),"暂无关联场景"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:(T.scenes||[]).map((x,D)=>e.jsx(t.Card,{size:"small",style:{background:"#fafafa",border:"none"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx(t.Tag,{color:"purple",children:x.sceneName}),e.jsx("span",{style:{fontSize:12,color:"#666",marginLeft:8},children:x.sceneCode})]}),e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>S(x.id)})]})},x.id||D))})]})}):e.jsx(t.Empty,{description:"请先选择产品",style:{padding:60},image:t.Empty.PRESENTED_IMAGE_SIMPLE})}),e.jsx(t.Modal,{title:"添加场景",open:h,onOk:v,onCancel:()=>m(!1),okText:"添加",children:e.jsxs(t.Form,{form:z,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"sceneName",label:"场景名称",rules:[{required:!0,message:"请输入场景名称"}],children:e.jsx(t.Input,{placeholder:"如 智能问答"})}),e.jsx(t.Form.Item,{name:"sceneCode",label:"场景编码",rules:[{required:!0,message:"请输入场景编码"}],children:e.jsx(t.Input,{placeholder:"如 chat_scene"})}),e.jsx(t.Form.Item,{name:"sceneType",label:"场景类型",initialValue:"CONVERSATION",children:e.jsxs(t.Select,{children:[e.jsx(ke,{value:"CONVERSATION",children:"对话"}),e.jsx(ke,{value:"TASK",children:"任务"}),e.jsx(ke,{value:"WORKFLOW",children:"工作流"})]})}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(os,{rows:2,placeholder:"场景描述"})})]})})]})},{TextArea:ml}=t.Input,{Text:Me,Title:gl}=t.Typography,{Option:ns}=t.Select,fl=()=>{var je,le,fe;const o=new URLSearchParams(window.location.search),i=o.get("productCode")||"",a=o.get("sceneCode")||"",[n,T]=s.useState(i),[d,b]=s.useState(a),[f,j]=s.useState([]),[w,h]=s.useState([]),[m,z]=s.useState([]),[F,N]=s.useState(""),[u,v]=s.useState(!1),[S,x]=s.useState(!1),[D,G]=s.useState(""),[g,C]=s.useState(!1),[P,K]=s.useState([]),[O,V]=s.useState(!1),[U]=t.Form.useForm(),[A,k]=s.useState({temperature:.7,maxTokens:2048,topP:1}),[_,p]=s.useState(null),y=s.useRef(null),M=s.useRef(null),E=s.useRef(null);s.useEffect(()=>{Se.page({id:1,pageSize:100,status:"PUBLISHED"}).then(W=>{var ee;j(((ee=W.data)==null?void 0:ee.records)||[])})},[]),s.useEffect(()=>{if(!n){h([]);return}ue.page({id:1,pageSize:100,status:"PUBLISHED",productCode:n}).then(W=>{var ee;h(((ee=W.data)==null?void 0:ee.records)||[])})},[n]),s.useEffect(()=>{if(!d){p(null);return}ue.configGet(d).then(W=>{p(W.data)}).catch(()=>p(null))},[d]),s.useEffect(()=>{d&&ue.chatHistory(d).then(W=>{K(Array.isArray(W.data)?W.data:[])}).catch(()=>K([]))},[d]),s.useEffect(()=>{var W;(W=y.current)==null||W.scrollIntoView({behavior:"smooth"})},[m,D]),s.useEffect(()=>{var W;(W=E.current)==null||W.focus()},[d]);const Q=s.useCallback(async()=>{if(!F.trim()||!d||u||S)return;const W=F.trim();N("");const ee={id:Date.now(),role:"user",content:W,timestamp:new Date().toLocaleTimeString()};z(ce=>[...ce,ee]),v(!0),G("");try{x(!0);const ce=localStorage.getItem("userId")||"anonymous",H=localStorage.getItem("userName")||"匿名用户",X=new EventSource(`/api/scene/execute/stream?sceneCode=${d}&message=${encodeURIComponent(W)}&userId=${ce}&userName=${encodeURIComponent(H)}`);M.current=X,X.onmessage=ie=>{try{const he=JSON.parse(ie.data);if(he.type==="chunk")G(ne=>ne+he.content);else if(he.type==="done"){const ne={id:Date.now()+1,role:"assistant",content:D+he.content,timestamp:new Date().toLocaleTimeString()};z(ye=>[...ye,ne]),G(""),x(!1),X.close()}else he.type==="error"&&(t.message.error(he.content||"执行出错"),G(""),x(!1),X.close())}catch{G(ne=>ne+ie.data)}},X.onerror=async()=>{var ie,he;X.close(),x(!1),v(!1);try{const ne=await ue.execute({sceneCode:d,message:W,userId:ce,userName:H,config:A}),ye={id:Date.now()+1,role:"assistant",content:((ie=ne.data)==null?void 0:ie.content)||((he=ne.data)==null?void 0:he.reply)||JSON.stringify(ne.data)||"无响应",timestamp:new Date().toLocaleTimeString()};z(_e=>[..._e,ye])}catch{const ye={id:Date.now()+1,role:"assistant",content:"抱歉,执行过程中出现错误,请稍后重试。",timestamp:new Date().toLocaleTimeString()};z(_e=>[..._e,ye])}}}catch{t.message.error("执行失败"),v(!1),x(!1)}},[F,d,u,S,A,D]),c=W=>{W.key==="Enter"&&!W.shiftKey&&(W.preventDefault(),Q())},r=()=>{z([]),t.message.success("对话已清空")},L=()=>{var W;if((W=M.current)==null||W.close(),D){const ee={id:Date.now()+1,role:"assistant",content:D,timestamp:new Date().toLocaleTimeString()};z(ce=>[...ce,ee])}G(""),x(!1),v(!1),t.message.info("已停止生成")},$=W=>{navigator.clipboard.writeText(W).then(()=>t.message.success("已复制")).catch(()=>{})},R=W=>{W.messages&&z(Array.isArray(W.messages)?W.messages:[]),C(!1),t.message.success("已加载历史记录")},se=W=>W.split(`
214
- `).map((ee,ce)=>ee.startsWith("```")&&ee.endsWith("```")?e.jsx("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:6,fontSize:12,overflow:"auto"},children:ee.slice(3,-3)},ce):e.jsx("div",{style:{lineHeight:1.7},children:ee},ce));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100vh - 140px)",padding:0},children:[e.jsxs("div",{style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",padding:"14px 20px",display:"flex",alignItems:"center",gap:16,flexWrap:"wrap"},children:[e.jsx(t.Select,{value:n||void 0,onChange:W=>{T(W),b("")},placeholder:"选择产品",allowClear:!0,style:{width:180,borderRadius:8},size:"large",children:f.map(W=>e.jsx(ns,{value:W.productCode,children:W.productName},W.productCode))}),e.jsx(t.Select,{value:d||void 0,onChange:W=>b(W),placeholder:"选择场景",allowClear:!0,style:{width:200,borderRadius:8},size:"large",disabled:!n,children:w.map(W=>e.jsx(ns,{value:W.sceneCode,children:W.sceneName},W.sceneCode))}),d&&e.jsxs(t.Tag,{icon:e.jsx(l.CheckCircleOutlined,{}),color:"green",style:{borderRadius:20},children:[((je=w.find(W=>W.sceneCode===d))==null?void 0:je.sceneName)||d," 已就绪"]}),e.jsx("div",{style:{flex:1}}),e.jsxs(t.Space,{children:[e.jsx(t.Tooltip,{title:"执行配置",children:e.jsx(t.Button,{icon:e.jsx(l.ThunderboltOutlined,{}),onClick:()=>V(!0),style:{borderRadius:8},children:"参数"})}),e.jsx(t.Tooltip,{title:"历史记录",children:e.jsx(t.Button,{icon:e.jsx(l.HistoryOutlined,{}),onClick:()=>C(!0),style:{borderRadius:8},children:"历史"})}),e.jsx(t.Tooltip,{title:"清空对话",children:e.jsx(t.Button,{icon:e.jsx(l.ClearOutlined,{}),onClick:r,style:{borderRadius:8},children:"清空"})})]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"16px 20px",background:"#f5f5f5",display:"flex",flexDirection:"column"},children:d?e.jsxs(e.Fragment,{children:[m.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"30px 0 20px"},children:[e.jsx(t.Avatar,{size:56,icon:e.jsx(l.RobotOutlined,{}),style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",margin:"0 auto"}}),e.jsx(gl,{level:5,style:{marginTop:12,marginBottom:4},children:((le=w.find(W=>W.sceneCode===d))==null?void 0:le.sceneName)||"场景助手"}),e.jsx(Me,{type:"secondary",children:(_==null?void 0:_.description)||((fe=w.find(W=>W.sceneCode===d))==null?void 0:fe.description)||"开始对话吧!"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[m.map(W=>e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[e.jsx(t.Avatar,{size:36,icon:W.role==="user"?e.jsx(l.UserOutlined,{}):e.jsx(l.RobotOutlined,{}),style:{background:W.role==="user"?"#1890ff":"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx(Me,{strong:!0,style:{fontSize:13},children:W.role==="user"?"我":"助手"}),e.jsx(Me,{type:"secondary",style:{fontSize:11},children:W.timestamp}),W.role==="assistant"&&e.jsx(t.Tooltip,{title:"复制回复",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>$(W.content),style:{padding:0}})})]}),e.jsx(t.Card,{size:"small",style:{background:W.role==="user"?"#1890ff":"#fff",color:W.role==="user"?"#fff":"#333",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},styles:{body:{padding:"10px 14px"}},children:se(W.content)})]})]},W.id)),S&&D&&e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[e.jsx(t.Avatar,{size:36,icon:e.jsx(l.RobotOutlined,{}),style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsx("div",{style:{flex:1},children:e.jsxs(t.Card,{size:"small",style:{background:"#fff",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},styles:{body:{padding:"10px 14px"}},children:[se(D),e.jsx("span",{style:{display:"inline-block",width:8,height:16,background:"#667eea",marginLeft:2,animation:"blink 1s infinite",borderRadius:2}})]})})]}),u&&!S&&e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[e.jsx(t.Avatar,{size:36,icon:e.jsx(l.RobotOutlined,{}),style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsxs(t.Card,{size:"small",style:{background:"#fff",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},styles:{body:{padding:"10px 14px"}},children:[e.jsx(t.Spin,{indicator:e.jsx(l.LoadingOutlined,{style:{fontSize:16,color:"#667eea"},spin:!0})}),e.jsx(Me,{type:"secondary",style:{marginLeft:8},children:"正在思考..."})]})]})]}),e.jsx("div",{ref:y})]}):e.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(t.Empty,{image:e.jsx("div",{style:{fontSize:48,opacity:.3},children:e.jsx(l.RobotOutlined,{})}),description:e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:15,marginBottom:6},children:"请先选择产品与场景"}),e.jsx("div",{style:{color:"#999",fontSize:13},children:"在顶部选择要执行的场景,即可开始体验"})]}),style:{padding:40}})})}),e.jsxs("div",{style:{background:"#fff",padding:"12px 20px",borderTop:"1px solid #f0f0f0",display:"flex",gap:12,alignItems:"flex-end"},children:[e.jsx(ml,{ref:E,value:F,onChange:W=>N(W.target.value),onKeyDown:c,placeholder:d?"输入消息,Enter 发送,Shift+Enter 换行...":"请先选择场景...",disabled:!d||S,autoSize:{minRows:1,maxRows:4},style:{flex:1,borderRadius:20,resize:"none"}}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:S?e.jsx(t.Tooltip,{title:"停止生成",children:e.jsx(t.Button,{danger:!0,icon:e.jsx(l.CloseCircleOutlined,{}),onClick:L,style:{borderRadius:20}})}):e.jsx(t.Tooltip,{title:"发送",children:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.SendOutlined,{}),onClick:Q,disabled:!d||!F.trim()||u,style:{borderRadius:20,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",border:"none"}})})})]}),e.jsx(t.Modal,{title:e.jsxs("span",{children:[e.jsx(l.HistoryOutlined,{style:{marginRight:8}}),"对话历史"]}),open:g,onCancel:()=>C(!1),footer:null,width:600,children:P.length===0?e.jsx(t.Empty,{description:"暂无历史记录"}):e.jsx(t.List,{dataSource:P,renderItem:(W,ee)=>{var ce;return e.jsx(t.List.Item,{actions:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>R(W),children:"加载"},"load")],children:e.jsx(t.List.Item.Meta,{avatar:e.jsx(t.Avatar,{icon:e.jsx(yl,{}),style:{background:"#667eea"}}),title:`会话 ${ee+1} — ${W.startTime||""}`,description:e.jsxs(Me,{type:"secondary",style:{fontSize:12},children:[((ce=W.messages)==null?void 0:ce.length)||0," 条消息"]})})})}})}),e.jsx(t.Modal,{title:e.jsxs("span",{children:[e.jsx(l.ThunderboltOutlined,{style:{marginRight:8}}),"执行参数配置"]}),open:O,onCancel:()=>V(!1),onOk:()=>{V(!1),t.message.success("参数已保存")},okText:"保存",children:e.jsxs(t.Form,{form:U,layout:"vertical",initialValues:A,children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"temperature",label:"Temperature (随机性)",children:e.jsx(InputNumber,{min:0,max:2,step:.1,style:{width:"100%"}})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"maxTokens",label:"Max Tokens (最大字数)",children:e.jsx(InputNumber,{min:100,max:8192,step:100,style:{width:"100%"}})})})]}),e.jsx(t.Form.Item,{name:"topP",label:"Top P",children:e.jsx(InputNumber,{min:0,max:1,step:.05,style:{width:"100%"}})})]})}),e.jsx("style",{children:`
213
+ `}]}],yt=[{categoryCode:"backend",categoryName:"后端开发",parentCode:"",skillCount:2},{categoryCode:"frontend",categoryName:"前端开发",parentCode:"",skillCount:2},{categoryCode:"devops",categoryName:"DevOps",parentCode:"",skillCount:1},{categoryCode:"testing",categoryName:"测试",parentCode:"",skillCount:1},{categoryCode:"ai-agent",categoryName:"AI Agent",parentCode:"",skillCount:1},{categoryCode:"doc",categoryName:"文档",parentCode:"",skillCount:1}],ts={total:8,published:7},{TextArea:al}=t.Input,{Title:eo,Paragraph:cl,Text:dl}=t.Typography,ss={backend:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",frontend:"linear-gradient(135deg, #f093fb 0%, #f5576c 100%)",devops:"linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",testing:"linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)","ai-agent":"linear-gradient(135deg, #fa709a 0%, #fee140 100%)",doc:"linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)",default:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)"},Me=i=>ss[i]||ss.default,ls={PUBLISHED:"已发布",DRAFT:"草稿",ARCHIVED:"已归档"},Ye=["blue","green","cyan","purple","orange","red"],pl=i=>{const o={};i.forEach(r=>{o[r.categoryCode]={key:r.categoryCode,title:r.categoryName,categoryCode:r.categoryCode,categoryName:r.categoryName,parentCode:r.parentCode||"",skillCount:r.skillCount||0,data:r,children:[]}});const a=[];return i.forEach(r=>{const j=o[r.categoryCode];r.parentCode&&o[r.parentCode]?o[r.parentCode].children.push(j):r.parentCode||a.push(j)}),a},os=i=>{const o=[],a=(r,j)=>{r.forEach(c=>{var b;const m=c.categoryCode||c.key;o.push({categoryCode:m,categoryName:c.categoryName||c.title,parentCode:j||c.parentCode||"",skillCount:c.skillCount||0}),(b=c.children)!=null&&b.length&&a(c.children,m)})};return i!=null&&i.length&&a(i,""),o};function ul(i){const o={key:"__root__",children:[]},a={"":o};return i.forEach(r=>{const j=r.path.split("/");j.pop();let c="";j.forEach((m,b)=>{const S=j.slice(0,b+1).join("/");a[S]||(a[S]={key:S,title:m,isLeaf:!1,children:[]}),a[c].children.some(y=>y.key===S)||a[c].children.push(a[S]),c=S})}),i.forEach(r=>{const j=r.path.includes("/")?r.path.split("/").slice(0,-1).join("/"):"",c=r.path.includes("/")?r.path.split("/").pop():r.path;a[j].children.push({key:r.path,title:c,isLeaf:!0,file:r})}),o.children}function xl(){const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState(0),[m,b]=s.useState(1),S=s.useRef(12),[y,p]=s.useState(""),[g,P]=s.useState(void 0),[N,D]=s.useState("download_count"),[x,v]=s.useState([]),[T,f]=s.useState([]),[M,K]=s.useState(!1),[C,k]=s.useState(null),[E,W]=s.useState(""),[h,B]=s.useState([]),[F,A]=s.useState(!1),[I,G]=s.useState("overview"),[u,w]=s.useState(null),[U,z]=s.useState([]),[Q,d]=s.useState(!1),[n]=t.Form.useForm(),[_,$]=s.useState(!1),[R,se]=s.useState(!1),[je,le]=s.useState({total:0,published:0}),[fe,V]=s.useState(!1),[ee,ce]=s.useState(null),[H,X]=s.useState(null),[ie,he]=s.useState(!1),[re]=t.Form.useForm(),[ye,Ue]=s.useState(220),Ml=s.useRef(null),Ze=s.useRef(!1),ds=s.useRef(0),ps=s.useRef(0),At=async()=>{try{const O=await ge.stats();O&&(O.total!==void 0||O.published!==void 0)?le(O):O!=null&&O.data?le(O.data):le(ts)}catch{le(ts)}},Ge=s.useCallback(async(O=1)=>{var J;r(!0);try{const Y={current:O,size:S.current,sortBy:N};y&&(Y.keyword=y),g&&(Y.categoryCode=g),(y||g)&&(Y.status="PUBLISHED");const q=await ge.page(Y);if(q&&q.records)o(q.records),c(Number(q.total)||q.records.length);else if(Array.isArray(q))o(q),c(q.length);else if((J=q==null?void 0:q.data)!=null&&J.records)o(q.data.records),c(Number(q.data.total)||q.data.records.length);else{const oe=es.filter(pe=>!(y&&!pe.skillName.includes(y)&&!pe.description.includes(y)||g&&pe.categoryCode!==g));o(oe),c(oe.length)}}catch(Y){console.error("loadSkills error:",Y);const q=es.filter(oe=>!(y&&!oe.skillName.includes(y)&&!oe.description.includes(y)||g&&oe.categoryCode!==g));o(q),c(q.length)}finally{r(!1)}},[y,g,N]),Xe=async()=>{var O,J;try{const Y=await ge.categoryTree(),q=oe=>(oe||[]).map(pe=>({categoryCode:pe.catCode||pe.categoryCode,categoryName:pe.catName||pe.categoryName,parentCode:pe.parentCode||"",skillCount:pe.skillCount||0,children:pe.children?q(pe.children):void 0}));if(Array.isArray(Y)&&Y.length>0){const oe=q(Y);(O=oe[0])!=null&&O.children?v(os(oe)):v(oe)}else if(Y!=null&&Y.data&&Y.data.length>0){const oe=q(Y.data);(J=oe[0])!=null&&J.children?v(os(oe)):v(oe)}else v(yt)}catch{const q=localStorage.getItem("z_skill_categories");if(q)try{v(JSON.parse(q))}catch{v(yt)}else v(yt)}};s.useEffect(()=>{At(),Xe()},[]),s.useEffect(()=>{Ge(m)},[Ge,m]);const _l=()=>{b(1),Ge(1)},Ul=O=>{P(J=>J===O?void 0:O),b(1)},Gl=O=>{D(O),b(1)},Wl=async O=>{var J,Y,q;k(O),K(!0),W(O.content||""),B([]),w(null),z([]),G("overview"),A(!0);try{const[oe,pe]=await Promise.allSettled([ge.getBySkillCode(O.skillCode),ge.versions(O.skillCode)]);if(oe.status==="fulfilled"&&oe.value){const ve=((J=oe.value)==null?void 0:J.data)||oe.value;if(ve&&typeof ve=="object"){const ql={...O,...ve};k(ql),W(ve.content||ve.readme||O.content||""),(Y=ve.files)!=null&&Y.length&&w(ve.files[0])}}if(pe.status==="fulfilled"&&pe.value){const ve=((q=pe.value)==null?void 0:q.data)||pe.value;Array.isArray(ve)&&B(ve)}}catch(oe){console.warn("openDetail error:",oe)}finally{A(!1)}},us=async O=>{try{await navigator.clipboard.writeText(O),t.message.success("已复制到剪贴板")}catch{t.message.error("复制失败")}},xs=O=>{if(O)if(O.packageType==="ZIP"&&(O.packagePath||O.version)){const J=ge.downloadPackage(O.skillCode,O.version);window.open(J,"_blank")}else O.content&&us(O.content)},hs=async O=>{try{const J=await ge.install({skillCode:O});J!=null?(t.message.success("安装成功"),At()):t.message.error("安装失败")}catch{t.message.error("安装异常")}},Vl=async O=>{if(!C)return!1;if(!O.name.toLowerCase().endsWith(".zip"))return t.message.error("仅支持 .zip 格式"),t.Upload.LIST_IGNORE;se(!0);try{await ge.uploadPackage(C.skillCode,C.version||"1.0.0",O),t.message.success("上传成功"),k(J=>J&&{...J,packageType:"ZIP"});try{const J=await ge.getBySkillCode(C.skillCode),Y=J&&typeof J=="object"&&"data"in J?J.data:J;Y&&k(q=>q&&{...q,...Y})}catch{}Ge(m)}catch(J){console.error("uploadPackage error:",J),t.message.error("上传失败:"+((J==null?void 0:J.message)||"未知错误"))}finally{se(!1)}return!1},Kl=async()=>{try{const O=await n.validateFields();$(!0);const J=await ge.create({...O,status:"PUBLISHED"});J!=null?(t.message.success("发布成功"),d(!1),n.resetFields(),Ge(1),At()):t.message.error("发布失败")}catch(O){if(O!=null&&O.errorFields)return;t.message.error("发布异常")}finally{$(!1)}},ms=O=>{ce(null),X(O),re.resetFields(),O&&re.setFieldsValue({parentCode:O.categoryCode}),V(!0)},Hl=O=>{ce(O),X(null),re.setFieldsValue({categoryCode:O.categoryCode,categoryName:O.categoryName,parentCode:O.parentCode||""}),V(!0)},Jl=async()=>{try{const O=await re.validateFields();he(!0),ee?(await ge.createCategory({catCode:O.categoryCode,catName:O.categoryName,parentCode:O.parentCode||""}),t.message.success("更新成功")):(await ge.createCategory({catCode:O.categoryCode,catName:O.categoryName,parentCode:O.parentCode||""}),t.message.success("创建成功")),V(!1),Xe()}catch(O){if(O!=null&&O.errorFields)return;const J=re.getFieldsValue();let Y=[...x];if(ee){const q=Y.findIndex(oe=>oe.categoryCode===ee.categoryCode);q>=0&&(Y[q]={...Y[q],...J})}else Y.push({categoryCode:J.categoryCode,categoryName:J.categoryName,parentCode:J.parentCode||"",skillCount:0});v(Y),localStorage.setItem("z_skill_categories",JSON.stringify(Y)),V(!1),t.message.success(ee?"更新成功":"创建成功")}finally{he(!1)}},Yl=async O=>{try{const J=x.find(q=>q.categoryCode===O),Y=J==null?void 0:J.id;if(Y)await ge.deleteCategory(Y);else throw new Error("no api id");t.message.success("删除成功"),Xe()}catch{const Y=x.filter(q=>q.categoryCode!==O);v(Y),localStorage.setItem("z_skill_categories",JSON.stringify(Y)),t.message.success("删除成功")}},Ql=O=>{const J=x.find(Y=>Y.categoryCode===O.categoryCode);return J?e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,padding:"2px 0",cursor:"pointer"},onClick:()=>Ul(O.categoryCode),children:[g===O.categoryCode?e.jsx(l.FolderOpenOutlined,{style:{fontSize:13,color:"#667eea"}}):e.jsx(l.FolderOutlined,{style:{fontSize:13,color:"#8c8c8c"}}),e.jsx("span",{style:{flex:1,fontSize:13,color:g===O.categoryCode?"#667eea":void 0,fontWeight:g===O.categoryCode?600:400},children:J.categoryName}),e.jsx(t.Tag,{style:{fontSize:10,padding:"0 4px",lineHeight:"16px",marginRight:0},children:J.skillCount||0}),e.jsx(t.Dropdown,{trigger:["click"],menu:{items:[{key:"add",icon:e.jsx(l.PlusOutlined,{}),label:"新增子分类"},{key:"edit",icon:e.jsx(l.EditOutlined,{}),label:"编辑分类"},{type:"divider"},{key:"delete",icon:e.jsx(l.DeleteOutlined,{}),label:"删除分类",danger:!0}],onClick:({key:Y,domEvent:q})=>{q.stopPropagation(),Y==="add"?ms(J):Y==="edit"?Hl(J):Y==="delete"&&t.Modal.confirm({title:`删除分类"${J.categoryName}"?`,content:"子分类也会被删除",okText:"确认删除",okType:"danger",cancelText:"取消",onOk:()=>Yl(O.categoryCode)})}},children:e.jsx(t.Button,{type:"text",size:"small",icon:e.jsx(l.MoreOutlined,{style:{fontSize:13}}),onClick:Y=>Y.stopPropagation()})})]}):e.jsx("span",{children:O.title})},Zl=[{value:"download_count",label:"最热门"},{value:"gmt_create",label:"最新发布"},{value:"skill_name",label:"名称排序"}],Xl=s.useCallback(O=>{O.preventDefault(),Ze.current=!0,ds.current=O.clientX,ps.current=ye,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[ye]);return s.useEffect(()=>{const O=Y=>{if(!Ze.current)return;const q=Math.max(180,Math.min(ps.current+Y.clientX-ds.current,340));Ue(q)},J=()=>{Ze.current&&(Ze.current=!1,document.body.style.cursor="",document.body.style.userSelect="")};return window.addEventListener("mousemove",O),window.addEventListener("mouseup",J),()=>{window.removeEventListener("mousemove",O),window.removeEventListener("mouseup",J)}},[]),e.jsxs("div",{style:{display:"flex",gap:16,minHeight:600},children:[e.jsx("div",{ref:Ml,style:{width:ye,flexShrink:0},children:e.jsx(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.AppstoreOutlined,{style:{color:"#667eea",marginRight:6}}),"分类"]}),extra:e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:Xe}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.PlusOutlined,{}),onClick:()=>ms(null)})]}),styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"10px 14px"},body:{padding:"6px 8px"}},children:e.jsx(t.Tree,{showIcon:!1,treeData:pl(x),defaultExpandAll:!0,showLine:!0,titleRender:Ql,selectedKeys:g?[g]:[],onSelect:()=>{},style:{fontSize:13}})})}),e.jsx("div",{onMouseDown:Xl,style:{width:6,cursor:"col-resize",flexShrink:0,background:"#f0f0f0",borderRadius:3,alignSelf:"stretch"}}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",gap:12,minWidth:0},children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"center",flexWrap:"wrap",background:"#fff",padding:"14px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.04)"},children:[e.jsx(t.Input,{prefix:e.jsx(l.SearchOutlined,{style:{color:"#bfbfbf"}}),placeholder:"搜索技能名称、描述、标签...",value:y,onChange:O=>p(O.target.value),onPressEnter:_l,allowClear:!0,style:{width:260,borderRadius:8}}),e.jsx(t.Select,{value:N,onChange:Gl,options:Zl,style:{width:130,borderRadius:8}}),e.jsx("div",{style:{flex:1}}),e.jsxs("div",{style:{display:"flex",gap:20,alignItems:"center"},children:[e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,color:"#667eea",lineHeight:1.2},children:je.total||0}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:"全部技能"})]}),e.jsx("div",{style:{width:1,height:32,background:"#f0f0f0"}}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:22,fontWeight:700,color:"#52c41a",lineHeight:1.2},children:je.published||0}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:"已发布"})]})]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CloudUploadOutlined,{}),onClick:()=>d(!0),style:{borderRadius:8,height:36,paddingInline:18,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",border:"none",fontWeight:600,boxShadow:"0 4px 12px rgba(102,126,234,0.3)"},children:"发布技能"})]}),a?e.jsx("div",{style:{textAlign:"center",padding:60},children:e.jsx(t.Spin,{size:"large"})}):i.length===0?e.jsx(t.Empty,{description:"暂无技能",style:{padding:60}}):e.jsx(t.Row,{gutter:[16,16],children:i.map(O=>{const J=(O.tags||"").split(",").filter(Boolean);return e.jsx(t.Col,{xs:24,sm:12,md:8,lg:6,children:e.jsxs(t.Card,{hoverable:!0,size:"small",onClick:()=>Wl(O),style:{borderRadius:12,border:"none",boxShadow:"0 2px 12px rgba(0,0,0,0.07)",overflow:"hidden",cursor:"pointer"},styles:{body:{padding:0}},onMouseEnter:Y=>{Y.currentTarget.style.boxShadow="0 8px 24px rgba(102,126,234,0.18)",Y.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:Y=>{Y.currentTarget.style.boxShadow="0 2px 12px rgba(0,0,0,0.07)",Y.currentTarget.style.transform="translateY(0)"},children:[e.jsx("div",{style:{background:Me(O.categoryCode),padding:"14px 16px",borderRadius:"12px 12px 0 0"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:10,background:"rgba(255,255,255,0.2)",display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(8px)"},children:e.jsx(l.CodeOutlined,{style:{fontSize:20,color:"#fff"}})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#fff",lineHeight:1.3},children:O.skillName}),e.jsxs("div",{style:{fontSize:11,color:"rgba(255,255,255,0.8)",marginTop:2},children:["v",O.version," · ",O.author]})]}),O.status!=="PUBLISHED"&&e.jsx(t.Tag,{style:{background:"rgba(255,255,255,0.25)",color:"#fff",border:"none",borderRadius:10,fontSize:11},children:ls[O.status]})]})}),e.jsxs("div",{style:{padding:"12px 14px 14px"},children:[e.jsx(cl,{ellipsis:{rows:2},style:{fontSize:12,color:"#666",marginBottom:10,minHeight:36},children:O.description||"暂无描述"}),e.jsxs("div",{style:{display:"flex",gap:4,flexWrap:"wrap",marginBottom:10},children:[J.slice(0,3).map((Y,q)=>e.jsx(t.Tag,{color:Ye[q%Ye.length],style:{fontSize:11,borderRadius:4,marginBottom:2},children:Y},Y)),J.length>3&&e.jsxs(t.Tag,{style:{fontSize:11},children:["+",J.length-3]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingTop:10,borderTop:"1px solid #f5f5f5"},children:[e.jsx(t.Tooltip,{title:"安装次数",children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:3},children:[e.jsx(l.FireOutlined,{style:{color:"#ff4d4f",fontSize:12}}),e.jsx(dl,{type:"secondary",style:{fontSize:12},children:O.downloadCount||0})]})}),e.jsx(t.Button,{type:"primary",size:"small",icon:e.jsx(l.DownloadOutlined,{}),onClick:Y=>{Y.stopPropagation(),hs(O.skillCode)},style:{borderRadius:6,background:Me(O.categoryCode),border:"none",fontWeight:500},children:"安装"})]})]})]})},O.id)})}),j>S.current&&e.jsx("div",{style:{textAlign:"right",padding:"8px 0"},children:e.jsx(t.Pagination,{current:m,pageSize:S.current,total:j,onChange:O=>{b(O),window.scrollTo({top:0,behavior:"smooth"})},showSizeChanger:!1})})]}),e.jsx(t.Drawer,{title:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:36,height:36,borderRadius:8,background:Me(C==null?void 0:C.categoryCode),display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.CodeOutlined,{style:{fontSize:18,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:15,fontWeight:600},children:C==null?void 0:C.skillName}),e.jsxs("div",{style:{fontSize:11,color:"#999",fontWeight:400},children:["v",C==null?void 0:C.version," · ",C==null?void 0:C.author," · ",ls[C==null?void 0:C.status]||(C==null?void 0:C.status)]})]})]}),open:M,onClose:()=>K(!1),width:"75%",styles:{header:{padding:"14px 24px",borderBottom:"1px solid #f0f0f0"},body:{padding:0}},children:C&&e.jsxs("div",{style:{height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{padding:"16px 24px",borderBottom:"1px solid #f0f0f0",display:"flex",alignItems:"center",gap:16,flexWrap:"wrap",background:"#fafafa"},children:[C.packageType==="ZIP"&&C.packagePath?e.jsx(t.Button,{type:"primary",size:"large",icon:e.jsx(l.DownloadOutlined,{}),onClick:()=>xs(C),style:{borderRadius:8,background:Me(C.categoryCode),border:"none",fontWeight:600,height:40,paddingInline:24},children:"下载技能包 (ZIP)"}):C.content?e.jsx(t.Button,{type:"primary",size:"large",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>us(C.content),style:{borderRadius:8,background:Me(C.categoryCode),border:"none",fontWeight:600,height:40,paddingInline:24},children:"复制技能内容"}):e.jsx(t.Button,{size:"large",disabled:!0,icon:e.jsx(l.DownloadOutlined,{}),style:{height:40},children:"暂无下载包"}),e.jsx(t.Button,{icon:e.jsx(l.DownloadOutlined,{}),onClick:()=>hs(C.skillCode),style:{borderRadius:8,height:40},children:"安装此技能"}),e.jsxs("div",{style:{flex:1,display:"flex",gap:8,flexWrap:"wrap",justifyContent:"flex-end"},children:[e.jsxs(t.Tag,{icon:e.jsx(l.CheckCircleOutlined,{}),color:"blue",children:["v",C.version]}),e.jsxs(t.Tag,{icon:e.jsx(l.FireOutlined,{}),color:"red",children:[C.downloadCount||0," 次安装"]}),e.jsx(t.Tag,{icon:e.jsx(l.StarOutlined,{}),color:"orange",children:C.author}),C.gmtModified&&e.jsx(t.Tag,{icon:e.jsx(l.ClockCircleOutlined,{}),color:"default",children:new Date(C.gmtModified).toLocaleDateString()})]})]}),e.jsx("div",{style:{flex:1,overflow:"auto"},children:e.jsx(t.Tabs,{activeKey:I,onChange:G,style:{height:"100%"},tabBarStyle:{padding:"0 24px",marginBottom:0},items:[{key:"overview",label:e.jsxs("span",{children:[e.jsx(l.InfoCircleOutlined,{})," 概述"]}),children:e.jsx("div",{style:{padding:"20px 24px"},children:F?e.jsx("div",{style:{textAlign:"center",padding:40},children:e.jsx(t.Spin,{})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#333",marginBottom:8},children:"简介"}),e.jsx("div",{style:{fontSize:14,color:"#555",lineHeight:1.8},children:C.description||"暂无描述"})]}),C.tags&&e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#333",marginBottom:8},children:"标签"}),e.jsx("div",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:(C.tags||"").split(",").filter(Boolean).map((O,J)=>e.jsx(t.Tag,{color:Ye[J%Ye.length],style:{fontSize:12,borderRadius:4,padding:"2px 8px"},children:O},O))})]}),E&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#333",marginBottom:8},children:"技能说明"}),e.jsx("div",{style:{background:"#fafafa",border:"1px solid #f0f0f0",padding:16,borderRadius:8,lineHeight:1.8,fontSize:14,color:"#333"},children:e.jsx(Et,{components:{code:({node:O,inline:J,className:Y,children:q,...oe})=>J?e.jsx("code",{style:{background:"#f0f0f0",padding:"2px 6px",borderRadius:4,fontSize:13},...oe,children:q}):e.jsx("pre",{style:{background:"#1e1e1e",color:"#d4d4d4",padding:14,borderRadius:8,overflow:"auto",fontSize:13},children:e.jsx("code",{...oe,children:q})}),h1:({children:O})=>e.jsx("h1",{style:{fontSize:20,fontWeight:700,borderBottom:"1px solid #eee",paddingBottom:8,marginBottom:12},children:O}),h2:({children:O})=>e.jsx("h2",{style:{fontSize:17,fontWeight:600,marginTop:20,marginBottom:8},children:O}),h3:({children:O})=>e.jsx("h3",{style:{fontSize:15,fontWeight:600,marginTop:16,marginBottom:6},children:O}),ul:({children:O})=>e.jsx("ul",{style:{paddingLeft:20,marginBottom:12},children:O}),li:({children:O})=>e.jsx("li",{style:{marginBottom:4},children:O}),p:({children:O})=>e.jsx("p",{style:{marginBottom:10},children:O})},children:E})})]})]})})},{key:"files",label:e.jsxs("span",{children:[e.jsx(l.FileTextOutlined,{})," 文件"]}),children:e.jsxs("div",{style:{padding:"20px 24px"},children:[C.files&&C.files.length>0?e.jsxs("div",{style:{display:"flex",gap:16,height:400},children:[e.jsx("div",{style:{width:220,flexShrink:0,border:"1px solid #f0f0f0",borderRadius:8,overflow:"auto",padding:"4px 0"},children:e.jsx(t.Tree,{treeData:ul(C.files),defaultExpandAll:!0,showIcon:!0,selectedKeys:u?[u.path]:[],onSelect:(O,J)=>{J.node.isLeaf&&J.node.file&&w(J.node.file)},titleRender:O=>e.jsx("span",{style:{fontSize:13},children:O.title}),icon:O=>O.isLeaf?e.jsx(l.FileTextOutlined,{style:{fontSize:13,color:"#8c8c8c"}}):e.jsx(l.FolderOutlined,{style:{fontSize:13,color:"#faad14"}})})}),e.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column"},children:u?e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:6},children:u.path}),e.jsx("pre",{style:{flex:1,background:"#1e1e1e",color:"#d4d4d4",padding:14,borderRadius:8,fontSize:12,lineHeight:1.6,overflow:"auto",whiteSpace:"pre-wrap",fontFamily:'"SF Mono","Fira Code","Consolas",monospace',margin:0},children:u.content||"(empty)"})]}):e.jsx("div",{style:{color:"#999",textAlign:"center",paddingTop:80},children:"选择一个文件查看内容"})})]}):C.packageType==="ZIP"&&C.packagePath?e.jsxs("div",{style:{background:"#f6ffed",border:"1px solid #b7eb8f",borderRadius:8,padding:20,textAlign:"center"},children:[e.jsx(l.FileZipOutlined,{style:{fontSize:36,color:"#52c41a",marginBottom:12}}),e.jsx("div",{style:{fontSize:14,fontWeight:600,color:"#389e0d",marginBottom:8},children:"ZIP 包已上传"}),e.jsx("div",{style:{fontSize:12,color:"#999",wordBreak:"break-all"},children:C.packagePath}),e.jsx(t.Button,{type:"link",icon:e.jsx(l.DownloadOutlined,{}),onClick:()=>xs(C),style:{marginTop:12},children:"下载并解压查看文件"})]}):e.jsxs("div",{style:{textAlign:"center",padding:40,color:"#999"},children:[e.jsx(l.FileTextOutlined,{style:{fontSize:36,color:"#d9d9d9",marginBottom:12}}),e.jsx("div",{children:"暂无文件,上传 ZIP 包后可查看文件目录"})]}),e.jsxs("div",{style:{marginTop:20,borderTop:"1px solid #f0f0f0",paddingTop:16},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#333",marginBottom:8},children:"上传技能包"}),e.jsx(t.Upload,{accept:".zip",showUploadList:!1,beforeUpload:Vl,disabled:R,children:e.jsxs("div",{style:{border:"2px dashed #d9d9d9",borderRadius:8,padding:16,textAlign:"center",cursor:R?"not-allowed":"pointer",opacity:R?.6:1},children:[R?e.jsx(t.Spin,{size:"small"}):e.jsx(l.CloudUploadOutlined,{style:{fontSize:20,color:"#bfbfbf"}}),e.jsx("div",{style:{fontSize:12,color:"#999",marginTop:6},children:R?"上传中...":C.packageType==="ZIP"?"重新上传 ZIP":"上传 ZIP 包"})]})})]})]})},{key:"versions",label:e.jsxs("span",{children:[e.jsx(l.HistoryOutlined,{})," 版本历史 ",h.length>0&&`(${h.length})`]}),children:e.jsx("div",{style:{padding:"20px 24px"},children:h.length>0?e.jsx(t.Timeline,{items:h.map((O,J)=>({color:J===0?"green":"gray",children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx(t.Tag,{color:J===0?"green":"default",style:{fontWeight:600},children:O.version||O.versionNumber||`v${J+1}`}),J===0&&e.jsx(t.Tag,{color:"blue",children:"当前版本"})]}),O.changeLog&&e.jsx("div",{style:{fontSize:13,color:"#666",marginTop:4},children:O.changeLog}),e.jsx("div",{style:{fontSize:11,color:"#bbb",marginTop:2},children:O.gmtCreate?new Date(O.gmtCreate).toLocaleString():""})]})}))}):e.jsxs("div",{style:{textAlign:"center",padding:40,color:"#999"},children:[e.jsx(l.HistoryOutlined,{style:{fontSize:36,color:"#d9d9d9",marginBottom:12}}),e.jsx("div",{children:"暂无版本记录"}),e.jsxs("div",{style:{fontSize:12,color:"#bbb",marginTop:4},children:["当前版本: v",C.version]})]})})}]})})]})}),e.jsx(t.Modal,{title:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:32,height:32,borderRadius:8,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.CloudUploadOutlined,{style:{fontSize:16,color:"#fff"}})}),e.jsx("span",{style:{fontSize:16},children:"发布新技能"})]}),open:Q,onCancel:()=>{d(!1),n.resetFields()},onOk:Kl,confirmLoading:_,okText:"确认发布",cancelText:"取消",width:580,style:{top:80},children:e.jsxs(t.Form,{form:n,layout:"vertical",style:{marginTop:12},children:[e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(t.Form.Item,{name:"skillCode",label:"技能编码",rules:[{required:!0,message:"请输入技能编码"}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"如 java-entity-gen",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"skillName",label:"技能名称",rules:[{required:!0,message:"请输入技能名称"}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"如 Java Entity 生成器",style:{borderRadius:8}})})]}),e.jsxs("div",{style:{display:"flex",gap:12},children:[e.jsx(t.Form.Item,{name:"categoryCode",label:"分类",style:{flex:1},children:e.jsx(t.Input,{placeholder:"如 backend",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"version",label:"版本号",initialValue:"1.0.0",rules:[{required:!0}],style:{flex:1},children:e.jsx(t.Input,{placeholder:"1.0.0",style:{borderRadius:8}})})]}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(al,{rows:3,placeholder:"简要描述技能功能...",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"tags",label:"标签",children:e.jsx(t.Input,{placeholder:"用逗号分隔,如 java,entity,generator",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"author",label:"作者",children:e.jsx(t.Input,{placeholder:"技能作者",style:{borderRadius:8}})})]})}),e.jsx(t.Modal,{title:ee?"编辑分类":H?`新建子分类 - ${H.categoryName}`:"新建分类",open:fe,onCancel:()=>V(!1),onOk:()=>re.submit(),confirmLoading:ie,destroyOnClose:!0,okText:"确认",cancelText:"取消",children:e.jsxs(t.Form,{form:re,layout:"vertical",onFinish:Jl,style:{marginTop:8},children:[e.jsx(t.Form.Item,{name:"categoryCode",label:"分类编码",rules:[{required:!0,message:"请输入分类编码"}],children:e.jsx(t.Input,{placeholder:"如 backend",disabled:!!ee,style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"categoryName",label:"分类名称",rules:[{required:!0,message:"请输入分类名称"}],children:e.jsx(t.Input,{placeholder:"如 后端开发",style:{borderRadius:8}})}),e.jsx(t.Form.Item,{name:"parentCode",label:"父分类",children:e.jsx(t.Select,{allowClear:!0,placeholder:"留空为顶级分类",popupMatchSelectWidth:!1,children:x.filter(O=>ee?O.categoryCode!==ee.categoryCode:!0).map(O=>e.jsx(t.Select.Option,{value:O.categoryCode,children:O.categoryName},O.categoryCode))})})]})})]})}const{TextArea:is}=t.Input,{Option:ke}=t.Select,{TabPane:rs}=t.Tabs,hl=()=>{const[i,o]=s.useState("list");return e.jsx(t.Card,{style:{minHeight:"calc(100vh - 140px)"},children:e.jsxs(t.Tabs,{activeKey:i,onChange:o,children:[e.jsx(rs,{tab:e.jsxs("span",{children:[e.jsx(l.ShopOutlined,{})," 产品管理"]}),children:e.jsx(ml,{})},"list"),e.jsx(rs,{tab:e.jsxs("span",{children:[e.jsx(l.FileTextOutlined,{})," 产品配置"]}),children:e.jsx(gl,{})},"config")]})})},ml=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState(""),[m,b]=s.useState(""),[S,y]=s.useState(1),[p]=s.useState(12),[g,P]=s.useState(0),[N,D]=s.useState(!1),[x]=t.Form.useForm(),[v,T]=s.useState(null),[f,M]=s.useState(!1),[K,C]=s.useState(!1),[k,E]=s.useState(null);s.useEffect(()=>{W()},[S,j,m]);const W=async()=>{r(!0);try{const z=await Se.page({productName:j,status:m,id:S});z.data&&(o(z.data.records||[]),P(z.data.total||0))}catch(z){t.message.error("加载失败: "+(z.message||""))}r(!1)},h=()=>{T(null),x.resetFields(),x.setFieldsValue({status:"DRAFT"}),D(!0)},B=z=>{T(z),x.setFieldsValue({productCode:z.productCode,productName:z.productName,description:z.description,category:z.category,version:z.version||"1.0.0",iconUrl:z.iconUrl,status:z.status,tags:z.tags}),D(!0)},F=async()=>{try{const z=await x.validateFields();M(!0),v?(await Se.update({id:v.id,...z}),t.message.success("更新成功")):(await Se.create(z),t.message.success("创建成功")),D(!1),W()}catch(z){z.errorFields||t.message.error("操作失败")}finally{M(!1)}},A=async z=>{try{await Se.delete(z),t.message.success("删除成功"),W()}catch{t.message.error("删除失败")}},I=async z=>{try{await Se.publish(z),t.message.success("发布成功"),W()}catch{t.message.error("发布失败")}},G=async z=>{try{await Se.offline(z),t.message.success("下架成功"),W()}catch{t.message.error("下架失败")}},u=async z=>{E(z),C(!0)},w=z=>{navigator.clipboard.writeText(z).then(()=>t.message.success("产品编码已复制")).catch(()=>{})},U=[{title:"产品",key:"product",width:280,render:(z,Q)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:8,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.ShopOutlined,{style:{fontSize:18,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:Q.productName}),e.jsxs("div",{style:{fontSize:12,color:"#999"},children:[e.jsx("span",{style:{fontFamily:"monospace"},children:Q.productCode}),e.jsx(t.Tooltip,{title:"复制编码",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>w(Q.productCode),style:{marginLeft:4,padding:0}})})]})]})]})},{title:"分类",dataIndex:"category",width:120,render:z=>z?e.jsx(t.Tag,{icon:e.jsx(l.TagOutlined,{}),children:z}):e.jsx("span",{style:{color:"#ccc"},children:"未分类"})},{title:"状态",dataIndex:"status",width:100,render:z=>{const Q={PUBLISHED:"success",DRAFT:"warning",OFFLINE:"error",ARCHIVED:"default"},d={PUBLISHED:"已发布",DRAFT:"草稿",OFFLINE:"已下架",ARCHIVED:"已归档"};return e.jsx(t.Badge,{status:Q[z]||"default",text:d[z]||z})}},{title:"版本",dataIndex:"version",width:90,render:z=>e.jsxs("span",{style:{fontFamily:"monospace"},children:["v",z||"1.0.0"]})},{title:"描述",dataIndex:"description",ellipsis:!0},{title:"操作",width:320,render:(z,Q)=>e.jsxs(t.Space,{size:"small",wrap:!0,children:[e.jsx(t.Tooltip,{title:"查看详情",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>u(Q),children:"详情"})}),e.jsx(t.Tooltip,{title:"编辑配置",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>B(Q),children:"编辑"})}),Q.status==="DRAFT"&&e.jsx(t.Tooltip,{title:"发布产品",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.CheckCircleOutlined,{}),onClick:()=>I(Q.productCode),children:"发布"})}),Q.status==="PUBLISHED"&&e.jsx(t.Tooltip,{title:"下架产品",children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.StopOutlined,{}),onClick:()=>G(Q.productCode),children:"下架"})}),e.jsx(t.Tooltip,{title:"执行场景",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:()=>window.open(`/ai/product/execute?productCode=${Q.productCode}`,"_blank"),children:"执行"})}),e.jsx(t.Popconfirm,{title:"确定删除此产品?",onConfirm:()=>A(Q.id),okText:"删除",okButtonProps:{danger:!0},children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:16,gap:12,flexWrap:"wrap"},children:[e.jsxs(t.Space,{children:[e.jsx(t.Input.Search,{placeholder:"搜索产品名称/编码",onSearch:z=>{c(z),y(1)},style:{width:220},allowClear:!0}),e.jsxs(t.Select,{placeholder:"状态筛选",allowClear:!0,style:{width:120},onChange:z=>{b(z),y(1)},children:[e.jsx(ke,{value:"DRAFT",children:"草稿"}),e.jsx(ke,{value:"PUBLISHED",children:"已发布"}),e.jsx(ke,{value:"OFFLINE",children:"已下架"}),e.jsx(ke,{value:"ARCHIVED",children:"已归档"})]})]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:h,children:"新建产品"})]}),e.jsx(t.Table,{dataSource:i,columns:U,loading:a,rowKey:"id",pagination:{current:S,pageSize:p,total:g,showSizeChanger:!1,showTotal:z=>`共 ${z} 个产品`,onChange:z=>y(z)},locale:{emptyText:e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"还没有产品,点击新建开始创建"})}}),e.jsx(t.Modal,{title:v?`编辑产品: ${v.productName}`:"新建产品",open:N,onOk:F,onCancel:()=>D(!1),width:640,confirmLoading:f,okText:v?"保存":"创建",children:e.jsxs(t.Form,{form:x,layout:"vertical",size:"middle",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"productName",label:"产品名称",rules:[{required:!0,message:"请输入产品名称"}],children:e.jsx(t.Input,{placeholder:"如:智能客服助手"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"productCode",label:"产品编码",rules:[{required:!0,message:"请输入产品编码"}],children:e.jsx(t.Input,{placeholder:"如 product-ai-assistant",disabled:!!v})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"category",label:"产品分类",children:e.jsx(t.Input,{placeholder:"如 AI助手, 图像生成"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"version",label:"版本号",initialValue:"1.0.0",children:e.jsx(t.Input,{placeholder:"1.0.0"})})})]}),e.jsx(t.Form.Item,{name:"description",label:"产品描述",children:e.jsx(is,{rows:2,placeholder:"简短描述这个产品的能力和使用场景"})}),e.jsx(t.Form.Item,{name:"tags",label:"产品标签",children:e.jsx(t.Input,{placeholder:"用逗号分隔,如 AI,客服,对话"})}),e.jsx(t.Form.Item,{name:"iconUrl",label:"图标URL",children:e.jsx(t.Input,{placeholder:"可选,图标图片URL"})}),!v&&e.jsx(t.Form.Item,{name:"status",label:"创建后状态",initialValue:"DRAFT",children:e.jsxs(t.Select,{children:[e.jsx(ke,{value:"DRAFT",children:"草稿(仅自己可见)"}),e.jsx(ke,{value:"PUBLISHED",children:"直接发布"})]})})]})}),e.jsx(t.Drawer,{title:"产品详情",open:K,onClose:()=>C(!1),width:560,children:k&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:10,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.ShopOutlined,{style:{fontSize:22,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600},children:k.productName}),e.jsx("div",{style:{fontSize:12,color:"#999"},children:k.productCode})]})]}),e.jsx(t.Divider,{style:{margin:"8px 0"}}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Statistic,{title:"分类",value:k.category||"未分类",valueStyle:{fontSize:14}})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Statistic,{title:"版本",value:k.version||"1.0.0",valueStyle:{fontSize:14}})})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"状态"}),e.jsx(t.Badge,{status:k.status==="PUBLISHED"?"success":k.status==="DRAFT"?"warning":"error",text:k.status==="PUBLISHED"?"已发布":k.status==="DRAFT"?"草稿":k.status==="OFFLINE"?"已下架":"已归档"})]}),k.tags&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:6},children:"标签"}),e.jsx(t.Space,{wrap:!0,children:(k.tags||"").split(",").filter(Boolean).map((z,Q)=>e.jsx(t.Tag,{color:"blue",children:z},Q))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"描述"}),e.jsx("div",{style:{color:"#333",lineHeight:1.6},children:k.description||"暂无描述"})]})]})})]})},gl=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(null),[j,c]=s.useState({scenes:[],params:[]}),[m,b]=s.useState(!1),[S,y]=s.useState(!1),[p,g]=s.useState(!1),[P]=t.Form.useForm();s.useEffect(()=>{Se.page({id:1,pageSize:100}).then(f=>{var M;o(((M=f.data)==null?void 0:M.records)||[])})},[]),s.useEffect(()=>{a&&N(a.productCode)},[a]);const N=async f=>{b(!0);try{const M=await Se.configGet(f);c(M.data||{scenes:[],params:[]})}catch{c({scenes:[],params:[]})}b(!1)},D=async()=>{if(a){y(!0);try{await Se.configSave({productCode:a.productCode,...j}),t.message.success("配置已保存")}catch{t.message.error("保存失败")}finally{y(!1)}}},x=()=>{P.resetFields(),g(!0)},v=async()=>{try{const f=await P.validateFields();c(M=>({...M,scenes:[...M.scenes||[],{...f,id:Date.now()}]})),g(!1),t.message.success("场景已添加")}catch{}},T=f=>{c(M=>({...M,scenes:(M.scenes||[]).filter(K=>K.id!==f)}))};return e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.ShopOutlined,{style:{color:"#667eea",marginRight:6}}),"选择产品"]}),style:{width:260,flexShrink:0,borderRadius:10},styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"12px 16px"},body:{padding:8}},children:[(i||[]).map(f=>e.jsxs("div",{onClick:()=>r(f),style:{padding:"10px 12px",borderRadius:8,cursor:"pointer",marginBottom:4,background:(a==null?void 0:a.id)===f.id?"linear-gradient(135deg, #667eea22, #764ba222)":"transparent",border:(a==null?void 0:a.id)===f.id?"1px solid #667eea44":"1px solid transparent",transition:"all 0.2s"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:f.productName}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:f.productCode})]},f.id)),i.length===0&&e.jsx(t.Empty,{description:"暂无产品",style:{padding:20}})]}),e.jsx(t.Card,{title:e.jsxs("span",{style:{fontWeight:600},children:["产品配置 ",a?`- ${a.productName}`:""]}),extra:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.CloudUploadOutlined,{}),onClick:D,disabled:!a,loading:S,children:"保存配置"}),style:{flex:1,borderRadius:10},children:a?m?e.jsx("div",{style:{textAlign:"center",padding:40},children:"加载中..."}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:20},children:e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12},children:[e.jsx("span",{style:{fontWeight:500},children:"关联场景"}),e.jsx(t.Button,{size:"small",icon:e.jsx(l.PlusOutlined,{}),onClick:x,children:"添加场景"})]}),(j.scenes||[]).length===0?e.jsxs("div",{style:{textAlign:"center",padding:"20px 0",color:"#999",background:"#fafafa",borderRadius:8},children:[e.jsx(l.ExclamationCircleOutlined,{style:{marginRight:6}}),"暂无关联场景"]}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:(j.scenes||[]).map((f,M)=>e.jsx(t.Card,{size:"small",style:{background:"#fafafa",border:"none"},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx(t.Tag,{color:"purple",children:f.sceneName}),e.jsx("span",{style:{fontSize:12,color:"#666",marginLeft:8},children:f.sceneCode})]}),e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>T(f.id)})]})},f.id||M))})]})}):e.jsx(t.Empty,{description:"请先选择产品",style:{padding:60},image:t.Empty.PRESENTED_IMAGE_SIMPLE})}),e.jsx(t.Modal,{title:"添加场景",open:p,onOk:v,onCancel:()=>g(!1),okText:"添加",children:e.jsxs(t.Form,{form:P,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"sceneName",label:"场景名称",rules:[{required:!0,message:"请输入场景名称"}],children:e.jsx(t.Input,{placeholder:"如 智能问答"})}),e.jsx(t.Form.Item,{name:"sceneCode",label:"场景编码",rules:[{required:!0,message:"请输入场景编码"}],children:e.jsx(t.Input,{placeholder:"如 chat_scene"})}),e.jsx(t.Form.Item,{name:"sceneType",label:"场景类型",initialValue:"CONVERSATION",children:e.jsxs(t.Select,{children:[e.jsx(ke,{value:"CONVERSATION",children:"对话"}),e.jsx(ke,{value:"TASK",children:"任务"}),e.jsx(ke,{value:"WORKFLOW",children:"工作流"})]})}),e.jsx(t.Form.Item,{name:"description",label:"描述",children:e.jsx(is,{rows:2,placeholder:"场景描述"})})]})})]})},{TextArea:fl}=t.Input,{Text:_e,Title:yl}=t.Typography,{Option:ns}=t.Select,jl=()=>{var je,le,fe;const i=new URLSearchParams(window.location.search),o=i.get("productCode")||"",a=i.get("sceneCode")||"",[r,j]=s.useState(o),[c,m]=s.useState(a),[b,S]=s.useState([]),[y,p]=s.useState([]),[g,P]=s.useState([]),[N,D]=s.useState(""),[x,v]=s.useState(!1),[T,f]=s.useState(!1),[M,K]=s.useState(""),[C,k]=s.useState(!1),[E,W]=s.useState([]),[h,B]=s.useState(!1),[F]=t.Form.useForm(),[A,I]=s.useState({temperature:.7,maxTokens:2048,topP:1}),[G,u]=s.useState(null),w=s.useRef(null),U=s.useRef(null),z=s.useRef(null);s.useEffect(()=>{Se.page({id:1,pageSize:100,status:"PUBLISHED"}).then(V=>{var ee;S(((ee=V.data)==null?void 0:ee.records)||[])})},[]),s.useEffect(()=>{if(!r){p([]);return}ue.page({id:1,pageSize:100,status:"PUBLISHED",productCode:r}).then(V=>{var ee;p(((ee=V.data)==null?void 0:ee.records)||[])})},[r]),s.useEffect(()=>{if(!c){u(null);return}ue.configGet(c).then(V=>{u(V.data)}).catch(()=>u(null))},[c]),s.useEffect(()=>{c&&ue.chatHistory(c).then(V=>{W(Array.isArray(V.data)?V.data:[])}).catch(()=>W([]))},[c]),s.useEffect(()=>{var V;(V=w.current)==null||V.scrollIntoView({behavior:"smooth"})},[g,M]),s.useEffect(()=>{var V;(V=z.current)==null||V.focus()},[c]);const Q=s.useCallback(async()=>{if(!N.trim()||!c||x||T)return;const V=N.trim();D("");const ee={id:Date.now(),role:"user",content:V,timestamp:new Date().toLocaleTimeString()};P(ce=>[...ce,ee]),v(!0),K("");try{f(!0);const ce=localStorage.getItem("userId")||"anonymous",H=localStorage.getItem("userName")||"匿名用户",X=new EventSource(`/api/scene/execute/stream?sceneCode=${c}&message=${encodeURIComponent(V)}&userId=${ce}&userName=${encodeURIComponent(H)}`);U.current=X,X.onmessage=ie=>{try{const he=JSON.parse(ie.data);if(he.type==="chunk")K(re=>re+he.content);else if(he.type==="done"){const re={id:Date.now()+1,role:"assistant",content:M+he.content,timestamp:new Date().toLocaleTimeString()};P(ye=>[...ye,re]),K(""),f(!1),X.close()}else he.type==="error"&&(t.message.error(he.content||"执行出错"),K(""),f(!1),X.close())}catch{K(re=>re+ie.data)}},X.onerror=async()=>{var ie,he;X.close(),f(!1),v(!1);try{const re=await ue.execute({sceneCode:c,message:V,userId:ce,userName:H,config:A}),ye={id:Date.now()+1,role:"assistant",content:((ie=re.data)==null?void 0:ie.content)||((he=re.data)==null?void 0:he.reply)||JSON.stringify(re.data)||"无响应",timestamp:new Date().toLocaleTimeString()};P(Ue=>[...Ue,ye])}catch{const ye={id:Date.now()+1,role:"assistant",content:"抱歉,执行过程中出现错误,请稍后重试。",timestamp:new Date().toLocaleTimeString()};P(Ue=>[...Ue,ye])}}}catch{t.message.error("执行失败"),v(!1),f(!1)}},[N,c,x,T,A,M]),d=V=>{V.key==="Enter"&&!V.shiftKey&&(V.preventDefault(),Q())},n=()=>{P([]),t.message.success("对话已清空")},_=()=>{var V;if((V=U.current)==null||V.close(),M){const ee={id:Date.now()+1,role:"assistant",content:M,timestamp:new Date().toLocaleTimeString()};P(ce=>[...ce,ee])}K(""),f(!1),v(!1),t.message.info("已停止生成")},$=V=>{navigator.clipboard.writeText(V).then(()=>t.message.success("已复制")).catch(()=>{})},R=V=>{V.messages&&P(Array.isArray(V.messages)?V.messages:[]),k(!1),t.message.success("已加载历史记录")},se=V=>V.split(`
214
+ `).map((ee,ce)=>ee.startsWith("```")&&ee.endsWith("```")?e.jsx("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:6,fontSize:12,overflow:"auto"},children:ee.slice(3,-3)},ce):e.jsx("div",{style:{lineHeight:1.7},children:ee},ce));return e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"calc(100vh - 140px)",padding:0},children:[e.jsxs("div",{style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",padding:"14px 20px",display:"flex",alignItems:"center",gap:16,flexWrap:"wrap"},children:[e.jsx(t.Select,{value:r||void 0,onChange:V=>{j(V),m("")},placeholder:"选择产品",allowClear:!0,style:{width:180,borderRadius:8},size:"large",children:b.map(V=>e.jsx(ns,{value:V.productCode,children:V.productName},V.productCode))}),e.jsx(t.Select,{value:c||void 0,onChange:V=>m(V),placeholder:"选择场景",allowClear:!0,style:{width:200,borderRadius:8},size:"large",disabled:!r,children:y.map(V=>e.jsx(ns,{value:V.sceneCode,children:V.sceneName},V.sceneCode))}),c&&e.jsxs(t.Tag,{icon:e.jsx(l.CheckCircleOutlined,{}),color:"green",style:{borderRadius:20},children:[((je=y.find(V=>V.sceneCode===c))==null?void 0:je.sceneName)||c," 已就绪"]}),e.jsx("div",{style:{flex:1}}),e.jsxs(t.Space,{children:[e.jsx(t.Tooltip,{title:"执行配置",children:e.jsx(t.Button,{icon:e.jsx(l.ThunderboltOutlined,{}),onClick:()=>B(!0),style:{borderRadius:8},children:"参数"})}),e.jsx(t.Tooltip,{title:"历史记录",children:e.jsx(t.Button,{icon:e.jsx(l.HistoryOutlined,{}),onClick:()=>k(!0),style:{borderRadius:8},children:"历史"})}),e.jsx(t.Tooltip,{title:"清空对话",children:e.jsx(t.Button,{icon:e.jsx(l.ClearOutlined,{}),onClick:n,style:{borderRadius:8},children:"清空"})})]})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:"16px 20px",background:"#f5f5f5",display:"flex",flexDirection:"column"},children:c?e.jsxs(e.Fragment,{children:[g.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"30px 0 20px"},children:[e.jsx(t.Avatar,{size:56,icon:e.jsx(l.RobotOutlined,{}),style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",margin:"0 auto"}}),e.jsx(yl,{level:5,style:{marginTop:12,marginBottom:4},children:((le=y.find(V=>V.sceneCode===c))==null?void 0:le.sceneName)||"场景助手"}),e.jsx(_e,{type:"secondary",children:(G==null?void 0:G.description)||((fe=y.find(V=>V.sceneCode===c))==null?void 0:fe.description)||"开始对话吧!"})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[g.map(V=>e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[e.jsx(t.Avatar,{size:36,icon:V.role==="user"?e.jsx(l.UserOutlined,{}):e.jsx(l.RobotOutlined,{}),style:{background:V.role==="user"?"#1890ff":"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx(_e,{strong:!0,style:{fontSize:13},children:V.role==="user"?"我":"助手"}),e.jsx(_e,{type:"secondary",style:{fontSize:11},children:V.timestamp}),V.role==="assistant"&&e.jsx(t.Tooltip,{title:"复制回复",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>$(V.content),style:{padding:0}})})]}),e.jsx(t.Card,{size:"small",style:{background:V.role==="user"?"#1890ff":"#fff",color:V.role==="user"?"#fff":"#333",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},styles:{body:{padding:"10px 14px"}},children:se(V.content)})]})]},V.id)),T&&M&&e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[e.jsx(t.Avatar,{size:36,icon:e.jsx(l.RobotOutlined,{}),style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsx("div",{style:{flex:1},children:e.jsxs(t.Card,{size:"small",style:{background:"#fff",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},styles:{body:{padding:"10px 14px"}},children:[se(M),e.jsx("span",{style:{display:"inline-block",width:8,height:16,background:"#667eea",marginLeft:2,animation:"blink 1s infinite",borderRadius:2}})]})})]}),x&&!T&&e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"flex-start"},children:[e.jsx(t.Avatar,{size:36,icon:e.jsx(l.RobotOutlined,{}),style:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",flexShrink:0}}),e.jsxs(t.Card,{size:"small",style:{background:"#fff",borderRadius:12,boxShadow:"0 1px 4px rgba(0,0,0,0.08)"},styles:{body:{padding:"10px 14px"}},children:[e.jsx(t.Spin,{indicator:e.jsx(l.LoadingOutlined,{style:{fontSize:16,color:"#667eea"},spin:!0})}),e.jsx(_e,{type:"secondary",style:{marginLeft:8},children:"正在思考..."})]})]})]}),e.jsx("div",{ref:w})]}):e.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(t.Empty,{image:e.jsx("div",{style:{fontSize:48,opacity:.3},children:e.jsx(l.RobotOutlined,{})}),description:e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500,fontSize:15,marginBottom:6},children:"请先选择产品与场景"}),e.jsx("div",{style:{color:"#999",fontSize:13},children:"在顶部选择要执行的场景,即可开始体验"})]}),style:{padding:40}})})}),e.jsxs("div",{style:{background:"#fff",padding:"12px 20px",borderTop:"1px solid #f0f0f0",display:"flex",gap:12,alignItems:"flex-end"},children:[e.jsx(fl,{ref:z,value:N,onChange:V=>D(V.target.value),onKeyDown:d,placeholder:c?"输入消息,Enter 发送,Shift+Enter 换行...":"请先选择场景...",disabled:!c||T,autoSize:{minRows:1,maxRows:4},style:{flex:1,borderRadius:20,resize:"none"}}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:T?e.jsx(t.Tooltip,{title:"停止生成",children:e.jsx(t.Button,{danger:!0,icon:e.jsx(l.CloseCircleOutlined,{}),onClick:_,style:{borderRadius:20}})}):e.jsx(t.Tooltip,{title:"发送",children:e.jsx(t.Button,{type:"primary",icon:e.jsx(l.SendOutlined,{}),onClick:Q,disabled:!c||!N.trim()||x,style:{borderRadius:20,background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",border:"none"}})})})]}),e.jsx(t.Modal,{title:e.jsxs("span",{children:[e.jsx(l.HistoryOutlined,{style:{marginRight:8}}),"对话历史"]}),open:C,onCancel:()=>k(!1),footer:null,width:600,children:E.length===0?e.jsx(t.Empty,{description:"暂无历史记录"}):e.jsx(t.List,{dataSource:E,renderItem:(V,ee)=>{var ce;return e.jsx(t.List.Item,{actions:[e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>R(V),children:"加载"},"load")],children:e.jsx(t.List.Item.Meta,{avatar:e.jsx(t.Avatar,{icon:e.jsx(bl,{}),style:{background:"#667eea"}}),title:`会话 ${ee+1} — ${V.startTime||""}`,description:e.jsxs(_e,{type:"secondary",style:{fontSize:12},children:[((ce=V.messages)==null?void 0:ce.length)||0," 条消息"]})})})}})}),e.jsx(t.Modal,{title:e.jsxs("span",{children:[e.jsx(l.ThunderboltOutlined,{style:{marginRight:8}}),"执行参数配置"]}),open:h,onCancel:()=>B(!1),onOk:()=>{B(!1),t.message.success("参数已保存")},okText:"保存",children:e.jsxs(t.Form,{form:F,layout:"vertical",initialValues:A,children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"temperature",label:"Temperature (随机性)",children:e.jsx(InputNumber,{min:0,max:2,step:.1,style:{width:"100%"}})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"maxTokens",label:"Max Tokens (最大字数)",children:e.jsx(InputNumber,{min:100,max:8192,step:100,style:{width:"100%"}})})})]}),e.jsx(t.Form.Item,{name:"topP",label:"Top P",children:e.jsx(InputNumber,{min:0,max:1,step:.05,style:{width:"100%"}})})]})}),e.jsx("style",{children:`
215
215
  @keyframes blink {
216
216
  0%, 100% { opacity: 1; }
217
217
  50% { opacity: 0; }
218
218
  }
219
- `})]})},yl=()=>e.jsx(l.RobotOutlined,{}),{TextArea:rs}=t.Input,{Option:de}=t.Select,{TabPane:yt}=t.Tabs,jl=()=>{const[o,i]=s.useState("list");return e.jsx(t.Card,{style:{minHeight:"calc(100vh - 140px)"},children:e.jsxs(t.Tabs,{activeKey:o,onChange:i,children:[e.jsx(yt,{tab:e.jsxs("span",{children:[e.jsx(l.NodeIndexOutlined,{})," 场景管理"]}),children:e.jsx(bl,{})},"list"),e.jsx(yt,{tab:e.jsxs("span",{children:[e.jsx(l.SettingOutlined,{})," 节点配置"]}),children:e.jsx(Sl,{})},"nodes"),e.jsx(yt,{tab:e.jsxs("span",{children:[e.jsx(l.ApiOutlined,{})," 场景编排"]}),children:e.jsx(Cl,{})},"canvas")]})})},bl=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(!1),[T,d]=s.useState(""),[b,f]=s.useState(""),[j,w]=s.useState(1),[h]=s.useState(12),[m,z]=s.useState(0),[F,N]=s.useState(!1),[u]=t.Form.useForm(),[v,S]=s.useState(null),[x,D]=s.useState(!1),[G,g]=s.useState(!1),[C,P]=s.useState(null),[K,O]=s.useState([]);s.useEffect(()=>{Se.page({id:1,pageSize:100}).then(r=>{var L;O(((L=r.data)==null?void 0:L.records)||[])})},[]),s.useEffect(()=>{V()},[j,T,b]);const V=async()=>{n(!0);try{const r=await ue.page({sceneName:T,status:b,id:j});r.data&&(i(r.data.records||[]),z(r.data.total||0))}catch(r){t.message.error("加载失败: "+(r.message||""))}n(!1)},U=()=>{S(null),u.resetFields(),u.setFieldsValue({status:"DRAFT",sceneType:"CONVERSATION"}),N(!0)},A=r=>{S(r),u.setFieldsValue({sceneCode:r.sceneCode,sceneName:r.sceneName,description:r.description,productCode:r.productCode,sceneType:r.sceneType||"CONVERSATION",version:r.version||"1.0.0",status:r.status,iconUrl:r.iconUrl}),N(!0)},k=async()=>{try{const r=await u.validateFields();D(!0),v?(await ue.update({id:v.id,...r}),t.message.success("更新成功")):(await ue.create(r),t.message.success("创建成功")),N(!1),V()}catch(r){r.errorFields||t.message.error("操作失败")}finally{D(!1)}},_=async r=>{try{await ue.delete(r),t.message.success("删除成功"),V()}catch{t.message.error("删除失败")}},p=async r=>{try{await ue.publish(r),t.message.success("发布成功"),V()}catch{t.message.error("发布失败")}},y=async r=>{try{await ue.offline(r),t.message.success("下架成功"),V()}catch{t.message.error("下架失败")}},M=r=>{P(r),g(!0)},E=async r=>{try{await ue.duplicate(r.id),t.message.success("复制成功"),V()}catch{t.message.error("复制失败")}},Q=r=>{navigator.clipboard.writeText(r).then(()=>t.message.success("场景编码已复制")).catch(()=>{})},c=[{title:"场景",key:"scene",width:280,render:(r,L)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:8,background:"linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.NodeIndexOutlined,{style:{fontSize:18,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:L.sceneName}),e.jsxs("div",{style:{fontSize:12,color:"#999"},children:[e.jsx("span",{style:{fontFamily:"monospace"},children:L.sceneCode}),e.jsx(t.Tooltip,{title:"复制编码",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>Q(L.sceneCode),style:{marginLeft:4,padding:0}})})]})]})]})},{title:"所属产品",dataIndex:"productCode",width:160,render:r=>r?e.jsx(t.Tag,{color:"blue",children:r}):e.jsx("span",{style:{color:"#ccc"},children:"未关联"})},{title:"类型",dataIndex:"sceneType",width:100,render:r=>{const L={CONVERSATION:"对话",TASK:"任务",WORKFLOW:"工作流"};return e.jsx(t.Tag,{icon:e.jsx(l.NodeIndexOutlined,{}),children:L[r]||r})}},{title:"状态",dataIndex:"status",width:100,render:r=>{const L={PUBLISHED:"success",DRAFT:"warning",OFFLINE:"error",ARCHIVED:"default"},$={PUBLISHED:"已发布",DRAFT:"草稿",OFFLINE:"已下架",ARCHIVED:"已归档"};return e.jsx(t.Badge,{status:L[r]||"default",text:$[r]||r})}},{title:"版本",dataIndex:"version",width:90,render:r=>e.jsxs("span",{style:{fontFamily:"monospace"},children:["v",r||"1.0.0"]})},{title:"描述",dataIndex:"description",ellipsis:!0},{title:"操作",width:340,render:(r,L)=>e.jsxs(t.Space,{size:"small",wrap:!0,children:[e.jsx(t.Tooltip,{title:"查看详情",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>M(L),children:"详情"})}),e.jsx(t.Tooltip,{title:"编辑配置",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>A(L),children:"编辑"})}),e.jsx(t.Tooltip,{title:"复制场景",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>E(L),children:"复制"})}),L.status==="DRAFT"&&e.jsx(t.Tooltip,{title:"发布场景",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.CheckCircleOutlined,{}),onClick:()=>p(L.sceneCode),children:"发布"})}),L.status==="PUBLISHED"&&e.jsx(t.Tooltip,{title:"下架场景",children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.StopOutlined,{}),onClick:()=>y(L.sceneCode),children:"下架"})}),e.jsx(t.Tooltip,{title:"执行场景",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:()=>window.open(`/ai/product/execute?sceneCode=${L.sceneCode}`,"_blank"),children:"执行"})}),e.jsx(t.Popconfirm,{title:"确定删除此场景?",onConfirm:()=>_(L.id),okText:"删除",okButtonProps:{danger:!0},children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:16,gap:12,flexWrap:"wrap"},children:[e.jsxs(t.Space,{children:[e.jsx(t.Input.Search,{placeholder:"搜索场景名称/编码",onSearch:r=>{d(r),w(1)},style:{width:220},allowClear:!0}),e.jsxs(t.Select,{placeholder:"状态筛选",allowClear:!0,style:{width:120},onChange:r=>{f(r),w(1)},children:[e.jsx(de,{value:"DRAFT",children:"草稿"}),e.jsx(de,{value:"PUBLISHED",children:"已发布"}),e.jsx(de,{value:"OFFLINE",children:"已下架"})]}),e.jsxs(t.Select,{placeholder:"类型筛选",allowClear:!0,style:{width:120},onChange:r=>{f(r),w(1)},children:[e.jsx(de,{value:"CONVERSATION",children:"对话"}),e.jsx(de,{value:"TASK",children:"任务"}),e.jsx(de,{value:"WORKFLOW",children:"工作流"})]})]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:U,children:"新建场景"})]}),e.jsx(t.Table,{dataSource:o,columns:c,loading:a,rowKey:"id",pagination:{current:j,pageSize:h,total:m,showSizeChanger:!1,showTotal:r=>`共 ${r} 个场景`,onChange:r=>w(r)},locale:{emptyText:e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"还没有场景,点击新建开始创建"})}}),e.jsx(t.Modal,{title:v?`编辑场景: ${v.sceneName}`:"新建场景",open:F,onOk:k,onCancel:()=>N(!1),width:640,confirmLoading:x,okText:v?"保存":"创建",children:e.jsxs(t.Form,{form:u,layout:"vertical",size:"middle",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"sceneName",label:"场景名称",rules:[{required:!0,message:"请输入场景名称"}],children:e.jsx(t.Input,{placeholder:"如 智能问答助手"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"sceneCode",label:"场景编码",rules:[{required:!0,message:"请输入场景编码"}],children:e.jsx(t.Input,{placeholder:"如 chat_scene",disabled:!!v})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"sceneType",label:"场景类型",initialValue:"CONVERSATION",children:e.jsxs(t.Select,{children:[e.jsx(de,{value:"CONVERSATION",children:"对话场景"}),e.jsx(de,{value:"TASK",children:"任务场景"}),e.jsx(de,{value:"WORKFLOW",children:"工作流场景"})]})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"productCode",label:"所属产品",children:e.jsx(t.Select,{allowClear:!0,placeholder:"选择产品",children:K.map(r=>e.jsx(de,{value:r.productCode,children:r.productName},r.productCode))})})})]}),e.jsx(t.Form.Item,{name:"description",label:"场景描述",children:e.jsx(rs,{rows:2,placeholder:"简短描述这个场景的能力和使用方式"})}),e.jsx(t.Form.Item,{name:"version",label:"版本号",initialValue:"1.0.0",children:e.jsx(t.Input,{placeholder:"1.0.0"})}),!v&&e.jsx(t.Form.Item,{name:"status",label:"创建后状态",initialValue:"DRAFT",children:e.jsxs(t.Select,{children:[e.jsx(de,{value:"DRAFT",children:"草稿"}),e.jsx(de,{value:"PUBLISHED",children:"直接发布"})]})})]})}),e.jsx(t.Drawer,{title:"场景详情",open:G,onClose:()=>g(!1),width:560,children:C&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:10,background:"linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.NodeIndexOutlined,{style:{fontSize:22,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600},children:C.sceneName}),e.jsx("div",{style:{fontSize:12,color:"#999"},children:C.sceneCode})]})]}),e.jsx(t.Divider,{style:{margin:"8px 0"}}),e.jsxs(t.Row,{gutter:16,children:[e.jsxs(t.Col,{span:12,children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"类型"}),e.jsx(t.Tag,{children:C.sceneType==="CONVERSATION"?"对话":C.sceneType==="TASK"?"任务":"工作流"})]}),e.jsxs(t.Col,{span:12,children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"版本"}),e.jsx("span",{style:{fontFamily:"monospace"},children:C.version||"1.0.0"})]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"状态"}),e.jsx(t.Badge,{status:C.status==="PUBLISHED"?"success":C.status==="DRAFT"?"warning":"error",text:C.status==="PUBLISHED"?"已发布":C.status==="DRAFT"?"草稿":C.status==="OFFLINE"?"已下架":"已归档"})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"描述"}),e.jsx("div",{style:{color:"#333",lineHeight:1.6},children:C.description||"暂无描述"})]})]})})]})},Sl=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(null),[T,d]=s.useState([]),[b,f]=s.useState(!1),[j,w]=s.useState(!1),[h]=t.Form.useForm();s.useEffect(()=>{ue.page({id:1,pageSize:100}).then(S=>{var x;i(((x=S.data)==null?void 0:x.records)||[])})},[]),s.useEffect(()=>{a&&m(a.sceneCode)},[a]);const m=async S=>{f(!0);try{const x=await ue.nodes(S);d(x.data||[])}catch{d([])}f(!1)},z=()=>{h.resetFields(),h.setFieldsValue({nodeType:"LLM",isEnabled:!0}),w(!0)},F=async()=>{try{const S=await h.validateFields();d(x=>[...x||[],{...S,id:Date.now()}]),w(!1),t.message.success("节点已添加")}catch{}},N=S=>{d(x=>(x||[]).filter(D=>D.id!==S))},u=S=>{d(x=>x.map(D=>D.id===S?{...D,isEnabled:!D.isEnabled}:D))},v=[{title:"节点名称",dataIndex:"nodeName",key:"nodeName"},{title:"节点类型",dataIndex:"nodeType",key:"nodeType",render:S=>e.jsx(t.Tag,{color:"blue",children:S})},{title:"配置",dataIndex:"config",key:"config",ellipsis:!0},{title:"启用",dataIndex:"isEnabled",key:"isEnabled",render:(S,x)=>e.jsx(t.Switch,{checked:S,onChange:()=>u(x.id)})},{title:"操作",width:100,render:(S,x)=>e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>N(x.id)})}];return e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.NodeIndexOutlined,{style:{color:"#4facfe",marginRight:6}}),"选择场景"]}),style:{width:260,flexShrink:0,borderRadius:10},styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"12px 16px"},body:{padding:8}},children:[(o||[]).map(S=>e.jsxs("div",{onClick:()=>n(S),style:{padding:"10px 12px",borderRadius:8,cursor:"pointer",marginBottom:4,background:(a==null?void 0:a.id)===S.id?"linear-gradient(135deg, #4facfe22, #00f2fe22)":"transparent",border:(a==null?void 0:a.id)===S.id?"1px solid #4facfe44":"1px solid transparent"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:S.sceneName}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:S.sceneCode})]},S.id)),o.length===0&&e.jsx(t.Empty,{description:"暂无场景",style:{padding:20}})]}),e.jsx(t.Card,{title:e.jsxs("span",{style:{fontWeight:600},children:["节点配置 ",a?`- ${a.sceneName}`:""]}),extra:e.jsx(t.Button,{size:"small",icon:e.jsx(l.PlusOutlined,{}),onClick:z,disabled:!a,children:"添加节点"}),style:{flex:1,borderRadius:10},children:a?e.jsx(t.Table,{dataSource:T,columns:v,rowKey:"id",pagination:!1,locale:{emptyText:e.jsx(t.Empty,{description:"暂无节点,点击添加开始配置",image:t.Empty.PRESENTED_IMAGE_SIMPLE})}}):e.jsx(t.Empty,{description:"请先选择场景",style:{padding:60},image:t.Empty.PRESENTED_IMAGE_SIMPLE})}),e.jsx(t.Modal,{title:"添加节点",open:j,onOk:F,onCancel:()=>w(!1),okText:"添加",children:e.jsxs(t.Form,{form:h,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"nodeName",label:"节点名称",rules:[{required:!0,message:"请输入节点名称"}],children:e.jsx(t.Input,{placeholder:"如 LLM调用节点"})}),e.jsx(t.Form.Item,{name:"nodeType",label:"节点类型",initialValue:"LLM",children:e.jsxs(t.Select,{children:[e.jsx(de,{value:"LLM",children:"LLM调用"}),e.jsx(de,{value:"TOOL",children:"工具调用"}),e.jsx(de,{value:"CONDITION",children:"条件分支"}),e.jsx(de,{value:"TRANSFORM",children:"数据转换"}),e.jsx(de,{value:"HTTP",children:"HTTP请求"})]})}),e.jsx(t.Form.Item,{name:"config",label:"节点配置",children:e.jsx(rs,{rows:3,placeholder:'JSON格式配置,如 {"model":"gpt-4"}'})})]})})]})},Cl=()=>{const[o,i]=s.useState([]),[a,n]=s.useState(null),[T,d]=s.useState([]),[b,f]=s.useState([]);s.useEffect(()=>{ue.page({id:1,pageSize:100}).then(h=>{var m;i(((m=h.data)==null?void 0:m.records)||[])})},[]);const j=async h=>{n(h);try{const m=await ue.canvasGet(h.sceneCode);m.data&&(d(m.data.nodes||[]),f(m.data.edges||[]))}catch{d([]),f([])}},w=[{title:"节点",dataIndex:"label",key:"label",width:200},{title:"类型",dataIndex:"type",key:"type",render:h=>e.jsx(t.Tag,{color:"purple",children:h})},{title:"位置",dataIndex:"position",key:"position",render:h=>e.jsxs("span",{style:{fontSize:11,color:"#999"},children:["x:",(h==null?void 0:h.x)||0," y:",(h==null?void 0:h.y)||0]})}];return e.jsxs("div",{style:{display:"flex",gap:16,minHeight:500},children:[e.jsx(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.NodeIndexOutlined,{style:{color:"#4facfe",marginRight:6}}),"场景列表"]}),style:{width:240,flexShrink:0,borderRadius:10},styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"12px 16px"},body:{padding:8}},children:(o||[]).map(h=>e.jsxs("div",{onClick:()=>j(h),style:{padding:"10px 12px",borderRadius:8,cursor:"pointer",marginBottom:4,background:(a==null?void 0:a.id)===h.id?"linear-gradient(135deg, #4facfe22, #00f2fe22)":"transparent",border:(a==null?void 0:a.id)===h.id?"1px solid #4facfe44":"1px solid transparent"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:h.sceneName}),e.jsx(t.Tag,{style:{fontSize:10,marginTop:2},children:h.sceneType})]},h.id))}),e.jsx(t.Card,{title:e.jsxs("span",{style:{fontWeight:600},children:["场景编排画布 ",a?`- ${a.sceneName}`:""]}),style:{flex:1,borderRadius:10},styles:{body:{padding:16,display:"flex",flexDirection:"column",gap:12}},children:a?T.length===0?e.jsx(t.Empty,{description:"暂无节点配置,请先在节点配置中添加节点",style:{padding:40},image:t.Empty.PRESENTED_IMAGE_SIMPLE}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 0",borderBottom:"1px solid #f0f0f0"},children:[e.jsx(l.ThunderboltOutlined,{style:{color:"#4facfe"}}),e.jsxs("span",{style:{fontSize:13,color:"#666"},children:["编排节点 ",T.length," 个,连接 ",b.length," 条"]})]}),e.jsx(t.Table,{dataSource:T,columns:w,rowKey:"id",pagination:!1,size:"small"}),b.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontSize:13,fontWeight:500,marginTop:8},children:"连线"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:b.map((h,m)=>e.jsx(t.Card,{size:"small",style:{background:"#fafafa",border:"none"},children:e.jsxs("span",{style:{fontFamily:"monospace",fontSize:12},children:[h.source," → ",h.target]})},m))})]})]}):e.jsx(t.Empty,{description:"请选择场景进行编排",style:{padding:60},image:t.Empty.PRESENTED_IMAGE_SIMPLE})})]})},{Text:jt}=t.Typography,{TabPane:Qe}=t.Tabs,vl=()=>{const[o,i]=s.useState(null),[a,n]=s.useState([]),[T,d]=s.useState([]),[b,f]=s.useState([]),[j,w]=s.useState([]),[h,m]=s.useState(!1),[z,F]=s.useState(null),[N,u]=s.useState(null),[v,S]=s.useState(null),[x,D]=s.useState([]),[G,g]=s.useState([]),[C,P]=s.useState([]);s.useEffect(()=>{te("/llm-center/provider/list").then(c=>{const r=Array.isArray(c)?c:(c==null?void 0:c.data)||[];D(r)}).catch(()=>{}),K(null),te("/agent/app/page",{method:"POST",body:JSON.stringify({current:1,size:100})}).then(c=>{const r=Array.isArray(c)?c:(c==null?void 0:c.records)||(c==null?void 0:c.data)||[];P(r)}).catch(()=>{})},[]);const K=c=>{te("/llm-center/model/list",{params:{providerCode:c}}).then(r=>{const L=Array.isArray(r)?r:(r==null?void 0:r.data)||[];g(L)}).catch(()=>{})},O=c=>{u(c),S(null),K(c)},V=()=>({appCode:z,providerCode:N,modelCode:v}),U=async()=>{try{const c=await te("/llm-gateway/usage/overview",{method:"GET",params:V()});i((c==null?void 0:c.data)||c||null)}catch(c){console.warn("Usage overview API unavailable:",c==null?void 0:c.message),i(null)}},A=async()=>{try{const c=await te("/llm-gateway/usage/by-app",{method:"GET"});n(Array.isArray(c)?c:(c==null?void 0:c.data)||[])}catch(c){console.warn("Usage by-app API unavailable:",c==null?void 0:c.message),n([])}},k=async()=>{try{const c=await te("/llm-gateway/usage/by-user",{method:"GET",params:V()});d(Array.isArray(c)?c:(c==null?void 0:c.data)||[])}catch(c){console.warn("Usage by-user API unavailable:",c==null?void 0:c.message),d([])}},_=async()=>{try{const c=await te("/llm-gateway/usage/trend",{method:"GET",params:{...V(),days:7}});f(Array.isArray(c)?c:(c==null?void 0:c.data)||[])}catch(c){console.warn("Usage trend API unavailable:",c==null?void 0:c.message),f([])}},p=async()=>{m(!0);try{const c=await te("/llm-gateway/usage/records",{method:"GET",params:{...V(),page:1,size:20}}),r=Array.isArray(c)?c:(c==null?void 0:c.records)||(c==null?void 0:c.data)||[];w(r)}catch(c){console.warn("Usage records API unavailable:",c==null?void 0:c.message),w([])}finally{m(!1)}};s.useEffect(()=>{U(),A(),k(),_(),p()},[z,N,v]);const y={tooltip:{trigger:"axis"},legend:{data:["Token消耗","调用次数"]},xAxis:{type:"category",data:b.map(c=>c.date)},yAxis:[{type:"value",name:"Tokens",position:"left"},{type:"value",name:"调用次数",position:"right"}],series:[{name:"Token消耗",type:"bar",data:b.map(c=>c.dailyTokens)},{name:"调用次数",type:"line",yAxisIndex:1,data:b.map(c=>c.dailyCalls)}]},M=[{title:"应用编码",dataIndex:"appCode"},{title:"调用次数",dataIndex:"totalCalls",render:c=>c==null?void 0:c.toLocaleString()},{title:"输入Token",dataIndex:"inputTokens",render:c=>c==null?void 0:c.toLocaleString()},{title:"输出Token",dataIndex:"outputTokens",render:c=>c==null?void 0:c.toLocaleString()},{title:"总Token",dataIndex:"totalTokens",render:c=>c==null?void 0:c.toLocaleString()},{title:"费用",dataIndex:"totalCost",render:c=>e.jsxs(jt,{style:{color:"#faad14"},children:["¥",(c==null?void 0:c.toFixed(4))||"0"]})}],E=[{title:"用户ID",dataIndex:"userId"},{title:"调用次数",dataIndex:"totalCalls",render:c=>c==null?void 0:c.toLocaleString()},{title:"总Token",dataIndex:"totalTokens",render:c=>c==null?void 0:c.toLocaleString()},{title:"费用",dataIndex:"totalCost",render:c=>e.jsxs(jt,{style:{color:"#faad14"},children:["¥",(c==null?void 0:c.toFixed(4))||"0"]})}],Q=[{title:"时间",dataIndex:"gmtCreate",width:160},{title:"应用",dataIndex:"appCode",render:c=>e.jsx(t.Tag,{color:"blue",children:c||"-"})},{title:"用户",dataIndex:"userName"},{title:"供应商",dataIndex:"providerCode",render:c=>e.jsx(t.Tag,{color:"purple",children:c||"-"})},{title:"模型",dataIndex:"modelCode",render:c=>e.jsx(t.Tag,{children:c||"-"})},{title:"输入Token",dataIndex:"inputTokens",render:c=>c==null?void 0:c.toLocaleString()},{title:"输出Token",dataIndex:"outputTokens",render:c=>c==null?void 0:c.toLocaleString()},{title:"延迟",dataIndex:"latencyMs",render:c=>c?`${c}ms`:"-"},{title:"状态",dataIndex:"status",render:c=>e.jsx(t.Tag,{color:c==="SUCCESS"?"green":"red",children:c||"-"})},{title:"费用",dataIndex:"totalCost",render:c=>e.jsxs(jt,{style:{color:"#faad14"},children:["¥",c||0]})}];return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"center",flexWrap:"wrap",background:"#fff",padding:"12px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)",marginBottom:16},children:[e.jsx("span",{style:{fontWeight:600,color:"#333",marginRight:4},children:"维度筛选:"}),e.jsx(t.Select,{placeholder:"筛选应用",allowClear:!0,style:{width:180},value:z,onChange:F,options:C.map(c=>({value:c.appCode,label:c.appName||c.appCode}))}),e.jsx(t.Select,{placeholder:"筛选供应商",allowClear:!0,style:{width:180},value:N,onChange:O,options:x.map(c=>({value:c.providerCode,label:c.providerName}))}),e.jsx(t.Select,{placeholder:"筛选模型",allowClear:!0,style:{width:180},value:v,onChange:S,options:G.map(c=>({value:c.modelCode,label:c.modelName}))}),(z||N||v)&&e.jsx("a",{onClick:()=>{F(null),u(null),S(null)},style:{fontSize:12},children:"清空筛选"})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"累计 Token"}),value:(o==null?void 0:o.totalTokens)||0,prefix:e.jsx(l.RocketOutlined,{style:{color:"#667eea"}}),formatter:c=>c==null?void 0:c.toLocaleString(),valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"累计费用"}),value:(o==null?void 0:o.totalCost)||0,prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"今日 Token"}),value:(o==null?void 0:o.todayTokens)||0,prefix:e.jsx(l.BarChartOutlined,{style:{color:"#52c41a"}}),formatter:c=>c==null?void 0:c.toLocaleString(),valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"今日费用"}),value:(o==null?void 0:o.todayCost)||0,prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),precision:4,suffix:"元",valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})})]}),e.jsxs(t.Tabs,{defaultActiveKey:"trend",children:[e.jsx(Qe,{tab:"用量趋势",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(Pt,{option:y,style:{height:300}})})},"trend"),e.jsx(Qe,{tab:"按应用统计",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Table,{columns:M,dataSource:a,rowKey:"appCode",pagination:!1,locale:{emptyText:"暂无数据"}})})},"byApp"),e.jsx(Qe,{tab:"按用户统计",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Table,{columns:E,dataSource:T,rowKey:"userId",pagination:!1,locale:{emptyText:"暂无数据"}})})},"byUser"),e.jsx(Qe,{tab:"调用明细",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Table,{columns:Q,dataSource:j,loading:h,rowKey:"id",pagination:{pageSize:20,showSizeChanger:!1},locale:{emptyText:"暂无数据"}})})},"records")]})]})};Z.AgentAppEditor=Mt,Z.AgentAppList=_t,Z.AgentAppPage=_t,Z.AgentSharePage=Ns,Z.AkManage=Gs,Z.AkUsageDrawer=Vt,Z.ApiBridgeEditor=Zt,Z.BucketList=Js,Z.CurlImportModal=Yt,Z.FieldMappingEditor=xt,Z.LlmModel=Vs,Z.LlmProvider=Us,Z.McpPage=Hs,Z.ModelManage=Ms,Z.ObjectBrowser=Qs,Z.OpenApiImportModal=Qt,Z.ProductExecute=fl,Z.ProductList=ul,Z.ProductScene=jl,Z.ScriptCenterPage=il,Z.SkillMarket=pl,Z.UsageDashboard=vl,Z.WorkflowEditor=Nt,Z.agentApi=ae,Z.authRequest=qe,Z.ctcRequest=$e,Z.flowApi=De,Z.llmApi=Ae,Z.mcpApi=Ie,Z.ossApi=me,Z.productApi=Se,Z.request=te,Z.sceneApi=ue,Z.scriptApi=be,Z.skillApi=ge,Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"})}));
219
+ `})]})},bl=()=>e.jsx(l.RobotOutlined,{}),{TextArea:as}=t.Input,{Option:de}=t.Select,{TabPane:jt}=t.Tabs,Sl=()=>{const[i,o]=s.useState("list");return e.jsx(t.Card,{style:{minHeight:"calc(100vh - 140px)"},children:e.jsxs(t.Tabs,{activeKey:i,onChange:o,children:[e.jsx(jt,{tab:e.jsxs("span",{children:[e.jsx(l.NodeIndexOutlined,{})," 场景管理"]}),children:e.jsx(Cl,{})},"list"),e.jsx(jt,{tab:e.jsxs("span",{children:[e.jsx(l.SettingOutlined,{})," 节点配置"]}),children:e.jsx(vl,{})},"nodes"),e.jsx(jt,{tab:e.jsxs("span",{children:[e.jsx(l.ApiOutlined,{})," 场景编排"]}),children:e.jsx(Tl,{})},"canvas")]})})},Cl=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState(""),[m,b]=s.useState(""),[S,y]=s.useState(1),[p]=s.useState(12),[g,P]=s.useState(0),[N,D]=s.useState(!1),[x]=t.Form.useForm(),[v,T]=s.useState(null),[f,M]=s.useState(!1),[K,C]=s.useState(!1),[k,E]=s.useState(null),[W,h]=s.useState([]);s.useEffect(()=>{Se.page({id:1,pageSize:100}).then(n=>{var _;h(((_=n.data)==null?void 0:_.records)||[])})},[]),s.useEffect(()=>{B()},[S,j,m]);const B=async()=>{r(!0);try{const n=await ue.page({sceneName:j,status:m,id:S});n.data&&(o(n.data.records||[]),P(n.data.total||0))}catch(n){t.message.error("加载失败: "+(n.message||""))}r(!1)},F=()=>{T(null),x.resetFields(),x.setFieldsValue({status:"DRAFT",sceneType:"CONVERSATION"}),D(!0)},A=n=>{T(n),x.setFieldsValue({sceneCode:n.sceneCode,sceneName:n.sceneName,description:n.description,productCode:n.productCode,sceneType:n.sceneType||"CONVERSATION",version:n.version||"1.0.0",status:n.status,iconUrl:n.iconUrl}),D(!0)},I=async()=>{try{const n=await x.validateFields();M(!0),v?(await ue.update({id:v.id,...n}),t.message.success("更新成功")):(await ue.create(n),t.message.success("创建成功")),D(!1),B()}catch(n){n.errorFields||t.message.error("操作失败")}finally{M(!1)}},G=async n=>{try{await ue.delete(n),t.message.success("删除成功"),B()}catch{t.message.error("删除失败")}},u=async n=>{try{await ue.publish(n),t.message.success("发布成功"),B()}catch{t.message.error("发布失败")}},w=async n=>{try{await ue.offline(n),t.message.success("下架成功"),B()}catch{t.message.error("下架失败")}},U=n=>{E(n),C(!0)},z=async n=>{try{await ue.duplicate(n.id),t.message.success("复制成功"),B()}catch{t.message.error("复制失败")}},Q=n=>{navigator.clipboard.writeText(n).then(()=>t.message.success("场景编码已复制")).catch(()=>{})},d=[{title:"场景",key:"scene",width:280,render:(n,_)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:8,background:"linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.NodeIndexOutlined,{style:{fontSize:18,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:500},children:_.sceneName}),e.jsxs("div",{style:{fontSize:12,color:"#999"},children:[e.jsx("span",{style:{fontFamily:"monospace"},children:_.sceneCode}),e.jsx(t.Tooltip,{title:"复制编码",children:e.jsx(t.Button,{size:"small",type:"text",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>Q(_.sceneCode),style:{marginLeft:4,padding:0}})})]})]})]})},{title:"所属产品",dataIndex:"productCode",width:160,render:n=>n?e.jsx(t.Tag,{color:"blue",children:n}):e.jsx("span",{style:{color:"#ccc"},children:"未关联"})},{title:"类型",dataIndex:"sceneType",width:100,render:n=>{const _={CONVERSATION:"对话",TASK:"任务",WORKFLOW:"工作流"};return e.jsx(t.Tag,{icon:e.jsx(l.NodeIndexOutlined,{}),children:_[n]||n})}},{title:"状态",dataIndex:"status",width:100,render:n=>{const _={PUBLISHED:"success",DRAFT:"warning",OFFLINE:"error",ARCHIVED:"default"},$={PUBLISHED:"已发布",DRAFT:"草稿",OFFLINE:"已下架",ARCHIVED:"已归档"};return e.jsx(t.Badge,{status:_[n]||"default",text:$[n]||n})}},{title:"版本",dataIndex:"version",width:90,render:n=>e.jsxs("span",{style:{fontFamily:"monospace"},children:["v",n||"1.0.0"]})},{title:"描述",dataIndex:"description",ellipsis:!0},{title:"操作",width:340,render:(n,_)=>e.jsxs(t.Space,{size:"small",wrap:!0,children:[e.jsx(t.Tooltip,{title:"查看详情",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EyeOutlined,{}),onClick:()=>U(_),children:"详情"})}),e.jsx(t.Tooltip,{title:"编辑配置",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.EditOutlined,{}),onClick:()=>A(_),children:"编辑"})}),e.jsx(t.Tooltip,{title:"复制场景",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.CopyOutlined,{}),onClick:()=>z(_),children:"复制"})}),_.status==="DRAFT"&&e.jsx(t.Tooltip,{title:"发布场景",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.CheckCircleOutlined,{}),onClick:()=>u(_.sceneCode),children:"发布"})}),_.status==="PUBLISHED"&&e.jsx(t.Tooltip,{title:"下架场景",children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.StopOutlined,{}),onClick:()=>w(_.sceneCode),children:"下架"})}),e.jsx(t.Tooltip,{title:"执行场景",children:e.jsx(t.Button,{size:"small",type:"primary",icon:e.jsx(l.PlayCircleOutlined,{}),onClick:()=>window.open(`/ai/product/execute?sceneCode=${_.sceneCode}`,"_blank"),children:"执行"})}),e.jsx(t.Popconfirm,{title:"确定删除此场景?",onConfirm:()=>G(_.id),okText:"删除",okButtonProps:{danger:!0},children:e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{})})})]})}];return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:16,gap:12,flexWrap:"wrap"},children:[e.jsxs(t.Space,{children:[e.jsx(t.Input.Search,{placeholder:"搜索场景名称/编码",onSearch:n=>{c(n),y(1)},style:{width:220},allowClear:!0}),e.jsxs(t.Select,{placeholder:"状态筛选",allowClear:!0,style:{width:120},onChange:n=>{b(n),y(1)},children:[e.jsx(de,{value:"DRAFT",children:"草稿"}),e.jsx(de,{value:"PUBLISHED",children:"已发布"}),e.jsx(de,{value:"OFFLINE",children:"已下架"})]}),e.jsxs(t.Select,{placeholder:"类型筛选",allowClear:!0,style:{width:120},onChange:n=>{b(n),y(1)},children:[e.jsx(de,{value:"CONVERSATION",children:"对话"}),e.jsx(de,{value:"TASK",children:"任务"}),e.jsx(de,{value:"WORKFLOW",children:"工作流"})]})]}),e.jsx(t.Button,{type:"primary",icon:e.jsx(l.PlusOutlined,{}),onClick:F,children:"新建场景"})]}),e.jsx(t.Table,{dataSource:i,columns:d,loading:a,rowKey:"id",pagination:{current:S,pageSize:p,total:g,showSizeChanger:!1,showTotal:n=>`共 ${n} 个场景`,onChange:n=>y(n)},locale:{emptyText:e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"还没有场景,点击新建开始创建"})}}),e.jsx(t.Modal,{title:v?`编辑场景: ${v.sceneName}`:"新建场景",open:N,onOk:I,onCancel:()=>D(!1),width:640,confirmLoading:f,okText:v?"保存":"创建",children:e.jsxs(t.Form,{form:x,layout:"vertical",size:"middle",children:[e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"sceneName",label:"场景名称",rules:[{required:!0,message:"请输入场景名称"}],children:e.jsx(t.Input,{placeholder:"如 智能问答助手"})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"sceneCode",label:"场景编码",rules:[{required:!0,message:"请输入场景编码"}],children:e.jsx(t.Input,{placeholder:"如 chat_scene",disabled:!!v})})})]}),e.jsxs(t.Row,{gutter:16,children:[e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"sceneType",label:"场景类型",initialValue:"CONVERSATION",children:e.jsxs(t.Select,{children:[e.jsx(de,{value:"CONVERSATION",children:"对话场景"}),e.jsx(de,{value:"TASK",children:"任务场景"}),e.jsx(de,{value:"WORKFLOW",children:"工作流场景"})]})})}),e.jsx(t.Col,{span:12,children:e.jsx(t.Form.Item,{name:"productCode",label:"所属产品",children:e.jsx(t.Select,{allowClear:!0,placeholder:"选择产品",children:W.map(n=>e.jsx(de,{value:n.productCode,children:n.productName},n.productCode))})})})]}),e.jsx(t.Form.Item,{name:"description",label:"场景描述",children:e.jsx(as,{rows:2,placeholder:"简短描述这个场景的能力和使用方式"})}),e.jsx(t.Form.Item,{name:"version",label:"版本号",initialValue:"1.0.0",children:e.jsx(t.Input,{placeholder:"1.0.0"})}),!v&&e.jsx(t.Form.Item,{name:"status",label:"创建后状态",initialValue:"DRAFT",children:e.jsxs(t.Select,{children:[e.jsx(de,{value:"DRAFT",children:"草稿"}),e.jsx(de,{value:"PUBLISHED",children:"直接发布"})]})})]})}),e.jsx(t.Drawer,{title:"场景详情",open:K,onClose:()=>C(!1),width:560,children:k&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("div",{style:{width:48,height:48,borderRadius:10,background:"linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(l.NodeIndexOutlined,{style:{fontSize:22,color:"#fff"}})}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:16,fontWeight:600},children:k.sceneName}),e.jsx("div",{style:{fontSize:12,color:"#999"},children:k.sceneCode})]})]}),e.jsx(t.Divider,{style:{margin:"8px 0"}}),e.jsxs(t.Row,{gutter:16,children:[e.jsxs(t.Col,{span:12,children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"类型"}),e.jsx(t.Tag,{children:k.sceneType==="CONVERSATION"?"对话":k.sceneType==="TASK"?"任务":"工作流"})]}),e.jsxs(t.Col,{span:12,children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"版本"}),e.jsx("span",{style:{fontFamily:"monospace"},children:k.version||"1.0.0"})]})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"状态"}),e.jsx(t.Badge,{status:k.status==="PUBLISHED"?"success":k.status==="DRAFT"?"warning":"error",text:k.status==="PUBLISHED"?"已发布":k.status==="DRAFT"?"草稿":k.status==="OFFLINE"?"已下架":"已归档"})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#999",marginBottom:4},children:"描述"}),e.jsx("div",{style:{color:"#333",lineHeight:1.6},children:k.description||"暂无描述"})]})]})})]})},vl=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(null),[j,c]=s.useState([]),[m,b]=s.useState(!1),[S,y]=s.useState(!1),[p]=t.Form.useForm();s.useEffect(()=>{ue.page({id:1,pageSize:100}).then(T=>{var f;o(((f=T.data)==null?void 0:f.records)||[])})},[]),s.useEffect(()=>{a&&g(a.sceneCode)},[a]);const g=async T=>{b(!0);try{const f=await ue.nodes(T);c(f.data||[])}catch{c([])}b(!1)},P=()=>{p.resetFields(),p.setFieldsValue({nodeType:"LLM",isEnabled:!0}),y(!0)},N=async()=>{try{const T=await p.validateFields();c(f=>[...f||[],{...T,id:Date.now()}]),y(!1),t.message.success("节点已添加")}catch{}},D=T=>{c(f=>(f||[]).filter(M=>M.id!==T))},x=T=>{c(f=>f.map(M=>M.id===T?{...M,isEnabled:!M.isEnabled}:M))},v=[{title:"节点名称",dataIndex:"nodeName",key:"nodeName"},{title:"节点类型",dataIndex:"nodeType",key:"nodeType",render:T=>e.jsx(t.Tag,{color:"blue",children:T})},{title:"配置",dataIndex:"config",key:"config",ellipsis:!0},{title:"启用",dataIndex:"isEnabled",key:"isEnabled",render:(T,f)=>e.jsx(t.Switch,{checked:T,onChange:()=>x(f.id)})},{title:"操作",width:100,render:(T,f)=>e.jsx(t.Button,{size:"small",danger:!0,icon:e.jsx(l.DeleteOutlined,{}),onClick:()=>D(f.id)})}];return e.jsxs("div",{style:{display:"flex",gap:16},children:[e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.NodeIndexOutlined,{style:{color:"#4facfe",marginRight:6}}),"选择场景"]}),style:{width:260,flexShrink:0,borderRadius:10},styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"12px 16px"},body:{padding:8}},children:[(i||[]).map(T=>e.jsxs("div",{onClick:()=>r(T),style:{padding:"10px 12px",borderRadius:8,cursor:"pointer",marginBottom:4,background:(a==null?void 0:a.id)===T.id?"linear-gradient(135deg, #4facfe22, #00f2fe22)":"transparent",border:(a==null?void 0:a.id)===T.id?"1px solid #4facfe44":"1px solid transparent"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:T.sceneName}),e.jsx("div",{style:{fontSize:11,color:"#999"},children:T.sceneCode})]},T.id)),i.length===0&&e.jsx(t.Empty,{description:"暂无场景",style:{padding:20}})]}),e.jsx(t.Card,{title:e.jsxs("span",{style:{fontWeight:600},children:["节点配置 ",a?`- ${a.sceneName}`:""]}),extra:e.jsx(t.Button,{size:"small",icon:e.jsx(l.PlusOutlined,{}),onClick:P,disabled:!a,children:"添加节点"}),style:{flex:1,borderRadius:10},children:a?e.jsx(t.Table,{dataSource:j,columns:v,rowKey:"id",pagination:!1,locale:{emptyText:e.jsx(t.Empty,{description:"暂无节点,点击添加开始配置",image:t.Empty.PRESENTED_IMAGE_SIMPLE})}}):e.jsx(t.Empty,{description:"请先选择场景",style:{padding:60},image:t.Empty.PRESENTED_IMAGE_SIMPLE})}),e.jsx(t.Modal,{title:"添加节点",open:S,onOk:N,onCancel:()=>y(!1),okText:"添加",children:e.jsxs(t.Form,{form:p,layout:"vertical",children:[e.jsx(t.Form.Item,{name:"nodeName",label:"节点名称",rules:[{required:!0,message:"请输入节点名称"}],children:e.jsx(t.Input,{placeholder:"如 LLM调用节点"})}),e.jsx(t.Form.Item,{name:"nodeType",label:"节点类型",initialValue:"LLM",children:e.jsxs(t.Select,{children:[e.jsx(de,{value:"LLM",children:"LLM调用"}),e.jsx(de,{value:"TOOL",children:"工具调用"}),e.jsx(de,{value:"CONDITION",children:"条件分支"}),e.jsx(de,{value:"TRANSFORM",children:"数据转换"}),e.jsx(de,{value:"HTTP",children:"HTTP请求"})]})}),e.jsx(t.Form.Item,{name:"config",label:"节点配置",children:e.jsx(as,{rows:3,placeholder:'JSON格式配置,如 {"model":"gpt-4"}'})})]})})]})},Tl=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(null),[j,c]=s.useState([]),[m,b]=s.useState([]);s.useEffect(()=>{ue.page({id:1,pageSize:100}).then(p=>{var g;o(((g=p.data)==null?void 0:g.records)||[])})},[]);const S=async p=>{r(p);try{const g=await ue.canvasGet(p.sceneCode);g.data&&(c(g.data.nodes||[]),b(g.data.edges||[]))}catch{c([]),b([])}},y=[{title:"节点",dataIndex:"label",key:"label",width:200},{title:"类型",dataIndex:"type",key:"type",render:p=>e.jsx(t.Tag,{color:"purple",children:p})},{title:"位置",dataIndex:"position",key:"position",render:p=>e.jsxs("span",{style:{fontSize:11,color:"#999"},children:["x:",(p==null?void 0:p.x)||0," y:",(p==null?void 0:p.y)||0]})}];return e.jsxs("div",{style:{display:"flex",gap:16,minHeight:500},children:[e.jsx(t.Card,{size:"small",title:e.jsxs("span",{style:{fontWeight:600},children:[e.jsx(l.NodeIndexOutlined,{style:{color:"#4facfe",marginRight:6}}),"场景列表"]}),style:{width:240,flexShrink:0,borderRadius:10},styles:{header:{borderBottom:"1px solid #f0f0f0",padding:"12px 16px"},body:{padding:8}},children:(i||[]).map(p=>e.jsxs("div",{onClick:()=>S(p),style:{padding:"10px 12px",borderRadius:8,cursor:"pointer",marginBottom:4,background:(a==null?void 0:a.id)===p.id?"linear-gradient(135deg, #4facfe22, #00f2fe22)":"transparent",border:(a==null?void 0:a.id)===p.id?"1px solid #4facfe44":"1px solid transparent"},children:[e.jsx("div",{style:{fontSize:13,fontWeight:500},children:p.sceneName}),e.jsx(t.Tag,{style:{fontSize:10,marginTop:2},children:p.sceneType})]},p.id))}),e.jsx(t.Card,{title:e.jsxs("span",{style:{fontWeight:600},children:["场景编排画布 ",a?`- ${a.sceneName}`:""]}),style:{flex:1,borderRadius:10},styles:{body:{padding:16,display:"flex",flexDirection:"column",gap:12}},children:a?j.length===0?e.jsx(t.Empty,{description:"暂无节点配置,请先在节点配置中添加节点",style:{padding:40},image:t.Empty.PRESENTED_IMAGE_SIMPLE}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 0",borderBottom:"1px solid #f0f0f0"},children:[e.jsx(l.ThunderboltOutlined,{style:{color:"#4facfe"}}),e.jsxs("span",{style:{fontSize:13,color:"#666"},children:["编排节点 ",j.length," 个,连接 ",m.length," 条"]})]}),e.jsx(t.Table,{dataSource:j,columns:y,rowKey:"id",pagination:!1,size:"small"}),m.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontSize:13,fontWeight:500,marginTop:8},children:"连线"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4},children:m.map((p,g)=>e.jsx(t.Card,{size:"small",style:{background:"#fafafa",border:"none"},children:e.jsxs("span",{style:{fontFamily:"monospace",fontSize:12},children:[p.source," → ",p.target]})},g))})]})]}):e.jsx(t.Empty,{description:"请选择场景进行编排",style:{padding:60},image:t.Empty.PRESENTED_IMAGE_SIMPLE})})]})},{Text:bt}=t.Typography,{TabPane:Qe}=t.Tabs,wl=()=>{const[i,o]=s.useState(null),[a,r]=s.useState([]),[j,c]=s.useState([]),[m,b]=s.useState([]),[S,y]=s.useState([]),[p,g]=s.useState(!1),[P,N]=s.useState(null),[D,x]=s.useState(null),[v,T]=s.useState(null),[f,M]=s.useState([]),[K,C]=s.useState([]),[k,E]=s.useState([]);s.useEffect(()=>{te("/llm-center/provider/list").then(d=>{const n=Array.isArray(d)?d:(d==null?void 0:d.data)||[];M(n)}).catch(()=>{}),W(null),te("/agent/app/page",{method:"POST",body:JSON.stringify({current:1,size:100})}).then(d=>{const n=Array.isArray(d)?d:(d==null?void 0:d.records)||(d==null?void 0:d.data)||[];E(n)}).catch(()=>{})},[]);const W=d=>{te("/llm-center/model/list",{params:{providerCode:d}}).then(n=>{const _=Array.isArray(n)?n:(n==null?void 0:n.data)||[];C(_)}).catch(()=>{})},h=d=>{x(d),T(null),W(d)},B=()=>({appCode:P,providerCode:D,modelCode:v}),F=async()=>{try{const d=await te("/llm-gateway/usage/overview",{method:"GET",params:B()});o((d==null?void 0:d.data)||d||null)}catch(d){console.warn("Usage overview API unavailable:",d==null?void 0:d.message),o(null)}},A=async()=>{try{const d=await te("/llm-gateway/usage/by-app",{method:"GET"});r(Array.isArray(d)?d:(d==null?void 0:d.data)||[])}catch(d){console.warn("Usage by-app API unavailable:",d==null?void 0:d.message),r([])}},I=async()=>{try{const d=await te("/llm-gateway/usage/by-user",{method:"GET",params:B()});c(Array.isArray(d)?d:(d==null?void 0:d.data)||[])}catch(d){console.warn("Usage by-user API unavailable:",d==null?void 0:d.message),c([])}},G=async()=>{try{const d=await te("/llm-gateway/usage/trend",{method:"GET",params:{...B(),days:7}});b(Array.isArray(d)?d:(d==null?void 0:d.data)||[])}catch(d){console.warn("Usage trend API unavailable:",d==null?void 0:d.message),b([])}},u=async()=>{g(!0);try{const d=await te("/llm-gateway/usage/records",{method:"GET",params:{...B(),page:1,size:20}}),n=Array.isArray(d)?d:(d==null?void 0:d.records)||(d==null?void 0:d.data)||[];y(n)}catch(d){console.warn("Usage records API unavailable:",d==null?void 0:d.message),y([])}finally{g(!1)}};s.useEffect(()=>{F(),A(),I(),G(),u()},[P,D,v]);const w={tooltip:{trigger:"axis"},legend:{data:["Token消耗","调用次数"]},xAxis:{type:"category",data:m.map(d=>d.date)},yAxis:[{type:"value",name:"Tokens",position:"left"},{type:"value",name:"调用次数",position:"right"}],series:[{name:"Token消耗",type:"bar",data:m.map(d=>d.dailyTokens)},{name:"调用次数",type:"line",yAxisIndex:1,data:m.map(d=>d.dailyCalls)}]},U=[{title:"应用编码",dataIndex:"appCode"},{title:"调用次数",dataIndex:"totalCalls",render:d=>d==null?void 0:d.toLocaleString()},{title:"输入Token",dataIndex:"inputTokens",render:d=>d==null?void 0:d.toLocaleString()},{title:"输出Token",dataIndex:"outputTokens",render:d=>d==null?void 0:d.toLocaleString()},{title:"总Token",dataIndex:"totalTokens",render:d=>d==null?void 0:d.toLocaleString()},{title:"费用",dataIndex:"totalCost",render:d=>e.jsxs(bt,{style:{color:"#faad14"},children:["¥",(d==null?void 0:d.toFixed(4))||"0"]})}],z=[{title:"用户ID",dataIndex:"userId"},{title:"调用次数",dataIndex:"totalCalls",render:d=>d==null?void 0:d.toLocaleString()},{title:"总Token",dataIndex:"totalTokens",render:d=>d==null?void 0:d.toLocaleString()},{title:"费用",dataIndex:"totalCost",render:d=>e.jsxs(bt,{style:{color:"#faad14"},children:["¥",(d==null?void 0:d.toFixed(4))||"0"]})}],Q=[{title:"时间",dataIndex:"gmtCreate",width:160},{title:"应用",dataIndex:"appCode",render:d=>e.jsx(t.Tag,{color:"blue",children:d||"-"})},{title:"用户",dataIndex:"userName"},{title:"供应商",dataIndex:"providerCode",render:d=>e.jsx(t.Tag,{color:"purple",children:d||"-"})},{title:"模型",dataIndex:"modelCode",render:d=>e.jsx(t.Tag,{children:d||"-"})},{title:"输入Token",dataIndex:"inputTokens",render:d=>d==null?void 0:d.toLocaleString()},{title:"输出Token",dataIndex:"outputTokens",render:d=>d==null?void 0:d.toLocaleString()},{title:"延迟",dataIndex:"latencyMs",render:d=>d?`${d}ms`:"-"},{title:"状态",dataIndex:"status",render:d=>e.jsx(t.Tag,{color:d==="SUCCESS"?"green":"red",children:d||"-"})},{title:"费用",dataIndex:"totalCost",render:d=>e.jsxs(bt,{style:{color:"#faad14"},children:["¥",d||0]})}];return e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",gap:12,alignItems:"center",flexWrap:"wrap",background:"#fff",padding:"12px 16px",borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)",marginBottom:16},children:[e.jsx("span",{style:{fontWeight:600,color:"#333",marginRight:4},children:"维度筛选:"}),e.jsx(t.Select,{placeholder:"筛选应用",allowClear:!0,style:{width:180},value:P,onChange:N,options:k.map(d=>({value:d.appCode,label:d.appName||d.appCode}))}),e.jsx(t.Select,{placeholder:"筛选供应商",allowClear:!0,style:{width:180},value:D,onChange:h,options:f.map(d=>({value:d.providerCode,label:d.providerName}))}),e.jsx(t.Select,{placeholder:"筛选模型",allowClear:!0,style:{width:180},value:v,onChange:T,options:K.map(d=>({value:d.modelCode,label:d.modelName}))}),(P||D||v)&&e.jsx("a",{onClick:()=>{N(null),x(null),T(null)},style:{fontSize:12},children:"清空筛选"})]}),e.jsxs(t.Row,{gutter:16,style:{marginBottom:16},children:[e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"累计 Token"}),value:(i==null?void 0:i.totalTokens)||0,prefix:e.jsx(l.RocketOutlined,{style:{color:"#667eea"}}),formatter:d=>d==null?void 0:d.toLocaleString(),valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"累计费用"}),value:(i==null?void 0:i.totalCost)||0,prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"今日 Token"}),value:(i==null?void 0:i.todayTokens)||0,prefix:e.jsx(l.BarChartOutlined,{style:{color:"#52c41a"}}),formatter:d=>d==null?void 0:d.toLocaleString(),valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})}),e.jsx(t.Col,{span:6,children:e.jsx(t.Card,{size:"small",style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Statistic,{title:e.jsx("span",{style:{color:"#666",fontSize:13},children:"今日费用"}),value:(i==null?void 0:i.todayCost)||0,prefix:e.jsx(l.DollarOutlined,{style:{color:"#faad14"}}),precision:4,suffix:"元",valueStyle:{color:"#333",fontSize:22,fontWeight:700}})})})]}),e.jsxs(t.Tabs,{defaultActiveKey:"trend",children:[e.jsx(Qe,{tab:"用量趋势",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(Pt,{option:w,style:{height:300}})})},"trend"),e.jsx(Qe,{tab:"按应用统计",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Table,{columns:U,dataSource:a,rowKey:"appCode",pagination:!1,locale:{emptyText:"暂无数据"}})})},"byApp"),e.jsx(Qe,{tab:"按用户统计",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Table,{columns:z,dataSource:j,rowKey:"userId",pagination:!1,locale:{emptyText:"暂无数据"}})})},"byUser"),e.jsx(Qe,{tab:"调用明细",children:e.jsx(t.Card,{style:{borderRadius:10,boxShadow:"0 1px 4px rgba(0,0,0,0.06)"},children:e.jsx(t.Table,{columns:Q,dataSource:S,loading:p,rowKey:"id",pagination:{pageSize:20,showSizeChanger:!1},locale:{emptyText:"暂无数据"}})})},"records")]})]})},kl=({trace:i,spans:o=[]})=>{if(!i)return e.jsx(t.Empty,{description:"请选择左侧 trace",image:t.Empty.PRESENTED_IMAGE_SIMPLE});const a=o.reduce((p,g)=>(p[g.spanType]=(p[g.spanType]||0)+1,p),{}),r=o.length,j=a.llm_call||0,c=a.tool_call||0,m=a.retrieve||0,b=a.think||0,S=o.filter(p=>p.status==="FAILURE"||p.status==="ERROR").length,y={SUCCESS:"success",FAILURE:"error",RUNNING:"processing",ERROR:"error"}[i.status]||"default";return e.jsxs("div",{children:[e.jsxs(t.Row,{gutter:[12,12],children:[e.jsx(t.Col,{xs:24,sm:12,md:4,children:e.jsx(t.Card,{size:"small",hoverable:!0,children:e.jsx(t.Statistic,{title:e.jsxs("span",{children:[e.jsx(l.RocketOutlined,{})," 状态"]}),value:i.status,valueStyle:{color:y==="success"?"#3f8600":y==="error"?"#cf1322":"#1677ff",fontSize:16}})})}),e.jsx(t.Col,{xs:24,sm:12,md:4,children:e.jsx(t.Card,{size:"small",hoverable:!0,children:e.jsx(t.Statistic,{title:e.jsxs("span",{children:[e.jsx(l.ClockCircleOutlined,{})," 总耗时"]}),value:i.durationMs||0,suffix:"ms",valueStyle:{color:"#1677ff"}})})}),e.jsx(t.Col,{xs:24,sm:12,md:4,children:e.jsx(t.Card,{size:"small",hoverable:!0,children:e.jsx(t.Statistic,{title:e.jsxs("span",{children:[e.jsx(l.CommentOutlined,{})," Span 总数"]}),value:r,suffix:"个"})})}),e.jsx(t.Col,{xs:24,sm:12,md:4,children:e.jsx(t.Card,{size:"small",hoverable:!0,children:e.jsx(t.Statistic,{title:"失败 Span",value:S,suffix:"个",valueStyle:{color:S>0?"#cf1322":"#3f8600"}})})}),e.jsx(t.Col,{xs:24,sm:12,md:8,children:e.jsxs(t.Card,{size:"small",hoverable:!0,children:[e.jsx(t.Statistic,{title:e.jsxs("span",{children:[e.jsx(l.CommentOutlined,{})," 用户目标 / Agent"]}),value:i.userGoal||"(空)",valueStyle:{fontSize:13,lineHeight:1.4}}),e.jsxs("div",{style:{marginTop:6,fontSize:11,color:"#666"},children:["agent: ",e.jsx(t.Tag,{children:i.agentName||"—"}),"app: ",e.jsx(t.Tag,{children:i.appCode||"—"}),"session: ",e.jsx(t.Tag,{children:i.sessionId||"—"})]})]})})]}),e.jsxs(t.Row,{gutter:[12,12],style:{marginTop:12},children:[e.jsx(t.Col,{xs:24,sm:8,children:e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{children:[e.jsx(l.ThunderboltOutlined,{})," LLM 调用"]}),children:[e.jsx(t.Statistic,{value:j,suffix:"次",valueStyle:{color:"#1677ff"}}),e.jsx(t.Progress,{percent:r?Math.round(j*100/r):0,strokeColor:"#1677ff",size:"small",showInfo:!1,style:{marginTop:6}})]})}),e.jsx(t.Col,{xs:24,sm:8,children:e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{children:[e.jsx(l.CodeOutlined,{})," 工具调用"]}),children:[e.jsx(t.Statistic,{value:c,suffix:"次",valueStyle:{color:"#fa8c16"}}),e.jsx(t.Progress,{percent:r?Math.round(c*100/r):0,strokeColor:"#fa8c16",size:"small",showInfo:!1,style:{marginTop:6}})]})}),e.jsx(t.Col,{xs:24,sm:8,children:e.jsxs(t.Card,{size:"small",title:e.jsxs("span",{children:[e.jsx(l.FileSearchOutlined,{})," RAG 检索"]}),children:[e.jsx(t.Statistic,{value:m,suffix:"次",valueStyle:{color:"#52c41a"}}),e.jsx(t.Progress,{percent:r?Math.round(m*100/r):0,strokeColor:"#52c41a",size:"small",showInfo:!1,style:{marginTop:6}})]})})]}),e.jsx(t.Card,{size:"small",title:"Trace 元信息",style:{marginTop:12},children:e.jsxs(t.Row,{gutter:[8,4],children:[e.jsxs(t.Col,{span:12,children:[e.jsx("span",{style:{color:"#666"},children:"trace_id:"})," ",e.jsx("code",{children:i.traceId})]}),e.jsxs(t.Col,{span:12,children:[e.jsx("span",{style:{color:"#666"},children:"DB ID:"})," ",i.id]}),e.jsxs(t.Col,{span:12,children:[e.jsx("span",{style:{color:"#666"},children:"开始:"})," ",i.startedAt]}),e.jsxs(t.Col,{span:12,children:[e.jsx("span",{style:{color:"#666"},children:"结束:"})," ",i.endedAt||"(进行中)"]}),e.jsxs(t.Col,{span:24,children:[e.jsx("span",{style:{color:"#666"},children:"LLM 调用 / Tool 调用 / RAG / Think:"})," ",e.jsx(t.Tag,{color:"blue",children:j}),e.jsx(t.Tag,{color:"orange",children:c}),e.jsx(t.Tag,{color:"green",children:m}),e.jsx(t.Tag,{color:"gold",children:b})]})]})})]})},Il={think:{color:"gold",icon:e.jsx(l.BulbOutlined,{}),label:"思考"},llm_call:{color:"blue",icon:e.jsx(l.ThunderboltOutlined,{}),label:"LLM"},tool_call:{color:"orange",icon:e.jsx(l.CodeOutlined,{}),label:"工具"},retrieve:{color:"green",icon:e.jsx(l.FileSearchOutlined,{}),label:"RAG"},observe:{color:"purple",icon:e.jsx(l.MailOutlined,{}),label:"观察"},step:{color:"default",icon:e.jsx(l.PlayCircleOutlined,{}),label:"步骤"},flow_node:{color:"cyan",icon:e.jsx(l.PlayCircleOutlined,{}),label:"Flow节点"}},cs={RUNNING:{color:"processing",icon:e.jsx(l.PlayCircleOutlined,{})},SUCCESS:{color:"success",icon:e.jsx(l.PlayCircleOutlined,{})},FAILURE:{color:"error",icon:e.jsx(l.StopOutlined,{})},ERROR:{color:"error",icon:e.jsx(l.StopOutlined,{})},PENDING:{color:"default",icon:null}},Ol=({spans:i=[]})=>i.length?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:i.map((o,a)=>{const r=Il[o.spanType]||{color:"default",icon:null,label:o.spanType},j=cs[o.status]||cs.PENDING;let c=null;if(o.attributes)try{c=typeof o.attributes=="string"?JSON.parse(o.attributes):o.attributes}catch{}const m=o.status==="FAILURE"||o.status==="ERROR";return e.jsxs("div",{style:{border:"1px solid #f0f0f0",borderLeft:`3px solid ${m?"#ff4d4f":"#1677ff"}`,borderRadius:6,padding:"10px 12px",background:"#fafafa"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[e.jsx("span",{style:{width:22,height:22,borderRadius:11,background:"#1677ff",color:"#fff",display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:11,fontWeight:600},children:a+1}),e.jsx(t.Tag,{color:r.color,icon:r.icon,children:r.label}),e.jsx(t.Tag,{color:j.color,icon:j.icon,children:o.status}),e.jsx("span",{style:{fontSize:12,color:"#666"},children:o.name}),e.jsx("div",{style:{flex:1}}),e.jsx(t.Tooltip,{title:"耗时",children:e.jsx(t.Tag,{children:o.durationMs!=null?`${o.durationMs}ms`:"—"})}),e.jsxs("span",{style:{fontSize:11,color:"#999"},children:["#",o.sequence]})]}),o.content&&e.jsx("div",{style:{fontSize:12,color:"#333",background:"#fff",padding:"6px 8px",borderRadius:4,border:"1px dashed #e8e8e8",marginBottom:c?6:0,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:120,overflow:"auto"},children:Al(o.content,500)}),c&&Object.keys(c).length>0&&e.jsxs("details",{style:{fontSize:11,color:"#888"},children:[e.jsxs("summary",{style:{cursor:"pointer",userSelect:"none"},children:["查看 attributes (",Object.keys(c).length,")"]}),e.jsx("pre",{style:{background:"#fff",padding:6,marginTop:4,borderRadius:4,maxHeight:150,overflow:"auto"},children:JSON.stringify(c,null,2)})]}),o.errorMessage&&e.jsxs("div",{style:{marginTop:6,fontSize:12,color:"#ff4d4f"},children:["❌ ",o.errorMessage]})]},o.spanId||a)})}):e.jsx(t.Empty,{description:"暂无 span 数据",image:t.Empty.PRESENTED_IMAGE_SIMPLE});function Al(i,o){return i&&(i.length>o?i.substring(0,o)+"…":i)}const El=({spans:i=[]})=>{const o=i.filter(c=>c.spanType==="tool_call"||c.spanType==="llm_call");if(!o.length)return e.jsx(t.Empty,{description:"本次执行没有工具/LLM 调用",image:t.Empty.PRESENTED_IMAGE_SIMPLE});const a=new Map(o.map(c=>[c.spanId,c])),r=o.filter(c=>!c.parentSpanId||!a.has(c.parentSpanId)),j=(c,m)=>{let b=null,S=null;try{const p=c.attributes?typeof c.attributes=="string"?JSON.parse(c.attributes):c.attributes:null;p&&(b=p.arguments||p.argumentsJson||p.tool_input,S=p.tool_result||p.result||p.output)}catch{}const y=o.filter(p=>p.parentSpanId===c.spanId);return e.jsxs("div",{style:{marginLeft:m*20,marginBottom:8,borderLeft:m>0?"2px solid #d9d9d9":"none",paddingLeft:m>0?12:0},children:[e.jsxs("div",{style:{background:"#fff",border:"1px solid #e8e8e8",borderRadius:6,padding:"8px 12px",borderLeft:`3px solid ${c.spanType==="tool_call"?"#fa8c16":"#1677ff"}`},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsx(l.BranchesOutlined,{}),e.jsx(t.Tag,{color:c.spanType==="tool_call"?"orange":"blue",children:c.spanType==="tool_call"?"Tool":"LLM"}),e.jsx("span",{style:{fontWeight:600},children:c.name}),e.jsx(t.Tag,{color:c.status==="SUCCESS"?"success":c.status==="FAILURE"?"error":"default",children:c.status}),e.jsx("div",{style:{flex:1}}),e.jsx("span",{style:{fontSize:11,color:"#999"},children:c.durationMs!=null?`${c.durationMs}ms`:""})]}),b&&e.jsxs("details",{children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:12,color:"#666"},children:"📥 入参"}),e.jsx("pre",{style:{background:"#fafafa",padding:6,marginTop:4,borderRadius:4,fontSize:11,maxHeight:100,overflow:"auto"},children:typeof b=="string"?b:JSON.stringify(b,null,2)})]}),S&&e.jsxs("details",{children:[e.jsx("summary",{style:{cursor:"pointer",fontSize:12,color:"#666"},children:"📤 结果"}),e.jsx("pre",{style:{background:"#f6ffed",padding:6,marginTop:4,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto"},children:typeof S=="string"?S:JSON.stringify(S,null,2)})]}),c.errorMessage&&e.jsxs("div",{style:{fontSize:12,color:"#ff4d4f",marginTop:4},children:["❌ ",c.errorMessage]})]}),y.length>0&&e.jsx("div",{style:{marginTop:6},children:y.map(p=>j(p,m+1))})]},c.spanId)};return e.jsx("div",{children:r.map(c=>j(c,0))})},Pl=({spans:i=[]})=>{const o=i.filter(j=>j.spanType==="retrieve");if(!o.length)return e.jsx(t.Empty,{description:"本次执行没有 RAG 检索",image:t.Empty.PRESENTED_IMAGE_SIMPLE});let a=0,r=-1;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[o.map((j,c)=>{let m=[],b="VECTOR",S=null;try{const y=j.attributes?typeof j.attributes=="string"?JSON.parse(j.attributes):j.attributes:null;y&&(m=y.chunks||y.results||[],b=y.retrieval_type||y.retrievalType||"VECTOR",S=y.knowledge_base_code||y.knowledgeBaseCode)}catch{}return Array.isArray(m)||(m=[]),a+=m.length,m.forEach(y=>{const p=parseFloat(y.score);!isNaN(p)&&p>r&&(r=p)}),e.jsxs("div",{style:{border:"1px solid #b7eb8f",borderRadius:6,background:"#f6ffed",padding:"10px 12px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:8},children:[e.jsx(l.FileTextOutlined,{style:{color:"#52c41a"}}),e.jsx(t.Tag,{color:"green",children:b}),S&&e.jsxs(t.Tag,{color:"blue",children:["知识库: ",S]}),e.jsxs(t.Tag,{children:[m.length," 个分块"]}),e.jsx("div",{style:{flex:1}}),e.jsxs("span",{style:{fontSize:11,color:"#999"},children:["耗时 ",j.durationMs!=null?`${j.durationMs}ms`:"—"]})]}),m.length>0?e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:m.map((y,p)=>{const g=parseFloat(y.score)||0,P=g>=.8?"green":g>=.5?"orange":"red";return e.jsxs("div",{style:{background:"#fff",padding:"8px 10px",borderRadius:4,border:"1px solid #d9f7be"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:4},children:[e.jsxs(t.Tag,{color:"cyan",children:["#",p+1]}),y.document_code&&e.jsxs("span",{style:{fontSize:11,color:"#666"},children:["doc: ",y.document_code]}),y.chunk_index!=null&&e.jsxs("span",{style:{fontSize:11,color:"#999"},children:["chunk #",y.chunk_index]}),e.jsx("div",{style:{flex:1}}),e.jsx(t.Tooltip,{title:"相似度分数",children:e.jsxs(t.Tag,{color:P,children:[(g*100).toFixed(1),"%"]})})]}),e.jsx("div",{style:{fontSize:12,color:"#333",lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:100,overflow:"auto"},children:zl(y.chunk_content||y.content||"(空)",300)})]},p)})}):e.jsx("div",{style:{fontSize:12,color:"#999",padding:"6px 8px"},children:"无召回结果"})]},j.spanId||c)}),e.jsxs("div",{style:{fontSize:11,color:"#666",textAlign:"right"},children:["汇总: ",o.length," 次检索 / ",a," 个分块 / top score ",r>=0?r.toFixed(3):"—"]})]})};function zl(i,o){return i.length>o?i.substring(0,o)+"…":i}const{Sider:Rl,Content:Nl}=t.Layout,{Text:to,Title:Bl}=t.Typography,Fl=()=>{const[i,o]=s.useState([]),[a,r]=s.useState(!1),[j,c]=s.useState("ALL"),[m,b]=s.useState(""),[S,y]=s.useState(null),[p,g]=s.useState(null),[P,N]=s.useState(!1),[D,x]=s.useState("timeline"),[v,T]=s.useState(null),f=s.useCallback(async()=>{r(!0);try{const h=await tt.list({pageNum:1,pageSize:50}),B=(h==null?void 0:h.data)||(h==null?void 0:h.records)||h||[];o(Array.isArray(B)?B:[])}catch(h){t.message.error("加载 trace 列表失败: "+((h==null?void 0:h.message)||"未知错误"))}finally{r(!1)}},[]),M=s.useCallback(async()=>{try{const h=await tt.health();T((h==null?void 0:h.data)||h)}catch{T(null)}},[]);s.useEffect(()=>{f(),M()},[f,M]);const K=s.useMemo(()=>{let h=i;if(j!=="ALL"&&(h=h.filter(B=>B.status===j)),m.trim()){const B=m.trim().toLowerCase();h=h.filter(F=>F.traceId&&F.traceId.toLowerCase().includes(B)||F.agentName&&F.agentName.toLowerCase().includes(B)||F.userGoal&&F.userGoal.toLowerCase().includes(B)||F.appCode&&F.appCode.toLowerCase().includes(B))}return h},[i,j,m]),C=s.useCallback(async h=>{N(!0);try{const B=await tt.get(h),F=(B==null?void 0:B.data)||B;F&&F.trace?(g(F),y(h)):(t.message.warning("未找到 trace: "+h),g(null))}catch(B){t.message.error("加载 trace 详情失败: "+((B==null?void 0:B.message)||"未知错误")),g(null)}finally{N(!1)}},[]);s.useEffect(()=>{i.length&&!S&&C(i[0].traceId)},[i,S,C]);const k=h=>{const B=S===h.traceId,F={SUCCESS:"success",FAILURE:"error",RUNNING:"processing",ERROR:"error"}[h.status]||"default";return e.jsx(t.List.Item,{style:{padding:"10px 12px",cursor:"pointer",background:B?"#e6f4ff":"transparent",borderLeft:B?"3px solid #1677ff":"3px solid transparent"},onClick:()=>C(h.traceId),children:e.jsxs("div",{style:{width:"100%"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,marginBottom:4},children:[e.jsx(t.Badge,{status:F}),e.jsx(t.Tag,{color:F==="success"?"green":F==="error"?"red":"blue",children:h.status}),e.jsx(t.Tooltip,{title:"DB ID",children:e.jsxs("span",{style:{fontSize:11,color:"#999"},children:["#",h.id]})}),e.jsx("div",{style:{flex:1}}),e.jsx("span",{style:{fontSize:11,color:"#999"},children:h.durationMs!=null?`${h.durationMs}ms`:"—"})]}),e.jsx("div",{style:{fontSize:12,color:"#333",fontWeight:500,marginBottom:4},title:h.userGoal,children:Ll(h.userGoal,60)}),e.jsxs("div",{style:{fontSize:10,color:"#999",display:"flex",gap:6},children:[e.jsx(t.Tag,{color:"cyan",style:{margin:0},children:h.agentName||"—"}),e.jsx("span",{children:h.startedAt?new Date(h.startedAt).toLocaleTimeString():"—"})]})]})},h.traceId)},E=p==null?void 0:p.trace,W=(p==null?void 0:p.spans)||[];return e.jsxs(t.Layout,{style:{height:"calc(100vh - 64px)",background:"#f5f5f5"},children:[e.jsxs(Rl,{width:340,theme:"light",style:{borderRight:"1px solid #e8e8e8",overflow:"auto"},children:[v&&e.jsx("div",{style:{padding:"8px 12px",background:v.trace_mapper_ready?"#f6ffed":"#fff7e6",borderBottom:"1px solid #e8e8e8",fontSize:11},children:e.jsxs(t.Space,{size:4,children:[e.jsx(t.Badge,{status:v.trace_mapper_ready?"success":"warning"}),e.jsxs("span",{children:["trace 模块: ",v.trace_mapper_ready?"就绪":"未启动",v.total_traces!=null&&` · 共 ${v.total_traces} 条`]})]})}),e.jsxs("div",{style:{padding:"10px 12px",borderBottom:"1px solid #e8e8e8"},children:[e.jsxs(Bl,{level:5,style:{margin:"0 0 8px 0"},children:[e.jsx(l.HistoryOutlined,{})," Trace 列表"]}),e.jsxs(t.Space.Compact,{style:{width:"100%",marginBottom:8},children:[e.jsx(t.Input,{prefix:e.jsx(l.SearchOutlined,{}),placeholder:"搜索 trace_id / agent / goal",value:m,onChange:h=>b(h.target.value),allowClear:!0}),e.jsx(t.Button,{icon:e.jsx(l.ReloadOutlined,{}),onClick:f})]}),e.jsx(t.Segmented,{block:!0,size:"small",value:j,onChange:c,options:[{label:"全部",value:"ALL"},{label:"成功",value:"SUCCESS"},{label:"失败",value:"FAILURE"},{label:"运行中",value:"RUNNING"}]})]}),e.jsx(t.Spin,{spinning:a,children:K.length>0?e.jsx(t.List,{size:"small",dataSource:K,renderItem:k,split:!1,locale:{emptyText:e.jsx(t.Empty,{description:"无匹配 trace",image:t.Empty.PRESENTED_IMAGE_SIMPLE})}}):!a&&e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:(v==null?void 0:v.trace_mapper_ready)===!1?"trace 表未启用":"暂无 trace",style:{padding:"40px 0"}})})]}),e.jsx(Nl,{style:{padding:"16px",overflow:"auto"},children:e.jsx(t.Spin,{spinning:P,children:E?e.jsxs(t.Space,{direction:"vertical",size:"middle",style:{width:"100%"},children:[e.jsx(t.Card,{title:e.jsxs("span",{children:[e.jsx(l.DashboardOutlined,{})," 调试仪表盘"]}),size:"small",extra:e.jsxs(t.Space,{children:[e.jsx(t.Tooltip,{title:"刷新",children:e.jsx(t.Button,{size:"small",icon:e.jsx(l.ReloadOutlined,{}),onClick:()=>C(E.traceId)})}),e.jsx(t.Tag,{color:"blue",children:E.traceId})]}),children:e.jsx(kl,{trace:E,spans:W})}),e.jsx(t.Card,{size:"small",styles:{body:{paddingTop:4}},children:e.jsx(t.Tabs,{activeKey:D,onChange:x,items:[{key:"timeline",label:e.jsxs("span",{children:[e.jsx(l.HistoryOutlined,{})," 时间线 (",W.length,")"]}),children:e.jsx(Ol,{spans:W})},{key:"tools",label:e.jsxs("span",{children:[e.jsx(l.CodeOutlined,{})," 工具/LLM 树 (",W.filter(h=>h.spanType==="tool_call"||h.spanType==="llm_call").length,")"]}),children:e.jsx(El,{spans:W})},{key:"rag",label:e.jsxs("span",{children:[e.jsx(l.FileSearchOutlined,{})," RAG 片段 (",W.filter(h=>h.spanType==="retrieve").length,")"]}),children:e.jsx(Pl,{spans:W})}]})})]}):e.jsx(t.Empty,{image:t.Empty.PRESENTED_IMAGE_SIMPLE,description:"选择左侧 trace 查看详情",style:{paddingTop:100}})})})]})};function Ll(i,o){return i&&(i.length>o?i.substring(0,o)+"…":i)}const Dl=()=>e.jsx(Be.Outlet,{});Z.AgentAppEditor=_t,Z.AgentAppList=Ut,Z.AgentAppPage=Ut,Z.AgentSharePage=Ds,Z.AkManage=Js,Z.AkUsageDrawer=Vt,Z.ApiBridgeEditor=Xt,Z.BucketList=Qs,Z.CurlImportModal=Qt,Z.DebugPlayground=Fl,Z.FieldMappingEditor=ht,Z.LlmModel=Ks,Z.LlmProvider=Ws,Z.McpPage=Ys,Z.ModelManage=Us,Z.ObjectBrowser=Xs,Z.OpenApiImportModal=Zt,Z.ProductExecute=jl,Z.ProductList=hl,Z.ProductScene=Sl,Z.ScriptCenterPage=nl,Z.SkillMarket=xl,Z.TraceApp=Dl,Z.UsageDashboard=wl,Z.WorkflowEditor=Lt,Z.agentApi=ae,Z.authRequest=qe,Z.ctcRequest=$e,Z.flowApi=De,Z.llmApi=Ae,Z.mcpApi=Ie,Z.ossApi=me,Z.productApi=Se,Z.request=te,Z.sceneApi=ue,Z.scriptApi=be,Z.skillApi=ge,Object.defineProperty(Z,Symbol.toStringTag,{value:"Module"})}));