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.
- package/dist/adapters/elements/index.cjs +478 -288
- package/dist/adapters/elements/index.cjs.map +1 -1
- package/dist/adapters/elements/index.d.cts +107 -172
- package/dist/adapters/elements/index.d.mts +107 -172
- package/dist/adapters/elements/index.mjs +471 -284
- package/dist/adapters/elements/index.mjs.map +1 -1
- package/dist/{types-4g9UvXal.d.mts → agent-D0bKkNI-.d.mts} +352 -3
- package/dist/{types-IulnvhFg.d.cts → agent-DwAj5emJ.d.cts} +352 -3
- package/dist/{chunk-CbDLau6x.cjs → chunk-C5azi7Hr.cjs} +33 -0
- package/dist/cli/index.cjs +12 -12
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.mjs +2 -2
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{agent-Cuks-Idh.cjs → file-saver-BYPKakT4.cjs} +799 -205
- package/dist/file-saver-BYPKakT4.cjs.map +1 -0
- package/dist/{agent-CrH-He58.mjs → file-saver-Hj5so3dV.mjs} +793 -199
- package/dist/file-saver-Hj5so3dV.mjs.map +1 -0
- package/dist/index.cjs +83 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -353
- package/dist/index.d.mts +5 -353
- package/dist/index.mjs +13 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{load-B6CA5js_.mjs → load-BBYEnMwz.mjs} +1 -1
- package/dist/{load-B6CA5js_.mjs.map → load-BBYEnMwz.mjs.map} +1 -1
- package/dist/{load-94gjHorc.mjs → load-BDxe6Cet.mjs} +1 -1
- package/dist/{load-79a2H4m0.cjs → load-BrRAKlO6.cjs} +2 -2
- package/dist/{load-79a2H4m0.cjs.map → load-BrRAKlO6.cjs.map} +1 -1
- package/dist/load-DqllBbDc.cjs +4 -0
- package/package.json +1 -1
- package/dist/agent-CrH-He58.mjs.map +0 -1
- package/dist/agent-Cuks-Idh.cjs.map +0 -1
- package/dist/file-saver-BJCqMIb5.mjs +0 -655
- package/dist/file-saver-BJCqMIb5.mjs.map +0 -1
- package/dist/file-saver-C6O2LAvg.cjs +0 -679
- package/dist/file-saver-C6O2LAvg.cjs.map +0 -1
- package/dist/load-C2qVmZMp.cjs +0 -3
|
@@ -1,212 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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/
|
|
4
|
+
//#region src/adapters/elements/createElementsRouteHandler.d.ts
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
11
|
+
* The DeepAgent instance to use for handling requests
|
|
83
12
|
*/
|
|
84
|
-
|
|
13
|
+
agent: DeepAgent;
|
|
85
14
|
/**
|
|
86
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
30
|
+
* Optional initial state to provide to the agent.
|
|
31
|
+
* If not provided, uses empty state { todos: [], files: {} }
|
|
98
32
|
*/
|
|
99
|
-
|
|
33
|
+
initialState?: DeepAgentState;
|
|
100
34
|
/**
|
|
101
|
-
*
|
|
35
|
+
* Optional thread ID for checkpointing.
|
|
36
|
+
* If provided, enables conversation persistence.
|
|
102
37
|
*/
|
|
103
|
-
|
|
38
|
+
threadId?: string;
|
|
104
39
|
/**
|
|
105
|
-
* Optional
|
|
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
|
-
*
|
|
44
|
+
* Custom ID generator for message IDs.
|
|
45
|
+
* Defaults to crypto.randomUUID if available.
|
|
115
46
|
*/
|
|
116
|
-
|
|
47
|
+
generateId?: () => string;
|
|
117
48
|
}
|
|
118
49
|
/**
|
|
119
|
-
*
|
|
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
|
|
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
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
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
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
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
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
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
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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/
|
|
93
|
+
//#region src/adapters/elements/messageConverters.d.ts
|
|
159
94
|
/**
|
|
160
|
-
*
|
|
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
|
-
* @
|
|
163
|
-
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { convertUIMessagesToModelMessages } from 'deepagentsdk/adapters/elements';
|
|
164
106
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
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
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/adapters/elements/messageAdapter.d.ts
|
|
110
|
+
declare function convertUIMessagesToModelMessages(messages: UIMessage$1[]): Promise<ModelMessage$1[]>;
|
|
174
111
|
/**
|
|
175
|
-
*
|
|
112
|
+
* Extract the last user message text from a UIMessage array.
|
|
113
|
+
* Useful for extracting the prompt from a conversation.
|
|
176
114
|
*
|
|
177
|
-
* @param
|
|
178
|
-
* @
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
*
|
|
183
|
-
*
|
|
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
|
|
133
|
+
declare function countMessagesByRole(messages: UIMessage$1[]): {
|
|
134
|
+
user: number;
|
|
135
|
+
assistant: number;
|
|
136
|
+
system: number;
|
|
137
|
+
};
|
|
189
138
|
/**
|
|
190
|
-
*
|
|
139
|
+
* Extract all text content from a message.
|
|
191
140
|
*
|
|
192
|
-
* @param
|
|
193
|
-
* @returns
|
|
141
|
+
* @param message - A UI message
|
|
142
|
+
* @returns Combined text from all text parts
|
|
194
143
|
*/
|
|
195
|
-
declare function
|
|
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
|
|
146
|
+
export { type CreateElementsRouteHandlerOptions, type ElementsRouteHandler, type UIMessage, type UIMessagePart, convertUIMessagesToModelMessages, countMessagesByRole, createElementsRouteHandler, extractLastUserMessage, extractTextFromMessage, hasToolParts, mapEventToProtocol };
|
|
212
147
|
//# sourceMappingURL=index.d.mts.map
|