@mono-agent/agent-runtime 0.15.0 → 0.15.2

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/src/runtime.js CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  import { createToolContext, updateToolContext } from "./agent/tools/shared/tool-context.js";
41
41
  import { resolveRuntimeBrand } from "./runtime-brand.js";
42
42
  import { retireDurableNativeSession } from "./ai/providers/pi-native/session-lifecycle.js";
43
+ import { instrumentLiveInputAppliedEvents } from "./ai/runtime/live-input-events.js";
43
44
 
44
45
  /**
45
46
  * @typedef {import('./ai/types.js').AgentRuntimeHostOptions} AgentRuntimeHostOptions
@@ -159,6 +160,7 @@ export function createRuntime(host = {}) {
159
160
  observers: [...hostObservers, ...callObservers],
160
161
  onEvent: options.onEvent,
161
162
  });
163
+ const liveInput = instrumentLiveInputAppliedEvents(options.liveInput, hub.emit);
162
164
  const prompts = resolvePrompts(host.prompts, options.prompts);
163
165
  const result = await bridge.execute(systemPrompt, {
164
166
  ...hostDefaults,
@@ -172,6 +174,7 @@ export function createRuntime(host = {}) {
172
174
  toolContext,
173
175
  observerHub: hub,
174
176
  onEvent: hub.emit,
177
+ ...(liveInput === undefined ? {} : { liveInput }),
175
178
  // Merged AFTER the spreads so the per-field run>host>default precedence
176
179
  // wins over either bag's whole-object `prompts`.
177
180
  ...(prompts === undefined ? {} : { prompts }),
@@ -84,8 +84,6 @@ export type AgentCompactionPolicy = {
84
84
  summaryMaxTokens: number;
85
85
  fixedOverheadEnabled: boolean;
86
86
  compactionMinSavingsTokens: number;
87
- toolPayloadCompactionTriggerChars: number;
88
- toolPruneTriggerTokens: number;
89
87
  toolTextLimitChars: number;
90
88
  bashOutputLimitChars: number;
91
89
  mcpTextLimitChars: number;
@@ -8,6 +8,9 @@ export function buildSkillPathNote({ assetsPath, skillsRoot }?: {
8
8
  skillsRoot?: any;
9
9
  }): string;
10
10
  /**
11
+ * Render a complete skill body plus its path note. Omitting `maxChars` returns
12
+ * the full text; pass a positive `maxChars` only when explicit truncation is
13
+ * required by the caller.
11
14
  * @param {{body?: string, assetsPath?: string, skillsRoot?: any, maxChars?: number}} [options]
12
15
  */
13
16
  export function formatSkillBodyWithPathNote({ body, assetsPath, skillsRoot, maxChars }?: {
@@ -3,5 +3,6 @@ export * from "./runtime/registry.js";
3
3
  export { createSessionRegistry, disposeAllProviderSessions, disposeProviderSession, invalidateProviderSession, refreshProviderSession, syncProviderSession } from "./runtime/sessions.js";
4
4
  export { createMetricsObserver, createObserverHub } from "./observer.js";
5
5
  export { generatePiNativeResponse, piNativeRuntimeBridge } from "./providers/pi-native.js";
6
+ export { getPiBuiltinModel, listPiBuiltinModels, loginPiOAuth, reasoningLevelsForPiModel, resolvePiOAuthApiKey } from "./pi-interop.js";
6
7
  export { CLAUDE_SDK_CATALOG_VERSION, createClaudeSdkDiscoveryIsolation, curatedClaudeSdkModels, discoverClaudeSdkModels, normalizeClaudeSdkCatalog, normalizeClaudeSdkModelId } from "./providers/claude-sdk-discovery.js";
7
8
  export { buildCapabilitiesUsed, toolCompactionAppliedFromWarnings, UNKNOWN_CAPABILITY } from "./runtime/capabilities-used.js";
@@ -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
+ };
@@ -168,6 +168,7 @@ export namespace claudeCodeRuntimeBridge {
168
168
  export let supports_builtin_tools: boolean;
169
169
  export let supports_live_input: boolean;
170
170
  export let supports_native_subagents: boolean;
171
+ export { TOOL_POLICY_PROJECTED as tool_policy };
171
172
  let kind_1: string;
172
173
  export { kind_1 as kind };
173
174
  export let runtime: string;
@@ -301,3 +302,4 @@ export namespace claudeCodeRuntimeBridge {
301
302
  };
302
303
  }>;
303
304
  }
