@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,192 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { createHash } from "node:crypto";
|
|
5
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
7
|
-
import { execFile } from "node:child_process";
|
|
8
|
-
import { promisify } from "node:util";
|
|
9
|
-
import { parse as parseYaml } from "yaml";
|
|
10
|
-
const execFileAsync = promisify(execFile);
|
|
11
|
-
export const DEFAULT_TOOL_SOURCE_URIS = ["file://./resources/tools"];
|
|
12
|
-
export const DEFAULT_SKILL_SOURCE_URIS = ["file://./resources/skills"];
|
|
13
|
-
const require = createRequire(import.meta.url);
|
|
14
|
-
function normalizeSourceList(value, fallback) {
|
|
15
|
-
if (!Array.isArray(value)) {
|
|
16
|
-
return [...fallback];
|
|
17
|
-
}
|
|
18
|
-
return value
|
|
19
|
-
.filter((item) => typeof item === "string" && item.trim().length > 0)
|
|
20
|
-
.map((item) => item.trim());
|
|
21
|
-
}
|
|
22
|
-
export function readRuntimeSources(runtimeDefaults) {
|
|
23
|
-
const rawSources = typeof runtimeDefaults?.sources === "object" && runtimeDefaults.sources && !Array.isArray(runtimeDefaults.sources)
|
|
24
|
-
? runtimeDefaults.sources
|
|
25
|
-
: {};
|
|
26
|
-
return {
|
|
27
|
-
tools: normalizeSourceList(rawSources.tools, DEFAULT_TOOL_SOURCE_URIS),
|
|
28
|
-
skills: normalizeSourceList(rawSources.skills, DEFAULT_SKILL_SOURCE_URIS),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export function isFileSourceUri(value) {
|
|
32
|
-
return value.startsWith("file://");
|
|
33
|
-
}
|
|
34
|
-
export function isNpmSourceUri(value) {
|
|
35
|
-
return value.startsWith("npm://");
|
|
36
|
-
}
|
|
37
|
-
export function isHttpSourceUri(value) {
|
|
38
|
-
return value.startsWith("http://") || value.startsWith("https://");
|
|
39
|
-
}
|
|
40
|
-
export function resolveFileSourcePath(uri, workspaceRoot) {
|
|
41
|
-
if (!isFileSourceUri(uri)) {
|
|
42
|
-
throw new Error(`Unsupported file source URI ${uri}`);
|
|
43
|
-
}
|
|
44
|
-
const rawPath = uri.slice("file://".length).trim();
|
|
45
|
-
if (!rawPath) {
|
|
46
|
-
throw new Error(`File source URI ${uri} must include a path`);
|
|
47
|
-
}
|
|
48
|
-
return path.isAbsolute(rawPath) ? rawPath : path.resolve(workspaceRoot, rawPath);
|
|
49
|
-
}
|
|
50
|
-
function parseToolPackageName(spec, workspaceRoot) {
|
|
51
|
-
if (spec.startsWith("file:")) {
|
|
52
|
-
const localPath = spec.slice("file:".length);
|
|
53
|
-
const resolvedPath = path.isAbsolute(localPath) ? localPath : path.resolve(workspaceRoot, localPath);
|
|
54
|
-
const packageJsonPath = path.join(resolvedPath, "package.json");
|
|
55
|
-
if (!existsSync(packageJsonPath)) {
|
|
56
|
-
throw new Error(`Package tool source ${spec} is missing package.json`);
|
|
57
|
-
}
|
|
58
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
59
|
-
if (typeof packageJson.name !== "string" || packageJson.name.trim().length === 0) {
|
|
60
|
-
throw new Error(`Package tool source ${spec} must define a package.json name`);
|
|
61
|
-
}
|
|
62
|
-
return packageJson.name.trim();
|
|
63
|
-
}
|
|
64
|
-
const match = spec.match(/^(@[^/]+\/[^@/]+|[^@/]+)(?:@.+)?$/);
|
|
65
|
-
if (!match?.[1]) {
|
|
66
|
-
throw new Error(`Unsupported package tool source ${spec}. Use npm://<package-name> or npm://<package-name>@<version>.`);
|
|
67
|
-
}
|
|
68
|
-
return match[1];
|
|
69
|
-
}
|
|
70
|
-
function packageInstallCacheRoot(spec) {
|
|
71
|
-
const digest = createHash("sha256").update(spec).digest("hex").slice(0, 16);
|
|
72
|
-
return path.join(os.tmpdir(), "agent-harness-package-tools", digest);
|
|
73
|
-
}
|
|
74
|
-
function resolvePackageEntry(packageRoot, pkg) {
|
|
75
|
-
const exportsField = pkg.exports;
|
|
76
|
-
if (typeof exportsField === "string") {
|
|
77
|
-
return path.resolve(packageRoot, exportsField);
|
|
78
|
-
}
|
|
79
|
-
if (exportsField && typeof exportsField === "object" && "." in exportsField) {
|
|
80
|
-
const rootExport = exportsField["."];
|
|
81
|
-
if (typeof rootExport === "string") {
|
|
82
|
-
return path.resolve(packageRoot, rootExport);
|
|
83
|
-
}
|
|
84
|
-
if (rootExport && typeof rootExport === "object") {
|
|
85
|
-
const importEntry = rootExport.import ?? rootExport.default;
|
|
86
|
-
if (typeof importEntry === "string") {
|
|
87
|
-
return path.resolve(packageRoot, importEntry);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (typeof pkg.module === "string") {
|
|
92
|
-
return path.resolve(packageRoot, pkg.module);
|
|
93
|
-
}
|
|
94
|
-
if (typeof pkg.main === "string") {
|
|
95
|
-
return path.resolve(packageRoot, pkg.main);
|
|
96
|
-
}
|
|
97
|
-
return path.resolve(packageRoot, "index.js");
|
|
98
|
-
}
|
|
99
|
-
function resolveInstalledPackageRoot(packageName, workspaceRoot) {
|
|
100
|
-
const packageJsonRef = `${packageName}/package.json`;
|
|
101
|
-
const directNodeModulesPath = path.join(workspaceRoot, "node_modules", ...packageName.split("/"), "package.json");
|
|
102
|
-
if (existsSync(directNodeModulesPath)) {
|
|
103
|
-
return path.dirname(directNodeModulesPath);
|
|
104
|
-
}
|
|
105
|
-
for (const candidateRoot of [workspaceRoot, process.cwd()]) {
|
|
106
|
-
try {
|
|
107
|
-
const candidateRequire = createRequire(path.join(candidateRoot, "__agent_harness_package_resolve__.cjs"));
|
|
108
|
-
return path.dirname(candidateRequire.resolve(packageJsonRef));
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
async function installPackageSource(spec, workspaceRoot) {
|
|
117
|
-
const packageName = parseToolPackageName(spec, workspaceRoot);
|
|
118
|
-
const installRoot = packageInstallCacheRoot(spec);
|
|
119
|
-
const packageJsonPath = path.join(installRoot, "package.json");
|
|
120
|
-
await mkdir(installRoot, { recursive: true });
|
|
121
|
-
if (!existsSync(packageJsonPath)) {
|
|
122
|
-
await writeFile(packageJsonPath, `${JSON.stringify({ name: "agent-harness-package-tool-cache", private: true }, null, 2)}\n`, "utf8");
|
|
123
|
-
}
|
|
124
|
-
const installedRoot = path.join(installRoot, "node_modules", ...packageName.split("/"));
|
|
125
|
-
if (!existsSync(path.join(installedRoot, "package.json"))) {
|
|
126
|
-
await execFileAsync("npm", ["install", "--no-save", spec], {
|
|
127
|
-
cwd: installRoot,
|
|
128
|
-
maxBuffer: 1024 * 1024 * 20,
|
|
129
|
-
env: process.env,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
const packageJson = JSON.parse(await readFile(path.join(installedRoot, "package.json"), "utf8"));
|
|
133
|
-
return {
|
|
134
|
-
packageName,
|
|
135
|
-
packageRoot: installedRoot,
|
|
136
|
-
entryPath: resolvePackageEntry(installedRoot, packageJson),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
export async function ensurePackageSource(uri, workspaceRoot) {
|
|
140
|
-
if (!isNpmSourceUri(uri)) {
|
|
141
|
-
throw new Error(`Unsupported package source URI ${uri}`);
|
|
142
|
-
}
|
|
143
|
-
const spec = uri.slice("npm://".length).trim();
|
|
144
|
-
if (!spec) {
|
|
145
|
-
throw new Error(`Package source URI ${uri} must include a package name`);
|
|
146
|
-
}
|
|
147
|
-
const packageName = parseToolPackageName(spec, workspaceRoot);
|
|
148
|
-
const installedRoot = resolveInstalledPackageRoot(packageName, workspaceRoot);
|
|
149
|
-
if (installedRoot && !spec.startsWith("file:") && !spec.includes("@", packageName.startsWith("@") ? packageName.length : 0)) {
|
|
150
|
-
const packageJson = JSON.parse(await readFile(path.join(installedRoot, "package.json"), "utf8"));
|
|
151
|
-
return {
|
|
152
|
-
packageName,
|
|
153
|
-
packageRoot: installedRoot,
|
|
154
|
-
entryPath: resolvePackageEntry(installedRoot, packageJson),
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return installPackageSource(spec, workspaceRoot);
|
|
158
|
-
}
|
|
159
|
-
function parseSkillFrontmatterName(document) {
|
|
160
|
-
const match = document.match(/^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/);
|
|
161
|
-
if (!match?.[1]) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
const parsed = parseYaml(match[1]);
|
|
165
|
-
return typeof parsed?.name === "string" && parsed.name.trim().length > 0 ? parsed.name.trim() : undefined;
|
|
166
|
-
}
|
|
167
|
-
function sanitizeSkillDirName(input) {
|
|
168
|
-
const normalized = input.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
169
|
-
return normalized || "remote-skill";
|
|
170
|
-
}
|
|
171
|
-
function remoteSkillCacheRoot(uri) {
|
|
172
|
-
const digest = createHash("sha256").update(uri).digest("hex").slice(0, 16);
|
|
173
|
-
return path.join(os.tmpdir(), "agent-harness-remote-skills", digest);
|
|
174
|
-
}
|
|
175
|
-
export async function ensureRemoteSkillSource(uri) {
|
|
176
|
-
if (!isHttpSourceUri(uri)) {
|
|
177
|
-
throw new Error(`Unsupported remote skill source ${uri}`);
|
|
178
|
-
}
|
|
179
|
-
const response = await fetch(uri);
|
|
180
|
-
if (!response.ok) {
|
|
181
|
-
throw new Error(`Remote skill source ${uri} returned ${response.status}`);
|
|
182
|
-
}
|
|
183
|
-
const document = await response.text();
|
|
184
|
-
const skillName = sanitizeSkillDirName(parseSkillFrontmatterName(document)
|
|
185
|
-
?? path.basename(new URL(uri).pathname).replace(/\.md$/i, "")
|
|
186
|
-
?? "remote-skill");
|
|
187
|
-
const cacheRoot = remoteSkillCacheRoot(uri);
|
|
188
|
-
const skillRoot = path.join(cacheRoot, skillName);
|
|
189
|
-
await mkdir(skillRoot, { recursive: true });
|
|
190
|
-
await writeFile(path.join(skillRoot, "SKILL.md"), document, "utf8");
|
|
191
|
-
return skillRoot;
|
|
192
|
-
}
|
|
1
|
+
import{createRequire as l}from"node:module";import u from"node:os";import n from"node:path";import{createHash as m}from"node:crypto";import{existsSync as c,readFileSync as w}from"node:fs";import{mkdir as p,readFile as f,writeFile as h}from"node:fs/promises";import{execFile as y}from"node:child_process";import{promisify as S}from"node:util";import{parse as j}from"yaml";const x=S(y),v=["file://./resources/tools"],U=["file://./resources/skills"],H=l(import.meta.url);function d(e,r){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim().length>0).map(t=>t.trim()):[...r]}function K(e){const r=typeof e?.sources=="object"&&e.sources&&!Array.isArray(e.sources)?e.sources:{};return{tools:d(r.tools,v),skills:d(r.skills,U)}}function R(e){return e.startsWith("file://")}function P(e){return e.startsWith("npm://")}function E(e){return e.startsWith("http://")||e.startsWith("https://")}function B(e,r){if(!R(e))throw new Error(`Unsupported file source URI ${e}`);const t=e.slice(7).trim();if(!t)throw new Error(`File source URI ${e} must include a path`);return n.isAbsolute(t)?t:n.resolve(r,t)}function g(e,r){if(e.startsWith("file:")){const o=e.slice(5),s=n.isAbsolute(o)?o:n.resolve(r,o),a=n.join(s,"package.json");if(!c(a))throw new Error(`Package tool source ${e} is missing package.json`);const i=JSON.parse(w(a,"utf8"));if(typeof i.name!="string"||i.name.trim().length===0)throw new Error(`Package tool source ${e} must define a package.json name`);return i.name.trim()}const t=e.match(/^(@[^/]+\/[^@/]+|[^@/]+)(?:@.+)?$/);if(!t?.[1])throw new Error(`Unsupported package tool source ${e}. Use npm://<package-name> or npm://<package-name>@<version>.`);return t[1]}function $(e){const r=m("sha256").update(e).digest("hex").slice(0,16);return n.join(u.tmpdir(),"agent-harness-package-tools",r)}function k(e,r){const t=r.exports;if(typeof t=="string")return n.resolve(e,t);if(t&&typeof t=="object"&&"."in t){const o=t["."];if(typeof o=="string")return n.resolve(e,o);if(o&&typeof o=="object"){const s=o.import??o.default;if(typeof s=="string")return n.resolve(e,s)}}return typeof r.module=="string"?n.resolve(e,r.module):typeof r.main=="string"?n.resolve(e,r.main):n.resolve(e,"index.js")}function _(e,r){const t=`${e}/package.json`,o=n.join(r,"node_modules",...e.split("/"),"package.json");if(c(o))return n.dirname(o);for(const s of[r,process.cwd()])try{const a=l(n.join(s,"__agent_harness_package_resolve__.cjs"));return n.dirname(a.resolve(t))}catch{continue}return null}async function F(e,r){const t=g(e,r),o=$(e),s=n.join(o,"package.json");await p(o,{recursive:!0}),c(s)||await h(s,`${JSON.stringify({name:"agent-harness-package-tool-cache",private:!0},null,2)}
|
|
2
|
+
`,"utf8");const a=n.join(o,"node_modules",...t.split("/"));c(n.join(a,"package.json"))||await x("npm",["install","--no-save",e],{cwd:o,maxBuffer:1024*1024*20,env:process.env});const i=JSON.parse(await f(n.join(a,"package.json"),"utf8"));return{packageName:t,packageRoot:a,entryPath:k(a,i)}}async function M(e,r){if(!P(e))throw new Error(`Unsupported package source URI ${e}`);const t=e.slice(6).trim();if(!t)throw new Error(`Package source URI ${e} must include a package name`);const o=g(t,r),s=_(o,r);if(s&&!t.startsWith("file:")&&!t.includes("@",o.startsWith("@")?o.length:0)){const a=JSON.parse(await f(n.join(s,"package.json"),"utf8"));return{packageName:o,packageRoot:s,entryPath:k(s,a)}}return F(t,r)}function N(e){const r=e.match(/^---\s*\n([\s\S]*?)\n---\s*(?:\n|$)/);if(!r?.[1])return;const t=j(r[1]);return typeof t?.name=="string"&&t.name.trim().length>0?t.name.trim():void 0}function I(e){return e.trim().toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"remote-skill"}function J(e){const r=m("sha256").update(e).digest("hex").slice(0,16);return n.join(u.tmpdir(),"agent-harness-remote-skills",r)}async function Y(e){if(!E(e))throw new Error(`Unsupported remote skill source ${e}`);const r=await fetch(e);if(!r.ok)throw new Error(`Remote skill source ${e} returned ${r.status}`);const t=await r.text(),o=I(N(t)??n.basename(new URL(e).pathname).replace(/\.md$/i,"")??"remote-skill"),s=J(e),a=n.join(s,o);return await p(a,{recursive:!0}),await h(n.join(a,"SKILL.md"),t,"utf8"),a}export{U as DEFAULT_SKILL_SOURCE_URIS,v as DEFAULT_TOOL_SOURCE_URIS,M as ensurePackageSource,Y as ensureRemoteSkillSource,R as isFileSourceUri,E as isHttpSourceUri,P as isNpmSourceUri,K as readRuntimeSources,B as resolveFileSourcePath};
|
|
@@ -1,362 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { readRuntimeSources } from "./source-protocols.js";
|
|
4
|
-
function getRoutingObject(refs) {
|
|
5
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
6
|
-
return typeof runtimeDefaults?.routing === "object" && runtimeDefaults.routing
|
|
7
|
-
? runtimeDefaults.routing
|
|
8
|
-
: undefined;
|
|
9
|
-
}
|
|
10
|
-
export function getWorkspaceObject(refs, ref) {
|
|
11
|
-
if (!ref) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const object = refs.get(ref);
|
|
15
|
-
if (!object || "executionMode" in object) {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
return object;
|
|
19
|
-
}
|
|
20
|
-
export function getRuntimeDefaults(refs) {
|
|
21
|
-
const runtimes = Array.from(refs.values()).filter((object) => !("executionMode" in object) && object.kind === "runtime");
|
|
22
|
-
if (runtimes.length === 0) {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
if (runtimes.length > 1) {
|
|
26
|
-
throw new Error(`Expected at most one Runtime object, found ${runtimes.length}`);
|
|
27
|
-
}
|
|
28
|
-
return runtimes[0].value;
|
|
29
|
-
}
|
|
30
|
-
function mergeConfigValue(base, override) {
|
|
31
|
-
if (override === undefined) {
|
|
32
|
-
return base;
|
|
33
|
-
}
|
|
34
|
-
if (typeof base === "object" &&
|
|
35
|
-
base &&
|
|
36
|
-
typeof override === "object" &&
|
|
37
|
-
override &&
|
|
38
|
-
!Array.isArray(base) &&
|
|
39
|
-
!Array.isArray(override)) {
|
|
40
|
-
const merged = { ...base };
|
|
41
|
-
for (const [key, value] of Object.entries(override)) {
|
|
42
|
-
merged[key] = key in merged ? mergeConfigValue(merged[key], value) : value;
|
|
43
|
-
}
|
|
44
|
-
return merged;
|
|
45
|
-
}
|
|
46
|
-
return override;
|
|
47
|
-
}
|
|
48
|
-
export function getRuntimeAgentDefaults(refs) {
|
|
49
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
50
|
-
const defaults = typeof runtimeDefaults?.defaults === "object" && runtimeDefaults.defaults && !Array.isArray(runtimeDefaults.defaults)
|
|
51
|
-
? runtimeDefaults.defaults
|
|
52
|
-
: undefined;
|
|
53
|
-
const agentDefaults = typeof defaults?.agent === "object" && defaults.agent && !Array.isArray(defaults.agent)
|
|
54
|
-
? defaults.agent
|
|
55
|
-
: undefined;
|
|
56
|
-
const agentConfig = typeof agentDefaults?.config === "object" && agentDefaults.config && !Array.isArray(agentDefaults.config)
|
|
57
|
-
? agentDefaults.config
|
|
58
|
-
: undefined;
|
|
59
|
-
const inlineAgentDefaults = typeof runtimeDefaults?.agent === "object" && runtimeDefaults.agent && !Array.isArray(runtimeDefaults.agent)
|
|
60
|
-
? runtimeDefaults.agent
|
|
61
|
-
: undefined;
|
|
62
|
-
const inlineAgentConfig = typeof inlineAgentDefaults?.config === "object" && inlineAgentDefaults.config && !Array.isArray(inlineAgentDefaults.config)
|
|
63
|
-
? inlineAgentDefaults.config
|
|
64
|
-
: undefined;
|
|
65
|
-
const merged = mergeConfigValue(agentConfig, inlineAgentConfig);
|
|
66
|
-
return typeof merged === "object" && merged && !Array.isArray(merged)
|
|
67
|
-
? merged
|
|
68
|
-
: undefined;
|
|
69
|
-
}
|
|
70
|
-
function asNonEmptyString(value) {
|
|
71
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
72
|
-
}
|
|
73
|
-
export function getRuntimeStorageRoots(refs, workspaceRoot) {
|
|
74
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
75
|
-
const configuredApplicationRoot = asNonEmptyString(runtimeDefaults?.applicationRoot);
|
|
76
|
-
const configuredDataRoot = asNonEmptyString(runtimeDefaults?.dataRoot);
|
|
77
|
-
const configuredProfile = asNonEmptyString(runtimeDefaults?.profile);
|
|
78
|
-
const applicationRoot = configuredApplicationRoot
|
|
79
|
-
? (path.isAbsolute(configuredApplicationRoot)
|
|
80
|
-
? configuredApplicationRoot
|
|
81
|
-
: path.resolve(workspaceRoot, configuredApplicationRoot))
|
|
82
|
-
: workspaceRoot;
|
|
83
|
-
const dataRoot = configuredDataRoot
|
|
84
|
-
? (path.isAbsolute(configuredDataRoot)
|
|
85
|
-
? configuredDataRoot
|
|
86
|
-
: path.resolve(applicationRoot, configuredDataRoot))
|
|
87
|
-
: path.join(applicationRoot, ".botbotgo");
|
|
88
|
-
const runtimeProfile = configuredProfile ?? "default";
|
|
89
|
-
return {
|
|
90
|
-
applicationRoot,
|
|
91
|
-
dataRoot,
|
|
92
|
-
runtimeProfile,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
export function getRuntimeResources(refs) {
|
|
96
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
97
|
-
if (!Array.isArray(runtimeDefaults?.resources)) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
return runtimeDefaults.resources
|
|
101
|
-
.filter((value) => typeof value === "string" && value.trim().length > 0)
|
|
102
|
-
.map((value) => value.trim());
|
|
103
|
-
}
|
|
104
|
-
export function getRuntimeSources(refs) {
|
|
105
|
-
return readRuntimeSources(getRuntimeDefaults(refs));
|
|
106
|
-
}
|
|
107
|
-
export function getToolModuleDiscoveryConfig(refs) {
|
|
108
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
109
|
-
const toolModuleDiscovery = typeof runtimeDefaults?.toolModuleDiscovery === "object" && runtimeDefaults.toolModuleDiscovery
|
|
110
|
-
? runtimeDefaults.toolModuleDiscovery
|
|
111
|
-
: {};
|
|
112
|
-
return {
|
|
113
|
-
scope: toolModuleDiscovery.scope === "top-level" ? "top-level" : "recursive",
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
export function getRuntimeMemoryDefaults(refs) {
|
|
117
|
-
const runtimeMemories = Array.from(refs.values()).filter((object) => !("executionMode" in object) && object.kind === "runtime-memory");
|
|
118
|
-
if (runtimeMemories.length === 0) {
|
|
119
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
120
|
-
return typeof runtimeDefaults?.runtimeMemory === "object" && runtimeDefaults.runtimeMemory && !Array.isArray(runtimeDefaults.runtimeMemory)
|
|
121
|
-
? runtimeDefaults.runtimeMemory
|
|
122
|
-
: undefined;
|
|
123
|
-
}
|
|
124
|
-
if (runtimeMemories.length > 1) {
|
|
125
|
-
throw new Error(`Expected at most one RuntimeMemory object, found ${runtimeMemories.length}`);
|
|
126
|
-
}
|
|
127
|
-
return runtimeMemories[0].value;
|
|
128
|
-
}
|
|
129
|
-
export function getProceduralMemoryDefaults(refs) {
|
|
130
|
-
const proceduralMemories = Array.from(refs.values()).filter((object) => !("executionMode" in object) && object.kind === "procedural-memory");
|
|
131
|
-
if (proceduralMemories.length === 0) {
|
|
132
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
133
|
-
return typeof runtimeDefaults?.proceduralMemory === "object" &&
|
|
134
|
-
runtimeDefaults.proceduralMemory &&
|
|
135
|
-
!Array.isArray(runtimeDefaults.proceduralMemory)
|
|
136
|
-
? runtimeDefaults.proceduralMemory
|
|
137
|
-
: undefined;
|
|
138
|
-
}
|
|
139
|
-
if (proceduralMemories.length > 1) {
|
|
140
|
-
throw new Error(`Expected at most one ProceduralMemoryRuntime object, found ${proceduralMemories.length}`);
|
|
141
|
-
}
|
|
142
|
-
return proceduralMemories[0].value;
|
|
143
|
-
}
|
|
144
|
-
export function getRecoveryConfig(refs) {
|
|
145
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
146
|
-
const recovery = typeof runtimeDefaults?.recovery === "object" && runtimeDefaults.recovery
|
|
147
|
-
? runtimeDefaults.recovery
|
|
148
|
-
: {};
|
|
149
|
-
const maxRecoveryAttempts = typeof recovery.maxRecoveryAttempts === "number" &&
|
|
150
|
-
Number.isFinite(recovery.maxRecoveryAttempts) &&
|
|
151
|
-
recovery.maxRecoveryAttempts > 0
|
|
152
|
-
? Math.floor(recovery.maxRecoveryAttempts)
|
|
153
|
-
: 3;
|
|
154
|
-
return {
|
|
155
|
-
enabled: recovery.enabled !== false,
|
|
156
|
-
resumeResumingRequestsOnStartup: typeof recovery.resumeResumingRequestsOnStartup === "boolean"
|
|
157
|
-
? recovery.resumeResumingRequestsOnStartup
|
|
158
|
-
: true,
|
|
159
|
-
maxRecoveryAttempts,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
export function getConcurrencyConfig(refs) {
|
|
163
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
164
|
-
const concurrency = typeof runtimeDefaults?.concurrency === "object" && runtimeDefaults.concurrency
|
|
165
|
-
? runtimeDefaults.concurrency
|
|
166
|
-
: {};
|
|
167
|
-
const maxConcurrentRuns = typeof concurrency.maxConcurrentRuns === "number" &&
|
|
168
|
-
Number.isFinite(concurrency.maxConcurrentRuns) &&
|
|
169
|
-
concurrency.maxConcurrentRuns > 0
|
|
170
|
-
? Math.floor(concurrency.maxConcurrentRuns)
|
|
171
|
-
: 3;
|
|
172
|
-
const leaseMs = typeof concurrency.leaseMs === "number" &&
|
|
173
|
-
Number.isFinite(concurrency.leaseMs) &&
|
|
174
|
-
concurrency.leaseMs > 0
|
|
175
|
-
? Math.floor(concurrency.leaseMs)
|
|
176
|
-
: 30_000;
|
|
177
|
-
const heartbeatIntervalMs = typeof concurrency.heartbeatIntervalMs === "number" &&
|
|
178
|
-
Number.isFinite(concurrency.heartbeatIntervalMs) &&
|
|
179
|
-
concurrency.heartbeatIntervalMs > 0
|
|
180
|
-
? Math.floor(concurrency.heartbeatIntervalMs)
|
|
181
|
-
: 5_000;
|
|
182
|
-
const heartbeatTimeoutMs = typeof concurrency.heartbeatTimeoutMs === "number" &&
|
|
183
|
-
Number.isFinite(concurrency.heartbeatTimeoutMs) &&
|
|
184
|
-
concurrency.heartbeatTimeoutMs > 0
|
|
185
|
-
? Math.floor(concurrency.heartbeatTimeoutMs)
|
|
186
|
-
: Math.max(leaseMs, heartbeatIntervalMs * 3);
|
|
187
|
-
return {
|
|
188
|
-
maxConcurrentRuns,
|
|
189
|
-
leaseMs,
|
|
190
|
-
heartbeatIntervalMs,
|
|
191
|
-
heartbeatTimeoutMs,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
export function getResilienceConfig(refs) {
|
|
195
|
-
const runtimeDefaults = getRuntimeDefaults(refs);
|
|
196
|
-
const resilience = typeof runtimeDefaults?.resilience === "object" && runtimeDefaults.resilience
|
|
197
|
-
? runtimeDefaults.resilience
|
|
198
|
-
: {};
|
|
199
|
-
const providerRetries = typeof resilience.providerRetries === "object" && resilience.providerRetries
|
|
200
|
-
? resilience.providerRetries
|
|
201
|
-
: {};
|
|
202
|
-
const maxAttempts = typeof providerRetries.maxAttempts === "number" &&
|
|
203
|
-
Number.isFinite(providerRetries.maxAttempts) &&
|
|
204
|
-
providerRetries.maxAttempts > 0
|
|
205
|
-
? Math.floor(providerRetries.maxAttempts)
|
|
206
|
-
: 2;
|
|
207
|
-
const backoffMs = typeof providerRetries.backoffMs === "number" &&
|
|
208
|
-
Number.isFinite(providerRetries.backoffMs) &&
|
|
209
|
-
providerRetries.backoffMs >= 0
|
|
210
|
-
? Math.floor(providerRetries.backoffMs)
|
|
211
|
-
: 1_000;
|
|
212
|
-
const retryableMessages = Array.isArray(providerRetries.retryableMessages)
|
|
213
|
-
? providerRetries.retryableMessages
|
|
214
|
-
.filter((value) => typeof value === "string" && value.trim().length > 0)
|
|
215
|
-
.map((value) => value.trim())
|
|
216
|
-
: [
|
|
217
|
-
"connection error",
|
|
218
|
-
"network error",
|
|
219
|
-
"fetch failed",
|
|
220
|
-
"socket hang up",
|
|
221
|
-
"econnreset",
|
|
222
|
-
"timed out",
|
|
223
|
-
];
|
|
224
|
-
return {
|
|
225
|
-
providerRetries: {
|
|
226
|
-
maxAttempts,
|
|
227
|
-
backoffMs,
|
|
228
|
-
retryableMessages,
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
export function getRoutingDefaultAgentId(refs) {
|
|
233
|
-
const routing = getRoutingObject(refs);
|
|
234
|
-
return typeof routing?.defaultAgentId === "string" && routing.defaultAgentId.trim()
|
|
235
|
-
? routing.defaultAgentId.trim()
|
|
236
|
-
: undefined;
|
|
237
|
-
}
|
|
238
|
-
function toStringList(value) {
|
|
239
|
-
if (typeof value === "string" && value.trim()) {
|
|
240
|
-
return [value];
|
|
241
|
-
}
|
|
242
|
-
if (!Array.isArray(value)) {
|
|
243
|
-
return undefined;
|
|
244
|
-
}
|
|
245
|
-
const items = value
|
|
246
|
-
.filter((item) => typeof item === "string" && item.trim().length > 0)
|
|
247
|
-
.map((item) => item.trim());
|
|
248
|
-
return items.length > 0 ? items : undefined;
|
|
249
|
-
}
|
|
250
|
-
function toPositiveNumber(value) {
|
|
251
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
252
|
-
}
|
|
253
|
-
export function getRoutingRules(refs) {
|
|
254
|
-
const routing = getRoutingObject(refs);
|
|
255
|
-
if (!Array.isArray(routing?.rules)) {
|
|
256
|
-
return [];
|
|
257
|
-
}
|
|
258
|
-
return routing.rules.flatMap((rule, index) => {
|
|
259
|
-
if (typeof rule !== "object" || rule === null || Array.isArray(rule)) {
|
|
260
|
-
throw new Error(`Runtime routing.rules[${index}] must be an object`);
|
|
261
|
-
}
|
|
262
|
-
const typed = rule;
|
|
263
|
-
if (typeof typed.agentId !== "string" || !typed.agentId.trim()) {
|
|
264
|
-
throw new Error(`Runtime routing.rules[${index}] requires a non-empty agentId`);
|
|
265
|
-
}
|
|
266
|
-
const regex = toStringList(typed.regex);
|
|
267
|
-
if (regex) {
|
|
268
|
-
for (const pattern of regex) {
|
|
269
|
-
try {
|
|
270
|
-
new RegExp(pattern);
|
|
271
|
-
}
|
|
272
|
-
catch (error) {
|
|
273
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
274
|
-
throw new Error(`Runtime routing.rules[${index}] has invalid regex ${JSON.stringify(pattern)}: ${detail}`);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return [{
|
|
279
|
-
agentId: typed.agentId.trim(),
|
|
280
|
-
equals: toStringList(typed.equals),
|
|
281
|
-
startsWith: toStringList(typed.startsWith),
|
|
282
|
-
contains: toStringList(typed.contains),
|
|
283
|
-
regex,
|
|
284
|
-
minLength: toPositiveNumber(typed.minLength),
|
|
285
|
-
maxLength: toPositiveNumber(typed.maxLength),
|
|
286
|
-
minLines: toPositiveNumber(typed.minLines),
|
|
287
|
-
maxLines: toPositiveNumber(typed.maxLines),
|
|
288
|
-
hasSessionId: typeof typed.hasSessionId === "boolean" ? typed.hasSessionId : undefined,
|
|
289
|
-
caseSensitive: typed.caseSensitive === true,
|
|
290
|
-
}];
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
export function matchRoutingRule(input, rule, options = {}) {
|
|
294
|
-
const text = input.trim();
|
|
295
|
-
const source = rule.caseSensitive ? text : text.toLowerCase();
|
|
296
|
-
const lineCount = text ? text.split(/\n+/).length : 0;
|
|
297
|
-
const normalize = (value) => (rule.caseSensitive ? value : value.toLowerCase());
|
|
298
|
-
const sessionId = options.sessionId ?? options.legacySessionId;
|
|
299
|
-
if (rule.hasSessionId !== undefined && rule.hasSessionId !== Boolean(sessionId)) {
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
if (rule.minLength !== undefined && text.length < rule.minLength) {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
if (rule.maxLength !== undefined && text.length > rule.maxLength) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (rule.minLines !== undefined && lineCount < rule.minLines) {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
if (rule.maxLines !== undefined && lineCount > rule.maxLines) {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
if (rule.equals && !rule.equals.some((candidate) => source === normalize(candidate.trim()))) {
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
if (rule.startsWith && !rule.startsWith.some((candidate) => source.startsWith(normalize(candidate.trim())))) {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
if (rule.contains && !rule.contains.some((candidate) => source.includes(normalize(candidate.trim())))) {
|
|
321
|
-
return false;
|
|
322
|
-
}
|
|
323
|
-
if (rule.regex && !rule.regex.some((pattern) => new RegExp(pattern, rule.caseSensitive ? undefined : "i").test(text))) {
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
return true;
|
|
327
|
-
}
|
|
328
|
-
export function resolvePromptValue(promptConfig, baseDir) {
|
|
329
|
-
if (typeof promptConfig === "string" && promptConfig.trim()) {
|
|
330
|
-
return promptConfig;
|
|
331
|
-
}
|
|
332
|
-
if (typeof promptConfig === "object" && promptConfig !== null && !Array.isArray(promptConfig)) {
|
|
333
|
-
const promptPath = typeof promptConfig.path === "string"
|
|
334
|
-
? promptConfig.path
|
|
335
|
-
: undefined;
|
|
336
|
-
if (promptPath?.trim()) {
|
|
337
|
-
const resolvedPath = baseDir && !path.isAbsolute(promptPath) ? path.resolve(baseDir, promptPath) : promptPath;
|
|
338
|
-
return readFileSync(resolvedPath, "utf8");
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return undefined;
|
|
342
|
-
}
|
|
343
|
-
export function resolveRefId(ref) {
|
|
344
|
-
const [namespace, ...rest] = ref.split("/");
|
|
345
|
-
if (rest.length === 0) {
|
|
346
|
-
return ref;
|
|
347
|
-
}
|
|
348
|
-
if (["agent", "embedding-model", "mcp", "model", "object", "procedural-memory", "prompt", "runtime", "runtime-memory", "tool", "vector-store"].includes(namespace)) {
|
|
349
|
-
return rest.join("/");
|
|
350
|
-
}
|
|
351
|
-
return ref;
|
|
352
|
-
}
|
|
353
|
-
export function resolvePathList(refs, workspaceRoot, refList) {
|
|
354
|
-
return refList.map((ref) => {
|
|
355
|
-
const object = getWorkspaceObject(refs, ref);
|
|
356
|
-
const maybePath = typeof object?.value.path === "string" ? object.value.path : resolveRefId(ref);
|
|
357
|
-
return path.isAbsolute(maybePath) ? maybePath : path.resolve(workspaceRoot, maybePath);
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
export function compileAgentMemories(workspaceRoot, sources) {
|
|
361
|
-
return sources.map((source) => (path.isAbsolute(source) ? source : path.resolve(workspaceRoot, source)));
|
|
362
|
-
}
|
|
1
|
+
import{readFileSync as p}from"node:fs";import c from"node:path";import{readRuntimeSources as h}from"./source-protocols.js";function g(n){const e=f(n);return typeof e?.routing=="object"&&e.routing?e.routing:void 0}function b(n,e){if(!e)return;const t=n.get(e);if(!(!t||"executionMode"in t))return t}function f(n){const e=Array.from(n.values()).filter(t=>!("executionMode"in t)&&t.kind==="runtime");if(e.length!==0){if(e.length>1)throw new Error(`Expected at most one Runtime object, found ${e.length}`);return e[0].value}}function y(n,e){if(e===void 0)return n;if(typeof n=="object"&&n&&typeof e=="object"&&e&&!Array.isArray(n)&&!Array.isArray(e)){const t={...n};for(const[r,o]of Object.entries(e))t[r]=r in t?y(t[r],o):o;return t}return e}function v(n){const e=f(n),t=typeof e?.defaults=="object"&&e.defaults&&!Array.isArray(e.defaults)?e.defaults:void 0,r=typeof t?.agent=="object"&&t.agent&&!Array.isArray(t.agent)?t.agent:void 0,o=typeof r?.config=="object"&&r.config&&!Array.isArray(r.config)?r.config:void 0,i=typeof e?.agent=="object"&&e.agent&&!Array.isArray(e.agent)?e.agent:void 0,u=typeof i?.config=="object"&&i.config&&!Array.isArray(i.config)?i.config:void 0,s=y(o,u);return typeof s=="object"&&s&&!Array.isArray(s)?s:void 0}function d(n){return typeof n=="string"&&n.trim().length>0?n.trim():void 0}function j(n,e){const t=f(n),r=d(t?.applicationRoot),o=d(t?.dataRoot),i=d(t?.profile),u=r?c.isAbsolute(r)?r:c.resolve(e,r):e,s=o?c.isAbsolute(o)?o:c.resolve(u,o):c.join(u,".botbotgo");return{applicationRoot:u,dataRoot:s,runtimeProfile:i??"default"}}function D(n){const e=f(n);return Array.isArray(e?.resources)?e.resources.filter(t=>typeof t=="string"&&t.trim().length>0).map(t=>t.trim()):[]}function I(n){return h(f(n))}function S(n){const e=f(n);return{scope:(typeof e?.toolModuleDiscovery=="object"&&e.toolModuleDiscovery?e.toolModuleDiscovery:{}).scope==="top-level"?"top-level":"recursive"}}function L(n){const e=Array.from(n.values()).filter(t=>!("executionMode"in t)&&t.kind==="runtime-memory");if(e.length===0){const t=f(n);return typeof t?.runtimeMemory=="object"&&t.runtimeMemory&&!Array.isArray(t.runtimeMemory)?t.runtimeMemory:void 0}if(e.length>1)throw new Error(`Expected at most one RuntimeMemory object, found ${e.length}`);return e[0].value}function w(n){const e=Array.from(n.values()).filter(t=>!("executionMode"in t)&&t.kind==="procedural-memory");if(e.length===0){const t=f(n);return typeof t?.proceduralMemory=="object"&&t.proceduralMemory&&!Array.isArray(t.proceduralMemory)?t.proceduralMemory:void 0}if(e.length>1)throw new Error(`Expected at most one ProceduralMemoryRuntime object, found ${e.length}`);return e[0].value}function E(n){const e=f(n),t=typeof e?.recovery=="object"&&e.recovery?e.recovery:{},r=typeof t.maxRecoveryAttempts=="number"&&Number.isFinite(t.maxRecoveryAttempts)&&t.maxRecoveryAttempts>0?Math.floor(t.maxRecoveryAttempts):3;return{enabled:t.enabled!==!1,resumeResumingRequestsOnStartup:typeof t.resumeResumingRequestsOnStartup=="boolean"?t.resumeResumingRequestsOnStartup:!0,maxRecoveryAttempts:r}}function k(n){const e=f(n),t=typeof e?.concurrency=="object"&&e.concurrency?e.concurrency:{},r=typeof t.maxConcurrentRuns=="number"&&Number.isFinite(t.maxConcurrentRuns)&&t.maxConcurrentRuns>0?Math.floor(t.maxConcurrentRuns):3,o=typeof t.leaseMs=="number"&&Number.isFinite(t.leaseMs)&&t.leaseMs>0?Math.floor(t.leaseMs):3e4,i=typeof t.heartbeatIntervalMs=="number"&&Number.isFinite(t.heartbeatIntervalMs)&&t.heartbeatIntervalMs>0?Math.floor(t.heartbeatIntervalMs):5e3,u=typeof t.heartbeatTimeoutMs=="number"&&Number.isFinite(t.heartbeatTimeoutMs)&&t.heartbeatTimeoutMs>0?Math.floor(t.heartbeatTimeoutMs):Math.max(o,i*3);return{maxConcurrentRuns:r,leaseMs:o,heartbeatIntervalMs:i,heartbeatTimeoutMs:u}}function N(n){const e=f(n),t=typeof e?.resilience=="object"&&e.resilience?e.resilience:{},r=typeof t.providerRetries=="object"&&t.providerRetries?t.providerRetries:{},o=typeof r.maxAttempts=="number"&&Number.isFinite(r.maxAttempts)&&r.maxAttempts>0?Math.floor(r.maxAttempts):2,i=typeof r.backoffMs=="number"&&Number.isFinite(r.backoffMs)&&r.backoffMs>=0?Math.floor(r.backoffMs):1e3,u=Array.isArray(r.retryableMessages)?r.retryableMessages.filter(s=>typeof s=="string"&&s.trim().length>0).map(s=>s.trim()):["connection error","network error","fetch failed","socket hang up","econnreset","timed out"];return{providerRetries:{maxAttempts:o,backoffMs:i,retryableMessages:u}}}function P(n){const e=g(n);return typeof e?.defaultAgentId=="string"&&e.defaultAgentId.trim()?e.defaultAgentId.trim():void 0}function m(n){if(typeof n=="string"&&n.trim())return[n];if(!Array.isArray(n))return;const e=n.filter(t=>typeof t=="string"&&t.trim().length>0).map(t=>t.trim());return e.length>0?e:void 0}function l(n){return typeof n=="number"&&Number.isFinite(n)&&n>=0?n:void 0}function C(n){const e=g(n);return Array.isArray(e?.rules)?e.rules.flatMap((t,r)=>{if(typeof t!="object"||t===null||Array.isArray(t))throw new Error(`Runtime routing.rules[${r}] must be an object`);const o=t;if(typeof o.agentId!="string"||!o.agentId.trim())throw new Error(`Runtime routing.rules[${r}] requires a non-empty agentId`);const i=m(o.regex);if(i)for(const u of i)try{new RegExp(u)}catch(s){const a=s instanceof Error?s.message:String(s);throw new Error(`Runtime routing.rules[${r}] has invalid regex ${JSON.stringify(u)}: ${a}`)}return[{agentId:o.agentId.trim(),equals:m(o.equals),startsWith:m(o.startsWith),contains:m(o.contains),regex:i,minLength:l(o.minLength),maxLength:l(o.maxLength),minLines:l(o.minLines),maxLines:l(o.maxLines),hasSessionId:typeof o.hasSessionId=="boolean"?o.hasSessionId:void 0,caseSensitive:o.caseSensitive===!0}]}):[]}function F(n,e,t={}){const r=n.trim(),o=e.caseSensitive?r:r.toLowerCase(),i=r?r.split(/\n+/).length:0,u=a=>e.caseSensitive?a:a.toLowerCase(),s=t.sessionId??t.legacySessionId;return!(e.hasSessionId!==void 0&&e.hasSessionId!==!!s||e.minLength!==void 0&&r.length<e.minLength||e.maxLength!==void 0&&r.length>e.maxLength||e.minLines!==void 0&&i<e.minLines||e.maxLines!==void 0&&i>e.maxLines||e.equals&&!e.equals.some(a=>o===u(a.trim()))||e.startsWith&&!e.startsWith.some(a=>o.startsWith(u(a.trim())))||e.contains&&!e.contains.some(a=>o.includes(u(a.trim())))||e.regex&&!e.regex.some(a=>new RegExp(a,e.caseSensitive?void 0:"i").test(r)))}function q(n,e){if(typeof n=="string"&&n.trim())return n;if(typeof n=="object"&&n!==null&&!Array.isArray(n)){const t=typeof n.path=="string"?n.path:void 0;if(t?.trim()){const r=e&&!c.isAbsolute(t)?c.resolve(e,t):t;return p(r,"utf8")}}}function A(n){const[e,...t]=n.split("/");return t.length===0?n:["agent","embedding-model","mcp","model","object","procedural-memory","prompt","runtime","runtime-memory","tool","vector-store"].includes(e)?t.join("/"):n}function $(n,e,t){return t.map(r=>{const o=b(n,r),i=typeof o?.value.path=="string"?o.value.path:A(r);return c.isAbsolute(i)?i:c.resolve(e,i)})}function O(n,e){return e.map(t=>c.isAbsolute(t)?t:c.resolve(n,t))}export{O as compileAgentMemories,k as getConcurrencyConfig,w as getProceduralMemoryDefaults,E as getRecoveryConfig,N as getResilienceConfig,P as getRoutingDefaultAgentId,C as getRoutingRules,v as getRuntimeAgentDefaults,f as getRuntimeDefaults,L as getRuntimeMemoryDefaults,D as getRuntimeResources,I as getRuntimeSources,j as getRuntimeStorageRoots,S as getToolModuleDiscoveryConfig,b as getWorkspaceObject,F as matchRoutingRule,$ as resolvePathList,q as resolvePromptValue,A as resolveRefId};
|