@mastra/libsql 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016
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/CHANGELOG.md +4789 -3
- package/LICENSE.md +15 -0
- package/README.md +30 -20
- package/dist/docs/SKILL.md +52 -0
- package/dist/docs/assets/SOURCE_MAP.json +6 -0
- package/dist/docs/references/docs-agents-agent-approval.md +664 -0
- package/dist/docs/references/docs-agents-networks.md +184 -0
- package/dist/docs/references/docs-deployment-workers.md +137 -0
- package/dist/docs/references/docs-editor-overview.md +349 -0
- package/dist/docs/references/docs-memory-memory-processors.md +385 -0
- package/dist/docs/references/docs-memory-message-history.md +348 -0
- package/dist/docs/references/docs-memory-multi-user-threads.md +208 -0
- package/dist/docs/references/docs-memory-overview.md +266 -0
- package/dist/docs/references/docs-memory-semantic-recall.md +401 -0
- package/dist/docs/references/docs-memory-working-memory.md +431 -0
- package/dist/docs/references/docs-storage-overview.md +214 -0
- package/dist/docs/references/docs-workflows-snapshots.md +240 -0
- package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +142 -0
- package/dist/docs/references/guides-rag-retrieval.md +520 -0
- package/dist/docs/references/reference-core-getMemory.md +51 -0
- package/dist/docs/references/reference-core-listMemory.md +57 -0
- package/dist/docs/references/reference-core-mastra-class.md +153 -0
- package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
- package/dist/docs/references/reference-file-based-agents-storage.md +30 -0
- package/dist/docs/references/reference-memory-memory-class.md +148 -0
- package/dist/docs/references/reference-storage-composite.md +397 -0
- package/dist/docs/references/reference-storage-dynamodb.md +284 -0
- package/dist/docs/references/reference-storage-libsql.md +143 -0
- package/dist/docs/references/reference-storage-retention.md +248 -0
- package/dist/docs/references/reference-vectors-libsql.md +307 -0
- package/dist/index.cjs +13164 -3390
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13134 -3383
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +389 -0
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/db/utils.d.ts +84 -0
- package/dist/storage/db/utils.d.ts.map +1 -0
- package/dist/storage/db/write-lock.d.ts +8 -0
- package/dist/storage/db/write-lock.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +30 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/background-tasks/index.d.ts +27 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
- package/dist/storage/domains/blobs/index.d.ts +17 -0
- package/dist/storage/domains/blobs/index.d.ts.map +1 -0
- package/dist/storage/domains/channels/index.d.ts +20 -0
- package/dist/storage/domains/channels/index.d.ts.map +1 -0
- package/dist/storage/domains/datasets/index.d.ts +43 -0
- package/dist/storage/domains/datasets/index.d.ts.map +1 -0
- package/dist/storage/domains/experiments/index.d.ts +54 -0
- package/dist/storage/domains/experiments/index.d.ts.map +1 -0
- package/dist/storage/domains/favorites/index.d.ts +17 -0
- package/dist/storage/domains/favorites/index.d.ts.map +1 -0
- package/dist/storage/domains/harness/index.d.ts +17 -0
- package/dist/storage/domains/harness/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-clients/index.d.ts +26 -0
- package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/index.d.ts +26 -0
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +58 -54
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts +23 -0
- package/dist/storage/domains/notifications/index.d.ts.map +1 -0
- package/dist/storage/domains/observability/index.d.ts +49 -29
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts +25 -0
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
- package/dist/storage/domains/schedules/index.d.ts +27 -0
- package/dist/storage/domains/schedules/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts +26 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +29 -31
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts +26 -0
- package/dist/storage/domains/skills/index.d.ts.map +1 -0
- package/dist/storage/domains/thread-state/index.d.ts +38 -0
- package/dist/storage/domains/thread-state/index.d.ts.map +1 -0
- package/dist/storage/domains/tool-provider-connections/index.d.ts +14 -0
- package/dist/storage/domains/tool-provider-connections/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +28 -54
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflow-definitions/index.d.ts +14 -0
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +27 -32
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/domains/workspaces/index.d.ts +26 -0
- package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
- package/dist/storage/factory-storage.d.ts +28 -0
- package/dist/storage/factory-storage.d.ts.map +1 -0
- package/dist/storage/index.d.ts +128 -255
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/retention.d.ts +77 -0
- package/dist/storage/retention.d.ts.map +1 -0
- package/dist/vector/index.d.ts +31 -4
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/sql-builder.d.ts.map +1 -1
- package/package.json +22 -16
- package/dist/storage/domains/legacy-evals/index.d.ts +0 -18
- package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
- package/dist/storage/domains/operations/index.d.ts +0 -110
- package/dist/storage/domains/operations/index.d.ts.map +0 -1
- package/dist/storage/domains/traces/index.d.ts +0 -21
- package/dist/storage/domains/traces/index.d.ts.map +0 -1
|
@@ -0,0 +1,389 @@
|
|
|
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
|
+
* SQLite `busy_timeout` (in milliseconds) applied to the underlying connection
|
|
21
|
+
* for local (`file:`/`:memory:`) databases. Lets a write wait for a lock to
|
|
22
|
+
* clear instead of failing immediately with `SQLITE_BUSY`. Requires
|
|
23
|
+
* `@libsql/client` >= 0.17.4 (see libsql-client-ts#288/#345). Ignored when an
|
|
24
|
+
* existing `client` is supplied.
|
|
25
|
+
* @default 5000
|
|
26
|
+
*/
|
|
27
|
+
connectionTimeoutMs?: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Default SQLite `busy_timeout` (ms) for local LibSQL connections. Chosen to
|
|
31
|
+
* comfortably exceed the write-retry backoff window so contended writes block
|
|
32
|
+
* briefly rather than surfacing as `SQLITE_BUSY` errors.
|
|
33
|
+
*/
|
|
34
|
+
export declare const DEFAULT_CONNECTION_TIMEOUT_MS = 5000;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration for LibSQL domains - accepts either credentials or an existing client
|
|
37
|
+
*/
|
|
38
|
+
export type LibSQLDomainConfig = (LibSQLDomainBaseConfig & {
|
|
39
|
+
/** The database connection URL (e.g., "file:local.db", "libsql://...", "file::memory:") */
|
|
40
|
+
url: string;
|
|
41
|
+
/** Optional authentication token for remote databases */
|
|
42
|
+
authToken?: string;
|
|
43
|
+
}) | (LibSQLDomainBaseConfig & {
|
|
44
|
+
/** An existing LibSQL client instance */
|
|
45
|
+
client: Client;
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Resolves a LibSQLDomainConfig to a Client instance.
|
|
49
|
+
* Creates a new client if credentials are provided, or returns the existing client.
|
|
50
|
+
*
|
|
51
|
+
* @param config - The domain configuration
|
|
52
|
+
* @returns The resolved LibSQL client
|
|
53
|
+
*/
|
|
54
|
+
export declare function resolveClient(config: LibSQLDomainConfig): Client;
|
|
55
|
+
export declare class LibSQLDB extends MastraBase {
|
|
56
|
+
private client;
|
|
57
|
+
maxRetries: number;
|
|
58
|
+
initialBackoffMs: number;
|
|
59
|
+
executeWriteOperationWithRetry: <T>(operationFn: () => Promise<T>, operationDescription: string) => Promise<T>;
|
|
60
|
+
/** Cache of actual table columns: tableName -> Promise<Set<columnName>> (stores in-flight promise to coalesce concurrent calls) */
|
|
61
|
+
private tableColumnsCache;
|
|
62
|
+
constructor({ client, maxRetries, initialBackoffMs, }: {
|
|
63
|
+
client: Client;
|
|
64
|
+
maxRetries?: number;
|
|
65
|
+
initialBackoffMs?: number;
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* Gets the set of column names that actually exist in the database table.
|
|
69
|
+
* Results are cached; the cache is invalidated when alterTable() adds new columns.
|
|
70
|
+
*/
|
|
71
|
+
private getTableColumns;
|
|
72
|
+
/**
|
|
73
|
+
* Filters a record to only include columns that exist in the actual database table.
|
|
74
|
+
* Unknown columns are silently dropped to ensure forward compatibility.
|
|
75
|
+
*/
|
|
76
|
+
private filterRecordToKnownColumns;
|
|
77
|
+
/**
|
|
78
|
+
* Checks if a column exists in the specified table.
|
|
79
|
+
*
|
|
80
|
+
* @param table - The name of the table to check
|
|
81
|
+
* @param column - The name of the column to look for
|
|
82
|
+
* @returns `true` if the column exists in the table, `false` otherwise
|
|
83
|
+
*/
|
|
84
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Internal insert implementation without retry logic.
|
|
87
|
+
*/
|
|
88
|
+
private doInsert;
|
|
89
|
+
/**
|
|
90
|
+
* Inserts or replaces a record in the specified table with automatic retry on lock errors.
|
|
91
|
+
*
|
|
92
|
+
* @param args - The insert arguments
|
|
93
|
+
* @param args.tableName - The name of the table to insert into
|
|
94
|
+
* @param args.record - The record to insert (key-value pairs)
|
|
95
|
+
*/
|
|
96
|
+
insert(args: {
|
|
97
|
+
tableName: TABLE_NAMES;
|
|
98
|
+
record: Record<string, any>;
|
|
99
|
+
}): Promise<void>;
|
|
100
|
+
/** Inserts a record without replacing an existing primary key. */
|
|
101
|
+
insertOnly(args: {
|
|
102
|
+
tableName: TABLE_NAMES;
|
|
103
|
+
record: Record<string, any>;
|
|
104
|
+
}): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Internal update implementation without retry logic.
|
|
107
|
+
*/
|
|
108
|
+
private doUpdate;
|
|
109
|
+
/**
|
|
110
|
+
* Updates a record in the specified table with automatic retry on lock errors.
|
|
111
|
+
*
|
|
112
|
+
* @param args - The update arguments
|
|
113
|
+
* @param args.tableName - The name of the table to update
|
|
114
|
+
* @param args.keys - The key(s) identifying the record to update
|
|
115
|
+
* @param args.data - The fields to update (key-value pairs)
|
|
116
|
+
*/
|
|
117
|
+
update(args: {
|
|
118
|
+
tableName: TABLE_NAMES;
|
|
119
|
+
keys: Record<string, any>;
|
|
120
|
+
data: Record<string, any>;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Internal batch insert implementation without retry logic.
|
|
124
|
+
*/
|
|
125
|
+
private doBatchInsert;
|
|
126
|
+
/**
|
|
127
|
+
* Inserts multiple records in a single batch transaction with automatic retry on lock errors.
|
|
128
|
+
*
|
|
129
|
+
* @param args - The batch insert arguments
|
|
130
|
+
* @param args.tableName - The name of the table to insert into
|
|
131
|
+
* @param args.records - Array of records to insert
|
|
132
|
+
* @throws {MastraError} When the batch insert fails after retries
|
|
133
|
+
*/
|
|
134
|
+
batchInsert(args: {
|
|
135
|
+
tableName: TABLE_NAMES;
|
|
136
|
+
records: Record<string, any>[];
|
|
137
|
+
}): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Internal batch update implementation without retry logic.
|
|
140
|
+
* Each record can be updated based on single or composite keys.
|
|
141
|
+
*/
|
|
142
|
+
private doBatchUpdate;
|
|
143
|
+
/**
|
|
144
|
+
* Updates multiple records in a single batch transaction with automatic retry on lock errors.
|
|
145
|
+
* Each record can be updated based on single or composite keys.
|
|
146
|
+
*
|
|
147
|
+
* @param args - The batch update arguments
|
|
148
|
+
* @param args.tableName - The name of the table to update
|
|
149
|
+
* @param args.updates - Array of update operations, each containing keys and data
|
|
150
|
+
* @throws {MastraError} When the batch update fails after retries
|
|
151
|
+
*/
|
|
152
|
+
batchUpdate(args: {
|
|
153
|
+
tableName: TABLE_NAMES;
|
|
154
|
+
updates: Array<{
|
|
155
|
+
keys: Record<string, any>;
|
|
156
|
+
data: Record<string, any>;
|
|
157
|
+
}>;
|
|
158
|
+
}): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Internal batch delete implementation without retry logic.
|
|
161
|
+
* Each record can be deleted based on single or composite keys.
|
|
162
|
+
*/
|
|
163
|
+
private doBatchDelete;
|
|
164
|
+
/**
|
|
165
|
+
* Deletes multiple records in a single batch transaction with automatic retry on lock errors.
|
|
166
|
+
* Each record can be deleted based on single or composite keys.
|
|
167
|
+
*
|
|
168
|
+
* @param args - The batch delete arguments
|
|
169
|
+
* @param args.tableName - The name of the table to delete from
|
|
170
|
+
* @param args.keys - Array of key objects identifying records to delete
|
|
171
|
+
* @throws {MastraError} When the batch delete fails after retries
|
|
172
|
+
*/
|
|
173
|
+
batchDelete({ tableName, keys, }: {
|
|
174
|
+
tableName: TABLE_NAMES;
|
|
175
|
+
keys: Array<Record<string, any>>;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Internal single-record delete implementation without retry logic.
|
|
179
|
+
*/
|
|
180
|
+
private doDelete;
|
|
181
|
+
/**
|
|
182
|
+
* Deletes a single record from the specified table with automatic retry on lock errors.
|
|
183
|
+
*
|
|
184
|
+
* @param args - The delete arguments
|
|
185
|
+
* @param args.tableName - The name of the table to delete from
|
|
186
|
+
* @param args.keys - The key(s) identifying the record to delete
|
|
187
|
+
* @throws {MastraError} When the delete fails after retries
|
|
188
|
+
*/
|
|
189
|
+
delete(args: {
|
|
190
|
+
tableName: TABLE_NAMES;
|
|
191
|
+
keys: Record<string, any>;
|
|
192
|
+
}): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Selects a single record from the specified table by key(s).
|
|
195
|
+
* Returns the most recently created record if multiple matches exist.
|
|
196
|
+
* Automatically parses JSON string values back to objects/arrays.
|
|
197
|
+
*
|
|
198
|
+
* @typeParam R - The expected return type of the record
|
|
199
|
+
* @param args - The select arguments
|
|
200
|
+
* @param args.tableName - The name of the table to select from
|
|
201
|
+
* @param args.keys - The key(s) identifying the record to select
|
|
202
|
+
* @returns The matching record or `null` if not found
|
|
203
|
+
*/
|
|
204
|
+
select<R>({ tableName, keys }: {
|
|
205
|
+
tableName: TABLE_NAMES;
|
|
206
|
+
keys: Record<string, string>;
|
|
207
|
+
}): Promise<R | null>;
|
|
208
|
+
/**
|
|
209
|
+
* Selects multiple records from the specified table with optional filtering, ordering, and pagination.
|
|
210
|
+
*
|
|
211
|
+
* @typeParam R - The expected return type of each record
|
|
212
|
+
* @param args - The select arguments
|
|
213
|
+
* @param args.tableName - The name of the table to select from
|
|
214
|
+
* @param args.whereClause - Optional WHERE clause with SQL string and arguments
|
|
215
|
+
* @param args.orderBy - Optional ORDER BY clause (e.g., "createdAt DESC")
|
|
216
|
+
* @param args.offset - Optional offset for pagination
|
|
217
|
+
* @param args.limit - Optional limit for pagination
|
|
218
|
+
* @param args.args - Optional additional query arguments
|
|
219
|
+
* @returns Array of matching records
|
|
220
|
+
*/
|
|
221
|
+
selectMany<R>({ tableName, whereClause, orderBy, offset, limit, args, }: {
|
|
222
|
+
tableName: TABLE_NAMES;
|
|
223
|
+
whereClause?: {
|
|
224
|
+
sql: string;
|
|
225
|
+
args: InValue[];
|
|
226
|
+
};
|
|
227
|
+
orderBy?: string;
|
|
228
|
+
offset?: number;
|
|
229
|
+
limit?: number;
|
|
230
|
+
args?: any[];
|
|
231
|
+
}): Promise<R[]>;
|
|
232
|
+
/**
|
|
233
|
+
* Returns the total count of records matching the optional WHERE clause.
|
|
234
|
+
*
|
|
235
|
+
* @param args - The count arguments
|
|
236
|
+
* @param args.tableName - The name of the table to count from
|
|
237
|
+
* @param args.whereClause - Optional WHERE clause with SQL string and arguments
|
|
238
|
+
* @returns The total count of matching records
|
|
239
|
+
*/
|
|
240
|
+
selectTotalCount({ tableName, whereClause, }: {
|
|
241
|
+
tableName: TABLE_NAMES;
|
|
242
|
+
whereClause?: {
|
|
243
|
+
sql: string;
|
|
244
|
+
args: InValue[];
|
|
245
|
+
};
|
|
246
|
+
}): Promise<number>;
|
|
247
|
+
/**
|
|
248
|
+
* Maps a storage column type to its SQLite equivalent.
|
|
249
|
+
*/
|
|
250
|
+
protected getSqlType(type: StorageColumn['type']): string;
|
|
251
|
+
/**
|
|
252
|
+
* Creates a table if it doesn't exist based on the provided schema.
|
|
253
|
+
*
|
|
254
|
+
* @param args - The create table arguments
|
|
255
|
+
* @param args.tableName - The name of the table to create
|
|
256
|
+
* @param args.schema - The schema definition for the table columns
|
|
257
|
+
*/
|
|
258
|
+
createTable({ tableName, schema, compositePrimaryKey, }: {
|
|
259
|
+
tableName: TABLE_NAMES;
|
|
260
|
+
schema: Record<string, StorageColumn>;
|
|
261
|
+
compositePrimaryKey?: string[];
|
|
262
|
+
}): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Migrates the spans table schema from OLD_SPAN_SCHEMA to current SPAN_SCHEMA.
|
|
265
|
+
* This adds new columns that don't exist in old schema and ensures required indexes exist.
|
|
266
|
+
*/
|
|
267
|
+
private migrateSpansTable;
|
|
268
|
+
/**
|
|
269
|
+
* Checks if the unique index on (spanId, traceId) already exists on the spans table.
|
|
270
|
+
* Used to skip deduplication when the index already exists (migration already complete).
|
|
271
|
+
*/
|
|
272
|
+
private spansUniqueIndexExists;
|
|
273
|
+
/**
|
|
274
|
+
* Checks for duplicate (traceId, spanId) combinations in the spans table.
|
|
275
|
+
* Returns information about duplicates for logging/CLI purposes.
|
|
276
|
+
*/
|
|
277
|
+
private checkForDuplicateSpans;
|
|
278
|
+
/**
|
|
279
|
+
* Manually run the spans migration to deduplicate and add the unique constraint.
|
|
280
|
+
* This is intended to be called from the CLI when duplicates are detected.
|
|
281
|
+
*
|
|
282
|
+
* @returns Migration result with status and details
|
|
283
|
+
*/
|
|
284
|
+
migrateSpans(): Promise<{
|
|
285
|
+
success: boolean;
|
|
286
|
+
alreadyMigrated: boolean;
|
|
287
|
+
duplicatesRemoved: number;
|
|
288
|
+
message: string;
|
|
289
|
+
}>;
|
|
290
|
+
/**
|
|
291
|
+
* Check migration status for the spans table.
|
|
292
|
+
* Returns information about whether migration is needed.
|
|
293
|
+
*/
|
|
294
|
+
checkSpansMigrationStatus(): Promise<{
|
|
295
|
+
needsMigration: boolean;
|
|
296
|
+
hasDuplicates: boolean;
|
|
297
|
+
duplicateCount: number;
|
|
298
|
+
constraintExists: boolean;
|
|
299
|
+
tableName: string;
|
|
300
|
+
}>;
|
|
301
|
+
/**
|
|
302
|
+
* Deduplicates spans table by removing duplicate (spanId, traceId) combinations.
|
|
303
|
+
* Keeps the "best" record for each duplicate group based on:
|
|
304
|
+
* 1. Completed spans (endedAt IS NOT NULL) over incomplete ones
|
|
305
|
+
* 2. Most recently updated (updatedAt DESC)
|
|
306
|
+
* 3. Most recently created (createdAt DESC) as tiebreaker
|
|
307
|
+
*/
|
|
308
|
+
private deduplicateSpans;
|
|
309
|
+
/**
|
|
310
|
+
* Gets a default value for a column type (used when adding NOT NULL columns).
|
|
311
|
+
*/
|
|
312
|
+
private getDefaultValue;
|
|
313
|
+
/**
|
|
314
|
+
* Alters an existing table to add missing columns.
|
|
315
|
+
* Used for schema migrations when new columns are added.
|
|
316
|
+
*
|
|
317
|
+
* @param args - The alter table arguments
|
|
318
|
+
* @param args.tableName - The name of the table to alter
|
|
319
|
+
* @param args.schema - The full schema definition for the table
|
|
320
|
+
* @param args.ifNotExists - Array of column names to add if they don't exist
|
|
321
|
+
*/
|
|
322
|
+
alterTable({ tableName, schema, ifNotExists, }: {
|
|
323
|
+
tableName: TABLE_NAMES;
|
|
324
|
+
schema: Record<string, StorageColumn>;
|
|
325
|
+
ifNotExists: string[];
|
|
326
|
+
}): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* Deletes all records from the specified table.
|
|
329
|
+
* Errors are logged but not thrown.
|
|
330
|
+
*
|
|
331
|
+
* @param args - The delete arguments
|
|
332
|
+
* @param args.tableName - The name of the table to clear
|
|
333
|
+
*/
|
|
334
|
+
deleteData({ tableName }: {
|
|
335
|
+
tableName: TABLE_NAMES;
|
|
336
|
+
}): Promise<void>;
|
|
337
|
+
/**
|
|
338
|
+
* Delete up to `limit` of the oldest rows whose `column` timestamp is strictly
|
|
339
|
+
* before `cutoffMs`, in a single bounded statement. Returns the number of rows
|
|
340
|
+
* removed so the caller can decide whether more batches remain.
|
|
341
|
+
*
|
|
342
|
+
* Deletes by `rowid` so the range scan is bounded by LIMIT and the write set
|
|
343
|
+
* stays small — short locks, bounded WAL growth. Requires an index on
|
|
344
|
+
* `column` to be fast at scale (see ensureIndex).
|
|
345
|
+
*/
|
|
346
|
+
pruneBatch({ tableName, column, cutoff, limit, }: {
|
|
347
|
+
tableName: TABLE_NAMES;
|
|
348
|
+
column: string;
|
|
349
|
+
/**
|
|
350
|
+
* Exclusive upper bound for the anchor column. Must match the column's
|
|
351
|
+
* stored type — the memory/observability timestamp anchors are stored as
|
|
352
|
+
* ISO-8601 strings, which sort lexicographically in chronological order, so
|
|
353
|
+
* the caller passes an ISO string cutoff.
|
|
354
|
+
*/
|
|
355
|
+
cutoff: string | number;
|
|
356
|
+
limit: number;
|
|
357
|
+
}): Promise<number>;
|
|
358
|
+
/**
|
|
359
|
+
* Delete up to `limit` aged parent rows *and* their child rows together, in a
|
|
360
|
+
* single transaction. Used for whole-unit (parent-driven) pruning where
|
|
361
|
+
* children must die with their parent (e.g. an aged experiment and its
|
|
362
|
+
* experiment_results) — deleting per unit means a bound or abort between
|
|
363
|
+
* batches never leaves a parent hollow (kept, but with its children gone) or
|
|
364
|
+
* children orphaned.
|
|
365
|
+
*
|
|
366
|
+
* Both deletes target the same parent set via an identical deterministic
|
|
367
|
+
* subquery (`ORDER BY rowid LIMIT ?`); the batch runs as one write
|
|
368
|
+
* transaction, so the set cannot change between the two statements.
|
|
369
|
+
*/
|
|
370
|
+
pruneUnitsBatch({ parentTable, parentKey, parentColumn, childTable, childForeignKey, cutoff, limit, }: {
|
|
371
|
+
parentTable: TABLE_NAMES;
|
|
372
|
+
parentKey: string;
|
|
373
|
+
parentColumn: string;
|
|
374
|
+
childTable: TABLE_NAMES;
|
|
375
|
+
childForeignKey: string;
|
|
376
|
+
cutoff: string | number;
|
|
377
|
+
limit: number;
|
|
378
|
+
}): Promise<{
|
|
379
|
+
parents: number;
|
|
380
|
+
children: number;
|
|
381
|
+
}>;
|
|
382
|
+
/** Create an index if it does not already exist. */
|
|
383
|
+
ensureIndex({ indexName, tableName, column, }: {
|
|
384
|
+
indexName: string;
|
|
385
|
+
tableName: TABLE_NAMES;
|
|
386
|
+
column: string;
|
|
387
|
+
}): Promise<void>;
|
|
388
|
+
}
|
|
389
|
+
//# 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,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|
1
|
+
import type { InValue } from '@libsql/client';
|
|
2
|
+
import type { IMastraLogger } from '@mastra/core/logger';
|
|
3
|
+
import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
|
|
4
|
+
/**
|
|
5
|
+
* Safely serializes a value to JSON string with pre-sanitization.
|
|
6
|
+
* Handles RPC proxies (Cloudflare Workers), functions, symbols, BigInt, and circular references.
|
|
7
|
+
*
|
|
8
|
+
* Pre-sanitization is required because RPC proxies throw on toJSON property access,
|
|
9
|
+
* which happens before JSON.stringify's replacer can intervene.
|
|
10
|
+
*
|
|
11
|
+
* @param value - The value to serialize
|
|
12
|
+
* @returns JSON string representation, with non-serializable values removed
|
|
13
|
+
*/
|
|
14
|
+
export declare const safeStringify: (value: unknown) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Builds a SQL column list for SELECT statements, wrapping JSONB columns with json()
|
|
17
|
+
* to convert binary JSONB to TEXT.
|
|
18
|
+
*
|
|
19
|
+
* The json() function handles both:
|
|
20
|
+
* - Binary JSONB data (converts to TEXT)
|
|
21
|
+
* - Legacy TEXT JSON data (returns as-is)
|
|
22
|
+
*
|
|
23
|
+
* Note: json_valid() was considered for guarding against malformed legacy TEXT,
|
|
24
|
+
* but it doesn't work correctly with binary JSONB data (returns false for valid JSONB blobs).
|
|
25
|
+
*
|
|
26
|
+
* @param tableName - The table name to get the schema for
|
|
27
|
+
* @returns A comma-separated column list with json() wrappers for JSONB columns
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildSelectColumns(tableName: TABLE_NAMES): string;
|
|
30
|
+
/**
|
|
31
|
+
* Same as `buildSelectColumns` but qualifies each column with the given table alias.
|
|
32
|
+
* Used by queries that JOIN multiple tables and need unambiguous column references.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildSelectColumnsWithAlias(tableName: TABLE_NAMES, alias: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if an error is a SQLite lock/busy error that should be retried
|
|
37
|
+
*/
|
|
38
|
+
export declare function isLockError(error: any): boolean;
|
|
39
|
+
export declare function createExecuteWriteOperationWithRetry({ logger, maxRetries, initialBackoffMs, }: {
|
|
40
|
+
logger: IMastraLogger;
|
|
41
|
+
maxRetries: number;
|
|
42
|
+
initialBackoffMs: number;
|
|
43
|
+
}): <T>(operationFn: () => Promise<T>, operationDescription: string) => Promise<T>;
|
|
44
|
+
export declare function prepareStatement({ tableName, record }: {
|
|
45
|
+
tableName: TABLE_NAMES;
|
|
46
|
+
record: Record<string, any>;
|
|
47
|
+
}): {
|
|
48
|
+
sql: string;
|
|
49
|
+
args: InValue[];
|
|
50
|
+
};
|
|
51
|
+
export declare function prepareUpdateStatement({ tableName, updates, keys, }: {
|
|
52
|
+
tableName: TABLE_NAMES;
|
|
53
|
+
updates: Record<string, any>;
|
|
54
|
+
keys: Record<string, any>;
|
|
55
|
+
}): {
|
|
56
|
+
sql: string;
|
|
57
|
+
args: InValue[];
|
|
58
|
+
};
|
|
59
|
+
export declare function transformToSqlValue(value: any, forceJsonStringify?: boolean): InValue;
|
|
60
|
+
export declare function prepareDeleteStatement({ tableName, keys }: {
|
|
61
|
+
tableName: TABLE_NAMES;
|
|
62
|
+
keys: Record<string, any>;
|
|
63
|
+
}): {
|
|
64
|
+
sql: string;
|
|
65
|
+
args: InValue[];
|
|
66
|
+
};
|
|
67
|
+
type WhereValue = InValue | {
|
|
68
|
+
startAt?: InValue;
|
|
69
|
+
endAt?: InValue;
|
|
70
|
+
};
|
|
71
|
+
export declare function prepareWhereClause(filters: Record<string, WhereValue>, schema: Record<string, StorageColumn>): {
|
|
72
|
+
sql: string;
|
|
73
|
+
args: InValue[];
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Transforms SQL row data back to a typed object format
|
|
77
|
+
* Reverses the transformations done in prepareStatement
|
|
78
|
+
*/
|
|
79
|
+
export declare function transformFromSqlRow<T>({ tableName, sqlRow, }: {
|
|
80
|
+
tableName: TABLE_NAMES;
|
|
81
|
+
sqlRow: Record<string, any>;
|
|
82
|
+
}): T;
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -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;AAQvE;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,MAyD9C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,WAAW,GAAG,MAAM,CAUjE;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAYzF;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,EAC7B,sBAAsB,MAAM,KAC3B,OAAO,CAAC,CAAC,CAAC,CAyCd;AAED,wBAAgB,gBAAgB,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE;IAAE,SAAS,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,GAAG;IAChH,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,OAAO,EAAE,CAAC;CAC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
|
1
|
+
import type { Client } from '@libsql/client';
|
|
2
|
+
/**
|
|
3
|
+
* Runs `fn` after every previously-enqueued write on `client` has settled, and
|
|
4
|
+
* returns its result. The chain advances regardless of whether `fn` resolves or
|
|
5
|
+
* rejects, so one failed write never wedges the queue.
|
|
6
|
+
*/
|
|
7
|
+
export declare function withClientWriteLock<T>(client: Client, fn: () => Promise<T>): Promise<T>;
|
|
8
|
+
//# sourceMappingURL=write-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-lock.d.ts","sourceRoot":"","sources":["../../../src/storage/db/write-lock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AA0B7C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAYvF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AgentsStorage } from '@mastra/core/storage';
|
|
2
|
+
import type { StorageAgentType, StorageCreateAgentInput, StorageUpdateAgentInput, StorageListAgentsInput, StorageListAgentsOutput, AgentVersion, CreateVersionInput, ListVersionsInput, ListVersionsOutput } from '@mastra/core/storage';
|
|
3
|
+
import type { LibSQLDomainConfig } from '../../db/index.js';
|
|
4
|
+
export declare class AgentsLibSQL extends AgentsStorage {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(config: LibSQLDomainConfig);
|
|
7
|
+
init(): Promise<void>;
|
|
8
|
+
dangerouslyClearAll(): Promise<void>;
|
|
9
|
+
private parseJson;
|
|
10
|
+
private parseRow;
|
|
11
|
+
getById(id: string): Promise<StorageAgentType | null>;
|
|
12
|
+
create(input: {
|
|
13
|
+
agent: StorageCreateAgentInput;
|
|
14
|
+
}): Promise<StorageAgentType>;
|
|
15
|
+
update(input: StorageUpdateAgentInput): Promise<StorageAgentType>;
|
|
16
|
+
delete(id: string): Promise<void>;
|
|
17
|
+
list(args?: StorageListAgentsInput): Promise<StorageListAgentsOutput>;
|
|
18
|
+
createVersion(input: CreateVersionInput): Promise<AgentVersion>;
|
|
19
|
+
getVersion(id: string): Promise<AgentVersion | null>;
|
|
20
|
+
getVersionByNumber(agentId: string, versionNumber: number): Promise<AgentVersion | null>;
|
|
21
|
+
getLatestVersion(agentId: string): Promise<AgentVersion | null>;
|
|
22
|
+
listVersions(input: ListVersionsInput): Promise<ListVersionsOutput>;
|
|
23
|
+
deleteVersion(id: string): Promise<void>;
|
|
24
|
+
deleteVersionsByParentId(entityId: string): Promise<void>;
|
|
25
|
+
countVersions(agentId: string): Promise<number>;
|
|
26
|
+
private serializeInstructions;
|
|
27
|
+
private deserializeInstructions;
|
|
28
|
+
private parseVersionRow;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/agents/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EASd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD,qBAAa,YAAa,SAAQ,aAAa;;gBAIjC,MAAM,EAAE,kBAAkB;IAOhC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAmOrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAK1C,OAAO,CAAC,SAAS;IAwCjB,OAAO,CAAC,QAAQ;IAcV,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAsBrD,MAAM,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,uBAAuB,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAmE5E,MAAM,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAgEjE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBjC,IAAI,CAAC,IAAI,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAsKrE,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAsD/D,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA0BpD,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA8BxF,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA+B/D,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA4EnE,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxC,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCzD,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BrD,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,uBAAuB;IAW/B,OAAO,CAAC,eAAe;CA8BxB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BackgroundTask, TaskFilter, TaskListResult, UpdateBackgroundTask } from '@mastra/core/background-tasks';
|
|
2
|
+
import { BackgroundTasksStorage } from '@mastra/core/storage';
|
|
3
|
+
import type { PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
4
|
+
import type { LibSQLDomainConfig } from '../../db/index.js';
|
|
5
|
+
export declare class BackgroundTasksLibSQL extends BackgroundTasksStorage {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Completed/failed task records accumulate. Anchored on `completedAt`, which
|
|
9
|
+
* is NULL while a task is in-flight (pending/running/suspended) — so `completedAt
|
|
10
|
+
* < cutoff` never prunes a live task, no explicit status filter needed.
|
|
11
|
+
*/
|
|
12
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
13
|
+
constructor(config: LibSQLDomainConfig);
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
dangerouslyClearAll(): Promise<void>;
|
|
16
|
+
/** Delete completed tasks older than the `backgroundTasks` policy's `maxAge`, batched. */
|
|
17
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
18
|
+
createTask(task: BackgroundTask): Promise<void>;
|
|
19
|
+
updateTask(taskId: string, update: UpdateBackgroundTask): Promise<void>;
|
|
20
|
+
getTask(taskId: string): Promise<BackgroundTask | null>;
|
|
21
|
+
listTasks(filter: TaskFilter): Promise<TaskListResult>;
|
|
22
|
+
deleteTask(taskId: string): Promise<void>;
|
|
23
|
+
deleteTasks(filter: TaskFilter): Promise<void>;
|
|
24
|
+
getRunningCount(): Promise<number>;
|
|
25
|
+
getRunningCountByAgent(agentId: string): Promise<number>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/background-tasks/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAyC,MAAM,sBAAsB,CAAC;AACrG,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEvH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AA6CnD,qBAAa,qBAAsB,SAAQ,sBAAsB;;IAC/D;;;;OAIG;IACH,gBAAyB,eAAe,EAAE,yBAAyB,CAEjE;gBAKU,MAAM,EAAE,kBAAkB;IAOhC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAarB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C,0FAA0F;IACpF,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IASrG,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA4B/C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CvE,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IASvD,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC;IAqFtD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2C9C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAQlC,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAO/D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BlobStore } from '@mastra/core/storage';
|
|
2
|
+
import type { StorageBlobEntry } from '@mastra/core/storage';
|
|
3
|
+
import type { LibSQLDomainConfig } from '../../db/index.js';
|
|
4
|
+
export declare class BlobsLibSQL extends BlobStore {
|
|
5
|
+
#private;
|
|
6
|
+
static readonly MANAGED_TABLES: readonly ["mastra_skill_blobs"];
|
|
7
|
+
constructor(config: LibSQLDomainConfig);
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
put(entry: StorageBlobEntry): Promise<void>;
|
|
10
|
+
get(hash: string): Promise<StorageBlobEntry | null>;
|
|
11
|
+
has(hash: string): Promise<boolean>;
|
|
12
|
+
delete(hash: string): Promise<boolean>;
|
|
13
|
+
putMany(entries: StorageBlobEntry[]): Promise<void>;
|
|
14
|
+
getMany(hashes: string[]): Promise<Map<string, StorageBlobEntry>>;
|
|
15
|
+
dangerouslyClearAll(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/blobs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAyC,MAAM,sBAAsB,CAAC;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD,qBAAa,WAAY,SAAQ,SAAS;;IAIxC,MAAM,CAAC,QAAQ,CAAC,cAAc,kCAAgC;gBAElD,MAAM,EAAE,kBAAkB;IAOhC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,GAAG,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IASnD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQnC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQtC,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAqBjE,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;CAa3C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ChannelsStorage } from '@mastra/core/storage';
|
|
2
|
+
import type { ChannelInstallation, ChannelConfig } from '@mastra/core/storage';
|
|
3
|
+
import type { LibSQLDomainConfig } from '../../db/index.js';
|
|
4
|
+
export declare class ChannelsLibSQL extends ChannelsStorage {
|
|
5
|
+
#private;
|
|
6
|
+
static readonly MANAGED_TABLES: readonly ["mastra_channel_installations", "mastra_channel_config"];
|
|
7
|
+
constructor(config: LibSQLDomainConfig);
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
dangerouslyClearAll(): Promise<void>;
|
|
10
|
+
saveInstallation(installation: ChannelInstallation): Promise<void>;
|
|
11
|
+
getInstallation(id: string): Promise<ChannelInstallation | null>;
|
|
12
|
+
getInstallationByAgent(platform: string, agentId: string): Promise<ChannelInstallation | null>;
|
|
13
|
+
getInstallationByWebhookId(webhookId: string): Promise<ChannelInstallation | null>;
|
|
14
|
+
listInstallations(platform: string): Promise<ChannelInstallation[]>;
|
|
15
|
+
deleteInstallation(id: string): Promise<void>;
|
|
16
|
+
saveConfig(config: ChannelConfig): Promise<void>;
|
|
17
|
+
getConfig(platform: string): Promise<ChannelConfig | null>;
|
|
18
|
+
deleteConfig(platform: string): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/channels/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EAIhB,MAAM,sBAAsB,CAAC;AAC9B,OAA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