@mono-agent/agent-runtime 0.14.0 → 0.15.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.
Files changed (41) hide show
  1. package/MIGRATION.md +147 -69
  2. package/README.md +83 -20
  3. package/package.json +3 -6
  4. package/src/agent/compaction.js +0 -11
  5. package/src/agent/prompt/skill-index.js +5 -1
  6. package/src/ai/index.js +7 -1
  7. package/src/ai/observer.js +48 -13
  8. package/src/ai/pi-interop.js +156 -0
  9. package/src/ai/providers/claude-cli.js +2 -13
  10. package/src/ai/providers/claude-sdk.js +14 -8
  11. package/src/ai/providers/codex-app.js +235 -56
  12. package/src/ai/providers/opencode-app.js +168 -3
  13. package/src/ai/providers/pi-messages.js +0 -8
  14. package/src/ai/providers/pi-native/compaction-driver.js +106 -10
  15. package/src/ai/providers/pi-native/result-builder.js +2 -14
  16. package/src/ai/providers/pi-native/stream-subscriber.js +20 -2
  17. package/src/ai/providers/pi-native/turn-runner.js +31 -8
  18. package/src/ai/providers/pi-native.js +2 -5
  19. package/src/ai/runtime/live-input-events.js +94 -0
  20. package/src/ai/runtime/registry.js +8 -1
  21. package/src/ai/runtime/router.js +21 -0
  22. package/src/ai/types.js +2 -1
  23. package/src/runtime.js +3 -0
  24. package/types/agent/compaction.d.ts +0 -2
  25. package/types/agent/prompt/skill-index.d.ts +3 -0
  26. package/types/ai/index.d.ts +1 -1
  27. package/types/ai/observer.d.ts +4 -2
  28. package/types/ai/pi-interop.d.ts +113 -0
  29. package/types/ai/providers/claude-cli.d.ts +6 -30
  30. package/types/ai/providers/claude-sdk.d.ts +2 -9
  31. package/types/ai/providers/codex-app.d.ts +4 -10
  32. package/types/ai/providers/pi-messages.d.ts +0 -1
  33. package/types/ai/providers/pi-native/result-builder.d.ts +3 -11
  34. package/types/ai/providers/pi-native/stream-subscriber.d.ts +4 -2
  35. package/types/ai/providers/pi-native/turn-runner.d.ts +1 -1
  36. package/types/ai/runtime/live-input-events.d.ts +22 -0
  37. package/types/ai/types.d.ts +10 -2
  38. package/src/ai/backend.js +0 -17
  39. package/src/ai/registry.js +0 -5
  40. package/types/ai/backend.d.ts +0 -57
  41. package/types/ai/registry.d.ts +0 -1
