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.
Files changed (218) hide show
  1. package/README.md +204 -114
  2. package/dist/client/index.js +1 -1
  3. package/dist/client-v2/117.7565cff57c39318a.js +10 -0
  4. package/dist/client-v2/214.106635011859dede.js +10 -0
  5. package/dist/client-v2/253.59577b40d9875be0.js +10 -0
  6. package/dist/client-v2/264.7ed8bee71fa5935c.js +10 -0
  7. package/dist/client-v2/{41.ba6e080cc0488143.js → 41.3deb9e57a0f64fc4.js} +1 -1
  8. package/dist/client-v2/418.41ed200e7d6da332.js +10 -0
  9. package/dist/client-v2/53.349fff8db80b19d4.js +10 -0
  10. package/dist/client-v2/619.0a2144aaffefe018.js +10 -0
  11. package/dist/client-v2/{70.bda9518881c05360.js → 70.ffff2997c10fd4b0.js} +1 -1
  12. package/dist/client-v2/{794.9bbb8d3a61b2bdf2.js → 794.a67a2614405ba627.js} +1 -1
  13. package/dist/client-v2/981.e4a1f41cfc94a856.js +10 -0
  14. package/dist/client-v2/{993.82778b6fd6db3cb1.js → 993.b0688fdc5ccb000a.js} +1 -1
  15. package/dist/client-v2/index.js +1 -1
  16. package/dist/externalVersion.js +8 -7
  17. package/dist/locale/en-US.json +199 -123
  18. package/dist/locale/vi-VN.json +199 -123
  19. package/dist/locale/zh-CN.json +199 -123
  20. package/dist/server/collections/agent-execution-spans.js +55 -0
  21. package/dist/server/collections/agent-harness-profile-versions.js +56 -0
  22. package/dist/server/collections/agent-harness-profiles.js +12 -0
  23. package/dist/server/collections/agent-loop-action-approvals.js +69 -0
  24. package/dist/server/collections/agent-loop-artifacts.js +55 -0
  25. package/dist/server/collections/agent-loop-circuit-states.js +53 -0
  26. package/dist/server/collections/agent-loop-control-settings.js +51 -0
  27. package/dist/server/collections/agent-loop-events.js +27 -0
  28. package/dist/server/collections/agent-loop-path-locks.js +57 -0
  29. package/dist/server/collections/agent-loop-patterns.js +72 -0
  30. package/dist/server/collections/agent-loop-runs.js +170 -3
  31. package/dist/server/collections/agent-loop-steps.js +76 -0
  32. package/dist/server/collections/agent-loop-usage-buckets.js +52 -0
  33. package/dist/server/collections/agent-loop-worktrees.js +55 -0
  34. package/dist/server/collections/skill-executions.js +8 -0
  35. package/dist/server/migrations/{20260427000000-change-packages-to-text.js → 20260427000002-change-packages-to-text.js} +2 -0
  36. package/dist/server/migrations/20260429000000-add-llm-fields.js +3 -2
  37. package/dist/server/migrations/{20260429000000-fix-inputargs-json-to-text.js → 20260429000001-fix-inputargs-json-to-text.js} +14 -6
  38. package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +2 -1
  39. package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +2 -1
  40. package/dist/server/migrations/20260803010000-backfill-loop-control-plane-data.js +262 -0
  41. package/dist/server/plugin.js +54 -150
  42. package/dist/server/resources/agent-harness-profile.js +117 -0
  43. package/dist/server/resources/agent-knowledge-insights.js +1 -3
  44. package/dist/server/resources/agent-loop-approval.js +108 -0
  45. package/dist/server/resources/agent-loop-artifact.js +86 -0
  46. package/dist/server/resources/agent-loop-events-stream.js +130 -0
  47. package/dist/server/resources/agent-loop.js +183 -139
  48. package/dist/server/resources/resource-helpers.js +63 -0
  49. package/dist/server/resources/tracing.js +121 -107
  50. package/dist/server/services/AgentMemoryContextService.js +34 -0
  51. package/dist/server/services/DurableCircuitBreakerService.js +229 -0
  52. package/dist/server/services/HarnessCompiler.js +175 -0
  53. package/dist/server/services/HarnessProfileService.js +233 -0
  54. package/dist/server/services/HarnessSchema.js +194 -0
  55. package/dist/server/services/LoopBudgetService.js +269 -0
  56. package/dist/server/services/LoopControlService.js +139 -0
  57. package/dist/server/services/LoopPatternSchema.js +195 -0
  58. package/dist/server/services/LoopPatternService.js +132 -0
  59. package/dist/server/services/LoopRunRepository.js +285 -0
  60. package/dist/server/services/LoopRunStateMachine.js +478 -0
  61. package/dist/server/services/LoopSchedulerService.js +193 -0
  62. package/dist/server/services/LoopTriggerService.js +165 -0
  63. package/dist/server/services/LoopWorkerService.js +699 -0
  64. package/dist/server/services/NativeSubAgentObserver.js +165 -23
  65. package/dist/server/services/PathLockService.js +288 -0
  66. package/dist/server/services/PluginAiRuntimeAdapter.js +226 -0
  67. package/dist/server/services/ToolLoopDetectionService.js +210 -0
  68. package/dist/server/services/VerificationSchema.js +59 -0
  69. package/dist/server/services/VerificationService.js +235 -0
  70. package/dist/server/services/harness-runtime-policy.js +139 -0
  71. package/dist/server/skill-hub/actions/git-import.js +13 -7
  72. package/dist/server/skill-hub/plugin.js +36 -3
  73. package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +1 -5
  74. package/dist/server/skill-hub/tasks/SkillExecutionTask.js +29 -0
  75. package/dist/server/utils/ensure-indexes.js +111 -0
  76. package/dist/server/utils/loop-pattern-context.js +56 -0
  77. package/package.json +53 -53
  78. package/src/client/ApprovalsTab.tsx +2 -0
  79. package/src/client/OrchestratorSettings.tsx +55 -0
  80. package/src/client/skill-hub/components/GitSkillImport.tsx +3 -3
  81. package/src/client/skill-hub/components/SkillMetrics.tsx +15 -10
  82. package/src/client/skill-hub/index.tsx +0 -52
  83. package/src/client-v2/components/AgentRunsTab.tsx +100 -18
  84. package/src/client-v2/components/ApprovalsTab.tsx +337 -0
  85. package/src/client-v2/components/HarnessProfilesTab.tsx +385 -100
  86. package/src/client-v2/components/MemoryInspectorTab.tsx +141 -125
  87. package/src/client-v2/components/TracingTab.tsx +160 -77
  88. package/src/client-v2/hooks/useApiRequest.ts +28 -8
  89. package/src/client-v2/pages/ApprovalsPage.tsx +10 -0
  90. package/src/client-v2/plugin.tsx +6 -6
  91. package/src/client-v2/skill-hub/components/SkillMetrics.tsx +11 -6
  92. package/src/locale/en-US.json +199 -123
  93. package/src/locale/vi-VN.json +199 -123
  94. package/src/locale/zh-CN.json +199 -123
  95. package/src/server/__tests__/circuit-breaker.test.ts +248 -169
  96. package/src/server/__tests__/harness-compiler.test.ts +214 -0
  97. package/src/server/__tests__/harness-profile-service.test.ts +167 -0
  98. package/src/server/__tests__/harness-runtime-policy.test.ts +293 -0
  99. package/src/server/__tests__/harness-tool-plan.test.ts +172 -0
  100. package/src/server/__tests__/loop-approval-decision.test.ts +512 -0
  101. package/src/server/__tests__/loop-approval-expiry.test.ts +258 -0
  102. package/src/server/__tests__/loop-budget-service.test.ts +255 -0
  103. package/src/server/__tests__/loop-control-plane-backfill.test.ts +266 -0
  104. package/src/server/__tests__/loop-pattern-schema.test.ts +73 -0
  105. package/src/server/__tests__/loop-pattern-service.test.ts +148 -0
  106. package/src/server/__tests__/loop-run-state-machine.test.ts +101 -0
  107. package/src/server/__tests__/loop-trigger-service.test.ts +148 -0
  108. package/src/server/__tests__/loop-worker-claim.test.ts +341 -0
  109. package/src/server/__tests__/loop-worker-execution.test.ts +317 -0
  110. package/src/server/__tests__/native-sub-agent-observer.test.ts +288 -4
  111. package/src/server/__tests__/path-lock-service.test.ts +254 -0
  112. package/src/server/__tests__/skill-execution-task-policy.test.ts +140 -0
  113. package/src/server/__tests__/smoke.test.ts +162 -121
  114. package/src/server/__tests__/tool-loop-detection.test.ts +275 -0
  115. package/src/server/collections/agent-execution-spans.ts +55 -0
  116. package/src/server/collections/agent-harness-profile-versions.ts +26 -0
  117. package/src/server/collections/agent-harness-profiles.ts +71 -59
  118. package/src/server/collections/agent-loop-action-approvals.ts +39 -0
  119. package/src/server/collections/agent-loop-artifacts.ts +25 -0
  120. package/src/server/collections/agent-loop-circuit-states.ts +23 -0
  121. package/src/server/collections/agent-loop-control-settings.ts +21 -0
  122. package/src/server/collections/agent-loop-events.ts +98 -71
  123. package/src/server/collections/agent-loop-path-locks.ts +27 -0
  124. package/src/server/collections/agent-loop-patterns.ts +42 -0
  125. package/src/server/collections/agent-loop-runs.ts +170 -3
  126. package/src/server/collections/agent-loop-steps.ts +76 -0
  127. package/src/server/collections/agent-loop-usage-buckets.ts +22 -0
  128. package/src/server/collections/agent-loop-worktrees.ts +25 -0
  129. package/src/server/collections/skill-executions.ts +8 -0
  130. package/src/server/migrations/{20260427000000-change-packages-to-text.ts → 20260427000002-change-packages-to-text.ts} +52 -49
  131. package/src/server/migrations/20260429000000-add-llm-fields.ts +47 -46
  132. package/src/server/migrations/{20260429000000-fix-inputargs-json-to-text.ts → 20260429000001-fix-inputargs-json-to-text.ts} +45 -38
  133. package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +33 -32
  134. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +31 -30
  135. package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -0
  136. package/src/server/plugin.ts +55 -167
  137. package/src/server/resources/agent-harness-profile.ts +94 -0
  138. package/src/server/resources/agent-knowledge-insights.ts +5 -3
  139. package/src/server/resources/agent-loop-approval.ts +84 -0
  140. package/src/server/resources/agent-loop-artifact.ts +56 -0
  141. package/src/server/resources/agent-loop-events-stream.ts +105 -0
  142. package/src/server/resources/agent-loop.ts +204 -143
  143. package/src/server/resources/agent-monitor.ts +482 -482
  144. package/src/server/resources/resource-helpers.ts +33 -0
  145. package/src/server/resources/tracing.ts +266 -258
  146. package/src/server/services/AgentMemoryContextService.ts +44 -0
  147. package/src/server/services/DurableCircuitBreakerService.ts +239 -0
  148. package/src/server/services/ExecutionSpanService.ts +2 -0
  149. package/src/server/services/HarnessCompiler.ts +170 -0
  150. package/src/server/services/HarnessProfileService.ts +239 -0
  151. package/src/server/services/HarnessSchema.ts +194 -0
  152. package/src/server/services/LoopBudgetService.ts +275 -0
  153. package/src/server/services/LoopControlService.ts +124 -0
  154. package/src/server/services/LoopPatternSchema.ts +185 -0
  155. package/src/server/services/LoopPatternService.ts +143 -0
  156. package/src/server/services/LoopRunRepository.ts +336 -0
  157. package/src/server/services/LoopRunStateMachine.ts +529 -0
  158. package/src/server/services/LoopSchedulerService.ts +199 -0
  159. package/src/server/services/LoopTriggerService.ts +157 -0
  160. package/src/server/services/LoopWorkerService.ts +822 -0
  161. package/src/server/services/NativeSubAgentObserver.ts +186 -21
  162. package/src/server/services/PathLockService.ts +321 -0
  163. package/src/server/services/PluginAiRuntimeAdapter.ts +332 -0
  164. package/src/server/services/ToolLoopDetectionService.ts +213 -0
  165. package/src/server/services/VerificationSchema.ts +31 -0
  166. package/src/server/services/VerificationService.ts +264 -0
  167. package/src/server/services/harness-runtime-policy.ts +141 -0
  168. package/src/server/skill-hub/actions/__tests__/git-import.test.ts +15 -1
  169. package/src/server/skill-hub/actions/git-import.ts +9 -3
  170. package/src/server/skill-hub/plugin.ts +41 -3
  171. package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +235 -239
  172. package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +61 -63
  173. package/src/server/skill-hub/tasks/SkillExecutionTask.ts +43 -2
  174. package/src/server/utils/ensure-indexes.ts +96 -0
  175. package/src/server/utils/logging.ts +62 -63
  176. package/src/server/utils/loop-pattern-context.ts +20 -0
  177. package/dist/client-v2/214.79650a549273f163.js +0 -10
  178. package/dist/client-v2/253.9f0537713cee9e6c.js +0 -10
  179. package/dist/client-v2/264.718a107e43fc163c.js +0 -10
  180. package/dist/client-v2/373.f5d5292e53c4e832.js +0 -10
  181. package/dist/client-v2/418.ce8f5b2b8a229d1d.js +0 -10
  182. package/dist/client-v2/53.7c29c28043e9112d.js +0 -10
  183. package/dist/client-v2/619.bd3c5698b40705c3.js +0 -10
  184. package/dist/client-v2/677.a991ce0250ff5c77.js +0 -10
  185. package/dist/client-v2/925.f5370de8f6632d65.js +0 -10
  186. package/dist/server/services/AgentHarness.js +0 -81
  187. package/dist/server/services/AgentLoopController.js +0 -1023
  188. package/dist/server/services/AgentLoopRepository.js +0 -192
  189. package/dist/server/services/AgentLoopService.js +0 -142
  190. package/dist/server/services/AgentPlanValidator.js +0 -99
  191. package/dist/server/services/AgentPlannerService.js +0 -99
  192. package/dist/server/services/CircuitBreaker.js +0 -125
  193. package/dist/server/services/ContextAggregator.js +0 -201
  194. package/dist/server/services/PlanningPromptService.js +0 -95
  195. package/dist/server/tools/agent-loop.js +0 -373
  196. package/dist/server/tools/orchestrator-plan.js +0 -254
  197. package/src/client/AIEmployeeSelect.tsx +0 -47
  198. package/src/client/AIEmployeesContext.tsx +0 -102
  199. package/src/client/RulesTab.tsx +0 -2
  200. package/src/client/TracingTab.tsx +0 -436
  201. package/src/client/skill-hub/components/ExecutionProgress.tsx +0 -51
  202. package/src/client-v2/components/RulesTab.tsx +0 -2
  203. package/src/client-v2/pages/AgentRunsPage.tsx +0 -13
  204. package/src/server/__tests__/agent-loop-controller.test.ts +0 -375
  205. package/src/server/__tests__/context-aggregator.test.ts +0 -222
  206. package/src/server/__tests__/parallel-execution.test.ts +0 -318
  207. package/src/server/__tests__/planning-prompt-service.test.ts +0 -23
  208. package/src/server/services/AgentHarness.ts +0 -67
  209. package/src/server/services/AgentLoopController.ts +0 -1263
  210. package/src/server/services/AgentLoopRepository.ts +0 -178
  211. package/src/server/services/AgentLoopService.ts +0 -177
  212. package/src/server/services/AgentPlanValidator.ts +0 -73
  213. package/src/server/services/AgentPlannerService.ts +0 -80
  214. package/src/server/services/CircuitBreaker.ts +0 -126
  215. package/src/server/services/ContextAggregator.ts +0 -239
  216. package/src/server/services/PlanningPromptService.ts +0 -72
  217. package/src/server/tools/agent-loop.ts +0 -360
  218. package/src/server/tools/orchestrator-plan.ts +0 -255
