@voltagent/libsql 1.0.14 → 1.1.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/index.d.mts CHANGED
@@ -1,17 +1,19 @@
1
- import { StorageAdapter, ConversationStepRecord, GetMessagesOptions, GetConversationStepsOptions, CreateConversationInput, Conversation, ConversationQueryOptions, WorkingMemoryScope, WorkflowStateEntry, ObservabilityStorageAdapter, ObservabilitySpan, ObservabilityLogRecord, LogFilter, VectorAdapter, VectorItem, VectorSearchOptions, SearchResult } from '@voltagent/core';
2
1
  import { Logger } from '@voltagent/logger';
3
- import { UIMessage } from 'ai';
2
+ import { L as LibSQLMemoryCore, a as LibSQLMemoryCoreOptions, b as LibSQLObservabilityCore, c as LibSQLObservabilityCoreOptions, d as LibSQLVectorCore, e as LibSQLVectorCoreOptions } from './vector-core-CKn8FNVK.mjs';
3
+ import '@libsql/client';
4
+ import '@voltagent/core';
5
+ import 'ai';
4
6
 
5
7
  /**
6
- * LibSQL Storage Adapter for Memory
8
+ * LibSQL Storage Adapter for Memory - Node.js
7
9
  * Stores conversations and messages in SQLite/Turso database
8
- * Compatible with existing LibSQL storage structure
10
+ * Supports both local file databases and remote Turso connections
9
11
  */
10
12
 
11
13
  /**
12
14
  * LibSQL configuration options for Memory
13
15
  */
