plugin-agent-orchestrator 1.1.3 → 1.1.5
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/README.md +204 -114
- package/dist/client/index.js +1 -1
- package/dist/client-v2/117.7565cff57c39318a.js +10 -0
- package/dist/client-v2/214.106635011859dede.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.41ed200e7d6da332.js +10 -0
- package/dist/client-v2/53.349fff8db80b19d4.js +10 -0
- 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/981.e4a1f41cfc94a856.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 -7
- package/dist/locale/en-US.json +199 -123
- package/dist/locale/vi-VN.json +199 -123
- package/dist/locale/zh-CN.json +199 -123
- package/dist/server/collections/agent-execution-spans.js +55 -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 +69 -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 +170 -3
- package/dist/server/collections/agent-loop-steps.js +76 -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/collections/skill-executions.js +8 -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 +54 -150
- package/dist/server/resources/agent-harness-profile.js +117 -0
- package/dist/server/resources/agent-knowledge-insights.js +1 -3
- package/dist/server/resources/agent-loop-approval.js +108 -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 +183 -139
- package/dist/server/resources/resource-helpers.js +63 -0
- package/dist/server/resources/tracing.js +121 -107
- package/dist/server/services/AgentMemoryContextService.js +34 -0
- package/dist/server/services/DurableCircuitBreakerService.js +229 -0
- package/dist/server/services/HarnessCompiler.js +175 -0
- package/dist/server/services/HarnessProfileService.js +233 -0
- package/dist/server/services/HarnessSchema.js +194 -0
- package/dist/server/services/LoopBudgetService.js +269 -0
- package/dist/server/services/LoopControlService.js +139 -0
- package/dist/server/services/LoopPatternSchema.js +195 -0
- package/dist/server/services/LoopPatternService.js +132 -0
- package/dist/server/services/LoopRunRepository.js +285 -0
- package/dist/server/services/LoopRunStateMachine.js +478 -0
- package/dist/server/services/LoopSchedulerService.js +193 -0
- package/dist/server/services/LoopTriggerService.js +165 -0
- package/dist/server/services/LoopWorkerService.js +699 -0
- package/dist/server/services/NativeSubAgentObserver.js +165 -23
- package/dist/server/services/PathLockService.js +288 -0
- package/dist/server/services/PluginAiRuntimeAdapter.js +226 -0
- package/dist/server/services/ToolLoopDetectionService.js +210 -0
- package/dist/server/services/VerificationSchema.js +59 -0
- package/dist/server/services/VerificationService.js +235 -0
- package/dist/server/services/harness-runtime-policy.js +139 -0
- package/dist/server/skill-hub/actions/git-import.js +13 -7
- package/dist/server/skill-hub/plugin.js +36 -3
- package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +1 -5
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +29 -0
- package/dist/server/utils/ensure-indexes.js +111 -0
- package/dist/server/utils/loop-pattern-context.js +56 -0
- package/package.json +53 -53
- package/src/client/ApprovalsTab.tsx +2 -0
- package/src/client/OrchestratorSettings.tsx +55 -0
- package/src/client/skill-hub/components/GitSkillImport.tsx +3 -3
- package/src/client/skill-hub/components/SkillMetrics.tsx +15 -10
- package/src/client/skill-hub/index.tsx +0 -52
- package/src/client-v2/components/AgentRunsTab.tsx +100 -18
- package/src/client-v2/components/ApprovalsTab.tsx +337 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +385 -100
- package/src/client-v2/components/MemoryInspectorTab.tsx +141 -125
- package/src/client-v2/components/TracingTab.tsx +160 -77
- package/src/client-v2/hooks/useApiRequest.ts +28 -8
- package/src/client-v2/pages/ApprovalsPage.tsx +10 -0
- package/src/client-v2/plugin.tsx +6 -6
- package/src/client-v2/skill-hub/components/SkillMetrics.tsx +11 -6
- package/src/locale/en-US.json +199 -123
- package/src/locale/vi-VN.json +199 -123
- package/src/locale/zh-CN.json +199 -123
- package/src/server/__tests__/circuit-breaker.test.ts +248 -169
- package/src/server/__tests__/harness-compiler.test.ts +214 -0
- package/src/server/__tests__/harness-profile-service.test.ts +167 -0
- package/src/server/__tests__/harness-runtime-policy.test.ts +293 -0
- package/src/server/__tests__/harness-tool-plan.test.ts +172 -0
- package/src/server/__tests__/loop-approval-decision.test.ts +512 -0
- package/src/server/__tests__/loop-approval-expiry.test.ts +258 -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 +73 -0
- package/src/server/__tests__/loop-pattern-service.test.ts +148 -0
- package/src/server/__tests__/loop-run-state-machine.test.ts +101 -0
- package/src/server/__tests__/loop-trigger-service.test.ts +148 -0
- package/src/server/__tests__/loop-worker-claim.test.ts +341 -0
- package/src/server/__tests__/loop-worker-execution.test.ts +317 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +288 -4
- package/src/server/__tests__/path-lock-service.test.ts +254 -0
- package/src/server/__tests__/skill-execution-task-policy.test.ts +140 -0
- package/src/server/__tests__/smoke.test.ts +162 -121
- package/src/server/__tests__/tool-loop-detection.test.ts +275 -0
- package/src/server/collections/agent-execution-spans.ts +55 -0
- package/src/server/collections/agent-harness-profile-versions.ts +26 -0
- package/src/server/collections/agent-harness-profiles.ts +71 -59
- package/src/server/collections/agent-loop-action-approvals.ts +39 -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 +98 -71
- 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 +170 -3
- package/src/server/collections/agent-loop-steps.ts +76 -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/collections/skill-executions.ts +8 -0
- package/src/server/migrations/{20260427000000-change-packages-to-text.ts → 20260427000002-change-packages-to-text.ts} +52 -49
- package/src/server/migrations/20260429000000-add-llm-fields.ts +47 -46
- package/src/server/migrations/{20260429000000-fix-inputargs-json-to-text.ts → 20260429000001-fix-inputargs-json-to-text.ts} +45 -38
- package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +33 -32
- package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +31 -30
- package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -0
- package/src/server/plugin.ts +55 -167
- package/src/server/resources/agent-harness-profile.ts +94 -0
- package/src/server/resources/agent-knowledge-insights.ts +5 -3
- package/src/server/resources/agent-loop-approval.ts +84 -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 +204 -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 +266 -258
- package/src/server/services/AgentMemoryContextService.ts +44 -0
- package/src/server/services/DurableCircuitBreakerService.ts +239 -0
- package/src/server/services/ExecutionSpanService.ts +2 -0
- package/src/server/services/HarnessCompiler.ts +170 -0
- package/src/server/services/HarnessProfileService.ts +239 -0
- package/src/server/services/HarnessSchema.ts +194 -0
- package/src/server/services/LoopBudgetService.ts +275 -0
- package/src/server/services/LoopControlService.ts +124 -0
- package/src/server/services/LoopPatternSchema.ts +185 -0
- package/src/server/services/LoopPatternService.ts +143 -0
- package/src/server/services/LoopRunRepository.ts +336 -0
- package/src/server/services/LoopRunStateMachine.ts +529 -0
- package/src/server/services/LoopSchedulerService.ts +199 -0
- package/src/server/services/LoopTriggerService.ts +157 -0
- package/src/server/services/LoopWorkerService.ts +822 -0
- package/src/server/services/NativeSubAgentObserver.ts +186 -21
- package/src/server/services/PathLockService.ts +321 -0
- package/src/server/services/PluginAiRuntimeAdapter.ts +332 -0
- package/src/server/services/ToolLoopDetectionService.ts +213 -0
- package/src/server/services/VerificationSchema.ts +31 -0
- package/src/server/services/VerificationService.ts +264 -0
- package/src/server/services/harness-runtime-policy.ts +141 -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/plugin.ts +41 -3
- package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +235 -239
- package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +61 -63
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +43 -2
- package/src/server/utils/ensure-indexes.ts +96 -0
- package/src/server/utils/logging.ts +62 -63
- 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/373.f5d5292e53c4e832.js +0 -10
- package/dist/client-v2/418.ce8f5b2b8a229d1d.js +0 -10
- package/dist/client-v2/53.7c29c28043e9112d.js +0 -10
- package/dist/client-v2/619.bd3c5698b40705c3.js +0 -10
- package/dist/client-v2/677.a991ce0250ff5c77.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/client/AIEmployeeSelect.tsx +0 -47
- package/src/client/AIEmployeesContext.tsx +0 -102
- package/src/client/RulesTab.tsx +0 -2
- package/src/client/TracingTab.tsx +0 -436
- package/src/client/skill-hub/components/ExecutionProgress.tsx +0 -51
- package/src/client-v2/components/RulesTab.tsx +0 -2
- package/src/client-v2/pages/AgentRunsPage.tsx +0 -13
- 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
|
@@ -29,7 +29,13 @@ __export(tracing_exports, {
|
|
|
29
29
|
registerTracingResource: () => registerTracingResource
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(tracing_exports);
|
|
32
|
-
var
|
|
32
|
+
var import_LoopRunRepository = require("../services/LoopRunRepository");
|
|
33
|
+
var import_resource_helpers = require("./resource-helpers");
|
|
34
|
+
function plainRecord(raw) {
|
|
35
|
+
if (!raw || typeof raw !== "object") return {};
|
|
36
|
+
const record = raw;
|
|
37
|
+
return typeof record.toJSON === "function" ? record.toJSON() : raw;
|
|
38
|
+
}
|
|
33
39
|
function normalizeSpanFilter(filter = {}) {
|
|
34
40
|
const next = { ...filter };
|
|
35
41
|
if (next.subAgentUsername) {
|
|
@@ -38,15 +44,28 @@ function normalizeSpanFilter(filter = {}) {
|
|
|
38
44
|
}
|
|
39
45
|
return next;
|
|
40
46
|
}
|
|
47
|
+
function mergeFilter(filter, required) {
|
|
48
|
+
return Object.keys(filter).length > 0 ? { $and: [filter, required] } : required;
|
|
49
|
+
}
|
|
50
|
+
function asObject(value) {
|
|
51
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
52
|
+
}
|
|
53
|
+
function asArray(value) {
|
|
54
|
+
return Array.isArray(value) ? value : [];
|
|
55
|
+
}
|
|
56
|
+
function positiveId(value) {
|
|
57
|
+
const parsed = Number(value);
|
|
58
|
+
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;
|
|
59
|
+
}
|
|
41
60
|
function spanTitle(row) {
|
|
42
|
-
if (row.title) return row.title;
|
|
43
|
-
if (row.type === "sub_agent") return `${row.leaderUsername || "-"} -> ${row.employeeUsername || "-"}`;
|
|
44
|
-
return row.toolName || row.type || "span";
|
|
61
|
+
if (typeof row.title === "string" && row.title) return row.title;
|
|
62
|
+
if (row.type === "sub_agent") return `${String(row.leaderUsername || "-")} -> ${String(row.employeeUsername || "-")}`;
|
|
63
|
+
return String(row.toolName || row.type || "span");
|
|
45
64
|
}
|
|
46
65
|
function formatSpanListRow(raw) {
|
|
47
|
-
const row = (
|
|
48
|
-
const metadata = row.metadata
|
|
49
|
-
const input = row.input
|
|
66
|
+
const row = plainRecord(raw);
|
|
67
|
+
const metadata = asObject(row.metadata);
|
|
68
|
+
const input = asObject(row.input);
|
|
50
69
|
return {
|
|
51
70
|
id: row.id,
|
|
52
71
|
rootRunId: row.rootRunId,
|
|
@@ -71,35 +90,32 @@ function formatSpanListRow(raw) {
|
|
|
71
90
|
};
|
|
72
91
|
}
|
|
73
92
|
function buildSpanTree(rows) {
|
|
74
|
-
const plainRows = rows.map(import_ctx_utils.toPlain);
|
|
75
93
|
const byId = /* @__PURE__ */ new Map();
|
|
76
94
|
const roots = [];
|
|
77
|
-
for (const
|
|
78
|
-
const
|
|
79
|
-
byId.set(String(row.id),
|
|
95
|
+
for (const raw of rows) {
|
|
96
|
+
const row = plainRecord(raw);
|
|
97
|
+
byId.set(String(row.id), { ...row, children: [] });
|
|
80
98
|
}
|
|
81
99
|
for (const row of byId.values()) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
roots.push(row);
|
|
86
|
-
}
|
|
100
|
+
const parent = row.parentSpanId ? byId.get(String(row.parentSpanId)) : void 0;
|
|
101
|
+
if (parent) parent.children.push(row);
|
|
102
|
+
else roots.push(row);
|
|
87
103
|
}
|
|
88
104
|
const sortTree = (items) => {
|
|
89
105
|
items.sort(
|
|
90
|
-
(
|
|
106
|
+
(left, right) => new Date(String(left.startedAt || left.createdAt || 0)).getTime() - new Date(String(right.startedAt || right.createdAt || 0)).getTime()
|
|
91
107
|
);
|
|
92
|
-
for (const item of items) sortTree(item.children
|
|
108
|
+
for (const item of items) sortTree(item.children);
|
|
93
109
|
};
|
|
94
110
|
sortTree(roots);
|
|
95
111
|
return roots;
|
|
96
112
|
}
|
|
97
113
|
function flattenSpanTimeline(rows) {
|
|
98
|
-
return rows.map(
|
|
99
|
-
(
|
|
114
|
+
return rows.map(plainRecord).sort(
|
|
115
|
+
(left, right) => new Date(String(left.startedAt || left.createdAt || 0)).getTime() - new Date(String(right.startedAt || right.createdAt || 0)).getTime()
|
|
100
116
|
).map((row) => {
|
|
101
|
-
const input = row.input
|
|
102
|
-
const metadata = row.metadata
|
|
117
|
+
const input = asObject(row.input);
|
|
118
|
+
const metadata = asObject(row.metadata);
|
|
103
119
|
return {
|
|
104
120
|
type: row.type,
|
|
105
121
|
at: row.startedAt || row.createdAt,
|
|
@@ -115,69 +131,74 @@ function flattenSpanTimeline(rows) {
|
|
|
115
131
|
});
|
|
116
132
|
}
|
|
117
133
|
function registerTracingResource(plugin) {
|
|
118
|
-
const
|
|
119
|
-
app.resource({
|
|
134
|
+
const runs = new import_LoopRunRepository.LoopRunRepository(plugin.db);
|
|
135
|
+
plugin.app.resource({
|
|
120
136
|
name: "orchestratorTracing",
|
|
121
137
|
actions: {
|
|
122
|
-
/**
|
|
123
|
-
* List all delegation execution logs.
|
|
124
|
-
*/
|
|
125
138
|
async list(ctx, next) {
|
|
126
|
-
const { page = 1, pageSize = 50, sort = ["-createdAt"], filter = {} } = ctx.action.params;
|
|
127
139
|
try {
|
|
140
|
+
const actor = (0, import_resource_helpers.requestActor)(ctx);
|
|
141
|
+
const { page = 1, pageSize = 50, sort = ["-createdAt"], filter = {} } = ctx.action.params;
|
|
142
|
+
const ownedRunIds = actor.isAdmin ? [] : await runs.listOwnedRunIds(actor.userId, false);
|
|
143
|
+
const spanAccess = actor.isAdmin ? {} : {
|
|
144
|
+
$or: [
|
|
145
|
+
{ agentLoopRunId: { $in: ownedRunIds.length > 0 ? ownedRunIds : [-1] } },
|
|
146
|
+
{ agentLoopRunId: null, userId: actor.userId }
|
|
147
|
+
]
|
|
148
|
+
};
|
|
149
|
+
const spanFilter = mergeFilter(
|
|
150
|
+
{ ...normalizeSpanFilter(filter), parentSpanId: null, type: "sub_agent" },
|
|
151
|
+
spanAccess
|
|
152
|
+
);
|
|
128
153
|
const spanRepo = ctx.db.getRepository("agentExecutionSpans");
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
const [spanRows, spanCount] = await spanRepo.findAndCount({
|
|
155
|
+
filter: spanFilter,
|
|
156
|
+
sort,
|
|
157
|
+
offset: (Number(page) - 1) * Number(pageSize),
|
|
158
|
+
limit: Number(pageSize)
|
|
159
|
+
});
|
|
160
|
+
if (spanCount > 0) {
|
|
161
|
+
ctx.body = {
|
|
162
|
+
data: spanRows.map(formatSpanListRow),
|
|
163
|
+
meta: {
|
|
164
|
+
count: spanCount,
|
|
165
|
+
page: Number(page),
|
|
166
|
+
pageSize: Number(pageSize),
|
|
167
|
+
totalPage: Math.ceil(spanCount / Number(pageSize))
|
|
168
|
+
}
|
|
134
169
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
sort,
|
|
138
|
-
offset: (Number(page) - 1) * Number(pageSize),
|
|
139
|
-
limit: Number(pageSize)
|
|
140
|
-
});
|
|
141
|
-
if (spanCount > 0) {
|
|
142
|
-
ctx.body = {
|
|
143
|
-
data: spanRows.map(formatSpanListRow),
|
|
144
|
-
meta: {
|
|
145
|
-
count: spanCount,
|
|
146
|
-
page: Number(page),
|
|
147
|
-
pageSize: Number(pageSize),
|
|
148
|
-
totalPage: Math.ceil(spanCount / Number(pageSize))
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
await next();
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
170
|
+
await next();
|
|
171
|
+
return;
|
|
154
172
|
}
|
|
155
|
-
const
|
|
156
|
-
const [rows, count] = await
|
|
157
|
-
filter,
|
|
173
|
+
const logFilter = actor.isAdmin ? filter : mergeFilter(filter, { userId: actor.userId });
|
|
174
|
+
const [rows, count] = await ctx.db.getRepository("orchestratorLogs").findAndCount({
|
|
175
|
+
filter: logFilter,
|
|
158
176
|
sort,
|
|
159
177
|
offset: (Number(page) - 1) * Number(pageSize),
|
|
160
178
|
limit: Number(pageSize)
|
|
161
179
|
});
|
|
162
180
|
ctx.body = {
|
|
163
|
-
data: rows.map((
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
data: rows.map((raw) => {
|
|
182
|
+
const row = plainRecord(raw);
|
|
183
|
+
return {
|
|
184
|
+
id: row.id,
|
|
185
|
+
leaderUsername: row.leaderUsername,
|
|
186
|
+
subAgentUsername: row.subAgentUsername,
|
|
187
|
+
toolName: row.toolName,
|
|
188
|
+
task: row.task,
|
|
189
|
+
context: row.context,
|
|
190
|
+
result: row.result,
|
|
191
|
+
status: row.status,
|
|
192
|
+
depth: row.depth,
|
|
193
|
+
durationMs: row.durationMs,
|
|
194
|
+
error: row.error,
|
|
195
|
+
userId: row.userId,
|
|
196
|
+
createdAt: row.createdAt,
|
|
197
|
+
traceCount: asArray(row.trace).length,
|
|
198
|
+
messageCount: asArray(row.messages).length,
|
|
199
|
+
hasUnifiedTrace: false
|
|
200
|
+
};
|
|
201
|
+
}),
|
|
181
202
|
meta: {
|
|
182
203
|
count,
|
|
183
204
|
page: Number(page),
|
|
@@ -185,62 +206,55 @@ function registerTracingResource(plugin) {
|
|
|
185
206
|
totalPage: Math.ceil(count / Number(pageSize))
|
|
186
207
|
}
|
|
187
208
|
};
|
|
188
|
-
} catch (
|
|
189
|
-
|
|
190
|
-
ctx.throw(500, (e == null ? void 0 : e.message) || "Failed to load tracing logs");
|
|
209
|
+
} catch (error) {
|
|
210
|
+
(0, import_resource_helpers.throwResourceError)(ctx, error);
|
|
191
211
|
}
|
|
192
212
|
await next();
|
|
193
213
|
},
|
|
194
|
-
/**
|
|
195
|
-
* Get a single delegation log by ID.
|
|
196
|
-
*/
|
|
197
214
|
async get(ctx, next) {
|
|
198
|
-
var _a;
|
|
199
|
-
const { filterByTk, source } = ctx.action.params;
|
|
200
|
-
if (!filterByTk) {
|
|
201
|
-
ctx.throw(400, "id is required");
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
215
|
try {
|
|
216
|
+
const actor = (0, import_resource_helpers.requestActor)(ctx);
|
|
217
|
+
const { filterByTk, source } = ctx.action.params;
|
|
218
|
+
if (!filterByTk) ctx.throw(400, "id is required");
|
|
205
219
|
const spanRepo = ctx.db.getRepository("agentExecutionSpans");
|
|
206
|
-
if (
|
|
207
|
-
const span = await spanRepo.findOne({
|
|
208
|
-
filter: { id: filterByTk }
|
|
209
|
-
});
|
|
220
|
+
if (source !== "log") {
|
|
221
|
+
const span = await spanRepo.findOne({ filterByTk });
|
|
210
222
|
if (span) {
|
|
211
|
-
const plainSpan = (
|
|
223
|
+
const plainSpan = plainRecord(span);
|
|
224
|
+
const runId = positiveId(plainSpan.agentLoopRunId);
|
|
225
|
+
if (runId) await runs.requireOwnedRun(runId, actor.userId, actor.isAdmin);
|
|
226
|
+
else if (!actor.isAdmin && Number(plainSpan.userId) !== actor.userId) {
|
|
227
|
+
throw new import_LoopRunRepository.LoopRunAccessError(403, "You cannot access this execution trace.");
|
|
228
|
+
}
|
|
212
229
|
const rows = await spanRepo.find({
|
|
213
230
|
filter: { rootRunId: plainSpan.rootRunId },
|
|
214
231
|
sort: ["createdAt"]
|
|
215
232
|
});
|
|
216
|
-
const
|
|
217
|
-
const timeline = flattenSpanTimeline(rows);
|
|
218
|
-
const rootRow = formatSpanListRow(plainSpan);
|
|
219
|
-
const metadata = plainSpan.metadata || {};
|
|
233
|
+
const metadata = asObject(plainSpan.metadata);
|
|
220
234
|
ctx.body = {
|
|
221
235
|
data: {
|
|
222
|
-
...
|
|
236
|
+
...formatSpanListRow(plainSpan),
|
|
223
237
|
input: plainSpan.input,
|
|
224
238
|
output: plainSpan.output,
|
|
225
239
|
metadata,
|
|
226
|
-
trace:
|
|
227
|
-
messages: metadata.messages
|
|
228
|
-
children:
|
|
240
|
+
trace: flattenSpanTimeline(rows),
|
|
241
|
+
messages: asArray(metadata.messages),
|
|
242
|
+
children: buildSpanTree(rows)
|
|
229
243
|
}
|
|
230
244
|
};
|
|
231
245
|
await next();
|
|
232
246
|
return;
|
|
233
247
|
}
|
|
234
248
|
}
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
249
|
+
const log = source === "span" ? null : await ctx.db.getRepository("orchestratorLogs").findOne({ filterByTk });
|
|
250
|
+
if (!log) throw new import_LoopRunRepository.LoopRunAccessError(404, `Execution trace ${String(filterByTk)} was not found.`);
|
|
251
|
+
const plainLog = plainRecord(log);
|
|
252
|
+
if (!actor.isAdmin && Number(plainLog.userId) !== actor.userId) {
|
|
253
|
+
throw new import_LoopRunRepository.LoopRunAccessError(403, "You cannot access this execution trace.");
|
|
254
|
+
}
|
|
255
|
+
ctx.body = { data: { ...plainLog, hasUnifiedTrace: false } };
|
|
256
|
+
} catch (error) {
|
|
257
|
+
(0, import_resource_helpers.throwResourceError)(ctx, error);
|
|
244
258
|
}
|
|
245
259
|
await next();
|
|
246
260
|
}
|
|
@@ -30,6 +30,7 @@ __export(AgentMemoryContextService_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(AgentMemoryContextService_exports);
|
|
32
32
|
var import_ctx_utils = require("../utils/ctx-utils");
|
|
33
|
+
var import_HarnessProfileService = require("./HarnessProfileService");
|
|
33
34
|
const DEFAULT_MEMORY_SCOPES = ["public", "user", "agent_user"];
|
|
34
35
|
const DEFAULT_MAX_CONTEXT_CHARS = 6e3;
|
|
35
36
|
function readModelValue(record, key) {
|
|
@@ -43,6 +44,16 @@ function normalizeScopes(value) {
|
|
|
43
44
|
function normalizeText(value) {
|
|
44
45
|
return typeof value === "string" ? value.trim() : "";
|
|
45
46
|
}
|
|
47
|
+
function flattenPublishedSettings(settings) {
|
|
48
|
+
return {
|
|
49
|
+
...settings,
|
|
50
|
+
nativeObserverEnabled: settings.observability.enabled,
|
|
51
|
+
memoryInjectionEnabled: settings.memory.enabled,
|
|
52
|
+
memoryScopes: settings.memory.scopes,
|
|
53
|
+
maxMemoryContextChars: settings.memory.maxChars,
|
|
54
|
+
tracingRetentionDays: settings.observability.tracingRetentionDays
|
|
55
|
+
};
|
|
56
|
+
}
|
|
46
57
|
function formatRecordSection(record) {
|
|
47
58
|
const content = normalizeText(record.contentMd);
|
|
48
59
|
const graph = normalizeText(record.graphMd);
|
|
@@ -59,6 +70,13 @@ class AgentMemoryContextService {
|
|
|
59
70
|
const employeeSettings = (0, import_ctx_utils.asObject)(readModelValue(task == null ? void 0 : task.employee, "skillSettings"));
|
|
60
71
|
const values = (0, import_ctx_utils.asObject)((_c = (_b = (_a = task == null ? void 0 : task.ctx) == null ? void 0 : _a.action) == null ? void 0 : _b.params) == null ? void 0 : _c.values);
|
|
61
72
|
const requestedTag = normalizeText(values.harnessTag) || normalizeText(values.orchestratorHarnessTag) || normalizeText(directSettings.harnessTag) || normalizeText(directSettings.orchestratorHarnessTag) || normalizeText(employeeSettings.harnessTag) || normalizeText(employeeSettings.orchestratorHarnessTag) || await this.resolveConfiguredHarnessTag(task) || "default";
|
|
73
|
+
const published = await this.resolvePublishedSettings(requestedTag);
|
|
74
|
+
if (published) {
|
|
75
|
+
return {
|
|
76
|
+
...published.settings,
|
|
77
|
+
harnessTag: published.tag
|
|
78
|
+
};
|
|
79
|
+
}
|
|
62
80
|
const profile = await this.findHarnessProfile(requestedTag);
|
|
63
81
|
const fallbackProfile = profile || (requestedTag === "default" ? null : await this.findHarnessProfile("default"));
|
|
64
82
|
const profileSettings = (0, import_ctx_utils.asObject)(fallbackProfile ? readModelValue(fallbackProfile, "settings") : {});
|
|
@@ -138,6 +156,22 @@ ${(0, import_ctx_utils.trimText)(body, maxChars)}
|
|
|
138
156
|
return null;
|
|
139
157
|
}
|
|
140
158
|
}
|
|
159
|
+
async resolvePublishedSettings(requestedTag) {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
try {
|
|
162
|
+
const profiles = new import_HarnessProfileService.HarnessProfileService(this.plugin.db);
|
|
163
|
+
const direct = await profiles.getPublishedByTag(requestedTag);
|
|
164
|
+
if (direct) return { tag: requestedTag, settings: flattenPublishedSettings(direct.settings) };
|
|
165
|
+
if (requestedTag !== "default") {
|
|
166
|
+
const fallback = await profiles.getPublishedByTag("default");
|
|
167
|
+
if (fallback) return { tag: "default", settings: flattenPublishedSettings(fallback.settings) };
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
(_b = (_a = this.plugin.app.logger) == null ? void 0 : _a.warn) == null ? void 0 : _b.call(_a, "[AgentOrchestrator] Failed to load published policy profile", error);
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
141
175
|
async resolveConfiguredHarnessTag(task) {
|
|
142
176
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
143
177
|
const values = (0, import_ctx_utils.asObject)((_c = (_b = (_a = task == null ? void 0 : task.ctx) == null ? void 0 : _a.action) == null ? void 0 : _b.params) == null ? void 0 : _c.values);
|
|
@@ -0,0 +1,229 @@
|
|
|
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 DurableCircuitBreakerService_exports = {};
|
|
28
|
+
__export(DurableCircuitBreakerService_exports, {
|
|
29
|
+
DurableCircuitBreakerService: () => DurableCircuitBreakerService,
|
|
30
|
+
normalizeErrorSignature: () => normalizeErrorSignature
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(DurableCircuitBreakerService_exports);
|
|
33
|
+
var import_node_crypto = require("node:crypto");
|
|
34
|
+
function read(record, key) {
|
|
35
|
+
const model = record;
|
|
36
|
+
return typeof model.get === "function" ? model.get(key) : record[key];
|
|
37
|
+
}
|
|
38
|
+
function count(value, label) {
|
|
39
|
+
if (value === null || value === void 0) return 0;
|
|
40
|
+
const parsed = Number(value);
|
|
41
|
+
if (!Number.isSafeInteger(parsed) || parsed < 0) throw new Error(`${label} counter is invalid.`);
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
function dateOrNull(value) {
|
|
45
|
+
if (!value) return null;
|
|
46
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
47
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
48
|
+
}
|
|
49
|
+
function snapshot(record) {
|
|
50
|
+
const id = Number(read(record, "id"));
|
|
51
|
+
const state = read(record, "state");
|
|
52
|
+
if (!Number.isSafeInteger(id) || id <= 0) throw new Error("Circuit breaker state has an invalid identifier.");
|
|
53
|
+
if (state !== "closed" && state !== "open" && state !== "half_open") {
|
|
54
|
+
throw new Error("Circuit breaker state is invalid.");
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
id,
|
|
58
|
+
state,
|
|
59
|
+
attempts: count(read(record, "attempts"), "Circuit attempt"),
|
|
60
|
+
consecutiveFailures: count(read(record, "consecutiveFailures"), "Circuit consecutive failure"),
|
|
61
|
+
errorSignature: typeof read(record, "errorSignature") === "string" ? String(read(record, "errorSignature")) : "",
|
|
62
|
+
repeatedErrorCount: count(read(record, "repeatedErrorCount"), "Circuit repeated error"),
|
|
63
|
+
retryAt: dateOrNull(read(record, "retryAt"))
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function normalizeScopeKey(scopeKey) {
|
|
67
|
+
const normalized = scopeKey.trim();
|
|
68
|
+
if (!normalized) throw new Error("Circuit breaker scope key is required.");
|
|
69
|
+
if (normalized.length > 300) throw new Error("Circuit breaker scope key cannot exceed 300 characters.");
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
72
|
+
function normalizeErrorSignature(error) {
|
|
73
|
+
const raw = error instanceof Error ? `${error.name}:${error.message}` : String(error);
|
|
74
|
+
const normalized = raw.toLowerCase().replace(/[a-z]:[\\/][^\s"']+/gi, "<path>").replace(/\/(?:[^\s/]+\/)+[^\s"']*/g, "<path>").replace(/\b[0-9a-f]{8}-[0-9a-f-]{27,}\b/gi, "<uuid>").replace(/\b\d+\b/g, "<n>").replace(/\s+/g, " ").trim();
|
|
75
|
+
return (0, import_node_crypto.createHash)("sha256").update(normalized || "unknown-error").digest("hex");
|
|
76
|
+
}
|
|
77
|
+
class DurableCircuitBreakerService {
|
|
78
|
+
constructor(database, distributedLock) {
|
|
79
|
+
this.database = database;
|
|
80
|
+
this.distributedLock = distributedLock;
|
|
81
|
+
}
|
|
82
|
+
async authorizeAttempt(input) {
|
|
83
|
+
const scopeKey = normalizeScopeKey(input.scopeKey);
|
|
84
|
+
const now = input.now || /* @__PURE__ */ new Date();
|
|
85
|
+
return this.withScopeLock(input.patternId, scopeKey, async () => {
|
|
86
|
+
var _a;
|
|
87
|
+
const decision = await this.database.sequelize.transaction(async (transaction) => {
|
|
88
|
+
const repository = this.database.getRepository("agentLoopCircuitStates");
|
|
89
|
+
let record = await repository.findOne({
|
|
90
|
+
filter: { patternId: input.patternId, scopeKey },
|
|
91
|
+
transaction,
|
|
92
|
+
lock: transaction.LOCK.UPDATE
|
|
93
|
+
});
|
|
94
|
+
if (!record) {
|
|
95
|
+
record = await repository.create({
|
|
96
|
+
values: {
|
|
97
|
+
patternId: input.patternId,
|
|
98
|
+
scopeKey,
|
|
99
|
+
state: "closed",
|
|
100
|
+
attempts: 0,
|
|
101
|
+
consecutiveFailures: 0,
|
|
102
|
+
repeatedErrorCount: 0
|
|
103
|
+
},
|
|
104
|
+
transaction
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const current = snapshot(record);
|
|
108
|
+
if (current.state === "half_open") {
|
|
109
|
+
return { allowed: false, reason: "probe", retryAt: current.retryAt };
|
|
110
|
+
}
|
|
111
|
+
if (current.state === "open" && (!current.retryAt || current.retryAt.getTime() > now.getTime())) {
|
|
112
|
+
return { allowed: false, reason: "open", retryAt: current.retryAt };
|
|
113
|
+
}
|
|
114
|
+
if (current.state === "closed" && current.attempts >= input.policy.maxAttempts) {
|
|
115
|
+
const retryAt = new Date(now.getTime() + input.policy.cooldownMs);
|
|
116
|
+
await repository.update({
|
|
117
|
+
filterByTk: current.id,
|
|
118
|
+
values: { state: "open", openedAt: now, retryAt },
|
|
119
|
+
transaction
|
|
120
|
+
});
|
|
121
|
+
return { allowed: false, reason: "attempts", retryAt };
|
|
122
|
+
}
|
|
123
|
+
const nextState = current.state === "open" ? "half_open" : "closed";
|
|
124
|
+
await repository.update({
|
|
125
|
+
filterByTk: current.id,
|
|
126
|
+
values: { state: nextState, attempts: current.attempts + 1 },
|
|
127
|
+
transaction
|
|
128
|
+
});
|
|
129
|
+
return { allowed: true, state: nextState, attempt: current.attempts + 1 };
|
|
130
|
+
});
|
|
131
|
+
if (decision.allowed) return decision;
|
|
132
|
+
if (decision.reason === "probe") throw new Error("Circuit breaker probe is already in progress.");
|
|
133
|
+
if (decision.reason === "attempts") throw new Error("Circuit breaker maximum attempts reached.");
|
|
134
|
+
throw new Error(`Circuit breaker is open until ${((_a = decision.retryAt) == null ? void 0 : _a.toISOString()) || "manual reset"}.`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async recordSuccess(patternId, scopeKey, lastRunId) {
|
|
138
|
+
const normalizedScope = normalizeScopeKey(scopeKey);
|
|
139
|
+
return this.withScopeLock(
|
|
140
|
+
patternId,
|
|
141
|
+
normalizedScope,
|
|
142
|
+
async () => this.database.sequelize.transaction(async (transaction) => {
|
|
143
|
+
const repository = this.database.getRepository("agentLoopCircuitStates");
|
|
144
|
+
const record = await repository.findOne({
|
|
145
|
+
filter: { patternId, scopeKey: normalizedScope },
|
|
146
|
+
transaction,
|
|
147
|
+
lock: transaction.LOCK.UPDATE
|
|
148
|
+
});
|
|
149
|
+
if (!record) return;
|
|
150
|
+
await repository.update({
|
|
151
|
+
filterByTk: read(record, "id"),
|
|
152
|
+
values: {
|
|
153
|
+
state: "closed",
|
|
154
|
+
attempts: 0,
|
|
155
|
+
consecutiveFailures: 0,
|
|
156
|
+
errorSignature: null,
|
|
157
|
+
repeatedErrorCount: 0,
|
|
158
|
+
lastRunId: lastRunId || null,
|
|
159
|
+
openedAt: null,
|
|
160
|
+
retryAt: null
|
|
161
|
+
},
|
|
162
|
+
transaction
|
|
163
|
+
});
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
async recordFailure(input) {
|
|
168
|
+
const scopeKey = normalizeScopeKey(input.scopeKey);
|
|
169
|
+
const signature = normalizeErrorSignature(input.error);
|
|
170
|
+
const now = input.now || /* @__PURE__ */ new Date();
|
|
171
|
+
return this.withScopeLock(
|
|
172
|
+
input.patternId,
|
|
173
|
+
scopeKey,
|
|
174
|
+
async () => this.database.sequelize.transaction(async (transaction) => {
|
|
175
|
+
const repository = this.database.getRepository("agentLoopCircuitStates");
|
|
176
|
+
let record = await repository.findOne({
|
|
177
|
+
filter: { patternId: input.patternId, scopeKey },
|
|
178
|
+
transaction,
|
|
179
|
+
lock: transaction.LOCK.UPDATE
|
|
180
|
+
});
|
|
181
|
+
if (!record) {
|
|
182
|
+
record = await repository.create({
|
|
183
|
+
values: {
|
|
184
|
+
patternId: input.patternId,
|
|
185
|
+
scopeKey,
|
|
186
|
+
state: "closed",
|
|
187
|
+
attempts: 1,
|
|
188
|
+
consecutiveFailures: 0,
|
|
189
|
+
repeatedErrorCount: 0
|
|
190
|
+
},
|
|
191
|
+
transaction
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const current = snapshot(record);
|
|
195
|
+
const consecutiveFailures = current.consecutiveFailures + 1;
|
|
196
|
+
const repeatedErrorCount = current.errorSignature === signature ? current.repeatedErrorCount + 1 : 1;
|
|
197
|
+
const shouldOpen = current.state === "half_open" || current.attempts >= input.policy.maxAttempts || consecutiveFailures >= input.policy.maxConsecutiveFailures || repeatedErrorCount >= input.policy.maxRepeatedError;
|
|
198
|
+
await repository.update({
|
|
199
|
+
filterByTk: current.id,
|
|
200
|
+
values: {
|
|
201
|
+
state: shouldOpen ? "open" : "closed",
|
|
202
|
+
consecutiveFailures,
|
|
203
|
+
errorSignature: signature,
|
|
204
|
+
repeatedErrorCount,
|
|
205
|
+
lastRunId: input.lastRunId || null,
|
|
206
|
+
openedAt: shouldOpen ? now : null,
|
|
207
|
+
retryAt: shouldOpen ? new Date(now.getTime() + input.policy.cooldownMs) : null
|
|
208
|
+
},
|
|
209
|
+
transaction
|
|
210
|
+
});
|
|
211
|
+
return { open: shouldOpen, signature, consecutiveFailures, repeatedErrorCount };
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
withScopeLock(patternId, scopeKey, operation) {
|
|
216
|
+
const normalizedScope = scopeKey.trim();
|
|
217
|
+
if (!normalizedScope) throw new Error("Circuit breaker scope key is required.");
|
|
218
|
+
return this.distributedLock.runExclusive(
|
|
219
|
+
`agent-loop:circuit:${patternId}:${(0, import_node_crypto.createHash)("sha256").update(normalizedScope).digest("hex")}`,
|
|
220
|
+
operation,
|
|
221
|
+
3e4
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
226
|
+
0 && (module.exports = {
|
|
227
|
+
DurableCircuitBreakerService,
|
|
228
|
+
normalizeErrorSignature
|
|
229
|
+
});
|