@mastra/libsql 1.0.0-beta.8 → 1.0.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +1358 -0
  2. package/dist/docs/README.md +39 -0
  3. package/dist/docs/SKILL.md +40 -0
  4. package/dist/docs/SOURCE_MAP.json +6 -0
  5. package/dist/docs/agents/01-agent-memory.md +166 -0
  6. package/dist/docs/agents/02-networks.md +292 -0
  7. package/dist/docs/agents/03-agent-approval.md +377 -0
  8. package/dist/docs/agents/04-network-approval.md +274 -0
  9. package/dist/docs/core/01-reference.md +151 -0
  10. package/dist/docs/guides/01-ai-sdk.md +141 -0
  11. package/dist/docs/memory/01-overview.md +76 -0
  12. package/dist/docs/memory/02-storage.md +233 -0
  13. package/dist/docs/memory/03-working-memory.md +390 -0
  14. package/dist/docs/memory/04-semantic-recall.md +233 -0
  15. package/dist/docs/memory/05-memory-processors.md +318 -0
  16. package/dist/docs/memory/06-reference.md +133 -0
  17. package/dist/docs/observability/01-overview.md +64 -0
  18. package/dist/docs/observability/02-default.md +177 -0
  19. package/dist/docs/rag/01-retrieval.md +548 -0
  20. package/dist/docs/storage/01-reference.md +542 -0
  21. package/dist/docs/vectors/01-reference.md +213 -0
  22. package/dist/docs/workflows/01-snapshots.md +240 -0
  23. package/dist/index.cjs +2394 -1824
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.js +2392 -1827
  26. package/dist/index.js.map +1 -1
  27. package/dist/storage/db/index.d.ts +305 -0
  28. package/dist/storage/db/index.d.ts.map +1 -0
  29. package/dist/storage/{domains → db}/utils.d.ts +21 -13
  30. package/dist/storage/db/utils.d.ts.map +1 -0
  31. package/dist/storage/domains/agents/index.d.ts +5 -7
  32. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  33. package/dist/storage/domains/memory/index.d.ts +8 -10
  34. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  35. package/dist/storage/domains/observability/index.d.ts +42 -27
  36. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  37. package/dist/storage/domains/scores/index.d.ts +11 -27
  38. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  39. package/dist/storage/domains/workflows/index.d.ts +10 -14
  40. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  41. package/dist/storage/index.d.ts +28 -189
  42. package/dist/storage/index.d.ts.map +1 -1
  43. package/dist/vector/index.d.ts +6 -2
  44. package/dist/vector/index.d.ts.map +1 -1
  45. package/dist/vector/sql-builder.d.ts.map +1 -1
  46. package/package.json +9 -8
  47. package/dist/storage/domains/operations/index.d.ts +0 -110
  48. package/dist/storage/domains/operations/index.d.ts.map +0 -1
  49. package/dist/storage/domains/utils.d.ts.map +0 -1
