plugin-agent-orchestrator 1.1.3 → 1.1.4

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 (173) hide show
  1. package/dist/client/index.js +1 -1
  2. package/dist/client-v2/214.b063f33ba044a808.js +10 -0
  3. package/dist/client-v2/253.59577b40d9875be0.js +10 -0
  4. package/dist/client-v2/264.7ed8bee71fa5935c.js +10 -0
  5. package/dist/client-v2/{41.ba6e080cc0488143.js → 41.3deb9e57a0f64fc4.js} +1 -1
  6. package/dist/client-v2/418.58fa350f5496efd3.js +10 -0
  7. package/dist/client-v2/{53.7c29c28043e9112d.js → 53.9a10455323390f14.js} +1 -1
  8. package/dist/client-v2/619.0a2144aaffefe018.js +10 -0
  9. package/dist/client-v2/{70.bda9518881c05360.js → 70.ffff2997c10fd4b0.js} +1 -1
  10. package/dist/client-v2/{794.9bbb8d3a61b2bdf2.js → 794.a67a2614405ba627.js} +1 -1
  11. package/dist/client-v2/925.e5925bf21ed68e7a.js +10 -0
  12. package/dist/client-v2/{993.82778b6fd6db3cb1.js → 993.b0688fdc5ccb000a.js} +1 -1
  13. package/dist/client-v2/index.js +1 -1
  14. package/dist/externalVersion.js +8 -6
  15. package/dist/locale/en-US.json +48 -28
  16. package/dist/locale/vi-VN.json +48 -28
  17. package/dist/locale/zh-CN.json +48 -28
  18. package/dist/server/collections/agent-execution-spans.js +47 -0
  19. package/dist/server/collections/agent-harness-profile-versions.js +56 -0
  20. package/dist/server/collections/agent-harness-profiles.js +12 -0
  21. package/dist/server/collections/agent-loop-action-approvals.js +68 -0
  22. package/dist/server/collections/agent-loop-artifacts.js +55 -0
  23. package/dist/server/collections/agent-loop-circuit-states.js +53 -0
  24. package/dist/server/collections/agent-loop-control-settings.js +51 -0
  25. package/dist/server/collections/agent-loop-events.js +27 -0
  26. package/dist/server/collections/agent-loop-path-locks.js +57 -0
  27. package/dist/server/collections/agent-loop-patterns.js +72 -0
  28. package/dist/server/collections/agent-loop-runs.js +163 -2
  29. package/dist/server/collections/agent-loop-steps.js +69 -0
  30. package/dist/server/collections/agent-loop-usage-buckets.js +52 -0
  31. package/dist/server/collections/agent-loop-worktrees.js +55 -0
  32. package/dist/server/migrations/{20260427000000-change-packages-to-text.js → 20260427000002-change-packages-to-text.js} +2 -0
  33. package/dist/server/migrations/20260429000000-add-llm-fields.js +3 -2
  34. package/dist/server/migrations/{20260429000000-fix-inputargs-json-to-text.js → 20260429000001-fix-inputargs-json-to-text.js} +14 -6
  35. package/dist/server/migrations/20260503000000-add-orchestrator-trace-fields.js +2 -1
  36. package/dist/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.js +2 -1
  37. package/dist/server/migrations/20260803010000-backfill-loop-control-plane-data.js +262 -0
  38. package/dist/server/plugin.js +52 -150
  39. package/dist/server/resources/agent-loop-approval.js +83 -0
  40. package/dist/server/resources/agent-loop-artifact.js +86 -0
  41. package/dist/server/resources/agent-loop-events-stream.js +130 -0
  42. package/dist/server/resources/agent-loop.js +181 -139
  43. package/dist/server/resources/resource-helpers.js +63 -0
  44. package/dist/server/resources/tracing.js +121 -107
  45. package/dist/server/services/DurableCircuitBreakerService.js +229 -0
  46. package/dist/server/services/HarnessCompiler.js +142 -0
  47. package/dist/server/services/HarnessProfileService.js +168 -0
  48. package/dist/server/services/HarnessSchema.js +167 -0
  49. package/dist/server/services/LoopBudgetService.js +269 -0
  50. package/dist/server/services/LoopControlService.js +139 -0
  51. package/dist/server/services/LoopPatternSchema.js +180 -0
  52. package/dist/server/services/LoopPatternService.js +132 -0
  53. package/dist/server/services/LoopRunRepository.js +205 -0
  54. package/dist/server/services/LoopRunStateMachine.js +389 -0
  55. package/dist/server/services/LoopSchedulerService.js +193 -0
  56. package/dist/server/services/LoopTriggerService.js +128 -0
  57. package/dist/server/services/LoopWorkerService.js +461 -0
  58. package/dist/server/services/PathLockService.js +288 -0
  59. package/dist/server/services/PluginAiRuntimeAdapter.js +215 -0
  60. package/dist/server/services/VerificationSchema.js +59 -0
  61. package/dist/server/services/VerificationService.js +169 -0
  62. package/dist/server/skill-hub/actions/git-import.js +13 -7
  63. package/dist/server/skill-hub/services/RegistrySkillSnapshotService.js +1 -5
  64. package/dist/server/utils/ensure-indexes.js +111 -0
  65. package/dist/server/utils/loop-pattern-context.js +56 -0
  66. package/package.json +1 -1
  67. package/src/client/OrchestratorSettings.tsx +44 -0
  68. package/src/client-v2/components/AgentRunsTab.tsx +576 -494
  69. package/src/client-v2/components/HarnessProfilesTab.tsx +13 -8
  70. package/src/client-v2/components/MemoryInspectorTab.tsx +19 -3
  71. package/src/client-v2/components/TracingTab.tsx +515 -432
  72. package/src/client-v2/hooks/useApiRequest.ts +141 -121
  73. package/src/client-v2/skill-hub/components/SkillMetrics.tsx +8 -6
  74. package/src/locale/en-US.json +52 -28
  75. package/src/locale/vi-VN.json +52 -28
  76. package/src/locale/zh-CN.json +52 -28
  77. package/src/server/__tests__/circuit-breaker.test.ts +225 -146
  78. package/src/server/__tests__/harness-compiler.test.ts +131 -0
  79. package/src/server/__tests__/harness-profile-service.test.ts +116 -0
  80. package/src/server/__tests__/harness-tool-plan.test.ts +148 -0
  81. package/src/server/__tests__/loop-budget-service.test.ts +255 -0
  82. package/src/server/__tests__/loop-control-plane-backfill.test.ts +266 -0
  83. package/src/server/__tests__/loop-pattern-schema.test.ts +56 -0
  84. package/src/server/__tests__/loop-pattern-service.test.ts +148 -0
  85. package/src/server/__tests__/loop-run-state-machine.test.ts +90 -0
  86. package/src/server/__tests__/loop-worker-claim.test.ts +341 -0
  87. package/src/server/__tests__/loop-worker-execution.test.ts +236 -0
  88. package/src/server/__tests__/path-lock-service.test.ts +254 -0
  89. package/src/server/__tests__/smoke.test.ts +62 -21
  90. package/src/server/collections/agent-execution-spans.ts +47 -0
  91. package/src/server/collections/agent-harness-profile-versions.ts +26 -0
  92. package/src/server/collections/agent-harness-profiles.ts +12 -0
  93. package/src/server/collections/agent-loop-action-approvals.ts +38 -0
  94. package/src/server/collections/agent-loop-artifacts.ts +25 -0
  95. package/src/server/collections/agent-loop-circuit-states.ts +23 -0
  96. package/src/server/collections/agent-loop-control-settings.ts +21 -0
  97. package/src/server/collections/agent-loop-events.ts +27 -0
  98. package/src/server/collections/agent-loop-path-locks.ts +27 -0
  99. package/src/server/collections/agent-loop-patterns.ts +42 -0
  100. package/src/server/collections/agent-loop-runs.ts +163 -2
  101. package/src/server/collections/agent-loop-steps.ts +69 -0
  102. package/src/server/collections/agent-loop-usage-buckets.ts +22 -0
  103. package/src/server/collections/agent-loop-worktrees.ts +25 -0
  104. package/src/server/migrations/{20260427000000-change-packages-to-text.ts → 20260427000002-change-packages-to-text.ts} +3 -0
  105. package/src/server/migrations/20260429000000-add-llm-fields.ts +3 -2
  106. package/src/server/migrations/{20260429000000-fix-inputargs-json-to-text.ts → 20260429000001-fix-inputargs-json-to-text.ts} +13 -6
  107. package/src/server/migrations/20260503000000-add-orchestrator-trace-fields.ts +2 -1
  108. package/src/server/migrations/20260524000000-add-agent-loop-fields-to-skill-executions.ts +2 -1
  109. package/src/server/migrations/20260803010000-backfill-loop-control-plane-data.ts +293 -0
  110. package/src/server/plugin.ts +53 -167
  111. package/src/server/resources/agent-loop-approval.ts +52 -0
  112. package/src/server/resources/agent-loop-artifact.ts +56 -0
  113. package/src/server/resources/agent-loop-events-stream.ts +105 -0
  114. package/src/server/resources/agent-loop.ts +202 -143
  115. package/src/server/resources/agent-monitor.ts +482 -482
  116. package/src/server/resources/resource-helpers.ts +33 -0
  117. package/src/server/resources/tracing.ts +145 -137
  118. package/src/server/services/DurableCircuitBreakerService.ts +239 -0
  119. package/src/server/services/HarnessCompiler.ts +133 -0
  120. package/src/server/services/HarnessProfileService.ts +157 -0
  121. package/src/server/services/HarnessSchema.ts +163 -0
  122. package/src/server/services/LoopBudgetService.ts +275 -0
  123. package/src/server/services/LoopControlService.ts +124 -0
  124. package/src/server/services/LoopPatternSchema.ts +167 -0
  125. package/src/server/services/LoopPatternService.ts +143 -0
  126. package/src/server/services/LoopRunRepository.ts +237 -0
  127. package/src/server/services/LoopRunStateMachine.ts +432 -0
  128. package/src/server/services/LoopSchedulerService.ts +199 -0
  129. package/src/server/services/LoopTriggerService.ts +115 -0
  130. package/src/server/services/LoopWorkerService.ts +522 -0
  131. package/src/server/services/PathLockService.ts +321 -0
  132. package/src/server/services/PluginAiRuntimeAdapter.ts +315 -0
  133. package/src/server/services/VerificationSchema.ts +31 -0
  134. package/src/server/services/VerificationService.ts +185 -0
  135. package/src/server/skill-hub/actions/__tests__/git-import.test.ts +15 -1
  136. package/src/server/skill-hub/actions/git-import.ts +9 -3
  137. package/src/server/skill-hub/services/RegistrySkillSnapshotService.ts +1 -5
  138. package/src/server/skill-hub/services/__tests__/RegistrySkillSnapshotService.test.ts +1 -3
  139. package/src/server/utils/ensure-indexes.ts +96 -0
  140. package/src/server/utils/logging.ts +0 -1
  141. package/src/server/utils/loop-pattern-context.ts +20 -0
  142. package/dist/client-v2/214.79650a549273f163.js +0 -10
  143. package/dist/client-v2/253.9f0537713cee9e6c.js +0 -10
  144. package/dist/client-v2/264.718a107e43fc163c.js +0 -10
  145. package/dist/client-v2/418.ce8f5b2b8a229d1d.js +0 -10
  146. package/dist/client-v2/619.bd3c5698b40705c3.js +0 -10
  147. package/dist/client-v2/925.f5370de8f6632d65.js +0 -10
  148. package/dist/server/services/AgentHarness.js +0 -81
  149. package/dist/server/services/AgentLoopController.js +0 -1023
  150. package/dist/server/services/AgentLoopRepository.js +0 -192
  151. package/dist/server/services/AgentLoopService.js +0 -142
  152. package/dist/server/services/AgentPlanValidator.js +0 -99
  153. package/dist/server/services/AgentPlannerService.js +0 -99
  154. package/dist/server/services/CircuitBreaker.js +0 -125
  155. package/dist/server/services/ContextAggregator.js +0 -201
  156. package/dist/server/services/PlanningPromptService.js +0 -95
  157. package/dist/server/tools/agent-loop.js +0 -373
  158. package/dist/server/tools/orchestrator-plan.js +0 -254
  159. package/src/server/__tests__/agent-loop-controller.test.ts +0 -375
  160. package/src/server/__tests__/context-aggregator.test.ts +0 -222
  161. package/src/server/__tests__/parallel-execution.test.ts +0 -318
  162. package/src/server/__tests__/planning-prompt-service.test.ts +0 -23
  163. package/src/server/services/AgentHarness.ts +0 -67
  164. package/src/server/services/AgentLoopController.ts +0 -1263
  165. package/src/server/services/AgentLoopRepository.ts +0 -178
  166. package/src/server/services/AgentLoopService.ts +0 -177
  167. package/src/server/services/AgentPlanValidator.ts +0 -73
  168. package/src/server/services/AgentPlannerService.ts +0 -80
  169. package/src/server/services/CircuitBreaker.ts +0 -126
  170. package/src/server/services/ContextAggregator.ts +0 -239
  171. package/src/server/services/PlanningPromptService.ts +0 -72
  172. package/src/server/tools/agent-loop.ts +0 -360
  173. package/src/server/tools/orchestrator-plan.ts +0 -255
