plugin-agent-orchestrator 1.2.0 → 1.2.1
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 +55 -0
- 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/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__/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 +58 -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/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,295 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { createMockServer, type MockServer } from '@nocobase/test';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PluginAgentOrchestratorServer } from '../plugin';
|
|
7
|
+
import { getAIToolsManager } from '../utils/ai-manager';
|
|
8
|
+
|
|
9
|
+
type InterruptCall = {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
args: Record<string, unknown>;
|
|
13
|
+
interrupt: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('session auto-approval checkpoints', () => {
|
|
17
|
+
let app: MockServer;
|
|
18
|
+
let ownerAgent: ReturnType<MockServer['agent']>;
|
|
19
|
+
let ownerId: number;
|
|
20
|
+
let username: string;
|
|
21
|
+
let toolA: string;
|
|
22
|
+
let toolB: string;
|
|
23
|
+
let backendTool: string;
|
|
24
|
+
let messageSequence: number;
|
|
25
|
+
|
|
26
|
+
beforeAll(async () => {
|
|
27
|
+
const suffix = `${process.pid}-${Date.now()}`;
|
|
28
|
+
username = 'dex';
|
|
29
|
+
toolA = `checkpoint_tool_a_${suffix.replace(/-/g, '_')}`;
|
|
30
|
+
toolB = `checkpoint_tool_b_${suffix.replace(/-/g, '_')}`;
|
|
31
|
+
backendTool = `checkpoint_backend_${suffix.replace(/-/g, '_')}`;
|
|
32
|
+
messageSequence = Date.now() * 1000;
|
|
33
|
+
app = await createMockServer({
|
|
34
|
+
plugins: ['nocobase', PluginAgentOrchestratorServer],
|
|
35
|
+
name: `auto-approval-checkpoint-${suffix}`,
|
|
36
|
+
acl: true,
|
|
37
|
+
skipSupervisor: true,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const owner = await app.db.getRepository('users').findOne({ filter: { 'roles.name': 'root' } });
|
|
41
|
+
if (!owner) throw new Error('Mock server did not seed a root user.');
|
|
42
|
+
ownerId = Number(owner.id);
|
|
43
|
+
ownerAgent = await app.agent().login(owner);
|
|
44
|
+
|
|
45
|
+
const tools = getAIToolsManager(app);
|
|
46
|
+
for (const name of [toolA, toolB, backendTool]) {
|
|
47
|
+
tools.registerTools({
|
|
48
|
+
scope: 'CUSTOM',
|
|
49
|
+
execution: 'backend',
|
|
50
|
+
defaultPermission: 'ALLOW',
|
|
51
|
+
definition: {
|
|
52
|
+
name,
|
|
53
|
+
description: 'Tool fixture for automatic approval checkpoint tests.',
|
|
54
|
+
schema: z.object({ value: z.string().optional() }),
|
|
55
|
+
},
|
|
56
|
+
invoke: async (_ctx: unknown, input: { value?: string }) => ({
|
|
57
|
+
status: 'success',
|
|
58
|
+
content: input.value ?? 'ok',
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterAll(async () => {
|
|
65
|
+
await app?.destroy();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const createCheckpointFixture = async (input: { calls?: InterruptCall[]; interruptId?: string } = {}) => {
|
|
69
|
+
const sessionId = randomUUID();
|
|
70
|
+
const messageId = ++messageSequence;
|
|
71
|
+
const interruptId = input.interruptId ?? `interrupt-${randomUUID()}`;
|
|
72
|
+
const calls = input.calls ?? [
|
|
73
|
+
{ id: `call-a-${randomUUID()}`, name: toolA, args: { value: 'A' }, interrupt: true },
|
|
74
|
+
{ id: `call-b-${randomUUID()}`, name: toolB, args: { value: 'B' }, interrupt: true },
|
|
75
|
+
{ id: `call-backend-${randomUUID()}`, name: backendTool, args: { value: 'done' }, interrupt: false },
|
|
76
|
+
];
|
|
77
|
+
await app.db.getRepository('aiConversations').create({
|
|
78
|
+
values: { sessionId, userId: ownerId, aiEmployeeUsername: username, title: 'Approval checkpoint fixture' },
|
|
79
|
+
});
|
|
80
|
+
const message = await app.db.getRepository(`aiConversations.messages`, sessionId).create({
|
|
81
|
+
values: {
|
|
82
|
+
messageId,
|
|
83
|
+
role: username,
|
|
84
|
+
content: { type: 'text', content: 'Approval checkpoint fixture.' },
|
|
85
|
+
toolCalls: calls.map(({ id, name, args }) => ({ id, name, args })),
|
|
86
|
+
metadata: { interruptId },
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
const toolMessages = app.db.getRepository('aiToolMessages');
|
|
90
|
+
for (const [index, call] of calls.entries()) {
|
|
91
|
+
const invokeStatus = call.interrupt ? 'interrupted' : 'done';
|
|
92
|
+
await toolMessages.create({
|
|
93
|
+
values: {
|
|
94
|
+
id: ++messageSequence,
|
|
95
|
+
sessionId,
|
|
96
|
+
messageId,
|
|
97
|
+
toolCallId: call.id,
|
|
98
|
+
toolName: call.name,
|
|
99
|
+
status: call.interrupt ? null : 'success',
|
|
100
|
+
content: call.interrupt ? null : 'previously completed',
|
|
101
|
+
invokeStatus,
|
|
102
|
+
auto: !call.interrupt,
|
|
103
|
+
execution: 'backend',
|
|
104
|
+
interruptActionOrder: index,
|
|
105
|
+
interruptAction: call.interrupt
|
|
106
|
+
? {
|
|
107
|
+
order: index,
|
|
108
|
+
toolCall: { id: call.id, name: call.name, args: call.args },
|
|
109
|
+
allowedDecisions: ['approve', 'reject', 'edit'],
|
|
110
|
+
currentConversation: { sessionId, username, from: 'main-agent' },
|
|
111
|
+
}
|
|
112
|
+
: null,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
await app.db.getRepository('agentSessionAutoApprovals').create({ values: { ownerId, sessionId, enabled: true } });
|
|
117
|
+
return { sessionId, messageId: String(messageId), interruptId, calls, message };
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const decide = (
|
|
121
|
+
identity: { sessionId: string; messageId: string; toolCallId: string },
|
|
122
|
+
decision: 'approve' | 'reject',
|
|
123
|
+
automatic = false,
|
|
124
|
+
) =>
|
|
125
|
+
ownerAgent.resource('aiConversations').updateUserDecision({
|
|
126
|
+
values: {
|
|
127
|
+
...identity,
|
|
128
|
+
userDecision: { type: decision },
|
|
129
|
+
...(automatic ? { agentAutoApproval: true } : {}),
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('lets one manual rejection finalize an enrolled checkpoint after automatic approval is disabled', async () => {
|
|
134
|
+
const fixture = await createCheckpointFixture();
|
|
135
|
+
const [callA, callB] = fixture.calls;
|
|
136
|
+
if (!callA || !callB) throw new Error('The multi-tool checkpoint fixture is incomplete.');
|
|
137
|
+
const first = await decide(
|
|
138
|
+
{ sessionId: fixture.sessionId, messageId: fixture.messageId, toolCallId: callA.id },
|
|
139
|
+
'approve',
|
|
140
|
+
true,
|
|
141
|
+
);
|
|
142
|
+
const firstData = first.body.data;
|
|
143
|
+
expect(first.status).toBe(200);
|
|
144
|
+
expect(firstData.updated).toBe(0);
|
|
145
|
+
expect(firstData.agentAutoApprovalCheckpoint).toMatchObject({
|
|
146
|
+
interruptId: fixture.interruptId,
|
|
147
|
+
decisionRecorded: true,
|
|
148
|
+
canFinalize: false,
|
|
149
|
+
validSnapshot: true,
|
|
150
|
+
});
|
|
151
|
+
expect(firstData.toolCalls).toHaveLength(3);
|
|
152
|
+
expect(firstData.toolCalls.find((call: { id: string }) => call.id === callA.id)).toMatchObject({
|
|
153
|
+
invokeStatus: 'waiting',
|
|
154
|
+
userDecision: { type: 'approve' },
|
|
155
|
+
willInterrupt: true,
|
|
156
|
+
});
|
|
157
|
+
expect(firstData.toolCalls.find((call: { id: string }) => call.id === callB.id)).toMatchObject({
|
|
158
|
+
invokeStatus: 'interrupted',
|
|
159
|
+
willInterrupt: true,
|
|
160
|
+
});
|
|
161
|
+
expect(firstData.toolCalls.find((call: { name: string }) => call.name === backendTool)).toMatchObject({
|
|
162
|
+
invokeStatus: 'done',
|
|
163
|
+
willInterrupt: false,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
await ownerAgent.resource('agentAutoApproval').set({
|
|
167
|
+
values: { sessionId: fixture.sessionId, enabled: false },
|
|
168
|
+
});
|
|
169
|
+
const final = await decide(
|
|
170
|
+
{ sessionId: fixture.sessionId, messageId: fixture.messageId, toolCallId: callB.id },
|
|
171
|
+
'reject',
|
|
172
|
+
);
|
|
173
|
+
expect(final.status).toBe(200);
|
|
174
|
+
expect(final.body.data.updated).toBe(1);
|
|
175
|
+
expect(final.body.data.agentAutoApprovalCheckpoint).toMatchObject({
|
|
176
|
+
interruptId: fixture.interruptId,
|
|
177
|
+
decisionRecorded: true,
|
|
178
|
+
canFinalize: true,
|
|
179
|
+
validSnapshot: true,
|
|
180
|
+
});
|
|
181
|
+
expect(final.body.data.toolCalls).toHaveLength(3);
|
|
182
|
+
expect(final.body.data.toolCalls.map((call: { invokeStatus: string }) => call.invokeStatus)).toEqual([
|
|
183
|
+
'waiting',
|
|
184
|
+
'waiting',
|
|
185
|
+
'done',
|
|
186
|
+
]);
|
|
187
|
+
expect(final.body.data.toolCalls[1].userDecision).toEqual({ type: 'reject' });
|
|
188
|
+
expect(final.body.data.toolCalls[2].willInterrupt).toBe(false);
|
|
189
|
+
|
|
190
|
+
const duplicate = await decide(
|
|
191
|
+
{ sessionId: fixture.sessionId, messageId: fixture.messageId, toolCallId: callB.id },
|
|
192
|
+
'reject',
|
|
193
|
+
);
|
|
194
|
+
expect(duplicate.body.data.updated).toBe(0);
|
|
195
|
+
expect(duplicate.body.data.agentAutoApprovalCheckpoint.canFinalize).toBe(false);
|
|
196
|
+
expect(
|
|
197
|
+
await app.db.getRepository('agentAutoApprovalCheckpoints').count({
|
|
198
|
+
filter: { ownerId, sessionId: fixture.sessionId, interruptId: fixture.interruptId, status: 'issued' },
|
|
199
|
+
}),
|
|
200
|
+
).toBe(1);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('issues a checkpoint exactly once for concurrent native decisions', async () => {
|
|
204
|
+
const fixture = await createCheckpointFixture();
|
|
205
|
+
const [callA, callB] = fixture.calls;
|
|
206
|
+
if (!callA || !callB) throw new Error('The multi-tool checkpoint fixture is incomplete.');
|
|
207
|
+
|
|
208
|
+
const results = await Promise.all(
|
|
209
|
+
[callA, callB].map((call) =>
|
|
210
|
+
decide({ sessionId: fixture.sessionId, messageId: fixture.messageId, toolCallId: call.id }, 'approve', true),
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(results.filter((result) => result.body.data.updated === 1)).toHaveLength(1);
|
|
215
|
+
expect(results.filter((result) => result.body.data.agentAutoApprovalCheckpoint?.canFinalize === true)).toHaveLength(
|
|
216
|
+
1,
|
|
217
|
+
);
|
|
218
|
+
expect(
|
|
219
|
+
await app.db.getRepository('agentAutoApprovalCheckpoints').count({
|
|
220
|
+
filter: { ownerId, sessionId: fixture.sessionId, interruptId: fixture.interruptId, status: 'issued' },
|
|
221
|
+
}),
|
|
222
|
+
).toBe(1);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('uses a fresh claim for a new interrupt and keeps single-tool approval on the native path', async () => {
|
|
226
|
+
const fixture = await createCheckpointFixture();
|
|
227
|
+
const callA = fixture.calls[0];
|
|
228
|
+
if (!callA) throw new Error('The checkpoint fixture has no first tool.');
|
|
229
|
+
const first = await decide(
|
|
230
|
+
{ sessionId: fixture.sessionId, messageId: fixture.messageId, toolCallId: callA.id },
|
|
231
|
+
'approve',
|
|
232
|
+
true,
|
|
233
|
+
);
|
|
234
|
+
expect(first.body.data.agentAutoApprovalCheckpoint.canFinalize).toBe(false);
|
|
235
|
+
|
|
236
|
+
const nextInterruptId = `interrupt-${randomUUID()}`;
|
|
237
|
+
await app.db
|
|
238
|
+
.getModel('aiMessages')
|
|
239
|
+
.update(
|
|
240
|
+
{ metadata: { interruptId: nextInterruptId } },
|
|
241
|
+
{ where: { sessionId: fixture.sessionId, messageId: Number(fixture.messageId) } },
|
|
242
|
+
);
|
|
243
|
+
await app.db
|
|
244
|
+
.getModel('aiToolMessages')
|
|
245
|
+
.update(
|
|
246
|
+
{ invokeStatus: 'interrupted', status: null, content: null, userDecision: null, auto: false },
|
|
247
|
+
{ where: { sessionId: fixture.sessionId, messageId: Number(fixture.messageId) } },
|
|
248
|
+
);
|
|
249
|
+
await ownerAgent.resource('agentAutoApproval').set({
|
|
250
|
+
values: { sessionId: fixture.sessionId, enabled: true },
|
|
251
|
+
});
|
|
252
|
+
const second = await decide(
|
|
253
|
+
{ sessionId: fixture.sessionId, messageId: fixture.messageId, toolCallId: callA.id },
|
|
254
|
+
'approve',
|
|
255
|
+
true,
|
|
256
|
+
);
|
|
257
|
+
expect(second.body.data.agentAutoApprovalCheckpoint.interruptId).toBe(nextInterruptId);
|
|
258
|
+
expect(second.body.data.agentAutoApprovalCheckpoint.canFinalize).toBe(false);
|
|
259
|
+
expect(
|
|
260
|
+
await app.db
|
|
261
|
+
.getRepository('agentAutoApprovalCheckpoints')
|
|
262
|
+
.count({ filter: { ownerId, sessionId: fixture.sessionId } }),
|
|
263
|
+
).toBe(2);
|
|
264
|
+
|
|
265
|
+
const single = await createCheckpointFixture({
|
|
266
|
+
calls: [{ id: `call-single-${randomUUID()}`, name: toolA, args: { value: 'single' }, interrupt: true }],
|
|
267
|
+
});
|
|
268
|
+
const singleCall = single.calls[0];
|
|
269
|
+
if (!singleCall) throw new Error('The single-tool checkpoint fixture is incomplete.');
|
|
270
|
+
const singleResult = await decide(
|
|
271
|
+
{ sessionId: single.sessionId, messageId: single.messageId, toolCallId: singleCall.id },
|
|
272
|
+
'approve',
|
|
273
|
+
true,
|
|
274
|
+
);
|
|
275
|
+
expect(singleResult.body.data.updated).toBe(1);
|
|
276
|
+
expect(singleResult.body.data.agentAutoApprovalCheckpoint).toBeUndefined();
|
|
277
|
+
expect(
|
|
278
|
+
await app.db.getRepository('agentAutoApprovalCheckpoints').count({ filter: { sessionId: single.sessionId } }),
|
|
279
|
+
).toBe(0);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('rejects direct access to checkpoint records', async () => {
|
|
283
|
+
const result = await ownerAgent.resource('agentAutoApprovalCheckpoints').create({
|
|
284
|
+
values: {
|
|
285
|
+
checkpointKey: `manual-${randomUUID()}`,
|
|
286
|
+
ownerId,
|
|
287
|
+
sessionId: randomUUID(),
|
|
288
|
+
messageId: 'manual',
|
|
289
|
+
interruptId: 'manual',
|
|
290
|
+
status: 'pending',
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
expect(result.status).toBe(403);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import { describe, expect, it, vi } from 'vitest';
|
|
11
4
|
import type { Plugin } from '@nocobase/server';
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
|
|
1
10
|
import { describe, expect, it } from 'vitest';
|
|
2
11
|
import { compileHarness, decideTool } from '../services/HarnessCompiler';
|
|
3
12
|
import { parseHarnessSettings, validateHarnessSettings } from '../services/HarnessSchema';
|
|
@@ -25,6 +34,28 @@ describe('HarnessSchema', () => {
|
|
|
25
34
|
expect(validateHarnessSettings({ limits: { recursionLimit: 0 } }).success).toBe(false);
|
|
26
35
|
expect(validateHarnessSettings({ unsupported: true }).success).toBe(false);
|
|
27
36
|
});
|
|
37
|
+
|
|
38
|
+
it('keeps legacy profiles valid and validates configured routing models', () => {
|
|
39
|
+
expect(parseHarnessSettings({}).routing).toBeUndefined();
|
|
40
|
+
expect(
|
|
41
|
+
validateHarnessSettings({
|
|
42
|
+
routing: {
|
|
43
|
+
models: {
|
|
44
|
+
primary: { llmService: ' fast ', model: ' lite ' },
|
|
45
|
+
fallback: [{ llmService: 'backup', model: 'backup-lite' }],
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
}).success,
|
|
49
|
+
).toBe(true);
|
|
50
|
+
expect(
|
|
51
|
+
validateHarnessSettings({ routing: { models: { primary: { llmService: '', model: 'lite' } } } }).success,
|
|
52
|
+
).toBe(false);
|
|
53
|
+
expect(
|
|
54
|
+
validateHarnessSettings({
|
|
55
|
+
routing: { models: { fallback: Array.from({ length: 21 }, () => ({ llmService: 'backup', model: 'lite' })) } },
|
|
56
|
+
}).success,
|
|
57
|
+
).toBe(false);
|
|
58
|
+
});
|
|
28
59
|
});
|
|
29
60
|
|
|
30
61
|
describe('HarnessCompiler', () => {
|
|
@@ -211,4 +242,37 @@ describe('HarnessCompiler', () => {
|
|
|
211
242
|
|
|
212
243
|
expect(compiled.tools.escalate).toEqual(['deployService']);
|
|
213
244
|
});
|
|
245
|
+
|
|
246
|
+
it('takes the most-specific routing models while retaining restrictive limits', () => {
|
|
247
|
+
const compiled = compileHarness([
|
|
248
|
+
{
|
|
249
|
+
source: 'platform',
|
|
250
|
+
settings: {
|
|
251
|
+
routing: { models: { primary: { llmService: 'shared', model: 'strong' } } },
|
|
252
|
+
limits: { timeoutMs: 90_000, maxInvocations: 8 },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
source: 'specialist',
|
|
257
|
+
settings: {
|
|
258
|
+
routing: {
|
|
259
|
+
models: {
|
|
260
|
+
primary: { llmService: 'fast', model: 'lite' },
|
|
261
|
+
fallback: [{ llmService: 'backup', model: 'backup-lite' }],
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
limits: { timeoutMs: 30_000, maxInvocations: 3 },
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
]);
|
|
268
|
+
|
|
269
|
+
expect(compiled.routing).toEqual({
|
|
270
|
+
models: {
|
|
271
|
+
primary: { llmService: 'fast', model: 'lite' },
|
|
272
|
+
fallback: [{ llmService: 'backup', model: 'backup-lite' }],
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
expect(compiled.limits.timeoutMs).toBe(30_000);
|
|
276
|
+
expect(compiled.limits.maxInvocations).toBe(3);
|
|
277
|
+
});
|
|
214
278
|
});
|
|
@@ -1,11 +1,4 @@
|
|
|
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
|
-
*/
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
2
|
|
|
10
3
|
import type { Application } from '@nocobase/server';
|
|
11
4
|
import { describe, expect, it } from 'vitest';
|