@@ -0,0 +1,113 @@
1
+ /**
2
+ * List defensive snapshots of Pi's built-in models for one provider.
3
+ *
4
+ * @param {string} providerId
5
+ * @returns {PiBuiltinModelSnapshot[]}
6
+ */
7
+ export function listPiBuiltinModels(providerId: string): PiBuiltinModelSnapshot[];
8
+ /**
9
+ * Read a defensive snapshot of one Pi built-in model.
10
+ *
11
+ * @param {string} providerId
12
+ * @param {string} modelId
13
+ * @returns {PiBuiltinModelSnapshot|undefined}
14
+ */
15
+ export function getPiBuiltinModel(providerId: string, modelId: string): PiBuiltinModelSnapshot | undefined;
16
+ /**
17
+ * Translate Pi's model-native thinking levels to mono-agent effort spelling.
18
+ *
19
+ * @param {PiBuiltinModelSnapshot} model
20
+ * @returns {PiReasoningLevel[]}
21
+ */
22
+ export function reasoningLevelsForPiModel(model: PiBuiltinModelSnapshot): PiReasoningLevel[];
23
+ /**
24
+ * Resolve an OAuth-backed API key without allowing Pi to mutate the caller's
25
+ * credential record or returning Pi-owned credential objects.
26
+ *
27
+ * @param {string} providerId
28
+ * @param {Object<string, PiOAuthCredentialsSnapshot>} credentials
29
+ * @returns {Promise<{apiKey: string, newCredentials: PiOAuthCredentialsSnapshot}|null>}
30
+ */
31
+ export function resolvePiOAuthApiKey(providerId: string, credentials: {
32
+ [x: string]: PiOAuthCredentialsSnapshot;
33
+ }): Promise<{
34
+ apiKey: string;
35
+ newCredentials: PiOAuthCredentialsSnapshot;
36
+ } | null>;
37
+ /**
38
+ * Run a supported Pi OAuth login flow without exposing Pi's mutable provider
39
+ * registry or provider instances.
40
+ *
41
+ * @param {string} providerId
42
+ * @param {PiOAuthLoginCallbacks} callbacks
43
+ * @returns {Promise<PiOAuthCredentialsSnapshot>}
44
+ */
45
+ export function loginPiOAuth(providerId: string, callbacks: PiOAuthLoginCallbacks): Promise<PiOAuthCredentialsSnapshot>;
46
+ export type PiBuiltinModelSnapshot = {
47
+ id: string;
48
+ name: string;
49
+ api: string;
50
+ provider: string;
51
+ baseUrl: string;
52
+ reasoning: boolean;
53
+ input: Array<"text" | "image">;
54
+ cost: {
55
+ input: number;
56
+ output: number;
57
+ cacheRead: number;
58
+ cacheWrite: number;
59
+ tiers?: Array<{
60
+ inputTokensAbove: number;
61
+ input: number;
62
+ output: number;
63
+ cacheRead: number;
64
+ cacheWrite: number;
65
+ }>;
66
+ };
67
+ contextWindow: number;
68
+ maxTokens: number;
69
+ thinkingLevelMap?: {
70
+ [x: string]: string | null;
71
+ };
72
+ compat?: {
73
+ [x: string]: any;
74
+ };
75
+ headers?: {
76
+ [x: string]: string;
77
+ };
78
+ [key: string]: any;
79
+ };
80
+ export type PiReasoningLevel = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
81
+ export type PiOAuthCredentialsSnapshot = {
82
+ refresh: string;
83
+ access: string;
84
+ expires: number;
85
+ [key: string]: any;
86
+ };
87
+ export type PiOAuthLoginCallbacks = {
88
+ onAuth: (info: {
89
+ url: string;
90
+ instructions?: string;
91
+ }) => void;
92
+ onDeviceCode: (info: {
93
+ userCode: string;
94
+ verificationUri: string;
95
+ intervalSeconds?: number;
96
+ expiresInSeconds?: number;
97
+ }) => void;
98
+ onPrompt: (prompt: {
99
+ message: string;
100
+ placeholder?: string;
101
+ allowEmpty?: boolean;
102
+ }) => Promise<string>;
103
+ onProgress?: (message: string) => void;
104
+ onManualCodeInput?: () => Promise<string>;
105
+ onSelect: (prompt: {
106
+ message: string;
107
+ options: Array<{
108
+ id: string;
109
+ label: string;
110
+ }>;
111
+ }) => Promise<string | undefined>;
112
+ signal?: AbortSignal;
113
+ };
@@ -155,9 +155,10 @@ export function generateCliResponse(systemPrompt: any, options?: {}): Promise<{
155
155
  context_compaction_applied: any;
156
156
  };
157
157
  }>;