305
+ import { TOOL_POLICY_PROJECTED } from "../runtime/tool-policy.js";
@@ -145,5 +145,7 @@ declare namespace CODEX_APP_CAPABILITIES {
145
145
  export let supports_live_input: boolean;
146
146
  export let supports_native_subagents: boolean;
147
147
  export let supports_fast_mode: boolean;
148
+ export { TOOL_POLICY_ALLOW_ALL_ONLY as tool_policy };
148
149
  }
150
+ import { TOOL_POLICY_ALLOW_ALL_ONLY } from "../runtime/tool-policy.js";
149
151
  export {};
@@ -27,6 +27,7 @@ declare namespace OPENCODE_APP_CAPABILITIES {
27
27
  export let supports_live_input: boolean;
28
28
  export let supports_native_subagents: boolean;
29
29
  export let supports_fast_mode: boolean;
30
+ export { TOOL_POLICY_ALLOW_ALL_ONLY as tool_policy };
30
31
  }
31
32
  declare function generateOpencodeAppResponse(systemPrompt: any, options?: {}): Promise<{
32
33
  text: any;
@@ -91,4 +92,5 @@ declare function generateOpencodeAppResponse(systemPrompt: any, options?: {}): P
91
92
  context_compaction_applied: any;
92
93
  };
93
94
  }>;
95
+ import { TOOL_POLICY_ALLOW_ALL_ONLY } from "../runtime/tool-policy.js";
94
96
  export {};
@@ -1,15 +1,16 @@
1
1
  export function runtimeCapabilities(sdkOrModel: any): any;
2
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
- let supports_fast_mode: boolean;
3
+ export let streaming: boolean;
4
+ export let structured_output: boolean;
5
+ export let supports_session_resume: boolean;
6
+ export let native_runtime_config: any;
7
+ export let supports_mcp: boolean;
8
+ export let supports_skills: boolean;
9
+ export let supports_builtin_tools: boolean;
10
+ export let supports_live_input: boolean;
11
+ export let supports_native_subagents: boolean;
12
+ export let supports_fast_mode: boolean;
13
+ export { TOOL_POLICY_PROJECTED as tool_policy };
13
14
  }