@@ -0,0 +1,305 @@
1
+ import type { Client, InValue } from '@libsql/client';
2
+ import { MastraBase } from '@mastra/core/base';
3
+ import type { TABLE_NAMES, StorageColumn } from '@mastra/core/storage';
4
+ /**
5
+ * Base configuration options shared across LibSQL domain configurations
6
+ */
7
+ export type LibSQLDomainBaseConfig = {
8
+ /**
9
+ * Maximum number of retries for write operations if an SQLITE_BUSY error occurs.
10
+ * @default 5
11
+ */
12
+ maxRetries?: number;
13
+ /**
14
+ * Initial backoff time in milliseconds for retrying write operations on SQLITE_BUSY.
15
+ * The backoff time will double with each retry (exponential backoff).
16
+ * @default 100
17
+ */
18
+ initialBackoffMs?: number;
19
+ };
20
+ /**
21
+ * Configuration for LibSQL domains - accepts either credentials or an existing client
22
+ */
23
+ export type LibSQLDomainConfig = (LibSQLDomainBaseConfig & {
24
+ /** The database connection URL (e.g., "file:local.db", "libsql://...", "file::memory:") */
25
+ url: string;
26
+ /** Optional authentication token for remote databases */
27
+ authToken?: string;
28
+ }) | (LibSQLDomainBaseConfig & {
29
+ /** An existing LibSQL client instance */
30
+ client: Client;
31
+ });
32
+ /**
33
+ * Resolves a LibSQLDomainConfig to a Client instance.
34
+ * Creates a new client if credentials are provided, or returns the existing client.
35
+ *
36
+ * @param config - The domain configuration
37
+ * @returns The resolved LibSQL client
38
+ */
39
+ export declare function resolveClient(config: LibSQLDomainConfig): Client;
40
+ export declare class LibSQLDB extends MastraBase {
41
+ private client;
42
+ maxRetries: number;
43
+ initialBackoffMs: number;
44
+ executeWriteOperationWithRetry: <T>(operationFn: () => Promise<T>, operationDescription: string) => Promise<T>;
45
+ constructor({ client, maxRetries, initialBackoffMs, }: {
46
+ client: Client;
47
+ maxRetries?: number;
48
+ initialBackoffMs?: number;
49
+ });
50
+ /**
51
+ * Checks if a column exists in the specified table.
52
+ *
53
+ * @param table - The name of the table to check
54
+ * @param column - The name of the column to look for
55
+ * @returns `true` if the column exists in the table, `false` otherwise
56
+ */
57
+ hasColumn(table: string, column: string): Promise<boolean>;
58
+ /**
59
+ * Internal insert implementation without retry logic.
60
+ */
61
+ private doInsert;
62
+ /**
63
+ * Inserts or replaces a record in the specified table with automatic retry on lock errors.
64
+ *
65
+ * @param args - The insert arguments
66
+ * @param args.tableName - The name of the table to insert into
67
+ * @param args.record - The record to insert (key-value pairs)
68
+ */
69
+ insert(args: {
70
+ tableName: TABLE_NAMES;
71
+ record: Record<string, any>;
72
+ }): Promise<void>;
73
+ /**
74
+ * Internal update implementation without retry logic.
75
+ */
76
+ private doUpdate;
77
+ /**
78
+ * Updates a record in the specified table with automatic retry on lock errors.
79
+ *
80
+ * @param args - The update arguments
81
+ * @param args.tableName - The name of the table to update
82
+ * @param args.keys - The key(s) identifying the record to update
83
+ * @param args.data - The fields to update (key-value pairs)
84
+ */
85
+ update(args: {
86
+ tableName: TABLE_NAMES;
87
+ keys: Record<string, any>;
88
+ data: Record<string, any>;
89
+ }): Promise<void>;
90
+ /**
91
+ * Internal batch insert implementation without retry logic.
92
+ */
93
+ private doBatchInsert;
94
+ /**
95
+ * Inserts multiple records in a single batch transaction with automatic retry on lock errors.
96
+ *
97
+ * @param args - The batch insert arguments
98
+ * @param args.tableName - The name of the table to insert into
99
+ * @param args.records - Array of records to insert
100
+ * @throws {MastraError} When the batch insert fails after retries
101
+ */
102
+ batchInsert(args: {
103
+ tableName: TABLE_NAMES;
104
+ records: Record<string, any>[];
105
+ }): Promise<void>;
106
+ /**
107
+ * Internal batch update implementation without retry logic.
108
+ * Each record can be updated based on single or composite keys.
109
+ */
110
+ private doBatchUpdate;
111
+ /**
112
+ * Updates multiple records in a single batch transaction with automatic retry on lock errors.
113
+ * Each record can be updated based on single or composite keys.
114
+ *
115
+ * @param args - The batch update arguments
116
+ * @param args.tableName - The name of the table to update
117
+ * @param args.updates - Array of update operations, each containing keys and data
118
+ * @throws {MastraError} When the batch update fails after retries
119
+ */
120
+ batchUpdate(args: {
121
+ tableName: TABLE_NAMES;
122
+ updates: Array<{
123
+ keys: Record<string, any>;
124
+ data: Record<string, any>;
125
+ }>;
126
+ }): Promise<void>;
127
+ /**
128
+ * Internal batch delete implementation without retry logic.
129
+ * Each record can be deleted based on single or composite keys.
130
+ */
131
+ private doBatchDelete;
132
+ /**
133
+ * Deletes multiple records in a single batch transaction with automatic retry on lock errors.
134
+ * Each record can be deleted based on single or composite keys.
135
+ *
136
+ * @param args - The batch delete arguments
137
+ * @param args.tableName - The name of the table to delete from
138
+ * @param args.keys - Array of key objects identifying records to delete
139
+ * @throws {MastraError} When the batch delete fails after retries
140
+ */
141
+ batchDelete({ tableName, keys, }: {
142
+ tableName: TABLE_NAMES;
143
+ keys: Array<Record<string, any>>;
144
+ }): Promise<void>;
145
+ /**
146
+ * Internal single-record delete implementation without retry logic.
147
+ */
148
+ private doDelete;
149
+ /**
150
+ * Deletes a single record from the specified table with automatic retry on lock errors.
151
+ *
152
+ * @param args - The delete arguments
153
+ * @param args.tableName - The name of the table to delete from
154
+ * @param args.keys - The key(s) identifying the record to delete
155
+ * @throws {MastraError} When the delete fails after retries
156
+ */
157
+ delete(args: {
158
+ tableName: TABLE_NAMES;
159
+ keys: Record<string, any>;
160
+ }): Promise<void>;
161
+ /**
162
+ * Selects a single record from the specified table by key(s).
163
+ * Returns the most recently created record if multiple matches exist.
164
+ * Automatically parses JSON string values back to objects/arrays.
165
+ *
166
+ * @typeParam R - The expected return type of the record
167
+ * @param args - The select arguments
168
+ * @param args.tableName - The name of the table to select from
169
+ * @param args.keys - The key(s) identifying the record to select
170
+ * @returns The matching record or `null` if not found
171
+ */
172
+ select<R>({ tableName, keys }: {
173
+ tableName: TABLE_NAMES;
174
+ keys: Record<string, string>;
175
+ }): Promise<R | null>;
176
+ /**
177
+ * Selects multiple records from the specified table with optional filtering, ordering, and pagination.
178
+ *
179
+ * @typeParam R - The expected return type of each record
180
+ * @param args - The select arguments
181
+ * @param args.tableName - The name of the table to select from
182
+ * @param args.whereClause - Optional WHERE clause with SQL string and arguments
183
+ * @param args.orderBy - Optional ORDER BY clause (e.g., "createdAt DESC")
184
+ * @param args.offset - Optional offset for pagination
185
+ * @param args.limit - Optional limit for pagination
186
+ * @param args.args - Optional additional query arguments
187
+ * @returns Array of matching records
188
+ */
189
+ selectMany<R>({ tableName, whereClause, orderBy, offset, limit, args, }: {
190
+ tableName: TABLE_NAMES;
191
+ whereClause?: {
192
+ sql: string;
193
+ args: InValue[];
194
+ };
195
+ orderBy?: string;
196
+ offset?: number;
197
+ limit?: number;
198
+ args?: any[];
199
+ }): Promise<R[]>;
200
+ /**
201
+ * Returns the total count of records matching the optional WHERE clause.
202
+ *
203
+ * @param args - The count arguments
204
+ * @param args.tableName - The name of the table to count from
205
+ * @param args.whereClause - Optional WHERE clause with SQL string and arguments
206
+ * @returns The total count of matching records
207
+ */
208
+ selectTotalCount({ tableName, whereClause, }: {
209
+ tableName: TABLE_NAMES;
210
+ whereClause?: {
211
+ sql: string;
212
+ args: InValue[];
213
+ };
214
+ }): Promise<number>;
215
+ /**
216
+ * Maps a storage column type to its SQLite equivalent.
217
+ */
218
+ protected getSqlType(type: StorageColumn['type']): string;
219
+ /**
220
+ * Creates a table if it doesn't exist based on the provided schema.
221
+ *
222
+ * @param args - The create table arguments
223
+ * @param args.tableName - The name of the table to create
224
+ * @param args.schema - The schema definition for the table columns
225
+ */
226
+ createTable({ tableName, schema, }: {
227
+ tableName: TABLE_NAMES;
228
+ schema: Record<string, StorageColumn>;
229
+ }): Promise<void>;
230
+ /**
231
+ * Migrates the spans table schema from OLD_SPAN_SCHEMA to current SPAN_SCHEMA.
232
+ * This adds new columns that don't exist in old schema and ensures required indexes exist.
233
+ */
234
+ private migrateSpansTable;
235
+ /**
236
+ * Checks if the unique index on (spanId, traceId) already exists on the spans table.
237
+ * Used to skip deduplication when the index already exists (migration already complete).
238
+ */
239
+ private spansUniqueIndexExists;
240
+ /**
241
+ * Checks for duplicate (traceId, spanId) combinations in the spans table.
242
+ * Returns information about duplicates for logging/CLI purposes.
243
+ */
244
+ private checkForDuplicateSpans;
245
+ /**
246
+ * Manually run the spans migration to deduplicate and add the unique constraint.
247
+ * This is intended to be called from the CLI when duplicates are detected.
248
+ *
249
+ * @returns Migration result with status and details
250
+ */
251
+ migrateSpans(): Promise<{
252
+ success: boolean;
253
+ alreadyMigrated: boolean;
254
+ duplicatesRemoved: number;
255
+ message: string;
256
+ }>;
257
+ /**
258
+ * Check migration status for the spans table.
259
+ * Returns information about whether migration is needed.
260
+ */
261
+ checkSpansMigrationStatus(): Promise<{
262
+ needsMigration: boolean;
263
+ hasDuplicates: boolean;
264
+ duplicateCount: number;
265
+ constraintExists: boolean;
266
+ tableName: string;
267
+ }>;
268
+ /**
269
+ * Deduplicates spans table by removing duplicate (spanId, traceId) combinations.
270
+ * Keeps the "best" record for each duplicate group based on:
271
+ * 1. Completed spans (endedAt IS NOT NULL) over incomplete ones
272
+ * 2. Most recently updated (updatedAt DESC)
273
+ * 3. Most recently created (createdAt DESC) as tiebreaker
274
+ */
275
+ private deduplicateSpans;
276
+ /**
277
+ * Gets a default value for a column type (used when adding NOT NULL columns).
278
+ */
279
+ private getDefaultValue;
280
+ /**
281
+ * Alters an existing table to add missing columns.
282
+ * Used for schema migrations when new columns are added.
283
+ *
284
+ * @param args - The alter table arguments
285
+ * @param args.tableName - The name of the table to alter
286
+ * @param args.schema - The full schema definition for the table
287
+ * @param args.ifNotExists - Array of column names to add if they don't exist
288
+ */
289
+ alterTable({ tableName, schema, ifNotExists, }: {
290
+ tableName: TABLE_NAMES;
291
+ schema: Record<string, StorageColumn>;
292
+ ifNotExists: string[];
293
+ }): Promise<void>;
294
+ /**
295
+ * Deletes all records from the specified table.
296
+ * Errors are logged but not thrown.
297
+ *
298
+ * @param args - The delete arguments
299
+ * @param args.tableName - The name of the table to clear
300
+ */
301
+ deleteData({ tableName }: {
302
+ tableName: TABLE_NAMES;
303
+ }): Promise<void>;
304
+ }
305
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/db/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAS/C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAUvE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,CAAC,sBAAsB,GAAG;IACxB,2FAA2F;IAC3F,GAAG,EAAE,MAAM,CAAC;IACZ,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,GACF,CAAC,sBAAsB,GAAG;IACxB,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEP;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAQhE;AAED,qBAAa,QAAS,SAAQ,UAA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ACH,OAAO,CAAC,eAAe;IAoBvB;;;;;;;;OAQG;IACG,UAAU,CAAC,EACf,SAAS,EACT,MAAM,EACN,WAAW,GACZ,EAAE;QACD,SAAS,EAAE,WAAW,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QACtC,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoCjB;;;;;;OAMG;IACG,UAAU,CAAC,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB3E"}
@@ -1,6 +1,25 @@
1
1
  import type { InValue } from '@libsql/client';
