deepagentsdk 0.12.0 → 0.14.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 +478 -288
  2. package/dist/adapters/elements/index.cjs.map +1 -1
  3. package/dist/adapters/elements/index.d.cts +107 -172
  4. package/dist/adapters/elements/index.d.mts +107 -172
  5. package/dist/adapters/elements/index.mjs +471 -284
  6. package/dist/adapters/elements/index.mjs.map +1 -1
  7. package/dist/{types-4g9UvXal.d.mts → agent-D0bKkNI-.d.mts} +352 -3
  8. package/dist/{types-IulnvhFg.d.cts → agent-DwAj5emJ.d.cts} +352 -3
  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
@@ -1,212 +1,147 @@
1
- import { _t as BackendProtocol, d as DeepAgentEvent } from "../../types-4g9UvXal.mjs";
2
- import { LanguageModel, ToolSet } from "ai";
3
- import "react";
1
+ import { p as DeepAgentEvent, r as ModelMessage$1, t as DeepAgent, yt as DeepAgentState } from "../../agent-D0bKkNI-.mjs";
2
+ import { UIMessage, UIMessage as UIMessage$1, UIMessagePart } from "ai";
4
3
 
5
- //#region src/adapters/elements/types.d.ts
4
+ //#region src/adapters/elements/createElementsRouteHandler.d.ts
6
5
 
7
6
  /**
8
- * Types for AI SDK Elements adapter
9
- *
10
- * These types align with Vercel AI SDK Elements UI component expectations.
11
- * @see https://ai-sdk.dev/elements
12
- */
13
- /**
14
- * UI message part types that Elements components expect
7
+ * Options for creating an Elements route handler
15
8
  */
