plugin-agent-orchestrator 1.0.16 → 1.0.18

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 (92) hide show
  1. package/dist/client/AgentRunsTab.d.ts +2 -0
  2. package/dist/client/HarnessProfilesTab.d.ts +2 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client/skill-hub/components/LoopSettings.d.ts +2 -0
  5. package/dist/client/skill-hub/index.d.ts +2 -1
  6. package/dist/client/skill-hub/tools/InteractionSchemasProvider.d.ts +1 -14
  7. package/dist/client/skill-hub/tools/loopTemplates.d.ts +22 -0
  8. package/dist/client/skill-hub/tools/registerSkillLoopCards.d.ts +1 -0
  9. package/dist/client/tools/PlanApprovalCard.d.ts +3 -0
  10. package/dist/client/tools/registerOrchestratorCards.d.ts +1 -0
  11. package/dist/externalVersion.js +6 -6
  12. package/dist/server/collections/agent-harness-profiles.d.ts +2 -0
  13. package/dist/server/collections/agent-harness-profiles.js +89 -0
  14. package/dist/server/collections/agent-loop-events.d.ts +2 -0
  15. package/dist/server/collections/agent-loop-events.js +101 -0
  16. package/dist/server/collections/agent-loop-runs.d.ts +2 -0
  17. package/dist/server/collections/agent-loop-runs.js +188 -0
  18. package/dist/server/collections/agent-loop-steps.d.ts +2 -0
  19. package/dist/server/collections/agent-loop-steps.js +174 -0
  20. package/dist/server/collections/orchestrator-config.js +7 -0
  21. package/dist/server/collections/skill-executions.js +12 -0
  22. package/dist/server/collections/skill-loop-configs.d.ts +3 -0
  23. package/dist/server/collections/skill-loop-configs.js +94 -0
  24. package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.d.ts +7 -0
  25. package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +55 -0
  26. package/dist/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.d.ts +12 -0
  27. package/dist/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.js +162 -0
  28. package/dist/server/plugin.d.ts +2 -0
  29. package/dist/server/plugin.js +13 -0
  30. package/dist/server/resources/agent-loop.d.ts +3 -0
  31. package/dist/server/resources/agent-loop.js +205 -0
  32. package/dist/server/services/AgentHarness.d.ts +42 -0
  33. package/dist/server/services/AgentHarness.js +565 -0
  34. package/dist/server/services/AgentLoopController.d.ts +205 -0
  35. package/dist/server/services/AgentLoopController.js +940 -0
  36. package/dist/server/services/AgentLoopRepository.d.ts +20 -0
  37. package/dist/server/services/AgentLoopRepository.js +210 -0
  38. package/dist/server/services/AgentLoopService.d.ts +149 -0
  39. package/dist/server/services/AgentLoopService.js +133 -0
  40. package/dist/server/services/AgentPlanValidator.d.ts +4 -0
  41. package/dist/server/services/AgentPlanValidator.js +99 -0
  42. package/dist/server/services/AgentPlannerService.d.ts +8 -0
  43. package/dist/server/services/AgentPlannerService.js +119 -0
  44. package/dist/server/services/AgentRegistryService.d.ts +13 -0
  45. package/dist/server/services/AgentRegistryService.js +178 -0
  46. package/dist/server/services/ExecutionSpanService.d.ts +2 -0
  47. package/dist/server/skill-hub/plugin.d.ts +3 -0
  48. package/dist/server/skill-hub/plugin.js +137 -54
  49. package/dist/server/tools/agent-loop.d.ts +235 -0
  50. package/dist/server/tools/agent-loop.js +406 -0
  51. package/dist/server/tools/delegate-task.js +37 -350
  52. package/dist/server/tools/orchestrator-plan.d.ts +205 -0
  53. package/dist/server/tools/orchestrator-plan.js +291 -0
  54. package/dist/server/tools/skill-execute.js +2 -0
  55. package/package.json +2 -2
  56. package/src/client/AgentRunsTab.tsx +764 -0
  57. package/src/client/HarnessProfilesTab.tsx +247 -0
  58. package/src/client/OrchestratorSettings.tsx +40 -2
  59. package/src/client/RulesTab.tsx +103 -6
  60. package/src/client/plugin.tsx +27 -54
  61. package/src/client/skill-hub/components/LoopSettings.tsx +331 -0
  62. package/src/client/skill-hub/index.tsx +51 -75
  63. package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +56 -16
  64. package/src/client/skill-hub/tools/SkillHubCard.tsx +35 -4
  65. package/src/client/skill-hub/tools/loopTemplates.ts +52 -0
  66. package/src/client/skill-hub/tools/registerSkillLoopCards.ts +58 -0
  67. package/src/client/tools/PlanApprovalCard.tsx +175 -0
  68. package/src/client/tools/registerOrchestratorCards.ts +7 -0
  69. package/src/server/collections/agent-harness-profiles.ts +59 -0
  70. package/src/server/collections/agent-loop-events.ts +71 -0
  71. package/src/server/collections/agent-loop-runs.ts +158 -0
  72. package/src/server/collections/agent-loop-steps.ts +144 -0
  73. package/src/server/collections/orchestrator-config.ts +7 -0
  74. package/src/server/collections/skill-executions.ts +63 -51
  75. package/src/server/collections/skill-loop-configs.ts +65 -0
  76. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +30 -0
  77. package/src/server/migrations/20260524001000-add-plan-approval-and-harness-profiles.ts +142 -0
  78. package/src/server/plugin.ts +15 -0
  79. package/src/server/resources/agent-loop.ts +183 -0
  80. package/src/server/services/AgentHarness.ts +663 -0
  81. package/src/server/services/AgentLoopController.ts +1128 -0
  82. package/src/server/services/AgentLoopRepository.ts +194 -0
  83. package/src/server/services/AgentLoopService.ts +161 -0
  84. package/src/server/services/AgentPlanValidator.ts +73 -0
  85. package/src/server/services/AgentPlannerService.ts +93 -0
  86. package/src/server/services/AgentRegistryService.ts +169 -0
  87. package/src/server/services/ExecutionSpanService.ts +2 -0
  88. package/src/server/skill-hub/plugin.ts +881 -771
  89. package/src/server/tools/agent-loop.ts +399 -0
  90. package/src/server/tools/delegate-task.ts +48 -463
  91. package/src/server/tools/orchestrator-plan.ts +279 -0
  92. package/src/server/tools/skill-execute.ts +68 -64
