@botbotgo/agent-harness 0.0.475 → 0.0.476

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 (227) hide show
  1. package/README.md +3 -1234
  2. package/README.zh.md +3 -1191
  3. package/dist/acp.js +1 -1
  4. package/dist/api.js +1 -404
  5. package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
  6. package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
  7. package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
  8. package/dist/cli/chat-interactive.js +25 -244
  9. package/dist/cli/chat-rendering.js +6 -100
  10. package/dist/cli/chat-stream.js +23 -512
  11. package/dist/cli/chat-ui.js +21 -199
  12. package/dist/cli/chat-workspace.js +2 -210
  13. package/dist/cli/main.js +21 -428
  14. package/dist/cli/managed-service-commands.js +9 -63
  15. package/dist/cli/managed-service.js +2 -137
  16. package/dist/cli/options-init-chat.js +1 -108
  17. package/dist/cli/options-runtime.js +1 -158
  18. package/dist/cli/options-serve.js +1 -282
  19. package/dist/cli/options.js +2 -19
  20. package/dist/cli/process-guards.js +1 -139
  21. package/dist/cli/request-tree.js +7 -296
  22. package/dist/cli/runtime-commands.js +12 -258
  23. package/dist/cli/runtime-output.js +16 -155
  24. package/dist/cli/server-commands.js +16 -270
  25. package/dist/cli/workspace.js +1 -67
  26. package/dist/cli.js +1 -7
  27. package/dist/client/acp.js +1 -1
  28. package/dist/client/in-process.js +1 -67
  29. package/dist/client/index.js +1 -2
  30. package/dist/client/types.js +0 -1
  31. package/dist/client.js +1 -1
  32. package/dist/contracts/core.js +1 -1
  33. package/dist/contracts/runtime-evaluation.js +0 -1
  34. package/dist/contracts/runtime-memory.js +0 -1
  35. package/dist/contracts/runtime-observability.js +0 -1
  36. package/dist/contracts/runtime-requests.js +0 -1
  37. package/dist/contracts/runtime-scheduling.js +0 -1
  38. package/dist/contracts/runtime.js +1 -27
  39. package/dist/contracts/types.js +1 -3
  40. package/dist/contracts/workspace.js +0 -1
  41. package/dist/flow/build-flow-graph.js +1 -50
  42. package/dist/flow/export-mermaid.js +2 -464
  43. package/dist/flow/export-sequence-mermaid.js +2 -325
  44. package/dist/flow/flow-graph-normalization.js +1 -214
  45. package/dist/flow/flow-graph-runtime.js +1 -107
  46. package/dist/flow/flow-graph-upstream.js +1 -494
  47. package/dist/flow/index.js +1 -3
  48. package/dist/flow/types.js +0 -1
  49. package/dist/index.js +1 -5
  50. package/dist/init-project.js +1 -1
  51. package/dist/knowledge/config.js +1 -32
  52. package/dist/knowledge/contracts.js +0 -1
  53. package/dist/knowledge/index.js +1 -2
  54. package/dist/knowledge/module.js +12 -909
  55. package/dist/knowledge/procedural/config.js +1 -125
  56. package/dist/knowledge/procedural/index.js +1 -2
  57. package/dist/knowledge/procedural/manager.js +9 -345
  58. package/dist/mcp.js +1 -2
  59. package/dist/package-version.d.ts +1 -1
  60. package/dist/package-version.js +1 -2
  61. package/dist/persistence/file-store.js +3 -758
  62. package/dist/persistence/sqlite-request-context-store.js +5 -54
  63. package/dist/persistence/sqlite-request-queue-store.js +10 -108
  64. package/dist/persistence/sqlite-runtime.js +1 -86
  65. package/dist/persistence/sqlite-store.js +62 -810
  66. package/dist/persistence/types.js +0 -1
  67. package/dist/projections/presentation.js +37 -206
  68. package/dist/projections/request-events.js +2 -502
  69. package/dist/projections/upstream-events.js +1 -201
  70. package/dist/protocol/a2a/http-discovery.js +1 -178
  71. package/dist/protocol/a2a/http-rpc.js +6 -622
  72. package/dist/protocol/a2a/http.js +1 -138
  73. package/dist/protocol/a2a/task-state.js +3 -317
  74. package/dist/protocol/acp/client.js +8 -294
  75. package/dist/protocol/acp/harness-client.js +1 -218
  76. package/dist/protocol/acp/http.js +5 -130
  77. package/dist/protocol/acp/server.js +1 -310
  78. package/dist/protocol/acp/stdio.js +2 -69
  79. package/dist/protocol/ag-ui/http.js +3 -378
  80. package/dist/protocol/mcp/server.js +1 -428
  81. package/dist/resource/backend/workspace-scoped-backend.js +1 -319
  82. package/dist/resource/isolation.js +1 -237
  83. package/dist/resource/mcp/tool-support.js +3 -296
  84. package/dist/resource/mcp-tool-support.js +1 -2
  85. package/dist/resource/providers/resource-provider.js +1 -215
  86. package/dist/resource/resource-impl.js +1 -3
  87. package/dist/resource/resource-types.js +0 -1
  88. package/dist/resource/resource.js +1 -1
  89. package/dist/resource/sources.js +1 -247
  90. package/dist/resource/tools/function-tool-resolver.js +2 -272
  91. package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
  92. package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
  93. package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
  94. package/dist/runtime/adapter/flow/execution-context.js +1 -71
  95. package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
  96. package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
  97. package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
  98. package/dist/runtime/adapter/invocation-result.js +2 -473
  99. package/dist/runtime/adapter/local-tool-invocation.js +6 -638
  100. package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
  101. package/dist/runtime/adapter/middleware-assembly.js +5 -477
  102. package/dist/runtime/adapter/model/invocation-request.js +3 -183
  103. package/dist/runtime/adapter/model/message-assembly.js +1 -28
  104. package/dist/runtime/adapter/model/model-providers.js +23 -1115
  105. package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
  106. package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
  107. package/dist/runtime/adapter/resilience.js +1 -104
  108. package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
  109. package/dist/runtime/adapter/runtime-shell.js +5 -166
  110. package/dist/runtime/adapter/stream-event-projection.js +2 -622
  111. package/dist/runtime/adapter/stream-text-consumption.js +1 -18
  112. package/dist/runtime/adapter/terminal-status.js +2 -67
  113. package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
  114. package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
  115. package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
  116. package/dist/runtime/adapter/tool/provider-tool.js +1 -25
  117. package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
  118. package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
  119. package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
  120. package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
  121. package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
  122. package/dist/runtime/adapter/tool/tool-replay.js +1 -37
  123. package/dist/runtime/adapter/tool-resolution.js +1 -86
  124. package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
  125. package/dist/runtime/agent-runtime-adapter.js +60 -2338
  126. package/dist/runtime/agent-runtime-assembly.js +7 -249
  127. package/dist/runtime/env/runtime-env.js +1 -62
  128. package/dist/runtime/harness/background-runtime.js +1 -8
  129. package/dist/runtime/harness/bindings.js +1 -58
  130. package/dist/runtime/harness/events/event-bus.js +1 -16
  131. package/dist/runtime/harness/events/event-sink.js +1 -61
  132. package/dist/runtime/harness/events/events.js +1 -80
  133. package/dist/runtime/harness/events/listener-runtime.js +1 -13
  134. package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
  135. package/dist/runtime/harness/events/streaming.js +1 -100
  136. package/dist/runtime/harness/events/timeline.js +1 -52
  137. package/dist/runtime/harness/public-shapes.js +1 -186
  138. package/dist/runtime/harness/run/artifact-paths.js +1 -15
  139. package/dist/runtime/harness/run/governance.js +1 -295
  140. package/dist/runtime/harness/run/helpers.js +1 -71
  141. package/dist/runtime/harness/run/inspection.js +1 -409
  142. package/dist/runtime/harness/run/operator-overview.js +1 -80
  143. package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
  144. package/dist/runtime/harness/run/recovery.js +1 -162
  145. package/dist/runtime/harness/run/resources.js +1 -60
  146. package/dist/runtime/harness/run/resume.js +1 -56
  147. package/dist/runtime/harness/run/routing.js +1 -48
  148. package/dist/runtime/harness/run/run-lifecycle.js +1 -66
  149. package/dist/runtime/harness/run/run-operations.js +1 -217
  150. package/dist/runtime/harness/run/run-queue.js +1 -43
  151. package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
  152. package/dist/runtime/harness/run/session-records.js +1 -97
  153. package/dist/runtime/harness/run/start-run.js +1 -120
  154. package/dist/runtime/harness/run/startup-runtime.js +1 -69
  155. package/dist/runtime/harness/run/stream-run.js +8 -1418
  156. package/dist/runtime/harness/run/surface-semantics.js +1 -79
  157. package/dist/runtime/harness/runtime-defaults.js +1 -39
  158. package/dist/runtime/harness/system/boundary-analysis.js +1 -234
  159. package/dist/runtime/harness/system/health-monitor.js +1 -258
  160. package/dist/runtime/harness/system/inventory.js +1 -129
  161. package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
  162. package/dist/runtime/harness/system/policy-engine.js +1 -175
  163. package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
  164. package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
  165. package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
  166. package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
  167. package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
  168. package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
  169. package/dist/runtime/harness/system/session-memory-sync.js +3 -113
  170. package/dist/runtime/harness/system/skill-requirements.js +1 -112
  171. package/dist/runtime/harness/system/store.js +9 -365
  172. package/dist/runtime/harness/tool-gateway/index.js +1 -2
  173. package/dist/runtime/harness/tool-gateway/policy.js +1 -45
  174. package/dist/runtime/harness/tool-gateway/validation.js +1 -176
  175. package/dist/runtime/harness/tool-schema.js +1 -3
  176. package/dist/runtime/harness.js +3 -1490
  177. package/dist/runtime/index.js +1 -3
  178. package/dist/runtime/layout/runtime-layout.js +1 -31
  179. package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
  180. package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
  181. package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
  182. package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
  183. package/dist/runtime/parsing/output-content.js +10 -550
  184. package/dist/runtime/parsing/output-parsing.js +1 -4
  185. package/dist/runtime/parsing/output-recovery.js +3 -213
  186. package/dist/runtime/parsing/output-tool-args.js +7 -663
  187. package/dist/runtime/parsing/stream-event-parsing.js +3 -362
  188. package/dist/runtime/prompts/runtime-prompts.js +4 -73
  189. package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
  190. package/dist/runtime/skills/skill-metadata.js +1 -197
  191. package/dist/runtime/startup-tracing.js +2 -37
  192. package/dist/runtime/support/compiled-binding.js +1 -290
  193. package/dist/runtime/support/embedding-models.js +1 -118
  194. package/dist/runtime/support/harness-support.js +5 -137
  195. package/dist/runtime/support/llamaindex.js +1 -108
  196. package/dist/runtime/support/runtime-adapter-options.js +1 -29
  197. package/dist/runtime/support/runtime-factories.js +1 -51
  198. package/dist/runtime/support/vector-stores.js +9 -270
  199. package/dist/scaffold/init-project.js +54 -233
  200. package/dist/tooling/extensions.js +1 -311
  201. package/dist/tooling/module-loader.js +1 -55
  202. package/dist/tools.js +1 -176
  203. package/dist/utils/agent-display.js +1 -18
  204. package/dist/utils/bundled-text.js +4 -39
  205. package/dist/utils/compiled-binding.js +1 -33
  206. package/dist/utils/fs.js +2 -45
  207. package/dist/utils/id.js +1 -9
  208. package/dist/utils/message-content.js +1 -30
  209. package/dist/utils/object.js +1 -6
  210. package/dist/workspace/agent-binding-compiler.js +3 -613
  211. package/dist/workspace/compile.js +1 -472
  212. package/dist/workspace/framework-contract-validation.js +2 -322
  213. package/dist/workspace/index.js +1 -1
  214. package/dist/workspace/object-loader-paths.js +1 -71
  215. package/dist/workspace/object-loader-readers.js +1 -187
  216. package/dist/workspace/object-loader.js +1 -754
  217. package/dist/workspace/resource-compilers.js +1 -374
  218. package/dist/workspace/support/agent-capabilities.js +1 -37
  219. package/dist/workspace/support/agent-execution-config.js +1 -44
  220. package/dist/workspace/support/discovery.js +1 -147
  221. package/dist/workspace/support/source-collectors.js +1 -30
  222. package/dist/workspace/support/source-protocols.js +2 -192
  223. package/dist/workspace/support/workspace-ref-utils.js +1 -362
  224. package/dist/workspace/tool-hydration.js +1 -280
  225. package/dist/workspace/validate.js +1 -99
  226. package/dist/workspace/yaml-object-reader.js +1 -285
  227. package/package.json +7 -3
