@openrouter/agent 0.8.0 → 0.10.0

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 (193) hide show
  1. package/README.md +732 -7
  2. package/THIRD_PARTY_NOTICES.md +25 -0
  3. package/esm/index.d.ts +20 -5
  4. package/esm/index.d.ts.map +1 -1
  5. package/esm/index.js +10 -3
  6. package/esm/index.js.map +1 -1
  7. package/esm/inner-loop/call-model.d.ts.map +1 -1
  8. package/esm/inner-loop/call-model.js +63 -46
  9. package/esm/inner-loop/call-model.js.map +1 -1
  10. package/esm/inner-loop/resume-tool-results.d.ts +128 -0
  11. package/esm/inner-loop/resume-tool-results.d.ts.map +1 -0
  12. package/esm/inner-loop/resume-tool-results.js +244 -0
  13. package/esm/inner-loop/resume-tool-results.js.map +1 -0
  14. package/esm/lib/agent-tool.d.ts +92 -0
  15. package/esm/lib/agent-tool.d.ts.map +1 -0
  16. package/esm/lib/agent-tool.js +211 -0
  17. package/esm/lib/agent-tool.js.map +1 -0
  18. package/esm/lib/async-params.d.ts +96 -0
  19. package/esm/lib/async-params.d.ts.map +1 -1
  20. package/esm/lib/async-params.js +30 -1
  21. package/esm/lib/async-params.js.map +1 -1
  22. package/esm/lib/async-tool-registry.d.ts +134 -0
  23. package/esm/lib/async-tool-registry.d.ts.map +1 -0
  24. package/esm/lib/async-tool-registry.js +352 -0
  25. package/esm/lib/async-tool-registry.js.map +1 -0
  26. package/esm/lib/async-tools.d.ts +23 -0
  27. package/esm/lib/async-tools.d.ts.map +1 -0
  28. package/esm/lib/async-tools.js +19 -0
  29. package/esm/lib/async-tools.js.map +1 -0
  30. package/esm/lib/conversation-state.d.ts +1 -0
  31. package/esm/lib/conversation-state.d.ts.map +1 -1
  32. package/esm/lib/conversation-state.js +8 -0
  33. package/esm/lib/conversation-state.js.map +1 -1
  34. package/esm/lib/doom-loop.d.ts +533 -0
  35. package/esm/lib/doom-loop.d.ts.map +1 -0
  36. package/esm/lib/doom-loop.js +1221 -0
  37. package/esm/lib/doom-loop.js.map +1 -0
  38. package/esm/lib/hooks-schemas.d.ts +33 -0
  39. package/esm/lib/hooks-schemas.d.ts.map +1 -1
  40. package/esm/lib/hooks-schemas.js +54 -0
  41. package/esm/lib/hooks-schemas.js.map +1 -1
  42. package/esm/lib/hooks-types.d.ts +6 -2
  43. package/esm/lib/hooks-types.d.ts.map +1 -1
  44. package/esm/lib/hooks-types.js.map +1 -1
  45. package/esm/lib/model-result.d.ts +648 -12
  46. package/esm/lib/model-result.d.ts.map +1 -1
  47. package/esm/lib/model-result.js +2784 -164
  48. package/esm/lib/model-result.js.map +1 -1
  49. package/esm/lib/next-turn-params.d.ts.map +1 -1
  50. package/esm/lib/next-turn-params.js +3 -1
  51. package/esm/lib/next-turn-params.js.map +1 -1
  52. package/esm/lib/next-turn-params.test.js +72 -0
  53. package/esm/lib/next-turn-params.test.js.map +1 -1
  54. package/esm/lib/reusable-stream.d.ts +9 -0
  55. package/esm/lib/reusable-stream.d.ts.map +1 -1
  56. package/esm/lib/reusable-stream.js +17 -0
  57. package/esm/lib/reusable-stream.js.map +1 -1
  58. package/esm/lib/stream-transformers.d.ts +21 -1
  59. package/esm/lib/stream-transformers.d.ts.map +1 -1
  60. package/esm/lib/stream-transformers.js +45 -0
  61. package/esm/lib/stream-transformers.js.map +1 -1
  62. package/esm/lib/tool-check.d.ts +76 -0
  63. package/esm/lib/tool-check.d.ts.map +1 -0
  64. package/esm/lib/tool-check.js +241 -0
  65. package/esm/lib/tool-check.js.map +1 -0
  66. package/esm/lib/tool-concurrency.d.ts +42 -0
  67. package/esm/lib/tool-concurrency.d.ts.map +1 -0
  68. package/esm/lib/tool-concurrency.js +80 -0
  69. package/esm/lib/tool-concurrency.js.map +1 -0
  70. package/esm/lib/tool-context.d.ts +45 -1
  71. package/esm/lib/tool-context.d.ts.map +1 -1
  72. package/esm/lib/tool-context.js +60 -1
  73. package/esm/lib/tool-context.js.map +1 -1
  74. package/esm/lib/tool-executor.d.ts +52 -9
  75. package/esm/lib/tool-executor.d.ts.map +1 -1
  76. package/esm/lib/tool-executor.js +253 -21
  77. package/esm/lib/tool-executor.js.map +1 -1
  78. package/esm/lib/tool-orchestrator.d.ts.map +1 -1
  79. package/esm/lib/tool-orchestrator.js +87 -50
  80. package/esm/lib/tool-orchestrator.js.map +1 -1
  81. package/esm/lib/tool-set-types.d.ts +298 -0
  82. package/esm/lib/tool-set-types.d.ts.map +1 -0
  83. package/esm/lib/tool-set-types.js +2 -0
  84. package/esm/lib/tool-set-types.js.map +1 -0
  85. package/esm/lib/tool-set.d.ts +157 -0
  86. package/esm/lib/tool-set.d.ts.map +1 -0
  87. package/esm/lib/tool-set.js +473 -0
  88. package/esm/lib/tool-set.js.map +1 -0
  89. package/esm/lib/tool-task.d.ts +157 -0
  90. package/esm/lib/tool-task.d.ts.map +1 -0
  91. package/esm/lib/tool-task.js +206 -0
  92. package/esm/lib/tool-task.js.map +1 -0
  93. package/esm/lib/tool-types.d.ts +667 -38
  94. package/esm/lib/tool-types.d.ts.map +1 -1
  95. package/esm/lib/tool-types.js +59 -10
  96. package/esm/lib/tool-types.js.map +1 -1
  97. package/esm/lib/tool.d.ts +227 -19
  98. package/esm/lib/tool.d.ts.map +1 -1
  99. package/esm/lib/tool.js +206 -6
  100. package/esm/lib/tool.js.map +1 -1
  101. package/esm/mcp/auth/auth-resolver.d.ts +14 -0
  102. package/esm/mcp/auth/auth-resolver.d.ts.map +1 -0
  103. package/esm/mcp/auth/auth-resolver.js +27 -0
  104. package/esm/mcp/auth/auth-resolver.js.map +1 -0
  105. package/esm/mcp/auth/auth-types.d.ts +33 -0
  106. package/esm/mcp/auth/auth-types.d.ts.map +1 -0
  107. package/esm/mcp/auth/auth-types.js +4 -0
  108. package/esm/mcp/auth/auth-types.js.map +1 -0
  109. package/esm/mcp/build-tools.d.ts +29 -0
  110. package/esm/mcp/build-tools.d.ts.map +1 -0
  111. package/esm/mcp/build-tools.js +80 -0
  112. package/esm/mcp/build-tools.js.map +1 -0
  113. package/esm/mcp/cache/cache-store.d.ts +24 -0
  114. package/esm/mcp/cache/cache-store.d.ts.map +1 -0
  115. package/esm/mcp/cache/cache-store.js +20 -0
  116. package/esm/mcp/cache/cache-store.js.map +1 -0
  117. package/esm/mcp/cache/cache-types.d.ts +71 -0
  118. package/esm/mcp/cache/cache-types.d.ts.map +1 -0
  119. package/esm/mcp/cache/cache-types.js +49 -0
  120. package/esm/mcp/cache/cache-types.js.map +1 -0
  121. package/esm/mcp/cache/serialize.d.ts +25 -0
  122. package/esm/mcp/cache/serialize.d.ts.map +1 -0
  123. package/esm/mcp/cache/serialize.js +96 -0
  124. package/esm/mcp/cache/serialize.js.map +1 -0
  125. package/esm/mcp/close-quietly.d.ts +24 -0
  126. package/esm/mcp/close-quietly.d.ts.map +1 -0
  127. package/esm/mcp/close-quietly.js +30 -0
  128. package/esm/mcp/close-quietly.js.map +1 -0
  129. package/esm/mcp/create-mcp-tools.d.ts +13 -0
  130. package/esm/mcp/create-mcp-tools.d.ts.map +1 -0
  131. package/esm/mcp/create-mcp-tools.js +87 -0
  132. package/esm/mcp/create-mcp-tools.js.map +1 -0
  133. package/esm/mcp/elicitation.d.ts +11 -0
  134. package/esm/mcp/elicitation.d.ts.map +1 -0
  135. package/esm/mcp/elicitation.js +51 -0
  136. package/esm/mcp/elicitation.js.map +1 -0
  137. package/esm/mcp/errors.d.ts +91 -0
  138. package/esm/mcp/errors.d.ts.map +1 -0
  139. package/esm/mcp/errors.js +91 -0
  140. package/esm/mcp/errors.js.map +1 -0
  141. package/esm/mcp/handle.d.ts +66 -0
  142. package/esm/mcp/handle.d.ts.map +1 -0
  143. package/esm/mcp/handle.js +323 -0
  144. package/esm/mcp/handle.js.map +1 -0
  145. package/esm/mcp/index.d.ts +13 -0
  146. package/esm/mcp/index.d.ts.map +1 -0
  147. package/esm/mcp/index.js +11 -0
  148. package/esm/mcp/index.js.map +1 -0
  149. package/esm/mcp/mcp-connection.d.ts +150 -0
  150. package/esm/mcp/mcp-connection.d.ts.map +1 -0
  151. package/esm/mcp/mcp-connection.js +478 -0
  152. package/esm/mcp/mcp-connection.js.map +1 -0
  153. package/esm/mcp/mcp-sdk.d.ts +10 -0
  154. package/esm/mcp/mcp-sdk.d.ts.map +1 -0
  155. package/esm/mcp/mcp-sdk.js +37 -0
  156. package/esm/mcp/mcp-sdk.js.map +1 -0
  157. package/esm/mcp/rehydrate.d.ts +76 -0
  158. package/esm/mcp/rehydrate.d.ts.map +1 -0
  159. package/esm/mcp/rehydrate.js +505 -0
  160. package/esm/mcp/rehydrate.js.map +1 -0
  161. package/esm/mcp/resource-tools.d.ts +17 -0
  162. package/esm/mcp/resource-tools.d.ts.map +1 -0
  163. package/esm/mcp/resource-tools.js +155 -0
  164. package/esm/mcp/resource-tools.js.map +1 -0
  165. package/esm/mcp/result-mapper.d.ts +19 -0
  166. package/esm/mcp/result-mapper.d.ts.map +1 -0
  167. package/esm/mcp/result-mapper.js +40 -0
  168. package/esm/mcp/result-mapper.js.map +1 -0
  169. package/esm/mcp/schema/json-schema-guards.d.ts +14 -0
  170. package/esm/mcp/schema/json-schema-guards.d.ts.map +1 -0
  171. package/esm/mcp/schema/json-schema-guards.js +19 -0
  172. package/esm/mcp/schema/json-schema-guards.js.map +1 -0
  173. package/esm/mcp/schema/json-schema-to-zod.d.ts +20 -0
  174. package/esm/mcp/schema/json-schema-to-zod.d.ts.map +1 -0
  175. package/esm/mcp/schema/json-schema-to-zod.js +72 -0
  176. package/esm/mcp/schema/json-schema-to-zod.js.map +1 -0
  177. package/esm/mcp/tool-wrapper.d.ts +41 -0
  178. package/esm/mcp/tool-wrapper.d.ts.map +1 -0
  179. package/esm/mcp/tool-wrapper.js +131 -0
  180. package/esm/mcp/tool-wrapper.js.map +1 -0
  181. package/esm/mcp/transport-types.d.ts +45 -0
  182. package/esm/mcp/transport-types.d.ts.map +1 -0
  183. package/esm/mcp/transport-types.js +2 -0
  184. package/esm/mcp/transport-types.js.map +1 -0
  185. package/esm/mcp/types.d.ts +119 -0
  186. package/esm/mcp/types.d.ts.map +1 -0
  187. package/esm/mcp/types.js +2 -0
  188. package/esm/mcp/types.js.map +1 -0
  189. package/esm/mcp/version.d.ts +3 -0
  190. package/esm/mcp/version.d.ts.map +1 -0
  191. package/esm/mcp/version.js +5 -0
  192. package/esm/mcp/version.js.map +1 -0
  193. package/package.json +70 -5
