@mono-agent/agent-runtime 0.4.0 → 0.5.0
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/ARCHITECTURE.md +37 -16
- package/MIGRATION.md +185 -7
- package/README.md +24 -14
- package/package.json +103 -10
- package/src/agent/allowlists.js +3 -0
- package/src/agent/approval.js +3 -0
- package/src/agent/compaction.js +244 -1
- package/src/agent/prompt/skill-index.js +6 -0
- package/src/agent/sandbox-seam.js +227 -0
- package/src/agent/tool-bloat.js +8 -2
- package/src/agent/tools/bash.js +16 -8
- package/src/agent/tools/edit.js +7 -3
- package/src/agent/tools/glob.js +11 -5
- package/src/agent/tools/grep.js +11 -5
- package/src/agent/tools/pi-bridge.js +227 -45
- package/src/agent/tools/read.js +28 -3
- package/src/agent/tools/shared/output-truncation.js +8 -3
- package/src/agent/tools/shared/path-resolver.js +24 -18
- package/src/agent/tools/shared/ripgrep.js +33 -6
- package/src/agent/tools/shared/runtime-context.js +60 -50
- package/src/agent/tools/shared/tool-context.js +157 -0
- package/src/agent/tools/web-fetch.js +21 -10
- package/src/agent/tools/web-search.js +11 -4
- package/src/agent/tools/write.js +7 -3
- package/src/agent/transcript.js +16 -1
- package/src/ai/cost.js +128 -3
- package/src/ai/failure.js +96 -4
- package/src/ai/live-input-prompt.js +11 -1
- package/src/ai/providers/claude-cli.js +2 -2
- package/src/ai/providers/claude-sdk.js +55 -12
- package/src/ai/providers/codex-app.js +36 -23
- package/src/ai/providers/opencode-app.js +2 -2
- package/src/ai/providers/opencode-discovery.js +2 -2
- package/src/ai/providers/pi-events.js +5 -0
- package/src/ai/providers/pi-models.js +21 -4
- package/src/ai/providers/pi-native/compaction-driver.js +394 -0
- package/src/ai/providers/pi-native/result-builder.js +312 -0
- package/src/ai/providers/pi-native/session-lifecycle.js +438 -0
- package/src/ai/providers/pi-native/stream-subscriber.js +148 -0
- package/src/ai/providers/pi-native/structured-output.js +130 -0
- package/src/ai/providers/pi-native/turn-runner.js +278 -0
- package/src/ai/providers/pi-native.js +415 -1106
- package/src/ai/runtime/model-refs.js +30 -0
- package/src/ai/runtime/registry.js +29 -0
- package/src/ai/runtime/router.js +96 -12
- package/src/ai/runtime/session-liveness.js +110 -0
- package/src/ai/runtime/sessions.js +16 -0
- package/src/ai/types.js +252 -19
- package/src/index.js +1 -1
- package/src/pi-auth.js +147 -16
- package/src/runtime-brand.js +21 -1
- package/src/runtime.js +72 -8
- package/types/agent/allowlists.d.ts +25 -0
- package/types/agent/approval.d.ts +30 -0
- package/types/agent/compaction.d.ts +97 -0
- package/types/agent/index.d.ts +5 -0
- package/types/agent/prompt/skill-index.d.ts +19 -0
- package/types/agent/sandbox-seam.d.ts +148 -0
- package/types/agent/tool-bloat.d.ts +22 -0
- package/types/agent/tools/bash.d.ts +16 -0
- package/types/agent/tools/edit.d.ts +14 -0
- package/types/agent/tools/glob.d.ts +16 -0
- package/types/agent/tools/grep.d.ts +22 -0
- package/types/agent/tools/index.d.ts +10 -0
- package/types/agent/tools/pi-bridge.d.ts +144 -0
- package/types/agent/tools/read.d.ts +19 -0
- package/types/agent/tools/shared/constants.d.ts +13 -0
- package/types/agent/tools/shared/dedup.d.ts +8 -0
- package/types/agent/tools/shared/output-truncation.d.ts +22 -0
- package/types/agent/tools/shared/path-resolver.d.ts +6 -0
- package/types/agent/tools/shared/ripgrep.d.ts +38 -0
- package/types/agent/tools/shared/runtime-context.d.ts +27 -0
- package/types/agent/tools/shared/tool-context.d.ts +48 -0
- package/types/agent/tools/web-fetch.d.ts +13 -0
- package/types/agent/tools/web-search.d.ts +11 -0
- package/types/agent/tools/write.d.ts +12 -0
- package/types/agent/transcript.d.ts +45 -0
- package/types/ai/backend.d.ts +41 -0
- package/types/ai/cost.d.ts +96 -0
- package/types/ai/failure.d.ts +117 -0
- package/types/ai/file-change-stats.d.ts +75 -0
- package/types/ai/index.d.ts +7 -0
- package/types/ai/live-input-prompt.d.ts +6 -0
- package/types/ai/observer.d.ts +68 -0
- package/types/ai/providers/claude-cli.d.ts +211 -0
- package/types/ai/providers/claude-sdk.d.ts +66 -0
- package/types/ai/providers/claude-subagents.d.ts +2 -0
- package/types/ai/providers/codex-app.d.ts +151 -0
- package/types/ai/providers/opencode-app.d.ts +95 -0
- package/types/ai/providers/opencode-discovery.d.ts +4 -0
- package/types/ai/providers/pi-errors.d.ts +3 -0
- package/types/ai/providers/pi-events.d.ts +24 -0
- package/types/ai/providers/pi-messages.d.ts +5 -0
- package/types/ai/providers/pi-models.d.ts +57 -0
- package/types/ai/providers/pi-native/compaction-driver.d.ts +86 -0
- package/types/ai/providers/pi-native/result-builder.d.ts +168 -0
- package/types/ai/providers/pi-native/session-lifecycle.d.ts +62 -0
- package/types/ai/providers/pi-native/stream-subscriber.d.ts +50 -0
- package/types/ai/providers/pi-native/structured-output.d.ts +69 -0
- package/types/ai/providers/pi-native/turn-runner.d.ts +60 -0
- package/types/ai/providers/pi-native.d.ts +18 -0
- package/types/ai/registry.d.ts +1 -0
- package/types/ai/runtime/capabilities-used.d.ts +21 -0
- package/types/ai/runtime/capabilities.d.ts +33 -0
- package/types/ai/runtime/context-windows.d.ts +8 -0
- package/types/ai/runtime/fast-mode.d.ts +2 -0
- package/types/ai/runtime/model-refs.d.ts +35 -0
- package/types/ai/runtime/registry.d.ts +38 -0
- package/types/ai/runtime/router.d.ts +56 -0
- package/types/ai/runtime/session-liveness.d.ts +55 -0
- package/types/ai/runtime/sessions.d.ts +38 -0
- package/types/ai/streaming/codex-events.d.ts +30 -0
- package/types/ai/streaming/opencode-events.d.ts +41 -0
- package/types/ai/types.d.ts +702 -0
- package/types/index.d.ts +7 -0
- package/types/pi-auth.d.ts +28 -0
- package/types/runtime-brand.d.ts +30 -0
- package/types/runtime.d.ts +10 -0
- package/src/ai/providers/pi-sdk.js +0 -35
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {any} _serverName
|
|
3
|
+
* @param {any} toolName
|
|
4
|
+
* @param {any} params
|
|
5
|
+
* @param {{qaOutputDir?: any, ctx?: any}} [options]
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeMcpToolParams(_serverName: any, toolName: any, params: any, { qaOutputDir, ctx }?: {
|
|
8
|
+
qaOutputDir?: any;
|
|
9
|
+
ctx?: any;
|
|
10
|
+
}): any;
|
|
11
|
+
/**
|
|
12
|
+
* @param {any} name
|
|
13
|
+
* @param {any} params
|
|
14
|
+
* @param {{cwd?: any, toolLimits?: any, ctx?: any}} [options]
|
|
15
|
+
*/
|
|
16
|
+
export function normalizePiBuiltinToolParams(name: any, params: any, { cwd, toolLimits, ctx }?: {
|
|
17
|
+
cwd?: any;
|
|
18
|
+
toolLimits?: any;
|
|
19
|
+
ctx?: any;
|
|
20
|
+
}): any;
|
|
21
|
+
export function createStructuredOutputTool(outputSchema: any, onStructuredOutput: any): {
|
|
22
|
+
name: string;
|
|
23
|
+
label: string;
|
|
24
|
+
description: string;
|
|
25
|
+
parameters: Type.TUnsafe<unknown>;
|
|
26
|
+
executionMode: string;
|
|
27
|
+
execute(_toolCallId: any, params: any): Promise<{
|
|
28
|
+
content: {
|
|
29
|
+
type: string;
|
|
30
|
+
text: string;
|
|
31
|
+
}[];
|
|
32
|
+
details: any;
|
|
33
|
+
terminate: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @param {any} allowedTools
|
|
38
|
+
* @param {{skillNames?: any[], skills?: any[], skillsRoot?: any, dataDir?: any, cwd?: any, onEvent?: (event: any) => void, toolLimits?: any, persistArtifact?: any, onTruncate?: any, toolPayloadMaxBytes?: number, imageInlineMaxBytes?: any, toolPolicy?: any, sandboxPolicy?: any, sandboxEngine?: any, approvalManager?: any, approvalModel?: any, ctx?: any}} [options]
|
|
39
|
+
*/
|
|
40
|
+
export function getPiBuiltinTools(allowedTools: any, { skillNames, skills, skillsRoot, dataDir, cwd, onEvent, toolLimits, persistArtifact, onTruncate, toolPayloadMaxBytes, imageInlineMaxBytes, toolPolicy, sandboxPolicy, sandboxEngine, approvalManager, approvalModel, ctx, }?: {
|
|
41
|
+
skillNames?: any[];
|
|
42
|
+
skills?: any[];
|
|
43
|
+
skillsRoot?: any;
|
|
44
|
+
dataDir?: any;
|
|
45
|
+
cwd?: any;
|
|
46
|
+
onEvent?: (event: any) => void;
|
|
47
|
+
toolLimits?: any;
|
|
48
|
+
persistArtifact?: any;
|
|
49
|
+
onTruncate?: any;
|
|
50
|
+
toolPayloadMaxBytes?: number;
|
|
51
|
+
imageInlineMaxBytes?: any;
|
|
52
|
+
toolPolicy?: any;
|
|
53
|
+
sandboxPolicy?: any;
|
|
54
|
+
sandboxEngine?: any;
|
|
55
|
+
approvalManager?: any;
|
|
56
|
+
approvalModel?: any;
|
|
57
|
+
ctx?: any;
|
|
58
|
+
}): any[];
|
|
59
|
+
export function resolveMcpStdioCwd(cfg?: {}, cwd?: any): any;
|
|
60
|
+
export function prepareMcpStdioCommand(cfg?: {}, { cwd, sandboxPolicy, sandboxEngine, ctx }?: {
|
|
61
|
+
cwd?: any;
|
|
62
|
+
sandboxPolicy?: any;
|
|
63
|
+
sandboxEngine?: any;
|
|
64
|
+
ctx?: any;
|
|
65
|
+
}): Promise<any>;
|
|
66
|
+
export function coerceMcpContent(out: any, { textLimit, imageInlineMaxBytes, persistArtifact, toolName, toolUseId, onTruncate, }?: {
|
|
67
|
+
textLimit?: number;
|
|
68
|
+
imageInlineMaxBytes?: number;
|
|
69
|
+
persistArtifact?: any;
|
|
70
|
+
toolName?: string;
|
|
71
|
+
toolUseId?: any;
|
|
72
|
+
onTruncate?: any;
|
|
73
|
+
}): any;
|
|
74
|
+
/**
|
|
75
|
+
* @param {any} mcpConfig
|
|
76
|
+
* @param {Set<any>} [reservedNames]
|
|
77
|
+
* @param {{limits?: any, cwd?: any, persistArtifact?: any, qaOutputDir?: any, onTruncate?: any, toolPayloadMaxBytes?: number, sandboxPolicy?: any, sandboxEngine?: any, onToolProgress?: any, ctx?: any}} [options]
|
|
78
|
+
*/
|
|
79
|
+
export function initPiMcpTools(mcpConfig: any, reservedNames?: Set<any>, { limits, cwd, persistArtifact, qaOutputDir, onTruncate, toolPayloadMaxBytes, sandboxPolicy, sandboxEngine, onToolProgress, ctx, }?: {
|
|
80
|
+
limits?: any;
|
|
81
|
+
cwd?: any;
|
|
82
|
+
persistArtifact?: any;
|
|
83
|
+
qaOutputDir?: any;
|
|
84
|
+
onTruncate?: any;
|
|
85
|
+
toolPayloadMaxBytes?: number;
|
|
86
|
+
sandboxPolicy?: any;
|
|
87
|
+
sandboxEngine?: any;
|
|
88
|
+
onToolProgress?: any;
|
|
89
|
+
ctx?: any;
|
|
90
|
+
}): Promise<{
|
|
91
|
+
clients: {
|
|
92
|
+
name: any;
|
|
93
|
+
client: McpClient<{
|
|
94
|
+
method: string;
|
|
95
|
+
params?: {
|
|
96
|
+
[x: string]: unknown;
|
|
97
|
+
_meta?: {
|
|
98
|
+
[x: string]: unknown;
|
|
99
|
+
progressToken?: string | number;
|
|
100
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
101
|
+
taskId: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}, {
|
|
106
|
+
method: string;
|
|
107
|
+
params?: {
|
|
108
|
+
[x: string]: unknown;
|
|
109
|
+
_meta?: {
|
|
110
|
+
[x: string]: unknown;
|
|
111
|
+
progressToken?: string | number;
|
|
112
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
113
|
+
taskId: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
}, {
|
|
118
|
+
[x: string]: unknown;
|
|
119
|
+
_meta?: {
|
|
120
|
+
[x: string]: unknown;
|
|
121
|
+
progressToken?: string | number;
|
|
122
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
123
|
+
taskId: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
}>;
|
|
127
|
+
transport: StreamableHTTPClientTransport | SSEClientTransport | StdioClientTransport;
|
|
128
|
+
}[];
|
|
129
|
+
tools: any[];
|
|
130
|
+
warnings: {
|
|
131
|
+
type: string;
|
|
132
|
+
warning_kind: string;
|
|
133
|
+
server: string;
|
|
134
|
+
message: any;
|
|
135
|
+
}[];
|
|
136
|
+
}>;
|
|
137
|
+
export function closePiMcpClients(clients: any, { timeoutMs }?: {
|
|
138
|
+
timeoutMs?: number;
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
import { Type } from "@earendil-works/pi-ai";
|
|
141
|
+
import { Client as McpClient } from "@modelcontextprotocol/sdk/client/index.js";
|
|
142
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
143
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
144
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{file_path: string, offset?: number, start_line?: number, limit?: number, max_output_chars?: number, workdir?: string}} params
|
|
3
|
+
* @param {{sandboxPolicy?: any, ctx?: any}} [options]
|
|
4
|
+
*/
|
|
5
|
+
export function readToolImpl({ file_path, offset, start_line, limit, max_output_chars, workdir }: {
|
|
6
|
+
file_path: string;
|
|
7
|
+
offset?: number;
|
|
8
|
+
start_line?: number;
|
|
9
|
+
limit?: number;
|
|
10
|
+
max_output_chars?: number;
|
|
11
|
+
workdir?: string;
|
|
12
|
+
}, { sandboxPolicy, ctx }?: {
|
|
13
|
+
sandboxPolicy?: any;
|
|
14
|
+
ctx?: any;
|
|
15
|
+
}): Promise<string | {
|
|
16
|
+
kind: string;
|
|
17
|
+
data: string;
|
|
18
|
+
mimeType: any;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const DEFAULT_READ_LINES: 240;
|
|
2
|
+
export const MAX_READ_LINES: 500;
|
|
3
|
+
export const MAX_READ_LINE_CHARS: 2000;
|
|
4
|
+
export const DEFAULT_MAX_READ_CHARS: 16000;
|
|
5
|
+
export const DEFAULT_MAX_TOOL_OUTPUT_CHARS: 16000;
|
|
6
|
+
export const DEFAULT_MAX_BASH_OUTPUT_CHARS: 20000;
|
|
7
|
+
export const MAX_WRITE_BYTES: number;
|
|
8
|
+
export const DEFAULT_EXCLUDED_DIRS: string[];
|
|
9
|
+
export const DEFAULT_EXCLUDED_FILES: string[];
|
|
10
|
+
export const DEFAULT_MAX_SEARCH_LINES: 100;
|
|
11
|
+
export const DEFAULT_MAX_SEARCH_CHARS: 16000;
|
|
12
|
+
export const SEARCH_MAX_BUFFER: number;
|
|
13
|
+
export const READ_HISTORY_LIMIT: 200;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function boundedInt(value: any, fallback: any, { min, max }?: {
|
|
2
|
+
min?: number;
|
|
3
|
+
max?: number;
|
|
4
|
+
}): any;
|
|
5
|
+
export function safeStat(path: any): import("fs").Stats;
|
|
6
|
+
export function rememberRead(target: any, start: any, count: any): boolean;
|
|
7
|
+
export function trimLine(line: any): string;
|
|
8
|
+
export const readHistory: Map<any, any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function writeToolArtifact(label: any, text: any, ctx: any): {
|
|
2
|
+
path: string;
|
|
3
|
+
bytes: number;
|
|
4
|
+
};
|
|
5
|
+
export function truncationSuffix({ label, shown, total, artifact, hint }: {
|
|
6
|
+
label: any;
|
|
7
|
+
shown: any;
|
|
8
|
+
total: any;
|
|
9
|
+
artifact: any;
|
|
10
|
+
hint: any;
|
|
11
|
+
}): string;
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} text
|
|
14
|
+
* @param {{label?: string, maxChars?: number, strategy?: string, hint?: string, ctx?: any}} [options]
|
|
15
|
+
*/
|
|
16
|
+
export function capChars(text: string, { label, maxChars, strategy, hint, ctx, }?: {
|
|
17
|
+
label?: string;
|
|
18
|
+
maxChars?: number;
|
|
19
|
+
strategy?: string;
|
|
20
|
+
hint?: string;
|
|
21
|
+
ctx?: any;
|
|
22
|
+
}): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function workspaceRoot(workdir: any, ctx: any): string;
|
|
2
|
+
export function resolveToolPath(path: any, workdir: any, ctx: any): any;
|
|
3
|
+
export function isPathAllowed(path: any, workdir: any, options?: {}): boolean;
|
|
4
|
+
export function isWritablePathAllowed(path: any, workdir: any, options?: {}): boolean;
|
|
5
|
+
export function isWorkdirAllowed(workdir: any, options?: {}): boolean;
|
|
6
|
+
export function isInsidePath(root: any, target: any): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function ripgrepMissingMessage(ctx: any): string;
|
|
2
|
+
/**
|
|
3
|
+
* @param {{refresh?: boolean, ctx?: any}} [options]
|
|
4
|
+
*/
|
|
5
|
+
export function resolveRgPath({ refresh, ctx }?: {
|
|
6
|
+
refresh?: boolean;
|
|
7
|
+
ctx?: any;
|
|
8
|
+
}): any;
|
|
9
|
+
export function excludedGlobArgs(): string[];
|
|
10
|
+
export function normalizeGlobPattern(pattern: any): string;
|
|
11
|
+
/**
|
|
12
|
+
* @param {any} rawLines
|
|
13
|
+
* @param {{label?: string, noMatches?: string, maxLines?: number, maxChars?: number, offset?: number, ctx?: any}} [options]
|
|
14
|
+
*/
|
|
15
|
+
export function formatSearchLines(rawLines: any, { label, noMatches, maxLines, maxChars, offset, ctx, }?: {
|
|
16
|
+
label?: string;
|
|
17
|
+
noMatches?: string;
|
|
18
|
+
maxLines?: number;
|
|
19
|
+
maxChars?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
ctx?: any;
|
|
22
|
+
}): string;
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} text
|
|
25
|
+
* @param {{label?: string, noMatches?: string, maxLines?: number, maxChars?: number, offset?: number, ctx?: any}} [options]
|
|
26
|
+
*/
|
|
27
|
+
export function capLines(text: string, { label, noMatches, maxLines, maxChars, offset, ctx, }?: {
|
|
28
|
+
label?: string;
|
|
29
|
+
noMatches?: string;
|
|
30
|
+
maxLines?: number;
|
|
31
|
+
maxChars?: number;
|
|
32
|
+
offset?: number;
|
|
33
|
+
ctx?: any;
|
|
34
|
+
}): string;
|
|
35
|
+
export function excludedPathSummary(): string;
|
|
36
|
+
export namespace cachedRgPath {
|
|
37
|
+
let value: any;
|
|
38
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Partial<ToolContext>} [next]
|
|
3
|
+
* @returns {void}
|
|
4
|
+
*/
|
|
5
|
+
export function configureToolRuntime(next?: Partial<ToolContext>): void;
|
|
6
|
+
/**
|
|
7
|
+
* @returns {ToolContext}
|
|
8
|
+
*/
|
|
9
|
+
export function readToolRuntime(): ToolContext;
|
|
10
|
+
/**
|
|
11
|
+
* @param {import('../../sandbox-seam.js').SandboxPolicy} [requestPolicy]
|
|
12
|
+
* @returns {import('../../sandbox-seam.js').SandboxPolicy|undefined}
|
|
13
|
+
*/
|
|
14
|
+
export function resolveSandboxPolicy(requestPolicy?: import("../../sandbox-seam.js").SandboxPolicy): import("../../sandbox-seam.js").SandboxPolicy | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* @returns {import('../../../runtime-brand.js').RuntimeBrand}
|
|
17
|
+
*/
|
|
18
|
+
export function readRuntimeBrand(): import("../../../runtime-brand.js").RuntimeBrand;
|
|
19
|
+
/**
|
|
20
|
+
* @returns {void}
|
|
21
|
+
*/
|
|
22
|
+
export function resetToolRuntime(): void;
|
|
23
|
+
export type ToolContext = import("./tool-context.js").ToolContext;
|
|
24
|
+
/**
|
|
25
|
+
* Back-compat alias for the historical name.
|
|
26
|
+
*/
|
|
27
|
+
export type ToolRuntimeContext = ToolContext;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a fresh ToolContext from a partial input. `runtimeBrand` is always
|
|
3
|
+
* resolved (to the defaults when absent); the remaining keys default to
|
|
4
|
+
* undefined and are copied from `input` when present.
|
|
5
|
+
* @param {Partial<ToolContext>} [input]
|
|
6
|
+
* @returns {ToolContext}
|
|
7
|
+
*/
|
|
8
|
+
export function createToolContext(input?: Partial<ToolContext>): ToolContext;
|
|
9
|
+
/**
|
|
10
|
+
* Mutate an existing ToolContext in place with the keys present on `next`,
|
|
11
|
+
* leaving untouched keys as-is. Mutating in place (rather than returning a
|
|
12
|
+
* copy) is deliberate: `createRuntime` threads a single context object to its
|
|
13
|
+
* bridges and `configureTools` updates that same reference so subsequent runs
|
|
14
|
+
* observe the change — the instance-scoped equivalent of the old global
|
|
15
|
+
* configureToolRuntime.
|
|
16
|
+
* @param {ToolContext} ctx
|
|
17
|
+
* @param {Partial<ToolContext>} [next]
|
|
18
|
+
* @returns {ToolContext}
|
|
19
|
+
*/
|
|
20
|
+
export function updateToolContext(ctx: ToolContext, next?: Partial<ToolContext>): ToolContext;
|
|
21
|
+
/**
|
|
22
|
+
* Reset every data key to undefined and the brand back to the defaults.
|
|
23
|
+
* @param {ToolContext} ctx
|
|
24
|
+
* @returns {ToolContext}
|
|
25
|
+
*/
|
|
26
|
+
export function resetToolContext(ctx: ToolContext): ToolContext;
|
|
27
|
+
/**
|
|
28
|
+
* @param {ToolContext|undefined} ctx
|
|
29
|
+
* @param {SandboxPolicy} [requestPolicy]
|
|
30
|
+
* @returns {SandboxPolicy|undefined}
|
|
31
|
+
*/
|
|
32
|
+
export function resolveSandboxPolicy(ctx: ToolContext | undefined, requestPolicy?: SandboxPolicy): SandboxPolicy | undefined;
|
|
33
|
+
export type RuntimeBrand = import("../../../runtime-brand.js").RuntimeBrand;
|
|
34
|
+
export type SandboxPolicy = import("../../sandbox-seam.js").SandboxPolicy;
|
|
35
|
+
export type RuntimeSandboxEngine = import("../../sandbox-seam.js").RuntimeSandboxEngine;
|
|
36
|
+
export type RuntimeSandbox = import("../../sandbox-seam.js").RuntimeSandbox;
|
|
37
|
+
export type ToolContext = {
|
|
38
|
+
workspace?: string;
|
|
39
|
+
repoRoot?: string;
|
|
40
|
+
runId?: string;
|
|
41
|
+
toolArtifactDir?: string;
|
|
42
|
+
ripgrepPath?: string;
|
|
43
|
+
qaOutputDir?: string;
|
|
44
|
+
sandboxPolicy?: SandboxPolicy;
|
|
45
|
+
sandboxEngine?: RuntimeSandboxEngine;
|
|
46
|
+
sandbox: RuntimeSandbox;
|
|
47
|
+
runtimeBrand: RuntimeBrand;
|
|
48
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{url: string, headers?: Record<string, string>, max_output_chars?: number}} params
|
|
3
|
+
* @param {{sandboxPolicy?: any, ctx?: any, retryDelaysMs?: number[]}} [options]
|
|
4
|
+
*/
|
|
5
|
+
export function webFetchToolImpl({ url, headers, max_output_chars }: {
|
|
6
|
+
url: string;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
max_output_chars?: number;
|
|
9
|
+
}, { sandboxPolicy, ctx, retryDelaysMs }?: {
|
|
10
|
+
sandboxPolicy?: any;
|
|
11
|
+
ctx?: any;
|
|
12
|
+
retryDelaysMs?: number[];
|
|
13
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{query: string, limit?: number}} params
|
|
3
|
+
* @param {{sandboxPolicy?: any, ctx?: any}} [options]
|
|
4
|
+
*/
|
|
5
|
+
export function webSearchToolImpl({ query, limit }: {
|
|
6
|
+
query: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
}, { sandboxPolicy, ctx }?: {
|
|
9
|
+
sandboxPolicy?: any;
|
|
10
|
+
ctx?: any;
|
|
11
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {{file_path: string, content?: string, workdir?: string}} params
|
|
3
|
+
* @param {{sandboxPolicy?: any, ctx?: any}} [options]
|
|
4
|
+
*/
|
|
5
|
+
export function writeToolImpl({ file_path, content, workdir }: {
|
|
6
|
+
file_path: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
workdir?: string;
|
|
9
|
+
}, { sandboxPolicy, ctx }?: {
|
|
10
|
+
sandboxPolicy?: any;
|
|
11
|
+
ctx?: any;
|
|
12
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Array<*>} events
|
|
3
|
+
* @param {Object} [options]
|
|
4
|
+
* @param {number} [options.maxTurns]
|
|
5
|
+
* @param {number} [options.verbatimTurns]
|
|
6
|
+
* @param {number} [options.maxChars]
|
|
7
|
+
* @param {number} [options.toolResultChars]
|
|
8
|
+
* @param {number} [options.assistantTextChars]
|
|
9
|
+
* @param {number} [options.turnSummaryChars]
|
|
10
|
+
* @param {import('../runtime-brand.js').RuntimeBrand} [options.runtimeBrand]
|
|
11
|
+
*/
|
|
12
|
+
export function buildTranscriptTailSnapshot(events: Array<any>, { maxTurns, verbatimTurns, maxChars, toolResultChars, assistantTextChars, turnSummaryChars, runtimeBrand, }?: {
|
|
13
|
+
maxTurns?: number;
|
|
14
|
+
verbatimTurns?: number;
|
|
15
|
+
maxChars?: number;
|
|
16
|
+
toolResultChars?: number;
|
|
17
|
+
assistantTextChars?: number;
|
|
18
|
+
turnSummaryChars?: number;
|
|
19
|
+
runtimeBrand?: import("../runtime-brand.js").RuntimeBrand;
|
|
20
|
+
}): {
|
|
21
|
+
schema: string;
|
|
22
|
+
captured_at: number;
|
|
23
|
+
turn_count: number;
|
|
24
|
+
earlier_turn_summaries: {
|
|
25
|
+
turn_index: number;
|
|
26
|
+
summary: string;
|
|
27
|
+
}[];
|
|
28
|
+
turns: any[];
|
|
29
|
+
};
|
|
30
|
+
export function renderResumeSnapshot(snapshot: any): string;
|
|
31
|
+
export namespace RESUME_SNAPSHOT_DEFAULTS {
|
|
32
|
+
export { DEFAULT_MAX_TURNS as maxTurns };
|
|
33
|
+
export { DEFAULT_VERBATIM_TURNS as verbatimTurns };
|
|
34
|
+
export { DEFAULT_MAX_CHARS as maxChars };
|
|
35
|
+
export { DEFAULT_TOOL_RESULT_CHARS as toolResultChars };
|
|
36
|
+
export { DEFAULT_ASSISTANT_TEXT_CHARS as assistantTextChars };
|
|
37
|
+
export { DEFAULT_TURN_SUMMARY_CHARS as turnSummaryChars };
|
|
38
|
+
}
|
|
39
|
+
declare const DEFAULT_MAX_TURNS: 12;
|
|
40
|
+
declare const DEFAULT_VERBATIM_TURNS: 3;
|
|
41
|
+
declare const DEFAULT_MAX_CHARS: 24000;
|
|
42
|
+
declare const DEFAULT_TOOL_RESULT_CHARS: 2400;
|
|
43
|
+
declare const DEFAULT_ASSISTANT_TEXT_CHARS: 4000;
|
|
44
|
+
declare const DEFAULT_TURN_SUMMARY_CHARS: 320;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function backendCapabilities(sdkOrModel: any): any;
|
|
2
|
+
export function backendUsesExecenvConfig(sdk: any): boolean;
|
|
3
|
+
export function backendSupportsSessionResume(sdk: any): boolean;
|
|
4
|
+
export const BACKEND_CAPABILITIES: {
|
|
5
|
+
claude: {
|
|
6
|
+
supports_session_resume: boolean;
|
|
7
|
+
streaming: boolean;
|
|
8
|
+
structured_output: boolean;
|
|
9
|
+
native_runtime_config: any;
|
|
10
|
+
supports_mcp: boolean;
|
|
11
|
+
supports_skills: boolean;
|
|
12
|
+
supports_builtin_tools: boolean;
|
|
13
|
+
supports_live_input: boolean;
|
|
14
|
+
supports_native_subagents: boolean;
|
|
15
|
+
runtime: string;
|
|
16
|
+
};
|
|
17
|
+
pi: {
|
|
18
|
+
supports_session_resume: boolean;
|
|
19
|
+
supports_native_subagents: boolean;
|
|
20
|
+
streaming: boolean;
|
|
21
|
+
structured_output: boolean;
|
|
22
|
+
native_runtime_config: any;
|
|
23
|
+
supports_mcp: boolean;
|
|
24
|
+
supports_skills: boolean;
|
|
25
|
+
supports_builtin_tools: boolean;
|
|
26
|
+
supports_live_input: boolean;
|
|
27
|
+
runtime: string;
|
|
28
|
+
};
|
|
29
|
+
codex: {
|
|
30
|
+
supports_session_resume: boolean;
|
|
31
|
+
streaming: boolean;
|
|
32
|
+
structured_output: boolean;
|
|
33
|
+
native_runtime_config: any;
|
|
34
|
+
supports_mcp: boolean;
|
|
35
|
+
supports_skills: boolean;
|
|
36
|
+
supports_builtin_tools: boolean;
|
|
37
|
+
supports_live_input: boolean;
|
|
38
|
+
supports_native_subagents: boolean;
|
|
39
|
+
runtime: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} [options]
|
|
3
|
+
* @param {(parsed: ParsedModelReference) => (NormalizedPricing|null)} [options.resolveCustomPricing]
|
|
4
|
+
* @param {string} [options.model]
|
|
5
|
+
* @returns {NormalizedPricing}
|
|
6
|
+
*/
|
|
7
|
+
export function resolvePricing({ resolveCustomPricing, model }?: {
|
|
8
|
+
resolveCustomPricing?: (parsed: ParsedModelReference) => (NormalizedPricing | null);
|
|
9
|
+
model?: string;
|
|
10
|
+
}): NormalizedPricing;
|
|
11
|
+
/**
|
|
12
|
+
* @param {Object} [options]
|
|
13
|
+
* @param {(parsed: ParsedModelReference) => (NormalizedPricing|null)} [options.resolveCustomPricing]
|
|
14
|
+
* @param {string} [options.model]
|
|
15
|
+
* @param {number} [options.inputTokens]
|
|
16
|
+
* @param {number} [options.outputTokens]
|
|
17
|
+
* @param {number} [options.cachedTokens]
|
|
18
|
+
* @param {number} [options.cacheWriteTokens]
|
|
19
|
+
* @param {number} [options.cacheCreationTokens]
|
|
20
|
+
* @returns {number|null}
|
|
21
|
+
*/
|
|
22
|
+
export function estimateCost({ resolveCustomPricing, model, inputTokens, outputTokens, cachedTokens, cacheWriteTokens, cacheCreationTokens, }?: {
|
|
23
|
+
resolveCustomPricing?: (parsed: ParsedModelReference) => (NormalizedPricing | null);
|
|
24
|
+
model?: string;
|
|
25
|
+
inputTokens?: number;
|
|
26
|
+
outputTokens?: number;
|
|
27
|
+
cachedTokens?: number;
|
|
28
|
+
cacheWriteTokens?: number;
|
|
29
|
+
cacheCreationTokens?: number;
|
|
30
|
+
}): number | null;
|
|
31
|
+
export type ParsedModelReference = {
|
|
32
|
+
sdk: string | null;
|
|
33
|
+
provider?: string;
|
|
34
|
+
model: string;
|
|
35
|
+
};
|
|
36
|
+
export type NormalizedPricing = {
|
|
37
|
+
input: number | null;
|
|
38
|
+
cacheRead: number | null;
|
|
39
|
+
cacheWrite: number | null;
|
|
40
|
+
output: number | null;
|
|
41
|
+
source: string;
|
|
42
|
+
priced: boolean;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Duck-typed pricing row a host (or the pi catalog) supplies: either
|
|
46
|
+
* camelCase or the provider's `*_per_million` snake_case spelling.
|
|
47
|
+
*/
|
|
48
|
+
export type PricingInputRow = {
|
|
49
|
+
input?: number | string;
|
|
50
|
+
input_per_million?: number | string;
|
|
51
|
+
cacheRead?: number | string;
|
|
52
|
+
cachedInput?: number | string;
|
|
53
|
+
cached_input_per_million?: number | string;
|
|
54
|
+
cacheWrite?: number | string;
|
|
55
|
+
cache_write_per_million?: number | string;
|
|
56
|
+
cache_creation_per_million?: number | string;
|
|
57
|
+
output?: number | string;
|
|
58
|
+
output_per_million?: number | string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* @param {PricingInputRow|null|undefined} pricing
|
|
62
|
+
* @param {Object} [options]
|
|
63
|
+
* @param {string} [options.source]
|
|
64
|
+
* @param {boolean} [options.priced]
|
|
65
|
+
* @param {number} [options.missing]
|
|
66
|
+
* @returns {NormalizedPricing|null}
|
|
67
|
+
*/
|
|
68
|
+
export function normalizePricing(pricing: PricingInputRow | null | undefined, { source, priced, missing }?: {
|
|
69
|
+
source?: string;
|
|
70
|
+
priced?: boolean;
|
|
71
|
+
missing?: number;
|
|
72
|
+
}): NormalizedPricing | null;
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} source
|
|
75
|
+
* @returns {NormalizedPricing}
|
|
76
|
+
*/
|
|
77
|
+
export function zeroPricing(source: string): NormalizedPricing;
|
|
78
|
+
/**
|
|
79
|
+
* @returns {NormalizedPricing}
|
|
80
|
+
*/
|
|
81
|
+
export function unknownPricing(): NormalizedPricing;
|
|
82
|
+
/**
|
|
83
|
+
* @param {PricingInputRow} [pricing]
|
|
84
|
+
* @returns {boolean}
|
|
85
|
+
*/
|
|
86
|
+
export function pricingHasRates(pricing?: PricingInputRow): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* @param {string} baseUrl
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
91
|
+
export function isPrivateHost(baseUrl: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* @param {string} reference
|
|
94
|
+
* @returns {ParsedModelReference|null}
|
|
95
|
+
*/
|
|
96
|
+
export function parseReference(reference: string): ParsedModelReference | null;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} text
|
|
3
|
+
* @returns {boolean}
|
|
4
|
+
*/
|
|
5
|
+
export function isProviderAuthFailureText(text?: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} [options]
|
|
8
|
+
* @param {string} [options.errorText]
|
|
9
|
+
* @param {string} [options.stderrTail]
|
|
10
|
+
* @param {string|null} [options.failureKind]
|
|
11
|
+
* @returns {RetryableProviderFailureInfo}
|
|
12
|
+
*/
|
|
13
|
+
export function retryableProviderFailureInfo({ errorText, stderrTail, failureKind, }?: {
|
|
14
|
+
errorText?: string;
|
|
15
|
+
stderrTail?: string;
|
|
16
|
+
failureKind?: string | null;
|
|
17
|
+
}): RetryableProviderFailureInfo;
|
|
18
|
+
/**
|
|
19
|
+
* @param {Object} [options]
|
|
20
|
+
* @param {number|null} [options.exitCode]
|
|
21
|
+
* @param {string|null} [options.signal]
|
|
22
|
+
* @param {string} [options.errorText]
|
|
23
|
+
* @param {string} [options.stderrTail]
|
|
24
|
+
* @param {boolean} [options.timedOut]
|
|
25
|
+
* @param {boolean} [options.cancelRequested]
|
|
26
|
+
* @param {string|null} [options.cancelInitiator]
|
|
27
|
+
* @param {boolean} [options.resultParseError]
|
|
28
|
+
* @param {boolean} [options.mcpInitFailed]
|
|
29
|
+
* @param {boolean} [options.budgetExceeded]
|
|
30
|
+
* @param {boolean} [options.childFailed]
|
|
31
|
+
* @param {string|null} [options.hint]
|
|
32
|
+
* @returns {FailureKind|null} One of FAILURE_KINDS, or null for a clean exit.
|
|
33
|
+
*/
|
|
34
|
+
export function classifyFailure({ exitCode, signal, errorText, stderrTail, timedOut, cancelRequested, cancelInitiator, resultParseError, mcpInitFailed, budgetExceeded, childFailed, hint, }?: {
|
|
35
|
+
exitCode?: number | null;
|
|
36
|
+
signal?: string | null;
|
|
37
|
+
errorText?: string;
|
|
38
|
+
stderrTail?: string;
|
|
39
|
+
timedOut?: boolean;
|
|
40
|
+
cancelRequested?: boolean;
|
|
41
|
+
cancelInitiator?: string | null;
|
|
42
|
+
resultParseError?: boolean;
|
|
43
|
+
mcpInitFailed?: boolean;
|
|
44
|
+
budgetExceeded?: boolean;
|
|
45
|
+
childFailed?: boolean;
|
|
46
|
+
hint?: string | null;
|
|
47
|
+
}): FailureKind | null;
|
|
48
|
+
/**
|
|
49
|
+
* @param {Object} [options]
|
|
50
|
+
* @param {number} [options.limit]
|
|
51
|
+
* @returns {{push: (chunk: (string|Buffer|null|undefined)) => void, toString: () => string, readonly bytesDropped: number}}
|
|
52
|
+
*/
|
|
53
|
+
export function createStderrTail({ limit }?: {
|
|
54
|
+
limit?: number;
|
|
55
|
+
}): {
|
|
56
|
+
push: (chunk: (string | Buffer | null | undefined)) => void;
|
|
57
|
+
toString: () => string;
|
|
58
|
+
readonly bytesDropped: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {Object} RetryableProviderFailureInfo
|
|
62
|
+
* @property {boolean} retryable
|
|
63
|
+
* @property {string|null} subkind
|
|
64
|
+
* @property {string|null} requestId
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {"spawn" | "timeout" | "stall" | "usage_limit" | "invalid_result"
|
|
68
|
+
* | "invalid_delegation" | "tool_failure" | "provider_unavailable"
|
|
69
|
+
* | "provider_unavailable_exhausted" | "provider_auth"
|
|
70
|
+
* | "skipped_capability_mismatch" | "cancelled" | "cancelled_user"
|
|
71
|
+
* | "cancelled_shutdown" | "cancelled_signal" | "abandoned"
|
|
72
|
+
* | "session_not_found" | "session_busy" | (string & {})} FailureKind
|
|
73
|
+
* OPEN string union. The literals above are the CORE taxonomy the kernel itself
|
|
74
|
+
* derives from provider/runtime signals in `classifyFailure` /
|
|
75
|
+
* `retryableProviderFailureInfo` (and `provider_unavailable_exhausted`, produced
|
|
76
|
+
* by the router on chain exhaustion). The union is intentionally open
|
|
77
|
+
* (`string & {}`) because `FAILURE_KINDS` also transports HOST-TAXONOMY kinds
|
|
78
|
+
* the kernel never originates on its own:
|
|
79
|
+
* - `child_failed`, `budget_exceeded` — `classifyFailure` only returns these
|
|
80
|
+
* when the HOST passes the matching `childFailed` / `budgetExceeded` (or a
|
|
81
|
+
* `cancelInitiator: "budget"`) input; the kernel never infers them from a
|
|
82
|
+
* provider signal.
|
|
83
|
+
* - `delegation_agent_not_in_team`, `delegation_team_roster_empty`,
|
|
84
|
+
* `invalid_delegation`, `cancelled_stale` (`stale_reconcile`) — set by a
|
|
85
|
+
* host coordinator (planner/roster/reconcile logic) and merely carried
|
|
86
|
+
* through `FAILURE_KINDS` / the `hint` passthrough; the kernel transports
|
|
87
|
+
* them in the result contract but never emits them from its own paths.
|
|
88
|
+
* Hosts (e.g. worklab's coordinator) validate against `FAILURE_KINDS` and may
|
|
89
|
+
* define additional kinds — accepting them at the type level is deliberate.
|
|
90
|
+
*/
|
|
91
|
+
export const FAILURE_KINDS: string[];
|
|
92
|
+
export const PROVIDER_ABORT_RE: RegExp;
|
|
93
|
+
export type RetryableProviderFailureInfo = {
|
|
94
|
+
retryable: boolean;
|
|
95
|
+
subkind: string | null;
|
|
96
|
+
requestId: string | null;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* OPEN string union. The literals above are the CORE taxonomy the kernel itself
|
|
100
|
+
* derives from provider/runtime signals in `classifyFailure` /
|
|
101
|
+
* `retryableProviderFailureInfo` (and `provider_unavailable_exhausted`, produced
|
|
102
|
+
* by the router on chain exhaustion). The union is intentionally open
|
|
103
|
+
* (`string & {}`) because `FAILURE_KINDS` also transports HOST-TAXONOMY kinds
|
|
104
|
+
* the kernel never originates on its own:
|
|
105
|
+
* - `child_failed`, `budget_exceeded` — `classifyFailure` only returns these
|
|
106
|
+
* when the HOST passes the matching `childFailed` / `budgetExceeded` (or a
|
|
107
|
+
* `cancelInitiator: "budget"`) input; the kernel never infers them from a
|
|
108
|
+
* provider signal.
|
|
109
|
+
* - `delegation_agent_not_in_team`, `delegation_team_roster_empty`,
|
|
110
|
+
* `invalid_delegation`, `cancelled_stale` (`stale_reconcile`) — set by a
|
|
111
|
+
* host coordinator (planner/roster/reconcile logic) and merely carried
|
|
112
|
+
* through `FAILURE_KINDS` / the `hint` passthrough; the kernel transports
|
|
113
|
+
* them in the result contract but never emits them from its own paths.
|
|
114
|
+
* Hosts (e.g. worklab's coordinator) validate against `FAILURE_KINDS` and may
|
|
115
|
+
* define additional kinds — accepting them at the type level is deliberate.
|
|
116
|
+
*/
|
|
117
|
+
export type FailureKind = "spawn" | "timeout" | "stall" | "usage_limit" | "invalid_result" | "invalid_delegation" | "tool_failure" | "provider_unavailable" | "provider_unavailable_exhausted" | "provider_auth" | "skipped_capability_mismatch" | "cancelled" | "cancelled_user" | "cancelled_shutdown" | "cancelled_signal" | "abandoned" | "session_not_found" | "session_busy" | (string & {});
|