@@ -1,322 +1,2 @@
1
- import path from "node:path";
2
- import { validateSkillMetadata } from "../runtime/skills/skill-metadata.js";
3
- import { getAgentExecutionConfigValue } from "./support/agent-execution-config.js";
4
- import { getRuntimeAgentDefaults, getWorkspaceObject, resolvePromptValue } from "./support/workspace-ref-utils.js";
5
- const UPSTREAM_GENERAL_PURPOSE_SUBAGENT_NAME = "general-purpose";
6
- const FRAMEWORK_AGENT_TOOL_NAMES = new Set(["task"]);
7
- const FRAMEWORK_EXECUTION_TOOL_NAMES = new Set(["write_todos", "read_todos"]);
8
- const TERMINAL_STATUS_VALUES = new Set(["completed", "blocked", "failed", "refused"]);
9
- function normalizeMode(mode) {
10
- if (mode === "warn" || mode === "error") {
11
- return mode;
12
- }
13
- return "off";
14
- }
15
- export function resolveFrameworkContractValidationMode(mode) {
16
- if (mode === "warn" || mode === "error" || mode === "off") {
17
- return mode;
18
- }
19
- const envValue = process.env.AGENT_HARNESS_FRAMEWORK_CONTRACT_VALIDATION?.trim().toLowerCase();
20
- if (envValue === "warn" || envValue === "error" || envValue === "off") {
21
- return envValue;
22
- }
23
- return "off";
24
- }
25
- function isPathWithinRoot(candidate, root) {
26
- const relative = path.relative(path.resolve(root), path.resolve(candidate));
27
- return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
28
- }
29
- function isWorkspaceOwnedPath(candidate, roots) {
30
- return roots.some((root) => isPathWithinRoot(candidate, root));
31
- }
32
- function addIssue(issues, code, message) {
33
- issues.push({ code, message });
34
- }
35
- function stripRefPrefix(value, prefix) {
36
- return value.startsWith(prefix) ? value.slice(prefix.length) : value;
37
- }
38
- function resolveRefId(value) {
39
- return stripRefPrefix(stripRefPrefix(value, "agent/"), "tool/");
40
- }
41
- function readBuiltinToolsConfig(agent) {
42
- const value = getAgentExecutionConfigValue(agent, "builtinTools");
43
- return typeof value === "object" && value && !Array.isArray(value)
44
- ? value
45
- : undefined;
46
- }
47
- function readExecutionContractConfig(agent) {
48
- const value = getAgentExecutionConfigValue(agent, "executionContract");
49
- return typeof value === "object" && value && !Array.isArray(value)
50
- ? value
51
- : undefined;
52
- }
53
- function readRecoveryEvidenceToolName(value) {
54
- if (typeof value === "string") {
55
- return value.trim();
56
- }
57
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
58
- return "";
59
- }
60
- const name = value.name;
61
- return typeof name === "string" ? name.trim() : "";
62
- }
63
- function collectAgentToolNames(agent, tools, ownsDelegation) {
64
- const names = new Set(FRAMEWORK_EXECUTION_TOOL_NAMES);
65
- if (ownsDelegation) {
66
- for (const toolName of FRAMEWORK_AGENT_TOOL_NAMES) {
67
- names.add(toolName);
68
- }
69
- }
70
- for (const ref of agent.toolRefs) {
71
- const tool = tools.get(resolveRefId(ref));
72
- if (tool) {
73
- names.add(tool.id);
74
- names.add(tool.name);
75
- }
76
- names.add(resolveRefId(ref));
77
- }
78
- for (const binding of agent.toolBindings ?? []) {
79
- const tool = tools.get(resolveRefId(binding.ref));
80
- if (tool) {
81
- names.add(tool.id);
82
- names.add(tool.name);
83
- }
84
- names.add(resolveRefId(binding.ref));
85
- }
86
- for (const tool of agent.inlineTools ?? []) {
87
- names.add(tool.id);
88
- names.add(tool.name);
89
- }
90
- return names;
91
- }
92
- function hasDuplicateValues(values) {
93
- return new Set(values).size !== values.length;
94
- }
95
- function readObject(value) {
96
- return typeof value === "object" && value !== null && !Array.isArray(value)
97
- ? value
98
- : undefined;
99
- }
100
- function normalizeResponseFormatRef(ref) {
101
- return ref.startsWith("response-format/") ? ref : `response-format/${ref}`;
102
- }
103
- function resolveResponseFormatRef(refs, ref) {
104
- if (!refs || !ref) {
105
- return undefined;
106
- }
107
- const object = getWorkspaceObject(refs, normalizeResponseFormatRef(ref));
108
- if (!object || object.kind !== "response-format") {
109
- return undefined;
110
- }
111
- return object.value.format;
112
- }
113
- function mergeResponseFormats(base, override) {
114
- if (override === undefined) {
115
- return base;
116
- }
117
- if (typeof base === "object" &&
118
- base &&
119
- typeof override === "object" &&
120
- override &&
121
- !Array.isArray(base) &&
122
- !Array.isArray(override)) {
123
- const merged = { ...base };
124
- for (const [key, value] of Object.entries(override)) {
125
- if (key === "required" && Array.isArray(merged.required) && Array.isArray(value)) {
126
- merged.required = Array.from(new Set([...merged.required, ...value]));
127
- continue;
128
- }
129
- if (key === "properties" &&
130
- typeof merged.properties === "object" &&
131
- merged.properties &&
132
- !Array.isArray(merged.properties) &&
133
- typeof value === "object" &&
134
- value &&
135
- !Array.isArray(value)) {
136
- merged.properties = {
137
- ...merged.properties,
138
- ...value,
139
- };
140
- continue;
141
- }
142
- merged[key] = key in merged ? mergeResponseFormats(merged[key], value) : value;
143
- }
144
- return merged;
145
- }
146
- return override;
147
- }
148
- function resolveInheritedResponseFormat(agent, refs) {
149
- if (!refs) {
150
- return undefined;
151
- }
152
- const defaults = getRuntimeAgentDefaults(refs);
153
- if (defaults && "responseFormat" in defaults) {
154
- return defaults.responseFormat === null ? undefined : defaults.responseFormat;
155
- }
156
- const defaultRef = typeof defaults?.responseFormatRef === "string" ? defaults.responseFormatRef.trim() : "";
157
- return defaultRef ? resolveResponseFormatRef(refs, defaultRef) : undefined;
158
- }
159
- function resolveEffectiveResponseFormat(agent, refs) {
160
- const explicitResponseFormat = getAgentExecutionConfigValue(agent, "responseFormat");
161
- if (explicitResponseFormat !== undefined) {
162
- return explicitResponseFormat === null
163
- ? undefined
164
- : mergeResponseFormats(resolveInheritedResponseFormat(agent, refs), explicitResponseFormat);
165
- }
166
- const explicitRef = getAgentExecutionConfigValue(agent, "responseFormatRef");
167
- if (typeof explicitRef === "string" && explicitRef.trim().length > 0) {
168
- return resolveResponseFormatRef(refs, explicitRef.trim());
169
- }
170
- return resolveInheritedResponseFormat(agent, refs);
171
- }
172
- function validateResponseFormatTerminalStatus(agent, responseFormat, issues) {
173
- const schema = readObject(responseFormat);
174
- const properties = readObject(schema?.properties);
175
- const statusProperty = readObject(properties?.status);
176
- const required = Array.isArray(schema?.required) ? schema.required : [];
177
- if (!statusProperty || !required.includes("status")) {
178
- addIssue(issues, "agent.response_format.missing_terminal_status", `Agent ${agent.id} responseFormat must require a status field so parents can distinguish completed, blocked, failed, and refused terminal states.`);
179
- return;
180
- }
181
- const statusEnum = Array.isArray(statusProperty.enum) ? statusProperty.enum : [];
182
- if (!Array.from(TERMINAL_STATUS_VALUES).every((value) => statusEnum.includes(value))) {
183
- addIssue(issues, "agent.response_format.incomplete_terminal_status_enum", `Agent ${agent.id} responseFormat status enum must include completed, blocked, failed, and refused.`);
184
- }
185
- }
186
- function validateAgentContract(agent, referencedSubagentIds, tools, refs, issues) {
187
- const description = agent.description.trim();
188
- const systemPrompt = resolvePromptValue(getAgentExecutionConfigValue(agent, "systemPrompt"), path.dirname(agent.sourcePath));
189
- const ownsDelegation = agent.subagentRefs.length > 0 || agent.subagentPathRefs.length > 0 || (agent.asyncSubagents?.length ?? 0) > 0;
190
- const isSubagent = referencedSubagentIds.has(agent.id);
191
- const hasTools = agent.toolRefs.length > 0
192
- || (agent.toolBindings?.length ?? 0) > 0
193
- || (agent.inlineTools?.length ?? 0) > 0;
194
- const responseFormat = resolveEffectiveResponseFormat(agent, refs);
195
- const builtinTools = readBuiltinToolsConfig(agent);
196
- const executionContract = readExecutionContractConfig(agent);
197
- const localSubagentNames = [
198
- ...agent.subagentRefs.map(resolveRefId),
199
- ...(agent.asyncSubagents ?? []).map((subagent) => subagent.name),
200
- ];
201
- const isDeepAgentsGeneralPurposeSubagentOverride = agent.executionMode === "deepagent"
202
- && isSubagent
203
- && agent.id === UPSTREAM_GENERAL_PURPOSE_SUBAGENT_NAME;
204
- if (agent.id === UPSTREAM_GENERAL_PURPOSE_SUBAGENT_NAME && !isDeepAgentsGeneralPurposeSubagentOverride) {
205
- addIssue(issues, "agent.general_purpose.forbidden", `Agent ${agent.id} uses the upstream DeepAgents general-purpose subagent name outside a DeepAgents subagent override. Define a product agent with a narrow runtime boundary instead.`);
206
- }
207
- for (const asyncSubagent of agent.asyncSubagents ?? []) {
208
- if (asyncSubagent.name === UPSTREAM_GENERAL_PURPOSE_SUBAGENT_NAME) {
209
- addIssue(issues, "agent.general_purpose.forbidden", `Agent ${agent.id} defines async subagent ${asyncSubagent.name}. DeepAgents reserves that name for its inline general-purpose subagent surface.`);
210
- }
211
- }
212
- if (hasDuplicateValues(localSubagentNames)) {
213
- addIssue(issues, "agent.subagent.duplicate_name", `Agent ${agent.id} exposes duplicate subagent names. Each delegated capability must have one stable owner.`);
214
- }
215
- if (description.length < 24) {
216
- addIssue(issues, "agent.description.too_short", `Agent ${agent.id} should use a more specific description that explains when it should be used.`);
217
- }
218
- if (executionContract?.requiresPlan === true && builtinTools?.todos === false) {
219
- addIssue(issues, "agent.execution_contract.plan_without_todos", `Agent ${agent.id} requires plan evidence but disables todo tools. Enable todo tools or remove config.executionContract.requiresPlan.`);
220
- }
221
- const recoveryEvidenceToolName = readRecoveryEvidenceToolName(executionContract?.recoveryEvidenceTool);
222
- if (recoveryEvidenceToolName) {
223
- const toolNames = collectAgentToolNames(agent, tools, ownsDelegation);
224
- if (FRAMEWORK_EXECUTION_TOOL_NAMES.has(recoveryEvidenceToolName) || !toolNames.has(recoveryEvidenceToolName)) {
225
- addIssue(issues, "agent.execution_contract.invalid_recovery_evidence_tool", `Agent ${agent.id} config.executionContract.recoveryEvidenceTool must name one declared non-planning tool.`);
226
- }
227
- }
228
- if (ownsDelegation) {
229
- if (hasTools) {
230
- addIssue(issues, "agent.orchestrator.mixed_tool_surface", `Delegating agent ${agent.id} defines both subagents and direct tools. Keep routing agents focused on delegation, and move execution tools to specialist agents.`);
231
- }
232
- const modelExposedBuiltins = builtinTools?.modelExposed;
233
- const exposesOnlyTask = Array.isArray(modelExposedBuiltins)
234
- && modelExposedBuiltins.length === 1
235
- && modelExposedBuiltins[0] === "task";
236
- if (modelExposedBuiltins !== false && !exposesOnlyTask) {
237
- addIssue(issues, "agent.orchestrator.model_exposed_builtins", `Delegating agent ${agent.id} should expose only the task builtin or set config.builtinTools.modelExposed: false so raw built-in tools do not compete with specialist routing.`);
238
- }
239
- if (!systemPrompt?.trim()) {
240
- addIssue(issues, "agent.orchestrator.missing_prompt", `Delegating agent ${agent.id} should define a systemPrompt that explains decomposition, delegation, synthesis, and stop conditions.`);
241
- }
242
- }
243
- if (isSubagent) {
244
- if (!systemPrompt?.trim()) {
245
- addIssue(issues, "agent.subagent.missing_prompt", `Subagent ${agent.id} should define a systemPrompt that makes its operating boundary and output contract explicit.`);
246
- }
247
- if (agent.executionMode === "deepagent" && hasTools && responseFormat === undefined) {
248
- addIssue(issues, "agent.subagent.deepagent.missing_response_format", `DeepAgents subagent ${agent.id} exposes tools, so it should inherit or define a responseFormat to guarantee a stable task result for its parent agent.`);
249
- }
250
- if (agent.executionMode === "deepagent" && hasTools && responseFormat !== undefined) {
251
- validateResponseFormatTerminalStatus(agent, responseFormat, issues);
252
- }
253
- if (hasTools && agent.skillPathRefs.length === 0) {
254
- addIssue(issues, "agent.subagent.tools_without_skills", `Subagent ${agent.id} exposes execution tools but no skills. Add skills that describe tool-selection workflows and boundaries.`);
255
- }
256
- }
257
- const toolNames = collectAgentToolNames(agent, tools, ownsDelegation);
258
- for (const skillPath of agent.skillPathRefs) {
259
- const metadata = validateSkillMetadata(skillPath);
260
- for (const allowedTool of metadata.allowedTools ?? []) {
261
- if (!toolNames.has(allowedTool)) {
262
- addIssue(issues, "agent.skill.allowed_tool_unavailable", `Agent ${agent.id} attaches skill ${metadata.name}, but that skill allows tool ${allowedTool} which is not available to the agent.`);
263
- }
264
- }
265
- }
266
- }
267
- function validateSkillContract(skillRoot, issues) {
268
- const metadata = validateSkillMetadata(skillRoot);
269
- const skillName = metadata.name || path.basename(skillRoot);
270
- if (!metadata.description?.trim()) {
271
- addIssue(issues, "skill.description.missing", `Skill ${skillName} must define a frontmatter description so agents can compare its boundary without reading the whole document.`);
272
- }
273
- }
274
- function validateToolContract(tool, issues) {
275
- const description = tool.description.trim();
276
- if (description.length < 20) {
277
- addIssue(issues, "tool.description.too_short", `Tool ${tool.id} should use a more specific description that explains invocation boundaries and argument expectations.`);
278
- return;
279
- }
280
- }
281
- export function validateFrameworkContracts(input) {
282
- const mode = normalizeMode(input.mode);
283
- if (mode === "off") {
284
- return;
285
- }
286
- const issues = [];
287
- const referencedSubagentIds = new Set(input.agents.flatMap((agent) => agent.subagentRefs.map(resolveRefId)));
288
- for (const agent of input.agents) {
289
- if (!isWorkspaceOwnedPath(agent.sourcePath, input.ownedRoots)) {
290
- continue;
291
- }
292
- validateAgentContract(agent, referencedSubagentIds, input.tools, input.refs, issues);
293
- }
294
- for (const [skillName, skillRoot] of input.skillRegistry) {
295
- if (!isWorkspaceOwnedPath(skillRoot, input.ownedRoots)) {
296
- continue;
297
- }
298
- validateSkillContract(skillRoot, issues);
299
- if (!skillName.trim()) {
300
- addIssue(issues, "skill.name.empty", `Skill ${skillRoot} must define a stable name in frontmatter.`);
301
- }
302
- }
303
- for (const tool of input.tools.values()) {
304
- if (!isWorkspaceOwnedPath(tool.sourcePath, input.ownedRoots)) {
305
- continue;
306
- }
307
- validateToolContract(tool, issues);
308
- }
309
- if (issues.length === 0) {
310
- return;
311
- }
312
- const message = [
313
- "Framework contract validation failed.",
314
- "The workspace should follow the agent-harness contract-writing guidance for agents, skills, and tools.",
315
- ...issues.map((issue) => `- [${issue.code}] ${issue.message}`),
316
- ].join("\n");
317
- if (mode === "warn") {
318
- console.warn(`[agent-harness] ${message}`);
319
- return;
320
- }
321
- throw new Error(message);
322
- }
1
+ import c from"node:path";import{validateSkillMetadata as x}from"../runtime/skills/skill-metadata.js";import{getAgentExecutionConfigValue as f}from"./support/agent-execution-config.js";import{getRuntimeAgentDefaults as O,getWorkspaceObject as M,resolvePromptValue as j}from"./support/workspace-ref-utils.js";const y="general-purpose",D=new Set(["task"]),E=new Set(["write_todos","read_todos"]),q=new Set(["completed","blocked","failed","refused"]);function W(e){return e==="warn"||e==="error"?e:"off"}function te(e){if(e==="warn"||e==="error"||e==="off")return e;const t=process.env.AGENT_HARNESS_FRAMEWORK_CONTRACT_VALIDATION?.trim().toLowerCase();return t==="warn"||t==="error"||t==="off"?t:"off"}function I(e,t){const o=c.relative(c.resolve(t),c.resolve(e));return o===""||!o.startsWith("..")&&!c.isAbsolute(o)}function A(e,t){return t.some(o=>I(e,o))}function i(e,t,o){e.push({code:t,message:o})}function S(e,t){return e.startsWith(t)?e.slice(t.length):e}function d(e){return S(S(e,"agent/"),"tool/")}function L(e){const t=f(e,"builtinTools");return typeof t=="object"&&t&&!Array.isArray(t)?t:void 0}function V(e){const t=f(e,"executionContract");return typeof t=="object"&&t&&!Array.isArray(t)?t:void 0}function U(e){if(typeof e=="string")return e.trim();if(typeof e!="object"||e===null||Array.isArray(e))return"";const t=e.name;return typeof t=="string"?t.trim():""}function T(e,t,o){const r=new Set(E);if(o)for(const n of D)r.add(n);for(const n of e.toolRefs){const s=t.get(d(n));s&&(r.add(s.id),r.add(s.name)),r.add(d(n))}for(const n of e.toolBindings??[]){const s=t.get(d(n.ref));s&&(r.add(s.id),r.add(s.name)),r.add(d(n.ref))}for(const n of e.inlineTools??[])r.add(n.id),r.add(n.name);return r}function B(e){return new Set(e).size!==e.length}function _(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:void 0}function G(e){return e.startsWith("response-format/")?e:`response-format/${e}`}function v(e,t){if(!e||!t)return;const o=M(e,G(t));if(!(!o||o.kind!=="response-format"))return o.value.format}function $(e,t){if(t===void 0)return e;if(typeof e=="object"&&e&&typeof t=="object"&&t&&!Array.isArray(e)&&!Array.isArray(t)){const o={...e};for(const[r,n]of Object.entries(t)){if(r==="required"&&Array.isArray(o.required)&&Array.isArray(n)){o.required=Array.from(new Set([...o.required,...n]));continue}if(r==="properties"&&typeof o.properties=="object"&&o.properties&&!Array.isArray(o.properties)&&typeof n=="object"&&n&&!Array.isArray(n)){o.properties={...o.properties,...n};continue}o[r]=r in o?$(o[r],n):n}return o}return t}function F(e,t){if(!t)return;const o=O(t);if(o&&"responseFormat"in o)return o.responseFormat===null?void 0:o.responseFormat;const r=typeof o?.responseFormatRef=="string"?o.responseFormatRef.trim():"";return r?v(t,r):void 0}function K(e,t){const o=f(e,"responseFormat");if(o!==void 0)return o===null?void 0:$(F(e,t),o);const r=f(e,"responseFormatRef");return typeof r=="string"&&r.trim().length>0?v(t,r.trim()):F(e,t)}function z(e,t,o){const r=_(t),n=_(r?.properties),s=_(n?.status),l=Array.isArray(r?.required)?r.required:[];if(!s||!l.includes("status")){i(o,"agent.response_format.missing_terminal_status",`Agent ${e.id} responseFormat must require a status field so parents can distinguish completed, blocked, failed, and refused terminal states.`);return}const u=Array.isArray(s.enum)?s.enum:[];Array.from(q).every(m=>u.includes(m))||i(o,"agent.response_format.incomplete_terminal_status_enum",`Agent ${e.id} responseFormat status enum must include completed, blocked, failed, and refused.`)}function H(e,t,o,r,n){const s=e.description.trim(),l=j(f(e,"systemPrompt"),c.dirname(e.sourcePath)),u=e.subagentRefs.length>0||e.subagentPathRefs.length>0||(e.asyncSubagents?.length??0)>0,m=t.has(e.id),p=e.toolRefs.length>0||(e.toolBindings?.length??0)>0||(e.inlineTools?.length??0)>0,h=K(e,r),w=L(e),R=V(e),P=[...e.subagentRefs.map(d),...(e.asyncSubagents??[]).map(a=>a.name)],N=e.executionMode==="deepagent"&&m&&e.id===y;e.id===y&&!N&&i(n,"agent.general_purpose.forbidden",`Agent ${e.id} uses the upstream DeepAgents general-purpose subagent name outside a DeepAgents subagent override. Define a product agent with a narrow runtime boundary instead.`);for(const a of e.asyncSubagents??[])a.name===y&&i(n,"agent.general_purpose.forbidden",`Agent ${e.id} defines async subagent ${a.name}. DeepAgents reserves that name for its inline general-purpose subagent surface.`);B(P)&&i(n,"agent.subagent.duplicate_name",`Agent ${e.id} exposes duplicate subagent names. Each delegated capability must have one stable owner.`),s.length<24&&i(n,"agent.description.too_short",`Agent ${e.id} should use a more specific description that explains when it should be used.`),R?.requiresPlan===!0&&w?.todos===!1&&i(n,"agent.execution_contract.plan_without_todos",`Agent ${e.id} requires plan evidence but disables todo tools. Enable todo tools or remove config.executionContract.requiresPlan.`);const b=U(R?.recoveryEvidenceTool);if(b){const a=T(e,o,u);(E.has(b)||!a.has(b))&&i(n,"agent.execution_contract.invalid_recovery_evidence_tool",`Agent ${e.id} config.executionContract.recoveryEvidenceTool must name one declared non-planning tool.`)}if(u){p&&i(n,"agent.orchestrator.mixed_tool_surface",`Delegating agent ${e.id} defines both subagents and direct tools. Keep routing agents focused on delegation, and move execution tools to specialist agents.`);const a=w?.modelExposed,g=Array.isArray(a)&&a.length===1&&a[0]==="task";a!==!1&&!g&&i(n,"agent.orchestrator.model_exposed_builtins",`Delegating agent ${e.id} should expose only the task builtin or set config.builtinTools.modelExposed: false so raw built-in tools do not compete with specialist routing.`),l?.trim()||i(n,"agent.orchestrator.missing_prompt",`Delegating agent ${e.id} should define a systemPrompt that explains decomposition, delegation, synthesis, and stop conditions.`)}m&&(l?.trim()||i(n,"agent.subagent.missing_prompt",`Subagent ${e.id} should define a systemPrompt that makes its operating boundary and output contract explicit.`),e.executionMode==="deepagent"&&p&&h===void 0&&i(n,"agent.subagent.deepagent.missing_response_format",`DeepAgents subagent ${e.id} exposes tools, so it should inherit or define a responseFormat to guarantee a stable task result for its parent agent.`),e.executionMode==="deepagent"&&p&&h!==void 0&&z(e,h,n),p&&e.skillPathRefs.length===0&&i(n,"agent.subagent.tools_without_skills",`Subagent ${e.id} exposes execution tools but no skills. Add skills that describe tool-selection workflows and boundaries.`));const C=T(e,o,u);for(const a of e.skillPathRefs){const g=x(a);for(const k of g.allowedTools??[])C.has(k)||i(n,"agent.skill.allowed_tool_unavailable",`Agent ${e.id} attaches skill ${g.name}, but that skill allows tool ${k} which is not available to the agent.`)}}function X(e,t){const o=x(e),r=o.name||c.basename(e);o.description?.trim()||i(t,"skill.description.missing",`Skill ${r} must define a frontmatter description so agents can compare its boundary without reading the whole document.`)}function J(e,t){if(e.description.trim().length<20){i(t,"tool.description.too_short",`Tool ${e.id} should use a more specific description that explains invocation boundaries and argument expectations.`);return}}function oe(e){const t=W(e.mode);if(t==="off")return;const o=[],r=new Set(e.agents.flatMap(s=>s.subagentRefs.map(d)));for(const s of e.agents)A(s.sourcePath,e.ownedRoots)&&H(s,r,e.tools,e.refs,o);for(const[s,l]of e.skillRegistry)A(l,e.ownedRoots)&&(X(l,o),s.trim()||i(o,"skill.name.empty",`Skill ${l} must define a stable name in frontmatter.`));for(const s of e.tools.values())A(s.sourcePath,e.ownedRoots)&&J(s,o);if(o.length===0)return;const n=["Framework contract validation failed.","The workspace should follow the agent-harness contract-writing guidance for agents, skills, and tools.",...o.map(s=>`- [${s.code}] ${s.message}`)].join(`
2
+ `);if(t==="warn"){console.warn(`[agent-harness] ${n}`);return}throw new Error(n)}export{te as resolveFrameworkContractValidationMode,oe as validateFrameworkContracts};
@@ -1 +1 @@
1
- export { loadWorkspace } from "./compile.js";
1
+ import{loadWorkspace as a}from"./compile.js";export{a as loadWorkspace};
@@ -1,71 +1 @@
1
- import path from "node:path";
2
- import { existsSync, statSync } from "node:fs";
3
- import { fileURLToPath } from "node:url";
4
- import { isExternalSourceLocator, resolveResourcePackageRoot } from "../resource/sources.js";
5
- export const CONVENTIONAL_OBJECT_DIRECTORIES = ["tools"];
6
- export const MODULE_AGENT_FILENAMES = ["agent.yaml", "agent.yml"];
7
- export const MODULE_TOOL_FILENAMES = ["tool.yaml", "tool.yml"];
8
- export const MODULE_TOOL_ENTRY_FILENAMES = ["index.mjs", "index.js", "index.cjs"];
9
- export function moduleCollectionRoot(root, kind) {
10
- return path.join(root, "modules", kind);
11
- }
12
- function isModuleDefinitionPath(sourcePath, kind) {
13
- const normalized = sourcePath.split(path.sep).join("/");
14
- const suffix = kind === "agents" ? "/agent.yaml" : "/tool.yaml";
15
- const altSuffix = kind === "agents" ? "/agent.yml" : "/tool.yml";
16
- return normalized.includes(`/modules/${kind}/`) && (normalized.endsWith(suffix) || normalized.endsWith(altSuffix));
17
- }
18
- export function moduleRootForSourcePath(sourcePath, kind) {
19
- if (!isModuleDefinitionPath(sourcePath, kind)) {
20
- return undefined;
21
- }
22
- return path.dirname(sourcePath);
23
- }
24
- export function conventionalConfigRoot(root) {
25
- if (path.basename(root) === "config" && existsSync(root) && statSync(root).isDirectory()) {
26
- return root;
27
- }
28
- const candidate = path.join(root, "config");
29
- if (existsSync(candidate) && statSync(candidate).isDirectory()) {
30
- return candidate;
31
- }
32
- return null;
33
- }
34
- function conventionalDirectoryRoots(root, relativeDir) {
35
- const resourceRoot = resolveResourcePackageRoot(root);
36
- const candidates = [
37
- ...(resourceRoot ? [path.join(resourceRoot, relativeDir)] : []),
38
- path.join(root, relativeDir),
39
- ];
40
- return Array.from(new Set(candidates));
41
- }
42
- export function conventionalPackageRoots(root, relativeDir) {
43
- const resourceRoot = resolveResourcePackageRoot(root);
44
- const candidates = resourceRoot ? [path.join(resourceRoot, relativeDir), resourceRoot] : [];
45
- return Array.from(new Set(candidates));
46
- }
47
- export function conventionalObjectRoots(root) {
48
- return CONVENTIONAL_OBJECT_DIRECTORIES.flatMap((directory) => conventionalDirectoryRoots(root, directory));
49
- }
50
- export function resolveFrameworkWorkspaceRoot(resolved) {
51
- const baseName = path.basename(resolved);
52
- if (baseName === "dist") {
53
- return resolved;
54
- }
55
- if (baseName === "src") {
56
- return path.dirname(resolved);
57
- }
58
- return resolved;
59
- }
60
- export function frameworkWorkspaceRoot() {
61
- return resolveFrameworkWorkspaceRoot(fileURLToPath(new URL("..", import.meta.url)));
62
- }
63
- function isModuleRelativePathCandidate(value) {
64
- return !path.isAbsolute(value) && !isExternalSourceLocator(value) && !value.includes("://");
65
- }
66
- export function resolveModuleRelativePath(value, moduleRoot) {
67
- if (!moduleRoot || !isModuleRelativePathCandidate(value)) {
68
- return value;
69
- }
70
- return path.resolve(moduleRoot, value);
71
- }
1
+ import n from"node:path";import{existsSync as i,statSync as c}from"node:fs";import{fileURLToPath as u}from"node:url";import{isExternalSourceLocator as f,resolveResourcePackageRoot as s}from"../resource/sources.js";const l=["tools"],O=["agent.yaml","agent.yml"],g=["tool.yaml","tool.yml"],S=["index.mjs","index.js","index.cjs"];function j(o,t){return n.join(o,"modules",t)}function m(o,t){const e=o.split(n.sep).join("/"),r=t==="agents"?"/agent.yaml":"/tool.yaml",a=t==="agents"?"/agent.yml":"/tool.yml";return e.includes(`/modules/${t}/`)&&(e.endsWith(r)||e.endsWith(a))}function M(o,t){if(m(o,t))return n.dirname(o)}function N(o){if(n.basename(o)==="config"&&i(o)&&c(o).isDirectory())return o;const t=n.join(o,"config");return i(t)&&c(t).isDirectory()?t:null}function p(o,t){const e=s(o),r=[...e?[n.join(e,t)]:[],n.join(o,t)];return Array.from(new Set(r))}function _(o,t){const e=s(o),r=e?[n.join(e,t),e]:[];return Array.from(new Set(r))}function A(o){return l.flatMap(t=>p(o,t))}function d(o){const t=n.basename(o);return t==="dist"?o:t==="src"?n.dirname(o):o}function T(){return d(u(new URL("..",import.meta.url)))}function x(o){return!n.isAbsolute(o)&&!f(o)&&!o.includes("://")}function h(o,t){return!t||!x(o)?o:n.resolve(t,o)}export{l as CONVENTIONAL_OBJECT_DIRECTORIES,O as MODULE_AGENT_FILENAMES,S as MODULE_TOOL_ENTRY_FILENAMES,g as MODULE_TOOL_FILENAMES,N as conventionalConfigRoot,A as conventionalObjectRoots,_ as conventionalPackageRoots,T as frameworkWorkspaceRoot,j as moduleCollectionRoot,M as moduleRootForSourcePath,d as resolveFrameworkWorkspaceRoot,h as resolveModuleRelativePath};
@@ -1,187 +1 @@
1
- export function toArray(value) {
2
- return Array.isArray(value) ? value : [];
3
- }
4
- export function asObject(value) {
5
- return typeof value === "object" && value ? value : undefined;
6
- }
7
- export function asMutableObject(value) {
8
- return typeof value === "object" && value !== null && !Array.isArray(value)
9
- ? { ...value }
10
- : undefined;
11
- }
12
- export function cloneConfigValue(value) {
13
- if (Array.isArray(value)) {
14
- return value.map((item) => cloneConfigValue(item));
15
- }
16
- if (typeof value === "object" && value !== null) {
17
- return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneConfigValue(entry)]));
18
- }
19
- return value;
20
- }
21
- export function readRefArray(items) {
22
- return toArray(items)
23
- .map((item) => typeof item === "string"
24
- ? item
25
- : typeof item === "object" && item && "ref" in item
26
- ? item.ref
27
- : undefined)
28
- .filter((item) => Boolean(item));
29
- }
30
- export function readStringRecord(value) {
31
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
32
- return undefined;
33
- }
34
- const entries = Object.entries(value)
35
- .filter((entry) => typeof entry[1] === "string");
36
- return entries.length > 0 ? Object.fromEntries(entries) : undefined;
37
- }
38
- export function readAsyncSubAgentArray(items) {
39
- return toArray(items)
40
- .flatMap((item) => {
41
- if (typeof item !== "object" || item === null || Array.isArray(item)) {
42
- return [];
43
- }
44
- const typed = item;
45
- const name = typeof typed.name === "string" ? typed.name.trim() : "";
46
- const description = typeof typed.description === "string" ? typed.description.trim() : "";
47
- const graphId = typeof typed.graphId === "string" ? typed.graphId.trim() : "";
48
- if (!name || !description || !graphId) {
49
- return [];
50
- }
51
- const headers = readStringRecord(typed.headers);
52
- return [{
53
- name,
54
- description,
55
- graphId,
56
- ...(typeof typed.url === "string" && typed.url.trim().length > 0 ? { url: typed.url.trim() } : {}),
57
- ...(headers ? { headers } : {}),
58
- }];
59
- });
60
- }
61
- export function readPrefixedRefArray(items, prefix) {
62
- return toArray(items)
63
- .map((item) => {
64
- if (typeof item === "string") {
65
- const value = item.trim();
66
- if (!value) {
67
- return undefined;
68
- }
69
- return value.startsWith(`${prefix}/`) ? value : `${prefix}/${value}`;
70
- }
71
- if (typeof item === "object" && item && "ref" in item && typeof item.ref === "string") {
72
- const value = String(item.ref).trim();
73
- return value || undefined;
74
- }
75
- return undefined;
76
- })
77
- .filter((item) => Boolean(item));
78
- }
79
- export function normalizeToolUsageOverrides(value) {
80
- const record = asMutableObject(value);
81
- if (!record) {
82
- return undefined;
83
- }
84
- const directKeys = new Set(["config", "hitl", "retryable", "subprocess", "embeddingModel", "embeddingModelRef"]);
85
- const directOverrides = {};
86
- const configOverrides = {};
87
- for (const [key, entry] of Object.entries(record)) {
88
- if (directKeys.has(key)) {
89
- directOverrides[key] = cloneConfigValue(entry);
90
- continue;
91
- }
92
- configOverrides[key] = cloneConfigValue(entry);
93
- }
94
- return {
95
- ...directOverrides,
96
- ...(Object.keys(configOverrides).length > 0
97
- ? {
98
- config: {
99
- ...(asMutableObject(directOverrides.config) ?? {}),
100
- ...configOverrides,
101
- },
102
- }
103
- : {}),
104
- };
105
- }
106
- export function readToolBindingArray(items) {
107
- return toArray(items)
108
- .map((item) => {
109
- if (typeof item === "string") {
110
- return { ref: item };
111
- }
112
- if (typeof item !== "object" || !item || Array.isArray(item)) {
113
- return undefined;
114
- }
115
- const entries = Object.entries(item);
116
- if (entries.length !== 1 || typeof entries[0]?.[0] !== "string") {
117
- throw new Error("Agent tools entries must be either a tool name string or a single-key override object");
118
- }
119
- const [ref, rawOverride] = entries[0];
120
- const overrides = normalizeToolUsageOverrides(rawOverride);
121
- return {
122
- ref,
123
- ...(overrides ? { overrides } : {}),
124
- };
125
- })
126
- .filter((item) => Boolean(item));
127
- }
128
- export function readPathArray(items) {
129
- return toArray(items)
130
- .map((item) => typeof item === "string"
131
- ? item
132
- : typeof item === "object" && item && "path" in item && typeof item.path === "string"
133
- ? item.path
134
- : undefined)
135
- .filter((item) => Boolean(item));
136
- }
137
- export function readStringArray(items) {
138
- return toArray(items)
139
- .filter((item) => typeof item === "string" && item.trim().length > 0)
140
- .map((item) => item.trim());
141
- }
142
- export function readSingleRef(value) {
143
- if (typeof value === "string" && value.trim()) {
144
- return value;
145
- }
146
- if (typeof value === "object" && value && "ref" in value && typeof value.ref === "string") {
147
- return value.ref;
148
- }
149
- return undefined;
150
- }
151
- export function readMiddlewareArray(items) {
152
- const middleware = toArray(items)
153
- .filter((item) => typeof item === "object" && item !== null && !Array.isArray(item))
154
- .map((item) => ({ ...item }));
155
- return middleware.length > 0 ? middleware : undefined;
156
- }
157
- export function readObjectArray(items) {
158
- const records = toArray(items)
159
- .filter((item) => typeof item === "object" && item !== null && !Array.isArray(item))
160
- .map((item) => ({ ...item }));
161
- return records.length > 0 ? records : undefined;
162
- }
163
- export function readMcpServerArray(items) {
164
- const records = toArray(items)
165
- .map((item) => {
166
- if (typeof item === "string" && item.trim()) {
167
- return { ref: item.startsWith("mcp/") ? item : `mcp/${item.trim()}` };
168
- }
169
- if (typeof item === "object" && item !== null && !Array.isArray(item)) {
170
- return { ...item };
171
- }
172
- return undefined;
173
- })
174
- .filter((item) => Boolean(item));
175
- return records.length > 0 ? records : undefined;
176
- }
177
- export function readCapabilities(value) {
178
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
179
- return undefined;
180
- }
181
- const typed = value;
182
- const capabilities = {
183
- ...(typeof typed.delegation === "boolean" ? { delegation: typed.delegation } : {}),
184
- ...(typeof typed.memory === "boolean" ? { memory: typed.memory } : {}),
185
- };
186
- return Object.keys(capabilities).length > 0 ? capabilities : undefined;
187
- }
1
+ function i(e){return Array.isArray(e)?e:[]}function y(e){return typeof e=="object"&&e?e:void 0}function d(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?{...e}:void 0}function c(e){return Array.isArray(e)?e.map(r=>c(r)):typeof e=="object"&&e!==null?Object.fromEntries(Object.entries(e).map(([r,n])=>[r,c(n)])):e}function u(e){return i(e).map(r=>typeof r=="string"?r:typeof r=="object"&&r&&"ref"in r?r.ref:void 0).filter(r=>!!r)}function p(e){if(typeof e!="object"||e===null||Array.isArray(e))return;const r=Object.entries(e).filter(n=>typeof n[1]=="string");return r.length>0?Object.fromEntries(r):void 0}function g(e){return i(e).flatMap(r=>{if(typeof r!="object"||r===null||Array.isArray(r))return[];const n=r,t=typeof n.name=="string"?n.name.trim():"",f=typeof n.description=="string"?n.description.trim():"",o=typeof n.graphId=="string"?n.graphId.trim():"";if(!t||!f||!o)return[];const s=p(n.headers);return[{name:t,description:f,graphId:o,...typeof n.url=="string"&&n.url.trim().length>0?{url:n.url.trim()}:{},...s?{headers:s}:{}}]})}function l(e,r){return i(e).map(n=>{if(typeof n=="string"){const t=n.trim();return t?t.startsWith(`${r}/`)?t:`${r}/${t}`:void 0}if(typeof n=="object"&&n&&"ref"in n&&typeof n.ref=="string")return String(n.ref).trim()||void 0}).filter(n=>!!n)}function a(e){const r=d(e);if(!r)return;const n=new Set(["config","hitl","retryable","subprocess","embeddingModel","embeddingModelRef"]),t={},f={};for(const[o,s]of Object.entries(r)){if(n.has(o)){t[o]=c(s);continue}f[o]=c(s)}return{...t,...Object.keys(f).length>0?{config:{...d(t.config)??{},...f}}:{}}}function b(e){return i(e).map(r=>{if(typeof r=="string")return{ref:r};if(typeof r!="object"||!r||Array.isArray(r))return;const n=Object.entries(r);if(n.length!==1||typeof n[0]?.[0]!="string")throw new Error("Agent tools entries must be either a tool name string or a single-key override object");const[t,f]=n[0],o=a(f);return{ref:t,...o?{overrides:o}:{}}}).filter(r=>!!r)}function A(e){return i(e).map(r=>typeof r=="string"?r:typeof r=="object"&&r&&"path"in r&&typeof r.path=="string"?r.path:void 0).filter(r=>!!r)}function j(e){return i(e).filter(r=>typeof r=="string"&&r.trim().length>0).map(r=>r.trim())}function h(e){if(typeof e=="string"&&e.trim())return e;if(typeof e=="object"&&e&&"ref"in e&&typeof e.ref=="string")return e.ref}function x(e){const r=i(e).filter(n=>typeof n=="object"&&n!==null&&!Array.isArray(n)).map(n=>({...n}));return r.length>0?r:void 0}function O(e){const r=i(e).filter(n=>typeof n=="object"&&n!==null&&!Array.isArray(n)).map(n=>({...n}));return r.length>0?r:void 0}function S(e){const r=i(e).map(n=>{if(typeof n=="string"&&n.trim())return{ref:n.startsWith("mcp/")?n:`mcp/${n.trim()}`};if(typeof n=="object"&&n!==null&&!Array.isArray(n))return{...n}}).filter(n=>!!n);return r.length>0?r:void 0}function w(e){if(typeof e!="object"||e===null||Array.isArray(e))return;const r=e,n={...typeof r.delegation=="boolean"?{delegation:r.delegation}:{},...typeof r.memory=="boolean"?{memory:r.memory}:{}};return Object.keys(n).length>0?n:void 0}export{d as asMutableObject,y as asObject,c as cloneConfigValue,a as normalizeToolUsageOverrides,g as readAsyncSubAgentArray,w as readCapabilities,S as readMcpServerArray,x as readMiddlewareArray,O as readObjectArray,A as readPathArray,l as readPrefixedRefArray,u as readRefArray,h as readSingleRef,j as readStringArray,p as readStringRecord,b as readToolBindingArray,i as toArray};