@voltagent/libsql 1.0.13 → 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.ts 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.js';
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,166 +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
- * Set workflow state
165
- */
166
- setWorkflowState(executionId: string, state: WorkflowStateEntry): Promise<void>;
167
- /**
168
- * Update workflow state
169
- */
170
- updateWorkflowState(executionId: string, updates: Partial<WorkflowStateEntry>): Promise<void>;
171
- /**
172
- * Get suspended workflow states for a workflow
173
- */
174
- getSuspendedWorkflowStates(workflowId: string): Promise<WorkflowStateEntry[]>;
175
- /**
176
- * Close database connection
177
- */
178
- close(): Promise<void>;
179
43
  }
180
44
 
181
45
  /**
182
- * LibSQL Observability Adapter
46
+ * LibSQL Observability Adapter - Node.js
183
47
  * Provides persistent storage for OpenTelemetry spans using LibSQL/Turso database
184
- * Part of the OpenTelemetry observability migration (Phase 3)
185
48
  */
186
49
 
187
50
  /**
188
51
  * Options for configuring the LibSQLObservabilityAdapter
189
52
  */
190
- interface LibSQLObservabilityOptions {
53
+ interface LibSQLObservabilityOptions extends LibSQLObservabilityCoreOptions {
191
54
  /**
192
55
  * LibSQL connection URL
193
56
  * Can be either a remote Turso URL or a local file path
194
57
  * @default "file:./.voltagent/observability.db"
195
- * @example "libsql://your-database.turso.io" for remote Turso
196
- * @example "file:observability.db" for local SQLite in current directory
197
- * @example "file:.voltagent/observability.db" for local SQLite in .voltagent folder
198
58
  */
199
59
  url?: string;
200
60
  /**
@@ -202,141 +62,29 @@ interface LibSQLObservabilityOptions {
202
62
  * Not needed for local SQLite
203
63
  */
204
64
  authToken?: string;
205
- /**
206
- * Prefix for table names
207
- * @default "observability"
208
- */
209
- tablePrefix?: string;
210
- /**
211
- * Whether to enable debug logging
212
- * @default false
213
- */
214
- debug?: boolean;
215
65
  /**
216
66
  * Optional logger instance
217
67
  */
218
68
  logger?: Logger;
219
- /**
220
- * Maximum number of spans to return in a single query
221
- * @default 1000
222
- */
223
- maxSpansPerQuery?: number;
224
69
  }
225
70
  /**
226
- * LibSQL Observability Adapter
71
+ * LibSQL Observability Adapter - Node.js
227
72
  * Provides observability storage using LibSQL/Turso database
228
- * Implements the ObservabilityStorageAdapter interface for OpenTelemetry spans
73
+ * Supports both local SQLite files and remote Turso databases
229
74
  */
230
- declare class LibSQLObservabilityAdapter implements ObservabilityStorageAdapter {
231
- private client;
232
- private tablePrefix;
233
- private debug;
234
- private logger;
235
- private initialized;
236
- private maxSpansPerQuery;
75
+ declare class LibSQLObservabilityAdapter extends LibSQLObservabilityCore {
237
76
  constructor(options?: LibSQLObservabilityOptions);
238
- /**
239
- * Log a debug message if debug is enabled
240
- */
241
- private debugLog;
242
- /**
243
- * Initialize database tables for observability
244
- */
245
- private initializeDatabase;
246
- /**
247
- * Ensure database is initialized before operations
248
- */
249
- private ensureInitialized;
250
- /**
251
- * Add a span to the database
252
- */
253
- addSpan(span: ObservabilitySpan): Promise<void>;
254
- /**
255
- * Update an existing span
256
- */
257
- updateSpan(spanId: string, updates: Partial<ObservabilitySpan>): Promise<void>;
258
- /**
259
- * Get a span by ID
260
- */
261
- getSpan(spanId: string): Promise<ObservabilitySpan | null>;
262
- /**
263
- * Get all spans in a trace
264
- */
265
- getTrace(traceId: string): Promise<ObservabilitySpan[]>;
266
- /**
267
- * List all traces with optional entity filter
268
- */
269
- listTraces(limit?: number, offset?: number, filter?: {
270
- entityId?: string;
271
- entityType?: "agent" | "workflow";
272
- }): Promise<string[]>;
273
- /**
274
- * Delete old spans
275
- */
276
- deleteOldSpans(beforeTimestamp: number): Promise<number>;
277
- /**
278
- * Clear all spans, traces, and logs
279
- */
280
- clear(): Promise<void>;
281
- /**
282
- * Convert a database row to an ObservabilitySpan
283
- */
284
- private rowToSpan;
285
- /**
286
- * Get statistics about stored spans
287
- */
288
- getStats(): Promise<{
289
- spanCount: number;
290
- traceCount: number;
291
- oldestSpan?: Date;
292
- newestSpan?: Date;
293
- }>;
294
- /**
295
- * Save a log record to the database
296
- */
297
- saveLogRecord(logRecord: any): Promise<void>;
298
- /**
299
- * Get logs by trace ID
300
- */
301
- getLogsByTraceId(traceId: string): Promise<ObservabilityLogRecord[]>;
302
- /**
303
- * Get logs by span ID
304
- */
305
- getLogsBySpanId(spanId: string): Promise<ObservabilityLogRecord[]>;
306
- /**
307
- * Query logs with flexible filtering
308
- */
309
- queryLogs(filter: LogFilter): Promise<ObservabilityLogRecord[]>;
310
- /**
311
- * Delete old logs
312
- */
313
- deleteOldLogs(beforeTimestamp: number): Promise<number>;
314
- /**
315
- * Convert a database row to an ObservabilityLogRecord
316
- */
317
- private rowToLogRecord;
318
- getInfo(): {
319
- adapter: string;
320
- displayName: string;
321
- persistent: boolean;
322
- description: string;
323
- };
324
- /**
325
- * Close the database connection
326
- */
327
- close(): Promise<void>;
328
77
  }
329
78
 
330
79
  /**
331
- * LibSQL Vector Adapter
80
+ * LibSQL Vector Adapter - Node.js
332
81
  * Provides vector storage and similarity search using LibSQL/Turso database
333
- * Stores vectors as binary BLOBs for efficiency
334
82
  */
335
83
 
336
84
  /**
337
85
  * LibSQL Vector Adapter configuration options
338
86
  */
339
- interface LibSQLVectorOptions {
87
+ interface LibSQLVectorOptions extends LibSQLVectorCoreOptions {
340
88
  /**
341
89
  * Database URL (e.g., 'file:./memory.db' or 'libsql://...')
342
90
  * @default "file:./.voltagent/memory.db"
@@ -346,130 +94,26 @@ interface LibSQLVectorOptions {
346
94
  * Auth token for remote connections (optional)
347
95
  */
348
96
  authToken?: string;
349
- /**
350
- * Prefix for table names
351
- * @default "voltagent"
352
- */
353
- tablePrefix?: string;
354
- /**
355
- * Maximum vector dimensions allowed
356
- * @default 1536
357
- */
358
- maxVectorDimensions?: number;
359
- /**
360
- * Size of the LRU cache for frequently accessed vectors
361
- * @default 100
362
- */
363
- cacheSize?: number;
364
- /**
365
- * Batch size for bulk operations
366
- * @default 100
367
- */
368
- batchSize?: number;
369
- /**
370
- * Enable debug logging
371
- * @default false
372
- */
373
- debug?: boolean;
374
97
  /**
375
98
  * Logger instance
376
99
  */
377
100
  logger?: Logger;
378
- /**
379
- * Maximum number of retries for database operations
380
- * @default 3
381
- */
382
- maxRetries?: number;
383
- /**
384
- * Initial retry delay in milliseconds
385
- * @default 100
386
- */
387
- retryDelayMs?: number;
388
101
  }
389
102
  /**
390
- * LibSQL Vector Adapter
103
+ * LibSQL Vector Adapter - Node.js
391
104
  * Production-ready vector storage with similarity search
105
+ * Supports both local SQLite files and remote Turso databases
392
106
  */
393
- declare class LibSQLVectorAdapter implements VectorAdapter {
394
- private client;
395
- private tablePrefix;
396
- private maxVectorDimensions;
397
- private cacheSize;
398
- private batchSize;
399
- private debug;
400
- private logger;
401
- private maxRetries;
402
- private retryDelayMs;
403
- private url;
404
- private initialized;
405
- private vectorCache;
406
- private dimensions;
107
+ declare class LibSQLVectorAdapter extends LibSQLVectorCore {
407
108
  constructor(options?: LibSQLVectorOptions);
408
109
  /**
409
- * Initialize the database schema
410
- */
411
- private initialize;
412
- /**
413
- * Serialize a vector to binary format
414
- */
415
- private serializeVector;
416
- /**
417
- * Deserialize a vector from binary format
418
- */
419
- private deserializeVector;
420
- /**
421
- * Execute a database operation with retries
422
- */
423
- private executeWithRetry;
424
- /**
425
- * Store a vector with associated metadata
426
- */
427
- store(id: string, vector: number[], metadata?: Record<string, unknown>): Promise<void>;
428
- /**
429
- * Store multiple vectors in batch
430
- */
431
- storeBatch(items: VectorItem[]): Promise<void>;
432
- /**
433
- * Search for similar vectors using cosine similarity
434
- */
435
- search(queryVector: number[], options?: VectorSearchOptions): Promise<SearchResult[]>;
436
- /**
437
- * Check if metadata matches the filter criteria
438
- */
439
- private matchesFilter;
440
- /**
441
- * Delete a vector by ID
442
- */
443
- delete(id: string): Promise<void>;
444
- /**
445
- * Delete multiple vectors by IDs
446
- */
447
- deleteBatch(ids: string[]): Promise<void>;
448
- /**
449
- * Clear all vectors
450
- */
451
- clear(): Promise<void>;
452
- /**
453
- * Get total count of stored vectors
454
- */
455
- count(): Promise<number>;
456
- /**
457
- * Get a specific vector by ID
458
- */
459
- get(id: string): Promise<VectorItem | null>;
460
- /**
461
- * Close the database connection
110
+ * Override to use Buffer for more efficient serialization in Node.js
462
111
  */
463
- close(): Promise<void>;
112
+ protected serializeVector(vector: number[]): Uint8Array;
464
113
  /**
465
- * Get statistics about the vector table and cache
114
+ * Override to use Buffer for more efficient deserialization in Node.js
466
115
  */
467
- getStats(): Promise<{
468
- count: number;
469
- dimensions: number | null;
470
- cacheSize: number;
471
- tableSizeBytes: number;
472
- }>;
116
+ protected deserializeVector(data: Uint8Array | ArrayBuffer): number[];
473
117
  }
474
118
 
475
119
  export { LibSQLMemoryAdapter, type LibSQLMemoryOptions, LibSQLObservabilityAdapter, type LibSQLObservabilityOptions, LibSQLVectorAdapter, type LibSQLVectorOptions };