plugin-agent-orchestrator 1.1.3 → 1.1.4
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/client-v2/214.b063f33ba044a808.js +10 -0
- package/dist/client-v2/253.59577b40d9875be0.js +10 -0
- package/dist/client-v2/264.7ed8bee71fa5935c.js +10 -0
- package/dist/client-v2/{41.ba6e080cc0488143.js → 41.3deb9e57a0f64fc4.js} +1 -1
- package/dist/client-v2/418.58fa350f5496efd3.js +10 -0
- package/dist/client-v2/{53.7c29c28043e9112d.js → 53.9a10455323390f14.js} +1 -1
- package/dist/client-v2/619.0a2144aaffefe018.js +10 -0
- package/dist/client-v2/{70.bda9518881c05360.js → 70.ffff2997c10fd4b0.js} +1 -1
- package/dist/client-v2/{794.9bbb8d3a61b2bdf2.js → 794.a67a2614405ba627.js} +1 -1
- package/dist/client-v2/925.e5925bf21ed68e7a.js +10 -0
- package/dist/client-v2/{993.82778b6fd6db3cb1.js → 993.b0688fdc5ccb000a.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -6
- package/dist/locale/en-US.json +48 -28
- package/dist/locale/vi-VN.json +48 -28
- package/dist/locale/zh-CN.json +48 -28
- package/dist/server/collections/agent-execution-spans.js +47 -0
- package/dist/server/collections/agent-harness-profile-versions.js +56 -0
- package/dist/server/collections/agent-harness-profiles.js +12 -0
- package/dist/server/collections/agent-loop-action-approvals.js +68 -0
- package/dist/server/collections/agent-loop-artifacts.js +55 -0
- package/dist/server/collections/agent-loop-circuit-states.js +53 -0
- package/dist/server/collections/agent-loop-control-settings.js +51 -0
- package/dist/server/collections/agent-loop-events.js +27 -0
- package/dist/server/collections/agent-loop-path-locks.js +57 -0
- package/dist/server/collections/agent-loop-patterns.js +72 -0
- package/dist/server/collections/agent-loop-runs.js +163 -2
- package/dist/server/collections/agent-loop-steps.js +69 -0
- package/dist/server/collections/agent-loop-usage-buckets.js +52 -0
- package/dist/server/collections/agent-loop-worktrees.js +55 -0
- package/dist/server/migrations/{20260427000000-change-packages-to-text.js → 20260427000002-change-packages-to-text.js} +2 -0
- package/dist/server/migrations/20260429000000-add-llm-fields.js +3 -2
- package/dist/server/migrations/{20260429000000-fix-inputargs-json-to-text.js → 20260429000001-fix-inputargs-json-to-text.js} +14 -6
- package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +2 -1
- package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +2 -1
- package/dist/server/migrations/20260803010000-backfill-loop-control-plane-data.js +262 -0
- package/dist/server/plugin.js +52 -150
- package/dist/server/resources/agent-loop-approval.js +83 -0
- package/dist/server/resources/agent-loop-artifact.js +86 -0
- package/dist/server/resources/agent-loop-events-stream.js +130 -0
- package/dist/server/resources/agent-loop.js +181 -139
- package/dist/server/resources/resource-helpers.js +63 -0
- package/dist/server/resources/tracing.js +121 -107
- package/dist/server/services/DurableCircuitBreakerService.js +229 -0
- package/dist/server/services/HarnessCompiler.js +142 -0
- package/dist/server/services/HarnessProfileService.js +168 -0
- package/dist/server/services/HarnessSchema.js +167 -0
- package/dist/server/services/LoopBudgetService.js +269 -0
- package/dist/server/services/LoopControlService.js +139 -0
- package/dist/server/services/LoopPatternSchema.js +180 -0
- package/dist/server/services/LoopPatternService.js +132 -0
- package/dist/server/services/LoopRunRepository.js +205 -0
- package/dist/server/services/LoopRunStateMachine.js +389 -0
- package/dist/server/services/LoopSchedulerService.js +193 -0
- package/dist/server/services/LoopTriggerService.js +128 -0
- package/dist/server/services/LoopWorkerService.js +461 -0
- package/dist/server/services/PathLockService.js +288 -0
- package/dist/server/services/PluginAiRuntimeAdapter.js +215 -0
- package/dist/server/services/VerificationSchema.js +59 -0
- package/dist/server/services/VerificationService.js +169 -0
- package/dist/server/skill-hub/actions/git-import.js +13 -7
- package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +1 -5
- package/dist/server/utils/ensure-indexes.js +111 -0
- package/dist/server/utils/loop-pattern-context.js +56 -0
- package/package.json +1 -1
- package/src/client/OrchestratorSettings.tsx +44 -0
- package/src/client-v2/components/AgentRunsTab.tsx +576 -494
- package/src/client-v2/components/HarnessProfilesTab.tsx +13 -8
- package/src/client-v2/components/MemoryInspectorTab.tsx +19 -3
- package/src/client-v2/components/TracingTab.tsx +515 -432
- package/src/client-v2/hooks/useApiRequest.ts +141 -121
- package/src/client-v2/skill-hub/components/SkillMetrics.tsx +8 -6
- package/src/locale/en-US.json +52 -28
- package/src/locale/vi-VN.json +52 -28
- package/src/locale/zh-CN.json +52 -28
- package/src/server/__tests__/circuit-breaker.test.ts +225 -146
- package/src/server/__tests__/harness-compiler.test.ts +131 -0
- package/src/server/__tests__/harness-profile-service.test.ts +116 -0
- package/src/server/__tests__/harness-tool-plan.test.ts +148 -0
- package/src/server/__tests__/loop-budget-service.test.ts +255 -0
- package/src/server/__tests__/loop-control-plane-backfill.test.ts +266 -0
- package/src/server/__tests__/loop-pattern-schema.test.ts +56 -0
- package/src/server/__tests__/loop-pattern-service.test.ts +148 -0
- package/src/server/__tests__/loop-run-state-machine.test.ts +90 -0
- package/src/server/__tests__/loop-worker-claim.test.ts +341 -0
- package/src/server/__tests__/loop-worker-execution.test.ts +236 -0
- package/src/server/__tests__/path-lock-service.test.ts +254 -0
- package/src/server/__tests__/smoke.test.ts +62 -21
- package/src/server/collections/agent-execution-spans.ts +47 -0
- package/src/server/collections/agent-harness-profile-versions.ts +26 -0
- package/src/server/collections/agent-harness-profiles.ts +12 -0
- package/src/server/collections/agent-loop-action-approvals.ts +38 -0
- package/src/server/collections/agent-loop-artifacts.ts +25 -0
- package/src/server/collections/agent-loop-circuit-states.ts +23 -0
- package/src/server/collections/agent-loop-control-settings.ts +21 -0
- package/src/server/collections/agent-loop-events.ts +27 -0
- package/src/server/collections/agent-loop-path-locks.ts +27 -0
- package/src/server/collections/agent-loop-patterns.ts +42 -0
- package/src/server/collections/agent-loop-runs.ts +163 -2
- package/src/server/collections/agent-loop-steps.ts +69 -0
- package/src/server/collections/agent-loop-usage-buckets.ts +22 -0
- package/src/server/collections/agent-loop-worktrees.ts +25 -0
- package/src/server/migrations/{20260427000000-change-packages-to-text.ts → 20260427000002-change-packages-to-text.ts} +3 -0
- package/src/server/migrations/20260429000000-add-llm-fields.ts +3 -2
- package/src/server/migrations/{20260429000000-fix-inputargs-json-to-text.ts → 20260429000001-fix-inputargs-json-to-text.ts} +13 -6
- package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +2 -1
- package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +2 -1
- package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -0
- package/src/server/plugin.ts +53 -167
- package/src/server/resources/agent-loop-approval.ts +52 -0
- package/src/server/resources/agent-loop-artifact.ts +56 -0
- package/src/server/resources/agent-loop-events-stream.ts +105 -0
- package/src/server/resources/agent-loop.ts +202 -143
- package/src/server/resources/agent-monitor.ts +482 -482
- package/src/server/resources/resource-helpers.ts +33 -0
- package/src/server/resources/tracing.ts +145 -137
- package/src/server/services/DurableCircuitBreakerService.ts +239 -0
- package/src/server/services/HarnessCompiler.ts +133 -0
- package/src/server/services/HarnessProfileService.ts +157 -0
- package/src/server/services/HarnessSchema.ts +163 -0
- package/src/server/services/LoopBudgetService.ts +275 -0
- package/src/server/services/LoopControlService.ts +124 -0
- package/src/server/services/LoopPatternSchema.ts +167 -0
- package/src/server/services/LoopPatternService.ts +143 -0
- package/src/server/services/LoopRunRepository.ts +237 -0
- package/src/server/services/LoopRunStateMachine.ts +432 -0
- package/src/server/services/LoopSchedulerService.ts +199 -0
- package/src/server/services/LoopTriggerService.ts +115 -0
- package/src/server/services/LoopWorkerService.ts +522 -0
- package/src/server/services/PathLockService.ts +321 -0
- package/src/server/services/PluginAiRuntimeAdapter.ts +315 -0
- package/src/server/services/VerificationSchema.ts +31 -0
- package/src/server/services/VerificationService.ts +185 -0
- package/src/server/skill-hub/actions/__tests__/git-import.test.ts +15 -1
- package/src/server/skill-hub/actions/git-import.ts +9 -3
- package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +1 -5
- package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +1 -3
- package/src/server/utils/ensure-indexes.ts +96 -0
- package/src/server/utils/logging.ts +0 -1
- package/src/server/utils/loop-pattern-context.ts +20 -0
- package/dist/client-v2/214.79650a549273f163.js +0 -10
- package/dist/client-v2/253.9f0537713cee9e6c.js +0 -10
- package/dist/client-v2/264.718a107e43fc163c.js +0 -10
- package/dist/client-v2/418.ce8f5b2b8a229d1d.js +0 -10
- package/dist/client-v2/619.bd3c5698b40705c3.js +0 -10
- package/dist/client-v2/925.f5370de8f6632d65.js +0 -10
- package/dist/server/services/AgentHarness.js +0 -81
- package/dist/server/services/AgentLoopController.js +0 -1023
- package/dist/server/services/AgentLoopRepository.js +0 -192
- package/dist/server/services/AgentLoopService.js +0 -142
- package/dist/server/services/AgentPlanValidator.js +0 -99
- package/dist/server/services/AgentPlannerService.js +0 -99
- package/dist/server/services/CircuitBreaker.js +0 -125
- package/dist/server/services/ContextAggregator.js +0 -201
- package/dist/server/services/PlanningPromptService.js +0 -95
- package/dist/server/tools/agent-loop.js +0 -373
- package/dist/server/tools/orchestrator-plan.js +0 -254
- package/src/server/__tests__/agent-loop-controller.test.ts +0 -375
- package/src/server/__tests__/context-aggregator.test.ts +0 -222
- package/src/server/__tests__/parallel-execution.test.ts +0 -318
- package/src/server/__tests__/planning-prompt-service.test.ts +0 -23
- package/src/server/services/AgentHarness.ts +0 -67
- package/src/server/services/AgentLoopController.ts +0 -1263
- package/src/server/services/AgentLoopRepository.ts +0 -178
- package/src/server/services/AgentLoopService.ts +0 -177
- package/src/server/services/AgentPlanValidator.ts +0 -73
- package/src/server/services/AgentPlannerService.ts +0 -80
- package/src/server/services/CircuitBreaker.ts +0 -126
- package/src/server/services/ContextAggregator.ts +0 -239
- package/src/server/services/PlanningPromptService.ts +0 -72
- package/src/server/tools/agent-loop.ts +0 -360
- package/src/server/tools/orchestrator-plan.ts +0 -255
|
@@ -0,0 +1,262 @@
|
|
|
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 backfill_loop_control_plane_data_exports = {};
|
|
28
|
+
__export(backfill_loop_control_plane_data_exports, {
|
|
29
|
+
backfillLoopControlPlaneData: () => backfillLoopControlPlaneData,
|
|
30
|
+
default: () => BackfillLoopControlPlaneData
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(backfill_loop_control_plane_data_exports);
|
|
33
|
+
var import_server = require("@nocobase/server");
|
|
34
|
+
var import_HarnessSchema = require("../services/HarnessSchema");
|
|
35
|
+
var import_LoopPatternSchema = require("../services/LoopPatternSchema");
|
|
36
|
+
var import_ensure_indexes = require("../utils/ensure-indexes");
|
|
37
|
+
const LEGACY_TERMINAL_STATUSES = /* @__PURE__ */ new Set(["succeeded", "failed", "rejected", "canceled"]);
|
|
38
|
+
const CONTROL_PLANE_STATUSES = /* @__PURE__ */ new Set([
|
|
39
|
+
"queued",
|
|
40
|
+
"preparing",
|
|
41
|
+
"waiting_lock",
|
|
42
|
+
"running",
|
|
43
|
+
"waiting_approval",
|
|
44
|
+
"verifying",
|
|
45
|
+
"waiting_human",
|
|
46
|
+
"paused",
|
|
47
|
+
"blocked",
|
|
48
|
+
"succeeded",
|
|
49
|
+
"failed",
|
|
50
|
+
"canceled"
|
|
51
|
+
]);
|
|
52
|
+
const LEGACY_PLAN_STATUSES = /* @__PURE__ */ new Set([
|
|
53
|
+
"planning",
|
|
54
|
+
"waiting_plan_approval",
|
|
55
|
+
"approved",
|
|
56
|
+
"waiting_user",
|
|
57
|
+
"needs_replan",
|
|
58
|
+
"rejected"
|
|
59
|
+
]);
|
|
60
|
+
const BACKFILL_BATCH_SIZE = 500;
|
|
61
|
+
async function* iterateInBatches(repository, options = {}) {
|
|
62
|
+
let page = 1;
|
|
63
|
+
for (; ; ) {
|
|
64
|
+
const batch = await repository.find({ ...options, sort: ["id"], page, pageSize: BACKFILL_BATCH_SIZE });
|
|
65
|
+
if (!batch.length) return;
|
|
66
|
+
for (const record of batch) {
|
|
67
|
+
yield record;
|
|
68
|
+
}
|
|
69
|
+
if (batch.length < BACKFILL_BATCH_SIZE) return;
|
|
70
|
+
page += 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function readValue(record, key) {
|
|
74
|
+
return typeof record.get === "function" ? record.get(key) : record[key];
|
|
75
|
+
}
|
|
76
|
+
function asObject(value) {
|
|
77
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
78
|
+
}
|
|
79
|
+
function positiveInteger(value) {
|
|
80
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
81
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
|
|
82
|
+
}
|
|
83
|
+
function stringValue(value) {
|
|
84
|
+
return typeof value === "string" ? value : "";
|
|
85
|
+
}
|
|
86
|
+
function isPublishedValidVersion(version) {
|
|
87
|
+
return readValue(version, "status") === "published" && (0, import_HarnessSchema.validateHarnessSettings)(readValue(version, "settings")).success;
|
|
88
|
+
}
|
|
89
|
+
async function backfillHarnessProfiles(db) {
|
|
90
|
+
const profiles = db.getRepository("agentHarnessProfiles");
|
|
91
|
+
const versions = db.getRepository("agentHarnessProfileVersions");
|
|
92
|
+
if (!profiles || !versions) return;
|
|
93
|
+
for await (const profile of iterateInBatches(profiles)) {
|
|
94
|
+
const profileId = positiveInteger(readValue(profile, "id"));
|
|
95
|
+
if (!profileId) continue;
|
|
96
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
97
|
+
const allVersions = await versions.find({ filter: { profileId }, sort: ["-version"], transaction });
|
|
98
|
+
const currentVersionId = positiveInteger(readValue(profile, "currentVersionId"));
|
|
99
|
+
const current = currentVersionId ? await versions.findOne({ filterByTk: currentVersionId, transaction }) : null;
|
|
100
|
+
if (current && isPublishedValidVersion(current)) return;
|
|
101
|
+
const published = allVersions.find(isPublishedValidVersion);
|
|
102
|
+
if (published) {
|
|
103
|
+
const publishedId = positiveInteger(readValue(published, "id"));
|
|
104
|
+
if (publishedId && currentVersionId !== publishedId) {
|
|
105
|
+
await profiles.update({
|
|
106
|
+
filterByTk: profileId,
|
|
107
|
+
values: { currentVersionId: publishedId },
|
|
108
|
+
transaction
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const settingsResult = (0, import_HarnessSchema.validateHarnessSettings)(readValue(profile, "settings"));
|
|
114
|
+
if (!settingsResult.success) return;
|
|
115
|
+
const settings = settingsResult.data;
|
|
116
|
+
const nextVersion = allVersions.reduce((maximum, version2) => Math.max(maximum, Number(readValue(version2, "version")) || 0), 0) + 1;
|
|
117
|
+
const version = await versions.create({
|
|
118
|
+
values: {
|
|
119
|
+
profileId,
|
|
120
|
+
version: nextVersion,
|
|
121
|
+
schemaVersion: positiveInteger(readValue(profile, "schemaVersion")) || 1,
|
|
122
|
+
status: "published",
|
|
123
|
+
settings,
|
|
124
|
+
publishedAt: readValue(profile, "updatedAt") || readValue(profile, "createdAt") || /* @__PURE__ */ new Date()
|
|
125
|
+
},
|
|
126
|
+
transaction
|
|
127
|
+
});
|
|
128
|
+
const versionId = positiveInteger(readValue(version, "id"));
|
|
129
|
+
if (versionId) {
|
|
130
|
+
await profiles.update({
|
|
131
|
+
filterByTk: profileId,
|
|
132
|
+
values: { currentVersionId: versionId },
|
|
133
|
+
transaction
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function hasLegacyPlanFields(run, status) {
|
|
140
|
+
const metadata = asObject(readValue(run, "metadata"));
|
|
141
|
+
return LEGACY_PLAN_STATUSES.has(status) || Boolean(stringValue(readValue(run, "planSource")).trim()) || Boolean(stringValue(readValue(run, "plannerModel")).trim()) || Boolean(stringValue(metadata.planSource).trim()) || Boolean(stringValue(metadata.plannerModel).trim()) || Boolean(stringValue(metadata.approvalMode).trim());
|
|
142
|
+
}
|
|
143
|
+
function isValidControlPlaneRun(run) {
|
|
144
|
+
const runtimeVersion = stringValue(readValue(run, "runtimeVersion"));
|
|
145
|
+
const status = stringValue(readValue(run, "status"));
|
|
146
|
+
const patternId = positiveInteger(readValue(run, "patternId"));
|
|
147
|
+
return runtimeVersion === "control-plane-v2" && CONTROL_PLANE_STATUSES.has(status) && !hasLegacyPlanFields(run, status) && patternId !== null && import_LoopPatternSchema.loopPatternPolicySchema.safeParse(readValue(run, "policySnapshot")).success;
|
|
148
|
+
}
|
|
149
|
+
async function backfillLegacyRuns(db) {
|
|
150
|
+
const runs = db.getRepository("agentLoopRuns");
|
|
151
|
+
const steps = db.getRepository("agentLoopSteps");
|
|
152
|
+
const events = db.getRepository("agentLoopEvents");
|
|
153
|
+
if (!runs || !steps || !events) return;
|
|
154
|
+
for await (const run of iterateInBatches(runs)) {
|
|
155
|
+
const runId = positiveInteger(readValue(run, "id"));
|
|
156
|
+
if (!runId || isValidControlPlaneRun(run)) continue;
|
|
157
|
+
const metadata = asObject(readValue(run, "metadata"));
|
|
158
|
+
const statusValue = stringValue(readValue(run, "status"));
|
|
159
|
+
const preservedLegacyStatus = stringValue(metadata.legacyStatus);
|
|
160
|
+
const legacyStatus = preservedLegacyStatus || statusValue || "unknown";
|
|
161
|
+
const isTerminal = LEGACY_TERMINAL_STATUSES.has(legacyStatus);
|
|
162
|
+
const correlationKey = `legacy-runtime-retired:${runId}`;
|
|
163
|
+
if (readValue(run, "runtimeVersion") === "legacy-plan-v1" && metadata.legacyRuntimeRetired === true) continue;
|
|
164
|
+
await db.sequelize.transaction(async (transaction) => {
|
|
165
|
+
await runs.update({
|
|
166
|
+
filterByTk: runId,
|
|
167
|
+
values: {
|
|
168
|
+
runtimeVersion: "legacy-plan-v1",
|
|
169
|
+
recordMode: "legacy-plan",
|
|
170
|
+
...isTerminal ? {} : {
|
|
171
|
+
status: "blocked",
|
|
172
|
+
blockedReason: "The legacy plan runtime was retired. This historical run is read-only.",
|
|
173
|
+
lockedBy: null,
|
|
174
|
+
lockedUntil: null
|
|
175
|
+
},
|
|
176
|
+
metadata: {
|
|
177
|
+
...metadata,
|
|
178
|
+
legacyStatus,
|
|
179
|
+
legacyRuntimeRetired: true
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
transaction
|
|
183
|
+
});
|
|
184
|
+
await steps.update({
|
|
185
|
+
filter: { runId },
|
|
186
|
+
values: { runtimeVersion: "legacy-plan-v1" },
|
|
187
|
+
transaction
|
|
188
|
+
});
|
|
189
|
+
if (!isTerminal) {
|
|
190
|
+
const existingEvent = await events.findOne({
|
|
191
|
+
filter: { runId, type: "legacy_runtime_retired", correlationKey },
|
|
192
|
+
transaction
|
|
193
|
+
});
|
|
194
|
+
if (!existingEvent) {
|
|
195
|
+
await events.create({
|
|
196
|
+
values: {
|
|
197
|
+
runId,
|
|
198
|
+
type: "legacy_runtime_retired",
|
|
199
|
+
title: "Legacy runtime retired",
|
|
200
|
+
content: "The nonterminal plan-era run was blocked during the Loop Control Plane cutover.",
|
|
201
|
+
status: "blocked",
|
|
202
|
+
payload: { legacyStatus },
|
|
203
|
+
actorType: "system",
|
|
204
|
+
actorIdentity: "loop-control-plane-migration",
|
|
205
|
+
correlationKey,
|
|
206
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
207
|
+
},
|
|
208
|
+
transaction
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function backfillSpanRunLinks(db) {
|
|
216
|
+
const spans = db.getRepository("agentExecutionSpans");
|
|
217
|
+
if (!spans) return;
|
|
218
|
+
for await (const span of iterateInBatches(spans)) {
|
|
219
|
+
if (positiveInteger(readValue(span, "agentLoopRunId"))) continue;
|
|
220
|
+
const runId = positiveInteger(asObject(readValue(span, "metadata")).agentLoopRunId);
|
|
221
|
+
const spanId = positiveInteger(readValue(span, "id"));
|
|
222
|
+
if (!runId || !spanId) continue;
|
|
223
|
+
await spans.update({
|
|
224
|
+
filterByTk: spanId,
|
|
225
|
+
values: { agentLoopRunId: runId }
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async function ensureGlobalControl(db) {
|
|
230
|
+
const controls = db.getRepository("agentLoopControlSettings");
|
|
231
|
+
if (!controls) return;
|
|
232
|
+
const existing = await controls.findOne({ filter: { key: "global" } });
|
|
233
|
+
if (existing) return;
|
|
234
|
+
await controls.create({
|
|
235
|
+
values: {
|
|
236
|
+
key: "global",
|
|
237
|
+
acceptNewRuns: true,
|
|
238
|
+
state: "running",
|
|
239
|
+
globalMaxConcurrency: 5,
|
|
240
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
241
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
async function backfillLoopControlPlaneData(db) {
|
|
246
|
+
await backfillHarnessProfiles(db);
|
|
247
|
+
await backfillLegacyRuns(db);
|
|
248
|
+
await backfillSpanRunLinks(db);
|
|
249
|
+
await ensureGlobalControl(db);
|
|
250
|
+
}
|
|
251
|
+
class BackfillLoopControlPlaneData extends import_server.Migration {
|
|
252
|
+
on = "afterLoad";
|
|
253
|
+
appVersion = ">=0.1.0";
|
|
254
|
+
async up() {
|
|
255
|
+
await backfillLoopControlPlaneData(this.db);
|
|
256
|
+
await (0, import_ensure_indexes.ensureAgentOrchestratorIndexes)(this.db);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
260
|
+
0 && (module.exports = {
|
|
261
|
+
backfillLoopControlPlaneData
|
|
262
|
+
});
|
package/dist/server/plugin.js
CHANGED
|
@@ -46,19 +46,25 @@ var import_external_rag_search = require("./tools/external-rag-search");
|
|
|
46
46
|
var import_tracing = require("./resources/tracing");
|
|
47
47
|
var import_agent_monitor = require("./resources/agent-monitor");
|
|
48
48
|
var import_agent_loop = require("./resources/agent-loop");
|
|
49
|
+
var import_agent_loop_approval = require("./resources/agent-loop-approval");
|
|
50
|
+
var import_agent_loop_artifact = require("./resources/agent-loop-artifact");
|
|
51
|
+
var import_agent_loop_events_stream = require("./resources/agent-loop-events-stream");
|
|
49
52
|
var import_agent_knowledge_insights = require("./resources/agent-knowledge-insights");
|
|
50
53
|
var import_plugin = __toESM(require("./skill-hub/plugin"));
|
|
51
54
|
var import_NativeSubAgentObserver = require("./services/NativeSubAgentObserver");
|
|
52
55
|
var import_RegistrySkillSnapshotService = require("./skill-hub/services/RegistrySkillSnapshotService");
|
|
53
56
|
var import_RegistrySkillInstallationService = require("./skill-hub/services/RegistrySkillInstallationService");
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
+
var import_LoopPatternService = require("./services/LoopPatternService");
|
|
58
|
+
var import_LoopSchedulerService = require("./services/LoopSchedulerService");
|
|
59
|
+
var import_LoopTriggerService = require("./services/LoopTriggerService");
|
|
60
|
+
var import_LoopWorkerService = require("./services/LoopWorkerService");
|
|
57
61
|
var import_ctx_utils = require("./utils/ctx-utils");
|
|
62
|
+
var import_loop_pattern_context = require("./utils/loop-pattern-context");
|
|
58
63
|
var import_ai_manager = require("./utils/ai-manager");
|
|
59
64
|
var import_AgentRuntimeLifecycle = require("./services/AgentRuntimeLifecycle");
|
|
60
65
|
var import_InputSchemaValidator = require("./services/InputSchemaValidator");
|
|
61
66
|
var import_skill_tool_name = require("./utils/skill-tool-name");
|
|
67
|
+
var import_ensure_indexes = require("./utils/ensure-indexes");
|
|
62
68
|
function normalizeOptionalString(value) {
|
|
63
69
|
return typeof value === "string" ? value.trim() : "";
|
|
64
70
|
}
|
|
@@ -185,6 +191,8 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
185
191
|
registrySkillInstallationService;
|
|
186
192
|
nativeObserver;
|
|
187
193
|
agentRuntimeLifecycle;
|
|
194
|
+
loopScheduler;
|
|
195
|
+
loopWorker;
|
|
188
196
|
installNativeObserver = () => {
|
|
189
197
|
var _a;
|
|
190
198
|
(_a = this.nativeObserver) == null ? void 0 : _a.install();
|
|
@@ -244,7 +252,14 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
244
252
|
this.app.acl.allow("skillHub", "download", "loggedIn");
|
|
245
253
|
this.app.acl.allow("skillHub", "listTemplates", "loggedIn");
|
|
246
254
|
this.app.acl.allow("agentMonitor", ["list", "get"], "loggedIn");
|
|
247
|
-
this.app.acl.allow(
|
|
255
|
+
this.app.acl.allow(
|
|
256
|
+
"agentLoops",
|
|
257
|
+
["list", "get", "runNow", "pause", "resume", "cancel", "retry", "escalate", "acceptResult", "status"],
|
|
258
|
+
"loggedIn"
|
|
259
|
+
);
|
|
260
|
+
this.app.acl.allow("agentLoopApprovals", ["list", "get"], "loggedIn");
|
|
261
|
+
this.app.acl.allow("agentLoopArtifactsView", ["list", "get"], "loggedIn");
|
|
262
|
+
this.app.acl.allow("agentLoopEventsStream", ["stream"], "loggedIn");
|
|
248
263
|
this.app.resourceManager.use(
|
|
249
264
|
async (ctx, next) => {
|
|
250
265
|
const { resourceName, actionName } = ctx.action || {};
|
|
@@ -330,64 +345,26 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
330
345
|
},
|
|
331
346
|
{ tag: "orchestrator-agent-memory-context-policy", after: "acl" }
|
|
332
347
|
);
|
|
333
|
-
const planningPrompt = new import_PlanningPromptService.PlanningPromptService();
|
|
334
|
-
this.agentRuntimeLifecycle.registerBeforeRunHook("orchestrator-planning", (context) => {
|
|
335
|
-
if (planningPrompt.applyPlanningContext(context.messages)) {
|
|
336
|
-
context.metadata.planningPromptInjected = true;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
this.app.resourceManager.use(
|
|
340
|
-
async (ctx, next) => {
|
|
341
|
-
var _a2, _b2;
|
|
342
|
-
const { resourceName, actionName } = ctx.action || {};
|
|
343
|
-
if (resourceName === "aiConversations" && actionName === "sendMessages") {
|
|
344
|
-
const values = ctx.action.params.values || {};
|
|
345
|
-
const messages = values.messages;
|
|
346
|
-
if (Array.isArray(messages)) {
|
|
347
|
-
const runtimeContext2 = {
|
|
348
|
-
ctx,
|
|
349
|
-
source: "chat-ui",
|
|
350
|
-
employee: void 0,
|
|
351
|
-
sessionId: String(((_a2 = ctx.state) == null ? void 0 : _a2.sessionId) || ""),
|
|
352
|
-
userId: (0, import_ctx_utils.currentUserId)(ctx),
|
|
353
|
-
messages,
|
|
354
|
-
metadata: {}
|
|
355
|
-
};
|
|
356
|
-
await this.agentRuntimeLifecycle.runBeforeHooks(runtimeContext2);
|
|
357
|
-
ctx.state.agentRuntimeContext = runtimeContext2;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const runtimeContext = (_b2 = ctx.state) == null ? void 0 : _b2.agentRuntimeContext;
|
|
361
|
-
try {
|
|
362
|
-
await next();
|
|
363
|
-
if (runtimeContext) {
|
|
364
|
-
await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
|
|
365
|
-
succeeded: ctx.status < 400,
|
|
366
|
-
value: ctx.body
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
} catch (error) {
|
|
370
|
-
if (runtimeContext) {
|
|
371
|
-
await this.agentRuntimeLifecycle.runAfterHooks(runtimeContext, {
|
|
372
|
-
succeeded: false,
|
|
373
|
-
error: error instanceof Error ? error : new Error(String(error))
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
throw error;
|
|
377
|
-
}
|
|
378
|
-
},
|
|
379
|
-
{ tag: "orchestrator-planning-prompt", after: "acl" }
|
|
380
|
-
);
|
|
381
348
|
const toolsManager = (0, import_ai_manager.getAIToolsManager)(this.app);
|
|
382
349
|
toolsManager.registerTools((0, import_external_rag_search.createExternalRagSearchTool)(this));
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
350
|
+
const patterns = new import_LoopPatternService.LoopPatternService(
|
|
351
|
+
this.db,
|
|
352
|
+
(0, import_loop_pattern_context.employeeHarnessResolver)(this),
|
|
353
|
+
async () => (0, import_loop_pattern_context.worktreeCapability)(this)
|
|
354
|
+
);
|
|
355
|
+
const triggers = new import_LoopTriggerService.LoopTriggerService(this.db, patterns);
|
|
356
|
+
this.loopScheduler = new import_LoopSchedulerService.LoopSchedulerService(this, patterns, triggers);
|
|
357
|
+
this.loopWorker = new import_LoopWorkerService.LoopWorkerService(this.app, this.db);
|
|
358
|
+
this.loopScheduler.install();
|
|
359
|
+
(_b = (_a = this.app).on) == null ? void 0 : _b.call(_a, "afterStart", this.startLoopWorker);
|
|
360
|
+
(0, import_agent_loop.registerAgentLoopResource)(this);
|
|
361
|
+
(0, import_agent_loop_approval.registerAgentLoopApprovalResource)(this);
|
|
362
|
+
(0, import_agent_loop_artifact.registerAgentLoopArtifactResource)(this);
|
|
363
|
+
(0, import_agent_loop_events_stream.registerAgentLoopEventsStreamResource)(this);
|
|
386
364
|
(0, import_agent_monitor.registerAgentMonitorResource)(this);
|
|
387
365
|
(0, import_agent_knowledge_insights.registerAgentKnowledgeInsightsResource)(this);
|
|
388
366
|
this.installNativeObserver();
|
|
389
|
-
(
|
|
390
|
-
(_d = (_c = this.app).on) == null ? void 0 : _d.call(_c, "afterStart", this.recoverAfterCrash);
|
|
367
|
+
(_d = (_c = this.app).on) == null ? void 0 : _d.call(_c, "afterStart", this.installNativeObserver);
|
|
391
368
|
(0, import_tracing.registerTracingResource)(this);
|
|
392
369
|
this.app.cronJobManager.addJob({
|
|
393
370
|
cronTime: "0 30 2 * * *",
|
|
@@ -414,6 +391,10 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
414
391
|
}
|
|
415
392
|
async install() {
|
|
416
393
|
await this.skillHub.install();
|
|
394
|
+
await (0, import_ensure_indexes.ensureAgentOrchestratorIndexes)(this.db);
|
|
395
|
+
}
|
|
396
|
+
async upgrade() {
|
|
397
|
+
await (0, import_ensure_indexes.ensureAgentOrchestratorIndexes)(this.db);
|
|
417
398
|
}
|
|
418
399
|
async afterEnable() {
|
|
419
400
|
}
|
|
@@ -424,103 +405,24 @@ class PluginAgentOrchestratorServer extends import_server.Plugin {
|
|
|
424
405
|
async remove() {
|
|
425
406
|
}
|
|
426
407
|
async beforeStop() {
|
|
427
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
408
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
428
409
|
(_b = (_a = this.app).off) == null ? void 0 : _b.call(_a, "afterStart", this.installNativeObserver);
|
|
429
410
|
(_d = (_c = this.app).removeListener) == null ? void 0 : _d.call(_c, "afterStart", this.installNativeObserver);
|
|
430
|
-
(_f = (_e = this.app).off) == null ? void 0 : _f.call(_e, "afterStart", this.
|
|
431
|
-
(_h = (_g = this.app).removeListener) == null ? void 0 : _h.call(_g, "afterStart", this.
|
|
432
|
-
(_i = this.
|
|
411
|
+
(_f = (_e = this.app).off) == null ? void 0 : _f.call(_e, "afterStart", this.startLoopWorker);
|
|
412
|
+
(_h = (_g = this.app).removeListener) == null ? void 0 : _h.call(_g, "afterStart", this.startLoopWorker);
|
|
413
|
+
await ((_i = this.loopWorker) == null ? void 0 : _i.stop());
|
|
414
|
+
await ((_j = this.loopScheduler) == null ? void 0 : _j.dispose());
|
|
415
|
+
(_k = this.nativeObserver) == null ? void 0 : _k.uninstall();
|
|
433
416
|
await this.skillHub.beforeStop();
|
|
434
417
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
try {
|
|
444
|
-
const stepsRepo = this.db.getRepository("agentLoopSteps");
|
|
445
|
-
const runsRepo = this.db.getRepository("agentLoopRuns");
|
|
446
|
-
if (stepsRepo) {
|
|
447
|
-
const staleSteps = await stepsRepo.find({
|
|
448
|
-
filter: {
|
|
449
|
-
status: "running",
|
|
450
|
-
startedAt: { $lt: cutoff.toISOString() }
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
for (const step of staleSteps) {
|
|
454
|
-
const stepId = readModelValue(step, "id");
|
|
455
|
-
const runId = readModelValue(step, "runId");
|
|
456
|
-
await stepsRepo.update({
|
|
457
|
-
filterByTk: stepId,
|
|
458
|
-
values: {
|
|
459
|
-
status: "pending",
|
|
460
|
-
startedAt: null,
|
|
461
|
-
error: `Recovered after crash at ${(/* @__PURE__ */ new Date()).toISOString()}`
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
(_b = (_a = this.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(
|
|
465
|
-
_a,
|
|
466
|
-
`[AgentOrchestrator] Crash recovery: reset step ${stepId} (run ${runId}) from running to pending`
|
|
467
|
-
);
|
|
468
|
-
}
|
|
469
|
-
if (staleSteps.length > 0) {
|
|
470
|
-
(_d = (_c = this.app.logger) == null ? void 0 : _c.info) == null ? void 0 : _d.call(
|
|
471
|
-
_c,
|
|
472
|
-
`[AgentOrchestrator] Crash recovery: reset ${staleSteps.length} stale running step(s)`
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (runsRepo) {
|
|
477
|
-
const runningRuns = await runsRepo.find({
|
|
478
|
-
filter: { status: "running" }
|
|
479
|
-
});
|
|
480
|
-
for (const run of runningRuns) {
|
|
481
|
-
const runId = readModelValue(run, "id");
|
|
482
|
-
const steps = await (stepsRepo == null ? void 0 : stepsRepo.find({
|
|
483
|
-
filter: { runId }
|
|
484
|
-
}));
|
|
485
|
-
if (!steps || steps.length === 0) {
|
|
486
|
-
await runsRepo.update({
|
|
487
|
-
filterByTk: runId,
|
|
488
|
-
values: {
|
|
489
|
-
status: "failed",
|
|
490
|
-
endedAt: /* @__PURE__ */ new Date(),
|
|
491
|
-
summary: "Run was orphaned after server crash (no steps found)."
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
(_f = (_e = this.app.logger) == null ? void 0 : _e.warn) == null ? void 0 : _f.call(
|
|
495
|
-
_e,
|
|
496
|
-
`[AgentOrchestrator] Crash recovery: marked orphaned run ${runId} as failed (no steps)`
|
|
497
|
-
);
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
const allTerminal = steps.every((s) => {
|
|
501
|
-
const st = readModelValue(s, "status");
|
|
502
|
-
return st === "succeeded" || st === "failed" || st === "skipped";
|
|
503
|
-
});
|
|
504
|
-
if (!allTerminal) continue;
|
|
505
|
-
const anyFailed = steps.some((s) => readModelValue(s, "status") === "failed");
|
|
506
|
-
const finalStatus = anyFailed ? "failed" : "succeeded";
|
|
507
|
-
await runsRepo.update({
|
|
508
|
-
filterByTk: runId,
|
|
509
|
-
values: {
|
|
510
|
-
status: finalStatus,
|
|
511
|
-
endedAt: /* @__PURE__ */ new Date(),
|
|
512
|
-
summary: `Run finalized as ${finalStatus} after server crash recovery.`
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
(_h = (_g = this.app.logger) == null ? void 0 : _g.warn) == null ? void 0 : _h.call(
|
|
516
|
-
_g,
|
|
517
|
-
`[AgentOrchestrator] Crash recovery: finalized orphaned run ${runId} as ${finalStatus}`
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
} catch (error) {
|
|
522
|
-
(_j = (_i = this.app.logger) == null ? void 0 : _i.error) == null ? void 0 : _j.call(_i, "[AgentOrchestrator] Crash recovery scan failed", error);
|
|
523
|
-
}
|
|
418
|
+
async handleSyncMessage(message) {
|
|
419
|
+
var _a, _b;
|
|
420
|
+
await ((_a = this.loopScheduler) == null ? void 0 : _a.handleSyncMessage(message));
|
|
421
|
+
await ((_b = this.loopWorker) == null ? void 0 : _b.handleSyncMessage(message));
|
|
422
|
+
}
|
|
423
|
+
startLoopWorker = () => {
|
|
424
|
+
var _a;
|
|
425
|
+
(_a = this.loopWorker) == null ? void 0 : _a.start();
|
|
524
426
|
};
|
|
525
427
|
}
|
|
526
428
|
var plugin_default = PluginAgentOrchestratorServer;
|
|
@@ -0,0 +1,83 @@
|
|
|
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_approval_exports = {};
|
|
28
|
+
__export(agent_loop_approval_exports, {
|
|
29
|
+
registerAgentLoopApprovalResource: () => registerAgentLoopApprovalResource
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(agent_loop_approval_exports);
|
|
32
|
+
var import_LoopRunRepository = require("../services/LoopRunRepository");
|
|
33
|
+
var import_resource_helpers = require("./resource-helpers");
|
|
34
|
+
function registerAgentLoopApprovalResource(plugin) {
|
|
35
|
+
const repository = new import_LoopRunRepository.LoopRunRepository(plugin.db);
|
|
36
|
+
plugin.app.resource({
|
|
37
|
+
name: "agentLoopApprovals",
|
|
38
|
+
actions: {
|
|
39
|
+
async list(ctx, next) {
|
|
40
|
+
try {
|
|
41
|
+
const actor = (0, import_resource_helpers.requestActor)(ctx);
|
|
42
|
+
const result = await repository.listApprovals({
|
|
43
|
+
userId: actor.userId,
|
|
44
|
+
isAdmin: actor.isAdmin,
|
|
45
|
+
filter: ctx.action.params.filter || {},
|
|
46
|
+
sort: ctx.action.params.sort,
|
|
47
|
+
page: Number(ctx.action.params.page),
|
|
48
|
+
pageSize: Number(ctx.action.params.pageSize)
|
|
49
|
+
});
|
|
50
|
+
ctx.body = {
|
|
51
|
+
data: result.rows,
|
|
52
|
+
meta: {
|
|
53
|
+
count: result.count,
|
|
54
|
+
page: result.page,
|
|
55
|
+
pageSize: result.pageSize,
|
|
56
|
+
totalPage: result.totalPage
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
} catch (error) {
|
|
60
|
+
(0, import_resource_helpers.throwResourceError)(ctx, error);
|
|
61
|
+
}
|
|
62
|
+
await next();
|
|
63
|
+
},
|
|
64
|
+
async get(ctx, next) {
|
|
65
|
+
try {
|
|
66
|
+
const actor = (0, import_resource_helpers.requestActor)(ctx);
|
|
67
|
+
const approvalId = ctx.action.params.filterByTk;
|
|
68
|
+
if (!approvalId) ctx.throw(400, "approval id is required");
|
|
69
|
+
ctx.body = {
|
|
70
|
+
data: await repository.requireAccessibleApproval(approvalId, actor.userId, actor.isAdmin)
|
|
71
|
+
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
(0, import_resource_helpers.throwResourceError)(ctx, error);
|
|
74
|
+
}
|
|
75
|
+
await next();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
registerAgentLoopApprovalResource
|
|
83
|
+
});
|