16
- type UIMessagePart = {
17
- type: "text";
18
- text: string;
19
- } | {
20
- type: "tool-call";
21
- toolCallId: string;
22
- toolName: string;
23
- args: unknown;
24
- } | {
25
- type: "tool-result";
26
- toolCallId: string;
27
- toolName: string;
28
- result: unknown;
29
- isError?: boolean;
30
- };
31
- /**
32
- * UI message format expected by Elements Message component
33
- */
34
- interface UIMessage {
35
- id: string;
36
- role: "user" | "assistant";
37
- parts: UIMessagePart[];
38
- status: "submitted" | "streaming" | "ready" | "error";
39
- }
40
- /**
41
- * UI status that Elements components use
42
- */
43
- type UIStatus = "submitted" | "streaming" | "ready" | "error";
44
- /**
45
- * PromptInput component message format
46
- */
47
- interface PromptInputMessage {
48
- text: string;
49
- }
50
- /**
51
- * Tool parts extracted from current message for Tool component
52
- */
53
- interface ToolUIPart {
54
- type: "tool-call" | "tool-result";
55
- toolCallId: string;
56
- toolName: string;
57
- args?: unknown;
58
- result?: unknown;
59
- isError?: boolean;
60
- }
61
- /**
62
- * Return type for useElementsAdapter hook
63
- */
64
- interface UseElementsAdapterReturn {
65
- /**
66
- * Messages formatted for Elements Message component
67
- */
68
- uiMessages: UIMessage[];
69
- /**
70
- * Current UI status for Elements components
71
- */
72
- uiStatus: UIStatus;
73
- /**
74
- * Tool parts from current message for Tool component
75
- */
76
- toolParts: ToolUIPart[];
77
- /**
78
- * Send a message (compatible with PromptInput onSubmit)
79
- */
80
- sendMessage: (message: PromptInputMessage) => Promise<void>;
9
+ interface CreateElementsRouteHandlerOptions {
81
10
  /**
82
- * Abort current streaming
11
+ * The DeepAgent instance to use for handling requests
83
12
  */
84
- abort: () => void;
13
+ agent: DeepAgent;
85
14
  /**
86
- * Clear all messages
15
+ * Optional callback before processing a request.
16
+ * Use for authentication, logging, rate limiting, etc.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * onRequest: async (req) => {
21
+ * const token = req.headers.get('Authorization');
22
+ * if (!validateToken(token)) {
23
+ * throw new Error('Unauthorized');
24
+ * }
25
+ * }
26
+ * ```
87
27
  */
88
- clear: () => void;
89
- }
90
- //#endregion
91
- //#region src/adapters/elements/useElementsAdapter.d.ts
92
- /**
93
- * Options for useElementsAdapter hook
94
- */
95
- interface UseElementsAdapterOptions {
28
+ onRequest?: (req: Request) => Promise<void> | void;
96
29
  /**
97
- * Language model instance from AI SDK provider
30
+ * Optional initial state to provide to the agent.
31
+ * If not provided, uses empty state { todos: [], files: {} }
98
32
  */
99
- model: LanguageModel;
33
+ initialState?: DeepAgentState;
100
34
  /**
101
- * Backend for state management
35
+ * Optional thread ID for checkpointing.
36
+ * If provided, enables conversation persistence.
102
37
  */
103
- backend: BackendProtocol;
38
+ threadId?: string;
104
39
  /**
105
- * Optional tools to provide to the agent
106
- */
107
- tools?: ToolSet;
108
- /**
109
- * Maximum number of tool loop iterations
110
- * @default 10
40
+ * Optional maximum number of steps for the agent loop.
111
41
  */
112
42
  maxSteps?: number;
113
43
  /**
114
- * System prompt for the agent
44
+ * Custom ID generator for message IDs.
45
+ * Defaults to crypto.randomUUID if available.
115
46
  */
116
- systemPrompt?: string;
47
+ generateId?: () => string;
117
48
  }
118
49
  /**
119
- * Hook that adapts deepagentsdk to work with AI SDK Elements UI components
50
+ * Creates a route handler that processes chat requests using DeepAgent
51
+ * and streams all 26+ event types in UI Message Stream Protocol format.
52
+ *
53
+ * The returned handler:
54
+ * - Accepts POST requests with { messages: UIMessage[] } body
55
+ * - Runs DeepAgent with the conversation history
56
+ * - Streams responses in UI Message Stream Protocol format
57
+ * - Works with useChat hook from @ai-sdk/react
58
+ * - Provides full visibility into agent behavior (file ops, web requests, subagents, etc.)
120
59
  *
121
60
  * @param options - Configuration options
122
- * @returns Elements-compatible interface
61
+ * @returns A request handler function compatible with Next.js/Express
62
+ */
63
+ declare function createElementsRouteHandler(options: CreateElementsRouteHandlerOptions): (req: Request) => Promise<Response>;
64
+ /**
65
+ * Maps a DeepAgent event to a UI Message Stream Protocol event.
123
66
  *
124
- * @example
125
- * ```tsx
126
- * import { useElementsAdapter } from 'deepagentsdk/elements';
127
- * import { Conversation, Message, PromptInput } from '@/components/ai-elements';
67
+ * This function handles all 26+ DeepAgent event types, mapping:
68
+ * - Standard protocol events (text, tools, steps, errors)
69
+ * - Custom data events (file operations, web requests, subagents, execution)
128
70
  *
129
- * function Chat() {
130
- * const { uiMessages, sendMessage } = useElementsAdapter({
131
- * model,
132
- * backend
133
- * });
71
+ * @param event - The DeepAgent event to map
72
+ * @param writer - The UI message stream writer
73
+ * @param genId - ID generator function
74
+ * @param currentTextId - The current text part ID (for tracking streaming text)
75
+ * @returns The new currentTextId value (string | null)
134
76
  *
135
- * return (
136
- * <Conversation>
137
- * {uiMessages.map(msg => <Message key={msg.id} from={msg.role} />)}
138
- * <PromptInput onSubmit={sendMessage} />
139
- * </Conversation>
140
- * );
141
- * }
77
+ * @example
78
+ * ```typescript
79
+ * // Handles text streaming with proper ID tracking
80
+ * let textId: string | null = null;
81
+ * textId = mapEventToProtocol({ type: 'text', text: 'Hello' }, writer, genId, textId);
82
+ * // textId is now the ID of the active text part
142
83
  * ```
143
84
  */
144
- declare function useElementsAdapter(options: UseElementsAdapterOptions): UseElementsAdapterReturn;
145
- //#endregion
146
- //#region src/cli/hooks/useAgent.d.ts
147
- type AgentStatus = "idle" | "thinking" | "streaming" | "tool-call" | "subagent" | "done" | "error";
148
- interface AgentEventLog {
149
- id: string;
150
- type: DeepAgentEvent["type"] | "text-segment";
151
- event: DeepAgentEvent | {
152
- type: "text-segment";
153
- text: string;
154
- };
155
- timestamp: Date;
156
- }
85
+ declare function mapEventToProtocol(event: DeepAgentEvent, writer: {
86
+ write: (chunk: any) => void;
87
+ }, genId: () => string, currentTextId: string | null): string | null;
88
+ /**
89
+ * Type for the request handler returned by createElementsRouteHandler
90
+ */
91
+ type ElementsRouteHandler = (req: Request) => Promise<Response>;
157
92
  //#endregion
158
- //#region src/adapters/elements/statusAdapter.d.ts
93
+ //#region src/adapters/elements/messageConverters.d.ts
159
94
  /**
160
- * Maps deepagentsdk AgentStatus to Elements UIStatus
95
+ * Re-export AI SDK's convertToModelMessages for convenience.
96
+ *
97
+ * This function converts UIMessage[] (from useChat) to ModelMessage[]
98
+ * (for agent consumption), handling:
99
+ * - Role mapping (user/assistant)
100
+ * - Tool call/result parts
101
+ * - Text content extraction
161
102
  *
162
- * @param agentStatus - The agent status from useAgent hook
163
- * @returns The corresponding UI status for Elements components
103
+ * @example
104
+ * ```typescript
105
+ * import { convertUIMessagesToModelMessages } from 'deepagentsdk/adapters/elements';
164
106
  *
165
- * Mapping rules:
166
- * - idle/done → ready (agent is waiting for input)
167
- * - thinking/tool-call/subagent → submitted (agent is processing)
168
- * - streaming → streaming (agent is generating text)
169
- * - error → error (an error occurred)
107
+ * const modelMessages = await convertUIMessagesToModelMessages(uiMessages);
108
+ * ```
170
109
  */
171
- declare function mapAgentStatusToUIStatus(agentStatus: AgentStatus): UIStatus;
172
- //#endregion
173
- //#region src/adapters/elements/messageAdapter.d.ts
110
+ declare function convertUIMessagesToModelMessages(messages: UIMessage$1[]): Promise<ModelMessage$1[]>;
174
111
  /**
175
- * Converts agent event log to UIMessage format expected by Elements
112
+ * Extract the last user message text from a UIMessage array.
113
+ * Useful for extracting the prompt from a conversation.
176
114
  *
177
- * @param events - Array of agent events from useAgent hook
178
- * @param streamingText - Current streaming text (if any)
179
- * @param uiStatus - Current UI status
180
- * @returns Array of UIMessage objects for Elements Message component
115
+ * @param messages - Array of UI messages
116
+ * @returns The text content of the last user message, or undefined if none
117
+ */
118
+ declare function extractLastUserMessage(messages: UIMessage$1[]): string | undefined;
119
+ /**
120
+ * Check if the messages contain any tool parts.
121
+ * This is a simplified helper that checks for any tool-related parts.
122
+ *
123
+ * @param messages - Array of UI messages
124
+ * @returns True if there are any tool-related parts in the messages
125
+ */
126
+ declare function hasToolParts(messages: UIMessage$1[]): boolean;
127
+ /**
128
+ * Count the number of messages by role.
181
129
  *
182
- * Conversion logic:
183
- * 1. Group events by role (user/assistant)
184
- * 2. Convert each event type to appropriate UIMessagePart
185
- * 3. Handle streaming text as in-progress message
186
- * 4. Preserve event order and tool call/result pairing
130
+ * @param messages - Array of UI messages
131
+ * @returns Object with counts by role
187
132
  */
188
- declare function convertEventsToUIMessages(events: AgentEventLog[], streamingText: string, uiStatus: UIStatus): UIMessage[];
133
+ declare function countMessagesByRole(messages: UIMessage$1[]): {
134
+ user: number;
135
+ assistant: number;
136
+ system: number;
137
+ };
189
138
  /**
190
- * Extracts tool parts from the most recent assistant message
139
+ * Extract all text content from a message.
191
140
  *
192
- * @param messages - UIMessage array
193
- * @returns Array of tool parts (tool-call and tool-result)
141
+ * @param message - A UI message
142
+ * @returns Combined text from all text parts
194
143
  */
195
- declare function extractToolParts(messages: UIMessage[]): ({
196
- type: "tool-call";
197
- toolCallId: string;
198
- toolName: string;
199
- args: unknown;
200
- result?: undefined;
201
- isError?: undefined;
202
- } | {
203
- type: "tool-result";
204
- toolCallId: string;
205
- toolName: string;
206
- result: unknown;
207
- isError: boolean | undefined;
208
- args?: undefined;
209
- })[];
144
+ declare function extractTextFromMessage(message: UIMessage$1): string;
210
145
  //#endregion
211
- export { type PromptInputMessage, type ToolUIPart, type UIMessage, type UIMessagePart, type UIStatus, type UseElementsAdapterOptions, type UseElementsAdapterReturn, convertEventsToUIMessages, extractToolParts, mapAgentStatusToUIStatus, useElementsAdapter };
146
+ export { type CreateElementsRouteHandlerOptions, type ElementsRouteHandler, type UIMessage, type UIMessagePart, convertUIMessagesToModelMessages, countMessagesByRole, createElementsRouteHandler, extractLastUserMessage, extractTextFromMessage, hasToolParts, mapEventToProtocol };
212
147
  //# sourceMappingURL=index.d.mts.map