@botbotgo/agent-harness 0.0.56 → 0.0.58
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 +66 -1
- package/README.zh.md +574 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.js +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/resource/resource-impl.js +41 -9
- package/dist/runtime/agent-runtime-adapter.d.ts +8 -0
- package/dist/runtime/agent-runtime-adapter.js +116 -8
- package/dist/runtime/harness.d.ts +7 -0
- package/dist/runtime/harness.js +7 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/inventory.d.ts +10 -5
- package/dist/runtime/inventory.js +50 -12
- package/dist/runtime/skill-requirements.d.ts +27 -0
- package/dist/runtime/skill-requirements.js +112 -0
- package/dist/runtime/support/runtime-env.d.ts +2 -0
- package/dist/runtime/support/runtime-env.js +57 -0
- package/dist/runtime/support/skill-metadata.d.ts +14 -1
- package/dist/runtime/support/skill-metadata.js +59 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AgentHarnessRuntime, createAgentHarness, createToolMcpServer, deleteThread, getApproval, getThread, listApprovals, listThreads, resolveApproval, run, serveToolsOverStdio, subscribe, stop, } from "./api.js";
|
|
1
|
+
export { AgentHarnessRuntime, createAgentHarness, createToolMcpServer, deleteThread, describeInventory, getApproval, getThread, listAgentSkills, listApprovals, listThreads, resolveApproval, run, serveToolsOverStdio, subscribe, stop, } from "./api.js";
|
|
2
2
|
export { tool } from "./tools.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export declare const AGENT_HARNESS_VERSION = "0.0.57";
|
package/dist/package-version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AGENT_HARNESS_VERSION = "0.0.
|
|
1
|
+
export const AGENT_HARNESS_VERSION = "0.0.57";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { stat } from "node:fs/promises";
|
|
@@ -12,6 +12,7 @@ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/
|
|
|
12
12
|
import { WebSocketClientTransport } from "@modelcontextprotocol/sdk/client/websocket.js";
|
|
13
13
|
import { AGENT_HARNESS_VERSION } from "../package-version.js";
|
|
14
14
|
import { isSupportedToolModulePath, loadToolModuleDefinition } from "../tool-modules.js";
|
|
15
|
+
import { createRuntimeEnv } from "../runtime/support/runtime-env.js";
|
|
15
16
|
import { resolveIsolatedResourceModulePath } from "./isolation.js";
|
|
16
17
|
import { ensureExternalResourceSource, ensureExternalSource, isExternalSourceLocator, parseExternalSourceLocator } from "./sources.js";
|
|
17
18
|
const resourceDir = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -38,6 +39,33 @@ export function resolveLocalResourceProviderEntry(currentResourceDir, resolveIns
|
|
|
38
39
|
return candidates.at(-1) ?? path.resolve(currentResourceDir, "../../../resource-package/dist/src/index.js");
|
|
39
40
|
}
|
|
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
|
+
}
|
|
41
69
|
async function loadLocalResource(entry) {
|
|
42
70
|
if (!existsSync(entry)) {
|
|
43
71
|
return null;
|
|
@@ -70,7 +98,11 @@ class CompatibleCompositeBackend {
|
|
|
70
98
|
const sandboxLike = defaultBackend;
|
|
71
99
|
if (typeof sandboxLike.id === "string" && typeof sandboxLike.execute === "function") {
|
|
72
100
|
this.id = sandboxLike.id;
|
|
73
|
-
|
|
101
|
+
const virtualCwd = typeof sandboxLike.cwd === "string" && sandboxLike.virtualMode === true ? sandboxLike.cwd : null;
|
|
102
|
+
this.execute =
|
|
103
|
+
virtualCwd
|
|
104
|
+
? (command) => this.composite.execute(normalizeVirtualExecuteCommand(command, virtualCwd))
|
|
105
|
+
: (command) => this.composite.execute(command);
|
|
74
106
|
}
|
|
75
107
|
}
|
|
76
108
|
lsInfo(filePath) {
|
|
@@ -116,6 +148,10 @@ function createInlineBackendResolver(workspace) {
|
|
|
116
148
|
return workspace.workspaceRoot;
|
|
117
149
|
};
|
|
118
150
|
const createBackend = (kind, config, runtimeLike) => {
|
|
151
|
+
const configuredEnv = typeof config?.env === "object" && config.env
|
|
152
|
+
? Object.fromEntries(Object.entries(config.env).filter((entry) => typeof entry[1] === "string"))
|
|
153
|
+
: undefined;
|
|
154
|
+
const inheritedEnv = config?.inheritEnv === false ? {} : process.env;
|
|
119
155
|
switch (kind) {
|
|
120
156
|
case "LocalShellBackend": {
|
|
121
157
|
const rootDir = resolveBackendRootDir(config?.rootDir);
|
|
@@ -125,9 +161,7 @@ function createInlineBackendResolver(workspace) {
|
|
|
125
161
|
virtualMode: config?.virtualMode === true,
|
|
126
162
|
timeout: typeof config?.timeout === "number" ? config.timeout : undefined,
|
|
127
163
|
maxOutputBytes: typeof config?.maxOutputBytes === "number" ? config.maxOutputBytes : undefined,
|
|
128
|
-
env:
|
|
129
|
-
? Object.fromEntries(Object.entries(config.env).filter((entry) => typeof entry[1] === "string"))
|
|
130
|
-
: undefined,
|
|
164
|
+
env: createRuntimeEnv(configuredEnv, inheritedEnv),
|
|
131
165
|
inheritEnv: config?.inheritEnv !== false,
|
|
132
166
|
});
|
|
133
167
|
}
|
|
@@ -139,9 +173,7 @@ function createInlineBackendResolver(workspace) {
|
|
|
139
173
|
virtualMode: config?.virtualMode === false ? false : true,
|
|
140
174
|
timeout: typeof config?.timeout === "number" ? config.timeout : undefined,
|
|
141
175
|
maxOutputBytes: typeof config?.maxOutputBytes === "number" ? config.maxOutputBytes : undefined,
|
|
142
|
-
env:
|
|
143
|
-
? Object.fromEntries(Object.entries(config.env).filter((entry) => typeof entry[1] === "string"))
|
|
144
|
-
: undefined,
|
|
176
|
+
env: createRuntimeEnv(configuredEnv, inheritedEnv),
|
|
145
177
|
inheritEnv: config?.inheritEnv !== false,
|
|
146
178
|
});
|
|
147
179
|
}
|
|
@@ -318,7 +350,7 @@ export async function getOrCreateMcpClient(config) {
|
|
|
318
350
|
: new StdioClientTransport({
|
|
319
351
|
command: config.command ?? "",
|
|
320
352
|
args: config.args,
|
|
321
|
-
env: config.env,
|
|
353
|
+
env: createRuntimeEnv(config.env),
|
|
322
354
|
cwd: config.cwd,
|
|
323
355
|
});
|
|
324
356
|
await client.connect(transport);
|
|
@@ -12,6 +12,13 @@ declare class RuntimeOperationTimeoutError extends Error {
|
|
|
12
12
|
readonly stage: "stream" | "invoke";
|
|
13
13
|
constructor(operation: string, timeoutMs: number, stage?: "stream" | "invoke");
|
|
14
14
|
}
|
|
15
|
+
export declare function relativizeDeepAgentSkillSourcePaths(workspaceRoot: string | undefined, skillPaths: string[] | undefined): string[] | undefined;
|
|
16
|
+
export declare function materializeDeepAgentSkillSourcePaths(options: {
|
|
17
|
+
workspaceRoot?: string;
|
|
18
|
+
runRoot?: string;
|
|
19
|
+
ownerId: string;
|
|
20
|
+
skillPaths?: string[];
|
|
21
|
+
}): Promise<string[] | undefined>;
|
|
15
22
|
export declare class AgentRuntimeAdapter {
|
|
16
23
|
private readonly options;
|
|
17
24
|
constructor(options?: RuntimeAdapterOptions);
|
|
@@ -26,6 +33,7 @@ export declare class AgentRuntimeAdapter {
|
|
|
26
33
|
private resolveModel;
|
|
27
34
|
private buildToolNameMapping;
|
|
28
35
|
private buildAgentMessages;
|
|
36
|
+
private buildSlashCommandSkillInstruction;
|
|
29
37
|
private buildInvocationRequest;
|
|
30
38
|
private buildStateSnapshot;
|
|
31
39
|
private buildRawModelMessages;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { existsSync, statSync } from "node:fs";
|
|
3
|
+
import { cp, mkdir, rm } from "node:fs/promises";
|
|
2
4
|
import { Command, MemorySaver } from "@langchain/langgraph";
|
|
3
5
|
import { tool as createLangChainTool } from "@langchain/core/tools";
|
|
4
6
|
import { createDeepAgent, createMemoryMiddleware, createSkillsMiddleware, createSubAgentMiddleware, FilesystemBackend, } from "deepagents";
|
|
@@ -16,6 +18,7 @@ import { wrapToolForExecution } from "./tool-hitl.js";
|
|
|
16
18
|
import { resolveDeclaredMiddleware } from "./declared-middleware.js";
|
|
17
19
|
import { extractMessageText, normalizeMessageContent } from "../utils/message-content.js";
|
|
18
20
|
import { getBindingDeepAgentParams, getBindingInterruptCompatibilityRules, getBindingLangChainParams, getBindingMiddlewareConfigs, getBindingModelInit, getBindingPrimaryModel, getBindingPrimaryTools, getBindingSystemPrompt, isDeepAgentBinding, isLangChainBinding, } from "./support/compiled-binding.js";
|
|
21
|
+
import { readSkillMetadata } from "./support/skill-metadata.js";
|
|
19
22
|
function countConfiguredTools(binding) {
|
|
20
23
|
return getBindingPrimaryTools(binding).length;
|
|
21
24
|
}
|
|
@@ -52,6 +55,65 @@ function computeRemainingTimeoutMs(deadlineAt, fallbackTimeoutMs) {
|
|
|
52
55
|
function isPlaceholderApiKey(value) {
|
|
53
56
|
return typeof value === "string" && value.trim().toLowerCase() === "dummy";
|
|
54
57
|
}
|
|
58
|
+
export function relativizeDeepAgentSkillSourcePaths(workspaceRoot, skillPaths) {
|
|
59
|
+
if (!workspaceRoot || !skillPaths) {
|
|
60
|
+
return skillPaths;
|
|
61
|
+
}
|
|
62
|
+
return skillPaths.map((skillPath) => {
|
|
63
|
+
if (!path.isAbsolute(skillPath)) {
|
|
64
|
+
return skillPath;
|
|
65
|
+
}
|
|
66
|
+
const relative = path.relative(workspaceRoot, skillPath);
|
|
67
|
+
if (!relative || relative.startsWith("..")) {
|
|
68
|
+
return skillPath;
|
|
69
|
+
}
|
|
70
|
+
return relative.split(path.sep).join("/");
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function isDeepAgentSkillDirectory(sourcePath) {
|
|
74
|
+
return existsSync(sourcePath) && statSync(sourcePath).isDirectory() && existsSync(path.join(sourcePath, "SKILL.md"));
|
|
75
|
+
}
|
|
76
|
+
function toWorkspaceRelativePath(workspaceRoot, targetPath) {
|
|
77
|
+
if (!workspaceRoot) {
|
|
78
|
+
return targetPath;
|
|
79
|
+
}
|
|
80
|
+
const relative = path.relative(workspaceRoot, targetPath);
|
|
81
|
+
if (!relative || relative.startsWith("..")) {
|
|
82
|
+
return targetPath;
|
|
83
|
+
}
|
|
84
|
+
return relative.split(path.sep).join("/");
|
|
85
|
+
}
|
|
86
|
+
export async function materializeDeepAgentSkillSourcePaths(options) {
|
|
87
|
+
const { workspaceRoot, runRoot, ownerId, skillPaths } = options;
|
|
88
|
+
if (!skillPaths) {
|
|
89
|
+
return skillPaths;
|
|
90
|
+
}
|
|
91
|
+
const materialized = relativizeDeepAgentSkillSourcePaths(workspaceRoot, skillPaths) ?? skillPaths;
|
|
92
|
+
if (!workspaceRoot || !runRoot) {
|
|
93
|
+
return materialized;
|
|
94
|
+
}
|
|
95
|
+
const sourceRoot = path.join(runRoot, "deepagent-skill-sources", ownerId);
|
|
96
|
+
let wroteSyntheticSource = false;
|
|
97
|
+
const resolvedSources = [];
|
|
98
|
+
for (const [index, sourcePath] of materialized.entries()) {
|
|
99
|
+
const absolutePath = path.isAbsolute(sourcePath) ? sourcePath : path.resolve(workspaceRoot, sourcePath);
|
|
100
|
+
if (!isDeepAgentSkillDirectory(absolutePath)) {
|
|
101
|
+
resolvedSources.push(sourcePath);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (!wroteSyntheticSource) {
|
|
105
|
+
await rm(sourceRoot, { recursive: true, force: true });
|
|
106
|
+
await mkdir(sourceRoot, { recursive: true });
|
|
107
|
+
wroteSyntheticSource = true;
|
|
108
|
+
}
|
|
109
|
+
const skillDirectoryName = path.basename(absolutePath);
|
|
110
|
+
const syntheticSourcePath = path.join(sourceRoot, `${String(index + 1).padStart(3, "0")}-${skillDirectoryName}`);
|
|
111
|
+
await mkdir(syntheticSourcePath, { recursive: true });
|
|
112
|
+
await cp(absolutePath, path.join(syntheticSourcePath, skillDirectoryName), { recursive: true });
|
|
113
|
+
resolvedSources.push(toWorkspaceRelativePath(workspaceRoot, syntheticSourcePath));
|
|
114
|
+
}
|
|
115
|
+
return resolvedSources;
|
|
116
|
+
}
|
|
55
117
|
function buildAuthOmittingFetch(baseFetch = fetch) {
|
|
56
118
|
return async (input, init) => {
|
|
57
119
|
const sanitizedHeaders = new Headers(input instanceof Request ? input.headers : undefined);
|
|
@@ -399,11 +461,42 @@ export class AgentRuntimeAdapter {
|
|
|
399
461
|
{ role: "user", content: normalizeMessageContent(input) },
|
|
400
462
|
];
|
|
401
463
|
}
|
|
402
|
-
|
|
464
|
+
buildSlashCommandSkillInstruction(binding, input) {
|
|
465
|
+
const inputText = extractMessageText(input).trim();
|
|
466
|
+
const match = inputText.match(/^\/([a-z0-9]+(?:-[a-z0-9]+)*)(?:\s+([\s\S]*))?$/i);
|
|
467
|
+
if (!match) {
|
|
468
|
+
return undefined;
|
|
469
|
+
}
|
|
470
|
+
const invokedName = match[1].toLowerCase();
|
|
471
|
+
const argumentText = match[2]?.trim() ?? "";
|
|
472
|
+
const skillPaths = binding.deepAgentParams?.skills ?? binding.langchainAgentParams?.skills ?? [];
|
|
473
|
+
const matchedSkillPath = skillPaths.find((skillPath) => readSkillMetadata(skillPath).name.toLowerCase() === invokedName);
|
|
474
|
+
if (!matchedSkillPath) {
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
const metadata = readSkillMetadata(matchedSkillPath);
|
|
478
|
+
const skillQualifier = metadata.userInvocable === true ? "user-invocable skill" : "skill";
|
|
479
|
+
const dryRunHint = /\s--dry-run(?:\s|$)/.test(` ${argumentText} `)
|
|
480
|
+
? "This invocation includes `--dry-run`. Perform the real fetch or inspection steps needed for dry-run output. Do not return hypothetical or mock results."
|
|
481
|
+
: undefined;
|
|
482
|
+
return [
|
|
483
|
+
`This user message is an explicit command-style invocation of the ${skillQualifier} \`${metadata.name}\`.`,
|
|
484
|
+
`Read the skill file for \`${metadata.name}\` before taking action, then follow its documented phases and constraints exactly.`,
|
|
485
|
+
`You must use the \`${metadata.name}\` skill for this request and follow its documented workflow.`,
|
|
486
|
+
`Treat everything after \`/${metadata.name}\` as the skill argument string: ${argumentText ? JSON.stringify(argumentText) : '""'}.`,
|
|
487
|
+
"Do not answer with a generic explanation of what the skill would do. Execute the skill workflow using the available tools unless the skill instructions explicitly require confirmation before acting.",
|
|
488
|
+
dryRunHint,
|
|
489
|
+
].filter((line) => typeof line === "string" && line.length > 0).join("\n");
|
|
490
|
+
}
|
|
491
|
+
buildInvocationRequest(binding, history, input, options = {}) {
|
|
492
|
+
const userInvocableInstruction = this.buildSlashCommandSkillInstruction(binding, input);
|
|
493
|
+
const messages = this.buildAgentMessages(history, input);
|
|
403
494
|
return {
|
|
404
495
|
...(options.state ?? {}),
|
|
405
496
|
...(options.files ? { files: options.files } : {}),
|
|
406
|
-
messages:
|
|
497
|
+
messages: userInvocableInstruction
|
|
498
|
+
? [{ role: "system", content: userInvocableInstruction }, ...messages]
|
|
499
|
+
: messages,
|
|
407
500
|
};
|
|
408
501
|
}
|
|
409
502
|
buildStateSnapshot(result) {
|
|
@@ -414,11 +507,15 @@ export class AgentRuntimeAdapter {
|
|
|
414
507
|
delete snapshot.files;
|
|
415
508
|
return Object.keys(snapshot).length > 0 ? snapshot : undefined;
|
|
416
509
|
}
|
|
417
|
-
buildRawModelMessages(systemPrompt, history, input) {
|
|
510
|
+
buildRawModelMessages(binding, systemPrompt, history, input) {
|
|
418
511
|
const messages = [];
|
|
419
512
|
if (systemPrompt) {
|
|
420
513
|
messages.push({ role: "system", content: systemPrompt });
|
|
421
514
|
}
|
|
515
|
+
const userInvocableInstruction = this.buildSlashCommandSkillInstruction(binding, input);
|
|
516
|
+
if (userInvocableInstruction) {
|
|
517
|
+
messages.push({ role: "system", content: userInvocableInstruction });
|
|
518
|
+
}
|
|
422
519
|
messages.push(...this.buildAgentMessages(history, input));
|
|
423
520
|
return messages;
|
|
424
521
|
}
|
|
@@ -572,6 +669,12 @@ export class AgentRuntimeAdapter {
|
|
|
572
669
|
...(subagent.passthrough ?? {}),
|
|
573
670
|
model: subagent.model ? (await this.resolveModel(subagent.model)) : undefined,
|
|
574
671
|
tools: subagent.tools ? this.resolveTools(subagent.tools) : undefined,
|
|
672
|
+
skills: await materializeDeepAgentSkillSourcePaths({
|
|
673
|
+
workspaceRoot: binding?.harnessRuntime.workspaceRoot,
|
|
674
|
+
runRoot: binding?.harnessRuntime.runRoot,
|
|
675
|
+
ownerId: `${binding?.agent.id ?? "agent"}-${subagent.name}`,
|
|
676
|
+
skillPaths: subagent.skills,
|
|
677
|
+
}),
|
|
575
678
|
interruptOn: this.compileInterruptOn(subagent.tools ?? [], subagent.interruptOn),
|
|
576
679
|
responseFormat: subagent.responseFormat,
|
|
577
680
|
contextSchema: subagent.contextSchema,
|
|
@@ -635,7 +738,12 @@ export class AgentRuntimeAdapter {
|
|
|
635
738
|
interruptOn: this.resolveInterruptOn(binding),
|
|
636
739
|
name: params.name,
|
|
637
740
|
memory: params.memory,
|
|
638
|
-
skills:
|
|
741
|
+
skills: await materializeDeepAgentSkillSourcePaths({
|
|
742
|
+
workspaceRoot: binding.harnessRuntime.workspaceRoot,
|
|
743
|
+
runRoot: binding.harnessRuntime.runRoot,
|
|
744
|
+
ownerId: binding.agent.id,
|
|
745
|
+
skillPaths: params.skills,
|
|
746
|
+
}),
|
|
639
747
|
generalPurposeAgent: params.generalPurposeAgent,
|
|
640
748
|
taskDescription: params.taskDescription,
|
|
641
749
|
};
|
|
@@ -670,7 +778,7 @@ export class AgentRuntimeAdapter {
|
|
|
670
778
|
}
|
|
671
779
|
async invoke(binding, input, threadId, runId, resumePayload, history = [], options = {}) {
|
|
672
780
|
const request = resumePayload === undefined
|
|
673
|
-
? this.buildInvocationRequest(history, input, options)
|
|
781
|
+
? this.buildInvocationRequest(binding, history, input, options)
|
|
674
782
|
: new Command({ resume: resumePayload });
|
|
675
783
|
let result;
|
|
676
784
|
try {
|
|
@@ -683,7 +791,7 @@ export class AgentRuntimeAdapter {
|
|
|
683
791
|
}
|
|
684
792
|
const retriedBinding = this.applyStrictToolJsonInstruction(binding);
|
|
685
793
|
const runnable = await this.create(retriedBinding);
|
|
686
|
-
result = (await this.withTimeout(() => runnable.invoke(this.buildInvocationRequest(history, input, options), { configurable: { thread_id: threadId }, ...(options.context ? { context: options.context } : {}) }), this.resolveBindingTimeout(retriedBinding), "agent invoke", "invoke"));
|
|
794
|
+
result = (await this.withTimeout(() => runnable.invoke(this.buildInvocationRequest(retriedBinding, history, input, options), { configurable: { thread_id: threadId }, ...(options.context ? { context: options.context } : {}) }), this.resolveBindingTimeout(retriedBinding), "agent invoke", "invoke"));
|
|
687
795
|
}
|
|
688
796
|
const interruptContent = Array.isArray(result.__interrupt__) && result.__interrupt__.length > 0 ? JSON.stringify(result.__interrupt__) : undefined;
|
|
689
797
|
const extractedOutput = extractVisibleOutput(result);
|
|
@@ -739,7 +847,7 @@ export class AgentRuntimeAdapter {
|
|
|
739
847
|
// agent loop and only adds an extra model round-trip before the runnable path.
|
|
740
848
|
if (canUseDirectModelStream && typeof model.stream === "function") {
|
|
741
849
|
let emitted = false;
|
|
742
|
-
const stream = await this.withTimeout(() => model.stream(this.buildRawModelMessages(getBindingSystemPrompt(binding), history, input)), computeRemainingTimeoutMs(streamDeadlineAt, invokeTimeoutMs), "model stream start", "stream");
|
|
850
|
+
const stream = await this.withTimeout(() => model.stream(this.buildRawModelMessages(binding, getBindingSystemPrompt(binding), history, input)), computeRemainingTimeoutMs(streamDeadlineAt, invokeTimeoutMs), "model stream start", "stream");
|
|
743
851
|
for await (const chunk of this.iterateWithTimeout(stream, streamIdleTimeoutMs, "model stream", streamDeadlineAt, invokeTimeoutMs)) {
|
|
744
852
|
const delta = readStreamDelta(chunk);
|
|
745
853
|
if (delta) {
|
|
@@ -758,7 +866,7 @@ export class AgentRuntimeAdapter {
|
|
|
758
866
|
}
|
|
759
867
|
}
|
|
760
868
|
const runnable = await this.create(binding);
|
|
761
|
-
const request = this.buildInvocationRequest(history, input, options);
|
|
869
|
+
const request = this.buildInvocationRequest(binding, history, input, options);
|
|
762
870
|
if (typeof runnable.streamEvents === "function") {
|
|
763
871
|
const events = await this.withTimeout(() => runnable.streamEvents(request, { configurable: { thread_id: threadId }, version: "v2", ...(options.context ? { context: options.context } : {}) }), computeRemainingTimeoutMs(streamDeadlineAt, invokeTimeoutMs), "agent streamEvents start", "stream");
|
|
764
872
|
const allowVisibleStreamDeltas = isLangChainBinding(binding);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ApprovalRecord, HarnessEvent, HarnessStreamItem, MessageContent, RunStartOptions, RestartConversationOptions, RuntimeAdapterOptions, ResumeOptions, RunOptions, RunResult, ThreadSummary, ThreadRecord, WorkspaceBundle } from "../contracts/types.js";
|
|
2
2
|
import { type ToolMcpServerOptions } from "../mcp.js";
|
|
3
|
+
import { type InventoryAgentRecord, type InventorySkillRecord } from "./inventory.js";
|
|
4
|
+
import type { RequirementAssessmentOptions } from "./skill-requirements.js";
|
|
3
5
|
export declare class AgentHarnessRuntime {
|
|
4
6
|
private readonly workspace;
|
|
5
7
|
private readonly runtimeAdapterOptions;
|
|
@@ -53,6 +55,11 @@ export declare class AgentHarnessRuntime {
|
|
|
53
55
|
runId?: string;
|
|
54
56
|
}): Promise<ApprovalRecord[]>;
|
|
55
57
|
getApproval(approvalId: string): Promise<ApprovalRecord | null>;
|
|
58
|
+
listAgentSkills(agentId: string, options?: RequirementAssessmentOptions): InventorySkillRecord[];
|
|
59
|
+
describeWorkspaceInventory(options?: RequirementAssessmentOptions): {
|
|
60
|
+
workspaceRoot: string;
|
|
61
|
+
agents: InventoryAgentRecord[];
|
|
62
|
+
};
|
|
56
63
|
private deleteThreadCheckpoints;
|
|
57
64
|
deleteThread(threadId: string): Promise<boolean>;
|
|
58
65
|
createToolMcpServer(options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp.js").McpServer>;
|
package/dist/runtime/harness.js
CHANGED
|
@@ -16,6 +16,7 @@ import { CheckpointMaintenanceLoop, discoverCheckpointMaintenanceTargets, readCh
|
|
|
16
16
|
import { extractMessageText, normalizeMessageContent } from "../utils/message-content.js";
|
|
17
17
|
import { createToolMcpServerFromTools, serveToolsOverStdioFromHarness } from "../mcp.js";
|
|
18
18
|
import { getBindingAdapterKind, getBindingPrimaryTools, getBindingStoreConfig } from "./support/compiled-binding.js";
|
|
19
|
+
import { describeWorkspaceInventory, listAgentSkills as listWorkspaceAgentSkills, } from "./inventory.js";
|
|
19
20
|
export class AgentHarnessRuntime {
|
|
20
21
|
workspace;
|
|
21
22
|
runtimeAdapterOptions;
|
|
@@ -286,6 +287,12 @@ export class AgentHarnessRuntime {
|
|
|
286
287
|
const approval = await this.persistence.getApproval(approvalId);
|
|
287
288
|
return approval ? this.toPublicApprovalRecord(approval) : null;
|
|
288
289
|
}
|
|
290
|
+
listAgentSkills(agentId, options = {}) {
|
|
291
|
+
return listWorkspaceAgentSkills(this.workspace, agentId, options);
|
|
292
|
+
}
|
|
293
|
+
describeWorkspaceInventory(options = {}) {
|
|
294
|
+
return describeWorkspaceInventory(this.workspace, options);
|
|
295
|
+
}
|
|
289
296
|
async deleteThreadCheckpoints(threadId) {
|
|
290
297
|
const resolver = this.resolvedRuntimeAdapterOptions.checkpointerResolver;
|
|
291
298
|
if (!resolver) {
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { CheckpointMaintenanceLoop, discoverCheckpointMaintenanceTargets, mainta
|
|
|
6
6
|
export { ManagedSqliteSaver } from "./sqlite-maintained-checkpoint-saver.js";
|
|
7
7
|
export { AgentHarnessRuntime, AgentHarness } from "./harness.js";
|
|
8
8
|
export { describeWorkspaceInventory, findAgentBinding, listAgentSkills, listAgentTools, listAvailableAgents, listSpecialists, } from "./inventory.js";
|
|
9
|
+
export { assessOpenClawRequirements, assessSkillRequirements, } from "./skill-requirements.js";
|
|
9
10
|
export * from "./parsing/index.js";
|
|
10
11
|
export { PolicyEngine } from "./policy-engine.js";
|
|
11
12
|
export { createInMemoryStore, FileBackedStore } from "./store.js";
|
package/dist/runtime/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { CheckpointMaintenanceLoop, discoverCheckpointMaintenanceTargets, mainta
|
|
|
6
6
|
export { ManagedSqliteSaver } from "./sqlite-maintained-checkpoint-saver.js";
|
|
7
7
|
export { AgentHarnessRuntime, AgentHarness } from "./harness.js";
|
|
8
8
|
export { describeWorkspaceInventory, findAgentBinding, listAgentSkills, listAgentTools, listAvailableAgents, listSpecialists, } from "./inventory.js";
|
|
9
|
+
export { assessOpenClawRequirements, assessSkillRequirements, } from "./skill-requirements.js";
|
|
9
10
|
export * from "./parsing/index.js";
|
|
10
11
|
export { PolicyEngine } from "./policy-engine.js";
|
|
11
12
|
export { createInMemoryStore, FileBackedStore } from "./store.js";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { CompiledAgentBinding, WorkspaceBundle } from "../contracts/types.js";
|
|
2
|
+
import type { OpenClawSkillMetadata } from "./support/skill-metadata.js";
|
|
3
|
+
import { type RequirementAssessmentOptions, type SkillRequirementAssessment } from "./skill-requirements.js";
|
|
2
4
|
export type InventoryToolRecord = {
|
|
3
5
|
name: string;
|
|
4
6
|
description: string;
|
|
@@ -9,8 +11,11 @@ export type InventorySkillRecord = {
|
|
|
9
11
|
description?: string;
|
|
10
12
|
license?: string;
|
|
11
13
|
compatibility?: string;
|
|
12
|
-
metadata?: Record<string,
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
13
15
|
allowedTools?: string[];
|
|
16
|
+
userInvocable?: boolean;
|
|
17
|
+
openclaw?: OpenClawSkillMetadata;
|
|
18
|
+
requirements?: SkillRequirementAssessment;
|
|
14
19
|
};
|
|
15
20
|
export type InventoryAgentRecord = {
|
|
16
21
|
id: string;
|
|
@@ -21,10 +26,10 @@ export type InventoryAgentRecord = {
|
|
|
21
26
|
};
|
|
22
27
|
export declare function findAgentBinding(workspace: WorkspaceBundle, agentId: string): CompiledAgentBinding | undefined;
|
|
23
28
|
export declare function listAgentTools(workspace: WorkspaceBundle, agentId: string): InventoryToolRecord[];
|
|
24
|
-
export declare function listAgentSkills(workspace: WorkspaceBundle, agentId: string): InventorySkillRecord[];
|
|
25
|
-
export declare function listSpecialists(workspace: WorkspaceBundle): InventoryAgentRecord[];
|
|
26
|
-
export declare function listAvailableAgents(workspace: WorkspaceBundle): InventoryAgentRecord[];
|
|
27
|
-
export declare function describeWorkspaceInventory(workspace: WorkspaceBundle): {
|
|
29
|
+
export declare function listAgentSkills(workspace: WorkspaceBundle, agentId: string, options?: RequirementAssessmentOptions): InventorySkillRecord[];
|
|
30
|
+
export declare function listSpecialists(workspace: WorkspaceBundle, options?: RequirementAssessmentOptions): InventoryAgentRecord[];
|
|
31
|
+
export declare function listAvailableAgents(workspace: WorkspaceBundle, options?: RequirementAssessmentOptions): InventoryAgentRecord[];
|
|
32
|
+
export declare function describeWorkspaceInventory(workspace: WorkspaceBundle, options?: RequirementAssessmentOptions): {
|
|
28
33
|
workspaceRoot: string;
|
|
29
34
|
agents: InventoryAgentRecord[];
|
|
30
35
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { readSkillMetadata } from "./support/skill-metadata.js";
|
|
2
2
|
import { getBindingPrimaryTools } from "./support/compiled-binding.js";
|
|
3
|
+
import { assessSkillRequirements, } from "./skill-requirements.js";
|
|
4
|
+
import { createRuntimeEnv } from "./support/runtime-env.js";
|
|
3
5
|
function listHostBindings(workspace) {
|
|
4
6
|
return Array.from(workspace.bindings.values()).filter((binding) => binding.harnessRuntime.hostFacing);
|
|
5
7
|
}
|
|
@@ -13,7 +15,36 @@ function dedupeTools(tools) {
|
|
|
13
15
|
}
|
|
14
16
|
return Array.from(deduped.values());
|
|
15
17
|
}
|
|
16
|
-
function
|
|
18
|
+
function readBackendRequirementOptions(binding) {
|
|
19
|
+
const backend = binding.deepAgentParams?.backend && typeof binding.deepAgentParams.backend === "object"
|
|
20
|
+
? binding.deepAgentParams.backend
|
|
21
|
+
: undefined;
|
|
22
|
+
if (!backend) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
const backendState = typeof backend.state === "object" && backend.state
|
|
26
|
+
? backend.state
|
|
27
|
+
: backend;
|
|
28
|
+
const env = typeof backendState.env === "object" && backendState.env
|
|
29
|
+
? Object.fromEntries(Object.entries(backendState.env).filter((entry) => typeof entry[1] === "string"))
|
|
30
|
+
: undefined;
|
|
31
|
+
const inheritedEnv = backendState.inheritEnv === false ? {} : process.env;
|
|
32
|
+
const runtimeEnv = createRuntimeEnv(env, inheritedEnv);
|
|
33
|
+
return {
|
|
34
|
+
env: runtimeEnv,
|
|
35
|
+
path: runtimeEnv.PATH,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function mergeRequirementOptions(binding, options = {}) {
|
|
39
|
+
const fromBackend = readBackendRequirementOptions(binding);
|
|
40
|
+
return {
|
|
41
|
+
...fromBackend,
|
|
42
|
+
...options,
|
|
43
|
+
env: options.env ? { ...(fromBackend.env ?? {}), ...options.env } : fromBackend.env,
|
|
44
|
+
path: options.path ?? fromBackend.path,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function toSkillRecords(skillPaths, options = {}) {
|
|
17
48
|
return Array.from(new Set(skillPaths)).map((skillPath) => {
|
|
18
49
|
const metadata = readSkillMetadata(skillPath);
|
|
19
50
|
return {
|
|
@@ -24,6 +55,9 @@ function toSkillRecords(skillPaths) {
|
|
|
24
55
|
compatibility: metadata.compatibility,
|
|
25
56
|
metadata: metadata.metadata,
|
|
26
57
|
allowedTools: metadata.allowedTools,
|
|
58
|
+
userInvocable: metadata.userInvocable,
|
|
59
|
+
openclaw: metadata.openclaw,
|
|
60
|
+
requirements: assessSkillRequirements(metadata, options),
|
|
27
61
|
};
|
|
28
62
|
});
|
|
29
63
|
}
|
|
@@ -34,38 +68,42 @@ export function listAgentTools(workspace, agentId) {
|
|
|
34
68
|
}
|
|
35
69
|
return dedupeTools(getBindingPrimaryTools(binding));
|
|
36
70
|
}
|
|
37
|
-
export function listAgentSkills(workspace, agentId) {
|
|
71
|
+
export function listAgentSkills(workspace, agentId, options = {}) {
|
|
38
72
|
const binding = findAgentBinding(workspace, agentId);
|
|
39
73
|
if (!binding) {
|
|
40
74
|
return [];
|
|
41
75
|
}
|
|
42
|
-
|
|
76
|
+
const resolvedOptions = mergeRequirementOptions(binding, options);
|
|
77
|
+
return toSkillRecords(binding.deepAgentParams?.skills ?? binding.langchainAgentParams?.skills ?? [], resolvedOptions);
|
|
43
78
|
}
|
|
44
|
-
function describeSubagent(subagent) {
|
|
79
|
+
function describeSubagent(subagent, options = {}) {
|
|
45
80
|
return {
|
|
46
81
|
id: subagent.name,
|
|
47
82
|
description: subagent.description,
|
|
48
83
|
role: "specialist",
|
|
49
84
|
tools: dedupeTools(subagent.tools ?? []),
|
|
50
|
-
skills: toSkillRecords(subagent.skills ?? []),
|
|
85
|
+
skills: toSkillRecords(subagent.skills ?? [], options),
|
|
51
86
|
};
|
|
52
87
|
}
|
|
53
|
-
export function listSpecialists(workspace) {
|
|
54
|
-
return listHostBindings(workspace).flatMap((binding) =>
|
|
88
|
+
export function listSpecialists(workspace, options = {}) {
|
|
89
|
+
return listHostBindings(workspace).flatMap((binding) => {
|
|
90
|
+
const resolvedOptions = mergeRequirementOptions(binding, options);
|
|
91
|
+
return (binding.deepAgentParams?.subagents ?? []).map((subagent) => describeSubagent(subagent, resolvedOptions));
|
|
92
|
+
});
|
|
55
93
|
}
|
|
56
|
-
export function listAvailableAgents(workspace) {
|
|
94
|
+
export function listAvailableAgents(workspace, options = {}) {
|
|
57
95
|
const topLevel = listHostBindings(workspace).map((binding) => ({
|
|
58
96
|
id: binding.agent.id,
|
|
59
97
|
description: binding.agent.description,
|
|
60
98
|
role: "host",
|
|
61
99
|
tools: listAgentTools(workspace, binding.agent.id),
|
|
62
|
-
skills: listAgentSkills(workspace, binding.agent.id),
|
|
100
|
+
skills: listAgentSkills(workspace, binding.agent.id, options),
|
|
63
101
|
}));
|
|
64
|
-
return [...topLevel, ...listSpecialists(workspace)];
|
|
102
|
+
return [...topLevel, ...listSpecialists(workspace, options)];
|
|
65
103
|
}
|
|
66
|
-
export function describeWorkspaceInventory(workspace) {
|
|
104
|
+
export function describeWorkspaceInventory(workspace, options = {}) {
|
|
67
105
|
return {
|
|
68
106
|
workspaceRoot: workspace.workspaceRoot,
|
|
69
|
-
agents: listAvailableAgents(workspace),
|
|
107
|
+
agents: listAvailableAgents(workspace, options),
|
|
70
108
|
};
|
|
71
109
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { OpenClawSkillMetadata, SkillMetadata } from "./support/skill-metadata.js";
|
|
2
|
+
export type RequirementStatus = "satisfied" | "missing" | "unknown";
|
|
3
|
+
export type RequirementCheckRecord = {
|
|
4
|
+
name: string;
|
|
5
|
+
status: RequirementStatus;
|
|
6
|
+
};
|
|
7
|
+
export type OpenClawRequirementAssessment = {
|
|
8
|
+
ready: boolean;
|
|
9
|
+
missing: boolean;
|
|
10
|
+
unknown: boolean;
|
|
11
|
+
bins: RequirementCheckRecord[];
|
|
12
|
+
anyBins: RequirementCheckRecord[];
|
|
13
|
+
env: RequirementCheckRecord[];
|
|
14
|
+
config: RequirementCheckRecord[];
|
|
15
|
+
primaryEnv?: RequirementCheckRecord;
|
|
16
|
+
};
|
|
17
|
+
export type SkillRequirementAssessment = {
|
|
18
|
+
openclaw?: OpenClawRequirementAssessment;
|
|
19
|
+
};
|
|
20
|
+
export type RequirementAssessmentOptions = {
|
|
21
|
+
env?: Record<string, string | undefined>;
|
|
22
|
+
path?: string;
|
|
23
|
+
availableBins?: string[];
|
|
24
|
+
config?: Record<string, unknown> | string[];
|
|
25
|
+
};
|
|
26
|
+
export declare function assessOpenClawRequirements(metadata: OpenClawSkillMetadata | undefined, options?: RequirementAssessmentOptions): OpenClawRequirementAssessment | undefined;
|
|
27
|
+
export declare function assessSkillRequirements(metadata: SkillMetadata, options?: RequirementAssessmentOptions): SkillRequirementAssessment;
|