2
2
  import type { IMastraLogger } from '@mastra/core/logger';
3
- import type { PaginationArgs, StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
3
+ import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
4
+ /**
5
+ * Builds a SQL column list for SELECT statements, wrapping JSONB columns with json()
6
+ * to convert binary JSONB to TEXT.
7
+ *
8
+ * The json() function handles both:
9
+ * - Binary JSONB data (converts to TEXT)
10
+ * - Legacy TEXT JSON data (returns as-is)
11
+ *
12
+ * Note: json_valid() was considered for guarding against malformed legacy TEXT,
13
+ * but it doesn't work correctly with binary JSONB data (returns false for valid JSONB blobs).
14
+ *
15
+ * @param tableName - The table name to get the schema for
16
+ * @returns A comma-separated column list with json() wrappers for JSONB columns
17
+ */
18
+ export declare function buildSelectColumns(tableName: TABLE_NAMES): string;
19
+ /**
20
+ * Checks if an error is a SQLite lock/busy error that should be retried
21
+ */
22
+ export declare function isLockError(error: any): boolean;
4
23
  export declare function createExecuteWriteOperationWithRetry({ logger, maxRetries, initialBackoffMs, }: {
5
24
  logger: IMastraLogger;
6
25
  maxRetries: number;
@@ -21,7 +40,7 @@ export declare function prepareUpdateStatement({ tableName, updates, keys, }: {
21
40
  sql: string;
22
41
  args: InValue[];
23
42
  };
24
- export declare function transformToSqlValue(value: any): InValue;
43
+ export declare function transformToSqlValue(value: any, forceJsonStringify?: boolean): InValue;
25
44
  export declare function prepareDeleteStatement({ tableName, keys }: {
26
45
  tableName: TABLE_NAMES;
27
46
  keys: Record<string, any>;
@@ -37,17 +56,6 @@ export declare function prepareWhereClause(filters: Record<string, WhereValue>,
37
56
  sql: string;
38
57
  args: InValue[];
39
58
  };
40
- type DateRangeFilter = {
41
- startAt?: string;
42
- endAt?: string;
43
- };
44
- /**
45
- * Converts pagination date range to where clause date range format
46
- * @param dateRange - The date range from pagination
47
- * @param columnName - The timestamp column to filter on (defaults to 'createdAt')
48
- * @returns Object with the date range filter, or empty object if no date range
49
- */
50
- export declare function buildDateRangeFilter(dateRange?: PaginationArgs['dateRange'], columnName?: string): Record<string, DateRangeFilter>;
51
59
  /**
52
60
  * Transforms SQL row data back to a typed object format
53
61
  * Reverses the transformations done in prepareStatement
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/storage/db/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,CASjE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAS/C;AAED,wBAAgB,oCAAoC,CAAC,EACnD,MAAM,EACN,UAAU,EACV,gBAAgB,GACjB,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,IACsD,CAAC,EACpD,aAAa,MAAM,OAAO,CAAC,CAAC,CAAC,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AM,CAAC;IACZ,IAAI,EAAE,OAAO,EAAE,CAAC;CACjB,CAqBA;AA+CD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,EACrC,SAAS,EACT,MAAM,GACP,EAAE;IACD,SAAS,EAAE,WAAW,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B,GAAG,CAAC,CAiCJ"}
@@ -1,13 +1,11 @@
1
- import type { Client } from '@libsql/client';
2
1
  import { AgentsStorage } from '@mastra/core/storage';
3
2
  import type { StorageAgentType, StorageCreateAgentInput, StorageUpdateAgentInput, StorageListAgentsInput, StorageListAgentsOutput } from '@mastra/core/storage';
4
- import type { StoreOperationsLibSQL } from '../operations/index.js';
3
+ import type { LibSQLDomainConfig } from '../../db/index.js';
5
4
  export declare class AgentsLibSQL extends AgentsStorage {
6
- private client;
7
- constructor({ client, operations: _ }: {
8
- client: Client;
9
- operations: StoreOperationsLibSQL;
10
- });
5
+ #private;
6
+ constructor(config: LibSQLDomainConfig);
7
+ init(): Promise<void>;
8
+ dangerouslyClearAll(): Promise<void>;
11
9
  private parseJson;
12
10
  private parseRow;
13
11
  getAgentById({ id }: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/agents/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAW,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EACL,aAAa,EAKd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,qBAAa,YAAa,SAAQ,aAAa;IAC7C,OAAO,CAAC,MAAM,CAAS;gBAEX,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,E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AAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAqBtE,WAAW,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,uBAAuB,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA4CrF,WAAW,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0EnF,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBlD,UAAU,CAAC,IAAI,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CA8DlF"}
@@ -1,16 +1,13 @@
1
- import type { Client } from '@libsql/client';
2
1
  import type { MastraMessageContentV2 } from '@mastra/core/agent';
3
2
  import type { MastraDBMessage, StorageThreadType } from '@mastra/core/memory';
4
- import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsByResourceIdInput, StorageListThreadsByResourceIdOutput } from '@mastra/core/storage';
3
+ import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput, StorageCloneThreadInput, StorageCloneThreadOutput } from '@mastra/core/storage';
5
4
  import { MemoryStorage } from '@mastra/core/storage';
6
- import type { StoreOperationsLibSQL } from '../operations/index.js';
5
+ import type { LibSQLDomainConfig } from '../../db/index.js';
7
6
  export declare class MemoryLibSQL extends MemoryStorage {
8
- private client;
9
- private operations;
10
- constructor({ client, operations }: {
11
- client: Client;
12
- operations: StoreOperationsLibSQL;
13
- });
7
+ #private;
8
+ constructor(config: LibSQLDomainConfig);
9
+ init(): Promise<void>;
10
+ dangerouslyClearAll(): Promise<void>;
14
11
  private parseRow;
15
12
  private _getIncludedMessages;
16
13
  listMessagesById({ messageIds }: {
@@ -48,7 +45,7 @@ export declare class MemoryLibSQL extends MemoryStorage {
48
45
  getThreadById({ threadId }: {
49
46
  threadId: string;
50
47
  }): Promise<StorageThreadType | null>;
51
- listThreadsByResourceId(args: StorageListThreadsByResourceIdInput): Promise<StorageListThreadsByResourceIdOutput>;
48
+ listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
52
49
  saveThread({ thread }: {
53
50
  thread: StorageThreadType;
54
51
  }): Promise<StorageThreadType>;
@@ -60,5 +57,6 @@ export declare class MemoryLibSQL extends MemoryStorage {
60
57
  deleteThread({ threadId }: {
61
58
  threadId: string;
62
59
  }): Promise<void>;
60
+ cloneThread(args: StorageCloneThreadInput): Promise<StorageCloneThreadOutput>;
63
61
  }
64
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAW,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAGjE,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,mCAAmC,EACnC,oCAAoC,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,aAAa,EAMd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,qBAAa,YAAa,SAAQ,aAAa;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAwB;gBAC9B,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,qBAAqB,CAAA;KAAE;IAMzF,OAAO,CAAC,QAAQ;YAmBF,oBAAoB;IAgDrB,gB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,mBAAmB,CAAC;IAY3F,cAAc,CAAC,EACnB,UAAU,EACV,aAAa,EACb,QAAQ,GACT,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAmD1B,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAgC7E,WAAW,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA0JpF,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,iBAAiB,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA2BjF,YAAY,CAAC,EACjB,EAAE,EACF,KAAK,EACL,QAAQ,GACT,EAAE;QACD,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA6CxB,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B/D,WAAW,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAsLpF"}
@@ -1,34 +1,49 @@
1
1
  import { ObservabilityStorage } from '@mastra/core/storage';
2
- import type { SpanRecord, CreateSpanRecord, UpdateSpanRecord, TraceRecord, TracesPaginatedArg, PaginationInfo } from '@mastra/core/storage';
3
- import type { StoreOperationsLibSQL } from '../operations/index.js';
2
+ import type { SpanRecord, ListTracesArgs, PaginationInfo, TracingStorageStrategy, UpdateSpanArgs, BatchDeleteTracesArgs, BatchUpdateSpansArgs, BatchCreateSpansArgs, CreateSpanArgs, GetSpanArgs, GetSpanResponse, GetRootSpanArgs, GetRootSpanResponse, GetTraceArgs, GetTraceResponse } from '@mastra/core/storage';
3
+ import type { LibSQLDomainConfig } from '../../db/index.js';
4
4
  export declare class ObservabilityLibSQL extends ObservabilityStorage {
5
- private operations;
6
- constructor({ operations }: {
7
- operations: StoreOperationsLibSQL;
8
- });
9
- createSpan(span: CreateSpanRecord): Promise<void>;
10
- getTrace(traceId: string): Promise<TraceRecord | null>;
11
- updateSpan({ spanId, traceId, updates, }: {
12
- spanId: string;
13
- traceId: string;
14
- updates: Partial<UpdateSpanRecord>;
15
- }): Promise<void>;
16
- getTracesPaginated({ filters, pagination, }: TracesPaginatedArg): Promise<{
5
+ #private;
6
+ constructor(config: LibSQLDomainConfig);
7
+ init(): Promise<void>;
8
+ dangerouslyClearAll(): Promise<void>;
9
+ /**
10
+ * Manually run the spans migration to deduplicate and add the unique constraint.
11
+ * This is intended to be called from the CLI when duplicates are detected.
12
+ *
13
+ * @returns Migration result with status and details
14
+ */
15
+ migrateSpans(): Promise<{
16
+ success: boolean;
17
+ alreadyMigrated: boolean;
18
+ duplicatesRemoved: number;
19
+ message: string;
20
+ }>;
21
+ /**
22
+ * Check migration status for the spans table.
23
+ * Returns information about whether migration is needed.
24
+ */
25
+ checkSpansMigrationStatus(): Promise<{
26
+ needsMigration: boolean;
27
+ hasDuplicates: boolean;
28
+ duplicateCount: number;
29
+ constraintExists: boolean;
30
+ tableName: string;
31
+ }>;
32
+ get tracingStrategy(): {
33
+ preferred: TracingStorageStrategy;
34
+ supported: TracingStorageStrategy[];
35
+ };
36
+ createSpan(args: CreateSpanArgs): Promise<void>;
37
+ getSpan(args: GetSpanArgs): Promise<GetSpanResponse | null>;
38
+ getRootSpan(args: GetRootSpanArgs): Promise<GetRootSpanResponse | null>;
39
+ getTrace(args: GetTraceArgs): Promise<GetTraceResponse | null>;
40
+ updateSpan(args: UpdateSpanArgs): Promise<void>;
41
+ listTraces(args: ListTracesArgs): Promise<{
17
42
  pagination: PaginationInfo;
18
43
  spans: SpanRecord[];
19
44
  }>;
20
- batchCreateSpans(args: {
21
- records: CreateSpanRecord[];
22
- }): Promise<void>;
23
- batchUpdateSpans(args: {
24
- records: {
25
- traceId: string;
26
- spanId: string;
27
- updates: Partial<UpdateSpanRecord>;
28
- }[];
29
- }): Promise<void>;
30
- batchDeleteTraces(args: {
31
- traceIds: string[];
32
- }): Promise<void>;
45
+ batchCreateSpans(args: BatchCreateSpansArgs): Promise<void>;
46
+ batchUpdateSpans(args: BatchUpdateSpansArgs): Promise<void>;
47
+ batchDeleteTraces(args: BatchDeleteTracesArgs): Promise<void>;
33
48
  }
34
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/observability/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAqC,oBAAoB,EAAe,MAAM,sBAAsB,CAAC;AAC5G,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3D,qBAAa,mBAAoB,SAAQ,oBAAoB;IAC3D,OAAO,CAAC,UAAU,CAAwB;gBAC9B,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,qBAAqB,CAAA;KAAE;IAK3D,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BjD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IA+BtD,UAAU,CAAC,EACf,MAAM,EACN,OAAO,EACP,OAAO,GACR,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;KACpC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBX,kBAAkB,CAAC,EACvB,OAAO,EACP,UAAU,GACX,EAAE,kBAAkB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,KAAK,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IA4G9E,gBAAgB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,gBAAgB,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBtE,gBAAgB,CAAC,IAAI,EAAE;QAC3B,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;YAChB,MAAM,EAAE,MAAM,CAAC;YACf,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;SACpC,EAAE,CAAC;KACL,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBX,iBAAiB,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBrE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/observability/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,oBAAoB,EAIrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,cAAc,EACd,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD,qBAAa,mBAAoB,SAAQ,oBAAoB;;gBAG/C,MAAM,EAAE,kBAAkB;IAMhC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,mBAA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AAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBpE"}
@@ -1,35 +1,25 @@
1
- import type { Client } from '@libsql/client';
2
- import type { SaveScorePayload, ScoreRowData, ScoringSource } from '@mastra/core/evals';
1
+ import type { ListScoresResponse, SaveScorePayload, ScoreRowData, ScoringSource } from '@mastra/core/evals';
3
2
  import { ScoresStorage } from '@mastra/core/storage';
4
- import type { PaginationInfo, StoragePagination } from '@mastra/core/storage';
5
- import type { StoreOperationsLibSQL } from '../operations/index.js';
3
+ import type { StoragePagination } from '@mastra/core/storage';
4
+ import type { LibSQLDomainConfig } from '../../db/index.js';
6
5
  export declare class ScoresLibSQL extends ScoresStorage {
7
- private operations;
8
- private client;
9
- constructor({ client, operations }: {
10
- client: Client;
11
- operations: StoreOperationsLibSQL;
12
- });
6
+ #private;
7
+ constructor(config: LibSQLDomainConfig);
8
+ init(): Promise<void>;
9
+ dangerouslyClearAll(): Promise<void>;
13
10
  listScoresByRunId({ runId, pagination, }: {
14
11
  runId: string;
15
12
  pagination: StoragePagination;
16
- }): Promise<{
17
- pagination: PaginationInfo;
18
- scores: ScoreRowData[];
19
- }>;
13
+ }): Promise<ListScoresResponse>;
20
14
  listScoresByScorerId({ scorerId, entityId, entityType, source, pagination, }: {
21
15
  scorerId: string;
22
16
  entityId?: string;
23
17
  entityType?: string;
24
18
  source?: ScoringSource;
25
19
  pagination: StoragePagination;
26
- }): Promise<{
27
- pagination: PaginationInfo;
28
- scores: ScoreRowData[];
29
- }>;
20
+ }): Promise<ListScoresResponse>;
30
21
  /**
31
22
  * LibSQL-specific score row transformation.
32
- * Maps additionalLLMContext column to additionalContext field.
33
23
  */
34
24
  private transformScoreRow;
35
25
  getScoreById({ id }: {
@@ -42,17 +32,11 @@ export declare class ScoresLibSQL extends ScoresStorage {
42
32
  pagination: StoragePagination;
43
33
  entityId: string;
44
34
  entityType: string;
45
- }): Promise<{
46
- pagination: PaginationInfo;
47
- scores: ScoreRowData[];
48
- }>;
35
+ }): Promise<ListScoresResponse>;
49
36
  listScoresBySpan({ traceId, spanId, pagination, }: {
50
37
  traceId: string;
51
38
  spanId: string;
52
39
  pagination: StoragePagination;
53
- }): Promise<{
54
- pagination: PaginationInfo;
55
- scores: ScoreRowData[];
56
- }>;
40
+ }): Promise<ListScoresResponse>;
57
41
  }
58
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAW,MAAM,gBAAgB,CAAC;AAGtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AACnH,OAAO,EAGL,aAAa,EAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,qBAAa,YAAa,SAAQ,aAAa;IAC7C,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,MAAM,CAAS;gBACX,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,qBAAqB,CAAA;KAAE;IAMnF,iBAAiB,CAAC,EACtB,KAAK,EACL,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAwD7D,oBAAoB,CAAC,EACzB,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,MAAM,EACN,UAAU,GACX,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;Q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