@botbotgo/agent-harness 0.0.100 → 0.0.102
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/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/sqlite-run-context-store.d.ts +22 -0
- package/dist/persistence/sqlite-run-context-store.js +64 -0
- package/dist/persistence/sqlite-run-queue-store.d.ts +41 -0
- package/dist/persistence/sqlite-run-queue-store.js +120 -0
- package/dist/persistence/sqlite-store.d.ts +2 -2
- package/dist/persistence/sqlite-store.js +31 -117
- package/dist/resource/mcp-tool-support.d.ts +21 -0
- package/dist/resource/mcp-tool-support.js +173 -0
- package/dist/resource/resource-impl.d.ts +1 -18
- package/dist/resource/resource-impl.js +79 -240
- package/dist/runtime/adapter/invoke-runtime.d.ts +22 -0
- package/dist/runtime/adapter/invoke-runtime.js +18 -0
- package/dist/runtime/adapter/stream-runtime.d.ts +46 -0
- package/dist/runtime/adapter/stream-runtime.js +93 -0
- package/dist/runtime/agent-runtime-adapter.d.ts +1 -12
- package/dist/runtime/agent-runtime-adapter.js +122 -312
- package/dist/runtime/harness/run/recovery.d.ts +42 -0
- package/dist/runtime/harness/run/recovery.js +139 -0
- package/dist/runtime/harness/run/run-operations.d.ts +50 -0
- package/dist/runtime/harness/run/run-operations.js +113 -0
- package/dist/runtime/harness/run/run-slot-acquisition.d.ts +64 -0
- package/dist/runtime/harness/run/run-slot-acquisition.js +157 -0
- package/dist/runtime/harness/run/stream-run.d.ts +53 -0
- package/dist/runtime/harness/run/stream-run.js +304 -0
- package/dist/runtime/harness.d.ts +2 -17
- package/dist/runtime/harness.js +157 -773
- package/dist/runtime/support/runtime-factories.js +2 -2
- package/dist/workspace/object-loader.d.ts +1 -8
- package/dist/workspace/object-loader.js +43 -275
- package/dist/workspace/yaml-object-reader.d.ts +15 -0
- package/dist/workspace/yaml-object-reader.js +202 -0
- package/package.json +1 -1
- package/dist/runtime/checkpoint-maintenance.d.ts +0 -1
- package/dist/runtime/checkpoint-maintenance.js +0 -1
- package/dist/runtime/file-checkpoint-saver.d.ts +0 -1
- package/dist/runtime/file-checkpoint-saver.js +0 -1
- package/dist/runtime/sqlite-maintained-checkpoint-saver.d.ts +0 -1
- package/dist/runtime/sqlite-maintained-checkpoint-saver.js +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { CompiledAgentBinding, CompiledTool, MessageContent, TranscriptMessage } from "../../contracts/types.js";
|
|
2
|
+
import type { RuntimeStreamChunk } from "../parsing/stream-event-parsing.js";
|
|
3
|
+
import type { ToolNameMapping } from "./tool/tool-name-mapping.js";
|
|
4
|
+
type RunnableLike = {
|
|
5
|
+
stream?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
|
|
6
|
+
streamEvents?: (input: unknown, config?: Record<string, unknown>) => Promise<AsyncIterable<unknown>>;
|
|
7
|
+
};
|
|
8
|
+
export declare function streamRuntimeExecution(options: {
|
|
9
|
+
binding: CompiledAgentBinding;
|
|
10
|
+
input: MessageContent;
|
|
11
|
+
threadId: string;
|
|
12
|
+
history: TranscriptMessage[];
|
|
13
|
+
runtimeOptions: {
|
|
14
|
+
context?: Record<string, unknown>;
|
|
15
|
+
state?: Record<string, unknown>;
|
|
16
|
+
files?: Record<string, unknown>;
|
|
17
|
+
runId?: string;
|
|
18
|
+
};
|
|
19
|
+
primaryTools: CompiledTool[];
|
|
20
|
+
toolNameMapping: ToolNameMapping;
|
|
21
|
+
forceInvokeFallback: boolean;
|
|
22
|
+
canUseDirectModelStream: boolean;
|
|
23
|
+
langChainStreamModel?: {
|
|
24
|
+
stream?: (input: unknown) => Promise<AsyncIterable<unknown>>;
|
|
25
|
+
};
|
|
26
|
+
createRunnable: () => Promise<RunnableLike>;
|
|
27
|
+
withTimeout: <T>(producer: () => T | Promise<T>, timeoutMs: number | undefined, operation: string, stage?: "stream" | "invoke") => Promise<T>;
|
|
28
|
+
iterateWithTimeout: <T>(iterable: AsyncIterable<T>, timeoutMs: number | undefined, operation: string, deadlineAt?: number, deadlineTimeoutMs?: number) => AsyncGenerator<T>;
|
|
29
|
+
invokeTimeoutMs?: number;
|
|
30
|
+
streamIdleTimeoutMs?: number;
|
|
31
|
+
streamDeadlineAt?: number;
|
|
32
|
+
invoke: (binding: CompiledAgentBinding, input: MessageContent, threadId: string, runId: string, resumePayload?: unknown, history?: TranscriptMessage[], options?: {
|
|
33
|
+
context?: Record<string, unknown>;
|
|
34
|
+
state?: Record<string, unknown>;
|
|
35
|
+
files?: Record<string, unknown>;
|
|
36
|
+
}) => Promise<{
|
|
37
|
+
output: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}>;
|
|
40
|
+
applyStrictToolJsonInstruction: (binding: CompiledAgentBinding) => CompiledAgentBinding;
|
|
41
|
+
getSystemPrompt: (binding: CompiledAgentBinding) => string | undefined;
|
|
42
|
+
isLangChainBinding: (binding: CompiledAgentBinding) => boolean;
|
|
43
|
+
isDeepAgentBinding: (binding: CompiledAgentBinding) => boolean;
|
|
44
|
+
countConfiguredTools: (binding: CompiledAgentBinding) => number;
|
|
45
|
+
}): AsyncGenerator<RuntimeStreamChunk | string>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isToolCallParseFailure, sanitizeVisibleText, } from "../parsing/output-parsing.js";
|
|
2
|
+
import { buildInvocationRequest } from "./model/invocation-request.js";
|
|
3
|
+
import { buildRawModelMessages } from "./model/message-assembly.js";
|
|
4
|
+
import { projectRuntimeStreamEvent, createStreamEventProjectionState } from "./stream-event-projection.js";
|
|
5
|
+
import { projectTextStreamChunks } from "./stream-text-consumption.js";
|
|
6
|
+
import { computeRemainingTimeoutMs } from "./resilience.js";
|
|
7
|
+
export async function* streamRuntimeExecution(options) {
|
|
8
|
+
const request = buildInvocationRequest(options.binding, options.history, options.input, options.runtimeOptions);
|
|
9
|
+
try {
|
|
10
|
+
if (options.isLangChainBinding(options.binding) && options.canUseDirectModelStream && options.langChainStreamModel?.stream) {
|
|
11
|
+
const stream = await options.withTimeout(() => options.langChainStreamModel.stream(buildRawModelMessages(options.binding, options.getSystemPrompt(options.binding), options.history, options.input)), computeRemainingTimeoutMs(options.streamDeadlineAt, options.invokeTimeoutMs), "model stream start", "stream");
|
|
12
|
+
let emitted = false;
|
|
13
|
+
const projected = projectTextStreamChunks(options.iterateWithTimeout(stream, options.streamIdleTimeoutMs, "model stream", options.streamDeadlineAt, options.invokeTimeoutMs));
|
|
14
|
+
let nextChunk = await projected.next();
|
|
15
|
+
while (!nextChunk.done) {
|
|
16
|
+
if (nextChunk.value.kind === "content") {
|
|
17
|
+
emitted = true;
|
|
18
|
+
}
|
|
19
|
+
yield nextChunk.value;
|
|
20
|
+
nextChunk = await projected.next();
|
|
21
|
+
}
|
|
22
|
+
if (nextChunk.value.emittedContent || emitted) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const runnable = await options.createRunnable();
|
|
27
|
+
if (!options.forceInvokeFallback && typeof runnable.streamEvents === "function") {
|
|
28
|
+
const events = await options.withTimeout(() => runnable.streamEvents(request, { configurable: { thread_id: options.threadId, run_id: options.runtimeOptions.runId }, version: "v2", ...(options.runtimeOptions.context ? { context: options.runtimeOptions.context } : {}) }), computeRemainingTimeoutMs(options.streamDeadlineAt, options.invokeTimeoutMs), "agent streamEvents start", "stream");
|
|
29
|
+
const projectionState = createStreamEventProjectionState();
|
|
30
|
+
for await (const event of options.iterateWithTimeout(events, options.streamIdleTimeoutMs, "agent streamEvents", options.streamDeadlineAt, options.invokeTimeoutMs)) {
|
|
31
|
+
const projectedChunks = projectRuntimeStreamEvent({
|
|
32
|
+
event,
|
|
33
|
+
allowVisibleStreamDeltas: options.isLangChainBinding(options.binding),
|
|
34
|
+
includeStateStreamOutput: options.isDeepAgentBinding(options.binding),
|
|
35
|
+
toolNameMapping: options.toolNameMapping,
|
|
36
|
+
primaryTools: options.primaryTools,
|
|
37
|
+
state: projectionState,
|
|
38
|
+
});
|
|
39
|
+
for (const chunk of projectedChunks) {
|
|
40
|
+
yield chunk;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (projectionState.emittedOutput || projectionState.emittedToolResult || projectionState.emittedToolError) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!options.forceInvokeFallback && options.isLangChainBinding(options.binding) && typeof runnable.stream === "function") {
|
|
48
|
+
const stream = await options.withTimeout(() => runnable.stream(request, { configurable: { thread_id: options.threadId, run_id: options.runtimeOptions.runId } }), computeRemainingTimeoutMs(options.streamDeadlineAt, options.invokeTimeoutMs), "agent stream start", "stream");
|
|
49
|
+
let emitted = false;
|
|
50
|
+
const projected = projectTextStreamChunks(options.iterateWithTimeout(stream, options.streamIdleTimeoutMs, "agent stream", options.streamDeadlineAt, options.invokeTimeoutMs));
|
|
51
|
+
let nextChunk = await projected.next();
|
|
52
|
+
while (!nextChunk.done) {
|
|
53
|
+
if (nextChunk.value.kind === "content") {
|
|
54
|
+
emitted = true;
|
|
55
|
+
}
|
|
56
|
+
yield nextChunk.value;
|
|
57
|
+
nextChunk = await projected.next();
|
|
58
|
+
}
|
|
59
|
+
if (nextChunk.value.emittedContent || emitted) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const result = await options.invoke(options.binding, options.input, options.threadId, options.runtimeOptions.runId ?? options.threadId, undefined, options.history, options.runtimeOptions);
|
|
64
|
+
const executedToolResults = Array.isArray(result.metadata?.executedToolResults)
|
|
65
|
+
? result.metadata.executedToolResults
|
|
66
|
+
: [];
|
|
67
|
+
for (const toolResult of executedToolResults) {
|
|
68
|
+
yield {
|
|
69
|
+
kind: "tool-result",
|
|
70
|
+
toolName: toolResult.toolName,
|
|
71
|
+
output: toolResult.output,
|
|
72
|
+
isError: toolResult.isError,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (result.output) {
|
|
76
|
+
yield { kind: "content", content: sanitizeVisibleText(result.output) };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (options.countConfiguredTools(options.binding) > 0 &&
|
|
81
|
+
error instanceof Error &&
|
|
82
|
+
error.message.includes("does not support tool binding")) {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
if (!isToolCallParseFailure(error)) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
const retried = await options.invoke(options.applyStrictToolJsonInstruction(options.binding), options.input, options.threadId, options.runtimeOptions.runId ?? options.threadId, undefined, options.history, options.runtimeOptions);
|
|
89
|
+
if (retried.output) {
|
|
90
|
+
yield { kind: "content", content: sanitizeVisibleText(retried.output) };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -29,28 +29,17 @@ export declare class AgentRuntimeAdapter {
|
|
|
29
29
|
private createModelFallbackRunnable;
|
|
30
30
|
private applyStrictToolJsonInstruction;
|
|
31
31
|
private resolveModel;
|
|
32
|
-
private buildToolNameMapping;
|
|
33
|
-
private buildSlashCommandSkillInstruction;
|
|
34
|
-
private buildInvocationRequest;
|
|
35
|
-
private buildRawModelMessages;
|
|
36
32
|
private resolveTools;
|
|
37
|
-
private compileInterruptOn;
|
|
38
|
-
private resolveInterruptOn;
|
|
39
33
|
private resolveFilesystemBackend;
|
|
40
34
|
private resolveBuiltinMiddlewareBackend;
|
|
35
|
+
private createDeclaredMiddlewareResolverOptions;
|
|
41
36
|
private invokeBuiltinTaskTool;
|
|
42
37
|
private resolveBuiltinMiddlewareTools;
|
|
43
38
|
private resolveAutomaticSummarizationMiddleware;
|
|
44
39
|
private resolveLangChainAutomaticMiddleware;
|
|
45
|
-
private resolveDeepAgentAutomaticMiddleware;
|
|
46
40
|
private resolveMiddleware;
|
|
47
|
-
private resolveCheckpointer;
|
|
48
41
|
private resolveSubagents;
|
|
49
42
|
private createLangChainRunnable;
|
|
50
|
-
private extractInvocationRequestText;
|
|
51
|
-
private prependSystemMessage;
|
|
52
|
-
private replaceLastUserMessage;
|
|
53
|
-
private extractExecutedToolResults;
|
|
54
43
|
private createRunnable;
|
|
55
44
|
private createDeepAgentRunnable;
|
|
56
45
|
create(binding: CompiledAgentBinding): Promise<RunnableLike>;
|