@@ -1,11 +1,16 @@
1
1
  import type * as models from '@openrouter/sdk/models';
2
2
  import type { OpenResponsesResult } from '@openrouter/sdk/models';
3
+ import type { DoomLoopOption } from './doom-loop.js';
3
4
  import type { HooksManager } from './hooks-manager.js';
4
5
  import type { InlineHookConfig } from './hooks-types.js';
5
6
  import type { Item } from './item-types.js';
6
7
  import type { ContextInput } from './tool-context.js';
7
8
  import type { ParsedToolCall, StateAccessor, StopWhen, Tool, ToolContextMapWithShared, TurnContext } from './tool-types.js';
8
9
  export type { Tool } from './tool-types.js';
10
+ /** Identifies objects produced by `@openrouter/agent/tool-set`. */
11
+ export declare const TOOL_SET_SNAPSHOT: unique symbol;
12
+ /** Remove tool-set metadata only from marked snapshots or their spreads. */
13
+ export declare function stripToolSetSnapshotMetadata(input: Record<PropertyKey, unknown>): void;
9
14
  /**
10
15
  * A field can be either a value of type T or a function that computes T
11
16
  */
@@ -18,6 +23,16 @@ type BaseCallModelInput<TTools extends readonly Tool[] = readonly Tool[], TShare
18
23
  } & {
19
24
  input: FieldOrAsyncFunction<Item[]> | string;
20
25
  tools?: TTools;
26
+ /**
27
+ * Optional filter restricting which tools are exposed to the model for this
28
+ * call. Tool names not in this list are removed before the request is sent
29
+ * and are also not callable by the model. Pairs with
30
+ * `@openrouter/agent/tool-set`'s `.inferTools()` output — spreading its
31
+ * `{ tools, activeTools }` (or a whole marked snapshot from `.inferTools()` /
32
+ * `.resolve()` / `.resolveSituation()`) into this object is safe: `callModel`
33
+ * strips metadata introduced by that snapshot before sending the request.
34
+ */
35
+ activeTools?: readonly string[];
21
36
  stopWhen?: StopWhen<TTools>;
22
37
  /** Typed context data passed to tools via contextSchema. Includes optional `shared` key. */
23
38
  context?: ContextInput<ToolContextMapWithShared<TTools, TShared>>;
@@ -71,6 +86,87 @@ type BaseCallModelInput<TTools extends readonly Tool[] = readonly Tool[], TShare
71
86
  strictFinalResponse?: boolean;
72
87
  /** Hook system for lifecycle events. Accepts inline config or a HooksManager instance. */
73
88
  hooks?: InlineHookConfig | HooksManager;
89
+ /**
90
+ * Doom-loop detection: catch runs that repeat the same tool call with
91
+ * identical arguments (including repeated empty or unparseable calls) or
92
+ * emit the same text over and over, and respond with a graduated ladder
93
+ * (observe → steer → block → stop; defaults observe@2, block@3, stop@6
94
+ * consecutive repetitions). `true` enables recommended defaults; an
95
+ * object tunes thresholds and text detection. Off by default.
96
+ *
97
+ * Tools declare precise call identity via `loopKey`: a computed function
98
+ * (return the search query, `({ command, cwd }) => ({ command, cwd })`,
99
+ * ...), a field-name array (`['command', 'cwd']` — serializable, used by
100
+ * MCP tool caches), or `false` to exempt a tool (legitimate polling);
101
+ * without one the full arguments object is the identity. Detection is
102
+ * deterministic: the same transcript always produces the same verdicts.
103
+ */
104
+ doomLoop?: DoomLoopOption;
105
+ /**
106
+ * Cancel the whole run. Aborting stops the tool-execution loop at the
107
+ * next turn boundary AND aborts the in-flight API request/stream, so a
108
+ * stalled provider fails fast instead of hanging until an outer test or
109
+ * caller timeout kills the process. The run's promises reject with the
110
+ * signal's abort reason.
111
+ *
112
+ * Composes with per-request `RequestOptions.timeoutMs` (the third
113
+ * `callModel` argument): when both are set, each request is bounded by
114
+ * whichever fires first. (Passing a raw `signal` through `RequestOptions`
115
+ * instead would silently disable the SDK's `timeoutMs` wiring.)
116
+ *
117
+ * Aborting also fires every in-flight tool's `ctx.signal` and aborts
118
+ * background tasks, so cooperative tool bodies stop working.
119
+ */
120
+ signal?: AbortSignal;
121
+ /**
122
+ * Default per-tool execution deadline in milliseconds; a tool-level
123
+ * `timeoutMs` overrides it. When the deadline elapses the round stops
124
+ * waiting — the model receives `{ error, code: 'tool_timeout' }`
125
+ * immediately and the tool's `ctx.signal` aborts. Bounds the round's
126
+ * WAIT, not the tool body: a body that ignores its signal keeps running
127
+ * detached and its result is discarded.
128
+ */
129
+ toolTimeoutMs?: number;
130
+ /**
131
+ * Concurrency limits for tool execution. A bare number is shorthand for
132
+ * `{ round: n }`.
133
+ * - `round`: max simultaneous tool executions within one tool round.
134
+ * Unbounded by default (matching previous behavior).
135
+ * - `background`: max simultaneous detached background-tool executions
136
+ * (`tool.background` work that outlived its grace window). Default 16.
137
+ * When full, work queues FIFO; queue wait counts against `timeoutMs`.
138
+ * Execution order may change under a cap; OUTPUT order never does
139
+ * (results stay in call order for prompt-cache stability).
140
+ */
141
+ toolConcurrency?: number | {
142
+ round?: number;
143
+ background?: number;
144
+ };
145
+ /**
146
+ * Behavior for async tools (`tool.background` / `tool.deferred`).
147
+ *
148
+ * `onRunEnd` decides what happens when the run would finish while
149
+ * background tasks are still in flight:
150
+ * - `'drain'` (default): wait up to `drainTimeoutMs` (default 30s),
151
+ * inject settled results, and grant up to `maxDrainTurns` (default 2)
152
+ * extra no-tool turns so the final answer incorporates them;
153
+ * - `'detach'`: return immediately — tasks keep running, results are
154
+ * dropped (persisted as `orphaned` when a StateAccessor exists);
155
+ * - `'cancel'`: abort in-flight tasks and finish.
156
+ */
157
+ asyncTools?: {
158
+ onRunEnd?: 'drain' | 'detach' | 'cancel';
159
+ drainTimeoutMs?: number;
160
+ maxDrainTurns?: number;
161
+ /**
162
+ * Whether the single universal `task` tool is registered so the model
163
+ * can check/steer/result/cancel running tasks by taskId. Default true
164
+ * when any long-running tool is present.
165
+ */
166
+ checkins?: boolean;
167
+ /** Max characters for the `transcript` check view. Default 20_000. */
168
+ maxTranscriptChars?: number;
169
+ };
74
170
  };
