@voltagent/core 0.1.31 → 0.1.32
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/index.d.ts +391 -16
- package/dist/index.js +1053 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1052 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -215,6 +215,36 @@ declare const createTool: <T extends ToolSchema>(options: ToolOptions<T>) => Too
|
|
|
215
215
|
*/
|
|
216
216
|
declare const tool: <T extends ToolSchema>(options: ToolOptions<T>) => Tool<T>;
|
|
217
217
|
|
|
218
|
+
/**
|
|
219
|
+
* An async iterable stream that can be read from.
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const stream: AsyncIterableStream<string> = getStream();
|
|
223
|
+
* for await (const chunk of stream) {
|
|
224
|
+
* console.log(chunk);
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
|
229
|
+
/**
|
|
230
|
+
* Create an async iterable stream from a readable stream.
|
|
231
|
+
*
|
|
232
|
+
* This is useful for creating an async iterable stream from a readable stream.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* const stream: AsyncIterableStream<string> = createAsyncIterableStream(new ReadableStream({
|
|
237
|
+
* start(controller) {
|
|
238
|
+
* controller.enqueue("Hello");
|
|
239
|
+
* controller.close();
|
|
240
|
+
* },
|
|
241
|
+
* }));
|
|
242
|
+
* ```
|
|
243
|
+
* @param source The readable stream to create an async iterable stream from.
|
|
244
|
+
* @returns The async iterable stream.
|
|
245
|
+
*/
|
|
246
|
+
declare function createAsyncIterableStream<T>(source: ReadableStream<T>): AsyncIterableStream<T>;
|
|
247
|
+
|
|
218
248
|
/**
|
|
219
249
|
* Memory options
|
|
220
250
|
*/
|
|
@@ -260,6 +290,7 @@ type MessageFilterOptions = {
|
|
|
260
290
|
type Conversation = {
|
|
261
291
|
id: string;
|
|
262
292
|
resourceId: string;
|
|
293
|
+
userId: string;
|
|
263
294
|
title: string;
|
|
264
295
|
metadata: Record<string, unknown>;
|
|
265
296
|
createdAt: string;
|
|
@@ -271,9 +302,21 @@ type Conversation = {
|
|
|
271
302
|
type CreateConversationInput = {
|
|
272
303
|
id: string;
|
|
273
304
|
resourceId: string;
|
|
305
|
+
userId: string;
|
|
274
306
|
title: string;
|
|
275
307
|
metadata: Record<string, unknown>;
|
|
276
308
|
};
|
|
309
|
+
/**
|
|
310
|
+
* Query builder options for conversations
|
|
311
|
+
*/
|
|
312
|
+
type ConversationQueryOptions = {
|
|
313
|
+
userId?: string;
|
|
314
|
+
resourceId?: string;
|
|
315
|
+
limit?: number;
|
|
316
|
+
offset?: number;
|
|
317
|
+
orderBy?: "created_at" | "updated_at" | "title";
|
|
318
|
+
orderDirection?: "ASC" | "DESC";
|
|
319
|
+
};
|
|
277
320
|
/**
|
|
278
321
|
* Memory interface for storing and retrieving messages
|
|
279
322
|
*/
|
|
@@ -305,6 +348,21 @@ type Memory = {
|
|
|
305
348
|
* Get conversations for a resource
|
|
306
349
|
*/
|
|
307
350
|
getConversations(resourceId: string): Promise<Conversation[]>;
|
|
351
|
+
/**
|
|
352
|
+
* Get conversations by user ID with query options
|
|
353
|
+
*/
|
|
354
|
+
getConversationsByUserId(userId: string, options?: Omit<ConversationQueryOptions, "userId">): Promise<Conversation[]>;
|
|
355
|
+
/**
|
|
356
|
+
* Get conversations with advanced query options
|
|
357
|
+
*/
|
|
358
|
+
queryConversations(options: ConversationQueryOptions): Promise<Conversation[]>;
|
|
359
|
+
/**
|
|
360
|
+
* Get all messages for a specific conversation
|
|
361
|
+
*/
|
|
362
|
+
getConversationMessages(conversationId: string, options?: {
|
|
363
|
+
limit?: number;
|
|
364
|
+
offset?: number;
|
|
365
|
+
}): Promise<MemoryMessage[]>;
|
|
308
366
|
/**
|
|
309
367
|
* Update a conversation
|
|
310
368
|
*/
|
|
@@ -765,27 +823,27 @@ type ModelType<T> = T extends {
|
|
|
765
823
|
/**
|
|
766
824
|
* Infer generate text response type
|
|
767
825
|
*/
|
|
768
|
-
type
|
|
826
|
+
type InferGenerateTextResponseFromProvider<TProvider extends {
|
|
769
827
|
llm: LLMProvider<any>;
|
|
770
|
-
}> =
|
|
828
|
+
}> = ProviderTextResponse<InferOriginalResponseFromProvider<TProvider, "generateText">>;
|
|
771
829
|
/**
|
|
772
830
|
* Infer stream text response type
|
|
773
831
|
*/
|
|
774
|
-
type
|
|
832
|
+
type InferStreamTextResponseFromProvider<TProvider extends {
|
|
775
833
|
llm: LLMProvider<any>;
|
|
776
|
-
}> =
|
|
834
|
+
}> = ProviderTextStreamResponse<InferOriginalResponseFromProvider<TProvider, "streamText">>;
|
|
777
835
|
/**
|
|
778
836
|
* Infer generate object response type
|
|
779
837
|
*/
|
|
780
|
-
type
|
|
838
|
+
type InferGenerateObjectResponseFromProvider<TProvider extends {
|
|
781
839
|
llm: LLMProvider<any>;
|
|
782
|
-
}> =
|
|
840
|
+
}, TSchema extends z.ZodType> = ProviderObjectResponse<InferOriginalResponseFromProvider<TProvider, "generateObject">, z.infer<TSchema>>;
|
|
783
841
|
/**
|
|
784
842
|
* Infer stream object response type
|
|
785
843
|
*/
|
|
786
|
-
type
|
|
844
|
+
type InferStreamObjectResponseFromProvider<TProvider extends {
|
|
787
845
|
llm: LLMProvider<any>;
|
|
788
|
-
}> =
|
|
846
|
+
}, TSchema extends z.ZodType> = ProviderObjectStreamResponse<InferOriginalResponseFromProvider<TProvider, "streamObject">, z.infer<TSchema>>;
|
|
789
847
|
/**
|
|
790
848
|
* Common generate options - internal version that includes historyEntryId
|
|
791
849
|
* Not exposed directly to users
|
|
@@ -945,6 +1003,8 @@ type OperationContext = {
|
|
|
945
1003
|
otelSpan?: Span;
|
|
946
1004
|
/** Map to store active OpenTelemetry spans for tool calls within this operation */
|
|
947
1005
|
toolSpans?: Map<string, Span>;
|
|
1006
|
+
/** Conversation steps for building full message history including tool calls/results */
|
|
1007
|
+
conversationSteps?: StepWithContent[];
|
|
948
1008
|
};
|
|
949
1009
|
/**
|
|
950
1010
|
* Tool execution context passed to tool.execute method
|
|
@@ -1082,6 +1142,12 @@ interface StandardizedObjectResult<TObject> {
|
|
|
1082
1142
|
* Object types are generalized to 'unknown' here for the union.
|
|
1083
1143
|
*/
|
|
1084
1144
|
type AgentOperationOutput = StandardizedTextResult | StreamTextFinishResult | StandardizedObjectResult<unknown> | StreamObjectFinishResult<unknown>;
|
|
1145
|
+
type InferResponseFromProvider<TProvider extends {
|
|
1146
|
+
llm: LLMProvider<any>;
|
|
1147
|
+
}, TMethod extends "generateText" | "streamText" | "generateObject" | "streamObject"> = Awaited<ReturnType<TProvider["llm"][TMethod]>>;
|
|
1148
|
+
type InferOriginalResponseFromProvider<TProvider extends {
|
|
1149
|
+
llm: LLMProvider<any>;
|
|
1150
|
+
}, TMethod extends "generateText" | "streamText" | "generateObject" | "streamObject"> = InferResponseFromProvider<TProvider, TMethod>["provider"];
|
|
1085
1151
|
|
|
1086
1152
|
/**
|
|
1087
1153
|
* Token usage information
|
|
@@ -1140,7 +1206,7 @@ type ProviderTextStreamResponse<TOriginalResponse> = {
|
|
|
1140
1206
|
/**
|
|
1141
1207
|
* Text stream for consuming the response
|
|
1142
1208
|
*/
|
|
1143
|
-
textStream:
|
|
1209
|
+
textStream: AsyncIterableStream<string>;
|
|
1144
1210
|
};
|
|
1145
1211
|
/**
|
|
1146
1212
|
* Response type for object generation operations
|
|
@@ -1174,7 +1240,7 @@ type ProviderObjectStreamResponse<TOriginalResponse, TObject> = {
|
|
|
1174
1240
|
/**
|
|
1175
1241
|
* Object stream for consuming partial objects
|
|
1176
1242
|
*/
|
|
1177
|
-
objectStream:
|
|
1243
|
+
objectStream: AsyncIterableStream<Partial<TObject>>;
|
|
1178
1244
|
};
|
|
1179
1245
|
/**
|
|
1180
1246
|
* Data content type for binary data
|
|
@@ -1362,6 +1428,11 @@ type LLMProvider<TProvider> = {
|
|
|
1362
1428
|
* @throws {VoltAgentError} If an error occurs during generation.
|
|
1363
1429
|
*/
|
|
1364
1430
|
generateText(options: GenerateTextOptions<InferModel<TProvider>>): Promise<ProviderTextResponse<InferGenerateTextResponse<TProvider>>>;
|
|
1431
|
+
/**
|
|
1432
|
+
* Streams a text response based on the provided options.
|
|
1433
|
+
* Implementers should catch underlying SDK/API errors and throw a VoltAgentError.
|
|
1434
|
+
* @throws {VoltAgentError} If an error occurs during streaming.
|
|
1435
|
+
*/
|
|
1365
1436
|
streamText(options: StreamTextOptions<InferModel<TProvider>>): Promise<ProviderTextStreamResponse<InferStreamResponse<TProvider>>>;
|
|
1366
1437
|
/**
|
|
1367
1438
|
* Generates a structured object response based on the provided options and schema.
|
|
@@ -1369,8 +1440,21 @@ type LLMProvider<TProvider> = {
|
|
|
1369
1440
|
* @throws {VoltAgentError} If an error occurs during generation.
|
|
1370
1441
|
*/
|
|
1371
1442
|
generateObject<TSchema extends z.ZodType>(options: GenerateObjectOptions<InferModel<TProvider>, TSchema>): Promise<ProviderObjectResponse<InferGenerateObjectResponse<TProvider>, z.infer<TSchema>>>;
|
|
1443
|
+
/**
|
|
1444
|
+
* Streams a structured object response based on the provided options and schema.
|
|
1445
|
+
* Implementers should catch underlying SDK/API errors and throw a VoltAgentError.
|
|
1446
|
+
* @throws {VoltAgentError} If an error occurs during streaming.
|
|
1447
|
+
*/
|
|
1372
1448
|
streamObject<TSchema extends z.ZodType>(options: StreamObjectOptions<InferModel<TProvider>, TSchema>): Promise<ProviderObjectStreamResponse<InferStreamResponse<TProvider>, z.infer<TSchema>>>;
|
|
1449
|
+
/**
|
|
1450
|
+
* Converts a base message to a provider-specific message.
|
|
1451
|
+
* @param message The base message to convert.
|
|
1452
|
+
* @returns The provider-specific message.
|
|
1453
|
+
*/
|
|
1373
1454
|
toMessage(message: BaseMessage): InferMessage<TProvider>;
|
|
1455
|
+
/**
|
|
1456
|
+
* Optional tool conversion method.
|
|
1457
|
+
*/
|
|
1374
1458
|
toTool?: (tool: BaseTool) => InferTool<TProvider>;
|
|
1375
1459
|
/**
|
|
1376
1460
|
* Returns a string representation of the model identifier.
|
|
@@ -1693,6 +1777,110 @@ declare class InMemoryStorage implements Memory {
|
|
|
1693
1777
|
* @returns Array of conversations
|
|
1694
1778
|
*/
|
|
1695
1779
|
getConversations(resourceId: string): Promise<Conversation[]>;
|
|
1780
|
+
/**
|
|
1781
|
+
* Get conversations by user ID with query options
|
|
1782
|
+
* @param userId User ID
|
|
1783
|
+
* @param options Query options
|
|
1784
|
+
* @returns Array of conversations
|
|
1785
|
+
*/
|
|
1786
|
+
getConversationsByUserId(userId: string, options?: Omit<ConversationQueryOptions, "userId">): Promise<Conversation[]>;
|
|
1787
|
+
/**
|
|
1788
|
+
* Query conversations with flexible filtering and pagination options
|
|
1789
|
+
*
|
|
1790
|
+
* This method provides a powerful way to search and filter conversations
|
|
1791
|
+
* with support for user-based filtering, resource filtering, pagination,
|
|
1792
|
+
* and custom sorting.
|
|
1793
|
+
*
|
|
1794
|
+
* @param options Query options for filtering and pagination
|
|
1795
|
+
* @param options.userId Optional user ID to filter conversations by specific user
|
|
1796
|
+
* @param options.resourceId Optional resource ID to filter conversations by specific resource
|
|
1797
|
+
* @param options.limit Maximum number of conversations to return (default: 50)
|
|
1798
|
+
* @param options.offset Number of conversations to skip for pagination (default: 0)
|
|
1799
|
+
* @param options.orderBy Field to sort by: 'created_at', 'updated_at', or 'title' (default: 'updated_at')
|
|
1800
|
+
* @param options.orderDirection Sort direction: 'ASC' or 'DESC' (default: 'DESC')
|
|
1801
|
+
*
|
|
1802
|
+
* @returns Promise that resolves to an array of conversations matching the criteria
|
|
1803
|
+
*
|
|
1804
|
+
* @example
|
|
1805
|
+
* ```typescript
|
|
1806
|
+
* // Get all conversations for a specific user
|
|
1807
|
+
* const userConversations = await storage.queryConversations({
|
|
1808
|
+
* userId: 'user123',
|
|
1809
|
+
* limit: 20
|
|
1810
|
+
* });
|
|
1811
|
+
*
|
|
1812
|
+
* // Get conversations for a resource with pagination
|
|
1813
|
+
* const resourceConversations = await storage.queryConversations({
|
|
1814
|
+
* resourceId: 'chatbot-v1',
|
|
1815
|
+
* limit: 10,
|
|
1816
|
+
* offset: 20,
|
|
1817
|
+
* orderBy: 'created_at',
|
|
1818
|
+
* orderDirection: 'ASC'
|
|
1819
|
+
* });
|
|
1820
|
+
*
|
|
1821
|
+
* // Get all conversations (admin view)
|
|
1822
|
+
* const allConversations = await storage.queryConversations({
|
|
1823
|
+
* limit: 100,
|
|
1824
|
+
* orderBy: 'updated_at'
|
|
1825
|
+
* });
|
|
1826
|
+
* ```
|
|
1827
|
+
*/
|
|
1828
|
+
queryConversations(options: ConversationQueryOptions): Promise<Conversation[]>;
|
|
1829
|
+
/**
|
|
1830
|
+
* Get messages for a specific conversation with pagination support
|
|
1831
|
+
*
|
|
1832
|
+
* This method retrieves all messages within a conversation, ordered chronologically
|
|
1833
|
+
* from oldest to newest. It supports pagination to handle large conversations
|
|
1834
|
+
* efficiently and avoid memory issues.
|
|
1835
|
+
*
|
|
1836
|
+
* @param conversationId The unique identifier of the conversation to retrieve messages from
|
|
1837
|
+
* @param options Optional pagination and filtering options
|
|
1838
|
+
* @param options.limit Maximum number of messages to return (default: 100)
|
|
1839
|
+
* @param options.offset Number of messages to skip for pagination (default: 0)
|
|
1840
|
+
*
|
|
1841
|
+
* @returns Promise that resolves to an array of messages in chronological order (oldest first)
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* ```typescript
|
|
1845
|
+
* // Get the first 50 messages in a conversation
|
|
1846
|
+
* const messages = await storage.getConversationMessages('conv-123', {
|
|
1847
|
+
* limit: 50
|
|
1848
|
+
* });
|
|
1849
|
+
*
|
|
1850
|
+
* // Get messages with pagination (skip first 20, get next 30)
|
|
1851
|
+
* const olderMessages = await storage.getConversationMessages('conv-123', {
|
|
1852
|
+
* limit: 30,
|
|
1853
|
+
* offset: 20
|
|
1854
|
+
* });
|
|
1855
|
+
*
|
|
1856
|
+
* // Get all messages (use with caution for large conversations)
|
|
1857
|
+
* const allMessages = await storage.getConversationMessages('conv-123');
|
|
1858
|
+
*
|
|
1859
|
+
* // Process messages in batches
|
|
1860
|
+
* const batchSize = 100;
|
|
1861
|
+
* let offset = 0;
|
|
1862
|
+
* let hasMore = true;
|
|
1863
|
+
*
|
|
1864
|
+
* while (hasMore) {
|
|
1865
|
+
* const batch = await storage.getConversationMessages('conv-123', {
|
|
1866
|
+
* limit: batchSize,
|
|
1867
|
+
* offset: offset
|
|
1868
|
+
* });
|
|
1869
|
+
*
|
|
1870
|
+
* // Process batch
|
|
1871
|
+
* processBatch(batch);
|
|
1872
|
+
*
|
|
1873
|
+
* hasMore = batch.length === batchSize;
|
|
1874
|
+
* offset += batchSize;
|
|
1875
|
+
* }
|
|
1876
|
+
* ```
|
|
1877
|
+
*
|
|
1878
|
+
* @throws {Error} If the conversation ID is invalid or operation fails
|
|
1879
|
+
*/
|
|
1880
|
+
getConversationMessages(conversationId: string, options?: {
|
|
1881
|
+
limit?: number;
|
|
1882
|
+
offset?: number;
|
|
1883
|
+
}): Promise<MemoryMessage[]>;
|
|
1696
1884
|
/**
|
|
1697
1885
|
* Update a conversation
|
|
1698
1886
|
* @param id Conversation ID
|
|
@@ -1792,6 +1980,11 @@ declare class LibSQLStorage implements Memory {
|
|
|
1792
1980
|
* @param conversationId Conversation identifier (optional, defaults to "default")
|
|
1793
1981
|
*/
|
|
1794
1982
|
addMessage(message: MemoryMessage, userId?: string, conversationId?: string): Promise<void>;
|
|
1983
|
+
/**
|
|
1984
|
+
* Prune old messages to respect storage limit
|
|
1985
|
+
* @param conversationId Conversation ID to prune messages for
|
|
1986
|
+
*/
|
|
1987
|
+
private pruneOldMessages;
|
|
1795
1988
|
/**
|
|
1796
1989
|
* Clear messages from memory
|
|
1797
1990
|
*/
|
|
@@ -1856,6 +2049,27 @@ declare class LibSQLStorage implements Memory {
|
|
|
1856
2049
|
createConversation(conversation: CreateConversationInput): Promise<Conversation>;
|
|
1857
2050
|
getConversation(id: string): Promise<Conversation | null>;
|
|
1858
2051
|
getConversations(resourceId: string): Promise<Conversation[]>;
|
|
2052
|
+
getConversationsByUserId(userId: string, options?: Omit<ConversationQueryOptions, "userId">): Promise<Conversation[]>;
|
|
2053
|
+
/**
|
|
2054
|
+
* Query conversations with filtering and pagination options
|
|
2055
|
+
*
|
|
2056
|
+
* @param options Query options for filtering and pagination
|
|
2057
|
+
* @returns Promise that resolves to an array of conversations matching the criteria
|
|
2058
|
+
* @see {@link https://voltagent.ai/docs/agents/memory/libsql#querying-conversations | Querying Conversations}
|
|
2059
|
+
*/
|
|
2060
|
+
queryConversations(options: ConversationQueryOptions): Promise<Conversation[]>;
|
|
2061
|
+
/**
|
|
2062
|
+
* Get messages for a specific conversation with pagination support
|
|
2063
|
+
*
|
|
2064
|
+
* @param conversationId The unique identifier of the conversation to retrieve messages from
|
|
2065
|
+
* @param options Optional pagination and filtering options
|
|
2066
|
+
* @returns Promise that resolves to an array of messages in chronological order (oldest first)
|
|
2067
|
+
* @see {@link https://voltagent.ai/docs/agents/memory/libsql#conversation-messages | Getting Conversation Messages}
|
|
2068
|
+
*/
|
|
2069
|
+
getConversationMessages(conversationId: string, options?: {
|
|
2070
|
+
limit?: number;
|
|
2071
|
+
offset?: number;
|
|
2072
|
+
}): Promise<MemoryMessage[]>;
|
|
1859
2073
|
updateConversation(id: string, updates: Partial<Omit<Conversation, "id" | "createdAt" | "updatedAt">>): Promise<Conversation>;
|
|
1860
2074
|
deleteConversation(id: string): Promise<void>;
|
|
1861
2075
|
/**
|
|
@@ -1885,6 +2099,159 @@ declare class LibSQLStorage implements Memory {
|
|
|
1885
2099
|
error?: Error;
|
|
1886
2100
|
backupCreated?: boolean;
|
|
1887
2101
|
}>;
|
|
2102
|
+
/**
|
|
2103
|
+
* Migrate conversation schema to add user_id and update messages table
|
|
2104
|
+
*
|
|
2105
|
+
* ⚠️ **CRITICAL WARNING: DESTRUCTIVE OPERATION** ⚠️
|
|
2106
|
+
*
|
|
2107
|
+
* This method performs a DESTRUCTIVE schema migration that:
|
|
2108
|
+
* - DROPS and recreates existing tables
|
|
2109
|
+
* - Creates temporary tables during migration
|
|
2110
|
+
* - Modifies the primary key structure of the messages table
|
|
2111
|
+
* - Can cause DATA LOSS if interrupted or if errors occur
|
|
2112
|
+
*
|
|
2113
|
+
* **IMPORTANT SAFETY REQUIREMENTS:**
|
|
2114
|
+
* - 🛑 STOP all application instances before running this migration
|
|
2115
|
+
* - 🛑 Ensure NO concurrent database operations are running
|
|
2116
|
+
* - 🛑 Take a full database backup before running (independent of built-in backup)
|
|
2117
|
+
* - 🛑 Test the migration on a copy of production data first
|
|
2118
|
+
* - 🛑 Plan for downtime during migration execution
|
|
2119
|
+
*
|
|
2120
|
+
* **What this migration does:**
|
|
2121
|
+
* 1. Creates backup tables (if createBackup=true)
|
|
2122
|
+
* 2. Creates temporary tables with new schema
|
|
2123
|
+
* 3. Migrates data from old tables to new schema
|
|
2124
|
+
* 4. DROPS original tables
|
|
2125
|
+
* 5. Renames temporary tables to original names
|
|
2126
|
+
* 6. All operations are wrapped in a transaction for atomicity
|
|
2127
|
+
*
|
|
2128
|
+
* @param options Migration configuration options
|
|
2129
|
+
* @param options.createBackup Whether to create backup tables before migration (default: true, HIGHLY RECOMMENDED)
|
|
2130
|
+
* @param options.restoreFromBackup Whether to restore from existing backup instead of migrating (default: false)
|
|
2131
|
+
* @param options.deleteBackupAfterSuccess Whether to delete backup tables after successful migration (default: false)
|
|
2132
|
+
*
|
|
2133
|
+
* @returns Promise resolving to migration result with success status, migrated count, and backup info
|
|
2134
|
+
*
|
|
2135
|
+
* @example
|
|
2136
|
+
* ```typescript
|
|
2137
|
+
* // RECOMMENDED: Run with backup creation (default)
|
|
2138
|
+
* const result = await storage.migrateConversationSchema({
|
|
2139
|
+
* createBackup: true,
|
|
2140
|
+
* deleteBackupAfterSuccess: false // Keep backup for safety
|
|
2141
|
+
* });
|
|
2142
|
+
*
|
|
2143
|
+
* if (result.success) {
|
|
2144
|
+
* console.log(`Migrated ${result.migratedCount} conversations successfully`);
|
|
2145
|
+
* } else {
|
|
2146
|
+
* console.error('Migration failed:', result.error);
|
|
2147
|
+
* // Consider restoring from backup
|
|
2148
|
+
* }
|
|
2149
|
+
*
|
|
2150
|
+
* // If migration fails, restore from backup:
|
|
2151
|
+
* const restoreResult = await storage.migrateConversationSchema({
|
|
2152
|
+
* restoreFromBackup: true
|
|
2153
|
+
* });
|
|
2154
|
+
* ```
|
|
2155
|
+
*
|
|
2156
|
+
* @throws {Error} If migration fails and transaction is rolled back
|
|
2157
|
+
*
|
|
2158
|
+
* @since This migration is typically only needed when upgrading from older schema versions
|
|
2159
|
+
*/
|
|
2160
|
+
private migrateConversationSchema;
|
|
2161
|
+
/**
|
|
2162
|
+
* Get conversations for a user with a fluent query builder interface
|
|
2163
|
+
* @param userId User ID to filter by
|
|
2164
|
+
* @returns Query builder object
|
|
2165
|
+
*/
|
|
2166
|
+
getUserConversations(userId: string): {
|
|
2167
|
+
/**
|
|
2168
|
+
* Limit the number of results
|
|
2169
|
+
* @param count Number of conversations to return
|
|
2170
|
+
* @returns Query builder
|
|
2171
|
+
*/
|
|
2172
|
+
limit: (count: number) => {
|
|
2173
|
+
/**
|
|
2174
|
+
* Order results by a specific field
|
|
2175
|
+
* @param field Field to order by
|
|
2176
|
+
* @param direction Sort direction
|
|
2177
|
+
* @returns Query builder
|
|
2178
|
+
*/
|
|
2179
|
+
orderBy: (field?: "created_at" | "updated_at" | "title", direction?: "ASC" | "DESC") => {
|
|
2180
|
+
/**
|
|
2181
|
+
* Execute the query and return results
|
|
2182
|
+
* @returns Promise of conversations
|
|
2183
|
+
*/
|
|
2184
|
+
execute: () => Promise<Conversation[]>;
|
|
2185
|
+
};
|
|
2186
|
+
/**
|
|
2187
|
+
* Execute the query with default ordering
|
|
2188
|
+
* @returns Promise of conversations
|
|
2189
|
+
*/
|
|
2190
|
+
execute: () => Promise<Conversation[]>;
|
|
2191
|
+
};
|
|
2192
|
+
/**
|
|
2193
|
+
* Order results by a specific field
|
|
2194
|
+
* @param field Field to order by
|
|
2195
|
+
* @param direction Sort direction
|
|
2196
|
+
* @returns Query builder
|
|
2197
|
+
*/
|
|
2198
|
+
orderBy: (field?: "created_at" | "updated_at" | "title", direction?: "ASC" | "DESC") => {
|
|
2199
|
+
/**
|
|
2200
|
+
* Limit the number of results
|
|
2201
|
+
* @param count Number of conversations to return
|
|
2202
|
+
* @returns Query builder
|
|
2203
|
+
*/
|
|
2204
|
+
limit: (count: number) => {
|
|
2205
|
+
/**
|
|
2206
|
+
* Execute the query and return results
|
|
2207
|
+
* @returns Promise of conversations
|
|
2208
|
+
*/
|
|
2209
|
+
execute: () => Promise<Conversation[]>;
|
|
2210
|
+
};
|
|
2211
|
+
/**
|
|
2212
|
+
* Execute the query without limit
|
|
2213
|
+
* @returns Promise of conversations
|
|
2214
|
+
*/
|
|
2215
|
+
execute: () => Promise<Conversation[]>;
|
|
2216
|
+
};
|
|
2217
|
+
/**
|
|
2218
|
+
* Execute the query with default options
|
|
2219
|
+
* @returns Promise of conversations
|
|
2220
|
+
*/
|
|
2221
|
+
execute: () => Promise<Conversation[]>;
|
|
2222
|
+
};
|
|
2223
|
+
/**
|
|
2224
|
+
* Get conversation by ID and ensure it belongs to the specified user
|
|
2225
|
+
* @param conversationId Conversation ID
|
|
2226
|
+
* @param userId User ID to validate ownership
|
|
2227
|
+
* @returns Conversation or null
|
|
2228
|
+
*/
|
|
2229
|
+
getUserConversation(conversationId: string, userId: string): Promise<Conversation | null>;
|
|
2230
|
+
/**
|
|
2231
|
+
* Get paginated conversations for a user
|
|
2232
|
+
* @param userId User ID
|
|
2233
|
+
* @param page Page number (1-based)
|
|
2234
|
+
* @param pageSize Number of items per page
|
|
2235
|
+
* @returns Object with conversations and pagination info
|
|
2236
|
+
*/
|
|
2237
|
+
getPaginatedUserConversations(userId: string, page?: number, pageSize?: number): Promise<{
|
|
2238
|
+
conversations: Conversation[];
|
|
2239
|
+
page: number;
|
|
2240
|
+
pageSize: number;
|
|
2241
|
+
hasMore: boolean;
|
|
2242
|
+
}>;
|
|
2243
|
+
/**
|
|
2244
|
+
* Check and create migration flag table, return if migration already completed
|
|
2245
|
+
* @param migrationType Type of migration to check
|
|
2246
|
+
* @returns Object with completion status and details
|
|
2247
|
+
*/
|
|
2248
|
+
private checkMigrationFlag;
|
|
2249
|
+
/**
|
|
2250
|
+
* Set migration flag after successful completion
|
|
2251
|
+
* @param migrationType Type of migration completed
|
|
2252
|
+
* @param migratedCount Number of records migrated
|
|
2253
|
+
*/
|
|
2254
|
+
private setMigrationFlag;
|
|
1888
2255
|
}
|
|
1889
2256
|
|
|
1890
2257
|
/**
|
|
@@ -2207,11 +2574,19 @@ interface OnStartHookArgs {
|
|
|
2207
2574
|
context: OperationContext;
|
|
2208
2575
|
}
|
|
2209
2576
|
interface OnEndHookArgs {
|
|
2577
|
+
/**
|
|
2578
|
+
* The conversation ID.
|
|
2579
|
+
*/
|
|
2580
|
+
conversationId: string;
|
|
2581
|
+
/**
|
|
2582
|
+
* The agent that generated the output.
|
|
2583
|
+
*/
|
|
2210
2584
|
agent: Agent<any>;
|
|
2211
2585
|
/** The standardized successful output object. Undefined on error. */
|
|
2212
2586
|
output: AgentOperationOutput | undefined;
|
|
2213
2587
|
/** The VoltAgentError object if the operation failed. Undefined on success. */
|
|
2214
2588
|
error: VoltAgentError | undefined;
|
|
2589
|
+
/** The complete conversation messages including user input and assistant responses (Vercel AI SDK compatible) */
|
|
2215
2590
|
context: OperationContext;
|
|
2216
2591
|
}
|
|
2217
2592
|
interface OnHandoffHookArgs {
|
|
@@ -2475,7 +2850,7 @@ declare class Agent<TProvider extends {
|
|
|
2475
2850
|
*/
|
|
2476
2851
|
getHistory(): Promise<AgentHistoryEntry[]>;
|
|
2477
2852
|
/**
|
|
2478
|
-
* Add step to history immediately
|
|
2853
|
+
* Add step to history immediately and to conversation steps
|
|
2479
2854
|
*/
|
|
2480
2855
|
private addStepToHistory;
|
|
2481
2856
|
/**
|
|
@@ -2497,19 +2872,19 @@ declare class Agent<TProvider extends {
|
|
|
2497
2872
|
/**
|
|
2498
2873
|
* Generate a text response without streaming
|
|
2499
2874
|
*/
|
|
2500
|
-
generateText(input: string | BaseMessage[], options?: PublicGenerateOptions): Promise<
|
|
2875
|
+
generateText(input: string | BaseMessage[], options?: PublicGenerateOptions): Promise<InferGenerateTextResponseFromProvider<TProvider>>;
|
|
2501
2876
|
/**
|
|
2502
2877
|
* Stream a text response
|
|
2503
2878
|
*/
|
|
2504
|
-
streamText(input: string | BaseMessage[], options?: PublicGenerateOptions): Promise<
|
|
2879
|
+
streamText(input: string | BaseMessage[], options?: PublicGenerateOptions): Promise<InferStreamTextResponseFromProvider<TProvider>>;
|
|
2505
2880
|
/**
|
|
2506
2881
|
* Generate a structured object response
|
|
2507
2882
|
*/
|
|
2508
|
-
generateObject<
|
|
2883
|
+
generateObject<TSchema extends z.ZodType>(input: string | BaseMessage[], schema: TSchema, options?: PublicGenerateOptions): Promise<InferGenerateObjectResponseFromProvider<TProvider, TSchema>>;
|
|
2509
2884
|
/**
|
|
2510
2885
|
* Stream a structured object response
|
|
2511
2886
|
*/
|
|
2512
|
-
streamObject<
|
|
2887
|
+
streamObject<TSchema extends z.ZodType>(input: string | BaseMessage[], schema: TSchema, options?: PublicGenerateOptions): Promise<InferStreamObjectResponseFromProvider<TProvider, TSchema>>;
|
|
2513
2888
|
/**
|
|
2514
2889
|
* Add a sub-agent that this agent can delegate tasks to
|
|
2515
2890
|
*/
|
|
@@ -3387,4 +3762,4 @@ declare class VoltAgent {
|
|
|
3387
3762
|
shutdownTelemetry(): Promise<void>;
|
|
3388
3763
|
}
|
|
3389
3764
|
|
|
3390
|
-
export { Agent, AgentErrorEvent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentStartEvent, AgentStartEventMetadata, AgentSuccessEvent, AgentSuccessEventMetadata, AgentTool, AllowedVariableValue, AnyToolConfig, BaseEventMetadata, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTimelineEvent, BaseTool, BaseToolCall, ClientInfo, Conversation, CreateConversationInput, CreateReasoningToolsOptions, CustomEndpointDefinition, CustomEndpointError, CustomEndpointHandler, DEFAULT_INSTRUCTIONS, DataContent, EventStatus, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, HistoryStatus, HttpMethod, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryEventMetadata, MemoryManager, MemoryMessage, MemoryOptions, MemoryReadErrorEvent, MemoryReadStartEvent, MemoryReadSuccessEvent, MemoryWriteErrorEvent, MemoryWriteStartEvent, MemoryWriteSuccessEvent, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NewTimelineEvent, NextAction, NodeType, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptCreator, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningToolExecuteOptions, RetrieveOptions, Retriever, RetrieverErrorEvent, RetrieverOptions, RetrieverStartEvent, RetrieverSuccessEvent, RetryConfig, StandardEventData, StandardTimelineEvent, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, TemplateVariables, TextPart, TimelineEventCoreLevel, TimelineEventCoreStatus, TimelineEventCoreType, Tool, ToolCall, ToolErrorEvent, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolSchema, ToolStartEvent, ToolStatus, ToolStatusInfo, ToolSuccessEvent, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, Usage, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, checkForUpdates, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };
|
|
3765
|
+
export { Agent, AgentErrorEvent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentStartEvent, AgentStartEventMetadata, AgentSuccessEvent, AgentSuccessEventMetadata, AgentTool, AllowedVariableValue, AnyToolConfig, AsyncIterableStream, BaseEventMetadata, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTimelineEvent, BaseTool, BaseToolCall, ClientInfo, Conversation, ConversationQueryOptions, CreateConversationInput, CreateReasoningToolsOptions, CustomEndpointDefinition, CustomEndpointError, CustomEndpointHandler, DEFAULT_INSTRUCTIONS, DataContent, EventStatus, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, HistoryStatus, HttpMethod, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryEventMetadata, MemoryManager, MemoryMessage, MemoryOptions, MemoryReadErrorEvent, MemoryReadStartEvent, MemoryReadSuccessEvent, MemoryWriteErrorEvent, MemoryWriteStartEvent, MemoryWriteSuccessEvent, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NewTimelineEvent, NextAction, NodeType, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptCreator, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningToolExecuteOptions, RetrieveOptions, Retriever, RetrieverErrorEvent, RetrieverOptions, RetrieverStartEvent, RetrieverSuccessEvent, RetryConfig, StandardEventData, StandardTimelineEvent, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, TemplateVariables, TextPart, TimelineEventCoreLevel, TimelineEventCoreStatus, TimelineEventCoreType, Tool, ToolCall, ToolErrorEvent, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolSchema, ToolStartEvent, ToolStatus, ToolStatusInfo, ToolSuccessEvent, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, Usage, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, checkForUpdates, createAsyncIterableStream, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };
|