plugin-agent-orchestrator 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/client/hooks/useRunEventStream.d.ts +22 -0
  2. package/dist/client/index.d.ts +1 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/externalVersion.js +6 -6
  5. package/dist/server/collections/agent-execution-spans.js +24 -0
  6. package/dist/server/collections/agent-loop-runs.js +36 -0
  7. package/dist/server/collections/orchestrator-config.js +14 -0
  8. package/dist/server/migrations/20260601000000-add-token-fields.d.ts +7 -0
  9. package/dist/server/migrations/20260601000000-add-token-fields.js +101 -0
  10. package/dist/server/plugin.js +47 -0
  11. package/dist/server/resources/agent-loop.js +33 -25
  12. package/dist/server/resources/tracing.js +5 -8
  13. package/dist/server/services/AgentHarness.d.ts +2 -0
  14. package/dist/server/services/AgentHarness.js +56 -90
  15. package/dist/server/services/AgentLoopController.d.ts +33 -20
  16. package/dist/server/services/AgentLoopController.js +164 -125
  17. package/dist/server/services/AgentLoopRepository.js +16 -34
  18. package/dist/server/services/AgentLoopService.d.ts +28 -18
  19. package/dist/server/services/AgentLoopService.js +7 -1
  20. package/dist/server/services/AgentPlannerService.js +5 -25
  21. package/dist/server/services/AgentRegistryService.d.ts +8 -0
  22. package/dist/server/services/AgentRegistryService.js +34 -24
  23. package/dist/server/services/CircuitBreaker.d.ts +40 -0
  24. package/dist/server/services/CircuitBreaker.js +120 -0
  25. package/dist/server/services/ContextAggregator.d.ts +45 -0
  26. package/dist/server/services/ContextAggregator.js +201 -0
  27. package/dist/server/services/ExecutionSpanService.js +2 -5
  28. package/dist/server/services/RunEventBus.d.ts +9 -0
  29. package/dist/server/services/RunEventBus.js +73 -0
  30. package/dist/server/services/TokenTracker.d.ts +62 -0
  31. package/dist/server/services/TokenTracker.js +173 -0
  32. package/dist/server/tools/agent-loop.d.ts +8 -8
  33. package/dist/server/tools/agent-loop.js +30 -63
  34. package/dist/server/tools/delegate-task.js +14 -72
  35. package/dist/server/tools/orchestrator-plan.d.ts +6 -6
  36. package/dist/server/tools/orchestrator-plan.js +10 -47
  37. package/dist/server/types.d.ts +47 -0
  38. package/dist/server/types.js +24 -0
  39. package/dist/server/utils/ctx-utils.d.ts +30 -0
  40. package/dist/server/utils/ctx-utils.js +152 -0
  41. package/dist/server/utils/logging.d.ts +6 -0
  42. package/dist/server/utils/logging.js +86 -0
  43. package/package.json +44 -44
  44. package/src/client/AgentRunsTab.tsx +764 -764
  45. package/src/client/HarnessProfilesTab.tsx +247 -247
  46. package/src/client/OrchestratorSettings.tsx +106 -106
  47. package/src/client/RulesTab.tsx +716 -716
  48. package/src/client/hooks/useRunEventStream.ts +76 -0
  49. package/src/client/index.tsx +2 -1
  50. package/src/client/plugin.tsx +27 -27
  51. package/src/client/skill-hub/components/LoopSettings.tsx +331 -331
  52. package/src/client/skill-hub/index.tsx +51 -51
  53. package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +99 -99
  54. package/src/client/skill-hub/tools/SkillHubCard.tsx +109 -109
  55. package/src/client/skill-hub/tools/loopTemplates.ts +52 -52
  56. package/src/client/skill-hub/tools/registerSkillLoopCards.ts +58 -58
  57. package/src/client/tools/PlanApprovalCard.tsx +175 -175
  58. package/src/client/tools/registerOrchestratorCards.ts +7 -7
  59. package/src/server/__tests__/agent-loop-controller.test.ts +375 -0
  60. package/src/server/__tests__/circuit-breaker.test.ts +169 -0
  61. package/src/server/__tests__/context-aggregator.test.ts +222 -0
  62. package/src/server/__tests__/parallel-execution.test.ts +318 -0
  63. package/src/server/__tests__/smoke.test.ts +120 -0
  64. package/src/server/collections/agent-execution-spans.ts +24 -0
  65. package/src/server/collections/agent-harness-profiles.ts +59 -59
  66. package/src/server/collections/agent-loop-events.ts +71 -71
  67. package/src/server/collections/agent-loop-runs.ts +38 -1
  68. package/src/server/collections/agent-loop-steps.ts +144 -144
  69. package/src/server/collections/orchestrator-config.ts +14 -0
  70. package/src/server/collections/skill-executions.ts +106 -106
  71. package/src/server/collections/skill-loop-configs.ts +65 -65
  72. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +30 -30
  73. package/src/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.ts +142 -142
  74. package/src/server/migrations/20260601000000-add-token-fields.ts +89 -0
  75. package/src/server/plugin.ts +53 -0
  76. package/src/server/resources/agent-loop.ts +21 -12
  77. package/src/server/resources/tracing.ts +3 -7
  78. package/src/server/services/AgentHarness.ts +78 -116
  79. package/src/server/services/AgentLoopController.ts +197 -122
  80. package/src/server/services/AgentLoopRepository.ts +9 -25
  81. package/src/server/services/AgentLoopService.ts +13 -1
  82. package/src/server/services/AgentPlanValidator.ts +73 -73
  83. package/src/server/services/AgentPlannerService.ts +2 -25
  84. package/src/server/services/AgentRegistryService.ts +40 -31
  85. package/src/server/services/CircuitBreaker.ts +116 -0
  86. package/src/server/services/ContextAggregator.ts +239 -0
  87. package/src/server/services/ExecutionSpanService.ts +2 -4
  88. package/src/server/services/RunEventBus.ts +45 -0
  89. package/src/server/services/TokenTracker.ts +209 -0
  90. package/src/server/skill-hub/plugin.ts +898 -898
  91. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +460 -460
  92. package/src/server/tools/agent-loop.ts +18 -57
  93. package/src/server/tools/delegate-task.ts +11 -93
  94. package/src/server/tools/orchestrator-plan.ts +26 -50
  95. package/src/server/tools/skill-execute.ts +160 -160
  96. package/src/server/types.ts +55 -0
  97. package/src/server/utils/ctx-utils.ts +118 -0
  98. package/src/server/utils/logging.ts +63 -0
