deepagentsdk 0.11.1 → 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.
- package/dist/adapters/elements/index.cjs +274 -0
- package/dist/adapters/elements/index.cjs.map +1 -0
- package/dist/adapters/elements/index.d.cts +122 -0
- package/dist/adapters/elements/index.d.mts +122 -0
- package/dist/adapters/elements/index.mjs +268 -0
- package/dist/adapters/elements/index.mjs.map +1 -0
- package/dist/agent-BDM-PIu8.d.mts +1500 -0
- package/dist/agent-DToEVxs-.d.cts +1500 -0
- package/dist/chunk-C5azi7Hr.cjs +67 -0
- package/dist/cli/index.cjs +3162 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +3120 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/file-saver-BYPKakT4.cjs +3990 -0
- package/dist/file-saver-BYPKakT4.cjs.map +1 -0
- package/dist/file-saver-Hj5so3dV.mjs +3568 -0
- package/dist/file-saver-Hj5so3dV.mjs.map +1 -0
- package/dist/index.cjs +1481 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1233 -0
- package/dist/index.d.mts +1233 -0
- package/dist/index.mjs +1381 -0
- package/dist/index.mjs.map +1 -0
- package/dist/load-BBYEnMwz.mjs +142 -0
- package/dist/load-BBYEnMwz.mjs.map +1 -0
- package/dist/load-BDxe6Cet.mjs +3 -0
- package/dist/load-BrRAKlO6.cjs +163 -0
- package/dist/load-BrRAKlO6.cjs.map +1 -0
- package/dist/load-DqllBbDc.cjs +4 -0
- package/package.json +26 -12
- package/src/adapters/elements/index.ts +0 -27
- package/src/adapters/elements/messageAdapter.ts +0 -165
- package/src/adapters/elements/statusAdapter.ts +0 -39
- package/src/adapters/elements/types.ts +0 -97
- package/src/adapters/elements/useElementsAdapter.ts +0 -261
- package/src/agent.ts +0 -1258
- package/src/backends/composite.ts +0 -273
- package/src/backends/filesystem.ts +0 -692
- package/src/backends/index.ts +0 -22
- package/src/backends/local-sandbox.ts +0 -175
- package/src/backends/persistent.ts +0 -593
- package/src/backends/sandbox.ts +0 -510
- package/src/backends/state.ts +0 -244
- package/src/backends/utils.ts +0 -287
- package/src/checkpointer/file-saver.ts +0 -98
- package/src/checkpointer/index.ts +0 -5
- package/src/checkpointer/kv-saver.ts +0 -82
- package/src/checkpointer/memory-saver.ts +0 -82
- package/src/checkpointer/types.ts +0 -125
- package/src/cli/components/ApiKeyInput.tsx +0 -300
- package/src/cli/components/FilePreview.tsx +0 -237
- package/src/cli/components/Input.tsx +0 -277
- package/src/cli/components/Message.tsx +0 -93
- package/src/cli/components/ModelSelection.tsx +0 -338
- package/src/cli/components/SlashMenu.tsx +0 -101
- package/src/cli/components/StatusBar.tsx +0 -89
- package/src/cli/components/Subagent.tsx +0 -91
- package/src/cli/components/TodoList.tsx +0 -133
- package/src/cli/components/ToolApproval.tsx +0 -70
- package/src/cli/components/ToolCall.tsx +0 -144
- package/src/cli/components/ToolCallSummary.tsx +0 -175
- package/src/cli/components/Welcome.tsx +0 -75
- package/src/cli/components/index.ts +0 -24
- package/src/cli/hooks/index.ts +0 -12
- package/src/cli/hooks/useAgent.ts +0 -933
- package/src/cli/index.tsx +0 -1066
- package/src/cli/theme.ts +0 -205
- package/src/cli/utils/model-list.ts +0 -365
- package/src/constants/errors.ts +0 -29
- package/src/constants/limits.ts +0 -195
- package/src/index.ts +0 -176
- package/src/middleware/agent-memory.ts +0 -330
- package/src/prompts.ts +0 -196
- package/src/skills/index.ts +0 -2
- package/src/skills/load.ts +0 -191
- package/src/skills/types.ts +0 -53
- package/src/tools/execute.ts +0 -167
- package/src/tools/filesystem.ts +0 -418
- package/src/tools/index.ts +0 -39
- package/src/tools/subagent.ts +0 -443
- package/src/tools/todos.ts +0 -101
- package/src/tools/web.ts +0 -567
- package/src/types/backend.ts +0 -177
- package/src/types/core.ts +0 -220
- package/src/types/events.ts +0 -430
- package/src/types/index.ts +0 -94
- package/src/types/structured-output.ts +0 -43
- package/src/types/subagent.ts +0 -96
- package/src/types.ts +0 -22
- package/src/utils/approval.ts +0 -213
- package/src/utils/events.ts +0 -416
- package/src/utils/eviction.ts +0 -181
- package/src/utils/index.ts +0 -34
- package/src/utils/model-parser.ts +0 -38
- package/src/utils/patch-tool-calls.ts +0 -233
- package/src/utils/project-detection.ts +0 -32
- package/src/utils/summarization.ts +0 -254
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
const require_chunk = require('../../chunk-C5azi7Hr.cjs');
|
|
2
|
+
let ai = require("ai");
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/elements/createElementsRouteHandler.ts
|
|
5
|
+
/**
|
|
6
|
+
* Server-side route handler adapter for AI SDK Elements
|
|
7
|
+
*
|
|
8
|
+
* Creates a Next.js/Express-compatible route handler that runs DeepAgent
|
|
9
|
+
* and returns UI Message Stream compatible responses for use with useChat.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // app/api/chat/route.ts (Next.js App Router)
|
|
14
|
+
* import { createDeepAgent } from 'deepagentsdk';
|
|
15
|
+
* import { createElementsRouteHandler } from 'deepagentsdk/adapters/elements';
|
|
16
|
+
* import { anthropic } from '@ai-sdk/anthropic';
|
|
17
|
+
*
|
|
18
|
+
* const agent = createDeepAgent({
|
|
19
|
+
* model: anthropic('claude-sonnet-4-20250514'),
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* export const POST = createElementsRouteHandler({ agent });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @see https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Creates a route handler that processes chat requests using DeepAgent
|
|
29
|
+
* and returns UI Message Stream compatible responses.
|
|
30
|
+
*
|
|
31
|
+
* The returned handler:
|
|
32
|
+
* - Accepts POST requests with { messages: UIMessage[] } body
|
|
33
|
+
* - Runs DeepAgent with the conversation history
|
|
34
|
+
* - Streams responses in UI Message Stream Protocol format
|
|
35
|
+
* - Works with useChat hook from @ai-sdk/react
|
|
36
|
+
*
|
|
37
|
+
* @param options - Configuration options
|
|
38
|
+
* @returns A request handler function compatible with Next.js/Express
|
|
39
|
+
*/
|
|
40
|
+
function createElementsRouteHandler(options) {
|
|
41
|
+
const { agent, onRequest, initialState = {
|
|
42
|
+
todos: [],
|
|
43
|
+
files: {}
|
|
44
|
+
}, threadId, maxSteps, generateId } = options;
|
|
45
|
+
return async (req) => {
|
|
46
|
+
if (onRequest) try {
|
|
47
|
+
await onRequest(req);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return new Response(JSON.stringify({ error: error instanceof Error ? error.message : "Request rejected" }), {
|
|
50
|
+
status: 401,
|
|
51
|
+
headers: { "Content-Type": "application/json" }
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
let requestBody;
|
|
55
|
+
try {
|
|
56
|
+
requestBody = await req.json();
|
|
57
|
+
} catch {
|
|
58
|
+
return new Response(JSON.stringify({ error: "Invalid JSON body" }), {
|
|
59
|
+
status: 400,
|
|
60
|
+
headers: { "Content-Type": "application/json" }
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const { messages } = requestBody;
|
|
64
|
+
if (!messages || !Array.isArray(messages)) return new Response(JSON.stringify({ error: "messages array is required" }), {
|
|
65
|
+
status: 400,
|
|
66
|
+
headers: { "Content-Type": "application/json" }
|
|
67
|
+
});
|
|
68
|
+
const modelMessages = await (0, ai.convertToModelMessages)(messages);
|
|
69
|
+
let currentTextId = null;
|
|
70
|
+
const genId = generateId || (() => crypto.randomUUID());
|
|
71
|
+
return (0, ai.createUIMessageStreamResponse)({ stream: (0, ai.createUIMessageStream)({
|
|
72
|
+
originalMessages: messages,
|
|
73
|
+
generateId: genId,
|
|
74
|
+
execute: async ({ writer }) => {
|
|
75
|
+
try {
|
|
76
|
+
for await (const event of agent.streamWithEvents({
|
|
77
|
+
messages: modelMessages,
|
|
78
|
+
state: initialState,
|
|
79
|
+
threadId,
|
|
80
|
+
maxSteps
|
|
81
|
+
})) switch (event.type) {
|
|
82
|
+
case "step-start":
|
|
83
|
+
writer.write({ type: "start-step" });
|
|
84
|
+
break;
|
|
85
|
+
case "step-finish":
|
|
86
|
+
writer.write({ type: "finish-step" });
|
|
87
|
+
break;
|
|
88
|
+
case "text":
|
|
89
|
+
if (!currentTextId) {
|
|
90
|
+
currentTextId = genId();
|
|
91
|
+
writer.write({
|
|
92
|
+
type: "text-start",
|
|
93
|
+
id: currentTextId
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
writer.write({
|
|
97
|
+
type: "text-delta",
|
|
98
|
+
id: currentTextId,
|
|
99
|
+
delta: event.text
|
|
100
|
+
});
|
|
101
|
+
break;
|
|
102
|
+
case "tool-call":
|
|
103
|
+
if (currentTextId) {
|
|
104
|
+
writer.write({
|
|
105
|
+
type: "text-end",
|
|
106
|
+
id: currentTextId
|
|
107
|
+
});
|
|
108
|
+
currentTextId = null;
|
|
109
|
+
}
|
|
110
|
+
writer.write({
|
|
111
|
+
type: "tool-input-available",
|
|
112
|
+
toolCallId: event.toolCallId,
|
|
113
|
+
toolName: event.toolName,
|
|
114
|
+
input: event.args
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
case "tool-result":
|
|
118
|
+
if (event.isError) writer.write({
|
|
119
|
+
type: "tool-output-error",
|
|
120
|
+
toolCallId: event.toolCallId,
|
|
121
|
+
errorText: String(event.result)
|
|
122
|
+
});
|
|
123
|
+
else writer.write({
|
|
124
|
+
type: "tool-output-available",
|
|
125
|
+
toolCallId: event.toolCallId,
|
|
126
|
+
output: event.result
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
case "todos-changed":
|
|
130
|
+
writer.write({
|
|
131
|
+
type: "data",
|
|
132
|
+
name: "todos-changed",
|
|
133
|
+
data: { todos: event.todos }
|
|
134
|
+
});
|
|
135
|
+
break;
|
|
136
|
+
case "error":
|
|
137
|
+
if (currentTextId) {
|
|
138
|
+
writer.write({
|
|
139
|
+
type: "text-end",
|
|
140
|
+
id: currentTextId
|
|
141
|
+
});
|
|
142
|
+
currentTextId = null;
|
|
143
|
+
}
|
|
144
|
+
writer.write({
|
|
145
|
+
type: "error",
|
|
146
|
+
errorText: event.error.message
|
|
147
|
+
});
|
|
148
|
+
break;
|
|
149
|
+
case "done":
|
|
150
|
+
if (currentTextId) {
|
|
151
|
+
writer.write({
|
|
152
|
+
type: "text-end",
|
|
153
|
+
id: currentTextId
|
|
154
|
+
});
|
|
155
|
+
currentTextId = null;
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
default: break;
|
|
159
|
+
}
|
|
160
|
+
if (currentTextId) writer.write({
|
|
161
|
+
type: "text-end",
|
|
162
|
+
id: currentTextId
|
|
163
|
+
});
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (currentTextId) writer.write({
|
|
166
|
+
type: "text-end",
|
|
167
|
+
id: currentTextId
|
|
168
|
+
});
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
onError: (error) => {
|
|
173
|
+
return error instanceof Error ? error.message : "Unknown error";
|
|
174
|
+
}
|
|
175
|
+
}) });
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/adapters/elements/messageConverters.ts
|
|
181
|
+
/**
|
|
182
|
+
* Message conversion utilities for AI SDK Elements adapter
|
|
183
|
+
*
|
|
184
|
+
* Provides utilities for converting between UI message formats and model message formats.
|
|
185
|
+
* The primary conversion is handled by AI SDK's `convertToModelMessages`, but these
|
|
186
|
+
* utilities provide additional helpers for DeepAgent-specific needs.
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* Re-export AI SDK's convertToModelMessages for convenience.
|
|
190
|
+
*
|
|
191
|
+
* This function converts UIMessage[] (from useChat) to ModelMessage[]
|
|
192
|
+
* (for agent consumption), handling:
|
|
193
|
+
* - Role mapping (user/assistant)
|
|
194
|
+
* - Tool call/result parts
|
|
195
|
+
* - Text content extraction
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* import { convertUIMessagesToModelMessages } from 'deepagentsdk/adapters/elements';
|
|
200
|
+
*
|
|
201
|
+
* const modelMessages = await convertUIMessagesToModelMessages(uiMessages);
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
async function convertUIMessagesToModelMessages(messages) {
|
|
205
|
+
return await (0, ai.convertToModelMessages)(messages);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Extract the last user message text from a UIMessage array.
|
|
209
|
+
* Useful for extracting the prompt from a conversation.
|
|
210
|
+
*
|
|
211
|
+
* @param messages - Array of UI messages
|
|
212
|
+
* @returns The text content of the last user message, or undefined if none
|
|
213
|
+
*/
|
|
214
|
+
function extractLastUserMessage(messages) {
|
|
215
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
216
|
+
const msg = messages[i];
|
|
217
|
+
if (msg && msg.role === "user" && msg.parts) {
|
|
218
|
+
const textParts = msg.parts.filter((p) => p.type === "text");
|
|
219
|
+
if (textParts.length > 0) return textParts.map((p) => p.text).join("");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Check if the messages contain any tool parts.
|
|
225
|
+
* This is a simplified helper that checks for any tool-related parts.
|
|
226
|
+
*
|
|
227
|
+
* @param messages - Array of UI messages
|
|
228
|
+
* @returns True if there are any tool-related parts in the messages
|
|
229
|
+
*/
|
|
230
|
+
function hasToolParts(messages) {
|
|
231
|
+
for (const msg of messages) {
|
|
232
|
+
if (!msg.parts) continue;
|
|
233
|
+
for (const part of msg.parts) if (part.type.startsWith("tool-") || part.type === "dynamic-tool") return true;
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Count the number of messages by role.
|
|
239
|
+
*
|
|
240
|
+
* @param messages - Array of UI messages
|
|
241
|
+
* @returns Object with counts by role
|
|
242
|
+
*/
|
|
243
|
+
function countMessagesByRole(messages) {
|
|
244
|
+
let user = 0;
|
|
245
|
+
let assistant = 0;
|
|
246
|
+
let system = 0;
|
|
247
|
+
for (const msg of messages) if (msg.role === "user") user++;
|
|
248
|
+
else if (msg.role === "assistant") assistant++;
|
|
249
|
+
else if (msg.role === "system") system++;
|
|
250
|
+
return {
|
|
251
|
+
user,
|
|
252
|
+
assistant,
|
|
253
|
+
system
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Extract all text content from a message.
|
|
258
|
+
*
|
|
259
|
+
* @param message - A UI message
|
|
260
|
+
* @returns Combined text from all text parts
|
|
261
|
+
*/
|
|
262
|
+
function extractTextFromMessage(message) {
|
|
263
|
+
if (!message.parts) return "";
|
|
264
|
+
return message.parts.filter((p) => p.type === "text").map((p) => p.text).join("");
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
exports.convertUIMessagesToModelMessages = convertUIMessagesToModelMessages;
|
|
269
|
+
exports.countMessagesByRole = countMessagesByRole;
|
|
270
|
+
exports.createElementsRouteHandler = createElementsRouteHandler;
|
|
271
|
+
exports.extractLastUserMessage = extractLastUserMessage;
|
|
272
|
+
exports.extractTextFromMessage = extractTextFromMessage;
|
|
273
|
+
exports.hasToolParts = hasToolParts;
|
|
274
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/adapters/elements/createElementsRouteHandler.ts","../../../src/adapters/elements/messageConverters.ts"],"sourcesContent":["/**\n * Server-side route handler adapter for AI SDK Elements\n *\n * Creates a Next.js/Express-compatible route handler that runs DeepAgent\n * and returns UI Message Stream compatible responses for use with useChat.\n *\n * @example\n * ```typescript\n * // app/api/chat/route.ts (Next.js App Router)\n * import { createDeepAgent } from 'deepagentsdk';\n * import { createElementsRouteHandler } from 'deepagentsdk/adapters/elements';\n * import { anthropic } from '@ai-sdk/anthropic';\n *\n * const agent = createDeepAgent({\n * model: anthropic('claude-sonnet-4-20250514'),\n * });\n *\n * export const POST = createElementsRouteHandler({ agent });\n * ```\n *\n * @see https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol\n */\n\nimport {\n createUIMessageStream,\n createUIMessageStreamResponse,\n convertToModelMessages,\n type UIMessage,\n} from \"ai\";\nimport type { DeepAgent } from \"../../agent\";\nimport type { DeepAgentState, ModelMessage } from \"../../types\";\n\n/**\n * Options for creating an Elements route handler\n */\nexport interface CreateElementsRouteHandlerOptions {\n /**\n * The DeepAgent instance to use for handling requests\n */\n agent: DeepAgent;\n\n /**\n * Optional callback before processing a request.\n * Use for authentication, logging, rate limiting, etc.\n *\n * @example\n * ```typescript\n * onRequest: async (req) => {\n * const token = req.headers.get('Authorization');\n * if (!validateToken(token)) {\n * throw new Error('Unauthorized');\n * }\n * }\n * ```\n */\n onRequest?: (req: Request) => Promise<void> | void;\n\n /**\n * Optional initial state to provide to the agent.\n * If not provided, uses empty state { todos: [], files: {} }\n */\n initialState?: DeepAgentState;\n\n /**\n * Optional thread ID for checkpointing.\n * If provided, enables conversation persistence.\n */\n threadId?: string;\n\n /**\n * Optional maximum number of steps for the agent loop.\n */\n maxSteps?: number;\n\n /**\n * Custom ID generator for message IDs.\n * Defaults to crypto.randomUUID if available.\n */\n generateId?: () => string;\n}\n\n/**\n * Creates a route handler that processes chat requests using DeepAgent\n * and returns UI Message Stream compatible responses.\n *\n * The returned handler:\n * - Accepts POST requests with { messages: UIMessage[] } body\n * - Runs DeepAgent with the conversation history\n * - Streams responses in UI Message Stream Protocol format\n * - Works with useChat hook from @ai-sdk/react\n *\n * @param options - Configuration options\n * @returns A request handler function compatible with Next.js/Express\n */\nexport function createElementsRouteHandler(\n options: CreateElementsRouteHandlerOptions\n): (req: Request) => Promise<Response> {\n const {\n agent,\n onRequest,\n initialState = { todos: [], files: {} },\n threadId,\n maxSteps,\n generateId,\n } = options;\n\n return async (req: Request): Promise<Response> => {\n // Run optional request hook (auth, logging, etc.)\n if (onRequest) {\n try {\n await onRequest(req);\n } catch (error) {\n return new Response(\n JSON.stringify({\n error: error instanceof Error ? error.message : \"Request rejected\",\n }),\n { status: 401, headers: { \"Content-Type\": \"application/json\" } }\n );\n }\n }\n\n // Parse request body\n let requestBody: { messages: UIMessage[] };\n try {\n requestBody = await req.json();\n } catch {\n return new Response(\n JSON.stringify({ error: \"Invalid JSON body\" }),\n { status: 400, headers: { \"Content-Type\": \"application/json\" } }\n );\n }\n\n const { messages } = requestBody;\n\n if (!messages || !Array.isArray(messages)) {\n return new Response(\n JSON.stringify({ error: \"messages array is required\" }),\n { status: 400, headers: { \"Content-Type\": \"application/json\" } }\n );\n }\n\n // Convert UI messages to model messages using AI SDK's converter\n const modelMessages = await convertToModelMessages(messages) as ModelMessage[];\n\n // Track current text part ID for proper text streaming\n let currentTextId: string | null = null;\n const genId = generateId || (() => crypto.randomUUID());\n\n // Create the UI message stream\n const stream = createUIMessageStream({\n originalMessages: messages,\n generateId: genId,\n execute: async ({ writer }) => {\n try {\n for await (const event of agent.streamWithEvents({\n messages: modelMessages,\n state: initialState,\n threadId,\n maxSteps,\n })) {\n switch (event.type) {\n case \"step-start\":\n // Emit step start for UI progress tracking\n writer.write({ type: \"start-step\" });\n break;\n\n case \"step-finish\":\n // Emit step finish\n writer.write({ type: \"finish-step\" });\n break;\n\n case \"text\":\n // Handle text streaming\n if (!currentTextId) {\n // Start a new text part\n currentTextId = genId();\n writer.write({\n type: \"text-start\",\n id: currentTextId,\n });\n }\n // Stream text delta\n writer.write({\n type: \"text-delta\",\n id: currentTextId,\n delta: event.text,\n });\n break;\n\n case \"tool-call\":\n // End any in-progress text before tool call\n if (currentTextId) {\n writer.write({ type: \"text-end\", id: currentTextId });\n currentTextId = null;\n }\n // Emit tool input available\n writer.write({\n type: \"tool-input-available\",\n toolCallId: event.toolCallId,\n toolName: event.toolName,\n input: event.args,\n });\n break;\n\n case \"tool-result\":\n // Emit tool output\n if (event.isError) {\n writer.write({\n type: \"tool-output-error\",\n toolCallId: event.toolCallId,\n errorText: String(event.result),\n });\n } else {\n writer.write({\n type: \"tool-output-available\",\n toolCallId: event.toolCallId,\n output: event.result,\n });\n }\n break;\n\n case \"todos-changed\":\n // Emit as custom data part for UI to handle\n // Note: This requires UI to handle custom data types\n writer.write({\n type: \"data\" as any,\n name: \"todos-changed\",\n data: { todos: event.todos },\n } as any);\n break;\n\n case \"error\":\n // End any in-progress text\n if (currentTextId) {\n writer.write({ type: \"text-end\", id: currentTextId });\n currentTextId = null;\n }\n // Emit error\n writer.write({\n type: \"error\",\n errorText: event.error.message,\n });\n break;\n\n case \"done\":\n // End any in-progress text\n if (currentTextId) {\n writer.write({ type: \"text-end\", id: currentTextId });\n currentTextId = null;\n }\n // Done event is handled automatically by the stream\n break;\n\n // Other events (file operations, subagents, etc.) can be\n // emitted as custom data parts if needed by the UI\n default:\n // Optionally emit other events as data parts\n // writer.write({\n // type: \"data\" as any,\n // name: event.type,\n // data: event,\n // } as any);\n break;\n }\n }\n\n // Ensure text is ended if stream completes\n if (currentTextId) {\n writer.write({ type: \"text-end\", id: currentTextId });\n }\n } catch (error) {\n // End any in-progress text on error\n if (currentTextId) {\n writer.write({ type: \"text-end\", id: currentTextId });\n }\n // Re-throw to let the stream handle the error\n throw error;\n }\n },\n onError: (error) => {\n // Return error message for the stream\n return error instanceof Error ? error.message : \"Unknown error\";\n },\n });\n\n // Return the stream response\n return createUIMessageStreamResponse({ stream });\n };\n}\n\n/**\n * Type for the request handler returned by createElementsRouteHandler\n */\nexport type ElementsRouteHandler = (req: Request) => Promise<Response>;\n","/**\n * Message conversion utilities for AI SDK Elements adapter\n *\n * Provides utilities for converting between UI message formats and model message formats.\n * The primary conversion is handled by AI SDK's `convertToModelMessages`, but these\n * utilities provide additional helpers for DeepAgent-specific needs.\n */\n\nimport {\n convertToModelMessages,\n type UIMessage,\n} from \"ai\";\nimport type { ModelMessage } from \"../../types\";\n\n/**\n * Re-export AI SDK's convertToModelMessages for convenience.\n *\n * This function converts UIMessage[] (from useChat) to ModelMessage[]\n * (for agent consumption), handling:\n * - Role mapping (user/assistant)\n * - Tool call/result parts\n * - Text content extraction\n *\n * @example\n * ```typescript\n * import { convertUIMessagesToModelMessages } from 'deepagentsdk/adapters/elements';\n *\n * const modelMessages = await convertUIMessagesToModelMessages(uiMessages);\n * ```\n */\nexport async function convertUIMessagesToModelMessages(\n messages: UIMessage[]\n): Promise<ModelMessage[]> {\n return await convertToModelMessages(messages) as ModelMessage[];\n}\n\n/**\n * Extract the last user message text from a UIMessage array.\n * Useful for extracting the prompt from a conversation.\n *\n * @param messages - Array of UI messages\n * @returns The text content of the last user message, or undefined if none\n */\nexport function extractLastUserMessage(messages: UIMessage[]): string | undefined {\n // Find the last user message\n for (let i = messages.length - 1; i >= 0; i--) {\n const msg = messages[i];\n if (msg && msg.role === \"user\" && msg.parts) {\n // Extract text parts\n const textParts = msg.parts.filter(\n (p): p is { type: \"text\"; text: string } => p.type === \"text\"\n );\n if (textParts.length > 0) {\n return textParts.map(p => p.text).join(\"\");\n }\n }\n }\n return undefined;\n}\n\n/**\n * Check if the messages contain any tool parts.\n * This is a simplified helper that checks for any tool-related parts.\n *\n * @param messages - Array of UI messages\n * @returns True if there are any tool-related parts in the messages\n */\nexport function hasToolParts(messages: UIMessage[]): boolean {\n for (const msg of messages) {\n if (!msg.parts) continue;\n for (const part of msg.parts) {\n // Tool parts have type starting with \"tool-\" or \"dynamic-tool\"\n if (part.type.startsWith(\"tool-\") || part.type === \"dynamic-tool\") {\n return true;\n }\n }\n }\n return false;\n}\n\n/**\n * Count the number of messages by role.\n *\n * @param messages - Array of UI messages\n * @returns Object with counts by role\n */\nexport function countMessagesByRole(\n messages: UIMessage[]\n): { user: number; assistant: number; system: number } {\n let user = 0;\n let assistant = 0;\n let system = 0;\n\n for (const msg of messages) {\n if (msg.role === \"user\") {\n user++;\n } else if (msg.role === \"assistant\") {\n assistant++;\n } else if (msg.role === \"system\") {\n system++;\n }\n }\n\n return { user, assistant, system };\n}\n\n/**\n * Extract all text content from a message.\n *\n * @param message - A UI message\n * @returns Combined text from all text parts\n */\nexport function extractTextFromMessage(message: UIMessage): string {\n if (!message.parts) return \"\";\n\n return message.parts\n .filter((p): p is { type: \"text\"; text: string } => p.type === \"text\")\n .map(p => p.text)\n .join(\"\");\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { r as ModelMessage$1, t as DeepAgent, yt as DeepAgentState } from "../../agent-DToEVxs-.cjs";
|
|
2
|
+
import { UIMessage, UIMessage as UIMessage$1, UIMessagePart } from "ai";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/elements/createElementsRouteHandler.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for creating an Elements route handler
|
|
8
|
+
*/
|
|
9
|
+
interface CreateElementsRouteHandlerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The DeepAgent instance to use for handling requests
|
|
12
|
+
*/
|
|
13
|
+
agent: DeepAgent;
|
|
14
|
+
/**
|
|
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
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
onRequest?: (req: Request) => Promise<void> | void;
|
|
29
|
+
/**
|
|
30
|
+
* Optional initial state to provide to the agent.
|
|
31
|
+
* If not provided, uses empty state { todos: [], files: {} }
|
|
32
|
+
*/
|
|
33
|
+
initialState?: DeepAgentState;
|
|
34
|
+
/**
|
|
35
|
+
* Optional thread ID for checkpointing.
|
|
36
|
+
* If provided, enables conversation persistence.
|
|
37
|
+
*/
|
|
38
|
+
threadId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional maximum number of steps for the agent loop.
|
|
41
|
+
*/
|
|
42
|
+
maxSteps?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Custom ID generator for message IDs.
|
|
45
|
+
* Defaults to crypto.randomUUID if available.
|
|
46
|
+
*/
|
|
47
|
+
generateId?: () => string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a route handler that processes chat requests using DeepAgent
|
|
51
|
+
* and returns UI Message Stream compatible responses.
|
|
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
|
+
*
|
|
59
|
+
* @param options - Configuration options
|
|
60
|
+
* @returns A request handler function compatible with Next.js/Express
|
|
61
|
+
*/
|
|
62
|
+
declare function createElementsRouteHandler(options: CreateElementsRouteHandlerOptions): (req: Request) => Promise<Response>;
|
|
63
|
+
/**
|
|
64
|
+
* Type for the request handler returned by createElementsRouteHandler
|
|
65
|
+
*/
|
|
66
|
+
type ElementsRouteHandler = (req: Request) => Promise<Response>;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/adapters/elements/messageConverters.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* Re-export AI SDK's convertToModelMessages for convenience.
|
|
71
|
+
*
|
|
72
|
+
* This function converts UIMessage[] (from useChat) to ModelMessage[]
|
|
73
|
+
* (for agent consumption), handling:
|
|
74
|
+
* - Role mapping (user/assistant)
|
|
75
|
+
* - Tool call/result parts
|
|
76
|
+
* - Text content extraction
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { convertUIMessagesToModelMessages } from 'deepagentsdk/adapters/elements';
|
|
81
|
+
*
|
|
82
|
+
* const modelMessages = await convertUIMessagesToModelMessages(uiMessages);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function convertUIMessagesToModelMessages(messages: UIMessage$1[]): Promise<ModelMessage$1[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Extract the last user message text from a UIMessage array.
|
|
88
|
+
* Useful for extracting the prompt from a conversation.
|
|
89
|
+
*
|
|
90
|
+
* @param messages - Array of UI messages
|
|
91
|
+
* @returns The text content of the last user message, or undefined if none
|
|
92
|
+
*/
|
|
93
|
+
declare function extractLastUserMessage(messages: UIMessage$1[]): string | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Check if the messages contain any tool parts.
|
|
96
|
+
* This is a simplified helper that checks for any tool-related parts.
|
|
97
|
+
*
|
|
98
|
+
* @param messages - Array of UI messages
|
|
99
|
+
* @returns True if there are any tool-related parts in the messages
|
|
100
|
+
*/
|
|
101
|
+
declare function hasToolParts(messages: UIMessage$1[]): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Count the number of messages by role.
|
|
104
|
+
*
|
|
105
|
+
* @param messages - Array of UI messages
|
|
106
|
+
* @returns Object with counts by role
|
|
107
|
+
*/
|
|
108
|
+
declare function countMessagesByRole(messages: UIMessage$1[]): {
|
|
109
|
+
user: number;
|
|
110
|
+
assistant: number;
|
|
111
|
+
system: number;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Extract all text content from a message.
|
|
115
|
+
*
|
|
116
|
+
* @param message - A UI message
|
|
117
|
+
* @returns Combined text from all text parts
|
|
118
|
+
*/
|
|
119
|
+
declare function extractTextFromMessage(message: UIMessage$1): string;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { type CreateElementsRouteHandlerOptions, type ElementsRouteHandler, type UIMessage, type UIMessagePart, convertUIMessagesToModelMessages, countMessagesByRole, createElementsRouteHandler, extractLastUserMessage, extractTextFromMessage, hasToolParts };
|
|
122
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { r as ModelMessage$1, t as DeepAgent, yt as DeepAgentState } from "../../agent-BDM-PIu8.mjs";
|
|
2
|
+
import { UIMessage, UIMessage as UIMessage$1, UIMessagePart } from "ai";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/elements/createElementsRouteHandler.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Options for creating an Elements route handler
|
|
8
|
+
*/
|
|
9
|
+
interface CreateElementsRouteHandlerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The DeepAgent instance to use for handling requests
|
|
12
|
+
*/
|
|
13
|
+
agent: DeepAgent;
|
|
14
|
+
/**
|
|
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
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
onRequest?: (req: Request) => Promise<void> | void;
|
|
29
|
+
/**
|
|
30
|
+
* Optional initial state to provide to the agent.
|
|
31
|
+
* If not provided, uses empty state { todos: [], files: {} }
|
|
32
|
+
*/
|
|
33
|
+
initialState?: DeepAgentState;
|
|
34
|
+
/**
|
|
35
|
+
* Optional thread ID for checkpointing.
|
|
36
|
+
* If provided, enables conversation persistence.
|
|
37
|
+
*/
|
|
38
|
+
threadId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional maximum number of steps for the agent loop.
|
|
41
|
+
*/
|
|
42
|
+
maxSteps?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Custom ID generator for message IDs.
|
|
45
|
+
* Defaults to crypto.randomUUID if available.
|
|
46
|
+
*/
|
|
47
|
+
generateId?: () => string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a route handler that processes chat requests using DeepAgent
|
|
51
|
+
* and returns UI Message Stream compatible responses.
|
|
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
|
+
*
|
|
59
|
+
* @param options - Configuration options
|
|
60
|
+
* @returns A request handler function compatible with Next.js/Express
|
|
61
|
+
*/
|
|
62
|
+
declare function createElementsRouteHandler(options: CreateElementsRouteHandlerOptions): (req: Request) => Promise<Response>;
|
|
63
|
+
/**
|
|
64
|
+
* Type for the request handler returned by createElementsRouteHandler
|
|
65
|
+
*/
|
|
66
|
+
type ElementsRouteHandler = (req: Request) => Promise<Response>;
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/adapters/elements/messageConverters.d.ts
|
|
69
|
+
/**
|
|
70
|
+
* Re-export AI SDK's convertToModelMessages for convenience.
|
|
71
|
+
*
|
|
72
|
+
* This function converts UIMessage[] (from useChat) to ModelMessage[]
|
|
73
|
+
* (for agent consumption), handling:
|
|
74
|
+
* - Role mapping (user/assistant)
|
|
75
|
+
* - Tool call/result parts
|
|
76
|
+
* - Text content extraction
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { convertUIMessagesToModelMessages } from 'deepagentsdk/adapters/elements';
|
|
81
|
+
*
|
|
82
|
+
* const modelMessages = await convertUIMessagesToModelMessages(uiMessages);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function convertUIMessagesToModelMessages(messages: UIMessage$1[]): Promise<ModelMessage$1[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Extract the last user message text from a UIMessage array.
|
|
88
|
+
* Useful for extracting the prompt from a conversation.
|
|
89
|
+
*
|
|
90
|
+
* @param messages - Array of UI messages
|
|
91
|
+
* @returns The text content of the last user message, or undefined if none
|
|
92
|
+
*/
|
|
93
|
+
declare function extractLastUserMessage(messages: UIMessage$1[]): string | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Check if the messages contain any tool parts.
|
|
96
|
+
* This is a simplified helper that checks for any tool-related parts.
|
|
97
|
+
*
|
|
98
|
+
* @param messages - Array of UI messages
|
|
99
|
+
* @returns True if there are any tool-related parts in the messages
|
|
100
|
+
*/
|
|
101
|
+
declare function hasToolParts(messages: UIMessage$1[]): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Count the number of messages by role.
|
|
104
|
+
*
|
|
105
|
+
* @param messages - Array of UI messages
|
|
106
|
+
* @returns Object with counts by role
|
|
107
|
+
*/
|
|
108
|
+
declare function countMessagesByRole(messages: UIMessage$1[]): {
|
|
109
|
+
user: number;
|
|
110
|
+
assistant: number;
|
|
111
|
+
system: number;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Extract all text content from a message.
|
|
115
|
+
*
|
|
116
|
+
* @param message - A UI message
|
|
117
|
+
* @returns Combined text from all text parts
|
|
118
|
+
*/
|
|
119
|
+
declare function extractTextFromMessage(message: UIMessage$1): string;
|
|
120
|
+
//#endregion
|
|
121
|
+
export { type CreateElementsRouteHandlerOptions, type ElementsRouteHandler, type UIMessage, type UIMessagePart, convertUIMessagesToModelMessages, countMessagesByRole, createElementsRouteHandler, extractLastUserMessage, extractTextFromMessage, hasToolParts };
|
|
122
|
+
//# sourceMappingURL=index.d.mts.map
|