@@ -0,0 +1,20 @@
1
+ export declare class AgentLoopRepository {
2
+ private readonly plugin;
3
+ constructor(plugin: any);
4
+ get db(): any;
5
+ getRun(runId: string | number): Promise<any>;
6
+ requireRun(runId: string | number): Promise<any>;
7
+ createRun(values: any): Promise<any>;
8
+ updateRun(runId: string | number, values: any): Promise<void>;
9
+ getStep(stepId: string | number): Promise<any>;
10
+ requireStep(stepId: string | number): Promise<any>;
11
+ createStep(values: any): Promise<any>;
12
+ updateStep(stepId: string | number, values: any): Promise<void>;
13
+ getSteps(runId: string | number): Promise<any>;
14
+ createEvent(values: any): Promise<any>;
15
+ getEvents(runId: string | number): Promise<any>;
16
+ getLinkedSpans(runId: string | number, rootRunId?: string): Promise<any>;
17
+ getLinkedSkillExecutions(runId: string | number, steps: any[]): Promise<any>;
18
+ lockRun(runId: string | number, lockName: string, durationMs: number): Promise<boolean>;
19
+ unlockRun(runId: string | number): Promise<void>;
20
+ }
@@ -0,0 +1,210 @@
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 AgentLoopRepository_exports = {};
28
+ __export(AgentLoopRepository_exports, {
29
+ AgentLoopRepository: () => AgentLoopRepository
30
+ });
31
+ module.exports = __toCommonJS(AgentLoopRepository_exports);
32
+ function toPlain(record) {
33
+ var _a;
34
+ return ((_a = record == null ? void 0 : record.toJSON) == null ? void 0 : _a.call(record)) || record;
35
+ }
36
+ function trimText(value, max = 5e4) {
37
+ let text = "";
38
+ if (typeof value === "string") {
39
+ text = value;
40
+ } else if (value != null) {
41
+ try {
42
+ text = JSON.stringify(value);
43
+ } catch {
44
+ text = String(value);
45
+ }
46
+ }
47
+ return text.length > max ? `${text.slice(0, max)}
48
+ ...[truncated]` : text;
49
+ }
50
+ class AgentLoopRepository {
51
+ constructor(plugin) {
52
+ this.plugin = plugin;
53
+ }
54
+ get db() {
55
+ return this.plugin.db;
56
+ }
57
+ async getRun(runId) {
58
+ const run = await this.db.getRepository("agentLoopRuns").findOne({
59
+ filter: { id: runId }
60
+ });
61
+ return run ? toPlain(run) : null;
62
+ }
63
+ async requireRun(runId) {
64
+ const run = await this.getRun(runId);
65
+ if (!run) {
66
+ throw new Error(`Agent loop run "${runId}" was not found.`);
67
+ }
68
+ return run;
69
+ }
70
+ async createRun(values) {
71
+ const run = await this.db.getRepository("agentLoopRuns").create({
72
+ values
73
+ });
74
+ return toPlain(run);
75
+ }
76
+ async updateRun(runId, values) {
77
+ await this.db.getRepository("agentLoopRuns").update({
78
+ filterByTk: runId,
79
+ values
80
+ });
81
+ }
82
+ async getStep(stepId) {
83
+ const step = await this.db.getRepository("agentLoopSteps").findOne({
84
+ filter: { id: stepId }
85
+ });
86
+ return step ? toPlain(step) : null;
87
+ }
88
+ async requireStep(stepId) {
89
+ const step = await this.getStep(stepId);
90
+ if (!step) {
91
+ throw new Error(`Agent loop step "${stepId}" was not found.`);
92
+ }
93
+ return step;
94
+ }
95
+ async createStep(values) {
96
+ const step = await this.db.getRepository("agentLoopSteps").create({
97
+ values
98
+ });
99
+ return toPlain(step);
100
+ }
101
+ async updateStep(stepId, values) {
102
+ await this.db.getRepository("agentLoopSteps").update({
103
+ filterByTk: stepId,
104
+ values
105
+ });
106
+ }
107
+ async getSteps(runId) {
108
+ const steps = await this.db.getRepository("agentLoopSteps").find({
109
+ filter: { runId },
110
+ sort: ["index", "createdAt"],
111
+ pageSize: 1e3
112
+ });
113
+ return steps.map(toPlain);
114
+ }
115
+ async createEvent(values) {
116
+ const record = await this.db.getRepository("agentLoopEvents").create({
117
+ values: {
118
+ ...values,
119
+ content: trimText(values.content || "", 1e4),
120
+ payload: values.payload || {},
121
+ createdAt: /* @__PURE__ */ new Date()
122
+ }
123
+ });
124
+ return toPlain(record);
125
+ }
126
+ async getEvents(runId) {
127
+ const events = await this.db.getRepository("agentLoopEvents").find({
128
+ filter: { runId },
129
+ sort: ["createdAt"],
130
+ pageSize: 500
131
+ });
132
+ return events.map(toPlain);
133
+ }
134
+ async getLinkedSpans(runId, rootRunId) {
135
+ const repo = this.db.getRepository("agentExecutionSpans");
136
+ if (!repo) return [];
137
+ const filters = [];
138
+ if (rootRunId) filters.push({ rootRunId });
139
+ filters.push({ "metadata.agentLoopRunId": String(runId) });
140
+ try {
141
+ const rows = await repo.find({
142
+ filter: { $or: filters },
143
+ sort: ["createdAt"],
144
+ pageSize: 1e3
145
+ });
146
+ return rows.map(toPlain);
147
+ } catch {
148
+ if (!rootRunId) return [];
149
+ const rows = await repo.find({
150
+ filter: { rootRunId },
151
+ sort: ["createdAt"],
152
+ pageSize: 1e3
153
+ });
154
+ return rows.map(toPlain);
155
+ }
156
+ }
157
+ async getLinkedSkillExecutions(runId, steps) {
158
+ const ids = Array.from(
159
+ new Set(
160
+ steps.map((step) => step.skillExecutionId).filter(Boolean).map(String)
161
+ )
162
+ );
163
+ const repo = this.db.getRepository("skillExecutions");
164
+ if (!repo) return [];
165
+ const filters = [{ agentLoopRunId: String(runId) }];
166
+ if (ids.length) {
167
+ filters.push({ id: { $in: ids } });
168
+ }
169
+ const rows = await repo.find({
170
+ filter: { $or: filters },
171
+ sort: ["createdAt"],
172
+ pageSize: 1e3
173
+ });
174
+ return rows.map(toPlain);
175
+ }
176
+ async lockRun(runId, lockName, durationMs) {
177
+ const repo = this.db.getRepository("agentLoopRuns");
178
+ if (!repo) return false;
179
+ const now = /* @__PURE__ */ new Date();
180
+ const Op = repo.model.sequelize.Sequelize.Op;
181
+ const result = await repo.model.update(
182
+ {
183
+ lockedBy: lockName,
184
+ lockedUntil: new Date(now.getTime() + durationMs)
185
+ },
186
+ {
187
+ where: {
188
+ id: runId,
189
+ [Op.or]: [
190
+ { lockedBy: null },
191
+ { lockedUntil: { [Op.lt]: now.toISOString() } },
192
+ { lockedBy: lockName }
193
+ ]
194
+ }
195
+ }
196
+ );
197
+ const affectedCount = Array.isArray(result) ? result[0] : Number(result || 0);
198
+ return affectedCount > 0;
199
+ }
200
+ async unlockRun(runId) {
201
+ await this.updateRun(runId, {
202
+ lockedBy: null,
203
+ lockedUntil: null
204
+ });
205
+ }
206
+ }
207
+ // Annotate the CommonJS export names for ESM import in node:
208
+ 0 && (module.exports = {
209
+ AgentLoopRepository
210
+ });
@@ -0,0 +1,149 @@
1
+ import { AgentRegistryService } from './AgentRegistryService';
2
+ import { AgentPlannerService } from './AgentPlannerService';
3
+ import { AgentPlanValidator } from './AgentPlanValidator';
4
+ import { AgentLoopRepository } from './AgentLoopRepository';
5
+ import { AgentHarness } from './AgentHarness';
6
+ import { AgentLoopController } from './AgentLoopController';
7
+ export type AgentLoopRunStatus = 'planning' | 'waiting_plan_approval' | 'approved' | 'running' | 'waiting_user' | 'needs_replan' | 'succeeded' | 'failed' | 'rejected' | 'canceled';
8
+ export type AgentLoopStepStatus = 'pending' | 'running' | 'waiting_user' | 'succeeded' | 'failed' | 'skipped';
9
+ export type AgentLoopStepType = 'reasoning' | 'skill' | 'tool' | 'sub_agent' | 'verification';
10
+ export type AgentLoopStepDependencyPolicy = 'require_success' | 'allow_skipped';
11
+ export type AgentLoopPolicy = {
12
+ maxIterations: number;
13
+ maxStepAttempts: number;
14
+ allowReplan: boolean;
15
+ requireVerification: boolean;
16
+ stopOnApprovalRequired: boolean;
17
+ };
18
+ export type AgentLoopPlanStepInput = {
19
+ id?: string;
20
+ key?: string;
21
+ planKey?: string;
22
+ parentStepId?: string | number;
23
+ title?: string;
24
+ description?: string;
25
+ type?: AgentLoopStepType;
26
+ target?: string;
27
+ input?: any;
28
+ dependsOn?: string[];
29
+ dependencyPolicy?: AgentLoopStepDependencyPolicy;
30
+ maxAttempts?: number;
31
+ metadata?: any;
32
+ };
33
+ export declare class AgentLoopService {
34
+ private readonly plugin;
35
+ readonly registryService: AgentRegistryService;
36
+ readonly plannerService: AgentPlannerService;
37
+ readonly validator: AgentPlanValidator;
38
+ readonly repository: AgentLoopRepository;
39
+ readonly harness: AgentHarness;
40
+ readonly controller: AgentLoopController;
41
+ constructor(plugin: any);
42
+ get db(): any;
43
+ get app(): any;
44
+ createRun(options: any): Promise<{
45
+ run: any;
46
+ steps: any;
47
+ nextStep: any;
48
+ }>;
49
+ planGoal(options: any): Promise<{
50
+ events: any;
51
+ spans: any;
52
+ skillExecutions: any;
53
+ run: any;
54
+ steps: any;
55
+ nextStep: any;
56
+ }>;
57
+ revisePlanGoal(runId: any, plan: any, options?: any): Promise<{
58
+ events: any;
59
+ spans: any;
60
+ skillExecutions: any;
61
+ run: any;
62
+ steps: any;
63
+ nextStep: any;
64
+ }>;
65
+ approvePlanAndExecute(runId: any, options?: any): Promise<{
66
+ run: any;
67
+ steps: any;
68
+ nextStep: any;
69
+ }>;
70
+ rejectPlan(runId: any, options?: any): Promise<{
71
+ run: any;
72
+ steps: any;
73
+ nextStep: any;
74
+ }>;
75
+ requestPlanChanges(runId: any, options?: any): Promise<{
76
+ events: any;
77
+ spans: any;
78
+ skillExecutions: any;
79
+ run: any;
80
+ steps: any;
81
+ nextStep: any;
82
+ }>;
83
+ replacePlan(runId: any, plan: any, options?: any): Promise<any[]>;
84
+ replan(runId: any, plan: any, options?: any): Promise<any[]>;
85
+ startStep(stepId: any, options?: any): Promise<{
86
+ run: any;
87
+ steps: any;
88
+ nextStep: any;
89
+ }>;
90
+ completeStep(stepId: any, output: any, options?: any): Promise<{
91
+ run: any;
92
+ steps: any;
93
+ nextStep: any;
94
+ }>;
95
+ failStep(stepId: any, error: any, options?: any): Promise<{
96
+ run: any;
97
+ steps: any;
98
+ nextStep: any;
99
+ }>;
100
+ skipStep(stepId: any, reason?: any, options?: any): Promise<{
101
+ run: any;
102
+ steps: any;
103
+ nextStep: any;
104
+ }>;
105
+ requestApproval(stepId: any, approval: any, options?: any): Promise<{
106
+ run: any;
107
+ steps: any;
108
+ nextStep: any;
109
+ }>;
110
+ resumeRun(runId: any, options: any): Promise<{
111
+ run: any;
112
+ steps: any;
113
+ nextStep: any;
114
+ }>;
115
+ retryStep(stepId: any, options?: any): Promise<{
116
+ run: any;
117
+ steps: any;
118
+ nextStep: any;
119
+ }>;
120
+ finishRun(runId: any, finalAnswer: any, options?: any): Promise<{
121
+ run: any;
122
+ steps: any;
123
+ nextStep: any;
124
+ }>;
125
+ cancelRun(runId: any, options?: any): Promise<{
126
+ run: any;
127
+ steps: any;
128
+ nextStep: any;
129
+ }>;
130
+ executeApprovedPlan(runId: any, options?: any): Promise<{
131
+ run: any;
132
+ steps: any;
133
+ nextStep: any;
134
+ }>;
135
+ getRunSnapshot(runId: any): Promise<{
136
+ run: any;
137
+ steps: any;
138
+ nextStep: any;
139
+ }>;
140
+ getRunDetail(runId: any): Promise<{
141
+ events: any;
142
+ spans: any;
143
+ skillExecutions: any;
144
+ run: any;
145
+ steps: any;
146
+ nextStep: any;
147
+ }>;
148
+ createEvent(values: any): Promise<any>;
149
+ }
@@ -0,0 +1,133 @@
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 AgentLoopService_exports = {};
28
+ __export(AgentLoopService_exports, {
29
+ AgentLoopService: () => AgentLoopService
30
+ });
31
+ module.exports = __toCommonJS(AgentLoopService_exports);
32
+ var import_AgentRegistryService = require("./AgentRegistryService");
33
+ var import_AgentPlannerService = require("./AgentPlannerService");
34
+ var import_AgentPlanValidator = require("./AgentPlanValidator");
35
+ var import_AgentLoopRepository = require("./AgentLoopRepository");
36
+ var import_AgentHarness = require("./AgentHarness");
37
+ var import_AgentLoopController = require("./AgentLoopController");
38
+ class AgentLoopService {
39
+ constructor(plugin) {
40
+ this.plugin = plugin;
41
+ this.registryService = new import_AgentRegistryService.AgentRegistryService(plugin);
42
+ this.plannerService = new import_AgentPlannerService.AgentPlannerService();
43
+ this.validator = new import_AgentPlanValidator.AgentPlanValidator();
44
+ this.repository = new import_AgentLoopRepository.AgentLoopRepository(plugin);
45
+ this.harness = new import_AgentHarness.AgentHarness(plugin, this.registryService);
46
+ this.controller = new import_AgentLoopController.AgentLoopController(
47
+ this.registryService,
48
+ this.plannerService,
49
+ this.validator,
50
+ this.repository,
51
+ this.harness
52
+ );
53
+ }
54
+ registryService;
55
+ plannerService;
56
+ validator;
57
+ repository;
58
+ harness;
59
+ controller;
60
+ get db() {
61
+ return this.plugin.db;
62
+ }
63
+ get app() {
64
+ return this.plugin.app;
65
+ }
66
+ async createRun(options) {
67
+ return this.controller.createRun(options);
68
+ }
69
+ async planGoal(options) {
70
+ return this.controller.planGoal(options);
71
+ }
72
+ async revisePlanGoal(runId, plan, options = {}) {
73
+ return this.controller.revisePlanGoal(runId, plan, options);
74
+ }
75
+ async approvePlanAndExecute(runId, options = {}) {
76
+ return this.controller.approvePlanAndExecute(runId, options);
77
+ }
78
+ async rejectPlan(runId, options = {}) {
79
+ return this.controller.rejectPlan(runId, options);
80
+ }
81
+ async requestPlanChanges(runId, options = {}) {
82
+ return this.controller.requestPlanChanges(runId, options);
83
+ }
84
+ async replacePlan(runId, plan, options = {}) {
85
+ return this.controller.replacePlan(runId, plan, options);
86
+ }
87
+ async replan(runId, plan, options = {}) {
88
+ return this.controller.replan(runId, plan, options);
89
+ }
90
+ async startStep(stepId, options = {}) {
91
+ return this.controller.startStep(stepId, options);
92
+ }
93
+ async completeStep(stepId, output, options = {}) {
94
+ return this.controller.completeStep(stepId, output, options);
95
+ }
96
+ async failStep(stepId, error, options = {}) {
97
+ return this.controller.failStep(stepId, error, options);
98
+ }
99
+ async skipStep(stepId, reason = "Skipped", options = {}) {
100
+ return this.controller.skipStep(stepId, reason, options);
101
+ }
102
+ async requestApproval(stepId, approval, options = {}) {
103
+ return this.controller.requestApproval(stepId, approval, options);
104
+ }
105
+ async resumeRun(runId, options) {
106
+ return this.controller.resumeRun(runId, options);
107
+ }
108
+ async retryStep(stepId, options = {}) {
109
+ return this.controller.retryStep(stepId, options);
110
+ }
111
+ async finishRun(runId, finalAnswer, options = {}) {
112
+ return this.controller.finishRun(runId, finalAnswer, options);
113
+ }
114
+ async cancelRun(runId, options = {}) {
115
+ return this.controller.cancelRun(runId, options);
116
+ }
117
+ async executeApprovedPlan(runId, options = {}) {
118
+ return this.controller.executeApprovedPlan(runId, options);
119
+ }
120
+ async getRunSnapshot(runId) {
121
+ return this.controller.getRunSnapshot(runId);
122
+ }
123
+ async getRunDetail(runId) {
124
+ return this.controller.getRunDetail(runId);
125
+ }
126
+ async createEvent(values) {
127
+ return this.repository.createEvent(values);
128
+ }
129
+ }
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ AgentLoopService
133
+ });
@@ -0,0 +1,4 @@
1
+ import { AgentLoopPlanStepInput } from './AgentLoopService';
2
+ export declare class AgentPlanValidator {
3
+ validate(plan: AgentLoopPlanStepInput[]): void;
4
+ }
@@ -0,0 +1,99 @@
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 AgentPlanValidator_exports = {};
28
+ __export(AgentPlanValidator_exports, {
29
+ AgentPlanValidator: () => AgentPlanValidator
30
+ });
31
+ module.exports = __toCommonJS(AgentPlanValidator_exports);
32
+ function normalizeStepType(value) {
33
+ return ["reasoning", "skill", "tool", "sub_agent", "verification"].includes(value) ? value : "tool";
34
+ }
35
+ function normalizePlanKey(step, index) {
36
+ return String(step.planKey || step.key || step.id || `step_${index + 1}`);
37
+ }
38
+ function asArray(value) {
39
+ return Array.isArray(value) ? value : [];
40
+ }
41
+ const ORCHESTRATOR_CONTROLLER_MAX_STEPS = 100;
42
+ class AgentPlanValidator {
43
+ validate(plan) {
44
+ if (!Array.isArray(plan) || plan.length === 0) {
45
+ throw new Error("Plan must include at least one step.");
46
+ }
47
+ if (plan.length > ORCHESTRATOR_CONTROLLER_MAX_STEPS) {
48
+ throw new Error(`Plan cannot exceed ${ORCHESTRATOR_CONTROLLER_MAX_STEPS} steps.`);
49
+ }
50
+ const keys = /* @__PURE__ */ new Set();
51
+ const graph = /* @__PURE__ */ new Map();
52
+ for (let i = 0; i < plan.length; i++) {
53
+ const key = normalizePlanKey(plan[i], i).trim();
54
+ if (!key) {
55
+ throw new Error(`Plan step ${i + 1} has an empty planKey.`);
56
+ }
57
+ if (keys.has(key)) {
58
+ throw new Error(`Duplicate planKey "${key}" in plan.`);
59
+ }
60
+ const type = normalizeStepType(plan[i].type);
61
+ if (["tool", "skill", "sub_agent"].includes(type) && !plan[i].target) {
62
+ throw new Error(`Step "${key}" of type "${type}" must include a target.`);
63
+ }
64
+ keys.add(key);
65
+ graph.set(key, asArray(plan[i].dependsOn).map(String));
66
+ }
67
+ for (const [key, dependencies] of graph.entries()) {
68
+ for (const dependency of dependencies) {
69
+ if (!keys.has(dependency)) {
70
+ throw new Error(`Step "${key}" depends on unknown step "${dependency}".`);
71
+ }
72
+ if (dependency === key) {
73
+ throw new Error(`Step "${key}" cannot depend on itself.`);
74
+ }
75
+ }
76
+ }
77
+ const visiting = /* @__PURE__ */ new Set();
78
+ const visited = /* @__PURE__ */ new Set();
79
+ const visit = (key) => {
80
+ if (visited.has(key)) return;
81
+ if (visiting.has(key)) {
82
+ throw new Error(`Plan has a dependency cycle at "${key}".`);
83
+ }
84
+ visiting.add(key);
85
+ for (const dependency of graph.get(key) || []) {
86
+ visit(dependency);
87
+ }
88
+ visiting.delete(key);
89
+ visited.add(key);
90
+ };
91
+ for (const key of graph.keys()) {
92
+ visit(key);
93
+ }
94
+ }
95
+ }
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ AgentPlanValidator
99
+ });
@@ -0,0 +1,8 @@
1
+ import { AgentLoopPlanStepInput } from './AgentLoopService';
2
+ export declare class AgentPlannerService {
3
+ buildPlan(goal: string, plan: AgentLoopPlanStepInput[] | undefined, options: {
4
+ targetAgent?: string;
5
+ harnessTag?: string;
6
+ metadata?: any;
7
+ }): AgentLoopPlanStepInput[];
8
+ }