deepagentsdk 0.12.0 → 0.13.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 (37) hide show
  1. package/dist/adapters/elements/index.cjs +244 -294
  2. package/dist/adapters/elements/index.cjs.map +1 -1
  3. package/dist/adapters/elements/index.d.cts +84 -174
  4. package/dist/adapters/elements/index.d.mts +84 -174
  5. package/dist/adapters/elements/index.mjs +238 -290
  6. package/dist/adapters/elements/index.mjs.map +1 -1
  7. package/dist/{types-4g9UvXal.d.mts → agent-BDM-PIu8.d.mts} +374 -25
  8. package/dist/{types-IulnvhFg.d.cts → agent-DToEVxs-.d.cts} +374 -25
  9. package/dist/{chunk-CbDLau6x.cjs → chunk-C5azi7Hr.cjs} +33 -0
  10. package/dist/cli/index.cjs +12 -12
  11. package/dist/cli/index.cjs.map +1 -1
  12. package/dist/cli/index.mjs +2 -2
  13. package/dist/cli/index.mjs.map +1 -1
  14. package/dist/{agent-Cuks-Idh.cjs → file-saver-BYPKakT4.cjs} +799 -205
  15. package/dist/file-saver-BYPKakT4.cjs.map +1 -0
  16. package/dist/{agent-CrH-He58.mjs → file-saver-Hj5so3dV.mjs} +793 -199
  17. package/dist/file-saver-Hj5so3dV.mjs.map +1 -0
  18. package/dist/index.cjs +83 -73
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +5 -353
  21. package/dist/index.d.mts +5 -353
  22. package/dist/index.mjs +13 -3
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{load-B6CA5js_.mjs → load-BBYEnMwz.mjs} +1 -1
  25. package/dist/{load-B6CA5js_.mjs.map → load-BBYEnMwz.mjs.map} +1 -1
  26. package/dist/{load-94gjHorc.mjs → load-BDxe6Cet.mjs} +1 -1
  27. package/dist/{load-79a2H4m0.cjs → load-BrRAKlO6.cjs} +2 -2
  28. package/dist/{load-79a2H4m0.cjs.map → load-BrRAKlO6.cjs.map} +1 -1
  29. package/dist/load-DqllBbDc.cjs +4 -0
  30. package/package.json +1 -1
  31. package/dist/agent-CrH-He58.mjs.map +0 -1
  32. package/dist/agent-Cuks-Idh.cjs.map +0 -1
  33. package/dist/file-saver-BJCqMIb5.mjs +0 -655
  34. package/dist/file-saver-BJCqMIb5.mjs.map +0 -1
  35. package/dist/file-saver-C6O2LAvg.cjs +0 -679
  36. package/dist/file-saver-C6O2LAvg.cjs.map +0 -1
  37. package/dist/load-C2qVmZMp.cjs +0 -3