@@ -0,0 +1,142 @@
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
+ function compileHarness(layers) {
71
+ if (!layers.length) {
72
+ throw new Error("At least one harness layer is required.");
73
+ }
74
+ const parsed = layers.map((layer) => ({ source: layer.source, settings: (0, import_HarnessSchema.parseHarnessSettings)(layer.settings) }));
75
+ const settings = parsed.map((layer) => layer.settings);
76
+ const effectNames = union(settings.map((layer) => Object.keys(layer.tools.effects)));
77
+ const effects = Object.fromEntries(
78
+ effectNames.map((name) => [
79
+ name,
80
+ strictestEffect(
81
+ settings.map((layer) => layer.tools.effects[name]).filter((effect) => effect !== void 0)
82
+ )
83
+ ])
84
+ );
85
+ return {
86
+ sources: parsed.map((layer) => layer.source),
87
+ tools: {
88
+ allow: intersectRestrictions(settings.map((layer) => layer.tools.allow)),
89
+ ask: union(settings.map((layer) => layer.tools.ask)),
90
+ deny: union(settings.map((layer) => layer.tools.deny)),
91
+ effects,
92
+ trustedPreHandlerTools: intersectRestrictions(settings.map((layer) => layer.tools.trustedPreHandlerTools))
93
+ },
94
+ memory: {
95
+ enabled: settings.every((layer) => layer.memory.enabled),
96
+ scopes: intersectRestrictions(
97
+ settings.map((layer) => layer.memory.scopes)
98
+ ),
99
+ maxChars: Math.min(...settings.map((layer) => layer.memory.maxChars))
100
+ },
101
+ delegation: {
102
+ allowedEmployees: intersectRestrictions(settings.map((layer) => layer.delegation.allowedEmployees)),
103
+ maxDepth: minimumNullable(settings.map((layer) => layer.delegation.maxDepth)),
104
+ maxCount: minimumNullable(settings.map((layer) => layer.delegation.maxCount))
105
+ },
106
+ limits: {
107
+ timeoutMs: minimumNullable(settings.map((layer) => layer.limits.timeoutMs)),
108
+ recursionLimit: minimumNullable(settings.map((layer) => layer.limits.recursionLimit)),
109
+ maxInvocations: minimumNullable(settings.map((layer) => layer.limits.maxInvocations)),
110
+ maxToolCalls: minimumNullable(settings.map((layer) => layer.limits.maxToolCalls)),
111
+ maxInputTokens: minimumNullable(settings.map((layer) => layer.limits.maxInputTokens)),
112
+ maxOutputTokens: minimumNullable(settings.map((layer) => layer.limits.maxOutputTokens)),
113
+ maxTotalTokens: minimumNullable(settings.map((layer) => layer.limits.maxTotalTokens)),
114
+ maxCost: minimumNullable(settings.map((layer) => layer.limits.maxCost))
115
+ },
116
+ isolation: {
117
+ mode: settings.some((layer) => layer.isolation.mode === "worktree") ? "worktree" : "none",
118
+ requireWorktree: settings.some((layer) => layer.isolation.requireWorktree),
119
+ allowedConnectors: intersectRestrictions(settings.map((layer) => layer.isolation.allowedConnectors)),
120
+ networkAccess: strictestNetwork(settings.map((layer) => layer.isolation.networkAccess))
121
+ },
122
+ observability: {
123
+ enabled: settings.every((layer) => layer.observability.enabled),
124
+ tracingRetentionDays: Math.min(...settings.map((layer) => layer.observability.tracingRetentionDays)),
125
+ captureInputs: settings.every((layer) => layer.observability.captureInputs),
126
+ captureOutputs: settings.every((layer) => layer.observability.captureOutputs)
127
+ }
128
+ };
129
+ }
130
+ function decideTool(harness, toolName, effect = harness.tools.effects[toolName] || "external") {
131
+ if (harness.tools.deny.includes(toolName)) return "deny";
132
+ if (harness.tools.ask.includes(toolName)) return "ask";
133
+ const explicitlyAllowed = harness.tools.allow.includes(toolName);
134
+ if (!explicitlyAllowed) return "ask";
135
+ if (effect !== "read" && !harness.tools.trustedPreHandlerTools.includes(toolName)) return "ask";
136
+ return "allow";
137
+ }
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ compileHarness,
141
+ decideTool
142
+ });
@@ -0,0 +1,168 @@
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) {
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
+ return this.database.sequelize.transaction(async (transaction) => {
68
+ await this.lockProfile(profileId, transaction);
69
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
70
+ const latest = await versions.findOne({
71
+ filter: { profileId },
72
+ sort: ["-version"],
73
+ transaction
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
85
+ });
86
+ return versionRecord(draft);
87
+ });
88
+ }
89
+ async updateDraft(versionId, settings) {
90
+ const id = positiveId(versionId, "Harness profile version id");
91
+ const parsedSettings = (0, import_HarnessSchema.parseHarnessSettings)(settings);
92
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
93
+ const version = await versions.findOne({ filterByTk: id });
94
+ if (!version) throw new Error(`Harness profile version ${id} was not found.`);
95
+ if (read(version, "status") !== "draft") {
96
+ throw new Error("Published Harness profile versions are immutable.");
97
+ }
98
+ await versions.update({ filterByTk: id, values: { settings: parsedSettings } });
99
+ const updated = await versions.findOne({ filterByTk: id });
100
+ if (!updated) throw new Error(`Harness profile version ${id} was not found after update.`);
101
+ return versionRecord(updated);
102
+ }
103
+ async publish(versionId, publishedById) {
104
+ const id = positiveId(versionId, "Harness profile version id");
105
+ return this.database.sequelize.transaction(async (transaction) => {
106
+ const versions = this.database.getRepository("agentHarnessProfileVersions");
107
+ const candidate = await versions.findOne({ filterByTk: id, transaction });
108
+ if (!candidate) throw new Error(`Harness profile version ${id} was not found.`);
109
+ const profileId = positiveId(read(candidate, "profileId"), "Harness profile id");
110
+ await this.lockProfile(profileId, transaction);
111
+ const current = await versions.findOne({ filterByTk: id, transaction });
112
+ if (!current) throw new Error(`Harness profile version ${id} was not found.`);
113
+ if (read(current, "status") === "published") {
114
+ return versionRecord(current);
115
+ }
116
+ const settings = (0, import_HarnessSchema.parseHarnessSettings)(read(current, "settings"));
117
+ const now = /* @__PURE__ */ new Date();
118
+ await versions.update({
119
+ filterByTk: id,
120
+ values: {
121
+ status: "published",
122
+ settings,
123
+ publishedById: publishedById ? positiveId(publishedById, "Publisher id") : null,
124
+ publishedAt: now
125
+ },
126
+ transaction
127
+ });
128
+ await this.database.getRepository("agentHarnessProfiles").update({
129
+ filterByTk: profileId,
130
+ values: {
131
+ currentVersionId: id,
132
+ schemaVersion: positiveId(read(current, "schemaVersion"), "Harness schema version")
133
+ },
134
+ transaction
135
+ });
136
+ const published = await versions.findOne({ filterByTk: id, transaction });
137
+ if (!published) throw new Error(`Harness profile version ${id} was not found after publish.`);
138
+ return versionRecord(published);
139
+ });
140
+ }
141
+ async getPublishedByTag(tag) {
142
+ const normalizedTag = tag.trim();
143
+ if (!normalizedTag) throw new Error("Harness profile tag is required.");
144
+ const profile = await this.database.getRepository("agentHarnessProfiles").findOne({
145
+ filter: { tag: normalizedTag, enabled: true }
146
+ });
147
+ if (!profile) return null;
148
+ const currentVersionId = Number(read(profile, "currentVersionId"));
149
+ if (!Number.isSafeInteger(currentVersionId) || currentVersionId <= 0) return null;
150
+ const version = await this.database.getRepository("agentHarnessProfileVersions").findOne({
151
+ filter: { id: currentVersionId, status: "published" }
152
+ });
153
+ return version ? versionRecord(version) : null;
154
+ }
155
+ async lockProfile(profileId, transaction) {
156
+ const profile = await this.database.getRepository("agentHarnessProfiles").findOne({
157
+ filterByTk: profileId,
158
+ transaction,
159
+ lock: transaction.LOCK.UPDATE
160
+ });
161
+ if (!profile) throw new Error(`Harness profile ${profileId} was not found.`);
162
+ return profile;
163
+ }
164
+ }
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ HarnessProfileService
168
+ });
@@ -0,0 +1,167 @@
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
+ effects: import_zod.z.record(toolEffectSchema).default({}),
48
+ trustedPreHandlerTools: import_zod.z.array(import_zod.z.string().min(1)).default([])
49
+ }).default({}),
50
+ memory: import_zod.z.object({
51
+ enabled: import_zod.z.boolean().default(true),
52
+ scopes: import_zod.z.array(import_zod.z.enum(["public", "user", "agent_user"])).default(["public", "user", "agent_user"]),
53
+ maxChars: import_zod.z.number().int().min(500).max(2e4).default(6e3)
54
+ }).default({}),
55
+ delegation: import_zod.z.object({
56
+ allowedEmployees: import_zod.z.array(import_zod.z.string().min(1)).default([]),
57
+ maxDepth: import_zod.z.number().int().nonnegative().nullable().default(null),
58
+ maxCount: import_zod.z.number().int().nonnegative().nullable().default(null)
59
+ }).default({}),
60
+ limits: import_zod.z.object({
61
+ timeoutMs: nullablePositiveLimit,
62
+ recursionLimit: import_zod.z.number().int().positive().nullable().default(null),
63
+ maxInvocations: import_zod.z.number().int().nonnegative().nullable().default(null),
64
+ maxToolCalls: import_zod.z.number().int().nonnegative().nullable().default(null),
65
+ maxInputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
66
+ maxOutputTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
67
+ maxTotalTokens: import_zod.z.number().int().nonnegative().nullable().default(null),
68
+ maxCost: nullableLimit
69
+ }).default({}),
70
+ isolation: import_zod.z.object({
71
+ mode: import_zod.z.enum(["none", "worktree"]).default("none"),
72
+ requireWorktree: import_zod.z.boolean().default(false),
73
+ allowedConnectors: import_zod.z.array(import_zod.z.string().min(1)).default([]),
74
+ networkAccess: import_zod.z.enum(["deny", "restricted", "allow"]).default("restricted")
75
+ }).default({}),
76
+ observability: import_zod.z.object({
77
+ enabled: import_zod.z.boolean().default(true),
78
+ tracingRetentionDays: import_zod.z.number().int().positive().max(3650).default(30),
79
+ captureInputs: import_zod.z.boolean().default(true),
80
+ captureOutputs: import_zod.z.boolean().default(true)
81
+ }).default({})
82
+ }).strict();
83
+ function isRecord(value) {
84
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
85
+ }
86
+ function stringArray(value) {
87
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.length > 0) : [];
88
+ }
89
+ function optionalNumber(value) {
90
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
91
+ }
92
+ function normalizeHarnessSettings(value) {
93
+ if (!isRecord(value)) return value;
94
+ const source = value;
95
+ const tools = isRecord(source.tools) ? source.tools : {};
96
+ const memory = isRecord(source.memory) ? source.memory : {};
97
+ const delegation = isRecord(source.delegation) ? source.delegation : {};
98
+ const limits = isRecord(source.limits) ? source.limits : {};
99
+ const isolation = isRecord(source.isolation) ? source.isolation : {};
100
+ const observability = isRecord(source.observability) ? source.observability : {};
101
+ const knownKeys = /* @__PURE__ */ new Set([
102
+ "tools",
103
+ "memory",
104
+ "delegation",
105
+ "limits",
106
+ "isolation",
107
+ "observability",
108
+ "nativeObserverEnabled",
109
+ "memoryInjectionEnabled",
110
+ "memoryScopes",
111
+ "maxMemoryContextChars",
112
+ "maxContextChars",
113
+ "tracingRetentionDays",
114
+ "knowledgeScopes",
115
+ "preferFileTools",
116
+ "requirePlanApproval",
117
+ "allowSubAgents",
118
+ "allowToolCalls",
119
+ "maxParallelSubAgents",
120
+ "maxControllerSteps",
121
+ "requireVerification"
122
+ ]);
123
+ const unknownSettings = Object.fromEntries(Object.entries(source).filter(([key]) => !knownKeys.has(key)));
124
+ return {
125
+ ...unknownSettings,
126
+ tools: {
127
+ ...tools,
128
+ allow: stringArray(tools.allow),
129
+ ask: stringArray(tools.ask),
130
+ deny: stringArray(tools.deny),
131
+ effects: isRecord(tools.effects) ? tools.effects : {},
132
+ trustedPreHandlerTools: stringArray(tools.trustedPreHandlerTools)
133
+ },
134
+ memory: {
135
+ ...memory,
136
+ enabled: typeof memory.enabled === "boolean" ? memory.enabled : typeof source.memoryInjectionEnabled === "boolean" ? source.memoryInjectionEnabled : void 0,
137
+ scopes: Array.isArray(memory.scopes) ? memory.scopes : source.memoryScopes,
138
+ maxChars: optionalNumber(memory.maxChars) ?? optionalNumber(source.maxMemoryContextChars)
139
+ },
140
+ delegation: {
141
+ ...delegation,
142
+ allowedEmployees: stringArray(delegation.allowedEmployees)
143
+ },
144
+ limits,
145
+ isolation,
146
+ observability: {
147
+ ...observability,
148
+ enabled: typeof observability.enabled === "boolean" ? observability.enabled : typeof source.nativeObserverEnabled === "boolean" ? source.nativeObserverEnabled : void 0,
149
+ tracingRetentionDays: optionalNumber(observability.tracingRetentionDays) ?? optionalNumber(source.tracingRetentionDays)
150
+ }
151
+ };
152
+ }
153
+ function parseHarnessSettings(value) {
154
+ return harnessSettingsSchema.parse(normalizeHarnessSettings(value));
155
+ }
156
+ function validateHarnessSettings(value) {
157
+ return harnessSettingsSchema.safeParse(normalizeHarnessSettings(value));
158
+ }
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ harnessSettingsSchema,
162
+ normalizeHarnessSettings,
163
+ parseHarnessSettings,
164
+ toolDecisionSchema,
165
+ toolEffectSchema,
166
+ validateHarnessSettings
167
+ });