@mono-agent/agent-runtime 0.3.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.
Files changed (123) hide show
  1. package/ARCHITECTURE.md +75 -9
  2. package/MIGRATION.md +293 -0
  3. package/README.md +46 -20
  4. package/package.json +104 -10
  5. package/src/agent/allowlists.js +3 -0
  6. package/src/agent/approval.js +3 -0
  7. package/src/agent/compaction.js +231 -654
  8. package/src/agent/index.js +1 -1
  9. package/src/agent/prompt/skill-index.js +6 -0
  10. package/src/agent/sandbox-seam.js +227 -0
  11. package/src/agent/tool-bloat.js +8 -2
  12. package/src/agent/tools/bash.js +16 -8
  13. package/src/agent/tools/edit.js +7 -3
  14. package/src/agent/tools/glob.js +11 -5
  15. package/src/agent/tools/grep.js +11 -5
  16. package/src/agent/tools/pi-bridge.js +272 -54
  17. package/src/agent/tools/read.js +28 -3
  18. package/src/agent/tools/shared/output-truncation.js +8 -3
  19. package/src/agent/tools/shared/path-resolver.js +24 -18
  20. package/src/agent/tools/shared/ripgrep.js +33 -6
  21. package/src/agent/tools/shared/runtime-context.js +60 -50
  22. package/src/agent/tools/shared/tool-context.js +157 -0
  23. package/src/agent/tools/web-fetch.js +65 -18
  24. package/src/agent/tools/web-search.js +11 -4
  25. package/src/agent/tools/write.js +7 -3
  26. package/src/agent/transcript.js +16 -1
  27. package/src/ai/cost.js +128 -3
  28. package/src/ai/failure.js +96 -4
  29. package/src/ai/index.js +1 -0
  30. package/src/ai/live-input-prompt.js +11 -1
  31. package/src/ai/providers/claude-cli.js +6 -2
  32. package/src/ai/providers/claude-sdk.js +55 -12
  33. package/src/ai/providers/codex-app.js +36 -23
  34. package/src/ai/providers/opencode-app.js +2 -2
  35. package/src/ai/providers/opencode-discovery.js +2 -2
  36. package/src/ai/providers/pi-errors.js +65 -0
  37. package/src/ai/providers/pi-events.js +5 -0
  38. package/src/ai/providers/pi-models.js +21 -4
  39. package/src/ai/providers/pi-native/compaction-driver.js +394 -0
  40. package/src/ai/providers/pi-native/result-builder.js +312 -0
  41. package/src/ai/providers/pi-native/session-lifecycle.js +438 -0
  42. package/src/ai/providers/pi-native/stream-subscriber.js +148 -0
  43. package/src/ai/providers/pi-native/structured-output.js +130 -0
  44. package/src/ai/providers/pi-native/turn-runner.js +278 -0
  45. package/src/ai/providers/pi-native.js +754 -0
  46. package/src/ai/runtime/capabilities.js +3 -0
  47. package/src/ai/runtime/model-refs.js +30 -0
  48. package/src/ai/runtime/registry.js +33 -2
  49. package/src/ai/runtime/router.js +119 -19
  50. package/src/ai/runtime/session-liveness.js +110 -0
  51. package/src/ai/runtime/sessions.js +19 -2
  52. package/src/ai/types.js +252 -20
  53. package/src/index.js +1 -1
  54. package/src/pi-auth.js +147 -16
  55. package/src/runtime-brand.js +21 -1
  56. package/src/runtime.js +75 -10
  57. package/types/agent/allowlists.d.ts +25 -0
  58. package/types/agent/approval.d.ts +30 -0
  59. package/types/agent/compaction.d.ts +97 -0
  60. package/types/agent/index.d.ts +5 -0
  61. package/types/agent/prompt/skill-index.d.ts +19 -0
  62. package/types/agent/sandbox-seam.d.ts +148 -0
  63. package/types/agent/tool-bloat.d.ts +22 -0
  64. package/types/agent/tools/bash.d.ts +16 -0
  65. package/types/agent/tools/edit.d.ts +14 -0
  66. package/types/agent/tools/glob.d.ts +16 -0
  67. package/types/agent/tools/grep.d.ts +22 -0
  68. package/types/agent/tools/index.d.ts +10 -0
  69. package/types/agent/tools/pi-bridge.d.ts +144 -0
  70. package/types/agent/tools/read.d.ts +19 -0
  71. package/types/agent/tools/shared/constants.d.ts +13 -0
  72. package/types/agent/tools/shared/dedup.d.ts +8 -0
  73. package/types/agent/tools/shared/output-truncation.d.ts +22 -0
  74. package/types/agent/tools/shared/path-resolver.d.ts +6 -0
  75. package/types/agent/tools/shared/ripgrep.d.ts +38 -0
  76. package/types/agent/tools/shared/runtime-context.d.ts +27 -0
  77. package/types/agent/tools/shared/tool-context.d.ts +48 -0
  78. package/types/agent/tools/web-fetch.d.ts +13 -0
  79. package/types/agent/tools/web-search.d.ts +11 -0
  80. package/types/agent/tools/write.d.ts +12 -0
  81. package/types/agent/transcript.d.ts +45 -0
  82. package/types/ai/backend.d.ts +41 -0
  83. package/types/ai/cost.d.ts +96 -0
  84. package/types/ai/failure.d.ts +117 -0
  85. package/types/ai/file-change-stats.d.ts +75 -0
  86. package/types/ai/index.d.ts +7 -0
  87. package/types/ai/live-input-prompt.d.ts +6 -0
  88. package/types/ai/observer.d.ts +68 -0
  89. package/types/ai/providers/claude-cli.d.ts +211 -0
  90. package/types/ai/providers/claude-sdk.d.ts +66 -0
  91. package/types/ai/providers/claude-subagents.d.ts +2 -0
  92. package/types/ai/providers/codex-app.d.ts +151 -0
  93. package/types/ai/providers/opencode-app.d.ts +95 -0
  94. package/types/ai/providers/opencode-discovery.d.ts +4 -0
  95. package/types/ai/providers/pi-errors.d.ts +3 -0
  96. package/types/ai/providers/pi-events.d.ts +24 -0
  97. package/types/ai/providers/pi-messages.d.ts +5 -0
  98. package/types/ai/providers/pi-models.d.ts +57 -0
  99. package/types/ai/providers/pi-native/compaction-driver.d.ts +86 -0
  100. package/types/ai/providers/pi-native/result-builder.d.ts +168 -0
  101. package/types/ai/providers/pi-native/session-lifecycle.d.ts +62 -0
  102. package/types/ai/providers/pi-native/stream-subscriber.d.ts +50 -0
  103. package/types/ai/providers/pi-native/structured-output.d.ts +69 -0
  104. package/types/ai/providers/pi-native/turn-runner.d.ts +60 -0
  105. package/types/ai/providers/pi-native.d.ts +18 -0
  106. package/types/ai/registry.d.ts +1 -0
  107. package/types/ai/runtime/capabilities-used.d.ts +21 -0
  108. package/types/ai/runtime/capabilities.d.ts +33 -0
  109. package/types/ai/runtime/context-windows.d.ts +8 -0
  110. package/types/ai/runtime/fast-mode.d.ts +2 -0
  111. package/types/ai/runtime/model-refs.d.ts +35 -0
  112. package/types/ai/runtime/registry.d.ts +38 -0
  113. package/types/ai/runtime/router.d.ts +56 -0
  114. package/types/ai/runtime/session-liveness.d.ts +55 -0
  115. package/types/ai/runtime/sessions.d.ts +38 -0
  116. package/types/ai/streaming/codex-events.d.ts +30 -0
  117. package/types/ai/streaming/opencode-events.d.ts +41 -0
  118. package/types/ai/types.d.ts +702 -0
  119. package/types/index.d.ts +7 -0
  120. package/types/pi-auth.d.ts +28 -0
  121. package/types/runtime-brand.d.ts +30 -0
  122. package/types/runtime.d.ts +10 -0
  123. package/src/ai/providers/pi-sdk.js +0 -1310
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @param {string} value
3
+ * @returns {string}
4
+ */
5
+ export function canonicalizeLegacyModelReference(value: string): string;
6
+ /**
7
+ * @param {string} value
8
+ * @returns {RuntimeModelRef}
9
+ */
10
+ export function normalizeRuntimeModelReference(value: string): RuntimeModelRef;
11
+ /**
12
+ * @param {string} value
13
+ * @returns {RuntimeModelRef["sdk"]}
14
+ */
15
+ export function sdkFromModelReference(value: string): RuntimeModelRef["sdk"];
16
+ /**
17
+ * @param {string} value
18
+ * @returns {RuntimeModelRef}
19
+ */
20
+ export function parseRuntimeModelReference(value: string): RuntimeModelRef;
21
+ /**
22
+ * @param {string|RuntimeModelRef} modelRefOrParsed
23
+ * @param {string} executionMode
24
+ * @returns {string|null}
25
+ */
26
+ export function executionModeIncompatibilityReason(modelRefOrParsed: string | RuntimeModelRef, executionMode: string): string | null;
27
+ /**
28
+ * @param {string|RuntimeModelRef} modelRefOrParsed
29
+ * @param {string} executionMode
30
+ * @returns {boolean}
31
+ */
32
+ export function isModelCompatibleWithExecutionMode(modelRefOrParsed: string | RuntimeModelRef, executionMode: string): boolean;
33
+ export const ACTIVE_RUNTIME_KINDS: string[];
34
+ export const RESERVED_RUNTIME_KINDS: string[];
35
+ export type RuntimeModelRef = import("../types.js").RuntimeModelRef;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @returns {Array<RuntimeBridgeDescriptor>}
3
+ */
4
+ export function listRuntimeBridges(): Array<RuntimeBridgeDescriptor>;
5
+ /**
6
+ * @param {import('../types.js').RuntimeModelRef} modelRef
7
+ * @param {Object} [options]
8
+ * @returns {Promise<RuntimeBridge>}
9
+ */
10
+ export function resolveRuntimeBridge(modelRef: import("../types.js").RuntimeModelRef, options?: any): Promise<RuntimeBridge>;
11
+ /**
12
+ * `RuntimeModelRef` is referenced inline (not aliased with a top-level
13
+ * `@typedef`) so this barrel does not re-export a second `RuntimeModelRef`
14
+ * type alongside model-refs.js's — that duplicate `export *` re-export is a
15
+ * TS2308 ambiguity. The canonical export stays in model-refs.js/types.js.
16
+ */
17
+ export type RuntimeBridge = import("../types.js").RuntimeBridge;
18
+ /**
19
+ * `RuntimeModelRef` is referenced inline (not aliased with a top-level
20
+ * `@typedef`) so this barrel does not re-export a second `RuntimeModelRef`
21
+ * type alongside model-refs.js's — that duplicate `export *` re-export is a
22
+ * TS2308 ambiguity. The canonical export stays in model-refs.js/types.js.
23
+ */
24
+ export type RuntimeBridgeDescriptor = import("../types.js").RuntimeBridgeDescriptor;
25
+ /**
26
+ * `RuntimeModelRef` is referenced inline (not aliased with a top-level
27
+ * `@typedef`) so this barrel does not re-export a second `RuntimeModelRef`
28
+ * type alongside model-refs.js's — that duplicate `export *` re-export is a
29
+ * TS2308 ambiguity. The canonical export stays in model-refs.js/types.js.
30
+ */
31
+ export type RuntimeBridgeId = import("../types.js").RuntimeBridgeId;
32
+ export type BridgeSpec = {
33
+ id: RuntimeBridgeId;
34
+ supports: (ref: (import("../types.js").RuntimeModelRef | undefined), options?: any) => boolean;
35
+ capabilities: (ref?: import("../types.js").RuntimeModelRef) => any;
36
+ load: (options?: any) => Promise<RuntimeBridge>;
37
+ };
38
+ export { RUNTIME_CAPABILITIES, runtimeCapabilities } from "./capabilities.js";
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @typedef {import('../types.js').RuntimeModelRef} RuntimeModelRef
3
+ * @typedef {import('../types.js').AgentRuntimeHostOptions} AgentRuntimeHostOptions
4
+ * @typedef {import('../types.js').AgentRuntimeInstance} AgentRuntimeInstance
5
+ * @typedef {import('../types.js').RuntimeRunOptions} RuntimeRunOptions
6
+ * @typedef {import('../types.js').RuntimeResult} RuntimeResult
7
+ */
8
+ /**
9
+ * @typedef {Object} RouterChainEntryInput
10
+ * A chain entry as accepted by createRouterRuntime: either the shorthand bare
11
+ * RuntimeModelRef, or the full `{model, executionMode?, requires?}` form.
12
+ * @property {RuntimeModelRef} model
13
+ * @property {string} [executionMode]
14
+ * @property {Object<string, *>} [requires]
15
+ */
16
+ /**
17
+ * @typedef {Object} RouterChainEntry
18
+ * @property {RuntimeModelRef} model
19
+ * @property {string|null} executionMode
20
+ * @property {Object<string, *>|null} requires
21
+ */
22
+ /**
23
+ * @param {Object} [options]
24
+ * @param {AgentRuntimeHostOptions} [options.host]
25
+ * @param {ReadonlyArray<RuntimeModelRef|RouterChainEntryInput>} [options.chain]
26
+ * @returns {AgentRuntimeInstance & {chain: () => Array<RouterChainEntry>}}
27
+ */
28
+ export function createRouterRuntime({ host, chain }?: {
29
+ host?: AgentRuntimeHostOptions;
30
+ chain?: ReadonlyArray<RuntimeModelRef | RouterChainEntryInput>;
31
+ }): AgentRuntimeInstance & {
32
+ chain: () => Array<RouterChainEntry>;
33
+ };
34
+ export type RuntimeModelRef = import("../types.js").RuntimeModelRef;
35
+ export type AgentRuntimeHostOptions = import("../types.js").AgentRuntimeHostOptions;
36
+ export type AgentRuntimeInstance = import("../types.js").AgentRuntimeInstance;
37
+ export type RuntimeRunOptions = import("../types.js").RuntimeRunOptions;
38
+ export type RuntimeResult = import("../types.js").RuntimeResult;
39
+ /**
40
+ * A chain entry as accepted by createRouterRuntime: either the shorthand bare
41
+ * RuntimeModelRef, or the full `{model, executionMode?, requires?}` form.
42
+ */
43
+ export type RouterChainEntryInput = {
44
+ model: RuntimeModelRef;
45
+ executionMode?: string;
46
+ requires?: {
47
+ [x: string]: any;
48
+ };
49
+ };
50
+ export type RouterChainEntry = {
51
+ model: RuntimeModelRef;
52
+ executionMode: string | null;
53
+ requires: {
54
+ [x: string]: any;
55
+ } | null;
56
+ };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @typedef {object} SessionRegistryLike
3
+ * @property {(id: string) => any} get
4
+ * @property {(id: string, value: any, opts?: {idleTimeoutMs?: number}) => void} set
5
+ * @property {(id: string) => boolean} delete
6
+ */
7
+ /**
8
+ * @typedef {{ok: true, entry: any} | {ok: false, reason: "busy" | "missing"}} ClaimResult
9
+ * @typedef {{ok: true, id: string, release: () => void, commit: (entry: any) => void} | {ok: false, entry: any}} ReserveResult
10
+ */
11
+ /**
12
+ * @typedef {object} SessionLiveness
13
+ * @property {(id: string) => ClaimResult} claim
14
+ * @property {(id: string) => any} adoptIfPresent
15
+ * @property {(id: string, seed: any, ttl: number|undefined) => ReserveResult} reserve
16
+ * @property {(id: string) => void} release
17
+ */
18
+ /**
19
+ * Wrap a session registry with the synchronous liveness primitives. The
20
+ * explicit return typedef pins the claim/reserve discriminated unions so
21
+ * callers narrow on `ok` (object-literal inference would otherwise widen `ok`
22
+ * to boolean and break narrowing).
23
+ * @param {SessionRegistryLike} registry
24
+ * @returns {SessionLiveness}
25
+ */
26
+ export function createSessionLiveness(registry: SessionRegistryLike): SessionLiveness;
27
+ export type SessionRegistryLike = {
28
+ get: (id: string) => any;
29
+ set: (id: string, value: any, opts?: {
30
+ idleTimeoutMs?: number;
31
+ }) => void;
32
+ delete: (id: string) => boolean;
33
+ };
34
+ export type ClaimResult = {
35
+ ok: true;
36
+ entry: any;
37
+ } | {
38
+ ok: false;
39
+ reason: "busy" | "missing";
40
+ };
41
+ export type ReserveResult = {
42
+ ok: true;
43
+ id: string;
44
+ release: () => void;
45
+ commit: (entry: any) => void;
46
+ } | {
47
+ ok: false;
48
+ entry: any;
49
+ };
50
+ export type SessionLiveness = {
51
+ claim: (id: string) => ClaimResult;
52
+ adoptIfPresent: (id: string) => any;
53
+ reserve: (id: string, seed: any, ttl: number | undefined) => ReserveResult;
54
+ release: (id: string) => void;
55
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @param {object} [options]
3
+ * @param {number} [options.idleTimeoutMs]
4
+ * @param {(value: any, reason: string) => (void | Promise<void>)} [options.onEvict]
5
+ * @param {() => number} [options.now]
6
+ * @param {(value: any) => boolean} [options.isBusy]
7
+ */
8
+ export function createSessionRegistry({ idleTimeoutMs, onEvict, now, isBusy }?: {
9
+ idleTimeoutMs?: number;
10
+ onEvict?: (value: any, reason: string) => (void | Promise<void>);
11
+ now?: () => number;
12
+ isBusy?: (value: any) => boolean;
13
+ }): {
14
+ get(id: any): any;
15
+ /**
16
+ * @param {any} id
17
+ * @param {any} value
18
+ * @param {{idleTimeoutMs?: number}} [options]
19
+ */
20
+ set(id: any, value: any, { idleTimeoutMs: entryTtl }?: {
21
+ idleTimeoutMs?: number;
22
+ }): void;
23
+ /**
24
+ * @param {any} id
25
+ * @param {{idleTimeoutMs?: number}} [options]
26
+ */
27
+ touch(id: any, { idleTimeoutMs: entryTtl }?: {
28
+ idleTimeoutMs?: number;
29
+ }): void;
30
+ has(id: any): boolean;
31
+ /** Remove without running onEvict — for callers that already cleaned up. */
32
+ delete(id: any): boolean;
33
+ dispose(id: any): Promise<boolean>;
34
+ disposeAll(): Promise<void>;
35
+ size(): number;
36
+ };
37
+ export function disposeProviderSession(providerSessionId: any): Promise<boolean>;
38
+ export function disposeAllProviderSessions(): Promise<void>;
@@ -0,0 +1,30 @@
1
+ export function normalizeCodexItemType(type: any): any;
2
+ export function normalizeCodexItemEvent(raw: any, context?: {}): {
3
+ type: string;
4
+ message: {
5
+ content: {
6
+ type: string;
7
+ tool_use_id: any;
8
+ content: any;
9
+ is_error: boolean;
10
+ }[];
11
+ };
12
+ } | {
13
+ type: string;
14
+ message: {
15
+ content: {
16
+ type: string;
17
+ id: any;
18
+ name: any;
19
+ input: any;
20
+ }[];
21
+ };
22
+ } | {
23
+ type: string;
24
+ message: {
25
+ content: {
26
+ type: string;
27
+ text: any;
28
+ }[];
29
+ };
30
+ };
@@ -0,0 +1,41 @@
1
+ export function toolUseEvent(part: any): {
2
+ type: string;
3
+ message: {
4
+ content: {
5
+ type: string;
6
+ id: any;
7
+ name: any;
8
+ input: any;
9
+ }[];
10
+ };
11
+ };
12
+ export function toolResultEvent(part: any): {
13
+ type: string;
14
+ message: {
15
+ content: {
16
+ type: string;
17
+ tool_use_id: any;
18
+ content: any;
19
+ is_error: boolean;
20
+ }[];
21
+ };
22
+ };
23
+ export function thinkingEvent(part: any): {
24
+ type: string;
25
+ message: {
26
+ content: {
27
+ type: string;
28
+ text: any;
29
+ }[];
30
+ };
31
+ };
32
+ export function assistantTextEvent(text: any): {
33
+ type: string;
34
+ message: {
35
+ content: {
36
+ type: string;
37
+ text: any;
38
+ }[];
39
+ };
40
+ };
41
+ export function toolPartSettled(part: any): boolean;