@botbotgo/agent-harness 0.0.308 → 0.0.310
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 +17 -1
- package/README.zh.md +17 -1
- package/dist/acp.d.ts +1 -116
- package/dist/acp.js +1 -310
- package/dist/api.d.ts +4 -2
- package/dist/api.js +4 -1
- package/dist/cli/chat-interactive.d.ts +24 -0
- package/dist/cli/chat-interactive.js +244 -0
- package/dist/cli/chat-rendering.d.ts +9 -0
- package/dist/cli/chat-rendering.js +102 -0
- package/dist/cli/chat-stream.d.ts +23 -0
- package/dist/cli/chat-stream.js +330 -0
- package/dist/cli/chat-ui.d.ts +20 -0
- package/dist/cli/chat-ui.js +198 -0
- package/dist/cli/chat-workspace.d.ts +15 -0
- package/dist/cli/chat-workspace.js +205 -0
- package/dist/cli/main.d.ts +52 -0
- package/dist/cli/main.js +323 -0
- package/dist/cli/managed-service-commands.d.ts +23 -0
- package/dist/cli/managed-service-commands.js +63 -0
- package/dist/cli/managed-service.d.ts +27 -0
- package/dist/cli/managed-service.js +61 -0
- package/dist/cli/options-init-chat.d.ts +16 -0
- package/dist/cli/options-init-chat.js +108 -0
- package/dist/cli/options-runtime.d.ts +27 -0
- package/dist/cli/options-runtime.js +158 -0
- package/dist/cli/options-serve.d.ts +24 -0
- package/dist/cli/options-serve.js +166 -0
- package/dist/cli/options.d.ts +5 -0
- package/dist/cli/options.js +47 -0
- package/dist/cli/process-guards.d.ts +14 -0
- package/dist/cli/process-guards.js +139 -0
- package/dist/cli/request-tree.d.ts +12 -0
- package/dist/cli/request-tree.js +296 -0
- package/dist/cli/runtime-commands.d.ts +15 -0
- package/dist/cli/runtime-commands.js +247 -0
- package/dist/cli/runtime-output.d.ts +5 -0
- package/dist/cli/runtime-output.js +124 -0
- package/dist/cli/server-commands.d.ts +36 -0
- package/dist/cli/server-commands.js +250 -0
- package/dist/cli/workspace.d.ts +6 -0
- package/dist/cli/workspace.js +71 -0
- package/dist/cli.d.ts +1 -67
- package/dist/cli.js +2 -2734
- package/dist/client/acp.d.ts +1 -50
- package/dist/client/acp.js +1 -219
- package/dist/client/in-process.d.ts +5 -5
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +1 -1
- package/dist/contracts/runtime-evaluation.d.ts +103 -0
- package/dist/contracts/runtime-evaluation.js +1 -0
- package/dist/contracts/runtime-memory.d.ts +162 -0
- package/dist/contracts/runtime-memory.js +1 -0
- package/dist/contracts/runtime-observability.d.ts +248 -0
- package/dist/contracts/runtime-observability.js +1 -0
- package/dist/contracts/runtime-requests.d.ts +342 -0
- package/dist/contracts/runtime-requests.js +1 -0
- package/dist/contracts/runtime-scheduling.d.ts +146 -0
- package/dist/contracts/runtime-scheduling.js +1 -0
- package/dist/contracts/runtime.d.ts +5 -1042
- package/dist/contracts/runtime.js +27 -1
- package/dist/flow/build-flow-graph.js +4 -875
- package/dist/flow/flow-graph-normalization.d.ts +56 -0
- package/dist/flow/flow-graph-normalization.js +214 -0
- package/dist/flow/flow-graph-runtime.d.ts +8 -0
- package/dist/flow/flow-graph-runtime.js +107 -0
- package/dist/flow/flow-graph-upstream.d.ts +18 -0
- package/dist/flow/flow-graph-upstream.js +498 -0
- package/dist/flow/types.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/init-project.d.ts +1 -12
- package/dist/init-project.js +1 -651
- package/dist/{procedural → knowledge/procedural}/manager.d.ts +3 -3
- package/dist/{procedural → knowledge/procedural}/manager.js +6 -6
- package/dist/mcp.d.ts +2 -62
- package/dist/mcp.js +2 -253
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.js +1 -1
- package/dist/persistence/sqlite-runtime.d.ts +19 -0
- package/dist/persistence/sqlite-runtime.js +86 -0
- package/dist/persistence/sqlite-store.js +11 -99
- package/dist/{request-events.d.ts → projections/request-events.d.ts} +1 -1
- package/dist/{upstream-events.js → projections/upstream-events.js} +1 -1
- package/dist/protocol/a2a/http-discovery.d.ts +39 -0
- package/dist/protocol/a2a/http-discovery.js +178 -0
- package/dist/protocol/a2a/http-rpc.d.ts +28 -0
- package/dist/protocol/a2a/http-rpc.js +623 -0
- package/dist/protocol/a2a/http.d.ts +72 -1
- package/dist/protocol/a2a/http.js +14 -1124
- package/dist/protocol/a2a/task-state.d.ts +29 -0
- package/dist/protocol/a2a/task-state.js +317 -0
- package/dist/protocol/acp/client.js +1 -1
- package/dist/protocol/acp/harness-client.d.ts +50 -0
- package/dist/protocol/acp/harness-client.js +219 -0
- package/dist/protocol/acp/server.d.ts +116 -0
- package/dist/protocol/acp/server.js +310 -0
- package/dist/protocol/ag-ui/http.js +1 -1
- package/dist/protocol/mcp/server.d.ts +76 -0
- package/dist/protocol/mcp/server.js +428 -0
- package/dist/resource/backend/workspace-scoped-backend.d.ts +40 -0
- package/dist/resource/backend/workspace-scoped-backend.js +296 -0
- package/dist/resource/mcp/tool-support.d.ts +35 -0
- package/dist/resource/mcp/tool-support.js +296 -0
- package/dist/resource/mcp-tool-support.d.ts +2 -35
- package/dist/resource/mcp-tool-support.js +2 -296
- package/dist/resource/providers/resource-provider.d.ts +22 -0
- package/dist/resource/providers/resource-provider.js +215 -0
- package/dist/resource/resource-impl.d.ts +3 -33
- package/dist/resource/resource-impl.js +2 -808
- package/dist/resource/resource-types.d.ts +33 -0
- package/dist/resource/resource-types.js +1 -0
- package/dist/resource/tools/function-tool-resolver.d.ts +2 -0
- package/dist/resource/tools/function-tool-resolver.js +306 -0
- package/dist/runtime/adapter/middleware-assembly.js +1 -1
- package/dist/runtime/adapter/model/invocation-request.js +2 -2
- package/dist/runtime/adapter/model/message-assembly.js +1 -1
- package/dist/runtime/agent-runtime-adapter.d.ts +3 -63
- package/dist/runtime/agent-runtime-adapter.js +5 -233
- package/dist/runtime/agent-runtime-assembly.d.ts +67 -0
- package/dist/runtime/agent-runtime-assembly.js +211 -0
- package/dist/runtime/harness/background-runtime.d.ts +1 -1
- package/dist/runtime/harness/events/event-sink.js +1 -1
- package/dist/runtime/harness/events/runtime-event-operations.d.ts +1 -1
- package/dist/runtime/harness/events/streaming.js +1 -1
- package/dist/runtime/harness/public-shapes.d.ts +43 -0
- package/dist/runtime/harness/public-shapes.js +186 -0
- package/dist/runtime/harness/run/inspection.js +2 -2
- package/dist/runtime/harness/run/resources.js +1 -1
- package/dist/runtime/harness/run/surface-semantics.js +1 -1
- package/dist/runtime/harness/system/inventory.d.ts +1 -1
- package/dist/runtime/harness/system/inventory.js +2 -2
- package/dist/runtime/harness/system/policy-engine.js +1 -1
- package/dist/runtime/harness/system/runtime-memory-manager.js +1 -1
- package/dist/runtime/harness/system/skill-requirements.d.ts +1 -1
- package/dist/runtime/harness/system/skill-requirements.js +1 -1
- package/dist/runtime/harness.d.ts +3 -2
- package/dist/runtime/harness.js +11 -191
- package/dist/runtime/maintenance/checkpoint-maintenance.js +1 -1
- package/dist/runtime/maintenance/runtime-record-maintenance.js +1 -1
- package/dist/runtime/parsing/output-content.d.ts +11 -0
- package/dist/runtime/parsing/output-content.js +442 -0
- package/dist/runtime/parsing/output-parsing.d.ts +3 -29
- package/dist/runtime/parsing/output-parsing.js +3 -806
- package/dist/runtime/parsing/output-recovery.d.ts +14 -0
- package/dist/runtime/parsing/output-recovery.js +288 -0
- package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
- package/dist/runtime/parsing/output-tool-args.js +120 -0
- package/dist/runtime/support/runtime-factories.js +1 -1
- package/dist/scaffold/init-project.d.ts +12 -0
- package/dist/scaffold/init-project.js +651 -0
- package/dist/{extensions.d.ts → tooling/extensions.d.ts} +1 -1
- package/dist/{extensions.js → tooling/extensions.js} +3 -3
- package/dist/{tool-modules.d.ts → tooling/module-loader.d.ts} +1 -1
- package/dist/{tool-modules.js → tooling/module-loader.js} +2 -2
- package/dist/workspace/agent-binding-compiler.js +2 -2
- package/dist/workspace/compile.js +2 -2
- package/dist/workspace/object-loader-paths.d.ts +11 -0
- package/dist/workspace/object-loader-paths.js +75 -0
- package/dist/workspace/object-loader-readers.d.ts +21 -0
- package/dist/workspace/object-loader-readers.js +187 -0
- package/dist/workspace/object-loader.d.ts +0 -1
- package/dist/workspace/object-loader.js +6 -260
- package/dist/workspace/resource-compilers.js +1 -1
- package/dist/workspace/support/discovery.js +1 -1
- package/package.json +1 -1
- package/dist/runtime/adapter/index.d.ts +0 -13
- package/dist/runtime/adapter/index.js +0 -13
- package/dist/runtime/harness/index.d.ts +0 -19
- package/dist/runtime/harness/index.js +0 -19
- package/dist/runtime/maintenance/index.d.ts +0 -4
- package/dist/runtime/maintenance/index.js +0 -4
- package/dist/runtime/parsing/index.d.ts +0 -2
- package/dist/runtime/parsing/index.js +0 -2
- package/dist/runtime/support/index.d.ts +0 -4
- package/dist/runtime/support/index.js +0 -4
- package/dist/workspace/support/index.d.ts +0 -2
- package/dist/workspace/support/index.js +0 -2
- /package/dist/{procedural → knowledge/procedural}/config.d.ts +0 -0
- /package/dist/{procedural → knowledge/procedural}/config.js +0 -0
- /package/dist/{procedural → knowledge/procedural}/index.d.ts +0 -0
- /package/dist/{procedural → knowledge/procedural}/index.js +0 -0
- /package/dist/{presentation.d.ts → projections/presentation.d.ts} +0 -0
- /package/dist/{presentation.js → projections/presentation.js} +0 -0
- /package/dist/{request-events.js → projections/request-events.js} +0 -0
- /package/dist/{upstream-events.d.ts → projections/upstream-events.d.ts} +0 -0
- /package/dist/runtime/{support → env}/runtime-env.d.ts +0 -0
- /package/dist/runtime/{support → env}/runtime-env.js +0 -0
- /package/dist/runtime/{support → layout}/runtime-layout.d.ts +0 -0
- /package/dist/runtime/{support → layout}/runtime-layout.js +0 -0
- /package/dist/runtime/{support → prompts}/runtime-prompts.d.ts +0 -0
- /package/dist/runtime/{support → prompts}/runtime-prompts.js +0 -0
- /package/dist/runtime/{support → skills}/skill-metadata.d.ts +0 -0
- /package/dist/runtime/{support → skills}/skill-metadata.js +0 -0
|
@@ -1,809 +1,3 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { stat } from "node:fs/promises";
|
|
6
|
-
import { readFile } from "node:fs/promises";
|
|
7
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
8
|
-
import { CompositeBackend, LangSmithSandbox, LocalShellBackend, StateBackend, StoreBackend } from "deepagents";
|
|
9
|
-
import { UPSTREAM_REQUEST_CONFIG_KEY, UPSTREAM_SESSION_CONFIG_KEY } from "../runtime/adapter/upstream-configurable-keys.js";
|
|
10
|
-
import { getBindingBackendConfig, getBindingExecutionView, getBindingPrimaryModel } from "../runtime/support/compiled-binding.js";
|
|
11
|
-
import { resolveCompiledEmbeddingModelRef } from "../runtime/support/embedding-models.js";
|
|
12
|
-
import { createRuntimeEnv } from "../runtime/support/runtime-env.js";
|
|
13
|
-
import { isSupportedToolModulePath, loadToolModuleDefinition } from "../tool-modules.js";
|
|
14
|
-
import { createMcpToolResolver, } from "./mcp-tool-support.js";
|
|
15
|
-
import { resolveIsolatedResourceModulePath } from "./isolation.js";
|
|
16
|
-
import { ensureExternalResourceSource, ensureExternalSource, isExternalSourceLocator, parseExternalSourceLocator, resolveResourcePackageRoot, } from "./sources.js";
|
|
17
1
|
export { getOrCreateMcpClient, listRemoteMcpTools, readMcpServerConfig, } from "./mcp-tool-support.js";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function installedResourceProviderEntry() {
|
|
21
|
-
try {
|
|
22
|
-
return require.resolve("@botbotgo/agent-harness-resource");
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export function resolveLocalResourceProviderEntry(currentResourceDir, resolveInstalledEntry = installedResourceProviderEntry) {
|
|
29
|
-
const candidates = [
|
|
30
|
-
path.resolve(currentResourceDir, "../../../resource-package/dist/src/index.js"),
|
|
31
|
-
path.resolve(currentResourceDir, "../../../resource-package/src/index.ts"),
|
|
32
|
-
resolveInstalledEntry(),
|
|
33
|
-
].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
34
|
-
for (const candidate of candidates) {
|
|
35
|
-
if (existsSync(candidate)) {
|
|
36
|
-
return candidate;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return candidates.at(-1) ?? path.resolve(currentResourceDir, "../../../resource-package/dist/src/index.js");
|
|
40
|
-
}
|
|
41
|
-
const resourceProviderEntry = resolveLocalResourceProviderEntry(resourceDir);
|
|
42
|
-
function listVirtualRootEntries(rootDir) {
|
|
43
|
-
try {
|
|
44
|
-
return new Set(readdirSync(rootDir, { withFileTypes: true }).map((entry) => entry.name));
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return new Set();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function normalizeVirtualExecuteCommand(command, rootDir) {
|
|
51
|
-
if (typeof command !== "string" || command.length === 0) {
|
|
52
|
-
return command;
|
|
53
|
-
}
|
|
54
|
-
const rootEntries = listVirtualRootEntries(rootDir);
|
|
55
|
-
if (rootEntries.size === 0) {
|
|
56
|
-
return command;
|
|
57
|
-
}
|
|
58
|
-
return command.replace(/(^|[\s=:(\[{,;|&])(?<quote>["']?)(?<virtualPath>\/(?:[^\s"'`;|&()<>]+))(?:\k<quote>)/g, (match, prefix, quote = "", virtualPath) => {
|
|
59
|
-
const normalizedVirtualPath = virtualPath.replace(/\/+/g, "/");
|
|
60
|
-
const segments = normalizedVirtualPath.split("/").filter((segment) => segment.length > 0);
|
|
61
|
-
const firstSegment = segments[0];
|
|
62
|
-
if (!firstSegment || !rootEntries.has(firstSegment)) {
|
|
63
|
-
return match;
|
|
64
|
-
}
|
|
65
|
-
const translatedPath = path.resolve(rootDir, ...segments);
|
|
66
|
-
return `${prefix}${quote}${translatedPath}${quote}`;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
export function normalizeWorkspaceScopedPath(rootDir, inputPath) {
|
|
70
|
-
if (typeof inputPath !== "string" || inputPath.length === 0 || !path.isAbsolute(inputPath)) {
|
|
71
|
-
return inputPath;
|
|
72
|
-
}
|
|
73
|
-
if (inputPath === "/") {
|
|
74
|
-
return ".";
|
|
75
|
-
}
|
|
76
|
-
const virtualSegments = inputPath.replace(/\/+/g, "/").split("/").filter((segment) => segment.length > 0);
|
|
77
|
-
if (virtualSegments.length > 0) {
|
|
78
|
-
const rootEntries = listVirtualRootEntries(rootDir);
|
|
79
|
-
const firstSegment = virtualSegments[0];
|
|
80
|
-
if (rootEntries.has(firstSegment)) {
|
|
81
|
-
return path.join(...virtualSegments);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const normalizedRootDir = path.resolve(rootDir);
|
|
85
|
-
const normalizedInputPath = path.resolve(inputPath);
|
|
86
|
-
if (normalizedInputPath === normalizedRootDir || normalizedInputPath.startsWith(`${normalizedRootDir}${path.sep}`)) {
|
|
87
|
-
return path.relative(normalizedRootDir, normalizedInputPath) || ".";
|
|
88
|
-
}
|
|
89
|
-
throw new Error(`Path '${inputPath}' is outside the workspace root '${normalizedRootDir}'. Use a workspace-relative path instead.`);
|
|
90
|
-
}
|
|
91
|
-
function normalizeWorkspaceScopedNullablePath(rootDir, inputPath) {
|
|
92
|
-
return typeof inputPath === "string" ? normalizeWorkspaceScopedPath(rootDir, inputPath) : inputPath;
|
|
93
|
-
}
|
|
94
|
-
class WorkspaceScopedBackend {
|
|
95
|
-
backend;
|
|
96
|
-
id;
|
|
97
|
-
cwd;
|
|
98
|
-
rootDir;
|
|
99
|
-
root;
|
|
100
|
-
virtualMode;
|
|
101
|
-
execute;
|
|
102
|
-
constructor(backend, rootDir) {
|
|
103
|
-
this.backend = backend;
|
|
104
|
-
this.rootDir = path.resolve(rootDir);
|
|
105
|
-
this.root = this.rootDir;
|
|
106
|
-
this.cwd = this.rootDir;
|
|
107
|
-
this.id = typeof backend.id === "string" ? backend.id : undefined;
|
|
108
|
-
this.virtualMode = backend.virtualMode === true;
|
|
109
|
-
this.execute = typeof backend.execute === "function"
|
|
110
|
-
? (command) => backend.execute(command)
|
|
111
|
-
: undefined;
|
|
112
|
-
}
|
|
113
|
-
ls(filePath) {
|
|
114
|
-
return this.backend.ls(normalizeWorkspaceScopedPath(this.rootDir, filePath));
|
|
115
|
-
}
|
|
116
|
-
read(filePath, offset, limit) {
|
|
117
|
-
return this.backend.read(normalizeWorkspaceScopedPath(this.rootDir, filePath), offset, limit);
|
|
118
|
-
}
|
|
119
|
-
readRaw(filePath) {
|
|
120
|
-
return this.backend.readRaw(normalizeWorkspaceScopedPath(this.rootDir, filePath));
|
|
121
|
-
}
|
|
122
|
-
grep(pattern, filePath, glob) {
|
|
123
|
-
return this.backend.grep(pattern, normalizeWorkspaceScopedNullablePath(this.rootDir, filePath), glob);
|
|
124
|
-
}
|
|
125
|
-
grepRaw(pattern, filePath, glob) {
|
|
126
|
-
return this.backend.grepRaw(pattern, normalizeWorkspaceScopedNullablePath(this.rootDir, filePath), glob);
|
|
127
|
-
}
|
|
128
|
-
glob(pattern, filePath) {
|
|
129
|
-
return this.backend.glob(pattern, typeof filePath === "string" ? normalizeWorkspaceScopedPath(this.rootDir, filePath) : filePath);
|
|
130
|
-
}
|
|
131
|
-
write(filePath, content) {
|
|
132
|
-
return this.backend.write(normalizeWorkspaceScopedPath(this.rootDir, filePath), content);
|
|
133
|
-
}
|
|
134
|
-
edit(filePath, oldString, newString, replaceAll) {
|
|
135
|
-
return this.backend.edit(normalizeWorkspaceScopedPath(this.rootDir, filePath), oldString, newString, replaceAll);
|
|
136
|
-
}
|
|
137
|
-
uploadFiles(files) {
|
|
138
|
-
return this.backend.uploadFiles(files);
|
|
139
|
-
}
|
|
140
|
-
downloadFiles(paths) {
|
|
141
|
-
const normalizedPaths = Array.isArray(paths) ? paths.map((currentPath) => normalizeWorkspaceScopedPath(this.rootDir, currentPath)) : paths;
|
|
142
|
-
return this.backend.downloadFiles(normalizedPaths);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
async function loadLocalResource(entry) {
|
|
146
|
-
if (!existsSync(entry)) {
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
const imported = await import(pathToFileURL(entry).href);
|
|
150
|
-
return (imported.default ?? imported);
|
|
151
|
-
}
|
|
152
|
-
const localResource = await loadLocalResource(resourceProviderEntry);
|
|
153
|
-
function listProviderTools(provider) {
|
|
154
|
-
const rawTools = provider?.listResourceTools?.() ?? provider?.listBuiltinTools?.() ?? [];
|
|
155
|
-
return rawTools.map((tool) => ({
|
|
156
|
-
...tool,
|
|
157
|
-
toolPath: tool.toolPath ?? tool.builtinPath ?? "",
|
|
158
|
-
}));
|
|
159
|
-
}
|
|
160
|
-
function preferProviderValue(provider, primary, fallback) {
|
|
161
|
-
return provider ? (primary(provider) ?? fallback(provider)) : undefined;
|
|
162
|
-
}
|
|
163
|
-
function createProviderToolResolver(provider, workspace, options) {
|
|
164
|
-
return preferProviderValue(provider, (candidate) => candidate.createResourceToolResolver?.(workspace, options), (candidate) => candidate.createBuiltinToolResolver?.(workspace, options));
|
|
165
|
-
}
|
|
166
|
-
function createProviderBackendResolver(provider, workspace) {
|
|
167
|
-
return preferProviderValue(provider, (candidate) => candidate.createResourceBackendResolver?.(workspace), (candidate) => candidate.createBuiltinBackendResolver?.(workspace));
|
|
168
|
-
}
|
|
169
|
-
class CompatibleCompositeBackend {
|
|
170
|
-
id;
|
|
171
|
-
execute;
|
|
172
|
-
composite;
|
|
173
|
-
constructor(defaultBackend, routes) {
|
|
174
|
-
this.composite = new CompositeBackend(defaultBackend, routes);
|
|
175
|
-
const sandboxLike = defaultBackend;
|
|
176
|
-
if (typeof sandboxLike.id === "string" && typeof sandboxLike.execute === "function") {
|
|
177
|
-
this.id = sandboxLike.id;
|
|
178
|
-
const virtualCwd = typeof sandboxLike.cwd === "string" && sandboxLike.virtualMode === true ? sandboxLike.cwd : null;
|
|
179
|
-
this.execute =
|
|
180
|
-
virtualCwd
|
|
181
|
-
? (command) => this.composite.execute(normalizeVirtualExecuteCommand(command, virtualCwd))
|
|
182
|
-
: (command) => this.composite.execute(command);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
ls(filePath) {
|
|
186
|
-
return this.composite.ls(filePath);
|
|
187
|
-
}
|
|
188
|
-
read(filePath, offset, limit) {
|
|
189
|
-
return this.composite.read(filePath, offset, limit);
|
|
190
|
-
}
|
|
191
|
-
readRaw(filePath) {
|
|
192
|
-
return this.composite.readRaw(filePath);
|
|
193
|
-
}
|
|
194
|
-
grep(pattern, filePath, glob) {
|
|
195
|
-
return this.composite.grep(pattern, filePath ?? undefined, glob ?? undefined);
|
|
196
|
-
}
|
|
197
|
-
glob(pattern, filePath) {
|
|
198
|
-
return this.composite.glob(pattern, filePath);
|
|
199
|
-
}
|
|
200
|
-
write(filePath, content) {
|
|
201
|
-
return this.composite.write(filePath, content);
|
|
202
|
-
}
|
|
203
|
-
edit(filePath, oldString, newString, replaceAll) {
|
|
204
|
-
return this.composite.edit(filePath, oldString, newString, replaceAll);
|
|
205
|
-
}
|
|
206
|
-
uploadFiles(files) {
|
|
207
|
-
return this.composite.uploadFiles(files);
|
|
208
|
-
}
|
|
209
|
-
downloadFiles(paths) {
|
|
210
|
-
return this.composite.downloadFiles(paths);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function omitKind(config) {
|
|
214
|
-
const { kind: _kind, ...rest } = config ?? {};
|
|
215
|
-
return rest;
|
|
216
|
-
}
|
|
217
|
-
class LazyLangSmithSandbox {
|
|
218
|
-
config;
|
|
219
|
-
sandboxPromise = null;
|
|
220
|
-
constructor(config) {
|
|
221
|
-
this.config = config;
|
|
222
|
-
}
|
|
223
|
-
get id() {
|
|
224
|
-
return "langsmith-pending";
|
|
225
|
-
}
|
|
226
|
-
get isRunning() {
|
|
227
|
-
return this.sandboxPromise !== null;
|
|
228
|
-
}
|
|
229
|
-
getSandbox() {
|
|
230
|
-
if (!this.sandboxPromise) {
|
|
231
|
-
this.sandboxPromise = LangSmithSandbox.create(omitKind(this.config));
|
|
232
|
-
}
|
|
233
|
-
return this.sandboxPromise;
|
|
234
|
-
}
|
|
235
|
-
async read(filePath, offset, limit) {
|
|
236
|
-
return (await this.getSandbox()).read(filePath, offset, limit);
|
|
237
|
-
}
|
|
238
|
-
async edit(filePath, oldString, newString, replaceAll) {
|
|
239
|
-
return (await this.getSandbox()).edit(filePath, oldString, newString, replaceAll);
|
|
240
|
-
}
|
|
241
|
-
async ls(dirPath) {
|
|
242
|
-
return (await this.getSandbox()).ls(dirPath);
|
|
243
|
-
}
|
|
244
|
-
async glob(pattern, searchPath) {
|
|
245
|
-
return (await this.getSandbox()).glob(pattern, searchPath);
|
|
246
|
-
}
|
|
247
|
-
async write(filePath, content) {
|
|
248
|
-
return (await this.getSandbox()).write(filePath, content);
|
|
249
|
-
}
|
|
250
|
-
async execute(command) {
|
|
251
|
-
return (await this.getSandbox()).execute(command);
|
|
252
|
-
}
|
|
253
|
-
async uploadFiles(files) {
|
|
254
|
-
return (await this.getSandbox()).uploadFiles(files);
|
|
255
|
-
}
|
|
256
|
-
async downloadFiles(paths) {
|
|
257
|
-
return (await this.getSandbox()).downloadFiles(paths);
|
|
258
|
-
}
|
|
259
|
-
async close() {
|
|
260
|
-
if (!this.sandboxPromise) {
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
await (await this.sandboxPromise).close();
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
const INLINE_BACKEND_ERROR = 'Unsupported DeepAgent backend kind "%s". Supported inline kinds: LocalShellBackend, VfsSandbox, StateBackend, StoreBackend, CompositeBackend, LangSmithSandbox.';
|
|
267
|
-
function unsupportedInlineBackend(kind) {
|
|
268
|
-
throw new Error(INLINE_BACKEND_ERROR.replace("%s", kind));
|
|
269
|
-
}
|
|
270
|
-
function resolveInlineBackendRootDir(workspaceRoot, configuredRootDir) {
|
|
271
|
-
if (typeof configuredRootDir === "string" && configuredRootDir.trim().length > 0) {
|
|
272
|
-
return path.isAbsolute(configuredRootDir)
|
|
273
|
-
? configuredRootDir
|
|
274
|
-
: path.resolve(workspaceRoot, configuredRootDir);
|
|
275
|
-
}
|
|
276
|
-
return workspaceRoot;
|
|
277
|
-
}
|
|
278
|
-
function createLocalShellStyleBackend(workspaceRoot, config, options) {
|
|
279
|
-
const rootDir = resolveInlineBackendRootDir(workspaceRoot, config?.rootDir);
|
|
280
|
-
mkdirSync(rootDir, { recursive: true });
|
|
281
|
-
const inheritedEnv = config?.inheritEnv === false ? {} : process.env;
|
|
282
|
-
return new WorkspaceScopedBackend(new LocalShellBackend({
|
|
283
|
-
rootDir,
|
|
284
|
-
virtualMode: options.virtualMode,
|
|
285
|
-
timeout: typeof config?.timeout === "number" ? config.timeout : undefined,
|
|
286
|
-
maxOutputBytes: typeof config?.maxOutputBytes === "number" ? config.maxOutputBytes : undefined,
|
|
287
|
-
env: createRuntimeEnv(readStringRecord(config?.env), inheritedEnv),
|
|
288
|
-
inheritEnv: config?.inheritEnv !== false,
|
|
289
|
-
}), rootDir);
|
|
290
|
-
}
|
|
291
|
-
function createInlineBackendInstance(workspaceRoot, kind, config, runtimeLike) {
|
|
292
|
-
switch (kind) {
|
|
293
|
-
case "LocalShellBackend":
|
|
294
|
-
return createLocalShellStyleBackend(workspaceRoot, config, {
|
|
295
|
-
virtualMode: config?.virtualMode === true,
|
|
296
|
-
});
|
|
297
|
-
case "VfsSandbox":
|
|
298
|
-
return createLocalShellStyleBackend(workspaceRoot, config, {
|
|
299
|
-
virtualMode: config?.virtualMode === false ? false : true,
|
|
300
|
-
});
|
|
301
|
-
case "StateBackend":
|
|
302
|
-
return new StateBackend(runtimeLike);
|
|
303
|
-
case "StoreBackend":
|
|
304
|
-
return new StoreBackend(runtimeLike);
|
|
305
|
-
case "LangSmithSandbox":
|
|
306
|
-
return new LazyLangSmithSandbox(config);
|
|
307
|
-
default:
|
|
308
|
-
return unsupportedInlineBackend(kind);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
function createInlineBackendResolver(workspace) {
|
|
312
|
-
return (binding) => {
|
|
313
|
-
const backendConfig = getBindingBackendConfig(binding);
|
|
314
|
-
if (!backendConfig || typeof backendConfig !== "object") {
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
return (runtimeLike) => {
|
|
318
|
-
const kind = typeof backendConfig.kind === "string" ? backendConfig.kind : "CompositeBackend";
|
|
319
|
-
switch (kind) {
|
|
320
|
-
case "LocalShellBackend":
|
|
321
|
-
return createInlineBackendInstance(workspace.workspaceRoot, "LocalShellBackend", backendConfig, runtimeLike);
|
|
322
|
-
case "VfsSandbox":
|
|
323
|
-
return createInlineBackendInstance(workspace.workspaceRoot, "VfsSandbox", backendConfig, runtimeLike);
|
|
324
|
-
case "StateBackend":
|
|
325
|
-
return createInlineBackendInstance(workspace.workspaceRoot, "StateBackend", backendConfig, runtimeLike);
|
|
326
|
-
case "StoreBackend":
|
|
327
|
-
return createInlineBackendInstance(workspace.workspaceRoot, "StoreBackend", backendConfig, runtimeLike);
|
|
328
|
-
case "LangSmithSandbox":
|
|
329
|
-
return createInlineBackendInstance(workspace.workspaceRoot, "LangSmithSandbox", backendConfig, runtimeLike);
|
|
330
|
-
case "CompositeBackend": {
|
|
331
|
-
const stateConfig = typeof backendConfig.state === "object" && backendConfig.state
|
|
332
|
-
? backendConfig.state
|
|
333
|
-
: { kind: "StateBackend" };
|
|
334
|
-
const defaultBackendKind = typeof stateConfig.kind === "string" ? stateConfig.kind : "StateBackend";
|
|
335
|
-
const routes = typeof backendConfig.routes === "object" && backendConfig.routes
|
|
336
|
-
? backendConfig.routes
|
|
337
|
-
: { "/memories/": { kind: "StoreBackend" } };
|
|
338
|
-
const mappedRoutes = Object.fromEntries(Object.entries(routes).map(([route, routeConfig]) => {
|
|
339
|
-
const routeKind = typeof routeConfig?.kind === "string" ? routeConfig.kind : "StoreBackend";
|
|
340
|
-
return [route, createInlineBackendInstance(workspace.workspaceRoot, routeKind, routeConfig, runtimeLike)];
|
|
341
|
-
}));
|
|
342
|
-
return new WorkspaceScopedBackend(new CompatibleCompositeBackend(createInlineBackendInstance(workspace.workspaceRoot, defaultBackendKind, stateConfig, runtimeLike), mappedRoutes), workspace.workspaceRoot);
|
|
343
|
-
}
|
|
344
|
-
default:
|
|
345
|
-
return unsupportedInlineBackend(kind);
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
function requireLocalResource(feature) {
|
|
351
|
-
if (localResource) {
|
|
352
|
-
return localResource;
|
|
353
|
-
}
|
|
354
|
-
throw new Error(`agent-harness optional tool bundle support is unavailable for ${feature}. Install the matching provider package or provide a local sibling checkout.`);
|
|
355
|
-
}
|
|
356
|
-
const remoteResourceCache = new Map();
|
|
357
|
-
async function findPackageRoot(startPath) {
|
|
358
|
-
const resourcePackageRoot = findEnclosingResourcePackageRoot(startPath);
|
|
359
|
-
if (resourcePackageRoot) {
|
|
360
|
-
return resourcePackageRoot;
|
|
361
|
-
}
|
|
362
|
-
let current = path.dirname(startPath);
|
|
363
|
-
for (;;) {
|
|
364
|
-
try {
|
|
365
|
-
await stat(path.join(current, "package.json"));
|
|
366
|
-
return current;
|
|
367
|
-
}
|
|
368
|
-
catch { }
|
|
369
|
-
const parent = path.dirname(current);
|
|
370
|
-
if (parent === current) {
|
|
371
|
-
return path.dirname(startPath);
|
|
372
|
-
}
|
|
373
|
-
current = parent;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
function findEnclosingResourcePackageRoot(startPath) {
|
|
377
|
-
let current = path.dirname(startPath);
|
|
378
|
-
for (;;) {
|
|
379
|
-
const resourcePackageRoot = resolveResourcePackageRoot(current);
|
|
380
|
-
if (resourcePackageRoot && isPathWithinRoot(startPath, resourcePackageRoot)) {
|
|
381
|
-
return resourcePackageRoot;
|
|
382
|
-
}
|
|
383
|
-
const parent = path.dirname(current);
|
|
384
|
-
if (parent === current) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
current = parent;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
function isPathWithinRoot(targetPath, rootPath) {
|
|
391
|
-
const relative = path.relative(rootPath, targetPath);
|
|
392
|
-
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
|
393
|
-
}
|
|
394
|
-
const functionToolModuleCache = new Map();
|
|
395
|
-
function readStringRecord(value) {
|
|
396
|
-
if (typeof value !== "object" || !value) {
|
|
397
|
-
return undefined;
|
|
398
|
-
}
|
|
399
|
-
const entries = Object.entries(value).filter((entry) => typeof entry[1] === "string");
|
|
400
|
-
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
401
|
-
}
|
|
402
|
-
function listWorkspaceResourceProviders(workspace) {
|
|
403
|
-
return (workspace.resources ?? [])
|
|
404
|
-
.map((source) => remoteResourceCache.get(source))
|
|
405
|
-
.filter((provider) => Boolean(provider));
|
|
406
|
-
}
|
|
407
|
-
function createWorkspaceProviderResolvers(workspace, factory) {
|
|
408
|
-
return listWorkspaceResourceProviders(workspace)
|
|
409
|
-
.map((provider) => factory(provider))
|
|
410
|
-
.filter((resolver) => Boolean(resolver));
|
|
411
|
-
}
|
|
412
|
-
function asObject(value) {
|
|
413
|
-
return typeof value === "object" && value !== null ? value : undefined;
|
|
414
|
-
}
|
|
415
|
-
function asStringRecord(value) {
|
|
416
|
-
const record = asObject(value);
|
|
417
|
-
if (!record) {
|
|
418
|
-
return undefined;
|
|
419
|
-
}
|
|
420
|
-
return Object.fromEntries(Object.entries(record).filter((entry) => typeof entry[1] === "string"));
|
|
421
|
-
}
|
|
422
|
-
function asStringArray(value) {
|
|
423
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
424
|
-
}
|
|
425
|
-
const FUNCTION_TOOL_SUBPROCESS_RUNNER_SOURCE = `
|
|
426
|
-
import { pathToFileURL } from "node:url";
|
|
427
|
-
|
|
428
|
-
const TOOL_DEFINITION_MARKER = "__agent_harness_tool_definition__";
|
|
429
|
-
|
|
430
|
-
function isToolDefinitionObject(value) {
|
|
431
|
-
return typeof value === "object" && value !== null && value[TOOL_DEFINITION_MARKER] === true;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function loadToolDefinition(imported, implementationName) {
|
|
435
|
-
for (const [exportName, value] of Object.entries(imported)) {
|
|
436
|
-
if (exportName === "default" || !isToolDefinitionObject(value)) {
|
|
437
|
-
continue;
|
|
438
|
-
}
|
|
439
|
-
const resolvedName = typeof value.name === "string" && value.name.trim() ? value.name.trim() : exportName;
|
|
440
|
-
if (resolvedName === implementationName) {
|
|
441
|
-
return value;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
throw new Error(\`Tool module must export a tool({...}) definition named \${implementationName}.\`);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
const [modulePath, implementationName] = process.argv.slice(1);
|
|
448
|
-
const imported = await import(pathToFileURL(modulePath).href);
|
|
449
|
-
const tool = loadToolDefinition(imported, implementationName);
|
|
450
|
-
let stdin = "";
|
|
451
|
-
for await (const chunk of process.stdin) {
|
|
452
|
-
stdin += String(chunk);
|
|
453
|
-
}
|
|
454
|
-
const payload = stdin.trim() ? JSON.parse(stdin) : {};
|
|
455
|
-
const input = tool.schema && typeof tool.schema.parse === "function"
|
|
456
|
-
? tool.schema.parse(payload.input ?? {})
|
|
457
|
-
: (payload.input ?? {});
|
|
458
|
-
const result = await tool.invoke(input, payload.context ?? {});
|
|
459
|
-
process.stdout.write(typeof result === "string" ? result : JSON.stringify(result));
|
|
460
|
-
`;
|
|
461
|
-
function resolveFunctionToolSubprocessConfig(tool, workspaceRoot, isolatedSourcePath) {
|
|
462
|
-
const execution = asObject(tool.config?.execution);
|
|
463
|
-
if (tool.subprocess !== true) {
|
|
464
|
-
return null;
|
|
465
|
-
}
|
|
466
|
-
const resolvedExecution = execution ?? {};
|
|
467
|
-
const entry = typeof resolvedExecution.entry === "string" && resolvedExecution.entry.trim()
|
|
468
|
-
? path.resolve(workspaceRoot, resolvedExecution.entry)
|
|
469
|
-
: undefined;
|
|
470
|
-
const command = typeof resolvedExecution.command === "string" && resolvedExecution.command.trim()
|
|
471
|
-
? resolvedExecution.command
|
|
472
|
-
: entry
|
|
473
|
-
? process.execPath
|
|
474
|
-
: process.execPath;
|
|
475
|
-
if (!command) {
|
|
476
|
-
throw new Error(`Tool ${tool.id} subprocess execution requires config.execution.command or config.execution.entry`);
|
|
477
|
-
}
|
|
478
|
-
const args = [
|
|
479
|
-
...(entry ? [entry] : ["--input-type=module", "--eval", FUNCTION_TOOL_SUBPROCESS_RUNNER_SOURCE, isolatedSourcePath, tool.implementationName ?? tool.id]),
|
|
480
|
-
...asStringArray(resolvedExecution.args),
|
|
481
|
-
];
|
|
482
|
-
const cwd = typeof resolvedExecution.cwd === "string" && resolvedExecution.cwd.trim()
|
|
483
|
-
? path.resolve(workspaceRoot, resolvedExecution.cwd)
|
|
484
|
-
: workspaceRoot;
|
|
485
|
-
const timeoutMs = Number.isFinite(resolvedExecution.timeoutMs) ? Number(resolvedExecution.timeoutMs) : undefined;
|
|
486
|
-
return {
|
|
487
|
-
command,
|
|
488
|
-
args,
|
|
489
|
-
cwd,
|
|
490
|
-
env: asStringRecord(resolvedExecution.env),
|
|
491
|
-
timeoutMs,
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
async function runFunctionToolInSubprocess(config, input, context) {
|
|
495
|
-
return await new Promise((resolve, reject) => {
|
|
496
|
-
const child = spawn(config.command, config.args, {
|
|
497
|
-
cwd: config.cwd,
|
|
498
|
-
env: createRuntimeEnv(config.env, process.env),
|
|
499
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
500
|
-
});
|
|
501
|
-
let stdout = "";
|
|
502
|
-
let stderr = "";
|
|
503
|
-
let settled = false;
|
|
504
|
-
let timeout;
|
|
505
|
-
const finish = (fn) => {
|
|
506
|
-
if (settled) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
settled = true;
|
|
510
|
-
if (timeout) {
|
|
511
|
-
clearTimeout(timeout);
|
|
512
|
-
}
|
|
513
|
-
fn();
|
|
514
|
-
};
|
|
515
|
-
if (config.timeoutMs && config.timeoutMs > 0) {
|
|
516
|
-
timeout = setTimeout(() => {
|
|
517
|
-
child.kill("SIGTERM");
|
|
518
|
-
finish(() => reject(new Error(`Subprocess tool timed out after ${config.timeoutMs}ms`)));
|
|
519
|
-
}, config.timeoutMs);
|
|
520
|
-
}
|
|
521
|
-
child.stdout.setEncoding("utf8");
|
|
522
|
-
child.stderr.setEncoding("utf8");
|
|
523
|
-
child.stdout.on("data", (chunk) => {
|
|
524
|
-
stdout += chunk;
|
|
525
|
-
});
|
|
526
|
-
child.stderr.on("data", (chunk) => {
|
|
527
|
-
stderr += chunk;
|
|
528
|
-
});
|
|
529
|
-
child.on("error", (error) => {
|
|
530
|
-
finish(() => reject(error));
|
|
531
|
-
});
|
|
532
|
-
child.on("close", (code, signal) => {
|
|
533
|
-
finish(() => {
|
|
534
|
-
if (code === 0) {
|
|
535
|
-
resolve(stdout.trim());
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
const message = stderr.trim() || stdout.trim() || `Subprocess tool exited with code ${code ?? "unknown"}${signal ? ` (${signal})` : ""}`;
|
|
539
|
-
reject(new Error(message));
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
child.stdin.end(JSON.stringify({ input, context }));
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
async function loadFunctionToolModule(tool) {
|
|
546
|
-
const cacheKey = `${tool.sourcePath}:${tool.implementationName ?? tool.id}`;
|
|
547
|
-
const cached = functionToolModuleCache.get(cacheKey);
|
|
548
|
-
if (cached) {
|
|
549
|
-
return cached;
|
|
550
|
-
}
|
|
551
|
-
const loading = (async () => {
|
|
552
|
-
const packageRoot = await findPackageRoot(tool.sourcePath);
|
|
553
|
-
const isolatedSourcePath = await resolveIsolatedResourceModulePath(packageRoot, tool.sourcePath);
|
|
554
|
-
const imported = await import(pathToFileURL(isolatedSourcePath).href);
|
|
555
|
-
const implementationName = tool.implementationName ?? tool.id;
|
|
556
|
-
const loaded = loadToolModuleDefinition(imported, implementationName);
|
|
557
|
-
return {
|
|
558
|
-
invoke: loaded.invoke,
|
|
559
|
-
schema: loaded.schema,
|
|
560
|
-
modelSchema: loaded.modelSchema,
|
|
561
|
-
description: loaded.description,
|
|
562
|
-
isolatedSourcePath,
|
|
563
|
-
implementationName,
|
|
564
|
-
};
|
|
565
|
-
})();
|
|
566
|
-
functionToolModuleCache.set(cacheKey, loading);
|
|
567
|
-
return loading;
|
|
568
|
-
}
|
|
569
|
-
function createFunctionToolResolver(workspace) {
|
|
570
|
-
const functionTools = new Map(Array.from(workspace.tools.values())
|
|
571
|
-
.filter((tool) => tool.type === "function" && isSupportedToolModulePath(tool.sourcePath))
|
|
572
|
-
.map((tool) => [tool.id, tool]));
|
|
573
|
-
return (toolIds, binding) => toolIds.flatMap((toolId) => {
|
|
574
|
-
const tool = functionTools.get(toolId);
|
|
575
|
-
if (!tool) {
|
|
576
|
-
return [];
|
|
577
|
-
}
|
|
578
|
-
return [
|
|
579
|
-
{
|
|
580
|
-
name: tool.name,
|
|
581
|
-
description: tool.description,
|
|
582
|
-
schema: tool.modelSchema,
|
|
583
|
-
modelSchema: tool.modelSchema,
|
|
584
|
-
async invoke(input, config) {
|
|
585
|
-
const loaded = await loadFunctionToolModule(tool);
|
|
586
|
-
const parsedInput = loaded.schema.parse(input ?? {});
|
|
587
|
-
const toolPackageRoot = await findPackageRoot(tool.sourcePath);
|
|
588
|
-
const bindingTool = binding
|
|
589
|
-
? getBindingExecutionView(binding).primaryTools.find((candidate) => candidate.id === tool.id || candidate.name === tool.name)
|
|
590
|
-
: undefined;
|
|
591
|
-
const effectiveEmbeddingModelRef = bindingTool?.embeddingModelRef ?? tool.embeddingModelRef;
|
|
592
|
-
const effectiveSubprocess = bindingTool?.subprocess ?? tool.subprocess;
|
|
593
|
-
const effectiveConfig = bindingTool?.config ?? tool.config;
|
|
594
|
-
const effectiveHitl = bindingTool?.hitl ?? tool.hitl;
|
|
595
|
-
const effectiveRetryable = bindingTool?.retryable ?? tool.retryable;
|
|
596
|
-
const embeddingModel = effectiveEmbeddingModelRef
|
|
597
|
-
? resolveCompiledEmbeddingModelRef(workspace, effectiveEmbeddingModelRef)
|
|
598
|
-
: undefined;
|
|
599
|
-
const model = binding ? getBindingPrimaryModel(binding) : undefined;
|
|
600
|
-
const configurable = typeof config?.configurable === "object" && config.configurable !== null
|
|
601
|
-
? config.configurable
|
|
602
|
-
: {};
|
|
603
|
-
const dynamicToolRuntimeContext = typeof config?.toolRuntimeContext === "object" && config.toolRuntimeContext !== null
|
|
604
|
-
? config.toolRuntimeContext
|
|
605
|
-
: {};
|
|
606
|
-
const baseToolContext = {
|
|
607
|
-
appRoot: workspace.workspaceRoot,
|
|
608
|
-
toolId: tool.id,
|
|
609
|
-
toolPath: tool.sourcePath,
|
|
610
|
-
toolPackageRoot,
|
|
611
|
-
embeddingModel,
|
|
612
|
-
model,
|
|
613
|
-
runtime: {
|
|
614
|
-
workspaceRoot: workspace.workspaceRoot,
|
|
615
|
-
runtimeRoot: binding?.harnessRuntime.runtimeRoot,
|
|
616
|
-
...(typeof configurable[UPSTREAM_SESSION_CONFIG_KEY] === "string"
|
|
617
|
-
? { sessionId: configurable[UPSTREAM_SESSION_CONFIG_KEY] }
|
|
618
|
-
: {}),
|
|
619
|
-
...(typeof configurable[UPSTREAM_REQUEST_CONFIG_KEY] === "string"
|
|
620
|
-
? { requestId: configurable[UPSTREAM_REQUEST_CONFIG_KEY] }
|
|
621
|
-
: {}),
|
|
622
|
-
},
|
|
623
|
-
agent: binding
|
|
624
|
-
? {
|
|
625
|
-
id: binding.agent.id,
|
|
626
|
-
executionMode: binding.agent.executionMode,
|
|
627
|
-
description: binding.agent.description,
|
|
628
|
-
sourcePath: binding.agent.sourcePath,
|
|
629
|
-
}
|
|
630
|
-
: undefined,
|
|
631
|
-
tool: {
|
|
632
|
-
id: tool.id,
|
|
633
|
-
name: tool.name,
|
|
634
|
-
type: tool.type,
|
|
635
|
-
description: tool.description,
|
|
636
|
-
sourcePath: tool.sourcePath,
|
|
637
|
-
packageRoot: toolPackageRoot,
|
|
638
|
-
config: effectiveConfig,
|
|
639
|
-
embeddingModelRef: effectiveEmbeddingModelRef,
|
|
640
|
-
inputSchemaRef: tool.inputSchemaRef,
|
|
641
|
-
retryable: effectiveRetryable,
|
|
642
|
-
hitl: effectiveHitl,
|
|
643
|
-
},
|
|
644
|
-
};
|
|
645
|
-
const subprocessConfig = resolveFunctionToolSubprocessConfig({
|
|
646
|
-
...tool,
|
|
647
|
-
config: effectiveConfig,
|
|
648
|
-
embeddingModelRef: effectiveEmbeddingModelRef,
|
|
649
|
-
hitl: effectiveHitl,
|
|
650
|
-
retryable: effectiveRetryable,
|
|
651
|
-
subprocess: effectiveSubprocess,
|
|
652
|
-
}, workspace.workspaceRoot, loaded.isolatedSourcePath);
|
|
653
|
-
if (subprocessConfig) {
|
|
654
|
-
return runFunctionToolInSubprocess(subprocessConfig, parsedInput, baseToolContext);
|
|
655
|
-
}
|
|
656
|
-
return loaded.invoke(parsedInput, {
|
|
657
|
-
...baseToolContext,
|
|
658
|
-
...dynamicToolRuntimeContext,
|
|
659
|
-
runtime: {
|
|
660
|
-
...(typeof baseToolContext.runtime === "object" && baseToolContext.runtime ? baseToolContext.runtime : {}),
|
|
661
|
-
...(typeof dynamicToolRuntimeContext.runtime === "object" && dynamicToolRuntimeContext.runtime ? dynamicToolRuntimeContext.runtime : {}),
|
|
662
|
-
},
|
|
663
|
-
});
|
|
664
|
-
},
|
|
665
|
-
},
|
|
666
|
-
];
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
function resolvePackageEntry(packageRoot, pkg) {
|
|
670
|
-
const exportsField = pkg.exports;
|
|
671
|
-
if (typeof exportsField === "string") {
|
|
672
|
-
return path.resolve(packageRoot, exportsField);
|
|
673
|
-
}
|
|
674
|
-
if (exportsField && typeof exportsField === "object" && "." in exportsField) {
|
|
675
|
-
const rootExport = exportsField["."];
|
|
676
|
-
if (typeof rootExport === "string") {
|
|
677
|
-
return path.resolve(packageRoot, rootExport);
|
|
678
|
-
}
|
|
679
|
-
if (rootExport && typeof rootExport === "object") {
|
|
680
|
-
const importEntry = rootExport.import ?? rootExport.default;
|
|
681
|
-
if (typeof importEntry === "string") {
|
|
682
|
-
return path.resolve(packageRoot, importEntry);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
if (typeof pkg.module === "string") {
|
|
687
|
-
return path.resolve(packageRoot, pkg.module);
|
|
688
|
-
}
|
|
689
|
-
if (typeof pkg.main === "string") {
|
|
690
|
-
return path.resolve(packageRoot, pkg.main);
|
|
691
|
-
}
|
|
692
|
-
return path.resolve(packageRoot, "index.js");
|
|
693
|
-
}
|
|
694
|
-
async function loadRemoteResource(source, workspaceRoot) {
|
|
695
|
-
const cached = remoteResourceCache.get(source);
|
|
696
|
-
if (cached !== undefined) {
|
|
697
|
-
return cached;
|
|
698
|
-
}
|
|
699
|
-
if (!isExternalSourceLocator(source)) {
|
|
700
|
-
throw new Error(`Unsupported resource source ${source}. Use npm:, tgz:, or file:.`);
|
|
701
|
-
}
|
|
702
|
-
const parsed = parseExternalSourceLocator(source);
|
|
703
|
-
if (parsed.subpath) {
|
|
704
|
-
throw new Error(`Resource source ${source} must point at a package root, not a subpath`);
|
|
705
|
-
}
|
|
706
|
-
await ensureExternalResourceSource(source, workspaceRoot);
|
|
707
|
-
const packageRoot = await ensureExternalSource(source, workspaceRoot);
|
|
708
|
-
const pkg = JSON.parse(await readFile(path.join(packageRoot, "package.json"), "utf8"));
|
|
709
|
-
const entry = resolvePackageEntry(packageRoot, pkg);
|
|
710
|
-
if (!existsSync(entry)) {
|
|
711
|
-
remoteResourceCache.set(source, null);
|
|
712
|
-
return null;
|
|
713
|
-
}
|
|
714
|
-
const imported = await import(pathToFileURL(entry).href);
|
|
715
|
-
const provider = (imported.default ?? imported);
|
|
716
|
-
if (listProviderTools(provider).length === 0 &&
|
|
717
|
-
!provider.listResourceTools &&
|
|
718
|
-
!provider.listBuiltinTools) {
|
|
719
|
-
remoteResourceCache.set(source, null);
|
|
720
|
-
return null;
|
|
721
|
-
}
|
|
722
|
-
if (!provider.createResourceToolResolver && !provider.createBuiltinToolResolver) {
|
|
723
|
-
remoteResourceCache.set(source, null);
|
|
724
|
-
return null;
|
|
725
|
-
}
|
|
726
|
-
const typedProvider = provider;
|
|
727
|
-
remoteResourceCache.set(source, typedProvider);
|
|
728
|
-
return typedProvider;
|
|
729
|
-
}
|
|
730
|
-
export async function ensureResourceSources(sources = [], workspaceRoot = process.cwd()) {
|
|
731
|
-
await Promise.all(sources.map((source) => loadRemoteResource(source, workspaceRoot)));
|
|
732
|
-
}
|
|
733
|
-
function resolveBundledFallbackRoot(kind) {
|
|
734
|
-
const suffix = kind === "skills" ? ["resources", "skills"] : ["config"];
|
|
735
|
-
const candidates = [
|
|
736
|
-
path.resolve(resourceDir, "..", ...suffix),
|
|
737
|
-
path.resolve(resourceDir, "..", "..", ...suffix),
|
|
738
|
-
];
|
|
739
|
-
for (const candidate of candidates) {
|
|
740
|
-
if (existsSync(candidate)) {
|
|
741
|
-
return candidate;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
return null;
|
|
745
|
-
}
|
|
746
|
-
export function defaultResourceSkillsRoot() {
|
|
747
|
-
if (localResource) {
|
|
748
|
-
return preferProviderValue(localResource, (candidate) => candidate.defaultResourceSkillsRoot?.(), (candidate) => candidate.builtinSkillsRoot?.()) ?? "";
|
|
749
|
-
}
|
|
750
|
-
return resolveBundledFallbackRoot("skills") ?? requireLocalResource("default resource skill resolution").defaultResourceSkillsRoot?.() ?? "";
|
|
751
|
-
}
|
|
752
|
-
export function defaultResourceConfigRoot() {
|
|
753
|
-
if (localResource) {
|
|
754
|
-
return (preferProviderValue(localResource, (candidate) => candidate.defaultResourceConfigRoot?.(), (candidate) => candidate.builtinConfigRoot?.() ?? candidate.builtinDefaultsRoot?.()) ?? "");
|
|
755
|
-
}
|
|
756
|
-
return resolveBundledFallbackRoot("config") ?? requireLocalResource("default resource config resolution").defaultResourceConfigRoot?.() ?? "";
|
|
757
|
-
}
|
|
758
|
-
export async function listResourceTools(sources = [], workspaceRoot = process.cwd()) {
|
|
759
|
-
await ensureResourceSources(sources, workspaceRoot);
|
|
760
|
-
const deduped = new Map();
|
|
761
|
-
for (const source of sources) {
|
|
762
|
-
for (const tool of listProviderTools(remoteResourceCache.get(source) ?? undefined)) {
|
|
763
|
-
deduped.set(tool.toolPath, tool);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
return Array.from(deduped.values());
|
|
767
|
-
}
|
|
768
|
-
export async function listResourceToolsForSource(source, workspaceRoot = process.cwd()) {
|
|
769
|
-
await ensureResourceSources([source], workspaceRoot);
|
|
770
|
-
return listProviderTools(remoteResourceCache.get(source) ?? undefined);
|
|
771
|
-
}
|
|
772
|
-
export function createResourceBackendResolver(workspace) {
|
|
773
|
-
const localResolver = createProviderBackendResolver(localResource, workspace);
|
|
774
|
-
const remoteResolvers = createWorkspaceProviderResolvers(workspace, (provider) => createProviderBackendResolver(provider, workspace));
|
|
775
|
-
const inlineResolver = createInlineBackendResolver(workspace);
|
|
776
|
-
return (binding) => {
|
|
777
|
-
const providerResolved = localResolver?.(binding) ??
|
|
778
|
-
remoteResolvers.map((resolver) => resolver(binding)).find((resolved) => resolved !== undefined);
|
|
779
|
-
return providerResolved ?? inlineResolver(binding);
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
export function createResourceToolResolver(workspace, options = {}) {
|
|
783
|
-
const functionResolver = createFunctionToolResolver(workspace);
|
|
784
|
-
const mcpResolver = createMcpToolResolver(workspace);
|
|
785
|
-
const remoteResolvers = createWorkspaceProviderResolvers(workspace, (provider) => createProviderToolResolver(provider, workspace, options));
|
|
786
|
-
return (toolIds, binding) => {
|
|
787
|
-
const resolved = [
|
|
788
|
-
...functionResolver(toolIds, binding),
|
|
789
|
-
...mcpResolver(toolIds, binding),
|
|
790
|
-
...remoteResolvers.flatMap((resolver) => resolver(toolIds, binding)),
|
|
791
|
-
];
|
|
792
|
-
const deduped = new Map();
|
|
793
|
-
for (const tool of resolved) {
|
|
794
|
-
const name = String(tool.name);
|
|
795
|
-
if (!deduped.has(name)) {
|
|
796
|
-
deduped.set(name, tool);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return Array.from(deduped.values());
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
export const ensureBuiltinSources = ensureResourceSources;
|
|
803
|
-
export const builtinSkillsRoot = defaultResourceSkillsRoot;
|
|
804
|
-
export const builtinConfigRoot = defaultResourceConfigRoot;
|
|
805
|
-
export const listBuiltinTools = listResourceTools;
|
|
806
|
-
export const listBuiltinToolsForSource = listResourceToolsForSource;
|
|
807
|
-
export const createBuiltinBackendResolver = createResourceBackendResolver;
|
|
808
|
-
export const createBuiltinToolResolver = createResourceToolResolver;
|
|
809
|
-
export const resolveLocalBuiltinsEntry = resolveLocalResourceProviderEntry;
|
|
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";
|