@@ -0,0 +1,175 @@
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 HarnessCompiler_exports = {};
28
+ __export(HarnessCompiler_exports, {
29
+ compileHarness: () => compileHarness,
30
+ decideTool: () => decideTool
31
+ });
32
+ module.exports = __toCommonJS(HarnessCompiler_exports);
33
+ var import_HarnessSchema = require("./HarnessSchema");
34
+ const effectRisk = {
35
+ read: 0,
36
+ write: 1,
37
+ external: 2
38
+ };
39
+ const networkRisk = {
40
+ allow: 0,
41
+ restricted: 1,
42
+ deny: 2
43
+ };
44
+ function unique(values) {
45
+ return Array.from(new Set(values)).sort();
46
+ }
47
+ function union(values) {
48
+ return unique(values.flat());
49
+ }
50
+ function intersectRestrictions(values) {
51
+ const restrictions = values.filter((items) => items.length > 0).map((items) => new Set(items));
52
+ if (!restrictions.length) return [];
53
+ return unique(
54
+ Array.from(restrictions[0]).filter((item) => restrictions.every((restriction) => restriction.has(item)))
55
+ );
56
+ }
57
+ function minimumNullable(values) {
58
+ const limits = values.filter((value) => value !== null);
59
+ return limits.length ? Math.min(...limits) : null;
60
+ }
61
+ function strictestEffect(values) {
62
+ return values.reduce((strictest, value) => effectRisk[value] > effectRisk[strictest] ? value : strictest, "read");
63
+ }
64
+ function strictestNetwork(values) {
65
+ return values.reduce(
66
+ (strictest, value) => networkRisk[value] > networkRisk[strictest] ? value : strictest,
67
+ "allow"
68
+ );
69
+ }
70
+ const sharingRank = {
71
+ full: 0,
72
+ "feedback-only": 1,
73
+ disabled: 2
74
+ };
75
+ function strictestSharing(values) {
76
+ return values.reduce(
77
+ (strictest, value) => sharingRank[value] > sharingRank[strictest] ? value : strictest,
78
+ "full"
79
+ );
80
+ }
81
+ function mergeTimeouts(settings) {
82
+ const timeouts = {};
83
+ for (const layer of settings) {
84
+ for (const [name, timeoutMs] of Object.entries(layer.tools.timeouts)) {
85
+ timeouts[name] = timeouts[name] === void 0 ? timeoutMs : Math.min(timeouts[name], timeoutMs);
86
+ }
87
+ }
88
+ return timeouts;
89
+ }
90
+ function compileHarness(layers) {
91
+ if (!layers.length) {
92
+ throw new Error("At least one harness layer is required.");
93
+ }
94
+ const parsed = layers.map((layer) => ({ source: layer.source, settings: (0, import_HarnessSchema.parseHarnessSettings)(layer.settings) }));
95
+ const settings = parsed.map((layer) => layer.settings);
96
+ const effectNames = union(settings.map((layer) => Object.keys(layer.tools.effects)));
97
+ const effects = Object.fromEntries(
98
+ effectNames.map((name) => [
99
+ name,
100
+ strictestEffect(
101
+ settings.map((layer) => layer.tools.effects[name]).filter((effect) => effect !== void 0)
102
+ )
103
+ ])
104
+ );
105
+ return {
106
+ sources: parsed.map((layer) => layer.source),
107
+ tools: {
108
+ allow: intersectRestrictions(settings.map((layer) => layer.tools.allow)),
109
+ ask: union(settings.map((layer) => layer.tools.ask)),
110
+ deny: union(settings.map((layer) => layer.tools.deny)),
111
+ // Escalatable tools widen authority per approved call, so a child may only inherit the
112
+ // escalation surface every layer agrees on — same semantics as `allow`.
113
+ escalate: intersectRestrictions(settings.map((layer) => layer.tools.escalate)),
114
+ effects,
115
+ trustedPreHandlerTools: intersectRestrictions(settings.map((layer) => layer.tools.trustedPreHandlerTools)),
116
+ timeouts: mergeTimeouts(settings)
117
+ },
118
+ memory: {
119
+ enabled: settings.every((layer) => layer.memory.enabled),
120
+ scopes: intersectRestrictions(
121
+ settings.map((layer) => layer.memory.scopes)
122
+ ),
123
+ maxChars: Math.min(...settings.map((layer) => layer.memory.maxChars))
124
+ },
125
+ delegation: {
126
+ allowedEmployees: intersectRestrictions(settings.map((layer) => layer.delegation.allowedEmployees)),
127
+ maxDepth: minimumNullable(settings.map((layer) => layer.delegation.maxDepth)),
128
+ maxCount: minimumNullable(settings.map((layer) => layer.delegation.maxCount))
129
+ },
130
+ limits: {
131
+ timeoutMs: minimumNullable(settings.map((layer) => layer.limits.timeoutMs)),
132
+ recursionLimit: minimumNullable(settings.map((layer) => layer.limits.recursionLimit)),
133
+ maxInvocations: minimumNullable(settings.map((layer) => layer.limits.maxInvocations)),
134
+ maxToolCalls: minimumNullable(settings.map((layer) => layer.limits.maxToolCalls)),
135
+ maxInputTokens: minimumNullable(settings.map((layer) => layer.limits.maxInputTokens)),
136
+ maxOutputTokens: minimumNullable(settings.map((layer) => layer.limits.maxOutputTokens)),
137
+ maxTotalTokens: minimumNullable(settings.map((layer) => layer.limits.maxTotalTokens)),
138
+ maxCost: minimumNullable(settings.map((layer) => layer.limits.maxCost))
139
+ },
140
+ context: {
141
+ spill: {
142
+ maxInlineBytes: minimumNullable(settings.map((layer) => layer.context.spill.maxInlineBytes))
143
+ }
144
+ },
145
+ isolation: {
146
+ mode: settings.some((layer) => layer.isolation.mode === "worktree") ? "worktree" : "none",
147
+ requireWorktree: settings.some((layer) => layer.isolation.requireWorktree),
148
+ allowedConnectors: intersectRestrictions(settings.map((layer) => layer.isolation.allowedConnectors)),
149
+ networkAccess: strictestNetwork(settings.map((layer) => layer.isolation.networkAccess))
150
+ },
151
+ observability: {
152
+ enabled: settings.every((layer) => layer.observability.enabled),
153
+ tracingRetentionDays: Math.min(...settings.map((layer) => layer.observability.tracingRetentionDays)),
154
+ captureInputs: settings.every((layer) => layer.observability.captureInputs),
155
+ captureOutputs: settings.every((layer) => layer.observability.captureOutputs),
156
+ // Any layer demanding redaction wins; any layer restricting sharing wins. Telemetry safety
157
+ // is union-of-concerns, not intersection.
158
+ redactSecrets: settings.some((layer) => layer.observability.redactSecrets),
159
+ sharing: strictestSharing(settings.map((layer) => layer.observability.sharing))
160
+ }
161
+ };
162
+ }
163
+ function decideTool(harness, toolName, effect = harness.tools.effects[toolName] || "external") {
164
+ if (harness.tools.deny.includes(toolName)) return "deny";
165
+ if (harness.tools.ask.includes(toolName)) return "ask";
166
+ const explicitlyAllowed = harness.tools.allow.includes(toolName);
167
+ if (!explicitlyAllowed) return "ask";
168
+ if (effect !== "read" && !harness.tools.trustedPreHandlerTools.includes(toolName)) return "ask";
169
+ return "allow";
170
+ }
171
+ // Annotate the CommonJS export names for ESM import in node:
172
+ 0 && (module.exports = {
173
+ compileHarness,
174
+ decideTool
175
+ });
@@ -0,0 +1,233 @@
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 HarnessProfileService_exports = {};
28
+ __export(HarnessProfileService_exports, {
29
+ HarnessProfileService: () => HarnessProfileService
30
+ });
31
+ module.exports = __toCommonJS(HarnessProfileService_exports);
32
+ var import_HarnessSchema = require("./HarnessSchema");
33
+ function read(record, key) {
34
+ const model = record;
35
+ return typeof model.get === "function" ? model.get(key) : record[key];
36
+ }
37
+ function positiveId(value, label) {
38
+ const parsed = typeof value === "number" ? value : Number(value);
39
+ if (!Number.isSafeInteger(parsed) || parsed <= 0) {
40
+ throw new Error(`${label} must be a positive integer.`);
41
+ }
42
+ return parsed;
43
+ }
44
+ function versionRecord(record) {
45
+ return {
46
+ id: positiveId(read(record, "id"), "Harness profile version id"),
47
+ profileId: positiveId(read(record, "profileId"), "Harness profile id"),
48
+ version: positiveId(read(record, "version"), "Harness profile version"),
49
+ schemaVersion: positiveId(read(record, "schemaVersion"), "Harness schema version"),
50
+ status: read(record, "status") === "published" ? "published" : "draft",
51
+ settings: (0, import_HarnessSchema.parseHarnessSettings)(read(record, "settings")),
52
+ publishedById: read(record, "publishedById") || null,
53
+ publishedAt: read(record, "publishedAt") || null
54
+ };
55
+ }
56
+ class HarnessProfileService {
57
+ constructor(database) {
58
+ this.database = database;
59
+ }
60
+ validate(settings) {
61
+ return (0, import_HarnessSchema.validateHarnessSettings)(settings);
62
+ }
63
+ async createDraft(input, transaction) {
64
+ const profileId = positiveId(input.profileId, "Harness profile id");
65
+ const schemaVersion = positiveId(input.schemaVersion || 1, "Harness schema version");
66
+ const settings = (0, import_HarnessSchema.parseHarnessSettings)(input.settings);
67
+ const create = async (active) => {
68
+ await this.lockProfile(profileId, active);
69
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
70
+ const latest = await versions.findOne({
71
+ filter: { profileId },
72
+ sort: ["-version"],
73
+ transaction: active
74
+ });
75
+ const nextVersion = latest ? positiveId(read(latest, "version"), "Harness profile version") + 1 : 1;
76
+ const draft = await versions.create({
77
+ values: {
78
+ profileId,
79
+ version: nextVersion,
80
+ schemaVersion,
81
+ status: "draft",
82
+ settings
83
+ },
84
+ transaction: active
85
+ });
86
+ return versionRecord(draft);
87
+ };
88
+ return transaction ? create(transaction) : this.database.sequelize.transaction(create);
89
+ }
90
+ // One open draft per profile: editing saves into the latest draft when it has not been
91
+ // published yet, and only starts a new version once the previous one shipped. This keeps the
92
+ // version history a clean publish trail instead of accumulating abandoned drafts.
93
+ async saveDraft(input) {
94
+ const profileId = positiveId(input.profileId, "Harness profile id");
95
+ const settings = (0, import_HarnessSchema.parseHarnessSettings)(input.settings);
96
+ return this.database.sequelize.transaction(async (transaction) => {
97
+ await this.lockProfile(profileId, transaction);
98
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
99
+ const latest = await versions.findOne({
100
+ filter: { profileId },
101
+ sort: ["-version"],
102
+ transaction
103
+ });
104
+ if (latest && read(latest, "status") !== "published") {
105
+ await versions.update({ filterByTk: read(latest, "id"), values: { settings }, transaction });
106
+ const updated = await versions.findOne({ filterByTk: read(latest, "id"), transaction });
107
+ if (!updated) throw new Error(`Harness profile version ${read(latest, "id")} was not found after update.`);
108
+ return versionRecord(updated);
109
+ }
110
+ const nextVersion = latest ? positiveId(read(latest, "version"), "Harness profile version") + 1 : 1;
111
+ const schemaVersion = latest ? positiveId(read(latest, "schemaVersion") || 1, "Harness schema version") : 1;
112
+ const draft = await versions.create({
113
+ values: {
114
+ profileId,
115
+ version: nextVersion,
116
+ schemaVersion,
117
+ status: "draft",
118
+ settings
119
+ },
120
+ transaction
121
+ });
122
+ return versionRecord(draft);
123
+ });
124
+ }
125
+ async updateDraft(versionId, settings) {
126
+ const id = positiveId(versionId, "Harness profile version id");
127
+ const parsedSettings = (0, import_HarnessSchema.parseHarnessSettings)(settings);
128
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
129
+ const version = await versions.findOne({ filterByTk: id });
130
+ if (!version) throw new Error(`Harness profile version ${id} was not found.`);
131
+ if (read(version, "status") !== "draft") {
132
+ throw new Error("Published Harness profile versions are immutable.");
133
+ }
134
+ await versions.update({ filterByTk: id, values: { settings: parsedSettings } });
135
+ const updated = await versions.findOne({ filterByTk: id });
136
+ if (!updated) throw new Error(`Harness profile version ${id} was not found after update.`);
137
+ return versionRecord(updated);
138
+ }
139
+ async publish(versionId, publishedById, transaction) {
140
+ const id = positiveId(versionId, "Harness profile version id");
141
+ const publishVersion = async (active) => {
142
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
143
+ const candidate = await versions.findOne({ filterByTk: id, transaction: active });
144
+ if (!candidate) throw new Error(`Harness profile version ${id} was not found.`);
145
+ const profileId = positiveId(read(candidate, "profileId"), "Harness profile id");
146
+ await this.lockProfile(profileId, active);
147
+ const current = await versions.findOne({ filterByTk: id, transaction: active });
148
+ if (!current) throw new Error(`Harness profile version ${id} was not found.`);
149
+ if (read(current, "status") === "published") {
150
+ return versionRecord(current);
151
+ }
152
+ const settings = (0, import_HarnessSchema.parseHarnessSettings)(read(current, "settings"));
153
+ const now = /* @__PURE__ */ new Date();
154
+ await versions.update({
155
+ filterByTk: id,
156
+ values: {
157
+ status: "published",
158
+ settings,
159
+ publishedById: publishedById ? positiveId(publishedById, "Publisher id") : null,
160
+ publishedAt: now
161
+ },
162
+ transaction: active
163
+ });
164
+ await this.database.getRepository("agentHarnessProfiles").update({
165
+ filterByTk: profileId,
166
+ values: {
167
+ currentVersionId: id,
168
+ schemaVersion: positiveId(read(current, "schemaVersion"), "Harness schema version")
169
+ },
170
+ transaction: active
171
+ });
172
+ const published = await versions.findOne({ filterByTk: id, transaction: active });
173
+ if (!published) throw new Error(`Harness profile version ${id} was not found after publish.`);
174
+ return versionRecord(published);
175
+ };
176
+ return transaction ? publishVersion(transaction) : this.database.sequelize.transaction(publishVersion);
177
+ }
178
+ // Atomic bootstrap: the profile row and its first published version are created together, so a
179
+ // profile can never exist in a state where the row promises settings no version accounts for.
180
+ async createProfile(input) {
181
+ const tag = input.tag.trim();
182
+ if (!tag) throw new Error("Harness profile tag is required.");
183
+ const settings = (0, import_HarnessSchema.parseHarnessSettings)(input.settings);
184
+ return this.database.sequelize.transaction(async (transaction) => {
185
+ const profile = await this.database.getRepository("agentHarnessProfiles").create({
186
+ values: {
187
+ tag,
188
+ title: input.title || "",
189
+ description: input.description || "",
190
+ enabled: input.enabled !== false,
191
+ schemaVersion: 1
192
+ },
193
+ transaction
194
+ });
195
+ const profileId = positiveId(read(profile, "id"), "Harness profile id");
196
+ const draft = await this.createDraft({ profileId, settings }, transaction);
197
+ const published = await this.publish(draft.id, input.publishedById, transaction);
198
+ const created = await this.database.getRepository("agentHarnessProfiles").findOne({
199
+ filterByTk: profileId,
200
+ transaction
201
+ });
202
+ if (!created) throw new Error(`Harness profile ${profileId} was not found after create.`);
203
+ return { profile: created, version: published };
204
+ });
205
+ }
206
+ async getPublishedByTag(tag) {
207
+ const normalizedTag = tag.trim();
208
+ if (!normalizedTag) throw new Error("Harness profile tag is required.");
209
+ const profile = await this.database.getRepository("agentHarnessProfiles").findOne({
210
+ filter: { tag: normalizedTag, enabled: true }
211
+ });
212
+ if (!profile) return null;
213
+ const currentVersionId = Number(read(profile, "currentVersionId"));
214
+ if (!Number.isSafeInteger(currentVersionId) || currentVersionId <= 0) return null;
215
+ const version = await this.database.getRepository("agentHarnessProfileVersions").findOne({
216
+ filter: { id: currentVersionId, status: "published" }
217
+ });
218
+ return version ? versionRecord(version) : null;
219
+ }
220
+ async lockProfile(profileId, transaction) {
221
+ const profile = await this.database.getRepository("agentHarnessProfiles").findOne({
222
+ filterByTk: profileId,
223
+ transaction,
224
+ lock: transaction.LOCK.UPDATE
225
+ });
226
+ if (!profile) throw new Error(`Harness profile ${profileId} was not found.`);
227
+ return profile;
228
+ }
229
+ }
230
+ // Annotate the CommonJS export names for ESM import in node:
231
+ 0 && (module.exports = {
232
+ HarnessProfileService
233
+ });
@@ -0,0 +1,194 @@
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 HarnessSchema_exports = {};
28
+ __export(HarnessSchema_exports, {
29
+ harnessSettingsSchema: () => harnessSettingsSchema,
30
+ normalizeHarnessSettings: () => normalizeHarnessSettings,
31
+ parseHarnessSettings: () => parseHarnessSettings,
32
+ toolDecisionSchema: () => toolDecisionSchema,
33
+ toolEffectSchema: () => toolEffectSchema,
34
+ validateHarnessSettings: () => validateHarnessSettings
35
+ });
36
+ module.exports = __toCommonJS(HarnessSchema_exports);
37
+ var import_zod = require("zod");
38
+ const toolDecisionSchema = import_zod.z.enum(["allow", "ask", "deny"]);
39
+ const toolEffectSchema = import_zod.z.enum(["read", "write", "external"]);
40
+ const nullableLimit = import_zod.z.number().finite().nonnegative().nullable().default(null);
41
+ const nullablePositiveLimit = import_zod.z.number().finite().positive().nullable().default(null);
42
+ const harnessSettingsSchema = import_zod.z.object({
43
+ tools: import_zod.z.object({
44
+ allow: import_zod.z.array(import_zod.z.string().min(1)).default([]),
45
+ ask: import_zod.z.array(import_zod.z.string().min(1)).default([]),
46
+ deny: import_zod.z.array(import_zod.z.string().min(1)).default([]),
47
+ // Tools the harness does not grant but may be requested for a single call: invoking one
48
+ // interrupts exactly like `ask` and parks the run, but the approval row is tagged as an
49
+ // escalation. Approving widens authority for that one call only; the harness is unchanged.
50
+ escalate: import_zod.z.array(import_zod.z.string().min(1)).default([]),
51
+ effects: import_zod.z.record(toolEffectSchema).default({}),
52
+ trustedPreHandlerTools: import_zod.z.array(import_zod.z.string().min(1)).default([]),
53
+ // Per-tool wall-clock caps in milliseconds. Only enforceable where this plugin owns the
54
+ // execution pipeline (skill hub sandbox); elsewhere it is advisory observability data.
55
+ timeouts: import_zod.z.record(import_zod.z.number().int().positive()).default({})
56
+ }).default({}),
57
+ memory: import_zod.z.object({
58
+ enabled: import_zod.z.boolean().default(true),
59
+ scopes: import_zod.z.array(import_zod.z.enum(["public", "user", "agent_user"])).default(["public", "user", "agent_user"]),
60
+ maxChars: import_zod.z.number().int().min(500).max(2e4).default(6e3)
61
+ }).default({}),
62
+ delegation: import_zod.z.object({
63
+ allowedEmployees: import_zod.z.array(import_zod.z.string().min(1)).default([]),
64
+ maxDepth: import_zod.z.number().int().nonnegative().nullable().default(null),
65
+ maxCount: import_zod.z.number().int().nonnegative().nullable().default(null)
66
+ }).default({}),
67
+ limits: import_zod.z.object({
68
+ timeoutMs: nullablePositiveLimit,
69
+ recursionLimit: import_zod.z.number().int().positive().nullable().default(null),
70
+ maxInvocations: import_zod.z.number().int().nonnegative().nullable().default(null),
71
+ maxToolCalls: import_zod.z.number().int().nonnegative().nullable().default(null),
72
+ maxInputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
73
+ maxOutputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
74
+ maxTotalTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
75
+ maxCost: nullableLimit
76
+ }).default({}),
77
+ context: import_zod.z.object({
78
+ spill: import_zod.z.object({
79
+ // Tool/sub-agent outputs larger than this many UTF-8 bytes are stored on disk and
80
+ // replaced inline by a head/tail preview plus a locator. null keeps everything inline.
81
+ maxInlineBytes: import_zod.z.number().int().positive().nullable().default(null)
82
+ }).default({})
83
+ }).default({}),
84
+ isolation: import_zod.z.object({
85
+ mode: import_zod.z.enum(["none", "worktree"]).default("none"),
86
+ requireWorktree: import_zod.z.boolean().default(false),
87
+ allowedConnectors: import_zod.z.array(import_zod.z.string().min(1)).default([]),
88
+ networkAccess: import_zod.z.enum(["deny", "restricted", "allow"]).default("restricted")
89
+ }).default({}),
90
+ observability: import_zod.z.object({
91
+ enabled: import_zod.z.boolean().default(true),
92
+ tracingRetentionDays: import_zod.z.number().int().positive().max(3650).default(30),
93
+ captureInputs: import_zod.z.boolean().default(true),
94
+ captureOutputs: import_zod.z.boolean().default(true),
95
+ // Scrub values whose key names look secret-bearing (KEY/SECRET/TOKEN/PASSWORD/CREDENTIAL)
96
+ // before span inputs are persisted. Defaults on: telemetry must never be the leak vector.
97
+ redactSecrets: import_zod.z.boolean().default(true),
98
+ // Who span content may be shared with: full = inputs+outputs, feedback-only = outputs
99
+ // only, disabled = no span content persisted at all.
100
+ sharing: import_zod.z.enum(["full", "feedback-only", "disabled"]).default("full")
101
+ }).default({})
102
+ }).strict();
103
+ function isRecord(value) {
104
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
105
+ }
106
+ function stringArray(value) {
107
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.length > 0) : [];
108
+ }
109
+ function optionalNumber(value) {
110
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
111
+ }
112
+ function normalizeHarnessSettings(value) {
113
+ if (!isRecord(value)) return value;
114
+ const source = value;
115
+ const tools = isRecord(source.tools) ? source.tools : {};
116
+ const memory = isRecord(source.memory) ? source.memory : {};
117
+ const delegation = isRecord(source.delegation) ? source.delegation : {};
118
+ const limits = isRecord(source.limits) ? source.limits : {};
119
+ const context = isRecord(source.context) ? source.context : {};
120
+ const isolation = isRecord(source.isolation) ? source.isolation : {};
121
+ const observability = isRecord(source.observability) ? source.observability : {};
122
+ const knownKeys = /* @__PURE__ */ new Set([
123
+ "tools",
124
+ "memory",
125
+ "delegation",
126
+ "limits",
127
+ "isolation",
128
+ "observability",
129
+ "nativeObserverEnabled",
130
+ "memoryInjectionEnabled",
131
+ "memoryScopes",
132
+ "maxMemoryContextChars",
133
+ "maxContextChars",
134
+ "tracingRetentionDays",
135
+ "knowledgeScopes",
136
+ "preferFileTools",
137
+ "requirePlanApproval",
138
+ "allowSubAgents",
139
+ "allowToolCalls",
140
+ "maxParallelSubAgents",
141
+ "maxControllerSteps",
142
+ "requireVerification"
143
+ ]);
144
+ const unknownSettings = Object.fromEntries(Object.entries(source).filter(([key]) => !knownKeys.has(key)));
145
+ return {
146
+ ...unknownSettings,
147
+ tools: {
148
+ ...tools,
149
+ allow: stringArray(tools.allow),
150
+ ask: stringArray(tools.ask),
151
+ deny: stringArray(tools.deny),
152
+ escalate: stringArray(tools.escalate),
153
+ effects: isRecord(tools.effects) ? tools.effects : {},
154
+ trustedPreHandlerTools: stringArray(tools.trustedPreHandlerTools),
155
+ timeouts: isRecord(tools.timeouts) ? tools.timeouts : {}
156
+ },
157
+ memory: {
158
+ ...memory,
159
+ enabled: typeof memory.enabled === "boolean" ? memory.enabled : typeof source.memoryInjectionEnabled === "boolean" ? source.memoryInjectionEnabled : void 0,
160
+ scopes: Array.isArray(memory.scopes) ? memory.scopes : source.memoryScopes,
161
+ maxChars: optionalNumber(memory.maxChars) ?? optionalNumber(source.maxMemoryContextChars)
162
+ },
163
+ delegation: {
164
+ ...delegation,
165
+ allowedEmployees: stringArray(delegation.allowedEmployees)
166
+ },
167
+ limits,
168
+ context: {
169
+ ...context,
170
+ spill: isRecord(context.spill) ? context.spill : {}
171
+ },
172
+ isolation,
173
+ observability: {
174
+ ...observability,
175
+ enabled: typeof observability.enabled === "boolean" ? observability.enabled : typeof source.nativeObserverEnabled === "boolean" ? source.nativeObserverEnabled : void 0,
176
+ tracingRetentionDays: optionalNumber(observability.tracingRetentionDays) ?? optionalNumber(source.tracingRetentionDays)
177
+ }
178
+ };
179
+ }
180
+ function parseHarnessSettings(value) {
181
+ return harnessSettingsSchema.parse(normalizeHarnessSettings(value));
182
+ }
183
+ function validateHarnessSettings(value) {
184
+ return harnessSettingsSchema.safeParse(normalizeHarnessSettings(value));
185
+ }
186
+ // Annotate the CommonJS export names for ESM import in node:
187
+ 0 && (module.exports = {
188
+ harnessSettingsSchema,
189
+ normalizeHarnessSettings,
190
+ parseHarnessSettings,
191
+ toolDecisionSchema,
192
+ toolEffectSchema,
193
+ validateHarnessSettings
194
+ });