@@ -0,0 +1,152 @@
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 ctx_utils_exports = {};
28
+ __export(ctx_utils_exports, {
29
+ asArray: () => asArray,
30
+ asObject: () => asObject,
31
+ captureCtxSnapshot: () => captureCtxSnapshot,
32
+ currentUserId: () => currentUserId,
33
+ normalizeEmployeeUsername: () => normalizeEmployeeUsername,
34
+ normalizePlanKey: () => normalizePlanKey,
35
+ normalizeStepType: () => normalizeStepType,
36
+ nowIso: () => nowIso,
37
+ resolveLeaderUsername: () => resolveLeaderUsername,
38
+ resolveMessageId: () => resolveMessageId,
39
+ resolveSessionId: () => resolveSessionId,
40
+ toPlain: () => toPlain,
41
+ trimText: () => trimText,
42
+ valuesFromCtx: () => valuesFromCtx
43
+ });
44
+ module.exports = __toCommonJS(ctx_utils_exports);
45
+ function toPlain(record) {
46
+ var _a;
47
+ return ((_a = record == null ? void 0 : record.toJSON) == null ? void 0 : _a.call(record)) || record;
48
+ }
49
+ function asObject(value) {
50
+ if (value && typeof value === "object" && !Array.isArray(value)) return value;
51
+ if (typeof value === "string" && value.trim()) {
52
+ try {
53
+ const parsed = JSON.parse(value);
54
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
55
+ } catch {
56
+ return {};
57
+ }
58
+ }
59
+ return {};
60
+ }
61
+ function asArray(value) {
62
+ return Array.isArray(value) ? value : [];
63
+ }
64
+ function trimText(value, max = 5e4) {
65
+ let text = "";
66
+ if (typeof value === "string") {
67
+ text = value;
68
+ } else if (value != null) {
69
+ try {
70
+ text = JSON.stringify(value);
71
+ } catch {
72
+ text = String(value);
73
+ }
74
+ }
75
+ return text.length > max ? `${text.slice(0, max)}
76
+ ...[truncated]` : text;
77
+ }
78
+ function currentUserId(ctx) {
79
+ var _a, _b, _c, _d;
80
+ return ((_b = (_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id) || ((_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.id);
81
+ }
82
+ function valuesFromCtx(ctx) {
83
+ var _a, _b, _c;
84
+ return ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.values) || ((_c = ctx == null ? void 0 : ctx.request) == null ? void 0 : _c.body) || {};
85
+ }
86
+ function normalizeEmployeeUsername(raw) {
87
+ if (!raw) return null;
88
+ if (typeof raw === "string") return raw;
89
+ return raw.username || raw.aiEmployeeUsername || raw.name || null;
90
+ }
91
+ function resolveSessionId(ctx, args) {
92
+ var _a, _b, _c;
93
+ const v = valuesFromCtx(ctx);
94
+ return (args == null ? void 0 : args.sessionId) || v.sessionId || ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.sessionId) || ((_c = ctx == null ? void 0 : ctx.state) == null ? void 0 : _c.sessionId);
95
+ }
96
+ function resolveMessageId(ctx, args) {
97
+ var _a, _b;
98
+ const v = valuesFromCtx(ctx);
99
+ return (args == null ? void 0 : args.messageId) || v.messageId || ((_b = (_a = ctx == null ? void 0 : ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.messageId);
100
+ }
101
+ async function resolveLeaderUsername(ctx, plugin, args) {
102
+ var _a, _b, _c, _d, _e, _f;
103
+ const v = valuesFromCtx(ctx);
104
+ const direct = normalizeEmployeeUsername(
105
+ (args == null ? void 0 : args.leaderUsername) || (ctx == null ? void 0 : ctx._currentAIEmployee) || ((_a = ctx == null ? void 0 : ctx.state) == null ? void 0 : _a.currentAIEmployee) || ((_c = (_b = ctx == null ? void 0 : ctx.runtime) == null ? void 0 : _b.context) == null ? void 0 : _c.currentAIEmployee) || v.aiEmployee
106
+ );
107
+ if (direct) return direct;
108
+ const sessionId = resolveSessionId(ctx, args);
109
+ if (!sessionId) return void 0;
110
+ try {
111
+ const repo = ((_e = (_d = ctx == null ? void 0 : ctx.db) == null ? void 0 : _d.getRepository) == null ? void 0 : _e.call(_d, "aiConversations")) || plugin.db.getRepository("aiConversations");
112
+ const conversation = await repo.findOne({ filter: { sessionId } });
113
+ return normalizeEmployeeUsername((conversation == null ? void 0 : conversation.aiEmployeeUsername) || ((_f = conversation == null ? void 0 : conversation.get) == null ? void 0 : _f.call(conversation, "aiEmployeeUsername")));
114
+ } catch {
115
+ return void 0;
116
+ }
117
+ }
118
+ function captureCtxSnapshot(ctx) {
119
+ var _a, _b, _c, _d;
120
+ let userId;
121
+ try {
122
+ userId = ((_b = (_a = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id) || ((_d = (_c = ctx == null ? void 0 : ctx.state) == null ? void 0 : _c.currentUser) == null ? void 0 : _d.id);
123
+ } catch {
124
+ }
125
+ return { userId };
126
+ }
127
+ function normalizeStepType(value) {
128
+ return ["reasoning", "skill", "tool", "sub_agent", "verification"].includes(value) ? value : "tool";
129
+ }
130
+ function normalizePlanKey(step, index) {
131
+ return String(step.planKey || step.key || step.id || `step_${index + 1}`);
132
+ }
133
+ function nowIso() {
134
+ return (/* @__PURE__ */ new Date()).toISOString();
135
+ }
136
+ // Annotate the CommonJS export names for ESM import in node:
137
+ 0 && (module.exports = {
138
+ asArray,
139
+ asObject,
140
+ captureCtxSnapshot,
141
+ currentUserId,
142
+ normalizeEmployeeUsername,
143
+ normalizePlanKey,
144
+ normalizeStepType,
145
+ nowIso,
146
+ resolveLeaderUsername,
147
+ resolveMessageId,
148
+ resolveSessionId,
149
+ toPlain,
150
+ trimText,
151
+ valuesFromCtx
152
+ });
@@ -0,0 +1,6 @@
1
+ import { DelegationLogData } from '../types';
2
+ /**
3
+ * Log (or update) a delegation event in the orchestratorLogs collection.
4
+ * Used by both delegate-task.ts and AgentHarness.ts.
5
+ */
6
+ export declare function logDelegation(ctx: any, plugin: any, data: DelegationLogData): Promise<any>;
@@ -0,0 +1,86 @@
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 logging_exports = {};
28
+ __export(logging_exports, {
29
+ logDelegation: () => logDelegation
30
+ });
31
+ module.exports = __toCommonJS(logging_exports);
32
+ var import_ctx_utils = require("./ctx-utils");
33
+ async function logDelegation(ctx, plugin, data) {
34
+ var _a, _b, _c, _d, _e, _f, _g, _h;
35
+ try {
36
+ const logsRepo = plugin.db.getRepository("orchestratorLogs");
37
+ if (!logsRepo) {
38
+ (_b = (_a = plugin.app.log) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "[AgentOrchestrator] orchestratorLogs repository not found \u2014 skipping log");
39
+ return null;
40
+ }
41
+ let userId = data.userId;
42
+ if (userId == null) {
43
+ try {
44
+ userId = ((_d = (_c = ctx == null ? void 0 : ctx.auth) == null ? void 0 : _c.user) == null ? void 0 : _d.id) || ((_f = (_e = ctx == null ? void 0 : ctx.state) == null ? void 0 : _e.currentUser) == null ? void 0 : _f.id);
45
+ } catch {
46
+ }
47
+ }
48
+ const values = {
49
+ leaderUsername: data.leaderUsername,
50
+ subAgentUsername: data.subAgentUsername,
51
+ toolName: data.toolName,
52
+ task: (0, import_ctx_utils.trimText)(data.task, 1e4),
53
+ context: (0, import_ctx_utils.trimText)(data.context || "", 1e4),
54
+ result: (0, import_ctx_utils.trimText)(data.result || "", 5e4),
55
+ status: data.status,
56
+ depth: data.depth,
57
+ durationMs: data.durationMs,
58
+ error: (0, import_ctx_utils.trimText)(data.error || "", 1e4),
59
+ trace: data.trace || [],
60
+ messages: data.messages || [],
61
+ userId,
62
+ updatedAt: /* @__PURE__ */ new Date()
63
+ };
64
+ if (data.id) {
65
+ await logsRepo.update({
66
+ filterByTk: data.id,
67
+ values
68
+ });
69
+ return { id: data.id };
70
+ }
71
+ const record = await logsRepo.create({
72
+ values: {
73
+ ...values,
74
+ createdAt: /* @__PURE__ */ new Date()
75
+ }
76
+ });
77
+ return (0, import_ctx_utils.toPlain)(record);
78
+ } catch (e) {
79
+ (_h = (_g = plugin.app.log) == null ? void 0 : _g.warn) == null ? void 0 : _h.call(_g, "[AgentOrchestrator] Failed to log delegation event", e);
80
+ return null;
81
+ }
82
+ }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ logDelegation
86
+ });
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "plugin-agent-orchestrator",
3
- "displayName": "Agent Orchestrator",
4
- "displayName.zh-CN": "代理协调器",
5
- "displayName.vi-VN": "Điều phối Agent",
6
- "description": "Hierarchical Multi-Agent orchestration for NocoBase AI Employees. Enables Leader agents to delegate tasks to Sub-Agent employees without modifying core plugin-ai.",
7
- "version": "1.0.20",
8
- "license": "Apache-2.0",
9
- "main": "dist/server/index.js",
10
- "keywords": [
11
- "AI",
12
- "Agent",
13
- "Orchestrator",
14
- "Multi-Agent",
15
- "Swarm"
16
- ],
17
- "files": [
18
- "dist",
19
- "src",
20
- "client.js",
21
- "server.js",
22
- "client.d.ts",
23
- "server.d.ts"
24
- ],
25
- "nocobase": {
26
- "supportedVersions": [
27
- "2.x"
28
- ],
29
- "editionLevel": 0
30
- },
31
- "dependencies": {
32
- "@langchain/core": "^0.3.0",
33
- "@langchain/langgraph": "^0.2.0",
34
- "adm-zip": "^0.5.10",
35
- "simple-git": "^3.22.0",
36
- "zod": "^3.23.0"
37
- },
38
- "peerDependencies": {
39
- "@nocobase/client": "2.x",
40
- "@nocobase/server": "2.x",
41
- "@nocobase/database": "2.x",
42
- "@nocobase/ai": "2.x",
43
- "@nocobase/plugin-ai": "2.x"
44
- }
1
+ {
2
+ "name": "plugin-agent-orchestrator",
3
+ "displayName": "Agent Orchestrator",
4
+ "displayName.zh-CN": "代理协调器",
5
+ "displayName.vi-VN": "Điều phối Agent",
6
+ "description": "Hierarchical Multi-Agent orchestration for NocoBase AI Employees. Enables Leader agents to delegate tasks to Sub-Agent employees without modifying core plugin-ai.",
7
+ "version": "1.0.21",
8
+ "license": "Apache-2.0",
9
+ "main": "dist/server/index.js",
10
+ "keywords": [
11
+ "AI",
12
+ "Agent",
13
+ "Orchestrator",
14
+ "Multi-Agent",
15
+ "Swarm"
16
+ ],
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "client.js",
21
+ "server.js",
22
+ "client.d.ts",
23
+ "server.d.ts"
24
+ ],
25
+ "nocobase": {
26
+ "supportedVersions": [
27
+ "2.x"
28
+ ],
29
+ "editionLevel": 0
30
+ },
31
+ "dependencies": {
32
+ "@langchain/core": "^0.3.0",
33
+ "@langchain/langgraph": "^0.2.0",
34
+ "adm-zip": "^0.5.10",
35
+ "simple-git": "^3.22.0",
36
+ "zod": "^3.23.0"
37
+ },
38
+ "peerDependencies": {
39
+ "@nocobase/client": "2.x",
40
+ "@nocobase/server": "2.x",
41
+ "@nocobase/database": "2.x",
42
+ "@nocobase/ai": "2.x",
43
+ "@nocobase/plugin-ai": "2.x"
44
+ }
45
45
  }