@botbotgo/agent-harness 0.0.96 → 0.0.97
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/dist/api.d.ts +5 -5
- package/dist/contracts/core.d.ts +9 -0
- package/dist/contracts/core.js +1 -0
- package/dist/contracts/runtime.d.ts +421 -0
- package/dist/contracts/runtime.js +1 -0
- package/dist/contracts/types.d.ts +3 -653
- package/dist/contracts/types.js +3 -1
- package/dist/contracts/workspace.d.ts +229 -0
- package/dist/contracts/workspace.js +1 -0
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/runtime/adapter/compat/deepagent-compat.d.ts +16 -0
- package/dist/runtime/adapter/compat/deepagent-compat.js +45 -0
- package/dist/runtime/adapter/compat/openai-compatible.d.ts +2 -0
- package/dist/runtime/adapter/compat/openai-compatible.js +43 -0
- package/dist/runtime/adapter/index.d.ts +15 -0
- package/dist/runtime/adapter/index.js +15 -0
- package/dist/runtime/{langgraph-profiles.d.ts → adapter/langgraph/profiles.d.ts} +1 -1
- package/dist/runtime/adapter/model/invocation-request.d.ts +10 -0
- package/dist/runtime/adapter/model/invocation-request.js +46 -0
- package/dist/runtime/adapter/model/message-assembly.d.ts +6 -0
- package/dist/runtime/adapter/model/message-assembly.js +21 -0
- package/dist/runtime/adapter/model/model-providers.d.ts +2 -0
- package/dist/runtime/adapter/model/model-providers.js +27 -0
- package/dist/runtime/adapter/resilience.d.ts +12 -0
- package/dist/runtime/adapter/resilience.js +60 -0
- package/dist/runtime/{declared-middleware.d.ts → adapter/tool/declared-middleware.d.ts} +1 -1
- package/dist/runtime/adapter/tool/interrupt-policy.d.ts +8 -0
- package/dist/runtime/adapter/tool/interrupt-policy.js +34 -0
- package/dist/runtime/adapter/tool/provider-tool.d.ts +2 -0
- package/dist/runtime/adapter/tool/provider-tool.js +25 -0
- package/dist/runtime/adapter/tool/resolved-tool.d.ts +18 -0
- package/dist/runtime/adapter/tool/resolved-tool.js +62 -0
- package/dist/runtime/adapter/tool/tool-arguments.d.ts +7 -0
- package/dist/runtime/adapter/tool/tool-arguments.js +87 -0
- package/dist/runtime/{tool-hitl.d.ts → adapter/tool/tool-hitl.d.ts} +2 -2
- package/dist/runtime/adapter/tool/tool-name-mapping.d.ts +13 -0
- package/dist/runtime/adapter/tool/tool-name-mapping.js +101 -0
- package/dist/runtime/agent-runtime-adapter.d.ts +5 -20
- package/dist/runtime/agent-runtime-adapter.js +33 -536
- package/dist/runtime/checkpoint-maintenance.d.ts +1 -45
- package/dist/runtime/checkpoint-maintenance.js +1 -259
- package/dist/runtime/file-checkpoint-saver.d.ts +1 -20
- package/dist/runtime/file-checkpoint-saver.js +1 -106
- package/dist/runtime/{event-bus.d.ts → harness/events/event-bus.d.ts} +1 -1
- package/dist/runtime/{event-sink.d.ts → harness/events/event-sink.d.ts} +1 -1
- package/dist/runtime/{event-sink.js → harness/events/event-sink.js} +1 -1
- package/dist/runtime/harness/events/events.d.ts +23 -0
- package/dist/runtime/harness/events/events.js +61 -0
- package/dist/runtime/harness/events/streaming.d.ts +19 -0
- package/dist/runtime/harness/events/streaming.js +96 -0
- package/dist/runtime/harness/index.d.ts +16 -0
- package/dist/runtime/harness/index.js +16 -0
- package/dist/runtime/harness/run/helpers.d.ts +33 -0
- package/dist/runtime/harness/run/helpers.js +74 -0
- package/dist/runtime/harness/run/resources.d.ts +7 -0
- package/dist/runtime/harness/run/resources.js +58 -0
- package/dist/runtime/harness/run/resume.d.ts +6 -0
- package/dist/runtime/harness/run/resume.js +56 -0
- package/dist/runtime/harness/run/routing.d.ts +12 -0
- package/dist/runtime/harness/run/routing.js +47 -0
- package/dist/runtime/harness/run/run-lifecycle.d.ts +37 -0
- package/dist/runtime/harness/run/run-lifecycle.js +109 -0
- package/dist/runtime/harness/run/run-queue.d.ts +17 -0
- package/dist/runtime/harness/run/run-queue.js +43 -0
- package/dist/runtime/{health-monitor.d.ts → harness/system/health-monitor.d.ts} +3 -3
- package/dist/runtime/{health-monitor.js → harness/system/health-monitor.js} +2 -2
- package/dist/runtime/{inventory.d.ts → harness/system/inventory.d.ts} +2 -2
- package/dist/runtime/{inventory.js → harness/system/inventory.js} +4 -4
- package/dist/runtime/{policy-engine.d.ts → harness/system/policy-engine.d.ts} +1 -1
- package/dist/runtime/{policy-engine.js → harness/system/policy-engine.js} +1 -1
- package/dist/runtime/{skill-requirements.d.ts → harness/system/skill-requirements.d.ts} +1 -1
- package/dist/runtime/{skill-requirements.js → harness/system/skill-requirements.js} +1 -1
- package/dist/runtime/{thread-memory-sync.d.ts → harness/system/thread-memory-sync.d.ts} +2 -2
- package/dist/runtime/{thread-memory-sync.js → harness/system/thread-memory-sync.js} +1 -1
- package/dist/runtime/harness.d.ts +2 -8
- package/dist/runtime/harness.js +143 -493
- package/dist/runtime/index.d.ts +7 -7
- package/dist/runtime/index.js +7 -7
- package/dist/runtime/maintenance/checkpoint-maintenance.d.ts +45 -0
- package/dist/runtime/maintenance/checkpoint-maintenance.js +259 -0
- package/dist/runtime/maintenance/file-checkpoint-saver.d.ts +20 -0
- package/dist/runtime/maintenance/file-checkpoint-saver.js +106 -0
- package/dist/runtime/maintenance/index.d.ts +4 -0
- package/dist/runtime/maintenance/index.js +4 -0
- package/dist/runtime/{runtime-record-maintenance.d.ts → maintenance/runtime-record-maintenance.d.ts} +1 -1
- package/dist/runtime/{runtime-record-maintenance.js → maintenance/runtime-record-maintenance.js} +2 -2
- package/dist/runtime/maintenance/sqlite-maintained-checkpoint-saver.d.ts +9 -0
- package/dist/runtime/maintenance/sqlite-maintained-checkpoint-saver.js +39 -0
- package/dist/runtime/sqlite-maintained-checkpoint-saver.d.ts +1 -9
- package/dist/runtime/sqlite-maintained-checkpoint-saver.js +1 -39
- package/dist/runtime/support/harness-support.d.ts +4 -4
- package/dist/runtime/support/runtime-factories.d.ts +1 -1
- package/dist/runtime/support/runtime-factories.js +1 -1
- package/package.json +4 -4
- /package/dist/runtime/{langgraph-presets.d.ts → adapter/langgraph/presets.d.ts} +0 -0
- /package/dist/runtime/{langgraph-presets.js → adapter/langgraph/presets.js} +0 -0
- /package/dist/runtime/{langgraph-profiles.js → adapter/langgraph/profiles.js} +0 -0
- /package/dist/runtime/{declared-middleware.js → adapter/tool/declared-middleware.js} +0 -0
- /package/dist/runtime/{tool-hitl.js → adapter/tool/tool-hitl.js} +0 -0
- /package/dist/runtime/{event-bus.js → harness/events/event-bus.js} +0 -0
- /package/dist/runtime/{store.d.ts → harness/system/store.d.ts} +0 -0
- /package/dist/runtime/{store.js → harness/system/store.js} +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tools as anthropicProviderTools } from "@langchain/anthropic";
|
|
2
|
+
import { tools as openAIProviderTools } from "@langchain/openai";
|
|
3
|
+
import { asRecord } from "./resolved-tool.js";
|
|
4
|
+
export function instantiateProviderTool(compiledTool) {
|
|
5
|
+
const providerTool = asRecord(compiledTool.config?.providerTool);
|
|
6
|
+
const provider = typeof providerTool?.provider === "string" ? providerTool.provider.trim().toLowerCase() : "";
|
|
7
|
+
const toolName = typeof providerTool?.tool === "string" ? providerTool.tool.trim() : "";
|
|
8
|
+
const args = asRecord(providerTool?.args) ?? {};
|
|
9
|
+
if (!provider || !toolName) {
|
|
10
|
+
throw new Error(`Provider tool ${compiledTool.id} must define providerTool.provider and providerTool.tool`);
|
|
11
|
+
}
|
|
12
|
+
const registry = provider === "openai"
|
|
13
|
+
? openAIProviderTools
|
|
14
|
+
: provider === "anthropic"
|
|
15
|
+
? anthropicProviderTools
|
|
16
|
+
: undefined;
|
|
17
|
+
if (!registry) {
|
|
18
|
+
throw new Error(`Provider tool ${compiledTool.id} uses unsupported provider ${provider}`);
|
|
19
|
+
}
|
|
20
|
+
const factory = registry[toolName];
|
|
21
|
+
if (typeof factory !== "function") {
|
|
22
|
+
throw new Error(`Provider tool ${compiledTool.id} references unknown ${provider} tool ${toolName}`);
|
|
23
|
+
}
|
|
24
|
+
return factory(args);
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export type ResolvedToolLike = {
|
|
3
|
+
name?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
schema?: {
|
|
6
|
+
parse?: (input: unknown) => unknown;
|
|
7
|
+
};
|
|
8
|
+
invoke?: (input: unknown, config?: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
9
|
+
call?: (input: unknown, config?: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
10
|
+
func?: (input: unknown, config?: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
11
|
+
};
|
|
12
|
+
export declare function asRecord(value: unknown): Record<string, unknown> | undefined;
|
|
13
|
+
export declare function wrapResolvedToolWithModelFacingName<T>(resolvedTool: T, modelFacingName: string): T;
|
|
14
|
+
export declare function hasCallableToolHandler(value: unknown): value is ResolvedToolLike;
|
|
15
|
+
export declare function normalizeResolvedToolSchema(resolvedTool: ResolvedToolLike): Record<string, unknown> | {
|
|
16
|
+
parse?: (input: unknown) => unknown;
|
|
17
|
+
} | z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">> | undefined;
|
|
18
|
+
export declare function asStructuredExecutableTool(resolvedTool: unknown, modelFacingName: string, description: string): unknown;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool as createLangChainTool } from "@langchain/core/tools";
|
|
3
|
+
export function asRecord(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
5
|
+
? { ...value }
|
|
6
|
+
: undefined;
|
|
7
|
+
}
|
|
8
|
+
export function wrapResolvedToolWithModelFacingName(resolvedTool, modelFacingName) {
|
|
9
|
+
if (typeof resolvedTool !== "object" || resolvedTool === null) {
|
|
10
|
+
return resolvedTool;
|
|
11
|
+
}
|
|
12
|
+
return new Proxy(resolvedTool, {
|
|
13
|
+
get(target, prop, receiver) {
|
|
14
|
+
if (prop === "name") {
|
|
15
|
+
return modelFacingName;
|
|
16
|
+
}
|
|
17
|
+
return Reflect.get(target, prop, receiver);
|
|
18
|
+
},
|
|
19
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
20
|
+
if (prop === "name") {
|
|
21
|
+
return {
|
|
22
|
+
configurable: true,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
writable: false,
|
|
25
|
+
value: modelFacingName,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function hasCallableToolHandler(value) {
|
|
33
|
+
if (typeof value !== "object" || value === null) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
const typed = value;
|
|
37
|
+
return typeof typed.invoke === "function" || typeof typed.call === "function" || typeof typed.func === "function";
|
|
38
|
+
}
|
|
39
|
+
export function normalizeResolvedToolSchema(resolvedTool) {
|
|
40
|
+
const schema = resolvedTool.schema;
|
|
41
|
+
if (schema && typeof schema.parse === "function" && "_def" in schema) {
|
|
42
|
+
return resolvedTool.schema;
|
|
43
|
+
}
|
|
44
|
+
if (schema && (schema.type === "object" || typeof schema.properties === "object")) {
|
|
45
|
+
return schema;
|
|
46
|
+
}
|
|
47
|
+
return z.object({}).passthrough();
|
|
48
|
+
}
|
|
49
|
+
export function asStructuredExecutableTool(resolvedTool, modelFacingName, description) {
|
|
50
|
+
if (!hasCallableToolHandler(resolvedTool)) {
|
|
51
|
+
return resolvedTool;
|
|
52
|
+
}
|
|
53
|
+
const handler = resolvedTool.invoke ?? resolvedTool.call ?? resolvedTool.func;
|
|
54
|
+
if (typeof handler !== "function") {
|
|
55
|
+
return resolvedTool;
|
|
56
|
+
}
|
|
57
|
+
return createLangChainTool(async (input, config) => handler(input, config), {
|
|
58
|
+
name: modelFacingName,
|
|
59
|
+
description,
|
|
60
|
+
schema: normalizeResolvedToolSchema(resolvedTool),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function stringifyToolOutput(output: unknown): string;
|
|
2
|
+
export declare function normalizeToolArgsForSchema(args: Record<string, unknown>, schema: unknown): Record<string, unknown>;
|
|
3
|
+
export declare function extractToolCallsFromResult(result: unknown): Array<{
|
|
4
|
+
id?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
args: Record<string, unknown>;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { salvageToolArgs } from "../../parsing/output-parsing.js";
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function isObject(value) {
|
|
6
|
+
return isRecord(value);
|
|
7
|
+
}
|
|
8
|
+
export function stringifyToolOutput(output) {
|
|
9
|
+
if (typeof output === "string") {
|
|
10
|
+
return output;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return JSON.stringify(output);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return `${String(output)}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function normalizeToolArgsForSchema(args, schema) {
|
|
20
|
+
const schemaDef = isObject(schema) ? schema._def : undefined;
|
|
21
|
+
const shape = schemaDef
|
|
22
|
+
? isRecord(schemaDef.shape)
|
|
23
|
+
? schemaDef.shape
|
|
24
|
+
: typeof schemaDef.shape === "function"
|
|
25
|
+
? schemaDef.shape()
|
|
26
|
+
: undefined
|
|
27
|
+
: undefined;
|
|
28
|
+
if (!shape || !isRecord(shape)) {
|
|
29
|
+
return args;
|
|
30
|
+
}
|
|
31
|
+
const keys = Object.keys(shape);
|
|
32
|
+
if (keys.length !== 1) {
|
|
33
|
+
return args;
|
|
34
|
+
}
|
|
35
|
+
const [expectedKey] = keys;
|
|
36
|
+
if (expectedKey in args) {
|
|
37
|
+
return args;
|
|
38
|
+
}
|
|
39
|
+
const aliasesByExpected = {
|
|
40
|
+
city: ["location", "locality", "place"],
|
|
41
|
+
location: ["city", "city_name"],
|
|
42
|
+
};
|
|
43
|
+
const aliases = aliasesByExpected[expectedKey] ?? [];
|
|
44
|
+
const aliasKey = aliases.find((candidate) => candidate in args);
|
|
45
|
+
if (!aliasKey || !(aliasKey in args)) {
|
|
46
|
+
return args;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...args,
|
|
50
|
+
[expectedKey]: args[aliasKey],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function extractToolCallsFromResult(result) {
|
|
54
|
+
const messages = isRecord(result) && Array.isArray(result.messages) ? result.messages : [];
|
|
55
|
+
const lastMessage = messages.at(-1);
|
|
56
|
+
if (!isObject(lastMessage)) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const messageKwargs = isObject(lastMessage.kwargs) ? lastMessage.kwargs : undefined;
|
|
60
|
+
const rawToolCalls = Array.isArray(lastMessage.tool_calls)
|
|
61
|
+
? (lastMessage.tool_calls ?? [])
|
|
62
|
+
: Array.isArray(messageKwargs?.tool_calls)
|
|
63
|
+
? messageKwargs.tool_calls
|
|
64
|
+
: [];
|
|
65
|
+
return rawToolCalls
|
|
66
|
+
.map((toolCall) => {
|
|
67
|
+
if (!isObject(toolCall)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const functionPayload = isObject(toolCall.function) ? toolCall.function : undefined;
|
|
71
|
+
const name = typeof toolCall.name === "string"
|
|
72
|
+
? toolCall.name
|
|
73
|
+
: typeof functionPayload?.name === "string"
|
|
74
|
+
? functionPayload.name
|
|
75
|
+
: null;
|
|
76
|
+
if (!name) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const rawArgs = salvageToolArgs(toolCall.args ?? functionPayload?.arguments) ?? {};
|
|
80
|
+
if (!isObject(rawArgs)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const id = typeof toolCall.id === "string" ? toolCall.id : undefined;
|
|
84
|
+
return { id, name, args: rawArgs };
|
|
85
|
+
})
|
|
86
|
+
.filter((item) => item !== null);
|
|
87
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CompiledTool } from "
|
|
2
|
-
import type { CompiledAgentBinding } from "
|
|
1
|
+
import type { CompiledTool } from "../../../contracts/types.js";
|
|
2
|
+
import type { CompiledAgentBinding } from "../../../contracts/types.js";
|
|
3
3
|
type InterruptFn = <I = unknown, R = unknown>(value: I) => R;
|
|
4
4
|
export declare function wrapToolForHumanInTheLoop<T>(resolvedTool: T, compiledTool: CompiledTool, interruptFn?: InterruptFn): T;
|
|
5
5
|
export declare function wrapToolForExecution<T>(resolvedTool: T, compiledTool: CompiledTool, binding?: CompiledAgentBinding, interruptFn?: InterruptFn): T;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ToolNameMapping = {
|
|
2
|
+
originalToModelFacing: Map<string, string>;
|
|
3
|
+
modelFacingToOriginal: Map<string, string>;
|
|
4
|
+
};
|
|
5
|
+
export declare function sanitizeToolNameForModel(name: string): string;
|
|
6
|
+
export declare function buildToolNameMapping(tools: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
}>): ToolNameMapping;
|
|
9
|
+
export declare function createModelFacingToolNameCandidates(toolName: string): string[];
|
|
10
|
+
export declare function createModelFacingToolNameLookupCandidates(toolName: string): string[];
|
|
11
|
+
export declare function resolveModelFacingToolName(toolName: string, mapping: ToolNameMapping, tools: Array<{
|
|
12
|
+
name: string;
|
|
13
|
+
}>): string;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const MODEL_SAFE_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
2
|
+
export function sanitizeToolNameForModel(name) {
|
|
3
|
+
const withoutNamespace = name.includes(".") ? name.split(".").at(-1) ?? name : name;
|
|
4
|
+
const sanitized = withoutNamespace
|
|
5
|
+
.replaceAll(".", "__")
|
|
6
|
+
.replace(/[^a-zA-Z0-9_-]+/g, "_")
|
|
7
|
+
.replace(/^_+|_+$/g, "");
|
|
8
|
+
return sanitized || "tool";
|
|
9
|
+
}
|
|
10
|
+
export function buildToolNameMapping(tools) {
|
|
11
|
+
const originalToModelFacing = new Map();
|
|
12
|
+
const modelFacingToOriginal = new Map();
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
for (const tool of tools) {
|
|
15
|
+
const originalName = tool.name;
|
|
16
|
+
const baseName = MODEL_SAFE_TOOL_NAME_PATTERN.test(originalName) ? originalName : sanitizeToolNameForModel(originalName);
|
|
17
|
+
let candidate = baseName;
|
|
18
|
+
let suffix = 2;
|
|
19
|
+
while (seen.has(candidate)) {
|
|
20
|
+
candidate = `${baseName}_${suffix}`;
|
|
21
|
+
suffix += 1;
|
|
22
|
+
}
|
|
23
|
+
seen.add(candidate);
|
|
24
|
+
originalToModelFacing.set(originalName, candidate);
|
|
25
|
+
modelFacingToOriginal.set(candidate, originalName);
|
|
26
|
+
}
|
|
27
|
+
return { originalToModelFacing, modelFacingToOriginal };
|
|
28
|
+
}
|
|
29
|
+
export function createModelFacingToolNameCandidates(toolName) {
|
|
30
|
+
const trimmed = toolName.trim();
|
|
31
|
+
if (!trimmed) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const lastSegment = trimmed.split(".").at(-1) ?? "";
|
|
35
|
+
const candidates = new Set([
|
|
36
|
+
trimmed,
|
|
37
|
+
sanitizeToolNameForModel(trimmed),
|
|
38
|
+
lastSegment,
|
|
39
|
+
lastSegment.trim() ? sanitizeToolNameForModel(lastSegment) : "",
|
|
40
|
+
trimmed.replace(/[^a-zA-Z0-9_]+/g, ""),
|
|
41
|
+
]);
|
|
42
|
+
candidates.delete("");
|
|
43
|
+
return [...candidates];
|
|
44
|
+
}
|
|
45
|
+
export function createModelFacingToolNameLookupCandidates(toolName) {
|
|
46
|
+
const trimmed = toolName.trim();
|
|
47
|
+
if (!trimmed) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const candidates = new Set();
|
|
51
|
+
const add = (value) => {
|
|
52
|
+
for (const candidate of createModelFacingToolNameCandidates(value)) {
|
|
53
|
+
candidates.add(candidate);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const addSuffixStripped = (value) => {
|
|
57
|
+
const stripped = value.includes(".") ? value.split(".").at(-1) ?? value : value;
|
|
58
|
+
if (stripped !== value) {
|
|
59
|
+
add(stripped);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
add(trimmed);
|
|
63
|
+
if (trimmed.startsWith("functions.")) {
|
|
64
|
+
const stripped = trimmed.substring("functions.".length);
|
|
65
|
+
add(stripped);
|
|
66
|
+
addSuffixStripped(stripped);
|
|
67
|
+
}
|
|
68
|
+
else if (trimmed.startsWith("function.")) {
|
|
69
|
+
const stripped = trimmed.substring("function.".length);
|
|
70
|
+
add(stripped);
|
|
71
|
+
addSuffixStripped(stripped);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
addSuffixStripped(trimmed);
|
|
75
|
+
}
|
|
76
|
+
return [...candidates];
|
|
77
|
+
}
|
|
78
|
+
export function resolveModelFacingToolName(toolName, mapping, tools) {
|
|
79
|
+
const candidateNames = createModelFacingToolNameLookupCandidates(toolName);
|
|
80
|
+
const candidateSet = new Set(candidateNames);
|
|
81
|
+
for (const candidate of candidateNames) {
|
|
82
|
+
const mappedToolName = mapping.modelFacingToOriginal.get(candidate);
|
|
83
|
+
if (mappedToolName) {
|
|
84
|
+
return mappedToolName;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const candidate of candidateNames) {
|
|
88
|
+
const directMatch = tools.find((tool) => tool.name === candidate);
|
|
89
|
+
if (directMatch) {
|
|
90
|
+
return directMatch.name;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const candidateMatches = tools.filter((tool) => {
|
|
94
|
+
const modelFacingCandidates = createModelFacingToolNameCandidates(tool.name);
|
|
95
|
+
return modelFacingCandidates.some((candidate) => candidateSet.has(candidate));
|
|
96
|
+
});
|
|
97
|
+
if (candidateMatches.length === 1) {
|
|
98
|
+
return candidateMatches[0].name;
|
|
99
|
+
}
|
|
100
|
+
return toolName;
|
|
101
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type { CompiledAgentBinding,
|
|
1
|
+
import type { CompiledAgentBinding, MessageContent, RunResult, RuntimeAdapterOptions, TranscriptMessage } from "../contracts/types.js";
|
|
2
2
|
import { type RuntimeStreamChunk } from "./parsing/stream-event-parsing.js";
|
|
3
|
+
export { applyDeepAgentDelegationPromptCompatibility, materializeDeepAgentSkillSourcePaths, relativizeDeepAgentSkillSourcePaths, shouldRelaxDeepAgentDelegationPrompt, } from "./adapter/compat/deepagent-compat.js";
|
|
4
|
+
export { buildAuthOmittingFetch, normalizeOpenAICompatibleInit } from "./adapter/compat/openai-compatible.js";
|
|
5
|
+
export { buildToolNameMapping, createModelFacingToolNameCandidates, createModelFacingToolNameLookupCandidates, resolveModelFacingToolName, sanitizeToolNameForModel, } from "./adapter/tool/tool-name-mapping.js";
|
|
6
|
+
export { computeRemainingTimeoutMs, isRetryableProviderError, resolveBindingTimeout, resolveProviderRetryPolicy, resolveStreamIdleTimeout, resolveTimeoutMs, } from "./adapter/resilience.js";
|
|
3
7
|
type RunnableLike = {
|
|
4
8
|
invoke: (input: unknown, config?: Record<string, unknown>) => Promise<unknown>;
|
|
5
9
|
stream?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
|
|
@@ -12,18 +16,6 @@ declare class RuntimeOperationTimeoutError extends Error {
|
|
|
12
16
|
readonly stage: "stream" | "invoke";
|
|
13
17
|
constructor(operation: string, timeoutMs: number, stage?: "stream" | "invoke");
|
|
14
18
|
}
|
|
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>;
|
|
22
|
-
export declare function shouldRelaxDeepAgentDelegationPrompt(model: CompiledModel | undefined, params: {
|
|
23
|
-
subagents?: CompiledSubAgent[];
|
|
24
|
-
generalPurposeAgent?: boolean;
|
|
25
|
-
taskDescription?: string;
|
|
26
|
-
}): boolean;
|
|
27
19
|
export declare class AgentRuntimeAdapter {
|
|
28
20
|
private readonly options;
|
|
29
21
|
private readonly modelCache;
|
|
@@ -31,10 +23,6 @@ export declare class AgentRuntimeAdapter {
|
|
|
31
23
|
private readonly langGraphSessions;
|
|
32
24
|
constructor(options?: RuntimeAdapterOptions);
|
|
33
25
|
private getModelCacheKey;
|
|
34
|
-
private resolveBindingTimeout;
|
|
35
|
-
private resolveStreamIdleTimeout;
|
|
36
|
-
private resolveProviderRetryPolicy;
|
|
37
|
-
private isRetryableProviderError;
|
|
38
26
|
private invokeWithProviderRetry;
|
|
39
27
|
private withTimeout;
|
|
40
28
|
private iterateWithTimeout;
|
|
@@ -43,13 +31,10 @@ export declare class AgentRuntimeAdapter {
|
|
|
43
31
|
private applyStrictToolJsonInstruction;
|
|
44
32
|
private resolveModel;
|
|
45
33
|
private buildToolNameMapping;
|
|
46
|
-
private buildAgentMessages;
|
|
47
34
|
private buildSlashCommandSkillInstruction;
|
|
48
35
|
private buildInvocationRequest;
|
|
49
|
-
private buildStateSnapshot;
|
|
50
36
|
private buildRawModelMessages;
|
|
51
37
|
private resolveTools;
|
|
52
|
-
private normalizeInterruptPolicy;
|
|
53
38
|
private compileInterruptOn;
|
|
54
39
|
private resolveInterruptOn;
|
|
55
40
|
private resolveFilesystemBackend;
|