@mono-agent/agent-runtime 0.15.2 → 0.15.4

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 (39) hide show
  1. package/README.md +55 -7
  2. package/package.json +5 -1
  3. package/src/agent/tools/agent-tool.js +859 -0
  4. package/src/agent/tools/bash.js +241 -123
  5. package/src/agent/tools/exec.js +238 -0
  6. package/src/agent/tools/index.js +10 -3
  7. package/src/agent/tools/node-repl.js +231 -95
  8. package/src/agent/tools/pi-bridge.js +115 -24
  9. package/src/agent/tools/shared/process-runner.js +162 -0
  10. package/src/agent/tools/shared/semaphore.js +73 -0
  11. package/src/agent/tools/web-browser-render.js +221 -0
  12. package/src/agent/tools/web-controller.js +160 -0
  13. package/src/agent/tools/web-fetch.js +653 -68
  14. package/src/agent/tools/web-search.js +568 -16
  15. package/src/ai/providers/codex-app.js +18 -0
  16. package/src/ai/providers/pi-native/stream-subscriber.js +37 -0
  17. package/src/ai/providers/pi-native/turn-runner.js +60 -5
  18. package/src/ai/providers/pi-native.js +49 -5
  19. package/src/ai/runtime/router.js +302 -166
  20. package/src/ai/types.js +52 -1
  21. package/src/runtime.js +51 -1
  22. package/types/agent/tools/agent-tool.d.ts +60 -0
  23. package/types/agent/tools/bash.d.ts +55 -7
  24. package/types/agent/tools/exec.d.ts +53 -0
  25. package/types/agent/tools/index.d.ts +5 -3
  26. package/types/agent/tools/node-repl.d.ts +28 -3
  27. package/types/agent/tools/pi-bridge.d.ts +6 -2
  28. package/types/agent/tools/shared/process-runner.d.ts +33 -0
  29. package/types/agent/tools/shared/semaphore.d.ts +29 -0
  30. package/types/agent/tools/web-browser-render.d.ts +16 -0
  31. package/types/agent/tools/web-controller.d.ts +20 -0
  32. package/types/agent/tools/web-fetch.d.ts +74 -5
  33. package/types/agent/tools/web-search.d.ts +81 -5
  34. package/types/ai/backend.d.ts +57 -0
  35. package/types/ai/providers/pi-native/turn-runner.d.ts +34 -2
  36. package/types/ai/providers/pi-native.d.ts +12 -0
  37. package/types/ai/registry.d.ts +1 -0
  38. package/types/ai/runtime/router.d.ts +23 -3
  39. package/types/ai/types.d.ts +163 -1
@@ -0,0 +1,57 @@
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
+ };
@@ -9,7 +9,7 @@
9
9
  * @param {any} params
10
10
  * @returns {Promise<{tools: any[], structuredTool: any, mcpClients: any[], closeRunTools: () => Promise<void>}>}
11
11
  */
12
- export function buildTurnTools(runState: any, { options, capabilities, toolLimits, approvalManager, runtime, resolved, onEvent, runtimeWarnings, }: any): Promise<{
12
+ export function buildTurnTools(runState: any, { options, capabilities, toolLimits, approvalManager, runtime, resolved, onEvent, runtimeWarnings, toolExecutionMode, }: any): Promise<{
13
13
  tools: any[];
14
14
  structuredTool: any;
15
15
  mcpClients: any[];
@@ -32,7 +32,38 @@ 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, sdk, reference, }: any): any;
35
+ /**
36
+ * Restore the error flag on a tool result pi resolved successfully.
37
+ *
38
+ * pi hardcodes `isError: false` for every `execute()` that returns rather than
39
+ * throws, so any tool that reports failure in its payload needs this hook or
40
+ * the model is told the call succeeded.
41
+ *
42
+ * @param {*} details Tool-result details recorded by the bridge.
43
+ * @returns {{isError: true}|undefined}
44
+ */
45
+ export function toolResultErrorOverride(details: any): {
46
+ isError: true;
47
+ } | undefined;
48
+ export function buildTurnHarness(runState: any, { cwd, session, piModels, model, thinkingLevel, systemPrompt, outputSchema, tools, transport, maxRetries, maxRetryDelayMs, steeringMode, onEvent, options, toolLimits, sdk, reference, }: {
49
+ cwd: any;
50
+ session: any;
51
+ piModels: any;
52
+ model: any;
53
+ thinkingLevel: any;
54
+ systemPrompt: any;
55
+ outputSchema: any;
56
+ tools: any;
57
+ transport: any;
58
+ maxRetries: any;
59
+ maxRetryDelayMs: any;
60
+ steeringMode: any;
61
+ onEvent: any;
62
+ options: any;
63
+ toolLimits: any;
64
+ sdk: any;
65
+ reference: any;
66
+ }): AgentHarness<import("@earendil-works/pi-agent-core").Skill, import("@earendil-works/pi-agent-core").PromptTemplate, import("@earendil-works/pi-agent-core").AgentTool<import("@earendil-works/pi-ai").TSchema, any>>;
36
67
  /**
37
68
  * Start the live-input steering consumer. Consumes follow-up messages and steers
38
69
  * the harness mid-run; the consumer is tied to run completion (an internal
@@ -60,3 +91,4 @@ export function startLiveInput({ harness, options, onEvent }: {
60
91
  export function runHarnessPrompt(harness: any, promptText: string, promptImages: Array<any>): Promise<{
61
92
  runError: any;
62
93
  }>;
94
+ import { AgentHarness } from "@earendil-works/pi-agent-core";
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Pi 0.80.6 exposes per-tool execution markers but not AgentHarness's global
3
+ * toolExecution option. Resolve mono-agent's programmatic mode once per run;
4
+ * individual tool builders then mark stateful/mutating tools sequential.
5
+ */
6
+ export function resolvePiToolExecutionMode(options?: {}): {
7
+ mode: any;
8
+ warnings: {
9
+ warning_kind: string;
10
+ message: string;
11
+ }[];
12
+ };
1
13
  export function createDynamicCredentialStore(apiKeys: any, resolvePiApiKey: any, runtimeWarnings: any): any;
