plugin-agent-orchestrator 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -114
- package/dist/client/index.js +1 -1
- package/dist/client-v2/117.7565cff57c39318a.js +10 -0
- package/dist/client-v2/214.106635011859dede.js +10 -0
- package/dist/client-v2/253.59577b40d9875be0.js +10 -0
- package/dist/client-v2/264.7ed8bee71fa5935c.js +10 -0
- package/dist/client-v2/{41.ba6e080cc0488143.js → 41.3deb9e57a0f64fc4.js} +1 -1
- package/dist/client-v2/418.41ed200e7d6da332.js +10 -0
- package/dist/client-v2/53.349fff8db80b19d4.js +10 -0
- package/dist/client-v2/619.0a2144aaffefe018.js +10 -0
- package/dist/client-v2/{70.bda9518881c05360.js → 70.ffff2997c10fd4b0.js} +1 -1
- package/dist/client-v2/{794.9bbb8d3a61b2bdf2.js → 794.a67a2614405ba627.js} +1 -1
- package/dist/client-v2/981.e4a1f41cfc94a856.js +10 -0
- package/dist/client-v2/{993.82778b6fd6db3cb1.js → 993.b0688fdc5ccb000a.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -7
- package/dist/locale/en-US.json +199 -123
- package/dist/locale/vi-VN.json +199 -123
- package/dist/locale/zh-CN.json +199 -123
- package/dist/server/collections/agent-execution-spans.js +55 -0
- package/dist/server/collections/agent-harness-profile-versions.js +56 -0
- package/dist/server/collections/agent-harness-profiles.js +12 -0
- package/dist/server/collections/agent-loop-action-approvals.js +69 -0
- package/dist/server/collections/agent-loop-artifacts.js +55 -0
- package/dist/server/collections/agent-loop-circuit-states.js +53 -0
- package/dist/server/collections/agent-loop-control-settings.js +51 -0
- package/dist/server/collections/agent-loop-events.js +27 -0
- package/dist/server/collections/agent-loop-path-locks.js +57 -0
- package/dist/server/collections/agent-loop-patterns.js +72 -0
- package/dist/server/collections/agent-loop-runs.js +170 -3
- package/dist/server/collections/agent-loop-steps.js +76 -0
- package/dist/server/collections/agent-loop-usage-buckets.js +52 -0
- package/dist/server/collections/agent-loop-worktrees.js +55 -0
- package/dist/server/collections/skill-executions.js +8 -0
- package/dist/server/migrations/{20260427000000-change-packages-to-text.js → 20260427000002-change-packages-to-text.js} +2 -0
- package/dist/server/migrations/20260429000000-add-llm-fields.js +3 -2
- package/dist/server/migrations/{20260429000000-fix-inputargs-json-to-text.js → 20260429000001-fix-inputargs-json-to-text.js} +14 -6
- package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +2 -1
- package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +2 -1
- package/dist/server/migrations/20260803010000-backfill-loop-control-plane-data.js +262 -0
- package/dist/server/plugin.js +54 -150
- package/dist/server/resources/agent-harness-profile.js +117 -0
- package/dist/server/resources/agent-knowledge-insights.js +1 -3
- package/dist/server/resources/agent-loop-approval.js +108 -0
- package/dist/server/resources/agent-loop-artifact.js +86 -0
- package/dist/server/resources/agent-loop-events-stream.js +130 -0
- package/dist/server/resources/agent-loop.js +183 -139
- package/dist/server/resources/resource-helpers.js +63 -0
- package/dist/server/resources/tracing.js +121 -107
- package/dist/server/services/AgentMemoryContextService.js +34 -0
- package/dist/server/services/DurableCircuitBreakerService.js +229 -0
- package/dist/server/services/HarnessCompiler.js +175 -0
- package/dist/server/services/HarnessProfileService.js +233 -0
- package/dist/server/services/HarnessSchema.js +194 -0
- package/dist/server/services/LoopBudgetService.js +269 -0
- package/dist/server/services/LoopControlService.js +139 -0
- package/dist/server/services/LoopPatternSchema.js +195 -0
- package/dist/server/services/LoopPatternService.js +132 -0
- package/dist/server/services/LoopRunRepository.js +285 -0
- package/dist/server/services/LoopRunStateMachine.js +478 -0
- package/dist/server/services/LoopSchedulerService.js +193 -0
- package/dist/server/services/LoopTriggerService.js +165 -0
- package/dist/server/services/LoopWorkerService.js +699 -0
- package/dist/server/services/NativeSubAgentObserver.js +165 -23
- package/dist/server/services/PathLockService.js +288 -0
- package/dist/server/services/PluginAiRuntimeAdapter.js +226 -0
- package/dist/server/services/ToolLoopDetectionService.js +210 -0
- package/dist/server/services/VerificationSchema.js +59 -0
- package/dist/server/services/VerificationService.js +235 -0
- package/dist/server/services/harness-runtime-policy.js +139 -0
- package/dist/server/skill-hub/actions/git-import.js +13 -7
- package/dist/server/skill-hub/plugin.js +36 -3
- package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +1 -5
- package/dist/server/skill-hub/tasks/SkillExecutionTask.js +29 -0
- package/dist/server/utils/ensure-indexes.js +111 -0
- package/dist/server/utils/loop-pattern-context.js +56 -0
- package/package.json +53 -53
- package/src/client/ApprovalsTab.tsx +2 -0
- package/src/client/OrchestratorSettings.tsx +55 -0
- package/src/client/skill-hub/components/GitSkillImport.tsx +3 -3
- package/src/client/skill-hub/components/SkillMetrics.tsx +15 -10
- package/src/client/skill-hub/index.tsx +0 -52
- package/src/client-v2/components/AgentRunsTab.tsx +100 -18
- package/src/client-v2/components/ApprovalsTab.tsx +337 -0
- package/src/client-v2/components/HarnessProfilesTab.tsx +385 -100
- package/src/client-v2/components/MemoryInspectorTab.tsx +141 -125
- package/src/client-v2/components/TracingTab.tsx +160 -77
- package/src/client-v2/hooks/useApiRequest.ts +28 -8
- package/src/client-v2/pages/ApprovalsPage.tsx +10 -0
- package/src/client-v2/plugin.tsx +6 -6
- package/src/client-v2/skill-hub/components/SkillMetrics.tsx +11 -6
- package/src/locale/en-US.json +199 -123
- package/src/locale/vi-VN.json +199 -123
- package/src/locale/zh-CN.json +199 -123
- package/src/server/__tests__/circuit-breaker.test.ts +248 -169
- package/src/server/__tests__/harness-compiler.test.ts +214 -0
- package/src/server/__tests__/harness-profile-service.test.ts +167 -0
- package/src/server/__tests__/harness-runtime-policy.test.ts +293 -0
- package/src/server/__tests__/harness-tool-plan.test.ts +172 -0
- package/src/server/__tests__/loop-approval-decision.test.ts +512 -0
- package/src/server/__tests__/loop-approval-expiry.test.ts +258 -0
- package/src/server/__tests__/loop-budget-service.test.ts +255 -0
- package/src/server/__tests__/loop-control-plane-backfill.test.ts +266 -0
- package/src/server/__tests__/loop-pattern-schema.test.ts +73 -0
- package/src/server/__tests__/loop-pattern-service.test.ts +148 -0
- package/src/server/__tests__/loop-run-state-machine.test.ts +101 -0
- package/src/server/__tests__/loop-trigger-service.test.ts +148 -0
- package/src/server/__tests__/loop-worker-claim.test.ts +341 -0
- package/src/server/__tests__/loop-worker-execution.test.ts +317 -0
- package/src/server/__tests__/native-sub-agent-observer.test.ts +288 -4
- package/src/server/__tests__/path-lock-service.test.ts +254 -0
- package/src/server/__tests__/skill-execution-task-policy.test.ts +140 -0
- package/src/server/__tests__/smoke.test.ts +162 -121
- package/src/server/__tests__/tool-loop-detection.test.ts +275 -0
- package/src/server/collections/agent-execution-spans.ts +55 -0
- package/src/server/collections/agent-harness-profile-versions.ts +26 -0
- package/src/server/collections/agent-harness-profiles.ts +71 -59
- package/src/server/collections/agent-loop-action-approvals.ts +39 -0
- package/src/server/collections/agent-loop-artifacts.ts +25 -0
- package/src/server/collections/agent-loop-circuit-states.ts +23 -0
- package/src/server/collections/agent-loop-control-settings.ts +21 -0
- package/src/server/collections/agent-loop-events.ts +98 -71
- package/src/server/collections/agent-loop-path-locks.ts +27 -0
- package/src/server/collections/agent-loop-patterns.ts +42 -0
- package/src/server/collections/agent-loop-runs.ts +170 -3
- package/src/server/collections/agent-loop-steps.ts +76 -0
- package/src/server/collections/agent-loop-usage-buckets.ts +22 -0
- package/src/server/collections/agent-loop-worktrees.ts +25 -0
- package/src/server/collections/skill-executions.ts +8 -0
- package/src/server/migrations/{20260427000000-change-packages-to-text.ts → 20260427000002-change-packages-to-text.ts} +52 -49
- package/src/server/migrations/20260429000000-add-llm-fields.ts +47 -46
- package/src/server/migrations/{20260429000000-fix-inputargs-json-to-text.ts → 20260429000001-fix-inputargs-json-to-text.ts} +45 -38
- package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +33 -32
- package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +31 -30
- package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -0
- package/src/server/plugin.ts +55 -167
- package/src/server/resources/agent-harness-profile.ts +94 -0
- package/src/server/resources/agent-knowledge-insights.ts +5 -3
- package/src/server/resources/agent-loop-approval.ts +84 -0
- package/src/server/resources/agent-loop-artifact.ts +56 -0
- package/src/server/resources/agent-loop-events-stream.ts +105 -0
- package/src/server/resources/agent-loop.ts +204 -143
- package/src/server/resources/agent-monitor.ts +482 -482
- package/src/server/resources/resource-helpers.ts +33 -0
- package/src/server/resources/tracing.ts +266 -258
- package/src/server/services/AgentMemoryContextService.ts +44 -0
- package/src/server/services/DurableCircuitBreakerService.ts +239 -0
- package/src/server/services/ExecutionSpanService.ts +2 -0
- package/src/server/services/HarnessCompiler.ts +170 -0
- package/src/server/services/HarnessProfileService.ts +239 -0
- package/src/server/services/HarnessSchema.ts +194 -0
- package/src/server/services/LoopBudgetService.ts +275 -0
- package/src/server/services/LoopControlService.ts +124 -0
- package/src/server/services/LoopPatternSchema.ts +185 -0
- package/src/server/services/LoopPatternService.ts +143 -0
- package/src/server/services/LoopRunRepository.ts +336 -0
- package/src/server/services/LoopRunStateMachine.ts +529 -0
- package/src/server/services/LoopSchedulerService.ts +199 -0
- package/src/server/services/LoopTriggerService.ts +157 -0
- package/src/server/services/LoopWorkerService.ts +822 -0
- package/src/server/services/NativeSubAgentObserver.ts +186 -21
- package/src/server/services/PathLockService.ts +321 -0
- package/src/server/services/PluginAiRuntimeAdapter.ts +332 -0
- package/src/server/services/ToolLoopDetectionService.ts +213 -0
- package/src/server/services/VerificationSchema.ts +31 -0
- package/src/server/services/VerificationService.ts +264 -0
- package/src/server/services/harness-runtime-policy.ts +141 -0
- package/src/server/skill-hub/actions/__tests__/git-import.test.ts +15 -1
- package/src/server/skill-hub/actions/git-import.ts +9 -3
- package/src/server/skill-hub/plugin.ts +41 -3
- package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +235 -239
- package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +61 -63
- package/src/server/skill-hub/tasks/SkillExecutionTask.ts +43 -2
- package/src/server/utils/ensure-indexes.ts +96 -0
- package/src/server/utils/logging.ts +62 -63
- package/src/server/utils/loop-pattern-context.ts +20 -0
- package/dist/client-v2/214.79650a549273f163.js +0 -10
- package/dist/client-v2/253.9f0537713cee9e6c.js +0 -10
- package/dist/client-v2/264.718a107e43fc163c.js +0 -10
- package/dist/client-v2/373.f5d5292e53c4e832.js +0 -10
- package/dist/client-v2/418.ce8f5b2b8a229d1d.js +0 -10
- package/dist/client-v2/53.7c29c28043e9112d.js +0 -10
- package/dist/client-v2/619.bd3c5698b40705c3.js +0 -10
- package/dist/client-v2/677.a991ce0250ff5c77.js +0 -10
- package/dist/client-v2/925.f5370de8f6632d65.js +0 -10
- package/dist/server/services/AgentHarness.js +0 -81
- package/dist/server/services/AgentLoopController.js +0 -1023
- package/dist/server/services/AgentLoopRepository.js +0 -192
- package/dist/server/services/AgentLoopService.js +0 -142
- package/dist/server/services/AgentPlanValidator.js +0 -99
- package/dist/server/services/AgentPlannerService.js +0 -99
- package/dist/server/services/CircuitBreaker.js +0 -125
- package/dist/server/services/ContextAggregator.js +0 -201
- package/dist/server/services/PlanningPromptService.js +0 -95
- package/dist/server/tools/agent-loop.js +0 -373
- package/dist/server/tools/orchestrator-plan.js +0 -254
- package/src/client/AIEmployeeSelect.tsx +0 -47
- package/src/client/AIEmployeesContext.tsx +0 -102
- package/src/client/RulesTab.tsx +0 -2
- package/src/client/TracingTab.tsx +0 -436
- package/src/client/skill-hub/components/ExecutionProgress.tsx +0 -51
- package/src/client-v2/components/RulesTab.tsx +0 -2
- package/src/client-v2/pages/AgentRunsPage.tsx +0 -13
- package/src/server/__tests__/agent-loop-controller.test.ts +0 -375
- package/src/server/__tests__/context-aggregator.test.ts +0 -222
- package/src/server/__tests__/parallel-execution.test.ts +0 -318
- package/src/server/__tests__/planning-prompt-service.test.ts +0 -23
- package/src/server/services/AgentHarness.ts +0 -67
- package/src/server/services/AgentLoopController.ts +0 -1263
- package/src/server/services/AgentLoopRepository.ts +0 -178
- package/src/server/services/AgentLoopService.ts +0 -177
- package/src/server/services/AgentPlanValidator.ts +0 -73
- package/src/server/services/AgentPlannerService.ts +0 -80
- package/src/server/services/CircuitBreaker.ts +0 -126
- package/src/server/services/ContextAggregator.ts +0 -239
- package/src/server/services/PlanningPromptService.ts +0 -72
- package/src/server/tools/agent-loop.ts +0 -360
- package/src/server/tools/orchestrator-plan.ts +0 -255
|
@@ -0,0 +1,235 @@
|
|
|
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 VerificationService_exports = {};
|
|
28
|
+
__export(VerificationService_exports, {
|
|
29
|
+
VerificationService: () => VerificationService
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(VerificationService_exports);
|
|
32
|
+
var import_ToolLoopDetectionService = require("./ToolLoopDetectionService");
|
|
33
|
+
var import_VerificationSchema = require("./VerificationSchema");
|
|
34
|
+
function read(record, key) {
|
|
35
|
+
const model = record;
|
|
36
|
+
return typeof model.get === "function" ? model.get(key) : record[key];
|
|
37
|
+
}
|
|
38
|
+
function extractVerdictObject(content) {
|
|
39
|
+
const fenced = content.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
40
|
+
const candidate = fenced ? fenced[1] : content;
|
|
41
|
+
const start = candidate.indexOf("{");
|
|
42
|
+
const end = candidate.lastIndexOf("}");
|
|
43
|
+
if (start < 0 || end <= start) {
|
|
44
|
+
throw new Error("The verifier did not return a structured verdict object.");
|
|
45
|
+
}
|
|
46
|
+
return JSON.parse(candidate.slice(start, end + 1));
|
|
47
|
+
}
|
|
48
|
+
function verifierPrompt(input, artifacts) {
|
|
49
|
+
const catalogue = artifacts.length ? artifacts.map((artifact) => `- id=${artifact.id} kind=${artifact.kind} title=${artifact.title || ""}`).join("\n") : "- (none)";
|
|
50
|
+
return [
|
|
51
|
+
"You are the independent verifier for an autonomous run. You did not produce this work.",
|
|
52
|
+
`Goal: ${input.goal}`,
|
|
53
|
+
"",
|
|
54
|
+
"Reported result:",
|
|
55
|
+
input.makerSummary || "(the maker produced no textual summary)",
|
|
56
|
+
"",
|
|
57
|
+
"Evidence artifacts recorded for this run:",
|
|
58
|
+
catalogue,
|
|
59
|
+
"",
|
|
60
|
+
`Required checks: ${input.policy.verification.requiredChecks.join(", ")}`,
|
|
61
|
+
"",
|
|
62
|
+
...input.loopNotices ?? [],
|
|
63
|
+
"Reply with a single JSON object and nothing else:",
|
|
64
|
+
'{"verdict":"pass|reject|escalate","summary":"...","checks":[{"name":"...","status":"pass|fail|skipped",',
|
|
65
|
+
'"evidenceArtifactIds":[<artifact ids from the list above>]}],"residualRisks":["..."]}',
|
|
66
|
+
'Every check you mark "pass" must cite at least one artifact id from the list above.',
|
|
67
|
+
'If the evidence does not support the goal, answer "reject". Never invent artifact ids.'
|
|
68
|
+
].join("\n");
|
|
69
|
+
}
|
|
70
|
+
class VerificationService {
|
|
71
|
+
constructor(database, runtime, stateMachine) {
|
|
72
|
+
this.database = database;
|
|
73
|
+
this.runtime = runtime;
|
|
74
|
+
this.stateMachine = stateMachine;
|
|
75
|
+
this.loopGuard = new import_ToolLoopDetectionService.ToolLoopDetectionService(database);
|
|
76
|
+
}
|
|
77
|
+
loopGuard;
|
|
78
|
+
async verifyAndFinalize(input) {
|
|
79
|
+
this.assertIndependentVerifier(input);
|
|
80
|
+
const artifacts = await this.runArtifacts(input.runId);
|
|
81
|
+
const verdict = await this.collectVerdict(input, artifacts);
|
|
82
|
+
const guard = await this.enforceToolLoopGuard(input);
|
|
83
|
+
if (guard === "halt") {
|
|
84
|
+
return { verdict, finalStatus: "halted" };
|
|
85
|
+
}
|
|
86
|
+
await this.assertEvidenceBelongsToRun(verdict, artifacts, input.verifierUsername);
|
|
87
|
+
const finalStatus = this.finalStatusFor(verdict, input.autonomyLevel);
|
|
88
|
+
await this.stateMachine.transition({
|
|
89
|
+
runId: input.runId,
|
|
90
|
+
to: finalStatus,
|
|
91
|
+
actorType: "worker",
|
|
92
|
+
actorIdentity: input.workerId,
|
|
93
|
+
leaseToken: input.leaseToken,
|
|
94
|
+
eventType: "run_verified",
|
|
95
|
+
title: `Verifier returned ${verdict.verdict}`,
|
|
96
|
+
content: verdict.summary,
|
|
97
|
+
correlationKey: `verified:${input.runId}:${verdict.verdict}`,
|
|
98
|
+
values: {
|
|
99
|
+
verifierVerdict: verdict.verdict,
|
|
100
|
+
verifierEvidence: verdict,
|
|
101
|
+
summary: verdict.summary
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return { verdict, finalStatus };
|
|
105
|
+
}
|
|
106
|
+
assertIndependentVerifier(input) {
|
|
107
|
+
const verifier = input.verifierUsername.trim();
|
|
108
|
+
if (!verifier) throw new Error("The run snapshot does not name a verifier.");
|
|
109
|
+
if (verifier === input.leaderUsername || input.makerUsernames.includes(verifier)) {
|
|
110
|
+
throw new Error("The verifier must be a different employee from the leader and every maker.");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async enforceToolLoopGuard(input) {
|
|
114
|
+
const finding = await this.loopGuard.scanRun(input.runId, input.policy);
|
|
115
|
+
if (!finding) return "continue";
|
|
116
|
+
await this.loopGuard.recordFinding(
|
|
117
|
+
{
|
|
118
|
+
runId: input.runId,
|
|
119
|
+
role: "verifier",
|
|
120
|
+
username: input.verifierUsername,
|
|
121
|
+
runStatus: "verifying",
|
|
122
|
+
actorType: "worker",
|
|
123
|
+
actorIdentity: input.workerId
|
|
124
|
+
},
|
|
125
|
+
finding
|
|
126
|
+
);
|
|
127
|
+
if (finding.level === "warn") return "continue";
|
|
128
|
+
const reason = (0, import_ToolLoopDetectionService.toolLoopReason)(finding);
|
|
129
|
+
await this.stateMachine.transition({
|
|
130
|
+
runId: input.runId,
|
|
131
|
+
to: finding.level === "block" ? "blocked" : "waiting_human",
|
|
132
|
+
actorType: "worker",
|
|
133
|
+
actorIdentity: input.workerId,
|
|
134
|
+
leaseToken: input.leaseToken,
|
|
135
|
+
eventType: finding.level === "block" ? "run_blocked" : "run_escalated",
|
|
136
|
+
title: finding.level === "block" ? "Run blocked by tool loop detection" : "Run escalated by tool loop detection",
|
|
137
|
+
content: reason,
|
|
138
|
+
correlationKey: `tool-loop-${finding.level}:${input.runId}:${finding.signature}`,
|
|
139
|
+
values: finding.level === "block" ? { blockedReason: reason } : { escalationReason: reason }
|
|
140
|
+
});
|
|
141
|
+
return "halt";
|
|
142
|
+
}
|
|
143
|
+
async nextSequence(runId) {
|
|
144
|
+
const steps = await this.database.getRepository("agentLoopSteps").find({ filter: { runId } });
|
|
145
|
+
return steps.length;
|
|
146
|
+
}
|
|
147
|
+
async collectVerdict(input, artifacts) {
|
|
148
|
+
const sessionId = await this.runtime.createConversation({
|
|
149
|
+
username: input.verifierUsername,
|
|
150
|
+
userId: input.userId,
|
|
151
|
+
runId: input.runId,
|
|
152
|
+
title: `Verification of run ${input.runId}`
|
|
153
|
+
});
|
|
154
|
+
const step = await this.database.getRepository("agentLoopSteps").create({
|
|
155
|
+
values: {
|
|
156
|
+
runId: input.runId,
|
|
157
|
+
runtimeVersion: "control-plane-v2",
|
|
158
|
+
sequence: await this.nextSequence(input.runId),
|
|
159
|
+
role: "verifier",
|
|
160
|
+
kind: "invocation",
|
|
161
|
+
type: "verification",
|
|
162
|
+
employeeUsername: input.verifierUsername,
|
|
163
|
+
sessionId,
|
|
164
|
+
title: "verifier invocation",
|
|
165
|
+
status: "running",
|
|
166
|
+
startedAt: /* @__PURE__ */ new Date(),
|
|
167
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
const outcome = await this.runtime.invoke({
|
|
171
|
+
username: input.verifierUsername,
|
|
172
|
+
sessionId,
|
|
173
|
+
userId: input.userId,
|
|
174
|
+
systemMessage: "You verify completed work against its stated goal using only recorded evidence. You never modify anything.",
|
|
175
|
+
harness: input.verifierHarness,
|
|
176
|
+
prompt: verifierPrompt(input, artifacts),
|
|
177
|
+
signal: input.signal
|
|
178
|
+
});
|
|
179
|
+
await this.database.getRepository("agentLoopSteps").update({
|
|
180
|
+
filterByTk: read(step, "id"),
|
|
181
|
+
values: {
|
|
182
|
+
status: "succeeded",
|
|
183
|
+
output: { content: outcome.content },
|
|
184
|
+
endedAt: /* @__PURE__ */ new Date()
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
if (outcome.interrupted.length) {
|
|
188
|
+
throw new Error("The verifier requested an approval-gated tool; verification cannot complete.");
|
|
189
|
+
}
|
|
190
|
+
const verdict = (0, import_VerificationSchema.parseVerificationVerdict)(extractVerdictObject(outcome.content));
|
|
191
|
+
const required = new Set(input.policy.verification.requiredChecks);
|
|
192
|
+
for (const check of verdict.checks) required.delete(check.name);
|
|
193
|
+
if (required.size) {
|
|
194
|
+
throw new Error(`The verifier omitted required checks: ${Array.from(required).join(", ")}.`);
|
|
195
|
+
}
|
|
196
|
+
return verdict;
|
|
197
|
+
}
|
|
198
|
+
async assertEvidenceBelongsToRun(verdict, artifacts, verifierUsername) {
|
|
199
|
+
const owned = new Map(artifacts.map((artifact) => [Number(artifact.id), artifact]));
|
|
200
|
+
for (const check of verdict.checks) {
|
|
201
|
+
for (const artifactId of check.evidenceArtifactIds) {
|
|
202
|
+
const artifact = owned.get(artifactId);
|
|
203
|
+
if (!artifact) {
|
|
204
|
+
throw new Error(`Evidence artifact ${artifactId} does not belong to this run.`);
|
|
205
|
+
}
|
|
206
|
+
if (String(artifact.producerUsername || "") === verifierUsername) {
|
|
207
|
+
throw new Error(`Evidence artifact ${artifactId} was produced by the verifier itself.`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
finalStatusFor(verdict, autonomyLevel) {
|
|
213
|
+
if (verdict.verdict !== "pass") {
|
|
214
|
+
return verdict.verdict === "escalate" ? "waiting_human" : "failed";
|
|
215
|
+
}
|
|
216
|
+
const passesEveryCheck = verdict.checks.every(
|
|
217
|
+
(check) => check.status === "pass" && check.evidenceArtifactIds.length > 0
|
|
218
|
+
);
|
|
219
|
+
if (!passesEveryCheck) return "failed";
|
|
220
|
+
return autonomyLevel === "L1" ? "succeeded" : "waiting_human";
|
|
221
|
+
}
|
|
222
|
+
async runArtifacts(runId) {
|
|
223
|
+
const rows = await this.database.getRepository("agentLoopArtifacts").find({ filter: { runId } });
|
|
224
|
+
return rows.map((row) => ({
|
|
225
|
+
id: Number(read(row, "id")),
|
|
226
|
+
kind: String(read(row, "kind") || ""),
|
|
227
|
+
title: String(read(row, "title") || ""),
|
|
228
|
+
producerUsername: String(read(row, "producerUsername") || "")
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
+
0 && (module.exports = {
|
|
234
|
+
VerificationService
|
|
235
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
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 harness_runtime_policy_exports = {};
|
|
28
|
+
__export(harness_runtime_policy_exports, {
|
|
29
|
+
REDACTED_PLACEHOLDER: () => REDACTED_PLACEHOLDER,
|
|
30
|
+
harnessTimeoutMs: () => harnessTimeoutMs,
|
|
31
|
+
redactSecretsIn: () => redactSecretsIn,
|
|
32
|
+
resolveRunRoleHarness: () => resolveRunRoleHarness,
|
|
33
|
+
resolveTraceHarness: () => resolveTraceHarness,
|
|
34
|
+
spilledText: () => spilledText
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(harness_runtime_policy_exports);
|
|
37
|
+
var import_HarnessCompiler = require("./HarnessCompiler");
|
|
38
|
+
var import_HarnessProfileService = require("./HarnessProfileService");
|
|
39
|
+
var import_HarnessSchema = require("./HarnessSchema");
|
|
40
|
+
function read(record, key) {
|
|
41
|
+
const model = record;
|
|
42
|
+
return typeof (model == null ? void 0 : model.get) === "function" ? model.get(key) : model == null ? void 0 : model[key];
|
|
43
|
+
}
|
|
44
|
+
function asObject(value) {
|
|
45
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
46
|
+
}
|
|
47
|
+
function compiledFromSnapshot(snapshot) {
|
|
48
|
+
const effective = asObject(asObject(snapshot).effective);
|
|
49
|
+
if (!effective.tools) return null;
|
|
50
|
+
const { sources: _sources, ...settings } = effective;
|
|
51
|
+
return (0, import_HarnessCompiler.compileHarness)([{ source: "run-snapshot", settings: (0, import_HarnessSchema.parseHarnessSettings)(settings) }]);
|
|
52
|
+
}
|
|
53
|
+
function snapshotForEmployee(run, username) {
|
|
54
|
+
const bindings = asObject(run.roleBindingsSnapshot);
|
|
55
|
+
if (!username) return null;
|
|
56
|
+
if (bindings.leader === username) return run.leaderHarnessSnapshot;
|
|
57
|
+
if (bindings.verifier === username) return run.verifierHarnessSnapshot;
|
|
58
|
+
const makers = asObject(run.makerHarnessSnapshot);
|
|
59
|
+
return makers[username] ?? null;
|
|
60
|
+
}
|
|
61
|
+
async function resolveRunRoleHarness(database, runId, username) {
|
|
62
|
+
var _a;
|
|
63
|
+
if (!Number.isSafeInteger(runId) || runId <= 0 || !username) return null;
|
|
64
|
+
const run = await database.getRepository("agentLoopRuns").findOne({ filterByTk: runId });
|
|
65
|
+
if (!run) return null;
|
|
66
|
+
const snapshot = snapshotForEmployee(asObject(((_a = run.toJSON) == null ? void 0 : _a.call(run)) ?? run), username);
|
|
67
|
+
return compiledFromSnapshot(snapshot);
|
|
68
|
+
}
|
|
69
|
+
async function resolveTraceHarness(database, trace) {
|
|
70
|
+
const runHarness = await resolveRunRoleHarness(database, Number(trace.agentLoopRunId), trace.employeeUsername);
|
|
71
|
+
if (runHarness) return runHarness;
|
|
72
|
+
if (!trace.employeeUsername) return null;
|
|
73
|
+
const employee = await database.getRepository("aiEmployees").findOne({
|
|
74
|
+
filter: { username: trace.employeeUsername }
|
|
75
|
+
});
|
|
76
|
+
if (!employee) return null;
|
|
77
|
+
const settings = asObject(read(employee, "skillSettings"));
|
|
78
|
+
const tag = typeof settings.harnessTag === "string" && settings.harnessTag.trim() ? settings.harnessTag.trim() : "default";
|
|
79
|
+
const profiles = new import_HarnessProfileService.HarnessProfileService(database);
|
|
80
|
+
const version = await profiles.getPublishedByTag(tag) || (tag !== "default" ? await profiles.getPublishedByTag("default") : null);
|
|
81
|
+
if (!version) return null;
|
|
82
|
+
return (0, import_HarnessCompiler.compileHarness)([{ source: `profile:${tag}`, settings: version.settings }]);
|
|
83
|
+
}
|
|
84
|
+
function harnessTimeoutMs(harness, toolName) {
|
|
85
|
+
const timeouts = harness.tools.timeouts;
|
|
86
|
+
const direct = timeouts[toolName];
|
|
87
|
+
if (typeof direct === "number" && direct > 0) return direct;
|
|
88
|
+
const generic = timeouts["skill_hub_execute"];
|
|
89
|
+
return typeof generic === "number" && generic > 0 ? generic : null;
|
|
90
|
+
}
|
|
91
|
+
const SECRET_KEY_PATTERN = /(?:KEY|SECRET|TOKEN|PASSWORD|PASSWD|CREDENTIAL)/i;
|
|
92
|
+
const REDACTED_PLACEHOLDER = "[REDACTED]";
|
|
93
|
+
function redactSecretsIn(value) {
|
|
94
|
+
const scrub = (input, depth) => {
|
|
95
|
+
if (depth > 8 || input === null || input === void 0) return input;
|
|
96
|
+
if (Array.isArray(input)) return input.map((item) => scrub(item, depth + 1));
|
|
97
|
+
if (typeof input === "object") {
|
|
98
|
+
const source = input;
|
|
99
|
+
const output = {};
|
|
100
|
+
for (const [key, entry] of Object.entries(source)) {
|
|
101
|
+
output[key] = SECRET_KEY_PATTERN.test(key) ? REDACTED_PLACEHOLDER : scrub(entry, depth + 1);
|
|
102
|
+
}
|
|
103
|
+
return output;
|
|
104
|
+
}
|
|
105
|
+
return input;
|
|
106
|
+
};
|
|
107
|
+
return scrub(value, 0);
|
|
108
|
+
}
|
|
109
|
+
function sliceBytes(buffer, start, end) {
|
|
110
|
+
let from = Math.max(0, start);
|
|
111
|
+
while (from < end && (buffer[from] & 192) === 128) from += 1;
|
|
112
|
+
return buffer.subarray(from, Math.min(buffer.length, end));
|
|
113
|
+
}
|
|
114
|
+
function spilledText(text, maxInlineBytes, locator) {
|
|
115
|
+
const buffer = Buffer.from(text, "utf8");
|
|
116
|
+
if (buffer.byteLength <= maxInlineBytes) return null;
|
|
117
|
+
const headTarget = Math.floor(maxInlineBytes * 0.6);
|
|
118
|
+
const tailTarget = Math.floor(maxInlineBytes * 0.2);
|
|
119
|
+
let head = sliceBytes(buffer, 0, headTarget).toString("utf8");
|
|
120
|
+
let tail = sliceBytes(buffer, buffer.byteLength - tailTarget, buffer.byteLength).toString("utf8");
|
|
121
|
+
const notice = () => `
|
|
122
|
+
|
|
123
|
+
... (${buffer.byteLength - Buffer.byteLength(head, "utf8") - Buffer.byteLength(tail, "utf8")} bytes omitted. Full output stored at: ${locator}) ...`;
|
|
124
|
+
while (Buffer.byteLength(head + notice() + tail, "utf8") > maxInlineBytes && head.length + tail.length > 0) {
|
|
125
|
+
head = head.slice(0, Math.floor(head.length * 0.9));
|
|
126
|
+
const keepTail = Math.floor(tail.length * 0.9);
|
|
127
|
+
tail = keepTail > 0 ? tail.slice(-keepTail) : "";
|
|
128
|
+
}
|
|
129
|
+
return `${head}${notice()}${tail}`;
|
|
130
|
+
}
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
REDACTED_PLACEHOLDER,
|
|
134
|
+
harnessTimeoutMs,
|
|
135
|
+
redactSecretsIn,
|
|
136
|
+
resolveRunRoleHarness,
|
|
137
|
+
resolveTraceHarness,
|
|
138
|
+
spilledText
|
|
139
|
+
});
|
|
@@ -61,7 +61,7 @@ async function gitListSkills(ctx, next) {
|
|
|
61
61
|
const { repositoryId, ref = "HEAD", prefix = "" } = ctx.action.params;
|
|
62
62
|
const rootFolder = normalizeRootFolder(ctx.action.params.rootFolder);
|
|
63
63
|
if (!repositoryId) {
|
|
64
|
-
ctx.throw(400, "repositoryId and rootFolder are required");
|
|
64
|
+
ctx.throw(400, translateGitImportMessage(ctx, "repositoryId and rootFolder are required"));
|
|
65
65
|
}
|
|
66
66
|
try {
|
|
67
67
|
const service = getGitManagerContentService(ctx);
|
|
@@ -108,7 +108,7 @@ async function gitSyncSkills(ctx, next) {
|
|
|
108
108
|
const rootFolder = normalizeRootFolder(ctx.action.params.rootFolder);
|
|
109
109
|
const { skills: selectedKeys, overwrite = false, prefix = "" } = ctx.action.params.values || ctx.action.params;
|
|
110
110
|
if (!repositoryId || !Array.isArray(selectedKeys) || selectedKeys.length === 0) {
|
|
111
|
-
ctx.throw(400, "repositoryId, rootFolder and skills[] are required");
|
|
111
|
+
ctx.throw(400, translateGitImportMessage(ctx, "repositoryId, rootFolder and skills[] are required"));
|
|
112
112
|
}
|
|
113
113
|
const selectedSkillKeys = selectedKeys.filter(
|
|
114
114
|
(key) => typeof key === "string" && key.trim().length > 0
|
|
@@ -278,7 +278,8 @@ function getGitManagerContentService(ctx) {
|
|
|
278
278
|
throw new GitImportError(
|
|
279
279
|
"GIT_MANAGER_CONTENT_UNAVAILABLE",
|
|
280
280
|
424,
|
|
281
|
-
"Git Manager is not enabled for Skill Hub imports."
|
|
281
|
+
"Git Manager is not enabled for Skill Hub imports.",
|
|
282
|
+
{ key: "Git Manager is not enabled for Skill Hub imports." }
|
|
282
283
|
);
|
|
283
284
|
}
|
|
284
285
|
const service = plugin.skillHubContentService;
|
|
@@ -286,7 +287,8 @@ function getGitManagerContentService(ctx) {
|
|
|
286
287
|
throw new GitImportError(
|
|
287
288
|
"GIT_MANAGER_CONTENT_UNAVAILABLE",
|
|
288
289
|
424,
|
|
289
|
-
"Git Manager must support actor-aware content reads for Skill Hub imports."
|
|
290
|
+
"Git Manager must support actor-aware content reads for Skill Hub imports.",
|
|
291
|
+
{ key: "Git Manager must support actor-aware content reads for Skill Hub imports." }
|
|
290
292
|
);
|
|
291
293
|
}
|
|
292
294
|
const candidate = service;
|
|
@@ -297,7 +299,8 @@ function getGitManagerContentService(ctx) {
|
|
|
297
299
|
throw new GitImportError(
|
|
298
300
|
"GIT_MANAGER_CONTENT_UNAVAILABLE",
|
|
299
301
|
424,
|
|
300
|
-
"Git Manager must support actor-aware content reads for Skill Hub imports."
|
|
302
|
+
"Git Manager must support actor-aware content reads for Skill Hub imports.",
|
|
303
|
+
{ key: "Git Manager must support actor-aware content reads for Skill Hub imports." }
|
|
301
304
|
);
|
|
302
305
|
}
|
|
303
306
|
return service;
|
|
@@ -309,7 +312,8 @@ function accessFromContext(ctx) {
|
|
|
309
312
|
throw new GitImportError(
|
|
310
313
|
"SKILL_HUB_REPOSITORY_ACCESS_DENIED",
|
|
311
314
|
403,
|
|
312
|
-
"A valid user role context is required to import skills from Git Manager."
|
|
315
|
+
"A valid user role context is required to import skills from Git Manager.",
|
|
316
|
+
{ key: "A valid user role context is required to import skills from Git Manager." }
|
|
313
317
|
);
|
|
314
318
|
}
|
|
315
319
|
return { kind: "user", roles: currentRoles };
|
|
@@ -342,7 +346,9 @@ function throwGitImportError(ctx, error) {
|
|
|
342
346
|
case MISSING_GIT_FILE_CODE:
|
|
343
347
|
return throwHttpError(ctx, 404, errorMessage(error));
|
|
344
348
|
default:
|
|
345
|
-
return throwHttpError(ctx, 502, "Git Manager could not read the requested repository content."
|
|
349
|
+
return throwHttpError(ctx, 502, "Git Manager could not read the requested repository content.", {
|
|
350
|
+
key: "Git Manager could not read the requested repository content."
|
|
351
|
+
});
|
|
346
352
|
}
|
|
347
353
|
}
|
|
348
354
|
function translateGitImportMessage(ctx, key, values, fallback = key) {
|
|
@@ -56,6 +56,7 @@ var import_git_import = require("./actions/git-import");
|
|
|
56
56
|
var import_git_import_request_method_policy = require("./middlewares/git-import-request-method-policy");
|
|
57
57
|
var import_json_fields = require("./utils/json-fields");
|
|
58
58
|
var import_ExecutionSpanService = require("../services/ExecutionSpanService");
|
|
59
|
+
var import_harness_runtime_policy = require("../services/harness-runtime-policy");
|
|
59
60
|
var import_ai_manager = require("../utils/ai-manager");
|
|
60
61
|
var import_SkillAccessService = require("../services/SkillAccessService");
|
|
61
62
|
var import_InputSchemaValidator = require("../services/InputSchemaValidator");
|
|
@@ -425,6 +426,35 @@ class SkillHubSubFeature {
|
|
|
425
426
|
this.skillTaskPolling = false;
|
|
426
427
|
}
|
|
427
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Resolve harness-derived enforcement overrides for one skill execution. The worker node owns
|
|
431
|
+
* the sandbox but not the harness, so the decision is made here (run snapshot for loop runs,
|
|
432
|
+
* employee harness-tag profile otherwise) and persisted on the execution row. A resolution
|
|
433
|
+
* failure must never block execution: the skill falls back to its own defaults.
|
|
434
|
+
*/
|
|
435
|
+
async resolveRuntimePolicy(traceContext, skill, aiEmployeeUsername) {
|
|
436
|
+
var _a, _b, _c;
|
|
437
|
+
try {
|
|
438
|
+
const harness = await (0, import_harness_runtime_policy.resolveTraceHarness)(this.db, {
|
|
439
|
+
agentLoopRunId: traceContext == null ? void 0 : traceContext.agentLoopRunId,
|
|
440
|
+
employeeUsername: (traceContext == null ? void 0 : traceContext.employeeUsername) || aiEmployeeUsername
|
|
441
|
+
});
|
|
442
|
+
if (!harness) return null;
|
|
443
|
+
const policy = {};
|
|
444
|
+
const timeoutMs = (0, import_harness_runtime_policy.harnessTimeoutMs)(harness, (0, import_skill_tool_name.getSkillToolName)(skill));
|
|
445
|
+
if (timeoutMs) {
|
|
446
|
+
const skillTimeoutSeconds = Number(skill.timeoutSeconds || ((_a = skill.get) == null ? void 0 : _a.call(skill, "timeoutSeconds")) || 60);
|
|
447
|
+
policy.timeoutSeconds = Math.min(skillTimeoutSeconds, Math.ceil(timeoutMs / 1e3));
|
|
448
|
+
}
|
|
449
|
+
if (harness.context.spill.maxInlineBytes) {
|
|
450
|
+
policy.spillMaxInlineBytes = harness.context.spill.maxInlineBytes;
|
|
451
|
+
}
|
|
452
|
+
return Object.keys(policy).length ? policy : null;
|
|
453
|
+
} catch (error) {
|
|
454
|
+
(_c = (_b = this.app.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[skill-hub] Failed to resolve harness runtime policy.", { error });
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
428
458
|
/**
|
|
429
459
|
* Execute skill — called by both AI tool and REST test endpoint.
|
|
430
460
|
* Dispatches to sandbox workers via PubSub, waits for result via PubSub.
|
|
@@ -445,6 +475,7 @@ class SkillHubSubFeature {
|
|
|
445
475
|
}
|
|
446
476
|
}
|
|
447
477
|
const traceContext = (0, import_ExecutionSpanService.getOrchestratorTraceContext)(ctx);
|
|
478
|
+
const runtimePolicy = await this.resolveRuntimePolicy(traceContext, skill, aiEmployeeUsername);
|
|
448
479
|
const execution = await this.db.getRepository("skillExecutions").create({
|
|
449
480
|
values: {
|
|
450
481
|
skillId: skill.id,
|
|
@@ -459,7 +490,8 @@ class SkillHubSubFeature {
|
|
|
459
490
|
orchestratorToolCallId: traceContext == null ? void 0 : traceContext.toolCallId,
|
|
460
491
|
agentLoopRunId: traceContext == null ? void 0 : traceContext.agentLoopRunId,
|
|
461
492
|
agentLoopStepId: traceContext == null ? void 0 : traceContext.agentLoopStepId,
|
|
462
|
-
triggeredById: (_f = (_e = ctx == null ? void 0 : ctx.state) == null ? void 0 : _e.currentUser) == null ? void 0 : _f.id
|
|
493
|
+
triggeredById: (_f = (_e = ctx == null ? void 0 : ctx.state) == null ? void 0 : _e.currentUser) == null ? void 0 : _f.id,
|
|
494
|
+
runtimePolicy
|
|
463
495
|
}
|
|
464
496
|
});
|
|
465
497
|
const execId = String(execution.id);
|
|
@@ -495,10 +527,11 @@ class SkillHubSubFeature {
|
|
|
495
527
|
resolvePromise = resolve2;
|
|
496
528
|
rejectPromise = reject;
|
|
497
529
|
});
|
|
498
|
-
const
|
|
530
|
+
const effectiveTimeoutSeconds = (runtimePolicy == null ? void 0 : runtimePolicy.timeoutSeconds) || skill.timeoutSeconds || ((_g = skill.get) == null ? void 0 : _g.call(skill, "timeoutSeconds")) || 60;
|
|
531
|
+
const timeoutMs = (effectiveTimeoutSeconds + 15) * 1e3;
|
|
499
532
|
const timeout = setTimeout(() => {
|
|
500
533
|
clearInterval(poll);
|
|
501
|
-
rejectPromise(new Error(`Skill execution timeout after ${
|
|
534
|
+
rejectPromise(new Error(`Skill execution timeout after ${effectiveTimeoutSeconds}s`));
|
|
502
535
|
}, timeoutMs);
|
|
503
536
|
const poll = setInterval(async () => {
|
|
504
537
|
var _a2, _b2, _c2, _d2, _e2;
|
|
@@ -38,11 +38,7 @@ function positiveLimit(value2, fallback, maximum) {
|
|
|
38
38
|
const parsed = Number(value2);
|
|
39
39
|
return Number.isSafeInteger(parsed) && parsed > 0 && parsed <= maximum ? parsed : fallback;
|
|
40
40
|
}
|
|
41
|
-
const MAX_REGISTRY_SKILL_SNAPSHOTS = positiveLimit(
|
|
42
|
-
process.env.SKILL_REGISTRY_MAX_SOURCE_ITEMS,
|
|
43
|
-
1e3,
|
|
44
|
-
1e4
|
|
45
|
-
);
|
|
41
|
+
const MAX_REGISTRY_SKILL_SNAPSHOTS = positiveLimit(process.env.SKILL_REGISTRY_MAX_SOURCE_ITEMS, 1e3, 1e4);
|
|
46
42
|
const MAX_REGISTRY_TEXT_BYTES = 10 * 1024 * 1024;
|
|
47
43
|
const registryExportFilter = {
|
|
48
44
|
registryPackageId: null,
|
|
@@ -32,6 +32,7 @@ module.exports = __toCommonJS(SkillExecutionTask_exports);
|
|
|
32
32
|
var import_fs = require("fs");
|
|
33
33
|
var import_path = require("path");
|
|
34
34
|
var import_CodeValidator = require("../../services/CodeValidator");
|
|
35
|
+
var import_harness_runtime_policy = require("../../services/harness-runtime-policy");
|
|
35
36
|
var import_crypto = require("crypto");
|
|
36
37
|
var import_skill_tool_name = require("../../utils/skill-tool-name");
|
|
37
38
|
var import_json_fields = require("../utils/json-fields");
|
|
@@ -155,6 +156,14 @@ class SkillExecutionTask {
|
|
|
155
156
|
throw new Error(`Plugin skill "${pluginSkillName}" not found. Is the parent plugin enabled?`);
|
|
156
157
|
}
|
|
157
158
|
}
|
|
159
|
+
const runtimePolicy = (0, import_json_fields.parseJsonLike)(
|
|
160
|
+
this.execution.get ? this.execution.get("runtimePolicy") : this.execution.runtimePolicy,
|
|
161
|
+
{}
|
|
162
|
+
);
|
|
163
|
+
if (typeof (runtimePolicy == null ? void 0 : runtimePolicy.timeoutSeconds) === "number" && runtimePolicy.timeoutSeconds > 0) {
|
|
164
|
+
timeoutSeconds = Math.min(Number(timeoutSeconds) || 60, runtimePolicy.timeoutSeconds);
|
|
165
|
+
}
|
|
166
|
+
const spillMaxInlineBytes = typeof (runtimePolicy == null ? void 0 : runtimePolicy.spillMaxInlineBytes) === "number" && runtimePolicy.spillMaxInlineBytes > 0 ? runtimePolicy.spillMaxInlineBytes : null;
|
|
158
167
|
if (!rawCodeTemplate) {
|
|
159
168
|
throw new Error(
|
|
160
169
|
`Skill "${skillName}" has no codeTemplate. Add a code file, inline codeTemplate, or bind it to an installed plugin skill.`
|
|
@@ -260,6 +269,26 @@ class SkillExecutionTask {
|
|
|
260
269
|
} else {
|
|
261
270
|
status = result.success ? "succeeded" : "failed";
|
|
262
271
|
}
|
|
272
|
+
if (spillMaxInlineBytes && typeof result.stdout === "string") {
|
|
273
|
+
const spillName = "stdout-full.txt";
|
|
274
|
+
const spillPath = (0, import_path.resolve)(this.fileManager.getOutputDir(execId), spillName);
|
|
275
|
+
const locator = `/api/skillHub:download?execId=${execId}&f=${Buffer.from(spillName).toString("base64url")}`;
|
|
276
|
+
const replaced = (0, import_harness_runtime_policy.spilledText)(result.stdout, spillMaxInlineBytes, locator);
|
|
277
|
+
if (replaced) {
|
|
278
|
+
try {
|
|
279
|
+
(0, import_fs.writeFileSync)(spillPath, result.stdout, "utf8");
|
|
280
|
+
result.stdout = replaced;
|
|
281
|
+
result.files = [
|
|
282
|
+
...result.files || [],
|
|
283
|
+
{ name: spillName, size: (0, import_fs.statSync)(spillPath).size, mimeType: "text/plain" }
|
|
284
|
+
];
|
|
285
|
+
} catch (spillError) {
|
|
286
|
+
this.app.logger.warn(`[skill-hub] Task ${execId}: stdout spill failed`, {
|
|
287
|
+
error: spillError
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
263
292
|
const completed = await this.updateIfOwned(execId, workerId, {
|
|
264
293
|
status,
|
|
265
294
|
stdout: result.stdout,
|