@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.
- package/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,280 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { listRemoteMcpTools } from "../resource/resource-impl.js";
|
|
4
|
-
import { ensureExternalResourceSource, isExternalSourceLocator } from "../resource/sources.js";
|
|
5
|
-
import { listResourceTools, listResourceToolsForSource } from "../resource/resource.js";
|
|
6
|
-
import { readToolModuleItems } from "./object-loader.js";
|
|
7
|
-
import { parseMcpServerObject, parseToolObject } from "./resource-compilers.js";
|
|
8
|
-
function toMcpServerConfig(server) {
|
|
9
|
-
return {
|
|
10
|
-
transport: server.transport,
|
|
11
|
-
command: server.command,
|
|
12
|
-
args: server.args,
|
|
13
|
-
env: server.env,
|
|
14
|
-
cwd: server.cwd,
|
|
15
|
-
url: server.url,
|
|
16
|
-
token: server.token,
|
|
17
|
-
headers: server.headers,
|
|
18
|
-
trustTier: server.trustTier,
|
|
19
|
-
access: server.access,
|
|
20
|
-
tenantScope: server.tenantScope,
|
|
21
|
-
approvalPolicy: server.approvalPolicy,
|
|
22
|
-
promptInjectionRisk: server.promptInjectionRisk,
|
|
23
|
-
oauth: server.oauth,
|
|
24
|
-
labels: server.labels,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function readStringArray(value) {
|
|
28
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.trim().length > 0) : [];
|
|
29
|
-
}
|
|
30
|
-
function readStringRecord(value) {
|
|
31
|
-
if (typeof value !== "object" || !value || Array.isArray(value)) {
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
const entries = Object.entries(value).filter((entry) => typeof entry[1] === "string");
|
|
35
|
-
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
36
|
-
}
|
|
37
|
-
function asObject(value) {
|
|
38
|
-
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
39
|
-
? value
|
|
40
|
-
: undefined;
|
|
41
|
-
}
|
|
42
|
-
function compileRegexList(value, label) {
|
|
43
|
-
return readStringArray(value).map((pattern) => {
|
|
44
|
-
try {
|
|
45
|
-
return new RegExp(pattern);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
throw new Error(`${label} contains invalid regex ${JSON.stringify(pattern)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function compileMcpToolFilter(serverItem) {
|
|
53
|
-
return {
|
|
54
|
-
includeNames: new Set(readStringArray(serverItem.tools)),
|
|
55
|
-
excludeNames: new Set(readStringArray(serverItem.excludeTools)),
|
|
56
|
-
includePatterns: compileRegexList(serverItem.toolFilters ?? serverItem.toolFilter, "toolFilter"),
|
|
57
|
-
excludePatterns: compileRegexList(serverItem.excludeToolFilters ?? serverItem.excludeToolFilter, "excludeToolFilter"),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function shouldIncludeRemoteMcpTool(filter, toolName) {
|
|
61
|
-
const { includeNames, excludeNames, includePatterns, excludePatterns } = filter;
|
|
62
|
-
const includedByName = includeNames.size === 0 || includeNames.has(toolName);
|
|
63
|
-
const includedByPattern = includePatterns.length === 0 || includePatterns.some((pattern) => pattern.test(toolName));
|
|
64
|
-
if (!includedByName || !includedByPattern) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if (excludeNames.has(toolName)) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
if (excludePatterns.some((pattern) => pattern.test(toolName))) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
function canResolveMcpToolsFromExplicitNamesOnly(filter) {
|
|
76
|
-
return filter.includeNames.size > 0 && filter.includePatterns.length === 0;
|
|
77
|
-
}
|
|
78
|
-
function normalizeAgentMcpServerUsage(item) {
|
|
79
|
-
const config = asObject(item.config);
|
|
80
|
-
if (!config) {
|
|
81
|
-
return item;
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
...config,
|
|
85
|
-
...item,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function hasMcpServerUsageOverrides(item) {
|
|
89
|
-
return [
|
|
90
|
-
"transport",
|
|
91
|
-
"command",
|
|
92
|
-
"args",
|
|
93
|
-
"env",
|
|
94
|
-
"cwd",
|
|
95
|
-
"url",
|
|
96
|
-
"token",
|
|
97
|
-
"headers",
|
|
98
|
-
].some((key) => item[key] !== undefined);
|
|
99
|
-
}
|
|
100
|
-
function mergeReferencedMcpServer(referencedServer, item, agentId, name, sourcePath) {
|
|
101
|
-
return {
|
|
102
|
-
id: `${agentId}.${name}`,
|
|
103
|
-
transport: item.transport === "stdio" || item.transport === "http" || item.transport === "sse" || item.transport === "websocket"
|
|
104
|
-
? item.transport
|
|
105
|
-
: referencedServer.transport,
|
|
106
|
-
url: typeof item.url === "string" ? item.url : referencedServer.url,
|
|
107
|
-
command: typeof item.command === "string" ? item.command : referencedServer.command,
|
|
108
|
-
args: Array.isArray(item.args)
|
|
109
|
-
? item.args.filter((entry) => typeof entry === "string")
|
|
110
|
-
: referencedServer.args,
|
|
111
|
-
env: {
|
|
112
|
-
...(referencedServer.env ?? {}),
|
|
113
|
-
...(readStringRecord(item.env) ?? {}),
|
|
114
|
-
},
|
|
115
|
-
cwd: typeof item.cwd === "string" ? item.cwd : referencedServer.cwd,
|
|
116
|
-
token: typeof item.token === "string" ? item.token : referencedServer.token,
|
|
117
|
-
headers: {
|
|
118
|
-
...(referencedServer.headers ?? {}),
|
|
119
|
-
...(readStringRecord(item.headers) ?? {}),
|
|
120
|
-
},
|
|
121
|
-
trustTier: item.trustTier === "trusted" || item.trustTier === "reviewed" || item.trustTier === "untrusted"
|
|
122
|
-
? item.trustTier
|
|
123
|
-
: referencedServer.trustTier,
|
|
124
|
-
access: item.access === "read-only" || item.access === "read-write" ? item.access : referencedServer.access,
|
|
125
|
-
tenantScope: item.tenantScope === "workspace" ||
|
|
126
|
-
item.tenantScope === "project" ||
|
|
127
|
-
item.tenantScope === "tenant" ||
|
|
128
|
-
item.tenantScope === "cross-tenant"
|
|
129
|
-
? item.tenantScope
|
|
130
|
-
: referencedServer.tenantScope,
|
|
131
|
-
approvalPolicy: item.approvalPolicy === "always" || item.approvalPolicy === "write" || item.approvalPolicy === "never"
|
|
132
|
-
? item.approvalPolicy
|
|
133
|
-
: referencedServer.approvalPolicy,
|
|
134
|
-
promptInjectionRisk: item.promptInjectionRisk === "low" || item.promptInjectionRisk === "medium" || item.promptInjectionRisk === "high"
|
|
135
|
-
? item.promptInjectionRisk
|
|
136
|
-
: referencedServer.promptInjectionRisk,
|
|
137
|
-
oauth: asObject(item.oauth)
|
|
138
|
-
? {
|
|
139
|
-
provider: typeof asObject(item.oauth)?.provider === "string" ? asObject(item.oauth)?.provider : referencedServer.oauth?.provider,
|
|
140
|
-
scopes: readStringArray(asObject(item.oauth)?.scopes) || referencedServer.oauth?.scopes,
|
|
141
|
-
}
|
|
142
|
-
: referencedServer.oauth,
|
|
143
|
-
labels: readStringArray(item.labels).length > 0 ? readStringArray(item.labels) : referencedServer.labels,
|
|
144
|
-
sourcePath,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
async function hydrateExternalToolSource(tools, source, workspaceRoot, toolModuleDiscoveryScope) {
|
|
148
|
-
const externalRoot = await ensureExternalResourceSource(source, workspaceRoot);
|
|
149
|
-
const discoveredToolRefs = [];
|
|
150
|
-
const sourcePrefix = `external.${createHash("sha256").update(source).digest("hex").slice(0, 12)}`;
|
|
151
|
-
for (const { item, sourcePath } of await readToolModuleItems(path.join(externalRoot, "tools"), { scope: toolModuleDiscoveryScope })) {
|
|
152
|
-
const toolId = typeof item.id === "string" ? item.id : undefined;
|
|
153
|
-
if (!toolId) {
|
|
154
|
-
continue;
|
|
155
|
-
}
|
|
156
|
-
const namespacedId = `${sourcePrefix}.${toolId}`;
|
|
157
|
-
const parsed = parseToolObject({
|
|
158
|
-
id: namespacedId,
|
|
159
|
-
kind: "tool",
|
|
160
|
-
sourcePath,
|
|
161
|
-
value: {
|
|
162
|
-
...item,
|
|
163
|
-
id: namespacedId,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
tools.set(parsed.id, parsed);
|
|
167
|
-
discoveredToolRefs.push(`tool/${parsed.id}`);
|
|
168
|
-
}
|
|
169
|
-
const sourceTools = await listResourceToolsForSource(source, workspaceRoot);
|
|
170
|
-
const bundleRefs = [...sourceTools.map((tool) => tool.toolPath), ...discoveredToolRefs];
|
|
171
|
-
if (bundleRefs.length > 0) {
|
|
172
|
-
tools.set(source, {
|
|
173
|
-
id: source,
|
|
174
|
-
type: "bundle",
|
|
175
|
-
name: source,
|
|
176
|
-
description: `External tool resource loaded from ${source}`,
|
|
177
|
-
bundleRefs,
|
|
178
|
-
sourcePath: source,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
export async function hydrateResourceAndExternalTools(tools, toolSourceRefs, workspaceRoot, toolModuleDiscoveryScope = "recursive") {
|
|
183
|
-
for (const source of toolSourceRefs) {
|
|
184
|
-
if (isExternalSourceLocator(source)) {
|
|
185
|
-
await hydrateExternalToolSource(tools, source, workspaceRoot, toolModuleDiscoveryScope);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
for (const resourceTool of await listResourceTools(toolSourceRefs, workspaceRoot)) {
|
|
189
|
-
const existing = tools.get(resourceTool.toolPath);
|
|
190
|
-
tools.set(resourceTool.toolPath, {
|
|
191
|
-
id: resourceTool.toolPath,
|
|
192
|
-
type: existing?.type ?? "backend",
|
|
193
|
-
name: existing?.name || resourceTool.name,
|
|
194
|
-
description: existing?.description || resourceTool.description,
|
|
195
|
-
config: existing?.config,
|
|
196
|
-
embeddingModelRef: existing?.embeddingModelRef,
|
|
197
|
-
backendOperation: existing?.backendOperation ?? resourceTool.backendOperation,
|
|
198
|
-
bundleRefs: existing?.bundleRefs ?? [],
|
|
199
|
-
hitl: existing?.hitl ?? resourceTool.hitl,
|
|
200
|
-
retryable: existing?.retryable ?? resourceTool.retryable,
|
|
201
|
-
sourcePath: resourceTool.toolPath,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
export async function hydrateAgentMcpTools(agents, mcpServers, tools) {
|
|
206
|
-
for (const agent of agents) {
|
|
207
|
-
const discoveredRefs = new Set(agent.toolRefs);
|
|
208
|
-
for (const rawItem of agent.mcpServers ?? []) {
|
|
209
|
-
const item = normalizeAgentMcpServerUsage(rawItem);
|
|
210
|
-
const serverRef = typeof item.ref === "string" ? item.ref.trim() : "";
|
|
211
|
-
const referencedServerId = serverRef.startsWith("mcp/") ? serverRef.slice(4) : serverRef;
|
|
212
|
-
const referencedServer = referencedServerId ? mcpServers.get(referencedServerId) : undefined;
|
|
213
|
-
const name = typeof item.name === "string" && item.name.trim()
|
|
214
|
-
? item.name.trim()
|
|
215
|
-
: referencedServer?.id
|
|
216
|
-
? referencedServer.id
|
|
217
|
-
: typeof item.id === "string" && item.id.trim()
|
|
218
|
-
? item.id.trim()
|
|
219
|
-
: "";
|
|
220
|
-
if (!name) {
|
|
221
|
-
throw new Error(`Agent ${agent.id} has an MCP server entry without a name`);
|
|
222
|
-
}
|
|
223
|
-
let serverId = referencedServer?.id;
|
|
224
|
-
let parsedServer = referencedServer;
|
|
225
|
-
if (!parsedServer) {
|
|
226
|
-
serverId = `${agent.id}.${name}`;
|
|
227
|
-
parsedServer = parseMcpServerObject({
|
|
228
|
-
id: serverId,
|
|
229
|
-
kind: "mcp",
|
|
230
|
-
sourcePath: agent.sourcePath,
|
|
231
|
-
value: item,
|
|
232
|
-
});
|
|
233
|
-
mcpServers.set(serverId, parsedServer);
|
|
234
|
-
}
|
|
235
|
-
else if (referencedServer && hasMcpServerUsageOverrides(item)) {
|
|
236
|
-
parsedServer = mergeReferencedMcpServer(referencedServer, item, agent.id, name, agent.sourcePath);
|
|
237
|
-
serverId = parsedServer.id;
|
|
238
|
-
mcpServers.set(serverId, parsedServer);
|
|
239
|
-
}
|
|
240
|
-
const filter = compileMcpToolFilter(item);
|
|
241
|
-
const remoteTools = canResolveMcpToolsFromExplicitNamesOnly(filter)
|
|
242
|
-
? Array.from(filter.includeNames)
|
|
243
|
-
.filter((toolName) => shouldIncludeRemoteMcpTool(filter, toolName))
|
|
244
|
-
.map((toolName) => ({ name: toolName }))
|
|
245
|
-
: await listRemoteMcpTools(toMcpServerConfig(parsedServer));
|
|
246
|
-
for (const remoteTool of remoteTools) {
|
|
247
|
-
if (!shouldIncludeRemoteMcpTool(filter, remoteTool.name)) {
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
const toolId = `mcp.${agent.id}.${name}.${remoteTool.name}`;
|
|
251
|
-
tools.set(toolId, {
|
|
252
|
-
id: toolId,
|
|
253
|
-
type: "mcp",
|
|
254
|
-
name: remoteTool.name,
|
|
255
|
-
description: remoteTool.description ?? remoteTool.name,
|
|
256
|
-
config: {
|
|
257
|
-
mcp: {
|
|
258
|
-
serverRef: `mcp/${serverId}`,
|
|
259
|
-
},
|
|
260
|
-
mcpServer: {
|
|
261
|
-
transport: parsedServer.transport,
|
|
262
|
-
...(parsedServer.trustTier ? { trustTier: parsedServer.trustTier } : {}),
|
|
263
|
-
...(parsedServer.access ? { access: parsedServer.access } : {}),
|
|
264
|
-
...(parsedServer.tenantScope ? { tenantScope: parsedServer.tenantScope } : {}),
|
|
265
|
-
...(parsedServer.approvalPolicy ? { approvalPolicy: parsedServer.approvalPolicy } : {}),
|
|
266
|
-
...(parsedServer.promptInjectionRisk ? { promptInjectionRisk: parsedServer.promptInjectionRisk } : {}),
|
|
267
|
-
...(parsedServer.oauth ? { oauth: parsedServer.oauth } : {}),
|
|
268
|
-
...(parsedServer.labels && parsedServer.labels.length > 0 ? { labels: parsedServer.labels } : {}),
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
mcpRef: remoteTool.name,
|
|
272
|
-
bundleRefs: [],
|
|
273
|
-
sourcePath: agent.sourcePath,
|
|
274
|
-
});
|
|
275
|
-
discoveredRefs.add(`tool/${toolId}`);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
agent.toolRefs = Array.from(discoveredRefs);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
1
|
+
import w from"node:path";import{createHash as k}from"node:crypto";import{listRemoteMcpTools as x}from"../resource/resource-impl.js";import{ensureExternalResourceSource as j,isExternalSourceLocator as $}from"../resource/sources.js";import{listResourceTools as A,listResourceToolsForSource as I}from"../resource/resource.js";import{readToolModuleItems as M}from"./object-loader.js";import{parseMcpServerObject as S,parseToolObject as E}from"./resource-compilers.js";function O(o){return{transport:o.transport,command:o.command,args:o.args,env:o.env,cwd:o.cwd,url:o.url,token:o.token,headers:o.headers,trustTier:o.trustTier,access:o.access,tenantScope:o.tenantScope,approvalPolicy:o.approvalPolicy,promptInjectionRisk:o.promptInjectionRisk,oauth:o.oauth,labels:o.labels}}function y(o){return Array.isArray(o)?o.filter(t=>typeof t=="string"&&t.trim().length>0):[]}function R(o){if(typeof o!="object"||!o||Array.isArray(o))return;const t=Object.entries(o).filter(a=>typeof a[1]=="string");return t.length>0?Object.fromEntries(t):void 0}function g(o){return typeof o=="object"&&o!==null&&!Array.isArray(o)?o:void 0}function b(o,t){return y(o).map(a=>{try{return new RegExp(a)}catch(e){throw new Error(`${t} contains invalid regex ${JSON.stringify(a)}: ${e instanceof Error?e.message:String(e)}`)}})}function F(o){return{includeNames:new Set(y(o.tools)),excludeNames:new Set(y(o.excludeTools)),includePatterns:b(o.toolFilters??o.toolFilter,"toolFilter"),excludePatterns:b(o.excludeToolFilters??o.excludeToolFilter,"excludeToolFilter")}}function P(o,t){const{includeNames:a,excludeNames:e,includePatterns:r,excludePatterns:s}=o,c=a.size===0||a.has(t),f=r.length===0||r.some(p=>p.test(t));return!(!c||!f||e.has(t)||s.some(p=>p.test(t)))}function N(o){return o.includeNames.size>0&&o.includePatterns.length===0}function z(o){const t=g(o.config);return t?{...t,...o}:o}function B(o){return["transport","command","args","env","cwd","url","token","headers"].some(t=>o[t]!==void 0)}function C(o,t,a,e,r){return{id:`${a}.${e}`,transport:t.transport==="stdio"||t.transport==="http"||t.transport==="sse"||t.transport==="websocket"?t.transport:o.transport,url:typeof t.url=="string"?t.url:o.url,command:typeof t.command=="string"?t.command:o.command,args:Array.isArray(t.args)?t.args.filter(s=>typeof s=="string"):o.args,env:{...o.env??{},...R(t.env)??{}},cwd:typeof t.cwd=="string"?t.cwd:o.cwd,token:typeof t.token=="string"?t.token:o.token,headers:{...o.headers??{},...R(t.headers)??{}},trustTier:t.trustTier==="trusted"||t.trustTier==="reviewed"||t.trustTier==="untrusted"?t.trustTier:o.trustTier,access:t.access==="read-only"||t.access==="read-write"?t.access:o.access,tenantScope:t.tenantScope==="workspace"||t.tenantScope==="project"||t.tenantScope==="tenant"||t.tenantScope==="cross-tenant"?t.tenantScope:o.tenantScope,approvalPolicy:t.approvalPolicy==="always"||t.approvalPolicy==="write"||t.approvalPolicy==="never"?t.approvalPolicy:o.approvalPolicy,promptInjectionRisk:t.promptInjectionRisk==="low"||t.promptInjectionRisk==="medium"||t.promptInjectionRisk==="high"?t.promptInjectionRisk:o.promptInjectionRisk,oauth:g(t.oauth)?{provider:typeof g(t.oauth)?.provider=="string"?g(t.oauth)?.provider:o.oauth?.provider,scopes:y(g(t.oauth)?.scopes)||o.oauth?.scopes}:o.oauth,labels:y(t.labels).length>0?y(t.labels):o.labels,sourcePath:r}}async function L(o,t,a,e){const r=await j(t,a),s=[],c=`external.${k("sha256").update(t).digest("hex").slice(0,12)}`;for(const{item:i,sourcePath:h}of await M(w.join(r,"tools"),{scope:e})){const d=typeof i.id=="string"?i.id:void 0;if(!d)continue;const n=`${c}.${d}`,u=E({id:n,kind:"tool",sourcePath:h,value:{...i,id:n}});o.set(u.id,u),s.push(`tool/${u.id}`)}const p=[...(await I(t,a)).map(i=>i.toolPath),...s];p.length>0&&o.set(t,{id:t,type:"bundle",name:t,description:`External tool resource loaded from ${t}`,bundleRefs:p,sourcePath:t})}async function G(o,t,a,e="recursive"){for(const r of t)$(r)&&await L(o,r,a,e);for(const r of await A(t,a)){const s=o.get(r.toolPath);o.set(r.toolPath,{id:r.toolPath,type:s?.type??"backend",name:s?.name||r.name,description:s?.description||r.description,config:s?.config,embeddingModelRef:s?.embeddingModelRef,backendOperation:s?.backendOperation??r.backendOperation,bundleRefs:s?.bundleRefs??[],hitl:s?.hitl??r.hitl,retryable:s?.retryable??r.retryable,sourcePath:r.toolPath})}}async function K(o,t,a){for(const e of o){const r=new Set(e.toolRefs);for(const s of e.mcpServers??[]){const c=z(s),f=typeof c.ref=="string"?c.ref.trim():"",p=f.startsWith("mcp/")?f.slice(4):f,i=p?t.get(p):void 0,h=typeof c.name=="string"&&c.name.trim()?c.name.trim():i?.id?i.id:typeof c.id=="string"&&c.id.trim()?c.id.trim():"";if(!h)throw new Error(`Agent ${e.id} has an MCP server entry without a name`);let d=i?.id,n=i;n?i&&B(c)&&(n=C(i,c,e.id,h,e.sourcePath),d=n.id,t.set(d,n)):(d=`${e.id}.${h}`,n=S({id:d,kind:"mcp",sourcePath:e.sourcePath,value:c}),t.set(d,n));const u=F(c),T=N(u)?Array.from(u.includeNames).filter(l=>P(u,l)).map(l=>({name:l})):await x(O(n));for(const l of T){if(!P(u,l.name))continue;const m=`mcp.${e.id}.${h}.${l.name}`;a.set(m,{id:m,type:"mcp",name:l.name,description:l.description??l.name,config:{mcp:{serverRef:`mcp/${d}`},mcpServer:{transport:n.transport,...n.trustTier?{trustTier:n.trustTier}:{},...n.access?{access:n.access}:{},...n.tenantScope?{tenantScope:n.tenantScope}:{},...n.approvalPolicy?{approvalPolicy:n.approvalPolicy}:{},...n.promptInjectionRisk?{promptInjectionRisk:n.promptInjectionRisk}:{},...n.oauth?{oauth:n.oauth}:{},...n.labels&&n.labels.length>0?{labels:n.labels}:{}}},mcpRef:l.name,bundleRefs:[],sourcePath:e.sourcePath}),r.add(`tool/${m}`)}}e.toolRefs=Array.from(r)}}export{K as hydrateAgentMcpTools,G as hydrateResourceAndExternalTools};
|
|
@@ -1,99 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getAgentExecutionConfigValue, getAgentExecutionConfigs } from "./support/agent-execution-config.js";
|
|
3
|
-
const allowedExecutionModes = new Set(["deepagent", "langchain-v1"]);
|
|
4
|
-
function validateCheckpointerConfig(agent) {
|
|
5
|
-
const checkpointer = getAgentExecutionConfigValue(agent, "checkpointer");
|
|
6
|
-
if (typeof checkpointer === "boolean") {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (!checkpointer) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const typedCheckpointer = checkpointer;
|
|
13
|
-
const kind = typeof typedCheckpointer.kind === "string" ? typedCheckpointer.kind : "SqliteSaver";
|
|
14
|
-
const hasPath = typeof typedCheckpointer.path === "string" && typedCheckpointer.path.trim().length > 0;
|
|
15
|
-
if (kind === "MemorySaver" && hasPath) {
|
|
16
|
-
throw new Error(`Agent ${agent.id} checkpointer.path is not supported for kind MemorySaver`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function validateMiddlewareConfig(agent) {
|
|
20
|
-
const middlewareConfigs = getAgentExecutionConfigs(agent).flatMap((config) => {
|
|
21
|
-
const middleware = config.middleware;
|
|
22
|
-
return Array.isArray(middleware) ? middleware : [];
|
|
23
|
-
});
|
|
24
|
-
for (const config of middlewareConfigs) {
|
|
25
|
-
if (typeof config !== "object" || config === null || Array.isArray(config)) {
|
|
26
|
-
throw new Error(`Agent ${agent.id} middleware entries must be objects`);
|
|
27
|
-
}
|
|
28
|
-
const typed = config;
|
|
29
|
-
const kind = typeof typed.kind === "string" ? typed.kind.trim() : "";
|
|
30
|
-
if (!kind) {
|
|
31
|
-
throw new Error(`Agent ${agent.id} middleware kind is required`);
|
|
32
|
-
}
|
|
33
|
-
if (kind === "summarization" && typed.model === undefined && typeof typed.modelRef !== "string") {
|
|
34
|
-
throw new Error(`Agent ${agent.id} summarization middleware requires model or modelRef`);
|
|
35
|
-
}
|
|
36
|
-
if (kind === "modelFallback" && !Array.isArray(typed.fallbackModels) && !Array.isArray(typed.models)) {
|
|
37
|
-
throw new Error(`Agent ${agent.id} modelFallback middleware requires fallbackModels or models`);
|
|
38
|
-
}
|
|
39
|
-
if (kind === "humanInTheLoop" && typeof typed.interruptOn !== "object") {
|
|
40
|
-
throw new Error(`Agent ${agent.id} humanInTheLoop middleware requires interruptOn`);
|
|
41
|
-
}
|
|
42
|
-
if (kind === "completionCallback" && typeof typed.callbackGraphId !== "string") {
|
|
43
|
-
throw new Error(`Agent ${agent.id} completionCallback middleware requires callbackGraphId`);
|
|
44
|
-
}
|
|
45
|
-
if (kind === "filesystem" && agent.executionMode === "deepagent") {
|
|
46
|
-
throw new Error(`Agent ${agent.id} cannot use filesystem middleware with DeepAgents; configure filesystem behavior through the deepagent backend instead`);
|
|
47
|
-
}
|
|
48
|
-
if (kind === "pii" && typeof typed.piiType !== "string") {
|
|
49
|
-
throw new Error(`Agent ${agent.id} pii middleware requires piiType`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export function validateAgent(agent) {
|
|
54
|
-
const asyncSubagents = agent.asyncSubagents ?? [];
|
|
55
|
-
if (!agent.id) {
|
|
56
|
-
throw new Error(`Agent id is required in ${agent.sourcePath}`);
|
|
57
|
-
}
|
|
58
|
-
if (!allowedExecutionModes.has(agent.executionMode)) {
|
|
59
|
-
throw new Error(`Agent ${agent.id} has unsupported execution mode ${agent.executionMode}`);
|
|
60
|
-
}
|
|
61
|
-
if (!agent.description.trim()) {
|
|
62
|
-
throw new Error(`Agent ${agent.id} description must not be empty`);
|
|
63
|
-
}
|
|
64
|
-
if (!isMemoryCapableAgent(agent) && agent.memorySources.length > 0) {
|
|
65
|
-
throw new Error(`Agent ${agent.id} cannot define memory unless it uses a memory-capable backend`);
|
|
66
|
-
}
|
|
67
|
-
if ((agent.subagentRefs.length > 0 || agent.subagentPathRefs.length > 0 || asyncSubagents.length > 0) && !isDelegationCapableAgent(agent)) {
|
|
68
|
-
throw new Error(`Agent ${agent.id} must use a delegation-capable backend when subagents are defined`);
|
|
69
|
-
}
|
|
70
|
-
if (asyncSubagents.length > 0 && agent.executionMode !== "deepagent") {
|
|
71
|
-
throw new Error(`Agent ${agent.id} async subagents require backend=deepagent`);
|
|
72
|
-
}
|
|
73
|
-
validateCheckpointerConfig(agent);
|
|
74
|
-
validateMiddlewareConfig(agent);
|
|
75
|
-
}
|
|
76
|
-
export function validateTopology(agents) {
|
|
77
|
-
const ids = new Set();
|
|
78
|
-
const referencedSubagentIds = new Set();
|
|
79
|
-
for (const agent of agents) {
|
|
80
|
-
if (ids.has(agent.id)) {
|
|
81
|
-
throw new Error(`Duplicate agent id ${agent.id}`);
|
|
82
|
-
}
|
|
83
|
-
ids.add(agent.id);
|
|
84
|
-
for (const ref of agent.subagentRefs) {
|
|
85
|
-
referencedSubagentIds.add(ref.replace(/^agent\//, ""));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
for (const agent of agents) {
|
|
89
|
-
if (!referencedSubagentIds.has(agent.id) && !agent.modelRef) {
|
|
90
|
-
throw new Error(`Agent ${agent.id} modelRef is required`);
|
|
91
|
-
}
|
|
92
|
-
if (!referencedSubagentIds.has(agent.id)) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (!isDelegationCapableAgent(agent)) {
|
|
96
|
-
throw new Error(`Subagent ${agent.id} must use a delegation-capable backend`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
import{isDelegationCapableAgent as n,isMemoryCapableAgent as d}from"./support/agent-capabilities.js";import{getAgentExecutionConfigValue as a,getAgentExecutionConfigs as s}from"./support/agent-execution-config.js";const l=new Set(["deepagent","langchain-v1"]);function c(e){const o=a(e,"checkpointer");if(typeof o=="boolean"||!o)return;const i=o,r=typeof i.kind=="string"?i.kind:"SqliteSaver",t=typeof i.path=="string"&&i.path.trim().length>0;if(r==="MemorySaver"&&t)throw new Error(`Agent ${e.id} checkpointer.path is not supported for kind MemorySaver`)}function f(e){const o=s(e).flatMap(i=>{const r=i.middleware;return Array.isArray(r)?r:[]});for(const i of o){if(typeof i!="object"||i===null||Array.isArray(i))throw new Error(`Agent ${e.id} middleware entries must be objects`);const r=i,t=typeof r.kind=="string"?r.kind.trim():"";if(!t)throw new Error(`Agent ${e.id} middleware kind is required`);if(t==="summarization"&&r.model===void 0&&typeof r.modelRef!="string")throw new Error(`Agent ${e.id} summarization middleware requires model or modelRef`);if(t==="modelFallback"&&!Array.isArray(r.fallbackModels)&&!Array.isArray(r.models))throw new Error(`Agent ${e.id} modelFallback middleware requires fallbackModels or models`);if(t==="humanInTheLoop"&&typeof r.interruptOn!="object")throw new Error(`Agent ${e.id} humanInTheLoop middleware requires interruptOn`);if(t==="completionCallback"&&typeof r.callbackGraphId!="string")throw new Error(`Agent ${e.id} completionCallback middleware requires callbackGraphId`);if(t==="filesystem"&&e.executionMode==="deepagent")throw new Error(`Agent ${e.id} cannot use filesystem middleware with DeepAgents; configure filesystem behavior through the deepagent backend instead`);if(t==="pii"&&typeof r.piiType!="string")throw new Error(`Agent ${e.id} pii middleware requires piiType`)}}function h(e){const o=e.asyncSubagents??[];if(!e.id)throw new Error(`Agent id is required in ${e.sourcePath}`);if(!l.has(e.executionMode))throw new Error(`Agent ${e.id} has unsupported execution mode ${e.executionMode}`);if(!e.description.trim())throw new Error(`Agent ${e.id} description must not be empty`);if(!d(e)&&e.memorySources.length>0)throw new Error(`Agent ${e.id} cannot define memory unless it uses a memory-capable backend`);if((e.subagentRefs.length>0||e.subagentPathRefs.length>0||o.length>0)&&!n(e))throw new Error(`Agent ${e.id} must use a delegation-capable backend when subagents are defined`);if(o.length>0&&e.executionMode!=="deepagent")throw new Error(`Agent ${e.id} async subagents require backend=deepagent`);c(e),f(e)}function m(e){const o=new Set,i=new Set;for(const r of e){if(o.has(r.id))throw new Error(`Duplicate agent id ${r.id}`);o.add(r.id);for(const t of r.subagentRefs)i.add(t.replace(/^agent\//,""))}for(const r of e){if(!i.has(r.id)&&!r.modelRef)throw new Error(`Agent ${r.id} modelRef is required`);if(i.has(r.id)&&!n(r))throw new Error(`Subagent ${r.id} must use a delegation-capable backend`)}}export{h as validateAgent,m as validateTopology};
|