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,3 @@
1
+ import { CollectionOptions } from '@nocobase/database';
2
+ declare const _default: CollectionOptions;
3
+ export default _default;
@@ -0,0 +1,94 @@
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 skill_loop_configs_exports = {};
28
+ __export(skill_loop_configs_exports, {
29
+ default: () => skill_loop_configs_default
30
+ });
31
+ module.exports = __toCommonJS(skill_loop_configs_exports);
32
+ var skill_loop_configs_default = {
33
+ name: "skillLoopConfigs",
34
+ title: "Skill Loop Configs",
35
+ fields: [
36
+ {
37
+ name: "id",
38
+ type: "bigInt",
39
+ autoIncrement: true,
40
+ primaryKey: true
41
+ },
42
+ {
43
+ name: "skill",
44
+ type: "belongsTo",
45
+ target: "skillDefinitions",
46
+ foreignKey: "skillId"
47
+ },
48
+ {
49
+ name: "enabled",
50
+ type: "boolean",
51
+ defaultValue: true
52
+ },
53
+ {
54
+ name: "title",
55
+ type: "string",
56
+ length: 200
57
+ },
58
+ {
59
+ name: "templateKey",
60
+ type: "string",
61
+ length: 80,
62
+ defaultValue: "confirm"
63
+ },
64
+ {
65
+ name: "prompt",
66
+ type: "text"
67
+ },
68
+ {
69
+ // Resolved interaction schema consumed by the generic Skill Hub UI card.
70
+ name: "schema",
71
+ type: "text"
72
+ },
73
+ {
74
+ // Optional template-specific state for future loop renderers.
75
+ name: "config",
76
+ type: "text",
77
+ defaultValue: null
78
+ },
79
+ {
80
+ name: "createdAt",
81
+ type: "date"
82
+ },
83
+ {
84
+ name: "updatedAt",
85
+ type: "date"
86
+ },
87
+ {
88
+ name: "createdBy",
89
+ type: "belongsTo",
90
+ target: "users",
91
+ foreignKey: "createdById"
92
+ }
93
+ ]
94
+ };
@@ -0,0 +1,7 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class AddAgentLoopFieldsToSkillExecutions extends Migration {
3
+ on: string;
4
+ appVersion: string;
5
+ up(): Promise<void>;
6
+ down(): Promise<void>;
7
+ }
@@ -0,0 +1,55 @@
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_agent_loop_fields_to_skill_executions_exports = {};
28
+ __export(add_agent_loop_fields_to_skill_executions_exports, {
29
+ default: () => AddAgentLoopFieldsToSkillExecutions
30
+ });
31
+ module.exports = __toCommonJS(add_agent_loop_fields_to_skill_executions_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class AddAgentLoopFieldsToSkillExecutions 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}skillExecutions`;
40
+ const tableExists = await queryInterface.tableExists(tableName).catch(() => false);
41
+ if (!tableExists) return;
42
+ const tableDesc = await queryInterface.describeTable(tableName);
43
+ const addIfMissing = async (name) => {
44
+ if (tableDesc[name]) return;
45
+ await queryInterface.addColumn(tableName, name, {
46
+ type: "VARCHAR(100)",
47
+ allowNull: true
48
+ });
49
+ };
50
+ await addIfMissing("agentLoopRunId");
51
+ await addIfMissing("agentLoopStepId");
52
+ }
53
+ async down() {
54
+ }
55
+ }
@@ -0,0 +1,12 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class AddPlanApprovalAndHarnessProfiles extends Migration {
3
+ on: string;
4
+ appVersion: string;
5
+ up(): Promise<void>;
6
+ addRunColumns(queryInterface: any, tableName: string): Promise<void>;
7
+ addStepColumns(queryInterface: any, tableName: string): Promise<void>;
8
+ addConfigColumns(queryInterface: any, tableName: string): Promise<void>;
9
+ ensureHarnessProfiles(queryInterface: any, tableName: string): Promise<void>;
10
+ seedDefaultProfiles(): Promise<void>;
11
+ down(): Promise<void>;
12
+ }
@@ -0,0 +1,162 @@
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_plan_approval_and_harness_profiles_exports = {};
28
+ __export(add_plan_approval_and_harness_profiles_exports, {
29
+ default: () => AddPlanApprovalAndHarnessProfiles
30
+ });
31
+ module.exports = __toCommonJS(add_plan_approval_and_harness_profiles_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var import_server = require("@nocobase/server");
34
+ class AddPlanApprovalAndHarnessProfiles extends import_server.Migration {
35
+ on = "afterLoad";
36
+ appVersion = ">=0.1.0";
37
+ async up() {
38
+ const db = this.db;
39
+ const queryInterface = db.sequelize.getQueryInterface();
40
+ const tablePrefix = db.options.tablePrefix || "";
41
+ await this.addRunColumns(queryInterface, `${tablePrefix}agentLoopRuns`);
42
+ await this.addStepColumns(queryInterface, `${tablePrefix}agentLoopSteps`);
43
+ await this.addConfigColumns(queryInterface, `${tablePrefix}orchestratorConfig`);
44
+ await this.ensureHarnessProfiles(queryInterface, `${tablePrefix}agentHarnessProfiles`);
45
+ await this.seedDefaultProfiles();
46
+ }
47
+ async addRunColumns(queryInterface, tableName) {
48
+ const tableExists = await queryInterface.tableExists(tableName).catch(() => false);
49
+ if (!tableExists) return;
50
+ const tableDesc = await queryInterface.describeTable(tableName);
51
+ const addIfMissing = async (name, spec) => {
52
+ if (tableDesc[name]) return;
53
+ await queryInterface.addColumn(tableName, name, spec);
54
+ };
55
+ await addIfMissing("approvalStatus", { type: import_database.DataTypes.STRING(30), allowNull: true, defaultValue: "none" });
56
+ await addIfMissing("approvedById", { type: import_database.DataTypes.BIGINT, allowNull: true });
57
+ await addIfMissing("approvedAt", { type: import_database.DataTypes.DATE, allowNull: true });
58
+ await addIfMissing("rejectionReason", { type: import_database.DataTypes.TEXT, allowNull: true });
59
+ await addIfMissing("changeRequest", { type: import_database.DataTypes.TEXT, allowNull: true });
60
+ await addIfMissing("planVersion", { type: import_database.DataTypes.INTEGER, allowNull: true, defaultValue: 1 });
61
+ await addIfMissing("planSource", { type: import_database.DataTypes.STRING(50), allowNull: true });
62
+ await addIfMissing("plannerModel", { type: import_database.DataTypes.STRING(100), allowNull: true });
63
+ await addIfMissing("lockedBy", { type: import_database.DataTypes.STRING(100), allowNull: true });
64
+ await addIfMissing("lockedUntil", { type: import_database.DataTypes.DATE, allowNull: true });
65
+ }
66
+ async addStepColumns(queryInterface, tableName) {
67
+ const tableExists = await queryInterface.tableExists(tableName).catch(() => false);
68
+ if (!tableExists) return;
69
+ const tableDesc = await queryInterface.describeTable(tableName);
70
+ if (!tableDesc.dependencyPolicy) {
71
+ await queryInterface.addColumn(tableName, "dependencyPolicy", {
72
+ type: import_database.DataTypes.STRING(30),
73
+ allowNull: true,
74
+ defaultValue: "require_success"
75
+ });
76
+ }
77
+ }
78
+ async addConfigColumns(queryInterface, tableName) {
79
+ const tableExists = await queryInterface.tableExists(tableName).catch(() => false);
80
+ if (!tableExists) return;
81
+ const tableDesc = await queryInterface.describeTable(tableName);
82
+ if (!tableDesc.harnessTag) {
83
+ await queryInterface.addColumn(tableName, "harnessTag", {
84
+ type: import_database.DataTypes.STRING(100),
85
+ allowNull: true,
86
+ defaultValue: "default"
87
+ });
88
+ }
89
+ }
90
+ async ensureHarnessProfiles(queryInterface, tableName) {
91
+ const tableExists = await queryInterface.tableExists(tableName).catch(() => false);
92
+ if (tableExists) return;
93
+ await queryInterface.createTable(tableName, {
94
+ id: { type: import_database.DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
95
+ tag: { type: import_database.DataTypes.STRING(100), allowNull: false, unique: true },
96
+ title: { type: import_database.DataTypes.STRING(200), allowNull: true },
97
+ description: { type: import_database.DataTypes.TEXT, allowNull: true },
98
+ enabled: { type: import_database.DataTypes.BOOLEAN, allowNull: true, defaultValue: true },
99
+ settings: { type: import_database.DataTypes.JSON, allowNull: true, defaultValue: {} },
100
+ createdAt: { type: import_database.DataTypes.DATE, allowNull: true },
101
+ updatedAt: { type: import_database.DataTypes.DATE, allowNull: true }
102
+ });
103
+ }
104
+ async seedDefaultProfiles() {
105
+ const repo = this.db.getRepository("agentHarnessProfiles");
106
+ if (!repo) return;
107
+ const profiles = [
108
+ {
109
+ tag: "default",
110
+ title: "Default",
111
+ description: "Balanced profile for normal multi-agent work.",
112
+ settings: {
113
+ requirePlanApproval: true,
114
+ allowSubAgents: true,
115
+ allowToolCalls: true,
116
+ maxParallelSubAgents: 3,
117
+ maxControllerSteps: 100
118
+ }
119
+ },
120
+ {
121
+ tag: "safe",
122
+ title: "Safe",
123
+ description: "Strict approval-first profile for higher-risk work.",
124
+ settings: {
125
+ requirePlanApproval: true,
126
+ allowSubAgents: true,
127
+ allowToolCalls: true,
128
+ maxParallelSubAgents: 1,
129
+ maxControllerSteps: 50,
130
+ requireVerification: true
131
+ }
132
+ },
133
+ {
134
+ tag: "file-heavy",
135
+ title: "File Heavy",
136
+ description: "Profile for tasks that inspect or transform many attachments/files.",
137
+ settings: {
138
+ requirePlanApproval: true,
139
+ allowSubAgents: true,
140
+ allowToolCalls: true,
141
+ maxParallelSubAgents: 2,
142
+ maxControllerSteps: 120,
143
+ preferFileTools: true
144
+ }
145
+ }
146
+ ];
147
+ for (const profile of profiles) {
148
+ const existing = await repo.findOne({ filter: { tag: profile.tag } });
149
+ if (existing) continue;
150
+ await repo.create({
151
+ values: {
152
+ ...profile,
153
+ enabled: true,
154
+ createdAt: /* @__PURE__ */ new Date(),
155
+ updatedAt: /* @__PURE__ */ new Date()
156
+ }
157
+ });
158
+ }
159
+ }
160
+ async down() {
161
+ }
162
+ }
@@ -1,7 +1,9 @@
1
1
  import { Plugin } from '@nocobase/server';
2
2
  import SkillHubSubFeature from './skill-hub/plugin';
3
+ import { AgentLoopService } from './services/AgentLoopService';
3
4
  export declare class PluginAgentOrchestratorServer extends Plugin {
4
5
  skillHub: SkillHubSubFeature;
6
+ agentLoopService: AgentLoopService;
5
7
  afterAdd(): Promise<void>;
6
8
  beforeLoad(): Promise<void>;
7
9
  load(): Promise<void>;
@@ -44,12 +44,17 @@ var import_server = require("@nocobase/server");
44
44
  var import_path = __toESM(require("path"));
45
45
  var import_delegate_task = require("./tools/delegate-task");
46
46
  var import_external_rag_search = require("./tools/external-rag-search");
47
+ var import_orchestrator_plan = require("./tools/orchestrator-plan");
47
48
  var import_tracing = require("./resources/tracing");
49
+ var import_agent_loop = require("./resources/agent-loop");
48
50
  var import_plugin = __toESM(require("./skill-hub/plugin"));
51
+ var import_AgentLoopService = require("./services/AgentLoopService");
49
52
  class PluginAgentOrchestratorServer extends import_server.Plugin {
50
53
  skillHub;
54
+ agentLoopService;
51
55
  async afterAdd() {
52
56
  this.skillHub = new import_plugin.default(this);
57
+ this.agentLoopService = new import_AgentLoopService.AgentLoopService(this);
53
58
  }
54
59
  async beforeLoad() {
55
60
  this.db.import({ directory: import_path.default.resolve(__dirname, "collections") });
@@ -66,16 +71,24 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
66
71
  actions: [
67
72
  "orchestratorConfig:*",
68
73
  "orchestratorTracing:*",
74
+ "agentLoops:*",
75
+ "agentLoopRuns:*",
76
+ "agentLoopSteps:*",
77
+ "agentLoopEvents:*",
78
+ "agentHarnessProfiles:*",
69
79
  "agentExecutionSpans:*",
70
80
  "skillDefinitions:*",
71
81
  "skillExecutions:*",
82
+ "skillLoopConfigs:*",
72
83
  "skillHub:*",
73
84
  "skillWorkerConfigs:*"
74
85
  ]
75
86
  });
76
87
  const toolsManager = this.app.aiManager.toolsManager;
88
+ toolsManager.registerTools((0, import_orchestrator_plan.createOrchestratorPlanTools)(this, this.agentLoopService));
77
89
  toolsManager.registerTools((0, import_external_rag_search.createExternalRagSearchTool)(this));
78
90
  toolsManager.registerDynamicTools((0, import_delegate_task.createDelegateToolsProvider)(this));
91
+ (0, import_agent_loop.registerAgentLoopResource)(this, this.agentLoopService);
79
92
  (0, import_tracing.registerTracingResource)(this);
80
93
  this.app.cronJobManager.addJob({
81
94
  cronTime: "0 30 2 * * *",
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@nocobase/server';
2
+ import { AgentLoopService } from '../services/AgentLoopService';
3
+ export declare function registerAgentLoopResource(plugin: Plugin, service: AgentLoopService): void;
@@ -0,0 +1,205 @@
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 agent_loop_exports = {};
28
+ __export(agent_loop_exports, {
29
+ registerAgentLoopResource: () => registerAgentLoopResource
30
+ });
31
+ module.exports = __toCommonJS(agent_loop_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 currentUserId(ctx) {
37
+ var _a, _b, _c, _d;
38
+ 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);
39
+ }
40
+ function values(ctx) {
41
+ var _a, _b, _c;
42
+ return ((_a = ctx.request) == null ? void 0 : _a.body) || ((_c = (_b = ctx.action) == null ? void 0 : _b.params) == null ? void 0 : _c.values) || {};
43
+ }
44
+ function formatRunRow(raw) {
45
+ const row = toPlain(raw);
46
+ return {
47
+ id: row.id,
48
+ rootRunId: row.rootRunId,
49
+ sessionId: row.sessionId,
50
+ messageId: row.messageId,
51
+ leaderUsername: row.leaderUsername,
52
+ goal: row.goal,
53
+ status: row.status,
54
+ approvalStatus: row.approvalStatus,
55
+ planVersion: row.planVersion,
56
+ planSource: row.planSource,
57
+ plannerModel: row.plannerModel,
58
+ approvedById: row.approvedById,
59
+ approvedAt: row.approvedAt,
60
+ rejectionReason: row.rejectionReason,
61
+ changeRequest: row.changeRequest,
62
+ currentStepId: row.currentStepId,
63
+ iterationCount: row.iterationCount || 0,
64
+ finalAnswer: row.finalAnswer,
65
+ summary: row.summary,
66
+ userId: row.userId,
67
+ startedAt: row.startedAt,
68
+ endedAt: row.endedAt,
69
+ createdAt: row.createdAt,
70
+ updatedAt: row.updatedAt
71
+ };
72
+ }
73
+ function registerAgentLoopResource(plugin, service) {
74
+ const app = plugin.app;
75
+ app.resource({
76
+ name: "agentLoops",
77
+ actions: {
78
+ async list(ctx, next) {
79
+ const { page = 1, pageSize = 20, sort = ["-createdAt"], filter = {} } = ctx.action.params;
80
+ const repo = ctx.db.getRepository("agentLoopRuns");
81
+ const [rows, count] = await repo.findAndCount({
82
+ filter,
83
+ sort,
84
+ offset: (Number(page) - 1) * Number(pageSize),
85
+ limit: Number(pageSize)
86
+ });
87
+ ctx.body = {
88
+ data: rows.map(formatRunRow),
89
+ meta: {
90
+ count,
91
+ page: Number(page),
92
+ pageSize: Number(pageSize),
93
+ totalPage: Math.ceil(count / Number(pageSize))
94
+ }
95
+ };
96
+ await next();
97
+ },
98
+ async get(ctx, next) {
99
+ const { filterByTk } = ctx.action.params;
100
+ if (!filterByTk) {
101
+ ctx.throw(400, "run id is required");
102
+ return;
103
+ }
104
+ ctx.body = { data: await service.getRunDetail(filterByTk) };
105
+ await next();
106
+ },
107
+ async resume(ctx, next) {
108
+ const body = values(ctx);
109
+ const runId = body.runId || ctx.action.params.filterByTk;
110
+ if (!runId) {
111
+ ctx.throw(400, "runId is required");
112
+ return;
113
+ }
114
+ ctx.body = {
115
+ data: await service.resumeRun(runId, {
116
+ stepId: body.stepId,
117
+ approved: body.approved !== false,
118
+ editedInput: body.editedInput,
119
+ userId: currentUserId(ctx),
120
+ ctx
121
+ })
122
+ };
123
+ await next();
124
+ },
125
+ async approvePlan(ctx, next) {
126
+ const body = values(ctx);
127
+ const runId = body.runId || ctx.action.params.filterByTk;
128
+ if (!runId) {
129
+ ctx.throw(400, "runId is required");
130
+ return;
131
+ }
132
+ ctx.body = {
133
+ data: await service.approvePlanAndExecute(runId, {
134
+ userId: currentUserId(ctx),
135
+ ctx,
136
+ reason: body.reason
137
+ })
138
+ };
139
+ await next();
140
+ },
141
+ async rejectPlan(ctx, next) {
142
+ const body = values(ctx);
143
+ const runId = body.runId || ctx.action.params.filterByTk;
144
+ if (!runId) {
145
+ ctx.throw(400, "runId is required");
146
+ return;
147
+ }
148
+ ctx.body = {
149
+ data: await service.rejectPlan(runId, {
150
+ reason: body.reason,
151
+ userId: currentUserId(ctx)
152
+ })
153
+ };
154
+ await next();
155
+ },
156
+ async requestPlanChanges(ctx, next) {
157
+ const body = values(ctx);
158
+ const runId = body.runId || ctx.action.params.filterByTk;
159
+ if (!runId) {
160
+ ctx.throw(400, "runId is required");
161
+ return;
162
+ }
163
+ ctx.body = {
164
+ data: await service.requestPlanChanges(runId, {
165
+ feedback: body.feedback,
166
+ userId: currentUserId(ctx)
167
+ })
168
+ };
169
+ await next();
170
+ },
171
+ async cancel(ctx, next) {
172
+ const body = values(ctx);
173
+ const runId = body.runId || ctx.action.params.filterByTk;
174
+ if (!runId) {
175
+ ctx.throw(400, "runId is required");
176
+ return;
177
+ }
178
+ ctx.body = {
179
+ data: await service.cancelRun(runId, {
180
+ reason: body.reason,
181
+ userId: currentUserId(ctx)
182
+ })
183
+ };
184
+ await next();
185
+ },
186
+ async retryStep(ctx, next) {
187
+ const body = values(ctx);
188
+ if (!body.stepId) {
189
+ ctx.throw(400, "stepId is required");
190
+ return;
191
+ }
192
+ ctx.body = {
193
+ data: await service.retryStep(body.stepId, {
194
+ userId: currentUserId(ctx)
195
+ })
196
+ };
197
+ await next();
198
+ }
199
+ }
200
+ });
201
+ }
202
+ // Annotate the CommonJS export names for ESM import in node:
203
+ 0 && (module.exports = {
204
+ registerAgentLoopResource
205
+ });
@@ -0,0 +1,42 @@
1
+ import { AgentRegistryService } from './AgentRegistryService';
2
+ export declare class AgentHarness {
3
+ private readonly plugin;
4
+ private readonly registryService;
5
+ private readonly spanService;
6
+ constructor(plugin: any, registryService: AgentRegistryService);
7
+ get db(): any;
8
+ get app(): any;
9
+ executeStep(run: any, step: any, options?: {
10
+ userId?: string | number;
11
+ ctx?: any;
12
+ }): Promise<any>;
13
+ private invokeSubAgentStep;
14
+ private invokeNamedTool;
15
+ runSubAgent(ctx: any, options: {
16
+ leaderUsername: string;
17
+ subAgentUsername: string;
18
+ subAgentEmployee: any;
19
+ task: string;
20
+ context?: string;
21
+ currentDepth?: number;
22
+ currentPath?: string[];
23
+ maxDepth: number;
24
+ timeout: number;
25
+ toolCallId: string;
26
+ toolName: string;
27
+ llmService?: string;
28
+ model?: string;
29
+ recursionLimit?: number;
30
+ rootRunId?: string;
31
+ parentSpanId?: string;
32
+ agentLoopRunId?: string;
33
+ agentLoopStepId?: string;
34
+ }): Promise<{
35
+ status: "success";
36
+ content: string;
37
+ } | {
38
+ status: "error";
39
+ content: any;
40
+ }>;
41
+ private logDelegation;
42
+ }