158
- export namespace claudeCodeBackend {
159
- export let kind: string;
160
- export namespace capabilities {
158
+ export namespace claudeCodeRuntimeBridge {
159
+ let id: string;
160
+ let kind: string;
161
+ namespace capabilities {
161
162
  export let streaming: boolean;
162
163
  export let structured_output: boolean;
163
164
  export let supports_session_resume: boolean;
@@ -171,33 +172,8 @@ export namespace claudeCodeBackend {
171
172
  export { kind_1 as kind };
172
173
  export let runtime: string;
173
174
  }
174
- export { generateCliResponse as execute };
175
- }
176
- export namespace codexCliBackend {
177
- let kind_2: string;
178
- export { kind_2 as kind };
179
- export namespace capabilities_1 {
180
- let kind_3: string;
181
- export { kind_3 as kind };
182
- let runtime_1: string;
183
- export { runtime_1 as runtime };
184
- }
185
- export { capabilities_1 as capabilities };
186
- export { generateCliResponse as execute };
187
- }
188
- export namespace claudeCodeRuntimeBridge {
189
- export let id: string;
190
- let kind_4: string;
191
- export { kind_4 as kind };
192
- export namespace capabilities_2 {
193
- let kind_5: string;
194
- export { kind_5 as kind };
195
- let runtime_2: string;
196
- export { runtime_2 as runtime };
197
- }
198
- export { capabilities_2 as capabilities };
199
- export function supports(ref: any, options: any): boolean;
200
- export function execute(systemPrompt: any, options: any): Promise<{
175
+ function supports(ref: any, options: any): boolean;
176
+ function execute(systemPrompt: any, options: any): Promise<{
201
177
  text: any;
202
178
  structuredResult: any;
203
179
  structuredResultSource: any;
@@ -129,17 +129,10 @@ export function generateClaudeResponse(systemPrompt: any, options: any): Promise
129
129
  context_compaction_applied: any;
130
130
  };
131
131
  }>;
132
- export namespace claudeSdkBackend {
133
- export let kind: string;
134
- export let capabilities: any;
135
- export { generateClaudeResponse as execute };
136
- }
137
132
  export namespace claudeRuntimeBridge {
138
133
  export let id: string;
139
- let kind_1: string;
140
- export { kind_1 as kind };
141
- let capabilities_1: any;
142
- export { capabilities_1 as capabilities };
134
+ export let kind: string;
135
+ export let capabilities: any;
143
136
  export function supports(ref: any): boolean;
144
137
  export { generateClaudeResponse as execute };
145
138
  }
@@ -62,7 +62,7 @@ export function generateCodexAppResponse(systemPrompt: any, options?: {}): Promi
62
62
  };
63
63
  durationMs: number;
64
64
  numTurns: number;
65
- model: string;
65
+ model: any;
66
66
  effort: any;
67
67
  sdk: string;
68
68
  providerSessionId: any;
@@ -124,22 +124,16 @@ export function generateCodexAppResponse(systemPrompt: any, options?: {}): Promi
124
124
  context_compaction_applied: any;
125
125
  };
126
126
  }>;
127
- export namespace codexAppBackend {
128
- export let kind: string;
129
- export { CODEX_APP_CAPABILITIES as capabilities };
130
- export { generateCodexAppResponse as execute };
131
- }
132
127
  export namespace codexAppRuntimeBridge {
133
128
  export let id: string;
134
- let kind_1: string;
135
- export { kind_1 as kind };
129
+ export let kind: string;
136
130
  export { CODEX_APP_CAPABILITIES as capabilities };
137
131
  export function supports(ref: any, options: any): boolean;
138
132
  export { generateCodexAppResponse as execute };
139
133
  }
140
134
  declare namespace CODEX_APP_CAPABILITIES {
141
- let kind_2: string;
142
- export { kind_2 as kind };
135
+ let kind_1: string;
136
+ export { kind_1 as kind };
143
137
  export let runtime: string;
144
138
  export let streaming: boolean;
145
139
  export let structured_output: boolean;
@@ -1,4 +1,3 @@
1
- export function promptTextFromMessages(messages: any): string;
2
1
  export function toAgentMessages(messages: any, model: any): any[];
3
2
  export function textFromContent(content: any): string;
4
3
  export function thinkingFromContent(content: any): string;
@@ -11,7 +11,7 @@ export function usageFromMessages(messages?: Array<any>): {
11
11
  cost: number;
12
12
  };
13
13
  /**
14
- * Normalize the final provider request's usage into an exact context snapshot.
14
+ * Normalize one provider request's usage into an exact context snapshot.
15
15
  * Unlike usageFromMessages(), this deliberately does not aggregate earlier
16
16
  * requests in the run: the last assistant usage is the same provider-counted
17
17
  * value Pi's compaction logic trusts, so it can decrease after compaction.
@@ -40,9 +40,9 @@ export function failureKindForPiError(message: string | null, diagnostics: Recor
40
40
  }): string | null;
41
41
  /**
42
42
  * Emit the per-run cache / cost / provider-completed events.
43
- * @param {{onEvent: (event: any) => void, resolved: any, reference: string, usage: {input: number, output: number, cacheRead: number, cacheWrite: number, cost: number}, contextUsage?: {input: number, output: number, cacheRead: number, cacheCreation: number, total: number}|null, contextWindow?: number, estimatedCost: number, start: number, externalAbort: boolean}} params
43
+ * @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
44
44
  */
45
- export function emitUsageCostEvents({ onEvent, resolved, reference, usage, contextUsage, contextWindow, estimatedCost, start, externalAbort, }: {
45
+ export function emitUsageCostEvents({ onEvent, resolved, reference, usage, estimatedCost, start, externalAbort, }: {
46
46
  onEvent: (event: any) => void;
47
47
  resolved: any;
48
48
  reference: string;
@@ -53,14 +53,6 @@ export function emitUsageCostEvents({ onEvent, resolved, reference, usage, conte
53
53
  cacheWrite: number;
54
54
  cost: number;
55
55
  };
56
- contextUsage?: {
57
- input: number;
58
- output: number;
59
- cacheRead: number;
60
- cacheCreation: number;
61
- total: number;
62
- } | null;
63
- contextWindow?: number;
64
56
  estimatedCost: number;
65
57
  start: number;
66
58
  externalAbort: boolean;
@@ -17,14 +17,16 @@
17
17
  * abort; it is already constructed when this is wired (subscribe follows the
18
18
  * AgentHarness constructor).
19
19
  * @param {StreamSubscriberState} runState
20
- * @param {{onEvent: (event: any) => void, options: any, toolLimits: any, harness: any}} deps
20
+ * @param {{onEvent: (event: any) => void, options: any, toolLimits: any, harness: any, sdk: string, model: string}} deps
21
21
  * @returns {(event: any) => void}
22
22
  */
23
- export function createStreamSubscriber(runState: StreamSubscriberState, { onEvent, options, toolLimits, harness }: {
23
+ export function createStreamSubscriber(runState: StreamSubscriberState, { onEvent, options, toolLimits, harness, sdk, model }: {
24
24
  onEvent: (event: any) => void;
25
25
  options: any;
26
26
  toolLimits: any;
27
27
  harness: any;
28
+ sdk: string;
29
+ model: string;
28
30
  }): (event: any) => void;
29
31
  /**
30
32
  * The slice of run state the stream subscriber reads and mutates. A structural
@@ -32,7 +32,7 @@ export function thinkingLevelForEffort(effort: string, capabilities: any): strin
32
32
  * @param {any} params
33
33
  * @returns {any}
34
34
  */
35
- export function buildTurnHarness(runState: any, { cwd, session, piModels, model, thinkingLevel, systemPrompt, outputSchema, tools, transport, maxRetries, maxRetryDelayMs, steeringMode, onEvent, options, toolLimits, }: any): any;
35
+ export function buildTurnHarness(runState: any, { cwd, session, piModels, model, thinkingLevel, systemPrompt, outputSchema, tools, transport, maxRetries, maxRetryDelayMs, steeringMode, onEvent, options, toolLimits, sdk, reference, }: any): any;
36
36
  /**
37
37
  * Start the live-input steering consumer. Consumes follow-up messages and steers
38
38
  * the harness mid-run; the consumer is tied to run completion (an internal
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @typedef {{body: string, id?: string, receivedAt?: string, acknowledge?: () => void, reject?: (reason?: unknown) => void}} RuntimeLiveInputMessage
3
+ * @typedef {{type: "live_input_applied", inputId: string, receivedAt?: string}} LiveInputAppliedEvent
4
+ */
5
+ /**
6
+ * @param {AsyncIterable<RuntimeLiveInputMessage>|undefined} liveInput
7
+ * @param {(event: LiveInputAppliedEvent) => void} onApplied
8
+ * @returns {AsyncIterable<RuntimeLiveInputMessage>|undefined}
9
+ */
10
+ export function instrumentLiveInputAppliedEvents(liveInput: AsyncIterable<RuntimeLiveInputMessage> | undefined, onApplied: (event: LiveInputAppliedEvent) => void): AsyncIterable<RuntimeLiveInputMessage> | undefined;
11
+ export type RuntimeLiveInputMessage = {
12
+ body: string;
13
+ id?: string;
14
+ receivedAt?: string;
15
+ acknowledge?: () => void;
16
+ reject?: (reason?: unknown) => void;
17
+ };
18
+ export type LiveInputAppliedEvent = {
19
+ type: "live_input_applied";
20
+ inputId: string;
21
+ receivedAt?: string;
22
+ };
@@ -102,9 +102,10 @@
102
102
  * @property {string} [executionMode] "sdk" (default) or "cli"; selects which bridge variant handles the model.
103
103
  * @property {string} [sessionId] Host conversation/session key for resumable bridges.
104
104
  * @property {string} [providerSessionId] Provider-owned resume id for resumable bridges.
105
+ * @property {typeof import("@anthropic-ai/claude-agent-sdk").query} [claudeAgentQuery] Advanced programmatic/test seam for the Claude SDK route; omitted runs use the runtime's pinned SDK query implementation.
105
106
  * @property {boolean} [sessionKeepAlive] Keep resumable provider state alive after the turn.
106
107
  * @property {number} [sessionIdleTimeoutMs] Idle TTL for resumable provider state.
107
- * @property {AsyncIterable<{body: string, id?: string}>} [liveInput] Stream of in-flight user messages for steering an active run.
108
+ * @property {AsyncIterable<{body: string, id?: string, receivedAt?: string, acknowledge?: () => void, reject?: (error?: unknown) => void}>} [liveInput] Stream of in-flight user messages for steering an active run. Providers acknowledge only after accepting a message into the active turn.
108
109
  * @property {ReadonlyArray<*>} [observers] Per-call observers (see RuntimeObserver) merged with host-level (createRuntime) observers.
109
110
  * @property {(event: RuntimeEvent) => void} [onEvent]
110
111
  * @property {ReadonlyArray<Object>} [messages]
@@ -481,6 +482,10 @@ export type RuntimeRunOptions = {
481
482
  * Provider-owned resume id for resumable bridges.
482
483
  */
483
484
  providerSessionId?: string;
485
+ /**
486
+ * Advanced programmatic/test seam for the Claude SDK route; omitted runs use the runtime's pinned SDK query implementation.
487
+ */
488
+ claudeAgentQuery?: typeof import("@anthropic-ai/claude-agent-sdk").query;
484
489
  /**
485
490
  * Keep resumable provider state alive after the turn.
486
491
  */
@@ -490,11 +495,14 @@ export type RuntimeRunOptions = {
490
495
  */
491
496
  sessionIdleTimeoutMs?: number;
492
497
  /**
493
- * Stream of in-flight user messages for steering an active run.
498
+ * Stream of in-flight user messages for steering an active run. Providers acknowledge only after accepting a message into the active turn.
494
499
  */
495
500
  liveInput?: AsyncIterable<{
496
501
  body: string;
497
502
  id?: string;
503
+ receivedAt?: string;
504
+ acknowledge?: () => void;
505
+ reject?: (error?: unknown) => void;
498
506
  }>;
499
507
  /**
500
508
  * Per-call observers (see RuntimeObserver) merged with host-level (createRuntime) observers.
package/src/ai/backend.js DELETED
@@ -1,17 +0,0 @@
1
- import { RUNTIME_CAPABILITIES, runtimeCapabilities } from "./runtime/capabilities.js";
2
-
3
- // Back-compat export name for callers that still ask for backend capabilities.
4
- // The canonical source is the runtime bridge registry.
5
- export const BACKEND_CAPABILITIES = RUNTIME_CAPABILITIES;
6
-
7
- export function backendCapabilities(sdkOrModel) {
8
- return runtimeCapabilities(sdkOrModel);
9
- }
10
-
11
- export function backendUsesExecenvConfig(sdk) {
12
- return !!RUNTIME_CAPABILITIES[sdk]?.native_runtime_config;
13
- }
14
-
15
- export function backendSupportsSessionResume(sdk) {
16
- return !!RUNTIME_CAPABILITIES[sdk]?.supports_session_resume;
17
- }
@@ -1,5 +0,0 @@
1
- export {
2
- listRuntimeBridges as listProviders,
3
- resolveRuntimeBridge as findProviderForModel,
4
- runtimeCapabilities,
5
- } from "./runtime/registry.js";
@@ -1,57 +0,0 @@
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
- supports_fast_mode: boolean;
16
- runtime: string;
17
- };
18
- pi: {
19
- supports_session_resume: boolean;
20
- supports_native_subagents: boolean;
21
- streaming: boolean;
22
- structured_output: boolean;
23
- native_runtime_config: any;
24
- supports_mcp: boolean;
25
- supports_skills: boolean;
26
- supports_builtin_tools: boolean;
27
- supports_live_input: boolean;
28
- supports_fast_mode: boolean;
29
- runtime: string;
30
- };
31
- codex: {
32
- supports_session_resume: boolean;
33
- supports_fast_mode: boolean;
34
- streaming: boolean;
35
- structured_output: boolean;
36
- native_runtime_config: any;
37
- supports_mcp: boolean;
38
- supports_skills: boolean;
39
- supports_builtin_tools: boolean;
40
- supports_live_input: boolean;
41
- supports_native_subagents: boolean;
42
- runtime: string;
43
- };
44
- opencode: {
45
- structured_output: boolean;
46
- supports_session_resume: boolean;
47
- supports_mcp: boolean;
48
- supports_skills: boolean;
49
- supports_live_input: boolean;
50
- supports_native_subagents: boolean;
51
- streaming: boolean;
52
- native_runtime_config: any;
53
- supports_builtin_tools: boolean;
54
- supports_fast_mode: boolean;
55
- runtime: string;
56
- };
57
- };
@@ -1 +0,0 @@
1
- export { listRuntimeBridges as listProviders, resolveRuntimeBridge as findProviderForModel, runtimeCapabilities } from "./runtime/registry.js";