14
- interface LibSQLMemoryOptions {
16
+ interface LibSQLMemoryOptions extends LibSQLMemoryCoreOptions {
15
17
  /**
16
18
  * Database URL (e.g., 'file:./conversations.db' or 'libsql://...')
17
19
  * @default "file:./.voltagent/memory.db"
@@ -21,11 +23,6 @@ interface LibSQLMemoryOptions {
21
23
  * Auth token for remote connections (optional)
22
24
  */
23
25
  authToken?: string;
24
- /**
25
- * Prefix for table names
26
- * @default "voltagent_memory"
27
- */
28
- tablePrefix?: string;
29
26
  /**
30
27
  * Enable debug logging
31
28
  * @default false
@@ -35,177 +32,29 @@ interface LibSQLMemoryOptions {
35
32
  * Logger instance
36
33
  */
37
34
  logger?: Logger;
38
- /**
39
- * Maximum number of retries for database operations
40
- * @default 3
41
- */
42
- maxRetries?: number;
43
- /**
44
- * Initial retry delay in milliseconds
45
- * @default 100
46
- */
47
- retryDelayMs?: number;
48
35
  }
49
36
  /**
50
- * LibSQL Storage Adapter for Memory
37
+ * LibSQL Storage Adapter for Memory - Node.js
51
38
  * Production-ready storage for conversations and messages
52
- * Compatible with existing LibSQL storage structure
39
+ * Supports both local SQLite files and remote Turso databases
53
40
  */
54
- declare class LibSQLMemoryAdapter implements StorageAdapter {
55
- private client;
56
- private tablePrefix;
57
- private initialized;
58
- private logger;
59
- private maxRetries;
60
- private retryDelayMs;
61
- private url;
41
+ declare class LibSQLMemoryAdapter extends LibSQLMemoryCore {
62
42
  constructor(options?: LibSQLMemoryOptions);
63
- /**
64
- * Execute a database operation with retry logic
65
- */
66
- private executeWithRetry;
67
- /**
68
- * Initialize database schema
69
- */
70
- private initialize;
71
- /**
72
- * Add new columns to messages table for V2 format if they don't exist
73
- * This allows existing tables to support both old and new message formats
74
- */
75
- private addV2ColumnsToMessagesTable;
76
- /**
77
- * Migrate default user_id values in messages table
78
- * Updates messages with user_id='default' to use the actual user_id from their conversation
79
- */
80
- private migrateDefaultUserIds;
81
- /**
82
- * Add new columns to workflow_states table for event persistence
83
- * This migration adds support for events, output, and cancellation tracking
84
- */
85
- private addWorkflowStateColumns;
86
- /**
87
- * Add a single message
88
- */
89
- addMessage(message: UIMessage, userId: string, conversationId: string): Promise<void>;
90
- /**
91
- * Add multiple messages
92
- */
93
- addMessages(messages: UIMessage[], userId: string, conversationId: string): Promise<void>;
94
- saveConversationSteps(steps: ConversationStepRecord[]): Promise<void>;
95
- /**
96
- * Get messages with optional filtering
97
- */
98
- getMessages(userId: string, conversationId: string, options?: GetMessagesOptions): Promise<UIMessage<{
99
- createdAt: Date;
100
- }>[]>;
101
- getConversationSteps(userId: string, conversationId: string, options?: GetConversationStepsOptions): Promise<ConversationStepRecord[]>;
102
- /**
103
- * Clear messages for a user
104
- */
105
- clearMessages(userId: string, conversationId?: string): Promise<void>;
106
- /**
107
- * Create a new conversation
108
- */
109
- createConversation(input: CreateConversationInput): Promise<Conversation>;
110
- /**
111
- * Get a conversation by ID
112
- */
113
- getConversation(id: string): Promise<Conversation | null>;
114
- /**
115
- * Get conversations by resource ID
116
- */
117
- getConversations(resourceId: string): Promise<Conversation[]>;
118
- /**
119
- * Get conversations by user ID
120
- */
121
- getConversationsByUserId(userId: string, options?: Omit<ConversationQueryOptions, "userId">): Promise<Conversation[]>;
122
- /**
123
- * Query conversations with filters
124
- */
125
- queryConversations(options: ConversationQueryOptions): Promise<Conversation[]>;
126
- /**
127
- * Update a conversation
128
- */
129
- updateConversation(id: string, updates: Partial<Omit<Conversation, "id" | "createdAt" | "updatedAt">>): Promise<Conversation>;
130
- /**
131
- * Delete a conversation
132
- */
133
- deleteConversation(id: string): Promise<void>;
134
- /**
135
- * Get working memory
136
- */
137
- getWorkingMemory(params: {
138
- conversationId?: string;
139
- userId?: string;
140
- scope: WorkingMemoryScope;
141
- }): Promise<string | null>;
142
- /**
143
- * Set working memory
144
- */
145
- setWorkingMemory(params: {
146
- conversationId?: string;
147
- userId?: string;
148
- content: string;
149
- scope: WorkingMemoryScope;
150
- }): Promise<void>;
151
- /**
152
- * Delete working memory
153
- */
154
- deleteWorkingMemory(params: {
155
- conversationId?: string;
156
- userId?: string;
157
- scope: WorkingMemoryScope;
158
- }): Promise<void>;
159
- /**
160
- * Get workflow state by execution ID
161
- */
162
- getWorkflowState(executionId: string): Promise<WorkflowStateEntry | null>;
163
- /**
164
- * Query workflow states with optional filters
165
- */
166
- queryWorkflowRuns(query: {
167
- workflowId?: string;
168
- status?: WorkflowStateEntry["status"];
169
- from?: Date;
170
- to?: Date;
171
- limit?: number;
172
- offset?: number;
173
- }): Promise<WorkflowStateEntry[]>;
174
- /**
175
- * Set workflow state
176
- */
177
- setWorkflowState(executionId: string, state: WorkflowStateEntry): Promise<void>;
178
- /**
179
- * Update workflow state
180
- */
181
- updateWorkflowState(executionId: string, updates: Partial<WorkflowStateEntry>): Promise<void>;
182
- /**
183
- * Get suspended workflow states for a workflow
184
- */
185
- getSuspendedWorkflowStates(workflowId: string): Promise<WorkflowStateEntry[]>;
186
- /**
187
- * Close database connection
188
- */
189
- close(): Promise<void>;
190
43
  }
191
44
 
192
45
  /**
193
- * LibSQL Observability Adapter
46
+ * LibSQL Observability Adapter - Node.js
194
47
  * Provides persistent storage for OpenTelemetry spans using LibSQL/Turso database
195
- * Part of the OpenTelemetry observability migration (Phase 3)
196
48
  */
197
49
 
198
50
  /**
199
51
  * Options for configuring the LibSQLObservabilityAdapter
200
52
  */
201
- interface LibSQLObservabilityOptions {
53
+ interface LibSQLObservabilityOptions extends LibSQLObservabilityCoreOptions {
202
54
  /**
203
55
  * LibSQL connection URL
204
56
  * Can be either a remote Turso URL or a local file path
205
57
  * @default "file:./.voltagent/observability.db"
206
- * @example "libsql://your-database.turso.io" for remote Turso
207
- * @example "file:observability.db" for local SQLite in current directory
208
- * @example "file:.voltagent/observability.db" for local SQLite in .voltagent folder
209
58
  */
210
59
  url?: string;
211
60
  /**
@@ -213,141 +62,29 @@ interface LibSQLObservabilityOptions {
213
62
  * Not needed for local SQLite
214
63
  */
215
64
  authToken?: string;
216
- /**
217
- * Prefix for table names
218
- * @default "observability"
219
- */
220
- tablePrefix?: string;
221
- /**
222
- * Whether to enable debug logging
223
- * @default false
224
- */
225
- debug?: boolean;
226
65
  /**
227
66
  * Optional logger instance
228
67
  */
229
68
  logger?: Logger;
230
- /**
231
- * Maximum number of spans to return in a single query
232
- * @default 1000
233
- */
234
- maxSpansPerQuery?: number;
235
69
  }
236
70
  /**
237
- * LibSQL Observability Adapter
71
+ * LibSQL Observability Adapter - Node.js
238
72
  * Provides observability storage using LibSQL/Turso database
239
- * Implements the ObservabilityStorageAdapter interface for OpenTelemetry spans
73
+ * Supports both local SQLite files and remote Turso databases
240
74
  */
241
- declare class LibSQLObservabilityAdapter implements ObservabilityStorageAdapter {
242
- private client;
243
- private tablePrefix;
244
- private debug;
245
- private logger;
246
- private initialized;
247
- private maxSpansPerQuery;
75
+ declare class LibSQLObservabilityAdapter extends LibSQLObservabilityCore {
248
76
  constructor(options?: LibSQLObservabilityOptions);
249
- /**
250
- * Log a debug message if debug is enabled
251
- */
252
- private debugLog;
253
- /**
254
- * Initialize database tables for observability
255
- */
256
- private initializeDatabase;
257
- /**
258
- * Ensure database is initialized before operations
259
- */
260
- private ensureInitialized;
261
- /**
262
- * Add a span to the database
263
- */
264
- addSpan(span: ObservabilitySpan): Promise<void>;
265
- /**
266
- * Update an existing span
267
- */
268
- updateSpan(spanId: string, updates: Partial<ObservabilitySpan>): Promise<void>;
269
- /**
270
- * Get a span by ID
271
- */
272
- getSpan(spanId: string): Promise<ObservabilitySpan | null>;
273
- /**
274
- * Get all spans in a trace
275
- */
276
- getTrace(traceId: string): Promise<ObservabilitySpan[]>;
277
- /**
278
- * List all traces with optional entity filter
279
- */
280
- listTraces(limit?: number, offset?: number, filter?: {
281
- entityId?: string;
282
- entityType?: "agent" | "workflow";
283
- }): Promise<string[]>;
284
- /**
285
- * Delete old spans
286
- */
287
- deleteOldSpans(beforeTimestamp: number): Promise<number>;
288
- /**
289
- * Clear all spans, traces, and logs
290
- */
291
- clear(): Promise<void>;
292
- /**
293
- * Convert a database row to an ObservabilitySpan
294
- */
295
- private rowToSpan;
296
- /**
297
- * Get statistics about stored spans
298
- */
299
- getStats(): Promise<{
300
- spanCount: number;
301
- traceCount: number;
302
- oldestSpan?: Date;
303
- newestSpan?: Date;
304
- }>;
305
- /**
306
- * Save a log record to the database
307
- */
308
- saveLogRecord(logRecord: any): Promise<void>;
309
- /**
310
- * Get logs by trace ID
311
- */
312
- getLogsByTraceId(traceId: string): Promise<ObservabilityLogRecord[]>;
313
- /**
314
- * Get logs by span ID
315
- */
316
- getLogsBySpanId(spanId: string): Promise<ObservabilityLogRecord[]>;
317
- /**
318
- * Query logs with flexible filtering
319
- */
320
- queryLogs(filter: LogFilter): Promise<ObservabilityLogRecord[]>;
321
- /**
322
- * Delete old logs
323
- */
324
- deleteOldLogs(beforeTimestamp: number): Promise<number>;
325
- /**
326
- * Convert a database row to an ObservabilityLogRecord
327
- */
328
- private rowToLogRecord;
329
- getInfo(): {
330
- adapter: string;
331
- displayName: string;
332
- persistent: boolean;
333
- description: string;
334
- };
335
- /**
336
- * Close the database connection
337
- */
338
- close(): Promise<void>;
339
77
  }
340
78
 
341
79
  /**
342
- * LibSQL Vector Adapter
80
+ * LibSQL Vector Adapter - Node.js
343
81
  * Provides vector storage and similarity search using LibSQL/Turso database
344
- * Stores vectors as binary BLOBs for efficiency
345
82
  */
346
83
 
347
84
  /**
348
85
  * LibSQL Vector Adapter configuration options
349
86
  */
350
- interface LibSQLVectorOptions {
87
+ interface LibSQLVectorOptions extends LibSQLVectorCoreOptions {
351
88
  /**
352
89
  * Database URL (e.g., 'file:./memory.db' or 'libsql://...')
353
90
  * @default "file:./.voltagent/memory.db"
@@ -357,130 +94,26 @@ interface LibSQLVectorOptions {
357
94
  * Auth token for remote connections (optional)
358
95
  */
359
96
  authToken?: string;
360
- /**
361
- * Prefix for table names
362
- * @default "voltagent"
363
- */
364
- tablePrefix?: string;
365
- /**
366
- * Maximum vector dimensions allowed
367
- * @default 1536
368
- */
369
- maxVectorDimensions?: number;
370
- /**
371
- * Size of the LRU cache for frequently accessed vectors
372
- * @default 100
373
- */
374
- cacheSize?: number;
375
- /**
376
- * Batch size for bulk operations
377
- * @default 100
378
- */
379
- batchSize?: number;
380
- /**
381
- * Enable debug logging
382
- * @default false
383
- */
384
- debug?: boolean;
385
97
  /**
386
98
  * Logger instance
387
99
  */
388
100
  logger?: Logger;
389
- /**
390
- * Maximum number of retries for database operations
391
- * @default 3
392
- */
393
- maxRetries?: number;
394
- /**
395
- * Initial retry delay in milliseconds
396
- * @default 100
397
- */
398
- retryDelayMs?: number;
399
101
  }
400
102
  /**
401
- * LibSQL Vector Adapter
103
+ * LibSQL Vector Adapter - Node.js
402
104
  * Production-ready vector storage with similarity search
105
+ * Supports both local SQLite files and remote Turso databases
403
106
  */
404
- declare class LibSQLVectorAdapter implements VectorAdapter {
405
- private client;
406
- private tablePrefix;
407
- private maxVectorDimensions;
408
- private cacheSize;
409
- private batchSize;
410
- private debug;
411
- private logger;
412
- private maxRetries;
413
- private retryDelayMs;
414
- private url;
415
- private initialized;
416
- private vectorCache;
417
- private dimensions;
107
+ declare class LibSQLVectorAdapter extends LibSQLVectorCore {
418
108
  constructor(options?: LibSQLVectorOptions);
419
109
  /**
420
- * Initialize the database schema
421
- */
422
- private initialize;
423
- /**
424
- * Serialize a vector to binary format
425
- */
426
- private serializeVector;
427
- /**
428
- * Deserialize a vector from binary format
429
- */
430
- private deserializeVector;
431
- /**
432
- * Execute a database operation with retries
433
- */
434
- private executeWithRetry;
435
- /**
436
- * Store a vector with associated metadata
437
- */
438
- store(id: string, vector: number[], metadata?: Record<string, unknown>): Promise<void>;
439
- /**
440
- * Store multiple vectors in batch
441
- */
442
- storeBatch(items: VectorItem[]): Promise<void>;
443
- /**
444
- * Search for similar vectors using cosine similarity
445
- */
446
- search(queryVector: number[], options?: VectorSearchOptions): Promise<SearchResult[]>;
447
- /**
448
- * Check if metadata matches the filter criteria
449
- */
450
- private matchesFilter;
451
- /**
452
- * Delete a vector by ID
453
- */
454
- delete(id: string): Promise<void>;
455
- /**
456
- * Delete multiple vectors by IDs
457
- */
458
- deleteBatch(ids: string[]): Promise<void>;
459
- /**
460
- * Clear all vectors
461
- */
462
- clear(): Promise<void>;
463
- /**
464
- * Get total count of stored vectors
465
- */
466
- count(): Promise<number>;
467
- /**
468
- * Get a specific vector by ID
469
- */
470
- get(id: string): Promise<VectorItem | null>;
471
- /**
472
- * Close the database connection
110
+ * Override to use Buffer for more efficient serialization in Node.js
473
111
  */
474
- close(): Promise<void>;
112
+ protected serializeVector(vector: number[]): Uint8Array;
475
113
  /**
476
- * Get statistics about the vector table and cache
114
+ * Override to use Buffer for more efficient deserialization in Node.js
477
115
  */
478
- getStats(): Promise<{
479
- count: number;
480
- dimensions: number | null;
481
- cacheSize: number;
482
- tableSizeBytes: number;
483
- }>;
116
+ protected deserializeVector(data: Uint8Array | ArrayBuffer): number[];
484
117
  }
485
118
 
486
119
  export { LibSQLMemoryAdapter, type LibSQLMemoryOptions, LibSQLObservabilityAdapter, type LibSQLObservabilityOptions, LibSQLVectorAdapter, type LibSQLVectorOptions };