@strands-agents/sdk 1.14.0 → 1.16.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 (155) hide show
  1. package/dist/src/agent/agent-delegation.d.ts +9 -30
  2. package/dist/src/agent/agent-delegation.d.ts.map +1 -1
  3. package/dist/src/agent/agent-delegation.js +26 -98
  4. package/dist/src/agent/agent-delegation.js.map +1 -1
  5. package/dist/src/agent/agent.d.ts +26 -8
  6. package/dist/src/agent/agent.d.ts.map +1 -1
  7. package/dist/src/agent/agent.js +132 -53
  8. package/dist/src/agent/agent.js.map +1 -1
  9. package/dist/src/agent/continuation.d.ts +41 -0
  10. package/dist/src/agent/continuation.d.ts.map +1 -1
  11. package/dist/src/agent/continuation.js +41 -0
  12. package/dist/src/agent/continuation.js.map +1 -1
  13. package/dist/src/background-tasks/background-tasks.d.ts +41 -0
  14. package/dist/src/background-tasks/background-tasks.d.ts.map +1 -0
  15. package/dist/src/background-tasks/background-tasks.js +402 -0
  16. package/dist/src/background-tasks/background-tasks.js.map +1 -0
  17. package/dist/src/background-tasks/errors.d.ts +15 -0
  18. package/dist/src/background-tasks/errors.d.ts.map +1 -0
  19. package/dist/src/background-tasks/errors.js +21 -0
  20. package/dist/src/background-tasks/errors.js.map +1 -0
  21. package/dist/src/background-tasks/in-process/engine.d.ts +95 -0
  22. package/dist/src/background-tasks/in-process/engine.d.ts.map +1 -0
  23. package/dist/src/background-tasks/in-process/engine.js +306 -0
  24. package/dist/src/background-tasks/in-process/engine.js.map +1 -0
  25. package/dist/src/background-tasks/in-process/manager.d.ts +41 -0
  26. package/dist/src/background-tasks/in-process/manager.d.ts.map +1 -0
  27. package/dist/src/background-tasks/in-process/manager.js +214 -0
  28. package/dist/src/background-tasks/in-process/manager.js.map +1 -0
  29. package/dist/src/background-tasks/in-process/types.d.ts +71 -0
  30. package/dist/src/background-tasks/in-process/types.d.ts.map +1 -0
  31. package/dist/src/background-tasks/in-process/types.js +2 -0
  32. package/dist/src/background-tasks/in-process/types.js.map +1 -0
  33. package/dist/src/background-tasks/manager.d.ts +59 -0
  34. package/dist/src/background-tasks/manager.d.ts.map +1 -0
  35. package/dist/src/background-tasks/manager.js +2 -0
  36. package/dist/src/background-tasks/manager.js.map +1 -0
  37. package/dist/src/background-tasks/timer.d.ts +3 -0
  38. package/dist/src/background-tasks/timer.d.ts.map +1 -0
  39. package/dist/src/background-tasks/timer.js +11 -0
  40. package/dist/src/background-tasks/timer.js.map +1 -0
  41. package/dist/src/background-tasks/types.d.ts +60 -0
  42. package/dist/src/background-tasks/types.d.ts.map +1 -0
  43. package/dist/src/background-tasks/types.js +11 -0
  44. package/dist/src/background-tasks/types.js.map +1 -0
  45. package/dist/src/hooks/events.d.ts +6 -5
  46. package/dist/src/hooks/events.d.ts.map +1 -1
  47. package/dist/src/hooks/events.js +5 -4
  48. package/dist/src/hooks/events.js.map +1 -1
  49. package/dist/src/hooks/types.d.ts +1 -0
  50. package/dist/src/hooks/types.d.ts.map +1 -1
  51. package/dist/src/hooks/types.js +1 -0
  52. package/dist/src/hooks/types.js.map +1 -1
  53. package/dist/src/index.d.ts +3 -0
  54. package/dist/src/index.d.ts.map +1 -1
  55. package/dist/src/index.js +2 -0
  56. package/dist/src/index.js.map +1 -1
  57. package/dist/src/models/bedrock.d.ts +11 -0
  58. package/dist/src/models/bedrock.d.ts.map +1 -1
  59. package/dist/src/models/bedrock.js +61 -10
  60. package/dist/src/models/bedrock.js.map +1 -1
  61. package/dist/src/models/google/adapters.d.ts.map +1 -1
  62. package/dist/src/models/google/adapters.js +18 -4
  63. package/dist/src/models/google/adapters.js.map +1 -1
  64. package/dist/src/models/google/model.d.ts.map +1 -1
  65. package/dist/src/models/google/model.js +9 -7
  66. package/dist/src/models/google/model.js.map +1 -1
  67. package/dist/src/models/google/types.d.ts +2 -0
  68. package/dist/src/models/google/types.d.ts.map +1 -1
  69. package/dist/src/models/model.d.ts +4 -0
  70. package/dist/src/models/model.d.ts.map +1 -1
  71. package/dist/src/models/model.js.map +1 -1
  72. package/dist/src/models/openai/cache.d.ts +31 -0
  73. package/dist/src/models/openai/cache.d.ts.map +1 -0
  74. package/dist/src/models/openai/cache.js +56 -0
  75. package/dist/src/models/openai/cache.js.map +1 -0
  76. package/dist/src/models/openai/chat-adapter.d.ts.map +1 -1
  77. package/dist/src/models/openai/chat-adapter.js +2 -0
  78. package/dist/src/models/openai/chat-adapter.js.map +1 -1
  79. package/dist/src/models/openai/model.d.ts.map +1 -1
  80. package/dist/src/models/openai/model.js +9 -3
  81. package/dist/src/models/openai/model.js.map +1 -1
  82. package/dist/src/models/openai/responses-adapter.d.ts.map +1 -1
  83. package/dist/src/models/openai/responses-adapter.js +3 -1
  84. package/dist/src/models/openai/responses-adapter.js.map +1 -1
  85. package/dist/src/models/openai/types.d.ts +5 -1
  86. package/dist/src/models/openai/types.d.ts.map +1 -1
  87. package/dist/src/models/routing/fallback-strategy.d.ts +13 -0
  88. package/dist/src/models/routing/fallback-strategy.d.ts.map +1 -0
  89. package/dist/src/models/routing/fallback-strategy.js +33 -0
  90. package/dist/src/models/routing/fallback-strategy.js.map +1 -0
  91. package/dist/src/models/routing/index.d.ts +11 -0
  92. package/dist/src/models/routing/index.d.ts.map +1 -0
  93. package/dist/src/models/routing/index.js +9 -0
  94. package/dist/src/models/routing/index.js.map +1 -0
  95. package/dist/src/models/routing/router.d.ts +161 -0
  96. package/dist/src/models/routing/router.d.ts.map +1 -0
  97. package/dist/src/models/routing/router.js +474 -0
  98. package/dist/src/models/routing/router.js.map +1 -0
  99. package/dist/src/models/routing/strategy.d.ts +53 -0
  100. package/dist/src/models/routing/strategy.d.ts.map +1 -0
  101. package/dist/src/models/routing/strategy.js +2 -0
  102. package/dist/src/models/routing/strategy.js.map +1 -0
  103. package/dist/src/models/streaming.d.ts +12 -0
  104. package/dist/src/models/streaming.d.ts.map +1 -1
  105. package/dist/src/models/streaming.js +17 -0
  106. package/dist/src/models/streaming.js.map +1 -1
  107. package/dist/src/retry/default-model-retry-strategy.d.ts +3 -8
  108. package/dist/src/retry/default-model-retry-strategy.d.ts.map +1 -1
  109. package/dist/src/retry/default-model-retry-strategy.js +3 -8
  110. package/dist/src/retry/default-model-retry-strategy.js.map +1 -1
  111. package/dist/src/retry/model-retry-strategy.d.ts +6 -9
  112. package/dist/src/retry/model-retry-strategy.d.ts.map +1 -1
  113. package/dist/src/retry/model-retry-strategy.js +8 -12
  114. package/dist/src/retry/model-retry-strategy.js.map +1 -1
  115. package/dist/src/session/session-manager.d.ts +4 -0
  116. package/dist/src/session/session-manager.d.ts.map +1 -1
  117. package/dist/src/session/session-manager.js +6 -0
  118. package/dist/src/session/session-manager.js.map +1 -1
  119. package/dist/src/storage/local-file-storage.d.ts +4 -6
  120. package/dist/src/storage/local-file-storage.d.ts.map +1 -1
  121. package/dist/src/storage/local-file-storage.js +12 -10
  122. package/dist/src/storage/local-file-storage.js.map +1 -1
  123. package/dist/src/storage/search/keyword.d.ts +1 -0
  124. package/dist/src/storage/search/keyword.d.ts.map +1 -1
  125. package/dist/src/storage/search/keyword.js +124 -0
  126. package/dist/src/storage/search/keyword.js.map +1 -1
  127. package/dist/src/storage/search/qmd.d.ts +66 -0
  128. package/dist/src/storage/search/qmd.d.ts.map +1 -0
  129. package/dist/src/storage/search/qmd.js +124 -0
  130. package/dist/src/storage/search/qmd.js.map +1 -0
  131. package/dist/src/telemetry/meter.d.ts +8 -6
  132. package/dist/src/telemetry/meter.d.ts.map +1 -1
  133. package/dist/src/telemetry/meter.js +8 -7
  134. package/dist/src/telemetry/meter.js.map +1 -1
  135. package/dist/src/telemetry/tracer.d.ts.map +1 -1
  136. package/dist/src/telemetry/tracer.js +9 -2
  137. package/dist/src/telemetry/tracer.js.map +1 -1
  138. package/dist/src/tools/executors/executor.d.ts +11 -1
  139. package/dist/src/tools/executors/executor.d.ts.map +1 -1
  140. package/dist/src/tools/executors/executor.js +50 -16
  141. package/dist/src/tools/executors/executor.js.map +1 -1
  142. package/dist/src/tsconfig.tsbuildinfo +1 -1
  143. package/dist/src/types/agent.d.ts +12 -2
  144. package/dist/src/types/agent.d.ts.map +1 -1
  145. package/dist/src/types/agent.js +3 -2
  146. package/dist/src/types/agent.js.map +1 -1
  147. package/dist/src/vended-memory-stores/file-memory-store/index.d.ts +1 -1
  148. package/dist/src/vended-memory-stores/file-memory-store/index.d.ts.map +1 -1
  149. package/dist/src/vended-memory-stores/file-memory-store/store.d.ts +31 -0
  150. package/dist/src/vended-memory-stores/file-memory-store/store.d.ts.map +1 -1
  151. package/dist/src/vended-memory-stores/file-memory-store/store.js +48 -25
  152. package/dist/src/vended-memory-stores/file-memory-store/store.js.map +1 -1
  153. package/dist/src/vended-tools/file-editor/file-editor.js +35 -30
  154. package/dist/src/vended-tools/file-editor/file-editor.js.map +1 -1
  155. package/package.json +21 -4
