@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,296 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
5
|
-
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
6
|
-
import { AGENT_HARNESS_VERSION } from "../../package-version.js";
|
|
7
|
-
import { createRuntimeEnv } from "../../runtime/env/runtime-env.js";
|
|
8
|
-
const mcpClientCache = new Map();
|
|
9
|
-
let mcpClientLoader = createConnectedMcpClient;
|
|
10
|
-
function readStringRecord(value) {
|
|
11
|
-
if (typeof value !== "object" || !value) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const entries = Object.entries(value).filter((entry) => typeof entry[1] === "string");
|
|
15
|
-
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
16
|
-
}
|
|
17
|
-
function readStringArray(value) {
|
|
18
|
-
if (!Array.isArray(value)) {
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
const entries = value.filter((item) => typeof item === "string" && item.trim().length > 0).map((item) => item.trim());
|
|
22
|
-
return entries.length > 0 ? entries : undefined;
|
|
23
|
-
}
|
|
24
|
-
function normalizeMcpTransport(value) {
|
|
25
|
-
if (value === "stdio" || value === "http" || value === "sse" || value === "websocket") {
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
export function readMcpServerConfig(workspace, tool) {
|
|
31
|
-
const mcpConfig = typeof tool.config?.mcp === "object" && tool.config?.mcp
|
|
32
|
-
? tool.config.mcp
|
|
33
|
-
: undefined;
|
|
34
|
-
const serverRef = typeof mcpConfig?.serverRef === "string" ? mcpConfig.serverRef : undefined;
|
|
35
|
-
if (serverRef) {
|
|
36
|
-
const serverId = serverRef.startsWith("mcp/") ? serverRef.slice(4) : serverRef;
|
|
37
|
-
const server = workspace.mcpServers.get(serverId);
|
|
38
|
-
if (!server) {
|
|
39
|
-
throw new Error(`MCP tool ${tool.id} references missing MCP server ${serverRef}`);
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
transport: server.transport,
|
|
43
|
-
command: server.command,
|
|
44
|
-
args: server.args,
|
|
45
|
-
env: server.env,
|
|
46
|
-
cwd: server.cwd,
|
|
47
|
-
url: server.url,
|
|
48
|
-
token: server.token,
|
|
49
|
-
headers: server.headers,
|
|
50
|
-
trustTier: server.trustTier,
|
|
51
|
-
access: server.access,
|
|
52
|
-
tenantScope: server.tenantScope,
|
|
53
|
-
approvalPolicy: server.approvalPolicy,
|
|
54
|
-
promptInjectionRisk: server.promptInjectionRisk,
|
|
55
|
-
oauth: server.oauth,
|
|
56
|
-
labels: server.labels,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
const config = typeof tool.config === "object" && tool.config
|
|
60
|
-
? tool.config
|
|
61
|
-
: undefined;
|
|
62
|
-
const mcpServer = typeof config?.mcpServer === "object" && config.mcpServer
|
|
63
|
-
? config.mcpServer
|
|
64
|
-
: config;
|
|
65
|
-
if (!mcpServer) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
transport: normalizeMcpTransport(mcpServer.transport) ?? ((typeof mcpServer.url === "string" && mcpServer.url.trim()) ? "http" : "stdio"),
|
|
70
|
-
command: typeof mcpServer.command === "string" ? mcpServer.command.trim() : undefined,
|
|
71
|
-
args: Array.isArray(mcpServer.args) ? mcpServer.args.filter((item) => typeof item === "string") : undefined,
|
|
72
|
-
env: readStringRecord(mcpServer.env),
|
|
73
|
-
cwd: typeof mcpServer.cwd === "string" ? mcpServer.cwd : undefined,
|
|
74
|
-
url: typeof mcpServer.url === "string" ? mcpServer.url.trim() : undefined,
|
|
75
|
-
token: typeof mcpServer.token === "string" ? mcpServer.token : undefined,
|
|
76
|
-
headers: readStringRecord(mcpServer.headers),
|
|
77
|
-
trustTier: mcpServer.trustTier === "trusted" || mcpServer.trustTier === "reviewed" || mcpServer.trustTier === "untrusted"
|
|
78
|
-
? mcpServer.trustTier
|
|
79
|
-
: undefined,
|
|
80
|
-
access: mcpServer.access === "read-only" || mcpServer.access === "read-write" ? mcpServer.access : undefined,
|
|
81
|
-
tenantScope: mcpServer.tenantScope === "workspace" ||
|
|
82
|
-
mcpServer.tenantScope === "project" ||
|
|
83
|
-
mcpServer.tenantScope === "tenant" ||
|
|
84
|
-
mcpServer.tenantScope === "cross-tenant"
|
|
85
|
-
? mcpServer.tenantScope
|
|
86
|
-
: undefined,
|
|
87
|
-
approvalPolicy: mcpServer.approvalPolicy === "always" || mcpServer.approvalPolicy === "write" || mcpServer.approvalPolicy === "never"
|
|
88
|
-
? mcpServer.approvalPolicy
|
|
89
|
-
: undefined,
|
|
90
|
-
promptInjectionRisk: mcpServer.promptInjectionRisk === "low" || mcpServer.promptInjectionRisk === "medium" || mcpServer.promptInjectionRisk === "high"
|
|
91
|
-
? mcpServer.promptInjectionRisk
|
|
92
|
-
: undefined,
|
|
93
|
-
oauth: typeof mcpServer.oauth === "object" && mcpServer.oauth
|
|
94
|
-
? {
|
|
95
|
-
provider: typeof mcpServer.oauth.provider === "string"
|
|
96
|
-
? mcpServer.oauth.provider
|
|
97
|
-
: undefined,
|
|
98
|
-
scopes: readStringArray(mcpServer.oauth.scopes),
|
|
99
|
-
}
|
|
100
|
-
: undefined,
|
|
101
|
-
labels: readStringArray(mcpServer.labels),
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function createMcpCacheKey(config) {
|
|
105
|
-
return JSON.stringify({
|
|
106
|
-
transport: config.transport ?? "stdio",
|
|
107
|
-
command: config.command,
|
|
108
|
-
args: config.args ?? [],
|
|
109
|
-
env: config.env ?? {},
|
|
110
|
-
cwd: config.cwd ?? "",
|
|
111
|
-
url: config.url ?? "",
|
|
112
|
-
token: config.token ?? "",
|
|
113
|
-
headers: config.headers ?? {},
|
|
114
|
-
trustTier: config.trustTier ?? "",
|
|
115
|
-
access: config.access ?? "",
|
|
116
|
-
tenantScope: config.tenantScope ?? "",
|
|
117
|
-
approvalPolicy: config.approvalPolicy ?? "",
|
|
118
|
-
promptInjectionRisk: config.promptInjectionRisk ?? "",
|
|
119
|
-
oauth: config.oauth ?? {},
|
|
120
|
-
labels: config.labels ?? [],
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
async function createConnectedMcpClient(config) {
|
|
124
|
-
const client = new Client({
|
|
125
|
-
name: "agent-harness",
|
|
126
|
-
version: AGENT_HARNESS_VERSION,
|
|
127
|
-
});
|
|
128
|
-
const headers = {
|
|
129
|
-
...(config.headers ?? {}),
|
|
130
|
-
...(config.token ? { Authorization: `Bearer ${config.token}` } : {}),
|
|
131
|
-
};
|
|
132
|
-
const transport = config.transport === "http"
|
|
133
|
-
? new StreamableHTTPClientTransport(new URL(config.url ?? ""), {
|
|
134
|
-
requestInit: Object.keys(headers).length > 0 ? { headers } : undefined,
|
|
135
|
-
})
|
|
136
|
-
: config.transport === "sse"
|
|
137
|
-
? new SSEClientTransport(new URL(config.url ?? ""), {
|
|
138
|
-
requestInit: Object.keys(headers).length > 0 ? { headers } : undefined,
|
|
139
|
-
})
|
|
140
|
-
: config.transport === "websocket"
|
|
141
|
-
? new WebSocketClientTransport(new URL(config.url ?? ""))
|
|
142
|
-
: new StdioClientTransport({
|
|
143
|
-
command: config.command ?? "",
|
|
144
|
-
args: config.args,
|
|
145
|
-
env: createRuntimeEnv(config.env),
|
|
146
|
-
cwd: config.cwd,
|
|
147
|
-
});
|
|
148
|
-
await client.connect(transport);
|
|
149
|
-
return client;
|
|
150
|
-
}
|
|
151
|
-
function isRecoverableMcpError(error) {
|
|
152
|
-
if (typeof error !== "object" || error === null) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
const message = typeof error.message === "string"
|
|
156
|
-
? (error.message).toLowerCase()
|
|
157
|
-
: "";
|
|
158
|
-
const code = typeof error.code === "string"
|
|
159
|
-
? (error.code).toLowerCase()
|
|
160
|
-
: "";
|
|
161
|
-
return [
|
|
162
|
-
"connection closed",
|
|
163
|
-
"transport closed",
|
|
164
|
-
"socket closed",
|
|
165
|
-
"stream closed",
|
|
166
|
-
"network socket disconnected",
|
|
167
|
-
].some((pattern) => message.includes(pattern))
|
|
168
|
-
|| ["econnreset", "epipe", "ehostunreach", "ecancelled"].includes(code);
|
|
169
|
-
}
|
|
170
|
-
async function closeCachedMcpClient(cacheKey) {
|
|
171
|
-
const cached = mcpClientCache.get(cacheKey);
|
|
172
|
-
mcpClientCache.delete(cacheKey);
|
|
173
|
-
if (!cached) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
try {
|
|
177
|
-
const client = await cached;
|
|
178
|
-
await client.close();
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
// Ignore teardown failures for clients that never connected successfully.
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async function invalidateMcpClient(config) {
|
|
185
|
-
await closeCachedMcpClient(createMcpCacheKey(config));
|
|
186
|
-
}
|
|
187
|
-
async function withRecoveredMcpClient(config, operation) {
|
|
188
|
-
const client = await getOrCreateMcpClient(config);
|
|
189
|
-
try {
|
|
190
|
-
return await operation(client);
|
|
191
|
-
}
|
|
192
|
-
catch (error) {
|
|
193
|
-
if (!isRecoverableMcpError(error)) {
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
await invalidateMcpClient(config);
|
|
197
|
-
return operation(await getOrCreateMcpClient(config));
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
export async function getOrCreateMcpClient(config) {
|
|
201
|
-
const cacheKey = createMcpCacheKey(config);
|
|
202
|
-
const cached = mcpClientCache.get(cacheKey);
|
|
203
|
-
if (cached) {
|
|
204
|
-
return cached;
|
|
205
|
-
}
|
|
206
|
-
const loading = mcpClientLoader(config).catch((error) => {
|
|
207
|
-
if (mcpClientCache.get(cacheKey) === loading) {
|
|
208
|
-
mcpClientCache.delete(cacheKey);
|
|
209
|
-
}
|
|
210
|
-
throw error;
|
|
211
|
-
});
|
|
212
|
-
mcpClientCache.set(cacheKey, loading);
|
|
213
|
-
return loading;
|
|
214
|
-
}
|
|
215
|
-
export async function closeMcpClientsForWorkspace(workspace) {
|
|
216
|
-
const cacheKeys = new Set();
|
|
217
|
-
for (const tool of workspace.tools.values()) {
|
|
218
|
-
if (tool.type !== "mcp") {
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
const config = readMcpServerConfig(workspace, tool);
|
|
222
|
-
if (!config) {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
cacheKeys.add(createMcpCacheKey(config));
|
|
226
|
-
}
|
|
227
|
-
await Promise.all(Array.from(cacheKeys, (cacheKey) => closeCachedMcpClient(cacheKey)));
|
|
228
|
-
}
|
|
229
|
-
export function __resetMcpClientCacheForTests() {
|
|
230
|
-
mcpClientCache.clear();
|
|
231
|
-
mcpClientLoader = createConnectedMcpClient;
|
|
232
|
-
}
|
|
233
|
-
export function __setMcpClientCacheEntryForTests(config, clientPromise) {
|
|
234
|
-
mcpClientCache.set(createMcpCacheKey(config), clientPromise);
|
|
235
|
-
}
|
|
236
|
-
export function __setMcpClientLoaderForTests(loader) {
|
|
237
|
-
mcpClientLoader = loader;
|
|
238
|
-
}
|
|
239
|
-
async function getRemoteMcpToolDescriptor(config, remoteToolName) {
|
|
240
|
-
const result = await withRecoveredMcpClient(config, (client) => client.listTools());
|
|
241
|
-
const tool = result.tools.find((item) => typeof item.name === "string" && item.name === remoteToolName);
|
|
242
|
-
if (!tool || typeof tool.name !== "string") {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
return {
|
|
246
|
-
name: tool.name,
|
|
247
|
-
description: typeof tool.description === "string" ? tool.description : undefined,
|
|
248
|
-
inputSchema: typeof tool.inputSchema === "object" && tool.inputSchema ? tool.inputSchema : undefined,
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
export async function listRemoteMcpTools(config) {
|
|
252
|
-
const result = await withRecoveredMcpClient(config, (client) => client.listTools());
|
|
253
|
-
return result.tools
|
|
254
|
-
.filter((tool) => typeof tool.name === "string")
|
|
255
|
-
.map((tool) => ({
|
|
256
|
-
name: tool.name,
|
|
257
|
-
description: typeof tool.description === "string" ? tool.description : undefined,
|
|
258
|
-
inputSchema: typeof tool.inputSchema === "object" && tool.inputSchema ? tool.inputSchema : undefined,
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
export function createMcpToolResolver(workspace) {
|
|
262
|
-
const mcpTools = new Map(Array.from(workspace.tools.values())
|
|
263
|
-
.filter((tool) => tool.type === "mcp")
|
|
264
|
-
.map((tool) => [tool.id, tool]));
|
|
265
|
-
return (toolIds) => toolIds.flatMap((toolId) => {
|
|
266
|
-
const tool = mcpTools.get(toolId);
|
|
267
|
-
if (!tool) {
|
|
268
|
-
return [];
|
|
269
|
-
}
|
|
270
|
-
const serverConfig = readMcpServerConfig(workspace, tool);
|
|
271
|
-
if (!serverConfig) {
|
|
272
|
-
throw new Error(`MCP tool ${tool.id} must define mcp.serverRef or inline MCP server config.`);
|
|
273
|
-
}
|
|
274
|
-
const remoteToolName = tool.mcpRef ?? tool.name;
|
|
275
|
-
const descriptorPromise = getRemoteMcpToolDescriptor(serverConfig, remoteToolName);
|
|
276
|
-
return [
|
|
277
|
-
{
|
|
278
|
-
name: tool.name,
|
|
279
|
-
description: tool.description,
|
|
280
|
-
inputSchemaPromise: descriptorPromise.then((descriptor) => descriptor?.inputSchema),
|
|
281
|
-
async invoke(input) {
|
|
282
|
-
const result = await withRecoveredMcpClient(serverConfig, (client) => client.callTool({
|
|
283
|
-
name: remoteToolName,
|
|
284
|
-
arguments: typeof input === "object" && input !== null ? input : {},
|
|
285
|
-
}));
|
|
286
|
-
const textParts = Array.isArray(result.content)
|
|
287
|
-
? result.content
|
|
288
|
-
.filter((item) => typeof item === "object" && item !== null && "type" in item)
|
|
289
|
-
.flatMap((item) => item.type === "text" && typeof item.text === "string" ? [item.text] : [])
|
|
290
|
-
: [];
|
|
291
|
-
return textParts.length > 0 ? textParts.join("\n\n") : JSON.stringify(result);
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
];
|
|
295
|
-
});
|
|
296
|
-
}
|
|
1
|
+
import{Client as T}from"@modelcontextprotocol/sdk/client/index.js";import{SSEClientTransport as k}from"@modelcontextprotocol/sdk/client/sse.js";import{StdioClientTransport as R}from"@modelcontextprotocol/sdk/client/stdio.js";import{StreamableHTTPClientTransport as b}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{WebSocketClientTransport as j}from"@modelcontextprotocol/sdk/client/websocket.js";import{AGENT_HARNESS_VERSION as M}from"../../package-version.js";import{createRuntimeEnv as P}from"../../runtime/env/runtime-env.js";const a=new Map;let m=S;function h(e){if(typeof e!="object"||!e)return;const r=Object.entries(e).filter(t=>typeof t[1]=="string");return r.length>0?Object.fromEntries(r):void 0}function w(e){if(!Array.isArray(e))return;const r=e.filter(t=>typeof t=="string"&&t.trim().length>0).map(t=>t.trim());return r.length>0?r:void 0}function I(e){if(e==="stdio"||e==="http"||e==="sse"||e==="websocket")return e}function v(e,r){const t=typeof r.config?.mcp=="object"&&r.config?.mcp?r.config.mcp:void 0,o=typeof t?.serverRef=="string"?t.serverRef:void 0;if(o){const p=o.startsWith("mcp/")?o.slice(4):o,c=e.mcpServers.get(p);if(!c)throw new Error(`MCP tool ${r.id} references missing MCP server ${o}`);return{transport:c.transport,command:c.command,args:c.args,env:c.env,cwd:c.cwd,url:c.url,token:c.token,headers:c.headers,trustTier:c.trustTier,access:c.access,tenantScope:c.tenantScope,approvalPolicy:c.approvalPolicy,promptInjectionRisk:c.promptInjectionRisk,oauth:c.oauth,labels:c.labels}}const s=typeof r.config=="object"&&r.config?r.config:void 0,n=typeof s?.mcpServer=="object"&&s.mcpServer?s.mcpServer:s;return n?{transport:I(n.transport)??(typeof n.url=="string"&&n.url.trim()?"http":"stdio"),command:typeof n.command=="string"?n.command.trim():void 0,args:Array.isArray(n.args)?n.args.filter(p=>typeof p=="string"):void 0,env:h(n.env),cwd:typeof n.cwd=="string"?n.cwd:void 0,url:typeof n.url=="string"?n.url.trim():void 0,token:typeof n.token=="string"?n.token:void 0,headers:h(n.headers),trustTier:n.trustTier==="trusted"||n.trustTier==="reviewed"||n.trustTier==="untrusted"?n.trustTier:void 0,access:n.access==="read-only"||n.access==="read-write"?n.access:void 0,tenantScope:n.tenantScope==="workspace"||n.tenantScope==="project"||n.tenantScope==="tenant"||n.tenantScope==="cross-tenant"?n.tenantScope:void 0,approvalPolicy:n.approvalPolicy==="always"||n.approvalPolicy==="write"||n.approvalPolicy==="never"?n.approvalPolicy:void 0,promptInjectionRisk:n.promptInjectionRisk==="low"||n.promptInjectionRisk==="medium"||n.promptInjectionRisk==="high"?n.promptInjectionRisk:void 0,oauth:typeof n.oauth=="object"&&n.oauth?{provider:typeof n.oauth.provider=="string"?n.oauth.provider:void 0,scopes:w(n.oauth.scopes)}:void 0,labels:w(n.labels)}:null}function u(e){return JSON.stringify({transport:e.transport??"stdio",command:e.command,args:e.args??[],env:e.env??{},cwd:e.cwd??"",url:e.url??"",token:e.token??"",headers:e.headers??{},trustTier:e.trustTier??"",access:e.access??"",tenantScope:e.tenantScope??"",approvalPolicy:e.approvalPolicy??"",promptInjectionRisk:e.promptInjectionRisk??"",oauth:e.oauth??{},labels:e.labels??[]})}async function S(e){const r=new T({name:"agent-harness",version:M}),t={...e.headers??{},...e.token?{Authorization:`Bearer ${e.token}`}:{}},o=e.transport==="http"?new b(new URL(e.url??""),{requestInit:Object.keys(t).length>0?{headers:t}:void 0}):e.transport==="sse"?new k(new URL(e.url??""),{requestInit:Object.keys(t).length>0?{headers:t}:void 0}):e.transport==="websocket"?new j(new URL(e.url??"")):new R({command:e.command??"",args:e.args,env:P(e.env),cwd:e.cwd});return await r.connect(o),r}function x(e){if(typeof e!="object"||e===null)return!1;const r=typeof e.message=="string"?e.message.toLowerCase():"",t=typeof e.code=="string"?e.code.toLowerCase():"";return["connection closed","transport closed","socket closed","stream closed","network socket disconnected"].some(o=>r.includes(o))||["econnreset","epipe","ehostunreach","ecancelled"].includes(t)}async function g(e){const r=a.get(e);if(a.delete(e),!!r)try{await(await r).close()}catch{}}async function A(e){await g(u(e))}async function f(e,r){const t=await C(e);try{return await r(t)}catch(o){if(!x(o))throw o;return await A(e),r(await C(e))}}async function C(e){const r=u(e),t=a.get(r);if(t)return t;const o=m(e).catch(s=>{throw a.get(r)===o&&a.delete(r),s});return a.set(r,o),o}async function W(e){const r=new Set;for(const t of e.tools.values()){if(t.type!=="mcp")continue;const o=v(e,t);o&&r.add(u(o))}await Promise.all(Array.from(r,t=>g(t)))}function q(){a.clear(),m=S}function z(e,r){a.set(u(e),r)}function H(e){m=e}async function E(e,r){const o=(await f(e,s=>s.listTools())).tools.find(s=>typeof s.name=="string"&&s.name===r);return!o||typeof o.name!="string"?null:{name:o.name,description:typeof o.description=="string"?o.description:void 0,inputSchema:typeof o.inputSchema=="object"&&o.inputSchema?o.inputSchema:void 0}}async function J(e){return(await f(e,t=>t.listTools())).tools.filter(t=>typeof t.name=="string").map(t=>({name:t.name,description:typeof t.description=="string"?t.description:void 0,inputSchema:typeof t.inputSchema=="object"&&t.inputSchema?t.inputSchema:void 0}))}function K(e){const r=new Map(Array.from(e.tools.values()).filter(t=>t.type==="mcp").map(t=>[t.id,t]));return t=>t.flatMap(o=>{const s=r.get(o);if(!s)return[];const n=v(e,s);if(!n)throw new Error(`MCP tool ${s.id} must define mcp.serverRef or inline MCP server config.`);const p=s.mcpRef??s.name,c=E(n,p);return[{name:s.name,description:s.description,inputSchemaPromise:c.then(d=>d?.inputSchema),async invoke(d){const l=await f(n,i=>i.callTool({name:p,arguments:typeof d=="object"&&d!==null?d:{}})),y=Array.isArray(l.content)?l.content.filter(i=>typeof i=="object"&&i!==null&&"type"in i).flatMap(i=>i.type==="text"&&typeof i.text=="string"?[i.text]:[]):[];return y.length>0?y.join(`
|
|
2
|
+
|
|
3
|
+
`):JSON.stringify(l)}}]})}export{q as __resetMcpClientCacheForTests,z as __setMcpClientCacheEntryForTests,H as __setMcpClientLoaderForTests,W as closeMcpClientsForWorkspace,K as createMcpToolResolver,C as getOrCreateMcpClient,J as listRemoteMcpTools,v as readMcpServerConfig};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "./mcp/tool-support.js";
|
|
1
|
+
import{AGENT_HARNESS_VERSION as E}from"../package-version.js";export*from"./mcp/tool-support.js";export{E as AGENT_HARNESS_VERSION};
|
|
@@ -1,215 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
-
import { createMcpToolResolver } from "../mcp/tool-support.js";
|
|
7
|
-
import { createFunctionToolResolver } from "../tools/function-tool-resolver.js";
|
|
8
|
-
import { createInlineBackendResolver } from "../backend/workspace-scoped-backend.js";
|
|
9
|
-
import { ensureExternalResourceSource, ensureExternalSource, isExternalSourceLocator, parseExternalSourceLocator } from "../sources.js";
|
|
10
|
-
const resourceDir = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
const require = createRequire(import.meta.url);
|
|
12
|
-
function installedResourceProviderEntry() {
|
|
13
|
-
try {
|
|
14
|
-
return require.resolve("@botbotgo/agent-harness-resource");
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function resolveLocalResourceProviderEntry(currentResourceDir, resolveInstalledEntry = installedResourceProviderEntry) {
|
|
21
|
-
const candidates = [
|
|
22
|
-
path.resolve(currentResourceDir, "../../../resource-package/dist/src/index.js"),
|
|
23
|
-
path.resolve(currentResourceDir, "../../../resource-package/src/index.ts"),
|
|
24
|
-
resolveInstalledEntry(),
|
|
25
|
-
].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
26
|
-
for (const candidate of candidates) {
|
|
27
|
-
if (existsSync(candidate)) {
|
|
28
|
-
return candidate;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return candidates.at(-1) ?? path.resolve(currentResourceDir, "../../../resource-package/dist/src/index.js");
|
|
32
|
-
}
|
|
33
|
-
async function loadLocalResource(entry) {
|
|
34
|
-
if (!existsSync(entry)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const imported = await import(pathToFileURL(entry).href);
|
|
38
|
-
return (imported.default ?? imported);
|
|
39
|
-
}
|
|
40
|
-
const resourceProviderEntry = resolveLocalResourceProviderEntry(resourceDir);
|
|
41
|
-
const localResource = await loadLocalResource(resourceProviderEntry);
|
|
42
|
-
const remoteResourceCache = new Map();
|
|
43
|
-
function listProviderTools(provider) {
|
|
44
|
-
const rawTools = provider?.listResourceTools?.() ?? provider?.listBuiltinTools?.() ?? [];
|
|
45
|
-
return rawTools.map((tool) => ({
|
|
46
|
-
...tool,
|
|
47
|
-
toolPath: tool.toolPath ?? tool.builtinPath ?? "",
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
function preferProviderValue(provider, primary, fallback) {
|
|
51
|
-
return provider ? (primary(provider) ?? fallback(provider)) : undefined;
|
|
52
|
-
}
|
|
53
|
-
function createProviderToolResolver(provider, workspace, options) {
|
|
54
|
-
return preferProviderValue(provider, (candidate) => candidate.createResourceToolResolver?.(workspace, options), (candidate) => candidate.createBuiltinToolResolver?.(workspace, options));
|
|
55
|
-
}
|
|
56
|
-
function createProviderBackendResolver(provider, workspace) {
|
|
57
|
-
return preferProviderValue(provider, (candidate) => candidate.createResourceBackendResolver?.(workspace), (candidate) => candidate.createBuiltinBackendResolver?.(workspace));
|
|
58
|
-
}
|
|
59
|
-
function requireLocalResource(feature) {
|
|
60
|
-
if (localResource) {
|
|
61
|
-
return localResource;
|
|
62
|
-
}
|
|
63
|
-
throw new Error(`agent-harness optional tool bundle support is unavailable for ${feature}. Install the matching provider package or provide a local sibling checkout.`);
|
|
64
|
-
}
|
|
65
|
-
function listWorkspaceResourceProviders(workspace) {
|
|
66
|
-
return (workspace.resources ?? [])
|
|
67
|
-
.map((source) => remoteResourceCache.get(source))
|
|
68
|
-
.filter((provider) => Boolean(provider));
|
|
69
|
-
}
|
|
70
|
-
function createWorkspaceProviderResolvers(workspace, factory) {
|
|
71
|
-
return listWorkspaceResourceProviders(workspace)
|
|
72
|
-
.map((provider) => factory(provider))
|
|
73
|
-
.filter((resolver) => Boolean(resolver));
|
|
74
|
-
}
|
|
75
|
-
function resolvePackageEntry(packageRoot, pkg) {
|
|
76
|
-
const exportsField = pkg.exports;
|
|
77
|
-
if (typeof exportsField === "string") {
|
|
78
|
-
return path.resolve(packageRoot, exportsField);
|
|
79
|
-
}
|
|
80
|
-
if (exportsField && typeof exportsField === "object" && "." in exportsField) {
|
|
81
|
-
const rootExport = exportsField["."];
|
|
82
|
-
if (typeof rootExport === "string") {
|
|
83
|
-
return path.resolve(packageRoot, rootExport);
|
|
84
|
-
}
|
|
85
|
-
if (rootExport && typeof rootExport === "object") {
|
|
86
|
-
const importEntry = rootExport.import ?? rootExport.default;
|
|
87
|
-
if (typeof importEntry === "string") {
|
|
88
|
-
return path.resolve(packageRoot, importEntry);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (typeof pkg.module === "string") {
|
|
93
|
-
return path.resolve(packageRoot, pkg.module);
|
|
94
|
-
}
|
|
95
|
-
if (typeof pkg.main === "string") {
|
|
96
|
-
return path.resolve(packageRoot, pkg.main);
|
|
97
|
-
}
|
|
98
|
-
return path.resolve(packageRoot, "index.js");
|
|
99
|
-
}
|
|
100
|
-
async function loadRemoteResource(source, workspaceRoot) {
|
|
101
|
-
const cached = remoteResourceCache.get(source);
|
|
102
|
-
if (cached !== undefined) {
|
|
103
|
-
return cached;
|
|
104
|
-
}
|
|
105
|
-
if (!isExternalSourceLocator(source)) {
|
|
106
|
-
throw new Error(`Unsupported resource source ${source}. Use npm:, tgz:, or file:.`);
|
|
107
|
-
}
|
|
108
|
-
const parsed = parseExternalSourceLocator(source);
|
|
109
|
-
if (parsed.subpath) {
|
|
110
|
-
throw new Error(`Resource source ${source} must point at a package root, not a subpath`);
|
|
111
|
-
}
|
|
112
|
-
await ensureExternalResourceSource(source, workspaceRoot);
|
|
113
|
-
const packageRoot = await ensureExternalSource(source, workspaceRoot);
|
|
114
|
-
const pkg = JSON.parse(await readFile(path.join(packageRoot, "package.json"), "utf8"));
|
|
115
|
-
const entry = resolvePackageEntry(packageRoot, pkg);
|
|
116
|
-
if (!existsSync(entry)) {
|
|
117
|
-
remoteResourceCache.set(source, null);
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
const imported = await import(pathToFileURL(entry).href);
|
|
121
|
-
const provider = (imported.default ?? imported);
|
|
122
|
-
if (listProviderTools(provider).length === 0 &&
|
|
123
|
-
!provider.listResourceTools &&
|
|
124
|
-
!provider.listBuiltinTools) {
|
|
125
|
-
remoteResourceCache.set(source, null);
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
if (!provider.createResourceToolResolver && !provider.createBuiltinToolResolver) {
|
|
129
|
-
remoteResourceCache.set(source, null);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
const typedProvider = provider;
|
|
133
|
-
remoteResourceCache.set(source, typedProvider);
|
|
134
|
-
return typedProvider;
|
|
135
|
-
}
|
|
136
|
-
export async function ensureResourceSources(sources = [], workspaceRoot = process.cwd()) {
|
|
137
|
-
await Promise.all(sources.map((source) => loadRemoteResource(source, workspaceRoot)));
|
|
138
|
-
}
|
|
139
|
-
function resolveBundledFallbackRoot(kind) {
|
|
140
|
-
const suffix = kind === "skills" ? ["resources", "skills"] : ["config"];
|
|
141
|
-
const candidates = [
|
|
142
|
-
path.resolve(resourceDir, "..", ...suffix),
|
|
143
|
-
path.resolve(resourceDir, "..", "..", ...suffix),
|
|
144
|
-
];
|
|
145
|
-
for (const candidate of candidates) {
|
|
146
|
-
if (existsSync(candidate)) {
|
|
147
|
-
return candidate;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
export function defaultResourceSkillsRoot() {
|
|
153
|
-
if (localResource) {
|
|
154
|
-
return preferProviderValue(localResource, (candidate) => candidate.defaultResourceSkillsRoot?.(), (candidate) => candidate.builtinSkillsRoot?.()) ?? "";
|
|
155
|
-
}
|
|
156
|
-
return resolveBundledFallbackRoot("skills") ?? requireLocalResource("default resource skill resolution").defaultResourceSkillsRoot?.() ?? "";
|
|
157
|
-
}
|
|
158
|
-
export function defaultResourceConfigRoot() {
|
|
159
|
-
if (localResource) {
|
|
160
|
-
return (preferProviderValue(localResource, (candidate) => candidate.defaultResourceConfigRoot?.(), (candidate) => candidate.builtinConfigRoot?.() ?? candidate.builtinDefaultsRoot?.()) ?? "");
|
|
161
|
-
}
|
|
162
|
-
return resolveBundledFallbackRoot("config") ?? requireLocalResource("default resource config resolution").defaultResourceConfigRoot?.() ?? "";
|
|
163
|
-
}
|
|
164
|
-
export async function listResourceTools(sources = [], workspaceRoot = process.cwd()) {
|
|
165
|
-
await ensureResourceSources(sources, workspaceRoot);
|
|
166
|
-
const deduped = new Map();
|
|
167
|
-
for (const source of sources) {
|
|
168
|
-
for (const tool of listProviderTools(remoteResourceCache.get(source) ?? undefined)) {
|
|
169
|
-
deduped.set(tool.toolPath, tool);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return Array.from(deduped.values());
|
|
173
|
-
}
|
|
174
|
-
export async function listResourceToolsForSource(source, workspaceRoot = process.cwd()) {
|
|
175
|
-
await ensureResourceSources([source], workspaceRoot);
|
|
176
|
-
return listProviderTools(remoteResourceCache.get(source) ?? undefined);
|
|
177
|
-
}
|
|
178
|
-
export function createResourceBackendResolver(workspace) {
|
|
179
|
-
const localResolver = createProviderBackendResolver(localResource, workspace);
|
|
180
|
-
const remoteResolvers = createWorkspaceProviderResolvers(workspace, (provider) => createProviderBackendResolver(provider, workspace));
|
|
181
|
-
const inlineResolver = createInlineBackendResolver(workspace);
|
|
182
|
-
return (binding) => {
|
|
183
|
-
const providerResolved = localResolver?.(binding) ??
|
|
184
|
-
remoteResolvers.map((resolver) => resolver(binding)).find((resolved) => resolved !== undefined);
|
|
185
|
-
return providerResolved ?? inlineResolver(binding);
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
export function createResourceToolResolver(workspace, options = {}) {
|
|
189
|
-
const functionResolver = createFunctionToolResolver(workspace);
|
|
190
|
-
const mcpResolver = createMcpToolResolver(workspace);
|
|
191
|
-
const remoteResolvers = createWorkspaceProviderResolvers(workspace, (provider) => createProviderToolResolver(provider, workspace, options));
|
|
192
|
-
return (toolIds, binding) => {
|
|
193
|
-
const resolved = [
|
|
194
|
-
...functionResolver(toolIds, binding),
|
|
195
|
-
...mcpResolver(toolIds, binding),
|
|
196
|
-
...remoteResolvers.flatMap((resolver) => resolver(toolIds, binding)),
|
|
197
|
-
];
|
|
198
|
-
const deduped = new Map();
|
|
199
|
-
for (const tool of resolved) {
|
|
200
|
-
const name = String(tool.name);
|
|
201
|
-
if (!deduped.has(name)) {
|
|
202
|
-
deduped.set(name, tool);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return Array.from(deduped.values());
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
export const ensureBuiltinSources = ensureResourceSources;
|
|
209
|
-
export const builtinSkillsRoot = defaultResourceSkillsRoot;
|
|
210
|
-
export const builtinConfigRoot = defaultResourceConfigRoot;
|
|
211
|
-
export const listBuiltinTools = listResourceTools;
|
|
212
|
-
export const listBuiltinToolsForSource = listResourceToolsForSource;
|
|
213
|
-
export const createBuiltinBackendResolver = createResourceBackendResolver;
|
|
214
|
-
export const createBuiltinToolResolver = createResourceToolResolver;
|
|
215
|
-
export const resolveLocalBuiltinsEntry = resolveLocalResourceProviderEntry;
|
|
1
|
+
import{existsSync as p}from"node:fs";import{createRequire as w}from"node:module";import s from"node:path";import{readFile as E}from"node:fs/promises";import{fileURLToPath as b,pathToFileURL as y}from"node:url";import{createMcpToolResolver as k}from"../mcp/tool-support.js";import{createFunctionToolResolver as L}from"../tools/function-tool-resolver.js";import{createInlineBackendResolver as j}from"../backend/workspace-scoped-backend.js";import{ensureExternalResourceSource as F,ensureExternalSource as C,isExternalSourceLocator as M,parseExternalSourceLocator as U}from"../sources.js";const v=s.dirname(b(import.meta.url)),q=w(import.meta.url);function $(){try{return q.resolve("@botbotgo/agent-harness-resource")}catch{return null}}function g(e,o=$){const r=[s.resolve(e,"../../../resource-package/dist/src/index.js"),s.resolve(e,"../../../resource-package/src/index.ts"),o()].filter(t=>typeof t=="string"&&t.length>0);for(const t of r)if(p(t))return t;return r.at(-1)??s.resolve(e,"../../../resource-package/dist/src/index.js")}async function A(e){if(!p(e))return null;const o=await import(y(e).href);return o.default??o}const W=g(v),f=await A(W),c=new Map;function m(e){return(e?.listResourceTools?.()??e?.listBuiltinTools?.()??[]).map(r=>({...r,toolPath:r.toolPath??r.builtinPath??""}))}function R(e,o,r){return e?o(e)??r(e):void 0}function z(e,o,r){return R(e,t=>t.createResourceToolResolver?.(o,r),t=>t.createBuiltinToolResolver?.(o,r))}function T(e,o){return R(e,r=>r.createResourceBackendResolver?.(o),r=>r.createBuiltinBackendResolver?.(o))}function B(e){if(f)return f;throw new Error(`agent-harness optional tool bundle support is unavailable for ${e}. Install the matching provider package or provide a local sibling checkout.`)}function J(e){return(e.resources??[]).map(o=>c.get(o)).filter(o=>!!o)}function P(e,o){return J(e).map(r=>o(r)).filter(r=>!!r)}function N(e,o){const r=o.exports;if(typeof r=="string")return s.resolve(e,r);if(r&&typeof r=="object"&&"."in r){const t=r["."];if(typeof t=="string")return s.resolve(e,t);if(t&&typeof t=="object"){const n=t.import??t.default;if(typeof n=="string")return s.resolve(e,n)}}return typeof o.module=="string"?s.resolve(e,o.module):typeof o.main=="string"?s.resolve(e,o.main):s.resolve(e,"index.js")}async function O(e,o){const r=c.get(e);if(r!==void 0)return r;if(!M(e))throw new Error(`Unsupported resource source ${e}. Use npm:, tgz:, or file:.`);if(U(e).subpath)throw new Error(`Resource source ${e} must point at a package root, not a subpath`);await F(e,o);const n=await C(e,o),u=JSON.parse(await E(s.join(n,"package.json"),"utf8")),l=N(n,u);if(!p(l))return c.set(e,null),null;const d=await import(y(l).href),i=d.default??d;if(m(i).length===0&&!i.listResourceTools&&!i.listBuiltinTools||!i.createResourceToolResolver&&!i.createBuiltinToolResolver)return c.set(e,null),null;const a=i;return c.set(e,a),a}async function x(e=[],o=process.cwd()){await Promise.all(e.map(r=>O(r,o)))}function S(e){const o=e==="skills"?["resources","skills"]:["config"],r=[s.resolve(v,"..",...o),s.resolve(v,"..","..",...o)];for(const t of r)if(p(t))return t;return null}function V(){return f?R(f,e=>e.defaultResourceSkillsRoot?.(),e=>e.builtinSkillsRoot?.())??"":S("skills")??B("default resource skill resolution").defaultResourceSkillsRoot?.()??""}function D(){return f?R(f,e=>e.defaultResourceConfigRoot?.(),e=>e.builtinConfigRoot?.()??e.builtinDefaultsRoot?.())??"":S("config")??B("default resource config resolution").defaultResourceConfigRoot?.()??""}async function G(e=[],o=process.cwd()){await x(e,o);const r=new Map;for(const t of e)for(const n of m(c.get(t)??void 0))r.set(n.toolPath,n);return Array.from(r.values())}async function H(e,o=process.cwd()){return await x([e],o),m(c.get(e)??void 0)}function I(e){const o=T(f,e),r=P(e,n=>T(n,e)),t=j(e);return n=>o?.(n)??r.map(l=>l(n)).find(l=>l!==void 0)??t(n)}function K(e,o={}){const r=L(e),t=k(e),n=P(e,u=>z(u,e,o));return(u,l)=>{const d=[...r(u,l),...t(u,l),...n.flatMap(a=>a(u,l))],i=new Map;for(const a of d){const h=String(a.name);i.has(h)||i.set(h,a)}return Array.from(i.values())}}const ne=x,se=V,le=D,ie=G,ue=H,ce=I,ae=K,fe=g;export{le as builtinConfigRoot,se as builtinSkillsRoot,ce as createBuiltinBackendResolver,ae as createBuiltinToolResolver,I as createResourceBackendResolver,K as createResourceToolResolver,D as defaultResourceConfigRoot,V as defaultResourceSkillsRoot,ne as ensureBuiltinSources,x as ensureResourceSources,ie as listBuiltinTools,ue as listBuiltinToolsForSource,G as listResourceTools,H as listResourceToolsForSource,fe as resolveLocalBuiltinsEntry,g as resolveLocalResourceProviderEntry};
|
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { ensureResourceSources, defaultResourceSkillsRoot, defaultResourceConfigRoot, listResourceTools, listResourceToolsForSource, createResourceBackendResolver, createResourceToolResolver, ensureBuiltinSources, builtinSkillsRoot, builtinConfigRoot, listBuiltinTools, listBuiltinToolsForSource, createBuiltinBackendResolver, createBuiltinToolResolver, resolveLocalResourceProviderEntry, resolveLocalBuiltinsEntry, } from "./providers/resource-provider.js";
|
|
3
|
-
export { normalizeWorkspaceScopedPath } from "./backend/workspace-scoped-backend.js";
|
|
1
|
+
import{getOrCreateMcpClient as r,listRemoteMcpTools as l,readMcpServerConfig as t}from"./mcp-tool-support.js";import{ensureResourceSources as i,defaultResourceSkillsRoot as c,defaultResourceConfigRoot as u,listResourceTools as n,listResourceToolsForSource as R,createResourceBackendResolver as a,createResourceToolResolver as f,ensureBuiltinSources as p,builtinSkillsRoot as v,builtinConfigRoot as B,listBuiltinTools as S,listBuiltinToolsForSource as d,createBuiltinBackendResolver as T,createBuiltinToolResolver as k,resolveLocalResourceProviderEntry as m,resolveLocalBuiltinsEntry as C}from"./providers/resource-provider.js";import{normalizeWorkspaceScopedPath as x}from"./backend/workspace-scoped-backend.js";export{B as builtinConfigRoot,v as builtinSkillsRoot,T as createBuiltinBackendResolver,k as createBuiltinToolResolver,a as createResourceBackendResolver,f as createResourceToolResolver,u as defaultResourceConfigRoot,c as defaultResourceSkillsRoot,p as ensureBuiltinSources,i as ensureResourceSources,r as getOrCreateMcpClient,S as listBuiltinTools,d as listBuiltinToolsForSource,l as listRemoteMcpTools,n as listResourceTools,R as listResourceToolsForSource,x as normalizeWorkspaceScopedPath,t as readMcpServerConfig,C as resolveLocalBuiltinsEntry,m as resolveLocalResourceProviderEntry};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ensureResourceSources as r,defaultResourceSkillsRoot as s,defaultResourceConfigRoot as c,listResourceTools as l,listResourceToolsForSource as u,createResourceBackendResolver as R,createResourceToolResolver as t,resolveLocalResourceProviderEntry as a}from"./resource-impl.js";export{R as createResourceBackendResolver,t as createResourceToolResolver,c as defaultResourceConfigRoot,s as defaultResourceSkillsRoot,r as ensureResourceSources,l as listResourceTools,u as listResourceToolsForSource,a as resolveLocalResourceProviderEntry};
|