package/dist/index.d.cts CHANGED
@@ -1,357 +1,9 @@
1
- import { $ as createReadFileTool, A as TodosChangedEvent, At as InterruptData, B as InterruptOnConfig, C as HttpRequestStartEvent, Ct as GrepMatch, D as SubagentFinishEvent, Dt as BaseCheckpointSaver, E as StreamWithEventsOptions, Et as isSandboxBackend, F as AgentMemoryOptions, G as execute, H as CreateExecuteToolOptions, I as CreateDeepAgentParams, J as createEditFileTool, K as createTodosTool, L as SummarizationConfig, M as ToolResultEvent, Mt as ResumeOptions, N as WebSearchFinishEvent, O as SubagentStartEvent, Ot as Checkpoint, P as WebSearchStartEvent, Q as createLsTool, R as TodoItem, S as HttpRequestFinishEvent, St as FileInfo, T as StepStartEvent, Tt as WriteResult, U as createExecuteTool, V as SubAgent, W as createExecuteToolFromBackend, X as createGlobTool, Y as createFilesystemTools, Z as createGrepTool, _ as FetchUrlFinishEvent, _t as BackendProtocol, a as getStructuredOutput, at as read_file, b as FileWriteStartEvent, bt as ExecuteResponse, c as ApprovalResponseEvent, ct as createFetchUrlTool, d as DeepAgentEvent, dt as createWebTools, et as createWriteFileTool, f as DoneEvent, ft as fetch_url, g as ExecuteStartEvent, gt as BackendFactory, h as ExecuteFinishEvent, ht as web_search, i as getEventOutput, it as ls, j as ToolCallEvent, jt as ResumeDecision, k as TextEvent, kt as CheckpointSaverOptions, l as CheckpointLoadedEvent, lt as createHttpRequestTool, m as EventCallback, mt as http_request, n as StructuredAgentResult, nt as glob, o as hasStructuredOutput, ot as write_file, p as ErrorEvent, pt as htmlToMarkdown, q as write_todos, r as eventHasStructuredOutput, rt as grep, s as ApprovalRequestedEvent, st as CreateWebToolsOptions, t as ModelMessage$1, tt as edit_file, u as CheckpointSavedEvent, ut as createWebSearchTool, v as FetchUrlStartEvent, vt as DeepAgentState, w as StepFinishEvent, wt as SandboxBackendProtocol, x as FileWrittenEvent, xt as FileData, y as FileEditedEvent, yt as EditResult, z as DynamicApprovalConfig } from "./types-IulnvhFg.cjs";
2
- import * as ai0 from "ai";
3
- import { LanguageModel, LanguageModelMiddleware, LanguageModelMiddleware as LanguageModelMiddleware$1, ModelMessage, ToolLoopAgent, ToolLoopAgent as ToolLoopAgent$1, ToolSet, hasToolCall, stepCountIs, wrapLanguageModel } from "ai";
1
+ import { $ as createLsTool, A as TextEvent, At as CheckpointSaverOptions, B as DynamicApprovalConfig, C as FileWrittenEvent, Ct as FileInfo, D as StepStartEvent, Dt as isSandboxBackend, E as StepFinishEvent, Et as WriteResult, F as WebSearchStartEvent, G as createExecuteToolFromBackend, H as SubAgent, I as AgentMemoryOptions, J as write_todos, K as execute, L as CreateDeepAgentParams, M as ToolCallEvent, Mt as ResumeDecision, N as ToolResultEvent, Nt as ResumeOptions, O as SubagentFinishEvent, Ot as BaseCheckpointSaver, P as WebSearchFinishEvent, Q as createGrepTool, R as SummarizationConfig, S as FileWriteStartEvent, St as FileData, T as HttpRequestStartEvent, Tt as SandboxBackendProtocol, U as CreateExecuteToolOptions, V as InterruptOnConfig, W as createExecuteTool, X as createFilesystemTools, Y as createEditFileTool, Z as createGlobTool, _ as ExecuteFinishEvent, _t as BackendFactory, a as eventHasStructuredOutput, at as ls, b as FetchUrlStartEvent, bt as EditResult, c as hasStructuredOutput, ct as CreateWebToolsOptions, d as CheckpointLoadedEvent, dt as createWebSearchTool, et as createReadFileTool, f as CheckpointSavedEvent, ft as createWebTools, g as EventCallback, gt as web_search, h as ErrorEvent, ht as http_request, i as StructuredAgentResult, it as grep, j as TodosChangedEvent, jt as InterruptData, k as SubagentStartEvent, kt as Checkpoint, l as ApprovalRequestedEvent, lt as createFetchUrlTool, m as DoneEvent, mt as htmlToMarkdown, n as createDeepAgent, nt as edit_file, o as getEventOutput, ot as read_file, p as DeepAgentEvent, pt as fetch_url, q as createTodosTool, r as ModelMessage$1, rt as glob, s as getStructuredOutput, st as write_file, t as DeepAgent, tt as createWriteFileTool, u as ApprovalResponseEvent, ut as createHttpRequestTool, v as ExecuteStartEvent, vt as BackendProtocol, w as HttpRequestFinishEvent, wt as GrepMatch, x as FileEditedEvent, xt as ExecuteResponse, y as FetchUrlFinishEvent, yt as DeepAgentState, z as TodoItem } from "./agent-DToEVxs-.cjs";
2
+ import * as ai18 from "ai";
3
+ import { LanguageModel, LanguageModelMiddleware, LanguageModelMiddleware as LanguageModelMiddleware$1, ModelMessage, ToolLoopAgent, ToolSet, hasToolCall, stepCountIs, wrapLanguageModel } from "ai";
4
4
 