75
171
  /**
76
172
  * Approval params when state is provided (allows approve/reject)
@@ -1 +1 @@
1
- {"version":3,"file":"async-params.d.ts","sourceRoot":"","sources":["../../src/lib/async-params.ts"],"names":[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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAC7D,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAE1E;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG;IACvF,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,SAAS,SAAS,IAAI,EAAE,GAAG,SAAS,IAAI,EAAE,EAC1F,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,sBAAsB,CAAC,CAuEjC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKzD"}
@@ -1,3 +1,21 @@
1
+ /** Identifies objects produced by `@openrouter/agent/tool-set`. */
2
+ export const TOOL_SET_SNAPSHOT = Symbol.for('@openrouter/agent/tool-set/snapshot');
3
+ const TOOL_SET_SNAPSHOT_METADATA_KEYS = new Set([
4
+ 'enabled',
5
+ 'disabled',
6
+ 'statusByTool',
7
+ 'callModel',
8
+ ]);
9
+ /** Remove tool-set metadata only from marked snapshots or their spreads. */
10
+ export function stripToolSetSnapshotMetadata(input) {
11
+ if (input[TOOL_SET_SNAPSHOT] !== true) {
12
+ return;
13
+ }
14
+ for (const key of TOOL_SET_SNAPSHOT_METADATA_KEYS) {
15
+ delete input[key];
16
+ }
17
+ delete input[TOOL_SET_SNAPSHOT];
18
+ }
1
19
  /**
2
20
  * Type guard to check if a value is a parameter function
3
21
  * Parameter functions take TurnContext and return a value or promise
@@ -50,11 +68,22 @@ export async function resolveAsyncFunctions(input, context) {
50
68
  'allowFinalResponse', // Client-side: tunes the default toolChoice:'none' final turn when stopWhen breaks the loop
51
69
  'strictFinalResponse', // Client-side: restore throw on empty final after tool rounds
52
70
  'hooks', // Client-side hook system
71
+ 'doomLoop', // Client-side doom-loop detection config
72
+ 'signal', // Client-side run cancellation
73
+ 'toolTimeoutMs', // Client-side per-tool deadline default
74
+ 'toolConcurrency', // Client-side tool concurrency limits
75
+ 'asyncTools', // Client-side async tool (background/deferred) behavior
76
+ 'activeTools', // Applied client-side to filter tools before conversion
53
77
  ]);
78
+ const request = {
79
+ ...input,
80
+ };
81
+ stripToolSetSnapshotMetadata(request);
54
82
  // Iterate over all keys in the input
55
- for (const [key, value] of Object.entries(input)) {
83
+ for (const [key, value] of Object.entries(request)) {
56
84
  // Skip client-only fields - they're handled separately and shouldn't be sent to the API
57
85
  // Note: tools are already in API format at this point (converted in callModel()), so we include them
86
+ //
58
87
  if (clientOnlyFields.has(key)) {
59
88
  continue;
60
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"async-params.js","sourceRoot":"","sources":["../../src/lib/async-params.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,SAAS,oBAAoB,CAC3B,OAKC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAExC,OAAO,GAAoC,CAAC;AAC9C,CAAC;AAqID;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAA6B,EAC7B,OAAoB;IAEpB,kCAAkC;IAClC,MAAM,eAAe,GAKjB,EAAE,CAAC;IAEP,+DAA+D;IAC/D,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;QAC/B,UAAU,EAAE,oCAAoC;QAChD,OAAO,EAAE,+BAA+B;QACxC,iBAAiB,EAAE,sCAAsC;QACzD,kBAAkB,EAAE,iCAAi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,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,CACH,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACN,4BAA4B;YAC5B,eAAe,CAAC,IAAI,CAAC;gBACnB,GAAG;gBACH,KAAK;aACG,CAAC,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,eAAe,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,134 @@
1
+ import type { TaskLogEntry } from './tool-task.js';
2
+ import { ToolTask } from './tool-task.js';
3
+ import type { PendingAsyncTool } from './tool-types.js';
4
+ /**
5
+ * Outcome of a settled async tool task, harvested by the engine at turn
6
+ * boundaries (`flushAsyncToolDeliveries`) or during end-of-run drain.
7
+ */
8
+ export interface SettledToolTask {
9
+ callId: string;
10
+ taskId: string;
11
+ name: string;
12
+ status: 'completed' | 'failed' | 'cancelled' | 'timed_out';
13
+ /** Present when status is 'completed'. */
14
+ result?: unknown;
15
+ /** Present otherwise. */
16
+ error?: string;
17
+ /** The call's arguments, when tracked — feeds PostToolUse at settle. */
18
+ input?: Record<string, unknown>;
19
+ /** Wall-clock ms from task start to settlement — feeds PostToolUse. */
20
+ durationMs: number;
21
+ }
22
+ /**
23
+ * Per-run registry of async tool tasks (background, deferred, agent).
24
+ *
25
+ * Owns the in-process half of async tool support:
26
+ * - background/agent tasks: tracks the in-flight work + ToolTask (logs,
27
+ * inbox, transcript source), queues settled outcomes for turn-boundary
28
+ * harvesting, supports drain / cancel / abort-all at run end;
29
+ * - deferred tasks: tracks identity only (the work lives outside the
30
+ * process); the durable copy is mirrored to
31
+ * `ConversationState.pendingAsyncTools` by the engine.
32
+ *
33
+ * The registry knows nothing about the tool loop or concurrency pools — the
34
+ * engine (`ModelResult`) owns semaphores and decides when to harvest and how
35
+ * to deliver. Settlement is first-writer-wins: a task settles exactly once
36
+ * (cancel racing completion is safe), and settled tasks drop their
37
+ * controller references so they cannot retain the run graph.
38
+ */
39
+ export declare class AsyncToolRegistry {
40
+ private readonly tasks;
41
+ /** Settled outcomes not yet harvested by the engine. */
42
+ private settledQueue;
43
+ private taskCounter;
44
+ /** Resolvers waiting on "any task settled" (drain support). */
45
+ private settleWaiters;
46
+ /** Generate a task id for background/agent tasks (deferred bring their own). */
47
+ generateTaskId(): string;
48
+ /**
49
+ * Register a task so it is visible to steering / cancel / snapshots.
50
+ * Used for background tasks DURING their grace window — the work is in
51
+ * flight but not yet committed to async delivery. `untrack` removes it
52
+ * again when the work settles in-window (the call behaved
53
+ * synchronously; no async machinery should remain visible).
54
+ */
55
+ register(task: ToolTask): void;
56
+ /**
57
+ * Remove a task registered via `register` whose work settled inside the
58
+ * grace window, along with any settlement queued for it in the meantime
59
+ * (e.g. a cancelTask racing the in-window completion) — the call is
60
+ * yielding a synchronous output, so a later envelope for the same callId
61
+ * would be a double delivery.
62
+ */
63
+ untrack(callId: string): void;
64
+ /**
65
+ * Track an already-started background/agent task. `work` is the tool's
66
+ * in-flight run promise (output-validated). When `timeoutMs` is set the
67
+ * task is raced against it, so a body that ignores its abort signal still
68
+ * settles as `timed_out` instead of hanging the drain. The deadline is
69
+ * anchored at `task.startedAt` (the work started before tracking — a
70
+ * grace window may already have elapsed), so `timeoutMs` bounds the
71
+ * task's TOTAL runtime, matching the documented contract.
72
+ */
73
+ trackBackground(task: ToolTask, work: Promise<unknown>, options?: {
74
+ timeoutMs?: number;
75
+ }): void;
76
+ /** Track a deferred task (identity only; work lives outside the process). */
77
+ trackDeferred(entry: {
78
+ callId: string;
79
+ taskId: string;
80
+ name: string;
81
+ expiresAt?: number;
82
+ pollAfterMs?: number;
83
+ }): ToolTask;
84
+ private settle;
85
+ /** Harvest (and clear) settled outcomes queued since the last call. */
86
+ takeSettled(): SettledToolTask[];
87
+ /** True when any background/agent task is still in flight. */
88
+ hasInFlight(): boolean;
89
+ /** True when any settled outcome awaits harvesting. */
90
+ hasUnharvestedSettled(): boolean;
91
+ /** True when any task (any mode) has been tracked this run. */
92
+ hasTasks(): boolean;
93
+ /** Find the live task for a task id. */
94
+ getTask(taskId: string): ToolTask | undefined;
95
+ /** Find the live task for a call id. */
96
+ findByCallId(callId: string): ToolTask | undefined;
97
+ /** All live tasks. */
98
+ listTasks(): ToolTask[];
99
+ /** Append a log entry to a task by call id (engine log sink). */
100
+ appendLog(callId: string, data: unknown, kind?: TaskLogEntry['kind']): void;
101
+ /** Mark every still-working background/agent task as orphaned (detach mode). */
102
+ markWorkingAsOrphaned(): PendingAsyncTool[];
103
+ /** Snapshot of every tracked task (for `getAsyncTasks()` / persistence). */
104
+ snapshot(): PendingAsyncTool[];
105
+ /**
106
+ * Send a steering message to a working task's run body. Deferred tasks
107
+ * are owned by an external system — steering them is the caller's job.
108
+ * @returns true when a working in-process task received the message.
109
+ */
110
+ sendToTask(taskId: string, message: unknown): boolean;
111
+ /**
112
+ * Cancel one task by task id. Settles it as 'cancelled' immediately
113
+ * (first-writer-wins makes the racing body's own settlement a no-op) and
114
+ * aborts the controller so cooperative bodies stop working.
115
+ *
116
+ * Deferred tasks: cancellation is LOCAL-ONLY — the conversation records
117
+ * the cancel, but the external system is not notified (mirror of the
118
+ * sendToTask contract; tell the external system yourself, or use the
119
+ * tool's `.cancel()` method which persists the terminal status for
120
+ * cross-process callers).
121
+ * @returns true when a working task was found and cancelled.
122
+ */
123
+ cancelTask(taskId: string, reason?: string): boolean;
124
+ /** Abort every in-flight background/agent task (run abort / onRunEnd: 'cancel'). */
125
+ abortAll(reason?: string): void;
126
+ /**
127
+ * Wait until every in-flight task settles or `timeoutMs` elapses,
128
+ * whichever comes first. Returns true when everything settled.
129
+ */
130
+ drain(timeoutMs: number): Promise<boolean>;
131
+ /** Resolve true on the next settle event, or false after `timeoutMs`. */
132
+ private waitForSettle;
133
+ }
134
+ //# sourceMappingURL=async-tool-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-tool-registry.d.ts","sourceRoot":"","sources":["../../src/lib/async-tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;IAC3D,0CAA0C;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IACrD,wDAAwD;IACxD,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,WAAW,CAAK;IACxB,+DAA+D;IAC/D,OAAO,CAAC,aAAa,CAAyB;IAE9C,gFAAgF;IAChF,cAAc,IAAI,MAAM;IAQxB;;;;;;OAMG;IACH,QAAQ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