2
14
  export function splitPromptMessages(messages: any, model: any): {
3
15
  priorMessages: any[];
@@ -0,0 +1 @@
1
+ export { listRuntimeBridges as listProviders, resolveRuntimeBridge as findProviderForModel, runtimeCapabilities } from "./runtime/registry.js";
@@ -3,10 +3,12 @@
3
3
  * @param {AgentRuntimeHostOptions} [options.host]
4
4
  * @param {ReadonlyArray<RuntimeModelRef|RouterChainEntryInput>} [options.chain]
5
5
  * @param {"uniform"|"per-route-native"} [options.routeSafety]
6
- * @param {(input: {model: RuntimeModelRef, executionMode: string|null, attemptIndex: number, routeSafety: "uniform"|"per-route-native"}) => (RouterAttemptResolution|Promise<RouterAttemptResolution>)} [options.resolveAttempt]
6
+ * @param {(input: {model: RuntimeModelRef, executionMode: string|null, attemptIndex: number, retryIndex: number, routeSafety: "uniform"|"per-route-native"}) => (RouterAttemptResolution|Promise<RouterAttemptResolution>)} [options.resolveAttempt]
7
+ * @param {Partial<RouterRetryPolicy>} [options.retry] Backoff shape for same-model
8
+ * retries. Per-route retry counts live on each chain entry's `attempts`.
7
9
  * @returns {AgentRuntimeInstance & {chain: () => Array<RouterChainEntry>}}
8
10
  */
9
- export function createRouterRuntime({ host, chain, routeSafety, resolveAttempt }?: {
11
+ export function createRouterRuntime({ host, chain, routeSafety, resolveAttempt, retry }?: {
10
12
  host?: AgentRuntimeHostOptions;
11
13
  chain?: ReadonlyArray<RuntimeModelRef | RouterChainEntryInput>;
12
14
  routeSafety?: "uniform" | "per-route-native";
@@ -14,8 +16,10 @@ export function createRouterRuntime({ host, chain, routeSafety, resolveAttempt }
14
16
  model: RuntimeModelRef;
15
17
  executionMode: string | null;
16
18
  attemptIndex: number;
19
+ retryIndex: number;
17
20
  routeSafety: "uniform" | "per-route-native";
18
21
  }) => (RouterAttemptResolution | Promise<RouterAttemptResolution>);
22
+ retry?: Partial<RouterRetryPolicy>;
19
23
  }): AgentRuntimeInstance & {
20
24
  chain: () => Array<RouterChainEntry>;
21
25
  };
@@ -26,7 +30,8 @@ export type RuntimeRunOptions = import("../types.js").RuntimeRunOptions;
26
30
  export type RuntimeResult = import("../types.js").RuntimeResult;
27
31
  /**
28
32
  * A chain entry as accepted by createRouterRuntime: either the shorthand bare
29
- * RuntimeModelRef, or the full `{model, executionMode?, effort?, requires?}` form.
33
+ * RuntimeModelRef, or the full `{model, executionMode?, effort?, requires?,
34
+ * attempts?}` form.
30
35
  */
31
36
  export type RouterChainEntryInput = {
32
37
  model: RuntimeModelRef;
@@ -35,6 +40,7 @@ export type RouterChainEntryInput = {
35
40
  requires?: {
36
41
  [x: string]: any;
37
42
  };
43
+ attempts?: number;
38
44
  };
39
45
  export type RouterChainEntry = {
40
46
  model: RuntimeModelRef;
@@ -43,6 +49,20 @@ export type RouterChainEntry = {
43
49
  requires: {
44
50
  [x: string]: any;
45
51
  } | null;
52
+ /**
53
+ * Total attempts on this route including the first.
54
+ */
55
+ attempts: number;
56
+ };
57
+ export type RouterRetryPolicy = {
58
+ /**
59
+ * Delay before the first retry; doubles per retry.
60
+ */
61
+ backoffMs: number;
62
+ /**
63
+ * Ceiling for the doubled delay.
64
+ */
65
+ maxBackoffMs: number;
46
66
  };
47
67
  /**
48
68
  * Private host seam for route-specific provider options/runtime ownership.
@@ -132,8 +132,13 @@
132
132
  * @property {RuntimeToolLimits} [toolLimits] Typed per-run tool-output limits (supported replacement for the deprecated `settings` tool keys).
133
133
  * @property {RuntimeCompactionPolicy} [compaction] Typed per-run compaction policy (supported replacement for the deprecated `settings` compaction keys).
134
134
  * @property {RuntimePromptOverrides} [prompts] Per-run prompt-fragment overrides (run wins over the host default).
135
+ * @property {{backend?: "auto"|"searxng"|"keyless", endpoint?: string}} [webSearchConfig] Run-scoped WebSearch backend configuration.
136
+ * @property {{render?: "never"|"auto", browserCommand?: string}} [webFetchConfig] Run-scoped WebFetch extraction/render configuration.
137
+ * @property {"sequential"|"safe-parallel"} [piToolExecutionMode] Pi built-in tool scheduling mode. Safe parallelism is the default.
138
+ * @property {"one-at-a-time"|"all"} [piToolParallelismMode] DEPRECATED. Compatibility alias mapped to piToolExecutionMode.
135
139
  * @property {Object} [settings] DEPRECATED. Legacy flat settings bag; consumed only as a per-group FALLBACK when the corresponding typed object (`toolLimits` / `compaction`) is absent. Consuming any key emits one `deprecated_settings_option` runtime_warning per run. Migrate via resolveRuntimePolicies (@mono-agent/runtime-adapter).
136
140
  * @property {Object} [nativeSubagents] Same-runtime teammate helpers exposed through native provider subagent surfaces.
141
+ * @property {RuntimeSubagentsOptions} [subagents] In-process `Agent` built-in: profiles, caps, and the nested-run callback.
137
142
  * @property {Object} [diagnosticsSeed] Set by createRouterRuntime (ai/runtime/router.js) with a `resume_snapshot` when
138
143
  * failing over mid-chain; a host-level coordinator may relay it forward (see agent/transcript.js), not read by any
139
144
  * bridge in this package today.
@@ -154,6 +159,48 @@
154
159
  * createRuntime), and the per-run observerHub (onEvent is overridden to the
155
160
  * hub's emit). `systemPrompt` is passed positionally, not folded into this object.
156
161
  */
162
+ /**
163
+ * @typedef {Object} RuntimeSubagentDefinition
164
+ * One named subagent profile the `Agent` built-in can deploy.
165
+ * @property {string} name Model-visible identifier and the tool's `name` enum value.
166
+ * @property {string} description Model-visible: when to pick this profile.
167
+ * @property {string} systemPrompt Full system prompt for the child run.
168
+ * @property {RuntimeModelRef} [model] Absent inherits the parent's configured route.
169
+ * @property {string} [effort]
170
+ * @property {ReadonlyArray<string>} [allowedTools] Absent uses the safe read-only default set.
171
+ * @property {ReadonlyArray<string>} [disallowedTools]
172
+ * @property {Object<string, Object>} [mcpServers]
173
+ * @property {number} [maxTurns]
174
+ * @property {number} [timeoutMs]
175
+ */
176
+ /**
177
+ * @callback RuntimeSubagentRun
178
+ * Owning-layer callback that actually executes one child turn. The kernel
179
+ * supplies a self-run fallback so `createRuntime` works without host wiring;
180
+ * agent-app replaces it so subagent runs get the configured fallback chain,
181
+ * same-model retries, and run recording.
182
+ * @param {Object} request
183
+ * @returns {Promise<RuntimeResult>}
184
+ */
185
+ /**
186
+ * @typedef {Object} RuntimeInlineSubagentsOptions
187
+ * Policy for subagents the model authors at call time rather than picking from
188
+ * `definitions`. Absent suppresses authoring entirely.
189
+ * @property {boolean} [enabled] Only `false` turns authoring off.
190
+ * @property {ReadonlyArray<string>} [allowedTools] Ceiling on what an authored subagent may
191
+ * request. Absent means the safe read-only default set, never every built-in.
192
+ */
193
+ /**
194
+ * @typedef {Object} RuntimeSubagentsOptions
195
+ * @property {ReadonlyArray<RuntimeSubagentDefinition>} [definitions] Named profiles.
196
+ * @property {RuntimeInlineSubagentsOptions} [inline] Call-time authoring policy.
197
+ * @property {number} [maxConcurrent] In-flight subagents per parent turn. Default 5.
198
+ * @property {number} [maxPerTurn] Total Agent calls per parent turn. Default 20.
199
+ * @property {number} [maxTurns] Default per-subagent turn cap. Default 100.
200
+ * @property {number} [timeoutMs] Default per-subagent wall clock.
201
+ * @property {RuntimeSubagentRun} [run] Nested-run callback; absent uses the kernel self-run.
202
+ * @property {number} [depth] Kernel-owned. Absent/0 is the parent; >=1 suppresses the `Agent` tool.
203
+ */
157
204
  /**
158
205
  * @typedef {Object} RuntimeResult
159
206
  * @property {string|null} [text]
@@ -175,7 +222,7 @@
175
222
  * @property {Array<Object>} [runtimeWarnings]
176
223
  * @property {Object} [diagnostics]
177
224
  * @property {Object} [capabilitiesUsed]
178
- * @property {Array<{model: RuntimeModelRef, failureKind: (string|null), requestId?: (string|null), retryableSubkind?: (string|null), requirements?: Object, routeSafety?: RuntimeRouteSafetyMode, safetyContract?: RuntimeRouteSafetyContract}>} [failoverHistory] Set by createRouterRuntime (ai/runtime/router.js) on every failed/skipped attempt.
225
+ * @property {Array<{model: RuntimeModelRef, failureKind: (string|null), requestId?: (string|null), retryableSubkind?: (string|null), retryIndex?: number, requirements?: Object, routeSafety?: RuntimeRouteSafetyMode, safetyContract?: RuntimeRouteSafetyContract}>} [failoverHistory] Set by createRouterRuntime (ai/runtime/router.js) on every failed/skipped attempt.
179
226
  * @property {Array<{attemptIndex: number, model: RuntimeModelRef, routeSafety: RuntimeRouteSafetyMode, safetyContract: RuntimeRouteSafetyContract, status: string}>} [routeSafetyHistory] Bounded route-safety audit emitted by createRouterRuntime.
180
227
  */
181
228
  /**
@@ -565,6 +612,28 @@ export type RuntimeRunOptions = {
565
612
  * Per-run prompt-fragment overrides (run wins over the host default).
566
613
  */
567
614
  prompts?: RuntimePromptOverrides;
615
+ /**
616
+ * Run-scoped WebSearch backend configuration.
617
+ */
618
+ webSearchConfig?: {
619
+ backend?: "auto" | "searxng" | "keyless";
620
+ endpoint?: string;
621
+ };
622
+ /**
623
+ * Run-scoped WebFetch extraction/render configuration.
624
+ */
625
+ webFetchConfig?: {
626
+ render?: "never" | "auto";
627
+ browserCommand?: string;
628
+ };
629
+ /**
630
+ * Pi built-in tool scheduling mode. Safe parallelism is the default.
631
+ */
632
+ piToolExecutionMode?: "sequential" | "safe-parallel";
633
+ /**
634
+ * DEPRECATED. Compatibility alias mapped to piToolExecutionMode.
635
+ */
636
+ piToolParallelismMode?: "one-at-a-time" | "all";
568
637
  /**
569
638
  * DEPRECATED. Legacy flat settings bag; consumed only as a per-group FALLBACK when the corresponding typed object (`toolLimits` / `compaction`) is absent. Consuming any key emits one `deprecated_settings_option` runtime_warning per run. Migrate via resolveRuntimePolicies (@mono-agent/runtime-adapter).
570
639
  */
@@ -573,6 +642,10 @@ export type RuntimeRunOptions = {
573
642
  * Same-runtime teammate helpers exposed through native provider subagent surfaces.
574
643
  */
575
644
  nativeSubagents?: any;
645
+ /**
646
+ * In-process `Agent` built-in: profiles, caps, and the nested-run callback.
647
+ */
648
+ subagents?: RuntimeSubagentsOptions;
576
649
  /**
577
650
  * Set by createRouterRuntime (ai/runtime/router.js) with a `resume_snapshot` when
578
651
  * failing over mid-chain; a host-level coordinator may relay it forward (see agent/transcript.js), not read by any
@@ -603,6 +676,94 @@ export type RuntimeRequest = RuntimeRunOptions & Pick<AgentRuntimeHostOptions, "
603
676
  flush: () => Promise<void>;
604
677
  };
605
678
  };
679
+ /**
680
+ * One named subagent profile the `Agent` built-in can deploy.
681
+ */
682
+ export type RuntimeSubagentDefinition = {
683
+ /**
684
+ * Model-visible identifier and the tool's `name` enum value.
685
+ */
686
+ name: string;
687
+ /**
688
+ * Model-visible: when to pick this profile.
689
+ */
690
+ description: string;
691
+ /**
692
+ * Full system prompt for the child run.
693
+ */
694
+ systemPrompt: string;
695
+ /**
696
+ * Absent inherits the parent's configured route.
697
+ */
698
+ model?: RuntimeModelRef;
699
+ effort?: string;
700
+ /**
701
+ * Absent uses the safe read-only default set.
702
+ */
703
+ allowedTools?: ReadonlyArray<string>;
704
+ disallowedTools?: ReadonlyArray<string>;
705
+ mcpServers?: {
706
+ [x: string]: any;
707
+ };
708
+ maxTurns?: number;
709
+ timeoutMs?: number;
710
+ };
711
+ /**
712
+ * Owning-layer callback that actually executes one child turn. The kernel
713
+ * supplies a self-run fallback so `createRuntime` works without host wiring;
714
+ * agent-app replaces it so subagent runs get the configured fallback chain,
715
+ * same-model retries, and run recording.
716
+ */
717
+ export type RuntimeSubagentRun = (request: any) => Promise<RuntimeResult>;
718
+ /**
719
+ * Policy for subagents the model authors at call time rather than picking from
720
+ * `definitions`. Absent suppresses authoring entirely.
721
+ */
722
+ export type RuntimeInlineSubagentsOptions = {
723
+ /**
724
+ * Only `false` turns authoring off.
725
+ */
726
+ enabled?: boolean;
727
+ /**
728
+ * Ceiling on what an authored subagent may
729
+ * request. Absent means the safe read-only default set, never every built-in.
730
+ */
731
+ allowedTools?: ReadonlyArray<string>;
732
+ };
733
+ export type RuntimeSubagentsOptions = {
734
+ /**
735
+ * Named profiles.
736
+ */
737
+ definitions?: ReadonlyArray<RuntimeSubagentDefinition>;
738
+ /**
739
+ * Call-time authoring policy.
740
+ */
741
+ inline?: RuntimeInlineSubagentsOptions;
742
+ /**
743
+ * In-flight subagents per parent turn. Default 5.
744
+ */
745
+ maxConcurrent?: number;
746
+ /**
747
+ * Total Agent calls per parent turn. Default 20.
748
+ */
749
+ maxPerTurn?: number;
750
+ /**
751
+ * Default per-subagent turn cap. Default 100.
752
+ */
753
+ maxTurns?: number;
754
+ /**
755
+ * Default per-subagent wall clock.
756
+ */
757
+ timeoutMs?: number;
758
+ /**
759
+ * Nested-run callback; absent uses the kernel self-run.
760
+ */
761
+ run?: RuntimeSubagentRun;
762
+ /**
763
+ * Kernel-owned. Absent/0 is the parent; >=1 suppresses the `Agent` tool.
764
+ */
765
+ depth?: number;
766
+ };
606
767
  export type RuntimeResult = {
607
768
  text?: string | null;
608
769
  structuredResult?: any;
@@ -634,6 +795,7 @@ export type RuntimeResult = {
634
795
  failureKind: (string | null);
635
796
  requestId?: (string | null);
636
797
  retryableSubkind?: (string | null);
798
+ retryIndex?: number;
637
799
  requirements?: any;
638
800
  routeSafety?: RuntimeRouteSafetyMode;
639
801
  safetyContract?: RuntimeRouteSafetyContract;