@@ -0,0 +1,306 @@
1
+ import { normalizeError } from '../../errors.js';
2
+ import { BackgroundTaskNotFoundError } from '../errors.js';
3
+ import { assertTimerDelay } from '../timer.js';
4
+ import { isTaskStatusTerminal } from '../types.js';
5
+ const DEFAULT_EXECUTION_FAILURE_MESSAGE = 'Background task execution failed';
6
+ /** Runs and tracks bounded in-process tasks. @internal */
7
+ export class InProcessTaskEngine {
8
+ _options;
9
+ _tasks = new Map();
10
+ _queue = new Set();
11
+ _activeExecutions = new Map();
12
+ _idleWaiters = new Set();
13
+ /**
14
+ * Creates an in-process task engine.
15
+ *
16
+ * @param options - Execution limits and callbacks supplied by the task manager.
17
+ * @throws TypeError if the concurrency or timeout configuration is invalid.
18
+ */
19
+ constructor(options) {
20
+ if (!Number.isSafeInteger(options.maxConcurrency) || options.maxConcurrency <= 0) {
21
+ throw new TypeError(`maxConcurrency must be a positive finite integer, got ${options.maxConcurrency}`);
22
+ }
23
+ if (options.timeout !== Infinity)
24
+ assertTimerDelay('timeout', options.timeout);
25
+ this._options = options;
26
+ }
27
+ /**
28
+ * Submits a task for execution.
29
+ *
30
+ * @param admission - Tool execution details.
31
+ * @returns A snapshot of the admitted task.
32
+ */
33
+ submit(admission) {
34
+ const now = new Date().toISOString();
35
+ const stored = {
36
+ taskId: globalThis.crypto.randomUUID(),
37
+ ...admission,
38
+ status: 'queued',
39
+ createdAt: now,
40
+ lastUpdatedAt: now,
41
+ };
42
+ this._tasks.set(stored.taskId, stored);
43
+ this._notifyTaskUpdated(stored);
44
+ this._scheduleTask(stored.taskId);
45
+ return globalThis.structuredClone(stored);
46
+ }
47
+ /**
48
+ * Gets a task by ID.
49
+ *
50
+ * @param taskId - ID of the task to retrieve.
51
+ * @returns A snapshot of the task, or `undefined` when it does not exist.
52
+ */
53
+ get(taskId) {
54
+ const task = this._tasks.get(taskId);
55
+ return task ? globalThis.structuredClone(task) : undefined;
56
+ }
57
+ /**
58
+ * Lists the tasks tracked by this engine.
59
+ *
60
+ * @returns Snapshots of the tracked tasks.
61
+ */
62
+ list() {
63
+ return [...this._tasks.values()].map((task) => globalThis.structuredClone(task));
64
+ }
65
+ /**
66
+ * Removes a terminal task.
67
+ *
68
+ * @param taskId - ID of the task to remove.
69
+ * @throws Error if the task does not exist or has not reached a terminal state.
70
+ */
71
+ remove(taskId) {
72
+ const task = this._requireTask(taskId);
73
+ if (!isTaskStatusTerminal(task.status)) {
74
+ throw new Error(`Background task '${taskId}' cannot be removed before reaching a terminal status`);
75
+ }
76
+ this._tasks.delete(taskId);
77
+ }
78
+ /**
79
+ * Cancels a non-terminal task and aborts its active execution.
80
+ *
81
+ * @param taskId - ID of the task to cancel.
82
+ * @param options - Cancellation options passed to the active execution.
83
+ * @returns A snapshot of the cancelled task, or the unchanged task if it was already terminal.
84
+ * @throws Error if the task does not exist.
85
+ */
86
+ cancel(taskId, options) {
87
+ const current = this._requireTask(taskId);
88
+ if (isTaskStatusTerminal(current.status))
89
+ return globalThis.structuredClone(current);
90
+ const task = this._updateTask(taskId, (record) => {
91
+ record.status = 'cancelled';
92
+ delete record.state;
93
+ return true;
94
+ });
95
+ this._queue.delete(taskId);
96
+ const activeExecution = this._activeExecutions.get(taskId);
97
+ if (activeExecution?.timeout) {
98
+ clearTimeout(activeExecution.timeout);
99
+ }
100
+ activeExecution?.controller.abort(options.reason);
101
+ this._wakeIdleWaiters();
102
+ return task;
103
+ }
104
+ /**
105
+ * Waits until no tasks are queued or executing.
106
+ *
107
+ * @param options - Optional cancellation signal for the wait.
108
+ * @returns A promise that resolves when the engine is idle.
109
+ * @throws The cancellation signal's reason if the wait is aborted.
110
+ */
111
+ async waitForIdle(options) {
112
+ const cancelSignal = options?.cancelSignal;
113
+ while (this._queue.size > 0 || this._activeExecutions.size > 0) {
114
+ if (cancelSignal?.aborted)
115
+ throw cancelSignal.reason;
116
+ await new Promise((resolve, reject) => {
117
+ const onAbort = () => {
118
+ this._idleWaiters.delete(onIdle);
119
+ reject(cancelSignal.reason);
120
+ };
121
+ const onIdle = () => {
122
+ cancelSignal?.removeEventListener('abort', onAbort);
123
+ resolve();
124
+ };
125
+ this._idleWaiters.add(onIdle);
126
+ cancelSignal?.addEventListener('abort', onAbort, { once: true });
127
+ });
128
+ }
129
+ }
130
+ /**
131
+ * Applies interrupt responses to a task with `input_required` status.
132
+ *
133
+ * The task remains `input_required` while interrupts are unanswered and is queued for
134
+ * execution once the updated interrupt state is ready.
135
+ *
136
+ * @param taskId - ID of the task requiring input.
137
+ * @param update - Applies interrupt responses to the task state and reports when it is ready.
138
+ * @returns A snapshot of the updated task.
139
+ * @throws BackgroundTaskNotFoundError if the task does not exist.
140
+ * @throws Error if the task does not require input or has no state.
141
+ */
142
+ resume(taskId, update) {
143
+ const task = this._updateTask(taskId, (record) => {
144
+ if (record.status !== 'input_required') {
145
+ throw new Error(`Background task '${taskId}' cannot be resumed: status is '${record.status}', not 'input_required'`);
146
+ }
147
+ if (record.state === undefined) {
148
+ throw new Error(`Background task '${taskId}' cannot be resumed: interrupt state is missing`);
149
+ }
150
+ const resumed = update(record.state);
151
+ record.state = resumed.state;
152
+ if (resumed.ready)
153
+ record.status = 'queued';
154
+ return true;
155
+ });
156
+ if (task.status === 'queued')
157
+ this._scheduleTask(taskId);
158
+ return task;
159
+ }
160
+ _scheduleTask(taskId) {
161
+ if (this._activeExecutions.has(taskId))
162
+ return;
163
+ this._queue.add(taskId);
164
+ this._startQueuedTasks();
165
+ }
166
+ _startQueuedTasks() {
167
+ while (this._activeExecutions.size < this._options.maxConcurrency && this._queue.size > 0) {
168
+ const taskId = this._queue.values().next().value;
169
+ this._queue.delete(taskId);
170
+ const activeExecution = {
171
+ controller: new AbortController(),
172
+ };
173
+ this._activeExecutions.set(taskId, activeExecution);
174
+ void this._execute(taskId, activeExecution)
175
+ .finally(() => {
176
+ if (activeExecution.timeout)
177
+ clearTimeout(activeExecution.timeout);
178
+ this._activeExecutions.delete(taskId);
179
+ if (this._tasks.get(taskId)?.status === 'queued') {
180
+ this._queue.add(taskId);
181
+ }
182
+ this._wakeIdleWaiters();
183
+ this._startQueuedTasks();
184
+ })
185
+ .catch(() => undefined);
186
+ }
187
+ }
188
+ async _execute(taskId, activeExecution) {
189
+ const working = this._updateTask(taskId, (task) => {
190
+ task.status = 'working';
191
+ return true;
192
+ });
193
+ if (Number.isFinite(this._options.timeout)) {
194
+ activeExecution.timeout = setTimeout(() => {
195
+ delete activeExecution.timeout;
196
+ this._timeoutTask(taskId, activeExecution);
197
+ }, this._options.timeout);
198
+ }
199
+ let outcome;
200
+ try {
201
+ outcome = await this._options.execute({
202
+ taskId,
203
+ toolUseId: working.toolUseId,
204
+ toolName: working.toolName,
205
+ invocationStateId: working.invocationStateId,
206
+ ...(working.state !== undefined && { state: working.state }),
207
+ cancelSignal: activeExecution.controller.signal,
208
+ });
209
+ }
210
+ catch (error) {
211
+ outcome = {
212
+ status: 'failed',
213
+ failure: {
214
+ type: 'executionError',
215
+ message: getExecutionFailureMessage(error),
216
+ },
217
+ };
218
+ }
219
+ this._finishOutcome(taskId, outcome);
220
+ }
221
+ _finishOutcome(taskId, outcome) {
222
+ if (outcome.status === 'input_required') {
223
+ this._updateTask(taskId, (record) => {
224
+ if (record.status !== 'working')
225
+ return false;
226
+ record.status = 'input_required';
227
+ record.state = outcome.state;
228
+ return true;
229
+ });
230
+ return;
231
+ }
232
+ this._updateTask(taskId, (record) => {
233
+ if (record.status !== 'working')
234
+ return false;
235
+ if (outcome.status === 'failed') {
236
+ record.status = 'failed';
237
+ delete record.state;
238
+ record.failure = {
239
+ type: outcome.failure.type,
240
+ message: outcome.failure.message || DEFAULT_EXECUTION_FAILURE_MESSAGE,
241
+ };
242
+ if (outcome.result !== undefined) {
243
+ record.result = outcome.result;
244
+ }
245
+ return true;
246
+ }
247
+ record.status = 'completed';
248
+ delete record.state;
249
+ record.result = outcome.result;
250
+ return true;
251
+ });
252
+ }
253
+ _timeoutTask(taskId, activeExecution) {
254
+ const reason = `Timed out after ${this._options.timeout}ms`;
255
+ const task = this._updateTask(taskId, (record) => {
256
+ if (record.status !== 'working')
257
+ return false;
258
+ record.status = 'failed';
259
+ delete record.state;
260
+ record.failure = {
261
+ type: 'timeout',
262
+ message: reason,
263
+ };
264
+ return true;
265
+ });
266
+ if (task)
267
+ activeExecution.controller.abort(reason);
268
+ }
269
+ _updateTask(taskId, update) {
270
+ const current = this._requireTask(taskId);
271
+ const next = globalThis.structuredClone(current);
272
+ if (!update(next))
273
+ return undefined;
274
+ next.lastUpdatedAt = new Date().toISOString();
275
+ const stored = globalThis.structuredClone(next);
276
+ this._tasks.set(taskId, stored);
277
+ this._notifyTaskUpdated(stored);
278
+ return globalThis.structuredClone(stored);
279
+ }
280
+ _requireTask(taskId) {
281
+ const task = this._tasks.get(taskId);
282
+ if (!task)
283
+ throw new BackgroundTaskNotFoundError(taskId);
284
+ return task;
285
+ }
286
+ _notifyTaskUpdated(task) {
287
+ const taskSnapshot = globalThis.structuredClone(task);
288
+ void Promise.resolve()
289
+ .then(() => this._options.onTaskUpdated(taskSnapshot))
290
+ .catch(() => undefined);
291
+ }
292
+ _wakeIdleWaiters() {
293
+ for (const resolve of this._idleWaiters)
294
+ resolve();
295
+ this._idleWaiters.clear();
296
+ }
297
+ }
298
+ function getExecutionFailureMessage(error) {
299
+ try {
300
+ return normalizeError(error).message || DEFAULT_EXECUTION_FAILURE_MESSAGE;
301
+ }
302
+ catch {
303
+ return DEFAULT_EXECUTION_FAILURE_MESSAGE;
304
+ }
305
+ }
306
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../../../src/background-tasks/in-process/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGlD,MAAM,iCAAiC,GAAG,kCAAkC,CAAA;AAO5E,0DAA0D;AAC1D,MAAM,OAAO,mBAAmB;IACb,QAAQ,CAA4B;IACpC,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAA;IAC/C,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAC1B,iBAAiB,GAAG,IAAI,GAAG,EAA2B,CAAA;IACtD,YAAY,GAAG,IAAI,GAAG,EAAc,CAAA;IAErD;;;;;OAKG;IACH,YAAY,OAAmC;QAC7C,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,cAAc,IAAI,CAAC,EAAE,CAAC;YACjF,MAAM,IAAI,SAAS,CAAC,yDAAyD,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;QACxG,CAAC;QACD,IAAI,OAAO,CAAC,OAAO,KAAK,QAAQ;YAAE,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;QAC9E,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;IACzB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,SA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,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACpC,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,2BAA2B,CAAC,MAAM,CAAC,CAAA;QACxD,OAAO,IAAI,CAAA;IACb,CAAC;IAEO,kBAAkB,CAAC,IAAyB;QAClD,MAAM,YAAY,GAAG,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;QACrD,KAAK,OAAO,CAAC,OAAO,EAAE;aACnB,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;aACrD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAC3B,CAAC;IAEO,gBAAgB;QACtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,YAAY;YAAE,OAAO,EAAE,CAAA;QAClD,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;CACF;AAED,SAAS,0BAA0B,CAAC,KAAc;IAChD,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,iCAAiC,CAAA;IAC3E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,iCAAiC,CAAA;IAC1C,CAAC;AACH,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { Agent } from '../../agent/agent.js';
2
+ import type { ToolUseData } from '../../hooks/events.js';
3
+ import type { ExecuteToolContext } from '../../middleware/index.js';
4
+ import type { InvocationState } from '../../types/agent.js';
5
+ import { type InterruptResponse } from '../../types/interrupt.js';
6
+ import { type ToolResultBlock } from '../../types/messages.js';
7
+ import type { Tool, ToolContext } from '../../tools/tool.js';
8
+ import type { BackgroundTaskManager } from '../manager.js';
9
+ import { type BackgroundTask } from '../types.js';
10
+ /** Configures in-process background task execution. @internal */
11
+ export interface InProcessTaskManagerConfig {
12
+ /** Maximum number of physically executing background tasks. Defaults to `4`. */
13
+ readonly maxConcurrency?: number;
14
+ /** Per-execution timeout in milliseconds. Defaults to `Infinity`. */
15
+ readonly timeout?: number;
16
+ readonly onTaskUpdated?: (task: BackgroundTask) => void;
17
+ }
18
+ /** Executes approved tool calls as in-process background tasks. @internal */
19
+ export declare class InProcessTaskManager implements BackgroundTaskManager {
20
+ private readonly _agent;
21
+ private readonly _executeTool;
22
+ private readonly _engine;
23
+ private readonly _executions;
24
+ private readonly _taskIdBySubmission;
25
+ private readonly _taskWaiters;
26
+ constructor(agent: Agent, executeTool: (tool: Tool, context: ToolContext, middlewareInterrupt: ExecuteToolContext['interrupt']) => Promise<ToolResultBlock>, config?: InProcessTaskManagerConfig);
27
+ submit(toolUse: Readonly<ToolUseData>, invocationState: InvocationState, passId: string, tool: Tool): Promise<BackgroundTask>;
28
+ get(taskId: string): Promise<BackgroundTask | undefined>;
29
+ list(): Promise<readonly BackgroundTask[]>;
30
+ hasTasks(): boolean;
31
+ cancel(taskId: string): Promise<BackgroundTask>;
32
+ wait(taskId: string): Promise<BackgroundTask>;
33
+ waitForIdle(options?: {
34
+ readonly timeout?: number;
35
+ }): Promise<void>;
36
+ resume(taskId: string, responses: readonly InterruptResponse[]): Promise<BackgroundTask>;
37
+ remove(taskIds: readonly string[]): Promise<void>;
38
+ private _executeToolTask;
39
+ private _notifyTaskWaiters;
40
+ }
41
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/background-tasks/in-process/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAkD,KAAK,iBAAiB,EAAE,MAAM,0BAA0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C,cAAc,GAAG,SAAS,CAAC;IAKxD,IAAI,IAAI,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC;IAIhD,QAAQ,IAAI,OAAO;IAIb,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAI/C,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAmB7C,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,iBAAiB,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAqBxF,MAAM,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAiBzC,gBAAgB;IAsC9B,OAAO,CAAC,kBAAkB;CAK3B"}
@@ -0,0 +1,214 @@
1
+ import { InterruptError, InterruptState } from '../../interrupt.js';
2
+ import { createMiddlewareInterrupt } from '../../middleware/interrupt.js';
3
+ import { InterruptResponseContent } from '../../types/interrupt.js';
4
+ import { TextBlock } from '../../types/messages.js';
5
+ import { BackgroundTaskNotFoundError, BackgroundTaskTimeoutError } from '../errors.js';
6
+ import { assertTimerDelay } from '../timer.js';
7
+ import { InProcessTaskEngine } from './engine.js';
8
+ import {} from './types.js';
9
+ import { isTaskStatusTerminal } from '../types.js';
10
+ /** Executes approved tool calls as in-process background tasks. @internal */
11
+ export class InProcessTaskManager {
12
+ _agent;
13
+ _executeTool;
14
+ _engine;
15
+ _executions = new Map();
16
+ _taskIdBySubmission = new Map();
17
+ _taskWaiters = new Map();
18
+ constructor(agent, executeTool, config = {}) {
19
+ this._agent = agent;
20
+ this._executeTool = executeTool;
21
+ this._engine = new InProcessTaskEngine({
22
+ maxConcurrency: config.maxConcurrency ?? 4,
23
+ timeout: config.timeout ?? Infinity,
24
+ execute: (context) => this._executeToolTask(context),
25
+ onTaskUpdated: (record) => {
26
+ const task = toBackgroundTask(record);
27
+ if (isTaskStatusTerminal(record.status)) {
28
+ this._executions.delete(record.invocationStateId);
29
+ }
30
+ if (record.status === 'input_required' || isTaskStatusTerminal(record.status)) {
31
+ this._notifyTaskWaiters(task);
32
+ }
33
+ config.onTaskUpdated?.(task);
34
+ },
35
+ });
36
+ }
37
+ async submit(toolUse, invocationState, passId, tool) {
38
+ const submissionKey = JSON.stringify([passId, toolUse.toolUseId]);
39
+ const existingTaskId = this._taskIdBySubmission.get(submissionKey);
40
+ if (existingTaskId)
41
+ return toBackgroundTask(this._engine.get(existingTaskId));
42
+ const invocationStateId = globalThis.crypto.randomUUID();
43
+ this._executions.set(invocationStateId, {
44
+ toolUse: globalThis.structuredClone(toolUse),
45
+ invocationState,
46
+ tool,
47
+ });
48
+ const record = this._engine.submit({
49
+ toolName: toolUse.name,
50
+ toolUseId: toolUse.toolUseId,
51
+ invocationStateId,
52
+ });
53
+ this._taskIdBySubmission.set(submissionKey, record.taskId);
54
+ return toBackgroundTask(record);
55
+ }
56
+ async get(taskId) {
57
+ const record = this._engine.get(taskId);
58
+ return record ? toBackgroundTask(record) : undefined;
59
+ }
60
+ async list() {
61
+ return this._engine.list().map(toBackgroundTask);
62
+ }
63
+ hasTasks() {
64
+ return this._taskIdBySubmission.size > 0;
65
+ }
66
+ async cancel(taskId) {
67
+ return toBackgroundTask(this._engine.cancel(taskId, { reason: 'Cancellation requested' }));
68
+ }
69
+ async wait(taskId) {
70
+ const current = this._engine.get(taskId);
71
+ if (!current)
72
+ throw new BackgroundTaskNotFoundError(taskId);
73
+ if (current.status === 'input_required' || isTaskStatusTerminal(current.status)) {
74
+ return toBackgroundTask(current);
75
+ }
76
+ return new Promise((resolve) => {
77
+ const waiters = this._taskWaiters.get(taskId) ?? new Set();
78
+ const onTaskUpdated = (task) => {
79
+ waiters.delete(onTaskUpdated);
80
+ if (waiters.size === 0)
81
+ this._taskWaiters.delete(taskId);
82
+ resolve(task);
83
+ };
84
+ waiters.add(onTaskUpdated);
85
+ this._taskWaiters.set(taskId, waiters);
86
+ });
87
+ }
88
+ async waitForIdle(options) {
89
+ const timeout = options?.timeout;
90
+ if (timeout !== undefined)
91
+ assertTimerDelay('wait timeout', timeout);
92
+ if (timeout === undefined)
93
+ return this._engine.waitForIdle();
94
+ const cancelSignal = AbortSignal.timeout(timeout);
95
+ try {
96
+ await this._engine.waitForIdle({ cancelSignal });
97
+ }
98
+ catch (error) {
99
+ if (error === cancelSignal.reason)
100
+ throw new BackgroundTaskTimeoutError(timeout);
101
+ throw error;
102
+ }
103
+ }
104
+ async resume(taskId, responses) {
105
+ return toBackgroundTask(this._engine.resume(taskId, (state) => {
106
+ const taskState = InterruptState.fromJSON(state);
107
+ taskState.resume(responses.map((response) => new InterruptResponseContent({
108
+ interruptId: response.interruptId,
109
+ response: response.response,
110
+ })));
111
+ return {
112
+ state: taskState.toJSON(),
113
+ ready: taskState.getUnansweredInterrupts().length === 0,
114
+ };
115
+ }));
116
+ }
117
+ async remove(taskIds) {
118
+ const uniqueTaskIds = new Set(taskIds);
119
+ for (const taskId of uniqueTaskIds) {
120
+ const task = this._engine.get(taskId);
121
+ if (!task)
122
+ throw new BackgroundTaskNotFoundError(taskId);
123
+ if (!isTaskStatusTerminal(task.status)) {
124
+ throw new Error(`Background task '${taskId}' cannot be removed before reaching a terminal status`);
125
+ }
126
+ }
127
+ for (const taskId of uniqueTaskIds) {
128
+ this._engine.remove(taskId);
129
+ }
130
+ for (const [submissionKey, taskId] of this._taskIdBySubmission) {
131
+ if (uniqueTaskIds.has(taskId))
132
+ this._taskIdBySubmission.delete(submissionKey);
133
+ }
134
+ }
135
+ async _executeToolTask(context) {
136
+ const execution = this._executions.get(context.invocationStateId);
137
+ if (!execution)
138
+ throw new Error('Background task live execution state is unavailable');
139
+ const interruptState = context.state ? InterruptState.fromJSON(context.state) : new InterruptState();
140
+ try {
141
+ return toolTaskOutcome(await this._executeTool(execution.tool, {
142
+ agent: this._agent,
143
+ invocationState: execution.invocationState,
144
+ cancelSignal: context.cancelSignal,
145
+ toolUse: execution.toolUse,
146
+ interrupt: (params) => interruptTool(interruptState, context.taskId, params),
147
+ }, createMiddlewareInterrupt(interruptState, `middleware:${context.taskId}`)));
148
+ }
149
+ catch (error) {
150
+ if (error instanceof InterruptError) {
151
+ const taskOwnsInterrupts = error.interrupts.length > 0 &&
152
+ error.interrupts.every((interrupt) => (interrupt.source === 'middleware' || interrupt.source === 'tool') &&
153
+ interrupt.id.startsWith(`${interrupt.source}:${context.taskId}:`));
154
+ if (!taskOwnsInterrupts)
155
+ throw error;
156
+ for (const interrupt of error.interrupts)
157
+ interruptState.registerInterrupt(interrupt);
158
+ interruptState.activate();
159
+ return { status: 'input_required', state: interruptState.toJSON() };
160
+ }
161
+ throw error;
162
+ }
163
+ }
164
+ _notifyTaskWaiters(task) {
165
+ const waiters = this._taskWaiters.get(task.taskId);
166
+ if (!waiters)
167
+ return;
168
+ for (const waiter of waiters)
169
+ waiter(task);
170
+ }
171
+ }
172
+ function toolTaskOutcome(resultBlock) {
173
+ const result = resultBlock.toJSON().toolResult;
174
+ if (resultBlock.status === 'success')
175
+ return { status: 'completed', result };
176
+ return {
177
+ status: 'failed',
178
+ failure: {
179
+ type: 'toolError',
180
+ message: resultBlock.error?.message ??
181
+ resultBlock.content.find((content) => content instanceof TextBlock)?.text ??
182
+ 'Tool returned an error without a message',
183
+ },
184
+ result,
185
+ };
186
+ }
187
+ function interruptTool(state, taskId, params) {
188
+ const interrupt = state.getOrCreateInterrupt(`tool:${taskId}:${params.name}`, params.name, params.reason, params.response, 'tool');
189
+ if (interrupt.response !== undefined)
190
+ return interrupt.response;
191
+ throw new InterruptError(interrupt);
192
+ }
193
+ function toBackgroundTask(record) {
194
+ const interrupts = record.state ? InterruptState.fromJSON(record.state).getUnansweredInterrupts() : [];
195
+ return {
196
+ taskId: record.taskId,
197
+ toolUseId: record.toolUseId,
198
+ toolName: record.toolName,
199
+ status: record.status,
200
+ createdAt: record.createdAt,
201
+ lastUpdatedAt: record.lastUpdatedAt,
202
+ ...(record.result && {
203
+ result: { content: record.result.content },
204
+ }),
205
+ ...(record.failure && {
206
+ error: {
207
+ type: record.failure.type,
208
+ message: record.failure.message,
209
+ },
210
+ }),
211
+ ...(interrupts.length > 0 && { interrupts }),
212
+ };
213
+ }
214
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/background-tasks/in-process/manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAA;AAGzE,OAAO,EAAE,wBAAwB,EAAgD,MAAM,0BAA0B,CAAA;AAEjH,OAAO,EAAE,SAAS,EAAwB,MAAM,yBAAyB,CAAA;AAEzE,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAIN,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,oBAAoB,EAAuB,MAAM,aAAa,CAAA;AAiBvE,6EAA6E;AAC7E,MAAM,OAAO,oBAAoB;IACd,MAAM,CAAO;IACb,YAAY,CAAA;IACZ,OAAO,CAAqB;IAC5B,WAAW,GAAG,IAAI,GAAG,EAA6B,CAAA;IAClD,mBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC/C,YAAY,GAAG,IAAI,GAAG,EAA+C,CAAA;IAEtF,YACE,KAAY,EACZ,WAI6B,EAC7B,SAAqC,EAAE;QAEvC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;QAC/B,IAAI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