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,167 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import type { Context, Next } from '@nocobase/actions';
|
|
3
|
+
import type { Filter, Model } from '@nocobase/database';
|
|
4
|
+
import { getAIToolsManager } from '../utils/ai-manager';
|
|
5
|
+
import { asRecord, read } from '../utils/record-utils';
|
|
6
|
+
import { getSkillToolName } from '../utils/skill-tool-name';
|
|
7
|
+
import { parseJsonText } from '../skill-hub/utils/json-fields';
|
|
8
|
+
import {
|
|
9
|
+
autoApprovalCheckpoint,
|
|
10
|
+
coordinateAutoApprovalDecision,
|
|
11
|
+
enrollAutoApprovalCheckpoint,
|
|
12
|
+
} from './AutoApprovalCheckpoint';
|
|
13
|
+
|
|
14
|
+
const interactiveTools = new Set(['suggestions', 'aiEmployeeWorkflowTaskOutput']);
|
|
15
|
+
|
|
16
|
+
export type AutoApprovalCall = { sessionId: string; messageId: string; toolCallId: string };
|
|
17
|
+
|
|
18
|
+
export function autoApprovalCall(values: Record<string, unknown>): AutoApprovalCall | null {
|
|
19
|
+
const { sessionId, messageId, toolCallId } = values;
|
|
20
|
+
if (typeof sessionId !== 'string' || !sessionId.trim() || sessionId.length > 100) return null;
|
|
21
|
+
if (
|
|
22
|
+
!(
|
|
23
|
+
(typeof messageId === 'string' && messageId.trim()) ||
|
|
24
|
+
(typeof messageId === 'number' && Number.isSafeInteger(messageId) && messageId > 0)
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
return null;
|
|
28
|
+
if (typeof toolCallId !== 'string' || !toolCallId.trim()) return null;
|
|
29
|
+
return { sessionId, messageId: String(messageId), toolCallId };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The caller must already have verified access to the root conversation. */
|
|
33
|
+
export async function sessionAutoApprovalEnabled(ctx: Context, sessionId: string): Promise<boolean> {
|
|
34
|
+
const ownerId = ctx.auth?.user?.id;
|
|
35
|
+
if (!ownerId || !sessionId) return false;
|
|
36
|
+
const setting = await ctx.db.getRepository('agentSessionAutoApprovals').findOne({
|
|
37
|
+
filter: { ownerId, sessionId },
|
|
38
|
+
});
|
|
39
|
+
return read(setting, 'enabled') === true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Skill Hub interaction schemas request user input and must not be filled by an approval. */
|
|
43
|
+
export async function skillRequiresUserInput(ctx: Context, name: string, args: unknown): Promise<boolean> {
|
|
44
|
+
const repository = ctx.db.getRepository('skillDefinitions');
|
|
45
|
+
let skill;
|
|
46
|
+
if (name === 'skill_hub_execute') {
|
|
47
|
+
const input = asRecord(args);
|
|
48
|
+
if (input.action === 'list' || input.action === 'describe') return false;
|
|
49
|
+
if (input.action !== 'execute' || typeof input.skillName !== 'string' || !input.skillName) return true;
|
|
50
|
+
skill = await repository.findOne({ filter: { name: input.skillName, enabled: true } });
|
|
51
|
+
if (!skill) return true;
|
|
52
|
+
} else {
|
|
53
|
+
skill = await repository.findOne({ filter: { toolName: name, enabled: true } });
|
|
54
|
+
if (!skill && name.startsWith('skill_hub_')) {
|
|
55
|
+
const legacy = await repository.find({ filter: { enabled: true } });
|
|
56
|
+
skill = legacy.find((item: Model) => {
|
|
57
|
+
try {
|
|
58
|
+
return getSkillToolName(item) === name;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!skill) return false;
|
|
65
|
+
}
|
|
66
|
+
const skillId = read(skill, 'id');
|
|
67
|
+
if (typeof skillId !== 'number' && typeof skillId !== 'string') return true;
|
|
68
|
+
const loop = await ctx.db.getRepository('skillLoopConfigs').findOne({
|
|
69
|
+
filter: { enabled: true, skillId },
|
|
70
|
+
sort: ['-updatedAt'],
|
|
71
|
+
});
|
|
72
|
+
const loopSchema = parseJsonText<unknown>(read(loop, 'schema'), null);
|
|
73
|
+
if ((loopSchema && typeof loopSchema === 'object') || read(loop, 'prompt')) return true;
|
|
74
|
+
return Boolean(parseJsonText<unknown>(read(skill, 'interactionSchema'), null));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Verify the persisted root interrupt rather than trusting the event sent to the browser. */
|
|
78
|
+
export async function isAutoApprovalEligible(ctx: Context, call: AutoApprovalCall): Promise<boolean> {
|
|
79
|
+
const ownerId = ctx.auth?.user?.id;
|
|
80
|
+
if (!ownerId || !(await sessionAutoApprovalEnabled(ctx, call.sessionId))) return false;
|
|
81
|
+
const conversation = await ctx.db.getRepository('aiConversations').findOne({
|
|
82
|
+
filter: { sessionId: call.sessionId, userId: ownerId },
|
|
83
|
+
});
|
|
84
|
+
if (!conversation || read(conversation, 'from') === 'sub-agent') return false;
|
|
85
|
+
const username = read(conversation, 'aiEmployeeUsername');
|
|
86
|
+
if (typeof username !== 'string' || !username) return false;
|
|
87
|
+
const requestedRoles = ctx.state.currentRoles;
|
|
88
|
+
if (!Array.isArray(requestedRoles)) return false;
|
|
89
|
+
const memberships = await ctx.db.getRepository('rolesUsers').find({ filter: { userId: ownerId } });
|
|
90
|
+
const memberRoles = new Set(memberships.map((row: Model) => read(row, 'roleName')));
|
|
91
|
+
const roles = requestedRoles.filter(
|
|
92
|
+
(role: unknown): role is string => typeof role === 'string' && memberRoles.has(role),
|
|
93
|
+
);
|
|
94
|
+
if (!roles.length) return false;
|
|
95
|
+
if (
|
|
96
|
+
typeof ctx.state.currentRole === 'string' &&
|
|
97
|
+
ctx.state.currentRole !== '__union__' &&
|
|
98
|
+
!roles.includes(ctx.state.currentRole)
|
|
99
|
+
)
|
|
100
|
+
return false;
|
|
101
|
+
const filter: Filter = { username };
|
|
102
|
+
if (!roles.includes('root')) filter['roles.name'] = roles;
|
|
103
|
+
const employee = await ctx.db.getRepository('aiEmployees').findOne({ filter });
|
|
104
|
+
if (!employee || read(employee, 'enabled') === false) return false;
|
|
105
|
+
const message = await ctx.db.getRepository('aiMessages').findOne({
|
|
106
|
+
filter: { sessionId: call.sessionId, messageId: call.messageId, role: username },
|
|
107
|
+
});
|
|
108
|
+
const calls = read(message, 'toolCalls');
|
|
109
|
+
const selected = Array.isArray(calls) ? calls.map(asRecord).find((item) => item.id === call.toolCallId) : undefined;
|
|
110
|
+
const name = selected?.name;
|
|
111
|
+
if (typeof name !== 'string' || !name || interactiveTools.has(name)) return false;
|
|
112
|
+
if (await skillRequiresUserInput(ctx, name, selected.args)) return false;
|
|
113
|
+
const tool = await ctx.db.getRepository('aiToolMessages').findOne({
|
|
114
|
+
filter: { ...call, toolName: name, invokeStatus: 'interrupted' },
|
|
115
|
+
});
|
|
116
|
+
if (!tool || read(tool, 'auto') !== false || read(tool, 'status') === 'error') return false;
|
|
117
|
+
const interrupt = asRecord(read(tool, 'interruptAction'));
|
|
118
|
+
const interruptCall = asRecord(interrupt.toolCall);
|
|
119
|
+
const interruptedConversation = asRecord(interrupt.currentConversation);
|
|
120
|
+
const metadata = asRecord(read(message, 'metadata'));
|
|
121
|
+
if (
|
|
122
|
+
!Array.isArray(interrupt.allowedDecisions) ||
|
|
123
|
+
!interrupt.allowedDecisions.includes('approve') ||
|
|
124
|
+
interruptCall.id !== call.toolCallId ||
|
|
125
|
+
interruptCall.name !== name ||
|
|
126
|
+
interruptedConversation.sessionId !== call.sessionId ||
|
|
127
|
+
interruptedConversation.from !== 'main-agent' ||
|
|
128
|
+
interruptedConversation.username !== username ||
|
|
129
|
+
typeof metadata.interruptId !== 'string' ||
|
|
130
|
+
!metadata.interruptId
|
|
131
|
+
)
|
|
132
|
+
return false;
|
|
133
|
+
const entry = await getAIToolsManager(ctx.app).getTools(name, { ctx, sessionId: call.sessionId });
|
|
134
|
+
if (!entry || typeof entry.invoke !== 'function') return false;
|
|
135
|
+
if (name === 'executeFrontendTool') {
|
|
136
|
+
const toolId = asRecord(selected.args).toolId;
|
|
137
|
+
const options = asRecord(read(conversation, 'options'));
|
|
138
|
+
const tools = options.frontendTools;
|
|
139
|
+
if (typeof toolId !== 'string' || !Array.isArray(tools)) return false;
|
|
140
|
+
return tools
|
|
141
|
+
.map(asRecord)
|
|
142
|
+
.some((tool) => tool.id === toolId && tool.id === `${tool.blockUid}:${tool.name}` && tool.permission === 'ASK');
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Marked automatic decisions are rechecked as the native action receives them. */
|
|
148
|
+
export async function guardAutoApprovalDecision(ctx: Context, next: Next) {
|
|
149
|
+
if (ctx.action?.resourceName !== 'aiConversations' || ctx.action.actionName !== 'updateUserDecision') return next();
|
|
150
|
+
const values = asRecord(ctx.action.params?.values);
|
|
151
|
+
const automatic = values.agentAutoApproval === true;
|
|
152
|
+
const decision = asRecord(values.userDecision);
|
|
153
|
+
const call = autoApprovalCall(values);
|
|
154
|
+
if (automatic && (!call || decision.type !== 'approve' || !(await isAutoApprovalEligible(ctx, call)))) {
|
|
155
|
+
ctx.body = { updated: 0, toolCalls: [] };
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (!call) return next();
|
|
159
|
+
const checkpoint = await autoApprovalCheckpoint(ctx, call);
|
|
160
|
+
if (automatic && checkpoint === undefined) {
|
|
161
|
+
ctx.body = { updated: 0, toolCalls: [] };
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (automatic && checkpoint) await enrollAutoApprovalCheckpoint(ctx, checkpoint);
|
|
165
|
+
await next();
|
|
166
|
+
if (checkpoint) await coordinateAutoApprovalDecision(ctx, checkpoint, call);
|
|
167
|
+
}
|
|
@@ -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 { read } from '../utils/record-utils';
|
|
11
4
|
|
|
@@ -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
|
function positiveDays(value: unknown): number | null {
|
|
11
4
|
const days = typeof value === 'number' ? value : Number(value);
|
|
@@ -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 { Database, Model } from '@nocobase/database';
|
|
11
4
|
import type { CompiledHarness } from './HarnessCompiler';
|
|
@@ -156,7 +149,7 @@ export class VerificationService {
|
|
|
156
149
|
eventType: 'run_verified',
|
|
157
150
|
title: `Verifier returned ${verdict.verdict}`,
|
|
158
151
|
content: verdict.summary,
|
|
159
|
-
correlationKey: `verified:${input.
|
|
152
|
+
correlationKey: `verified:${input.leaseToken}`,
|
|
160
153
|
values: {
|
|
161
154
|
verifierVerdict: verdict.verdict,
|
|
162
155
|
verifierEvidence: verdict,
|
|
@@ -201,7 +194,7 @@ export class VerificationService {
|
|
|
201
194
|
eventType: finding.level === 'block' ? 'run_blocked' : 'run_escalated',
|
|
202
195
|
title: finding.level === 'block' ? 'Run blocked by tool loop detection' : 'Run escalated by tool loop detection',
|
|
203
196
|
content: reason,
|
|
204
|
-
correlationKey: `tool-loop-${finding.level}:${input.
|
|
197
|
+
correlationKey: `tool-loop-${finding.level}:${input.leaseToken}`,
|
|
205
198
|
values: finding.level === 'block' ? { blockedReason: reason } : { escalationReason: reason },
|
|
206
199
|
});
|
|
207
200
|
return 'halt';
|
|
@@ -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 { resolve } from 'path';
|
|
2
11
|
import { createReadStream, createWriteStream, unlinkSync } from 'fs';
|
|
3
12
|
import * as os from 'os';
|
|
@@ -886,6 +895,36 @@ export class SkillHubSubFeature {
|
|
|
886
895
|
return configsBySkillId;
|
|
887
896
|
}
|
|
888
897
|
|
|
898
|
+
async assertSkillReviewApproved(
|
|
899
|
+
skill: unknown,
|
|
900
|
+
runtime: ToolRuntimeInput,
|
|
901
|
+
toolName: string,
|
|
902
|
+
ctx?: { t?: (key: string, options: { ns: string }) => string },
|
|
903
|
+
) {
|
|
904
|
+
const loopConfig = await this.db.getRepository('skillLoopConfigs').findOne({
|
|
905
|
+
filter: { enabled: true, skillId: this.getSkillRecordId(skill) },
|
|
906
|
+
sort: ['-updatedAt'],
|
|
907
|
+
});
|
|
908
|
+
const interactionSchema =
|
|
909
|
+
this.resolveLoopInteractionSchema(loopConfig) || parseJsonText(readRecordValue(skill, 'interactionSchema'), null);
|
|
910
|
+
if (!interactionSchema) return;
|
|
911
|
+
|
|
912
|
+
const toolCallId = normalizeToolRuntime(runtime)?.toolCallId;
|
|
913
|
+
const call = toolCallId
|
|
914
|
+
? await this.db.getRepository('aiToolMessages').findOne({ filter: { toolCallId, toolName } })
|
|
915
|
+
: null;
|
|
916
|
+
const decision = readRecordValue(readRecordValue(call, 'userDecision'), 'type');
|
|
917
|
+
if (
|
|
918
|
+
readRecordValue(call, 'auto') !== false ||
|
|
919
|
+
readRecordValue(call, 'invokeStatus') !== 'pending' ||
|
|
920
|
+
(decision !== 'approve' && decision !== 'edit')
|
|
921
|
+
) {
|
|
922
|
+
const message =
|
|
923
|
+
'Human review is required for this skill. Disable Auto call and approve the tool call before execution.';
|
|
924
|
+
throw new Error(ctx?.t?.(message, { ns: 'plugin-agent-orchestrator' }) || message);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
889
928
|
private registerAITools() {
|
|
890
929
|
try {
|
|
891
930
|
// Register on the SAME tools manager the harness resolves from
|
|
@@ -952,6 +991,7 @@ export class SkillHubSubFeature {
|
|
|
952
991
|
if (!latestSkill) {
|
|
953
992
|
return { status: 'error', content: `Skill "${skill.get('name')}" is no longer available` };
|
|
954
993
|
}
|
|
994
|
+
await this.assertSkillReviewApproved(latestSkill, runtime, getSkillToolName(skill), toolCtx);
|
|
955
995
|
const result = await this.executeSkill(latestSkill, args, toolCtx);
|
|
956
996
|
return {
|
|
957
997
|
status: result.status === 'succeeded' ? 'success' : 'error',
|
|
@@ -1,9 +1,19 @@
|
|
|
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 { createHash } from 'crypto';
|
|
2
11
|
|
|
3
12
|
import type { Database } from '@nocobase/database';
|
|
4
13
|
|
|
5
14
|
import type { SkillRepositoryService } from '../../services/SkillRepositoryService';
|
|
6
15
|
import { assertSkillToolNameAvailable, buildSkillToolName } from '../../utils/skill-tool-name';
|
|
16
|
+
import { registryNodeWrapper } from './registry-node-package';
|
|
7
17
|
|
|
8
18
|
export interface RegistryInstallationInput {
|
|
9
19
|
registryPackageId: string | number;
|
|
@@ -84,7 +94,7 @@ function executionWrapper(runtime: 'python' | 'node', entrypoint: string): strin
|
|
|
84
94
|
'',
|
|
85
95
|
].join('\n');
|
|
86
96
|
}
|
|
87
|
-
return
|
|
97
|
+
return registryNodeWrapper(entrypoint);
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
export class RegistrySkillInstallationService {
|
|
@@ -0,0 +1,191 @@
|
|
|
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
|
+
import { lstatSync, readFileSync, readdirSync, realpathSync } from 'fs';
|
|
11
|
+
import { createRequire } from 'module';
|
|
12
|
+
import { dirname, extname, isAbsolute, relative, resolve, sep } from 'path';
|
|
13
|
+
import { Script } from 'vm';
|
|
14
|
+
import {
|
|
15
|
+
parse,
|
|
16
|
+
type CallExpression,
|
|
17
|
+
type ExpressionStatement,
|
|
18
|
+
type FunctionExpression,
|
|
19
|
+
type Identifier,
|
|
20
|
+
type MemberExpression,
|
|
21
|
+
} from 'acorn';
|
|
22
|
+
import { fullAncestor } from 'acorn-walk';
|
|
23
|
+
import { CodeValidator } from '../../services/CodeValidator';
|
|
24
|
+
|
|
25
|
+
export function registryNodeWrapper(entrypoint: string): string {
|
|
26
|
+
return `require(${JSON.stringify(`./skill/${entrypoint}`)});\n`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function registryNodeEntrypoint(template: string, translate: (message: string) => string): string | null {
|
|
30
|
+
const legacy = template.match(
|
|
31
|
+
/^require\(require\('path'\)\.join\(process\.env\.SKILL_DIR, ("(?:[^"\\]|\\.)*")\)\);\s*$/,
|
|
32
|
+
);
|
|
33
|
+
const current = template.match(/^require\(("(?:[^"\\]|\\.)*")\);\s*$/);
|
|
34
|
+
if (!legacy && !current) return null;
|
|
35
|
+
let path: string;
|
|
36
|
+
try {
|
|
37
|
+
path = JSON.parse((legacy || current)[1]) as string;
|
|
38
|
+
} catch {
|
|
39
|
+
throw new Error(translate('Registry Node package requires must stay inside the package.'));
|
|
40
|
+
}
|
|
41
|
+
if (current && !path.startsWith('./skill/')) return null;
|
|
42
|
+
const entrypoint = current ? path.slice('./skill/'.length) : path;
|
|
43
|
+
if (
|
|
44
|
+
!entrypoint ||
|
|
45
|
+
/[\\:\0]/.test(entrypoint) ||
|
|
46
|
+
entrypoint.split('/').some((part) => !part || part === '.' || part === '..')
|
|
47
|
+
) {
|
|
48
|
+
throw new Error(translate('Registry Node package requires must stay inside the package.'));
|
|
49
|
+
}
|
|
50
|
+
return entrypoint;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Validate the copied package's reachable CommonJS modules before the sandbox loads them. */
|
|
54
|
+
export function validateRegistryNodePackage(
|
|
55
|
+
code: string,
|
|
56
|
+
workDir: string,
|
|
57
|
+
packageDir: string,
|
|
58
|
+
whitelist: string[],
|
|
59
|
+
translate: (message: string) => string,
|
|
60
|
+
): void {
|
|
61
|
+
const fail: (message: string) => never = (message) => {
|
|
62
|
+
throw new Error(translate(message));
|
|
63
|
+
};
|
|
64
|
+
const packageRoot = realpathSync(packageDir);
|
|
65
|
+
const workRoot = realpathSync(workDir);
|
|
66
|
+
const checkDirectory = (directory: string) => {
|
|
67
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
68
|
+
const path = resolve(directory, entry.name);
|
|
69
|
+
if (entry.isSymbolicLink()) {
|
|
70
|
+
fail('Registry Node packages cannot contain symbolic links or bundled node_modules.');
|
|
71
|
+
}
|
|
72
|
+
if (entry.isDirectory()) {
|
|
73
|
+
if (entry.name.toLowerCase() === 'node_modules') {
|
|
74
|
+
fail('Registry Node packages cannot contain symbolic links or bundled node_modules.');
|
|
75
|
+
}
|
|
76
|
+
checkDirectory(path);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
if (!lstatSync(packageDir).isDirectory()) {
|
|
81
|
+
fail('Registry Node package requires must stay inside the package.');
|
|
82
|
+
}
|
|
83
|
+
checkDirectory(packageDir);
|
|
84
|
+
|
|
85
|
+
const validator = new CodeValidator();
|
|
86
|
+
const visited = new Set<string>();
|
|
87
|
+
const visit = (source: string, filename: string) => {
|
|
88
|
+
validator.validate(source, 'node', { allowSkillInputFile: filename !== resolve(workRoot, 'script.js') });
|
|
89
|
+
validator.validateImports(source, 'node', whitelist);
|
|
90
|
+
let wrapper: FunctionExpression;
|
|
91
|
+
try {
|
|
92
|
+
const commonJsSource = source.replace(/^\uFEFF/, '').replace(/^#![^\r\n]*/, '');
|
|
93
|
+
const wrappedSource = `(function(exports, require, module, __filename, __dirname) {\n${commonJsSource}\n});`;
|
|
94
|
+
new Script(wrappedSource);
|
|
95
|
+
const parsed = parse(wrappedSource, { ecmaVersion: 'latest' });
|
|
96
|
+
wrapper = (parsed.body[0] as ExpressionStatement).expression as FunctionExpression;
|
|
97
|
+
} catch {
|
|
98
|
+
fail('Registry Node packages must use valid CommonJS code and cannot load native modules.');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const entrypoint = filename === resolve(workRoot, 'script.js') ? registryNodeEntrypoint(source, translate) : null;
|
|
102
|
+
const requests: string[] = [];
|
|
103
|
+
const requireError = 'Registry Node packages must use direct require calls with literal, unescaped paths.';
|
|
104
|
+
fullAncestor(wrapper.body, (node, _state, ancestors) => {
|
|
105
|
+
if (node.type === 'Identifier') {
|
|
106
|
+
const identifier = node as Identifier;
|
|
107
|
+
const parent = ancestors[ancestors.length - 2];
|
|
108
|
+
if (identifier.name === 'require') {
|
|
109
|
+
const call = parent as CallExpression;
|
|
110
|
+
if (parent?.type !== 'CallExpression' || call.callee !== node || call.optional) fail(requireError);
|
|
111
|
+
}
|
|
112
|
+
if (identifier.name === 'module') {
|
|
113
|
+
const member = parent as MemberExpression;
|
|
114
|
+
const property = member?.property;
|
|
115
|
+
const isExports =
|
|
116
|
+
parent?.type === 'MemberExpression' &&
|
|
117
|
+
member.object === node &&
|
|
118
|
+
((!member.computed && property.type === 'Identifier' && property.name === 'exports') ||
|
|
119
|
+
(member.computed && property.type === 'Literal' && property.value === 'exports'));
|
|
120
|
+
if (!isExports) fail(requireError);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (node.type === 'CallExpression') {
|
|
124
|
+
const call = node as CallExpression;
|
|
125
|
+
if (call.callee.type !== 'Identifier' || call.callee.name !== 'require') return;
|
|
126
|
+
const argument = call.arguments[0];
|
|
127
|
+
if (
|
|
128
|
+
call.arguments.length !== 1 ||
|
|
129
|
+
argument.type !== 'Literal' ||
|
|
130
|
+
typeof argument.value !== 'string' ||
|
|
131
|
+
(!entrypoint && argument.raw?.includes('\\'))
|
|
132
|
+
) {
|
|
133
|
+
fail(requireError);
|
|
134
|
+
}
|
|
135
|
+
requests.push(argument.value);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
for (const request of requests) {
|
|
139
|
+
if (isAbsolute(request) || /^[A-Za-z]:/.test(request) || request.startsWith('#')) {
|
|
140
|
+
fail('Registry Node package requires must stay inside the package.');
|
|
141
|
+
}
|
|
142
|
+
if (!['.', '..'].includes(request) && !request.startsWith('./') && !request.startsWith('../')) continue;
|
|
143
|
+
|
|
144
|
+
const requestedPath = resolve(dirname(filename), request);
|
|
145
|
+
const requestedRelative = relative(packageRoot, requestedPath);
|
|
146
|
+
if (requestedRelative === '..' || requestedRelative.startsWith(`..${sep}`) || isAbsolute(requestedRelative)) {
|
|
147
|
+
fail('Registry Node package requires must stay inside the package.');
|
|
148
|
+
}
|
|
149
|
+
let resolved: string;
|
|
150
|
+
try {
|
|
151
|
+
resolved = realpathSync(createRequire(filename).resolve(request));
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if ((error as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
|
|
154
|
+
fail('Registry Node package contains a missing local module.');
|
|
155
|
+
}
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
const inside = relative(packageRoot, resolved);
|
|
159
|
+
if (!inside || inside === '..' || inside.startsWith(`..${sep}`) || isAbsolute(inside)) {
|
|
160
|
+
fail('Registry Node package requires must stay inside the package.');
|
|
161
|
+
}
|
|
162
|
+
if (resolved === resolve(workRoot, 'script.js')) {
|
|
163
|
+
fail('Registry Node package requires must stay inside the package.');
|
|
164
|
+
}
|
|
165
|
+
const extension = extname(resolved);
|
|
166
|
+
if (extension === '.node' || extension === '.mjs') {
|
|
167
|
+
fail('Registry Node packages must use valid CommonJS code and cannot load native modules.');
|
|
168
|
+
}
|
|
169
|
+
if (extension === '.json' || visited.has(resolved)) continue;
|
|
170
|
+
visited.add(resolved);
|
|
171
|
+
|
|
172
|
+
for (let directory = dirname(resolved); extension !== '.cjs'; directory = dirname(directory)) {
|
|
173
|
+
const packageJson = resolve(directory, 'package.json');
|
|
174
|
+
if (lstatSync(directory).isDirectory()) {
|
|
175
|
+
try {
|
|
176
|
+
const metadata = JSON.parse(readFileSync(packageJson, 'utf8')) as { type?: unknown };
|
|
177
|
+
if (metadata.type === 'module') {
|
|
178
|
+
fail('Registry Node packages must use valid CommonJS code and cannot load native modules.');
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (directory === packageRoot) break;
|
|
186
|
+
}
|
|
187
|
+
visit(readFileSync(resolved, 'utf8'), resolved);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
visit(code, resolve(workRoot, 'script.js'));
|
|
191
|
+
}
|
|
@@ -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 Application from '@nocobase/server';
|
|
2
11
|
import { cpSync, existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
|
|
3
12
|
import { resolve, sep } from 'path';
|
|
@@ -9,6 +18,11 @@ import { spilledText } from '../../services/harness-runtime-policy';
|
|
|
9
18
|
import { createHash } from 'crypto';
|
|
10
19
|
import { assertSkillToolNameAvailable, buildSkillToolName } from '../../utils/skill-tool-name';
|
|
11
20
|
import { parseJsonLike, parseJsonText, stringifyJsonText } from '../utils/json-fields';
|
|
21
|
+
import {
|
|
22
|
+
registryNodeEntrypoint,
|
|
23
|
+
registryNodeWrapper,
|
|
24
|
+
validateRegistryNodePackage,
|
|
25
|
+
} from '../services/registry-node-package';
|
|
12
26
|
|
|
13
27
|
/**
|
|
14
28
|
* Lightweight abort controller compatible with the SandboxRunner signal interface.
|
|
@@ -180,11 +194,18 @@ export class SkillExecutionTask {
|
|
|
180
194
|
);
|
|
181
195
|
}
|
|
182
196
|
|
|
197
|
+
const registryPackageId = skill.get ? skill.get('registryPackageId') : skill.registryPackageId;
|
|
198
|
+
const registryNode = storageType !== 'plugin' && language === 'node' && !!registryPackageId;
|
|
199
|
+
const translateRegistryError = (message: string) =>
|
|
200
|
+
this.app.i18n?.t?.(message, { ns: 'plugin-agent-orchestrator' }) || message;
|
|
201
|
+
const entrypoint = registryNode ? registryNodeEntrypoint(rawCodeTemplate, translateRegistryError) : null;
|
|
183
202
|
if (storageType !== 'plugin') {
|
|
184
|
-
skillDir = workDir;
|
|
203
|
+
skillDir = entrypoint ? resolve(workDir, 'skill') : workDir;
|
|
185
204
|
}
|
|
186
205
|
|
|
187
|
-
const code =
|
|
206
|
+
const code = entrypoint
|
|
207
|
+
? registryNodeWrapper(entrypoint)
|
|
208
|
+
: this.renderTemplate(rawCodeTemplate, inputArgs, execId, skillDir);
|
|
188
209
|
const skillDigest = createHash('sha256').update(code, 'utf8').digest('hex');
|
|
189
210
|
if (!(await this.updateIfOwned(execId, workerId, { executedCode: code, skillDigest }))) {
|
|
190
211
|
abortController.abort();
|
|
@@ -260,8 +281,12 @@ export class SkillExecutionTask {
|
|
|
260
281
|
}
|
|
261
282
|
|
|
262
283
|
if (storageType !== 'plugin') {
|
|
263
|
-
|
|
264
|
-
skillDir
|
|
284
|
+
if (entrypoint) rmSync(skillDir, { recursive: true, force: true });
|
|
285
|
+
this.skillRepoService.copySkillPackageTo(skillName, skillDir);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (registryNode) {
|
|
289
|
+
validateRegistryNodePackage(code, workDir, skillDir, packageWhitelist, translateRegistryError);
|
|
265
290
|
}
|
|
266
291
|
|
|
267
292
|
const result = await this.sandboxRunner.execute({
|
|
@@ -271,6 +296,7 @@ export class SkillExecutionTask {
|
|
|
271
296
|
timeoutSeconds: timeoutSeconds || 60,
|
|
272
297
|
maxOutputSizeMb: maxOutputSizeMb || 50,
|
|
273
298
|
skillDir,
|
|
299
|
+
packageSnapshotDir: entrypoint ? skillDir : undefined,
|
|
274
300
|
inputArgs,
|
|
275
301
|
signal: abortController.signal,
|
|
276
302
|
packageWhitelist,
|
|
@@ -356,7 +382,10 @@ export class SkillExecutionTask {
|
|
|
356
382
|
`outputSize=${this.fileManager.getTotalOutputSize(execId)}bytes`,
|
|
357
383
|
);
|
|
358
384
|
} catch (error) {
|
|
359
|
-
|
|
385
|
+
let errorMessage = error instanceof Error ? error.message : String(error);
|
|
386
|
+
if (errorMessage === 'Invalid skill package snapshot path.') {
|
|
387
|
+
errorMessage = this.app.i18n?.t?.(errorMessage, { ns: 'plugin-agent-orchestrator' }) || errorMessage;
|
|
388
|
+
}
|
|
360
389
|
|
|
361
390
|
const failed = await this.updateIfOwned(execId, workerId, {
|
|
362
391
|
status: 'failed',
|
|
@@ -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 { parseJsonText } from '../skill-hub/utils/json-fields';
|
|
2
11
|
import type { ToolsRuntime } from '@nocobase/ai';
|
|
3
12
|
import { getSkillToolName } from '../utils/skill-tool-name';
|
|
@@ -165,6 +174,7 @@ IMPORTANT: If the skill returns file download URLs, you MUST format them as clic
|
|
|
165
174
|
}
|
|
166
175
|
|
|
167
176
|
try {
|
|
177
|
+
await plugin.assertSkillReviewApproved(skill, runtime, 'skill_hub_execute', ctx);
|
|
168
178
|
const normalizedRuntime = normalizeRuntime(runtime);
|
|
169
179
|
const previousRuntime = ctx.runtime;
|
|
170
180
|
if (normalizedRuntime) {
|
|
@@ -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 { Database } from '@nocobase/database';
|
|
11
4
|
|
|
@@ -13,6 +6,7 @@ const INDEXED_COLLECTIONS = [
|
|
|
13
6
|
'agentExecutionSpans',
|
|
14
7
|
'agentHarnessProfiles',
|
|
15
8
|
'agentHarnessProfileVersions',
|
|
9
|
+
'agentHierarchyInvocations',
|
|
16
10
|
'agentLoopActionApprovals',
|
|
17
11
|
'agentLoopArtifacts',
|
|
18
12
|
'agentLoopCircuitStates',
|