deepagentsdk 0.9.2
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.
- package/LICENSE +21 -0
- package/README.md +159 -0
- package/package.json +95 -0
- package/src/agent.ts +1230 -0
- package/src/backends/composite.ts +273 -0
- package/src/backends/filesystem.ts +692 -0
- package/src/backends/index.ts +22 -0
- package/src/backends/local-sandbox.ts +175 -0
- package/src/backends/persistent.ts +593 -0
- package/src/backends/sandbox.ts +510 -0
- package/src/backends/state.ts +244 -0
- package/src/backends/utils.ts +287 -0
- package/src/checkpointer/file-saver.ts +98 -0
- package/src/checkpointer/index.ts +5 -0
- package/src/checkpointer/kv-saver.ts +82 -0
- package/src/checkpointer/memory-saver.ts +82 -0
- package/src/checkpointer/types.ts +125 -0
- package/src/cli/components/ApiKeyInput.tsx +300 -0
- package/src/cli/components/FilePreview.tsx +237 -0
- package/src/cli/components/Input.tsx +277 -0
- package/src/cli/components/Message.tsx +93 -0
- package/src/cli/components/ModelSelection.tsx +338 -0
- package/src/cli/components/SlashMenu.tsx +101 -0
- package/src/cli/components/StatusBar.tsx +89 -0
- package/src/cli/components/Subagent.tsx +91 -0
- package/src/cli/components/TodoList.tsx +133 -0
- package/src/cli/components/ToolApproval.tsx +70 -0
- package/src/cli/components/ToolCall.tsx +144 -0
- package/src/cli/components/ToolCallSummary.tsx +175 -0
- package/src/cli/components/Welcome.tsx +75 -0
- package/src/cli/components/index.ts +24 -0
- package/src/cli/hooks/index.ts +12 -0
- package/src/cli/hooks/useAgent.ts +933 -0
- package/src/cli/index.tsx +1066 -0
- package/src/cli/theme.ts +205 -0
- package/src/cli/utils/model-list.ts +365 -0
- package/src/constants/errors.ts +29 -0
- package/src/constants/limits.ts +195 -0
- package/src/index.ts +176 -0
- package/src/middleware/agent-memory.ts +330 -0
- package/src/prompts.ts +196 -0
- package/src/skills/index.ts +2 -0
- package/src/skills/load.ts +191 -0
- package/src/skills/types.ts +53 -0
- package/src/tools/execute.ts +167 -0
- package/src/tools/filesystem.ts +418 -0
- package/src/tools/index.ts +39 -0
- package/src/tools/subagent.ts +443 -0
- package/src/tools/todos.ts +101 -0
- package/src/tools/web.ts +567 -0
- package/src/types/backend.ts +177 -0
- package/src/types/core.ts +220 -0
- package/src/types/events.ts +429 -0
- package/src/types/index.ts +94 -0
- package/src/types/structured-output.ts +43 -0
- package/src/types/subagent.ts +96 -0
- package/src/types.ts +22 -0
- package/src/utils/approval.ts +213 -0
- package/src/utils/events.ts +416 -0
- package/src/utils/eviction.ts +181 -0
- package/src/utils/index.ts +34 -0
- package/src/utils/model-parser.ts +38 -0
- package/src/utils/patch-tool-calls.ts +233 -0
- package/src/utils/project-detection.ts +32 -0
- package/src/utils/summarization.ts +254 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import type { TodoItem } from "./core.js";
|
|
2
|
+
import type { DeepAgentState } from "./backend.js";
|
|
3
|
+
import type { ModelMessage } from "ai";
|
|
4
|
+
import type { ResumeOptions } from "../checkpointer/types.js";
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Event Types for Streaming
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Event emitted when text is streamed from the agent.
|
|
12
|
+
*/
|
|
13
|
+
export interface TextEvent {
|
|
14
|
+
type: "text";
|
|
15
|
+
text: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Event emitted when a step starts.
|
|
20
|
+
*/
|
|
21
|
+
export interface StepStartEvent {
|
|
22
|
+
type: "step-start";
|
|
23
|
+
stepNumber: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Event emitted when a step finishes.
|
|
28
|
+
*/
|
|
29
|
+
export interface StepFinishEvent {
|
|
30
|
+
type: "step-finish";
|
|
31
|
+
stepNumber: number;
|
|
32
|
+
toolCalls: Array<{
|
|
33
|
+
toolName: string;
|
|
34
|
+
args: unknown;
|
|
35
|
+
result: unknown;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Event emitted when a tool is called.
|
|
41
|
+
*/
|
|
42
|
+
export interface ToolCallEvent {
|
|
43
|
+
type: "tool-call";
|
|
44
|
+
toolName: string;
|
|
45
|
+
toolCallId: string;
|
|
46
|
+
args: unknown;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Event emitted when a tool returns a result.
|
|
51
|
+
*/
|
|
52
|
+
export interface ToolResultEvent {
|
|
53
|
+
type: "tool-result";
|
|
54
|
+
toolName: string;
|
|
55
|
+
toolCallId: string;
|
|
56
|
+
result: unknown;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Event emitted when the todo list changes.
|
|
61
|
+
*/
|
|
62
|
+
export interface TodosChangedEvent {
|
|
63
|
+
type: "todos-changed";
|
|
64
|
+
todos: TodoItem[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Event emitted when a file write starts (for preview).
|
|
69
|
+
*/
|
|
70
|
+
export interface FileWriteStartEvent {
|
|
71
|
+
type: "file-write-start";
|
|
72
|
+
path: string;
|
|
73
|
+
content: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Event emitted when a file is written.
|
|
78
|
+
*/
|
|
79
|
+
export interface FileWrittenEvent {
|
|
80
|
+
type: "file-written";
|
|
81
|
+
path: string;
|
|
82
|
+
content: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Event emitted when a file is edited.
|
|
87
|
+
*/
|
|
88
|
+
export interface FileEditedEvent {
|
|
89
|
+
type: "file-edited";
|
|
90
|
+
path: string;
|
|
91
|
+
occurrences: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Event emitted when a file is read.
|
|
96
|
+
*/
|
|
97
|
+
export interface FileReadEvent {
|
|
98
|
+
type: "file-read";
|
|
99
|
+
path: string;
|
|
100
|
+
/** Number of lines read */
|
|
101
|
+
lines: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Event emitted when listing directory contents.
|
|
106
|
+
*/
|
|
107
|
+
export interface LsEvent {
|
|
108
|
+
type: "ls";
|
|
109
|
+
path: string;
|
|
110
|
+
/** Number of items found */
|
|
111
|
+
count: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Event emitted when searching with glob pattern.
|
|
116
|
+
*/
|
|
117
|
+
export interface GlobEvent {
|
|
118
|
+
type: "glob";
|
|
119
|
+
pattern: string;
|
|
120
|
+
/** Number of files found */
|
|
121
|
+
count: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Event emitted when searching with grep.
|
|
126
|
+
*/
|
|
127
|
+
export interface GrepEvent {
|
|
128
|
+
type: "grep";
|
|
129
|
+
pattern: string;
|
|
130
|
+
/** Number of matches found */
|
|
131
|
+
count: number;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Event emitted when a command execution starts.
|
|
136
|
+
*/
|
|
137
|
+
export interface ExecuteStartEvent {
|
|
138
|
+
type: "execute-start";
|
|
139
|
+
/** The command being executed */
|
|
140
|
+
command: string;
|
|
141
|
+
/** The sandbox ID where the command is running */
|
|
142
|
+
sandboxId: string;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Event emitted when a command execution finishes.
|
|
147
|
+
*/
|
|
148
|
+
export interface ExecuteFinishEvent {
|
|
149
|
+
type: "execute-finish";
|
|
150
|
+
/** The command that was executed */
|
|
151
|
+
command: string;
|
|
152
|
+
/** Exit code (0 = success, non-zero = failure, null = unknown/timeout) */
|
|
153
|
+
exitCode: number | null;
|
|
154
|
+
/** Whether the output was truncated */
|
|
155
|
+
truncated: boolean;
|
|
156
|
+
/** The sandbox ID where the command ran */
|
|
157
|
+
sandboxId: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Event emitted when a web search starts.
|
|
162
|
+
*/
|
|
163
|
+
export interface WebSearchStartEvent {
|
|
164
|
+
type: "web-search-start";
|
|
165
|
+
/** The search query */
|
|
166
|
+
query: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Event emitted when a web search finishes.
|
|
171
|
+
*/
|
|
172
|
+
export interface WebSearchFinishEvent {
|
|
173
|
+
type: "web-search-finish";
|
|
174
|
+
/** The search query */
|
|
175
|
+
query: string;
|
|
176
|
+
/** Number of results returned */
|
|
177
|
+
resultCount: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Event emitted when an HTTP request starts.
|
|
182
|
+
*/
|
|
183
|
+
export interface HttpRequestStartEvent {
|
|
184
|
+
type: "http-request-start";
|
|
185
|
+
/** The request URL */
|
|
186
|
+
url: string;
|
|
187
|
+
/** HTTP method (GET, POST, etc.) */
|
|
188
|
+
method: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Event emitted when an HTTP request finishes.
|
|
193
|
+
*/
|
|
194
|
+
export interface HttpRequestFinishEvent {
|
|
195
|
+
type: "http-request-finish";
|
|
196
|
+
/** The request URL */
|
|
197
|
+
url: string;
|
|
198
|
+
/** HTTP status code */
|
|
199
|
+
statusCode: number;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Event emitted when a URL fetch starts.
|
|
204
|
+
*/
|
|
205
|
+
export interface FetchUrlStartEvent {
|
|
206
|
+
type: "fetch-url-start";
|
|
207
|
+
/** The URL being fetched */
|
|
208
|
+
url: string;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Event emitted when a URL fetch finishes.
|
|
213
|
+
*/
|
|
214
|
+
export interface FetchUrlFinishEvent {
|
|
215
|
+
type: "fetch-url-finish";
|
|
216
|
+
/** The URL that was fetched */
|
|
217
|
+
url: string;
|
|
218
|
+
/** Whether extraction was successful */
|
|
219
|
+
success: boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Event emitted when a subagent starts.
|
|
224
|
+
*/
|
|
225
|
+
export interface SubagentStartEvent {
|
|
226
|
+
type: "subagent-start";
|
|
227
|
+
name: string;
|
|
228
|
+
task: string;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Event emitted when a subagent finishes.
|
|
233
|
+
*/
|
|
234
|
+
export interface SubagentFinishEvent {
|
|
235
|
+
type: "subagent-finish";
|
|
236
|
+
name: string;
|
|
237
|
+
result: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Event emitted when a subagent completes a step with tool calls.
|
|
242
|
+
*/
|
|
243
|
+
export interface SubagentStepEvent {
|
|
244
|
+
type: "subagent-step";
|
|
245
|
+
stepIndex: number;
|
|
246
|
+
toolCalls: Array<{
|
|
247
|
+
toolName: string;
|
|
248
|
+
args: any;
|
|
249
|
+
result: any;
|
|
250
|
+
}>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Event emitted for a segment of text (used for CLI display).
|
|
255
|
+
* Text segments are flushed before tool events to maintain chronological order.
|
|
256
|
+
*/
|
|
257
|
+
export interface TextSegmentEvent {
|
|
258
|
+
type: "text-segment";
|
|
259
|
+
text: string;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Event emitted when a user sends a message (used for CLI history).
|
|
264
|
+
*/
|
|
265
|
+
export interface UserMessageEvent {
|
|
266
|
+
type: "user-message";
|
|
267
|
+
content: string;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Event emitted when the agent is done.
|
|
272
|
+
*/
|
|
273
|
+
export interface DoneEvent {
|
|
274
|
+
type: "done";
|
|
275
|
+
state: DeepAgentState;
|
|
276
|
+
text?: string;
|
|
277
|
+
/** Updated conversation history including the assistant's response */
|
|
278
|
+
messages?: ModelMessage[];
|
|
279
|
+
/** Structured output if schema was provided (validated by Zod) */
|
|
280
|
+
output?: unknown; // Will be typed based on schema at call site
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Event emitted when an error occurs.
|
|
285
|
+
*/
|
|
286
|
+
export interface ErrorEvent {
|
|
287
|
+
type: "error";
|
|
288
|
+
error: Error;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Event emitted when a tool requires approval before execution.
|
|
293
|
+
*/
|
|
294
|
+
export interface ApprovalRequestedEvent {
|
|
295
|
+
type: "approval-requested";
|
|
296
|
+
/** Unique ID for this approval request */
|
|
297
|
+
approvalId: string;
|
|
298
|
+
/** The tool call ID */
|
|
299
|
+
toolCallId: string;
|
|
300
|
+
/** Name of the tool requiring approval */
|
|
301
|
+
toolName: string;
|
|
302
|
+
/** Arguments that will be passed to the tool */
|
|
303
|
+
args: unknown;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Event emitted when user responds to an approval request.
|
|
308
|
+
*/
|
|
309
|
+
export interface ApprovalResponseEvent {
|
|
310
|
+
type: "approval-response";
|
|
311
|
+
/** The approval ID being responded to */
|
|
312
|
+
approvalId: string;
|
|
313
|
+
/** Whether the tool was approved */
|
|
314
|
+
approved: boolean;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Event emitted when a checkpoint is saved.
|
|
319
|
+
*/
|
|
320
|
+
export interface CheckpointSavedEvent {
|
|
321
|
+
type: "checkpoint-saved";
|
|
322
|
+
/** Thread ID */
|
|
323
|
+
threadId: string;
|
|
324
|
+
/** Step number */
|
|
325
|
+
step: number;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Event emitted when a checkpoint is loaded.
|
|
330
|
+
*/
|
|
331
|
+
export interface CheckpointLoadedEvent {
|
|
332
|
+
type: "checkpoint-loaded";
|
|
333
|
+
/** Thread ID */
|
|
334
|
+
threadId: string;
|
|
335
|
+
/** Step number from loaded checkpoint */
|
|
336
|
+
step: number;
|
|
337
|
+
/** Number of messages restored */
|
|
338
|
+
messagesCount: number;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Union type of all possible Deep Agent events.
|
|
343
|
+
*/
|
|
344
|
+
export type DeepAgentEvent =
|
|
345
|
+
| TextEvent
|
|
346
|
+
| StepStartEvent
|
|
347
|
+
| StepFinishEvent
|
|
348
|
+
| ToolCallEvent
|
|
349
|
+
| ToolResultEvent
|
|
350
|
+
| TodosChangedEvent
|
|
351
|
+
| FileWriteStartEvent
|
|
352
|
+
| FileWrittenEvent
|
|
353
|
+
| FileEditedEvent
|
|
354
|
+
| FileReadEvent
|
|
355
|
+
| LsEvent
|
|
356
|
+
| GlobEvent
|
|
357
|
+
| GrepEvent
|
|
358
|
+
| ExecuteStartEvent
|
|
359
|
+
| ExecuteFinishEvent
|
|
360
|
+
| WebSearchStartEvent
|
|
361
|
+
| WebSearchFinishEvent
|
|
362
|
+
| HttpRequestStartEvent
|
|
363
|
+
| HttpRequestFinishEvent
|
|
364
|
+
| FetchUrlStartEvent
|
|
365
|
+
| FetchUrlFinishEvent
|
|
366
|
+
| SubagentStartEvent
|
|
367
|
+
| SubagentFinishEvent
|
|
368
|
+
| SubagentStepEvent
|
|
369
|
+
| TextSegmentEvent
|
|
370
|
+
| UserMessageEvent
|
|
371
|
+
| ApprovalRequestedEvent
|
|
372
|
+
| ApprovalResponseEvent
|
|
373
|
+
| CheckpointSavedEvent
|
|
374
|
+
| CheckpointLoadedEvent
|
|
375
|
+
| DoneEvent
|
|
376
|
+
| ErrorEvent;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Callback function for handling Deep Agent events.
|
|
380
|
+
*/
|
|
381
|
+
export type EventCallback = (event: DeepAgentEvent) => void;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Context passed to tools for emitting events.
|
|
385
|
+
*/
|
|
386
|
+
export interface ToolEventContext {
|
|
387
|
+
emit: EventCallback;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Options for streamWithEvents method.
|
|
392
|
+
*/
|
|
393
|
+
export interface StreamWithEventsOptions {
|
|
394
|
+
/** @deprecated Use messages instead for better conversation context support */
|
|
395
|
+
/** The user's prompt/message */
|
|
396
|
+
prompt?: string; // Make optional for resume-only calls
|
|
397
|
+
/** Maximum number of steps for the agent loop */
|
|
398
|
+
maxSteps?: number;
|
|
399
|
+
/** Shared state for todos and files */
|
|
400
|
+
state?: DeepAgentState;
|
|
401
|
+
/** Conversation history for multi-turn conversations. Takes precedence over prompt. */
|
|
402
|
+
messages?: ModelMessage[];
|
|
403
|
+
/** Signal to abort the generation */
|
|
404
|
+
abortSignal?: AbortSignal;
|
|
405
|
+
/**
|
|
406
|
+
* Thread ID for checkpoint persistence.
|
|
407
|
+
* When provided with a checkpointer, enables:
|
|
408
|
+
* - Auto-saving checkpoints after each step
|
|
409
|
+
* - Loading previous conversation state on start
|
|
410
|
+
* - Resume from interrupts
|
|
411
|
+
*/
|
|
412
|
+
threadId?: string;
|
|
413
|
+
/**
|
|
414
|
+
* Resume options for continuing from an interrupt.
|
|
415
|
+
* Use when resuming from a tool approval request.
|
|
416
|
+
*/
|
|
417
|
+
resume?: ResumeOptions;
|
|
418
|
+
/**
|
|
419
|
+
* Callback to handle tool approval requests.
|
|
420
|
+
* Return true to approve, false to deny.
|
|
421
|
+
* If not provided, tools requiring approval will be auto-denied.
|
|
422
|
+
*/
|
|
423
|
+
onApprovalRequest?: (request: {
|
|
424
|
+
approvalId: string;
|
|
425
|
+
toolCallId: string;
|
|
426
|
+
toolName: string;
|
|
427
|
+
args: unknown;
|
|
428
|
+
}) => Promise<boolean>;
|
|
429
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Re-export all types from modular files for backward compatibility
|
|
2
|
+
export type { ModelMessage, LanguageModel } from "ai";
|
|
3
|
+
|
|
4
|
+
// Core types
|
|
5
|
+
export type {
|
|
6
|
+
AgentMemoryOptions,
|
|
7
|
+
TodoItem,
|
|
8
|
+
DeepAgentToolChoice,
|
|
9
|
+
PrepareStepResult,
|
|
10
|
+
PrepareStepArgs,
|
|
11
|
+
PrepareStepFunction,
|
|
12
|
+
LoopControlOptions,
|
|
13
|
+
GenerationOptions,
|
|
14
|
+
AdvancedAgentOptions,
|
|
15
|
+
SummarizationConfig,
|
|
16
|
+
CreateDeepAgentParams,
|
|
17
|
+
} from "./core.js";
|
|
18
|
+
|
|
19
|
+
// Backend types
|
|
20
|
+
export type {
|
|
21
|
+
FileData,
|
|
22
|
+
FileInfo,
|
|
23
|
+
GrepMatch,
|
|
24
|
+
WriteResult,
|
|
25
|
+
EditResult,
|
|
26
|
+
DeepAgentState,
|
|
27
|
+
BackendProtocol,
|
|
28
|
+
BackendFactory,
|
|
29
|
+
ExecuteResponse,
|
|
30
|
+
SandboxBackendProtocol,
|
|
31
|
+
} from "./backend.js";
|
|
32
|
+
|
|
33
|
+
export { isSandboxBackend } from "./backend.js";
|
|
34
|
+
|
|
35
|
+
// Event types
|
|
36
|
+
export type {
|
|
37
|
+
TextEvent,
|
|
38
|
+
StepStartEvent,
|
|
39
|
+
StepFinishEvent,
|
|
40
|
+
ToolCallEvent,
|
|
41
|
+
ToolResultEvent,
|
|
42
|
+
TodosChangedEvent,
|
|
43
|
+
FileWriteStartEvent,
|
|
44
|
+
FileWrittenEvent,
|
|
45
|
+
FileEditedEvent,
|
|
46
|
+
FileReadEvent,
|
|
47
|
+
LsEvent,
|
|
48
|
+
GlobEvent,
|
|
49
|
+
GrepEvent,
|
|
50
|
+
ExecuteStartEvent,
|
|
51
|
+
ExecuteFinishEvent,
|
|
52
|
+
WebSearchStartEvent,
|
|
53
|
+
WebSearchFinishEvent,
|
|
54
|
+
HttpRequestStartEvent,
|
|
55
|
+
HttpRequestFinishEvent,
|
|
56
|
+
FetchUrlStartEvent,
|
|
57
|
+
FetchUrlFinishEvent,
|
|
58
|
+
SubagentStartEvent,
|
|
59
|
+
SubagentFinishEvent,
|
|
60
|
+
SubagentStepEvent,
|
|
61
|
+
TextSegmentEvent,
|
|
62
|
+
UserMessageEvent,
|
|
63
|
+
ApprovalRequestedEvent,
|
|
64
|
+
ApprovalResponseEvent,
|
|
65
|
+
CheckpointSavedEvent,
|
|
66
|
+
CheckpointLoadedEvent,
|
|
67
|
+
DoneEvent,
|
|
68
|
+
ErrorEvent,
|
|
69
|
+
DeepAgentEvent,
|
|
70
|
+
EventCallback,
|
|
71
|
+
ToolEventContext,
|
|
72
|
+
StreamWithEventsOptions,
|
|
73
|
+
} from "./events.js";
|
|
74
|
+
|
|
75
|
+
// Subagent types
|
|
76
|
+
export type {
|
|
77
|
+
DynamicApprovalConfig,
|
|
78
|
+
InterruptOnConfig,
|
|
79
|
+
BuiltinToolCreator,
|
|
80
|
+
SubagentToolConfig,
|
|
81
|
+
SubAgent,
|
|
82
|
+
} from "./subagent.js";
|
|
83
|
+
|
|
84
|
+
// Structured output types
|
|
85
|
+
export type {
|
|
86
|
+
StructuredAgentResult,
|
|
87
|
+
} from "./structured-output.js";
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
hasStructuredOutput,
|
|
91
|
+
eventHasStructuredOutput,
|
|
92
|
+
getStructuredOutput,
|
|
93
|
+
getEventOutput,
|
|
94
|
+
} from "./structured-output.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Zod import removed - not needed for these utility functions
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for agent results that include structured output
|
|
5
|
+
*/
|
|
6
|
+
export interface StructuredAgentResult<T = unknown> {
|
|
7
|
+
text: string;
|
|
8
|
+
output?: T;
|
|
9
|
+
state?: any; // DeepAgentState from core types
|
|
10
|
+
messages?: any[]; // ModelMessage array
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Type guard for checking if a result has structured output
|
|
15
|
+
*/
|
|
16
|
+
export function hasStructuredOutput<T>(
|
|
17
|
+
result: any
|
|
18
|
+
): result is StructuredAgentResult<T> {
|
|
19
|
+
return result && typeof result === "object" && "output" in result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for checking if an event has structured output
|
|
24
|
+
*/
|
|
25
|
+
export function eventHasStructuredOutput<T>(
|
|
26
|
+
event: any
|
|
27
|
+
): event is { type: "done"; output: T } {
|
|
28
|
+
return event && event.type === "done" && "output" in event;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extract structured output from agent result with type safety
|
|
33
|
+
*/
|
|
34
|
+
export function getStructuredOutput<T>(result: any): T | undefined {
|
|
35
|
+
return hasStructuredOutput<T>(result) ? result.output : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Extract structured output from event with type safety
|
|
40
|
+
*/
|
|
41
|
+
export function getEventOutput<T>(event: any): T | undefined {
|
|
42
|
+
return eventHasStructuredOutput<T>(event) ? event.output : undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subagent infrastructure types.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ToolSet, LanguageModel } from "ai";
|
|
6
|
+
import type { z } from "zod";
|
|
7
|
+
import type { GenerationOptions, AdvancedAgentOptions } from "./core.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for dynamic tool approval.
|
|
11
|
+
*/
|
|
12
|
+
export interface DynamicApprovalConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Function to determine if approval is needed based on tool arguments.
|
|
15
|
+
*/
|
|
16
|
+
shouldApprove?: (args: unknown) => boolean | Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for human-in-the-loop tool approval.
|
|
21
|
+
*/
|
|
22
|
+
export type InterruptOnConfig = Record<string, boolean | DynamicApprovalConfig>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type for builtin tool creator functions.
|
|
26
|
+
*/
|
|
27
|
+
export type BuiltinToolCreator =
|
|
28
|
+
| typeof import("../tools/web.js").createWebSearchTool
|
|
29
|
+
| typeof import("../tools/web.js").createHttpRequestTool
|
|
30
|
+
| typeof import("../tools/web.js").createFetchUrlTool
|
|
31
|
+
| typeof import("../tools/filesystem.js").createLsTool
|
|
32
|
+
| typeof import("../tools/filesystem.js").createReadFileTool
|
|
33
|
+
| typeof import("../tools/filesystem.js").createWriteFileTool
|
|
34
|
+
| typeof import("../tools/filesystem.js").createEditFileTool
|
|
35
|
+
| typeof import("../tools/filesystem.js").createGlobTool
|
|
36
|
+
| typeof import("../tools/filesystem.js").createGrepTool
|
|
37
|
+
| typeof import("../tools/todos.js").createTodosTool
|
|
38
|
+
| typeof import("../tools/execute.js").createExecuteTool;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Union type for subagent tool configuration.
|
|
42
|
+
*/
|
|
43
|
+
export type SubagentToolConfig = ToolSet | BuiltinToolCreator;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* SubAgent specification for task delegation.
|
|
47
|
+
*/
|
|
48
|
+
export interface SubAgent {
|
|
49
|
+
/**
|
|
50
|
+
* Unique name identifier for the subagent.
|
|
51
|
+
*/
|
|
52
|
+
name: string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Description shown to the main agent when deciding which subagent to use.
|
|
56
|
+
*/
|
|
57
|
+
description: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* System prompt that defines the subagent's behavior and instructions.
|
|
61
|
+
*/
|
|
62
|
+
systemPrompt: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Optional custom tools available only to this subagent.
|
|
66
|
+
*/
|
|
67
|
+
tools?: ToolSet | SubagentToolConfig[];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Optional model override for this subagent.
|
|
71
|
+
*/
|
|
72
|
+
model?: LanguageModel;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Optional interrupt configuration for this subagent.
|
|
76
|
+
*/
|
|
77
|
+
interruptOn?: InterruptOnConfig;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Optional structured output configuration for this subagent.
|
|
81
|
+
*/
|
|
82
|
+
output?: {
|
|
83
|
+
schema: z.ZodType<any>;
|
|
84
|
+
description?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Advanced generation options for this subagent.
|
|
89
|
+
*/
|
|
90
|
+
generationOptions?: GenerationOptions;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Advanced agent options for this subagent.
|
|
94
|
+
*/
|
|
95
|
+
advancedOptions?: AdvancedAgentOptions;
|
|
96
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type definitions for AI SDK Deep Agent.
|
|
3
|
+
*
|
|
4
|
+
* This file re-exports all types from the modular type structure
|
|
5
|
+
* to maintain backward compatibility.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Core AI SDK types that we re-export
|
|
9
|
+
export type {
|
|
10
|
+
ToolSet,
|
|
11
|
+
ModelMessage,
|
|
12
|
+
LanguageModel,
|
|
13
|
+
LanguageModelMiddleware,
|
|
14
|
+
ToolLoopAgent,
|
|
15
|
+
StopCondition,
|
|
16
|
+
ToolLoopAgentSettings,
|
|
17
|
+
} from "ai";
|
|
18
|
+
|
|
19
|
+
export type { BaseCheckpointSaver, ResumeOptions } from "./checkpointer/types";
|
|
20
|
+
|
|
21
|
+
// Re-export all modular types
|
|
22
|
+
export * from "./types/index";
|