plugin-agent-orchestrator 1.2.0 → 1.2.2
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/LICENSE +201 -0
- package/dist/client/{117.2e4cb0477da3db1f.js → 117.6c69b6a87751dd18.js} +1 -1
- package/dist/client/{253.93deb9e0192e76a5.js → 253.52f62e1bc0e9520a.js} +1 -1
- package/dist/client/{404.498d2d9516dd1dce.js → 404.86593f98c9768ed5.js} +1 -1
- package/dist/client/{627.fdd60bcc0f3a9cf6.js → 453.fa2d169576262213.js} +1 -1
- package/dist/client/{53.774ff07505d521fa.js → 53.567db3ae078650c6.js} +1 -1
- package/dist/client/{619.e342b0fa467d39ca.js → 619.01713281e5e951d3.js} +1 -1
- package/dist/client/652.69da1598312b3a3f.js +10 -0
- package/dist/client/773.648965568ff476f9.js +10 -0
- package/dist/client/{981.e0546ffc34afedcd.js → 981.37e7aeecdb1ef6fa.js} +1 -1
- package/dist/client/{993.5d04b510835ab0d2.js → 993.ac89f3852990918d.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{117.ccf43ae8631f7d74.js → 117.c982d79ff68738f5.js} +1 -1
- package/dist/client-v2/{214.cdf76752053a8990.js → 214.94c4257bf2838577.js} +1 -1
- package/dist/client-v2/{253.1198df22f5baf304.js → 253.8e19956d2a44dfb8.js} +1 -1
- package/dist/client-v2/{264.78887ff88f969467.js → 264.80e8e358c8c6c2e5.js} +1 -1
- package/dist/client-v2/{404.9ba964c28a151c81.js → 404.ab032b79c95dab6f.js} +1 -1
- package/dist/client-v2/{41.b28cf7a675a603d1.js → 41.cd5610fcf7446127.js} +1 -1
- package/dist/client-v2/{627.e16f4a0dd596c3e6.js → 453.42c6d70628d56cc2.js} +1 -1
- package/dist/client-v2/{53.282081f97e4308c6.js → 53.37c08089a648f89a.js} +1 -1
- package/dist/client-v2/{619.8c03913873785fb6.js → 619.6e9618550101e819.js} +1 -1
- package/dist/client-v2/652.eeba4e0c38367321.js +10 -0
- package/dist/client-v2/{70.9166ed70906d041f.js → 70.332698e53eb59677.js} +1 -1
- package/dist/client-v2/773.4de2ba5acb07318c.js +10 -0
- package/dist/client-v2/981.76060f466e6f7c11.js +10 -0
- package/dist/client-v2/{993.ca5b28f1e2b4c1ef.js → 993.f8cdb5172566ce75.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +4 -1
- package/dist/locale/en-US.json +80 -1
- package/dist/locale/vi-VN.json +5 -1
- package/dist/locale/zh-CN.json +80 -1
- package/dist/node_modules/acorn/LICENSE +21 -0
- package/dist/node_modules/acorn/bin/acorn +4 -0
- package/dist/node_modules/acorn/dist/acorn.d.mts +857 -0
- package/dist/node_modules/acorn/dist/acorn.d.ts +857 -0
- package/dist/node_modules/acorn/dist/acorn.js +1 -0
- package/dist/node_modules/acorn/dist/bin.js +90 -0
- package/dist/node_modules/acorn/package.json +1 -0
- package/dist/node_modules/acorn-walk/LICENSE +21 -0
- package/dist/node_modules/acorn-walk/dist/walk.d.mts +177 -0
- package/dist/node_modules/acorn-walk/dist/walk.d.ts +177 -0
- package/dist/node_modules/acorn-walk/dist/walk.js +1 -0
- package/dist/node_modules/acorn-walk/node_modules/.bin/acorn +15 -0
- package/dist/node_modules/acorn-walk/node_modules/.bin/acorn.cmd +7 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/bin/acorn +4 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.mts +866 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.d.ts +866 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/acorn.js +6174 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/dist/bin.js +90 -0
- package/dist/node_modules/acorn-walk/node_modules/acorn/package.json +50 -0
- package/dist/node_modules/acorn-walk/package.json +1 -0
- package/dist/node_modules/adm-zip/package.json +1 -1
- package/dist/node_modules/ajv/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/collections/agent-auto-approval-checkpoints.js +47 -0
- package/dist/server/collections/agent-execution-spans.js +3 -3
- package/dist/server/collections/agent-hierarchy-invocations.js +59 -0
- package/dist/server/collections/agent-routing-graph-locks.js +40 -0
- package/dist/server/collections/agent-session-auto-approvals.js +45 -0
- package/dist/server/collections/orchestrator-config.js +17 -0
- package/dist/server/migrations/20261119000000-widen-native-employee-identifiers.js +59 -0
- package/dist/server/plugin.js +80 -12
- package/dist/server/resources/agent-auto-approval.js +80 -0
- package/dist/server/resources/hierarchical-routing.js +60 -0
- package/dist/server/services/AutoApprovalCheckpoint.js +133 -0
- package/dist/server/services/CodeValidator.js +8 -4
- package/dist/server/services/GovernanceAdmission.js +60 -0
- package/dist/server/services/HarnessCompiler.js +3 -0
- package/dist/server/services/HarnessSchema.js +13 -1
- package/dist/server/services/HierarchicalAgentRuntime.js +925 -0
- package/dist/server/services/HierarchyEnrollmentGuard.js +216 -0
- package/dist/server/services/HierarchyInvocationJournal.js +157 -0
- package/dist/server/services/HierarchyRequestCancellation.js +150 -0
- package/dist/server/services/LoopRunRepository.js +1 -1
- package/dist/server/services/LoopRunStateMachine.js +2 -2
- package/dist/server/services/LoopWorkerService.js +7 -7
- package/dist/server/services/ParallelInterruptActionsPatch.js +132 -0
- package/dist/server/services/PluginAiRuntimeAdapter.js +107 -9
- package/dist/server/services/RoutingBindingRepository.js +156 -0
- package/dist/server/services/RoutingBindingValidation.js +161 -0
- package/dist/server/services/SandboxRunner.js +19 -0
- package/dist/server/services/SessionAutoApproval.js +173 -0
- package/dist/server/services/VerificationService.js +2 -2
- package/dist/server/skill-hub/plugin.js +17 -0
- package/dist/server/skill-hub/services/RegistrySkillInstallationService.js +2 -2
- package/dist/server/skill-hub/services/registry-node-package.js +191 -0
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +21 -6
- package/dist/server/tools/skill-execute.js +1 -0
- package/dist/server/utils/ensure-indexes.js +1 -0
- package/package.json +5 -2
- package/src/client/SkillPages.tsx +1 -8
- package/src/client/__tests__/embedded-settings.test.tsx +1 -8
- package/src/client/plugin.tsx +3 -8
- package/src/client/skill-hub/tools/InteractionSchemasProvider.tsx +21 -6
- package/src/client/skill-hub/tools/SkillHubCard.tsx +22 -16
- package/src/client/skill-hub/tools/__tests__/skill-hub-card.test.tsx +255 -0
- package/src/client/skill-hub/tools/registerSkillLoopCards.ts +12 -3
- package/src/client-v2/__tests__/embedded-settings.test.tsx +20 -11
- package/src/client-v2/__tests__/hierarchical-routing-settings.test.tsx +350 -0
- package/src/client-v2/auto-approval/AutoApprovalBridge.tsx +513 -0
- package/src/client-v2/auto-approval/AutoApprovalProvider.tsx +399 -0
- package/src/client-v2/auto-approval/__tests__/session-auto-approval.test.tsx +1676 -0
- package/src/client-v2/components/AgentBindingsTab.tsx +275 -3
- package/src/client-v2/components/AgentRunsTab.tsx +1 -8
- package/src/client-v2/components/EmployeeGovernanceTab.tsx +1 -8
- package/src/client-v2/components/HarnessProfilesTab.tsx +4 -8
- package/src/client-v2/components/HarnessSettingsForm.tsx +221 -0
- package/src/client-v2/components/UsageGovernanceTab.tsx +1 -8
- package/src/client-v2/pages/AgentBindingsPage.tsx +1 -8
- package/src/client-v2/pages/ApprovalsPage.tsx +1 -8
- package/src/client-v2/pages/EmployeeGovernancePage.tsx +1 -8
- package/src/client-v2/pages/ExecutionHistoryPage.tsx +1 -8
- package/src/client-v2/pages/HarnessProfilesPage.tsx +1 -8
- package/src/client-v2/pages/KnowledgeAccessPage.tsx +1 -8
- package/src/client-v2/pages/LoopSettingsPage.tsx +1 -8
- package/src/client-v2/pages/MemoryInspectorPage.tsx +1 -8
- package/src/client-v2/pages/RetrievalTracePage.tsx +1 -8
- package/src/client-v2/pages/RulesPage.tsx +1 -8
- package/src/client-v2/pages/SkillDefinitionsPage.tsx +1 -8
- package/src/client-v2/pages/SkillMetricsPage.tsx +1 -8
- package/src/client-v2/pages/TracingPage.tsx +1 -8
- package/src/client-v2/pages/UsageGovernancePage.tsx +1 -8
- package/src/client-v2/plugin.tsx +3 -8
- package/src/client-v2/skill-hub/tools/__tests__/interactions.test.ts +17 -1
- package/src/client-v2/skill-hub/tools/interactions.ts +12 -3
- package/src/locale/en-US.json +80 -1
- package/src/locale/vi-VN.json +5 -1
- package/src/locale/zh-CN.json +80 -1
- package/src/server/__tests__/agent-governance.integration.test.ts +1 -8
- package/src/server/__tests__/agent-monitor-acl.integration.test.ts +1 -8
- package/src/server/__tests__/agent-usage-report.integration.test.ts +1 -8
- package/src/server/__tests__/auto-approval-checkpoint.integration.test.ts +295 -0
- package/src/server/__tests__/harness-capabilities.test.ts +1 -8
- package/src/server/__tests__/harness-compiler.test.ts +64 -0
- package/src/server/__tests__/harness-tool-plan.test.ts +1 -8
- package/src/server/__tests__/hierarchical-routing.integration.test.ts +2318 -0
- package/src/server/__tests__/hierarchy-invocation-journal.integration.test.ts +119 -0
- package/src/server/__tests__/loop-approval-decision.test.ts +59 -12
- package/src/server/__tests__/loop-budget-service.test.ts +1 -8
- package/src/server/__tests__/loop-run-repository.test.ts +1 -8
- package/src/server/__tests__/loop-trigger-service.test.ts +1 -8
- package/src/server/__tests__/loop-worker-claim.test.ts +46 -9
- package/src/server/__tests__/loop-worker-execution.test.ts +1 -8
- package/src/server/__tests__/native-agent-monitor-sync.test.ts +1 -8
- package/src/server/__tests__/native-hierarchy-probe.integration.test.ts +527 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +1 -8
- package/src/server/__tests__/native-usage-attribution.integration.test.ts +1 -8
- package/src/server/__tests__/parallel-interrupt-actions.test.ts +342 -0
- package/src/server/__tests__/plugin-ai-runtime-adapter.test.ts +403 -0
- package/src/server/__tests__/registry-node-package.test.ts +299 -0
- package/src/server/__tests__/routing-binding-graph.integration.test.ts +217 -0
- package/src/server/__tests__/routing-binding-validation.test.ts +256 -0
- package/src/server/__tests__/session-auto-approval.integration.test.ts +329 -0
- package/src/server/__tests__/skill-execute.test.ts +11 -0
- package/src/server/__tests__/skill-review-guard.test.ts +171 -0
- package/src/server/__tests__/token-tracker.test.ts +1 -8
- package/src/server/__tests__/tracing-retention-policy.test.ts +1 -8
- package/src/server/__tests__/usage-ledger.integration.test.ts +1 -8
- package/src/server/collections/agent-auto-approval-checkpoints.ts +18 -0
- package/src/server/collections/agent-execution-spans.ts +4 -11
- package/src/server/collections/agent-governance-audit-events.ts +1 -8
- package/src/server/collections/agent-governance-policies.ts +1 -8
- package/src/server/collections/agent-governance-policy-versions.ts +1 -8
- package/src/server/collections/agent-governance-prompt-bindings.ts +1 -8
- package/src/server/collections/agent-hierarchy-invocations.ts +30 -0
- package/src/server/collections/agent-loop-runs.ts +1 -8
- package/src/server/collections/agent-routing-graph-locks.ts +11 -0
- package/src/server/collections/agent-session-auto-approvals.ts +16 -0
- package/src/server/collections/orchestrator-config.ts +26 -0
- package/src/server/migrations/20261110000000-add-usage-pricing-snapshots.ts +1 -8
- package/src/server/migrations/20261110010000-add-usage-department-attribution.ts +1 -8
- package/src/server/migrations/20261119000000-widen-native-employee-identifiers.ts +37 -0
- package/src/server/plugin.ts +72 -8
- package/src/server/resources/agent-auto-approval.ts +51 -0
- package/src/server/resources/agent-governance.ts +1 -8
- package/src/server/resources/agent-harness-profile.ts +1 -8
- package/src/server/resources/agent-monitor.ts +1 -8
- package/src/server/resources/agent-usage.ts +1 -8
- package/src/server/resources/hierarchical-routing.ts +39 -0
- package/src/server/resources/native-monitor-format.ts +1 -8
- package/src/server/resources/tracing.ts +1 -8
- package/src/server/services/AgentGovernanceService.ts +1 -8
- package/src/server/services/AutoApprovalCheckpoint.ts +140 -0
- package/src/server/services/CodeValidator.ts +23 -4
- package/src/server/services/DepartmentAttribution.ts +1 -8
- package/src/server/services/ExecutionSpanService.ts +1 -8
- package/src/server/services/GovernanceAdmission.ts +83 -8
- package/src/server/services/HarnessCapabilities.ts +1 -8
- package/src/server/services/HarnessCompiler.ts +12 -0
- package/src/server/services/HarnessSchema.ts +30 -0
- package/src/server/services/HierarchicalAgentRuntime.ts +1052 -0
- package/src/server/services/HierarchyEnrollmentGuard.ts +211 -0
- package/src/server/services/HierarchyInvocationJournal.ts +172 -0
- package/src/server/services/HierarchyRequestCancellation.ts +132 -0
- package/src/server/services/LoopBudgetService.ts +1 -8
- package/src/server/services/LoopRunRepository.ts +2 -9
- package/src/server/services/LoopRunStateMachine.ts +3 -10
- package/src/server/services/LoopTriggerService.ts +1 -8
- package/src/server/services/LoopWorkerService.ts +8 -19
- package/src/server/services/ManagedPromptProtection.ts +1 -8
- package/src/server/services/NativeAgentMonitorSyncService.ts +1 -8
- package/src/server/services/NativeSubAgentObserver.ts +1 -8
- package/src/server/services/NativeUsageAttribution.ts +1 -8
- package/src/server/services/ParallelInterruptActionsPatch.ts +164 -0
- package/src/server/services/PluginAiRuntimeAdapter.ts +140 -9
- package/src/server/services/RoutingBindingRepository.ts +146 -0
- package/src/server/services/RoutingBindingValidation.ts +161 -0
- package/src/server/services/SandboxRunner.ts +35 -1
- package/src/server/services/SessionAutoApproval.ts +167 -0
- package/src/server/services/TokenTracker.ts +1 -8
- package/src/server/services/TracingRetentionPolicy.ts +1 -8
- package/src/server/services/VerificationService.ts +3 -10
- package/src/server/skill-hub/plugin.ts +40 -0
- package/src/server/skill-hub/services/RegistrySkillInstallationService.ts +11 -1
- package/src/server/skill-hub/services/registry-node-package.ts +191 -0
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +34 -5
- package/src/server/tools/skill-execute.ts +10 -0
- package/src/server/utils/ensure-indexes.ts +2 -8
- package/dist/client/418.6f01da17774a5a25.js +0 -10
- package/dist/client/652.477e21bfff67bc1c.js +0 -10
- package/dist/client-v2/418.55b6b28cda8bb5f3.js +0 -10
- package/dist/client-v2/652.1a48364774d5383a.js +0 -10
- package/dist/client-v2/981.a81521f0296c7db8.js +0 -10
|
@@ -0,0 +1,216 @@
|
|
|
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 HierarchyEnrollmentGuard_exports = {};
|
|
28
|
+
__export(HierarchyEnrollmentGuard_exports, {
|
|
29
|
+
guardHierarchyEnrollment: () => guardHierarchyEnrollment,
|
|
30
|
+
guardManagedChildActions: () => guardManagedChildActions
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(HierarchyEnrollmentGuard_exports);
|
|
33
|
+
var import_ai = require("@nocobase/ai");
|
|
34
|
+
var import_ai_manager = require("../utils/ai-manager");
|
|
35
|
+
var import_record_utils = require("../utils/record-utils");
|
|
36
|
+
var import_HarnessProfileService = require("./HarnessProfileService");
|
|
37
|
+
var import_SessionAutoApproval = require("./SessionAutoApproval");
|
|
38
|
+
function names(value) {
|
|
39
|
+
if (!Array.isArray(value)) return [];
|
|
40
|
+
return value.map((item) => typeof item === "string" ? item : (0, import_record_utils.asRecord)(item).name).filter((item) => typeof item === "string" && item.length > 0);
|
|
41
|
+
}
|
|
42
|
+
async function guardManagedChildActions(ctx, next) {
|
|
43
|
+
var _a, _b, _c, _d, _e;
|
|
44
|
+
const action = ctx.action;
|
|
45
|
+
if ((action == null ? void 0 : action.resourceName) !== "aiConversations") return next();
|
|
46
|
+
const sessionActions = [
|
|
47
|
+
"sendMessages",
|
|
48
|
+
"resendMessages",
|
|
49
|
+
"resumeToolCall",
|
|
50
|
+
"updateUserDecision",
|
|
51
|
+
"updateToolArgs",
|
|
52
|
+
"updateOptions",
|
|
53
|
+
"abort"
|
|
54
|
+
];
|
|
55
|
+
if (!sessionActions.includes(action.actionName)) return next();
|
|
56
|
+
const userId = (_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
57
|
+
const values = ((_c = action.params) == null ? void 0 : _c.values) ?? {};
|
|
58
|
+
if (typeof values !== "object" || Array.isArray(values)) {
|
|
59
|
+
return ctx.throw(400, ctx.t("Invalid conversation action input."));
|
|
60
|
+
}
|
|
61
|
+
const id = action.actionName === "updateOptions" ? (_d = action.params) == null ? void 0 : _d.filterByTk : values.sessionId;
|
|
62
|
+
if (typeof id !== "string" || !id.trim()) {
|
|
63
|
+
return ctx.throw(400, ctx.t("A single conversation identifier is required."));
|
|
64
|
+
}
|
|
65
|
+
const messageActions = ["sendMessages", "resendMessages", "resumeToolCall", "updateUserDecision", "updateToolArgs"];
|
|
66
|
+
const messageId = action.actionName === "sendMessages" ? values.editingMessageId : values.messageId;
|
|
67
|
+
const messageRequired = ["updateUserDecision", "updateToolArgs"].includes(action.actionName);
|
|
68
|
+
const messageAbsent = messageId == null || messageId === "";
|
|
69
|
+
const validMessage = typeof messageId === "string" && Boolean(messageId.trim()) || typeof messageId === "number" && Number.isSafeInteger(messageId) && messageId > 0;
|
|
70
|
+
if (messageActions.includes(action.actionName) && (messageRequired && messageAbsent || !messageAbsent && !validMessage)) {
|
|
71
|
+
return ctx.throw(400, ctx.t("A single message identifier is required."));
|
|
72
|
+
}
|
|
73
|
+
if (action.actionName === "updateUserDecision" && (typeof values.toolCallId !== "string" || !values.toolCallId.trim())) {
|
|
74
|
+
return ctx.throw(400, ctx.t("A single tool call identifier is required."));
|
|
75
|
+
}
|
|
76
|
+
if (action.actionName === "updateToolArgs" && (typeof ((_e = values.tool) == null ? void 0 : _e.id) !== "string" || !values.tool.id.trim())) {
|
|
77
|
+
return ctx.throw(400, ctx.t("A single tool call identifier is required."));
|
|
78
|
+
}
|
|
79
|
+
if (!userId) return next();
|
|
80
|
+
const conversations = ctx.db.getRepository("aiConversations");
|
|
81
|
+
const conversation = await conversations.findOne({ filter: { sessionId: id, userId } });
|
|
82
|
+
if (!conversation) return next();
|
|
83
|
+
const isManagedChild = async (record) => {
|
|
84
|
+
if ((0, import_record_utils.read)(record, "from") !== "sub-agent") return false;
|
|
85
|
+
const childSessionId = (0, import_record_utils.read)(record, "sessionId");
|
|
86
|
+
const options = (0, import_record_utils.asRecord)((0, import_record_utils.read)(record, "options"));
|
|
87
|
+
if (typeof options.hierarchyRootSessionId === "string" && typeof options.hierarchyParentSessionId === "string") {
|
|
88
|
+
return Boolean(options.hierarchyRootSessionId && options.hierarchyParentSessionId);
|
|
89
|
+
}
|
|
90
|
+
const invocation = await ctx.db.getRepository("agentHierarchyInvocations").findOne({
|
|
91
|
+
filter: { childSessionId, ownerId: userId }
|
|
92
|
+
});
|
|
93
|
+
return Boolean(invocation);
|
|
94
|
+
};
|
|
95
|
+
if (await isManagedChild(conversation)) {
|
|
96
|
+
return ctx.throw(403, ctx.t("Managed child conversations cannot be modified directly."));
|
|
97
|
+
}
|
|
98
|
+
if (messageActions.includes(action.actionName) && messageId) {
|
|
99
|
+
const message = await ctx.db.getRepository("aiMessages").findOne({ filter: { messageId } });
|
|
100
|
+
const messageSessionId = (0, import_record_utils.read)(message, "sessionId");
|
|
101
|
+
if (typeof messageSessionId === "string" && messageSessionId !== id) {
|
|
102
|
+
const messageConversation = await conversations.findOne({ filter: { sessionId: messageSessionId, userId } });
|
|
103
|
+
if (messageConversation && await isManagedChild(messageConversation)) {
|
|
104
|
+
return ctx.throw(403, ctx.t("Managed child conversations cannot be modified directly."));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return next();
|
|
109
|
+
}
|
|
110
|
+
async function guardHierarchyEnrollment(ctx, next) {
|
|
111
|
+
var _a, _b, _c, _d, _e;
|
|
112
|
+
const action = ctx.action;
|
|
113
|
+
if ((action == null ? void 0 : action.resourceName) !== "aiConversations" || !["sendMessages", "resendMessages", "resumeToolCall"].includes(action.actionName)) {
|
|
114
|
+
return next();
|
|
115
|
+
}
|
|
116
|
+
const userId = (_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
117
|
+
const values = ((_c = action.params) == null ? void 0 : _c.values) ?? {};
|
|
118
|
+
const sessionId = typeof values.sessionId === "string" ? values.sessionId : "";
|
|
119
|
+
if (!userId || !sessionId) return next();
|
|
120
|
+
const conversation = await ctx.db.getRepository("aiConversations").findOne({ filter: { sessionId, userId } });
|
|
121
|
+
if (!conversation || (0, import_record_utils.read)(conversation, "from") === "sub-agent") return next();
|
|
122
|
+
const storedUsername = (0, import_record_utils.read)(conversation, "aiEmployeeUsername");
|
|
123
|
+
const requested = typeof values.aiEmployee === "string" ? values.aiEmployee : storedUsername;
|
|
124
|
+
if (typeof requested !== "string" || !requested) return next();
|
|
125
|
+
const roots = await ctx.db.getRepository("orchestratorConfig").find({
|
|
126
|
+
filter: { leaderUsername: requested, enabled: true, routingEnabled: true, routingRole: "specialist" }
|
|
127
|
+
});
|
|
128
|
+
if (!roots.length) return next();
|
|
129
|
+
if (requested !== storedUsername) return ctx.throw(403, ctx.t("The employee does not match the conversation."));
|
|
130
|
+
const employee = await ctx.db.getRepository("aiEmployees").findOne({ filter: { username: requested } });
|
|
131
|
+
if (!employee) return ctx.throw(403, ctx.t("The AI employee is unavailable."));
|
|
132
|
+
const settings = (0, import_record_utils.asRecord)((0, import_record_utils.read)(employee, "skillSettings"));
|
|
133
|
+
const options = (0, import_record_utils.asRecord)((0, import_record_utils.read)(conversation, "options"));
|
|
134
|
+
const configuredTools = /* @__PURE__ */ new Set([...names(settings.tools), ...names(options.tools)]);
|
|
135
|
+
const profiles = new import_HarnessProfileService.HarnessProfileService(ctx.db);
|
|
136
|
+
const workerTools = /* @__PURE__ */ new Set();
|
|
137
|
+
const autoApprove = await (0, import_SessionAutoApproval.sessionAutoApprovalEnabled)(ctx, sessionId);
|
|
138
|
+
for (const root of roots) {
|
|
139
|
+
const specialist = (0, import_record_utils.read)(root, "subAgentUsername");
|
|
140
|
+
const workerBindings = await ctx.db.getRepository("orchestratorConfig").find({
|
|
141
|
+
filter: { leaderUsername: specialist, enabled: true, routingEnabled: true, routingRole: "worker" }
|
|
142
|
+
});
|
|
143
|
+
for (const binding of workerBindings) {
|
|
144
|
+
const tag = typeof (0, import_record_utils.read)(binding, "harnessTag") === "string" ? String((0, import_record_utils.read)(binding, "harnessTag")) : "default";
|
|
145
|
+
const profile = await profiles.getPublishedByTag(tag);
|
|
146
|
+
if (!profile) return ctx.throw(403, ctx.t("The delegation policy profile is unavailable."));
|
|
147
|
+
for (const name of profile.settings.tools.allow) workerTools.add(name);
|
|
148
|
+
if (autoApprove) for (const name of profile.settings.tools.ask) workerTools.add(name);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const generalTools = await (0, import_ai_manager.getAIToolsManager)(ctx.app).listTools({ scope: "GENERAL", ctx, sessionId });
|
|
152
|
+
for (const tool of generalTools) {
|
|
153
|
+
if ((_d = tool.definition) == null ? void 0 : _d.name) configuredTools.add(tool.definition.name);
|
|
154
|
+
}
|
|
155
|
+
const conversationSettings = (0, import_record_utils.asRecord)(options.skillSettings);
|
|
156
|
+
const toolFilter = names(conversationSettings.tools);
|
|
157
|
+
const hasToolFilter = Array.isArray(conversationSettings.tools) && (Boolean(conversationSettings.toolsVersion) || toolFilter.length > 0);
|
|
158
|
+
if (hasToolFilter) {
|
|
159
|
+
const systemTools = new Set((0, import_ai.listSystemTools)());
|
|
160
|
+
for (const name of configuredTools) {
|
|
161
|
+
if (!systemTools.has(name) && !toolFilter.includes(name)) configuredTools.delete(name);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const chatSettings = (0, import_record_utils.asRecord)((0, import_record_utils.read)(employee, "chatSettings"));
|
|
165
|
+
const ai = ctx.app.pm.get("ai");
|
|
166
|
+
if (!((_e = ai == null ? void 0 : ai.ai) == null ? void 0 : _e.skillsManager)) return ctx.throw(403, ctx.t("The AI employee skills are unavailable."));
|
|
167
|
+
const skillsManager = ai.ai.skillsManager;
|
|
168
|
+
if (chatSettings.enableSkills !== false) {
|
|
169
|
+
const general = await skillsManager.listSkills({ scope: "GENERAL" });
|
|
170
|
+
const selected = names(settings.skills);
|
|
171
|
+
const specified = selected.length ? await skillsManager.getSkills(selected) : [];
|
|
172
|
+
const skillFilter = names(conversationSettings.skills);
|
|
173
|
+
const hasSkillFilter = Array.isArray(conversationSettings.skills) && (Boolean(conversationSettings.skillsVersion) || skillFilter.length > 0);
|
|
174
|
+
for (const skill of [...general, ...specified]) {
|
|
175
|
+
if (hasSkillFilter && !skillFilter.includes(skill.name)) continue;
|
|
176
|
+
for (const name of names(skill.tools)) configuredTools.add(name);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const loaded = await ctx.db.getRepository("aiToolMessages").find({
|
|
180
|
+
filter: { sessionId, toolName: "getSkill", status: "success" }
|
|
181
|
+
});
|
|
182
|
+
const loadedNames = /* @__PURE__ */ new Set();
|
|
183
|
+
for (const call of loaded) {
|
|
184
|
+
let content = (0, import_record_utils.read)(call, "content");
|
|
185
|
+
if (typeof content === "string") {
|
|
186
|
+
try {
|
|
187
|
+
content = JSON.parse(content);
|
|
188
|
+
} catch {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const name = (0, import_record_utils.asRecord)(content).skillName;
|
|
193
|
+
if (typeof name === "string" && name) loadedNames.add(name);
|
|
194
|
+
}
|
|
195
|
+
if (loadedNames.size) {
|
|
196
|
+
const loadedSkills = await skillsManager.getSkills([...loadedNames]);
|
|
197
|
+
for (const skill of loadedSkills) {
|
|
198
|
+
for (const name of names(skill.tools)) configuredTools.add(name);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (configuredTools.has("dispatch-sub-agent-task")) {
|
|
202
|
+
return ctx.throw(403, ctx.t("Disable native AI employee dispatch before using managed hierarchy routing."));
|
|
203
|
+
}
|
|
204
|
+
if ([...workerTools].some((name) => configuredTools.has(name))) {
|
|
205
|
+
return ctx.throw(
|
|
206
|
+
403,
|
|
207
|
+
ctx.t("Remove managed worker tools from the parent employee before using hierarchy routing.")
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return next();
|
|
211
|
+
}
|
|
212
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
213
|
+
0 && (module.exports = {
|
|
214
|
+
guardHierarchyEnrollment,
|
|
215
|
+
guardManagedChildActions
|
|
216
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
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 HierarchyInvocationJournal_exports = {};
|
|
28
|
+
__export(HierarchyInvocationJournal_exports, {
|
|
29
|
+
HierarchyInvocationJournal: () => HierarchyInvocationJournal
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(HierarchyInvocationJournal_exports);
|
|
32
|
+
var import_node_crypto = require("node:crypto");
|
|
33
|
+
var import_record_utils = require("../utils/record-utils");
|
|
34
|
+
function digest(question) {
|
|
35
|
+
return (0, import_node_crypto.createHash)("sha256").update(question, "utf8").digest("hex");
|
|
36
|
+
}
|
|
37
|
+
function requireKey(key) {
|
|
38
|
+
if (!Number.isSafeInteger(key.ownerId) || key.ownerId <= 0 || !key.parentSessionId || !key.parentToolCallId) {
|
|
39
|
+
throw new Error("Invalid hierarchy invocation identity.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class HierarchyInvocationJournal {
|
|
43
|
+
constructor(database) {
|
|
44
|
+
this.database = database;
|
|
45
|
+
}
|
|
46
|
+
async findOwned(key) {
|
|
47
|
+
requireKey(key);
|
|
48
|
+
const row = await this.database.getRepository("agentHierarchyInvocations").findOne({
|
|
49
|
+
filter: { parentSessionId: key.parentSessionId, parentToolCallId: key.parentToolCallId, ownerId: key.ownerId }
|
|
50
|
+
});
|
|
51
|
+
if (!row) throw new Error("The hierarchy invocation is unavailable.");
|
|
52
|
+
return row;
|
|
53
|
+
}
|
|
54
|
+
async get(key) {
|
|
55
|
+
return this.findOwned(key);
|
|
56
|
+
}
|
|
57
|
+
assertSame(row, input) {
|
|
58
|
+
if (Number((0, import_record_utils.read)(row, "ownerId")) !== input.ownerId || (0, import_record_utils.read)(row, "rootSessionId") !== input.rootSessionId || (0, import_record_utils.read)(row, "parentEmployee") !== input.parentEmployee || (0, import_record_utils.read)(row, "employeeUsername") !== input.employeeUsername || (0, import_record_utils.read)(row, "role") !== input.role || (0, import_record_utils.read)(row, "questionHash") !== digest(input.question)) {
|
|
59
|
+
throw new Error("The hierarchy invocation identity does not match the existing request.");
|
|
60
|
+
}
|
|
61
|
+
return row;
|
|
62
|
+
}
|
|
63
|
+
async reserve(input) {
|
|
64
|
+
requireKey(input);
|
|
65
|
+
if (!input.rootSessionId || !input.parentEmployee || !input.employeeUsername || !input.question) {
|
|
66
|
+
throw new Error("Incomplete hierarchy invocation.");
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
return await this.database.getRepository("agentHierarchyInvocations").create({
|
|
70
|
+
values: {
|
|
71
|
+
ownerId: input.ownerId,
|
|
72
|
+
rootSessionId: input.rootSessionId,
|
|
73
|
+
parentSessionId: input.parentSessionId,
|
|
74
|
+
parentToolCallId: input.parentToolCallId,
|
|
75
|
+
parentEmployee: input.parentEmployee,
|
|
76
|
+
employeeUsername: input.employeeUsername,
|
|
77
|
+
role: input.role,
|
|
78
|
+
questionHash: digest(input.question),
|
|
79
|
+
snapshot: input.snapshot,
|
|
80
|
+
status: "reserved"
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (!(error instanceof Error) || error.name !== "SequelizeUniqueConstraintError") throw error;
|
|
85
|
+
return this.assertSame(await this.findOwned(input), input);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async claim(key) {
|
|
89
|
+
const row = await this.findOwned(key);
|
|
90
|
+
const status = (0, import_record_utils.read)(row, "status");
|
|
91
|
+
if (status !== "reserved") throw new Error("The hierarchy invocation is not ready.");
|
|
92
|
+
const token = (0, import_node_crypto.randomUUID)();
|
|
93
|
+
const [updated] = await this.database.getModel("agentHierarchyInvocations").update(
|
|
94
|
+
{ status: "running", claimToken: token },
|
|
95
|
+
{ where: { id: (0, import_record_utils.read)(row, "id"), ownerId: key.ownerId, status } }
|
|
96
|
+
);
|
|
97
|
+
if (updated !== 1) throw new Error("The hierarchy invocation was claimed by another request.");
|
|
98
|
+
return { row, token };
|
|
99
|
+
}
|
|
100
|
+
async updateClaim(key, token, values) {
|
|
101
|
+
requireKey(key);
|
|
102
|
+
if (!token) throw new Error("A hierarchy claim is required.");
|
|
103
|
+
const [updated] = await this.database.getModel("agentHierarchyInvocations").update(values, {
|
|
104
|
+
where: {
|
|
105
|
+
parentSessionId: key.parentSessionId,
|
|
106
|
+
parentToolCallId: key.parentToolCallId,
|
|
107
|
+
ownerId: key.ownerId,
|
|
108
|
+
status: "running",
|
|
109
|
+
claimToken: token
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (updated !== 1) throw new Error("The hierarchy claim is no longer active.");
|
|
113
|
+
}
|
|
114
|
+
async attachChild(key, token, childSessionId) {
|
|
115
|
+
if (!childSessionId) throw new Error("A child session is required.");
|
|
116
|
+
await this.updateClaim(key, token, { childSessionId });
|
|
117
|
+
}
|
|
118
|
+
async complete(key, token, result, signal) {
|
|
119
|
+
if (signal == null ? void 0 : signal.aborted) throw new Error("The hierarchy invocation was cancelled.");
|
|
120
|
+
await this.updateClaim(key, token, { status: "succeeded", claimToken: null, result });
|
|
121
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
122
|
+
await this.database.getModel("agentHierarchyInvocations").update(
|
|
123
|
+
{ status: "uncertain", result: null },
|
|
124
|
+
{
|
|
125
|
+
where: {
|
|
126
|
+
parentSessionId: key.parentSessionId,
|
|
127
|
+
parentToolCallId: key.parentToolCallId,
|
|
128
|
+
ownerId: key.ownerId,
|
|
129
|
+
status: "succeeded"
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
throw new Error("The hierarchy invocation was cancelled.");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async markUncertain(key, token) {
|
|
137
|
+
await this.updateClaim(key, token, { status: "uncertain", claimToken: null });
|
|
138
|
+
}
|
|
139
|
+
async invalidateCompleted(key) {
|
|
140
|
+
requireKey(key);
|
|
141
|
+
await this.database.getModel("agentHierarchyInvocations").update(
|
|
142
|
+
{ status: "uncertain", result: null },
|
|
143
|
+
{
|
|
144
|
+
where: {
|
|
145
|
+
parentSessionId: key.parentSessionId,
|
|
146
|
+
parentToolCallId: key.parentToolCallId,
|
|
147
|
+
ownerId: key.ownerId,
|
|
148
|
+
status: "succeeded"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
155
|
+
0 && (module.exports = {
|
|
156
|
+
HierarchyInvocationJournal
|
|
157
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
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 HierarchyRequestCancellation_exports = {};
|
|
28
|
+
__export(HierarchyRequestCancellation_exports, {
|
|
29
|
+
HierarchyRequestCancellation: () => HierarchyRequestCancellation,
|
|
30
|
+
hasHierarchyRequest: () => hasHierarchyRequest,
|
|
31
|
+
hierarchyRequestSignal: () => hierarchyRequestSignal
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(HierarchyRequestCancellation_exports);
|
|
34
|
+
var import_record_utils = require("../utils/record-utils");
|
|
35
|
+
const contextRequests = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
function hierarchyRequestSignal(ctx, nativeSignal) {
|
|
37
|
+
const request = contextRequests.get(ctx);
|
|
38
|
+
if (!request) return nativeSignal;
|
|
39
|
+
if (nativeSignal && !request.removeNativeListener) {
|
|
40
|
+
const abort = () => request.controller.abort();
|
|
41
|
+
if (nativeSignal.aborted) abort();
|
|
42
|
+
else {
|
|
43
|
+
nativeSignal.addEventListener("abort", abort, { once: true });
|
|
44
|
+
request.removeNativeListener = () => nativeSignal.removeEventListener("abort", abort);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return request.controller.signal;
|
|
48
|
+
}
|
|
49
|
+
function hasHierarchyRequest(ctx) {
|
|
50
|
+
return contextRequests.has(ctx);
|
|
51
|
+
}
|
|
52
|
+
class HierarchyRequestCancellation {
|
|
53
|
+
constructor(plugin) {
|
|
54
|
+
this.plugin = plugin;
|
|
55
|
+
}
|
|
56
|
+
active = /* @__PURE__ */ new Map();
|
|
57
|
+
cancel(ownerId, sessionId) {
|
|
58
|
+
for (const request of this.active.get(sessionId) ?? []) {
|
|
59
|
+
if (request.ownerId === ownerId) request.controller.abort();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async middleware(ctx, next) {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
const action = ctx.action;
|
|
65
|
+
if ((action == null ? void 0 : action.resourceName) !== "aiConversations") return next();
|
|
66
|
+
const userId = (_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
|
|
67
|
+
const values = ((_c = action.params) == null ? void 0 : _c.values) ?? {};
|
|
68
|
+
const sessionId = typeof values.sessionId === "string" ? values.sessionId : "";
|
|
69
|
+
if (!userId || !sessionId) return next();
|
|
70
|
+
const isAbort = action.actionName === "abort";
|
|
71
|
+
if (!isAbort && !["sendMessages", "resendMessages", "resumeToolCall"].includes(action.actionName)) return next();
|
|
72
|
+
const conversation = await ctx.db.getRepository("aiConversations").findOne({ filter: { sessionId, userId } });
|
|
73
|
+
if (!conversation || (0, import_record_utils.read)(conversation, "from") === "sub-agent") return next();
|
|
74
|
+
const ownerId = String(userId);
|
|
75
|
+
const username = (0, import_record_utils.read)(conversation, "aiEmployeeUsername");
|
|
76
|
+
if (typeof username !== "string" || !username) return next();
|
|
77
|
+
const binding = await ctx.db.getRepository("orchestratorConfig").findOne({
|
|
78
|
+
filter: { leaderUsername: username, enabled: true, routingEnabled: true, routingRole: "specialist" }
|
|
79
|
+
});
|
|
80
|
+
if (isAbort) {
|
|
81
|
+
const locallyManaged = [...this.active.get(sessionId) ?? []].some((request2) => request2.ownerId === ownerId);
|
|
82
|
+
if (!binding && !locallyManaged) {
|
|
83
|
+
const recorded = await ctx.db.getRepository("agentHierarchyInvocations").findOne({
|
|
84
|
+
filter: { rootSessionId: sessionId, ownerId: userId }
|
|
85
|
+
});
|
|
86
|
+
if (!recorded) return next();
|
|
87
|
+
}
|
|
88
|
+
this.cancel(ownerId, sessionId);
|
|
89
|
+
try {
|
|
90
|
+
if (!this.plugin.name) throw new Error("Plugin name is unavailable.");
|
|
91
|
+
await this.plugin.app.syncMessageManager.publish(this.plugin.name, {
|
|
92
|
+
type: "hierarchy:abort",
|
|
93
|
+
ownerId,
|
|
94
|
+
sessionId
|
|
95
|
+
});
|
|
96
|
+
} catch {
|
|
97
|
+
try {
|
|
98
|
+
this.plugin.app.logger.warn("[AgentOrchestrator] Could not synchronize managed request cancellation.");
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return next();
|
|
103
|
+
}
|
|
104
|
+
if (!binding) return next();
|
|
105
|
+
const request = { ownerId, sessionId, controller: new AbortController() };
|
|
106
|
+
let requests = this.active.get(sessionId);
|
|
107
|
+
if (!requests) this.active.set(sessionId, requests = /* @__PURE__ */ new Set());
|
|
108
|
+
requests.add(request);
|
|
109
|
+
contextRequests.set(ctx, request);
|
|
110
|
+
const cleanup = () => {
|
|
111
|
+
var _a2;
|
|
112
|
+
(_a2 = request.removeNativeListener) == null ? void 0 : _a2.call(request);
|
|
113
|
+
if (contextRequests.get(ctx) === request) contextRequests.delete(ctx);
|
|
114
|
+
requests.delete(request);
|
|
115
|
+
if (!requests.size && this.active.get(sessionId) === requests) this.active.delete(sessionId);
|
|
116
|
+
};
|
|
117
|
+
const nonStreaming = action.actionName !== "resumeToolCall" && values.stream === false;
|
|
118
|
+
try {
|
|
119
|
+
const result = await next();
|
|
120
|
+
if (nonStreaming && request.controller.signal.aborted) {
|
|
121
|
+
return ctx.throw(499, ctx.t("The managed request was cancelled."));
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (nonStreaming && request.controller.signal.aborted) {
|
|
126
|
+
return ctx.throw(499, ctx.t("The managed request was cancelled."));
|
|
127
|
+
}
|
|
128
|
+
throw error;
|
|
129
|
+
} finally {
|
|
130
|
+
cleanup();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
handleSyncMessage(message) {
|
|
134
|
+
const value = (0, import_record_utils.asRecord)(message);
|
|
135
|
+
if (value.type !== "hierarchy:abort") return;
|
|
136
|
+
if (typeof value.ownerId !== "string" || typeof value.sessionId !== "string") return;
|
|
137
|
+
this.cancel(value.ownerId, value.sessionId);
|
|
138
|
+
}
|
|
139
|
+
abortAll() {
|
|
140
|
+
for (const requests of this.active.values()) {
|
|
141
|
+
for (const request of requests) request.controller.abort();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
146
|
+
0 && (module.exports = {
|
|
147
|
+
HierarchyRequestCancellation,
|
|
148
|
+
hasHierarchyRequest,
|
|
149
|
+
hierarchyRequestSignal
|
|
150
|
+
});
|
|
@@ -234,7 +234,7 @@ class LoopRunRepository {
|
|
|
234
234
|
payload: { decision: input.decision },
|
|
235
235
|
actorType: "human",
|
|
236
236
|
actorIdentity: String(decidedById),
|
|
237
|
-
correlationKey: `approval-decided:${
|
|
237
|
+
correlationKey: `approval-decided:${id}`,
|
|
238
238
|
createdAt: now
|
|
239
239
|
},
|
|
240
240
|
transaction
|
|
@@ -248,7 +248,7 @@ class LoopRunStateMachine {
|
|
|
248
248
|
payload: { reason: blockedReason },
|
|
249
249
|
actorType: "worker",
|
|
250
250
|
actorIdentity: normalizedWorkerId,
|
|
251
|
-
correlationKey: `claim-blocked:${
|
|
251
|
+
correlationKey: `claim-blocked:${(0, import_node_crypto.randomUUID)()}`,
|
|
252
252
|
createdAt: now
|
|
253
253
|
},
|
|
254
254
|
transaction
|
|
@@ -366,7 +366,7 @@ class LoopRunStateMachine {
|
|
|
366
366
|
payload: { reason, expiredApprovals: overdue.length },
|
|
367
367
|
actorType: "system",
|
|
368
368
|
actorIdentity: "approval-reaper",
|
|
369
|
-
correlationKey: `approval-expired:${
|
|
369
|
+
correlationKey: `approval-expired:${String((0, import_record_utils.read)(overdue[0], "id"))}`,
|
|
370
370
|
createdAt: now
|
|
371
371
|
},
|
|
372
372
|
transaction
|
|
@@ -233,7 +233,7 @@ class LoopWorkerService {
|
|
|
233
233
|
eventType: "run_waiting_approval",
|
|
234
234
|
title: "Waiting for action approval",
|
|
235
235
|
content: "Run requeued while its approval decisions are still pending.",
|
|
236
|
-
correlationKey: `approval-repark:${
|
|
236
|
+
correlationKey: `approval-repark:${leaseToken}`,
|
|
237
237
|
values: { approvalStatus: "pending" }
|
|
238
238
|
});
|
|
239
239
|
return;
|
|
@@ -247,7 +247,7 @@ class LoopWorkerService {
|
|
|
247
247
|
eventType: "run_started",
|
|
248
248
|
title: snapshot.verificationRecoverySummary ? "Verification recovery started" : snapshot.resumeContext ? "Run resumed" : "Run started",
|
|
249
249
|
content: snapshot.verificationRecoverySummary ? "Recovering verification using the saved maker summary." : snapshot.resumeContext ? `${snapshot.resumeContext.username} resumed after approval decisions.` : `Leader ${snapshot.leaderUsername} began working on the goal.`,
|
|
250
|
-
correlationKey:
|
|
250
|
+
correlationKey: `started:${leaseToken}`,
|
|
251
251
|
values: {
|
|
252
252
|
currentRole: snapshot.verificationRecoverySummary ? "verifier" : snapshot.resumeContext ? snapshot.resumeContext.role : "leader"
|
|
253
253
|
}
|
|
@@ -388,7 +388,7 @@ ${maker.content}`);
|
|
|
388
388
|
eventType: "run_verifying",
|
|
389
389
|
title: "Verification started",
|
|
390
390
|
content: `Verifier ${snapshot.verifierUsername} is reviewing the reported result.`,
|
|
391
|
-
correlationKey:
|
|
391
|
+
correlationKey: `verifying:${leaseToken}`,
|
|
392
392
|
values: {
|
|
393
393
|
currentRole: "verifier",
|
|
394
394
|
finalAnswer: makerSummary,
|
|
@@ -470,7 +470,7 @@ ${maker.content}`);
|
|
|
470
470
|
eventType: deadlocked ? "run_blocked" : "run_waiting_lock",
|
|
471
471
|
title: deadlocked ? "Run blocked by a lock cycle" : "Waiting for repository paths",
|
|
472
472
|
content: `Blocked by run(s): ${lock.blockers.join(", ")}.`,
|
|
473
|
-
correlationKey: `lock:${
|
|
473
|
+
correlationKey: `lock:${leaseToken}`,
|
|
474
474
|
values: deadlocked ? { blockedReason: "Path lock wait graph contains a cycle." } : {}
|
|
475
475
|
});
|
|
476
476
|
return false;
|
|
@@ -642,7 +642,7 @@ ${maker.content}`);
|
|
|
642
642
|
eventType: finding.level === "block" ? "run_blocked" : "run_escalated",
|
|
643
643
|
title: finding.level === "block" ? "Run blocked by tool loop detection" : "Run escalated by tool loop detection",
|
|
644
644
|
content: reason,
|
|
645
|
-
correlationKey: `tool-loop-${finding.level}:${
|
|
645
|
+
correlationKey: `tool-loop-${finding.level}:${leaseToken}`,
|
|
646
646
|
values: finding.level === "block" ? { blockedReason: reason } : { escalationReason: reason }
|
|
647
647
|
});
|
|
648
648
|
return "halt";
|
|
@@ -720,7 +720,7 @@ ${maker.content}`);
|
|
|
720
720
|
eventType: "run_waiting_approval",
|
|
721
721
|
title: "Waiting for action approval",
|
|
722
722
|
content: `${outcome.interrupted.length} tool call(s) require approval.`,
|
|
723
|
-
correlationKey: `approval:${
|
|
723
|
+
correlationKey: `approval:${leaseToken}`,
|
|
724
724
|
values: { approvalStatus: "pending", messageId: outcome.messageId }
|
|
725
725
|
});
|
|
726
726
|
}
|
|
@@ -745,7 +745,7 @@ ${maker.content}`);
|
|
|
745
745
|
eventType: "run_failed",
|
|
746
746
|
title: "Run failed",
|
|
747
747
|
content: message,
|
|
748
|
-
correlationKey: `failed:${
|
|
748
|
+
correlationKey: `failed:${leaseToken}`,
|
|
749
749
|
values: { summary: message }
|
|
750
750
|
});
|
|
751
751
|
} catch (transitionError) {
|