5
- //#region src/agent.d.ts
6
-
7
- /**
8
- * Deep Agent wrapper class that provides generate() and stream() methods.
9
- * Uses ToolLoopAgent from AI SDK v6 for the agent loop.
10
- */
11
- declare class DeepAgent {
12
- private model;
13
- private systemPrompt;
14
- private userTools;
15
- private maxSteps;
16
- private backend;
17
- private subagentOptions;
18
- private toolResultEvictionLimit?;
19
- private enablePromptCaching;
20
- private summarizationConfig?;
21
- private hasSandboxBackend;
22
- private interruptOn?;
23
- private checkpointer?;
24
- private skillsMetadata;
25
- private outputConfig?;
26
- private loopControl?;
27
- private generationOptions?;
28
- private advancedOptions?;
29
- constructor(params: CreateDeepAgentParams);
30
- /**
31
- * Create core tools (todos and filesystem).
32
- * @private
33
- */
34
- private createCoreTools;
35
- /**
36
- * Create web tools if TAVILY_API_KEY is available.
37
- * @private
38
- */
39
- private createWebToolSet;
40
- /**
41
- * Create execute tool if backend is a sandbox.
42
- * @private
43
- */
44
- private createExecuteToolSet;
45
- /**
46
- * Create subagent tool if configured.
47
- * @private
48
- */
49
- private createSubagentToolSet;
50
- /**
51
- * Create all tools for the agent, combining core, web, execute, and subagent tools.
52
- * @private
53
- */
54
- private createTools;
55
- /**
56
- * Build stop conditions with maxSteps safety limit.
57
- * Combines user-provided stop conditions with the maxSteps limit.
58
- */
59
- private buildStopConditions;
60
- /**
61
- * Build agent settings by combining passthrough options with defaults.
62
- */
63
- private buildAgentSettings;
64
- /**
65
- * Create a ToolLoopAgent for a given state.
66
- * @param state - The shared agent state
67
- * @param maxSteps - Optional max steps override
68
- * @param onEvent - Optional callback for emitting events
69
- */
70
- private createAgent;
71
- /**
72
- * Load skills from directory asynchronously.
73
- * Supports both legacy skillsDir and new agentId modes.
74
- */
75
- private loadSkills;
76
- /**
77
- * Generate a response (non-streaming).
78
- */
79
- generate(options: {
80
- prompt: string;
81
- maxSteps?: number;
82
- }): Promise<ai0.GenerateTextResult<{}, never> & {
83
- state: DeepAgentState;
84
- }>;
85
- /**
86
- * Stream a response.
87
- */
88
- stream(options: {
89
- prompt: string;
90
- maxSteps?: number;
91
- }): Promise<ai0.StreamTextResult<{}, never> & {
92
- state: DeepAgentState;
93
- }>;
94
- /**
95
- * Generate with an existing state (for continuing conversations).
96
- */
97
- generateWithState(options: {
98
- prompt: string;
99
- state: DeepAgentState;
100
- maxSteps?: number;
101
- }): Promise<ai0.GenerateTextResult<{}, never> & {
102
- state: DeepAgentState;
103
- }>;
104
- /**
105
- * Get the underlying ToolLoopAgent for advanced usage.
106
- * This allows using AI SDK's createAgentUIStream and other utilities.
107
- */
108
- getAgent(state?: DeepAgentState): ToolLoopAgent$1<never, {}, never>;
109
- /**
110
- * Stream a response with real-time events.
111
- * This is an async generator that yields DeepAgentEvent objects.
112
- *
113
- * Supports conversation history via the `messages` option for multi-turn conversations.
114
- *
115
- * @example
116
- * ```typescript
117
- * // Single turn
118
- * for await (const event of agent.streamWithEvents({ prompt: "..." })) {
119
- * switch (event.type) {
120
- * case 'text':
121
- * process.stdout.write(event.text);
122
- * break;
123
- * case 'done':
124
- * // event.messages contains the updated conversation history
125
- * console.log('Messages:', event.messages);
126
- * break;
127
- * }
128
- * }
129
- *
130
- * // Multi-turn conversation
131
- * let messages = [];
132
- * for await (const event of agent.streamWithEvents({ prompt: "Hello", messages })) {
133
- * if (event.type === 'done') {
134
- * messages = event.messages; // Save for next turn
135
- * }
136
- * }
137
- * for await (const event of agent.streamWithEvents({ prompt: "Follow up", messages })) {
138
- * // Agent now has context from previous turn
139
- * }
140
- * ```
141
- */
142
- /**
143
- * Compose user's onStepFinish callback with DeepAgent's internal checkpointing logic.
144
- * User callback executes first, errors are caught to prevent breaking checkpointing.
145
- */
146
- private composeOnStepFinish;
147
- /**
148
- * Compose user's onFinish callback with DeepAgent's internal cleanup logic.
149
- */
150
- private composeOnFinish;
151
- /**
152
- * Compose user's prepareStep callback with DeepAgent's internal step preparation.
153
- * Returns a function typed as `any` to avoid AI SDK's strict toolName inference.
154
- */
155
- private composePrepareStep;
156
- /**
157
- * Build streamText options with callbacks for step tracking and checkpointing.
158
- *
159
- * @private
160
- */
161
- private buildStreamTextOptions;
162
- /**
163
- * Build message array from options, handling validation and priority logic.
164
- * Priority: explicit messages > prompt > checkpoint history.
165
- *
166
- * @private
167
- */
168
- private buildMessageArray;
169
- /**
170
- * Load checkpoint context if threadId is provided.
171
- * Handles checkpoint restoration and resume from interrupt.
172
- *
173
- * @private
174
- */
175
- private loadCheckpointContext;
176
- streamWithEvents(options: StreamWithEventsOptions): AsyncGenerator<DeepAgentEvent, void, unknown>;
177
- /**
178
- * Stream with a simple callback interface.
179
- * This is a convenience wrapper around streamWithEvents.
180
- */
181
- streamWithCallback(options: StreamWithEventsOptions, onEvent: EventCallback): Promise<{
182
- state: DeepAgentState;
183
- text?: string;
184
- messages?: ModelMessage$1[];
185
- }>;
186
- }
187
- /**
188
- * Create a Deep Agent with planning, filesystem, and subagent capabilities.
189
- *
190
- * @param params - Configuration object for the Deep Agent
191
- * @param params.model - **Required.** AI SDK LanguageModel instance (e.g., `anthropic('claude-sonnet-4-20250514')`, `openai('gpt-4o')`)
192
- * @param params.systemPrompt - Optional custom system prompt for the agent
193
- * @param params.tools - Optional custom tools to add to the agent (AI SDK ToolSet)
194
- * @param params.subagents - Optional array of specialized subagent configurations for task delegation
195
- * @param params.backend - Optional backend for filesystem operations (default: StateBackend for in-memory storage)
196
- * @param params.maxSteps - Optional maximum number of steps for the agent loop (default: 100)
197
- * @param params.includeGeneralPurposeAgent - Optional flag to include general-purpose subagent (default: true)
198
- * @param params.toolResultEvictionLimit - Optional token limit before evicting large tool results to filesystem (default: disabled)
199
- * @param params.enablePromptCaching - Optional flag to enable prompt caching for improved performance (Anthropic only, default: false)
200
- * @param params.summarization - Optional summarization configuration for automatic conversation summarization
201
- * @returns A configured DeepAgent instance
202
- *
203
- * @see {@link CreateDeepAgentParams} for detailed parameter types
204
- *
205
- * @example Basic usage
206
- * ```typescript
207
- * import { createDeepAgent } from 'deepagentsdk';
208
- * import { anthropic } from '@ai-sdk/anthropic';
209
- *
210
- * const agent = createDeepAgent({
211
- * model: anthropic('claude-sonnet-4-20250514'),
212
- * systemPrompt: 'You are a research assistant...',
213
- * });
214
- *
215
- * const result = await agent.generate({
216
- * prompt: 'Research the topic and write a report',
217
- * });
218
- * ```
219
- *
220
- * @example With custom tools
221
- * ```typescript
222
- * import { tool } from 'ai';
223
- * import { z } from 'zod';
224
- *
225
- * const customTool = tool({
226
- * description: 'Get current time',
227
- * inputSchema: z.object({}),
228
- * execute: async () => new Date().toISOString(),
229
- * });
230
- *
231
- * const agent = createDeepAgent({
232
- * model: anthropic('claude-sonnet-4-20250514'),
233
- * tools: { get_time: customTool },
234
- * });
235
- * ```
236
- *
237
- * @example With subagents
238
- * ```typescript
239
- * const agent = createDeepAgent({
240
- * model: anthropic('claude-sonnet-4-20250514'),
241
- * subagents: [{
242
- * name: 'research-agent',
243
- * description: 'Specialized for research tasks',
244
- * systemPrompt: 'You are a research specialist...',
245
- * }],
246
- * });
247
- * ```
248
- *
249
- * @example With StateBackend (default, explicit)
250
- * ```typescript
251
- * import { StateBackend } from 'deepagentsdk';
252
- *
253
- * const state = { todos: [], files: {} };
254
- * const agent = createDeepAgent({
255
- * model: anthropic('claude-sonnet-4-20250514'),
256
- * backend: new StateBackend(state), // Ephemeral in-memory storage
257
- * });
258
- * ```
259
- *
260
- * @example With FilesystemBackend
261
- * ```typescript
262
- * import { FilesystemBackend } from 'deepagentsdk';
263
- *
264
- * const agent = createDeepAgent({
265
- * model: anthropic('claude-sonnet-4-20250514'),
266
- * backend: new FilesystemBackend({ rootDir: './workspace' }), // Persist to disk
267
- * });
268
- * ```
269
- *
270
- * @example With PersistentBackend
271
- * ```typescript
272
- * import { PersistentBackend, InMemoryStore } from 'deepagentsdk';
273
- *
274
- * const store = new InMemoryStore();
275
- * const agent = createDeepAgent({
276
- * model: anthropic('claude-sonnet-4-20250514'),
277
- * backend: new PersistentBackend({ store, namespace: 'project-1' }), // Cross-session persistence
278
- * });
279
- * ```
280
- *
281
- * @example With CompositeBackend
282
- * ```typescript
283
- * import { CompositeBackend, FilesystemBackend, StateBackend } from 'deepagentsdk';
284
- *
285
- * const state = { todos: [], files: {} };
286
- * const agent = createDeepAgent({
287
- * model: anthropic('claude-sonnet-4-20250514'),
288
- * backend: new CompositeBackend(
289
- * new StateBackend(state),
290
- * { '/persistent/': new FilesystemBackend({ rootDir: './persistent' }) }
291
- * ), // Route files by path prefix
292
- * });
293
- * ```
294
- *
295
- * @example With middleware for logging and caching
296
- * ```typescript
297
- * import { createDeepAgent } from 'deepagentsdk';
298
- * import { anthropic } from '@ai-sdk/anthropic';
299
- *
300
- * const loggingMiddleware = {
301
- * wrapGenerate: async ({ doGenerate, params }) => {
302
- * console.log('Model called with:', params.prompt);
303
- * const result = await doGenerate();
304
- * console.log('Model returned:', result.text);
305
- * return result;
306
- * },
307
- * };
308
- *
309
- * const agent = createDeepAgent({
310
- * model: anthropic('claude-sonnet-4-20250514'),
311
- * middleware: [loggingMiddleware],
312
- * });
313
- * ```
314
- *
315
- * @example With middleware factory for context access
316
- * ```typescript
317
- * import { FilesystemBackend } from 'deepagentsdk';
318
- *
319
- * function createContextMiddleware(backend: BackendProtocol) {
320
- * return {
321
- * wrapGenerate: async ({ doGenerate }) => {
322
- * const state = await backend.read('state');
323
- * const result = await doGenerate();
324
- * await backend.write('state', { ...state, lastCall: result });
325
- * return result;
326
- * },
327
- * };
328
- * }
329
- *
330
- * const backend = new FilesystemBackend({ rootDir: './workspace' });
331
- * const agent = createDeepAgent({
332
- * model: anthropic('claude-sonnet-4-20250514'),
333
- * backend,
334
- * middleware: createContextMiddleware(backend),
335
- * });
336
- * ```
337
- *
338
- * @example With performance optimizations
339
- * ```typescript
340
- * const agent = createDeepAgent({
341
- * model: anthropic('claude-sonnet-4-20250514'),
342
- * enablePromptCaching: true,
343
- * toolResultEvictionLimit: 20000,
344
- * summarization: {
345
- * enabled: true,
346
- * tokenThreshold: 170000,
347
- * keepMessages: 6,
348
- * },
349
- * });
350
- * ```
351
- */
352
- declare function createDeepAgent(params: CreateDeepAgentParams): DeepAgent;
353
- //#endregion
354
5
  //#region src/backends/state.d.ts
6
+
355
7
  /**
356
8
  * Backend that stores files in shared state (ephemeral).
357
9
  *
@@ -1085,7 +737,7 @@ interface CreateSubagentToolOptions {
1085
737
  /**
1086
738
  * Create the task tool for spawning subagents using ToolLoopAgent.
1087
739
  */
1088
- declare function createSubagentTool(state: DeepAgentState, options: CreateSubagentToolOptions): ai0.Tool<{
740
+ declare function createSubagentTool(state: DeepAgentState, options: CreateSubagentToolOptions): ai18.Tool<{
1089
741
  description: string;
1090
742
  subagent_type: string;
1091
743
  }, string>;