plugin-agent-orchestrator 1.0.5 → 1.0.13
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.
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +6 -6
- package/dist/server/collections/orchestrator-config.js +10 -0
- package/dist/server/collections/orchestrator-logs.js +19 -2
- package/dist/server/migrations/20260427000000-add-tracing-detail-fields.d.ts +7 -0
- package/dist/server/migrations/20260427000000-add-tracing-detail-fields.js +62 -0
- package/dist/server/migrations/20260429000000-add-llm-fields.d.ts +7 -0
- package/dist/server/migrations/20260429000000-add-llm-fields.js +60 -0
- package/dist/server/resources/tracing.js +8 -3
- package/dist/server/tools/delegate-task.js +314 -100
- package/package.json +1 -1
- package/src/client/RulesTab.tsx +134 -8
- package/src/client/TracingTab.tsx +171 -21
- package/src/server/collections/orchestrator-config.ts +10 -0
- package/src/server/collections/orchestrator-logs.ts +19 -2
- package/src/server/migrations/20260427000000-add-tracing-detail-fields.ts +41 -0
- package/src/server/migrations/20260429000000-add-llm-fields.ts +37 -0
- package/src/server/resources/tracing.ts +6 -2
- package/src/server/tools/delegate-task.ts +379 -109
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):"function"==typeof define&&define.amd?define("plugin-agent-orchestrator",["react","@nocobase/client","@ant-design/icons","antd"],t):"object"==typeof exports?exports["plugin-agent-orchestrator"]=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):e["plugin-agent-orchestrator"]=t(e.react,e["@nocobase/client"],e["@ant-design/icons"],e.antd)}(self,function(e,t,r,n){return function(){"use strict";var a={482:function(e){e.exports=r},772:function(e){e.exports=t},721:function(e){e.exports=n},156:function(t){t.exports=e}},o={};function l(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return a[e](r,r.exports,l),r.exports}l.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(t,{a:t}),t},l.d=function(e,t){for(var r in t)l.o(t,r)&&!l.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},l.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return!function(){l.r(i),l.d(i,{default:function(){return T}});var e=l(772),t=l(156),r=l.n(t),n=l(721),a=l(482),o=(0,t.createContext)({employees:[],employeeMap:new Map,loading:!1}),u=function(t){var n=t.children,a=(0,e.useRequest)({url:"aiEmployees:list",params:{pageSize:200}}),l=a.data,i=a.loading,u=r().useMemo(function(){var e=((null==l?void 0:l.data)||[]).map(function(e){var t;return{username:e.username,nickname:e.nickname||e.username,about:null==(t=e.about)?void 0:t.substring(0,80)}}),t=new Map,r=!0,n=!1,a=void 0;try{for(var o,u=e[Symbol.iterator]();!(r=(o=u.next()).done);r=!0){var c=o.value;t.set(c.username,c.nickname)}}catch(e){n=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(n)throw a}}return{employees:e,employeeMap:t,loading:i}},[l,i]);return r().createElement(o.Provider,{value:u},n)},c=function(){return(0,t.useContext)(o)},s=function(e){var t=e.value,a=e.onChange,o=e.exclude,l=e.placeholder,i=c(),u=i.employees,s=i.loading,d=r().useMemo(function(){return u.filter(function(e){return!o||e.username!==o}).map(function(e){return{label:e.nickname,value:e.username,description:e.about}})},[u,o]);return r().createElement(n.Select,{loading:s,options:d,value:t,onChange:a,placeholder:void 0===l?"Select AI Employee...":l,showSearch:!0,filterOption:function(e,t){var r,n;return(null!=(r=null==t?void 0:t.label)?r:"").toString().toLowerCase().includes(e.toLowerCase())||(null!=(n=null==t?void 0:t.value)?n:"").toString().toLowerCase().includes(e.toLowerCase())},optionRender:function(e){return r().createElement("div",null,r().createElement("div",{style:{fontWeight:500}},e.label),e.data.description&&r().createElement("div",{style:{fontSize:12,color:"#888"}},e.data.description))}})};function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t,r,n,a,o,l){try{var i=e[o](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function f(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var o=e.apply(t,r);function l(e){m(o,n,a,l,i,"next",e)}function i(e){m(o,n,a,l,i,"throw",e)}l(void 0)})}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var o=[],l=!0,i=!1;try{for(a=a.call(e);!(l=(r=a.next()).done)&&(o.push(r.value),!t||o.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==a.return||a.return()}finally{if(i)throw n}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return d(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e,t){var r,n,a,o,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){var u=[o,i];if(r)throw TypeError("Generator is already executing.");for(;l;)try{if(r=1,n&&(a=2&u[0]?n.return:u[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;switch(n=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,n=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){l.label=u[1];break}if(6===u[0]&&l.label<a[1]){l.label=a[1],a=u;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(u);break}a[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],n=0}finally{r=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var h=n.Typography.Text,g=function(){var o,l,i=(0,e.useAPIClient)(),u=p((0,t.useState)(!1),2),d=u[0],m=u[1],g=p((0,t.useState)(null),2),b=g[0],v=g[1],E=p(n.Form.useForm(),1)[0],w=(0,e.useRequest)({url:"orchestratorConfig:list",params:{sort:["-createdAt"]}}),S=w.data,x=w.loading,k=w.refresh,A=c().employeeMap,C=function(e){v(e),e?E.setFieldsValue(e):(E.resetFields(),E.setFieldsValue({enabled:!0,maxDepth:1,timeout:12e4})),m(!0)},O=function(){m(!1),v(null)},I=(o=f(function(e){var t,r,a,o,l,u;return y(this,function(c){switch(c.label){case 0:if(e.leaderUsername===e.subAgentUsername)return n.message.error("Leader and Sub-Agent cannot be the same employee."),[2];c.label=1;case 1:if(c.trys.push([1,6,,7]),!b)return[3,3];return[4,i.request({url:"orchestratorConfig:update",method:"put",params:{filterByTk:b.id},data:e})];case 2:return c.sent(),n.message.success("Rule updated"),[3,5];case 3:return[4,i.request({url:"orchestratorConfig:create",method:"post",data:e})];case 4:c.sent(),n.message.success("Rule created"),c.label=5;case 5:return O(),k(),[3,7];case 6:return u=(null==(t=c.sent())||null==(l=t.response)||null==(o=l.data)||null==(a=o.errors)||null==(r=a[0])?void 0:r.message)||t.message,n.message.error("Save failed: ".concat(u)),[3,7];case 7:return[2]}})}),function(e){return o.apply(this,arguments)}),T=(l=f(function(e){var t;return y(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,i.request({url:"orchestratorConfig:destroy",method:"delete",params:{filterByTk:e}})];case 1:return r.sent(),n.message.success("Rule deleted"),k(),[3,3];case 2:return t=r.sent(),n.message.error("Delete failed: ".concat(t.message)),[3,3];case 3:return[2]}})}),function(e){return l.apply(this,arguments)}),D=[{title:"Leader (Orchestrator)",dataIndex:"leaderUsername",key:"leaderUsername",render:function(e){return r().createElement(n.Tag,{color:"blue"},A.get(e)||e)}},{title:"",key:"arrow",width:50,render:function(){return r().createElement(a.SwapRightOutlined,{style:{color:"#999",fontSize:18}})}},{title:"Sub-Agent",dataIndex:"subAgentUsername",key:"subAgentUsername",render:function(e){return r().createElement(n.Tag,{color:"green"},A.get(e)||e)}},{title:"Max Depth",dataIndex:"maxDepth",key:"maxDepth",width:100,render:function(e){return null!=e?e:1}},{title:"Timeout",dataIndex:"timeout",key:"timeout",width:100,render:function(e){return"".concat(((null!=e?e:12e4)/1e3).toFixed(0),"s")}},{title:"Enabled",dataIndex:"enabled",key:"enabled",width:80,render:function(e,t){var a;return r().createElement(n.Switch,{checked:e,size:"small",onChange:(a=f(function(e){return y(this,function(r){switch(r.label){case 0:return[4,i.request({url:"orchestratorConfig:update",method:"put",params:{filterByTk:t.id},data:{enabled:e}})];case 1:return r.sent(),k(),[2]}})}),function(e){return a.apply(this,arguments)})})}},{title:"Actions",key:"actions",width:160,render:function(e,t){return r().createElement(n.Space,null,r().createElement(n.Button,{type:"link",size:"small",icon:r().createElement(a.EditOutlined,null),onClick:function(){return C(t)}},"Edit"),r().createElement(n.Popconfirm,{title:"Delete this rule?",onConfirm:function(){return T(t.id)}},r().createElement(n.Button,{type:"link",size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)},"Delete")))}}],M=n.Form.useWatch("leaderUsername",E);return r().createElement("div",null,r().createElement(n.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"Orchestration Rules",description:r().createElement(h,{type:"secondary"},"Configure which AI Employees can act as Leaders (Orchestrators) and which ones they can delegate tasks to. Each rule creates a callable tool for the Leader to invoke the Sub-Agent.")}),r().createElement(n.Card,{bordered:!1},r().createElement("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-end"}},r().createElement(n.Button,{type:"primary",icon:r().createElement(a.PlusOutlined,null),onClick:function(){return C()}},"New Rule")),r().createElement(n.Table,{rowKey:"id",loading:x,dataSource:(null==S?void 0:S.data)||[],columns:D,pagination:{hideOnSinglePage:!0,pageSize:20},size:"middle"})),r().createElement(n.Drawer,{title:b?"Edit Orchestration Rule":"New Orchestration Rule",width:480,onClose:O,open:d,styles:{body:{paddingBottom:80}},extra:r().createElement(n.Space,null,r().createElement(n.Button,{onClick:O},"Cancel"),r().createElement(n.Button,{onClick:function(){return E.submit()},type:"primary"},"Save"))},r().createElement(n.Form,{form:E,layout:"vertical",onFinish:I},r().createElement(n.Form.Item,{name:"leaderUsername",label:"Leader (Orchestrator)",rules:[{required:!0,message:"Please select a Leader"}],tooltip:"The AI Employee that will be able to delegate tasks to the Sub-Agent"},r().createElement(s,{placeholder:"Select Leader AI Employee..."})),r().createElement(n.Form.Item,{name:"subAgentUsername",label:"Sub-Agent",rules:[{required:!0,message:"Please select a Sub-Agent"}],tooltip:"The AI Employee that will receive delegated tasks"},r().createElement(s,{placeholder:"Select Sub-Agent AI Employee...",exclude:M})),r().createElement(n.Form.Item,{name:"maxDepth",label:"Max Delegation Depth",tooltip:"How many layers of delegation are allowed (1 = leader calls sub-agent, sub-agent cannot delegate further)"},r().createElement(n.InputNumber,{min:1,max:3,style:{width:"100%"}})),r().createElement(n.Form.Item,{name:"timeout",label:"Timeout (ms)",tooltip:"Maximum time in milliseconds for the sub-agent to complete its task"},r().createElement(n.InputNumber,{min:1e4,max:6e5,step:1e4,style:{width:"100%"}})),r().createElement(n.Form.Item,{name:"enabled",label:"Enabled",valuePropName:"checked"},r().createElement(n.Switch,null)))))};function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var v=n.Typography.Text,E=n.Typography.Paragraph,w=function(){var o,l,i=(o=(0,t.useState)(null),function(e){if(Array.isArray(e))return e}(o)||function(e,t){var r,n,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var o=[],l=!0,i=!1;try{for(a=a.call(e);!(l=(r=a.next()).done)&&(o.push(r.value),o.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==a.return||a.return()}finally{if(i)throw n}}return o}}(o,2)||function(e,t){if(e){if("string"==typeof e)return b(e,2);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return b(e,t)}}(o,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),u=i[0],s=i[1],d=(0,e.useRequest)({url:"orchestratorTracing:list",params:{sort:["-createdAt"],pageSize:50}}),m=d.data,f=d.loading,p=d.refresh,y=c().employeeMap,h=[{title:"Time",dataIndex:"createdAt",key:"createdAt",width:170,render:function(e){return e?new Date(e).toLocaleString():"-"}},{title:"Sub-Agent",dataIndex:"subAgentUsername",key:"subAgentUsername",render:function(e){return r().createElement(n.Tag,{color:"green"},y.get(e)||e)}},{title:"Task",dataIndex:"task",key:"task",render:function(e){return r().createElement(v,{ellipsis:!0,style:{maxWidth:280}},(null==e?void 0:e.substring(0,100))||"-")}},{title:"Status",dataIndex:"status",key:"status",width:90,render:function(e){return r().createElement(n.Tag,{icon:"success"===e?r().createElement(a.CheckCircleOutlined,null):r().createElement(a.CloseCircleOutlined,null),color:"success"===e?"success":"error"},e)}},{title:"Duration",dataIndex:"durationMs",key:"durationMs",width:90,render:function(e){return e?e>=1e3?"".concat((e/1e3).toFixed(1),"s"):"".concat(e,"ms"):"-"}},{title:"Depth",dataIndex:"depth",key:"depth",width:60,render:function(e){return null!=e?e:0}},{title:"",key:"actions",width:80,render:function(e,t){return r().createElement(n.Button,{type:"link",size:"small",icon:r().createElement(a.EyeOutlined,null),onClick:function(){return s(t)}},"Detail")}}];return r().createElement("div",null,r().createElement(n.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"Swarm Tracing",description:r().createElement(v,{type:"secondary"},"View delegation execution logs. Each row represents one sub-agent invocation triggered by a Leader's tool call.")}),r().createElement(n.Card,{bordered:!1},r().createElement("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-end"}},r().createElement(n.Button,{onClick:p},"Refresh")),r().createElement(n.Table,{rowKey:"id",loading:f,dataSource:Array.isArray(null==m?void 0:m.data)?m.data:Array.isArray(m)?m:[],columns:h,pagination:{hideOnSinglePage:!0,pageSize:20},size:"middle",locale:{emptyText:r().createElement(n.Empty,{description:"No delegation executions yet"})}})),r().createElement(n.Drawer,{title:"Delegation Detail",width:640,onClose:function(){return s(null)},open:!!u},u&&r().createElement(r().Fragment,null,r().createElement(n.Descriptions,{column:1,bordered:!0,size:"small",style:{marginBottom:16}},r().createElement(n.Descriptions.Item,{label:"Status"},r().createElement(n.Tag,{icon:"success"===u.status?r().createElement(a.CheckCircleOutlined,null):r().createElement(a.CloseCircleOutlined,null),color:"success"===u.status?"success":"error"},u.status)),r().createElement(n.Descriptions.Item,{label:"Sub-Agent"},r().createElement(n.Tag,{color:"green"},y.get(u.subAgentUsername)||u.subAgentUsername)),r().createElement(n.Descriptions.Item,{label:"Tool"},r().createElement(v,{code:!0},u.toolName)),r().createElement(n.Descriptions.Item,{label:"Depth"},null!=(l=u.depth)?l:0),r().createElement(n.Descriptions.Item,{label:"Duration"},u.durationMs?u.durationMs>=1e3?"".concat((u.durationMs/1e3).toFixed(1),"s"):"".concat(u.durationMs,"ms"):"-"),r().createElement(n.Descriptions.Item,{label:"Time"},u.createdAt?new Date(u.createdAt).toLocaleString():"-")),r().createElement(n.Card,{title:"Task",size:"small",style:{marginBottom:16}},r().createElement(E,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:13}},u.task||"No task description")),r().createElement(n.Card,{title:"Result",size:"small",style:{marginBottom:16,borderColor:"success"===u.status?"#b7eb8f":"#ffa39e"}},r().createElement(E,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:13},ellipsis:{rows:20,expandable:!0}},u.result||u.error||"No result")),u.error&&r().createElement(n.Card,{title:"Error",size:"small",style:{borderColor:"#ffa39e"}},r().createElement(E,{type:"danger",style:{whiteSpace:"pre-wrap",margin:0,fontSize:13}},u.error)))))},S=function(){return r().createElement(u,null,r().createElement("div",{style:{padding:"0 24px 24px"}},r().createElement(n.Tabs,{defaultActiveKey:"rules",items:[{key:"rules",label:r().createElement("span",null,r().createElement(a.ApartmentOutlined,null)," Orchestration Rules"),children:r().createElement(g,null)},{key:"tracing",label:r().createElement("span",null,r().createElement(a.MonitorOutlined,null)," Swarm Tracing"),children:r().createElement(w,null)}]})))};function x(e,t,r,n,a,o,l){try{var i=e[o](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function k(e,t,r){return(k=I()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&C(a,r.prototype),a}).apply(null,arguments)}function A(e){return(A=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function C(e,t){return(C=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function O(e){var t="function"==typeof Map?new Map:void 0;return(O=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return k(e,arguments,A(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),C(r,e)})(e)}function I(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(I=function(){return!!e})()}var T=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=A(e),function(e,t){var r;if(t&&("object"==((r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,I()?Reflect.construct(e,t||[],A(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&C(r,e),t=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var r,n,a,o,l={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function i(o){return function(i){var u=[o,i];if(r)throw TypeError("Generator is already executing.");for(;l;)try{if(r=1,n&&(a=2&u[0]?n.return:u[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;switch(n=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return l.label++,{value:u[1],done:!1};case 5:l.label++,n=u[1],u=[0];continue;case 7:u=l.ops.pop(),l.trys.pop();continue;default:if(!(a=(a=l.trys).length>0&&a[a.length-1])&&(6===u[0]||2===u[0])){l=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){l.label=u[1];break}if(6===u[0]&&l.label<a[1]){l.label=a[1],a=u;break}if(a&&l.label<a[2]){l.label=a[2],l.ops.push(u);break}a[2]&&l.ops.pop(),l.trys.pop();continue}u=t.call(e,l)}catch(e){u=[6,e],n=0}finally{r=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(e){return t.app.pluginSettingsManager.add("ai.orchestrator",{title:"Agent Orchestrator",icon:"ApartmentOutlined",Component:S}),[2]})},function(){var t=this,r=arguments;return new Promise(function(n,a){var o=e.apply(t,r);function l(e){x(o,n,a,l,i,"next",e)}function i(e){x(o,n,a,l,i,"throw",e)}l(void 0)})})()}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(r.prototype,t),r}(O(e.Plugin))}(),i}()});
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):"function"==typeof define&&define.amd?define("plugin-agent-orchestrator",["react","@nocobase/client","@ant-design/icons","antd"],t):"object"==typeof exports?exports["plugin-agent-orchestrator"]=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):e["plugin-agent-orchestrator"]=t(e.react,e["@nocobase/client"],e["@ant-design/icons"],e.antd)}(self,function(e,t,r,n){return function(){"use strict";var a={482:function(e){e.exports=r},772:function(e){e.exports=t},721:function(e){e.exports=n},156:function(t){t.exports=e}},l={};function o(e){var t=l[e];if(void 0!==t)return t.exports;var r=l[e]={exports:{}};return a[e](r,r.exports,o),r.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return!function(){o.r(i),o.d(i,{default:function(){return z}});var e=o(772),t=o(156),r=o.n(t),n=o(721),a=o(482),l=(0,t.createContext)({employees:[],employeeMap:new Map,loading:!1}),u=function(t){var n=t.children,a=(0,e.useRequest)({url:"aiEmployees:list",params:{pageSize:200}}),o=a.data,i=a.loading,u=r().useMemo(function(){var e=((null==o?void 0:o.data)||[]).map(function(e){var t;return{username:e.username,nickname:e.nickname||e.username,about:null==(t=e.about)?void 0:t.substring(0,80)}}),t=new Map,r=!0,n=!1,a=void 0;try{for(var l,u=e[Symbol.iterator]();!(r=(l=u.next()).done);r=!0){var c=l.value;t.set(c.username,c.nickname)}}catch(e){n=!0,a=e}finally{try{r||null==u.return||u.return()}finally{if(n)throw a}}return{employees:e,employeeMap:t,loading:i}},[o,i]);return r().createElement(l.Provider,{value:u},n)},c=function(){return(0,t.useContext)(l)},s=function(e){var t=e.value,a=e.onChange,l=e.exclude,o=e.placeholder,i=c(),u=i.employees,s=i.loading,m=r().useMemo(function(){return u.filter(function(e){return!l||e.username!==l}).map(function(e){return{label:e.nickname,value:e.username,description:e.about}})},[u,l]);return r().createElement(n.Select,{loading:s,options:m,value:t,onChange:a,placeholder:void 0===o?"Select AI Employee...":o,showSearch:!0,filterOption:function(e,t){var r,n;return(null!=(r=null==t?void 0:t.label)?r:"").toString().toLowerCase().includes(e.toLowerCase())||(null!=(n=null==t?void 0:t.value)?n:"").toString().toLowerCase().includes(e.toLowerCase())},optionRender:function(e){return r().createElement("div",null,r().createElement("div",{style:{fontWeight:500}},e.label),e.data.description&&r().createElement("div",{style:{fontSize:12,color:"#888"}},e.data.description))}})};function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t,r,n,a,l,o){try{var i=e[l](o),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){d(l,n,a,o,i,"next",e)}function i(e){d(l,n,a,o,i,"throw",e)}o(void 0)})}}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,i=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){i=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(i)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return m(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return m(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e,t){var r,n,a,l,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){var u=[l,i];if(r)throw TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(a=2&u[0]?n.return:u[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;switch(n=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(a=(a=o.trys).length>0&&a[a.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){o.label=u[1];break}if(6===u[0]&&o.label<a[1]){o.label=a[1],a=u;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(u);break}a[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],n=0}finally{r=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var h=n.Typography.Text,g=function(){var l,o,i=(0,e.useAPIClient)(),u=f((0,t.useState)(!1),2),m=u[0],d=u[1],g=f((0,t.useState)(null),2),b=g[0],v=g[1],E=f(n.Form.useForm(),1)[0],w=(0,e.useRequest)({url:"orchestratorConfig:list",params:{sort:["-createdAt"]}}),S=w.data,x=w.loading,k=w.refresh,A=(0,e.useRequest)({url:"llmServices:list",params:{filter:{enabled:!0}}}),C=A.data;A.loading;var O=r().useMemo(function(){return(null==C?void 0:C.data)||[]},[C]),T=c().employeeMap,I=r().useMemo(function(){var e=null==S?void 0:S.data;return Array.isArray(e)?e:[]},[S]),M=r().useMemo(function(){var e=new Map,t=!0,r=!1,n=void 0;try{for(var a,l=I[Symbol.iterator]();!(t=(a=l.next()).done);t=!0){var o=a.value,i=o.leaderUsername||"unknown";e.has(i)||e.set(i,[]),e.get(i).push(o)}}catch(e){r=!0,n=e}finally{try{t||null==l.return||l.return()}finally{if(r)throw n}}return Array.from(e.entries()).map(function(e){var t=f(e,2);return{leaderUsername:t[0],items:t[1]}})},[I]),z=function(e){v(e),e?E.setFieldsValue(e):(E.resetFields(),E.setFieldsValue({enabled:!0,maxDepth:1,timeout:12e4})),d(!0)},U=function(){d(!1),v(null)},D=(l=p(function(e){var t,r,a,l,o,u;return y(this,function(c){switch(c.label){case 0:if(e.leaderUsername===e.subAgentUsername)return n.message.error("Leader and Sub-Agent cannot be the same employee."),[2];c.label=1;case 1:if(c.trys.push([1,6,,7]),!b)return[3,3];return[4,i.request({url:"orchestratorConfig:update",method:"put",params:{filterByTk:b.id},data:e})];case 2:return c.sent(),n.message.success("Rule updated"),[3,5];case 3:return[4,i.request({url:"orchestratorConfig:create",method:"post",data:e})];case 4:c.sent(),n.message.success("Rule created"),c.label=5;case 5:return U(),k(),[3,7];case 6:return u=(null==(t=c.sent())||null==(o=t.response)||null==(l=o.data)||null==(a=l.errors)||null==(r=a[0])?void 0:r.message)||t.message,n.message.error("Save failed: ".concat(u)),[3,7];case 7:return[2]}})}),function(e){return l.apply(this,arguments)}),P=(o=p(function(e){var t;return y(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,i.request({url:"orchestratorConfig:destroy",method:"delete",params:{filterByTk:e}})];case 1:return r.sent(),n.message.success("Rule deleted"),k(),[3,3];case 2:return t=r.sent(),n.message.error("Delete failed: ".concat(t.message)),[3,3];case 3:return[2]}})}),function(e){return o.apply(this,arguments)}),L=[{title:"Leader (Orchestrator)",dataIndex:"leaderUsername",key:"leaderUsername",render:function(e){return r().createElement(n.Tag,{color:"blue"},T.get(e)||e)}},{title:"",key:"arrow",width:50,render:function(){return r().createElement(a.SwapRightOutlined,{style:{color:"#999",fontSize:18}})}},{title:"Sub-Agent",dataIndex:"subAgentUsername",key:"subAgentUsername",render:function(e){return r().createElement(n.Tag,{color:"green"},T.get(e)||e)}},{title:"Max Depth",dataIndex:"maxDepth",key:"maxDepth",width:100,render:function(e){return null!=e?e:1}},{title:"Timeout",dataIndex:"timeout",key:"timeout",width:100,render:function(e){return"".concat(((null!=e?e:12e4)/1e3).toFixed(0),"s")}},{title:"LLM Override",key:"llmOverride",width:140,render:function(e,t){if(t.llmService&&t.model){var a=O.find(function(e){return e.name===t.llmService}),l=a?a.title:t.llmService;return r().createElement(n.Space,{direction:"vertical",size:0},r().createElement(h,{style:{fontSize:12}},l),r().createElement(h,{type:"secondary",style:{fontSize:12}},t.model))}return r().createElement(h,{type:"secondary",style:{fontSize:12}},"Inherited")}},{title:"Enabled",dataIndex:"enabled",key:"enabled",width:80,render:function(e,t){var a;return r().createElement(n.Switch,{checked:e,size:"small",onChange:(a=p(function(e){return y(this,function(r){switch(r.label){case 0:return[4,i.request({url:"orchestratorConfig:update",method:"put",params:{filterByTk:t.id},data:{enabled:e}})];case 1:return r.sent(),k(),[2]}})}),function(e){return a.apply(this,arguments)})})}},{title:"Actions",key:"actions",width:160,render:function(e,t){return r().createElement(n.Space,null,r().createElement(n.Button,{type:"link",size:"small",icon:r().createElement(a.EditOutlined,null),onClick:function(){return z(t)}},"Edit"),r().createElement(n.Popconfirm,{title:"Delete this rule?",onConfirm:function(){return P(t.id)}},r().createElement(n.Button,{type:"link",size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)},"Delete")))}}],B=n.Form.useWatch("leaderUsername",E);return r().createElement("div",null,r().createElement(n.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"Orchestration Rules",description:r().createElement(h,{type:"secondary"},"Configure which AI Employees can act as Leaders (Orchestrators) and which ones they can delegate tasks to. Each rule creates a callable tool for the Leader to invoke the Sub-Agent.")}),r().createElement(n.Card,{bordered:!1},r().createElement("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-end"}},r().createElement(n.Button,{type:"primary",icon:r().createElement(a.PlusOutlined,null),onClick:function(){return z()}},"New Rule")),M.length?r().createElement(n.Collapse,{bordered:!1,defaultActiveKey:M.map(function(e){return e.leaderUsername}),items:M.map(function(e){return{key:e.leaderUsername,label:r().createElement(n.Space,null,r().createElement(n.Tag,{color:"blue"},T.get(e.leaderUsername)||e.leaderUsername),r().createElement(h,{type:"secondary"},e.items.length," sub-agent",e.items.length>1?"s":"")),children:r().createElement(n.Table,{rowKey:"id",loading:x,dataSource:e.items,columns:L,pagination:!1,size:"middle"})}})}):r().createElement(n.Table,{rowKey:"id",loading:x,dataSource:[],columns:L,pagination:!1,size:"middle",locale:{emptyText:r().createElement(n.Empty,{description:"No orchestration rules yet"})}})),r().createElement(n.Drawer,{title:b?"Edit Orchestration Rule":"New Orchestration Rule",width:480,onClose:U,open:m,styles:{body:{paddingBottom:80}},extra:r().createElement(n.Space,null,r().createElement(n.Button,{onClick:U},"Cancel"),r().createElement(n.Button,{onClick:function(){return E.submit()},type:"primary"},"Save"))},r().createElement(n.Form,{form:E,layout:"vertical",onFinish:D},r().createElement(n.Form.Item,{name:"leaderUsername",label:"Leader (Orchestrator)",rules:[{required:!0,message:"Please select a Leader"}],tooltip:"The AI Employee that will be able to delegate tasks to the Sub-Agent"},r().createElement(s,{placeholder:"Select Leader AI Employee..."})),r().createElement(n.Form.Item,{name:"subAgentUsername",label:"Sub-Agent",rules:[{required:!0,message:"Please select a Sub-Agent"}],tooltip:"The AI Employee that will receive delegated tasks"},r().createElement(s,{placeholder:"Select Sub-Agent AI Employee...",exclude:B})),r().createElement(n.Form.Item,{name:"maxDepth",label:"Max Delegation Depth",tooltip:"How many layers of delegation are allowed (1 = leader calls sub-agent, sub-agent cannot delegate further)"},r().createElement(n.InputNumber,{min:1,max:3,style:{width:"100%"}})),r().createElement(n.Form.Item,{name:"timeout",label:"Timeout (ms)",tooltip:"Maximum time in milliseconds for the sub-agent to complete its task"},r().createElement(n.InputNumber,{min:1e4,max:6e5,step:1e4,style:{width:"100%"}})),r().createElement(n.Form.Item,{name:"llmService",label:"Override LLM Service",tooltip:"Optional: Provider name. Leave empty to inherit from Leader."},r().createElement(n.Select,{allowClear:!0,placeholder:"Inherit from Leader",options:O.map(function(e){return{label:e.title||e.name,value:e.name}}),onChange:function(){return E.setFieldValue("model",void 0)}})),r().createElement(n.Form.Item,{noStyle:!0,shouldUpdate:function(e,t){return e.llmService!==t.llmService}},function(){var e,t=E.getFieldValue("llmService"),a=O.find(function(e){return e.name===t}),l=(null==a||null==(e=a.enabledModels)?void 0:e.models)||[];return r().createElement(n.Form.Item,{name:"model",label:"Override Model",tooltip:"Optional: Model name. Leave empty to inherit from Leader.",rules:[{required:!!t,message:"Please select a model"}]},r().createElement(n.Select,{allowClear:!0,placeholder:t?"Select a model":"Inherit from Leader",disabled:!t,options:l.map(function(e){return{label:e.label,value:e.value}})}))}),r().createElement(n.Form.Item,{name:"enabled",label:"Enabled",valuePropName:"checked"},r().createElement(n.Switch,null)))))};function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function v(e,t,r,n,a,l,o){try{var i=e[l](o),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function E(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var l=[],o=!0,i=!1;try{for(a=a.call(e);!(o=(r=a.next()).done)&&(l.push(r.value),!t||l.length!==t);o=!0);}catch(e){i=!0,n=e}finally{try{o||null==a.return||a.return()}finally{if(i)throw n}}return l}}(e,t)||function(e,t){if(e){if("string"==typeof e)return b(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return b(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var w=n.Typography.Text,S=n.Typography.Paragraph,x=function(){var l,o,i,u=(0,e.useAPIClient)(),s=E((0,t.useState)(null),2),m=s[0],d=s[1],p=E((0,t.useState)(!1),2),f=p[0],y=p[1],h=(0,e.useRequest)({url:"orchestratorTracing:list",params:{sort:["-createdAt"],pageSize:50}}),g=h.data,b=h.loading,x=h.refresh,k=c().employeeMap,A=r().useMemo(function(){var e=null==g?void 0:g.data;return e&&!Array.isArray(e)&&Array.isArray(e.data)&&(e=e.data),Array.isArray(e)?e:Array.isArray(g)?g:[]},[g]),C=r().useMemo(function(){var e=new Map,t=!0,r=!1,n=void 0;try{for(var a,l=A[Symbol.iterator]();!(t=(a=l.next()).done);t=!0){var o=a.value,i=o.leaderUsername||"unknown";e.has(i)||e.set(i,[]),e.get(i).push(o)}}catch(e){r=!0,n=e}finally{try{t||null==l.return||l.return()}finally{if(r)throw n}}return Array.from(e.entries()).map(function(e){var t=E(e,2);return{leaderUsername:t[0],items:t[1]}})},[A]),O=function(e){return e?e>=1e3?"".concat((e/1e3).toFixed(1),"s"):"".concat(e,"ms"):"-"},T=(l=function(e){var t,r;return function(e,t){var r,n,a,l,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){var u=[l,i];if(r)throw TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(a=2&u[0]?n.return:u[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;switch(n=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(a=(a=o.trys).length>0&&a[a.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){o.label=u[1];break}if(6===u[0]&&o.label<a[1]){o.label=a[1],a=u;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(u);break}a[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],n=0}finally{r=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(n){switch(n.label){case 0:d(e),y(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),[4,u.request({url:"orchestratorTracing:get",params:{filterByTk:e.id}})];case 2:return d((null==(r=n.sent())||null==(t=r.data)?void 0:t.data)||(null==r?void 0:r.data)||e),[3,4];case 3:return y(!1),[7];case 4:return[2]}})},o=function(){var e=this,t=arguments;return new Promise(function(r,n){var a=l.apply(e,t);function o(e){v(a,r,n,o,i,"next",e)}function i(e){v(a,r,n,o,i,"throw",e)}o(void 0)})},function(e){return o.apply(this,arguments)}),I=[{title:"Time",dataIndex:"createdAt",key:"createdAt",width:170,render:function(e){return e?new Date(e).toLocaleString():"-"}},{title:"Leader",dataIndex:"leaderUsername",key:"leaderUsername",render:function(e){return r().createElement(n.Tag,{color:"blue"},k.get(e)||e)}},{title:"Sub-Agent",dataIndex:"subAgentUsername",key:"subAgentUsername",render:function(e){return r().createElement(n.Tag,{color:"green"},k.get(e)||e)}},{title:"Task",dataIndex:"task",key:"task",render:function(e){return r().createElement(w,{ellipsis:!0,style:{maxWidth:280}},(null==e?void 0:e.substring(0,100))||"-")}},{title:"Status",dataIndex:"status",key:"status",width:90,render:function(e){return r().createElement(n.Tag,{icon:"success"===e?r().createElement(a.CheckCircleOutlined,null):r().createElement(a.CloseCircleOutlined,null),color:"success"===e?"success":"error"},e)}},{title:"Duration",dataIndex:"durationMs",key:"durationMs",width:90,render:O},{title:"Depth",dataIndex:"depth",key:"depth",width:60,render:function(e){return null!=e?e:0}},{title:"",key:"actions",width:80,render:function(e,t){return r().createElement(n.Button,{type:"link",size:"small",icon:r().createElement(a.EyeOutlined,null),onClick:function(){return T(t)}},"Detail")}}];return r().createElement("div",null,r().createElement(n.Alert,{type:"info",showIcon:!0,style:{marginBottom:16},message:"Swarm Tracing",description:r().createElement(w,{type:"secondary"},"View delegation execution logs. Each row represents one sub-agent invocation triggered by a Leader's tool call.")}),r().createElement(n.Card,{bordered:!1},r().createElement("div",{style:{marginBottom:16,display:"flex",justifyContent:"flex-end"}},r().createElement(n.Button,{onClick:x},"Refresh")),C.length?r().createElement(n.Collapse,{bordered:!1,defaultActiveKey:C.map(function(e){return e.leaderUsername}),items:C.map(function(e){return{key:e.leaderUsername,label:r().createElement(n.Space,null,r().createElement(n.Tag,{color:"blue"},k.get(e.leaderUsername)||e.leaderUsername),r().createElement(w,{type:"secondary"},e.items.length," execution",e.items.length>1?"s":"")),children:r().createElement(n.Table,{rowKey:"id",loading:b,dataSource:e.items,columns:I,pagination:{hideOnSinglePage:!0,pageSize:20},size:"middle"})}})}):r().createElement(n.Table,{rowKey:"id",loading:b,dataSource:[],columns:I,pagination:!1,size:"middle",locale:{emptyText:r().createElement(n.Empty,{description:"No delegation executions yet"})}})),r().createElement(n.Drawer,{title:"Delegation Detail",width:760,onClose:function(){return d(null)},open:!!m},m&&r().createElement(n.Spin,{spinning:f},r().createElement(r().Fragment,null,r().createElement(n.Descriptions,{column:1,bordered:!0,size:"small",style:{marginBottom:16}},r().createElement(n.Descriptions.Item,{label:"Status"},r().createElement(n.Tag,{icon:"success"===m.status?r().createElement(a.CheckCircleOutlined,null):r().createElement(a.CloseCircleOutlined,null),color:"success"===m.status?"success":"error"},m.status)),r().createElement(n.Descriptions.Item,{label:"Leader"},r().createElement(n.Tag,{color:"blue"},k.get(m.leaderUsername)||m.leaderUsername)),r().createElement(n.Descriptions.Item,{label:"Sub-Agent"},r().createElement(n.Tag,{color:"green"},k.get(m.subAgentUsername)||m.subAgentUsername)),r().createElement(n.Descriptions.Item,{label:"Tool"},r().createElement(w,{code:!0},m.toolName)),r().createElement(n.Descriptions.Item,{label:"Depth"},null!=(i=m.depth)?i:0),r().createElement(n.Descriptions.Item,{label:"Duration"},O(m.durationMs)),r().createElement(n.Descriptions.Item,{label:"Time"},m.createdAt?new Date(m.createdAt).toLocaleString():"-")),r().createElement(n.Card,{title:"Task",size:"small",style:{marginBottom:16}},r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:13}},m.task||"No task description")),m.context&&r().createElement(n.Card,{title:"Context",size:"small",style:{marginBottom:16}},r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:13}},m.context)),r().createElement(n.Card,{title:"Sub-Agent Flow",size:"small",style:{marginBottom:16}},Array.isArray(m.trace)&&m.trace.length?r().createElement(n.Timeline,{items:m.trace.map(function(e,t){return{key:t,color:"error"===e.status?"red":"tool_call"===e.type?"blue":"green",children:r().createElement("div",null,r().createElement(n.Space,{direction:"vertical",size:2,style:{width:"100%"}},r().createElement(w,{strong:!0},e.title||e.type),r().createElement(w,{type:"secondary"},e.at?new Date(e.at).toLocaleString():""),e.toolName&&r().createElement(w,{code:!0},e.toolName),e.content&&r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:13}},e.content),e.args&&r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:12}},JSON.stringify(e.args,null,2))))}})}):r().createElement(n.Empty,{description:"No flow trace captured"})),Array.isArray(m.messages)&&m.messages.length>0&&r().createElement(n.Collapse,{style:{marginBottom:16},items:[{key:"messages",label:"Raw messages (".concat(m.messages.length,")"),children:r().createElement(n.Space,{direction:"vertical",style:{width:"100%"}},m.messages.map(function(e){var t;return r().createElement(n.Card,{key:e.index,size:"small",title:"".concat(e.index+1,". ").concat(e.type)},r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:12}},e.content||JSON.stringify(e.toolCalls||e,null,2)),(null==(t=e.toolCalls)?void 0:t.length)>0&&r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:"8px 0 0",fontSize:12}},JSON.stringify(e.toolCalls,null,2)))}))}]}),r().createElement(n.Card,{title:"Result",size:"small",style:{marginBottom:16,borderColor:"success"===m.status?"#b7eb8f":"#ffa39e"}},r().createElement(S,{style:{whiteSpace:"pre-wrap",margin:0,fontSize:13},ellipsis:{rows:20,expandable:!0}},m.result||m.error||"No result")),m.error&&r().createElement(n.Card,{title:"Error",size:"small",style:{borderColor:"#ffa39e"}},r().createElement(S,{type:"danger",style:{whiteSpace:"pre-wrap",margin:0,fontSize:13}},m.error))))))},k=function(){return r().createElement(u,null,r().createElement("div",{style:{padding:"0 24px 24px"}},r().createElement(n.Tabs,{defaultActiveKey:"rules",items:[{key:"rules",label:r().createElement("span",null,r().createElement(a.ApartmentOutlined,null)," Orchestration Rules"),children:r().createElement(g,null)},{key:"tracing",label:r().createElement("span",null,r().createElement(a.MonitorOutlined,null)," Swarm Tracing"),children:r().createElement(x,null)}]})))};function A(e,t,r,n,a,l,o){try{var i=e[l](o),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,a)}function C(e,t,r){return(C=M()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&T(a,r.prototype),a}).apply(null,arguments)}function O(e){return(O=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function I(e){var t="function"==typeof Map?new Map:void 0;return(I=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return C(e,arguments,O(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,e)})(e)}function M(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(M=function(){return!!e})()}var z=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=O(e),function(e,t){var r;if(t&&("object"==((r=t)&&"undefined"!=typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,M()?Reflect.construct(e,t||[],O(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&T(r,e),t=[{key:"load",value:function(){var e,t=this;return(e=function(){return function(e,t){var r,n,a,l,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return l={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function i(l){return function(i){var u=[l,i];if(r)throw TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(a=2&u[0]?n.return:u[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,u[1])).done)return a;switch(n=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,n=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(a=(a=o.trys).length>0&&a[a.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){o.label=u[1];break}if(6===u[0]&&o.label<a[1]){o.label=a[1],a=u;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(u);break}a[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],n=0}finally{r=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(e){return t.app.pluginSettingsManager.add("ai.orchestrator",{title:"Agent Orchestrator",icon:"ApartmentOutlined",Component:k}),[2]})},function(){var t=this,r=arguments;return new Promise(function(n,a){var l=e.apply(t,r);function o(e){A(l,n,a,o,i,"next",e)}function i(e){A(l,n,a,o,i,"throw",e)}o(void 0)})})()}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(r.prototype,t),r}(I(e.Plugin))}(),i}()});
|
package/dist/externalVersion.js
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
11
|
"react": "18.2.0",
|
|
12
|
-
"@nocobase/client": "2.0.
|
|
12
|
+
"@nocobase/client": "2.0.45",
|
|
13
13
|
"antd": "5.24.2",
|
|
14
14
|
"@ant-design/icons": "5.6.1",
|
|
15
|
-
"@nocobase/server": "2.0.
|
|
16
|
-
"@nocobase/database": "2.0.
|
|
17
|
-
"@nocobase/actions": "2.0.
|
|
15
|
+
"@nocobase/server": "2.0.45",
|
|
16
|
+
"@nocobase/database": "2.0.45",
|
|
17
|
+
"@nocobase/actions": "2.0.45",
|
|
18
18
|
"@langchain/langgraph": "0.2.74",
|
|
19
19
|
"@langchain/core": "0.3.80",
|
|
20
|
-
"@nocobase/plugin-ai": "2.0.
|
|
21
|
-
"@nocobase/ai": "2.0.
|
|
20
|
+
"@nocobase/plugin-ai": "2.0.45",
|
|
21
|
+
"@nocobase/ai": "2.0.45"
|
|
22
22
|
};
|
|
@@ -68,6 +68,16 @@ var orchestrator_config_default = (0, import_database.defineCollection)({
|
|
|
68
68
|
type: "integer",
|
|
69
69
|
defaultValue: 12e4,
|
|
70
70
|
comment: "Timeout in ms for sub-agent execution"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "llmService",
|
|
74
|
+
type: "string",
|
|
75
|
+
comment: "Optional overridden LLM provider for the sub-agent"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "model",
|
|
79
|
+
type: "string",
|
|
80
|
+
comment: "Optional overridden model for the sub-agent"
|
|
71
81
|
}
|
|
72
82
|
],
|
|
73
83
|
indexes: [
|
|
@@ -55,7 +55,12 @@ var orchestrator_logs_default = (0, import_database.defineCollection)({
|
|
|
55
55
|
{
|
|
56
56
|
name: "toolName",
|
|
57
57
|
type: "string",
|
|
58
|
-
comment: "The tool name used for delegation (e.g.,
|
|
58
|
+
comment: "The tool name used for delegation (e.g., delegate_pm_to_sql_expert)"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "context",
|
|
62
|
+
type: "text",
|
|
63
|
+
comment: "Optional context sent with the delegated task"
|
|
59
64
|
},
|
|
60
65
|
{
|
|
61
66
|
name: "task",
|
|
@@ -70,7 +75,7 @@ var orchestrator_logs_default = (0, import_database.defineCollection)({
|
|
|
70
75
|
{
|
|
71
76
|
name: "status",
|
|
72
77
|
type: "string",
|
|
73
|
-
comment: "success or error"
|
|
78
|
+
comment: "running, success, or error"
|
|
74
79
|
},
|
|
75
80
|
{
|
|
76
81
|
name: "depth",
|
|
@@ -88,6 +93,18 @@ var orchestrator_logs_default = (0, import_database.defineCollection)({
|
|
|
88
93
|
type: "text",
|
|
89
94
|
comment: "Error message if status is error"
|
|
90
95
|
},
|
|
96
|
+
{
|
|
97
|
+
name: "trace",
|
|
98
|
+
type: "json",
|
|
99
|
+
defaultValue: [],
|
|
100
|
+
comment: "Structured timeline of sub-agent execution and tool calls"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "messages",
|
|
104
|
+
type: "json",
|
|
105
|
+
defaultValue: [],
|
|
106
|
+
comment: "Serialized LangChain messages from the sub-agent run"
|
|
107
|
+
},
|
|
91
108
|
{
|
|
92
109
|
name: "userId",
|
|
93
110
|
type: "bigInt",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var add_tracing_detail_fields_exports = {};
|
|
28
|
+
__export(add_tracing_detail_fields_exports, {
|
|
29
|
+
default: () => AddTracingDetailFieldsMigration
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(add_tracing_detail_fields_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class AddTracingDetailFieldsMigration extends import_server.Migration {
|
|
34
|
+
on = "afterLoad";
|
|
35
|
+
appVersion = "<=2.x";
|
|
36
|
+
async up() {
|
|
37
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
38
|
+
const DataTypes = this.db.sequelize.constructor["DataTypes"];
|
|
39
|
+
const tableName = `${this.db.options.tablePrefix || ""}orchestratorLogs`;
|
|
40
|
+
const tableExists = await queryInterface.describeTable(tableName).then(() => true).catch(() => false);
|
|
41
|
+
if (!tableExists) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const columns = await queryInterface.describeTable(tableName);
|
|
45
|
+
const addIfMissing = async (name, definition) => {
|
|
46
|
+
if (!columns[name]) {
|
|
47
|
+
await queryInterface.addColumn(tableName, name, definition);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
await addIfMissing("context", { type: DataTypes.TEXT, allowNull: true });
|
|
51
|
+
await addIfMissing("trace", { type: DataTypes.JSON, allowNull: true, defaultValue: [] });
|
|
52
|
+
await addIfMissing("messages", { type: DataTypes.JSON, allowNull: true, defaultValue: [] });
|
|
53
|
+
}
|
|
54
|
+
async down() {
|
|
55
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
56
|
+
const tableName = `${this.db.options.tablePrefix || ""}orchestratorLogs`;
|
|
57
|
+
for (const column of ["context", "trace", "messages"]) {
|
|
58
|
+
await queryInterface.removeColumn(tableName, column).catch(() => {
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var add_llm_fields_exports = {};
|
|
28
|
+
__export(add_llm_fields_exports, {
|
|
29
|
+
default: () => AddLlmFieldsToOrchestratorConfig
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(add_llm_fields_exports);
|
|
32
|
+
var import_server = require("@nocobase/server");
|
|
33
|
+
class AddLlmFieldsToOrchestratorConfig extends import_server.Migration {
|
|
34
|
+
on = "afterLoad";
|
|
35
|
+
appVersion = ">=0.1.0";
|
|
36
|
+
async up() {
|
|
37
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
38
|
+
const tablePrefix = this.db.options.tablePrefix || "";
|
|
39
|
+
const tableName = `${tablePrefix}orchestratorConfig`;
|
|
40
|
+
const tableExists = await queryInterface.tableExists(tableName);
|
|
41
|
+
if (!tableExists) return;
|
|
42
|
+
const tableDesc = await queryInterface.describeTable(tableName);
|
|
43
|
+
if (!tableDesc["llmService"]) {
|
|
44
|
+
await queryInterface.addColumn(tableName, "llmService", {
|
|
45
|
+
type: "VARCHAR(255)",
|
|
46
|
+
allowNull: true
|
|
47
|
+
});
|
|
48
|
+
console.log(`[AgentOrchestrator] Added llmService column to ${tableName}`);
|
|
49
|
+
}
|
|
50
|
+
if (!tableDesc["model"]) {
|
|
51
|
+
await queryInterface.addColumn(tableName, "model", {
|
|
52
|
+
type: "VARCHAR(255)",
|
|
53
|
+
allowNull: true
|
|
54
|
+
});
|
|
55
|
+
console.log(`[AgentOrchestrator] Added model column to ${tableName}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async down() {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -39,9 +39,10 @@ function registerTracingResource(plugin) {
|
|
|
39
39
|
*/
|
|
40
40
|
async list(ctx, next) {
|
|
41
41
|
const repo = ctx.db.getRepository("orchestratorLogs");
|
|
42
|
-
const { page = 1, pageSize = 50, sort = ["-createdAt"] } = ctx.action.params;
|
|
42
|
+
const { page = 1, pageSize = 50, sort = ["-createdAt"], filter = {} } = ctx.action.params;
|
|
43
43
|
try {
|
|
44
44
|
const [rows, count] = await repo.findAndCount({
|
|
45
|
+
filter,
|
|
45
46
|
sort,
|
|
46
47
|
offset: (Number(page) - 1) * Number(pageSize),
|
|
47
48
|
limit: Number(pageSize)
|
|
@@ -53,13 +54,16 @@ function registerTracingResource(plugin) {
|
|
|
53
54
|
subAgentUsername: row.subAgentUsername,
|
|
54
55
|
toolName: row.toolName,
|
|
55
56
|
task: row.task,
|
|
57
|
+
context: row.context,
|
|
56
58
|
result: row.result,
|
|
57
59
|
status: row.status,
|
|
58
60
|
depth: row.depth,
|
|
59
61
|
durationMs: row.durationMs,
|
|
60
62
|
error: row.error,
|
|
61
63
|
userId: row.userId,
|
|
62
|
-
createdAt: row.createdAt
|
|
64
|
+
createdAt: row.createdAt,
|
|
65
|
+
traceCount: Array.isArray(row.trace) ? row.trace.length : 0,
|
|
66
|
+
messageCount: Array.isArray(row.messages) ? row.messages.length : 0
|
|
63
67
|
})),
|
|
64
68
|
meta: {
|
|
65
69
|
count,
|
|
@@ -78,6 +82,7 @@ function registerTracingResource(plugin) {
|
|
|
78
82
|
* Get a single delegation log by ID.
|
|
79
83
|
*/
|
|
80
84
|
async get(ctx, next) {
|
|
85
|
+
var _a;
|
|
81
86
|
const { filterByTk } = ctx.action.params;
|
|
82
87
|
if (!filterByTk) {
|
|
83
88
|
ctx.throw(400, "id is required");
|
|
@@ -88,7 +93,7 @@ function registerTracingResource(plugin) {
|
|
|
88
93
|
const log = await repo.findOne({
|
|
89
94
|
filter: { id: filterByTk }
|
|
90
95
|
});
|
|
91
|
-
ctx.body = { data: log };
|
|
96
|
+
ctx.body = { data: ((_a = log == null ? void 0 : log.toJSON) == null ? void 0 : _a.call(log)) || log || null };
|
|
92
97
|
} catch (e) {
|
|
93
98
|
ctx.log.error("[AgentOrchestrator] Tracing get error", e);
|
|
94
99
|
ctx.body = { data: null };
|