@strands-agents/sdk 1.15.0 → 1.17.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 (162) hide show
  1. package/README.md +1 -1
  2. package/dist/src/agent/agent.d.ts +4 -0
  3. package/dist/src/agent/agent.d.ts.map +1 -1
  4. package/dist/src/agent/agent.js +66 -16
  5. package/dist/src/agent/agent.js.map +1 -1
  6. package/dist/src/background-tasks/background-tasks.d.ts +41 -0
  7. package/dist/src/background-tasks/background-tasks.d.ts.map +1 -0
  8. package/dist/src/background-tasks/background-tasks.js +402 -0
  9. package/dist/src/background-tasks/background-tasks.js.map +1 -0
  10. package/dist/src/background-tasks/errors.d.ts +7 -0
  11. package/dist/src/background-tasks/errors.d.ts.map +1 -1
  12. package/dist/src/background-tasks/errors.js +10 -0
  13. package/dist/src/background-tasks/errors.js.map +1 -1
  14. package/dist/src/background-tasks/in-process/engine.d.ts +3 -4
  15. package/dist/src/background-tasks/in-process/engine.d.ts.map +1 -1
  16. package/dist/src/background-tasks/in-process/engine.js +9 -25
  17. package/dist/src/background-tasks/in-process/engine.js.map +1 -1
  18. package/dist/src/background-tasks/in-process/manager.d.ts +41 -0
  19. package/dist/src/background-tasks/in-process/manager.d.ts.map +1 -0
  20. package/dist/src/background-tasks/in-process/manager.js +214 -0
  21. package/dist/src/background-tasks/in-process/manager.js.map +1 -0
  22. package/dist/src/background-tasks/in-process/types.d.ts +9 -14
  23. package/dist/src/background-tasks/in-process/types.d.ts.map +1 -1
  24. package/dist/src/background-tasks/manager.d.ts +59 -0
  25. package/dist/src/background-tasks/manager.d.ts.map +1 -0
  26. package/dist/src/background-tasks/manager.js +2 -0
  27. package/dist/src/background-tasks/manager.js.map +1 -0
  28. package/dist/src/background-tasks/timer.d.ts +3 -0
  29. package/dist/src/background-tasks/timer.d.ts.map +1 -0
  30. package/dist/src/background-tasks/timer.js +11 -0
  31. package/dist/src/background-tasks/timer.js.map +1 -0
  32. package/dist/src/background-tasks/types.d.ts +60 -0
  33. package/dist/src/background-tasks/types.d.ts.map +1 -0
  34. package/dist/src/background-tasks/types.js +11 -0
  35. package/dist/src/background-tasks/types.js.map +1 -0
  36. package/dist/src/context-manager/context-manager.d.ts +22 -1
  37. package/dist/src/context-manager/context-manager.d.ts.map +1 -1
  38. package/dist/src/context-manager/context-manager.js +57 -3
  39. package/dist/src/context-manager/context-manager.js.map +1 -1
  40. package/dist/src/context-manager/methods/summarize.d.ts +2 -2
  41. package/dist/src/context-manager/methods/summarize.d.ts.map +1 -1
  42. package/dist/src/context-manager/methods/summarize.js +0 -2
  43. package/dist/src/context-manager/methods/summarize.js.map +1 -1
  44. package/dist/src/context-manager/methods/truncate.d.ts +2 -2
  45. package/dist/src/context-manager/methods/truncate.d.ts.map +1 -1
  46. package/dist/src/context-manager/methods/truncate.js +0 -2
  47. package/dist/src/context-manager/methods/truncate.js.map +1 -1
  48. package/dist/src/context-manager/modes/agentic/agentic-context.d.ts +2 -2
  49. package/dist/src/context-manager/retrieval-tool.d.ts +29 -0
  50. package/dist/src/context-manager/retrieval-tool.d.ts.map +1 -0
  51. package/dist/src/context-manager/retrieval-tool.js +98 -0
  52. package/dist/src/context-manager/retrieval-tool.js.map +1 -0
  53. package/dist/src/context-manager/stash.d.ts +107 -0
  54. package/dist/src/context-manager/stash.d.ts.map +1 -0
  55. package/dist/src/context-manager/stash.js +186 -0
  56. package/dist/src/context-manager/stash.js.map +1 -0
  57. package/dist/src/context-manager/strategies/offload/base.d.ts +10 -6
  58. package/dist/src/context-manager/strategies/offload/base.d.ts.map +1 -1
  59. package/dist/src/context-manager/strategies/offload/base.js +21 -9
  60. package/dist/src/context-manager/strategies/offload/base.js.map +1 -1
  61. package/dist/src/context-manager/strategies/offload/drop.d.ts +2 -2
  62. package/dist/src/context-manager/strategies/offload/drop.d.ts.map +1 -1
  63. package/dist/src/context-manager/strategies/offload/drop.js +6 -4
  64. package/dist/src/context-manager/strategies/offload/drop.js.map +1 -1
  65. package/dist/src/context-manager/strategies/offload/index.d.ts +1 -1
  66. package/dist/src/context-manager/strategies/offload/index.js +1 -1
  67. package/dist/src/context-manager/strategies/offload/summarize.d.ts +2 -2
  68. package/dist/src/context-manager/strategies/offload/summarize.d.ts.map +1 -1
  69. package/dist/src/context-manager/strategies/offload/summarize.js +16 -18
  70. package/dist/src/context-manager/strategies/offload/summarize.js.map +1 -1
  71. package/dist/src/context-manager/strategies/offload/truncate.d.ts +2 -2
  72. package/dist/src/context-manager/strategies/offload/truncate.d.ts.map +1 -1
  73. package/dist/src/context-manager/strategies/offload/truncate.js +33 -4
  74. package/dist/src/context-manager/strategies/offload/truncate.js.map +1 -1
  75. package/dist/src/context-manager/types.d.ts +35 -1
  76. package/dist/src/context-manager/types.d.ts.map +1 -1
  77. package/dist/src/experimental/index.d.ts +6 -0
  78. package/dist/src/experimental/index.d.ts.map +1 -1
  79. package/dist/src/experimental/index.js +3 -0
  80. package/dist/src/experimental/index.js.map +1 -1
  81. package/dist/src/index.d.ts +4 -3
  82. package/dist/src/index.d.ts.map +1 -1
  83. package/dist/src/index.js +1 -1
  84. package/dist/src/index.js.map +1 -1
  85. package/dist/src/mcp/client.d.ts +3 -2
  86. package/dist/src/mcp/client.d.ts.map +1 -1
  87. package/dist/src/mcp/client.js +3 -2
  88. package/dist/src/mcp/client.js.map +1 -1
  89. package/dist/src/mcp/config.d.ts +11 -1
  90. package/dist/src/mcp/config.d.ts.map +1 -1
  91. package/dist/src/mcp/config.js.map +1 -1
  92. package/dist/src/mcp/config.node.d.ts +3 -2
  93. package/dist/src/mcp/config.node.d.ts.map +1 -1
  94. package/dist/src/mcp/config.node.js +6 -3
  95. package/dist/src/mcp/config.node.js.map +1 -1
  96. package/dist/src/mcp/index.d.ts +1 -1
  97. package/dist/src/mcp/index.d.ts.map +1 -1
  98. package/dist/src/models/openai/cache.d.ts +28 -1
  99. package/dist/src/models/openai/cache.d.ts.map +1 -1
  100. package/dist/src/models/openai/cache.js +37 -13
  101. package/dist/src/models/openai/cache.js.map +1 -1
  102. package/dist/src/models/routing/classifier-strategy.d.ts +87 -0
  103. package/dist/src/models/routing/classifier-strategy.d.ts.map +1 -0
  104. package/dist/src/models/routing/classifier-strategy.js +285 -0
  105. package/dist/src/models/routing/classifier-strategy.js.map +1 -0
  106. package/dist/src/models/routing/index.d.ts +2 -0
  107. package/dist/src/models/routing/index.d.ts.map +1 -1
  108. package/dist/src/models/routing/index.js +1 -0
  109. package/dist/src/models/routing/index.js.map +1 -1
  110. package/dist/src/models/routing/router.d.ts +14 -2
  111. package/dist/src/models/routing/router.d.ts.map +1 -1
  112. package/dist/src/models/routing/router.js +43 -8
  113. package/dist/src/models/routing/router.js.map +1 -1
  114. package/dist/src/models/vercel.d.ts +9 -1
  115. package/dist/src/models/vercel.d.ts.map +1 -1
  116. package/dist/src/models/vercel.js +248 -7
  117. package/dist/src/models/vercel.js.map +1 -1
  118. package/dist/src/session/session-manager.d.ts +5 -1
  119. package/dist/src/session/session-manager.d.ts.map +1 -1
  120. package/dist/src/session/session-manager.js +51 -1
  121. package/dist/src/session/session-manager.js.map +1 -1
  122. package/dist/src/session/snapshot-storage-adapter.d.ts.map +1 -1
  123. package/dist/src/session/snapshot-storage-adapter.js +1 -0
  124. package/dist/src/session/snapshot-storage-adapter.js.map +1 -1
  125. package/dist/src/storage/in-memory-storage.d.ts +2 -0
  126. package/dist/src/storage/in-memory-storage.d.ts.map +1 -1
  127. package/dist/src/storage/in-memory-storage.js +2 -1
  128. package/dist/src/storage/in-memory-storage.js.map +1 -1
  129. package/dist/src/storage/local-file-storage.d.ts +4 -6
  130. package/dist/src/storage/local-file-storage.d.ts.map +1 -1
  131. package/dist/src/storage/local-file-storage.js +12 -10
  132. package/dist/src/storage/local-file-storage.js.map +1 -1
  133. package/dist/src/storage/search/keyword.d.ts +1 -0
  134. package/dist/src/storage/search/keyword.d.ts.map +1 -1
  135. package/dist/src/storage/search/keyword.js +124 -0
  136. package/dist/src/storage/search/keyword.js.map +1 -1
  137. package/dist/src/storage/search/qmd.d.ts +66 -0
  138. package/dist/src/storage/search/qmd.d.ts.map +1 -0
  139. package/dist/src/storage/search/qmd.js +124 -0
  140. package/dist/src/storage/search/qmd.js.map +1 -0
  141. package/dist/src/storage/storage.d.ts +8 -0
  142. package/dist/src/storage/storage.d.ts.map +1 -1
  143. package/dist/src/storage/storage.js +18 -0
  144. package/dist/src/storage/storage.js.map +1 -1
  145. package/dist/src/telemetry/tracer.d.ts.map +1 -1
  146. package/dist/src/telemetry/tracer.js +4 -2
  147. package/dist/src/telemetry/tracer.js.map +1 -1
  148. package/dist/src/tools/executors/executor.d.ts +11 -1
  149. package/dist/src/tools/executors/executor.d.ts.map +1 -1
  150. package/dist/src/tools/executors/executor.js +50 -16
  151. package/dist/src/tools/executors/executor.js.map +1 -1
  152. package/dist/src/tsconfig.tsbuildinfo +1 -1
  153. package/dist/src/types/agent.d.ts +9 -0
  154. package/dist/src/types/agent.d.ts.map +1 -1
  155. package/dist/src/types/agent.js.map +1 -1
  156. package/dist/src/vended-memory-stores/file-memory-store/store.d.ts +9 -0
  157. package/dist/src/vended-memory-stores/file-memory-store/store.d.ts.map +1 -1
  158. package/dist/src/vended-memory-stores/file-memory-store/store.js +18 -13
  159. package/dist/src/vended-memory-stores/file-memory-store/store.js.map +1 -1
  160. package/dist/src/vended-tools/file-editor/file-editor.js +35 -30
  161. package/dist/src/vended-tools/file-editor/file-editor.js.map +1 -1
  162. package/package.json +12 -2