14
15
  export namespace RUNTIME_CAPABILITIES {
15
16
  namespace claude {
@@ -30,6 +31,7 @@ export namespace RUNTIME_CAPABILITIES {
30
31
  export { supports_session_resume_3 as supports_session_resume };
31
32
  let supports_fast_mode_1: boolean;
32
33
  export { supports_fast_mode_1 as supports_fast_mode };
34
+ export { TOOL_POLICY_ALLOW_ALL_ONLY as tool_policy };
33
35
  let runtime_2: string;
34
36
  export { runtime_2 as runtime };
35
37
  }
@@ -46,7 +48,10 @@ export namespace RUNTIME_CAPABILITIES {
46
48
  export { supports_live_input_1 as supports_live_input };
47
49
  let supports_native_subagents_2: boolean;
48
50
  export { supports_native_subagents_2 as supports_native_subagents };
51
+ export { TOOL_POLICY_ALLOW_ALL_ONLY as tool_policy };
49
52
  let runtime_3: string;
50
53
  export { runtime_3 as runtime };
51
54
  }
52
55
  }
56
+ import { TOOL_POLICY_PROJECTED } from "./tool-policy.js";
57
+ import { TOOL_POLICY_ALLOW_ALL_ONLY } from "./tool-policy.js";
@@ -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
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * True when a tool policy is semantically unrestricted.
3
+ *
4
+ * An omitted allowlist and any allowlist containing the global `"*"` sentinel
5
+ * both mean allow-all. A denylist still makes the policy restrictive.
6
+ *
7
+ * @param {*} allowedTools
8
+ * @param {*} disallowedTools
9
+ * @returns {boolean}
10
+ */
11
+ export function isAllowAllToolPolicy(allowedTools: any, disallowedTools: any): boolean;
12
+ /** @type {"projected"} */
13
+ export const TOOL_POLICY_PROJECTED: "projected";
14
+ /** @type {"allow_all_only"} */
15
+ export const TOOL_POLICY_ALLOW_ALL_ONLY: "allow_all_only";
@@ -33,7 +33,12 @@
33
33
  * explicitly permits host execution if unavailable; it does not claim which
34
34
  * branch ran for a particular command.
35
35
  */
36
- /** @typedef {"mono-agent-monotonic"|"mono-agent-policy"|"provider-representable"|"exact-allow-all"|"unsupported"} RuntimeRouteToolsContract */
36
+ /**
37
+ * @typedef {"mono-agent-monotonic"|"mono-agent-policy"|"provider-representable"|"exact-allow-all"|"unsupported"} RuntimeRouteToolsContract
38
+ * `exact-allow-all` is a stable telemetry token. It describes an effective
39
+ * unrestricted contract, including mixed allowlists that contain `"*"`;
40
+ * it does not require the literal one-element array `["*"]`.
41
+ */
37
42
  /**
38
43
  * @typedef {Object} RuntimeRouteSafetyContract
39
44
  * Bounded, credential-free description of the sandbox/tool contract applied
@@ -102,6 +107,7 @@
102
107
  * @property {string} [executionMode] "sdk" (default) or "cli"; selects which bridge variant handles the model.
103
108
  * @property {string} [sessionId] Host conversation/session key for resumable bridges.
104
109
  * @property {string} [providerSessionId] Provider-owned resume id for resumable bridges.
110
+ * @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
111
  * @property {boolean} [sessionKeepAlive] Keep resumable provider state alive after the turn.
106
112
  * @property {number} [sessionIdleTimeoutMs] Idle TTL for resumable provider state.
107
113
  * @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.
@@ -190,6 +196,10 @@
190
196
  * @property {boolean} [supports_live_input]
191
197
  * @property {boolean} [supports_native_subagents]
192
198
  * @property {boolean} [supports_fast_mode]
199
+ * @property {"projected"|"allow_all_only"} [tool_policy] Whether the bridge can
200
+ * project named allow/deny policies or accepts only a semantically unrestricted
201
+ * policy. Built-in bridges always report this field; omission means unknown
202
+ * for custom structural capability objects.
193
203
  */
194
204
  /**
195
205
  * @typedef {Object} RuntimeBridge
@@ -340,6 +350,11 @@ export type RuntimeRouteSafetyMode = "uniform" | "per-route-native";
340
350
  * branch ran for a particular command.
341
351
  */
342
352
  export type RuntimeRouteSandboxContract = "mono-agent-monotonic" | "disabled" | "mono-agent-srt" | "mono-agent-srt-unsafe-host-fallback" | "provider-native" | "codex-native" | "unsupported";
353
+ /**
354
+ * `exact-allow-all` is a stable telemetry token. It describes an effective
355
+ * unrestricted contract, including mixed allowlists that contain `"*"`;
356
+ * it does not require the literal one-element array `["*"]`.
357
+ */
343
358
  export type RuntimeRouteToolsContract = "mono-agent-monotonic" | "mono-agent-policy" | "provider-representable" | "exact-allow-all" | "unsupported";
344
359
  /**
345
360
  * Bounded, credential-free description of the sandbox/tool contract applied
@@ -481,6 +496,10 @@ export type RuntimeRunOptions = {
481
496
  * Provider-owned resume id for resumable bridges.
482
497
  */
483
498
  providerSessionId?: string;
499
+ /**
500
+ * Advanced programmatic/test seam for the Claude SDK route; omitted runs use the runtime's pinned SDK query implementation.
501
+ */
502
+ claudeAgentQuery?: typeof import("@anthropic-ai/claude-agent-sdk").query;
484
503
  /**
485
504
  * Keep resumable provider state alive after the turn.
486
505
  */
@@ -649,6 +668,13 @@ export type RuntimeCapabilities = {
649
668
  supports_live_input?: boolean;
650
669
  supports_native_subagents?: boolean;
651
670
  supports_fast_mode?: boolean;
671
+ /**
672
+ * Whether the bridge can
673
+ * project named allow/deny policies or accepts only a semantically unrestricted
674
+ * policy. Built-in bridges always report this field; omission means unknown
675
+ * for custom structural capability objects.
676
+ */
677
+ tool_policy?: "projected" | "allow_all_only";
652
678
  };
653
679
  /**
654
680
  * A fully loaded bridge (registry.js's resolveRuntimeBridge result): the
@@ -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";