@mono-agent/agent-runtime 0.4.0 → 0.4.1
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,24 @@
|
|
|
1
|
+
export function streamContentKey(streamEvent: any, fallback: any): any;
|
|
2
|
+
export function jsonSerializable(value: any, fallback?: any): any;
|
|
3
|
+
export function compactToolRawResult(result: any, resultContent: any): {
|
|
4
|
+
details_truncated?: boolean;
|
|
5
|
+
content: {
|
|
6
|
+
omitted: boolean;
|
|
7
|
+
reason: string;
|
|
8
|
+
original_length: number;
|
|
9
|
+
};
|
|
10
|
+
details: any;
|
|
11
|
+
truncated?: boolean;
|
|
12
|
+
original_length?: number;
|
|
13
|
+
preview?: any;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @param {any} toolName
|
|
17
|
+
* @param {any} args
|
|
18
|
+
* @param {{cwd?: any, toolLimits?: any}} [options]
|
|
19
|
+
*/
|
|
20
|
+
export function eventToolArgs(toolName: any, args: any, { cwd, toolLimits }?: {
|
|
21
|
+
cwd?: any;
|
|
22
|
+
toolLimits?: any;
|
|
23
|
+
}): any;
|
|
24
|
+
export function emitCaptured(events: any, onEvent: any, event: any): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function promptTextFromMessages(messages: any): string;
|
|
2
|
+
export function toAgentMessages(messages: any, model: any): any[];
|
|
3
|
+
export function textFromContent(content: any): string;
|
|
4
|
+
export function thinkingFromContent(content: any): string;
|
|
5
|
+
export function toolResultContent(result: any): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function resolvePiRuntimeModel(resolved: any, options: any): {
|
|
2
|
+
model: {
|
|
3
|
+
id: any;
|
|
4
|
+
name: any;
|
|
5
|
+
api: string;
|
|
6
|
+
provider: string;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
reasoning: boolean;
|
|
9
|
+
input: string[];
|
|
10
|
+
cost: {
|
|
11
|
+
input: number;
|
|
12
|
+
output: number;
|
|
13
|
+
cacheRead: number;
|
|
14
|
+
cacheWrite: number;
|
|
15
|
+
};
|
|
16
|
+
contextWindow: number;
|
|
17
|
+
maxTokens: number;
|
|
18
|
+
compat: {
|
|
19
|
+
supportsStore: boolean;
|
|
20
|
+
supportsDeveloperRole: boolean;
|
|
21
|
+
supportsReasoningEffort: boolean;
|
|
22
|
+
maxTokensField: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
capabilities: any;
|
|
26
|
+
apiKeys: Map<string, any>;
|
|
27
|
+
} | {
|
|
28
|
+
model: import("@earendil-works/pi-ai").Model<never>;
|
|
29
|
+
capabilities: {
|
|
30
|
+
tool_use: boolean;
|
|
31
|
+
reasoning: boolean;
|
|
32
|
+
reasoning_mode: string;
|
|
33
|
+
reasoning_levels: string[];
|
|
34
|
+
reasoning_disable_supported: boolean;
|
|
35
|
+
vision: boolean;
|
|
36
|
+
json_mode: boolean;
|
|
37
|
+
};
|
|
38
|
+
apiKeys: Map<any, any>;
|
|
39
|
+
};
|
|
40
|
+
export namespace EMPTY_USAGE {
|
|
41
|
+
let input: number;
|
|
42
|
+
let output: number;
|
|
43
|
+
let cacheRead: number;
|
|
44
|
+
let cacheWrite: number;
|
|
45
|
+
let totalTokens: number;
|
|
46
|
+
namespace cost {
|
|
47
|
+
let input_1: number;
|
|
48
|
+
export { input_1 as input };
|
|
49
|
+
let output_1: number;
|
|
50
|
+
export { output_1 as output };
|
|
51
|
+
let cacheRead_1: number;
|
|
52
|
+
export { cacheRead_1 as cacheRead };
|
|
53
|
+
let cacheWrite_1: number;
|
|
54
|
+
export { cacheWrite_1 as cacheWrite };
|
|
55
|
+
export let total: number;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export function estimateCurrentContextTokens(session: any, fixedOverheadTokens?: number): Promise<{
|
|
2
|
+
tokens: number;
|
|
3
|
+
source: string;
|
|
4
|
+
}>;
|
|
5
|
+
export function tryCompact(harness: any, { trigger, onEvent, runtimeWarnings, onCompactionRecorded, runId, model }: {
|
|
6
|
+
trigger: any;
|
|
7
|
+
onEvent: any;
|
|
8
|
+
runtimeWarnings: any;
|
|
9
|
+
onCompactionRecorded: any;
|
|
10
|
+
runId: any;
|
|
11
|
+
model: any;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
applied: boolean;
|
|
14
|
+
tokensBefore: number;
|
|
15
|
+
nothingToCompact: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Express the kernel's compaction policy as a pi `CompactionSettings` so the
|
|
19
|
+
* proactive trigger runs through pi's own `shouldCompact()`.
|
|
20
|
+
*
|
|
21
|
+
* EQUIVALENCE (exact, proven by pi-native-compaction-parity.test.js): pi fires
|
|
22
|
+
* when `contextTokens > contextWindow - reserveTokens` (STRICT `>`), while the
|
|
23
|
+
* kernel policy fires when `estimate >= triggerTokens` (`>=`). Both `estimate`
|
|
24
|
+
* and `triggerTokens` are non-negative INTEGERS — pi's `estimateTokens` /
|
|
25
|
+
* `calculateContextTokens` return `Math.ceil(...)`/summed provider counts, and
|
|
26
|
+
* `resolveAgentCompactionPolicy` builds `triggerTokens` with `Math.floor` — so
|
|
27
|
+
* for integers `x >= t` iff `x > t - 1`. Setting
|
|
28
|
+
* `reserveTokens = contextWindow - triggerTokens + 1`
|
|
29
|
+
* gives `contextWindow - reserveTokens = triggerTokens - 1`, hence
|
|
30
|
+
* `shouldCompact(x, window, s)` == `x > triggerTokens - 1` == `x >= triggerTokens`.
|
|
31
|
+
* `triggerTokens < contextWindow` always (it is `min(floor(window*ratio),
|
|
32
|
+
* window - reserve)` with `ratio <= 0.95`), so `reserveTokens >= 2` — never
|
|
33
|
+
* degenerate. `keepRecentTokens` is carried through for a faithful settings
|
|
34
|
+
* object even though `shouldCompact` ignores it.
|
|
35
|
+
* @param {{enabled: boolean, contextWindow: number, triggerTokens: number, keepRecentTokens: number}} policy
|
|
36
|
+
* @returns {{enabled: boolean, reserveTokens: number, keepRecentTokens: number}}
|
|
37
|
+
*/
|
|
38
|
+
export function piCompactionSettings(policy: {
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
contextWindow: number;
|
|
41
|
+
triggerTokens: number;
|
|
42
|
+
keepRecentTokens: number;
|
|
43
|
+
}): {
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
reserveTokens: number;
|
|
46
|
+
keepRecentTokens: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the compaction policy against the LIVE model's context window
|
|
50
|
+
* (auto-recognized from the model actually serving the request, lowered by any
|
|
51
|
+
* ceiling learned from a prior overflow). A positive `contextWindowOverride`
|
|
52
|
+
* (from the typed `compaction` policy object) replaces the auto-recognized
|
|
53
|
+
* window — it is not a legacy `settings` key, so it is applied here directly
|
|
54
|
+
* rather than through the settings shim. Drives the proactive trigger +
|
|
55
|
+
* reactive recovery.
|
|
56
|
+
* @param {{harness: any, runtime: any, resolved: any, settings: any, contextWindowOverride?: number}} params
|
|
57
|
+
*/
|
|
58
|
+
export function resolveLiveCompactionPolicy({ harness, runtime, resolved, settings, contextWindowOverride }: {
|
|
59
|
+
harness: any;
|
|
60
|
+
runtime: any;
|
|
61
|
+
resolved: any;
|
|
62
|
+
settings: any;
|
|
63
|
+
contextWindowOverride?: number;
|
|
64
|
+
}): import("../../../agent/compaction.js").AgentCompactionPolicy;
|
|
65
|
+
/**
|
|
66
|
+
* Proactive compaction: if the session is already near the window, compact
|
|
67
|
+
* BEFORE issuing the request so a long-lived session never overflows. Mutates
|
|
68
|
+
* runState.compaction (applied / compactedThisRun / diagnostics) and re-anchors
|
|
69
|
+
* runState.sessionBaselineCount when it fires.
|
|
70
|
+
* @param {any} runState
|
|
71
|
+
* @param {any} params
|
|
72
|
+
*/
|
|
73
|
+
export function runProactiveCompaction(runState: any, { harness, systemPrompt, options, tools, promptText, promptImages, reference, onEvent, runtimeWarnings, }: any): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Reactive recovery: if the turn ended in a context overflow and we have not
|
|
76
|
+
* already compacted-and-retried this run, compact once and re-prompt once.
|
|
77
|
+
* Learns the real ceiling from the overflow error. Returns the (possibly
|
|
78
|
+
* re-captured) state + runError.
|
|
79
|
+
* @param {any} runState
|
|
80
|
+
* @param {any} params
|
|
81
|
+
* @returns {Promise<{state: any, runError: any}>}
|
|
82
|
+
*/
|
|
83
|
+
export function runReactiveCompaction(runState: any, { harness, runtime, resolved, options, promptText, promptImages, reference, onEvent, runtimeWarnings, state, runError, captureState, }: any): Promise<{
|
|
84
|
+
state: any;
|
|
85
|
+
runError: any;
|
|
86
|
+
}>;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sum assistant-message usage across a transcript slice.
|
|
3
|
+
* @param {Array<any>} [messages]
|
|
4
|
+
* @returns {{input: number, output: number, cacheRead: number, cacheWrite: number, cost: number}}
|
|
5
|
+
*/
|
|
6
|
+
export function usageFromMessages(messages?: Array<any>): {
|
|
7
|
+
input: number;
|
|
8
|
+
output: number;
|
|
9
|
+
cacheRead: number;
|
|
10
|
+
cacheWrite: number;
|
|
11
|
+
cost: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Classify a pi error message into a runtime failure kind. Context-limit /
|
|
15
|
+
* max-turns terminations map to usage_limit; credential/config auth failures
|
|
16
|
+
* map to provider_auth; everything else to provider_unavailable. Null message → null.
|
|
17
|
+
* @param {string|null} message
|
|
18
|
+
* @param {Record<string, unknown>} diagnostics
|
|
19
|
+
* @param {{maxTurnsHit?: boolean}} [opts]
|
|
20
|
+
* @returns {string|null}
|
|
21
|
+
*/
|
|
22
|
+
export function failureKindForPiError(message: string | null, diagnostics: Record<string, unknown>, { maxTurnsHit }?: {
|
|
23
|
+
maxTurnsHit?: boolean;
|
|
24
|
+
}): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Emit the per-run cache / cost / provider-completed events.
|
|
27
|
+
* @param {{onEvent: (event: any) => void, resolved: any, reference: string, usage: {input: number, output: number, cacheRead: number, cacheWrite: number, cost: number}, estimatedCost: number, start: number, externalAbort: boolean}} params
|
|
28
|
+
*/
|
|
29
|
+
export function emitUsageCostEvents({ onEvent, resolved, reference, usage, estimatedCost, start, externalAbort }: {
|
|
30
|
+
onEvent: (event: any) => void;
|
|
31
|
+
resolved: any;
|
|
32
|
+
reference: string;
|
|
33
|
+
usage: {
|
|
34
|
+
input: number;
|
|
35
|
+
output: number;
|
|
36
|
+
cacheRead: number;
|
|
37
|
+
cacheWrite: number;
|
|
38
|
+
cost: number;
|
|
39
|
+
};
|
|
40
|
+
estimatedCost: number;
|
|
41
|
+
start: number;
|
|
42
|
+
externalAbort: boolean;
|
|
43
|
+
}): void;
|
|
44
|
+
/**
|
|
45
|
+
* Emit the capabilities_resolved event.
|
|
46
|
+
* @param {(event: any) => void} onEvent
|
|
47
|
+
* @param {{sdk: string, model: string, capabilitiesUsed: any}} payload
|
|
48
|
+
*/
|
|
49
|
+
export function emitCapabilitiesResolved(onEvent: (event: any) => void, { sdk, model, capabilitiesUsed }: {
|
|
50
|
+
sdk: string;
|
|
51
|
+
model: string;
|
|
52
|
+
capabilitiesUsed: any;
|
|
53
|
+
}): void;
|
|
54
|
+
/**
|
|
55
|
+
* The aborted-run result (entry pre-check / pre-request abort). Pure factory.
|
|
56
|
+
* @param {{resolved: any, options: any, events: any[], runtimeWarnings: any[], start: number, providerSessionId: string}} params
|
|
57
|
+
*/
|
|
58
|
+
export function abortedResult({ resolved, options, events, runtimeWarnings, start, providerSessionId }: {
|
|
59
|
+
resolved: any;
|
|
60
|
+
options: any;
|
|
61
|
+
events: any[];
|
|
62
|
+
runtimeWarnings: any[];
|
|
63
|
+
start: number;
|
|
64
|
+
providerSessionId: string;
|
|
65
|
+
}): {
|
|
66
|
+
text: any;
|
|
67
|
+
thinking: string;
|
|
68
|
+
events: any[];
|
|
69
|
+
usage: {};
|
|
70
|
+
durationMs: number;
|
|
71
|
+
numTurns: number;
|
|
72
|
+
model: any;
|
|
73
|
+
effort: any;
|
|
74
|
+
sdk: any;
|
|
75
|
+
cancelled: boolean;
|
|
76
|
+
error: any;
|
|
77
|
+
failureKind: any;
|
|
78
|
+
providerSessionId: string;
|
|
79
|
+
runtimeWarnings: any[];
|
|
80
|
+
diagnostics: {
|
|
81
|
+
provider_session_id: string;
|
|
82
|
+
pi_stop_reason: string;
|
|
83
|
+
pi_engine: string;
|
|
84
|
+
external_abort: boolean;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The verbatim success-path result object (also carries a run-level error when
|
|
89
|
+
* a turn ended in an error/max-turns/abort without throwing). Pure assembly.
|
|
90
|
+
* @param {object} params
|
|
91
|
+
*/
|
|
92
|
+
export function buildSuccessResult(params: object): {
|
|
93
|
+
structuredResult: any;
|
|
94
|
+
structuredResultSource: string;
|
|
95
|
+
text: any;
|
|
96
|
+
thinking: any;
|
|
97
|
+
events: any;
|
|
98
|
+
usage: {
|
|
99
|
+
input_tokens: any;
|
|
100
|
+
output_tokens: any;
|
|
101
|
+
cache_read_tokens: any;
|
|
102
|
+
cache_creation_tokens: any;
|
|
103
|
+
cache_write_tokens: any;
|
|
104
|
+
cost_usd: any;
|
|
105
|
+
};
|
|
106
|
+
durationMs: number;
|
|
107
|
+
numTurns: any;
|
|
108
|
+
model: any;
|
|
109
|
+
effort: any;
|
|
110
|
+
sdk: any;
|
|
111
|
+
cancelled: any;
|
|
112
|
+
error: any;
|
|
113
|
+
errorDetails: any;
|
|
114
|
+
failureKind: string;
|
|
115
|
+
providerSessionId: any;
|
|
116
|
+
runtimeWarnings: any;
|
|
117
|
+
diagnostics: any;
|
|
118
|
+
capabilitiesUsed: any;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The verbatim outer-catch error result. Pure assembly.
|
|
122
|
+
* @param {object} params
|
|
123
|
+
*/
|
|
124
|
+
export function buildErrorResult(params: object): {
|
|
125
|
+
text: any;
|
|
126
|
+
events: any;
|
|
127
|
+
usage: {};
|
|
128
|
+
durationMs: number;
|
|
129
|
+
numTurns: any;
|
|
130
|
+
model: any;
|
|
131
|
+
effort: any;
|
|
132
|
+
sdk: any;
|
|
133
|
+
cancelled: any;
|
|
134
|
+
error: any;
|
|
135
|
+
errorDetails: {
|
|
136
|
+
pi_stop_reason: string;
|
|
137
|
+
last_tool_name: any;
|
|
138
|
+
tool_results_seen: any;
|
|
139
|
+
turn_count: any;
|
|
140
|
+
max_turns_hit: any;
|
|
141
|
+
provider_session_id: any;
|
|
142
|
+
pi_engine: string;
|
|
143
|
+
pi_error_retryable: any;
|
|
144
|
+
};
|
|
145
|
+
failureKind: string;
|
|
146
|
+
providerSessionId: any;
|
|
147
|
+
runtimeWarnings: any;
|
|
148
|
+
diagnostics: {
|
|
149
|
+
provider_session_id: any;
|
|
150
|
+
pi_stop_reason: string;
|
|
151
|
+
pi_engine: string;
|
|
152
|
+
max_turns_hit: any;
|
|
153
|
+
turn_count: any;
|
|
154
|
+
external_abort: any;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Assemble the success-path diagnostics object. Pure.
|
|
159
|
+
* @param {object} params
|
|
160
|
+
* @returns {Record<string, unknown>}
|
|
161
|
+
*/
|
|
162
|
+
export function buildDiagnostics(params: object): Record<string, unknown>;
|
|
163
|
+
/**
|
|
164
|
+
* Assemble the success-path errorDetails object (or null when no error). Pure.
|
|
165
|
+
* @param {object} params
|
|
166
|
+
* @returns {Record<string, unknown>|null}
|
|
167
|
+
*/
|
|
168
|
+
export function buildErrorDetails(params: object): Record<string, unknown> | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export function resolveDurableNativeSessionRepo(piSessionsRoot: any): any;
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the session for this run: warm registry hit, durable cold reopen,
|
|
4
|
+
* create-on-miss (durable resume only), or fresh create. Mutates runState
|
|
5
|
+
* (session / sessionEntry / createdOnMiss / reservation). Returns
|
|
6
|
+
* `{ done: true, result }` for a fast-fail early return (session_not_found /
|
|
7
|
+
* session_busy), else `{ done: false }` to proceed.
|
|
8
|
+
* @param {any} runState
|
|
9
|
+
* @param {any} params
|
|
10
|
+
* @returns {Promise<{done: true, result: any} | {done: false}>}
|
|
11
|
+
*/
|
|
12
|
+
export function resolveSession(runState: any, { requestedSessionId, providerSessionId, durableRepo, sessionTtlMs, cwd, resolved, options, events, runtimeWarnings, start, }: any): Promise<{
|
|
13
|
+
done: true;
|
|
14
|
+
result: any;
|
|
15
|
+
} | {
|
|
16
|
+
done: false;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Drop an uncommitted fresh session (and any create-on-miss reservation) on the
|
|
20
|
+
* pre-request abort path. A resumed (user-owned) session is NEVER deleted
|
|
21
|
+
* (guarded `session && !sessionEntry`).
|
|
22
|
+
* @param {any} runState
|
|
23
|
+
* @param {{durableRepo: any}} params
|
|
24
|
+
*/
|
|
25
|
+
export function discardUncommittedSession(runState: any, { durableRepo }: {
|
|
26
|
+
durableRepo: any;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Session lifecycle commit: keep-alive registration, resumed-turn rollback, or
|
|
30
|
+
* fresh/non-keep-alive drop. The harness already durably persisted the
|
|
31
|
+
* transcript; this tracks LIVENESS so disposeProviderSession / idle-TTL
|
|
32
|
+
* eviction can reach native sessions, and rolls a failed/aborted resumed turn
|
|
33
|
+
* back to its pre-turn leaf.
|
|
34
|
+
* @param {any} runState
|
|
35
|
+
* @param {any} params
|
|
36
|
+
*/
|
|
37
|
+
export function commitSession(runState: any, { options, requestedSessionId, providerSessionId, durableRepo, sessionTtlMs, externalAbort, errorMessage, onEvent, }: any): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Final abort guard (durable cancel TOCTOU) rollback actions: a resumed session
|
|
40
|
+
* moves to its baseline leaf and drops its live entry; a fresh durable session
|
|
41
|
+
* deletes its jsonl. The orchestrator keeps the abort re-check + return inline
|
|
42
|
+
* so no await sits between the re-check and the return (I10); this only runs the
|
|
43
|
+
* rollback body when the guard fires.
|
|
44
|
+
* @param {any} runState
|
|
45
|
+
* @param {{requestedSessionId: string|null, providerSessionId: string, durableRepo: any}} params
|
|
46
|
+
*/
|
|
47
|
+
export function rollbackAbortedTurn(runState: any, { requestedSessionId, providerSessionId, durableRepo }: {
|
|
48
|
+
requestedSessionId: string | null;
|
|
49
|
+
providerSessionId: string;
|
|
50
|
+
durableRepo: any;
|
|
51
|
+
}): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Outer-catch session cleanup: drop a just-created fresh durable session, drop a
|
|
54
|
+
* create-on-miss reservation placeholder, and roll a resumed session back to its
|
|
55
|
+
* pre-turn leaf for host/runtime-side throws that landed after the harness
|
|
56
|
+
* already mutated the live session.
|
|
57
|
+
* @param {any} runState
|
|
58
|
+
* @param {{durableRepo: any}} params
|
|
59
|
+
*/
|
|
60
|
+
export function cleanupSessionOnThrow(runState: any, { durableRepo }: {
|
|
61
|
+
durableRepo: any;
|
|
62
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool-start progress line surfaced as a thinking block, or null for a
|
|
3
|
+
* blank/invalid tool name.
|
|
4
|
+
* @param {unknown} toolName
|
|
5
|
+
* @returns {string|null}
|
|
6
|
+
*/
|
|
7
|
+
export function toolStartProgressText(toolName: unknown): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* The slice of run state the stream subscriber reads and mutates. A structural
|
|
10
|
+
* subset of the orchestrator's runState.
|
|
11
|
+
* @typedef {object} StreamSubscriberState
|
|
12
|
+
* @property {string[]} assistantTexts
|
|
13
|
+
* @property {string[]} assistantThinking
|
|
14
|
+
* @property {Set<unknown>} textDeltaIndexes
|
|
15
|
+
* @property {Set<unknown>} thinkingDeltaIndexes
|
|
16
|
+
* @property {Map<string, number>} toolStartTimes
|
|
17
|
+
* @property {number} turnCount
|
|
18
|
+
* @property {number} toolResultsSeen
|
|
19
|
+
* @property {string|null} lastToolName
|
|
20
|
+
* @property {boolean} maxTurnsHit
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Build the harness subscribe handler. `harness` is passed for the maxTurns
|
|
24
|
+
* abort; it is already constructed when this is wired (subscribe follows the
|
|
25
|
+
* AgentHarness constructor).
|
|
26
|
+
* @param {StreamSubscriberState} runState
|
|
27
|
+
* @param {{onEvent: (event: any) => void, options: any, toolLimits: any, harness: any}} deps
|
|
28
|
+
* @returns {(event: any) => void}
|
|
29
|
+
*/
|
|
30
|
+
export function createStreamSubscriber(runState: StreamSubscriberState, { onEvent, options, toolLimits, harness }: {
|
|
31
|
+
onEvent: (event: any) => void;
|
|
32
|
+
options: any;
|
|
33
|
+
toolLimits: any;
|
|
34
|
+
harness: any;
|
|
35
|
+
}): (event: any) => void;
|
|
36
|
+
/**
|
|
37
|
+
* The slice of run state the stream subscriber reads and mutates. A structural
|
|
38
|
+
* subset of the orchestrator's runState.
|
|
39
|
+
*/
|
|
40
|
+
export type StreamSubscriberState = {
|
|
41
|
+
assistantTexts: string[];
|
|
42
|
+
assistantThinking: string[];
|
|
43
|
+
textDeltaIndexes: Set<unknown>;
|
|
44
|
+
thinkingDeltaIndexes: Set<unknown>;
|
|
45
|
+
toolStartTimes: Map<string, number>;
|
|
46
|
+
turnCount: number;
|
|
47
|
+
toolResultsSeen: number;
|
|
48
|
+
lastToolName: string | null;
|
|
49
|
+
maxTurnsHit: boolean;
|
|
50
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append the StructuredOutput usage instruction to the system prompt when an
|
|
3
|
+
* output schema is active. No schema → the prompt is returned unchanged. A host
|
|
4
|
+
* or run `prompts.structuredOutputInstruction(systemPrompt)` override, when
|
|
5
|
+
* supplied, replaces the default instruction text (it receives the raw system
|
|
6
|
+
* prompt and returns the augmented one); otherwise the default below is used.
|
|
7
|
+
* @param {string} systemPrompt
|
|
8
|
+
* @param {unknown} outputSchema
|
|
9
|
+
* @param {import('../../types.js').RuntimePromptOverrides} [prompts]
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function appendStructuredOutputInstruction(systemPrompt: string, outputSchema: unknown, prompts?: import("../../types.js").RuntimePromptOverrides): string;
|
|
13
|
+
/**
|
|
14
|
+
* The finalization re-prompt issued when a turn ended without submitting the
|
|
15
|
+
* required structured result. A `prompts.structuredOutputFinalization()`
|
|
16
|
+
* override, when supplied, replaces the default text.
|
|
17
|
+
* @param {import('../../types.js').RuntimePromptOverrides} [prompts]
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export function structuredOutputFinalizationPrompt(prompts?: import("../../types.js").RuntimePromptOverrides): string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the run should re-prompt once for structured-output finalization: a
|
|
23
|
+
* schema is active, no structured result was produced, the turn ended with no
|
|
24
|
+
* text, the run was not aborted / did not hit max turns, and the stop reason is
|
|
25
|
+
* not an error/abort.
|
|
26
|
+
* @param {{outputSchema: unknown, structuredResult: unknown, finalText: unknown, stopReason: unknown, externalAbort: boolean, maxTurnsHit: boolean}} params
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
export function shouldRetryStructuredOutputFinalization({ outputSchema, structuredResult, finalText, stopReason, externalAbort, maxTurnsHit, }: {
|
|
30
|
+
outputSchema: unknown;
|
|
31
|
+
structuredResult: unknown;
|
|
32
|
+
finalText: unknown;
|
|
33
|
+
stopReason: unknown;
|
|
34
|
+
externalAbort: boolean;
|
|
35
|
+
maxTurnsHit: boolean;
|
|
36
|
+
}): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The structured-output finalization diagnostics spread into the run's
|
|
39
|
+
* diagnostics/errorDetails. Empty when no retry was attempted.
|
|
40
|
+
* @param {number} attempts
|
|
41
|
+
* @param {string|null} reason
|
|
42
|
+
* @param {boolean} failed
|
|
43
|
+
* @returns {Record<string, unknown>}
|
|
44
|
+
*/
|
|
45
|
+
export function structuredOutputRetryDiagnostics(attempts: number, reason: string | null, failed: boolean): Record<string, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Run the single structured-output finalization re-prompt in the same session.
|
|
48
|
+
*
|
|
49
|
+
* The harness is idle after waitForIdle(), so re-prompt (not followUp, which
|
|
50
|
+
* only queues onto an active run) with only StructuredOutput active. This
|
|
51
|
+
* re-prompts ONCE in the same session, matching the legacy single
|
|
52
|
+
* agent.continue() finalization re-prompt. Tools are restored in finally.
|
|
53
|
+
*
|
|
54
|
+
* Returns the retry bookkeeping ({attempts, reason}); the caller computes
|
|
55
|
+
* `failed` from the (closure-owned) structuredResult after re-capturing state.
|
|
56
|
+
* @param {{harness: any, structuredTool: {name: string}|null, runtimeWarnings: Array<Record<string, unknown>>, prompts?: import('../../types.js').RuntimePromptOverrides}} deps
|
|
57
|
+
* @returns {Promise<{attempts: number, reason: string}>}
|
|
58
|
+
*/
|
|
59
|
+
export function runStructuredOutputFinalizationRetry({ harness, structuredTool, runtimeWarnings, prompts }: {
|
|
60
|
+
harness: any;
|
|
61
|
+
structuredTool: {
|
|
62
|
+
name: string;
|
|
63
|
+
} | null;
|
|
64
|
+
runtimeWarnings: Array<Record<string, unknown>>;
|
|
65
|
+
prompts?: import("../../types.js").RuntimePromptOverrides;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
attempts: number;
|
|
68
|
+
reason: string;
|
|
69
|
+
}>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the turn's tool set: the sandboxed/allowlisted/bloat-guarded builtin
|
|
3
|
+
* tools, the MCP tool bridge, and the StructuredOutput tool (whose callback
|
|
4
|
+
* writes runState.structuredResult). Surfaces MCP init/list failures to both the
|
|
5
|
+
* event stream and runtimeWarnings. Returns the assembled tools plus the MCP
|
|
6
|
+
* clients (closed by the caller's finally) and the structured tool.
|
|
7
|
+
* @param {any} runState
|
|
8
|
+
* @param {any} params
|
|
9
|
+
* @returns {Promise<{tools: any[], structuredTool: any, mcpClients: any[]}>}
|
|
10
|
+
*/
|
|
11
|
+
export function buildTurnTools(runState: any, { options, capabilities, toolLimits, approvalManager, runtime, resolved, onEvent, runtimeWarnings, }: any): Promise<{
|
|
12
|
+
tools: any[];
|
|
13
|
+
structuredTool: any;
|
|
14
|
+
mcpClients: any[];
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Map an effort level to the harness thinkingLevel, respecting model reasoning
|
|
18
|
+
* capability (no reasoning / reasoning_mode "none" → "off").
|
|
19
|
+
* @param {string} effort
|
|
20
|
+
* @param {any} capabilities
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
export function thinkingLevelForEffort(effort: string, capabilities: any): string;
|
|
24
|
+
/**
|
|
25
|
+
* Construct the AgentHarness for this turn, subscribe the stream-subscriber, and
|
|
26
|
+
* wire the external abort handler. Sets runState.harness and
|
|
27
|
+
* runState.removeAbortHandler; the abort handler sets runState.externalAbort and
|
|
28
|
+
* aborts the harness. Returns the harness.
|
|
29
|
+
* @param {any} runState
|
|
30
|
+
* @param {any} params
|
|
31
|
+
* @returns {any}
|
|
32
|
+
*/
|
|
33
|
+
export function buildTurnHarness(runState: any, { cwd, session, piModels, model, thinkingLevel, systemPrompt, outputSchema, tools, maxRetries, maxRetryDelayMs, steeringMode, onEvent, options, toolLimits, }: any): any;
|
|
34
|
+
/**
|
|
35
|
+
* Start the live-input steering consumer. Consumes follow-up messages and steers
|
|
36
|
+
* the harness mid-run; the consumer is tied to run completion (an internal
|
|
37
|
+
* runComplete flag) so it stops steering once the run finishes and does not
|
|
38
|
+
* swallow a follow-up meant for a later turn. Returns a `stop()` teardown.
|
|
39
|
+
* @param {{harness: any, options: any, onEvent: (event: any) => void}} deps
|
|
40
|
+
* @returns {{stop: () => Promise<void>}}
|
|
41
|
+
*/
|
|
42
|
+
export function startLiveInput({ harness, options, onEvent }: {
|
|
43
|
+
harness: any;
|
|
44
|
+
options: any;
|
|
45
|
+
onEvent: (event: any) => void;
|
|
46
|
+
}): {
|
|
47
|
+
stop: () => Promise<void>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Run a single prompt on the harness and wait for it to go idle. A stream error
|
|
51
|
+
* surfaces on the harness (not a throw), so a thrown prompt is captured as
|
|
52
|
+
* runError; waitForIdle always runs afterward.
|
|
53
|
+
* @param {any} harness
|
|
54
|
+
* @param {string} promptText
|
|
55
|
+
* @param {Array<any>} promptImages
|
|
56
|
+
* @returns {Promise<{runError: any}>}
|
|
57
|
+
*/
|
|
58
|
+
export function runHarnessPrompt(harness: any, promptText: string, promptImages: Array<any>): Promise<{
|
|
59
|
+
runError: any;
|
|
60
|
+
}>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function createDynamicCredentialStore(apiKeys: any, resolvePiApiKey: any, runtimeWarnings: any): any;
|
|
2
|
+
export function splitPromptMessages(messages: any, model: any): {
|
|
3
|
+
priorMessages: any[];
|
|
4
|
+
promptText: string;
|
|
5
|
+
promptImages: {
|
|
6
|
+
type: string;
|
|
7
|
+
data: any;
|
|
8
|
+
mimeType: any;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
export function generatePiNativeResponse(systemPrompt: any, options?: {}): Promise<any>;
|
|
12
|
+
export namespace piNativeRuntimeBridge {
|
|
13
|
+
export let id: string;
|
|
14
|
+
export let kind: string;
|
|
15
|
+
export let capabilities: any;
|
|
16
|
+
export function supports(ref: any): boolean;
|
|
17
|
+
export { generatePiNativeResponse as execute };
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { listRuntimeBridges as listProviders, resolveRuntimeBridge as findProviderForModel, runtimeCapabilities } from "./runtime/registry.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function buildCapabilitiesUsed({ promptCacheActive, thinkingEnabled, structuredOutputEnforced, subagentInvoked, mcpServersUsed, nativeSubagentsUsed, toolCompactionApplied, contextCompactionApplied, }?: {
|
|
2
|
+
promptCacheActive?: any;
|
|
3
|
+
thinkingEnabled?: any;
|
|
4
|
+
structuredOutputEnforced?: boolean;
|
|
5
|
+
subagentInvoked?: any;
|
|
6
|
+
mcpServersUsed?: any[];
|
|
7
|
+
nativeSubagentsUsed?: any[];
|
|
8
|
+
toolCompactionApplied?: boolean;
|
|
9
|
+
contextCompactionApplied?: any;
|
|
10
|
+
}): {
|
|
11
|
+
prompt_cache_active: any;
|
|
12
|
+
thinking_enabled: any;
|
|
13
|
+
structured_output_enforced: boolean;
|
|
14
|
+
subagent_invoked: any;
|
|
15
|
+
mcp_servers_used: any[];
|
|
16
|
+
native_subagents_used: any[];
|
|
17
|
+
tool_compaction_applied: boolean;
|
|
18
|
+
context_compaction_applied: any;
|
|
19
|
+
};
|
|
20
|
+
export function toolCompactionAppliedFromWarnings(runtimeWarnings?: any[]): boolean;
|
|
21
|
+
export const UNKNOWN_CAPABILITY: any;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function runtimeCapabilities(sdkOrModel: any): any;
|
|
2
|
+
export namespace COMMON_CAPABILITIES {
|
|
3
|
+
let streaming: boolean;
|
|
4
|
+
let structured_output: boolean;
|
|
5
|
+
let supports_session_resume: boolean;
|
|
6
|
+
let native_runtime_config: any;
|
|
7
|
+
let supports_mcp: boolean;
|
|
8
|
+
let supports_skills: boolean;
|
|
9
|
+
let supports_builtin_tools: boolean;
|
|
10
|
+
let supports_live_input: boolean;
|
|
11
|
+
let supports_native_subagents: boolean;
|
|
12
|
+
}
|
|
13
|
+
export namespace RUNTIME_CAPABILITIES {
|
|
14
|
+
namespace claude {
|
|
15
|
+
let supports_session_resume_1: boolean;
|
|
16
|
+
export { supports_session_resume_1 as supports_session_resume };
|
|
17
|
+
export let runtime: string;
|
|
18
|
+
}
|
|
19
|
+
namespace pi {
|
|
20
|
+
let supports_session_resume_2: boolean;
|
|
21
|
+
export { supports_session_resume_2 as supports_session_resume };
|
|
22
|
+
let supports_native_subagents_1: boolean;
|
|
23
|
+
export { supports_native_subagents_1 as supports_native_subagents };
|
|
24
|
+
let runtime_1: string;
|
|
25
|
+
export { runtime_1 as runtime };
|
|
26
|
+
}
|
|
27
|
+
namespace codex {
|
|
28
|
+
let supports_session_resume_3: boolean;
|
|
29
|
+
export { supports_session_resume_3 as supports_session_resume };
|
|
30
|
+
let runtime_2: string;
|
|
31
|
+
export { runtime_2 as runtime };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function normalizeContextWindow(value: any): "default" | "1m";
|
|
2
|
+
export function stripContextWindowSuffix(model: any): string;
|
|
3
|
+
export function claudeModelSupportsOneMillionContext(model: any): boolean;
|
|
4
|
+
export function claudeModelSupportsContextWindow(model: any, contextWindow: any): boolean;
|
|
5
|
+
export function modelWithContextWindow(model: any, contextWindow: any): string;
|
|
6
|
+
export const DEFAULT_CONTEXT_WINDOW: "default";
|
|
7
|
+
export const ONE_MILLION_CONTEXT_WINDOW: "1m";
|
|
8
|
+
export const CLAUDE_ONE_MILLION_CONTEXT_MODELS: Set<string>;
|