@@ -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,KA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EAAE,IAAI,GACT,OAAO,CAAC,cAAc,CAAC;IAoBpB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,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;QA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OAAO,CAAC,OAAO;aAChC;SACF,CAAC;QACF,GAAG,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC;KAC7C,CAAA;AACH,CAAC"}
@@ -1,9 +1,6 @@
1
1
  import type { InterruptStateData } from '../../interrupt.js';
2
2
  import type { ToolResultBlockData } from '../../types/messages.js';
3
- /** Background task lifecycle status. @internal */
4
- export type TaskStatus = 'queued' | 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled';
5
- /** Background task failure category. @internal */
6
- export type TaskFailureType = 'toolError' | 'executionError' | 'timeout';
3
+ import type { BackgroundTaskFailureType, BackgroundTaskStatus } from '../types.js';
7
4
  /** Options and callbacks for bounded in-process task execution. @internal */
8
5
  export interface InProcessTaskEngineOptions {
9
6
  /** Maximum number of task executions that may run concurrently. */
@@ -11,7 +8,7 @@ export interface InProcessTaskEngineOptions {
11
8
  /** Per-execution timeout in milliseconds, or `Infinity` to disable timeouts. */
12
9
  readonly timeout: number;
13
10
  /** Runs one task execution and returns whether it completed, requires input, or failed. */
14
- readonly execute: (context: InProcessTaskExecutionContext) => Promise<TaskExecutionOutcome>;
11
+ readonly execute: (context: InProcessTaskExecutionContext) => Promise<InProcessTaskExecutionOutcome>;
15
12
  /** Receives committed task updates without blocking or failing the engine. */
16
13
  readonly onTaskUpdated: (task: InProcessTaskRecord) => void;
17
14
  }
@@ -21,7 +18,7 @@ export interface InProcessTaskExecutionContext {
21
18
  readonly taskId: string;
22
19
  /** Identifier of the tool use. */
23
20
  readonly toolUseId: string;
24
- /** Name of the tool to execute. */
21
+ /** Tool name from the original model request. */
25
22
  readonly toolName: string;
26
23
  /** Identifier of the manager-owned live execution state. */
27
24
  readonly invocationStateId: string;
@@ -31,7 +28,7 @@ export interface InProcessTaskExecutionContext {
31
28
  readonly cancelSignal: AbortSignal;
32
29
  }
33
30
  /** Outcome returned by one in-process task execution. @internal */
34
- export type TaskExecutionOutcome = {
31
+ export type InProcessTaskExecutionOutcome = {
35
32
  readonly status: 'completed';
36
33
  readonly result: ToolResultBlockData;
37
34
  } | {
@@ -40,7 +37,7 @@ export type TaskExecutionOutcome = {
40
37
  } | {
41
38
  readonly status: 'failed';
42
39
  readonly failure: {
43
- readonly type: TaskFailureType;
40
+ readonly type: BackgroundTaskFailureType;
44
41
  readonly message: string;
45
42
  };
46
43
  readonly result?: ToolResultBlockData;
@@ -49,28 +46,26 @@ export type TaskExecutionOutcome = {
49
46
  export interface InProcessTaskRecord {
50
47
  /** Identifier of the logical task. */
51
48
  readonly taskId: string;
52
- /** Optional key used to deduplicate task admission. */
53
- readonly idempotencyKey?: string;
54
49
  /** Identifier of the tool use. */
55
50
  readonly toolUseId: string;
56
- /** Name of the tool to execute. */
51
+ /** Tool name from the original model request. */
57
52
  readonly toolName: string;
58
53
  /** Identifier of the manager-owned live execution state. */
59
54
  readonly invocationStateId: string;
60
55
  /** Current task lifecycle status. */
61
- status: TaskStatus;
56
+ status: BackgroundTaskStatus;
62
57
  /** Interrupt state, required while the task needs input and retained while resuming. */
63
58
  state?: InterruptStateData;
64
59
  /** Execution result, required while completed and optional while failed. */
65
60
  result?: ToolResultBlockData;
66
61
  /** Failure details recorded when the task fails. */
67
62
  failure?: {
68
- readonly type: TaskFailureType;
63
+ readonly type: BackgroundTaskFailureType;
69
64
  readonly message: string;
70
65
  };
71
66
  /** ISO-8601 creation timestamp. */
72
67
  readonly createdAt: string;
73
68
  /** ISO-8601 timestamp of the latest transition. */
74
- updatedAt: string;
69
+ lastUpdatedAt: string;
75
70
  }
76
71
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/background-tasks/in-process/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAElE,kDAAkD;AAClD,MAAM,MAAM,U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AA;CACtC,CAAA;AAEL,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAClC,qCAAqC;IACrC,MAAM,EAAE,oBAAoB,CAAA;IAC5B,wFAAwF;IACxF,KAAK,CAAC,EAAE,kBAAkB,CAAA;IAC1B,4EAA4E;IAC5E,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,oDAAoD;IACpD,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAA;QACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAA;CACtB"}
@@ -0,0 +1,59 @@
1
+ import type { ToolUseData } from '../hooks/events.js';
2
+ import type { Tool } from '../tools/tool.js';
3
+ import type { InvocationState } from '../types/agent.js';
4
+ import type { InterruptResponse } from '../types/interrupt.js';
5
+ import type { BackgroundTask } from './types.js';
6
+ /** Background task lifecycle operations used by an Agent integration. @internal */
7
+ export interface BackgroundTaskManager {
8
+ /**
9
+ * Submits an approved tool call for background execution.
10
+ *
11
+ * Repeated submission of the same pending tool call returns its existing task; removing that task allows the
12
+ * submission to create a new task.
13
+ */
14
+ submit(toolUse: Readonly<ToolUseData>, invocationState: InvocationState, passId: string, tool: Tool): Promise<BackgroundTask>;
15
+ /** Gets one task by its stable identifier. */
16
+ get(taskId: string): Promise<BackgroundTask | undefined>;
17
+ /** Lists the tasks currently tracked by the manager. */
18
+ list(): Promise<readonly BackgroundTask[]>;
19
+ /** Whether the manager is tracking any tasks (including terminal ones not yet removed). */
20
+ hasTasks(): boolean;
21
+ /**
22
+ * Requests cancellation of one task.
23
+ *
24
+ * @throws BackgroundTaskNotFoundError if the task does not exist.
25
+ */
26
+ cancel(taskId: string): Promise<BackgroundTask>;
27
+ /**
28
+ * Waits until one task requires input or reaches a terminal state.
29
+ *
30
+ * @throws BackgroundTaskNotFoundError if the task does not exist.
31
+ */
32
+ wait(taskId: string): Promise<BackgroundTask>;
33
+ /**
34
+ * Waits until the manager has no queued or executing tasks.
35
+ *
36
+ * Tasks in `input_required` do not block this wait.
37
+ *
38
+ * @throws TypeError if the timeout is invalid.
39
+ * @throws BackgroundTaskTimeoutError if the configured wait timeout elapses.
40
+ */
41
+ waitForIdle(options?: {
42
+ readonly timeout?: number;
43
+ }): Promise<void>;
44
+ /**
45
+ * Applies interrupt responses to one task that requires input.
46
+ *
47
+ * @throws BackgroundTaskNotFoundError if the task does not exist.
48
+ * @throws Error if the task cannot accept the interrupt responses.
49
+ */
50
+ resume(taskId: string, responses: readonly InterruptResponse[]): Promise<BackgroundTask>;
51
+ /**
52
+ * Removes terminal tasks.
53
+ *
54
+ * @throws BackgroundTaskNotFoundError if a task does not exist.
55
+ * @throws Error if a task has not reached a terminal state.
56
+ */
57
+ remove(taskIds: readonly string[]): Promise<void>;
58
+ }
59
+ //# sourceMappingURL=manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../src/background-tasks/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD,mFAAmF;AACnF,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,MAAM,CACJ,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC9B,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,cAAc,CAAC,CAAA;IAC1B,8CAA8C;IAC9C,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAA;IACxD,wDAAwD;IACxD,IAAI,IAAI,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CAAA;IAC1C,2FAA2F;IAC3F,QAAQ,IAAI,OAAO,CAAA;IACnB;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC/C;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC7C;;;;;;;OAOG;IACH,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnE;;;;;OAKG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,iBAAiB,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACxF;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAClD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../src/background-tasks/manager.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ /** Validates a delay accepted by JavaScript timers. @internal */
2
+ export declare function assertTimerDelay(name: string, value: number): void;
3
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../../src/background-tasks/timer.ts"],"names":[],"mappings":"AAEA,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOlE"}
@@ -0,0 +1,11 @@
1
+ const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
2
+ /** Validates a delay accepted by JavaScript timers. @internal */
3
+ export function assertTimerDelay(name, value) {
4
+ if (!Number.isSafeInteger(value) || value <= 0) {
5
+ throw new TypeError(`${name} must be a positive finite integer, got ${value}`);
6
+ }
7
+ if (value > MAX_TIMER_DELAY_MS) {
8
+ throw new TypeError(`${name} must be at most ${MAX_TIMER_DELAY_MS}ms, got ${value}`);
9
+ }
10
+ }
11
+ //# sourceMappingURL=timer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timer.js","sourceRoot":"","sources":["../../../src/background-tasks/timer.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;AAEtC,iEAAiE;AACjE,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,KAAa;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,2CAA2C,KAAK,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,IAAI,KAAK,GAAG,kBAAkB,EAAE,CAAC;QAC/B,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,oBAAoB,kBAAkB,WAAW,KAAK,EAAE,CAAC,CAAA;IACtF,CAAC;AACH,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { Interrupt } from '../interrupt.js';
2
+ import type { Tool } from '../tools/tool.js';
3
+ import type { ToolResultContentData } from '../types/messages.js';
4
+ /** Configures background tool execution. */
5
+ export interface BackgroundTasksConfig {
6
+ /** Wait for background work before an invocation returns. Defaults to `true`. */
7
+ readonly waitForCompletion?: boolean;
8
+ /** Tools or registered tool names whose execution mode is selected by the model. Defaults to `['*']`. */
9
+ readonly agentic?: readonly (Tool | string)[];
10
+ /** Tools or registered tool names that always execute in the background. */
11
+ readonly always?: readonly (Tool | string)[];
12
+ /** Tools or registered tool names that never execute in the background. */
13
+ readonly never?: readonly (Tool | string)[];
14
+ /** Maximum number of physically executing background tasks. Defaults to `4`. */
15
+ readonly maxConcurrency?: number;
16
+ /** Per-execution timeout in milliseconds. Defaults to `Infinity`. */
17
+ readonly timeout?: number;
18
+ }
19
+ /** Background task lifecycle status. @internal */
20
+ export type BackgroundTaskStatus = 'queued' | 'working' | 'input_required' | 'completed' | 'failed' | 'cancelled';
21
+ /** Background task failure category. @internal */
22
+ export type BackgroundTaskFailureType = 'toolError' | 'executionError' | 'timeout';
23
+ /** Read-only snapshot of a background task. @internal */
24
+ export interface BackgroundTask {
25
+ /** Stable identifier for task inspection and cancellation. */
26
+ readonly taskId: string;
27
+ /** Tool-use identifier from the original model request. */
28
+ readonly toolUseId: string;
29
+ /** Tool name from the original model request. */
30
+ readonly toolName: string;
31
+ /** Current task lifecycle status. */
32
+ readonly status: BackgroundTaskStatus;
33
+ /** ISO timestamp recorded when the task was admitted. */
34
+ readonly createdAt: string;
35
+ /** ISO timestamp recorded at the latest task state change. */
36
+ readonly lastUpdatedAt: string;
37
+ /** Tool result when execution produced one. */
38
+ readonly result?: {
39
+ /** Tool-result content blocks. */
40
+ readonly content: readonly ToolResultContentData[];
41
+ };
42
+ /** Task failure details. */
43
+ readonly error?: {
44
+ /** Failure category. */
45
+ readonly type: BackgroundTaskFailureType;
46
+ /** Failure message. */
47
+ readonly message: string;
48
+ };
49
+ /** Unanswered interrupts when the task requires input. */
50
+ readonly interrupts?: readonly Readonly<Interrupt>[];
51
+ }
52
+ /**
53
+ * Checks whether a background task status is terminal.
54
+ *
55
+ * @param status - Status to check.
56
+ * @returns Whether the status is terminal.
57
+ * @internal
58
+ */
59
+ export declare function isTaskStatusTerminal(status: BackgroundTaskStatus): boolean;
60
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/background-tasks/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAEjE,4CAA4C;AAC5C,MAAM,WAAW,qBAAqB;IACpC,iFAAiF;IACjF,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IACpC,yGAAyG;IACzG,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,CAAA;IAC7C,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,CAAA;IAC5C,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,CAAA;IAC3C,gFAAgF;IAChF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,gBAAgB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAA;AAEjH,kDAAkD;AAClD,MAAM,MAAM,yBAAyB,GAAG,WAAW,GAAG,gBAAgB,GAAG,SAAS,CAAA;AAElF,yDAAyD;AACzD,MAAM,WAAW,cAAc;IAC7B,8DAA8D;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,iDAAiD;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAA;IACrC,yDAAyD;IACzD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChB,kCAAkC;QAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAA;KACnD,CAAA;IACD,4BAA4B;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE;QACf,wBAAwB;QACxB,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAA;QACxC,uBAAuB;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KACzB,CAAA;IACD,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAA;CACrD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAE1E"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks whether a background task status is terminal.
3
+ *
4
+ * @param status - Status to check.
5
+ * @returns Whether the status is terminal.
6
+ * @internal
7
+ */
8
+ export function isTaskStatusTerminal(status) {
9
+ return status === 'completed' || status === 'failed' || status === 'cancelled';
10
+ }
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/background-tasks/types.ts"],"names":[],"mappings":"AAwDA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAA4B;IAC/D,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,WAAW,CAAA;AAChF,CAAC"}
@@ -4,8 +4,10 @@
4
4
  * On overflow, runs the strategy pipeline (including an emergency truncation as the final step).
5
5
  */
6
6
  import type { Plugin } from '../plugins/plugin.js';
7
+ import type { Tool } from '../tools/tool.js';
7
8
  import type { LocalAgent } from '../types/agent.js';
8
9
  import type { ContextManagerConfig } from './types.js';
10
+ import { Stash } from './stash.js';
9
11
  /**
10
12
  * Manages context reduction for an agent's conversation.
11
13
  *
@@ -18,13 +20,32 @@ import type { ContextManagerConfig } from './types.js';
18
20
  * overflow recovery — no separate ConversationManager is needed.
19
21
  *
20
22
  * @experimental
21
- * @internal
22
23
  */
23
24
  export declare class ContextManager implements Plugin {
24
25
  readonly name = "strands:context-manager";
25
26
  private readonly _strategies;
27
+ private readonly _stashStorage;
28
+ private readonly _enableRetrievalTool;
29
+ private readonly _retrievalToolUseIds;
30
+ private _stash;
31
+ private _stashIsDurable;
32
+ private _retrievalTool;
26
33
  constructor(config?: ContextManagerConfig);
34
+ getTools(): Tool[];
27
35
  initAgent(agent: LocalAgent): void;
36
+ /**
37
+ * The L1 stash instance, if stash is enabled and the agent has been initialized.
38
+ *
39
+ * @returns The stash, or undefined if stash is disabled or initAgent has not run
40
+ */
41
+ get stash(): Stash | undefined;
42
+ /**
43
+ * Whether the stash is backed by durable storage that survives process restarts.
44
+ * When true, stash data does not need to be embedded in session snapshots.
45
+ *
46
+ * @returns true if the stash storage is not ephemeral
47
+ */
48
+ get stashIsDurable(): boolean;
28
49
  private _runStrategies;
29
50
  }
30
51
  //# sourceMappingURL=context-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context-manager.d.ts","sourceRoot":"","sources":["../../../src/context-manager/context-manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE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